1
+ use colored:: Colorize ;
1
2
use dkn_p2p:: libp2p:: multiaddr:: Protocol ;
2
3
use std:: time:: Duration ;
3
4
use tokio:: time:: Instant ;
@@ -21,19 +22,29 @@ impl DriaComputeNode {
21
22
pub ( crate ) async fn handle_diagnostic_refresh ( & self ) {
22
23
let mut diagnostics = vec ! [ format!( "Diagnostics (v{}):" , DRIA_COMPUTE_NODE_VERSION ) ] ;
23
24
25
+ // if we have not received pings for a while, we are considered offline
26
+ let is_offline =
27
+ self . last_pinged_at < Instant :: now ( ) - Duration :: from_secs ( PING_LIVENESS_SECS ) ;
28
+
24
29
// print peer counts
25
30
match self . p2p . peer_counts ( ) . await {
26
- Ok ( ( mesh, all) ) => {
27
- diagnostics. push ( format ! ( "Peer Count (mesh/all): {} / {}" , mesh, all) )
28
- }
31
+ Ok ( ( mesh, all) ) => diagnostics. push ( format ! (
32
+ "Peer Count (mesh/all): {} / {}" ,
33
+ if mesh == 0 {
34
+ "0" . red( )
35
+ } else {
36
+ mesh. to_string( ) . white( )
37
+ } ,
38
+ all
39
+ ) ) ,
29
40
Err ( e) => log:: error!( "Error getting peer counts: {:?}" , e) ,
30
41
}
31
42
32
43
// print steps
33
44
if let Ok ( steps) = get_steps ( & self . config . address ) . await {
34
45
let earned = steps. score - self . initial_steps ;
35
46
diagnostics. push ( format ! (
36
- "Steps: {} total (+ {} this run) , within top {}%" ,
47
+ "Steps: {} total, {} earned in this run, within top {}%" ,
37
48
steps. score, earned, steps. percentile
38
49
) ) ;
39
50
}
@@ -62,10 +73,20 @@ impl DriaComputeNode {
62
73
. join( ", " )
63
74
) ) ;
64
75
76
+ // add network status as well
77
+ diagnostics. push ( format ! (
78
+ "Node Status: {}" ,
79
+ if is_offline {
80
+ "OFFLINE" . bold( ) . red( )
81
+ } else {
82
+ "ONLINE" . bold( ) . green( )
83
+ }
84
+ ) ) ;
85
+
65
86
log:: info!( "{}" , diagnostics. join( "\n " ) ) ;
66
87
67
- // check liveness of the node w.r.t last ping-pong time
68
- if self . last_pinged_at < Instant :: now ( ) - Duration :: from_secs ( PING_LIVENESS_SECS ) {
88
+ // if offline, print this error message as well
89
+ if is_offline {
69
90
log:: error!(
70
91
"Node has not received any pings for at least {} seconds & it may be unreachable!\n Please restart your node!" ,
71
92
PING_LIVENESS_SECS
@@ -74,7 +95,7 @@ impl DriaComputeNode {
74
95
75
96
// added rpc nodes check, sometimes this happens when API is down / bugs for some reason
76
97
if self . dria_nodes . rpc_peerids . is_empty ( ) {
77
- log:: error!( "No RPC peerids were found to be available, please restart your node!" , ) ;
98
+ log:: error!( "No RPC peer IDs were found to be available, please restart your node!" , ) ;
78
99
}
79
100
}
80
101
0 commit comments