fix discovery issue for legacy sync

pull/4366/head
“GheisMohammadi” 2 years ago committed by Soph
parent bd6d7ca7db
commit f07dd5681a
  1. 2
      api/service/legacysync/epoch_syncing.go
  2. 4
      p2p/discovery/option.go
  3. 2
      p2p/stream/common/streammanager/cooldown.go

@ -112,7 +112,7 @@ func syncLoop(bc core.BlockChain, syncConfig *SyncConfig) (timeout int) {
} }
if otherEpoch < curEpoch { if otherEpoch < curEpoch {
for _, peerCfg := range syncConfig.GetPeers() { 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 return 2
} }

@ -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.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 return opts, nil
} }

@ -36,6 +36,8 @@ func (cache *coolDownCache) Has(id peer.ID) bool {
// Add adds the peer ID to the cache // Add adds the peer ID to the cache
func (cache *coolDownCache) Add(id peer.ID) { func (cache *coolDownCache) Add(id peer.ID) {
cache.mu.Lock()
defer cache.mu.Unlock()
has := cache.timeCache.Has(string(id)) has := cache.timeCache.Has(string(id))
if !has { if !has {
cache.timeCache.Add(string(id)) cache.timeCache.Add(string(id))

Loading…
Cancel
Save