Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/optimism/trie/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ where
new_earliest_block_ref: BlockWithParent,
diff: BlockStateDiff,
) -> OpProofsStorageResult<()> {
self.metrics.block_metrics.earliest_number.set(new_earliest_block_ref.block.number as f64);
self.storage.prune_earliest_state(new_earliest_block_ref, diff).await
}

Expand Down
23 changes: 16 additions & 7 deletions crates/optimism/trie/src/prune/pruner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::prune::metrics::Metrics;
use crate::{
prune::error::{OpProofStoragePrunerResult, PrunerError, PrunerOutput},
BlockStateDiff, OpProofsStore,
BlockStateDiff, OpProofsStorage, OpProofsStore,
};
use alloy_eips::{eip1898::BlockWithParent, BlockNumHash};
use reth_provider::BlockHashReader;
Expand All @@ -13,7 +13,7 @@ use tracing::{error, info, trace};
#[derive(Debug)]
pub struct OpProofStoragePruner<P, H> {
// Database provider for the prune
provider: P,
provider: OpProofsStorage<P>,
/// Reader to fetch block hash by block number
block_hash_reader: H,
/// Keep at least these many recent blocks
Expand All @@ -26,7 +26,11 @@ pub struct OpProofStoragePruner<P, H> {

impl<P, H> OpProofStoragePruner<P, H> {
/// Create a new pruner.
pub fn new(provider: P, block_hash_reader: H, min_block_interval: u64) -> Self {
pub fn new(
provider: OpProofsStorage<P>,
block_hash_reader: H,
min_block_interval: u64,
) -> Self {
Self {
provider,
block_hash_reader,
Expand Down Expand Up @@ -206,7 +210,9 @@ mod tests {
async fn run_inner_and_and_verify_updated_state() {
// --- env/store ---
let dir = TempDir::new().unwrap();
let store = Arc::new(MdbxProofsStorage::new(dir.path()).expect("env"));
let store: OpProofsStorage<Arc<MdbxProofsStorage>> =
OpProofsStorage::from(Arc::new(MdbxProofsStorage::new(dir.path()).expect("env")));

store.set_earliest_block_number(0, B256::ZERO).await.expect("set earliest");

// --- entities ---
Expand Down Expand Up @@ -492,7 +498,8 @@ mod tests {
#[tokio::test]
async fn run_inner_where_latest_block_is_none() {
let dir = TempDir::new().unwrap();
let store = Arc::new(MdbxProofsStorage::new(dir.path()).expect("env"));
let store: OpProofsStorage<Arc<MdbxProofsStorage>> =
OpProofsStorage::from(Arc::new(MdbxProofsStorage::new(dir.path()).expect("env")));

let earliest = store.get_earliest_block_number().await.unwrap();
let latest = store.get_latest_block_number().await.unwrap();
Expand All @@ -512,7 +519,8 @@ mod tests {
use crate::BlockStateDiff;

let dir = TempDir::new().unwrap();
let store = Arc::new(MdbxProofsStorage::new(dir.path()).expect("env"));
let store: OpProofsStorage<Arc<MdbxProofsStorage>> =
OpProofsStorage::from(Arc::new(MdbxProofsStorage::new(dir.path()).expect("env")));

// Write a single block to set *latest* only.
store
Expand All @@ -537,7 +545,8 @@ mod tests {
use crate::BlockStateDiff;

let dir = TempDir::new().unwrap();
let store = Arc::new(MdbxProofsStorage::new(dir.path()).expect("env"));
let store: OpProofsStorage<Arc<MdbxProofsStorage>> =
OpProofsStorage::from(Arc::new(MdbxProofsStorage::new(dir.path()).expect("env")));

// Set earliest=4 explicitly
let earliest_num = 4u64;
Expand Down
4 changes: 2 additions & 2 deletions crates/optimism/trie/src/prune/task.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{prune::OpProofStoragePruner, OpProofsStore};
use crate::{prune::OpProofStoragePruner, OpProofsStorage, OpProofsStore};
use reth_provider::BlockHashReader;
use reth_tasks::shutdown::GracefulShutdown;
use tokio::{
Expand All @@ -22,7 +22,7 @@ where
{
/// Initialize a new [`OpProofStoragePrunerTask`]
pub fn new(
provider: P,
provider: OpProofsStorage<P>,
hash_reader: H,
min_block_interval: u64,
task_run_interval: Duration,
Expand Down
Loading