net: rename DEFAULT_BANSCORE_THRESHOLD to DISCOURAGEMENT_THRESHOLD

and move it from validation to net processing.
pull/19464/head
Jon Atack 4 years ago
parent 1d4024bca8
commit 06059b0c2a
No known key found for this signature in database
GPG Key ID: 4F5721B3D0E3921D

@ -1016,7 +1016,7 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
} }
/** /**
* Increment peer's misbehavior score. If the new value >= DEFAULT_BANSCORE_THRESHOLD, mark the node * Increment peer's misbehavior score. If the new value >= DISCOURAGEMENT_THRESHOLD, mark the node
* to be discouraged, meaning the peer might be disconnected and added to the discouragement filter. * to be discouraged, meaning the peer might be disconnected and added to the discouragement filter.
*/ */
void Misbehaving(NodeId pnode, int howmuch, const std::string& message) EXCLUSIVE_LOCKS_REQUIRED(cs_main) void Misbehaving(NodeId pnode, int howmuch, const std::string& message) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
@ -1030,7 +1030,7 @@ void Misbehaving(NodeId pnode, int howmuch, const std::string& message) EXCLUSIV
state->nMisbehavior += howmuch; state->nMisbehavior += howmuch;
std::string message_prefixed = message.empty() ? "" : (": " + message); std::string message_prefixed = message.empty() ? "" : (": " + message);
if (state->nMisbehavior >= DEFAULT_BANSCORE_THRESHOLD && state->nMisbehavior - howmuch < DEFAULT_BANSCORE_THRESHOLD) if (state->nMisbehavior >= DISCOURAGEMENT_THRESHOLD && state->nMisbehavior - howmuch < DISCOURAGEMENT_THRESHOLD)
{ {
LogPrint(BCLog::NET, "%s: %s peer=%d (%d -> %d) DISCOURAGE THRESHOLD EXCEEDED%s\n", __func__, state->name, pnode, state->nMisbehavior-howmuch, state->nMisbehavior, message_prefixed); LogPrint(BCLog::NET, "%s: %s peer=%d (%d -> %d) DISCOURAGE THRESHOLD EXCEEDED%s\n", __func__, state->name, pnode, state->nMisbehavior-howmuch, state->nMisbehavior, message_prefixed);
state->m_should_discourage = true; state->m_should_discourage = true;

@ -23,6 +23,8 @@ static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100; static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100;
static const bool DEFAULT_PEERBLOOMFILTERS = false; static const bool DEFAULT_PEERBLOOMFILTERS = false;
static const bool DEFAULT_PEERBLOCKFILTERS = false; static const bool DEFAULT_PEERBLOCKFILTERS = false;
/** Threshold for marking a node to be discouraged, e.g. disconnected and added to the discouragement filter. */
static const int DISCOURAGEMENT_THRESHOLD{100};
class PeerLogicValidation final : public CValidationInterface, public NetEventsInterface { class PeerLogicValidation final : public CValidationInterface, public NetEventsInterface {
private: private:

@ -232,14 +232,14 @@ BOOST_AUTO_TEST_CASE(DoS_banning)
dummyNode1.fSuccessfullyConnected = true; dummyNode1.fSuccessfullyConnected = true;
{ {
LOCK(cs_main); LOCK(cs_main);
Misbehaving(dummyNode1.GetId(), DEFAULT_BANSCORE_THRESHOLD); // Should get banned Misbehaving(dummyNode1.GetId(), DISCOURAGEMENT_THRESHOLD); // Should be discouraged
} }
{ {
LOCK2(cs_main, dummyNode1.cs_sendProcessing); LOCK2(cs_main, dummyNode1.cs_sendProcessing);
BOOST_CHECK(peerLogic->SendMessages(&dummyNode1)); BOOST_CHECK(peerLogic->SendMessages(&dummyNode1));
} }
BOOST_CHECK(banman->IsDiscouraged(addr1)); BOOST_CHECK(banman->IsDiscouraged(addr1));
BOOST_CHECK(!banman->IsDiscouraged(ip(0xa0b0c001|0x0000ff00))); // Different IP, not banned BOOST_CHECK(!banman->IsDiscouraged(ip(0xa0b0c001|0x0000ff00))); // Different IP, not discouraged
CAddress addr2(ip(0xa0b0c002), NODE_NONE); CAddress addr2(ip(0xa0b0c002), NODE_NONE);
CNode dummyNode2(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr2, 1, 1, CAddress(), "", true); CNode dummyNode2(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr2, 1, 1, CAddress(), "", true);
@ -255,7 +255,7 @@ BOOST_AUTO_TEST_CASE(DoS_banning)
LOCK2(cs_main, dummyNode2.cs_sendProcessing); LOCK2(cs_main, dummyNode2.cs_sendProcessing);
BOOST_CHECK(peerLogic->SendMessages(&dummyNode2)); BOOST_CHECK(peerLogic->SendMessages(&dummyNode2));
} }
BOOST_CHECK(!banman->IsDiscouraged(addr2)); // 2 not banned yet... BOOST_CHECK(!banman->IsDiscouraged(addr2)); // 2 not discouraged yet...
BOOST_CHECK(banman->IsDiscouraged(addr1)); // ... but 1 still should be BOOST_CHECK(banman->IsDiscouraged(addr1)); // ... but 1 still should be
{ {
LOCK(cs_main); LOCK(cs_main);
@ -287,7 +287,7 @@ BOOST_AUTO_TEST_CASE(DoS_banscore)
dummyNode1.fSuccessfullyConnected = true; dummyNode1.fSuccessfullyConnected = true;
{ {
LOCK(cs_main); LOCK(cs_main);
Misbehaving(dummyNode1.GetId(), DEFAULT_BANSCORE_THRESHOLD - 11); Misbehaving(dummyNode1.GetId(), DISCOURAGEMENT_THRESHOLD - 11);
} }
{ {
LOCK2(cs_main, dummyNode1.cs_sendProcessing); LOCK2(cs_main, dummyNode1.cs_sendProcessing);
@ -336,7 +336,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime)
{ {
LOCK(cs_main); LOCK(cs_main);
Misbehaving(dummyNode.GetId(), DEFAULT_BANSCORE_THRESHOLD); Misbehaving(dummyNode.GetId(), DISCOURAGEMENT_THRESHOLD);
} }
{ {
LOCK2(cs_main, dummyNode.cs_sendProcessing); LOCK2(cs_main, dummyNode.cs_sendProcessing);

@ -74,7 +74,6 @@ static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
static const bool DEFAULT_CHECKPOINTS_ENABLED = true; static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
static const bool DEFAULT_TXINDEX = false; static const bool DEFAULT_TXINDEX = false;
static const char* const DEFAULT_BLOCKFILTERINDEX = "0"; static const char* const DEFAULT_BLOCKFILTERINDEX = "0";
static const int DEFAULT_BANSCORE_THRESHOLD = 100;
/** Default for -persistmempool */ /** Default for -persistmempool */
static const bool DEFAULT_PERSIST_MEMPOOL = true; static const bool DEFAULT_PERSIST_MEMPOOL = true;
/** Default for using fee filter */ /** Default for using fee filter */

@ -26,7 +26,7 @@ from test_framework.util import (
wait_until, wait_until,
) )
DEFAULT_BANSCORE_THRESHOLD = 100 DISCOURAGEMENT_THRESHOLD = 100
class CLazyNode(P2PInterface): class CLazyNode(P2PInterface):
@ -70,7 +70,7 @@ class CNodeNoVersionBan(CLazyNode):
# NOTE: implementation-specific check here. Remove if bitcoind ban behavior changes # NOTE: implementation-specific check here. Remove if bitcoind ban behavior changes
def on_open(self): def on_open(self):
super().on_open() super().on_open()
for _ in range(DEFAULT_BANSCORE_THRESHOLD): for _ in range(DISCOURAGEMENT_THRESHOLD):
self.send_message(msg_verack()) self.send_message(msg_verack())
# Node that never sends a version. This one just sits idle and hopes to receive # Node that never sends a version. This one just sits idle and hopes to receive

Loading…
Cancel
Save