Log CreateSyncConfig errors from the caller side

pull/686/head
Eugene Kim 6 years ago
parent 58b054f8cd
commit 1aa2d9bbd6
  1. 8
      api/service/syncing/syncing.go
  2. 9
      node/node_syncing.go

@ -16,6 +16,7 @@ import (
pb "github.com/harmony-one/harmony/api/service/syncing/downloader/proto"
"github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/ctxerror"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/node/worker"
"github.com/harmony-one/harmony/p2p"
@ -149,11 +150,10 @@ func (peerConfig *SyncPeerConfig) GetBlocks(hashes [][]byte) ([][]byte, error) {
}
// CreateSyncConfig creates SyncConfig for StateSync object.
func (ss *StateSync) CreateSyncConfig(peers []p2p.Peer) bool {
func (ss *StateSync) CreateSyncConfig(peers []p2p.Peer) error {
utils.GetLogInstance().Debug("CreateSyncConfig: len of peers", "len", len(peers))
if len(peers) == 0 {
utils.GetLogInstance().Warn("[SYNC] Unable to get neighbor peers")
return false
return ctxerror.New("[SYNC] no peers to connect to")
}
ss.peerNumber = len(peers)
ss.syncConfig = &SyncConfig{
@ -166,7 +166,7 @@ func (ss *StateSync) CreateSyncConfig(peers []p2p.Peer) bool {
}
}
utils.GetLogInstance().Info("[SYNC] Finished creating SyncConfig")
return true
return nil
}
// MakeConnectionToPeers makes grpc connection to all peers.

@ -13,6 +13,7 @@ import (
"github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/core/types"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/harmony-one/harmony/internal/ctxerror"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/node/worker"
"github.com/harmony-one/harmony/p2p"
@ -61,12 +62,12 @@ SyncingLoop:
node.stateSync = syncing.CreateStateSync(node.SelfPeer.IP, node.SelfPeer.Port, node.GetSyncID())
}
if node.stateSync.GetActivePeerNumber() == 0 {
if node.stateSync.CreateSyncConfig(getPeers()) {
node.stateSync.MakeConnectionToPeers()
} else {
utils.GetLogInstance().Debug("[SYNC] no active peers, continue SyncingLoop")
peers := getPeers()
if err := node.stateSync.CreateSyncConfig(peers); err != nil {
ctxerror.Log15(utils.GetLogInstance().Debug, err)
continue SyncingLoop
}
node.stateSync.MakeConnectionToPeers()
}
if node.stateSync.IsOutOfSync(bc) {
utils.GetLogInstance().Debug("[SYNC] out of sync, doing syncing")

Loading…
Cancel
Save