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

BlockchainProvider2::block_state_provider may return inconsistent state provider #34

Closed
1 task done
nekomoto911 opened this issue Jan 29, 2025 · 2 comments · Fixed by #36
Closed
1 task done
Assignees

Comments

@nekomoto911
Copy link
Collaborator

nekomoto911 commented Jan 29, 2025

Describe the bug

} else if let Some(state) = self.canonical_in_memory_state.state_by_hash(block_hash) {
// ... or this could be tracked by the in memory state
let state_provider = self.block_state_provider(state, opts)?;
Ok(Box::new(state_provider))

fn block_state_provider(
&self,
state: impl AsRef<BlockState>,
opts: StateProviderOptions,
) -> ProviderResult<MemoryOverlayStateProvider> {
let state = state.as_ref();
let anchor_hash = state.anchor().hash;
let latest_historical = self.database.history_by_block_hash(anchor_hash, opts)?;
Ok(self.canonical_in_memory_state.state_provider(state.hash(), latest_historical))
}

pub fn state_provider(
&self,
hash: B256,
historical: StateProviderBox,
) -> MemoryOverlayStateProvider {
let in_memory = if let Some(state) = self.state_by_hash(hash) {
state.chain().into_iter().map(|block_state| block_state.block()).collect()
} else {
Vec::new()
};
MemoryOverlayStateProvider::new(historical, in_memory)
}

In the block_state_provider, the in memory BlockState is first obtained from CanonicalInMemoryState, and with the anchor hash of this BlockState, an already written state provider in the database is retrieved, attempting to construct a MemoryOverlayStateProvider by combining the in memory BlockState and the state provider returned from the database. However, when constructing the MemoryOverlayStateProvider, the BlockState used is obtained again from CanonicalInMemoryState by hash, where this new BlockState may have an anchor hash different from the state provider obtained from the database (for example, the memory layout of CanonicalInMemoryState may have been modified by advancing persistent block between two calls to CanonicalInMemoryState::state_by_hash), resulting in an inconsistent CanonicalInMemoryState between the memory portion and the database portion.

Platform(s)

Linux (x86)

What version/commit are you on?

v1.0.7-gravity

Which chain / network are you on?

reth --chain

What type of node are you running?

Full via --full flag

Code of Conduct

  • I agree to follow the Code of Conduct
@nekomoto911
Copy link
Collaborator Author

The latest version of reth has solved this problem. Merge the latest version of reth will solve it.

@nekomoto911 nekomoto911 self-assigned this Jan 29, 2025
@nekomoto911
Copy link
Collaborator Author

paradigmxyz/reth#11338

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant