@@ -12,7 +12,7 @@ use ibc_attestor::{
1212 } ,
1313 config:: { AttestorConfig , TracingConfig } ,
1414 logging:: init_logging,
15- rpc:: { RpcError , server} ,
15+ rpc:: { RpcError , health , server} ,
1616 signer:: {
1717 SignerBuilder ,
1818 local:: { DEFAULT_KEYSTORE_NAME , LocalSigner , LocalSignerConfig } ,
@@ -43,25 +43,37 @@ fn default_attestor_dir() -> Result<PathBuf, anyhow::Error> {
4343 Ok ( PathBuf :: from ( home) . join ( ".ibc-attestor" ) )
4444}
4545
46- fn run_server_with_adapter_and_signer < B : AdapterBuilder , S : SignerBuilder > (
46+ fn run_servers < B : AdapterBuilder + ' static , S : SignerBuilder + ' static > (
4747 config : AttestorConfig < B :: Config , S :: Config > ,
48- shutdown_rx : broadcast:: Receiver < ( ) > ,
49- ) -> Result < JoinHandle < Result < ( ) , RpcError > > , anyhow:: Error > {
48+ shutdown_tx : & broadcast:: Sender < ( ) > ,
49+ ) -> Result < ( JoinHandle < Result < ( ) , RpcError > > , JoinHandle < ( ) > ) , anyhow:: Error > {
5050 let adapter = B :: build ( config. adapter ) ?;
5151 let signer = S :: build ( config. signer ) ?;
52+ let server_config = config. server ;
5253
53- Ok ( tokio:: spawn ( async move {
54- // Start rpc server
54+ let grpc_shutdown_rx = shutdown_tx. subscribe ( ) ;
55+ let health_shutdown_rx = shutdown_tx. subscribe ( ) ;
56+
57+ let grpc_addr = server_config. listen_addr ;
58+ let health_addr = server_config. health_addr ;
59+
60+ let grpc_handle = tokio:: spawn ( async move {
5561 server:: start (
56- config . server . listen_addr ,
62+ grpc_addr ,
5763 adapter,
5864 B :: adapter_name ( ) ,
5965 signer,
6066 S :: signer_name ( ) ,
61- shutdown_rx ,
67+ grpc_shutdown_rx ,
6268 )
6369 . await
64- } ) )
70+ } ) ;
71+
72+ let health_handle = tokio:: spawn ( async move {
73+ health:: start ( health_addr, grpc_addr, health_shutdown_rx) . await ;
74+ } ) ;
75+
76+ Ok ( ( grpc_handle, health_handle) )
6577}
6678
6779#[ tokio:: main]
@@ -75,73 +87,56 @@ async fn main() -> Result<(), anyhow::Error> {
7587 let _tracing_guard = init_logging ( tracing_config) ;
7688
7789 // Create shutdown broadcast channel
78- let ( shutdown_tx, shutdown_rx ) = broadcast:: channel ( 1 ) ;
90+ let ( shutdown_tx, _shutdown_rx ) = broadcast:: channel ( 1 ) ;
7991
80- let rpc_handle = match ( args. chain_type , args. signer_type ) {
92+ let ( grpc_handle , health_handle ) = match ( args. chain_type , args. signer_type ) {
8193 ( ChainType :: Evm , SignerType :: Local ) => {
8294 let config = AttestorConfig :: < EvmAdapterConfig , LocalSignerConfig > :: from_file (
8395 & args. config ,
8496 ) ?;
85- run_server_with_adapter_and_signer :: < EvmAdapterBuilder , LocalSigner > (
86- config,
87- shutdown_rx,
88- ) ?
97+ run_servers :: < EvmAdapterBuilder , LocalSigner > ( config, & shutdown_tx) ?
8998 }
9099 ( ChainType :: Evm , SignerType :: Remote ) => {
91100 let config = AttestorConfig :: < EvmAdapterConfig , RemoteSignerConfig > :: from_file (
92101 & args. config ,
93102 ) ?;
94- run_server_with_adapter_and_signer :: < EvmAdapterBuilder , RemoteSigner > (
95- config,
96- shutdown_rx,
97- ) ?
103+ run_servers :: < EvmAdapterBuilder , RemoteSigner > ( config, & shutdown_tx) ?
98104 }
99105 ( ChainType :: Solana , SignerType :: Local ) => {
100106 let config =
101107 AttestorConfig :: < SolanaAdapterConfig , LocalSignerConfig > :: from_file (
102108 & args. config ,
103109 ) ?;
104- run_server_with_adapter_and_signer :: < SolanaAdapterBuilder , LocalSigner > (
105- config,
106- shutdown_rx,
107- ) ?
110+ run_servers :: < SolanaAdapterBuilder , LocalSigner > ( config, & shutdown_tx) ?
108111 }
109112 ( ChainType :: Solana , SignerType :: Remote ) => {
110113 let config =
111114 AttestorConfig :: < SolanaAdapterConfig , RemoteSignerConfig > :: from_file (
112115 & args. config ,
113116 ) ?;
114- run_server_with_adapter_and_signer :: < SolanaAdapterBuilder , RemoteSigner > (
115- config,
116- shutdown_rx,
117- ) ?
117+ run_servers :: < SolanaAdapterBuilder , RemoteSigner > ( config, & shutdown_tx) ?
118118 }
119119 ( ChainType :: Cosmos , SignerType :: Local ) => {
120120 let config =
121121 AttestorConfig :: < CosmosAdapterConfig , LocalSignerConfig > :: from_file (
122122 & args. config ,
123123 ) ?;
124- run_server_with_adapter_and_signer :: < CosmosAdapterBuilder , LocalSigner > (
125- config,
126- shutdown_rx,
127- ) ?
124+ run_servers :: < CosmosAdapterBuilder , LocalSigner > ( config, & shutdown_tx) ?
128125 }
129126 ( ChainType :: Cosmos , SignerType :: Remote ) => {
130127 let config =
131128 AttestorConfig :: < CosmosAdapterConfig , RemoteSignerConfig > :: from_file (
132129 & args. config ,
133130 ) ?;
134- run_server_with_adapter_and_signer :: < CosmosAdapterBuilder , RemoteSigner > (
135- config,
136- shutdown_rx,
137- ) ?
131+ run_servers :: < CosmosAdapterBuilder , RemoteSigner > ( config, & shutdown_tx) ?
138132 }
139133 } ;
140134
141135 _ = wait_for_shutdown_signal ( ) . await ;
142136 info ! ( "shutdown signal received, starting graceful shutdown" ) ;
143137 let _ = shutdown_tx. send ( ( ) ) ;
144- rpc_handle. await ??;
138+ grpc_handle. await ??;
139+ health_handle. await ?;
145140 }
146141 Commands :: Key ( cmd) => {
147142 match cmd {
0 commit comments