Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce StaticFileSegment::BlockMeta #13226

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions book/cli/reth/db/clear/static-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Arguments:
- headers: Static File segment responsible for the `CanonicalHeaders`, `Headers`, `HeaderTerminalDifficulties` tables
- transactions: Static File segment responsible for the `Transactions` table
- receipts: Static File segment responsible for the `Receipts` table
- block-meta: Static File segment responsible for the `BlockBodyIndices`, `BlockOmmers`, `BlockWithdrawals` tables

Options:
--instance <INSTANCE>
Expand Down
1 change: 1 addition & 0 deletions book/cli/reth/db/get/static-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Arguments:
- headers: Static File segment responsible for the `CanonicalHeaders`, `Headers`, `HeaderTerminalDifficulties` tables
- transactions: Static File segment responsible for the `Transactions` table
- receipts: Static File segment responsible for the `Receipts` table
- block-meta: Static File segment responsible for the `BlockBodyIndices`, `BlockOmmers`, `BlockWithdrawals` tables

<KEY>
The key to get content for
Expand Down
4 changes: 4 additions & 0 deletions crates/cli/commands/src/db/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl Command {
StaticFileSegment::Receipts => {
(table_key::<tables::Receipts>(&key)?, <ReceiptMask<ReceiptTy<N>>>::MASK)
}
StaticFileSegment::BlockMeta => todo!(),
};

let content = tool.provider_factory.static_file_provider().find_static_file(
Expand Down Expand Up @@ -113,6 +114,9 @@ impl Command {
)?;
println!("{}", serde_json::to_string_pretty(&receipt)?);
}
StaticFileSegment::BlockMeta => {
todo!()
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/consensus/beacon/src/engine/hooks/static_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ where
headers: Some(finalized_block_number),
receipts: Some(finalized_block_number),
transactions: Some(finalized_block_number),
block_meta: Some(finalized_block_number),
})?;

// Check if the moving data to static files has been requested.
Expand Down
38 changes: 32 additions & 6 deletions crates/static-file/static-file/src/static_file_producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ where
headers: stages_checkpoints[0],
receipts: stages_checkpoints[1],
transactions: stages_checkpoints[2],
block_meta: stages_checkpoints[2],
};
let targets = self.get_static_file_targets(highest_static_files)?;
self.run(targets)?;
Expand Down Expand Up @@ -226,6 +227,9 @@ where
finalized_block_number,
)
}),
block_meta: finalized_block_numbers.block_meta.and_then(|finalized_block_number| {
self.get_static_file_target(highest_static_files.block_meta, finalized_block_number)
}),
};

trace!(
Expand Down Expand Up @@ -322,56 +326,72 @@ mod tests {
headers: Some(1),
receipts: Some(1),
transactions: Some(1),
block_meta: None,
})
.expect("get static file targets");
assert_eq!(
targets,
StaticFileTargets {
headers: Some(0..=1),
receipts: Some(0..=1),
transactions: Some(0..=1)
transactions: Some(0..=1),
block_meta: None
}
);
assert_matches!(static_file_producer.run(targets), Ok(_));
assert_eq!(
provider_factory.static_file_provider().get_highest_static_files(),
HighestStaticFiles { headers: Some(1), receipts: Some(1), transactions: Some(1) }
HighestStaticFiles {
headers: Some(1),
receipts: Some(1),
transactions: Some(1),
block_meta: None
}
);

let targets = static_file_producer
.get_static_file_targets(HighestStaticFiles {
headers: Some(3),
receipts: Some(3),
transactions: Some(3),
block_meta: None,
})
.expect("get static file targets");
assert_eq!(
targets,
StaticFileTargets {
headers: Some(2..=3),
receipts: Some(2..=3),
transactions: Some(2..=3)
transactions: Some(2..=3),
block_meta: None
}
);
assert_matches!(static_file_producer.run(targets), Ok(_));
assert_eq!(
provider_factory.static_file_provider().get_highest_static_files(),
HighestStaticFiles { headers: Some(3), receipts: Some(3), transactions: Some(3) }
HighestStaticFiles {
headers: Some(3),
receipts: Some(3),
transactions: Some(3),
block_meta: None
}
);

let targets = static_file_producer
.get_static_file_targets(HighestStaticFiles {
headers: Some(4),
receipts: Some(4),
transactions: Some(4),
block_meta: None,
})
.expect("get static file targets");
assert_eq!(
targets,
StaticFileTargets {
headers: Some(4..=4),
receipts: Some(4..=4),
transactions: Some(4..=4)
transactions: Some(4..=4),
block_meta: None
}
);
assert_matches!(
Expand All @@ -380,7 +400,12 @@ mod tests {
);
assert_eq!(
provider_factory.static_file_provider().get_highest_static_files(),
HighestStaticFiles { headers: Some(3), receipts: Some(3), transactions: Some(3) }
HighestStaticFiles {
headers: Some(3),
receipts: Some(3),
transactions: Some(3),
block_meta: None
}
);
}

