Skip to content

Commit

Permalink
fix(rln): error in api when rate limit (#2212)
Browse files Browse the repository at this point in the history
  • Loading branch information
alrevuelta committed Nov 21, 2023
1 parent c973b85 commit 51f3609
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions waku/waku_api/jsonrpc/relay/handlers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ proc installRelayApiHandlers*(node: WakuNode, server: RpcServer, cache: MessageC
server.rpc("post_waku_v2_relay_v1_subscriptions") do (pubsubTopics: seq[PubsubTopic]) -> bool:
if pubsubTopics.len == 0:
raise newException(ValueError, "No pubsub topic provided")

## Subscribes a node to a list of PubSub topics
debug "post_waku_v2_relay_v1_subscriptions"

Expand All @@ -55,7 +55,7 @@ proc installRelayApiHandlers*(node: WakuNode, server: RpcServer, cache: MessageC
server.rpc("delete_waku_v2_relay_v1_subscriptions") do (pubsubTopics: seq[PubsubTopic]) -> bool:
if pubsubTopics.len == 0:
raise newException(ValueError, "No pubsub topic provided")

## Unsubscribes a node from a list of PubSub topics
debug "delete_waku_v2_relay_v1_subscriptions"

Expand All @@ -74,7 +74,7 @@ proc installRelayApiHandlers*(node: WakuNode, server: RpcServer, cache: MessageC
server.rpc("post_waku_v2_relay_v1_message") do (pubsubTopic: PubsubTopic, msg: WakuMessageRPC) -> bool:
if pubsubTopic == "":
raise newException(ValueError, "Empty pubsub topic")

## Publishes a WakuMessage to a PubSub topic
debug "post_waku_v2_relay_v1_message", pubsubTopic=pubsubTopic

Expand Down Expand Up @@ -107,7 +107,7 @@ proc installRelayApiHandlers*(node: WakuNode, server: RpcServer, cache: MessageC
if not success:
raise newException(ValueError, "Failed to publish: error appending RLN proof to message")
# validate the message before sending it
let result = node.wakuRlnRelay.validateMessage(message)
let result = node.wakuRlnRelay.validateMessageAndUpdateLog(message)
if result == MessageValidationResult.Invalid:
raise newException(ValueError, "Failed to publish: invalid RLN proof")
elif result == MessageValidationResult.Spam:
Expand All @@ -128,7 +128,7 @@ proc installRelayApiHandlers*(node: WakuNode, server: RpcServer, cache: MessageC
server.rpc("get_waku_v2_relay_v1_messages") do (pubsubTopic: PubsubTopic) -> seq[WakuMessageRPC]:
if pubsubTopic == "":
raise newException(ValueError, "Empty pubsub topic")

## Returns all WakuMessages received on a PubSub topic since the
## last time this method was called
debug "get_waku_v2_relay_v1_messages", topic=pubsubTopic
Expand All @@ -144,7 +144,7 @@ proc installRelayApiHandlers*(node: WakuNode, server: RpcServer, cache: MessageC
server.rpc("post_waku_v2_relay_v1_auto_subscriptions") do (contentTopics: seq[ContentTopic]) -> bool:
if contentTopics.len == 0:
raise newException(ValueError, "No content topic provided")

## Subscribes a node to a list of Content topics
debug "post_waku_v2_relay_v1_auto_subscriptions"

Expand All @@ -163,7 +163,7 @@ proc installRelayApiHandlers*(node: WakuNode, server: RpcServer, cache: MessageC
server.rpc("delete_waku_v2_relay_v1_auto_subscriptions") do (contentTopics: seq[ContentTopic]) -> bool:
if contentTopics.len == 0:
raise newException(ValueError, "No content topic provided")

## Unsubscribes a node from a list of Content topics
debug "delete_waku_v2_relay_v1_auto_subscriptions"

Expand Down Expand Up @@ -197,7 +197,7 @@ proc installRelayApiHandlers*(node: WakuNode, server: RpcServer, cache: MessageC
timestamp: msg.timestamp.get(Timestamp(0)),
ephemeral: msg.ephemeral.get(false)
)

# if RLN is mounted, append the proof to the message
if not node.wakuRlnRelay.isNil():
# append the proof to the message
Expand All @@ -206,7 +206,7 @@ proc installRelayApiHandlers*(node: WakuNode, server: RpcServer, cache: MessageC
if not success:
raise newException(ValueError, "Failed to publish: error appending RLN proof to message")
# validate the message before sending it
let result = node.wakuRlnRelay.validateMessage(message)
let result = node.wakuRlnRelay.validateMessageAndUpdateLog(message)
if result == MessageValidationResult.Invalid:
raise newException(ValueError, "Failed to publish: invalid RLN proof")
elif result == MessageValidationResult.Spam:
Expand All @@ -227,7 +227,7 @@ proc installRelayApiHandlers*(node: WakuNode, server: RpcServer, cache: MessageC
server.rpc("get_waku_v2_relay_v1_auto_messages") do (contentTopic: ContentTopic) -> seq[WakuMessageRPC]:
if contentTopic == "":
raise newException(ValueError, "Empty content topic")

## Returns all WakuMessages received on a Content topic since the
## last time this method was called
debug "get_waku_v2_relay_v1_auto_messages", topic=contentTopic
Expand All @@ -236,4 +236,4 @@ proc installRelayApiHandlers*(node: WakuNode, server: RpcServer, cache: MessageC
if msgRes.isErr():
raise newException(ValueError, "Not subscribed to content topic: " & contentTopic)

return msgRes.value.map(toWakuMessageRPC)
return msgRes.value.map(toWakuMessageRPC)
4 changes: 2 additions & 2 deletions waku/waku_api/rest/relay/handlers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ proc installRelayApiHandlers*(router: var RestRouter, node: WakuNode, cache: Mes
return RestApiResponse.internalServerError("Failed to publish: error appending RLN proof to message")

# validate the message before sending it
let result = node.wakuRlnRelay.validateMessage(message)
let result = node.wakuRlnRelay.validateMessageAndUpdateLog(message)
if result == MessageValidationResult.Invalid:
return RestApiResponse.internalServerError("Failed to publish: invalid RLN proof")
elif result == MessageValidationResult.Spam:
Expand Down Expand Up @@ -244,7 +244,7 @@ proc installRelayApiHandlers*(router: var RestRouter, node: WakuNode, cache: Mes
return RestApiResponse.internalServerError("Failed to publish: error appending RLN proof to message")

# validate the message before sending it
let result = node.wakuRlnRelay.validateMessage(message)
let result = node.wakuRlnRelay.validateMessageAndUpdateLog(message)
if result == MessageValidationResult.Invalid:
return RestApiResponse.internalServerError("Failed to publish: invalid RLN proof")
elif result == MessageValidationResult.Spam:
Expand Down

0 comments on commit 51f3609

Please sign in to comment.