From 5e22ea18b651e5d603fde4953a8d4f702c4e69c2 Mon Sep 17 00:00:00 2001 From: gabrielmer <101006718+gabrielmer@users.noreply.github.com> Date: Thu, 29 May 2025 12:05:48 +0200 Subject: [PATCH] chore: don't return error on double relay subscription/unsubscription (#3429) --- tests/waku_relay/test_wakunode_relay.nim | 10 +++++----- waku/node/waku_node.nim | 13 ++++++------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/waku_relay/test_wakunode_relay.nim b/tests/waku_relay/test_wakunode_relay.nim index c9c8d82ef..3f6bfd3e7 100644 --- a/tests/waku_relay/test_wakunode_relay.nim +++ b/tests/waku_relay/test_wakunode_relay.nim @@ -631,7 +631,7 @@ suite "WakuNode - Relay": # Stop all nodes 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 let nodeKey = generateSecp256k1Key() @@ -663,12 +663,12 @@ suite "WakuNode - Relay": ## When node.subscribe((kind: ContentSub, topic: contentTopicA), some(handler)).isOkOr: 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, - "The subscription should fail because is already subscribe to that shard" - node.subscribe((kind: ContentSub, topic: contentTopicC), some(handler)).isErrOr: + "The subscription call shouldn't error even though it's already subscribed to that shard" + node.subscribe((kind: ContentSub, topic: contentTopicC), some(handler)).isOkOr: 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 node.unsubscribe((kind: ContentUnsub, topic: contentTopicB)).isOkOr: diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index 152c7125d..1538d9096 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -323,12 +323,12 @@ proc subscribe*( return err("Unsupported subscription type in relay subscribe") if node.wakuRelay.isSubscribed(pubsubTopic): - debug "already subscribed to topic", pubsubTopic - return err("Already subscribed to topic: " & $pubsubTopic) + warn "No-effect API call to subscribe. Already subscribed to topic", pubsubTopic + return ok() if contentTopicOp.isSome() and node.contentTopicHandlers.hasKey(contentTopicOp.get()): - error "Invalid API call to `subscribe`. Was already subscribed" - return err("Invalid API call to `subscribe`. Was already subscribed") + warn "No-effect API call to `subscribe`. Was already subscribed" + return ok() node.topicSubscriptionQueue.emit((kind: PubsubSub, topic: pubsubTopic)) node.registerRelayDefaultHandler(pubsubTopic) @@ -364,9 +364,8 @@ proc unsubscribe*( return err("Unsupported subscription type in relay unsubscribe") if not node.wakuRelay.isSubscribed(pubsubTopic): - error "Invalid API call to `unsubscribe`. Was not subscribed", pubsubTopic - return - err("Invalid API call to `unsubscribe`. Was not subscribed to: " & $pubsubTopic) + warn "No-effect API call to `unsubscribe`. Was not subscribed", pubsubTopic + return ok() if contentTopicOp.isSome(): # Remove this handler only