-
Notifications
You must be signed in to change notification settings - Fork 62
chore(l1): standarize revm/levm behaviour when importing blocks. #2452
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5aa796b
chore(l1): Standarize revm/levm behaviour when importing blocks.
mpaulucci 0078124
Remove import function from blockchain.
mpaulucci 24bcb3b
Merge branch 'main' of github.com:lambdaclass/lambda_ethereum_rust in…
mpaulucci dd6d650
Fix linting.
mpaulucci 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
This file contains hidden or 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ use std::{ | |
}; | ||
|
||
use clap::{ArgAction, Parser as ClapParser, Subcommand as ClapSubcommand}; | ||
use ethrex_blockchain::fork_choice::apply_fork_choice; | ||
use ethrex_p2p::{sync::SyncMode, types::Node}; | ||
use ethrex_vm::EvmEngine; | ||
use tracing::{info, warn, Level}; | ||
|
@@ -55,7 +56,7 @@ pub struct Options { | |
)] | ||
pub datadir: String, | ||
#[arg( | ||
long = "force", | ||
long = "force", | ||
help = "Force remove the database", | ||
long_help = "Delete the database without confirmation.", | ||
action = clap::ArgAction::SetTrue, | ||
|
@@ -298,7 +299,7 @@ pub async fn import_blocks(path: &str, data_dir: &str, network: &str, evm: EvmEn | |
|
||
let store = init_store(&data_dir, network).await; | ||
|
||
let blockchain = init_blockchain(evm, store); | ||
let blockchain = init_blockchain(evm, store.clone()); | ||
|
||
let path_metadata = metadata(path).expect("Failed to read path"); | ||
let blocks = if path_metadata.is_dir() { | ||
|
@@ -317,5 +318,32 @@ pub async fn import_blocks(path: &str, data_dir: &str, network: &str, evm: EvmEn | |
info!("Importing blocks from chain file: {path}"); | ||
utils::read_chain_file(path) | ||
}; | ||
blockchain.import_blocks(&blocks).await; | ||
|
||
let size = blocks.len(); | ||
|
||
for block in &blocks { | ||
let hash = block.hash(); | ||
|
||
info!( | ||
"Adding block {} with hash {:#x}.", | ||
block.header.number, hash | ||
); | ||
|
||
if let Err(error) = blockchain.add_block(block).await { | ||
warn!( | ||
"Failed to add block {} with hash {:#x}: {}.", | ||
block.header.number, hash, error | ||
); | ||
return; | ||
} | ||
} | ||
|
||
if let Some(last_block) = blocks.last() { | ||
let hash = last_block.hash(); | ||
if let Err(error) = apply_fork_choice(&store, hash, hash, hash).await { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. applying forkchoice should set all the blocks as canonical, you don't need to do it explicitly |
||
warn!("Failed to apply fork choice: {}", error); | ||
} | ||
} | ||
|
||
info!("Added {size} blocks to blockchain"); | ||
} |
This file contains hidden or 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
Oops, something went wrong.
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.
Why remove the method instead of refactoring 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.
I don't see the point of having such a function. It is ambiguous with
add_block
(s). What is the point of having a function that adds blocks + calls forkchoice instead of calling the two function separately?