Skip to content

Conversation

@yongkangc
Copy link
Member

@yongkangc yongkangc commented Oct 27, 2025

Refactors multiproof computation code to close #19182

Changes

  1. Optimize Storage Proof Hot Path
  • Introduced ProofResult enum to eliminate unnecessary allocations when returning storage proofs
  • Storage proofs now returned directly instead of being wrapped in full DecodedMultiProof structure
  1. Remove Dead Code
  • StorageMultiproofInput (never constructed)
  • PendingMultiproofTask (unnecessary wrapper)
  • AccountMultiproofResult (unused alias)
  1. Replace Unreachable Error Handling
  • Changed defensive error returns to unreachable!() and debug_assert_eq!() for impossible conditions with storage proofs.
  1. Code Organization
  • Reorganized proof_task.rs and multiproof.rs for logical flow. i.e main types at the start

Future PR

Testing

  • Running on reth4 to test the refactor

@@ -1,11 +1,7 @@
//! Multiproof task related functionality.
Copy link
Member Author

Choose a reason for hiding this comment

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

The module in multiproof.rs is now organised as

//! This module is organized as follows:
//! - Main Types: [MultiproofManager], [MultiProofTask]
//! - Metrics: [MultiProofTaskMetrics]
//! - Supporting Types: [SparseTrieUpdate], [MultiProofConfig], [MultiProofMessage],
//!   [StateHookSender]
//! - Internal Types: [ProofSequencer], [MultiProofTaskState], [MultiproofInput]
//! - Helper Functions: [evm_state_to_hashed_post_state], [get_proof_targets]

- Introduced `ProofWorkerHandle` for type-safe access to storage and account worker pools.
- Replaced `ProofResultContext` with direct senders for improved performance.
- Updated worker loops to handle proof tasks more efficiently, including better tracing and error handling.
- Added methods for dispatching storage and account multiproof computations, improving interleaved parallelism.
- Enhanced metrics tracking for storage and account processing.

type StorageProofResult = Result<DecodedStorageMultiProof, ParallelStateRootError>;
type TrieNodeProviderResult = Result<Option<RevealedNode>, SparseTrieError>;
type AccountMultiproofResult =
Copy link
Member Author

Choose a reason for hiding this comment

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

removed AccountMultiproofResult as it is redundant. Both account and storage results now come as ProofResult, with the account case carried by ProofResult::AccountMultiproof(multiproof, stats).

Comment on lines -218 to -225
/// A pending multiproof task, either [`StorageMultiproofInput`] or [`MultiproofInput`].
#[derive(Debug)]
enum PendingMultiproofTask {
/// A storage multiproof task input.
Storage(StorageMultiproofInput),
/// A regular multiproof task input.
Regular(MultiproofInput),
}
Copy link
Member Author

Choose a reason for hiding this comment

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

removed this

After we removed the old storage/account enum and always pass a single MultiproofInput value into MultiproofManager::dispatch, the alias was redundant.

Removing it lets thecall sites work directly with MultiproofInput, without indirection

…nversion

- Updated the `dispatch` method to accept `MultiproofInput` directly, simplifying the handling of proof targets.
- Removed the separate handling for `PendingMultiproofTask`, consolidating the dispatch logic.
- Introduced `into_multiproof` method in `ProofResult` for converting proof results into `DecodedMultiProof`, enhancing clarity and usability.
- Updated the extraction of storage proofs to directly match against `ProofResult`, improving clarity and reducing unnecessary complexity.
- Replaced error handling for mismatched addresses with `debug_assert_eq!` for better debugging during development.
- Ensured that unreachable code paths are clearly defined for account multiproof handling, enhancing code safety and maintainability.
@yongkangc yongkangc marked this pull request as ready for review October 27, 2025 05:38
@yongkangc yongkangc self-assigned this Oct 27, 2025
@yongkangc yongkangc moved this from Backlog to In Review in Reth Tracker Oct 27, 2025
@yongkangc yongkangc closed this Oct 27, 2025
@github-project-automation github-project-automation bot moved this from In Review to Done in Reth Tracker Oct 27, 2025
@yongkangc
Copy link
Member Author

splitting this up into smaller prs to review :)

@jenpaff jenpaff moved this from Done to Out of Scope in Reth Tracker Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Out of Scope

Development

Successfully merging this pull request may close these issues.

refactor: clean up multiproof code for better abstractions

2 participants