From ec4c4155a10ad76ec6375e5e7bcf819c387723c5 Mon Sep 17 00:00:00 2001 From: Luciano Freitas Date: Thu, 13 Feb 2025 13:23:06 +0100 Subject: [PATCH 1/4] EVM node: add chain_configuration to durable storage --- .../bin_node/lib_dev/durable_storage_path.ml | 17 +++++++++++++++++ .../bin_node/lib_dev/durable_storage_path.mli | 12 ++++++++++++ 2 files changed, 29 insertions(+) diff --git a/etherlink/bin_node/lib_dev/durable_storage_path.ml b/etherlink/bin_node/lib_dev/durable_storage_path.ml index 6f2841e65ba0..f3cbe1d47375 100644 --- a/etherlink/bin_node/lib_dev/durable_storage_path.ml +++ b/etherlink/bin_node/lib_dev/durable_storage_path.ml @@ -225,3 +225,20 @@ module Trace = struct let call_trace ~transaction_hash i = call_trace_root ~transaction_hash ^ "/" ^ string_of_int i end + +module Chain_configuration = struct + let root chain_id = + EVM.make "/chain_configurations/" ^ Chain_id.to_string chain_id + + let minimum_base_fee_per_gas chain_id = + root chain_id ^ "/minimum_base_fee_per_gas" + + let da_fee_per_byte chain_id = root chain_id ^ "/da_fee_per_byte" + + let maximum_gas_per_transaction chain_id = + root chain_id ^ "/maximum_gas_per_transaction" + + let chain_family chain_id = root chain_id ^ "/chain_family" + + let world_state chain_id = root chain_id ^ "/world_state" +end diff --git a/etherlink/bin_node/lib_dev/durable_storage_path.mli b/etherlink/bin_node/lib_dev/durable_storage_path.mli index 5c929a1b2ab5..70efeb8735cf 100644 --- a/etherlink/bin_node/lib_dev/durable_storage_path.mli +++ b/etherlink/bin_node/lib_dev/durable_storage_path.mli @@ -160,3 +160,15 @@ module Trace : sig (** Path where is stored the [i]eth trace *) val call_trace : transaction_hash:path option -> int -> path end + +module Chain_configuration : sig + val minimum_base_fee_per_gas : Ethereum_types.chain_id -> path + + val da_fee_per_byte : Ethereum_types.chain_id -> path + + val maximum_gas_per_transaction : Ethereum_types.chain_id -> path + + val chain_family : Ethereum_types.chain_id -> path + + val world_state : Ethereum_types.chain_id -> path +end -- GitLab From 2898522fd19f1f25f4e5efb00ca0fadbfa578631 Mon Sep 17 00:00:00 2001 From: Luciano Freitas Date: Thu, 20 Feb 2025 10:38:36 +0100 Subject: [PATCH 2/4] EVM node: add readers to chain configuration --- etherlink/bin_node/lib_dev/durable_storage.ml | 56 +++++++++++++++++++ .../lib_dev/encodings/ethereum_types.mli | 2 + 2 files changed, 58 insertions(+) diff --git a/etherlink/bin_node/lib_dev/durable_storage.ml b/etherlink/bin_node/lib_dev/durable_storage.ml index 99441c94f461..0409574ae0be 100644 --- a/etherlink/bin_node/lib_dev/durable_storage.ml +++ b/etherlink/bin_node/lib_dev/durable_storage.ml @@ -276,6 +276,37 @@ let chain_id read = Durable_storage_path.chain_id Chain_id.decode_le +let l2_minimum_base_fee_per_gas read chain_id = + inspect_durable_and_decode + read + (Durable_storage_path.Chain_configuration.minimum_base_fee_per_gas chain_id) + Ethereum_types.decode_z_le + +let l2_da_fee_per_byte read chain_id = + inspect_durable_and_decode + read + (Durable_storage_path.Chain_configuration.da_fee_per_byte chain_id) + Ethereum_types.decode_z_le + +let l2_maximum_gas_per_transaction read chain_id = + inspect_durable_and_decode + read + (Durable_storage_path.Chain_configuration.maximum_gas_per_transaction + chain_id) + Ethereum_types.decode_z_le + +let chain_family read chain_id = + inspect_durable_and_decode + read + (Durable_storage_path.Chain_configuration.chain_family chain_id) + (fun x -> Ethereum_types.Chain_family.of_string_exn (Bytes.to_string x)) + +let world_state read chain_id = + inspect_durable_and_decode + read + (Durable_storage_path.Chain_configuration.world_state chain_id) + Bytes.to_string + let base_fee_per_gas read = let open Lwt_result_syntax in let* block = @@ -389,6 +420,31 @@ module Make (Reader : READER) = struct let* read = read_with_state () in chain_id read + let l2_minimum_base_fee_per_gas chain_id = + let open Lwt_result_syntax in + let* read = read_with_state () in + l2_minimum_base_fee_per_gas read chain_id + + let l2_da_fee_per_byte chain_id = + let open Lwt_result_syntax in + let* read = read_with_state () in + l2_da_fee_per_byte read chain_id + + let l2_maximum_gas_per_transaction chain_id = + let open Lwt_result_syntax in + let* read = read_with_state () in + l2_maximum_gas_per_transaction read chain_id + + let chain_family chain_id = + let open Lwt_result_syntax in + let* read = read_with_state () in + chain_family read chain_id + + let world_state chain_id = + let open Lwt_result_syntax in + let* read = read_with_state () in + world_state read chain_id + let base_fee_per_gas () = let open Lwt_result_syntax in let* read = read_with_state () in diff --git a/etherlink/bin_node/lib_dev/encodings/ethereum_types.mli b/etherlink/bin_node/lib_dev/encodings/ethereum_types.mli index d2d3a9d452c5..06decb4d6bd4 100644 --- a/etherlink/bin_node/lib_dev/encodings/ethereum_types.mli +++ b/etherlink/bin_node/lib_dev/encodings/ethereum_types.mli @@ -120,6 +120,8 @@ val quantity_encoding : quantity Data_encoding.t val pp_quantity : Format.formatter -> quantity -> unit +val decode_z_le : bytes -> Z.t + val quantity_of_z : Z.t -> quantity val decode_number_le : bytes -> quantity -- GitLab From f7ff096d99a389fe70b036b922434d762c9af138 Mon Sep 17 00:00:00 2001 From: Luciano Freitas Date: Thu, 20 Feb 2025 18:09:32 +0100 Subject: [PATCH 3/4] EVM Node: add get_chain_family service --- etherlink/bin_node/lib_dev/rpc_encodings.ml | 15 +++++++++++++++ etherlink/bin_node/lib_dev/rpc_encodings.mli | 5 +++++ etherlink/bin_node/lib_dev/services.ml | 6 ++++++ .../bin_node/lib_dev/services_backend_sig.ml | 4 ++++ 4 files changed, 30 insertions(+) diff --git a/etherlink/bin_node/lib_dev/rpc_encodings.ml b/etherlink/bin_node/lib_dev/rpc_encodings.ml index e3fb013a4618..a466cfd95730 100644 --- a/etherlink/bin_node/lib_dev/rpc_encodings.ml +++ b/etherlink/bin_node/lib_dev/rpc_encodings.ml @@ -235,6 +235,20 @@ module Chain_id = struct type ('input, 'output) method_ += Method : (input, output) method_ end +module Chain_family = struct + type input = Ethereum_types.chain_id + + type output = Ethereum_types.chain_family + + let input_encoding = Data_encoding.tup1 Ethereum_types.Chain_id.encoding + + let output_encoding = Ethereum_types.Chain_family.encoding + + let method_ = "tez_chainFamily" + + type ('input, 'output) method_ += Method : (input, output) method_ +end + module Accounts = struct type input = unit @@ -971,6 +985,7 @@ let supported_methods : (module METHOD) list = (module Kernel_root_hash); (module Network_id); (module Chain_id); + (module Chain_family); (module Accounts); (module Get_balance); (module Get_storage_at); diff --git a/etherlink/bin_node/lib_dev/rpc_encodings.mli b/etherlink/bin_node/lib_dev/rpc_encodings.mli index c4887be4c269..e3ccdf992c52 100644 --- a/etherlink/bin_node/lib_dev/rpc_encodings.mli +++ b/etherlink/bin_node/lib_dev/rpc_encodings.mli @@ -139,6 +139,11 @@ module Network_id : METHOD with type input = unit and type output = string module Chain_id : METHOD with type input = unit and type output = Ethereum_types.chain_id +module Chain_family : + METHOD + with type input = Ethereum_types.chain_id + and type output = Ethereum_types.chain_family + module Accounts : METHOD with type input = unit and type output = Ethereum_types.address list diff --git a/etherlink/bin_node/lib_dev/services.ml b/etherlink/bin_node/lib_dev/services.ml index fbfe7c8a9f87..c28f4beaeaab 100644 --- a/etherlink/bin_node/lib_dev/services.ml +++ b/etherlink/bin_node/lib_dev/services.ml @@ -451,6 +451,12 @@ let dispatch_request (rpc : Configuration.rpc) rpc_ok chain_id in build ~f module_ parameters + | Rpc_encodings.Chain_family.Method -> + let f chain_id = + let* chain_family = Backend_rpc.chain_family chain_id in + rpc_ok chain_family + in + build_with_input ~f module_ parameters | Get_balance.Method -> let f (address, block_param) = let* balance = Backend_rpc.balance 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 3a5fc3d75d36..a69faca1e48b 100644 --- a/etherlink/bin_node/lib_dev/services_backend_sig.ml +++ b/etherlink/bin_node/lib_dev/services_backend_sig.ml @@ -48,6 +48,10 @@ module type S = sig (** [chain_id ()] returns chain id defined by the rollup. *) val chain_id : unit -> Ethereum_types.chain_id tzresult Lwt.t + (** [chain_family chain_id] returns chain family defined for the chain with id chain_id. *) + val chain_family : + Ethereum_types.chain_id -> Ethereum_types.chain_family tzresult Lwt.t + (** [base_fee_per_gas ()] returns base fee defined by the rollup. *) val base_fee_per_gas : unit -> Ethereum_types.quantity tzresult Lwt.t -- GitLab From 7b93f7e0ef401e0d0a926d614d0b048bec6b412f Mon Sep 17 00:00:00 2001 From: Luciano Freitas Date: Fri, 14 Feb 2025 14:33:00 +0100 Subject: [PATCH 4/4] Etherlink/Tezt: test rpc behaviour with family --- etherlink/tezt/lib/rpc.ml | 13 +++++++++++++ etherlink/tezt/lib/rpc.mli | 4 ++++ etherlink/tezt/tests/evm_sequencer.ml | 20 +++----------------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/etherlink/tezt/lib/rpc.ml b/etherlink/tezt/lib/rpc.ml index 2325bce425dc..418efc2a222a 100644 --- a/etherlink/tezt/lib/rpc.ml +++ b/etherlink/tezt/lib/rpc.ml @@ -144,6 +144,12 @@ module Request = struct let eth_getChainId = {method_ = "eth_chainId"; parameters = `A []} + let tez_getChainFamily ~chain_id = + { + method_ = "tez_chainFamily"; + parameters = `A [`String (string_of_int chain_id)]; + } + let net_version = {method_ = "net_version"; parameters = `A []} let tez_kernelVersion = {method_ = "tez_kernelVersion"; parameters = `Null} @@ -331,6 +337,13 @@ let get_chain_id ?websocket evm_node = let* json = Evm_node.jsonrpc ?websocket evm_node Request.eth_getChainId in return (decode_or_error (fun json -> JSON.(json |-> "result" |> as_int)) json) +let get_chain_family ?websocket evm_node chain_id = + let* json = + Evm_node.jsonrpc ?websocket evm_node (Request.tez_getChainFamily ~chain_id) + in + return + (decode_or_error (fun json -> JSON.(json |-> "result" |> as_string)) json) + let get_transaction_by_hash ?websocket ~transaction_hash evm_node = let* json = Evm_node.jsonrpc diff --git a/etherlink/tezt/lib/rpc.mli b/etherlink/tezt/lib/rpc.mli index 7a03789ca753..b68df202f131 100644 --- a/etherlink/tezt/lib/rpc.mli +++ b/etherlink/tezt/lib/rpc.mli @@ -97,6 +97,10 @@ val net_version : val get_chain_id : ?websocket:Websocket.t -> Evm_node.t -> (int, error) result Lwt.t +(** [get_chain_family node] calls [tez_getChainFamily]. *) +val get_chain_family : + ?websocket:Websocket.t -> Evm_node.t -> int -> (string, error) result Lwt.t + (** [get_transaction_by_hash ~transaction_hash evm_node] calls [eth_getTransactionByHash]. *) val get_transaction_by_hash : ?websocket:Websocket.t -> diff --git a/etherlink/tezt/tests/evm_sequencer.ml b/etherlink/tezt/tests/evm_sequencer.ml index 6ba43aa16fbc..ed5ae96a3c50 100644 --- a/etherlink/tezt/tests/evm_sequencer.ml +++ b/etherlink/tezt/tests/evm_sequencer.ml @@ -453,23 +453,9 @@ let test_make_l2_kernel_installer_config chain_family = Evm_node.init ~mode:sequencer (Sc_rollup_node.endpoint sc_rollup_node) in - (* Verify the chain_family is set to EVM *) - let family_path = - "/evm/chain_configurations/" ^ string_of_int chain_id ^ "/chain_family" - in - let*@ rpc = Rpc.state_value sequencer family_path in - let family_value = - match rpc with - | None -> - Test.fail - ~__LOC__ - "There should be a value at %s setup by the \ - make_l2_kernel_installer_config" - family_path - | Some family_value -> family_value - in - let (`Hex expected) = Hex.of_string chain_family in - Check.((family_value = expected) string) + (* Verify the chain_family is properly set *) + let*@ family_value = Rpc.get_chain_family sequencer chain_id in + Check.((family_value = chain_family) string) ~error_msg:"Expected chain_family to be %R, got %L" ; (* Verify that the balance of the bootstrap account is set by the command -- GitLab