package octez-shell-libs

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file chain_validator_worker_state.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
(*****************************************************************************)
(*                                                                           *)
(* Open Source License                                                       *)
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com>     *)
(* Copyright (c) 2020 Nomadic Labs. <contact@nomadic-labs.com>               *)
(*                                                                           *)
(* Permission is hereby granted, free of charge, to any person obtaining a   *)
(* copy of this software and associated documentation files (the "Software"),*)
(* to deal in the Software without restriction, including without limitation *)
(* the rights to use, copy, modify, merge, publish, distribute, sublicense,  *)
(* and/or sell copies of the Software, and to permit persons to whom the     *)
(* Software is furnished to do so, subject to the following conditions:      *)
(*                                                                           *)
(* The above copyright notice and this permission notice shall be included   *)
(* in all copies or substantial portions of the Software.                    *)
(*                                                                           *)
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  *)
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL   *)
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING   *)
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER       *)
(* DEALINGS IN THE SOFTWARE.                                                 *)
(*                                                                           *)
(*****************************************************************************)

module Request = struct
  type view = Hash of Block_hash.t | PeerId of P2p_peer.Id.t

  let encoding =
    let open Data_encoding in
    union
      [
        case
          (Tag 0)
          ~title:"Hash"
          (obj1 (req "hash" Block_hash.encoding))
          (function Hash h -> Some h | _ -> None)
          (fun h -> Hash h);
        case
          (Tag 1)
          ~title:"Peer_id"
          (obj1 (req "peer_id" P2p_peer.Id.encoding))
          (function PeerId pid -> Some pid | _ -> None)
          (fun pid -> PeerId pid);
      ]

  let pp ppf = function
    | Hash h -> Block_hash.pp ppf h
    | PeerId pid -> P2p_peer.Id.pp ppf pid
end

type synchronisation_status =
  | Synchronised of {is_chain_stuck : bool}
  | Not_synchronised

let sync_status_encoding =
  let open Data_encoding in
  def
    "chain_status"
    ~description:
      "If 'unsynced', the node is not currently synchronized with of its peers \
       (it is probably still bootstrapping and its head is lagging behind the \
       chain's).\n\
       If 'synced', the node considers itself synchronized with its peers and \
       the current head timestamp is recent.\n\
       If 'stuck', the node considers itself synchronized with its peers but \
       the chain seems to be halted from its viewpoint."
    (string_enum
       [
         ("synced", Synchronised {is_chain_stuck = false});
         ("unsynced", Not_synchronised);
         ("stuck", Synchronised {is_chain_stuck = true});
       ])

let sync_status_pp fmt = function
  | Synchronised {is_chain_stuck = true} -> Format.fprintf fmt "stuck"
  | Synchronised {is_chain_stuck = false} -> Format.fprintf fmt "synced"
  | Not_synchronised -> Format.fprintf fmt "unsynced"

type update = Ignored_head | Branch_switch | Head_increment

let update_encoding =
  let open Data_encoding in
  def
    "chain_update"
    ~description:
      "If 'ignored', the new validated block is ignored since the current head \
       fitness is better. If 'branch', we have set our head to a new validated \
       block which is not the direct successor of the previous head. If \
       'increment', the new validated head is the direct successor of the \
       previous head."
    (string_enum
       [
         ("ignored", Ignored_head);
         ("branch", Branch_switch);
         ("increment", Head_increment);
       ])

module Distributed_db_state = struct
  type table_scheduler = {table_length : int; scheduler_length : int}

  type view = {
    p2p_readers_length : int;
    active_chains_length : int;
    operation_db : table_scheduler;
    operations_db : table_scheduler;
    block_header_db : table_scheduler;
    active_connections_length : int;
    active_peers_length : int;
  }

  let table_scheduler_encoding =
    let open Data_encoding in
    conv
      (fun {table_length; scheduler_length} -> (table_length, scheduler_length))
      (fun (table_length, scheduler_length) -> {table_length; scheduler_length})
      (obj2 (req "table_length" int31) (req "scheduler_length" int31))

  let encoding =
    let open Data_encoding in
    conv
      (fun {
             p2p_readers_length;
             active_chains_length;
             operation_db;
             operations_db;
             block_header_db;
             active_connections_length;
             active_peers_length;
           } ->
        ( p2p_readers_length,
          active_chains_length,
          operation_db,
          operations_db,
          block_header_db,
          active_connections_length,
          active_peers_length ))
      (fun ( p2p_readers_length,
             active_chains_length,
             operation_db,
             operations_db,
             block_header_db,
             active_connections_length,
             active_peers_length ) ->
        {
          p2p_readers_length;
          active_chains_length;
          operation_db;
          operations_db;
          block_header_db;
          active_connections_length;
          active_peers_length;
        })
      (obj7
         (req "p2p_readers" int31)
         (req "active_chains" int31)
         (req "operation_db" table_scheduler_encoding)
         (req "operations_db" table_scheduler_encoding)
         (req "block_header_db" table_scheduler_encoding)
         (req "active_connections" int31)
         (req "active_peers" int31))
end
OCaml

Innovation. Community. Security.