diff --git a/waku/v2/protocol/relay/waku_relay.go b/waku/v2/protocol/relay/waku_relay.go index f2fd823b..05fc823d 100644 --- a/waku/v2/protocol/relay/waku_relay.go +++ b/waku/v2/protocol/relay/waku_relay.go @@ -459,37 +459,28 @@ func (w *WakuRelay) Unsubscribe(ctx context.Context, contentFilter waku_proto.Co defer w.topicsMutex.Unlock() for pubSubTopic, cTopics := range pubSubTopicMap { - cfTemp := waku_proto.NewContentFilter(pubSubTopic, cTopics...) pubsubUnsubscribe := false - sub, ok := w.topics[pubSubTopic] + topicData, ok := w.topics[pubSubTopic] if !ok { w.log.Error("not subscribed to topic", zap.String("topic", pubSubTopic)) return errors.New("not subscribed to topic") } - topicData, ok := w.topics[pubSubTopic] - if ok { - //Remove relevant subscription - for subID, sub := range topicData.contentSubs { - if sub.contentFilter.Equals(cfTemp) { - sub.Unsubscribe() - delete(topicData.contentSubs, subID) - } + cfTemp := waku_proto.NewContentFilter(pubSubTopic, cTopics...) + //Remove relevant subscription + for subID, sub := range topicData.contentSubs { + if sub.contentFilter.Equals(cfTemp) { + sub.Unsubscribe() + delete(topicData.contentSubs, subID) } + } - if len(topicData.contentSubs) == 0 { - pubsubUnsubscribe = true - } - } else { - //Should not land here ideally - w.log.Error("pubsub subscriptions exists, but contentSubscription doesn't for contentFilter", - zap.String("pubsubTopic", pubSubTopic), zap.Strings("contentTopics", cTopics)) - - return errors.New("unexpected error in unsubscribe") + if len(topicData.contentSubs) == 0 { + pubsubUnsubscribe = true } if pubsubUnsubscribe { - err = w.unsubscribeFromPubsubTopic(sub) + err = w.unsubscribeFromPubsubTopic(topicData) if err != nil { return err }