VerifyDB progress

This commit is contained in:
Cozz Lovan 2014-05-23 18:04:09 +02:00
parent 4c097f9669
commit 06a91d9698
10 changed files with 74 additions and 5 deletions

View File

@ -858,7 +858,7 @@ bool AppInit2(boost::thread_group& threadGroup)
} }
uiInterface.InitMessage(_("Verifying blocks...")); uiInterface.InitMessage(_("Verifying blocks..."));
if (!VerifyDB(GetArg("-checklevel", 3), if (!CVerifyDB().VerifyDB(GetArg("-checklevel", 3),
GetArg("-checkblocks", 288))) { GetArg("-checkblocks", 288))) {
strLoadError = _("Corrupted block database detected"); strLoadError = _("Corrupted block database detected");
break; break;

View File

@ -2968,7 +2968,17 @@ bool static LoadBlockIndexDB()
return true; return true;
} }
bool VerifyDB(int nCheckLevel, int nCheckDepth) CVerifyDB::CVerifyDB()
{
uiInterface.ShowProgress(_("Verifying blocks..."), 0);
}
CVerifyDB::~CVerifyDB()
{
uiInterface.ShowProgress("", 100);
}
bool CVerifyDB::VerifyDB(int nCheckLevel, int nCheckDepth)
{ {
LOCK(cs_main); LOCK(cs_main);
if (chainActive.Tip() == NULL || chainActive.Tip()->pprev == NULL) if (chainActive.Tip() == NULL || chainActive.Tip()->pprev == NULL)
@ -2989,6 +2999,7 @@ bool VerifyDB(int nCheckLevel, int nCheckDepth)
for (CBlockIndex* pindex = chainActive.Tip(); pindex && pindex->pprev; pindex = pindex->pprev) for (CBlockIndex* pindex = chainActive.Tip(); pindex && pindex->pprev; pindex = pindex->pprev)
{ {
boost::this_thread::interruption_point(); boost::this_thread::interruption_point();
uiInterface.ShowProgress(_("Verifying blocks..."), std::max(1, std::min(99, (int)(((double)(chainActive.Height() - pindex->nHeight)) / (double)nCheckDepth * (nCheckLevel >= 4 ? 50 : 100)))));
if (pindex->nHeight < chainActive.Height()-nCheckDepth) if (pindex->nHeight < chainActive.Height()-nCheckDepth)
break; break;
CBlock block; CBlock block;
@ -3028,6 +3039,7 @@ bool VerifyDB(int nCheckLevel, int nCheckDepth)
CBlockIndex *pindex = pindexState; CBlockIndex *pindex = pindexState;
while (pindex != chainActive.Tip()) { while (pindex != chainActive.Tip()) {
boost::this_thread::interruption_point(); boost::this_thread::interruption_point();
uiInterface.ShowProgress(_("Verifying blocks..."), std::max(1, std::min(99, 100 - (int)(((double)(chainActive.Height() - pindex->nHeight)) / (double)nCheckDepth * 50))));
pindex = chainActive.Next(pindex); pindex = chainActive.Next(pindex);
CBlock block; CBlock block;
if (!ReadBlockFromDisk(block, pindex)) if (!ReadBlockFromDisk(block, pindex))

View File

@ -144,8 +144,6 @@ bool InitBlockIndex();
bool LoadBlockIndex(); bool LoadBlockIndex();
/** Unload database information */ /** Unload database information */
void UnloadBlockIndex(); void UnloadBlockIndex();
/** Verify consistency of the block and coin databases */
bool VerifyDB(int nCheckLevel, int nCheckDepth);
/** Print the loaded block tree */ /** Print the loaded block tree */
void PrintBlockTree(); void PrintBlockTree();
/** Process protocol messages received from a given node */ /** Process protocol messages received from a given node */
@ -1024,6 +1022,15 @@ public:
std::string GetRejectReason() const { return strRejectReason; } std::string GetRejectReason() const { return strRejectReason; }
}; };
/** RAII wrapper for VerifyDB: Verify consistency of the block and coin databases */
class CVerifyDB {
public:
CVerifyDB();
~CVerifyDB();
bool VerifyDB(int nCheckLevel, int nCheckDepth);
};
/** An in-memory indexed chain of blocks. */ /** An in-memory indexed chain of blocks. */
class CChain { class CChain {
private: private:

View File

@ -40,6 +40,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QMimeData> #include <QMimeData>
#include <QProgressBar> #include <QProgressBar>
#include <QProgressDialog>
#include <QSettings> #include <QSettings>
#include <QStackedWidget> #include <QStackedWidget>
#include <QStatusBar> #include <QStatusBar>
@ -409,6 +410,9 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
// Receive and report messages from client model // Receive and report messages from client model
connect(clientModel, SIGNAL(message(QString,QString,unsigned int)), this, SLOT(message(QString,QString,unsigned int))); connect(clientModel, SIGNAL(message(QString,QString,unsigned int)), this, SLOT(message(QString,QString,unsigned int)));
// Show progress dialog
connect(clientModel, SIGNAL(showProgress(QString,int)), this, SLOT(showProgress(QString,int)));
rpcConsole->setClientModel(clientModel); rpcConsole->setClientModel(clientModel);
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
if(walletFrame) if(walletFrame)
@ -949,6 +953,29 @@ void BitcoinGUI::detectShutdown()
} }
} }
void BitcoinGUI::showProgress(const QString &title, int nProgress)
{
if (nProgress == 0)
{
progressDialog = new QProgressDialog(title, "", 0, 100);
progressDialog->setWindowModality(Qt::ApplicationModal);
progressDialog->setMinimumDuration(0);
progressDialog->setCancelButton(0);
progressDialog->setAutoClose(false);
progressDialog->setValue(0);
}
else if (nProgress == 100)
{
if (progressDialog)
{
progressDialog->close();
progressDialog->deleteLater();
}
}
else if (progressDialog)
progressDialog->setValue(nProgress);
}
static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string& message, const std::string& caption, unsigned int style) static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string& message, const std::string& caption, unsigned int style)
{ {
bool modal = (style & CClientUIInterface::MODAL); bool modal = (style & CClientUIInterface::MODAL);

View File

@ -26,6 +26,7 @@ QT_BEGIN_NAMESPACE
class QAction; class QAction;
class QLabel; class QLabel;
class QProgressBar; class QProgressBar;
class QProgressDialog;
QT_END_NAMESPACE QT_END_NAMESPACE
/** /**
@ -73,6 +74,7 @@ private:
QLabel *labelBlocksIcon; QLabel *labelBlocksIcon;
QLabel *progressBarLabel; QLabel *progressBarLabel;
QProgressBar *progressBar; QProgressBar *progressBar;
QProgressDialog *progressDialog;
QMenuBar *appMenuBar; QMenuBar *appMenuBar;
QAction *overviewAction; QAction *overviewAction;
@ -191,6 +193,9 @@ private slots:
/** called by a timer to check if fRequestShutdown has been set **/ /** called by a timer to check if fRequestShutdown has been set **/
void detectShutdown(); void detectShutdown();
/** Show progress dialog e.g. for verifychain */
void showProgress(const QString &title, int nProgress);
}; };
#endif // BITCOINGUI_H #endif // BITCOINGUI_H

