Skip to content

Commit

Permalink
fix(providers): collect BlockState before constructing DB provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected committed Sep 30, 2024
1 parent 65f7e88 commit 32b3697
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions crates/chain-state/src/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,21 @@ impl CanonicalInMemoryState {
self.inner.canon_state_notification_sender.send(event).ok();
}

/// Return state provider with reference to in-memory blocks that overlay database state.
///
/// This merges the state of all blocks that are part of the chain that the requested block is
/// the head of. This includes all blocks that connect back to the canonical block on disk.
pub fn state_provider_from_state(
&self,
state: &BlockState,
historical: StateProviderBox,
) -> MemoryOverlayStateProvider {
let in_memory: Vec<_> =
state.chain().into_iter().map(|block_state| block_state.block()).collect();

MemoryOverlayStateProvider::new(historical, in_memory)
}

/// Return state provider with reference to in-memory blocks that overlay database state.
///
/// This merges the state of all blocks that are part of the chain that the requested block is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl<N: ProviderNodeTypes> BlockchainProvider2<N> {
let state = state.as_ref();
let anchor_hash = state.anchor().hash;
let latest_historical = self.database.history_by_block_hash(anchor_hash)?;
Ok(self.canonical_in_memory_state.state_provider(state.hash(), latest_historical))
Ok(self.canonical_in_memory_state.state_provider_from_state(state, latest_historical))
}

/// Returns:
Expand Down

0 comments on commit 32b3697

Please sign in to comment.