WIP: p2p: Relay stale tip announcements (BIP 332)(Stale Tip Relay) #36920

Draft
pseudoramdom wants to merge 21 commits from bip332-staletips-pt2-headersrelay into master AGit
pseudoramdom commented 2026-11-19 22:04:25 +00:00 (Migrated from github.com)

Part of #36833.
Based on #36919; review from p2p: add staletip message type and payload.

This adds the BIP 332 staletip message, negotiated through the BIP 434 BIP332 feature. With -staletips=headers, the node announces the stale tips it tracks and tracks the ones its peers announce. Only headers are relayed.

Key changes

  • New staletip message type and payload.

  • Add a StaleTipRelayManager, which holds the relay policy.

  • With -staletips=headers, the node advertises BIP332 (with prefers_blocks=false) and relays only with peers that advertise it too.

  • Stale tips learned from peers are tracked, and listed by getchaintips with staletips_only:

    Sample output

    A node that learned of a stale tip only from a peer's staletip message:

    $ bitcoin-cli -named getchaintips staletips_only=true
    [
      {
        "height": 111,
        "hash": "6377f9037ff98cb738f676bee62d1931adf41c2cdb00e0148b8d5fbf6161807d",
        "branchlen": 1,
        "fork_point": "24bed510a58473fb7ac8cd0f48bb25d75cf9848f00a62be08721b64cea6acd20",
        "status": "headers-only"
      }
    ]
    
  • getnetworkinfo gets a localfeatures field, listing the BIP 434 features the node advertises.

    Sample output
    $ bitcoin-cli getnetworkinfo
    {
      ...
      "localfeatures": {
        "BIP332": {
          "prefers_blocks": false
        }
      },
      ...
    }
    
  • getpeerinfo gets a features field, listing the BIP 434 features each peer advertises.

    Sample output
    $ bitcoin-cli getpeerinfo
    [
      {
        "id": 1,
        ...
        "features": {
          "BIP332": {
            "prefers_blocks": false
          }
        },
        ...
      }
    ]
    
Part of #36833. Based on #36919; review from `p2p: add staletip message type and payload`. This adds the [BIP 332](https://github.com/bitcoin/bips/blob/master/bip-0332.md) `staletip` message, negotiated through the BIP 434 `BIP332` feature. With `-staletips=headers`, the node announces the stale tips it tracks and tracks the ones its peers announce. Only headers are relayed. ### Key changes * New `staletip` message type and payload. * Add a `StaleTipRelayManager`, which holds the relay policy. * With `-staletips=headers`, the node advertises `BIP332` (with `prefers_blocks=false`) and relays only with peers that advertise it too. * Stale tips learned from peers are tracked, and listed by `getchaintips` with `staletips_only`: <details> <summary>Sample output</summary> A node that learned of a stale tip only from a peer's `staletip` message: ``` $ bitcoin-cli -named getchaintips staletips_only=true [ { "height": 111, "hash": "6377f9037ff98cb738f676bee62d1931adf41c2cdb00e0148b8d5fbf6161807d", "branchlen": 1, "fork_point": "24bed510a58473fb7ac8cd0f48bb25d75cf9848f00a62be08721b64cea6acd20", "status": "headers-only" } ] ``` </details> * `getnetworkinfo` gets a `localfeatures` field, listing the BIP 434 features the node advertises. <details> <summary>Sample output</summary> ``` $ bitcoin-cli getnetworkinfo { ... "localfeatures": { "BIP332": { "prefers_blocks": false } }, ... } ``` </details> * `getpeerinfo` gets a `features` field, listing the BIP 434 features each peer advertises. <details> <summary>Sample output</summary> ``` $ bitcoin-cli getpeerinfo [ { "id": 1, ... "features": { "BIP332": { "prefers_blocks": false } }, ... } ] ``` </details>
DrahtBot commented 2026-11-19 22:04:37 +00:00 (Migrated from github.com)

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

External sites

