Skip to content

Commit 9e2a2b8

Browse files
committed
Merge bitcoin/bitcoin#26132: wallet: Fix nNextResend data race in ResubmitWalletTransactions
fad6157 Fix nNextResend data race in ResubmitWalletTransactions (MacroFake) Pull request description: Now that `ResubmitWalletTransactions` is called from more than one thread, it is no longer thread-safe. Introduced in 5291933. ACKs for top commit: achow101: ACK fad6157 jonatack: ACK fad6157 stickies-v: However, I think the current data race UB fix in fad6157 is the most critical to get into v24, so: ACK fad6157 - but open to further improvements. Tree-SHA512: 54da2ed1c5f44e33588ac1d21ce26908fcf0bfe785c28ba8f6a479389b5ab7a0b32b016d4c482a2ccb405e0686efb61ffe23e427f5e589dc7d2b3c7469978977
2 parents 9bd842a + fad6157 commit 9e2a2b8

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/wallet/wallet.cpp

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

19421942
// Do this infrequently and randomly to avoid giving away
19431943
// that these are our transactions.
1944-
if (!force && GetTime() < nNextResend) return;
1944+
if (!force && GetTime() < m_next_resend) return;
19451945
// resend 12-36 hours from now, ~1 day on average.
1946-
nNextResend = GetTime() + (12 * 60 * 60) + GetRand(24 * 60 * 60);
1946+
m_next_resend = GetTime() + (12 * 60 * 60) + GetRand(24 * 60 * 60);
19471947

19481948
int submitted_tx_count = 0;
19491949

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
250250
int nWalletVersion GUARDED_BY(cs_wallet){FEATURE_BASE};
251251

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

0 commit comments

Comments
 (0)