diff --git a/etherlink/bin_node/lib_dev/durable_storage.ml b/etherlink/bin_node/lib_dev/durable_storage.ml index 99441c94f461dedcbfc697c56bbdd68b1e2d95e5..0409574ae0be616fb7d364d7629986f058b0daa6 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/durable_storage_path.ml b/etherlink/bin_node/lib_dev/durable_storage_path.ml index 6f2841e65ba0022240bc8f6c406d71f5daf35499..f3cbe1d47375e99bfb7fbdfc38fa6e6a100e6e3d 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 5c929a1b2ab5494610cfef79eb3c6e6560d5c241..70efeb8735cf3c5f11741be6a3e5a64eebfe2fda 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 diff --git a/etherlink/bin_node/lib_dev/encodings/ethereum_types.mli b/etherlink/bin_node/lib_dev/encodings/ethereum_types.mli index d2d3a9d452c5f9ee20fcd22e122301ed6bbaa6cc..06decb4d6bd4d2d056006ad65d47df155d70c8d4 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 diff --git a/etherlink/bin_node/lib_dev/rpc_encodings.ml b/etherlink/bin_node/lib_dev/rpc_encodings.ml index e3fb013a46188a95ee2b65f63af32ede197c7bb0..a466cfd95730423d9c539c3ff37452afd0ce1444 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 c4887be4c2690a62212e2fca6b9c0865cd7a27d8..e3ccdf992c52eea698bb0dfd3dd4b003449f5c77 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 fbfe7c8a9f87caa13c7f1666c8af2879a2103bf3..c28f4beaeaab94cf8d847d4a9440a6f009912a54 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 3a5fc3d75d363960b2a974fc2ecaa6ebc56afc00..a69faca1e48bf29419c059b26aa4df4788b59589 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 diff --git a/etherlink/tezt/lib/rpc.ml b/etherlink/tezt/lib/rpc.ml index 2325bce425dcdf1954a90723e79a1a6d037bd6d6..418efc2a222a187593831d3e351248547a54d265 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 7a03789ca753a1bd4d40105092d884e72b663a09..b68df202f131775f743f1797d9138a27df5e8b88 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 6ba43aa16fbc7554ffc8ebdd973519399b12a89d..ed5ae96a3c50b3aa12e0a0b83395398e9420b701 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