From 40e93a5f9eb75ba65e064f197e6e3d79800d30a8 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Thu, 16 Nov 2017 04:08:46 +0000 Subject: [PATCH] p2p/addrbook: fix addToOldBucket --- p2p/addrbook.go | 2 +- p2p/addrbook_test.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/p2p/addrbook.go b/p2p/addrbook.go index 842fcfdee..1101ffeef 100644 --- a/p2p/addrbook.go +++ b/p2p/addrbook.go @@ -475,7 +475,7 @@ func (a *AddrBook) addToOldBucket(ka *knownAddress, bucketIdx int) bool { } addrStr := ka.Addr.String() - bucket := a.getBucket(bucketTypeNew, bucketIdx) + bucket := a.getBucket(bucketTypeOld, bucketIdx) // Already exists? if _, ok := bucket[addrStr]; ok { diff --git a/p2p/addrbook_test.go b/p2p/addrbook_test.go index 6ebb34c34..419081d01 100644 --- a/p2p/addrbook_test.go +++ b/p2p/addrbook_test.go @@ -53,8 +53,10 @@ func TestAddrBookPickAddress(t *testing.T) { assert.NotNil(addr, "expected an address") addr = book.PickAddress(50) assert.NotNil(addr, "expected an address") + + // in this case, nNew==0 but we biased 100% to new, so we return nil addr = book.PickAddress(100) - assert.NotNil(addr, "expected an address") + assert.Nil(addr, "did not expected an address") } func TestAddrBookSaveLoad(t *testing.T) {