Trait DatabaseStateRoot
pub trait DatabaseStateRoot<'a, TX>: Sized {
// Required methods
fn from_tx(tx: &'a TX) -> Self;
fn incremental_root_calculator(
tx: &'a TX,
range: RangeInclusive<u64>,
) -> Result<Self, StateRootError>;
fn incremental_root(
tx: &'a TX,
range: RangeInclusive<u64>,
) -> Result<FixedBytes<32>, StateRootError>;
fn incremental_root_with_updates(
tx: &'a TX,
range: RangeInclusive<u64>,
) -> Result<(FixedBytes<32>, TrieUpdates), StateRootError>;
fn incremental_root_with_progress(
tx: &'a TX,
range: RangeInclusive<u64>,
) -> Result<StateRootProgress, StateRootError>;
fn overlay_root(
tx: &'a TX,
post_state: HashedPostState,
) -> Result<FixedBytes<32>, StateRootError>;
fn overlay_root_with_updates(
tx: &'a TX,
post_state: HashedPostState,
) -> Result<(FixedBytes<32>, TrieUpdates), StateRootError>;
fn overlay_root_from_nodes(
tx: &'a TX,
input: TrieInput,
) -> Result<FixedBytes<32>, StateRootError>;
fn overlay_root_from_nodes_with_updates(
tx: &'a TX,
input: TrieInput,
) -> Result<(FixedBytes<32>, TrieUpdates), StateRootError>;
}
trie
and trie-db
only.Expand description
Extends StateRoot
with operations specific for working with a database transaction.
Required Methods§
fn incremental_root_calculator(
tx: &'a TX,
range: RangeInclusive<u64>,
) -> Result<Self, StateRootError>
fn incremental_root_calculator( tx: &'a TX, range: RangeInclusive<u64>, ) -> Result<Self, StateRootError>
Given a block number range, identifies all the accounts and storage keys that have changed.
§Returns
An instance of state root calculator with account and storage prefixes loaded.
fn incremental_root(
tx: &'a TX,
range: RangeInclusive<u64>,
) -> Result<FixedBytes<32>, StateRootError>
fn incremental_root( tx: &'a TX, range: RangeInclusive<u64>, ) -> Result<FixedBytes<32>, StateRootError>
Computes the state root of the trie with the changed account and storage prefixes and existing trie nodes.
§Returns
The updated state root.
fn incremental_root_with_updates(
tx: &'a TX,
range: RangeInclusive<u64>,
) -> Result<(FixedBytes<32>, TrieUpdates), StateRootError>
fn incremental_root_with_updates( tx: &'a TX, range: RangeInclusive<u64>, ) -> Result<(FixedBytes<32>, TrieUpdates), StateRootError>
Computes the state root of the trie with the changed account and storage prefixes and existing trie nodes collecting updates in the process.
Ignores the threshold.
§Returns
The updated state root and the trie updates.
fn incremental_root_with_progress(
tx: &'a TX,
range: RangeInclusive<u64>,
) -> Result<StateRootProgress, StateRootError>
fn incremental_root_with_progress( tx: &'a TX, range: RangeInclusive<u64>, ) -> Result<StateRootProgress, StateRootError>
Computes the state root of the trie with the changed account and storage prefixes and existing trie nodes collecting updates in the process.
§Returns
The intermediate progress of state root computation.
fn overlay_root(
tx: &'a TX,
post_state: HashedPostState,
) -> Result<FixedBytes<32>, StateRootError>
fn overlay_root( tx: &'a TX, post_state: HashedPostState, ) -> Result<FixedBytes<32>, StateRootError>
Calculate the state root for this HashedPostState
.
Internally, this method retrieves prefixsets and uses them
to calculate incremental state root.
§Example
use alloy_primitives::U256;
use reth_db::test_utils::create_test_rw_db;
use reth_db_api::database::Database;
use reth_primitives_traits::Account;
use reth_trie::{updates::TrieUpdates, HashedPostState, StateRoot};
use reth_trie_db::DatabaseStateRoot;
// Initialize the database
let db = create_test_rw_db();
// Initialize hashed post state
let mut hashed_state = HashedPostState::default();
hashed_state.accounts.insert(
[0x11; 32].into(),
Some(Account { nonce: 1, balance: U256::from(10), bytecode_hash: None }),
);
// Calculate the state root
let tx = db.tx().expect("failed to create transaction");
let state_root = StateRoot::overlay_root(&tx, hashed_state);
§Returns
The state root for this HashedPostState
.
fn overlay_root_with_updates(
tx: &'a TX,
post_state: HashedPostState,
) -> Result<(FixedBytes<32>, TrieUpdates), StateRootError>
fn overlay_root_with_updates( tx: &'a TX, post_state: HashedPostState, ) -> Result<(FixedBytes<32>, TrieUpdates), StateRootError>
Calculates the state root for this HashedPostState
and returns it alongside trie
updates. See Self::overlay_root
for more info.
fn overlay_root_from_nodes(
tx: &'a TX,
input: TrieInput,
) -> Result<FixedBytes<32>, StateRootError>
fn overlay_root_from_nodes( tx: &'a TX, input: TrieInput, ) -> Result<FixedBytes<32>, StateRootError>
Calculates the state root for provided HashedPostState
using cached intermediate nodes.
fn overlay_root_from_nodes_with_updates(
tx: &'a TX,
input: TrieInput,
) -> Result<(FixedBytes<32>, TrieUpdates), StateRootError>
fn overlay_root_from_nodes_with_updates( tx: &'a TX, input: TrieInput, ) -> Result<(FixedBytes<32>, TrieUpdates), StateRootError>
Calculates the state root and trie updates for provided HashedPostState
using
cached intermediate nodes.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.