Skip to content

Commit

Permalink
fix: network section
Browse files Browse the repository at this point in the history
  • Loading branch information
mistakia committed Mar 10, 2024
1 parent 845a3f3 commit 94bc24b
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 52 deletions.
29 changes: 19 additions & 10 deletions src/core/network/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function getNetworkWattHour(state) {
const network = getNetwork(state)
const accounts = getAccountItems(state)

const peers = network.getIn(['stats', 'peers'], [])
const peers = network.getIn(['stats', 'nanobrowse_monitors'], [])
const prs = peers.filter((p) => p.PR)
let sum = 0
for (const pr of prs) {
Expand All @@ -24,35 +24,44 @@ export function getNetworkWattHour(state) {

export function getNetworkStats(state) {
const network = getNetwork(state)
const quorumTotal = BigNumber(network.getIn(['weight', 'quorumTotal'], 0))
const quorum_total = BigNumber(network.getIn(['weight', 'quorumTotal'], 0))
.shiftedBy(-30)
.toNumber()
const onlineWeight = BigNumber(
const online_weight = BigNumber(
network.getIn(['weight', 'onlineWeight', 'median'], 0)
)
.shiftedBy(-30)
.toNumber()
const trendedWeight = BigNumber(
const trended_weight = BigNumber(
network.getIn(['weight', 'trendedWeight', 'median'], 0)
)
.shiftedBy(-30)
.toNumber()

const stats = network.get('stats', {})
const prs = network
.getIn(['stats', 'peers'], [])
.getIn(['stats', 'nanobrowse_monitors'], [])
.filter((p) => p.PR)
.sort((a, b) => b.weight - a.weight)

const confirmLimit = quorumTotal * 0.67
const censorLimit =
quorumTotal * 0.33 - Math.max(0, trendedWeight - onlineWeight)
if (prs.length === 0) {
return {
...stats,
prCount: 0,
censorReps: 0,
confirmReps: 0
}
}

const confirm_limit = quorum_total * 0.67
const censor_limit =
quorum_total * 0.33 - Math.max(0, trended_weight - online_weight)

let sum = 0
let c = 0
let i = 0
for (; c < prs.length && sum < confirmLimit; c++) {
if (sum < censorLimit) {
for (; c < prs.length && sum < confirm_limit; c++) {
if (sum < censor_limit) {
i = c
}
sum += prs[c].weight
Expand Down
109 changes: 67 additions & 42 deletions src/views/components/network/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class Network extends React.Component {
const confirmationsText =
'Total number of transactions confirmed by the network over the last 24 hours'
const settlementText =
'Total amount of value settled by the network over the last 24 hours'
'Total amount of value settled by the network over the last 24 hours (only send blocks)'
const throughputText = `Median number of transactions confirmed per second in the last minute ${prText}`
const speedText =
'Median time in seconds for a block to get confirmed (across all buckets)'
Expand All @@ -51,12 +51,15 @@ export default class Network extends React.Component {
</Tooltip>
</div>
<div>
{formatNumber(
network.getIn(
['stats', 'nanodb', 'confirmations_last_24_hours'],
0
)
)}
{network.getIn(['stats', 'nanodb', 'confirmations_last_24_hours'])
? formatNumber(
network.getIn([
'stats',
'nanodb',
'confirmations_last_24_hours'
])
)
: '-'}
</div>
</div>
<div className='network__stat'>
Expand All @@ -67,13 +70,14 @@ export default class Network extends React.Component {
</Tooltip>
</div>
<div>
$
{formatNumber(
(
send_volume_nano *
network.getIn(['stats', 'current_price_usd'], 0)
).toFixed(0)
)}
{network.getIn(['stats', 'current_price_usd'])
? `$${formatNumber(
(
send_volume_nano *
network.getIn(['stats', 'current_price_usd'])
).toFixed(0)
)}`
: '-'}
</div>
</div>
<div className='network__stat'>
Expand All @@ -94,7 +98,11 @@ export default class Network extends React.Component {
</div>
<div>
{/* TODO remove this nanoticker dependency */}
{network.getIn(['stats', 'CPSMedian_pr'], 0).toFixed(1)} CPS
{network.getIn(['stats', 'nanobrowse', 'CPSMedian_pr'])
? `${network
.getIn(['stats', 'nanobrowse', 'CPSMedian_pr'])
.toFixed(1)} CPS`
: '-'}
</div>
</div>
<div className='network__stat'>
Expand All @@ -104,15 +112,18 @@ export default class Network extends React.Component {
<HelpOutlineIcon fontSize='inherit' />
</Tooltip>
</div>
{/* TODO remove this nanoticker dependency */}
<div>
{Math.round(
network.getIn(
['stats', 'nanodb', 'median_latency_ms_last_24_hours'],
0
) / 1000
)}{' '}
s
{network.getIn(
['stats', 'nanodb', 'median_latency_ms_last_24_hours'],
0
)
? `${Math.round(
network.getIn(
['stats', 'nanodb', 'median_latency_ms_last_24_hours'],
0
) / 1000
)} s`
: '-'}
</div>
</div>
<div className='network__stat'>
Expand All @@ -122,15 +133,18 @@ export default class Network extends React.Component {
<HelpOutlineIcon fontSize='inherit' />
</Tooltip>
</div>
{/* TODO remove this nanoticker dependency */}
<div>
{Math.round(
network.getIn(
['stats', 'nanodb', 'median_latency_ms_last_hour'],
0
) / 1000
)}{' '}
s
{network.getIn(
['stats', 'nanodb', 'median_latency_ms_last_hour'],
0
)
? `${Math.round(
network.getIn(
['stats', 'nanodb', 'median_latency_ms_last_hour'],
0
) / 1000
)} s`
: '-'}
</div>
</div>
<div className='network__stat'>
Expand All @@ -140,15 +154,18 @@ export default class Network extends React.Component {
<HelpOutlineIcon fontSize='inherit' />
</Tooltip>
</div>
{/* TODO remove this nanoticker dependency */}
<div>
{Math.round(
network.getIn(
['stats', 'nanodb', 'median_latency_ms_last_10_mins'],
0
) / 1000
)}{' '}
s
{network.getIn(
['stats', 'nanodb', 'median_latency_ms_last_10_mins'],
0
)
? `${Math.round(
network.getIn(
['stats', 'nanodb', 'median_latency_ms_last_10_mins'],
0
) / 1000
)} s`
: '-'}
</div>
</div>
<div className='network__stat'>
Expand All @@ -159,7 +176,11 @@ export default class Network extends React.Component {
</Tooltip>
</div>
{/* TODO remove this nanoticker dependency */}
<div>{formatNumber(unconfirmed_block_pool_count || 0)}</div>
<div>
{unconfirmed_block_pool_count != null
? formatNumber(unconfirmed_block_pool_count)
: '-'}
</div>
</div>
<div className='network__stat'>
<div>
Expand All @@ -170,7 +191,11 @@ export default class Network extends React.Component {
</div>
<div>
{/* TODO remove this nanoticker dependency */}
{network.getIn(['stats', 'pStakeTotalStat'], 0).toFixed(1)}%
{network.getIn(['stats', 'nanobrowse', 'pStakeTotalStat'])
? `${network
.getIn(['stats', 'nanobrowse', 'pStakeTotalStat'])
.toFixed(1)}%`
: '-'}
</div>
</div>
<div className='network__stat'>
Expand All @@ -183,7 +208,7 @@ export default class Network extends React.Component {
</div>
<div className='network__stat'>
<div>Peers</div>
<div>{network.getIn(['stats', 'peersMax'], '-')}</div>
<div>{network.getIn(['stats', 'nanobrowse', 'peersMax'], '-')}</div>
</div>
<div className='network__stat'>
<div>
Expand Down

0 comments on commit 94bc24b

Please sign in to comment.