mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
Replace automatic bans with discouragement filter
This patch improves performance and resource usage around IP addresses that are banned for misbehavior. They're already not actually banned, as connections from them are still allowed, but they are preferred for eviction if the inbound connection slots are full. Stop treating these like manually banned IP ranges, and instead just keep them in a rolling Bloom filter of misbehaving nodes, which isn't persisted to disk or exposed through the ban framework. The effect remains the same: preferred for eviction, avoided for outgoing connections, and not relayed to other peers. Also change the name of this mechanism to better reflect reality; they're not banned, just discouraged. Contains release notes and several interface improvements by John Newbery.
This commit is contained in:
@@ -601,7 +601,8 @@ static UniValue setban(const JSONRPCRequest& request)
|
||||
|
||||
if (strCommand == "add")
|
||||
{
|
||||
if (isSubnet ? node.banman->IsBanned(subNet) : node.banman->IsBanned(netAddr)) {
|
||||
if ((isSubnet && node.banman->IsBanned(subNet)) ||
|
||||
(!isSubnet && node.banman->IsBannedLevel(netAddr) == BanReasonManuallyAdded)) {
|
||||
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: IP/Subnet already banned");
|
||||
}
|
||||
|
||||
@@ -628,7 +629,7 @@ static UniValue setban(const JSONRPCRequest& request)
|
||||
else if(strCommand == "remove")
|
||||
{
|
||||
if (!( isSubnet ? node.banman->Unban(subNet) : node.banman->Unban(netAddr) )) {
|
||||
throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, "Error: Unban failed. Requested address/subnet was not previously banned.");
|
||||
throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, "Error: Unban failed. Requested address/subnet was not previously manually banned.");
|
||||
}
|
||||
}
|
||||
return NullUniValue;
|
||||
@@ -637,7 +638,7 @@ static UniValue setban(const JSONRPCRequest& request)
|
||||
static UniValue listbanned(const JSONRPCRequest& request)
|
||||
{
|
||||
RPCHelpMan{"listbanned",
|
||||
"\nList all banned IPs/Subnets.\n",
|
||||
"\nList all manually banned IPs/Subnets.\n",
|
||||
{},
|
||||
RPCResult{RPCResult::Type::ARR, "", "",
|
||||
{
|
||||
@@ -646,7 +647,6 @@ static UniValue listbanned(const JSONRPCRequest& request)
|
||||
{RPCResult::Type::STR, "address", ""},
|
||||
{RPCResult::Type::NUM_TIME, "banned_until", ""},
|
||||
{RPCResult::Type::NUM_TIME, "ban_created", ""},
|
||||
{RPCResult::Type::STR, "ban_reason", ""},
|
||||
}},
|
||||
}},
|
||||
RPCExamples{
|
||||
@@ -671,7 +671,6 @@ static UniValue listbanned(const JSONRPCRequest& request)
|
||||
rec.pushKV("address", entry.first.ToString());
|
||||
rec.pushKV("banned_until", banEntry.nBanUntil);
|
||||
rec.pushKV("ban_created", banEntry.nCreateTime);
|
||||
rec.pushKV("ban_reason", banEntry.banReasonToString());
|
||||
|
||||
bannedAddresses.push_back(rec);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user