-
Notifications
You must be signed in to change notification settings - Fork 55
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: rendezvous refactor #1183
Conversation
Could you please add to the PR description a high-level overview of the changes and if possible how they make the protocol easier to use? |
The reason why min and max TTL are hardcoded is because those limits are set by the specifications: https://github.com/libp2p/specs/blob/master/rendezvous/README.md?plain=1#L270-L273. |
I understand but those are only recommendations. In the context of Waku we decided to go with more "lively" registrations lifecycle hence the shorter TTL. I know we are bending the intended purpose of rendezvous a little but we are not breaking the core spec. |
@SionoiS is the PR's purpose to make those hardcoded values configurable? |
Yes and also allow the selection of specific peers for |
Anything else I can do or suggestions for this PR @diegomrsantos @lchenut ? Waku's rendezvous work is blocked by this. cc @jm-clius |
The use of exceptions and results isn't consistent in the project, we still need to define a new strategy for new code. I would stick with what is implemented instead of changing it when it comes to existing code. |
@SionoiS I rechecked and the only thing that annoys me with this PR is that you do not verify anything about the minimum and the maximum ttl.
But overall, this PR looks great. |
Thanks for the comments. I will make the changes. |
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!
libp2p/protocols/rendezvous.nim
Outdated
@@ -690,6 +690,15 @@ proc new*( | |||
minDuration = MinimumDuration, | |||
maxDuration = MaximumDuration, | |||
): T = | |||
if minDuration < 1.minutes: | |||
raiseAssert("TTL too short: 1 minute minimum") |
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'm not sure raising a Defect here is appropriate. Defect types (like those raised by raiseAssert) are meant to indicate programming errors - situations that should never occur if the code is correct. They are not intended for handling invalid input or runtime errors that can occur during normal operation. The invalid minDuration
and maxDuration
values represent incorrect usage of the new procedure by the caller, possibly due to user input or misconfiguration. These are not programming errors but runtime issues that should be handled gracefully. By raising an Exception
, you allow the caller of the procedure to catch and handle the exception appropriately.
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.
Good catch, you're right, raiseAssert is not the good call here... I did my last review a bit too fast (or too early).
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 address the defect concern and this PR should also include tests for the features added.
let | ||
minTTL = minDuration.seconds.uint64 | ||
maxTTL = maxDuration.seconds.uint64 | ||
|
||
let rdv = T( | ||
rng: rng, | ||
salt: string.fromBytes(generateBytes(rng[], 8)), | ||
registered: initOffsettedSeq[RegisteredData](1), | ||
defaultDT: Moment.now() - 1.days, | ||
#registerEvent: newAsyncEvent(), |
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.
@lchenut just realized this. Do you remember why is this commented?
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 don't. I guess it's an artifact of an old implementation. Because it's not really useful afaik
The first thing I did was raise exceptions but I forgot about the pragma and was confused it didn't work so I tried something else. We good now. I also added a test for misconfig. |
Thank you for the changes. Could you please elaborate more on this feature? |
Waku rendezvous strategy will be to register at rdv points for multiple namespaces specific to GossipSub topics that a node uses. Without a way to choose specific peers to register at, it was not possible to impl. this strategy. |
libp2p/protocols/rendezvous.nim
Outdated
) {.async, base.} = | ||
let sprBuff = rdv.switch.peerInfo.signedPeerRecord.encode().valueOr: | ||
raise newException(RendezVousError, "Wrong Signed Peer Record") | ||
proc batchAdvertise*( |
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 have just realized this has been changed from a method to a proc, could you please explain why?
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 advertise
method now call a public batchAdvertise
proc so that the interface still work like before but you can also use the proc with the new parameters.
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.
@lchenut does it make sense to pass the peers as a parameter here instead of using the seq inside the rdv instance?
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.
There's really nothing against it. In theory, the rendezvous protocol manage this with the peer event handler on joined/left, but if you want to use your own, why not. It wasn't something we needed at the beginning (because we don't really use it outside testing), but if waku needs it, it's a good thing to implement.
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.
Ideally, it would be good to add docs explaining the use of those procs and testing covering them. I don't know if different names for them are a good idea either.
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.
@lchenut it'd be good to add to the issue an evaluation of the use of methods and procs.
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'm not sure I understand your last point
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.
Some things are implemented as procs and some as methods, why?
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 did a little checking. The Rendezvous protocol inherits from LPProtocol, so it should have a start
and stop
method, which it does. But advertise
is also a method, which is wrong, it should be proc.
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 explains the difference and when to use one or the other https://matthiashager.com/proc-method-nim
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.
Thank you, it looks good.
I changed the names but I'll let someone else do the docs since there's none yet. |
added test wrt subscribe and unsubscribe added tests/pubsub/testgossipinternal2 file linters feat: rendezvous refactor (#1183) Hello! This PR aim to refactor rendezvous code so that it is easier to impl. Waku rdv strategy. The hardcoded min and max TTL were out of range with what we needed and specifying which peers to interact with is also needed since Waku deals with peers on multiple separate shards. I tried to keep the changes to a minimum, specifically I did not change the name of any public procs which result in less than descriptive names in some cases. I also wanted to return results instead of raising exceptions but didn't. Would it be acceptable to do so? Please advise on best practices, thank you. --------- Co-authored-by: Ludovic Chenut <[email protected]> refactor and suite name refactor chore(ci): Enable S3 caching for interop (#1193) - Adds our S3 bucket for caching docker images as Protocol Labs shut down their shared one. - Remove the free disk space workaround that prevented the jobs from failing for using too much space for the images. --------- Co-authored-by: diegomrsantos <[email protected]> PR review comment changes
Hello!
This PR aim to refactor rendezvous code so that it is easier to impl. Waku rdv strategy. The hardcoded min and max TTL were out of range with what we needed and specifying which peers to interact with is also needed since Waku deals with peers on multiple separate shards.
I tried to keep the changes to a minimum, specifically I did not change the name of any public procs which result in less than descriptive names in some cases. I also wanted to return results instead of raising exceptions but didn't. Would it be acceptable to do so?
Please advise on best practices, thank you.