Skip to content

Commit 7fbde8a

Browse files
committed
refactor: carve out tx resend timer logic into ShouldResend
Moves the logic of whether or not transactions should actually be resent out of the function that's resending them. This reduces responsibilities of ResubmitWalletTransactions and allows carving out the updating of m_next_resend in a future commit.
1 parent 01f3534 commit 7fbde8a

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/wallet/wallet.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,23 @@ std::set<uint256> CWallet::GetTxConflicts(const CWalletTx& wtx) const
19031903
return result;
19041904
}
19051905

1906+
bool CWallet::ShouldResend() const
1907+
{
1908+
// Don't attempt to resubmit if the wallet is configured to not broadcast
1909+
if (!fBroadcastTransactions) return false;
1910+
1911+
// During reindex, importing and IBD, old wallet transactions become
1912+
// unconfirmed. Don't resend them as that would spam other nodes.
1913+
// We only allow forcing mempool submission when not relaying to avoid this spam.
1914+
if (!chain().isReadyToBroadcast()) return false;
1915+
1916+
// Do this infrequently and randomly to avoid giving away
1917+
// that these are our transactions.
1918+
if (GetTime() < m_next_resend) return false;
1919+
1920+
return true;
1921+
}
1922+
19061923
// Resubmit transactions from the wallet to the mempool, optionally asking the
19071924
// mempool to relay them. On startup, we will do this for all unconfirmed
19081925
// transactions but will not ask the mempool to relay them. We do this on startup
@@ -1934,14 +1951,6 @@ void CWallet::ResubmitWalletTransactions(bool relay, bool force)
19341951
// even if forcing.
19351952
if (!fBroadcastTransactions) return;
19361953

1937-
// During reindex, importing and IBD, old wallet transactions become
1938-
// unconfirmed. Don't resend them as that would spam other nodes.
1939-
// We only allow forcing mempool submission when not relaying to avoid this spam.
1940-
if (!force && relay && !chain().isReadyToBroadcast()) return;
1941-
1942-
// Do this infrequently and randomly to avoid giving away
1943-
// that these are our transactions.
1944-
if (!force && GetTime() < m_next_resend) return;
19451954
// resend 12-36 hours from now, ~1 day on average.
19461955
m_next_resend = GetTime() + (12 * 60 * 60) + GetRand(24 * 60 * 60);
19471956

@@ -1979,6 +1988,7 @@ void CWallet::ResubmitWalletTransactions(bool relay, bool force)
19791988
void MaybeResendWalletTxs(WalletContext& context)
19801989
{
19811990
for (const std::shared_ptr<CWallet>& pwallet : GetWallets(context)) {
1991+
if (!pwallet->ShouldResend()) continue;
19821992
pwallet->ResubmitWalletTransactions(/*relay=*/true, /*force=*/false);
19831993
}
19841994
}

src/wallet/wallet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,8 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
537537
};
538538
ScanResult ScanForWalletTransactions(const uint256& start_block, int start_height, std::optional<int> max_height, const WalletRescanReserver& reserver, bool fUpdate, const bool save_progress);
539539
void transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override;
540+
/** Return true if all conditions for periodically resending transactions are met. */
541+
bool ShouldResend() const;
540542
void ResubmitWalletTransactions(bool relay, bool force);
541543

542544
OutputType TransactionChangeType(const std::optional<OutputType>& change_type, const std::vector<CRecipient>& vecSend) const;

0 commit comments

Comments
 (0)