Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/walletdb.cpp
Show First 20 Lines • Show All 539 Lines • ▼ Show 20 Lines | try { | ||||
return DBErrors::TOO_NEW; | return DBErrors::TOO_NEW; | ||||
} | } | ||||
pwallet->LoadMinVersion(nMinVersion); | pwallet->LoadMinVersion(nMinVersion); | ||||
} | } | ||||
// Get cursor | // Get cursor | ||||
Dbc *pcursor = m_batch.GetCursor(); | Dbc *pcursor = m_batch.GetCursor(); | ||||
if (!pcursor) { | if (!pcursor) { | ||||
LogPrintf("Error getting wallet database cursor\n"); | pwallet->WalletLogPrintf("Error getting wallet database cursor\n"); | ||||
return DBErrors::CORRUPT; | return DBErrors::CORRUPT; | ||||
} | } | ||||
while (true) { | while (true) { | ||||
// Read next record | // Read next record | ||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION); | CDataStream ssKey(SER_DISK, CLIENT_VERSION); | ||||
CDataStream ssValue(SER_DISK, CLIENT_VERSION); | CDataStream ssValue(SER_DISK, CLIENT_VERSION); | ||||
int ret = m_batch.ReadAtCursor(pcursor, ssKey, ssValue); | int ret = m_batch.ReadAtCursor(pcursor, ssKey, ssValue); | ||||
if (ret == DB_NOTFOUND) { | if (ret == DB_NOTFOUND) { | ||||
break; | break; | ||||
} | } | ||||
if (ret != 0) { | if (ret != 0) { | ||||
LogPrintf("Error reading next record from wallet database\n"); | pwallet->WalletLogPrintf( | ||||
"Error reading next record from wallet database\n"); | |||||
return DBErrors::CORRUPT; | return DBErrors::CORRUPT; | ||||
} | } | ||||
// Try to be tolerant of single corrupt records: | // Try to be tolerant of single corrupt records: | ||||
std::string strType, strErr; | std::string strType, strErr; | ||||
if (!ReadKeyValue(pwallet, ssKey, ssValue, wss, strType, strErr)) { | if (!ReadKeyValue(pwallet, ssKey, ssValue, wss, strType, strErr)) { | ||||
// losing keys is considered a catastrophic error, anything else | // losing keys is considered a catastrophic error, anything else | ||||
// we assume the user can live with: | // we assume the user can live with: | ||||
Show All 10 Lines | try { | ||||
fNoncriticalErrors = true; | fNoncriticalErrors = true; | ||||
if (strType == "tx") { | if (strType == "tx") { | ||||
// Rescan if there is a bad transaction record: | // Rescan if there is a bad transaction record: | ||||
gArgs.SoftSetBoolArg("-rescan", true); | gArgs.SoftSetBoolArg("-rescan", true); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (!strErr.empty()) { | if (!strErr.empty()) { | ||||
LogPrintf("%s\n", strErr); | pwallet->WalletLogPrintf("%s\n", strErr); | ||||
} | } | ||||
} | } | ||||
pcursor->close(); | pcursor->close(); | ||||
} catch (const boost::thread_interrupted &) { | } catch (const boost::thread_interrupted &) { | ||||
throw; | throw; | ||||
} catch (...) { | } catch (...) { | ||||
result = DBErrors::CORRUPT; | result = DBErrors::CORRUPT; | ||||
} | } | ||||
if (fNoncriticalErrors && result == DBErrors::LOAD_OK) { | if (fNoncriticalErrors && result == DBErrors::LOAD_OK) { | ||||
result = DBErrors::NONCRITICAL_ERROR; | result = DBErrors::NONCRITICAL_ERROR; | ||||
} | } | ||||
// Any wallet corruption at all: skip any rewriting or upgrading, we don't | // Any wallet corruption at all: skip any rewriting or upgrading, we don't | ||||
// want to make it worse. | // want to make it worse. | ||||
if (result != DBErrors::LOAD_OK) { | if (result != DBErrors::LOAD_OK) { | ||||
return result; | return result; | ||||
} | } | ||||
LogPrintf("nFileVersion = %d\n", wss.nFileVersion); | pwallet->WalletLogPrintf("nFileVersion = %d\n", wss.nFileVersion); | ||||
LogPrintf("Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total. " | pwallet->WalletLogPrintf("Keys: %u plaintext, %u encrypted, %u w/ " | ||||
"Unknown wallet records: %u\n", | "metadata, %u total. Unknown wallet records: %u\n", | ||||
wss.nKeys, wss.nCKeys, wss.nKeyMeta, wss.nKeys + wss.nCKeys, | wss.nKeys, wss.nCKeys, wss.nKeyMeta, | ||||
wss.m_unknown_records); | wss.nKeys + wss.nCKeys, wss.m_unknown_records); | ||||
// nTimeFirstKey is only reliable if all keys have metadata | // nTimeFirstKey is only reliable if all keys have metadata | ||||
if ((wss.nKeys + wss.nCKeys + wss.nWatchKeys) != wss.nKeyMeta) { | if ((wss.nKeys + wss.nCKeys + wss.nWatchKeys) != wss.nKeyMeta) { | ||||
pwallet->UpdateTimeFirstKey(1); | pwallet->UpdateTimeFirstKey(1); | ||||
} | } | ||||
for (const TxId &txid : wss.vWalletUpgrade) { | for (const TxId &txid : wss.vWalletUpgrade) { | ||||
WriteTx(pwallet->mapWallet.at(txid)); | WriteTx(pwallet->mapWallet.at(txid)); | ||||
▲ Show 20 Lines • Show All 279 Lines • Show Last 20 Lines |