Verified Commit d0c16b4f authored by Grégoire Henry's avatar Grégoire Henry Committed by Marco Stronati

Alpha/Vote/Migration: update constants binary representation

This patch is part of the migration code from `alpha_003` to `athens_004`.

Since we changed `Constants_repr.parametric_encoding` for adding the
new constant `test_chain_duration`, we need to upgrade the content
of the `constants_key` in the context.
parent 34aaf6c7
......@@ -296,3 +296,160 @@ let encoding =
(opt "security_deposit_ramp_up_cycles" int31)
(opt "no_reward_cycles" int31))
constants_encoding)
(* Only for stitching form proto_003 *)
module Proto_003 = struct
(* This is an excerpt from constants_repr.ml of proto_003_PsddFKi3 *)
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 ;
}
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 400_000 ;
hard_gas_limit_per_block = Z.of_int 4_000_000 ;
proof_of_work_threshold =
Int64.(sub (shift_left 1L 46) 1L) ;
tokens_per_roll =
Tez_repr.(mul_exn one 10_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 ;
}
(* This is an excerpt from parameters_repr.ml of proto_003_PsddFKi3:
the encoder was removed and the default redirected to the one above *)
let constants_encoding =
let open Data_encoding in
conv
(fun (_c : parametric) -> assert false)
(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))) ->
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 ;
} )
(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))
(obj3
(opt "endorsement_reward" Tez_repr.encoding)
(opt "cost_per_byte" Tez_repr.encoding)
(opt "hard_storage_limit_per_operation" z))))
end
......@@ -46,3 +46,32 @@ type t = {
val encoding: t Data_encoding.t
val constants_encoding: Constants_repr.parametric Data_encoding.t
(* Only for stitching form proto_003 *)
module Proto_003 : sig
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 ;
}
val constants_encoding : parametric Data_encoding.encoding
end
......@@ -415,6 +415,22 @@ let get_constants ctxt =
failwith "Internal error: cannot parse constants in context."
| Some constants -> return constants
(* Only for stitching from proto_003 *)
let get_003_constants ctxt =
Context.get ctxt constants_key >>= function
| None ->
failwith "Internal error: cannot read constants in context."
| Some bytes ->
match
Data_encoding.Binary.of_bytes
Parameters_repr.Proto_003.constants_encoding
bytes
with
| None ->
failwith "Internal error: cannot parse constants in context."
| Some constants ->
return constants
let patch_constants ctxt f =
let constants = f ctxt.constants in
set_constants ctxt.context constants >>= fun context ->
......@@ -495,6 +511,32 @@ let prepare_first_block ~level ~timestamp ~fitness ctxt =
set_constants ctxt param.constants >>= fun ctxt ->
return ctxt
| Alpha_previous ->
(* Migration: Since we changed `Constants_repr.parametric_encoding`,
we need to upgrade the contents of `constants_key` in the context. *)
get_003_constants ctxt >>=? fun (old : Parameters_repr.Proto_003.parametric) ->
set_constants ctxt {
preserved_cycles = old.preserved_cycles ;
blocks_per_cycle = old.blocks_per_cycle ;
blocks_per_commitment = old.blocks_per_commitment ;
blocks_per_roll_snapshot = old.blocks_per_roll_snapshot ;
blocks_per_voting_period = old.blocks_per_voting_period ;
time_between_blocks = old.time_between_blocks ;
endorsers_per_block = old.endorsers_per_block ;
hard_gas_limit_per_operation = old.hard_gas_limit_per_operation ;
hard_gas_limit_per_block = old.hard_gas_limit_per_block ;
proof_of_work_threshold = old.proof_of_work_threshold ;
tokens_per_roll = old.tokens_per_roll ;
michelson_maximum_type_size = old.michelson_maximum_type_size ;
seed_nonce_revelation_tip = old.seed_nonce_revelation_tip ;
origination_size = old.origination_size ;
block_security_deposit = old.block_security_deposit ;
endorsement_security_deposit = old.endorsement_security_deposit ;
block_reward = old.block_reward ;
endorsement_reward = old.endorsement_reward ;
cost_per_byte = old.cost_per_byte ;
hard_storage_limit_per_operation = old.hard_storage_limit_per_operation ;
test_chain_duration = Constants_repr.default.test_chain_duration ;
} >>= fun ctxt ->
return ctxt
end >>=? fun ctxt ->
prepare ctxt ~level ~timestamp ~fitness >>=? fun ctxt ->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment