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

Gossipsub Builder Pattern #177

Open
AgeManning opened this issue Mar 17, 2022 · 0 comments
Open

Gossipsub Builder Pattern #177

AgeManning opened this issue Mar 17, 2022 · 0 comments

Comments

@AgeManning
Copy link
Member

Creating a Gossipsub struct is somewhat awkward in the current design.

We have a bunch of new_with_X functions, see for example here: https://github.com/sigp/rust-libp2p/blob/master/protocols/gossipsub/src/behaviour.rs#L342

Apart from being somewhat non-ergonomic, we have recently introduced some metrics into the protocol. One metric requires building a histogram of the score distribution: https://github.com/sigp/rust-libp2p/blob/master/protocols/gossipsub/src/metrics.rs#L227

The metrics need to build constructed when the Gossipsub struct is instantiated but this particular metrics requires bounds for the score. In the current design the scoring system can be activated at some future time rather than during the creation of the Gossipsub struct so we cannot properly initialise this metric.

One way we could resolve this is to use a builder pattern to create the Gossipsub struct and force the user to choose scoring on creation. An example of the builder pattern is with the config: https://github.com/sigp/rust-libp2p/blob/master/protocols/gossipsub/src/config.rs#L389

There are a few traits we need to deal with for the Gossipsub struct, which makes this slightly more complicated than the example. However I'm hoping a builder pattern will be a nicer way of handling the variable configurations for creating a Gossipsub struct.

I had started work on this at some time ages ago and have found an old file lying around which starts this modification. I've put it in this branch: https://github.com/sigp/rust-libp2p/tree/gossipsub-builder

Feel free to use anything in there (I think its just a single file at the moment) or to write from scratch :).

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

No branches or pull requests

1 participant