refactor: remove Receipts struct (#14130)

This commit is contained in:
Arsenii Kulikov
2025-02-01 01:59:31 +04:00
committed by GitHub
parent d30a1b6c7d
commit 1c9ef8c5a3
32 changed files with 179 additions and 307 deletions

2
Cargo.lock generated
View File

@ -8554,7 +8554,6 @@ dependencies = [
"arbitrary", "arbitrary",
"c-kzg", "c-kzg",
"codspeed-criterion-compat", "codspeed-criterion-compat",
"derive_more",
"once_cell", "once_cell",
"pprof", "pprof",
"proptest", "proptest",
@ -8564,7 +8563,6 @@ dependencies = [
"reth-ethereum-primitives", "reth-ethereum-primitives",
"reth-primitives-traits", "reth-primitives-traits",
"reth-static-file-types", "reth-static-file-types",
"serde",
"serde_json", "serde_json",
] ]

View File

@ -11,9 +11,7 @@ use parking_lot::RwLock;
use reth_chainspec::ChainInfo; use reth_chainspec::ChainInfo;
use reth_execution_types::{Chain, ExecutionOutcome}; use reth_execution_types::{Chain, ExecutionOutcome};
use reth_metrics::{metrics::Gauge, Metrics}; use reth_metrics::{metrics::Gauge, Metrics};
use reth_primitives::{ use reth_primitives::{EthPrimitives, NodePrimitives, RecoveredBlock, SealedBlock, SealedHeader};
EthPrimitives, NodePrimitives, Receipts, RecoveredBlock, SealedBlock, SealedHeader,
};
use reth_primitives_traits::{BlockBody as _, SignedTransaction}; use reth_primitives_traits::{BlockBody as _, SignedTransaction};
use reth_storage_api::StateProviderBox; use reth_storage_api::StateProviderBox;
use reth_trie::{updates::TrieUpdates, HashedPostState}; use reth_trie::{updates::TrieUpdates, HashedPostState};
@ -648,7 +646,7 @@ impl<N: NodePrimitives> BlockState<N> {
} }
/// Returns the `Receipts` of executed block that determines the state. /// Returns the `Receipts` of executed block that determines the state.
pub fn receipts(&self) -> &Receipts<N::Receipt> { pub fn receipts(&self) -> &Vec<Vec<N::Receipt>> {
&self.block.execution_outcome().receipts &self.block.execution_outcome().receipts
} }
@ -660,12 +658,12 @@ impl<N: NodePrimitives> BlockState<N> {
let receipts = self.receipts(); let receipts = self.receipts();
debug_assert!( debug_assert!(
receipts.receipt_vec.len() <= 1, receipts.len() <= 1,
"Expected at most one block's worth of receipts, found {}", "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`. /// Returns a vector of __parent__ `BlockStates`.
@ -1244,7 +1242,7 @@ mod tests {
#[test] #[test]
fn test_state_receipts() { 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 mut test_block_builder: TestBlockBuilder = TestBlockBuilder::default();
let block = let block =
test_block_builder.get_executed_block_with_receipts(receipts.clone(), B256::random()); 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()); test_block_builder.get_executed_block_with_number(2, block1.recovered_block.hash());
let sample_execution_outcome = ExecutionOutcome { let sample_execution_outcome = ExecutionOutcome {
receipts: Receipts::from_iter([vec![], vec![]]), receipts: vec![vec![], vec![]],
requests: vec![Requests::default(), Requests::default()], requests: vec![Requests::default(), Requests::default()],
..Default::default() ..Default::default()
}; };

View File

@ -217,7 +217,7 @@ mod tests {
use alloy_consensus::BlockBody; use alloy_consensus::BlockBody;
use alloy_primitives::{b256, B256}; use alloy_primitives::{b256, B256};
use reth_execution_types::ExecutionOutcome; use reth_execution_types::ExecutionOutcome;
use reth_primitives::{Receipt, Receipts, SealedBlock, TransactionSigned, TxType}; use reth_primitives::{Receipt, SealedBlock, TransactionSigned, TxType};
#[test] #[test]
fn test_commit_notification() { fn test_commit_notification() {
@ -334,7 +334,7 @@ mod tests {
}; };
// Wrap the receipt in a `Receipts` structure, as expected in the `ExecutionOutcome`. // 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. // Define an `ExecutionOutcome` with the created receipts.
let execution_outcome = ExecutionOutcome { receipts, ..Default::default() }; let execution_outcome = ExecutionOutcome { receipts, ..Default::default() };
@ -393,7 +393,7 @@ mod tests {
success: false, success: false,
..Default::default() ..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 = let old_execution_outcome =
ExecutionOutcome { receipts: old_receipts, ..Default::default() }; ExecutionOutcome { receipts: old_receipts, ..Default::default() };
@ -424,7 +424,7 @@ mod tests {
success: true, success: true,
..Default::default() ..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 = let new_execution_outcome =
ExecutionOutcome { receipts: new_receipts, ..Default::default() }; ExecutionOutcome { receipts: new_receipts, ..Default::default() };

View File

@ -19,8 +19,7 @@ use reth_chainspec::{ChainSpec, EthereumHardfork, MIN_TRANSACTION_GAS};
use reth_execution_types::{Chain, ExecutionOutcome}; use reth_execution_types::{Chain, ExecutionOutcome};
use reth_primitives::{ use reth_primitives::{
transaction::SignedTransactionIntoRecoveredExt, BlockBody, EthPrimitives, NodePrimitives, transaction::SignedTransactionIntoRecoveredExt, BlockBody, EthPrimitives, NodePrimitives,
Receipt, Receipts, Recovered, RecoveredBlock, SealedBlock, SealedHeader, Transaction, Receipt, Recovered, RecoveredBlock, SealedBlock, SealedHeader, Transaction, TransactionSigned,
TransactionSigned,
}; };
use reth_primitives_traits::{ use reth_primitives_traits::{
proofs::{calculate_receipt_root, calculate_transaction_root, calculate_withdrawals_root}, proofs::{calculate_receipt_root, calculate_transaction_root, calculate_withdrawals_root},
@ -204,11 +203,11 @@ impl<N: NodePrimitives> TestBlockBuilder<N> {
fork fork
} }
/// Gets an [`ExecutedBlockWithTrieUpdates`] with [`BlockNumber`], [`Receipts`] and parent hash. /// Gets an [`ExecutedBlockWithTrieUpdates`] with [`BlockNumber`], receipts and parent hash.
fn get_executed_block( fn get_executed_block(
&mut self, &mut self,
block_number: BlockNumber, block_number: BlockNumber,
receipts: Receipts, receipts: Vec<Vec<Receipt>>,
parent_hash: B256, parent_hash: B256,
) -> ExecutedBlockWithTrieUpdates { ) -> ExecutedBlockWithTrieUpdates {
let block_with_senders = self.generate_random_block(block_number, parent_hash); let block_with_senders = self.generate_random_block(block_number, parent_hash);
@ -227,10 +226,10 @@ impl<N: NodePrimitives> TestBlockBuilder<N> {
) )
} }
/// Generates an [`ExecutedBlockWithTrieUpdates`] that includes the given [`Receipts`]. /// Generates an [`ExecutedBlockWithTrieUpdates`] that includes the given receipts.
pub fn get_executed_block_with_receipts( pub fn get_executed_block_with_receipts(
&mut self, &mut self,
receipts: Receipts, receipts: Vec<Vec<Receipt>>,
parent_hash: B256, parent_hash: B256,
) -> ExecutedBlockWithTrieUpdates { ) -> ExecutedBlockWithTrieUpdates {
let number = rand::thread_rng().gen::<u64>(); let number = rand::thread_rng().gen::<u64>();
@ -243,7 +242,7 @@ impl<N: NodePrimitives> TestBlockBuilder<N> {
block_number: BlockNumber, block_number: BlockNumber,
parent_hash: B256, parent_hash: B256,
) -> ExecutedBlockWithTrieUpdates { ) -> 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. /// Generates a range of executed blocks with ascending block numbers.
@ -296,12 +295,12 @@ impl<N: NodePrimitives> TestBlockBuilder<N> {
let execution_outcome = ExecutionOutcome::new( let execution_outcome = ExecutionOutcome::new(
bundle_state_builder.build(), bundle_state_builder.build(),
vec![vec![]].into(), vec![vec![]],
block.number, block.number,
Vec::new(), Vec::new(),
); );
execution_outcome.with_receipts(Receipts::from(receipts)) execution_outcome.with_receipts(vec![receipts])
} }
} }

View File

@ -28,7 +28,7 @@ reth-stages-api.workspace = true
# alloy # alloy
alloy-consensus.workspace = true alloy-consensus.workspace = true
alloy-primitives.workspace = true alloy-primitives = { workspace = true, features = ["getrandom"] }
alloy-rpc-types-engine.workspace = true alloy-rpc-types-engine.workspace = true
# async # async

View File

@ -18,9 +18,7 @@ use reth_evm::{
}; };
use reth_payload_primitives::EngineApiMessageVersion; use reth_payload_primitives::EngineApiMessageVersion;
use reth_payload_validator::ExecutionPayloadValidator; use reth_payload_validator::ExecutionPayloadValidator;
use reth_primitives::{ use reth_primitives::{transaction::SignedTransactionIntoRecoveredExt, Block, BlockBody, Receipt};
transaction::SignedTransactionIntoRecoveredExt, Block, BlockBody, Receipt, Receipts,
};
use reth_primitives_traits::{block::Block as _, proofs, SignedTransaction}; use reth_primitives_traits::{block::Block as _, proofs, SignedTransaction};
use reth_provider::{BlockReader, ExecutionOutcome, ProviderError, StateProviderFactory}; use reth_provider::{BlockReader, ExecutionOutcome, ProviderError, StateProviderFactory};
use reth_revm::{ use reth_revm::{
@ -373,7 +371,7 @@ where
let outcome: ExecutionOutcome = ExecutionOutcome::new( let outcome: ExecutionOutcome = ExecutionOutcome::new(
state.take_bundle(), state.take_bundle(),
Receipts::from(vec![receipts]), vec![receipts],
reorg_target.number, reorg_target.number,
Default::default(), Default::default(),
); );

View File

@ -380,7 +380,7 @@ where
let requests_hash = requests.as_ref().map(|requests| requests.requests_hash()); let requests_hash = requests.as_ref().map(|requests| requests.requests_hash());
let execution_outcome = ExecutionOutcome::new( let execution_outcome = ExecutionOutcome::new(
db.take_bundle(), db.take_bundle(),
vec![receipts].into(), vec![receipts],
block_number, block_number,
vec![requests.clone().unwrap_or_default()], vec![requests.clone().unwrap_or_default()],
); );

View File

@ -85,7 +85,7 @@ impl Receipt {
/// Calculates the receipt root for a header for the reference type of [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. /// 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)) ordered_trie_root_with_encoder(receipts, |r, buf| r.with_bloom_ref().encode_2718(buf))
} }
} }

View File

@ -703,7 +703,6 @@ mod tests {
use alloy_consensus::TxType; use alloy_consensus::TxType;
use alloy_primitives::{Address, B256}; use alloy_primitives::{Address, B256};
use reth_ethereum_primitives::Receipt; use reth_ethereum_primitives::Receipt;
use reth_primitives::Receipts;
use revm::primitives::{AccountInfo, HashMap}; use revm::primitives::{AccountInfo, HashMap};
// TODO: this is temporary, until we fully switch over to `reth_ethereum_primitives` for the // 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![(Address::new([2; 20]), None, vec![])]],
vec![], vec![],
), ),
vec![vec![]].into(), vec![vec![]],
1, 1,
vec![], vec![],
); );
@ -781,7 +780,7 @@ mod tests {
vec![vec![(Address::new([3; 20]), None, vec![])]], vec![vec![(Address::new([3; 20]), None, vec![])]],
vec![], vec![],
), ),
vec![vec![]].into(), vec![vec![]],
2, 2,
vec![], vec![],
); );
@ -884,7 +883,7 @@ mod tests {
}; };
// Create a Receipts object with a vector of receipt vectors // 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 // Create an ExecutionOutcome object with the created bundle, receipts, an empty requests
// vector, and first_block set to 10 // vector, and first_block set to 10
@ -909,7 +908,7 @@ mod tests {
// Create an ExecutionOutcome object with a single receipt vector containing receipt1 // Create an ExecutionOutcome object with a single receipt vector containing receipt1
let execution_outcome1 = ExecutionOutcome { let execution_outcome1 = ExecutionOutcome {
bundle: Default::default(), bundle: Default::default(),
receipts: Receipts { receipt_vec: vec![vec![receipt1]] }, receipts: vec![vec![receipt1]],
requests: vec![], requests: vec![],
first_block: 10, first_block: 10,
}; };

View File

@ -2,7 +2,6 @@ use crate::BlockExecutionOutput;
use alloc::{vec, vec::Vec}; use alloc::{vec, vec::Vec};
use alloy_eips::eip7685::Requests; use alloy_eips::eip7685::Requests;
use alloy_primitives::{logs_bloom, map::HashMap, Address, BlockNumber, Bloom, Log, B256, U256}; 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_primitives_traits::{Account, Bytecode, Receipt, StorageEntry};
use reth_trie::{HashedPostState, KeyHasher}; use reth_trie::{HashedPostState, KeyHasher};
use revm::{ use revm::{
@ -40,9 +39,7 @@ pub struct ExecutionOutcome<T = reth_primitives::Receipt> {
/// The collection of receipts. /// The collection of receipts.
/// Outer vector stores receipts for each block sequentially. /// Outer vector stores receipts for each block sequentially.
/// The inner vector stores receipts ordered by transaction number. /// The inner vector stores receipts ordered by transaction number.
/// pub receipts: Vec<Vec<T>>,
/// If receipt is None it means it is pruned.
pub receipts: Receipts<T>,
/// First block of bundle state. /// First block of bundle state.
pub first_block: BlockNumber, pub first_block: BlockNumber,
/// The collection of EIP-7685 requests. /// The collection of EIP-7685 requests.
@ -82,7 +79,7 @@ impl<T> ExecutionOutcome<T> {
/// bundle state, receipts, first block number, and EIP-7685 requests. /// bundle state, receipts, first block number, and EIP-7685 requests.
pub const fn new( pub const fn new(
bundle: BundleState, bundle: BundleState,
receipts: Receipts<T>, receipts: Vec<Vec<T>>,
first_block: BlockNumber, first_block: BlockNumber,
requests: Vec<Requests>, requests: Vec<Requests>,
) -> Self { ) -> Self {
@ -97,7 +94,7 @@ impl<T> ExecutionOutcome<T> {
state_init: BundleStateInit, state_init: BundleStateInit,
revert_init: RevertsInit, revert_init: RevertsInit,
contracts_init: impl IntoIterator<Item = (B256, Bytecode)>, contracts_init: impl IntoIterator<Item = (B256, Bytecode)>,
receipts: Receipts<T>, receipts: Vec<Vec<T>>,
first_block: BlockNumber, first_block: BlockNumber,
requests: Vec<Requests>, requests: Vec<Requests>,
) -> Self { ) -> Self {
@ -197,18 +194,18 @@ impl<T> ExecutionOutcome<T> {
pub fn generic_receipts_root_slow( pub fn generic_receipts_root_slow(
&self, &self,
block_number: BlockNumber, block_number: BlockNumber,
f: impl FnOnce(&[&T]) -> B256, f: impl FnOnce(&[T]) -> B256,
) -> Option<B256> { ) -> Option<B256> {
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. /// Returns reference to receipts.
pub const fn receipts(&self) -> &Receipts<T> { pub const fn receipts(&self) -> &Vec<Vec<T>> {
&self.receipts &self.receipts
} }
/// Returns mutable reference to receipts. /// Returns mutable reference to receipts.
pub fn receipts_mut(&mut self) -> &mut Receipts<T> { pub fn receipts_mut(&mut self) -> &mut Vec<Vec<T>> {
&mut self.receipts &mut self.receipts
} }
@ -285,7 +282,7 @@ impl<T> ExecutionOutcome<T> {
// Truncate higher state to [at..]. // Truncate higher state to [at..].
let at_idx = higher_state.block_number_to_index(at).unwrap(); 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. // Ensure that there are enough requests to truncate.
// Sometimes we just have receipts and no requests. // Sometimes we just have receipts and no requests.
if at_idx < higher_state.requests.len() { if at_idx < higher_state.requests.len() {
@ -304,7 +301,7 @@ impl<T> ExecutionOutcome<T> {
/// In most cases this would be true. /// In most cases this would be true.
pub fn extend(&mut self, other: Self) { pub fn extend(&mut self, other: Self) {
self.bundle.extend(other.bundle); self.bundle.extend(other.bundle);
self.receipts.extend(other.receipts.receipt_vec); self.receipts.extend(other.receipts);
self.requests.extend(other.requests); self.requests.extend(other.requests);
} }
@ -325,7 +322,7 @@ impl<T> ExecutionOutcome<T> {
} }
/// Create a new instance with updated receipts. /// Create a new instance with updated receipts.
pub fn with_receipts(mut self, receipts: Receipts<T>) -> Self { pub fn with_receipts(mut self, receipts: Vec<Vec<T>>) -> Self {
self.receipts = receipts; self.receipts = receipts;
self self
} }
@ -366,10 +363,11 @@ impl ExecutionOutcome {
/// ///
/// Note: this function calculated Bloom filters for every receipt and created merkle trees /// Note: this function calculated Bloom filters for every receipt and created merkle trees
/// of receipt. This is a expensive operation. /// of receipt. This is a expensive operation.
pub fn ethereum_receipts_root(&self, _block_number: BlockNumber) -> Option<B256> { pub fn ethereum_receipts_root(&self, block_number: BlockNumber) -> Option<B256> {
Some(self.receipts.root_slow(self.block_number_to_index(_block_number)?, |receipts| { self.generic_receipts_root_slow(
reth_primitives::Receipt::calculate_receipt_root_no_memo(receipts) block_number,
})) reth_primitives::Receipt::calculate_receipt_root_no_memo,
)
} }
} }
@ -377,7 +375,7 @@ impl<T> From<(BlockExecutionOutput<T>, BlockNumber)> for ExecutionOutcome<T> {
fn from(value: (BlockExecutionOutput<T>, BlockNumber)) -> Self { fn from(value: (BlockExecutionOutput<T>, BlockNumber)) -> Self {
Self { Self {
bundle: value.0.state, bundle: value.0.state,
receipts: Receipts::from(value.0.receipts), receipts: vec![value.0.receipts],
first_block: value.1, first_block: value.1,
requests: vec![value.0.requests], requests: vec![value.0.requests],
} }
@ -389,7 +387,6 @@ mod tests {
use super::*; use super::*;
use alloy_consensus::TxType; use alloy_consensus::TxType;
use alloy_primitives::{bytes, Address, LogData, B256}; use alloy_primitives::{bytes, Address, LogData, B256};
use reth_primitives::Receipts;
#[test] #[test]
fn test_initialisation() { fn test_initialisation() {
@ -401,14 +398,12 @@ mod tests {
); );
// Create a Receipts object with a vector of receipt vectors // Create a Receipts object with a vector of receipt vectors
let receipts = Receipts { let receipts = vec![vec![Some(reth_ethereum_primitives::Receipt {
receipt_vec: vec![vec![Some(reth_ethereum_primitives::Receipt { tx_type: TxType::Legacy,
tx_type: TxType::Legacy, cumulative_gas_used: 46913,
cumulative_gas_used: 46913, logs: vec![],
logs: vec![], success: true,
success: true, })]];
})]],
};
// Create a Requests object with a vector of requests // Create a Requests object with a vector of requests
let requests = vec![Requests::new(vec![bytes!("dead"), bytes!("beef"), bytes!("beebee")])]; let requests = vec![Requests::new(vec![bytes!("dead"), bytes!("beef"), bytes!("beebee")])];
@ -462,14 +457,12 @@ mod tests {
#[test] #[test]
fn test_block_number_to_index() { fn test_block_number_to_index() {
// Create a Receipts object with a vector of receipt vectors // Create a Receipts object with a vector of receipt vectors
let receipts = Receipts { let receipts = vec![vec![Some(reth_ethereum_primitives::Receipt {
receipt_vec: vec![vec![Some(reth_ethereum_primitives::Receipt { tx_type: TxType::Legacy,
tx_type: TxType::Legacy, cumulative_gas_used: 46913,
cumulative_gas_used: 46913, logs: vec![],
logs: vec![], success: true,
success: true, })]];
})]],
};
// Define the first block number // Define the first block number
let first_block = 123; let first_block = 123;
@ -496,14 +489,12 @@ mod tests {
#[test] #[test]
fn test_get_logs() { fn test_get_logs() {
// Create a Receipts object with a vector of receipt vectors // Create a Receipts object with a vector of receipt vectors
let receipts = Receipts { let receipts = vec![vec![reth_ethereum_primitives::Receipt {
receipt_vec: vec![vec![reth_ethereum_primitives::Receipt { tx_type: TxType::Legacy,
tx_type: TxType::Legacy, cumulative_gas_used: 46913,
cumulative_gas_used: 46913, logs: vec![Log::<LogData>::default()],
logs: vec![Log::<LogData>::default()], success: true,
success: true, }]];
}]],
};
// Define the first block number // Define the first block number
let first_block = 123; let first_block = 123;
@ -527,14 +518,12 @@ mod tests {
#[test] #[test]
fn test_receipts_by_block() { fn test_receipts_by_block() {
// Create a Receipts object with a vector of receipt vectors // Create a Receipts object with a vector of receipt vectors
let receipts = Receipts { let receipts = vec![vec![Some(reth_ethereum_primitives::Receipt {
receipt_vec: vec![vec![Some(reth_ethereum_primitives::Receipt { tx_type: TxType::Legacy,
tx_type: TxType::Legacy, cumulative_gas_used: 46913,
cumulative_gas_used: 46913, logs: vec![Log::<LogData>::default()],
logs: vec![Log::<LogData>::default()], success: true,
success: true, })]];
})]],
};
// Define the first block number // Define the first block number
let first_block = 123; let first_block = 123;
@ -566,17 +555,15 @@ mod tests {
#[test] #[test]
fn test_receipts_len() { fn test_receipts_len() {
// Create a Receipts object with a vector of receipt vectors // Create a Receipts object with a vector of receipt vectors
let receipts = Receipts { let receipts = vec![vec![Some(reth_ethereum_primitives::Receipt {
receipt_vec: vec![vec![Some(reth_ethereum_primitives::Receipt { tx_type: TxType::Legacy,
tx_type: TxType::Legacy, cumulative_gas_used: 46913,
cumulative_gas_used: 46913, logs: vec![Log::<LogData>::default()],
logs: vec![Log::<LogData>::default()], success: true,
success: true, })]];
})]],
};
// Create an empty Receipts object // Create an empty Receipts object
let receipts_empty: Receipts = Receipts { receipt_vec: vec![] }; let receipts_empty = vec![];
// Define the first block number // Define the first block number
let first_block = 123; let first_block = 123;
@ -597,7 +584,7 @@ mod tests {
assert!(!exec_res.is_empty()); assert!(!exec_res.is_empty());
// Create a ExecutionOutcome object with an empty Receipts object // 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 bundle: Default::default(), // Default value for bundle
receipts: receipts_empty, // Include the empty receipts receipts: receipts_empty, // Include the empty receipts
requests: vec![], // Empty vector for requests requests: vec![], // Empty vector for requests
@ -622,9 +609,7 @@ mod tests {
}; };
// Create a Receipts object with a vector of receipt vectors // Create a Receipts object with a vector of receipt vectors
let receipts = Receipts { let receipts = vec![vec![Some(receipt.clone())], vec![Some(receipt.clone())]];
receipt_vec: vec![vec![Some(receipt.clone())], vec![Some(receipt.clone())]],
};
// Define the first block number // Define the first block number
let first_block = 123; let first_block = 123;
@ -645,7 +630,7 @@ mod tests {
assert!(exec_res.revert_to(123)); assert!(exec_res.revert_to(123));
// Assert that the receipts are properly cut after reverting to the initial block number. // 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 that the requests are properly cut after reverting to the initial block number.
assert_eq!(exec_res.requests, vec![Requests::new(vec![request])]); assert_eq!(exec_res.requests, vec![Requests::new(vec![request])]);
@ -670,7 +655,7 @@ mod tests {
}; };
// Create a Receipts object containing the receipt. // 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. // Create a request.
let request = bytes!("deadbeef"); let request = bytes!("deadbeef");
@ -693,9 +678,7 @@ mod tests {
exec_res, exec_res,
ExecutionOutcome { ExecutionOutcome {
bundle: Default::default(), bundle: Default::default(),
receipts: Receipts { receipts: vec![vec![Some(receipt.clone())], vec![Some(receipt)]],
receipt_vec: vec![vec![Some(receipt.clone())], vec![Some(receipt)]]
},
requests: vec![Requests::new(vec![request.clone()]), Requests::new(vec![request])], requests: vec![Requests::new(vec![request.clone()]), Requests::new(vec![request])],
first_block: 123, first_block: 123,
} }
@ -713,13 +696,11 @@ mod tests {
}; };
// Create a Receipts object with a vector of receipt vectors // Create a Receipts object with a vector of receipt vectors
let receipts = Receipts { let receipts = vec![
receipt_vec: vec![ vec![Some(receipt.clone())],
vec![Some(receipt.clone())], vec![Some(receipt.clone())],
vec![Some(receipt.clone())], vec![Some(receipt.clone())],
vec![Some(receipt.clone())], ];
],
};
// Define the first block number // Define the first block number
let first_block = 123; let first_block = 123;
@ -745,7 +726,7 @@ mod tests {
// Define the expected lower ExecutionOutcome after splitting // Define the expected lower ExecutionOutcome after splitting
let lower_execution_outcome = ExecutionOutcome { let lower_execution_outcome = ExecutionOutcome {
bundle: Default::default(), 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()])], requests: vec![Requests::new(vec![request.clone()])],
first_block, first_block,
}; };
@ -753,9 +734,7 @@ mod tests {
// Define the expected higher ExecutionOutcome after splitting // Define the expected higher ExecutionOutcome after splitting
let higher_execution_outcome = ExecutionOutcome { let higher_execution_outcome = ExecutionOutcome {
bundle: Default::default(), bundle: Default::default(),
receipts: Receipts { receipts: vec![vec![Some(receipt.clone())], vec![Some(receipt)]],
receipt_vec: vec![vec![Some(receipt.clone())], vec![Some(receipt)]],
},
requests: vec![Requests::new(vec![request.clone()]), Requests::new(vec![request])], requests: vec![Requests::new(vec![request.clone()]), Requests::new(vec![request])],
first_block: 124, first_block: 124,
}; };
@ -815,7 +794,7 @@ mod tests {
let execution_outcome: ExecutionOutcome = ExecutionOutcome { let execution_outcome: ExecutionOutcome = ExecutionOutcome {
bundle: bundle_state, bundle: bundle_state,
receipts: Receipts::default(), receipts: Default::default(),
first_block: 0, first_block: 0,
requests: vec![], requests: vec![],
}; };

View File

@ -12,7 +12,7 @@ use alloy_eips::eip7685::Requests;
use parking_lot::Mutex; use parking_lot::Mutex;
use reth_execution_errors::BlockExecutionError; use reth_execution_errors::BlockExecutionError;
use reth_execution_types::ExecutionOutcome; use reth_execution_types::ExecutionOutcome;
use reth_primitives::{EthPrimitives, NodePrimitives, Receipt, Receipts, RecoveredBlock}; use reth_primitives::{EthPrimitives, NodePrimitives, Receipt, RecoveredBlock};
use revm::State; use revm::State;
use std::sync::Arc; use std::sync::Arc;
@ -153,7 +153,7 @@ where
} }
/// Accessor for batch executor receipts. /// Accessor for batch executor receipts.
pub const fn receipts(&self) -> &Receipts<<S::Primitives as NodePrimitives>::Receipt> { pub const fn receipts(&self) -> &Vec<Vec<<S::Primitives as NodePrimitives>::Receipt>> {
self.batch_record.receipts() self.batch_record.receipts()
} }
} }

View File

@ -23,7 +23,7 @@ pub(crate) fn to_execution_outcome(
) -> ExecutionOutcome { ) -> ExecutionOutcome {
ExecutionOutcome { ExecutionOutcome {
bundle: block_execution_output.state.clone(), bundle: block_execution_output.state.clone(),
receipts: block_execution_output.receipts.clone().into(), receipts: vec![block_execution_output.receipts.clone()],
first_block: block_number, first_block: block_number,
requests: vec![block_execution_output.requests.clone()], requests: vec![block_execution_output.requests.clone()],
} }

View File

@ -1,7 +1,7 @@
use std::{fmt, io}; use std::{fmt, io};
use futures::Future; use futures::Future;
use reth_primitives::{Receipt, Receipts}; use reth_primitives::Receipt;
use tokio::io::AsyncReadExt; use tokio::io::AsyncReadExt;
use tokio_stream::StreamExt; use tokio_stream::StreamExt;
use tokio_util::codec::{Decoder, FramedRead}; use tokio_util::codec::{Decoder, FramedRead};
@ -27,10 +27,10 @@ where
#[derive(Debug)] #[derive(Debug)]
pub struct ReceiptFileClient<D: ReceiptDecoder> { pub struct ReceiptFileClient<D: ReceiptDecoder> {
/// The buffered receipts, read from file, as nested lists. One list per block number. /// The buffered receipts, read from file, as nested lists. One list per block number.
pub receipts: Receipts<D::Receipt>, pub receipts: Vec<Vec<D::Receipt>>,
/// First (lowest) block number read from file. /// First (lowest) block number read from file.
pub first_block: u64, 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, pub total_receipts: usize,
} }
@ -66,7 +66,7 @@ where
where where
B: AsyncReadExt + Unpin, 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 // 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); let mut stream = FramedRead::with_capacity(reader, D::default(), num_bytes as usize);

View File

@ -22,7 +22,7 @@ reth-tokio-util.workspace = true
reth-ethereum-forks.workspace = true reth-ethereum-forks.workspace = true
# ethereum # ethereum
alloy-primitives.workspace = true alloy-primitives = { workspace = true, features = ["getrandom"] }
# eth # eth
enr = { workspace = true, default-features = false, features = ["rust-secp256k1"] } enr = { workspace = true, default-features = false, features = ["rust-secp256k1"] }

View File

@ -16,7 +16,7 @@ use reth_node_builder::ReceiptTy;
use reth_node_core::version::SHORT_VERSION; use reth_node_core::version::SHORT_VERSION;
use reth_optimism_chainspec::OpChainSpec; use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_primitives::{bedrock::is_dup_tx, OpPrimitives, OpReceipt}; use reth_optimism_primitives::{bedrock::is_dup_tx, OpPrimitives, OpReceipt};
use reth_primitives::{NodePrimitives, Receipts}; use reth_primitives::NodePrimitives;
use reth_provider::{ use reth_provider::{
providers::ProviderNodeTypes, writer::UnifiedStorageWriter, DatabaseProviderFactory, providers::ProviderNodeTypes, writer::UnifiedStorageWriter, DatabaseProviderFactory,
OriginalValuesKnown, ProviderFactory, StageCheckpointReader, StageCheckpointWriter, OriginalValuesKnown, ProviderFactory, StageCheckpointReader, StageCheckpointWriter,
@ -90,7 +90,7 @@ pub async fn import_receipts_from_file<N, P, F>(
where where
N: ProviderNodeTypes<ChainSpec = OpChainSpec, Primitives: NodePrimitives<Receipt = OpReceipt>>, N: ProviderNodeTypes<ChainSpec = OpChainSpec, Primitives: NodePrimitives<Receipt = OpReceipt>>,
P: AsRef<Path>, P: AsRef<Path>,
F: FnMut(u64, &mut Receipts<OpReceipt>) -> usize, F: FnMut(u64, &mut Vec<Vec<OpReceipt>>) -> usize,
{ {
for stage in StageId::ALL { for stage in StageId::ALL {
let checkpoint = provider_factory.database_provider_ro()?.get_stage_checkpoint(stage)?; 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 /// 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 /// 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<N, F>( pub async fn import_receipts_from_reader<N, F>(
provider_factory: &ProviderFactory<N>, provider_factory: &ProviderFactory<N>,
mut reader: ChunkedFileReader, mut reader: ChunkedFileReader,
@ -127,7 +127,7 @@ pub async fn import_receipts_from_reader<N, F>(
) -> eyre::Result<ImportReceiptsResult> ) -> eyre::Result<ImportReceiptsResult>
where where
N: ProviderNodeTypes<Primitives: NodePrimitives<Receipt = OpReceipt>>, N: ProviderNodeTypes<Primitives: NodePrimitives<Receipt = OpReceipt>>,
F: FnMut(u64, &mut Receipts<ReceiptTy<N>>) -> usize, F: FnMut(u64, &mut Vec<Vec<ReceiptTy<N>>>) -> usize,
{ {
let static_file_provider = provider_factory.static_file_provider(); let static_file_provider = provider_factory.static_file_provider();
@ -207,7 +207,7 @@ where
highest_block_receipts -= excess; highest_block_receipts -= excess;
// Remove the last `excess` blocks // 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}."); warn!(target: "reth::cli", highest_block_receipts, "Too many decoded blocks, ignoring the last {excess}.");
} }

View File

@ -45,7 +45,7 @@ pub(crate) fn calculate_receipt_root_optimism<R: DepositReceipt>(
/// ///
/// NOTE: Prefer calculate receipt root optimism if you have log blooms memoized. /// NOTE: Prefer calculate receipt root optimism if you have log blooms memoized.
pub fn calculate_receipt_root_no_memo_optimism( pub fn calculate_receipt_root_no_memo_optimism(
receipts: &[&OpReceipt], receipts: &[OpReceipt],
chain_spec: impl OpHardforks, chain_spec: impl OpHardforks,
timestamp: u64, timestamp: u64,
) -> B256 { ) -> B256 {

View File

@ -284,7 +284,7 @@ mod tests {
}; };
use reth_optimism_chainspec::BASE_MAINNET; use reth_optimism_chainspec::BASE_MAINNET;
use reth_optimism_primitives::{OpBlock, OpPrimitives, OpReceipt}; use reth_optimism_primitives::{OpBlock, OpPrimitives, OpReceipt};
use reth_primitives::{Account, Log, Receipts, RecoveredBlock}; use reth_primitives::{Account, Log, RecoveredBlock};
use reth_revm::{ use reth_revm::{
db::{BundleState, CacheDB, EmptyDBTyped}, db::{BundleState, CacheDB, EmptyDBTyped},
inspectors::NoOpInspector, inspectors::NoOpInspector,
@ -533,7 +533,7 @@ mod tests {
}); });
// Create a Receipts object with a vector of receipt vectors // 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 // Create an ExecutionOutcome object with the created bundle, receipts, an empty requests
// vector, and first_block set to 10 // vector, and first_block set to 10
@ -555,7 +555,7 @@ mod tests {
// Create an ExecutionOutcome object with a single receipt vector containing receipt1 // Create an ExecutionOutcome object with a single receipt vector containing receipt1
let execution_outcome1 = ExecutionOutcome { let execution_outcome1 = ExecutionOutcome {
bundle: Default::default(), bundle: Default::default(),
receipts: Receipts { receipt_vec: vec![vec![receipt1]] }, receipts: vec![vec![receipt1]],
requests: vec![], requests: vec![],
first_block: 10, first_block: 10,
}; };
@ -577,13 +577,11 @@ mod tests {
); );
// Create a Receipts object with a vector of receipt vectors // Create a Receipts object with a vector of receipt vectors
let receipts = Receipts { let receipts = vec![vec![Some(OpReceipt::Legacy(Receipt {
receipt_vec: vec![vec![Some(OpReceipt::Legacy(Receipt { cumulative_gas_used: 46913,
cumulative_gas_used: 46913, logs: vec![],
logs: vec![], status: true.into(),
status: true.into(), }))]];
}))]],
};
// Create a Requests object with a vector of requests // Create a Requests object with a vector of requests
let requests = vec![Requests::new(vec![bytes!("dead"), bytes!("beef"), bytes!("beebee")])]; let requests = vec![Requests::new(vec![bytes!("dead"), bytes!("beef"), bytes!("beebee")])];
@ -637,13 +635,11 @@ mod tests {
#[test] #[test]
fn test_block_number_to_index() { fn test_block_number_to_index() {
// Create a Receipts object with a vector of receipt vectors // Create a Receipts object with a vector of receipt vectors
let receipts = Receipts { let receipts = vec![vec![Some(OpReceipt::Legacy(Receipt {
receipt_vec: vec![vec![Some(OpReceipt::Legacy(Receipt { cumulative_gas_used: 46913,
cumulative_gas_used: 46913, logs: vec![],
logs: vec![], status: true.into(),
status: true.into(), }))]];
}))]],
};
// Define the first block number // Define the first block number
let first_block = 123; let first_block = 123;
@ -670,13 +666,11 @@ mod tests {
#[test] #[test]
fn test_get_logs() { fn test_get_logs() {
// Create a Receipts object with a vector of receipt vectors // Create a Receipts object with a vector of receipt vectors
let receipts = Receipts { let receipts = vec![vec![OpReceipt::Legacy(Receipt {
receipt_vec: vec![vec![OpReceipt::Legacy(Receipt { cumulative_gas_used: 46913,
cumulative_gas_used: 46913, logs: vec![Log::<LogData>::default()],
logs: vec![Log::<LogData>::default()], status: true.into(),
status: true.into(), })]];
})]],
};
// Define the first block number // Define the first block number
let first_block = 123; let first_block = 123;
@ -700,13 +694,11 @@ mod tests {
#[test] #[test]
fn test_receipts_by_block() { fn test_receipts_by_block() {
// Create a Receipts object with a vector of receipt vectors // Create a Receipts object with a vector of receipt vectors
let receipts = Receipts { let receipts = vec![vec![Some(OpReceipt::Legacy(Receipt {
receipt_vec: vec![vec![Some(OpReceipt::Legacy(Receipt { cumulative_gas_used: 46913,
cumulative_gas_used: 46913, logs: vec![Log::<LogData>::default()],
logs: vec![Log::<LogData>::default()], status: true.into(),
status: true.into(), }))]];
}))]],
};
// Define the first block number // Define the first block number
let first_block = 123; let first_block = 123;
@ -737,16 +729,14 @@ mod tests {
#[test] #[test]
fn test_receipts_len() { fn test_receipts_len() {
// Create a Receipts object with a vector of receipt vectors // Create a Receipts object with a vector of receipt vectors
let receipts = Receipts { let receipts = vec![vec![Some(OpReceipt::Legacy(Receipt {
receipt_vec: vec![vec![Some(OpReceipt::Legacy(Receipt { cumulative_gas_used: 46913,
cumulative_gas_used: 46913, logs: vec![Log::<LogData>::default()],
logs: vec![Log::<LogData>::default()], status: true.into(),
status: true.into(), }))]];
}))]],
};
// Create an empty Receipts object // Create an empty Receipts object
let receipts_empty = Receipts::<Receipt> { receipt_vec: vec![] }; let receipts_empty = vec![];
// Define the first block number // Define the first block number
let first_block = 123; let first_block = 123;
@ -767,7 +757,7 @@ mod tests {
assert!(!exec_res.is_empty()); assert!(!exec_res.is_empty());
// Create a ExecutionOutcome object with an empty Receipts object // Create a ExecutionOutcome object with an empty Receipts object
let exec_res_empty_receipts = ExecutionOutcome { let exec_res_empty_receipts: ExecutionOutcome<OpReceipt> = ExecutionOutcome {
bundle: Default::default(), // Default value for bundle bundle: Default::default(), // Default value for bundle
receipts: receipts_empty, // Include the empty receipts receipts: receipts_empty, // Include the empty receipts
requests: vec![], // Empty vector for requests requests: vec![], // Empty vector for requests
@ -791,9 +781,7 @@ mod tests {
}); });
// Create a Receipts object with a vector of receipt vectors // Create a Receipts object with a vector of receipt vectors
let receipts = Receipts { let receipts = vec![vec![Some(receipt.clone())], vec![Some(receipt.clone())]];
receipt_vec: vec![vec![Some(receipt.clone())], vec![Some(receipt.clone())]],
};
// Define the first block number // Define the first block number
let first_block = 123; let first_block = 123;
@ -814,7 +802,7 @@ mod tests {
assert!(exec_res.revert_to(123)); assert!(exec_res.revert_to(123));
// Assert that the receipts are properly cut after reverting to the initial block number. // 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 that the requests are properly cut after reverting to the initial block number.
assert_eq!(exec_res.requests, vec![Requests::new(vec![request])]); assert_eq!(exec_res.requests, vec![Requests::new(vec![request])]);
@ -838,7 +826,7 @@ mod tests {
}); });
// Create a Receipts object containing the receipt. // 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. // Create a request.
let request = bytes!("deadbeef"); let request = bytes!("deadbeef");
@ -861,9 +849,7 @@ mod tests {
exec_res, exec_res,
ExecutionOutcome { ExecutionOutcome {
bundle: Default::default(), bundle: Default::default(),
receipts: Receipts { receipts: vec![vec![Some(receipt.clone())], vec![Some(receipt)]],
receipt_vec: vec![vec![Some(receipt.clone())], vec![Some(receipt)]]
},
requests: vec![Requests::new(vec![request.clone()]), Requests::new(vec![request])], requests: vec![Requests::new(vec![request.clone()]), Requests::new(vec![request])],
first_block: 123, first_block: 123,
} }
@ -880,13 +866,11 @@ mod tests {
}); });
// Create a Receipts object with a vector of receipt vectors // Create a Receipts object with a vector of receipt vectors
let receipts = Receipts { let receipts = vec![
receipt_vec: vec![ vec![Some(receipt.clone())],
vec![Some(receipt.clone())], vec![Some(receipt.clone())],
vec![Some(receipt.clone())], vec![Some(receipt.clone())],
vec![Some(receipt.clone())], ];
],
};
// Define the first block number // Define the first block number
let first_block = 123; let first_block = 123;
@ -912,7 +896,7 @@ mod tests {
// Define the expected lower ExecutionOutcome after splitting // Define the expected lower ExecutionOutcome after splitting
let lower_execution_outcome = ExecutionOutcome { let lower_execution_outcome = ExecutionOutcome {
bundle: Default::default(), 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()])], requests: vec![Requests::new(vec![request.clone()])],
first_block, first_block,
}; };
@ -920,9 +904,7 @@ mod tests {
// Define the expected higher ExecutionOutcome after splitting // Define the expected higher ExecutionOutcome after splitting
let higher_execution_outcome = ExecutionOutcome { let higher_execution_outcome = ExecutionOutcome {
bundle: Default::default(), bundle: Default::default(),
receipts: Receipts { receipts: vec![vec![Some(receipt.clone())], vec![Some(receipt)]],
receipt_vec: vec![vec![Some(receipt.clone())], vec![Some(receipt)]],
},
requests: vec![Requests::new(vec![request.clone()]), Requests::new(vec![request])], requests: vec![Requests::new(vec![request.clone()]), Requests::new(vec![request])],
first_block: 124, first_block: 124,
}; };

View File

@ -359,7 +359,7 @@ where
let block_number = ctx.block_number(); let block_number = ctx.block_number();
let execution_outcome = ExecutionOutcome::new( let execution_outcome = ExecutionOutcome::new(
state.take_bundle(), state.take_bundle(),
info.receipts.into(), vec![info.receipts],
block_number, block_number,
Vec::new(), Vec::new(),
); );

View File

@ -104,11 +104,8 @@ where
let timestamp = block_env.timestamp.to::<u64>(); let timestamp = block_env.timestamp.to::<u64>();
let transactions_root = calculate_transaction_root(&transactions); let transactions_root = calculate_transaction_root(&transactions);
let receipts_root = calculate_receipt_root_no_memo_optimism( let receipts_root =
&receipts.iter().collect::<Vec<_>>(), calculate_receipt_root_no_memo_optimism(receipts, &chain_spec, timestamp);
&chain_spec,
timestamp,
);
let logs_bloom = logs_bloom(receipts.iter().flat_map(|r| r.logs())); let logs_bloom = logs_bloom(receipts.iter().flat_map(|r| r.logs()));
let is_cancun = chain_spec.is_cancun_active_at_timestamp(timestamp); let is_cancun = chain_spec.is_cancun_active_at_timestamp(timestamp);

View File

@ -20,15 +20,12 @@ reth-static-file-types.workspace = true
# ethereum # ethereum
alloy-consensus.workspace = true alloy-consensus.workspace = true
alloy-primitives = { workspace = true, features = ["rand", "rlp"] }
# for eip-4844 # for eip-4844
c-kzg = { workspace = true, features = ["serde"], optional = true } c-kzg = { workspace = true, features = ["serde"], optional = true }
# misc # misc
derive_more.workspace = true
once_cell.workspace = true once_cell.workspace = true
serde.workspace = true
# arbitrary utils # arbitrary utils
arbitrary = { workspace = true, features = ["derive"], optional = true } arbitrary = { workspace = true, features = ["derive"], optional = true }
@ -37,6 +34,7 @@ arbitrary = { workspace = true, features = ["derive"], optional = true }
# eth # eth
reth-primitives-traits = { workspace = true, features = ["arbitrary", "test-utils"] } reth-primitives-traits = { workspace = true, features = ["arbitrary", "test-utils"] }
alloy-primitives.workspace = true
alloy-rlp.workspace = true alloy-rlp.workspace = true
alloy-eips = { workspace = true, features = ["arbitrary"] } alloy-eips = { workspace = true, features = ["arbitrary"] }
alloy-genesis.workspace = true alloy-genesis.workspace = true
@ -58,21 +56,21 @@ std = [
"alloy-consensus/std", "alloy-consensus/std",
"alloy-eips/std", "alloy-eips/std",
"alloy-genesis/std", "alloy-genesis/std",
"alloy-primitives/std",
"once_cell/std", "once_cell/std",
"serde/std",
"reth-ethereum-forks/std", "reth-ethereum-forks/std",
"derive_more/std",
"serde_json/std", "serde_json/std",
"reth-ethereum-primitives/std", "reth-ethereum-primitives/std",
"alloy-rlp/std", "alloy-rlp/std",
"alloy-primitives/std",
] ]
reth-codec = [ reth-codec = [
"std", "std",
"reth-primitives-traits/reth-codec", "reth-primitives-traits/reth-codec",
"reth-ethereum-primitives/reth-codec", "reth-ethereum-primitives/reth-codec",
] ]
asm-keccak = ["alloy-primitives/asm-keccak"] asm-keccak = [
"alloy-primitives/asm-keccak",
]
arbitrary = [ arbitrary = [
"dep:arbitrary", "dep:arbitrary",
"alloy-eips/arbitrary", "alloy-eips/arbitrary",
@ -80,9 +78,9 @@ arbitrary = [
"reth-ethereum-forks/arbitrary", "reth-ethereum-forks/arbitrary",
"reth-primitives-traits/arbitrary", "reth-primitives-traits/arbitrary",
"alloy-consensus/arbitrary", "alloy-consensus/arbitrary",
"alloy-primitives/arbitrary",
"reth-ethereum-primitives/arbitrary", "reth-ethereum-primitives/arbitrary",
"reth-codecs/arbitrary", "reth-codecs/arbitrary",
"alloy-primitives/arbitrary",
] ]
secp256k1 = [ secp256k1 = [
"reth-primitives-traits/secp256k1", "reth-primitives-traits/secp256k1",

View File

@ -19,8 +19,6 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
mod block; mod block;
mod receipt; mod receipt;
pub use reth_static_file_types as static_file; pub use reth_static_file_types as static_file;
@ -31,7 +29,7 @@ pub use block::{Block, BlockBody, SealedBlock};
#[allow(deprecated)] #[allow(deprecated)]
pub use block::{BlockWithSenders, SealedBlockFor, SealedBlockWithSenders}; 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::{ pub use reth_primitives_traits::{
logs_bloom, Account, Bytecode, GotExpected, GotExpectedBoxed, Header, HeaderError, Log, logs_bloom, Account, Bytecode, GotExpected, GotExpectedBoxed, Header, HeaderError, Log,
LogData, NodePrimitives, RecoveredBlock, SealedHeader, StorageEntry, LogData, NodePrimitives, RecoveredBlock, SealedHeader, StorageEntry,

View File

@ -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). /// Retrieves gas spent by transactions as a vector of tuples (transaction index, gas used).
pub use reth_primitives_traits::receipt::gas_spent_by_transactions; pub use reth_primitives_traits::receipt::gas_spent_by_transactions;
/// Receipt containing result of transaction execution. /// Receipt containing result of transaction execution.
pub use reth_ethereum_primitives::Receipt; 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<T = Receipt> {
/// A two-dimensional vector of optional `Receipt` instances.
pub receipt_vec: Vec<Vec<T>>,
}
impl<T> Receipts<T> {
/// 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<T>) {
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::<Vec<_>>();
f(receipts.as_slice())
}
}
impl<T> From<Vec<T>> for Receipts<T> {
fn from(block_receipts: Vec<T>) -> Self {
Self { receipt_vec: vec![block_receipts.into_iter().collect()] }
}
}
impl<T> FromIterator<Vec<T>> for Receipts<T> {
fn from_iter<I: IntoIterator<Item = Vec<T>>>(iter: I) -> Self {
iter.into_iter().collect::<Vec<_>>().into()
}
}
impl<T> Default for Receipts<T> {
fn default() -> Self {
Self { receipt_vec: Vec::new() }
}
}

View File

@ -4,7 +4,6 @@ use alloc::vec::Vec;
use alloy_eips::eip7685::Requests; use alloy_eips::eip7685::Requests;
use alloy_primitives::BlockNumber; use alloy_primitives::BlockNumber;
use reth_primitives::Receipts;
/// Takes care of: /// Takes care of:
/// - recording receipts during execution of multiple blocks. /// - recording receipts during execution of multiple blocks.
@ -17,7 +16,7 @@ pub struct BlockBatchRecord<T = reth_primitives::Receipt> {
/// The inner vector stores receipts ordered by transaction number. /// The inner vector stores receipts ordered by transaction number.
/// ///
/// If receipt is None it means it is pruned. /// If receipt is None it means it is pruned.
receipts: Receipts<T>, receipts: Vec<Vec<T>>,
/// The collection of EIP-7685 requests. /// The collection of EIP-7685 requests.
/// Outer vector stores requests for each block sequentially. /// Outer vector stores requests for each block sequentially.
/// The inner vector stores requests ordered by transaction number. /// The inner vector stores requests ordered by transaction number.
@ -57,12 +56,12 @@ impl<T> BlockBatchRecord<T> {
} }
/// Returns the recorded receipts. /// Returns the recorded receipts.
pub const fn receipts(&self) -> &Receipts<T> { pub const fn receipts(&self) -> &Vec<Vec<T>> {
&self.receipts &self.receipts
} }
/// Returns all recorded receipts. /// Returns all recorded receipts.
pub fn take_receipts(&mut self) -> Receipts<T> { pub fn take_receipts(&mut self) -> Vec<Vec<T>> {
core::mem::take(&mut self.receipts) core::mem::take(&mut self.receipts)
} }
@ -99,6 +98,6 @@ mod tests {
recorder.save_receipts(receipts); recorder.save_receipts(receipts);
// Verify that the saved receipts are equal to a nested empty vector // 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![]]);
} }
} }

View File

@ -62,8 +62,7 @@ where
let chain_spec = self.provider().chain_spec(); let chain_spec = self.provider().chain_spec();
let transactions_root = calculate_transaction_root(&transactions); let transactions_root = calculate_transaction_root(&transactions);
let receipts_root = let receipts_root = Receipt::calculate_receipt_root_no_memo(receipts);
Receipt::calculate_receipt_root_no_memo(&receipts.iter().collect::<Vec<_>>());
let logs_bloom = logs_bloom(receipts.iter().flat_map(|r| &r.logs)); let logs_bloom = logs_bloom(receipts.iter().flat_map(|r| &r.logs));

View File

@ -10,7 +10,7 @@ use reth_db::tables;
use reth_db_api::{transaction::DbTxMut, DatabaseError}; use reth_db_api::{transaction::DbTxMut, DatabaseError};
use reth_etl::Collector; use reth_etl::Collector;
use reth_primitives::{ use reth_primitives::{
Account, Bytecode, GotExpected, NodePrimitives, Receipts, StaticFileSegment, StorageEntry, Account, Bytecode, GotExpected, NodePrimitives, StaticFileSegment, StorageEntry,
}; };
use reth_provider::{ use reth_provider::{
errors::provider::ProviderResult, providers::StaticFileWriter, writer::UnifiedStorageWriter, errors::provider::ProviderResult, providers::StaticFileWriter, writer::UnifiedStorageWriter,
@ -246,7 +246,7 @@ where
state_init, state_init,
all_reverts_init, all_reverts_init,
contracts, contracts,
Receipts::default(), Vec::default(),
block, block,
Vec::new(), Vec::new(),
); );

View File

@ -928,7 +928,7 @@ mod tests {
let senders = block.senders().expect("failed to recover senders"); let senders = block.senders().expect("failed to recover senders");
let block_receipts = receipts.get(block.number as usize).unwrap().clone(); let block_receipts = receipts.get(block.number as usize).unwrap().clone();
let execution_outcome = let execution_outcome =
ExecutionOutcome { receipts: block_receipts.into(), ..Default::default() }; ExecutionOutcome { receipts: vec![block_receipts], ..Default::default() };
ExecutedBlockWithTrieUpdates::new( ExecutedBlockWithTrieUpdates::new(
Arc::new(RecoveredBlock::new_sealed(block.clone(), senders)), Arc::new(RecoveredBlock::new_sealed(block.clone(), senders)),

View File

@ -208,7 +208,7 @@ impl<N: ProviderNodeTypes> ConsistentProvider<N> {
reverts, reverts,
// We skip new contracts since we never delete them from the database // We skip new contracts since we never delete them from the database
Vec::new(), Vec::new(),
receipts.into(), receipts,
start_block_number, start_block_number,
Vec::new(), Vec::new(),
))) )))

View File

@ -2289,7 +2289,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider> StateWriter
state, state,
reverts, reverts,
Vec::new(), Vec::new(),
receipts.into(), receipts,
start_block_number, start_block_number,
Vec::new(), Vec::new(),
)) ))

View File

@ -220,8 +220,7 @@ fn block1(number: BlockNumber) -> (RecoveredBlock<reth_primitives::Block>, Execu
)], )],
..Default::default() ..Default::default()
}, },
]] ]],
.into(),
number, number,
Vec::new(), Vec::new(),
); );
@ -279,8 +278,7 @@ fn block2(
)], )],
..Default::default() ..Default::default()
}, },
]] ]],
.into(),
number, number,
Vec::new(), Vec::new(),
); );
@ -347,8 +345,7 @@ fn block3(
)], )],
..Default::default() ..Default::default()
}, },
]] ]],
.into(),
number, number,
Vec::new(), Vec::new(),
); );
@ -435,8 +432,7 @@ fn block4(
)], )],
..Default::default() ..Default::default()
}, },
]] ]],
.into(),
number, number,
Vec::new(), Vec::new(),
); );
@ -520,8 +516,7 @@ fn block5(
)], )],
..Default::default() ..Default::default()
}, },
]] ]],
.into(),
number, number,
Vec::new(), Vec::new(),
); );

