Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Commit

Permalink
feat: move uptime calculation stragglers into API
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnygleason committed Dec 23, 2019
1 parent 8eba3de commit 44e7330
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 33 deletions.
11 changes: 10 additions & 1 deletion api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {FriendlyGet} from './friendlyGet';
import config from './config';
import {addNetworkExplorerRoutes} from './network-explorer';
import {FULLNODE_URL} from './fullnode-url';
import {lamportsToSol} from './util';
import {calculateUptimeValues, lamportsToSol} from './util';

const GLOBAL_STATS_BROADCAST_INTERVAL_MS = 2000;
const CLUSTER_INFO_BROADCAST_INTERVAL_MS = 5000;
Expand Down Expand Up @@ -579,6 +579,8 @@ async function getClusterInfo() {
feeCalculator,
inflation,
currentSlot,
epochInfo,
epochSchedule,
supply,
clusterNodes,
leader,
Expand All @@ -589,6 +591,8 @@ async function getClusterInfo() {
.with('feeCalculator', connection.getRecentBlockhash())
.with('inflation', connection.getInflation())
.with('currentSlot', getAsync('!blk-last-slot'))
.with('epochInfo', connection.getEpochInfo())
.with('epochSchedule', connection.getEpochSchedule())
.with('supply', connection.getTotalSupply())
.with('clusterNodes', connection.getClusterNodes(), [])
.with('leader', connection.getSlotLeader())
Expand Down Expand Up @@ -695,6 +699,11 @@ async function getClusterInfo() {
node.votePubkey = votePubkey;
node.identity = _.find(identities, x => x.pubkey === nodePubkey);
node.uptime = _.find(uptime, x => x.nodePubkey === nodePubkey);
node.uptimeStats = calculateUptimeValues(
epochInfo,
epochSchedule,
node.uptime && node.uptime.uptime,
);

node.voteStatus =
_.find(voteAccounts.current, x => x.nodePubkey === nodePubkey) ||
Expand Down
19 changes: 17 additions & 2 deletions src/v2/components/Validators/Detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import ValidatorsMap from 'v2/components/ValidatorsMap';
import InfoRow from 'v2/components/InfoRow';

import useStyles from './styles';
import Uptime from '../../UI/Uptime';

const ValidatorsDetail = ({match}: {match: Match}) => {
const {validators, inactiveValidators} = NodesStore;
Expand Down Expand Up @@ -42,9 +43,16 @@ const ValidatorsDetail = ({match}: {match: Match}) => {
identity = {},
stakedSol,
stakedSolPercent,
calcUptime,
uptimeStats,
} = node;

const {
lastEpochUptimePercent,
cumulativeUptimePercent,
uptimeEpochs,
uptimeComplete,
} = uptimeStats || {};

const specs = [
{
label: 'Address',
Expand Down Expand Up @@ -73,7 +81,14 @@ const ValidatorsDetail = ({match}: {match: Match}) => {
{
label: 'Uptime',
hint: '',
value: `${calcUptime}%`,
value: (
<Uptime
lastEpochUptimePercent={lastEpochUptimePercent}
cumulativeUptimePercent={cumulativeUptimePercent}
uptimeEpochs={uptimeEpochs}
uptimeComplete={uptimeComplete}
/>
),
},
{
label: 'keybase',
Expand Down
35 changes: 31 additions & 4 deletions src/v2/components/Validators/Table/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import ValidatorName from 'v2/components/UI/ValidatorName';
import TableCard from 'v2/components/UI/TableCard';

import useStyles from './styles';
import Uptime from '../../UI/Uptime';

const fields = [
{
Expand Down Expand Up @@ -76,8 +77,14 @@ const ValidatorsTable = ({separate}: {separate: boolean}) => {
stakedSol,
stakedSolPercent,
calcCommission,
calcUptime,
uptimeStats,
} = row;
const {
lastEpochUptimePercent,
cumulativeUptimePercent,
uptimeEpochs,
uptimeComplete,
} = uptimeStats || {};
return (
<TableRow hover key={nodePubkey}>
<TableCell>
Expand All @@ -91,7 +98,14 @@ const ValidatorsTable = ({separate}: {separate: boolean}) => {
<div>{stakedSol ? `${stakedSol} (${stakedSolPercent}%)` : 'N/A'}</div>
</TableCell>
<TableCell>{calcCommission ? `${calcCommission}%` : 'N/A'}</TableCell>
<TableCell>{calcUptime ? `${calcUptime}%` : 'Unavailable'}</TableCell>
<TableCell>
<Uptime
lastEpochUptimePercent={lastEpochUptimePercent}
cumulativeUptimePercent={cumulativeUptimePercent}
uptimeEpochs={uptimeEpochs}
uptimeComplete={uptimeComplete}
/>
</TableCell>
</TableRow>
);
};
Expand All @@ -102,8 +116,14 @@ const ValidatorsTable = ({separate}: {separate: boolean}) => {
stakedSol,
stakedSolPercent,
calcCommission,
calcUptime,
uptimeStats,
} = card;
const {
lastEpochUptimePercent,
cumulativeUptimePercent,
uptimeEpochs,
uptimeComplete,
} = uptimeStats || {};
const data = [
{
label: 'Name',
Expand All @@ -125,7 +145,14 @@ const ValidatorsTable = ({separate}: {separate: boolean}) => {
},
{
label: 'Uptime',
value: calcUptime ? `${calcUptime}%` : 'Unavailable',
value: (
<Uptime
lastEpochUptimePercent={lastEpochUptimePercent}
cumulativeUptimePercent={cumulativeUptimePercent}
uptimeEpochs={uptimeEpochs}
uptimeComplete={uptimeComplete}
/>
),
},
];
return <TableCard vertical={separate} key={nodePubkey} data={data} />;
Expand Down
21 changes: 18 additions & 3 deletions src/v2/components/ValidatorsMap/Marker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Avatar from 'v2/components/UI/Avatar';
import ValidatorName from 'v2/components//UI/ValidatorName';

import useStyles from './styles';
import Uptime from '../UI/Uptime';

const Marker = ({scale, marker}: {scale: number, marker: any}) => {
const classes = useStyles();
Expand All @@ -13,11 +14,16 @@ const Marker = ({scale, marker}: {scale: number, marker: any}) => {
nodePubkey,
identity = {},
calcCommission,
calcUptime,
uptimeStats,
stakedSol,
stakedSolPercent,
} = marker;

const {
lastEpochUptimePercent,
cumulativeUptimePercent,
uptimeEpochs,
uptimeComplete,
} = uptimeStats || {};
return (
<MapTooltip
classes={{tooltip: classes.tooltip}}
Expand All @@ -36,7 +42,16 @@ const Marker = ({scale, marker}: {scale: number, marker: any}) => {
<div>
Commission: {calcCommission ? `${calcCommission}%` : 'N/A'}
</div>
<div>Uptime: {calcUptime ? `${calcUptime}%` : 'Unavailable'}</div>
<div>
{' '}
Uptime:{' '}
<Uptime
lastEpochUptimePercent={lastEpochUptimePercent}
cumulativeUptimePercent={cumulativeUptimePercent}
uptimeEpochs={uptimeEpochs}
uptimeComplete={uptimeComplete}
/>
</div>
</div>
</div>
)}
Expand Down
12 changes: 2 additions & 10 deletions src/v2/stores/nodes.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import {filter, reject, map} from 'lodash/fp';
import {filter, reject} from 'lodash/fp';
import {action, computed, decorate, observable, flow} from 'mobx';
import * as API from 'v2/api/stats';
import getUptime from 'v2/utils/getUptime';

const addNetworkSolInfo = () => node => ({
...node,
calcUptime: getUptime(node.uptime),
});

class Store {
network = [];
Expand All @@ -15,9 +9,7 @@ class Store {
if (typeof data === 'string') {
data = JSON.parse(data);
}
this.network = data.network
? map(addNetworkSolInfo(data.totalStaked))(data.network)
: [];
this.network = data.network || [];
this.totalStaked = data.totalStaked;
this.totalStakedSol = data.totalStakedSol;
this.supply = data.supply;
Expand Down
13 changes: 0 additions & 13 deletions src/v2/utils/getUptime.js

This file was deleted.

0 comments on commit 44e7330

Please sign in to comment.