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

MinaProtocol / mina / 177

06 May 2025 07:33AM UTC coverage: 35.868% (-24.9%) from 60.761%
177

push

buildkite

web-flow
Merge pull request #17152 from MinaProtocol/dw/replace-codeowners-master

CODEOWNERS: add Deepthi, George and Danny

25597 of 71365 relevant lines covered (35.87%)

26668.14 hits per line

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

15.04
/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

27
  val proof_cache_db : Proof_cache_tag.cache_db
28
end
29

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

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

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

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

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

465
let%test_module "Transition_handler.Processor tests" =
466
  ( module struct
467
    open Async
468
    open Pipe_lib
469

470
    let () =
471
      Backtrace.elide := false ;
472
      Printexc.record_backtrace true ;
473
      Async.Scheduler.set_record_backtraces true
×
474

475
    let logger = Logger.null ()
×
476

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

486
               let transport () _ = ()
×
487
             end )
488
             () )
489
        ()
490

491
    let precomputed_values = Lazy.force Precomputed_values.for_unit_tests
×
492

493
    let proof_level = precomputed_values.proof_level
494

495
    let constraint_constants = precomputed_values.constraint_constants
496

497
    let time_controller = Block_time.Controller.basic ~logger
498

499
    let trust_system = Trust_system.null ()
×
500

501
    let verifier =
502
      Async.Thread_safe.block_on_async_exn (fun () ->
×
503
          Verifier.For_tests.default ~constraint_constants ~logger ~proof_level
×
504
            () )
505

506
    module Context = struct
507
      let logger = logger
508

509
      let precomputed_values = precomputed_values
510

511
      let constraint_constants = constraint_constants
512

513
      let consensus_constants = precomputed_values.consensus_constants
514

515
      let proof_cache_db = Proof_cache_tag.For_tests.create_db ()
×
516
    end
517

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

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