diff --git a/src/lib_shell/node_rpc.ml b/src/lib_shell/node_rpc.ml index add189143..49a7d8373 100644 --- a/src/lib_shell/node_rpc.ml +++ b/src/lib_shell/node_rpc.ml @@ -449,14 +449,14 @@ let build_rpc_directory node = (* Workers : Prevalidators *) let dir = - RPC_directory.register0 dir Worker_services.Prevalidators.list + RPC_directory.register0 dir Worker_services.Prevalidators.S.list (fun () () -> RPC_answer.return (List.map (fun (id, w) -> (id, Prevalidator.status w)) (Prevalidator.running_workers ()))) in let dir = - RPC_directory.register1 dir Worker_services.Prevalidators.state + RPC_directory.register1 dir Worker_services.Prevalidators.S.state (fun net_id () () -> let w = List.assoc net_id (Prevalidator.running_workers ()) in RPC_answer.return @@ -468,7 +468,7 @@ let build_rpc_directory node = (* Workers : Block_validator *) let dir = - RPC_directory.register0 dir Worker_services.Block_validator.state + RPC_directory.register0 dir Worker_services.Block_validator.S.state (fun () () -> let w = Block_validator.running_worker () in RPC_answer.return @@ -480,7 +480,7 @@ let build_rpc_directory node = (* Workers : Peer validators *) let dir = - RPC_directory.register1 dir Worker_services.Peer_validators.list + RPC_directory.register1 dir Worker_services.Peer_validators.S.list (fun net_id () () -> RPC_answer.return (List.filter_map @@ -490,7 +490,7 @@ let build_rpc_directory node = else None) (Peer_validator.running_workers ()))) in let dir = - RPC_directory.register2 dir Worker_services.Peer_validators.state + RPC_directory.register2 dir Worker_services.Peer_validators.S.state (fun net_id peer_id () () -> let w = List.assoc (net_id, peer_id) (Peer_validator.running_workers ()) in RPC_answer.return @@ -502,14 +502,14 @@ let build_rpc_directory node = (* Workers : Net validators *) let dir = - RPC_directory.register0 dir Worker_services.Net_validators.list + RPC_directory.register0 dir Worker_services.Net_validators.S.list (fun () () -> RPC_answer.return (List.map (fun (id, w) -> (id, Net_validator.status w)) (Net_validator.running_workers ()))) in let dir = - RPC_directory.register1 dir Worker_services.Net_validators.state + RPC_directory.register1 dir Worker_services.Net_validators.S.state (fun net_id () () -> let w = List.assoc net_id (Net_validator.running_workers ()) in RPC_answer.return diff --git a/src/lib_shell_services/worker_services.ml b/src/lib_shell_services/worker_services.ml index fb611b29c..8303aa77c 100644 --- a/src/lib_shell_services/worker_services.ml +++ b/src/lib_shell_services/worker_services.ml @@ -11,144 +11,162 @@ open Data_encoding module Prevalidators = struct - let (net_id_arg : Net_id.t RPC_arg.t) = - RPC_arg.make - ~name:"net_id" - ~descr:"The network identifier of whom the prevalidator is responsible." - ~destruct:(fun s -> try - Ok (Net_id.of_b58check_exn s) - with Failure msg -> Error msg) - ~construct:Net_id.to_b58check - () + module S = struct - let list = - RPC_service.post_service - ~description:"Lists the Prevalidator workers and their status." - ~query: RPC_query.empty - ~input: empty - ~output: - (list - (obj2 - (req "net_id" Net_id.encoding) - (req "status" (Worker_types.worker_status_encoding RPC_error.encoding)))) - RPC_path.(root / "workers" / "prevalidators") + let (net_id_arg : Net_id.t RPC_arg.t) = + RPC_arg.like + Net_id.rpc_arg + ~descr:"The network identifier of whom the prevalidator is responsible." + "net_id" - let state = - let open Data_encoding in - RPC_service.post_service - ~description:"Introspect the state of a prevalidator worker." - ~query: RPC_query.empty - ~input: empty - ~output: - (Worker_types.full_status_encoding - Prevalidator_worker_state.Request.encoding - Prevalidator_worker_state.Event.encoding - RPC_error.encoding) - RPC_path.(root / "workers" / "prevalidators" /: net_id_arg ) + let list = + RPC_service.post_service + ~description:"Lists the Prevalidator workers and their status." + ~query: RPC_query.empty + ~input: empty + ~output: + (list + (obj2 + (req "net_id" Net_id.encoding) + (req "status" (Worker_types.worker_status_encoding RPC_error.encoding)))) + RPC_path.(root / "workers" / "prevalidators") + + let state = + let open Data_encoding in + RPC_service.post_service + ~description:"Introspect the state of a prevalidator worker." + ~query: RPC_query.empty + ~input: empty + ~output: + (Worker_types.full_status_encoding + Prevalidator_worker_state.Request.encoding + Prevalidator_worker_state.Event.encoding + RPC_error.encoding) + RPC_path.(root / "workers" / "prevalidators" /: Net_id.rpc_arg ) + + end + + open RPC_context + let list ctxt = make_call S.list ctxt () () () + let state ctxt h = make_call1 S.state ctxt h () () end module Block_validator = struct - let state = - let open Data_encoding in - RPC_service.post_service - ~description:"Introspect the state of the block_validator worker." - ~query: RPC_query.empty - ~input: empty - ~output: - (Worker_types.full_status_encoding - Block_validator_worker_state.Request.encoding - Block_validator_worker_state.Event.encoding - RPC_error.encoding) - RPC_path.(root / "workers" / "block_validator") + module S = struct + + let state = + let open Data_encoding in + RPC_service.post_service + ~description:"Introspect the state of the block_validator worker." + ~query: RPC_query.empty + ~input: empty + ~output: + (Worker_types.full_status_encoding + Block_validator_worker_state.Request.encoding + Block_validator_worker_state.Event.encoding + RPC_error.encoding) + RPC_path.(root / "workers" / "block_validator") + + end + + open RPC_context + let state ctxt = make_call S.state ctxt () () () end module Peer_validators = struct - let (net_id_arg : Net_id.t RPC_arg.t) = - RPC_arg.make - ~name:"net_id" - ~descr:"The network identifier the peer validator is associated to." - ~destruct:(fun s -> try - Ok (Net_id.of_b58check_exn s) - with Failure msg -> Error msg) - ~construct:Net_id.to_b58check - () + module S = struct - let (peer_id_arg : P2p_peer.Id.t RPC_arg.t) = - RPC_arg.make - ~name:"peer_id" - ~descr:"The peer identifier of whom the prevalidator is responsible." - ~destruct:(fun s -> try - Ok (P2p_peer.Id.of_b58check_exn s) - with Failure msg -> Error msg) - ~construct:P2p_peer.Id.to_b58check - () + let (net_id_arg : Net_id.t RPC_arg.t) = + RPC_arg.like + Net_id.rpc_arg + ~descr:"The network identifier the peer validator is associated to." + "net_id" - let list = - RPC_service.post_service - ~description:"Lists the peer validator workers and their status." - ~query: RPC_query.empty - ~input: empty - ~output: - (list - (obj2 - (req "peer_id" P2p_peer.Id.encoding) - (req "status" (Worker_types.worker_status_encoding RPC_error.encoding)))) - RPC_path.(root / "workers" / "peer_validators" /: net_id_arg) + let (peer_id_arg : P2p_peer.Id.t RPC_arg.t) = + RPC_arg.make + ~name:"peer_id" + ~descr:"The peer identifier of whom the prevalidator is responsible." + ~destruct:(fun s -> try + Ok (P2p_peer.Id.of_b58check_exn s) + with Failure msg -> Error msg) + ~construct:P2p_peer.Id.to_b58check + () - let state = - let open Data_encoding in - RPC_service.post_service - ~description:"Introspect the state of a peer validator worker." - ~query: RPC_query.empty - ~input: empty - ~output: - (Worker_types.full_status_encoding - Peer_validator_worker_state.Request.encoding - Peer_validator_worker_state.Event.encoding - RPC_error.encoding) - RPC_path.(root / "workers" / "peer_validators" /: net_id_arg /: peer_id_arg) + let list = + RPC_service.post_service + ~description:"Lists the peer validator workers and their status." + ~query: RPC_query.empty + ~input: empty + ~output: + (list + (obj2 + (req "peer_id" P2p_peer.Id.encoding) + (req "status" (Worker_types.worker_status_encoding RPC_error.encoding)))) + RPC_path.(root / "workers" / "peer_validators" /: net_id_arg) + + let state = + let open Data_encoding in + RPC_service.post_service + ~description:"Introspect the state of a peer validator worker." + ~query: RPC_query.empty + ~input: empty + ~output: + (Worker_types.full_status_encoding + Peer_validator_worker_state.Request.encoding + Peer_validator_worker_state.Event.encoding + RPC_error.encoding) + RPC_path.(root / "workers" / "peer_validators" /: net_id_arg /: peer_id_arg) + + end + + open RPC_context + let list ctxt n = make_call1 S.list ctxt n () () + let state ctxt n h = make_call2 S.state ctxt n h () () end module Net_validators = struct - let (net_id_arg : Net_id.t RPC_arg.t) = - RPC_arg.make - ~name:"net_id" - ~descr:"The network identifier of whom the net validator is responsible." - ~destruct:(fun s -> try - Ok (Net_id.of_b58check_exn s) - with Failure msg -> Error msg) - ~construct:Net_id.to_b58check - () + module S = struct + let (net_id_arg : Net_id.t RPC_arg.t) = + RPC_arg.like + Net_id.rpc_arg + ~descr:"The network identifier of whom the net validator is responsible." + "net_id" - let list = - RPC_service.post_service - ~description:"Lists the net validator workers and their status." - ~query: RPC_query.empty - ~input: empty - ~output: - (list - (obj2 - (req "net_id" Net_id.encoding) - (req "status" (Worker_types.worker_status_encoding RPC_error.encoding)))) - RPC_path.(root / "workers" / "net_validators") + let list = + RPC_service.post_service + ~description:"Lists the net validator workers and their status." + ~query: RPC_query.empty + ~input: empty + ~output: + (list + (obj2 + (req "net_id" Net_id.encoding) + (req "status" (Worker_types.worker_status_encoding RPC_error.encoding)))) + RPC_path.(root / "workers" / "net_validators") - let state = - let open Data_encoding in - RPC_service.post_service - ~description:"Introspect the state of a net validator worker." - ~query: RPC_query.empty - ~input: empty - ~output: - (Worker_types.full_status_encoding - Net_validator_worker_state.Request.encoding - Net_validator_worker_state.Event.encoding - RPC_error.encoding) - RPC_path.(root / "workers" / "net_validators" /: net_id_arg ) + let state = + let open Data_encoding in + RPC_service.post_service + ~description:"Introspect the state of a net validator worker." + ~query: RPC_query.empty + ~input: empty + ~output: + (Worker_types.full_status_encoding + Net_validator_worker_state.Request.encoding + Net_validator_worker_state.Event.encoding + RPC_error.encoding) + RPC_path.(root / "workers" / "net_validators" /: net_id_arg ) + + end + + open RPC_context + let list ctxt = make_call S.list ctxt () () () + let state ctxt h = make_call1 S.state ctxt h () () end diff --git a/src/lib_shell_services/worker_services.mli b/src/lib_shell_services/worker_services.mli index b479dddeb..7c412d63e 100644 --- a/src/lib_shell_services/worker_services.mli +++ b/src/lib_shell_services/worker_services.mli @@ -7,19 +7,30 @@ (* *) (**************************************************************************) +open RPC_context + module Prevalidators : sig open Prevalidator_worker_state - val list : - ([ `POST ], unit, - unit, unit, unit, - (Net_id.t * Worker_types.worker_status) list) RPC_service.t + val list: + #simple -> (Net_id.t * Worker_types.worker_status) list tzresult Lwt.t + val state: + #simple -> Net_id.t -> (Request.view, Event.t) Worker_types.full_status tzresult Lwt.t - val state : - ([ `POST ], unit, - unit * Net_id.t, unit, unit, - (Request.view, Event.t) Worker_types.full_status) RPC_service.t + module S : sig + + val list : + ([ `POST ], unit, + unit, unit, unit, + (Net_id.t * Worker_types.worker_status) list) RPC_service.t + + val state : + ([ `POST ], unit, + unit * Net_id.t, unit, unit, + (Request.view, Event.t) Worker_types.full_status) RPC_service.t + + end end @@ -27,10 +38,17 @@ module Block_validator : sig open Block_validator_worker_state - val state : - ([ `POST ], unit, - unit, unit, unit, - (Request.view, Event.t) Worker_types.full_status) RPC_service.t + val state: + #simple -> (Request.view, Event.t) Worker_types.full_status tzresult Lwt.t + + module S : sig + + val state : + ([ `POST ], unit, + unit, unit, unit, + (Request.view, Event.t) Worker_types.full_status) RPC_service.t + + end end @@ -38,15 +56,27 @@ module Peer_validators : sig open Peer_validator_worker_state - val list : - ([ `POST ], unit, - unit * Net_id.t, unit, unit, - (P2p_peer.Id.t * Worker_types.worker_status) list) RPC_service.t + val list: + #simple -> Net_id.t -> + (P2p_peer.Id.t * Worker_types.worker_status) list tzresult Lwt.t - val state : - ([ `POST ], unit, - (unit * Net_id.t) * P2p_peer.Id.t, unit, unit, - (Request.view, Event.t) Worker_types.full_status) RPC_service.t + val state: + #simple -> + Net_id.t -> P2p_peer.Id.t -> (Request.view, Event.t) Worker_types.full_status tzresult Lwt.t + + module S : sig + + val list : + ([ `POST ], unit, + unit * Net_id.t, unit, unit, + (P2p_peer.Id.t * Worker_types.worker_status) list) RPC_service.t + + val state : + ([ `POST ], unit, + (unit * Net_id.t) * P2p_peer.Id.t, unit, unit, + (Request.view, Event.t) Worker_types.full_status) RPC_service.t + + end end @@ -54,14 +84,23 @@ module Net_validators : sig open Net_validator_worker_state - val list : - ([ `POST ], unit, - unit, unit, unit, - (Net_id.t * Worker_types.worker_status) list) RPC_service.t + val list: + #simple -> (Net_id.t * Worker_types.worker_status) list tzresult Lwt.t + val state: + #simple -> Net_id.t -> (Request.view, Event.t) Worker_types.full_status tzresult Lwt.t - val state : - ([ `POST ], unit, - unit * Net_id.t, unit, unit, - (Request.view, Event.t) Worker_types.full_status) RPC_service.t + module S : sig + + val list : + ([ `POST ], unit, + unit, unit, unit, + (Net_id.t * Worker_types.worker_status) list) RPC_service.t + + val state : + ([ `POST ], unit, + unit * Net_id.t, unit, unit, + (Request.view, Event.t) Worker_types.full_status) RPC_service.t + + end end