• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MinaProtocol / mina / 1239

31 Mar 2026 12:24PM UTC coverage: 38.104% (-3.7%) from 41.817%
1239

push

buildkite

web-flow
Merge pull request #18591 from MinaProtocol/copilot/fix-error-message-blockchain-verification

0 of 1 new or added line in 1 file covered. (0.0%)

2995 existing lines in 128 files now uncovered.

28619 of 75108 relevant lines covered (38.1%)

51610.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

1.96
/src/lib/transition_frontier/persistent_frontier/diff_buffer.ml
1
(* TODO: flush on timeout interval in addition to meeting flush capacity *)
173✔
2
open Async_kernel
3
open Core_kernel
4
open Frontier_base
5

6
let max_latency
7
    { Genesis_constants.Constraint_constants.block_window_duration_ms; _ } =
UNCOV
8
  Block_time.Span.(
×
UNCOV
9
    (block_window_duration_ms |> Int64.of_int |> Block_time.Span.of_ms)
×
UNCOV
10
    * of_ms 5L)
×
11

12
module Capacity = struct
UNCOV
13
  type t =
×
UNCOV
14
    { flush : int
×
15
          (** The number of entries that will trigger a frontier buffer flush *)
UNCOV
16
    ; max : int  (** The maximum capacity of the diff buffer *)
×
17
    }
18
  [@@deriving to_yojson]
19

20
  let make ?flush () =
UNCOV
21
    let flush = Option.value ~default:30 flush in
×
UNCOV
22
    let max = flush * 4 in
×
23
    { flush; max }
24
end
25

26
(* TODO: lift up as Block_time utility *)
27
module Timer = struct
28
  open Block_time
29

30
  type t =
31
    { time_controller : Controller.t
32
    ; f : unit -> unit
33
    ; span : Span.t
34
    ; mutable timeout : unit Timeout.t option
35
    }
36

37
  let create ~time_controller ~f span =
UNCOV
38
    { time_controller; span; f; timeout = None }
×
39

40
  let start t =
41
    assert (Option.is_none t.timeout) ;
×
42
    let rec run_timeout t =
43
      t.timeout <-
×
44
        Some
45
          (Timeout.create t.time_controller t.span ~f:(fun _ ->
×
46
               t.f () ; run_timeout t ) )
×
47
    in
48
    run_timeout t
49

50
  let stop t =
51
    Option.iter t.timeout ~f:(fun timeout ->
×
52
        Timeout.cancel t.time_controller timeout () ) ;
×
53
    t.timeout <- None
×
54

55
  let reset t = stop t ; start t
×
56
end
57

58
type work = { diffs : Diff.Lite.E.t list }
59

60
module Rev_dyn_array : sig
61
  type 'a t
62

63
  val create : unit -> _ t
64

65
  val length : _ t -> int
66

67
  val clear : _ t -> unit
68

69
  val to_list : 'a t -> 'a list
70

71
  val add : 'a t -> 'a -> unit
72
end = struct
73
  type 'a t = { mutable length : int; mutable rev_list : 'a list }
74

UNCOV
75
  let create () = { length = 0; rev_list = [] }
×
76

77
  let length { length; _ } = length
×
78

79
  let to_list { rev_list; _ } = List.rev rev_list
×
80

81
  let clear t =
82
    t.length <- 0 ;
×
83
    t.rev_list <- []
84

85
  let add t x =
86
    t.length <- t.length + 1 ;
×
87
    t.rev_list <- x :: t.rev_list
88
end
89

90
type t =
91
  { diff_array : Diff.Lite.E.t Rev_dyn_array.t
92
  ; capacity : Capacity.t
93
  ; worker : Worker.t
94
        (* timer unfortunately needs to be mutable to break recursion *)
95
  ; mutable timer : Timer.t option
96
  ; mutable flush_job : unit Deferred.t option
97
  ; mutable closed : bool
98
  }
99

100
let check_for_overflow t =
101
  if Rev_dyn_array.length t.diff_array > t.capacity.max then
×
102
    failwith "persistence buffer overflow"
×
103

104
let should_flush t = Rev_dyn_array.length t.diff_array >= t.capacity.flush
×
105

106
let flush t =
107
  let rec flush_job t =
×
108
    let diffs = Rev_dyn_array.to_list t.diff_array in
×
109
    Rev_dyn_array.clear t.diff_array ;
×
110
    let%bind () = Worker.dispatch t.worker diffs in
×
111
    if should_flush t then flush_job t
×
112
    else (
×
113
      t.flush_job <- None ;
114
      Deferred.unit )
115
  in
116
  assert (Option.is_none t.flush_job) ;
×
117
  if Rev_dyn_array.length t.diff_array > 0 then
×
118
    t.flush_job <- Some (flush_job t)
×
119

120
let create ~(constraint_constants : Genesis_constants.Constraint_constants.t)
121
    ~time_controller ~worker ~capacity =
UNCOV
122
  let t =
×
UNCOV
123
    { diff_array = Rev_dyn_array.create ()
×
124
    ; capacity
125
    ; worker
126
    ; timer = None
127
    ; flush_job = None
128
    ; closed = false
129
    }
130
  in
131
  let timer =
132
    Timer.create ~time_controller
133
      ~f:(fun () -> if Option.is_none t.flush_job then flush t)
×
UNCOV
134
      (max_latency constraint_constants)
×
135
  in
UNCOV
136
  t.timer <- Some timer ;
×
137
  t
138

139
let write t ~diffs =
140
  if t.closed then failwith "attempt to write to diff buffer after closed" ;
×
141
  List.iter diffs ~f:(Rev_dyn_array.add t.diff_array) ;
×
142
  if should_flush t && Option.is_none t.flush_job then flush t
×
143
  else check_for_overflow t
×
144

145
let close_and_finish_copy t =
146
  ( match t.timer with
×
147
  | None ->
×
148
      failwith "diff buffer timer was never initialized"
149
  | Some timer ->
×
150
      Timer.stop timer ) ;
×
151
  t.closed <- true ;
152
  let%bind () = Option.value t.flush_job ~default:Deferred.unit in
×
153
  flush t ;
×
154
  Option.value t.flush_job ~default:Deferred.unit
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc