VmContext

Struct VmContext 

Source
pub struct VmContext {
    pub instructions_executed: u64,
    pub cache_hits: u64,
    pub pda_cache_hits: u64,
    pub pda_cache_misses: u64,
    pub pending_queue_size: u64,
    /* private fields */
}

Fields§

§instructions_executed: u64§cache_hits: u64§pda_cache_hits: u64§pda_cache_misses: u64§pending_queue_size: u64

Implementations§

Source§

impl VmContext

Source

pub fn new() -> Self

Source

pub fn new_with_config(state_config: StateTableConfig) -> Self

Source

pub fn get_state_table_mut(&mut self, state_id: u32) -> Option<&mut StateTable>

Get a mutable reference to a state table by ID Returns None if the state ID doesn’t exist

Source

pub fn registers_mut(&mut self) -> &mut Vec<RegisterValue>

Get public access to registers (for metrics context)

Source

pub fn path_cache(&self) -> &HashMap<String, CompiledPath>

Get public access to path cache (for metrics context)

Source

pub fn current_context(&self) -> Option<&UpdateContext>

Get the current update context

Source

pub fn update_state_from_register( &mut self, state_id: u32, key: Value, register: Register, ) -> Result<()>

Source

pub fn extract_partial_state( &self, state_reg: Register, dirty_fields: &HashSet<String>, ) -> Result<Value>

Extract only the dirty fields from state (public for use by instruction hooks)

Source

pub fn process_event_with_context( &mut self, bytecode: &MultiEntityBytecode, event_value: Value, event_type: &str, context: Option<&UpdateContext>, ) -> Result<Vec<Mutation>>

Process an event with optional context metadata

Source

pub fn process_event( &mut self, bytecode: &MultiEntityBytecode, event_value: Value, event_type: &str, ) -> Result<Vec<Mutation>>

Process an event without context (backward compatibility)

Source

pub fn process_any( &mut self, bytecode: &MultiEntityBytecode, any: Any, ) -> Result<Vec<Mutation>>

Source

pub fn update_pda_reverse_lookup( &mut self, state_id: u32, lookup_name: &str, pda_address: String, seed_value: String, ) -> Result<Vec<PendingAccountUpdate>>

Update a PDA reverse lookup and return pending updates for reprocessing

After registering the PDA reverse lookup, this returns any pending account updates that were queued for this PDA. The caller should reprocess these through the VM by calling process_event() for each update.

§Example
let pending = vm.update_pda_reverse_lookup(state_id, lookup_name, pda_addr, seed)?;
for update in pending {
    vm.process_event(&bytecode, update.account_data, &update.account_type)?;
}
Source

pub fn cleanup_expired_pending_updates(&mut self, state_id: u32) -> usize

Clean up expired pending updates that are older than the TTL

Returns the number of updates that were removed. This should be called periodically to prevent memory leaks from orphaned updates.

Source

pub fn queue_account_update( &mut self, state_id: u32, update: QueuedAccountUpdate, ) -> Result<()>

Queue an account update for later processing when PDA reverse lookup is not yet available

§Workflow

This implements a deferred processing pattern for account updates when the PDA reverse lookup needed to resolve the primary key is not yet available:

  1. Initial Account Update: When an account update arrives but the PDA reverse lookup is not available, call queue_account_update() to queue it for later.

  2. Register PDA Mapping: When the instruction that establishes the PDA mapping is processed, call update_pda_reverse_lookup() which returns pending updates.

  3. Reprocess Pending Updates: Process the returned pending updates through the VM:

    let pending = vm.update_pda_reverse_lookup(state_id, lookup_name, pda_addr, seed)?;
    for update in pending {
        let mutations = vm.process_event(
            &bytecode,
            update.account_data,
            &update.account_type
        )?;
        // Handle mutations...
    }
§Arguments
  • state_id - The state table ID
  • pda_address - The PDA address that needs reverse lookup
  • account_type - The event type name for reprocessing
  • account_data - The account data (event value) for reprocessing
  • slot - The slot number when this update occurred
  • signature - The transaction signature
Source

pub fn get_pending_queue_stats( &self, state_id: u32, ) -> Option<PendingQueueStats>

Get statistics about the pending queue for monitoring

Source

pub fn get_memory_stats(&self, state_id: u32) -> VmMemoryStats

Source

pub fn cleanup_all_expired(&mut self, state_id: u32) -> CleanupResult

Source

pub fn check_state_table_capacity( &self, state_id: u32, ) -> Option<CapacityWarning>

Source

pub fn try_pda_reverse_lookup( &mut self, state_id: u32, lookup_name: &str, pda_address: &str, ) -> Option<String>

Try to resolve a primary key via PDA reverse lookup

Source

pub fn evaluate_computed_expr( &self, expr: &ComputedExpr, state: &Value, ) -> Result<Value>

Evaluate a computed expression AST against the current state This is the core runtime evaluator for computed fields from the AST

Source

pub fn evaluate_computed_fields_from_ast( &self, state: &mut Value, computed_field_specs: &[ComputedFieldSpec], ) -> Result<Vec<String>>

Evaluate all computed fields for an entity and update the state This takes a list of ComputedFieldSpec from the AST and applies them

Source

pub fn create_evaluator_from_specs( specs: Vec<ComputedFieldSpec>, ) -> impl Fn(&mut Value) -> Result<()> + Send + Sync + 'static

Create a computed fields evaluator closure from AST specs This returns a function that can be passed to the bytecode builder

Trait Implementations§

Source§

impl Default for VmContext

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl ReverseLookupUpdater for VmContext

Source§

fn update( &mut self, pda_address: String, seed_value: String, ) -> Vec<PendingAccountUpdate>

Source§

fn flush_pending(&mut self, pda_address: &str) -> Vec<PendingAccountUpdate>

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> 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> 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> Same for T

Source§

type Output = T

Should always be Self
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<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