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

MinaProtocol / mina / 2863

05 Nov 2024 06:20PM UTC coverage: 30.754% (-16.6%) from 47.311%
2863

push

buildkite

web-flow
Merge pull request #16296 from MinaProtocol/dkijania/more_multi_jobs

more multi jobs in CI

20276 of 65930 relevant lines covered (30.75%)

8631.7 hits per line

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

1.54
/src/lib/transition_handler/breadcrumb_builder.ml
1
open Mina_base
1✔
2
open Core
3
open Async
4
open Cache_lib
5
open Network_peer
6

7
let build_subtrees_of_breadcrumbs ~logger ~precomputed_values ~verifier
8
    ~trust_system ~frontier ~initial_hash subtrees_of_enveloped_transitions =
9
  let missing_parent_msg =
×
10
    Printf.sprintf
11
      "Transition frontier already garbage-collected the parent of %s"
12
      (Mina_base.State_hash.to_base58_check initial_hash)
×
13
  in
14
  (* If the breadcrumb we are targeting is removed from the transition
15
   * frontier while we're catching up, it means this path is not on the
16
   * critical path that has been chosen in the frontier. As such, we should
17
   * drop it on the floor. *)
18
  let breadcrumb_if_present logger =
×
19
    match Transition_frontier.find frontier initial_hash with
×
20
    | None ->
×
21
        [%log error]
×
22
          ~metadata:
23
            [ ("state_hash", Mina_base.State_hash.to_yojson initial_hash)
×
24
            ; ( "transition_hashes"
25
              , `List
26
                  (List.map subtrees_of_enveloped_transitions ~f:(fun subtree ->
×
27
                       Rose_tree.to_yojson
×
28
                         (fun (enveloped_transitions, _vc) ->
29
                           let transition, _ =
×
30
                             enveloped_transitions |> Cached.peek
×
31
                             |> Envelope.Incoming.data
32
                           in
33
                           Mina_base.State_hash.(
×
34
                             to_yojson (With_state_hashes.state_hash transition))
×
35
                           )
36
                         subtree ) ) )
37
            ]
38
          "Transition frontier already garbage-collected the parent of \
39
           $state_hash" ;
40
        Or_error.error_string missing_parent_msg
×
41
    | Some breadcrumb ->
×
42
        Or_error.return breadcrumb
43
  in
44
  Deferred.Or_error.List.map subtrees_of_enveloped_transitions
45
    ~f:(fun subtree_of_enveloped_transitions ->
46
      let%bind.Deferred.Or_error init_breadcrumb =
47
        breadcrumb_if_present
×
48
          (Logger.extend logger
×
49
             [ ("Check", `String "Before creating breadcrumb") ] )
50
        |> Deferred.return
×
51
      in
52
      Rose_tree.Deferred.Or_error.fold_map_over_subtrees
×
53
        subtree_of_enveloped_transitions
54
        ~init:(Cached.pure init_breadcrumb, None)
