From bd721b1085945dcbda1e765d1fa40a38b9242a57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Fri, 23 Feb 2018 11:13:20 -0500 Subject: [PATCH] Alpha: add constant "preserved_cycles" --- .../lib_protocol/src/alpha_context.mli | 1 + .../lib_protocol/src/constants_repr.ml | 54 +++++++++++-------- .../lib_protocol/src/constants_services.ml | 13 +++++ .../lib_protocol/src/constants_services.mli | 3 ++ 4 files changed, 49 insertions(+), 22 deletions(-) diff --git a/src/proto_alpha/lib_protocol/src/alpha_context.mli b/src/proto_alpha/lib_protocol/src/alpha_context.mli index 04efc2212..b09796289 100644 --- a/src/proto_alpha/lib_protocol/src/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/src/alpha_context.mli @@ -261,6 +261,7 @@ module Constants : sig val endorsement_bond_cost: Tez.t val faucet_credit: Tez.t + val preserved_cycles: context -> int val cycle_length: context -> int32 val voting_period_length: context -> int32 val time_before_reward: context -> Period.t diff --git a/src/proto_alpha/lib_protocol/src/constants_repr.ml b/src/proto_alpha/lib_protocol/src/constants_repr.ml index 7aedfb626..590891ac9 100644 --- a/src/proto_alpha/lib_protocol/src/constants_repr.ml +++ b/src/proto_alpha/lib_protocol/src/constants_repr.ml @@ -45,6 +45,7 @@ let bootstrap_wealth = Tez_repr.(mul_exn one 4_000_000) type constants = { + preserved_cycles: int ; cycle_length: int32 ; voting_period_length: int32 ; time_before_reward: Period_repr.t ; @@ -64,6 +65,7 @@ type constants = { let read_public_key s = Ed25519.Public_key.of_hex_exn (`Hex s) let default = { + preserved_cycles = 5 ; cycle_length = 2048l ; voting_period_length = 32768l ; time_before_reward = @@ -112,7 +114,10 @@ let constants_encoding = (fun c -> let module Compare_slot_durations = Compare.List (Period_repr) in let module Compare_keys = Compare.List (Ed25519.Public_key) in - let cycle_length = + let preserved_cycles = + opt Compare.Int.(=) + default.preserved_cycles c.preserved_cycles + and cycle_length = opt Compare.Int32.(=) default.cycle_length c.cycle_length and voting_period_length = @@ -156,35 +161,39 @@ let constants_encoding = opt Compare.Int.(=) default.michelson_maximum_type_size c.michelson_maximum_type_size in - ((( cycle_length, + ((( preserved_cycles, + cycle_length, voting_period_length, time_before_reward, slot_durations, first_free_baking_slot, max_signing_slot, max_gas, - proof_of_work_threshold, - bootstrap_keys, - dictator_pubkey), - (max_number_of_operations, - max_operation_data_length, - initial_roll_value, - michelson_maximum_type_size)), ()) ) - (fun ((( cycle_length, + proof_of_work_threshold), + ( bootstrap_keys, + dictator_pubkey, + max_number_of_operations, + max_operation_data_length, + initial_roll_value, + michelson_maximum_type_size)), ()) ) + (fun ((( preserved_cycles, + cycle_length, voting_period_length, time_before_reward, slot_durations, first_free_baking_slot, max_signing_slot, max_gas, - proof_of_work_threshold, - bootstrap_keys, - dictator_pubkey), - (max_number_of_operations, - max_operation_data_length, - initial_roll_value, - michelson_maximum_type_size)), ()) -> - { cycle_length = + proof_of_work_threshold), + ( bootstrap_keys, + dictator_pubkey, + max_number_of_operations, + max_operation_data_length, + initial_roll_value, + michelson_maximum_type_size)), ()) -> + { preserved_cycles = + unopt default.preserved_cycles preserved_cycles ; + cycle_length = unopt default.cycle_length cycle_length ; voting_period_length = unopt default.voting_period_length voting_period_length ; @@ -218,7 +227,8 @@ let constants_encoding = Data_encoding.( merge_objs (merge_objs - (obj10 + (obj9 + (opt "preserved_cycles" uint8) (opt "cycle_length" int32) (opt "voting_period_length" int32) (opt "time_before_reward" int64) @@ -226,10 +236,10 @@ let constants_encoding = (opt "first_free_baking_slot" uint16) (opt "max_signing_slot" uint16) (opt "instructions_per_transaction" int31) - (opt "proof_of_work_threshold" int64) + (opt "proof_of_work_threshold" int64)) + (obj6 (opt "bootstrap_keys" (list Ed25519.Public_key.encoding)) - (opt "dictator_pubkey" Ed25519.Public_key.encoding)) - (obj4 + (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) diff --git a/src/proto_alpha/lib_protocol/src/constants_services.ml b/src/proto_alpha/lib_protocol/src/constants_services.ml index 0c0a2f463..100092d10 100644 --- a/src/proto_alpha/lib_protocol/src/constants_services.ml +++ b/src/proto_alpha/lib_protocol/src/constants_services.ml @@ -16,6 +16,14 @@ module S = struct open Data_encoding + let preserved_cycles = + RPC_service.post_service + ~description: "How many cycle before the 'no-automatic-fork point'" + ~query: RPC_query.empty + ~input: empty + ~output: (obj1 (req "preserved_cycles" int31)) + RPC_path.(custom_root / "preserved_cycles") + let cycle_length = RPC_service.post_service ~description: "Cycle length" @@ -93,6 +101,9 @@ end let () = let open Services_registration in + register0 S.preserved_cycles begin fun ctxt () () -> + return (Constants.preserved_cycles ctxt) + end ; register0 S.cycle_length begin fun ctxt () () -> return (Constants.cycle_length ctxt) end ; @@ -123,6 +134,8 @@ let () = let cycle_length ctxt block = RPC_context.make_call0 S.cycle_length ctxt block () () +let preserved_cycles ctxt block = + RPC_context.make_call0 S.preserved_cycles ctxt block () () let voting_period_length ctxt block = RPC_context.make_call0 S.voting_period_length ctxt block () () let time_before_reward ctxt block = diff --git a/src/proto_alpha/lib_protocol/src/constants_services.mli b/src/proto_alpha/lib_protocol/src/constants_services.mli index 1e19d8754..81060f60c 100644 --- a/src/proto_alpha/lib_protocol/src/constants_services.mli +++ b/src/proto_alpha/lib_protocol/src/constants_services.mli @@ -9,6 +9,9 @@ open Alpha_context +val preserved_cycles: + 'a #RPC_context.simple -> 'a -> int shell_tzresult Lwt.t + val cycle_length: 'a #RPC_context.simple -> 'a -> int32 shell_tzresult Lwt.t