Trait reth_trie_db::DatabaseStateRoot

source ·
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§

source

fn from_tx(tx: &'a TX) -> Self

Create a new [StateRoot] instance.

source

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.

source

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.

source

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.

source

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.

source

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 reth_db::test_utils::create_test_rw_db;
use reth_db_api::database::Database;
use reth_primitives::{Account, U256};
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].

source

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.

source

fn overlay_root_from_nodes( tx: &'a TX, input: TrieInput, ) -> Result<B256, StateRootError>

Calculates the state root for provided [HashedPostState] using cached intermediate nodes.

source

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'a, TX: DbTx> DatabaseStateRoot<'a, TX> for StateRoot<DatabaseTrieCursorFactory<'a, TX>, DatabaseHashedCursorFactory<'a, TX>>

source§

fn from_tx(tx: &'a TX) -> Self

source§

fn incremental_root_calculator( tx: &'a TX, range: RangeInclusive<BlockNumber>, ) -> Result<Self, StateRootError>

source§

fn incremental_root( tx: &'a TX, range: RangeInclusive<BlockNumber>, ) -> Result<B256, StateRootError>

source§

fn incremental_root_with_updates( tx: &'a TX, range: RangeInclusive<BlockNumber>, ) -> Result<(B256, TrieUpdates), StateRootError>

source§

fn incremental_root_with_progress( tx: &'a TX, range: RangeInclusive<BlockNumber>, ) -> Result<StateRootProgress, StateRootError>

source§

fn overlay_root( tx: &'a TX, post_state: HashedPostState, ) -> Result<B256, StateRootError>

source§

fn overlay_root_with_updates( tx: &'a TX, post_state: HashedPostState, ) -> Result<(B256, TrieUpdates), StateRootError>

source§

fn overlay_root_from_nodes( tx: &'a TX, input: TrieInput, ) -> Result<B256, StateRootError>

source§

fn overlay_root_from_nodes_with_updates( tx: &'a TX, input: TrieInput, ) -> Result<(B256, TrieUpdates), StateRootError>

Implementors§