[monitor] move to int64 for height
This commit is contained in:
parent
d831b443da
commit
5a211ff791
|
@ -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
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue