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 55 commits into
base: main
Choose a base branch
from

Conversation

joshieDo
Copy link
Collaborator

@joshieDo joshieDo commented May 7, 2024

The bulk of changes are regarding ProviderFactoryinitialization, but the real change is introducing 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,
) -> ProviderResult<Option<PipelineTarget>> {

For each segment the following invariants are checked:

/// Check invariants for each corresponding table and static file segment:
///
/// * the corresponding database table should overlap or have continuity in their keys
/// ([TxNumber] or [BlockNumber]).
/// * its highest block should match the stage checkpoint block number if it's equal or higher
/// than the corresponding database table last entry.
/// * If the checkpoint block is higher, then request a pipeline unwind to the static file
/// block.
/// * If the checkpoint block is lower, then heal by removing rows from the static file.
fn ensure_invariants<TX: DbTx, T: Table<Key = u64>>(
&self,

These will be called on starting up the node, before any data is queried from storage. If it fails any check it will try to self-heal, and if not possible, 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
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?

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

crates/primitives/src/static_file/segment.rs Outdated Show resolved Hide resolved
crates/evm/src/execute.rs Outdated Show resolved Hide resolved
crates/interfaces/src/executor.rs Outdated Show resolved Hide resolved
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.

looks like most of the changes concern the Providerfactory::new call

this no longer requires a result

pub fn new(
db: DB,
chain_spec: Arc<ChainSpec>,
static_file_provider: StaticFileProvider,
) -> ProviderResult<ProviderFactory<DB>> {

crates/evm/execution-errors/src/lib.rs Outdated Show resolved Hide resolved
@joshieDo
Copy link
Collaborator Author

looks like most of the changes concern the Providerfactory::new call

yes, because of the stacked PR: #8405

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