Skip to content

Commit

Permalink
Revert "p2p, p2p/discover: add dial metrics (ethereum#27621)"
Browse files Browse the repository at this point in the history
This reverts commit 463ad60.
  • Loading branch information
devopsbo3 committed Nov 10, 2023
1 parent b361de5 commit aa8d15e
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 277 deletions.
8 changes: 0 additions & 8 deletions eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/p2p"
)

Expand Down Expand Up @@ -425,13 +424,6 @@ func (h *handler) runSnapExtension(peer *snap.Peer, handler snap.Handler) error
defer h.peerWG.Done()

if err := h.peers.registerSnapExtension(peer); err != nil {
if metrics.Enabled {
if peer.Inbound() {
snap.IngressRegistrationErrorMeter.Mark(1)
} else {
snap.EgressRegistrationErrorMeter.Mark(1)
}
}
peer.Log().Warn("Snapshot extension registration failed", "err", err)
return err
}
Expand Down
26 changes: 0 additions & 26 deletions eth/protocols/eth/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
package eth

import (
"errors"
"fmt"
"math/big"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/forkid"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/p2p"
)

Expand Down Expand Up @@ -61,11 +59,9 @@ func (p *Peer) Handshake(network uint64, td *big.Int, head common.Hash, genesis
select {
case err := <-errc:
if err != nil {
markError(p, err)
return err
}
case <-timeout.C:
markError(p, p2p.DiscReadTimeout)
return p2p.DiscReadTimeout
}
}
Expand Down Expand Up @@ -109,25 +105,3 @@ func (p *Peer) readStatus(network uint64, status *StatusPacket, genesis common.H
}
return nil
}

// markError registers the error with the corresponding metric.
func markError(p *Peer, err error) {
if !metrics.Enabled {
return
}
m := meters.get(p.Inbound())
switch errors.Unwrap(err) {
case errNetworkIDMismatch:
m.networkIDMismatch.Mark(1)
case errProtocolVersionMismatch:
m.protocolVersionMismatch.Mark(1)
case errGenesisMismatch:
m.genesisMismatch.Mark(1)
case errForkIDRejected:
m.forkidRejected.Mark(1)
case p2p.DiscReadTimeout:
m.timeoutError.Mark(1)
default:
m.peerError.Mark(1)
}
}
81 changes: 0 additions & 81 deletions eth/protocols/eth/metrics.go

This file was deleted.

29 changes: 0 additions & 29 deletions eth/protocols/snap/metrics.go

This file was deleted.

