From c42e7d24e8927b82cdce9091da11cfc70affbcc6 Mon Sep 17 00:00:00 2001 From: stubbsta Date: Thu, 25 Jun 2026 11:39:30 +0200 Subject: [PATCH] allow mountLightPush without wakuRelay --- .../send_service/send_service.nim | 2 +- .../waku/node/waku_node/lightpush.nim | 29 +++++++++++-------- .../waku/waku_lightpush/callbacks.nim | 21 +++++++++++--- .../waku/waku_lightpush_legacy/callbacks.nim | 17 +++++++++-- tests/node/test_wakunode_legacy_lightpush.nim | 10 ++++--- tests/node/test_wakunode_lightpush.nim | 9 +++--- 6 files changed, 60 insertions(+), 28 deletions(-) diff --git a/logos_delivery/messaging/delivery_service/send_service/send_service.nim b/logos_delivery/messaging/delivery_service/send_service/send_service.nim index 67f8de95f..3794d1d3c 100644 --- a/logos_delivery/messaging/delivery_service/send_service/send_service.nim +++ b/logos_delivery/messaging/delivery_service/send_service/send_service.nim @@ -82,7 +82,7 @@ proc setupSendProcessorChain( none[Rln]() else: some(rlnRelay) - let publishProc = getRelayPushHandler(relay, rln) + let publishProc = getRelayPushHandler(some(relay), rln) processors.add(RelaySendProcessor.new(isLightPushAvail, publishProc, brokerCtx)) if isLightPushAvail: diff --git a/logos_delivery/waku/node/waku_node/lightpush.nim b/logos_delivery/waku/node/waku_node/lightpush.nim index 6b9d816fd..58b29b271 100644 --- a/logos_delivery/waku/node/waku_node/lightpush.nim +++ b/logos_delivery/waku/node/waku_node/lightpush.nim @@ -30,23 +30,25 @@ import ../../waku_lightpush as lightpush_protocol, ../peer_manager, ../../common/rate_limit/setting, + ../../waku_relay, ../../rln logScope: topics = "waku node lightpush api" -const MountWithoutRelayError* = "cannot mount lightpush because relay is not mounted" - ## Waku lightpush proc mountLegacyLightPush*( node: WakuNode, rateLimit: RateLimitSetting = DefaultGlobalNonRelayRateLimit ): Future[Result[void, string]] {.async.} = info "mounting legacy light push" - if node.wakuRelay.isNil(): - return err(MountWithoutRelayError) - - info "mounting legacy lightpush with relay" + let wakuRelayOpt = + if node.wakuRelay.isNil(): + info "mounting legacy lightpush without relay" + none(WakuRelay) + else: + info "mounting legacy lightpush with relay" + some(node.wakuRelay) let rlnPeer = if node.rln.isNil(): info "mounting legacy lightpush without rln-relay" @@ -55,7 +57,7 @@ proc mountLegacyLightPush*( info "mounting legacy lightpush with rln-relay" some(node.rln) let pushHandler = - legacy_lightpush_protocol.getRelayPushHandler(node.wakuRelay, rlnPeer) + legacy_lightpush_protocol.getRelayPushHandler(wakuRelayOpt, rlnPeer) node.wakuLegacyLightPush = WakuLegacyLightPush.new(node.peerManager, node.rng, pushHandler, some(rateLimit)) @@ -154,10 +156,13 @@ proc mountLightPush*( ): Future[Result[void, string]] {.async.} = info "mounting light push" - if node.wakuRelay.isNil(): - return err(MountWithoutRelayError) - - info "mounting lightpush with relay" + let wakuRelayOpt = + if node.wakuRelay.isNil(): + info "mounting lightpush without relay" + none(WakuRelay) + else: + info "mounting lightpush with relay" + some(node.wakuRelay) let rlnPeer = if node.rln.isNil(): info "mounting lightpush without rln-relay" @@ -165,7 +170,7 @@ proc mountLightPush*( else: info "mounting lightpush with rln-relay" some(node.rln) - let pushHandler = lightpush_protocol.getRelayPushHandler(node.wakuRelay, rlnPeer) + let pushHandler = lightpush_protocol.getRelayPushHandler(wakuRelayOpt, rlnPeer) node.wakuLightPush = WakuLightPush.new( node.peerManager, node.rng, pushHandler, node.wakuAutoSharding, some(rateLimit) diff --git a/logos_delivery/waku/waku_lightpush/callbacks.nim b/logos_delivery/waku/waku_lightpush/callbacks.nim index 68af190f1..3f66c1ca1 100644 --- a/logos_delivery/waku/waku_lightpush/callbacks.nim +++ b/logos_delivery/waku/waku_lightpush/callbacks.nim @@ -35,7 +35,7 @@ proc getNilPushHandler*(): PushMessageHandler = return lightpushResultInternalError("no waku relay found") proc getRelayPushHandler*( - wakuRelay: WakuRelay, rlnPeer: Option[Rln] = none[Rln]() + wakuRelay: Option[WakuRelay], rlnPeer: Option[Rln] = none[Rln]() ): PushMessageHandler = return proc( pubsubTopic: string, message: WakuMessage @@ -44,10 +44,23 @@ proc getRelayPushHandler*( let msgWithProof = (await checkAndGenerateRLNProof(rlnPeer, message)).valueOr: return lighpushErrorResult(LightPushErrorCode.OUT_OF_RLN_PROOF, error) - (await wakuRelay.validateMessage(pubSubTopic, msgWithProof)).isOkOr: - return lighpushErrorResult(LightPushErrorCode.INVALID_MESSAGE, $error) + # Prefer the relay validator chain when available (preserves the full + # chain, including any non-RLN validators). Fall back to RLN-direct + # when relay is not mounted. + if wakuRelay.isSome(): + (await wakuRelay.get().validateMessage(pubSubTopic, msgWithProof)).isOkOr: + return lighpushErrorResult(LightPushErrorCode.INVALID_MESSAGE, $error) + elif rlnPeer.isSome(): + let validationRes = await rlnPeer.get().validateMessageAndUpdateLog(msgWithProof) + if validationRes != MessageValidationResult.Valid: + return lighpushErrorResult(LightPushErrorCode.INVALID_MESSAGE, $validationRes) - let publishedResult = (await wakuRelay.publish(pubsubTopic, msgWithProof)).valueOr: + if wakuRelay.isNone(): + return lighpushErrorResult( + LightPushErrorCode.SERVICE_NOT_AVAILABLE, "no relay publish path" + ) + + let publishedResult = (await wakuRelay.get().publish(pubsubTopic, msgWithProof)).valueOr: let msgHash = computeMessageHash(pubsubTopic, message).to0xHex() notice "Lightpush request has not been published to any peers", msg_hash = msgHash, reason = $error diff --git a/logos_delivery/waku/waku_lightpush_legacy/callbacks.nim b/logos_delivery/waku/waku_lightpush_legacy/callbacks.nim index 4fc92d516..a026fac5d 100644 --- a/logos_delivery/waku/waku_lightpush_legacy/callbacks.nim +++ b/logos_delivery/waku/waku_lightpush_legacy/callbacks.nim @@ -38,7 +38,7 @@ proc getNilPushHandler*(): PushMessageHandler = return err("no waku relay found") proc getRelayPushHandler*( - wakuRelay: WakuRelay, rlnPeer: Option[Rln] = none[Rln]() + wakuRelay: Option[WakuRelay], rlnPeer: Option[Rln] = none[Rln]() ): PushMessageHandler = return proc( pubsubTopic: string, message: WakuMessage @@ -46,9 +46,20 @@ proc getRelayPushHandler*( # append RLN proof let msgWithProof = ?(await checkAndGenerateRLNProof(rlnPeer, message)) - ?(await wakuRelay.validateMessage(pubSubTopic, msgWithProof)) + # Prefer the relay validator chain when available (preserves the full + # chain, including any non-RLN validators). Fall back to RLN-direct + # when relay is not mounted. + if wakuRelay.isSome(): + ?(await wakuRelay.get().validateMessage(pubSubTopic, msgWithProof)) + elif rlnPeer.isSome(): + let validationRes = await rlnPeer.get().validateMessageAndUpdateLog(msgWithProof) + if validationRes != MessageValidationResult.Valid: + return err($validationRes) - (await wakuRelay.publish(pubsubTopic, msgWithProof)).isOkOr: + if wakuRelay.isNone(): + return err(protocol_metrics.notPublishedAnyPeer) + + (await wakuRelay.get().publish(pubsubTopic, msgWithProof)).isOkOr: ## Agreed change expected to the lightpush protocol to better handle such case. https://github.com/waku-org/pm/issues/93 let msgHash = computeMessageHash(pubsubTopic, message).to0xHex() notice "Lightpush request has not been published to any peers", diff --git a/tests/node/test_wakunode_legacy_lightpush.nim b/tests/node/test_wakunode_legacy_lightpush.nim index 54cc0b6f6..9e25cbaf4 100644 --- a/tests/node/test_wakunode_legacy_lightpush.nim +++ b/tests/node/test_wakunode_legacy_lightpush.nim @@ -230,7 +230,7 @@ suite "Waku Legacy Lightpush message delivery": await allFutures(lightNode.stop(), bridgeNode.stop(), destNode.stop()) suite "Waku Legacy Lightpush mounting behavior": - asyncTest "fails to mount when relay is not mounted": + asyncTest "mounts without relay": ## Given a node without Relay mounted let key = generateSecp256k1Key() @@ -239,8 +239,10 @@ suite "Waku Legacy Lightpush mounting behavior": # Do not mount Relay on purpose check node.wakuRelay.isNil() - ## Then mounting Legacy Lightpush must fail + ## Then mounting Legacy Lightpush should succeed; the handler will + ## return notPublishedAnyPeer on push attempts as long as relay + ## stays absent. let res = await node.mountLegacyLightPush() check: - res.isErr() - res.error == MountWithoutRelayError + res.isOk() + not node.wakuLegacyLightPush.isNil() diff --git a/tests/node/test_wakunode_lightpush.nim b/tests/node/test_wakunode_lightpush.nim index 6c28f5083..bc15cbcb1 100644 --- a/tests/node/test_wakunode_lightpush.nim +++ b/tests/node/test_wakunode_lightpush.nim @@ -229,7 +229,7 @@ suite "Waku Lightpush message delivery": await allFutures(lightNode.stop(), bridgeNode.stop(), destNode.stop()) suite "Waku Lightpush mounting behavior": - asyncTest "fails to mount when relay is not mounted": + asyncTest "mounts without relay": ## Given a node without Relay mounted let key = generateSecp256k1Key() @@ -238,8 +238,9 @@ suite "Waku Lightpush mounting behavior": # Do not mount Relay on purpose check node.wakuRelay.isNil() - ## Then mounting Lightpush must fail + ## Then mounting Lightpush should succeed; the handler will return + ## SERVICE_NOT_AVAILABLE on push attempts as long as relay stays absent. let res = await node.mountLightPush() check: - res.isErr() - res.error == MountWithoutRelayError + res.isOk() + not node.wakuLightPush.isNil()