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

Abstracts GossipSubRouter interface #505

Conversation

yhassanzadeh13
Copy link
Contributor

Problem Statement

Although in #503 we introduced injectible PubSubRouter into the GossipSub, there are several places in the code that initializing a GossipSub instance with a customized PubSubRouter is failing due to the strict type assertions, e.g., example-1, example-2, and example-3.

Although the rt (router) attribute of the GossipSub is deemed as a PubSubRouter interface type, nevertheless through the initialization phase of the GossipSub the rt attribute is strictly asserted as a GossipSubRouter value type. This is a blocker for initializing GossipSub with customized wrappers around GossipSubRouter as it no longer is going to be a GossipSubRouter strict value type. Hence the initialization fails with an pubsub router is not gossipsub error.

Contributions

In order to resolve the initialization failure due to the strict type assertions with GossipSubRouter this PR introduces the following changes:

  • We define the GossipPubSubRouter interface type, and replaced strict type assertions with interface type assertions.
  • We decouple the option functions that deal with GossipSubRouter struct type from those deal with the PubSub.

yhassanzadeh13 and others added 7 commits October 19, 2022 13:31
* Enables non-atomic validation for peer scoring parameters (libp2p#499)

* decouples topic scoring parameters

* adds skiping atomic validation for topic parameters

* cleans up

* adds skip atomic validation to peer score threshold

* adds skip atomic validation for peer parameters

* adds test for non-atomic validation

* adds tests for peer score

* adds tests for peer score thresholds

* refactors tests

* chore: Update .github/workflows/stale.yml [skip ci]

* adds with gossipsub tracker

Co-authored-by: libp2p-mgmt-read-write[bot] <104492852+libp2p-mgmt-read-write[bot]@users.noreply.github.com>
@vyzo vyzo self-requested a review November 9, 2022 04:31
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.

Well, day of reckoning.... sigh.

I am really not fond of reifying and exposing the internal types like that, but i can accept it if there is no other way around it.

Are you sure this isnt the case?
Cant we just reify the router type and offer an interface you can use, without changing the internal plumbing?

These abstractions are not public proof and thre is cost associated with having to go through the interface potentially (hundreds of) thousands times per second.

rt, err := DefaultGossipSubRouter(h)
if err != nil {
return nil, fmt.Errorf("failed to create default gossipsub router: %w", err)
}
opts = append(opts, WithRawTracer(rt.tagTracer))
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to find a way to absorb this (the tag tracer) into the defaults, it is very error prone to require it to be explicitly instantaited.


gs.gossipTracer = newGossipTracer()
gs.SetGossipTracer(newGossipTracer())
Copy link
Collaborator

Choose a reason for hiding this comment

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

this very ugly.

@yhassanzadeh13
Copy link
Contributor Author

Thanks @vyzo, closing this PR in the favor of #509

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.

2 participants