Alpha/Vote: fix initialization of voting rights from genesis

This patch fixes the voting system initialisation from genesis.

It improves voting in sandbox mode and test networks.
It has no effect on mainnet.
parent 2d51e996
......@@ -14,12 +14,7 @@ sed -e 's/"blocks_per_voting_period" : [0-9]*/"blocks_per_voting_period" : 4/' $
parameters_file=$tempdir/parameters.json
echo params=${parameters_file}
# Start a node
start_node 1
activate_alpha
echo Alpha activated
#useful RPCs
function get_ballot_list() {
$client rpc get /chains/main/blocks/head/votes/ballot_list
}
......@@ -43,24 +38,16 @@ function get_proposals() {
}
function get_period_position() {
#TODO why offset 1?
$client rpc get /chains/main/blocks/head/helpers/current_level?offset=1 | jq .voting_period_position
$client rpc get /chains/main/blocks/head/helpers/current_level | jq .voting_period_position
}
$client show voting period
[ `get_period_position` = '1' ] \
|| { echo "strange voting_period_position" ; exit 1 ; }
echo Checking the bug of the empty listing in the first voting period...
[ `get_listings` = '[]' ] \
|| { echo "empty listings bug was fixed?!" ; exit 1 ; }
bake # pos=2
# Start a node
start_node 1
activate_alpha
[ `get_period_position` = '2' ] \
|| { echo "strange voting_period_position" ; exit 1 ; }
echo Alpha activated
bake # pos=3
bake # new period, pos=0
$client show voting period
echo 'Checking the current period = proposal with non empty listings'
[ `get_period_position` = '0' ] \
......
......@@ -42,6 +42,7 @@ let prepare_first_block ctxt ~typecheck ~level ~timestamp ~fitness =
Roll_storage.init_first_cycles ctxt >>=? fun ctxt ->
Vote_storage.init ctxt >>=? fun ctxt ->
Storage.Last_block_priority.init ctxt 0 >>=? fun ctxt ->
Vote_storage.freeze_listings ctxt >>=? fun ctxt ->
return ctxt
| Alpha_previous ->
return ctxt
......
......@@ -93,12 +93,7 @@ let get_rolls b delegates loc =
let test_successful_vote num_delegates () =
Context.init num_delegates >>=? fun (b,_) ->
(* Because of a minor bug in the initialization of the voting state, the
listings are not populated in the very first period. After that they get
correctly populated. An empty listing means no proposals will be accepted. *)
Context.get_constants (B b) >>=? fun { parametric = {blocks_per_voting_period} } ->
Block.bake_n (Int32.to_int blocks_per_voting_period) b >>=? fun b ->
(* no ballots in proposal period *)
Context.Vote.get_ballots (B b) >>=? fun v ->
......@@ -111,11 +106,11 @@ let test_successful_vote num_delegates () =
| _ -> failwith "%s - Unexpected ballot list" __LOC__
end >>=? fun () ->
(* period 1 *)
(* period 0 *)
Context.Vote.get_voting_period (B b) >>=? fun v ->
let open Alpha_context in
Assert.equal ~loc:__LOC__ Voting_period.equal "Unexpected period"
Voting_period.pp v Voting_period.(succ root)
Voting_period.pp v Voting_period.(root)
>>=? fun () ->
Context.Vote.get_current_period_kind (B b) >>=? begin function
......@@ -196,11 +191,11 @@ let test_successful_vote num_delegates () =
| _ -> failwith "%s - Unexpected period kind" __LOC__
end >>=? fun () ->
(* period 2 *)
(* period 1 *)
Context.Vote.get_voting_period (B b) >>=? fun v ->
let open Alpha_context in
Assert.equal ~loc:__LOC__ Voting_period.equal "Unexpected period"
Voting_period.pp v Voting_period.(succ (succ root))
Voting_period.pp v Voting_period.(succ root)
>>=? fun () ->
(* listings must be populated in testing_vote period *)
......@@ -271,11 +266,11 @@ let test_successful_vote num_delegates () =
| _ -> failwith "%s - Unexpected period kind" __LOC__
end >>=? fun () ->
(* period 3 *)
(* period 2 *)
Context.Vote.get_voting_period (B b) >>=? fun v ->
let open Alpha_context in
Assert.equal ~loc:__LOC__ Voting_period.equal "Unexpected period"
Voting_period.pp v Voting_period.(succ (succ (succ root)))
Voting_period.pp v Voting_period.(succ (succ root))
>>=? fun () ->
(* no ballots in testing period *)
......@@ -298,11 +293,11 @@ let test_successful_vote num_delegates () =
| _ -> failwith "%s - Unexpected period kind" __LOC__
end >>=? fun () ->
(* period 4 *)
(* period 3 *)
Context.Vote.get_voting_period (B b) >>=? fun v ->
let open Alpha_context in
Assert.equal ~loc:__LOC__ Voting_period.equal "Unexpected period"
Voting_period.pp v Voting_period.(succ (succ (succ (succ root))))
Voting_period.pp v Voting_period.(succ (succ (succ root)))
>>=? fun () ->
(* listings must be populated in promotion_vote period *)
......@@ -403,12 +398,7 @@ let get_expected_quorum ?(min_participation=0) rolls voter_rolls old_quorum =
go back to proposal period *)
let test_not_enough_quorum_in_testing_vote num_delegates () =
Context.init num_delegates >>=? fun (b,delegates) ->
(* Because of a minor bug in the initialization of the voting state, the
listings are not populated in the very first period. After that they get
correctly populated. An empty listing means no proposals will be accepted. *)
Context.get_constants (B b) >>=? fun { parametric = {blocks_per_voting_period} } ->
Block.bake_n (Int32.to_int blocks_per_voting_period) b >>=? fun b ->
(* proposal period *)
let open Alpha_context in
......@@ -471,11 +461,7 @@ let test_not_enough_quorum_in_testing_vote num_delegates () =
go back to proposal period *)
let test_not_enough_quorum_in_promotion_vote num_delegates () =
Context.init num_delegates >>=? fun (b,delegates) ->
(* Because of a minor bug in the initialization of the voting state, the
listings are not populated in the very first period. After that they get
correctly populated. An empty listing means no proposals will be accepted. *)
Context.get_constants (B b) >>=? fun { parametric = {blocks_per_voting_period} } ->
Block.bake_n (Int32.to_int blocks_per_voting_period) b >>=? fun b ->
Context.Vote.get_current_period_kind (B b) >>=? begin function
| Proposal -> return_unit
......@@ -569,12 +555,6 @@ let test_not_enough_quorum_in_promotion_vote num_delegates () =
let test_multiple_identical_proposals_count_as_one () =
Context.init 1 >>=? fun (b,delegates) ->
(* Because of a minor bug in the initialization of the voting state, the
listings are not populated in the very first period. After that they get
correctly populated. An empty listing means no proposals will be accepted. *)
Context.get_constants (B b) >>=? fun { parametric = {blocks_per_voting_period} } ->
Block.bake_n (Int32.to_int blocks_per_voting_period) b >>=? fun b ->
Context.Vote.get_current_period_kind (B b) >>=? begin function
| Proposal -> return_unit
| _ -> failwith "%s - Unexpected period kind" __LOC__
......@@ -667,9 +647,7 @@ let test_supermajority_in_proposal there_is_a_winner () =
let test_supermajority_in_testing_vote supermajority () =
Context.init 100 >>=? fun (b,delegates) ->
Context.get_constants (B b) >>=? fun { parametric = {blocks_per_voting_period} } ->
Block.bake_n (Int32.to_int blocks_per_voting_period) b >>=? fun b ->
let del1 = List.nth delegates 0 in
let proposal = protos.(0) in
......@@ -733,12 +711,7 @@ let test_supermajority_in_testing_vote supermajority () =
(* test also how the selection scales: all delegates propose max proposals *)
let test_no_winning_proposal num_delegates () =
Context.init num_delegates >>=? fun (b,_) ->
(* Because of a minor bug in the initialization of the voting state, the
listings are not populated in the very first period. After that they get
correctly populated. An empty listing means no proposals will be accepted. *)
Context.get_constants (B b) >>=? fun { parametric = {blocks_per_voting_period} } ->
Block.bake_n (Int32.to_int blocks_per_voting_period) b >>=? fun b ->
(* beginning of proposal, denoted by _p1;
take a snapshot of the active delegates and their rolls from listings *)
......
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