-
Notifications
You must be signed in to change notification settings - Fork 33
[P2P] refactor: peerstore provider (part 1) #804
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
Merged
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
34d42bf
refactor: move `persistencePeerstoreProvider` & implement `#GetUnstak…
bryanchriswhite 142071d
feat: add `p2pPeerstoreProvider`
bryanchriswhite bcf3f65
refactor: only embed IntegratableModule in PeerstoreProvider
bryanchriswhite 00730d4
refactor: remove unused `PeerstoreProvider#GetP2PConfig()` method
bryanchriswhite 41d18ae
feat: add `PeerstoreProvider#GetUnstakedPeerstore()` interface method
bryanchriswhite 507d8af
chore: implement `rpcPeerstoreProvider#GetUnstakedPeerstore()`
bryanchriswhite e74fea4
chore: add TECHDEBT comment
bryanchriswhite 6128d84
chore: add `Factory` generic type
bryanchriswhite 4bc605a
chore: update comments
bryanchriswhite 094a95e
chore: update changelogs
bryanchriswhite 2a5b300
chore: update changelogs
bryanchriswhite 1d03f38
empty commit
bryanchriswhite c1318da
chore: replace empty interfaces with `any`
bryanchriswhite 8d1f62a
chore: edit comment
bryanchriswhite 08bcafd
chore: remove unused `GetP2PConfig()` method
bryanchriswhite 5a54400
chore: add godoc comments
bryanchriswhite 5000ad8
fix: retrieve p2p mdoule from bus on each call
bryanchriswhite c587afa
refactor: persistence peerstor provider
bryanchriswhite e70b99c
refactor: embed `p2pPStoreProviderFactory`
bryanchriswhite b3ce271
chore: oneline function signature
bryanchriswhite 8a476a4
refactor: consolidate p2pPeerstoreProvider into persistencePeerstorPr…
bryanchriswhite 650d432
refactor: rename persistence.go back to provider.go
bryanchriswhite 59fffb5
refactor: `p2pPeerstoreProvider` to a single function'
bryanchriswhite a1e22c4
refactor: update peerstore provider method receivers
bryanchriswhite ccd9fb7
refactor: re-implement `GetUnstakedPeerstore`
bryanchriswhite 6e1a5b8
chore: add TECHDEBT comments
bryanchriswhite 60302a4
chore: add issue numbers to TECHDEBT comments
bryanchriswhite 1ac2e00
chore: improve comment
bryanchriswhite 3a8e138
refactor: rename `T` & `K` type params to `M` &`C`
bryanchriswhite 0cbca43
chore: update changelogs
bryanchriswhite 9cee9dd
fix: bugs
bryanchriswhite 2489b92
Merge remote-tracking branch 'pokt/main' into refactor/peerstore-prov…
bryanchriswhite c98e8d1
chore: add TECHDEBT comments
bryanchriswhite 84ce1bd
chore: combine `NewRPCPeerstoreProvider()` & `Create()`
bryanchriswhite 341d982
refactor: rename `NewPersistencePeerstoreProvider()` to `Create()`
bryanchriswhite a9ffa56
chore: persistence peerstore provider includes all staked actors
bryanchriswhite 0d92a09
chore: fix consensus test
bryanchriswhite 024d88b
fix: p2p test
bryanchriswhite 22ff0fd
chore: update changelogs
bryanchriswhite 044f6f1
revert: `readCtx.GetAllStakedActors()`
bryanchriswhite b273e87
chore: update changelogs
bryanchriswhite 2e4d60d
chore: fix nit
bryanchriswhite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -3,19 +3,28 @@ package persistence | |
| import ( | ||
| "github.com/pokt-network/pocket/p2p/providers/peerstore_provider" | ||
| typesP2P "github.com/pokt-network/pocket/p2p/types" | ||
| "github.com/pokt-network/pocket/runtime/configs" | ||
| "github.com/pokt-network/pocket/shared/modules" | ||
| "github.com/pokt-network/pocket/shared/modules/base_modules" | ||
| ) | ||
|
|
||
| var _ peerstore_provider.PeerstoreProvider = &persistencePeerstoreProvider{} | ||
| var ( | ||
| _ peerstore_provider.PeerstoreProvider = &persistencePeerstoreProvider{} | ||
| _ persistencePStoreProviderFactory = &persistencePeerstoreProvider{} | ||
| ) | ||
|
|
||
| type persistencePStoreProviderOption func(*persistencePeerstoreProvider) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the topic of "not being afraid to change everything", take into consideration that maybe "providers" aren't the best approach with our bus based system. Not making a comment on removing/extending them, but just sharing that it is not set in stone so don't feel constrained. |
||
| type persistencePStoreProviderFactory = modules.FactoryWithOptions[peerstore_provider.PeerstoreProvider, persistencePStoreProviderOption] | ||
|
|
||
| // TECHDEBT(#810): refactor to implement `Submodule` interface. | ||
| type persistencePeerstoreProvider struct { | ||
| base_modules.IntegratableModule | ||
| base_modules.InterruptableModule | ||
| } | ||
|
|
||
| func NewPersistencePeerstoreProvider(bus modules.Bus, options ...func(*persistencePeerstoreProvider)) *persistencePeerstoreProvider { | ||
| func Create(bus modules.Bus, options ...persistencePStoreProviderOption) (peerstore_provider.PeerstoreProvider, error) { | ||
| return new(persistencePeerstoreProvider).Create(bus, options...) | ||
| } | ||
|
|
||
| func (*persistencePeerstoreProvider) Create(bus modules.Bus, options ...persistencePStoreProviderOption) (peerstore_provider.PeerstoreProvider, error) { | ||
| pabp := &persistencePeerstoreProvider{ | ||
| IntegratableModule: *base_modules.NewIntegratableModule(bus), | ||
| } | ||
|
|
@@ -24,35 +33,30 @@ func NewPersistencePeerstoreProvider(bus modules.Bus, options ...func(*persisten | |
| o(pabp) | ||
| } | ||
|
|
||
| return pabp | ||
| } | ||
|
|
||
| func Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) { | ||
| return new(persistencePeerstoreProvider).Create(bus, options...) | ||
| } | ||
|
|
||
| func (*persistencePeerstoreProvider) Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) { | ||
| return NewPersistencePeerstoreProvider(bus), nil | ||
| return pabp, nil | ||
| } | ||
|
|
||
| func (*persistencePeerstoreProvider) GetModuleName() string { | ||
| return peerstore_provider.ModuleName | ||
| } | ||
|
|
||
| func (pabp *persistencePeerstoreProvider) GetStakedPeerstoreAtHeight(height uint64) (typesP2P.Peerstore, error) { | ||
| readCtx, err := pabp.GetBus().GetPersistenceModule().NewReadContext(int64(height)) | ||
| // GetStakedPeerstoreAtHeight implements the respective `PeerstoreProvider` interface method. | ||
| func (persistencePSP *persistencePeerstoreProvider) GetStakedPeerstoreAtHeight(height uint64) (typesP2P.Peerstore, error) { | ||
| readCtx, err := persistencePSP.GetBus().GetPersistenceModule().NewReadContext(int64(height)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer readCtx.Release() | ||
|
|
||
| // TECHDEBT(#818): consider all staked actors, not just validators. | ||
| validators, err := readCtx.GetAllValidators(int64(height)) | ||
bryanchriswhite marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return peerstore_provider.ActorsToPeerstore(pabp, validators) | ||
| return peerstore_provider.ActorsToPeerstore(persistencePSP, validators) | ||
| } | ||
|
|
||
| func (pabp *persistencePeerstoreProvider) GetP2PConfig() *configs.P2PConfig { | ||
| return pabp.GetBus().GetRuntimeMgr().GetConfig().P2P | ||
| // GetStakedPeerstoreAtHeight implements the respective `PeerstoreProvider` interface method. | ||
| func (persistencePSP *persistencePeerstoreProvider) GetUnstakedPeerstore() (typesP2P.Peerstore, error) { | ||
| return peerstore_provider.GetUnstakedPeerstore(persistencePSP.GetBus()) | ||
| } | ||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.