add eligibility check in Lightpush protocol

This commit is contained in:
Sergei Tikhomirov 2025-06-26 23:37:39 +02:00
parent d20f64f0f8
commit 5e038f6a4b
2 changed files with 42 additions and 31 deletions

View File

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

View File

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