Skip to main content

GeneralizedDatabase

Struct GeneralizedDatabase 

Source
pub struct GeneralizedDatabase {
    pub store: Arc<dyn Database>,
    pub current_accounts_state: CacheDB,
    pub initial_accounts_state: CacheDB,
    pub shared_base: Option<Arc<CacheDB>>,
    pub codes: FxHashMap<H256, Code>,
    pub code_metadata: FxHashMap<H256, CodeMetadata>,
    pub tx_backup: Option<CallFrameBackup>,
    pub bal_recorder: Option<BlockAccessListRecorder>,
    pub accessed_accounts: Option<FxHashSet<Address>>,
    pub lazy_bal: Option<LazyBalCursor>,
    /* private fields */
}

Fields§

§store: Arc<dyn Database>§current_accounts_state: CacheDB§initial_accounts_state: CacheDB§shared_base: Option<Arc<CacheDB>>

Shared read-only base state (pre-block snapshot of system-touched addresses for parallel groups, captured from initial_accounts_state after prepare_block). Checked on load_account AFTER the lazy_bal hook so the BAL overlay (which includes system-call effects at idx 0) takes precedence for any address the BAL covers. Accounts are cloned into initial_accounts_state on first access.

§codes: FxHashMap<H256, Code>§code_metadata: FxHashMap<H256, CodeMetadata>§tx_backup: Option<CallFrameBackup>§bal_recorder: Option<BlockAccessListRecorder>

Optional BAL recorder for EIP-7928 Block Access List recording.

§accessed_accounts: Option<FxHashSet<Address>>

Optional tracker for BAL validation: records addresses accessed via load_account. Enabled only during parallel execution to detect extraneous BAL pure-access entries.

§lazy_bal: Option<LazyBalCursor>

Optional BAL cursor for lazy per-read prefix materialization. When set, account loads and storage reads consult the BAL before hitting the store.

Implementations§

Source§

impl GeneralizedDatabase

Source

pub fn new(store: Arc<dyn Database>) -> Self

Source

pub fn new_with_shared_base( store: Arc<dyn Database>, shared_base: Arc<CacheDB>, ) -> Self

Creates a new GeneralizedDatabase with a shared read-only base state. Used for parallel execution groups that share post-system-call state. Skips initial_accounts_state tracking since parallel per-tx DBs never call get_state_transitions_tx (state comes from BAL instead).

Source

pub fn new_with_shared_base_and_capacity( store: Arc<dyn Database>, shared_base: Arc<CacheDB>, capacity: usize, ) -> Self

Like new_with_shared_base but pre-allocates account/code maps to capacity entries, avoiding rehashing during BAL seeding.

Source

pub fn enable_bal_recording(&mut self)

Enables BAL recording for EIP-7928. After enabling, state changes will be recorded during execution.

Source

pub fn disable_bal_recording(&mut self)

Disables BAL recording.

Source

pub fn set_bal_index(&mut self, index: u32)

Sets the current block access index for BAL recording per EIP-7928 spec (uint32). Call this before each transaction or phase.

Source

pub fn take_bal(&mut self) -> Option<BlockAccessList>

Takes the BAL recorder and builds the final BlockAccessList. Returns None if recording was not enabled.

Source

pub fn bal_recorder_mut(&mut self) -> Option<&mut BlockAccessListRecorder>

Returns a mutable reference to the BAL recorder if enabled.

Source

pub fn new_with_account_state( store: Arc<dyn Database>, current_accounts_state: FxHashMap<Address, Account>, ) -> Self

Only used within Levm Runner, where the accounts already have all the storage pre-loaded, not used in real case scenarios.

Source

pub fn get_account( &mut self, address: Address, ) -> Result<&LevmAccount, InternalError>

Gets reference of an account

Source

pub fn get_account_mut( &mut self, address: Address, ) -> Result<&mut LevmAccount, InternalError>

Gets mutable reference of an account Warning: Use directly only if outside of the EVM, otherwise use vm.get_account_mut because it contemplates call frame backups.

Source

pub fn get_code(&mut self, code_hash: H256) -> Result<&Code, InternalError>

Gets code immutably given the code hash. Use this only inside of the VM, when we don’t surely know if the code is in the cache or not But e.g. in get_state_transitions just do db.codes.get(code_hash) because we know for sure code is there.

Source

pub fn get_account_code( &mut self, address: Address, ) -> Result<&Code, InternalError>

Shortcut for getting the code when we only have the address of an account and we don’t need anything else.

Source

pub fn get_code_metadata( &mut self, code_hash: H256, ) -> Result<&CodeMetadata, InternalError>

Gets code metadata immutably given the code hash.

Source

pub fn get_code_length( &mut self, address: Address, ) -> Result<usize, InternalError>

Convenience method to get code length by address (optimized for EXTCODESIZE).

Source

pub fn get_tx_backup(&self) -> Result<CallFrameBackup, InternalError>

Gets the transaction backup, if it exists. It only works if the BackupHook was enabled during the transaction execution.

Source

pub fn undo_last_transaction(&mut self) -> Result<(), VMError>

Undoes the last transaction by restoring the cache state to the state before the transaction.

Source

pub fn get_state_transitions(&mut self) -> Result<Vec<AccountUpdate>, VMError>

Source

pub fn get_state_transitions_tx( &mut self, ) -> Result<Vec<AccountUpdate>, VMError>

Trait Implementations§

Source§

impl Clone for GeneralizedDatabase

Source§

fn clone(&self) -> GeneralizedDatabase

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T, U> ExactFrom<T> for U
where U: TryFrom<T>,

Source§

fn exact_from(value: T) -> U

Source§

impl<T, U> ExactInto<U> for T
where U: ExactFrom<T>,

Source§

fn exact_into(self) -> U

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T, U> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T, U> RoundingInto<U> for T
where U: RoundingFrom<T>,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> SaturatingInto<U> for T
where U: SaturatingFrom<T>,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T, U> WrappingInto<U> for T
where U: WrappingFrom<T>,

Source§

fn wrapping_into(self) -> U