Skip to content

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

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

test: p2p: check that peer's announced starting height is remembered#33990
theStack wants to merge 1 commit intobitcoin:masterfrom
theStack:202512-test-announced_starting_height

Conversation

@theStack
Copy link
Contributor

@theStack theStack commented Dec 2, 2025

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
Copy link
Contributor

DrahtBot commented Dec 2, 2025

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
Copy link
Contributor

@rkrux rkrux left a comment

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
Copy link
Contributor

brunoerg commented Dec 2, 2025

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
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
Copy link
Member

fanquake commented Dec 6, 2025

@ajtowns @mzumsande conceptual thoughts?

@ajtowns
Copy link
Contributor

ajtowns commented Dec 6, 2025

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
Copy link
Member

maflcko commented Dec 7, 2025

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
Copy link
Contributor

ajtowns commented Dec 7, 2025

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.

Copy link
Contributor

@mzumsande mzumsande left a comment

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
Copy link
Contributor Author

theStack commented Jan 3, 2026

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
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