#27052 test: rpc: add last block announcement time to getpeerinfo result

full analysis

https://github.com/bitcoin/bitcoin/pull/27052 · LarryRuane · +146/-19 in 8 files, 5 commits · labels: Tests

Goal

  • Give node operators visibility into which peers provide prompt block announcements
  • Add test coverage to protect outbound peer eviction logic from regressions

This PR adds a `last_block_announcement` field to the `getpeerinfo` RPC output, reporting the UNIX timestamp when a peer was the first to announce a new block extending the tip. It updates the internal representation in net_processing to use `NodeClock::time_point` instead of `int64_t`, refactors the peer eviction loop slightly, and adds a functional test (`p2p_block_times.py`) ensuring this timestamp is correctly set and maintained.

Problem: Stale-tip outbound peer eviction relies on tracking which peer least recently announced a new block, but this tracking had no dedicated functional test coverage, making regression verification difficult (e.g. after #26172). Additionally, node operators had no visibility into which peers provide prompt block announcements.

Category: P2P (#44 of 65)

P3 · test coverage

  • P3 because it adds regression test coverage for peer announcement tracking in eviction logic
  • Modernizes internal time representation used during peer eviction

P3 because it adds regression test coverage for peer block announcement timestamp tracking which drives stale-tip peer eviction, and modernizes internal net_processing time representation.

Membership: Touches net_processing eviction logic and adds a functional test for P2P block announcement message processing.

Factors: security/stability 1, bug 0, performance 0, user value 1, leverage 1

Category: RPC / REST / ZMQ (#38 of 52)

P3 · new feature

  • P3 because it exposes peer responsiveness timestamps to operators without breaking compatibility
  • Enables external monitoring and functional testing of peer block announcement timing

P3 because it exposes a previously internal timestamp in getpeerinfo, providing visibility into peer responsiveness for operators and tests without breaking backwards compatibility.

Membership: Adds the last_block_announcement field to getpeerinfo RPC output and updates rpc_net.py.

Factors: security/stability 0, bug 0, performance 0, user value 1, leverage 1

Reviewability: Ready

  • Ready for review with passing CI and all feedback resolved

All review feedback, test edge cases, and type cleanups have been resolved and the PR is passing CI.

Author status: active

Resolved concerns:

  • Switching timestamp representation from int64_t to NodeClock::time_point / NodeSeconds and avoiding duration count calls (maflcko, theuni)
  • Avoiding sentinel values in worst_peer eviction iteration (naiyoma, dergoegge, theuni)
  • Addressing functional test timeouts and verifying chainwork edge cases using mutation testing (naiyoma, danielabrozzoni)

Agreement: Strong

  • Strong support with all concerns resolved
  • Verified by mutation testing and checking header announcement edge cases (naiyoma)
  • Verified by running test suites and checking RPC output (rkrux)
  • Concept approval favoring test coverage and peer observability (satsie, kristapsk)

Tested ACKs from naiyoma and rkrux, with earlier concept approval and all reviewer concerns resolved.

Multiple contributors tested and reviewed the functional test, RPC changes, and chrono cleanups with no outstanding objections.

  • Tested ACK from naiyoma confirming functional test catches header announcement bugs and survives mutations.
  • Tested ACK from rkrux confirming RPC output and running test suites.
  • Concept ACKs from satsie and kristapsk in favor of test coverage and peer observability.

Review verdicts (DrahtBot): 2

Files

114 lines under test/bench/ci.

  • test/functional/p2p_block_times.py +105/-0
  • src/net_processing.cpp +22/-16
  • doc/release-notes-27052.md +8/-0
  • test/functional/rpc_net.py +5/-1
  • src/net_processing.h +2/-1
  • src/rpc/net.cpp +2/-0
  • src/test/denialofservice_tests.cpp +1/-1
  • test/functional/test_runner.py +1/-0

Card

This PR adds a `last_block_announcement` timestamp field to `getpeerinfo` and adds a dedicated functional test (`p2p_block_times.py`) verifying that the node properly records when a peer was first to announce a block extending the active chain. This timestamp drives stale-tip peer eviction and was previously uncovered by functional tests following a bug fix in #26172. The change also modernizes internal announcement timestamps to use `NodeClock::time_point`. The PR has multiple tested ACKs, green CI, and is ready for merge.

Data

dossier JSON · extract JSON · model openrouter/google/gemini-3.8-flash, generated 2026-09-17T15:48, confidence high, input hash 5ef8bae2e28f7683