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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
098a08b
feat(engine): proof fetching on state update for StateRootTask
fgimenez Nov 18, 2024
154aa8c
fix account trie nodes collection
fgimenez Nov 18, 2024
d950182
add state root from proofs bench and simplify account trie nodes coll…
fgimenez Nov 18, 2024
06db565
extend test to check state root value
fgimenez Nov 19, 2024
38d0b66
use reth_testing_utils::generators
fgimenez Nov 20, 2024
acf8254
fix test
fgimenez Nov 20, 2024
ea292e8
prevent state root calculation and returning final result without the…
fgimenez Nov 20, 2024
02e75e8
do not share provider among workers
fgimenez Nov 21, 2024
74bf59f
add error traces for multiproof tasks
fgimenez Nov 21, 2024
9eadda3
use map_init to initialize provider once per thread in calculate_stat…
fgimenez Nov 21, 2024
7032bfe
Update crates/engine/tree/src/tree/root.rs
fgimenez Nov 22, 2024
a4c3bbf
fmt
fgimenez Nov 22, 2024
cebcbd8
refactor: StateRootMessages and single channel for managing task state
fgimenez Nov 22, 2024
00345a6
fix add proof
fgimenez Nov 22, 2024
589b1b2
fix add_proof
fgimenez Nov 22, 2024
227fdc4
reduce test state elements
fgimenez Nov 22, 2024
992e96d
refactor: remove incoming state updates thread
fgimenez Nov 25, 2024
0d4e70b
StateRootMessage -> InternalMessage
fgimenez Nov 25, 2024
44d3a61
feat(engine): use non-parallel multiproof for state root task (#12849)
shekhirin Nov 25, 2024
776cef8
add StateRootMessage::StateUpdate variant and manage internal task st…
fgimenez Nov 25, 2024
6b3d67a
Update crates/engine/tree/src/tree/root.rs
fgimenez Nov 26, 2024
344a9b8
fix add_proof
fgimenez Nov 27, 2024
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
5 changes: 5 additions & 0 deletions Cargo.lock

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

11 changes: 11 additions & 0 deletions crates/engine/tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ reth-consensus.workspace = true
reth-engine-primitives.workspace = true
reth-errors.workspace = true
reth-evm.workspace = true
reth-execution-errors.workspace = true
reth-network-p2p.workspace = true
reth-payload-builder-primitives.workspace = true
reth-payload-builder.workspace = true
Expand All @@ -32,6 +33,7 @@ reth-prune.workspace = true
reth-revm.workspace = true
reth-stages-api.workspace = true
reth-tasks.workspace = true
reth-trie-db.workspace = true
reth-trie-parallel.workspace = true
reth-trie-sparse.workspace = true
reth-trie.workspace = true
Expand All @@ -55,6 +57,7 @@ metrics.workspace = true
reth-metrics = { workspace = true, features = ["common"] }

# misc
rayon.workspace = true
tracing.workspace = true

# optional deps for test-utils
Expand All @@ -77,6 +80,7 @@ reth-prune.workspace = true
reth-rpc-types-compat.workspace = true
reth-stages = { workspace = true, features = ["test-utils"] }
reth-static-file.workspace = true
reth-testing-utils.workspace = true
reth-tracing.workspace = true

# alloy
Expand All @@ -85,11 +89,16 @@ alloy-rlp.workspace = true
assert_matches.workspace = true
criterion.workspace = true
crossbeam-channel = "0.5.13"
rand.workspace = true

[[bench]]
name = "channel_perf"
harness = false

[[bench]]
name = "state_root_from_proofs"
harness = false

[features]
test-utils = [
"reth-blockchain-tree/test-utils",
Expand All @@ -110,4 +119,6 @@ test-utils = [
"reth-static-file",
"reth-tracing",
"reth-trie/test-utils",
"reth-prune-types?/test-utils",
"reth-trie-db/test-utils",
]
81 changes: 81 additions & 0 deletions crates/engine/tree/benches/state_root_from_proofs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#![allow(missing_docs)]

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use reth_engine_tree::tree::calculate_state_root_from_proofs;
use reth_provider::{providers::ConsistentDbView, test_utils::create_test_provider_factory};
use reth_trie::{
updates::TrieUpdatesSorted, HashedPostState, HashedPostStateSorted, HashedStorage, MultiProof,
};
use revm_primitives::{
keccak256, Account, AccountInfo, AccountStatus, Address, EvmStorage, EvmStorageSlot, HashMap,
HashSet, B256, U256,
};

fn create_test_state(size: usize) -> (HashMap<B256, HashSet<B256>>, HashedPostState) {
let mut state = HashedPostState::default();
let mut targets = HashMap::default();

for i in 0..size {
let address = Address::random();
let hashed_address = keccak256(address);

// Create account
let info = AccountInfo {
balance: U256::from(100 + i),
nonce: i as u64,
code_hash: B256::random(),
code: Default::default(),
};

// Create storage with multiple slots
let mut storage = EvmStorage::default();
let mut slots = HashSet::default();
for j in 0..100 {
let slot = U256::from(j);
let value = U256::from(100 + j);
storage.insert(slot, EvmStorageSlot::new(value));
slots.insert(keccak256(B256::from(slot)));
}

let account = Account { info, storage: storage.clone(), status: AccountStatus::Loaded };

state.accounts.insert(hashed_address, Some(account.info.into()));
state.storages.insert(
hashed_address,
HashedStorage::from_iter(
false,
storage.into_iter().map(|(k, v)| (keccak256(B256::from(k)), v.present_value)),
),
);
targets.insert(hashed_address, slots);
}

(targets, state)
}

fn bench_state_root_collection(c: &mut Criterion) {
let factory = create_test_provider_factory();
let view = ConsistentDbView::new(factory, None);

let mut group = c.benchmark_group("state_root_collection");
for size in &[10, 100, 1000] {
let (_targets, state) = create_test_state(*size);
let multiproof = MultiProof::default();

group.bench_with_input(format!("size_{}", size), size, |b, _| {
b.iter(|| {
black_box(calculate_state_root_from_proofs(
view.clone(),
&TrieUpdatesSorted::default(),
&HashedPostStateSorted::default(),
multiproof.clone(),
state.clone(),
))
});
});
}
group.finish();
}

criterion_group!(benches, bench_state_root_collection);
criterion_main!(benches);
1 change: 1 addition & 0 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub use config::TreeConfig;
pub use invalid_block_hook::{InvalidBlockHooks, NoopInvalidBlockHook};
pub use persistence_state::PersistenceState;
pub use reth_engine_primitives::InvalidBlockHook;
pub use root::calculate_state_root_from_proofs;

mod root;

Expand Down
Loading
Loading