View File

@ -235,7 +235,7 @@ mod tests {
transaction::{DbTx, DbTxMut}, transaction::{DbTx, DbTxMut},
}; };
use reth_execution_types::ExecutionOutcome; 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_storage_api::{DatabaseProviderFactory, HashedPostStateProvider};
use reth_trie::{ use reth_trie::{
test_utils::{state_root, storage_root_prehashed}, test_utils::{state_root, storage_root_prehashed},
@ -498,8 +498,7 @@ mod tests {
state.merge_transitions(BundleRetention::Reverts); state.merge_transitions(BundleRetention::Reverts);
let outcome = let outcome = ExecutionOutcome::new(state.take_bundle(), Default::default(), 1, Vec::new());
ExecutionOutcome::new(state.take_bundle(), Receipts::default(), 1, Vec::new());
provider provider
.write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database) .write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database)
.expect("Could not write bundle state to DB"); .expect("Could not write bundle state to DB");
@ -598,8 +597,7 @@ mod tests {
)])); )]));
state.merge_transitions(BundleRetention::Reverts); state.merge_transitions(BundleRetention::Reverts);
let outcome = let outcome = ExecutionOutcome::new(state.take_bundle(), Default::default(), 2, Vec::new());
ExecutionOutcome::new(state.take_bundle(), Receipts::default(), 2, Vec::new());
provider provider
.write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database) .write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database)
.expect("Could not write bundle state to DB"); .expect("Could not write bundle state to DB");
@ -666,7 +664,7 @@ mod tests {
init_state.merge_transitions(BundleRetention::Reverts); init_state.merge_transitions(BundleRetention::Reverts);
let outcome = 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 provider
.write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database) .write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database)
.expect("Could not write bundle state to DB"); .expect("Could not write bundle state to DB");
@ -814,7 +812,7 @@ mod tests {
let bundle = state.take_bundle(); let bundle = state.take_bundle();
let outcome: ExecutionOutcome = let outcome: ExecutionOutcome =
ExecutionOutcome::new(bundle, Receipts::default(), 1, Vec::new()); ExecutionOutcome::new(bundle, Default::default(), 1, Vec::new());
provider provider
.write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database) .write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database)
.expect("Could not write bundle state to DB"); .expect("Could not write bundle state to DB");
@ -979,7 +977,7 @@ mod tests {
)])); )]));
init_state.merge_transitions(BundleRetention::Reverts); init_state.merge_transitions(BundleRetention::Reverts);
let outcome = 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 provider
.write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database) .write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database)
.expect("Could not write bundle state to DB"); .expect("Could not write bundle state to DB");
@ -1025,8 +1023,7 @@ mod tests {
// Commit block #1 changes to the database. // Commit block #1 changes to the database.
state.merge_transitions(BundleRetention::Reverts); state.merge_transitions(BundleRetention::Reverts);
let outcome = let outcome = ExecutionOutcome::new(state.take_bundle(), Default::default(), 1, Vec::new());
ExecutionOutcome::new(state.take_bundle(), Receipts::default(), 1, Vec::new());
provider provider
.write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database) .write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database)
.expect("Could not write bundle state to DB"); .expect("Could not write bundle state to DB");
@ -1059,7 +1056,7 @@ mod tests {
fn revert_to_indices() { fn revert_to_indices() {
let base: ExecutionOutcome = ExecutionOutcome { let base: ExecutionOutcome = ExecutionOutcome {
bundle: BundleState::default(), bundle: BundleState::default(),
receipts: vec![vec![Receipt::default(); 2]; 7].into(), receipts: vec![vec![Receipt::default(); 2]; 7],
first_block: 10, first_block: 10,
requests: Vec::new(), requests: Vec::new(),
}; };
@ -1270,7 +1267,7 @@ mod tests {
let mut test: ExecutionOutcome = ExecutionOutcome { let mut test: ExecutionOutcome = ExecutionOutcome {
bundle: present_state, bundle: present_state,
receipts: vec![vec![Receipt::default(); 2]; 1].into(), receipts: vec![vec![Receipt::default(); 2]; 1],
first_block: 2, first_block: 2,
requests: Vec::new(), requests: Vec::new(),
}; };

View File

@ -589,7 +589,7 @@ impl<P> RevealedSparseTrie<P> {
// Get the nodes that have changed at the given depth. // 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); 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; self.prefix_set = new_prefix_set;
trace!(target: "trie::sparse", ?depth, ?targets, "Updating nodes at depth"); trace!(target: "trie::sparse", ?depth, ?targets, "Updating nodes at depth");

View File

@ -16,7 +16,7 @@ reth-primitives = { workspace = true, features = ["secp256k1", "arbitrary"] }
reth-primitives-traits = { workspace = true, features = ["secp256k1", "arbitrary"] } reth-primitives-traits = { workspace = true, features = ["secp256k1", "arbitrary"] }
alloy-genesis.workspace = true alloy-genesis.workspace = true
alloy-primitives.workspace = true alloy-primitives = { workspace = true, features = ["rand"] }
alloy-consensus.workspace = true alloy-consensus.workspace = true
alloy-eips.workspace = true alloy-eips.workspace = true