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

Refactor libp2p code #154

Merged
merged 34 commits into from
May 16, 2022
Merged

Refactor libp2p code #154

merged 34 commits into from
May 16, 2022

Conversation

altonen
Copy link
Contributor

@altonen altonen commented Apr 27, 2022

Highlights:

  • replace libp2p::floodsub with libp2p::gossipsub
  • use multiplexing provided by libp2p and remove libp2p::streaming (our fork) and the peer object
  • use libp2p::ping for keep-alive
  • use libp2p::identify for exchanging peer information
  • move protocol handlers to their own files so they are more easily testable
  • remove SocketService and introduce a new request/response-based SyncingService

I'm leaning towards the viewpoint that SwarmManager should ultimately be the one that decided whether inbound/outbound peer is kept in our swarm and not the libp2p::identify handler. The reason for that is because the manager must anyway check the incoming peer information against the info it has (unless we start adding panics to the code) so it would be cleaner if that check was done in one place. I'll experiment with tests to see which is nicer (duplicate check or only SwarmManager checking) and decide based on that. Let me know what you think about it.

For now this is a draft as I still need to write more tests for the libp2p implementation and sync the mock interface with these new changes. I don't expect the tests to reveal a lot of need for changes so you're free to start reviewing if you feel like it.

@altonen altonen force-pushed the libp2p-refactor branch 3 times, most recently from ef6f37d to 2180615 Compare May 2, 2022 05:21
@altonen altonen marked this pull request as ready for review May 4, 2022 06:41
@altonen
Copy link
Contributor Author

altonen commented May 4, 2022

This PR is ready for review. Mock interface and SwarmManager updates will be implemented in separate PRs so this PR doesn't grow any larger.

Copy link
Contributor

@iljakuklic iljakuklic left a comment

Choose a reason for hiding this comment

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

Looks good to me over all. Added a bunch of suggestions. It was not completely clear to me which bits just moved around and which have also changed, so some of the comments may not be specifically connected to the changes in this PR.

common/src/chain/config.rs Show resolved Hide resolved
p2p/src/net/libp2p/mod.rs Outdated Show resolved Hide resolved
p2p/src/net/libp2p/mod.rs Show resolved Hide resolved
p2p/src/net/libp2p/mod.rs Show resolved Hide resolved
p2p/src/net/libp2p/mod.rs Show resolved Hide resolved
p2p/src/net/libp2p/proto/util.rs Show resolved Hide resolved
p2p/src/net/libp2p/proto/util.rs Show resolved Hide resolved
p2p/src/swarm/mod.rs Outdated Show resolved Hide resolved
@altonen altonen force-pushed the libp2p-refactor branch 3 times, most recently from 76c5540 to 132a84a Compare May 10, 2022 08:48
@altonen altonen force-pushed the libp2p-refactor branch 2 times, most recently from bb12802 to 81f5773 Compare May 13, 2022 05:12
altonen added 10 commits May 16, 2022 12:20
Rename common.rs to types.rs to follow naming convention with
the mock interface.
This commit does not implement the now-required message validation
API for the mock interface.
Peer object was used to implement multiplexing between SwarmManager
and SyncManager, to handle handshaking and ping/pong connectivity
checks. Now that responsibility of providing that functionality is
given to the network service provider, the peer object doesn't have
a use in its current form.
From now on it's required that multiplexing is provided by the
network service provider and that the users of the protocol can issue
generic request-response type messages.
Now that handshaking is part of the connection establishment and
that the front-end gets only handshaked connections, peer don't need
to be registered to the backend anymore.
altonen added 24 commits May 16, 2022 12:21
This service is used instead the old SocketService + Peer combo
by allowing the network service provider to do the socket multiplexing
as it sees fit. It simplifies the design on the upper-level and allows
Mintlayer to better utilize the tools libp2p provides.
- configure Ping and Identify protocols
- move protocol handlers to separate files
- creat/interpret protocol string correctly

Unit tests for the protocol handlers are missing
Inbound connections also carry the address of the remote peer which
was previously discarded in the backend.

While there, rename the events more logically.
- rename Strategy to DiscoveryStrategy
- do not use hard-coded ports in tests
- rename addr to bind_addr
- rename config to chain_config
- format source code
- gate `create_custom()` behind "testing" attribute
@altonen altonen merged commit 915ca9d into master May 16, 2022
@altonen altonen deleted the libp2p-refactor branch May 16, 2022 09:56
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.

4 participants