fix(storage): invalid stage checkpoints on unwind (#3029)

This commit is contained in:
Alexey Shekhirin
2023-06-07 00:18:26 +04:00
committed by GitHub
parent c0fb169da4
commit 7eeecf0835

View File

@ -511,7 +511,7 @@ where
self.calculate_history_indices(first_number..=last_block_number)?; self.calculate_history_indices(first_number..=last_block_number)?;
// Update pipeline progress // Update pipeline progress
self.update_pipeline_stages(new_tip_number)?; self.update_pipeline_stages(new_tip_number, false)?;
Ok(()) Ok(())
} }
@ -1009,7 +1009,7 @@ where
// Update pipeline progress // Update pipeline progress
if let Some(fork_number) = unwind_to { if let Some(fork_number) = unwind_to {
self.update_pipeline_stages(fork_number)?; self.update_pipeline_stages(fork_number, true)?;
} }
} }
@ -1021,12 +1021,18 @@ where
pub fn update_pipeline_stages( pub fn update_pipeline_stages(
&self, &self,
block_number: BlockNumber, block_number: BlockNumber,
drop_stage_checkpoint: bool,
) -> Result<(), TransactionError> { ) -> Result<(), TransactionError> {
// iterate over all existing stages in the table and update its progress. // iterate over all existing stages in the table and update its progress.
let mut cursor = self.cursor_write::<tables::SyncStage>()?; let mut cursor = self.cursor_write::<tables::SyncStage>()?;
while let Some((stage_name, checkpoint)) = cursor.next()? { while let Some((stage_name, checkpoint)) = cursor.next()? {
// TODO(alexey): do we want to invalidate stage-specific checkpoint data? cursor.upsert(
cursor.upsert(stage_name, StageCheckpoint { block_number, ..checkpoint })? stage_name,
StageCheckpoint {
block_number,
..if drop_stage_checkpoint { Default::default() } else { checkpoint }
},
)?
} }
Ok(()) Ok(())