NS API: clamp load to offline when score is offline and add mixnet_score field to preformance_v2 (#6076)

* ns-api: when `score` is `Offline`, clamp `load` to `Offline`

* ns-api: bump version

* ns-api: add mixnet score field to performance_v2 struct

---------

Co-authored-by: Mark Sinclair <mmsinclair@users.noreply.github.com>
This commit is contained in:
Mark Sinclair
2025-10-07 17:30:37 +01:00
committed by GitHub
parent 83a598907f
commit 8cc996bc0d
3 changed files with 31 additions and 4 deletions
Generated
+1 -1
View File
@@ -6455,7 +6455,7 @@ dependencies = [
[[package]]
name = "nym-node-status-api"
version = "4.0.5"
version = "4.0.6"
dependencies = [
"ammonia",
"anyhow",
@@ -3,7 +3,7 @@
[package]
name = "nym-node-status-api"
version = "4.0.5"
version = "4.0.6"
authors.workspace = true
repository.workspace = true
homepage.workspace = true
@@ -78,6 +78,7 @@ pub struct Location {
#[derive(Debug, Clone, Deserialize, Serialize, ToSchema, EnumString)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
#[derive(PartialEq)]
pub enum ScoreValue {
Offline,
Low,
@@ -89,6 +90,7 @@ pub enum ScoreValue {
pub struct DVpnGatewayPerformance {
last_updated_utc: String,
score: ScoreValue,
mixnet_score: ScoreValue,
load: ScoreValue,
uptime_percentage_last_24_hours: f32,
}
@@ -293,10 +295,20 @@ impl DVpnGateway {
});
tracing::info!("🌈 gateway probe parsed: {:?}", parsed);
let mixnet_score = calculate_mixnet_score(&gateway);
let score = calculate_score(&gateway, &parsed);
let mut load = calculate_load(&parsed);
// clamp the load value to offline, when the score is offline
if score == ScoreValue::Offline {
load = ScoreValue::Offline;
}
let performance_v2 = DVpnGatewayPerformance {
last_updated_utc: last_updated_utc.to_string(),
load: calculate_load(&parsed),
score: calculate_score(&gateway, &parsed),
load,
score,
mixnet_score,
// the network monitor's measure is a good proxy for node uptime, it can be improved in the future
uptime_percentage_last_24_hours: network_monitor_performance_mixnet_mode,
@@ -353,6 +365,21 @@ impl DVpnGateway {
}
}
/// calculates the gateway probe score for mixnet mode
fn calculate_mixnet_score(gateway: &Gateway) -> ScoreValue {
let mixnet_performance = gateway.performance as f64 / 100.0;
if mixnet_performance > 0.8 {
ScoreValue::High
} else if mixnet_performance > 0.6 {
ScoreValue::Medium
} else if mixnet_performance > 0.1 {
ScoreValue::Low
} else {
ScoreValue::Offline
}
}
/// calculates a visual score for the gateway
fn calculate_score(gateway: &Gateway, probe_outcome: &LastProbeResult) -> ScoreValue {
let mixnet_performance = gateway.performance as f64 / 100.0;