diff --git a/crates/interfaces/src/provider.rs b/crates/interfaces/src/provider.rs index c7b5f62583..cede0deba4 100644 --- a/crates/interfaces/src/provider.rs +++ b/crates/interfaces/src/provider.rs @@ -164,7 +164,7 @@ pub enum ConsistentViewError { #[error("inconsistent database state: {tip:?}")] Inconsistent { /// The tip diff. - tip: GotExpected>, + tip: GotExpected>, }, } diff --git a/crates/storage/provider/src/providers/consistent_view.rs b/crates/storage/provider/src/providers/consistent_view.rs index 3cad431b90..cccd64b5fc 100644 --- a/crates/storage/provider/src/providers/consistent_view.rs +++ b/crates/storage/provider/src/providers/consistent_view.rs @@ -25,7 +25,7 @@ pub use reth_interfaces::provider::ConsistentViewError; pub struct ConsistentDbView { database: PhantomData, provider: Provider, - tip: Option, + tip: Option<(u64, B256)>, } impl ConsistentDbView @@ -34,7 +34,7 @@ where Provider: DatabaseProviderFactory, { /// Creates new consistent database view. - pub fn new(provider: Provider, tip: Option) -> Self { + pub fn new(provider: Provider, tip: Option<(u64, B256)>) -> Self { Self { database: PhantomData, provider, tip } } @@ -45,7 +45,7 @@ where .tx_ref() .cursor_read::()? .last()?; - Ok(Self::new(provider, tip.map(|(_, hash)| hash))) + Ok(Self::new(provider, tip)) } /// Creates new read-only provider and performs consistency checks on the current tip. @@ -57,7 +57,7 @@ where .and_then(|mut cursor| cursor.last()) .map_err(ProviderError::Database)?; - let tip = last_entry.map(|(_, hash)| hash); + let tip = last_entry; if self.tip != tip { return Err(ConsistentViewError::Inconsistent { tip: GotExpected { got: tip, expected: self.tip }, @@ -65,9 +65,11 @@ where .into()) } - let best_block_number = provider_ro.best_block_number()?; - if last_entry.map(|(number, _)| number).unwrap_or_default() != best_block_number { - return Err(ConsistentViewError::Syncing(best_block_number).into()) + if let Some((num, _)) = last_entry { + let best_block_number = provider_ro.best_block_number()?; + if num != best_block_number { + return Err(ConsistentViewError::Syncing(best_block_number).into()) + } } Ok(provider_ro)