Expand Down Expand Up @@ -408,6 +433,7 @@ mod tests {
headers: Some(1),
receipts: Some(1),
transactions: Some(1),
block_meta: Some(1),
})
.expect("get static file targets");
assert_matches!(locked_producer.run(targets.clone()), Ok(_));
Expand Down
51 changes: 42 additions & 9 deletions crates/static-file/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ pub struct HighestStaticFiles {
/// Highest static file block of transactions, inclusive.
/// If [`None`], no static file is available.
pub transactions: Option<BlockNumber>,
/// Highest static file block of transactions, inclusive.
/// If [`None`], no static file is available.
pub block_meta: Option<BlockNumber>,
}

impl HighestStaticFiles {
Expand All @@ -42,6 +45,7 @@ impl HighestStaticFiles {
StaticFileSegment::Headers => self.headers,
StaticFileSegment::Transactions => self.transactions,
StaticFileSegment::Receipts => self.receipts,
StaticFileSegment::BlockMeta => self.block_meta,
}
}

Expand All @@ -51,17 +55,24 @@ impl HighestStaticFiles {
StaticFileSegment::Headers => &mut self.headers,
StaticFileSegment::Transactions => &mut self.transactions,
StaticFileSegment::Receipts => &mut self.receipts,
StaticFileSegment::BlockMeta => &mut self.block_meta,
}
}

/// Returns the minimum block of all segments.
pub fn min_block_num(&self) -> Option<u64> {
[self.headers, self.transactions, self.receipts].iter().filter_map(|&option| option).min()
[self.headers, self.transactions, self.receipts, self.block_meta]
.iter()
.filter_map(|&option| option)
.min()
}

/// Returns the maximum block of all segments.
pub fn max_block_num(&self) -> Option<u64> {
[self.headers, self.transactions, self.receipts].iter().filter_map(|&option| option).max()
[self.headers, self.transactions, self.receipts, self.block_meta]
.iter()
.filter_map(|&option| option)
.max()
}
}

Expand All @@ -74,12 +85,17 @@ pub struct StaticFileTargets {
pub receipts: Option<RangeInclusive<BlockNumber>>,
/// Targeted range of transactions.
pub transactions: Option<RangeInclusive<BlockNumber>>,
/// Targeted range of block meta.
pub block_meta: Option<RangeInclusive<BlockNumber>>,
}

impl StaticFileTargets {
/// Returns `true` if any of the targets are [Some].
pub const fn any(&self) -> bool {
self.headers.is_some() || self.receipts.is_some() || self.transactions.is_some()
self.headers.is_some() ||
self.receipts.is_some() ||
self.transactions.is_some() ||
self.block_meta.is_some()
}

/// Returns `true` if all targets are either [`None`] or has beginning of the range equal to the
Expand All @@ -89,6 +105,7 @@ impl StaticFileTargets {
(self.headers.as_ref(), static_files.headers),
(self.receipts.as_ref(), static_files.receipts),
(self.transactions.as_ref(), static_files.transactions),
(self.block_meta.as_ref(), static_files.block_meta),
]
.iter()
.all(|(target_block_range, highest_static_fileted_block)| {
Expand Down Expand Up @@ -118,8 +135,12 @@ mod tests {

#[test]
fn test_highest_static_files_highest() {
let files =
HighestStaticFiles { headers: Some(100), receipts: Some(200), transactions: None };
let files = HighestStaticFiles {
headers: Some(100),
receipts: Some(200),
transactions: None,
block_meta: None,
};

// Test for headers segment
assert_eq!(files.highest(StaticFileSegment::Headers), Some(100));
Expand All @@ -146,12 +167,20 @@ mod tests {
// Modify transactions value
*files.as_mut(StaticFileSegment::Transactions) = Some(350);
assert_eq!(files.transactions, Some(350));

// Modify block meta value
*files.as_mut(StaticFileSegment::BlockMeta) = Some(350);
assert_eq!(files.block_meta, Some(350));
}

#[test]
fn test_highest_static_files_min() {
let files =
HighestStaticFiles { headers: Some(300), receipts: Some(100), transactions: None };
let files = HighestStaticFiles {
headers: Some(300),
receipts: Some(100),
transactions: None,
block_meta: None,
};

// Minimum value among the available segments
assert_eq!(files.min_block_num(), Some(100));
Expand All @@ -163,8 +192,12 @@ mod tests {

#[test]
fn test_highest_static_files_max() {
let files =
HighestStaticFiles { headers: Some(300), receipts: Some(100), transactions: Some(500) };
let files = HighestStaticFiles {
headers: Some(300),
receipts: Some(100),
transactions: Some(500),
block_meta: Some(500),
};

// Maximum value among the available segments
assert_eq!(files.max_block_num(), Some(500));
Expand Down
Loading
Loading