Reviews

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36819 ([RFC] enable clang-tidy optin.performance.Padding by fanquake)
  • #36808 (iwyu: Fix warnings in src/test/fuzz and treat them as errors by hebasto)
  • #36598 ([Demo] validation: remove AssumeUTXO by l0rinc)
  • #36268 (refactor: prune unused semi-colons by fanquake)
  • #35713 (Remove boost as a unit test runner by rustaceanrob)
  • #35570 (refactor: Change some validation.cpp methods to return BlockValidationState by optout21)
  • #35522 (refactor: Extract per-message helpers from SendMessages() (move-only) by pablomartin4btc)
  • #35502 (refactor: extract per-message helpers from ProcessMessage (move-only) by w0xlt)
  • #35474 (node: move index ownership to NodeContext by w0xlt)
  • #31260 (scripted-diff: Type-safe settings retrieval by ryanofsky)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

LLM Linter (✨ experimental)

Possible places where comparison-specific test macros should replace generic comparisons:

  • src/test/staletipmessage_tests.cpp: BOOST_CHECK_THROW(DecodeExact(trailing), std::ios_base::failure) → Prefer BOOST_CHECK_EXCEPTION with a predicate checking the expected failure message.
  • src/test/staletipmessage_tests.cpp: BOOST_CHECK_THROW(DecodeExact(invalid_bool), std::ios_base::failure) → Prefer BOOST_CHECK_EXCEPTION checking "staletip invalid have_block".
  • src/test/staletipmessage_tests.cpp: BOOST_CHECK_THROW(DecodeExact(truncated), std::ios_base::failure) → Prefer BOOST_CHECK_EXCEPTION checking the expected truncation failure.
  • src/test/staletipmessage_tests.cpp: BOOST_CHECK_THROW(DecodeExact(noncanonical), std::ios_base::failure) → Prefer BOOST_CHECK_EXCEPTION checking the expected non-canonical CompactSize failure.
  • src/test/staletipmessage_tests.cpp: BOOST_CHECK_THROW(DecodeExact(empty_headers), std::ios_base::failure) → Prefer BOOST_CHECK_EXCEPTION checking "staletip headers empty".
  • test/functional/p2p_staletip.py: assert len([msg for msg in peer.staletips if msg.tip_hash() == block.hash_int]) == 1 → Prefer assert_equal(len([...]), 1).
  • test/functional/p2p_staletip.py: assert len(tracked) > 0 → Prefer assert_greater_than(len(tracked), 0).