5 changes: 2 additions & 3 deletions p2p/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,14 +521,13 @@ func (t *dialTask) resolve(d *dialScheduler) bool {

// dial performs the actual connection attempt.
func (t *dialTask) dial(d *dialScheduler, dest *enode.Node) error {
dialMeter.Mark(1)
fd, err := d.dialer.Dial(d.ctx, t.dest)
if err != nil {
d.log.Trace("Dial error", "id", t.dest.ID(), "addr", nodeAddr(t.dest), "conn", t.flags, "err", cleanupDialErr(err))
dialConnectionError.Mark(1)
return &dialError{err}
}
return d.setupFunc(newMeteredConn(fd), t.flags, dest)
mfd := newMeteredConn(fd, false, &net.TCPAddr{IP: dest.IP(), Port: dest.TCP()})
return d.setupFunc(mfd, t.flags, dest)
}

func (t *dialTask) String() string {
Expand Down
8 changes: 0 additions & 8 deletions p2p/discover/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package discover

import (
"fmt"
"net"

"github.com/ethereum/go-ethereum/metrics"
Expand All @@ -33,17 +32,10 @@ const (
)

var (
bucketsCounter []metrics.Counter
ingressTrafficMeter = metrics.NewRegisteredMeter(ingressMeterName, nil)
egressTrafficMeter = metrics.NewRegisteredMeter(egressMeterName, nil)
)

func init() {
for i := 0; i < nBuckets; i++ {
bucketsCounter = append(bucketsCounter, metrics.NewRegisteredCounter(fmt.Sprintf("%s/bucket/%d/count", moduleName, i), nil))
}
}

// meteredConn is a wrapper around a net.UDPConn that meters both the
// inbound and outbound network traffic.
type meteredUdpConn struct {
Expand Down
36 changes: 4 additions & 32 deletions p2p/discover/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/netutil"
)
Expand Down Expand Up @@ -81,8 +80,7 @@ type Table struct {
closeReq chan struct{}
closed chan struct{}

nodeAddedHook func(*bucket, *node)
nodeRemovedHook func(*bucket, *node)
nodeAddedHook func(*node) // for testing
}

// transport is implemented by the UDP transports.
Expand All @@ -100,7 +98,6 @@ type bucket struct {
entries []*node // live entries, sorted by time of last contact
replacements []*node // recently seen nodes to be used if revalidation fails
ips netutil.DistinctNetSet
index int
}

func newTable(t transport, db *enode.DB, cfg Config) (*Table, error) {
Expand All @@ -122,8 +119,7 @@ func newTable(t transport, db *enode.DB, cfg Config) (*Table, error) {
}
for i := range tab.buckets {
tab.buckets[i] = &bucket{
index: i,
ips: netutil.DistinctNetSet{Subnet: bucketSubnet, Limit: bucketIPLimit},
ips: netutil.DistinctNetSet{Subnet: bucketSubnet, Limit: bucketIPLimit},
}
}
tab.seedRand()
Expand All @@ -132,22 +128,6 @@ func newTable(t transport, db *enode.DB, cfg Config) (*Table, error) {
return tab, nil
}

func newMeteredTable(t transport, db *enode.DB, cfg Config) (*Table, error) {
tab, err := newTable(t, db, cfg)
if err != nil {
return nil, err
}
if metrics.Enabled {
tab.nodeAddedHook = func(b *bucket, n *node) {
bucketsCounter[b.index].Inc(1)
}
tab.nodeRemovedHook = func(b *bucket, n *node) {
bucketsCounter[b.index].Dec(1)
}
}
return tab, nil
}

// Nodes returns all nodes contained in the table.
func (tab *Table) Nodes() []*enode.Node {
if !tab.isInitDone() {
Expand Down Expand Up @@ -515,7 +495,7 @@ func (tab *Table) addSeenNode(n *node) {
n.addedAt = time.Now()

if tab.nodeAddedHook != nil {
tab.nodeAddedHook(b, n)
tab.nodeAddedHook(n)
}
}

Expand Down Expand Up @@ -559,7 +539,7 @@ func (tab *Table) addVerifiedNode(n *node) {
n.addedAt = time.Now()

if tab.nodeAddedHook != nil {
tab.nodeAddedHook(b, n)
tab.nodeAddedHook(n)
}
}

Expand Down Expand Up @@ -658,16 +638,8 @@ func (tab *Table) bumpInBucket(b *bucket, n *node) bool {
}

func (tab *Table) deleteInBucket(b *bucket, n *node) {
// Check if the node is actually in the bucket so the removed hook
// isn't called multiple times for the same node.
if !contains(b.entries, n.ID()) {
return
}
b.entries = deleteNode(b.entries, n)
tab.removeIP(b, n.IP())
if tab.nodeRemovedHook != nil {
tab.nodeRemovedHook(b, n)
}
}

func contains(ns []*node, id enode.ID) bool {
Expand Down
2 changes: 1 addition & 1 deletion p2p/discover/v4_udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func ListenV4(c UDPConn, ln *enode.LocalNode, cfg Config) (*UDPv4, error) {
log: cfg.Log,
}

tab, err := newMeteredTable(t, ln.Database(), cfg)
tab, err := newTable(t, ln.Database(), cfg)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion p2p/discover/v4_udp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func TestUDPv4_pingMatchIP(t *testing.T) {
func TestUDPv4_successfulPing(t *testing.T) {
test := newUDPTest(t)
added := make(chan *node, 1)
test.table.nodeAddedHook = func(b *bucket, n *node) { added <- n }
test.table.nodeAddedHook = func(n *node) { added <- n }
defer test.close()

// The remote side sends a ping packet to initiate the exchange.
Expand Down
2 changes: 1 addition & 1 deletion p2p/discover/v5_udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func newUDPv5(conn UDPConn, ln *enode.LocalNode, cfg Config) (*UDPv5, error) {
cancelCloseCtx: cancelCloseCtx,
}
t.talk = newTalkSystem(t)
tab, err := newMeteredTable(t, t.db, cfg)
tab, err := newTable(t, t.db, cfg)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit aa8d15e

Please sign in to comment.