mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(trie): expose multiproof via StateProofProvider (#10915)
This commit is contained in:
@ -4,9 +4,10 @@ use reth_execution_errors::StateProofError;
|
||||
use reth_primitives::{Address, B256};
|
||||
use reth_trie::{
|
||||
hashed_cursor::HashedPostStateCursorFactory, proof::Proof,
|
||||
trie_cursor::InMemoryTrieCursorFactory, TrieInput,
|
||||
trie_cursor::InMemoryTrieCursorFactory, MultiProof, TrieInput,
|
||||
};
|
||||
use reth_trie_common::AccountProof;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
/// Extends [`Proof`] with operations specific for working with a database transaction.
|
||||
pub trait DatabaseProof<'a, TX> {
|
||||
@ -20,6 +21,13 @@ pub trait DatabaseProof<'a, TX> {
|
||||
address: Address,
|
||||
slots: &[B256],
|
||||
) -> Result<AccountProof, StateProofError>;
|
||||
|
||||
/// Generates the state [`MultiProof`] for target hashed account and storage keys.
|
||||
fn overlay_multiproof(
|
||||
tx: &'a TX,
|
||||
input: TrieInput,
|
||||
targets: HashMap<B256, HashSet<B256>>,
|
||||
) -> Result<MultiProof, StateProofError>;
|
||||
}
|
||||
|
||||
impl<'a, TX: DbTx> DatabaseProof<'a, TX>
|
||||
@ -50,4 +58,25 @@ impl<'a, TX: DbTx> DatabaseProof<'a, TX>
|
||||
.with_prefix_sets_mut(input.prefix_sets)
|
||||
.account_proof(address, slots)
|
||||
}
|
||||
|
||||
fn overlay_multiproof(
|
||||
tx: &'a TX,
|
||||
input: TrieInput,
|
||||
targets: HashMap<B256, HashSet<B256>>,
|
||||
) -> Result<MultiProof, StateProofError> {
|
||||
let nodes_sorted = input.nodes.into_sorted();
|
||||
let state_sorted = input.state.into_sorted();
|
||||
Self::from_tx(tx)
|
||||
.with_trie_cursor_factory(InMemoryTrieCursorFactory::new(
|
||||
DatabaseTrieCursorFactory::new(tx),
|
||||
&nodes_sorted,
|
||||
))
|
||||
.with_hashed_cursor_factory(HashedPostStateCursorFactory::new(
|
||||
DatabaseHashedCursorFactory::new(tx),
|
||||
&state_sorted,
|
||||
))
|
||||
.with_prefix_sets_mut(input.prefix_sets)
|
||||
.with_targets(targets)
|
||||
.multiproof()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user