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

MinaProtocol / mina / 77

13 Apr 2025 07:49AM UTC coverage: 35.871% (-24.9%) from 60.793%
77

push

buildkite

web-flow
Merge pull request #16866 from MinaProtocol/georgeee/use-stable-zkapp_command-in-network-pool

Use Zkapp_command.Stable.Latest in network_pool

1 of 29 new or added lines in 2 files covered. (3.45%)

16190 existing lines in 348 files now uncovered.

25656 of 71523 relevant lines covered (35.87%)

34337.21 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

8✔
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
    =
UNCOV
38
  Cached.transform cached ~f:transform_cached
×
UNCOV
39
  |> Cached.sequence_deferred
×
UNCOV
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) =
UNCOV
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
×
UNCOV
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
UNCOV
55
  [%log debug] "add_and_finalize $state_hash %s callback"
×
56
    ~metadata:
57
      [ ( "state_hash"
UNCOV
58
        , Transition_frontier.Breadcrumb.state_hash breadcrumb
×
UNCOV
59
          |> State_hash.to_yojson )
×
60
      ]
UNCOV
61
    (Option.value_map valid_cb ~default:"without" ~f:(const "with")) ;
×
UNCOV
62
  let state_hash = Transition_frontier.Breadcrumb.state_hash breadcrumb in
×
UNCOV
63
  Internal_tracing.with_state_hash state_hash
×
64
  @@ fun () ->
UNCOV
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 )
×
UNCOV
79
    else Transition_frontier.add_breadcrumb_exn frontier breadcrumb
×
80
  in
UNCOV
81
  ( match source with
×
82
  | `Internal ->
×
83
      ()
UNCOV
84
  | _ ->
×
85
      let transition_time =
UNCOV
86
        transition |> Mina_block.Validated.header
×
UNCOV
87
        |> Mina_block.Header.protocol_state |> Protocol_state.consensus_state
×
88
        |> Consensus.Data.Consensus_state.consensus_time
89
      in
UNCOV
90
      let time_elapsed =
×
91
        Block_time.diff
UNCOV
92
          (Block_time.now time_controller)
×
UNCOV
93
          (Consensus.Data.Consensus_time.to_time ~constants:consensus_constants
×
94
             transition_time )
95
      in
UNCOV
96
      Inclusion_time.update (Block_time.Span.to_time_span time_elapsed) ) ;
×
UNCOV
97
  [%log internal] "Add_and_finalize_done" ;
×
UNCOV
98
  if Writer.is_closed processed_transition_writer then
×
99
    Or_error.error_string "processed transitions closed"
×
UNCOV
100
  else (
×
101
    Writer.write processed_transition_writer
102
      (`Transition transition, `Source source, `Valid_cb valid_cb) ;
UNCOV
103
    Catchup_scheduler.notify catchup_scheduler
×
UNCOV
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 open Context in
3✔
113
  let header, transition_hash, transition_receipt_time, sender, validation =
114
    match block_or_header with
115
    | `Block cached_env ->
3✔
116
        let env = Cached.peek cached_env in
117
        let block, v = Envelope.Incoming.data env in
3✔
118
        ( Mina_block.header @@ With_hash.data block
3✔
119
        , State_hash.With_state_hashes.state_hash block
3✔
120
        , Some (Envelope.Incoming.received_at env)
3✔
121
        , Envelope.Incoming.sender env
3✔
122
        , v )
123
    | `Header env ->
×
124
        let h, v = Envelope.Incoming.data env in
125
        ( With_hash.data h
×
126
        , State_hash.With_state_hashes.state_hash h
×
127
        , Some (Envelope.Incoming.received_at env)
×
128
        , Envelope.Incoming.sender env
×
129
        , v )
130
  in
131
  let parent_hash =
132
    Protocol_state.previous_state_hash (Header.protocol_state header)
3✔
133
  in
134
  let root_block =
3✔
135
    Transition_frontier.(Breadcrumb.block_with_hash @@ root frontier)
3✔
136
  in
137
  let metadata = [ ("state_hash", State_hash.to_yojson transition_hash) ] in
3✔
138
  let state_hash = transition_hash in
