From 5d3af6d3c36f669a3cc74fe261652c96bb17b5ac Mon Sep 17 00:00:00 2001 From: Sergei Tikhomirov Date: Thu, 5 Jun 2025 10:22:30 +0200 Subject: [PATCH] [WIP] eligibility check with hard-coded parameters --- waku/factory/builder.nim | 2 ++ waku/factory/external_config.nim | 2 ++ waku/factory/node_factory.nim | 8 +++++++ waku/node/waku_node.nim | 29 +++++++++++++++++++++-- waku/waku_api/rest/lightpush/handlers.nim | 2 +- 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/waku/factory/builder.nim b/waku/factory/builder.nim index d1cede969..4af6fc658 100644 --- a/waku/factory/builder.nim +++ b/waku/factory/builder.nim @@ -206,6 +206,8 @@ proc build*(builder: WakuNodeBuilder): Result[WakuNode, string] = colocationLimit = builder.colocationLimit, shardedPeerManagement = builder.shardAware, dnsNameServers = netConfig.dnsNameServers, + eligibilityEnabled = true, # FIXME: i13n: read config or something instead + #reputationEnabled = true, # FIXME: i13n: read config or something instead ) var node: WakuNode diff --git a/waku/factory/external_config.nim b/waku/factory/external_config.nim index ce0eec97f..075b132ab 100644 --- a/waku/factory/external_config.nim +++ b/waku/factory/external_config.nim @@ -487,6 +487,7 @@ hence would have reachability issues.""", .}: bool ## Eligibility config + ## Is eligibility check enabled or not eligibilityEnabled* {. desc: "Enable server-side eligibility (proof-of-payment) check for light protocols: true|false", @@ -494,6 +495,7 @@ hence would have reachability issues.""", name: "eligibility" .}: bool + ## Reliability config reliabilityEnabled* {. desc: diff --git a/waku/factory/node_factory.nim b/waku/factory/node_factory.nim index 7df5c2567..fc53ea81f 100644 --- a/waku/factory/node_factory.nim +++ b/waku/factory/node_factory.nim @@ -430,6 +430,14 @@ proc setupProtocols( return err("failed to set node waku peer-exchange peer: " & peerExchangeNode.error) + # set up eligibility check (i13n POC) + # check that: rlnRelay is mounted; Lightpush is mounted + # FIXME: conf items are not propagated here; where are they parsed? + #if conf.eligibilityEnabled: + # debug "i13n: eligibility enabled!" + # debug "eligibilityReceiverAddress:", conf.eligibilityReceiverAddress + # debug "eligibilityPaymentAmountWei:", conf.eligibilityPaymentAmountWei + return ok() ## Start node diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index 127f34941..04bf54c79 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -1213,9 +1213,34 @@ proc lightpushPublish*( error "lightpush publish error", error = msg return lighpushErrorResult(INTERNAL_SERVER_ERROR, msg) - # TODO: check eligibilityProof here + # Checking eligibility proof of Lightpush request + 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() + # FIXME: where should I init eligibilityManager? + # FIXME: how to reuse EthClient from CLI arguments? + debug "initializing eligibilityManager..." + let ethClient = "https://sepolia.infura.io/v3/470c2e9a16f24057aee6660081729fb9" + em = await EligibilityManager.init(ethClient) + debug "checking eligibilityProof..." + let txNonExistent = TxHash.fromHex("0x0000000000000000000000000000000000000000000000000000000000000000") + let expectedToAddress = Address.fromHex("0xe8284Af9A5F3b0CD1334DBFaf512F09BeDA805a3") + let expectedValueWei = 30000000000000.u256 + + let isEligible = await em.isEligibleTxId( + eligibilityProof.get(), expectedToAddress, expectedValueWei + ) + if isEligible.isErr(): + let msg = "Eligibility check failed!" + #debug msg + return lighpushErrorResult(PAYMENT_REQUIRED, msg) - # TODO: eligibilityProof must be already checked if present + debug "Eligibility check passed!" return await lightpushPublishHandler(node, pubsubForPublish, message, toPeer) ## Waku RLN Relay diff --git a/waku/waku_api/rest/lightpush/handlers.nim b/waku/waku_api/rest/lightpush/handlers.nim index 454d1c807..daa8a5571 100644 --- a/waku/waku_api/rest/lightpush/handlers.nim +++ b/waku/waku_api/rest/lightpush/handlers.nim @@ -94,7 +94,7 @@ proc installLightPushRequestHandler*( makeRestResponse(lightpushResultServiceUnavailable(NoPeerNoneFoundError)) toPeer = some(aPeer) - let subFut = node.lightpushPublish(req.pubsubTopic, msg, none(EligibilityProof), toPeer) + let subFut = node.lightpushPublish(req.pubsubTopic, msg, req.eligibilityProof, toPeer) if not await subFut.withTimeout(FutTimeoutForPushRequestProcessing): error "Failed to request a message push due to timeout!"