Skip to content
This repository has been archived by the owner on Feb 6, 2025. It is now read-only.

Commit

Permalink
fix: init provider ro without best number checks
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Oct 31, 2024
1 parent bc3791a commit a66aebf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2374,7 +2374,7 @@ where
input.append_ref(hashed_state);

// Prepare db provider read-only transaction for parallel state root computation.
let provider_ro = consistent_view.provider_ro()?;
let provider_ro = consistent_view.provider_ro_without_best_number_check()?;

ParallelStateRoot::new(consistent_view, input, Some(Ok(provider_ro)))
.incremental_root_with_updates()
Expand Down
22 changes: 22 additions & 0 deletions crates/storage/provider/src/providers/consistent_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,26 @@ where

Ok(provider_ro)
}

/// Creates new read-only provider and performs consistency checks on the current tip.
pub fn provider_ro_without_best_number_check(&self) -> ProviderResult<Factory::Provider> {
// Create a new provider.
let provider_ro = self.factory.database_provider_ro()?;

// Check that the latest stored header number matches the number
// that consistent view was initialized with.
// The mismatch can happen if a new block was appended while
// the view was being used.
// We compare block hashes instead of block numbers to account for reorgs.
let last_num = provider_ro.last_block_number()?;
let tip = provider_ro.sealed_header(last_num)?.map(|h| h.hash());
if self.tip != tip {
return Err(ConsistentViewError::Inconsistent {
tip: GotExpected { got: tip, expected: self.tip },
}
.into())
}

Ok(provider_ro)
}
}

0 comments on commit a66aebf

Please sign in to comment.