Type Alias JournalInit

pub type JournalInit = Journal<EmptyDBTyped<Infallible>>;
Expand description

A clonable version of JournaledState that uses EmptyDB. Used to clone the journaled state and for initialization of new journaled state.

Aliased Type§

struct JournalInit {
    pub database: EmptyDBTyped<Infallible>,
    pub state: HashMap<Address, Account, RandomState>,
    pub transient_storage: HashMap<(Address, Uint<256, 4>), Uint<256, 4>, RandomState>,
    pub logs: Vec<Log>,
    pub depth: usize,
    pub journal: Vec<Vec<JournalEntry>>,
    pub spec: SpecId,
    pub warm_preloaded_addresses: HashSet<Address, RandomState>,
    pub precompiles: HashSet<Address, RandomState>,
}

Fields§

§database: EmptyDBTyped<Infallible>

Database

§state: HashMap<Address, Account, RandomState>

The current state

§transient_storage: HashMap<(Address, Uint<256, 4>), Uint<256, 4>, RandomState>

Transient storage that is discarded after every transaction.

See EIP-1153.

§logs: Vec<Log>

Emitted logs

§depth: usize

The current call stack depth

§journal: Vec<Vec<JournalEntry>>

The journal of state changes, one for each call

§spec: SpecId

The spec ID for the EVM

This spec is used for two things:

  • EIP-161: Prior to this EIP, Ethereum had separate definitions for empty and non-existing accounts.
  • EIP-6780: SELFDESTRUCT only in same transaction
§warm_preloaded_addresses: HashSet<Address, RandomState>

Warm loaded addresses are used to check if loaded address should be considered cold or warm loaded when the account is first accessed.

Note that this not include newly loaded accounts, account and storage is considered warm if it is found in the State.

§precompiles: HashSet<Address, RandomState>

Precompile addresses

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: 224 bytes

Implementations

§

impl<DB> Journal<DB>

pub fn from_init( init: &Journal<EmptyDBTyped<Infallible>>, database: DB, ) -> Journal<DB>

Creates a new JournaledState by copying state data from a JournalInit and provided database. This allows reusing the state, logs, and other data from a previous execution context while connecting it to a different database backend.

§

impl<DB> Journal<DB>

pub fn into_init(self) -> Journal<EmptyDBTyped<Infallible>>

Creates a new JournalInit by moving all internal state data (state, storage, logs, etc) into a new journal with an empty database. This consumes the original journal.

This is useful when you want to transfer the current state to a new execution context that doesn’t need access to the original database, like when snapshotting state or forking execution.

If you need to preserve the original journal, use Self::to_init instead which clones the state.

pub fn to_init(&self) -> Journal<EmptyDBTyped<Infallible>>

Creates a new JournalInit by cloning all internal state data (state, storage, logs, etc) but using an empty database. This allows creating a new journaled state with the same state data but without carrying over the original database.

This is useful when you want to reuse the current state for a new transaction or execution context, but want to start with a fresh database.

§

impl<DB, ENTRY> Journal<DB, ENTRY>
where DB: Database, ENTRY: JournalEntryTr,

pub fn new(spec: SpecId, database: DB) -> Journal<DB, ENTRY>

Creates new JournaledState.

warm_preloaded_addresses is used to determine if address is considered warm loaded. In ordinary case this is precompile or beneficiary.

§Note

This function will journal state after Spurious Dragon fork. And will not take into account if account is not existing or empty.

pub fn state(&mut self) -> &mut HashMap<Address, Account, RandomState>

Return reference to state.

pub fn set_spec_id(&mut self, spec: SpecId)

Sets SpecId.

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

Mark account as touched as only touched accounts will be added to state. This is especially important for state clear where touched empty accounts needs to be removed from state.

pub fn account(&self, address: Address) -> &Account

Returns the loaded Account for the given address.

This assumes that the account has already been loaded.

§Panics

Panics if the account has not been loaded and is missing from the state set.

pub fn set_code_with_hash( &mut self, address: Address, code: Bytecode, hash: FixedBytes<32>, )

Set code and its hash to the account.

Note: Assume account is warm and that hash is calculated from code.

pub fn set_code(&mut self, address: Address, code: Bytecode)

Use it only if you know that acc is warm.

Assume account is warm.

pub fn inc_nonce(&mut self, address: Address) -> Option<u64>

pub fn transfer( &mut self, from: &Address, to: &Address, balance: Uint<256, 4>, ) -> Result<Option<TransferError>, <DB as Database>::Error>

Transfers balance from two accounts. Returns error if sender balance is not enough.

pub fn create_account_checkpoint( &mut self, caller: Address, target_address: Address, balance: Uint<256, 4>, spec_id: SpecId, ) -> Result<JournalCheckpoint, TransferError>

Creates account or returns false if collision is detected.

There are few steps done:

  1. Make created account warm loaded (AccessList) and this should be done before subroutine checkpoint is created.
  2. Check if there is collision of newly created account with existing one.
  3. Mark created account as created.
  4. Add fund to created account
  5. Increment nonce of created account if SpuriousDragon is active
  6. Decrease balance of caller account.
§Panics

Panics if the caller is not loaded inside the EVM state. This should have been done inside create_inner.

pub fn checkpoint(&mut self) -> JournalCheckpoint

Makes a checkpoint that in case of Revert can bring back state to this point.

pub fn checkpoint_commit(&mut self)

Commits the checkpoint.

pub fn checkpoint_revert(&mut self, checkpoint: JournalCheckpoint)

Reverts all changes to state until given checkpoint.

pub fn selfdestruct( &mut self, address: Address, target: Address, ) -> Result<StateLoad<SelfDestructResult>, <DB as Database>::Error>

Performs selfdestruct action. Transfers balance from address to target. Check if target exist/is_cold

Note: Balance will be lost if address and target are the same BUT when current spec enables Cancun, this happens only when the account associated to address is created in the same tx

§References:

pub fn initial_account_load( &mut self, address: Address, storage_keys: impl IntoIterator<Item = Uint<256, 4>>, ) -> Result<&mut Account, <DB as Database>::Error>

Initial load of account. This load will not be tracked inside journal

pub fn load_account( &mut self, address: Address, ) -> Result<StateLoad<&mut Account>, <DB as Database>::Error>

Loads account into memory. return if it is cold or warm accessed

pub fn load_account_delegated( &mut self, address: Address, ) -> Result<StateLoad<AccountLoad>, <DB as Database>::Error>

pub fn load_code( &mut self, address: Address, ) -> Result<StateLoad<&mut Account>, <DB as Database>::Error>

pub fn load_account_optional( &mut self, address: Address, load_code: bool, ) -> Result<StateLoad<&mut Account>, <DB as Database>::Error>

Loads code

pub fn sload( &mut self, address: Address, key: Uint<256, 4>, ) -> Result<StateLoad<Uint<256, 4>>, <DB as Database>::Error>

Loads storage slot.

§Panics

Panics if the account is not present in the state.

pub fn sstore( &mut self, address: Address, key: Uint<256, 4>, new: Uint<256, 4>, ) -> Result<StateLoad<SStoreResult>, <DB as Database>::Error>

Stores storage slot.

And returns (original,present,new) slot value.

Note: Account should already be present in our state.

pub fn tload(&mut self, address: Address, key: Uint<256, 4>) -> Uint<256, 4>

Read transient storage tied to the account.

EIP-1153: Transient storage opcodes

pub fn tstore(&mut self, address: Address, key: Uint<256, 4>, new: Uint<256, 4>)

Store transient storage tied to the account.

If values is different add entry to the journal so that old state can be reverted if that action is needed.

EIP-1153: Transient storage opcodes

pub fn log(&mut self, log: Log)

Pushes log into subroutine.

Trait Implementations

§

impl<DB, ENTRY> Clone for Journal<DB, ENTRY>
where DB: Clone, ENTRY: Clone + JournalEntryTr,

§

fn clone(&self) -> Journal<DB, ENTRY>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<DB, ENTRY> Debug for Journal<DB, ENTRY>
where DB: Debug, ENTRY: Debug + JournalEntryTr,

§

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

Formats the value using the given formatter. Read more
§

impl<'de, DB, ENTRY> Deserialize<'de> for Journal<DB, ENTRY>
where ENTRY: JournalEntryTr + Deserialize<'de>, DB: Deserialize<'de>,

§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Journal<DB, ENTRY>, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl<DB> JournalExt for Journal<DB>
where DB: Database,

§

fn logs(&self) -> &[Log]

§

fn last_journal(&self) -> &[JournalEntry]

§

fn evm_state(&self) -> &HashMap<Address, Account, RandomState>

§

fn evm_state_mut(&mut self) -> &mut HashMap<Address, Account, RandomState>

§

impl<DB, ENTRY> JournalTr for Journal<DB, ENTRY>
where DB: Database, ENTRY: JournalEntryTr,

§

fn depth(&self) -> usize

Returns call depth.

§

type Database = DB

§

type FinalOutput = JournalOutput

§

fn new(database: DB) -> Journal<DB, ENTRY>

