Skip to content

Add method to check invariants on RocksDB tables #20153

@Rjected

Description

@Rjected

Describe the feature

Right now we make sure that static files have been properly committed, and in the right order, by using check_consistency and ensure_invariants:

/// Ensures that any broken invariants which cannot be healed on the spot return a pipeline
/// target to unwind to.
///
/// Two types of consistency checks are done for:
///
/// 1) When a static file fails to commit but the underlying data was changed.
/// 2) When a static file was committed, but the required database transaction was not.
///
/// For 1) it can self-heal if `self.access.is_read_only()` is set to `false`. Otherwise, it
/// will return an error.
/// For 2) the invariants below are checked, and if broken, might require a pipeline unwind
/// to heal.
///
/// For each 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.
///
/// Returns a [`Option`] of [`PipelineTarget::Unwind`] if any healing is further required.
///
/// WARNING: No static file writer should be held before calling this function, otherwise it
/// will deadlock.
pub fn check_consistency<Provider>(
&self,
provider: &Provider,
) -> ProviderResult<Option<PipelineTarget>>
where
Provider: DBProvider
+ BlockReader
+ StageCheckpointReader
+ ChainSpecProvider
+ StorageSettingsCache,
N: NodePrimitives<Receipt: Value, BlockHeader: Value, SignedTx: Value>,
{

fn ensure_invariants<Provider, T: Table<Key = u64>>(

We should add a version of this for tables that we've moved to RocksDB

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions