Skip to content

Emit mempool transactions that share a timestamp - #1177

Open
ajaysehwal wants to merge 1 commit into
lightningdevkit:mainfrom
ajaysehwal:fix-mempool-same-second-emission
Open

ajaysehwal wants to merge 1 commit into
lightningdevkit:mainfrom
ajaysehwal:fix-mempool-same-second-emission

Conversation

@ajaysehwal

Copy link
Copy Markdown
Contributor

Fixes #1140.

get_mempool_transactions_and_timestamp_at_height decided whether a mempool transaction had already been emitted solely by comparing its entry time to the saved cursor. Bitcoin Core's mempool entry times only have second resolution, so a new transaction that shares the second of an already emitted one was skipped, and kept being skipped for as long as it stayed unconfirmed. The wallet then missed the unconfirmed payment until it confirmed in a block.

We now track emitted txids instead:

  • An entry is skipped only if its txid was already emitted and its ancestors are known to be processed (the existing entry.height <= best_processed_height check is unchanged).
  • Txids that left the mempool are forgotten, so a transaction that re-enters it is emitted again. The set is bounded by the mempool size.
  • TxIDs are only added once the poll succeeds, so a failed poll (or a transaction vanishing between listing and fetching) doesn't mark transactions as emitted that the receiver never got.

The timestamp cursor is still used for the evicted-transaction timestamps, and the transaction body cache is unchanged, so correctness no longer depends on cache retention.

Testing

The selection logic is a separate function with unit tests for: a new txid sharing the cursor's second is emitted, emitted transactions aren't repeated, lagging ancestors are emitted again, eviction and re-entry, and a failed poll not being remembered. The same-second, re-entry and failed-poll tests fail with the previous timestamp-only rule and pass with this change. The full lib test suite passes, as do cargo +nightly fmt --check and cargo clippy --lib -- -D clippy::unwrap_used.

AI disclosure

This change was prepared with the assistance of Claude Code.

@ldk-reviews-bot

ldk-reviews-bot commented Oct 17, 2026 •

Copy link
Copy Markdown

I've assigned @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@ldk-reviews-bot
ldk-reviews-bot requested a review from tnull October 17, 2026 15:36
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.

Emit newly observed mempool transactions sharing a timestamp

2 participants