From aec6d1f29ee0e9d78b0189d769bbbd1008984b05 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Fri, 9 Sep 2022 14:47:36 +0200 Subject: [PATCH 1/5] Tezt/Tx_rollup: parse tx rollup client output --- tezt/lib_tezos/tx_rollup_client.ml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tezt/lib_tezos/tx_rollup_client.ml b/tezt/lib_tezos/tx_rollup_client.ml index 16c20c47044d..77cef02012e9 100644 --- a/tezt/lib_tezos/tx_rollup_client.ml +++ b/tezt/lib_tezos/tx_rollup_client.ml @@ -199,7 +199,10 @@ let transfer ?counter tx_client ~source @ optional_arg "counter" Int64.to_string counter) |> Process.check_and_read_stdout in - Lwt.return out + out + =~* rex "Transaction hash: ?(\\w*)" + |> mandatory "transaction hash" + |> Lwt.return let withdraw ?counter tx_client ~source Rollup.Tx_rollup.(`Withdraw {qty; destination; ticket}) = @@ -211,7 +214,10 @@ let withdraw ?counter tx_client ~source @ optional_arg "counter" Int64.to_string counter) |> Process.check_and_read_stdout in - Lwt.return out + out + =~* rex "Transaction hash: ?(\\w*)" + |> mandatory "transaction hash" + |> Lwt.return let get_batcher_queue tx_client = let* out = -- GitLab From c609d225c4509818d82a97260c6375c11e944a0b Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Fri, 9 Sep 2022 09:49:57 +0200 Subject: [PATCH 2/5] Tezt/Test: faster injection of operations on TORU L2 --- tezt/tests/tx_rollup_l2_node.ml | 47 ++++++++++++++++----------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/tezt/tests/tx_rollup_l2_node.ml b/tezt/tests/tx_rollup_l2_node.ml index 1c77a03d42c0..3c7193c0daf7 100644 --- a/tezt/tests/tx_rollup_l2_node.ml +++ b/tezt/tests/tx_rollup_l2_node.ml @@ -1372,10 +1372,10 @@ let test_batcher ~test_persistence = bls_pkh_1 bls_pkh_2 ; let* txh1 = - craft_tx_and_inject + inject_transfer tx_client ~qty:1L - ~signer:bls_key_1 + ~source:bls_key_1.aggregate_alias ~dest:bls_pkh_2 ~ticket:ticket_id in @@ -1385,10 +1385,10 @@ let test_batcher ~test_persistence = bls_pkh_2 bls_pkh_1 ; let* txh2 = - craft_tx_and_inject + inject_transfer tx_client ~qty:5L - ~signer:bls_key_2 + ~source:bls_key_2.aggregate_alias ~dest:bls_pkh_1 ~ticket:ticket_id in @@ -1473,28 +1473,27 @@ let test_batcher ~test_persistence = in let inject_tx ?(amount = 1L) ~counter ~from ~dest () = - craft_tx_and_inject + inject_transfer + ~counter tx_client + ~source:from.Account.aggregate_alias ~qty:amount - ~counter - ~signer:from ~dest ~ticket:ticket_id in let nbtxs1 = 70 in + let nbtxs2 = 30 in let batch_success_promise = wait_for_batch_success_event tx_node in - Log.info "Injecting %d transactions to queue" nbtxs1 ; let* () = + Log.info "Injecting %d transactions to queue" nbtxs1 ; Lwt_list.iter_s (fun counter -> let* _ = inject_tx ~counter ~from:bls_key_1 ~dest:bls_pkh_2 () in unit) (List.init nbtxs1 (fun i -> Int64.of_int (i + 2))) - in - let nbtxs2 = 30 in - Log.info "Injecting %d transactions to queue" nbtxs2 ; - let* () = + and* () = + Log.info "Injecting %d transactions to queue" nbtxs2 ; Lwt_list.iter_s (fun counter -> let* _ = inject_tx ~counter ~from:bls_key_2 ~dest:bls_pkh_1 () in @@ -2037,11 +2036,11 @@ let test_committer = let* inbox = Tx_rollup_node.Client.get_inbox ~tx_node ~block:"head" in let ticket_id = get_ticket_hash_from_deposit (List.hd inbox) in let inject_tx ?counter ~from ~dest ?(amount = 1L) () = - craft_tx_and_inject + inject_transfer tx_client ~qty:amount ?counter - ~signer:from + ~source:from.Account.aggregate_alias ~dest ~ticket:ticket_id in @@ -2190,17 +2189,17 @@ let test_tickets_context = ~error_msg:"Ticket is %L but expected %R" ; Log.info "Submitting transactions to queue" ; let* _txh1 = - craft_tx_and_inject + inject_transfer tx_client - ~signer:bls_key_1 + ~source:bls_key_1.aggregate_alias ~dest:bls_pkh_2 ~ticket:ticket_id ~qty:10L in let* _txh2 = - craft_tx_and_inject + inject_transfer tx_client - ~signer:bls_key_2 + ~source:bls_key_2.aggregate_alias ~dest:bls_pkh_1 ~ticket:ticket_id ~qty:5L @@ -2294,17 +2293,17 @@ let test_round_trip ~title ?before_init ~originator ~operator ~batch_signer Log.info "Ticket %s was successfully emitted" ticket_id ; Log.info "Submitting transactions to queue" ; let* _txh1 = - craft_tx_and_inject + inject_transfer tx_client - ~signer:bls_key_1 + ~source:bls_key_1.aggregate_alias ~dest:bls_pkh_2 ~ticket:ticket_id ~qty:10L in let* _txh2 = - craft_tx_and_inject + inject_transfer tx_client - ~signer:bls_key_2 + ~source:bls_key_2.aggregate_alias ~dest:bls_pkh_1 ~ticket:ticket_id ~qty:5L @@ -2784,11 +2783,11 @@ let test_catch_up = let* block = Tx_rollup_node.Client.get_block ~tx_node ~block:"head" in check_l2_level block 0 ; let inject_tx ?counter ~from ~dest ?(amount = 1L) () = - craft_tx_and_inject + inject_transfer tx_client ~qty:amount ?counter - ~signer:from + ~source:from.Account.aggregate_alias ~dest ~ticket:ticket_id in -- GitLab From b242b98a5cb718dec49732f96454eb8bbff90d93 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Fri, 9 Sep 2022 12:25:22 +0200 Subject: [PATCH 3/5] ORU/Injector/Alpha: enrich error trace with injector step --- src/proto_alpha/lib_injector/injector_errors.ml | 14 ++++++++++++++ src/proto_alpha/lib_injector/injector_errors.mli | 3 +++ src/proto_alpha/lib_injector/injector_functor.ml | 10 +++++++--- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_injector/injector_errors.ml b/src/proto_alpha/lib_injector/injector_errors.ml index f263920da56a..c6c9f590ef93 100644 --- a/src/proto_alpha/lib_injector/injector_errors.ml +++ b/src/proto_alpha/lib_injector/injector_errors.ml @@ -71,3 +71,17 @@ let () = Data_encoding.(obj1 (req "operation" L1_operation.encoding)) (function No_worker_for_operation op -> Some op | _ -> None) (fun op -> No_worker_for_operation op) + +type error += Step_failed of string + +let () = + register_error_kind + ~id:"rollups.injector.step_failed" + ~title:"A step failed in the injector" + ~description:"A step failed in the injector." + ~pp:(fun ppf step -> + Format.fprintf ppf "%s failed in injector" (String.capitalize_ascii step)) + `Temporary + Data_encoding.(obj1 (req "step" string)) + (function Step_failed s -> Some s | _ -> None) + (fun s -> Step_failed s) diff --git a/src/proto_alpha/lib_injector/injector_errors.mli b/src/proto_alpha/lib_injector/injector_errors.mli index 4745709f70d0..e3e0f56666c9 100644 --- a/src/proto_alpha/lib_injector/injector_errors.mli +++ b/src/proto_alpha/lib_injector/injector_errors.mli @@ -33,3 +33,6 @@ type error += No_worker_for_tag of string (** Error when the injector does not handle the operation. *) type error += No_worker_for_operation of L1_operation.t + +(** Error when a step of the injector failed. *) +type error += Step_failed of string diff --git a/src/proto_alpha/lib_injector/injector_functor.ml b/src/proto_alpha/lib_injector/injector_functor.ml index 21f5b15e99c9..57b764bdd847 100644 --- a/src/proto_alpha/lib_injector/injector_functor.ml +++ b/src/proto_alpha/lib_injector/injector_functor.ml @@ -539,7 +539,8 @@ module Make (Rollup : PARAMETERS) = struct (operations : L1_operation.t list) = let open Lwt_result_syntax in let* packed_op, result = - simulate_operations ~must_succeed state operations + trace (Step_failed "simulation") + @@ simulate_operations ~must_succeed state operations in let results = Apply_results.to_list result in let failure = ref false in @@ -584,7 +585,9 @@ module Make (Rollup : PARAMETERS) = struct inject_operations ~must_succeed state operations else (* Inject on node for real *) - let+ oph = inject_on_node state packed_op in + let+ oph = + trace (Step_failed "injection") @@ inject_on_node state packed_op + in (oph, operations) (** Returns the (upper bound on) the size of an L1 batch of operations composed @@ -878,7 +881,8 @@ module Make (Rollup : PARAMETERS) = struct let on_launch _w signer Types.{cctxt; data_dir; rollup_node_state; strategy; tags} = - init_injector cctxt ~data_dir rollup_node_state ~signer strategy tags + trace (Step_failed "initialization") + @@ init_injector cctxt ~data_dir rollup_node_state ~signer strategy tags let on_error (type a b) w st (r : (a, b) Request.t) (errs : b) : unit tzresult Lwt.t = -- GitLab From 3c00e6518eaf1c85dee2a383631756652aed6014 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Fri, 9 Sep 2022 12:27:36 +0200 Subject: [PATCH 4/5] ORU/Injector/Alpha: show number of operations effectively injected --- src/proto_alpha/lib_injector/injector_events.ml | 5 +++-- src/proto_alpha/lib_injector/injector_functor.ml | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/proto_alpha/lib_injector/injector_events.ml b/src/proto_alpha/lib_injector/injector_events.ml index 71c8c70cada1..71b9d45181b0 100644 --- a/src/proto_alpha/lib_injector/injector_events.ml +++ b/src/proto_alpha/lib_injector/injector_events.ml @@ -164,10 +164,11 @@ module Make (Rollup : Injector_sigs.PARAMETERS) = struct ~pp2:Environment.Error_monad.pp_trace let injected = - declare_1 + declare_2 ~name:"injected" - ~msg:"Injected in {oph}" + ~msg:"Injected {nb} operations in {oph}" ~level:Notice + ("nb", Data_encoding.int31) ("oph", Operation_hash.encoding) let add_pending = diff --git a/src/proto_alpha/lib_injector/injector_functor.ml b/src/proto_alpha/lib_injector/injector_functor.ml index 57b764bdd847..d9a45ad722e6 100644 --- a/src/proto_alpha/lib_injector/injector_functor.ml +++ b/src/proto_alpha/lib_injector/injector_functor.ml @@ -499,8 +499,8 @@ module Make (Rollup : PARAMETERS) = struct in return (op, Apply_results.Contents_result_list result) - let inject_on_node state {shell; protocol_data = Operation_data {contents; _}} - = + let inject_on_node state ~nb + {shell; protocol_data = Operation_data {contents; _}} = let open Lwt_result_syntax in let unsigned_op = (shell, Contents_list contents) in let unsigned_op_bytes = @@ -524,7 +524,7 @@ module Make (Rollup : PARAMETERS) = struct ~chain:state.cctxt#chain op_bytes >>=? fun oph -> - let*! () = Event.(emit1 injected) state oph in + let*! () = Event.(emit2 injected) state nb oph in return oph (** Inject the given [operations] in an L1 batch. If [must_succeed] is [`All] @@ -586,7 +586,8 @@ module Make (Rollup : PARAMETERS) = struct else (* Inject on node for real *) let+ oph = - trace (Step_failed "injection") @@ inject_on_node state packed_op + trace (Step_failed "injection") + @@ inject_on_node ~nb:(List.length operations) state packed_op in (oph, operations) -- GitLab From bdc1ced9a6ed99d7b1cc540c82e2ad4908ff7bf8 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Fri, 9 Sep 2022 12:24:02 +0200 Subject: [PATCH 5/5] ORU/Injector/Alpha: inject L1 batches below the block gas limit --- .../lib_injector/injector_functor.ml | 52 +++++++++++++++---- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/src/proto_alpha/lib_injector/injector_functor.ml b/src/proto_alpha/lib_injector/injector_functor.ml index d9a45ad722e6..a8cdf8742c90 100644 --- a/src/proto_alpha/lib_injector/injector_functor.ml +++ b/src/proto_alpha/lib_injector/injector_functor.ml @@ -444,10 +444,20 @@ module Make (Rollup : PARAMETERS) = struct } ops - (** Simulate the injection of [operations]. See {!inject_operations} for the - specification of [must_succeed]. *) - let simulate_operations ~must_succeed state (operations : L1_operation.t list) - = + (** Returns the first half of the list [ops] if there is more than two + elements, or [None] otherwise. *) + let keep_half ops = + let total = List.length ops in + if total <= 1 then None else Some (List.take_n (total / 2) ops) + + (** [simulate_operations ~must_succeed state operations] simulates the + injection of [operations] and returns a triple [(op, ops, results)] where + [op] is the packed operation with the adjusted limits, [ops] is the prefix + of [operations] which was considered (because it did not exceed the + quotas) and [results] are the results of the simulation. See + {!inject_operations} for the specification of [must_succeed]. *) + let rec simulate_operations ~must_succeed state + (operations : L1_operation.t list) = let open Lwt_result_syntax in let open Annotated_manager_operation in let force = @@ -465,7 +475,7 @@ module Make (Rollup : PARAMETERS) = struct let fee_parameter = fee_parameter_of_operations state.rollup_node_state operations in - let operations = + let annotated_operations = List.map (fun {L1_operation.manager_operation = Manager operation; _} -> Annotated_manager_operation @@ -477,9 +487,9 @@ module Make (Rollup : PARAMETERS) = struct operations in let (Manager_list annot_op) = - Annotated_manager_operation.manager_of_list operations + Annotated_manager_operation.manager_of_list annotated_operations in - let* _, op, _, result = + let*! simulation_result = Injection.inject_manager_operation state.cctxt ~simulation:true (* Only simulation here *) @@ -497,7 +507,31 @@ module Make (Rollup : PARAMETERS) = struct ~fee_parameter annot_op in - return (op, Apply_results.Contents_result_list result) + match simulation_result with + | Error trace -> + let exceeds_quota = + TzTrace.fold + (fun exceeds -> function + | Environment.Ecoproto_error + (Gas.Block_quota_exceeded | Gas.Operation_quota_exceeded) -> + true + | _ -> exceeds) + false + trace + in + if exceeds_quota then + (* We perform a dichotomy by injecting the first half of the + operations (we are not looking to maximize the number of operations + injected because of the cost of simulation). Only the operations + which are actually injected will be removed from the queue so the + other half will be reconsidered later. *) + match keep_half operations with + | None -> fail trace + | Some operations -> + simulate_operations ~must_succeed state operations + else fail trace + | Ok (_, op, _, result) -> + return (op, operations, Apply_results.Contents_result_list result) let inject_on_node state ~nb {shell; protocol_data = Operation_data {contents; _}} = @@ -538,7 +572,7 @@ module Make (Rollup : PARAMETERS) = struct let rec inject_operations ~must_succeed state (operations : L1_operation.t list) = let open Lwt_result_syntax in - let* packed_op, result = + let* packed_op, operations, result = trace (Step_failed "simulation") @@ simulate_operations ~must_succeed state operations in -- GitLab