diff --git a/backend/src/aggregator.rs b/backend/src/aggregator.rs index ff8ab47..cb0c91e 100644 --- a/backend/src/aggregator.rs +++ b/backend/src/aggregator.rs @@ -290,7 +290,7 @@ impl Handler for Aggregator { connector.do_send(Connected(fid)); - self.serializer.push(feed::Version(30)); + self.serializer.push(feed::Version(31)); // TODO: keep track on number of nodes connected to each chain for (_, entry) in self.chains.iter() { diff --git a/backend/src/feed.rs b/backend/src/feed.rs index 5f5227d..aeb6216 100644 --- a/backend/src/feed.rs +++ b/backend/src/feed.rs @@ -172,7 +172,7 @@ impl Serialize for AddedNode<'_> { tup.serialize_element(node.hardware())?; tup.serialize_element(node.block_details())?; tup.serialize_element(&node.location())?; - tup.serialize_element(&node.connected_at())?; + tup.serialize_element(&node.startup_time())?; tup.end() } } diff --git a/backend/src/node.rs b/backend/src/node.rs index b239d33..e3e6563 100644 --- a/backend/src/node.rs +++ b/backend/src/node.rs @@ -33,16 +33,19 @@ pub struct Node { location: Option>, /// Flag marking if the node is stale (not syncing or producing blocks) stale: bool, - /// Connected at timestamp - connected_at: Timestamp, + /// Unix timestamp for when node started up (falls back to connection time) + startup_time: Option, /// Network state network_state: Option, } impl Node { - pub fn new(details: NodeDetails) -> Self { - Node { + pub fn new(mut details: NodeDetails) -> Self { + let startup_time = details.startup_time + .take() + .and_then(|time| time.parse().ok()); + Node { details, stats: NodeStats::default(), io: NodeIO::default(), @@ -52,7 +55,7 @@ impl Node { hardware: NodeHardware::default(), location: None, stale: false, - connected_at: now(), + startup_time, network_state: None, } } @@ -230,7 +233,7 @@ impl Node { } } - pub fn connected_at(&self) -> Timestamp { - self.connected_at + pub fn startup_time(&self) -> Option { + self.startup_time } } diff --git a/backend/src/node/connector.rs b/backend/src/node/connector.rs index d6f09bb..c39c69c 100644 --- a/backend/src/node/connector.rs +++ b/backend/src/node/connector.rs @@ -161,7 +161,6 @@ impl StreamHandler> for NodeConnector { match serde_json::from_slice(&data) { Ok(msg) => { - // info!("New node message: {}", std::str::from_utf8(&data).unwrap_or_else(|_| "INVALID UTF8")); self.handle_message(msg, data, ctx) }, #[cfg(debug)] diff --git a/backend/src/node/message.rs b/backend/src/node/message.rs index 80e56b1..f310f23 100644 --- a/backend/src/node/message.rs +++ b/backend/src/node/message.rs @@ -8,18 +8,11 @@ use crate::types::{Block, BlockNumber, BlockHash}; #[derive(Deserialize, Debug, Message)] #[rtype(result = "()")] pub struct NodeMessage { - pub level: Level, pub ts: DateTime, #[serde(flatten)] pub details: Details, } -#[derive(Deserialize, Debug)] -pub enum Level { - #[serde(rename = "INFO")] - Info, -} - #[derive(Deserialize, Debug)] #[serde(tag = "msg")] pub enum Details { diff --git a/backend/src/types.rs b/backend/src/types.rs index 585cf98..0488987 100644 --- a/backend/src/types.rs +++ b/backend/src/types.rs @@ -17,6 +17,7 @@ pub struct NodeDetails { pub version: Box, pub validator: Option>, pub network_id: Option>, + pub startup_time: Option>, } #[derive(Deserialize, Debug, Clone, Copy, PartialEq, Eq, Default)] diff --git a/frontend/src/Connection.ts b/frontend/src/Connection.ts index a2ea557..83ca69e 100644 --- a/frontend/src/Connection.ts +++ b/frontend/src/Connection.ts @@ -204,7 +204,7 @@ export class Connection { nodeHardware, blockDetails, location, - connectedAt, + startupTime, ] = message.payload; const pinned = this.pins.has(nodeDetails[0]); const node = new Node( @@ -216,7 +216,7 @@ export class Connection { nodeHardware, blockDetails, location, - connectedAt + startupTime ); nodes.add(node); diff --git a/frontend/src/common/feed.ts b/frontend/src/common/feed.ts index 2bc0ce5..04ce2b9 100644 --- a/frontend/src/common/feed.ts +++ b/frontend/src/common/feed.ts @@ -80,7 +80,7 @@ export namespace Variants { NodeHardware, BlockDetails, Maybe, - Timestamp + Maybe ]; } diff --git a/frontend/src/common/index.ts b/frontend/src/common/index.ts index e7db83d..9a3e98c 100644 --- a/frontend/src/common/index.ts +++ b/frontend/src/common/index.ts @@ -9,4 +9,4 @@ import * as FeedMessage from './feed'; export { Types, FeedMessage }; // Increment this if breaking changes were made to types in `feed.ts` -export const VERSION: Types.FeedVersion = 30 as Types.FeedVersion; +export const VERSION: Types.FeedVersion = 31 as Types.FeedVersion; diff --git a/frontend/src/components/List/Column/UptimeColumn.tsx b/frontend/src/components/List/Column/UptimeColumn.tsx index d596dca..d46d39d 100644 --- a/frontend/src/components/List/Column/UptimeColumn.tsx +++ b/frontend/src/components/List/Column/UptimeColumn.tsx @@ -9,7 +9,7 @@ export class UptimeColumn extends React.Component { public static readonly icon = icon; public static readonly width = 58; public static readonly setting = 'uptime'; - public static readonly sortBy = ({ connectedAt }: Node) => connectedAt || 0; + public static readonly sortBy = ({ startupTime }: Node) => startupTime || 0; public shouldComponentUpdate(nextProps: Column.Props) { // Uptime only changes when the node does @@ -17,11 +17,15 @@ export class UptimeColumn extends React.Component { } render() { - const { connectedAt } = this.props.node; + const { startupTime } = this.props.node; + + if (!startupTime) { + return -; + } return ( - + ); } diff --git a/frontend/src/state.ts b/frontend/src/state.ts index fc5856d..b5e6e81 100644 --- a/frontend/src/state.ts +++ b/frontend/src/state.ts @@ -43,7 +43,7 @@ export class Node { public readonly version: Types.NodeVersion; public readonly validator: Maybe; public readonly networkId: Maybe; - public readonly connectedAt: Types.Timestamp; + public readonly startupTime: Maybe; public readonly sortableName: string; public readonly sortableVersion: number; @@ -82,7 +82,7 @@ export class Node { nodeHardware: Types.NodeHardware, blockDetails: Types.BlockDetails, location: Maybe, - connectedAt: Types.Timestamp + startupTime: Maybe ) { const [name, implementation, version, validator, networkId] = nodeDetails; @@ -94,7 +94,7 @@ export class Node { this.version = version; this.validator = validator; this.networkId = networkId; - this.connectedAt = connectedAt; + this.startupTime = startupTime; const [major = 0, minor = 0, patch = 0] = (version || '0.0.0') .split('.')