Skip to content

Commit 00ec73e

Browse files
committed
wallet: Ignore MarkConflict if block hash is not known
If number of conflict confirms cannot be determined, this means that the block is still unknown or not yet part of the main chain, for example during a reindex. Do nothing in that case, instead of crash with an assertion. Fixes #7234. Github-Pull: #7491 Rebased-From: 40e7b61
1 parent 827a2b6 commit 00ec73e

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/wallet/wallet.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -847,14 +847,19 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx)
847847
{
848848
LOCK2(cs_main, cs_wallet);
849849

850-
CBlockIndex* pindex;
851-
assert(mapBlockIndex.count(hashBlock));
852-
pindex = mapBlockIndex[hashBlock];
853850
int conflictconfirms = 0;
854-
if (chainActive.Contains(pindex)) {
855-
conflictconfirms = -(chainActive.Height() - pindex->nHeight + 1);
851+
if (mapBlockIndex.count(hashBlock)) {
852+
CBlockIndex* pindex = mapBlockIndex[hashBlock];
853+
if (chainActive.Contains(pindex)) {
854+
conflictconfirms = -(chainActive.Height() - pindex->nHeight + 1);
855+
}
856856
}
857-
assert(conflictconfirms < 0);
857+
// If number of conflict confirms cannot be determined, this means
858+
// that the block is still unknown or not yet part of the main chain,
859+
// for example when loading the wallet during a reindex. Do nothing in that
860+
// case.
861+
if (conflictconfirms >= 0)
862+
return;
858863

859864
// Do not flush the wallet here for performance reasons
860865
CWalletDB walletdb(strWalletFile, "r+", false);

0 commit comments

Comments
 (0)