diff --git a/cmd/sentry/download/sentry.go b/cmd/sentry/download/sentry.go index 634ff3c5f21dd155b5c749271cb67d3fc29a2108..91b5a27356e295f0e4c3dff4a812b6cd7e33f6ff 100644 --- a/cmd/sentry/download/sentry.go +++ b/cmd/sentry/download/sentry.go @@ -260,8 +260,7 @@ func runPeer( peerPrinted = true } } - var err error - if err = common.Stopped(ctx.Done()); err != nil { + if err := common.Stopped(ctx.Done()); err != nil { return err } if peerInfo.Removed() { @@ -844,8 +843,7 @@ func (ss *SentryServerImpl) SetStatus(_ context.Context, statusData *proto_sentr return reply, nil } -func (ss *SentryServerImpl) PeerCount(_ context.Context, req *proto_sentry.PeerCountRequest) (*proto_sentry.PeerCountReply, error) { - var pc uint64 = 0 +func (ss *SentryServerImpl) SimplePeerCount() (pc int) { ss.Peers.Range(func(key, value interface{}) bool { peerID := key.(string) x, _ := ss.Peers.Load(peerID) @@ -856,7 +854,11 @@ func (ss *SentryServerImpl) PeerCount(_ context.Context, req *proto_sentry.PeerC pc++ return true }) - return &proto_sentry.PeerCountReply{Count: pc}, nil + return pc +} + +func (ss *SentryServerImpl) PeerCount(_ context.Context, req *proto_sentry.PeerCountRequest) (*proto_sentry.PeerCountReply, error) { + return &proto_sentry.PeerCountReply{Count: uint64(ss.SimplePeerCount())}, nil } // setupDiscovery creates the node discovery source for the `eth` and `snap` diff --git a/eth/backend.go b/eth/backend.go index b1fcac9069efa2952503cf33eddee88357f51b49..12eecc51cba2bcf542fa8c7aa2ce9eefd00d42e5 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -28,6 +28,7 @@ import ( "os" "path" "reflect" + "strconv" "sync" "time" @@ -377,6 +378,25 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { server65 := download.NewSentryServer(backend.downloadV2Ctx, d65, readNodeInfo, &cfg65, eth.ETH65) backend.sentryServers = append(backend.sentryServers, server65) backend.sentries = append(backend.sentries, remote.NewSentryClientDirect(eth.ETH65, server65)) + go func() { + logEvery := time.NewTicker(60 * time.Second) + defer logEvery.Stop() + + var logItems []interface{} + + for { + select { + case <-backend.downloadV2Ctx.Done(): + return + case <-logEvery.C: + logItems = logItems[:0] + for _, srv := range backend.sentryServers { + logItems = append(logItems, eth.ProtocolToString[srv.Protocol.Version], strconv.Itoa(srv.SimplePeerCount())) + } + log.Info("[p2p] Peers", logItems...) + } + } + }() } backend.downloadServer, err = download.NewControlServer(chainKv, stack.Config().NodeName(), chainConfig, genesis.Hash(), backend.engine, backend.config.NetworkID, backend.sentries, config.BlockDownloaderWindow) if err != nil { diff --git a/eth/protocols/eth/protocol.go b/eth/protocols/eth/protocol.go index 7ce8bee56f0b82003924603385791591b9ac3cf9..97539aee519868e9dfc68e4fcd55d4ecb76fcfe7 100644 --- a/eth/protocols/eth/protocol.go +++ b/eth/protocols/eth/protocol.go @@ -37,6 +37,11 @@ const ( ETH66 = 66 ) +var ProtocolToString = map[uint]string{ + ETH65: "eth65", + ETH66: "eth66", +} + // ProtocolName is the official short name of the `eth` protocol used during // devp2p capability negotiation. const ProtocolName = "eth" diff --git a/p2p/dial.go b/p2p/dial.go index ce1a6e4ebd28bbae9d5d44c01e41b78ad13ba6fb..961b4584427c06d6936d8de558747a80b66f134a 100644 --- a/p2p/dial.go +++ b/p2p/dial.go @@ -247,7 +247,7 @@ loop: nodesCh = nil } d.rearmHistoryTimer(historyExp) - d.logStats() + //d.logStats() select { case <-d.ctx.Done(): @@ -338,9 +338,8 @@ func (d *dialScheduler) readNodes(it enode.Iterator) { } } -// logStats prints dialer statistics to the log. The message is suppressed when enough -// peers are connected because users should only see it while their client is starting up // or comes back online. +//nolint func (d *dialScheduler) logStats() { now := d.clock.Now() if d.lastStatsLog.Add(dialStatsLogInterval) > now { diff --git a/p2p/server.go b/p2p/server.go index 3883f763e608a69dfcb6d68e0e8f1e18c4156596..57b5ae5b37d042f610106d389d0219c3f64a0868 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -748,7 +748,6 @@ running: case <-srv.quit: // The server was stopped. Run the cleanup logic. break running - case n := <-srv.addtrusted: // This channel is used by AddTrustedPeer to add a node // to the trusted node set.