Changeset View
Changeset View
Standalone View
Standalone View
src/txdb.cpp
Show First 20 Lines • Show All 372 Lines • ▼ Show 20 Lines | bool CCoinsViewDB::Upgrade() { | ||||
std::unique_ptr<CDBIterator> pcursor(db.NewIterator()); | std::unique_ptr<CDBIterator> pcursor(db.NewIterator()); | ||||
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%%]..."); | LogPrintfToBeContinued("[0%%]..."); | ||||
uiInterface.ShowProgress(_("Upgrading UTXO database"), 0, true); | 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); | ||||
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(_("Upgrading UTXO database"), | uiInterface.ShowProgress(_("Upgrading UTXO database"), | ||||
percentageDone, true); | percentageDone, true); | ||||
if (reportDone < percentageDone / 10) { | if (reportDone < percentageDone / 10) { | ||||
// report max. every 10% step | // report max. every 10% step | ||||
LogPrintf("[%d%%]...", percentageDone); | LogPrintfToBeContinued("[%d%%]...", percentageDone); | ||||
reportDone = percentageDone / 10; | reportDone = percentageDone / 10; | ||||
} | } | ||||
} | } | ||||
CCoins old_coins; | CCoins old_coins; | ||||
if (!pcursor->GetValue(old_coins)) { | if (!pcursor->GetValue(old_coins)) { | ||||
return error("%s: cannot parse CCoins record", __func__); | return error("%s: cannot parse CCoins record", __func__); | ||||
} | } | ||||
Show All 30 Lines |