-
Notifications
You must be signed in to change notification settings - Fork 60
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): abstract group management into its own api #1465
Conversation
cfca7a6
to
df21773
Compare
Jenkins BuildsClick to see older builds (4)
|
Note: imo we should create a separate PR to integrate these changes into the rln-relay itself. At the current moment, I have not removed any code from the utils.nim file, and left it as is for ease of review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, check my comments 🙂
waku/v2/protocol/waku_rln_relay.nim
Outdated
export | ||
rln, | ||
ffi, | ||
constants, | ||
protocol_types, | ||
protocol_metrics, | ||
conversion_utils, | ||
utils, | ||
contract |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the members of all these modules used outside the waku_rln_relay
module?
Typically you only expose/export the APIs used outside of the module, nothing else. This prevents the misusage of the module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we do test even the ffi to ensure that breaking upstream changes are detected whenever we update submodules
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. But... One thing is the module APIs, and another thing is testing.
A clean API without exposing internal symbols (types, methods, etc.) helps prevent the library's misusage that could break the program. You'll still be able to test the different submodules by importing them explicitly in the test file/module at the moment of testing.
Said that, do you still think that we should expose everything in this module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, we should just be functionally testing the logic. Tracking the fix - #1489
proc appendLength*(input: openArray[byte]): seq[byte] = | ||
## returns length prefixed version of the input | ||
## with the following format [len<8>|input<var>] | ||
## len: 8-byte value that represents the number of bytes in the `input` | ||
## len is serialized in little-endian | ||
## input: the supplied `input` | ||
let | ||
# the length should be serialized in little-endian | ||
len = toBytes(uint64(input.len), Endianness.littleEndian) | ||
output = concat(@len, @input) | ||
return output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
appendLength()
But:
... length prefixed version of the input ...
I would call this method something like encodeLengthPrefixed
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will address when fixing #1487 :)
rootsBytes = concat(rootsBytes, @root) | ||
return rootsBytes | ||
|
||
proc serializeIdCommitments*(idComms: seq[IDCommitment]): seq[byte] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two methods above are named as simple as serialize
; this is serializeIdCommitments
. I think that we need to improve the consistency in the procs naming and use only one naming schema :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will address when fixing #1487 :)
proc toIdentityCredentials*(groupKeys: seq[(string, string)]): RlnRelayResult[seq[ | ||
IdentityCredential]] = | ||
## groupKeys is sequence of membership key tuples in the form of (identity key, identity commitment) all in the hexadecimal format | ||
## the toIdentityCredentials proc populates a sequence of IdentityCredentials using the supplied groupKeys | ||
## Returns an error if the conversion fails | ||
|
||
var groupIdCredentials = newSeq[IdentityCredential]() | ||
|
||
for i in 0..groupKeys.len-1: | ||
try: | ||
let | ||
idSecretHash = hexToUint[IdentitySecretHash.len*8](groupKeys[i][0]).toBytesLE() | ||
idCommitment = hexToUint[IDCommitment.len*8](groupKeys[i][1]).toBytesLE() | ||
groupIdCredentials.add(IdentityCredential(idSecretHash: idSecretHash, | ||
idCommitment: idCommitment)) | ||
except ValueError as err: | ||
warn "could not convert the group key to bytes", err = err.msg | ||
return err("could not convert the group key to bytes: " & err.msg) | ||
return ok(groupIdCredentials) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This proc
could be collocated with the IdentityCredential
type. In the "utils" modules, which I abhor and avoid, you should keep only things that are common to everything (e.g. toHex()
, encodeLengthPrefixed()
, toEpoch()
or fromEpoch()
).
Please review this module and see if it makes sense to collocate other methods next to the types based on the module imports graph. This is: if you are importing this utils module to use that proc, and the proc is not used elsewhere, then the proc is not in the right module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will address when fixing #1487 :)
waku/v2/protocol/waku_rln_relay.nim
Outdated
rln, | ||
ffi, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, I prefer the rln
name since it comes from librln
. The ffi
and wrapper
names are too generic.
For example, I would name ffi
a module that contains utilities to do ffi
in an easier/opinionated way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you prefer librln
to be more explicit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK in nim, the convention is to name the module after the library without the lib
part (like in Rust, binding crates are appended with -sys
). I prefer just rln
, but I don't have a strong opinion as far as it is descriptive and not generic like ffi
or wrapper
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type GroupManagerResult*[T] = Result[T, string] | ||
|
||
type | ||
GroupManager*[Config] = ref object of RootObj |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You declared the interface (the base object) here, but the associated procs are not using the method
statement and the {.base.}
pragma. Is there any reason for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops! looks like this change was pushed by mistake, Addressed in 4135b87, thanks!
One question/suggestion regarding the module's structure:
|
@LNSD can I merge this now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ✅
Proposes a GroupManager, which will be a field on WakuRlnRelay, having a standard interface across all implementations. This aims to solve the issues related to readability of the code when it operates in different modes.
TODO (not exhaustive):
In follow up PR: