Skip to content

Commit

Permalink
Add support for v0.7 JSON RPC (#1730)
Browse files Browse the repository at this point in the history
Add new method `starknet_getBlockWithReceipts`
Update Traces with execution resources
Update EstimateFee and Block Header with data availability fields 

Co-authored-by: Wojciech Zieba <[email protected]>
Co-authored-by: IronGauntlets <[email protected]>
Co-authored-by: kirugan <[email protected]>
  • Loading branch information
4 people committed Mar 5, 2024
1 parent 6499f7f commit 1f856a7
Show file tree
Hide file tree
Showing 27 changed files with 698 additions and 757 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
needs: [deploy_to_dev]
uses: ./.github/workflows/starknet-js-tests.yml
secrets:
TEST_RPC_URL: ${{ secrets.DEV_GOERLI_URL }}/v0_5
TEST_RPC_URL: ${{ secrets.DEV_GOERLI_URL }}/v0_6
TEST_ACCOUNT_ADDRESS: ${{ secrets.GOERLI_TEST_ACCOUNT_ADDRESS }}
TEST_ACCOUNT_PRIVATE_KEY: ${{ secrets.GOERLI_TEST_ACCOUNT_PRIVATE_KEY }}

Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
needs: [deploy_to_staging]
uses: ./.github/workflows/starknet-js-tests.yml
secrets:
TEST_RPC_URL: ${{ secrets.STAGING_GOERLI_URL }}/v0_5
TEST_RPC_URL: ${{ secrets.STAGING_GOERLI_URL }}/v0_6
TEST_ACCOUNT_ADDRESS: ${{ secrets.GOERLI_TEST_ACCOUNT_ADDRESS }}
TEST_ACCOUNT_PRIVATE_KEY: ${{ secrets.GOERLI_TEST_ACCOUNT_PRIVATE_KEY }}

Expand Down Expand Up @@ -154,6 +154,6 @@ jobs:
needs: [deploy_to_production]
uses: ./.github/workflows/starknet-js-tests.yml
secrets:
TEST_RPC_URL: ${{ secrets.PROD_GOERLI_URL }}/v0_5
TEST_RPC_URL: ${{ secrets.PROD_GOERLI_URL }}/v0_6
TEST_ACCOUNT_ADDRESS: ${{ secrets.GOERLI_TEST_ACCOUNT_ADDRESS }}
TEST_ACCOUNT_PRIVATE_KEY: ${{ secrets.GOERLI_TEST_ACCOUNT_PRIVATE_KEY }}
2 changes: 1 addition & 1 deletion .github/workflows/starknet-js-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: starknet-io/starknet.js
ref: v5.24.3
ref: v6.1.5

- name: Setup Node.js
uses: actions/setup-node@v3
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/starknet-rs-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ jobs:
cd starknet-providers && cargo test jsonrpc
cd ../starknet-accounts && cargo test jsonrpc
env:
STARKNET_RPC: ${{ secrets.STARKNET_RPC }}
STARKNET_RPC: ${{ secrets.STARKNET_RPC }}
RUST_BACKTRACE: full
22 changes: 12 additions & 10 deletions adapters/vm2core/vm2core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,17 @@ func TestAdaptExecutionResources(t *testing.T) {
MemoryHoles: 9,
Steps: 10,
}, vm2core.AdaptExecutionResources(&vm.ExecutionResources{
Steps: 10,
MemoryHoles: 9,
Pedersen: 1,
RangeCheck: 2,
Bitwise: 3,
Ecdsa: 4,
EcOp: 5,
Keccak: 6,
Poseidon: 7,
SegmentArena: 8,
ComputationResources: vm.ComputationResources{
Steps: 10,
MemoryHoles: 9,
Pedersen: 1,
RangeCheck: 2,
Bitwise: 3,
Ecdsa: 4,
EcOp: 5,
Keccak: 6,
Poseidon: 7,
SegmentArena: 8,
},
}))
}
1 change: 1 addition & 0 deletions jsonrpc/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (h *HTTP) ServeHTTP(writer http.ResponseWriter, req *http.Request) {
resp, err := h.rpc.HandleReader(req.Context(), req.Body)
writer.Header().Set("Content-Type", "application/json")
if err != nil {
h.log.Errorw("Handler failure", "err", err)
writer.WriteHeader(http.StatusInternalServerError)
}
if resp != nil {
Expand Down
2 changes: 1 addition & 1 deletion jsonrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func Err(code int, data any) *Error {
case InvalidParams:
return &Error{Code: InvalidParams, Message: "Invalid Params", Data: data}
default:
return &Error{Code: InternalError, Message: "Internal Error", Data: data}
return &Error{Code: InternalError, Message: "Internal error", Data: data}
}
}

Expand Down
2 changes: 1 addition & 1 deletion jsonrpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func TestHandle(t *testing.T) {
},
"fails internally": {
req: `{"jsonrpc": "2.0", "method": "errorsInternally", "params": {}, "id": 1}`,
res: `{"jsonrpc":"2.0","error":{"code":-32603,"message":"Internal Error"},"id":1}`,
res: `{"jsonrpc":"2.0","error":{"code":-32603,"message":"Internal error"},"id":1}`,
checkFailedEvent: true,
},
}
Expand Down
1 change: 1 addition & 0 deletions mocks/mock_blockchain.go

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

