package tezos-protocol-demo-noops

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

Source file main.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
(*****************************************************************************)
(*                                                                           *)
(* Open Source License                                                       *)
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.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.                                                 *)
(*                                                                           *)
(*****************************************************************************)

let max_block_length = 100

let max_operation_data_length = 0

let validation_passes = []

let acceptable_pass _op = None

type block_header_data = string

let block_header_data_encoding =
  Data_encoding.(obj1 (req "block_header_data" (string Plain)))

type block_header = {
  shell : Block_header.shell_header;
  protocol_data : block_header_data;
}

type block_header_metadata = unit

let block_header_metadata_encoding_with_legacy_attestation_name =
  Data_encoding.unit

let block_header_metadata_encoding = Data_encoding.unit

type operation_data = unit

let operation_data_encoding = Data_encoding.unit

let operation_data_encoding_with_legacy_attestation_name =
  operation_data_encoding

type operation_receipt = unit

let operation_receipt_encoding = Data_encoding.unit

let operation_receipt_encoding_with_legacy_attestation_name =
  operation_receipt_encoding

let operation_data_and_receipt_encoding =
  Data_encoding.conv
    (function ((), ()) -> ())
    (fun () -> ((), ()))
    Data_encoding.unit

let operation_data_and_receipt_encoding_with_legacy_attestation_name =
  operation_data_and_receipt_encoding

type operation = {
  shell : Operation.shell_header;
  protocol_data : operation_data;
}

let compare_operations _ _ = 0

type validation_state = {context : Context.t; fitness : Fitness.t}

type application_state = validation_state

type mode =
  | Application of block_header
  | Partial_validation of block_header
  | Construction of {
      predecessor_hash : Block_hash.t;
      timestamp : Time.t;
      block_header_data : block_header_data;
    }
  | Partial_construction of {
      predecessor_hash : Block_hash.t;
      timestamp : Time.t;
    }

(* Same as genesis *)
let fitness_from_level level =
  let version_number = "\002" in
  let int32_to_bytes i =
    let b = Bytes.make 4 '\000' in
    TzEndian.set_int32 b 0 i ;
    b
  in
  [
    Bytes.of_string version_number;
    int32_to_bytes level ;
    Bytes.empty ;
    int32_to_bytes (-1l) ;
    int32_to_bytes 0l ;
  ]

let begin_validation context _chain_id mode
    ~(predecessor : Block_header.shell_header) =
  let fitness =
    match mode with
    | Application block_header | Partial_validation block_header ->
        block_header.shell.fitness
    | Construction _ | Partial_construction _ ->
        fitness_from_level Int32.(succ predecessor.level)
  in
  return {context; fitness}

let begin_application = begin_validation

type error += No_error

let () =
  register_error_kind
    `Permanent
    ~id:"no-error"
    ~title:"No error"
    ~description:"There is no error, this is a no-op protocol"
    ~pp:(fun ppf () -> Format.fprintf ppf "@[<h 0>No error in no-op protocol@]")
    Data_encoding.unit
    (function No_error -> Some () | _ -> None)
    (fun () -> No_error)

let validate_operation ?check_signature:_ _state _oph _op = tzfail No_error

let apply_operation _state _oph _op = tzfail No_error

let finalize_validation _state = return_unit

let finalize_application application_state _shell_header =
  return
    ( {
        Updater.message = None;
        context = application_state.context;
        fitness = application_state.fitness;
        max_operations_ttl = 0;
        last_preserved_block_level = 0l;
        last_finalized_block_level = 0l ;
      },
      () )

let init _chain_id context block_header =
  let open Lwt_result_syntax in
  let open Block_header in
  let fitness = block_header.fitness in
  let*! context = Context.Cache.set_cache_layout context [] in
  return
    {
      Updater.message = None;
      context;
      fitness;
      max_operations_ttl = 0;
      last_finalized_block_level = 0l;
      last_preserved_block_level = 0l;
    }

let value_of_key ~chain_id:_ ~predecessor_context:_ ~predecessor_timestamp:_
    ~predecessor_level:_ ~predecessor_fitness:_ ~predecessor:_ ~timestamp:_ =
  return (fun _ -> tzfail No_error)

let rpc_services = RPC_directory.empty

(* Fake mempool *)
module Mempool = struct
  type t = unit

  type validation_info = unit

  type conflict_handler =
    existing_operation:Operation_hash.t * operation ->
    new_operation:Operation_hash.t * operation ->
    [`Keep | `Replace]

  type operation_conflict =
    | Operation_conflict of {
        existing : Operation_hash.t;
        new_operation : Operation_hash.t;
      }

  type add_result =
    | Added
    | Replaced of {removed : Operation_hash.t}
    | Unchanged

  type add_error =
    | Validation_error of error trace
    | Add_conflict of operation_conflict

  type merge_error =
    | Incompatible_mempool
    | Merge_conflict of operation_conflict

  let init _ _ ~head_hash:_ ~head:_  = Lwt.return_ok ((), ())

  let encoding = Data_encoding.unit

  let add_operation ?check_signature:_ ?conflict_handler:_ _ _ _ =
    Lwt.return_ok ((), Unchanged)

  let remove_operation () _ = ()

  let merge ?conflict_handler:_ () () = Ok ()

  let operations () = Operation_hash.Map.empty
end
OCaml

Innovation. Community. Security.