Creates new Journaled state. Read more
§

fn db_ref(&self) -> &<Journal<DB, ENTRY> as JournalTr>::Database

Returns the database.
§

fn db(&mut self) -> &mut <Journal<DB, ENTRY> as JournalTr>::Database

Returns the mutable database.
§

fn sload( &mut self, address: Address, key: Uint<256, 4>, ) -> Result<StateLoad<Uint<256, 4>>, <<Journal<DB, ENTRY> as JournalTr>::Database as Database>::Error>

Returns the storage value from Journal state. Read more
§

fn sstore( &mut self, address: Address, key: Uint<256, 4>, value: Uint<256, 4>, ) -> Result<StateLoad<SStoreResult>, <<Journal<DB, ENTRY> as JournalTr>::Database as Database>::Error>

Stores the storage value in Journal state.
§

fn tload(&mut self, address: Address, key: Uint<256, 4>) -> Uint<256, 4>

Loads transient storage value.
§

fn tstore(&mut self, address: Address, key: Uint<256, 4>, value: Uint<256, 4>)

Stores transient storage value.
§

fn log(&mut self, log: Log)

Logs the log in Journal state.
§

fn selfdestruct( &mut self, address: Address, target: Address, ) -> Result<StateLoad<SelfDestructResult>, <DB as Database>::Error>

Marks the account for selfdestruction and transfers all the balance to the target.
§

fn warm_account(&mut self, address: Address)

§

fn warm_precompiles(&mut self, address: HashSet<Address, RandomState>)

§

fn precompile_addresses(&self) -> &HashSet<Address, RandomState>

§

fn warm_account_and_storage( &mut self, address: Address, storage_keys: impl IntoIterator<Item = Uint<256, 4>>, ) -> Result<(), <<Journal<DB, ENTRY> as JournalTr>::Database as Database>::Error>

§

fn set_spec_id(&mut self, spec_id: SpecId)

§

fn transfer( &mut self, from: &Address, to: &Address, balance: Uint<256, 4>, ) -> Result<Option<TransferError>, <DB as Database>::Error>

§

fn touch_account(&mut self, address: Address)

§

fn inc_account_nonce( &mut self, address: Address, ) -> Result<Option<u64>, <DB as Database>::Error>

§

fn load_account( &mut self, address: Address, ) -> Result<StateLoad<&mut Account>, <DB as Database>::Error>

§

fn load_account_code( &mut self, address: Address, ) -> Result<StateLoad<&mut Account>, <DB as Database>::Error>

§

fn load_account_delegated( &mut self, address: Address, ) -> Result<StateLoad<AccountLoad>, <DB as Database>::Error>

§

fn checkpoint(&mut self) -> JournalCheckpoint

§

fn checkpoint_commit(&mut self)

§

fn checkpoint_revert(&mut self, checkpoint: JournalCheckpoint)

§

fn set_code_with_hash( &mut self, address: Address, code: Bytecode, hash: FixedBytes<32>, )

Sets bytecode with hash. Assume that account is warm.
§

fn clear(&mut self)

Called at the end of the transaction to clean all residue data from journal.
§

fn create_account_checkpoint( &mut self, caller: Address, address: Address, balance: Uint<256, 4>, spec_id: SpecId, ) -> Result<JournalCheckpoint, TransferError>

§

fn finalize(&mut self) -> <Journal<DB, ENTRY> as JournalTr>::FinalOutput

Does cleanup and returns modified state. Read more
§

fn set_code(&mut self, address: Address, code: Bytecode)

Sets bytecode and calculates hash. Read more
§

fn code( &mut self, address: Address, ) -> Result<StateLoad<Bytes>, <Self::Database as Database>::Error>

Returns account code bytes and if address is cold loaded. Read more
§

fn code_hash( &mut self, address: Address, ) -> Result<StateLoad<FixedBytes<32>>, <Self::Database as Database>::Error>

Gets code hash of account. Read more
§

impl<DB, ENTRY> PartialEq for Journal<DB, ENTRY>
where DB: PartialEq, ENTRY: PartialEq + JournalEntryTr,

§

fn eq(&self, other: &Journal<DB, ENTRY>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<DB, ENTRY> Serialize for Journal<DB, ENTRY>
where ENTRY: JournalEntryTr + Serialize, DB: Serialize,

§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl<DB, ENTRY> Eq for Journal<DB, ENTRY>
where DB: Eq, ENTRY: Eq + JournalEntryTr,

§

impl<DB, ENTRY> StructuralPartialEq for Journal<DB, ENTRY>
where ENTRY: JournalEntryTr,