Skip to content

Commit 7452e36

Browse files
committed
merge bitcoin#26132: Fix nNextResend data race in ResubmitWalletTransactions
1 parent 664343f commit 7452e36

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/wallet/wallet.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,7 @@ std::set<uint256> CWallet::GetTxConflicts(const CWalletTx& wtx) const
18611861
// mempool to relay them. On startup, we will do this for all unconfirmed
18621862
// transactions but will not ask the mempool to relay them. We do this on startup
18631863
// to ensure that our own mempool is aware of our transactions, and to also
1864-
// initialize nNextResend so that the actual rebroadcast is scheduled. There
1864+
// initialize m_next_resend so that the actual rebroadcast is scheduled. There
18651865
// is a privacy side effect here as not broadcasting on startup also means that we won't
18661866
// inform the world of our wallet's state, particularly if the wallet (or node) is not
18671867
// yet synced.
@@ -1895,9 +1895,9 @@ void CWallet::ResubmitWalletTransactions(bool relay, bool force)
18951895

18961896
// Do this infrequently and randomly to avoid giving away
18971897
// that these are our transactions.
1898-
if (!force && GetTime() < nNextResend) return;
1898+
if (!force && GetTime() < m_next_resend) return;
18991899
// resend 1-3 hours from now, ~2 hours on average.
1900-
nNextResend = GetTime() + (1 * 60 * 60) + GetRand(2 * 60 * 60);
1900+
m_next_resend = GetTime() + (1 * 60 * 60) + GetRand(2 * 60 * 60);
19011901

19021902
int submitted_tx_count = 0;
19031903

src/wallet/wallet.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
272272
//! the current wallet version: clients below this version are not able to load the wallet
273273
int nWalletVersion GUARDED_BY(cs_wallet){FEATURE_BASE};
274274

275-
int64_t nNextResend = 0;
275+
/** The next scheduled rebroadcast of wallet transactions. */
276+
std::atomic<int64_t> m_next_resend{};
276277
/** Whether this wallet will submit newly created transactions to the node's mempool and
277278
* prompt rebroadcasts (see ResendWalletTransactions()). */
278279
bool fBroadcastTransactions = false;

0 commit comments

Comments
 (0)