diff --git a/scripts/create_genesis/create_genesis_info.py b/scripts/create_genesis/create_genesis_info.py index f00a3a887..8f37a014c 100755 --- a/scripts/create_genesis/create_genesis_info.py +++ b/scripts/create_genesis/create_genesis_info.py @@ -130,4 +130,7 @@ if __name__ == '__main__': [ (commitment['half_pkh'], commitment['blinded_pkh'], str(commitment['amount'])) - for commitment in commitments if commitment['amount'] > 0]}, f, indent=1) + for commitment in commitments if commitment['amount'] > 0] + "no_rewards_cycles": 7, + "security_deposit_ramp_up_cycles": 64 + }, f, indent=1) diff --git a/src/proto_alpha/lib_protocol/src/bootstrap_storage.ml b/src/proto_alpha/lib_protocol/src/bootstrap_storage.ml index b3cd66174..530b80649 100644 --- a/src/proto_alpha/lib_protocol/src/bootstrap_storage.ml +++ b/src/proto_alpha/lib_protocol/src/bootstrap_storage.ml @@ -17,8 +17,26 @@ let init_account ctxt (account: Parameters_repr.bootstrap_account) = Delegate_storage.set ctxt contract (Some public_key_hash) >>=? fun ctxt -> return ctxt -let init ctxt ?ramp_up_cycles accounts = +let init ctxt ?ramp_up_cycles ?no_reward_cycles accounts = fold_left_s init_account ctxt accounts >>=? fun ctxt -> + begin + match no_reward_cycles with + | None -> return ctxt + | Some cycles -> + (* Store pending ramp ups. *) + let constants = Raw_context.constants ctxt in + (* Start without reward *) + Raw_context.patch_constants ctxt + (fun c -> + { c with + block_reward = Tez_repr.zero ; + endorsement_reward = Tez_repr.zero }) >>= fun ctxt -> + (* Store the final reward. *) + Storage.Ramp_up.Rewards.init ctxt + (Cycle_repr.of_int32_exn (Int32.of_int cycles)) + (constants.block_reward, + constants.endorsement_reward) + end >>=? fun ctxt -> match ramp_up_cycles with | None -> return ctxt | Some cycles -> @@ -50,6 +68,17 @@ let init ctxt ?ramp_up_cycles accounts = let cycle_end ctxt last_cycle = let next_cycle = Cycle_repr.succ last_cycle in + begin + Storage.Ramp_up.Rewards.get_option ctxt next_cycle >>=? function + | None -> return ctxt + | Some (block_reward, endorsement_reward) -> + Storage.Ramp_up.Rewards.delete ctxt next_cycle >>=? fun ctxt -> + Raw_context.patch_constants ctxt + (fun c -> + { c with block_reward ; + endorsement_reward }) >>= fun ctxt -> + return ctxt + end >>=? fun ctxt -> Storage.Ramp_up.Security_deposits.get_option ctxt next_cycle >>=? function | None -> return ctxt | Some (block_security_deposit, endorsement_security_deposit) -> diff --git a/src/proto_alpha/lib_protocol/src/bootstrap_storage.mli b/src/proto_alpha/lib_protocol/src/bootstrap_storage.mli index d7f93399d..353bfc0d5 100644 --- a/src/proto_alpha/lib_protocol/src/bootstrap_storage.mli +++ b/src/proto_alpha/lib_protocol/src/bootstrap_storage.mli @@ -10,6 +10,7 @@ val init: Raw_context.t -> ?ramp_up_cycles:int -> + ?no_reward_cycles:int -> Parameters_repr.bootstrap_account list -> Raw_context.t tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/src/init_storage.ml b/src/proto_alpha/lib_protocol/src/init_storage.ml index 6ffcf674c..e6227576a 100644 --- a/src/proto_alpha/lib_protocol/src/init_storage.ml +++ b/src/proto_alpha/lib_protocol/src/init_storage.ml @@ -17,6 +17,7 @@ let prepare_first_block ctxt ~level ~timestamp ~fitness = Contract_storage.init ctxt >>=? fun ctxt -> Bootstrap_storage.init ctxt ?ramp_up_cycles:param.security_deposit_ramp_up_cycles + ?no_reward_cycles:param.no_reward_cycles param.bootstrap_accounts >>=? fun ctxt -> Roll_storage.init_first_cycles ctxt >>=? fun ctxt -> Vote_storage.init ctxt >>=? fun ctxt -> diff --git a/src/proto_alpha/lib_protocol/src/parameters_repr.ml b/src/proto_alpha/lib_protocol/src/parameters_repr.ml index c0458db24..f0426d9e7 100644 --- a/src/proto_alpha/lib_protocol/src/parameters_repr.ml +++ b/src/proto_alpha/lib_protocol/src/parameters_repr.ml @@ -17,6 +17,7 @@ type t = { commitments : (Unclaimed_public_key_hash.t * Commitment_repr.t) list ; constants : Constants_repr.parametric ; security_deposit_ramp_up_cycles : int option ; + no_reward_cycles : int option ; } let bootstrap_account_encoding = @@ -210,19 +211,22 @@ let encoding = let open Data_encoding in conv (fun { bootstrap_accounts ; commitments ; constants ; - security_deposit_ramp_up_cycles } -> - ((bootstrap_accounts, commitments, security_deposit_ramp_up_cycles), + security_deposit_ramp_up_cycles ; no_reward_cycles } -> + ((bootstrap_accounts, commitments, + security_deposit_ramp_up_cycles, no_reward_cycles), constants)) - (fun ( (bootstrap_accounts, commitments, security_deposit_ramp_up_cycles), + (fun ( (bootstrap_accounts, commitments, + security_deposit_ramp_up_cycles, no_reward_cycles), constants) -> { bootstrap_accounts ; commitments ; constants ; - security_deposit_ramp_up_cycles}) + security_deposit_ramp_up_cycles ; no_reward_cycles }) (merge_objs - (obj3 + (obj4 (req "bootstrap_accounts" (list bootstrap_account_encoding)) (dft "commitments" (list (merge_tups (tup1 Unclaimed_public_key_hash.encoding) Commitment_repr.encoding)) []) - (opt "security_deposit_ramp_up_cycles" int31)) + (opt "security_deposit_ramp_up_cycles" int31) + (opt "no_reward_cycles" int31)) constants_encoding) diff --git a/src/proto_alpha/lib_protocol/src/parameters_repr.mli b/src/proto_alpha/lib_protocol/src/parameters_repr.mli index c2e8f3a61..0c20ba9e3 100644 --- a/src/proto_alpha/lib_protocol/src/parameters_repr.mli +++ b/src/proto_alpha/lib_protocol/src/parameters_repr.mli @@ -17,6 +17,7 @@ type t = { commitments : (Unclaimed_public_key_hash.t * Commitment_repr.t) list ; constants : Constants_repr.parametric ; security_deposit_ramp_up_cycles : int option ; + no_reward_cycles : int option ; } val encoding: t Data_encoding.t diff --git a/src/proto_alpha/lib_protocol/src/storage.ml b/src/proto_alpha/lib_protocol/src/storage.ml index 2b527281b..130672def 100644 --- a/src/proto_alpha/lib_protocol/src/storage.ml +++ b/src/proto_alpha/lib_protocol/src/storage.ml @@ -431,6 +431,15 @@ module Commitments = module Ramp_up = struct + module Rewards = + Make_indexed_data_storage + (Make_subcontext(Raw_context)(struct let name = ["ramp_up"; "rewards"] end)) + (Cycle_repr.Index) + (Make_value(struct + type t = Tez_repr.t * Tez_repr.t + let encoding = Data_encoding.tup2 Tez_repr.encoding Tez_repr.encoding + end)) + module Security_deposits = Make_indexed_data_storage (Make_subcontext(Raw_context)(struct let name = ["ramp_up"; "deposits"] end)) diff --git a/src/proto_alpha/lib_protocol/src/storage.mli b/src/proto_alpha/lib_protocol/src/storage.mli index 7d677981a..0d578d3ef 100644 --- a/src/proto_alpha/lib_protocol/src/storage.mli +++ b/src/proto_alpha/lib_protocol/src/storage.mli @@ -268,6 +268,12 @@ module Commitments : Indexed_data_storage module Ramp_up : sig + module Rewards : + Indexed_data_storage + with type key = Cycle_repr.t + and type value = Tez_repr.t * Tez_repr.t (* baking * endorsement *) + and type t := Raw_context.t + module Security_deposits : Indexed_data_storage with type key = Cycle_repr.t