Skip to content

Commit

Permalink
discov: add status log for bootnode (bnb-chain#1878)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatusKysel authored Sep 19, 2023
1 parent 1bc27f6 commit 2c7a07b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ require (
github.com/schollz/progressbar/v3 v3.3.4 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/thomaso-mirodin/intmath v0.0.0-20160323211736-5dc6d854e46e // indirect
github.com/tidwall/gjson v1.10.2 // indirect
github.com/tidwall/match v1.1.1 // indirect
Expand Down
8 changes: 8 additions & 0 deletions p2p/discover/v4_udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ func (t *UDPv4) loop() {
var (
plist = list.New()
timeout = time.NewTimer(0)
statusTicker = time.NewTicker(60 * time.Second)
nextTimeout *replyMatcher // head of plist when timeout was last reset
contTimeouts = 0 // number of continuous timeouts to do NTP checks
ntpWarnTime = time.Unix(0, 0)
Expand Down Expand Up @@ -440,6 +441,10 @@ func (t *UDPv4) loop() {
timeout.Stop()
}

logStatistic := func() {
t.log.Info("Current status", "table_size", t.tab.len(), "pending_size", plist.Len(), "db_size", t.db.Size())
}

for {
resetTimeout()

Expand Down Expand Up @@ -495,6 +500,9 @@ func (t *UDPv4) loop() {
}
contTimeouts = 0
}

case <-statusTicker.C:
logStatistic()
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions p2p/enode/nodedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,3 +504,9 @@ func (db *DB) Close() {
close(db.quit)
db.lvl.Close()
}

func (db *DB) Size() int64 {
var stats leveldb.DBStats
db.lvl.Stats(&stats)
return stats.LevelSizes.Sum()
}

0 comments on commit 2c7a07b

Please sign in to comment.