diff --git a/src/avalanche/processor.cpp b/src/avalanche/processor.cpp --- a/src/avalanche/processor.cpp +++ b/src/avalanche/processor.cpp @@ -544,7 +544,9 @@ return hasher.GetHash(); } -uint256 Processor::buildRemoteSighash(CNode *pfrom) const { +uint256 Processor::buildRemoteSighash(CNode *pfrom) const + EXCLUSIVE_LOCKS_REQUIRED(pfrom->cs_avalanche_state) { + AssertLockHeld(pfrom->cs_avalanche_state); CHashWriter hasher(SER_GETHASH, 0); hasher << pfrom->m_avalanche_state->delegation.getId(); hasher << pfrom->nRemoteHostNonce; diff --git a/src/net.h b/src/net.h --- a/src/net.h +++ b/src/net.h @@ -1010,6 +1010,7 @@ // m_proof_relay == nullptr if we're not relaying proofs with this peer std::unique_ptr m_proof_relay; + Mutex cs_avalanche_state; struct AvalancheState { AvalancheState() {} @@ -1017,7 +1018,8 @@ }; // m_avalanche_state == nullptr if we're not using avalanche with this peer - std::unique_ptr m_avalanche_state; + std::unique_ptr + m_avalanche_state GUARDED_BY(cs_avalanche_state); // Used for headers announcements - unfiltered blocks to relay std::vector vBlockHashesToAnnounce GUARDED_BY(cs_inventory); diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -4118,6 +4118,8 @@ } if (msg_type == NetMsgType::AVAHELLO) { + LOCK(pfrom.cs_avalanche_state); + if (!pfrom.m_avalanche_state) { pfrom.m_avalanche_state = std::make_unique(); }