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

chore(rln-relay): remove all raises and replace with Result types #1321

Merged
merged 8 commits into from
Nov 4, 2022

Conversation

rymnc
Copy link
Contributor

@rymnc rymnc commented Nov 1, 2022

Should resolve #1189, and allow work to be started on #1245

List of changes -

  • mountRlnRelay is now async: Removed waitFor

  • Procs that do not raise exceptions, but return their errors with the RlnRelayResult type -

    • mountRlnRelayDynamic
    • mountRlnRelayStatic
    • mount
    • toMembershipKeyPairs
    • membershipKeyGen
    • createMembershipList
    • ... and more
  • Replaced many var with let, can create a new issue to clean up outliers

@rymnc rymnc added this to the Release 0.13.0 milestone Nov 1, 2022
@rymnc rymnc added track:maintenance track:rln RLN Track (Secure Messaging/Applied ZK), e.g. relay and applications labels Nov 1, 2022
@rymnc rymnc self-assigned this Nov 1, 2022
@status-im-auto
Copy link
Collaborator

status-im-auto commented Nov 1, 2022

Jenkins Builds

Click to see older builds (13)
Commit #️⃣ Finished (UTC) Duration Platform Result
75c2bf5 #1 2022-11-01 09:56:15 ~2 min macos 📄log
✔️ 75c2bf5 #1 2022-11-01 10:10:02 ~16 min linux 📦bin
✔️ 75c2bf5 #2 2022-11-01 10:14:26 ~16 min macos 📦bin
✔️ db10a8a #3 2022-11-01 12:22:54 ~16 min macos 📦bin
✔️ db10a8a #2 2022-11-01 12:24:41 ~18 min linux 📦bin
✔️ 0e9fe75 #4 2022-11-01 12:31:25 ~17 min macos 📦bin
✔️ 0e9fe75 #3 2022-11-01 12:32:22 ~18 min linux 📦bin
✔️ 3570dd1 #5 2022-11-03 05:55:00 ~16 min macos 📦bin
✔️ 3570dd1 #4 2022-11-03 05:55:11 ~17 min linux 📦bin
✔️ b7e0eb5 #6 2022-11-03 11:12:01 ~15 min macos 📦bin
✔️ b7e0eb5 #5 2022-11-03 11:13:18 ~17 min linux 📦bin
✔️ e5d1425 #7 2022-11-03 14:04:31 ~14 min macos 📦bin
✔️ e5d1425 #6 2022-11-03 14:07:05 ~17 min linux 📦bin
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 3a9c3e7 #8 2022-11-03 16:37:12 ~14 min macos 📦bin
✔️ 3a9c3e7 #7 2022-11-03 16:37:47 ~15 min linux 📦bin
✔️ 6edfb44 #9 2022-11-03 17:21:52 ~14 min macos 📦bin
✔️ 6edfb44 #8 2022-11-03 17:22:16 ~15 min linux 📦bin

@rymnc rymnc marked this pull request as ready for review November 2, 2022 03:19
Copy link
Contributor

@LNSD LNSD left a comment

Choose a reason for hiding this comment

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

LGTM ✅

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.

Good stuff! :)

Copy link
Contributor

@staheri14 staheri14 left a comment

Choose a reason for hiding this comment

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

LGTM in general, please see my comments below.

): RlnRelayResult[bool] {.raises: [Defect, ValueError, IOError, CatchableError, Exception].} =
waku_rln_relay_mounting_duration_seconds.nanosecondTime:
let res = mount(
): Future[RlnRelayResult[void]] {.async.} =
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. We don't really need to use bool for a result unless necessary. In this case, we just need to check if it mounted successfully, which is indicated by a success result, i.e ok()
  2. It is a Future now since we moved from using waitFor to async processing

return err("could not convert the group key to bytes: " & err.msg)
return ok(groupKeyPairs)

proc calcMerkleRoot*(list: seq[IDCommitment]): RlnRelayResult[string] =
## returns the root of the Merkle tree that is computed from the supplied list
Copy link
Contributor

Choose a reason for hiding this comment

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

The proc description should change to indicate that the Result output may contain an error if the operation does not go through. This shall be done for all the procs in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 3570dd1


proc createRLNInstance*(d: int = MerkleTreeDepth): RLNResult {.raises: [Defect, IOError].} =
proc createRLNInstance*(d: int = MerkleTreeDepth): RLNResult =
Copy link
Contributor

Choose a reason for hiding this comment

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

There seems to be no possibility for errors in this proc, right? then why result type for the output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the rln instance creation fails, etc we do return an error as part of the RlnResult. This would allow appropriate error handling.

@@ -545,8 +545,8 @@ proc processInput(rfd: AsyncFD) {.async.} =
echo "You are registered to the rln membership contract, find details of your registration transaction in https://goerli.etherscan.io/tx/0x", txHash

echo "rln-relay preparation is in progress..."
let res = node.mountRlnRelay(conf = conf, spamHandler = some(spamHandler), registrationHandler = some(registrationHandler))
if res.isErr:
let res = await node.mountRlnRelay(conf = conf, spamHandler = some(spamHandler), registrationHandler = some(registrationHandler))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why treat it as an async proc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the dynamic mounting proc is async. We're trying to avoid use of waitFor unless absolutely necessary (i.e in entrypoints)

Copy link
Contributor

Choose a reason for hiding this comment

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

Because the dynamic mounting proc is async. We're trying to avoid use of waitFor unless absolutely necessary (i.e in entrypoints)

Exactly, this is the rule we are following. Only use waitFor at the application level (e.g., chat2 or wakunode2)

The reason is that using waitFor indiscriminately can lead to a live-lock situation where the chronos' futures won't progress. This situation can happen if we wait for a method that (at some point deep in the call hierarchy) also contains a waitFor. The clearest example is asyncTest method: which contains a waitFor keeping the chronos' scheduler polling until all the asynchronous methods/futures have been completed.

@rymnc rymnc requested a review from staheri14 November 3, 2022 13:53
@rymnc rymnc merged commit 53e8979 into master Nov 4, 2022
@rymnc rymnc deleted the return-results-rln branch November 4, 2022 03:00
@rymnc
Copy link
Contributor Author

rymnc commented Nov 4, 2022

Merged since this was blocking #1266

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
track:rln RLN Track (Secure Messaging/Applied ZK), e.g. relay and applications
Projects
None yet
Development

Successfully merging this pull request may close these issues.

chore(rln-relay): handle Exceptions and CatchableErrors
5 participants