mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-27 11:41:39 +00:00
[monitor] move to int64 for height
This commit is contained in:
@ -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
|
||||||
|
|
||||||
|
@ -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()
|
||||||
|
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
@ -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() {
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user