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
280 changes: 151 additions & 129 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ version = "1.3.0"
edition = "2024"
license = "MIT OR Apache-2.0"

[[bin]]
name = "bera-reth"
path = "src/main.rs"

[[bin]]
name = "bera-sequencer"
path = "src/bin/bera-sequencer.rs"

[dependencies]
alloy-consensus = "1.0.37"
alloy-eips = "1.0.37"
Expand All @@ -23,6 +31,9 @@ derive_more = "2.0.1"
eyre = "0.6.12"
sha2 = "0.10"

# Requires minor modifications to rblib such that `FixedTransactions` is public
rblib = { path = "../rblib", default-features = false }

# rpc
jsonrpsee = "0.26.0"
jsonrpsee-core = { version = "0.26.0", features = ["server"] }
Expand Down Expand Up @@ -69,12 +80,9 @@ tokio = "1.46.0"
tracing = "0.1.41"

[dev-dependencies]
alloy-provider = "1.0.37"
alloy-rpc-client = "1.0.37"
alloy-rpc-types-trace = "1.0.37"
eyre = "0.6.12"
reth-e2e-test-utils = { git = "https://github.com/paradigmxyz/reth", tag = "v1.8.2" }
reth-rpc-builder = { git = "https://github.com/paradigmxyz/reth", tag = "v1.8.2" }
revm-inspectors = "0.30.0"
serde_json = "1.0"
test-fuzz = "7"
Expand Down
104 changes: 104 additions & 0 deletions src/bin/bera-sequencer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//! Berachain Sequencer Binary
//!
//! This binary runs bera-reth with a custom payload builder for sequencing.
//!
//! Usage: `cargo run --bin bera-sequencer -- node`

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

use bera_reth::{
chainspec::{BerachainChainSpec, BerachainChainSpecParser},
consensus::BerachainBeaconConsensus,
engine::{rpc::BerachainEngineApiBuilder, validator::BerachainEngineValidatorBuilder},
evm::BerachainEvmFactory,
node::{BerachainNode, evm::config::BerachainEvmConfig},
platform::BerachainPlatform,
rpc::{BerachainAddOns, BerachainEthApiBuilder},
version::init_bera_version,
};
use clap::Parser;
use rblib::{
pool::{AppendOrders, HostNodeInstaller, OrderPool},
prelude::{Loop, Pipeline},
steps::{OrderByPriorityFee, RemoveRevertedTransactions},
};
use reth::CliRunner;
use reth_cli_commands::node::NoArgs;
use reth_ethereum_cli::Cli;
use reth_node_builder::{Node, NodeHandle};
use std::sync::Arc;
use tracing::info;

/// Example Berachain builder pipeline with Revert Protection
fn berachain_builder_pipeline(pool: &OrderPool<BerachainPlatform>) -> Pipeline<BerachainPlatform> {
let pipeline = Pipeline::<BerachainPlatform>::named("classic").with_pipeline(
Loop,
(
AppendOrders::from_pool(pool),
OrderByPriorityFee::default(),
RemoveRevertedTransactions::default(),
),
);

pool.attach_pipeline(&pipeline);
pipeline
}

