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
66 changes: 66 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ reth-zstd-compressors = { version = "0.8.2", default-features = false }
reth-execution-cache = { git = "https://github.com/paradigmxyz/reth", tag = "v2.11.0" }
reth-trie-parallel = { git = "https://github.com/paradigmxyz/reth", tag = "v2.11.0" }

# StreamingFast Firehose tracer and its Reth integration (local paths pending upstream PRs/tags).
firehose-tracer = "5.7.0"
firehose-tracer-test = "5.7.0"
reth-firehose = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }

# evm2 has no release yet; this is the rev reth v2.11.0 declares, overridden by the
# `[patch]` below to match reth's own `[patch]` section.
evm2 = { git = "https://github.com/alloy-rs/evm2", rev = "66687c18b34d3bdbb899f5eb7605070615c03475", default-features = false }
Expand All @@ -199,6 +204,7 @@ alloy-signer-local = "2.5.0"
alloy-chains = { version = "0.2.33", default-features = false }
async-trait = "0.1.92"
auto_impl = "1"
base64 = "0.22"
bytes = "1.8"
bincode = "2"
clap = { version = "4.5.45", features = ["derive"] }
Expand All @@ -210,6 +216,7 @@ jsonrpsee = { version = "0.26.0", features = ["server", "client", "macros"] }
metrics = "0.24.0"
mockall = "0.14"
parking_lot = "0.12.4"
prost = "0.14"
rand = "0.8.5"
rayon = "1.10"
serde = { version = "1.0.219", features = ["derive"] }
Expand All @@ -235,7 +242,66 @@ evm2 = { git = "https://github.com/DaniPopes/evm2", rev = "66687c18b34d3bdbb899f
evm2-inspectors = { git = "https://github.com/DaniPopes/evm2", rev = "66687c18b34d3bdbb899f5eb7605070615c03475" }
evm2-macros = { git = "https://github.com/DaniPopes/evm2", rev = "66687c18b34d3bdbb899f5eb7605070615c03475" }

# Firehose: route every Reth crate to the StreamingFast Firehose fork of Reth v2.11.0
# (`release/reth-2.x` + chain-agnostic Morph hooks, pending upstream tag).
[patch."https://github.com/paradigmxyz/reth"]
reth-basic-payload-builder = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-chain-state = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-chainspec = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-cli = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-cli-commands = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-cli-runner = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-cli-util = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-consensus = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-consensus-common = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-db = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-db-api = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-e2e-test-utils = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-engine-local = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-engine-tree = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-errors = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-ethereum-cli = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-ethereum-primitives = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-evm = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-evm-ethereum = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-execution-cache = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-execution-errors = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-execution-types = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-exex = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-exex-test-utils = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-metrics = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-network = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-network-peers = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-node-api = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-node-builder = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-node-core = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-node-ethereum = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-payload-builder = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-payload-primitives = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-payload-util = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-provider = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-prune-types = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-rpc = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-rpc-api = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-rpc-builder = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-rpc-convert = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-rpc-eth-api = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-rpc-eth-types = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-rpc-server-types = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-stages-types = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-storage-api = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-storage-errors = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-storage-overlay = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-tasks = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-tracing = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-transaction-pool = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-trie = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-trie-common = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }
reth-trie-parallel = { git = "https://github.com/panos-xyz/reth", rev = "5e9ef20084b9a5f35328e6cf3fbe11558de36f8a" }

[patch.crates-io]
firehose-tracer = { git = "https://github.com/panos-xyz/evm-firehose-tracer-rs", rev = "dae104e9806e2973954b11a2c265e817b21db39d" }
firehose-tracer-test = { git = "https://github.com/panos-xyz/evm-firehose-tracer-rs", rev = "dae104e9806e2973954b11a2c265e817b21db39d" }
reth-codecs = { git = "https://github.com/paradigmxyz/reth-core", rev = "275ce4cf5befeb9f1e8acd935ff2882d2d25fc61" }
reth-codecs-derive = { git = "https://github.com/paradigmxyz/reth-core", rev = "275ce4cf5befeb9f1e8acd935ff2882d2d25fc61" }
reth-primitives-traits = { git = "https://github.com/paradigmxyz/reth-core", rev = "275ce4cf5befeb9f1e8acd935ff2882d2d25fc61" }
Expand Down
15 changes: 15 additions & 0 deletions bin/morph-reth/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ fn main() {
Cli::<MorphChainSpecParser, MorphArgs, MorphRpcModuleValidator, MorphSubcommand>::parse();
apply_morph_cli_defaults(&mut cli);

// Install the process-wide Firehose tracer by default before the node builds its components so
// the payload builder disables pre-inserting already-executed blocks.
if let Commands::Node(command) = &cli.command
&& !command.ext.no_firehose
{
morph_node::firehose::init_tracer();
}

// Run the node
if let Err(err) =
cli.run_with_components::<MorphNode>(components, async move |builder, morph_args| {
Expand Down Expand Up @@ -182,6 +190,7 @@ fn main() {
} else {
None
};
let firehose = !morph_args.no_firehose;
let node = MorphNode::new(morph_args);

let mut add_ons = MorphAddOns::new();
Expand All @@ -207,6 +216,12 @@ fn main() {
);
}

if firehose {
node_builder = node_builder.on_component_initialized(|node| {
morph_node::firehose::init_blockchain(&node.provider)
});
}

let handle = node_builder.launch_with_debug_capabilities().await?;

info!(target: "morph::cli", "Node started successfully");
Expand Down
8 changes: 8 additions & 0 deletions crates/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ reth-ethereum-primitives = { workspace = true, features = ["serde"] }
reth-execution-types.workspace = true
reth-primitives-traits.workspace = true
reth-rpc-eth-api = { workspace = true, optional = true }
reth-firehose = { workspace = true, optional = true }
firehose-tracer = { workspace = true, optional = true }

evm2 = { workspace = true, features = ["std"] }
evm2-inspectors = { workspace = true, optional = true }
Expand Down Expand Up @@ -64,3 +66,9 @@ rpc = [
"dep:reth-rpc-eth-api",
"morph-primitives/reth-codec",
]
firehose = [
"std",
"dep:reth-firehose",
"dep:firehose-tracer",
"morph-primitives/firehose",
]
16 changes: 16 additions & 0 deletions crates/evm/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ impl ConfigureEvm for MorphEvmConfig {
slot_number: None,
})
}

#[cfg(feature = "firehose")]
fn batch_executor<DB: reth_evm::Database>(
&self,
db: DB,
) -> impl reth_evm::execute::Executor<
DB,
Primitives = Self::Primitives,
Error = reth_evm::execute::BlockExecutionError,
> {
reth_firehose::FirehoseBlockExecutor::new_with_chain_hooks(
self.clone(),
db,
reth_firehose::LiveChainHooks,
)
}
}

#[cfg(test)]
Expand Down
114 changes: 114 additions & 0 deletions crates/evm/src/firehose.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
//! StreamingFast Firehose tracing hooks for Morph block execution on `evm2`.
//!
//! `reth-firehose` derives the post-transaction `GasRefund` and `RewardTransactionFee` balance
//! changes from Ethereum gas rules because `evm2` settles gas after the root frame returns without
//! firing inspector hooks. [`MorphPostTxExtras`] supplies Morph's gas accounting and receipt
//! metadata (`MorphTrxOutput`) for both the live engine path (`FirehoseLiveHooks`) and staged sync
//! (`LiveChainHooks`).
//!
//! Tracing is only active once the process-wide tracer is initialized; otherwise every path runs
//! identically to untraced execution.

use crate::{MorphEvmConfig, evm::MorphEvm};
use alloy_primitives::U256;
use evm2::TxResult;
use firehose_tracer::{
pb::sf::ethereum::r#type::v2::{BigInt, MorphTrxOutput},
types::{BlockData, ReceiptData, TxType},
};
use morph_primitives::Block;
use morph_revm::MorphEvmTypes;
use reth_firehose::{
FirehoseInspector, FirehoseLiveHooks, NoPreTxAdjust, PostTxExtras, PostTxGasAccounting,
};
use reth_primitives_traits::SealedBlock;
use std::ops::DerefMut;

fn u256_to_pb(value: U256) -> Option<BigInt> {
(!value.is_zero()).then(|| BigInt {
bytes: value.to_be_bytes_trimmed_vec(),
})
}

/// Applies Morph's gas-fee rules and receipt metadata to Firehose traces.
///
/// - An L1 message has its gas paid on L1, so nothing is refunded or rewarded on L2 and no
/// `MorphTrxOutput` is emitted.
/// - A MorphTx paying its fee in an ERC-20 token moves no native balance for gas.
/// - Every other transaction is refunded at its effective gas price, and the fee recipient
/// (`BlockFees::coinbase`, which comes from `MorphEvmConfig::evm_env` and equals the configured
/// fee vault) receives the whole effective gas price of the consumed gas (Morph does not burn the
/// base fee) plus the L1 data fee, in one `RewardTransactionFee` change.
#[derive(Debug, Clone, Copy, Default)]
pub struct MorphPostTxExtras;

impl<'a> PostTxExtras<MorphEvm<'a>> for MorphPostTxExtras {
fn emit_post_tx_extras<G: DerefMut<Target = firehose_tracer::Tracer>>(
&self,
_evm: &mut MorphEvm<'a>,
_inspector: &FirehoseInspector<G>,
_gas_used: u64,
_base_fee: u64,
) {
}

fn gas_accounting_for_tx(
&self,
_evm: &mut MorphEvm<'a>,
tx_result: &TxResult<MorphEvmTypes>,
tx_type: TxType,
ethereum: PostTxGasAccounting,
) -> PostTxGasAccounting {
if tx_type == TxType::MorphL1Message || tx_result.ext.token_fee_info.is_some() {
return PostTxGasAccounting::none();
}

PostTxGasAccounting {
refund_gas_price: ethereum.refund_gas_price,
reward_gas_price: ethereum.refund_gas_price,
extra_reward: tx_result.ext.l1_data_fee,
}
}

fn capture_receipt_extras(
&self,
tx_result: &TxResult<MorphEvmTypes>,
tx_type: TxType,
) -> Option<Box<dyn FnOnce(&mut ReceiptData) + Send>> {
if tx_type == TxType::MorphL1Message {
return None;
}

let l1_fee = u256_to_pb(tx_result.ext.l1_data_fee);
let fee_rate = tx_result
.ext
.token_fee_info
.and_then(|info| u256_to_pb(info.price_ratio));
let token_scale = tx_result
.ext
.token_fee_info
.and_then(|info| u256_to_pb(info.scale));

if l1_fee.is_none() && fee_rate.is_none() && token_scale.is_none() {
return None;
}

let output = MorphTrxOutput {
l1_fee,
fee_rate,
token_scale,
};
Some(Box::new(move |receipt: &mut ReceiptData| {
receipt.morph_trx_output = Some(output);
}))
}
}

