You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
wallet: mempool replay can deliver a child before its parent and miss the spend #8208
When the wallet reads the mempool, it can record an unconfirmed payment to itself but miss the unconfirmed transaction that spends it. The spent output then shows as unspent until the spend is mined.
ChainImpl::requestMempoolTransactions() in src/node/interfaces.cpp walks mapTx through its default index, which is hashed by txid, so a child can be delivered before its parent:
for (const CTxMemPoolEntry& entry : m_node.mempool->mapTx) {
notifications.transactionAddedToMempool(entry.GetSharedTx(), /*nAcceptTime=*/0);
}
If the child pays only external addresses, the wallet does not recognise it when it arrives first: none of its outputs are ours, and its input is not known to be ours until the parent is in mapWallet. Nothing revisits the child after the parent is added.
This is reached on every path that replays the mempool:
wallet load (CWallet::postInitProcess());
any rescan without an end height (ScanForWalletTransactions(), used by rescanblockchain, importdescriptors and the wallet interface's rescans).
How to reproduce
Have two wallets from the same seed, or one wallet that is unloaded for step 2.
With wallet A not loaded, receive an unconfirmed payment to one of its addresses, and spend that output with wallet B to an external address. Keep both transactions in the mempool.
Load wallet A (or rescan it).
Depending on the two txids, wallet A lists the payment as an unspent output although the mempool already spends it.
Fix
Bitcoin Core fixed the order in bitcoin#28391: requestMempoolTransactions() iterates CTxMemPool::entryAll(), which returns entries sorted by ancestor count, parents first. bitcoin#29179 added the regression tests (wallet_rescan_unconfirmed.py and a case in wallet_import_rescan.py: a parent with an IsFromMe child in the mempool), and bitcoin#29019, which would have removed the sorting, was closed for this reason.
Activity
Merge dashpay#8209: backport: bitcoin#28391, bitcoin#29179, bitcoin#2…