Browse Source

Merge pull request #80 from tendermint/update-monitor-and-bench-2

Update tm-bench
pull/1943/head
Anton Kaliaev 7 years ago
committed by GitHub
parent
commit
a66b20aff4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 442 additions and 190 deletions
  1. +3
    -3
      tm-bench/Dockerfile.dev
  2. +283
    -0
      tm-bench/Gopkg.lock
  3. +58
    -0
      tm-bench/Gopkg.toml
  4. +78
    -10
      tm-bench/Makefile
  5. +0
    -134
      tm-bench/glide.lock
  6. +0
    -20
      tm-bench/glide.yaml
  7. +4
    -3
      tm-bench/main.go
  8. +0
    -1
      tm-monitor/.dockerignore
  9. +1
    -4
      tm-monitor/Dockerfile.dev
  10. +1
    -1
      tm-monitor/main.go
  11. +1
    -1
      tm-monitor/monitor/monitor.go
  12. +4
    -4
      tm-monitor/monitor/network.go
  13. +1
    -1
      tm-monitor/monitor/network_test.go
  14. +5
    -5
      tm-monitor/monitor/node.go
  15. +3
    -3
      tm-monitor/monitor/node_test.go

+ 3
- 3
tm-bench/Dockerfile.dev View File

@ -4,9 +4,9 @@ RUN mkdir -p /go/src/github.com/tendermint/tools/tm-bench
WORKDIR /go/src/github.com/tendermint/tools/tm-bench WORKDIR /go/src/github.com/tendermint/tools/tm-bench
COPY Makefile /go/src/github.com/tendermint/tools/tm-bench/ COPY Makefile /go/src/github.com/tendermint/tools/tm-bench/
COPY glide.yaml /go/src/github.com/tendermint/tools/tm-bench/
COPY glide.lock /go/src/github.com/tendermint/tools/tm-bench/
RUN make get_vendor_deps
RUN make get_tools
COPY . /go/src/github.com/tendermint/tools/tm-bench COPY . /go/src/github.com/tendermint/tools/tm-bench
RUN make get_vendor_deps

+ 283
- 0
tm-bench/Gopkg.lock View File

