wallet: Iterate block txs in reverse on blockDisconnected

When a block is disconnected, we need to process the transactions in
reverse order so that the wallet's TXO set is updated in the correct
order.
This commit is contained in:
Ava Chow 2024-02-20 11:54:53 -05:00
parent 710a59dcc4
commit f8a18da0fb

View file

@ -1558,7 +1558,10 @@ void CWallet::blockDisconnected(const interfaces::BlockInfo& block)
int disconnect_height = block.height;
for (const CTransactionRef& ptx : Assert(block.data)->vtx) {
Assert(block.data);
// Iterate the block backwards so that we can undo the UTXO changes in the correct order
for (auto it = block.data->vtx.rbegin(); it != block.data->vtx.rend(); ++it) {
const CTransactionRef& ptx = *it;
SyncTransaction(ptx, TxStateInactive{});
for (const CTxIn& tx_in : ptx->vin) {