From 23a23dbd625b5b1bf52cad5e3f34077ffb44f271 Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Wed, 8 Jan 2025 15:07:15 +0100 Subject: [PATCH 1/3] EVM/tezt: test fee_history with zero or negative block_count --- etherlink/tezt/tests/evm_rollup.ml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/etherlink/tezt/tests/evm_rollup.ml b/etherlink/tezt/tests/evm_rollup.ml index 5c2d669c30c3..2c2e5f0069d9 100644 --- a/etherlink/tezt/tests/evm_rollup.ml +++ b/etherlink/tezt/tests/evm_rollup.ml @@ -6055,6 +6055,23 @@ let test_rpc_feeHistory_long = ~error_msg:"Expected list of size %R, but got %L" ; unit +let test_rpc_feeHistory_negative_blockcount = + register_both + ~tags:["evm"; "rpc"; "fee_history"; "block_count"] + ~title:"RPC methods eth_feeHistory with zero or negative blockCount" + @@ fun ~protocol:_ ~evm_setup -> + let* _ = + repeat 3 (fun () -> + let*@ _ = evm_setup.produce_block () in + unit) + in + (* block_count can't be 0 or negative *) + let*@? _ = Rpc.fee_history (Int64.to_string 0L) "latest" evm_setup.evm_node in + let*@? _ = + Rpc.fee_history (Int64.to_string (-1L)) "latest" evm_setup.evm_node + in + unit + let test_rpcs_can_be_disabled = register_both ~tags:["evm"; "rpc"; "restricted"] @@ -6293,6 +6310,7 @@ let register_evm_node ~protocols = test_rpc_feeHistory_past protocols ; test_rpc_feeHistory_future protocols ; test_rpc_feeHistory_long protocols ; + test_rpc_feeHistory_negative_blockcount protocols ; test_rpcs_can_be_disabled protocols ; test_simulation_out_of_funds protocols ; test_rpc_state_value_and_subkeys protocols ; -- GitLab From 9a8110aa93fc0dfcf9bed73b38ad7cf5543b8cab Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Wed, 8 Jan 2025 14:56:44 +0100 Subject: [PATCH 2/3] EVM/node: fee_history RPC block_count can't be negative --- etherlink/bin_node/lib_dev/services.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/etherlink/bin_node/lib_dev/services.ml b/etherlink/bin_node/lib_dev/services.ml index 5f13e2147098..55b0694b9bd3 100644 --- a/etherlink/bin_node/lib_dev/services.ml +++ b/etherlink/bin_node/lib_dev/services.ml @@ -352,7 +352,8 @@ let get_fee_history block_count block_parameter config let rec get_fee_history_aux block_count block_parameter (history_acc : Fee_history.t) = - if block_count = Z.zero || block_parameter = Block_parameter.Number Qty.zero + if + block_count <= Z.zero || block_parameter = Block_parameter.Number Qty.zero then return history_acc else let* block = @@ -755,7 +756,7 @@ let dispatch_request (rpc : Configuration.rpc) (config : Configuration.t) build_with_input ~f module_ parameters | Eth_fee_history.Method -> let f (Qty block_count, newest_block, _reward_percentile) = - if block_count = Z.zero then + if block_count <= Z.zero then rpc_error (Rpc_errors.invalid_params "Number of block should be greater than 0.") -- GitLab From 36878c6baaac1747329c3f4f1c8d08fed790be32 Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Wed, 8 Jan 2025 15:33:06 +0100 Subject: [PATCH 3/3] EVM/node: add default value 1024 for fee_history max count --- etherlink/CHANGES_NODE.md | 3 ++ etherlink/bin_node/config/configuration.ml | 32 ++++++++++++++++--- etherlink/bin_node/config/configuration.mli | 4 ++- etherlink/bin_node/lib_dev/services.ml | 6 ++-- .../Alpha- Configuration RPC.out | 12 +++++-- .../EVM Node- describe config.out | 7 ++-- 6 files changed, 51 insertions(+), 13 deletions(-) diff --git a/etherlink/CHANGES_NODE.md b/etherlink/CHANGES_NODE.md index 8026402aebfb..d0a93eac5da0 100644 --- a/etherlink/CHANGES_NODE.md +++ b/etherlink/CHANGES_NODE.md @@ -22,6 +22,9 @@ source for fresh data directories. (!16093) - The `snapshot import` command can now download a snapshot if provided with a URL instead of a path. (!16112) +- Add a default value, 1024, for the RPC `eth_feeHistory` block_count + parameters. Configuration can be `unlimited` if no maximum is + wanted. (!16150) #### Experimental diff --git a/etherlink/bin_node/config/configuration.ml b/etherlink/bin_node/config/configuration.ml index fd91ee51dd36..02b3cebcf6a4 100644 --- a/etherlink/bin_node/config/configuration.ml +++ b/etherlink/bin_node/config/configuration.ml @@ -85,7 +85,9 @@ type proxy = { ignore_block_param : bool; } -type fee_history = {max_count : int option; max_past : int option} +type fee_history_max_count = Unlimited | Limit of int + +type fee_history = {max_count : fee_history_max_count; max_past : int option} (* The regular expression is compiled at the launch of the node, and encoded into its raw form. *) @@ -263,7 +265,7 @@ let default_blueprints_publisher_config_with_dal = significantly larger than max_blueprints_lag. *) } -let default_fee_history = {max_count = None; max_past = None} +let default_fee_history = {max_count = Limit 1024; max_past = None} let make_pattern_restricted_rpcs raw = Pattern {raw; regex = Re.Perl.compile_pat raw} @@ -888,16 +890,38 @@ let default_proxy ?evm_node_endpoint ?(ignore_block_param = false) () = let fee_history_encoding = let open Data_encoding in + let max_count_encoding : fee_history_max_count Data_encoding.t = + union + [ + case + ~title:"unlimited" + ~description:"Allow any number for block_count parameter request." + Json_only + (constant "unlimited") + (function + | (Unlimited : fee_history_max_count) -> Some () | _ -> None) + (fun () -> Unlimited); + case + ~title:"limit" + ~description:"Limit the number of block allowed to be queried." + Json_only + strictly_positive_encoding + (function + | (Limit limit : fee_history_max_count) -> Some limit | _ -> None) + (fun limit -> Limit limit); + ] + in conv (fun {max_count; max_past} -> (max_count, max_past)) (fun (max_count, max_past) -> {max_count; max_past}) (obj2 - (opt + (dft ~description: "The maximum number of blocks whose fee history can be retrieved \ at once" "max_count" - strictly_positive_encoding) + max_count_encoding + default_fee_history.max_count) (opt ~description: "The maximum number of blocks in the past where the fee history is \ diff --git a/etherlink/bin_node/config/configuration.mli b/etherlink/bin_node/config/configuration.mli index 2dafde1e141d..ad4a4dc6c060 100644 --- a/etherlink/bin_node/config/configuration.mli +++ b/etherlink/bin_node/config/configuration.mli @@ -126,7 +126,9 @@ type proxy = { ignore_block_param : bool; } -type fee_history = {max_count : int option; max_past : int option} +type fee_history_max_count = Unlimited | Limit of int + +type fee_history = {max_count : fee_history_max_count; max_past : int option} type restricted_rpcs = | Unrestricted diff --git a/etherlink/bin_node/lib_dev/services.ml b/etherlink/bin_node/lib_dev/services.ml index 55b0694b9bd3..26e65de13535 100644 --- a/etherlink/bin_node/lib_dev/services.ml +++ b/etherlink/bin_node/lib_dev/services.ml @@ -317,11 +317,11 @@ let get_fee_history block_count block_parameter config (* TODO: exclude 0 blocks *) let open Lwt_result_syntax in let open Ethereum_types in - (* block count can be bounded in configuration *) + (* block count is bounded by configuration (default to Configuration.default_fee_history.max_count *) let block_count = match Configuration.(config.fee_history.max_count) with - | None -> block_count - | Some count -> Z.(min (of_int count) block_count) + | Unlimited -> block_count + | Limit block_count_limit -> Z.(min (of_int block_count_limit) block_count) in let* nb_latest = Backend_rpc.Block_storage.current_block_number () in let is_reachable nb = diff --git a/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Configuration RPC.out b/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Configuration RPC.out index 58fc43cce0f2..dea63c4c649b 100644 --- a/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Configuration RPC.out +++ b/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Configuration RPC.out @@ -28,7 +28,9 @@ "proxy": { "ignore_block_param": false }, - "fee_history": {}, + "fee_history": { + "max_count": 1024 + }, "kernel_execution": { "preimages": "hidden", "native_execution_policy": "never" @@ -85,7 +87,9 @@ "proxy": { "ignore_block_param": false }, - "fee_history": {}, + "fee_history": { + "max_count": 1024 + }, "kernel_execution": { "preimages": "hidden", "native_execution_policy": "never" @@ -136,7 +140,9 @@ "evm_node_endpoint": "hidden", "ignore_block_param": false }, - "fee_history": {}, + "fee_history": { + "max_count": 1024 + }, "kernel_execution": { "preimages": "hidden", "native_execution_policy": "never" diff --git a/etherlink/tezt/tests/expected/evm_sequencer.ml/EVM Node- describe config.out b/etherlink/tezt/tests/expected/evm_sequencer.ml/EVM Node- describe config.out index 29d4b1cf880c..7685b61274c0 100644 --- a/etherlink/tezt/tests/expected/evm_sequencer.ml/EVM Node- describe config.out +++ b/etherlink/tezt/tests/expected/evm_sequencer.ml/EVM Node- describe config.out @@ -175,9 +175,12 @@ "ignore_block_param"?: boolean }, "fee_history"?: { "max_count"?: - integer ∈ [1, 2^30] /* The maximum number of blocks whose fee history can be retrieved at - once */, + once */ + "unlimited" + || integer ∈ [1, 2^30] + /* limit + Limit the number of block allowed to be queried. */, "max_past"?: integer ∈ [1, 2^30] /* The maximum number of blocks in the past where the fee history is -- GitLab