139
  Internal_tracing.with_state_hash state_hash
140
  @@ fun () ->
141
  [%log internal] "@block_metadata"
3✔
142
    ~metadata:
143
      [ ( "blockchain_length"
144
        , Mina_numbers.Length.to_yojson (Header.blockchain_length header) )
3✔
145
      ] ;
146
  [%log internal] "Begin_external_block_processing" ;
3✔
147
  let handle_not_selected () =
3✔
148
    [%log internal] "Failure"
×
149
      ~metadata:[ ("reason", `String "Not_selected_over_frontier_root") ] ;
150
    Trust_system.record_envelope_sender trust_system logger sender
×
151
      ( Trust_system.Actions.Gossiped_invalid_transition
152
      , Some
153
          ( "The transition with hash $state_hash was not selected over the \
154
             transition frontier root"
155
          , metadata ) )
156
  in
157
  match block_or_header with
158
  | `Header env -> (
×
159
      let header_with_hash, _ = Envelope.Incoming.data env in
160
      [%log internal] "Validate_frontier_dependencies" ;
×
161
      match
×
162
        Mina_block.Validation.validate_frontier_dependencies
163
          ~context:(module Context)
164
          ~root_block ~is_block_in_frontier ~to_header:ident
165
          (Envelope.Incoming.data env)
×
166
      with
167
      | Ok _ | Error `Parent_missing_from_frontier ->
×
168
          [%log internal] "Schedule_catchup" ;
×
169
          Catchup_scheduler.watch_header catchup_scheduler ~valid_cb
×
170
            ~header_with_hash ;
171
          return ()
×
172
      | Error `Not_selected_over_frontier_root ->
×
173
          handle_not_selected ()
174
      | Error `Already_in_frontier ->
×
175
          [%log internal] "Failure"
×
176
            ~metadata:[ ("reason", `String "Already_in_frontier") ] ;
177
          [%log warn] ~metadata
×
178
            "Refusing to process the transition with hash $state_hash because \
179
             it is already in the transition frontier" ;
180
          return () )
×
181
  | `Block cached_initially_validated_transition ->
3✔
182
      Deferred.ignore_m
183
      @@
184
      let open Deferred.Result.Let_syntax in
185
      let%bind mostly_validated_transition =
186
        let open Deferred.Let_syntax in
187
        let initially_validated_transition =
188
          Cached.peek cached_initially_validated_transition
3✔
189
          |> Envelope.Incoming.data
190
        in
191
        [%log internal] "Validate_frontier_dependencies" ;
3✔
192
        match
3✔
193
          Mina_block.Validation.validate_frontier_dependencies
194
            ~context:(module Context)
195
            ~root_block ~is_block_in_frontier ~to_header:Mina_block.header
196
            initially_validated_transition
197
        with
UNCOV
198
        | Ok t ->
×
UNCOV
199
            return (Ok t)
×
200
        | Error `Not_selected_over_frontier_root ->
×
201
            let (_ : Mina_block.initial_valid_block Envelope.Incoming.t) =
202
              Cached.invalidate_with_failure
203
                cached_initially_validated_transition
204
            in
205
            let%map () = handle_not_selected () in
×
206
            Error ()
×
207
        | Error `Already_in_frontier ->
3✔
208
            [%log internal] "Failure"
3✔
209
              ~metadata:[ ("reason", `String "Already_in_frontier") ] ;
210
            [%log warn] ~metadata
3✔
211
              "Refusing to process the transition with hash $state_hash \
212
               because is is already in the transition frontier" ;
213
            let (_ : Mina_block.initial_valid_block Envelope.Incoming.t) =
3✔
214
              Cached.invalidate_with_failure
215
                cached_initially_validated_transition
216
            in
217
            return (Error ())
3✔
218
        | Error `Parent_missing_from_frontier -> (
×
219
            [%log internal] "Schedule_catchup" ;
×
220
            match validation with
×
221
            | ( _
×
222
              , _
223
              , _
224
              , (`Delta_block_chain, Truth.True delta_state_hashes)
225
              , _
226
              , _
227
              , _ ) ->
228
                let timeout_duration =
229
                  Option.fold
