remove subscriber checker (#13234)

This commit is contained in:
Nishant Das 2023-11-29 10:11:10 +08:00 committed by GitHub
parent 6a638bd148
commit 9f41375550
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 19 deletions

View File

@ -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()
@ -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) {
@ -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
}

View File

@ -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 .
@ -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()