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: run StaticFileProvider::check_consistency on start up #8143

Open
wants to merge 32 commits into
base: main
Choose a base branch
from

Conversation

joshieDo
Copy link
Collaborator

@joshieDo joshieDo commented May 7, 2024

Introduces a function to check the overall consistency between static files and database:

pub fn check_consistency<TX: DbTx>(
&self,
provider: &DatabaseProvider<TX>,
has_receipt_pruning: bool,
read_only: bool,
) -> ProviderResult<Option<PipelineTarget>> {

This will be called on starting up the node, before any data is queried from storage. If it fails the check, it will return a PipelineTarget::Unwind(N) that will be straight away handled by a standalone unwind-only pipeline.

The tests live in crates/stages/mod.rs because there are other necessary test functions there and can not be imported into providers crate. Follow-up will refactor the test-utils in stages crate and move them to providers crate.

Pending live testing - but open to review

@joshieDo joshieDo requested a review from onbjerg May 7, 2024 17:37
@joshieDo joshieDo added A-db Related to the database A-static-files Related to static files labels May 7, 2024
@joshieDo joshieDo marked this pull request as draft May 7, 2024 17:38
Comment on lines +527 to +540
loop {
if let Some(indices) = provider.block_body_indices(last_block)? {
if indices.last_tx_num() <= highest_tx {
break
}
}
if last_block == 0 {
break
}
last_block -= 1;

highest_block = Some(last_block);
update_unwind_target(highest_block);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this to static file manager, so that we can re-use it in stages as well?

Copy link
Collaborator

@shekhirin shekhirin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a first pass, want to also look at unwrap_or_default() usage

crates/node/builder/src/launch/common.rs Show resolved Hide resolved
crates/node/builder/src/launch/common.rs Outdated Show resolved Hide resolved
) -> ProviderResult<Option<PipelineTarget>> {
let mut unwind_target: Option<BlockNumber> = None;
let mut update_unwind_target = |new_target: Option<BlockNumber>| {
let new_target = new_target.unwrap_or_default();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unwrap_or_default seems correct, because we need to unwind to 0 if we pass None as a new target. I would prefer passing just the BlockNumber here instead, and do the unwrap_or_default() only in the call where None is possible.

Comment on lines 580 to 581
let static_file_entry = static_file_entry.unwrap_or_default();
let highest_static_block = highest_static_block.unwrap_or_default();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it correct that if we don't even have a genesis block in the segment, we unwrap these to 0?

@joshieDo joshieDo marked this pull request as ready for review May 22, 2024 13:08
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few nits

@@ -138,6 +138,11 @@ impl StaticFileSegment {
pub fn is_headers(&self) -> bool {
matches!(self, StaticFileSegment::Headers)
}

/// Returns `true` if the segment is `StaticFileSegment::Receipts`.
pub fn is_receipts(&self) -> bool {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn is_receipts(&self) -> bool {
pub const fn is_receipts(&self) -> bool {

Comment on lines +179 to +182
/// A [BlockExecutorProvider] implementation that does nothing.
#[derive(Debug, Default, Clone)]
#[non_exhaustive]
pub struct NoopBlockExecutorProvider;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this to noop.rs

Comment on lines +118 to +120
/// Only used for NoopBlockExecutorProvider
#[error("execution unavailable for noop")]
UnavailableForNoop,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need this, we should use the Other variant instead

Comment on lines +655 to +656
#[cfg(any(test, feature = "test-utils"))]
/// Helper function to override block range for testing.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swap order

Comment on lines 643 to 644
#[cfg(any(test, feature = "test-utils"))]
/// Helper function to override block range for testing.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swap order

{
/// Returns the [ProviderFactory] for the attached database.
pub fn create_provider_factory(&self) -> eyre::Result<ProviderFactory<DB>> {
pub async fn create_provider_factory(&self) -> eyre::Result<ProviderFactory<DB>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this now needs more docs that describe what this does

Comment on lines +478 to +479
has_receipt_pruning: bool,
read_only: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to use a new type for this, in case we need more settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-db Related to the database A-static-files Related to static files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants