mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: remove PruneModes from batch executor (#14025)
This commit is contained in:
@ -15,7 +15,6 @@ workspace = true
|
||||
# reth
|
||||
reth-primitives.workspace = true
|
||||
reth-storage-errors.workspace = true
|
||||
reth-prune-types.workspace = true
|
||||
reth-storage-api.workspace = true
|
||||
reth-trie = { workspace = true, optional = true }
|
||||
|
||||
@ -48,7 +47,6 @@ test-utils = [
|
||||
"reth-primitives/test-utils",
|
||||
"reth-trie?/test-utils",
|
||||
"revm/test-utils",
|
||||
"reth-prune-types/test-utils",
|
||||
]
|
||||
serde = [
|
||||
"revm/serde",
|
||||
|
||||
@ -5,8 +5,6 @@ use alloc::vec::Vec;
|
||||
use alloy_eips::eip7685::Requests;
|
||||
use alloy_primitives::BlockNumber;
|
||||
use reth_primitives::Receipts;
|
||||
use reth_prune_types::PruneModes;
|
||||
use revm::db::states::bundle_state::BundleRetention;
|
||||
|
||||
/// Takes care of:
|
||||
/// - recording receipts during execution of multiple blocks.
|
||||
@ -14,8 +12,6 @@ use revm::db::states::bundle_state::BundleRetention;
|
||||
/// - batch range if known
|
||||
#[derive(Debug)]
|
||||
pub struct BlockBatchRecord<T = reth_primitives::Receipt> {
|
||||
/// Pruning configuration.
|
||||
prune_modes: PruneModes,
|
||||
/// The collection of receipts.
|
||||
/// Outer vector stores receipts for each block sequentially.
|
||||
/// The inner vector stores receipts ordered by transaction number.
|
||||
@ -32,31 +28,22 @@ pub struct BlockBatchRecord<T = reth_primitives::Receipt> {
|
||||
/// First block will be initialized to `None`
|
||||
/// and be set to the block number of first block executed.
|
||||
first_block: Option<BlockNumber>,
|
||||
/// The maximum known block.
|
||||
tip: Option<BlockNumber>,
|
||||
}
|
||||
|
||||
impl<T> Default for BlockBatchRecord<T> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
prune_modes: Default::default(),
|
||||
receipts: Default::default(),
|
||||
requests: Default::default(),
|
||||
first_block: Default::default(),
|
||||
tip: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> BlockBatchRecord<T> {
|
||||
/// Create a new receipts recorder with the given pruning configuration.
|
||||
pub fn new(prune_modes: PruneModes) -> Self {
|
||||
Self { prune_modes, ..Default::default() }
|
||||
}
|
||||
|
||||
/// Set prune modes.
|
||||
pub fn set_prune_modes(&mut self, prune_modes: PruneModes) {
|
||||
self.prune_modes = prune_modes;
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
/// Set the first block number of the batch.
|
||||
@ -69,16 +56,6 @@ impl<T> BlockBatchRecord<T> {
|
||||
self.first_block
|
||||
}
|
||||
|
||||
/// Set tip - highest known block number.
|
||||
pub fn set_tip(&mut self, tip: BlockNumber) {
|
||||
self.tip = Some(tip);
|
||||
}
|
||||
|
||||
/// Returns the tip of the batch if known.
|
||||
pub const fn tip(&self) -> Option<BlockNumber> {
|
||||
self.tip
|
||||
}
|
||||
|
||||
/// Returns the recorded receipts.
|
||||
pub const fn receipts(&self) -> &Receipts<T> {
|
||||
&self.receipts
|
||||
@ -99,24 +76,6 @@ impl<T> BlockBatchRecord<T> {
|
||||
core::mem::take(&mut self.requests)
|
||||
}
|
||||
|
||||
/// Returns the [`BundleRetention`] for the given block based on the configured prune modes.
|
||||
pub fn bundle_retention(&self, block_number: BlockNumber) -> BundleRetention {
|
||||
if self.tip.is_none_or(|tip| {
|
||||
!self
|
||||
.prune_modes
|
||||
.account_history
|
||||
.is_some_and(|mode| mode.should_prune(block_number, tip)) &&
|
||||
!self
|
||||
.prune_modes
|
||||
.storage_history
|
||||
.is_some_and(|mode| mode.should_prune(block_number, tip))
|
||||
}) {
|
||||
BundleRetention::Reverts
|
||||
} else {
|
||||
BundleRetention::PlainState
|
||||
}
|
||||
}
|
||||
|
||||
/// Save receipts to the executor.
|
||||
pub fn save_receipts(&mut self, receipts: Vec<T>) {
|
||||
self.receipts.push(receipts);
|
||||
|
||||
Reference in New Issue
Block a user