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
186 changes: 168 additions & 18 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ repository = "https://github.com/okx/xlayer-reth.git"
resolver = "2"
members = [
"crates/chainspec",
"crates/evm",
"crates/flashblocks",
"crates/node",
"crates/rpc",
"crates/tests",
"crates/legacy-rpc",
Expand Down Expand Up @@ -61,7 +63,9 @@ codegen-units = 1
# ==============================================================================

xlayer-chainspec = { path = "crates/chainspec" }
xlayer-evm = { path = "crates/evm" }
xlayer-flashblocks = { path = "crates/flashblocks" }
xlayer-node = { path = "crates/node" }
xlayer-reth-node = { path = "bin/node" }
xlayer-rpc = { path = "crates/rpc" }
xlayer-legacy-rpc = { path = "crates/legacy-rpc" }
Expand Down Expand Up @@ -105,11 +109,13 @@ reth-rpc-convert = { git = "https://github.com/okx/reth", rev = "3ba1e5d3820fff4
reth-rpc-eth-api = { git = "https://github.com/okx/reth", rev = "3ba1e5d3820fff48ade7962769cb367ac183ba92" }
reth-rpc-eth-types = { git = "https://github.com/okx/reth", rev = "3ba1e5d3820fff48ade7962769cb367ac183ba92" }
reth-storage-api = { git = "https://github.com/okx/reth", rev = "3ba1e5d3820fff48ade7962769cb367ac183ba92" }
reth-storage-errors = { git = "https://github.com/okx/reth", rev = "3ba1e5d3820fff48ade7962769cb367ac183ba92" }
reth-tasks = { git = "https://github.com/okx/reth", rev = "3ba1e5d3820fff48ade7962769cb367ac183ba92" }
reth-tracing = { git = "https://github.com/okx/reth", rev = "3ba1e5d3820fff48ade7962769cb367ac183ba92" }
reth-transaction-pool = { git = "https://github.com/okx/reth", rev = "3ba1e5d3820fff48ade7962769cb367ac183ba92" }
reth-optimism-flashblocks = { git = "https://github.com/okx/reth", rev = "3ba1e5d3820fff48ade7962769cb367ac183ba92" }
reth-rpc-server-types = { git = "https://github.com/okx/reth", rev = "3ba1e5d3820fff48ade7962769cb367ac183ba92" }
reth-payload-builder = { git = "https://github.com/okx/reth", rev = "3ba1e5d3820fff48ade7962769cb367ac183ba92" }


# ==============================================================================
Expand Down
5 changes: 5 additions & 0 deletions bin/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ workspace = true
# internal
xlayer-flashblocks.workspace = true
xlayer-chainspec.workspace = true
xlayer-evm.workspace = true
xlayer-node.workspace = true
xlayer-rpc.workspace = true
xlayer-legacy-rpc.workspace = true
xlayer-version.workspace = true
Expand All @@ -25,6 +27,7 @@ reth-optimism-node.workspace = true
reth-optimism-cli.workspace = true
reth-primitives.workspace = true
reth-node-api.workspace = true
reth-node-builder.workspace = true
reth-rpc-eth-api.workspace = true
reth-optimism-primitives.workspace = true
reth-rpc-convert.workspace = true
Expand All @@ -33,6 +36,7 @@ reth-optimism-evm.workspace = true
reth-optimism-chainspec.workspace = true
reth-cli-util.workspace = true
reth-exex.workspace = true
reth-payload-builder.workspace = true
reth-rpc-server-types.workspace = true

# flashblocks
Expand All @@ -53,6 +57,7 @@ jsonrpsee.workspace = true

# alloy
alloy-primitives.workspace = true
op-alloy-network.workspace = true

# misc
clap.workspace = true
Expand Down
87 changes: 75 additions & 12 deletions bin/node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,64 @@ use args_xlayer::XLayerArgs;
use clap::Parser;
use tracing::info;

use op_alloy_network::Optimism;
use op_rbuilder::{
args::OpRbuilderArgs,
builders::{BuilderConfig, FlashblocksServiceBuilder},
traits::{NodeBounds, PoolBounds},
};
use reth::{
builder::{EngineNodeLauncher, Node, NodeHandle, TreeConfig},
builder::{EngineNodeLauncher, NodeHandle, TreeConfig},
providers::providers::BlockchainProvider,
};
use reth_optimism_cli::Cli;
use reth_optimism_node::OpNode;

use reth_node_api::FullNodeComponents;
use reth_node_api::{FullNodeComponents, NodeTypes};
use reth_node_builder::{
BuilderContext,
components::PayloadServiceBuilder,
rpc::BasicEngineValidatorBuilder,
};
use reth_optimism_evm::OpEvmConfig;
use reth_optimism_node::{OpEngineApiBuilder, OpEngineValidatorBuilder};
use reth_payload_builder::PayloadBuilderHandle;
use reth_rpc_eth_api::EthApiTypes;
use reth_rpc_server_types::RethRpcModule;
use xlayer_chainspec::XLayerChainSpecParser;
use xlayer_flashblocks::handler::FlashblocksService;
use xlayer_flashblocks::subscription::FlashblocksPubSub;
use xlayer_legacy_rpc::{layer::LegacyRpcRouterLayer, LegacyRpcRouterConfig};
use xlayer_node::{XLayerNode, XLayerExecutorBuilder};
use xlayer_rpc::xlayer_ext::{XlayerRpcExt, XlayerRpcExtApiServer};

/// Flashblocks payload builder wrapper that accepts XLayerEvmConfig.
struct XLayerFlashblocksServiceBuilder(FlashblocksServiceBuilder);

impl<Node, Pool> PayloadServiceBuilder<Node, Pool, xlayer_evm::XLayerEvmConfig>
for XLayerFlashblocksServiceBuilder
where
Node: NodeBounds,
Pool: PoolBounds,
{
async fn spawn_payload_builder_service(
self,
ctx: &BuilderContext<Node>,
pool: Pool,
_evm_config: xlayer_evm::XLayerEvmConfig,
) -> eyre::Result<PayloadBuilderHandle<<Node::Types as NodeTypes>::Payload>> {
// Delegate to the original flashblocks builder using the standard OP EVM config.
let base_evm = OpEvmConfig::optimism(ctx.chain_spec());
<FlashblocksServiceBuilder as PayloadServiceBuilder<Node, Pool, OpEvmConfig>>::spawn_payload_builder_service(
self.0,
ctx,
pool,
base_evm,
)
.await
}
}

#[global_allocator]
static ALLOC: reth_cli_util::allocator::Allocator = reth_cli_util::allocator::new_allocator();

Expand Down Expand Up @@ -67,7 +105,9 @@ fn main() {
std::process::exit(1);
}

let op_node = OpNode::new(args.node_args.rollup_args.clone());
// Create XLayerNode (re-exported OpNode)
let xlayer_node = XLayerNode::new(args.node_args.rollup_args.clone());
info!(target: "reth::cli", "XLayer node initialized with Poseidon precompile support");

let genesis_block = builder.config().chain.genesis().number.unwrap_or_default();
info!("XLayer genesis block = {}", genesis_block);
Expand All @@ -79,11 +119,6 @@ fn main() {
timeout: args.xlayer_args.legacy.legacy_rpc_timeout,
};

// Build add-ons with RPC middleware
// If not enabled, the layer will not do any re-routing.
let add_ons =
op_node.add_ons().with_rpc_middleware(LegacyRpcRouterLayer::new(legacy_config));

// Should run as sequencer if flashblocks.enabled = true. Doing so means you are
// running a flashblocks producing sequencer.
let NodeHandle { node: _node, node_exit_future } = if args.node_args.flashblocks.enabled
Expand All @@ -94,9 +129,24 @@ fn main() {
builder
.with_types_and_provider::<OpNode, BlockchainProvider<_>>()
.with_components(
op_node.components().payload(FlashblocksServiceBuilder(builder_config)),
xlayer_node
.components()
.executor(XLayerExecutorBuilder)
.payload(XLayerFlashblocksServiceBuilder(
FlashblocksServiceBuilder(builder_config),
)),
)
.with_add_ons(
xlayer_node
.add_ons_builder::<Optimism>()
.with_rpc_middleware(LegacyRpcRouterLayer::new(legacy_config))
.build::<
_,
OpEngineValidatorBuilder,
OpEngineApiBuilder<OpEngineValidatorBuilder>,
BasicEngineValidatorBuilder<OpEngineValidatorBuilder>,
>(),
)
.with_add_ons(add_ons)
.on_component_initialized(move |_ctx| {
// TODO: Initialize XLayer components here
Ok(())
Expand Down Expand Up @@ -133,8 +183,21 @@ fn main() {
} else {
builder
.with_types_and_provider::<OpNode, BlockchainProvider<_>>()
.with_components(op_node.components())
.with_add_ons(add_ons)
.with_components(
xlayer_node.components()
.executor(XLayerExecutorBuilder) // ← 使用自定义 Executor with Poseidon
)
.with_add_ons(
xlayer_node
.add_ons_builder::<Optimism>()
.with_rpc_middleware(LegacyRpcRouterLayer::new(legacy_config))
.build::<
_,
OpEngineValidatorBuilder,
OpEngineApiBuilder<OpEngineValidatorBuilder>,
BasicEngineValidatorBuilder<OpEngineValidatorBuilder>,
>(),
)
.on_component_initialized(move |_ctx| {
// TODO: Initialize XLayer components here
Ok(())
Expand Down
45 changes: 45 additions & 0 deletions crates/evm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[package]
name = "xlayer-evm"
version.workspace = true
edition.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true

[dependencies]
# Reth dependencies
reth-chainspec.workspace = true
reth-primitives.workspace = true
reth-evm.workspace = true
reth-optimism-chainspec.workspace = true
reth-optimism-evm.workspace = true
reth-optimism-forks.workspace = true
reth-optimism-primitives.workspace = true
reth-node-api.workspace = true
reth-execution-types.workspace = true
reth-primitives-traits.workspace = true
reth-storage-errors.workspace = true

# Revm dependencies
revm.workspace = true
revm-context-interface.workspace = true
revm-database.workspace = true
op-revm = { version = "12.0.2", default-features = false }

# Alloy
alloy-primitives.workspace = true
alloy-consensus.workspace = true
alloy-eips.workspace = true
op-alloy-consensus.workspace = true
op-alloy-rpc-types-engine.workspace = true

# Poseidon implementation
poseidon-rs = "0.0.10"
num-bigint = "0.4"
ff_ce = "0.11"

# Utils
once_cell.workspace = true
tracing.workspace = true

[dev-dependencies]
Loading