mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-24 00:33:11 +00:00
[WIP] eligibility check with hard-coded parameters
This commit is contained in:
parent
ec363fd458
commit
5d3af6d3c3
@ -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
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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!"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user