mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
Fix importmulti failure to return rescan errors
An off-by-one-block bug in importmulti rescan logic could cause it to return success in an edge case even when a rescan was not successful. The case where this would happen is if there were multiple blocks in a row with the same GetBlockTimeMax() value, and the last block was scanned successfully, but one or more of the earlier blocks was not readable.
This commit is contained in:
@@ -1456,10 +1456,9 @@ void CWalletTx::GetAmounts(std::list<COutputEntry>& listReceived,
|
||||
* from or to us. If fUpdate is true, found transactions that already
|
||||
* exist in the wallet will be updated.
|
||||
*
|
||||
* Returns pointer to the first block in the last contiguous range that was
|
||||
* successfully scanned or elided (elided if pIndexStart points at a block
|
||||
* before CWallet::nTimeFirstKey). Returns null if there is no such range, or
|
||||
* the range doesn't include chainActive.Tip().
|
||||
* Returns null if scan was successful. Otherwise, if a complete rescan was not
|
||||
* possible (due to pruning or corruption), returns pointer to the most recent
|
||||
* block that could not be scanned.
|
||||
*/
|
||||
CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
||||
{
|
||||
@@ -1467,7 +1466,7 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool f
|
||||
const CChainParams& chainParams = Params();
|
||||
|
||||
CBlockIndex* pindex = pindexStart;
|
||||
CBlockIndex* ret = pindexStart;
|
||||
CBlockIndex* ret = nullptr;
|
||||
{
|
||||
LOCK2(cs_main, cs_wallet);
|
||||
fAbortRescan = false;
|
||||
@@ -1495,11 +1494,8 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool f
|
||||
for (size_t posInBlock = 0; posInBlock < block.vtx.size(); ++posInBlock) {
|
||||
AddToWalletIfInvolvingMe(block.vtx[posInBlock], pindex, posInBlock, fUpdate);
|
||||
}
|
||||
if (!ret) {
|
||||
ret = pindex;
|
||||
}
|
||||
} else {
|
||||
ret = nullptr;
|
||||
ret = pindex;
|
||||
}
|
||||
pindex = chainActive.Next(pindex);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user