From 5e2729cdc1bc273cbe2b64e1867df543a1bc0449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keszey=20D=C3=A1niel?= Date: Fri, 18 Oct 2024 15:15:49 +0200 Subject: [PATCH 1/8] first trial --- bin/reth/src/main.rs | 67 ++++++++++++++++++++------------ crates/gwyneth/src/engine_api.rs | 31 +++++++++++---- crates/gwyneth/src/exex.rs | 60 +++++++++++++++++----------- 3 files changed, 104 insertions(+), 54 deletions(-) diff --git a/bin/reth/src/main.rs b/bin/reth/src/main.rs index 6d475e993067..141e90a97a47 100644 --- a/bin/reth/src/main.rs +++ b/bin/reth/src/main.rs @@ -1,5 +1,4 @@ #![allow(missing_docs)] - // We use jemalloc for performance reasons. #[cfg(all(feature = "jemalloc", unix))] #[global_allocator] @@ -12,6 +11,9 @@ use reth_node_builder::{NodeBuilder, NodeConfig, NodeHandle}; use reth_node_ethereum::EthereumNode; use reth_tasks::TaskManager; +// Define a list of suffixes for chain IDs and RPC ports +const SUFFIXES: [char; 2] = ['A', 'B'/* , 'C'*/]; // Add more suffixes as needed, like C + fn main() -> eyre::Result<()> { reth::cli::Cli::parse_args().run(|builder, _| async move { let tasks = TaskManager::current(); @@ -22,34 +24,51 @@ fn main() -> eyre::Result<()> { ..NetworkArgs::default() }; - let chain_spec = ChainSpecBuilder::default() - .chain(gwyneth::exex::CHAIN_ID.into()) - .genesis( - serde_json::from_str(include_str!( - "../../../crates/ethereum/node/tests/assets/genesis.json" - )) - .unwrap(), - ) - .cancun_activated() - .build(); + let mut gwyneth_nodes = Vec::new(); + + for suffix in SUFFIXES.iter() { + let chain_id = match suffix { + 'A' => gwyneth::exex::CHAIN_ID_A, + 'B' => gwyneth::exex::CHAIN_ID_B, + // 'C' => gwyneth::exex::CHAIN_ID_C, // Add this constant in your exex.rs + _ => panic!("Unsupported chain ID suffix"), + }; - let node_config = NodeConfig::test() - .with_chain(chain_spec.clone()) - .with_network(network_config.clone()) - .with_unused_ports() - .with_rpc(RpcServerArgs::default().with_unused_ports().with_static_l2_rpc_ip_and_port(chain_spec.chain.id())); + let chain_spec = ChainSpecBuilder::default() + .chain(chain_id.into()) + .genesis( + serde_json::from_str(include_str!( + "../../../crates/ethereum/node/tests/assets/genesis.json" + )) + .unwrap(), + ) + .cancun_activated() + .build(); - let NodeHandle { node: gwyneth_node, node_exit_future: _ } = - NodeBuilder::new(node_config.clone()) - .gwyneth_node(exec.clone(), chain_spec.chain.id()) - .node(GwynethNode::default()) - .launch() - .await?; + let node_config = NodeConfig::test() + .with_chain(chain_spec.clone()) + .with_network(network_config.clone()) + .with_unused_ports() + .with_rpc( + RpcServerArgs::default() + .with_unused_ports() + .with_static_l2_rpc_ip_and_port(chain_spec.chain.id(), *suffix) + ); + + let NodeHandle { node: gwyneth_node, node_exit_future: _ } = + NodeBuilder::new(node_config.clone()) + .gwyneth_node(exec.clone(), chain_spec.chain.id()) + .node(GwynethNode::default()) + .launch() + .await?; + + gwyneth_nodes.push(gwyneth_node); + } let handle = builder .node(EthereumNode::default()) .install_exex("Rollup", move |ctx| async { - Ok(gwyneth::exex::Rollup::new(ctx, gwyneth_node).await?.start()) + Ok(gwyneth::exex::Rollup::new(ctx, gwyneth_nodes).await?.start()) }) .launch() .await?; @@ -69,4 +88,4 @@ mod tests { #[command(flatten)] args: T, } -} +} \ No newline at end of file diff --git a/crates/gwyneth/src/engine_api.rs b/crates/gwyneth/src/engine_api.rs index 16e8287a82e1..3d585f79718e 100644 --- a/crates/gwyneth/src/engine_api.rs +++ b/crates/gwyneth/src/engine_api.rs @@ -113,18 +113,35 @@ impl PayloadEnvelopeExt for ExecutionPayloadEnvelopeV3 { } } pub trait RpcServerArgsExEx { - fn with_static_l2_rpc_ip_and_port(self, chain_id: u64) -> Self; + fn with_static_l2_rpc_ip_and_port(self, chain_id: u64, suffix: char) -> Self; } impl RpcServerArgsExEx for RpcServerArgs { - fn with_static_l2_rpc_ip_and_port(mut self, chain_id: u64) -> Self { + fn with_static_l2_rpc_ip_and_port(mut self, chain_id: u64, suffix: char) -> Self { self.http = true; - // On the instance the program is running, we wanna have 10111 exposed as the (exex) L2's - // RPC port. self.http_addr = Ipv4Addr::new(0, 0, 0, 0).into(); - self.http_port = 10110u16; - self.ws_port = 10111u16; - self.ipcpath = format!("{}-{}", constants::DEFAULT_IPC_ENDPOINT, chain_id); + + // Set HTTP and WS ports based on suffix + match suffix { + 'A' => { + self.http_port = 10110u16; + self.ws_port = 10111u16; + }, + 'B' => { + self.http_port = 20110u16; + self.ws_port = 20111u16; + }, + 'C' => { + self.http_port = 30110u16; + self.ws_port = 30111u16; + }, + // Obviously add more if needed more chain + _ => panic!("Unsupported suffix: {}", suffix), + } + + // Set IPC path + self.ipcpath = format!("{}-{}-{}", constants::DEFAULT_IPC_ENDPOINT, chain_id, suffix); + self } } diff --git a/crates/gwyneth/src/exex.rs b/crates/gwyneth/src/exex.rs index 144f5cc8f25b..9160b307bf6a 100644 --- a/crates/gwyneth/src/exex.rs +++ b/crates/gwyneth/src/exex.rs @@ -31,7 +31,8 @@ use reth_transaction_pool::{ use RollupContract::{BlockProposed, RollupContractEvents}; const ROLLUP_CONTRACT_ADDRESS: Address = address!("9fCF7D13d10dEdF17d0f24C62f0cf4ED462f65b7"); -pub const CHAIN_ID: u64 = 167010; +pub const CHAIN_ID_A: u64 = 167010; +pub const CHAIN_ID_B: u64 = 267010; const INITIAL_TIMESTAMP: u64 = 1710338135; pub type GwynethFullNode = FullNode< @@ -69,18 +70,22 @@ sol!(RollupContract, "TaikoL1.json"); pub struct Rollup { ctx: ExExContext, - node: GwynethFullNode, - engine_api: EngineApiContext, + nodes: Vec, + engine_apis: Vec>, } impl Rollup { - pub async fn new(ctx: ExExContext, node: GwynethFullNode) -> eyre::Result { - let engine_api = EngineApiContext { - engine_api_client: node.auth_server_handle().http_client(), - canonical_stream: node.provider.canonical_state_stream(), - _marker: PhantomData::, - }; - Ok(Self { ctx, node, /* payload_event_stream, */ engine_api }) + pub async fn new(ctx: ExExContext, nodes: Vec) -> eyre::Result { + let mut engine_apis = Vec::new(); + for node in &nodes { + let engine_api = EngineApiContext { + engine_api_client: node.auth_server_handle().http_client(), + canonical_stream: node.provider.canonical_state_stream(), + _marker: PhantomData::, + }; + engine_apis.push(engine_api); + } + Ok(Self { ctx, nodes, /* payload_event_stream, */ engine_apis }) } pub async fn start(mut self) -> eyre::Result<()> { @@ -91,7 +96,13 @@ impl Rollup { } if let Some(committed_chain) = notification.committed_chain() { - self.commit(&committed_chain).await?; + let nodes = &self.nodes; + let engine_apis = &self.engine_apis; + for i in 0..nodes.len() { + let node = &nodes[i]; + let engine_api = &engine_apis[i]; + self.commit(&committed_chain, node, engine_api).await?; + } self.ctx.events.send(ExExEvent::FinishedHeight(committed_chain.tip().number))?; } } @@ -103,13 +114,14 @@ impl Rollup { /// /// This function decodes all transactions to the rollup contract into events, executes the /// corresponding actions and inserts the results into the database. - pub async fn commit(&mut self, chain: &Chain) -> eyre::Result<()> { + pub async fn commit( + &mut self, + chain: &Chain, + node: &GwynethFullNode, + engine_api: &EngineApiContext, + ) -> eyre::Result<()> { let events = decode_chain_into_rollup_events(chain); for (block, _, event) in events { - // TODO: Don't emit ProposeBlock event but directely - // read the function call RollupContractCalls to extract Txs - // let _call = RollupContractCalls::abi_decode(tx.input(), true)?; - if let RollupContractEvents::BlockProposed(BlockProposed { blockId: block_number, meta, @@ -148,15 +160,16 @@ impl Rollup { let payload_id = builder_attrs.inner.payload_id(); let parrent_beacon_block_root = builder_attrs.inner.parent_beacon_block_root.unwrap(); + // trigger new payload building draining the pool - self.node.payload_builder.new_payload(builder_attrs).await.unwrap(); + node.payload_builder.new_payload(builder_attrs).await.unwrap(); + // wait for the payload builder to have finished building let mut payload = EthBuiltPayload::new(payload_id, SealedBlock::default(), U256::ZERO); loop { - let result = self.node.payload_builder.best_payload(payload_id).await; + let result = node.payload_builder.best_payload(payload_id).await; - // TODO: There seems to be no result when there's an empty tx list if let Some(result) = result { if let Ok(new_payload) = result { payload = new_payload; @@ -174,11 +187,12 @@ impl Rollup { } break; } + // trigger resolve payload via engine api - self.engine_api.get_payload_v3_value(payload_id).await?; + engine_api.get_payload_v3_value(payload_id).await?; + // submit payload to engine api - let block_hash = self - .engine_api + let block_hash = engine_api .submit_payload( payload.clone(), parrent_beacon_block_root, @@ -188,7 +202,7 @@ impl Rollup { .await?; // trigger forkchoice update via engine api to commit the block to the blockchain - self.engine_api.update_forkchoice(block_hash, block_hash).await?; + engine_api.update_forkchoice(block_hash, block_hash).await?; } } From ca53bd32b1ed04d26cd09c3471380ba15244dc12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keszey=20D=C3=A1niel?= Date: Fri, 18 Oct 2024 21:45:46 +0200 Subject: [PATCH 2/8] some req changes --- bin/reth/src/main.rs | 16 +++++----------- crates/gwyneth/src/engine_api.rs | 27 +++++++-------------------- crates/gwyneth/src/exex.rs | 26 +++++++------------------- 3 files changed, 19 insertions(+), 50 deletions(-) diff --git a/bin/reth/src/main.rs b/bin/reth/src/main.rs index 141e90a97a47..5656019e0536 100644 --- a/bin/reth/src/main.rs +++ b/bin/reth/src/main.rs @@ -11,14 +11,13 @@ use reth_node_builder::{NodeBuilder, NodeConfig, NodeHandle}; use reth_node_ethereum::EthereumNode; use reth_tasks::TaskManager; -// Define a list of suffixes for chain IDs and RPC ports -const SUFFIXES: [char; 2] = ['A', 'B'/* , 'C'*/]; // Add more suffixes as needed, like C +const BASE_CHAIN_ID: u64 = gwyneth::exex::BASE_CHAIN_ID; // Base chain ID for L2s +const NUM_L2_CHAINS: u64 = 2; // Number of L2 chains to create fn main() -> eyre::Result<()> { reth::cli::Cli::parse_args().run(|builder, _| async move { let tasks = TaskManager::current(); let exec = tasks.executor(); - let network_config = NetworkArgs { discovery: DiscoveryArgs { disable_discovery: true, ..DiscoveryArgs::default() }, ..NetworkArgs::default() @@ -26,13 +25,8 @@ fn main() -> eyre::Result<()> { let mut gwyneth_nodes = Vec::new(); - for suffix in SUFFIXES.iter() { - let chain_id = match suffix { - 'A' => gwyneth::exex::CHAIN_ID_A, - 'B' => gwyneth::exex::CHAIN_ID_B, - // 'C' => gwyneth::exex::CHAIN_ID_C, // Add this constant in your exex.rs - _ => panic!("Unsupported chain ID suffix"), - }; + for i in 0..NUM_L2_CHAINS { + let chain_id = BASE_CHAIN_ID + (i * 100000); // Increment by 100000 for each L2 let chain_spec = ChainSpecBuilder::default() .chain(chain_id.into()) @@ -52,7 +46,7 @@ fn main() -> eyre::Result<()> { .with_rpc( RpcServerArgs::default() .with_unused_ports() - .with_static_l2_rpc_ip_and_port(chain_spec.chain.id(), *suffix) + .with_static_l2_rpc_ip_and_port(chain_id) ); let NodeHandle { node: gwyneth_node, node_exit_future: _ } = diff --git a/crates/gwyneth/src/engine_api.rs b/crates/gwyneth/src/engine_api.rs index 3d585f79718e..4e63207e3266 100644 --- a/crates/gwyneth/src/engine_api.rs +++ b/crates/gwyneth/src/engine_api.rs @@ -113,34 +113,21 @@ impl PayloadEnvelopeExt for ExecutionPayloadEnvelopeV3 { } } pub trait RpcServerArgsExEx { - fn with_static_l2_rpc_ip_and_port(self, chain_id: u64, suffix: char) -> Self; + fn with_static_l2_rpc_ip_and_port(self, chain_id: u64) -> Self; } impl RpcServerArgsExEx for RpcServerArgs { - fn with_static_l2_rpc_ip_and_port(mut self, chain_id: u64, suffix: char) -> Self { + fn with_static_l2_rpc_ip_and_port(mut self, chain_id: u64) -> Self { self.http = true; self.http_addr = Ipv4Addr::new(0, 0, 0, 0).into(); - // Set HTTP and WS ports based on suffix - match suffix { - 'A' => { - self.http_port = 10110u16; - self.ws_port = 10111u16; - }, - 'B' => { - self.http_port = 20110u16; - self.ws_port = 20111u16; - }, - 'C' => { - self.http_port = 30110u16; - self.ws_port = 30111u16; - }, - // Obviously add more if needed more chain - _ => panic!("Unsupported suffix: {}", suffix), - } + // Calculate HTTP and WS ports based on chain_id + let port_offset = ((chain_id - 167010) / 100000) as u16; + self.http_port = 10110 + (port_offset * 10000); + self.ws_port = 10111 + (port_offset * 10000); // Set IPC path - self.ipcpath = format!("{}-{}-{}", constants::DEFAULT_IPC_ENDPOINT, chain_id, suffix); + self.ipcpath = format!("{}-{}", constants::DEFAULT_IPC_ENDPOINT, chain_id); self } diff --git a/crates/gwyneth/src/exex.rs b/crates/gwyneth/src/exex.rs index 9160b307bf6a..cff105d27b99 100644 --- a/crates/gwyneth/src/exex.rs +++ b/crates/gwyneth/src/exex.rs @@ -31,8 +31,7 @@ use reth_transaction_pool::{ use RollupContract::{BlockProposed, RollupContractEvents}; const ROLLUP_CONTRACT_ADDRESS: Address = address!("9fCF7D13d10dEdF17d0f24C62f0cf4ED462f65b7"); -pub const CHAIN_ID_A: u64 = 167010; -pub const CHAIN_ID_B: u64 = 267010; +pub const BASE_CHAIN_ID: u64 = 167010; const INITIAL_TIMESTAMP: u64 = 1710338135; pub type GwynethFullNode = FullNode< @@ -89,19 +88,14 @@ impl Rollup { } pub async fn start(mut self) -> eyre::Result<()> { - // Process all new chain state notifications while let Some(notification) = self.ctx.notifications.recv().await { if let Some(reverted_chain) = notification.reverted_chain() { self.revert(&reverted_chain)?; } if let Some(committed_chain) = notification.committed_chain() { - let nodes = &self.nodes; - let engine_apis = &self.engine_apis; - for i in 0..nodes.len() { - let node = &nodes[i]; - let engine_api = &engine_apis[i]; - self.commit(&committed_chain, node, engine_api).await?; + for i in 0..self.nodes.len() { + self.commit(&committed_chain, i).await?; } self.ctx.events.send(ExExEvent::FinishedHeight(committed_chain.tip().number))?; } @@ -110,16 +104,10 @@ impl Rollup { Ok(()) } - /// Process a new chain commit. - /// - /// This function decodes all transactions to the rollup contract into events, executes the - /// corresponding actions and inserts the results into the database. - pub async fn commit( - &mut self, - chain: &Chain, - node: &GwynethFullNode, - engine_api: &EngineApiContext, - ) -> eyre::Result<()> { + pub async fn commit(&mut self, chain: &Chain, node_idx: usize) -> eyre::Result<()> { + let node = &self.nodes[node_idx]; + let engine_api = &self.engine_apis[node_idx]; + let events = decode_chain_into_rollup_events(chain); for (block, _, event) in events { if let RollupContractEvents::BlockProposed(BlockProposed { From d7f4eced5192fc699a837a511ac491c0bdabfce0 Mon Sep 17 00:00:00 2001 From: Brecht Devos Date: Tue, 22 Oct 2024 00:17:29 +0200 Subject: [PATCH 3/8] fix compile error --- crates/gwyneth/src/exex.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/crates/gwyneth/src/exex.rs b/crates/gwyneth/src/exex.rs index cff105d27b99..7d7d8dc177cc 100644 --- a/crates/gwyneth/src/exex.rs +++ b/crates/gwyneth/src/exex.rs @@ -105,9 +105,6 @@ impl Rollup { } pub async fn commit(&mut self, chain: &Chain, node_idx: usize) -> eyre::Result<()> { - let node = &self.nodes[node_idx]; - let engine_api = &self.engine_apis[node_idx]; - let events = decode_chain_into_rollup_events(chain); for (block, _, event) in events { if let RollupContractEvents::BlockProposed(BlockProposed { @@ -148,15 +145,15 @@ impl Rollup { let payload_id = builder_attrs.inner.payload_id(); let parrent_beacon_block_root = builder_attrs.inner.parent_beacon_block_root.unwrap(); - + // trigger new payload building draining the pool - node.payload_builder.new_payload(builder_attrs).await.unwrap(); - + self.nodes[node_idx].payload_builder.new_payload(builder_attrs).await.unwrap(); + // wait for the payload builder to have finished building let mut payload = EthBuiltPayload::new(payload_id, SealedBlock::default(), U256::ZERO); loop { - let result = node.payload_builder.best_payload(payload_id).await; + let result = self.nodes[node_idx].payload_builder.best_payload(payload_id).await; if let Some(result) = result { if let Ok(new_payload) = result { @@ -175,12 +172,12 @@ impl Rollup { } break; } - + // trigger resolve payload via engine api - engine_api.get_payload_v3_value(payload_id).await?; - + self.engine_apis[node_idx].get_payload_v3_value(payload_id).await?; + // submit payload to engine api - let block_hash = engine_api + let block_hash = self.engine_apis[node_idx] .submit_payload( payload.clone(), parrent_beacon_block_root, @@ -190,7 +187,7 @@ impl Rollup { .await?; // trigger forkchoice update via engine api to commit the block to the blockchain - engine_api.update_forkchoice(block_hash, block_hash).await?; + self.engine_apis[node_idx].update_forkchoice(block_hash, block_hash).await?; } } From 34e62a33eb754bfd15eb13fac5e46768076b6485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keszey=20D=C3=A1niel?= Date: Tue, 22 Oct 2024 15:09:36 +0200 Subject: [PATCH 4/8] necessary deployemnts for multiple rollups --- packages/protocol/scripts/confs/network_params.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/protocol/scripts/confs/network_params.yaml b/packages/protocol/scripts/confs/network_params.yaml index 9a8eec16992a..e97f16aa52fc 100644 --- a/packages/protocol/scripts/confs/network_params.yaml +++ b/packages/protocol/scripts/confs/network_params.yaml @@ -3,6 +3,7 @@ participants: el_image: taiko_reth cl_type: lighthouse cl_image: sigp/lighthouse:latest + el_extra_params: ["--num_of_l2s", "2"] cl_extra_params: [--always-prepare-payload, --prepare-payload-lookahead, "12000"] - el_type: reth el_image: taiko_reth @@ -12,7 +13,7 @@ network_params: network_id: '160010' additional_services: - blockscout - - blockscout_l2_1 + - blockscout_l2_2 port_publisher: nat_exit_ip: KURTOSIS_IP_ADDR_PLACEHOLDER el: From da36de612cbd877e72e258490f17fe4ca0e44e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keszey=20D=C3=A1niel?= Date: Tue, 22 Oct 2024 16:02:55 +0200 Subject: [PATCH 5/8] filter for propoer chainId --- crates/gwyneth/src/exex.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/gwyneth/src/exex.rs b/crates/gwyneth/src/exex.rs index 7d7d8dc177cc..f11dd2ff3ec7 100644 --- a/crates/gwyneth/src/exex.rs +++ b/crates/gwyneth/src/exex.rs @@ -117,6 +117,14 @@ impl Rollup { let transactions: Vec = decode_transactions(&meta.txList); println!("transactions: {:?}", transactions); + let all_transactions: Vec = decode_transactions(&meta.txList); + let node_chain_id = BASE_CHAIN_ID + node_idx as u64; + + let filtered_transactions: Vec = all_transactions + .into_iter() + .filter(|tx| tx.chain_id() == Some(node_chain_id)) + .collect(); + let attrs = GwynethPayloadAttributes { inner: EthPayloadAttributes { timestamp: block.timestamp, @@ -125,7 +133,7 @@ impl Rollup { withdrawals: Some(vec![]), parent_beacon_block_root: Some(B256::ZERO), }, - transactions: Some(transactions.clone()), + transactions: Some(filtered_transactions.clone()), gas_limit: None, }; From e31c08a076b00d11082871614f5d33fb87588b46 Mon Sep 17 00:00:00 2001 From: Brecht Devos Date: Thu, 24 Oct 2024 02:37:39 +0200 Subject: [PATCH 6/8] fix transactions on different chains --- crates/gwyneth/src/exex.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/gwyneth/src/exex.rs b/crates/gwyneth/src/exex.rs index f11dd2ff3ec7..d3e6df503aba 100644 --- a/crates/gwyneth/src/exex.rs +++ b/crates/gwyneth/src/exex.rs @@ -118,13 +118,18 @@ impl Rollup { println!("transactions: {:?}", transactions); let all_transactions: Vec = decode_transactions(&meta.txList); - let node_chain_id = BASE_CHAIN_ID + node_idx as u64; - + let node_chain_id = BASE_CHAIN_ID + (node_idx as u64) * 100000; + let filtered_transactions: Vec = all_transactions .into_iter() .filter(|tx| tx.chain_id() == Some(node_chain_id)) .collect(); + if filtered_transactions.len() == 0 { + println!("no transactions for chain: {}", node_chain_id); + continue; + } + let attrs = GwynethPayloadAttributes { inner: EthPayloadAttributes { timestamp: block.timestamp, From 5f6d3a6ffcf0ea359e4c52bbd94a251aef28b54c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keszey=20D=C3=A1niel?= Date: Thu, 24 Oct 2024 09:58:07 +0200 Subject: [PATCH 7/8] change ports --- bin/reth/src/main.rs | 4 ++-- crates/gwyneth/src/engine_api.rs | 8 +++++--- crates/gwyneth/src/exex.rs | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bin/reth/src/main.rs b/bin/reth/src/main.rs index 5656019e0536..6d975a178e64 100644 --- a/bin/reth/src/main.rs +++ b/bin/reth/src/main.rs @@ -12,7 +12,7 @@ use reth_node_ethereum::EthereumNode; use reth_tasks::TaskManager; const BASE_CHAIN_ID: u64 = gwyneth::exex::BASE_CHAIN_ID; // Base chain ID for L2s -const NUM_L2_CHAINS: u64 = 2; // Number of L2 chains to create +const NUM_L2_CHAINS: u64 = 2; // Number of L2 chains to create. Todo: Shall come from config */ fn main() -> eyre::Result<()> { reth::cli::Cli::parse_args().run(|builder, _| async move { @@ -26,7 +26,7 @@ fn main() -> eyre::Result<()> { let mut gwyneth_nodes = Vec::new(); for i in 0..NUM_L2_CHAINS { - let chain_id = BASE_CHAIN_ID + (i * 100000); // Increment by 100000 for each L2 + let chain_id = BASE_CHAIN_ID + i; // Increment by 1 for each L2 let chain_spec = ChainSpecBuilder::default() .chain(chain_id.into()) diff --git a/crates/gwyneth/src/engine_api.rs b/crates/gwyneth/src/engine_api.rs index 4e63207e3266..f27b61c827bd 100644 --- a/crates/gwyneth/src/engine_api.rs +++ b/crates/gwyneth/src/engine_api.rs @@ -17,6 +17,8 @@ use reth_rpc_types::{ use std::{marker::PhantomData, net::Ipv4Addr}; use reth_rpc_builder::constants; +use crate::exex::BASE_CHAIN_ID; + /// Helper for engine api operations pub struct EngineApiContext { pub canonical_stream: CanonStateNotificationStream, @@ -122,9 +124,9 @@ impl RpcServerArgsExEx for RpcServerArgs { self.http_addr = Ipv4Addr::new(0, 0, 0, 0).into(); // Calculate HTTP and WS ports based on chain_id - let port_offset = ((chain_id - 167010) / 100000) as u16; - self.http_port = 10110 + (port_offset * 10000); - self.ws_port = 10111 + (port_offset * 10000); + let port_offset = (chain_id - BASE_CHAIN_ID) as u16; + self.http_port = 10110 + (port_offset * 100); + self.ws_port = 10111 + (port_offset * 100); // Set IPC path self.ipcpath = format!("{}-{}", constants::DEFAULT_IPC_ENDPOINT, chain_id); diff --git a/crates/gwyneth/src/exex.rs b/crates/gwyneth/src/exex.rs index d3e6df503aba..6ae2206a7be4 100644 --- a/crates/gwyneth/src/exex.rs +++ b/crates/gwyneth/src/exex.rs @@ -118,7 +118,7 @@ impl Rollup { println!("transactions: {:?}", transactions); let all_transactions: Vec = decode_transactions(&meta.txList); - let node_chain_id = BASE_CHAIN_ID + (node_idx as u64) * 100000; + let node_chain_id = BASE_CHAIN_ID + (node_idx as u64); let filtered_transactions: Vec = all_transactions .into_iter() From 6476cb1e021ee05e814a0049b7f0e23cd4208f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keszey=20D=C3=A1niel?= Date: Thu, 24 Oct 2024 10:17:12 +0200 Subject: [PATCH 8/8] add readme and network_params --- README.md | 18 ++++++++++++++++++ .../protocol/scripts/confs/network_params.yaml | 1 + 2 files changed, 19 insertions(+) diff --git a/README.md b/README.md index d42fb8e95bfe..04b28744f33f 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,14 @@ Currency: ETH Block explorer: http://127.0.0.1:64003 ``` +``` +chain_id: 167011 +name: Gwyneth-2 +rpc: http://127.0.0.1:32006 +Currency: ETH +Block explorer: http://127.0.0.1:64005 +``` + ``` chain_id: 160010 name: Gwyneth L1 @@ -35,6 +43,16 @@ Add test accounts that have some ETH to play with: Rabby/Brave wallet works, but some issues with nonces so you may have to manually input the correct nonce. +# How to add extra layer2s ? + +In order to add extra layer 2 networks, you need to increase the the `NUM_L2_CHAINS` in the main function [here](https://github.com/taikoxyz/gwyneth/blob/5f6d3a6ffcf0ea359e4c52bbd94a251aef28b54c/bin/reth/src/main.rs#L15). (Later on it will be a configurational setting - no code !) + +If you want infrastructure support too, namingly: + +1. Exposing the jspn rpc port to the host machine (since everything is running in Docker with Kurtosis), you need to specify as a config param like [here](https://github.com/taikoxyz/gwyneth/blob/5f6d3a6ffcf0ea359e4c52bbd94a251aef28b54c/packages/protocol/scripts/confs/network_params.yaml#L6). (By default, if you dont specify this param, the first Layer2 port - which is 10110 - will be exposed to the host anyways. You only need to add this param if you are exposing more than 1 ports to the outter world.) +2. Blockscout support: [Here](https://github.com/taikoxyz/gwyneth/blob/5f6d3a6ffcf0ea359e4c52bbd94a251aef28b54c/packages/protocol/scripts/confs/network_params.yaml#L16) you can see a pattern, how to shoot up blockscout service too. If you want 3 layer2 explorers, just use the service name `blockscout_l2_3`. + + # reth [![CI status](https://github.com/paradigmxyz/reth/workflows/unit/badge.svg)][gh-ci] diff --git a/packages/protocol/scripts/confs/network_params.yaml b/packages/protocol/scripts/confs/network_params.yaml index e97f16aa52fc..e0c2a2bb1d76 100644 --- a/packages/protocol/scripts/confs/network_params.yaml +++ b/packages/protocol/scripts/confs/network_params.yaml @@ -9,6 +9,7 @@ participants: el_image: taiko_reth cl_type: teku cl_image: consensys/teku:latest + el_extra_params: ["--num_of_l2s", "2"] network_params: network_id: '160010' additional_services: