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-relay): process blocks atomically #1349

Merged
merged 41 commits into from
Nov 10, 2022
Merged

Conversation

rymnc
Copy link
Contributor

@rymnc rymnc commented Nov 7, 2022

Fixes #1266, includes the following changes -

  1. Updates zerokit submodules to vacp2p/zerokit@490206a
    2. Removes all references of insertMember since it is unsafe and can brick merkle trees without a good reconciliation mechanism
  2. Replaces usages of insertMember with insertMembers, which batches updates to the MT
  3. Adds new zerokit ffi api (set_leaves_from: feat(rln): ability to set leaves from a given index vacp2p/zerokit#63)

Misc:

  • test(rln-relay): atomic block processing
  • fix(rln-relay): use correct starting index
  • fix(rln-relay): args
  • fix(rln-relay): append length
  • fix(rln-relay): tests, remove insertMember
  • fix(rln-relay): camelCase, cleanup

@rymnc rymnc added this to the Release 0.13.0 milestone Nov 7, 2022
@rymnc rymnc added the track:rln RLN Track (Secure Messaging/Applied ZK), e.g. relay and applications label Nov 7, 2022
@rymnc rymnc self-assigned this Nov 7, 2022
@rymnc rymnc requested review from LNSD, s1fr0 and staheri14 November 7, 2022 16:56
@status-im-auto
Copy link
Collaborator

status-im-auto commented Nov 7, 2022

Jenkins Builds

Click to see older builds (51)
Commit #️⃣ Finished (UTC) Duration Platform Result
adb5c60 #1 2022-11-07 17:13:11 ~16 min linux 📄log
✔️ adb5c60 #1 2022-11-07 17:17:59 ~21 min macos 📦bin
✔️ 0a60042 #2 2022-11-07 17:25:44 ~18 min linux 📦bin
✔️ 0a60042 #2 2022-11-07 17:27:34 ~20 min macos 📦bin
✔️ 83dae90 #3 2022-11-07 18:29:59 ~15 min linux 📦bin
83dae90 #3 2022-11-07 18:33:41 ~19 min macos 📄log
dd8518e #4 2022-11-07 18:30:08 ~14 min linux 📄log
✔️ dd8518e #4 2022-11-07 18:37:22 ~21 min macos 📦bin
✔️ 6de3978 #5 2022-11-07 18:39:04 ~20 min linux 📦bin
✔️ 6de3978 #5 2022-11-07 18:40:14 ~21 min macos 📦bin
✔️ fb7853b #6 2022-11-08 04:34:02 ~16 min macos 📦bin
fb7853b #6 2022-11-08 04:39:14 ~21 min linux 📄log
✔️ fb7853b #7 2022-11-08 04:40:43 ~22 min linux 📦bin
✔️ 8b0ff46 #7 2022-11-08 08:00:55 ~14 min macos 📦bin
✔️ 8b0ff46 #8 2022-11-08 08:06:55 ~20 min linux 📦bin
✔️ b77d7c6 #8 2022-11-08 08:04:14 ~15 min macos 📦bin
✔️ b77d7c6 #9 2022-11-08 08:10:14 ~21 min linux 📦bin
✔️ d40636d #9 2022-11-08 08:16:23 ~14 min macos 📦bin
✔️ d40636d #10 2022-11-08 08:16:26 ~14 min linux 📦bin
✔️ 83e8794 #10 2022-11-08 15:01:37 ~17 min macos 📦bin
✔️ 83e8794 #11 2022-11-08 15:04:38 ~20 min linux 📦bin
✔️ f23350e #12 2022-11-08 16:03:10 ~16 min linux 📦bin
✔️ f23350e #11 2022-11-08 16:11:26 ~24 min macos 📦bin
✔️ 84a72e3 #13 2022-11-09 05:05:56 ~15 min linux 📦bin
✔️ 84a72e3 #12 2022-11-09 05:06:11 ~15 min macos 📦bin
✔️ 14f833b #14 2022-11-09 06:01:59 ~15 min linux 📦bin
✔️ 14f833b #13 2022-11-09 06:02:13 ~15 min macos 📦bin
✔️ 0a5f79f #14 2022-11-09 06:23:59 ~15 min macos 📦bin
0a5f79f #15 2022-11-09 06:24:10 ~15 min linux 📄log
✔️ 5a6ec33 #16 2022-11-09 06:31:38 ~15 min linux 📦bin
✔️ 5a6ec33 #15 2022-11-09 06:32:14 ~16 min macos 📦bin
✔️ ec52697 #17 2022-11-09 06:33:14 ~16 min linux 📦bin
✔️ ec52697 #16 2022-11-09 06:38:06 ~20 min macos 📦bin
✔️ c40aee6 #17 2022-11-09 06:43:54 ~16 min macos 📦bin
✔️ c40aee6 #18 2022-11-09 06:49:24 ~21 min linux 📦bin
✔️ 33cba52 #18 2022-11-09 07:43:55 ~14 min macos 📦bin
✔️ 33cba52 #19 2022-11-09 07:44:43 ~15 min linux 📦bin
✔️ 868be86 #19 2022-11-09 09:35:11 ~20 min macos 📦bin
✔️ 868be86 #20 2022-11-09 09:37:58 ~23 min linux 📦bin
✔️ 9835897 #20 2022-11-09 10:22:26 ~18 min macos 📦bin
✔️ 9835897 #21 2022-11-09 10:22:28 ~18 min linux 📦bin
✔️ 0ddcd11 #21 2022-11-09 13:51:30 ~17 min macos 📦bin
✔️ 0ddcd11 #22 2022-11-09 13:54:19 ~20 min linux 📦bin
5919e05 #23 2022-11-09 14:54:47 ~20 min linux 📄log
✔️ 5919e05 #22 2022-11-09 15:43:44 ~1 hr 9 min macos 📦bin
✔️ 103c80b #24 2022-11-09 14:58:43 ~21 min linux 📦bin
✔️ 103c80b #23 2022-11-09 16:01:45 ~1 hr 24 min macos 📦bin
✔️ c1d9c16 #24 2022-11-10 06:18:28 ~15 min macos 📦bin
c1d9c16 #25 2022-11-10 06:23:02 ~19 min linux 📄log
✔️ 54dca37 #25 2022-11-10 06:21:36 ~15 min macos 📦bin
✔️ 54dca37 #26 2022-11-10 06:27:35 ~21 min linux 📦bin
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 71f9343 #26 2022-11-10 07:14:10 ~15 min macos 📦bin
✔️ 71f9343 #27 2022-11-10 07:16:11 ~17 min linux 📦bin
✔️ 71c5bfd #28 2022-11-10 11:48:06 ~16 min linux 📦bin
✔️ 71c5bfd #27 2022-11-10 11:48:28 ~16 min macos 📦bin

rymnc and others added 2 commits November 7, 2022 23:44
Co-authored-by: Lorenzo Delgado <lorenzo@status.im>
return err("failed to parse the data field of the MemberRegistered event")

type BlockTable = OrderedTable[BlockNumber, seq[MembershipTuple]]
proc getHistoricalEvents*(ethClientUri: string,
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'm aware some of this looks unsafe. The goal is to get this proc to look like https://github.com/status-im/nimbus-eth2/blob/44f652f704f14c67e648f2b14dee652d44b858c5/ncli/deposit_downloader.nim#L42, which has a cleaner way to handle rate limiting, etc. Will track it in a separate issue, for common web3 utils.

@staheri14
Copy link
Contributor

staheri14 commented Nov 7, 2022

Can you please explain the un-safety of the insertMember

Removes all references of insertMember since it is unsafe and can brick merkle trees without a good reconciliation mechanism

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.

Thanks, please see my comments below.

%*{"fromBlock": fromBlock, "address": contractAddress},
onMemberRegistered,
onError)
proc parse*(event: type MemberRegistered,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please also add a comment to each line of this code explaining what is happeing.

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 8b0ff46

rymnc and others added 2 commits November 8, 2022 09:47
Co-authored-by: Sanaz Taheri <35961250+staheri14@users.noreply.github.com>
Co-authored-by: Sanaz Taheri <35961250+staheri14@users.noreply.github.com>
Copy link
Contributor

@alrevuelta alrevuelta left a comment

Choose a reason for hiding this comment

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

just a minor suggestion :)

@rymnc rymnc requested review from s1fr0 and staheri14 November 9, 2022 06:28
@rymnc rymnc marked this pull request as ready for review November 9, 2022 07:04
if indexGap > 1.uint:
let indexGap = lastIndex - rlnPeer.lastSeenMembershipIndex
if not (@[startingIndex..lastIndex, uint] == members.map(index)):
return err("the indices of the new members are not in order")
Copy link
Contributor

Choose a reason for hiding this comment

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

return err("indexes of new members are not in order")

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 5919e05

let indexGap = lastIndex - rlnPeer.lastSeenMembershipIndex
if not (@[startingIndex..lastIndex, uint] == members.map(index)):
return err("the indices of the new members are not in order")
if indexGap > 0.uint:
Copy link
Contributor

Choose a reason for hiding this comment

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

a safer way from creative bugs would be to have if indexGap != 0.uint:

Copy link
Contributor

Choose a reason for hiding this comment

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

Anyway I still don't understand the logic of this check: if blocks are processed atomically I expect lastSeenMembershipIndex to be the latest index seen in previous processed block, if any. Not the last seen in current processed block: only if the block is successfully processed you then update lastSeenMembershipIndex. For this reason before I was asking if it was more correct to check that startIndex = lastSeenMembershipIndex + 1 which ensure no event was missed in the meanwhile.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

a safer way from creative bugs would be to have if indexGap != 0.uint:

Addressed in 5919e05

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for previous comment, it seems I was looking at a wrong commit. Here seems to be fixed https://github.com/status-im/nwaku/blob/0ddcd115a0faa755f78fe7a66fd7085dbd56cd37/waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim#L1015-L1022 I would just change the check on the gap to be != 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and fixed additionally in 103c80b

Copy link
Contributor

@s1fr0 s1fr0 left a comment

Choose a reason for hiding this comment

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

What a great PR! Thank you for addressing the (many!) comments received and for solving the (many!) merge conflicts!

I'd say just track for future reference what discussed in https://github.com/status-im/nwaku/pull/1349/files#r1017619179 so that we can enforce blocks to have chronological order.

@LNSD
Copy link
Contributor

LNSD commented Nov 10, 2022

The test failure at the macOS test2 CI job seems unrelated to the PR changes.

@rymnc Feel free to merge these changes ✅

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.

feat(rln-relay): The window of acceptable roots should change per block, not per event
6 participants