AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Informational 21 Bitcoin

log,blocks: avoid `ComputeTotalSize` and `GetHash` work when logging is disabled

Public commit record

What the developer wrote

Authored by Lőrinc

85/100 · Strong
log,blocks: avoid `ComputeTotalSize` and `GetHash` work when logging is disabled

`PartiallyDownloadedBlock::FillBlock()` computed the block header hash and summed missing transaction sizes for debug logging unconditionally, including when cmpctblock debug logging is disabled.

Guard the debug-only hash and size computations with `LogAcceptCategory`.
Since `txn_available` is invalidated after the first loop (needed for efficient moving), we compute `tx_missing_size` by iterating `vtx_missing` directly. This is safe because the later `tx_missing_offset` check guarantees `vtx_missing` was fully consumed during reconstruction.

Use `block.GetHash()` instead of `header.GetHash()`, since header is cleared before logging.

No behavior change when debug logging is enabled: the reported counts, hashes, and byte totals remain the same.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode
The short version

What changed, and why it matters

This is a small performance cleanup, not a security fix. Bitcoin Core was doing unnecessary work—calculating a block hash and adding up transaction byte sizes—every time it reconstructed a compact block, even when the relevant debug logging was turned off. The change simply skips that work when debug logging is disabled. The log output is unchanged when logging is on, and no network behavior or consensus rules change.

Recommended action

No security action needed. Treat as a normal performance/refactoring commit. Reviewers may verify that the new vtx_missing iteration is safe and that log output remains identical when BCLog::CMPCTBLOCK debug logging is enabled.

Security signals we found

01

No security-relevant signal present

02

Performance optimization only

03

No input validation, memory safety, or cryptographic changes

Risk score

Why this scored 21/100

Our methodology →
Potential impact 2/30
Exploitability 0/25
Stealth signal 0/15
Affected reach 5/15
Confidence 9/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.