-
Notifications
You must be signed in to change notification settings - Fork 97
feat(l2): commit blocks in batches #2397
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
Changes from 73 commits
e1b15dc
f7dac5a
0f5b31d
1ebf86d
da7cafe
6c29e0c
720b06c
9b17446
82c0e43
a142a0a
426babc
3af5fc3
bc48f76
290f14e
8881003
25ec922
fb0f735
7d31c24
cc8fe3d
a241b39
73b5774
aee4d98
68b17fc
dfb30cc
f074da6
360434f
c69be4d
6f4cd08
0beff71
e1a58e0
63562b9
4fe1208
5e70f3b
6b73ae5
e29a6ba
8308833
6ac802d
d73467b
f7eafa4
7d89cae
46b0b29
34199df
fb57d89
0626349
f0653cb
2d3b8ca
f3a8762
3b72e5c
321088c
cfd4e8a
4882284
305ec8b
6e7bd4c
5b95493
be137b9
78858e2
51b62dd
9075a0e
9520bf0
e9749e7
479c13f
07f6494
ea4f57d
283375b
b862498
0ea129f
ec500e6
79c3a98
9a17797
2dd185c
266bccf
cbdb030
5956d11
251b16d
efdf7a5
02b667e
73df73c
8e40117
f2ec6c4
fb9f8b3
b680cfb
b713d28
d72bd7c
83b8fa5
4f21f4c
ecad4ae
ef87b0f
c29368e
78c7b0b
697f939
98a4169
64064cd
69126ce
0f2104d
0aa19e6
f394811
1be6290
1fee017
c298043
0e45d8d
7fa2787
1eeb1eb
a6cbaaa
77a00eb
89d4a16
004e332
68e2a54
2543264
b755fd2
0529b51
133e9c5
459074a
445d28b
d63d1d5
37646a7
65bb86f
File filter
Filter by extension
Conversations
Jump to
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.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,6 +14,8 @@ use tracing::info; | |||||
|
||||||
#[cfg(any(feature = "l2", feature = "based"))] | ||||||
use ethrex::l2::L2Options; | ||||||
#[cfg(feature = "l2")] | ||||||
ilitteri marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
use ethrex_storage_l2::StoreL2; | ||||||
|
||||||
#[tokio::main] | ||||||
async fn main() -> eyre::Result<()> { | ||||||
|
@@ -55,6 +57,8 @@ async fn main() -> eyre::Result<()> { | |||||
blockchain.clone(), | ||||||
cancel_token.clone(), | ||||||
tracker.clone(), | ||||||
#[cfg(feature = "l2")] | ||||||
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.
Suggested change
|
||||||
StoreL2::default(), | ||||||
) | ||||||
.await; | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ use crate::l2::L2Options; | |
use ::{ | ||
ethrex_common::Address, | ||
ethrex_l2::utils::config::{read_env_file_by_config, ConfigMode}, | ||
ethrex_storage_l2::{EngineTypeL2, StoreL2}, | ||
secp256k1::SecretKey, | ||
}; | ||
|
||
|
@@ -94,6 +95,27 @@ pub async fn init_store(data_dir: &str, network: &str) -> Store { | |
store | ||
} | ||
|
||
#[cfg(feature = "l2")] | ||
pub async fn init_l2_store(data_dir: &str) -> StoreL2 { | ||
let path = PathBuf::from(data_dir); | ||
if path.ends_with("memory") { | ||
StoreL2::new(data_dir, EngineTypeL2::InMemory).expect("Failed to create StoreL2") | ||
} else { | ||
cfg_if::cfg_if! { | ||
if #[cfg(feature = "redb")] { | ||
let engine_type = EngineTypeL2::RedB; | ||
} else if #[cfg(feature = "libmdbx")] { | ||
let engine_type = EngineTypeL2::Libmdbx; | ||
} else { | ||
let engine_type = EngineTypeL2::InMemory; | ||
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. why do you specify in memory if you're going to panic in the next line? 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. That was a legacy from |
||
error!("No database specified. The feature flag `redb` or `libmdbx` should've been set while building."); | ||
panic!("Specify the desired database engine."); | ||
} | ||
} | ||
StoreL2::new(data_dir, engine_type).expect("Failed to create StoreL2") | ||
} | ||
} | ||
|
||
pub fn init_blockchain(evm_engine: EvmEngine, store: Store) -> Arc<Blockchain> { | ||
Blockchain::new(evm_engine, store).into() | ||
} | ||
|
@@ -109,6 +131,7 @@ pub async fn init_rpc_api( | |
blockchain: Arc<Blockchain>, | ||
cancel_token: CancellationToken, | ||
tracker: TaskTracker, | ||
#[cfg(feature = "l2")] l2_store: StoreL2, | ||
) { | ||
let enr_seq = std::time::SystemTime::now() | ||
.duration_since(std::time::UNIX_EPOCH) | ||
|
@@ -146,6 +169,8 @@ pub async fn init_rpc_api( | |
get_valid_delegation_addresses(l2_opts), | ||
#[cfg(feature = "l2")] | ||
get_sponsor_pk(l2_opts), | ||
#[cfg(feature = "l2")] | ||
l2_store, | ||
) | ||
.into_future(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
use crate::{ | ||
cli::{self as ethrex_cli, Options}, | ||
initializers::{ | ||
get_local_p2p_node, get_network, get_signer, init_blockchain, init_metrics, init_network, | ||
init_rpc_api, init_store, | ||
get_local_p2p_node, get_network, get_signer, init_blockchain, init_l2_store, init_metrics, | ||
init_network, init_rpc_api, init_store, | ||
}, | ||
utils::{self, set_datadir, store_known_peers}, | ||
DEFAULT_L2_DATADIR, | ||
|
@@ -121,12 +121,14 @@ impl Command { | |
match self { | ||
Command::Init { opts } => { | ||
let data_dir = set_datadir(&opts.node_opts.datadir); | ||
let l2_store_dir = data_dir.clone() + "/l2_store"; | ||
|
||
let network = get_network(&opts.node_opts); | ||
|
||
let store = init_store(&data_dir, &network).await; | ||
let l1_store = init_store(&data_dir, &network).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. I think this is not the L1 store. 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. Agree, I think I would keep the 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. Renamed to |
||
let l2_store = init_l2_store(&l2_store_dir).await; | ||
|
||
let blockchain = init_blockchain(opts.node_opts.evm, store.clone()); | ||
let blockchain = init_blockchain(opts.node_opts.evm, l1_store.clone()); | ||
|
||
let signer = get_signer(&data_dir); | ||
|
||
|
@@ -145,10 +147,11 @@ impl Command { | |
&signer, | ||
peer_table.clone(), | ||
local_p2p_node, | ||
store.clone(), | ||
l1_store.clone(), | ||
blockchain.clone(), | ||
cancel_token.clone(), | ||
tracker.clone(), | ||
l2_store.clone(), | ||
) | ||
.await; | ||
|
||
|
@@ -165,7 +168,7 @@ impl Command { | |
local_p2p_node, | ||
signer, | ||
peer_table.clone(), | ||
store.clone(), | ||
l1_store.clone(), | ||
tracker.clone(), | ||
blockchain.clone(), | ||
) | ||
|
@@ -174,7 +177,8 @@ impl Command { | |
info!("P2P is disabled"); | ||
} | ||
|
||
let l2_sequencer = ethrex_l2::start_l2(store, blockchain).into_future(); | ||
let l2_sequencer = | ||
ethrex_l2::start_l2(l1_store, l2_store, blockchain).into_future(); | ||
|
||
tracker.spawn(l2_sequencer); | ||
|
||
|
@@ -219,7 +223,7 @@ impl Command { | |
.checked_sub(U256::from(64)) | ||
.ok_or_eyre("Cannot get finalized block")?; | ||
|
||
let event_signature = keccak("BlockCommitted(bytes32)"); | ||
let event_signature = keccak("BatchCommitted(bytes32)"); | ||
|
||
loop { | ||
// Wait for a block | ||
|
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.
Wouldn't this import
ethrex-storage-l2
when thel2
feature is unset?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
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.
For this, I defined the
rollup_storage_libmdbx
androllup_storage_redb
feature flags in 0e45d8d. I'm not happy with this approach, but if you have a better idea, I'd be glad to change it.