diff --git a/etherlink/bin_node/lib_dev/observer.ml b/etherlink/bin_node/lib_dev/observer.ml index e26bf8fb64794da59bdcbdd1dccb4b48f91f7e12..b4faabd2aa061f329600d76a3ad7ffe0c1edf31f 100644 --- a/etherlink/bin_node/lib_dev/observer.ml +++ b/etherlink/bin_node/lib_dev/observer.ml @@ -206,18 +206,22 @@ let main ?network ?kernel_path ~data_dir ~(config : Configuration.t) ~no_sync init_from_snapshot in - let tx_container, ping_tx_pool = + let start_tx_container, tx_container, ping_tx_pool = match config.experimental_features.enable_tx_queue with - | Some _tx_queue_config -> (Tx_queue.tx_container, false) + | Some tx_queue_config -> + let start, tx_container = Tx_queue.tx_container ~chain_family:EVM in + ( (fun ~tx_pool_parameters:_ -> + start ~config:tx_queue_config ~keep_alive:config.keep_alive ()), + tx_container, + false ) | None -> if config.finalized_view then - let tx_container = + ( (fun ~tx_pool_parameters:_ -> return_unit), container_forward_tx ~keep_alive:config.keep_alive - ~evm_node_endpoint - in - (tx_container, false) - else (Tx_pool.tx_container, true) + ~evm_node_endpoint, + false ) + else (Tx_pool.start, Tx_pool.tx_container, true) in let* _loaded = @@ -253,25 +257,20 @@ let main ?network ?kernel_path ~data_dir ~(config : Configuration.t) ~no_sync in let* () = - match config.experimental_features.enable_tx_queue with - | Some tx_queue_config -> - Tx_queue.start ~config:tx_queue_config ~keep_alive:config.keep_alive () - | None -> - if config.finalized_view then return_unit - else - Tx_pool.start - { - backend = observer_backend; - smart_rollup_address = - Tezos_crypto.Hashed.Smart_rollup_address.to_b58check - smart_rollup_address; - mode = Relay; - tx_timeout_limit = config.tx_pool_timeout_limit; - tx_pool_addr_limit = Int64.to_int config.tx_pool_addr_limit; - tx_pool_tx_per_addr_limit = - Int64.to_int config.tx_pool_tx_per_addr_limit; - chain_family = Ex_chain_family chain_family; - } + start_tx_container + ~tx_pool_parameters: + { + backend = observer_backend; + smart_rollup_address = + Tezos_crypto.Hashed.Smart_rollup_address.to_b58check + smart_rollup_address; + mode = Relay; + tx_timeout_limit = config.tx_pool_timeout_limit; + tx_pool_addr_limit = Int64.to_int config.tx_pool_addr_limit; + tx_pool_tx_per_addr_limit = + Int64.to_int config.tx_pool_tx_per_addr_limit; + chain_family = Ex_chain_family chain_family; + } in Metrics.init diff --git a/etherlink/bin_node/lib_dev/proxy.ml b/etherlink/bin_node/lib_dev/proxy.ml index f6a7354ac719c37172db4e14663a0dde4db1cf2d..19bab2ce033456b20b86db79c9a50a0e8b08c9fe 100644 --- a/etherlink/bin_node/lib_dev/proxy.ml +++ b/etherlink/bin_node/lib_dev/proxy.ml @@ -188,13 +188,10 @@ let main config.experimental_features.enable_tx_queue ) with | true, None, Some tx_queue_config -> + let start, tx_container = Tx_queue.tx_container ~chain_family:EVM in let* () = - Tx_queue.start - ~config:tx_queue_config - ~keep_alive:config.keep_alive - () + start ~config:tx_queue_config ~keep_alive:config.keep_alive () in - let tx_container = Tx_queue.tx_container in return @@ ( Some (fun () -> @@ -206,16 +203,17 @@ let main | true, None, None -> let* () = Tx_pool.start - { - backend = (module Rollup_node_rpc); - smart_rollup_address; - mode = Proxy; - tx_timeout_limit = config.tx_pool_timeout_limit; - tx_pool_addr_limit = Int64.to_int config.tx_pool_addr_limit; - tx_pool_tx_per_addr_limit = - Int64.to_int config.tx_pool_tx_per_addr_limit; - chain_family = Ex_chain_family chain_family; - } + ~tx_pool_parameters: + { + backend = (module Rollup_node_rpc); + smart_rollup_address; + mode = Proxy; + tx_timeout_limit = config.tx_pool_timeout_limit; + tx_pool_addr_limit = Int64.to_int config.tx_pool_addr_limit; + tx_pool_tx_per_addr_limit = + Int64.to_int config.tx_pool_tx_per_addr_limit; + chain_family = Ex_chain_family chain_family; + } in return (Some Tx_pool.pop_and_inject_transactions_lazy, Tx_pool.tx_container) diff --git a/etherlink/bin_node/lib_dev/rpc.ml b/etherlink/bin_node/lib_dev/rpc.ml index c10924dd36fe39d70c8cc4ab0fa5e6bf6608c252..cee90c95f3399946a4da9cd16b31dea00fc36e99 100644 --- a/etherlink/bin_node/lib_dev/rpc.ml +++ b/etherlink/bin_node/lib_dev/rpc.ml @@ -214,30 +214,32 @@ let main ~data_dir ~evm_node_endpoint ?evm_node_private_endpoint return (false, forward_request) | None, Some tx_queue_config -> + let start, tx_container = + Tx_queue.tx_container ~chain_family:L2_types.EVM + in let* () = - Tx_queue.start - ~config:tx_queue_config - ~keep_alive:config.keep_alive - () + start ~config:tx_queue_config ~keep_alive:config.keep_alive () in - return (false, Tx_queue.tx_container) + return (false, tx_container) | None, None -> + let tx_container = Tx_pool.tx_container in let* () = Tx_pool.start - { - backend = rpc_backend; - smart_rollup_address = - Tezos_crypto.Hashed.Smart_rollup_address.to_b58check - ctxt.smart_rollup_address; - mode = Relay; - tx_timeout_limit = config.tx_pool_timeout_limit; - tx_pool_addr_limit = Int64.to_int config.tx_pool_addr_limit; - tx_pool_tx_per_addr_limit = - Int64.to_int config.tx_pool_tx_per_addr_limit; - chain_family = Ex_chain_family chain_family; - } + ~tx_pool_parameters: + { + backend = rpc_backend; + smart_rollup_address = + Tezos_crypto.Hashed.Smart_rollup_address.to_b58check + ctxt.smart_rollup_address; + mode = Relay; + tx_timeout_limit = config.tx_pool_timeout_limit; + tx_pool_addr_limit = Int64.to_int config.tx_pool_addr_limit; + tx_pool_tx_per_addr_limit = + Int64.to_int config.tx_pool_tx_per_addr_limit; + chain_family = Ex_chain_family chain_family; + } in - return (true, Tx_pool.tx_container) + return (true, tx_container) in let* () = set_metrics_level ctxt in diff --git a/etherlink/bin_node/lib_dev/sequencer.ml b/etherlink/bin_node/lib_dev/sequencer.ml index 05f805f6d3caabcc63aacbaad39701b3c63237ba..a7bf86e30573f72244d1ed29fa579f3c05fb5238 100644 --- a/etherlink/bin_node/lib_dev/sequencer.ml +++ b/etherlink/bin_node/lib_dev/sequencer.ml @@ -181,10 +181,21 @@ let main ~data_dir ?(genesis_timestamp = Misc.now ()) ~cctxt init_from_snapshot | None -> Result.return_none in - let* tx_container = + (* The Tx_pool parameters are ignored by the start function when a + Tx_queue is configured. + + TODO: simplify start_tx_container when removing the Tx_pool. *) + let start_tx_container, tx_container = match configuration.experimental_features.enable_tx_queue with - | Some _tx_queue_config -> return Tx_queue.tx_container - | None -> return Tx_pool.tx_container + | Some tx_queue_config -> + let start, tx_container = Tx_queue.tx_container ~chain_family:EVM in + ( (fun ~tx_pool_parameters:_ -> + start + ~config:tx_queue_config + ~keep_alive:configuration.keep_alive + ()), + tx_container ) + | None -> (Tx_pool.start, Tx_pool.tx_container) in let (module Tx_container) = Services_backend_sig.tx_container_module tx_container @@ -338,24 +349,18 @@ let main ~data_dir ?(genesis_timestamp = Misc.now ()) ~cctxt Backend.single_chain_id_and_family ~config:configuration ~enable_multichain in let* () = - match configuration.experimental_features.enable_tx_queue with - | Some tx_queue_config -> - Tx_queue.start - ~config:tx_queue_config - ~keep_alive:configuration.keep_alive - () - | None -> - Tx_pool.start - { - backend; - smart_rollup_address = smart_rollup_address_b58; - mode = Sequencer; - tx_timeout_limit = configuration.tx_pool_timeout_limit; - tx_pool_addr_limit = Int64.to_int configuration.tx_pool_addr_limit; - tx_pool_tx_per_addr_limit = - Int64.to_int configuration.tx_pool_tx_per_addr_limit; - chain_family = Ex_chain_family chain_family; - } + start_tx_container + ~tx_pool_parameters: + { + backend; + smart_rollup_address = smart_rollup_address_b58; + mode = Sequencer; + tx_timeout_limit = configuration.tx_pool_timeout_limit; + tx_pool_addr_limit = Int64.to_int configuration.tx_pool_addr_limit; + tx_pool_tx_per_addr_limit = + Int64.to_int configuration.tx_pool_tx_per_addr_limit; + chain_family = Ex_chain_family chain_family; + } in Metrics.init ~mode:"sequencer" diff --git a/etherlink/bin_node/lib_dev/services.ml b/etherlink/bin_node/lib_dev/services.ml index 311bd6fe8bb5a70865fcaffe1efbd6af4d3500d7..7f9cb2249f209d70e729e90d5b5fe7d4d6d7e39b 100644 --- a/etherlink/bin_node/lib_dev/services.ml +++ b/etherlink/bin_node/lib_dev/services.ml @@ -1429,9 +1429,8 @@ let dispatch_websocket_private (type f) "/private/ws" (dispatch_private_websocket rpc_server_family ~block_production rpc) -let directory (type f) ~rpc_server_family ?delegate_health_check_to rpc - validation config (tx_container : f Services_backend_sig.tx_container) - backend dir = +let directory ~rpc_server_family ?delegate_health_check_to rpc validation config + (tx_container : _ Services_backend_sig.tx_container) backend dir = dir |> version |> configuration config |> health_check ?delegate_to:delegate_health_check_to |> dispatch_public @@ -1449,8 +1448,8 @@ let directory (type f) ~rpc_server_family ?delegate_health_check_to rpc tx_container backend -let private_directory (type f) ~rpc_server_family rpc config - (tx_container : f Services_backend_sig.tx_container) backend +let private_directory ~rpc_server_family rpc config + (tx_container : _ Services_backend_sig.tx_container) backend ~block_production = Evm_directory.empty config.experimental_features.rpc_server |> version diff --git a/etherlink/bin_node/lib_dev/tezlink/tezos_types.ml b/etherlink/bin_node/lib_dev/tezlink/tezos_types.ml index 44cf253e998abbd773b1f56e45054799d4701346..49b5e26be5c04361912cfa7773290935d63fc146 100644 --- a/etherlink/bin_node/lib_dev/tezlink/tezos_types.ml +++ b/etherlink/bin_node/lib_dev/tezlink/tezos_types.ml @@ -59,6 +59,22 @@ module Contract = struct @@ Tezlink_imports.Alpha_context.Contract.of_b58check s end +module Operation = struct + module ImportedOperation = Tezlink_imports.Alpha_context.Operation + + type t = { + source : Signature.V1.public_key_hash; + counter : Z.t; + op : Tezlink_imports.Alpha_context.packed_operation; + raw : bytes; + } + + let hash_operation {source = _; counter = _; op; raw = _} = + let hash = ImportedOperation.hash_packed op in + let (`Hex hex) = Operation_hash.to_hex hash in + Ethereum_types.Hash (Ethereum_types.Hex hex) +end + module Tez = struct include Tezlink_imports.Alpha_context.Tez diff --git a/etherlink/bin_node/lib_dev/tezlink/tezos_types.mli b/etherlink/bin_node/lib_dev/tezlink/tezos_types.mli index 0f9e836bddfb8f9b125059e4d4a1d0cfad9d988a..2e0ca089f0c3b5d356721fd36c89ee4304dd0658 100644 --- a/etherlink/bin_node/lib_dev/tezlink/tezos_types.mli +++ b/etherlink/bin_node/lib_dev/tezlink/tezos_types.mli @@ -44,6 +44,17 @@ module Contract : sig val of_implicit : Signature.V1.public_key_hash -> t end +module Operation : sig + type t = { + source : Signature.V1.public_key_hash; + counter : Z.t; + op : Tezlink_imports.Alpha_context.packed_operation; + raw : bytes; + } + + val hash_operation : t -> Ethereum_types.hash +end + module Tez : sig include module type of Tezlink_imports.Alpha_context.Tez diff --git a/etherlink/bin_node/lib_dev/tx_pool.ml b/etherlink/bin_node/lib_dev/tx_pool.ml index c9d8deaa607738ae5bc51a16a347e486326be006..d1eac3019ccc62e33ea9e7337aa2468938ed6e18 100644 --- a/etherlink/bin_node/lib_dev/tx_pool.ml +++ b/etherlink/bin_node/lib_dev/tx_pool.ml @@ -803,9 +803,9 @@ let handle_request_error rq = | Error (Closed (Some errs)) -> Lwt.return_error errs | Error (Any exn) -> Lwt.return_error [Exn exn] -let start parameters = +let start ~tx_pool_parameters = let open Lwt_result_syntax in - let+ worker = Worker.launch table () parameters (module Handlers) in + let+ worker = Worker.launch table () tx_pool_parameters (module Handlers) in Lwt.wakeup worker_waker worker let add transaction_object raw_tx = diff --git a/etherlink/bin_node/lib_dev/tx_pool.mli b/etherlink/bin_node/lib_dev/tx_pool.mli index 3d8fc89ced37e40fe048f8359998605d3edc954d..d84a76baad61fd67e332fae02d4b5a320d90ec4f 100644 --- a/etherlink/bin_node/lib_dev/tx_pool.mli +++ b/etherlink/bin_node/lib_dev/tx_pool.mli @@ -24,7 +24,7 @@ type parameters = { } (** [start parameters] starts the tx-pool *) -val start : parameters -> unit tzresult Lwt.t +val start : tx_pool_parameters:parameters -> unit tzresult Lwt.t (** [pop_transactions chain_family maximum_cumulative_size] pops as much valid transactions as possible from the pool, until their cumulative diff --git a/etherlink/bin_node/lib_dev/tx_queue.ml b/etherlink/bin_node/lib_dev/tx_queue.ml index d672117f1bd4366b2cc4c857167911d02284778d..43bf1224797b529e0494ff6ee9ef3ec74f39d160 100644 --- a/etherlink/bin_node/lib_dev/tx_queue.ml +++ b/etherlink/bin_node/lib_dev/tx_queue.ml @@ -1209,10 +1209,23 @@ module Eth_tx_container = let chain_name = "etherlink" end) -let start = Eth_tx_container.start +module Tezlink_tx_container = + Tx_container + (Tx_queue_types.Tezlink_operation) + (struct + let chain_name = "tezlink" + end) -let tx_container = - Services_backend_sig.Evm_tx_container (module Eth_tx_container) +let tx_container (type f) ~(chain_family : f L2_types.chain_family) : + _ * f Services_backend_sig.tx_container = + match chain_family with + | EVM -> + ( Eth_tx_container.start, + Services_backend_sig.Evm_tx_container (module Eth_tx_container) ) + | Michelson -> + ( Tezlink_tx_container.start, + Services_backend_sig.Michelson_tx_container + (module Tezlink_tx_container) ) module Internal_for_tests = struct module Nonce_bitset = Nonce_bitset diff --git a/etherlink/bin_node/lib_dev/tx_queue.mli b/etherlink/bin_node/lib_dev/tx_queue.mli index 1c3f7a149460f52cd35a5882b3451ed9b49329c5..d6290bac58f7ba23daeb7079373352f43664efd4 100644 --- a/etherlink/bin_node/lib_dev/tx_queue.mli +++ b/etherlink/bin_node/lib_dev/tx_queue.mli @@ -24,18 +24,18 @@ [callback] is called with [`Dropped].}} *) type callback = [`Accepted | `Confirmed | `Dropped | `Refused] -> unit Lwt.t -(** [start ~config ~max_transaction_batch_length ()] starts the +(** [tx_container ~chain_family] is a pair [(start, container)] where + [start ~config ~max_transaction_batch_length ()] starts the worker, meaning it is possible to call {!inject}, {!confirm} and - {!beacon}. *) -val start : - config:Configuration.tx_queue -> + {!beacon} and [container] is a wrapper of the Tx_queue to be + compatible with the Tx_container signature for the services. *) +val tx_container : + chain_family:'f L2_types.chain_family -> + (config:Configuration.tx_queue -> keep_alive:bool -> unit -> - unit tzresult Lwt.t - -(** wrapper of the Tx_queue to be compatible with the Tx_container - signature for the services. *) -val tx_container : L2_types.evm_chain_family Services_backend_sig.tx_container + unit tzresult Lwt.t) + * 'f Services_backend_sig.tx_container (**/*) diff --git a/etherlink/bin_node/lib_dev/tx_queue_types.ml b/etherlink/bin_node/lib_dev/tx_queue_types.ml index bc3d418a8e3023ed55ecf0e49d5b77bd0816e270..0bb6bc9190bd1818f836faa53c6ac99bffe8f9e2 100644 --- a/etherlink/bin_node/lib_dev/tx_queue_types.ml +++ b/etherlink/bin_node/lib_dev/tx_queue_types.ml @@ -65,3 +65,37 @@ module Eth_transaction_object : let make_txpool ~pending ~queued = {pending; queued} end + +module Tezlink_operation : + L2_transaction + with type t = Tezos_types.Operation.t + and type legacy = Tezos_types.Operation.t = struct + open Ethereum_types + + type t = Tezos_types.Operation.t + + type legacy = Tezos_types.Operation.t + + type address = Signature.V1.public_key_hash + + let address_encoding = Signature.V1.Public_key_hash.encoding + + let hash_of_tx_object = Tezos_types.Operation.hash_operation + + let address_to_string = Signature.V1.Public_key_hash.to_string + + let from_address_of_tx_object (op : Tezos_types.Operation.t) = op.source + + let nonce_of_tx_object (op : Tezos_types.Operation.t) = + Ethereum_types.Qty op.counter + + let transaction_object_from_legacy op = op + + module AddressMap = Map.Make (Signature.V1.Public_key_hash) + + let make_txpool ~pending:_ ~queued:_ = + { + pending = Ethereum_types.AddressMap.empty; + queued = Ethereum_types.AddressMap.empty; + } +end diff --git a/etherlink/bin_node/lib_dev/tx_queue_types.mli b/etherlink/bin_node/lib_dev/tx_queue_types.mli index d00734a2e4d263d0cefc23f32f22dc7594b24c77..a9fd58b1804cc80b2753383fa975ce7fe76cc6f4 100644 --- a/etherlink/bin_node/lib_dev/tx_queue_types.mli +++ b/etherlink/bin_node/lib_dev/tx_queue_types.mli @@ -38,3 +38,6 @@ module Eth_transaction_object : and type legacy = Ethereum_types.legacy_transaction_object and type address = Ethereum_types.address and module AddressMap = Ethereum_types.AddressMap + +module Tezlink_operation : + L2_transaction with type legacy = Tezos_types.Operation.t diff --git a/etherlink/bin_node/main.ml b/etherlink/bin_node/main.ml index b0899e1e2229ee52deaef98999370cecde0af692..661130567c6f58ffe93b1302ccb7413f39c06a9b 100644 --- a/etherlink/bin_node/main.ml +++ b/etherlink/bin_node/main.ml @@ -1582,12 +1582,15 @@ let init_from_rollup_node_command = let config_file = config_filename ~data_dir config_file in let* configuration = Cli.create_or_read_config ~data_dir config_file in let*! () = init_logs ~daily_logs:false ~data_dir configuration in + let _start_tx_queue, tx_container = + Evm_node_lib_dev.Tx_queue.tx_container ~chain_family:EVM + in Evm_node_lib_dev.Evm_context.init_from_rollup_node ~configuration ~omit_delayed_tx_events ~data_dir ~rollup_node_data_dir - ~tx_container:Evm_node_lib_dev.Tx_queue.tx_container + ~tx_container ()) let dump_to_rlp_command = @@ -1797,12 +1800,15 @@ let patch_kernel_command = to interact with an upstream EVM node. *) let configuration = {configuration with observer = None} in if force then + let _start_tx_queue, tx_container = + Evm_node_lib_dev.Tx_queue.tx_container ~chain_family:EVM + in let* _status = Evm_context.start ~configuration ~data_dir ~store_perm:Read_write - ~tx_container:Evm_node_lib_dev.Tx_queue.tx_container + ~tx_container () in Evm_context.patch_kernel ?block_number (On_disk kernel_path) @@ -3058,12 +3064,15 @@ let patch_state_command = (* We remove the [observer] configuration. This [patch] should not need to interact with an upstream EVM node. *) let configuration = {configuration with observer = None} in + let _start_tx_queue, tx_container = + Evm_node_lib_dev.Tx_queue.tx_container ~chain_family:EVM + in let* _status = Evm_context.start ~configuration ~data_dir ~store_perm:Read_write - ~tx_container:Evm_node_lib_dev.Tx_queue.tx_container + ~tx_container () in Evm_context.patch_state ?block_number ~key ~value () diff --git a/etherlink/fa-bridge-watchtower/etherlink_monitor.ml b/etherlink/fa-bridge-watchtower/etherlink_monitor.ml index c79456f673dc87a3e10a49ced9fb3765d06aaac0..27989d1876c18c5a0dd0408c58b365d6229f841a 100644 --- a/etherlink/fa-bridge-watchtower/etherlink_monitor.ml +++ b/etherlink/fa-bridge-watchtower/etherlink_monitor.ml @@ -54,7 +54,8 @@ end module Tx_queue = struct include Tx_queue - let (Services_backend_sig.Evm_tx_container tx_container) = tx_container + let start, Services_backend_sig.Evm_tx_container tx_container = + tx_container ~chain_family:EVM let ( let**? ) v f = let open Lwt_result_syntax in