diff --git a/api/service/syncing/syncing.go b/api/service/syncing/syncing.go index 566424a1a..2b984a145 100644 --- a/api/service/syncing/syncing.go +++ b/api/service/syncing/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. diff --git a/node/node_syncing.go b/node/node_syncing.go index c9c479216..cf01ef984 100644 --- a/node/node_syncing.go +++ b/node/node_syncing.go @@ -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")