2026-11-20 19:36:55

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36920 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36920.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36920#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. A summary of reviews will appear here. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36819](https://github.com/bitcoin/bitcoin/pull/36819) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36819.svg"></sub> ([RFC] enable `clang-tidy` `optin.performance.Padding` by fanquake) * [#36808](https://github.com/bitcoin/bitcoin/pull/36808) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36808.svg"></sub> (iwyu: Fix warnings in `src/test/fuzz` and treat them as errors by hebasto) * [#36598](https://github.com/bitcoin/bitcoin/pull/36598) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36598.svg"></sub> ([Demo] validation: remove AssumeUTXO by l0rinc) * [#36268](https://github.com/bitcoin/bitcoin/pull/36268) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36268.svg"></sub> (refactor: prune unused semi-colons by fanquake) * [#35713](https://github.com/bitcoin/bitcoin/pull/35713) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35713.svg"></sub> (Remove boost as a unit test runner by rustaceanrob) * [#35570](https://github.com/bitcoin/bitcoin/pull/35570) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35570.svg"></sub> (refactor: Change some validation.cpp methods to return BlockValidationState by optout21) * [#35522](https://github.com/bitcoin/bitcoin/pull/35522) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35522.svg"></sub> (refactor: Extract per-message helpers from SendMessages() (move-only) by pablomartin4btc) * [#35502](https://github.com/bitcoin/bitcoin/pull/35502) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35502.svg"></sub> (refactor: extract per-message helpers from ProcessMessage (move-only) by w0xlt) * [#35474](https://github.com/bitcoin/bitcoin/pull/35474) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35474.svg"></sub> (node: move index ownership to NodeContext by w0xlt) * [#31260](https://github.com/bitcoin/bitcoin/pull/31260) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/31260.svg"></sub> (scripted-diff: Type-safe settings retrieval by ryanofsky) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3--> ### LLM Linter (✨ experimental) Possible places where comparison-specific test macros should replace generic comparisons: - `src/test/staletipmessage_tests.cpp`: `BOOST_CHECK_THROW(DecodeExact(trailing), std::ios_base::failure)` → Prefer `BOOST_CHECK_EXCEPTION` with a predicate checking the expected failure message. - `src/test/staletipmessage_tests.cpp`: `BOOST_CHECK_THROW(DecodeExact(invalid_bool), std::ios_base::failure)` → Prefer `BOOST_CHECK_EXCEPTION` checking `"staletip invalid have_block"`. - `src/test/staletipmessage_tests.cpp`: `BOOST_CHECK_THROW(DecodeExact(truncated), std::ios_base::failure)` → Prefer `BOOST_CHECK_EXCEPTION` checking the expected truncation failure. - `src/test/staletipmessage_tests.cpp`: `BOOST_CHECK_THROW(DecodeExact(noncanonical), std::ios_base::failure)` → Prefer `BOOST_CHECK_EXCEPTION` checking the expected non-canonical CompactSize failure. - `src/test/staletipmessage_tests.cpp`: `BOOST_CHECK_THROW(DecodeExact(empty_headers), std::ios_base::failure)` → Prefer `BOOST_CHECK_EXCEPTION` checking `"staletip headers empty"`. - `test/functional/p2p_staletip.py`: `assert len([msg for msg in peer.staletips if msg.tip_hash() == block.hash_int]) == 1` → Prefer `assert_equal(len([...]), 1)`. - `test/functional/p2p_staletip.py`: `assert len(tracked) > 0` → Prefer `assert_greater_than(len(tracked), 0)`. <sup>2026-11-20 19:36:55</sup>
DrahtBot commented 2026-11-19 22:09:28 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task i686: https://github.com/bitcoin/bitcoin/actions/runs/44625059152/job/135916554369
LLM reason (✨ experimental): The build failed because staletiprelayman.cpp omits the StaleTipMessage::headers initializer, and warnings are treated as errors.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `i686`: https://github.com/bitcoin/bitcoin/actions/runs/44625059152/job/135916554369</sub> <sub>LLM reason (✨ experimental): The build failed because `staletiprelayman.cpp` omits the `StaleTipMessage::headers` initializer, and warnings are treated as errors.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
First-time contributor

Earlier concerns remain unresolved; see the Run archive linked from the Review report.

No verified findings are available from this review.

Review coverage was incomplete.


Reviewed: de7a810827be · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:3705f06c6a27c475c77f2533c4d016ac03c829c839b7b538bba5e4768ccf54f1:1ed10c4979af6fc548d6b8d4534d505e02e84ac4b0aa4f8633555b2ba75119e8 --> <!-- ralph-base:a690300ee0d523de0b91e59b00a16fe47297cb85 --> <!-- ralph-head:de7a810827be61bbdc9206ed149a372368fec38a --> <!-- ralph-case:6da22b6decf98db4aa71ea4e4da8efe30c8abd668a6c6a14a90b04813bf4363d --> Earlier concerns remain unresolved; see the Run archive linked from the Review report. No verified findings are available from this review. Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`de7a810827be`](<https://git.fish.foo/bitcoin/bitcoin/commit/de7a810827be61bbdc9206ed149a372368fec38a>) · [Review report](<https://review.fish.foo/report/36920-de7a810827be61bbdc9206ed149a372368fec38a-2893-5.html>) · [Previous reports](<https://review.fish.foo/traces/36920/>) [permalink](<https://review.fish.foo/report/36920-de7a810827be61bbdc9206ed149a372368fec38a-2893-5.html>)
DrahtBot commented 2026-11-23 10:22:27 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36920
No description provided.