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: merkle tree persistence #630

Merged
merged 3 commits into from
Aug 18, 2023
Merged

feat: merkle tree persistence #630

merged 3 commits into from
Aug 18, 2023

Conversation

richard-ramos
Copy link
Member

Description

Persist Merkle Tree in sled db
This is part of Milestone: #605

Changes

  • Resume onchain sync from persisted tree db
  • Close eth client and DB connection appropriately
  • Pass in the path to the tree db

@status-im-auto
Copy link

status-im-auto commented Aug 7, 2023

Jenkins Builds

Click to see older builds (58)
Commit #️⃣ Finished (UTC) Duration Platform Result
✖️ f61b410 #1 2023-08-07 21:33:15 ~29 sec nix-flake 📄log
✔️ f61b410 #1 2023-08-07 21:33:58 ~1 min linux 📦deb
✖️ f61b410 #1 2023-08-07 21:35:17 ~2 min tests 📄log
✔️ f61b410 #1 2023-08-07 21:36:36 ~3 min android 📦tgz
✔️ f61b410 #1 2023-08-07 21:36:55 ~4 min ios 📦tgz
✖️ 19a2f8e #2 2023-08-08 17:47:27 ~31 sec nix-flake 📄log
✔️ 19a2f8e #2 2023-08-08 17:48:08 ~1 min linux 📦deb
✔️ 19a2f8e #2 2023-08-08 17:49:30 ~2 min tests 📄log
✔️ 19a2f8e #2 2023-08-08 17:50:37 ~3 min android 📦tgz
✔️ 19a2f8e #2 2023-08-08 17:52:35 ~5 min ios 📦tgz
✖️ 4de8870 #3 2023-08-08 18:14:01 ~25 sec nix-flake 📄log
✔️ 4de8870 #3 2023-08-08 18:14:03 ~32 sec linux 📦deb
✔️ 4de8870 #3 2023-08-08 18:15:08 ~1 min tests 📄log
✔️ 4de8870 #3 2023-08-08 18:16:37 ~3 min android 📦tgz
✔️ 4de8870 #3 2023-08-08 18:17:04 ~3 min ios 📦tgz
✔️ 4de8870 #1 2023-08-09 08:00:46 ~3 min tests 📄log
✖️ 4de8870 #5 2023-08-11 15:57:19 ~28 sec nix-flake 📄log
✔️ 4de8870 #5 2023-08-11 15:57:22 ~30 sec linux 📦deb
✔️ 4de8870 #5 2023-08-11 15:58:27 ~1 min tests 📄log
✔️ 4de8870 #3 2023-08-11 15:59:26 ~2 min tests 📄log
✔️ 4de8870 #5 2023-08-11 16:00:15 ~3 min android 📦tgz
✔️ 4de8870 #5 2023-08-11 16:01:04 ~4 min ios 📦tgz
✔️ dd4be9f #4 2023-08-11 15:52:01 ~30 sec linux 📦deb
✔️ dd4be9f #4 2023-08-11 15:53:14 ~1 min tests 📄log
✔️ dd4be9f #4 2023-08-11 15:53:28 ~1 min nix-flake 📄log
✔️ dd4be9f #2 2023-08-11 15:54:09 ~2 min tests 📄log
✔️ dd4be9f #4 2023-08-11 15:54:25 ~2 min android 📦tgz
✔️ dd4be9f #4 2023-08-11 15:55:58 ~4 min ios 📦tgz
✔️ 9d7eef8 #6 2023-08-11 17:03:43 ~33 sec linux 📦deb
✔️ 9d7eef8 #6 2023-08-11 17:04:50 ~1 min tests 📄log
✔️ 9d7eef8 #4 2023-08-11 17:04:53 ~1 min tests 📄log
✔️ 9d7eef8 #6 2023-08-11 17:05:17 ~2 min nix-flake 📄log
✔️ 9d7eef8 #6 2023-08-11 17:06:37 ~3 min android 📦tgz
✔️ 9d7eef8 #6 2023-08-11 17:08:10 ~5 min ios 📦tgz
✔️ 9d7eef8 #7 2023-08-12 11:45:00 ~36 sec linux 📦deb
✔️ 9d7eef8 #5 2023-08-12 11:46:11 ~1 min tests 📄log
✔️ 9d7eef8 #7 2023-08-12 11:46:14 ~1 min tests 📄log
✔️ 9d7eef8 #7 2023-08-12 11:46:42 ~2 min nix-flake 📄log
✔️ 9d7eef8 #7 2023-08-12 11:48:04 ~3 min android 📦tgz
✔️ 9d7eef8 #7 2023-08-12 11:48:48 ~4 min ios 📦tgz
✖️ c68c89a #8 2023-08-17 22:32:20 ~12 sec nix-flake 📄log
✔️ c68c89a #8 2023-08-17 22:32:39 ~32 sec linux 📦deb
✖️ c68c89a #8 2023-08-17 22:33:12 ~1 min tests 📄log
✖️ c68c89a #6 2023-08-17 22:33:48 ~1 min tests 📄log
✔️ c68c89a #8 2023-08-17 22:36:00 ~3 min android 📦tgz
✔️ c68c89a #8 2023-08-17 22:37:02 ~4 min ios 📦tgz
✖️ 18d0e40 #9 2023-08-17 22:43:54 ~12 sec nix-flake 📄log
✔️ 18d0e40 #9 2023-08-17 22:44:12 ~30 sec linux 📦deb
✔️ 18d0e40 #7 2023-08-17 22:44:30 ~48 sec tests 📄log
✖️ 18d0e40 #9 2023-08-17 22:44:43 ~58 sec tests 📄log
✔️ 18d0e40 #9 2023-08-17 22:46:49 ~3 min android 📦tgz
✔️ 18d0e40 #9 2023-08-17 22:49:20 ~5 min ios 📦tgz
✔️ 849845b #10 2023-08-17 22:49:25 ~30 sec linux 📦deb
✔️ 849845b #8 2023-08-17 22:49:39 ~42 sec tests 📄log
✖️ 849845b #10 2023-08-17 22:49:55 ~58 sec tests 📄log
✔️ 849845b #10 2023-08-17 22:51:05 ~2 min nix-flake 📄log
✔️ 849845b #10 2023-08-17 22:51:47 ~2 min android 📦tgz
✔️ 849845b #10 2023-08-17 22:53:35 ~4 min ios 📦tgz
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 7bafa30 #11 2023-08-17 22:54:48 ~32 sec linux 📦deb
✔️ 7bafa30 #9 2023-08-17 22:55:01 ~45 sec tests 📄log
✔️ 7bafa30 #11 2023-08-17 22:55:49 ~1 min tests 📄log
✔️ 7bafa30 #11 2023-08-17 22:56:23 ~2 min nix-flake 📄log
✔️ 7bafa30 #11 2023-08-17 22:57:16 ~3 min android 📦tgz
✔️ 7bafa30 #11 2023-08-17 22:58:07 ~3 min ios 📦tgz
✔️ 94ed1d8 #12 2023-08-17 23:00:50 ~1 min linux 📦deb
✔️ 94ed1d8 #12 2023-08-17 23:01:16 ~1 min tests 📄log
✔️ 94ed1d8 #12 2023-08-17 23:01:31 ~1 min nix-flake 📄log
✔️ 94ed1d8 #10 2023-08-17 23:01:42 ~2 min tests 📄log
✔️ 94ed1d8 #12 2023-08-17 23:03:17 ~3 min android 📦tgz
✔️ 94ed1d8 #12 2023-08-17 23:03:18 ~3 min ios 📦tgz

@richard-ramos
Copy link
Member Author

🤔 For some reason, when a tree config is passed in https://github.com/waku-org/go-waku/pull/630/files#diff-f9f1366bf48973e91af5a769c566b2662c33177e31388325c7f9307b4e7cca55R72 RLN refuses to initialize. Tomorrow I'll figure out what's going on here so I can properly test interop between nwaku and go-waku

@richard-ramos
Copy link
Member Author

richard-ramos commented Aug 8, 2023

The issue was that I was using the same database for all nodes in the test units, so RLN was complaining about not being able to acquire locks on the DB. It's now fixed :)

@@ -49,15 +49,34 @@ type WakuRLNRelay struct {
log *zap.Logger
}

const rlnDefaultDepth = 20
const rlnDefaultTreePath = "rln_tree.db"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should have default path prefixed with ./

"errors"
)

type RLNMetadata struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to add comments for all the exported types.


// TODO: should we track indexes to identify missing?
startIndex := rln.MembershipIndex(uint(oldestIndexInBlock.Int64()))
err := gm.rln.InsertMembers(startIndex, idCommitments)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does the RLN API take care of a scenario where few members are already inserted and not throw error? If not, this has to be handled at this level.

e.g: While inserting members, let's say member insertion succeeded whereas before metadata got updated, node went down. Next time when node comes up, it will try to insert some set of members which are already inserted and probably a new set if they are part of a later block. In this case, atomicOp should not fail. If it fails, then we may have to handle it at this layer(identify if members are already present and not insert them again).

Copy link
Member Author

Choose a reason for hiding this comment

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

Does the RLN API take care of a scenario where few members are already inserted and not throw error? I

The RLN API handles it by acting as an upsert, overwriting whatever is stored at some index in the merkle tree, so atomicOp should not fail as it will just replace the same members at the same position with the same values

@@ -112,7 +112,17 @@ func (gm *DynamicGroupManager) HandleGroupUpdates(ctx context.Context, handler R
}

func (gm *DynamicGroupManager) loadOldEvents(ctx context.Context, rlnContract *contracts.RLN, handler RegistrationEventHandler) error {
events, err := gm.getEvents(ctx, 0, nil)

Copy link
Collaborator

Choose a reason for hiding this comment

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

General Improvement: Does this require an archive node access(since we are querying event logs from past)?

If so, archive node operations are costly and running archive node itself is as well. Maybe we should think of an alternative way to get merkleTree changes (either by Store protocol or some other decentralized storage service).

Copy link
Member Author

Choose a reason for hiding this comment

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

It should be possible to retrieve events with a full node because these type of nodes contain all transaction receipts/logs. A full node can still be costly so I agree that we'll need to come up with a solution for obtaining the merkle tree changes, instead of relying only on the event logs (although for the time being, it should be fine with using infura/pocket)

- resume onchain sync from persisted tree db
- close eth client and db connection appropriately
- pass in the path to the tree db
@richard-ramos richard-ramos force-pushed the tree-path branch 4 times, most recently from 849845b to 7bafa30 Compare August 17, 2023 22:53
@richard-ramos
Copy link
Member Author

@chaitanyaprem I updated this PR with fixes for code review observations, most code climate issues, and also fixed some interop issues I found while attempting to get messages going back and forth between nwaku's chat2 and go-waku's

Copy link
Collaborator

@chaitanyaprem chaitanyaprem left a comment

Choose a reason for hiding this comment

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

LGTM other than few minor comments.

@@ -30,7 +31,7 @@ func rlnFlags() []cli.Flag {
},
&cli.StringFlag{
Name: "rln-relay-content-topic",
Value: "/toy-chat/2/luzhou/proto",
Value: protocol.NewContentTopic("toy-chat", 3, "mingde", "proto").String(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it make sense to have a default value for content-topic? Rather we should throw an error if content-topic is not mentioned.
We can always inlcude in docs which content-topic can be used if someone wants to just test.

Choose a reason for hiding this comment

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

Note that we plan to remove rln pubsub topics and content topics, so that rln is applied in all the subscribed ones if enabled.

See 1. from waku-org/nwaku#1906
and https://discord.com/channels/1110799176264056863/1111540684575477821/1141378004841410640

Copy link
Member Author

Choose a reason for hiding this comment

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

For this PR let's keep it with the hardcoded default content topic to match nwaku's flag: https://github.com/waku-org/nwaku/blob/master/apps/wakunode2/external_config.nim#L165

@richard-ramos richard-ramos merged commit 387ee5f into master Aug 18, 2023
@richard-ramos richard-ramos deleted the tree-path branch August 18, 2023 13:59
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