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

MinaProtocol / mina / 3001

01 Dec 2024 06:25PM UTC coverage: 36.257% (-24.4%) from 60.697%
3001

push

buildkite

web-flow
Merge pull request #16393 from leopardracer/patch-1

fix: typos in documentation files

25609 of 70631 relevant lines covered (36.26%)

27168.12 hits per line

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

15.1
/src/lib/transition_handler/processor.ml
1
(** This module contains the transition processor. The transition processor is
2
 *  the thread in which transitions are attached the to the transition frontier.
3
 *
4
 *  Two types of data are handled by the transition processor: validated external transitions
5
 *  with precomputed state hashes (via the block producer and validator pipes)
6
 *  and breadcrumb rose trees (via the catchup pipe).
7
 *)
8

5✔
9
open Core_kernel
10
open Async_kernel
11
open Pipe_lib.Strict_pipe
12
open Mina_base
13
open Mina_state
14
open Cache_lib
15
open Mina_block
16
open Network_peer
17

18
module type CONTEXT = sig
19
  val logger : Logger.t
20

21
  val precomputed_values : Precomputed_values.t
22

23
  val constraint_constants : Genesis_constants.Constraint_constants.t
24

25
  val consensus_constants : Consensus.Constants.t
26
end
27

28
(* TODO: calculate a sensible value from postake consensus arguments *)
29
let catchup_timeout_duration (precomputed_values : Precomputed_values.t) =
30
  Block_time.Span.of_ms
×
31
    ( (precomputed_values.genesis_constants.protocol.delta + 1)
32
      * precomputed_values.constraint_constants.block_window_duration_ms
33
    |> Int64.of_int )
×
34
  |> Block_time.Span.min (Block_time.Span.of_ms (Int64.of_int 5000))
×
35

36
let cached_transform_deferred_result ~transform_cached ~transform_result cached
37
    =
38
  Cached.transform cached ~f:transform_cached
×
39
  |> Cached.sequence_deferred
×
40
  >>= Fn.compose transform_result Cached.sequence_result
×
41

42
(* add a breadcrumb and perform post processing *)
43
let add_and_finalize ~logger ~frontier ~catchup_scheduler
44
    ~processed_transition_writer ~only_if_present ~time_controller ~source
45
    ~valid_cb cached_breadcrumb ~(precomputed_values : Precomputed_values.t) =
46
  let module Inclusion_time = Mina_metrics.Block_latency.Inclusion_time in
×
47
  let breadcrumb =
48
    if Cached.is_pure cached_breadcrumb then Cached.peek cached_breadcrumb
×
49
    else Cached.invalidate_with_success cached_breadcrumb
×
50
  in
51
  let consensus_constants = precomputed_values.consensus_constants in
52
  let transition =
53
    Transition_frontier.Breadcrumb.validated_transition breadcrumb
54
  in
55
  [%log debug] "add_and_finalize $state_hash %s callback"
×
56
    ~metadata:
57
      [ ( "state_hash"
58
        , Transition_frontier.Breadcrumb.state_hash breadcrumb
×
59
          |> State_hash.to_yojson )
×
60
      ]
61
    (Option.value_map valid_cb ~default:"without" ~f:(const "with")) ;
×
62
  let state_hash = Transition_frontier.Breadcrumb.state_hash breadcrumb in
×
63
  Internal_tracing.with_state_hash state_hash
×
64
  @@ fun () ->
65
  [%log internal] "Add_and_finalize" ;
×
66
  let%map () =
67
    if only_if_present then (
×
68
      let parent_hash = Transition_frontier.Breadcrumb.parent_hash breadcrumb in
69
      match Transition_frontier.find frontier parent_hash with
×
70
      | Some _ ->
×
71
          Transition_frontier.add_breadcrumb_exn frontier breadcrumb
×
72
      | None ->
×
73
          [%log internal] "Parent_breadcrumb_not_found" ;
×
74
          [%log warn]
×
75
            !"When trying to add breadcrumb, its parent had been removed from \
×
76
              transition frontier: %{sexp: State_hash.t}"
77
            parent_hash ;
78
          Deferred.unit )
×
79
    else Transition_frontier.add_breadcrumb_exn frontier breadcrumb
×
80
  in
81
  ( match source with
×
82
  | `Internal ->
×
83
      ()
84
  | _ ->
×
85
      let transition_time =
86
        transition |> Mina_block.Validated.header
×
87
        |> Mina_block.Header.protocol_state |> Protocol_state.consensus_state
×
88
        |> Consensus.Data.Consensus_state.consensus_time
89
      in
90
      let time_elapsed =
×
91
        Block_time.diff
92
          (Block_time.now time_controller)
×
93
          (Consensus.Data.Consensus_time.to_time ~constants:consensus_constants
×
94
             transition_time )
95
      in
96
      Inclusion_time.update (Block_time.Span.to_time_span time_elapsed) ) ;
×
97
  [%log internal] "Add_and_finalize_done" ;
×
98
  if Writer.is_closed processed_transition_writer then
×
99
    Or_error.error_string "processed transitions closed"
×
100
  else (
×
101
    Writer.write processed_transition_writer
102
      (`Transition transition, `Source source, `Valid_cb valid_cb) ;
103
    Catchup_scheduler.notify catchup_scheduler
×
104
      ~hash:(Mina_block.Validated.state_hash transition) )
×
105

106
let process_transition ~context:(module Context : CONTEXT) ~trust_system
107
    ~verifier ~get_completed_work ~frontier ~catchup_scheduler
108
    ~processed_transition_writer ~time_controller ~block_or_header ~valid_cb =
109
  let is_block_in_frontier =
3✔
110
    Fn.compose Option.is_some @@ Transition_frontier.find frontier
3✔
111
  in
112
  let module Consensus_context = struct
3✔
113
    include Context
114

115
    let compile_config = precomputed_values.compile_config
116
  end in
117
  let open Consensus_context in
118
  let header, transition_hash, transition_receipt_time, sender, validation =
119
    match block_or_header with
120
    | `Block cached_env ->
3✔
121
        let env = Cached.peek cached_env in
122
        let block, v = Envelope.Incoming.data env in
3✔
123
        ( Mina_block.header @@ With_hash.data block
3✔
124
        , State_hash.With_state_hashes.state_hash block
3✔
125
        , Some (Envelope.Incoming.received_at env)
3✔
126
        , Envelope.Incoming.sender env
3✔
127
        , v )
128
    | `Header env ->
×
129
        let h, v = Envelope.Incoming.data env in
130
        ( With_hash.data h
×
131
        , State_hash.With_state_hashes.state_hash h
×
132
        , Some (Envelope.Incoming.received_at env)
×
133
        , Envelope.Incoming.sender env
×
134
        , v )
135
  in
136
  let parent_hash =
137
    Protocol_state.previous_state_hash (Header.protocol_state header)
3✔
138
  in
139
  let root_block =
3✔
140
    Transition_frontier.(Breadcrumb.block_with_hash @@ root frontier)
3✔
141
  in
142
  let metadata = [ ("state_hash", State_hash.to_yojson transition_hash) ] in
3✔
143
  let state_hash = transition_hash in
144
  Internal_tracing.with_state_hash state_hash
145
  @@ fun () ->
146
  [%log internal] "@block_metadata"
3✔
147
    ~metadata:
148
      [ ( "blockchain_length"
149
        , Mina_numbers.Length.to_yojson (Header.blockchain_length header) )
3✔
150
      ] ;
151
  [%log internal] "Begin_external_block_processing" ;
3✔
152
  let handle_not_selected () =
3✔
153
    [%log internal] "Failure"
×
154
      ~metadata:[ ("reason", `String "Not_selected_over_frontier_root") ] ;
155
    Trust_system.record_envelope_sender trust_system logger sender
×
156
      ( Trust_system.Actions.Gossiped_invalid_transition
157
      , Some
158
          ( "The transition with hash $state_hash was not selected over the \
159
             transition frontier root"
160
          , metadata ) )
161
  in
162
  match block_or_header with
163
  | `Header env -> (
×
164
      let header_with_hash, _ = Envelope.Incoming.data env in
165
      [%log internal] "Validate_frontier_dependencies" ;
×
166
      match
×
167
        Mina_block.Validation.validate_frontier_dependencies
168
          ~context:(module Consensus_context)
169
          ~root_block ~is_block_in_frontier ~to_header:ident
170
          (Envelope.Incoming.data env)
×
171
      with
172
      | Ok _ | Error `Parent_missing_from_frontier ->
×
173
          [%log internal] "Schedule_catchup" ;
×
174
          Catchup_scheduler.watch_header catchup_scheduler ~valid_cb
×
175
            ~header_with_hash ;
176
          return ()
×
177
      | Error `Not_selected_over_frontier_root ->
×
178
          handle_not_selected ()
179
      | Error `Already_in_frontier ->
×
180
          [%log internal] "Failure"
×
181
            ~metadata:[ ("reason", `String "Already_in_frontier") ] ;
182
          [%log warn] ~metadata
×
183
            "Refusing to process the transition with hash $state_hash because \
184
             is is already in the transition frontier" ;
185
          return () )
×
186
  | `Block cached_initially_validated_transition ->
3✔
187
      Deferred.ignore_m
188
      @@
189
      let open Deferred.Result.Let_syntax in
190
      let%bind mostly_validated_transition =
191
        let open Deferred.Let_syntax in
192
        let initially_validated_transition =
193
          Cached.peek cached_initially_validated_transition
3✔
194
          |> Envelope.Incoming.data
195
        in
196
        [%log internal] "Validate_frontier_dependencies" ;
3✔
197
        match
3✔
198
          Mina_block.Validation.validate_frontier_dependencies
199
            ~context:(module Consensus_context)
200
            ~root_block ~is_block_in_frontier ~to_header:Mina_block.header
201
            initially_validated_transition
202
        with
203
        | Ok t ->
×
204
            return (Ok t)
×
205
        | Error `Not_selected_over_frontier_root ->
×
206
            let (_ : Mina_block.initial_valid_block Envelope.Incoming.t) =
207
              Cached.invalidate_with_failure
208
                cached_initially_validated_transition
209
            in
210
            let%map () = handle_not_selected () in
×
211
            Error ()
×
212
        | Error `Already_in_frontier ->
3✔
213
            [%log internal] "Failure"
3✔
214
              ~metadata:[ ("reason", `String "Already_in_frontier") ] ;
215
            [%log warn] ~metadata
3✔
216
              "Refusing to process the transition with hash $state_hash \
217
               because is is already in the transition frontier" ;
218
            let (_ : Mina_block.initial_valid_block Envelope.Incoming.t) =
3✔
219
              Cached.invalidate_with_failure
220
                cached_initially_validated_transition
221
            in
222
            return (Error ())
3✔
223
        | Error `Parent_missing_from_frontier -> (
×
224
            [%log internal] "Schedule_catchup" ;
×
225
            match validation with
×
226
            | ( _
×
227
              , _
228
              , _
229
              , (`Delta_block_chain, Truth.True delta_state_hashes)
230
              , _
231
              , _
232
              , _ ) ->
233
                let timeout_duration =
234
                  Option.fold
235
                    (Transition_frontier.find frontier
×
236
                       (Mina_stdlib.Nonempty_list.head delta_state_hashes) )
×
237
                    ~init:(Block_time.Span.of_ms 0L)
×
238
                    ~f:(fun _ _ -> catchup_timeout_duration precomputed_values)
×
239
                in
240
                Catchup_scheduler.watch catchup_scheduler ~timeout_duration
×
241
                  ~cached_transition:cached_initially_validated_transition
242
                  ~valid_cb ;
243
                return (Error ()) )
×
244
      in
