-
Notifications
You must be signed in to change notification settings - Fork 111
refactor(l1): transform crate blockchain into struct #2047
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
|
|
||
// Attempt to add the block as the head of the chain | ||
let chain_result = add_block(block, &store); | ||
let chain_result = Blockchain::default().add_block(block, &store); |
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.
The idea is that the blockchain will be stateful,
let blockchain = Blockchain:new(evm, store, ... etc);
for block in blocks {
blockchain.add_block(block)
}
Otherwise a blockchain struct wouldn't make much sense
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.
Right! I haven't thought about that.
crates/blockchain/blockchain.rs
Outdated
|
||
Ok(()) | ||
impl Blockchain { | ||
pub fn new(evm: EVM) -> Self { |
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 we add store
?
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 be in a follow up.
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 will try to implement it and see if I can make it work, so that we don't need to send store
as parameter
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.
pub use execution_result::*; | ||
pub use revm::primitives::{Address as RevmAddress, SpecId, U256 as RevmU256}; | ||
|
||
use std::sync::OnceLock; |
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.
nice!
finalize_payload(&mut context)?; | ||
Ok((context.blobs_bundle, context.block_value)) | ||
} | ||
impl Blockchain { |
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 did we need to move this methods to Blockchain in the first iteration?
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 moved them to Blockchain
because these methods were using get_evm_backend_or_default()
and I wanted them to use the Blockchain EVM that we previously set.
crates/l2/utils/test_data_io.rs
Outdated
store.add_initial_state(genesis)?; | ||
for block in chain { | ||
add_block(&block, &store)?; | ||
Blockchain::default().add_block(&block, &store)?; |
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.
create blockchain above the adding of blocks.
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.
Although it has changed a little bit I fixed that here. The difference with the current code is that now we also have Store
inside of Blockchain
and we don't need to send it as parameter in some Blockchain methods.
let block: &CoreBlock = &block_fixture.block().unwrap().clone().into(); | ||
let hash = block.hash(); | ||
|
||
let blockchain = Blockchain::default(); |
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.
Once you move store
, you won't be able to use default
. Maybe the default should be on the evm.
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.
Yeah, I was thinking on using something like default_with_store(store)
so that we use the default VM and the provided store. Is there a better alternative to that?
crates/blockchain/blockchain.rs
Outdated
block.header.number, hash, error | ||
); | ||
} | ||
if store |
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.
Add a TODO comment stating that the forkchoice update should not be part of 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.
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.
🎉
L2 Integration Test will probably fail until #1705 is merged |
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.
LGTM, just a small comment for something that we might need to check later.
let add_block_result = { | ||
let lock = context.syncer.try_lock(); | ||
if let Ok(syncer) = lock { | ||
syncer.blockchain.add_block(block) | ||
} else { | ||
Err(ChainError::Custom( | ||
"Error when trying to lock syncer".to_string(), | ||
)) | ||
} | ||
}; |
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'm not sure if the new locks to the syncer might have some impact or if we want to maintain the state of the blockchain in it, but we can check this later if needed.
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 agree. I created an issue just for not forgetting about it.
#2063
Co-authored-by: Ivan Litteri <[email protected]>
**Motivation** <!-- Why does this pull request exist? What are its goals? --> **Description** <!-- A clear and concise general description of the changes this PR introduces --> - Move methods like `add_block` to `Blockchain` struct. - I use `Blockchain::default_with_store(store)` in the case of tests. Default VM is REVM. The Store that I use for tests is the `InMemory` Engine Type. - Blockchain has attributes: VM and Store Note: I don't know if I should test these changes in some other way rather than just running the tests that we have. <!-- Link to issues: Resolves #111, Resolves #222 --> Closes #2018 --------- Co-authored-by: Ivan Litteri <[email protected]>
**Motivation** <!-- Why does this pull request exist? What are its goals? --> **Description** <!-- A clear and concise general description of the changes this PR introduces --> - Move methods like `add_block` to `Blockchain` struct. - I use `Blockchain::default_with_store(store)` in the case of tests. Default VM is REVM. The Store that I use for tests is the `InMemory` Engine Type. - Blockchain has attributes: VM and Store Note: I don't know if I should test these changes in some other way rather than just running the tests that we have. <!-- Link to issues: Resolves #111, Resolves #222 --> Closes #2018 --------- Co-authored-by: Ivan Litteri <[email protected]>
**Motivation** <!-- Why does this pull request exist? What are its goals? --> **Description** <!-- A clear and concise general description of the changes this PR introduces --> - Move methods like `add_block` to `Blockchain` struct. - I use `Blockchain::default_with_store(store)` in the case of tests. Default VM is REVM. The Store that I use for tests is the `InMemory` Engine Type. - Blockchain has attributes: VM and Store Note: I don't know if I should test these changes in some other way rather than just running the tests that we have. <!-- Link to issues: Resolves #111, Resolves #222 --> Closes #2018 --------- Co-authored-by: Ivan Litteri <[email protected]>
**Motivation** <!-- Why does this pull request exist? What are its goals? --> **Description** <!-- A clear and concise general description of the changes this PR introduces --> - Move methods like `add_block` to `Blockchain` struct. - I use `Blockchain::default_with_store(store)` in the case of tests. Default VM is REVM. The Store that I use for tests is the `InMemory` Engine Type. - Blockchain has attributes: VM and Store Note: I don't know if I should test these changes in some other way rather than just running the tests that we have. <!-- Link to issues: Resolves lambdaclass#111, Resolves lambdaclass#222 --> Closes lambdaclass#2018 --------- Co-authored-by: Ivan Litteri <[email protected]>
Motivation
Description
add_block
toBlockchain
struct.Blockchain::default_with_store(store)
in the case of tests. Default VM is REVM. The Store that I use for tests is theInMemory
Engine Type.Note: I don't know if I should test these changes in some other way rather than just running the tests that we have.
Closes #2018