Skip to content

Commit 316fcb5

Browse files
committed
Allow to cancel the txdb upgrade via splashscreen callback
1 parent ae09d45 commit 316fcb5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/txdb.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "pow.h"
1212
#include "uint256.h"
1313
#include "util.h"
14+
#include "ui_interface.h"
15+
#include "init.h"
1416

1517
#include <stdint.h>
1618

@@ -366,16 +368,22 @@ bool CCoinsViewDB::Upgrade() {
366368
return true;
367369
}
368370

371+
int64_t count = 0;
369372
LogPrintf("Upgrading database...\n");
370373
size_t batch_size = 1 << 24;
371374
CDBBatch batch(db);
375+
uiInterface.SetProgressBreakAction(StartShutdown);
372376
while (pcursor->Valid()) {
373377
boost::this_thread::interruption_point();
374378
if (ShutdownRequested()) {
375379
break;
376380
}
377381
std::pair<unsigned char, uint256> key;
378382
if (pcursor->GetKey(key) && key.first == DB_COINS) {
383+
if (count++ % 256 == 0) {
384+
uint32_t high = 0x100 * *key.second.begin() + *(key.second.begin() + 1);
385+
uiInterface.ShowProgress(_("Upgrading UTXO database") + "\n"+ _("(press q to shutdown and continue later)") + "\n", (int)(high * 100.0 / 65536.0 + 0.5));
386+
}
379387
CCoins old_coins;
380388
if (!pcursor->GetValue(old_coins)) {
381389
return error("%s: cannot parse CCoins record", __func__);
@@ -400,5 +408,6 @@ bool CCoinsViewDB::Upgrade() {
400408
}
401409
}
402410
db.WriteBatch(batch);
411+
uiInterface.SetProgressBreakAction(std::function<void(void)>());
403412
return true;
404413
}

0 commit comments

Comments
 (0)