mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: remove Receipts struct (#14130)
This commit is contained in:
@ -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<N, P, F>(
|
||||
where
|
||||
N: ProviderNodeTypes<ChainSpec = OpChainSpec, Primitives: NodePrimitives<Receipt = OpReceipt>>,
|
||||
P: AsRef<Path>,
|
||||
F: FnMut(u64, &mut Receipts<OpReceipt>) -> usize,
|
||||
F: FnMut(u64, &mut Vec<Vec<OpReceipt>>) -> 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<N, F>(
|
||||
provider_factory: &ProviderFactory<N>,
|
||||
mut reader: ChunkedFileReader,
|
||||
@ -127,7 +127,7 @@ pub async fn import_receipts_from_reader<N, F>(
|
||||
) -> eyre::Result<ImportReceiptsResult>
|
||||
where
|
||||
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();
|
||||
|
||||
@ -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}.");
|
||||
}
|
||||
|
||||
@ -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.
|
||||
pub fn calculate_receipt_root_no_memo_optimism(
|
||||
receipts: &[&OpReceipt],
|
||||
receipts: &[OpReceipt],
|
||||
chain_spec: impl OpHardforks,
|
||||
timestamp: u64,
|
||||
) -> B256 {
|
||||
|
||||
@ -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::<LogData>::default()],
|
||||
status: true.into(),
|
||||
})]],
|
||||
};
|
||||
let receipts = vec![vec![OpReceipt::Legacy(Receipt {
|
||||
cumulative_gas_used: 46913,
|
||||
logs: vec![Log::<LogData>::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::<LogData>::default()],
|
||||
status: true.into(),
|
||||
}))]],
|
||||
};
|
||||
let receipts = vec![vec![Some(OpReceipt::Legacy(Receipt {
|
||||
cumulative_gas_used: 46913,
|
||||
logs: vec![Log::<LogData>::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::<LogData>::default()],
|
||||
status: true.into(),
|
||||
}))]],
|
||||
};
|
||||
let receipts = vec![vec![Some(OpReceipt::Legacy(Receipt {
|
||||
cumulative_gas_used: 46913,
|
||||
logs: vec![Log::<LogData>::default()],
|
||||
status: true.into(),
|
||||
}))]];
|
||||
|
||||
// Create an empty Receipts object
|
||||
let receipts_empty = Receipts::<Receipt> { 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<OpReceipt> = 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,
|
||||
};
|
||||
|
||||
@ -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(),
|
||||
);
|
||||
|
||||
@ -104,11 +104,8 @@ where
|
||||
let timestamp = block_env.timestamp.to::<u64>();
|
||||
|
||||
let transactions_root = calculate_transaction_root(&transactions);
|
||||
let receipts_root = calculate_receipt_root_no_memo_optimism(
|
||||
&receipts.iter().collect::<Vec<_>>(),
|
||||
&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);
|
||||
|
||||
Reference in New Issue
Block a user