diff --git a/crates/cli/commands/src/test_vectors/compact.rs b/crates/cli/commands/src/test_vectors/compact.rs index 90aafee1e8ab5..3d8e7b13f966d 100644 --- a/crates/cli/commands/src/test_vectors/compact.rs +++ b/crates/cli/commands/src/test_vectors/compact.rs @@ -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; @@ -110,6 +113,7 @@ compact_types!( StoredBlockOmmers, StoredBlockBodyIndices, StoredBlockWithdrawals, + StaticFileBlockWithdrawals, // Manual implementations TransactionSigned, // Bytecode, // todo revm arbitrary diff --git a/crates/optimism/storage/src/lib.rs b/crates/optimism/storage/src/lib.rs index 3f13133dd3912..aa098cd137d52 100644 --- a/crates/optimism/storage/src/lib.rs +++ b/crates/optimism/storage/src/lib.rs @@ -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}; @@ -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 @@ -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); } } diff --git a/crates/storage/db-api/src/models/mod.rs b/crates/storage/db-api/src/models/mod.rs index 232e257a1dc85..f5646e04bcf50 100644 --- a/crates/storage/db-api/src/models/mod.rs +++ b/crates/storage/db-api/src/models/mod.rs @@ -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; @@ -224,6 +225,7 @@ impl_compression_for_compact!( StoredBlockBodyIndices, StoredBlockOmmers, StoredBlockWithdrawals, + StaticFileBlockWithdrawals, Bytecode, AccountBeforeTx, TransactionSigned, @@ -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); @@ -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); } } diff --git a/crates/storage/db-models/src/blocks.rs b/crates/storage/db-models/src/blocks.rs index be7661c8b123b..4afd2ada3a545 100644 --- a/crates/storage/db-models/src/blocks.rs +++ b/crates/storage/db-models/src/blocks.rs @@ -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, +} + #[cfg(test)] mod tests { use crate::StoredBlockBodyIndices; diff --git a/crates/storage/db-models/src/lib.rs b/crates/storage/db-models/src/lib.rs index b8595362afc31..fd97574a646c2 100644 --- a/crates/storage/db-models/src/lib.rs +++ b/crates/storage/db-models/src/lib.rs @@ -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; diff --git a/crates/storage/db/src/static_file/masks.rs b/crates/storage/db/src/static_file/masks.rs index f89a0eac1d4e2..6dbc384fab86b 100644 --- a/crates/storage/db/src/static_file/masks.rs +++ b/crates/storage/db/src/static_file/masks.rs @@ -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! { @@ -53,6 +56,6 @@ add_static_file_mask! { OmmersMask, StoredBlockOmmers, 0b010 } add_static_file_mask! { - #[doc = "Mask for a `StoredBlockWithdrawals` from BlockMeta static file segment"] - WithdrawalsMask, ::Value, 0b100 + #[doc = "Mask for a `StaticFileBlockWithdrawals` from BlockMeta static file segment"] + WithdrawalsMask, StaticFileBlockWithdrawals, 0b100 } diff --git a/crates/storage/provider/src/providers/static_file/jar.rs b/crates/storage/provider/src/providers/static_file/jar.rs index 4b6525c1d1dc7..8a7654470d08b 100644 --- a/crates/storage/provider/src/providers/static_file/jar.rs +++ b/crates/storage/provider/src/providers/static_file/jar.rs @@ -362,7 +362,10 @@ impl WithdrawalsProvider for StaticFileJarProvider<'_, N> { _: u64, ) -> ProviderResult> { if let Some(num) = id.as_number() { - return Ok(self.cursor()?.get_one::(num.into())?.map(|s| s.withdrawals)) + return Ok(self + .cursor()? + .get_one::(num.into())? + .and_then(|s| s.withdrawals)) } // Only accepts block number queries Err(ProviderError::UnsupportedProvider)