Skip to content

Commit

Permalink
Retrieve total execution steps for all transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
obasekiosa committed Jul 31, 2024
1 parent ca76d85 commit 752bf1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vm/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extern "C" {
fn JunoAppendResponse(reader_handle: usize, ptr: *const c_uchar);
fn JunoAppendActualFee(reader_handle: usize, ptr: *const c_uchar);
fn JunoAppendDataGasConsumed(reader_handle: usize, ptr: *const c_uchar);
fn JunoAddExecutionSteps(reader_handle: usize, execSteps: c_longlong);
}

#[repr(C)]
Expand Down Expand Up @@ -348,6 +349,7 @@ pub extern "C" fn cairoVMExecute(

let actual_fee = t.transaction_receipt.fee.0.into();
let data_gas_consumed = t.transaction_receipt.da_gas.l1_data_gas.into();
let execution_steps = t.n_steps; // todo: n_steps may not be in this object check later

let trace =
jsonrpc::new_transaction_trace(&txn_and_query_bit.txn, t, &mut txn_state);
Expand All @@ -370,6 +372,7 @@ pub extern "C" fn cairoVMExecute(
reader_handle,
felt_to_byte_array(&data_gas_consumed).as_ptr(),
);
JunoAddExecutionSteps(reader_handle, execution_steps)
}
append_trace(reader_handle, trace.as_ref().unwrap(), &mut trace_buffer);
}
Expand Down
7 changes: 7 additions & 0 deletions vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type callContext struct {
actualFees []*felt.Felt
traces []json.RawMessage
dataGasConsumed []*felt.Felt
executionSteps uint64
}

func unwrapContext(readerHandle C.uintptr_t) *callContext {
Expand Down Expand Up @@ -138,6 +139,12 @@ func JunoAppendDataGasConsumed(readerHandle C.uintptr_t, ptr unsafe.Pointer) {
context.dataGasConsumed = append(context.dataGasConsumed, makeFeltFromPtr(ptr))
}

//export JunoAddExecutionSteps
func JunoAddExecutionSteps(readerHandle C.uintptr_t, execSteps C.long) {
context := unwrapContext(readerHandle)
context.executionSteps += uint64(execSteps) // todo: assumes initial default value is zero even in ffi
}

func makeFeltFromPtr(ptr unsafe.Pointer) *felt.Felt {
return new(felt.Felt).SetBytes(C.GoBytes(ptr, felt.Bytes))
}
Expand Down

0 comments on commit 752bf1e

Please sign in to comment.