diff --git a/doc/release-notes.md b/doc/release-notes.md --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -5,3 +5,12 @@ This release includes the following features and fixes: + +- The `getpeerinfo` RPC now returns a `connection_type` field. This indicates + the type of connection established with the peer. It will return one of six + options. For more information, see the `getpeerinfo` help documentation. +- The `getpeerinfo` RPC no longer returns the `addnode` field by default. This + field will be fully removed in a future release. It can be accessed + with the configuration option `-deprecatedrpc=getpeerinfo_addnode`. However, + it is recommended to instead use the `connection_type` field (it will return + `manual` when addnode is true). diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -152,6 +152,11 @@ {RPCResult::Type::BOOL, "addnode", "Whether connection was due to addnode/-connect or if it " "was an automatic/inbound connection"}, + {RPCResult::Type::BOOL, "addnode", + "Whether connection was due to addnode/-connect or if it " + "was an automatic/inbound connection\n(DEPRECATED, " + "returned only if the config option " + "-deprecatedrpc=getpeerinfo_addnode is passed)"}, {RPCResult::Type::STR, "connection_type", "Type of connection: \n" + Join(CONNECTION_TYPE_DOC, ",\n") + "."}, @@ -261,7 +266,10 @@ // putting special characters in their ver message. obj.pushKV("subver", stats.cleanSubVer); obj.pushKV("inbound", stats.fInbound); - obj.pushKV("addnode", stats.m_manual_connection); + if (IsDeprecatedRPCEnabled(gArgs, "getpeerinfo_addnode")) { + // addnode is deprecated in v0.24.5 for removal in v0.26.x + obj.pushKV("addnode", stats.m_manual_connection); + } obj.pushKV("startingheight", stats.nStartingHeight); if (fStateStats) { if (IsDeprecatedRPCEnabled(gArgs, "banscore")) { diff --git a/test/functional/rpc_getpeerinfo_deprecation.py b/test/functional/rpc_getpeerinfo_deprecation.py --- a/test/functional/rpc_getpeerinfo_deprecation.py +++ b/test/functional/rpc_getpeerinfo_deprecation.py @@ -5,6 +5,7 @@ """Test deprecation of getpeerinfo RPC fields.""" from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import connect_nodes class GetpeerinfoDeprecationTest(BitcoinTestFramework): @@ -14,6 +15,7 @@ def run_test(self): self.test_banscore_deprecation() + self.test_addnode_deprecation() def test_banscore_deprecation(self): self.log.info( @@ -24,6 +26,18 @@ "Test getpeerinfo returns banscore with -deprecatedrpc=banscore") assert "banscore" in self.nodes[1].getpeerinfo()[0].keys() + def test_addnode_deprecation(self): + self.restart_node(1, ["-deprecatedrpc=getpeerinfo_addnode"]) + connect_nodes(self.nodes[0], self.nodes[1]) + + self.log.info( + "Test getpeerinfo by default no longer returns an addnode field") + assert "addnode" not in self.nodes[0].getpeerinfo()[0].keys() + + self.log.info( + "Test getpeerinfo returns addnode with -deprecatedrpc=addnode") + assert "addnode" in self.nodes[1].getpeerinfo()[0].keys() + if __name__ == "__main__": GetpeerinfoDeprecationTest().main()