tracing: add block header and compact block tracepoints #35368

Open
w0xlt wants to merge 2 commits from tracing-compact-block-usdt into master AGit
w0xlt commented 2026-05-23 21:04:39 +00:00 (Migrated from github.com)

This PR adds two USDT tracepoints for compact block relay:

  • net:block_header: fires when a new valid header is received from a peer (via headers or cmpctblock).
  • net:compact_block_reconstructed: fires when a compact block is successfully reconstructed, just before validation.

The motivation is to expose structured, low-overhead observability for compact block relay behavior.

Compact block relay is performance-sensitive: whether a node reconstructs a block without round trips depends on mempool overlap, extra transaction pool usefulness, and peer behavior.

Today this information is mostly available only through debug logs, which are string-based, less precise for tooling, and not ideal for continuous measurement.

What they enable measuring:

  • Which peers announce new headers first, and whether headers arrived via compact block announcements.
  • Per-peer compact block reconstruction success.
  • Where each transaction came from — prefilled, mempool, extra pool, or a getblocktxn round trip.
  • How often compact blocks reconstruct with no round trip, and the bandwidth cost when they don't.
  • Whether high-bandwidth compact block peers actually improve relay, and how mempool divergence affects reconstruction quality.

Design notes.

  • All data is already available at the reconstruction point; nothing new is computed in the hot path. USDT tracepoints stay inactive unless a tracing tool is attached.
  • Mempool and extra-pool counts are reported as disjoint fields, so consumers can aggregate without double-counting. The reconstruction tracepoint includes the peer ID, making metrics attributable to the peer that supplied the compact block data.
This PR adds two USDT tracepoints for compact block relay: - `net:block_header`: fires when a new valid header is received from a peer (via `headers` or `cmpctblock`). - `net:compact_block_reconstructed`: fires when a compact block is successfully reconstructed, just before validation. The motivation is to expose structured, low-overhead observability for compact block relay behavior. Compact block relay is performance-sensitive: whether a node reconstructs a block without round trips depends on mempool overlap, extra transaction pool usefulness, and peer behavior. Today this information is mostly available only through debug logs, which are string-based, less precise for tooling, and not ideal for continuous measurement. What they enable measuring: - Which peers announce new headers first, and whether headers arrived via compact block announcements. - Per-peer compact block reconstruction success. - Where each transaction came from — prefilled, mempool, extra pool, or a `getblocktxn` round trip. - How often compact blocks reconstruct with no round trip, and the bandwidth cost when they don't. - Whether high-bandwidth compact block peers actually improve relay, and how mempool divergence affects reconstruction quality. Design notes. - All data is already available at the reconstruction point; nothing new is computed in the hot path. USDT tracepoints stay inactive unless a tracing tool is attached. - Mempool and extra-pool counts are reported as disjoint fields, so consumers can aggregate without double-counting. The reconstruction tracepoint includes the peer ID, making metrics attributable to the peer that supplied the compact block data.
DrahtBot commented 2026-05-23 21:04:45 +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.

Type Reviewers
Concept ACK 0xB10C, m4ycon

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #35724 (cmpctblock: Improve logging of cmpctblock message reconstruction statistics [part of prefill series] by davidgumberg)
  • #35558 (p2p: Prefill compact blocks by davidgumberg)
  • #35502 (refactor: extract per-message helpers from ProcessMessage (move-only) by w0xlt)

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.

<!--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/35368 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/35368.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/35368#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. | Type | Reviewers | | ---- | --------- | | Concept ACK | [0xB10C](https://github.com/bitcoin/bitcoin/pull/35368#issuecomment-4528980947), [m4ycon](https://github.com/bitcoin/bitcoin/pull/35368#pullrequestreview-4353399369) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#35724](https://github.com/bitcoin/bitcoin/pull/35724) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35724.svg"></sub> (cmpctblock: Improve logging of `cmpctblock` message reconstruction statistics [part of prefill series] by davidgumberg) * [#35558](https://github.com/bitcoin/bitcoin/pull/35558) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35558.svg"></sub> (p2p: Prefill compact blocks by davidgumberg) * [#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) 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-->
w0xlt commented 2026-05-23 22:49:15 +00:00 (Migrated from github.com)
CI error unrelated. See https://github.com/bitcoin/bitcoin/issues/34731.
0xB10C commented 2026-05-24 14:14:30 +00:00 (Migrated from github.com)

Generally in favor of having a way of exposing data about this in a non-logging way. Especially since fast compact block relay and reconstructions seem to be somewhat of a share priority by contributors. Concept ACK on exposing this data.

In https://github.com/peer-observer/peer-observer/pull/420, @m4ycon has been working on reading very similar information for the debug log. My understanding is that this works well, but is obviously brittle.

There's also the question about adding more tracepoints now, or investing time into seeing if #35142 is feasible...

