-
Notifications
You must be signed in to change notification settings - Fork 146
feat(l1): preload previous 256 block hashes when creating vm database #5443
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
Lines of code reportTotal lines added: Detailed view |
Benchmark Results ComparisonNo significant difference was registered for any benchmark run. Detailed ResultsBenchmark Results: BubbleSort
Benchmark Results: ERC20Approval
Benchmark Results: ERC20Mint
Benchmark Results: ERC20Transfer
Benchmark Results: Factorial
Benchmark Results: FactorialRecursive
Benchmark Results: Fibonacci
Benchmark Results: FibonacciRecursive
Benchmark Results: ManyHashes
Benchmark Results: MstoreBench
Benchmark Results: Push
Benchmark Results: SstoreBench_no_opt
|
| newest: BlockNumber, | ||
| oldest: BlockNumber, | ||
| ) -> Result<Vec<BlockHash>, StoreError> { | ||
| self.engine.get_canonical_block_hashes(newest, oldest) |
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.
This should be reading from memory most of the time. Only on startup it should need to go to the DB to populate its in-memory cache.
| let mut results = Vec::with_capacity(newest.saturating_sub(oldest) as usize); | ||
| for number in (oldest..newest).rev() { | ||
| match db.get_cf(&cf, number.to_le_bytes())? { | ||
| Some(res) => results.push(BlockHashRLP::from_bytes(res).to()?), | ||
| None => break, | ||
| } | ||
| } |
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.
This should fetch the whole range in batch:
| let mut results = Vec::with_capacity(newest.saturating_sub(oldest) as usize); | |
| for number in (oldest..newest).rev() { | |
| match db.get_cf(&cf, number.to_le_bytes())? { | |
| Some(res) => results.push(BlockHashRLP::from_bytes(res).to()?), | |
| None => break, | |
| } | |
| } | |
| let keys = (oldest..newest).map(BlockNumber::to_le_bytes()); | |
| let hashes = db.batched_multiget_cf(&cf, keys, true); | |
| hashes.into_iter().map(|h| h.ok().flatten().or_else(|| StoreError::Custom("missing value"))).collect() |
Motivation
Addressing #5344 by using the existing
block_hash_cacheto preload the previous 256 block hashes so we can skip block hash lookup during executionAlternative to #5434 as proposed by review comment #5434 (comment)
Description
Benchmark Results: worse results than #5434 for BlockHash EEST gas benchmark:
1080.92 Mgas/s PR #5434
802.74 Mgas/s This PR
32.18 Gas/s Main (7b4a0ba)