Skip to content

Commit dac7cbc

Browse files
authored
p2p/enode: use localItemKey for local sequence number (#19131)
* p2p/discover: remove unused function * 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.
2 parents dd28ba3 + 57f959a commit dac7cbc

4 files changed

Lines changed: 6 additions & 13 deletions

File tree

‎p2p/discover/table_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,8 @@ func (tn *preminedTestnet) findnode(toid enode.ID, toaddr *net.UDPAddr, target e
624624
func (*preminedTestnet) close() {}
625625
func (*preminedTestnet) ping(toid enode.ID, toaddr *net.UDPAddr) error { return nil }
626626

627+
var _ = (*preminedTestnet).mine // avoid linter warning about mine being dead code.
628+
627629
// mine generates a testnet struct literal with nodes at
628630
// various distances to the given target.
629631
func (tn *preminedTestnet) mine(target encPubkey) {

‎p2p/discover/table_util_test.go‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package discover
1818

1919
import (
20-
"crypto/ecdsa"
2120
"encoding/hex"
2221
"fmt"
2322
"math/rand"
@@ -167,11 +166,3 @@ func hexEncPubkey(h string) (ret encPubkey) {
167166
copy(ret[:], b)
168167
return ret
169168
}
170-
171-
func hexPubkey(h string) *ecdsa.PublicKey {
172-
k, err := decodePubkey(hexEncPubkey(h))
173-
if err != nil {
174-
panic(err)
175-
}
176-
return k
177-
}

‎p2p/enode/nodedb.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const (
5757
const (
5858
dbNodeExpiration = 24 * time.Hour // Time after which an unseen node should be dropped.
5959
dbCleanupCycle = time.Hour // Time period for running the expiration task.
60-
dbVersion = 8
60+
dbVersion = 9
6161
)
6262

6363
var zeroIP = make(net.IP, 16)
@@ -380,12 +380,12 @@ func (db *DB) UpdateFindFails(id ID, ip net.IP, fails int) error {
380380

381381
// LocalSeq retrieves the local record sequence counter.
382382
func (db *DB) localSeq(id ID) uint64 {
383-
return db.fetchUint64(nodeItemKey(id, zeroIP, dbLocalSeq))
383+
return db.fetchUint64(localItemKey(id, dbLocalSeq))
384384
}
385385

386386
// storeLocalSeq stores the local record sequence counter.
387387
func (db *DB) storeLocalSeq(id ID, n uint64) {
388-
db.storeUint64(nodeItemKey(id, zeroIP, dbLocalSeq), n)
388+
db.storeUint64(localItemKey(id, dbLocalSeq), n)
389389
}
390390

391391
// QuerySeeds retrieves random nodes to be used as potential seed nodes

‎p2p/enode/nodedb_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestDBNodeItemKey(t *testing.T) {
7171
if id != keytestID {
7272
t.Errorf("splitNodeItemKey returned wrong ID: %v", id)
7373
}
74-
if !bytes.Equal(ip, wantIP) {
74+
if !ip.Equal(wantIP) {
7575
t.Errorf("splitNodeItemKey returned wrong IP: %v", ip)
7676
}
7777
if field != wantField {

0 commit comments

Comments
 (0)