1a35042 wallet: Update tx chain state after chain notifications are attached:
Do we need the reverse traversal here, or could we do the state updates and abandonments in separate passes instead? It seems simpler to first update every transaction state, then run the inactive coinbase abandonment pass afterward.
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
--- a/src/wallet/wallet.cpp (revision d33afaf84e54c0262f3b6f1e93ac2edf877747de)
+++ b/src/wallet/wallet.cpp (revision 866e54d2e3f0851256950ad6c737c6032f67527d)
@@ -76,7 +76,6 @@
#include <condition_variable>
#include <exception>
#include <optional>
-#include <ranges>
#include <stdexcept>
#include <thread>
#include <tuple>
@@ -3254,17 +3253,18 @@
walletInstance->SetLastBlockProcessedInMem(-1, uint256());
}
- // Update the state of every transaction now that we are connected to the chain
- // Do this in reverse order to ensure that any abandoning will work recursively
- for (auto& [_, wtx] : std::ranges::reverse_view(walletInstance->wtxOrdered)) {
- wtx->updateState(chain);
- // After updating the state of the tx, abandon if it is a coinbase that is no longer in the active chain.
- // This could happen during an external wallet load, or if the user replaced the chain data.
- if (wtx->IsCoinBase() && wtx->isInactive()) {
- walletInstance->AbandonTransaction(*wtx);
+ // Update the state of every transaction now that we are connected to the chain.
+ for (auto& [_, wtx] : walletInstance->mapWallet) {
+ wtx.updateState(chain);
+ }
+
+ // After updating all tx records, abandon any coinbase that is no longer in the active chain.
+ // This could happen during an external wallet load, or if the user replaced the chain data.
+ for (auto& [_, wtx] : walletInstance->mapWallet) {
+ if (wtx.IsCoinBase() && wtx.isInactive()) {
+ walletInstance->AbandonTransaction(wtx);
}
}
-
if (tip_height && *tip_height != rescan_height)
{