diff --git a/etherlink/bin_node/lib_dev/encodings/ethereum_types.ml b/etherlink/bin_node/lib_dev/encodings/ethereum_types.ml index e8c40ab0554993e439981904f17235fa163b972a..085f6c022958e6bb02a1884deea0aed0a7dcc26e 100644 --- a/etherlink/bin_node/lib_dev/encodings/ethereum_types.ml +++ b/etherlink/bin_node/lib_dev/encodings/ethereum_types.ml @@ -143,6 +143,21 @@ module Chain_id = struct let decode_be bytes = Chain_id (decode_z_be bytes) end +type chain_family = EVM | Michelson + +module Chain_family = struct + let to_string = function EVM -> "EVM" | Michelson -> "Michelson" + + let of_string_exn s = + match String.lowercase_ascii s with + | "evm" -> EVM + | "michelson" -> Michelson + | _ -> invalid_arg "Chain_family.of_string" + + let encoding = + Data_encoding.string_enum [("EVM", EVM); ("Michelson", Michelson)] +end + type block_hash = Block_hash of hex [@@ocaml.unboxed] let pp_block_hash fmt (Block_hash (Hex h)) = Format.pp_print_string fmt h diff --git a/etherlink/bin_node/lib_dev/encodings/ethereum_types.mli b/etherlink/bin_node/lib_dev/encodings/ethereum_types.mli index 887610972d2ade8665222d47029fa502fc432b2c..d2d3a9d452c5f9ee20fcd22e122301ed6bbaa6cc 100644 --- a/etherlink/bin_node/lib_dev/encodings/ethereum_types.mli +++ b/etherlink/bin_node/lib_dev/encodings/ethereum_types.mli @@ -70,6 +70,20 @@ module Chain_id : sig val decode_be : bytes -> chain_id end +type chain_family = EVM | Michelson + +module Chain_family : sig + val encoding : chain_family Data_encoding.t + + (** [of_string_exn s] returns the chain family corresponding to the string [s]. + The comparison is case-insensitive, so ["Evm"], ["evm"], ["EVM"], etc. are all valid. + @raise Invalid_argument if [s] does not correspond to a recognized chain family. + *) + val of_string_exn : string -> chain_family + + val to_string : chain_family -> string +end + (** Ethereum block hash (32 bytes) *) type block_hash = Block_hash of hex [@@unboxed] diff --git a/etherlink/bin_node/lib_dev/kernel_config.ml b/etherlink/bin_node/lib_dev/kernel_config.ml index c070a0e5902eea3892b8155c7e6fbc613ff59457..6edeb50cb087cc3b710690f15a33b4fb634850a2 100644 --- a/etherlink/bin_node/lib_dev/kernel_config.ml +++ b/etherlink/bin_node/lib_dev/kernel_config.ml @@ -48,7 +48,8 @@ let clean_path path = let make_l2 ~boostrap_balance ?bootstrap_accounts ?minimum_base_fee_per_gas ?da_fee_per_byte ?sequencer_pool_address ?maximum_gas_per_transaction - ?set_account_code ?world_state_path ~l2_chain_id ~output () = + ?set_account_code ?world_state_path ~l2_chain_id ~l2_chain_family ~output () + = let world_state_prefix = match world_state_path with | None -> ["evm"; "world_state"; l2_chain_id] @@ -95,6 +96,11 @@ let make_l2 ~boostrap_balance ?bootstrap_accounts ?minimum_base_fee_per_gas ~l2_chain_id ~convert:le_int64_bytes maximum_gas_per_transaction + @ make_l2_config_instr + ~l2_chain_id + (Some + ( "chain_family", + l2_chain_family |> Ethereum_types.Chain_family.to_string )) @ make_l2_config_instr ~l2_chain_id world_state_path in let world_state_instrs = diff --git a/etherlink/bin_node/lib_dev/kernel_config.mli b/etherlink/bin_node/lib_dev/kernel_config.mli index ae656139d910317e7b69c6f182408b2a9f2573b7..49684d5484245bcc4049de6274d29178b0c4b9bd 100644 --- a/etherlink/bin_node/lib_dev/kernel_config.mli +++ b/etherlink/bin_node/lib_dev/kernel_config.mli @@ -43,7 +43,7 @@ val make : unit tzresult Lwt.t (** [make_l2 ~boostrap_balance ?bootstrap_accounts ... ~l2_chain_id ~output ()] - generates a configuration file located at [output] for the chain [l2_chain_id], + generates a configuration file located at [output] for the chain [l2_chain_id], where [bootstrap_accounts] are provisioned with [bootstrap_balance]. *) val make_l2 : boostrap_balance:Z.t -> @@ -55,6 +55,7 @@ val make_l2 : ?set_account_code:(string * string) list -> ?world_state_path:string * string -> l2_chain_id:string -> + l2_chain_family:Ethereum_types.chain_family -> output:string -> unit -> unit tzresult Lwt.t diff --git a/etherlink/bin_node/main.ml b/etherlink/bin_node/main.ml index a20be2d532d74c8fb2828a634244d8614d8ce9e7..a903d32bf1815405778419334bd9b25fe7b232d1 100644 --- a/etherlink/bin_node/main.ml +++ b/etherlink/bin_node/main.ml @@ -1858,7 +1858,7 @@ let make_l2_kernel_config_command = ~desc: "Produce a file containing the part of the kernel configuration \ instructions related to a particular L2 chain." - (args9 + (args10 (config_key_arg ~name:"minimum_base_fee_per_gas" ~placeholder:"111...") (config_key_arg ~name:"da_fee_per_byte" ~placeholder:"111...") (config_key_arg ~name:"sequencer_pool_address" ~placeholder:"0x...") @@ -1880,7 +1880,14 @@ let make_l2_kernel_config_command = ~long:"l2-chain-id" ~doc:"L2 chain id" ~placeholder:"1" - (Tezos_clic.parameter (fun _ s -> return @@ Chain_id.of_string_exn s)))) + (Tezos_clic.parameter (fun _ s -> return @@ Chain_id.of_string_exn s))) + (Tezos_clic.default_arg + ~long:"l2-chain-family" + ~doc:"Configure the family (either EVM or Michelson) of the L2 chain." + ~default:"EVM" + ~placeholder:"EVM" + (Tezos_clic.parameter (fun _ s -> + return @@ Chain_family.of_string_exn s)))) (prefixes ["make"; "l2"; "kernel"; "installer"; "config"] @@ param ~name:"kernel config file" @@ -1895,7 +1902,8 @@ let make_l2_kernel_config_command = bootstrap_accounts, set_account_code, world_state_path, - l2_chain_id ) + l2_chain_id, + l2_chain_family ) output () -> let* l2_chain_id = @@ -1916,6 +1924,7 @@ let make_l2_kernel_config_command = ?set_account_code ?world_state_path ~l2_chain_id + ~l2_chain_family ~output ()) diff --git a/etherlink/tezt/lib/evm_node.ml b/etherlink/tezt/lib/evm_node.ml index c558077704fde3850641e81c748bfd975ae4f5d5..6782c628b86e20368ca22416fbb0a2c8927001bb 100644 --- a/etherlink/tezt/lib/evm_node.ml +++ b/etherlink/tezt/lib/evm_node.ml @@ -1684,7 +1684,7 @@ let make_kernel_installer_config ?max_delayed_inbox_blueprint_length let process = Process.spawn (Uses.path Constant.octez_evm_node) cmd in Runnable.{value = process; run = Process.check} -let make_l2_kernel_installer_config ?chain_id ?bootstrap_balance +let make_l2_kernel_installer_config ?chain_id ?chain_family ?bootstrap_balance ?bootstrap_accounts ?minimum_base_fee_per_gas ?(da_fee_per_byte = Wei.zero) ?sequencer_pool_address ?maximum_gas_per_transaction ?(set_account_code = []) ?world_state_path ~output () = @@ -1698,6 +1698,7 @@ let make_l2_kernel_installer_config ?chain_id ?bootstrap_balance let cmd = ["make"; "l2"; "kernel"; "installer"; "config"; output] @ Cli_arg.optional_arg "l2-chain-id" string_of_int chain_id + @ Cli_arg.optional_arg "l2-chain-family" Fun.id chain_family @ Cli_arg.optional_arg "minimum-base-fee-per-gas" Wei.to_string diff --git a/etherlink/tezt/lib/evm_node.mli b/etherlink/tezt/lib/evm_node.mli index af41ac4ee0ad72485d1db07f4bb13141e0b3e6af..05d1afd45cefc3d108857cf21ec3f87a2f742ae4 100644 --- a/etherlink/tezt/lib/evm_node.mli +++ b/etherlink/tezt/lib/evm_node.mli @@ -561,10 +561,11 @@ val snapshot_info : snapshot_file:string -> (Process.t, string) runnable val wait_termination : t -> unit Lwt.t -(** [make_l2_kernel_installer_config ~output ()] create the config needed for - a l2 chain in a multichain kernel *) +(** [make_l2_kernel_installer_config ~output ()] creates the config needed for + an l2 chain in a multichain kernel *) val make_l2_kernel_installer_config : ?chain_id:int -> + ?chain_family:string -> ?bootstrap_balance:Wei.t -> ?bootstrap_accounts:string list -> ?minimum_base_fee_per_gas:Wei.t -> diff --git a/etherlink/tezt/tests/evm_sequencer.ml b/etherlink/tezt/tests/evm_sequencer.ml index 63aa8f5814c57c7272db57ad9865d01904fff757..5dd7bc6c149f8dced6674430eb74defa802dc759 100644 --- a/etherlink/tezt/tests/evm_sequencer.ml +++ b/etherlink/tezt/tests/evm_sequencer.ml @@ -348,12 +348,14 @@ let register_upgrade_all ~title ~tags ~genesis_timestamp protocols) kernels -let test_make_l2_kernel_installer_config = +let test_make_l2_kernel_installer_config chain_family = Protocol.register_test ~__FILE__ ~title: - "Test that the command make_l2_kernel_installer setup bootstrap account \ - at the right path" + (Printf.sprintf + "Test that the command make_l2_kernel_installer setup bootstrap \ + account at the right path with %s family" + chain_family) ~tags:["evm"; "multichain"; "installer"] ~uses_admin_client:true ~uses_client:true @@ -381,6 +383,7 @@ let test_make_l2_kernel_installer_config = let*! () = Evm_node.make_l2_kernel_installer_config ~chain_id + ~chain_family ~world_state_path ~bootstrap_accounts:[address] ~output:l2_config @@ -450,6 +453,25 @@ let test_make_l2_kernel_installer_config = 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) + ~error_msg:"Expected chain_family to be %R, got %L" ; + (* Verify that the balance of the bootstrap account is set by the command `make_l2_kernel_installer_config` *) let address_in_durable = Helpers.remove_0x (String.lowercase_ascii address) in @@ -10263,7 +10285,8 @@ let () = test_miner protocols ; test_fa_bridge_feature_flag protocols ; test_multichain_feature_flag protocols ; - test_make_l2_kernel_installer_config protocols ; + test_make_l2_kernel_installer_config "EVM" protocols ; + test_make_l2_kernel_installer_config "Michelson" protocols ; test_fast_withdrawal_feature_flag protocols ; test_trace_call protocols ; test_trace_empty_block protocols ; diff --git a/etherlink/tezt/tests/expected/evm_sequencer.ml/EVM Node- man.out b/etherlink/tezt/tests/expected/evm_sequencer.ml/EVM Node- man.out index 5b89e52759f3df3137dec447f7d8476ed2e0c25b..53519429c6f4c507400247b29113878240878697 100644 --- a/etherlink/tezt/tests/expected/evm_sequencer.ml/EVM Node- man.out +++ b/etherlink/tezt/tests/expected/evm_sequencer.ml/EVM Node- man.out @@ -518,7 +518,7 @@ Miscellaneous commands: [--bootstrap-account <0x...>] [--set-code <0x...,0x....>] [--world-state-path >] - [--l2-chain-id <1>] + [--l2-chain-id <1>] [--l2-chain-family ] Produce a file containing the part of the kernel configuration instructions related to a particular L2 chain. : file path where the config will be written to --minimum-base-fee-per-gas <111...>: value for minimum_base_fee_per_gas in the installer config @@ -530,6 +530,7 @@ Miscellaneous commands: --set-code <0x...,0x....>: add code to an account in the installer config. --world-state-path >: value for world_state_path in the installer config --l2-chain-id <1>: L2 chain id + --l2-chain-family : Configure the family (either EVM or Michelson) of the L2 chain. octez-evm-node patch state at with [--data-dir ] [--block-number ] [-f --force]