-
Notifications
You must be signed in to change notification settings - Fork 43
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(l1): process blocks in batches when syncing #2174
base: main
Are you sure you want to change the base?
Conversation
Lines of code reportTotal lines added: Detailed view
|
@@ -110,6 +110,63 @@ impl Blockchain { | |||
Ok(()) | |||
} | |||
|
|||
pub fn add_blocks_in_batch( |
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.
Can't we change the implementation of add_block
to just call this function?
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.
Yes, I planned to refactor it after having some benches.
@@ -110,6 +110,63 @@ impl Blockchain { | |||
Ok(()) | |||
} | |||
|
|||
pub fn add_blocks_in_batch( | |||
&self, | |||
parent_hash: BlockHash, |
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.
why do you need to explicitly pass parent_hash
? Couldn't you just get it from blocks[0].parent_hash
?
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.
Yes you are right, it was a param inherited from add_block
.
crates/blockchain/blockchain.rs
Outdated
for (i, block) in blocks.iter().enumerate() { | ||
let block_hash = block.header.compute_block_hash(); | ||
// Validate if it can be the new head and find the parent | ||
let Ok(parent_header) = find_parent_header(&block.header, &self.storage) else { |
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.
wait, shouldn't it be a precondition of the function that block n + 1 has block n as parent?
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.
Sure we could add that pre-condition to return earlier. Thou, I don't know if its actually really necessary as in the next iteration you are going to verify that block n-1
is indeed the parent of n
.
crates/blockchain/blockchain.rs
Outdated
return Err(ChainError::ParentNotFound); | ||
}; | ||
|
||
let chain_config: ChainConfig = self.storage.get_chain_config()?; |
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 is inmutable so it could be passed to Blockchain
on new
, or called in the constructor.
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.
You are right, we would avoid a db read as well.
// todo only execute transactions | ||
// batch account updates to merge the repeated accounts | ||
self.storage | ||
.apply_account_updates_to_trie(&account_updates, &mut state_trie)?; |
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.
Ahh, I understand now. I was hoping we could just call: https://github.com/lambdaclass/lambda_ethereum_rust/blob/0acc5e28b861f88c30cebb6cbfe0230970df25ed/crates/vm/backends/revm.rs#L96 get_state_transitions
only once.
We would need to add a execute_blocks
inside vm.
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.
we can discuss this 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.
I've tried this approach but it won't work without making larger modifications to the vm backend.
we were missing to set the cannonical block hash for the number
Motivation
Accelerate syncing!
Description
This PR introduces block batching during full sync:
n
blocks instead of one per block (we'll need less storage also).Considerations:
levm
backend we need it to cache the executions state and persist it between them, as we don't store anything until the final of the batch.Closes None