Skip to content

fix(mempool): compare input output_hash in ReorgPool::discard_double_spends - #8441

Closed
aswadi wants to merge 0 commit into
tari-project:developmentfrom
aswadi:fix/reorg-pool-discard-double-spends-output-hash
Closed

aswadi wants to merge 0 commit into
tari-project:developmentfrom
aswadi:fix/reorg-pool-discard-double-spends-output-hash

Conversation

@aswadi

@aswadi aswadi commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

ReorgPool::discard_double_spends previously checked published_block.body.inputs().contains(input), which compares full TransactionInput equality (including script_signature, input_data, and SpentOutput representation) instead of the spent UTXO's output_hash(). As a result, competing transactions in the ReorgPool that spend the same output with a different script_signature were not discarded when a conflicting block was added during a reorg.

Changes

  • Precompute the set of spent output_hash() values from published_block.body.inputs() in ReorgPool::discard_double_spends and discard any ReorgPool transaction that spends a matching output_hash().
  • Avoid pushing duplicate transaction IDs when a transaction shares multiple spent inputs with the published block.
  • Add unit test discard_double_spends_matches_competing_spend_by_output_hash verifying that a competing spend with a distinct script_signature is removed from ReorgPool and all pool indexes remain consistent.

Confidence Score: 4/5 · Fix the new test's always-failing equality assertion before merging.RetriggerView in GreptileConfidence Score: 4/5

Fix the new test's always-failing equality assertion before merging.

FindingsFix All in Claude CodeFindings

  1. P1 New test always fails ▶

Summary

ReorgPool::discard_double_spends now builds a set of spent output hashes and selects each conflicting transaction once.

  • Reorg cleanup removes transactions that spend outputs in a new block.

Reviews (1) · Last reviewed commit: "fix(mempool): compare input output_hash ..." · Reviewed by Greptile

@aswadi
aswadi requested a review from a team as a code owner November 30, 2026 14:23

let mut competing_input = tx1.body.inputs()[0].clone();
competing_input.script_signature = tx2.body.inputs()[0].script_signature.clone();
assert_ne!(&competing_input, &tx1.body.inputs()[0]);

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.

P1 New test always fails

assert_ne! always fails here because TransactionInput::eq compares only output_hash(). Changing script_signature leaves these inputs equal, so the test stops before checking pool removal. Compare the two script_signature fields or their canonical_hash() values instead.

Suggested change
assert_ne!(&competing_input, &tx1.body.inputs()[0]);
assert_ne!(competing_input.script_signature, tx1.body.inputs()[0].script_signature);

Fix in Claude Code Fix in Codex

@aswadi aswadi closed this Nov 30, 2026
@aswadi
aswadi force-pushed the fix/reorg-pool-discard-double-spends-output-hash branch from c43303e to e1eb873 Compare November 30, 2026 14:30
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.

1 participant