230
                    (Transition_frontier.find frontier
×
231
                       (Mina_stdlib.Nonempty_list.head delta_state_hashes) )
×
232
                    ~init:(Block_time.Span.of_ms 0L)
×
233
                    ~f:(fun _ _ -> catchup_timeout_duration precomputed_values)
×
234
                in
235
                Catchup_scheduler.watch catchup_scheduler ~timeout_duration
×
236
                  ~cached_transition:cached_initially_validated_transition
237
                  ~valid_cb ;
238
                return (Error ()) )
×
239
      in
240
      (* TODO: only access parent in transition frontier once (already done in call to validate dependencies) #2485 *)
UNCOV
241
      [%log internal] "Find_parent_breadcrumb" ;
×
UNCOV
242
      let parent_breadcrumb =
×
243
        Transition_frontier.find_exn frontier parent_hash
244
      in
245
      let%bind breadcrumb =
UNCOV
246
        cached_transform_deferred_result cached_initially_validated_transition
×
247
          ~transform_cached:(fun _ ->
UNCOV
248
            Transition_frontier.Breadcrumb.build ~logger ~precomputed_values
×
249
              ~verifier ~get_completed_work ~trust_system
250
              ~transition_receipt_time ~sender:(Some sender)
251
              ~parent:parent_breadcrumb ~transition:mostly_validated_transition
252
              (* TODO: Can we skip here? *) () )
253
          ~transform_result:(function
254
            | Error (`Invalid_staged_ledger_hash error)
×
255
            | Error (`Invalid_staged_ledger_diff error) ->
×
256
                Internal_tracing.with_state_hash state_hash
257
                @@ fun () ->
258
                [%log internal] "Failure"
×
259
                  ~metadata:[ ("reason", `String (Error.to_string_hum error)) ] ;
×
260
                [%log error]
×
261
                  ~metadata:
262
                    (metadata @ [ ("error", Error_json.error_to_yojson error) ])
×
263
                  "Error while building breadcrumb in the transition handler \
264
                   processor: $error" ;
265
                Deferred.return (Error ())
×
266
            | Error (`Fatal_error exn) ->
×
267
                Internal_tracing.with_state_hash state_hash
268
                @@ fun () ->
269
                [%log internal] "Failure"
×
270
                  ~metadata:[ ("reason", `String "Fatal error") ] ;
271
                raise exn
×
UNCOV
272
            | Ok breadcrumb ->
×
273
                Deferred.return (Ok breadcrumb) )
274
      in
UNCOV
275
      Mina_metrics.(
×
UNCOV
276
        Counter.inc_one
×
277
          Transition_frontier_controller.breadcrumbs_built_by_processor) ;
278
      let%map.Deferred result =
UNCOV
279
        add_and_finalize ~logger ~frontier ~catchup_scheduler
×
280
          ~processed_transition_writer ~only_if_present:false ~time_controller
281
          ~source:`Gossip breadcrumb ~precomputed_values ~valid_cb
282
      in
UNCOV
283
      ( match result with
×
UNCOV
284
      | Ok () ->
×
UNCOV
285
          [%log internal] "Breadcrumb_integrated"
×
286
      | Error err ->
×
287
          [%log internal] "Failure"
×
288
            ~metadata:[ ("reason", `String (Error.to_string_hum err)) ] ) ;
×
289
      Result.return result
290

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

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

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

UNCOV
473
    let logger = Logger.null ()
×
474

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

UNCOV
484
               let transport () _ = ()
×
485
             end )
486
             () )
487
        ()
488

UNCOV
489
    let precomputed_values = Lazy.force Precomputed_values.for_unit_tests
×
490

491
    let proof_level = precomputed_values.proof_level
492

493
    let constraint_constants = precomputed_values.constraint_constants
494

495
    let time_controller = Block_time.Controller.basic ~logger
496

UNCOV
497
    let trust_system = Trust_system.null ()
×
498

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

504
    module Context = struct
505
      let logger = logger
506

507
      let precomputed_values = precomputed_values
508

509
      let constraint_constants = constraint_constants
510

511
      let consensus_constants = precomputed_values.consensus_constants
512
    end
513

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

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