-
Notifications
You must be signed in to change notification settings - Fork 33
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] Refactor P2P interfaces #558
Conversation
4ad4965
to
278558e
Compare
278558e
to
45bdc8a
Compare
0343d5e
to
ec7dbe8
Compare
The new `Peer` interface defines a `GetStream()` method, which returns `io.ReadWriteCloser`. Currently, this must be exposed via the `Transport` interface. This change: - renames `Transport#Read()` to `Transrport#ReadAll()` - embeds `io.ReadWriteCloser` in the `Transport` interface - implements `io.ReadWriteCloser` in the `tcpConn` implementation
b797cd2
to
970946b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bryanchriswhite I didn't do a super deep dive, but mostly looks good.
Overall, the PR got pretty big with lots of renaming and things moving around, so it is getting a little hard to maintain overall context. No actionable feedback but just FYI that I don't think my review on this one is as best as it could be.
98b4761
to
1665e5b
Compare
1665e5b
to
96ad4fb
Compare
shared/p2p/peers_view_test.go
Outdated
) | ||
|
||
func TestSortedPeersView_Remove(t *testing.T) { | ||
t.Skip("TECHDEBT(554): test that this method works as expected when target peer/addr is not in the list!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bryanchriswhite I left a couple replies regarding that we could/should potentially add here. Use your best judgment to do what you deem is appropriate. Approving since it is not a blocker, since you will likely revisit a lot of it in the followup PR and because I'm getting a bit of "PR fatigue" from this one :)
Thanks for bearing with me @Olshansk 🙏 I think we're almost done with the necessarily large PRs (after #576 😅). FWIW, after reflecting on my most recent experience, I've noticed one heuristic I seemed to be using when thinking about if a PR like this can be split seems to boil down the atomicity of commits with respect to the test suite. I.e., can the commits be organized such that there is a commit at which the tests are passing prior to the conclusion of the main change? If the answer is yes, then you have a decent fist estimation for how/where to make a split. |
## @Reviewer This PR may be more digestible / reviewable on a commit-by-commit basis. Commits are organized logically and any given line is only modified in a single commit, with few exceptions. --- ## Description Redifines P2P module packages in terms of new interfaces: - `Peer` / `PeerList` - `Peerstore` - `PeerManager` / `PeersView` This has the effect of decoupling the `Network` implementation (e.g. `rainTreeNetwork`) from the peer representation and storage/lookup. This will be necessary for use with the libp2p based P2P module as it uses different implementations for these concerns. ### Organization This PR adds a *temporary* `shared/p2p` package to facilitate the migration to the new libp2p based P2P module implementation. This package will be re-consolidated into the remaining P2P module as part of #554. ``` ├── p2p │ └── * addrbook_delta_test.go -> peer_test.go └── shared └── p2p ├── + peer.go ├── + peer_manager.go └── + peerstore.go ``` #### peer.go - `Peer` interface - abstracted from [`typesP2P.NetworkPeer`](https://github.com/pokt-network/pocket/blob/main/p2p/types/network_peer.go#L7) and its usage - `PeerList` concrete type (`[]Peer`) - implements a `#Delta()` method - ported from [`GetAddrBookDelta`](https://github.com/pokt-network/pocket/blob/main/p2p/addrbook_delta.go#L6) #### peerstore.go - `Peerstore` interface plus a simple map-based implementation, `PeerAddrMap` #### peer_manager.go - `PeerManager` and `PeerView` interfaces - abstracted from [`raintree.peersManager`](https://github.com/pokt-network/pocket/blob/main/p2p/raintree/peers_manager.go#L15) and its usage - `SortedPeerManager` implementation factored out of the same, `raintree.peersManager` - decouples sorting and "view construction" ([`networkView`](https://github.com/pokt-network/pocket/blob/main/p2p/raintree/peers_manager.go#L181)) behavior from any conception of raintree specific network features (e.g. "levels") ### Nomenclature changes `AddrBook` --> `Peerstore`: The word "address" is becoming ambiguous as libp2p nomenclature uses it to refer to the network address (e.g. IP / hostname). As it's currently used, this object holds more than just the both identity and network address so regardless of interpretation, I would argue that `AddrBook` doesn't accurately convey its responsibility. `Peerstore` also better aligns with other libp2p nomenclature and should result it in more consistent and coherent integration and refactoring going forward. ### Potential next steps 1. Decouple peer connection management from identity/address storage and lookup. - Add a `ConnManager` interface to be responsible for this - Move `Peer#GetStream()` to it - Move `PeerManager#GetSelfAddr()` to it - Refactor accordingly ## Issue Fixes #552 ## Type of change Please mark the relevant option(s): - [ ] New feature, functionality or library - [ ] Bug fix - [x] Code health or cleanup - [ ] Major breaking change - [ ] Documentation - [ ] Other <!-- add details here if it a different type of change --> ## List of changes - Add `Peer` and `Peerstore` interfaces - Refactor `AddrBook` to `PeerList` type - Refactor `getAddrBookDelta` to be a member of `PeerList` - Move `typesP2P.AddrBookMap` to `sharedP2P.PeerAddrMap` and refactor to implement the new `Peerstore` interface - Factor `SortedPeerManager` out of `raintree.peersManager` and add `peerManager` interface - Refactor `raintree.peersManager` to use `SortedPeerManager` and implement `PeerManager` interface - Refactor `stdnetwork.Network` implementation to use P2P interfaces - Refactor `AddrBookProvider` to use new P2P interfaces - Refactor `typesP2P.Network` to use new P2P interfaces - Refactor `typesP2P.Transport` to embed `io.ReadWriteCloser` - Rename `NetworkPeer#Dialer` to `NetworkPeer#Transport`for readability and consistency - Refactor `typesP2P.NetworkPeer` to implement the new `Peer` interface - Refactor debug CLI to use new P2P interfaces ## 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)
This PR may be more digestible / reviewable on a commit-by-commit basis. Commits are organized logically and any given line is only modified in a single commit, with few exceptions. --- Redifines P2P module packages in terms of new interfaces: - `Peer` / `PeerList` - `Peerstore` - `PeerManager` / `PeersView` This has the effect of decoupling the `Network` implementation (e.g. `rainTreeNetwork`) from the peer representation and storage/lookup. This will be necessary for use with the libp2p based P2P module as it uses different implementations for these concerns. This PR adds a *temporary* `shared/p2p` package to facilitate the migration to the new libp2p based P2P module implementation. This package will be re-consolidated into the remaining P2P module as part of ``` ├── p2p │ └── * addrbook_delta_test.go -> peer_test.go └── shared └── p2p ├── + peer.go ├── + peer_manager.go └── + peerstore.go ``` - `Peer` interface - abstracted from [`typesP2P.NetworkPeer`](https://github.com/pokt-network/pocket/blob/main/p2p/types/network_peer.go#L7) and its usage - `PeerList` concrete type (`[]Peer`) - implements a `#Delta()` method - ported from [`GetAddrBookDelta`](https://github.com/pokt-network/pocket/blob/main/p2p/addrbook_delta.go#L6) - `Peerstore` interface plus a simple map-based implementation, `PeerAddrMap` - `PeerManager` and `PeerView` interfaces - abstracted from [`raintree.peersManager`](https://github.com/pokt-network/pocket/blob/main/p2p/raintree/peers_manager.go#L15) and its usage - `SortedPeerManager` implementation factored out of the same, `raintree.peersManager` - decouples sorting and "view construction" ([`networkView`](https://github.com/pokt-network/pocket/blob/main/p2p/raintree/peers_manager.go#L181)) behavior from any conception of raintree specific network features (e.g. "levels") `AddrBook` --> `Peerstore`: The word "address" is becoming ambiguous as libp2p nomenclature uses it to refer to the network address (e.g. IP / hostname). As it's currently used, this object holds more than just the both identity and network address so regardless of interpretation, I would argue that `AddrBook` doesn't accurately convey its responsibility. `Peerstore` also better aligns with other libp2p nomenclature and should result it in more consistent and coherent integration and refactoring going forward. 1. Decouple peer connection management from identity/address storage and lookup. - Add a `ConnManager` interface to be responsible for this - Move `Peer#GetStream()` to it - Move `PeerManager#GetSelfAddr()` to it - Refactor accordingly Fixes pokt-network#552 Please mark the relevant option(s): - [ ] New feature, functionality or library - [ ] Bug fix - [x] Code health or cleanup - [ ] Major breaking change - [ ] Documentation - [ ] Other <!-- add details here if it a different type of change --> - Add `Peer` and `Peerstore` interfaces - Refactor `AddrBook` to `PeerList` type - Refactor `getAddrBookDelta` to be a member of `PeerList` - Move `typesP2P.AddrBookMap` to `sharedP2P.PeerAddrMap` and refactor to implement the new `Peerstore` interface - Factor `SortedPeerManager` out of `raintree.peersManager` and add `peerManager` interface - Refactor `raintree.peersManager` to use `SortedPeerManager` and implement `PeerManager` interface - Refactor `stdnetwork.Network` implementation to use P2P interfaces - Refactor `AddrBookProvider` to use new P2P interfaces - Refactor `typesP2P.Network` to use new P2P interfaces - Refactor `typesP2P.Transport` to embed `io.ReadWriteCloser` - Rename `NetworkPeer#Dialer` to `NetworkPeer#Transport`for readability and consistency - Refactor `typesP2P.NetworkPeer` to implement the new `Peer` interface - Refactor debug CLI to use new P2P interfaces - [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. --> - [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 - [ ] 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)
@Reviewer
This PR may be more digestible / reviewable on a commit-by-commit basis. Commits are organized logically and any given line is only modified in a single commit, with few exceptions.
Description
Redifines P2P module packages in terms of new interfaces:
Peer
/PeerList
Peerstore
PeerManager
/PeersView
This has the effect of decoupling the
Network
implementation (e.g.rainTreeNetwork
) from the peer representation and storage/lookup. This will be necessary for use with the libp2p based P2P module as it uses different implementations for these concerns.Organization
This PR adds a temporary
shared/p2p
package to facilitate the migration to the new libp2p based P2P module implementation. This package will be re-consolidated into the remaining P2P module as part of #554.peer.go
Peer
interfacetypesP2P.NetworkPeer
and its usagePeerList
concrete type ([]Peer
)#Delta()
methodGetAddrBookDelta
peerstore.go
Peerstore
interface plus a simple map-based implementation,PeerAddrMap
peer_manager.go
PeerManager
andPeerView
interfacesraintree.peersManager
and its usageSortedPeerManager
implementation factored out of the same,raintree.peersManager
networkView
) behavior from any conception of raintree specific network features (e.g. "levels")Nomenclature changes
AddrBook
-->Peerstore
: The word "address" is becoming ambiguous as libp2p nomenclature uses it to refer to the network address (e.g. IP / hostname). As it's currently used, this object holds more than just the both identity and network address so regardless of interpretation, I would argue thatAddrBook
doesn't accurately convey its responsibility.Peerstore
also better aligns with other libp2p nomenclature and should result it in more consistent and coherent integration and refactoring going forward.Potential next steps
ConnManager
interface to be responsible for thisPeer#GetStream()
to itPeerManager#GetSelfAddr()
to itIssue
Fixes #552
Type of change
Please mark the relevant option(s):
List of changes
Peer
andPeerstore
interfacesAddrBook
toPeerList
typegetAddrBookDelta
to be a member ofPeerList
typesP2P.AddrBookMap
tosharedP2P.PeerAddrMap
and refactor to implement the newPeerstore
interfaceSortedPeerManager
out ofraintree.peersManager
and addpeerManager
interfaceraintree.peersManager
to useSortedPeerManager
and implementPeerManager
interfacestdnetwork.Network
implementation to use P2P interfacesAddrBookProvider
to use new P2P interfacestypesP2P.Network
to use new P2P interfacestypesP2P.Transport
to embedio.ReadWriteCloser
NetworkPeer#Dialer
toNetworkPeer#Transport
for readability and consistencytypesP2P.NetworkPeer
to implement the newPeer
interfaceTesting
make develop_test
README
Required Checklist
If Applicable Checklist
shared/docs/*
if I updatedshared/*
README(s)