Alpha/RPC: more query parameters in /helpers

This commit is contained in:
Grégoire Henry 2018-04-20 15:43:59 +02:00 committed by Benjamin Canou
parent 482dbb116c
commit b11a604d20
6 changed files with 70 additions and 74 deletions

View File

@ -156,7 +156,8 @@ let forge_block cctxt ?(chain = `Main) block
return (priority, Some time) return (priority, Some time)
end end
| `Auto (src_pkh, max_priority, free_baking) -> | `Auto (src_pkh, max_priority, free_baking) ->
Alpha_services.Helpers.next_level cctxt (chain, block) >>=? fun { level } -> Alpha_services.Helpers.level
cctxt ~offset:1l (chain, block)>>=? fun { level } ->
Alpha_services.Delegate.Baking_rights.get cctxt Alpha_services.Delegate.Baking_rights.get cctxt
?max_priority ?max_priority
~levels:[level] ~levels:[level]
@ -392,7 +393,7 @@ let compute_timeout { future_slots } =
let get_unrevealed_nonces let get_unrevealed_nonces
(cctxt : #Proto_alpha.full) ?(force = false) ?(chain = `Main) block = (cctxt : #Proto_alpha.full) ?(force = false) ?(chain = `Main) block =
Alpha_services.Helpers.next_level cctxt (chain, block) >>=? fun level -> Alpha_services.Helpers.level cctxt ~offset:1l (chain, block) >>=? fun level ->
let cur_cycle = level.cycle in let cur_cycle = level.cycle in
match Cycle.pred cur_cycle with match Cycle.pred cur_cycle with
| None -> return [] | None -> return []
@ -491,7 +492,7 @@ let bake (cctxt : #Proto_alpha.full) state =
(fun (timestamp, (bi, priority, delegate)) -> (fun (timestamp, (bi, priority, delegate)) ->
let chain = `Hash bi.Client_baking_blocks.chain_id in let chain = `Hash bi.Client_baking_blocks.chain_id in
let block = `Hash (bi.hash, 0) in let block = `Hash (bi.hash, 0) in
Alpha_services.Helpers.next_level cctxt (chain, block) >>=? fun next_level -> Alpha_services.Helpers.level cctxt ~offset:1l (chain, block) >>=? fun next_level ->
let timestamp = let timestamp =
if Block_hash.equal bi.Client_baking_blocks.hash state.genesis then if Block_hash.equal bi.Client_baking_blocks.hash state.genesis then
Time.now () Time.now ()

View File

@ -21,7 +21,7 @@ let bake_block (cctxt : #Proto_alpha.full)
return src_sk return src_sk
| Some sk -> return sk | Some sk -> return sk
end >>=? fun src_sk -> end >>=? fun src_sk ->
Alpha_services.Helpers.next_level cctxt (chain, block) >>=? fun level -> Alpha_services.Helpers.level cctxt ~offset:1l (chain, block) >>=? fun level ->
let seed_nonce, seed_nonce_hash = let seed_nonce, seed_nonce_hash =
if level.expected_commitment then if level.expected_commitment then
let seed_nonce = Client_baking_forge.generate_seed_nonce () in let seed_nonce = Client_baking_forge.generate_seed_nonce () in

View File

@ -342,8 +342,8 @@ module Protocol = struct
let proposals ?(block = `Head 0) ~src:({ pkh; sk } : Account.t) proposals = let proposals ?(block = `Head 0) ~src:({ pkh; sk } : Account.t) proposals =
Block_services.hash !rpc_ctxt ~block () >>=? fun hash -> Block_services.hash !rpc_ctxt ~block () >>=? fun hash ->
Alpha_services.Helpers.next_level Alpha_services.Helpers.level
!rpc_ctxt (`Main, block) >>=? fun next_level -> !rpc_ctxt ~offset:1l (`Main, block) >>=? fun next_level ->
let shell = { Tezos_base.Operation.branch = hash } in let shell = { Tezos_base.Operation.branch = hash } in
let contents = let contents =
Amendment_operation Amendment_operation
@ -354,8 +354,8 @@ module Protocol = struct
let ballot ?(block = `Head 0) ~src:({ pkh; sk } : Account.t) ~proposal ballot = let ballot ?(block = `Head 0) ~src:({ pkh; sk } : Account.t) ~proposal ballot =
Block_services.hash !rpc_ctxt ~block () >>=? fun hash -> Block_services.hash !rpc_ctxt ~block () >>=? fun hash ->
Alpha_services.Helpers.next_level Alpha_services.Helpers.level
!rpc_ctxt (`Main, block) >>=? fun next_level -> !rpc_ctxt ~offset:1l (`Main, block) >>=? fun next_level ->
let shell = { Tezos_base.Operation.branch = hash } in let shell = { Tezos_base.Operation.branch = hash } in
let contents = let contents =
Amendment_operation Amendment_operation
@ -516,7 +516,7 @@ module Baking = struct
let bake block (contract: Account.t) operations = let bake block (contract: Account.t) operations =
let ctxt = (new wrap_full (no_write_context ~block !rpc_config)) in let ctxt = (new wrap_full (no_write_context ~block !rpc_config)) in
Alpha_services.Helpers.next_level ctxt (`Main, block) >>=? fun level -> Alpha_services.Helpers.level ctxt ~offset:1l (`Main, block) >>=? fun level ->
let seed_nonce_hash = let seed_nonce_hash =
if level.Level.expected_commitment then if level.Level.expected_commitment then
let seed_nonce = let seed_nonce =

View File

@ -40,19 +40,44 @@ module S = struct
let custom_root = RPC_path.(open_root / "helpers") let custom_root = RPC_path.(open_root / "helpers")
let next_level = type level_query = {
RPC_service.post_service offset: int32 ;
~description: "Detailled level information for the next block" }
~query: RPC_query.empty let level_query : level_query RPC_query.t =
~input: empty let open RPC_query in
query (fun offset -> { offset })
|+ field "offset" RPC_arg.int32 0l (fun t -> t.offset)
|> seal
let level =
RPC_service.get_service
~description: "..."
~query: level_query
~output: Level.encoding ~output: Level.encoding
RPC_path.(custom_root / "next_level") RPC_path.(custom_root / "level")
let levels =
RPC_service.get_service
~description: "Levels of a cycle"
~query: RPC_query.empty
~output: (obj2
(req "first" Raw_level.encoding)
(req "last" Raw_level.encoding))
RPC_path.(custom_root / "levels_in_cycle" /: Cycle.arg)
type minimal_timestamp_query = {
priority: int ;
}
let minimal_timestamp_query : minimal_timestamp_query RPC_query.t =
let open RPC_query in
query (fun priority -> { priority })
|+ field "priority" RPC_arg.int 0 (fun t -> t.priority)
|> seal
let minimal_timestamp = let minimal_timestamp =
RPC_service.post_service RPC_service.get_service
~description: "Minimal timestamp for the next block." ~description: "Minimal timestamp for the next block."
~query: RPC_query.empty ~query: minimal_timestamp_query
~input: (obj1 (opt "priority" int31))
~output: (obj1 (req "timestamp" Timestamp.encoding)) ~output: (obj1 (req "timestamp" Timestamp.encoding))
RPC_path.(custom_root / "minimal_timestamp") RPC_path.(custom_root / "minimal_timestamp")
@ -143,24 +168,6 @@ module S = struct
~query: RPC_query.empty ~query: RPC_query.empty
RPC_path.(custom_root / "hash_data") RPC_path.(custom_root / "hash_data")
let level =
RPC_service.post_service
~description: "..."
~query: RPC_query.empty
~input: (obj1 (opt "offset" int32))
~output: Level.encoding
RPC_path.(custom_root / "level" /: Raw_level.arg)
let levels =
RPC_service.post_service
~description: "Levels of a cycle"
~query: RPC_query.empty
~input: empty
~output: (obj2
(req "first" Raw_level.encoding)
(req "last" Raw_level.encoding))
RPC_path.(custom_root / "levels" /: Cycle.arg)
end end
module I = struct module I = struct
@ -181,13 +188,19 @@ end
let () = let () =
let open Services_registration in let open Services_registration in
register0 S.next_level begin fun ctxt () () -> register0 S.level begin fun ctxt q () ->
return (Level.succ ctxt (Level.current ctxt)) let level = Level.current ctxt in
return (Level.from_raw ctxt ~offset:q.offset level.level)
end ; end ;
register0 S.minimal_timestamp begin fun ctxt () slot -> register1 S.levels begin fun ctxt cycle () () ->
let levels = Level.levels_in_cycle ctxt cycle in
let first = List.hd (List.rev levels) in
let last = List.hd levels in
return (first.level, last.level)
end ;
register0 S.minimal_timestamp begin fun ctxt q () ->
let timestamp = Alpha_context.Timestamp.current ctxt in let timestamp = Alpha_context.Timestamp.current ctxt in
let slot = match slot with None -> 0 | Some p -> p in Baking.minimal_time ctxt q.priority timestamp
Baking.minimal_time ctxt slot timestamp
end ; end ;
register0 S.apply_operation I.apply_operation ; register0 S.apply_operation I.apply_operation ;
register0 S.run_code begin fun ctxt () register0 S.run_code begin fun ctxt ()
@ -243,22 +256,16 @@ let () =
parse_data ctxt typ (Micheline.root expr) >>=? fun (data, ctxt) -> parse_data ctxt typ (Micheline.root expr) >>=? fun (data, ctxt) ->
Script_ir_translator.hash_data ctxt typ data >>=? fun (hash, ctxt) -> Script_ir_translator.hash_data ctxt typ data >>=? fun (hash, ctxt) ->
return (hash, Gas.level ctxt) return (hash, Gas.level ctxt)
end ;
register1 S.level begin fun ctxt raw () offset ->
return (Level.from_raw ctxt ?offset raw)
end ;
register1 S.levels begin fun ctxt cycle () () ->
let levels = Level.levels_in_cycle ctxt cycle in
let first = List.hd (List.rev levels) in
let last = List.hd levels in
return (first.level, last.level)
end end
let next_level ctxt block = let level ctxt ?(offset = 0l) block =
RPC_context.make_call0 S.next_level ctxt block () () RPC_context.make_call0 S.level ctxt block { offset } ()
let minimal_time ctxt ?priority block = let levels ctxt block cycle =
RPC_context.make_call0 S.minimal_timestamp ctxt block () priority RPC_context.make_call1 S.levels ctxt block cycle () ()
let minimal_time ctxt ?(priority = 0) block =
RPC_context.make_call0 S.minimal_timestamp ctxt block { priority } ()
let run_code ctxt block code (storage, input, amount, contract) = let run_code ctxt block code (storage, input, amount, contract) =
RPC_context.make_call0 S.run_code ctxt RPC_context.make_call0 S.run_code ctxt
@ -281,12 +288,6 @@ let typecheck_data ctxt block =
let hash_data ctxt block = let hash_data ctxt block =
RPC_context.make_call0 S.hash_data ctxt block () RPC_context.make_call0 S.hash_data ctxt block ()
let level ctxt block ?offset lvl =
RPC_context.make_call1 S.level ctxt block lvl () offset
let levels ctxt block cycle =
RPC_context.make_call1 S.levels ctxt block cycle () ()
module Forge = struct module Forge = struct
module S = struct module S = struct

View File

@ -13,10 +13,13 @@ type error +=
| Cannot_parse_operation (* `Branch *) | Cannot_parse_operation (* `Branch *)
| Cant_parse_block_header | Cant_parse_block_header
val next_level: val level:
'a #RPC_context.simple -> 'a -> Level.t shell_tzresult Lwt.t 'a #RPC_context.simple ->
(** [next_level cctxt blk] returns the (protocol view of the) level ?offset:int32 -> 'a -> Level.t shell_tzresult Lwt.t
of the successor of [blk]. *)
val levels:
'a #RPC_context.simple ->
'a -> Cycle.t -> (Raw_level.t * Raw_level.t) shell_tzresult Lwt.t
val minimal_time: val minimal_time:
'a #RPC_context.simple -> 'a #RPC_context.simple ->
@ -60,15 +63,6 @@ val hash_data:
'a #RPC_context.simple -> 'a #RPC_context.simple ->
'a -> Script.expr * Script.expr * Z.t option -> (string * Gas.t) shell_tzresult Lwt.t 'a -> Script.expr * Script.expr * Z.t option -> (string * Gas.t) shell_tzresult Lwt.t
val level:
'a #RPC_context.simple ->
'a -> ?offset:int32 -> Raw_level.t -> Level.t shell_tzresult Lwt.t
val levels:
'a #RPC_context.simple ->
'a -> Cycle.t -> (Raw_level.t * Raw_level.t) shell_tzresult Lwt.t
module Forge : sig module Forge : sig
module Manager : sig module Manager : sig

View File

@ -149,7 +149,7 @@ module Forge = struct
| Error _ -> assert false | Error _ -> assert false
end >>=? fun fitness -> end >>=? fun fitness ->
begin begin
Alpha_services.Helpers.next_level (rpc_ctxt) pred >>|? function Alpha_services.Helpers.level ~offset:1l (rpc_ctxt) pred >>|? function
| { expected_commitment = true } -> Some (fst (Proto_Nonce.generate ())) | { expected_commitment = true } -> Some (fst (Proto_Nonce.generate ()))
| { expected_commitment = false } -> None | { expected_commitment = false } -> None
end >>=? fun seed_nonce_hash -> end >>=? fun seed_nonce_hash ->