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

[P2P] Initial libp2p integration #500

Closed
wants to merge 92 commits into from
Closed

[P2P] Initial libp2p integration #500

wants to merge 92 commits into from

Conversation

bryanchriswhite
Copy link
Contributor

@bryanchriswhite bryanchriswhite commented Feb 8, 2023

Description

Adds a new P2P module implementation which wraps libp2p abstractions (mainly host.Host and pubsub.Pubsub) and adapts them to the current interfaces (modules.Module, types.Network, types.Transport).

Network Implementation

For "broadcast" messages (i.e. send to the network), the network implementation utilizes go-libp2p-pubsub to establish a publish / subscribe relationship between network nodes. A pubsub router implementation is used to determine which nodes to send which messages. For simplicity, this initial implementation uses the basic FloodSubRouter, which causes each node to contact every other node directly (i.e. fully-connected network); however, more sophisticated options are available, such as RandomSubRouter and GossipSubRouter.

For "direct" messages (i.e. send to specific node by identity), the network implementation opens a new stream to the desired peer, writes the network level message, establishing a connection to the peer if one does not already exist in the libp2p-managed connection pool, and then closes the stream. On the receiving side, peers watch for incoming streams on network start. When a new stream is opened by a remote peer, it's read from until EOF (i.e. stream closes) or until the read deadline times out.

Address Book

The network interface makes its API responsible for managing the address book (i.e. adding / removing peers). As this is encapsulated by the host.Host implementation in the libp2p regime, the new network implementation maintains a map of pocket peers by pocket "address", analogous to other network implementations; however, the pocket peers retrieved from this map are subsequently converted to their respective libp2p representations (peer.AddrInfo) for use by libp2p. The "pocket address book" is also updated when a remote peer opens a new stream, keeping it in sync with libp2p's.

Next Steps

  1. Redefine P2P concrete types in terms of interfaces
    • PeersManager (raintree/peersManager)
    • Peer (p2p/types/NetworkPeer)
    • AddrBook (p2p/types/AddrBook)
    • AddrBookMap (p2p/types/NetworkPeer)
    • rainTreeNetwork shouldn't depend on any concrete p2p types
  2. Simplify libp2p module implementation
    • The Transport interface likely reduces to nothing
    • The Network interface can be simplified
    • Consider renaming "network" as it functions more like a "router"
      (NB: could be replaced in future iterations with a "raintree pubsub router")
  3. Remove "legacy" P2P module & rename libp2p module directory (possibly object names as well)
    • P2PModule interface can be simplified
    • Clean up TECHDEBT introduced in debug CLI and node startup

Issue

Relates to #347

Type of change

Please mark the relevant option(s):

  • New feature, functionality or library
  • Bug fix
  • Code health or cleanup
  • Major breaking change
  • Documentation
  • Other

List of changes

  • Adds a new libp2p-based P2P modules.Module implementation in p2p/libp2p.
  • Adds a new types.Network implemenation.
  • Adds a new types.Transport.
  • Adds new P2P config options:
    • use_lib_p2p to switch between the two P2P modules.
    • hostname to specify a registered name or IP address to listen on.

Testing

  • make develop_test
  • LocalNet w/ all of the steps outlined in the README

Required Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have tested my changes using the available tooling
  • I have updated the corresponding CHANGELOG

