Repository: libp2p/go-libp2p
Pull request #2860 (2024-07-03 17:36:26)

 peerstore: don't intern protocols 


Patch:
diff --git a/dashboards/autonatv2/autonatv2.json b/dashboards/autonatv2/autonatv2.json
deleted file mode 100644
index 11186c09..00000000
--- a/dashboards/autonatv2/autonatv2.json
+++ /dev/null
@@ -1,506 +0,0 @@
-{
-  "annotations": {
-    "list": [
-      {
-        "builtIn": 1,
-        "datasource": {
-          "type": "grafana",
-          "uid": "-- Grafana --"
-        },
-        "enable": true,
-        "hide": true,
-        "iconColor": "rgba(0, 211, 255, 1)",
-        "name": "Annotations & Alerts",
-        "target": {
-          "limit": 100,
-          "matchAny": false,
-          "tags": [],
-          "type": "dashboard"
-        },
-        "type": "dashboard"
-      }
-    ]
-  },
-  "editable": true,
-  "fiscalYearStartMonth": 0,
-  "graphTooltip": 0,
-  "id": 4,
-  "links": [],
-  "panels": [
-    {
-      "datasource": {
-        "type": "prometheus",
-        "uid": "${data_source}"
-      },
-      "fieldConfig": {
-        "defaults": {
-          "color": {
-            "mode": "palette-classic",
-            "seriesBy": "last"
-          },
-          "custom": {
-            "axisBorderShow": false,
-            "axisCenteredZero": false,
-            "axisColorMode": "text",
-            "axisLabel": "",
-            "axisPlacement": "auto",
-            "barAlignment": 0,
-            "drawStyle": "line",
-            "fillOpacity": 0,
-            "gradientMode": "none",
-            "hideFrom": {
-              "legend": false,
-              "tooltip": false,
-              "viz": false
-            },
-            "insertNulls": false,
-            "lineInterpolation": "linear",
-            "lineWidth": 1,
-            "pointSize": 5,
-            "scaleDistribution": {
-              "type": "linear"
-            },
-            "showPoints": "auto",
-            "spanNulls": false,
-            "stacking": {
-              "group": "A",
-              "mode": "none"
-            },
-            "thresholdsStyle": {
-              "mode": "off"
-            }
-          },
-          "mappings": [],
-          "thresholds": {
-            "mode": "absolute",
-            "steps": [
-              {
-                "color": "green",
-                "value": null
-              },
-              {
-                "color": "red",
-                "value": 80
-              }
-            ]
-          }
-        },
-        "overrides": [
-          {
-            "matcher": {
-              "id": "byName",
-              "options": "OK"
-            },
-            "properties": [
-              {
-                "id": "color",
-                "value": {
-                  "fixedColor": "green",
-                  "mode": "fixed"
-                }
-              }
-            ]
-          },
-          {
-            "matcher": {
-              "id": "byName",
-              "options": "E_DIAL_REFUSED"
-            },
-            "properties": [
-              {
-                "id": "color",
-                "value": {
-                  "fixedColor": "purple",
-                  "mode": "fixed"
-                }
-              }
-            ]
-          }
-        ]
-      },
-      "gridPos": {
-        "h": 8,
-        "w": 12,
-        "x": 0,
-        "y": 0
-      },
-      "id": 1,
-      "options": {
-        "legend": {
-          "calcs": [],
-          "displayMode": "list",
-          "placement": "bottom",
-          "showLegend": true
-        },
-        "tooltip": {
-          "maxHeight": 600,
-          "mode": "single",
-          "sort": "none"
-        }
-      },
-      "targets": [
-        {
-          "datasource": {
-            "type": "prometheus",
-            "uid": "${data_source}"
-          },
-          "editorMode": "code",
-          "expr": "sum by (response_status) (increase(libp2p_autonatv2_requests_completed_total{instance=~\"$instance\", server_error=\"nil\"}[$__rate_interval]))\n",
-          "instant": false,
-          "legendFormat": "__auto",
-          "range": true,
-          "refId": "A"
-        }
-      ],
-      "title": "Dial Request by Response Status",
-      "type": "timeseries"
-    },
-    {
-      "datasource": {
-        "type": "prometheus",
-        "uid": "${data_source}"
-      },
-      "fieldConfig": {
-        "defaults": {
-          "color": {
-            "mode": "palette-classic",
-            "seriesBy": "last"
-          },
-          "custom": {
-            "axisBorderShow": false,
-            "axisCenteredZero": false,
-            "axisColorMode": "text",
-            "axisLabel": "",
-            "axisPlacement": "auto",
-            "barAlignment": 0,
-            "drawStyle": "line",
-            "fillOpacity": 0,
-            "gradientMode": "none",
-            "hideFrom": {
-              "legend": false,
-              "tooltip": false,
-              "viz": false
-            },
-            "insertNulls": false,
-            "lineInterpolation": "linear",
-            "lineWidth": 1,
-            "pointSize": 5,
-            "scaleDistribution": {
-              "type": "linear"
-            },
-            "showPoints": "auto",
-            "spanNulls": false,
-            "stacking": {
-              "group": "A",
-              "mode": "none"
-            },
-            "thresholdsStyle": {
-              "mode": "off"
-            }
-          },
-          "mappings": [],
-          "thresholds": {
-            "mode": "absolute",
-            "steps": [
-              {
-                "color": "green",
-                "value": null
-              },
-              {
-                "color": "red",
-                "value": 80
-              }
-            ]
-          }
-        },
-        "overrides": [
-          {
-            "matcher": {
-              "id": "byName",
-              "options": "OK"
-            },
-            "properties": [
-              {
-                "id": "color",
-                "value": {
-                  "fixedColor": "green",
-                  "mode": "fixed"
-                }
-              }
-            ]
-          },
-          {
-            "matcher": {
-              "id": "byName",
-              "options": "E_DIAL_REFUSED"
-            },
-            "properties": [
-              {
-                "id": "color",
-                "value": {
-                  "fixedColor": "purple",
-                  "mode": "fixed"
-                }
-              }
-            ]
-          },
-          {
-            "matcher": {
-              "id": "byName",
-              "options": "E_DIAL_ERROR"
-            },
-            "properties": [
-              {
-                "id": "color",
-                "value": {
-                  "fixedColor": "purple",
-                  "mode": "fixed"
-                }
-              }
-            ]
-          }
-        ]
-      },
-      "gridPos": {
-        "h": 8,
-        "w": 12,
-        "x": 12,
-        "y": 0
-      },
-      "id": 2,
-      "options": {
-        "legend": {
-          "calcs": [],
-          "displayMode": "list",
-          "placement": "bottom",
-          "showLegend": true
-        },
-        "tooltip": {
-          "maxHeight": 600,
-          "mode": "single",
-          "sort": "none"
-        }
-      },
-      "targets": [
-        {
-          "datasource": {
-            "type": "prometheus",
-            "uid": "${data_source}"
-          },
-          "editorMode": "code",
-          "expr": "sum by (ip_or_dns_version, transport, dial_status) (increase(libp2p_autonatv2_requests_completed_total{instance=~\"$instance\", server_error=\"nil\", response_status=\"OK\"}[$__rate_interval]))\n",
-          "instant": false,
-          "legendFormat": "__auto",
-          "range": true,
-          "refId": "A"
-        }
-      ],
-      "title": "Dial Request by Dial Status",
-      "type": "timeseries"
-    },
-    {
-      "datasource": {
-        "type": "prometheus",
-        "uid": "${data_source}"
-      },
-      "fieldConfig": {
-        "defaults": {
-          "color": {
-            "mode": "palette-classic",
-            "seriesBy": "last"
-          },
-          "custom": {
-            "axisBorderShow": false,
-            "axisCenteredZero": false,
-            "axisColorMode": "text",
-            "axisLabel": "",
-            "axisPlacement": "auto",
-            "barAlignment": 0,
-            "drawStyle": "line",
-            "fillOpacity": 0,
-            "gradientMode": "none",
-            "hideFrom": {
-              "legend": false,
-              "tooltip": false,
-              "viz": false
-            },
-            "insertNulls": false,
-            "lineInterpolation": "linear",
-            "lineWidth": 1,
-            "pointSize": 5,
-            "scaleDistribution": {
-              "type": "linear"
-            },
-            "showPoints": "auto",
-            "spanNulls": false,
-            "stacking": {
-              "group": "A",
-              "mode": "none"
-            },
-            "thresholdsStyle": {
-              "mode": "off"
-            }
-          },
-          "mappings": [],
-          "thresholds": {
-            "mode": "absolute",
-            "steps": [
-              {
-                "color": "green",
-                "value": null
-              },
-              {
-                "color": "red",
-                "value": 80
-              }
-            ]
-          }
-        },
-        "overrides": [
-          {
-            "matcher": {
-              "id": "byName",
-              "options": "OK"
-            },
-            "properties": [
-              {
-                "id": "color",
-                "value": {
-                  "fixedColor": "green",
-                  "mode": "fixed"
-                }
-              }
-            ]
-          },
-          {
-            "matcher": {
-              "id": "byName",
-              "options": "E_DIAL_REFUSED"
-            },
-            "properties": [
-              {
-                "id": "color",
-                "value": {
-                  "fixedColor": "purple",
-                  "mode": "fixed"
-                }
-              }
-            ]
-          },
-          {
-            "matcher": {
-              "id": "byName",
-              "options": "E_DIAL_ERROR"
-            },
-            "properties": [
-              {
-                "id": "color",
-                "value": {
-                  "fixedColor": "purple",
-                  "mode": "fixed"
-                }
-              }
-            ]
-          }
-        ]
-      },
-      "gridPos": {
-        "h": 8,
-        "w": 12,
-        "x": 5,
-        "y": 8
-      },
-      "id": 3,
-      "options": {
-        "legend": {
-          "calcs": [],
-          "displayMode": "list",
-          "placement": "bottom",
-          "showLegend": true
-        },
-        "tooltip": {
-          "maxHeight": 600,
-          "mode": "single",
-          "sort": "none"
-        }
-      },
-      "targets": [
-        {
-          "datasource": {
-            "type": "prometheus",
-            "uid": "${data_source}"
-          },
-          "editorMode": "code",
-          "expr": "sum by (server_error) (increase(libp2p_autonatv2_requests_completed_total{instance=~\"$instance\", server_error!=\"nil\"}[$__rate_interval]))\n",
-          "instant": false,
-          "legendFormat": "__auto",
-          "range": true,
-          "refId": "A"
-        }
-      ],
-      "title": "Dial Request Errors",
-      "type": "timeseries"
-    }
-  ],
-  "refresh": "",
-  "schemaVersion": 39,
-  "tags": [],
-  "templating": {
-    "list": [
-      {
-        "allValue": "",
-        "current": {
-          "selected": true,
-          "text": [
-            "All"
-          ],
-          "value": [
-            "$__all"
-          ]
-        },
-        "definition": "label_values(up,instance)",
-        "hide": 0,
-        "includeAll": true,
-        "label": "instance",
-        "multi": true,
-        "name": "instance",
-        "options": [],
-        "query": {
-          "qryType": 1,
-          "query": "label_values(up,instance)",
-          "refId": "PrometheusVariableQueryEditor-VariableQuery"
-        },
-        "refresh": 1,
-        "regex": "",
-        "skipUrlSync": false,
-        "sort": 0,
-        "type": "query"
-      },
-      {
-        "hide": 0,
-        "includeAll": false,
-        "label": "",
-        "multi": false,
-        "name": "data_source",
-        "options": [],
-        "query": "prometheus",
-        "queryValue": "",
-        "refresh": 1,
-        "regex": "",
-        "skipUrlSync": false,
-        "type": "datasource"
-      }
-    ]
-  },
-  "time": {
-    "from": "now-1h",
-    "to": "now"
-  },
-  "timeRangeUpdatedDuringEditOrView": false,
-  "timepicker": {},
-  "timezone": "browser",
-  "title": "go-libp2p autoNATv2",
-  "uid": "cdpusyp3xtfcwa",
-  "version": 1,
-  "weekStart": ""
-}
\ No newline at end of file
diff --git a/go.mod b/go.mod
index d9038066..52737974 100644
--- a/go.mod
+++ b/go.mod
@@ -55,7 +55,7 @@ require (
 	github.com/quic-go/webtransport-go v0.8.0
 	github.com/raulk/go-watchdog v1.3.0
 	github.com/stretchr/testify v1.9.0
-	go.uber.org/fx v1.22.1
+	go.uber.org/fx v1.22.0
 	go.uber.org/goleak v1.3.0
 	go.uber.org/mock v0.4.0
 	golang.org/x/crypto v0.23.0
diff --git a/go.sum b/go.sum
index 8cf26679..0d5cfeca 100644
--- a/go.sum
+++ b/go.sum
@@ -415,8 +415,8 @@ go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
 go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
 go.uber.org/dig v1.17.1 h1:Tga8Lz8PcYNsWsyHMZ1Vm0OQOUaJNDyvPImgbAu9YSc=
 go.uber.org/dig v1.17.1/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE=
-go.uber.org/fx v1.22.1 h1:nvvln7mwyT5s1q201YE29V/BFrGor6vMiDNpU/78Mys=
-go.uber.org/fx v1.22.1/go.mod h1:HT2M7d7RHo+ebKGh9NRcrsrHHfpZ60nW3QRubMRfv48=
+go.uber.org/fx v1.22.0 h1:pApUK7yL0OUHMd8vkunWSlLxZVFFk70jR2nKde8X2NM=
+go.uber.org/fx v1.22.0/go.mod h1:HT2M7d7RHo+ebKGh9NRcrsrHHfpZ60nW3QRubMRfv48=
 go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
 go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
 go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go
index 6c894403..766b1b13 100644
--- a/p2p/host/basic/basic_host.go
+++ b/p2p/host/basic/basic_host.go
@@ -316,11 +316,7 @@ func NewHost(n network.Network, opts *HostOpts) (*BasicHost, error) {
 	}
 
 	if opts.EnableAutoNATv2 {
-		var mt autonatv2.MetricsTracer
-		if opts.EnableMetrics {
-			mt = autonatv2.NewMetricsTracer(opts.PrometheusRegisterer)
-		}
-		h.autonatv2, err = autonatv2.New(h, opts.AutoNATv2Dialer, autonatv2.WithMetricsTracer(mt))
+		h.autonatv2, err = autonatv2.New(h, opts.AutoNATv2Dialer)
 		if err != nil {
 			return nil, fmt.Errorf("failed to create autonatv2: %w", err)
 		}
diff --git a/p2p/host/peerstore/pstoreds/protobook.go b/p2p/host/peerstore/pstoreds/protobook.go
index 40fa7d95..9ef7d1c9 100644
--- a/p2p/host/peerstore/pstoreds/protobook.go
+++ b/p2p/host/peerstore/pstoreds/protobook.go
@@ -48,7 +48,7 @@ func NewProtoBook(meta pstore.PeerMetadata, opts ...ProtoBookOption) (*dsProtoBo
 			}
 			return ret
 		}(),
-		maxProtos: 1024,
+		maxProtos: 128,
 	}
 
 	for _, opt := range opts {
diff --git a/p2p/host/peerstore/pstoremem/protobook.go b/p2p/host/peerstore/pstoremem/protobook.go
index 51c4b028..b28ffe11 100644
--- a/p2p/host/peerstore/pstoremem/protobook.go
+++ b/p2p/host/peerstore/pstoremem/protobook.go
@@ -26,9 +26,6 @@ type memoryProtoBook struct {
 	segments protoSegments
 
 	maxProtos int
-
-	lk       sync.RWMutex
-	interned map[protocol.ID]protocol.ID
 }
 
 var _ pstore.ProtoBook = (*memoryProtoBook)(nil)
@@ -44,7 +41,6 @@ func WithMaxProtocols(num int) ProtoBookOption {
 
 func NewProtoBook(opts ...ProtoBookOption) (*memoryProtoBook, error) {
 	pb := &memoryProtoBook{
-		interned: make(map[protocol.ID]protocol.ID, 256),
 		segments: func() (ret protoSegments) {
 			for i := range ret {
 				ret[i] = &protoSegment{
@@ -53,7 +49,7 @@ func NewProtoBook(opts ...ProtoBookOption) (*memoryProtoBook, error) {
 			}
 			return ret
 		}(),
-		maxProtos: 1024,
+		maxProtos: 128,
 	}
 
 	for _, opt := range opts {
@@ -64,30 +60,6 @@ func NewProtoBook(opts ...ProtoBookOption) (*memoryProtoBook, error) {
 	return pb, nil
 }
 
-func (pb *memoryProtoBook) internProtocol(proto protocol.ID) protocol.ID {
-	// check if it is interned with the read lock
-	pb.lk.RLock()
-	interned, ok := pb.interned[proto]
-	pb.lk.RUnlock()
-
-	if ok {
-		return interned
-	}
-
-	// intern with the write lock
-	pb.lk.Lock()
-	defer pb.lk.Unlock()
-
-	// check again in case it got interned in between locks
-	interned, ok = pb.interned[proto]
-	if ok {
-		return interned
-	}
-
-	pb.interned[proto] = proto
-	return proto
-}
-
 func (pb *memoryProtoBook) SetProtocols(p peer.ID, protos ...protocol.ID) error {
 	if len(protos) > pb.maxProtos {
 		return errTooManyProtocols
@@ -95,7 +67,7 @@ func (pb *memoryProtoBook) SetProtocols(p peer.ID, protos ...protocol.ID) error
 
 	newprotos := make(map[protocol.ID]struct{}, len(protos))
 	for _, proto := range protos {
-		newprotos[pb.internProtocol(proto)] = struct{}{}
+		newprotos[proto] = struct{}{}
 	}
 
 	s := pb.segments.get(p)
@@ -121,7 +93,7 @@ func (pb *memoryProtoBook) AddProtocols(p peer.ID, protos ...protocol.ID) error
 	}
 
 	for _, proto := range protos {
-		protomap[pb.internProtocol(proto)] = struct{}{}
+		protomap[proto] = struct{}{}
 	}
 	return nil
 }
@@ -151,7 +123,10 @@ func (pb *memoryProtoBook) RemoveProtocols(p peer.ID, protos ...protocol.ID) err
 	}
 
 	for _, proto := range protos {
-		delete(protomap, pb.internProtocol(proto))
+		delete(protomap, proto)
+	}
+	if len(protomap) == 0 {
+		delete(s.protocols, p)
 	}
 	return nil
 }
diff --git a/p2p/protocol/autonatv2/metrics.go b/p2p/protocol/autonatv2/metrics.go
deleted file mode 100644
index baa467f6..00000000
--- a/p2p/protocol/autonatv2/metrics.go
+++ /dev/null
@@ -1,97 +0,0 @@
-package autonatv2
-
-import (
-	"github.com/libp2p/go-libp2p/p2p/metricshelper"
-	"github.com/libp2p/go-libp2p/p2p/protocol/autonatv2/pb"
-	ma "github.com/multiformats/go-multiaddr"
-	"github.com/prometheus/client_golang/prometheus"
-)
-
-type MetricsTracer interface {
-	CompletedRequest(EventDialRequestCompleted)
-}
-
-const metricNamespace = "libp2p_autonatv2"
-
-var (
-	requestsCompleted = prometheus.NewCounterVec(
-		prometheus.CounterOpts{
-			Namespace: metricNamespace,
-			Name:      "requests_completed_total",
-			Help:      "Requests Completed",
-		},
-		[]string{"server_error", "response_status", "dial_status", "dial_data_required", "ip_or_dns_version", "transport"},
-	)
-)
-
-type metricsTracer struct {
-}
-
-func NewMetricsTracer(reg prometheus.Registerer) MetricsTracer {
-	metricshelper.RegisterCollectors(reg, requestsCompleted)
-	return &metricsTracer{}
-}
-
-func (m *metricsTracer) CompletedRequest(e EventDialRequestCompleted) {
-	labels := metricshelper.GetStringSlice()
-	defer metricshelper.PutStringSlice(labels)
-
-	errStr := getErrString(e.Error)
-
-	dialData := "false"
-	if e.DialDataRequired {
-		dialData = "true"
-	}
-
-	var ip, transport string
-	if e.DialedAddr != nil {
-		ip = getIPOrDNSVersion(e.DialedAddr)
-		transport = metricshelper.GetTransport(e.DialedAddr)
-	}
-
-	*labels = append(*labels,
-		errStr,
-		pb.DialResponse_ResponseStatus_name[int32(e.ResponseStatus)],
-		pb.DialStatus_name[int32(e.DialStatus)],
-		dialData,
-		ip,
-		transport,
-	)
-	requestsCompleted.WithLabelValues(*labels...).Inc()
-}
-
-func getIPOrDNSVersion(a ma.Multiaddr) string {
-	if a == nil {
-		return ""
-	}
-	res := "unknown"
-	ma.ForEach(a, func(c ma.Component) bool {
-		switch c.Protocol().Code {
-		case ma.P_IP4:
-			res = "ip4"
-		case ma.P_IP6:
-			res = "ip6"
-		case ma.P_DNS, ma.P_DNSADDR:
-			res = "dns"
-		case ma.P_DNS4:
-			res = "dns4"
-		case ma.P_DNS6:
-			res = "dns6"
-		}
-		return false
-	})
-	return res
-}
-
-func getErrString(e error) string {
-	var errStr string
-	switch e {
-	case nil:
-		errStr = "nil"
-	case errBadRequest, errDialDataRefused, errResourceLimitExceeded:
-		errStr = e.Error()
-	default:
-		errStr = "other"
-	}
-	return errStr
-}
diff --git a/p2p/protocol/autonatv2/options.go b/p2p/protocol/autonatv2/options.go
index 15268f62..5cdb0fe9 100644
--- a/p2p/protocol/autonatv2/options.go
+++ b/p2p/protocol/autonatv2/options.go
@@ -11,7 +11,6 @@ type autoNATSettings struct {
 	dataRequestPolicy                    dataRequestPolicyFunc
 	now                                  func() time.Time
 	amplificatonAttackPreventionDialWait time.Duration
-	metricsTracer                        MetricsTracer
 }
 
 func defaultSettings() *autoNATSettings {
@@ -37,13 +36,6 @@ func WithServerRateLimit(rpm, perPeerRPM, dialDataRPM int) AutoNATOption {
 	}
 }
 
-func WithMetricsTracer(m MetricsTracer) AutoNATOption {
-	return func(s *autoNATSettings) error {
-		s.metricsTracer = m
-		return nil
-	}
-}
-
 func withDataRequestPolicy(drp dataRequestPolicyFunc) AutoNATOption {
 	return func(s *autoNATSettings) error {
 		s.dataRequestPolicy = drp
diff --git a/p2p/protocol/autonatv2/server.go b/p2p/protocol/autonatv2/server.go
index c5dd2dce..12a6fa78 100644
--- a/p2p/protocol/autonatv2/server.go
+++ b/p2p/protocol/autonatv2/server.go
@@ -2,7 +2,6 @@ package autonatv2
 
 import (
 	"context"
-	"errors"
 	"fmt"
 	"io"
 	"sync"
@@ -22,22 +21,8 @@ import (
 	manet "github.com/multiformats/go-multiaddr/net"
 )
 
-var (
-	errResourceLimitExceeded = errors.New("resource limit exceeded")
-	errBadRequest            = errors.New("bad request")
-	errDialDataRefused       = errors.New("dial data refused")
-)
-
 type dataRequestPolicyFunc = func(s network.Stream, dialAddr ma.Multiaddr) bool
 
-type EventDialRequestCompleted struct {
-	Error            error
-	ResponseStatus   pb.DialResponse_ResponseStatus
-	DialStatus       pb.DialStatus
-	DialDataRequired bool
-	DialedAddr       ma.Multiaddr
-}
-
 // server implements the AutoNATv2 server.
 // It can ask client to provide dial data before attempting the requested dial.
 // It rate limits requests on a global level, per peer level and on whether the request requires dial data.
@@ -50,7 +35,6 @@ type server struct {
 	// dial data. It is set to amplification attack prevention by default.
 	dialDataRequestPolicy                dataRequestPolicyFunc
 	amplificatonAttackPreventionDialWait time.Duration
-	metricsTracer                        MetricsTracer
 
 	// for tests
 	now               func() time.Time
@@ -70,8 +54,7 @@ func newServer(host, dialer host.Host, s *autoNATSettings) *server {
 			DialDataRPM: s.serverDialDataRPM,
 			now:         s.now,
 		},
-		now:           s.now,
-		metricsTracer: s.metricsTracer,
+		now: s.now,
 	}
 }
 
@@ -88,27 +71,16 @@ func (as *server) Close() {
 
 // handleDialRequest is the dial-request protocol stream handler
 func (as *server) handleDialRequest(s network.Stream) {
-	evt := as.serveDialRequest(s)
-	log.Debugf("completed dial-request from %s, response status: %s, dial status: %s, err: %s",
-		s.Conn().RemotePeer(), evt.ResponseStatus, evt.DialStatus, evt.Error)
-	if as.metricsTracer != nil {
-		as.metricsTracer.CompletedRequest(evt)
-	}
-}
-
-func (as *server) serveDialRequest(s network.Stream) EventDialRequestCompleted {
 	if err := s.Scope().SetService(ServiceName); err != nil {
 		s.Reset()
-		log.Debugf("failed to attach stream to %s service: %w", ServiceName, err)
-		return EventDialRequestCompleted{
-			Error: errors.New("failed to attach stream to autonat-v2"),
-		}
+		log.Debugf("failed to attach stream to service %s: %w", ServiceName, err)
+		return
 	}
 
 	if err := s.Scope().ReserveMemory(maxMsgSize, network.ReservationPriorityAlways); err != nil {
 		s.Reset()
 		log.Debugf("failed to reserve memory for stream %s: %w", DialProtocol, err)
-		return EventDialRequestCompleted{Error: errResourceLimitExceeded}
+		return
 	}
 	defer s.Scope().ReleaseMemory(maxMsgSize)
 
@@ -134,13 +106,10 @@ func (as *server) serveDialRequest(s network.Stream) EventDialRequestCompleted {
 		if err := w.WriteMsg(&msg); err != nil {
 			s.Reset()
 			log.Debugf("failed to write request rejected response to %s: %s", p, err)
-			return EventDialRequestCompleted{
-				ResponseStatus: pb.DialResponse_E_REQUEST_REJECTED,
-				Error:          fmt.Errorf("write failed: %w", err),
-			}
+			return
 		}
 		log.Debugf("rejected request from %s: rate limit exceeded", p)
-		return EventDialRequestCompleted{ResponseStatus: pb.DialResponse_E_REQUEST_REJECTED}
+		return
 	}
 	defer as.limiter.CompleteRequest(p)
 
@@ -148,12 +117,12 @@ func (as *server) serveDialRequest(s network.Stream) EventDialRequestCompleted {
 	if err := r.ReadMsg(&msg); err != nil {
 		s.Reset()
 		log.Debugf("failed to read request from %s: %s", p, err)
-		return EventDialRequestCompleted{Error: fmt.Errorf("read failed: %w", err)}
+		return
 	}
 	if msg.GetDialRequest() == nil {
 		s.Reset()
 		log.Debugf("invalid message type from %s: %T expected: DialRequest", p, msg.Msg)
-		return EventDialRequestCompleted{Error: errBadRequest}
+		return
 	}
 
 	// parse peer's addresses
@@ -189,14 +158,9 @@ func (as *server) serveDialRequest(s network.Stream) EventDialRequestCompleted {
 		if err := w.WriteMsg(&msg); err != nil {
 			s.Reset()
 			log.Debugf("failed to write dial refused response to %s: %s", p, err)
-			return EventDialRequestCompleted{
-				ResponseStatus: pb.DialResponse_E_DIAL_REFUSED,
-				Error:          fmt.Errorf("write failed: %w", err),
-			}
-		}
-		return EventDialRequestCompleted{
-			ResponseStatus: pb.DialResponse_E_DIAL_REFUSED,
+			return
 		}
+		return
 	}
 
 	nonce := msg.GetDialRequest().Nonce
@@ -213,28 +177,17 @@ func (as *server) serveDialRequest(s network.Stream) EventDialRequestCompleted {
 		if err := w.WriteMsg(&msg); err != nil {
 			s.Reset()
 			log.Debugf("failed to write request rejected response to %s: %s", p, err)
-			return EventDialRequestCompleted{
-				ResponseStatus:   pb.DialResponse_E_REQUEST_REJECTED,
-				Error:            fmt.Errorf("write failed: %w", err),
-				DialDataRequired: true,
-			}
+			return
 		}
 		log.Debugf("rejected request from %s: rate limit exceeded", p)
-		return EventDialRequestCompleted{
-			ResponseStatus:   pb.DialResponse_E_REQUEST_REJECTED,
-			DialDataRequired: true,
-		}
+		return
 	}
 
 	if isDialDataRequired {
 		if err := getDialData(w, s, &msg, addrIdx); err != nil {
 			s.Reset()
 			log.Debugf("%s refused dial data request: %s", p, err)
-			return EventDialRequestCompleted{
-				Error:            errDialDataRefused,
-				DialDataRequired: true,
-				DialedAddr:       dialAddr,
-			}
+			return
 		}
 		// wait for a bit to prevent thundering herd style attacks on a victim
 		waitTime := time.Duration(rand.Intn(int(as.amplificatonAttackPreventionDialWait) + 1)) // the range is [0, n)
@@ -244,7 +197,7 @@ func (as *server) serveDialRequest(s network.Stream) EventDialRequestCompleted {
 		case <-ctx.Done():
 			s.Reset()
 			log.Debugf("rejecting request without dialing: %s %p ", p, ctx.Err())
-			return EventDialRequestCompleted{Error: ctx.Err(), DialDataRequired: true, DialedAddr: dialAddr}
+			return
 		case <-t.C:
 		}
 	}
@@ -262,20 +215,7 @@ func (as *server) serveDialRequest(s network.Stream) EventDialRequestCompleted {
 	if err := w.WriteMsg(&msg); err != nil {
 		s.Reset()
 		log.Debugf("failed to write response to %s: %s", p, err)
-		return EventDialRequestCompleted{
-			ResponseStatus:   pb.DialResponse_OK,
-			DialStatus:       dialStatus,
-			Error:            fmt.Errorf("write failed: %w", err),
-			DialDataRequired: isDialDataRequired,
-			DialedAddr:       dialAddr,
-		}
-	}
-	return EventDialRequestCompleted{
-		ResponseStatus:   pb.DialResponse_OK,
-		DialStatus:       dialStatus,
-		Error:            nil,
-		DialDataRequired: isDialDataRequired,
-		DialedAddr:       dialAddr,
+		return
 	}
 }
 


Test patch:
diff --git a/p2p/protocol/autonatv2/metrics_test.go b/p2p/protocol/autonatv2/metrics_test.go
deleted file mode 100644
index 78671514..00000000
--- a/p2p/protocol/autonatv2/metrics_test.go
+++ /dev/null
@@ -1,51 +0,0 @@
-package autonatv2
-
-import (
-	"errors"
-	"math/rand"
-	"testing"
-
-	"github.com/libp2p/go-libp2p/p2p/protocol/autonatv2/pb"
-	ma "github.com/multiformats/go-multiaddr"
-	"github.com/prometheus/client_golang/prometheus"
-)
-
-func TestMetricsNoAllocNoCover(t *testing.T) {
-	mt := NewMetricsTracer(prometheus.DefaultRegisterer)
-	respStatuses := []pb.DialResponse_ResponseStatus{
-		pb.DialResponse_E_DIAL_REFUSED,
-		pb.DialResponse_OK,
-	}
-	dialStatuses := []pb.DialStatus{
-		pb.DialStatus_OK,
-		pb.DialStatus_E_DIAL_BACK_ERROR,
-	}
-	errs := []error{
-		nil,
-		errBadRequest,
-		errDialDataRefused,
-		errors.New("write failed"),
-	}
-	addrs := []ma.Multiaddr{
-		nil,
-		ma.StringCast("/ip4/1.2.3.4/udp/1/quic-v1"),
-		ma.StringCast("/ip4/1.1.1.1/tcp/1/"),
-	}
-	tests := map[string]func(){
-		"CompletedRequest": func() {
-			mt.CompletedRequest(EventDialRequestCompleted{
-				Error:            errs[rand.Intn(len(errs))],
-				ResponseStatus:   respStatuses[rand.Intn(len(respStatuses))],
-				DialStatus:       dialStatuses[rand.Intn(len(dialStatuses))],
-				DialDataRequired: rand.Intn(2) == 1,
-				DialedAddr:       addrs[rand.Intn(len(addrs))],
-			})
-		},
-	}
-	for method, f := range tests {
-		allocs := testing.AllocsPerRun(10000, f)
-		if allocs > 0 {
-			t.Fatalf("%s alloc test failed expected 0 received %0.2f", method, allocs)
-		}
-	}
-}
diff --git a/p2p/protocol/identify/id_test.go b/p2p/protocol/identify/id_test.go
index a65d64f2..904e47ce 100644
--- a/p2p/protocol/identify/id_test.go
+++ b/p2p/protocol/identify/id_test.go
@@ -4,6 +4,7 @@ import (
 	"context"
 	"errors"
 	"fmt"
+	"math/rand"
 	"slices"
 	"sync"
 	"testing"
@@ -730,6 +731,15 @@ func TestLargeIdentifyMessage(t *testing.T) {
 	}
 }
 
+func randString(n int) string {
+	chars := "abcdefghijklmnopqrstuvwxyz"
+	buf := make([]byte, n)
+	for i := 0; i < n; i++ {
+		buf[i] = chars[rand.Intn(len(chars))]
+	}
+	return string(buf)
+}
+
 func TestLargePushMessage(t *testing.T) {
 	ctx, cancel := context.WithCancel(context.Background())
 	defer cancel()
@@ -738,9 +748,9 @@ func TestLargePushMessage(t *testing.T) {
 	h2 := blhost.NewBlankHost(swarmt.GenSwarm(t))
 
 	// add protocol strings to make the message larger
-	// about 2K of protocol strings
-	for i := 0; i < 500; i++ {
-		r := protocol.ID(fmt.Sprintf("rand%d", i))
+	// about 3K of protocol strings
+	for i := 0; i < 100; i++ {
+		r := protocol.ID(fmt.Sprintf("%s-%d", randString(30), i))
 		h1.SetStreamHandler(r, func(network.Stream) {})
 		h2.SetStreamHandler(r, func(network.Stream) {})
 	}
diff --git a/test-plans/go.mod b/test-plans/go.mod
index 823570c6..f0cf86aa 100644
--- a/test-plans/go.mod
+++ b/test-plans/go.mod
@@ -93,7 +93,7 @@ require (
 	github.com/spaolacci/murmur3 v1.1.0 // indirect
 	github.com/stretchr/testify v1.9.0 // indirect
 	go.uber.org/dig v1.17.1 // indirect
-	go.uber.org/fx v1.22.1 // indirect
+	go.uber.org/fx v1.22.0 // indirect
 	go.uber.org/mock v0.4.0 // indirect
 	go.uber.org/multierr v1.11.0 // indirect
 	go.uber.org/zap v1.27.0 // indirect
diff --git a/test-plans/go.sum b/test-plans/go.sum
index b6cb55bf..e94d7dcc 100644
--- a/test-plans/go.sum
+++ b/test-plans/go.sum
@@ -350,8 +350,8 @@ go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA=
 go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
 go.uber.org/dig v1.17.1 h1:Tga8Lz8PcYNsWsyHMZ1Vm0OQOUaJNDyvPImgbAu9YSc=
 go.uber.org/dig v1.17.1/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE=
-go.uber.org/fx v1.22.1 h1:nvvln7mwyT5s1q201YE29V/BFrGor6vMiDNpU/78Mys=
-go.uber.org/fx v1.22.1/go.mod h1:HT2M7d7RHo+ebKGh9NRcrsrHHfpZ60nW3QRubMRfv48=
+go.uber.org/fx v1.22.0 h1:pApUK7yL0OUHMd8vkunWSlLxZVFFk70jR2nKde8X2NM=
+go.uber.org/fx v1.22.0/go.mod h1:HT2M7d7RHo+ebKGh9NRcrsrHHfpZ60nW3QRubMRfv48=
 go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
 go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
 go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=