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

Large diffs are not rendered by default.

189 changes: 97 additions & 92 deletions Cargo.toml

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions crates/builder/op-rbuilder/src/builders/builder_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ use op_alloy_consensus::OpTypedTransaction;
use op_alloy_rpc_types::OpTransactionRequest;
use op_revm::{OpHaltReason, OpTransactionError};
use reth_evm::{
ConfigureEvm, Evm, EvmError, InvalidTxError, eth::receipt_builder::ReceiptBuilderCtx,
precompiles::PrecompilesMap,
ConfigureEvm, Evm, EvmEnv, EvmError, InvalidTxError, eth::receipt_builder::ReceiptBuilderCtx, precompiles::PrecompilesMap, rpc::TryIntoTxEnv
};
use reth_node_api::PayloadBuilderError;
use reth_optimism_primitives::OpTransactionSigned;
use reth_primitives::Recovered;
use reth_provider::{ProviderError, StateProvider};
use reth_revm::{State, database::StateProviderDatabase};
use reth_rpc_api::eth::{EthTxEnvError, transaction::TryIntoTxEnv};
use reth_rpc_api::eth::{EthTxEnvError};
use revm::{
DatabaseCommit, DatabaseRef,
context::{
Expand Down Expand Up @@ -323,7 +322,8 @@ pub trait BuilderTransactions<ExtraCtx: Debug + Default = (), Extra: Debug + Def
expected_logs: Vec<B256>,
evm: &mut OpEvm<impl Database, NoOpInspector, PrecompilesMap>,
) -> Result<SimulationSuccessResult<T>, BuilderTransactionError> {
let tx_env = tx.try_into_tx_env(evm.cfg(), evm.block())?;
let evm_env = EvmEnv { cfg_env: evm.cfg().clone(), block_env: evm.block().clone() };
let tx_env = tx.try_into_tx_env(&evm_env)?;
let to = tx_env.base.kind.into_to().unwrap_or_default();

let ResultAndState { result, state } = match evm.transact(tx_env) {
Expand Down
19 changes: 11 additions & 8 deletions crates/builder/op-rbuilder/src/builders/flashblocks/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ use core::time::Duration;
use eyre::WrapErr as _;
use reth::payload::PayloadBuilderAttributes;
use reth_basic_payload_builder::BuildOutcome;
use reth_chain_state::ExecutedBlock;
use reth_chainspec::EthChainSpec;
use reth_evm::{ConfigureEvm, execute::BlockBuilder};
use reth_node_api::{Block, NodePrimitives, PayloadBuilderError};
use reth_node_api::{Block, BuiltPayloadExecutedBlock, NodePrimitives, PayloadBuilderError};
use reth_optimism_consensus::{calculate_receipt_root_no_memo_optimism, isthmus};
use reth_optimism_evm::{OpEvmConfig, OpNextBlockEnvAttributes};
use reth_optimism_forks::OpHardforks;
Expand Down Expand Up @@ -336,7 +335,7 @@ where
.map_err(|e| PayloadBuilderError::Other(e.into()))?;

let state_provider = self.client.state_by_block_hash(ctx.parent().hash())?;
let db = StateProviderDatabase::new(&state_provider);
let db = StateProviderDatabase::new(state_provider);
self.address_gas_limiter.refresh(ctx.block_number());

// 1. execute the pre steps and seal an early block with that
Expand All @@ -346,6 +345,8 @@ where
.with_bundle_update()
.build();

let state_provider = self.client.state_by_block_hash(ctx.parent().hash())?;

let mut info = execute_pre_steps(&mut state, &ctx)?;
let sequencer_tx_time = sequencer_tx_start_time.elapsed();
ctx.metrics.sequencer_tx_duration.record(sequencer_tx_time);
Expand Down Expand Up @@ -537,13 +538,15 @@ where
return Ok(());
}

let state_provider = self.client.state_by_block_hash(ctx.parent().hash())?;

// build first flashblock immediately
let next_flashblocks_ctx = match self
.build_next_flashblock(
&ctx,
&mut info,
&mut state,
&state_provider,
state_provider,
&mut best_txs,
&block_cancel,
&best_payload,
Expand Down Expand Up @@ -601,7 +604,7 @@ where
ctx: &OpPayloadBuilderCtx<FlashblocksExtraCtx>,
info: &mut ExecutionInfo<FlashblocksExecutionInfo>,
state: &mut State<DB>,
state_provider: impl reth::providers::StateProvider + Clone,
state_provider: impl reth::providers::StateProvider,
best_txs: &mut NextBestFlashblocksTxs<Pool>,
block_cancel: &CancellationToken,
best_payload: &BlockCell<OpBuiltPayload>,
Expand Down Expand Up @@ -1110,11 +1113,11 @@ where
RecoveredBlock::new_unhashed(block.clone(), info.executed_senders.clone());
// create the executed block data

let executed = ExecutedBlock {
let executed = BuiltPayloadExecutedBlock {
recovered_block: Arc::new(recovered_block),
execution_output: Arc::new(execution_outcome),
hashed_state: Arc::new(hashed_state),
trie_updates: Arc::new(trie_output),
hashed_state: either::Either::Left(Arc::new(hashed_state)),
trie_updates: either::Either::Left(Arc::new(trie_output)),
};
debug!(target: "payload_builder", message = "Executed block created");

Expand Down
5 changes: 2 additions & 3 deletions crates/builder/op-rbuilder/src/builders/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,7 @@ mod tests {
use alloy_primitives::U256;
use rand::rng;
use reth::tasks::TokioTaskExecutor;
use reth_chain_state::ExecutedBlock;
use reth_node_api::NodePrimitives;
use reth_node_api::{BuiltPayloadExecutedBlock, NodePrimitives};
use reth_optimism_payload_builder::{OpPayloadPrimitives, payload::OpPayloadBuilderAttributes};
use reth_optimism_primitives::OpPrimitives;
use reth_primitives::SealedBlock;
Expand Down Expand Up @@ -590,7 +589,7 @@ mod tests {
}

/// Returns the entire execution data for the built block, if available.
fn executed_block(&self) -> Option<ExecutedBlock<Self::Primitives>> {
fn executed_block(&self) -> Option<BuiltPayloadExecutedBlock<Self::Primitives>> {
None
}

Expand Down
9 changes: 4 additions & 5 deletions crates/builder/op-rbuilder/src/builders/standard/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ use alloy_evm::Database;
use alloy_primitives::U256;
use reth::payload::PayloadBuilderAttributes;
use reth_basic_payload_builder::{BuildOutcome, BuildOutcomeKind, MissingPayloadBehaviour};
use reth_chain_state::ExecutedBlock;
use reth_evm::{ConfigureEvm, execute::BlockBuilder};
use reth_node_api::{Block, PayloadBuilderError};
use reth_node_api::{Block, BuiltPayloadExecutedBlock, PayloadBuilderError};
use reth_optimism_consensus::{calculate_receipt_root_no_memo_optimism, isthmus};
use reth_optimism_evm::{OpEvmConfig, OpNextBlockEnvAttributes};
use reth_optimism_forks::OpHardforks;
Expand Down Expand Up @@ -586,16 +585,16 @@ impl<Txs: PayloadTxsBounds> OpBuilder<'_, Txs> {
info!(target: "payload_builder", id=%ctx.attributes().payload_id(), "sealed built block");

// create the executed block data
let executed = ExecutedBlock {
let executed = BuiltPayloadExecutedBlock {
recovered_block: Arc::new(
RecoveredBlock::<alloy_consensus::Block<OpTransactionSigned>>::new_sealed(
sealed_block.as_ref().clone(),
info.executed_senders,
),
),
execution_output: Arc::new(execution_outcome),
hashed_state: Arc::new(hashed_state),
trie_updates: Arc::new(trie_output),
hashed_state: either::Either::Left(Arc::new(hashed_state)),
trie_updates: either::Either::Left(Arc::new(trie_output)),
};

let no_tx_pool = ctx.attributes().no_tx_pool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ where
EngineCapabilities::new(OP_ENGINE_CAPABILITIES.iter().copied()),
engine_validator,
ctx.config.engine.accept_execution_requests_hash,
ctx.node.network().clone(),
);

Ok(OpEngineApiExt::new(OpEngineApi::new(inner)))
Expand Down
11 changes: 7 additions & 4 deletions crates/builder/op-rbuilder/src/primitives/telemetry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::args::TelemetryArgs;
use reth_tracing_otlp::OtlpConfig;
use tracing_subscriber::{Layer, filter::Targets};
use url::Url;

use crate::args::TelemetryArgs;

/// Setup telemetry layer with sampling and custom endpoint configuration
pub fn setup_telemetry_layer(
args: &TelemetryArgs,
Expand All @@ -19,11 +21,12 @@ pub fn setup_telemetry_layer(
}

// Create OTLP layer with custom configuration
let otlp_layer = reth_tracing_otlp::span_layer(
let otlp_layer = reth_tracing_otlp::span_layer(OtlpConfig::new(
"op-rbuilder",
&Url::parse(args.otlp_endpoint.as_ref().unwrap()).expect("Invalid OTLP endpoint"),
Url::parse(args.otlp_endpoint.as_ref().unwrap()).expect("Invalid OTLP endpoint"),
reth_tracing_otlp::OtlpProtocol::Http,
)?;
Some((args.sampling_ratio as f64) / 100.0),
)?)?;

// Create a trace filter that sends more data to OTLP but less to stdout
let trace_filter = Targets::new()
Expand Down
12 changes: 12 additions & 0 deletions crates/builder/op-rbuilder/src/tests/framework/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,18 @@ pub fn default_node_config() -> NodeConfig<OpChainSpec> {
let data_path = tempdir
.join(format!("rbuilder.{random_id}.datadir"))
.to_path_buf();

let rocksdb_path = tempdir
.join(format!("rbuilder.{random_id}.rocksdb"))
.to_path_buf();

let pprof_dumps_path = tempdir
.join(format!("rbuilder.{random_id}.pprof-dumps"))
.to_path_buf();

std::fs::create_dir_all(&data_path).expect("Failed to create temporary data directory");
std::fs::create_dir_all(&rocksdb_path).expect("Failed to create temporary rocksdb directory");
std::fs::create_dir_all(&pprof_dumps_path).expect("Failed to create temporary pprof dumps directory");

let rpc_ipc_path = tempdir
.join(format!("rbuilder.{random_id}.rpc-ipc"))
Expand All @@ -363,6 +373,8 @@ pub fn default_node_config() -> NodeConfig<OpChainSpec> {
.to_string_lossy()
.parse()
.expect("Failed to parse data dir path"),
rocksdb_path: Some(rocksdb_path),
pprof_dumps_path: Some(pprof_dumps_path),
static_files_path: None,
};

Expand Down
5 changes: 3 additions & 2 deletions crates/client/flashblocks/src/rpc/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,9 @@ where
// state hasn't been cleared yet after canonical block commit
if let Some(canonical_tx) = EthTransactions::transaction_by_hash(&self.eth_api, tx_hash)
.await?
.map(|tx| tx.into_transaction(self.eth_api.tx_resp_builder()))
.transpose()?
.map(|tx| tx.into_transaction(self.eth_api.converter()))
.transpose()
.map_err(Eth::Error::from)?
{
return Ok(Some(canonical_tx));
}
Expand Down
19 changes: 8 additions & 11 deletions crates/client/flashblocks/src/state_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use alloy_op_evm::block::receipt_builder::OpReceiptBuilder;
use alloy_primitives::B256;
use alloy_rpc_types::TransactionTrait;
use alloy_rpc_types_eth::state::StateOverride;
use op_alloy_consensus::{OpDepositReceipt, OpTxEnvelope};
use op_alloy_consensus::{OpDepositReceipt, OpReceipt, OpTxEnvelope};
use op_alloy_rpc_types::{OpTransactionReceipt, Transaction};
use reth::revm::{Database, DatabaseCommit, context::result::ResultAndState, state::EvmState};
use reth_evm::{
Expand Down Expand Up @@ -131,11 +131,9 @@ where
effective_gas_price: u128,
) -> Result<ExecutedPendingTransaction, StateProcessorError> {
let (deposit_receipt_version, deposit_nonce) = if transaction.is_deposit() {
let deposit_receipt = receipt
.inner
.inner
.as_deposit_receipt()
.ok_or(ExecutionError::DepositReceiptMismatch)?;
let OpReceipt::Deposit(deposit_receipt) = &receipt.inner.inner.receipt else {
return Err(ExecutionError::DepositReceiptMismatch.into());
};

(deposit_receipt.deposit_receipt_version, deposit_receipt.deposit_nonce)
} else {
Expand Down Expand Up @@ -261,11 +259,10 @@ where
self.next_log_index += receipt.logs().len();

let (deposit_receipt_version, deposit_nonce) = if transaction.is_deposit() {
let deposit_receipt = op_receipt
.inner
.inner
.as_deposit_receipt()
.ok_or(ExecutionError::DepositReceiptMismatch)?;
let OpReceipt::Deposit(deposit_receipt) = &op_receipt.inner.inner.receipt
else {
return Err(ExecutionError::DepositReceiptMismatch.into());
};

(deposit_receipt.deposit_receipt_version, deposit_receipt.deposit_nonce)
} else {
Expand Down
17 changes: 13 additions & 4 deletions crates/client/node/src/test_utils/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ use std::sync::Arc;
use alloy_genesis::GenesisAccount;
use alloy_primitives::{U256, utils::Unit};
use base_primitives::{Account, build_test_genesis};
use reth::api::{NodeTypes, NodeTypesWithDBAdapter};
use reth::api::NodeTypesWithDBAdapter;
use reth_db::{
ClientVersion, DatabaseEnv, init_db,
mdbx::{DatabaseArguments, KILOBYTE, MEGABYTE, MaxReadTransactionDuration},
test_utils::{ERROR_DB_CREATION, TempDatabase, create_test_static_files_dir, tempdir_path},
test_utils::{
ERROR_DB_CREATION, TempDatabase, create_test_rocksdb_dir, create_test_static_files_dir,
tempdir_path,
},
};
use reth_optimism_chainspec::OpChainSpec;
use reth_provider::{ProviderFactory, providers::StaticFileProvider};
use reth_provider::{
ProviderFactory,
providers::{ProviderNodeTypes, RocksDBProvider, StaticFileProvider},
};

use crate::test_utils::{GENESIS_GAS_LIMIT, TEST_ACCOUNT_BALANCE_ETH};

Expand All @@ -36,16 +42,19 @@ pub fn load_chain_spec() -> Arc<OpChainSpec> {
}

/// Creates a provider factory for tests with the given chain spec.
pub fn create_provider_factory<N: NodeTypes>(
pub fn create_provider_factory<N: ProviderNodeTypes>(
chain_spec: Arc<N::ChainSpec>,
) -> ProviderFactory<NodeTypesWithDBAdapter<N, Arc<TempDatabase<DatabaseEnv>>>> {
let (static_dir, _) = create_test_static_files_dir();
let db = create_test_db();
let (rocksdb_dir, _) = create_test_rocksdb_dir();
ProviderFactory::new(
db,
chain_spec,
StaticFileProvider::read_write(static_dir.keep()).expect("static file provider"),
RocksDBProvider::builder(rocksdb_dir.keep()).build().unwrap(),
)
.unwrap()
}

/// Creates a temporary test database.
Expand Down
4 changes: 2 additions & 2 deletions crates/shared/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ test-utils = [
"dep:alloy-contract",
"dep:alloy-eips",
"dep:alloy-genesis",
"dep:alloy-primitives",
"dep:alloy-signer",
"dep:alloy-signer-local",
"dep:alloy-sol-macro",
Expand All @@ -29,9 +30,8 @@ test-utils = [
]

[dependencies]
alloy-primitives = { workspace = true, features = ["serde"] }

# test-utils (optional)
alloy-primitives = { workspace = true, features = ["serde"], optional = true }
alloy-consensus = { workspace = true, features = ["std"], optional = true }
alloy-contract = { workspace = true, optional = true }
alloy-eips = { workspace = true, optional = true }
Expand Down
Loading