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

Sparse trie #174

Merged
merged 1 commit into from
Sep 24, 2024
Merged

Sparse trie #174

merged 1 commit into from
Sep 24, 2024

Conversation

dvush
Copy link
Contributor

@dvush dvush commented Sep 10, 2024

Faster root hash

This pr introduces option to use sparse merkle trie implementation for the root hash calculation.

This implementation fetches relevant pieces of the trie into memory making subsequent root hash calculations faster.

On my PC reference implementation takes about 150ms to calculate hash and the new one when everything is prefetched around 5ms.

Fetching proof for data for one uncached account takes about 0.25ms.

There are things to improve in implementation itself but the basic interface for the integration into the builder will be the same.

debug-bench-machine

This PR also redoes debug-bench-machine. Now you need to stop reth node and provide external rpc for it to work.

The reason is that reth has trie only for the last block. Previous implementation used last block to generate changes and it applied that changes to the trie after the last block. Trie would already have these changes but default reth root hash does not care about that discrepancy and it would evaluate anyway, this was used as a hack to benchmark trie even though it would give incorrect results.

Sparse trie implemenation would not work like that because it would detect errors such as removing key that was already removed from the trie.

The benefit of this is that we can actually check correctness of the root hash on historical block.


✅ I have completed the following steps:

  • Run make lint
  • Run make test
  • Added tests (if applicable)

@ZanCorDX
Copy link
Contributor

It would be nice to have some struct to make the roothash to avoid passing so many parameters all over.
Ideally, we could have a trait and instantiate the proper version depending on the configuration so we only create what is really needed (SkipRootHash could be the dummy roothasher).

Copy link
Contributor

@ZanCorDX ZanCorDX left a comment

Choose a reason for hiding this comment

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

Shouldn't the code of

eth-sparse-mpt = { git = "https://github.com/dvush/eth-sparse-mpt", rev = "a89e02e" } 

be inside rbuilder?

Base automatically changed from reth_1_0_6 to develop September 12, 2024 10:46
@dvush dvush requested a review from ZanCorDX September 24, 2024 16:06
Copy link

github-actions bot commented Sep 24, 2024

Benchmark results for f23c142

Report: https://flashbots-rbuilder-ci-stats.s3.us-east-2.amazonaws.com/benchmark/f23c142-900aa72/report/index.html

Date (UTC) 2024-09-24T16:49:46+00:00
Commit f23c14285330cca76b0d388a5bd3bce450021895
Base SHA 900aa724583e7331d3a64004b6b9f93007f039e7

Significant changes

None

@dvush dvush merged commit 0ac5cf1 into develop Sep 24, 2024
5 checks passed
@dvush dvush deleted the sparse_mpt_rebbo branch September 24, 2024 17:38
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