Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin committed Jan 29, 2024
1 parent f1aa297 commit a67ebec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions crates/primitives/src/stage/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/// For custom stages, use [`StageId::Other`]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum StageId {
/// Snapshot stage in the process.
Snapshot,
/// Header stage in the process.
Headers,
Expand Down
3 changes: 3 additions & 0 deletions crates/stages/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ pub enum StageError {
/// Expected static file block number.
static_file: BlockNumber,
},
/// Unwind is not supported for this stage.
#[error("unwind not supported")]
UnwindNotSupported,
/// Internal error
#[error(transparent)]
Internal(#[from] RethError),
Expand Down
12 changes: 7 additions & 5 deletions crates/stages/src/stages/snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::{ExecInput, ExecOutput, Stage, StageError, UnwindInput, UnwindOutput};
use reth_db::database::Database;
use reth_primitives::stage::{StageCheckpoint, StageId};
use reth_primitives::stage::StageId;
use reth_provider::{BlockNumReader, DatabaseProviderRW};
use reth_snapshot::Snapshotter;

/// The snapshot stage.
/// The snapshot stage _copies_ all data from database to static files using [Snapshotter]. The
/// block range for copying is determined by the current highest blocks contained in static files
/// and [BlockNumReader::best_block_number],
/// i.e. the range is `highest_snapshotted_block_number..=best_block_number`.
#[derive(Debug)]
pub struct SnapshotStage<DB: Database> {
snapshotter: Snapshotter<DB>,
Expand All @@ -29,15 +32,14 @@ impl<DB: Database> Stage<DB> for SnapshotStage<DB> {
) -> Result<ExecOutput, StageError> {
let targets = self.snapshotter.get_snapshot_targets(provider.best_block_number()?)?;
self.snapshotter.run(targets)?;
Ok(ExecOutput { checkpoint: StageCheckpoint::new(input.target()), done: true })
Ok(ExecOutput::done(input.checkpoint()))
}

fn unwind(
&mut self,
_provider: &DatabaseProviderRW<DB>,
_input: UnwindInput,
) -> Result<UnwindOutput, StageError> {
// TODO(alexey): return proper error
Err(StageError::ChannelClosed)
Err(StageError::UnwindNotSupported)
}
}

0 comments on commit a67ebec

Please sign in to comment.