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:
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>
impl<DB> Journal<DB>
pub fn from_init(
init: &Journal<EmptyDBTyped<Infallible>>,
database: 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>
impl<DB> Journal<DB>
pub fn into_init(self) -> Journal<EmptyDBTyped<Infallible>>
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>>
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,
impl<DB, ENTRY> Journal<DB, ENTRY>where
DB: Database,
ENTRY: JournalEntryTr,
pub fn new(spec: SpecId, database: DB) -> Journal<DB, ENTRY>
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>
pub fn state(&mut self) -> &mut HashMap<Address, Account, RandomState>
Return reference to state.
pub fn set_spec_id(&mut self, spec: SpecId)
pub fn set_spec_id(&mut self, spec: SpecId)
Sets SpecId.
pub fn touch(&mut self, address: &Address)
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 set_code_with_hash(
&mut self,
address: Address,
code: Bytecode,
hash: FixedBytes<32>,
)
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)
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>
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>
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:
- Make created account warm loaded (AccessList) and this should be done before subroutine checkpoint is created.
- Check if there is collision of newly created account with existing one.
- Mark created account as created.
- Add fund to created account
- Increment nonce of created account if SpuriousDragon is active
- 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
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)
pub fn checkpoint_commit(&mut self)
Commits the checkpoint.
pub fn checkpoint_revert(&mut self, checkpoint: JournalCheckpoint)
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>
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>
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>
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>
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>
pub fn sload( &mut self, address: Address, key: Uint<256, 4>, ) -> Result<StateLoad<Uint<256, 4>>, <DB as Database>::Error>
pub fn sstore(
&mut self,
address: Address,
key: Uint<256, 4>,
new: Uint<256, 4>,
) -> Result<StateLoad<SStoreResult>, <DB as Database>::Error>
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>
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