Shell/RPC: add raw block header in monitoring RPCs

This commit is contained in:
Grégoire Henry 2018-06-06 15:15:44 +02:00
parent 5aa65ee71f
commit ca1d4158a7
5 changed files with 35 additions and 20 deletions

View File

@ -25,7 +25,7 @@ let wait_for_operation_inclusion
(* Fetch _all_ the 'unknown' predecessors af a block. *)
let fetch_predecessors block =
let fetch_predecessors (block, _) =
let rec loop acc block =
Block_services.Empty.Header.shell_header
ctxt ~chain ~block:(`Hash (block, 0)) () >>=? fun { predecessor } ->
@ -93,7 +93,7 @@ let wait_for_operation_inclusion
Shell_services.Monitor.heads ctxt chain >>=? fun (stream, stop) ->
Lwt_stream.get stream >>= function
| None -> assert false
| Some head ->
| Some (head, _) ->
let rec loop n =
if n >= 0 then
process (`Hash (head, n)) >>=? function

View File

@ -76,7 +76,8 @@ let build_rpc_directory validator mainchain_validator =
in_protocols block >>= fun in_protocols ->
if in_chains && in_protocols && in_next_protocols then
Lwt.return_some
(State.Block.chain_id block, State.Block.hash block)
((State.Block.chain_id block, State.Block.hash block),
State.Block.header block)
else
Lwt.return_none)
block_stream in
@ -104,14 +105,14 @@ let build_rpc_directory validator mainchain_validator =
(fun block ->
in_next_protocols block >>= fun in_next_protocols ->
if in_next_protocols then
Lwt.return_some (State.Block.hash block)
Lwt.return_some (State.Block.hash block, State.Block.header block)
else
Lwt.return_none)
block_stream in
let first_call = ref true in
let next () =
if !first_call then begin
first_call := false ; Lwt.return_some (State.Block.hash head)
first_call := false ; Lwt.return_some (State.Block.hash head, State.Block.header head)
end else
Lwt_stream.get stream in
RPC_answer.return_stream { next ; shutdown }

View File

@ -48,9 +48,11 @@ module S = struct
by the node, disregarding whether they were \
selected as the new head or not."
~query: valid_blocks_query
~output: (obj2
~output: (merge_objs
(obj2
(req "chain_id" Chain_id.encoding)
(req "hash" Block_hash.encoding))
Block_header.encoding)
RPC_path.(path / "valid_blocks")
let heads_query =
@ -68,7 +70,10 @@ module S = struct
by the node and selected as the new head of the \
given chain."
~query: heads_query
~output: Block_hash.encoding
~output: (merge_objs
(obj1
(req "hash" Block_hash.encoding))
Block_header.encoding)
RPC_path.(path / "heads" /: Chain_services.chain_arg)
let protocols =

View File

@ -17,13 +17,13 @@ val valid_blocks:
?chains:Chain_services.chain list ->
?protocols:Protocol_hash.t list ->
?next_protocols:Protocol_hash.t list ->
unit -> ((Chain_id.t * Block_hash.t) Lwt_stream.t * stopper) tzresult Lwt.t
unit -> (((Chain_id.t * Block_hash.t) * Block_header.t) Lwt_stream.t * stopper) tzresult Lwt.t
val heads:
#streamed ->
?next_protocols:Protocol_hash.t list ->
Chain_services.chain ->
(Block_hash.t Lwt_stream.t * stopper) tzresult Lwt.t
((Block_hash.t * Block_header.t) Lwt_stream.t * stopper) tzresult Lwt.t
val protocols:
#streamed ->
@ -41,13 +41,13 @@ module S : sig
unit, < chains : Chain_services.chain list;
next_protocols : Protocol_hash.t list;
protocols : Protocol_hash.t list >, unit,
Chain_id.t * Block_hash.t) RPC_service.t
(Chain_id.t * Block_hash.t) * Block_header.t) RPC_service.t
val heads:
([ `GET ], unit,
unit * Chain_services.chain,
< next_protocols : Protocol_hash.t list >, unit,
Block_hash.t) RPC_service.t
Block_hash.t * Block_header.t) RPC_service.t
val protocols:
([ `GET ], unit,

View File

@ -21,31 +21,40 @@ type block_info = {
level: Level.t ;
}
let info cctxt ?(chain = `Main) block =
let raw_info cctxt ?(chain = `Main) hash header =
let block = `Hash (hash, 0) in
Shell_services.Chain.chain_id cctxt ~chain () >>=? fun chain_id ->
Shell_services.Blocks.hash cctxt ~chain ~block () >>=? fun hash ->
Shell_services.Blocks.Header.shell_header cctxt ~chain ~block () >>=? fun header ->
Shell_services.Blocks.protocols
cctxt ~chain ~block () >>=? fun { current_protocol = protocol ;
next_protocol } ->
Alpha_block_services.metadata cctxt
~chain ~block () >>=? fun { protocol_data = { level } } ->
let { Tezos_base.Block_header.predecessor ; fitness ; timestamp ; _ } = header in
let { Tezos_base.Block_header.predecessor ; fitness ; timestamp ; _ } =
header.Tezos_base.Block_header.shell in
return { hash ; chain_id ; predecessor ; fitness ;
timestamp ; protocol ; next_protocol ; level }
let info cctxt ?(chain = `Main) block =
Shell_services.Blocks.hash cctxt ~chain ~block () >>=? fun hash ->
Shell_services.Blocks.Header.shell_header
cctxt ~chain ~block () >>=? fun shell ->
Shell_services.Blocks.Header.raw_protocol_data
cctxt ~chain ~block () >>=? fun protocol_data ->
raw_info cctxt ~chain hash { shell ; protocol_data }
let monitor_valid_blocks cctxt ?chains ?protocols ?next_protocols () =
Shell_services.Monitor.valid_blocks cctxt
?chains ?protocols ?next_protocols () >>=? fun (block_stream, _stop) ->
return (Lwt_stream.map_s
(fun (chain, block) ->
info cctxt ~chain:(`Hash chain) (`Hash (block, 0))) block_stream)
(fun ((chain, block), header) ->
raw_info cctxt ~chain:(`Hash chain) block header)
block_stream)
let monitor_heads cctxt ?next_protocols chain =
Monitor_services.heads
cctxt ?next_protocols chain >>=? fun (block_stream, _stop) ->
return (Lwt_stream.map_s
(fun block -> info cctxt ~chain (`Hash (block, 0)))
(fun (block, header) -> raw_info cctxt ~chain block header)
block_stream)
let blocks_from_current_cycle cctxt ?(chain = `Main) block ?(offset = 0l) () =