Changeset View
Changeset View
Standalone View
Standalone View
src/txdb.cpp
Show First 20 Lines • Show All 385 Lines • ▼ Show 20 Lines | bool CCoinsViewDB::Upgrade() { | ||||
pcursor->Seek(std::make_pair(DB_COINS, uint256())); | pcursor->Seek(std::make_pair(DB_COINS, uint256())); | ||||
if (!pcursor->Valid()) { | if (!pcursor->Valid()) { | ||||
return true; | return true; | ||||
} | } | ||||
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<uint8_t, uint256> key; | std::pair<uint8_t, uint256> key; | ||||
std::pair<uint8_t, uint256> prev_key = {DB_COINS, uint256()}; | std::pair<uint8_t, uint256> prev_key = {DB_COINS, uint256()}; | ||||
while (pcursor->Valid()) { | while (pcursor->Valid()) { | ||||
boost::this_thread::interruption_point(); | boost::this_thread::interruption_point(); | ||||
if (ShutdownRequested()) { | if (ShutdownRequested()) { | ||||
break; | break; | ||||
} | } | ||||
if (!pcursor->GetKey(key) || key.first != DB_COINS) { | if (!pcursor->GetKey(key) || key.first != DB_COINS) { | ||||
break; | break; | ||||
} | } | ||||
if (count++ % 256 == 0) { | if (count++ % 256 == 0) { | ||||
uint32_t high = | uint32_t high = | ||||
0x100 * *key.second.begin() + *(key.second.begin() + 1); | 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( | uiInterface.ShowProgress(_("Upgrading UTXO database"), | ||||
_("Upgrading UTXO database") + "\n" + | percentageDone, true); | ||||
_("(press q to shutdown and continue later)") + "\n", | |||||
percentageDone); | |||||
if (reportDone < percentageDone / 10) { | if (reportDone < percentageDone / 10) { | ||||
// report max. every 10% step | // report max. every 10% step | ||||
LogPrintf("[%d%%]...", percentageDone); | LogPrintf("[%d%%]...", percentageDone); | ||||
reportDone = percentageDone / 10; | reportDone = percentageDone / 10; | ||||
} | } | ||||
} | } | ||||
CCoins old_coins; | CCoins old_coins; | ||||
Show All 21 Lines | while (pcursor->Valid()) { | ||||
prev_key = key; | prev_key = key; | ||||
} | } | ||||
pcursor->Next(); | pcursor->Next(); | ||||
} | } | ||||
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(); | ||||
} | } |