1
+ use colored:: Colorize ;
1
2
use dkn_p2p:: libp2p:: multiaddr:: Protocol ;
2
3
use std:: time:: Duration ;
3
4
use tokio:: time:: Instant ;
4
5
5
- use crate :: { refresh_dria_nodes, DriaComputeNode , DRIA_COMPUTE_NODE_VERSION } ;
6
+ use crate :: { refresh_dria_nodes, utils :: get_steps , DriaComputeNode , DRIA_COMPUTE_NODE_VERSION } ;
6
7
7
8
/// Number of seconds such that if the last ping is older than this, the node is considered unreachable.
8
9
const PING_LIVENESS_SECS : u64 = 150 ;
@@ -21,20 +22,32 @@ 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
- // print tasks count
33
- let [ single, batch] = self . get_pending_task_count ( ) ;
34
- diagnostics. push ( format ! (
35
- "Pending Tasks (single/batch): {} / {}" ,
36
- single, batch
37
- ) ) ;
43
+ // print steps
44
+ if let Ok ( steps) = get_steps ( & self . config . address ) . await {
45
+ let earned = steps. score - self . initial_steps ;
46
+ diagnostics. push ( format ! (
47
+ "Steps: {} total, {} earned in this run, within top {}%" ,
48
+ steps. score, earned, steps. percentile
49
+ ) ) ;
50
+ }
38
51
39
52
// completed tasks count is printed as well in debug
40
53
if log:: log_enabled!( log:: Level :: Debug ) {
@@ -60,10 +73,20 @@ impl DriaComputeNode {
60
73
. join( ", " )
61
74
) ) ;
62
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
+
63
86
log:: info!( "{}" , diagnostics. join( "\n " ) ) ;
64
87
65
- // check liveness of the node w.r.t last ping-pong time
66
- 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 {
67
90
log:: error!(
68
91
"Node has not received any pings for at least {} seconds & it may be unreachable!\n Please restart your node!" ,
69
92
PING_LIVENESS_SECS
@@ -72,7 +95,7 @@ impl DriaComputeNode {
72
95
73
96
// added rpc nodes check, sometimes this happens when API is down / bugs for some reason
74
97
if self . dria_nodes . rpc_peerids . is_empty ( ) {
75
- 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!" , ) ;
76
99
}
77
100
}
78
101
0 commit comments