Skip to content

blockencodings: fix extra transaction accounting - #229

Closed
l0rinc wants to merge 2 commits into
masterfrom
l0rinc/extra-count-source-accounting
Closed

l0rinc wants to merge 2 commits into
masterfrom
l0rinc/extra-count-source-accounting

Conversation

@l0rinc

@l0rinc l0rinc commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Problem: When an extra_txn candidate collides with a transaction already found in the mempool, InitData() decrements extra_count even though the invalidated transaction did not come from extra_txn.
bitcoin#35727 prevents underflow at zero with a saturating decrement, but that still consumes the credit for an unrelated extra transaction when the count is positive, leaving the logged count incorrect.

Fix: Track whether each short-ID slot was filled from the mempool or extra_txn, and decrement extra_count only when a collision invalidates an extra-sourced transaction.
The source remains set after a collision, preserving the existing behavior that later candidates cannot refill that slot.

@instagibbs

Copy link
Copy Markdown

this seems better, and I couldn't detect any obvious performance impact. Code being easier to read is a bonus

l0rinc added 2 commits July 16, 2026 10:50
A short ID collision can invalidate a mempool-sourced transaction after an unrelated transaction was found in `extra_txn`.

Track each slot's state so `extra_count` is decremented only when invalidating an extra-sourced transaction.
Mark collided slots explicitly to preserve the rule that later candidates do not refill them.
@l0rinc
l0rinc force-pushed the l0rinc/extra-count-source-accounting branch from 0c69909 to 1c9ce58 Compare July 16, 2026 17:51
Comment thread src/blockencodings.cpp
// If we find two mempool txn that match the short id, just request it.
// This should be rare enough that the extra bandwidth doesn't matter,
// but eating a round-trip due to FillBlock failure would be annoying
if (txn_available[idit->second]) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should probably become

Suggested change
if (txn_available[idit->second]) {
if (tx_source[idit->second] != TxSource::CONFLICTED) {

and ikewise below

@l0rinc l0rinc closed this Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants