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

MinaProtocol / mina / 60

07 Apr 2025 05:16PM UTC coverage: 32.433%. First build
60

push

buildkite

web-flow
Merge pull request #16873 from MinaProtocol/amcie-merging-release-to-master

Merging 3.1.0 release branch to master

837 of 3614 new or added lines in 177 files covered. (23.16%)

23210 of 71564 relevant lines covered (32.43%)

16793.1 hits per line

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

8.82
/src/lib/bootstrap_controller/transition_cache.ml
1
open Mina_base
4✔
2
open Core
3
open Network_peer
4

5
type initial_valid_block_or_header =
6
  [ `Block of Mina_block.initial_valid_block
7
  | `Header of Mina_block.initial_valid_header ]
8

9
type element =
10
  initial_valid_block_or_header Envelope.Incoming.t
11
  * Mina_net2.Validation_callback.t option
12

13
let header_with_hash e =
NEW
14
  match e with
×
NEW
15
  | `Block b ->
×
16
      With_hash.map ~f:Mina_block.header
NEW
17
      @@ Mina_block.Validation.block_with_hash b
×
NEW
18
  | `Header h ->
×
19
      Mina_block.Validation.header_with_hash h
20

21
(* Cache represents a graph. The key is a State_hash, which is the node in
22
   the graph, and the value is the children transitions of the node *)
23

24
type t = element list State_hash.Table.t
25

26
let create () = State_hash.Table.create ()
×
27

28
let state_hash e =
NEW
29
  State_hash.With_state_hashes.state_hash @@ header_with_hash
×
NEW
30
  @@ Envelope.Incoming.data e
×
31

32
let logger = Logger.create ()
4✔
33

34
let merge (old_env, old_vc) (new_env, new_vc) =
NEW
35
  let old_b = Envelope.Incoming.data old_env in
×
NEW
36
  let vc =
×
37
    match (old_vc, new_vc) with
NEW
38
    | Some _, Some _ ->
×
NEW
39
        [%log warn] "Received gossip on $state_hash twice"
×
40
          ~metadata:
NEW
41
            [ ("state_hash", State_hash.to_yojson @@ state_hash old_env) ] ;
×
NEW
42
        old_vc
×
NEW
43
    | None, Some _ ->
×
44
        new_vc
NEW
45
    | _ ->
×
46
        old_vc
47
  in
NEW
48
  ( Envelope.Incoming.map new_env ~f:(fun new_b ->
×
NEW
49
        match new_b with `Block _ -> new_b | _ -> old_b )
×
50
  , vc )
51

52
let add (t : t) ~parent new_child =
53
  State_hash.Table.update t parent ~f:(function
×
54
    | None ->
×
55
        [ new_child ]
56
    | Some children ->
×
57
        let children', b =
58
          List.fold children ~init:([], false) ~f:(fun (acc, b) child ->
59
              (* If state hash was already among children, existing child is
60
                 merged with the new transition.
61
                 It's needed to maintain consistency about transitions that may
62
                 come from gossip or other ways; we want to preserve some
63
                 validation callback (and we don't expect two gossips for the
64
                 same).
65
                 Also, if we received a block after receiving a header
66
                 (possible when we'll simultaneously support both old and new
67
                 gossip topics), we want to preserve a block because it's more
68
                 than a header. *)
NEW
69
              if
×
70
                (not b)
NEW
71
                && State_hash.equal
×
NEW
72
                     (state_hash @@ fst child)
×
NEW
73
                     (state_hash @@ fst new_child)
×
NEW
74
              then (merge child new_child :: acc, true)
×
NEW
75
              else (acc, b) )
×
76
        in
NEW
77
        if b then children' else new_child :: children )
×
78

79
let data t =
80
  let collected_transitions = State_hash.Table.data t |> List.concat in
×
81
  assert (
×
82
    Stdlib.List.compare_lengths collected_transitions
×
83
      (List.stable_dedup collected_transitions)
×
84
    = 0 )
85
  (* TODO: make this assertion more efficient *) ;
86
  collected_transitions
8✔
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