Skip to content

Commit d681a28

Browse files
committed
RPC: getpeerinfo: Deprecate "whitelisted" field (replaced by "permissions")
1 parent 99a1d57 commit d681a28

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/rpc/net.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ static RPCHelpMan getpeerinfo()
127127
{
128128
{RPCResult::Type::NUM, "n", "The heights of blocks we're currently asking from this peer"},
129129
}},
130-
{RPCResult::Type::BOOL, "whitelisted", "Whether the peer is whitelisted"},
130+
{RPCResult::Type::BOOL, "whitelisted", /* optional */ true, "Whether the peer is whitelisted with default permissions\n"
131+
"(DEPRECATED, returned only if config option -deprecatedrpc=whitelisted is passed)"},
131132
{RPCResult::Type::NUM, "minfeefilter", "The minimum fee rate for transactions this peer accepts"},
132133
{RPCResult::Type::OBJ_DYN, "bytessent_per_msg", "",
133134
{
@@ -216,7 +217,10 @@ static RPCHelpMan getpeerinfo()
216217
}
217218
obj.pushKV("inflight", heights);
218219
}
219-
obj.pushKV("whitelisted", stats.m_legacyWhitelisted);
220+
if (IsDeprecatedRPCEnabled("whitelisted")) {
221+
// whitelisted is deprecated in v0.21 for removal in v0.22
222+
obj.pushKV("whitelisted", stats.m_legacyWhitelisted);
223+
}
220224
UniValue permissions(UniValue::VARR);
221225
for (const auto& permission : NetPermissions::ToStrings(stats.m_permissionFlags)) {
222226
permissions.push_back(permission);

test/functional/p2p_blocksonly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def run_test(self):
5959

6060
self.log.info('Check that txs from peers with relay-permission are not rejected and relayed to others')
6161
self.log.info("Restarting node 0 with relay permission and blocksonly")
62-
self.restart_node(0, ["-persistmempool=0", "[email protected]", "-blocksonly"])
62+
self.restart_node(0, ["-persistmempool=0", "[email protected]", "-blocksonly", '-deprecatedrpc=whitelisted'])
6363
assert_equal(self.nodes[0].getrawmempool(), [])
6464
first_peer = self.nodes[0].add_p2p_connection(P2PInterface())
6565
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
@@ -42,6 +42,13 @@ def run_test(self):
4242
["relay", "noban", "mempool", "download"],
4343
True)
4444

45+
self.checkpermission(
46+
# check without deprecatedrpc=whitelisted
47+
["-whitelist=127.0.0.1"],
48+
# Make sure the default values in the command line documentation match the ones here
49+
["relay", "noban", "mempool", "download"],
50+
None)
51+
4552
self.checkpermission(
4653
# no permission (even with forcerelay)
4754
["[email protected]", "-whitelistforcerelay=1"],
@@ -80,6 +87,12 @@ def run_test(self):
8087
["noban", "mempool", "download"],
8188
False)
8289

90+
self.checkpermission(
91+
# check without deprecatedrpc=whitelisted
92+
["-whitelist=noban,[email protected]", "-whitelistrelay"],
93+
["noban", "mempool", "download"],
94+
None)
95+
8396
self.checkpermission(
8497
# legacy whitelistforcerelay should be ignored
8598
["-whitelist=noban,[email protected]", "-whitelistforcerelay"],
@@ -149,10 +162,15 @@ def check_tx_relay(self):
149162
)
150163

151164
def checkpermission(self, args, expectedPermissions, whitelisted):
165+
if whitelisted is not None:
166+
args = [*args, '-deprecatedrpc=whitelisted']
152167
self.restart_node(1, args)
153168
connect_nodes(self.nodes[0], 1)
154169
peerinfo = self.nodes[1].getpeerinfo()[0]
155-
assert_equal(peerinfo['whitelisted'], whitelisted)
170+
if whitelisted is None:
171+
assert 'whitelisted' not in peerinfo
172+
else:
173+
assert_equal(peerinfo['whitelisted'], whitelisted)
156174
assert_equal(len(expectedPermissions), len(peerinfo['permissions']))
157175
for p in expectedPermissions:
158176
if not p in peerinfo['permissions']:

0 commit comments

Comments
 (0)