pub struct State<B> { /* private fields */ }
Expand description

Representation of the entire state of all accounts in the system.

State can work together with StateDB to share account cache.

Local cache contains changes made locally and changes accumulated locally from previous commits. Global cache reflects the database state and never contains any changes.

Cache items contains account data, or the flag that account does not exist and modification state (see AccountState)

Account data can be in the following cache states:

  • In global but not local - something that was queried from the database, but never modified
  • In local but not global - something that was just added (e.g. new account)
  • In both with the same value - something that was changed to a new value, but changed back to a previous block in the same block (same State instance)
  • In both with different values - something that was overwritten with a new value.

All read-only state queries check local cache/modifications first, then global state cache. If data is not found in any of the caches it is loaded from the DB to the local cache.

**** IMPORTANT ************************************************************* All the modifications to the account data must set the Dirty state in the AccountEntry. This is done in require and require_or_from. So just use that.


Upon destruction all the local cache data propagated into the global cache. Propagated items might be rejected if current state is non-canonical.

State checkpointing.

A new checkpoint can be created with checkpoint(). checkpoints can be created in a hierarchy. When a checkpoint is active all changes are applied directly into cache and the original value is copied into an active checkpoint. Reverting a checkpoint with revert_to_checkpoint involves copying original values from the latest checkpoint back into cache. The code takes care not to overwrite cached storage while doing that. checkpoint can be discarded with discard_checkpoint. All of the orignal backed-up values are moved into a parent checkpoint (if any).

Implementations

Creates new state with empty state root Used for tests.

Creates new state with existing state root

Get a VM factory that can execute on this state.

Create a recoverable checkpoint of this state. Return the checkpoint index.

Merge last checkpoint with previous.

Revert to the last checkpoint and discard it.

Destroy the current object and return root and database.

Destroy the current object and return single account data.

Return reference to root

Create a new contract at address contract. If there is already an account at the address it will have its code reset, ready for init_code().

Remove an existing account.

Determine whether an account exists.

Determine whether an account exists and if not empty.

Determine whether an account exists and has code or non-zero nonce.

Get the balance of account a.

Get the nonce of account a.

Whether the base storage root of an account remains unchanged.

Get the storage root of account a.

Get the original storage root since last commit of account a.

Get the value of storage at a specific checkpoint.

Mutate storage of account address so that it is value for key.

Get the value of storage after last state commitment.

Get accounts’ code.

Get an account’s code hash.

Get accounts’ code size.

Add incr to the balance of account a.

Subtract decr from the balance of account a.

Subtracts by from the balance of from and adds it to that of to.

Increment the nonce of account a by 1.

Mutate storage of account a so that it is value for key.

Initialise the code of account a so that it is code. NOTE: Account should have been created with new_contract.

Reset the code of account a so that it is code.

Execute a given transaction, producing a receipt and an optional trace. This will change the state accordingly.

Execute a given transaction with given tracer and VM tracer producing a receipt and an optional trace. This will change the state accordingly.

t_nb 8.5.2 Commits our cached account changes into the trie.

Clear state cache

Remove any touched empty or dust accounts.

Populate the state from accounts. Used for tests.

Returns a StateDiff describing the difference from orig to self. Consumes self.

Replace account code and storage. Creates account if it does not exist.

Prove an account’s existence or nonexistence in the state trie. Returns a merkle proof of the account’s trie node omitted or an encountered trie error. If the account doesn’t exist in the trie, prove that and return defaults. Requires a secure trie to be used for accurate results. account_key == keccak(address)

Prove an account’s storage key’s existence or nonexistence in the state. Returns a merkle proof of the account’s storage trie. Requires a secure trie to be used for correctness. account_key == keccak(address) storage_key == keccak(key)

Get a reference to the underlying state DB.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Get the nonce of account a.

Get the balance of account a.

Mutate storage of account address so that it is value for key.

Get accounts’ code.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.