Skip to content

Commit 2b38daa

Browse files
authored
p2p: refactor to use time.Now().UnixMilli() in golang std lib (#32402)
1 parent 3ff99ae commit 2b38daa

File tree

3 files changed

+3
-11
lines changed

3 files changed

+3
-11
lines changed

p2p/enode/localnode.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,3 @@ func (ln *LocalNode) bumpSeq() {
305305
ln.seq++
306306
ln.db.storeLocalSeq(ln.id, ln.seq)
307307
}
308-
309-
// nowMilliseconds gives the current timestamp at millisecond precision.
310-
func nowMilliseconds() uint64 {
311-
ns := time.Now().UnixNano()
312-
if ns < 0 {
313-
return 0
314-
}
315-
return uint64(ns / 1000 / 1000)
316-
}

p2p/enode/localnode_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"net"
2222
"net/netip"
2323
"testing"
24+
"time"
2425

2526
"github.com/ethereum/go-ethereum/crypto"
2627
"github.com/ethereum/go-ethereum/p2p/enr"
@@ -53,7 +54,7 @@ func TestLocalNode(t *testing.T) {
5354

5455
// This test checks that the sequence number is persisted between restarts.
5556
func TestLocalNodeSeqPersist(t *testing.T) {
56-
timestamp := nowMilliseconds()
57+
timestamp := uint64(time.Now().UnixMilli())
5758

5859
ln, db := newLocalNodeForTesting()
5960
defer db.Close()

p2p/enode/nodedb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ func (db *DB) localSeq(id ID) uint64 {
434434
if seq := db.fetchUint64(localItemKey(id, dbLocalSeq)); seq > 0 {
435435
return seq
436436
}
437-
return nowMilliseconds()
437+
return uint64(time.Now().UnixMilli())
438438
}
439439

440440
// storeLocalSeq stores the local record sequence counter.

0 commit comments

Comments
 (0)