mirror of
https://github.com/tendermint/tendermint.git
synced 2026-06-01 20:06:21 +00:00
[tm-monitor] fixed online status not changing issue. (#99)
* [tm-monitor] fixed online status not changing issue. * Refactor UpdateNodeStatus.
This commit is contained in:
committed by
Anton Kaliaev
parent
95e3e7afcd
commit
a12785aa60
@@ -131,6 +131,21 @@ func (m *Monitor) NodeByName(name string) (index int, node *Node) {
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
// NodeIsOnline is called when connection to the node is restored.
|
||||
// Must be safe to call multiple times.
|
||||
func (m *Monitor) NodeIsOnline(name string) {
|
||||
|
||||
_, node := m.NodeByName(name)
|
||||
if nil != node {
|
||||
if online, ok := m.Network.nodeStatusMap[name]; ok && online {
|
||||
m.mtx.Lock()
|
||||
node.Online = online
|
||||
m.mtx.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Start starts the monitor's routines: recalculating network uptime and
|
||||
// updating number of validators.
|
||||
func (m *Monitor) Start() error {
|
||||
@@ -160,14 +175,17 @@ func (m *Monitor) listen(nodeName string, blockCh <-chan tmtypes.Header, blockLa
|
||||
case b := <-blockCh:
|
||||
m.Network.NewBlock(b)
|
||||
m.Network.NodeIsOnline(nodeName)
|
||||
m.NodeIsOnline(nodeName)
|
||||
case l := <-blockLatencyCh:
|
||||
m.Network.NewBlockLatency(l)
|
||||
m.Network.NodeIsOnline(nodeName)
|
||||
m.NodeIsOnline(nodeName)
|
||||
case disconnected := <-disconnectCh:
|
||||
if disconnected {
|
||||
m.Network.NodeIsDown(nodeName)
|
||||
} else {
|
||||
m.Network.NodeIsOnline(nodeName)
|
||||
m.NodeIsOnline(nodeName)
|
||||
}
|
||||
case <-time.After(nodeLivenessTimeout):
|
||||
logger.Info("event", fmt.Sprintf("node was not responding for %v", nodeLivenessTimeout))
|
||||
|
||||
Reference in New Issue
Block a user