@ -0,0 +1,283 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
branch = "master"
name = "github.com/btcsuite/btcd"
packages = ["btcec"]
revision = "2be2f12b358dc57d70b8f501b00be450192efbc3"
[[projects]]
branch = "master"
name = "github.com/ebuchman/fail-test"
packages = ["."]
revision = "95f809107225be108efcf10a3509e4ea6ceef3c4"
[[projects]]
name = "github.com/go-kit/kit"
packages = [
"log",
"log/level",
"log/term"
]
revision = "4dc7be5d2d12881735283bcab7352178e190fc71"
version = "v0.6.0"
[[projects]]
name = "github.com/go-logfmt/logfmt"
packages = ["."]
revision = "390ab7935ee28ec6b286364bba9b4dd6410cb3d5"
version = "v0.3.0"
[[projects]]
name = "github.com/go-stack/stack"
packages = ["."]
revision = "259ab82a6cad3992b4e21ff5cac294ccb06474bc"
version = "v1.7.0"
[[projects]]
name = "github.com/gogo/protobuf"
packages = [
"gogoproto",
"jsonpb",
"proto",
"protoc-gen-gogo/descriptor",
"sortkeys",
"types"
]
revision = "1adfc126b41513cc696b209667c8656ea7aac67c"
version = "v1.0.0"
[[projects]]
name = "github.com/golang/protobuf"
packages = [
"proto",
"ptypes",
"ptypes/any",
"ptypes/duration",
"ptypes/timestamp"
]
revision = "925541529c1fa6821df4e44ce2723319eb2be768"
version = "v1.0.0"
[[projects]]
branch = "master"
name = "github.com/golang/snappy"
packages = ["."]
revision = "553a641470496b2327abcac10b36396bd98e45c9"
[[projects]]
name = "github.com/gorilla/websocket"
packages = ["."]
revision = "ea4d1f681babbce9545c9c5f3d5194a789c89f5b"
version = "v1.2.0"
[[projects]]
branch = "master"
name = "github.com/jmhodges/levigo"
packages = ["."]
revision = "c42d9e0ca023e2198120196f842701bb4c55d7b9"
[[projects]]
branch = "master"
name = "github.com/kr/logfmt"
packages = ["."]
revision = "b84e30acd515aadc4b783ad4ff83aff3299bdfe0"
[[projects]]
name = "github.com/pkg/errors"
packages = ["."]
revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
version = "v0.8.0"
[[projects]]
branch = "master"
name = "github.com/rcrowley/go-metrics"
packages = ["."]
revision = "8732c616f52954686704c8645fe1a9d59e9df7c1"
[[projects]]
branch = "master"
name = "github.com/syndtr/goleveldb"
packages = [
"leveldb",
"leveldb/cache",
"leveldb/comparer",
"leveldb/errors",
"leveldb/filter",
"leveldb/iterator",
"leveldb/journal",
"leveldb/memdb",
"leveldb/opt",
"leveldb/storage",
"leveldb/table",
"leveldb/util"
]
revision = "714f901b98fdb3aa954b4193d8cbd64a28d80cad"
[[projects]]
name = "github.com/tendermint/abci"
packages = [
"client",
"example/code",
"example/kvstore",
"types"
]
revision = "46686763ba8ea595ede16530ed4a40fb38f49f94"
version = "v0.10.2"
[[projects]]
branch = "master"
name = "github.com/tendermint/ed25519"
packages = [
".",
"edwards25519",
"extra25519"
]
revision = "d8387025d2b9d158cf4efb07e7ebf814bcce2057"
[[projects]]
name = "github.com/tendermint/go-crypto"
packages = ["."]
revision = "c3e19f3ea26f5c3357e0bcbb799b0761ef923755"
version = "v0.5.0"
[[projects]]
name = "github.com/tendermint/go-wire"
packages = [
".",
"data"
]
revision = "fa721242b042ecd4c6ed1a934ee740db4f74e45c"
source = "github.com/tendermint/go-amino"
version = "v0.7.3"
[[projects]]
name = "github.com/tendermint/tendermint"
packages = [
"config",
"consensus/types",
"p2p",
"p2p/conn",
"p2p/upnp",
"proxy",
"rpc/core/types",
"rpc/lib/client",
"rpc/lib/types",
"state",
"types",
"wire"
]
revision = "6f9956990c444d53f62f2a3905ed410cfe9afe77"
version = "v0.17.1"
[[projects]]
branch = "master"
name = "github.com/tendermint/tmlibs"
packages = [
"common",
"db",
"events",
"flowrate",
"log",
"merkle",
"pubsub",
"pubsub/query"
]
revision = "24da7009c3d8c019b40ba4287495749e3160caca"
[[projects]]
branch = "master"
name = "github.com/tendermint/tools"
packages = [
"tm-monitor/eventmeter",
"tm-monitor/monitor"
]
revision = "62965e68f13de80f196bea194ed4a3dbfcf4048b"
[[projects]]
branch = "master"
name = "golang.org/x/crypto"
packages = [
"curve25519",
"nacl/box",
"nacl/secretbox",
"openpgp/armor",
"openpgp/errors",
"poly1305",
"ripemd160",
"salsa20/salsa"
]
revision = "12892e8c234f4fe6f6803f052061de9057903bb2"
[[projects]]
branch = "master"
name = "golang.org/x/net"
packages = [
"context",
"http2",
"http2/hpack",
"idna",
"internal/timeseries",
"lex/httplex",
"trace"
]
revision = "b68f30494add4df6bd8ef5e82803f308e7f7c59c"
[[projects]]
name = "golang.org/x/text"
packages = [
"collate",
"collate/build",
"internal/colltab",
"internal/gen",
"internal/tag",
"internal/triegen",
"internal/ucd",
"language",
"secure/bidirule",
"transform",
"unicode/bidi",
"unicode/cldr",
"unicode/norm",
"unicode/rangetable"
]
revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
version = "v0.3.0"
[[projects]]
branch = "master"
name = "google.golang.org/genproto"
packages = ["googleapis/rpc/status"]
revision = "ab0870e398d5dd054b868c0db1481ab029b9a9f2"
[[projects]]
name = "google.golang.org/grpc"
packages = [
".",
"balancer",
"codes",
"connectivity",
"credentials",
"grpclb/grpc_lb_v1/messages",
"grpclog",
"internal",
"keepalive",
"metadata",
"naming",
"peer",
"resolver",
"stats",
"status",
"tap",
"transport"
]
revision = "5b3c4e850e90a4cf6a20ebd46c8b32a0a3afcb9e"
version = "v1.7.5"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "9e81caf774c988dc43578eac01f7b783d5179226a14e60b31db5d50a29cf633f"
solver-name = "gps-cdcl"
solver-version = 1

