Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f20d5c8
feat(engine): wiring up of storage proof with tokio pool
yongkangc Oct 1, 2025
0b8e8dc
feat(trie): Extract build_account_multiproof_with_storage() Function
yongkangc Oct 2, 2025
7333845
feat(engine): account proof task integration
yongkangc Oct 2, 2025
2b38f20
preliminary integration of acc proofs
yongkangc Oct 2, 2025
2c424fe
fix for test
yongkangc Oct 2, 2025
85f0ff1
feat(trie): enhance proof task with crossbeam channels
yongkangc Oct 2, 2025
20770f4
refactor(trie): implement on-demand storage proof fetching
yongkangc Oct 2, 2025
5535123
metrics
yongkangc Oct 2, 2025
e24037f
fix clippy
yongkangc Oct 2, 2025
0dd639a
refactor(trie): improve on-demand storage proof fetching and add tests
yongkangc Oct 2, 2025
b697bc3
test(trie): add tests for parallel proof with mixed storage targets a…
yongkangc Oct 2, 2025
8cade5d
feat(trie): add storage proof metrics to ParallelTrieStats and Parall…
yongkangc Oct 2, 2025
cbe59c3
fix(engine): handle spawn failure in state root benchmark and update …
yongkangc Oct 2, 2025
f1e0e72
add new test
yongkangc Oct 2, 2025
8dfd1f6
fix: clippy and formatting issues
yongkangc Oct 2, 2025
76675d9
comment
yongkangc Oct 2, 2025
b725d02
refactor(trie): enhance error handling and worker management in proof…
yongkangc Oct 2, 2025
47ded5b
added back stats
yongkangc Oct 2, 2025
e13a7b2
panic recovery
yongkangc Oct 2, 2025
8b64847
fix
yongkangc Oct 2, 2025
a29acfa
fix: race condition on depth -> panic
yongkangc Oct 2, 2025
3049ee9
cleanup comment
yongkangc Oct 2, 2025
471903f
refactor: update proof task concurrency management
yongkangc Oct 2, 2025
d9c6540
fmt
yongkangc Oct 2, 2025
a064beb
refactor(trie): enhance proof job management and error handling
yongkangc Oct 3, 2025
7e1801c
fix rebase
yongkangc Oct 4, 2025
78903e7
fix clippy
yongkangc Oct 4, 2025
e7a15b9
refactor(trie): Remove tx/task_ctx fields from BlindedAccountNode an…
yongkangc Oct 4, 2025
44aefd2
simplify prooftaskmanager
yongkangc Oct 4, 2025
ff4bf72
refactor(trie): remove ProofTaskManager indirection
yongkangc Oct 4, 2025
9c122bd
refactor(trie): relocate storage_channel_closed_error function
yongkangc Oct 5, 2025
f29d0da
refactor(config): enhance proof worker management
yongkangc Oct 5, 2025
8e38531
refactor(tree): streamline proof manager structure
yongkangc Oct 5, 2025
587326e
refactor(engine): integrate dynamic proof worker allocation
yongkangc Oct 5, 2025
2f97f23
refactor(multiproof): move frozen_prefix
yongkangc Oct 5, 2025
1e09b87
refactor(tree): use calculate_proof_concurrency function
yongkangc Oct 5, 2025
ab8bf51
optimse clone
yongkangc Oct 5, 2025
2ba7905
fmt
yongkangc Oct 5, 2025
3c77e7d
fix: attempt to fix multiproof generation
yongkangc Oct 6, 2025
70a88c3
refactor(multiproof): streamline storage proof request handling
yongkangc Oct 6, 2025
5bda712
debug log:
yongkangc Oct 6, 2025
aa0e9d0
add debug logs again to understan the bug
yongkangc Oct 6, 2025
b89e38d
add debug log:
yongkangc Oct 6, 2025
5aadea6
fix: remove caching of frozen_prefix_set
yongkangc Oct 6, 2025
0552828
fmt, clippy
yongkangc Oct 6, 2025
befaf10
debug logs:
yongkangc Oct 6, 2025
1031894
fix: Account trie walker encounters a leaf for hashed_address that is…
yongkangc Oct 6, 2025
2103862
feat: restore caching for missed leaf storage roots
yongkangc Oct 6, 2025
38bb377
fixes to compile
yongkangc Oct 6, 2025
85f95fe
rm stats
yongkangc Oct 6, 2025
bb3d9bd
add logs: identify root cause of stall
yongkangc Oct 6, 2025
e012683
fix clippy
yongkangc Oct 6, 2025
36a6390
improve comments
yongkangc Oct 6, 2025
2f6de56
update comments
yongkangc Oct 6, 2025
cf86a17
fmt
yongkangc Oct 6, 2025
1a41987
rm comments
yongkangc Oct 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 102 additions & 0 deletions crates/engine/primitives/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,76 @@ pub const DEFAULT_MULTIPROOF_TASK_CHUNK_SIZE: usize = 10;
/// This will be deducted from the thread count of main reth global threadpool.
pub const DEFAULT_RESERVED_CPU_CORES: usize = 1;

