Skip to content
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

SynchMempoolTask: Add parallel UTXO precacher for perf. benefit of up to ~30% + BugFix #207

Merged
merged 14 commits into from
Nov 5, 2023

Conversation

cculianu
Copy link
Owner

@cculianu cculianu commented Nov 5, 2023

We add a parallel UTXO precache mechanism to the SynchMempoolTask. This mechanism looks UTXOs up in the utxodb as we are busy downloading mempool txns from bitcoind. The benefit is not large for small mempools but on e.g. BTC with ~140k txns in the mempool, the performance benefit is up to ~33% over existing code. This is because we utilize the disk and CPU concurrently with the network while downloading large mempools.


Also in this PR:

  • Refactor of the SynchMempoolTask into its own compilation unit and header.
  • BUGFIX! -- A corner case on BTC could occur where a "failed" txn during mempool synch would be downloaded after its children. If the parent and children were evicted during download, but we managed to grab the children before the eviction, but the parent after (as can happen with RBF for example), inconsistent behavior from the server could be observed.
    • In such cases the SynchMempoolTask would attempt to add the child txns to the mempool but the parent would be missing, thus inputs would be missing, and this would lead to an exception being thrown and the mempool being left in a state where not all its data structures for the new txns would be filled-in, leading to observed behavior of scripthash notifications for the txns in question not being sent to clients.
    • This very rare corner-case bug has been fixed.

This should work well enough, and should improve performance.
Hopefully this makes SynchMempool on pathological mempools faster.
This reverts commit f46bd75.

It was no faster to use threads, and if anything, it ate up resources.
We download out-of-order so it's possible to dl a child txn while the
parent txn drops out, and then we fail to find the coin for the parent.

This caused very rare scripthash notification bugs on BTC and has now been
fixed.
@cculianu cculianu added bug Something isn't working performance Improvements to performance labels Nov 5, 2023
@cculianu cculianu merged commit 31fbfbf into master Nov 5, 2023
@cculianu cculianu deleted the syncmempool_parallel_precache branch November 5, 2023 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working performance Improvements to performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant