mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-08 23:08:19 -05:00
docs: update db.md BodyStage unwind implementation (#20727)
This commit is contained in:
@@ -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<DB>, input: UnwindInput) {
|
||||
self.buffer.take();
|
||||
fn unwind(
|
||||
&mut self,
|
||||
provider: &Provider,
|
||||
input: UnwindInput,
|
||||
) -> Result<UnwindOutput, StageError> {
|
||||
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::<tables::BlockBodyIndices>()?;
|
||||
let mut ommers_cursor = tx.cursor_write::<tables::BlockOmmers>()?;
|
||||
let mut withdrawals_cursor = tx.cursor_write::<tables::BlockWithdrawals>()?;
|
||||
// Cursors to unwind transitions
|
||||
let mut tx_block_cursor = tx.cursor_write::<tables::TransactionBlocks>()?;
|
||||
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)?),
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user