Browse Source

Drop upgrade-cancel callback registration for a generic "resumeable"

Instead of passing a StartShutdown reference all the way up from
txdb, give ShowProgress a "resumeable" boolean, which is used to
inform the user if the action will be resumed, but cancel is always
allowed by just calling StartShutdown().
0.16
Matt Corallo 7 years ago
parent
commit
ee4d1493e2
  1. 32
      src/qt/splashscreen.cpp
  2. 4
      src/qt/splashscreen.h
  3. 6
      src/txdb.cpp
  4. 10
      src/ui_interface.h
  5. 12
      src/validation.cpp

32
src/qt/splashscreen.cpp

@ -142,8 +142,8 @@ SplashScreen::~SplashScreen()
bool SplashScreen::eventFilter(QObject * obj, QEvent * ev) { bool SplashScreen::eventFilter(QObject * obj, QEvent * ev) {
if (ev->type() == QEvent::KeyPress) { if (ev->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev); QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev);
if(keyEvent->text()[0] == 'q' && breakAction != nullptr) { if(keyEvent->text()[0] == 'q') {
breakAction(); StartShutdown();
} }
} }
return QObject::eventFilter(obj, ev); return QObject::eventFilter(obj, ev);
@ -170,27 +170,18 @@ static void InitMessage(SplashScreen *splash, const std::string &message)
Q_ARG(QColor, QColor(55,55,55))); Q_ARG(QColor, QColor(55,55,55)));
} }
static void ShowProgress(SplashScreen *splash, const std::string &title, int nProgress) static void ShowProgress(SplashScreen *splash, const std::string &title, int nProgress, bool resume_possible)
{ {
InitMessage(splash, title + strprintf("%d", nProgress) + "%"); InitMessage(splash, title + std::string("\n") +
} (resume_possible ? _("(press q to shutdown and continue later)")
: _("press q to shutdown")) +
void SplashScreen::setBreakAction(const std::function<void(void)> &action) strprintf("\n%d", nProgress) + "%");
{
breakAction = action;
}
static void SetProgressBreakAction(SplashScreen *splash, const std::function<void(void)> &action)
{
QMetaObject::invokeMethod(splash, "setBreakAction",
Qt::QueuedConnection,
Q_ARG(std::function<void(void)>, action));
} }
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
void SplashScreen::ConnectWallet(CWallet* wallet) void SplashScreen::ConnectWallet(CWallet* wallet)
{ {
wallet->ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2)); wallet->ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2, false));
connectedWallets.push_back(wallet); connectedWallets.push_back(wallet);
} }
#endif #endif
@ -199,8 +190,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)); uiInterface.ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2, _3));
uiInterface.SetProgressBreakAction.connect(boost::bind(SetProgressBreakAction, this, _1));
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
uiInterface.LoadWallet.connect(boost::bind(&SplashScreen::ConnectWallet, this, _1)); uiInterface.LoadWallet.connect(boost::bind(&SplashScreen::ConnectWallet, this, _1));
#endif #endif
@ -210,10 +200,10 @@ 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)); uiInterface.ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2, _3));
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
for (CWallet* const & pwallet : connectedWallets) { for (CWallet* const & pwallet : connectedWallets) {
pwallet->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2)); pwallet->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2, false));
} }
#endif #endif
} }

4
src/qt/splashscreen.h

@ -36,8 +36,6 @@ public Q_SLOTS:
/** Show message and progress */ /** Show message and progress */
void showMessage(const QString &message, int alignment, const QColor &color); void showMessage(const QString &message, int alignment, const QColor &color);
/** Sets the break action */
void setBreakAction(const std::function<void(void)> &action);
protected: protected:
bool eventFilter(QObject * obj, QEvent * ev); bool eventFilter(QObject * obj, QEvent * ev);
@ -55,8 +53,6 @@ private:
int curAlignment; int curAlignment;
QList<CWallet*> connectedWallets; QList<CWallet*> connectedWallets;
std::function<void(void)> breakAction;
}; };
#endif // BITCOIN_QT_SPLASHSCREEN_H #endif // BITCOIN_QT_SPLASHSCREEN_H

6
src/txdb.cpp

@ -371,9 +371,9 @@ bool CCoinsViewDB::Upgrade() {
int64_t count = 0; int64_t count = 0;
LogPrintf("Upgrading utxo-set database...\n"); LogPrintf("Upgrading utxo-set database...\n");
LogPrintf("[0%%]..."); LogPrintf("[0%%]...");
uiInterface.ShowProgress(_("Upgrading UTXO database"), 0, true);
size_t batch_size = 1 << 24; size_t batch_size = 1 << 24;
CDBBatch batch(db); CDBBatch batch(db);
uiInterface.SetProgressBreakAction(StartShutdown);
int reportDone = 0; int reportDone = 0;
std::pair<unsigned char, uint256> key; std::pair<unsigned char, uint256> key;
std::pair<unsigned char, uint256> prev_key = {DB_COINS, uint256()}; std::pair<unsigned char, uint256> prev_key = {DB_COINS, uint256()};
@ -386,7 +386,7 @@ bool CCoinsViewDB::Upgrade() {
if (count++ % 256 == 0) { if (count++ % 256 == 0) {
uint32_t high = 0x100 * *key.second.begin() + *(key.second.begin() + 1); uint32_t high = 0x100 * *key.second.begin() + *(key.second.begin() + 1);
int percentageDone = (int)(high * 100.0 / 65536.0 + 0.5); int percentageDone = (int)(high * 100.0 / 65536.0 + 0.5);
uiInterface.ShowProgress(_("Upgrading UTXO database") + "\n"+ _("(press q to shutdown and continue later)") + "\n", percentageDone); uiInterface.ShowProgress(_("Upgrading UTXO database"), percentageDone, true);
if (reportDone < percentageDone/10) { if (reportDone < percentageDone/10) {
// report max. every 10% step // report max. every 10% step
LogPrintf("[%d%%]...", percentageDone); LogPrintf("[%d%%]...", percentageDone);
@ -420,7 +420,7 @@ bool CCoinsViewDB::Upgrade() {
} }
db.WriteBatch(batch); db.WriteBatch(batch);
db.CompactRange({DB_COINS, uint256()}, key); db.CompactRange({DB_COINS, uint256()}, key);
uiInterface.SetProgressBreakAction(std::function<void(void)>()); uiInterface.ShowProgress("", 100, false);
LogPrintf("[%s].\n", ShutdownRequested() ? "CANCELLED" : "DONE"); LogPrintf("[%s].\n", ShutdownRequested() ? "CANCELLED" : "DONE");
return !ShutdownRequested(); return !ShutdownRequested();
} }

10
src/ui_interface.h

@ -94,11 +94,11 @@ 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; * Show progress e.g. for verifychain.
* resume_possible indicates shutting down now will result in the current progress action resuming upon restart.
/** Set progress break action (possible "cancel button" triggers that action) */ */
boost::signals2::signal<void (std::function<void(void)> action)> SetProgressBreakAction; boost::signals2::signal<void (const std::string &title, int nProgress, bool resume_possible)> ShowProgress;
/** New block has been accepted */ /** New block has been accepted */
boost::signals2::signal<void (bool, const CBlockIndex *)> NotifyBlockTip; boost::signals2::signal<void (bool, const CBlockIndex *)> NotifyBlockTip;

12
src/validation.cpp

@ -3563,12 +3563,12 @@ bool LoadChainTip(const CChainParams& chainparams)
CVerifyDB::CVerifyDB() CVerifyDB::CVerifyDB()
{ {
uiInterface.ShowProgress(_("Verifying blocks..."), 0); uiInterface.ShowProgress(_("Verifying blocks..."), 0, false);
} }
CVerifyDB::~CVerifyDB() CVerifyDB::~CVerifyDB()
{ {
uiInterface.ShowProgress("", 100); uiInterface.ShowProgress("", 100, false);
} }
bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth) bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
@ -3598,7 +3598,7 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
LogPrintf("[%d%%]...", percentageDone); LogPrintf("[%d%%]...", percentageDone);
reportDone = percentageDone/10; reportDone = percentageDone/10;
} }
uiInterface.ShowProgress(_("Verifying blocks..."), percentageDone); uiInterface.ShowProgress(_("Verifying blocks..."), percentageDone, false);
if (pindex->nHeight < chainActive.Height()-nCheckDepth) if (pindex->nHeight < chainActive.Height()-nCheckDepth)
break; break;
if (fPruneMode && !(pindex->nStatus & BLOCK_HAVE_DATA)) { if (fPruneMode && !(pindex->nStatus & BLOCK_HAVE_DATA)) {
@ -3649,7 +3649,7 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
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)))); uiInterface.ShowProgress(_("Verifying blocks..."), std::max(1, std::min(99, 100 - (int)(((double)(chainActive.Height() - pindex->nHeight)) / (double)nCheckDepth * 50))), false);
pindex = chainActive.Next(pindex); pindex = chainActive.Next(pindex);
CBlock block; CBlock block;
if (!ReadBlockFromDisk(block, pindex, chainparams.GetConsensus())) if (!ReadBlockFromDisk(block, pindex, chainparams.GetConsensus()))
@ -3696,7 +3696,7 @@ bool ReplayBlocks(const CChainParams& params, CCoinsView* view)
if (hashHeads.empty()) return true; // We're already in a consistent state. if (hashHeads.empty()) return true; // We're already in a consistent state.
if (hashHeads.size() != 2) return error("ReplayBlocks(): unknown inconsistent state"); if (hashHeads.size() != 2) return error("ReplayBlocks(): unknown inconsistent state");
uiInterface.ShowProgress(_("Replaying blocks..."), 0); uiInterface.ShowProgress(_("Replaying blocks..."), 0, false);
LogPrintf("Replaying blocks\n"); LogPrintf("Replaying blocks\n");
const CBlockIndex* pindexOld = nullptr; // Old tip during the interrupted flush. const CBlockIndex* pindexOld = nullptr; // Old tip during the interrupted flush.
@ -3747,7 +3747,7 @@ bool ReplayBlocks(const CChainParams& params, CCoinsView* view)
cache.SetBestBlock(pindexNew->GetBlockHash()); cache.SetBestBlock(pindexNew->GetBlockHash());
cache.Flush(); cache.Flush();
uiInterface.ShowProgress("", 100); uiInterface.ShowProgress("", 100, false);
return true; return true;
} }

Loading…
Cancel
Save