Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: RLN proofs as a lightpush service #2768

Merged
merged 9 commits into from
Jun 13, 2024
Merged

Conversation

shash256
Copy link
Contributor

@shash256 shash256 commented Jun 4, 2024

Description

  • Extend lightpush service protocol to attach RLN proofs to messages received from clients (Issue feat: RLN-proofs as a lightpush service #2593)
  • Ensure that the proof is valid. If the service node was able to generate a valid proof, publish the message, otherwise return an error in the lightpush response.

Changes

  • Moved PushHandler to waku_lightpush/callbacks
  • It can optionally can take in WakuRLNRelay, and attach RLN proof to messages received.
  • If not enabled, the messages can still get published without any additions
  • Unit test covering scenario when RLN enabled (and existing e2e test covers the scenario when not enabled)

Copy link

github-actions bot commented Jun 4, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2768-rln-v2

Built from cbb54d7

Copy link

github-actions bot commented Jun 4, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2768-rln-v1

Built from cbb54d7

@shash256 shash256 changed the title feat: RLN proofs as a lightpush service (draft - don't merge) feat: RLN proofs as a lightpush service Jun 7, 2024
@shash256 shash256 marked this pull request as ready for review June 7, 2024 12:12
Copy link
Contributor

@jm-clius jm-clius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Some comments below, but generally LGTM

waku/node/waku_node.nim Outdated Show resolved Hide resolved
waku/waku_lightpush/callbacks.nim Outdated Show resolved Hide resolved
waku/waku_lightpush/callbacks.nim Outdated Show resolved Hide resolved
waku/waku_lightpush/callbacks.nim Outdated Show resolved Hide resolved
waku/waku_lightpush/callbacks.nim Outdated Show resolved Hide resolved
Copy link
Contributor

@SionoiS SionoiS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic is good but code organisation I don't like.

It seams like the RelayPushHandler no longer has only 1 purpose. I would split the handler in 2 (proofs & relay), updating the logic in protocol.nim in the process.

Also, get familiar with .isOkOr: and .valueOr: those are great line savers.

Comment on lines 19 to 33
proc generateAndValidateRLNProof*(rlnPeer: Option[WakuRLNRelay], message: WakuMessage): Result[WakuMessage, string] =
# TODO: check and validate if the message already has RLN proof?
if rlnPeer.isNone():
return ok(message) # publishing message without RLN proof

# generate and append RLN proof
let
time = getTime().toUnix()
senderEpochTime = float64(time)
var msgWithProof = message
let appendProofRes = rlnPeer.get().appendRLNProof(msgWithProof, senderEpochTime)
if appendProofRes.isOk():
return ok(msgWithProof)

return err("RLN proof generation failed: " & appendProofRes.error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a callback in RLNRelay that any protocol can use IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this has specific stuff which is relevant to light push such as checking whether rln mounted and, the appendRLNProof might be something that is more suitable for other protocols to be called in general.

waku/waku_lightpush/callbacks.nim Show resolved Hide resolved
Comment on lines 935 to 948
var pushHandler =
if node.wakuRelay.isNil:
debug "mounting lightpush without relay (nil)"
getNilPushHandler()
else:
debug "mounting lightpush with relay"
let rlnPeer =
if node.wakuRlnRelay.isNil:
debug "mounting lightpush without rln-relay"
none(WakuRLNRelay)
else:
debug "mounting lightpush with rln-relay"
some(node.wakuRlnRelay)
getRelayPushHandler(node.wakuRelay, rlnPeer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better than what we had but maybe log only mounting lightpush once and add another log in WakuLightPush.new() for the specific cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the challenge in this case would be that we would need wakuRlnRelay (or wakuRelay) in light push which as I understand we would want to generally avoid. Also might be good to have mounting related items in waku_node itself for easy readability ?

waku/waku_lightpush/callbacks.nim Outdated Show resolved Hide resolved
Copy link
Contributor

@jm-clius jm-clius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Some code organisation can be done before merging, but no need to re-request review.

@SionoiS it will be good to understand which specific comments are blocking approval? Minor code re-organisation can generally be done without requiring another approval or be left for subsequent PRs. I agree with most of your proposals, but think splitting the attach-RLN-proof and publish-RLN handlers is out of scope here: it would imply, among other things, changing the lightpush protocol to accept multiple push handlers with strong dependency on the order in which these handlers are called. Could be done, but I think it needs a proper design and is best left for when we introduce multiple services to the lightpush service node.

Copy link
Contributor

@NagyZoltanPeter NagyZoltanPeter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this great work, it is an awaited feature I think, at least I need it for lite-protocol-tester to run on RLN-ed networks.
I approve it with some comment for you to consider.

waku/waku_lightpush/protocol.nim Outdated Show resolved Hide resolved
waku/waku_lightpush/protocol.nim Outdated Show resolved Hide resolved
waku/waku_lightpush/protocol.nim Outdated Show resolved Hide resolved
waku/node/waku_node.nim Outdated Show resolved Hide resolved
waku/node/waku_node.nim Show resolved Hide resolved
waku/node/waku_node.nim Show resolved Hide resolved
waku/waku_lightpush/callbacks.nim Outdated Show resolved Hide resolved
): Future[WakuLightPushResult[void]] {.async.} =
return err("no waku relay found")

proc getRelayPushHandler*(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to have proc producing another proc?
Isn't it possible to define the necessary callback proc here and just use it as handler there?

tests/node/test_wakunode_lightpush.nim Show resolved Hide resolved
@shash256 shash256 merged commit 0561e5b into master Jun 13, 2024
12 of 15 checks passed
@shash256 shash256 deleted the rln-proofs-lp-service branch June 13, 2024 17:10
rymnc pushed a commit that referenced this pull request Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants