eth/dropper: simplify sync status query

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2025-04-11 11:37:14 +02:00
parent 1647f51eed
commit 7a76bdd75e
No known key found for this signature in database
GPG key ID: 0FE274EE8C95166E

View file

@ -40,8 +40,6 @@ const (
// dropping when no more peers can be added. Larger numbers result in more
// aggressive drop behavior.
peerDropThreshold = 0
// Sync status poll interval (no need to be too reactive here)
syncCheckInterval = 60 * time.Second
)
var (
@ -158,27 +156,11 @@ func randomDuration(min, max time.Duration) time.Duration {
func (cm *dropper) loop() {
defer cm.wg.Done()
// Set up periodic timer to pull syncing status.
// We could get syncing status in a few ways:
// - poll the sync status (we use this for now)
// - subscribe to Downloader.mux
// - subscribe to DownloaderAPI (which itself polls the sync status)
syncing := cm.syncingFunc()
syncCheckTimer := time.NewTimer(syncCheckInterval)
defer syncCheckTimer.Stop()
for {
select {
case <-syncCheckTimer.C:
// Update info about syncing status, and rearm the timers.
syncingNew := cm.syncingFunc()
if syncing != syncingNew {
// Syncing status changed, we might need to update the timers.
syncing = syncingNew
}
syncCheckTimer.Reset(syncCheckInterval)
case <-cm.peerDropTimer.C:
if !syncing {
// Drop a random peer if we are not syncing and the peer count is close to the limit.
if !cm.syncingFunc() {
cm.dropRandomPeer()
}
cm.peerDropTimer.Reset(randomDuration(peerDropIntervalMin, peerDropIntervalMax))