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

Merged
merged 6 commits into from
Sep 25, 2024
Merged

feat: rendezvous refactor #1183

merged 6 commits into from
Sep 25, 2024

Conversation

SionoiS
Copy link
Contributor

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

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
Contributor 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
Contributor

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

@SionoiS
Copy link
Contributor 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
Contributor 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
Contributor

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
Contributor 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
Contributor

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

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

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

@diegomrsantos
Copy link
Contributor

specifying which peers to interact with is also needed since Waku deals with peers on multiple separate shards.

Thank you for the changes. Could you please elaborate more on this feature?

@SionoiS
Copy link
Contributor Author

SionoiS commented Sep 23, 2024

specifying which peers to interact with is also needed since Waku deals with peers on multiple separate shards.

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.

) {.async, base.} =
let sprBuff = rdv.switch.peerInfo.signedPeerRecord.encode().valueOr:
raise newException(RendezVousError, "Wrong Signed Peer Record")
proc batchAdvertise*(
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Collaborator

@lchenut lchenut Sep 24, 2024

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Collaborator

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

Copy link
Contributor

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?

Copy link
Collaborator

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.

Copy link
Contributor

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

Copy link
Contributor

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

Thank you, it looks good.

@SionoiS
Copy link
Contributor Author

SionoiS commented Sep 24, 2024

I changed the names but I'll let someone else do the docs since there's none yet.

@diegomrsantos diegomrsantos added this pull request to the merge queue Sep 25, 2024
Merged via the queue into master with commit d389d96 Sep 25, 2024
14 checks passed
@diegomrsantos diegomrsantos deleted the feat--rendezvous-refactor branch September 25, 2024 10:10
shashankshampi added a commit that referenced this pull request Oct 1, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: done
Development

Successfully merging this pull request may close these issues.

3 participants