Skip to content

Commit 416a343

Browse files
committed
adding steps log
1 parent f7d545e commit 416a343

File tree

6 files changed

+60
-16
lines changed

6 files changed

+60
-16
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
resolver = "2"
33
members = ["compute", "p2p", "workflows", "utils"]
44

5-
# FIXME: removing this breaks the workflows
6-
# compute node is the default member, until Oracle comes in
7-
# then, a Launcher will be the default member
5+
# removing this breaks the workflows
86
default-members = ["compute"]
97

108
[workspace.package]
119
edition = "2021"
12-
version = "0.3.7"
10+
version = "0.3.8"
1311
license = "Apache-2.0"
1412
readme = "README.md"
1513

compute/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct DriaComputeNodeConfig {
1818
pub secret_key: SecretKey,
1919
/// Wallet public key, derived from the secret key.
2020
pub public_key: PublicKey,
21-
/// Wallet address in hex, derived from the public key.
21+
/// Wallet address in hex without `0x` prefix, derived from the public key.
2222
pub address: String,
2323
/// Peer ID of the node.
2424
pub peer_id: PeerId,

compute/src/node/diagnostic.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use dkn_p2p::libp2p::multiaddr::Protocol;
22
use std::time::Duration;
33
use tokio::time::Instant;
44

5-
use crate::{refresh_dria_nodes, DriaComputeNode, DRIA_COMPUTE_NODE_VERSION};
5+
use crate::{refresh_dria_nodes, utils::get_steps, DriaComputeNode, DRIA_COMPUTE_NODE_VERSION};
66

77
/// Number of seconds such that if the last ping is older than this, the node is considered unreachable.
88
const PING_LIVENESS_SECS: u64 = 150;
@@ -29,12 +29,13 @@ impl DriaComputeNode {
2929
Err(e) => log::error!("Error getting peer counts: {:?}", e),
3030
}
3131

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-
));
32+
// print steps
33+
if let Ok(steps) = get_steps(&self.config.address).await {
34+
diagnostics.push(format!(
35+
"Steps: {} (top {}%)",
36+
steps.score, steps.percentile
37+
));
38+
}
3839

3940
// completed tasks count is printed as well in debug
4041
if log::log_enabled!(log::Level::Debug) {

compute/src/utils/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ pub use nodes::*;
99

1010
mod specs;
1111
pub use specs::*;
12+
13+
mod steps;
14+
pub use steps::*;

compute/src/utils/steps.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use eyre::Context;
2+
use serde::{Deserialize, Serialize};
3+
4+
const STEPS_API_BASE_URL: &str = "https://dkn.dria.co/dashboard/supply/v0/leaderboard/steps";
5+
6+
#[derive(Debug, Serialize, Deserialize)]
7+
pub struct StepsScore {
8+
/// Indicates in which top percentile your steps are.
9+
pub percentile: String,
10+
/// The total number of steps you have accumulated.
11+
pub score: u64,
12+
}
13+
14+
/// Returns the steps for the given address.
15+
pub async fn get_steps(address: &str) -> eyre::Result<StepsScore> {
16+
// the address can have 0x or not, we add it ourselves here
17+
let url = format!(
18+
"{}?address=0x{}",
19+
STEPS_API_BASE_URL,
20+
address.trim_start_matches("0x")
21+
);
22+
23+
reqwest::get(&url)
24+
.await
25+
.wrap_err("could not make request")?
26+
.json::<StepsScore>()
27+
.await
28+
.wrap_err("could not parse steps body")
29+
}
30+
31+
#[cfg(test)]
32+
mod tests {
33+
use super::*;
34+
35+
#[tokio::test]
36+
async fn test_get_steps() {
37+
let steps = get_steps("0xa43536a6032a3907ccf60e8109429ee1047b207c")
38+
.await
39+
.unwrap();
40+
println!("{:?}", steps);
41+
}
42+
}

0 commit comments

Comments
 (0)