From 2a03528f1f9a300c1cdaf9c6878b80cceea0c363 Mon Sep 17 00:00:00 2001 From: gop Date: Thu, 28 Sep 2023 09:44:10 -0500 Subject: [PATCH] Remove the force sync cycle, now need at least 3 peers to start sync --- eth/sync.go | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/eth/sync.go b/eth/sync.go index 1f529c34a7..29c04704a0 100644 --- a/eth/sync.go +++ b/eth/sync.go @@ -19,7 +19,6 @@ package eth import ( "math/big" "math/rand" - "time" "github.com/dominant-strategies/go-quai/common" "github.com/dominant-strategies/go-quai/core/types" @@ -30,8 +29,7 @@ import ( ) const ( - forceSyncCycle = 60 * time.Second // Time interval to force syncs, even if few peers are available - defaultMinSyncPeers = 3 // Amount of peers desired to start syncing + defaultMinSyncPeers = 3 // Amount of peers desired to start syncing // This is the target size for the packs of transactions sent by txsyncLoop64. // A pack can get larger than this if a single transactions exceeds this size. @@ -154,8 +152,6 @@ func (h *handler) txsyncLoop64() { // chainSyncer coordinates blockchain sync components. type chainSyncer struct { handler *handler - force *time.Timer - forced bool // true when force timer fired peerEventCh chan struct{} doneCh chan error // non-nil when sync is running } @@ -201,11 +197,6 @@ func (cs *chainSyncer) loop() { defer cs.handler.blockFetcher.Stop() defer cs.handler.downloader.Terminate() - // The force timer lowers the peer count threshold down to one when it fires. - // This ensures we'll always start sync even if there aren't enough peers. - cs.force = time.NewTimer(forceSyncCycle) - defer cs.force.Stop() - for { if op := cs.nextSyncOp(); op != nil { cs.startSync(op) @@ -215,10 +206,6 @@ func (cs *chainSyncer) loop() { // Peer information changed, recheck. case <-cs.doneCh: cs.doneCh = nil - cs.force.Reset(forceSyncCycle) - cs.forced = false - case <-cs.force.C: - cs.forced = true case <-cs.handler.quitSync: // Disable all insertion on the blockchain. This needs to happen before @@ -241,9 +228,8 @@ func (cs *chainSyncer) nextSyncOp() *chainSyncOp { // Ensure we're at minimum peer count. minPeers := defaultMinSyncPeers - if cs.forced { - minPeers = 1 - } else if minPeers > cs.handler.maxPeers { + + if minPeers > cs.handler.maxPeers { minPeers = cs.handler.maxPeers } if cs.handler.peers.len() < minPeers {