Skip to content

Commit

Permalink
snapshot from zero
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin committed Jan 25, 2024
1 parent 076926b commit f93a730
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions crates/snapshot/src/snapshotter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,9 @@ impl SnapshotTargets {
.iter()
.all(|(target_block_range, highest_snapshotted_block)| {
target_block_range.map_or(true, |target_block_range| {
highest_snapshotted_block.map_or(
*target_block_range.start() == 1,
|highest_snapshotted_block| {
*target_block_range.start() == highest_snapshotted_block + 1
},
)
*target_block_range.start() ==
highest_snapshotted_block
.map_or(0, |highest_snapshotted_block| highest_snapshotted_block + 1)
})
})
}
Expand Down Expand Up @@ -158,7 +155,7 @@ impl<DB: Database> Snapshotter<DB> {
highest_snapshot: Option<BlockNumber>,
finalized_block_number: BlockNumber,
) -> Option<RangeInclusive<BlockNumber>> {
let range = highest_snapshot.unwrap_or_default() + 1..=finalized_block_number;
let range = highest_snapshot.map_or(0, |block| block + 1)..=finalized_block_number;
(!range.is_empty()).then_some(range)
}
}
Expand All @@ -180,8 +177,8 @@ mod tests {

let db = TestStageDB::default();

let blocks = random_block_range(&mut rng, 1..=3, B256::ZERO, 2..3);
db.insert_blocks(blocks.iter(), Some(1)).expect("insert blocks");
let blocks = random_block_range(&mut rng, 0..=3, B256::ZERO, 2..3);
db.insert_blocks(blocks.iter(), None).expect("insert blocks");

let snapshots_dir = tempfile::TempDir::new().unwrap();
let provider_factory = db
Expand All @@ -195,7 +192,7 @@ mod tests {
let targets = snapshotter.get_snapshot_targets(1).expect("get snapshot targets");
assert_eq!(
targets,
SnapshotTargets { headers: Some(1..=1), receipts: None, transactions: Some(1..=1) }
SnapshotTargets { headers: Some(0..=1), receipts: None, transactions: Some(0..=1) }
);
assert_matches!(snapshotter.run(targets), Ok(_));
assert_eq!(
Expand Down

0 comments on commit f93a730

Please sign in to comment.