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

allow waiting for enough peers in gossipsub #452

Merged
merged 1 commit into from
Oct 29, 2021
Merged

allow waiting for enough peers in gossipsub #452

merged 1 commit into from
Oct 29, 2021

Conversation

mvdan
Copy link
Contributor

@mvdan mvdan commented Sep 21, 2021

(see commit message)

@mvdan
Copy link
Contributor Author

mvdan commented Sep 21, 2021

FYI @adlrocha @masih @willscott for the time.Sleep TODOs in go-legs and indexer-reference-provider.

@mvdan
Copy link
Contributor Author

mvdan commented Sep 21, 2021

@willscott another question is how to expose this via go-legs. Right now it calls NewGossipSub, which creates a GossipSubRouter and feeds it to NewPubSub. Unfortunately, that is then hidden behind an unexported field in PubSub.rt, so neither go-legs nor its downstreams can access it to call methods like WaitEnoughPeers.

One option would be to add another method, like:

func (*PubSub) Router() PubSubRouter

Thoughts, @vyzo?

@mvdan
Copy link
Contributor Author

mvdan commented Sep 21, 2021

Yet another option is to leave it up to the downstream to poll EnoughPeers in a loop, since that's already part of the PubSubRouter interface. That would certainly work, but then we'd be stuck with polling and sleeping forever, without the ability to do better like the TODO says. So I think supporting a standard method like "wait for enough peers" is worthwhile.

I'm new to this module and its design, though, so maybe there's a better design to be had here.

Copy link
Collaborator

@vyzo vyzo left a comment

Choose a reason for hiding this comment

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

This should be part of the pubsub interface, not the router; all routers implement enough peers.
Also, thread safety...

@vyzo
Copy link
Collaborator

vyzo commented Sep 23, 2021

Actually it should be in the topic interface.

@vyzo
Copy link
Collaborator

vyzo commented Sep 23, 2021

and there is also machinery for topic related events, which can make implementation of this much nicer.

@vyzo
Copy link
Collaborator

vyzo commented Sep 23, 2021

and there is already an option that more or less does what you want, it's called WithReadiness.

@mvdan
Copy link
Contributor Author

mvdan commented Sep 23, 2021

and there is already an option that more or less does what you want, it's called WithReadiness.

I saw that, but it doesn't do anything at all in our case, because we're not using WithDiscovery.
Maybe we could teach that option to also work without WithDiscovery? It's unclear to me what API would be nicest.

Actually it should be in the topic interface.

That's fine by me; I was just following EnoughPeers. I can rewrite this PR if we can agree on what API to add or modify.

@vyzo
Copy link
Collaborator

vyzo commented Sep 23, 2021 via email

@mvdan
Copy link
Contributor Author

mvdan commented Sep 23, 2021

then open an issue to discuss and agree on an api.

Done: #454

@vyzo
Copy link
Collaborator

vyzo commented Sep 23, 2021 via email

@mvdan
Copy link
Contributor Author

mvdan commented Oct 28, 2021

I've updated the code to no longer be racy, I think - the added WithReadiness logic inside Publish now uses the eval channel to call the ready func, which then calls EnoughPeers. Can you take another look?

Copy link
Collaborator

@vyzo vyzo left a comment

Choose a reason for hiding this comment

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

i would say this is good enough.

However, please don't change the gossipsub tests to remove the sleep, we want to test mesh formation with heartbeats.

gossipsub.go Outdated Show resolved Hide resolved
topic.go Outdated Show resolved Hide resolved
@mvdan
Copy link
Contributor Author

mvdan commented Oct 28, 2021

Hm, I'm not sure I understand removing the sleeps from tests. Sleeping for two seconds or sleep-polling until the equivalent condition is met seems basically the same, just that sleeping makes the tests slower. I'm happy to revert those changes though, as I'm not the maintainer.

If I'm not touching any of the existing tests, then it sounds like I need to add a new test to cover this feature.

@vyzo
Copy link
Collaborator

vyzo commented Oct 28, 2021 via email

@mvdan
Copy link
Contributor Author

mvdan commented Oct 29, 2021

All done, I think.

Copy link
Collaborator

@vyzo vyzo left a comment

Choose a reason for hiding this comment

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

looks pretty good - we just need to avoid unnecessary ticker allocations once we've got enough peers.

topic.go Outdated Show resolved Hide resolved
That is, when MinTopicSize is used but not WithDiscovery,
Publish will keep waiting until MinTopicSize's condition is met.

At the moment, this is done by polling every 200ms.
In the future, the mechanism could be optimized to be event-based.
A TODO is left for that purpose.

Fixes #454.
Copy link
Collaborator

@vyzo vyzo 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!

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

Successfully merging this pull request may close these issues.

support waiting until a gossipsub topic has enough peers
2 participants