diff options
author | Jon Atack <jon@atack.com> | 2020-07-08 09:33:30 +0200 |
---|---|---|
committer | Jon Atack <jon@atack.com> | 2020-07-11 19:41:24 +0200 |
commit | 06059b0c2a6c2db70c87a7715f8a344a13400fa1 (patch) | |
tree | a0f7c09df27c25e8a3c624f6b3ad1334670105e9 /src | |
parent | 1d4024bca8086cceff7539dd8c15e0b7fe1cc5ea (diff) |
net: rename DEFAULT_BANSCORE_THRESHOLD to DISCOURAGEMENT_THRESHOLD
and move it from validation to net processing.
Diffstat (limited to 'src')
-rw-r--r-- | src/net_processing.cpp | 4 | ||||
-rw-r--r-- | src/net_processing.h | 2 | ||||
-rw-r--r-- | src/test/denialofservice_tests.cpp | 10 | ||||
-rw-r--r-- | src/validation.h | 1 |
4 files changed, 9 insertions, 8 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 0e0a8a5b48..bf8849025e 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -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. */ 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; 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); state->m_should_discourage = true; diff --git a/src/net_processing.h b/src/net_processing.h index eadf29e59f..3479ef6865 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -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 bool DEFAULT_PEERBLOOMFILTERS = 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 { private: diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp index 6f7effcce9..3d84fa855f 100644 --- a/src/test/denialofservice_tests.cpp +++ b/src/test/denialofservice_tests.cpp @@ -232,14 +232,14 @@ BOOST_AUTO_TEST_CASE(DoS_banning) dummyNode1.fSuccessfullyConnected = true; { 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); BOOST_CHECK(peerLogic->SendMessages(&dummyNode1)); } 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); 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); 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 { LOCK(cs_main); @@ -287,7 +287,7 @@ BOOST_AUTO_TEST_CASE(DoS_banscore) dummyNode1.fSuccessfullyConnected = true; { LOCK(cs_main); - Misbehaving(dummyNode1.GetId(), DEFAULT_BANSCORE_THRESHOLD - 11); + Misbehaving(dummyNode1.GetId(), DISCOURAGEMENT_THRESHOLD - 11); } { LOCK2(cs_main, dummyNode1.cs_sendProcessing); @@ -336,7 +336,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime) { LOCK(cs_main); - Misbehaving(dummyNode.GetId(), DEFAULT_BANSCORE_THRESHOLD); + Misbehaving(dummyNode.GetId(), DISCOURAGEMENT_THRESHOLD); } { LOCK2(cs_main, dummyNode.cs_sendProcessing); diff --git a/src/validation.h b/src/validation.h index 23ad4e20df..acadf151c5 100644 --- a/src/validation.h +++ b/src/validation.h @@ -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_TXINDEX = false; static const char* const DEFAULT_BLOCKFILTERINDEX = "0"; -static const int DEFAULT_BANSCORE_THRESHOLD = 100; /** Default for -persistmempool */ static const bool DEFAULT_PERSIST_MEMPOOL = true; /** Default for using fee filter */ |