Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 0.6 rpc endpoints #2401

Closed
wants to merge 14 commits into from
1 change: 0 additions & 1 deletion adapters/core2p2p/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ func AdaptExecutionResources(er *core.ExecutionResources) *gen.Receipt_Execution
var l1Gas, l1DataGas, l2Gas, totalL1Gas, totalL1DataGas *felt.Felt
if da := er.DataAvailability; da != nil { // todo(kirill) check that it might be null
l1Gas = new(felt.Felt).SetUint64(da.L1Gas)
l2Gas = new(felt.Felt).SetUint64(da.L2Gas)
l1DataGas = new(felt.Felt).SetUint64(da.L1DataGas)
}
if tgs := er.TotalGasConsumed; tgs != nil {
Expand Down
1 change: 0 additions & 1 deletion adapters/p2p2core/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func adaptExecutionResources(er *gen.Receipt_ExecutionResources) *core.Execution
},
DataAvailability: &core.DataAvailability{
L1Gas: feltToUint64(er.L1Gas),
L2Gas: feltToUint64(er.L2Gas),
L1DataGas: feltToUint64(er.L1DataGas),
},
MemoryHoles: uint64(er.MemoryHoles),
Expand Down
1 change: 0 additions & 1 deletion core/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ type ExecutionResources struct {
type DataAvailability struct {
L1Gas uint64
L1DataGas uint64
L2Gas uint64
}

type BuiltinInstanceCounter struct {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ require (
go.uber.org/mock v0.5.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.32.0
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67
google.golang.org/grpc v1.70.0
google.golang.org/protobuf v1.36.4
gopkg.in/yaml.v3 v3.0.1
Expand Down Expand Up @@ -188,7 +189,6 @@ require (
go.uber.org/dig v1.18.0 // indirect
go.uber.org/fx v1.23.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sync v0.10.0 // indirect
Expand Down
17 changes: 9 additions & 8 deletions mocks/mock_vm.go

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

32 changes: 21 additions & 11 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,28 @@
if err = jsonrpcServer.RegisterMethods(methods...); err != nil {
return nil, err
}
jsonrpcServerLegacy := jsonrpc.NewServer(maxGoroutines, log).WithValidator(validator.Validator())
legacyMethods, legacyPath := rpcHandler.MethodsV0_7()
if err = jsonrpcServerLegacy.RegisterMethods(legacyMethods...); err != nil {

jsonrpcServerV0_6 := jsonrpc.NewServer(maxGoroutines, log).WithValidator(validator.Validator())
methodsV0_6, pathV0_6 := rpcHandler.MethodsV0_6()
if err = jsonrpcServerV0_6.RegisterMethods(methodsV0_6...); err != nil {
return nil, err
}

jsonrpcServerV0_7 := jsonrpc.NewServer(maxGoroutines, log).WithValidator(validator.Validator())
methodsV0_7, pathV0_7 := rpcHandler.MethodsV0_7()
if err = jsonrpcServerV0_7.RegisterMethods(methodsV0_7...); err != nil {
return nil, err
}

Check warning on line 224 in node/node.go

View check run for this annotation

Codecov / codecov/patch

node/node.go#L223-L224

Added lines #L223 - L224 were not covered by tests

rpcServers := map[string]*jsonrpc.Server{
"/": jsonrpcServer,
path: jsonrpcServer,
legacyPath: jsonrpcServerLegacy,
"/rpc": jsonrpcServer,
"/rpc" + path: jsonrpcServer,
"/rpc" + legacyPath: jsonrpcServerLegacy,
"/": jsonrpcServer,
path: jsonrpcServer,
pathV0_7: jsonrpcServerV0_7,
pathV0_6: jsonrpcServerV0_6,
"/rpc": jsonrpcServer,
"/rpc" + path: jsonrpcServer,
"/rpc" + pathV0_7: jsonrpcServerV0_7,
"/rpc" + pathV0_6: jsonrpcServerV0_6,
}
if cfg.HTTP {
readinessHandlers := NewReadinessHandlers(chain, synchronizer)
Expand All @@ -242,9 +252,9 @@
chain.WithListener(makeBlockchainMetrics())
makeJunoMetrics(version)
database.WithListener(makeDBMetrics())
rpcMetrics, legacyRPCMetrics := makeRPCMetrics(path, legacyPath)
rpcMetrics, legacyRPCMetrics := makeRPCMetrics(path, pathV0_7)
jsonrpcServer.WithListener(rpcMetrics)
jsonrpcServerLegacy.WithListener(legacyRPCMetrics)
jsonrpcServerV0_7.WithListener(legacyRPCMetrics)
client.WithListener(makeFeederMetrics())
gatewayClient.WithListener(makeGatewayMetrics())
metricsService = makeMetrics(cfg.MetricsHost, cfg.MetricsPort)
Expand Down
9 changes: 5 additions & 4 deletions node/throttled_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@

func NewThrottledVM(res vm.VM, concurrenyBudget uint, maxQueueLen int32) *ThrottledVM {
return &ThrottledVM{
Throttler: utils.NewThrottler[vm.VM](concurrenyBudget, &res).WithMaxQueueLen(maxQueueLen),
Throttler: utils.NewThrottler(concurrenyBudget, &res).WithMaxQueueLen(maxQueueLen),
}
}

func (tvm *ThrottledVM) Call(callInfo *vm.CallInfo, blockInfo *vm.BlockInfo, state core.StateReader,
network *utils.Network, maxSteps uint64,
network *utils.Network, maxSteps uint64, useBlobData bool,
) ([]*felt.Felt, error) {
var ret []*felt.Felt
return ret, tvm.Do(func(vm *vm.VM) error {
var err error
ret, err = (*vm).Call(callInfo, blockInfo, state, network, maxSteps)
ret, err = (*vm).Call(callInfo, blockInfo, state, network, maxSteps, useBlobData)

Check warning on line 28 in node/throttled_vm.go

View check run for this annotation

Codecov / codecov/patch

node/throttled_vm.go#L28

Added line #L28 was not covered by tests
return err
})
}

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 bool,
useBlobData bool,
) ([]*felt.Felt, []core.GasConsumed, []vm.TransactionTrace, uint64, error) {
var ret []*felt.Felt
var traces []vm.TransactionTrace
Expand All @@ -40,7 +41,7 @@
return ret, daGas, traces, numSteps, tvm.Do(func(vm *vm.VM) error {
var err error
ret, daGas, traces, numSteps, err = (*vm).Execute(txns, declaredClasses, paidFeesOnL1, blockInfo, state, network,
skipChargeFee, skipValidate, errOnRevert)
skipChargeFee, skipValidate, errOnRevert, useBlobData)

Check warning on line 44 in node/throttled_vm.go

View check run for this annotation

Codecov / codecov/patch

node/throttled_vm.go#L44

Added line #L44 was not covered by tests
return err
})
}
57 changes: 55 additions & 2 deletions rpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
Timestamp uint64 `json:"timestamp"`
SequencerAddress *felt.Felt `json:"sequencer_address,omitempty"`
L1GasPrice *ResourcePrice `json:"l1_gas_price"`
L2GasPrice *ResourcePrice `json:"l2_gas_price"`
L2GasPrice *ResourcePrice `json:"l2_gas_price,omitempty"`
L1DataGasPrice *ResourcePrice `json:"l1_data_gas_price,omitempty"`
L1DAMode *L1DAMode `json:"l1_da_mode,omitempty"`
StarknetVersion string `json:"starknet_version"`
Expand Down Expand Up @@ -171,6 +171,15 @@
//
// It follows the specification defined here:
// https://github.com/starkware-libs/starknet-specs/blob/a789ccc3432c57777beceaa53a34a7ae2f25fda0/api/starknet_api_openrpc.json#L11
func (h *Handler) BlockWithTxHashesV0_7(id BlockID) (*BlockWithTxHashes, *jsonrpc.Error) {
blockWithTxHashes, rpcErr := h.BlockWithTxHashes(id)
if rpcErr != nil {
return nil, rpcErr
}
blockWithTxHashes.L2GasPrice = nil
return blockWithTxHashes, nil

Check warning on line 180 in rpc/block.go

View check run for this annotation

Codecov / codecov/patch

rpc/block.go#L174-L180

Added lines #L174 - L180 were not covered by tests
}

func (h *Handler) BlockWithTxHashes(id BlockID) (*BlockWithTxHashes, *jsonrpc.Error) {
block, rpcErr := h.blockByID(&id)
if rpcErr != nil {
Expand All @@ -194,6 +203,17 @@
}, nil
}

func (h *Handler) BlockWithTxHashesV0_6(id BlockID) (*BlockWithTxHashes, *jsonrpc.Error) {
resp, err := h.BlockWithTxHashes(id)
if err != nil {
return nil, err
}

Check warning on line 210 in rpc/block.go

View check run for this annotation

Codecov / codecov/patch

rpc/block.go#L206-L210

Added lines #L206 - L210 were not covered by tests

resp.L1DAMode = nil
resp.L1DataGasPrice = nil
return resp, nil

Check warning on line 214 in rpc/block.go

View check run for this annotation

Codecov / codecov/patch

rpc/block.go#L212-L214

Added lines #L212 - L214 were not covered by tests
}

// BlockTransactionCount returns the number of transactions in a block
// identified by the given BlockID.
//
Expand All @@ -207,7 +227,20 @@
return header.TransactionCount, nil
}

func (h *Handler) BlockWithReceiptsV0_7(id BlockID) (*BlockWithReceipts, *jsonrpc.Error) {
blockWithReceipts, err := h.blockWithReceipts(id, V0_7)
if err != nil {
return nil, err
}
blockWithReceipts.L2GasPrice = nil
return blockWithReceipts, nil

Check warning on line 236 in rpc/block.go

View check run for this annotation

Codecov / codecov/patch

rpc/block.go#L230-L236

Added lines #L230 - L236 were not covered by tests
}

func (h *Handler) BlockWithReceipts(id BlockID) (*BlockWithReceipts, *jsonrpc.Error) {
return h.blockWithReceipts(id, V0_8)
}

func (h *Handler) blockWithReceipts(id BlockID, rpcVersion version) (*BlockWithReceipts, *jsonrpc.Error) {
block, rpcErr := h.blockByID(&id)
if rpcErr != nil {
return nil, rpcErr
Expand All @@ -232,7 +265,7 @@
txsWithReceipts[index] = TransactionWithReceipt{
Transaction: t,
// block_hash, block_number are optional in BlockWithReceipts response
Receipt: AdaptReceipt(r, txn, finalityStatus, nil, 0),
Receipt: AdaptReceipt(r, txn, finalityStatus, nil, 0, rpcVersion),
}
}

Expand All @@ -247,6 +280,15 @@
//
// It follows the specification defined here:
// https://github.com/starkware-libs/starknet-specs/blob/a789ccc3432c57777beceaa53a34a7ae2f25fda0/api/starknet_api_openrpc.json#L44
func (h *Handler) BlockWithTxsV0_7(id BlockID) (*BlockWithTxs, *jsonrpc.Error) {
blockWithTxs, rpcErr := h.BlockWithTxs(id)
if rpcErr != nil {
return nil, rpcErr
}
blockWithTxs.L2GasPrice = nil
return blockWithTxs, nil

Check warning on line 289 in rpc/block.go

View check run for this annotation

Codecov / codecov/patch

rpc/block.go#L283-L289

Added lines #L283 - L289 were not covered by tests
}

func (h *Handler) BlockWithTxs(id BlockID) (*BlockWithTxs, *jsonrpc.Error) {
block, rpcErr := h.blockByID(&id)
if rpcErr != nil {
Expand All @@ -270,6 +312,17 @@
}, nil
}

func (h *Handler) BlockWithTxsV0_6(id BlockID) (*BlockWithTxs, *jsonrpc.Error) {
resp, err := h.BlockWithTxs(id)
if err != nil {
return nil, err
}

Check warning on line 319 in rpc/block.go

View check run for this annotation

Codecov / codecov/patch

rpc/block.go#L318-L319

Added lines #L318 - L319 were not covered by tests

resp.L1DAMode = nil
resp.L1DataGasPrice = nil
return resp, nil
}

func (h *Handler) blockStatus(id BlockID, block *core.Block) (BlockStatus, *jsonrpc.Error) {
l1H, jsonErr := h.l1Head()
if jsonErr != nil {
Expand Down
77 changes: 74 additions & 3 deletions rpc/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,78 @@ func TestBlockWithTxHashesV013(t *testing.T) {
Timestamp: coreBlock.Timestamp,
},
Status: rpc.BlockAcceptedL2,
Transactions: []*rpc.Transaction{
Transactions: []*rpc.Transaction{ //nolint:dupl
{
Hash: tx.Hash(),
Type: rpc.TxnInvoke,
Version: tx.Version.AsFelt(),
Nonce: tx.Nonce,
MaxFee: tx.MaxFee,
ContractAddress: tx.ContractAddress,
SenderAddress: tx.SenderAddress,
Signature: &tx.TransactionSignature,
CallData: &tx.CallData,
EntryPointSelector: tx.EntryPointSelector,
ResourceBounds: &map[rpc.Resource]rpc.ResourceBounds{
rpc.ResourceL1Gas: {
MaxAmount: new(felt.Felt).SetUint64(tx.ResourceBounds[core.ResourceL1Gas].MaxAmount),
MaxPricePerUnit: tx.ResourceBounds[core.ResourceL1Gas].MaxPricePerUnit,
},
rpc.ResourceL2Gas: {
MaxAmount: new(felt.Felt).SetUint64(tx.ResourceBounds[core.ResourceL2Gas].MaxAmount),
MaxPricePerUnit: tx.ResourceBounds[core.ResourceL2Gas].MaxPricePerUnit,
},
},
Tip: new(felt.Felt).SetUint64(tx.Tip),
PaymasterData: &tx.PaymasterData,
AccountDeploymentData: &tx.AccountDeploymentData,
NonceDAMode: utils.Ptr(rpc.DataAvailabilityMode(tx.NonceDAMode)),
FeeDAMode: utils.Ptr(rpc.DataAvailabilityMode(tx.FeeDAMode)),
},
},
}, got)
}

func TestBlockWithTxHashesV013_V06(t *testing.T) {
n := utils.Ptr(utils.SepoliaIntegration)
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)
mockReader := mocks.NewMockReader(mockCtrl)
handler := rpc.New(mockReader, nil, nil, "", nil)

blockNumber := uint64(16350)
gw := adaptfeeder.New(feeder.NewTestClient(t, n))
coreBlock, err := gw.BlockByNumber(context.Background(), blockNumber)
require.NoError(t, err)
tx, ok := coreBlock.Transactions[0].(*core.InvokeTransaction)
require.True(t, ok)

mockReader.EXPECT().BlockByNumber(gomock.Any()).Return(coreBlock, nil)
mockReader.EXPECT().L1Head().Return(&core.L1Head{}, nil)
got, rpcErr := handler.BlockWithTxsV0_6(rpc.BlockID{Number: blockNumber})
require.Nil(t, rpcErr)
got.Transactions = got.Transactions[:1]

require.Equal(t, &rpc.BlockWithTxs{
BlockHeader: rpc.BlockHeader{
Hash: coreBlock.Hash,
StarknetVersion: coreBlock.ProtocolVersion,
NewRoot: coreBlock.GlobalStateRoot,
Number: &coreBlock.Number,
ParentHash: coreBlock.ParentHash,
L1GasPrice: &rpc.ResourcePrice{
InFri: utils.HexToFelt(t, "0x17882b6aa74"),
InWei: utils.HexToFelt(t, "0x3b9aca10"),
},
L2GasPrice: &rpc.ResourcePrice{
InFri: &felt.Zero,
InWei: &felt.Zero,
},
SequencerAddress: coreBlock.SequencerAddress,
Timestamp: coreBlock.Timestamp,
},
Status: rpc.BlockAcceptedL2,
Transactions: []*rpc.Transaction{ //nolint:dupl
{
Hash: tx.Hash(),
Type: rpc.TxnInvoke,
Expand Down Expand Up @@ -632,7 +703,7 @@ func TestBlockWithReceipts(t *testing.T) {

txsWithReceipt = append(txsWithReceipt, rpc.TransactionWithReceipt{
Transaction: adaptedTx,
Receipt: rpc.AdaptReceipt(receipt, tx, rpc.TxnAcceptedOnL2, nil, 0),
Receipt: rpc.AdaptReceipt(receipt, tx, rpc.TxnAcceptedOnL2, nil, 0, rpc.V0_8),
})
}

Expand Down Expand Up @@ -678,7 +749,7 @@ func TestBlockWithReceipts(t *testing.T) {

transactions = append(transactions, rpc.TransactionWithReceipt{
Transaction: adaptedTx,
Receipt: rpc.AdaptReceipt(receipt, tx, rpc.TxnAcceptedOnL1, nil, 0),
Receipt: rpc.AdaptReceipt(receipt, tx, rpc.TxnAcceptedOnL1, nil, 0, rpc.V0_8),
})
}

Expand Down
Loading