impl FirehoseLiveHooks for MorphEvmConfig {
type PreTxAdjust = NoPreTxAdjust;
type PostTxExtras = MorphPostTxExtras;

fn adjust_block_data(&self, block: &SealedBlock<Block>, block_data: &mut BlockData) {
block_data.morph_next_l1_msg_index = Some(block.header().next_l1_msg_index);
}
}
2 changes: 2 additions & 0 deletions crates/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ pub use context::MorphNextBlockEnvAttributes;
mod error;
pub use error::MorphEvmError;
pub mod evm;
#[cfg(feature = "firehose")]
pub mod firehose;
use std::sync::Arc;

pub use evm::{MorphEvm, MorphEvmFactory};
Expand Down
14 changes: 12 additions & 2 deletions crates/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ workspace = true
morph-chainspec.workspace = true
morph-consensus.workspace = true
morph-engine-api.workspace = true
morph-evm = { workspace = true, features = ["engine"] }
morph-evm = { workspace = true, features = ["engine", "firehose"] }
morph-payload-builder.workspace = true
morph-payload-types.workspace = true
morph-primitives = { workspace = true, features = ["reth-codec"] }
morph-primitives = { workspace = true, features = ["reth-codec", "firehose"] }
morph-proofs.workspace = true
morph-reference-index.workspace = true
morph-rpc.workspace = true
Expand All @@ -34,6 +34,7 @@ reth-engine-tree.workspace = true
reth-errors.workspace = true
reth-evm = { workspace = true, features = ["std"] }
reth-execution-cache.workspace = true
reth-firehose.workspace = true
reth-network.workspace = true
reth-node-api.workspace = true
reth-node-builder.workspace = true
Expand Down Expand Up @@ -62,6 +63,7 @@ alloy-rpc-types-eth.workspace = true

# Async
eyre.workspace = true
firehose-tracer.workspace = true
clap.workspace = true
futures.workspace = true
parking_lot.workspace = true
Expand Down Expand Up @@ -101,11 +103,14 @@ alloy-signer-local.workspace = true
alloy-rpc-types-debug.workspace = true
alloy-rpc-types-engine.workspace = true
alloy-rpc-types-eth.workspace = true
base64.workspace = true
firehose-tracer-test.workspace = true
jsonrpsee.workspace = true
morph-chainspec.workspace = true
morph-payload-types.workspace = true
morph-primitives.workspace = true
morph-proofs-exex.workspace = true
prost.workspace = true
serde_json.workspace = true
tempfile.workspace = true

Expand All @@ -114,6 +119,11 @@ name = "it"
path = "tests/it/main.rs"
required-features = ["test-utils"]

[[test]]
name = "firehose"
path = "tests/firehose/main.rs"
required-features = ["test-utils"]

[features]
default = []
test-utils = [
Expand Down
15 changes: 15 additions & 0 deletions crates/node/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ pub struct MorphArgs {
value_parser = clap::builder::RangedU64ValueParser::<usize>::new().range(1..)
)]
pub proofs_history_max_multi_proof_targets: usize,

/// Disable StreamingFast Firehose block trace output (`FIRE INIT` / `FIRE BLOCK`) on stdout.
#[arg(long = "no-firehose", default_value_t = false)]
pub no_firehose: bool,
}

impl Default for MorphArgs {
Expand All @@ -75,6 +79,7 @@ impl Default for MorphArgs {
proofs_history_window: DEFAULT_PROOFS_HISTORY_WINDOW,
proofs_history_verification_interval: 0,
proofs_history_max_multi_proof_targets: DEFAULT_MAX_MULTI_PROOF_TARGETS,
no_firehose: false,
}
}
}
Expand Down Expand Up @@ -178,5 +183,15 @@ mod tests {
fn test_default_trait_impl() {
let args = MorphArgs::default();
assert_eq!(args.max_tx_payload_bytes, None);
assert!(!args.no_firehose);
}

#[test]
fn firehose_is_enabled_by_default_and_can_be_disabled() {
let default_args = CommandParser::<MorphArgs>::parse_from(["test"]).args;
assert!(!default_args.no_firehose);

let disabled_args = CommandParser::<MorphArgs>::parse_from(["test", "--no-firehose"]).args;
assert!(disabled_args.no_firehose);
}
}
Loading