Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p2p/enode: use localItemKey for local sequence number #19131

Merged
merged 2 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions p2p/discover/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 0 additions & 9 deletions p2p/discover/table_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package discover

import (
"crypto/ecdsa"
"encoding/hex"
"fmt"
"math/rand"
Expand Down Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions p2p/enode/nodedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion p2p/enode/nodedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down