eth: add per-peer metrics

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2025-03-27 19:47:22 +01:00
parent 2a1784baef
commit dc0db2fdd7
No known key found for this signature in database
GPG key ID: 0FE274EE8C95166E
4 changed files with 47 additions and 0 deletions

View file

@ -310,6 +310,7 @@ func (f *TxFetcher) isKnownUnderpriced(hash common.Hash) bool {
// direct request replies. The differentiation is important so the fetcher can
// re-schedule missing transactions as soon as possible.
func (f *TxFetcher) Enqueue(peer string, txs []*types.Transaction, direct bool) error {
// TODO: add peer metrics here
var (
inMeter = txReplyInMeter
knownMeter = txReplyKnownMeter

View file

@ -501,6 +501,7 @@ func handleTransactions(backend Backend, msg Decoder, peer *Peer) error {
}
peer.markTransaction(tx.Hash())
}
peer.meters.txReceived.Mark(int64(len(txs)))
return backend.Handle(peer, &txs)
}

View file

@ -59,6 +59,8 @@ type Peer struct {
reqCancel chan *cancel // Dispatch channel to cancel pending requests and untrack them
resDispatch chan *response // Dispatch channel to fulfil pending requests and untrack them
meters *peerMeters // Peer-specific metrics for diagnositics and to use in decision logic
term chan struct{} // Termination channel to stop the broadcasters
}
@ -77,6 +79,7 @@ func NewPeer(version uint, p *p2p.Peer, rw p2p.MsgReadWriter, txpool TxPool) *Pe
reqCancel: make(chan *cancel),
resDispatch: make(chan *response),
txpool: txpool,
meters: newPeerMeters("peers/"+p.ID().String(), nil),
term: make(chan struct{}),
}
// Start up all the broadcasters

View file

@ -0,0 +1,42 @@
// Copyright 2025 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package eth
import "github.com/ethereum/go-ethereum/metrics"
type peerMeters struct {
txReceived *metrics.Meter
txSent *metrics.Meter
txReplyInMeter *metrics.Meter
txReplyKnownMeter *metrics.Meter
txReplyUnderpricedMeter *metrics.Meter
txReplyOtherRejectMeter *metrics.Meter
}
// newPeerMeters registers and returns peer-level meters.
func newPeerMeters(base string, r metrics.Registry) *peerMeters {
return &peerMeters{
txReceived: metrics.NewRegisteredMeter(base+"/txReceived", r),
txSent: metrics.NewRegisteredMeter(base+"/txSent", r),
txReplyInMeter: metrics.NewRegisteredMeter(base+"/eth/fetcher/transaction/replies/in", nil),
txReplyKnownMeter: metrics.NewRegisteredMeter(base+"/eth/fetcher/transaction/replies/known", nil),
txReplyUnderpricedMeter: metrics.NewRegisteredMeter(base+"/eth/fetcher/transaction/replies/underpriced", nil),
txReplyOtherRejectMeter: metrics.NewRegisteredMeter(base+"/eth/fetcher/transaction/replies/otherreject", nil),
}
}