Skip to content

Commit

Permalink
add StaticFileBlockWithdrawals to BlockMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
joshieDo committed Jan 20, 2025
1 parent f527b5a commit b57d5e5
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 10 deletions.
6 changes: 5 additions & 1 deletion crates/cli/commands/src/test_vectors/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use reth_codecs::alloy::{
withdrawal::Withdrawal,
};
use reth_db::{
models::{AccountBeforeTx, StoredBlockBodyIndices, StoredBlockOmmers, StoredBlockWithdrawals},
models::{
AccountBeforeTx, StaticFileBlockWithdrawals, StoredBlockBodyIndices, StoredBlockOmmers,
StoredBlockWithdrawals,
},
ClientVersion,
};
use reth_fs_util as fs;
Expand Down Expand Up @@ -110,6 +113,7 @@ compact_types!(
StoredBlockOmmers,
StoredBlockBodyIndices,
StoredBlockWithdrawals,
StaticFileBlockWithdrawals,
// Manual implementations
TransactionSigned,
// Bytecode, // todo revm arbitrary
Expand Down
6 changes: 4 additions & 2 deletions crates/optimism/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
mod tests {
use reth_codecs::{test_utils::UnusedBits, validate_bitflag_backwards_compat};
use reth_db_api::models::{
CompactClientVersion, CompactU256, CompactU64, StoredBlockBodyIndices,
StoredBlockWithdrawals,
CompactClientVersion, CompactU256, CompactU64, StaticFileBlockWithdrawals,
StoredBlockBodyIndices, StoredBlockWithdrawals,
};
use reth_primitives::Account;
use reth_prune_types::{PruneCheckpoint, PruneMode, PruneSegment};
Expand Down Expand Up @@ -43,6 +43,7 @@ mod tests {
assert_eq!(StageUnitCheckpoint::bitflag_encoded_bytes(), 1);
assert_eq!(StoredBlockBodyIndices::bitflag_encoded_bytes(), 1);
assert_eq!(StoredBlockWithdrawals::bitflag_encoded_bytes(), 0);
assert_eq!(StaticFileBlockWithdrawals::bitflag_encoded_bytes(), 1);
assert_eq!(StorageHashingCheckpoint::bitflag_encoded_bytes(), 1);

// In case of failure, refer to the documentation of the
Expand All @@ -65,6 +66,7 @@ mod tests {
validate_bitflag_backwards_compat!(StageUnitCheckpoint, UnusedBits::Zero);
validate_bitflag_backwards_compat!(StoredBlockBodyIndices, UnusedBits::Zero);
validate_bitflag_backwards_compat!(StoredBlockWithdrawals, UnusedBits::Zero);
validate_bitflag_backwards_compat!(StaticFileBlockWithdrawals, UnusedBits::NotZero);
validate_bitflag_backwards_compat!(StorageHashingCheckpoint, UnusedBits::NotZero);
}
}
6 changes: 5 additions & 1 deletion crates/storage/db-api/src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ pub use accounts::*;
pub use blocks::*;
pub use integer_list::IntegerList;
pub use reth_db_models::{
AccountBeforeTx, ClientVersion, StoredBlockBodyIndices, StoredBlockWithdrawals,
blocks::StaticFileBlockWithdrawals, AccountBeforeTx, ClientVersion, StoredBlockBodyIndices,
StoredBlockWithdrawals,
};
pub use sharded_key::ShardedKey;

Expand Down Expand Up @@ -224,6 +225,7 @@ impl_compression_for_compact!(
StoredBlockBodyIndices,
StoredBlockOmmers<H>,
StoredBlockWithdrawals,
StaticFileBlockWithdrawals,
Bytecode,
AccountBeforeTx,
TransactionSigned,
Expand Down Expand Up @@ -347,6 +349,7 @@ mod tests {
assert_eq!(StageUnitCheckpoint::bitflag_encoded_bytes(), 1);
assert_eq!(StoredBlockBodyIndices::bitflag_encoded_bytes(), 1);
assert_eq!(StoredBlockWithdrawals::bitflag_encoded_bytes(), 0);
assert_eq!(StaticFileBlockWithdrawals::bitflag_encoded_bytes(), 1);
assert_eq!(StorageHashingCheckpoint::bitflag_encoded_bytes(), 1);

validate_bitflag_backwards_compat!(Account, UnusedBits::NotZero);
Expand All @@ -367,6 +370,7 @@ mod tests {
validate_bitflag_backwards_compat!(StageUnitCheckpoint, UnusedBits::Zero);
validate_bitflag_backwards_compat!(StoredBlockBodyIndices, UnusedBits::Zero);
validate_bitflag_backwards_compat!(StoredBlockWithdrawals, UnusedBits::Zero);
validate_bitflag_backwards_compat!(StaticFileBlockWithdrawals, UnusedBits::NotZero);
validate_bitflag_backwards_compat!(StorageHashingCheckpoint, UnusedBits::NotZero);
}
}
10 changes: 10 additions & 0 deletions crates/storage/db-models/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ pub struct StoredBlockWithdrawals {
pub withdrawals: Withdrawals,
}

/// A storage representation of block withdrawals that is static file friendly. An inner `None`
/// represents a pre-merge block.
#[derive(Debug, Default, Eq, PartialEq, Clone, Serialize, Deserialize, Compact)]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(compact)]
pub struct StaticFileBlockWithdrawals {
/// The block withdrawals. A `None` value represents a pre-merge block.
pub withdrawals: Option<Withdrawals>,
}

#[cfg(test)]
mod tests {
use crate::StoredBlockBodyIndices;
Expand Down
2 changes: 1 addition & 1 deletion crates/storage/db-models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub use accounts::AccountBeforeTx;

/// Blocks
pub mod blocks;
pub use blocks::{StoredBlockBodyIndices, StoredBlockWithdrawals};
pub use blocks::{StaticFileBlockWithdrawals, StoredBlockBodyIndices, StoredBlockWithdrawals};

/// Client Version
pub mod client_version;
Expand Down
11 changes: 7 additions & 4 deletions crates/storage/db/src/static_file/masks.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::{
add_static_file_mask,
static_file::mask::{ColumnSelectorOne, ColumnSelectorTwo},
BlockBodyIndices, BlockWithdrawals, HeaderTerminalDifficulties,
BlockBodyIndices, HeaderTerminalDifficulties,
};
use alloy_primitives::BlockHash;
use reth_db_api::{models::StoredBlockOmmers, table::Table};
use reth_db_api::{
models::{StaticFileBlockWithdrawals, StoredBlockOmmers},
table::Table,
};

// HEADER MASKS
add_static_file_mask! {
Expand Down Expand Up @@ -53,6 +56,6 @@ add_static_file_mask! {
OmmersMask<H>, StoredBlockOmmers<H>, 0b010
}
add_static_file_mask! {
#[doc = "Mask for a `StoredBlockWithdrawals` from BlockMeta static file segment"]
WithdrawalsMask, <BlockWithdrawals as Table>::Value, 0b100
#[doc = "Mask for a `StaticFileBlockWithdrawals` from BlockMeta static file segment"]
WithdrawalsMask, StaticFileBlockWithdrawals, 0b100
}
5 changes: 4 additions & 1 deletion crates/storage/provider/src/providers/static_file/jar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,10 @@ impl<N: NodePrimitives> WithdrawalsProvider for StaticFileJarProvider<'_, N> {
_: u64,
) -> ProviderResult<Option<Withdrawals>> {
if let Some(num) = id.as_number() {
return Ok(self.cursor()?.get_one::<WithdrawalsMask>(num.into())?.map(|s| s.withdrawals))
return Ok(self
.cursor()?
.get_one::<WithdrawalsMask>(num.into())?
.and_then(|s| s.withdrawals))
}
// Only accepts block number queries
Err(ProviderError::UnsupportedProvider)
Expand Down

0 comments on commit b57d5e5

Please sign in to comment.