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 2d22990
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
2 changes: 2 additions & 0 deletions crates/optimism/storage/src/lib.rs
Original file line number Diff line number Diff line change
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);
}
}
4 changes: 4 additions & 0 deletions crates/storage/db-api/src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use alloy_consensus::Header;
use alloy_genesis::GenesisAccount;
use alloy_primitives::{Address, Bytes, Log, B256, U256};
use reth_codecs::{add_arbitrary_tests, Compact};
use reth_db_models::blocks::StaticFileBlockWithdrawals;
use reth_primitives::{Receipt, StorageEntry, TransactionSigned, TxType};
use reth_primitives_traits::{Account, Bytecode};
use reth_prune_types::{PruneCheckpoint, PruneSegment};
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
1 change: 1 addition & 0 deletions crates/storage/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ workspace = true
[dependencies]
# reth
reth-db-api.workspace = true
reth-db-models.workspace = true
reth-primitives = { workspace = true, features = ["reth-codec"] }
reth-primitives-traits = { workspace = true, features = ["serde", "reth-codec"] }
reth-fs-util.workspace = true
Expand Down
7 changes: 4 additions & 3 deletions crates/storage/db/src/static_file/masks.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
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_models::blocks::StaticFileBlockWithdrawals;

// HEADER MASKS
add_static_file_mask! {
Expand Down Expand Up @@ -53,6 +54,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 2d22990

Please sign in to comment.