From 1c9ef8c5a38115eabc383bbcbc7dde96a7fd9069 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Sat, 1 Feb 2025 01:59:31 +0400 Subject: [PATCH] refactor: remove `Receipts` struct (#14130) --- Cargo.lock | 2 - crates/chain-state/src/in_memory.rs | 16 +- crates/chain-state/src/notifications.rs | 8 +- crates/chain-state/src/test_utils.rs | 17 +-- crates/engine/local/Cargo.toml | 2 +- crates/engine/util/src/reorg.rs | 6 +- crates/ethereum/payload/src/lib.rs | 2 +- crates/ethereum/primitives/src/receipt.rs | 2 +- crates/evm/execution-types/src/chain.rs | 9 +- .../execution-types/src/execution_outcome.rs | 141 ++++++++---------- crates/evm/src/test_utils.rs | 4 +- crates/exex/exex/src/backfill/test_utils.rs | 2 +- .../downloaders/src/receipt_file_client.rs | 8 +- crates/net/network-api/Cargo.toml | 2 +- .../cli/src/commands/import_receipts.rs | 10 +- crates/optimism/consensus/src/proof.rs | 2 +- crates/optimism/evm/src/lib.rs | 100 +++++-------- crates/optimism/payload/src/builder.rs | 2 +- crates/optimism/rpc/src/eth/pending_block.rs | 7 +- crates/primitives/Cargo.toml | 14 +- crates/primitives/src/lib.rs | 4 +- crates/primitives/src/receipt.rs | 64 -------- crates/revm/src/batch.rs | 9 +- .../rpc/rpc/src/eth/helpers/pending_block.rs | 3 +- crates/storage/db-common/src/init.rs | 4 +- .../src/providers/blockchain_provider.rs | 2 +- .../provider/src/providers/consistent.rs | 2 +- .../src/providers/database/provider.rs | 2 +- .../storage/provider/src/test_utils/blocks.rs | 15 +- crates/storage/provider/src/writer/mod.rs | 21 ++- crates/trie/sparse/src/trie.rs | 2 +- testing/testing-utils/Cargo.toml | 2 +- 32 files changed, 179 insertions(+), 307 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7c515f03f..2e406c1b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8554,7 +8554,6 @@ dependencies = [ "arbitrary", "c-kzg", "codspeed-criterion-compat", - "derive_more", "once_cell", "pprof", "proptest", @@ -8564,7 +8563,6 @@ dependencies = [ "reth-ethereum-primitives", "reth-primitives-traits", "reth-static-file-types", - "serde", "serde_json", ] diff --git a/crates/chain-state/src/in_memory.rs b/crates/chain-state/src/in_memory.rs index f4f0094f0..44b0cfaed 100644 --- a/crates/chain-state/src/in_memory.rs +++ b/crates/chain-state/src/in_memory.rs @@ -11,9 +11,7 @@ use parking_lot::RwLock; use reth_chainspec::ChainInfo; use reth_execution_types::{Chain, ExecutionOutcome}; use reth_metrics::{metrics::Gauge, Metrics}; -use reth_primitives::{ - EthPrimitives, NodePrimitives, Receipts, RecoveredBlock, SealedBlock, SealedHeader, -}; +use reth_primitives::{EthPrimitives, NodePrimitives, RecoveredBlock, SealedBlock, SealedHeader}; use reth_primitives_traits::{BlockBody as _, SignedTransaction}; use reth_storage_api::StateProviderBox; use reth_trie::{updates::TrieUpdates, HashedPostState}; @@ -648,7 +646,7 @@ impl BlockState { } /// Returns the `Receipts` of executed block that determines the state. - pub fn receipts(&self) -> &Receipts { + pub fn receipts(&self) -> &Vec> { &self.block.execution_outcome().receipts } @@ -660,12 +658,12 @@ impl BlockState { let receipts = self.receipts(); debug_assert!( - receipts.receipt_vec.len() <= 1, + receipts.len() <= 1, "Expected at most one block's worth of receipts, found {}", - receipts.receipt_vec.len() + receipts.len() ); - receipts.receipt_vec.first().cloned().unwrap_or_default() + receipts.first().cloned().unwrap_or_default() } /// Returns a vector of __parent__ `BlockStates`. @@ -1244,7 +1242,7 @@ mod tests { #[test] fn test_state_receipts() { - let receipts = Receipts { receipt_vec: vec![vec![Receipt::default()]] }; + let receipts = vec![vec![Receipt::default()]]; let mut test_block_builder: TestBlockBuilder = TestBlockBuilder::default(); let block = test_block_builder.get_executed_block_with_receipts(receipts.clone(), B256::random()); @@ -1532,7 +1530,7 @@ mod tests { test_block_builder.get_executed_block_with_number(2, block1.recovered_block.hash()); let sample_execution_outcome = ExecutionOutcome { - receipts: Receipts::from_iter([vec![], vec![]]), + receipts: vec![vec![], vec![]], requests: vec![Requests::default(), Requests::default()], ..Default::default() }; diff --git a/crates/chain-state/src/notifications.rs b/crates/chain-state/src/notifications.rs index a113dd77d..5046f48ad 100644 --- a/crates/chain-state/src/notifications.rs +++ b/crates/chain-state/src/notifications.rs @@ -217,7 +217,7 @@ mod tests { use alloy_consensus::BlockBody; use alloy_primitives::{b256, B256}; use reth_execution_types::ExecutionOutcome; - use reth_primitives::{Receipt, Receipts, SealedBlock, TransactionSigned, TxType}; + use reth_primitives::{Receipt, SealedBlock, TransactionSigned, TxType}; #[test] fn test_commit_notification() { @@ -334,7 +334,7 @@ mod tests { }; // Wrap the receipt in a `Receipts` structure, as expected in the `ExecutionOutcome`. - let receipts = Receipts { receipt_vec: vec![vec![receipt1.clone()]] }; + let receipts = vec![vec![receipt1.clone()]]; // Define an `ExecutionOutcome` with the created receipts. let execution_outcome = ExecutionOutcome { receipts, ..Default::default() }; @@ -393,7 +393,7 @@ mod tests { success: false, ..Default::default() }; - let old_receipts = Receipts { receipt_vec: vec![vec![old_receipt.clone()]] }; + let old_receipts = vec![vec![old_receipt.clone()]]; let old_execution_outcome = ExecutionOutcome { receipts: old_receipts, ..Default::default() }; @@ -424,7 +424,7 @@ mod tests { success: true, ..Default::default() }; - let new_receipts = Receipts { receipt_vec: vec![vec![new_receipt.clone()]] }; + let new_receipts = vec![vec![new_receipt.clone()]]; let new_execution_outcome = ExecutionOutcome { receipts: new_receipts, ..Default::default() }; diff --git a/crates/chain-state/src/test_utils.rs b/crates/chain-state/src/test_utils.rs index 3c519d291..368e68089 100644 --- a/crates/chain-state/src/test_utils.rs +++ b/crates/chain-state/src/test_utils.rs @@ -19,8 +19,7 @@ use reth_chainspec::{ChainSpec, EthereumHardfork, MIN_TRANSACTION_GAS}; use reth_execution_types::{Chain, ExecutionOutcome}; use reth_primitives::{ transaction::SignedTransactionIntoRecoveredExt, BlockBody, EthPrimitives, NodePrimitives, - Receipt, Receipts, Recovered, RecoveredBlock, SealedBlock, SealedHeader, Transaction, - TransactionSigned, + Receipt, Recovered, RecoveredBlock, SealedBlock, SealedHeader, Transaction, TransactionSigned, }; use reth_primitives_traits::{ proofs::{calculate_receipt_root, calculate_transaction_root, calculate_withdrawals_root}, @@ -204,11 +203,11 @@ impl TestBlockBuilder { fork } - /// Gets an [`ExecutedBlockWithTrieUpdates`] with [`BlockNumber`], [`Receipts`] and parent hash. + /// Gets an [`ExecutedBlockWithTrieUpdates`] with [`BlockNumber`], receipts and parent hash. fn get_executed_block( &mut self, block_number: BlockNumber, - receipts: Receipts, + receipts: Vec>, parent_hash: B256, ) -> ExecutedBlockWithTrieUpdates { let block_with_senders = self.generate_random_block(block_number, parent_hash); @@ -227,10 +226,10 @@ impl TestBlockBuilder { ) } - /// Generates an [`ExecutedBlockWithTrieUpdates`] that includes the given [`Receipts`]. + /// Generates an [`ExecutedBlockWithTrieUpdates`] that includes the given receipts. pub fn get_executed_block_with_receipts( &mut self, - receipts: Receipts, + receipts: Vec>, parent_hash: B256, ) -> ExecutedBlockWithTrieUpdates { let number = rand::thread_rng().gen::(); @@ -243,7 +242,7 @@ impl TestBlockBuilder { block_number: BlockNumber, parent_hash: B256, ) -> ExecutedBlockWithTrieUpdates { - self.get_executed_block(block_number, Receipts { receipt_vec: vec![vec![]] }, parent_hash) + self.get_executed_block(block_number, vec![vec![]], parent_hash) } /// Generates a range of executed blocks with ascending block numbers. @@ -296,12 +295,12 @@ impl TestBlockBuilder { let execution_outcome = ExecutionOutcome::new( bundle_state_builder.build(), - vec![vec![]].into(), + vec![vec![]], block.number, Vec::new(), ); - execution_outcome.with_receipts(Receipts::from(receipts)) + execution_outcome.with_receipts(vec![receipts]) } } diff --git a/crates/engine/local/Cargo.toml b/crates/engine/local/Cargo.toml index 0e4e546eb..bd4910cf7 100644 --- a/crates/engine/local/Cargo.toml +++ b/crates/engine/local/Cargo.toml @@ -28,7 +28,7 @@ reth-stages-api.workspace = true # alloy alloy-consensus.workspace = true -alloy-primitives.workspace = true +alloy-primitives = { workspace = true, features = ["getrandom"] } alloy-rpc-types-engine.workspace = true # async diff --git a/crates/engine/util/src/reorg.rs b/crates/engine/util/src/reorg.rs index c4423ced8..7e4a09f75 100644 --- a/crates/engine/util/src/reorg.rs +++ b/crates/engine/util/src/reorg.rs @@ -18,9 +18,7 @@ use reth_evm::{ }; use reth_payload_primitives::EngineApiMessageVersion; use reth_payload_validator::ExecutionPayloadValidator; -use reth_primitives::{ - transaction::SignedTransactionIntoRecoveredExt, Block, BlockBody, Receipt, Receipts, -}; +use reth_primitives::{transaction::SignedTransactionIntoRecoveredExt, Block, BlockBody, Receipt}; use reth_primitives_traits::{block::Block as _, proofs, SignedTransaction}; use reth_provider::{BlockReader, ExecutionOutcome, ProviderError, StateProviderFactory}; use reth_revm::{ @@ -373,7 +371,7 @@ where let outcome: ExecutionOutcome = ExecutionOutcome::new( state.take_bundle(), - Receipts::from(vec![receipts]), + vec![receipts], reorg_target.number, Default::default(), ); diff --git a/crates/ethereum/payload/src/lib.rs b/crates/ethereum/payload/src/lib.rs index 814e06651..916426118 100644 --- a/crates/ethereum/payload/src/lib.rs +++ b/crates/ethereum/payload/src/lib.rs @@ -380,7 +380,7 @@ where let requests_hash = requests.as_ref().map(|requests| requests.requests_hash()); let execution_outcome = ExecutionOutcome::new( db.take_bundle(), - vec![receipts].into(), + vec![receipts], block_number, vec![requests.clone().unwrap_or_default()], ); diff --git a/crates/ethereum/primitives/src/receipt.rs b/crates/ethereum/primitives/src/receipt.rs index 23e80064e..2fec1bf85 100644 --- a/crates/ethereum/primitives/src/receipt.rs +++ b/crates/ethereum/primitives/src/receipt.rs @@ -85,7 +85,7 @@ impl Receipt { /// Calculates the receipt root for a header for the reference type of [Receipt]. /// /// NOTE: Prefer `proofs::calculate_receipt_root` if you have log blooms memoized. - pub fn calculate_receipt_root_no_memo(receipts: &[&Self]) -> B256 { + pub fn calculate_receipt_root_no_memo(receipts: &[Self]) -> B256 { ordered_trie_root_with_encoder(receipts, |r, buf| r.with_bloom_ref().encode_2718(buf)) } } diff --git a/crates/evm/execution-types/src/chain.rs b/crates/evm/execution-types/src/chain.rs index c8e66dff7..948ccc47c 100644 --- a/crates/evm/execution-types/src/chain.rs +++ b/crates/evm/execution-types/src/chain.rs @@ -703,7 +703,6 @@ mod tests { use alloy_consensus::TxType; use alloy_primitives::{Address, B256}; use reth_ethereum_primitives::Receipt; - use reth_primitives::Receipts; use revm::primitives::{AccountInfo, HashMap}; // TODO: this is temporary, until we fully switch over to `reth_ethereum_primitives` for the @@ -765,7 +764,7 @@ mod tests { vec![vec![(Address::new([2; 20]), None, vec![])]], vec![], ), - vec![vec![]].into(), + vec![vec![]], 1, vec![], ); @@ -781,7 +780,7 @@ mod tests { vec![vec![(Address::new([3; 20]), None, vec![])]], vec![], ), - vec![vec![]].into(), + vec![vec![]], 2, vec![], ); @@ -884,7 +883,7 @@ mod tests { }; // Create a Receipts object with a vector of receipt vectors - let receipts = Receipts { receipt_vec: vec![vec![receipt1.clone()], vec![receipt2]] }; + let receipts = vec![vec![receipt1.clone()], vec![receipt2]]; // Create an ExecutionOutcome object with the created bundle, receipts, an empty requests // vector, and first_block set to 10 @@ -909,7 +908,7 @@ mod tests { // Create an ExecutionOutcome object with a single receipt vector containing receipt1 let execution_outcome1 = ExecutionOutcome { bundle: Default::default(), - receipts: Receipts { receipt_vec: vec![vec![receipt1]] }, + receipts: vec![vec![receipt1]], requests: vec![], first_block: 10, }; diff --git a/crates/evm/execution-types/src/execution_outcome.rs b/crates/evm/execution-types/src/execution_outcome.rs index 64d128c96..1f579e3fd 100644 --- a/crates/evm/execution-types/src/execution_outcome.rs +++ b/crates/evm/execution-types/src/execution_outcome.rs @@ -2,7 +2,6 @@ use crate::BlockExecutionOutput; use alloc::{vec, vec::Vec}; use alloy_eips::eip7685::Requests; use alloy_primitives::{logs_bloom, map::HashMap, Address, BlockNumber, Bloom, Log, B256, U256}; -use reth_primitives::Receipts; use reth_primitives_traits::{Account, Bytecode, Receipt, StorageEntry}; use reth_trie::{HashedPostState, KeyHasher}; use revm::{ @@ -40,9 +39,7 @@ pub struct ExecutionOutcome { /// The collection of receipts. /// Outer vector stores receipts for each block sequentially. /// The inner vector stores receipts ordered by transaction number. - /// - /// If receipt is None it means it is pruned. - pub receipts: Receipts, + pub receipts: Vec>, /// First block of bundle state. pub first_block: BlockNumber, /// The collection of EIP-7685 requests. @@ -82,7 +79,7 @@ impl ExecutionOutcome { /// bundle state, receipts, first block number, and EIP-7685 requests. pub const fn new( bundle: BundleState, - receipts: Receipts, + receipts: Vec>, first_block: BlockNumber, requests: Vec, ) -> Self { @@ -97,7 +94,7 @@ impl ExecutionOutcome { state_init: BundleStateInit, revert_init: RevertsInit, contracts_init: impl IntoIterator, - receipts: Receipts, + receipts: Vec>, first_block: BlockNumber, requests: Vec, ) -> Self { @@ -197,18 +194,18 @@ impl ExecutionOutcome { pub fn generic_receipts_root_slow( &self, block_number: BlockNumber, - f: impl FnOnce(&[&T]) -> B256, + f: impl FnOnce(&[T]) -> B256, ) -> Option { - Some(self.receipts.root_slow(self.block_number_to_index(block_number)?, f)) + Some(f(self.receipts.get(self.block_number_to_index(block_number)?)?)) } /// Returns reference to receipts. - pub const fn receipts(&self) -> &Receipts { + pub const fn receipts(&self) -> &Vec> { &self.receipts } /// Returns mutable reference to receipts. - pub fn receipts_mut(&mut self) -> &mut Receipts { + pub fn receipts_mut(&mut self) -> &mut Vec> { &mut self.receipts } @@ -285,7 +282,7 @@ impl ExecutionOutcome { // Truncate higher state to [at..]. let at_idx = higher_state.block_number_to_index(at).unwrap(); - higher_state.receipts = higher_state.receipts.split_off(at_idx).into(); + higher_state.receipts = higher_state.receipts.split_off(at_idx); // Ensure that there are enough requests to truncate. // Sometimes we just have receipts and no requests. if at_idx < higher_state.requests.len() { @@ -304,7 +301,7 @@ impl ExecutionOutcome { /// In most cases this would be true. pub fn extend(&mut self, other: Self) { self.bundle.extend(other.bundle); - self.receipts.extend(other.receipts.receipt_vec); + self.receipts.extend(other.receipts); self.requests.extend(other.requests); } @@ -325,7 +322,7 @@ impl ExecutionOutcome { } /// Create a new instance with updated receipts. - pub fn with_receipts(mut self, receipts: Receipts) -> Self { + pub fn with_receipts(mut self, receipts: Vec>) -> Self { self.receipts = receipts; self } @@ -366,10 +363,11 @@ impl ExecutionOutcome { /// /// Note: this function calculated Bloom filters for every receipt and created merkle trees /// of receipt. This is a expensive operation. - pub fn ethereum_receipts_root(&self, _block_number: BlockNumber) -> Option { - Some(self.receipts.root_slow(self.block_number_to_index(_block_number)?, |receipts| { - reth_primitives::Receipt::calculate_receipt_root_no_memo(receipts) - })) + pub fn ethereum_receipts_root(&self, block_number: BlockNumber) -> Option { + self.generic_receipts_root_slow( + block_number, + reth_primitives::Receipt::calculate_receipt_root_no_memo, + ) } } @@ -377,7 +375,7 @@ impl From<(BlockExecutionOutput, BlockNumber)> for ExecutionOutcome { fn from(value: (BlockExecutionOutput, BlockNumber)) -> Self { Self { bundle: value.0.state, - receipts: Receipts::from(value.0.receipts), + receipts: vec![value.0.receipts], first_block: value.1, requests: vec![value.0.requests], } @@ -389,7 +387,6 @@ mod tests { use super::*; use alloy_consensus::TxType; use alloy_primitives::{bytes, Address, LogData, B256}; - use reth_primitives::Receipts; #[test] fn test_initialisation() { @@ -401,14 +398,12 @@ mod tests { ); // Create a Receipts object with a vector of receipt vectors - let receipts = Receipts { - receipt_vec: vec![vec![Some(reth_ethereum_primitives::Receipt { - tx_type: TxType::Legacy, - cumulative_gas_used: 46913, - logs: vec![], - success: true, - })]], - }; + let receipts = vec![vec![Some(reth_ethereum_primitives::Receipt { + tx_type: TxType::Legacy, + cumulative_gas_used: 46913, + logs: vec![], + success: true, + })]]; // Create a Requests object with a vector of requests let requests = vec![Requests::new(vec![bytes!("dead"), bytes!("beef"), bytes!("beebee")])]; @@ -462,14 +457,12 @@ mod tests { #[test] fn test_block_number_to_index() { // Create a Receipts object with a vector of receipt vectors - let receipts = Receipts { - receipt_vec: vec![vec![Some(reth_ethereum_primitives::Receipt { - tx_type: TxType::Legacy, - cumulative_gas_used: 46913, - logs: vec![], - success: true, - })]], - }; + let receipts = vec![vec![Some(reth_ethereum_primitives::Receipt { + tx_type: TxType::Legacy, + cumulative_gas_used: 46913, + logs: vec![], + success: true, + })]]; // Define the first block number let first_block = 123; @@ -496,14 +489,12 @@ mod tests { #[test] fn test_get_logs() { // Create a Receipts object with a vector of receipt vectors - let receipts = Receipts { - receipt_vec: vec![vec![reth_ethereum_primitives::Receipt { - tx_type: TxType::Legacy, - cumulative_gas_used: 46913, - logs: vec![Log::::default()], - success: true, - }]], - }; + let receipts = vec![vec![reth_ethereum_primitives::Receipt { + tx_type: TxType::Legacy, + cumulative_gas_used: 46913, + logs: vec![Log::::default()], + success: true, + }]]; // Define the first block number let first_block = 123; @@ -527,14 +518,12 @@ mod tests { #[test] fn test_receipts_by_block() { // Create a Receipts object with a vector of receipt vectors - let receipts = Receipts { - receipt_vec: vec![vec![Some(reth_ethereum_primitives::Receipt { - tx_type: TxType::Legacy, - cumulative_gas_used: 46913, - logs: vec![Log::::default()], - success: true, - })]], - }; + let receipts = vec![vec![Some(reth_ethereum_primitives::Receipt { + tx_type: TxType::Legacy, + cumulative_gas_used: 46913, + logs: vec![Log::::default()], + success: true, + })]]; // Define the first block number let first_block = 123; @@ -566,17 +555,15 @@ mod tests { #[test] fn test_receipts_len() { // Create a Receipts object with a vector of receipt vectors - let receipts = Receipts { - receipt_vec: vec![vec![Some(reth_ethereum_primitives::Receipt { - tx_type: TxType::Legacy, - cumulative_gas_used: 46913, - logs: vec![Log::::default()], - success: true, - })]], - }; + let receipts = vec![vec![Some(reth_ethereum_primitives::Receipt { + tx_type: TxType::Legacy, + cumulative_gas_used: 46913, + logs: vec![Log::::default()], + success: true, + })]]; // Create an empty Receipts object - let receipts_empty: Receipts = Receipts { receipt_vec: vec![] }; + let receipts_empty = vec![]; // Define the first block number let first_block = 123; @@ -597,7 +584,7 @@ mod tests { assert!(!exec_res.is_empty()); // Create a ExecutionOutcome object with an empty Receipts object - let exec_res_empty_receipts = ExecutionOutcome { + let exec_res_empty_receipts: ExecutionOutcome = ExecutionOutcome { bundle: Default::default(), // Default value for bundle receipts: receipts_empty, // Include the empty receipts requests: vec![], // Empty vector for requests @@ -622,9 +609,7 @@ mod tests { }; // Create a Receipts object with a vector of receipt vectors - let receipts = Receipts { - receipt_vec: vec![vec![Some(receipt.clone())], vec![Some(receipt.clone())]], - }; + let receipts = vec![vec![Some(receipt.clone())], vec![Some(receipt.clone())]]; // Define the first block number let first_block = 123; @@ -645,7 +630,7 @@ mod tests { assert!(exec_res.revert_to(123)); // Assert that the receipts are properly cut after reverting to the initial block number. - assert_eq!(exec_res.receipts, Receipts { receipt_vec: vec![vec![Some(receipt)]] }); + assert_eq!(exec_res.receipts, vec![vec![Some(receipt)]]); // Assert that the requests are properly cut after reverting to the initial block number. assert_eq!(exec_res.requests, vec![Requests::new(vec![request])]); @@ -670,7 +655,7 @@ mod tests { }; // Create a Receipts object containing the receipt. - let receipts = Receipts { receipt_vec: vec![vec![Some(receipt.clone())]] }; + let receipts = vec![vec![Some(receipt.clone())]]; // Create a request. let request = bytes!("deadbeef"); @@ -693,9 +678,7 @@ mod tests { exec_res, ExecutionOutcome { bundle: Default::default(), - receipts: Receipts { - receipt_vec: vec![vec![Some(receipt.clone())], vec![Some(receipt)]] - }, + receipts: vec![vec![Some(receipt.clone())], vec![Some(receipt)]], requests: vec![Requests::new(vec![request.clone()]), Requests::new(vec![request])], first_block: 123, } @@ -713,13 +696,11 @@ mod tests { }; // Create a Receipts object with a vector of receipt vectors - let receipts = Receipts { - receipt_vec: vec![ - vec![Some(receipt.clone())], - vec![Some(receipt.clone())], - vec![Some(receipt.clone())], - ], - }; + let receipts = vec![ + vec![Some(receipt.clone())], + vec![Some(receipt.clone())], + vec![Some(receipt.clone())], + ]; // Define the first block number let first_block = 123; @@ -745,7 +726,7 @@ mod tests { // Define the expected lower ExecutionOutcome after splitting let lower_execution_outcome = ExecutionOutcome { bundle: Default::default(), - receipts: Receipts { receipt_vec: vec![vec![Some(receipt.clone())]] }, + receipts: vec![vec![Some(receipt.clone())]], requests: vec![Requests::new(vec![request.clone()])], first_block, }; @@ -753,9 +734,7 @@ mod tests { // Define the expected higher ExecutionOutcome after splitting let higher_execution_outcome = ExecutionOutcome { bundle: Default::default(), - receipts: Receipts { - receipt_vec: vec![vec![Some(receipt.clone())], vec![Some(receipt)]], - }, + receipts: vec![vec![Some(receipt.clone())], vec![Some(receipt)]], requests: vec![Requests::new(vec![request.clone()]), Requests::new(vec![request])], first_block: 124, }; @@ -815,7 +794,7 @@ mod tests { let execution_outcome: ExecutionOutcome = ExecutionOutcome { bundle: bundle_state, - receipts: Receipts::default(), + receipts: Default::default(), first_block: 0, requests: vec![], }; diff --git a/crates/evm/src/test_utils.rs b/crates/evm/src/test_utils.rs index a78004d15..ad7c8bc14 100644 --- a/crates/evm/src/test_utils.rs +++ b/crates/evm/src/test_utils.rs @@ -12,7 +12,7 @@ use alloy_eips::eip7685::Requests; use parking_lot::Mutex; use reth_execution_errors::BlockExecutionError; use reth_execution_types::ExecutionOutcome; -use reth_primitives::{EthPrimitives, NodePrimitives, Receipt, Receipts, RecoveredBlock}; +use reth_primitives::{EthPrimitives, NodePrimitives, Receipt, RecoveredBlock}; use revm::State; use std::sync::Arc; @@ -153,7 +153,7 @@ where } /// Accessor for batch executor receipts. - pub const fn receipts(&self) -> &Receipts<::Receipt> { + pub const fn receipts(&self) -> &Vec::Receipt>> { self.batch_record.receipts() } } diff --git a/crates/exex/exex/src/backfill/test_utils.rs b/crates/exex/exex/src/backfill/test_utils.rs index 19527fdd6..a10a2785e 100644 --- a/crates/exex/exex/src/backfill/test_utils.rs +++ b/crates/exex/exex/src/backfill/test_utils.rs @@ -23,7 +23,7 @@ pub(crate) fn to_execution_outcome( ) -> ExecutionOutcome { ExecutionOutcome { bundle: block_execution_output.state.clone(), - receipts: block_execution_output.receipts.clone().into(), + receipts: vec![block_execution_output.receipts.clone()], first_block: block_number, requests: vec![block_execution_output.requests.clone()], } diff --git a/crates/net/downloaders/src/receipt_file_client.rs b/crates/net/downloaders/src/receipt_file_client.rs index 8aace21ef..beca2f46b 100644 --- a/crates/net/downloaders/src/receipt_file_client.rs +++ b/crates/net/downloaders/src/receipt_file_client.rs @@ -1,7 +1,7 @@ use std::{fmt, io}; use futures::Future; -use reth_primitives::{Receipt, Receipts}; +use reth_primitives::Receipt; use tokio::io::AsyncReadExt; use tokio_stream::StreamExt; use tokio_util::codec::{Decoder, FramedRead}; @@ -27,10 +27,10 @@ where #[derive(Debug)] pub struct ReceiptFileClient { /// The buffered receipts, read from file, as nested lists. One list per block number. - pub receipts: Receipts, + pub receipts: Vec>, /// First (lowest) block number read from file. pub first_block: u64, - /// Total number of receipts. Count of elements in [`Receipts`] flattened. + /// Total number of receipts. Count of elements in receipts flattened. pub total_receipts: usize, } @@ -66,7 +66,7 @@ where where B: AsyncReadExt + Unpin, { - let mut receipts = Receipts::default(); + let mut receipts = Vec::default(); // use with_capacity to make sure the internal buffer contains the entire chunk let mut stream = FramedRead::with_capacity(reader, D::default(), num_bytes as usize); diff --git a/crates/net/network-api/Cargo.toml b/crates/net/network-api/Cargo.toml index 46f8cf94d..bca2025a3 100644 --- a/crates/net/network-api/Cargo.toml +++ b/crates/net/network-api/Cargo.toml @@ -22,7 +22,7 @@ reth-tokio-util.workspace = true reth-ethereum-forks.workspace = true # ethereum -alloy-primitives.workspace = true +alloy-primitives = { workspace = true, features = ["getrandom"] } # eth enr = { workspace = true, default-features = false, features = ["rust-secp256k1"] } diff --git a/crates/optimism/cli/src/commands/import_receipts.rs b/crates/optimism/cli/src/commands/import_receipts.rs index e6235de92..6aaa604d0 100644 --- a/crates/optimism/cli/src/commands/import_receipts.rs +++ b/crates/optimism/cli/src/commands/import_receipts.rs @@ -16,7 +16,7 @@ use reth_node_builder::ReceiptTy; use reth_node_core::version::SHORT_VERSION; use reth_optimism_chainspec::OpChainSpec; use reth_optimism_primitives::{bedrock::is_dup_tx, OpPrimitives, OpReceipt}; -use reth_primitives::{NodePrimitives, Receipts}; +use reth_primitives::NodePrimitives; use reth_provider::{ providers::ProviderNodeTypes, writer::UnifiedStorageWriter, DatabaseProviderFactory, OriginalValuesKnown, ProviderFactory, StageCheckpointReader, StageCheckpointWriter, @@ -90,7 +90,7 @@ pub async fn import_receipts_from_file( where N: ProviderNodeTypes>, P: AsRef, - F: FnMut(u64, &mut Receipts) -> usize, + F: FnMut(u64, &mut Vec>) -> usize, { for stage in StageId::ALL { let checkpoint = provider_factory.database_provider_ro()?.get_stage_checkpoint(stage)?; @@ -119,7 +119,7 @@ where /// /// Caution! Filter callback must replace completely filtered out receipts for a block, with empty /// vectors, rather than `vec!(None)`. This is since the code for writing to static files, expects -/// indices in the [`Receipts`] list, to map to sequential block numbers. +/// indices in the receipts list, to map to sequential block numbers. pub async fn import_receipts_from_reader( provider_factory: &ProviderFactory, mut reader: ChunkedFileReader, @@ -127,7 +127,7 @@ pub async fn import_receipts_from_reader( ) -> eyre::Result where N: ProviderNodeTypes>, - F: FnMut(u64, &mut Receipts>) -> usize, + F: FnMut(u64, &mut Vec>>) -> usize, { let static_file_provider = provider_factory.static_file_provider(); @@ -207,7 +207,7 @@ where highest_block_receipts -= excess; // Remove the last `excess` blocks - receipts.receipt_vec.truncate(receipts.len() - excess as usize); + receipts.truncate(receipts.len() - excess as usize); warn!(target: "reth::cli", highest_block_receipts, "Too many decoded blocks, ignoring the last {excess}."); } diff --git a/crates/optimism/consensus/src/proof.rs b/crates/optimism/consensus/src/proof.rs index 439edf0d3..0b1e6c74f 100644 --- a/crates/optimism/consensus/src/proof.rs +++ b/crates/optimism/consensus/src/proof.rs @@ -45,7 +45,7 @@ pub(crate) fn calculate_receipt_root_optimism( /// /// NOTE: Prefer calculate receipt root optimism if you have log blooms memoized. pub fn calculate_receipt_root_no_memo_optimism( - receipts: &[&OpReceipt], + receipts: &[OpReceipt], chain_spec: impl OpHardforks, timestamp: u64, ) -> B256 { diff --git a/crates/optimism/evm/src/lib.rs b/crates/optimism/evm/src/lib.rs index 7961b1392..917f7c861 100644 --- a/crates/optimism/evm/src/lib.rs +++ b/crates/optimism/evm/src/lib.rs @@ -284,7 +284,7 @@ mod tests { }; use reth_optimism_chainspec::BASE_MAINNET; use reth_optimism_primitives::{OpBlock, OpPrimitives, OpReceipt}; - use reth_primitives::{Account, Log, Receipts, RecoveredBlock}; + use reth_primitives::{Account, Log, RecoveredBlock}; use reth_revm::{ db::{BundleState, CacheDB, EmptyDBTyped}, inspectors::NoOpInspector, @@ -533,7 +533,7 @@ mod tests { }); // Create a Receipts object with a vector of receipt vectors - let receipts = Receipts { receipt_vec: vec![vec![receipt1.clone()], vec![receipt2]] }; + let receipts = vec![vec![receipt1.clone()], vec![receipt2]]; // Create an ExecutionOutcome object with the created bundle, receipts, an empty requests // vector, and first_block set to 10 @@ -555,7 +555,7 @@ mod tests { // Create an ExecutionOutcome object with a single receipt vector containing receipt1 let execution_outcome1 = ExecutionOutcome { bundle: Default::default(), - receipts: Receipts { receipt_vec: vec![vec![receipt1]] }, + receipts: vec![vec![receipt1]], requests: vec![], first_block: 10, }; @@ -577,13 +577,11 @@ mod tests { ); // Create a Receipts object with a vector of receipt vectors - let receipts = Receipts { - receipt_vec: vec![vec![Some(OpReceipt::Legacy(Receipt { - cumulative_gas_used: 46913, - logs: vec![], - status: true.into(), - }))]], - }; + let receipts = vec![vec![Some(OpReceipt::Legacy(Receipt { + cumulative_gas_used: 46913, + logs: vec![], + status: true.into(), + }))]]; // Create a Requests object with a vector of requests let requests = vec![Requests::new(vec![bytes!("dead"), bytes!("beef"), bytes!("beebee")])]; @@ -637,13 +635,11 @@ mod tests { #[test] fn test_block_number_to_index() { // Create a Receipts object with a vector of receipt vectors - let receipts = Receipts { - receipt_vec: vec![vec![Some(OpReceipt::Legacy(Receipt { - cumulative_gas_used: 46913, - logs: vec![], - status: true.into(), - }))]], - }; + let receipts = vec![vec![Some(OpReceipt::Legacy(Receipt { + cumulative_gas_used: 46913, + logs: vec![], + status: true.into(), + }))]]; // Define the first block number let first_block = 123; @@ -670,13 +666,11 @@ mod tests { #[test] fn test_get_logs() { // Create a Receipts object with a vector of receipt vectors - let receipts = Receipts { - receipt_vec: vec![vec![OpReceipt::Legacy(Receipt { - cumulative_gas_used: 46913, - logs: vec![Log::::default()], - status: true.into(), - })]], - }; + let receipts = vec![vec![OpReceipt::Legacy(Receipt { + cumulative_gas_used: 46913, + logs: vec![Log::::default()], + status: true.into(), + })]]; // Define the first block number let first_block = 123; @@ -700,13 +694,11 @@ mod tests { #[test] fn test_receipts_by_block() { // Create a Receipts object with a vector of receipt vectors - let receipts = Receipts { - receipt_vec: vec![vec![Some(OpReceipt::Legacy(Receipt { - cumulative_gas_used: 46913, - logs: vec![Log::::default()], - status: true.into(), - }))]], - }; + let receipts = vec![vec![Some(OpReceipt::Legacy(Receipt { + cumulative_gas_used: 46913, + logs: vec![Log::::default()], + status: true.into(), + }))]]; // Define the first block number let first_block = 123; @@ -737,16 +729,14 @@ mod tests { #[test] fn test_receipts_len() { // Create a Receipts object with a vector of receipt vectors - let receipts = Receipts { - receipt_vec: vec![vec![Some(OpReceipt::Legacy(Receipt { - cumulative_gas_used: 46913, - logs: vec![Log::::default()], - status: true.into(), - }))]], - }; + let receipts = vec![vec![Some(OpReceipt::Legacy(Receipt { + cumulative_gas_used: 46913, + logs: vec![Log::::default()], + status: true.into(), + }))]]; // Create an empty Receipts object - let receipts_empty = Receipts:: { receipt_vec: vec![] }; + let receipts_empty = vec![]; // Define the first block number let first_block = 123; @@ -767,7 +757,7 @@ mod tests { assert!(!exec_res.is_empty()); // Create a ExecutionOutcome object with an empty Receipts object - let exec_res_empty_receipts = ExecutionOutcome { + let exec_res_empty_receipts: ExecutionOutcome = ExecutionOutcome { bundle: Default::default(), // Default value for bundle receipts: receipts_empty, // Include the empty receipts requests: vec![], // Empty vector for requests @@ -791,9 +781,7 @@ mod tests { }); // Create a Receipts object with a vector of receipt vectors - let receipts = Receipts { - receipt_vec: vec![vec![Some(receipt.clone())], vec![Some(receipt.clone())]], - }; + let receipts = vec![vec![Some(receipt.clone())], vec![Some(receipt.clone())]]; // Define the first block number let first_block = 123; @@ -814,7 +802,7 @@ mod tests { assert!(exec_res.revert_to(123)); // Assert that the receipts are properly cut after reverting to the initial block number. - assert_eq!(exec_res.receipts, Receipts { receipt_vec: vec![vec![Some(receipt)]] }); + assert_eq!(exec_res.receipts, vec![vec![Some(receipt)]]); // Assert that the requests are properly cut after reverting to the initial block number. assert_eq!(exec_res.requests, vec![Requests::new(vec![request])]); @@ -838,7 +826,7 @@ mod tests { }); // Create a Receipts object containing the receipt. - let receipts = Receipts { receipt_vec: vec![vec![Some(receipt.clone())]] }; + let receipts = vec![vec![Some(receipt.clone())]]; // Create a request. let request = bytes!("deadbeef"); @@ -861,9 +849,7 @@ mod tests { exec_res, ExecutionOutcome { bundle: Default::default(), - receipts: Receipts { - receipt_vec: vec![vec![Some(receipt.clone())], vec![Some(receipt)]] - }, + receipts: vec![vec![Some(receipt.clone())], vec![Some(receipt)]], requests: vec![Requests::new(vec![request.clone()]), Requests::new(vec![request])], first_block: 123, } @@ -880,13 +866,11 @@ mod tests { }); // Create a Receipts object with a vector of receipt vectors - let receipts = Receipts { - receipt_vec: vec![ - vec![Some(receipt.clone())], - vec![Some(receipt.clone())], - vec![Some(receipt.clone())], - ], - }; + let receipts = vec![ + vec![Some(receipt.clone())], + vec![Some(receipt.clone())], + vec![Some(receipt.clone())], + ]; // Define the first block number let first_block = 123; @@ -912,7 +896,7 @@ mod tests { // Define the expected lower ExecutionOutcome after splitting let lower_execution_outcome = ExecutionOutcome { bundle: Default::default(), - receipts: Receipts { receipt_vec: vec![vec![Some(receipt.clone())]] }, + receipts: vec![vec![Some(receipt.clone())]], requests: vec![Requests::new(vec![request.clone()])], first_block, }; @@ -920,9 +904,7 @@ mod tests { // Define the expected higher ExecutionOutcome after splitting let higher_execution_outcome = ExecutionOutcome { bundle: Default::default(), - receipts: Receipts { - receipt_vec: vec![vec![Some(receipt.clone())], vec![Some(receipt)]], - }, + receipts: vec![vec![Some(receipt.clone())], vec![Some(receipt)]], requests: vec![Requests::new(vec![request.clone()]), Requests::new(vec![request])], first_block: 124, }; diff --git a/crates/optimism/payload/src/builder.rs b/crates/optimism/payload/src/builder.rs index 15a350190..4d6868c87 100644 --- a/crates/optimism/payload/src/builder.rs +++ b/crates/optimism/payload/src/builder.rs @@ -359,7 +359,7 @@ where let block_number = ctx.block_number(); let execution_outcome = ExecutionOutcome::new( state.take_bundle(), - info.receipts.into(), + vec![info.receipts], block_number, Vec::new(), ); diff --git a/crates/optimism/rpc/src/eth/pending_block.rs b/crates/optimism/rpc/src/eth/pending_block.rs index 13e3d0351..9c2ece00d 100644 --- a/crates/optimism/rpc/src/eth/pending_block.rs +++ b/crates/optimism/rpc/src/eth/pending_block.rs @@ -104,11 +104,8 @@ where let timestamp = block_env.timestamp.to::(); let transactions_root = calculate_transaction_root(&transactions); - let receipts_root = calculate_receipt_root_no_memo_optimism( - &receipts.iter().collect::>(), - &chain_spec, - timestamp, - ); + let receipts_root = + calculate_receipt_root_no_memo_optimism(receipts, &chain_spec, timestamp); let logs_bloom = logs_bloom(receipts.iter().flat_map(|r| r.logs())); let is_cancun = chain_spec.is_cancun_active_at_timestamp(timestamp); diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 6be665d94..99ffd7ef7 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -20,15 +20,12 @@ reth-static-file-types.workspace = true # ethereum alloy-consensus.workspace = true -alloy-primitives = { workspace = true, features = ["rand", "rlp"] } # for eip-4844 c-kzg = { workspace = true, features = ["serde"], optional = true } # misc -derive_more.workspace = true once_cell.workspace = true -serde.workspace = true # arbitrary utils arbitrary = { workspace = true, features = ["derive"], optional = true } @@ -37,6 +34,7 @@ arbitrary = { workspace = true, features = ["derive"], optional = true } # eth reth-primitives-traits = { workspace = true, features = ["arbitrary", "test-utils"] } +alloy-primitives.workspace = true alloy-rlp.workspace = true alloy-eips = { workspace = true, features = ["arbitrary"] } alloy-genesis.workspace = true @@ -58,21 +56,21 @@ std = [ "alloy-consensus/std", "alloy-eips/std", "alloy-genesis/std", - "alloy-primitives/std", "once_cell/std", - "serde/std", "reth-ethereum-forks/std", - "derive_more/std", "serde_json/std", "reth-ethereum-primitives/std", "alloy-rlp/std", + "alloy-primitives/std", ] reth-codec = [ "std", "reth-primitives-traits/reth-codec", "reth-ethereum-primitives/reth-codec", ] -asm-keccak = ["alloy-primitives/asm-keccak"] +asm-keccak = [ + "alloy-primitives/asm-keccak", +] arbitrary = [ "dep:arbitrary", "alloy-eips/arbitrary", @@ -80,9 +78,9 @@ arbitrary = [ "reth-ethereum-forks/arbitrary", "reth-primitives-traits/arbitrary", "alloy-consensus/arbitrary", - "alloy-primitives/arbitrary", "reth-ethereum-primitives/arbitrary", "reth-codecs/arbitrary", + "alloy-primitives/arbitrary", ] secp256k1 = [ "reth-primitives-traits/secp256k1", diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 302044d6e..e4ea3edce 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -19,8 +19,6 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(feature = "std"), no_std)] -extern crate alloc; - mod block; mod receipt; pub use reth_static_file_types as static_file; @@ -31,7 +29,7 @@ pub use block::{Block, BlockBody, SealedBlock}; #[allow(deprecated)] pub use block::{BlockWithSenders, SealedBlockFor, SealedBlockWithSenders}; -pub use receipt::{gas_spent_by_transactions, Receipt, Receipts}; +pub use receipt::{gas_spent_by_transactions, Receipt}; pub use reth_primitives_traits::{ logs_bloom, Account, Bytecode, GotExpected, GotExpectedBoxed, Header, HeaderError, Log, LogData, NodePrimitives, RecoveredBlock, SealedHeader, StorageEntry, diff --git a/crates/primitives/src/receipt.rs b/crates/primitives/src/receipt.rs index b792f3877..80f4aadd7 100644 --- a/crates/primitives/src/receipt.rs +++ b/crates/primitives/src/receipt.rs @@ -1,69 +1,5 @@ -use alloc::{vec, vec::Vec}; -use alloy_primitives::B256; -use derive_more::{DerefMut, From, IntoIterator}; -use serde::{Deserialize, Serialize}; - /// Retrieves gas spent by transactions as a vector of tuples (transaction index, gas used). pub use reth_primitives_traits::receipt::gas_spent_by_transactions; /// Receipt containing result of transaction execution. pub use reth_ethereum_primitives::Receipt; - -/// A collection of receipts organized as a two-dimensional vector. -#[derive( - Clone, - Debug, - PartialEq, - Eq, - Serialize, - Deserialize, - From, - derive_more::Deref, - DerefMut, - IntoIterator, -)] -pub struct Receipts { - /// A two-dimensional vector of optional `Receipt` instances. - pub receipt_vec: Vec>, -} - -impl Receipts { - /// Returns the length of the `Receipts` vector. - pub fn len(&self) -> usize { - self.receipt_vec.len() - } - - /// Returns true if the `Receipts` vector is empty. - pub fn is_empty(&self) -> bool { - self.receipt_vec.is_empty() - } - - /// Push a new vector of receipts into the `Receipts` collection. - pub fn push(&mut self, receipts: Vec) { - self.receipt_vec.push(receipts); - } - - /// Retrieves all recorded receipts from index and calculates the root using the given closure. - pub fn root_slow(&self, index: usize, f: impl FnOnce(&[&T]) -> B256) -> B256 { - let receipts = self.receipt_vec[index].iter().collect::>(); - f(receipts.as_slice()) - } -} - -impl From> for Receipts { - fn from(block_receipts: Vec) -> Self { - Self { receipt_vec: vec![block_receipts.into_iter().collect()] } - } -} - -impl FromIterator> for Receipts { - fn from_iter>>(iter: I) -> Self { - iter.into_iter().collect::>().into() - } -} - -impl Default for Receipts { - fn default() -> Self { - Self { receipt_vec: Vec::new() } - } -} diff --git a/crates/revm/src/batch.rs b/crates/revm/src/batch.rs index ccecaaf8f..1cd188458 100644 --- a/crates/revm/src/batch.rs +++ b/crates/revm/src/batch.rs @@ -4,7 +4,6 @@ use alloc::vec::Vec; use alloy_eips::eip7685::Requests; use alloy_primitives::BlockNumber; -use reth_primitives::Receipts; /// Takes care of: /// - recording receipts during execution of multiple blocks. @@ -17,7 +16,7 @@ pub struct BlockBatchRecord { /// The inner vector stores receipts ordered by transaction number. /// /// If receipt is None it means it is pruned. - receipts: Receipts, + receipts: Vec>, /// The collection of EIP-7685 requests. /// Outer vector stores requests for each block sequentially. /// The inner vector stores requests ordered by transaction number. @@ -57,12 +56,12 @@ impl BlockBatchRecord { } /// Returns the recorded receipts. - pub const fn receipts(&self) -> &Receipts { + pub const fn receipts(&self) -> &Vec> { &self.receipts } /// Returns all recorded receipts. - pub fn take_receipts(&mut self) -> Receipts { + pub fn take_receipts(&mut self) -> Vec> { core::mem::take(&mut self.receipts) } @@ -99,6 +98,6 @@ mod tests { recorder.save_receipts(receipts); // Verify that the saved receipts are equal to a nested empty vector - assert_eq!(*recorder.receipts(), vec![vec![]].into()); + assert_eq!(*recorder.receipts(), vec![vec![]]); } } diff --git a/crates/rpc/rpc/src/eth/helpers/pending_block.rs b/crates/rpc/rpc/src/eth/helpers/pending_block.rs index f4bf68737..cf6299017 100644 --- a/crates/rpc/rpc/src/eth/helpers/pending_block.rs +++ b/crates/rpc/rpc/src/eth/helpers/pending_block.rs @@ -62,8 +62,7 @@ where let chain_spec = self.provider().chain_spec(); let transactions_root = calculate_transaction_root(&transactions); - let receipts_root = - Receipt::calculate_receipt_root_no_memo(&receipts.iter().collect::>()); + let receipts_root = Receipt::calculate_receipt_root_no_memo(receipts); let logs_bloom = logs_bloom(receipts.iter().flat_map(|r| &r.logs)); diff --git a/crates/storage/db-common/src/init.rs b/crates/storage/db-common/src/init.rs index 86e4e312d..605a36d25 100644 --- a/crates/storage/db-common/src/init.rs +++ b/crates/storage/db-common/src/init.rs @@ -10,7 +10,7 @@ use reth_db::tables; use reth_db_api::{transaction::DbTxMut, DatabaseError}; use reth_etl::Collector; use reth_primitives::{ - Account, Bytecode, GotExpected, NodePrimitives, Receipts, StaticFileSegment, StorageEntry, + Account, Bytecode, GotExpected, NodePrimitives, StaticFileSegment, StorageEntry, }; use reth_provider::{ errors::provider::ProviderResult, providers::StaticFileWriter, writer::UnifiedStorageWriter, @@ -246,7 +246,7 @@ where state_init, all_reverts_init, contracts, - Receipts::default(), + Vec::default(), block, Vec::new(), ); diff --git a/crates/storage/provider/src/providers/blockchain_provider.rs b/crates/storage/provider/src/providers/blockchain_provider.rs index 6ef8ab5a9..23cac3df8 100644 --- a/crates/storage/provider/src/providers/blockchain_provider.rs +++ b/crates/storage/provider/src/providers/blockchain_provider.rs @@ -928,7 +928,7 @@ mod tests { let senders = block.senders().expect("failed to recover senders"); let block_receipts = receipts.get(block.number as usize).unwrap().clone(); let execution_outcome = - ExecutionOutcome { receipts: block_receipts.into(), ..Default::default() }; + ExecutionOutcome { receipts: vec![block_receipts], ..Default::default() }; ExecutedBlockWithTrieUpdates::new( Arc::new(RecoveredBlock::new_sealed(block.clone(), senders)), diff --git a/crates/storage/provider/src/providers/consistent.rs b/crates/storage/provider/src/providers/consistent.rs index 901e3f785..4d47cc23d 100644 --- a/crates/storage/provider/src/providers/consistent.rs +++ b/crates/storage/provider/src/providers/consistent.rs @@ -208,7 +208,7 @@ impl ConsistentProvider { reverts, // We skip new contracts since we never delete them from the database Vec::new(), - receipts.into(), + receipts, start_block_number, Vec::new(), ))) diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index f5b5ed455..ac3ea42e1 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -2289,7 +2289,7 @@ impl StateWriter state, reverts, Vec::new(), - receipts.into(), + receipts, start_block_number, Vec::new(), )) diff --git a/crates/storage/provider/src/test_utils/blocks.rs b/crates/storage/provider/src/test_utils/blocks.rs index f722e8c54..6f44b9fe1 100644 --- a/crates/storage/provider/src/test_utils/blocks.rs +++ b/crates/storage/provider/src/test_utils/blocks.rs @@ -220,8 +220,7 @@ fn block1(number: BlockNumber) -> (RecoveredBlock, Execu )], ..Default::default() }, - ]] - .into(), + ]], number, Vec::new(), ); @@ -279,8 +278,7 @@ fn block2( )], ..Default::default() }, - ]] - .into(), + ]], number, Vec::new(), ); @@ -347,8 +345,7 @@ fn block3( )], ..Default::default() }, - ]] - .into(), + ]], number, Vec::new(), ); @@ -435,8 +432,7 @@ fn block4( )], ..Default::default() }, - ]] - .into(), + ]], number, Vec::new(), ); @@ -520,8 +516,7 @@ fn block5( )], ..Default::default() }, - ]] - .into(), + ]], number, Vec::new(), ); diff --git a/crates/storage/provider/src/writer/mod.rs b/crates/storage/provider/src/writer/mod.rs index e88c1dfb5..8867698c5 100644 --- a/crates/storage/provider/src/writer/mod.rs +++ b/crates/storage/provider/src/writer/mod.rs @@ -235,7 +235,7 @@ mod tests { transaction::{DbTx, DbTxMut}, }; use reth_execution_types::ExecutionOutcome; - use reth_primitives::{Account, Receipt, Receipts, StorageEntry}; + use reth_primitives::{Account, Receipt, StorageEntry}; use reth_storage_api::{DatabaseProviderFactory, HashedPostStateProvider}; use reth_trie::{ test_utils::{state_root, storage_root_prehashed}, @@ -498,8 +498,7 @@ mod tests { state.merge_transitions(BundleRetention::Reverts); - let outcome = - ExecutionOutcome::new(state.take_bundle(), Receipts::default(), 1, Vec::new()); + let outcome = ExecutionOutcome::new(state.take_bundle(), Default::default(), 1, Vec::new()); provider .write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database) .expect("Could not write bundle state to DB"); @@ -598,8 +597,7 @@ mod tests { )])); state.merge_transitions(BundleRetention::Reverts); - let outcome = - ExecutionOutcome::new(state.take_bundle(), Receipts::default(), 2, Vec::new()); + let outcome = ExecutionOutcome::new(state.take_bundle(), Default::default(), 2, Vec::new()); provider .write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database) .expect("Could not write bundle state to DB"); @@ -666,7 +664,7 @@ mod tests { init_state.merge_transitions(BundleRetention::Reverts); let outcome = - ExecutionOutcome::new(init_state.take_bundle(), Receipts::default(), 0, Vec::new()); + ExecutionOutcome::new(init_state.take_bundle(), Default::default(), 0, Vec::new()); provider .write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database) .expect("Could not write bundle state to DB"); @@ -814,7 +812,7 @@ mod tests { let bundle = state.take_bundle(); let outcome: ExecutionOutcome = - ExecutionOutcome::new(bundle, Receipts::default(), 1, Vec::new()); + ExecutionOutcome::new(bundle, Default::default(), 1, Vec::new()); provider .write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database) .expect("Could not write bundle state to DB"); @@ -979,7 +977,7 @@ mod tests { )])); init_state.merge_transitions(BundleRetention::Reverts); let outcome = - ExecutionOutcome::new(init_state.take_bundle(), Receipts::default(), 0, Vec::new()); + ExecutionOutcome::new(init_state.take_bundle(), Default::default(), 0, Vec::new()); provider .write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database) .expect("Could not write bundle state to DB"); @@ -1025,8 +1023,7 @@ mod tests { // Commit block #1 changes to the database. state.merge_transitions(BundleRetention::Reverts); - let outcome = - ExecutionOutcome::new(state.take_bundle(), Receipts::default(), 1, Vec::new()); + let outcome = ExecutionOutcome::new(state.take_bundle(), Default::default(), 1, Vec::new()); provider .write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database) .expect("Could not write bundle state to DB"); @@ -1059,7 +1056,7 @@ mod tests { fn revert_to_indices() { let base: ExecutionOutcome = ExecutionOutcome { bundle: BundleState::default(), - receipts: vec![vec![Receipt::default(); 2]; 7].into(), + receipts: vec![vec![Receipt::default(); 2]; 7], first_block: 10, requests: Vec::new(), }; @@ -1270,7 +1267,7 @@ mod tests { let mut test: ExecutionOutcome = ExecutionOutcome { bundle: present_state, - receipts: vec![vec![Receipt::default(); 2]; 1].into(), + receipts: vec![vec![Receipt::default(); 2]; 1], first_block: 2, requests: Vec::new(), }; diff --git a/crates/trie/sparse/src/trie.rs b/crates/trie/sparse/src/trie.rs index 17e764183..162131f58 100644 --- a/crates/trie/sparse/src/trie.rs +++ b/crates/trie/sparse/src/trie.rs @@ -589,7 +589,7 @@ impl

RevealedSparseTrie

{ // Get the nodes that have changed at the given depth. let (targets, new_prefix_set) = self.get_changed_nodes_at_depth(&mut prefix_set, depth); - // Update the prefix set to the prefix set of the nodes that stil need to be updated. + // Update the prefix set to the prefix set of the nodes that still need to be updated. self.prefix_set = new_prefix_set; trace!(target: "trie::sparse", ?depth, ?targets, "Updating nodes at depth"); diff --git a/testing/testing-utils/Cargo.toml b/testing/testing-utils/Cargo.toml index 6dfd38e84..45e60b2a1 100644 --- a/testing/testing-utils/Cargo.toml +++ b/testing/testing-utils/Cargo.toml @@ -16,7 +16,7 @@ reth-primitives = { workspace = true, features = ["secp256k1", "arbitrary"] } reth-primitives-traits = { workspace = true, features = ["secp256k1", "arbitrary"] } alloy-genesis.workspace = true -alloy-primitives.workspace = true +alloy-primitives = { workspace = true, features = ["rand"] } alloy-consensus.workspace = true alloy-eips.workspace = true