Merge pull request #1519 from chaosma/master

add debug log for beacon syncing
pull/1522/head
chaosma 5 years ago committed by GitHub
commit bac6e8ab33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      api/service/syncing/syncing.go

@ -687,7 +687,7 @@ func (ss *StateSync) RegisterNodeInfo() int {
}
// getMaxPeerHeight gets the maximum blockchain heights from peers
func (ss *StateSync) getMaxPeerHeight() uint64 {
func (ss *StateSync) getMaxPeerHeight(isBeacon bool) uint64 {
maxHeight := uint64(0)
var wg sync.WaitGroup
ss.syncConfig.ForEachPeer(func(peerConfig *SyncPeerConfig) (brk bool) {
@ -695,7 +695,7 @@ func (ss *StateSync) getMaxPeerHeight() uint64 {
go func() {
defer wg.Done()
//debug
utils.Logger().Debug().Str("IP", peerConfig.ip).Str("Port", peerConfig.port).Msg("[Sync]getMaxPeerHeight")
utils.Logger().Debug().Bool("isBeacon", isBeacon).Str("IP", peerConfig.ip).Str("Port", peerConfig.port).Msg("[Sync]getMaxPeerHeight")
response, err := peerConfig.client.GetBlockChainHeight()
if err != nil {
utils.Logger().Warn().Err(err).Str("IP", peerConfig.ip).Str("Port", peerConfig.port).Msg("[Sync]GetBlockChainHeight failed")
@ -715,14 +715,14 @@ func (ss *StateSync) getMaxPeerHeight() uint64 {
// IsSameBlockchainHeight checks whether the node is out of sync from other peers
func (ss *StateSync) IsSameBlockchainHeight(bc *core.BlockChain) (uint64, bool) {
otherHeight := ss.getMaxPeerHeight()
otherHeight := ss.getMaxPeerHeight(false)
currentHeight := bc.CurrentBlock().NumberU64()
return otherHeight, currentHeight == otherHeight
}
// IsOutOfSync checks whether the node is out of sync from other peers
func (ss *StateSync) IsOutOfSync(bc *core.BlockChain) bool {
otherHeight := ss.getMaxPeerHeight()
otherHeight := ss.getMaxPeerHeight(false)
currentHeight := bc.CurrentBlock().NumberU64()
utils.Logger().Debug().
Uint64("OtherHeight", otherHeight).
@ -743,11 +743,13 @@ Loop:
for {
select {
case <-ticker.C:
otherHeight := ss.getMaxPeerHeight()
otherHeight := ss.getMaxPeerHeight(isBeacon)
currentHeight := bc.CurrentBlock().NumberU64()
if currentHeight >= otherHeight {
utils.Logger().Info().Msgf("[SYNC] Node is now IN SYNC! (ShardID: %d, otherHeight: %d, currentHeight: %d)", bc.ShardID(), otherHeight, currentHeight)
utils.Logger().Info().Msgf("[SYNC] Node is now IN SYNC! (isBeacon: %t, ShardID: %d, otherHeight: %d, currentHeight: %d)", isBeacon, bc.ShardID(), otherHeight, currentHeight)
break Loop
} else {
utils.Logger().Debug().Msgf("[SYNC] Node is Not in Sync (isBeacon: %t, ShardID: %d, otherHeight: %d, currentHeight: %d)", isBeacon, bc.ShardID(), otherHeight, currentHeight)
}
startHash := bc.CurrentBlock().Hash()
size := uint32(otherHeight - currentHeight)

Loading…
Cancel
Save