Skip to content
Draft
Show file tree
Hide file tree
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
5,660 changes: 4,427 additions & 1,233 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ members = [
"crates/version",

"bin/tools",
"bin/node",
"bin/node",
"bin/legacy-migrate",
]
default-members = ["bin/node"]

Expand Down Expand Up @@ -68,6 +69,7 @@ xlayer-monitor = { path = "crates/monitor" }
xlayer-reth-node = { path = "bin/node" }
xlayer-rpc = { path = "crates/rpc" }
xlayer-version = { path = "crates/version" }
xlayer-legacy-migrate = { path = "bin/legacy-migrate" }

# For X layer
xlayer-trace-monitor = { git = "https://github.com/okx/xlayer-toolkit", rev = "0004d202181bb772821797cd54983e29f32cae07" }
Expand Down Expand Up @@ -122,6 +124,7 @@ reth-tracing = { git = "https://github.com/okx/reth", rev = "b6a31f31af91abdecb4
reth-transaction-pool = { git = "https://github.com/okx/reth", rev = "b6a31f31af91abdecb475f2a991906bff9bbef7f" }
reth-optimism-flashblocks = { git = "https://github.com/okx/reth", rev = "b6a31f31af91abdecb475f2a991906bff9bbef7f" }
reth-rpc-server-types = { git = "https://github.com/okx/reth", rev = "b6a31f31af91abdecb475f2a991906bff9bbef7f" }
reth-static-file-types = { git = "https://github.com/okx/reth", rev = "b6a31f31af91abdecb475f2a991906bff9bbef7f" }

# ==============================================================================
# Revm Dependencies (follows upstream reth)
Expand All @@ -148,7 +151,7 @@ alloy-evm = { version = "0.26.3", default-features = false }
alloy-genesis = { version = "1.4.3", default-features = false }
alloy-json-rpc = { version = "1.4.3" }
alloy-network = { version = "1.4.3", default-features = false }
alloy-primitives = { version = "1.5.2", default-features = false, features = [
alloy-primitives = { version = "1.5.4", default-features = false, features = [
"map-foldhash",
] }
alloy-provider = { version = "1.4.3" }
Expand Down Expand Up @@ -207,6 +210,7 @@ tracing = { version = "0.1.41" }
url = "2.5"
uuid = { version = "1.6.1", features = ["serde", "v5", "v4"] }
moka = { version = "0.12.11", features = ["sync"] }
rayon = "1.7"

# ==============================================================================
# Dependency Patches
Expand Down Expand Up @@ -257,6 +261,7 @@ reth-rpc-api = { git = "https://github.com/okx/reth", rev = "b6a31f31af91abdecb4
reth-rpc-engine-api = { git = "https://github.com/okx/reth", rev = "b6a31f31af91abdecb475f2a991906bff9bbef7f" }
reth-rpc-eth-types = { git = "https://github.com/okx/reth", rev = "b6a31f31af91abdecb475f2a991906bff9bbef7f" }
reth-rpc-layer = { git = "https://github.com/okx/reth", rev = "b6a31f31af91abdecb475f2a991906bff9bbef7f" }
reth-static-file-types = { git = "https://github.com/okx/reth", rev = "b6a31f31af91abdecb475f2a991906bff9bbef7f" }
reth-storage-api = { git = "https://github.com/okx/reth", rev = "b6a31f31af91abdecb475f2a991906bff9bbef7f" }
reth-tasks = { git = "https://github.com/okx/reth", rev = "b6a31f31af91abdecb475f2a991906bff9bbef7f" }
reth-testing-utils = { git = "https://github.com/okx/reth", rev = "b6a31f31af91abdecb475f2a991906bff9bbef7f" }
Expand Down
57 changes: 57 additions & 0 deletions bin/legacy-migrate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[package]
name = "xlayer-legacy-migrate"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true

[dependencies]

# Use workspace reth dependencies to ensure consistent versions
reth-db = { git = "https://github.com/okx/reth", rev = "9359e21f943108972b2e4c4da7ffea80266a37e9" }
reth-db-api = { git = "https://github.com/okx/reth", rev = "9359e21f943108972b2e4c4da7ffea80266a37e9" }
reth-cli = { git = "https://github.com/okx/reth", rev = "9359e21f943108972b2e4c4da7ffea80266a37e9" }
reth-cli-commands = { git = "https://github.com/okx/reth", rev = "9359e21f943108972b2e4c4da7ffea80266a37e9", features = ["edge"] }
reth-node-builder = { git = "https://github.com/okx/reth", rev = "9359e21f943108972b2e4c4da7ffea80266a37e9" }
reth-optimism-chainspec = { git = "https://github.com/okx/reth", rev = "9359e21f943108972b2e4c4da7ffea80266a37e9" }
reth-optimism-cli = { git = "https://github.com/okx/reth", rev = "9359e21f943108972b2e4c4da7ffea80266a37e9" }
reth-optimism-node = { git = "https://github.com/okx/reth", rev = "9359e21f943108972b2e4c4da7ffea80266a37e9" }
reth-primitives-traits = { git = "https://github.com/okx/reth", rev = "9359e21f943108972b2e4c4da7ffea80266a37e9" }
reth-provider = { git = "https://github.com/okx/reth", rev = "9359e21f943108972b2e4c4da7ffea80266a37e9", features = ["rocksdb"] }
reth-static-file-types = { git = "https://github.com/okx/reth", rev = "9359e21f943108972b2e4c4da7ffea80266a37e9" }
reth-storage-api = { git = "https://github.com/okx/reth", rev = "9359e21f943108972b2e4c4da7ffea80266a37e9" }
reth-tracing = { git = "https://github.com/okx/reth", rev = "9359e21f943108972b2e4c4da7ffea80266a37e9" }

alloy-primitives.workspace = true

clap = { workspace = true, features = ["derive"] }
eyre.workspace = true
tokio.workspace = true
tracing.workspace = true
rayon.workspace = true

# Chainspec deps

# reth
reth-chainspec = { git = "https://github.com/okx/reth", rev = "9359e21f943108972b2e4c4da7ffea80266a37e9" }
reth-optimism-forks = { git = "https://github.com/okx/reth", rev = "9359e21f943108972b2e4c4da7ffea80266a37e9" }
reth-ethereum-forks = { git = "https://github.com/okx/reth", rev = "9359e21f943108972b2e4c4da7ffea80266a37e9" }

# ethereum
alloy-genesis = { version = "1.6.1", default-features = false }
alloy-consensus = { version = "1.6.1", default-features = false }
alloy-eips = { version = "1.6.1", default-features = false }
alloy-chains = { version = "0.2.5", default-features = false }

# op
op-alloy-rpc-types = { workspace = true }

# misc
serde = { workspace = true }
serde_json = { workspace = true }
once_cell = { workspace = true }

[lints]
workspace = true
94 changes: 94 additions & 0 deletions bin/legacy-migrate/src/chainspec_parser.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
use crate::xlayer_mainnet::XLAYER_MAINNET;
use crate::xlayer_testnet::XLAYER_TESTNET;
use alloy_genesis::Genesis;
use reth_cli::chainspec::ChainSpecParser;
use reth_optimism_chainspec::{generated_chain_value_parser, OpChainSpec};
use std::sync::Arc;
use tracing::debug;

/// XLayer chain specification parser
///
/// This parser extends the default OpChainSpecParser to support XLayer chains:
/// - xlayer-mainnet (chain id 196)
/// - xlayer-testnet (chain id 1952)
///
/// It also supports all standard Optimism chains through delegation to the
/// upstream OpChainSpecParser.
#[derive(Debug, Clone, Default)]
#[non_exhaustive]
pub(crate) struct XLayerChainSpecParser;

impl ChainSpecParser for XLayerChainSpecParser {
type ChainSpec = OpChainSpec;

const SUPPORTED_CHAINS: &'static [&'static str] = &[
// Standard OP chains
"dev",
"optimism",
"optimism_sepolia",
"optimism-sepolia",
"base",
"base_sepolia",
"base-sepolia",
// XLayer chains
"xlayer-mainnet",
"xlayer-testnet",
];

fn parse(s: &str) -> eyre::Result<Arc<Self::ChainSpec>> {
xlayer_chain_value_parser(s)
}
}

/// Parse genesis from file path or JSON string
fn parse_genesis(s: &str) -> eyre::Result<Genesis> {
// Use the standard reth parse_genesis to maintain compatibility
let mut genesis = reth_cli::chainspec::parse_genesis(s)?;

// XLayer extension: If legacyXLayerBlock is specified in config, override genesis.number
// This allows XLayer to migrate from a legacy chain by setting the genesis
// block number to match the legacy chain's starting block.
if let Some(legacy_block_value) = genesis.config.extra_fields.get("legacyXLayerBlock")
&& let Some(legacy_block) = legacy_block_value.as_u64()
{
debug!("Overriding genesis.number from {:?} to {legacy_block}", genesis.number);
genesis.number = Some(legacy_block);
}

Ok(genesis)
}

/// XLayer chain value parser
///
/// Parses chain specifications with the following priority:
/// 1. XLayer named chains (xlayer-mainnet, xlayer-testnet)
/// 2. Standard Optimism named chains (via `generated_chain_value_parser`)
/// 3. Genesis file path or JSON string (with `legacyXLayerBlock` support)
fn xlayer_chain_value_parser(s: &str) -> eyre::Result<Arc<OpChainSpec>> {
match s {
"xlayer-mainnet" => {
// Support environment variable override for genesis path
if let Ok(genesis_path) = std::env::var("XLAYER_MAINNET_GENESIS") {
return Ok(Arc::new(parse_genesis(&genesis_path)?.into()));
}
Ok(XLAYER_MAINNET.clone())
}
"xlayer-testnet" => {
// Support environment variable override for genesis path
if let Ok(genesis_path) = std::env::var("XLAYER_TESTNET_GENESIS") {
return Ok(Arc::new(parse_genesis(&genesis_path)?.into()));
}
Ok(XLAYER_TESTNET.clone())
}
// For other inputs, try known OP chains first, then parse as genesis
_ => {
// Try to match known OP chains (optimism, base, etc.)
if let Some(op_chain_spec) = generated_chain_value_parser(s) {
return Ok(op_chain_spec);
}

// Otherwise, parse as genesis file/JSON with XLayer extensions
Ok(Arc::new(parse_genesis(s)?.into()))
}
}
}
Loading