-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[P2P] refactor: peerstore provider (part 1) (#804)
## Description 1. Simplify `PeerstoreProvider` interface 2. Extend it to support retrieval of the unstaked actor peerstore 3. Implement the extended interface in `persistencePeerstoreProvider` ### Before ```mermaid classDiagram class InterruptableModule { <<interface>> Start() error Stop() error } class IntegratableModule { <<interface>> +SetBus(bus Bus) +GetBus() Bus } class InitializableModule { <<interface>> +GetModuleName() string +Create(bus Bus, opts ...Option) (Module, error) } class Module { <<interface>> } Module --|> InitializableModule Module --|> IntegratableModule Module --|> InterruptableModule class PeerstoreProvider { <<interface>> +GetStakedPeerstoreAtHeight(height int) (Peerstore, error) +GetP2PConfig() *P2PConfig } class persistencePeerstoreProvider class rpcPeerstoreProvider persistencePeerstoreProvider --|> PeerstoreProvider rpcPeerstoreProvider --|> PeerstoreProvider PeerstoreProvider --|> Module ``` ### After ```mermaid classDiagram class IntegratableModule { <<interface>> +GetBus() Bus +SetBus(bus Bus) } class PeerstoreProvider { <<interface>> +GetStakedPeerstoreAtHeight(height int) (Peerstore, error) +GetUnstakedPeerstore() (Peerstore, error) } class persistencePeerstoreProvider class rpcPeerstoreProvider class p2pModule class unstakedPeerstoreProvider { <<interface>> +GetUnstakedPeerstore() (Peerstore, error) } persistencePeerstoreProvider --|> PeerstoreProvider persistencePeerstoreProvider --> p2pModule : from Bus rpcPeerstoreProvider --> p2pModule : from Bus p2pModule --|> unstakedPeerstoreProvider rpcPeerstoreProvider --|> PeerstoreProvider rpcPeerstoreProvider --|> Module PeerstoreProvider --|> IntegratableModule class Module { <<interface>> } Module --|> InitializableModule Module --|> IntegratableModule Module --|> InterruptableModule ``` ## Issue Realted: - #810 Dependants: - #505 - #806 ## 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 <!-- add details here if it a different type of change --> ## List of changes - Replaced embedded `modules.Module` with simpler `modules.IntegratableModule` in `PeerstoreProvider` interface - Removed unused `PeerstoreProvider#GetP2PConfig()` method - Added `PeerstoreProvider#GetUnstakedPeerstore()` method - Added `p2pPeerstoreProvider` implementation of `PeerstoreProvider` interface - Added `Factory` generic type ## Testing - [ ] `make develop_test`; if any code changes were made - [x] `make test_e2e` on [k8s LocalNet](https://github.com/pokt-network/pocket/blob/main/build/localnet/README.md); if any code changes were made - [ ] `e2e-devnet-test` passes tests on [DevNet](https://pocketnetwork.notion.site/How-to-DevNet-ff1598f27efe44c09f34e2aa0051f0dd); if any code was changed - [x] [Docker Compose LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md); if any major functionality was changed or introduced - [x] [k8s LocalNet](https://github.com/pokt-network/pocket/blob/main/build/localnet/README.md); if any infrastructure or configuration changes were made <!-- 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 added, or updated, [`godoc` format comments](https://go.dev/blog/godoc) on touched members (see: [tip.golang.org/doc/comment](https://tip.golang.org/doc/comment)) - [ ] 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](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)
- Loading branch information
1 parent
f72e1f0
commit 9cb0ee9
Showing
16 changed files
with
172 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package testutil | ||
|
||
// Concatenate appends the contents of multiple slices of any type (T) into a | ||
// single slice of type T. | ||
func Concatenate[T any](tt ...[]T) (result []T) { | ||
for _, t := range tt { | ||
result = append(result, t...) | ||
} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package peerstore_provider | ||
|
||
import ( | ||
"fmt" | ||
|
||
typesP2P "github.com/pokt-network/pocket/p2p/types" | ||
"github.com/pokt-network/pocket/shared/modules" | ||
) | ||
|
||
// unstakedPeerstoreProvider is an interface which the p2p module supports in | ||
// order to allow access to the unstaked-actor-router's peerstore. | ||
// | ||
// NB: this peerstore includes all actors which participate in P2P (e.g. full | ||
// and light clients but also validators, servicers, etc.). | ||
// | ||
// TECHDEBT(#811): will become unnecessary after `modules.P2PModule#GetUnstakedPeerstore` is added.` | ||
// CONSIDERATION: split `PeerstoreProvider` into `StakedPeerstoreProvider` and `UnstakedPeerstoreProvider`. | ||
// (see: https://github.com/pokt-network/pocket/pull/804#issuecomment-1576531916) | ||
type unstakedPeerstoreProvider interface { | ||
GetUnstakedPeerstore() (typesP2P.Peerstore, error) | ||
} | ||
|
||
func GetUnstakedPeerstore(bus modules.Bus) (typesP2P.Peerstore, error) { | ||
p2pModule := bus.GetP2PModule() | ||
if p2pModule == nil { | ||
return nil, fmt.Errorf("p2p module is not registered to bus and is required") | ||
} | ||
|
||
unstakedPSP, ok := p2pModule.(unstakedPeerstoreProvider) | ||
if !ok { | ||
return nil, fmt.Errorf("p2p module does not implement unstakedPeerstoreProvider") | ||
} | ||
return unstakedPSP.GetUnstakedPeerstore() | ||
} |
Oops, something went wrong.