/// Upper limit for storage proof workers to prevent excessive memory usage.
const MAX_STORAGE_PROOF_WORKERS: usize = 12;

/// Upper limit for account proof workers to prevent excessive memory usage.
const MAX_ACCOUNT_PROOF_WORKERS: usize = 4;

/// Lower limit for storage proof workers to maintain pipeline progress.
const MIN_STORAGE_PROOF_WORKERS: usize = 2;

/// Lower limit for account proof workers to keep the pool active.
const MIN_ACCOUNT_PROOF_WORKERS: usize = 1;

/// Default `(storage, account)` worker counts used when CPU detection fails.
const FALLBACK_PROOF_WORKERS: (usize, usize) = (6, 2);

/// Calculates optimal `(storage, account)` proof worker counts based on available CPU cores.
///
/// Each worker runs in a dedicated blocking thread via `tokio::spawn_blocking`. The allocation
/// strategy:
/// 1. Query available logical CPUs via `available_parallelism`
/// 2. Reserve `reserved_cpu_cores` for other tasks (e.g., networking, RPC)
/// 3. Allocate remaining cores with a 3:1 ratio favoring storage proofs (which are more intensive)
/// 4. Clamp results to `[MIN, MAX]` bounds to handle both low-core and high-core systems
///
/// Returns `(6, 2)` if CPU detection fails.
pub fn default_proof_workers(reserved_cpu_cores: usize) -> (usize, usize) {
#[cfg(feature = "std")]
{
if let Ok(parallelism) = std::thread::available_parallelism() {
return split_proof_worker_budget(parallelism.get(), reserved_cpu_cores);
}
}

FALLBACK_PROOF_WORKERS
}

#[cfg(feature = "std")]
/// Splits the usable CPU budget into storage/account threads while applying the fixed 3:1 ratio
/// and clamping to the configured min/max bounds.
fn split_proof_worker_budget(parallelism: usize, reserved_cpu_cores: usize) -> (usize, usize) {
const STORAGE_WEIGHT: usize = 3;
const ACCOUNT_WEIGHT: usize = 1;
const TOTAL_WEIGHT: usize = STORAGE_WEIGHT + ACCOUNT_WEIGHT;

let usable = parallelism.saturating_sub(reserved_cpu_cores);
let budget = usable.max(MIN_STORAGE_PROOF_WORKERS + MIN_ACCOUNT_PROOF_WORKERS);

let mut storage = (budget * STORAGE_WEIGHT) / TOTAL_WEIGHT;
let mut account = budget.saturating_sub(storage);

storage = storage.clamp(MIN_STORAGE_PROOF_WORKERS, MAX_STORAGE_PROOF_WORKERS);
account = account.clamp(MIN_ACCOUNT_PROOF_WORKERS, MAX_ACCOUNT_PROOF_WORKERS);

(storage, account)
}

/// Default number of storage proof workers, derived from available parallelism.
///
/// Uses [`default_proof_workers`] with [`DEFAULT_RESERVED_CPU_CORES`].
pub fn default_storage_proof_workers() -> usize {
default_proof_workers(DEFAULT_RESERVED_CPU_CORES).0
}

/// Default number of account proof workers, derived from available parallelism.
///
/// Uses [`default_proof_workers`] with [`DEFAULT_RESERVED_CPU_CORES`].
pub fn default_account_proof_workers() -> usize {
default_proof_workers(DEFAULT_RESERVED_CPU_CORES).1
}

/// Default maximum concurrency for prewarm task.
pub const DEFAULT_PREWARM_MAX_CONCURRENCY: usize = 16;

