From cf147c71d5d441198a9d326969ffcf7fb1333abd Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 19 Feb 2019 13:29:19 +0100 Subject: [PATCH 1/2] p2p/discover: remove unused function --- p2p/discover/table_test.go | 2 ++ p2p/discover/table_util_test.go | 9 --------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/p2p/discover/table_test.go b/p2p/discover/table_test.go index b5622e3a2..233687d79 100644 --- a/p2p/discover/table_test.go +++ b/p2p/discover/table_test.go @@ -624,6 +624,8 @@ func (tn *preminedTestnet) findnode(toid enode.ID, toaddr *net.UDPAddr, target e func (*preminedTestnet) close() {} func (*preminedTestnet) ping(toid enode.ID, toaddr *net.UDPAddr) error { return nil } +var _ = (*preminedTestnet).mine // avoid linter warning about mine being dead code. + // mine generates a testnet struct literal with nodes at // various distances to the given target. func (tn *preminedTestnet) mine(target encPubkey) { diff --git a/p2p/discover/table_util_test.go b/p2p/discover/table_util_test.go index e61c9e6fc..f4dbc25a3 100644 --- a/p2p/discover/table_util_test.go +++ b/p2p/discover/table_util_test.go @@ -17,7 +17,6 @@ package discover import ( - "crypto/ecdsa" "encoding/hex" "fmt" "math/rand" @@ -167,11 +166,3 @@ func hexEncPubkey(h string) (ret encPubkey) { copy(ret[:], b) return ret } - -func hexPubkey(h string) *ecdsa.PublicKey { - k, err := decodePubkey(hexEncPubkey(h)) - if err != nil { - panic(err) - } - return k -} From 57f959af41bd94887aafea87af6a1f80b8182cf5 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 19 Feb 2019 13:29:41 +0100 Subject: [PATCH 2/2] p2p/enode: use localItemKey for local sequence number I added localItemKey for this purpose in #18963, but then forgot to actually use it. This changes the database layout yet again and requires bumping the version number. --- p2p/enode/nodedb.go | 6 +++--- p2p/enode/nodedb_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/p2p/enode/nodedb.go b/p2p/enode/nodedb.go index 9353b155c..a43e63868 100644 --- a/p2p/enode/nodedb.go +++ b/p2p/enode/nodedb.go @@ -57,7 +57,7 @@ const ( const ( dbNodeExpiration = 24 * time.Hour // Time after which an unseen node should be dropped. dbCleanupCycle = time.Hour // Time period for running the expiration task. - dbVersion = 8 + dbVersion = 9 ) var zeroIP = make(net.IP, 16) @@ -380,12 +380,12 @@ func (db *DB) UpdateFindFails(id ID, ip net.IP, fails int) error { // LocalSeq retrieves the local record sequence counter. func (db *DB) localSeq(id ID) uint64 { - return db.fetchUint64(nodeItemKey(id, zeroIP, dbLocalSeq)) + return db.fetchUint64(localItemKey(id, dbLocalSeq)) } // storeLocalSeq stores the local record sequence counter. func (db *DB) storeLocalSeq(id ID, n uint64) { - db.storeUint64(nodeItemKey(id, zeroIP, dbLocalSeq), n) + db.storeUint64(localItemKey(id, dbLocalSeq), n) } // QuerySeeds retrieves random nodes to be used as potential seed nodes diff --git a/p2p/enode/nodedb_test.go b/p2p/enode/nodedb_test.go index 341b61a28..21283524c 100644 --- a/p2p/enode/nodedb_test.go +++ b/p2p/enode/nodedb_test.go @@ -71,7 +71,7 @@ func TestDBNodeItemKey(t *testing.T) { if id != keytestID { t.Errorf("splitNodeItemKey returned wrong ID: %v", id) } - if !bytes.Equal(ip, wantIP) { + if !ip.Equal(wantIP) { t.Errorf("splitNodeItemKey returned wrong IP: %v", ip) } if field != wantField {