Type Alias StateDBBox

pub type StateDBBox<'a, E> = State<Box<dyn Database<Error = E> + Send + 'a>>;
Expand description

More constrained version of State that uses Boxed database with a lifetime

This is used to make it easier to use State.

Aliased Type§

struct StateDBBox<'a, E> {
    pub cache: CacheState,
    pub database: Box<dyn Database<Error = E> + Send + 'a>,
    pub transition_state: Option<TransitionState>,
    pub bundle_state: BundleState,
    pub use_preloaded_bundle: bool,
    pub block_hashes: BTreeMap<u64, FixedBytes<32>>,
}

Fields§

§cache: CacheState

Cached state contains both changed from evm execution and cached/loaded account/storages from database

This allows us to have only one layer of cache where we can fetch data.

Additionally, we can introduce some preloading of data from database.

§database: Box<dyn Database<Error = E> + Send + 'a>

Optional database that we use to fetch data from

If database is not present, we will return not existing account and storage.

Note: It is marked as Send so database can be shared between threads.

§transition_state: Option<TransitionState>

Block state, it aggregates transactions transitions into one state

Build reverts and state that gets applied to the state.

§bundle_state: BundleState

After block is finishes we merge those changes inside bundle

Bundle is used to update database and create changesets.

Bundle state can be set on initialization if we want to use preloaded bundle.

§use_preloaded_bundle: bool

Addition layer that is going to be used to fetched values before fetching values from database

Bundle is the main output of the state execution and this allows setting previous bundle and using its values for execution.

§block_hashes: BTreeMap<u64, FixedBytes<32>>

If EVM asks for block hash, we will first check if they are found here, then ask the database

This map can be used to give different values for block hashes if in case.

The fork block is different or some blocks are not saved inside database.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 296 bytes

Implementations

§

impl<DB> State<DB>
where DB: Database,

pub fn bundle_size_hint(&self) -> usize

Returns the size hint for the inner bundle state.

See BundleState::size_hint for more info.

pub fn increment_balances( &mut self, balances: impl IntoIterator<Item = (Address, u128)>, ) -> Result<(), <DB as Database>::Error>

Iterates over received balances and increment all account balances.

Note: If account is not found inside cache state it will be loaded from database.

Update will create transitions for all accounts that are updated.

Like CacheAccount::increment_balance, this assumes that incremented balances are not zero, and will not overflow once incremented.

If using this to implement withdrawals, zero balances must be filtered out before calling this function.

pub fn drain_balances( &mut self, addresses: impl IntoIterator<Item = Address>, ) -> Result<Vec<u128>, <DB as Database>::Error>

Drains balances from given account and return those values.

It is used for DAO hardfork state change to move values from given accounts.

pub fn set_state_clear_flag(&mut self, has_state_clear: bool)

State clear EIP-161 is enabled in Spurious Dragon hardfork.

pub fn insert_not_existing(&mut self, address: Address)

pub fn insert_account(&mut self, address: Address, info: AccountInfo)

pub fn insert_account_with_storage( &mut self, address: Address, info: AccountInfo, storage: HashMap<Uint<256, 4>, Uint<256, 4>, RandomState>, )

pub fn apply_transition( &mut self, transitions: Vec<(Address, TransitionAccount)>, )

Applies evm transitions to transition state.

pub fn merge_transitions(&mut self, retention: BundleRetention)

Take all transitions and merge them inside bundle state.

This action will create final post state and all reverts so that we at any time revert state of bundle to the state before transition is applied.

pub fn load_cache_account( &mut self, address: Address, ) -> Result<&mut CacheAccount, <DB as Database>::Error>

Get a mutable reference to the CacheAccount for the given address.

If the account is not found in the cache, it will be loaded from the database and inserted into the cache.

pub fn take_bundle(&mut self) -> BundleState

Takess the BundleState changeset from the State, replacing it with an empty one.

This will not apply any pending TransitionState.

It is recommended to call State::merge_transitions before taking the bundle.

If the State has been built with the StateBuilder::with_bundle_prestate option, the pre-state will be taken along with any changes made by State::merge_transitions.

Trait Implementations

§

impl<DB> Database for State<DB>
where DB: Database,

§

type Error = <DB as Database>::Error

The database error type.
§

fn basic( &mut self, address: Address, ) -> Result<Option<AccountInfo>, <State<DB> as Database>::Error>

Gets basic account information.
§

fn code_by_hash( &mut self, code_hash: FixedBytes<32>, ) -> Result<Bytecode, <State<DB> as Database>::Error>

Gets account code by its hash.
§

fn storage( &mut self, address: Address, index: Uint<256, 4>, ) -> Result<Uint<256, 4>, <State<DB> as Database>::Error>

Gets storage value of address at index.
§

fn block_hash( &mut self, number: u64, ) -> Result<FixedBytes<32>, <State<DB> as Database>::Error>

Gets block hash by block number.
§

impl<DB> DatabaseCommit for State<DB>
where DB: Database,

§

fn commit(&mut self, evm_state: HashMap<Address, Account, RandomState>)

Commit changes to the database.
§

impl<DB> Debug for State<DB>
where DB: Debug,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<DB> OverrideBlockHashes for State<DB>

Source§

fn override_block_hashes(&mut self, block_hashes: BTreeMap<u64, FixedBytes<32>>)

Overrides the given block hashes.