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

feat(engine): proof fetching on state update for StateRootTask #12458

Merged
merged 22 commits into from
Nov 27, 2024

Conversation

fgimenez
Copy link
Member

@fgimenez fgimenez commented Nov 11, 2024

Towards #12053
Requires #12378 #12467 #12510

@fgimenez fgimenez added C-perf A change motivated by improving speed, memory usage or disk footprint A-blockchain-tree Related to sidechains, reorgs and pending blocks A-trie Related to Merkle Patricia Trie implementation labels Nov 11, 2024
@fgimenez fgimenez force-pushed the fgimenez/srt-sync-async-impls branch from d0f48d5 to fdb55e9 Compare November 12, 2024 15:34
@fgimenez fgimenez force-pushed the fgimenez/srt-proof-fetching branch from 14ca9a0 to da06971 Compare November 12, 2024 15:35
@fgimenez fgimenez force-pushed the fgimenez/srt-proof-fetching branch from c38de83 to a8e0cf2 Compare November 13, 2024 13:15
@fgimenez fgimenez force-pushed the fgimenez/srt-sync-async-impls branch from fdb55e9 to 5d2048f Compare November 13, 2024 13:34
@fgimenez fgimenez force-pushed the fgimenez/srt-proof-fetching branch from a8e0cf2 to 6e0e20e Compare November 13, 2024 13:35
Base automatically changed from fgimenez/srt-sync-async-impls to main November 18, 2024 14:19
@fgimenez fgimenez force-pushed the fgimenez/srt-proof-fetching branch from 6e0e20e to 3b04efb Compare November 18, 2024 15:35
@fgimenez fgimenez marked this pull request as ready for review November 18, 2024 15:50
@@ -237,6 +241,7 @@ impl From<ParallelStateRootError> for ProviderError {
ParallelStateRootError::StorageRoot(StorageRootError::Database(error)) => {
Self::Database(error)
}
ParallelStateRootError::Other(other) => Self::Database(DatabaseError::Other(other)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be casted to database error. out of scope for this PR, but we have to fix this at some point ^^

@fgimenez fgimenez force-pushed the fgimenez/srt-proof-fetching branch 4 times, most recently from 52e1366 to 2ffe7c8 Compare November 21, 2024 09:43
crates/engine/tree/src/tree/root.rs Outdated Show resolved Hide resolved

pending_proofs.push_back(rx);

state.extend(hashed_state_update);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this extends the state immediately and that's what is used to perform state root updates, but this might result in invalid cached trie nodes. not sure yet, but worth double checking @fgimenez

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is still relevant and should be solved by updating the state only when we finish calculating the proof

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a few questions

crates/engine/tree/src/tree/root.rs Outdated Show resolved Hide resolved
Comment on lines 305 to 314
rayon::spawn(move || {
let result = calculate_state_root_from_proofs(
view,
&input_nodes_sorted,
&input_state_sorted,
multiproof,
state,
);
let _ = tx.send(result);
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this spawns a new rayon job that then also branches out via par_iter
all of this looks very IO heavy

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, that's the case

crates/engine/tree/src/tree/root.rs Outdated Show resolved Hide resolved
@fgimenez fgimenez force-pushed the fgimenez/srt-proof-fetching branch 2 times, most recently from f982fa2 to 1665120 Compare November 24, 2024 16:49
crates/engine/tree/src/tree/root.rs Outdated Show resolved Hide resolved
let destroyed = account.is_selfdestructed();
hashed_state_update.accounts.insert(
hashed_address,
if destroyed || account.is_empty() { None } else { Some(account.info.into()) },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

account can be destroyed and recreated, worth checking again if this line is correct


// TODO: replace with parallel proof
let result =
Proof::overlay_multiproof(provider.tx_ref(), input.as_ref().clone(), targets);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this clone is expensive, we should find a way to get rid of it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it happens inside the ParallelProof anyway, but maybe we can avoid it altogether

let trie_nodes_sorted = Arc::new(self.input.nodes.into_sorted());
let hashed_state_sorted = Arc::new(self.input.state.into_sorted());
// Extend prefix sets with targets
let mut prefix_sets = self.input.prefix_sets.clone();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in parallel proof it only re-allocates. here it clones and re-allocates

)?);
}

let storage_root = next_root_from_proofs(storage_trie_nodes, |key: Nibbles| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next_root_from_proofs function served its purpose, but is not always correct (see #12859). let's integrate sparse trie and debug it instead

@fgimenez fgimenez force-pushed the fgimenez/srt-proof-fetching branch from fbc22f5 to 344a9b8 Compare November 27, 2024 10:01
Copy link
Member

@rkrasiuk rkrasiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

taking notes of outstanding comments. let's merge this PR and iterate in follow ups

@fgimenez fgimenez added this pull request to the merge queue Nov 27, 2024
Merged via the queue into main with commit 1131bde Nov 27, 2024
42 checks passed
@fgimenez fgimenez deleted the fgimenez/srt-proof-fetching branch November 27, 2024 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-blockchain-tree Related to sidechains, reorgs and pending blocks A-trie Related to Merkle Patricia Trie implementation C-perf A change motivated by improving speed, memory usage or disk footprint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants