mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
Merge pull request #2310 from sipa/progressbar
Progressbar based on time-based estimation of transactions.
This commit is contained in:
commit
9dca7190f9
@ -14,13 +14,25 @@ namespace Checkpoints
|
|||||||
{
|
{
|
||||||
typedef std::map<int, uint256> MapCheckpoints;
|
typedef std::map<int, uint256> MapCheckpoints;
|
||||||
|
|
||||||
//
|
// How many times we expect transactions after the last checkpoint to
|
||||||
|
// be slower. This number is conservative. On multi-core CPUs with
|
||||||
|
// parallel signature checking enabled, this number is way too high.
|
||||||
|
// We prefer a progressbar that's faster at the end than the other
|
||||||
|
// way around, though.
|
||||||
|
static const double fSigcheckVerificationFactor = 15.0;
|
||||||
|
|
||||||
|
struct CCheckpointData {
|
||||||
|
const MapCheckpoints *mapCheckpoints;
|
||||||
|
int64 nTimeLastCheckpoint;
|
||||||
|
int64 nTransactionsLastCheckpoint;
|
||||||
|
double fTransactionsPerDay;
|
||||||
|
};
|
||||||
|
|
||||||
// What makes a good checkpoint block?
|
// What makes a good checkpoint block?
|
||||||
// + Is surrounded by blocks with reasonable timestamps
|
// + Is surrounded by blocks with reasonable timestamps
|
||||||
// (no blocks before with a timestamp after, none after with
|
// (no blocks before with a timestamp after, none after with
|
||||||
// timestamp before)
|
// timestamp before)
|
||||||
// + Contains no strange transactions
|
// + Contains no strange transactions
|
||||||
//
|
|
||||||
static MapCheckpoints mapCheckpoints =
|
static MapCheckpoints mapCheckpoints =
|
||||||
boost::assign::map_list_of
|
boost::assign::map_list_of
|
||||||
( 11111, uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d"))
|
( 11111, uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d"))
|
||||||
@ -33,30 +45,81 @@ namespace Checkpoints
|
|||||||
(210000, uint256("0x000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e"))
|
(210000, uint256("0x000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e"))
|
||||||
(216116, uint256("0x00000000000001b4f4b433e81ee46494af945cf96014816a4e2370f11b23df4e"))
|
(216116, uint256("0x00000000000001b4f4b433e81ee46494af945cf96014816a4e2370f11b23df4e"))
|
||||||
;
|
;
|
||||||
|
static const CCheckpointData data = {
|
||||||
|
&mapCheckpoints,
|
||||||
|
1357902690, // * UNIX timestamp of last checkpoint block
|
||||||
|
11011160, // * total number of transactions between genesis and last checkpoint
|
||||||
|
// (the tx=... number in the SetBestChain debug.log lines)
|
||||||
|
50000.0 // * estimated number of transactions per day after checkpoint
|
||||||
|
};
|
||||||
|
|
||||||
static MapCheckpoints mapCheckpointsTestnet =
|
static MapCheckpoints mapCheckpointsTestnet =
|
||||||
boost::assign::map_list_of
|
boost::assign::map_list_of
|
||||||
( 546, uint256("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70"))
|
( 546, uint256("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70"))
|
||||||
;
|
;
|
||||||
|
static const CCheckpointData dataTestnet = {
|
||||||
|
&mapCheckpointsTestnet,
|
||||||
|
1338180505,
|
||||||
|
16341,
|
||||||
|
300
|
||||||
|
};
|
||||||
|
|
||||||
|
const CCheckpointData &Checkpoints() {
|
||||||
|
if (fTestNet)
|
||||||
|
return dataTestnet;
|
||||||
|
else
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
bool CheckBlock(int nHeight, const uint256& hash)
|
bool CheckBlock(int nHeight, const uint256& hash)
|
||||||
{
|
{
|
||||||
if (!GetBoolArg("-checkpoints", true))
|
if (!GetBoolArg("-checkpoints", true))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
MapCheckpoints& checkpoints = (fTestNet ? mapCheckpointsTestnet : mapCheckpoints);
|
const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;
|
||||||
|
|
||||||
MapCheckpoints::const_iterator i = checkpoints.find(nHeight);
|
MapCheckpoints::const_iterator i = checkpoints.find(nHeight);
|
||||||
if (i == checkpoints.end()) return true;
|
if (i == checkpoints.end()) return true;
|
||||||
return hash == i->second;
|
return hash == i->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Guess how far we are in the verification process at the given block index
|
||||||
|
double GuessVerificationProgress(CBlockIndex *pindex) {
|
||||||
|
if (pindex==NULL)
|
||||||
|
return 0.0;
|
||||||
|
|
||||||
|
int64 nNow = time(NULL);
|
||||||
|
|
||||||
|
double fWorkBefore = 0.0; // Amount of work done before pindex
|
||||||
|
double fWorkAfter = 0.0; // Amount of work left after pindex (estimated)
|
||||||
|
// Work is defined as: 1.0 per transaction before the last checkoint, and
|
||||||
|
// fSigcheckVerificationFactor per transaction after.
|
||||||
|
|
||||||
|
const CCheckpointData &data = Checkpoints();
|
||||||
|
|
||||||
|
if (pindex->nChainTx <= data.nTransactionsLastCheckpoint) {
|
||||||
|
double nCheapBefore = pindex->nChainTx;
|
||||||
|
double nCheapAfter = data.nTransactionsLastCheckpoint - pindex->nChainTx;
|
||||||
|
double nExpensiveAfter = (nNow - data.nTimeLastCheckpoint)/86400.0*data.fTransactionsPerDay;
|
||||||
|
fWorkBefore = nCheapBefore;
|
||||||
|
fWorkAfter = nCheapAfter + nExpensiveAfter*fSigcheckVerificationFactor;
|
||||||
|
} else {
|
||||||
|
double nCheapBefore = data.nTransactionsLastCheckpoint;
|
||||||
|
double nExpensiveBefore = pindex->nChainTx - data.nTransactionsLastCheckpoint;
|
||||||
|
double nExpensiveAfter = (nNow - pindex->nTime)/86400.0*data.fTransactionsPerDay;
|
||||||
|
fWorkBefore = nCheapBefore + nExpensiveBefore*fSigcheckVerificationFactor;
|
||||||
|
fWorkAfter = nExpensiveAfter*fSigcheckVerificationFactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fWorkBefore / (fWorkBefore + fWorkAfter);
|
||||||
|
}
|
||||||
|
|
||||||
int GetTotalBlocksEstimate()
|
int GetTotalBlocksEstimate()
|
||||||
{
|
{
|
||||||
if (!GetBoolArg("-checkpoints", true))
|
if (!GetBoolArg("-checkpoints", true))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
MapCheckpoints& checkpoints = (fTestNet ? mapCheckpointsTestnet : mapCheckpoints);
|
const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;
|
||||||
|
|
||||||
return checkpoints.rbegin()->first;
|
return checkpoints.rbegin()->first;
|
||||||
}
|
}
|
||||||
@ -66,7 +129,7 @@ namespace Checkpoints
|
|||||||
if (!GetBoolArg("-checkpoints", true))
|
if (!GetBoolArg("-checkpoints", true))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
MapCheckpoints& checkpoints = (fTestNet ? mapCheckpointsTestnet : mapCheckpoints);
|
const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;
|
||||||
|
|
||||||
BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints)
|
BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints)
|
||||||
{
|
{
|
||||||
|
@ -22,6 +22,8 @@ namespace Checkpoints
|
|||||||
|
|
||||||
// Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
|
// Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
|
||||||
CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);
|
CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);
|
||||||
|
|
||||||
|
double GuessVerificationProgress(CBlockIndex *pindex);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -67,7 +67,8 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
|
|||||||
aboutQtAction(0),
|
aboutQtAction(0),
|
||||||
trayIcon(0),
|
trayIcon(0),
|
||||||
notificator(0),
|
notificator(0),
|
||||||
rpcConsole(0)
|
rpcConsole(0),
|
||||||
|
prevBlocks(0)
|
||||||
{
|
{
|
||||||
resize(850, 550);
|
resize(850, 550);
|
||||||
setWindowTitle(tr("Bitcoin") + " - " + tr("Wallet"));
|
setWindowTitle(tr("Bitcoin") + " - " + tr("Wallet"));
|
||||||
@ -527,54 +528,19 @@ void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
|
|||||||
importText = tr("Reindexing blocks on disk...");
|
importText = tr("Reindexing blocks on disk...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDateTime lastBlockDate = clientModel->getLastBlockDate();
|
||||||
|
QDateTime currentDate = QDateTime::currentDateTime();
|
||||||
|
int secs = lastBlockDate.secsTo(currentDate);
|
||||||
|
|
||||||
if(count < nTotalBlocks)
|
if(count < nTotalBlocks)
|
||||||
{
|
{
|
||||||
int nRemainingBlocks = nTotalBlocks - count;
|
tooltip = tr("Processed %1 of %2 (estimated) blocks of transaction history.").arg(count).arg(nTotalBlocks);
|
||||||
float nPercentageDone = count / (nTotalBlocks * 0.01f);
|
|
||||||
|
|
||||||
progressBarLabel->setText(importText);
|
|
||||||
progressBarLabel->setVisible(true);
|
|
||||||
progressBar->setFormat(tr("~%n block(s) remaining", "", nRemainingBlocks));
|
|
||||||
progressBar->setMaximum(nTotalBlocks);
|
|
||||||
progressBar->setValue(count);
|
|
||||||
progressBar->setVisible(true);
|
|
||||||
|
|
||||||
tooltip = tr("Processed %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotalBlocks).arg(nPercentageDone, 0, 'f', 2);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
progressBarLabel->setVisible(false);
|
|
||||||
|
|
||||||
progressBar->setVisible(false);
|
|
||||||
tooltip = tr("Processed %1 blocks of transaction history.").arg(count);
|
tooltip = tr("Processed %1 blocks of transaction history.").arg(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime lastBlockDate = clientModel->getLastBlockDate();
|
|
||||||
int secs = lastBlockDate.secsTo(QDateTime::currentDateTime());
|
|
||||||
QString text;
|
|
||||||
|
|
||||||
// Represent time from last generated block in human readable text
|
|
||||||
if(secs <= 0)
|
|
||||||
{
|
|
||||||
// Fully up to date. Leave text empty.
|
|
||||||
}
|
|
||||||
else if(secs < 60)
|
|
||||||
{
|
|
||||||
text = tr("%n second(s) ago","",secs);
|
|
||||||
}
|
|
||||||
else if(secs < 60*60)
|
|
||||||
{
|
|
||||||
text = tr("%n minute(s) ago","",secs/60);
|
|
||||||
}
|
|
||||||
else if(secs < 24*60*60)
|
|
||||||
{
|
|
||||||
text = tr("%n hour(s) ago","",secs/(60*60));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
text = tr("%n day(s) ago","",secs/(60*60*24));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set icon state: spinning if catching up, tick otherwise
|
// Set icon state: spinning if catching up, tick otherwise
|
||||||
if(secs < 90*60 && count >= nTotalBlocks)
|
if(secs < 90*60 && count >= nTotalBlocks)
|
||||||
{
|
{
|
||||||
@ -582,20 +548,46 @@ void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
|
|||||||
labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
|
labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
|
||||||
|
|
||||||
overviewPage->showOutOfSyncWarning(false);
|
overviewPage->showOutOfSyncWarning(false);
|
||||||
|
|
||||||
|
progressBarLabel->setVisible(false);
|
||||||
|
progressBar->setVisible(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Represent time from last generated block in human readable text
|
||||||
|
QString timeBehindText;
|
||||||
|
if(secs < 48*60*60)
|
||||||
|
{
|
||||||
|
timeBehindText = tr("%n hour(s)","",secs/(60*60));
|
||||||
|
}
|
||||||
|
else if(secs < 14*24*60*60)
|
||||||
|
{
|
||||||
|
timeBehindText = tr("%n day(s)","",secs/(24*60*60));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
timeBehindText = tr("%n week(s)","",secs/(7*24*60*60));
|
||||||
|
}
|
||||||
|
|
||||||
|
progressBarLabel->setText(importText);
|
||||||
|
progressBarLabel->setVisible(true);
|
||||||
|
progressBar->setFormat(tr("%1 behind").arg(timeBehindText));
|
||||||
|
progressBar->setMaximum(1000000000);
|
||||||
|
progressBar->setValue(clientModel->getVerificationProgress() * 1000000000.0 + 0.5);
|
||||||
|
progressBar->setVisible(true);
|
||||||
|
|
||||||
tooltip = tr("Catching up...") + QString("<br>") + tooltip;
|
tooltip = tr("Catching up...") + QString("<br>") + tooltip;
|
||||||
labelBlocksIcon->setMovie(syncIconMovie);
|
labelBlocksIcon->setMovie(syncIconMovie);
|
||||||
syncIconMovie->start();
|
if(count != prevBlocks)
|
||||||
|
syncIconMovie->jumpToNextFrame();
|
||||||
|
prevBlocks = count;
|
||||||
|
|
||||||
overviewPage->showOutOfSyncWarning(true);
|
overviewPage->showOutOfSyncWarning(true);
|
||||||
}
|
|
||||||
|
|
||||||
if(!text.isEmpty())
|
|
||||||
{
|
|
||||||
tooltip += QString("<br>");
|
tooltip += QString("<br>");
|
||||||
tooltip += tr("Last received block was generated %1.").arg(text);
|
tooltip += tr("Last received block was generated %1 ago.").arg(timeBehindText);
|
||||||
|
tooltip += QString("<br>");
|
||||||
|
tooltip += tr("Transactions after this will not yet be visible.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't word-wrap this (fixed-width) tooltip
|
// Don't word-wrap this (fixed-width) tooltip
|
||||||
|
@ -98,6 +98,8 @@ private:
|
|||||||
RPCConsole *rpcConsole;
|
RPCConsole *rpcConsole;
|
||||||
|
|
||||||
QMovie *syncIconMovie;
|
QMovie *syncIconMovie;
|
||||||
|
/** Keep track of previous number of blocks, to detect progress */
|
||||||
|
int prevBlocks;
|
||||||
|
|
||||||
/** Create the main UI actions. */
|
/** Create the main UI actions. */
|
||||||
void createActions();
|
void createActions();
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "alert.h"
|
#include "alert.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "checkpoints.h"
|
||||||
#include "ui_interface.h"
|
#include "ui_interface.h"
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
@ -54,6 +55,11 @@ QDateTime ClientModel::getLastBlockDate() const
|
|||||||
return QDateTime::fromTime_t(1231006505); // Genesis block's time
|
return QDateTime::fromTime_t(1231006505); // Genesis block's time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double ClientModel::getVerificationProgress() const
|
||||||
|
{
|
||||||
|
return Checkpoints::GuessVerificationProgress(pindexBest);
|
||||||
|
}
|
||||||
|
|
||||||
void ClientModel::updateTimer()
|
void ClientModel::updateTimer()
|
||||||
{
|
{
|
||||||
// Some quantities (such as number of blocks) change so fast that we don't want to be notified for each change.
|
// Some quantities (such as number of blocks) change so fast that we don't want to be notified for each change.
|
||||||
|
@ -34,6 +34,7 @@ public:
|
|||||||
int getNumBlocks() const;
|
int getNumBlocks() const;
|
||||||
int getNumBlocksAtStartup();
|
int getNumBlocksAtStartup();
|
||||||
|
|
||||||
|
double getVerificationProgress() const;
|
||||||
QDateTime getLastBlockDate() const;
|
QDateTime getLastBlockDate() const;
|
||||||
|
|
||||||
//! Return true if client connected to testnet
|
//! Return true if client connected to testnet
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#define GUICONSTANTS_H
|
#define GUICONSTANTS_H
|
||||||
|
|
||||||
/* Milliseconds between model updates */
|
/* Milliseconds between model updates */
|
||||||
static const int MODEL_UPDATE_DELAY = 500;
|
static const int MODEL_UPDATE_DELAY = 250;
|
||||||
|
|
||||||
/* AskPassphraseDialog -- Maximum passphrase length */
|
/* AskPassphraseDialog -- Maximum passphrase length */
|
||||||
static const int MAX_PASSPHRASE_SIZE = 1024;
|
static const int MAX_PASSPHRASE_SIZE = 1024;
|
||||||
|
Loading…
Reference in New Issue
Block a user