Skip to content

Commit e979438

Browse files
authored
p2p/enode: use atomic.Pointer in LocalNode (#32360)
1 parent f9f85d0 commit e979438

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

p2p/enode/localnode.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const (
4545
// current process. Setting ENR entries via the Set method updates the record. A new version
4646
// of the record is signed on demand when the Node method is called.
4747
type LocalNode struct {
48-
cur atomic.Value // holds a non-nil node pointer while the record is up-to-date
48+
cur atomic.Pointer[Node] // holds a non-nil node pointer while the record is up-to-date
4949

5050
id ID
5151
key *ecdsa.PrivateKey
@@ -82,7 +82,7 @@ func NewLocalNode(db *DB, key *ecdsa.PrivateKey) *LocalNode {
8282
}
8383
ln.seq = db.localSeq(ln.id)
8484
ln.update = time.Now()
85-
ln.cur.Store((*Node)(nil))
85+
ln.cur.Store(nil)
8686
return ln
8787
}
8888

@@ -94,7 +94,7 @@ func (ln *LocalNode) Database() *DB {
9494
// Node returns the current version of the local node record.
9595
func (ln *LocalNode) Node() *Node {
9696
// If we have a valid record, return that
97-
n := ln.cur.Load().(*Node)
97+
n := ln.cur.Load()
9898
if n != nil {
9999
return n
100100
}
@@ -105,7 +105,7 @@ func (ln *LocalNode) Node() *Node {
105105

106106
// Double check the current record, since multiple goroutines might be waiting
107107
// on the write mutex.
108-
if n = ln.cur.Load().(*Node); n != nil {
108+
if n = ln.cur.Load(); n != nil {
109109
return n
110110
}
111111

@@ -121,7 +121,7 @@ func (ln *LocalNode) Node() *Node {
121121

122122
ln.sign()
123123
ln.update = time.Now()
124-
return ln.cur.Load().(*Node)
124+
return ln.cur.Load()
125125
}
126126

127127
// Seq returns the current sequence number of the local node record.
@@ -276,11 +276,11 @@ func (e *lnEndpoint) get() (newIP net.IP, newPort uint16) {
276276
}
277277

278278
func (ln *LocalNode) invalidate() {
279-
ln.cur.Store((*Node)(nil))
279+
ln.cur.Store(nil)
280280
}
281281

282282
func (ln *LocalNode) sign() {
283-
if n := ln.cur.Load().(*Node); n != nil {
283+
if n := ln.cur.Load(); n != nil {
284284
return // no changes
285285
}
286286

0 commit comments

Comments
 (0)