245
      (* TODO: only access parent in transition frontier once (already done in call to validate dependencies) #2485 *)
246
      [%log internal] "Find_parent_breadcrumb" ;
×
247
      let parent_breadcrumb =
×
248
        Transition_frontier.find_exn frontier parent_hash
249
      in
250
      let%bind breadcrumb =
251
        cached_transform_deferred_result cached_initially_validated_transition
×
252
          ~transform_cached:(fun _ ->
253
            Transition_frontier.Breadcrumb.build ~logger ~precomputed_values
×
254
              ~verifier ~get_completed_work ~trust_system
255
              ~transition_receipt_time ~sender:(Some sender)
256
              ~parent:parent_breadcrumb ~transition:mostly_validated_transition
257
              (* TODO: Can we skip here? *) () )
258
          ~transform_result:(function
259
            | Error (`Invalid_staged_ledger_hash error)
×
260
            | Error (`Invalid_staged_ledger_diff error) ->
×
261
                Internal_tracing.with_state_hash state_hash
262
                @@ fun () ->
263
                [%log internal] "Failure"
×
264
                  ~metadata:[ ("reason", `String (Error.to_string_hum error)) ] ;
×
265
                [%log error]
×
266
                  ~metadata:
267
                    (metadata @ [ ("error", Error_json.error_to_yojson error) ])
×
268
                  "Error while building breadcrumb in the transition handler \
269
                   processor: $error" ;
270
                Deferred.return (Error ())
×
271
            | Error (`Fatal_error exn) ->
×
272
                Internal_tracing.with_state_hash state_hash
273
                @@ fun () ->
274
                [%log internal] "Failure"
×
275
                  ~metadata:[ ("reason", `String "Fatal error") ] ;
276
                raise exn
×
277
            | Ok breadcrumb ->
×
278
                Deferred.return (Ok breadcrumb) )
279
      in
280
      Mina_metrics.(
×
281
        Counter.inc_one
×
282
          Transition_frontier_controller.breadcrumbs_built_by_processor) ;
283
      let%map.Deferred result =
284
        add_and_finalize ~logger ~frontier ~catchup_scheduler
×
285
          ~processed_transition_writer ~only_if_present:false ~time_controller
286
          ~source:`Gossip breadcrumb ~precomputed_values ~valid_cb
287
      in
288
      ( match result with
×
289
      | Ok () ->
×
290
          [%log internal] "Breadcrumb_integrated"
×
291
      | Error err ->
×
292
          [%log internal] "Failure"
×
293
            ~metadata:[ ("reason", `String (Error.to_string_hum err)) ] ) ;
×
294
      Result.return result
295

296
let run ~context:(module Context : CONTEXT) ~verifier ~trust_system
297
    ~time_controller ~frontier ~get_completed_work
298
    ~(primary_transition_reader :
299
       ( [ `Block of
300
           ( Mina_block.initial_valid_block Envelope.Incoming.t
301
           , State_hash.t )
302
           Cached.t
303
         | `Header of Mina_block.initial_valid_header Envelope.Incoming.t ]
304
       * [ `Valid_cb of Mina_net2.Validation_callback.t option ] )
305
       Reader.t )
306
    ~(producer_transition_reader : Transition_frontier.Breadcrumb.t Reader.t)
307
    ~(clean_up_catchup_scheduler : unit Ivar.t) ~catchup_job_writer
308
    ~(catchup_breadcrumbs_reader :
309
       ( ( (Transition_frontier.Breadcrumb.t, State_hash.t) Cached.t
310
         * Mina_net2.Validation_callback.t option )
311
         Rose_tree.t
312
         list
313
       * [ `Ledger_catchup of unit Ivar.t | `Catchup_scheduler ] )
314
       Reader.t )
315
    ~(catchup_breadcrumbs_writer :
316
       ( ( (Transition_frontier.Breadcrumb.t, State_hash.t) Cached.t
317
         * Mina_net2.Validation_callback.t option )
318
         Rose_tree.t
319
         list
320
         * [ `Ledger_catchup of unit Ivar.t | `Catchup_scheduler ]
321
       , crash buffered
322
       , unit )
323
       Writer.t ) ~processed_transition_writer =
324
  let open Context in
6✔
325
  let catchup_scheduler =
326
    Catchup_scheduler.create ~logger ~precomputed_values ~verifier ~trust_system
327
      ~frontier ~time_controller ~catchup_job_writer ~catchup_breadcrumbs_writer
328
      ~clean_up_signal:clean_up_catchup_scheduler
329
  in
330
  let add_and_finalize =
331
    add_and_finalize ~frontier ~catchup_scheduler ~processed_transition_writer
332
      ~time_controller ~precomputed_values
333
  in
334
  let process_transition =
335
    process_transition
336
      ~context:(module Context)
337
      ~get_completed_work ~trust_system ~verifier ~frontier ~catchup_scheduler
338
      ~processed_transition_writer ~time_controller
339
  in
340
  O1trace.background_thread "process_blocks" (fun () ->
341
      Reader.Merge.iter
6✔
342
        (* It is fine to skip the cache layer on blocks produced by this node
343
           * because it is extraordinarily unlikely we would write an internal bug
344
           * triggering this case, and the external case (where we received an
345
           * identical external transition from the network) can happen iff there
346
           * is another node with the exact same private key and view of the
347
           * transaction pool. *)
348
        [ Reader.map producer_transition_reader ~f:(fun breadcrumb ->
6✔
349
              Mina_metrics.(
×
350
                Gauge.inc_one
×
351
                  Transition_frontier_controller.transitions_being_processed) ;
352
              `Local_breadcrumb (Cached.pure breadcrumb) )
×
353
        ; Reader.map catchup_breadcrumbs_reader
6✔
354
            ~f:(fun (cb, catchup_breadcrumbs_callback) ->
355
              `Catchup_breadcrumbs (cb, catchup_breadcrumbs_callback) )
×
356
        ; Reader.map primary_transition_reader ~f:(fun vt ->
6✔
357
              `Partially_valid_transition vt )
3✔
358
        ]
359
        ~f:(fun msg ->
360
          let open Deferred.Let_syntax in
3✔
361
          O1trace.thread "transition_handler_processor" (fun () ->
362
              match msg with
3✔
363
              | `Catchup_breadcrumbs
×
364
                  (breadcrumb_subtrees, subsequent_callback_action) -> (
365
                  ( match%map
366
                      Deferred.Or_error.List.iter breadcrumb_subtrees
×
367
                        ~f:(fun subtree ->
368
                          Rose_tree.Deferred.Or_error.iter
×
369
                            subtree
370
                            (* It could be the case that by the time we try and
371
                               * add the breadcrumb, it's no longer relevant when
372
                               * we're catching up *) ~f:(fun (b, valid_cb) ->
373
                              let state_hash =
×
374
                                Frontier_base.Breadcrumb.state_hash
375
                                  (Cached.peek b)
×
376
                              in
377
                              let%map result =
378
                                add_and_finalize ~logger ~only_if_present:true
×
379
                                  ~source:`Catchup ~valid_cb b
380
                              in
381
                              Internal_tracing.with_state_hash state_hash
×
382
                              @@ fun () ->
383
                              ( match result with
×
384
                              | Error err ->
×
385
                                  [%log internal] "Failure"
×
386
                                    ~metadata:
387
                                      [ ( "reason"
388
                                        , `String (Error.to_string_hum err) )
×
389
                                      ]
390
                              | Ok () ->
×
391
                                  [%log internal] "Breadcrumb_integrated" ) ;
×
392
                              result ) )
393
                    with
394
                  | Ok () ->
×
395
                      ()
396
                  | Error err ->
×
397
                      List.iter breadcrumb_subtrees ~f:(fun tree ->
398
                          Rose_tree.iter tree
×
399
                            ~f:(fun (cached_breadcrumb, _vc) ->
400
                              let (_ : Transition_frontier.Breadcrumb.t) =
×
401
                                Cached.invalidate_with_failure cached_breadcrumb
402
                              in
403
                              () ) ) ;
×
404
                      [%log error]
×
405
                        "Error, failed to attach all catchup breadcrumbs to \
406
                         transition frontier: $error"
407
                        ~metadata:[ ("error", Error_json.error_to_yojson err) ]
×
408
                  )
409
                  >>| fun () ->
410
                  match subsequent_callback_action with
×
411
                  | `Ledger_catchup decrement_signal ->
×
412
                      if Ivar.is_full decrement_signal then
413
                        [%log error] "Ivar.fill bug is here!" ;
×
414
                      Ivar.fill decrement_signal ()
×
415
                  | `Catchup_scheduler ->
×
416
                      () )
417
              | `Local_breadcrumb breadcrumb ->
×
418
                  let state_hash =
419
                    Transition_frontier.Breadcrumb.validated_transition
×
420
                      (Cached.peek breadcrumb)
×
421
                    |> Mina_block.Validated.state_hash
422
                  in
423
                  Internal_tracing.with_state_hash state_hash
×
424
                  @@ fun () ->
425
                  [%log internal] "Begin_local_block_processing" ;
×
426
                  let transition_time =
×
427
                    Transition_frontier.Breadcrumb.validated_transition
×
428
                      (Cached.peek breadcrumb)
×
429
                    |> Mina_block.Validated.header
×
430
                    |> Mina_block.Header.protocol_state
×
431
                    |> Protocol_state.blockchain_state
×
432
                    |> Blockchain_state.timestamp |> Block_time.to_time_exn
×
433
                  in
434
                  Perf_histograms.add_span
×
435
                    ~name:"accepted_transition_local_latency"
436
                    (Core_kernel.Time.diff
×
437
                       Block_time.(now time_controller |> to_time_exn)
×
438
                       transition_time ) ;
439
                  let%map () =
440
                    match%map
441
                      add_and_finalize ~logger ~only_if_present:false
×
442
                        ~source:`Internal breadcrumb ~valid_cb:None
443
                    with
444
                    | Ok () ->
×
445
                        [%log internal] "Breadcrumb_integrated" ;
×
446
                        ()
×
447
                    | Error err ->
×
448
                        [%log internal] "Failure"
×
449
                          ~metadata:
450
                            [ ("reason", `String (Error.to_string_hum err)) ] ;
×
451
                        [%log error]
×
452
                          ~metadata:
453
                            [ ("error", Error_json.error_to_yojson err) ]
×
454
                          "Error, failed to attach produced breadcrumb to \
455
                           transition frontier: $error" ;
456
                        let (_ : Transition_frontier.Breadcrumb.t) =
×
457
                          Cached.invalidate_with_failure breadcrumb
458
                        in
459
                        ()
×
460
                  in
461
                  Mina_metrics.(
×
462
                    Gauge.dec_one
463
                      Transition_frontier_controller.transitions_being_processed)
464
              | `Partially_valid_transition (block_or_header, `Valid_cb valid_cb)
3✔
465
                ->
466
                  process_transition ~block_or_header ~valid_cb ) ) )
467

468
let%test_module "Transition_handler.Processor tests" =
469
  ( module struct
470
    open Async
471
    open Pipe_lib
472

473
    let () =
474
      Backtrace.elide := false ;
475
      Printexc.record_backtrace true ;
476
      Async.Scheduler.set_record_backtraces true
×
477

478
    let logger = Logger.null ()
×
479

480
    let () =
481
      (* Disable log messages from best_tip_diff logger. *)
482
      Logger.Consumer_registry.register ~commit_id:Mina_version.commit_id
×
483
        ~id:Logger.Logger_id.best_tip_diff ~processor:(Logger.Processor.raw ())
×
484
        ~transport:
485
          (Logger.Transport.create
×
486
             ( module struct
487
               type t = unit
488

489
               let transport () _ = ()
×
490
             end )
491
             () )
492
        ()
493

494
    let precomputed_values = Lazy.force Precomputed_values.for_unit_tests
×
495

496
    let proof_level = precomputed_values.proof_level
497

498
    let constraint_constants = precomputed_values.constraint_constants
499

500
    let time_controller = Block_time.Controller.basic ~logger
501

502
    let trust_system = Trust_system.null ()
×
503

504
    let verifier =
505
      Async.Thread_safe.block_on_async_exn (fun () ->
×
506
          Verifier.For_tests.default ~constraint_constants ~logger ~proof_level
×
507
            () )
508

509
    module Context = struct
510
      let logger = logger
511

512
      let precomputed_values = precomputed_values
513

514
      let constraint_constants = constraint_constants
515

516
      let consensus_constants = precomputed_values.consensus_constants
517
    end
518

519
    let downcast_breadcrumb breadcrumb =
520
      let transition =
×
521
        Transition_frontier.Breadcrumb.validated_transition breadcrumb
×
522
        |> Mina_block.Validated.remember
×
523
        |> Mina_block.Validation.reset_frontier_dependencies_validation
×
524
        |> Mina_block.Validation.reset_staged_ledger_diff_validation
525
      in
526
      Envelope.Incoming.wrap ~data:transition ~sender:Envelope.Sender.Local
×
527

528
    let%test_unit "adding transitions whose parents are in the frontier" =
529
      let frontier_size = 1 in
×
530
      let branch_size = 10 in
531
      let max_length = frontier_size + branch_size in
532
      Quickcheck.test ~trials:4
533
        (Transition_frontier.For_tests.gen_with_branch ~precomputed_values
×
534
           ~verifier ~max_length ~frontier_size ~branch_size () )
535
        ~f:(fun (frontier, branch) ->
536
          assert (
×
537
            Thread_safe.block_on_async_exn (fun () ->
×
538
                let valid_transition_reader, valid_transition_writer =
×
539
                  Strict_pipe.create
540
                    (Buffered
541
                       (`Capacity branch_size, `Overflow (Drop_head ignore)) )
542
                in
543
                let producer_transition_reader, _ =
×
544
                  Strict_pipe.create
545
                    (Buffered
546
                       (`Capacity branch_size, `Overflow (Drop_head ignore)) )
547
                in
548
                let _, catchup_job_writer =
×
549
                  Strict_pipe.create (Buffered (`Capacity 1, `Overflow Crash))
550
                in
551
                let catchup_breadcrumbs_reader, catchup_breadcrumbs_writer =
×
552
                  Strict_pipe.create (Buffered (`Capacity 1, `Overflow Crash))
553
                in
554
                let processed_transition_reader, processed_transition_writer =
×
555
                  Strict_pipe.create
556
                    (Buffered
557
                       (`Capacity branch_size, `Overflow (Drop_head ignore)) )
558
                in
559
                let clean_up_catchup_scheduler = Ivar.create () in
×
560
                let cache =
×
561
                  Unprocessed_transition_cache.create ~logger
562
                    ~cache_exceptions:true
563
                in
564
                run
565
                  ~context:(module Context)
566
                  ~time_controller ~verifier ~get_completed_work:(Fn.const None)
×
567
                  ~trust_system ~clean_up_catchup_scheduler ~frontier
568
                  ~primary_transition_reader:valid_transition_reader
569
                  ~producer_transition_reader ~catchup_job_writer
570
                  ~catchup_breadcrumbs_reader ~catchup_breadcrumbs_writer
571
                  ~processed_transition_writer ;
572
                List.iter branch ~f:(fun breadcrumb ->
573
                    let b =
×
574
                      downcast_breadcrumb breadcrumb
×
575
                      |> Unprocessed_transition_cache.register_exn cache
576
                    in
577
                    Strict_pipe.Writer.write valid_transition_writer
×
578
                      (`Block b, `Valid_cb None) ) ;
579
                match%map
580
                  Block_time.Timeout.await
×
581
                    ~timeout_duration:(Block_time.Span.of_ms 30000L)
×
582
                    time_controller
583
                    (Strict_pipe.Reader.fold_until processed_transition_reader
×
584
                       ~init:branch
585
                       ~f:(fun
586
                            remaining_breadcrumbs
587
                            (`Transition newly_added_transition, _, _)
588
                          ->
589
                         Deferred.return
×
590
                           ( match remaining_breadcrumbs with
591
                           | next_expected_breadcrumb :: tail ->
×
592
                               [%test_eq: State_hash.t]
×
593
                                 (Transition_frontier.Breadcrumb.state_hash
×
594
                                    next_expected_breadcrumb )
595
                                 (Mina_block.Validated.state_hash
×
596
                                    newly_added_transition ) ;
597
                               [%log info]
×
598
                                 ~metadata:
599
                                   [ ( "height"
600
                                     , `Int
601
                                         ( newly_added_transition
602
                                         |> Mina_block.Validated.forget
×
603
                                         |> With_hash.data |> Mina_block.header
×
604
                                         |> Mina_block.Header.protocol_state
×
605
                                         |> Protocol_state.consensus_state
×
606
                                         |> Consensus.Data.Consensus_state
607
                                            .blockchain_length
×
608
                                         |> Mina_numbers.Length.to_uint32
×
609
                                         |> Unsigned.UInt32.to_int ) )
×
610
                                   ]
611
                                 "transition of $height passed processor" ;
612
                               if List.is_empty tail then `Stop true
×
613
                               else `Continue tail
×
614
                           | [] ->
×
615
                               `Stop false ) ) )
616
                with
617
                | `Timeout ->
×
618
                    failwith "test timed out"
619
                | `Ok (`Eof _) ->
×
620
                    failwith "pipe closed unexpectedly"
621
                | `Ok (`Terminated x) ->
×
622
                    x ) ) )
623
  end )
10✔
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