diff --git a/src/proto_alpha/lib_protocol/src/alpha_context.mli b/src/proto_alpha/lib_protocol/src/alpha_context.mli index d8507717a..9657753c9 100644 --- a/src/proto_alpha/lib_protocol/src/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/src/alpha_context.mli @@ -277,6 +277,7 @@ module Constants : sig val dictator_pubkey: context -> Ed25519.Public_key.t val max_number_of_operations: context -> int list val max_operation_data_length: context -> int + val token_per_rolls: context -> Tez.t val michelson_maximum_type_size: context -> int end @@ -738,8 +739,6 @@ end module Roll : sig - val value: context -> Tez.t - val snapshot_rolls: context -> context tzresult Lwt.t val cycle_end: context -> Cycle.t -> context tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/src/constants_repr.ml b/src/proto_alpha/lib_protocol/src/constants_repr.ml index 22119b331..151223cf6 100644 --- a/src/proto_alpha/lib_protocol/src/constants_repr.ml +++ b/src/proto_alpha/lib_protocol/src/constants_repr.ml @@ -59,7 +59,7 @@ type constants = { dictator_pubkey: Ed25519.Public_key.t ; max_number_of_operations: int list ; max_operation_data_length: int ; - initial_roll_value: Tez_repr.t ; + token_per_rolls: Tez_repr.t ; michelson_maximum_type_size: int; } @@ -93,7 +93,7 @@ let default = { [ 300 ] ; max_operation_data_length = 16 * 1024 ; (* 16kB *) - initial_roll_value = + token_per_rolls = Tez_repr.(mul_exn one 10_000) ; michelson_maximum_type_size = 1000 ; } @@ -155,9 +155,9 @@ let constants_encoding = and max_operation_data_length = opt Compare.Int.(=) default.max_operation_data_length c.max_operation_data_length - and initial_roll_value = + and token_per_rolls = opt Tez_repr.(=) - default.initial_roll_value c.initial_roll_value + default.token_per_rolls c.token_per_rolls and michelson_maximum_type_size = opt Compare.Int.(=) default.michelson_maximum_type_size c.michelson_maximum_type_size @@ -176,7 +176,7 @@ let constants_encoding = dictator_pubkey, max_number_of_operations, max_operation_data_length, - initial_roll_value, + token_per_rolls, michelson_maximum_type_size)), ()) ) (fun ((( preserved_cycles, cycle_length, @@ -192,7 +192,7 @@ let constants_encoding = dictator_pubkey, max_number_of_operations, max_operation_data_length, - initial_roll_value, + token_per_rolls, michelson_maximum_type_size)), ()) -> { preserved_cycles = unopt default.preserved_cycles preserved_cycles ; @@ -223,8 +223,8 @@ let constants_encoding = unopt default.max_number_of_operations max_number_of_operations ; max_operation_data_length = unopt default.max_operation_data_length max_operation_data_length ; - initial_roll_value = - unopt default.initial_roll_value initial_roll_value ; + token_per_rolls = + unopt default.token_per_rolls token_per_rolls ; michelson_maximum_type_size = unopt default.michelson_maximum_type_size michelson_maximum_type_size ; } ) @@ -247,7 +247,7 @@ let constants_encoding = (opt "dictator_pubkey" Ed25519.Public_key.encoding) (opt "max_number_of_operations" (list uint16)) (opt "max_number_of_operations" int31) - (opt "initial_roll_value" Tez_repr.encoding) + (opt "token_per_rolls" Tez_repr.encoding) (opt "michelson_maximum_type_size" uint16) )) unit) diff --git a/src/proto_alpha/lib_protocol/src/constants_storage.ml b/src/proto_alpha/lib_protocol/src/constants_storage.ml index d22b38e74..ef9b25473 100644 --- a/src/proto_alpha/lib_protocol/src/constants_storage.ml +++ b/src/proto_alpha/lib_protocol/src/constants_storage.ml @@ -46,6 +46,9 @@ let max_number_of_operations c = let max_operation_data_length c = let constants = Raw_context.constants c in constants.max_operation_data_length +let token_per_rolls c = + let constants = Raw_context.constants c in + constants.token_per_rolls let michelson_maximum_type_size c = let constants = Raw_context.constants c in constants.michelson_maximum_type_size diff --git a/src/proto_alpha/lib_protocol/src/raw_context.ml b/src/proto_alpha/lib_protocol/src/raw_context.ml index f93a1de57..62e26aa69 100644 --- a/src/proto_alpha/lib_protocol/src/raw_context.ml +++ b/src/proto_alpha/lib_protocol/src/raw_context.ml @@ -16,7 +16,6 @@ type t = { level: Level_repr.t ; timestamp: Time.t ; fitness: Int64.t ; - roll_value: Tez_repr.t ; faucet_count: int; endorsements_received: Int_set.t; } @@ -30,7 +29,6 @@ let current_fitness ctxt = ctxt.fitness let first_level ctxt = ctxt.first_level let faucet_count ctxt = ctxt.faucet_count let constants ctxt = ctxt.constants -let roll_value ctxt = ctxt.roll_value let recover ctxt = ctxt.context let record_endorsement ctxt k = { ctxt with endorsements_received = Int_set.add k ctxt.endorsements_received } @@ -140,7 +138,6 @@ let is_first_block ctxt = let version = "v1" let first_level_key = [ version ; "first_level" ] -let roll_value_key = [ version ; "roll_value" ] let sandboxed_key = [ version ; "sandboxed" ] let get_first_level ctxt = @@ -159,22 +156,6 @@ let set_first_level ctxt level = Context.set ctxt first_level_key bytes >>= fun ctxt -> return ctxt -let get_roll_value ctxt = - Context.get ctxt roll_value_key >>= function - | None -> storage_error (Missing_key (roll_value_key, `Get)) - | Some bytes -> - match - Data_encoding.Binary.of_bytes Tez_repr.encoding bytes - with - | None -> storage_error (Corrupted_data roll_value_key) - | Some level -> return level - -let set_roll_value ctxt level = - let bytes = - Data_encoding.Binary.to_bytes Tez_repr.encoding level in - Context.set ctxt roll_value_key bytes >>= fun ctxt -> - return ctxt - type error += Failed_to_parse_sandbox_parameter of MBytes.t let () = @@ -222,15 +203,6 @@ let prepare ~level ~timestamp ~fitness ctxt = may_tag_first_block ctxt level >>=? fun (ctxt, first_block, first_level) -> get_sandboxed ctxt >>=? fun sandbox -> Constants_repr.read sandbox >>=? fun constants -> - begin - if first_block then begin - set_roll_value ctxt constants.initial_roll_value >>=? fun ctxt -> - return (ctxt, constants.initial_roll_value) - end else begin - get_roll_value ctxt >>=? fun roll_value -> - return (ctxt, roll_value) - end - end >>=? fun (ctxt, roll_value) -> let level = Level_repr.from_raw ~first_level @@ -239,19 +211,11 @@ let prepare ~level ~timestamp ~fitness ctxt = ~blocks_per_commitment:constants.Constants_repr.blocks_per_commitment level in return ({ context = ctxt ; constants ; level ; - timestamp ; fitness ; first_level ; roll_value ; faucet_count = 0 ; endorsements_received = Int_set.empty ; + timestamp ; fitness ; first_level ; }, first_block) -let rec double_roll_value ctxt i = - if Compare.Int.(i <= 0) then - return ctxt - else - Lwt.return Tez_repr.(ctxt.roll_value +? ctxt.roll_value) >>=? fun roll_value -> - set_roll_value ctxt.context roll_value >>=? fun context -> - double_roll_value { ctxt with context ; roll_value } (i-1) - let activate ({ context = c ; _ } as s) h = Updater.activate c h >>= fun c -> Lwt.return { s with context = c } let fork_test_chain ({ context = c ; _ } as s) protocol expiration = @@ -267,7 +231,6 @@ let register_resolvers enc resolve = level = Level_repr.root Raw_level_repr.root ; timestamp = Time.of_seconds 0L ; fitness = 0L ; - roll_value = Tez_repr.zero ; faucet_count = 0 ; endorsements_received = Int_set.empty ; } in diff --git a/src/proto_alpha/lib_protocol/src/raw_context.mli b/src/proto_alpha/lib_protocol/src/raw_context.mli index 0ea0fb2b9..35ed54d15 100644 --- a/src/proto_alpha/lib_protocol/src/raw_context.mli +++ b/src/proto_alpha/lib_protocol/src/raw_context.mli @@ -58,7 +58,6 @@ val set_current_fitness: context -> Int64.t -> t val constants: context -> Constants_repr.constants val first_level: context -> Raw_level_repr.t -val roll_value: context -> Tez_repr.t (** {1 Generic accessors} *************************************************) diff --git a/src/proto_alpha/lib_protocol/src/roll_storage.ml b/src/proto_alpha/lib_protocol/src/roll_storage.ml index 1122aed8f..988f00411 100644 --- a/src/proto_alpha/lib_protocol/src/roll_storage.ml +++ b/src/proto_alpha/lib_protocol/src/roll_storage.ml @@ -148,16 +148,16 @@ module Delegate = struct return (roll, c) let consume_roll_change c delegate = - let roll_value = Raw_context.roll_value c in + let token_per_rolls = Constants_storage.token_per_rolls c in Storage.Roll.Delegate_change.get c delegate >>=? fun change -> trace Consume_roll_change - (Lwt.return Tez_repr.(change -? roll_value)) >>=? fun new_change -> + (Lwt.return Tez_repr.(change -? token_per_rolls)) >>=? fun new_change -> Storage.Roll.Delegate_change.set c delegate new_change let recover_roll_change c delegate = - let roll_value = Raw_context.roll_value c in + let token_per_rolls = Constants_storage.token_per_rolls c in Storage.Roll.Delegate_change.get c delegate >>=? fun change -> - Lwt.return Tez_repr.(change +? roll_value) >>=? fun new_change -> + Lwt.return Tez_repr.(change +? token_per_rolls) >>=? fun new_change -> Storage.Roll.Delegate_change.set c delegate new_change let pop_roll_from_delegate c delegate = @@ -217,16 +217,16 @@ module Delegate = struct let add_amount c delegate amount = ensure_inited c delegate >>=? fun c -> - let roll_value = Raw_context.roll_value c in + let token_per_rolls = Constants_storage.token_per_rolls c in Storage.Roll.Delegate_change.get c delegate >>=? fun change -> Lwt.return Tez_repr.(amount +? change) >>=? fun change -> Storage.Roll.Delegate_change.set c delegate change >>=? fun c -> delegate_pubkey c delegate >>=? fun delegate_pk -> let rec loop c change = - if Tez_repr.(change < roll_value) then + if Tez_repr.(change < token_per_rolls) then return c else - Lwt.return Tez_repr.(change -? roll_value) >>=? fun change -> + Lwt.return Tez_repr.(change -? token_per_rolls) >>=? fun change -> create_roll_in_delegate c delegate delegate_pk >>=? fun c -> loop c change in Storage.Contract.Inactive_delegate.mem c @@ -234,13 +234,13 @@ module Delegate = struct if inactive then return c else loop c change let remove_amount c delegate amount = - let roll_value = Raw_context.roll_value c in + let token_per_rolls = Constants_storage.token_per_rolls c in let rec loop c change = if Tez_repr.(amount <= change) then return (c, change) else pop_roll_from_delegate c delegate >>=? fun (_, c) -> - Lwt.return Tez_repr.(change +? roll_value) >>=? fun change -> + Lwt.return Tez_repr.(change +? token_per_rolls) >>=? fun change -> loop c change in Storage.Roll.Delegate_change.get c delegate >>=? fun change -> Storage.Contract.Inactive_delegate.mem c @@ -257,7 +257,7 @@ module Delegate = struct let set_inactive ctxt delegate = ensure_inited ctxt delegate >>=? fun ctxt -> - let roll_value = Raw_context.roll_value ctxt in + let token_per_rolls = Constants_storage.token_per_rolls ctxt in Storage.Roll.Delegate_change.get ctxt delegate >>=? fun change -> Storage.Contract.Inactive_delegate.add ctxt (Contract_repr.implicit_contract delegate) >>= fun ctxt -> @@ -266,7 +266,7 @@ module Delegate = struct | None -> return (ctxt, change) | Some _roll -> pop_roll_from_delegate ctxt delegate >>=? fun (_, ctxt) -> - Lwt.return Tez_repr.(change +? roll_value) >>=? fun change -> + Lwt.return Tez_repr.(change +? token_per_rolls) >>=? fun change -> loop ctxt change in loop ctxt change >>=? fun (ctxt, change) -> Storage.Roll.Delegate_change.set ctxt delegate change >>=? fun ctxt -> @@ -300,16 +300,16 @@ module Delegate = struct return ctxt else begin ensure_inited ctxt delegate >>=? fun ctxt -> - let roll_value = Raw_context.roll_value ctxt in + let token_per_rolls = Constants_storage.token_per_rolls ctxt in Storage.Roll.Delegate_change.get ctxt delegate >>=? fun change -> Storage.Contract.Inactive_delegate.del ctxt (Contract_repr.implicit_contract delegate) >>= fun ctxt -> delegate_pubkey ctxt delegate >>=? fun delegate_pk -> let rec loop ctxt change = - if Tez_repr.(change < roll_value) then + if Tez_repr.(change < token_per_rolls) then return ctxt else - Lwt.return Tez_repr.(change -? roll_value) >>=? fun change -> + Lwt.return Tez_repr.(change -? token_per_rolls) >>=? fun change -> create_roll_in_delegate ctxt delegate delegate_pk >>=? fun ctxt -> loop ctxt change in loop ctxt change >>=? fun ctxt -> @@ -334,8 +334,6 @@ module Contract = struct end -let value = Raw_context.roll_value - let init ctxt = Storage.Roll.Next.init ctxt Roll_repr.first