@@ -223,8 +223,6 @@ struct Peer {
223
223
224
224
/* * Protects misbehavior data members */
225
225
Mutex m_misbehavior_mutex;
226
- /* * Accumulated misbehavior score for this peer */
227
- int m_misbehavior_score GUARDED_BY (m_misbehavior_mutex){0 };
228
226
/* * Whether this peer should be disconnected and marked as discouraged (unless it has NetPermissionFlags::NoBan permission). */
229
227
bool m_should_discourage GUARDED_BY (m_misbehavior_mutex){false };
230
228
@@ -521,7 +519,7 @@ class PeerManagerImpl final : public PeerManager
521
519
m_best_height = height;
522
520
m_best_block_time = time;
523
521
};
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)), " " ); };
525
523
void ProcessMessage (CNode& pfrom, const std::string& msg_type, DataStream& vRecv,
526
524
const std::chrono::microseconds time_received, const std::atomic<bool >& interruptMsgProc) override
527
525
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
546
544
* May return an empty shared_ptr if the Peer object can't be found. */
547
545
PeerRef RemovePeer (NodeId id) EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
548
546
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);
554
550
555
551
/* *
556
552
* Potentially mark a node discouraged based on the contents of a BlockValidationState object
@@ -1711,7 +1707,6 @@ void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler)
1711
1707
void PeerManagerImpl::FinalizeNode (const CNode& node)
1712
1708
{
1713
1709
NodeId nodeid = node.GetId ();
1714
- int misbehavior{0 };
1715
1710
{
1716
1711
LOCK (cs_main);
1717
1712
{
@@ -1722,7 +1717,6 @@ void PeerManagerImpl::FinalizeNode(const CNode& node)
1722
1717
// destructed.
1723
1718
PeerRef peer = RemovePeer (nodeid);
1724
1719
assert (peer != nullptr );
1725
- misbehavior = WITH_LOCK (peer->m_misbehavior_mutex , return peer->m_misbehavior_score );
1726
1720
m_wtxid_relay_peers -= peer->m_wtxid_relay ;
1727
1721
assert (m_wtxid_relay_peers >= 0 );
1728
1722
}
@@ -1765,7 +1759,7 @@ void PeerManagerImpl::FinalizeNode(const CNode& node)
1765
1759
assert (m_orphanage.Size () == 0 );
1766
1760
}
1767
1761
} // cs_main
1768
- if (node.fSuccessfullyConnected && misbehavior == 0 &&
1762
+ if (node.fSuccessfullyConnected &&
1769
1763
!node.IsBlockOnlyConn () && !node.IsInboundConn ()) {
1770
1764
// Only change visible addrman state for full outbound peers. We don't
1771
1765
// call Connected() for feeler connections since they don't have
@@ -1886,25 +1880,13 @@ void PeerManagerImpl::AddToCompactExtraTransactions(const CTransactionRef& tx)
1886
1880
vExtraTxnForCompactIt = (vExtraTxnForCompactIt + 1 ) % m_opts.max_extra_txs ;
1887
1881
}
1888
1882
1889
- void PeerManagerImpl::Misbehaving (Peer& peer, int howmuch, const std::string& message)
1883
+ void PeerManagerImpl::Misbehaving (Peer& peer, const std::string& message)
1890
1884
{
1891
- assert (howmuch > 0 );
1892
-
1893
1885
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 };
1897
1886
1898
1887
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);
1908
1890
}
1909
1891
1910
1892
bool PeerManagerImpl::MaybePunishNodeForBlock (NodeId nodeid, const BlockValidationState& state,
@@ -1922,7 +1904,7 @@ bool PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati
1922
1904
case BlockValidationResult::BLOCK_CONSENSUS:
1923
1905
case BlockValidationResult::BLOCK_MUTATED:
1924
1906
if (!via_compact_block) {
1925
- if (peer) Misbehaving (*peer, 100 , message);
1907
+ if (peer) Misbehaving (*peer, message);
1926
1908
return true ;
1927
1909
}
1928
1910
break ;
@@ -1937,19 +1919,19 @@ bool PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati
1937
1919
// Discourage outbound (but not inbound) peers if on an invalid chain.
1938
1920
// Exempt HB compact block peers. Manual connections are always protected from discouragement.
1939
1921
if (!via_compact_block && !node_state->m_is_inbound ) {
1940
- if (peer) Misbehaving (*peer, 100 , message);
1922
+ if (peer) Misbehaving (*peer, message);
1941
1923
return true ;
1942
1924
}
1943
1925
break ;
1944
1926
}
1945
1927
case BlockValidationResult::BLOCK_INVALID_HEADER:
1946
1928
case BlockValidationResult::BLOCK_CHECKPOINT:
1947
1929
case BlockValidationResult::BLOCK_INVALID_PREV:
1948
- if (peer) Misbehaving (*peer, 100 , message);
1930
+ if (peer) Misbehaving (*peer, message);
1949
1931
return true ;
1950
1932
// Conflicting (but not necessarily invalid) data or different policy:
1951
1933
case BlockValidationResult::BLOCK_MISSING_PREV:
1952
- if (peer) Misbehaving (*peer, 100 , message);
1934
+ if (peer) Misbehaving (*peer, message);
1953
1935
return true ;
1954
1936
case BlockValidationResult::BLOCK_RECENT_CONSENSUS_CHANGE:
1955
1937
case BlockValidationResult::BLOCK_TIME_FUTURE:
@@ -1969,7 +1951,7 @@ bool PeerManagerImpl::MaybePunishNodeForTx(NodeId nodeid, const TxValidationStat
1969
1951
break ;
1970
1952
// The node is providing invalid data:
1971
1953
case TxValidationResult::TX_CONSENSUS:
1972
- if (peer) Misbehaving (*peer, 100 , " " );
1954
+ if (peer) Misbehaving (*peer, " " );
1973
1955
return true ;
1974
1956
// Conflicting (but not necessarily invalid) data or different policy:
1975
1957
case TxValidationResult::TX_RECENT_CONSENSUS_CHANGE:
@@ -2670,7 +2652,7 @@ void PeerManagerImpl::SendBlockTransactions(CNode& pfrom, Peer& peer, const CBlo
2670
2652
BlockTransactions resp (req);
2671
2653
for (size_t i = 0 ; i < req.indexes .size (); i++) {
2672
2654
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" );
2674
2656
return ;
2675
2657
}
2676
2658
resp.txn [i] = block.vtx [req.indexes [i]];
@@ -2683,13 +2665,13 @@ bool PeerManagerImpl::CheckHeadersPoW(const std::vector<CBlockHeader>& headers,
2683
2665
{
2684
2666
// Do these headers have proof-of-work matching what's claimed?
2685
2667
if (!HasValidProofOfWork (headers, consensusParams)) {
2686
- Misbehaving (peer, 100 , " header with invalid proof of work" );
2668
+ Misbehaving (peer, " header with invalid proof of work" );
2687
2669
return false ;
2688
2670
}
2689
2671
2690
2672
// Are these headers connected to each other?
2691
2673
if (!CheckHeadersAreContinuous (headers)) {
2692
- Misbehaving (peer, 100 , " non-continuous headers sequence" );
2674
+ Misbehaving (peer, " non-continuous headers sequence" );
2693
2675
return false ;
2694
2676
}
2695
2677
return true ;
@@ -3622,7 +3604,7 @@ void PeerManagerImpl::ProcessCompactBlockTxns(CNode& pfrom, Peer& peer, const Bl
3622
3604
ReadStatus status = partialBlock.FillBlock (*pblock, block_transactions.txn );
3623
3605
if (status == READ_STATUS_INVALID) {
3624
3606
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" );
3626
3608
return ;
3627
3609
} else if (status == READ_STATUS_FAILED) {
3628
3610
if (first_in_flight) {
@@ -4106,7 +4088,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4106
4088
4107
4089
if (vAddr.size () > MAX_ADDR_TO_SEND)
4108
4090
{
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 ()));
4110
4092
return ;
4111
4093
}
4112
4094
@@ -4188,7 +4170,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4188
4170
vRecv >> vInv;
4189
4171
if (vInv.size () > MAX_INV_SZ)
4190
4172
{
4191
- Misbehaving (*peer, 100 , strprintf (" inv message size = %u" , vInv.size ()));
4173
+ Misbehaving (*peer, strprintf (" inv message size = %u" , vInv.size ()));
4192
4174
return ;
4193
4175
}
4194
4176
@@ -4280,7 +4262,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4280
4262
vRecv >> vInv;
4281
4263
if (vInv.size () > MAX_INV_SZ)
4282
4264
{
4283
- Misbehaving (*peer, 100 , strprintf (" getdata message size = %u" , vInv.size ()));
4265
+ Misbehaving (*peer, strprintf (" getdata message size = %u" , vInv.size ()));
4284
4266
return ;
4285
4267
}
4286
4268
@@ -4820,7 +4802,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4820
4802
ReadStatus status = partialBlock.InitData (cmpctblock, vExtraTxnForCompact);
4821
4803
if (status == READ_STATUS_INVALID) {
4822
4804
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" );
4824
4806
return ;
4825
4807
} else if (status == READ_STATUS_FAILED) {
4826
4808
if (first_in_flight) {
@@ -4965,7 +4947,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4965
4947
// Bypass the normal CBlock deserialization, as we don't want to risk deserializing 2000 full blocks.
4966
4948
unsigned int nCount = ReadCompactSize (vRecv);
4967
4949
if (nCount > MAX_HEADERS_RESULTS) {
4968
- Misbehaving (*peer, 100 , strprintf (" headers message size = %u" , nCount));
4950
+ Misbehaving (*peer, strprintf (" headers message size = %u" , nCount));
4969
4951
return ;
4970
4952
}
4971
4953
headers.resize (nCount);
@@ -5012,7 +4994,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
5012
4994
if (prev_block && IsBlockMutated (/* block=*/ *pblock,
5013
4995
/* check_witness_root=*/ DeploymentActiveAfter (prev_block, m_chainman, Consensus::DEPLOYMENT_SEGWIT))) {
5014
4996
LogDebug (BCLog::NET, " Received mutated block from peer=%d\n " , peer->m_id );
5015
- Misbehaving (*peer, 100 , " mutated block" );
4997
+ Misbehaving (*peer, " mutated block" );
5016
4998
WITH_LOCK (cs_main, RemoveBlockRequest (pblock->GetHash (), peer->m_id ));
5017
4999
return ;
5018
5000
}
@@ -5193,7 +5175,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
5193
5175
if (!filter.IsWithinSizeConstraints ())
5194
5176
{
5195
5177
// 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" );
5197
5179
} else if (auto tx_relay = peer->GetTxRelay (); tx_relay != nullptr ) {
5198
5180
{
5199
5181
LOCK (tx_relay->m_bloom_filter_mutex );
@@ -5229,7 +5211,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
5229
5211
}
5230
5212
}
5231
5213
if (bad) {
5232
- Misbehaving (*peer, 100 , " bad filteradd message" );
5214
+ Misbehaving (*peer, " bad filteradd message" );
5233
5215
}
5234
5216
return ;
5235
5217
}
0 commit comments