Verified Commit 34aaf6c7 authored by Eugen Zalinescu's avatar Eugen Zalinescu Committed by Marco Stronati

Alpha/Vote: new constant `test_chain_duration`

This patch turns the test chain lifetime from a hardcoded two-days
constant in the code to a parameter. This is useful for testing of
the voting system, for testnet rehearsals, or for more easily changing
the value in a future protocol upgrade.

The value of this constant is also updated to prolong the test chain
to the end of period. The test chain is now spawned at the beginning of
the third voting period and lasts the whole period.
parent d98fe4e5
......@@ -309,6 +309,7 @@ let genesis
?(endorsement_reward = Constants_repr.default.endorsement_reward)
?(cost_per_byte = Constants_repr.default.cost_per_byte)
?(hard_storage_limit_per_operation = Constants_repr.default.hard_storage_limit_per_operation)
?(test_chain_duration = Constants_repr.default.test_chain_duration)
(initial_accounts : (Account.t * Tez_repr.t) list) =
let constants : Constants_repr.parametric = {
preserved_cycles ;
......@@ -331,6 +332,7 @@ let genesis
endorsement_reward ;
cost_per_byte ;
hard_storage_limit_per_operation ;
test_chain_duration ;
} in
genesis_with_parameters constants initial_accounts
......
......@@ -117,6 +117,7 @@ val genesis:
?endorsement_reward:Tez_repr.tez ->
?cost_per_byte: Tez_repr.t ->
?hard_storage_limit_per_operation: Z.t ->
?test_chain_duration: Int64.t ->
(Account.t * Tez_repr.tez) list -> block tzresult Lwt.t
(** Applies a signed header and its operations to a block and
......
......@@ -379,6 +379,7 @@ module Constants : sig
endorsement_reward: Tez.t ;
cost_per_byte: Tez.t ;
hard_storage_limit_per_operation: Z.t ;
test_chain_duration: int64;
}
val parametric_encoding: parametric Data_encoding.t
val parametric: context -> parametric
......@@ -402,6 +403,7 @@ module Constants : sig
val origination_size: context -> int
val block_security_deposit: context -> Tez.t
val endorsement_security_deposit: context -> Tez.t
val test_chain_duration: context -> int64
(** All constants: fixed and parametric *)
type t = {
......
......@@ -101,7 +101,7 @@ let start_new_voting_period ctxt =
Vote.clear_listings ctxt >>=? fun ctxt ->
if approved then
let expiration = (* in two days maximum... *)
Time.add (Timestamp.current ctxt) (Int64.mul 48L 3600L) in
Time.add (Timestamp.current ctxt) (Constants.test_chain_duration ctxt) in
Vote.get_current_proposal ctxt >>=? fun proposal ->
fork_test_chain ctxt proposal expiration >>= fun ctxt ->
Vote.set_current_period_kind ctxt Testing >>=? fun ctxt ->
......
......@@ -94,6 +94,7 @@ type parametric = {
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 = {
......@@ -124,6 +125,7 @@ let default = {
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;
}
let parametric_encoding =
......@@ -149,7 +151,8 @@ let parametric_encoding =
c.block_reward),
(c.endorsement_reward,
c.cost_per_byte,
c.hard_storage_limit_per_operation))) )
c.hard_storage_limit_per_operation,
c.test_chain_duration))) )
(fun (( preserved_cycles,
blocks_per_cycle,
blocks_per_commitment,
......@@ -169,7 +172,8 @@ let parametric_encoding =
block_reward),
(endorsement_reward,
cost_per_byte,
hard_storage_limit_per_operation))) ->
hard_storage_limit_per_operation,
test_chain_duration))) ->
{ preserved_cycles ;
blocks_per_cycle ;
blocks_per_commitment ;
......@@ -190,6 +194,7 @@ let parametric_encoding =
endorsement_reward ;
cost_per_byte ;
hard_storage_limit_per_operation ;
test_chain_duration ;
} )
(merge_objs
(obj9
......@@ -212,10 +217,11 @@ let parametric_encoding =
(req "block_security_deposit" Tez_repr.encoding)
(req "endorsement_security_deposit" Tez_repr.encoding)
(req "block_reward" Tez_repr.encoding))
(obj3
(obj4
(req "endorsement_reward" Tez_repr.encoding)
(req "cost_per_byte" Tez_repr.encoding)
(req "hard_storage_limit_per_operation" z))))
(req "hard_storage_limit_per_operation" z)
(req "test_chain_duration" int64))))
type t = {
fixed : fixed ;
......
......@@ -83,5 +83,8 @@ let block_reward c =
let endorsement_reward c =
let constants = Raw_context.constants c in
constants.endorsement_reward
let test_chain_duration c =
let constants = Raw_context.constants c in
constants.test_chain_duration
let parametric c =
Raw_context.constants c
......@@ -156,6 +156,9 @@ let constants_encoding =
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,
......@@ -176,7 +179,8 @@ let constants_encoding =
block_reward),
(endorsement_reward,
cost_per_byte,
hard_storage_limit_per_operation))))
hard_storage_limit_per_operation,
test_chain_duration))))
(fun (( preserved_cycles,
blocks_per_cycle,
blocks_per_commitment,
......@@ -196,7 +200,8 @@ let constants_encoding =
block_reward),
(endorsement_reward,
cost_per_byte,
hard_storage_limit_per_operation))) ->
hard_storage_limit_per_operation,
test_chain_duration))) ->
let unopt def = function None -> def | Some v -> v in
let default = Constants_repr.default in
{ Constants_repr.preserved_cycles =
......@@ -240,6 +245,8 @@ let constants_encoding =
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
......@@ -262,10 +269,11 @@ let constants_encoding =
(opt "block_security_deposit" Tez_repr.encoding)
(opt "endorsement_security_deposit" Tez_repr.encoding)
(opt "block_reward" Tez_repr.encoding))
(obj3
(obj4
(opt "endorsement_reward" Tez_repr.encoding)
(opt "cost_per_byte" Tez_repr.encoding)
(opt "hard_storage_limit_per_operation" z))))
(opt "hard_storage_limit_per_operation" z)
(opt "test_chain_duration" int64))))
let encoding =
let open Data_encoding in
......
......@@ -295,6 +295,7 @@ let genesis
endorsement_reward ;
cost_per_byte ;
hard_storage_limit_per_operation ;
test_chain_duration = Constants_repr.default.test_chain_duration;
} in
check_constants_consistency constants >>=? fun () ->
......
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