From d2af530a8af307948198fdbf5e7d5c765074609d Mon Sep 17 00:00:00 2001 From: pikatos Date: Thu, 16 May 2024 17:32:57 +0200 Subject: [PATCH 1/5] EVM/Node: add eth_getBlockReceipts encoding schema --- etherlink/bin_node/lib_dev/rpc_encodings.ml | 18 +++++++++++++++++- etherlink/bin_node/lib_dev/rpc_encodings.mli | 5 +++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/etherlink/bin_node/lib_dev/rpc_encodings.ml b/etherlink/bin_node/lib_dev/rpc_encodings.ml index 196df4331993..a33891477de2 100644 --- a/etherlink/bin_node/lib_dev/rpc_encodings.ml +++ b/etherlink/bin_node/lib_dev/rpc_encodings.ml @@ -308,6 +308,22 @@ module Get_block_by_hash = struct type ('input, 'output) method_ += Method : (input, output) method_ end +module Get_block_receipts = struct + open Ethereum_types + + type input = Block_parameter.t + + type output = Ethereum_types.transaction_receipt list + + let input_encoding = Data_encoding.tup1 Block_parameter.encoding + + let output_encoding = Data_encoding.list transaction_receipt_encoding + + let method_ = "eth_getBlockReceipts" + + type ('input, 'output) method_ += Method : (input, output) method_ +end + module Get_code = struct open Ethereum_types @@ -740,6 +756,7 @@ let supported_methods : (module METHOD) list = (module Block_number); (module Get_block_by_number); (module Get_block_by_hash); + (module Get_block_receipts); (module Get_code); (module Gas_price); (module Get_transaction_count); @@ -785,7 +802,6 @@ let unsupported_methods : string list = "eth_getProof"; "eth_createAccessList"; "eth_feeHistory"; - "eth_getBlockReceipts"; "eth_getFilterChanges"; "eth_getFilterLogs"; "eth_newBlockFilter"; diff --git a/etherlink/bin_node/lib_dev/rpc_encodings.mli b/etherlink/bin_node/lib_dev/rpc_encodings.mli index 29cdf9bc263d..fd1838b22c70 100644 --- a/etherlink/bin_node/lib_dev/rpc_encodings.mli +++ b/etherlink/bin_node/lib_dev/rpc_encodings.mli @@ -157,6 +157,11 @@ module Get_block_by_hash : with type input = Ethereum_types.block_hash * bool and type output = Ethereum_types.block +module Get_block_receipts : + METHOD + with type input = Ethereum_types.Block_parameter.t + and type output = Ethereum_types.transaction_receipt list + module Get_code : METHOD with type input = -- GitLab From 4550d2dc49c8129d4d7da4908f476d2622b57bfb Mon Sep 17 00:00:00 2001 From: pikatos Date: Tue, 21 May 2024 12:34:31 +0200 Subject: [PATCH 2/5] EVM/Node: add eth_getBlockReceipts implementation --- etherlink/bin_node/lib_dev/durable_storage.ml | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/etherlink/bin_node/lib_dev/durable_storage.ml b/etherlink/bin_node/lib_dev/durable_storage.ml index 0890e6fed354..c88deeb62d9b 100644 --- a/etherlink/bin_node/lib_dev/durable_storage.ml +++ b/etherlink/bin_node/lib_dev/durable_storage.ml @@ -207,6 +207,28 @@ module Make (Reader : READER) = struct | None -> raise @@ Invalid_block_structure "Couldn't decode bytes" | Some block -> populate_tx_objects ~full_transaction_object block + let block_receipts n = + let number = Durable_storage_path.Block.(Nth n) in + let open Lwt_result_syntax in + let* block = blocks_by_number ~full_transaction_object:false ~number in + let get_receipt_from_hash tx_hash = + Lwt.map + (function Ok receipt -> receipt | _ -> None) + (transaction_receipt tx_hash) + in + let tx_hashes : hash list = + match block.transactions with + | TxHash tx_hashes -> tx_hashes + | TxFull tx_objects -> + (* This case should never happen, because there is no ways + to ask for full objects when requestion block receipts. *) + List.map + (fun (tx_object : transaction_object) -> tx_object.hash) + tx_objects + in + let*! receipts = Lwt_list.filter_map_s get_receipt_from_hash tx_hashes in + Lwt.return_ok receipts + let chain_id () = inspect_durable_and_decode Durable_storage_path.chain_id decode_number -- GitLab From 300a5c283a1cbb2b9b238c35aa1775e02d79b243 Mon Sep 17 00:00:00 2001 From: pikatos Date: Tue, 21 May 2024 12:37:58 +0200 Subject: [PATCH 3/5] EVM/Node: add eth_getBlockReceipts RPC entry --- etherlink/bin_node/lib_dev/services.ml | 14 ++++++++++++++ etherlink/bin_node/lib_dev/services_backend_sig.ml | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/etherlink/bin_node/lib_dev/services.ml b/etherlink/bin_node/lib_dev/services.ml index b9efe69ab16b..c2d5e90da46d 100644 --- a/etherlink/bin_node/lib_dev/services.ml +++ b/etherlink/bin_node/lib_dev/services.ml @@ -86,6 +86,14 @@ let get_block_by_number ~full_transaction_object block_param in Rollup_node_rpc.nth_block ~full_transaction_object n +let get_block_receipts block_param + (module Rollup_node_rpc : Services_backend_sig.S) = + let open Lwt_result_syntax in + let* (Ethereum_types.Qty n) = + Rollup_node_rpc.block_param_to_block_number (Block_parameter block_param) + in + Rollup_node_rpc.block_receipts n + let get_transaction_from_index block index (module Rollup_node_rpc : Services_backend_sig.S) = let open Lwt_result_syntax in @@ -207,6 +215,12 @@ let dispatch_request (config : Configuration.t) rpc_ok block in build_with_input ~f module_ parameters + | Method (Get_block_receipts.Method, module_) -> + let f block_param = + let* receipts = get_block_receipts block_param (module Backend_rpc) in + rpc_ok receipts + in + build_with_input ~f module_ parameters | Method (Get_code.Method, module_) -> let f (address, block_param) = let* code = Backend_rpc.code address block_param in diff --git a/etherlink/bin_node/lib_dev/services_backend_sig.ml b/etherlink/bin_node/lib_dev/services_backend_sig.ml index a5a02184ad32..c038a65a3113 100644 --- a/etherlink/bin_node/lib_dev/services_backend_sig.ml +++ b/etherlink/bin_node/lib_dev/services_backend_sig.ml @@ -80,6 +80,12 @@ module type S = sig Ethereum_types.block_hash -> Ethereum_types.block tzresult Lwt.t + (** [block_receipts n] returns the receipts of the [n]th + processed and stored block. + *) + val block_receipts : + Z.t -> Ethereum_types.transaction_receipt list tzresult Lwt.t + (** [transaction_receipt tx_hash] returns the receipt of [tx_hash]. *) val transaction_receipt : Ethereum_types.hash -> -- GitLab From 07d517c4d1f423483d48735dd6fa535eb38ed08c Mon Sep 17 00:00:00 2001 From: pikatos Date: Thu, 23 May 2024 09:27:58 +0200 Subject: [PATCH 4/5] EVM/Tezt: test eth_getBlockReceipts --- etherlink/tezt/tests/evm_rollup.ml | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/etherlink/tezt/tests/evm_rollup.ml b/etherlink/tezt/tests/evm_rollup.ml index df10eaa7dc7c..51ae8b3ced5b 100644 --- a/etherlink/tezt/tests/evm_rollup.ml +++ b/etherlink/tezt/tests/evm_rollup.ml @@ -760,6 +760,46 @@ let test_rpc_getBlockByHash = assert (block = block') ; unit +let test_rpc_getBlockReceipts = + register_both + ~bootstrap_accounts:Eth_account.lots_of_address + ~tags:["evm"; "rpc"; "get_block_receipts"] + ~title:"RPC method eth_getBlockReceipts" + ~minimum_base_fee_per_gas:base_fee_for_hardcoded_tx + @@ fun ~protocol:_ ~evm_setup:{evm_node; sc_rollup_node; client; _} -> + let txs = + read_tx_from_file () + |> List.filteri (fun i _ -> i < 5) + |> List.map (fun (tx, _hash) -> tx) + in + let* _requests, receipt, _hashes = + send_n_transactions ~sc_rollup_node ~client ~evm_node txs + in + let* receipts = + Evm_node.( + call_evm_rpc + evm_node + { + method_ = "eth_getBlockReceipts"; + parameters = `A [`String (Format.sprintf "%#lx" receipt.blockNumber)]; + }) + in + let txs = + List.map + (fun receipt -> + JSON. + ( receipt |-> "transactionHash" |> as_string, + receipt |-> "transactionIndex" |> as_int )) + JSON.(receipts |-> "result" |> as_list) + in + let expected_txs = + read_tx_from_file () + |> List.filteri (fun i _ -> i < 5) + |> List.mapi (fun i (_tx, hash) -> (hash, i)) + in + assert (List.equal ( = ) txs expected_txs) ; + unit + let test_l2_block_size_non_zero = register_both ~tags:["evm"; "block"; "size"] @@ -5662,6 +5702,7 @@ let register_evm_node ~protocols = test_rpc_net_version protocols ; test_rpc_getBlockByNumber protocols ; test_rpc_getBlockByHash protocols ; + test_rpc_getBlockReceipts protocols ; test_rpc_getTransactionCount protocols ; test_rpc_getTransactionCountBatch protocols ; test_rpc_batch protocols ; -- GitLab From 90fd443d0f2ca2731904db6a9e20be8f199d5952 Mon Sep 17 00:00:00 2001 From: pikatos Date: Thu, 23 May 2024 10:19:18 +0200 Subject: [PATCH 5/5] Etherlink: changelog 13370 --- etherlink/CHANGES_NODE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/etherlink/CHANGES_NODE.md b/etherlink/CHANGES_NODE.md index 6602e46d2d5c..1c41077fe688 100644 --- a/etherlink/CHANGES_NODE.md +++ b/etherlink/CHANGES_NODE.md @@ -20,6 +20,7 @@ upstream EVM node endpoint is stalled. (!13265) - Support for the `charset` specifier for `Content-Type: application/json`. (!13256) - `txpool_content` support. (!12873, !13292) +- Support the RPC `eth_getBlockReceipts`. (!13370) ### Experimental -- GitLab