Skip to content

Commit

Permalink
Change error message on VM busy
Browse files Browse the repository at this point in the history
  • Loading branch information
omerfirmak authored and wojciechos committed Feb 17, 2024
1 parent a5178ae commit 2a9c024
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions rpc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const (
maxEventChunkSize = 10240
maxEventFilterKeys = 1024
traceCacheSize = 128
throttledVMErr = "VM throughput limit reached"
)

type traceCacheKey struct {
Expand Down Expand Up @@ -1262,7 +1263,7 @@ func (h *Handler) Call(call FunctionCall, id BlockID) ([]*felt.Felt, *jsonrpc.Er
call.Calldata, header.Number, header.Timestamp, state, h.bcReader.Network(), h.callMaxSteps)
if err != nil {
if errors.Is(err, utils.ErrResourceBusy) {
return nil, ErrInternal.CloneWithData(err.Error())
return nil, ErrInternal.CloneWithData(throttledVMErr)
}
return nil, makeContractError(err)
}
Expand Down Expand Up @@ -1507,7 +1508,7 @@ func (h *Handler) simulateTransactions(id BlockID, transactions []BroadcastedTra
header.GasPriceSTRK, legacyTraceJSON)
if err != nil {
if errors.Is(err, utils.ErrResourceBusy) {
return nil, ErrInternal.CloneWithData(err.Error())
return nil, ErrInternal.CloneWithData(throttledVMErr)
}
var txnExecutionError vm.TransactionExecutionError
if errors.As(err, &txnExecutionError) {
Expand Down Expand Up @@ -1650,7 +1651,7 @@ func (h *Handler) traceBlockTransactions(ctx context.Context, block *core.Block,
block.Header.GasPriceSTRK, legacyJSON)
if err != nil {
if errors.Is(err, utils.ErrResourceBusy) {
return nil, ErrInternal.CloneWithData(err.Error())
return nil, ErrInternal.CloneWithData(throttledVMErr)
}
// Since we are tracing an existing block, we know that there should be no errors during execution. If we encounter any,
// report them as unexpected errors
Expand Down
7 changes: 4 additions & 3 deletions rpc/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3741,19 +3741,20 @@ func TestThrottledVMError(t *testing.T) {
handler := rpc.New(mockReader, nil, throttledVM, "", nil)
mockState := mocks.NewMockStateHistoryReader(mockCtrl)

throttledErr := "VM throughput limit reached"
t.Run("call", func(t *testing.T) {
mockReader.EXPECT().HeadState().Return(mockState, nopCloser, nil)
mockReader.EXPECT().HeadsHeader().Return(new(core.Header), nil)
mockState.EXPECT().ContractClassHash(&felt.Zero).Return(new(felt.Felt), nil)
_, rpcErr := handler.Call(rpc.FunctionCall{}, rpc.BlockID{Latest: true})
assert.Equal(t, utils.ErrResourceBusy.Error(), rpcErr.Data)
assert.Equal(t, throttledErr, rpcErr.Data)
})

t.Run("simulate", func(t *testing.T) {
mockReader.EXPECT().HeadState().Return(mockState, nopCloser, nil)
mockReader.EXPECT().HeadsHeader().Return(&core.Header{}, nil)
_, rpcErr := handler.SimulateTransactions(rpc.BlockID{Latest: true}, []rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipFeeChargeFlag})
assert.Equal(t, utils.ErrResourceBusy.Error(), rpcErr.Data)
assert.Equal(t, throttledErr, rpcErr.Data)
})

t.Run("trace", func(t *testing.T) {
Expand Down Expand Up @@ -3788,7 +3789,7 @@ func TestThrottledVMError(t *testing.T) {
headState.EXPECT().Class(declareTx.ClassHash).Return(declaredClass, nil)
mockReader.EXPECT().PendingState().Return(headState, nopCloser, nil)
_, rpcErr := handler.TraceBlockTransactions(context.Background(), rpc.BlockID{Hash: blockHash})
assert.Equal(t, utils.ErrResourceBusy.Error(), rpcErr.Data)
assert.Equal(t, throttledErr, rpcErr.Data)
})
}

Expand Down

0 comments on commit 2a9c024

Please sign in to comment.