fn main() {
// Install signal handler for better crash reporting
reth_cli_util::sigsegv_handler::install();

// Initialize Bera-Reth version metadata
init_bera_version().expect("Failed to initialize Bera-Reth version metadata");

// Enable backtraces unless a RUST_BACKTRACE value has already been explicitly provided.
if std::env::var_os("RUST_BACKTRACE").is_none() {
unsafe { std::env::set_var("RUST_BACKTRACE", "1") };
}

let cli_components_builder = |spec: Arc<BerachainChainSpec>| {
(
BerachainEvmConfig::new_with_evm_factory(spec.clone(), BerachainEvmFactory::default()),
Arc::new(BerachainBeaconConsensus::new(spec)),
)
};

if let Err(err) = Cli::<BerachainChainSpecParser, NoArgs>::parse()
.with_runner_and_components::<BerachainNode>(
CliRunner::try_default_runtime().expect("Failed to create default runtime"),
cli_components_builder,
async move |builder, _| {
info!(target: "reth::cli", "Launching Berachain Sequencer node");
let pool = OrderPool::<BerachainPlatform>::default();
let pipeline = berachain_builder_pipeline(&pool);
let berachain_node = BerachainNode::default();

// Helps compiler
let add_ons: BerachainAddOns<
_,
BerachainEthApiBuilder,
BerachainEngineValidatorBuilder,
BerachainEngineApiBuilder<BerachainEngineValidatorBuilder>,
> = BerachainAddOns::default();

let NodeHandle { node: _node, node_exit_future } = builder
.with_types::<BerachainNode>()
.with_components(
berachain_node
.components_builder()
.attach_pool(&pool)
.payload(pipeline.into_service()),
)
.with_add_ons(add_ons)
.launch_with_debug_capabilities()
.await?;

node_exit_future.await
},
)
{
eprintln!("Error: {err:?}");
std::process::exit(1);
}
}
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ pub mod evm;
pub mod genesis;
pub mod hardforks;
pub mod node;
pub mod platform;
pub mod pool;
pub mod primitives;
pub mod rpc;
pub mod transaction;
pub mod version;

#[cfg(test)]
pub mod test_utils;
pub mod transaction;
pub mod version;
21 changes: 13 additions & 8 deletions src/node/evm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
//! Berachain EVM executor using standard Ethereum execution with Berachain chain spec

mod assembler;
mod block_context;
pub mod block_context;
pub mod config;
pub mod error;
pub mod executor;
pub mod receipt;

use crate::{
evm::BerachainEvmFactory,
node::{BerachainNode, evm::config::BerachainEvmConfig},
};
pub use config::BerachainEvmConfig;

use crate::evm;
use alloy_primitives::Bytes;
use reth_node_api::NodeTypes;
use reth_node_builder::{BuilderContext, FullNodeTypes, components::ExecutorBuilder};

/// Default extra data for Berachain blocks
Expand All @@ -20,7 +20,7 @@ fn default_extra_data() -> String {
}

/// Default extra data in bytes for Berachain blocks
fn default_extra_data_bytes() -> Bytes {
pub fn default_extra_data_bytes() -> Bytes {
Bytes::from(default_extra_data().as_bytes().to_vec())
}

Expand All @@ -30,7 +30,12 @@ pub struct BerachainExecutorBuilder;

impl<Node> ExecutorBuilder<Node> for BerachainExecutorBuilder
where
Node: FullNodeTypes<Types = BerachainNode>,
Node: FullNodeTypes<
Types: NodeTypes<
ChainSpec = crate::chainspec::BerachainChainSpec,
Primitives = crate::primitives::BerachainPrimitives,
>,
>,
{
/// The EVM configuration type that will be built
type EVM = BerachainEvmConfig;
Expand All @@ -39,7 +44,7 @@ where
async fn build_evm(self, ctx: &BuilderContext<Node>) -> eyre::Result<Self::EVM> {
let evm_config = BerachainEvmConfig::new_with_evm_factory(
ctx.chain_spec(),
BerachainEvmFactory::default(),
evm::BerachainEvmFactory::default(),
)
.with_extra_data(default_extra_data_bytes());
Ok(evm_config)
Expand Down
10 changes: 6 additions & 4 deletions src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

pub mod evm;

pub use crate::{
consensus::BerachainConsensusBuilder, pool::BerachainPoolBuilder, rpc::BerachainAddOns,
};
pub use evm::BerachainExecutorBuilder;

use crate::{
chainspec::BerachainChainSpec,
consensus::BerachainConsensusBuilder,
engine::{
BerachainEngineTypes, builder::BerachainPayloadServiceBuilder,
validator::BerachainEngineValidatorBuilder,
},
node::evm::BerachainExecutorBuilder,
pool::BerachainPoolBuilder,
primitives::{BerachainHeader, BerachainPrimitives},
rpc::{BerachainAddOns, BerachainEthApiBuilder},
rpc::BerachainEthApiBuilder,
transaction::BerachainTxEnvelope,
};
use alloy_consensus::{SignableTransaction, error::ValueError};
Expand Down
Loading
Loading