If Applicable Checklist

  • I have updated the corresponding README(s); local and/or global
  • I have added tests that prove my fix is effective or that my feature works
  • I have added, or updated, mermaid.js diagrams in the corresponding README(s)
  • I have added, or updated, documentation and mermaid.js diagrams in shared/docs/* if I updated shared/*README(s)

@bryanchriswhite bryanchriswhite added core Core infrastructure - protocol related p2p P2P specific changes labels Feb 8, 2023
@bryanchriswhite bryanchriswhite self-assigned this Feb 8, 2023
@bryanchriswhite bryanchriswhite linked an issue Feb 8, 2023 that may be closed by this pull request
6 tasks
@bryanchriswhite bryanchriswhite force-pushed the chore/libp2p branch 2 times, most recently from cca88a7 to f37f302 Compare February 9, 2023 13:40
@bryanchriswhite bryanchriswhite force-pushed the chore/libp2p branch 3 times, most recently from 0562356 to c1fb339 Compare February 13, 2023 09:22
@bryanchriswhite
Copy link
Contributor Author

Closing in preparation for splitting.

bryanchriswhite added a commit that referenced this pull request Mar 1, 2023
## Description

This is another of a series of PRs split out from
#500. Here we update the base
and P2P configs in preparation for the addition of the libp2p module.

## Issue

#347 

## Type of change

Please mark the relevant option(s):

- [x] New feature, functionality or library
- [ ] Bug fix
- [ ] Code health or cleanup
- [ ] Major breaking change
- [ ] Documentation
- [ ] Other <!-- add details here if it a different type of change -->

## List of changes

- Replace `consensus_port` with `port` in P2P config.
- Update default P2P config `port` to from `8080` to `42069`.
- Add `use_libp2p` field to base config.
- Add `hostname` field to P2P config.
- Update state hash test after modifying genesis (updated port numbers).

## Testing

- [x] `make develop_test`
- [x]
[LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md)
w/ all of the steps outlined in the `README`

## Required Checklist

- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have tested my changes using the available tooling
- [x] I have updated the corresponding CHANGELOG

### If Applicable Checklist

- [ ] I have updated the corresponding README(s); local and/or global
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have added, or updated,
[mermaid.js](https://mermaid-js.github.io) diagrams in the corresponding
README(s)
- [ ] I have added, or updated, documentation and
[mermaid.js](https://mermaid-js.github.io) diagrams in `shared/docs/*`
if I updated `shared/*`README(s)
bryanchriswhite added a commit that referenced this pull request Mar 2, 2023
## Description

This is the first of a series of PRs split out from #500. Here we set up
the new libp2p module directory structure and add crypto and identity /
network helpers.

## Issue

#347 

## Type of change

Please mark the relevant option(s):

- [x] New feature, functionality or library
- [ ] Bug fix
- [ ] Code health or cleanup
- [ ] Major breaking change
- [ ] Documentation
- [ ] Other <!-- add details here if it a different type of change -->

## List of changes

- prepare pocket repo new libp2p module
- add pocket / libp2p identity helpers
- add url <--> multiaddr conversion helpers for use with libp2p (see:
https://github.com/multiformats/go-multiaddr)
- add pokt --> libp2p crypto helpers

## Testing

- [x] `make develop_test`
- [x]
[LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md)
w/ all of the steps outlined in the `README`

<!-- REMOVE this comment block after following the instructions
 If you added additional tests or infrastructure, describe it here.
 Bonus points for images and videos or gifs.
-->

## Required Checklist

- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have tested my changes using the available tooling
- [x] I have updated the corresponding CHANGELOG

### If Applicable Checklist

- [ ] I have updated the corresponding README(s); local and/or global
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have added, or updated,
[mermaid.js](https://mermaid-js.github.io) diagrams in the corresponding
README(s)
- [ ] I have added, or updated, documentation and
[mermaid.js](https://mermaid-js.github.io) diagrams in `shared/docs/*`
if I updated `shared/*`README(s)

---------

Co-authored-by: Alessandro De Blasis <[email protected]>
bryanchriswhite added a commit that referenced this pull request Mar 3, 2023
## Description

This is another of a series of PRs split out from
#500. Here we add a new
implementation of `typesP2P.Network` in terms of libp2p abstractions,
utilizing the helpers which were added in #534.

## Issue

#347 

## Type of change

Please mark the relevant option(s):

- [x] New feature, functionality or library
- [ ] Bug fix
- [ ] Code health or cleanup
- [ ] Major breaking change
- [ ] Documentation
- [ ] Other <!-- add details here if it a different type of change -->

## List of changes

- Added a new `typesP2P.Network` implementation to the `libp2p` module
directory
- Added embedded `modules.InitializableModule` to the P2P
`AddrBookProvider` interface so that it can be dependency injected as a
`modules.Module` via the bus registry.
- Added `PoktProtocolID` for use within the libp2p module or by public
API consumers

## Testing

- [x] `make develop_test`
- [x]
[LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md)
w/ all of the steps outlined in the `README`

## Required Checklist

- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have tested my changes using the available tooling
- [x] I have updated the corresponding CHANGELOG

### If Applicable Checklist

- [ ] I have updated the corresponding README(s); local and/or global
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have added, or updated,
[mermaid.js](https://mermaid-js.github.io) diagrams in the corresponding
README(s)
- [ ] I have added, or updated, documentation and
[mermaid.js](https://mermaid-js.github.io) diagrams in `shared/docs/*`
if I updated `shared/*`README(s)

---------

Co-authored-by: Alessandro De Blasis <[email protected]>
bryanchriswhite added a commit that referenced this pull request Mar 3, 2023
## Description

This is another of a series of PRs split out from
#500. Here we add a new
`modules.P2PModule` implementation which utilizes the `typesP2P.Network`
implementation which was added in #540. It will be utilized together
with the config changes introduced by #535 in forthcoming changes to the
node and debug CLI.

## Issue

#347 

## Type of change

Please mark the relevant option(s):

- [x] New feature, functionality or library
- [ ] Bug fix
- [ ] Code health or cleanup
- [ ] Major breaking change
- [ ] Documentation
- [ ] Other <!-- add details here if it a different type of change -->

## List of changes

- Added a new `modules.P2PModule` implementation to the `libp2p` module
directory

## Testing

- [x] `make develop_test`
- [x]
[LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md)
w/ all of the steps outlined in the `README`

## Required Checklist

- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have tested my changes using the available tooling
- [x] I have updated the corresponding CHANGELOG

### If Applicable Checklist

- [ ] I have updated the corresponding README(s); local and/or global
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have added, or updated,
[mermaid.js](https://mermaid-js.github.io) diagrams in the corresponding
README(s)
- [ ] I have added, or updated, documentation and
[mermaid.js](https://mermaid-js.github.io) diagrams in `shared/docs/*`
if I updated `shared/*`README(s)
bryanchriswhite added a commit that referenced this pull request Mar 3, 2023
## Description

This is another (last, probably) in a series of PRs split out from
#500. Here we finally enable
support for use of the new libp2p module (and dependent packages) by
considering the config changes made in #535 in the node and debug CLI.

## Issue

#347 

## Type of change

Please mark the relevant option(s):

- [x] New feature, functionality or library
- [ ] Bug fix
- [ ] Code health or cleanup
- [ ] Major breaking change
- [ ] Documentation
- [ ] Other <!-- add details here if it a different type of change -->

## List of changes

- Support libp2p module in node
- Support libp2p module in debug CLI

## Testing

- [x] `make develop_test`
- [x]
[LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md)
w/ all of the steps outlined in the `README`

<!-- REMOVE this comment block after following the instructions
 If you added additional tests or infrastructure, describe it here.
 Bonus points for images and videos or gifs.
-->

## Required Checklist

- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have tested my changes using the available tooling
- [x] I have updated the corresponding CHANGELOG

### If Applicable Checklist

- [ ] I have updated the corresponding README(s); local and/or global
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have added, or updated,
[mermaid.js](https://mermaid-js.github.io) diagrams in the corresponding
README(s)
- [ ] I have added, or updated, documentation and
[mermaid.js](https://mermaid-js.github.io) diagrams in `shared/docs/*`
if I updated `shared/*`README(s)
@Olshansk Olshansk deleted the chore/libp2p branch June 2, 2023 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core infrastructure - protocol related p2p P2P specific changes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[P2P] Integrate LibP2P
3 participants