Merge c42e7d24e8927b82cdce9091da11cfc70affbcc6 into f02e8bc6685310ac7577f61b0d7e084298191596

This commit is contained in:
Tanya S 2026-06-27 11:30:13 +00:00 committed by GitHub
commit 3f53c5a001
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 60 additions and 28 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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

View File

@ -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",

View File

@ -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()

View File

@ -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()