Skip to content

bitcoind RPC: Make mempool syncing more efficient #465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 12, 2025

Conversation

tnull
Copy link
Collaborator

@tnull tnull commented Feb 11, 2025

Querying the mempool unfortunately takes multiple sequential steps:
first we call getrawmempool to retrieve a list of all entries and then
retrieve all of them via getmempoolentry.

Previously, we would error out if a previously retrieved Txid wouldn't
be available anymore at the second step. Here, we ensure smooth
continuation by simply skipping any entries we can't retrieve anymore.

Also we would retransmit entry and transaction data whenever
polling for mempool data. Here we introduce simple caches for both, so
most data is only retrieved in bulk on the first iteration after
startup.

Querying the mempool unfortunately takes multiple sequential steps:
first we call `getrawmempool` to retrieve a list of all entries and then
retrieve all of them via `getmempoolentry`.

Previously, we would error out if a previously retrieved `Txid` wouldn't
be available anymore at the second step. Here, we ensure smooth
continuation by simply skipping any entries we can't retrieve anymore.
@tnull tnull requested review from jkczyz and arik-so and removed request for jkczyz February 11, 2025 15:37
@tnull tnull force-pushed the 2025-02-fix-mempool-access branch from ccc699e to a8dbe2e Compare February 11, 2025 15:42
Previously, we would retransmit entry and transaction data whenever
polling for mempool data. Here we introduce simple caches for both, so
most data is only retrieved in bulk on the first iteration after
startup.
.. including `TRACE` logs of relevant interval times
@tnull tnull force-pushed the 2025-02-fix-mempool-access branch from a8dbe2e to 150ea3d Compare February 11, 2025 15:46
match self.get_raw_transaction(&entry.txid).await {
Ok(Some(tx)) => {
mempool_txs_cache.insert(entry.txid, (tx.clone(), entry.time));
txs_to_emit.push((tx, entry.time));
},
Ok(None) => {
Copy link

Choose a reason for hiding this comment

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

should the case of having a txid among the mempool entries but not being able to find its full tx hex be handled somehow?

Copy link
Collaborator Author

@tnull tnull Feb 12, 2025

Choose a reason for hiding this comment

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

Well, we handle it by skipping :)

Note that we used to log/error out in some of these races, but its exactly the point to get rid of that behavior in this PR. In fact, turns out you'll regularly run into these races between getrawmempool/getmempoolentry and getmempoolentry/getrawtransaction, since entries are dropped often from the mempool. So we can just skip processing them and will re-detect them if they would reappear in the mempool.

@tnull tnull merged commit 7e6f9c1 into lightningdevkit:main Feb 12, 2025
11 of 14 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.

2 participants