mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 12:17:38 +00:00
cmpctblock: Improve logging of cmpctblock message reconstruction statistics [part of prefill series] #35724
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!35724
Loading…
Reference in a new issue
No description provided.
Delete branch "2026-07-14-cb-logging"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Split from #35558, this makes it easier to observe compact block reconstruction performance by:
CMPCTBLOCKs.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.
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:
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.
If I understand correctly, removing this decrement assumes that the existing candidate came from the extrapool.
However, it may have been inserted during the earlier mempool scan. Would it make sense to track the candidate’s source and decrement the corresponding counter?
Seems tangentially related to https://github.com/bitcoin/bitcoin/pull/35727
yeah, thanks for catching @w0xlt, I'll fix this after #35727, as that will make this change easier to make correct, marking this pr as draft for now
🐙 This pull request conflicts with the target branch and needs rebase.
Reworked after https://github.com/bitcoin/bitcoin/pull/35727 merged, this is ready for review.
The code has contradictory logging levels:
Suggestion:
nit: tiny preference for
redundant_prefilled_mempool_countinstead ofredundant_prefilled_mp_count(and similar) here for readability. Not sure if saving the 5 characters is worth it.Good catch @w0xlt. In addition to that, I fear the current log will be hard to analyze automatically or even grep for. It might make sense to include slightly more information than
- txid: 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33bin the line, similar to the reconstruction logging you changed above. How about:"Sending {txid} to {peer} in BLOCKTXN"?
Alternatively, does it make sense to put all txids, maybe comma separated, into a single line?
I'm not sure this is the right data structure here. I think we can do this more cleanly with a
std::map<Wtxid, size_t>and populate it below in thefor (size_t i = 0; i < cmpctblock.prefilledtxn.size(); i++) {loop. Instead of callingpool->existsfor each prefill (which takes the pool lock each time), we can take callGetIterafter we take the pool lock later. This lets us avoid sorting the vector as well.A quick example of how it could look
nit: prefer prefixing
++and--.I'm not sure I agree with the approach of
78715aab94. Incrementing the counts inline is very cheap. I can't see it be worth the code complexity to move these out. The next commit where the size of transactions are computed only for debug logging would make sense to do.We should have a comment here that these will only be set if debug logging is enabled.
marking as resolvesed since #35727 was merged and I've updated this PR based on that.
I moved the count inc/dec out because I thought it made the code easier to read, not for performance.
The problem is tracking the states, e.g. when decrementing because of a collision, we will have to check whether the tx_source is mempool or extra. it is definitely possible to do it inline, but IMO it's logic that is unrelated to compactblock reconstruction right in the middle of critical and subtle code, it's nice to scope all the logging code, and even though it's ~7 lines longer as-is, I think it makes it easier to read the function.
I could shorten the current thing to something like
but I think it is clearer as a switch.
Thanks, fixed.
Thanks, fixed
Thanks, fixed
Thanks, I've made it one log line instead.
ACK
a55e3bb55aHey @davidgumberg just wondering if you had any thoughts on this suggestion?
The main thing is that we're taking the lock inside each loop via
pool->existswith the current approach.Doing another review pass over the code and also running it on signet a bit. Saw this log, which looks good to me:
Before leaving an ACK, it would be good to have andrew's comment https://github.com/bitcoin/bitcoin/pull/35724#discussion_r3992152662 addressed/answered.
Sorry, I did not mean to leave this unaddressed, I just have to think about how to integrate this with the other PR and haven't had a chance yet, will update soon.
Would be good to have a block hash here too
You can probably reuse
debug_lognit
nit: An LLM told me about this, which might be a tiny bit slower than your manual pre-reserve string construction, but might be a bit cleaner. Needs
#include <util/string.h>.might make sense to change this into one long line too?
For anyone wondering: The length of the log message is capped by the bounds of the number of transactions in the block. While GETBLOCKTXN allows up to potentially 65k indexes, we don't log (as we call
Misbehaving()andreturn) if a peer requests out-of-bounds indexes.Base:
f13ae519de94394314cd63a27924b0998ac65d45Head:
4f5ce816db1055b8d885113397c7215dc7af3c83Findings
Minor
Logging enabled during reconstruction can report uncaptured statistics as zero (src/blockencodings.cpp:201, head)
InitData collects source counts, sizes, and redundancy totals only when its
debug_logsnapshot is true, but FillBlock checks the current setting before printing them. Ifcmpctblocklogging is enabled while the partial block waits for a BLOCKTXN response, the log reports zero counts, byte totals, and redundancy even when those values are nonzero. Track whether the statistics were collected and avoid presenting uncaptured values as measured zeros.Suggestions
Update the collision test comment to describe final source counts (src/blockencodings.cpp:190, head)
The collision path now decrements
available_count, whilemempool_countandextra_countare derived later from the final source state. The test comment atsrc/test/blockencodings_tests.cpp:379says both counters decrement exactly once, which no longer describes the implementation. Reword it to describe the final source counts.Include
<map>directly (src/blockencodings.cpp:75, head)This file now uses
std::mapwithout directly including<map>, relying instead on an indirect include. The repository's source-organization guidance calls for including headers that provide definitions used by the file. Add<map>to keep this dependency explicit if transitive includes change.Trace missing transaction IDs when reconstruction fails (src/blockencodings.cpp:301, head)
The new missing-transaction ID trace runs only after the mutation check succeeds. When FillBlock returns READ_STATUS_FAILED, such as on a reconstruction mismatch, this path does not log the returned
vtx_missingIDs, and the network caller provides only generic failure context. Consider logging those IDs at trace level on the failure path so the diagnostic information is available for failed reconstructions.Review coverage was incomplete. adversarial: The CMPCTBLOCK callers around net_processing.cpp:4931/4982 and GETBLOCKTXN callers around :4590/4616 were not inspected; their admission and retry guards determine the repetition bounds on the added logging work. adversarial: The runtime logging-category update path was not inspected, leaving the reachability of the in-flight logging-toggle case below unverified. adversarial_glm: Whether the unit-test harness enables BCLog::CMPCTBLOCK debug logging by default (setup_common logging defaults) was not read; it decides whether the GetExtraCount()/GetMempoolCount() assertions in blockencodings_tests.cpp actually fail at head or are merely fragile. This could upgrade finding 2 from a fragility to a broken test. adversarial_glm: CTxMemPool::GetIter(const uint256&) semantics in txmempool.h (txid index vs wtxid index lookup) were not read. InitData:137 passes a Wtxid; if GetIter resolves only by txid, redundant_prefilled_mempool_* undercounts witness prefills (logging-accuracy only). adversarial_glm: blockencodings.cpp lines 150-308 at head (tail of InitData and FillBlock) and net_processing.cpp around SendBlockTransactions were verified only against the literal patch hunks, not re-read in the checkout; residual risk is low since the hunks cover all changed lines and FillBlock's unchanged prologue uses prefilled_count, which is still maintained unconditionally (InitData:78).
Full review report
OK, thanks for patience here, this is much better and I've taken it, it will cause a little bit more churn in the next PR but both are improved by this IMO and I'd rather not have bad code merged "temporarily" because it will make a future PR that may or may not happen cleaner. I'll mark this as resolved and we can continue discussion on the current diff if needed, it might still need improving.
Oops, copy paste mistake, thanks for catching, fixed.
Good catch, I have had to write debug.log parsing state trackers before because of log message like this, maybe I was subconsciously making it so that others would feel my pain.
Taken, thank you.
Much better, thank you.
That's awesome, thank you.
Done, and used the same thing you suggested above.
Thanks for the patience here, I've pushed to address reviewer feedback.
I'm not sure if this
Assumecan ever be hit in fuzzing. My understanding is that we e.g. don't run fuzzing with logging enabled. (however, I happen to run binaries that will Assert on Assumes on peer-observer).Code review ACK
1a9b2865caThis is how it looked for me on signet (without anyone prefilling yet):
ACK
1a9b2865caThanks for taking the
std::mapsuggestions ❤️A future refactor could change the type of
extra_txnfromconst std::vector<std::pair<Wtxid, CTransactionRef>>& extra_txnto
const std::vector<std::pair<Wtxid, util::NotNull<CTransactionRef>>>& extra_txnand then this line would not be necessary.
typo in first commit description:
nit: we could specify that "cmpctblock logging is enabled".
nit: same here, "cmpctblock logging is enabled".
@davidgumberg do you want to take the nits?
Good idea, I'll leave this for later.
Thanks, done.
Thanks, I've updated the comment to be clearer and more specific.
Thanks, fixed.
I've pushed to address @andrewtoth's feedback, the changes since the last push only change a commit message and some code comments.
ACK
8abb996f05reACK
8abb996f05if you retouch
Ah, thanks I fixed since I could not live with this.
Pushed to fix a code comment typo.
reACK
4f5ce816dbreACK
4f5ce816dbreACK
4f5ce816dbACK
4f5ce816dbClean and straightforward logging change. Reproduced and checked the logs (on live mainnet node). Reviewed code, left some non-blocking optional nits.
Concern checked:
available_countunderflowing. Due the logic that's not possible, because every decrement must be preceeded by an increment. (Even if overflow happened, that wouldn't be a critical issue.)Nit: The trailing
"\n"is recommended to be omitted from log messages (also not consistent with the other changed log lines).Nit (for the future): The variable names could be prefixed by
log_, to hint that they are used for logging (slightly stronger hint than the comments).Nit (for the future): Since there are a number of count&size pairs here, maybe a minimal count+size struct would make sense.
Good point. As there is a hard cap on the max number, the long log line is acceptable, though the worse-case memory usage of few MB's is not that nice. Breaking the line after every 100 IDs or so would be more robust though.
Yeah, enforcing this with a comment is bad, variable name is a little bit better, ideally there would be a programmatic way to stop others from using, but I couldn't think of one.
Thanks, if not blocking I'll fix this in the next prefill-related PR.
utACK
4f5ce816db