Skip to content

Commit

Permalink
some req changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Keszey Dániel authored and Keszey Dániel committed Oct 18, 2024
1 parent 5e2729c commit ca53bd3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 50 deletions.
16 changes: 5 additions & 11 deletions bin/reth/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,22 @@ 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()
};

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())
Expand All @@ -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: _ } =
Expand Down
27 changes: 7 additions & 20 deletions crates/gwyneth/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
26 changes: 7 additions & 19 deletions crates/gwyneth/src/exex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down Expand Up @@ -89,19 +88,14 @@ impl<Node: reth_node_api::FullNodeComponents> Rollup<Node> {
}

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))?;
}
Expand All @@ -110,16 +104,10 @@ impl<Node: reth_node_api::FullNodeComponents> Rollup<Node> {
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<GwynethEngineTypes>,
) -> 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 {
Expand Down

0 comments on commit ca53bd3

Please sign in to comment.