chore: don't return error on double relay subscription/unsubscription (#3429)

This commit is contained in:
gabrielmer 2025-05-29 12:05:48 +02:00 committed by GitHub
parent 768b2785e1
commit 5e22ea18b6
2 changed files with 11 additions and 12 deletions

View File

@ -631,7 +631,7 @@ suite "WakuNode - Relay":
# Stop all nodes # Stop all nodes
await allFutures(nodes.mapIt(it.stop())) await allFutures(nodes.mapIt(it.stop()))
asyncTest "Only one subscription is allowed for contenttopics that generate the same shard": asyncTest "Multiple subscription calls are allowed for contenttopics that generate the same shard":
## Setup ## Setup
let let
nodeKey = generateSecp256k1Key() nodeKey = generateSecp256k1Key()
@ -663,12 +663,12 @@ suite "WakuNode - Relay":
## When ## When
node.subscribe((kind: ContentSub, topic: contentTopicA), some(handler)).isOkOr: node.subscribe((kind: ContentSub, topic: contentTopicA), some(handler)).isOkOr:
assert false, "Failed to subscribe to topic: " & $error assert false, "Failed to subscribe to topic: " & $error
node.subscribe((kind: ContentSub, topic: contentTopicB), some(handler)).isErrOr: node.subscribe((kind: ContentSub, topic: contentTopicB), some(handler)).isOkOr:
assert false, assert false,
"The subscription should fail because is already subscribe to that shard" "The subscription call shouldn't error even though it's already subscribed to that shard"
node.subscribe((kind: ContentSub, topic: contentTopicC), some(handler)).isErrOr: node.subscribe((kind: ContentSub, topic: contentTopicC), some(handler)).isOkOr:
assert false, assert false,
"The subscription should fail because is already subscribe to that shard" "The subscription call shouldn't error even though it's already subscribed to that shard"
## Then ## Then
node.unsubscribe((kind: ContentUnsub, topic: contentTopicB)).isOkOr: node.unsubscribe((kind: ContentUnsub, topic: contentTopicB)).isOkOr:

View File

@ -323,12 +323,12 @@ proc subscribe*(
return err("Unsupported subscription type in relay subscribe") return err("Unsupported subscription type in relay subscribe")
if node.wakuRelay.isSubscribed(pubsubTopic): if node.wakuRelay.isSubscribed(pubsubTopic):
debug "already subscribed to topic", pubsubTopic warn "No-effect API call to subscribe. Already subscribed to topic", pubsubTopic
return err("Already subscribed to topic: " & $pubsubTopic) return ok()
if contentTopicOp.isSome() and node.contentTopicHandlers.hasKey(contentTopicOp.get()): if contentTopicOp.isSome() and node.contentTopicHandlers.hasKey(contentTopicOp.get()):
error "Invalid API call to `subscribe`. Was already subscribed" warn "No-effect API call to `subscribe`. Was already subscribed"
return err("Invalid API call to `subscribe`. Was already subscribed") return ok()
node.topicSubscriptionQueue.emit((kind: PubsubSub, topic: pubsubTopic)) node.topicSubscriptionQueue.emit((kind: PubsubSub, topic: pubsubTopic))
node.registerRelayDefaultHandler(pubsubTopic) node.registerRelayDefaultHandler(pubsubTopic)
@ -364,9 +364,8 @@ proc unsubscribe*(
return err("Unsupported subscription type in relay unsubscribe") return err("Unsupported subscription type in relay unsubscribe")
if not node.wakuRelay.isSubscribed(pubsubTopic): if not node.wakuRelay.isSubscribed(pubsubTopic):
error "Invalid API call to `unsubscribe`. Was not subscribed", pubsubTopic warn "No-effect API call to `unsubscribe`. Was not subscribed", pubsubTopic
return return ok()
err("Invalid API call to `unsubscribe`. Was not subscribed to: " & $pubsubTopic)
if contentTopicOp.isSome(): if contentTopicOp.isSome():
# Remove this handler only # Remove this handler only