Skip to content

Commit ee4d149

Browse files
committed
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().
1 parent 22e301a commit ee4d149

File tree

5 files changed

+25
-39
lines changed

5 files changed

+25
-39
lines changed

src/qt/splashscreen.cpp

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ SplashScreen::~SplashScreen()
142142
bool SplashScreen::eventFilter(QObject * obj, QEvent * ev) {
143143
if (ev->type() == QEvent::KeyPress) {
144144
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev);
145-
if(keyEvent->text()[0] == 'q' && breakAction != nullptr) {
146-
breakAction();
145+
if(keyEvent->text()[0] == 'q') {
146+
StartShutdown();
147147
}
148148
}
149149
return QObject::eventFilter(obj, ev);
@@ -170,27 +170,18 @@ static void InitMessage(SplashScreen *splash, const std::string &message)
170170
Q_ARG(QColor, QColor(55,55,55)));
171171
}
172172

173-
static void ShowProgress(SplashScreen *splash, const std::string &title, int nProgress)
173+
static void ShowProgress(SplashScreen *splash, const std::string &title, int nProgress, bool resume_possible)
174174
{
175-
InitMessage(splash, title + strprintf("%d", nProgress) + "%");
176-
}
177-
178-
void SplashScreen::setBreakAction(const std::function<void(void)> &action)
179-
{
180-
breakAction = action;
181-
}
182-
183-
static void SetProgressBreakAction(SplashScreen *splash, const std::function<void(void)> &action)
184-
{
185-
QMetaObject::invokeMethod(splash, "setBreakAction",
186-
Qt::QueuedConnection,
187-
Q_ARG(std::function<void(void)>, action));
175+
InitMessage(splash, title + std::string("\n") +
176+
(resume_possible ? _("(press q to shutdown and continue later)")
177+
: _("press q to shutdown")) +
178+
strprintf("\n%d", nProgress) + "%");
188179
}
189180

190181
#ifdef ENABLE_WALLET
191182
void SplashScreen::ConnectWallet(CWallet* wallet)
192183
{
193-
wallet->ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2));
184+
wallet->ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2, false));
194185
connectedWallets.push_back(wallet);
195186
}
196187
#endif
@@ -199,8 +190,7 @@ void SplashScreen::subscribeToCoreSignals()
199190
{
200191
// Connect signals to client
201192
uiInterface.InitMessage.connect(boost::bind(InitMessage, this, _1));
202-
uiInterface.ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2));
203-
uiInterface.SetProgressBreakAction.connect(boost::bind(SetProgressBreakAction, this, _1));
193+
uiInterface.ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2, _3));
204194
#ifdef ENABLE_WALLET
205195
uiInterface.LoadWallet.connect(boost::bind(&SplashScreen::ConnectWallet, this, _1));
206196
#endif
@@ -210,10 +200,10 @@ void SplashScreen::unsubscribeFromCoreSignals()
210200
{
211201
// Disconnect signals from client
212202
uiInterface.InitMessage.disconnect(boost::bind(InitMessage, this, _1));
213-
uiInterface.ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
203+
uiInterface.ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2, _3));
214204
#ifdef ENABLE_WALLET
215205
for (CWallet* const & pwallet : connectedWallets) {
216-
pwallet->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
206+
pwallet->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2, false));
217207
}
218208
#endif
219209
}

src/qt/splashscreen.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ public Q_SLOTS:
3636
/** Show message and progress */
3737
void showMessage(const QString &message, int alignment, const QColor &color);
3838

39-
/** Sets the break action */
40-
void setBreakAction(const std::function<void(void)> &action);
4139
protected:
4240
bool eventFilter(QObject * obj, QEvent * ev);
4341

@@ -55,8 +53,6 @@ public Q_SLOTS:
5553
int curAlignment;
5654

5755
QList<CWallet*> connectedWallets;
58-
59-
std::function<void(void)> breakAction;
6056
};
6157

6258
#endif // BITCOIN_QT_SPLASHSCREEN_H

