Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions backend/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,26 @@ 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 {
if peers != self.stats.peers {
self.stats.peers = peers;
changed = true;
}
}
if let Some(txcount) = interval.txcount {
if txcount != self.stats.txcount {
self.stats.txcount = txcount;
changed = true;
}
}

if changed {
Some(&self.stats)
} else {
None
}
}

pub fn update_io(&mut self, interval: &SystemInterval) -> Option<&NodeIO> {
Expand Down
13 changes: 6 additions & 7 deletions backend/src/node/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -63,14 +63,14 @@ pub struct SystemConnected {

#[derive(Deserialize, Debug)]
pub struct SystemInterval {
#[serde(flatten)]
pub stats: NodeStats,
pub peers: Option<u64>,
pub txcount: Option<u64>,
pub bandwidth_upload: Option<f64>,
pub bandwidth_download: Option<f64>,
pub finalized_height: Option<BlockNumber>,
pub finalized_hash: Option<BlockHash>,
#[serde(flatten)]
pub block: Block,
pub block: Option<Block>,
pub network_state: Option<IgnoredAny>,
pub used_state_cache_size: Option<f32>,
}
Expand Down Expand Up @@ -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,
}
}
Expand Down