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
This commit is contained in:
Odysseas Gabrielides 2023-03-29 19:23:45 +03:00 committed by GitHub
parent 7f520f5c95
commit 5456be6780
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,5 @@
Added RPCs
--------
- `cleardiscouraged` clears all the already discouraged peers.

View File

@ -68,6 +68,16 @@ void BanMan::ClearBanned()
if (m_client_interface) m_client_interface->BannedListChanged(); 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) bool BanMan::IsDiscouraged(const CNetAddr& net_addr)
{ {
LOCK(m_cs_banned); LOCK(m_cs_banned);

View File

@ -63,6 +63,7 @@ public:
void Ban(const CSubNet& sub_net, int64_t ban_time_offset = 0, bool since_unix_epoch = false); void Ban(const CSubNet& sub_net, int64_t ban_time_offset = 0, bool since_unix_epoch = false);
void Discourage(const CNetAddr& net_addr); void Discourage(const CNetAddr& net_addr);
void ClearBanned(); void ClearBanned();
void ClearDiscouraged();
//! Return whether net_addr is banned //! Return whether net_addr is banned
bool IsBanned(const CNetAddr& net_addr); bool IsBanned(const CNetAddr& net_addr);

View File

@ -736,6 +736,27 @@ static UniValue clearbanned(const JSONRPCRequest& request)
return NullUniValue; 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) static UniValue setnetworkactive(const JSONRPCRequest& request)
{ {
RPCHelpMan{"setnetworkactive", RPCHelpMan{"setnetworkactive",
@ -825,6 +846,7 @@ static const CRPCCommand commands[] =
{ "network", "setban", &setban, {"subnet", "command", "bantime", "absolute"} }, { "network", "setban", &setban, {"subnet", "command", "bantime", "absolute"} },
{ "network", "listbanned", &listbanned, {} }, { "network", "listbanned", &listbanned, {} },
{ "network", "clearbanned", &clearbanned, {} }, { "network", "clearbanned", &clearbanned, {} },
{ "network", "cleardiscouraged", &cleardiscouraged, {} },
{ "network", "setnetworkactive", &setnetworkactive, {"state"} }, { "network", "setnetworkactive", &setnetworkactive, {"state"} },
{ "network", "getnodeaddresses", &getnodeaddresses, {"count"} }, { "network", "getnodeaddresses", &getnodeaddresses, {"count"} },
}; };