From 2a2eaa20780303c4a44a05f857d570eb5340e90a Mon Sep 17 00:00:00 2001 From: DanS Date: Tue, 1 Dec 2026 15:07:24 -0600 Subject: [PATCH 1/2] wallet: stop logging every mined transaction as "expired" on each rebroadcast ResendWalletTransactionsBefore applied its "expired, don't relay" test to every wallet transaction, mined ones included. A confirmed transaction is past its expiry height a few hundred blocks after it was mined, so every pass (every 0-30 minutes) logged one "ignoring expired tx" line per transaction the wallet had ever made, and the count only grew. Measured in the 2026-12-01 soak (exchange-style wallet, ~15k transactions): 14,735 distinct "expired" txs x 89 passes = 1.1 million lines; debug.log grew by 354 MB in 24 h. Mined transactions are now skipped before the expiry test (they have nothing to rebroadcast; RelayWalletTransaction already refused them). Genuinely expired unconfirmed transactions are counted and reported in one summary line, with the per-transaction detail under -debug=wallet. The function now takes cs_main itself as well; both callers already hold it, and GetDepthInMainChain needs it. Co-Authored-By: Claude Opus 5.5 (1M context) --- src/wallet/wallet.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 66d68c272..481dec154 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4351,7 +4351,9 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) { std::vector result; - LOCK(cs_wallet); + // Both callers (the periodic Broadcast signal from SendMessages, and resendwallettransactions) hold + // cs_main already; GetDepthInMainChain below needs it. + LOCK2(cs_main, cs_wallet); // Sort them in chronological order multimap mapSorted; uint32_t now = (uint32_t)time(NULL); @@ -4359,7 +4361,7 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) // vector of wallet transactions to delete std::vector vwtxh; - uint32_t erased = 0, skipped = 0; + uint32_t erased = 0, skipped = 0, expired = 0; BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet) { @@ -4368,10 +4370,18 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) if (wtx.nTimeReceived > nTime) continue; + // A mined transaction has nothing to rebroadcast. It used to reach the expiry test below, and every + // confirmed tx is past its expiry height a few hundred blocks after it was mined, so each pass logged + // one "ignoring expired tx" line per wallet tx ever made: 1.1M lines (354 MB of debug.log) in a day on + // an exchange-style wallet of ~15k txs. + if (wtx.GetDepthInMainChain() > 0) + continue; + // Do not relay expired transactions, to avoid other nodes banning us // Current code will not ban nodes relaying expired txs but older nodes will if (wtx.nExpiryHeight > 0 && wtx.nExpiryHeight < chainActive.LastTip()->GetHeight()) { - LogPrintf("%s: ignoring expired tx %s with expiry %d at height %d\n", __func__, wtx.GetHash().ToString().c_str(), wtx.nExpiryHeight, chainActive.LastTip()->GetHeight() ); + LogPrint("wallet", "%s: ignoring expired tx %s with expiry %d at height %d\n", __func__, wtx.GetHash().ToString().c_str(), wtx.nExpiryHeight, chainActive.LastTip()->GetHeight() ); + expired++; // TODO: expired detection doesn't seem to work right // append to list of txs to delete // vwtxh.push_back(wtx.GetHash()); @@ -4417,6 +4427,8 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) if(erased > 0 || skipped > 0) { LogPrintf("%s: Prevented relaying %d and erased %d transactions which are too old\n", __func__, skipped, erased); } + if (expired > 0) + LogPrintf("%s: not relaying %u expired unconfirmed transaction(s) (-debug=wallet lists them)\n", __func__, expired); return result; } From a7b15e40a0806ff5792ece34c184d4f988f913f7 Mon Sep 17 00:00:00 2001 From: DanS Date: Tue, 1 Dec 2026 15:11:48 -0600 Subject: [PATCH 2/2] wallet: say why a zsweep or autoshield round failed when its tx is rejected When CommitAutomatedTx refused a transaction (AcceptToMemoryPool rejected it), the sweep and autoshield ops returned false without setting an error, so the operation finished as "failed" with an empty message: Sweep operation finished. (status=failed, error=) Seen twice in 175 sweep rounds in the 2026-12-01 soak; one was a note already spent by another transaction ("sapling nullifier ... exists"). Both ops now set RPC_WALLET_ERROR and a message naming the rejected txid, pointing at debug.log for the mempool's reason (CommitTransaction does not return it), and saying the next round retries. Consolidation already records a per-address reason. Co-Authored-By: Claude Opus 5.5 (1M context) --- src/wallet/asyncrpcoperation_autoshieldcoinbase.cpp | 3 +++ src/wallet/asyncrpcoperation_sweep.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/wallet/asyncrpcoperation_autoshieldcoinbase.cpp b/src/wallet/asyncrpcoperation_autoshieldcoinbase.cpp index 72cf166b6..9628269ed 100644 --- a/src/wallet/asyncrpcoperation_autoshieldcoinbase.cpp +++ b/src/wallet/asyncrpcoperation_autoshieldcoinbase.cpp @@ -461,6 +461,9 @@ bool AsyncRPCOperation_autoshieldcoinbase::main_impl() { } LogPrintf("%s: autoshield tx FAILED in CommitTransaction, txid=%s\n", opid, tx.GetHash().ToString()); + set_error_code(RPC_WALLET_ERROR); + set_error_message(strprintf("Autoshield transaction %s was not accepted into the mempool (see debug.log for the " + "reason). The next round tries again.", tx.GetHash().ToString())); return false; } diff --git a/src/wallet/asyncrpcoperation_sweep.cpp b/src/wallet/asyncrpcoperation_sweep.cpp index fcc4ccad1..e86f3d457 100644 --- a/src/wallet/asyncrpcoperation_sweep.cpp +++ b/src/wallet/asyncrpcoperation_sweep.cpp @@ -411,6 +411,12 @@ bool AsyncRPCOperation_sweep::main_impl() { numTxCreated++; } else { LogPrintf("%s: Sweep transaction FAILED in CommitTransaction, txid=%s\n",opid , tx.GetHash().ToString()); + // Say why the round failed: this used to finish as "failed" with an empty error. The mempool's + // reason is in debug.log just above (most often a note already spent by another transaction). + set_error_code(RPC_WALLET_ERROR); + set_error_message(strprintf("Sweep transaction %s was not accepted into the mempool (see debug.log for " + "the reason; usually one of its notes was spent by another transaction " + "meanwhile). The next round sweeps what is left.", tx.GetHash().ToString())); setSweepResult(numTxCreated, amountSwept, sweepTxIds); status = false; break;