From 5a211ff791b3b3db1e8ad39e0c0d751c53ab3eb5 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 3 Apr 2018 13:02:09 +0200 Subject: [PATCH] [monitor] move to int64 for height --- tm-monitor/monitor/monitor.go | 2 +- tm-monitor/monitor/network.go | 8 ++++---- tm-monitor/monitor/network_test.go | 2 +- tm-monitor/monitor/node.go | 10 +++++----- tm-monitor/monitor/node_test.go | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tm-monitor/monitor/monitor.go b/tm-monitor/monitor/monitor.go index c32361221..022e1db7c 100644 --- a/tm-monitor/monitor/monitor.go +++ b/tm-monitor/monitor/monitor.go @@ -193,7 +193,7 @@ func (m *Monitor) recalculateNetworkUptimeLoop() { func (m *Monitor) updateNumValidatorLoop() { rand.Seed(time.Now().Unix()) - var height uint64 + var height int64 var num int var err error diff --git a/tm-monitor/monitor/network.go b/tm-monitor/monitor/network.go index 00d41f4c0..2a2e4f0c8 100644 --- a/tm-monitor/monitor/network.go +++ b/tm-monitor/monitor/network.go @@ -33,7 +33,7 @@ const ( // Common statistics for network of nodes type Network struct { - Height uint64 `json:"height"` + Height int64 `json:"height"` AvgBlockTime float64 `json:"avg_block_time" wire:"unsafe"` // ms (avg over last minute) blockTimeMeter metrics.Meter @@ -73,11 +73,11 @@ func (n *Network) NewBlock(b tmtypes.Header) { n.mu.Lock() defer n.mu.Unlock() - if n.Height >= uint64(b.Height) { + if n.Height >= b.Height { return } - n.Height = uint64(b.Height) + n.Height = b.Height n.blockTimeMeter.Mark(1) 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() defer n.mu.Unlock() diff --git a/tm-monitor/monitor/network_test.go b/tm-monitor/monitor/network_test.go index 54627a697..d01afaf0d 100644 --- a/tm-monitor/monitor/network_test.go +++ b/tm-monitor/monitor/network_test.go @@ -13,7 +13,7 @@ func TestNetworkNewBlock(t *testing.T) { n := monitor.NewNetwork() 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.AvgTxThroughput) } diff --git a/tm-monitor/monitor/node.go b/tm-monitor/monitor/node.go index f8fdc3add..b00fc8a7d 100644 --- a/tm-monitor/monitor/node.go +++ b/tm-monitor/monitor/node.go @@ -25,7 +25,7 @@ type Node struct { Name string `json:"name"` Online bool `json:"online"` - Height uint64 `json:"height"` + Height int64 `json:"height"` 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. @@ -128,7 +128,7 @@ func newBlockCallback(n *Node) em.EventCallbackFunc { return func(metric *em.EventMetric, data interface{}) { 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) 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() if err != nil { return 0, 0, err @@ -191,12 +191,12 @@ func (n *Node) NumValidators() (height uint64, num int, err error) { 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) if _, err = n.rpcClient.Call("validators", nil, vals); err != nil { return 0, make([]*tmtypes.Validator, 0), err } - return uint64(vals.BlockHeight), vals.Validators, nil + return vals.BlockHeight, vals.Validators, nil } func (n *Node) checkIsValidatorLoop() { diff --git a/tm-monitor/monitor/node_test.go b/tm-monitor/monitor/node_test.go index d79725c8b..79b4675ae 100644 --- a/tm-monitor/monitor/node_test.go +++ b/tm-monitor/monitor/node_test.go @@ -15,7 +15,7 @@ import ( ) const ( - blockHeight = 1 + blockHeight = int64(1) ) func TestNodeStartStop(t *testing.T) { @@ -35,7 +35,7 @@ func TestNodeNewBlockReceived(t *testing.T) { blockHeader := &tmtypes.Header{Height: 5} 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) } @@ -69,7 +69,7 @@ func TestNumValidators(t *testing.T) { height, num, err := n.NumValidators() assert.Nil(t, err) - assert.Equal(t, uint64(blockHeight), height) + assert.Equal(t, blockHeight, height) assert.Equal(t, 1, num) }