[WIP] pass eligibility proof to the service node (check still required)(

This commit is contained in:
Sergei Tikhomirov 2025-06-26 15:51:16 +02:00
parent 2a6e3c9119
commit d20f64f0f8
5 changed files with 35 additions and 27 deletions

View File

@ -457,8 +457,7 @@ proc setupProtocols(
expectedValueWei
)
node.peerManager.eligibilityManager = some(manager)
debug "i13n: eligibilityManager initialized with values:", ethUrl=ethUrl, expectedToAddress=expectedToAddress, expectedValueWei=$expectedValueWei
# FIXME: why debug displays expectedValueWei 3948404736 and not 30000000000000?
debug "i13n: eligibilityManager initialized with values:", ethUrl=ethUrl, expectedToAddress=expectedToAddress, expectedValueWei=expectedValueWei
except CatchableError:
return err("failed to initialize eligibility manager: " & getCurrentExceptionMsg())

View File

@ -1159,17 +1159,19 @@ proc lightpushPublishHandler(
node: WakuNode,
pubsubTopic: PubsubTopic,
message: WakuMessage,
eligibilityProof: Option[EligibilityProof] = none(EligibilityProof),
peer: RemotePeerInfo | PeerInfo,
): Future[lightpush_protocol.WakuLightPushResult] {.async.} =
# note: eligibilityProof is not used in this function, it has already been checked
let msgHash = pubsubTopic.computeMessageHash(message).to0xHex()
if not node.wakuLightpushClient.isNil():
notice "publishing message with lightpush",
pubsubTopic = pubsubTopic,
contentTopic = message.contentTopic,
target_peer_id = peer.peerId,
msg_hash = msgHash
return await node.wakuLightpushClient.publish(some(pubsubTopic), message, peer)
msg_hash = msgHash,
eligibilityProof = eligibilityProof
return await node.wakuLightpushClient.publish(some(pubsubTopic), message, eligibilityProof, peer)
if not node.wakuLightPush.isNil():
notice "publishing message with self hosted lightpush",
@ -1197,7 +1199,7 @@ proc lightpushPublish*(
elif not node.wakuLightpushClient.isNil():
node.peerManager.selectPeer(WakuLightPushCodec).valueOr:
let msg = "no suitable remote peers"
error "failed to publish message", msg = msg
error "failed to publish message", err = msg
return lighpushErrorResult(NO_PEERS_TO_RELAY, msg)
else:
return lighpushErrorResult(NO_PEERS_TO_RELAY, "no suitable remote peers")
@ -1212,10 +1214,16 @@ proc lightpushPublish*(
let msg = "Autosharding error: " & error
error "lightpush publish error", error = msg
return lighpushErrorResult(INTERNAL_SERVER_ERROR, msg)
# Checking eligibility proof of Lightpush request
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"
@ -1224,11 +1232,6 @@ proc lightpushPublish*(
var em = node.peerManager.eligibilityManager.get()
try:
#let ethClient = "https://sepolia.infura.io/v3/470c2e9a16f24057aee6660081729fb9"
#let expectedToAddress = Address.fromHex("0xe8284Af9A5F3b0CD1334DBFaf512F09BeDA805a3")
#let expectedValueWei = 30000000000000.u256
#em = await EligibilityManager.init(em.ethClient, em.expectedToAddress, em.expectedValueWei)
debug "checking eligibilityProof..."
# Check if eligibility proof is provided before accessing it
@ -1243,7 +1246,8 @@ proc lightpushPublish*(
return lighpushErrorResult(PAYMENT_REQUIRED, msg)
debug "Eligibility check passed!"
return await lightpushPublishHandler(node, pubsubForPublish, message, toPeer)
]#
return await lightpushPublishHandler(node, pubsubForPublish, message, eligibilityProof, toPeer)
## Waku RLN Relay
proc mountRlnRelay*(
@ -1341,7 +1345,7 @@ proc startPeerExchangeLoop*(node: WakuNode) =
return
node.wakuPeerExchange.pxLoopHandle = node.peerExchangeLoop()
# TODO: Move to application module (e.g., wakunode2.nim)
# TODO: Move to application module (e.g, wakunode2.nim)
proc setPeerExchangePeer*(
node: WakuNode, peer: RemotePeerInfo | MultiAddress | string
) =

View File

@ -94,6 +94,10 @@ proc installLightPushRequestHandler*(
makeRestResponse(lightpushResultServiceUnavailable(NoPeerNoneFoundError))
toPeer = some(aPeer)
debug "in installLightPushRequestHandler"
debug "request:", req
debug "request.eligibilityProof:", eligibilityProof = req.eligibilityProof
let subFut = node.lightpushPublish(req.pubsubTopic, msg, req.eligibilityProof, toPeer)
if not await subFut.withTimeout(FutTimeoutForPushRequestProcessing):

View File

@ -12,7 +12,7 @@ import
./protocol_metrics,
./rpc,
./rpc_codec,
../incentivization/reputation_manager
../incentivization/[reputation_manager, eligibility_manager, rpc]
logScope:
topics = "waku lightpush client"
@ -78,6 +78,7 @@ proc publish*(
wl: WakuLightPushClient,
pubSubTopic: Option[PubsubTopic] = none(PubsubTopic),
wakuMessage: WakuMessage,
eligibilityProof: Option[EligibilityProof] = none(EligibilityProof),
peer: PeerId | RemotePeerInfo,
): Future[WakuLightPushResult] {.async, gcsafe.} =
var message = wakuMessage
@ -93,13 +94,11 @@ proc publish*(
peerId = shortLog(peer.peerId),
msg_hash = computeMessageHash(pubsubTopic.get(""), message).to0xHex
# TODO: i13n POC: add eligibilityProof to the request
# (if expected by the server - how does the client know?..)
# The tx must have already been sent at this point?
# i13n POC: adding eligibilityProof to the request
let pushRequest = LightpushRequest(
requestId: generateRequestId(wl.rng), pubSubTopic: pubSubTopic, message: message
requestId: generateRequestId(wl.rng), pubSubTopic: pubSubTopic, message: message, eligibilityProof: eligibilityProof
)
debug "in Lightpush client publish: created pushRequest: ", pushRequest
let publishedCount = ?await wl.sendPushRequest(pushRequest, peer)
for obs in wl.publishObservers:
@ -108,7 +107,8 @@ proc publish*(
return lightpushSuccessResult(publishedCount)
proc publishToAny*(
wl: WakuLightPushClient, pubSubTopic: PubsubTopic, wakuMessage: WakuMessage
wl: WakuLightPushClient, pubSubTopic: PubsubTopic, wakuMessage: WakuMessage,
eligibilityproof: Option[EligibilityProof] = none(EligibilityProof)
): Future[WakuLightPushResult] {.async, gcsafe.} =
## This proc is similar to the publish one but in this case
## we don't specify a particular peer and instead we get it from peer manager
@ -122,4 +122,4 @@ proc publishToAny*(
# TODO: check if it is matches the situation - shall we distinguish client side missing peers from server side?
return lighpushErrorResult(NO_PEERS_TO_RELAY, "no suitable remote peers")
return await wl.publish(some(pubSubTopic), message, peer)
return await wl.publish(some(pubSubTopic), message, eligibilityproof, peer)

View File

@ -16,7 +16,8 @@ import
./rpc,
./rpc_codec,
./protocol_metrics,
../common/rate_limit/request_limiter
../common/rate_limit/request_limiter,
../incentivization/[eligibility_manager, rpc]
logScope:
topics = "waku lightpush"
@ -73,9 +74,6 @@ proc handleRequest*(
statusDesc: some(msg),
)
# TODO: i13n POC: check eligibility here (if eligibilityManager.isSome)
# if eligibility check fails, return a response with LightpushStatusCode.PAYMENT_REQUIRED
waku_lightpush_v3_messages.inc(labelValues = ["PushRequest"])
let msg_hash = pubsubTopic.computeMessageHash(pushRequest.message).to0xHex()
@ -84,9 +82,12 @@ proc handleRequest*(
peer_id = peerId,
requestId = pushRequest.requestId,
pubsubTopic = pushRequest.pubsubTopic,
eligibilityProof = pushRequest.eligibilityProof,
msg_hash = msg_hash,
receivedTime = getNowInNanosecondTime()
# FIXME: pass eligibilityProof here??????
# What is pushHandler, where is it defined?
let handleRes = await wl.pushHandler(peerId, pubsubTopic, pushRequest.message)
isSuccess = handleRes.isOk()