Overview
Theemit_event syscall records an event in the transaction’s event log. Events are stored in anonymous memory and become part of the transaction’s output for external consumption.
Syscall Code
Code:0x0D (TN_SYSCALL_CODE_EMIT_EVENT)
C SDK Function
Arguments
Pointer to the event data to be recorded.
Size of the event data in bytes. Must not exceed the maximum event size.
Return Value
Returns a syscall result code:TN_VM_SYSCALL_SUCCESS(0) - Event recorded successfully
TN_VM_ERR_SYSCALL_EVENT_TOO_LARGE(-30) - Event size exceeds maximum allowedTN_VM_ERR_SYSCALL_INVALID_ADDRESS(-21) - Invalid virtual address for event dataTN_VM_ERR_SYSCALL_INSUFFICIENT_PAGES(-25) - Not enough pages to expand event storage
Resource Consumption
Compute Units
- Base cost:
TN_VM_SYSCALL_BASE_COST(512 units) - Event cost: Additional units equal to event data size in bytes
- Total formula:
base_cost + data_sz
Memory Pages
- Event storage: Pages allocated for event storage in anonymous memory segment
- Automatic expansion: Event storage segment grows as needed (page-aligned)
- Metadata overhead: Additional space for event metadata per event
Side Effects
- Event storage: Copies event data to transaction’s event log
- Memory allocation: May expand event storage segment if needed
- Event counter: Increments the transaction’s event count
Event Structure
Each event is stored with metadata:Event Metadata
The system automatically adds metadata to each event:- Event size: Size of the event data
- Call index: Unique identifier for the program invocation
- Program account index: Index of the program that emitted the event
Storage Management
- Events are stored in a grow-up anonymous memory segment
- Storage automatically expands as needed (page-aligned)
- Events are stored sequentially in the order emitted
- Multiple events can be emitted by the same program
Size Limitations
- Maximum event size:
UINT_MAXbytes (4GB) - Practical limits imposed by available memory pages
- Event storage competes with other memory allocations
Usage Notes
- Events are included in transaction output for external consumption
- Event order is preserved within the transaction
- Events from different programs are distinguished by metadata
- Event data format is application-defined