Skip to content

Commit f90fa08

Browse files
committed
wallet: Ignore MarkConflict if block hash is not known
>>> backports bitcoin/bitcoin@40e7b61 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 bitcoin#7234.
1 parent 6298035 commit f90fa08

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/wallet/wallet.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,14 +1012,20 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx)
10121012
{
10131013
LOCK2(cs_main, cs_wallet);
10141014

1015-
CBlockIndex* pindex;
1016-
assert(mapBlockIndex.count(hashBlock));
1017-
pindex = mapBlockIndex[hashBlock];
10181015
int conflictconfirms = 0;
1019-
if (chainActive.Contains(pindex)) {
1020-
conflictconfirms = -(chainActive.Height() - pindex->nHeight + 1);
1016+
if (mapBlockIndex.count(hashBlock)) {
1017+
CBlockIndex* pindex = mapBlockIndex[hashBlock];
1018+
if (chainActive.Contains(pindex)) {
1019+
conflictconfirms = -(chainActive.Height() - pindex->nHeight + 1);
1020+
}
10211021
}
1022-
assert(conflictconfirms < 0);
1022+
1023+
// If number of conflict confirms cannot be determined, this means
1024+
// that the block is still unknown or not yet part of the main chain,
1025+
// for example when loading the wallet during a reindex. Do nothing in that
1026+
// case.
1027+
if (conflictconfirms >= 0)
1028+
return;
10231029

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

0 commit comments

Comments
 (0)