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

MinaProtocol / mina / 767

04 Nov 2025 01:59PM UTC coverage: 32.374% (-4.5%) from 36.902%
767

push

buildkite

web-flow
Merge pull request #18063 from MinaProtocol/lyh/compat-into-dev-nov4-2025

Merge compatible into develop Nov. 4th 2025

87 of 228 new or added lines in 10 files covered. (38.16%)

3416 existing lines in 136 files now uncovered.

23591 of 72871 relevant lines covered (32.37%)

26590.67 hits per line

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

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

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

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

21
  val precomputed_values : Precomputed_values.t
22

23
  val constraint_constants : Genesis_constants.Constraint_constants.t
24

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

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

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

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

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

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

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

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