mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-11 10:36:37 +00:00
p2p: refactor to use time.Now().UnixMilli() in golang std lib (#32402)
This commit is contained in:
parent
3ff99ae52c
commit
2b38daa48c
3 changed files with 3 additions and 11 deletions
|
|
@ -305,12 +305,3 @@ func (ln *LocalNode) bumpSeq() {
|
||||||
ln.seq++
|
ln.seq++
|
||||||
ln.db.storeLocalSeq(ln.id, 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)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/p2p/enr"
|
"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.
|
// This test checks that the sequence number is persisted between restarts.
|
||||||
func TestLocalNodeSeqPersist(t *testing.T) {
|
func TestLocalNodeSeqPersist(t *testing.T) {
|
||||||
timestamp := nowMilliseconds()
|
timestamp := uint64(time.Now().UnixMilli())
|
||||||
|
|
||||||
ln, db := newLocalNodeForTesting()
|
ln, db := newLocalNodeForTesting()
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
|
||||||
|
|
@ -434,7 +434,7 @@ func (db *DB) localSeq(id ID) uint64 {
|
||||||
if seq := db.fetchUint64(localItemKey(id, dbLocalSeq)); seq > 0 {
|
if seq := db.fetchUint64(localItemKey(id, dbLocalSeq)); seq > 0 {
|
||||||
return seq
|
return seq
|
||||||
}
|
}
|
||||||
return nowMilliseconds()
|
return uint64(time.Now().UnixMilli())
|
||||||
}
|
}
|
||||||
|
|
||||||
// storeLocalSeq stores the local record sequence counter.
|
// storeLocalSeq stores the local record sequence counter.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue