refactor: unify logic for blocks removal (#12743)

Co-authored-by: joshieDo <93316087+joshieDo@users.noreply.github.com>
This commit is contained in:
Arsenii Kulikov
2024-11-21 23:47:33 +04:00
committed by GitHub
parent edeacbecfb
commit 0558235b98
9 changed files with 267 additions and 536 deletions

View File

@@ -5,6 +5,7 @@ use reth_db::{
models::{StoredBlockOmmers, StoredBlockWithdrawals},
tables,
transaction::DbTxMut,
DbTxUnwindExt,
};
use reth_primitives_traits::{Block, BlockBody, FullNodePrimitives};
use reth_storage_errors::provider::ProviderResult;
@@ -21,6 +22,13 @@ pub trait BlockBodyWriter<Provider, Body: BlockBody> {
provider: &Provider,
bodies: Vec<(BlockNumber, Option<Body>)>,
) -> ProviderResult<()>;
/// Removes all block bodies above the given block number from the database.
fn remove_block_bodies_above(
&self,
provider: &Provider,
block: BlockNumber,
) -> ProviderResult<()>;
}
/// Trait that implements how chain-specific types are written to the storage.
@@ -69,4 +77,15 @@ where
Ok(())
}
fn remove_block_bodies_above(
&self,
provider: &Provider,
block: BlockNumber,
) -> ProviderResult<()> {
provider.tx_ref().unwind_table_by_num::<tables::BlockWithdrawals>(block)?;
provider.tx_ref().unwind_table_by_num::<tables::BlockOmmers>(block)?;
Ok(())
}
}