Generally in favor of having a way of exposing data about this in a non-logging way. Especially since fast compact block relay and reconstructions seem to be somewhat of a share priority by contributors. Concept ACK on exposing this data. In https://github.com/peer-observer/peer-observer/pull/420, @m4ycon has been working on reading very similar information for the debug log. My understanding is that this works well, but is obviously brittle. There's also the question about adding more tracepoints now, or investing time into seeing if #35142 is feasible...
0xB10C (Migrated from github.com) reviewed 2026-05-24 14:19:19 +00:00
0xB10C (Migrated from github.com) commented 2026-05-24 14:19:19 +00:00

With tracepoints essentially matching the log statements, I wonder if there's some way of combine the two - but that's obviously out of scope for this PR.

With tracepoints essentially matching the log statements, I wonder if there's some way of combine the two - but that's obviously out of scope for this PR.
m4ycon (Migrated from github.com) reviewed 2026-05-24 21:08:38 +00:00
m4ycon (Migrated from github.com) left a comment

Concept ACK

Also a suggestion on additional info.

Concept ACK Also a suggestion on additional info.
Lines 236-244
m4ycon (Migrated from github.com) commented 2026-05-24 21:05:48 +00:00

While monitoring dashboards from https://github.com/peer-observer/peer-observer/pull/420, my node had a pretty weird period where it was always requesting txs from other nodes (stats.requested_txn_count > 0). The image below, this panels measures time taken to reconstruct a block, left panel shows reconstructions that didn't need to request txs, and the right one shows more than zero requested transactions.

image

One of the things that people suggested to me, it was that I look at what kind of transactions were being requested, if there was some pattern or things like that. Unfortunately, I didn't have -debug=net enabled which probably would have helped me to answer it.

But with your PR, it makes me think if this isn't an interesting information to pass through tracepoints: all the txids from vtx_missing. What do you guys think? Maybe this is too much data to send? As a real sample from my node, the highest "transactions requested" was 2041 in the last 30 days.

While monitoring dashboards from https://github.com/peer-observer/peer-observer/pull/420, my node had a pretty weird period where it was always requesting txs from other nodes (`stats.requested_txn_count > 0`). The image below, this panels measures time taken to reconstruct a block, left panel shows reconstructions that didn't need to request txs, and the right one shows more than zero requested transactions. <img width="1242" height="435" alt="image" src="/attachments/4b02ea05-aa89-4d39-abeb-384b6558fec7" /> One of the things that people suggested to me, it was that I look at what kind of transactions were being requested, if there was some pattern or things like that. Unfortunately, I didn't have `-debug=net` enabled which probably would have helped me to answer it. But with your PR, it makes me think if this isn't an interesting information to pass through tracepoints: all the txids from `vtx_missing`. What do you guys think? Maybe this is too much data to send? As a real sample from my node, the highest "transactions requested" was 2041 in the last 30 days.
0xB10C (Migrated from github.com) reviewed 2026-05-25 09:52:51 +00:00
0xB10C (Migrated from github.com) commented 2026-05-25 09:52:51 +00:00

I think a structured logging interface as discussed in https://github.com/bitcoin/bitcoin/issues/35369 would be a good solution avoiding duplication between logging statements and tracepoints. We'd get the same information about compact block reconstructions in a machine-to-machine interface.

I think a structured logging interface as discussed in https://github.com/bitcoin/bitcoin/issues/35369 would be a good solution avoiding duplication between logging statements and tracepoints. We'd get the same information about compact block reconstructions in a machine-to-machine interface.
0xB10C (Migrated from github.com) reviewed 2026-05-25 10:04:59 +00:00
Lines 236-244
0xB10C (Migrated from github.com) commented 2026-05-25 10:04:59 +00:00

It's rather impractical to pass lists or sets via tracaepoints, they don't really support it. While it might work by concatenating the txids and passing the length and passing the concatenated bytes, I don't think we should do these kind of hacks if we can avoid it.

I didn't have -debug=net enabled

Note that you only need compact block logging enabled. However, we only print the txids if there were less than 5 transactions missing. I've in the past ran a patched bitcoind that removed this limitation and logged all missing txids. To look up why your node didn't know about a certain transaction, you probably want to have -debug=net enabled. It might tell you that a transaction was replaced, evicted from orphanage, you never got an inv for it, ...

github.com/bitcoin/bitcoin@de925455c8/src/blockencodings.cpp (L222-L232)

It's rather impractical to pass lists or sets via tracaepoints, they don't really support it. While it might work by concatenating the txids and passing the length and passing the concatenated bytes, I don't think we should do these kind of hacks if we can avoid it. > I didn't have -debug=net enabled Note that you only need compact block logging enabled. However, we only print the txids if there were less than 5 transactions missing. I've in the past ran a patched bitcoind that removed this limitation and logged all missing txids. To look up why your node didn't know about a certain transaction, you probably want to have `-debug=net` enabled. It might tell you that a transaction was replaced, evicted from orphanage, you never got an inv for it, ... https://github.com/bitcoin/bitcoin/blob/de925455c8025fc1f75d65d981c28b9dfa20e9f7/src/blockencodings.cpp#L222-L232
stickies-v commented 2026-05-26 11:13:53 +00:00 (Migrated from github.com)

