diff --git a/src/lib_shell/node.ml b/src/lib_shell/node.ml index 7be34c118..edb59a866 100644 --- a/src/lib_shell/node.ml +++ b/src/lib_shell/node.ml @@ -144,7 +144,7 @@ let build_rpc_directory node = merge (Injection_directory.build_rpc_directory node.validator) ; merge (Chain_directory.build_rpc_directory node.validator) ; merge (P2p.build_rpc_directory node.p2p) ; - merge Worker_directory.rpc_directory ; + merge (Worker_directory.build_rpc_directory node.state) ; register0 RPC_service.error_service begin fun () () -> return (Data_encoding.Json.schema Error_monad.error_encoding) diff --git a/src/lib_shell/worker_directory.ml b/src/lib_shell/worker_directory.ml index 94c32a287..be196de8c 100644 --- a/src/lib_shell/worker_directory.ml +++ b/src/lib_shell/worker_directory.ml @@ -7,7 +7,7 @@ (* *) (**************************************************************************) -let rpc_directory = +let build_rpc_directory state = let dir : unit RPC_directory.t ref = ref RPC_directory.empty in let register0 s f = @@ -26,7 +26,8 @@ let rpc_directory = (Prevalidator.running_workers ())) end ; - register1 Worker_services.Prevalidators.S.state begin fun chain_id () () -> + register1 Worker_services.Prevalidators.S.state begin fun chain () () -> + Chain_directory.get_chain_id state chain >>= fun chain_id -> let w = List.assoc chain_id (Prevalidator.running_workers ()) in return { Worker_types.status = Prevalidator.status w ; @@ -48,7 +49,8 @@ let rpc_directory = (* Workers : Peer validators *) - register1 Worker_services.Peer_validators.S.list begin fun chain_id () () -> + register1 Worker_services.Peer_validators.S.list begin fun chain () () -> + Chain_directory.get_chain_id state chain >>= fun chain_id -> return (List.filter_map (fun ((id, peer_id), w) -> @@ -58,7 +60,8 @@ let rpc_directory = (Peer_validator.running_workers ())) end ; - register2 Worker_services.Peer_validators.S.state begin fun chain_id peer_id () () -> + register2 Worker_services.Peer_validators.S.state begin fun chain peer_id () () -> + Chain_directory.get_chain_id state chain >>= fun chain_id -> let w = List.assoc (chain_id, peer_id) (Peer_validator.running_workers ()) in return { Worker_types.status = Peer_validator.status w ; @@ -76,7 +79,8 @@ let rpc_directory = (Chain_validator.running_workers ())) end ; - register1 Worker_services.Chain_validators.S.state begin fun chain_id () () -> + register1 Worker_services.Chain_validators.S.state begin fun chain () () -> + Chain_directory.get_chain_id state chain >>= fun chain_id -> let w = List.assoc chain_id (Chain_validator.running_workers ()) in return { Worker_types.status = Chain_validator.status w ; diff --git a/src/lib_shell/worker_directory.mli b/src/lib_shell/worker_directory.mli index c77d4e66c..5c4e06f73 100644 --- a/src/lib_shell/worker_directory.mli +++ b/src/lib_shell/worker_directory.mli @@ -7,4 +7,4 @@ (* *) (**************************************************************************) -val rpc_directory: unit RPC_directory.t +val build_rpc_directory: State.t -> unit RPC_directory.t diff --git a/src/lib_shell_services/worker_services.ml b/src/lib_shell_services/worker_services.ml index 002721640..c57b0185d 100644 --- a/src/lib_shell_services/worker_services.ml +++ b/src/lib_shell_services/worker_services.ml @@ -14,10 +14,9 @@ module Prevalidators = struct module S = struct let list = - RPC_service.post_service + RPC_service.get_service ~description:"Lists the Prevalidator workers and their status." ~query: RPC_query.empty - ~input: empty ~output: (list (obj2 @@ -26,17 +25,15 @@ module Prevalidators = struct RPC_path.(root / "workers" / "prevalidators") let state = - let open Data_encoding in - RPC_service.post_service + RPC_service.get_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" /: Chain_id.rpc_arg ) + RPC_path.(root / "workers" / "prevalidators" /: Chain_services.chain_arg ) end @@ -51,11 +48,9 @@ module Block_validator = struct module S = struct let state = - let open Data_encoding in - RPC_service.post_service + RPC_service.get_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 @@ -74,12 +69,6 @@ module Peer_validators = struct module S = struct - let (chain_id_arg : Chain_id.t RPC_arg.t) = - RPC_arg.like - Chain_id.rpc_arg - ~descr:"The chain identifier the peer validator is associated to." - "chain_id" - let (peer_id_arg : P2p_peer.Id.t RPC_arg.t) = RPC_arg.make ~name:"peer_id" @@ -91,29 +80,26 @@ module Peer_validators = struct () let list = - RPC_service.post_service + RPC_service.get_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" /: chain_id_arg) + RPC_path.(root / "workers" / "peer_validators" /: Chain_services.chain_arg) let state = - let open Data_encoding in - RPC_service.post_service + RPC_service.get_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" /: chain_id_arg /: peer_id_arg) + RPC_path.(root / "workers" / "peer_validators" /: Chain_services.chain_arg /: peer_id_arg) end @@ -126,17 +112,11 @@ end module Chain_validators = struct module S = struct - let (chain_id_arg : Chain_id.t RPC_arg.t) = - RPC_arg.like - Chain_id.rpc_arg - ~descr:"The chain identifier of whom the chain validator is responsible." - "chain_id" let list = - RPC_service.post_service + RPC_service.get_service ~description:"Lists the chain validator workers and their status." ~query: RPC_query.empty - ~input: empty ~output: (list (obj2 @@ -145,17 +125,15 @@ module Chain_validators = struct RPC_path.(root / "workers" / "chain_validators") let state = - let open Data_encoding in - RPC_service.post_service + RPC_service.get_service ~description:"Introspect the state of a chain validator worker." ~query: RPC_query.empty - ~input: empty ~output: (Worker_types.full_status_encoding Chain_validator_worker_state.Request.encoding Chain_validator_worker_state.Event.encoding RPC_error.encoding) - RPC_path.(root / "workers" / "chain_validators" /: chain_id_arg ) + RPC_path.(root / "workers" / "chain_validators" /: Chain_services.chain_arg ) end diff --git a/src/lib_shell_services/worker_services.mli b/src/lib_shell_services/worker_services.mli index 1f1ad705b..583f00698 100644 --- a/src/lib_shell_services/worker_services.mli +++ b/src/lib_shell_services/worker_services.mli @@ -16,18 +16,18 @@ module Prevalidators : sig val list: #simple -> (Chain_id.t * Worker_types.worker_status) list tzresult Lwt.t val state: - #simple -> Chain_id.t -> (Request.view, Event.t) Worker_types.full_status tzresult Lwt.t + #simple -> Chain_services.chain -> (Request.view, Event.t) Worker_types.full_status tzresult Lwt.t module S : sig val list : - ([ `POST ], unit, + ([ `GET ], unit, unit, unit, unit, (Chain_id.t * Worker_types.worker_status) list) RPC_service.t val state : - ([ `POST ], unit, - unit * Chain_id.t, unit, unit, + ([ `GET ], unit, + unit * Chain_services.chain, unit, unit, (Request.view, Event.t) Worker_types.full_status) RPC_service.t end @@ -44,7 +44,7 @@ module Block_validator : sig module S : sig val state : - ([ `POST ], unit, + ([ `GET ], unit, unit, unit, unit, (Request.view, Event.t) Worker_types.full_status) RPC_service.t @@ -57,23 +57,23 @@ module Peer_validators : sig open Peer_validator_worker_state val list: - #simple -> Chain_id.t -> + #simple -> Chain_services.chain -> (P2p_peer.Id.t * Worker_types.worker_status) list tzresult Lwt.t val state: #simple -> - Chain_id.t -> P2p_peer.Id.t -> (Request.view, Event.t) Worker_types.full_status tzresult Lwt.t + Chain_services.chain -> P2p_peer.Id.t -> (Request.view, Event.t) Worker_types.full_status tzresult Lwt.t module S : sig val list : - ([ `POST ], unit, - unit * Chain_id.t, unit, unit, + ([ `GET ], unit, + unit * Chain_services.chain, unit, unit, (P2p_peer.Id.t * Worker_types.worker_status) list) RPC_service.t val state : - ([ `POST ], unit, - (unit * Chain_id.t) * P2p_peer.Id.t, unit, unit, + ([ `GET ], unit, + (unit * Chain_services.chain) * P2p_peer.Id.t, unit, unit, (Request.view, Event.t) Worker_types.full_status) RPC_service.t end @@ -87,18 +87,18 @@ module Chain_validators : sig val list: #simple -> (Chain_id.t * Worker_types.worker_status) list tzresult Lwt.t val state: - #simple -> Chain_id.t -> (Request.view, Event.t) Worker_types.full_status tzresult Lwt.t + #simple -> Chain_services.chain -> (Request.view, Event.t) Worker_types.full_status tzresult Lwt.t module S : sig val list : - ([ `POST ], unit, + ([ `GET ], unit, unit, unit, unit, (Chain_id.t * Worker_types.worker_status) list) RPC_service.t val state : - ([ `POST ], unit, - unit * Chain_id.t, unit, unit, + ([ `GET ], unit, + unit * Chain_services.chain, unit, unit, (Request.view, Event.t) Worker_types.full_status) RPC_service.t end