From 5e038f6a4b962cf568d69bd984eef1c17c8da68c Mon Sep 17 00:00:00 2001 From: Sergei Tikhomirov Date: Thu, 26 Jun 2025 23:37:39 +0200 Subject: [PATCH] add eligibility check in Lightpush protocol --- waku/node/waku_node.nim | 29 --------------------- waku/waku_lightpush/protocol.nim | 44 ++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index 26b8e891c..7cc313844 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -1218,35 +1218,6 @@ proc lightpushPublish*( debug "in lightpushPublish" debug "eligibilityProof: ", eligibilityProof - # FIXME: THIS SHOULD NOT BE CHECKED HERE! - # CHECKING ELIGIBILITY HERE MEANS CHECKING OUR OWN REQUEST BEFORE IT IS SENT - debug "in lightpushPublish" - debug "eligibilityProof: ", eligibilityProof - - #[ - if node.peerManager.eligibilityManager.isNone(): - # the service node doesn't want to check eligibility - debug "eligibilityManager is disabled - skipping eligibility check" - else: - debug "eligibilityManager is enabled" - var em = node.peerManager.eligibilityManager.get() - - try: - debug "checking eligibilityProof..." - - # Check if eligibility proof is provided before accessing it - if eligibilityProof.isNone(): - let msg = "Eligibility proof is required" - return lighpushErrorResult(PAYMENT_REQUIRED, msg) - - let isEligible = await em.isEligibleTxId(eligibilityProof.get()) - - except CatchableError: - let msg = "Eligibility check threw exception: " & getCurrentExceptionMsg() - return lighpushErrorResult(PAYMENT_REQUIRED, msg) - - debug "Eligibility check passed!" - ]# return await lightpushPublishHandler(node, pubsubForPublish, message, eligibilityProof, toPeer) ## Waku RLN Relay diff --git a/waku/waku_lightpush/protocol.nim b/waku/waku_lightpush/protocol.nim index 069863fa1..1619b6bae 100644 --- a/waku/waku_lightpush/protocol.nim +++ b/waku/waku_lightpush/protocol.nim @@ -86,8 +86,48 @@ proc handleRequest*( msg_hash = msg_hash, receivedTime = getNowInNanosecondTime() - # FIXME: pass eligibilityProof here?????? - # What is pushHandler, where is it defined? + # Check eligibility if manager is available + if wl.peerManager.eligibilityManager.isSome(): + debug "eligibilityManager is enabled" + let em = wl.peerManager.eligibilityManager.get() + + try: + debug "checking eligibilityProof..." + + # Check if eligibility proof is provided + if pushRequest.eligibilityProof.isNone(): + let msg = "Eligibility proof is required" + error "lightpush request handling error", error = msg + return LightpushResponse( + requestId: pushRequest.requestId, + statusCode: LightpushStatusCode.PAYMENT_REQUIRED.uint32, + statusDesc: some(msg), + ) + + let isEligible = await em.isEligibleTxId(pushRequest.eligibilityProof.get()) + if isEligible.isErr(): + let msg = "Eligibility check failed: " & isEligible.error + error "lightpush request handling error", error = msg + return LightpushResponse( + requestId: pushRequest.requestId, + statusCode: LightpushStatusCode.PAYMENT_REQUIRED.uint32, + statusDesc: some(msg), + ) + + debug "Eligibility check passed!" + + except CatchableError: + let msg = "Eligibility check threw exception: " & getCurrentExceptionMsg() + error "lightpush request handling error", error = msg + return LightpushResponse( + requestId: pushRequest.requestId, + statusCode: LightpushStatusCode.PAYMENT_REQUIRED.uint32, + statusDesc: some(msg), + ) + else: + # the service node doesn't want to check eligibility + debug "eligibilityManager is disabled - skipping eligibility check" + let handleRes = await wl.pushHandler(peerId, pubsubTopic, pushRequest.message) isSuccess = handleRes.isOk()