There's also the question about adding more tracepoints now, or investing time into seeing if #35142 is feasible...

I agree it would make more sense to clarify that first before adding more tracepoints.

> There's also the question about adding more tracepoints now, or investing time into seeing if #35142 is feasible... I agree it would make more sense to clarify that first before adding more tracepoints.
w0xlt commented 2026-05-27 03:46:45 +00:00 (Migrated from github.com)

I don't think the IPC tracing discussion should block this functionality, assuming there is demand for it.

My understanding is that IPC tracing is a promising direction, but not a drop-in replacement for USDT today.
With the current libmultiprocess-generated C++ proxy interfaces, calls are synchronous by default, so a naive tracing implementation where an instrumentation site directly invokes subscriber callbacks would block the Bitcoin Core thread until the subscriber replies.

That callback model is a poor fit for high-frequency tracing, especially for events like raw P2P messages or per-UTXO cache events, unless it is designed with non-blocking buffering, batching, filtering, and backpressure/drop handling.

So I see IPC tracing as a longer-term project with its own tradeoffs, while this PR is a small addition to the existing USDT tracing interface.

I don't think the IPC tracing discussion should block this functionality, assuming there is demand for it. My understanding is that IPC tracing is a promising direction, but not a drop-in replacement for USDT today. With the current libmultiprocess-generated C++ proxy interfaces, calls are synchronous by default, so a naive tracing implementation where an instrumentation site directly invokes subscriber callbacks would block the Bitcoin Core thread until the subscriber replies. That callback model is a poor fit for high-frequency tracing, especially for events like raw P2P messages or per-UTXO cache events, unless it is designed with non-blocking buffering, batching, filtering, and backpressure/drop handling. So I see IPC tracing as a longer-term project with its own tradeoffs, while this PR is a small addition to the existing USDT tracing interface.
DrahtBot commented 2026-07-21 21:21:53 +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).
sedited commented 2026-08-27 11:20:21 +00:00 (Migrated from github.com)

@w0xlt can you rebase this?

@w0xlt can you rebase this?
sedited commented 2026-10-08 13:11:54 +00:00 (Migrated from github.com)

This has been in need of rebase for a few months now. Are you still working on this?

This has been in need of rebase for a few months now. Are you still working on this?
First-time contributor

Base: 152a55397e451fed9c10041bddf01aa6839847d5
Head: ef3121b6e028b4bd6ecc07f713006ed1a7ba99ed

No verified findings are available from this review.

Review coverage was incomplete.

Review limitations
  • adversarial_deepseek: Stage did not complete (ValueError).
  • verifier: Model API request timed out.

Full review report

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:78d2fcf8f9ff126c05365e10c73177ff8910b0e09bc81c9ec0b230b2aa3a4312:f359184720b19d8f4199eb38e750c73a24dbe6263b5428fbe549b1858030cb9b --> Base: `152a55397e451fed9c10041bddf01aa6839847d5` Head: `ef3121b6e028b4bd6ecc07f713006ed1a7ba99ed` No verified findings are available from this review. Review coverage was incomplete. <details> <summary>Review limitations</summary> - adversarial_deepseek: Stage did not complete (ValueError). - verifier: Model API request timed out. </details> [Full review report](<https://review.fish.foo/traces/35368-ef3121b6e028b4bd6ecc07f713006ed1a7ba99ed-1142-3.html>)
w0xlt commented 2026-10-08 17:08:41 +00:00 (Migrated from github.com)

@sedited Rebased. Thanks

@sedited Rebased. Thanks
DrahtBot commented 2026-10-16 08:04:25 +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).
maflcko commented 2026-10-16 08:15:27 +00:00 (Migrated from github.com)

So I see IPC tracing as a longer-term project with its own tradeoffs, while this PR is a small addition to the existing USDT tracing interface.

Not sure about adding code that will be removed soon anyway? Ref https://github.com/bitcoin/bitcoin/issues/35142#issuecomment-5992319514

perhaps dropping tracing entirely from this repo

But no strong opinion. If there are active users that want this pull, it should be trivial for them to step up and review it? Though, if those users are compiling from source anyway, they can just use this code (or any other code their LLM writes) without having to go through review here. Again, no objection. I am just curious about the direction and impact.

> So I see IPC tracing as a longer-term project with its own tradeoffs, while this PR is a small addition to the existing USDT tracing interface. Not sure about adding code that will be removed soon anyway? Ref https://github.com/bitcoin/bitcoin/issues/35142#issuecomment-5992319514 > perhaps dropping tracing entirely from this repo But no strong opinion. If there are active users that want this pull, it should be trivial for them to step up and review it? Though, if those users are compiling from source anyway, they can just use this code (or any other code their LLM writes) without having to go through review here. Again, no objection. I am just curious about the direction and impact.
w0xlt commented 2026-10-22 17:30:11 +00:00 (Migrated from github.com)
Thanks for the feedback. Added my two cents in the thread: https://github.com/bitcoin/bitcoin/issues/35142#issuecomment-6346952054
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!35368
No description provided.