Alpha/RPC: rename levels_in_cycle
into levels_in_current_cycle
This commit is contained in:
parent
7e8f4341d7
commit
3783e43a2e
@ -48,10 +48,12 @@ let monitor_heads cctxt ?next_protocols chain =
|
|||||||
(fun block -> info cctxt ~chain (`Hash (block, 0)))
|
(fun block -> info cctxt ~chain (`Hash (block, 0)))
|
||||||
block_stream)
|
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 ->
|
Shell_services.Blocks.hash cctxt ~chain ~block () >>=? fun hash ->
|
||||||
Alpha_block_services.Metadata.protocol_data cctxt ~chain ~block () >>=? fun { level } ->
|
Alpha_block_services.Metadata.protocol_data
|
||||||
Alpha_services.Helpers.levels cctxt (chain, block) cycle >>=? fun (first, last) ->
|
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
|
let length = Int32.to_int (Raw_level.diff level.level first) in
|
||||||
Shell_services.Blocks.list cctxt ~heads:[hash] ~length () >>=? fun blocks ->
|
Shell_services.Blocks.list cctxt ~heads:[hash] ~length () >>=? fun blocks ->
|
||||||
let blocks =
|
let blocks =
|
||||||
|
@ -40,9 +40,10 @@ val monitor_heads:
|
|||||||
Chain_services.chain ->
|
Chain_services.chain ->
|
||||||
block_info tzresult Lwt_stream.t tzresult Lwt.t
|
block_info tzresult Lwt_stream.t tzresult Lwt.t
|
||||||
|
|
||||||
val blocks_from_cycle:
|
val blocks_from_current_cycle:
|
||||||
#Proto_alpha.rpc_context ->
|
#Proto_alpha.rpc_context ->
|
||||||
?chain:Chain_services.chain ->
|
?chain:Chain_services.chain ->
|
||||||
Block_services.block ->
|
Block_services.block ->
|
||||||
Cycle.t ->
|
?offset:int32 ->
|
||||||
|
unit ->
|
||||||
Block_hash.t list tzresult Lwt.t
|
Block_hash.t list tzresult Lwt.t
|
||||||
|
@ -159,7 +159,7 @@ let forge_block cctxt ?(chain = `Main) block
|
|||||||
return (priority, time)
|
return (priority, time)
|
||||||
end
|
end
|
||||||
| `Auto (src_pkh, max_priority, free_baking) ->
|
| `Auto (src_pkh, max_priority, free_baking) ->
|
||||||
Alpha_services.Helpers.level
|
Alpha_services.Helpers.current_level
|
||||||
cctxt ~offset:1l (chain, block)>>=? fun { 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
|
||||||
@ -396,37 +396,32 @@ 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.level cctxt ~offset:1l (chain, block) >>=? fun level ->
|
Client_baking_blocks.blocks_from_current_cycle
|
||||||
let cur_cycle = level.cycle in
|
cctxt block ~offset:(-1l) () >>=? fun blocks ->
|
||||||
match Cycle.pred cur_cycle with
|
filter_map_s (fun hash ->
|
||||||
| None -> return []
|
Client_baking_nonces.find cctxt hash >>=? function
|
||||||
| Some cycle ->
|
| None -> return None
|
||||||
Client_baking_blocks.blocks_from_cycle
|
| Some nonce ->
|
||||||
cctxt block cycle >>=? fun blocks ->
|
Alpha_block_services.Metadata.protocol_data
|
||||||
filter_map_s (fun hash ->
|
cctxt ~chain ~block:(`Hash (hash, 0)) () >>=? fun { level } ->
|
||||||
Client_baking_nonces.find cctxt hash >>=? function
|
if force then
|
||||||
| None -> return None
|
return (Some (hash, (level.level, nonce)))
|
||||||
| Some nonce ->
|
else
|
||||||
Alpha_block_services.Metadata.protocol_data
|
Alpha_services.Nonce.get
|
||||||
cctxt ~chain ~block:(`Hash (hash, 0)) () >>=? fun { level } ->
|
cctxt (chain, block) level.level >>=? function
|
||||||
if force then
|
| 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)))
|
return (Some (hash, (level.level, nonce)))
|
||||||
else
|
| Missing _nonce_hash ->
|
||||||
Alpha_services.Nonce.get
|
cctxt#error "Incoherent nonce for level %a"
|
||||||
cctxt (chain, block) level.level >>=? function
|
Raw_level.pp level.level >>= fun () ->
|
||||||
| Missing nonce_hash
|
return None
|
||||||
when Nonce.check_hash nonce nonce_hash ->
|
| Forgotten -> return None
|
||||||
cctxt#warning "Found nonce for %a (level: %a)@."
|
| Revealed _ -> return None)
|
||||||
Block_hash.pp_short hash
|
blocks
|
||||||
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
|
|
||||||
|
|
||||||
let safe_get_unrevealed_nonces cctxt block =
|
let safe_get_unrevealed_nonces cctxt block =
|
||||||
get_unrevealed_nonces cctxt block >>= function
|
get_unrevealed_nonces cctxt block >>= function
|
||||||
@ -495,7 +490,8 @@ 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.level cctxt ~offset:1l (chain, block) >>=? fun next_level ->
|
Alpha_services.Helpers.current_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 ()
|
||||||
|
@ -21,7 +21,8 @@ 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.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 =
|
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
|
||||||
|
@ -343,7 +343,7 @@ 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 =
|
||||||
Shell_services.Blocks.hash !rpc_ctxt ~block () >>=? fun hash ->
|
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 ->
|
!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 =
|
||||||
@ -355,7 +355,7 @@ 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 =
|
||||||
Shell_services.Blocks.hash !rpc_ctxt ~block () >>=? fun hash ->
|
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 ->
|
!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 =
|
||||||
@ -517,7 +517,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.level
|
Alpha_services.Helpers.current_level
|
||||||
ctxt ~offset:1l (`Main, block) >>=? fun 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
|
||||||
|
@ -504,14 +504,14 @@ module S = struct
|
|||||||
|+ field "offset" RPC_arg.int32 0l (fun t -> t.offset)
|
|+ field "offset" RPC_arg.int32 0l (fun t -> t.offset)
|
||||||
|> seal
|
|> seal
|
||||||
|
|
||||||
let level =
|
let current_level =
|
||||||
RPC_service.get_service
|
RPC_service.get_service
|
||||||
~description: "..."
|
~description: "..."
|
||||||
~query: level_query
|
~query: level_query
|
||||||
~output: Level.encoding
|
~output: Level.encoding
|
||||||
RPC_path.(path / "level")
|
RPC_path.(path / "current_level")
|
||||||
|
|
||||||
let levels =
|
let levels_in_current_cycle =
|
||||||
RPC_service.get_service
|
RPC_service.get_service
|
||||||
~description: "Levels of a cycle"
|
~description: "Levels of a cycle"
|
||||||
~query: level_query
|
~query: level_query
|
||||||
@ -524,19 +524,19 @@ end
|
|||||||
|
|
||||||
let () =
|
let () =
|
||||||
let open Services_registration in
|
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
|
let level = Level.current ctxt in
|
||||||
return (Level.from_raw ctxt ~offset:q.offset level.level)
|
return (Level.from_raw ctxt ~offset:q.offset level.level)
|
||||||
end ;
|
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 levels = Level.levels_in_current_cycle ctxt ~offset:q.offset () in
|
||||||
let first = List.hd (List.rev levels) in
|
let first = List.hd (List.rev levels) in
|
||||||
let last = List.hd levels in
|
let last = List.hd levels in
|
||||||
return (first.level, last.level)
|
return (first.level, last.level)
|
||||||
end
|
end
|
||||||
|
|
||||||
let level ctxt ?(offset = 0l) block =
|
let current_level ctxt ?(offset = 0l) block =
|
||||||
RPC_context.make_call0 S.level ctxt block { offset } ()
|
RPC_context.make_call0 S.current_level ctxt block { offset } ()
|
||||||
|
|
||||||
let levels ctxt block cycle =
|
let levels_in_current_cycle ctxt ?(offset = 0l) block =
|
||||||
RPC_context.make_call1 S.levels ctxt block cycle () ()
|
RPC_context.make_call0 S.levels_in_current_cycle ctxt block { offset } ()
|
||||||
|
@ -13,13 +13,13 @@ type error +=
|
|||||||
| Cannot_parse_operation (* `Branch *)
|
| Cannot_parse_operation (* `Branch *)
|
||||||
| Cant_parse_block_header
|
| Cant_parse_block_header
|
||||||
|
|
||||||
val level:
|
val current_level:
|
||||||
'a #RPC_context.simple ->
|
'a #RPC_context.simple ->
|
||||||
?offset:int32 -> 'a -> Level.t shell_tzresult Lwt.t
|
?offset:int32 -> 'a -> Level.t shell_tzresult Lwt.t
|
||||||
|
|
||||||
val levels:
|
val levels_in_current_cycle:
|
||||||
'a #RPC_context.simple ->
|
'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
|
module Scripts : sig
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ module Forge = struct
|
|||||||
| Error _ -> assert false
|
| Error _ -> assert false
|
||||||
end >>=? fun fitness ->
|
end >>=? fun fitness ->
|
||||||
begin
|
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 = true } -> Some (fst (Proto_Nonce.generate ()))
|
||||||
| { expected_commitment = false } -> None
|
| { expected_commitment = false } -> None
|
||||||
end >>=? fun seed_nonce_hash ->
|
end >>=? fun seed_nonce_hash ->
|
||||||
|
Loading…
Reference in New Issue
Block a user