Skip to content

Commit b6c8d85

Browse files
MarcoFalkeknst
authored andcommitted
Merge bitcoin#19725: [RPC] Add connection type to getpeerinfo, improve logs
a512925 [doc] Release notes (Amiti Uttarwar) 50f94b3 [rpc] Deprecate getpeerinfo addnode field (Amiti Uttarwar) df091b9 [refactor] Rename test file to allow any getpeerinfo deprecations. (Amiti Uttarwar) 395acfa [rpc] Add connection type to getpeerinfo RPC, update tests (Amiti Uttarwar) 49c10a9 [log] Add connection type to log statement (Amiti Uttarwar) Pull request description: After bitcoin#19316, we can more directly expose information about the connection type on the `getpeerinfo` RPC. Doing so also makes the existing addnode field redundant, so this PR begins the process of deprecating this field. This PR also includes one commit that improves a log message, as both use a shared function to return the connection type as a string. Suggested by sdaftuar- bitcoin#19316 (comment) & bitcoin#19316 (comment) ACKs for top commit: jnewbery: Code review ACK a512925. sipa: utACK a512925 guggero: Tested and code review ACK a512925. MarcoFalke: cr ACK a512925 🌇 promag: Code review ACK a512925. Tree-SHA512: 601a7a38aee235ee59aca690784f886dc2ae4e418b2e6422c4b58cd597376c00f74910f66920b08a08a0bec28bf8022e71a1435785ff6ba8a188954261aba78e
1 parent f86263b commit b6c8d85

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

doc/release-notes-19725.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
Updated RPCs
3+
------------
4+
5+
- The `getpeerinfo` RPC no longer returns the `addnode` field by default. This
6+
field will be fully removed in the next major release. It can be accessed
7+
with the configuration option `-deprecatedrpc=getpeerinfo_addnode`. However,
8+
it is recommended to instead use the `connection_type` field (it will return
9+
`manual` when addnode is true). (#6033)
10+

src/rpc/net.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ static RPCHelpMan getpeerinfo()
145145
{RPCResult::Type::NUM, "version", "The peer version, such as 70001"},
146146
{RPCResult::Type::STR, "subver", "The string version"},
147147
{RPCResult::Type::BOOL, "inbound", "Inbound (true) or Outbound (false)"},
148-
{RPCResult::Type::BOOL, "addnode", "Whether connection was due to addnode/-connect or if it was an automatic/inbound connection"},
148+
{RPCResult::Type::BOOL, "addnode", "Whether connection was due to addnode/-connect or if it was an automatic/inbound connection\n"
149+
"(DEPRECATED, returned only if the config option -deprecatedrpc=getpeerinfo_addnode is passed)"},
149150
{RPCResult::Type::BOOL, "masternode", "Whether connection was due to masternode connection attempt"},
150151
{RPCResult::Type::NUM, "banscore", "The ban score (DEPRECATED, returned only if config option -deprecatedrpc=banscore is passed)"},
151152
{RPCResult::Type::NUM, "startingheight", "The starting height (block) of the peer"},
@@ -242,7 +243,10 @@ static RPCHelpMan getpeerinfo()
242243
// their ver message.
243244
obj.pushKV("subver", stats.cleanSubVer);
244245
obj.pushKV("inbound", stats.fInbound);
245-
obj.pushKV("addnode", stats.m_manual_connection);
246+
if (IsDeprecatedRPCEnabled("getpeerinfo_addnode")) {
247+
// addnode is deprecated in v0.21 for removal in v0.22
248+
obj.pushKV("addnode", stats.m_manual_connection);
249+
}
246250
obj.pushKV("masternode", stats.m_masternode_connection);
247251
if (fStateStats) {
248252
if (IsDeprecatedRPCEnabled("banscore")) {

test/functional/rpc_getpeerinfo_banscore_deprecation.py renamed to test/functional/rpc_getpeerinfo_deprecation.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,37 @@
22
# Copyright (c) 2020 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5-
"""Test deprecation of getpeerinfo RPC banscore field."""
5+
"""Test deprecation of getpeerinfo RPC fields."""
66

77
from test_framework.test_framework import BitcoinTestFramework
88

99

10-
class GetpeerinfoBanscoreDeprecationTest(BitcoinTestFramework):
10+
class GetpeerinfoDeprecationTest(BitcoinTestFramework):
1111
def set_test_params(self):
1212
self.num_nodes = 2
1313
self.extra_args = [[], ["-deprecatedrpc=banscore"]]
1414

1515
def run_test(self):
16+
self.test_banscore_deprecation()
17+
self.test_addnode_deprecation()
18+
19+
def test_banscore_deprecation(self):
1620
self.log.info("Test getpeerinfo by default no longer returns a banscore field")
1721
assert "banscore" not in self.nodes[0].getpeerinfo()[0].keys()
1822

1923
self.log.info("Test getpeerinfo returns banscore with -deprecatedrpc=banscore")
2024
assert "banscore" in self.nodes[1].getpeerinfo()[0].keys()
2125

26+
def test_addnode_deprecation(self):
27+
self.restart_node(1, ["-deprecatedrpc=getpeerinfo_addnode"])
28+
self.connect_nodes(0, 1)
29+
30+
self.log.info("Test getpeerinfo by default no longer returns an addnode field")
31+
assert "addnode" not in self.nodes[0].getpeerinfo()[0].keys()
32+
33+
self.log.info("Test getpeerinfo returns addnode with -deprecatedrpc=addnode")
34+
assert "addnode" in self.nodes[1].getpeerinfo()[0].keys()
35+
2236

2337
if __name__ == "__main__":
24-
GetpeerinfoBanscoreDeprecationTest().main()
38+
GetpeerinfoDeprecationTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@
332332
'feature_config_args.py',
333333
'feature_settings.py',
334334
'rpc_getdescriptorinfo.py',
335-
'rpc_getpeerinfo_banscore_deprecation.py',
335+
'rpc_getpeerinfo_deprecation.py',
336336
'rpc_help.py',
337337
'feature_help.py',
338338
'feature_blockfilterindex_prune.py'

0 commit comments

Comments
 (0)