Skip to content

Commit

Permalink
fix: use in memory state for state_by_hash (paradigmxyz#10105)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected authored Aug 5, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent eda161a commit 40f44b7
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions crates/storage/provider/src/providers/blockchain_provider.rs
Original file line number Diff line number Diff line change
@@ -894,19 +894,25 @@ where
self.database.history_by_block_hash(block_hash)
}

fn state_by_block_hash(&self, block: BlockHash) -> ProviderResult<StateProviderBox> {
trace!(target: "providers::blockchain", ?block, "Getting state by block hash");
let mut state = self.history_by_block_hash(block);

// we failed to get the state by hash, from disk, hash block be the pending block
if state.is_err() {
if let Ok(Some(pending)) = self.pending_state_by_hash(block) {
// we found pending block by hash
state = Ok(pending)
}
fn state_by_block_hash(&self, hash: BlockHash) -> ProviderResult<StateProviderBox> {
trace!(target: "providers::blockchain", ?hash, "Getting state by block hash");
if let Ok(state) = self.history_by_block_hash(hash) {
// This could be tracked by a historical block
Ok(state)
} else if let Some(state) = self.canonical_in_memory_state.state_by_hash(hash) {
// ... or this could be tracked by the in memory state
let anchor_hash = state.anchor().hash;
let latest_historical = self.database.history_by_block_hash(anchor_hash)?;
let state_provider =
self.canonical_in_memory_state.state_provider(hash, latest_historical);
Ok(Box::new(state_provider))
} else if let Ok(Some(pending)) = self.pending_state_by_hash(hash) {
// .. or this could be the pending state
Ok(pending)
} else {
// if we couldn't find it anywhere, then we should return an error
Err(ProviderError::StateForHashNotFound(hash))
}

state
}

/// Returns the state provider for pending state.

0 comments on commit 40f44b7

Please sign in to comment.