Merge bitcoin/bitcoin#34197: rpc, net: deprecate startingheight field of getpeerinfo RPC

4ce3f4a265 rpc, net: deprecate `startingheight` field of `getpeerinfo` RPC (Sebastian Falbesoner)

Pull request description:

  This PR deprecates the "startingheight" result field of the `getpeerinfo` RPC, following the discussion in #33990.

  Rationale: the reported starting height of a peer in the VERSION message is untrusted, and it doesn't seem to be useful anymore (after #20624), so deprecating the corresponding field seems reasonable. After that, it can be removed, along with the `m_starting_height` field of the Peer / CNodeStats structs, as it is sufficient to show the reported height only once at connection in the debug log.

ACKs for top commit:
  optout21:
    crACK 4ce3f4a265
  achow101:
    ACK 4ce3f4a265
  fjahr:
    utACK 4ce3f4a265
  rkrux:
    crACK 4ce3f4a265
  janb84:
    cr ACK 4ce3f4a265

Tree-SHA512: b296a28d30084fd35c67a2162e85576e3365e5d6fffe5b1add500034c1850604ee8c37b61afe812bfab8a7cc20f6a9e22db445e3c371311a5f82a777e5700ebf
This commit is contained in:
Ava Chow
2026-01-05 15:17:48 -08:00
4 changed files with 16 additions and 3 deletions

View File

@@ -0,0 +1,7 @@
Updated RPCs
------------
- The `getpeerinfo` RPC no longer returns the `startingheight` field unless
the configuration option `-deprecatedrpc=startingheight` is used. The
`startingheight` field will be fully removed in the next major release.
(#34197)

View File

@@ -268,6 +268,7 @@ struct Peer {
bool m_outbound_version_message_sent GUARDED_BY(NetEventsInterface::g_msgproc_mutex){false};
/** This peer's reported block height when we connected */
// TODO: remove in v32.0, only show reported height once in "receive version message: ..." debug log
std::atomic<int> m_starting_height{-1};
/** The pong reply we're expecting, or 0 if no pong expected. */

View File

@@ -160,7 +160,7 @@ static RPCHelpMan getpeerinfo()
{RPCResult::Type::BOOL, "inbound", "Inbound (true) or Outbound (false)"},
{RPCResult::Type::BOOL, "bip152_hb_to", "Whether we selected peer as (compact blocks) high-bandwidth peer"},
{RPCResult::Type::BOOL, "bip152_hb_from", "Whether peer selected us as (compact blocks) high-bandwidth peer"},
{RPCResult::Type::NUM, "startingheight", "The starting height (block) of the peer"},
{RPCResult::Type::NUM, "startingheight", /*optional=*/true, "(DEPRECATED, returned only if config option -deprecatedrpc=startingheight is passed) The starting height (block) of the peer"},
{RPCResult::Type::NUM, "presynced_headers", "The current height of header pre-synchronization with this peer, or -1 if no low-work sync is in progress"},
{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"},
@@ -267,7 +267,9 @@ static RPCHelpMan getpeerinfo()
obj.pushKV("inbound", stats.fInbound);
obj.pushKV("bip152_hb_to", stats.m_bip152_highbandwidth_to);
obj.pushKV("bip152_hb_from", stats.m_bip152_highbandwidth_from);
obj.pushKV("startingheight", statestats.m_starting_height);
if (IsDeprecatedRPCEnabled("startingheight")) {
obj.pushKV("startingheight", statestats.m_starting_height);
}
obj.pushKV("presynced_headers", statestats.presync_height);
obj.pushKV("synced_headers", statestats.nSyncHeight);
obj.pushKV("synced_blocks", statestats.nCommonHeight);

View File

@@ -62,7 +62,10 @@ def seed_addrman(node):
class NetTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2
self.extra_args = [["-minrelaytxfee=0.00001000"], ["-minrelaytxfee=0.00000500"]]
self.extra_args = [
["-minrelaytxfee=0.00001000", "-deprecatedrpc=startingheight"],
["-minrelaytxfee=0.00000500"],
]
# Specify a non-working proxy to make sure no actual connections to public IPs are attempted
for args in self.extra_args:
args.append("-proxy=127.0.0.1:1")