From 45062b362e3afa62abffb5f0ae440ce99bf2b219 Mon Sep 17 00:00:00 2001 From: iho Date: Thu, 9 Jul 2026 10:53:57 +0300 Subject: [PATCH] fix: claim state_sync_requested with compare_exchange Replace separate load/store when accepting a TxHashSetArchive with an atomic compare_exchange so two concurrent messages cannot both observe the flag as true. Addresses #3588. --- p2p/src/protocol.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/p2p/src/protocol.rs b/p2p/src/protocol.rs index 0bb7ef831..91eef492d 100644 --- a/p2p/src/protocol.rs +++ b/p2p/src/protocol.rs @@ -289,12 +289,17 @@ impl MessageHandler for Protocol { ); return Err(Error::BadMessage); } - if !self.state_sync_requested.load(Ordering::Relaxed) { + // Atomically claim the outstanding state-sync request so two + // concurrent archive messages cannot both observe "requested" + // and proceed (load+store race; see #3588). + if self + .state_sync_requested + .compare_exchange(true, false, Ordering::SeqCst, Ordering::Relaxed) + .is_err() + { error!("handle_payload: txhashset archive received but from the wrong peer",); return Err(Error::BadMessage); } - // Update the sync state requested status - self.state_sync_requested.store(false, Ordering::Relaxed); let start_time = Utc::now(); self.adapter