diff --git a/etherlink/bin_floodgate/craft.ml b/etherlink/bin_floodgate/craft.ml index 196bdeca5c27645e6c790ca8a00b48f48f5fd00f..3e8d366aafba003bb44af1ff8c3b6eb597e85193 100644 --- a/etherlink/bin_floodgate/craft.ml +++ b/etherlink/bin_floodgate/craft.ml @@ -34,7 +34,7 @@ let prepare_and_forge_tx ?to_ ?data ~gas_limit ~base_fee_per_gas ~chain_id let transfer ?nonce ?to_ ?data ~value ~gas_limit ~infos ~from () = let nonce = Option.value nonce ~default:from.Account.nonce |> Z.to_int in - let (Ethereum_types.Qty chain_id) = infos.Network_info.chain_id in + let (Ethereum_types.Chain_id chain_id) = infos.Network_info.chain_id in let txn = prepare_and_forge_tx ?to_ diff --git a/etherlink/bin_floodgate/dune b/etherlink/bin_floodgate/dune index aa562c93030fffe0dcd6f2bef1041c39970f2ccc..260775957c6c2e2c95236518227470d41749c702 100644 --- a/etherlink/bin_floodgate/dune +++ b/etherlink/bin_floodgate/dune @@ -16,6 +16,7 @@ octez-libs.clic octez-evm-node-libs.evm_node_lib_dev octez-evm-node-libs.evm_node_lib_dev_encoding + octez-evm-node-libs.evm_node_config octez-libs.tezos-workers) (link_flags (:standard) @@ -24,4 +25,5 @@ (:standard) -open Tezos_base.TzPervasives -open Evm_node_lib_dev - -open Evm_node_lib_dev_encoding)) + -open Evm_node_lib_dev_encoding + -open Evm_node_config)) diff --git a/etherlink/bin_floodgate/floodgate_events.ml b/etherlink/bin_floodgate/floodgate_events.ml index 55c8a06a34dd725747c1fdcb5ab7a3921f02cf36..af09740786dd9e2a61fa865a4698e41e4d209226 100644 --- a/etherlink/bin_floodgate/floodgate_events.ml +++ b/etherlink/bin_floodgate/floodgate_events.ml @@ -28,7 +28,7 @@ let is_ready = {base_fee_per_gas})" ~level:Notice ~pp2:pp_eth - ("chain_id", Ethereum_types.quantity_encoding) + ("chain_id", Ethereum_types.Chain_id.encoding) ("base_fee_per_gas", Data_encoding.n) let tx_queue_is_ready = diff --git a/etherlink/bin_floodgate/floodgate_events.mli b/etherlink/bin_floodgate/floodgate_events.mli index d549431db907cddc7e94b56c0704530a7fb210f1..97bec6f33e0563b81d8e1c30024a6917a18b4b35 100644 --- a/etherlink/bin_floodgate/floodgate_events.mli +++ b/etherlink/bin_floodgate/floodgate_events.mli @@ -8,7 +8,7 @@ (** [is_ready chain_id base_fee_per_gas] advertises that Floodgate has started and is ready to spam. *) -val is_ready : Ethereum_types.quantity -> Z.t -> unit Lwt.t +val is_ready : Ethereum_types.chain_id -> Z.t -> unit Lwt.t (** [tx_queue_is_ready ()] advertises that the [Tx_queue] is ready to receive transactions. *) @@ -48,11 +48,11 @@ val reimbursed_controller : Account.t -> unit Lwt.t has been funded and is now used to spam the Etherlink network. *) val setup_completed : unit -> unit Lwt.t -(** [injecting_transactions nb] advertises [nb] transactions are about to be +(** [injecting_transactions nb] advertises [nb] transactions are about to be injected to the relay endpoint with a batch of [eth_sendRawTransaction]. *) val injecting_transactions : int -> unit Lwt.t -(** [deploy_erc20 address] advertises an ERC20 contract as been deployed at +(** [deploy_erc20 address] advertises an ERC20 contract as been deployed at address [address]. *) val deploy_erc20 : string -> unit Lwt.t diff --git a/etherlink/bin_floodgate/network_info.ml b/etherlink/bin_floodgate/network_info.ml index 334c4c78862cb09c8fcd01db3f21178fe4b2c269..728004ad16fa654e48bba6446b280204c825b20c 100644 --- a/etherlink/bin_floodgate/network_info.ml +++ b/etherlink/bin_floodgate/network_info.ml @@ -6,7 +6,7 @@ (* *) (*****************************************************************************) -type t = {chain_id : Ethereum_types.quantity; base_fee_per_gas : Z.t} +type t = {chain_id : Ethereum_types.chain_id; base_fee_per_gas : Z.t} let get_chain_id ~evm_node_endpoint = let open Lwt_result_syntax in @@ -17,8 +17,9 @@ let get_chain_id ~evm_node_endpoint = ~evm_node_endpoint () in + let mainnet_chain_id = Configuration.chain_id Mainnet in let* () = - when_ (chain_id = Constants.chain_id Mainnet) @@ fun () -> + when_ (chain_id = mainnet_chain_id) @@ fun () -> Lwt_result.ok (Floodgate_events.mainnet_experiment ()) in return chain_id diff --git a/etherlink/bin_floodgate/network_info.mli b/etherlink/bin_floodgate/network_info.mli index 3c3e7e7cab50f75bb052835157975d5b87ea4fdc..87c921633fc234e1fe61208da490d194ff495503 100644 --- a/etherlink/bin_floodgate/network_info.mli +++ b/etherlink/bin_floodgate/network_info.mli @@ -6,7 +6,7 @@ (* *) (*****************************************************************************) -type t = {chain_id : Ethereum_types.quantity; base_fee_per_gas : Z.t} +type t = {chain_id : Ethereum_types.chain_id; base_fee_per_gas : Z.t} val fetch : rpc_endpoint:Uri.t -> base_fee_factor:float -> t tzresult Lwt.t diff --git a/etherlink/bin_node/config/configuration.ml b/etherlink/bin_node/config/configuration.ml index 8303988938cf7cf8c0f80212b6a07c4f2f0391ed..718e482e4e21ac7470ef9c169582287e9abfec0b 100644 --- a/etherlink/bin_node/config/configuration.ml +++ b/etherlink/bin_node/config/configuration.ml @@ -57,6 +57,11 @@ let chain_id network = Ethereum_types.Chain_id (Z.of_int (match network with Mainnet -> 0xa729 | Testnet -> 0x1f47b)) +let chain_id_encoding : Ethereum_types.chain_id Data_encoding.t = + let open Ethereum_types in + let open Data_encoding in + conv (fun (Chain_id z) -> z) (fun z -> Chain_id z) z + type l2_chain = {chain_id : Ethereum_types.chain_id} type experimental_features = { @@ -822,13 +827,9 @@ let opt_monitor_websocket_heartbeat_encoding = let l2_chain_encoding : l2_chain Data_encoding.t = let open Data_encoding in - let open Evm_node_lib_dev_encoding in conv (fun {chain_id} -> chain_id) (fun chain_id -> {chain_id}) @@ obj1 - (req - "chain_id" - ~description:"The id of the l2 chain" - Ethereum_types.chain_id_encoding) + (req "chain_id" ~description:"The id of the l2 chain" chain_id_encoding) let experimental_features_encoding = let open Data_encoding in diff --git a/etherlink/bin_node/lib_dev/constants.ml b/etherlink/bin_node/lib_dev/constants.ml index c8021c0012419ccb8bdf9755e0cd9a010dfd39c3..000b2321e4870fd494935ece3e0dcac106cc4c58 100644 --- a/etherlink/bin_node/lib_dev/constants.ml +++ b/etherlink/bin_node/lib_dev/constants.ml @@ -11,9 +11,6 @@ let network_name = function | Configuration.Mainnet -> "Mainnet" | Testnet -> "Testnet" -let chain_id network = - match Configuration.chain_id network with Chain_id x -> Ethereum_types.Qty x - let rollup_address network = Tezos_crypto.Hashed.Smart_rollup_address.of_b58check_exn @@ diff --git a/etherlink/bin_node/lib_dev/constants.mli b/etherlink/bin_node/lib_dev/constants.mli index 9482f7d3be7d05958c3afe7f8dc1f22a35d7b651..b213e334d5737b2745be6413b143d9b5ce1f436f 100644 --- a/etherlink/bin_node/lib_dev/constants.mli +++ b/etherlink/bin_node/lib_dev/constants.mli @@ -14,6 +14,4 @@ val network_name : Configuration.supported_network -> string val rollup_address : Configuration.supported_network -> Tezos_crypto.Hashed.Smart_rollup_address.t -val chain_id : Configuration.supported_network -> Ethereum_types.quantity - val latest_snapshot_url : Configuration.supported_network -> string diff --git a/etherlink/bin_node/lib_dev/durable_storage.ml b/etherlink/bin_node/lib_dev/durable_storage.ml index a02cccb365bf42266d46f538c0d539896b312104..99441c94f461dedcbfc697c56bbdd68b1e2d95e5 100644 --- a/etherlink/bin_node/lib_dev/durable_storage.ml +++ b/etherlink/bin_node/lib_dev/durable_storage.ml @@ -271,7 +271,10 @@ let block_receipts read n = Lwt.return_ok receipts let chain_id read = - inspect_durable_and_decode read Durable_storage_path.chain_id decode_number_le + inspect_durable_and_decode + read + Durable_storage_path.chain_id + Chain_id.decode_le let base_fee_per_gas read = let open Lwt_result_syntax in diff --git a/etherlink/bin_node/lib_dev/encodings/ethereum_types.ml b/etherlink/bin_node/lib_dev/encodings/ethereum_types.ml index 500e3fa13741d43837e18bf6b6beee61689a259d..6ed70377acf1cd0b9e8a6c1026397817ac81623c 100644 --- a/etherlink/bin_node/lib_dev/encodings/ethereum_types.ml +++ b/etherlink/bin_node/lib_dev/encodings/ethereum_types.ml @@ -115,11 +115,29 @@ let quantity_encoding = let pp_quantity fmt (Qty q) = Z.pp_print fmt q -type chain_id = Chain_id of Z.t +let decode_z_le bytes = Bytes.to_string bytes |> Z.of_bits -let chain_id_encoding : chain_id Data_encoding.t = - let open Data_encoding in - conv (fun (Chain_id z) -> z) (fun z -> Chain_id z) z +let decode_z_be bytes = + Bytes.fold_left + (fun acc c -> + let open Z in + add (of_int (Char.code c)) (shift_left acc 8)) + Z.zero + bytes + +type chain_id = Chain_id of Z.t [@@ocaml.unboxed] + +module Chain_id = struct + let encoding = + Data_encoding.conv + (fun (Chain_id c) -> z_to_hexa c) + (fun c -> Chain_id (Z.of_string c)) + Data_encoding.string + + let decode_le bytes = Chain_id (decode_z_le bytes) + + let decode_be bytes = Chain_id (decode_z_be bytes) +end type block_hash = Block_hash of hex [@@ocaml.unboxed] @@ -254,16 +272,9 @@ let decode_address bytes = Address (decode_hex bytes) let encode_address (Address address) = encode_hex address -let decode_number_le bytes = Bytes.to_string bytes |> Z.of_bits |> quantity_of_z +let decode_number_le bytes = decode_z_le bytes |> quantity_of_z -let decode_number_be bytes = - Bytes.fold_left - (fun acc c -> - let open Z in - add (of_int (Char.code c)) (shift_left acc 8)) - Z.zero - bytes - |> quantity_of_z +let decode_number_be bytes = decode_z_be bytes |> quantity_of_z let decode_hash bytes = Hash (decode_hex bytes) diff --git a/etherlink/bin_node/lib_dev/encodings/ethereum_types.mli b/etherlink/bin_node/lib_dev/encodings/ethereum_types.mli index efaf47b67b9c3355c178732d0970fa5a6eefebd1..ed79c265fed2831b651784386e80bc3a04551d6f 100644 --- a/etherlink/bin_node/lib_dev/encodings/ethereum_types.mli +++ b/etherlink/bin_node/lib_dev/encodings/ethereum_types.mli @@ -53,9 +53,15 @@ val hex_of_utf8 : string -> hex (** [hex_of_bytes] transforms the [bytes] to hexadecimal. *) val hex_of_bytes : bytes -> hex -type chain_id = Chain_id of Z.t +type chain_id = Chain_id of Z.t [@@unboxed] -val chain_id_encoding : chain_id Data_encoding.t +module Chain_id : sig + val encoding : chain_id Data_encoding.t + + val decode_le : bytes -> chain_id + + val decode_be : bytes -> chain_id +end (** Ethereum block hash (32 bytes) *) type block_hash = Block_hash of hex [@@unboxed] diff --git a/etherlink/bin_node/lib_dev/encodings/transaction.ml b/etherlink/bin_node/lib_dev/encodings/transaction.ml index f6b1951d272fe62ed37ddc859c7952e821f0d252..9f0e3102072984bc6a3c8f477c3a228b94ec9c65 100644 --- a/etherlink/bin_node/lib_dev/encodings/transaction.ml +++ b/etherlink/bin_node/lib_dev/encodings/transaction.ml @@ -93,7 +93,7 @@ let decode_transaction ?chain_id ~tx_type ~nonce ~max_priority_fee_per_gas else if v = of_int 27 || v = of_int 28 then return None else fail "Chain ID cannot be decoded" | Some chain_id -> - let (Qty chain_id) = decode_number_be chain_id in + let (Chain_id chain_id) = Chain_id.decode_be chain_id in return (Some chain_id) in return diff --git a/etherlink/bin_node/lib_dev/evm_ro_context.ml b/etherlink/bin_node/lib_dev/evm_ro_context.ml index a88fb2ae1a36d313a6e79511cf131b59f6b262fd..edd72db7012b88150ac3f7a73909d601d7f8bec6 100644 --- a/etherlink/bin_node/lib_dev/evm_ro_context.ml +++ b/etherlink/bin_node/lib_dev/evm_ro_context.ml @@ -32,7 +32,7 @@ let read state path = let network_sanity_check ~network ctxt = let open Lwt_result_syntax in let expected_smart_rollup_address = Constants.rollup_address network in - let (Qty expected_chain_id) = Constants.chain_id network in + let (Chain_id expected_chain_id) = Configuration.chain_id network in let* _, hash = Evm_store.(use ctxt.store Context_hashes.get_latest) in let* evm_state = get_evm_state ctxt hash in @@ -40,7 +40,7 @@ let network_sanity_check ~network ctxt = let* () = match chain_id with - | Ok (Qty chain_id) -> + | Ok (Chain_id chain_id) -> unless Compare.Z.(chain_id = expected_chain_id) @@ fun () -> failwith "Local state is inconsistent with selected network %a: incorrect \ diff --git a/etherlink/bin_node/lib_dev/rpc_encodings.ml b/etherlink/bin_node/lib_dev/rpc_encodings.ml index 135f73e6b5701489aec250eb15ce79b34906d3c8..fd8d0f6c1f6834d8438b642ebe40c9bae14b15e1 100644 --- a/etherlink/bin_node/lib_dev/rpc_encodings.ml +++ b/etherlink/bin_node/lib_dev/rpc_encodings.ml @@ -224,11 +224,11 @@ end module Chain_id = struct type input = unit - type output = Ethereum_types.quantity + type output = Ethereum_types.chain_id let input_encoding = Data_encoding.unit - let output_encoding = Ethereum_types.quantity_encoding + let output_encoding = Ethereum_types.Chain_id.encoding let method_ = "eth_chainId" diff --git a/etherlink/bin_node/lib_dev/rpc_encodings.mli b/etherlink/bin_node/lib_dev/rpc_encodings.mli index d1679a2b137491825b0f4167214c573498d32fc8..2d776e218671f77bf2c6561eab481c92a48c5390 100644 --- a/etherlink/bin_node/lib_dev/rpc_encodings.mli +++ b/etherlink/bin_node/lib_dev/rpc_encodings.mli @@ -137,7 +137,7 @@ module Kernel_root_hash : 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.quantity + METHOD with type input = unit and type output = Ethereum_types.chain_id 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 534e490aa54b3e185c6b5b809c6a8ff3c8ace8ea..0306337638dbdcc8484561c6436619c7e88490e7 100644 --- a/etherlink/bin_node/lib_dev/services.ml +++ b/etherlink/bin_node/lib_dev/services.ml @@ -442,11 +442,11 @@ let dispatch_request (rpc : Configuration.rpc) (config : Configuration.t) | Network_id.Method -> let f (_ : unit option) = let open Lwt_result_syntax in - let* (Qty chain_id) = Backend_rpc.chain_id () in + let* (Chain_id chain_id) = Backend_rpc.chain_id () in rpc_ok (Z.to_string chain_id) in build ~f module_ parameters - | Chain_id.Method -> + | Rpc_encodings.Chain_id.Method -> let f (_ : unit option) = let* chain_id = Backend_rpc.chain_id () in rpc_ok chain_id diff --git a/etherlink/bin_node/lib_dev/services_backend_sig.ml b/etherlink/bin_node/lib_dev/services_backend_sig.ml index e70800767e17cd67f1575d2a4387b7bddcffe34d..3a5fc3d75d363960b2a974fc2ecaa6ebc56afc00 100644 --- a/etherlink/bin_node/lib_dev/services_backend_sig.ml +++ b/etherlink/bin_node/lib_dev/services_backend_sig.ml @@ -46,7 +46,7 @@ module type S = sig Ethereum_types.quantity tzresult Lwt.t (** [chain_id ()] returns chain id defined by the rollup. *) - val chain_id : unit -> Ethereum_types.quantity tzresult Lwt.t + val chain_id : unit -> Ethereum_types.chain_id 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/bin_node/lib_dev/validate.ml b/etherlink/bin_node/lib_dev/validate.ml index 6734e623b0084d6aca3842467ce03897e177ac91..d18009d1a350d536cb2746371c71f35a0c9ce464 100644 --- a/etherlink/bin_node/lib_dev/validate.ml +++ b/etherlink/bin_node/lib_dev/validate.ml @@ -24,7 +24,7 @@ let validate_chain_id (module Backend_rpc : Services_backend_sig.S) match transaction.chain_id with | None -> return (Ok ()) | Some transaction_chain_id -> - let* (Qty chain_id) = Backend_rpc.chain_id () in + let* (Chain_id chain_id) = Backend_rpc.chain_id () in if Z.equal transaction_chain_id chain_id then return (Ok ()) else return (Error "Invalid chain id") diff --git a/manifest/product_etherlink.ml b/manifest/product_etherlink.ml index f61b59277b228e54522613c78398a35f1972ffed..94f7bf2ec1041a5303211b6531600edf24b523fd 100644 --- a/manifest/product_etherlink.ml +++ b/manifest/product_etherlink.ml @@ -473,5 +473,6 @@ let _floodgate_bin = octez_clic; evm_node_lib_dev |> open_; evm_node_lib_dev_encoding |> open_; + evm_node_config |> open_; octez_workers; ]