From e4ffbd2854e0462a51b4ffd3129f95338ed0c6f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Tue, 29 May 2018 12:30:00 +0200 Subject: [PATCH] RPC: remove access to a single contant --- .../lib_baking/client_baking_forge.ml | 12 +- .../lib_baking/test/proto_alpha_helpers.ml | 3 +- src/proto_alpha/lib_client/injection.ml | 9 +- .../client_proto_programs_commands.ml | 7 +- .../lib_protocol/src/constants_services.ml | 219 ------------------ .../lib_protocol/src/constants_services.mli | 54 ----- 6 files changed, 21 insertions(+), 283 deletions(-) diff --git a/src/proto_alpha/lib_baking/client_baking_forge.ml b/src/proto_alpha/lib_baking/client_baking_forge.ml index ab577852e..fdbf62412 100644 --- a/src/proto_alpha/lib_baking/client_baking_forge.ml +++ b/src/proto_alpha/lib_baking/client_baking_forge.ml @@ -24,8 +24,10 @@ let generate_seed_nonce () = let forge_block_header (cctxt : #Proto_alpha.full) ?(chain = `Main) block delegate_sk shell priority seed_nonce_hash = - Alpha_services.Constants.proof_of_work_threshold - cctxt (chain, block) >>=? fun stamp_threshold -> + Alpha_services.Constants.all cctxt + (chain, block) >>=? fun { parametric = { + proof_of_work_threshold = stamp_threshold ; + } } -> let rec loop () = let proof_of_work_nonce = generate_proof_of_work_nonce () in let contents = @@ -171,7 +173,11 @@ let forge_block cctxt ?(chain = `Main) block try begin if free_baking then - Alpha_services.Constants.first_free_baking_slot cctxt (chain, block) + Alpha_services.Constants.all cctxt + (chain, block) >>=? fun { parametric = { + first_free_baking_slot ; + } } -> + return first_free_baking_slot else return 0 end >>=? fun min_prio -> diff --git a/src/proto_alpha/lib_baking/test/proto_alpha_helpers.ml b/src/proto_alpha/lib_baking/test/proto_alpha_helpers.ml index ca39a2a93..8fe8f2b18 100644 --- a/src/proto_alpha/lib_baking/test/proto_alpha_helpers.ml +++ b/src/proto_alpha/lib_baking/test/proto_alpha_helpers.ml @@ -634,7 +634,8 @@ let display_level block = return () let endorsement_security_deposit block = - Constants_services.endorsement_security_deposit !rpc_ctxt (`Main, block) + Constants_services.all !rpc_ctxt (`Main, block) >>=? fun c -> + return c.parametric.endorsement_security_deposit let () = Client_keys.register_signer diff --git a/src/proto_alpha/lib_client/injection.ml b/src/proto_alpha/lib_client/injection.ml index 84832c2fc..ef3a7a539 100644 --- a/src/proto_alpha/lib_client/injection.ml +++ b/src/proto_alpha/lib_client/injection.ml @@ -198,10 +198,11 @@ let detect_script_failure : let may_patch_limits (type kind) (cctxt : #Proto_alpha.full) ~chain ~block ?branch ?src_sk (contents: kind contents_list) : kind contents_list tzresult Lwt.t = - Alpha_services.Constants.hard_gas_limits - cctxt (chain, block) >>=? fun (_, gas_limit) -> - Alpha_services.Constants.hard_storage_limits - cctxt (chain, block) >>=? fun (_, storage_limit) -> + Alpha_services.Constants.all cctxt + (chain, block) >>=? fun { parametric = { + hard_gas_limit_per_operation = gas_limit ; + hard_storage_limit_per_operation = storage_limit ; + } } -> let may_need_patching_single : type kind. kind contents -> kind contents option = function | Manager_operation c diff --git a/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml index 0e7ef7e61..a467a7557 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml @@ -55,8 +55,11 @@ let commands () = with _ -> failwith "invalid gas limit (must be a positive number)")) in let resolve_max_gas cctxt block = function | None -> - Alpha_services.Constants.hard_gas_limits cctxt (`Main, block) >>=? fun (_, gas) -> - return gas + Alpha_services.Constants.all cctxt + (`Main, block) >>=? fun { parametric = { + hard_gas_limit_per_operation + } } -> + return hard_gas_limit_per_operation | Some gas -> return gas in let data_parameter = Clic.parameter (fun _ data -> diff --git a/src/proto_alpha/lib_protocol/src/constants_services.ml b/src/proto_alpha/lib_protocol/src/constants_services.ml index 2536a9c4a..2a73dd2c9 100644 --- a/src/proto_alpha/lib_protocol/src/constants_services.ml +++ b/src/proto_alpha/lib_protocol/src/constants_services.ml @@ -16,132 +16,6 @@ module S = struct open Data_encoding - let preserved_cycles = - RPC_service.get_service - ~description: "How many cycle before the 'no-automatic-fork point'" - ~query: RPC_query.empty - ~output: int31 - RPC_path.(custom_root / "preserved_cycles") - - let blocks_per_cycle = - RPC_service.get_service - ~description: "Cycle length" - ~query: RPC_query.empty - ~output: int32 - RPC_path.(custom_root / "blocks_per_cycle") - - let blocks_per_voting_period = - RPC_service.get_service - ~description: "Length of the voting period" - ~query: RPC_query.empty - ~output: int32 - RPC_path.(custom_root / "blocks_per_voting_period") - - let blocks_per_commitment = - RPC_service.get_service - ~description: "How many blocks between random seed's nonce commitment" - ~query: RPC_query.empty - ~output: int32 - RPC_path.(custom_root / "blocks_per_commitment") - - let blocks_per_roll_snapshot = - RPC_service.get_service - ~description: "How many blocks between roll snapshots" - ~query: RPC_query.empty - ~output: int32 - RPC_path.(custom_root / "blocks_per_roll_snapshot") - - let time_between_blocks = - RPC_service.get_service - ~description: "Slot durations" - ~query: RPC_query.empty - ~output: (list Period.encoding) - RPC_path.(custom_root / "time_between_slots") - - let first_free_baking_slot = - RPC_service.get_service - ~description: "First free baking slot" - ~query: RPC_query.empty - ~output: uint16 - RPC_path.(custom_root / "first_free_baking_slot") - - let endorsers_per_block = - RPC_service.get_service - ~description: "Max signing slot" - ~query: RPC_query.empty - ~output: uint16 - RPC_path.(custom_root / "endorsers_per_block") - - let hard_gas_limits = - RPC_service.get_service - ~description: "Hard maximum amount of gas per operation and per block" - ~query: RPC_query.empty - ~output: (obj2 (req "per_block" z) (req "per_operation" z)) - RPC_path.(custom_root / "hard_gas_limits") - - let hard_storage_limits = - RPC_service.get_service - ~description: "Hard maximum amount of bytes stored per operation and per block" - ~query: RPC_query.empty - ~output: (obj2 (req "per_block" int64) (req "per_operation" int64)) - RPC_path.(custom_root / "hard_storage_limits") - - let cost_per_byte = - RPC_service.get_service - ~description: "The cost per bytes added to the storage" - ~query: RPC_query.empty - ~output: (obj1 (req "cost_per_byte" Tez.encoding)) - RPC_path.(custom_root / "cost_per_byte") - - let proof_of_work_threshold = - RPC_service.get_service - ~description: "Stamp threshold" - ~query: RPC_query.empty - ~output: int64 - RPC_path.(custom_root / "proof_of_work_threshold") - - let seed_nonce_revelation_tip = - RPC_service.get_service - ~description: "seed_nonce_revelation_tip" - ~query: RPC_query.empty - ~output: Tez.encoding - RPC_path.(custom_root / "seed_nonce_revelation_tip") - - let origination_burn = - RPC_service.get_service - ~description: "origination_burn" - ~query: RPC_query.empty - ~output: Tez.encoding - RPC_path.(custom_root / "origination_burn") - - let block_security_deposit = - RPC_service.get_service - ~description: "block_security_deposit" - ~query: RPC_query.empty - ~output: Tez.encoding - RPC_path.(custom_root / "block_security_deposit") - - let endorsement_security_deposit = - RPC_service.get_service - ~description: "endorsement_security_deposit" - ~query: RPC_query.empty - ~output: Tez.encoding - RPC_path.(custom_root / "endorsement_security_deposit") - - let block_reward = - RPC_service.get_service - ~description: "block_reward" - ~query: RPC_query.empty - ~output: Tez.encoding - RPC_path.(custom_root / "block_reward") - - let endorsement_reward = - RPC_service.get_service - ~description: "endorsement_reward" - ~query: RPC_query.empty - ~output: Tez.encoding - RPC_path.(custom_root / "endorsement_reward") - let errors = RPC_service.get_service ~description: "Schema for all the RPC errors from this protocol version" @@ -158,65 +32,8 @@ module S = struct end - let () = let open Services_registration in - register0 S.preserved_cycles begin fun ctxt () () -> - return (Constants.preserved_cycles ctxt) - end ; - register0 S.blocks_per_cycle begin fun ctxt () () -> - return (Constants.blocks_per_cycle ctxt) - end ; - register0 S.blocks_per_voting_period begin fun ctxt () () -> - return (Constants.blocks_per_voting_period ctxt) - end ; - register0 S.blocks_per_commitment begin fun ctxt () () -> - return (Constants.blocks_per_commitment ctxt) - end ; - register0 S.blocks_per_roll_snapshot begin fun ctxt () () -> - return (Constants.blocks_per_roll_snapshot ctxt) - end ; - register0 S.time_between_blocks begin fun ctxt () () -> - return (Constants.time_between_blocks ctxt) - end ; - register0 S.first_free_baking_slot begin fun ctxt () () -> - return (Constants.first_free_baking_slot ctxt) - end ; - register0 S.endorsers_per_block begin fun ctxt () () -> - return (Constants.endorsers_per_block ctxt) - end ; - register0 S.hard_gas_limits begin fun ctxt () () -> - return (Constants.hard_gas_limit_per_block ctxt, - Constants.hard_gas_limit_per_operation ctxt) - end ; - register0 S.hard_storage_limits begin fun ctxt () () -> - return (Constants.hard_storage_limit_per_block ctxt, - Constants.hard_storage_limit_per_operation ctxt) - end ; - register0 S.cost_per_byte begin fun ctxt () () -> - return (Constants.cost_per_byte ctxt) - end ; - register0 S.proof_of_work_threshold begin fun ctxt () () -> - return (Constants.proof_of_work_threshold ctxt) - end ; - register0 S.seed_nonce_revelation_tip begin fun ctxt () () -> - return (Constants.seed_nonce_revelation_tip ctxt) - end ; - register0 S.origination_burn begin fun ctxt () () -> - return (Constants.origination_burn ctxt) - end ; - register0 S.block_security_deposit begin fun ctxt () () -> - return (Constants.block_security_deposit ctxt) - end ; - register0 S.endorsement_security_deposit begin fun ctxt () () -> - return (Constants.endorsement_security_deposit ctxt) - end ; - register0 S.block_reward begin fun ctxt () () -> - return (Constants.block_reward ctxt) - end ; - register0 S.endorsement_reward begin fun ctxt () () -> - return (Constants.endorsement_reward ctxt) - end ; register0_noctxt S.errors begin fun () () -> return (Data_encoding.Json.(schema error_encoding)) end ; @@ -226,42 +43,6 @@ let () = parametric = parametric ctxt } end -let blocks_per_cycle ctxt block = - RPC_context.make_call0 S.blocks_per_cycle ctxt block () () -let preserved_cycles ctxt block = - RPC_context.make_call0 S.preserved_cycles ctxt block () () -let blocks_per_voting_period ctxt block = - RPC_context.make_call0 S.blocks_per_voting_period ctxt block () () -let blocks_per_commitment ctxt block = - RPC_context.make_call0 S.blocks_per_commitment ctxt block () () -let blocks_per_roll_snapshot ctxt block = - RPC_context.make_call0 S.blocks_per_roll_snapshot ctxt block () () -let time_between_blocks ctxt block = - RPC_context.make_call0 S.time_between_blocks ctxt block () () -let first_free_baking_slot ctxt block = - RPC_context.make_call0 S.first_free_baking_slot ctxt block () () -let endorsers_per_block ctxt block = - RPC_context.make_call0 S.endorsers_per_block ctxt block () () -let hard_gas_limits ctxt block = - RPC_context.make_call0 S.hard_gas_limits ctxt block () () -let cost_per_byte ctxt block = - RPC_context.make_call0 S.cost_per_byte ctxt block () () -let hard_storage_limits ctxt block = - RPC_context.make_call0 S.hard_storage_limits ctxt block () () -let proof_of_work_threshold ctxt block = - RPC_context.make_call0 S.proof_of_work_threshold ctxt block () () -let seed_nonce_revelation_tip ctxt block = - RPC_context.make_call0 S.seed_nonce_revelation_tip ctxt block () () -let origination_burn ctxt block = - RPC_context.make_call0 S.origination_burn ctxt block () () -let block_security_deposit ctxt block = - RPC_context.make_call0 S.block_security_deposit ctxt block () () -let endorsement_security_deposit ctxt block = - RPC_context.make_call0 S.endorsement_security_deposit ctxt block () () -let block_reward ctxt block = - RPC_context.make_call0 S.block_reward ctxt block () () -let endorsement_reward ctxt block = - RPC_context.make_call0 S.endorsement_reward ctxt block () () let errors ctxt block = RPC_context.make_call0 S.errors ctxt block () () let all 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 9cc0e4dd5..b03cef85e 100644 --- a/src/proto_alpha/lib_protocol/src/constants_services.mli +++ b/src/proto_alpha/lib_protocol/src/constants_services.mli @@ -9,60 +9,6 @@ open Alpha_context -val preserved_cycles: - 'a #RPC_context.simple -> 'a -> int shell_tzresult Lwt.t - -val blocks_per_cycle: - 'a #RPC_context.simple -> 'a -> int32 shell_tzresult Lwt.t - -val blocks_per_commitment: - 'a #RPC_context.simple -> 'a -> int32 shell_tzresult Lwt.t - -val blocks_per_roll_snapshot: - 'a #RPC_context.simple -> 'a -> int32 shell_tzresult Lwt.t - -val blocks_per_voting_period: - 'a #RPC_context.simple -> 'a -> int32 shell_tzresult Lwt.t - -val time_between_blocks: - 'a #RPC_context.simple -> 'a -> Period.t list shell_tzresult Lwt.t - -val first_free_baking_slot: - 'a #RPC_context.simple -> 'a -> int shell_tzresult Lwt.t - -val endorsers_per_block: - 'a #RPC_context.simple -> 'a -> int shell_tzresult Lwt.t - -val hard_gas_limits: - 'a #RPC_context.simple -> 'a -> (Z.t * Z.t) shell_tzresult Lwt.t - -val hard_storage_limits: - 'a #RPC_context.simple -> 'a -> (Int64.t * Int64.t) shell_tzresult Lwt.t - -val cost_per_byte: - 'a #RPC_context.simple -> 'a -> Tez.t shell_tzresult Lwt.t - -val proof_of_work_threshold: - 'a #RPC_context.simple -> 'a -> Int64.t shell_tzresult Lwt.t - -val seed_nonce_revelation_tip: - 'a #RPC_context.simple -> 'a -> Tez.t shell_tzresult Lwt.t - -val origination_burn: - 'a #RPC_context.simple -> 'a -> Tez.t shell_tzresult Lwt.t - -val block_security_deposit: - 'a #RPC_context.simple -> 'a -> Tez.t shell_tzresult Lwt.t - -val endorsement_security_deposit: - 'a #RPC_context.simple -> 'a -> Tez.t shell_tzresult Lwt.t - -val block_reward: - 'a #RPC_context.simple -> 'a -> Tez.t shell_tzresult Lwt.t - -val endorsement_reward: - 'a #RPC_context.simple -> 'a -> Tez.t shell_tzresult Lwt.t - val errors: 'a #RPC_context.simple -> 'a -> Data_encoding.json_schema shell_tzresult Lwt.t