src/txdb.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,9 @@ bool CCoinsViewDB::Upgrade() {
371371
int64_t count = 0;
372372
LogPrintf("Upgrading utxo-set database...\n");
373373
LogPrintf("[0%%]...");
374+
uiInterface.ShowProgress(_("Upgrading UTXO database"), 0, true);
374375
size_t batch_size = 1 << 24;
375376
CDBBatch batch(db);
376-
uiInterface.SetProgressBreakAction(StartShutdown);
377377
int reportDone = 0;
378378
std::pair<unsigned char, uint256> key;
379379
std::pair<unsigned char, uint256> prev_key = {DB_COINS, uint256()};
@@ -386,7 +386,7 @@ bool CCoinsViewDB::Upgrade() {
386386
if (count++ % 256 == 0) {
387387
uint32_t high = 0x100 * *key.second.begin() + *(key.second.begin() + 1);
388388
int percentageDone = (int)(high * 100.0 / 65536.0 + 0.5);
389-
uiInterface.ShowProgress(_("Upgrading UTXO database") + "\n"+ _("(press q to shutdown and continue later)") + "\n", percentageDone);
389+
uiInterface.ShowProgress(_("Upgrading UTXO database"), percentageDone, true);
390390
if (reportDone < percentageDone/10) {
391391
// report max. every 10% step
392392
LogPrintf("[%d%%]...", percentageDone);
@@ -420,7 +420,7 @@ bool CCoinsViewDB::Upgrade() {
420420
}
421421
db.WriteBatch(batch);
422422
db.CompactRange({DB_COINS, uint256()}, key);
423-
uiInterface.SetProgressBreakAction(std::function<void(void)>());
423+
uiInterface.ShowProgress("", 100, false);
424424
LogPrintf("[%s].\n", ShutdownRequested() ? "CANCELLED" : "DONE");
425425
return !ShutdownRequested();
426426
}

src/ui_interface.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ class CClientUIInterface
9494
/** A wallet has been loaded. */
9595
boost::signals2::signal<void (CWallet* wallet)> LoadWallet;
9696

97-
/** Show progress e.g. for verifychain */
98-
boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
99-
100-
/** Set progress break action (possible "cancel button" triggers that action) */
101-
boost::signals2::signal<void (std::function<void(void)> action)> SetProgressBreakAction;
97+
/**
98+
* Show progress e.g. for verifychain.
99+
* resume_possible indicates shutting down now will result in the current progress action resuming upon restart.
100+
*/
101+
boost::signals2::signal<void (const std::string &title, int nProgress, bool resume_possible)> ShowProgress;
102102

103103
/** New block has been accepted */
104104
boost::signals2::signal<void (bool, const CBlockIndex *)> NotifyBlockTip;

src/validation.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3563,12 +3563,12 @@ bool LoadChainTip(const CChainParams& chainparams)
35633563

35643564
CVerifyDB::CVerifyDB()
35653565
{
3566-
uiInterface.ShowProgress(_("Verifying blocks..."), 0);
3566+
uiInterface.ShowProgress(_("Verifying blocks..."), 0, false);
35673567
}
35683568

35693569
CVerifyDB::~CVerifyDB()
35703570
{
3571-
uiInterface.ShowProgress("", 100);
3571+
uiInterface.ShowProgress("", 100, false);
35723572
}
35733573

35743574
bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
@@ -3598,7 +3598,7 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
35983598
LogPrintf("[%d%%]...", percentageDone);
35993599
reportDone = percentageDone/10;
36003600
}
3601-
uiInterface.ShowProgress(_("Verifying blocks..."), percentageDone);
3601+
uiInterface.ShowProgress(_("Verifying blocks..."), percentageDone, false);
36023602
if (pindex->nHeight < chainActive.Height()-nCheckDepth)
36033603
break;
36043604
if (fPruneMode && !(pindex->nStatus & BLOCK_HAVE_DATA)) {
@@ -3649,7 +3649,7 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
36493649
CBlockIndex *pindex = pindexState;
36503650
while (pindex != chainActive.Tip()) {
36513651
boost::this_thread::interruption_point();
3652-
uiInterface.ShowProgress(_("Verifying blocks..."), std::max(1, std::min(99, 100 - (int)(((double)(chainActive.Height() - pindex->nHeight)) / (double)nCheckDepth * 50))));
3652+
uiInterface.ShowProgress(_("Verifying blocks..."), std::max(1, std::min(99, 100 - (int)(((double)(chainActive.Height() - pindex->nHeight)) / (double)nCheckDepth * 50))), false);
36533653
pindex = chainActive.Next(pindex);
36543654
CBlock block;
36553655
if (!ReadBlockFromDisk(block, pindex, chainparams.GetConsensus()))
@@ -3696,7 +3696,7 @@ bool ReplayBlocks(const CChainParams& params, CCoinsView* view)
36963696
if (hashHeads.empty()) return true; // We're already in a consistent state.
36973697
if (hashHeads.size() != 2) return error("ReplayBlocks(): unknown inconsistent state");
36983698

3699-
uiInterface.ShowProgress(_("Replaying blocks..."), 0);
3699+
uiInterface.ShowProgress(_("Replaying blocks..."), 0, false);
37003700
LogPrintf("Replaying blocks\n");
37013701

37023702
const CBlockIndex* pindexOld = nullptr; // Old tip during the interrupted flush.
@@ -3747,7 +3747,7 @@ bool ReplayBlocks(const CChainParams& params, CCoinsView* view)
37473747

37483748
cache.SetBestBlock(pindexNew->GetBlockHash());
37493749
cache.Flush();
3750-
uiInterface.ShowProgress("", 100);
3750+
uiInterface.ShowProgress("", 100, false);
37513751
return true;
37523752
}
37533753

0 commit comments

Comments
 (0)