p2p: refactor to use time.Now().UnixMilli() in golang std lib (#32402)

This commit is contained in:
cui 2025-08-14 16:28:57 +08:00 committed by GitHub
parent 3ff99ae52c
commit 2b38daa48c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 3 additions and 11 deletions

View file

@ -305,12 +305,3 @@ func (ln *LocalNode) bumpSeq() {
ln.seq++
ln.db.storeLocalSeq(ln.id, ln.seq)
}
// nowMilliseconds gives the current timestamp at millisecond precision.
func nowMilliseconds() uint64 {
ns := time.Now().UnixNano()
if ns < 0 {
return 0
}
return uint64(ns / 1000 / 1000)
}

View file

@ -21,6 +21,7 @@ import (
"net"
"net/netip"
"testing"
"time"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/p2p/enr"
@ -53,7 +54,7 @@ func TestLocalNode(t *testing.T) {
// This test checks that the sequence number is persisted between restarts.
func TestLocalNodeSeqPersist(t *testing.T) {
timestamp := nowMilliseconds()
timestamp := uint64(time.Now().UnixMilli())
ln, db := newLocalNodeForTesting()
defer db.Close()

View file

@ -434,7 +434,7 @@ func (db *DB) localSeq(id ID) uint64 {
if seq := db.fetchUint64(localItemKey(id, dbLocalSeq)); seq > 0 {
return seq
}
return nowMilliseconds()
return uint64(time.Now().UnixMilli())
}
// storeLocalSeq stores the local record sequence counter.