Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate memory overlay in canonical state #9614

Closed
Tracked by #8742
mattsse opened this issue Jul 18, 2024 · 0 comments · Fixed by #9817
Closed
Tracked by #8742

Integrate memory overlay in canonical state #9614

mattsse opened this issue Jul 18, 2024 · 0 comments · Fixed by #9817
Assignees
Labels
C-enhancement New feature or request

Comments

@mattsse
Copy link
Collaborator

mattsse commented Jul 18, 2024

in addition to tracking the the executed block, we also need to be able to serve the state at a canonical block, which works like:

/// Return state provider with reference to in-memory blocks that overlay database state.
fn state_provider(
&self,
hash: B256,
) -> ProviderResult<MemoryOverlayStateProvider<Box<dyn StateProvider>>> {
let mut in_memory = Vec::new();
let mut parent_hash = hash;
while let Some(executed) = self.state.tree_state.blocks_by_hash.get(&parent_hash) {
parent_hash = executed.block.parent_hash;
in_memory.insert(0, executed.clone());
}
let historical = self.provider.state_by_block_hash(parent_hash)?;
Ok(MemoryOverlayStateProvider::new(in_memory, historical))
}

this we need keep in the State so we can easily serve it

/// State after applying the given block.
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct State(ExecutedBlock);

this will be accessed a lot concurrently, so we need to be careful we keep the mapping right, which is updated when we flushed to disk.

This can now be integrated into the Blockchainprovider2 state_by calls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants