make initial block download reporting somewhat better by tracking version responses

This commit is contained in:
Wladimir J. van der Laan 2011-07-17 14:06:43 +02:00
parent b5f918cbd6
commit 5df0b03c95
7 changed files with 49 additions and 16 deletions

View file

@ -32,7 +32,7 @@ map<COutPoint, CInPoint> mapNextTx;
map<uint256, CBlockIndex*> mapBlockIndex; map<uint256, CBlockIndex*> mapBlockIndex;
uint256 hashGenesisBlock("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"); uint256 hashGenesisBlock("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f");
CBigNum bnProofOfWorkLimit(~uint256(0) >> 32); CBigNum bnProofOfWorkLimit(~uint256(0) >> 32);
const int nTotalBlocksEstimate = 134444; // Conservative estimate of total nr of blocks on main chain int nTotalBlocksEstimate = 134444; // Conservative estimate of total nr of blocks on main chain
const int nInitialBlockThreshold = 120; // Regard blocks up until N-threshold as "initial download" const int nInitialBlockThreshold = 120; // Regard blocks up until N-threshold as "initial download"
CBlockIndex* pindexGenesisBlock = NULL; CBlockIndex* pindexGenesisBlock = NULL;
int nBestHeight = -1; int nBestHeight = -1;
@ -1869,6 +1869,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
pfrom->fSuccessfullyConnected = true; pfrom->fSuccessfullyConnected = true;
printf("version message: version %d, blocks=%d\n", pfrom->nVersion, pfrom->nStartingHeight); printf("version message: version %d, blocks=%d\n", pfrom->nVersion, pfrom->nStartingHeight);
if(pfrom->nStartingHeight > nTotalBlocksEstimate)
{
nTotalBlocksEstimate = pfrom->nStartingHeight;
}
} }

View file

@ -292,17 +292,21 @@ void BitcoinGUI::setNumConnections(int count)
void BitcoinGUI::setNumBlocks(int count) void BitcoinGUI::setNumBlocks(int count)
{ {
int total = clientModel->getTotalBlocksEstimate(); int total = clientModel->getTotalBlocksEstimate();
QString tooltip;
if(count < total) if(count < total)
{ {
progressBarLabel->setVisible(true); progressBarLabel->setVisible(true);
progressBar->setVisible(true); progressBar->setVisible(true);
progressBar->setMaximum(total); progressBar->setMaximum(total);
progressBar->setValue(count); progressBar->setValue(count);
tooltip = tr("Downloaded %1 of %2 blocks of transaction history.").arg(count).arg(total);
} }
else else
{ {
progressBarLabel->setVisible(false); progressBarLabel->setVisible(false);
progressBar->setVisible(false); progressBar->setVisible(false);
tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
} }
QDateTime now = QDateTime::currentDateTime(); QDateTime now = QDateTime::currentDateTime();
@ -329,10 +333,13 @@ void BitcoinGUI::setNumBlocks(int count)
{ {
text = tr("%n day(s) ago","",secs/(60*60*24)); text = tr("%n day(s) ago","",secs/(60*60*24));
} }
tooltip += QString("\n");
tooltip += tr("Last block was generated %1.").arg(QLocale::system().toString(lastBlockDate));
labelBlocks->setText("<img src=\""+icon+"\"> " + text); labelBlocks->setText("<img src=\""+icon+"\"> " + text);
labelBlocks->setToolTip(tr("Downloaded %n block(s) of transaction history. Last block was generated %1.", "", count) labelBlocks->setToolTip(tooltip);
.arg(QLocale::system().toString(lastBlockDate))); progressBarLabel->setToolTip(tooltip);
progressBar->setToolTip(tooltip);
} }
void BitcoinGUI::error(const QString &title, const QString &message) void BitcoinGUI::error(const QString &title, const QString &message)

View file

@ -10,7 +10,8 @@
#include <QDateTime> #include <QDateTime>
ClientModel::ClientModel(CWallet *wallet, QObject *parent) : ClientModel::ClientModel(CWallet *wallet, QObject *parent) :
QObject(parent), wallet(wallet), optionsModel(0) QObject(parent), wallet(wallet), optionsModel(0),
cachedNumConnections(0), cachedNumBlocks(0)
{ {
// Until signal notifications is built into the bitcoin core, // Until signal notifications is built into the bitcoin core,
// simply update everything after polling using a timer. // simply update everything after polling using a timer.
@ -38,11 +39,16 @@ QDateTime ClientModel::getLastBlockDate() const
void ClientModel::update() void ClientModel::update()
{ {
// Plainly emit all signals for now. To be more efficient this should check int newNumConnections = getNumConnections();
// whether the values actually changed first, although it'd be even better if these int newNumBlocks = getNumBlocks();
// were events coming in from the bitcoin core.
emit numConnectionsChanged(getNumConnections()); if(cachedNumConnections != newNumConnections)
emit numBlocksChanged(getNumBlocks()); emit numConnectionsChanged(newNumConnections);
if(cachedNumBlocks != newNumBlocks)
emit numBlocksChanged(newNumBlocks);
cachedNumConnections = newNumConnections;
cachedNumBlocks = newNumBlocks;
} }
bool ClientModel::isTestNet() const bool ClientModel::isTestNet() const

View file

@ -42,6 +42,9 @@ private:
OptionsModel *optionsModel; OptionsModel *optionsModel;
int cachedNumConnections;
int cachedNumBlocks;
signals: signals:
void numConnectionsChanged(int count); void numConnectionsChanged(int count);
void numBlocksChanged(int count); void numBlocksChanged(int count);

View file

@ -2,7 +2,7 @@
#define GUICONSTANTS_H #define GUICONSTANTS_H
/* milliseconds between model updates */ /* milliseconds between model updates */
static const int MODEL_UPDATE_DELAY = 250; static const int MODEL_UPDATE_DELAY = 500;
/* size of cache */ /* size of cache */
static const unsigned int WALLET_CACHE_SIZE = 100; static const unsigned int WALLET_CACHE_SIZE = 100;

View file

@ -11,7 +11,8 @@
WalletModel::WalletModel(CWallet *wallet, QObject *parent) : WalletModel::WalletModel(CWallet *wallet, QObject *parent) :
QObject(parent), wallet(wallet), optionsModel(0), addressTableModel(0), QObject(parent), wallet(wallet), optionsModel(0), addressTableModel(0),
transactionTableModel(0) transactionTableModel(0),
cachedBalance(0), cachedUnconfirmedBalance(0), cachedNumTransactions(0)
{ {
// Until signal notifications is built into the bitcoin core, // Until signal notifications is built into the bitcoin core,
// simply update everything after polling using a timer. // simply update everything after polling using a timer.
@ -46,11 +47,19 @@ int WalletModel::getNumTransactions() const
void WalletModel::update() void WalletModel::update()
{ {
// Plainly emit all signals for now. To be more efficient this should check qint64 newBalance = getBalance();
// whether the values actually changed first, although it'd be even better if these qint64 newUnconfirmedBalance = getUnconfirmedBalance();
// were events coming in from the bitcoin core. int newNumTransactions = getNumTransactions();
emit balanceChanged(getBalance(), wallet->GetUnconfirmedBalance());
emit numTransactionsChanged(getNumTransactions()); if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance)
emit balanceChanged(newBalance, newUnconfirmedBalance);
if(cachedNumTransactions != newNumTransactions)
emit numTransactionsChanged(newNumTransactions);
cachedBalance = newBalance;
cachedUnconfirmedBalance = newUnconfirmedBalance;
cachedNumTransactions = newNumTransactions;
addressTableModel->update(); addressTableModel->update();
} }

View file

@ -73,6 +73,10 @@ private:
AddressTableModel *addressTableModel; AddressTableModel *addressTableModel;
TransactionTableModel *transactionTableModel; TransactionTableModel *transactionTableModel;
qint64 cachedBalance;
qint64 cachedUnconfirmedBalance;
qint64 cachedNumTransactions;
signals: signals:
void balanceChanged(qint64 balance, qint64 unconfirmedBalance); void balanceChanged(qint64 balance, qint64 unconfirmedBalance);
void numTransactionsChanged(int count); void numTransactionsChanged(int count);