Skip to content

Commit 50f94b3

Browse files
committed
[rpc] Deprecate getpeerinfo addnode field
This field is now redundant since the connection type field will indicate MANUAL for addnode connections.
1 parent df091b9 commit 50f94b3

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/rpc/net.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
112112
{RPCResult::Type::NUM, "version", "The peer version, such as 70001"},
113113
{RPCResult::Type::STR, "subver", "The string version"},
114114
{RPCResult::Type::BOOL, "inbound", "Inbound (true) or Outbound (false)"},
115-
{RPCResult::Type::BOOL, "addnode", "Whether connection was due to addnode/-connect or if it was an automatic/inbound connection"},
115+
{RPCResult::Type::BOOL, "addnode", "Whether connection was due to addnode/-connect or if it was an automatic/inbound connection\n"
116+
"(DEPRECATED, returned only if the config option -deprecatedrpc=getpeerinfo_addnode is passed)"},
116117
{RPCResult::Type::STR, "connection_type", "Type of connection: \n" + Join(CONNECTION_TYPE_DOC, ",\n") + "."},
117118
{RPCResult::Type::NUM, "startingheight", "The starting height (block) of the peer"},
118119
{RPCResult::Type::NUM, "banscore", "The ban score (DEPRECATED, returned only if config option -deprecatedrpc=banscore is passed)"},
@@ -193,7 +194,10 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
193194
// their ver message.
194195
obj.pushKV("subver", stats.cleanSubVer);
195196
obj.pushKV("inbound", stats.fInbound);
196-
obj.pushKV("addnode", stats.m_manual_connection);
197+
if (IsDeprecatedRPCEnabled("getpeerinfo_addnode")) {
198+
// addnode is deprecated in v0.21 for removal in v0.22
199+
obj.pushKV("addnode", stats.m_manual_connection);
200+
}
197201
obj.pushKV("startingheight", stats.nStartingHeight);
198202
if (fStateStats) {
199203
if (IsDeprecatedRPCEnabled("banscore")) {

test/functional/rpc_getpeerinfo_deprecation.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""Test deprecation of getpeerinfo RPC fields."""
66

77
from test_framework.test_framework import BitcoinTestFramework
8+
from test_framework.util import connect_nodes
89

910

1011
class GetpeerinfoDeprecationTest(BitcoinTestFramework):
@@ -14,6 +15,7 @@ def set_test_params(self):
1415

1516
def run_test(self):
1617
self.test_banscore_deprecation()
18+
self.test_addnode_deprecation()
1719

1820
def test_banscore_deprecation(self):
1921
self.log.info("Test getpeerinfo by default no longer returns a banscore field")
@@ -22,5 +24,16 @@ def test_banscore_deprecation(self):
2224
self.log.info("Test getpeerinfo returns banscore with -deprecatedrpc=banscore")
2325
assert "banscore" in self.nodes[1].getpeerinfo()[0].keys()
2426

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

0 commit comments

Comments
 (0)