From 8c7647b3fbbab03ea84071cf3cd2d0d2bf8be255 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Wed, 8 Jul 2020 13:00:58 +0200 Subject: [PATCH 1/3] rpc: deprecate banscore field in rpc getpeerinfo --- src/rpc/net.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 393442e946..9981ea35df 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -112,7 +112,7 @@ static UniValue getpeerinfo(const JSONRPCRequest& request) {RPCResult::Type::BOOL, "inbound", "Inbound (true) or Outbound (false)"}, {RPCResult::Type::BOOL, "addnode", "Whether connection was due to addnode/-connect or if it was an automatic/inbound connection"}, {RPCResult::Type::NUM, "startingheight", "The starting height (block) of the peer"}, - {RPCResult::Type::NUM, "banscore", "The ban score"}, + {RPCResult::Type::NUM, "banscore", "The ban score (DEPRECATED, returned only if config option -deprecatedrpc=banscore is passed)"}, {RPCResult::Type::NUM, "synced_headers", "The last header we have in common with this peer"}, {RPCResult::Type::NUM, "synced_blocks", "The last block we have in common with this peer"}, {RPCResult::Type::ARR, "inflight", "", @@ -191,7 +191,10 @@ static UniValue getpeerinfo(const JSONRPCRequest& request) obj.pushKV("addnode", stats.m_manual_connection); obj.pushKV("startingheight", stats.nStartingHeight); if (fStateStats) { - obj.pushKV("banscore", statestats.nMisbehavior); + if (IsDeprecatedRPCEnabled("banscore")) { + // banscore is deprecated in v0.21 for removal in v0.22 + obj.pushKV("banscore", statestats.nMisbehavior); + } obj.pushKV("synced_headers", statestats.nSyncHeight); obj.pushKV("synced_blocks", statestats.nCommonHeight); UniValue heights(UniValue::VARR); From dd54e3796e633cfdf6954af306afd26eadc25116 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Wed, 8 Jul 2020 12:33:14 +0200 Subject: [PATCH 2/3] test: getpeerinfo banscore deprecation test --- .../rpc_getpeerinfo_banscore_deprecation.py | 24 +++++++++++++++++++ test/functional/test_runner.py | 1 + 2 files changed, 25 insertions(+) create mode 100755 test/functional/rpc_getpeerinfo_banscore_deprecation.py diff --git a/test/functional/rpc_getpeerinfo_banscore_deprecation.py b/test/functional/rpc_getpeerinfo_banscore_deprecation.py new file mode 100755 index 0000000000..b830248e1e --- /dev/null +++ b/test/functional/rpc_getpeerinfo_banscore_deprecation.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +# Copyright (c) 2020 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. +"""Test deprecation of getpeerinfo RPC banscore field.""" + +from test_framework.test_framework import BitcoinTestFramework + + +class GetpeerinfoBanscoreDeprecationTest(BitcoinTestFramework): + def set_test_params(self): + self.num_nodes = 2 + self.extra_args = [[], ["-deprecatedrpc=banscore"]] + + def run_test(self): + self.log.info("Test getpeerinfo by default no longer returns a banscore field") + assert "banscore" not in self.nodes[0].getpeerinfo()[0].keys() + + self.log.info("Test getpeerinfo returns banscore with -deprecatedrpc=banscore") + assert "banscore" in self.nodes[1].getpeerinfo()[0].keys() + + +if __name__ == "__main__": + GetpeerinfoBanscoreDeprecationTest().main() diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index 2fa48006f4..6deba9a9ec 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -243,6 +243,7 @@ BASE_SCRIPTS = [ 'feature_blocksdir.py', 'feature_config_args.py', 'rpc_getdescriptorinfo.py', + 'rpc_getpeerinfo_banscore_deprecation.py', 'rpc_help.py', 'feature_help.py', 'feature_shutdown.py', From 41d55d30579358c805036201664ad6a1c1d48681 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Wed, 8 Jul 2020 12:54:28 +0200 Subject: [PATCH 3/3] doc: getpeerinfo banscore deprecation release note --- doc/release-notes-19469.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 doc/release-notes-19469.md diff --git a/doc/release-notes-19469.md b/doc/release-notes-19469.md new file mode 100644 index 0000000000..974b228cc1 --- /dev/null +++ b/doc/release-notes-19469.md @@ -0,0 +1,6 @@ +Updated RPCs +------------ + +- `getpeerinfo` no longer returns the `banscore` field unless the configuration + option `-deprecatedrpc=banscore` is used. The `banscore` field will be fully + removed in the next major release. (#19469)