Skip to content

Commit a4eb6a5

Browse files
committed
Merge #19469: rpc: deprecate banscore field in getpeerinfo
41d55d3 doc: getpeerinfo banscore deprecation release note (Jon Atack) dd54e37 test: getpeerinfo banscore deprecation test (Jon Atack) 8c7647b rpc: deprecate banscore field in rpc getpeerinfo (Jon Atack) Pull request description: Per bitcoin/bitcoin#19219 (comment) and bitcoin/bitcoin#19219 (comment), this PR deprecates returning the `banscore` field in the `getpeerinfo` RPC, updates the help, adds a test, and updates the release notes. Related to #19464. ACKs for top commit: fanquake: ACK 41d55d3 Tree-SHA512: 8eca08332581e2fe191a2aafff6ba89ce39413f0491ed0de8b86577739f0ec430b1a8fbff2914b0f3138a229563dfcc1981c0cf5b7dd6061b5c48680a28423bc
2 parents 2aaff48 + 41d55d3 commit a4eb6a5

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

doc/release-notes-19469.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Updated RPCs
2+
------------
3+
4+
- `getpeerinfo` no longer returns the `banscore` field unless the configuration
5+
option `-deprecatedrpc=banscore` is used. The `banscore` field will be fully
6+
removed in the next major release. (#19469)

src/rpc/net.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
112112
{RPCResult::Type::BOOL, "inbound", "Inbound (true) or Outbound (false)"},
113113
{RPCResult::Type::BOOL, "addnode", "Whether connection was due to addnode/-connect or if it was an automatic/inbound connection"},
114114
{RPCResult::Type::NUM, "startingheight", "The starting height (block) of the peer"},
115-
{RPCResult::Type::NUM, "banscore", "The ban score"},
115+
{RPCResult::Type::NUM, "banscore", "The ban score (DEPRECATED, returned only if config option -deprecatedrpc=banscore is passed)"},
116116
{RPCResult::Type::NUM, "synced_headers", "The last header we have in common with this peer"},
117117
{RPCResult::Type::NUM, "synced_blocks", "The last block we have in common with this peer"},
118118
{RPCResult::Type::ARR, "inflight", "",
@@ -191,7 +191,10 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
191191
obj.pushKV("addnode", stats.m_manual_connection);
192192
obj.pushKV("startingheight", stats.nStartingHeight);
193193
if (fStateStats) {
194-
obj.pushKV("banscore", statestats.nMisbehavior);
194+
if (IsDeprecatedRPCEnabled("banscore")) {
195+
// banscore is deprecated in v0.21 for removal in v0.22
196+
obj.pushKV("banscore", statestats.nMisbehavior);
197+
}
195198
obj.pushKV("synced_headers", statestats.nSyncHeight);
196199
obj.pushKV("synced_blocks", statestats.nCommonHeight);
197200
UniValue heights(UniValue::VARR);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2020 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Test deprecation of getpeerinfo RPC banscore field."""
6+
7+
from test_framework.test_framework import BitcoinTestFramework
8+
9+
10+
class GetpeerinfoBanscoreDeprecationTest(BitcoinTestFramework):
11+
def set_test_params(self):
12+
self.num_nodes = 2
13+
self.extra_args = [[], ["-deprecatedrpc=banscore"]]
14+
15+
def run_test(self):
16+
self.log.info("Test getpeerinfo by default no longer returns a banscore field")
17+
assert "banscore" not in self.nodes[0].getpeerinfo()[0].keys()
18+
19+
self.log.info("Test getpeerinfo returns banscore with -deprecatedrpc=banscore")
20+
assert "banscore" in self.nodes[1].getpeerinfo()[0].keys()
21+
22+
23+
if __name__ == "__main__":
24+
GetpeerinfoBanscoreDeprecationTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@
243243
'feature_blocksdir.py',
244244
'feature_config_args.py',
245245
'rpc_getdescriptorinfo.py',
246+
'rpc_getpeerinfo_banscore_deprecation.py',
246247
'rpc_help.py',
247248
'feature_help.py',
248249
'feature_shutdown.py',

0 commit comments

Comments
 (0)