Skip to content

Commit

Permalink
add append_block_meta and prune_block_meta
Browse files Browse the repository at this point in the history
  • Loading branch information
joshieDo committed Dec 10, 2024
1 parent 8d9535e commit 445f2ef
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions crates/storage/provider/src/providers/static_file/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use alloy_consensus::BlockHeader;
use alloy_primitives::{BlockHash, BlockNumber, TxNumber, U256};
use parking_lot::{lock_api::RwLockWriteGuard, RawRwLock, RwLock};
use reth_codecs::Compact;
use reth_db::models::StoredBlockBodyIndices;
use reth_db_api::models::CompactU256;
use reth_nippy_jar::{NippyJar, NippyJarError, NippyJarWriter};
use reth_node_types::NodePrimitives;
Expand Down Expand Up @@ -554,6 +555,45 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
Ok(())
}

/// Appends [`StoredBlockBodyIndices`] and any other two arbitrary types belonging to the block
/// body ([`reth_db::models::StoredBlockOmmers`] and
/// [`reth_db::models::StoredBlockWithdrawals`] on ethereum) to static file.
///
/// It **CALLS** `increment_block()` since it's a block based segment.
pub fn append_block_meta<F1, F2>(
&mut self,
body_indices: &StoredBlockBodyIndices,
field1: &F1,
field2: &F2,
expected_block_number: BlockNumber,
) -> ProviderResult<()>
where
N::BlockHeader: Compact,
F1: Compact,
F2: Compact,
{
let start = Instant::now();
self.ensure_no_queued_prune()?;

debug_assert!(self.writer.user_header().segment() == StaticFileSegment::BlockMeta);

self.increment_block(expected_block_number)?;

self.append_column(body_indices)?;
self.append_column(field1)?;
self.append_column(field2)?;

if let Some(metrics) = &self.metrics {
metrics.record_segment_operation(
StaticFileSegment::BlockMeta,
StaticFileProviderOperation::Append,
Some(start.elapsed()),
);
}

Ok(())
}

/// Appends transaction to static file.
///
/// It **DOES NOT CALL** `increment_block()`, it should be handled elsewhere. There might be
Expand Down Expand Up @@ -680,6 +720,12 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
self.queue_prune(to_delete, None)
}

/// Adds an instruction to prune `to_delete` bloc_ meta rows during commit.
pub fn prune_block_meta(&mut self, to_delete: u64) -> ProviderResult<()> {
debug_assert_eq!(self.writer.user_header().segment(), StaticFileSegment::BlockMeta);
self.queue_prune(to_delete, None)
}

/// Adds an instruction to prune `to_delete` elements during commit.
///
/// Note: `last_block` refers to the block the unwinds ends at if dealing with transaction-based
Expand Down

0 comments on commit 445f2ef

Please sign in to comment.