From 8028e08abc2e4f9877026ab6fb4a6e920c0e302d Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 13 Oct 2020 14:16:06 +0300 Subject: [PATCH] network: an address should either be good or bad, but not both --- pkg/network/discovery.go | 2 ++ pkg/network/discovery_test.go | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/network/discovery.go b/pkg/network/discovery.go index cf21618c1..4be7d8375 100644 --- a/pkg/network/discovery.go +++ b/pkg/network/discovery.go @@ -115,6 +115,7 @@ func (d *DefaultDiscovery) RegisterBadAddr(addr string) { } else { d.badAddrs[addr] = true delete(d.unconnectedAddrs, addr) + delete(d.goodAddrs, addr) } d.lock.Unlock() } @@ -161,6 +162,7 @@ func (d *DefaultDiscovery) GoodPeers() []AddressWithCapabilities { func (d *DefaultDiscovery) RegisterGoodAddr(s string, c capability.Capabilities) { d.lock.Lock() d.goodAddrs[s] = c + delete(d.badAddrs, s) d.lock.Unlock() } diff --git a/pkg/network/discovery_test.go b/pkg/network/discovery_test.go index 94af43d83..753142de5 100644 --- a/pkg/network/discovery_test.go +++ b/pkg/network/discovery_test.go @@ -153,14 +153,14 @@ func TestDefaultDiscoverer(t *testing.T) { time.Sleep(time.Second) } assert.Equal(t, len(set1), len(d.BadPeers())) - assert.Equal(t, len(set1), len(d.GoodPeers())) + assert.Equal(t, 0, len(d.GoodPeers())) assert.Equal(t, 0, len(d.UnconnectedPeers())) // Re-adding bad addresses is a no-op. d.BackFill(set1...) assert.Equal(t, 0, len(d.UnconnectedPeers())) assert.Equal(t, len(set1), len(d.BadPeers())) - assert.Equal(t, len(set1), len(d.GoodPeers())) + assert.Equal(t, 0, len(d.GoodPeers())) require.Equal(t, 0, d.PoolCount()) // Close should work and subsequent RequestRemote is a no-op.