-
Notifications
You must be signed in to change notification settings - Fork 41
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
feat: fallback preimage recovery w/o debug_dbGet #30
Merged
xJonathanLEI
merged 2 commits into
succinctlabs:main
from
xJonathanLEI:dev/dbget_fallback
Aug 27, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
use reth_primitives::{Bytes, B256}; | ||
use reth_primitives::{Address, Bytes, B256}; | ||
use reth_trie::Nibbles; | ||
|
||
/// Custom database access methods implemented by RSP storage backends. | ||
pub trait ExtDatabaseRef { | ||
/// The database error type. | ||
type Error; | ||
|
||
/// Gets the preimage of a trie node given its Keccak hash. | ||
fn trie_node_ref(&self, hash: B256) -> Result<Bytes, Self::Error>; | ||
fn trie_node_ref(&self, hash: B256, context: PreimageContext) -> Result<Bytes, Self::Error>; | ||
} | ||
|
||
/// Additional context for retrieving trie node preimages. These are useful when the JSON-RPC node | ||
/// does not serve the `debug_dbGet`. | ||
pub struct PreimageContext<'a> { | ||
/// The account address if calculating a storage trie root; `None` if calculating the state | ||
/// root. | ||
pub address: &'a Option<Address>, | ||
/// The trie key path of the branch child containing the hash whose preimage is being fetched. | ||
pub branch_path: &'a Nibbles, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does passing this around affect the number of cycles in the client program? I feel like since client program cycles are super critical, we should make sure it doesn't
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.
I was thinking about the same thing but thought it shouldn't matter since it's just passing 2 references. But I can do a quick benchmark on a before/after for this. Will update here. Do note that since the code is not yet deterministic it might not be 100% accurate.
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.
Hmmm to my surprise the cycle count change turns out to be not really negligible. I was expected it to be buried in the noise of the non-determinism. Turns out for the block tested
20600000
(avg out of 10 runs each):762,727,324
cycles765,003,639
cyclesWe got some 0.5% increase from this. This is quite surprising as this is really just passing 2 references, and I was half expecting the compiler to optimize it away since it's unused.
0.5% isn't huge but for something that can be avoided altogether it's not ideal. Will do a bit refactor here to add a feature that makes this host-only. Was hoping that it would be negligible so we don't have to over-engineer it.
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.
@puma314 Just pushed a new commit that uses Rust feature to make sure none of the changes affect client other than adding a unit type parameter (which I'm kina sure gets optimized away since it's zero-sized).
Ran the test against the same block and I'm now getting
762,685,729
which is actually even lower than before this change, though I'm pretty sure this comes from the noise of non-determinism.In any case, we're now no longer sacrificing client efficiency for this feature.