package tezos-protocol-005-PsBABY5H

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

Source file parameters_repr.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
(*****************************************************************************)
(*                                                                           *)
(* 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.                                                 *)
(*                                                                           *)
(*****************************************************************************)

type bootstrap_account = {
  public_key_hash : Signature.Public_key_hash.t ;
  public_key : Signature.Public_key.t option ;
  amount : Tez_repr.t ;
}

type bootstrap_contract = {
  delegate : Signature.Public_key_hash.t ;
  amount : Tez_repr.t ;
  script : Script_repr.t ;
}

type t = {
  bootstrap_accounts : bootstrap_account list ;
  bootstrap_contracts : bootstrap_contract list ;
  commitments : Commitment_repr.t list ;
  constants : Constants_repr.parametric ;
  security_deposit_ramp_up_cycles : int option ;
  no_reward_cycles : int option ;
}

let bootstrap_account_encoding =
  let open Data_encoding in
  union
    [ case (Tag 0) ~title:"Public_key_known"
        (tup2
           Signature.Public_key.encoding
           Tez_repr.encoding)
        (function
          | { public_key_hash ; public_key = Some public_key ; amount } ->
              assert (Signature.Public_key_hash.equal
                        (Signature.Public_key.hash public_key)
                        public_key_hash) ;
              Some (public_key, amount)
          | { public_key = None }  -> None)
        (fun (public_key, amount) ->
           { public_key = Some public_key ;
             public_key_hash = Signature.Public_key.hash public_key ;
             amount }) ;
      case (Tag 1) ~title:"Public_key_unknown"
        (tup2
           Signature.Public_key_hash.encoding
           Tez_repr.encoding)
        (function
          | { public_key_hash ; public_key = None ; amount } ->
              Some (public_key_hash, amount)
          | { public_key = Some _ }  -> None)
        (fun (public_key_hash, amount) ->
           { public_key = None ;
             public_key_hash ;
             amount }) ]

let bootstrap_contract_encoding =
  let open Data_encoding in
  conv
    (fun { delegate ; amount ; script } -> (delegate, amount, script))
    (fun (delegate, amount, script) -> { delegate ; amount ; script })
    (obj3
       (req "delegate" Signature.Public_key_hash.encoding)
       (req "amount" Tez_repr.encoding)
       (req "script" Script_repr.encoding))

let encoding =
  let open Data_encoding in
  conv
    (fun { bootstrap_accounts ; bootstrap_contracts ; commitments ; constants ;
           security_deposit_ramp_up_cycles ; no_reward_cycles } ->
      ((bootstrap_accounts, bootstrap_contracts, commitments,
        security_deposit_ramp_up_cycles, no_reward_cycles),
       constants))
    (fun ( (bootstrap_accounts, bootstrap_contracts, commitments,
            security_deposit_ramp_up_cycles, no_reward_cycles),
           constants) ->
      { bootstrap_accounts ; bootstrap_contracts ; commitments ; constants ;
        security_deposit_ramp_up_cycles ; no_reward_cycles })
    (merge_objs
       (obj5
          (req "bootstrap_accounts" (list bootstrap_account_encoding))
          (dft "bootstrap_contracts" (list bootstrap_contract_encoding) [])
          (dft "commitments" (list Commitment_repr.encoding) [])
          (opt "security_deposit_ramp_up_cycles" int31)
          (opt "no_reward_cycles" int31))
       Constants_repr.parametric_encoding)


(* Only for migration from 004 to 005 *)

