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) <noreply@anthropic.com>
This commit is contained in:
+15
-3
@@ -4351,7 +4351,9 @@ std::vector<uint256> CWallet::ResendWalletTransactionsBefore(int64_t nTime)
|
||||
{
|
||||
std::vector<uint256> 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<unsigned int, CWalletTx*> mapSorted;
|
||||
uint32_t now = (uint32_t)time(NULL);
|
||||
@@ -4359,7 +4361,7 @@ std::vector<uint256> CWallet::ResendWalletTransactionsBefore(int64_t nTime)
|
||||
|
||||
// vector of wallet transactions to delete
|
||||
std::vector<uint256> 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<uint256> 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<uint256> 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user