Skip to content

Commit

Permalink
remove subscriber checker (#13234)
Browse files Browse the repository at this point in the history
  • Loading branch information
nisdas authored Nov 29, 2023
1 parent 6a638bd commit 9f41375
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
15 changes: 1 addition & 14 deletions beacon-chain/p2p/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ const digestLength = 4
// Specifies the prefix for any pubsub topic.
const gossipTopicPrefix = "/eth2/"

type subscriberChecker interface {
isSubscribedToTopic(topic string) bool
}

// JoinTopic will join PubSub topic, if not already joined.
func (s *Service) JoinTopic(topic string, opts ...pubsub.TopicOpt) (*pubsub.Topic, error) {
s.joinedTopicsLock.Lock()
Expand Down Expand Up @@ -123,15 +119,6 @@ func (s *Service) SubscribeToTopic(topic string, opts ...pubsub.SubOpt) (*pubsub
return topicHandle.Subscribe(opts...)
}

// checks if we are subscribed to the particular topic.
func (s *Service) isSubscribedToTopic(topic string) bool {
s.joinedTopicsLock.RLock()
defer s.joinedTopicsLock.RUnlock()

_, ok := s.joinedTopics[topic]
return ok
}

// peerInspector will scrape all the relevant scoring data and add it to our
// peer handler.
func (s *Service) peerInspector(peerMap map[peer.ID]*pubsub.PeerScoreSnapshot) {
Expand All @@ -158,7 +145,7 @@ func (s *Service) pubsubOptions() []pubsub.Option {
pubsub.WithPeerScore(peerScoringParams()),
pubsub.WithPeerScoreInspect(s.peerInspector, time.Minute),
pubsub.WithGossipSubParams(pubsubGossipParam()),
pubsub.WithRawTracer(gossipTracer{host: s.host, checker: s}),
pubsub.WithRawTracer(gossipTracer{host: s.host}),
}
return psOpts
}
Expand Down
9 changes: 4 additions & 5 deletions beacon-chain/p2p/pubsub_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ const (
// This tracer is used to implement metrics collection for messages received
// and broadcasted through gossipsub.
type gossipTracer struct {
host host.Host
checker subscriberChecker
host host.Host
}

// AddPeer .
Expand Down Expand Up @@ -111,9 +110,9 @@ func (g gossipTracer) setMetricFromRPC(act action, subCtr prometheus.Counter, pu
ctrlCtr.WithLabelValues("iwant").Add(float64(len(rpc.Control.Iwant)))
}
for _, msg := range rpc.Publish {
// For incoming messages from pubsub, we validate that the topics are valid
// before recording metrics for them.
if act == recv && !g.checker.isSubscribedToTopic(*msg.Topic) {
// For incoming messages from pubsub, we do not record metrics for them as these values
// could be junk.
if act == recv {
continue
}
pubCtr.WithLabelValues(*msg.Topic).Inc()
Expand Down

0 comments on commit 9f41375

Please sign in to comment.