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,6 +730,7 @@ void CWallet::WriteWitnessCache() {
LogPrintf("WriteWitnessCache(): Couldn't start atomic write\n"); LogPrintf("WriteWitnessCache(): Couldn't start atomic write\n");
return; return;
} }
try {
for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) { for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) {
if (!walletdb.WriteTx(wtxItem.first, wtxItem.second)) { if (!walletdb.WriteTx(wtxItem.first, wtxItem.second)) {
LogPrintf("WriteWitnessCache(): Failed to write CWalletTx, aborting atomic write\n"); LogPrintf("WriteWitnessCache(): Failed to write CWalletTx, aborting atomic write\n");
@ -742,6 +743,13 @@ void CWallet::WriteWitnessCache() {
walletdb.TxnAbort(); walletdb.TxnAbort();
return; return;
} }
} catch (const std::exception &exc) {
// Unexpected failure
LogPrintf("WriteWitnessCache(): Unexpected error during atomic write:\n");
LogPrintf("%s\n", exc.what());
walletdb.TxnAbort();
return;
}
if (!walletdb.TxnCommit()) { if (!walletdb.TxnCommit()) {
// Couldn't commit all to db, but in-memory state is fine // Couldn't commit all to db, but in-memory state is fine
LogPrintf("WriteWitnessCache(): Couldn't commit atomic write\n"); LogPrintf("WriteWitnessCache(): Couldn't commit atomic write\n");