×
55
        ~f:(fun (cached_parent, _parent_vc)
56
                ( Rose_tree.T ((cached_enveloped_transition, valid_cb), _) as
57
                subtree ) ->
58
          let%map.Deferred cached_result =
59
            Cached.transform cached_enveloped_transition
×
60
              ~f:(fun enveloped_transition ->
61
                let open Deferred.Or_error.Let_syntax in
×
62
                let transition_with_initial_validation =
63
                  Envelope.Incoming.data enveloped_transition
64
                in
65
                let transition_receipt_time = Some (Time.now ()) in
×
66
                let transition_with_hash, _ =
67
                  transition_with_initial_validation
68
                in
69
                let mostly_validated_transition =
70
                  (* TODO: handle this edge case more gracefully *)
71
                  (* since we are building a disconnected subtree of breadcrumbs,
72
                   * we skip this step in validation *)
73
                  Mina_block.Validation.skip_frontier_dependencies_validation
74
                    `This_block_belongs_to_a_detached_subtree
75
                    transition_with_initial_validation
76
                in
77
                let sender = Envelope.Incoming.sender enveloped_transition in
×
78
                let parent = Cached.peek cached_parent in
×
79
                let expected_parent_hash =
×
80
                  Transition_frontier.Breadcrumb.state_hash parent
81
                in
82
                let actual_parent_hash =
×
83
                  transition_with_hash |> With_hash.data |> Mina_block.header
×
84
                  |> Mina_block.Header.protocol_state
×
85
                  |> Mina_state.Protocol_state.previous_state_hash
86
                in
87
                let%bind () =
88
                  Deferred.return
×
89
                    (Result.ok_if_true
×
90
                       (State_hash.equal actual_parent_hash expected_parent_hash)
×
91
                       ~error:
92
                         (Error.of_string
×
93
                            "Previous external transition hash does not equal \
94
                             to current external transition's parent hash" ) )
95
                in
96
                let open Deferred.Let_syntax in
×
97
                match%bind
98
                  Deferred.Or_error.try_with ~here:[%here] (fun () ->
×
99
                      Transition_frontier.Breadcrumb.build ~logger
×
100
                        ~precomputed_values ~verifier ~trust_system ~parent
101
                        ~transition:mostly_validated_transition
102
                        ~get_completed_work:(Fn.const None)
×
103
                        ~sender:(Some sender) ~transition_receipt_time () )
104
                with
105
                | Error _ ->
×
106
                    Deferred.return @@ Or_error.error_string missing_parent_msg
×
107
                | Ok result -> (
×
108
                    match result with
109
                    | Ok new_breadcrumb ->
×
110
                        let open Result.Let_syntax in
111
                        Mina_metrics.(
112
                          Counter.inc_one
×
113
                            Transition_frontier_controller
114
                            .breadcrumbs_built_by_builder) ;
115
                        Deferred.return
116
                          (let%map (_ : Transition_frontier.Breadcrumb.t) =
117
                             breadcrumb_if_present
×
118
                               (Logger.extend logger
×
119
                                  [ ( "Check"
120
                                    , `String "After creating breadcrumb" )
121
                                  ] )
122
                           in
123
                           new_breadcrumb )
×
124
                    | Error err -> (
×
125
                        (* propagate bans through subtree *)
126
                        let subtree_nodes = Rose_tree.flatten subtree in
127
                        let ip_address_set =
×
128
                          let sender_from_tree_node node =
129
                            Envelope.Incoming.sender (Cached.peek node)
×
130
                          in
131
                          List.fold subtree_nodes
×
132
                            ~init:(Set.empty (module Network_peer.Peer))
×
133
                            ~f:(fun inet_addrs (node, _vc) ->
134
                              match sender_from_tree_node node with
×
135
                              | Local ->
×
136
                                  failwith
137
                                    "build_subtrees_of_breadcrumbs: sender of \
138
                                     external transition should not be Local"
139
                              | Remote peer ->
×
140
                                  Set.add inet_addrs peer )
141
                        in
142
                        let ip_addresses = Set.to_list ip_address_set in
143
                        let trust_system_record_invalid msg error =
×
144
                          let%map () =
145
                            Deferred.List.iter ip_addresses ~f:(fun ip_addr ->
×
146
                                Trust_system.record trust_system logger ip_addr
×
147
                                  ( Trust_system.Actions
148
                                    .Gossiped_invalid_transition
149
                                  , Some (msg, []) ) )
150
                          in
151
                          Error error
×
152
                        in
153
                        match err with
154
                        | `Invalid_staged_ledger_hash error ->
×
155
                            trust_system_record_invalid
156
                              "invalid staged ledger hash" error
157
                        | `Invalid_staged_ledger_diff error ->
×
158
                            trust_system_record_invalid
159
                              "invalid staged ledger diff" error
160
                        | `Fatal_error exn ->
×
161
                            Deferred.return (Or_error.of_exn exn) ) ) )
×
162
            |> Cached.sequence_deferred
×
163
          in
164
          Result.map ~f:(Fn.flip Tuple2.create valid_cb)
×
165
          @@ Cached.sequence_result cached_result ) )
×
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