mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 08:49:29 +00:00
eth/txtracker: prune peer stats on disconnect
Peer stats were never pruned, so the peers map grew with every peer ever seen. The EMA decay loop and stats copy iterated all historical peers on every block/query. Add NotifyPeerDrop(peer) that deletes the peer's stats entry. Called from handler.unregisterPeer alongside txFetcher.Drop.
This commit is contained in:
parent
3785d43db4
commit
6d53acfa22
2 changed files with 9 additions and 0 deletions
|
|
@ -406,6 +406,7 @@ func (h *handler) unregisterPeer(id string) {
|
|||
}
|
||||
h.downloader.UnregisterPeer(id)
|
||||
h.txFetcher.Drop(id)
|
||||
h.txTracker.NotifyPeerDrop(id)
|
||||
|
||||
if err := h.peers.unregisterPeer(id); err != nil {
|
||||
logger.Error("Ethereum peer removal failed", "err", err)
|
||||
|
|
|
|||
|
|
@ -85,6 +85,14 @@ func (t *Tracker) Start(chain Chain) {
|
|||
go t.loop()
|
||||
}
|
||||
|
||||
// NotifyPeerDrop removes a disconnected peer's stats to prevent unbounded
|
||||
// growth. Safe to call from any goroutine.
|
||||
func (t *Tracker) NotifyPeerDrop(peer string) {
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
delete(t.peers, peer)
|
||||
}
|
||||
|
||||
// Stop shuts down the tracker.
|
||||
func (t *Tracker) Stop() {
|
||||
t.sub.Unsubscribe()
|
||||
|
|
|
|||
Loading…
Reference in a new issue