Skip to content

Commit b93c424

Browse files
author
MarcoFalke
committed
Merge #19464: net: remove -banscore configuration option
06059b0 net: rename DEFAULT_BANSCORE_THRESHOLD to DISCOURAGEMENT_THRESHOLD (Jon Atack) 1d4024b net: remove -banscore configuration option (Jon Atack) Pull request description: per bitcoin/bitcoin#19219 (comment), bitcoin/bitcoin#19219 (comment) and bitcoin/bitcoin#19219 (comment). Edit: now split into 3 straightforward PRs: - net: remove -banscore configuration option (this PR) - rpc: deprecate banscore field in getpeerinfo (#19469, *merged*) - gui: no longer display banscores (TBA in the gui repo) ACKs for top commit: MarcoFalke: review ACK 06059b0 📙 vasild: ACK 06059b0 Tree-SHA512: 03fad249986e0896697033fbb8ba2cbfaae7d7603b1fb2a38b3d41db697630d238623f4d732b9098c82af249ce5a1767dd432b7ca0fec10544e23d24fbd57c50
2 parents 5550fa5 + 06059b0 commit b93c424

File tree

7 files changed

+17
-15
lines changed

7 files changed

+17
-15
lines changed

doc/release-notes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ Build System
121121
Updated settings
122122
----------------
123123

