-
Notifications
You must be signed in to change notification settings - Fork 110
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
Conversation
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.
ccc699e
to
a8dbe2e
Compare
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
a8dbe2e
to
150ea3d
Compare
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) => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Querying the mempool unfortunately takes multiple sequential steps:
first we call
getrawmempool
to retrieve a list of all entries and thenretrieve all of them via
getmempoolentry
.Previously, we would error out if a previously retrieved
Txid
wouldn'tbe 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.