Skip to content

Commit f2718e1

Browse files
committed
refactor: copy SimulationFlag and MsgFromL1 from v6
1 parent b89fc7b commit f2718e1

6 files changed

Lines changed: 60 additions & 24 deletions

File tree

rpc/v8/estimate_fee.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/NethermindEth/juno/core/felt"
1010
"github.com/NethermindEth/juno/jsonrpc"
1111
"github.com/NethermindEth/juno/rpc/rpccore"
12-
rpcv6 "github.com/NethermindEth/juno/rpc/v6"
12+
"github.com/ethereum/go-ethereum/common"
1313
)
1414

1515
type FeeUnit byte
@@ -41,6 +41,16 @@ type FeeEstimate struct {
4141
Unit *FeeUnit `json:"unit,omitempty"`
4242
}
4343

44+
type MsgFromL1 struct {
45+
// The address of the L1 contract sending the message.
46+
From common.Address `json:"from_address" validate:"required"`
47+
// The address of the L2 contract receiving the message.
48+
To felt.Felt `json:"to_address" validate:"required"`
49+
// The payload of the message.
50+
Payload []felt.Felt `json:"payload" validate:"required"`
51+
Selector felt.Felt `json:"entry_point_selector" validate:"required"`
52+
}
53+
4454
/****************************************************
4555
Estimate Fee Handlers
4656
*****************************************************/
@@ -262,14 +272,14 @@ curl --location 'http://localhost:6060/rpc/v0_8' \
262272
func (h *Handler) EstimateFee(
263273
ctx context.Context,
264274
broadcastedTxns BroadcastedTransactionInputs,
265-
simulationFlags []rpcv6.SimulationFlag,
275+
simulationFlags []SimulationFlag,
266276
id *BlockID,
267277
) ([]FeeEstimate, http.Header, *jsonrpc.Error) {
268278
txnResults, httpHeader, err := h.simulateTransactions(
269279
ctx,
270280
id,
271281
broadcastedTxns.Data,
272-
append(simulationFlags, rpcv6.SkipFeeChargeFlag),
282+
append(simulationFlags, SkipFeeChargeFlag),
273283
true,
274284
true,
275285
)
@@ -287,7 +297,7 @@ func (h *Handler) EstimateFee(
287297

288298
func (h *Handler) EstimateMessageFee(
289299
ctx context.Context,
290-
msg *rpcv6.MsgFromL1,
300+
msg *MsgFromL1,
291301
id *BlockID,
292302
) (FeeEstimate, http.Header, *jsonrpc.Error) {
293303
calldata := make([]*felt.Felt, len(msg.Payload)+1)

rpc/v8/estimate_fee_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/NethermindEth/juno/jsonrpc"
1010
"github.com/NethermindEth/juno/mocks"
1111
"github.com/NethermindEth/juno/rpc/rpccore"
12-
rpcv6 "github.com/NethermindEth/juno/rpc/v6"
1312
rpc "github.com/NethermindEth/juno/rpc/v8"
1413
"github.com/NethermindEth/juno/utils"
1514
"github.com/NethermindEth/juno/vm"
@@ -61,7 +60,7 @@ func TestEstimateFee(t *testing.T) {
6160
_, httpHeader, err := handler.EstimateFee(
6261
t.Context(),
6362
rpc.BroadcastedTransactionInputs{},
64-
[]rpcv6.SimulationFlag{},
63+
[]rpc.SimulationFlag{},
6564
&blockID,
6665
)
6766
require.Nil(t, err)
@@ -89,7 +88,7 @@ func TestEstimateFee(t *testing.T) {
8988
_, httpHeader, err := handler.EstimateFee(
9089
t.Context(),
9190
rpc.BroadcastedTransactionInputs{},
92-
[]rpcv6.SimulationFlag{rpcv6.SkipValidateFlag},
91+
[]rpc.SimulationFlag{rpc.SkipValidateFlag},
9392
&blockID,
9493
)
9594
require.Nil(t, err)
@@ -117,7 +116,7 @@ func TestEstimateFee(t *testing.T) {
117116
_, httpHeader, err := handler.EstimateFee(
118117
t.Context(),
119118
rpc.BroadcastedTransactionInputs{},
120-
[]rpcv6.SimulationFlag{rpcv6.SkipValidateFlag},
119+
[]rpc.SimulationFlag{rpc.SkipValidateFlag},
121120
&blockID,
122121
)
123122
require.Equal(t, rpccore.ErrTransactionExecutionError.CloneWithData(rpc.TransactionExecutionErrorData{
@@ -144,7 +143,7 @@ func TestEstimateFee(t *testing.T) {
144143
_, _, err := handler.EstimateFee(
145144
t.Context(),
146145
rpc.BroadcastedTransactionInputs{Data: []rpc.BroadcastedTransaction{invalidTx}},
147-
[]rpcv6.SimulationFlag{},
146+
[]rpc.SimulationFlag{},
148147
&blockID,
149148
)
150149
expectedErr := &jsonrpc.Error{

rpc/v8/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (h *Handler) Events(args EventsArg) (*EventsChunk, *jsonrpc.Error) {
7373
if args.EventFilter.Address != nil {
7474
addresses = []felt.Address{felt.Address(*args.EventFilter.Address)}
7575
}
76-
// rpc/v6 builds its pending block via MakeEmptyPendingForParent, which returns the deprecated
76+
// rpc/v8 builds its pending block via MakeEmptyPendingForParent, which returns the deprecated
7777
// *core.Pending type and carries no events. EventFilter requires *core.PreConfirmed, so a
7878
// no-op is passed here — the result is identical since there are no pending events to emit.
7979
filter, err := h.bcReader.EventFilter(

rpc/v8/handlers_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/NethermindEth/juno/core/felt"
88
"github.com/NethermindEth/juno/mocks"
99
"github.com/NethermindEth/juno/node"
10-
rpcv6 "github.com/NethermindEth/juno/rpc/v6"
1110
rpcv8 "github.com/NethermindEth/juno/rpc/v8"
1211
"github.com/NethermindEth/juno/utils"
1312
"github.com/stretchr/testify/assert"
@@ -56,7 +55,7 @@ func TestThrottledVMError(t *testing.T) {
5655
t.Context(),
5756
&blockID,
5857
rpcv8.BroadcastedTransactionInputs{},
59-
[]rpcv6.SimulationFlag{rpcv6.SkipFeeChargeFlag},
58+
[]rpcv8.SimulationFlag{rpcv8.SkipFeeChargeFlag},
6059
)
6160
assert.Equal(t, throttledErr, rpcErr.Data)
6261
assert.NotEmpty(t, httpHeader.Get(rpcv8.ExecutionStepsHeader))

rpc/v8/simulation.go

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
"github.com/NethermindEth/juno/core/felt"
1414
"github.com/NethermindEth/juno/jsonrpc"
1515
"github.com/NethermindEth/juno/rpc/rpccore"
16-
rpcv6 "github.com/NethermindEth/juno/rpc/v6"
1716
"github.com/NethermindEth/juno/utils"
1817
"github.com/NethermindEth/juno/vm"
18+
"github.com/consensys/gnark-crypto/ecc/stark-curve/fp"
1919
)
2020

2121
const ExecutionStepsHeader string = "X-Cairo-Steps"
@@ -35,6 +35,35 @@ type BroadcastedTransactionInputs = rpccore.LimitSlice[
3535
rpccore.SimulationLimit,
3636
]
3737

38+
type SimulationFlag int
39+
40+
const (
41+
SkipValidateFlag SimulationFlag = iota + 1
42+
SkipFeeChargeFlag
43+
)
44+
45+
var RPCVersion3Value = felt.Felt(fp.Element(
46+
[4]uint64{
47+
18446744073709551521,
48+
18446744073709551615,
49+
18446744073709551615,
50+
576460752303421872,
51+
},
52+
))
53+
54+
func (s *SimulationFlag) UnmarshalJSON(bytes []byte) (err error) {
55+
switch flag := string(bytes); flag {
56+
case `"SKIP_VALIDATE"`:
57+
*s = SkipValidateFlag
58+
case `"SKIP_FEE_CHARGE"`:
59+
*s = SkipFeeChargeFlag
60+
default:
61+
err = fmt.Errorf("unknown simulation flag %q", flag)
62+
}
63+
64+
return err
65+
}
66+
3867
/****************************************************
3968
Simulate Handlers
4069
*****************************************************/
@@ -43,7 +72,7 @@ func (h *Handler) SimulateTransactions(
4372
ctx context.Context,
4473
id *BlockID,
4574
transactions BroadcastedTransactionInputs,
46-
simulationFlags []rpcv6.SimulationFlag,
75+
simulationFlags []SimulationFlag,
4776
) ([]SimulatedTransaction, http.Header, *jsonrpc.Error) {
4877
return h.simulateTransactions(ctx, id, transactions.Data, simulationFlags, false, false)
4978
}
@@ -52,12 +81,12 @@ func (h *Handler) simulateTransactions(
5281
ctx context.Context,
5382
id *BlockID,
5483
transactions []BroadcastedTransaction,
55-
simulationFlags []rpcv6.SimulationFlag,
84+
simulationFlags []SimulationFlag,
5685
errOnRevert bool,
5786
isEstimateFee bool,
5887
) ([]SimulatedTransaction, http.Header, *jsonrpc.Error) {
59-
skipFeeCharge := slices.Contains(simulationFlags, rpcv6.SkipFeeChargeFlag)
60-
skipValidate := slices.Contains(simulationFlags, rpcv6.SkipValidateFlag)
88+
skipFeeCharge := slices.Contains(simulationFlags, SkipFeeChargeFlag)
89+
skipValidate := slices.Contains(simulationFlags, SkipValidateFlag)
6190

6291
httpHeader := http.Header{}
6392
httpHeader.Set(ExecutionStepsHeader, "0")

rpc/v8/simulation_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/NethermindEth/juno/jsonrpc"
1212
"github.com/NethermindEth/juno/mocks"
1313
"github.com/NethermindEth/juno/rpc/rpccore"
14-
rpcv6 "github.com/NethermindEth/juno/rpc/v6"
1514
rpc "github.com/NethermindEth/juno/rpc/v8"
1615
"github.com/NethermindEth/juno/utils"
1716
"github.com/NethermindEth/juno/vm"
@@ -54,7 +53,7 @@ func TestSimulateTransactions(t *testing.T) {
5453
mockVM *mocks.MockVM,
5554
mockState *mocks.MockStateReader,
5655
)
57-
simulationFlags []rpcv6.SimulationFlag
56+
simulationFlags []rpc.SimulationFlag
5857
simulatedTxs []rpc.SimulatedTransaction
5958
}{
6059
{ //nolint:dupl
@@ -77,7 +76,7 @@ func TestSimulateTransactions(t *testing.T) {
7776
NumSteps: uint64(123),
7877
}, nil)
7978
},
80-
simulationFlags: []rpcv6.SimulationFlag{rpcv6.SkipFeeChargeFlag},
79+
simulationFlags: []rpc.SimulationFlag{rpc.SkipFeeChargeFlag},
8180
simulatedTxs: []rpc.SimulatedTransaction{},
8281
},
8382
{ //nolint:dupl
@@ -100,7 +99,7 @@ func TestSimulateTransactions(t *testing.T) {
10099
NumSteps: uint64(123),
101100
}, nil)
102101
},
103-
simulationFlags: []rpcv6.SimulationFlag{rpcv6.SkipValidateFlag},
102+
simulationFlags: []rpc.SimulationFlag{rpc.SkipValidateFlag},
104103
simulatedTxs: []rpc.SimulatedTransaction{},
105104
},
106105
{
@@ -119,7 +118,7 @@ func TestSimulateTransactions(t *testing.T) {
119118
Cause: json.RawMessage("oops"),
120119
})
121120
},
122-
simulationFlags: []rpcv6.SimulationFlag{rpcv6.SkipValidateFlag},
121+
simulationFlags: []rpc.SimulationFlag{rpc.SkipValidateFlag},
123122
err: rpccore.ErrTransactionExecutionError.CloneWithData(rpc.TransactionExecutionErrorData{
124123
TransactionIndex: 44,
125124
ExecutionError: json.RawMessage("oops"),
@@ -144,7 +143,7 @@ func TestSimulateTransactions(t *testing.T) {
144143
NumSteps: uint64(0),
145144
}, nil)
146145
},
147-
simulationFlags: []rpcv6.SimulationFlag{rpcv6.SkipValidateFlag},
146+
simulationFlags: []rpc.SimulationFlag{rpc.SkipValidateFlag},
148147
err: rpccore.ErrInternal.CloneWithData(errors.New(
149148
"inconsistent lengths: 1 overall fees, 1 traces, 1 gas consumed, 2 data availability, 0 txns",
150149
)),
@@ -297,7 +296,7 @@ func TestSimulateTransactionsShouldErrorWithoutSenderAddressOrResourceBounds(t *
297296
t.Context(),
298297
&blockID,
299298
rpc.BroadcastedTransactionInputs{Data: test.transactions},
300-
[]rpcv6.SimulationFlag{},
299+
[]rpc.SimulationFlag{},
301300
)
302301
if test.err != nil {
303302
require.Equal(t, test.err, err)

0 commit comments

Comments
 (0)