Source file injector_server.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
(*****************************************************************************)
(*                                                                           *)
(* SPDX-License-Identifier: MIT                                              *)
(* Copyright (c) 2023 Functori, <contact@functori.com>                       *)
(* Copyright (c) 2023 Nomadic Labs <contact@nomadic-labs.com>                *)
(*                                                                           *)
(*****************************************************************************)

module Configuration = struct
  type tag = Transaction

  type fee_parameters = Injector_common.fee_parameter

  let tags = [Transaction]

  let string_of_purpose = function Transaction -> "Transaction"

  let default_fee_parameters =
    {
      Injector_common.minimal_fees = {Injector_common.mutez = 100L};
      minimal_nanotez_per_byte = Q.of_int 1000;
      minimal_nanotez_per_gas_unit = Q.of_int 100;
      force_low_fee = false;
      fee_cap = {Injector_common.mutez = 1_000_000L};
      burn_cap = {Injector_common.mutez = 1_000_000L};
    }
end

(* The rest of this  module is adapted from
   [lib_smart_rollup_node/injector.ml] *)

type state = {
  cctxt : Client_context.full;
  fee_parameters : Configuration.fee_parameters;
  minimal_block_delay : int64;
  delay_increment_per_round : int64;
}

open Injector_sigs

module Parameters :
  PARAMETERS
    with type state = state
     and type Tag.t = Configuration.tag
     and type Operation.t = Injector_server_operation.t = struct
  type nonrec state = state

  let events_section = ["injector"; "server"]

  module Tag : TAG with type t = Configuration.tag = struct
    type t = Configuration.tag

    let compare = Stdlib.compare

    let equal = Stdlib.( = )

    let hash = Hashtbl.hash

    let string_of_tag = Configuration.string_of_purpose

    let pp ppf t = Format.pp_print_string ppf (string_of_tag t)

    let encoding : t Data_encoding.t =
      let open Data_encoding in
      match Configuration.tags with
      (* first case can be removed once we have multiple tags *)
      | [tag] -> conv string_of_tag (fun _ -> tag) string
      | tags -> string_enum (List.map (fun t -> (string_of_tag t, t)) tags)
  end

  module Operation = Injector_server_operation

  (* Very coarse approximation for the number of operation we
     expect for each block *)
  let table_estimated_size : Tag.t -> int = function Transaction -> 100

  let operation_tag : Operation.t -> Tag.t = function
    | Transaction _ -> Transaction

  (* TODO: https://gitlab.com/tezos/tezos/-/issues/6281
     revise if multiple operation kinds have different fee parameter
     structures *)
  let fee_parameter {fee_parameters; _} _ = fee_parameters

  (* TODO: https://gitlab.com/tezos/tezos/-/issues/3459
     Decide if some batches must have all the operations succeed. See
     {!Injector_common.Parameter.batch_must_succeed}. *)
  let batch_must_succeed _ = `At_least_one

  let retry_unsuccessful_operation _node_ctxt (_op : Operation.t) status =
    let open Lwt_syntax in
    match status with
    | Backtracked | Skipped | Other_branch ->
        (* Always retry backtracked or skipped operations, or operations that
           are on another branch because of a reorg. *)
        return Retry
    | Failed error -> (
        (* TODO: https://gitlab.com/tezos/tezos/-/issues/4071
           Think about which operations should be retried and when. *)
        match classify_trace error with
        | Permanent | Outdated -> return Forget
        | Branch | Temporary -> return Retry)
    | Never_included ->
        (* Forget operations that are never included *)
        return Forget
end

include Injector_functor.Make (Parameters)