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

fix(rln-relay): window of acceptable roots synced to rln metadata #1953

Merged
merged 2 commits into from
Aug 25, 2023

Conversation

rymnc
Copy link
Contributor

@rymnc rymnc commented Aug 25, 2023

Description

It is noticed that when a node is restarted, and has access to a persisted tree, the window of acceptable roots is not
persisted, and may result in an empty deque. To mitigate this bug, we are persisting the window of acceptable roots in
the rln metadata.

Changes

  • RlnMetadata now also contains a field validRoots which is a seq of MerkleNode's
  • test updated to check this change
  • serde for the validRoots seq

Issue

closes #1952

Thanks @alrevuelta for the report!

@rymnc rymnc self-assigned this Aug 25, 2023
Comment on lines 74 to 93
proc setMetadata*(g: OnchainGroupManager): RlnRelayResult[void] =
if g.latestProcessedBlock.isNone():
return err("latest processed block is not set")
try:
let metadataSetRes = g.rlnInstance.setMetadata(RlnMetadata(
lastProcessedBlock: g.latestProcessedBlock.get(),
chainId: uint64(g.chainId.get()),
contractAddress: g.ethContractAddress,
validRoots: g.validRoots.toSeq()))
if metadataSetRes.isErr():
return err("failed to persist rln metadata: " & metadataSetRes.error())
except CatchableError:
return err("failed to persist rln metadata: " & getCurrentExceptionMsg())
return ok()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this fn was moved up

@github-actions
Copy link

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:1953

@rymnc rymnc marked this pull request as ready for review August 25, 2023 12:11
@rymnc rymnc requested a review from alrevuelta August 25, 2023 12:11
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

let len = uint64.fromBytes(merkleNodeByteSeq[0..7], Endianness.littleEndian)
trace "length of valid roots", len
var offset = 8'u64
while i <= len:
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor Q: any reason why not a for loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, addressed in c69728f

var i = 1'u64
let len = uint64.fromBytes(merkleNodeByteSeq[0..7], Endianness.littleEndian)
trace "length of valid roots", len
var offset = 8'u64
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor Q: any particular reason why var and not let?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, addressed in c69728f

@richard-ramos
Copy link
Member

Shouldn't g.validRootBuffer be also stored in the metadata?

@rymnc
Copy link
Contributor Author

rymnc commented Aug 25, 2023

Shouldn't g.validRootBuffer be also stored in the metadata?

not really, the buffer is mainly used for chain reorgs, so it should be short-lived, right?

Copy link
Collaborator

@Ivansete-status Ivansete-status left a comment

Choose a reason for hiding this comment

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

LGTM! I just left comments that I hope you find useful!

waku/waku_rln_relay/rln/wrappers.nim Outdated Show resolved Hide resolved
Comment on lines +112 to +118
if setMetadataRes.isErr():
error "failed to persist rln metadata", error=setMetadataRes.error
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see that this method can either raise an exception or like in this case, just print the error.
For the future I think it worth reviewing this file and make all funcs/methods/procs to return Result[T] rather than raising exceptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, you're right! for all the functions that return Future's, I abstain from returning results as 2 errors need to be handled then - will create a follow up pr for this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but, setting the metadata is not a fatal error, we should be okay if we can't set it for any reason

@rymnc rymnc merged commit 01634f5 into master Aug 25, 2023
13 checks passed
@rymnc rymnc deleted the fix-window-of-roots-sync branch August 25, 2023 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

bug(rln): "provided root does not belong to acceptable window of roots"
4 participants