Changeset View
Changeset View
Standalone View
Standalone View
src/txdb.cpp
Show First 20 Lines • Show All 337 Lines • ▼ Show 20 Lines | 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%%]..."); | ||||
size_t batch_size = 1 << 24; | size_t batch_size = 1 << 24; | ||||
CDBBatch batch(db); | CDBBatch batch(db); | ||||
uiInterface.SetProgressBreakAction(StartShutdown); | uiInterface.SetProgressBreakAction(StartShutdown); | ||||
int reportDone = 0; | int reportDone = 0; | ||||
std::pair<uint8_t, uint256> key; | |||||
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; | ||||
} | } | ||||
std::pair<uint8_t, uint256> key; | |||||
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); | ||||
Show All 24 Lines | while (pcursor->Valid()) { | ||||
batch.Write(entry, newcoin); | batch.Write(entry, newcoin); | ||||
} | } | ||||
} | } | ||||
batch.Erase(key); | batch.Erase(key); | ||||
if (batch.SizeEstimate() > batch_size) { | if (batch.SizeEstimate() > batch_size) { | ||||
db.WriteBatch(batch); | db.WriteBatch(batch); | ||||
batch.Clear(); | batch.Clear(); | ||||
db.CompactRange(prev_key, key); | |||||
prev_key = key; | |||||
} | } | ||||
pcursor->Next(); | pcursor->Next(); | ||||
} | } | ||||
db.WriteBatch(batch); | db.WriteBatch(batch); | ||||
db.CompactRange({DB_COINS, uint256()}, key); | |||||
uiInterface.SetProgressBreakAction(std::function<void(void)>()); | uiInterface.SetProgressBreakAction(std::function<void(void)>()); | ||||
LogPrintf("[%s].\n", ShutdownRequested() ? "CANCELLED" : "DONE"); | LogPrintf("[%s].\n", ShutdownRequested() ? "CANCELLED" : "DONE"); | ||||
return !ShutdownRequested(); | return !ShutdownRequested(); | ||||
} | } |