mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-04 21:04:58 +02:00
wallet, tests: mark unconflicted txs as inactive
In `blockDisconnected`, for each transaction in the block, look for any wallet transactions spending the same inputs. If any of these transactions were marked conflicted, they are now marked as inactive. Co-authored-by: ariard <antoine.riard@gmail.com>
This commit is contained in:
@@ -1446,8 +1446,36 @@ void CWallet::blockDisconnected(const interfaces::BlockInfo& block)
|
||||
// future with a stickier abandoned state or even removing abandontransaction call.
|
||||
m_last_block_processed_height = block.height - 1;
|
||||
m_last_block_processed = *Assert(block.prev_hash);
|
||||
|
||||
int disconnect_height = block.height;
|
||||
|
||||
for (const CTransactionRef& ptx : Assert(block.data)->vtx) {
|
||||
SyncTransaction(ptx, TxStateInactive{});
|
||||
|
||||
for (const CTxIn& tx_in : ptx->vin) {
|
||||
// No other wallet transactions conflicted with this transaction
|
||||
if (mapTxSpends.count(tx_in.prevout) < 1) continue;
|
||||
|
||||
std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = mapTxSpends.equal_range(tx_in.prevout);
|
||||
|
||||
// For all of the spends that conflict with this transaction
|
||||
for (TxSpends::const_iterator _it = range.first; _it != range.second; ++_it) {
|
||||
CWalletTx& wtx = mapWallet.find(_it->second)->second;
|
||||
|
||||
if (!wtx.isConflicted()) continue;
|
||||
|
||||
auto try_updating_state = [&](CWalletTx& tx) {
|
||||
if (!tx.isConflicted()) return TxUpdate::UNCHANGED;
|
||||
if (tx.state<TxStateConflicted>()->conflicting_block_height >= disconnect_height) {
|
||||
tx.m_state = TxStateInactive{};
|
||||
return TxUpdate::CHANGED;
|
||||
}
|
||||
return TxUpdate::UNCHANGED;
|
||||
};
|
||||
|
||||
RecursiveUpdateTxState(wtx.tx->GetHash(), try_updating_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user