-
Notifications
You must be signed in to change notification settings - Fork 2.4k
refactor(trie): Unify proof return types #19311
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2ad0725
refactor(trie): introduce ProofResult enum and remove dead code
yongkangc 1624209
refactor(trie): simplify storage proof handling in proof_task
yongkangc 34e790b
refactor(trie): simplify accountmultproofinput to match storage
yongkangc 1057899
added back StorageMultiproofInput
yongkangc 185ba12
move down
yongkangc a5a795c
remove into
yongkangc 379cadf
using into
yongkangc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,8 +84,40 @@ use crate::proof_task_metrics::ProofTaskTrieMetrics; | |
|
|
||
| type StorageProofResult = Result<DecodedStorageMultiProof, ParallelStateRootError>; | ||
| type TrieNodeProviderResult = Result<Option<RevealedNode>, SparseTrieError>; | ||
| type AccountMultiproofResult = | ||
| Result<(DecodedMultiProof, ParallelTrieStats), ParallelStateRootError>; | ||
|
|
||
| /// Result of a proof calculation, which can be either an account multiproof or a storage proof. | ||
| #[derive(Debug)] | ||
| pub enum ProofResult { | ||
| /// Account multiproof with statistics | ||
| AccountMultiproof { | ||
| /// The account multiproof | ||
| proof: DecodedMultiProof, | ||
| /// Statistics collected during proof computation | ||
| stats: ParallelTrieStats, | ||
| }, | ||
| /// Storage proof for a specific account | ||
| StorageProof { | ||
| /// The hashed address this storage proof belongs to | ||
| hashed_address: B256, | ||
| /// The storage multiproof | ||
| proof: DecodedStorageMultiProof, | ||
| }, | ||
| } | ||
|
|
||
| impl ProofResult { | ||
| /// Convert this proof result into a `DecodedMultiProof`. | ||
| /// | ||
| /// For account multiproofs, returns the multiproof directly (discarding stats). | ||
| /// For storage proofs, wraps the storage proof into a minimal multiproof. | ||
| pub fn into_multiproof(self) -> DecodedMultiProof { | ||
| match self { | ||
| Self::AccountMultiproof { proof, stats: _ } => proof, | ||
| Self::StorageProof { hashed_address, proof } => { | ||
| DecodedMultiProof::from_storage_proof(hashed_address, proof) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Channel used by worker threads to deliver `ProofResultMessage` items back to | ||
| /// `MultiProofTask`. | ||
|
|
@@ -101,8 +133,8 @@ pub type ProofResultSender = CrossbeamSender<ProofResultMessage>; | |
| pub struct ProofResultMessage { | ||
| /// Sequence number for ordering proofs | ||
| pub sequence_number: u64, | ||
| /// The proof calculation result | ||
| pub result: AccountMultiproofResult, | ||
| /// The proof calculation result (either account multiproof or storage proof) | ||
| pub result: Result<ProofResult, ParallelStateRootError>, | ||
| /// Time taken for the entire proof calculation (from dispatch to completion) | ||
| pub elapsed: Duration, | ||
| /// Original state update that triggered this proof | ||
|
|
@@ -248,18 +280,10 @@ fn storage_worker_loop<Factory>( | |
| let proof_elapsed = proof_start.elapsed(); | ||
| storage_proofs_processed += 1; | ||
|
|
||
| // Convert storage proof to account multiproof format | ||
| let result_msg = match result { | ||
| Ok(storage_proof) => { | ||
| let multiproof = reth_trie::DecodedMultiProof::from_storage_proof( | ||
| hashed_address, | ||
| storage_proof, | ||
| ); | ||
| let stats = crate::stats::ParallelTrieTracker::default().finish(); | ||
| Ok((multiproof, stats)) | ||
| } | ||
| Err(e) => Err(e), | ||
| }; | ||
| let result_msg = result.map(|storage_proof| ProofResult::StorageProof { | ||
| hashed_address, | ||
| proof: storage_proof, | ||
| }); | ||
|
|
||
| if sender | ||
| .send(ProofResultMessage { | ||
|
|
@@ -496,7 +520,7 @@ fn account_worker_loop<Factory>( | |
| let proof_elapsed = proof_start.elapsed(); | ||
| let total_elapsed = start.elapsed(); | ||
| let stats = tracker.finish(); | ||
| let result = result.map(|proof| (proof, stats)); | ||
| let result = result.map(|proof| ProofResult::AccountMultiproof { proof, stats }); | ||
| account_proofs_processed += 1; | ||
|
|
||
| // Send result to MultiProofTask | ||
|
|
@@ -657,14 +681,20 @@ where | |
| ) | ||
| })?; | ||
|
|
||
| // Extract storage proof from the multiproof wrapper | ||
| let (mut multiproof, _stats) = proof_msg.result?; | ||
| let proof = | ||
| multiproof.storages.remove(&hashed_address).ok_or_else(|| { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the key issue pointed out as footgun. where we are doing potentially double conversion in the hot path. |
||
| ParallelStateRootError::Other(format!( | ||
| "storage proof not found in multiproof for {hashed_address}" | ||
| )) | ||
| })?; | ||
| // Extract storage proof from the result | ||
| let proof = match proof_msg.result? { | ||
| ProofResult::StorageProof { hashed_address: addr, proof } => { | ||
| debug_assert_eq!( | ||
| addr, | ||
| hashed_address, | ||
| "storage worker must return same address: expected {hashed_address}, got {addr}" | ||
| ); | ||
| proof | ||
| } | ||
| ProofResult::AccountMultiproof { .. } => { | ||
| unreachable!("storage worker only sends StorageProof variant") | ||
| } | ||
| }; | ||
|
|
||
| let root = proof.root; | ||
| collected_decoded_storages.insert(hashed_address, proof); | ||
|
|
@@ -716,10 +746,8 @@ where | |
| // Consume remaining storage proof receivers for accounts not encountered during trie walk. | ||
| for (hashed_address, receiver) in storage_proof_receivers { | ||
| if let Ok(proof_msg) = receiver.recv() { | ||
| // Extract storage proof from the multiproof wrapper | ||
| if let Ok((mut multiproof, _stats)) = proof_msg.result && | ||
| let Some(proof) = multiproof.storages.remove(&hashed_address) | ||
| { | ||
| // Extract storage proof from the result | ||
| if let Ok(ProofResult::StorageProof { proof, .. }) = proof_msg.result { | ||
| collected_decoded_storages.insert(hashed_address, proof); | ||
| } | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
AccountMultiproofResultas it is redundant. Both account and storage results now come as ProofResult, with the account case carried by ProofResult::AccountMultiproof(multiproof, stats).