mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-15 09:25:33 -05:00
fix(op): stages checkpoints init-state (#8021)
This commit is contained in:
@@ -6,6 +6,8 @@ use bytes::Buf;
|
||||
use reth_codecs::{main_codec, Compact};
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
use super::StageId;
|
||||
|
||||
/// Saves the progress of Merkle stage.
|
||||
#[derive(Default, Debug, Clone, PartialEq)]
|
||||
pub struct MerkleCheckpoint {
|
||||
@@ -201,6 +203,25 @@ impl StageCheckpoint {
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the block range, if checkpoint uses block range.
|
||||
pub fn with_block_range(mut self, stage_id: &StageId, from: u64, to: u64) -> Self {
|
||||
self.stage_checkpoint = Some(match stage_id {
|
||||
StageId::Execution => StageUnitCheckpoint::Execution(ExecutionCheckpoint::default()),
|
||||
StageId::AccountHashing => {
|
||||
StageUnitCheckpoint::Account(AccountHashingCheckpoint::default())
|
||||
}
|
||||
StageId::StorageHashing => {
|
||||
StageUnitCheckpoint::Storage(StorageHashingCheckpoint::default())
|
||||
}
|
||||
StageId::IndexStorageHistory | StageId::IndexAccountHistory => {
|
||||
StageUnitCheckpoint::IndexHistory(IndexHistoryCheckpoint::default())
|
||||
}
|
||||
_ => return self,
|
||||
});
|
||||
_ = self.stage_checkpoint.map(|mut checkpoint| checkpoint.set_block_range(from, to));
|
||||
self
|
||||
}
|
||||
|
||||
/// Get the underlying [`EntitiesCheckpoint`], if any, to determine the number of entities
|
||||
/// processed, and the number of total entities to process.
|
||||
pub fn entities(&self) -> Option<EntitiesCheckpoint> {
|
||||
@@ -244,6 +265,25 @@ pub enum StageUnitCheckpoint {
|
||||
IndexHistory(IndexHistoryCheckpoint),
|
||||
}
|
||||
|
||||
impl StageUnitCheckpoint {
|
||||
/// Sets the block range. Returns old block range, or `None` if checkpoint doesn't use block
|
||||
/// range.
|
||||
pub fn set_block_range(&mut self, from: u64, to: u64) -> Option<CheckpointBlockRange> {
|
||||
match self {
|
||||
Self::Account(AccountHashingCheckpoint { ref mut block_range, .. }) |
|
||||
Self::Storage(StorageHashingCheckpoint { ref mut block_range, .. }) |
|
||||
Self::Execution(ExecutionCheckpoint { ref mut block_range, .. }) |
|
||||
Self::IndexHistory(IndexHistoryCheckpoint { ref mut block_range, .. }) => {
|
||||
let old_range = *block_range;
|
||||
*block_range = CheckpointBlockRange { from, to };
|
||||
|
||||
Some(old_range)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl Default for StageUnitCheckpoint {
|
||||
fn default() -> Self {
|
||||
|
||||
@@ -53,6 +53,17 @@ impl StageId {
|
||||
StageId::Finish,
|
||||
];
|
||||
|
||||
/// Stages that require state.
|
||||
pub const STATE_REQUIRED: [StageId; 7] = [
|
||||
StageId::Execution,
|
||||
StageId::MerkleUnwind,
|
||||
StageId::AccountHashing,
|
||||
StageId::StorageHashing,
|
||||
StageId::MerkleExecute,
|
||||
StageId::IndexStorageHistory,
|
||||
StageId::IndexAccountHistory,
|
||||
];
|
||||
|
||||
/// Return stage id formatted as string.
|
||||
pub fn as_str(&self) -> &str {
|
||||
match self {
|
||||
|
||||
Reference in New Issue
Block a user