Skip to content

Emit mempool transactions that share a timestamp - #1177

Merged
tnull merged 1 commit into
lightningdevkit:mainfrom
ajaysehwal:fix-mempool-same-second-emission
Nov 18, 2026
Merged

tnull merged 1 commit into
lightningdevkit:mainfrom
ajaysehwal:fix-mempool-same-second-emission

Conversation

@ajaysehwal

@ajaysehwal ajaysehwal commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1140.

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

We now track whether a transaction was emitted with an emitted flag on the cached MempoolEntry:

  • An entry is skipped only if it was already emitted and its ancestors are known to be processed (the existing entry.height <= best_processed_height check is unchanged).
  • Entries that left the mempool are dropped with their flag, so a transaction that re-enters it is emitted again.
  • Flags are set only after all transactions of a poll were fetched, so a failed poll doesn't mark transactions the receiver never got.

latest_mempool_timestamp is now only used as the timestamp of evicted transactions.

Tests: the selection and marking live in emit_new_mempool_txs, which takes the fetch as a closure, so the tests drive it directly: same-second transaction, lagging ancestors, and a failed fetch followed by a retry. The lib tests pass, and I didn't run the integration tests.

AI disclosure: prepared with the assistance of Claude Code.

@ldk-reviews-bot

ldk-reviews-bot commented Oct 17, 2026 •

Copy link
Copy Markdown

👋 Thanks for assigning @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
@ajaysehwal
ajaysehwal force-pushed the fix-mempool-same-second-emission branch from d12c5fd to f33bb4c Compare November 10, 2026 10:58
@tnull tnull added this to the 0.8 milestone Nov 17, 2026

@tnull tnull left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks! It seems there might be simpler ways to address this though. If possible would be good to avoid the parallel HashSet tracking.

Comment thread src/chain/bitcoind.rs Resolved
Comment thread src/chain/bitcoind.rs Resolved
Comment thread src/chain/bitcoind.rs Resolved
Comment thread src/chain/bitcoind.rs Resolved
@ajaysehwal
ajaysehwal force-pushed the fix-mempool-same-second-emission branch from f33bb4c to ea79f25 Compare November 17, 2026 16:16
@ajaysehwal

ajaysehwal commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks! It seems there might be simpler ways to address this though. If possible would be good to avoid the parallel HashSet tracking.

@tnull , Thanks for the review. Reworked as suggested: the txid set is replaced by an emitted flag on MempoolEntry, and the select-and-mark logic is one function that the tests drive directly. Force-pushed.

@ajaysehwal
ajaysehwal requested a review from tnull November 17, 2026 17:13

@tnull tnull left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Two comments, otherwise looks good.

Comment thread src/chain/bitcoind.rs Resolved
Comment thread src/chain/bitcoind.rs Resolved
`get_mempool_transactions_and_timestamp_at_height` decided whether a
mempool transaction was already emitted solely by comparing its entry
time to the saved cursor. Entry times only have second resolution, so
a new transaction sharing the second of an already emitted one was
skipped for as long as it stayed unconfirmed, and the wallet missed
the unconfirmed payment until it confirmed.

Cache each `MempoolEntry` in a `CachedMempoolEntry` that tracks
whether we emitted its transaction instead. Entries are only marked
once all transactions of a poll were fetched, so a failed poll doesn't
mark transactions the receiver never got, and entries that left the
mempool are dropped with their flag, so a transaction that re-enters
it is emitted again. The selection and marking now live in
`emit_new_mempool_txs`, which takes the fetch as a closure so tests
can drive it.

As the cursor is now only used as the timestamp of evicted
transactions, rename it to `mempool_eviction_timestamp`.

Fixes lightningdevkit#1140.

Prepared with the assistance of Claude Code.
@ajaysehwal
ajaysehwal force-pushed the fix-mempool-same-second-emission branch from ea79f25 to 1a9e8a3 Compare November 18, 2026 13:25
@ajaysehwal
ajaysehwal requested a review from tnull November 18, 2026 13:28
@tnull
tnull merged commit 0c214c5 into lightningdevkit:main Nov 18, 2026
13 of 27 checks passed
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

3 participants