@@ -223,8 +223,6 @@ struct Peer {
223223
224224 /* * Protects misbehavior data members */
225225 Mutex m_misbehavior_mutex;
226- /* * Accumulated misbehavior score for this peer */
227- int m_misbehavior_score GUARDED_BY (m_misbehavior_mutex){0 };
228226 /* * Whether this peer should be disconnected and marked as discouraged (unless it has NetPermissionFlags::NoBan permission). */
229227 bool m_should_discourage GUARDED_BY (m_misbehavior_mutex){false };
230228
@@ -521,7 +519,7 @@ class PeerManagerImpl final : public PeerManager
521519 m_best_height = height;
522520 m_best_block_time = time;
523521 };
524- void UnitTestMisbehaving (NodeId peer_id, int howmuch ) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex) { Misbehaving (*Assert (GetPeerRef (peer_id)), howmuch , " " ); };
522+ void UnitTestMisbehaving (NodeId peer_id) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex) { Misbehaving (*Assert (GetPeerRef (peer_id)), " " ); };
525523 void ProcessMessage (CNode& pfrom, const std::string& msg_type, DataStream& vRecv,
526524 const std::chrono::microseconds time_received, const std::atomic<bool >& interruptMsgProc) override
527525 EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, !m_recent_confirmed_transactions_mutex, !m_most_recent_block_mutex, !m_headers_presync_mutex, g_msgproc_mutex);
@@ -546,11 +544,9 @@ class PeerManagerImpl final : public PeerManager
546544 * May return an empty shared_ptr if the Peer object can't be found. */
547545 PeerRef RemovePeer (NodeId id) EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
548546
549- /* *
550- * Increment peer's misbehavior score. If the new value >= DISCOURAGEMENT_THRESHOLD, mark the node
551- * to be discouraged, meaning the peer might be disconnected and added to the discouragement filter.
552- */
553- void Misbehaving (Peer& peer, int howmuch, const std::string& message);
547+ /* * Mark a peer as misbehaving, which will cause it to be disconnected and its
548+ * address discouraged. */
549+ void Misbehaving (Peer& peer, const std::string& message);
554550
555551 /* *
556552 * Potentially mark a node discouraged based on the contents of a BlockValidationState object
@@ -1711,7 +1707,6 @@ void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler)
17111707void PeerManagerImpl::FinalizeNode (const CNode& node)
17121708{
17131709 NodeId nodeid = node.GetId ();
1714- int misbehavior{0 };
17151710 {
17161711 LOCK (cs_main);
17171712 {
@@ -1722,7 +1717,6 @@ void PeerManagerImpl::FinalizeNode(const CNode& node)
17221717 // destructed.
17231718 PeerRef peer = RemovePeer (nodeid);
17241719 assert (peer != nullptr );
1725- misbehavior = WITH_LOCK (peer->m_misbehavior_mutex , return peer->m_misbehavior_score );
17261720 m_wtxid_relay_peers -= peer->m_wtxid_relay ;
17271721 assert (m_wtxid_relay_peers >= 0 );
17281722 }
@@ -1765,7 +1759,7 @@ void PeerManagerImpl::FinalizeNode(const CNode& node)
17651759 assert (m_orphanage.Size () == 0 );
17661760 }
17671761 } // cs_main
1768- if (node.fSuccessfullyConnected && misbehavior == 0 &&
1762+ if (node.fSuccessfullyConnected &&
17691763 !node.IsBlockOnlyConn () && !node.IsInboundConn ()) {
17701764 // Only change visible addrman state for full outbound peers. We don't
17711765 // call Connected() for feeler connections since they don't have
@@ -1886,25 +1880,13 @@ void PeerManagerImpl::AddToCompactExtraTransactions(const CTransactionRef& tx)
18861880 vExtraTxnForCompactIt = (vExtraTxnForCompactIt + 1 ) % m_opts.max_extra_txs ;
18871881}
18881882
1889- void PeerManagerImpl::Misbehaving (Peer& peer, int howmuch, const std::string& message)
1883+ void PeerManagerImpl::Misbehaving (Peer& peer, const std::string& message)
18901884{
1891- assert (howmuch > 0 );
1892-
18931885 LOCK (peer.m_misbehavior_mutex );
1894- const int score_before{peer.m_misbehavior_score };
1895- peer.m_misbehavior_score += howmuch;
1896- const int score_now{peer.m_misbehavior_score };
18971886
18981887 const std::string message_prefixed = message.empty () ? " " : (" : " + message);
1899- std::string warning;
1900-
1901- if (score_now >= DISCOURAGEMENT_THRESHOLD && score_before < DISCOURAGEMENT_THRESHOLD) {
1902- warning = " DISCOURAGE THRESHOLD EXCEEDED" ;
1903- peer.m_should_discourage = true ;
1904- }
1905-
1906- LogPrint (BCLog::NET, " Misbehaving: peer=%d (%d -> %d)%s%s\n " ,
1907- peer.m_id , score_before, score_now, warning, message_prefixed);
1888+ peer.m_should_discourage = true ;
1889+ LogPrint (BCLog::NET, " Misbehaving: peer=%d%s\n " , peer.m_id , message_prefixed);
19081890}
19091891
19101892bool PeerManagerImpl::MaybePunishNodeForBlock (NodeId nodeid, const BlockValidationState& state,
@@ -1922,7 +1904,7 @@ bool PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati
19221904 case BlockValidationResult::BLOCK_CONSENSUS:
19231905 case BlockValidationResult::BLOCK_MUTATED:
19241906 if (!via_compact_block) {
1925- if (peer) Misbehaving (*peer, 100 , message);
1907+ if (peer) Misbehaving (*peer, message);
19261908 return true ;
19271909 }
19281910 break ;
@@ -1937,19 +1919,19 @@ bool PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati
19371919 // Discourage outbound (but not inbound) peers if on an invalid chain.
19381920 // Exempt HB compact block peers. Manual connections are always protected from discouragement.
19391921 if (!via_compact_block && !node_state->m_is_inbound ) {
1940- if (peer) Misbehaving (*peer, 100 , message);
1922+ if (peer) Misbehaving (*peer, message);
19411923 return true ;
19421924 }
19431925 break ;
19441926 }
19451927 case BlockValidationResult::BLOCK_INVALID_HEADER:
19461928 case BlockValidationResult::BLOCK_CHECKPOINT:
19471929 case BlockValidationResult::BLOCK_INVALID_PREV:
1948- if (peer) Misbehaving (*peer, 100 , message);
1930+ if (peer) Misbehaving (*peer, message);
19491931 return true ;
19501932 // Conflicting (but not necessarily invalid) data or different policy:
19511933 case BlockValidationResult::BLOCK_MISSING_PREV:
1952- if (peer) Misbehaving (*peer, 100 , message);
1934+ if (peer) Misbehaving (*peer, message);
19531935 return true ;
19541936 case BlockValidationResult::BLOCK_RECENT_CONSENSUS_CHANGE:
19551937 case BlockValidationResult::BLOCK_TIME_FUTURE:
@@ -1969,7 +1951,7 @@ bool PeerManagerImpl::MaybePunishNodeForTx(NodeId nodeid, const TxValidationStat
19691951 break ;
19701952 // The node is providing invalid data:
19711953 case TxValidationResult::TX_CONSENSUS:
1972- if (peer) Misbehaving (*peer, 100 , " " );
1954+ if (peer) Misbehaving (*peer, " " );
19731955 return true ;
19741956 // Conflicting (but not necessarily invalid) data or different policy:
19751957 case TxValidationResult::TX_RECENT_CONSENSUS_CHANGE:
@@ -2670,7 +2652,7 @@ void PeerManagerImpl::SendBlockTransactions(CNode& pfrom, Peer& peer, const CBlo
26702652 BlockTransactions resp (req);
26712653 for (size_t i = 0 ; i < req.indexes .size (); i++) {
26722654 if (req.indexes [i] >= block.vtx .size ()) {
2673- Misbehaving (peer, 100 , " getblocktxn with out-of-bounds tx indices" );
2655+ Misbehaving (peer, " getblocktxn with out-of-bounds tx indices" );
26742656 return ;
26752657 }
26762658 resp.txn [i] = block.vtx [req.indexes [i]];
@@ -2683,13 +2665,13 @@ bool PeerManagerImpl::CheckHeadersPoW(const std::vector<CBlockHeader>& headers,
26832665{
26842666 // Do these headers have proof-of-work matching what's claimed?
26852667 if (!HasValidProofOfWork (headers, consensusParams)) {
2686- Misbehaving (peer, 100 , " header with invalid proof of work" );
2668+ Misbehaving (peer, " header with invalid proof of work" );
26872669 return false ;
26882670 }
26892671
26902672 // Are these headers connected to each other?
26912673 if (!CheckHeadersAreContinuous (headers)) {
2692- Misbehaving (peer, 100 , " non-continuous headers sequence" );
2674+ Misbehaving (peer, " non-continuous headers sequence" );
26932675 return false ;
26942676 }
26952677 return true ;
@@ -3622,7 +3604,7 @@ void PeerManagerImpl::ProcessCompactBlockTxns(CNode& pfrom, Peer& peer, const Bl
36223604 ReadStatus status = partialBlock.FillBlock (*pblock, block_transactions.txn );
36233605 if (status == READ_STATUS_INVALID) {
36243606 RemoveBlockRequest (block_transactions.blockhash , pfrom.GetId ()); // Reset in-flight state in case Misbehaving does not result in a disconnect
3625- Misbehaving (peer, 100 , " invalid compact block/non-matching block transactions" );
3607+ Misbehaving (peer, " invalid compact block/non-matching block transactions" );
36263608 return ;
36273609 } else if (status == READ_STATUS_FAILED) {
36283610 if (first_in_flight) {
@@ -4106,7 +4088,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
41064088
41074089 if (vAddr.size () > MAX_ADDR_TO_SEND)
41084090 {
4109- Misbehaving (*peer, 100 , strprintf (" %s message size = %u" , msg_type, vAddr.size ()));
4091+ Misbehaving (*peer, strprintf (" %s message size = %u" , msg_type, vAddr.size ()));
41104092 return ;
41114093 }
41124094
@@ -4188,7 +4170,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
41884170 vRecv >> vInv;
41894171 if (vInv.size () > MAX_INV_SZ)
41904172 {
4191- Misbehaving (*peer, 100 , strprintf (" inv message size = %u" , vInv.size ()));
4173+ Misbehaving (*peer, strprintf (" inv message size = %u" , vInv.size ()));
41924174 return ;
41934175 }
41944176
@@ -4280,7 +4262,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
42804262 vRecv >> vInv;
42814263 if (vInv.size () > MAX_INV_SZ)
42824264 {
4283- Misbehaving (*peer, 100 , strprintf (" getdata message size = %u" , vInv.size ()));
4265+ Misbehaving (*peer, strprintf (" getdata message size = %u" , vInv.size ()));
42844266 return ;
42854267 }
42864268
@@ -4820,7 +4802,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
48204802 ReadStatus status = partialBlock.InitData (cmpctblock, vExtraTxnForCompact);
48214803 if (status == READ_STATUS_INVALID) {
48224804 RemoveBlockRequest (pindex->GetBlockHash (), pfrom.GetId ()); // Reset in-flight state in case Misbehaving does not result in a disconnect
4823- Misbehaving (*peer, 100 , " invalid compact block" );
4805+ Misbehaving (*peer, " invalid compact block" );
48244806 return ;
48254807 } else if (status == READ_STATUS_FAILED) {
48264808 if (first_in_flight) {
@@ -4965,7 +4947,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
49654947 // Bypass the normal CBlock deserialization, as we don't want to risk deserializing 2000 full blocks.
49664948 unsigned int nCount = ReadCompactSize (vRecv);
49674949 if (nCount > MAX_HEADERS_RESULTS) {
4968- Misbehaving (*peer, 100 , strprintf (" headers message size = %u" , nCount));
4950+ Misbehaving (*peer, strprintf (" headers message size = %u" , nCount));
49694951 return ;
49704952 }
49714953 headers.resize (nCount);
@@ -5012,7 +4994,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
50124994 if (prev_block && IsBlockMutated (/* block=*/ *pblock,
50134995 /* check_witness_root=*/ DeploymentActiveAfter (prev_block, m_chainman, Consensus::DEPLOYMENT_SEGWIT))) {
50144996 LogDebug (BCLog::NET, " Received mutated block from peer=%d\n " , peer->m_id );
5015- Misbehaving (*peer, 100 , " mutated block" );
4997+ Misbehaving (*peer, " mutated block" );
50164998 WITH_LOCK (cs_main, RemoveBlockRequest (pblock->GetHash (), peer->m_id ));
50174999 return ;
50185000 }
@@ -5193,7 +5175,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
51935175 if (!filter.IsWithinSizeConstraints ())
51945176 {
51955177 // There is no excuse for sending a too-large filter
5196- Misbehaving (*peer, 100 , " too-large bloom filter" );
5178+ Misbehaving (*peer, " too-large bloom filter" );
51975179 } else if (auto tx_relay = peer->GetTxRelay (); tx_relay != nullptr ) {
51985180 {
51995181 LOCK (tx_relay->m_bloom_filter_mutex );
@@ -5229,7 +5211,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
52295211 }
52305212 }
52315213 if (bad) {
5232- Misbehaving (*peer, 100 , " bad filteradd message" );
5214+ Misbehaving (*peer, " bad filteradd message" );
52335215 }
52345216 return ;
52355217 }
0 commit comments