0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

[rpc] Remove deprecated "whitelisted" field from getpeerinfo

This commit is contained in:
Amiti Uttarwar 2020-12-22 16:54:18 -08:00
parent 094c3beaa4
commit b1a936d4ae
5 changed files with 12 additions and 52 deletions

View file

@ -599,7 +599,6 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
X(mapRecvBytesPerMsgCmd); X(mapRecvBytesPerMsgCmd);
X(nRecvBytes); X(nRecvBytes);
} }
X(m_legacyWhitelisted);
X(m_permissionFlags); X(m_permissionFlags);
if (m_tx_relay != nullptr) { if (m_tx_relay != nullptr) {
LOCK(m_tx_relay->cs_feeFilter); LOCK(m_tx_relay->cs_feeFilter);
@ -1122,8 +1121,6 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
CNode* pnode = new CNode(id, nodeServices, GetBestHeight(), hSocket, addr, CalculateKeyedNetGroup(addr), nonce, addr_bind, "", ConnectionType::INBOUND, inbound_onion); CNode* pnode = new CNode(id, nodeServices, GetBestHeight(), hSocket, addr, CalculateKeyedNetGroup(addr), nonce, addr_bind, "", ConnectionType::INBOUND, inbound_onion);
pnode->AddRef(); pnode->AddRef();
pnode->m_permissionFlags = permissionFlags; pnode->m_permissionFlags = permissionFlags;
// If this flag is present, the user probably expect that RPC and QT report it as whitelisted (backward compatibility)
pnode->m_legacyWhitelisted = legacyWhitelisted;
pnode->m_prefer_evict = discouraged; pnode->m_prefer_evict = discouraged;
m_msgproc->InitializeNode(pnode); m_msgproc->InitializeNode(pnode);

View file

@ -710,7 +710,6 @@ public:
uint64_t nRecvBytes; uint64_t nRecvBytes;
mapMsgCmdSize mapRecvBytesPerMsgCmd; mapMsgCmdSize mapRecvBytesPerMsgCmd;
NetPermissionFlags m_permissionFlags; NetPermissionFlags m_permissionFlags;
bool m_legacyWhitelisted;
int64_t m_ping_usec; int64_t m_ping_usec;
int64_t m_ping_wait_usec; int64_t m_ping_wait_usec;
int64_t m_min_ping_usec; int64_t m_min_ping_usec;
@ -891,8 +890,6 @@ public:
bool HasPermission(NetPermissionFlags permission) const { bool HasPermission(NetPermissionFlags permission) const {
return NetPermissions::HasFlag(m_permissionFlags, permission); return NetPermissions::HasFlag(m_permissionFlags, permission);
} }
// This boolean is unusued in actual processing, only present for backward compatibility at RPC/QT level
bool m_legacyWhitelisted{false};
bool fClient{false}; // set by version message bool fClient{false}; // set by version message
bool m_limited_node{false}; //after BIP159, set by version message bool m_limited_node{false}; //after BIP159, set by version message
/** /**

View file

@ -138,8 +138,6 @@ static RPCHelpMan getpeerinfo()
{ {
{RPCResult::Type::NUM, "n", "The heights of blocks we're currently asking from this peer"}, {RPCResult::Type::NUM, "n", "The heights of blocks we're currently asking from this peer"},
}}, }},
{RPCResult::Type::BOOL, "whitelisted", /* optional */ true, "Whether the peer is whitelisted with default permissions\n"
"(DEPRECATED, returned only if config option -deprecatedrpc=whitelisted is passed)"},
{RPCResult::Type::ARR, "permissions", "Any special permissions that have been granted to this peer", {RPCResult::Type::ARR, "permissions", "Any special permissions that have been granted to this peer",
{ {
{RPCResult::Type::STR, "permission_type", Join(NET_PERMISSIONS_DOC, ",\n") + ".\n"}, {RPCResult::Type::STR, "permission_type", Join(NET_PERMISSIONS_DOC, ",\n") + ".\n"},
@ -231,10 +229,6 @@ static RPCHelpMan getpeerinfo()
} }
obj.pushKV("inflight", heights); obj.pushKV("inflight", heights);
} }
if (IsDeprecatedRPCEnabled("whitelisted")) {
// whitelisted is deprecated in v0.21 for removal in v0.22
obj.pushKV("whitelisted", stats.m_legacyWhitelisted);
}
UniValue permissions(UniValue::VARR); UniValue permissions(UniValue::VARR);
for (const auto& permission : NetPermissions::ToStrings(stats.m_permissionFlags)) { for (const auto& permission : NetPermissions::ToStrings(stats.m_permissionFlags)) {
permissions.push_back(permission); permissions.push_back(permission);

View file

@ -59,7 +59,7 @@ class P2PBlocksOnly(BitcoinTestFramework):
self.log.info('Check that txs from peers with relay-permission are not rejected and relayed to others') self.log.info('Check that txs from peers with relay-permission are not rejected and relayed to others')
self.log.info("Restarting node 0 with relay permission and blocksonly") self.log.info("Restarting node 0 with relay permission and blocksonly")
self.restart_node(0, ["-persistmempool=0", "-whitelist=relay@127.0.0.1", "-blocksonly", '-deprecatedrpc=whitelisted']) self.restart_node(0, ["-persistmempool=0", "-whitelist=relay@127.0.0.1", "-blocksonly"])
assert_equal(self.nodes[0].getrawmempool(), []) assert_equal(self.nodes[0].getrawmempool(), [])
first_peer = self.nodes[0].add_p2p_connection(P2PInterface()) first_peer = self.nodes[0].add_p2p_connection(P2PInterface())
second_peer = self.nodes[0].add_p2p_connection(P2PInterface()) second_peer = self.nodes[0].add_p2p_connection(P2PInterface())

View file

@ -38,35 +38,24 @@ class P2PPermissionsTests(BitcoinTestFramework):
# default permissions (no specific permissions) # default permissions (no specific permissions)
["-whitelist=127.0.0.1"], ["-whitelist=127.0.0.1"],
# Make sure the default values in the command line documentation match the ones here # Make sure the default values in the command line documentation match the ones here
["relay", "noban", "mempool", "download"], ["relay", "noban", "mempool", "download"])
True)
self.checkpermission(
# check without deprecatedrpc=whitelisted
["-whitelist=127.0.0.1"],
# Make sure the default values in the command line documentation match the ones here
["relay", "noban", "mempool", "download"],
None)
self.checkpermission( self.checkpermission(
# no permission (even with forcerelay) # no permission (even with forcerelay)
["-whitelist=@127.0.0.1", "-whitelistforcerelay=1"], ["-whitelist=@127.0.0.1", "-whitelistforcerelay=1"],
[], [])
False)
self.checkpermission( self.checkpermission(
# relay permission removed (no specific permissions) # relay permission removed (no specific permissions)
["-whitelist=127.0.0.1", "-whitelistrelay=0"], ["-whitelist=127.0.0.1", "-whitelistrelay=0"],
["noban", "mempool", "download"], ["noban", "mempool", "download"])
True)
self.checkpermission( self.checkpermission(
# forcerelay and relay permission added # forcerelay and relay permission added
# Legacy parameter interaction which set whitelistrelay to true # Legacy parameter interaction which set whitelistrelay to true
# if whitelistforcerelay is true # if whitelistforcerelay is true
["-whitelist=127.0.0.1", "-whitelistforcerelay"], ["-whitelist=127.0.0.1", "-whitelistforcerelay"],
["forcerelay", "relay", "noban", "mempool", "download"], ["forcerelay", "relay", "noban", "mempool", "download"])
True)
# Let's make sure permissions are merged correctly # Let's make sure permissions are merged correctly
# For this, we need to use whitebind instead of bind # For this, we need to use whitebind instead of bind
@ -76,39 +65,28 @@ class P2PPermissionsTests(BitcoinTestFramework):
self.checkpermission( self.checkpermission(
["-whitelist=noban@127.0.0.1"], ["-whitelist=noban@127.0.0.1"],
# Check parameter interaction forcerelay should activate relay # Check parameter interaction forcerelay should activate relay
["noban", "bloomfilter", "forcerelay", "relay", "download"], ["noban", "bloomfilter", "forcerelay", "relay", "download"])
False)
self.replaceinconfig(1, "whitebind=bloomfilter,forcerelay@" + ip_port, "bind=127.0.0.1") self.replaceinconfig(1, "whitebind=bloomfilter,forcerelay@" + ip_port, "bind=127.0.0.1")
self.checkpermission( self.checkpermission(
# legacy whitelistrelay should be ignored # legacy whitelistrelay should be ignored
["-whitelist=noban,mempool@127.0.0.1", "-whitelistrelay"], ["-whitelist=noban,mempool@127.0.0.1", "-whitelistrelay"],
["noban", "mempool", "download"], ["noban", "mempool", "download"])
False)
self.checkpermission(
# check without deprecatedrpc=whitelisted
["-whitelist=noban,mempool@127.0.0.1", "-whitelistrelay"],
["noban", "mempool", "download"],
None)
self.checkpermission( self.checkpermission(
# legacy whitelistforcerelay should be ignored # legacy whitelistforcerelay should be ignored
["-whitelist=noban,mempool@127.0.0.1", "-whitelistforcerelay"], ["-whitelist=noban,mempool@127.0.0.1", "-whitelistforcerelay"],
["noban", "mempool", "download"], ["noban", "mempool", "download"])
False)
self.checkpermission( self.checkpermission(
# missing mempool permission to be considered legacy whitelisted # missing mempool permission to be considered legacy whitelisted
["-whitelist=noban@127.0.0.1"], ["-whitelist=noban@127.0.0.1"],
["noban", "download"], ["noban", "download"])
False)
self.checkpermission( self.checkpermission(
# all permission added # all permission added
["-whitelist=all@127.0.0.1"], ["-whitelist=all@127.0.0.1"],
["forcerelay", "noban", "mempool", "bloomfilter", "relay", "download", "addr"], ["forcerelay", "noban", "mempool", "bloomfilter", "relay", "download", "addr"])
False)
self.stop_node(1) self.stop_node(1)
self.nodes[1].assert_start_raises_init_error(["-whitelist=oopsie@127.0.0.1"], "Invalid P2P permission", match=ErrorMatch.PARTIAL_REGEX) self.nodes[1].assert_start_raises_init_error(["-whitelist=oopsie@127.0.0.1"], "Invalid P2P permission", match=ErrorMatch.PARTIAL_REGEX)
@ -169,19 +147,13 @@ class P2PPermissionsTests(BitcoinTestFramework):
reject_reason='Not relaying non-mempool transaction {} from forcerelay peer=0'.format(txid) reject_reason='Not relaying non-mempool transaction {} from forcerelay peer=0'.format(txid)
) )
def checkpermission(self, args, expectedPermissions, whitelisted): def checkpermission(self, args, expectedPermissions):
if whitelisted is not None:
args = [*args, '-deprecatedrpc=whitelisted']
self.restart_node(1, args) self.restart_node(1, args)
self.connect_nodes(0, 1) self.connect_nodes(0, 1)
peerinfo = self.nodes[1].getpeerinfo()[0] peerinfo = self.nodes[1].getpeerinfo()[0]
if whitelisted is None:
assert 'whitelisted' not in peerinfo
else:
assert_equal(peerinfo['whitelisted'], whitelisted)
assert_equal(len(expectedPermissions), len(peerinfo['permissions'])) assert_equal(len(expectedPermissions), len(peerinfo['permissions']))
for p in expectedPermissions: for p in expectedPermissions:
if not p in peerinfo['permissions']: if p not in peerinfo['permissions']:
raise AssertionError("Expected permissions %r is not granted." % p) raise AssertionError("Expected permissions %r is not granted." % p)
def replaceinconfig(self, nodeid, old, new): def replaceinconfig(self, nodeid, old, new):