Skip to content

tracing: add block header and compact block tracepoints - #35368

Open
w0xlt wants to merge 2 commits into
bitcoin:masterfrom
w0xlt:tracing-compact-block-usdt
Open

w0xlt wants to merge 2 commits into
bitcoin:masterfrom
w0xlt:tracing-compact-block-usdt

Conversation

@w0xlt

@w0xlt w0xlt commented May 23, 2026

Copy link
Copy Markdown
Contributor

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

DrahtBot commented May 23, 2026 •

Copy link
Copy Markdown
Contributor

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.

@w0xlt
w0xlt force-pushed the tracing-compact-block-usdt branch from c317972 to c96e7d7 Compare May 23, 2026 21:47
@w0xlt
w0xlt force-pushed the tracing-compact-block-usdt branch from c96e7d7 to fbfeb88 Compare May 23, 2026 21:49
@w0xlt

w0xlt commented May 23, 2026

Copy link
Copy Markdown
Contributor Author

CI error unrelated. See #34731.

@0xB10C

0xB10C commented May 24, 2026 •

Copy link
Copy Markdown
Contributor

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 peer-observer/peer-observer#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...

Comment thread src/net_processing.cpp
block_hash.ToString(),
index.nHeight,
peer.LogPeer()
);

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.

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.

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 think a structured logging interface as discussed in #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.

@m4ycon m4ycon left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Concept ACK

Also a suggestion on additional info.

Comment thread src/net_processing.cpp
Comment on lines +228 to +236
TRACEPOINT(net, compact_block_reconstructed,
peer.GetId(),
stats.prefilled_txn_count,
stats.mempool_txn_count,
stats.extra_pool_txn_count,
stats.requested_txn_count,
stats.requested_txn_bytes,
hash.data()
);

@m4ycon m4ycon May 24, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

While monitoring dashboards from peer-observer/peer-observer#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.

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.

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

if (util::log::ShouldDebugLog(BCLog::CMPCTBLOCK)) {
const uint256 hash{block.GetHash()};
uint32_t tx_missing_size{0};
for (const auto& tx : vtx_missing) tx_missing_size += tx->ComputeTotalSize();
LogDebug(BCLog::CMPCTBLOCK, "Successfully reconstructed block %s with %u txn prefilled, %u txn from mempool (incl at least %u from extra pool) and %u txn (%u bytes) requested\n", hash.ToString(), prefilled_count, mempool_count, extra_count, vtx_missing.size(), tx_missing_size);
if (vtx_missing.size() < 5) {
for (const auto& tx : vtx_missing) {
LogDebug(BCLog::CMPCTBLOCK, "Reconstructed block %s required tx %s\n", hash.ToString(), tx->GetHash().ToString());
}
}
}

@stickies-v

Copy link
Copy Markdown
Contributor

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

w0xlt commented May 27, 2026 •

Copy link
Copy Markdown
Contributor Author

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.

@sedited

sedited commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

@w0xlt can you rebase this?

@sedited

sedited commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

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

@w0xlt
w0xlt force-pushed the tracing-compact-block-usdt branch from fbfeb88 to ef3121b Compare October 8, 2026 17:05
@w0xlt

w0xlt commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@sedited Rebased. Thanks

@DrahtBot

Copy link
Copy Markdown
Contributor

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

@maflcko

maflcko commented Oct 16, 2026

Copy link
Copy Markdown
Member

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 #35142 (comment)

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

w0xlt commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback. Added my two cents in the thread: #35142 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants