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
3,117 changes: 2,032 additions & 1,085 deletions Cargo.lock

Large diffs are not rendered by default.

231 changes: 114 additions & 117 deletions Cargo.toml

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions crates/builder/op-rbuilder/src/flashblocks/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,7 @@ mod tests {
use alloy_eips::eip7685::Requests;
use alloy_primitives::U256;
use rand::rng;
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 @@ -568,7 +567,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
13 changes: 6 additions & 7 deletions crates/builder/op-rbuilder/src/flashblocks/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ use alloy_primitives::{Address, B256, U256, map::foldhash::HashMap};
use base_flashtypes::{
ExecutionPayloadBaseV1, ExecutionPayloadFlashblockDeltaV1, FlashblocksPayloadV1,
};
use either::Either;
use eyre::WrapErr as _;
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 @@ -244,7 +243,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 Down Expand Up @@ -871,11 +870,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::Left(Arc::new(hashed_state)),
trie_updates: Either::Left(Arc::new(trie_output)),
};
debug!(target: "payload_builder", message = "Executed block created");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,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
7 changes: 5 additions & 2 deletions crates/builder/op-rbuilder/src/primitives/telemetry.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use base_builder_cli::TelemetryArgs;
use reth_tracing_otlp::OtlpConfig;
use tracing_subscriber::{Layer, filter::Targets};
use url::Url;

Expand All @@ -19,11 +20,13 @@ pub fn setup_telemetry_layer(
}

// Create OTLP layer with custom configuration
let otlp_layer = reth_tracing_otlp::span_layer(
let otlp_config = 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),
)?;
let otlp_layer = reth_tracing_otlp::span_layer(otlp_config)?;

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

let data_path = tempdir.join(format!("rbuilder.{random_id}.datadir"));
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 @@ -278,6 +284,8 @@ pub fn default_node_config() -> NodeConfig<OpChainSpec> {
let datadir = DatadirArgs {
datadir: data_path.to_string_lossy().parse().expect("Failed to parse data dir path"),
static_files_path: None,
rocksdb_path: Some(rocksdb_path),
pprof_dumps_path: Some(pprof_dumps_path),
};

NodeConfig::<OpChainSpec>::new(chain_spec())
Expand Down
50 changes: 36 additions & 14 deletions crates/client/engine/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::{fmt::Debug, sync::Arc};

use reth_chainspec::EthChainSpec;
use reth_consensus::{ConsensusError, FullConsensus};
use reth_consensus::FullConsensus;
use reth_engine_primitives::{ConfigureEngineEvm, InvalidBlockHook, PayloadValidator};
use reth_engine_tree::tree::{
BasicEngineValidator, EngineValidator,
Expand All @@ -20,10 +20,10 @@ use reth_node_builder::{
rpc::{EngineValidatorBuilder, PayloadValidatorBuilder},
};
use reth_payload_primitives::{BuiltPayload, NewPayloadError};
use reth_primitives_traits::{NodePrimitives, RecoveredBlock};
use reth_primitives_traits::{NodePrimitives, SealedBlock};
use reth_provider::{
BlockReader, DatabaseProviderFactory, HashedPostStateProvider, PruneCheckpointReader,
StageCheckpointReader, StateProviderFactory, StateReader, TrieReader,
BlockNumReader, BlockReader, ChangeSetReader, DatabaseProviderFactory, HashedPostStateProvider,
PruneCheckpointReader, StageCheckpointReader, StateProviderFactory, StateReader, TrieReader,
};
use tracing::instrument;
/// Basic implementation of [`EngineValidatorBuilder`].
Expand Down Expand Up @@ -104,8 +104,15 @@ impl<N, P, Evm, V> BaseEngineValidator<P, Evm, V>
where
N: NodePrimitives,
P: DatabaseProviderFactory<
Provider: BlockReader + TrieReader + StageCheckpointReader + PruneCheckpointReader,
Provider: BlockReader
+ TrieReader
+ StageCheckpointReader
+ PruneCheckpointReader
+ ChangeSetReader
+ BlockNumReader,
> + BlockReader<Header = N::BlockHeader>
+ ChangeSetReader
+ BlockNumReader
+ StateProviderFactory
+ StateReader
+ HashedPostStateProvider
Expand All @@ -117,7 +124,7 @@ where
#[allow(clippy::too_many_arguments)]
pub fn new(
provider: P,
consensus: Arc<dyn FullConsensus<N, Error = ConsensusError>>,
consensus: Arc<dyn FullConsensus<N>>,
evm_config: Evm,
validator: V,
config: TreeConfig,
Expand Down Expand Up @@ -167,10 +174,17 @@ where
impl<N, Types, P, Evm, V> EngineValidator<Types> for BaseEngineValidator<P, Evm, V>
where
P: DatabaseProviderFactory<
Provider: BlockReader + TrieReader + StageCheckpointReader + PruneCheckpointReader,
Provider: BlockReader
+ TrieReader
+ StageCheckpointReader
+ PruneCheckpointReader
+ ChangeSetReader
+ BlockNumReader,
> + BlockReader<Header = N::BlockHeader>
+ StateProviderFactory
+ StateReader
+ ChangeSetReader
+ BlockNumReader
+ HashedPostStateProvider
+ Clone
+ 'static,
Expand All @@ -187,12 +201,11 @@ where
self.inner.validate_payload_attributes_against_header(attr, header)
}

fn ensure_well_formed_payload(
&self,
payload: Types::ExecutionData,
) -> Result<RecoveredBlock<N::Block>, NewPayloadError> {
let block = self.inner.ensure_well_formed_payload(payload)?;
Ok(block)
fn convert_payload_to_block(
&self,
payload: <Types as PayloadTypes>::ExecutionData,
) -> Result<reth_primitives_traits::SealedBlock<<<<Types as PayloadTypes>::BuiltPayload as BuiltPayload>::Primitives as NodePrimitives>::Block>, NewPayloadError>{
self.inner.convert_payload_to_block(payload)
}

fn validate_payload(
Expand All @@ -205,9 +218,18 @@ where

fn validate_block(
&mut self,
block: RecoveredBlock<N::Block>,
block: SealedBlock<N::Block>,
ctx: TreeCtx<'_, N>,
) -> ValidationOutcome<N> {
self.validate_block_with_state(BlockOrPayload::Block(block), ctx)
}

fn on_inserted_executed_block(
&self,
block: reth_chain_state::ExecutedBlock<
<<Types as PayloadTypes>::BuiltPayload as BuiltPayload>::Primitives,
>,
) {
self.inner.on_inserted_executed_block(block)
}
}
4 changes: 2 additions & 2 deletions crates/client/flashblocks/src/receipt_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,15 @@ mod tests {

#[test]
fn test_op_receipt_legacy_variant() {
let receipt =
let receipt: Receipt<Log> =
Receipt { status: Eip658Value::Eip658(true), cumulative_gas_used: 21000, logs: vec![] };
let op_receipt = OpReceipt::Legacy(receipt);
assert!(matches!(op_receipt, OpReceipt::Legacy(_)));
}

#[test]
fn test_op_receipt_deposit_variant() {
let receipt =
let receipt: Receipt<Log> =
Receipt { status: Eip658Value::Eip658(true), cumulative_gas_used: 21000, logs: vec![] };
let op_receipt = OpReceipt::Deposit(OpDepositReceipt {
inner: receipt,
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 @@ -252,8 +252,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 @@ -7,7 +7,7 @@ use alloy_consensus::{
use alloy_primitives::B256;
use alloy_rpc_types::TransactionTrait;
use alloy_rpc_types_eth::state::StateOverride;
use op_alloy_consensus::OpTxEnvelope;
use op_alloy_consensus::{OpReceipt, OpTxEnvelope};
use op_alloy_rpc_types::{OpTransactionReceipt, Transaction};
use reth_evm::{Evm, FromRecoveredTx, op_revm::L1BlockInfo};
use reth_optimism_chainspec::OpHardforks;
Expand Down Expand Up @@ -124,11 +124,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 @@ -227,11 +225,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 @@ -8,11 +8,17 @@ use base_primitives::{Account, build_test_genesis};
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_node_builder::{NodeTypes, NodeTypesWithDBAdapter};
use reth_node_builder::NodeTypesWithDBAdapter;
use reth_optimism_chainspec::OpChainSpec;
use reth_provider::{ProviderFactory, providers::StaticFileProvider};
use reth_provider::{
ProviderFactory,
providers::{NodeTypesForProvider, RocksDBBuilder, 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: NodeTypesForProvider>(
chain_spec: Arc<N::ChainSpec>,
) -> ProviderFactory<NodeTypesWithDBAdapter<N, Arc<TempDatabase<DatabaseEnv>>>> {
let (static_dir, _) = create_test_static_files_dir();
let (rocksdb_dir, _) = create_test_rocksdb_dir();
let db = create_test_db();
ProviderFactory::new(
db,
chain_spec,
StaticFileProvider::read_write(static_dir.keep()).expect("static file provider"),
RocksDBBuilder::new(&rocksdb_dir).with_default_tables().build().expect("rocks db provider"),
)
.expect("create provider factory")
}

/// Creates a temporary test database.
Expand Down
6 changes: 3 additions & 3 deletions crates/shared/access-lists/src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alloy_eip7928::{
AccountChanges, BalanceChange, CodeChange, NonceChange, SlotChanges, StorageChange,
};
use alloy_primitives::{Address, U256};
use alloy_primitives::{Address, B256, U256};
use revm::{
primitives::{HashMap, HashSet},
state::Bytecode,
Expand Down Expand Up @@ -45,9 +45,9 @@ impl FlashblockAccessListBuilder {
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct AccountChangesBuilder {
/// Mapping from Storage Slot -> (Transaction Index -> New Value)
pub storage_changes: HashMap<U256, HashMap<u64, U256>>,
pub storage_changes: HashMap<B256, HashMap<u64, B256>>,
/// Set of storage slots
pub storage_reads: HashSet<U256>,
pub storage_reads: HashSet<B256>,
/// Mapping from Transaction Index -> New Balance
pub balance_changes: HashMap<u64, U256>,
/// Mapping from Transaction Index -> New Nonce
Expand Down
14 changes: 5 additions & 9 deletions crates/shared/access-lists/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ where
if prev != new {
account_changes
.storage_changes
.entry(*slot)
.entry(B256::from(*slot))
.or_default()
.insert(self.index, new);
.insert(self.index, new.into());
}
}
}
Expand Down Expand Up @@ -144,14 +144,10 @@ where
self.db.code_by_hash(code_hash)
}

fn storage(
&mut self,
address: Address,
index: StorageKey,
) -> Result<StorageValue, Self::Error> {
fn storage(&mut self, address: Address, key: StorageKey) -> Result<StorageValue, Self::Error> {
let account = self.access_list.changes.entry(address).or_default();
account.storage_reads.insert(index);
self.db.storage(address, index)
account.storage_reads.insert(B256::from(key));
self.db.storage(address, key)
}

fn block_hash(&mut self, number: u64) -> Result<B256, Self::Error> {
Expand Down
8 changes: 6 additions & 2 deletions crates/shared/access-lists/tests/builder/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ fn test_create_and_immediate_call() {

// Verify the storage slot is 0 and value is 42
let storage_change = &deployed_changes.storage_changes[0];
assert_eq!(storage_change.slot, U256::ZERO, "Storage slot should be 0");
assert_eq!(storage_change.changes[0].new_value, U256::from(42), "Storage value should be 42");
assert_eq!(storage_change.slot, B256::ZERO, "Storage slot should be 0");
assert_eq!(
storage_change.changes[0].new_value,
B256::from(U256::from(42)),
"Storage value should be 42"
);
}
Loading
Loading