Skip to content

test: p2p: check that peer's announced starting height is remembered - #33990

Closed
theStack wants to merge 1 commit into
bitcoin:masterfrom
theStack:202512-test-announced_starting_height
Closed

theStack wants to merge 1 commit into
bitcoin:masterfrom
theStack:202512-test-announced_starting_height

Conversation

@theStack

@theStack theStack commented Dec 2, 2025 •

Copy link
Copy Markdown
Contributor

Note that the announced starting height of a peer is neither verified nor used in any other logic, so reporting a bogus value [1] as done in the test doesn't have any consequences on the connection -- it's only used for inspection via the getpeerinfo RPC and in some debug messages (see also e.g. bitcoin-dot-org/Bitcoin.org#1387 (comment)). Admittedly this is not terribly important, but I'd still think having test coverage for this simple reporting functionality is better than not having it.

[1] any signed 32-bit integer is fine, i.e. in the range [-2^31,2^31-1]

Note that the announced starting height is neither verified nor
used in any other logic, so reporting a bogus value doesn't
have any consequences -- it's only used for inspection via the
`getpeerinfo` RPC and in some debug messages.
@DrahtBot DrahtBot added the Tests label Dec 2, 2025
@DrahtBot

DrahtBot commented Dec 2, 2025 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33990.

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

@theStack theStack changed the title test: check that peer's announced starting height is remembered test: p2p: check that peer's announced starting height is remembered Dec 2, 2025

@rkrux rkrux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ~0 52f96cc

I'm on the fence regarding whether this case testing just one field is warranted. I don't see much coverage gained in the corecheck.
Though there is a similar test_desirable_service_flags case as well but in it the connection is disconnected conditionally, so one can argue that there is more to test over there.

@brunoerg

brunoerg commented Dec 2, 2025

Copy link
Copy Markdown
Contributor

Can be tested with the following diff:

diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 5dac413319..ec417b97ac 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -3535,7 +3535,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
             LOCK(pfrom.m_subver_mutex);
             pfrom.cleanSubVer = cleanSubVer;
         }
-        peer->m_starting_height = starting_height;
+        peer->m_starting_height = starting_height + 1;

         // Only initialize the Peer::TxRelay m_relay_txs data structure if:
         // - this isn't an outbound block-relay-only connection, and

self.add_outbound_connection(node, conn_type, services, wait_for_disconnect=False)

def test_startingheight(self, node):
for fake_startheight in [-2**31, -1, 0, 1000000, 2**31-1] + [random.randint(-2**31, 2**31) for _ in range(5)]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Perhaps a comment explaining these values (edge cases for 32-bit integers) would be good.

@fanquake

fanquake commented Dec 6, 2025

Copy link
Copy Markdown
Member

@ajtowns @mzumsande conceptual thoughts?

@ajtowns

ajtowns commented Dec 6, 2025

Copy link
Copy Markdown
Contributor

Seems fine to test it if we have code to export it over RPC.

I don't think I've ever seen it be useful for debugging anything, and just knowing the height without knowing if it's the same header you have for that height or what the chainwork is doesn't seem very useful. So dropping peer->m_starting_height entirely (and only reporting it in the receive version message debug log entry) might be better?

@maflcko

maflcko commented Dec 7, 2025

Copy link
Copy Markdown
Member

Yeah, I also wonder what the use-case here is or was.

If it is an estimate of how long the connection is established, there is the more accurate conntime field. If it exists to show which peer is ahead of whom, then the existing headers-sync and block-sync p2p flow seems a better way to figure it out, which is reported via the synced_headers, presynced_headers, or synced_blocks fields. If it exists just for debugging the sync logic, it seems best to just log it in the debug log.

In any case, if it is kept, the rpc docs should be updated to say it is the height reported by the peer, not a confirmed or calculated value.

@ajtowns

ajtowns commented Dec 7, 2025

Copy link
Copy Markdown
Contributor

Yeah, I also wonder what the use-case here is or was.

Looks like it was introduced in v0.2.9 where it was used as a heuristic for determining if we're in IBD (due to being more than 2k blocks behind where our peers were), The check was removed in #20624, which also has some more context.

@mzumsande mzumsande left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it isn't useful, and deprecation would makes sense in my opinion. If we decide not to do that for some reason, a test makes sense though.

@theStack

theStack commented Jan 3, 2026

Copy link
Copy Markdown
Contributor Author

Seems reasonable to deprecate the field if there is really no use-case, opened #34197 for that. Closing this one, it can always be re-opened if there is (for any reason) a preference to keep the field.

@theStack theStack closed this Jan 3, 2026
achow101 added a commit that referenced this pull request Jan 5, 2026
…nfo` RPC

4ce3f4a 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 4ce3f4a
  achow101:
    ACK 4ce3f4a
  fjahr:
    utACK 4ce3f4a
  rkrux:
    crACK 4ce3f4a
  janb84:
    cr ACK 4ce3f4a

Tree-SHA512: b296a28d30084fd35c67a2162e85576e3365e5d6fffe5b1add500034c1850604ee8c37b61afe812bfab8a7cc20f6a9e22db445e3c371311a5f82a777e5700ebf
luke-jr pushed a commit to luke-jr/bitcoin that referenced this pull request Jan 13, 2026
Note that the announced starting height is neither verified nor
used in any other logic, so reporting a bogus value doesn't
have any consequences -- it's only used for inspection via the
`getpeerinfo` RPC and in some debug messages.

Github-Pull: bitcoin#33990
Rebased-From: 52f96cc
sedited added a commit that referenced this pull request Mar 12, 2026
…` RPC and from node state

745ad94 p2p: remove m_starting_height field from node state (only show once in debug log) (Sebastian Falbesoner)
b267efc rpc, net: completely remove `startingheight` field of `getpeerinfo` RPC (Sebastian Falbesoner)

Pull request description:

  This PR completely removes the `startingheight` field in the `getpeerinfo` RPC, previously deprecated in v31.0 (see #34197). The second commit goes one step further: the only remaining usage for a `Peer`s `m_starting_height` field is for printing P2P debug messages. Considering that the information is untrusted and not deemed useful (see discussion #33990), remove the field and only print the starting height information once at reception of the `VERSION` message (suggested by ajtowns in #33990 (comment)), without saving it.

ACKs for top commit:
  stickies-v:
    re-ACK 745ad94, no changes except for addressing minor merge conflict
  w0xlt:
    ACK 745ad94
  sedited:
    Re-ACK 745ad94

Tree-SHA512: 09d30f34ea564e884e5d5c0e56cd66f99d6127ba8cc779f1e7ab29ea4fe8603835d306e343ee3a0038b1c07245f429012375034518135c915f543ba175d6dc45
Kino1994 pushed a commit to Kino1994/bitcoin-full-history that referenced this pull request Jun 28, 2026
…of `getpeerinfo` RPC and from node state

f29cf13 p2p: remove m_starting_height field from node state (only show once in debug log) (Sebastian Falbesoner)
8302a26 rpc, net: completely remove `startingheight` field of `getpeerinfo` RPC (Sebastian Falbesoner)

Pull request description:

  This PR completely removes the `startingheight` field in the `getpeerinfo` RPC, previously deprecated in v31.0 (see #34197). The second commit goes one step further: the only remaining usage for a `Peer`s `m_starting_height` field is for printing P2P debug messages. Considering that the information is untrusted and not deemed useful (see discussion #33990), remove the field and only print the starting height information once at reception of the `VERSION` message (suggested by ajtowns in bitcoin/bitcoin#33990 (comment)), without saving it.

ACKs for top commit:
  stickies-v:
    re-ACK f29cf13, no changes except for addressing minor merge conflict
  w0xlt:
    ACK f29cf13
  sedited:
    Re-ACK f29cf13

Tree-SHA512: 09d30f34ea564e884e5d5c0e56cd66f99d6127ba8cc779f1e7ab29ea4fe8603835d306e343ee3a0038b1c07245f429012375034518135c915f543ba175d6dc45
BigcoinBGC pushed a commit to BigcoinBGC/bigcoin that referenced this pull request Jun 30, 2026
…of `getpeerinfo` RPC and from node state

e94486a p2p: remove m_starting_height field from node state (only show once in debug log) (Sebastian Falbesoner)
a11a2f8 rpc, net: completely remove `startingheight` field of `getpeerinfo` RPC (Sebastian Falbesoner)

Pull request description:

  This PR completely removes the `startingheight` field in the `getpeerinfo` RPC, previously deprecated in v31.0 (see #34197). The second commit goes one step further: the only remaining usage for a `Peer`s `m_starting_height` field is for printing P2P debug messages. Considering that the information is untrusted and not deemed useful (see discussion #33990), remove the field and only print the starting height information once at reception of the `VERSION` message (suggested by ajtowns in bitcoin/bitcoin#33990 (comment)), without saving it.

ACKs for top commit:
  stickies-v:
    re-ACK e94486a, no changes except for addressing minor merge conflict
  w0xlt:
    ACK e94486a
  sedited:
    Re-ACK e94486a

Tree-SHA512: 09d30f34ea564e884e5d5c0e56cd66f99d6127ba8cc779f1e7ab29ea4fe8603835d306e343ee3a0038b1c07245f429012375034518135c915f543ba175d6dc45
Kino1994 pushed a commit to Kino1994/bitcoin-full-history that referenced this pull request Aug 19, 2026
…of `getpeerinfo` RPC and from node state

745ad941dedaa0f4e2a5fdda58a3bf683d672196 p2p: remove m_starting_height field from node state (only show once in debug log) (Sebastian Falbesoner)
b267efcdaf854b6b50424d6a6af7cac8ba458390 rpc, net: completely remove `startingheight` field of `getpeerinfo` RPC (Sebastian Falbesoner)

Pull request description:

  This PR completely removes the `startingheight` field in the `getpeerinfo` RPC, previously deprecated in v31.0 (see #34197). The second commit goes one step further: the only remaining usage for a `Peer`s `m_starting_height` field is for printing P2P debug messages. Considering that the information is untrusted and not deemed useful (see discussion #33990), remove the field and only print the starting height information once at reception of the `VERSION` message (suggested by ajtowns in bitcoin/bitcoin#33990 (comment)), without saving it.

ACKs for top commit:
  stickies-v:
    re-ACK 745ad941dedaa0f4e2a5fdda58a3bf683d672196, no changes except for addressing minor merge conflict
  w0xlt:
    ACK 745ad941dedaa0f4e2a5fdda58a3bf683d672196
  sedited:
    Re-ACK 745ad941dedaa0f4e2a5fdda58a3bf683d672196

Tree-SHA512: 09d30f34ea564e884e5d5c0e56cd66f99d6127ba8cc779f1e7ab29ea4fe8603835d306e343ee3a0038b1c07245f429012375034518135c915f543ba175d6dc45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants