Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[P2P] Module-level background router peer discovery coverage #793

Draft
wants to merge 82 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
df3cce9
wip: testutils
bryanchriswhite Jun 1, 2023
1b4ea5d
wip: checkpoint
bryanchriswhite May 11, 2023
906452d
wip: testutils
bryanchriswhite Jun 1, 2023
06ef34e
wip: checkpoint
bryanchriswhite May 11, 2023
e7f057b
wip: checkpoint
bryanchriswhite May 11, 2023
70a0fc3
wip: testutils
bryanchriswhite Jun 1, 2023
430477b
wip: utils/host
bryanchriswhite Jun 1, 2023
86a067d
wip: checkpoint
bryanchriswhite May 16, 2023
83e80e6
wip: checkpoint
bryanchriswhite May 16, 2023
e46f386
wip: testutils
bryanchriswhite Jun 1, 2023
dc43563
wip: checkpoint
bryanchriswhite May 22, 2023
262a770
wip: testutils
bryanchriswhite Jun 1, 2023
0a27fad
wip: testutils
bryanchriswhite Jun 1, 2023
7fc3c3d
wip: testutils - refactor & add to generics
bryanchriswhite Jun 1, 2023
02b6b1e
wip: testutils
bryanchriswhite Jun 1, 2023
f0aee72
wip: testutils
bryanchriswhite Jun 1, 2023
d0acc92
wip: testutils
bryanchriswhite Jun 1, 2023
7f69910
wip: testutils
bryanchriswhite Jun 1, 2023
2e4f26a
wip: testutils - p2p module test refactor
bryanchriswhite Jun 1, 2023
f956fcc
wip: testutils
bryanchriswhite Jun 1, 2023
b7203cb
wip: testutils
bryanchriswhite Jun 1, 2023
cb4bf21
wip: testutils
bryanchriswhite Jun 1, 2023
3a4db57
test: add background gossip feature
bryanchriswhite May 5, 2023
0569a5e
wip: background gossip integration test
bryanchriswhite Jun 1, 2023
70a9b51
wip: background gossip integration test
bryanchriswhite Jun 1, 2023
598eb62
wip: background gossip integration test
bryanchriswhite Jun 1, 2023
61d529b
wip: background gossip integration test
bryanchriswhite Jun 1, 2023
8dd9609
wip: background gossip integration test
bryanchriswhite Jun 1, 2023
cc85184
wip: background gossip integration test
bryanchriswhite Jun 1, 2023
bc60f11
wip: background gossip integration test
bryanchriswhite Jun 1, 2023
c0a8f68
wip: background gossip integration test
bryanchriswhite Jun 1, 2023
2c22f01
wip: background gossip integration test
bryanchriswhite Jun 1, 2023
e00031b
wip: background gossip integration test
bryanchriswhite Jun 1, 2023
b0d25e7
wip: background gossip integration test
bryanchriswhite Jun 1, 2023
a33bafe
wip: background gossip integration test
bryanchriswhite Jun 1, 2023
9d3a18d
wip: raintree router
bryanchriswhite Jun 1, 2023
8e98698
wip: bg router integration - p2p module
bryanchriswhite Jun 1, 2023
4b95a55
wip: p2p module tests
bryanchriswhite Jun 1, 2023
4afe27b
chore: update go.mod
bryanchriswhite May 22, 2023
be68644
wip: background router testutil
bryanchriswhite Jun 1, 2023
442303c
wip: background router testutils
bryanchriswhite May 22, 2023
2cda45f
wip: p2p module tests
bryanchriswhite Jun 1, 2023
663859f
wip: move RainTreeMessage & add BackgroundMessage proto types
bryanchriswhite Jun 1, 2023
5c50916
wip: bg router handle messages
bryanchriswhite Jun 1, 2023
ae0b7aa
wip: integrate bg router - module
bryanchriswhite Jun 1, 2023
ce65e6f
wip: add comment to shared/k8s/debug.go
bryanchriswhite Jun 1, 2023
63a03fb
fixup: refactor move generics pkg
bryanchriswhite May 23, 2023
b40a4de
chore: remove unused `backgroundRouter#HandleNetworkData()` method
bryanchriswhite May 23, 2023
a6c5949
wip: update multierr in go.mod
bryanchriswhite Jun 1, 2023
0ebe5ff
wip: background router
bryanchriswhite Jun 1, 2023
0d49f29
wip bg router testing
bryanchriswhite Jun 1, 2023
c125019
wip: handler fixes
bryanchriswhite Jun 1, 2023
c61e2bd
wip: integrate bg router - module
bryanchriswhite Jun 1, 2023
39b8510
wip: integrate bg router - module test
bryanchriswhite Jun 1, 2023
db1fafd
wip: raintree comment
bryanchriswhite Jun 1, 2023
3eaecce
wip: integrate bg router - raintree test
bryanchriswhite Jun 1, 2023
d4b28be
wip: integrate bg router - module test
bryanchriswhite Jun 1, 2023
90bcf66
wip: generate nonce in `messaging.PackMessage()`
bryanchriswhite Jun 1, 2023
709f78c
fixup: bg router
bryanchriswhite Jun 1, 2023
f44aaa9
fixup: bg router test
bryanchriswhite Jun 1, 2023
667a082
fixup: integrate bg router - module
bryanchriswhite Jun 1, 2023
2a33404
wip: integrate bg router - module
bryanchriswhite Jun 1, 2023
585fcc6
wip: update go.mod add go-mockdns
bryanchriswhite Jun 1, 2023
63bcc15
chore: add `typesP2P.Router#Close()` interface method
bryanchriswhite Jun 1, 2023
c90d9fd
chore: implement `backgroundRouter#Close()`
bryanchriswhite Jun 1, 2023
566f849
chore: integrate `typesP2P.Router#Close()` into p2p module
bryanchriswhite Jun 1, 2023
f6ec162
chore: implement `rainTreeRouter#Close()`
bryanchriswhite Jun 1, 2023
dc6e27f
wip: bg router
bryanchriswhite Jun 1, 2023
316789a
wip: tracing
bryanchriswhite Jun 1, 2023
7093181
wip: misc
bryanchriswhite Jun 1, 2023
75ba0bf
wip: bg gossip test
bryanchriswhite Jun 1, 2023
cc06619
fixup: add LoadLocalNetKrivatekeys
bryanchriswhite Jun 1, 2023
b3da937
fixup: integrate bg router
bryanchriswhite Jun 1, 2023
a8206ec
fixup: add handler router config fields
bryanchriswhite Jun 1, 2023
03d5c41
test: add peer discovery feature
bryanchriswhite May 5, 2023
7ab03ae
wip: peer discovery integration test
bryanchriswhite Jun 1, 2023
1ee07f0
wip: peer discovery integration test
bryanchriswhite Jun 1, 2023
be68967
wip: peer discovery integration test
bryanchriswhite Jun 1, 2023
0f34a64
wip: peer discovery integration test
bryanchriswhite Jun 1, 2023
b213598
wip: peer discovery integration test
bryanchriswhite Jun 1, 2023
333b1e9
wip: peer discovery integration test
bryanchriswhite Jun 1, 2023
a00b9d1
wip: peer discovery integration test
bryanchriswhite Jun 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ protogen_local: go_protoc-go-inject-tag ## Generate go structures for all of the
$(PROTOC_SHARED) -I=./consensus/types/proto --go_out=./consensus/types ./consensus/types/proto/*.proto

# P2P
$(PROTOC_SHARED) -I=./p2p/raintree/types/proto --go_out=./p2p/types ./p2p/raintree/types/proto/*.proto
$(PROTOC_SHARED) -I=./p2p/types/proto --go_out=./p2p/types ./p2p/types/proto/*.proto

# echo "View generated proto files by running: make protogen_show"

Expand Down
25 changes: 6 additions & 19 deletions consensus/e2e_tests/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package e2e_tests
import (
"context"
"fmt"
"github.com/pokt-network/pocket/internal/testutil/p2p"
"github.com/pokt-network/pocket/internal/testutil/persistence"
telemetry_testutil "github.com/pokt-network/pocket/internal/testutil/telemetry"
"os"
"reflect"
"sort"
Expand All @@ -13,7 +16,6 @@ import (
"github.com/golang/mock/gomock"
"github.com/pokt-network/pocket/consensus"
typesCons "github.com/pokt-network/pocket/consensus/types"
persistenceMocks "github.com/pokt-network/pocket/persistence/types/mocks"
"github.com/pokt-network/pocket/runtime"
"github.com/pokt-network/pocket/runtime/configs"
"github.com/pokt-network/pocket/runtime/defaults"
Expand Down Expand Up @@ -101,7 +103,7 @@ func CreateTestConsensusPocketNode(
bus modules.Bus,
eventsChannel modules.EventsChannel,
) *shared.Node {
persistenceMock := basePersistenceMock(t, eventsChannel, bus)
persistenceMock := persistence_testutil.PersistenceMockWithBlockStore(t, eventsChannel, bus)
bus.RegisterModule(persistenceMock)

consensusMod, err := consensus.Create(bus)
Expand All @@ -115,9 +117,9 @@ func CreateTestConsensusPocketNode(
runtimeMgr := (bus).GetRuntimeMgr()
// TODO(olshansky): At the moment we are using the same base mocks for all the tests,
// but note that they will need to be customized on a per test basis.
p2pMock := baseP2PMock(t, eventsChannel)
p2pMock := p2p_testutil.BaseP2PMock(t, eventsChannel)
utilityMock := baseUtilityMock(t, eventsChannel, runtimeMgr.GetGenesis(), consensusModule)
telemetryMock := baseTelemetryMock(t, eventsChannel)
telemetryMock := telemetry_testutil.MinimalTelemetryMock(t)
loggerMock := baseLoggerMock(t, eventsChannel)
rpcMock := baseRpcMock(t, eventsChannel)

Expand Down Expand Up @@ -548,21 +550,6 @@ func baseReplicaUtilityUnitOfWorkMock(t *testing.T, genesisState *genesis.Genesi
return utilityReplicaUnitOfWorkMock
}

func baseTelemetryMock(t *testing.T, _ modules.EventsChannel) *mockModules.MockTelemetryModule {
ctrl := gomock.NewController(t)
telemetryMock := mockModules.NewMockTelemetryModule(ctrl)
timeSeriesAgentMock := baseTelemetryTimeSeriesAgentMock(t)
eventMetricsAgentMock := baseTelemetryEventMetricsAgentMock(t)

telemetryMock.EXPECT().Start().Return(nil).AnyTimes()
telemetryMock.EXPECT().SetBus(gomock.Any()).Return().AnyTimes()
telemetryMock.EXPECT().GetTimeSeriesAgent().Return(timeSeriesAgentMock).AnyTimes()
telemetryMock.EXPECT().GetEventMetricsAgent().Return(eventMetricsAgentMock).AnyTimes()
telemetryMock.EXPECT().GetModuleName().Return(modules.TelemetryModuleName).AnyTimes()

return telemetryMock
}

func baseRpcMock(t *testing.T, _ modules.EventsChannel) *mockModules.MockRPCModule {
ctrl := gomock.NewController(t)
rpcMock := mockModules.NewMockRPCModule(ctrl)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
github.com/dgraph-io/badger/v3 v3.2103.2
github.com/foxcpp/go-mockdns v1.0.0
github.com/getkin/kin-openapi v0.107.0
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/vault/api v1.9.0
github.com/jackc/pgconn v1.13.0
github.com/jordanorelli/lexnum v0.0.0-20141216151731-460eeb125754
Expand Down Expand Up @@ -112,7 +113,6 @@ require (
github.com/gotestyourself/gotestyourself v2.2.0+incompatible // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.6.6 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.6 // indirect
Expand Down
96 changes: 96 additions & 0 deletions internal/testutil/bus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package testutil

import (
"github.com/golang/mock/gomock"
"github.com/pokt-network/pocket/p2p/providers/current_height_provider"
"github.com/pokt-network/pocket/p2p/providers/peerstore_provider"
"github.com/pokt-network/pocket/runtime"
"github.com/pokt-network/pocket/shared/messaging"
"github.com/regen-network/gocuke"

"github.com/pokt-network/pocket/shared/modules"
"github.com/pokt-network/pocket/shared/modules/mocks"
)

type BusEventHandler func(*messaging.PocketEnvelope)
type BusEventHandlerFactory func(t gocuke.TestingT, busMock *mock_modules.MockBus) BusEventHandler

// MinimalBusMock returns a bus mock with a module registry and minimal
// expectations registered to maximize re-usability.
func MinimalBusMock(
t gocuke.TestingT,
runtimeMgr modules.RuntimeMgr,
) *mock_modules.MockBus {
t.Helper()

ctrl := gomock.NewController(t)
busMock := mock_modules.NewMockBus(ctrl)
busMock.EXPECT().GetRuntimeMgr().Return(runtimeMgr).AnyTimes()
busMock.EXPECT().RegisterModule(gomock.Any()).DoAndReturn(func(m modules.Module) {
m.SetBus(busMock)
}).AnyTimes()

mockModulesRegistry := mock_modules.NewMockModulesRegistry(ctrl)

// TODO_THIS_COMMIT: refactor - this doesn't belong here
mockModulesRegistry.EXPECT().GetModule(peerstore_provider.ModuleName).Return(nil, runtime.ErrModuleNotRegistered(peerstore_provider.ModuleName)).AnyTimes()
mockModulesRegistry.EXPECT().GetModule(current_height_provider.ModuleName).Return(nil, runtime.ErrModuleNotRegistered(current_height_provider.ModuleName)).AnyTimes()

busMock.EXPECT().GetModulesRegistry().Return(mockModulesRegistry).AnyTimes()
return busMock
}

// BaseBusMock returns a base bus mock which will accept any event,
// passing it to the provided handler function, any number of times.
func BaseBusMock(
t gocuke.TestingT,
runtimeMgr modules.RuntimeMgr,
) *mock_modules.MockBus {
t.Helper()

return WithoutBusEventHandler(t, MinimalBusMock(t, runtimeMgr))
}

// BusMockWithEventHandler returns a base bus mock which will accept any event,
// any number of times, calling the `handler` returned from `handlerFactory`
// with the event as an argument.
func BusMockWithEventHandler(
t gocuke.TestingT,
runtimeMgr modules.RuntimeMgr,
handlerFactory BusEventHandlerFactory,
) *mock_modules.MockBus {
t.Helper()

busMock := MinimalBusMock(t, runtimeMgr)
return WithBusEventHandler(t, busMock, handlerFactory)
}

// WithBusEventHandler adds an expectation to a bus mock such that it will accept
// any event, any number of times, calling the `handler` returned from `handlerFactory`
// with the event as an argument.
func WithBusEventHandler(
t gocuke.TestingT,
busMock *mock_modules.MockBus,
handlerFactory BusEventHandlerFactory,
) *mock_modules.MockBus {
t.Helper()

if handlerFactory != nil {
handler := handlerFactory(t, busMock)
busMock.EXPECT().PublishEventToBus(gomock.Any()).Do(handler).AnyTimes()
}

return busMock
}

// WithoutBusEventHandler adds an expectation to a bus mock such that it will accept
// any event, any number of times.
func WithoutBusEventHandler(
t gocuke.TestingT,
busMock *mock_modules.MockBus,
) *mock_modules.MockBus {
t.Helper()

busMock.EXPECT().PublishEventToBus(gomock.Any()).AnyTimes()
return busMock
}
30 changes: 30 additions & 0 deletions internal/testutil/bus/bus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package bus_testutil

import (
"github.com/regen-network/gocuke"

"github.com/pokt-network/pocket/internal/testutil"
"github.com/pokt-network/pocket/internal/testutil/runtime"
"github.com/pokt-network/pocket/runtime/genesis"
"github.com/pokt-network/pocket/shared/crypto"
"github.com/pokt-network/pocket/shared/modules/mocks"
)

func NewBus(
t gocuke.TestingT,
privKey crypto.PrivateKey,
serviceURL string,
genesisState *genesis.GenesisState,
busEventHandlerFactory testutil.BusEventHandlerFactory,
) *mock_modules.MockBus {
t.Helper()

runtimeMgrMock := runtime_testutil.BaseRuntimeManagerMock(
t, privKey,
serviceURL,
genesisState,
)
busMock := testutil.BusMockWithEventHandler(t, runtimeMgrMock, busEventHandlerFactory)
busMock.EXPECT().GetRuntimeMgr().Return(runtimeMgrMock).AnyTimes()
return busMock
}
30 changes: 30 additions & 0 deletions internal/testutil/composition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package testutil

// PipeTwoToOne threads two values of any type (T and U) through a pipeline of
// functions and returns the result of any type (U). Each function in the pipeline
// takes two arguments of type T and U, and returns a value of type U.
//
// Applies each function in the pipeline to the current value of U and the
// constant value of T, effectively "threading" the initial U value through the
// pipeline of functions.
//
// Does *not* mutate the original U value. Instead, it operates on a reference
// to U, ensuring that value types (non-pointer types) are not mutated.
//
// Returns the final value of U after it has been threaded through all the functions in the pipeline.
//
// Usage:
//
// result := PipeTwo(initialT, initialU, func1, func2, func3)
//
// In this example, initialT and initialU are the initial values of T and U, and func1, func2, and func3
// are functions that take two arguments of type T and U and return a value of type U.
func PipeTwoToOne[T, U any](t T, u U, pipeline ...func(T, U) U) U {
// NB: don't mutate potential value type `u` (i.e. non-pointer)
uRef := u
for _, fn := range pipeline {
uRef = fn(t, uRef)
}

return u
}
24 changes: 24 additions & 0 deletions internal/testutil/consensus/mocks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package consensus_testutil

import (
"github.com/golang/mock/gomock"
"github.com/regen-network/gocuke"

"github.com/pokt-network/pocket/shared/modules"
"github.com/pokt-network/pocket/shared/modules/mocks"
)

// Consensus mock - only needed for validatorMap access
func BaseConsensusMock(t gocuke.TestingT, busMock *mock_modules.MockBus) *mock_modules.MockConsensusModule {
ctrl := gomock.NewController(t)
consensusMock := mock_modules.NewMockConsensusModule(ctrl)
consensusMock.EXPECT().CurrentHeight().Return(uint64(1)).AnyTimes()

consensusMock.EXPECT().GetBus().Return(busMock).AnyTimes()
consensusMock.EXPECT().SetBus(busMock).AnyTimes()
consensusMock.EXPECT().GetModuleName().Return(modules.ConsensusModuleName).AnyTimes()
busMock.EXPECT().GetConsensusModule().Return(consensusMock).AnyTimes()
//busMock.RegisterModule(consensusMock)

return consensusMock
}
Loading