Source file constants_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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
let version_number_004 = "\000"
let version_number = "\001"
let proof_of_work_nonce_size = 8
let nonce_length = 32
let max_anon_ops_per_block = 132
let max_proposals_per_delegate = 20
let max_operation_data_length = 32 * 1024
let max_micheline_node_count = 50_000
let max_micheline_bytes_limit = 50_000
let max_allowed_global_constant_depth = 10_000
let cache_layout = [100_000_000]
let michelson_maximum_type_size = 2001
type fixed = unit
let fixed_encoding =
let open Data_encoding in
let uint62 =
let max_int_int64 = Int64.of_int max_int in
conv_with_guard
(fun int -> Int64.of_int int)
(fun int64 ->
if Compare.Int64.(int64 < 0L) then Error "Negative integer"
else if Compare.Int64.(int64 > max_int_int64) then
Error "Integer does not fit in 62 bits"
else ok @@ Int64.to_int int64)
int64
in
conv
(fun () ->
( proof_of_work_nonce_size,
nonce_length,
max_anon_ops_per_block,
max_operation_data_length,
max_proposals_per_delegate,
max_micheline_node_count,
max_micheline_bytes_limit,
max_allowed_global_constant_depth,
cache_layout,
michelson_maximum_type_size ))
(fun ( _proof_of_work_nonce_size,
_nonce_length,
_max_anon_ops_per_block,
_max_operation_data_length,
_max_proposals_per_delegate,
_max_micheline_node_count,
_max_micheline_bytes_limit,
_max_allowed_global_constant_depth,
_cache_layout,
_michelson_maximum_type_size ) -> ())
(obj10
(req "proof_of_work_nonce_size" uint8)
(req "nonce_length" uint8)
(req "max_anon_ops_per_block" uint8)
(req "max_operation_data_length" int31)
(req "max_proposals_per_delegate" uint8)
(req "max_micheline_node_count" int31)
(req "max_micheline_bytes_limit" int31)
(req "max_allowed_global_constants_depth" int31)
(req "cache_layout" (list uint62))
(req "michelson_maximum_type_size" uint16))
let fixed = ()
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;
minimal_block_delay : Period_repr.t;
endorsers_per_block : int;
hard_gas_limit_per_operation : Gas_limit_repr.Arith.integral;
hard_gas_limit_per_block : Gas_limit_repr.Arith.integral;
proof_of_work_threshold : int64;
tokens_per_roll : Tez_repr.t;
seed_nonce_revelation_tip : Tez_repr.t;
origination_size : int;
block_security_deposit : Tez_repr.t;
endorsement_security_deposit : Tez_repr.t;
baking_reward_per_endorsement : Tez_repr.t list;
endorsement_reward : Tez_repr.t list;
cost_per_byte : Tez_repr.t;
hard_storage_limit_per_operation : Z.t;
quorum_min : int32;
quorum_max : int32;
min_proposal_quorum : int32;
initial_endorsers : int;
delay_per_missing_endorsement : Period_repr.t;
liquidity_baking_subsidy : Tez_repr.t;
liquidity_baking_sunset_level : int32;
liquidity_baking_escape_ema_threshold : int32;
}
let parametric_encoding =
let open Data_encoding in
conv
(fun c ->
( ( c.preserved_cycles,
c.blocks_per_cycle,
c.blocks_per_commitment,
c.blocks_per_roll_snapshot,
c.blocks_per_voting_period,
c.time_between_blocks,
c.endorsers_per_block,
c.hard_gas_limit_per_operation,
c.hard_gas_limit_per_block,
c.proof_of_work_threshold ),
( ( c.tokens_per_roll,
c.seed_nonce_revelation_tip,
c.origination_size,
c.block_security_deposit,
c.endorsement_security_deposit,
c.baking_reward_per_endorsement,
c.endorsement_reward,
c.cost_per_byte,
c.hard_storage_limit_per_operation ),
( c.quorum_min,
c.quorum_max,
c.min_proposal_quorum,
c.initial_endorsers,
c.delay_per_missing_endorsement,
c.minimal_block_delay,
c.liquidity_baking_subsidy,
c.liquidity_baking_sunset_level,
c.liquidity_baking_escape_ema_threshold ) ) ))
(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,
seed_nonce_revelation_tip,
origination_size,
block_security_deposit,
endorsement_security_deposit,
baking_reward_per_endorsement,
endorsement_reward,
cost_per_byte,
hard_storage_limit_per_operation ),
( quorum_min,
quorum_max,
min_proposal_quorum,
initial_endorsers,
delay_per_missing_endorsement,
minimal_block_delay,
liquidity_baking_subsidy,
liquidity_baking_sunset_level,
liquidity_baking_escape_ema_threshold ) ) ) ->
{
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;
seed_nonce_revelation_tip;
origination_size;
block_security_deposit;
endorsement_security_deposit;
baking_reward_per_endorsement;
endorsement_reward;
cost_per_byte;
hard_storage_limit_per_operation;
quorum_min;
quorum_max;
min_proposal_quorum;
initial_endorsers;
delay_per_missing_endorsement;
minimal_block_delay;
liquidity_baking_subsidy;
liquidity_baking_sunset_level;
liquidity_baking_escape_ema_threshold;
})
(merge_objs
(obj10
(req "preserved_cycles" uint8)
(req "blocks_per_cycle" int32)
(req "blocks_per_commitment" int32)
(req "blocks_per_roll_snapshot" int32)
(req "blocks_per_voting_period" int32)
(req "time_between_blocks" (list Period_repr.encoding))
(req "endorsers_per_block" uint16)
(req
"hard_gas_limit_per_operation"
Gas_limit_repr.Arith.z_integral_encoding)
(req
"hard_gas_limit_per_block"
Gas_limit_repr.Arith.z_integral_encoding)
(req "proof_of_work_threshold" int64))
(merge_objs
(obj9
(req "tokens_per_roll" Tez_repr.encoding)
(req "seed_nonce_revelation_tip" Tez_repr.encoding)
(req "origination_size" int31)
(req "block_security_deposit" Tez_repr.encoding)
(req "endorsement_security_deposit" Tez_repr.encoding)
(req "baking_reward_per_endorsement" (list Tez_repr.encoding))
(req "endorsement_reward" (list Tez_repr.encoding))
(req "cost_per_byte" Tez_repr.encoding)
(req "hard_storage_limit_per_operation" z))
(obj9
(req "quorum_min" int32)
(req "quorum_max" int32)
(req "min_proposal_quorum" int32)
(req "initial_endorsers" uint16)
(req "delay_per_missing_endorsement" Period_repr.encoding)
(req "minimal_block_delay" Period_repr.encoding)
(req "liquidity_baking_subsidy" Tez_repr.encoding)
(req "liquidity_baking_sunset_level" int32)
(req "liquidity_baking_escape_ema_threshold" int32))))
type t = {fixed : fixed; parametric : parametric}
let all parametric = {fixed; parametric}
let encoding =
let open Data_encoding in
conv
(fun {fixed; parametric} -> (fixed, parametric))
(fun (fixed, parametric) -> {fixed; parametric})
(merge_objs fixed_encoding parametric_encoding)
type error += Invalid_protocol_constants of string
let () =
register_error_kind
`Permanent
~id:"constants.invalid_protocol_constants"
~title:"Invalid protocol constants"
~description:"The provided protocol constants are not coherent."
~pp:(fun ppf reason ->
Format.fprintf ppf "Invalid protocol constants: %s" reason)
Data_encoding.(obj1 (req "reason" string))
(function Invalid_protocol_constants reason -> Some reason | _ -> None)
(fun reason -> Invalid_protocol_constants reason)
let check_constants constants =
let min_time_between_blocks =
match constants.time_between_blocks with
| first_time_between_blocks :: _ -> first_time_between_blocks
| [] ->
Period_repr.one_minute
in
error_unless
Compare.Int64.(
Period_repr.to_seconds min_time_between_blocks
>= Period_repr.to_seconds constants.minimal_block_delay)
(Invalid_protocol_constants
(Format.asprintf
"minimal_block_delay value (%Ld) should be smaller than \
time_between_blocks[0] value (%Ld)"
(Period_repr.to_seconds constants.minimal_block_delay)
(Period_repr.to_seconds min_time_between_blocks)))
>>? fun () ->
error_unless
Compare.Int.(constants.endorsers_per_block >= constants.initial_endorsers)
(Invalid_protocol_constants
"initial_endorsers should be smaller than endorsers_per_block")
module Proto_previous = 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;
minimal_block_delay : Period_repr.t;
endorsers_per_block : int;
hard_gas_limit_per_operation : Gas_limit_repr.Arith.integral;
hard_gas_limit_per_block : Gas_limit_repr.Arith.integral;
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;
baking_reward_per_endorsement : Tez_repr.t list;
endorsement_reward : Tez_repr.t list;
cost_per_byte : Tez_repr.t;
hard_storage_limit_per_operation : Z.t;
quorum_min : int32;
quorum_max : int32;
min_proposal_quorum : int32;
initial_endorsers : int;
delay_per_missing_endorsement : Period_repr.t;
liquidity_baking_subsidy : Tez_repr.t;
liquidity_baking_sunset_level : int32;
liquidity_baking_escape_ema_threshold : int32;
}
let parametric_encoding =
let open Data_encoding in
conv
(fun c ->
( ( c.preserved_cycles,
c.blocks_per_cycle,
c.blocks_per_commitment,
c.blocks_per_roll_snapshot,
c.blocks_per_voting_period,
c.time_between_blocks,
c.endorsers_per_block,
c.hard_gas_limit_per_operation,
c.hard_gas_limit_per_block,
c.proof_of_work_threshold ),
( ( c.tokens_per_roll,
c.michelson_maximum_type_size,
c.seed_nonce_revelation_tip,
c.origination_size,
c.block_security_deposit,
c.endorsement_security_deposit,
c.baking_reward_per_endorsement,
c.endorsement_reward,
c.cost_per_byte,
c.hard_storage_limit_per_operation ),
( c.quorum_min,
c.quorum_max,
c.min_proposal_quorum,
c.initial_endorsers,
c.delay_per_missing_endorsement,
c.minimal_block_delay,
c.liquidity_baking_subsidy,
c.liquidity_baking_sunset_level,
c.liquidity_baking_escape_ema_threshold ) ) ))
(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,
baking_reward_per_endorsement,
endorsement_reward,
cost_per_byte,
hard_storage_limit_per_operation ),
( quorum_min,
quorum_max,
min_proposal_quorum,
initial_endorsers,
delay_per_missing_endorsement,
minimal_block_delay,
liquidity_baking_subsidy,
liquidity_baking_sunset_level,
liquidity_baking_escape_ema_threshold ) ) ) ->
{
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;
baking_reward_per_endorsement;
endorsement_reward;
cost_per_byte;
hard_storage_limit_per_operation;
quorum_min;
quorum_max;
min_proposal_quorum;
initial_endorsers;
delay_per_missing_endorsement;
minimal_block_delay;
liquidity_baking_subsidy;
liquidity_baking_sunset_level;
liquidity_baking_escape_ema_threshold;
})
(merge_objs
(obj10
(req "preserved_cycles" uint8)
(req "blocks_per_cycle" int32)
(req "blocks_per_commitment" int32)
(req "blocks_per_roll_snapshot" int32)
(req "blocks_per_voting_period" int32)
(req "time_between_blocks" (list Period_repr.encoding))
(req "endorsers_per_block" uint16)
(req
"hard_gas_limit_per_operation"
Gas_limit_repr.Arith.z_integral_encoding)
(req
"hard_gas_limit_per_block"
Gas_limit_repr.Arith.z_integral_encoding)
(req "proof_of_work_threshold" int64))
(merge_objs
(obj10
(req "tokens_per_roll" Tez_repr.encoding)
(req "michelson_maximum_type_size" uint16)
(req "seed_nonce_revelation_tip" Tez_repr.encoding)
(req "origination_size" int31)
(req "block_security_deposit" Tez_repr.encoding)
(req "endorsement_security_deposit" Tez_repr.encoding)
(req "baking_reward_per_endorsement" (list Tez_repr.encoding))
(req "endorsement_reward" (list Tez_repr.encoding))
(req "cost_per_byte" Tez_repr.encoding)
(req "hard_storage_limit_per_operation" z))
(obj9
(req "quorum_min" int32)
(req "quorum_max" int32)
(req "min_proposal_quorum" int32)
(req "initial_endorsers" uint16)
(req "delay_per_missing_endorsement" Period_repr.encoding)
(req "minimal_block_delay" Period_repr.encoding)
(req "liquidity_baking_subsidy" Tez_repr.encoding)
(req "liquidity_baking_sunset_level" int32)
(req "liquidity_baking_escape_ema_threshold" int32))))
end