diff --git a/docs/doc_gen/rpcs/usage.rst b/docs/doc_gen/rpcs/usage.rst index 8b0e6d6e6..eaf48fa79 100644 --- a/docs/doc_gen/rpcs/usage.rst +++ b/docs/doc_gen/rpcs/usage.rst @@ -9,7 +9,7 @@ client using this command ``tezos-admin-client rpc (get|post) ``. For instance, if you wish to request the current balance of a given block and contract, you can call the associated RPC via the command : -``$ tezos-admin-client rpc post +``$ tezos-admin-client rpc get /blocks//proto/context/contracts//balance``. A RPC may takes an *input* and generates an *output* both in JSON diff --git a/scripts/alphanet.sh b/scripts/alphanet.sh index 5384cd54f..326d55e31 100755 --- a/scripts/alphanet.sh +++ b/scripts/alphanet.sh @@ -382,7 +382,7 @@ run_shell() { display_head() { assert_node_uptodate exec_docker tezos-client rpc get /chains/main/blocks/head - exec_docker tezos-client rpc post /chains/main/blocks/head/context/level with {} + exec_docker tezos-client rpc get /chains/main/blocks/head/metadata/protocol_data/level } ## Main #################################################################### diff --git a/src/bin_client/test/test_multinode.sh b/src/bin_client/test/test_multinode.sh index ee26426d9..282ca1943 100755 --- a/src/bin_client/test/test_multinode.sh +++ b/src/bin_client/test/test_multinode.sh @@ -40,8 +40,8 @@ assert_propagation_level() { level=$1 printf "\n\nAsserting all nodes have reached level %s\n" "$level" for client in "${client_instances[@]}"; do - ( $client rpc post /chains/main/blocks/head/context/level with {} \ - | assert_in_output "\"level\": $level" ) \ + ( $client rpc get /chains/main/blocks/head/header/shell/level \ + | assert_in_output "$level" ) \ || exit 2 done } diff --git a/src/proto_alpha/lib_baking/client_baking_blocks.ml b/src/proto_alpha/lib_baking/client_baking_blocks.ml index 4db2397ed..0e0e042e1 100644 --- a/src/proto_alpha/lib_baking/client_baking_blocks.ml +++ b/src/proto_alpha/lib_baking/client_baking_blocks.ml @@ -29,7 +29,7 @@ let info cctxt ?(chain = `Main) block = cctxt ~chain ~block () >>=? fun next_protocol -> Block_services.Metadata.protocol_hash cctxt ~chain ~block () >>=? fun protocol -> - Alpha_services.Context.level cctxt (chain, block) >>=? fun level -> + Block_services.Metadata.protocol_data cctxt ~chain ~block () >>=? fun { level } -> let { Tezos_base.Block_header.predecessor ; fitness ; timestamp ; _ } = header in return { hash ; chain_id ; predecessor ; fitness ; timestamp ; protocol ; next_protocol ; level } @@ -50,7 +50,7 @@ let monitor_heads cctxt ?next_protocols chain = let blocks_from_cycle cctxt ?(chain = `Main) block cycle = Block_services.hash cctxt ~chain ~block () >>=? fun hash -> - Alpha_services.Context.level cctxt (chain, block) >>=? fun level -> + Block_services.Metadata.protocol_data cctxt ~chain ~block () >>=? fun { level } -> Alpha_services.Helpers.levels cctxt (chain, block) cycle >>=? fun (first, last) -> let length = Int32.to_int (Raw_level.diff level.level first) in Chain_services.Blocks.list cctxt ~heads:[hash] ~length () >>=? fun blocks -> diff --git a/src/proto_alpha/lib_baking/client_baking_endorsement.ml b/src/proto_alpha/lib_baking/client_baking_endorsement.ml index 3ba276e1d..72a230636 100644 --- a/src/proto_alpha/lib_baking/client_baking_endorsement.ml +++ b/src/proto_alpha/lib_baking/client_baking_endorsement.ml @@ -132,7 +132,8 @@ let forge_endorsement (cctxt : #Proto_alpha.full) ?(chain = `Main) block ~src_sk ?slots ?max_priority src_pk = let src_pkh = Signature.Public_key.hash src_pk in - Alpha_services.Context.level cctxt (chain, block) >>=? fun { level } -> + Block_services.Metadata.protocol_data + cctxt ~chain ~block () >>=? fun { level = { level } } -> begin match slots with | Some slots -> return slots diff --git a/src/proto_alpha/lib_baking/client_baking_forge.ml b/src/proto_alpha/lib_baking/client_baking_forge.ml index ab1b78535..ecbcc1aaf 100644 --- a/src/proto_alpha/lib_baking/client_baking_forge.ml +++ b/src/proto_alpha/lib_baking/client_baking_forge.ml @@ -156,7 +156,7 @@ let forge_block cctxt ?(chain = `Main) block return (priority, time) end | `Auto (src_pkh, max_priority, free_baking) -> - Alpha_services.Context.next_level cctxt (chain, block) >>=? fun { level } -> + Alpha_services.Helpers.next_level cctxt (chain, block) >>=? fun { level } -> Alpha_services.Delegate.Baker.rights_for_delegate cctxt ?max_priority ~first_level:level @@ -393,7 +393,7 @@ let compute_timeout { future_slots } = let get_unrevealed_nonces (cctxt : #Proto_alpha.full) ?(force = false) ?(chain = `Main) block = - Alpha_services.Context.next_level cctxt (chain, block) >>=? fun level -> + Alpha_services.Helpers.next_level cctxt (chain, block) >>=? fun level -> let cur_cycle = level.cycle in match Cycle.pred cur_cycle with | None -> return [] @@ -404,8 +404,8 @@ let get_unrevealed_nonces Client_baking_nonces.find cctxt hash >>=? function | None -> return None | Some nonce -> - Alpha_services.Context.level - cctxt (chain, `Hash (hash, 0)) >>=? fun level -> + Block_services.Metadata.protocol_data + cctxt ~chain ~block:(`Hash (hash, 0)) () >>=? fun { level } -> if force then return (Some (hash, (level.level, nonce))) else @@ -492,7 +492,7 @@ let bake (cctxt : #Proto_alpha.full) state = (fun (timestamp, (bi, priority, delegate)) -> let chain = `Hash bi.Client_baking_blocks.chain_id in let block = `Hash (bi.hash, 0) in - Alpha_services.Context.next_level cctxt (chain, block) >>=? fun next_level -> + Alpha_services.Helpers.next_level cctxt (chain, block) >>=? fun next_level -> let timestamp = if Block_hash.equal bi.Client_baking_blocks.hash state.genesis then Time.now () diff --git a/src/proto_alpha/lib_baking/client_baking_lib.ml b/src/proto_alpha/lib_baking/client_baking_lib.ml index 7e94935e5..9d3991c9a 100644 --- a/src/proto_alpha/lib_baking/client_baking_lib.ml +++ b/src/proto_alpha/lib_baking/client_baking_lib.ml @@ -21,7 +21,7 @@ let bake_block (cctxt : #Proto_alpha.full) return src_sk | Some sk -> return sk end >>=? fun src_sk -> - Alpha_services.Context.next_level cctxt (chain, block) >>=? fun level -> + Alpha_services.Helpers.next_level cctxt (chain, block) >>=? fun level -> let seed_nonce, seed_nonce_hash = if level.expected_commitment then let seed_nonce = Client_baking_forge.generate_seed_nonce () in 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 3c499b690..1fadc7772 100644 --- a/src/proto_alpha/lib_baking/test/proto_alpha_helpers.ml +++ b/src/proto_alpha/lib_baking/test/proto_alpha_helpers.ml @@ -146,8 +146,9 @@ let init ?exe ?vote ?rpc_port () = activate_alpha ?vote () >>=? fun hash -> return (pid, hash) -let level block = - Alpha_services.Context.level !rpc_ctxt block +let level (chain, block) = + Block_services.Metadata.protocol_data !rpc_ctxt ~chain ~block () >>=? fun { level } -> + return level let rpc_raw_context block path depth = Block_services.Context.Raw.read !rpc_ctxt ~block ~depth path @@ -335,11 +336,13 @@ module Protocol = struct open Account let voting_period_kind ?(block = `Head 0) () = - Alpha_services.Context.voting_period_kind !rpc_ctxt (`Main, block) + Block_services.Metadata.protocol_data + !rpc_ctxt ~chain:`Main ~block () >>=? fun { voting_period_kind } -> + return voting_period_kind let proposals ?(block = `Head 0) ~src:({ pkh; sk } : Account.t) proposals = Block_services.hash !rpc_ctxt ~block () >>=? fun hash -> - Alpha_services.Context.next_level + Alpha_services.Helpers.next_level !rpc_ctxt (`Main, block) >>=? fun next_level -> let shell = { Tezos_base.Operation.branch = hash } in let contents = @@ -351,7 +354,7 @@ module Protocol = struct let ballot ?(block = `Head 0) ~src:({ pkh; sk } : Account.t) ~proposal ballot = Block_services.hash !rpc_ctxt ~block () >>=? fun hash -> - Alpha_services.Context.next_level + Alpha_services.Helpers.next_level !rpc_ctxt (`Main, block) >>=? fun next_level -> let shell = { Tezos_base.Operation.branch = hash } in let contents = @@ -495,11 +498,12 @@ module Assert = struct block_proto h let check_voting_period_kind ?msg ~block kind = - Alpha_services.Context.voting_period_kind !rpc_ctxt (`Main, block) - >>=? fun current_kind -> + Block_services.Metadata.protocol_data + !rpc_ctxt ~chain:`Main ~block () >>=? fun { voting_period_kind } -> return @@ equal ?msg - current_kind kind + voting_period_kind + kind let is_none ?(msg="") x = if x <> None then fail "None" "Some _" msg @@ -512,7 +516,7 @@ module Baking = struct let bake block (contract: Account.t) operations = let ctxt = (new wrap_full (no_write_context ~block !rpc_config)) in - Alpha_services.Context.next_level ctxt (`Main, block) >>=? fun level -> + Alpha_services.Helpers.next_level ctxt (`Main, block) >>=? fun level -> let seed_nonce_hash = if level.Level.expected_commitment then let seed_nonce = @@ -546,7 +550,9 @@ module Endorse = struct src_sk slot = Block_services.hash !rpc_ctxt ~block () >>=? fun hash -> - Alpha_services.Context.level !rpc_ctxt (`Main, block) >>=? fun { level } -> + Block_services.Metadata.protocol_data + !rpc_ctxt ~chain:`Main ~block () >>=? fun { level } -> + let level = level.level in let shell = { Tezos_base.Operation.branch = hash } in let contents = Consensus_operation @@ -570,7 +576,9 @@ module Endorse = struct ?slot (contract : Account.t) block = - Alpha_services.Context.level !rpc_ctxt (`Main, block) >>=? fun { level } -> + Block_services.Metadata.protocol_data + !rpc_ctxt ~chain:`Main ~block () >>=? fun { level } -> + let level = level.level in begin match slot with | Some slot -> return slot @@ -597,7 +605,8 @@ module Endorse = struct in let { Account.b1 ; b2 ; b3 ; b4 ; b5 } = Account.bootstrap_accounts in let result = Array.make 16 b1 in - Alpha_services.Context.level !rpc_ctxt (`Main, block) >>=? fun level -> + Block_services.Metadata.protocol_data + !rpc_ctxt ~chain:`Main ~block () >>=? fun { level } -> let level = level.level in get_endorser_list result b1 level block >>=? fun () -> get_endorser_list result b2 level block >>=? fun () -> @@ -609,9 +618,10 @@ module Endorse = struct let endorsement_rights ?(max_priority = 1024) (contract : Account.t) block = - Alpha_services.Context.level !rpc_ctxt (`Main, block) >>=? fun level -> - let delegate = contract.pkh in + Block_services.Metadata.protocol_data + !rpc_ctxt ~chain:`Main ~block () >>=? fun { level } -> let level = level.level in + let delegate = contract.pkh in Alpha_services.Delegate.Endorser.rights_for_delegate !rpc_ctxt ~max_priority @@ -622,8 +632,9 @@ module Endorse = struct end let display_level block = - Alpha_services.Context.level !rpc_ctxt (`Main, block) >>=? fun lvl -> - Format.eprintf "Level: %a@." Level.pp_full lvl ; + Block_services.Metadata.protocol_data + !rpc_ctxt ~chain:`Main ~block () >>=? fun { level } -> + Format.eprintf "Level: %a@." Level.pp_full level ; return () let endorsement_security_deposit block = diff --git a/src/proto_alpha/lib_baking/test/proto_alpha_helpers.mli b/src/proto_alpha/lib_baking/test/proto_alpha_helpers.mli index 2a81dcd92..750ddcbd5 100644 --- a/src/proto_alpha/lib_baking/test/proto_alpha_helpers.mli +++ b/src/proto_alpha/lib_baking/test/proto_alpha_helpers.mli @@ -19,7 +19,8 @@ val init : forked Tezos node and the block info of the block from where the tests will begin. *) -val level : Chain_services.chain * Block_services.block -> Alpha_context.Level.t tzresult Lwt.t +val level: + Chain_services.chain * Block_services.block -> Alpha_context.Level.t tzresult Lwt.t (** Calls the rpc service raw_context using the right rpc context *) val rpc_raw_context : Block_services.block -> string list -> int -> diff --git a/src/proto_alpha/lib_protocol/src/alpha_services.ml b/src/proto_alpha/lib_protocol/src/alpha_services.ml index a9ec6ca73..da4b62605 100644 --- a/src/proto_alpha/lib_protocol/src/alpha_services.ml +++ b/src/proto_alpha/lib_protocol/src/alpha_services.ml @@ -11,62 +11,6 @@ open Alpha_context let custom_root = RPC_path.open_root -module Context = struct - - module S = struct - - open Data_encoding - - let level = - RPC_service.post_service - ~description: "Detailled level information for the current block" - ~query: RPC_query.empty - ~input: empty - ~output: Level.encoding - RPC_path.(custom_root / "context" / "level") - - let next_level = - RPC_service.post_service - ~description: "Detailled level information for the next block" - ~query: RPC_query.empty - ~input: empty - ~output: Level.encoding - RPC_path.(custom_root / "context" / "next_level") - - let voting_period_kind = - RPC_service.post_service - ~description: "Voting period kind for the current block" - ~query: RPC_query.empty - ~input: empty - ~output: - (obj1 (req "voting_period_kind" Voting_period.kind_encoding)) - RPC_path.(custom_root / "context" / "voting_period_kind") - - end - - let () = - let open Services_registration in - register0 S.level begin fun ctxt () () -> - return (Level.current ctxt) - end ; - register0 S.next_level begin fun ctxt () () -> - return (Level.succ ctxt (Level.current ctxt)) - end ; - register0 S.voting_period_kind begin fun ctxt () () -> - Vote.get_current_period_kind ctxt - end - - let level ctxt block = - RPC_context.make_call0 S.level ctxt block () () - - let next_level ctxt block = - RPC_context.make_call0 S.next_level ctxt block () () - - let voting_period_kind ctxt block = - RPC_context.make_call0 S.voting_period_kind ctxt block () () - -end - module Nonce = struct type info = @@ -93,23 +37,12 @@ module Nonce = struct module S = struct - open Data_encoding - let get = - RPC_service.post_service + RPC_service.get_service ~description: "Info about the nonce of a previous block." ~query: RPC_query.empty - ~input: empty ~output: info_encoding - RPC_path.(custom_root / "context" / "nonce" /: Raw_level.arg) - - let hash = - RPC_service.post_service - ~description: "Hash of the current block's nonce." - ~query: RPC_query.empty - ~input: empty - ~output: Nonce_hash.encoding - RPC_path.(custom_root / "context" / "nonce") + RPC_path.(custom_root / "context" / "nonces" /: Raw_level.arg) end @@ -122,20 +55,11 @@ module Nonce = struct | Ok (Unrevealed { nonce_hash ; _ }) -> return (Missing nonce_hash) | Error _ -> return Forgotten - end ; - register0 S.hash begin fun ctxt () () -> - let level = Level.current ctxt in - Nonce.get ctxt level >>=? function - | Unrevealed { nonce_hash ; _ } -> return nonce_hash - | _ -> assert false end let get ctxt block level = RPC_context.make_call1 S.get ctxt block level () () - let hash ctxt block = - RPC_context.make_call0 S.hash ctxt block () () - end module Contract = Contract_services diff --git a/src/proto_alpha/lib_protocol/src/alpha_services.mli b/src/proto_alpha/lib_protocol/src/alpha_services.mli index 3dd64bab3..46c495c37 100644 --- a/src/proto_alpha/lib_protocol/src/alpha_services.mli +++ b/src/proto_alpha/lib_protocol/src/alpha_services.mli @@ -9,31 +9,8 @@ open Alpha_context -module Context : sig - - val level: - 'a #RPC_context.simple -> 'a -> Level.t shell_tzresult Lwt.t - (** [level cctxt blk] returns the (protocol view of the) level of - [blk]. *) - - val next_level: - 'a #RPC_context.simple -> 'a -> Level.t shell_tzresult Lwt.t - (** [next_level cctxt blk] returns the (protocol view of the) level - of the successor of [blk]. *) - - val voting_period_kind: - 'a #RPC_context.simple -> 'a -> Voting_period.kind shell_tzresult Lwt.t - (** [voting_period_kind cctxt blk] returns the voting period kind - of [blk]. *) - -end - module Nonce : sig - val hash: - 'a #RPC_context.simple -> - 'a -> Nonce_hash.t shell_tzresult Lwt.t - type info = | Revealed of Nonce.t | Missing of Nonce_hash.t diff --git a/src/proto_alpha/lib_protocol/src/helpers_services.ml b/src/proto_alpha/lib_protocol/src/helpers_services.ml index 8bb44d682..1eed38a98 100644 --- a/src/proto_alpha/lib_protocol/src/helpers_services.ml +++ b/src/proto_alpha/lib_protocol/src/helpers_services.ml @@ -40,6 +40,14 @@ module S = struct let custom_root = RPC_path.(open_root / "helpers") + let next_level = + RPC_service.post_service + ~description: "Detailled level information for the next block" + ~query: RPC_query.empty + ~input: empty + ~output: Level.encoding + RPC_path.(custom_root / "next_level") + let minimal_timestamp = RPC_service.post_service ~description: "Minimal timestamp for the next block." @@ -173,6 +181,9 @@ end let () = let open Services_registration in + register0 S.next_level begin fun ctxt () () -> + return (Level.succ ctxt (Level.current ctxt)) + end ; register0 S.minimal_timestamp begin fun ctxt () slot -> let timestamp = Alpha_context.Timestamp.current ctxt in let slot = match slot with None -> 0 | Some p -> p in @@ -243,6 +254,9 @@ let () = return (first.level, last.level) end +let next_level ctxt block = + RPC_context.make_call0 S.next_level ctxt block () () + let minimal_time ctxt ?priority block = RPC_context.make_call0 S.minimal_timestamp ctxt block () priority diff --git a/src/proto_alpha/lib_protocol/src/helpers_services.mli b/src/proto_alpha/lib_protocol/src/helpers_services.mli index c2189d7bc..c28e869c5 100644 --- a/src/proto_alpha/lib_protocol/src/helpers_services.mli +++ b/src/proto_alpha/lib_protocol/src/helpers_services.mli @@ -13,6 +13,11 @@ type error += | Cannot_parse_operation (* `Branch *) | Cant_parse_block_header +val next_level: + 'a #RPC_context.simple -> 'a -> Level.t shell_tzresult Lwt.t +(** [next_level cctxt blk] returns the (protocol view of the) level + of the successor of [blk]. *) + val minimal_time: 'a #RPC_context.simple -> ?priority:int -> 'a -> Time.t shell_tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.ml b/src/proto_alpha/lib_protocol/test/helpers/block.ml index fb072077e..1bcdb6354 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/block.ml @@ -139,7 +139,7 @@ module Forge = struct | Error _ -> assert false end >>=? fun fitness -> begin - Alpha_services.Context.next_level (rpc_ctxt) pred >>|? function + Alpha_services.Helpers.next_level (rpc_ctxt) pred >>|? function | { expected_commitment = true } -> Some (fst (Proto_Nonce.generate ())) | { expected_commitment = false } -> None end >>=? fun seed_nonce_hash -> diff --git a/src/proto_alpha/lib_protocol/test/helpers/jbuild b/src/proto_alpha/lib_protocol/test/helpers/jbuild index 4e2906700..9b11336a6 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/jbuild +++ b/src/proto_alpha/lib_protocol/test/helpers/jbuild @@ -4,12 +4,14 @@ ((name tezos_alpha_test_helpers) (libraries (tezos-base tezos-stdlib-unix + tezos-shell-services tezos-protocol-environment tezos-protocol-alpha alcotest-lwt)) (flags (:standard -w -9-32 -safe-string -open Tezos_base__TzPervasives - -open Tezos_stdlib_unix)))) + -open Tezos_stdlib_unix + -open Tezos_shell_services)))) (alias ((name runtest_indent) diff --git a/src/proto_alpha/lib_protocol/test/helpers/proto_alpha.ml b/src/proto_alpha/lib_protocol/test/helpers/proto_alpha.ml index 8667d8d37..3648b99c8 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/proto_alpha.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/proto_alpha.ml @@ -13,6 +13,11 @@ module Alpha_environment = Tezos_protocol_environment_memory.MakeV1(Name)() type alpha_error = Alpha_environment.Error_monad.error type 'a alpha_tzresult = 'a Alpha_environment.Error_monad.tzresult -include Tezos_protocol_alpha.Functor.Make(Alpha_environment) +module Proto = Tezos_protocol_alpha.Functor.Make(Alpha_environment) +module Block_services = struct + include Block_services + include Block_services.Make(Proto)(Proto) +end +include Proto module M = Alpha_environment.Lift(Main)