Skip to content

Commit

Permalink
upgrade GO; decimal tx rate when < 1; prefer gwei to szabo (#72)
Browse files Browse the repository at this point in the history
* upgrade GO; decimal tx rate when < 1; prefer gwei to szabo

* upgrade dockerfile to go 1.16; upgrade lodash

* Dockerfile: drop bzr
  • Loading branch information
jmank88 authored Apr 9, 2021
1 parent 4fd169d commit ee3325e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Build in a stock Go builder container
FROM golang:1.13-alpine as builder
FROM golang:1.16-alpine as builder

RUN apk --no-cache add build-base git bzr mercurial gcc linux-headers npm
RUN apk --no-cache add build-base git mercurial gcc linux-headers npm
RUN npm install -g grunt-cli

ENV GENESIS_VERSION 0.2.1
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module github.com/gochain-io/netstats

go 1.13
go 1.16

require (
github.com/blendle/zapdriver v1.2.1
github.com/google/go-cmp v0.2.0
github.com/gorilla/websocket v1.4.0
github.com/shopspring/decimal v1.2.0
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce
go.uber.org/multierr v1.2.0 // indirect
go.uber.org/zap v1.11.0
Expand Down
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
github.com/blendle/zapdriver v1.2.1 h1:CwapMXZCok+D9b/FuVF82Mwf4GfxffJIeJKZ1Mhm4Rg=
github.com/blendle/zapdriver v1.2.1/go.mod h1:mdXfREi6u5MArG4j9fewC+FGnXaBR+T4Ox4J2u4eHCc=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -12,18 +11,18 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce h1:fb190+cK2Xz/dvi9Hv8eCYJYvIGUTN2/KLq1pT6CjEc=
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce/go.mod h1:o8v6yHRoik09Xen7gje4m9ERNah1d1PPsVq1VEx9vE4=
go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.2.0 h1:6I+W7f5VwC5SV9dNrZ3qXrDB9mD0dyGOi/ZJmYw03T4=
go.uber.org/multierr v1.2.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.11.0 h1:gSmpCfs+R47a4yQPAI4xJ0IPDLTRGXskm6UelqNXpqE=
go.uber.org/zap v1.11.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
11 changes: 9 additions & 2 deletions netstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sort"
"strconv"

"github.com/shopspring/decimal"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
Expand Down Expand Up @@ -574,7 +575,13 @@ func (bc *Blockchain) Chart() *Chart {
chart.Miners = bc.MinersCount()
chart.Propagation = bc.BlockPropagation()
if len(bc.blocks) > 0 && sumTime >= 1000 {
chart.AvgTransactionRate = transactionCount / (int(sumTime) / 1000)
avgTransactionRate := decimal.NewFromInt(int64(transactionCount)).
Div(decimal.New(sumTime, -3))
if avgTransactionRate.LessThan(decimal.NewFromInt(1)) {
chart.AvgTransactionRate = json.Number(avgTransactionRate.StringFixed(2))
} else {
chart.AvgTransactionRate = json.Number(avgTransactionRate.StringFixed(0))
}
chart.AvgHashRate = (bc.blocks[len(bc.blocks)-1].Difficulty / (int(sumTime) / len(bc.blocks)) / 1000)
}

Expand Down Expand Up @@ -633,7 +640,7 @@ type Chart struct {
Miners []*ChartMiner `json:"miners"`
UncleCount []int `json:"uncleCount"`
AvgHashRate int `json:"avgHashrate"`
AvgTransactionRate int `json:"avgTransactionRate"`
AvgTransactionRate json.Number `json:"avgTransactionRate"`

Propagation *BlockPropagationStats `json:"propagation"`
}
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"grunt-contrib-jade": "^0.14.1",
"grunt-contrib-uglify": "^0.9.1",
"jade": "1.11.0",
"lodash": "4.17.13",
"lodash": "4.17.19",
"primus": "^6.0.5",
"primus-emit": "^1.0.0",
"primus-spark-latency": "^0.1.1",
Expand Down
18 changes: 11 additions & 7 deletions src/js/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ angular.module('netStatsApp.filters', [])
return numberFilter(price/1000000000) + " gwei";

if(price.length < 16)
return numberFilter(price/1000000000000) + " szabo";
return numberFilter(price/1000000000) + " gwei"; // prefer > 1000 gwei over szabo
// return numberFilter(price/1000000000000) + " szabo";

if(price.length < 19)
return numberFilter(price.substr(0, price.length - 15)) + " finney";
Expand Down Expand Up @@ -232,21 +233,24 @@ angular.module('netStatsApp.filters', [])
if (rate === null)
rate = 0;

var result = 0;
var result = '0';
var unit = '';

if (rate < 10000) {
result = rate;
if (rate < 1) {
result = rate.toFixed(2);
unit = '';
} else if (rate < 10000) {
result = rate.toFixed(0);
unit = '';
} else if (rate < Math.pow(1000, 2)) {
result = rate / 1000;
result = (rate / 1000).toFixed(0);
unit = 'K';
} else if (rate >= Math.pow(1000, 2)) { // keeping the condition to cover the zero case
result = rate / Math.pow(1000, 2);
result = (rate / Math.pow(1000, 2)).toFixed(0);
unit = 'M';
}

return $sce.trustAsHtml(filter('number')(result.toFixed(0)) + ' <span class="small-hash">' + unit + 'tx/s</span>');
return $sce.trustAsHtml(filter('number')(result) + ' <span class="small-hash">' + unit + 'tx/s</span>');
};
}])
.filter('latencyCellFilter', function() {
Expand Down

0 comments on commit ee3325e

Please sign in to comment.