diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/net_processing.cpp | 11 | ||||
-rw-r--r-- | src/net_processing.h | 2 |
2 files changed, 6 insertions, 7 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp index f8b22cd7c8..570cca0c66 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -3559,7 +3559,7 @@ void ProcessMessage( bool PeerLogicValidation::MaybeDiscourageAndDisconnect(CNode& pnode) { - AssertLockHeld(cs_main); + LOCK(cs_main); CNodeState &state = *State(pnode.GetId()); if (state.m_should_discourage) { @@ -3675,9 +3675,6 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic<bool>& inter LogPrint(BCLog::NET, "%s(%s, %u bytes): Unknown exception caught\n", __func__, SanitizeString(msg_type), nMessageSize); } - LOCK(cs_main); - MaybeDiscourageAndDisconnect(*pfrom); - return fMoreWork; } @@ -3839,6 +3836,10 @@ bool PeerLogicValidation::SendMessages(CNode* pto) { const Consensus::Params& consensusParams = Params().GetConsensus(); + // We must call MaybeDiscourageAndDisconnect first, to ensure that we'll + // disconnect misbehaving peers even before the version handshake is complete. + if (MaybeDiscourageAndDisconnect(*pto)) return true; + // Don't send anything until the version handshake is complete if (!pto->fSuccessfullyConnected || pto->fDisconnect) return true; @@ -3878,8 +3879,6 @@ bool PeerLogicValidation::SendMessages(CNode* pto) { LOCK(cs_main); - if (MaybeDiscourageAndDisconnect(*pto)) return true; - CNodeState &state = *State(pto->GetId()); // Address refresh broadcast diff --git a/src/net_processing.h b/src/net_processing.h index eadf29e59f..48bcbc1a6c 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -31,7 +31,7 @@ private: ChainstateManager& m_chainman; CTxMemPool& m_mempool; - bool MaybeDiscourageAndDisconnect(CNode& pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main); + bool MaybeDiscourageAndDisconnect(CNode& pnode); public: PeerLogicValidation(CConnman* connman, BanMan* banman, CScheduler& scheduler, ChainstateManager& chainman, CTxMemPool& pool); |