Skip to content

Commit

Permalink
return previous checkpoint if pruner didn't finish
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin committed Jul 10, 2024
1 parent 65730f3 commit 47669ba
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 36 deletions.
19 changes: 6 additions & 13 deletions crates/stages/stages/src/stages/prune.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use reth_db_api::database::Database;
use reth_provider::{DatabaseProviderRW, PruneCheckpointReader};
use reth_provider::DatabaseProviderRW;
use reth_prune::{PruneModes, PrunerBuilder};
use reth_stages_api::{
ExecInput, ExecOutput, Stage, StageCheckpoint, StageError, StageId, UnwindInput, UnwindOutput,
Expand Down Expand Up @@ -47,18 +47,11 @@ impl<DB: Database> Stage<DB> for PruneStage {
.build();

let result = pruner.run(provider, input.target())?;
let lowest_pruned_block = provider
.get_prune_checkpoints()?
.into_iter()
.map(|(_, checkpoint)| checkpoint.block_number)
.min()
.flatten()
.unwrap_or_else(|| input.target());

Ok(ExecOutput {
checkpoint: StageCheckpoint::new(lowest_pruned_block),
done: result.is_finished(),
})
if result.is_finished() {
Ok(ExecOutput { checkpoint: StageCheckpoint::new(input.target()), done: true })
} else {
Ok(ExecOutput { checkpoint: input.checkpoint(), done: false })
}
}

fn unwind(
Expand Down
4 changes: 0 additions & 4 deletions crates/storage/provider/src/providers/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,6 @@ impl<DB: Database> PruneCheckpointReader for ProviderFactory<DB> {
) -> ProviderResult<Option<PruneCheckpoint>> {
self.provider()?.get_prune_checkpoint(segment)
}

fn get_prune_checkpoints(&self) -> ProviderResult<Vec<(PruneSegment, PruneCheckpoint)>> {
self.provider()?.get_prune_checkpoints()
}
}

impl<DB> Clone for ProviderFactory<DB> {
Expand Down
8 changes: 0 additions & 8 deletions crates/storage/provider/src/providers/database/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2822,14 +2822,6 @@ impl<TX: DbTx> PruneCheckpointReader for DatabaseProvider<TX> {
) -> ProviderResult<Option<PruneCheckpoint>> {
Ok(self.tx.get::<tables::PruneCheckpoints>(segment)?)
}

fn get_prune_checkpoints(&self) -> ProviderResult<Vec<(PruneSegment, PruneCheckpoint)>> {
Ok(self
.tx
.cursor_read::<tables::PruneCheckpoints>()?
.walk(None)?
.collect::<Result<Vec<_>, _>>()?)
}
}

impl<TX: DbTxMut> PruneCheckpointWriter for DatabaseProvider<TX> {
Expand Down
4 changes: 0 additions & 4 deletions crates/storage/provider/src/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,6 @@ where
) -> ProviderResult<Option<PruneCheckpoint>> {
self.database.provider()?.get_prune_checkpoint(segment)
}

fn get_prune_checkpoints(&self) -> ProviderResult<Vec<(PruneSegment, PruneCheckpoint)>> {
self.database.provider()?.get_prune_checkpoints()
}
}

impl<DB> ChainSpecProvider for BlockchainProvider<DB>
Expand Down
4 changes: 0 additions & 4 deletions crates/storage/provider/src/test_utils/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,6 @@ impl PruneCheckpointReader for NoopProvider {
) -> ProviderResult<Option<PruneCheckpoint>> {
Ok(None)
}

fn get_prune_checkpoints(&self) -> ProviderResult<Vec<(PruneSegment, PruneCheckpoint)>> {
Ok(vec![])
}
}

impl StaticFileProviderFactory for NoopProvider {
Expand Down
3 changes: 0 additions & 3 deletions crates/storage/storage-api/src/prune_checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ pub trait PruneCheckpointReader: Send + Sync {
&self,
segment: PruneSegment,
) -> ProviderResult<Option<PruneCheckpoint>>;

/// Fetch the checkpoints for all prune segments.
fn get_prune_checkpoints(&self) -> ProviderResult<Vec<(PruneSegment, PruneCheckpoint)>>;
}

/// The trait for updating prune checkpoint related data.
Expand Down

0 comments on commit 47669ba

Please sign in to comment.