From 34d42bf013f2d1679061acdfd582ccfffaaa8e44 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 5 Jun 2023 10:04:52 +0200 Subject: [PATCH 01/41] refactor: move `persistencePeerstoreProvider` & implement `#GetUnstakedPeerstore()` --- .../persistence/{provider.go => persistence.go} | 9 +++++++++ 1 file changed, 9 insertions(+) rename p2p/providers/peerstore_provider/persistence/{provider.go => persistence.go} (87%) diff --git a/p2p/providers/peerstore_provider/persistence/provider.go b/p2p/providers/peerstore_provider/persistence/persistence.go similarity index 87% rename from p2p/providers/peerstore_provider/persistence/provider.go rename to p2p/providers/peerstore_provider/persistence/persistence.go index e7c8e7a40..a5e23e74b 100644 --- a/p2p/providers/peerstore_provider/persistence/provider.go +++ b/p2p/providers/peerstore_provider/persistence/persistence.go @@ -1,6 +1,8 @@ package persistence import ( + "fmt" + "github.com/pokt-network/pocket/p2p/providers/peerstore_provider" typesP2P "github.com/pokt-network/pocket/p2p/types" "github.com/pokt-network/pocket/runtime/configs" @@ -15,6 +17,7 @@ type persistencePeerstoreProvider struct { base_modules.InterruptableModule } +// TECHDEBT: refactor func NewPersistencePeerstoreProvider(bus modules.Bus, options ...func(*persistencePeerstoreProvider)) *persistencePeerstoreProvider { pabp := &persistencePeerstoreProvider{ IntegratableModule: *base_modules.NewIntegratableModule(bus), @@ -27,10 +30,12 @@ func NewPersistencePeerstoreProvider(bus modules.Bus, options ...func(*persisten return pabp } +// TECHDEBT: remove func Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) { return new(persistencePeerstoreProvider).Create(bus, options...) } +// TECHDEBT: refactor func (*persistencePeerstoreProvider) Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) { return NewPersistencePeerstoreProvider(bus), nil } @@ -56,3 +61,7 @@ func (pabp *persistencePeerstoreProvider) GetStakedPeerstoreAtHeight(height uint func (pabp *persistencePeerstoreProvider) GetP2PConfig() *configs.P2PConfig { return pabp.GetBus().GetRuntimeMgr().GetConfig().P2P } + +func (pabp *persistencePeerstoreProvider) GetUnstakedPeerstore() (typesP2P.Peerstore, error) { + return nil, fmt.Errorf("persistence peerstore provider does not support unstaked peerstore") +} From 142071d951467d00549c75a67199331f903c6a5d Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 5 Jun 2023 10:05:41 +0200 Subject: [PATCH 02/41] feat: add `p2pPeerstoreProvider` --- .../peerstore_provider/persistence/p2p.go | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 p2p/providers/peerstore_provider/persistence/p2p.go diff --git a/p2p/providers/peerstore_provider/persistence/p2p.go b/p2p/providers/peerstore_provider/persistence/p2p.go new file mode 100644 index 000000000..18d645c21 --- /dev/null +++ b/p2p/providers/peerstore_provider/persistence/p2p.go @@ -0,0 +1,72 @@ +package persistence + +import ( + "fmt" + + "github.com/pokt-network/pocket/p2p/providers/peerstore_provider" + typesP2P "github.com/pokt-network/pocket/p2p/types" + "github.com/pokt-network/pocket/shared/modules" + "github.com/pokt-network/pocket/shared/modules/base_modules" +) + +var ( + _ peerstore_provider.PeerstoreProvider = &p2pPeerstoreProvider{} + _ p2pPStoreProviderFactory = &p2pPeerstoreProvider{} +) + +// unstakedPeerstoreProvider is an interface which the p2p module supports in +// order to allow access to the unstaked-actor-router's peerstore +// +// TECHDEBT(#xxx): 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) +} + +type p2pPStoreProviderFactory = modules.Factory[peerstore_provider.PeerstoreProvider] + +type p2pPeerstoreProvider struct { + base_modules.IntegratableModule + persistencePeerstoreProvider + + p2pModule modules.P2PModule +} + +func NewP2PPeerstoreProvider( + bus modules.Bus, +) (peerstore_provider.PeerstoreProvider, error) { + return new(p2pPeerstoreProvider).Create(bus) +} + +func (*p2pPeerstoreProvider) Create( + bus modules.Bus, +) (peerstore_provider.PeerstoreProvider, error) { + if bus == nil { + return nil, fmt.Errorf("bus is required") + } + + p2pModule := bus.GetP2PModule() + if p2pModule == nil { + return nil, fmt.Errorf("p2p module is not registered to bus and is required") + } + + p2pPSP := &p2pPeerstoreProvider{ + IntegratableModule: *base_modules.NewIntegratableModule(bus), + p2pModule: p2pModule, + } + + return p2pPSP, nil +} + +func (*p2pPeerstoreProvider) GetModuleName() string { + return peerstore_provider.ModuleName +} + +func (p2pPSP *p2pPeerstoreProvider) GetUnstakedPeerstore() (typesP2P.Peerstore, error) { + unstakedPSP, ok := p2pPSP.p2pModule.(unstakedPeerstoreProvider) + if !ok { + return nil, fmt.Errorf("p2p module does not implement unstakedPeerstoreProvider") + } + return unstakedPSP.GetUnstakedPeerstore() +} From bcf3f650a71185bbff6269eca82e16f19cc1f3cf Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 5 Jun 2023 09:54:03 +0200 Subject: [PATCH 03/41] refactor: only embed IntegratableModule in PeerstoreProvider --- p2p/providers/peerstore_provider/peerstore_provider.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p2p/providers/peerstore_provider/peerstore_provider.go b/p2p/providers/peerstore_provider/peerstore_provider.go index 95725865d..8abd063b7 100644 --- a/p2p/providers/peerstore_provider/peerstore_provider.go +++ b/p2p/providers/peerstore_provider/peerstore_provider.go @@ -16,7 +16,7 @@ const ModuleName = "peerstore_provider" // PeerstoreProvider is an interface that provides Peerstore accessors type PeerstoreProvider interface { - modules.Module + modules.IntegratableModule GetStakedPeerstoreAtHeight(height uint64) (typesP2P.Peerstore, error) GetP2PConfig() *configs.P2PConfig From 00730d49c327690d842ebc0eda8fafa7fc7531ad Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 5 Jun 2023 09:54:40 +0200 Subject: [PATCH 04/41] refactor: remove unused `PeerstoreProvider#GetP2PConfig()` method --- p2p/providers/peerstore_provider/peerstore_provider.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/p2p/providers/peerstore_provider/peerstore_provider.go b/p2p/providers/peerstore_provider/peerstore_provider.go index 8abd063b7..edc5067bd 100644 --- a/p2p/providers/peerstore_provider/peerstore_provider.go +++ b/p2p/providers/peerstore_provider/peerstore_provider.go @@ -5,7 +5,6 @@ package peerstore_provider import ( "github.com/pokt-network/pocket/logger" typesP2P "github.com/pokt-network/pocket/p2p/types" - "github.com/pokt-network/pocket/runtime/configs" coreTypes "github.com/pokt-network/pocket/shared/core/types" cryptoPocket "github.com/pokt-network/pocket/shared/crypto" "github.com/pokt-network/pocket/shared/modules" @@ -19,7 +18,6 @@ type PeerstoreProvider interface { modules.IntegratableModule GetStakedPeerstoreAtHeight(height uint64) (typesP2P.Peerstore, error) - GetP2PConfig() *configs.P2PConfig } func ActorsToPeerstore(abp PeerstoreProvider, actors []*coreTypes.Actor) (pstore typesP2P.Peerstore, errs error) { From 41d18ae3181595178fb0d50b586c69844fd1fb38 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 5 Jun 2023 09:55:22 +0200 Subject: [PATCH 05/41] feat: add `PeerstoreProvider#GetUnstakedPeerstore()` interface method --- p2p/providers/peerstore_provider/peerstore_provider.go | 1 + 1 file changed, 1 insertion(+) diff --git a/p2p/providers/peerstore_provider/peerstore_provider.go b/p2p/providers/peerstore_provider/peerstore_provider.go index edc5067bd..d368f65a8 100644 --- a/p2p/providers/peerstore_provider/peerstore_provider.go +++ b/p2p/providers/peerstore_provider/peerstore_provider.go @@ -18,6 +18,7 @@ type PeerstoreProvider interface { modules.IntegratableModule GetStakedPeerstoreAtHeight(height uint64) (typesP2P.Peerstore, error) + GetUnstakedPeerstore() (typesP2P.Peerstore, error) } func ActorsToPeerstore(abp PeerstoreProvider, actors []*coreTypes.Actor) (pstore typesP2P.Peerstore, errs error) { From 507d8af4036b000f4da76d343ec3bc54cc746074 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 5 Jun 2023 09:55:54 +0200 Subject: [PATCH 06/41] chore: implement `rpcPeerstoreProvider#GetUnstakedPeerstore()` --- p2p/providers/peerstore_provider/rpc/provider.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/p2p/providers/peerstore_provider/rpc/provider.go b/p2p/providers/peerstore_provider/rpc/provider.go index bd6a70d58..18dcabcf2 100644 --- a/p2p/providers/peerstore_provider/rpc/provider.go +++ b/p2p/providers/peerstore_provider/rpc/provider.go @@ -101,6 +101,10 @@ func (rabp *rpcPeerstoreProvider) GetP2PConfig() *configs.P2PConfig { return rabp.p2pCfg } +func (rabp *rpcPeerstoreProvider) GetUnstakedPeerstore() (typesP2P.Peerstore, error) { + return nil, fmt.Errorf("unstaked peerstore not supported by rpc peerstore provider") +} + func (rabp *rpcPeerstoreProvider) initRPCClient() { rpcClient, err := rpc.NewClientWithResponses(rabp.rpcURL) if err != nil { From e74fea407278f157adca4b6e8e738783748064a6 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 5 Jun 2023 12:42:32 +0200 Subject: [PATCH 07/41] chore: add TECHDEBT comment --- shared/modules/p2p_module.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shared/modules/p2p_module.go b/shared/modules/p2p_module.go index ac71af2eb..d34a594d3 100644 --- a/shared/modules/p2p_module.go +++ b/shared/modules/p2p_module.go @@ -14,6 +14,8 @@ type P2PModule interface { // Returns the public P2P address of this node GetAddress() (cryptoPocket.Address, error) + // TECHDEBT(#xxx): uncomment after moving `typesP2P.Peerstore` interface to a shared package + // GetUnstakedPeerstore() (typesP2P.Peerstore, error) // A network broadcast to all staked actors on the network using RainTree Broadcast(msg *anypb.Any) error From 6128d8495381a191b00bfd7563c2cd5fc8202495 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 5 Jun 2023 12:51:09 +0200 Subject: [PATCH 08/41] chore: add `Factory` generic type --- shared/modules/factory.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/shared/modules/factory.go b/shared/modules/factory.go index c4c2a5f19..58b4ef16e 100644 --- a/shared/modules/factory.go +++ b/shared/modules/factory.go @@ -4,8 +4,14 @@ package modules // a variadic `ModuleOption` argument(s) and returns a `Module`and an error. type ModuleFactoryWithOptions FactoryWithOptions[Module, ModuleOption] -// FactoryWithConfig implements a `#Create()` factory method which takes a -// required "config" argument of type K and returns a value of type T and an error. +// Factory implements a `#Create()` factory method which takes a bus and returns +// a value of type T and an error. +type Factory[T interface{}] interface { + Create(bus Bus) (T, error) +} + +// FactoryWithConfig implements a `#Create()` factory method which takes a bus and +// a required "config" argument of type K and returns a value of type T and an error. // TECHDEBT: apply enforcement across applicable "sub-modules" (see: `p2p/raintree/router.go`: `raintTreeFactory`) type FactoryWithConfig[T interface{}, K interface{}] interface { Create(bus Bus, cfg K) (T, error) From 4bc605a3a151efe415de1f8f930c35f519127ef1 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 5 Jun 2023 12:51:24 +0200 Subject: [PATCH 09/41] chore: update comments --- shared/modules/factory.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shared/modules/factory.go b/shared/modules/factory.go index 58b4ef16e..5cda020d8 100644 --- a/shared/modules/factory.go +++ b/shared/modules/factory.go @@ -17,16 +17,16 @@ type FactoryWithConfig[T interface{}, K interface{}] interface { Create(bus Bus, cfg K) (T, error) } -// FactoryWithOptions implements a `#Create()` factory method which takes a -// variadic "optional" argument(s) of type O and returns a value of type T +// FactoryWithOptions implements a `#Create()` factory method which takes a bus +// and a variadic "optional" argument(s) of type O and returns a value of type T // and an error. // TECHDEBT: apply enforcement across applicable "sub-modules" type FactoryWithOptions[T interface{}, O interface{}] interface { Create(bus Bus, opts ...O) (T, error) } -// FactoryWithConfigAndOptions implements a `#Create()` factory method which -// takes both a required "config" argument of type K and a variadic "optional" +// FactoryWithConfigAndOptions implements a `#Create()` factory method which takes +// a bus and both a required "config" argument of type K and a variadic "optional" // argument(s) of type O and returns a value of type T and an error. // TECHDEBT: apply enforcement across applicable "sub-modules" type FactoryWithConfigAndOptions[T interface{}, K interface{}, O interface{}] interface { From 094a95e15311c61707e1e16a9311ac44deae6faa Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 5 Jun 2023 13:24:18 +0200 Subject: [PATCH 10/41] chore: update changelogs --- p2p/CHANGELOG.md | 7 +++++++ shared/CHANGELOG.md | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/p2p/CHANGELOG.md b/p2p/CHANGELOG.md index 982b1040c..3a2e8b74f 100644 --- a/p2p/CHANGELOG.md +++ b/p2p/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.0.0.54] - 2023-06-05 + +- 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 + ## [0.0.0.53] - 2023-06-01 - Moved nonce field from RainTreeMessage to PocketEnvelope protobuf types diff --git a/shared/CHANGELOG.md b/shared/CHANGELOG.md index e548dfb3b..cd51917e2 100644 --- a/shared/CHANGELOG.md +++ b/shared/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.0.0.60] - 2023-06-05 + +- Added `Factory` generic type +- Improved godoc comments + ## [0.0.0.59] - 2023-06-01 - Use ApplicationAddress in RelayMeta From 2a5b300371ecd396a18e16ea07ef254a10c90bac Mon Sep 17 00:00:00 2001 From: Bryan White Date: Tue, 6 Jun 2023 08:52:42 +0200 Subject: [PATCH 11/41] chore: update changelogs --- p2p/CHANGELOG.md | 2 +- shared/CHANGELOG.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/p2p/CHANGELOG.md b/p2p/CHANGELOG.md index 3a2e8b74f..088ea9a3c 100644 --- a/p2p/CHANGELOG.md +++ b/p2p/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.54] - 2023-06-05 +## [0.0.0.54] - 2023-06-06 - Replaced embedded modules.Module with simpler modules.IntegratableModule in PeerstoreProvider interface - Removed unused PeerstoreProvider#GetP2PConfig() method diff --git a/shared/CHANGELOG.md b/shared/CHANGELOG.md index cd51917e2..2a44eef61 100644 --- a/shared/CHANGELOG.md +++ b/shared/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.60] - 2023-06-05 +## [0.0.0.60] - 2023-06-06 - Added `Factory` generic type - Improved godoc comments From 1d03f381932943a17ad7278ea9eb0a72275dcbdf Mon Sep 17 00:00:00 2001 From: Bryan White Date: Tue, 6 Jun 2023 08:53:29 +0200 Subject: [PATCH 12/41] empty commit From c1318dacbaf82d7e99c3d1e06c612e174d9dc987 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Tue, 6 Jun 2023 09:31:53 +0200 Subject: [PATCH 13/41] chore: replace empty interfaces with `any` --- shared/modules/factory.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shared/modules/factory.go b/shared/modules/factory.go index 5cda020d8..64286f435 100644 --- a/shared/modules/factory.go +++ b/shared/modules/factory.go @@ -6,14 +6,14 @@ type ModuleFactoryWithOptions FactoryWithOptions[Module, ModuleOption] // Factory implements a `#Create()` factory method which takes a bus and returns // a value of type T and an error. -type Factory[T interface{}] interface { +type Factory[T any] interface { Create(bus Bus) (T, error) } // FactoryWithConfig implements a `#Create()` factory method which takes a bus and // a required "config" argument of type K and returns a value of type T and an error. // TECHDEBT: apply enforcement across applicable "sub-modules" (see: `p2p/raintree/router.go`: `raintTreeFactory`) -type FactoryWithConfig[T interface{}, K interface{}] interface { +type FactoryWithConfig[T any, K any] interface { Create(bus Bus, cfg K) (T, error) } @@ -21,7 +21,7 @@ type FactoryWithConfig[T interface{}, K interface{}] interface { // and a variadic "optional" argument(s) of type O and returns a value of type T // and an error. // TECHDEBT: apply enforcement across applicable "sub-modules" -type FactoryWithOptions[T interface{}, O interface{}] interface { +type FactoryWithOptions[T any, O any] interface { Create(bus Bus, opts ...O) (T, error) } @@ -29,6 +29,6 @@ type FactoryWithOptions[T interface{}, O interface{}] interface { // a bus and both a required "config" argument of type K and a variadic "optional" // argument(s) of type O and returns a value of type T and an error. // TECHDEBT: apply enforcement across applicable "sub-modules" -type FactoryWithConfigAndOptions[T interface{}, K interface{}, O interface{}] interface { +type FactoryWithConfigAndOptions[T any, K any, O any] interface { Create(bus Bus, cfg K, opts ...O) (T, error) } From 8d1f62a44eb25be452aea76ea5ca5bfcbff5a21c Mon Sep 17 00:00:00 2001 From: Bryan White Date: Tue, 6 Jun 2023 09:33:01 +0200 Subject: [PATCH 14/41] chore: edit comment --- shared/modules/factory.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/modules/factory.go b/shared/modules/factory.go index 64286f435..d2812555b 100644 --- a/shared/modules/factory.go +++ b/shared/modules/factory.go @@ -26,7 +26,7 @@ type FactoryWithOptions[T any, O any] interface { } // FactoryWithConfigAndOptions implements a `#Create()` factory method which takes -// a bus and both a required "config" argument of type K and a variadic "optional" +// a bus, a required "config" argument of type K, and a variadic (optional) // argument(s) of type O and returns a value of type T and an error. // TECHDEBT: apply enforcement across applicable "sub-modules" type FactoryWithConfigAndOptions[T any, K any, O any] interface { From 08bcafd27bc05fbc674801bd6e2e9bb4c33a4cc2 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 7 Jun 2023 09:16:19 +0200 Subject: [PATCH 15/41] chore: remove unused `GetP2PConfig()` method --- p2p/providers/peerstore_provider/persistence/persistence.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/p2p/providers/peerstore_provider/persistence/persistence.go b/p2p/providers/peerstore_provider/persistence/persistence.go index a5e23e74b..55c810159 100644 --- a/p2p/providers/peerstore_provider/persistence/persistence.go +++ b/p2p/providers/peerstore_provider/persistence/persistence.go @@ -5,7 +5,6 @@ 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" ) @@ -58,10 +57,6 @@ func (pabp *persistencePeerstoreProvider) GetStakedPeerstoreAtHeight(height uint return peerstore_provider.ActorsToPeerstore(pabp, validators) } -func (pabp *persistencePeerstoreProvider) GetP2PConfig() *configs.P2PConfig { - return pabp.GetBus().GetRuntimeMgr().GetConfig().P2P -} - func (pabp *persistencePeerstoreProvider) GetUnstakedPeerstore() (typesP2P.Peerstore, error) { return nil, fmt.Errorf("persistence peerstore provider does not support unstaked peerstore") } From 5a54400bf040f1b8a68c3cf0c65cc56d84b900a1 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 7 Jun 2023 09:18:06 +0200 Subject: [PATCH 16/41] chore: add godoc comments --- p2p/providers/peerstore_provider/peerstore_provider.go | 5 +++++ p2p/providers/peerstore_provider/persistence/persistence.go | 2 ++ 2 files changed, 7 insertions(+) diff --git a/p2p/providers/peerstore_provider/peerstore_provider.go b/p2p/providers/peerstore_provider/peerstore_provider.go index d368f65a8..e947c6712 100644 --- a/p2p/providers/peerstore_provider/peerstore_provider.go +++ b/p2p/providers/peerstore_provider/peerstore_provider.go @@ -17,7 +17,12 @@ const ModuleName = "peerstore_provider" type PeerstoreProvider interface { modules.IntegratableModule + // GetStakedPeerstoreAtHeight returns a peerstore containing all staked peers + // at a given height. These peers communicate via the p2p module's staked actor + // router. GetStakedPeerstoreAtHeight(height uint64) (typesP2P.Peerstore, error) + // GetUnstakedPeerstore returns a peerstore containing all peers which + // communicate via the p2p module's unstaked actor router. GetUnstakedPeerstore() (typesP2P.Peerstore, error) } diff --git a/p2p/providers/peerstore_provider/persistence/persistence.go b/p2p/providers/peerstore_provider/persistence/persistence.go index 55c810159..a62350ffb 100644 --- a/p2p/providers/peerstore_provider/persistence/persistence.go +++ b/p2p/providers/peerstore_provider/persistence/persistence.go @@ -43,6 +43,7 @@ func (*persistencePeerstoreProvider) GetModuleName() string { return peerstore_provider.ModuleName } +// GetStakedPeerstoreAtHeight implements the respective `PeerstoreProvider` interface method. func (pabp *persistencePeerstoreProvider) GetStakedPeerstoreAtHeight(height uint64) (typesP2P.Peerstore, error) { readCtx, err := pabp.GetBus().GetPersistenceModule().NewReadContext(int64(height)) if err != nil { @@ -57,6 +58,7 @@ func (pabp *persistencePeerstoreProvider) GetStakedPeerstoreAtHeight(height uint return peerstore_provider.ActorsToPeerstore(pabp, validators) } +// GetStakedPeerstoreAtHeight implements the respective `PeerstoreProvider` interface method. func (pabp *persistencePeerstoreProvider) GetUnstakedPeerstore() (typesP2P.Peerstore, error) { return nil, fmt.Errorf("persistence peerstore provider does not support unstaked peerstore") } From 5000ad8e2ed86c7e7f5d3e77eea371c480e0b4b8 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 7 Jun 2023 09:19:33 +0200 Subject: [PATCH 17/41] fix: retrieve p2p mdoule from bus on each call --- .../peerstore_provider/persistence/p2p.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/p2p/providers/peerstore_provider/persistence/p2p.go b/p2p/providers/peerstore_provider/persistence/p2p.go index 18d645c21..a9c942c94 100644 --- a/p2p/providers/peerstore_provider/persistence/p2p.go +++ b/p2p/providers/peerstore_provider/persistence/p2p.go @@ -29,8 +29,6 @@ type p2pPStoreProviderFactory = modules.Factory[peerstore_provider.PeerstoreProv type p2pPeerstoreProvider struct { base_modules.IntegratableModule persistencePeerstoreProvider - - p2pModule modules.P2PModule } func NewP2PPeerstoreProvider( @@ -46,14 +44,8 @@ func (*p2pPeerstoreProvider) Create( return nil, fmt.Errorf("bus is required") } - p2pModule := bus.GetP2PModule() - if p2pModule == nil { - return nil, fmt.Errorf("p2p module is not registered to bus and is required") - } - p2pPSP := &p2pPeerstoreProvider{ IntegratableModule: *base_modules.NewIntegratableModule(bus), - p2pModule: p2pModule, } return p2pPSP, nil @@ -64,7 +56,12 @@ func (*p2pPeerstoreProvider) GetModuleName() string { } func (p2pPSP *p2pPeerstoreProvider) GetUnstakedPeerstore() (typesP2P.Peerstore, error) { - unstakedPSP, ok := p2pPSP.p2pModule.(unstakedPeerstoreProvider) + p2pModule := p2pPSP.GetBus().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") } From c587afa5ecf53977d17dd1867dd0e1e3cbac54b2 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 7 Jun 2023 09:23:58 +0200 Subject: [PATCH 18/41] refactor: persistence peerstor provider --- p2p/module.go | 18 +++++++++------ .../persistence/persistence.go | 23 ++++++++----------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/p2p/module.go b/p2p/module.go index 44095b53b..53d50ece9 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -3,15 +3,19 @@ package p2p import ( "errors" "fmt" + "github.com/libp2p/go-libp2p" libp2pHost "github.com/libp2p/go-libp2p/core/host" "github.com/multiformats/go-multiaddr" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/anypb" + "github.com/pokt-network/pocket/logger" "github.com/pokt-network/pocket/p2p/config" "github.com/pokt-network/pocket/p2p/providers" "github.com/pokt-network/pocket/p2p/providers/current_height_provider" "github.com/pokt-network/pocket/p2p/providers/peerstore_provider" - persABP "github.com/pokt-network/pocket/p2p/providers/peerstore_provider/persistence" + persPSP "github.com/pokt-network/pocket/p2p/providers/peerstore_provider/persistence" "github.com/pokt-network/pocket/p2p/raintree" typesP2P "github.com/pokt-network/pocket/p2p/types" "github.com/pokt-network/pocket/p2p/utils" @@ -24,8 +28,6 @@ import ( "github.com/pokt-network/pocket/shared/modules" "github.com/pokt-network/pocket/shared/modules/base_modules" "github.com/pokt-network/pocket/telemetry" - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/types/known/anypb" ) var _ modules.P2PModule = &p2pModule{} @@ -229,16 +231,18 @@ func (m *p2pModule) setupDependencies() error { // setupPeerstoreProvider attempts to retrieve the peerstore provider from the // bus, if one is registered, otherwise returns a new `persistencePeerstoreProvider`. -func (m *p2pModule) setupPeerstoreProvider() error { +func (m *p2pModule) setupPeerstoreProvider() (err error) { m.logger.Debug().Msg("setupPeerstoreProvider") + + // TECHDEBT(#810): simplify once submodules are more convenient to retrieve. pstoreProviderModule, err := m.GetBus().GetModulesRegistry().GetModule(peerstore_provider.ModuleName) if err != nil { m.logger.Debug().Msg("creating new persistence peerstore...") - pstoreProviderModule = persABP.NewPersistencePeerstoreProvider(m.GetBus()) - } else if pstoreProviderModule != nil { - m.logger.Debug().Msg("loaded persistence peerstore...") + m.pstoreProvider, err = persPSP.NewPersistencePeerstoreProvider(m.GetBus()) + return nil } + m.logger.Debug().Msg("loaded persistence peerstore...") pstoreProvider, ok := pstoreProviderModule.(providers.PeerstoreProvider) if !ok { return fmt.Errorf("unknown peerstore provider type: %T", pstoreProviderModule) diff --git a/p2p/providers/peerstore_provider/persistence/persistence.go b/p2p/providers/peerstore_provider/persistence/persistence.go index a62350ffb..0b6082c09 100644 --- a/p2p/providers/peerstore_provider/persistence/persistence.go +++ b/p2p/providers/peerstore_provider/persistence/persistence.go @@ -11,13 +11,18 @@ import ( var _ peerstore_provider.PeerstoreProvider = &persistencePeerstoreProvider{} +type persistencePStoreProviderOption func(*persistencePeerstoreProvider) +type persistencePStoreProviderFactory = modules.FactoryWithOptions[peerstore_provider.PeerstoreProvider, persistencePStoreProviderOption] type persistencePeerstoreProvider struct { base_modules.IntegratableModule - base_modules.InterruptableModule + persistencePStoreProviderFactory } -// TECHDEBT: refactor -func NewPersistencePeerstoreProvider(bus modules.Bus, options ...func(*persistencePeerstoreProvider)) *persistencePeerstoreProvider { +func NewPersistencePeerstoreProvider(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), } @@ -26,17 +31,7 @@ func NewPersistencePeerstoreProvider(bus modules.Bus, options ...func(*persisten o(pabp) } - return pabp -} - -// TECHDEBT: remove -func Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) { - return new(persistencePeerstoreProvider).Create(bus, options...) -} - -// TECHDEBT: refactor -func (*persistencePeerstoreProvider) Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) { - return NewPersistencePeerstoreProvider(bus), nil + return pabp, nil } func (*persistencePeerstoreProvider) GetModuleName() string { From e70b99c97ba7861400dea5da601a41891786b5cb Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 7 Jun 2023 09:24:43 +0200 Subject: [PATCH 19/41] refactor: embed `p2pPStoreProviderFactory` --- p2p/providers/peerstore_provider/persistence/p2p.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/p2p/providers/peerstore_provider/persistence/p2p.go b/p2p/providers/peerstore_provider/persistence/p2p.go index a9c942c94..8f53ecff2 100644 --- a/p2p/providers/peerstore_provider/persistence/p2p.go +++ b/p2p/providers/peerstore_provider/persistence/p2p.go @@ -9,10 +9,7 @@ import ( "github.com/pokt-network/pocket/shared/modules/base_modules" ) -var ( - _ peerstore_provider.PeerstoreProvider = &p2pPeerstoreProvider{} - _ p2pPStoreProviderFactory = &p2pPeerstoreProvider{} -) +var _ peerstore_provider.PeerstoreProvider = &p2pPeerstoreProvider{} // unstakedPeerstoreProvider is an interface which the p2p module supports in // order to allow access to the unstaked-actor-router's peerstore @@ -28,6 +25,7 @@ type p2pPStoreProviderFactory = modules.Factory[peerstore_provider.PeerstoreProv type p2pPeerstoreProvider struct { base_modules.IntegratableModule + p2pPStoreProviderFactory persistencePeerstoreProvider } From b3ce2710c1e834b266cd02ca0c643eae52cfd01a Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 7 Jun 2023 09:25:00 +0200 Subject: [PATCH 20/41] chore: oneline function signature --- p2p/providers/peerstore_provider/persistence/p2p.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/p2p/providers/peerstore_provider/persistence/p2p.go b/p2p/providers/peerstore_provider/persistence/p2p.go index 8f53ecff2..ddf577c67 100644 --- a/p2p/providers/peerstore_provider/persistence/p2p.go +++ b/p2p/providers/peerstore_provider/persistence/p2p.go @@ -29,9 +29,7 @@ type p2pPeerstoreProvider struct { persistencePeerstoreProvider } -func NewP2PPeerstoreProvider( - bus modules.Bus, -) (peerstore_provider.PeerstoreProvider, error) { +func NewP2PPeerstoreProvider(bus modules.Bus) (peerstore_provider.PeerstoreProvider, error) { return new(p2pPeerstoreProvider).Create(bus) } From 8a476a46aa7e0a352257d8109d46f428c9eb7f2d Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 7 Jun 2023 09:31:38 +0200 Subject: [PATCH 21/41] refactor: consolidate p2pPeerstoreProvider into persistencePeerstorProvider --- .../peerstore_provider/persistence/p2p.go | 65 ------------------- .../persistence/persistence.go | 22 ++++++- 2 files changed, 21 insertions(+), 66 deletions(-) delete mode 100644 p2p/providers/peerstore_provider/persistence/p2p.go diff --git a/p2p/providers/peerstore_provider/persistence/p2p.go b/p2p/providers/peerstore_provider/persistence/p2p.go deleted file mode 100644 index ddf577c67..000000000 --- a/p2p/providers/peerstore_provider/persistence/p2p.go +++ /dev/null @@ -1,65 +0,0 @@ -package persistence - -import ( - "fmt" - - "github.com/pokt-network/pocket/p2p/providers/peerstore_provider" - typesP2P "github.com/pokt-network/pocket/p2p/types" - "github.com/pokt-network/pocket/shared/modules" - "github.com/pokt-network/pocket/shared/modules/base_modules" -) - -var _ peerstore_provider.PeerstoreProvider = &p2pPeerstoreProvider{} - -// unstakedPeerstoreProvider is an interface which the p2p module supports in -// order to allow access to the unstaked-actor-router's peerstore -// -// TECHDEBT(#xxx): 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) -} - -type p2pPStoreProviderFactory = modules.Factory[peerstore_provider.PeerstoreProvider] - -type p2pPeerstoreProvider struct { - base_modules.IntegratableModule - p2pPStoreProviderFactory - persistencePeerstoreProvider -} - -func NewP2PPeerstoreProvider(bus modules.Bus) (peerstore_provider.PeerstoreProvider, error) { - return new(p2pPeerstoreProvider).Create(bus) -} - -func (*p2pPeerstoreProvider) Create( - bus modules.Bus, -) (peerstore_provider.PeerstoreProvider, error) { - if bus == nil { - return nil, fmt.Errorf("bus is required") - } - - p2pPSP := &p2pPeerstoreProvider{ - IntegratableModule: *base_modules.NewIntegratableModule(bus), - } - - return p2pPSP, nil -} - -func (*p2pPeerstoreProvider) GetModuleName() string { - return peerstore_provider.ModuleName -} - -func (p2pPSP *p2pPeerstoreProvider) GetUnstakedPeerstore() (typesP2P.Peerstore, error) { - p2pModule := p2pPSP.GetBus().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() -} diff --git a/p2p/providers/peerstore_provider/persistence/persistence.go b/p2p/providers/peerstore_provider/persistence/persistence.go index 0b6082c09..5c990b5a7 100644 --- a/p2p/providers/peerstore_provider/persistence/persistence.go +++ b/p2p/providers/peerstore_provider/persistence/persistence.go @@ -13,11 +13,22 @@ var _ peerstore_provider.PeerstoreProvider = &persistencePeerstoreProvider{} type persistencePStoreProviderOption func(*persistencePeerstoreProvider) type persistencePStoreProviderFactory = modules.FactoryWithOptions[peerstore_provider.PeerstoreProvider, persistencePStoreProviderOption] + type persistencePeerstoreProvider struct { base_modules.IntegratableModule persistencePStoreProviderFactory } +// unstakedPeerstoreProvider is an interface which the p2p module supports in +// order to allow access to the unstaked-actor-router's peerstore +// +// TECHDEBT(#xxx): 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 NewPersistencePeerstoreProvider(bus modules.Bus, options ...persistencePStoreProviderOption) (peerstore_provider.PeerstoreProvider, error) { return new(persistencePeerstoreProvider).Create(bus, options...) } @@ -55,5 +66,14 @@ func (pabp *persistencePeerstoreProvider) GetStakedPeerstoreAtHeight(height uint // GetStakedPeerstoreAtHeight implements the respective `PeerstoreProvider` interface method. func (pabp *persistencePeerstoreProvider) GetUnstakedPeerstore() (typesP2P.Peerstore, error) { - return nil, fmt.Errorf("persistence peerstore provider does not support unstaked peerstore") + p2pModule := pabp.GetBus().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() } From 650d432a807b4d9576dc77471035c5766ffcf0fb Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 7 Jun 2023 09:32:21 +0200 Subject: [PATCH 22/41] refactor: rename persistence.go back to provider.go --- .../persistence/{persistence.go => provider.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename p2p/providers/peerstore_provider/persistence/{persistence.go => provider.go} (100%) diff --git a/p2p/providers/peerstore_provider/persistence/persistence.go b/p2p/providers/peerstore_provider/persistence/provider.go similarity index 100% rename from p2p/providers/peerstore_provider/persistence/persistence.go rename to p2p/providers/peerstore_provider/persistence/provider.go From 59fffb5d59b03bac066abb176746a68e18956eec Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 7 Jun 2023 09:33:07 +0200 Subject: [PATCH 23/41] refactor: `p2pPeerstoreProvider` to a single function' --- .../persistence/provider.go | 22 +------------ p2p/providers/peerstore_provider/unstaked.go | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 p2p/providers/peerstore_provider/unstaked.go diff --git a/p2p/providers/peerstore_provider/persistence/provider.go b/p2p/providers/peerstore_provider/persistence/provider.go index 5c990b5a7..0b6082c09 100644 --- a/p2p/providers/peerstore_provider/persistence/provider.go +++ b/p2p/providers/peerstore_provider/persistence/provider.go @@ -13,22 +13,11 @@ var _ peerstore_provider.PeerstoreProvider = &persistencePeerstoreProvider{} type persistencePStoreProviderOption func(*persistencePeerstoreProvider) type persistencePStoreProviderFactory = modules.FactoryWithOptions[peerstore_provider.PeerstoreProvider, persistencePStoreProviderOption] - type persistencePeerstoreProvider struct { base_modules.IntegratableModule persistencePStoreProviderFactory } -// unstakedPeerstoreProvider is an interface which the p2p module supports in -// order to allow access to the unstaked-actor-router's peerstore -// -// TECHDEBT(#xxx): 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 NewPersistencePeerstoreProvider(bus modules.Bus, options ...persistencePStoreProviderOption) (peerstore_provider.PeerstoreProvider, error) { return new(persistencePeerstoreProvider).Create(bus, options...) } @@ -66,14 +55,5 @@ func (pabp *persistencePeerstoreProvider) GetStakedPeerstoreAtHeight(height uint // GetStakedPeerstoreAtHeight implements the respective `PeerstoreProvider` interface method. func (pabp *persistencePeerstoreProvider) GetUnstakedPeerstore() (typesP2P.Peerstore, error) { - p2pModule := pabp.GetBus().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() + return nil, fmt.Errorf("persistence peerstore provider does not support unstaked peerstore") } diff --git a/p2p/providers/peerstore_provider/unstaked.go b/p2p/providers/peerstore_provider/unstaked.go new file mode 100644 index 000000000..740263b71 --- /dev/null +++ b/p2p/providers/peerstore_provider/unstaked.go @@ -0,0 +1,31 @@ +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 +// +// TECHDEBT(#xxx): 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() +} From a1e22c4440764c6ea29bb6544c1a3dabaf418436 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 7 Jun 2023 09:42:33 +0200 Subject: [PATCH 24/41] refactor: update peerstore provider method receivers --- .../peerstore_provider/persistence/provider.go | 6 +++--- p2p/providers/peerstore_provider/rpc/provider.go | 16 ++++++---------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/p2p/providers/peerstore_provider/persistence/provider.go b/p2p/providers/peerstore_provider/persistence/provider.go index 0b6082c09..e5c09e0e0 100644 --- a/p2p/providers/peerstore_provider/persistence/provider.go +++ b/p2p/providers/peerstore_provider/persistence/provider.go @@ -39,8 +39,8 @@ func (*persistencePeerstoreProvider) GetModuleName() string { } // GetStakedPeerstoreAtHeight implements the respective `PeerstoreProvider` interface method. -func (pabp *persistencePeerstoreProvider) GetStakedPeerstoreAtHeight(height uint64) (typesP2P.Peerstore, error) { - readCtx, err := pabp.GetBus().GetPersistenceModule().NewReadContext(int64(height)) +func (persistencePSP *persistencePeerstoreProvider) GetStakedPeerstoreAtHeight(height uint64) (typesP2P.Peerstore, error) { + readCtx, err := persistencePSP.GetBus().GetPersistenceModule().NewReadContext(int64(height)) if err != nil { return nil, err } @@ -50,7 +50,7 @@ func (pabp *persistencePeerstoreProvider) GetStakedPeerstoreAtHeight(height uint if err != nil { return nil, err } - return peerstore_provider.ActorsToPeerstore(pabp, validators) + return peerstore_provider.ActorsToPeerstore(persistencePSP, validators) } // GetStakedPeerstoreAtHeight implements the respective `PeerstoreProvider` interface method. diff --git a/p2p/providers/peerstore_provider/rpc/provider.go b/p2p/providers/peerstore_provider/rpc/provider.go index 18dcabcf2..cc5419652 100644 --- a/p2p/providers/peerstore_provider/rpc/provider.go +++ b/p2p/providers/peerstore_provider/rpc/provider.go @@ -63,7 +63,7 @@ func (*rpcPeerstoreProvider) GetModuleName() string { return peerstore_provider.ModuleName } -func (rabp *rpcPeerstoreProvider) GetStakedPeerstoreAtHeight(height uint64) (typesP2P.Peerstore, error) { +func (rpcPSP *rpcPeerstoreProvider) GetStakedPeerstoreAtHeight(height uint64) (typesP2P.Peerstore, error) { ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second) defer cancel() @@ -71,7 +71,7 @@ func (rabp *rpcPeerstoreProvider) GetStakedPeerstoreAtHeight(height uint64) (typ h int64 = int64(height) actorType rpc.ActorTypesEnum = "validator" ) - response, err := rabp.rpcClient.GetV1P2pStakedActorsAddressBookWithResponse(ctx, &rpc.GetV1P2pStakedActorsAddressBookParams{Height: &h, ActorType: &actorType}) + response, err := rpcPSP.rpcClient.GetV1P2pStakedActorsAddressBookWithResponse(ctx, &rpc.GetV1P2pStakedActorsAddressBookParams{Height: &h, ActorType: &actorType}) if err != nil { return nil, err } @@ -91,7 +91,7 @@ func (rabp *rpcPeerstoreProvider) GetStakedPeerstoreAtHeight(height uint64) (typ }) } - return peerstore_provider.ActorsToPeerstore(rabp, coreActors) + return peerstore_provider.ActorsToPeerstore(rpcPSP, coreActors) } func (rabp *rpcPeerstoreProvider) GetP2PConfig() *configs.P2PConfig { @@ -101,16 +101,12 @@ func (rabp *rpcPeerstoreProvider) GetP2PConfig() *configs.P2PConfig { return rabp.p2pCfg } -func (rabp *rpcPeerstoreProvider) GetUnstakedPeerstore() (typesP2P.Peerstore, error) { - return nil, fmt.Errorf("unstaked peerstore not supported by rpc peerstore provider") -} - -func (rabp *rpcPeerstoreProvider) initRPCClient() { - rpcClient, err := rpc.NewClientWithResponses(rabp.rpcURL) +func (rpcPSP *rpcPeerstoreProvider) initRPCClient() { + rpcClient, err := rpc.NewClientWithResponses(rpcPSP.rpcURL) if err != nil { log.Fatalf("could not create RPC client: %v", err) } - rabp.rpcClient = rpcClient + rpcPSP.rpcClient = rpcClient } // options From ccd9fb7364801767b3dc3b7eeca3b298343804b7 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 7 Jun 2023 09:43:11 +0200 Subject: [PATCH 25/41] refactor: re-implement `GetUnstakedPeerstore` --- p2p/providers/peerstore_provider/persistence/provider.go | 6 ++---- p2p/providers/peerstore_provider/rpc/provider.go | 7 ++----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/p2p/providers/peerstore_provider/persistence/provider.go b/p2p/providers/peerstore_provider/persistence/provider.go index e5c09e0e0..9c45203bc 100644 --- a/p2p/providers/peerstore_provider/persistence/provider.go +++ b/p2p/providers/peerstore_provider/persistence/provider.go @@ -1,8 +1,6 @@ package persistence import ( - "fmt" - "github.com/pokt-network/pocket/p2p/providers/peerstore_provider" typesP2P "github.com/pokt-network/pocket/p2p/types" "github.com/pokt-network/pocket/shared/modules" @@ -54,6 +52,6 @@ func (persistencePSP *persistencePeerstoreProvider) GetStakedPeerstoreAtHeight(h } // GetStakedPeerstoreAtHeight implements the respective `PeerstoreProvider` interface method. -func (pabp *persistencePeerstoreProvider) GetUnstakedPeerstore() (typesP2P.Peerstore, error) { - return nil, fmt.Errorf("persistence peerstore provider does not support unstaked peerstore") +func (persistencePSP *persistencePeerstoreProvider) GetUnstakedPeerstore() (typesP2P.Peerstore, error) { + return peerstore_provider.GetUnstakedPeerstore(persistencePSP.GetBus()) } diff --git a/p2p/providers/peerstore_provider/rpc/provider.go b/p2p/providers/peerstore_provider/rpc/provider.go index cc5419652..c730dc210 100644 --- a/p2p/providers/peerstore_provider/rpc/provider.go +++ b/p2p/providers/peerstore_provider/rpc/provider.go @@ -94,11 +94,8 @@ func (rpcPSP *rpcPeerstoreProvider) GetStakedPeerstoreAtHeight(height uint64) (t return peerstore_provider.ActorsToPeerstore(rpcPSP, coreActors) } -func (rabp *rpcPeerstoreProvider) GetP2PConfig() *configs.P2PConfig { - if rabp.p2pCfg == nil { - return rabp.GetBus().GetRuntimeMgr().GetConfig().P2P - } - return rabp.p2pCfg +func (rpcPSP *rpcPeerstoreProvider) GetUnstakedPeerstore() (typesP2P.Peerstore, error) { + return peerstore_provider.GetUnstakedPeerstore(rpcPSP.GetBus()) } func (rpcPSP *rpcPeerstoreProvider) initRPCClient() { From 6e1a5b8f21c4bb3e77b920bb53d1a05fd41b7417 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Thu, 8 Jun 2023 15:12:37 +0200 Subject: [PATCH 26/41] chore: add TECHDEBT comments --- p2p/providers/peerstore_provider/rpc/provider.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/p2p/providers/peerstore_provider/rpc/provider.go b/p2p/providers/peerstore_provider/rpc/provider.go index c730dc210..c414431d5 100644 --- a/p2p/providers/peerstore_provider/rpc/provider.go +++ b/p2p/providers/peerstore_provider/rpc/provider.go @@ -29,6 +29,7 @@ func init() { } type rpcPeerstoreProvider struct { + // TECHDEBT(#810): simplify once submodules are more convenient to retrieve. base_modules.IntegratableModule base_modules.InterruptableModule @@ -37,6 +38,8 @@ type rpcPeerstoreProvider struct { rpcClient *rpc.ClientWithResponses } +// TECHDEBT(#810): refactor to be consistent with `persistencePeerstoreProvider` +// (i.e. `NewRPCPeerstoreProvider` calls `rpcPeerstoreProvider#Create()`. func NewRPCPeerstoreProvider(options ...modules.ModuleOption) *rpcPeerstoreProvider { rabp := &rpcPeerstoreProvider{ rpcURL: fmt.Sprintf("http://%s:%s", rpcHost, defaults.DefaultRPCPort), // TODO: Make port configurable @@ -51,10 +54,13 @@ func NewRPCPeerstoreProvider(options ...modules.ModuleOption) *rpcPeerstoreProvi return rabp } +// TECHDEBT(#810): remove as it should no longer be needed. func Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) { return new(rpcPeerstoreProvider).Create(bus, options...) } +// TECHDEBT(#810): refactor to be consistent with `persistencePeerstoreProvider` +// (i.e. `NewRPCPeerstoreProvider` calls `rpcPeerstoreProvider#Create()`. func (*rpcPeerstoreProvider) Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) { return NewRPCPeerstoreProvider(options...), nil } From 60302a4bb3d087156234e6b9666baa72b4a32794 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Thu, 8 Jun 2023 15:39:11 +0200 Subject: [PATCH 27/41] chore: add issue numbers to TECHDEBT comments --- p2p/providers/peerstore_provider/unstaked.go | 2 +- shared/modules/p2p_module.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/p2p/providers/peerstore_provider/unstaked.go b/p2p/providers/peerstore_provider/unstaked.go index 740263b71..c0c06f511 100644 --- a/p2p/providers/peerstore_provider/unstaked.go +++ b/p2p/providers/peerstore_provider/unstaked.go @@ -10,7 +10,7 @@ import ( // unstakedPeerstoreProvider is an interface which the p2p module supports in // order to allow access to the unstaked-actor-router's peerstore // -// TECHDEBT(#xxx): will become unnecessary after `modules.P2PModule#GetUnstakedPeerstore` is added.` +// 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 { diff --git a/shared/modules/p2p_module.go b/shared/modules/p2p_module.go index d34a594d3..e306d4fd2 100644 --- a/shared/modules/p2p_module.go +++ b/shared/modules/p2p_module.go @@ -14,7 +14,7 @@ type P2PModule interface { // Returns the public P2P address of this node GetAddress() (cryptoPocket.Address, error) - // TECHDEBT(#xxx): uncomment after moving `typesP2P.Peerstore` interface to a shared package + // TECHDEBT(#811): uncomment after moving `typesP2P.Peerstore` interface to a shared package // GetUnstakedPeerstore() (typesP2P.Peerstore, error) // A network broadcast to all staked actors on the network using RainTree From 1ac2e00ef9c77141c34d5583eddab791109cdfb8 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Thu, 8 Jun 2023 15:43:07 +0200 Subject: [PATCH 28/41] chore: improve comment --- p2p/providers/peerstore_provider/unstaked.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/p2p/providers/peerstore_provider/unstaked.go b/p2p/providers/peerstore_provider/unstaked.go index c0c06f511..b107922fe 100644 --- a/p2p/providers/peerstore_provider/unstaked.go +++ b/p2p/providers/peerstore_provider/unstaked.go @@ -8,7 +8,10 @@ import ( ) // unstakedPeerstoreProvider is an interface which the p2p module supports in -// order to allow access to the unstaked-actor-router's peerstore +// 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`. From 3a8e138997eebd70e470c1787690dcf823bdb33a Mon Sep 17 00:00:00 2001 From: Bryan White Date: Thu, 8 Jun 2023 15:46:05 +0200 Subject: [PATCH 29/41] refactor: rename `T` & `K` type params to `M` &`C` --- shared/modules/factory.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/shared/modules/factory.go b/shared/modules/factory.go index d2812555b..3b2300a4e 100644 --- a/shared/modules/factory.go +++ b/shared/modules/factory.go @@ -5,30 +5,30 @@ package modules type ModuleFactoryWithOptions FactoryWithOptions[Module, ModuleOption] // Factory implements a `#Create()` factory method which takes a bus and returns -// a value of type T and an error. -type Factory[T any] interface { - Create(bus Bus) (T, error) +// a value of type M and an error. +type Factory[M any] interface { + Create(bus Bus) (M, error) } // FactoryWithConfig implements a `#Create()` factory method which takes a bus and -// a required "config" argument of type K and returns a value of type T and an error. +// a required "config" argument of type C and returns a value of type M and an error. // TECHDEBT: apply enforcement across applicable "sub-modules" (see: `p2p/raintree/router.go`: `raintTreeFactory`) -type FactoryWithConfig[T any, K any] interface { - Create(bus Bus, cfg K) (T, error) +type FactoryWithConfig[T any, C any] interface { + Create(bus Bus, cfg C) (T, error) } // FactoryWithOptions implements a `#Create()` factory method which takes a bus -// and a variadic "optional" argument(s) of type O and returns a value of type T +// and a variadic "optional" argument(s) of type O and returns a value of type M // and an error. // TECHDEBT: apply enforcement across applicable "sub-modules" -type FactoryWithOptions[T any, O any] interface { - Create(bus Bus, opts ...O) (T, error) +type FactoryWithOptions[M any, O any] interface { + Create(bus Bus, opts ...O) (M, error) } // FactoryWithConfigAndOptions implements a `#Create()` factory method which takes -// a bus, a required "config" argument of type K, and a variadic (optional) -// argument(s) of type O and returns a value of type T and an error. +// a bus, a required "config" argument of type C, and a variadic (optional) +// argument(s) of type O and returns a value of type M and an error. // TECHDEBT: apply enforcement across applicable "sub-modules" -type FactoryWithConfigAndOptions[T any, K any, O any] interface { - Create(bus Bus, cfg K, opts ...O) (T, error) +type FactoryWithConfigAndOptions[M any, C any, O any] interface { + Create(bus Bus, cfg C, opts ...O) (M, error) } From 0cbca436734cae62af399900ff417e26abaf1013 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Thu, 8 Jun 2023 16:18:24 +0200 Subject: [PATCH 30/41] chore: update changelogs --- p2p/CHANGELOG.md | 10 +++++----- shared/CHANGELOG.md | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/p2p/CHANGELOG.md b/p2p/CHANGELOG.md index 088ea9a3c..9a9714d95 100644 --- a/p2p/CHANGELOG.md +++ b/p2p/CHANGELOG.md @@ -7,12 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.54] - 2023-06-06 +## [0.0.0.54] - 2023-06-08 -- 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 +- Replaced embedded `modules.Module` with simpler `modules.IntegratableModule` in `PeerstoreProvider` interface +- Removed unused `PeerstoreProvider#GetP2PConfig()` method +- Added `PeerstoreProvider#GetUnstakedPeerstore()` method +- Added temporary `unstakedPeerstoreProvider` interface ## [0.0.0.53] - 2023-06-01 diff --git a/shared/CHANGELOG.md b/shared/CHANGELOG.md index 2a44eef61..429633f2b 100644 --- a/shared/CHANGELOG.md +++ b/shared/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.60] - 2023-06-06 +## [0.0.0.60] - 2023-06-08 - Added `Factory` generic type - Improved godoc comments From 9cee9ddb0d89b0000c502547be000c57cc72e6c8 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Thu, 8 Jun 2023 17:32:01 +0200 Subject: [PATCH 31/41] fix: bugs --- p2p/module.go | 9 +++++++-- p2p/providers/peerstore_provider/persistence/provider.go | 6 ++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/p2p/module.go b/p2p/module.go index 53d50ece9..3edb1c697 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -231,14 +231,19 @@ func (m *p2pModule) setupDependencies() error { // setupPeerstoreProvider attempts to retrieve the peerstore provider from the // bus, if one is registered, otherwise returns a new `persistencePeerstoreProvider`. -func (m *p2pModule) setupPeerstoreProvider() (err error) { +func (m *p2pModule) setupPeerstoreProvider() error { m.logger.Debug().Msg("setupPeerstoreProvider") // TECHDEBT(#810): simplify once submodules are more convenient to retrieve. pstoreProviderModule, err := m.GetBus().GetModulesRegistry().GetModule(peerstore_provider.ModuleName) if err != nil { m.logger.Debug().Msg("creating new persistence peerstore...") - m.pstoreProvider, err = persPSP.NewPersistencePeerstoreProvider(m.GetBus()) + pstoreProvider, err := persPSP.NewPersistencePeerstoreProvider(m.GetBus()) + if err != nil { + return err + } + + m.pstoreProvider = pstoreProvider return nil } diff --git a/p2p/providers/peerstore_provider/persistence/provider.go b/p2p/providers/peerstore_provider/persistence/provider.go index 9c45203bc..caf4dc094 100644 --- a/p2p/providers/peerstore_provider/persistence/provider.go +++ b/p2p/providers/peerstore_provider/persistence/provider.go @@ -7,13 +7,15 @@ import ( "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) type persistencePStoreProviderFactory = modules.FactoryWithOptions[peerstore_provider.PeerstoreProvider, persistencePStoreProviderOption] type persistencePeerstoreProvider struct { base_modules.IntegratableModule - persistencePStoreProviderFactory } func NewPersistencePeerstoreProvider(bus modules.Bus, options ...persistencePStoreProviderOption) (peerstore_provider.PeerstoreProvider, error) { From c98e8d1eba776ed69d91746b1da6c558afc943c9 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 12 Jun 2023 10:11:37 +0200 Subject: [PATCH 32/41] chore: add TECHDEBT comments --- p2p/providers/peerstore_provider/persistence/provider.go | 2 ++ p2p/providers/peerstore_provider/rpc/provider.go | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/p2p/providers/peerstore_provider/persistence/provider.go b/p2p/providers/peerstore_provider/persistence/provider.go index caf4dc094..8951916e0 100644 --- a/p2p/providers/peerstore_provider/persistence/provider.go +++ b/p2p/providers/peerstore_provider/persistence/provider.go @@ -14,6 +14,8 @@ var ( type persistencePStoreProviderOption func(*persistencePeerstoreProvider) type persistencePStoreProviderFactory = modules.FactoryWithOptions[peerstore_provider.PeerstoreProvider, persistencePStoreProviderOption] + +// TECHDEBT(#810): refactor to implement `Submodule` interface. type persistencePeerstoreProvider struct { base_modules.IntegratableModule } diff --git a/p2p/providers/peerstore_provider/rpc/provider.go b/p2p/providers/peerstore_provider/rpc/provider.go index c414431d5..023920c57 100644 --- a/p2p/providers/peerstore_provider/rpc/provider.go +++ b/p2p/providers/peerstore_provider/rpc/provider.go @@ -28,6 +28,7 @@ func init() { rpcHost = runtime.GetEnv("RPC_HOST", defaults.DefaultRPCHost) } +// TECHDEBT(#810): refactor to implement `Submodule` interface. type rpcPeerstoreProvider struct { // TECHDEBT(#810): simplify once submodules are more convenient to retrieve. base_modules.IntegratableModule @@ -59,8 +60,7 @@ func Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, e return new(rpcPeerstoreProvider).Create(bus, options...) } -// TECHDEBT(#810): refactor to be consistent with `persistencePeerstoreProvider` -// (i.e. `NewRPCPeerstoreProvider` calls `rpcPeerstoreProvider#Create()`. +// TECHDEBT(#810): refactor to implement `Submodule` interface. func (*rpcPeerstoreProvider) Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) { return NewRPCPeerstoreProvider(options...), nil } From 84ce1bdfffba93ecba847ae8e714b513e3324a16 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 12 Jun 2023 10:14:41 +0200 Subject: [PATCH 33/41] chore: combine `NewRPCPeerstoreProvider()` & `Create()` --- app/client/cli/debug.go | 2 +- p2p/bootstrap.go | 2 +- p2p/providers/peerstore_provider/rpc/provider.go | 11 ++--------- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/app/client/cli/debug.go b/app/client/cli/debug.go index bd581fa64..2f1bfaa59 100644 --- a/app/client/cli/debug.go +++ b/app/client/cli/debug.go @@ -126,7 +126,7 @@ func persistentPreRun(cmd *cobra.Command, _ []string) { func setupPeerstoreProvider(rm runtime.Manager, rpcURL string) { bus := rm.GetBus() modulesRegistry := bus.GetModulesRegistry() - pstoreProvider := rpcABP.NewRPCPeerstoreProvider( + pstoreProvider := rpcABP.Create( rpcABP.WithP2PConfig(rm.GetConfig().P2P), rpcABP.WithCustomRPCURL(rpcURL), ) diff --git a/p2p/bootstrap.go b/p2p/bootstrap.go index f9f76a049..75198ee0e 100644 --- a/p2p/bootstrap.go +++ b/p2p/bootstrap.go @@ -58,7 +58,7 @@ func (m *p2pModule) bootstrap() error { continue } - pstoreProvider := rpcABP.NewRPCPeerstoreProvider( + pstoreProvider := rpcABP.Create( rpcABP.WithP2PConfig( m.GetBus().GetRuntimeMgr().GetConfig().P2P, ), diff --git a/p2p/providers/peerstore_provider/rpc/provider.go b/p2p/providers/peerstore_provider/rpc/provider.go index 023920c57..3fb12f3b5 100644 --- a/p2p/providers/peerstore_provider/rpc/provider.go +++ b/p2p/providers/peerstore_provider/rpc/provider.go @@ -39,9 +39,7 @@ type rpcPeerstoreProvider struct { rpcClient *rpc.ClientWithResponses } -// TECHDEBT(#810): refactor to be consistent with `persistencePeerstoreProvider` -// (i.e. `NewRPCPeerstoreProvider` calls `rpcPeerstoreProvider#Create()`. -func NewRPCPeerstoreProvider(options ...modules.ModuleOption) *rpcPeerstoreProvider { +func Create(options ...modules.ModuleOption) *rpcPeerstoreProvider { rabp := &rpcPeerstoreProvider{ rpcURL: fmt.Sprintf("http://%s:%s", rpcHost, defaults.DefaultRPCPort), // TODO: Make port configurable } @@ -55,14 +53,9 @@ func NewRPCPeerstoreProvider(options ...modules.ModuleOption) *rpcPeerstoreProvi return rabp } -// TECHDEBT(#810): remove as it should no longer be needed. -func Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) { - return new(rpcPeerstoreProvider).Create(bus, options...) -} - // TECHDEBT(#810): refactor to implement `Submodule` interface. func (*rpcPeerstoreProvider) Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) { - return NewRPCPeerstoreProvider(options...), nil + return Create(options...), nil } func (*rpcPeerstoreProvider) GetModuleName() string { From 341d982cff46efabc3c04c9efae9d90b598a4553 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 12 Jun 2023 10:16:34 +0200 Subject: [PATCH 34/41] refactor: rename `NewPersistencePeerstoreProvider()` to `Create()` --- p2p/module.go | 2 +- p2p/providers/peerstore_provider/persistence/provider.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/p2p/module.go b/p2p/module.go index 3edb1c697..d9e164fc7 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -238,7 +238,7 @@ func (m *p2pModule) setupPeerstoreProvider() error { pstoreProviderModule, err := m.GetBus().GetModulesRegistry().GetModule(peerstore_provider.ModuleName) if err != nil { m.logger.Debug().Msg("creating new persistence peerstore...") - pstoreProvider, err := persPSP.NewPersistencePeerstoreProvider(m.GetBus()) + pstoreProvider, err := persPSP.Create(m.GetBus()) if err != nil { return err } diff --git a/p2p/providers/peerstore_provider/persistence/provider.go b/p2p/providers/peerstore_provider/persistence/provider.go index 8951916e0..c4ce0381f 100644 --- a/p2p/providers/peerstore_provider/persistence/provider.go +++ b/p2p/providers/peerstore_provider/persistence/provider.go @@ -20,7 +20,7 @@ type persistencePeerstoreProvider struct { base_modules.IntegratableModule } -func NewPersistencePeerstoreProvider(bus modules.Bus, options ...persistencePStoreProviderOption) (peerstore_provider.PeerstoreProvider, error) { +func Create(bus modules.Bus, options ...persistencePStoreProviderOption) (peerstore_provider.PeerstoreProvider, error) { return new(persistencePeerstoreProvider).Create(bus, options...) } From a9ffa5672616f3ac84d8e472122921f5a754fb83 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 12 Jun 2023 10:19:13 +0200 Subject: [PATCH 35/41] chore: persistence peerstore provider includes all staked actors --- p2p/providers/peerstore_provider/persistence/provider.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/p2p/providers/peerstore_provider/persistence/provider.go b/p2p/providers/peerstore_provider/persistence/provider.go index c4ce0381f..7588843e5 100644 --- a/p2p/providers/peerstore_provider/persistence/provider.go +++ b/p2p/providers/peerstore_provider/persistence/provider.go @@ -48,11 +48,11 @@ func (persistencePSP *persistencePeerstoreProvider) GetStakedPeerstoreAtHeight(h } defer readCtx.Release() - validators, err := readCtx.GetAllValidators(int64(height)) + stakedActors, err := readCtx.GetAllStakedActors(int64(height)) if err != nil { return nil, err } - return peerstore_provider.ActorsToPeerstore(persistencePSP, validators) + return peerstore_provider.ActorsToPeerstore(persistencePSP, stakedActors) } // GetStakedPeerstoreAtHeight implements the respective `PeerstoreProvider` interface method. From 0d92a09f1531ec6c6b7daef01e1cd10699201859 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 12 Jun 2023 11:06:04 +0200 Subject: [PATCH 36/41] chore: fix consensus test --- consensus/e2e_tests/utils_test.go | 16 ++++++++++++++++ internal/testutil/slice.go | 12 ++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 internal/testutil/slice.go diff --git a/consensus/e2e_tests/utils_test.go b/consensus/e2e_tests/utils_test.go index 41340abc6..bd2a400f7 100644 --- a/consensus/e2e_tests/utils_test.go +++ b/consensus/e2e_tests/utils_test.go @@ -11,8 +11,10 @@ import ( "github.com/benbjohnson/clock" "github.com/golang/mock/gomock" + "github.com/pokt-network/pocket/consensus" typesCons "github.com/pokt-network/pocket/consensus/types" + "github.com/pokt-network/pocket/internal/testutil" persistenceMocks "github.com/pokt-network/pocket/persistence/types/mocks" "github.com/pokt-network/pocket/runtime" "github.com/pokt-network/pocket/runtime/configs" @@ -432,6 +434,20 @@ func basePersistenceMock(t *testing.T, _ modules.EventsChannel, bus modules.Bus) Return(bus.GetRuntimeMgr().GetGenesis().Validators, nil). AnyTimes() + persistenceReadContextMock. + EXPECT(). + GetAllStakedActors(gomock.Any()). + DoAndReturn(func(height int64) ([]*coreTypes.Actor, error) { + genesisState := bus.GetRuntimeMgr().GetGenesis() + return testutil.Concatenate[*coreTypes.Actor]( + genesisState.Validators, + genesisState.Servicers, + genesisState.Fishermen, + genesisState.Applications, + ), nil + }). + AnyTimes() + persistenceReadContextMock. EXPECT(). GetBlockHash(gomock.Any()). diff --git a/internal/testutil/slice.go b/internal/testutil/slice.go new file mode 100644 index 000000000..270142541 --- /dev/null +++ b/internal/testutil/slice.go @@ -0,0 +1,12 @@ +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) []T { + var result []T + for _, t := range tt { + result = append(result, t...) + } + + return result +} From 024d88be844cbfc71be9565b5dd77833600be2d9 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 12 Jun 2023 14:13:05 +0200 Subject: [PATCH 37/41] fix: p2p test --- p2p/utils_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/p2p/utils_test.go b/p2p/utils_test.go index 66466acb0..633ea1425 100644 --- a/p2p/utils_test.go +++ b/p2p/utils_test.go @@ -14,6 +14,9 @@ import ( libp2pCrypto "github.com/libp2p/go-libp2p/core/crypto" libp2pPeer "github.com/libp2p/go-libp2p/core/peer" mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" + "github.com/stretchr/testify/require" + + "github.com/pokt-network/pocket/internal/testutil" "github.com/pokt-network/pocket/p2p/providers/current_height_provider" "github.com/pokt-network/pocket/p2p/providers/peerstore_provider" typesP2P "github.com/pokt-network/pocket/p2p/types" @@ -29,7 +32,6 @@ import ( "github.com/pokt-network/pocket/shared/modules" mockModules "github.com/pokt-network/pocket/shared/modules/mocks" "github.com/pokt-network/pocket/telemetry" - "github.com/stretchr/testify/require" ) // ~~~~~~ RainTree Unit Test Configurations ~~~~~~ @@ -257,6 +259,14 @@ func preparePersistenceMock(t *testing.T, busMock *mockModules.MockBus, genesisS readCtxMock := mockModules.NewMockPersistenceReadContext(ctrl) readCtxMock.EXPECT().GetAllValidators(gomock.Any()).Return(genesisState.GetValidators(), nil).AnyTimes() + readCtxMock.EXPECT().GetAllStakedActors(gomock.Any()).DoAndReturn(func(height int64) ([]*coreTypes.Actor, error) { + return testutil.Concatenate[*coreTypes.Actor]( + genesisState.GetValidators(), + genesisState.GetServicers(), + genesisState.GetFishermen(), + genesisState.GetApplications(), + ), nil + }).AnyTimes() persistenceModuleMock.EXPECT().NewReadContext(gomock.Any()).Return(readCtxMock, nil).AnyTimes() readCtxMock.EXPECT().Release().AnyTimes() From 22ff0fd95050cedcd9fa72101dceb73633ab651f Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 12 Jun 2023 10:20:34 +0200 Subject: [PATCH 38/41] chore: update changelogs --- app/client/doc/CHANGELOG.md | 4 ++++ consensus/doc/CHANGELOG.md | 4 ++++ p2p/CHANGELOG.md | 4 +++- shared/CHANGELOG.md | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/client/doc/CHANGELOG.md b/app/client/doc/CHANGELOG.md index ed4d7a883..19d675da6 100644 --- a/app/client/doc/CHANGELOG.md +++ b/app/client/doc/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.0.0.33] - 2023-06-12 + +- Renamed `NewRPCPeerstoreProvider()` and `NewPersistencePeerstoreProvider()` to `Create()` (per package) + ## [0.0.0.32] - 2023-05-25 - Add the `nonInteractive` flag in a couple spots where it was missing diff --git a/consensus/doc/CHANGELOG.md b/consensus/doc/CHANGELOG.md index 477bfcc03..d1aa559ae 100644 --- a/consensus/doc/CHANGELOG.md +++ b/consensus/doc/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.0.0.54] - 2023-06-12 + +- Fix tests + ## [0.0.0.53] - 2023-06-08 - Add consensus README diff --git a/p2p/CHANGELOG.md b/p2p/CHANGELOG.md index 9a9714d95..ef28448ea 100644 --- a/p2p/CHANGELOG.md +++ b/p2p/CHANGELOG.md @@ -7,12 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.54] - 2023-06-08 +## [0.0.0.54] - 2023-06-12 - Replaced embedded `modules.Module` with simpler `modules.IntegratableModule` in `PeerstoreProvider` interface - Removed unused `PeerstoreProvider#GetP2PConfig()` method - Added `PeerstoreProvider#GetUnstakedPeerstore()` method - Added temporary `unstakedPeerstoreProvider` interface +- Renamed `NewRPCPeerstoreProvider()` and `NewPersistencePeerstoreProvider()` to `Create()` (per package) +- Updated `persistencePeerstoreProvider` to retrieve all staked actors (not just validators) ## [0.0.0.53] - 2023-06-01 diff --git a/shared/CHANGELOG.md b/shared/CHANGELOG.md index 429633f2b..1c74de141 100644 --- a/shared/CHANGELOG.md +++ b/shared/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.60] - 2023-06-08 +## [0.0.0.60] - 2023-06-12 - Added `Factory` generic type - Improved godoc comments From 044f6f1484ba94fc5d30610be424eb0c27d113c2 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Tue, 13 Jun 2023 11:00:29 +0200 Subject: [PATCH 39/41] revert: `readCtx.GetAllStakedActors()` (cherry picked from commit 5254967bbe067e30c02fb63d40bc263f3d6def22) --- p2p/providers/peerstore_provider/persistence/provider.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/p2p/providers/peerstore_provider/persistence/provider.go b/p2p/providers/peerstore_provider/persistence/provider.go index 7588843e5..2b818ae01 100644 --- a/p2p/providers/peerstore_provider/persistence/provider.go +++ b/p2p/providers/peerstore_provider/persistence/provider.go @@ -48,11 +48,12 @@ func (persistencePSP *persistencePeerstoreProvider) GetStakedPeerstoreAtHeight(h } defer readCtx.Release() - stakedActors, err := readCtx.GetAllStakedActors(int64(height)) + // TECHDEBT(#818): consider all staked actors, not just validators. + validators, err := readCtx.GetAllValidators(int64(height)) if err != nil { return nil, err } - return peerstore_provider.ActorsToPeerstore(persistencePSP, stakedActors) + return peerstore_provider.ActorsToPeerstore(persistencePSP, validators) } // GetStakedPeerstoreAtHeight implements the respective `PeerstoreProvider` interface method. From b273e878b11575cbb668479d843393748231e4f2 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Tue, 13 Jun 2023 11:06:10 +0200 Subject: [PATCH 40/41] chore: update changelogs --- app/client/doc/CHANGELOG.md | 2 +- consensus/doc/CHANGELOG.md | 2 +- p2p/CHANGELOG.md | 3 +-- shared/CHANGELOG.md | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/client/doc/CHANGELOG.md b/app/client/doc/CHANGELOG.md index 19d675da6..016d9e212 100644 --- a/app/client/doc/CHANGELOG.md +++ b/app/client/doc/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.33] - 2023-06-12 +## [0.0.0.33] - 2023-06-13 - Renamed `NewRPCPeerstoreProvider()` and `NewPersistencePeerstoreProvider()` to `Create()` (per package) diff --git a/consensus/doc/CHANGELOG.md b/consensus/doc/CHANGELOG.md index d1aa559ae..4d5b89930 100644 --- a/consensus/doc/CHANGELOG.md +++ b/consensus/doc/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.54] - 2023-06-12 +## [0.0.0.54] - 2023-06-13 - Fix tests diff --git a/p2p/CHANGELOG.md b/p2p/CHANGELOG.md index ef28448ea..52c20d3f7 100644 --- a/p2p/CHANGELOG.md +++ b/p2p/CHANGELOG.md @@ -7,14 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.54] - 2023-06-12 +## [0.0.0.54] - 2023-06-13 - Replaced embedded `modules.Module` with simpler `modules.IntegratableModule` in `PeerstoreProvider` interface - Removed unused `PeerstoreProvider#GetP2PConfig()` method - Added `PeerstoreProvider#GetUnstakedPeerstore()` method - Added temporary `unstakedPeerstoreProvider` interface - Renamed `NewRPCPeerstoreProvider()` and `NewPersistencePeerstoreProvider()` to `Create()` (per package) -- Updated `persistencePeerstoreProvider` to retrieve all staked actors (not just validators) ## [0.0.0.53] - 2023-06-01 diff --git a/shared/CHANGELOG.md b/shared/CHANGELOG.md index 1c74de141..fe1cceeab 100644 --- a/shared/CHANGELOG.md +++ b/shared/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.60] - 2023-06-12 +## [0.0.0.60] - 2023-06-13 - Added `Factory` generic type - Improved godoc comments From 2e4d60de826d651aa7d182e913300f4c16a09871 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Tue, 13 Jun 2023 11:06:18 +0200 Subject: [PATCH 41/41] chore: fix nit --- internal/testutil/slice.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/internal/testutil/slice.go b/internal/testutil/slice.go index 270142541..6129002f2 100644 --- a/internal/testutil/slice.go +++ b/internal/testutil/slice.go @@ -2,11 +2,9 @@ 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) []T { - var result []T +func Concatenate[T any](tt ...[]T) (result []T) { for _, t := range tt { result = append(result, t...) } - return result }