1 change: 1 addition & 0 deletions mocks/mock_gateway_handler.go

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

1 change: 1 addition & 0 deletions mocks/mock_starknetdata.go

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

1 change: 1 addition & 0 deletions mocks/mock_state.go

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

1 change: 1 addition & 0 deletions mocks/mock_subscriber.go

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

1 change: 1 addition & 0 deletions mocks/mock_synchronizer.go

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

15 changes: 8 additions & 7 deletions mocks/mock_vm.go

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

2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen
return nil, err
}
jsonrpcServerLegacy := jsonrpc.NewServer(maxGoroutines, log).WithValidator(validator.Validator())
legacyMethods, legacyPath := rpcHandler.LegacyMethods()
legacyMethods, legacyPath := rpcHandler.MethodsV0_6()
if err = jsonrpcServerLegacy.RegisterMethods(legacyMethods...); err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions node/throttled_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ 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, legacyTraceJSON bool,
) ([]*felt.Felt, []vm.TransactionTrace, error) {
blockInfo *vm.BlockInfo, state core.StateReader, network *utils.Network, skipChargeFee, skipValidate, errOnRevert bool,
) ([]*felt.Felt, []*felt.Felt, []vm.TransactionTrace, error) {
var ret []*felt.Felt
var traces []vm.TransactionTrace
return ret, traces, tvm.Do(func(vm *vm.VM) error {
var dataGasConsumed []*felt.Felt
return ret, dataGasConsumed, traces, tvm.Do(func(vm *vm.VM) error {
var err error
ret, traces, err = (*vm).Execute(txns, declaredClasses, paidFeesOnL1, blockInfo, state, network,
skipChargeFee, skipValidate, errOnRevert, legacyTraceJSON)
ret, dataGasConsumed, traces, err = (*vm).Execute(txns, declaredClasses, paidFeesOnL1, blockInfo, state, network,
skipChargeFee, skipValidate, errOnRevert)
return err
})
}
37 changes: 34 additions & 3 deletions rpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rpc
import (
"encoding/json"
"errors"
"fmt"

"github.com/NethermindEth/juno/core/felt"
)
Expand Down Expand Up @@ -32,6 +33,24 @@ func (s BlockStatus) MarshalJSON() ([]byte, error) {
}
}

type L1DAMode uint8

const (
Blob L1DAMode = iota
Calldata
)

func (l L1DAMode) MarshalText() ([]byte, error) {
switch l {
case Blob:
return []byte("BLOB"), nil
case Calldata:
return []byte("CALLDATA"), nil
default:
return nil, fmt.Errorf("unknown L1DAMode value = %v", l)
}
}

// https://github.com/starkware-libs/starknet-specs/blob/a789ccc3432c57777beceaa53a34a7ae2f25fda0/api/starknet_api_openrpc.json#L520-L534
type BlockHashAndNumber struct {
Hash *felt.Felt `json:"block_hash"`
Expand Down Expand Up @@ -73,9 +92,8 @@ func (b *BlockID) UnmarshalJSON(data []byte) error {
}

type ResourcePrice struct {
InStark *felt.Felt `json:"price_in_strk,omitempty"`
InFri *felt.Felt `json:"price_in_fri,omitempty"`
InWei *felt.Felt `json:"price_in_wei"`
InFri *felt.Felt `json:"price_in_fri"`
InWei *felt.Felt `json:"price_in_wei"`
}

// https://github.com/starkware-libs/starknet-specs/blob/a789ccc3432c57777beceaa53a34a7ae2f25fda0/api/starknet_api_openrpc.json#L1072
Expand All @@ -87,6 +105,8 @@ type BlockHeader struct {
Timestamp uint64 `json:"timestamp"`
SequencerAddress *felt.Felt `json:"sequencer_address,omitempty"`
L1GasPrice *ResourcePrice `json:"l1_gas_price"`
L1DataGasPrice *ResourcePrice `json:"l1_data_gas_price,omitempty"`
L1DAMode *L1DAMode `json:"l1_da_mode,omitempty"`
StarknetVersion string `json:"starknet_version"`
}

Expand All @@ -103,3 +123,14 @@ type BlockWithTxHashes struct {
BlockHeader
TxnHashes []*felt.Felt `json:"transactions"`
}

type TransactionWithReceipt struct {
Transaction *Transaction `json:"transaction"`
Receipt *TransactionReceipt `json:"receipt"`
}

type BlockWithReceipts struct {
Status BlockStatus `json:"status,omitempty"`
BlockHeader
Transactions []TransactionWithReceipt `json:"transactions"`
}
Loading

0 comments on commit 1f856a7

Please sign in to comment.