Browse Source

Merge pull request #1295 from jgarzik/txn-retval

[FIX] Always check return values of TxnBegin() and TxnCommit()
try
Jeff Garzik 13 years ago
parent
commit
cf2f7c30a3
  1. 6
      src/bitcoinrpc.cpp
  2. 12
      src/main.cpp
  3. 3
      src/wallet.cpp

6
src/bitcoinrpc.cpp

@ -1037,7 +1037,8 @@ Value movecmd(const Array& params, bool fHelp)
strComment = params[4].get_str(); strComment = params[4].get_str();
CWalletDB walletdb(pwalletMain->strWalletFile); CWalletDB walletdb(pwalletMain->strWalletFile);
walletdb.TxnBegin(); if (!walletdb.TxnBegin())
throw JSONRPCError(-20, "database error");
int64 nNow = GetAdjustedTime(); int64 nNow = GetAdjustedTime();
@ -1059,7 +1060,8 @@ Value movecmd(const Array& params, bool fHelp)
credit.strComment = strComment; credit.strComment = strComment;
walletdb.WriteAccountingEntry(credit); walletdb.WriteAccountingEntry(credit);
walletdb.TxnCommit(); if (!walletdb.TxnCommit())
throw JSONRPCError(-20, "database error");
return true; return true;
} }

12
src/main.cpp

@ -1514,7 +1514,9 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew)
{ {
uint256 hash = GetHash(); uint256 hash = GetHash();
txdb.TxnBegin(); if (!txdb.TxnBegin())
return error("SetBestChain() : TxnBegin failed");
if (pindexGenesisBlock == NULL && hash == hashGenesisBlock) if (pindexGenesisBlock == NULL && hash == hashGenesisBlock)
{ {
txdb.WriteHashBestChain(hash); txdb.WriteHashBestChain(hash);
@ -1563,7 +1565,10 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew)
printf("SetBestChain() : ReadFromDisk failed\n"); printf("SetBestChain() : ReadFromDisk failed\n");
break; break;
} }
txdb.TxnBegin(); if (!txdb.TxnBegin()) {
printf("SetBestChain() : TxnBegin 2 failed\n");
break;
}
// errors now are not fatal, we still did a reorganisation to a new chain in a valid way // errors now are not fatal, we still did a reorganisation to a new chain in a valid way
if (!block.SetBestChainInner(txdb, pindex)) if (!block.SetBestChainInner(txdb, pindex))
break; break;
@ -1621,7 +1626,8 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos)
pindexNew->bnChainWork = (pindexNew->pprev ? pindexNew->pprev->bnChainWork : 0) + pindexNew->GetBlockWork(); pindexNew->bnChainWork = (pindexNew->pprev ? pindexNew->pprev->bnChainWork : 0) + pindexNew->GetBlockWork();
CTxDB txdb; CTxDB txdb;
txdb.TxnBegin(); if (!txdb.TxnBegin())
return false;
txdb.WriteBlockIndex(CDiskBlockIndex(pindexNew)); txdb.WriteBlockIndex(CDiskBlockIndex(pindexNew));
if (!txdb.TxnCommit()) if (!txdb.TxnCommit())
return false; return false;

3
src/wallet.cpp

@ -242,7 +242,8 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
if (fFileBacked) if (fFileBacked)
{ {
pwalletdbEncryption = new CWalletDB(strWalletFile); pwalletdbEncryption = new CWalletDB(strWalletFile);
pwalletdbEncryption->TxnBegin(); if (!pwalletdbEncryption->TxnBegin())
return false;
pwalletdbEncryption->WriteMasterKey(nMasterKeyMaxID, kMasterKey); pwalletdbEncryption->WriteMasterKey(nMasterKeyMaxID, kMasterKey);
} }

Loading…
Cancel
Save