Skip to content

Commit e424129

Browse files
MarcoFalkeknst
authored andcommitted
Merge bitcoin#19770: RPC: getpeerinfo: Deprecate "whitelisted" field (replaced by "permissions")
5b57dc5 RPC: getpeerinfo: Wrap long help line for bytesrecv_per_msg (Luke Dashjr) d681a28 RPC: getpeerinfo: Deprecate "whitelisted" field (replaced by "permissions") (Luke Dashjr) Pull request description: If we were going to continue support for "whitelisted", we should have probably made it true if any permission flag was set, rather than only if "default permissions" were used. This corrects the description, and deprecates it. ACKs for top commit: laanwj: ACK 5b57dc5 Tree-SHA512: a2e2137f8be8110357c1b2fef2c923fa8c7c4a49b0b2b3a2d78aedf12f8ed5cc7e140018a21b37e6ec7770ed4007542aeef7ad4558973901b107e8e0f81d6003
1 parent f96966b commit e424129

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

src/rpc/net.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ static RPCHelpMan getpeerinfo()
159159
{RPCResult::Type::BOOL, "addr_relay_enabled", "Whether we participate in address relay with this peer"},
160160
{RPCResult::Type::NUM, "addr_processed", "The total number of addresses processed, excluding those dropped due to rate limiting"},
161161
{RPCResult::Type::NUM, "addr_rate_limited", "The total number of addresses dropped due to rate limiting"},
162-
{RPCResult::Type::BOOL, "whitelisted", "Whether the peer is whitelisted"},
162+
{RPCResult::Type::BOOL, "whitelisted", /* optional */ true, "Whether the peer is whitelisted with default permissions\n"
163+
"(DEPRECATED, returned only if config option -deprecatedrpc=whitelisted is passed)"},
163164
{RPCResult::Type::ARR, "permissions", "Any special permissions that have been granted to this peer",
164165
{
165166
{RPCResult::Type::STR, "permission_type", Join(NET_PERMISSIONS_DOC, ",\n") + ".\n"},
@@ -244,7 +245,7 @@ static RPCHelpMan getpeerinfo()
244245
obj.pushKV("subver", stats.cleanSubVer);
245246
obj.pushKV("inbound", stats.fInbound);
246247
if (IsDeprecatedRPCEnabled("getpeerinfo_addnode")) {
247-
// addnode is deprecated in v0.21 for removal in v0.22
248+
// addnode is deprecated in v21 for removal in v22
248249
obj.pushKV("addnode", stats.m_manual_connection);
249250
}
250251
obj.pushKV("masternode", stats.m_masternode_connection);
@@ -266,7 +267,10 @@ static RPCHelpMan getpeerinfo()
266267
obj.pushKV("addr_processed", statestats.m_addr_processed);
267268
obj.pushKV("addr_rate_limited", statestats.m_addr_rate_limited);
268269
}
269-
obj.pushKV("whitelisted", stats.m_legacyWhitelisted);
270+
if (IsDeprecatedRPCEnabled("whitelisted")) {
271+
// whitelisted is deprecated in v0.21 for removal in v0.22
272+
obj.pushKV("whitelisted", stats.m_legacyWhitelisted);
273+
}
270274
UniValue permissions(UniValue::VARR);
271275
for (const auto& permission : NetPermissions::ToStrings(stats.m_permissionFlags)) {
272276
permissions.push_back(permission);

test/functional/p2p_blocksonly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def blocksonly_mode_tests(self):
4343
assert_equal(self.nodes[0].getmempoolinfo()['size'], 1)
4444

4545
self.log.info("Restarting node 0 with relay permission and blocksonly")
46-
self.restart_node(0, ["-persistmempool=0", "[email protected]", "-blocksonly"])
46+
self.restart_node(0, ["-persistmempool=0", "[email protected]", "-blocksonly", '-deprecatedrpc=whitelisted'])
4747
assert_equal(self.nodes[0].getrawmempool(), [])
4848
first_peer = self.nodes[0].add_p2p_connection(P2PInterface())
4949
second_peer = self.nodes[0].add_p2p_connection(P2PInterface())

test/functional/p2p_permissions.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ def run_test(self):
3939
["relay", "noban", "mempool", "download"],
4040
True)
4141

42+
self.checkpermission(
43+
# check without deprecatedrpc=whitelisted
44+
["-whitelist=127.0.0.1"],
45+
# Make sure the default values in the command line documentation match the ones here
46+
["relay", "noban", "mempool", "download"],
47+
None)
48+
4249
self.checkpermission(
4350
# no permission (even with forcerelay)
4451
["[email protected]", "-whitelistforcerelay=1"],
@@ -77,6 +84,12 @@ def run_test(self):
7784
["noban", "mempool", "download"],
7885
False)
7986

87+
self.checkpermission(
88+
# check without deprecatedrpc=whitelisted
89+
["-whitelist=noban,[email protected]", "-whitelistrelay"],
90+
["noban", "mempool", "download"],
91+
None)
92+
8093
self.checkpermission(
8194
# legacy whitelistforcerelay should be ignored
8295
["-whitelist=noban,[email protected]", "-whitelistforcerelay"],
@@ -159,10 +172,15 @@ def in_mempool():
159172
)
160173

161174
def checkpermission(self, args, expectedPermissions, whitelisted):
175+
if whitelisted is not None:
176+
args = [*args, '-deprecatedrpc=whitelisted']
162177
self.restart_node(1, args)
163178
self.connect_nodes(0, 1)
164179
peerinfo = self.nodes[1].getpeerinfo()[0]
165-
assert_equal(peerinfo['whitelisted'], whitelisted)
180+
if whitelisted is None:
181+
assert 'whitelisted' not in peerinfo
182+
else:
183+
assert_equal(peerinfo['whitelisted'], whitelisted)
166184
assert_equal(len(expectedPermissions), len(peerinfo['permissions']))
167185
for p in expectedPermissions:
168186
if not p in peerinfo['permissions']:

0 commit comments

Comments
 (0)