124+
- The `-banscore` configuration option, which modified the default threshold for
125+
disconnecting and discouraging misbehaving peers, has been removed as part of
126+
changes in this release to the handling of misbehaving peers. Refer to the
127+
section, "Changes regarding misbehaving peers", for details. (#19464)
128+
124129
- The `-debug=db` logging category, which was deprecated in 0.20 and replaced by
125130
`-debug=walletdb` to distinguish it from `coindb`, has been removed. (#19202)
126131

src/init.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,6 @@ void SetupServerArgs(NodeContext& node)
431431

432432
gArgs.AddArg("-addnode=<ip>", "Add a node to connect to and attempt to keep the connection open (see the `addnode` RPC command help for more info). This option can be specified multiple times to add multiple nodes.", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::CONNECTION);
433433
gArgs.AddArg("-asmap=<file>", strprintf("Specify asn mapping used for bucketing of the peers (default: %s). Relative paths will be prefixed by the net-specific datadir location.", DEFAULT_ASMAP_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
434-
gArgs.AddArg("-banscore=<n>", strprintf("Threshold for disconnecting and discouraging misbehaving peers (default: %u)", DEFAULT_BANSCORE_THRESHOLD), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
435434
gArgs.AddArg("-bantime=<n>", strprintf("Default duration (in seconds) of manually configured bans (default: %u)", DEFAULT_MISBEHAVING_BANTIME), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
436435
gArgs.AddArg("-bind=<addr>", "Bind to given address and always listen on it. Use [host]:port notation for IPv6", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::CONNECTION);
437436
gArgs.AddArg("-connect=<ip>", "Connect only to the specified node; -noconnect disables automatic connections (the rules for this peer are the same as for -addnode). This option can be specified multiple times to connect to multiple nodes.", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::CONNECTION);

src/net_processing.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,8 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
10311031
}
10321032

10331033
/**
1034-
* Increment peer's misbehavior score. If the new value surpasses banscore (specified on startup or by default), mark node to be discouraged, meaning the peer might be disconnected & added to the discouragement filter.
1034+
* Increment peer's misbehavior score. If the new value >= DISCOURAGEMENT_THRESHOLD, mark the node
1035+
* to be discouraged, meaning the peer might be disconnected and added to the discouragement filter.
10351036
*/
10361037
void Misbehaving(NodeId pnode, int howmuch, const std::string& message) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
10371038
{
@@ -1043,9 +1044,8 @@ void Misbehaving(NodeId pnode, int howmuch, const std::string& message) EXCLUSIV
10431044
return;
10441045

10451046
state->nMisbehavior += howmuch;
1046-
int banscore = gArgs.GetArg("-banscore", DEFAULT_BANSCORE_THRESHOLD);
10471047
std::string message_prefixed = message.empty() ? "" : (": " + message);
1048-
if (state->nMisbehavior >= banscore && state->nMisbehavior - howmuch < banscore)
1048+
if (state->nMisbehavior >= DISCOURAGEMENT_THRESHOLD && state->nMisbehavior - howmuch < DISCOURAGEMENT_THRESHOLD)
10491049
{
10501050
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);
10511051
state->m_should_discourage = true;

src/net_processing.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
2323
static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100;
2424
static const bool DEFAULT_PEERBLOOMFILTERS = false;
2525
static const bool DEFAULT_PEERBLOCKFILTERS = false;
26+
/** Threshold for marking a node to be discouraged, e.g. disconnected and added to the discouragement filter. */
27+
static const int DISCOURAGEMENT_THRESHOLD{100};
2628

2729
class PeerLogicValidation final : public CValidationInterface, public NetEventsInterface {
2830
private:

src/test/denialofservice_tests.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,14 @@ BOOST_AUTO_TEST_CASE(DoS_banning)
232232
dummyNode1.fSuccessfullyConnected = true;
233233
{
234234
LOCK(cs_main);
235-
Misbehaving(dummyNode1.GetId(), 100); // Should get banned
235+
Misbehaving(dummyNode1.GetId(), DISCOURAGEMENT_THRESHOLD); // Should be discouraged
236236
}
237237
{
238238
LOCK2(cs_main, dummyNode1.cs_sendProcessing);
239239
BOOST_CHECK(peerLogic->SendMessages(&dummyNode1));
240240
}
241241
BOOST_CHECK(banman->IsDiscouraged(addr1));
242-
BOOST_CHECK(!banman->IsDiscouraged(ip(0xa0b0c001|0x0000ff00))); // Different IP, not banned
242+
BOOST_CHECK(!banman->IsDiscouraged(ip(0xa0b0c001|0x0000ff00))); // Different IP, not discouraged
243243

244244
CAddress addr2(ip(0xa0b0c002), NODE_NONE);
245245
CNode dummyNode2(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr2, 1, 1, CAddress(), "", true);
@@ -255,7 +255,7 @@ BOOST_AUTO_TEST_CASE(DoS_banning)
255255
LOCK2(cs_main, dummyNode2.cs_sendProcessing);
256256
BOOST_CHECK(peerLogic->SendMessages(&dummyNode2));
257257
}
258-
BOOST_CHECK(!banman->IsDiscouraged(addr2)); // 2 not banned yet...
258+
BOOST_CHECK(!banman->IsDiscouraged(addr2)); // 2 not discouraged yet...
259259
BOOST_CHECK(banman->IsDiscouraged(addr1)); // ... but 1 still should be
260260
{
261261
LOCK(cs_main);
@@ -279,7 +279,6 @@ BOOST_AUTO_TEST_CASE(DoS_banscore)
279279
auto peerLogic = MakeUnique<PeerLogicValidation>(connman.get(), banman.get(), *m_node.scheduler, *m_node.chainman, *m_node.mempool);
280280

281281
banman->ClearBanned();
282-
gArgs.ForceSetArg("-banscore", "111"); // because 11 is my favorite number
283282
CAddress addr1(ip(0xa0b0c001), NODE_NONE);
284283
CNode dummyNode1(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr1, 3, 1, CAddress(), "", true);
285284
dummyNode1.SetSendVersion(PROTOCOL_VERSION);
@@ -288,7 +287,7 @@ BOOST_AUTO_TEST_CASE(DoS_banscore)
288287
dummyNode1.fSuccessfullyConnected = true;
289288
{
290289
LOCK(cs_main);
291-
Misbehaving(dummyNode1.GetId(), 100);
290+
Misbehaving(dummyNode1.GetId(), DISCOURAGEMENT_THRESHOLD - 11);
292291
}
293292
{
294293
LOCK2(cs_main, dummyNode1.cs_sendProcessing);
@@ -313,7 +312,6 @@ BOOST_AUTO_TEST_CASE(DoS_banscore)
313312
BOOST_CHECK(peerLogic->SendMessages(&dummyNode1));
314313
}
315314
BOOST_CHECK(banman->IsDiscouraged(addr1));
316-
gArgs.ForceSetArg("-banscore", ToString(DEFAULT_BANSCORE_THRESHOLD));
317315

318316
bool dummy;
319317
peerLogic->FinalizeNode(dummyNode1.GetId(), dummy);
@@ -338,7 +336,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime)
338336

339337
{
340338
LOCK(cs_main);
341-
Misbehaving(dummyNode.GetId(), 100);
339+
Misbehaving(dummyNode.GetId(), DISCOURAGEMENT_THRESHOLD);
342340
}
343341
{
344342
LOCK2(cs_main, dummyNode.cs_sendProcessing);

src/validation.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
7474
static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
7575
static const bool DEFAULT_TXINDEX = false;
7676
static const char* const DEFAULT_BLOCKFILTERINDEX = "0";
77-
static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100;
7877
/** Default for -persistmempool */
7978
static const bool DEFAULT_PERSIST_MEMPOOL = true;
8079
/** Default for using fee filter */

test/functional/p2p_leak.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
wait_until,
2727
)
2828

29-
banscore = 10
29+
DISCOURAGEMENT_THRESHOLD = 100
3030

3131

3232
class CLazyNode(P2PInterface):
@@ -70,7 +70,7 @@ class CNodeNoVersionBan(CLazyNode):
7070
# NOTE: implementation-specific check here. Remove if bitcoind ban behavior changes
7171
def on_open(self):
7272
super().on_open()
73-
for i in range(banscore):
73+
for _ in range(DISCOURAGEMENT_THRESHOLD):
7474
self.send_message(msg_verack())
7575

7676
# Node that never sends a version. This one just sits idle and hopes to receive
@@ -106,7 +106,6 @@ def on_version(self, msg):
106106
class P2PLeakTest(BitcoinTestFramework):
107107
def set_test_params(self):
108108
self.num_nodes = 1
109-
self.extra_args = [['-banscore=' + str(banscore)]]
110109

111110
def run_test(self):
112111
no_version_bannode = self.nodes[0].add_p2p_connection(CNodeNoVersionBan(), send_version=False, wait_for_verack=False)

0 commit comments

Comments
 (0)