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: rendezvous refactor #1183

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

feat: rendezvous refactor #1183

wants to merge 5 commits into from

Conversation

SionoiS
Copy link

@SionoiS SionoiS commented Aug 28, 2024

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.

@SionoiS SionoiS self-assigned this Aug 28, 2024
@diegomrsantos
Copy link
Collaborator

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?

@lchenut
Copy link
Collaborator

lchenut commented Aug 30, 2024

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.
In theory, you shouldn't have to change those.

@SionoiS
Copy link
Author

SionoiS commented Aug 30, 2024

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. In theory, you shouldn't have to change those.

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.

@diegomrsantos
Copy link
Collaborator

@SionoiS is the PR's purpose to make those hardcoded values configurable?

@SionoiS
Copy link
Author

SionoiS commented Aug 30, 2024

@SionoiS is the PR's purpose to make those hardcoded values configurable?

Yes and also allow the selection of specific peers for advertise and request

@SionoiS
Copy link
Author

SionoiS commented Sep 16, 2024

Anything else I can do or suggestions for this PR @diegomrsantos @lchenut ?

Waku's rendezvous work is blocked by this.

cc @jm-clius

@diegomrsantos
Copy link
Collaborator

I also wanted to return results instead of raising exceptions but didn't. Would it be acceptable to do so?

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.

@lchenut
Copy link
Collaborator

lchenut commented Sep 19, 2024

@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.

  • Users can set a minimum bigger than the maximum, which will cause a weird behavior.
  • While I get why you could use a shorter TTL, using one bigger than 72 hours seems a bit excessive, I would limit the maximum.

But overall, this PR looks great.

@SionoiS
Copy link
Author

SionoiS commented Sep 19, 2024

Thanks for the comments. I will make the changes.

Copy link
Collaborator

@lchenut lchenut left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -690,6 +690,15 @@ proc new*(
minDuration = MinimumDuration,
maxDuration = MaximumDuration,
): T =
if minDuration < 1.minutes:
raiseAssert("TTL too short: 1 minute minimum")
Copy link
Collaborator

@diegomrsantos diegomrsantos Sep 20, 2024

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.

Copy link
Collaborator

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).

Copy link
Collaborator

@diegomrsantos diegomrsantos left a 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(),
Copy link
Collaborator

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?

Copy link
Collaborator

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

@SionoiS
Copy link
Author

SionoiS commented Sep 20, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants