restore things mistakenly removed during merge

This commit is contained in:
Sergei Tikhomirov 2025-07-15 16:56:27 +02:00
parent 4e8de55de0
commit fcdf674726
2 changed files with 46 additions and 1 deletions

View File

@ -249,11 +249,13 @@ proc selectPeer*(
var preSelectedPeers =
if pm.reputationManager.isSome():
debug "Reputation enabled: consider only non-negative reputation peers"
# FIXME: remove double loop
for peer in peers:
let rep = try:
pm.reputationManager.get().getReputation(peer.peerId)
except KeyError:
none(bool)
debug "Peer with reputation:", peer=peer, reputation=rep
peers.filterIt:
let rep =
try:

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"
@ -89,6 +90,48 @@ proc handleRequest*(
statusDesc: some(desc),
)
# 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: LightPushErrorCode.PAYMENT_REQUIRED,
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: LightPushErrorCode.PAYMENT_REQUIRED,
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: LightPushErrorCode.PAYMENT_REQUIRED,
statusDesc: some(msg),
)
else:
# the service node doesn't want to check eligibility
debug "eligibilityManager is disabled - skipping eligibility check"
let relayPeerCount = (await handleRequest(wl, peerId, pushRequest)).valueOr:
let desc = error.desc
waku_lightpush_v3_errors.inc(labelValues = [$error.code])