Skip to content

Commit

Permalink
Remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
alrevuelta committed Sep 1, 2023
1 parent 0bcc43e commit c964916
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
17 changes: 6 additions & 11 deletions waku/node/jsonrpc/relay/handlers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,17 @@ proc installRelayApiHandlers*(node: WakuNode, server: RpcServer, cache: MessageC
elif result == MessageValidationResult.Spam:
raise newException(ValueError, "Failed to publish: limit exceeded, try again later")
elif result == MessageValidationResult.Valid:
debug "Publishing message WITH RLN proof", pubSubTopic=pubSubTopic
let publishFut = node.publish(pubsubTopic, message)
if not await publishFut.withTimeout(futTimeout):
raise newException(ValueError, "Failed to publish: timed out")
debug "RLN proof validated successfully", pubSubTopic=pubSubTopic
else:
raise newException(ValueError, "Failed to publish: unknown RLN proof validation result")
else:
raise newException(ValueError, "Failed to publish: RLN enabled but not mounted")

# if RLN is not mounted, publish the message as is
else:
debug "Publishing message WITHOUT RLN proof", pubSubTopic=pubSubTopic
let publishFut = node.publish(pubsubTopic, message)

if not await publishFut.withTimeout(futTimeout):
raise newException(ValueError, "Failed to publish: timed out")
# if we reach here its either a non-RLN message or a RLN message with a valid proof
debug "Publishing message", pubSubTopic=pubSubTopic, rln=defined(rln)
let publishFut = node.publish(pubsubTopic, message)
if not await publishFut.withTimeout(futTimeout):
raise newException(ValueError, "Failed to publish: timed out")

return true

Expand Down
16 changes: 6 additions & 10 deletions waku/node/rest/relay/handlers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,17 @@ proc installRelayPostMessagesV1Handler*(router: var RestRouter, node: WakuNode)
elif result == MessageValidationResult.Spam:
return RestApiResponse.badRequest("Failed to publish: limit exceeded, try again later")
elif result == MessageValidationResult.Valid:
debug "Publishing message WITH RLN proof", pubSubTopic=pubSubTopic
let publishFut = node.publish(pubSubTopic, message)
if not await publishFut.withTimeout(futTimeout):
return RestApiResponse.internalServerError("Failed to publish: timed out")
debug "RLN proof validated successfully", pubSubTopic=pubSubTopic
else:
return RestApiResponse.internalServerError("Failed to publish: unknown RLN proof validation result")
else:
return RestApiResponse.internalServerError("Failed to publish: RLN enabled but not mounted")

# if RLN is not enabled, just publish the message
else:
debug "Publishing message WITHOUT RLN proof", pubSubTopic=pubSubTopic
if not (waitFor node.publish(pubSubTopic, resMessage.value).withTimeout(futTimeout)):
error "Failed to publish message to topic", pubSubTopic=pubSubTopic
return RestApiResponse.internalServerError("Failed to publish: timedout")
# if we reach here its either a non-RLN message or a RLN message with a valid proof
debug "Publishing message", pubSubTopic=pubSubTopic, rln=defined(rln)
if not (waitFor node.publish(pubSubTopic, resMessage.value).withTimeout(futTimeout)):
error "Failed to publish message to topic", pubSubTopic=pubSubTopic
return RestApiResponse.internalServerError("Failed to publish: timedout")

return RestApiResponse.ok()

Expand Down

0 comments on commit c964916

Please sign in to comment.