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(swarm): introduce ToSwarm type alias #3242

Conversation

thomaseizinger
Copy link
Contributor

@thomaseizinger thomaseizinger commented Dec 14, 2022

Description

The NetworkBehaviourAction type is often clunky to name because it has several type parameters. Usually, those can all be inferred from the corresponding NetworkBehaviour. However, that would require us to add bounds to the type definition which generally not a good idea because those bounds creep easily into upper layers where you don't want them.

This PR instead adds a type alias for NetworkBehaviourAction called ToSwarm which is just a NetworkBehaviourAction with all parameters inferred from a NetworkBehaviour.

Resolves #3123.

Notes

At the moment, this only compiles by adding type annotations everywhere which is kind of unacceptable. I opened an issue on rust-lang/rust for that: rust-lang/rust#105680.

I think we should not merge this PR until that is sorted.

Depends-On: #3239 to remove the build failures in libp2p-kad.
Depends-On: #3241

I've tagged this as resolving #3123 but didn't straight away deprecate NetworkBehaviourAction because we still use it in gossipsub to implement some optimization via Arc. Once/if #3243 is merged, the next step is to remove the trait bounds from NetworkBehaviourAction.

Links to any relevant issues

Open Questions

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

@thomaseizinger thomaseizinger marked this pull request as draft December 14, 2022 03:56
@thomaseizinger thomaseizinger deleted the branch refactor-autonat/buffer-entire-actions December 16, 2022 20:40
mergify bot pushed a commit that referenced this pull request Dec 20, 2022
Currently, we store messages to be sent to the `ConnectionHandler` in an `Arc`. However, we never actually clone these messages as we can see with this patch, hence we remove this wrapping.

Related: #3242
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.

1 participant