Skip to content

Commit

Permalink
Use placeholder nonce when serving L1 handlers over RPC (#1600)
Browse files Browse the repository at this point in the history
Old L1 handlers don't have nonces, but the spec requires the nonce. We
use 0x0 as the placeholder.

A regression test is included.
  • Loading branch information
joshklop authored Dec 23, 2023
1 parent 922ed78 commit 96576b5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"execution_status": "SUCCEEDED", "finality_status": "ACCEPTED_ON_L1", "status": "ACCEPTED_ON_L1", "block_hash": "0x27d1e625a4293d2ed162eb2a1ad031cf71eaa2bab3a3d10fe9bddc51b877ccd", "block_number": 192, "transaction_index": 22, "transaction": {"transaction_hash": "0x5d50b7020f7cf8033fd7d913e489f47edf74fbf3c8ada85be512c7baa6a2eab", "version": "0x0", "contract_address": "0x58b43819bb12aba8ab3fb2e997523e507399a3f48a1e2aa20a5fb7734a0449f", "entry_point_selector": "0xe3f5e9e1456ffa52a3fbc7e8c296631d4cc2120c0be1e2829301c0d8fa026b", "calldata": ["0x5474c49483aa09993090979ade8101ebb4cdce4a", "0xabf8dd8438d1c21e83a8b5e9c1f9b58aaf3ed360", "0x2", "0x4c04fac82913f01a8f01f6e15ff7e834ff2d9a9a1d8e9adffc7bd45692f4f9a"], "type": "L1_HANDLER"}}
7 changes: 5 additions & 2 deletions rpc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,15 @@ func AdaptTransaction(t core.Transaction) *Transaction {
case *core.DeployAccountTransaction:
txn = adaptDeployAccountTrandaction(v)
case *core.L1HandlerTransaction:
// https://github.com/starkware-libs/starknet-specs/blob/a789ccc3432c57777beceaa53a34a7ae2f25fda0/api/starknet_api_openrpc.json#L1669
nonce := v.Nonce
if nonce == nil {
nonce = &felt.Zero
}
txn = &Transaction{
Type: TxnL1Handler,
Hash: v.Hash(),
Version: v.Version.AsFelt(),
Nonce: v.Nonce,
Nonce: nonce,
ContractAddress: v.ContractAddress,
EntryPointSelector: v.EntryPointSelector,
CallData: &v.CallData,
Expand Down
20 changes: 19 additions & 1 deletion rpc/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func TestTransactionByHash(t *testing.T) {
}`,
},

"L1 Handler v0": {
"L1 Handler v0 with nonce": {
hash: "0x537eacfd3c49166eec905daff61ff7feef9c133a049ea2135cb94eec840a4a8",
network: utils.Mainnet,
expected: `{
Expand All @@ -585,6 +585,24 @@ func TestTransactionByHash(t *testing.T) {
]
}`,
},
"L1 Handler v0 without nonce": {
hash: "0x5d50b7020f7cf8033fd7d913e489f47edf74fbf3c8ada85be512c7baa6a2eab",
network: utils.Mainnet,
expected: `{
"type": "L1_HANDLER",
"transaction_hash": "0x5d50b7020f7cf8033fd7d913e489f47edf74fbf3c8ada85be512c7baa6a2eab",
"version": "0x0",
"nonce": "0x0",
"contract_address": "0x58b43819bb12aba8ab3fb2e997523e507399a3f48a1e2aa20a5fb7734a0449f",
"entry_point_selector": "0xe3f5e9e1456ffa52a3fbc7e8c296631d4cc2120c0be1e2829301c0d8fa026b",
"calldata": [
"0x5474c49483aa09993090979ade8101ebb4cdce4a",
"0xabf8dd8438d1c21e83a8b5e9c1f9b58aaf3ed360",
"0x2",
"0x4c04fac82913f01a8f01f6e15ff7e834ff2d9a9a1d8e9adffc7bd45692f4f9a"
]
}`,
},

"Invoke v1": {
hash: "0x2897e3cec3e24e4d341df26b8cf1ab84ea1c01a051021836b36c6639145b497",
Expand Down

0 comments on commit 96576b5

Please sign in to comment.