Shell/RPC: add raw block header in monitoring RPCs
This commit is contained in:
parent
5aa65ee71f
commit
ca1d4158a7
@ -25,7 +25,7 @@ let wait_for_operation_inclusion
|
|||||||
|
|
||||||
(* Fetch _all_ the 'unknown' predecessors af a block. *)
|
(* Fetch _all_ the 'unknown' predecessors af a block. *)
|
||||||
|
|
||||||
let fetch_predecessors block =
|
let fetch_predecessors (block, _) =
|
||||||
let rec loop acc block =
|
let rec loop acc block =
|
||||||
Block_services.Empty.Header.shell_header
|
Block_services.Empty.Header.shell_header
|
||||||
ctxt ~chain ~block:(`Hash (block, 0)) () >>=? fun { predecessor } ->
|
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) ->
|
Shell_services.Monitor.heads ctxt chain >>=? fun (stream, stop) ->
|
||||||
Lwt_stream.get stream >>= function
|
Lwt_stream.get stream >>= function
|
||||||
| None -> assert false
|
| None -> assert false
|
||||||
| Some head ->
|
| Some (head, _) ->
|
||||||
let rec loop n =
|
let rec loop n =
|
||||||
if n >= 0 then
|
if n >= 0 then
|
||||||
process (`Hash (head, n)) >>=? function
|
process (`Hash (head, n)) >>=? function
|
||||||
|
@ -76,7 +76,8 @@ let build_rpc_directory validator mainchain_validator =
|
|||||||
in_protocols block >>= fun in_protocols ->
|
in_protocols block >>= fun in_protocols ->
|
||||||
if in_chains && in_protocols && in_next_protocols then
|
if in_chains && in_protocols && in_next_protocols then
|
||||||
Lwt.return_some
|
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
|
else
|
||||||
Lwt.return_none)
|
Lwt.return_none)
|
||||||
block_stream in
|
block_stream in
|
||||||
@ -104,14 +105,14 @@ let build_rpc_directory validator mainchain_validator =
|
|||||||
(fun block ->
|
(fun block ->
|
||||||
in_next_protocols block >>= fun in_next_protocols ->
|
in_next_protocols block >>= fun in_next_protocols ->
|
||||||
if in_next_protocols then
|
if in_next_protocols then
|
||||||
Lwt.return_some (State.Block.hash block)
|
Lwt.return_some (State.Block.hash block, State.Block.header block)
|
||||||
else
|
else
|
||||||
Lwt.return_none)
|
Lwt.return_none)
|
||||||
block_stream in
|
block_stream in
|
||||||
let first_call = ref true in
|
let first_call = ref true in
|
||||||
let next () =
|
let next () =
|
||||||
if !first_call then begin
|
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
|
end else
|
||||||
Lwt_stream.get stream in
|
Lwt_stream.get stream in
|
||||||
RPC_answer.return_stream { next ; shutdown }
|
RPC_answer.return_stream { next ; shutdown }
|
||||||
|
@ -48,9 +48,11 @@ module S = struct
|
|||||||
by the node, disregarding whether they were \
|
by the node, disregarding whether they were \
|
||||||
selected as the new head or not."
|
selected as the new head or not."
|
||||||
~query: valid_blocks_query
|
~query: valid_blocks_query
|
||||||
~output: (obj2
|
~output: (merge_objs
|
||||||
|
(obj2
|
||||||
(req "chain_id" Chain_id.encoding)
|
(req "chain_id" Chain_id.encoding)
|
||||||
(req "hash" Block_hash.encoding))
|
(req "hash" Block_hash.encoding))
|
||||||
|
Block_header.encoding)
|
||||||
RPC_path.(path / "valid_blocks")
|
RPC_path.(path / "valid_blocks")
|
||||||
|
|
||||||
let heads_query =
|
let heads_query =
|
||||||
@ -68,7 +70,10 @@ module S = struct
|
|||||||
by the node and selected as the new head of the \
|
by the node and selected as the new head of the \
|
||||||
given chain."
|
given chain."
|
||||||
~query: heads_query
|
~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)
|
RPC_path.(path / "heads" /: Chain_services.chain_arg)
|
||||||
|
|
||||||
let protocols =
|
let protocols =
|
||||||
|
@ -17,13 +17,13 @@ val valid_blocks:
|
|||||||
?chains:Chain_services.chain list ->
|
?chains:Chain_services.chain list ->
|
||||||
?protocols:Protocol_hash.t list ->
|
?protocols:Protocol_hash.t list ->
|
||||||
?next_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:
|
val heads:
|
||||||
#streamed ->
|
#streamed ->
|
||||||
?next_protocols:Protocol_hash.t list ->
|
?next_protocols:Protocol_hash.t list ->
|
||||||
Chain_services.chain ->
|
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:
|
val protocols:
|
||||||
#streamed ->
|
#streamed ->
|
||||||
@ -41,13 +41,13 @@ module S : sig
|
|||||||
unit, < chains : Chain_services.chain list;
|
unit, < chains : Chain_services.chain list;
|
||||||
next_protocols : Protocol_hash.t list;
|
next_protocols : Protocol_hash.t list;
|
||||||
protocols : Protocol_hash.t list >, unit,
|
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:
|
val heads:
|
||||||
([ `GET ], unit,
|
([ `GET ], unit,
|
||||||
unit * Chain_services.chain,
|
unit * Chain_services.chain,
|
||||||
< next_protocols : Protocol_hash.t list >, unit,
|
< next_protocols : Protocol_hash.t list >, unit,
|
||||||
Block_hash.t) RPC_service.t
|
Block_hash.t * Block_header.t) RPC_service.t
|
||||||
|
|
||||||
val protocols:
|
val protocols:
|
||||||
([ `GET ], unit,
|
([ `GET ], unit,
|
||||||
|
@ -21,31 +21,40 @@ type block_info = {
|
|||||||
level: Level.t ;
|
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.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
|
Shell_services.Blocks.protocols
|
||||||
cctxt ~chain ~block () >>=? fun { current_protocol = protocol ;
|
cctxt ~chain ~block () >>=? fun { current_protocol = protocol ;
|
||||||
next_protocol } ->
|
next_protocol } ->
|
||||||
Alpha_block_services.metadata cctxt
|
Alpha_block_services.metadata cctxt
|
||||||
~chain ~block () >>=? fun { protocol_data = { level } } ->
|
~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 ;
|
return { hash ; chain_id ; predecessor ; fitness ;
|
||||||
timestamp ; protocol ; next_protocol ; level }
|
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 () =
|
let monitor_valid_blocks cctxt ?chains ?protocols ?next_protocols () =
|
||||||
Shell_services.Monitor.valid_blocks cctxt
|
Shell_services.Monitor.valid_blocks cctxt
|
||||||
?chains ?protocols ?next_protocols () >>=? fun (block_stream, _stop) ->
|
?chains ?protocols ?next_protocols () >>=? fun (block_stream, _stop) ->
|
||||||
return (Lwt_stream.map_s
|
return (Lwt_stream.map_s
|
||||||
(fun (chain, block) ->
|
(fun ((chain, block), header) ->
|
||||||
info cctxt ~chain:(`Hash chain) (`Hash (block, 0))) block_stream)
|
raw_info cctxt ~chain:(`Hash chain) block header)
|
||||||
|
block_stream)
|
||||||
|
|
||||||
let monitor_heads cctxt ?next_protocols chain =
|
let monitor_heads cctxt ?next_protocols chain =
|
||||||
Monitor_services.heads
|
Monitor_services.heads
|
||||||
cctxt ?next_protocols chain >>=? fun (block_stream, _stop) ->
|
cctxt ?next_protocols chain >>=? fun (block_stream, _stop) ->
|
||||||
return (Lwt_stream.map_s
|
return (Lwt_stream.map_s
|
||||||
(fun block -> info cctxt ~chain (`Hash (block, 0)))
|
(fun (block, header) -> raw_info cctxt ~chain block header)
|
||||||
block_stream)
|
block_stream)
|
||||||
|
|
||||||
let blocks_from_current_cycle cctxt ?(chain = `Main) block ?(offset = 0l) () =
|
let blocks_from_current_cycle cctxt ?(chain = `Main) block ?(offset = 0l) () =
|
||||||
|
Loading…
Reference in New Issue
Block a user