pub trait DatabaseStateRoot<'a, TX>: Sized {
// Required methods
fn from_tx(tx: &'a TX) -> Self;
fn incremental_root_calculator(
tx: &'a TX,
range: RangeInclusive<BlockNumber>,
) -> Result<Self, StateRootError>;
fn incremental_root(
tx: &'a TX,
range: RangeInclusive<BlockNumber>,
) -> Result<B256, StateRootError>;
fn incremental_root_with_updates(
tx: &'a TX,
range: RangeInclusive<BlockNumber>,
) -> Result<(B256, TrieUpdates), StateRootError>;
fn incremental_root_with_progress(
tx: &'a TX,
range: RangeInclusive<BlockNumber>,
) -> Result<StateRootProgress, StateRootError>;
fn overlay_root(
tx: &'a TX,
post_state: HashedPostState,
) -> Result<B256, StateRootError>;
fn overlay_root_with_updates(
tx: &'a TX,
post_state: HashedPostState,
) -> Result<(B256, TrieUpdates), StateRootError>;
fn overlay_root_from_nodes(
tx: &'a TX,
input: TrieInput,
) -> Result<B256, StateRootError>;
fn overlay_root_from_nodes_with_updates(
tx: &'a TX,
input: TrieInput,
) -> Result<(B256, TrieUpdates), StateRootError>;
}
Expand description
Extends StateRoot
with operations specific for working with a database transaction.
Required Methods§
Sourcefn incremental_root_calculator(
tx: &'a TX,
range: RangeInclusive<BlockNumber>,
) -> Result<Self, StateRootError>
fn incremental_root_calculator( tx: &'a TX, range: RangeInclusive<BlockNumber>, ) -> 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.
Sourcefn incremental_root(
tx: &'a TX,
range: RangeInclusive<BlockNumber>,
) -> Result<B256, StateRootError>
fn incremental_root( tx: &'a TX, range: RangeInclusive<BlockNumber>, ) -> Result<B256, StateRootError>
Computes the state root of the trie with the changed account and storage prefixes and existing trie nodes.
§Returns
The updated state root.
Sourcefn incremental_root_with_updates(
tx: &'a TX,
range: RangeInclusive<BlockNumber>,
) -> Result<(B256, TrieUpdates), StateRootError>
fn incremental_root_with_updates( tx: &'a TX, range: RangeInclusive<BlockNumber>, ) -> Result<(B256, 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.
Sourcefn incremental_root_with_progress(
tx: &'a TX,
range: RangeInclusive<BlockNumber>,
) -> Result<StateRootProgress, StateRootError>
fn incremental_root_with_progress( tx: &'a TX, range: RangeInclusive<BlockNumber>, ) -> 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.
Sourcefn overlay_root(
tx: &'a TX,
post_state: HashedPostState,
) -> Result<B256, StateRootError>
fn overlay_root( tx: &'a TX, post_state: HashedPostState, ) -> Result<B256, 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::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
.
Sourcefn overlay_root_with_updates(
tx: &'a TX,
post_state: HashedPostState,
) -> Result<(B256, TrieUpdates), StateRootError>
fn overlay_root_with_updates( tx: &'a TX, post_state: HashedPostState, ) -> Result<(B256, TrieUpdates), StateRootError>
Calculates the state root for this HashedPostState
and returns it alongside trie
updates. See Self::overlay_root
for more info.
Sourcefn overlay_root_from_nodes(
tx: &'a TX,
input: TrieInput,
) -> Result<B256, StateRootError>
fn overlay_root_from_nodes( tx: &'a TX, input: TrieInput, ) -> Result<B256, StateRootError>
Calculates the state root for provided HashedPostState
using cached intermediate nodes.
Sourcefn overlay_root_from_nodes_with_updates(
tx: &'a TX,
input: TrieInput,
) -> Result<(B256, TrieUpdates), StateRootError>
fn overlay_root_from_nodes_with_updates( tx: &'a TX, input: TrieInput, ) -> Result<(B256, 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.