[syncing] fix mis-matched min syncing peers

Signed-off-by: Leo Chen <leo@harmony.one>
pull/3179/head
Leo Chen 5 years ago
parent 885ecda233
commit 36c80f4c1b
  1. 4
      api/service/syncing/syncing.go
  2. 3
      node/node_syncing.go

@ -40,7 +40,7 @@ const (
// after cutting off a number of connected peers, the result number of peers
// shall be between numPeersLowBound and numPeersHighBound
numPeersLowBound = 3
NumPeersLowBound = 3
numPeersHighBound = 5
)
@ -276,7 +276,7 @@ func (ss *StateSync) CreateSyncConfig(peers []p2p.Peer, isBeacon bool) error {
// limitNumPeers limits number of peers to release some server end sources.
func limitNumPeers(ps []p2p.Peer, randSeed int64) []p2p.Peer {
targetSize := calcNumPeersWithBound(len(ps), numPeersLowBound, numPeersHighBound)
targetSize := calcNumPeersWithBound(len(ps), NumPeersLowBound, numPeersHighBound)
if len(ps) <= targetSize {
return ps
}

@ -26,7 +26,6 @@ const (
lastMileThreshold = 4
inSyncThreshold = 1 // unit in number of block
SyncFrequency = 60
MinConnectedPeers = 10 // minimum number of peers connected to in node syncing
)
// getNeighborPeers is a helper function to return list of peers
@ -223,7 +222,7 @@ func (node *Node) doSync(bc *core.BlockChain, worker *worker.Worker, willJoinCon
node.stateSync = syncing.CreateStateSync(node.SelfPeer.IP, node.SelfPeer.Port, node.GetSyncID())
utils.Logger().Debug().Msg("[SYNC] initialized state sync")
}
if node.stateSync.GetActivePeerNumber() < MinConnectedPeers {
if node.stateSync.GetActivePeerNumber() < syncing.NumPeersLowBound {
shardID := bc.ShardID()
peers, err := node.SyncingPeerProvider.SyncingPeers(shardID)
if err != nil {

Loading…
Cancel
Save