Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Revert lightpush error handling to allow zero peer publish again succeed #2099

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions tests/wakunode_rest/test_rest_lightpush.nim
Original file line number Diff line number Diff line change
Expand Up @@ -171,24 +171,27 @@ suite "Waku v2 Rest API - lightpush":

await restLightPushTest.shutdown()

asyncTest "Push message request service not available":
# Given
let restLightPushTest = await RestLightPushTest.init()

# When
let message : RelayWakuMessage = fakeWakuMessage(contentTopic = DefaultContentTopic,
payload = toBytes("TEST-1")).toRelayWakuMessage()

let requestBody = PushRequest(pubsubTopic: some("NoExistTopic"),
message: message)
let response = await restLightPushTest.client.sendPushRequest(requestBody)

echo "response", $response

# Then
check:
response.status == 503
$response.contentType == $MIMETYPE_TEXT
response.data == "Failed to request a message push: Can not publish to any peers"

await restLightPushTest.shutdown()
## TODO: Re-work this test when lightpush protocol change is done: https://github.com/waku-org/pm/issues/93
## This test is similar when no available peer exists for publish. Currently it is returning success,
## that makes this test not useful.
# asyncTest "Push message request service not available":
# # Given
# let restLightPushTest = await RestLightPushTest.init()

# # When
# let message : RelayWakuMessage = fakeWakuMessage(contentTopic = DefaultContentTopic,
# payload = toBytes("TEST-1")).toRelayWakuMessage()

# let requestBody = PushRequest(pubsubTopic: some("NoExistTopic"),
# message: message)
# let response = await restLightPushTest.client.sendPushRequest(requestBody)

# echo "response", $response

# # Then
# check:
# response.status == 503
# $response.contentType == $MIMETYPE_TEXT
# response.data == "Failed to request a message push: Can not publish to any peers"

# await restLightPushTest.shutdown()
9 changes: 5 additions & 4 deletions waku/node/waku_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ proc registerRelayDefaultHandler(node: WakuNode, topic: PubsubTopic) =
proc subscribe*(node: WakuNode, subscription: SubscriptionEvent, handler = none(WakuRelayHandler)) =
## Subscribes to a PubSub or Content topic. Triggers handler when receiving messages on
## this topic. WakuRelayHandler is a method that takes a topic and a Waku message.

if node.wakuRelay.isNil():
error "Invalid API call to `subscribe`. WakuRelay not mounted."
return
Expand All @@ -242,7 +242,7 @@ proc subscribe*(node: WakuNode, subscription: SubscriptionEvent, handler = none(
(shard, some(subscription.topic))
of PubsubSub: (subscription.topic, none(ContentTopic))
else: return

if contentTopicOp.isSome() and node.contentTopicHandlers.hasKey(contentTopicOp.get()):
error "Invalid API call to `subscribe`. Was already subscribed"
return
Expand All @@ -260,7 +260,7 @@ proc subscribe*(node: WakuNode, subscription: SubscriptionEvent, handler = none(

proc unsubscribe*(node: WakuNode, subscription: SubscriptionEvent) =
## Unsubscribes from a specific PubSub or Content topic.

if node.wakuRelay.isNil():
error "Invalid API call to `unsubscribe`. WakuRelay not mounted."
return
Expand Down Expand Up @@ -876,7 +876,8 @@ proc mountLightPush*(node: WakuNode) {.async.} =
let publishedCount = await node.wakuRelay.publish(pubsubTopic, message.encode().buffer)

if publishedCount == 0:
return err("Can not publish to any peers")
## Agreed change expected to the lightpush protocol to better handle such case. https://github.com/waku-org/pm/issues/93
debug("Lightpush request has not been published to any peers")

return ok()

Expand Down
Loading