diff --git a/src/proto/bootstrap/apply.ml b/src/proto/bootstrap/apply.ml index 24a0e3d0f..ed713d2df 100644 --- a/src/proto/bootstrap/apply.ml +++ b/src/proto/bootstrap/apply.ml @@ -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 = diff --git a/src/proto/bootstrap/bootstrap_storage.ml b/src/proto/bootstrap/bootstrap_storage.ml index c6d6f205d..987b73ab4 100644 --- a/src/proto/bootstrap/bootstrap_storage.ml +++ b/src/proto/bootstrap/bootstrap_storage.ml @@ -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