Alphanet: bootstrap accounts should always have 1/2 of the mining rights

This commit is contained in:
Grégoire Henry 2017-02-24 17:14:20 +01:00
parent 300dd5ea6d
commit 26ce119072
2 changed files with 13 additions and 2 deletions

View File

@ -190,6 +190,7 @@ let may_start_new_cycle ctxt =
match Cycle.pred new_cycle with
| None -> assert false
| Some last_cycle -> last_cycle in
Bootstrap.refill ctxt >>=? fun ctxt ->
Seed.clear_cycle ctxt last_cycle >>=? fun ctxt ->
Seed.compute_for_cycle ctxt (Cycle.succ new_cycle) >>=? fun ctxt ->
Roll.clear_cycle ctxt last_cycle >>=? fun ctxt ->
@ -199,7 +200,6 @@ let may_start_new_cycle ctxt =
>>=? fun reward_date ->
Reward.set_reward_time_for_cycle
ctxt last_cycle reward_date >>=? fun ctxt ->
Bootstrap.refill ctxt >>=? fun ctxt ->
return ctxt
let apply_main ctxt accept_failing_script block operations =

View File

@ -99,12 +99,23 @@ let account_encoding =
(req "secretKey" Ed25519.secret_key_encoding))
let refill ctxt =
(* Unefficient HACK for tha alphanet only... *)
Contract_storage.list ctxt >>=? fun contracts ->
List.fold_left
(fun total contract ->
Contract_storage.get_balance ctxt contract >>=? fun balance ->
total >>=? fun total -> Lwt.return Tez_repr.(total +? balance))
(return Tez_repr.zero) contracts >>=? fun total ->
(* The 5 bootstrap accounts should have at least 1/2 of the total amount
of tokens. *)
let min_balance =
Tez_repr.(total / 2L / (Int64.of_int (List.length accounts))) in
fold_left_s
(fun ctxt account ->
let contract =
Contract_repr.default_contract account.public_key_hash in
Contract_storage.get_balance ctxt contract >>=? fun balance ->
match Tez_repr.(wealth -? balance) with
match Tez_repr.(min_balance -? balance) with
| Error _ -> return ctxt
| Ok tez -> Contract_storage.credit ctxt contract tez)
ctxt