mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
chore(trie): make MultiProofTargets a type alias (#13364)
This commit is contained in:
@ -326,7 +326,7 @@ where
|
|||||||
let hashed_state_update = evm_state_to_hashed_post_state(update);
|
let hashed_state_update = evm_state_to_hashed_post_state(update);
|
||||||
|
|
||||||
let proof_targets = get_proof_targets(&hashed_state_update, fetched_proof_targets);
|
let proof_targets = get_proof_targets(&hashed_state_update, fetched_proof_targets);
|
||||||
fetched_proof_targets.extend_ref(&proof_targets);
|
extend_multi_proof_targets_ref(fetched_proof_targets, &proof_targets);
|
||||||
|
|
||||||
// Dispatch proof gathering for this state update
|
// Dispatch proof gathering for this state update
|
||||||
scope.spawn(move |_| {
|
scope.spawn(move |_| {
|
||||||
@ -379,12 +379,16 @@ where
|
|||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
// Merge all ready proofs and state updates
|
// Merge all ready proofs and state updates
|
||||||
ready_proofs.into_iter().reduce(|mut acc, (state_update, targets, proof)| {
|
ready_proofs.into_iter().reduce(
|
||||||
acc.0.extend(state_update);
|
|(mut acc_state_update, mut acc_targets, mut acc_proof),
|
||||||
acc.1.extend(targets);
|
(state_update, targets, proof)| {
|
||||||
acc.2.extend(proof);
|
acc_state_update.extend(state_update);
|
||||||
acc
|
extend_multi_proof_targets(&mut acc_targets, targets);
|
||||||
})
|
acc_proof.extend(proof);
|
||||||
|
|
||||||
|
(acc_state_update, acc_targets, acc_proof)
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -483,7 +487,10 @@ where
|
|||||||
) {
|
) {
|
||||||
if self.sparse_trie.is_none() {
|
if self.sparse_trie.is_none() {
|
||||||
current_state_update.extend(combined_state_update);
|
current_state_update.extend(combined_state_update);
|
||||||
current_proof_targets.extend(combined_proof_targets);
|
extend_multi_proof_targets(
|
||||||
|
&mut current_proof_targets,
|
||||||
|
combined_proof_targets,
|
||||||
|
);
|
||||||
current_multiproof.extend(combined_proof);
|
current_multiproof.extend(combined_proof);
|
||||||
} else {
|
} else {
|
||||||
self.spawn_root_calculation(
|
self.spawn_root_calculation(
|
||||||
@ -683,6 +690,18 @@ fn update_sparse_trie<
|
|||||||
Ok((trie, elapsed))
|
Ok((trie, elapsed))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn extend_multi_proof_targets(targets: &mut MultiProofTargets, other: MultiProofTargets) {
|
||||||
|
for (address, slots) in other {
|
||||||
|
targets.entry(address).or_default().extend(slots);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extend_multi_proof_targets_ref(targets: &mut MultiProofTargets, other: &MultiProofTargets) {
|
||||||
|
for (address, slots) in other {
|
||||||
|
targets.entry(*address).or_default().extend(slots);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@ -13,29 +13,11 @@ use alloy_trie::{
|
|||||||
proof::{verify_proof, ProofNodes, ProofVerificationError},
|
proof::{verify_proof, ProofNodes, ProofVerificationError},
|
||||||
TrieMask, EMPTY_ROOT_HASH,
|
TrieMask, EMPTY_ROOT_HASH,
|
||||||
};
|
};
|
||||||
use derive_more::derive::{Deref, DerefMut, From, Into, IntoIterator};
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use reth_primitives_traits::Account;
|
use reth_primitives_traits::Account;
|
||||||
|
|
||||||
/// Proof targets map.
|
/// Proof targets map.
|
||||||
#[derive(Debug, Default, Clone, Deref, DerefMut, From, Into, IntoIterator)]
|
pub type MultiProofTargets = B256HashMap<B256HashSet>;
|
||||||
pub struct MultiProofTargets(B256HashMap<B256HashSet>);
|
|
||||||
|
|
||||||
impl MultiProofTargets {
|
|
||||||
/// Extends the proof targets map with another one.
|
|
||||||
pub fn extend(&mut self, other: Self) {
|
|
||||||
for (address, slots) in other.0 {
|
|
||||||
self.0.entry(address).or_default().extend(slots);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Extends the proof targets map with another one by reference.
|
|
||||||
pub fn extend_ref(&mut self, other: &Self) {
|
|
||||||
for (address, slots) in &other.0 {
|
|
||||||
self.0.entry(*address).or_default().extend(slots);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The state multiproof of target accounts and multiproofs of their storage tries.
|
/// The state multiproof of target accounts and multiproofs of their storage tries.
|
||||||
/// Multiproof is effectively a state subtrie that only contains the nodes
|
/// Multiproof is effectively a state subtrie that only contains the nodes
|
||||||
|
|||||||
@ -39,9 +39,7 @@ fn includes_empty_node_preimage() {
|
|||||||
|
|
||||||
let state_root = StateRoot::from_tx(provider.tx_ref()).root().unwrap();
|
let state_root = StateRoot::from_tx(provider.tx_ref()).root().unwrap();
|
||||||
let multiproof = Proof::from_tx(provider.tx_ref())
|
let multiproof = Proof::from_tx(provider.tx_ref())
|
||||||
.multiproof(
|
.multiproof(HashMap::from_iter([(hashed_address, HashSet::from_iter([hashed_slot]))]))
|
||||||
HashMap::from_iter([(hashed_address, HashSet::from_iter([hashed_slot]))]).into(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let witness = TrieWitness::from_tx(provider.tx_ref())
|
let witness = TrieWitness::from_tx(provider.tx_ref())
|
||||||
@ -79,9 +77,7 @@ fn includes_nodes_for_destroyed_storage_nodes() {
|
|||||||
|
|
||||||
let state_root = StateRoot::from_tx(provider.tx_ref()).root().unwrap();
|
let state_root = StateRoot::from_tx(provider.tx_ref()).root().unwrap();
|
||||||
let multiproof = Proof::from_tx(provider.tx_ref())
|
let multiproof = Proof::from_tx(provider.tx_ref())
|
||||||
.multiproof(
|
.multiproof(HashMap::from_iter([(hashed_address, HashSet::from_iter([hashed_slot]))]))
|
||||||
HashMap::from_iter([(hashed_address, HashSet::from_iter([hashed_slot]))]).into(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let witness =
|
let witness =
|
||||||
@ -126,13 +122,10 @@ fn correctly_decodes_branch_node_values() {
|
|||||||
|
|
||||||
let state_root = StateRoot::from_tx(provider.tx_ref()).root().unwrap();
|
let state_root = StateRoot::from_tx(provider.tx_ref()).root().unwrap();
|
||||||
let multiproof = Proof::from_tx(provider.tx_ref())
|
let multiproof = Proof::from_tx(provider.tx_ref())
|
||||||
.multiproof(
|
.multiproof(HashMap::from_iter([(
|
||||||
HashMap::from_iter([(
|
hashed_address,
|
||||||
hashed_address,
|
HashSet::from_iter([hashed_slot1, hashed_slot2]),
|
||||||
HashSet::from_iter([hashed_slot1, hashed_slot2]),
|
)]))
|
||||||
)])
|
|
||||||
.into(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let witness = TrieWitness::from_tx(provider.tx_ref())
|
let witness = TrieWitness::from_tx(provider.tx_ref())
|
||||||
|
|||||||
@ -560,8 +560,7 @@ mod tests {
|
|||||||
HashMap::from_iter([
|
HashMap::from_iter([
|
||||||
(address_1, HashSet::from_iter([slot_1, slot_2])),
|
(address_1, HashSet::from_iter([slot_1, slot_2])),
|
||||||
(address_2, HashSet::from_iter([slot_1, slot_2])),
|
(address_2, HashSet::from_iter([slot_1, slot_2])),
|
||||||
])
|
]),
|
||||||
.into(),
|
|
||||||
MultiProof {
|
MultiProof {
|
||||||
account_subtree: proof_nodes,
|
account_subtree: proof_nodes,
|
||||||
branch_node_hash_masks: HashMap::from_iter([(
|
branch_node_hash_masks: HashMap::from_iter([(
|
||||||
|
|||||||
@ -91,7 +91,7 @@ where
|
|||||||
let proof =
|
let proof =
|
||||||
Proof::new(self.trie_cursor_factory.clone(), self.hashed_cursor_factory.clone())
|
Proof::new(self.trie_cursor_factory.clone(), self.hashed_cursor_factory.clone())
|
||||||
.with_prefix_sets_mut(self.prefix_sets.as_ref().clone())
|
.with_prefix_sets_mut(self.prefix_sets.as_ref().clone())
|
||||||
.multiproof(targets.into())
|
.multiproof(targets)
|
||||||
.map_err(|error| SparseTrieErrorKind::Other(Box::new(error)))?;
|
.map_err(|error| SparseTrieErrorKind::Other(Box::new(error)))?;
|
||||||
|
|
||||||
Ok(proof.account_subtree.into_inner().remove(path))
|
Ok(proof.account_subtree.into_inner().remove(path))
|
||||||
|
|||||||
@ -94,10 +94,10 @@ where
|
|||||||
slots: &[B256],
|
slots: &[B256],
|
||||||
) -> Result<AccountProof, StateProofError> {
|
) -> Result<AccountProof, StateProofError> {
|
||||||
Ok(self
|
Ok(self
|
||||||
.multiproof(
|
.multiproof(HashMap::from_iter([(
|
||||||
HashMap::from_iter([(keccak256(address), slots.iter().map(keccak256).collect())])
|
keccak256(address),
|
||||||
.into(),
|
slots.iter().map(keccak256).collect(),
|
||||||
)?
|
)]))?
|
||||||
.account_proof(address, slots)?)
|
.account_proof(address, slots)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user