Tracking issue (https://github.com/bitcoin/bitcoin/issues/29901)
this add fuzz target for wallet receive…
Also, for block height handling for unknown heights
Allowing -1 for conflicting_block_height in TxStateBlockConflicted which is a valid state when deserializing old wallet data where block heights weren’t stored. This helps sorting an assertion failure that would occur when GetTxDepthInMainChain() encounters transactions with unknown conflicting block heights.
discovered that GetTxDepthInMainChain() would crash with assert(conf->conflicting_block_height >= 0) when handling transactions with -1 (unknown height), even though this is used elsewhere in the codebase.
Code inconsistency here below:
In src/wallet/transaction.h:94, -1 is used for unknown heights:
0} else if (data.index == -1) {
1 return TxStateBlockConflicted{data.block_hash, /*height=*/-1};
2}
In src/wallet/wallet.cpp:1320, negative heights are handled
0// If number of conflict confirms cannot be determined, this means
1// that the block is still unknown or not yet part of the main chain,
2// for example when loading the wallet during a reindex. Do nothing in that
3// case.
4if (m_last_block_processed_height < 0 || conflicting_height < 0) {
5 return;
6}
But in src/wallet/wallet.cpp:3299, the assertion requires >= 0:
0} else if (auto* conf = wtx.state<TxStateBlockConflicted>()) {
1 assert(conf->conflicting_block_height >= 0); // here it crashes
2 return -1 * (GetLastBlockHeight() - conf->conflicting_block_height + 1);
3}