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)
end
| `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
?max_priority
~levels:[level]
@ -392,7 +393,7 @@ let compute_timeout { future_slots } =
let get_unrevealed_nonces
(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
match Cycle.pred cur_cycle with
| None -> return []
@ -491,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.Helpers.next_level cctxt (chain, block) >>=? fun next_level ->
Alpha_services.Helpers.level cctxt ~offset:1l (chain, block) >>=? fun next_level ->
let timestamp =
if Block_hash.equal bi.Client_baking_blocks.hash state.genesis then
Time.now ()

View File

@ -21,7 +21,7 @@ let bake_block (cctxt : #Proto_alpha.full)
return src_sk
| Some sk -> return 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 =
if level.expected_commitment then
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 =
Block_services.hash !rpc_ctxt ~block () >>=? fun hash ->
Alpha_services.Helpers.next_level
!rpc_ctxt (`Main, block) >>=? fun next_level ->
Alpha_services.Helpers.level
!rpc_ctxt ~offset:1l (`Main, block) >>=? fun next_level ->
let shell = { Tezos_base.Operation.branch = hash } in
let contents =
Amendment_operation
@ -354,8 +354,8 @@ 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.Helpers.next_level
!rpc_ctxt (`Main, block) >>=? fun next_level ->
Alpha_services.Helpers.level
!rpc_ctxt ~offset:1l (`Main, block) >>=? fun next_level ->
let shell = { Tezos_base.Operation.branch = hash } in
let contents =
Amendment_operation
@ -516,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.Helpers.next_level ctxt (`Main, block) >>=? fun level ->
Alpha_services.Helpers.level ctxt ~offset:1l (`Main, block) >>=? fun level ->
let seed_nonce_hash =
if level.Level.expected_commitment then
let seed_nonce =

View File

@ -40,19 +40,44 @@ 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
type level_query = {
offset: int32 ;
}
let level_query : level_query RPC_query.t =
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
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 =
RPC_service.post_service
RPC_service.get_service
~description: "Minimal timestamp for the next block."
~query: RPC_query.empty
~input: (obj1 (opt "priority" int31))
~query: minimal_timestamp_query
~output: (obj1 (req "timestamp" Timestamp.encoding))
RPC_path.(custom_root / "minimal_timestamp")
@ -143,24 +168,6 @@ module S = struct
~query: RPC_query.empty
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
module I = struct
@ -181,13 +188,19 @@ end
let () =
let open Services_registration in
register0 S.next_level begin fun ctxt () () ->
return (Level.succ ctxt (Level.current ctxt))
register0 S.level begin fun ctxt q () ->
let level = Level.current ctxt in
return (Level.from_raw ctxt ~offset:q.offset level.level)
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 slot = match slot with None -> 0 | Some p -> p in
Baking.minimal_time ctxt slot timestamp
Baking.minimal_time ctxt q.priority timestamp
end ;
register0 S.apply_operation I.apply_operation ;
register0 S.run_code begin fun ctxt ()
@ -243,22 +256,16 @@ let () =
parse_data ctxt typ (Micheline.root expr) >>=? fun (data, ctxt) ->
Script_ir_translator.hash_data ctxt typ data >>=? fun (hash, 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
let next_level ctxt block =
RPC_context.make_call0 S.next_level ctxt block () ()
let level ctxt ?(offset = 0l) block =
RPC_context.make_call0 S.level ctxt block { offset } ()
let minimal_time ctxt ?priority block =
RPC_context.make_call0 S.minimal_timestamp ctxt block () priority
let levels ctxt block cycle =
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) =
RPC_context.make_call0 S.run_code ctxt
@ -281,12 +288,6 @@ let typecheck_data ctxt block =
let 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 S = struct

View File

@ -13,10 +13,13 @@ 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 level:
'a #RPC_context.simple ->
?offset:int32 -> 'a -> 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
val minimal_time:
'a #RPC_context.simple ->
@ -60,15 +63,6 @@ val hash_data:
'a #RPC_context.simple ->
'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 Manager : sig

View File

@ -149,7 +149,7 @@ module Forge = struct
| Error _ -> assert false
end >>=? fun fitness ->
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 = false } -> None
end >>=? fun seed_nonce_hash ->