Skip to content

Use EventName for TransactionEvent #2043

@PhilippGackstatter

Description

@PhilippGackstatter

After the VM upgrade to 0.19 (#2042), we can provide EventNames for TransactionEvents. Currently we have:

pub enum TransactionEvent {
    AccountBeforeForeignLoad = ACCOUNT_BEFORE_FOREIGN_LOAD,
}

where ACCOUNT_BEFORE_FOREIGN_LOAD is a u64, essentially an EventId, generated in build.rs.

With VM 0.19 we still need a way to map an EventId to a TransactionEvent so we can implement TransactionEvent::try_from(event_id). But, additionally, we can implement TransactionEvent::event_name, e.g.:

// Generated by build.rs next to ACCOUNT_BEFORE_FOREIGN_LOAD.
pub const ACCOUNT_BEFORE_FOREIGN_LOAD_EVENT_NAME: EventName =
    EventName::new("miden::account::before_foreign_load");

impl TransactionEvent {
    pub fn event_name(&self) -> &EventName {
        match self {
            TransactionEvent::AccountBeforeForeignLoad => &ACCOUNT_BEFORE_FOREIGN_LOAD_EVENT_NAME,
            // ...
        }
    }
}

The main benefit is that we can then implement BaseHost::resolve_event for TransactionExecutorHost roughly like this:

fn resolve_event(&self, event_id: EventId) -> Option<&EventName> {
    let event_name = self.base_host.stdlib_handlers().resolve_event(event_id);
    if event_name.is_some() {
        return event_name;
    }

    TransactionEvent::try_from(event_id).map(|event| event.event_name()).ok()
}

As part of this, we can check if having the EVENT_NAME_LUT still makes sense. At first glance, it looks like its functionality is covered by BaseHost::resolve_event and if so, we can probably remove it.

Metadata

Metadata

Labels

rustIssues that affect or pull requests that update Rust code

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions