From 0c2487c4271eaf80286478cb21ad8754ec281f0a Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 18 Jul 2022 10:43:22 -0400 Subject: [PATCH] Throw error in wallet if ReadBlockFromDisk fails --- src/wallet/wallet.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 8d12d903a..bda0140f0 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1032,7 +1032,10 @@ int CWallet::VerifyAndSetInitialWitness(const CBlockIndex* pindex, bool witnessO //Cycle through blocks and transactions building sapling tree until the commitment needed is reached const CBlock* pblock; CBlock block; - ReadBlockFromDisk(block, pblockindex, 1); + if (!ReadBlockFromDisk(block, pblockindex, 1)) { + throw std::runtime_error( + strprintf("Cannot read block height %d (%s) from disk", pindex->GetHeight(), pindex->GetBlockHash().GetHex())); + } pblock = █ for (const CTransaction& tx : block.vtx) { @@ -1102,7 +1105,10 @@ void CWallet::BuildWitnessCache(const CBlockIndex* pindex, bool witnessOnly) //Cycle through blocks and transactions building sapling tree until the commitment needed is reached CBlock block; - ReadBlockFromDisk(block, pblockindex, 1); + if (!ReadBlockFromDisk(block, pblockindex, 1)) { + throw std::runtime_error( + strprintf("Cannot read block height %d (%s) from disk", pindex->GetHeight(), pindex->GetBlockHash().GetHex())); + } for (std::pair& wtxItem : mapWallet) { @@ -2721,7 +2727,11 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) CBlock block; bool involvesMe = false; - ReadBlockFromDisk(block, pindex,1); + if (!ReadBlockFromDisk(block, pindex,1)) { + throw std::runtime_error( + strprintf("Cannot read block height %d (%s) from disk", pindex->GetHeight(), pindex->GetBlockHash().GetHex())); + } + BOOST_FOREACH(CTransaction& tx, block.vtx) { if (AddToWalletIfInvolvingMe(tx, &block, fUpdate)) {