View File

@ -206,6 +206,14 @@ QString ClientModel::formatClientStartupTime() const
} }
// Handlers for core signals // Handlers for core signals
static void ShowProgress(ClientModel *clientmodel, const std::string &title, int nProgress)
{
// emits signal "showProgress"
QMetaObject::invokeMethod(clientmodel, "showProgress", Qt::QueuedConnection,
Q_ARG(QString, QString::fromStdString(title)),
Q_ARG(int, nProgress));
}
static void NotifyBlocksChanged(ClientModel *clientmodel) static void NotifyBlocksChanged(ClientModel *clientmodel)
{ {
// This notification is too frequent. Don't trigger a signal. // This notification is too frequent. Don't trigger a signal.
@ -230,6 +238,7 @@ static void NotifyAlertChanged(ClientModel *clientmodel, const uint256 &hash, Ch
void ClientModel::subscribeToCoreSignals() void ClientModel::subscribeToCoreSignals()
{ {
// Connect signals to client // Connect signals to client
uiInterface.ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2));
uiInterface.NotifyBlocksChanged.connect(boost::bind(NotifyBlocksChanged, this)); uiInterface.NotifyBlocksChanged.connect(boost::bind(NotifyBlocksChanged, this));
uiInterface.NotifyNumConnectionsChanged.connect(boost::bind(NotifyNumConnectionsChanged, this, _1)); uiInterface.NotifyNumConnectionsChanged.connect(boost::bind(NotifyNumConnectionsChanged, this, _1));
uiInterface.NotifyAlertChanged.connect(boost::bind(NotifyAlertChanged, this, _1, _2)); uiInterface.NotifyAlertChanged.connect(boost::bind(NotifyAlertChanged, this, _1, _2));
@ -238,6 +247,7 @@ void ClientModel::subscribeToCoreSignals()
void ClientModel::unsubscribeFromCoreSignals() void ClientModel::unsubscribeFromCoreSignals()
{ {
// Disconnect signals from client // Disconnect signals from client
uiInterface.ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
uiInterface.NotifyBlocksChanged.disconnect(boost::bind(NotifyBlocksChanged, this)); uiInterface.NotifyBlocksChanged.disconnect(boost::bind(NotifyBlocksChanged, this));
uiInterface.NotifyNumConnectionsChanged.disconnect(boost::bind(NotifyNumConnectionsChanged, this, _1)); uiInterface.NotifyNumConnectionsChanged.disconnect(boost::bind(NotifyNumConnectionsChanged, this, _1));
uiInterface.NotifyAlertChanged.disconnect(boost::bind(NotifyAlertChanged, this, _1, _2)); uiInterface.NotifyAlertChanged.disconnect(boost::bind(NotifyAlertChanged, this, _1, _2));

View File

@ -95,6 +95,9 @@ signals:
//! Fired when a message should be reported to the user //! Fired when a message should be reported to the user
void message(const QString &title, const QString &message, unsigned int style); void message(const QString &title, const QString &message, unsigned int style);
// Show progress dialog e.g. for verifychain
void showProgress(const QString &title, int nProgress);
public slots: public slots:
void updateTimer(); void updateTimer();
void updateNumConnections(int numConnections); void updateNumConnections(int numConnections);

View File

@ -129,6 +129,7 @@ void SplashScreen::subscribeToCoreSignals()
{ {
// Connect signals to client // Connect signals to client
uiInterface.InitMessage.connect(boost::bind(InitMessage, this, _1)); uiInterface.InitMessage.connect(boost::bind(InitMessage, this, _1));
uiInterface.ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2));
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
uiInterface.LoadWallet.connect(boost::bind(ConnectWallet, this, _1)); uiInterface.LoadWallet.connect(boost::bind(ConnectWallet, this, _1));
#endif #endif
@ -138,6 +139,7 @@ void SplashScreen::unsubscribeFromCoreSignals()
{ {
// Disconnect signals from client // Disconnect signals from client
uiInterface.InitMessage.disconnect(boost::bind(InitMessage, this, _1)); uiInterface.InitMessage.disconnect(boost::bind(InitMessage, this, _1));
uiInterface.ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
if(pwalletMain) if(pwalletMain)
pwalletMain->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2)); pwalletMain->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));

View File

@ -427,7 +427,7 @@ Value verifychain(const Array& params, bool fHelp)
if (params.size() > 1) if (params.size() > 1)
nCheckDepth = params[1].get_int(); nCheckDepth = params[1].get_int();
return VerifyDB(nCheckLevel, nCheckDepth); return CVerifyDB().VerifyDB(nCheckLevel, nCheckDepth);
} }
Value getblockchaininfo(const Array& params, bool fHelp) Value getblockchaininfo(const Array& params, bool fHelp)

View File

@ -94,6 +94,9 @@ public:
/** A wallet has been loaded. */ /** A wallet has been loaded. */
boost::signals2::signal<void (CWallet* wallet)> LoadWallet; boost::signals2::signal<void (CWallet* wallet)> LoadWallet;
/** Show progress e.g. for verifychain */
boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
}; };
extern CClientUIInterface uiInterface; extern CClientUIInterface uiInterface;