Skip to content

Commit

Permalink
gracefully handle deduplicated registration of topic validators (#4399)
Browse files Browse the repository at this point in the history
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
prestonvanloon and prylabs-bulldozer[bot] authored Jan 4, 2020
1 parent fd46407 commit 01cf5d7
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions beacon-chain/sync/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ func (r *Service) subscribeWithBase(base proto.Message, topic string, validator
log := log.WithField("topic", topic)

if err := r.p2p.PubSub().RegisterTopicValidator(wrapAndReportValidation(topic, validator)); err != nil {
// Configuring a topic validator would only return an error as a result of misconfiguration
// and is not a runtime concern.
panic(err)
log.WithError(err).Error("Failed to register validator")
}

sub, err := r.p2p.PubSub().Subscribe(topic)
Expand Down Expand Up @@ -219,8 +217,9 @@ func (r *Service) subscribeDynamic(topicFormat string, determineSubsLen func() i
if len(subscriptions) > wantedSubs { // Reduce topics
var cancelSubs []*pubsub.Subscription
subscriptions, cancelSubs = subscriptions[:wantedSubs-1], subscriptions[wantedSubs:]
for _, sub := range cancelSubs {
for i, sub := range cancelSubs {
sub.Cancel()
r.p2p.PubSub().UnregisterTopicValidator(fmt.Sprintf(topicFormat, i+wantedSubs))
}
} else if len(subscriptions) < wantedSubs { // Increase topics
for i := len(subscriptions); i < wantedSubs; i++ {
Expand Down

0 comments on commit 01cf5d7

Please sign in to comment.