33//! RS-Drive-ABCI server starts a single-threaded server and listens to connections from Tenderdash.
44
55use clap:: { Parser , Subcommand } ;
6+ use dapi_grpc:: platform:: v0:: get_status_request;
7+ use dapi_grpc:: platform:: v0:: get_status_request:: GetStatusRequestV0 ;
8+ use dapi_grpc:: platform:: v0:: platform_client:: PlatformClient ;
9+ use dapi_grpc:: tonic:: transport:: Uri ;
610use dpp:: version:: PlatformVersion ;
711use drive_abci:: config:: { FromEnv , PlatformConfig } ;
812use drive_abci:: core:: wait_for_core_to_sync:: v0:: wait_for_core_to_sync_v0;
913use drive_abci:: logging:: { LogBuilder , LogConfig , LogDestination , Loggers } ;
10- use drive_abci:: metrics:: { Prometheus , DEFAULT_PROMETHEUS_PORT } ;
14+ use drive_abci:: metrics:: Prometheus ;
1115use drive_abci:: platform_types:: platform:: Platform ;
1216use drive_abci:: rpc:: core:: DefaultCoreRPC ;
1317use drive_abci:: { logging, server} ;
@@ -17,6 +21,7 @@ use std::fs::remove_file;
1721use std:: net:: SocketAddr ;
1822use std:: path:: PathBuf ;
1923use std:: process:: ExitCode ;
24+ use std:: str:: FromStr ;
2025use std:: sync:: Arc ;
2126use tokio:: runtime:: { Builder , Runtime } ;
2227use tokio:: signal:: unix:: { signal, SignalKind } ;
@@ -98,6 +103,13 @@ impl Cli {
98103 ) -> Result < ( ) , String > {
99104 match self . command {
100105 Commands :: Start => {
106+ tracing:: info!(
107+ version = env!( "CARGO_PKG_VERSION" ) ,
108+ features = list_enabled_features( ) . join( "," ) ,
109+ rust = env!( "CARGO_PKG_RUST_VERSION" ) ,
110+ "drive-abci server initializing" ,
111+ ) ;
112+
101113 if config. drive . grovedb_verify_on_startup {
102114 verify_grovedb ( & config. db_path , false ) ?;
103115 }
@@ -129,10 +141,12 @@ impl Cli {
129141
130142 server:: start ( runtime, Arc :: new ( platform) , config, cancel) ;
131143
144+ tracing:: info!( "drive-abci server is stopped" ) ;
145+
132146 return Ok ( ( ) ) ;
133147 }
134148 Commands :: Config => dump_config ( & config) ?,
135- Commands :: Status => check_status ( & config) ?,
149+ Commands :: Status => runtime . block_on ( check_status ( & config) ) ?,
136150 Commands :: Verify => verify_grovedb ( & config. db_path , true ) ?,
137151 } ;
138152
@@ -202,13 +216,6 @@ fn main() -> Result<(), ExitCode> {
202216 install_panic_hook ( cancel. clone ( ) ) ;
203217
204218 // Start runtime in the main thread
205- tracing:: info!(
206- version = env!( "CARGO_PKG_VERSION" ) ,
207- features = list_enabled_features( ) . join( "," ) ,
208- rust = env!( "CARGO_PKG_RUST_VERSION" ) ,
209- "drive-abci server initializing" ,
210- ) ;
211-
212219 let runtime_guard = runtime. enter ( ) ;
213220
214221 runtime. spawn ( handle_signals ( cancel. clone ( ) , loggers) ) ;
@@ -219,15 +226,13 @@ fn main() -> Result<(), ExitCode> {
219226 Ok ( ( ) )
220227 }
221228 Err ( e) => {
222- tracing:: error!( error = e, "drive-abci failed" ) ;
229+ tracing:: error!( error = e, "drive-abci failed: {e} " ) ;
223230 Err ( ExitCode :: FAILURE )
224231 }
225232 } ;
226233
227234 drop ( runtime_guard) ;
228235 runtime. shutdown_timeout ( Duration :: from_millis ( SHUTDOWN_TIMEOUT_MILIS ) ) ;
229- tracing:: info!( "drive-abci server is stopped" ) ;
230-
231236 result
232237}
233238
@@ -303,31 +308,27 @@ fn list_enabled_features() -> Vec<&'static str> {
303308}
304309
305310/// Check status of ABCI server.
306- fn check_status ( config : & PlatformConfig ) -> Result < ( ) , String > {
307- if let Some ( prometheus_addr) = & config. prometheus_bind_address {
308- let url =
309- url:: Url :: parse ( prometheus_addr) . expect ( "cannot parse ABCI_PROMETHEUS_BIND_ADDRESS" ) ;
310-
311- let addr = format ! (
312- "{}://{}:{}/metrics" ,
313- url. scheme( ) ,
314- url. host( )
315- . ok_or( "ABCI_PROMETHEUS_BIND_ADDRESS must contain valid host" . to_string( ) ) ?,
316- url. port( ) . unwrap_or( DEFAULT_PROMETHEUS_PORT )
317- ) ;
318-
319- let body: String = ureq:: get ( & addr)
320- . set ( "Content-type" , "text/plain" )
321- . call ( )
322- . map_err ( |e| e. to_string ( ) ) ?
323- . into_string ( )
324- . map_err ( |e| e. to_string ( ) ) ?;
311+ async fn check_status ( config : & PlatformConfig ) -> Result < ( ) , String > {
312+ // Convert the gRPC bind address string to a Uri
313+ let uri = Uri :: from_str ( & format ! ( "http://{}" , config. grpc_bind_address) )
314+ . map_err ( |e| format ! ( "invalid url: {e}" ) ) ?;
315+
316+ // Connect to the gRPC server
317+ let mut client = PlatformClient :: connect ( uri. clone ( ) )
318+ . await
319+ . map_err ( |e| format ! ( "can't connect to grpc server {uri}: {e}" ) ) ?;
320+
321+ // Make a request to the server
322+ let request = dapi_grpc:: platform:: v0:: GetStatusRequest {
323+ version : Some ( get_status_request:: Version :: V0 ( GetStatusRequestV0 { } ) ) ,
324+ } ;
325325
326- println ! ( "{}" , body) ;
327- Ok ( ( ) )
328- } else {
329- Err ( "ABCI_PROMETHEUS_BIND_ADDRESS not defined, cannot check status" . to_string ( ) )
330- }
326+ // Should return non-zero error code if Drive is not responding
327+ client
328+ . get_status ( request)
329+ . await
330+ . map ( |_| ( ) )
331+ . map_err ( |e| format ! ( "can't request status: {e}" ) )
331332}
332333
333334/// Verify GroveDB integrity.
@@ -415,7 +416,7 @@ fn configure_logging(cli: &Cli, config: &PlatformConfig) -> Result<Loggers, logg
415416 if configs. is_empty ( ) || cli. verbose > 0 {
416417 let cli_config = LogConfig {
417418 destination : LogDestination :: StdOut ,
418- level : cli. verbose . try_into ( ) . unwrap ( ) ,
419+ level : cli. verbose . try_into ( ) ? ,
419420 color : cli. color ,
420421 ..Default :: default ( )
421422 } ;
@@ -442,15 +443,14 @@ fn install_panic_hook(cancel: CancellationToken) {
442443
443444#[ cfg( test) ]
444445mod test {
446+ use :: drive:: { drive:: Drive , query:: Element } ;
447+ use dpp:: block:: epoch:: Epoch ;
448+ use drive:: drive:: credit_pools:: epochs:: epoch_key_constants;
445449 use std:: {
446450 fs,
447451 path:: { Path , PathBuf } ,
448452 } ;
449453
450- use :: drive:: { drive:: Drive , query:: Element } ;
451- use dpp:: block:: epoch:: Epoch ;
452- use drive:: drive:: credit_pools:: epochs:: epoch_key_constants;
453-
454454 use dpp:: version:: PlatformVersion ;
455455 use drive:: drive:: credit_pools:: epochs:: paths:: EpochProposers ;
456456 use drive_abci:: logging:: LogLevel ;
0 commit comments