Skip to content

Commit ee5932e

Browse files
authored
chore: don't return error on double relay subscription/unsubscription (#3429)
1 parent 91885fb commit ee5932e

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

tests/waku_relay/test_wakunode_relay.nim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ suite "WakuNode - Relay":
631631
# Stop all nodes
632632
await allFutures(nodes.mapIt(it.stop()))
633633

634-
asyncTest "Only one subscription is allowed for contenttopics that generate the same shard":
634+
asyncTest "Multiple subscription calls are allowed for contenttopics that generate the same shard":
635635
## Setup
636636
let
637637
nodeKey = generateSecp256k1Key()
@@ -663,12 +663,12 @@ suite "WakuNode - Relay":
663663
## When
664664
node.subscribe((kind: ContentSub, topic: contentTopicA), some(handler)).isOkOr:
665665
assert false, "Failed to subscribe to topic: " & $error
666-
node.subscribe((kind: ContentSub, topic: contentTopicB), some(handler)).isErrOr:
666+
node.subscribe((kind: ContentSub, topic: contentTopicB), some(handler)).isOkOr:
667667
assert false,
668-
"The subscription should fail because is already subscribe to that shard"
669-
node.subscribe((kind: ContentSub, topic: contentTopicC), some(handler)).isErrOr:
668+
"The subscription call shouldn't error even though it's already subscribed to that shard"
669+
node.subscribe((kind: ContentSub, topic: contentTopicC), some(handler)).isOkOr:
670670
assert false,
671-
"The subscription should fail because is already subscribe to that shard"
671+
"The subscription call shouldn't error even though it's already subscribed to that shard"
672672

673673
## Then
674674
node.unsubscribe((kind: ContentUnsub, topic: contentTopicB)).isOkOr:

waku/node/waku_node.nim

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,12 @@ proc subscribe*(
323323
return err("Unsupported subscription type in relay subscribe")
324324

325325
if node.wakuRelay.isSubscribed(pubsubTopic):
326-
debug "already subscribed to topic", pubsubTopic
327-
return err("Already subscribed to topic: " & $pubsubTopic)
326+
warn "No-effect API call to subscribe. Already subscribed to topic", pubsubTopic
327+
return ok()
328328

329329
if contentTopicOp.isSome() and node.contentTopicHandlers.hasKey(contentTopicOp.get()):
330-
error "Invalid API call to `subscribe`. Was already subscribed"
331-
return err("Invalid API call to `subscribe`. Was already subscribed")
330+
warn "No-effect API call to `subscribe`. Was already subscribed"
331+
return ok()
332332

333333
node.topicSubscriptionQueue.emit((kind: PubsubSub, topic: pubsubTopic))
334334
node.registerRelayDefaultHandler(pubsubTopic)
@@ -364,9 +364,8 @@ proc unsubscribe*(
364364
return err("Unsupported subscription type in relay unsubscribe")
365365

366366
if not node.wakuRelay.isSubscribed(pubsubTopic):
367-
error "Invalid API call to `unsubscribe`. Was not subscribed", pubsubTopic
368-
return
369-
err("Invalid API call to `unsubscribe`. Was not subscribed to: " & $pubsubTopic)
367+
warn "No-effect API call to `unsubscribe`. Was not subscribed", pubsubTopic
368+
return ok()
370369

371370
if contentTopicOp.isSome():
372371
# Remove this handler only

0 commit comments

Comments
 (0)