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

MinaProtocol / mina / 2890

12 Nov 2024 12:30PM UTC coverage: 37.632% (-23.2%) from 60.813%
2890

push

buildkite

web-flow
Merge pull request #16333 from MinaProtocol/dkijania/port_new_deb_s3_dev

[DEV] Use new version of deb-s3 for validating job publishing

14488 of 38499 relevant lines covered (37.63%)

35927.1 hits per line

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

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

9
(* Only show stdout for failed inline tests. *)
2✔
10
open Inline_test_quiet_logs
11
open Core_kernel
12
open Async_kernel
13
open Pipe_lib.Strict_pipe
14
open Mina_base
15
open Mina_state
16
open Cache_lib
17
open Mina_block
18
open Network_peer
19

20
module type CONTEXT = sig
21
  val logger : Logger.t
22

23
  val precomputed_values : Precomputed_values.t
24

25
  val constraint_constants : Genesis_constants.Constraint_constants.t
26

27
  val consensus_constants : Consensus.Constants.t
28

29
  val compile_config : Mina_compile_config.t
30
end
31

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

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

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

111
let process_transition ~context:(module Context : CONTEXT) ~trust_system
112
    ~verifier ~get_completed_work ~frontier ~catchup_scheduler
113
    ~processed_transition_writer ~time_controller ~block_or_header ~valid_cb =
114
  let is_block_in_frontier =
3✔
115
    Fn.compose Option.is_some @@ Transition_frontier.find frontier
3✔
116
  in
117
  let open Context in
3✔
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 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 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
          ~block_window_duration:compile_config.block_window_duration
288
      in
289
      ( match result with
×
290
      | Ok () ->
×
291
          [%log internal] "Breadcrumb_integrated"
×
292
      | Error err ->
×
293
          [%log internal] "Failure"
×
294
            ~metadata:[ ("reason", `String (Error.to_string_hum err)) ] ) ;
×
295
      Result.return result
296

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

473
let%test_module "Transition_handler.Processor tests" =
474
  ( module struct
475
    open Async
476
    open Pipe_lib
477

478
    let () =
479
      Backtrace.elide := false ;
480
      Printexc.record_backtrace true ;
481
      Async.Scheduler.set_record_backtraces true
×
482

483
    let logger = Logger.create ()
×
484

485
    let precomputed_values = Lazy.force Precomputed_values.for_unit_tests
×
486

487
    let proof_level = precomputed_values.proof_level
488

489
    let constraint_constants = precomputed_values.constraint_constants
490

491
    let time_controller = Block_time.Controller.basic ~logger
492

493
    let trust_system = Trust_system.null ()
×
494

495
    let compile_config = Mina_compile_config.For_unit_tests.t
496

497
    let verifier =
498
      Async.Thread_safe.block_on_async_exn (fun () ->
×
499
          Verifier.For_tests.default ~constraint_constants ~logger ~proof_level
×
500
            () )
501

502
    module Context = struct
503
      let logger = logger
504

505
      let precomputed_values = precomputed_values
506

507
      let constraint_constants = constraint_constants
508

509
      let consensus_constants = precomputed_values.consensus_constants
510

511
      let compile_config = compile_config
512
    end
513

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

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