Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions builder/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (e *executor) RunTxns(state *BuildState, txns []mempool.BroadcastedTransact
}

// Execute the transaction
vmResults, err := e.vm.Execute(
vmResults, err := e.vm.BuildBlock(
coreTxns,
declaredClasses,
paidFeesOnL1,
Expand All @@ -89,13 +89,10 @@ func (e *executor) RunTxns(state *BuildState, txns []mempool.BroadcastedTransact
BlockHashToBeRevealed: state.RevealedBlockHash,
},
stateWriter,
e.disableFees,
e.skipValidate,
false,
true,
false,
false,
false,
vm.BuildBlockOptions{
SkipChargeFee: e.disableFees,
SkipValidate: e.skipValidate,
},
)
if err != nil {
return err
Expand Down
8 changes: 6 additions & 2 deletions genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,12 @@ func executeTransactions(
}

blockInfo := vm.BlockInfo{Header: &genesisHeader}
executionResults, err := v.Execute(coreTxns, nil, []*felt.Felt{new(felt.Felt).SetUint64(1)},
&blockInfo, genesisState, true, true, true, true, false, false, false)
executionResults, err := v.BuildBlock(coreTxns, nil, []*felt.Felt{new(felt.Felt).SetUint64(1)},
Comment thread
rodrodros marked this conversation as resolved.
Outdated
Comment thread
rodrodros marked this conversation as resolved.
Outdated
&blockInfo, genesisState, vm.BuildBlockOptions{
SkipChargeFee: true,
SkipValidate: true,
ErrOnRevert: true,
})
if err != nil {
return fmt.Errorf("execute transactions: %v", err)
}
Expand Down
53 changes: 49 additions & 4 deletions mocks/mock_vm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 54 additions & 21 deletions node/throttled_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,64 @@ func (tvm *ThrottledVM) Execute(
paidFeesOnL1 []*felt.Felt,
blockInfo *vm.BlockInfo,
state core.StateReader,
skipChargeFee,
skipValidate,
errOnRevert,
errStack,
allowBinarySearch bool,
isEstimateFee bool,
returnInitialReads bool,
opts vm.ExecutionOptions,
) (vm.ExecutionResults, error) {
var executionResult vm.ExecutionResults
return executionResult, tvm.Do(func(vm *vm.VM) error {
return executionResult, tvm.Do(func(inner *vm.VM) error {
var err error
executionResult, err = (*vm).Execute(
txns,
declaredClasses,
paidFeesOnL1,
blockInfo,
state,
skipChargeFee,
skipValidate,
errOnRevert,
errStack,
allowBinarySearch,
isEstimateFee,
returnInitialReads,
executionResult, err = (*inner).Execute(
txns, declaredClasses, paidFeesOnL1, blockInfo, state, opts,
)
return err
})
}

func (tvm *ThrottledVM) runExec(
fn func(inner vm.VM) (vm.ExecutionResults, error),
) (vm.ExecutionResults, error) {
var result vm.ExecutionResults
return result, tvm.Do(func(inner *vm.VM) error {
var err error
result, err = fn(*inner)
return err
})
}

func (tvm *ThrottledVM) Simulate(
txns []core.Transaction,
declaredClasses []core.ClassDefinition,
paidFeesOnL1 []*felt.Felt,
blockInfo *vm.BlockInfo,
state core.StateReader,
opts vm.SimulateOptions,
) (vm.ExecutionResults, error) {
return tvm.runExec(func(inner vm.VM) (vm.ExecutionResults, error) {
return inner.Simulate(txns, declaredClasses, paidFeesOnL1, blockInfo, state, opts)
})
}

func (tvm *ThrottledVM) Trace(
txns []core.Transaction,
declaredClasses []core.ClassDefinition,
paidFeesOnL1 []*felt.Felt,
blockInfo *vm.BlockInfo,
state core.StateReader,
opts vm.TraceOptions,
) (vm.ExecutionResults, error) {
return tvm.runExec(func(inner vm.VM) (vm.ExecutionResults, error) {
return inner.Trace(txns, declaredClasses, paidFeesOnL1, blockInfo, state, opts)
})
}

func (tvm *ThrottledVM) BuildBlock(
txns []core.Transaction,
declaredClasses []core.ClassDefinition,
paidFeesOnL1 []*felt.Felt,
blockInfo *vm.BlockInfo,
state core.StateReader,
opts vm.BuildBlockOptions,
) (vm.ExecutionResults, error) {
return tvm.runExec(func(inner vm.VM) (vm.ExecutionResults, error) {
return inner.BuildBlock(txns, declaredClasses, paidFeesOnL1, blockInfo, state, opts)
})
}
28 changes: 16 additions & 12 deletions rpc/v10/estimate_fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ func TestEstimateFee(t *testing.T) {

blockInfo := vm.BlockInfo{Header: &core.Header{}}
t.Run("ok with zero values", func(t *testing.T) {
mockVM.EXPECT().Execute(
mockVM.EXPECT().Simulate(
[]core.Transaction{},
nil,
[]*felt.Felt{},
&blockInfo,
mockState,
true,
false,
true, true, true, true, false).
vm.SimulateOptions{SkipChargeFee: true, ErrOnRevert: true, IsEstimateFee: true}).
Return(vm.ExecutionResults{
OverallFees: []*felt.Felt{},
DataAvailability: []core.DataAvailability{},
Expand All @@ -66,15 +64,18 @@ func TestEstimateFee(t *testing.T) {
})

t.Run("ok with zero values, skip validate", func(t *testing.T) {
mockVM.EXPECT().Execute(
mockVM.EXPECT().Simulate(
[]core.Transaction{},
nil,
[]*felt.Felt{},
&blockInfo,
mockState,
true,
true,
true, true, true, true, false).
vm.SimulateOptions{
SkipChargeFee: true,
SkipValidate: true,
ErrOnRevert: true,
IsEstimateFee: true,
}).
Return(
vm.ExecutionResults{
OverallFees: []*felt.Felt{},
Expand All @@ -99,15 +100,18 @@ func TestEstimateFee(t *testing.T) {
})

t.Run("transaction execution error", func(t *testing.T) {
mockVM.EXPECT().Execute(
mockVM.EXPECT().Simulate(
[]core.Transaction{},
nil,
[]*felt.Felt{},
&blockInfo,
mockState,
true,
true,
true, true, true, true, false).
vm.SimulateOptions{
SkipChargeFee: true,
SkipValidate: true,
ErrOnRevert: true,
IsEstimateFee: true,
}).
Return(vm.ExecutionResults{}, vm.TransactionExecutionError{
Index: 44,
Cause: json.RawMessage("oops"),
Expand Down
16 changes: 8 additions & 8 deletions rpc/v10/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,19 @@ func (h *Handler) simulateTransactions(
BlockHashToBeRevealed: blockHashToBeRevealed,
}

executionResults, err := h.vm.Execute(
executionResults, err := h.vm.Simulate(
txns,
classes,
paidFeesOnL1,
&blockInfo,
state,
skipFeeCharge,
skipValidate,
errOnRevert,
true,
true,
isEstimateFee,
returnInitialReads,
vm.SimulateOptions{
SkipChargeFee: skipFeeCharge,
SkipValidate: skipValidate,
ErrOnRevert: errOnRevert,
IsEstimateFee: isEstimateFee,
ReturnInitialReads: returnInitialReads,
},
)
if err != nil {
return SimulateTransactionsResponse{}, httpHeader, handleExecutionError(err)
Expand Down
20 changes: 10 additions & 10 deletions rpc/v10/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func TestSimulateTransactions(t *testing.T) {
mockState *mocks.MockStateReader,
) {
defaultMockBehavior(mockReader, mockVM, mockState)
mockVM.EXPECT().Execute([]core.Transaction{}, nil, []*felt.Felt{}, &vm.BlockInfo{
mockVM.EXPECT().Simulate([]core.Transaction{}, nil, []*felt.Felt{}, &vm.BlockInfo{
Header: headsHeader,
}, mockState, true, false, false, true, true, false, false).
}, mockState, vm.SimulateOptions{SkipChargeFee: true}).
Return(vm.ExecutionResults{
OverallFees: []*felt.Felt{},
DataAvailability: []core.DataAvailability{},
Expand All @@ -86,9 +86,9 @@ func TestSimulateTransactions(t *testing.T) {
mockState *mocks.MockStateReader,
) {
defaultMockBehavior(mockReader, mockVM, mockState)
mockVM.EXPECT().Execute([]core.Transaction{}, nil, []*felt.Felt{}, &vm.BlockInfo{
mockVM.EXPECT().Simulate([]core.Transaction{}, nil, []*felt.Felt{}, &vm.BlockInfo{
Header: headsHeader,
}, mockState, false, true, false, true, true, false, false).
}, mockState, vm.SimulateOptions{SkipValidate: true}).
Return(vm.ExecutionResults{
OverallFees: []*felt.Felt{},
DataAvailability: []core.DataAvailability{},
Expand All @@ -108,9 +108,9 @@ func TestSimulateTransactions(t *testing.T) {
mockState *mocks.MockStateReader,
) {
defaultMockBehavior(mockReader, mockVM, mockState)
mockVM.EXPECT().Execute([]core.Transaction{}, nil, []*felt.Felt{}, &vm.BlockInfo{
mockVM.EXPECT().Simulate([]core.Transaction{}, nil, []*felt.Felt{}, &vm.BlockInfo{
Header: headsHeader,
}, mockState, false, true, false, true, true, false, false).
}, mockState, vm.SimulateOptions{SkipValidate: true}).
Return(vm.ExecutionResults{}, vm.TransactionExecutionError{
Index: 44,
Cause: json.RawMessage("oops"),
Expand All @@ -130,9 +130,9 @@ func TestSimulateTransactions(t *testing.T) {
mockState *mocks.MockStateReader,
) {
defaultMockBehavior(mockReader, mockVM, mockState)
mockVM.EXPECT().Execute([]core.Transaction{}, nil, []*felt.Felt{}, &vm.BlockInfo{
mockVM.EXPECT().Simulate([]core.Transaction{}, nil, []*felt.Felt{}, &vm.BlockInfo{
Header: headsHeader,
}, mockState, false, true, false, true, true, false, false).
}, mockState, vm.SimulateOptions{SkipValidate: true}).
Return(vm.ExecutionResults{
OverallFees: []*felt.Felt{&felt.Zero},
DataAvailability: []core.DataAvailability{{L1Gas: 0}, {L1Gas: 0}},
Expand Down Expand Up @@ -454,8 +454,8 @@ func TestSimulateTransactionsWithReturnInitialReads(t *testing.T) {
},
}}

mockVM.EXPECT().Execute(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), mockState,
false, false, false, true, true, false, returnInitialReads,
mockVM.EXPECT().Simulate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), mockState,
vm.SimulateOptions{ReturnInitialReads: returnInitialReads},
).Return(vm.ExecutionResults{
OverallFees: []*felt.Felt{&felt.Zero},
DataAvailability: []core.DataAvailability{{L1Gas: 0}},
Expand Down
12 changes: 3 additions & 9 deletions rpc/v10/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (h *Handler) TraceBlockTransactions(
//
// - returnInitialReads: Whether to return initial reads in the response
func traceTransactionsWithState(
vm vm.VM,
runner vm.VM,
transactions []core.Transaction,
executionState core.StateReader,
classLookupState core.StateReader,
Expand All @@ -181,19 +181,13 @@ func traceTransactionsWithState(
return nil, nil, httpHeader, err
}

executionResult, vmErr := vm.Execute(
executionResult, vmErr := runner.Trace(
transactions,
declaredClasses,
paidFeesOnL1,
blockInfo,
executionState,
false, // skipValidate
false, // skipFeeCharge
false, // skipNonceCharge
true, // allowZeroMaxFee
false, // allowNoSignature
false, // isEstimateFee
returnInitialReads,
vm.TraceOptions{ReturnInitialReads: returnInitialReads},
)

httpHeader.Set(ExecutionStepsHeader, strconv.FormatUint(executionResult.NumSteps, 10))
Expand Down
Loading
Loading