Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions bin/reth-bench-compare/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ use tokio::{
};
use tracing::{debug, info, warn};

const CUSTOM_CHAINIDS: &[(&str, &str)] = &[
("1952", "xlayer-testnet"),
("196", "xlayer-mainnet"),
];

/// Manages reth node lifecycle and operations
pub(crate) struct NodeManager {
datadir: Option<String>,
Expand Down Expand Up @@ -123,8 +128,9 @@ impl NodeManager {
let mut reth_args = vec![binary_path_str.to_string(), "node".to_string()];

// Add chain argument (skip for mainnet as it's the default)
let chain_str = self.chain.to_string();
let mut chain_str = self.chain.to_string();
if chain_str != "mainnet" {
chain_str = self.custom_chainname(chain_str, self.chain.is_id());
reth_args.extend_from_slice(&["--chain".to_string(), chain_str.clone()]);
}

Expand Down Expand Up @@ -456,8 +462,9 @@ impl NodeManager {
};

// Add chain argument (skip for mainnet as it's the default)
let chain_str = self.chain.to_string();
let mut chain_str = self.chain.to_string();
if chain_str != "mainnet" {
chain_str = self.custom_chainname(chain_str, self.chain.is_id());
cmd.args(["--chain", &chain_str]);
}

Expand Down Expand Up @@ -508,4 +515,21 @@ impl NodeManager {
info!("Unwound to block: {}", block_number);
Ok(())
}

/// XLayer: custom chain names are not of `alloy` chain enum, and this name is passed
/// into reth node as arg. If we passed in a numerical value to `--chain`, the reth node
/// fails to start.
fn custom_chainname(&self, chain_str: String, is_id: bool) -> String {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it's better to add xlayer chain name in alloy

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good if I were only testing mainnet. But for testnet, I do not believe we commit such a change to alloy?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe passing an arg to override the chainname (if no exist) will allow any custom name to be passed?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this can be committed temparary, but pls add a mark TODO to commit to alloy later on

// If id matches custom chain ids, map to chain name that is absent
// from alloy chain enum.
if is_id {
for (id, name) in CUSTOM_CHAINIDS {
if *id == chain_str {
return (*name).into();
}
}
}

chain_str
}
}