Alpha/RPC: rename levels_in_cycle into levels_in_current_cycle

This commit is contained in:
Grégoire Henry 2018-04-21 16:15:52 +02:00 committed by Benjamin Canou
parent 7e8f4341d7
commit 3783e43a2e
8 changed files with 54 additions and 54 deletions

View File

@ -48,10 +48,12 @@ let monitor_heads cctxt ?next_protocols chain =
(fun block -> info cctxt ~chain (`Hash (block, 0)))
block_stream)
let blocks_from_cycle cctxt ?(chain = `Main) block cycle =
let blocks_from_current_cycle cctxt ?(chain = `Main) block ?(offset = 0l) () =
Shell_services.Blocks.hash cctxt ~chain ~block () >>=? fun hash ->
Alpha_block_services.Metadata.protocol_data cctxt ~chain ~block () >>=? fun { level } ->
Alpha_services.Helpers.levels cctxt (chain, block) cycle >>=? fun (first, last) ->
Alpha_block_services.Metadata.protocol_data
cctxt ~chain ~block () >>=? fun { level } ->
Alpha_services.Helpers.levels_in_current_cycle
cctxt ~offset (chain, block) >>=? fun (first, last) ->
let length = Int32.to_int (Raw_level.diff level.level first) in
Shell_services.Blocks.list cctxt ~heads:[hash] ~length () >>=? fun blocks ->
let blocks =

View File

@ -40,9 +40,10 @@ val monitor_heads:
Chain_services.chain ->
block_info tzresult Lwt_stream.t tzresult Lwt.t
val blocks_from_cycle:
val blocks_from_current_cycle:
#Proto_alpha.rpc_context ->
?chain:Chain_services.chain ->
Block_services.block ->
Cycle.t ->
?offset:int32 ->
unit ->
Block_hash.t list tzresult Lwt.t

View File

@ -159,7 +159,7 @@ let forge_block cctxt ?(chain = `Main) block
return (priority, time)
end
| `Auto (src_pkh, max_priority, free_baking) ->
Alpha_services.Helpers.level
Alpha_services.Helpers.current_level
cctxt ~offset:1l (chain, block)>>=? fun { level } ->
Alpha_services.Delegate.Baking_rights.get cctxt
?max_priority
@ -396,37 +396,32 @@ let compute_timeout { future_slots } =
let get_unrevealed_nonces
(cctxt : #Proto_alpha.full) ?(force = false) ?(chain = `Main) block =
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 []
| Some cycle ->
Client_baking_blocks.blocks_from_cycle
cctxt block cycle >>=? fun blocks ->
filter_map_s (fun hash ->
Client_baking_nonces.find cctxt hash >>=? function
| None -> return None
| Some nonce ->
Alpha_block_services.Metadata.protocol_data
cctxt ~chain ~block:(`Hash (hash, 0)) () >>=? fun { level } ->
if force then
Client_baking_blocks.blocks_from_current_cycle
cctxt block ~offset:(-1l) () >>=? fun blocks ->
filter_map_s (fun hash ->
Client_baking_nonces.find cctxt hash >>=? function
| None -> return None
| Some nonce ->
Alpha_block_services.Metadata.protocol_data
cctxt ~chain ~block:(`Hash (hash, 0)) () >>=? fun { level } ->
if force then
return (Some (hash, (level.level, nonce)))
else
Alpha_services.Nonce.get
cctxt (chain, block) level.level >>=? function
| Missing nonce_hash
when Nonce.check_hash nonce nonce_hash ->
cctxt#warning "Found nonce for %a (level: %a)@."
Block_hash.pp_short hash
Level.pp level >>= fun () ->
return (Some (hash, (level.level, nonce)))
else
Alpha_services.Nonce.get
cctxt (chain, block) level.level >>=? function
| Missing nonce_hash
when Nonce.check_hash nonce nonce_hash ->
cctxt#warning "Found nonce for %a (level: %a)@."
Block_hash.pp_short hash
Level.pp level >>= fun () ->
return (Some (hash, (level.level, nonce)))
| Missing _nonce_hash ->
cctxt#error "Incoherent nonce for level %a"
Raw_level.pp level.level >>= fun () ->
return None
| Forgotten -> return None
| Revealed _ -> return None)
blocks
| Missing _nonce_hash ->
cctxt#error "Incoherent nonce for level %a"
Raw_level.pp level.level >>= fun () ->
return None
| Forgotten -> return None
| Revealed _ -> return None)
blocks
let safe_get_unrevealed_nonces cctxt block =
get_unrevealed_nonces cctxt block >>= function
@ -495,7 +490,8 @@ 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.level cctxt ~offset:1l (chain, block) >>=? fun next_level ->
Alpha_services.Helpers.current_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,8 @@ let bake_block (cctxt : #Proto_alpha.full)
return src_sk
| Some sk -> return sk
end >>=? fun src_sk ->
Alpha_services.Helpers.level cctxt ~offset:1l (chain, block) >>=? fun level ->
Alpha_services.Helpers.current_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

@ -343,7 +343,7 @@ module Protocol = struct
let proposals ?(block = `Head 0) ~src:({ pkh; sk } : Account.t) proposals =
Shell_services.Blocks.hash !rpc_ctxt ~block () >>=? fun hash ->
Alpha_services.Helpers.level
Alpha_services.Helpers.current_level
!rpc_ctxt ~offset:1l (`Main, block) >>=? fun next_level ->
let shell = { Tezos_base.Operation.branch = hash } in
let contents =
@ -355,7 +355,7 @@ module Protocol = struct
let ballot ?(block = `Head 0) ~src:({ pkh; sk } : Account.t) ~proposal ballot =
Shell_services.Blocks.hash !rpc_ctxt ~block () >>=? fun hash ->
Alpha_services.Helpers.level
Alpha_services.Helpers.current_level
!rpc_ctxt ~offset:1l (`Main, block) >>=? fun next_level ->
let shell = { Tezos_base.Operation.branch = hash } in
let contents =
@ -517,7 +517,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.level
Alpha_services.Helpers.current_level
ctxt ~offset:1l (`Main, block) >>=? fun level ->
let seed_nonce_hash =
if level.Level.expected_commitment then

View File

@ -504,14 +504,14 @@ module S = struct
|+ field "offset" RPC_arg.int32 0l (fun t -> t.offset)
|> seal
let level =
let current_level =
RPC_service.get_service
~description: "..."
~query: level_query
~output: Level.encoding
RPC_path.(path / "level")
RPC_path.(path / "current_level")
let levels =
let levels_in_current_cycle =
RPC_service.get_service
~description: "Levels of a cycle"
~query: level_query
@ -524,19 +524,19 @@ end
let () =
let open Services_registration in
register0 S.level begin fun ctxt q () ->
register0 S.current_level begin fun ctxt q () ->
let level = Level.current ctxt in
return (Level.from_raw ctxt ~offset:q.offset level.level)
end ;
register0 S.levels begin fun ctxt q () ->
register0 S.levels_in_current_cycle begin fun ctxt q () ->
let levels = Level.levels_in_current_cycle ctxt ~offset:q.offset () in
let first = List.hd (List.rev levels) in
let last = List.hd levels in
return (first.level, last.level)
end
let level ctxt ?(offset = 0l) block =
RPC_context.make_call0 S.level ctxt block { offset } ()
let current_level ctxt ?(offset = 0l) block =
RPC_context.make_call0 S.current_level ctxt block { offset } ()
let levels ctxt block cycle =
RPC_context.make_call1 S.levels ctxt block cycle () ()
let levels_in_current_cycle ctxt ?(offset = 0l) block =
RPC_context.make_call0 S.levels_in_current_cycle ctxt block { offset } ()

View File

@ -13,13 +13,13 @@ type error +=
| Cannot_parse_operation (* `Branch *)
| Cant_parse_block_header
val level:
val current_level:
'a #RPC_context.simple ->
?offset:int32 -> 'a -> Level.t shell_tzresult Lwt.t
val levels:
val levels_in_current_cycle:
'a #RPC_context.simple ->
'a -> Cycle.t -> (Raw_level.t * Raw_level.t) shell_tzresult Lwt.t
?offset:int32 -> 'a -> (Raw_level.t * Raw_level.t) shell_tzresult Lwt.t
module Scripts : sig

View File

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