WriteWitnessCache: Catch errors and abort transaction

Closes #1456
This commit is contained in:
Jack Grigg 2016-10-05 09:49:43 -05:00
parent 17b23ffe20
commit 6216b4b2dc
No known key found for this signature in database
GPG Key ID: 6A6914DAFBEA00DA
1 changed files with 14 additions and 6 deletions

View File

@ -730,15 +730,23 @@ void CWallet::WriteWitnessCache() {
LogPrintf("WriteWitnessCache(): Couldn't start atomic write\n");
return;
}
for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) {
if (!walletdb.WriteTx(wtxItem.first, wtxItem.second)) {
LogPrintf("WriteWitnessCache(): Failed to write CWalletTx, aborting atomic write\n");
try {
for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) {
if (!walletdb.WriteTx(wtxItem.first, wtxItem.second)) {
LogPrintf("WriteWitnessCache(): Failed to write CWalletTx, aborting atomic write\n");
walletdb.TxnAbort();
return;
}
}
if (!walletdb.WriteWitnessCacheSize(nWitnessCacheSize)) {
LogPrintf("WriteWitnessCache(): Failed to write nWitnessCacheSize, aborting atomic write\n");
walletdb.TxnAbort();
return;
}
}
if (!walletdb.WriteWitnessCacheSize(nWitnessCacheSize)) {
LogPrintf("WriteWitnessCache(): Failed to write nWitnessCacheSize, aborting atomic write\n");
} catch (const std::exception &exc) {
// Unexpected failure
LogPrintf("WriteWitnessCache(): Unexpected error during atomic write:\n");
LogPrintf("%s\n", exc.what());
walletdb.TxnAbort();
return;
}