From 5456be67800007cd2654ab3961cf506905317029 Mon Sep 17 00:00:00 2001 From: Odysseas Gabrielides Date: Wed, 29 Mar 2023 19:23:45 +0300 Subject: [PATCH] feat(rpc): Added RPC cleardiscouraged (#5273) ## Issue being fixed or feature implemented ## What was done? Added RPC `cleardiscouraged` which clears internally the list of discouraged peers. Note: Implementation of a `listdiscouraged` RPC is not possible because the internal data structure used for discouraged peers is a Bloom filter. ## How Has This Been Tested? ## Breaking Changes ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [x] I have made corresponding changes to the documentation **For repository code-owners and collaborators only** - [x] I have assigned this pull request to a milestone --- doc/release-notes-5273.md | 5 +++++ src/banman.cpp | 10 ++++++++++ src/banman.h | 1 + src/rpc/net.cpp | 22 ++++++++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 doc/release-notes-5273.md diff --git a/doc/release-notes-5273.md b/doc/release-notes-5273.md new file mode 100644 index 0000000000..16bd0c88dc --- /dev/null +++ b/doc/release-notes-5273.md @@ -0,0 +1,5 @@ +Added RPCs +-------- + +- `cleardiscouraged` clears all the already discouraged peers. + diff --git a/src/banman.cpp b/src/banman.cpp index 48973e9c4a..807ad19faa 100644 --- a/src/banman.cpp +++ b/src/banman.cpp @@ -68,6 +68,16 @@ void BanMan::ClearBanned() if (m_client_interface) m_client_interface->BannedListChanged(); } +void BanMan::ClearDiscouraged() +{ + { + LOCK(m_cs_banned); + m_discouraged.reset(); + m_is_dirty = true; + } + if (m_client_interface) m_client_interface->BannedListChanged(); +} + bool BanMan::IsDiscouraged(const CNetAddr& net_addr) { LOCK(m_cs_banned); diff --git a/src/banman.h b/src/banman.h index 6b972c84e2..ca46677e3e 100644 --- a/src/banman.h +++ b/src/banman.h @@ -63,6 +63,7 @@ public: void Ban(const CSubNet& sub_net, int64_t ban_time_offset = 0, bool since_unix_epoch = false); void Discourage(const CNetAddr& net_addr); void ClearBanned(); + void ClearDiscouraged(); //! Return whether net_addr is banned bool IsBanned(const CNetAddr& net_addr); diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index eca3d2179c..8db4721c19 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -736,6 +736,27 @@ static UniValue clearbanned(const JSONRPCRequest& request) return NullUniValue; } +static UniValue cleardiscouraged(const JSONRPCRequest& request) +{ + RPCHelpMan{"cleardiscouraged", + "\nClear all discouraged nodes.\n", + {}, + RPCResult{RPCResult::Type::NONE, "", ""}, + RPCExamples{ + HelpExampleCli("cleardiscouraged", "") + + HelpExampleRpc("cleardiscouraged", "") + }, + }.Check(request); + NodeContext& node = EnsureNodeContext(request.context); + if (!node.banman) { + throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded"); + } + + node.banman->ClearDiscouraged(); + + return NullUniValue; +} + static UniValue setnetworkactive(const JSONRPCRequest& request) { RPCHelpMan{"setnetworkactive", @@ -825,6 +846,7 @@ static const CRPCCommand commands[] = { "network", "setban", &setban, {"subnet", "command", "bantime", "absolute"} }, { "network", "listbanned", &listbanned, {} }, { "network", "clearbanned", &clearbanned, {} }, + { "network", "cleardiscouraged", &cleardiscouraged, {} }, { "network", "setnetworkactive", &setnetworkactive, {"state"} }, { "network", "getnodeaddresses", &getnodeaddresses, {"count"} }, };