module Proto_004 = struct

  type parametric = {
    preserved_cycles: int ;
    blocks_per_cycle: int32 ;
    blocks_per_commitment: int32 ;
    blocks_per_roll_snapshot: int32 ;
    blocks_per_voting_period: int32 ;
    time_between_blocks: Period_repr.t list ;
    endorsers_per_block: int ;
    hard_gas_limit_per_operation: Z.t ;
    hard_gas_limit_per_block: Z.t ;
    proof_of_work_threshold: int64 ;
    tokens_per_roll: Tez_repr.t ;
    michelson_maximum_type_size: int;
    seed_nonce_revelation_tip: Tez_repr.t ;
    origination_size: int ;
    block_security_deposit: Tez_repr.t ;
    endorsement_security_deposit: Tez_repr.t ;
    block_reward: Tez_repr.t ;
    endorsement_reward: Tez_repr.t ;
    cost_per_byte: Tez_repr.t ;
    hard_storage_limit_per_operation: Z.t ;
    test_chain_duration: int64 ;  (* in seconds *)
  }

  let default = {
    preserved_cycles = 5 ;
    blocks_per_cycle = 4096l ;
    blocks_per_commitment = 32l ;
    blocks_per_roll_snapshot = 256l ;
    blocks_per_voting_period = 32768l ;
    time_between_blocks =
      List.map Period_repr.of_seconds_exn [ 60L ; 75L ] ;
    endorsers_per_block = 32 ;
    hard_gas_limit_per_operation = Z.of_int 800_000 ;
    hard_gas_limit_per_block = Z.of_int 8_000_000 ;
    proof_of_work_threshold =
      Int64.(sub (shift_left 1L 46) 1L) ;
    tokens_per_roll =
      Tez_repr.(mul_exn one 8_000) ;
    michelson_maximum_type_size = 1000 ;
    seed_nonce_revelation_tip = begin
      match Tez_repr.(one /? 8L) with
      | Ok c -> c
      | Error _ -> assert false
    end ;
    origination_size = 257 ;
    block_security_deposit = Tez_repr.(mul_exn one 512) ;
    endorsement_security_deposit = Tez_repr.(mul_exn one 64) ;
    block_reward = Tez_repr.(mul_exn one 16) ;
    endorsement_reward = Tez_repr.(mul_exn one 2) ;
    hard_storage_limit_per_operation = Z.of_int 60_000 ;
    cost_per_byte = Tez_repr.of_mutez_exn 1_000L ;
    test_chain_duration = Int64.mul 32768L 60L;
  }

  (* This encoding is used to read configuration files (e.g. sandbox.json)
     where some fields can be missing, in that case they are replaced by
     the default. *)
  let constants_encoding =
    let open Data_encoding in
    conv
      (fun (c : parametric) ->
         let module Compare_time_between_blocks = Compare.List (Period_repr) in
         let module Compare_keys = Compare.List (Ed25519.Public_key) in
         let opt (=) def v = if def = v then None else Some v in
         let preserved_cycles =
           opt Compare.Int.(=)
             default.preserved_cycles c.preserved_cycles
         and blocks_per_cycle =
           opt Compare.Int32.(=)
             default.blocks_per_cycle c.blocks_per_cycle
         and blocks_per_commitment =
           opt Compare.Int32.(=)
             default.blocks_per_commitment c.blocks_per_commitment
         and blocks_per_roll_snapshot =
           opt Compare.Int32.(=)
             default.blocks_per_roll_snapshot c.blocks_per_roll_snapshot
         and blocks_per_voting_period =
           opt Compare.Int32.(=)
             default.blocks_per_voting_period c.blocks_per_voting_period
         and time_between_blocks =
           opt Compare_time_between_blocks.(=)
             default.time_between_blocks c.time_between_blocks
         and endorsers_per_block =
           opt Compare.Int.(=)
             default.endorsers_per_block c.endorsers_per_block
         and hard_gas_limit_per_operation =
           opt Compare.Z.(=)
             default.hard_gas_limit_per_operation c.hard_gas_limit_per_operation
         and hard_gas_limit_per_block =
           opt Compare.Z.(=)
             default.hard_gas_limit_per_block c.hard_gas_limit_per_block
         and proof_of_work_threshold =
           opt Compare.Int64.(=)
             default.proof_of_work_threshold c.proof_of_work_threshold
         and tokens_per_roll =
           opt Tez_repr.(=)
             default.tokens_per_roll c.tokens_per_roll
         and michelson_maximum_type_size =
           opt Compare.Int.(=)
             default.michelson_maximum_type_size c.michelson_maximum_type_size
         and seed_nonce_revelation_tip =
           opt Tez_repr.(=)
             default.seed_nonce_revelation_tip c.seed_nonce_revelation_tip
         and origination_size =
           opt Compare.Int.(=)
             default.origination_size c.origination_size
         and block_security_deposit =
           opt Tez_repr.(=)
             default.block_security_deposit c.block_security_deposit
         and endorsement_security_deposit =
           opt Tez_repr.(=)
             default.endorsement_security_deposit c.endorsement_security_deposit
         and block_reward =
           opt Tez_repr.(=)
             default.block_reward c.block_reward
         and endorsement_reward =
           opt Tez_repr.(=)
             default.endorsement_reward c.endorsement_reward
         and cost_per_byte =
           opt Tez_repr.(=)
             default.cost_per_byte c.cost_per_byte
         and hard_storage_limit_per_operation =
           opt Compare.Z.(=)
             default.hard_storage_limit_per_operation c.hard_storage_limit_per_operation
         and test_chain_duration =
           opt Compare.Int64.(=)
             default.test_chain_duration c.test_chain_duration
         in
         (( preserved_cycles,
            blocks_per_cycle,
            blocks_per_commitment,
            blocks_per_roll_snapshot,
            blocks_per_voting_period,
            time_between_blocks,
            endorsers_per_block,
            hard_gas_limit_per_operation,
            hard_gas_limit_per_block),
          ((proof_of_work_threshold,
            tokens_per_roll,
            michelson_maximum_type_size,
            seed_nonce_revelation_tip,
            origination_size,
            block_security_deposit,
            endorsement_security_deposit,
            block_reward),
           (endorsement_reward,
            cost_per_byte,
            hard_storage_limit_per_operation,
            test_chain_duration))))
      (fun (( preserved_cycles,
              blocks_per_cycle,
              blocks_per_commitment,
              blocks_per_roll_snapshot,
              blocks_per_voting_period,
              time_between_blocks,
              endorsers_per_block,
              hard_gas_limit_per_operation,
              hard_gas_limit_per_block),
            ((proof_of_work_threshold,
              tokens_per_roll,
              michelson_maximum_type_size,
              seed_nonce_revelation_tip,
              origination_size,
              block_security_deposit,
              endorsement_security_deposit,
              block_reward),
             (endorsement_reward,
              cost_per_byte,
              hard_storage_limit_per_operation,
              test_chain_duration))) ->
        let unopt def = function None -> def | Some v -> v in
        { preserved_cycles =
            unopt default.preserved_cycles preserved_cycles ;
          blocks_per_cycle =
            unopt default.blocks_per_cycle blocks_per_cycle ;
          blocks_per_commitment =
            unopt default.blocks_per_commitment blocks_per_commitment ;
          blocks_per_roll_snapshot =
            unopt default.blocks_per_roll_snapshot blocks_per_roll_snapshot ;
          blocks_per_voting_period =
            unopt default.blocks_per_voting_period blocks_per_voting_period ;
          time_between_blocks =
            unopt default.time_between_blocks @@
            time_between_blocks ;
          endorsers_per_block =
            unopt default.endorsers_per_block endorsers_per_block ;
          hard_gas_limit_per_operation =
            unopt default.hard_gas_limit_per_operation hard_gas_limit_per_operation ;
          hard_gas_limit_per_block =
            unopt default.hard_gas_limit_per_block hard_gas_limit_per_block ;
          proof_of_work_threshold =
            unopt default.proof_of_work_threshold proof_of_work_threshold ;
          tokens_per_roll =
            unopt default.tokens_per_roll tokens_per_roll ;
          michelson_maximum_type_size =
            unopt default.michelson_maximum_type_size michelson_maximum_type_size ;
          seed_nonce_revelation_tip =
            unopt default.seed_nonce_revelation_tip seed_nonce_revelation_tip ;
          origination_size =
            unopt default.origination_size origination_size ;
          block_security_deposit =
            unopt default.block_security_deposit block_security_deposit ;
          endorsement_security_deposit =
            unopt default.endorsement_security_deposit endorsement_security_deposit ;
          block_reward =
            unopt default.block_reward block_reward ;
          endorsement_reward =
            unopt default.endorsement_reward endorsement_reward ;
          cost_per_byte =
            unopt default.cost_per_byte cost_per_byte ;
          hard_storage_limit_per_operation =
            unopt default.hard_storage_limit_per_operation hard_storage_limit_per_operation ;
          test_chain_duration =
            unopt default.test_chain_duration test_chain_duration ;
        } )
      (merge_objs
         (obj9
            (opt "preserved_cycles" uint8)
            (opt "blocks_per_cycle" int32)
            (opt "blocks_per_commitment" int32)
            (opt "blocks_per_roll_snapshot" int32)
            (opt "blocks_per_voting_period" int32)
            (opt "time_between_blocks" (list Period_repr.encoding))
            (opt "endorsers_per_block" uint16)
            (opt "hard_gas_limit_per_operation" z)
            (opt "hard_gas_limit_per_block" z))
         (merge_objs
            (obj8
               (opt "proof_of_work_threshold" int64)
               (opt "tokens_per_roll" Tez_repr.encoding)
               (opt "michelson_maximum_type_size" uint16)
               (opt "seed_nonce_revelation_tip" Tez_repr.encoding)
               (opt "origination_size" int31)
               (opt "block_security_deposit" Tez_repr.encoding)
               (opt "endorsement_security_deposit" Tez_repr.encoding)
               (opt "block_reward" Tez_repr.encoding))
            (obj4
               (opt "endorsement_reward" Tez_repr.encoding)
               (opt "cost_per_byte" Tez_repr.encoding)
               (opt "hard_storage_limit_per_operation" z)
               (opt "test_chain_duration" int64))))

end
OCaml

Innovation. Community. Security.