From d8ae36dc34250dd567e28fede1f1c01fdbb57d70 Mon Sep 17 00:00:00 2001 From: "Roman S. Borschel" Date: Mon, 14 Sep 2020 11:19:43 +0200 Subject: [PATCH 1/3] Further decouple SystemInterval values. --- backend/src/node.rs | 22 ++++++++++++++++------ backend/src/node/message.rs | 13 ++++++------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/backend/src/node.rs b/backend/src/node.rs index a359b9495..67aa43066 100644 --- a/backend/src/node.rs +++ b/backend/src/node.rs @@ -142,12 +142,22 @@ impl Node { } pub fn update_stats(&mut self, interval: &SystemInterval) -> Option<&NodeStats> { - if self.stats != interval.stats { - self.stats = interval.stats; - Some(&self.stats) - } else { - None - } + let mut changed = false; + + if let Some(peers) = interval.peers { + self.stats.peers = peers; + changed = true; + } + if let Some(txcount) = interval.txcount { + self.stats.txcount = txcount; + changed = true; + } + + if changed { + Some(&self.stats) + } else { + None + } } pub fn update_io(&mut self, interval: &SystemInterval) -> Option<&NodeIO> { diff --git a/backend/src/node/message.rs b/backend/src/node/message.rs index 9ce2afca2..ee4f2cc91 100644 --- a/backend/src/node/message.rs +++ b/backend/src/node/message.rs @@ -2,7 +2,7 @@ use actix::prelude::*; use chrono::{DateTime, Utc}; use serde::Deserialize; use serde::de::IgnoredAny; -use crate::node::{NodeDetails, NodeStats}; +use crate::node::NodeDetails; use crate::types::{Block, BlockNumber, BlockHash}; #[derive(Deserialize, Debug, Message)] @@ -63,14 +63,14 @@ pub struct SystemConnected { #[derive(Deserialize, Debug)] pub struct SystemInterval { - #[serde(flatten)] - pub stats: NodeStats, + pub peers: Option, + pub txcount: Option, pub bandwidth_upload: Option, pub bandwidth_download: Option, pub finalized_height: Option, pub finalized_hash: Option, #[serde(flatten)] - pub block: Block, + pub block: Option, pub network_state: Option, pub used_state_cache_size: Option, } @@ -132,9 +132,8 @@ impl Block { impl Details { pub fn best_block(&self) -> Option<&Block> { match self { - Details::BlockImport(block) | Details::SystemInterval(SystemInterval { block, .. }) => { - Some(block) - } + Details::BlockImport(block) => Some(block), + Details::SystemInterval(SystemInterval { block, .. }) => block.as_ref(), _ => None, } } From 5ecd6e2c4657697ed087a9d3eaa665645f5406fd Mon Sep 17 00:00:00 2001 From: Roman Borschel Date: Mon, 14 Sep 2020 17:04:38 +0200 Subject: [PATCH 2/3] Update backend/src/node.rs Co-authored-by: Maciej Hirsz <1096222+maciejhirsz@users.noreply.github.com> --- backend/src/node.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/src/node.rs b/backend/src/node.rs index 67aa43066..2c94c57aa 100644 --- a/backend/src/node.rs +++ b/backend/src/node.rs @@ -145,12 +145,16 @@ impl Node { let mut changed = false; if let Some(peers) = interval.peers { - self.stats.peers = peers; - changed = true; + if peers != self.stats.peers { + self.stats.peers = peers; + changed = true; + } } if let Some(txcount) = interval.txcount { - self.stats.txcount = txcount; - changed = true; + if txcoint != self.stats.txcount { + self.stats.txcount = txcount; + changed = true; + } } if changed { From a65250118e50ff7c805d28f73b8e9d0647c8c221 Mon Sep 17 00:00:00 2001 From: Roman Borschel Date: Mon, 14 Sep 2020 17:05:36 +0200 Subject: [PATCH 3/3] Update backend/src/node.rs --- backend/src/node.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/node.rs b/backend/src/node.rs index 2c94c57aa..740b6907a 100644 --- a/backend/src/node.rs +++ b/backend/src/node.rs @@ -151,7 +151,7 @@ impl Node { } } if let Some(txcount) = interval.txcount { - if txcoint != self.stats.txcount { + if txcount != self.stats.txcount { self.stats.txcount = txcount; changed = true; }