Expand Down Expand Up @@ -81,6 +151,10 @@ pub struct TreeConfig {
has_enough_parallelism: bool,
/// Maximum number of concurrent proof tasks
max_proof_task_concurrency: u64,
/// Number of workers dedicated to storage proof execution
storage_proof_workers: usize,
/// Number of workers dedicated to account proof execution
account_proof_workers: usize,
/// Whether multiproof task should chunk proof targets.
multiproof_chunking_enabled: bool,
/// Multiproof task chunk size for proof targets.
Expand Down Expand Up @@ -127,6 +201,8 @@ impl Default for TreeConfig {
cross_block_cache_size: DEFAULT_CROSS_BLOCK_CACHE_SIZE,
has_enough_parallelism: has_enough_parallelism(),
max_proof_task_concurrency: DEFAULT_MAX_PROOF_TASK_CONCURRENCY,
storage_proof_workers: default_storage_proof_workers(),
account_proof_workers: default_account_proof_workers(),
multiproof_chunking_enabled: true,
multiproof_chunk_size: DEFAULT_MULTIPROOF_TASK_CHUNK_SIZE,
reserved_cpu_cores: DEFAULT_RESERVED_CPU_CORES,
Expand Down Expand Up @@ -156,6 +232,8 @@ impl TreeConfig {
cross_block_cache_size: u64,
has_enough_parallelism: bool,
max_proof_task_concurrency: u64,
storage_proof_workers: usize,
account_proof_workers: usize,
multiproof_chunking_enabled: bool,
multiproof_chunk_size: usize,
reserved_cpu_cores: usize,
Expand All @@ -179,6 +257,8 @@ impl TreeConfig {
cross_block_cache_size,
has_enough_parallelism,
max_proof_task_concurrency,
storage_proof_workers,
account_proof_workers,
multiproof_chunking_enabled,
multiproof_chunk_size,
reserved_cpu_cores,
Expand Down Expand Up @@ -220,6 +300,16 @@ impl TreeConfig {
self.max_proof_task_concurrency
}

/// Return the number of storage proof workers.
pub const fn storage_proof_workers(&self) -> usize {
self.storage_proof_workers
}

/// Return the number of account proof workers.
pub const fn account_proof_workers(&self) -> usize {
self.account_proof_workers
}

/// Return whether the multiproof task chunking is enabled.
pub const fn multiproof_chunking_enabled(&self) -> bool {
self.multiproof_chunking_enabled
Expand Down Expand Up @@ -398,6 +488,18 @@ impl TreeConfig {
self
}

/// Setter for number of storage proof workers.
pub const fn with_storage_proof_workers(mut self, storage_proof_workers: usize) -> Self {
self.storage_proof_workers = storage_proof_workers;
self
}

/// Setter for number of account proof workers.
pub const fn with_account_proof_workers(mut self, account_proof_workers: usize) -> Self {
self.account_proof_workers = account_proof_workers;
self
}

/// Setter for whether multiproof task should chunk proof targets.
pub const fn with_multiproof_chunking_enabled(
mut self,
Expand Down
1 change: 1 addition & 0 deletions crates/engine/tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ thiserror.workspace = true
tokio = { workspace = true, features = ["rt", "rt-multi-thread", "sync", "macros"] }
mini-moka = { workspace = true, features = ["sync"] }
smallvec.workspace = true
crossbeam-channel.workspace = true

# metrics
metrics.workspace = true
Expand Down
25 changes: 15 additions & 10 deletions crates/engine/tree/benches/state_root_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,21 @@ fn bench_state_root(c: &mut Criterion) {
},
|(genesis_hash, mut payload_processor, provider, state_updates)| {
black_box({
let mut handle = payload_processor.spawn(
Default::default(),
core::iter::empty::<
Result<Recovered<TransactionSigned>, core::convert::Infallible>,
>(),
StateProviderBuilder::new(provider.clone(), genesis_hash, None),
ConsistentDbView::new_with_latest_tip(provider).unwrap(),
TrieInput::default(),
&TreeConfig::default(),
);
let mut handle = payload_processor
.spawn(
Default::default(),
core::iter::empty::<
Result<
Recovered<TransactionSigned>,
core::convert::Infallible,
>,
>(),
StateProviderBuilder::new(provider.clone(), genesis_hash, None),
ConsistentDbView::new_with_latest_tip(provider).unwrap(),
TrieInput::default(),
&TreeConfig::default(),
)
.expect("spawn failed");

let mut state_hook = handle.state_hook();

Expand Down
Loading