diff --git a/docs/crates/db.md b/docs/crates/db.md index 4e368cad77..d17d29810b 100644 --- a/docs/crates/db.md +++ b/docs/crates/db.md @@ -264,45 +264,20 @@ Let's look at an example of how cursors are used. The code snippet below contain ```rust ignore /// Unwind the stage. -fn unwind(&mut self, provider: &DatabaseProviderRW, input: UnwindInput) { - self.buffer.take(); +fn unwind( + &mut self, + provider: &Provider, + input: UnwindInput, +) -> Result { + self.buffer.take(); - let static_file_provider = provider.static_file_provider(); - let tx = provider.tx_ref(); - // Cursors to unwind bodies, ommers - let mut body_cursor = tx.cursor_write::()?; - let mut ommers_cursor = tx.cursor_write::()?; - let mut withdrawals_cursor = tx.cursor_write::()?; - // Cursors to unwind transitions - let mut tx_block_cursor = tx.cursor_write::()?; + ensure_consistency(provider, Some(input.unwind_to))?; + provider.remove_bodies_above(input.unwind_to)?; - let mut rev_walker = body_cursor.walk_back(None)?; - while let Some((number, block_meta)) = rev_walker.next().transpose()? { - if number <= input.unwind_to { - break - } - - // Delete the ommers entry if any - if ommers_cursor.seek_exact(number)?.is_some() { - ommers_cursor.delete_current()?; - } - - // Delete the withdrawals entry if any - if withdrawals_cursor.seek_exact(number)?.is_some() { - withdrawals_cursor.delete_current()?; - } - - // Delete all transactions to block values. - if !block_meta.is_empty() && - tx_block_cursor.seek_exact(block_meta.last_tx_num())?.is_some() - { - tx_block_cursor.delete_current()?; - } - - // Delete the current body value - rev_walker.delete_current()?; - } - //--snip-- + Ok(UnwindOutput { + checkpoint: StageCheckpoint::new(input.unwind_to) + .with_entities_stage_checkpoint(stage_checkpoint(provider)?), + }) } ```