Skip to content

Commit

Permalink
Update vm execute interface to allow return of execution steps
Browse files Browse the repository at this point in the history
  • Loading branch information
obasekiosa committed Jul 31, 2024
1 parent 752bf1e commit ebf301a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
7 changes: 4 additions & 3 deletions node/throttled_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ func (tvm *ThrottledVM) Call(callInfo *vm.CallInfo, blockInfo *vm.BlockInfo, sta
func (tvm *ThrottledVM) Execute(txns []core.Transaction, declaredClasses []core.Class, paidFeesOnL1 []*felt.Felt,
blockInfo *vm.BlockInfo, state core.StateReader, network *utils.Network, skipChargeFee, skipValidate, errOnRevert,
useBlobData bool,
) ([]*felt.Felt, []*felt.Felt, []vm.TransactionTrace, error) {
) ([]*felt.Felt, []*felt.Felt, []vm.TransactionTrace, uint64, error) {
var ret []*felt.Felt
var traces []vm.TransactionTrace
var dataGasConsumed []*felt.Felt
return ret, dataGasConsumed, traces, tvm.Do(func(vm *vm.VM) error {
var numSteps uint64
return ret, dataGasConsumed, traces, numSteps, tvm.Do(func(vm *vm.VM) error {
var err error
ret, dataGasConsumed, traces, err = (*vm).Execute(txns, declaredClasses, paidFeesOnL1, blockInfo, state, network,
ret, dataGasConsumed, traces, numSteps, err = (*vm).Execute(txns, declaredClasses, paidFeesOnL1, blockInfo, state, network,
skipChargeFee, skipValidate, errOnRevert, useBlobData)
return err
})
Expand Down
2 changes: 1 addition & 1 deletion rpc/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (h *Handler) simulateTransactions(id BlockID, transactions []BroadcastedTra
BlockHashToBeRevealed: blockHashToBeRevealed,
}
useBlobData := !v0_6Response
overallFees, dataGasConsumed, traces, err := h.vm.Execute(txns, classes, paidFeesOnL1, &blockInfo,
overallFees, dataGasConsumed, traces, numSteps, err := h.vm.Execute(txns, classes, paidFeesOnL1, &blockInfo,

Check failure on line 109 in rpc/simulation.go

View workflow job for this annotation

GitHub Actions / lint

numSteps declared and not used

Check failure on line 109 in rpc/simulation.go

View workflow job for this annotation

GitHub Actions / lint

numSteps declared and not used

Check failure on line 109 in rpc/simulation.go

View workflow job for this annotation

GitHub Actions / lint

numSteps declared and not used
state, h.bcReader.Network(), skipFeeCharge, skipValidate, errOnRevert, useBlobData)
if err != nil {
if errors.Is(err, utils.ErrResourceBusy) {
Expand Down
2 changes: 1 addition & 1 deletion rpc/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (h *Handler) traceBlockTransactions(ctx context.Context, block *core.Block,
}

useBlobData := !v0_6Response
overallFees, dataGasConsumed, traces, err := h.vm.Execute(block.Transactions, classes, paidFeesOnL1, &blockInfo, state, network, false,
overallFees, dataGasConsumed, traces, numSteps, err := h.vm.Execute(block.Transactions, classes, paidFeesOnL1, &blockInfo, state, network, false,

Check failure on line 265 in rpc/trace.go

View workflow job for this annotation

GitHub Actions / lint

numSteps declared and not used (typecheck)

Check failure on line 265 in rpc/trace.go

View workflow job for this annotation

GitHub Actions / lint

numSteps declared and not used) (typecheck)

Check failure on line 265 in rpc/trace.go

View workflow job for this annotation

GitHub Actions / lint

numSteps declared and not used) (typecheck)
false, false, useBlobData)
if err != nil {
if errors.Is(err, utils.ErrResourceBusy) {
Expand Down
16 changes: 8 additions & 8 deletions vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type VM interface {
maxSteps uint64, useBlobData bool) ([]*felt.Felt, error)
Execute(txns []core.Transaction, declaredClasses []core.Class, paidFeesOnL1 []*felt.Felt, blockInfo *BlockInfo,
state core.StateReader, network *utils.Network, skipChargeFee, skipValidate, errOnRevert, useBlobData bool,
) ([]*felt.Felt, []*felt.Felt, []TransactionTrace, error)
) ([]*felt.Felt, []*felt.Felt, []TransactionTrace, uint64, error)
}

type vm struct {
Expand Down Expand Up @@ -267,7 +267,7 @@ func (v *vm) Call(callInfo *CallInfo, blockInfo *BlockInfo, state core.StateRead
func (v *vm) Execute(txns []core.Transaction, declaredClasses []core.Class, paidFeesOnL1 []*felt.Felt,
blockInfo *BlockInfo, state core.StateReader, network *utils.Network,
skipChargeFee, skipValidate, errOnRevert, useBlobData bool,
) ([]*felt.Felt, []*felt.Felt, []TransactionTrace, error) {
) ([]*felt.Felt, []*felt.Felt, []TransactionTrace, uint64, error) {
context := &callContext{
state: state,
log: v.log,
Expand All @@ -277,12 +277,12 @@ func (v *vm) Execute(txns []core.Transaction, declaredClasses []core.Class, paid

txnsJSON, classesJSON, err := marshalTxnsAndDeclaredClasses(txns, declaredClasses)
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, 0, err
}

paidFeesOnL1Bytes, err := json.Marshal(paidFeesOnL1)
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, 0, err
}

paidFeesOnL1CStr := cstring(paidFeesOnL1Bytes)
Expand Down Expand Up @@ -331,23 +331,23 @@ func (v *vm) Execute(txns []core.Transaction, declaredClasses []core.Class, paid

if context.err != "" {
if context.errTxnIndex >= 0 {
return nil, nil, nil, TransactionExecutionError{
return nil, nil, nil, context.executionSteps, TransactionExecutionError{
Index: uint64(context.errTxnIndex),
Cause: errors.New(context.err),
}
}
return nil, nil, nil, errors.New(context.err)
return nil, nil, nil, context.executionSteps, errors.New(context.err)
}

traces := make([]TransactionTrace, len(context.traces))
for index, traceJSON := range context.traces {
if err := json.Unmarshal(traceJSON, &traces[index]); err != nil {
return nil, nil, nil, fmt.Errorf("unmarshal trace: %v", err)
return nil, nil, nil, context.executionSteps, fmt.Errorf("unmarshal trace: %v", err)
}
//
}

return context.actualFees, context.dataGasConsumed, traces, nil
return context.actualFees, context.dataGasConsumed, traces, context.executionSteps, nil
}

func marshalTxnsAndDeclaredClasses(txns []core.Transaction, declaredClasses []core.Class) (json.RawMessage, json.RawMessage, error) { //nolint:lll
Expand Down
4 changes: 2 additions & 2 deletions vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func TestExecute(t *testing.T) {
state := core.NewState(txn)

t.Run("empty transaction list", func(t *testing.T) {
_, _, _, err := New(false, nil).Execute([]core.Transaction{}, []core.Class{}, []*felt.Felt{}, &BlockInfo{
_, _, _, _, err := New(false, nil).Execute([]core.Transaction{}, []core.Class{}, []*felt.Felt{}, &BlockInfo{
Header: &core.Header{
Timestamp: 1666877926,
SequencerAddress: utils.HexToFelt(t, "0x46a89ae102987331d369645031b49c27738ed096f2789c24449966da4c6de6b"),
Expand All @@ -215,7 +215,7 @@ func TestExecute(t *testing.T) {
require.NoError(t, err)
})
t.Run("zero data", func(t *testing.T) {
_, _, _, err := New(false, nil).Execute(nil, nil, []*felt.Felt{}, &BlockInfo{
_, _, _, _, err := New(false, nil).Execute(nil, nil, []*felt.Felt{}, &BlockInfo{
Header: &core.Header{
SequencerAddress: &felt.Zero,
GasPrice: &felt.Zero,
Expand Down

0 comments on commit ebf301a

Please sign in to comment.