+ 58
- 0
tm-bench/Gopkg.toml View File

@ -0,0 +1,58 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true
[[constraint]]
name = "github.com/go-kit/kit"
version = "^0.6.0"
[[constraint]]
name = "github.com/gorilla/websocket"
version = "1.2.0"
[[constraint]]
name = "github.com/pkg/errors"
version = "0.8.0"
[[constraint]]
branch = "master"
name = "github.com/rcrowley/go-metrics"
[[constraint]]
name = "github.com/tendermint/tendermint"
version = "0.17.1"
[[constraint]]
name = "github.com/tendermint/tmlibs"
version = "0.7.1"
[[constraint]]
name = "github.com/tendermint/tools"
branch = "master"
[prune]
go-tests = true
unused-packages = true

+ 78
- 10
tm-bench/Makefile View File

@ -1,25 +1,49 @@
DIST_DIRS := find * -type d -exec DIST_DIRS := find * -type d -exec
VERSION := $(shell perl -ne '/^var version.*"([^"]+)".*$$/ && print "v$$1\n"' main.go) VERSION := $(shell perl -ne '/^var version.*"([^"]+)".*$$/ && print "v$$1\n"' main.go)
GOTOOLS = \ GOTOOLS = \
github.com/mitchellh/gox
github.com/mitchellh/gox \
github.com/golang/dep/cmd/dep \
gopkg.in/alecthomas/gometalinter.v2
tools:
go get $(GOTOOLS)
all: check get_vendor_deps build test install metalinter
check: check_tools
########################################
### Tools & dependencies
check_tools:
@# https://stackoverflow.com/a/25668869
@echo "Found tools: $(foreach tool,$(GOTOOLS_CHECK),\
$(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"
get_tools:
@echo "--> Installing tools"
go get -u -v $(GOTOOLS)
@gometalinter.v2 --install
update_tools:
@echo "--> Updating tools"
@go get -u $(GOTOOLS)
get_vendor_deps: get_vendor_deps:
@hash glide 2>/dev/null || go get github.com/Masterminds/glide
glide install
@rm -rf vendor/
@echo "--> Running dep ensure"
@dep ensure
########################################
### Build
build: build:
go build
@go build
install: install:
go install
@go install
test: test:
go test -race
@go test -race
build-all: tools
build-all: check_tools
rm -rf ./dist rm -rf ./dist
gox -verbose \ gox -verbose \
-ldflags "-s -w" \ -ldflags "-s -w" \
@ -36,6 +60,9 @@ dist: build-all
shasum -a256 ./*.tar.gz > "./tm-bench_${VERSION}_SHA256SUMS" && \ shasum -a256 ./*.tar.gz > "./tm-bench_${VERSION}_SHA256SUMS" && \
cd .. cd ..
########################################
### Docker
build-docker: build-docker:
rm -f ./tm-bench rm -f ./tm-bench
docker run -it --rm -v "$(PWD):/go/src/app" -w "/go/src/app" -e "CGO_ENABLED=0" golang:alpine go build -ldflags "-s -w" -o tm-bench docker run -it --rm -v "$(PWD):/go/src/app" -w "/go/src/app" -e "CGO_ENABLED=0" golang:alpine go build -ldflags "-s -w" -o tm-bench
@ -45,4 +72,45 @@ clean:
rm -f ./tm-bench rm -f ./tm-bench
rm -rf ./dist rm -rf ./dist
.PHONY: tools get_vendor_deps build install test build-all dist clean build-docker
########################################
### Formatting, linting, and vetting
fmt:
@go fmt ./...
metalinter:
@echo "==> Running linter"
gometalinter.v2 --vendor --deadline=600s --disable-all \
--enable=maligned \
--enable=deadcode \
--enable=goconst \
--enable=goimports \
--enable=gosimple \
--enable=ineffassign \
--enable=megacheck \
--enable=misspell \
--enable=staticcheck \
--enable=safesql \
--enable=structcheck \
--enable=unconvert \
--enable=unused \
--enable=varcheck \
--enable=vetshadow \
./...
#--enable=gas \
#--enable=dupl \
#--enable=errcheck \
#--enable=gocyclo \
#--enable=golint \ <== comments on anything exported
#--enable=gotype \
#--enable=interfacer \
#--enable=unparam \
#--enable=vet \
metalinter_all:
gometalinter.v2 --vendor --deadline=600s --enable-all --disable=lll ./...
# To avoid unintended conflicts with file names, always add to .PHONY
# unless there is a reason not to.
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
.PHONY: check check_tools get_tools update_tools get_vendor_deps build install test build-all dist fmt metalinter metalinter_all build-docker clean

+ 0
- 134
tm-bench/glide.lock View File

@ -1,134 +0,0 @@
hash: 46f5e4380fdca1f3c0211f1f54f2c0dcd2213aabbb96cdaaaa201a55156bfb97
updated: 2017-12-07T17:26:11.121786018Z
imports:
- name: github.com/btcsuite/btcd
version: 2e60448ffcc6bf78332d1fe590260095f554dd78
subpackages:
- btcec
- name: github.com/go-kit/kit
version: ebf82f4a7270657af57182f212579e5ec8c9fac8
subpackages:
- log
- log/level
- log/term
- name: github.com/go-logfmt/logfmt
version: 390ab7935ee28ec6b286364bba9b4dd6410cb3d5
- name: github.com/go-playground/locales
version: e4cbcb5d0652150d40ad0646651076b6bd2be4f6
subpackages:
- currency
- name: github.com/go-playground/universal-translator
version: 71201497bace774495daed26a3874fd339e0b538
- name: github.com/go-stack/stack
version: 259ab82a6cad3992b4e21ff5cac294ccb06474bc
- name: github.com/golang/protobuf
version: 1e59b77b52bf8e4b449a57e6f79f21226d571845
subpackages:
- proto
- ptypes
- ptypes/any
- ptypes/duration
- ptypes/timestamp
- name: github.com/gorilla/websocket
version: ea4d1f681babbce9545c9c5f3d5194a789c89f5b
- name: github.com/kr/logfmt
version: b84e30acd515aadc4b783ad4ff83aff3299bdfe0
- name: github.com/pkg/errors
version: 645ef00459ed84a119197bfb8d8205042c6df63d
- name: github.com/rcrowley/go-metrics
version: e181e095bae94582363434144c61a9653aff6e50
- name: github.com/tendermint/abci
version: 76ef8a0697c6179220a74c479b36c27a5b53008a
subpackages:
- client
- example/dummy
- types
- name: github.com/tendermint/ed25519
version: d8387025d2b9d158cf4efb07e7ebf814bcce2057
subpackages:
- edwards25519
- extra25519
- name: github.com/tendermint/go-crypto
version: dd20358a264c772b4a83e477b0cfce4c88a7001d
- name: github.com/tendermint/go-wire
version: b6fc872b42d41158a60307db4da051dd6f179415
subpackages:
- data
- name: github.com/tendermint/tendermint
version: c7f923c5b0d0f0f26566281aa251259d1bef3a6c
subpackages:
- config
- consensus/types
- p2p
- p2p/upnp
- rpc/core/types
- rpc/lib/client
- rpc/lib/types
- types
- name: github.com/tendermint/tmlibs
version: b854baa1fce7101c90b1d301b3359bb412f981c0
subpackages:
- common
- events
- flowrate
- log
- merkle
- name: github.com/tendermint/tools
version: c36867e971f4d717e7ceb2c3d451a64e9a101b99
subpackages:
- tm-monitor/eventmeter
- tm-monitor/monitor
- name: golang.org/x/crypto
version: 94eea52f7b742c7cbe0b03b22f0c4c8631ece122
subpackages:
- curve25519
- nacl/box
- nacl/secretbox
- openpgp/armor
- openpgp/errors
- poly1305
- ripemd160
- salsa20/salsa
- name: golang.org/x/net
version: faacc1b5e36e3ff02cbec9661c69ac63dd5a83ad
subpackages:
- context
- http2
- http2/hpack
- idna
- internal/timeseries
- lex/httplex
- trace
- name: golang.org/x/text
version: be25de41fadfae372d6470bda81ca6beb55ef551
subpackages:
- secure/bidirule
- transform
- unicode/bidi
- unicode/norm
- name: google.golang.org/genproto
version: 7f0da29060c682909f650ad8ed4e515bd74fa12a
subpackages:
- googleapis/rpc/status
- name: google.golang.org/grpc
version: f7bf885db0b7479a537ec317c6e48ce53145f3db
subpackages:
- balancer
- codes
- connectivity
- credentials
- grpclb/grpc_lb_v1/messages
- grpclog
- internal
- keepalive
- metadata
- naming
- peer
- resolver
- stats
- status
- tap
- transport
- name: gopkg.in/go-playground/validator.v9
version: 61caf9d3038e1af346dbf5c2e16f6678e1548364
testImports: []

+ 0
- 20
tm-bench/glide.yaml View File

@ -1,20 +0,0 @@
package: github.com/tendermint/tools/tm-bench
import:
- package: github.com/go-kit/kit
subpackages:
- log/term
- package: github.com/gorilla/websocket
- package: github.com/pkg/errors
- package: github.com/rcrowley/go-metrics
- package: github.com/tendermint/tendermint
version: v0.12.1
subpackages:
- rpc/lib/types
- types
- package: github.com/tendermint/tmlibs
subpackages:
- log
- package: github.com/tendermint/tools
version: c36867e971f4d717e7ceb2c3d451a64e9a101b99
subpackages:
- tm-monitor/monitor

+ 4
- 3
tm-bench/main.go View File

@ -84,11 +84,12 @@ Examples:
BlockLatency: metrics.NewHistogram(metrics.NewUniformSample(1000)), BlockLatency: metrics.NewHistogram(metrics.NewUniformSample(1000)),
} }
lastBlockHeight := -1
lastBlockHeight := int64(-1)
durationTimer := time.After(time.Duration(duration) * time.Second) durationTimer := time.After(time.Duration(duration) * time.Second)
ticker := time.NewTicker(1 * time.Second) ticker := time.NewTicker(1 * time.Second)
var blocks, txs int
var blocks int
var txs int64
for { for {
select { select {
case b := <-blockCh: case b := <-blockCh:
@ -101,7 +102,7 @@ Examples:
stats.BlockLatency.Update(int64(l)) stats.BlockLatency.Update(int64(l))
case <-ticker.C: case <-ticker.C:
stats.BlockTimeSample.Update(int64(blocks)) stats.BlockTimeSample.Update(int64(blocks))
stats.TxThroughputSample.Update(int64(txs))
stats.TxThroughputSample.Update(txs)
blocks = 0 blocks = 0
txs = 0 txs = 0
case <-durationTimer: case <-durationTimer:


+ 0
- 1
tm-monitor/.dockerignore View File

@ -1 +0,0 @@
vendor

+ 1
- 4
tm-monitor/Dockerfile.dev View File

@ -7,9 +7,6 @@ COPY Makefile /go/src/github.com/tendermint/tools/tm-monitor/
RUN make get_tools RUN make get_tools
COPY Gopkg.toml /go/src/github.com/tendermint/tools/tm-monitor/
COPY Gopkg.lock /go/src/github.com/tendermint/tools/tm-monitor/
COPY . /go/src/github.com/tendermint/tools/tm-monitor
RUN make get_vendor_deps RUN make get_vendor_deps
COPY . /go/src/github.com/tendermint/tools/tm-monitor

+ 1
- 1
tm-monitor/main.go View File

@ -11,7 +11,7 @@ import (
monitor "github.com/tendermint/tools/tm-monitor/monitor" monitor "github.com/tendermint/tools/tm-monitor/monitor"
) )
var version = "0.3.1"
var version = "0.4.0"
var logger = log.NewNopLogger() var logger = log.NewNopLogger()


+ 1
- 1
tm-monitor/monitor/monitor.go View File

@ -193,7 +193,7 @@ func (m *Monitor) recalculateNetworkUptimeLoop() {
func (m *Monitor) updateNumValidatorLoop() { func (m *Monitor) updateNumValidatorLoop() {
rand.Seed(time.Now().Unix()) rand.Seed(time.Now().Unix())
var height uint64
var height int64
var num int var num int
var err error var err error


+ 4
- 4
tm-monitor/monitor/network.go View File

@ -33,7 +33,7 @@ const (
// Common statistics for network of nodes // Common statistics for network of nodes
type Network struct { type Network struct {
Height uint64 `json:"height"`
Height int64 `json:"height"`
AvgBlockTime float64 `json:"avg_block_time" wire:"unsafe"` // ms (avg over last minute) AvgBlockTime float64 `json:"avg_block_time" wire:"unsafe"` // ms (avg over last minute)
blockTimeMeter metrics.Meter blockTimeMeter metrics.Meter
@ -73,11 +73,11 @@ func (n *Network) NewBlock(b tmtypes.Header) {
n.mu.Lock() n.mu.Lock()
defer n.mu.Unlock() defer n.mu.Unlock()
if n.Height >= uint64(b.Height) {
if n.Height >= b.Height {
return return
} }
n.Height = uint64(b.Height)
n.Height = b.Height
n.blockTimeMeter.Mark(1) n.blockTimeMeter.Mark(1)
if n.blockTimeMeter.Rate1() > 0.0 { if n.blockTimeMeter.Rate1() > 0.0 {
@ -164,7 +164,7 @@ func (n *Network) updateHealth() {
} }
} }
func (n *Network) UpdateNumValidatorsForHeight(num int, height uint64) {
func (n *Network) UpdateNumValidatorsForHeight(num int, height int64) {
n.mu.Lock() n.mu.Lock()
defer n.mu.Unlock() defer n.mu.Unlock()


+ 1
- 1
tm-monitor/monitor/network_test.go View File

@ -13,7 +13,7 @@ func TestNetworkNewBlock(t *testing.T) {
n := monitor.NewNetwork() n := monitor.NewNetwork()
n.NewBlock(tmtypes.Header{Height: 5, NumTxs: 100}) n.NewBlock(tmtypes.Header{Height: 5, NumTxs: 100})
assert.Equal(t, uint64(5), n.Height)
assert.Equal(t, int64(5), n.Height)
assert.Equal(t, 0.0, n.AvgBlockTime) assert.Equal(t, 0.0, n.AvgBlockTime)
assert.Equal(t, 0.0, n.AvgTxThroughput) assert.Equal(t, 0.0, n.AvgTxThroughput)
} }


+ 5
- 5
tm-monitor/monitor/node.go View File

@ -25,7 +25,7 @@ type Node struct {
Name string `json:"name"` Name string `json:"name"`
Online bool `json:"online"` Online bool `json:"online"`
Height uint64 `json:"height"`
Height int64 `json:"height"`
BlockLatency float64 `json:"block_latency" wire:"unsafe"` // ms, interval between block commits BlockLatency float64 `json:"block_latency" wire:"unsafe"` // ms, interval between block commits
// em holds the ws connection. Each eventMeter callback is called in a separate go-routine. // em holds the ws connection. Each eventMeter callback is called in a separate go-routine.
@ -128,7 +128,7 @@ func newBlockCallback(n *Node) em.EventCallbackFunc {
return func(metric *em.EventMetric, data interface{}) { return func(metric *em.EventMetric, data interface{}) {
block := data.(tmtypes.TMEventData).Unwrap().(tmtypes.EventDataNewBlockHeader).Header block := data.(tmtypes.TMEventData).Unwrap().(tmtypes.EventDataNewBlockHeader).Header
n.Height = uint64(block.Height)
n.Height = block.Height
n.logger.Info("new block", "height", block.Height, "numTxs", block.NumTxs) n.logger.Info("new block", "height", block.Height, "numTxs", block.NumTxs)
if n.blockCh != nil { if n.blockCh != nil {
@ -183,7 +183,7 @@ func (n *Node) RestartEventMeterBackoff() error {
} }
} }
func (n *Node) NumValidators() (height uint64, num int, err error) {
func (n *Node) NumValidators() (height int64, num int, err error) {
height, vals, err := n.validators() height, vals, err := n.validators()
if err != nil { if err != nil {
return 0, 0, err return 0, 0, err
@ -191,12 +191,12 @@ func (n *Node) NumValidators() (height uint64, num int, err error) {
return height, len(vals), nil return height, len(vals), nil
} }
func (n *Node) validators() (height uint64, validators []*tmtypes.Validator, err error) {
func (n *Node) validators() (height int64, validators []*tmtypes.Validator, err error) {
vals := new(ctypes.ResultValidators) vals := new(ctypes.ResultValidators)
if _, err = n.rpcClient.Call("validators", nil, vals); err != nil { if _, err = n.rpcClient.Call("validators", nil, vals); err != nil {
return 0, make([]*tmtypes.Validator, 0), err return 0, make([]*tmtypes.Validator, 0), err
} }
return uint64(vals.BlockHeight), vals.Validators, nil
return vals.BlockHeight, vals.Validators, nil
} }
func (n *Node) checkIsValidatorLoop() { func (n *Node) checkIsValidatorLoop() {


+ 3
- 3
tm-monitor/monitor/node_test.go View File

@ -15,7 +15,7 @@ import (
) )
const ( const (
blockHeight = 1
blockHeight = int64(1)
) )
func TestNodeStartStop(t *testing.T) { func TestNodeStartStop(t *testing.T) {
@ -35,7 +35,7 @@ func TestNodeNewBlockReceived(t *testing.T) {
blockHeader := &tmtypes.Header{Height: 5} blockHeader := &tmtypes.Header{Height: 5}
emMock.Call("eventCallback", &em.EventMetric{}, tmtypes.TMEventData{tmtypes.EventDataNewBlockHeader{blockHeader}}) emMock.Call("eventCallback", &em.EventMetric{}, tmtypes.TMEventData{tmtypes.EventDataNewBlockHeader{blockHeader}})
assert.Equal(t, uint64(5), n.Height)
assert.Equal(t, int64(5), n.Height)
assert.Equal(t, *blockHeader, <-blockCh) assert.Equal(t, *blockHeader, <-blockCh)
} }
@ -69,7 +69,7 @@ func TestNumValidators(t *testing.T) {
height, num, err := n.NumValidators() height, num, err := n.NumValidators()
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, uint64(blockHeight), height)
assert.Equal(t, blockHeight, height)
assert.Equal(t, 1, num) assert.Equal(t, 1, num)
} }


Loading…
Cancel
Save