@@ -264,10 +264,10 @@ struct Peer {
264
264
/* * The feerate in the most recent BIP133 `feefilter` message sent to the peer.
265
265
* It is *not* a p2p protocol violation for the peer to send us
266
266
* transactions with a lower fee rate than this. See BIP133. */
267
- CAmount m_fee_filter_sent{0 };
267
+ CAmount m_fee_filter_sent GUARDED_BY (NetEventsInterface::g_msgproc_mutex) {0 };
268
268
/* * Timestamp after which we will send the next BIP133 `feefilter` message
269
269
* to the peer. */
270
- std::chrono::microseconds m_next_send_feefilter{0 };
270
+ std::chrono::microseconds m_next_send_feefilter GUARDED_BY (NetEventsInterface::g_msgproc_mutex) {0 };
271
271
272
272
struct TxRelay {
273
273
mutable RecursiveMutex m_bloom_filter_mutex;
@@ -298,7 +298,7 @@ struct Peer {
298
298
std::atomic<std::chrono::seconds> m_last_mempool_req{0s};
299
299
/* * The next time after which we will send an `inv` message containing
300
300
* transaction announcements to this peer. */
301
- std::chrono::microseconds m_next_inv_send_time{0 };
301
+ std::chrono::microseconds m_next_inv_send_time GUARDED_BY (NetEventsInterface::g_msgproc_mutex) {0 };
302
302
303
303
/* * Minimum fee rate with which to filter transaction announcements to this node. See BIP133. */
304
304
std::atomic<CAmount> m_fee_filter_received{0 };
@@ -319,7 +319,7 @@ struct Peer {
319
319
};
320
320
321
321
/* * A vector of addresses to send to the peer, limited to MAX_ADDR_TO_SEND. */
322
- std::vector<CAddress> m_addrs_to_send;
322
+ std::vector<CAddress> m_addrs_to_send GUARDED_BY (NetEventsInterface::g_msgproc_mutex) ;
323
323
/* * Probabilistic filter to track recent addr messages relayed with this
324
324
* peer. Used to avoid relaying redundant addresses to this peer.
325
325
*
@@ -329,7 +329,7 @@ struct Peer {
329
329
*
330
330
* Presence of this filter must correlate with m_addr_relay_enabled.
331
331
**/
332
- std::unique_ptr<CRollingBloomFilter> m_addr_known;
332
+ std::unique_ptr<CRollingBloomFilter> m_addr_known GUARDED_BY (NetEventsInterface::g_msgproc_mutex) ;
333
333
/* * Whether we are participating in address relay with this connection.
334
334
*
335
335
* We set this bool to true for outbound peers (other than
@@ -346,7 +346,7 @@ struct Peer {
346
346
* initialized.*/
347
347
std::atomic_bool m_addr_relay_enabled{false };
348
348
/* * Whether a getaddr request to this peer is outstanding. */
349
- bool m_getaddr_sent{false };
349
+ bool m_getaddr_sent GUARDED_BY (NetEventsInterface::g_msgproc_mutex) {false };
350
350
/* * Guards address sending timers. */
351
351
mutable Mutex m_addr_send_times_mutex;
352
352
/* * Time point to send the next ADDR message to this peer. */
@@ -357,12 +357,12 @@ struct Peer {
357
357
* messages, indicating a preference to receive ADDRv2 instead of ADDR ones. */
358
358
std::atomic_bool m_wants_addrv2{false };
359
359
/* * Whether this peer has already sent us a getaddr message. */
360
- bool m_getaddr_recvd{false };
360
+ bool m_getaddr_recvd GUARDED_BY (NetEventsInterface::g_msgproc_mutex) {false };
361
361
/* * Number of addresses that can be processed from this peer. Start at 1 to
362
362
* permit self-announcement. */
363
- double m_addr_token_bucket{1.0 };
363
+ double m_addr_token_bucket GUARDED_BY (NetEventsInterface::g_msgproc_mutex) {1.0 };
364
364
/* * When m_addr_token_bucket was last updated */
365
- std::chrono::microseconds m_addr_token_timestamp{GetTime<std::chrono::microseconds>()};
365
+ std::chrono::microseconds m_addr_token_timestamp GUARDED_BY (NetEventsInterface::g_msgproc_mutex) {GetTime<std::chrono::microseconds>()};
366
366
/* * Total number of addresses that were dropped due to rate limiting. */
367
367
std::atomic<uint64_t > m_addr_rate_limited{0 };
368
368
/* * Total number of addresses that were processed (excludes rate-limited ones). */
@@ -372,15 +372,15 @@ struct Peer {
372
372
std::set<uint256> m_orphan_work_set GUARDED_BY (g_cs_orphans);
373
373
374
374
/* * Whether we've sent this peer a getheaders in response to an inv prior to initial-headers-sync completing */
375
- bool m_inv_triggered_getheaders_before_sync{false };
375
+ bool m_inv_triggered_getheaders_before_sync GUARDED_BY (NetEventsInterface::g_msgproc_mutex) {false };
376
376
377
377
/* * Protects m_getdata_requests **/
378
378
Mutex m_getdata_requests_mutex;
379
379
/* * Work queue of items requested by this peer **/
380
380
std::deque<CInv> m_getdata_requests GUARDED_BY (m_getdata_requests_mutex);
381
381
382
382
/* * Time of the last getheaders message to this peer */
383
- NodeClock::time_point m_last_getheaders_timestamp{};
383
+ NodeClock::time_point m_last_getheaders_timestamp GUARDED_BY (NetEventsInterface::g_msgproc_mutex) {};
384
384
385
385
/* * Protects m_headers_sync **/
386
386
Mutex m_headers_sync_mutex;
@@ -537,7 +537,7 @@ class PeerManagerImpl final : public PeerManager
537
537
538
538
private:
539
539
/* * Consider evicting an outbound peer based on the amount of time they've been behind our tip */
540
- void ConsiderEviction (CNode& pto, Peer& peer, std::chrono::seconds time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
540
+ void ConsiderEviction (CNode& pto, Peer& peer, std::chrono::seconds time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main, g_msgproc_mutex );
541
541
542
542
/* * If we have extra outbound peers, try to disconnect the one with the oldest block announcement */
543
543
void EvictExtraOutboundPeers (std::chrono::seconds now) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
@@ -601,7 +601,7 @@ class PeerManagerImpl final : public PeerManager
601
601
void ProcessHeadersMessage (CNode& pfrom, Peer& peer,
602
602
std::vector<CBlockHeader>&& headers,
603
603
bool via_compact_block)
604
- EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, !m_headers_presync_mutex);
604
+ EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, !m_headers_presync_mutex, g_msgproc_mutex );
605
605
/* * Various helpers for headers processing, invoked by ProcessHeadersMessage() */
606
606
/* * Return true if headers are continuous and have valid proof-of-work (DoS points assigned on failure) */
607
607
bool CheckHeadersPoW (const std::vector<CBlockHeader>& headers, const Consensus::Params& consensusParams, Peer& peer);
@@ -610,7 +610,7 @@ class PeerManagerImpl final : public PeerManager
610
610
/* * Deal with state tracking and headers sync for peers that send the
611
611
* occasional non-connecting header (this can happen due to BIP 130 headers
612
612
* announcements for blocks interacting with the 2hr (MAX_FUTURE_BLOCK_TIME) rule). */
613
- void HandleFewUnconnectingHeaders (CNode& pfrom, Peer& peer, const std::vector<CBlockHeader>& headers);
613
+ void HandleFewUnconnectingHeaders (CNode& pfrom, Peer& peer, const std::vector<CBlockHeader>& headers) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex) ;
614
614
/* * Return true if the headers connect to each other, false otherwise */
615
615
bool CheckHeadersAreContinuous (const std::vector<CBlockHeader>& headers) const ;
616
616
/* * Try to continue a low-work headers sync that has already begun.
@@ -633,7 +633,7 @@ class PeerManagerImpl final : public PeerManager
633
633
*/
634
634
bool IsContinuationOfLowWorkHeadersSync (Peer& peer, CNode& pfrom,
635
635
std::vector<CBlockHeader>& headers)
636
- EXCLUSIVE_LOCKS_REQUIRED(peer.m_headers_sync_mutex, !m_headers_presync_mutex);
636
+ EXCLUSIVE_LOCKS_REQUIRED(peer.m_headers_sync_mutex, !m_headers_presync_mutex, g_msgproc_mutex );
637
637
/* * Check work on a headers chain to be processed, and if insufficient,
638
638
* initiate our anti-DoS headers sync mechanism.
639
639
*
@@ -649,7 +649,7 @@ class PeerManagerImpl final : public PeerManager
649
649
bool TryLowWorkHeadersSync (Peer& peer, CNode& pfrom,
650
650
const CBlockIndex* chain_start_header,
651
651
std::vector<CBlockHeader>& headers)
652
- EXCLUSIVE_LOCKS_REQUIRED(!peer.m_headers_sync_mutex, !m_peer_mutex, !m_headers_presync_mutex);
652
+ EXCLUSIVE_LOCKS_REQUIRED(!peer.m_headers_sync_mutex, !m_peer_mutex, !m_headers_presync_mutex, g_msgproc_mutex );
653
653
654
654
/* * Return true if the given header is an ancestor of
655
655
* m_chainman.m_best_header or our current tip */
@@ -659,7 +659,7 @@ class PeerManagerImpl final : public PeerManager
659
659
* We don't issue a getheaders message if we have a recent one outstanding.
660
660
* This returns true if a getheaders is actually sent, and false otherwise.
661
661
*/
662
- bool MaybeSendGetHeaders (CNode& pfrom, const CBlockLocator& locator, Peer& peer);
662
+ bool MaybeSendGetHeaders (CNode& pfrom, const CBlockLocator& locator, Peer& peer) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex) ;
663
663
/* * Potentially fetch blocks from this peer upon receipt of a new headers tip */
664
664
void HeadersDirectFetchBlocks (CNode& pfrom, const Peer& peer, const CBlockIndex* pindexLast);
665
665
/* * Update peer state based on received headers message */
@@ -683,10 +683,10 @@ class PeerManagerImpl final : public PeerManager
683
683
void MaybeSendPing (CNode& node_to, Peer& peer, std::chrono::microseconds now);
684
684
685
685
/* * Send `addr` messages on a regular schedule. */
686
- void MaybeSendAddr (CNode& node, Peer& peer, std::chrono::microseconds current_time);
686
+ void MaybeSendAddr (CNode& node, Peer& peer, std::chrono::microseconds current_time) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex) ;
687
687
688
688
/* * Send a single `sendheaders` message, after we have completed headers sync with a peer. */
689
- void MaybeSendSendHeaders (CNode& node, Peer& peer);
689
+ void MaybeSendSendHeaders (CNode& node, Peer& peer) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex) ;
690
690
691
691
/* * Relay (gossip) an address to a few randomly chosen nodes.
692
692
*
@@ -695,10 +695,10 @@ class PeerManagerImpl final : public PeerManager
695
695
* @param[in] fReachable Whether the address' network is reachable. We relay unreachable
696
696
* addresses less.
697
697
*/
698
- void RelayAddress (NodeId originator, const CAddress& addr, bool fReachable ) EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
698
+ void RelayAddress (NodeId originator, const CAddress& addr, bool fReachable ) EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, g_msgproc_mutex );
699
699
700
700
/* * Send `feefilter` message. */
701
- void MaybeSendFeefilter (CNode& node, Peer& peer, std::chrono::microseconds current_time);
701
+ void MaybeSendFeefilter (CNode& node, Peer& peer, std::chrono::microseconds current_time) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex) ;
702
702
703
703
const CChainParams& m_chainparams;
704
704
CConnman& m_connman;
@@ -1010,7 +1010,10 @@ class PeerManagerImpl final : public PeerManager
1010
1010
* @return True if address relay is enabled with peer
1011
1011
* False if address relay is disallowed
1012
1012
*/
1013
- bool SetupAddressRelay (const CNode& node, Peer& peer);
1013
+ bool SetupAddressRelay (const CNode& node, Peer& peer) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
1014
+
1015
+ void AddAddressKnown (Peer& peer, const CAddress& addr) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
1016
+ void PushAddress (Peer& peer, const CAddress& addr, FastRandomContext& insecure_rand) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
1014
1017
};
1015
1018
1016
1019
const CNodeState* PeerManagerImpl::State (NodeId pnode) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
@@ -1036,13 +1039,13 @@ static bool IsAddrCompatible(const Peer& peer, const CAddress& addr)
1036
1039
return peer.m_wants_addrv2 || addr.IsAddrV1Compatible ();
1037
1040
}
1038
1041
1039
- static void AddAddressKnown (Peer& peer, const CAddress& addr)
1042
+ void PeerManagerImpl:: AddAddressKnown (Peer& peer, const CAddress& addr)
1040
1043
{
1041
1044
assert (peer.m_addr_known );
1042
1045
peer.m_addr_known ->insert (addr.GetKey ());
1043
1046
}
1044
1047
1045
- static void PushAddress (Peer& peer, const CAddress& addr, FastRandomContext& insecure_rand)
1048
+ void PeerManagerImpl:: PushAddress (Peer& peer, const CAddress& addr, FastRandomContext& insecure_rand)
1046
1049
{
1047
1050
// Known checking here is only to save space from duplicates.
1048
1051
// Before sending, we'll filter it again for known addresses that were
@@ -5103,7 +5106,7 @@ void PeerManagerImpl::MaybeSendAddr(CNode& node, Peer& peer, std::chrono::micros
5103
5106
5104
5107
// Remove addr records that the peer already knows about, and add new
5105
5108
// addrs to the m_addr_known filter on the same pass.
5106
- auto addr_already_known = [&peer](const CAddress& addr) {
5109
+ auto addr_already_known = [&peer](const CAddress& addr) EXCLUSIVE_LOCKS_REQUIRED (g_msgproc_mutex) {
5107
5110
bool ret = peer.m_addr_known ->contains (addr.GetKey ());
5108
5111
if (!ret) peer.m_addr_known ->insert (addr.GetKey ());
5109
5112
return ret;
0 commit comments