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 aefe1dd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 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
2 changes: 2 additions & 0 deletions crates/stages/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ pub enum StageError {
/// Expected static file block number.
static_file: BlockNumber,
},
#[error("unwind not supported for this stage")]
UnwindNotSupported,
/// Internal error
#[error(transparent)]
Internal(#[from] RethError),
Expand Down
10 changes: 6 additions & 4 deletions crates/stages/src/stages/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use reth_primitives::stage::{StageCheckpoint, 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 aefe1dd

Please sign in to comment.