From f07dd5681a2033092821421afcd0a267eefc40af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CGheisMohammadi=E2=80=9D?= <36589218+GheisMohammadi@users.noreply.github.com> Date: Fri, 10 Feb 2023 22:36:54 +0800 Subject: [PATCH] fix discovery issue for legacy sync --- api/service/legacysync/epoch_syncing.go | 2 +- p2p/discovery/option.go | 4 +++- p2p/stream/common/streammanager/cooldown.go | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/api/service/legacysync/epoch_syncing.go b/api/service/legacysync/epoch_syncing.go index 641fb5889..8d1cb37c4 100644 --- a/api/service/legacysync/epoch_syncing.go +++ b/api/service/legacysync/epoch_syncing.go @@ -112,7 +112,7 @@ func syncLoop(bc core.BlockChain, syncConfig *SyncConfig) (timeout int) { } if otherEpoch < curEpoch { for _, peerCfg := range syncConfig.GetPeers() { - syncConfig.RemovePeer(peerCfg, fmt.Sprintf("[EPOCHSYNC]: current height is higher that others, remove peers: %s", peerCfg.String())) + syncConfig.RemovePeer(peerCfg, fmt.Sprintf("[EPOCHSYNC]: current height is higher than others, remove peers: %s", peerCfg.String())) } return 2 } diff --git a/p2p/discovery/option.go b/p2p/discovery/option.go index ce4259270..fff8eea20 100644 --- a/p2p/discovery/option.go +++ b/p2p/discovery/option.go @@ -42,7 +42,9 @@ func (opt DHTConfig) GetLibp2pRawOptions() ([]libp2p_dht.Option, error) { opts = append(opts, libp2p_dht.Concurrency(opt.DiscConcurrency)) } - opts = append(opts, libp2p_dht.DisableAutoRefresh()) + // TODO: to disable auto refresh to make sure there is no conflicts with protocol discovery functions + // it's not applicable for legacy sync + // opts = append(opts, libp2p_dht.DisableAutoRefresh()) return opts, nil } diff --git a/p2p/stream/common/streammanager/cooldown.go b/p2p/stream/common/streammanager/cooldown.go index f22f4956f..ef6d21bc9 100644 --- a/p2p/stream/common/streammanager/cooldown.go +++ b/p2p/stream/common/streammanager/cooldown.go @@ -36,6 +36,8 @@ func (cache *coolDownCache) Has(id peer.ID) bool { // Add adds the peer ID to the cache func (cache *coolDownCache) Add(id peer.ID) { + cache.mu.Lock() + defer cache.mu.Unlock() has := cache.timeCache.Has(string(id)) if !has { cache.timeCache.Add(string(id))