From 79e988cdc457f13cbd423b0b183fbf6210ad55ff Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Sun, 4 Dec 2022 21:01:19 +0000 Subject: [PATCH 001/143] feat(Messaging): new events and message --- .../messaging/proto/addressbook_at_height.proto | 16 ++++++++++++++++ shared/messaging/proto/events.proto | 8 ++++++++ 2 files changed, 24 insertions(+) create mode 100644 shared/messaging/proto/addressbook_at_height.proto diff --git a/shared/messaging/proto/addressbook_at_height.proto b/shared/messaging/proto/addressbook_at_height.proto new file mode 100644 index 000000000..a843715c6 --- /dev/null +++ b/shared/messaging/proto/addressbook_at_height.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; + +package pocket; + +option go_package = "github.com/pokt-network/pocket/shared/messaging"; + +message AddressBookAtHeight { + repeated NetworkPeer network_peers = 1; + uint64 height = 2; +} + +message NetworkPeer { + bytes public_key = 1; + bytes address = 2; + string service_url = 3; +} \ No newline at end of file diff --git a/shared/messaging/proto/events.proto b/shared/messaging/proto/events.proto index 22356bcc7..5840d335a 100644 --- a/shared/messaging/proto/events.proto +++ b/shared/messaging/proto/events.proto @@ -5,3 +5,11 @@ package pocket; option go_package = "github.com/pokt-network/pocket/shared/messaging"; message NodeStartedEvent {} + +message BeforeHeightChangedEvent { + uint64 current_height = 1; +} + +message HeightChangedEvent { + uint64 new_height = 1; +} From f925a1f474e29b28fb45bee4be67b51a0e39e035 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Sun, 4 Dec 2022 21:05:45 +0000 Subject: [PATCH 002/143] feat(Consensus): the pacemaker emits Height related events --- consensus/pacemaker.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/consensus/pacemaker.go b/consensus/pacemaker.go index 049df6516..198b3510e 100644 --- a/consensus/pacemaker.go +++ b/consensus/pacemaker.go @@ -8,6 +8,7 @@ import ( consensusTelemetry "github.com/pokt-network/pocket/consensus/telemetry" typesCons "github.com/pokt-network/pocket/consensus/types" + "github.com/pokt-network/pocket/shared/messaging" "github.com/pokt-network/pocket/shared/modules" ) @@ -204,11 +205,15 @@ func (p *paceMaker) InterruptRound() { func (p *paceMaker) NewHeight() { p.consensusMod.nodeLog(typesCons.PacemakerNewHeight(p.consensusMod.CurrentHeight() + 1)) + p.onBeforeNewHeight() + p.consensusMod.Height++ p.consensusMod.resetForNewHeight() p.startNextView(nil, false) // TODO(design): We are omitting CommitQC and TimeoutQC here. + p.onAfterNewHeight() + p.consensusMod. GetBus(). GetTelemetryModule(). @@ -262,3 +267,13 @@ func (p *paceMaker) getStepTimeout(round uint64) timePkg.Duration { baseTimeout := timePkg.Duration(int64(timePkg.Millisecond) * int64(p.pacemakerCfg.GetTimeoutMsec())) return baseTimeout } + +func (p *paceMaker) onBeforeNewHeight() { + event, _ := messaging.PackMessage(&messaging.BeforeHeightChangedEvent{CurrentHeight: p.consensusMod.CurrentHeight()}) + p.GetBus().PublishEventToBus(event) +} + +func (p *paceMaker) onAfterNewHeight() { + event, _ := messaging.PackMessage(&messaging.HeightChangedEvent{NewHeight: p.consensusMod.CurrentHeight()}) + p.GetBus().PublishEventToBus(event) +} From 27859db6888ccd4735cdf0a59fba7977df2fb7fa Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Sun, 4 Dec 2022 21:06:58 +0000 Subject: [PATCH 003/143] feat(P2P): reacts to BeforeHeightChanged and broadcasts addrb --- p2p/module.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/p2p/module.go b/p2p/module.go index ac4f402c2..92e63001e 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -7,6 +7,7 @@ import ( "github.com/pokt-network/pocket/p2p/raintree" "github.com/pokt-network/pocket/p2p/stdnetwork" typesP2P "github.com/pokt-network/pocket/p2p/types" + "github.com/pokt-network/pocket/shared/codec" cryptoPocket "github.com/pokt-network/pocket/shared/crypto" "github.com/pokt-network/pocket/shared/messaging" "github.com/pokt-network/pocket/shared/modules" @@ -31,6 +32,49 @@ type p2pModule struct { network typesP2P.Network } +// HandleEvent implements modules.P2PModule +func (m *p2pModule) HandleEvent(message *anypb.Any) error { + switch message.MessageName() { + case messaging.BeforeHeightChangedEventType: + msg, err := codec.GetCodec().FromAny(message) + if err != nil { + return err + } + event, ok := msg.(*messaging.BeforeHeightChangedEvent) + if !ok { + return fmt.Errorf("failed to cast message to BeforeHeightChangedEvent") + } + + m.broadcastAddressBookAtHeight(event.CurrentHeight) + + default: + return typesP2P.ErrUnknownEventType(message.MessageName()) + } + return nil +} + +// broadcastAddressBookAtHeight broadcasts on the event bus the address book at the given height +func (m *p2pModule) broadcastAddressBookAtHeight(height uint64) error { + addrBook := m.network.GetAddrBook() + networkPeers := make([]*messaging.NetworkPeer, len(addrBook)) + for i, peer := range addrBook { + networkPeers[i] = &messaging.NetworkPeer{ + Address: peer.Address, + PublicKey: peer.PublicKey.Bytes(), + ServiceUrl: peer.ServiceUrl, + } + } + message, err := messaging.PackMessage(&messaging.AddressBookAtHeight{ + NetworkPeers: networkPeers, + Height: height, + }) + if err != nil { + return err + } + m.GetBus().PublishEventToBus(message) + return nil +} + // TECHDEBT(drewsky): Discuss how to best expose/access `Address` throughout the codebase. func (m *p2pModule) GetAddress() (cryptoPocket.Address, error) { return m.address, nil From e19041b95ce177025a046d70d553bd95b8682bda Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Sun, 4 Dec 2022 21:07:32 +0000 Subject: [PATCH 004/143] feat(Messaging): eventTypes for new messages/events --- shared/messaging/events.go | 4 +++- shared/messaging/messages.go | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/shared/messaging/events.go b/shared/messaging/events.go index 1ccfdf0c0..7c38a599b 100644 --- a/shared/messaging/events.go +++ b/shared/messaging/events.go @@ -1,5 +1,7 @@ package messaging const ( - NodeStartedEventType = "pocket.NodeStartedEvent" + NodeStartedEventType = "pocket.NodeStartedEvent" + BeforeHeightChangedEventType = "pocket.BeforeHeightChangedEvent" + HeightChangedEventType = "pocket.HeightChangedEvent" ) diff --git a/shared/messaging/messages.go b/shared/messaging/messages.go index 6dbdf89fd..20829ce2e 100644 --- a/shared/messaging/messages.go +++ b/shared/messaging/messages.go @@ -4,6 +4,8 @@ import "strings" const ( DebugMessageEventType = "pocket.DebugMessage" + + AddressBookAtHeightEventType = "pocket.AddressBookAtHeight" ) func (envelope *PocketEnvelope) GetContentType() string { From 550c47e1f91c0e340e53b576a4630ad362735729 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Sun, 4 Dec 2022 21:11:42 +0000 Subject: [PATCH 005/143] chore(P2P): ErrUnknownEventType --- p2p/types/errors.go | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 p2p/types/errors.go diff --git a/p2p/types/errors.go b/p2p/types/errors.go new file mode 100644 index 000000000..815667e69 --- /dev/null +++ b/p2p/types/errors.go @@ -0,0 +1,7 @@ +package types + +import "fmt" + +func ErrUnknownEventType(msg interface{}) error { + return fmt.Errorf("unknown event type: %v", msg) +} From 3dc5ffd3e203a1af0585eab46ce45b67605a5e2d Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Sun, 4 Dec 2022 21:12:06 +0000 Subject: [PATCH 006/143] feat(P2P): HandleEvent --- 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 d3ece2fe7..9b1b079d5 100644 --- a/shared/modules/p2p_module.go +++ b/shared/modules/p2p_module.go @@ -11,6 +11,8 @@ type P2PModule interface { Module ConfigurableModule + HandleEvent(*anypb.Any) error + Broadcast(msg *anypb.Any) error Send(addr cryptoPocket.Address, msg *anypb.Any) error GetAddress() (cryptoPocket.Address, error) From 3c9cbc7d780dc0c5682b0f6b2c80cae9e789028a Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Sun, 4 Dec 2022 21:13:25 +0000 Subject: [PATCH 007/143] feat(Shared): event handling for height events and addressbook --- shared/node.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/shared/node.go b/shared/node.go index 822d75ee8..bdb9f482d 100644 --- a/shared/node.go +++ b/shared/node.go @@ -159,6 +159,18 @@ func (node *Node) handleEvent(message *messaging.PocketEnvelope) error { switch contentType { case messaging.NodeStartedEventType: log.Println("[NOOP] Received NodeStartedEvent") + case messaging.BeforeHeightChangedEventType: + log.Println("Received BeforeNewHeightEvent") + node.GetBus().GetP2PModule().HandleEvent(message.Content) + case messaging.AddressBookAtHeightEventType: + log.Printf("Received AddressBookAtHeightEvent: %v\n", message.Content) + // DISCUSS (deblasis): here we'd delegate a module to handle the event. + // We need an open PersistenceRWContext where we can update the validator list (sounds like churn management). + // The recent changes (StateHash) made me question/revisit my initial implementation. + // Should the addressbook be considered separately from the "ValidatorMap" (currently)? + + case messaging.HeightChangedEventType: + log.Println("[NOOP] Received HeightChangedEventType") case consensus.HotstuffMessageContentType: return node.GetBus().GetConsensusModule().HandleMessage(message.Content) case messaging.DebugMessageEventType: From a4abab873b3856b56242714e9d97700651b628dd Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Sun, 4 Dec 2022 21:14:07 +0000 Subject: [PATCH 008/143] docs(Consensus): changelog --- consensus/doc/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/consensus/doc/CHANGELOG.md b/consensus/doc/CHANGELOG.md index 074b7e69b..e35c2c5db 100644 --- a/consensus/doc/CHANGELOG.md +++ b/consensus/doc/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.0.0.11] - 2022-12-04 + +- The `Pacemaker` now emits `BeforeHeightChangedEvent` events when the height is about to change. +- The `Pacemaker` now emits `HeightChangedEvent` events when the height changes. + ## [0.0.0.10] - 2022-11-30 - Propagate `highPrepareQC` if available to the block being created From 4d01838d1b5589224d3747043a454efc4be78c0b Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Sun, 4 Dec 2022 21:14:19 +0000 Subject: [PATCH 009/143] docs(Shared): changelog --- shared/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/shared/CHANGELOG.md b/shared/CHANGELOG.md index eb02de134..a1d585513 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.5] - 2022-12-04 + +- Added `AddressBookAtHeight` message used cross-module broadcast of the address book right before we reach a new Height. +- Added `BeforeHeightChangedEvent` and `HeightChangedEvent` events that respectively signal the other modules that we are about to change the Height and that we have changed the Height. + ## [0.0.0.4] - 2022-11-30 Debug: From 12ee0ecfcb43f3afe122a536a312a0755e9a1167 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Sun, 4 Dec 2022 21:52:00 +0000 Subject: [PATCH 010/143] test(Consensus): P2PMock fix (HandleEvent) --- consensus/consensus_tests/utils_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/consensus/consensus_tests/utils_test.go b/consensus/consensus_tests/utils_test.go index 8fe54c90b..3e2f012e4 100644 --- a/consensus/consensus_tests/utils_test.go +++ b/consensus/consensus_tests/utils_test.go @@ -340,6 +340,7 @@ func baseP2PMock(t *testing.T, testChannel modules.EventsChannel) *modulesMock.M testChannel <- *e }). AnyTimes() + p2pMock.EXPECT().HandleEvent(gomock.Any()).Return(nil).AnyTimes() return p2pMock } From 520b8b96e16cbd2ef1ddc96fe99dafa491c3a075 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Sun, 4 Dec 2022 21:52:30 +0000 Subject: [PATCH 011/143] feat(P2P): raintree mempool map not unbounded anymore --- p2p/raintree/network.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/p2p/raintree/network.go b/p2p/raintree/network.go index a813b9520..800dfb534 100644 --- a/p2p/raintree/network.go +++ b/p2p/raintree/network.go @@ -18,6 +18,8 @@ import ( var _ typesP2P.Network = &rainTreeNetwork{} var _ modules.IntegratableModule = &rainTreeNetwork{} +const mempoolMaxNonces = 1e6 // 1 million rolling nonces. The oldest will be pruned in favor of the newest when this threshold is reached + type rainTreeNetwork struct { bus modules.Bus @@ -26,7 +28,8 @@ type rainTreeNetwork struct { peersManager *peersManager // TODO (#278): What should we use for de-duping messages within P2P? - mempool map[uint64]struct{} // TODO (#278) replace map implementation (can grow unbounded) + mempool map[uint64]struct{} + mempool_keys []uint64 } func NewRainTreeNetwork(addr cryptoPocket.Address, addrBook typesP2P.AddrBook) typesP2P.Network { @@ -39,6 +42,7 @@ func NewRainTreeNetwork(addr cryptoPocket.Address, addrBook typesP2P.AddrBook) t selfAddr: addr, peersManager: pm, mempool: make(map[uint64]struct{}), + mempool_keys: make([]uint64, 0, mempoolMaxNonces), } return typesP2P.Network(n) @@ -179,6 +183,12 @@ func (n *rainTreeNetwork) HandleNetworkData(data []byte) ([]byte, error) { } n.mempool[rainTreeMsg.Nonce] = struct{}{} + n.mempool_keys = append(n.mempool_keys, rainTreeMsg.Nonce) + if len(n.mempool_keys) > mempoolMaxNonces { + // removing the oldest nonce and the oldest key from the slice + delete(n.mempool, n.mempool_keys[0]) + n.mempool_keys = n.mempool_keys[1:] + } // Return the data back to the caller so it can be handled by the app specific bus return rainTreeMsg.Data, nil From caaad9cd9a3ce959326ee86464416c480a08bd44 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Sun, 4 Dec 2022 21:56:39 +0000 Subject: [PATCH 012/143] docs(P2P): changelog --- p2p/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/p2p/CHANGELOG.md b/p2p/CHANGELOG.md index 970cc23ed..e4f56ab99 100644 --- a/p2p/CHANGELOG.md +++ b/p2p/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.0.0.9] - 2022-12-04 + +- Raintree mempool cannot grow unbounded anymore. It's now bounded by a constant limit and when new nonces are inserted the oldest ones are removed. +- Reacting to the `BeforeHeightChanged` event to broadcast the addressBook to the other modules via the bus. + ## [0.0.0.8] - 2022-11-14 - Removed topic from messaging From 9506419627784b9de849e12b4abb6d1b9a15eb38 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 5 Dec 2022 01:20:41 +0000 Subject: [PATCH 013/143] feat(P2P): raintree now allows ephemeral peersmanager --- p2p/raintree/addrbook_utils.go | 16 +++++++++++----- p2p/raintree/network.go | 29 ++++++++++++++++++++++++++--- p2p/raintree/peers_manager.go | 15 ++++++++++++++- 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/p2p/raintree/addrbook_utils.go b/p2p/raintree/addrbook_utils.go index f9b7a570f..3a8f4cf02 100644 --- a/p2p/raintree/addrbook_utils.go +++ b/p2p/raintree/addrbook_utils.go @@ -15,12 +15,18 @@ const ( floatPrecision = float64(0.0000001) ) -// TODO(team): Need to integrate with persistence layer so we are storing this on a per height basis. -// We can easily hit an issue where we are propagating a message from an older height (e.g. before -// the addr book was updated), but we're using `maxNumLevels` associated with the number of -// validators at the current height. -func (n *rainTreeNetwork) getAddrBookLength(level uint32, _height uint64) int { +func (n *rainTreeNetwork) getAddrBookLength(level uint32, height uint64) int { peersManagerStateView := n.peersManager.getNetworkView() + + // if we are propagating a message from a previous height, we need to instantiate an ephemeral peersManager (without add/remove) + if height < n.GetBus().GetConsensusModule().CurrentHeight() { + peersManagerWithAddrBookProvider, err := NewPeersManagerWithAddrBookProvider(n.selfAddr, n.addrBookProvider, height) + if err != nil { + log.Fatalf("[ERROR] Error initializing rainTreeNetwork peersManagerWithAddrBookProvider: %v", err) + } + peersManagerStateView = peersManagerWithAddrBookProvider.getNetworkView() + } + shrinkageCoefficient := math.Pow(shrinkagePercentage, float64(peersManagerStateView.maxNumLevels-level)) return int(float64(len(peersManagerStateView.addrList)) * (shrinkageCoefficient)) } diff --git a/p2p/raintree/network.go b/p2p/raintree/network.go index 800dfb534..305f7b38e 100644 --- a/p2p/raintree/network.go +++ b/p2p/raintree/network.go @@ -23,7 +23,8 @@ const mempoolMaxNonces = 1e6 // 1 million rolling nonces. The oldest will be pru type rainTreeNetwork struct { bus modules.Bus - selfAddr cryptoPocket.Address + selfAddr cryptoPocket.Address + addrBookProvider typesP2P.AddrBookProvider peersManager *peersManager @@ -33,9 +34,9 @@ type rainTreeNetwork struct { } func NewRainTreeNetwork(addr cryptoPocket.Address, addrBook typesP2P.AddrBook) typesP2P.Network { - pm, err := newPeersManager(addr, addrBook) + pm, err := newPeersManager(addr, addrBook, true) if err != nil { - log.Println("[ERROR] Error initializing rainTreeNetwork peersManager: ", err) + log.Fatalf("[ERROR] Error initializing rainTreeNetwork peersManager: %v", err) } n := &rainTreeNetwork{ @@ -48,6 +49,28 @@ func NewRainTreeNetwork(addr cryptoPocket.Address, addrBook typesP2P.AddrBook) t return typesP2P.Network(n) } +func NewRainTreeNetworkWithAddrBookProvider(addr cryptoPocket.Address, addrBookProvider typesP2P.AddrBookProvider, height uint64) typesP2P.Network { + addrBook, err := addrBookProvider(height) + if err != nil { + log.Fatalf("[ERROR] Error getting addrBook from addrBookProvider: %v", err) + } + + pm, err := newPeersManager(addr, addrBook, true) + if err != nil { + log.Fatalf("[ERROR] Error initializing rainTreeNetwork peersManager: %v", err) + } + + n := &rainTreeNetwork{ + selfAddr: addr, + addrBookProvider: addrBookProvider, + peersManager: pm, + mempool: make(map[uint64]struct{}), + mempool_keys: make([]uint64, 0, mempoolMaxNonces), + } + + return typesP2P.Network(n) +} + func (n *rainTreeNetwork) NetworkBroadcast(data []byte) error { return n.networkBroadcastAtLevel(data, n.peersManager.getNetworkView().maxNumLevels, getNonce()) } diff --git a/p2p/raintree/peers_manager.go b/p2p/raintree/peers_manager.go index 87cfabf44..58d3c7e91 100644 --- a/p2p/raintree/peers_manager.go +++ b/p2p/raintree/peers_manager.go @@ -30,7 +30,16 @@ type peersManager struct { maxNumLevels uint32 } -func newPeersManager(selfAddr cryptoPocket.Address, addrBook typesP2P.AddrBook) (*peersManager, error) { +func NewPeersManagerWithAddrBookProvider(selfAddr cryptoPocket.Address, addrBookProvider typesP2P.AddrBookProvider, height uint64) (*peersManager, error) { + addrBook, err := addrBookProvider(height) + if err != nil { + return nil, err + } + + return newPeersManager(selfAddr, addrBook, false) +} + +func newPeersManager(selfAddr cryptoPocket.Address, addrBook typesP2P.AddrBook, handleEvents bool) (*peersManager, error) { pm := &peersManager{ selfAddr: selfAddr, addrBook: addrBook, @@ -66,6 +75,10 @@ func newPeersManager(selfAddr cryptoPocket.Address, addrBook typesP2P.AddrBook) pm.maxNumLevels = pm.getMaxAddrBookLevels() + if !handleEvents { + return pm, nil + } + // listening and reacting to peer changes (addition/deletion) events go func() { for evt := range pm.eventCh { From 0cf393c9e1ba2399e6ea0902a0ca923d6e9f2423 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 5 Dec 2022 01:22:56 +0000 Subject: [PATCH 014/143] docs(P2P): changelog --- p2p/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/p2p/CHANGELOG.md b/p2p/CHANGELOG.md index e4f56ab99..eebc7b4f8 100644 --- a/p2p/CHANGELOG.md +++ b/p2p/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Raintree mempool cannot grow unbounded anymore. It's now bounded by a constant limit and when new nonces are inserted the oldest ones are removed. - Reacting to the `BeforeHeightChanged` event to broadcast the addressBook to the other modules via the bus. +- Raintree is now capable of fetching the address book for a previous height and to instantiate an ephemeral `peersManager` with it. ## [0.0.0.8] - 2022-11-14 From 3fdc817899c4524c4516df5248c0ae81c086f07b Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 5 Dec 2022 01:23:31 +0000 Subject: [PATCH 015/143] feat(P2P): AddrBookProvider --- p2p/types/addr_book.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/p2p/types/addr_book.go b/p2p/types/addr_book.go index 3a317b18b..912ee7265 100644 --- a/p2p/types/addr_book.go +++ b/p2p/types/addr_book.go @@ -7,3 +7,6 @@ type AddrBook []*NetworkPeer // // Since maps cannot be sorted arbitrarily in Go, to achieve sorting, we need to rely on `addrList` which is a slice of addresses/strings and therefore we can sort it the way we want. type AddrBookMap map[string]*NetworkPeer + +// AddrBookProvider is a way of accessing the AddrBook per height +type AddrBookProvider func(height uint64) (AddrBook, error) From 10a1bb6ec60368acc18fe5a7c2c93f4493b0df74 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 5 Dec 2022 01:23:47 +0000 Subject: [PATCH 016/143] test(P2P): fix tests --- p2p/module_raintree_test.go | 3 ++- p2p/utils_test.go | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/p2p/module_raintree_test.go b/p2p/module_raintree_test.go index 349dbe315..dcf2ca70d 100644 --- a/p2p/module_raintree_test.go +++ b/p2p/module_raintree_test.go @@ -225,8 +225,9 @@ func testRainTreeCalls(t *testing.T, origNode string, networkSimulationConfig Te wg.Add(expectedCall.numNetworkWrites) consensusMock := prepareConsensusMock(t, runtimeConfigs[0].GetGenesis()) + persistenceMock := preparePersistenceMock(t, runtimeConfigs[0].GetGenesis()) telemetryMock := prepareTelemetryMock(t, &wg, expectedCall.numNetworkWrites) - busMocks[valId] = prepareBusMock(t, consensusMock, telemetryMock) + busMocks[valId] = prepareBusMock(t, consensusMock, persistenceMock, telemetryMock) } // Inject the connection and bus mocks into the P2P modules diff --git a/p2p/utils_test.go b/p2p/utils_test.go index 033601ad0..3e662d433 100644 --- a/p2p/utils_test.go +++ b/p2p/utils_test.go @@ -165,13 +165,19 @@ func createMockGenesisState(t *testing.T, valKeys []cryptoPocket.PrivateKey) mod } // Bus Mock - needed to return the appropriate modules when accessed -func prepareBusMock(t *testing.T, consensusMock *modulesMock.MockConsensusModule, telemetryMock *modulesMock.MockTelemetryModule) *modulesMock.MockBus { +func prepareBusMock(t *testing.T, + consensusMock *modulesMock.MockConsensusModule, + persistenceMock *modulesMock.MockPersistenceModule, + telemetryMock *modulesMock.MockTelemetryModule, +) *modulesMock.MockBus { ctrl := gomock.NewController(t) busMock := modulesMock.NewMockBus(ctrl) busMock.EXPECT().PublishEventToBus(gomock.Any()).AnyTimes() busMock.EXPECT().GetConsensusModule().Return(consensusMock).AnyTimes() + busMock.EXPECT().GetPersistenceModule().Return(persistenceMock).AnyTimes() busMock.EXPECT().GetTelemetryModule().Return(telemetryMock).AnyTimes() + busMock.EXPECT().GetPersistenceModule().Return(persistenceMock).AnyTimes() return busMock } @@ -193,6 +199,19 @@ func prepareConsensusMock(t *testing.T, genesisState modules.GenesisState) *modu return consensusMock } +// Persistence mock - only needed for validatorMap access +func preparePersistenceMock(t *testing.T, genesisState modules.GenesisState) *modulesMock.MockPersistenceModule { + ctrl := gomock.NewController(t) + + persistenceMock := modulesMock.NewMockPersistenceModule(ctrl) + readContextMock := modulesMock.NewMockPersistenceReadContext(ctrl) + + readContextMock.EXPECT().GetAllValidators(gomock.Any()).Return(genesisState.GetPersistenceGenesisState().GetVals(), nil).AnyTimes() + persistenceMock.EXPECT().NewReadContext(gomock.Any()).Return(readContextMock, nil).AnyTimes() + + return persistenceMock +} + // Telemetry mock - Needed to help with proper counts for number of expected network writes func prepareTelemetryMock(t *testing.T, wg *sync.WaitGroup, expectedNumNetworkWrites int) *modulesMock.MockTelemetryModule { ctrl := gomock.NewController(t) From 5a7c14ced97c3173eb0546a1850e9339a610da4d Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 5 Dec 2022 01:25:59 +0000 Subject: [PATCH 017/143] =?UTF-8?q?fix(P2P):=20fix=20client=20P2P.Start()?= =?UTF-8?q?=20=F0=9F=92=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- p2p/module.go | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/p2p/module.go b/p2p/module.go index 92e63001e..bbcb99aef 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -140,13 +140,31 @@ func (m *p2pModule) Start() error { telemetry.P2P_NODE_STARTED_TIMESERIES_METRIC_DESCRIPTION, ) - addrBook, err := ValidatorMapToAddrBook(m.p2pCfg, m.bus.GetConsensusModule().ValidatorMap()) + currentHeight := m.bus.GetConsensusModule().CurrentHeight() + var ( + addrBook typesP2P.AddrBook + err error + ) + + if m.GetBus().GetPersistenceModule() == nil { + // we are getting called by the client and we use the "legacy behaviour" + // TODO (team): improve this. + addrBook, err = ValidatorMapToAddrBook(m.p2pCfg, m.bus.GetConsensusModule().ValidatorMap()) + } else { + addrBook, err = m.getAddrBookPerHeight(currentHeight) + } if err != nil { return err } if m.p2pCfg.GetUseRainTree() { - m.network = raintree.NewRainTreeNetwork(m.address, addrBook) + if m.GetBus().GetPersistenceModule() == nil { + // we are getting called by the client and we use the "legacy behaviour" + // TODO (team): improve this. + m.network = raintree.NewRainTreeNetwork(m.address, addrBook) + } else { + m.network = raintree.NewRainTreeNetworkWithAddrBookProvider(m.address, m.getAddrBookPerHeight, currentHeight) + } } else { m.network = stdnetwork.NewNetwork(addrBook) } @@ -171,6 +189,26 @@ func (m *p2pModule) Start() error { return nil } +func (m *p2pModule) getAddrBookPerHeight(height uint64) (typesP2P.AddrBook, error) { + persistenceReadContext, err := m.bus.GetPersistenceModule().NewReadContext(int64(height)) + if err != nil { + return nil, err + } + vals, err := persistenceReadContext.GetAllValidators(int64(height)) + if err != nil { + return nil, err + } + validatorMap := make(modules.ValidatorMap, len(vals)) + for _, v := range vals { + validatorMap[v.GetAddress()] = v + } + addrBook, err := ValidatorMapToAddrBook(m.p2pCfg, validatorMap) + if err != nil { + return nil, err + } + return addrBook, nil +} + func (m *p2pModule) Stop() error { log.Println("Stopping network module") if err := m.listener.Close(); err != nil { From f3df734351ac0b9f0027accb49461c7aed43c67c Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 5 Dec 2022 16:44:37 +0000 Subject: [PATCH 018/143] feat(Consensus): leader election gets validators from persistence --- consensus/leader_election/module.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/consensus/leader_election/module.go b/consensus/leader_election/module.go index f5f5d4c6e..ff305671b 100644 --- a/consensus/leader_election/module.go +++ b/consensus/leader_election/module.go @@ -60,5 +60,14 @@ func (m *leaderElectionModule) ElectNextLeader(message *typesCons.HotstuffMessag func (m *leaderElectionModule) electNextLeaderDeterministicRoundRobin(message *typesCons.HotstuffMessage) typesCons.NodeId { value := int64(message.Height) + int64(message.Round) + int64(message.Step) - 1 - return typesCons.NodeId(value%int64(len(m.GetBus().GetConsensusModule().ValidatorMap())) + 1) + + ctx, err := m.GetBus().GetPersistenceModule().NewReadContext(int64(message.Height)) + if err != nil { + log.Fatal(err) + } + vals, err := ctx.GetAllValidators(int64(message.Height)) + if err != nil { + log.Fatal(err) + } + return typesCons.NodeId(value%int64(len(vals)) + 1) } From 1e14b353c7c78c93448fb3b838bba38e7447c292 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 5 Dec 2022 16:46:11 +0000 Subject: [PATCH 019/143] refactor(P2P): renamed ValidatorToXXXX to ActorToXXXX --- p2p/module.go | 4 ++-- p2p/utils.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/p2p/module.go b/p2p/module.go index bbcb99aef..811d3c54f 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -149,7 +149,7 @@ func (m *p2pModule) Start() error { if m.GetBus().GetPersistenceModule() == nil { // we are getting called by the client and we use the "legacy behaviour" // TODO (team): improve this. - addrBook, err = ValidatorMapToAddrBook(m.p2pCfg, m.bus.GetConsensusModule().ValidatorMap()) + addrBook, err = ActorToAddrBook(m.p2pCfg, m.bus.GetConsensusModule().ValidatorMap()) } else { addrBook, err = m.getAddrBookPerHeight(currentHeight) } @@ -202,7 +202,7 @@ func (m *p2pModule) getAddrBookPerHeight(height uint64) (typesP2P.AddrBook, erro for _, v := range vals { validatorMap[v.GetAddress()] = v } - addrBook, err := ValidatorMapToAddrBook(m.p2pCfg, validatorMap) + addrBook, err := ActorToAddrBook(m.p2pCfg, validatorMap) if err != nil { return nil, err } diff --git a/p2p/utils.go b/p2p/utils.go index 149e1282d..2e92afddc 100644 --- a/p2p/utils.go +++ b/p2p/utils.go @@ -11,10 +11,10 @@ import ( // CLEANUP(drewsky): These functions will turn into more of a "ActorToAddrBook" when we have a closer // integration with utility. -func ValidatorMapToAddrBook(cfg modules.P2PConfig, validators map[string]modules.Actor) (typesP2P.AddrBook, error) { +func ActorToAddrBook(cfg modules.P2PConfig, validators map[string]modules.Actor) (typesP2P.AddrBook, error) { book := make(typesP2P.AddrBook, 0) for _, v := range validators { - networkPeer, err := ValidatorToNetworkPeer(cfg, v) + networkPeer, err := ActorToNetworkPeer(cfg, v) if err != nil { log.Println("[WARN] Error connecting to validator: ", err) continue @@ -26,7 +26,7 @@ func ValidatorMapToAddrBook(cfg modules.P2PConfig, validators map[string]modules // CLEANUP(drewsky): These functions will turn into more of a "ActorToAddrBook" when we have a closer // integration with utility. -func ValidatorToNetworkPeer(cfg modules.P2PConfig, v modules.Actor) (*typesP2P.NetworkPeer, error) { +func ActorToNetworkPeer(cfg modules.P2PConfig, v modules.Actor) (*typesP2P.NetworkPeer, error) { conn, err := CreateDialer(cfg, v.GetGenericParam()) // service url if err != nil { return nil, fmt.Errorf("error resolving addr: %v", err) From 3e5dd5913e281d76d554b52881f677f78fecd53c Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 5 Dec 2022 16:46:38 +0000 Subject: [PATCH 020/143] test(Consensus): fixed tests (mock config due to changed flow) --- consensus/consensus_tests/utils_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/consensus/consensus_tests/utils_test.go b/consensus/consensus_tests/utils_test.go index 3e2f012e4..4c0fda6d3 100644 --- a/consensus/consensus_tests/utils_test.go +++ b/consensus/consensus_tests/utils_test.go @@ -304,17 +304,22 @@ func basePersistenceMock(t *testing.T, _ modules.EventsChannel) *modulesMock.Moc ctrl := gomock.NewController(t) persistenceMock := modulesMock.NewMockPersistenceModule(ctrl) persistenceContextMock := modulesMock.NewMockPersistenceRWContext(ctrl) + persistenceReadContextMock := modulesMock.NewMockPersistenceReadContext(ctrl) persistenceMock.EXPECT().Start().Return(nil).AnyTimes() persistenceMock.EXPECT().SetBus(gomock.Any()).Return().AnyTimes() - persistenceMock.EXPECT().NewReadContext(int64(-1)).Return(persistenceContextMock, nil).AnyTimes() + persistenceMock.EXPECT().NewReadContext(gomock.Any()).Return(persistenceReadContextMock, nil).AnyTimes() persistenceMock.EXPECT().ReleaseWriteContext().Return(nil).AnyTimes() // The persistence context should usually be accessed via the utility module within the context // of the consensus module. This one is only used when loading the initial consensus module // state; hence the `-1` expectation in the call above. persistenceContextMock.EXPECT().Close().Return(nil).AnyTimes() - persistenceContextMock.EXPECT().GetLatestBlockHeight().Return(uint64(0), nil).AnyTimes() + persistenceReadContextMock.EXPECT().GetLatestBlockHeight().Return(uint64(0), nil).AnyTimes() + + // here we are mocking 4 actors since we are considering the 4 nodes in the LocalNet genesis + persistenceReadContextMock.EXPECT().GetAllValidators(gomock.Any()).Return([]modules.Actor{&modulesMock.MockActor{}, &modulesMock.MockActor{}, &modulesMock.MockActor{}, &modulesMock.MockActor{}}, nil).AnyTimes() + persistenceReadContextMock.EXPECT().Close().Return(nil).AnyTimes() return persistenceMock } From ec77c338ae42d5ae86b2565bfda39fa513fe14d0 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 5 Dec 2022 16:52:57 +0000 Subject: [PATCH 021/143] docs(Consensus): changelog --- consensus/doc/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/consensus/doc/CHANGELOG.md b/consensus/doc/CHANGELOG.md index e35c2c5db..198406b1c 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.12] - 2022-12-05 + +- `LeaderElectionModule`'s `electNextLeaderDeterministicRoundRobin` now uses `Persistence` to access the list of validators instead of the static `ValidatorMap`. + ## [0.0.0.11] - 2022-12-04 - The `Pacemaker` now emits `BeforeHeightChangedEvent` events when the height is about to change. From 8e2866e8f01cd1509d3177fcd0971bb266d80e28 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 5 Dec 2022 16:54:46 +0000 Subject: [PATCH 022/143] docs(P2P): changelog --- p2p/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/p2p/CHANGELOG.md b/p2p/CHANGELOG.md index eebc7b4f8..88c66eebc 100644 --- a/p2p/CHANGELOG.md +++ b/p2p/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.0.0.10] - 2022-12-05 + +- `ValidatorMapToAddrBook` renamed to `ActorToAddrBook` +- `ValidatorToNetworkPeer` renamed to `ActorToNetworkPeer` + ## [0.0.0.9] - 2022-12-04 - Raintree mempool cannot grow unbounded anymore. It's now bounded by a constant limit and when new nonces are inserted the oldest ones are removed. From f54875fb40031acff1d759c9ca3b4cbda4ea95e7 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 5 Dec 2022 17:04:31 +0000 Subject: [PATCH 023/143] chore(P2P): remove TECHDEBT TODOes --- p2p/utils.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/p2p/utils.go b/p2p/utils.go index 2e92afddc..12acf3d62 100644 --- a/p2p/utils.go +++ b/p2p/utils.go @@ -9,8 +9,6 @@ import ( "github.com/pokt-network/pocket/shared/modules" ) -// CLEANUP(drewsky): These functions will turn into more of a "ActorToAddrBook" when we have a closer -// integration with utility. func ActorToAddrBook(cfg modules.P2PConfig, validators map[string]modules.Actor) (typesP2P.AddrBook, error) { book := make(typesP2P.AddrBook, 0) for _, v := range validators { @@ -24,8 +22,6 @@ func ActorToAddrBook(cfg modules.P2PConfig, validators map[string]modules.Actor) return book, nil } -// CLEANUP(drewsky): These functions will turn into more of a "ActorToAddrBook" when we have a closer -// integration with utility. func ActorToNetworkPeer(cfg modules.P2PConfig, v modules.Actor) (*typesP2P.NetworkPeer, error) { conn, err := CreateDialer(cfg, v.GetGenericParam()) // service url if err != nil { From 8e5b367756ddd397e9cd2cedeccf75475875fe99 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 5 Dec 2022 16:44:37 +0000 Subject: [PATCH 024/143] feat(Consensus): leader election gets validators from persistence --- consensus/leader_election/module.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/consensus/leader_election/module.go b/consensus/leader_election/module.go index f5f5d4c6e..ff305671b 100644 --- a/consensus/leader_election/module.go +++ b/consensus/leader_election/module.go @@ -60,5 +60,14 @@ func (m *leaderElectionModule) ElectNextLeader(message *typesCons.HotstuffMessag func (m *leaderElectionModule) electNextLeaderDeterministicRoundRobin(message *typesCons.HotstuffMessage) typesCons.NodeId { value := int64(message.Height) + int64(message.Round) + int64(message.Step) - 1 - return typesCons.NodeId(value%int64(len(m.GetBus().GetConsensusModule().ValidatorMap())) + 1) + + ctx, err := m.GetBus().GetPersistenceModule().NewReadContext(int64(message.Height)) + if err != nil { + log.Fatal(err) + } + vals, err := ctx.GetAllValidators(int64(message.Height)) + if err != nil { + log.Fatal(err) + } + return typesCons.NodeId(value%int64(len(vals)) + 1) } From 47540f6e04d1322ab4f3386184eb3fda2050ec41 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 5 Dec 2022 16:46:38 +0000 Subject: [PATCH 025/143] test(Consensus): fixed tests (mock config due to changed flow) --- consensus/consensus_tests/utils_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/consensus/consensus_tests/utils_test.go b/consensus/consensus_tests/utils_test.go index 3e2f012e4..4c0fda6d3 100644 --- a/consensus/consensus_tests/utils_test.go +++ b/consensus/consensus_tests/utils_test.go @@ -304,17 +304,22 @@ func basePersistenceMock(t *testing.T, _ modules.EventsChannel) *modulesMock.Moc ctrl := gomock.NewController(t) persistenceMock := modulesMock.NewMockPersistenceModule(ctrl) persistenceContextMock := modulesMock.NewMockPersistenceRWContext(ctrl) + persistenceReadContextMock := modulesMock.NewMockPersistenceReadContext(ctrl) persistenceMock.EXPECT().Start().Return(nil).AnyTimes() persistenceMock.EXPECT().SetBus(gomock.Any()).Return().AnyTimes() - persistenceMock.EXPECT().NewReadContext(int64(-1)).Return(persistenceContextMock, nil).AnyTimes() + persistenceMock.EXPECT().NewReadContext(gomock.Any()).Return(persistenceReadContextMock, nil).AnyTimes() persistenceMock.EXPECT().ReleaseWriteContext().Return(nil).AnyTimes() // The persistence context should usually be accessed via the utility module within the context // of the consensus module. This one is only used when loading the initial consensus module // state; hence the `-1` expectation in the call above. persistenceContextMock.EXPECT().Close().Return(nil).AnyTimes() - persistenceContextMock.EXPECT().GetLatestBlockHeight().Return(uint64(0), nil).AnyTimes() + persistenceReadContextMock.EXPECT().GetLatestBlockHeight().Return(uint64(0), nil).AnyTimes() + + // here we are mocking 4 actors since we are considering the 4 nodes in the LocalNet genesis + persistenceReadContextMock.EXPECT().GetAllValidators(gomock.Any()).Return([]modules.Actor{&modulesMock.MockActor{}, &modulesMock.MockActor{}, &modulesMock.MockActor{}, &modulesMock.MockActor{}}, nil).AnyTimes() + persistenceReadContextMock.EXPECT().Close().Return(nil).AnyTimes() return persistenceMock } From dbb24d5918291dc28c8921bc2045de15180bc2e9 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 6 Dec 2022 21:58:05 +0000 Subject: [PATCH 026/143] test(messaging): contentType tests --- shared/messaging/messages_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/shared/messaging/messages_test.go b/shared/messaging/messages_test.go index dc2dbf923..2faec54ed 100644 --- a/shared/messaging/messages_test.go +++ b/shared/messaging/messages_test.go @@ -28,6 +28,18 @@ func TestPocketEnvelope_GetContentType(t *testing.T) { msg: &typesCons.HotstuffMessage{}, wantContentType: consensus.HotstuffMessageContentType, }, + { + msg: &messaging.BeforeHeightChangedEvent{}, + wantContentType: messaging.BeforeHeightChangedEventType, + }, + { + msg: &messaging.HeightChangedEvent{}, + wantContentType: messaging.HeightChangedEventType, + }, + { + msg: &messaging.AddressBookAtHeight{}, + wantContentType: messaging.AddressBookAtHeightEventType, + }, } for _, tt := range tests { t.Run(fmt.Sprintf("GetContentType %T", tt.msg), func(t *testing.T) { From 09aa018a911b87a3259f2921d7ee90e77bff6a63 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 7 Dec 2022 10:55:14 +0000 Subject: [PATCH 027/143] test(consensus): consolidated numValidators and mocks mgmt --- consensus/consensus_tests/hotstuff_test.go | 13 ++++++------- consensus/consensus_tests/pacemaker_test.go | 16 +++++++--------- consensus/consensus_tests/utils_test.go | 9 +++++++-- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/consensus/consensus_tests/hotstuff_test.go b/consensus/consensus_tests/hotstuff_test.go index 8ac97b4e6..12a8861b6 100644 --- a/consensus/consensus_tests/hotstuff_test.go +++ b/consensus/consensus_tests/hotstuff_test.go @@ -15,8 +15,7 @@ import ( func TestHotstuff4Nodes1BlockHappyPath(t *testing.T) { clockMock := clock.NewMock() // Test configs - numNodes := 4 - runtimeMgrs := GenerateNodeRuntimeMgrs(t, numNodes, clockMock) + runtimeMgrs := GenerateNodeRuntimeMgrs(t, numValidators, clockMock) go timeReminder(clockMock, 100*time.Millisecond) @@ -33,7 +32,7 @@ func TestHotstuff4Nodes1BlockHappyPath(t *testing.T) { advanceTime(clockMock, 10*time.Millisecond) // NewRound - newRoundMessages, err := WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.NewRound, consensus.Propose, numNodes, 1000) + newRoundMessages, err := WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.NewRound, consensus.Propose, numValidators, 1000) require.NoError(t, err) for nodeId, pocketNode := range pocketNodes { nodeState := GetConsensusNodeState(pocketNode) @@ -78,7 +77,7 @@ func TestHotstuff4Nodes1BlockHappyPath(t *testing.T) { advanceTime(clockMock, 10*time.Millisecond) // Precommit - prepareVotes, err := WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.Prepare, consensus.Vote, numNodes, 1000) + prepareVotes, err := WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.Prepare, consensus.Vote, numValidators, 1000) require.NoError(t, err) for _, vote := range prepareVotes { P2PSend(t, leader, vote) @@ -106,7 +105,7 @@ func TestHotstuff4Nodes1BlockHappyPath(t *testing.T) { advanceTime(clockMock, 10*time.Millisecond) // Commit - preCommitVotes, err := WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.PreCommit, consensus.Vote, numNodes, 1000) + preCommitVotes, err := WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.PreCommit, consensus.Vote, numValidators, 1000) require.NoError(t, err) for _, vote := range preCommitVotes { P2PSend(t, leader, vote) @@ -134,7 +133,7 @@ func TestHotstuff4Nodes1BlockHappyPath(t *testing.T) { advanceTime(clockMock, 10*time.Millisecond) // Decide - commitVotes, err := WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.Commit, consensus.Vote, numNodes, 1000) + commitVotes, err := WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.Commit, consensus.Vote, numValidators, 1000) require.NoError(t, err) for _, vote := range commitVotes { P2PSend(t, leader, vote) @@ -174,7 +173,7 @@ func TestHotstuff4Nodes1BlockHappyPath(t *testing.T) { advanceTime(clockMock, 10*time.Millisecond) // Block has been committed and new round has begun - _, err = WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.NewRound, consensus.Propose, numNodes, 1000) + _, err = WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.NewRound, consensus.Propose, numValidators, 1000) require.NoError(t, err) for pocketId, pocketNode := range pocketNodes { nodeState := GetConsensusNodeState(pocketNode) diff --git a/consensus/consensus_tests/pacemaker_test.go b/consensus/consensus_tests/pacemaker_test.go index 109ad2acf..38756ae08 100644 --- a/consensus/consensus_tests/pacemaker_test.go +++ b/consensus/consensus_tests/pacemaker_test.go @@ -22,10 +22,9 @@ func TestTinyPacemakerTimeouts(t *testing.T) { timeReminder(clockMock, 100*time.Millisecond) // Test configs - numNodes := 4 paceMakerTimeoutMsec := uint64(50) // Set a very small pacemaker timeout paceMakerTimeout := 50 * time.Millisecond - runtimeMgrs := GenerateNodeRuntimeMgrs(t, numNodes, clockMock) + runtimeMgrs := GenerateNodeRuntimeMgrs(t, numValidators, clockMock) for _, runtimeConfig := range runtimeMgrs { if consCfg, ok := runtimeConfig.GetConfig().GetConsensusConfig().(consensus.HasPacemakerConfig); ok { consCfg.GetPacemakerConfig().SetTimeoutMsec(paceMakerTimeoutMsec) @@ -46,7 +45,7 @@ func TestTinyPacemakerTimeouts(t *testing.T) { advanceTime(clockMock, 10*time.Millisecond) // paceMakerTimeout - _, err := WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.NewRound, consensus.Propose, numNodes, 500) + _, err := WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.NewRound, consensus.Propose, numValidators, 500) require.NoError(t, err) for pocketId, pocketNode := range pocketNodes { assertNodeConsensusView(t, pocketId, @@ -61,7 +60,7 @@ func TestTinyPacemakerTimeouts(t *testing.T) { forcePacemakerTimeout(clockMock, paceMakerTimeout) // Check that a new round starts at the same height. - _, err = WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.NewRound, consensus.Propose, numNodes, 500) + _, err = WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.NewRound, consensus.Propose, numValidators, 500) require.NoError(t, err) for pocketId, pocketNode := range pocketNodes { assertNodeConsensusView(t, pocketId, @@ -75,7 +74,7 @@ func TestTinyPacemakerTimeouts(t *testing.T) { forcePacemakerTimeout(clockMock, paceMakerTimeout) // // Check that a new round starts at the same height - _, err = WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.NewRound, consensus.Propose, numNodes, 500) + _, err = WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.NewRound, consensus.Propose, numValidators, 500) require.NoError(t, err) for pocketId, pocketNode := range pocketNodes { assertNodeConsensusView(t, pocketId, @@ -90,7 +89,7 @@ func TestTinyPacemakerTimeouts(t *testing.T) { forcePacemakerTimeout(clockMock, paceMakerTimeout) // Check that a new round starts at the same height. - newRoundMessages, err := WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.NewRound, consensus.Propose, numNodes, 500) + newRoundMessages, err := WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.NewRound, consensus.Propose, numValidators, 500) require.NoError(t, err) for pocketId, pocketNode := range pocketNodes { assertNodeConsensusView(t, pocketId, @@ -126,8 +125,7 @@ func TestTinyPacemakerTimeouts(t *testing.T) { func TestPacemakerCatchupSameStepDifferentRounds(t *testing.T) { clockMock := clock.NewMock() - numNodes := 4 - runtimeConfigs := GenerateNodeRuntimeMgrs(t, numNodes, clockMock) + runtimeConfigs := GenerateNodeRuntimeMgrs(t, numValidators, clockMock) timeReminder(clockMock, 100*time.Millisecond) @@ -200,7 +198,7 @@ func TestPacemakerCatchupSameStepDifferentRounds(t *testing.T) { P2PBroadcast(t, pocketNodes, anyMsg) // numNodes-1 because one of the messages is a self-proposal that is not passed through the network - _, err = WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.Prepare, consensus.Vote, numNodes-1, 2000) + _, err = WaitForNetworkConsensusMessages(t, clockMock, testChannel, consensus.Prepare, consensus.Vote, numValidators-1, 2000) require.NoError(t, err) forcePacemakerTimeout(clockMock, 600*time.Millisecond) diff --git a/consensus/consensus_tests/utils_test.go b/consensus/consensus_tests/utils_test.go index 4c0fda6d3..6f77a4183 100644 --- a/consensus/consensus_tests/utils_test.go +++ b/consensus/consensus_tests/utils_test.go @@ -45,6 +45,8 @@ var maxTxBytes = 90000 var emptyByzValidators = make([][]byte, 0) var emptyTxs = make([][]byte, 0) +const numValidators = 4 + // Initialize certain unit test configurations on startup. func init() { flag.BoolVar(&failOnExtraMessages, "failOnExtraMessages", false, "Fail if unexpected additional messages are received") @@ -317,8 +319,11 @@ func basePersistenceMock(t *testing.T, _ modules.EventsChannel) *modulesMock.Moc persistenceContextMock.EXPECT().Close().Return(nil).AnyTimes() persistenceReadContextMock.EXPECT().GetLatestBlockHeight().Return(uint64(0), nil).AnyTimes() - // here we are mocking 4 actors since we are considering the 4 nodes in the LocalNet genesis - persistenceReadContextMock.EXPECT().GetAllValidators(gomock.Any()).Return([]modules.Actor{&modulesMock.MockActor{}, &modulesMock.MockActor{}, &modulesMock.MockActor{}, &modulesMock.MockActor{}}, nil).AnyTimes() + mockValidators := make([]modules.Actor, numValidators) + for i := 0; i < numValidators; i++ { + mockValidators[i] = &modulesMock.MockActor{} + } + persistenceReadContextMock.EXPECT().GetAllValidators(gomock.Any()).Return(mockValidators, nil).AnyTimes() persistenceReadContextMock.EXPECT().Close().Return(nil).AnyTimes() return persistenceMock From f77334595922520d36c641db8cee354659111b25 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 7 Dec 2022 10:58:27 +0000 Subject: [PATCH 028/143] fix(pacemaker): logging packing errors if any --- consensus/pacemaker.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/consensus/pacemaker.go b/consensus/pacemaker.go index 198b3510e..25b5308f4 100644 --- a/consensus/pacemaker.go +++ b/consensus/pacemaker.go @@ -269,11 +269,17 @@ func (p *paceMaker) getStepTimeout(round uint64) timePkg.Duration { } func (p *paceMaker) onBeforeNewHeight() { - event, _ := messaging.PackMessage(&messaging.BeforeHeightChangedEvent{CurrentHeight: p.consensusMod.CurrentHeight()}) + event, err := messaging.PackMessage(&messaging.BeforeHeightChangedEvent{CurrentHeight: p.consensusMod.CurrentHeight()}) + if err != nil { + log.Printf("[WARN] error packing message: %v\n", err) + } p.GetBus().PublishEventToBus(event) } func (p *paceMaker) onAfterNewHeight() { - event, _ := messaging.PackMessage(&messaging.HeightChangedEvent{NewHeight: p.consensusMod.CurrentHeight()}) + event, err := messaging.PackMessage(&messaging.HeightChangedEvent{NewHeight: p.consensusMod.CurrentHeight()}) + if err != nil { + log.Printf("[WARN] error packing message: %v\n", err) + } p.GetBus().PublishEventToBus(event) } From ea0b2a7eb408e6644985d5ed702d670e01c945be Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 7 Dec 2022 11:49:31 +0000 Subject: [PATCH 029/143] refactor(P2P): nonceSet, nonceList --- p2p/module.go | 1 - p2p/raintree/network.go | 25 +++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/p2p/module.go b/p2p/module.go index bbcb99aef..ab480ca20 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -46,7 +46,6 @@ func (m *p2pModule) HandleEvent(message *anypb.Any) error { } m.broadcastAddressBookAtHeight(event.CurrentHeight) - default: return typesP2P.ErrUnknownEventType(message.MessageName()) } diff --git a/p2p/raintree/network.go b/p2p/raintree/network.go index 305f7b38e..fd38d552c 100644 --- a/p2p/raintree/network.go +++ b/p2p/raintree/network.go @@ -29,8 +29,9 @@ type rainTreeNetwork struct { peersManager *peersManager // TODO (#278): What should we use for de-duping messages within P2P? - mempool map[uint64]struct{} - mempool_keys []uint64 + // TODO (team): we should generalize and use the FIFOMempool (in utility/types/mempool.go at the time of writing) in here as well for this. Same concept + nonceSet map[uint64]struct{} + nonceList []uint64 } func NewRainTreeNetwork(addr cryptoPocket.Address, addrBook typesP2P.AddrBook) typesP2P.Network { @@ -42,8 +43,8 @@ func NewRainTreeNetwork(addr cryptoPocket.Address, addrBook typesP2P.AddrBook) t n := &rainTreeNetwork{ selfAddr: addr, peersManager: pm, - mempool: make(map[uint64]struct{}), - mempool_keys: make([]uint64, 0, mempoolMaxNonces), + nonceSet: make(map[uint64]struct{}), + nonceList: make([]uint64, 0, mempoolMaxNonces), } return typesP2P.Network(n) @@ -64,8 +65,8 @@ func NewRainTreeNetworkWithAddrBookProvider(addr cryptoPocket.Address, addrBookP selfAddr: addr, addrBookProvider: addrBookProvider, peersManager: pm, - mempool: make(map[uint64]struct{}), - mempool_keys: make([]uint64, 0, mempoolMaxNonces), + nonceSet: make(map[uint64]struct{}), + nonceList: make([]uint64, 0, mempoolMaxNonces), } return typesP2P.Network(n) @@ -191,7 +192,7 @@ func (n *rainTreeNetwork) HandleNetworkData(data []byte) ([]byte, error) { // Avoids this node from processing a messages / transactions is has already processed at the // application layer. The logic above makes sure it is only propagated and returns. // DISCUSS(#278): Add more tests to verify this is sufficient for deduping purposes. - if _, contains := n.mempool[rainTreeMsg.Nonce]; contains { + if _, contains := n.nonceSet[rainTreeMsg.Nonce]; contains { n.GetBus(). GetTelemetryModule(). GetEventMetricsAgent(). @@ -205,12 +206,12 @@ func (n *rainTreeNetwork) HandleNetworkData(data []byte) ([]byte, error) { return nil, nil } - n.mempool[rainTreeMsg.Nonce] = struct{}{} - n.mempool_keys = append(n.mempool_keys, rainTreeMsg.Nonce) - if len(n.mempool_keys) > mempoolMaxNonces { + n.nonceSet[rainTreeMsg.Nonce] = struct{}{} + n.nonceList = append(n.nonceList, rainTreeMsg.Nonce) + if len(n.nonceList) > mempoolMaxNonces { // removing the oldest nonce and the oldest key from the slice - delete(n.mempool, n.mempool_keys[0]) - n.mempool_keys = n.mempool_keys[1:] + delete(n.nonceSet, n.nonceList[0]) + n.nonceList = n.nonceList[1:] } // Return the data back to the caller so it can be handled by the app specific bus From 359648a44ba06ec139d2155fc830ddc6ede035c6 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 7 Dec 2022 16:23:06 +0000 Subject: [PATCH 030/143] Revert "feat(Consensus): leader election gets validators from persistence" This reverts commit 8e5b367756ddd397e9cd2cedeccf75475875fe99. --- consensus/leader_election/module.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/consensus/leader_election/module.go b/consensus/leader_election/module.go index ff305671b..f5f5d4c6e 100644 --- a/consensus/leader_election/module.go +++ b/consensus/leader_election/module.go @@ -60,14 +60,5 @@ func (m *leaderElectionModule) ElectNextLeader(message *typesCons.HotstuffMessag func (m *leaderElectionModule) electNextLeaderDeterministicRoundRobin(message *typesCons.HotstuffMessage) typesCons.NodeId { value := int64(message.Height) + int64(message.Round) + int64(message.Step) - 1 - - ctx, err := m.GetBus().GetPersistenceModule().NewReadContext(int64(message.Height)) - if err != nil { - log.Fatal(err) - } - vals, err := ctx.GetAllValidators(int64(message.Height)) - if err != nil { - log.Fatal(err) - } - return typesCons.NodeId(value%int64(len(vals)) + 1) + return typesCons.NodeId(value%int64(len(m.GetBus().GetConsensusModule().ValidatorMap())) + 1) } From 8e146a6bc794825bb9d622c06fbb22b56d3a4a6b Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 7 Dec 2022 16:25:01 +0000 Subject: [PATCH 031/143] Revert "test(Consensus): fixed tests (mock config due to changed flow)" This reverts commit 47540f6e04d1322ab4f3386184eb3fda2050ec41. Signed-off-by: Alessandro De Blasis --- consensus/consensus_tests/utils_test.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/consensus/consensus_tests/utils_test.go b/consensus/consensus_tests/utils_test.go index 6f77a4183..0570a87d0 100644 --- a/consensus/consensus_tests/utils_test.go +++ b/consensus/consensus_tests/utils_test.go @@ -306,25 +306,17 @@ func basePersistenceMock(t *testing.T, _ modules.EventsChannel) *modulesMock.Moc ctrl := gomock.NewController(t) persistenceMock := modulesMock.NewMockPersistenceModule(ctrl) persistenceContextMock := modulesMock.NewMockPersistenceRWContext(ctrl) - persistenceReadContextMock := modulesMock.NewMockPersistenceReadContext(ctrl) persistenceMock.EXPECT().Start().Return(nil).AnyTimes() persistenceMock.EXPECT().SetBus(gomock.Any()).Return().AnyTimes() - persistenceMock.EXPECT().NewReadContext(gomock.Any()).Return(persistenceReadContextMock, nil).AnyTimes() + persistenceMock.EXPECT().NewReadContext(int64(-1)).Return(persistenceContextMock, nil).AnyTimes() persistenceMock.EXPECT().ReleaseWriteContext().Return(nil).AnyTimes() // The persistence context should usually be accessed via the utility module within the context // of the consensus module. This one is only used when loading the initial consensus module // state; hence the `-1` expectation in the call above. persistenceContextMock.EXPECT().Close().Return(nil).AnyTimes() - persistenceReadContextMock.EXPECT().GetLatestBlockHeight().Return(uint64(0), nil).AnyTimes() - - mockValidators := make([]modules.Actor, numValidators) - for i := 0; i < numValidators; i++ { - mockValidators[i] = &modulesMock.MockActor{} - } - persistenceReadContextMock.EXPECT().GetAllValidators(gomock.Any()).Return(mockValidators, nil).AnyTimes() - persistenceReadContextMock.EXPECT().Close().Return(nil).AnyTimes() + persistenceContextMock.EXPECT().GetLatestBlockHeight().Return(uint64(0), nil).AnyTimes() return persistenceMock } From 5c3d93988f66168b6c75b6f7c0405640e471610e Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 7 Dec 2022 19:27:46 +0000 Subject: [PATCH 032/143] refactor(P2P): no need to broadcast changes to its addressBook --- p2p/module.go | 29 ++++--------------- shared/messaging/messages.go | 2 -- shared/messaging/messages_test.go | 4 --- .../proto/addressbook_at_height.proto | 16 ---------- shared/node.go | 7 ----- 5 files changed, 5 insertions(+), 53 deletions(-) delete mode 100644 shared/messaging/proto/addressbook_at_height.proto diff --git a/p2p/module.go b/p2p/module.go index ab480ca20..bc929fd42 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -40,40 +40,21 @@ func (m *p2pModule) HandleEvent(message *anypb.Any) error { if err != nil { return err } - event, ok := msg.(*messaging.BeforeHeightChangedEvent) + _, ok := msg.(*messaging.BeforeHeightChangedEvent) if !ok { return fmt.Errorf("failed to cast message to BeforeHeightChangedEvent") } - m.broadcastAddressBookAtHeight(event.CurrentHeight) + // DISCUSS (https://github.com/pokt-network/pocket/pull/374#issuecomment-1341350786): decide if we want a pull or push model for integrating with persistence + // I am leaving this code while we are in code-review as a placeholder but it will be either removed or implemented fully + // with P2P handling the message and adjusting the addrBook accordingly + default: return typesP2P.ErrUnknownEventType(message.MessageName()) } return nil } -// broadcastAddressBookAtHeight broadcasts on the event bus the address book at the given height -func (m *p2pModule) broadcastAddressBookAtHeight(height uint64) error { - addrBook := m.network.GetAddrBook() - networkPeers := make([]*messaging.NetworkPeer, len(addrBook)) - for i, peer := range addrBook { - networkPeers[i] = &messaging.NetworkPeer{ - Address: peer.Address, - PublicKey: peer.PublicKey.Bytes(), - ServiceUrl: peer.ServiceUrl, - } - } - message, err := messaging.PackMessage(&messaging.AddressBookAtHeight{ - NetworkPeers: networkPeers, - Height: height, - }) - if err != nil { - return err - } - m.GetBus().PublishEventToBus(message) - return nil -} - // TECHDEBT(drewsky): Discuss how to best expose/access `Address` throughout the codebase. func (m *p2pModule) GetAddress() (cryptoPocket.Address, error) { return m.address, nil diff --git a/shared/messaging/messages.go b/shared/messaging/messages.go index 20829ce2e..6dbdf89fd 100644 --- a/shared/messaging/messages.go +++ b/shared/messaging/messages.go @@ -4,8 +4,6 @@ import "strings" const ( DebugMessageEventType = "pocket.DebugMessage" - - AddressBookAtHeightEventType = "pocket.AddressBookAtHeight" ) func (envelope *PocketEnvelope) GetContentType() string { diff --git a/shared/messaging/messages_test.go b/shared/messaging/messages_test.go index 2faec54ed..a2501cf7e 100644 --- a/shared/messaging/messages_test.go +++ b/shared/messaging/messages_test.go @@ -36,10 +36,6 @@ func TestPocketEnvelope_GetContentType(t *testing.T) { msg: &messaging.HeightChangedEvent{}, wantContentType: messaging.HeightChangedEventType, }, - { - msg: &messaging.AddressBookAtHeight{}, - wantContentType: messaging.AddressBookAtHeightEventType, - }, } for _, tt := range tests { t.Run(fmt.Sprintf("GetContentType %T", tt.msg), func(t *testing.T) { diff --git a/shared/messaging/proto/addressbook_at_height.proto b/shared/messaging/proto/addressbook_at_height.proto deleted file mode 100644 index a843715c6..000000000 --- a/shared/messaging/proto/addressbook_at_height.proto +++ /dev/null @@ -1,16 +0,0 @@ -syntax = "proto3"; - -package pocket; - -option go_package = "github.com/pokt-network/pocket/shared/messaging"; - -message AddressBookAtHeight { - repeated NetworkPeer network_peers = 1; - uint64 height = 2; -} - -message NetworkPeer { - bytes public_key = 1; - bytes address = 2; - string service_url = 3; -} \ No newline at end of file diff --git a/shared/node.go b/shared/node.go index bdb9f482d..b06bb0c69 100644 --- a/shared/node.go +++ b/shared/node.go @@ -162,13 +162,6 @@ func (node *Node) handleEvent(message *messaging.PocketEnvelope) error { case messaging.BeforeHeightChangedEventType: log.Println("Received BeforeNewHeightEvent") node.GetBus().GetP2PModule().HandleEvent(message.Content) - case messaging.AddressBookAtHeightEventType: - log.Printf("Received AddressBookAtHeightEvent: %v\n", message.Content) - // DISCUSS (deblasis): here we'd delegate a module to handle the event. - // We need an open PersistenceRWContext where we can update the validator list (sounds like churn management). - // The recent changes (StateHash) made me question/revisit my initial implementation. - // Should the addressbook be considered separately from the "ValidatorMap" (currently)? - case messaging.HeightChangedEventType: log.Println("[NOOP] Received HeightChangedEventType") case consensus.HotstuffMessageContentType: From 266b47afe5f47d7433acea2a6c63936f8662fc01 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 8 Dec 2022 08:11:39 +0000 Subject: [PATCH 033/143] docs(P2P): updated changelog (removed AddressBookAtHeight) --- shared/CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/shared/CHANGELOG.md b/shared/CHANGELOG.md index a1d585513..87de6c332 100644 --- a/shared/CHANGELOG.md +++ b/shared/CHANGELOG.md @@ -9,7 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.0.0.5] - 2022-12-04 -- Added `AddressBookAtHeight` message used cross-module broadcast of the address book right before we reach a new Height. - Added `BeforeHeightChangedEvent` and `HeightChangedEvent` events that respectively signal the other modules that we are about to change the Height and that we have changed the Height. ## [0.0.0.4] - 2022-11-30 From 4ce80bc24b0cbad8a27df6d7468475626954defb Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 8 Dec 2022 08:48:06 +0000 Subject: [PATCH 034/143] feat(P2P): configurable mempool cap via P2PConfig --- p2p/CHANGELOG.md | 4 ++++ p2p/module.go | 4 ++-- p2p/raintree/network.go | 25 +++++++++++++------------ p2p/raintree/network_test.go | 16 ++++++++++++---- p2p/raintree/peers_manager_test.go | 18 +++++++++++++++--- p2p/types/proto/p2p_config.proto | 4 +++- runtime/defaults/defaults.go | 1 + shared/modules/types.go | 1 + 8 files changed, 51 insertions(+), 22 deletions(-) diff --git a/p2p/CHANGELOG.md b/p2p/CHANGELOG.md index eebc7b4f8..362a71015 100644 --- a/p2p/CHANGELOG.md +++ b/p2p/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.0.0.10] 2022-12-08 + +- mempool cap is now configurable via P2PConfig. Tests implement the mock accordingly. + ## [0.0.0.9] - 2022-12-04 - Raintree mempool cannot grow unbounded anymore. It's now bounded by a constant limit and when new nonces are inserted the oldest ones are removed. diff --git a/p2p/module.go b/p2p/module.go index bc929fd42..40a31d623 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -141,9 +141,9 @@ func (m *p2pModule) Start() error { if m.GetBus().GetPersistenceModule() == nil { // we are getting called by the client and we use the "legacy behaviour" // TODO (team): improve this. - m.network = raintree.NewRainTreeNetwork(m.address, addrBook) + m.network = raintree.NewRainTreeNetwork(m.address, addrBook, m.p2pCfg) } else { - m.network = raintree.NewRainTreeNetworkWithAddrBookProvider(m.address, m.getAddrBookPerHeight, currentHeight) + m.network = raintree.NewRainTreeNetworkWithAddrBookProvider(m.address, m.getAddrBookPerHeight, currentHeight, m.p2pCfg) } } else { m.network = stdnetwork.NewNetwork(addrBook) diff --git a/p2p/raintree/network.go b/p2p/raintree/network.go index fd38d552c..4ff9b90cc 100644 --- a/p2p/raintree/network.go +++ b/p2p/raintree/network.go @@ -18,8 +18,6 @@ import ( var _ typesP2P.Network = &rainTreeNetwork{} var _ modules.IntegratableModule = &rainTreeNetwork{} -const mempoolMaxNonces = 1e6 // 1 million rolling nonces. The oldest will be pruned in favor of the newest when this threshold is reached - type rainTreeNetwork struct { bus modules.Bus @@ -30,27 +28,30 @@ type rainTreeNetwork struct { // TODO (#278): What should we use for de-duping messages within P2P? // TODO (team): we should generalize and use the FIFOMempool (in utility/types/mempool.go at the time of writing) in here as well for this. Same concept - nonceSet map[uint64]struct{} - nonceList []uint64 + nonceSet map[uint64]struct{} + nonceList []uint64 + mampoolMaxNonces uint64 } -func NewRainTreeNetwork(addr cryptoPocket.Address, addrBook typesP2P.AddrBook) typesP2P.Network { +func NewRainTreeNetwork(addr cryptoPocket.Address, addrBook typesP2P.AddrBook, p2pCfg modules.P2PConfig) typesP2P.Network { pm, err := newPeersManager(addr, addrBook, true) if err != nil { log.Fatalf("[ERROR] Error initializing rainTreeNetwork peersManager: %v", err) } + mempoolMaxNonces := p2pCfg.GetMempoolMaxNonces() n := &rainTreeNetwork{ - selfAddr: addr, - peersManager: pm, - nonceSet: make(map[uint64]struct{}), - nonceList: make([]uint64, 0, mempoolMaxNonces), + selfAddr: addr, + peersManager: pm, + nonceSet: make(map[uint64]struct{}), + nonceList: make([]uint64, 0, mempoolMaxNonces), + mampoolMaxNonces: mempoolMaxNonces, } return typesP2P.Network(n) } -func NewRainTreeNetworkWithAddrBookProvider(addr cryptoPocket.Address, addrBookProvider typesP2P.AddrBookProvider, height uint64) typesP2P.Network { +func NewRainTreeNetworkWithAddrBookProvider(addr cryptoPocket.Address, addrBookProvider typesP2P.AddrBookProvider, height uint64, p2pCfg modules.P2PConfig) typesP2P.Network { addrBook, err := addrBookProvider(height) if err != nil { log.Fatalf("[ERROR] Error getting addrBook from addrBookProvider: %v", err) @@ -66,7 +67,7 @@ func NewRainTreeNetworkWithAddrBookProvider(addr cryptoPocket.Address, addrBookP addrBookProvider: addrBookProvider, peersManager: pm, nonceSet: make(map[uint64]struct{}), - nonceList: make([]uint64, 0, mempoolMaxNonces), + nonceList: make([]uint64, 0, p2pCfg.GetMempoolMaxNonces()), } return typesP2P.Network(n) @@ -208,7 +209,7 @@ func (n *rainTreeNetwork) HandleNetworkData(data []byte) ([]byte, error) { n.nonceSet[rainTreeMsg.Nonce] = struct{}{} n.nonceList = append(n.nonceList, rainTreeMsg.Nonce) - if len(n.nonceList) > mempoolMaxNonces { + if uint64(len(n.nonceList)) > n.mampoolMaxNonces { // removing the oldest nonce and the oldest key from the slice delete(n.nonceSet, n.nonceList[0]) n.nonceList = n.nonceList[1:] diff --git a/p2p/raintree/network_test.go b/p2p/raintree/network_test.go index 9c0c09df5..447ba48fb 100644 --- a/p2p/raintree/network_test.go +++ b/p2p/raintree/network_test.go @@ -3,13 +3,19 @@ package raintree import ( "testing" + "github.com/golang/mock/gomock" "github.com/pokt-network/pocket/p2p/types" typesP2P "github.com/pokt-network/pocket/p2p/types" + "github.com/pokt-network/pocket/runtime/defaults" cryptoPocket "github.com/pokt-network/pocket/shared/crypto" + mock_modules "github.com/pokt-network/pocket/shared/modules/mocks" "github.com/stretchr/testify/require" ) func TestRainTreeNetwork_AddPeerToAddrBook(t *testing.T) { + ctrl := gomock.NewController(t) + mockP2PCfg := mock_modules.NewMockP2PConfig(ctrl) + mockP2PCfg.EXPECT().GetMempoolMaxNonces().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() // starting with an empty address book and only self selfAddr, err := cryptoPocket.GenerateAddress() require.NoError(t, err) @@ -17,7 +23,7 @@ func TestRainTreeNetwork_AddPeerToAddrBook(t *testing.T) { addrBook := getAddrBook(nil, 0) addrBook = append(addrBook, &types.NetworkPeer{Address: selfAddr}) - network := NewRainTreeNetwork(selfAddr, addrBook).(*rainTreeNetwork) + network := NewRainTreeNetwork(selfAddr, addrBook, mockP2PCfg).(*rainTreeNetwork) peerAddr, err := cryptoPocket.GenerateAddress() require.NoError(t, err) @@ -40,16 +46,18 @@ func TestRainTreeNetwork_AddPeerToAddrBook(t *testing.T) { } func TestRainTreeNetwork_RemovePeerToAddrBook(t *testing.T) { + ctrl := gomock.NewController(t) + mockP2PCfg := mock_modules.NewMockP2PConfig(ctrl) + mockP2PCfg.EXPECT().GetMempoolMaxNonces().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() + // starting with an address book having only self and an arbitrary number of peers `numAddressesInAddressBook`` numAddressesInAddressBook := 3 addrBook := getAddrBook(nil, numAddressesInAddressBook) selfAddr, err := cryptoPocket.GenerateAddress() require.NoError(t, err) selfPeer := &typesP2P.NetworkPeer{Address: selfAddr} - addrBook = append(addrBook, &types.NetworkPeer{Address: selfAddr}) - network := NewRainTreeNetwork(selfAddr, addrBook).(*rainTreeNetwork) - + network := NewRainTreeNetwork(selfAddr, addrBook, mockP2PCfg).(*rainTreeNetwork) stateView := network.peersManager.getNetworkView() require.Equal(t, numAddressesInAddressBook+1, len(stateView.addrList)) // +1 to account for self in the addrBook as well diff --git a/p2p/raintree/peers_manager_test.go b/p2p/raintree/peers_manager_test.go index b836c16c8..c7892f3e3 100644 --- a/p2p/raintree/peers_manager_test.go +++ b/p2p/raintree/peers_manager_test.go @@ -8,8 +8,10 @@ import ( "github.com/golang/mock/gomock" "github.com/pokt-network/pocket/p2p/types" + "github.com/pokt-network/pocket/runtime/defaults" "github.com/pokt-network/pocket/shared/crypto" cryptoPocket "github.com/pokt-network/pocket/shared/crypto" + mock_modules "github.com/pokt-network/pocket/shared/modules/mocks" modulesMock "github.com/pokt-network/pocket/shared/modules/mocks" "github.com/stretchr/testify/require" ) @@ -36,6 +38,10 @@ type ExpectedRainTreeMessageProp struct { } func TestRainTreeAddrBookUtilsHandleUpdate(t *testing.T) { + ctrl := gomock.NewController(t) + mockP2PCfg := mock_modules.NewMockP2PConfig(ctrl) + mockP2PCfg.EXPECT().GetMempoolMaxNonces().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() + addr, err := cryptoPocket.GenerateAddress() require.NoError(t, err) @@ -73,7 +79,7 @@ func TestRainTreeAddrBookUtilsHandleUpdate(t *testing.T) { t.Run(fmt.Sprintf("n=%d", n), func(t *testing.T) { addrBook := getAddrBook(t, n-1) addrBook = append(addrBook, &types.NetworkPeer{Address: addr}) - network := NewRainTreeNetwork(addr, addrBook).(*rainTreeNetwork) + network := NewRainTreeNetwork(addr, addrBook, mockP2PCfg).(*rainTreeNetwork) peersManagerStateView := network.peersManager.getNetworkView() @@ -85,6 +91,10 @@ func TestRainTreeAddrBookUtilsHandleUpdate(t *testing.T) { } func BenchmarkAddrBookUpdates(b *testing.B) { + ctrl := gomock.NewController(gomock.TestReporter(b)) + mockP2PCfg := mock_modules.NewMockP2PConfig(ctrl) + mockP2PCfg.EXPECT().GetMempoolMaxNonces().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() + addr, err := cryptoPocket.GenerateAddress() require.NoError(b, err) @@ -107,7 +117,7 @@ func BenchmarkAddrBookUpdates(b *testing.B) { b.Run(fmt.Sprintf("n=%d", n), func(b *testing.B) { addrBook := getAddrBook(nil, n-1) addrBook = append(addrBook, &types.NetworkPeer{Address: addr}) - network := NewRainTreeNetwork(addr, addrBook).(*rainTreeNetwork) + network := NewRainTreeNetwork(addr, addrBook, mockP2PCfg).(*rainTreeNetwork) peersManagerStateView := network.peersManager.getNetworkView() @@ -190,9 +200,11 @@ func testRainTreeMessageTargets(t *testing.T, expectedMsgProp *ExpectedRainTreeM consensusMock := modulesMock.NewMockConsensusModule(ctrl) consensusMock.EXPECT().CurrentHeight().Return(uint64(1)).AnyTimes() busMock.EXPECT().GetConsensusModule().Return(consensusMock).AnyTimes() + mockP2PCfg := mock_modules.NewMockP2PConfig(ctrl) + mockP2PCfg.EXPECT().GetMempoolMaxNonces().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() addrBook := getAlphabetAddrBook(expectedMsgProp.numNodes) - network := NewRainTreeNetwork([]byte{expectedMsgProp.orig}, addrBook).(*rainTreeNetwork) + network := NewRainTreeNetwork([]byte{expectedMsgProp.orig}, addrBook, mockP2PCfg).(*rainTreeNetwork) network.SetBus(busMock) peersManagerStateView := network.peersManager.getNetworkView() diff --git a/p2p/types/proto/p2p_config.proto b/p2p/types/proto/p2p_config.proto index 5bb7d29be..b03d4647d 100644 --- a/p2p/types/proto/p2p_config.proto +++ b/p2p/types/proto/p2p_config.proto @@ -1,4 +1,5 @@ syntax = "proto3"; + package p2p; option go_package = "github.com/pokt-network/pocket/p2p/types"; @@ -8,9 +9,10 @@ message P2PConfig { uint32 consensus_port = 2; bool use_rain_tree = 3; bool is_empty_connection_type = 4; // TODO (Drewsky) switch back to enum + uint64 mempool_max_nonces = 5; // this is used to limit the number of nonces that can be stored in the mempool, after which a FIFO mechanism is used to remove the oldest nonces and make space for the new ones } enum ConnectionType { EmptyConnection = 0; TCPConnection = 1; -} \ No newline at end of file +} diff --git a/runtime/defaults/defaults.go b/runtime/defaults/defaults.go index ac9a00f5e..fef8661df 100644 --- a/runtime/defaults/defaults.go +++ b/runtime/defaults/defaults.go @@ -30,4 +30,5 @@ var ( DefaultRpcPort = defaultRPCPort DefaultRpcTimeout = uint64(defaultRPCTimeout) DefaultRemoteCLIURL = fmt.Sprintf("http://%s:%s", defaultRPCHost, defaultRPCPort) + DefaultP2PMempoolMaxNonces = uint64(1e6) ) diff --git a/shared/modules/types.go b/shared/modules/types.go index 1b9a4b909..348a929c9 100644 --- a/shared/modules/types.go +++ b/shared/modules/types.go @@ -55,6 +55,7 @@ type P2PConfig interface { GetConsensusPort() uint32 GetUseRainTree() bool GetIsEmptyConnectionType() bool // TODO : make enum + GetMempoolMaxNonces() uint64 } type TelemetryConfig interface { From 34c0e76de48d113f5c92044af8ebf9dc9ec60f91 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 8 Dec 2022 09:06:28 +0000 Subject: [PATCH 035/143] style(P2P): spacing --- p2p/raintree/network_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/p2p/raintree/network_test.go b/p2p/raintree/network_test.go index 447ba48fb..30d73667b 100644 --- a/p2p/raintree/network_test.go +++ b/p2p/raintree/network_test.go @@ -16,6 +16,7 @@ func TestRainTreeNetwork_AddPeerToAddrBook(t *testing.T) { ctrl := gomock.NewController(t) mockP2PCfg := mock_modules.NewMockP2PConfig(ctrl) mockP2PCfg.EXPECT().GetMempoolMaxNonces().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() + // starting with an empty address book and only self selfAddr, err := cryptoPocket.GenerateAddress() require.NoError(t, err) From 8880c17224a38d9c746258dbf22b1242a101d63a Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 8 Dec 2022 09:53:45 +0000 Subject: [PATCH 036/143] style(P2P): validators -> actors --- p2p/utils.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/p2p/utils.go b/p2p/utils.go index 12acf3d62..842413349 100644 --- a/p2p/utils.go +++ b/p2p/utils.go @@ -9,9 +9,9 @@ import ( "github.com/pokt-network/pocket/shared/modules" ) -func ActorToAddrBook(cfg modules.P2PConfig, validators map[string]modules.Actor) (typesP2P.AddrBook, error) { +func ActorToAddrBook(cfg modules.P2PConfig, actors map[string]modules.Actor) (typesP2P.AddrBook, error) { book := make(typesP2P.AddrBook, 0) - for _, v := range validators { + for _, v := range actors { networkPeer, err := ActorToNetworkPeer(cfg, v) if err != nil { log.Println("[WARN] Error connecting to validator: ", err) From dd3020e9343972561ad00cee123e65f86357b97a Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 8 Dec 2022 10:45:16 +0000 Subject: [PATCH 037/143] fix(consensus): electNextLeaderDeterministicRoundRobin ret err --- consensus/leader_election/module.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/consensus/leader_election/module.go b/consensus/leader_election/module.go index ff305671b..f7b3a2cf4 100644 --- a/consensus/leader_election/module.go +++ b/consensus/leader_election/module.go @@ -55,19 +55,23 @@ func (m *leaderElectionModule) GetBus() modules.Bus { } func (m *leaderElectionModule) ElectNextLeader(message *typesCons.HotstuffMessage) (typesCons.NodeId, error) { - return m.electNextLeaderDeterministicRoundRobin(message), nil + nodeId, err := m.electNextLeaderDeterministicRoundRobin(message) + if err != nil { + return typesCons.NodeId(0), err + } + return nodeId, nil } -func (m *leaderElectionModule) electNextLeaderDeterministicRoundRobin(message *typesCons.HotstuffMessage) typesCons.NodeId { +func (m *leaderElectionModule) electNextLeaderDeterministicRoundRobin(message *typesCons.HotstuffMessage) (typesCons.NodeId, error) { value := int64(message.Height) + int64(message.Round) + int64(message.Step) - 1 ctx, err := m.GetBus().GetPersistenceModule().NewReadContext(int64(message.Height)) if err != nil { - log.Fatal(err) + return typesCons.NodeId(0), err } vals, err := ctx.GetAllValidators(int64(message.Height)) if err != nil { - log.Fatal(err) + return typesCons.NodeId(0), err } - return typesCons.NodeId(value%int64(len(vals)) + 1) + return typesCons.NodeId(value%int64(len(vals)) + 1), nil } From 8f837201f2f2ec9132e72993bd98b1219cc2d88a Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Fri, 9 Dec 2022 23:33:26 +0000 Subject: [PATCH 038/143] fix(leader_election): context from utility --- consensus/consensus_tests/utils_test.go | 11 ++++++----- consensus/leader_election/module.go | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/consensus/consensus_tests/utils_test.go b/consensus/consensus_tests/utils_test.go index 695aba895..983e68d92 100644 --- a/consensus/consensus_tests/utils_test.go +++ b/consensus/consensus_tests/utils_test.go @@ -140,7 +140,7 @@ func CreateTestConsensusPocketNode( // but note that they will need to be customized on a per test basis. persistenceMock := basePersistenceMock(t, testChannel) p2pMock := baseP2PMock(t, testChannel) - utilityMock := baseUtilityMock(t, testChannel) + utilityMock := baseUtilityMock(t, testChannel, runtimeMgr.GetGenesis()) telemetryMock := baseTelemetryMock(t, testChannel) loggerMock := baseLoggerMock(t, testChannel) rpcMock := baseRpcMock(t, testChannel) @@ -310,7 +310,7 @@ func basePersistenceMock(t *testing.T, _ modules.EventsChannel) *modulesMock.Moc persistenceMock.EXPECT().Start().Return(nil).AnyTimes() persistenceMock.EXPECT().SetBus(gomock.Any()).Return().AnyTimes() - persistenceMock.EXPECT().NewReadContext(gomock.Any()).Return(persistenceReadContextMock, nil).AnyTimes() + persistenceMock.EXPECT().NewReadContext(int64(-1)).Return(persistenceReadContextMock, nil).AnyTimes() persistenceMock.EXPECT().ReleaseWriteContext().Return(nil).AnyTimes() // The persistence context should usually be accessed via the utility module within the context @@ -353,10 +353,10 @@ func baseP2PMock(t *testing.T, testChannel modules.EventsChannel) *modulesMock.M } // Creates a utility module mock with mock implementations of some basic functionality -func baseUtilityMock(t *testing.T, _ modules.EventsChannel) *modulesMock.MockUtilityModule { +func baseUtilityMock(t *testing.T, _ modules.EventsChannel, genesisState modules.GenesisState) *modulesMock.MockUtilityModule { ctrl := gomock.NewController(t) utilityMock := modulesMock.NewMockUtilityModule(ctrl) - utilityContextMock := baseUtilityContextMock(t) + utilityContextMock := baseUtilityContextMock(t, genesisState) utilityMock.EXPECT().Start().Return(nil).AnyTimes() utilityMock.EXPECT().SetBus(gomock.Any()).Return().AnyTimes() @@ -368,12 +368,13 @@ func baseUtilityMock(t *testing.T, _ modules.EventsChannel) *modulesMock.MockUti return utilityMock } -func baseUtilityContextMock(t *testing.T) *modulesMock.MockUtilityContext { +func baseUtilityContextMock(t *testing.T, genesisState modules.GenesisState) *modulesMock.MockUtilityContext { ctrl := gomock.NewController(t) utilityContextMock := modulesMock.NewMockUtilityContext(ctrl) persistenceContextMock := modulesMock.NewMockPersistenceRWContext(ctrl) persistenceContextMock.EXPECT().SetProposalBlock(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() persistenceContextMock.EXPECT().GetBlockHash(gomock.Any()).Return([]byte(""), nil).AnyTimes() + persistenceContextMock.EXPECT().GetAllValidators(gomock.Any()).Return(genesisState.GetPersistenceGenesisState().GetVals(), nil).AnyTimes() utilityContextMock.EXPECT(). CreateAndApplyProposalBlock(gomock.Any(), maxTxBytes). diff --git a/consensus/leader_election/module.go b/consensus/leader_election/module.go index f7b3a2cf4..8ab583121 100644 --- a/consensus/leader_election/module.go +++ b/consensus/leader_election/module.go @@ -65,11 +65,11 @@ func (m *leaderElectionModule) ElectNextLeader(message *typesCons.HotstuffMessag func (m *leaderElectionModule) electNextLeaderDeterministicRoundRobin(message *typesCons.HotstuffMessage) (typesCons.NodeId, error) { value := int64(message.Height) + int64(message.Round) + int64(message.Step) - 1 - ctx, err := m.GetBus().GetPersistenceModule().NewReadContext(int64(message.Height)) + uCtx, err := m.GetBus().GetUtilityModule().NewContext(int64(message.Height)) if err != nil { return typesCons.NodeId(0), err } - vals, err := ctx.GetAllValidators(int64(message.Height)) + vals, err := uCtx.GetPersistenceContext().GetAllValidators(int64(message.Height)) if err != nil { return typesCons.NodeId(0), err } From cf1ef0d645ec5452fd701166e0921e207942bca2 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Fri, 9 Dec 2022 23:57:23 +0000 Subject: [PATCH 039/143] refactor(P2P): MaxMempoolCount --- p2p/raintree/network.go | 2 +- p2p/types/proto/p2p_config.proto | 2 +- shared/modules/types.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/p2p/raintree/network.go b/p2p/raintree/network.go index 4ff9b90cc..149c3fb64 100644 --- a/p2p/raintree/network.go +++ b/p2p/raintree/network.go @@ -39,7 +39,7 @@ func NewRainTreeNetwork(addr cryptoPocket.Address, addrBook typesP2P.AddrBook, p log.Fatalf("[ERROR] Error initializing rainTreeNetwork peersManager: %v", err) } - mempoolMaxNonces := p2pCfg.GetMempoolMaxNonces() + mempoolMaxNonces := p2pCfg.GetMaxMempoolCount() n := &rainTreeNetwork{ selfAddr: addr, peersManager: pm, diff --git a/p2p/types/proto/p2p_config.proto b/p2p/types/proto/p2p_config.proto index b03d4647d..6b4700a55 100644 --- a/p2p/types/proto/p2p_config.proto +++ b/p2p/types/proto/p2p_config.proto @@ -9,7 +9,7 @@ message P2PConfig { uint32 consensus_port = 2; bool use_rain_tree = 3; bool is_empty_connection_type = 4; // TODO (Drewsky) switch back to enum - uint64 mempool_max_nonces = 5; // this is used to limit the number of nonces that can be stored in the mempool, after which a FIFO mechanism is used to remove the oldest nonces and make space for the new ones + uint64 max_mempool_count = 5; // this is used to limit the number of nonces that can be stored in the mempool, after which a FIFO mechanism is used to remove the oldest nonces and make space for the new ones } enum ConnectionType { diff --git a/shared/modules/types.go b/shared/modules/types.go index 348a929c9..f224fd9d1 100644 --- a/shared/modules/types.go +++ b/shared/modules/types.go @@ -55,7 +55,7 @@ type P2PConfig interface { GetConsensusPort() uint32 GetUseRainTree() bool GetIsEmptyConnectionType() bool // TODO : make enum - GetMempoolMaxNonces() uint64 + GetMaxMempoolCount() uint64 } type TelemetryConfig interface { From 1ff01a2b691af61da0fad6efcf54671f70577aa6 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Sat, 10 Dec 2022 00:00:16 +0000 Subject: [PATCH 040/143] docs(Consensus): changelog --- consensus/doc/CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/consensus/doc/CHANGELOG.md b/consensus/doc/CHANGELOG.md index 1c9829798..3613cbb24 100644 --- a/consensus/doc/CHANGELOG.md +++ b/consensus/doc/CHANGELOG.md @@ -9,12 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.0.0.12] - 2022-12-06 -- Removed unused `consensus.UtilityMessage` +- The `Pacemaker` now emits `BeforeHeightChangedEvent` events when the height is about to change. +- The `Pacemaker` now emits `HeightChangedEvent` events when the height changes. ## [0.0.0.11] - 2022-12-04 -- The `Pacemaker` now emits `BeforeHeightChangedEvent` events when the height is about to change. -- The `Pacemaker` now emits `HeightChangedEvent` events when the height changes. +- Removed unused `consensus.UtilityMessage` ## [0.0.0.10] - 2022-11-30 From f66c62156fa1838cfe69179c1ed299ab086d2ea3 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Sat, 10 Dec 2022 00:02:36 +0000 Subject: [PATCH 041/143] fix(P2P): GetMaxMempoolCount --- p2p/raintree/network.go | 2 +- p2p/raintree/network_test.go | 4 ++-- p2p/raintree/peers_manager_test.go | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/p2p/raintree/network.go b/p2p/raintree/network.go index 149c3fb64..3ab15a81f 100644 --- a/p2p/raintree/network.go +++ b/p2p/raintree/network.go @@ -67,7 +67,7 @@ func NewRainTreeNetworkWithAddrBookProvider(addr cryptoPocket.Address, addrBookP addrBookProvider: addrBookProvider, peersManager: pm, nonceSet: make(map[uint64]struct{}), - nonceList: make([]uint64, 0, p2pCfg.GetMempoolMaxNonces()), + nonceList: make([]uint64, 0, p2pCfg.GetMaxMempoolCount()), } return typesP2P.Network(n) diff --git a/p2p/raintree/network_test.go b/p2p/raintree/network_test.go index 30d73667b..f4c32cb81 100644 --- a/p2p/raintree/network_test.go +++ b/p2p/raintree/network_test.go @@ -15,7 +15,7 @@ import ( func TestRainTreeNetwork_AddPeerToAddrBook(t *testing.T) { ctrl := gomock.NewController(t) mockP2PCfg := mock_modules.NewMockP2PConfig(ctrl) - mockP2PCfg.EXPECT().GetMempoolMaxNonces().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() + mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() // starting with an empty address book and only self selfAddr, err := cryptoPocket.GenerateAddress() @@ -49,7 +49,7 @@ func TestRainTreeNetwork_AddPeerToAddrBook(t *testing.T) { func TestRainTreeNetwork_RemovePeerToAddrBook(t *testing.T) { ctrl := gomock.NewController(t) mockP2PCfg := mock_modules.NewMockP2PConfig(ctrl) - mockP2PCfg.EXPECT().GetMempoolMaxNonces().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() + mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() // starting with an address book having only self and an arbitrary number of peers `numAddressesInAddressBook`` numAddressesInAddressBook := 3 diff --git a/p2p/raintree/peers_manager_test.go b/p2p/raintree/peers_manager_test.go index c7892f3e3..c0b377a92 100644 --- a/p2p/raintree/peers_manager_test.go +++ b/p2p/raintree/peers_manager_test.go @@ -40,7 +40,7 @@ type ExpectedRainTreeMessageProp struct { func TestRainTreeAddrBookUtilsHandleUpdate(t *testing.T) { ctrl := gomock.NewController(t) mockP2PCfg := mock_modules.NewMockP2PConfig(ctrl) - mockP2PCfg.EXPECT().GetMempoolMaxNonces().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() + mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() addr, err := cryptoPocket.GenerateAddress() require.NoError(t, err) @@ -93,7 +93,7 @@ func TestRainTreeAddrBookUtilsHandleUpdate(t *testing.T) { func BenchmarkAddrBookUpdates(b *testing.B) { ctrl := gomock.NewController(gomock.TestReporter(b)) mockP2PCfg := mock_modules.NewMockP2PConfig(ctrl) - mockP2PCfg.EXPECT().GetMempoolMaxNonces().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() + mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() addr, err := cryptoPocket.GenerateAddress() require.NoError(b, err) @@ -201,7 +201,7 @@ func testRainTreeMessageTargets(t *testing.T, expectedMsgProp *ExpectedRainTreeM consensusMock.EXPECT().CurrentHeight().Return(uint64(1)).AnyTimes() busMock.EXPECT().GetConsensusModule().Return(consensusMock).AnyTimes() mockP2PCfg := mock_modules.NewMockP2PConfig(ctrl) - mockP2PCfg.EXPECT().GetMempoolMaxNonces().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() + mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() addrBook := getAlphabetAddrBook(expectedMsgProp.numNodes) network := NewRainTreeNetwork([]byte{expectedMsgProp.orig}, addrBook, mockP2PCfg).(*rainTreeNetwork) From f70466a8a3844732bd8bcf9b700953af88263126 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Sat, 10 Dec 2022 00:23:59 +0000 Subject: [PATCH 042/143] refactor(P2P): v -> a --- consensus/types/types.go | 4 ++-- p2p/utils.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/consensus/types/types.go b/consensus/types/types.go index a73637d6a..67f3af523 100644 --- a/consensus/types/types.go +++ b/consensus/types/types.go @@ -55,8 +55,8 @@ func ValidatorMapToModulesValidatorMap(validatorMap ValidatorMap) (vm modules.Va func ActorListToValidatorMap(actors []modules.Actor) (m ValidatorMap) { m = make(ValidatorMap, len(actors)) - for _, v := range actors { - m[v.GetAddress()] = v + for _, a := range actors { + m[a.GetAddress()] = a } return } diff --git a/p2p/utils.go b/p2p/utils.go index 842413349..d16955eca 100644 --- a/p2p/utils.go +++ b/p2p/utils.go @@ -11,8 +11,8 @@ import ( func ActorToAddrBook(cfg modules.P2PConfig, actors map[string]modules.Actor) (typesP2P.AddrBook, error) { book := make(typesP2P.AddrBook, 0) - for _, v := range actors { - networkPeer, err := ActorToNetworkPeer(cfg, v) + for _, a := range actors { + networkPeer, err := ActorToNetworkPeer(cfg, a) if err != nil { log.Println("[WARN] Error connecting to validator: ", err) continue From 7c051965290273863892406755f36914d7c83132 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 12 Dec 2022 22:54:49 +0000 Subject: [PATCH 043/143] test(Consensus): makeMockActors(numValidators) --- consensus/consensus_tests/utils_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/consensus/consensus_tests/utils_test.go b/consensus/consensus_tests/utils_test.go index 983e68d92..ca90c1aa0 100644 --- a/consensus/consensus_tests/utils_test.go +++ b/consensus/consensus_tests/utils_test.go @@ -320,7 +320,7 @@ func basePersistenceMock(t *testing.T, _ modules.EventsChannel) *modulesMock.Moc persistenceReadContextMock.EXPECT().GetLatestBlockHeight().Return(uint64(0), nil).AnyTimes() // here we are mocking 4 actors since we are considering the 4 nodes in the LocalNet genesis - persistenceReadContextMock.EXPECT().GetAllValidators(gomock.Any()).Return([]modules.Actor{&modulesMock.MockActor{}, &modulesMock.MockActor{}, &modulesMock.MockActor{}, &modulesMock.MockActor{}}, nil).AnyTimes() + persistenceReadContextMock.EXPECT().GetAllValidators(gomock.Any()).Return(makeMockActors(numValidators), nil).AnyTimes() persistenceReadContextMock.EXPECT().Close().Return(nil).AnyTimes() return persistenceMock @@ -487,3 +487,12 @@ func assertStep(t *testing.T, nodeId typesCons.NodeId, expected, actual typesCon func assertRound(t *testing.T, nodeId typesCons.NodeId, expected, actual uint8) { require.Equal(t, expected, actual, "[NODE][%v] failed assertRound", nodeId) } + +// makeMockActors creates a slice of modules.Actor with n &modulesMock.MockActor{} in it. +func makeMockActors(n int) []modules.Actor { + actors := make([]modules.Actor, n) + for i := 0; i < n; i++ { + actors[i] = &modulesMock.MockActor{} + } + return actors +} From d82b66ad94f8c43201ffd1178a3cc12e2cb23140 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 12 Dec 2022 23:14:08 +0000 Subject: [PATCH 044/143] docs(shared): changelog --- shared/CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shared/CHANGELOG.md b/shared/CHANGELOG.md index 9fcabee8d..6dee588ec 100644 --- a/shared/CHANGELOG.md +++ b/shared/CHANGELOG.md @@ -7,13 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.6] - 2022-12-06 +## [0.0.0.6] - 2022-12-04 -- Change the `bus` to be a pointer receiver rather than a value receiver in all the functions it implements +- Added `BeforeHeightChangedEvent` and `HeightChangedEvent` events that respectively signal the other modules that we are about to change the Height and that we have changed the Height. -## [0.0.0.5] - 2022-12-04 +## [0.0.0.5] - 2022-12-06 -- Added `BeforeHeightChangedEvent` and `HeightChangedEvent` events that respectively signal the other modules that we are about to change the Height and that we have changed the Height. +- Change the `bus` to be a pointer receiver rather than a value receiver in all the functions it implements ## [0.0.0.4] - 2022-11-30 From 644df90581756060662959eeafa5ecb25cc75237 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 12 Dec 2022 23:14:24 +0000 Subject: [PATCH 045/143] docs(consensus): changelog --- consensus/doc/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/consensus/doc/CHANGELOG.md b/consensus/doc/CHANGELOG.md index 3613cbb24..a2eaa5f0d 100644 --- a/consensus/doc/CHANGELOG.md +++ b/consensus/doc/CHANGELOG.md @@ -7,12 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.12] - 2022-12-06 +## [0.0.0.12] - 2022-12-12 - The `Pacemaker` now emits `BeforeHeightChangedEvent` events when the height is about to change. - The `Pacemaker` now emits `HeightChangedEvent` events when the height changes. -## [0.0.0.11] - 2022-12-04 +## [0.0.0.11] - 2022-12-06 - Removed unused `consensus.UtilityMessage` From b53f12797e27e108cd3578f690700ee3c93a395d Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 12 Dec 2022 23:29:20 +0000 Subject: [PATCH 046/143] docs(shared): changelog --- consensus/doc/CHANGELOG.md | 10 +++++----- p2p/CHANGELOG.md | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/consensus/doc/CHANGELOG.md b/consensus/doc/CHANGELOG.md index 9dc1001c0..750866fda 100644 --- a/consensus/doc/CHANGELOG.md +++ b/consensus/doc/CHANGELOG.md @@ -7,14 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.13] - 2022-12-12 +## [0.0.0.13] - 2022-12-13 -- The `Pacemaker` now emits `BeforeHeightChangedEvent` events when the height is about to change. -- The `Pacemaker` now emits `HeightChangedEvent` events when the height changes. +- `LeaderElectionModule`'s `electNextLeaderDeterministicRoundRobin` now uses `Persistence` to access the list of validators instead of the static `ValidatorMap`. -## [0.0.0.12] - 2022-12-08 +## [0.0.0.12] - 2022-12-12 -- `LeaderElectionModule`'s `electNextLeaderDeterministicRoundRobin` now uses `Persistence` to access the list of validators instead of the static `ValidatorMap`. +- The `Pacemaker` now emits `BeforeHeightChangedEvent` events when the height is about to change. +- The `Pacemaker` now emits `HeightChangedEvent` events when the height changes. ## [0.0.0.11] - 2022-12-06 diff --git a/p2p/CHANGELOG.md b/p2p/CHANGELOG.md index 77d0cf52a..6e6a44cff 100644 --- a/p2p/CHANGELOG.md +++ b/p2p/CHANGELOG.md @@ -6,15 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] -## [0.0.0.11] 2022-12-08 -- mempool cap is now configurable via P2PConfig. Tests implement the mock accordingly. - -## [0.0.0.10] - 2022-12-05 +## [0.0.0.11] - 2022-12-12 - `ValidatorMapToAddrBook` renamed to `ActorToAddrBook` - `ValidatorToNetworkPeer` renamed to `ActorToNetworkPeer` +## [0.0.0.10] 2022-12-08 + +- mempool cap is now configurable via P2PConfig. Tests implement the mock accordingly. + ## [0.0.0.9] - 2022-12-04 - Raintree mempool cannot grow unbounded anymore. It's now bounded by a constant limit and when new nonces are inserted the oldest ones are removed. From 7b8d75b9172c887b2975f359bce873585d38093e Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 09:01:00 +0000 Subject: [PATCH 047/143] refactor(Shared): *.bus.* -> *.GetBus().* --- consensus/pacemaker.go | 2 +- p2p/module.go | 6 +++--- rpc/server.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/consensus/pacemaker.go b/consensus/pacemaker.go index 25b5308f4..1b7311273 100644 --- a/consensus/pacemaker.go +++ b/consensus/pacemaker.go @@ -177,7 +177,7 @@ func (p *paceMaker) RestartTimer() { stepTimeout := p.getStepTimeout(p.consensusMod.Round) - clock := p.bus.GetRuntimeMgr().GetClock() + clock := p.GetBus().GetRuntimeMgr().GetClock() ctx, cancel := clock.WithTimeout(context.TODO(), stepTimeout) p.stepCancelFunc = cancel diff --git a/p2p/module.go b/p2p/module.go index 10e451e13..420ea6adf 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -120,7 +120,7 @@ func (m *p2pModule) Start() error { telemetry.P2P_NODE_STARTED_TIMESERIES_METRIC_DESCRIPTION, ) - currentHeight := m.bus.GetConsensusModule().CurrentHeight() + currentHeight := m.GetBus().GetConsensusModule().CurrentHeight() var ( addrBook typesP2P.AddrBook err error @@ -129,7 +129,7 @@ func (m *p2pModule) Start() error { if m.GetBus().GetPersistenceModule() == nil { // we are getting called by the client and we use the "legacy behaviour" // TODO (team): improve this. - addrBook, err = ActorToAddrBook(m.p2pCfg, m.bus.GetConsensusModule().ValidatorMap()) + addrBook, err = ActorToAddrBook(m.p2pCfg, m.GetBus().GetConsensusModule().ValidatorMap()) } else { addrBook, err = m.getAddrBookPerHeight(currentHeight) } @@ -170,7 +170,7 @@ func (m *p2pModule) Start() error { } func (m *p2pModule) getAddrBookPerHeight(height uint64) (typesP2P.AddrBook, error) { - persistenceReadContext, err := m.bus.GetPersistenceModule().NewReadContext(int64(height)) + persistenceReadContext, err := m.GetBus().GetPersistenceModule().NewReadContext(int64(height)) if err != nil { return nil, err } diff --git a/rpc/server.go b/rpc/server.go index 807e92c49..621f8ea4c 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -36,7 +36,7 @@ func (s *rpcServer) StartRPC(port string, timeout uint64) { Timeout: time.Duration(defaults.DefaultRpcTimeout) * time.Millisecond, }), } - if s.bus.GetRuntimeMgr().GetConfig().GetRPCConfig().GetUseCors() { + if s.GetBus().GetRuntimeMgr().GetConfig().GetRPCConfig().GetUseCors() { log.Println("Enabling CORS middleware") middlewares = append(middlewares, middleware.CORS()) } From 07a4b4008fe8a88899e880bf950e3ed7e917a8ba Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 09:01:00 +0000 Subject: [PATCH 048/143] refactor(Shared): *.bus.* -> *.GetBus().* Signed-off-by: Alessandro De Blasis --- consensus/pacemaker.go | 2 +- p2p/module.go | 6 +++--- rpc/server.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/consensus/pacemaker.go b/consensus/pacemaker.go index 25b5308f4..1b7311273 100644 --- a/consensus/pacemaker.go +++ b/consensus/pacemaker.go @@ -177,7 +177,7 @@ func (p *paceMaker) RestartTimer() { stepTimeout := p.getStepTimeout(p.consensusMod.Round) - clock := p.bus.GetRuntimeMgr().GetClock() + clock := p.GetBus().GetRuntimeMgr().GetClock() ctx, cancel := clock.WithTimeout(context.TODO(), stepTimeout) p.stepCancelFunc = cancel diff --git a/p2p/module.go b/p2p/module.go index 40a31d623..1df24ff87 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -120,7 +120,7 @@ func (m *p2pModule) Start() error { telemetry.P2P_NODE_STARTED_TIMESERIES_METRIC_DESCRIPTION, ) - currentHeight := m.bus.GetConsensusModule().CurrentHeight() + currentHeight := m.GetBus().GetConsensusModule().CurrentHeight() var ( addrBook typesP2P.AddrBook err error @@ -129,7 +129,7 @@ func (m *p2pModule) Start() error { if m.GetBus().GetPersistenceModule() == nil { // we are getting called by the client and we use the "legacy behaviour" // TODO (team): improve this. - addrBook, err = ValidatorMapToAddrBook(m.p2pCfg, m.bus.GetConsensusModule().ValidatorMap()) + addrBook, err = ValidatorMapToAddrBook(m.p2pCfg, m.GetBus().GetConsensusModule().ValidatorMap()) } else { addrBook, err = m.getAddrBookPerHeight(currentHeight) } @@ -170,7 +170,7 @@ func (m *p2pModule) Start() error { } func (m *p2pModule) getAddrBookPerHeight(height uint64) (typesP2P.AddrBook, error) { - persistenceReadContext, err := m.bus.GetPersistenceModule().NewReadContext(int64(height)) + persistenceReadContext, err := m.GetBus().GetPersistenceModule().NewReadContext(int64(height)) if err != nil { return nil, err } diff --git a/rpc/server.go b/rpc/server.go index 807e92c49..621f8ea4c 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -36,7 +36,7 @@ func (s *rpcServer) StartRPC(port string, timeout uint64) { Timeout: time.Duration(defaults.DefaultRpcTimeout) * time.Millisecond, }), } - if s.bus.GetRuntimeMgr().GetConfig().GetRPCConfig().GetUseCors() { + if s.GetBus().GetRuntimeMgr().GetConfig().GetRPCConfig().GetUseCors() { log.Println("Enabling CORS middleware") middlewares = append(middlewares, middleware.CORS()) } From e0eedd0dd61dbfba7d7f9a3ecb7a049326628d60 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 09:24:44 +0000 Subject: [PATCH 049/143] style(consensus): rm redundant comment --- consensus/consensus_tests/utils_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/consensus/consensus_tests/utils_test.go b/consensus/consensus_tests/utils_test.go index ca90c1aa0..5cf4da009 100644 --- a/consensus/consensus_tests/utils_test.go +++ b/consensus/consensus_tests/utils_test.go @@ -319,7 +319,6 @@ func basePersistenceMock(t *testing.T, _ modules.EventsChannel) *modulesMock.Moc persistenceContextMock.EXPECT().Close().Return(nil).AnyTimes() persistenceReadContextMock.EXPECT().GetLatestBlockHeight().Return(uint64(0), nil).AnyTimes() - // here we are mocking 4 actors since we are considering the 4 nodes in the LocalNet genesis persistenceReadContextMock.EXPECT().GetAllValidators(gomock.Any()).Return(makeMockActors(numValidators), nil).AnyTimes() persistenceReadContextMock.EXPECT().Close().Return(nil).AnyTimes() From 7d6983766c9dcadbec3b63f2cd9a5fccb580f5f0 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 09:49:50 +0000 Subject: [PATCH 050/143] Update p2p/raintree/network.go Co-authored-by: Daniel Olshansky --- p2p/raintree/network.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p2p/raintree/network.go b/p2p/raintree/network.go index 3ab15a81f..5fa6d09dd 100644 --- a/p2p/raintree/network.go +++ b/p2p/raintree/network.go @@ -27,7 +27,7 @@ type rainTreeNetwork struct { peersManager *peersManager // TODO (#278): What should we use for de-duping messages within P2P? - // TODO (team): we should generalize and use the FIFOMempool (in utility/types/mempool.go at the time of writing) in here as well for this. Same concept + // TODO(#388): generalize to use the shared `FIFOMempool` type (in `utility/types/mempool.go` at the time of writing) in here as well for this. nonceSet map[uint64]struct{} nonceList []uint64 mampoolMaxNonces uint64 From ff1b66de42cc4ae760b8477dfd1e5e270700825c Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 09:53:10 +0000 Subject: [PATCH 051/143] fix(P2P): removed redundant mock config --- p2p/utils_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/p2p/utils_test.go b/p2p/utils_test.go index 3e662d433..fbf6452c6 100644 --- a/p2p/utils_test.go +++ b/p2p/utils_test.go @@ -177,7 +177,6 @@ func prepareBusMock(t *testing.T, busMock.EXPECT().GetConsensusModule().Return(consensusMock).AnyTimes() busMock.EXPECT().GetPersistenceModule().Return(persistenceMock).AnyTimes() busMock.EXPECT().GetTelemetryModule().Return(telemetryMock).AnyTimes() - busMock.EXPECT().GetPersistenceModule().Return(persistenceMock).AnyTimes() return busMock } From 30e2cfbda618799eb7f35f5f698181c6e33db014 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 09:53:43 +0000 Subject: [PATCH 052/143] refactor(P2P): consistency in imports --- p2p/raintree/network_test.go | 13 ++++++------- p2p/raintree/peers_manager_test.go | 10 ++++------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/p2p/raintree/network_test.go b/p2p/raintree/network_test.go index f4c32cb81..be812c5d9 100644 --- a/p2p/raintree/network_test.go +++ b/p2p/raintree/network_test.go @@ -4,17 +4,16 @@ import ( "testing" "github.com/golang/mock/gomock" - "github.com/pokt-network/pocket/p2p/types" typesP2P "github.com/pokt-network/pocket/p2p/types" "github.com/pokt-network/pocket/runtime/defaults" cryptoPocket "github.com/pokt-network/pocket/shared/crypto" - mock_modules "github.com/pokt-network/pocket/shared/modules/mocks" + mockModules "github.com/pokt-network/pocket/shared/modules/mocks" "github.com/stretchr/testify/require" ) func TestRainTreeNetwork_AddPeerToAddrBook(t *testing.T) { ctrl := gomock.NewController(t) - mockP2PCfg := mock_modules.NewMockP2PConfig(ctrl) + mockP2PCfg := mockModules.NewMockP2PConfig(ctrl) mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() // starting with an empty address book and only self @@ -23,7 +22,7 @@ func TestRainTreeNetwork_AddPeerToAddrBook(t *testing.T) { selfPeer := &typesP2P.NetworkPeer{Address: selfAddr} addrBook := getAddrBook(nil, 0) - addrBook = append(addrBook, &types.NetworkPeer{Address: selfAddr}) + addrBook = append(addrBook, &typesP2P.NetworkPeer{Address: selfAddr}) network := NewRainTreeNetwork(selfAddr, addrBook, mockP2PCfg).(*rainTreeNetwork) peerAddr, err := cryptoPocket.GenerateAddress() @@ -38,7 +37,7 @@ func TestRainTreeNetwork_AddPeerToAddrBook(t *testing.T) { stateView := network.peersManager.getNetworkView() require.Equal(t, 2, len(stateView.addrList)) require.ElementsMatch(t, []string{selfAddr.String(), peerAddr.String()}, stateView.addrList, "addrList does not match") - require.ElementsMatch(t, []*types.NetworkPeer{selfPeer, peer}, stateView.addrBook, "addrBook does not match") + require.ElementsMatch(t, []*typesP2P.NetworkPeer{selfPeer, peer}, stateView.addrBook, "addrBook does not match") require.Contains(t, stateView.addrBookMap, selfAddr.String(), "addrBookMap does not contain self key") require.Equal(t, selfPeer, stateView.addrBookMap[selfAddr.String()], "addrBookMap does not contain self") @@ -48,7 +47,7 @@ func TestRainTreeNetwork_AddPeerToAddrBook(t *testing.T) { func TestRainTreeNetwork_RemovePeerToAddrBook(t *testing.T) { ctrl := gomock.NewController(t) - mockP2PCfg := mock_modules.NewMockP2PConfig(ctrl) + mockP2PCfg := mockModules.NewMockP2PConfig(ctrl) mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() // starting with an address book having only self and an arbitrary number of peers `numAddressesInAddressBook`` @@ -57,7 +56,7 @@ func TestRainTreeNetwork_RemovePeerToAddrBook(t *testing.T) { selfAddr, err := cryptoPocket.GenerateAddress() require.NoError(t, err) selfPeer := &typesP2P.NetworkPeer{Address: selfAddr} - addrBook = append(addrBook, &types.NetworkPeer{Address: selfAddr}) + addrBook = append(addrBook, &typesP2P.NetworkPeer{Address: selfAddr}) network := NewRainTreeNetwork(selfAddr, addrBook, mockP2PCfg).(*rainTreeNetwork) stateView := network.peersManager.getNetworkView() require.Equal(t, numAddressesInAddressBook+1, len(stateView.addrList)) // +1 to account for self in the addrBook as well diff --git a/p2p/raintree/peers_manager_test.go b/p2p/raintree/peers_manager_test.go index c0b377a92..8697075aa 100644 --- a/p2p/raintree/peers_manager_test.go +++ b/p2p/raintree/peers_manager_test.go @@ -9,9 +9,7 @@ import ( "github.com/golang/mock/gomock" "github.com/pokt-network/pocket/p2p/types" "github.com/pokt-network/pocket/runtime/defaults" - "github.com/pokt-network/pocket/shared/crypto" cryptoPocket "github.com/pokt-network/pocket/shared/crypto" - mock_modules "github.com/pokt-network/pocket/shared/modules/mocks" modulesMock "github.com/pokt-network/pocket/shared/modules/mocks" "github.com/stretchr/testify/require" ) @@ -39,7 +37,7 @@ type ExpectedRainTreeMessageProp struct { func TestRainTreeAddrBookUtilsHandleUpdate(t *testing.T) { ctrl := gomock.NewController(t) - mockP2PCfg := mock_modules.NewMockP2PConfig(ctrl) + mockP2PCfg := modulesMock.NewMockP2PConfig(ctrl) mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() addr, err := cryptoPocket.GenerateAddress() @@ -92,7 +90,7 @@ func TestRainTreeAddrBookUtilsHandleUpdate(t *testing.T) { func BenchmarkAddrBookUpdates(b *testing.B) { ctrl := gomock.NewController(gomock.TestReporter(b)) - mockP2PCfg := mock_modules.NewMockP2PConfig(ctrl) + mockP2PCfg := modulesMock.NewMockP2PConfig(ctrl) mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() addr, err := cryptoPocket.GenerateAddress() @@ -126,7 +124,7 @@ func BenchmarkAddrBookUpdates(b *testing.B) { require.Equal(b, testCase.numExpectedLevels, int(peersManagerStateView.maxNumLevels)) for i := 0; i < numAddressesToBeAdded; i++ { - newAddr, err := crypto.GenerateAddress() + newAddr, err := cryptoPocket.GenerateAddress() require.NoError(b, err) network.AddPeerToAddrBook(&types.NetworkPeer{Address: newAddr}) } @@ -200,7 +198,7 @@ func testRainTreeMessageTargets(t *testing.T, expectedMsgProp *ExpectedRainTreeM consensusMock := modulesMock.NewMockConsensusModule(ctrl) consensusMock.EXPECT().CurrentHeight().Return(uint64(1)).AnyTimes() busMock.EXPECT().GetConsensusModule().Return(consensusMock).AnyTimes() - mockP2PCfg := mock_modules.NewMockP2PConfig(ctrl) + mockP2PCfg := modulesMock.NewMockP2PConfig(ctrl) mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() addrBook := getAlphabetAddrBook(expectedMsgProp.numNodes) From 964360b495ac225ccce810e501f5920a55a079ad Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 10:01:12 +0000 Subject: [PATCH 053/143] refactor(P2P): peersManager flag --- p2p/raintree/peers_manager.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/p2p/raintree/peers_manager.go b/p2p/raintree/peers_manager.go index 58d3c7e91..29640dd7e 100644 --- a/p2p/raintree/peers_manager.go +++ b/p2p/raintree/peers_manager.go @@ -39,7 +39,11 @@ func NewPeersManagerWithAddrBookProvider(selfAddr cryptoPocket.Address, addrBook return newPeersManager(selfAddr, addrBook, false) } -func newPeersManager(selfAddr cryptoPocket.Address, addrBook typesP2P.AddrBook, handleEvents bool) (*peersManager, error) { +// newPeersManager creates a new peersManager instance, it is in charge of handling operations on peers (like adding/removing them) within an AddrBook +// it also takes care of keeping the AddrBook sorted and indexed for fast access +// +// If `isDynamic` is true, the peersManager will not handle addressBook changes, it will only be used for querying the AddrBook +func newPeersManager(selfAddr cryptoPocket.Address, addrBook typesP2P.AddrBook, isDynamic bool) (*peersManager, error) { pm := &peersManager{ selfAddr: selfAddr, addrBook: addrBook, @@ -75,7 +79,7 @@ func newPeersManager(selfAddr cryptoPocket.Address, addrBook typesP2P.AddrBook, pm.maxNumLevels = pm.getMaxAddrBookLevels() - if !handleEvents { + if !isDynamic { return pm, nil } From 1084944741ae029ae9e5087a95e972e36d399efc Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 10:47:05 +0000 Subject: [PATCH 054/143] docs(P2P): referenced refactoring/techdebt issue --- p2p/module.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/p2p/module.go b/p2p/module.go index 1df24ff87..6be53f34c 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -127,8 +127,7 @@ func (m *p2pModule) Start() error { ) if m.GetBus().GetPersistenceModule() == nil { - // we are getting called by the client and we use the "legacy behaviour" - // TODO (team): improve this. + // TODO (#203): refactor this. addrBook, err = ValidatorMapToAddrBook(m.p2pCfg, m.GetBus().GetConsensusModule().ValidatorMap()) } else { addrBook, err = m.getAddrBookPerHeight(currentHeight) @@ -139,8 +138,7 @@ func (m *p2pModule) Start() error { if m.p2pCfg.GetUseRainTree() { if m.GetBus().GetPersistenceModule() == nil { - // we are getting called by the client and we use the "legacy behaviour" - // TODO (team): improve this. + // TODO (#203): refactor this. m.network = raintree.NewRainTreeNetwork(m.address, addrBook, m.p2pCfg) } else { m.network = raintree.NewRainTreeNetworkWithAddrBookProvider(m.address, m.getAddrBookPerHeight, currentHeight, m.p2pCfg) From 36d7129cfc1c0199ddb1931438c16b6480dda88e Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 11:39:40 +0000 Subject: [PATCH 055/143] refactor(persistence): GetAllStakedActors --- p2p/module.go | 7 ++++--- persistence/genesis.go | 27 +++++++++++++++++++++++++++ shared/modules/persistence_module.go | 3 +++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/p2p/module.go b/p2p/module.go index 6be53f34c..ca29effac 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -172,12 +172,13 @@ func (m *p2pModule) getAddrBookPerHeight(height uint64) (typesP2P.AddrBook, erro if err != nil { return nil, err } - vals, err := persistenceReadContext.GetAllValidators(int64(height)) + stakedActors, err := persistenceReadContext.GetAllStakedActors(int64(height)) if err != nil { return nil, err } - validatorMap := make(modules.ValidatorMap, len(vals)) - for _, v := range vals { + // TODO(#203): refactor `ValidatorMap`` + validatorMap := make(modules.ValidatorMap, len(stakedActors)) + for _, v := range stakedActors { validatorMap[v.GetAddress()] = v } addrBook, err := ValidatorMapToAddrBook(m.p2pCfg, validatorMap) diff --git a/persistence/genesis.go b/persistence/genesis.go index ba384eafd..c515f543f 100644 --- a/persistence/genesis.go +++ b/persistence/genesis.go @@ -321,3 +321,30 @@ func (p PostgresContext) GetAllFishermen(height int64) (f []modules.Actor, err e } return } + +// IMPROVE: This is a proof of concept. Ideally we should have a single query that returns all actors. +func (p PostgresContext) GetAllStakedActors(height int64) (actors []modules.Actor, err error) { + actors = make([]modules.Actor, 0) + var allActors []modules.Actor + allActors, err = p.GetAllValidators(height) + if err != nil { + return + } + actors = append(actors, allActors...) + allActors, err = p.GetAllServiceNodes(height) + if err != nil { + return + } + actors = append(actors, allActors...) + allActors, err = p.GetAllFishermen(height) + if err != nil { + return + } + actors = append(actors, allActors...) + allActors, err = p.GetAllApps(height) + if err != nil { + return + } + actors = append(actors, allActors...) + return +} diff --git a/shared/modules/persistence_module.go b/shared/modules/persistence_module.go index caf535b01..9692d724f 100644 --- a/shared/modules/persistence_module.go +++ b/shared/modules/persistence_module.go @@ -183,6 +183,9 @@ type PersistenceReadContext interface { GetValidatorOutputAddress(operator []byte, height int64) (output []byte, err error) GetValidatorMissedBlocks(address []byte, height int64) (int, error) + // Actors Queries + GetAllStakedActors(height int64) ([]Actor, error) + // Params GetIntParam(paramName string, height int64) (int, error) GetStringParam(paramName string, height int64) (string, error) From 219559486fff7b5ec1fffa18474bdb87d7afe8ed Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 12:55:31 +0000 Subject: [PATCH 056/143] refactor(persistence): GetAllStakedActors --- p2p/module.go | 7 ++++--- p2p/utils_test.go | 2 +- persistence/genesis.go | 27 +++++++++++++++++++++++++++ shared/modules/persistence_module.go | 3 +++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/p2p/module.go b/p2p/module.go index 6be53f34c..ca29effac 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -172,12 +172,13 @@ func (m *p2pModule) getAddrBookPerHeight(height uint64) (typesP2P.AddrBook, erro if err != nil { return nil, err } - vals, err := persistenceReadContext.GetAllValidators(int64(height)) + stakedActors, err := persistenceReadContext.GetAllStakedActors(int64(height)) if err != nil { return nil, err } - validatorMap := make(modules.ValidatorMap, len(vals)) - for _, v := range vals { + // TODO(#203): refactor `ValidatorMap`` + validatorMap := make(modules.ValidatorMap, len(stakedActors)) + for _, v := range stakedActors { validatorMap[v.GetAddress()] = v } addrBook, err := ValidatorMapToAddrBook(m.p2pCfg, validatorMap) diff --git a/p2p/utils_test.go b/p2p/utils_test.go index fbf6452c6..fb279db64 100644 --- a/p2p/utils_test.go +++ b/p2p/utils_test.go @@ -205,7 +205,7 @@ func preparePersistenceMock(t *testing.T, genesisState modules.GenesisState) *mo persistenceMock := modulesMock.NewMockPersistenceModule(ctrl) readContextMock := modulesMock.NewMockPersistenceReadContext(ctrl) - readContextMock.EXPECT().GetAllValidators(gomock.Any()).Return(genesisState.GetPersistenceGenesisState().GetVals(), nil).AnyTimes() + readContextMock.EXPECT().GetAllStakedActors(gomock.Any()).Return(genesisState.GetPersistenceGenesisState().GetVals(), nil).AnyTimes() persistenceMock.EXPECT().NewReadContext(gomock.Any()).Return(readContextMock, nil).AnyTimes() return persistenceMock diff --git a/persistence/genesis.go b/persistence/genesis.go index ba384eafd..c515f543f 100644 --- a/persistence/genesis.go +++ b/persistence/genesis.go @@ -321,3 +321,30 @@ func (p PostgresContext) GetAllFishermen(height int64) (f []modules.Actor, err e } return } + +// IMPROVE: This is a proof of concept. Ideally we should have a single query that returns all actors. +func (p PostgresContext) GetAllStakedActors(height int64) (actors []modules.Actor, err error) { + actors = make([]modules.Actor, 0) + var allActors []modules.Actor + allActors, err = p.GetAllValidators(height) + if err != nil { + return + } + actors = append(actors, allActors...) + allActors, err = p.GetAllServiceNodes(height) + if err != nil { + return + } + actors = append(actors, allActors...) + allActors, err = p.GetAllFishermen(height) + if err != nil { + return + } + actors = append(actors, allActors...) + allActors, err = p.GetAllApps(height) + if err != nil { + return + } + actors = append(actors, allActors...) + return +} diff --git a/shared/modules/persistence_module.go b/shared/modules/persistence_module.go index caf535b01..9692d724f 100644 --- a/shared/modules/persistence_module.go +++ b/shared/modules/persistence_module.go @@ -183,6 +183,9 @@ type PersistenceReadContext interface { GetValidatorOutputAddress(operator []byte, height int64) (output []byte, err error) GetValidatorMissedBlocks(address []byte, height int64) (int, error) + // Actors Queries + GetAllStakedActors(height int64) ([]Actor, error) + // Params GetIntParam(paramName string, height int64) (int, error) GetStringParam(paramName string, height int64) (string, error) From 3adc9a5c1a1359276c10b379524456d357a369f7 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 12:59:51 +0000 Subject: [PATCH 057/143] refactor(P2P): getAddrBookPerHeight -> getStakedAddrBookAtHeight --- p2p/module.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/p2p/module.go b/p2p/module.go index ca29effac..360e60ebd 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -130,7 +130,7 @@ func (m *p2pModule) Start() error { // TODO (#203): refactor this. addrBook, err = ValidatorMapToAddrBook(m.p2pCfg, m.GetBus().GetConsensusModule().ValidatorMap()) } else { - addrBook, err = m.getAddrBookPerHeight(currentHeight) + addrBook, err = m.getStakedAddrBookAtHeight(currentHeight) } if err != nil { return err @@ -141,7 +141,7 @@ func (m *p2pModule) Start() error { // TODO (#203): refactor this. m.network = raintree.NewRainTreeNetwork(m.address, addrBook, m.p2pCfg) } else { - m.network = raintree.NewRainTreeNetworkWithAddrBookProvider(m.address, m.getAddrBookPerHeight, currentHeight, m.p2pCfg) + m.network = raintree.NewRainTreeNetworkWithAddrBookProvider(m.address, m.getStakedAddrBookAtHeight, currentHeight, m.p2pCfg) } } else { m.network = stdnetwork.NewNetwork(addrBook) @@ -167,7 +167,7 @@ func (m *p2pModule) Start() error { return nil } -func (m *p2pModule) getAddrBookPerHeight(height uint64) (typesP2P.AddrBook, error) { +func (m *p2pModule) getStakedAddrBookAtHeight(height uint64) (typesP2P.AddrBook, error) { persistenceReadContext, err := m.GetBus().GetPersistenceModule().NewReadContext(int64(height)) if err != nil { return nil, err From bcc96c925ad5a88d258295d014bbc7def64ae4f5 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 22:19:17 +0000 Subject: [PATCH 058/143] fix(Makefile): p2p mocks cleanup and test name typo --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b3a1cdb96..4c74fae79 100644 --- a/Makefile +++ b/Makefile @@ -239,6 +239,8 @@ docker_loki_check: clean_mocks: $(eval modules_dir = "shared/modules") find ${modules_dir}/mocks -type f ! -name "mocks.go" -exec rm {} \; + $(eval p2p_type_mocks_dir = "p2p/types/mocks") + find ${p2p_type_mocks_dir} -type f ! -name "mocks.go" -exec rm {} \; .PHONY: mockgen ## Use `mockgen` to generate mocks used for testing purposes of all the modules. @@ -347,7 +349,7 @@ test_consensus: # mockgen .PHONY: test_consensus_concurrent_tests ## Run unit tests in the consensus module that could be prone to race conditions (#192) test_consensus_concurrent_tests: - for i in $$(seq 1 100); do go test -timeout 2s -count=1 -run ^TestHotstuff4Nodes1BlockHappyPath$ ./consensus/consensus_tests; done; + for i in $$(seq 1 100); do go test -timeout 2s -count=1 -run ^TestTinyPacemakerTimeouts$ ./consensus/consensus_tests; done; for i in $$(seq 1 100); do go test -timeout 2s -count=1 -run ^TestHotstuff4Nodes1BlockHappyPath$ ./consensus/consensus_tests; done; for i in $$(seq 1 100); do go test -timeout 2s -count=1 -race -run ^TestTinyPacemakerTimeouts$ ./consensus/consensus_tests; done; for i in $$(seq 1 100); do go test -timeout 2s -count=1 -race -run ^TestHotstuff4Nodes1BlockHappyPath$ ./consensus/consensus_tests; done; From f3717ebf9b6bd4f5e62c9a24360cc005b62e4664 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 22:20:13 +0000 Subject: [PATCH 059/143] refactor(P2P): moved transport into its own package --- p2p/{ => transport}/transport.go | 2 +- p2p/types/transport.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) rename p2p/{ => transport}/transport.go (99%) diff --git a/p2p/transport.go b/p2p/transport/transport.go similarity index 99% rename from p2p/transport.go rename to p2p/transport/transport.go index cf836ea19..6df8f3932 100644 --- a/p2p/transport.go +++ b/p2p/transport/transport.go @@ -1,4 +1,4 @@ -package p2p +package transport import ( "fmt" diff --git a/p2p/types/transport.go b/p2p/types/transport.go index 095a5869f..4625cb573 100644 --- a/p2p/types/transport.go +++ b/p2p/types/transport.go @@ -1,5 +1,7 @@ package types +import "github.com/pokt-network/pocket/shared/modules" + //go:generate mockgen -source=$GOFILE -destination=./mocks/transport_mock.go github.com/pokt-network/pocket/p2p/types Transport type Transport interface { @@ -8,3 +10,5 @@ type Transport interface { Write([]byte) error Close() error } + +type ConnectionFactory func(cfg modules.P2PConfig, url string) (Transport, error) From 8107177fb09d7ef14b7923d177fc64752f250ab4 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 22:26:50 +0000 Subject: [PATCH 060/143] feat(P2P): introduced addrbook_provider abstracts away how we source addrBook from persistence --- p2p/addrbook_provider/getter.go | 28 +++++++ p2p/addrbook_provider/persistence.go | 108 +++++++++++++++++++++++++++ p2p/utils.go | 48 ------------ 3 files changed, 136 insertions(+), 48 deletions(-) create mode 100644 p2p/addrbook_provider/getter.go create mode 100644 p2p/addrbook_provider/persistence.go delete mode 100644 p2p/utils.go diff --git a/p2p/addrbook_provider/getter.go b/p2p/addrbook_provider/getter.go new file mode 100644 index 000000000..ac0f8b105 --- /dev/null +++ b/p2p/addrbook_provider/getter.go @@ -0,0 +1,28 @@ +package addrbook_provider + +import ( + "log" + + typesP2P "github.com/pokt-network/pocket/p2p/types" + "github.com/pokt-network/pocket/shared/modules" +) + +// GetAddrBook is a helper function that returns the addrBook depending on the availability of the persistence module +// +// this is a temporary solution simply used to centralize the logic that is going to be refactored in #331 and #203 +func GetAddrBook(bus modules.Bus, addrBookProvider typesP2P.AddrBookProvider) typesP2P.AddrBook { + var ( + addrBook typesP2P.AddrBook + err error + ) + if bus.GetPersistenceModule() == nil { + // TODO (#203): refactor this. + addrBook, err = addrBookProvider.ValidatorMapToAddrBook(bus.GetConsensusModule().ValidatorMap()) + } else { + addrBook, err = addrBookProvider.GetStakedAddrBookAtHeight(bus.GetConsensusModule().CurrentHeight()) + } + if err != nil { + log.Fatalf("[ERROR] Error getting addrBook: %v", err) + } + return addrBook +} diff --git a/p2p/addrbook_provider/persistence.go b/p2p/addrbook_provider/persistence.go new file mode 100644 index 000000000..f3451664b --- /dev/null +++ b/p2p/addrbook_provider/persistence.go @@ -0,0 +1,108 @@ +package addrbook_provider + +import ( + "fmt" + "log" + + "github.com/pokt-network/pocket/p2p/transport" + typesP2P "github.com/pokt-network/pocket/p2p/types" + cryptoPocket "github.com/pokt-network/pocket/shared/crypto" + "github.com/pokt-network/pocket/shared/modules" +) + +var _ modules.IntegratableModule = &persistenceAddrBookProvider{} +var _ typesP2P.AddrBookProvider = &persistenceAddrBookProvider{} + +type persistenceAddrBookProvider struct { + bus modules.Bus + p2pCfg modules.P2PConfig + connFactory typesP2P.ConnectionFactory +} + +func NewPersistenceAddrBookProvider(bus modules.Bus, p2pCfg modules.P2PConfig, options ...func(*persistenceAddrBookProvider)) *persistenceAddrBookProvider { + pabp := &persistenceAddrBookProvider{ + bus: bus, + p2pCfg: p2pCfg, + connFactory: transport.CreateDialer, // default connection factory, overridable with WithConnectionFactory() + } + + for _, o := range options { + o(pabp) + } + + return pabp +} + +// WithConnectionFactory allows the user to specify a custom connection factory +func WithConnectionFactory(connFactory typesP2P.ConnectionFactory) func(*persistenceAddrBookProvider) { + return func(pabp *persistenceAddrBookProvider) { + pabp.connFactory = connFactory + } +} + +func (pabp *persistenceAddrBookProvider) GetBus() modules.Bus { + return pabp.bus +} + +func (pabp *persistenceAddrBookProvider) SetBus(bus modules.Bus) { + pabp.bus = bus +} + +func (pabp *persistenceAddrBookProvider) GetStakedAddrBookAtHeight(height uint64) (typesP2P.AddrBook, error) { + persistenceReadContext, err := pabp.GetBus().GetPersistenceModule().NewReadContext(int64(height)) + if err != nil { + return nil, err + } + stakedActors, err := persistenceReadContext.GetAllStakedActors(int64(height)) + if err != nil { + return nil, err + } + // TODO(#203): refactor `ValidatorMap`` + validatorMap := make(modules.ValidatorMap, len(stakedActors)) + for _, v := range stakedActors { + validatorMap[v.GetAddress()] = v + } + addrBook, err := pabp.ValidatorMapToAddrBook(validatorMap) + if err != nil { + return nil, err + } + return addrBook, nil +} + +// TODO(#270): These functions will turn into more of a "ActorToAddrBook" when we have a closer +// integration with utility. +func (pabp *persistenceAddrBookProvider) ValidatorMapToAddrBook(validators map[string]modules.Actor) (typesP2P.AddrBook, error) { + book := make(typesP2P.AddrBook, 0) + for _, v := range validators { + networkPeer, err := pabp.ValidatorToNetworkPeer(v) + if err != nil { + log.Println("[WARN] Error connecting to validator: ", err) + continue + } + book = append(book, networkPeer) + } + return book, nil +} + +// TODO(#270): These functions will turn into more of a "ActorToAddrBook" when we have a closer +// integration with utility. +func (pabp *persistenceAddrBookProvider) ValidatorToNetworkPeer(v modules.Actor) (*typesP2P.NetworkPeer, error) { + conn, err := pabp.connFactory(pabp.p2pCfg, v.GetGenericParam()) // service url + if err != nil { + return nil, fmt.Errorf("error resolving addr: %v", err) + } + + pubKey, err := cryptoPocket.NewPublicKey(v.GetPublicKey()) + if err != nil { + return nil, err + } + + peer := &typesP2P.NetworkPeer{ + Dialer: conn, + PublicKey: pubKey, + Address: pubKey.Address(), + ServiceUrl: v.GetGenericParam(), // service url + } + + return peer, nil +} diff --git a/p2p/utils.go b/p2p/utils.go deleted file mode 100644 index 149e1282d..000000000 --- a/p2p/utils.go +++ /dev/null @@ -1,48 +0,0 @@ -package p2p - -import ( - "fmt" - "log" - - typesP2P "github.com/pokt-network/pocket/p2p/types" - cryptoPocket "github.com/pokt-network/pocket/shared/crypto" - "github.com/pokt-network/pocket/shared/modules" -) - -// CLEANUP(drewsky): These functions will turn into more of a "ActorToAddrBook" when we have a closer -// integration with utility. -func ValidatorMapToAddrBook(cfg modules.P2PConfig, validators map[string]modules.Actor) (typesP2P.AddrBook, error) { - book := make(typesP2P.AddrBook, 0) - for _, v := range validators { - networkPeer, err := ValidatorToNetworkPeer(cfg, v) - if err != nil { - log.Println("[WARN] Error connecting to validator: ", err) - continue - } - book = append(book, networkPeer) - } - return book, nil -} - -// CLEANUP(drewsky): These functions will turn into more of a "ActorToAddrBook" when we have a closer -// integration with utility. -func ValidatorToNetworkPeer(cfg modules.P2PConfig, v modules.Actor) (*typesP2P.NetworkPeer, error) { - conn, err := CreateDialer(cfg, v.GetGenericParam()) // service url - if err != nil { - return nil, fmt.Errorf("error resolving addr: %v", err) - } - - pubKey, err := cryptoPocket.NewPublicKey(v.GetPublicKey()) - if err != nil { - return nil, err - } - - peer := &typesP2P.NetworkPeer{ - Dialer: conn, - PublicKey: pubKey, - Address: pubKey.Address(), - ServiceUrl: v.GetGenericParam(), // service url - } - - return peer, nil -} From cb58f21f53b42ae67cd5ce5f6f2d70e1d9cd26a7 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 22:28:05 +0000 Subject: [PATCH 061/143] refactor(P2P): newPeersManagerWithAddrBookProvider unexported --- p2p/raintree/addrbook_utils.go | 2 +- p2p/raintree/peers_manager.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/p2p/raintree/addrbook_utils.go b/p2p/raintree/addrbook_utils.go index 3a8f4cf02..042a0edc8 100644 --- a/p2p/raintree/addrbook_utils.go +++ b/p2p/raintree/addrbook_utils.go @@ -20,7 +20,7 @@ func (n *rainTreeNetwork) getAddrBookLength(level uint32, height uint64) int { // if we are propagating a message from a previous height, we need to instantiate an ephemeral peersManager (without add/remove) if height < n.GetBus().GetConsensusModule().CurrentHeight() { - peersManagerWithAddrBookProvider, err := NewPeersManagerWithAddrBookProvider(n.selfAddr, n.addrBookProvider, height) + peersManagerWithAddrBookProvider, err := newPeersManagerWithAddrBookProvider(n.selfAddr, n.addrBookProvider, height) if err != nil { log.Fatalf("[ERROR] Error initializing rainTreeNetwork peersManagerWithAddrBookProvider: %v", err) } diff --git a/p2p/raintree/peers_manager.go b/p2p/raintree/peers_manager.go index 29640dd7e..2ea63c315 100644 --- a/p2p/raintree/peers_manager.go +++ b/p2p/raintree/peers_manager.go @@ -30,8 +30,8 @@ type peersManager struct { maxNumLevels uint32 } -func NewPeersManagerWithAddrBookProvider(selfAddr cryptoPocket.Address, addrBookProvider typesP2P.AddrBookProvider, height uint64) (*peersManager, error) { - addrBook, err := addrBookProvider(height) +func newPeersManagerWithAddrBookProvider(selfAddr cryptoPocket.Address, addrBookProvider typesP2P.AddrBookProvider, height uint64) (*peersManager, error) { + addrBook, err := addrBookProvider.GetStakedAddrBookAtHeight(height) if err != nil { return nil, err } From 604aa8e1e1a30d47333c259f6e6723403f502880 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 22:28:44 +0000 Subject: [PATCH 062/143] feat(P2P): using addrBook_provider in raintree --- p2p/raintree/network.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/p2p/raintree/network.go b/p2p/raintree/network.go index 5fa6d09dd..1559fe98d 100644 --- a/p2p/raintree/network.go +++ b/p2p/raintree/network.go @@ -6,6 +6,7 @@ import ( "math/rand" "time" + "github.com/pokt-network/pocket/p2p/addrbook_provider" typesP2P "github.com/pokt-network/pocket/p2p/types" "github.com/pokt-network/pocket/shared/codec" cryptoPocket "github.com/pokt-network/pocket/shared/crypto" @@ -33,7 +34,7 @@ type rainTreeNetwork struct { mampoolMaxNonces uint64 } -func NewRainTreeNetwork(addr cryptoPocket.Address, addrBook typesP2P.AddrBook, p2pCfg modules.P2PConfig) typesP2P.Network { +func NewRainTreeNetworkWithAddrBook(addr cryptoPocket.Address, addrBook typesP2P.AddrBook, p2pCfg modules.P2PConfig) typesP2P.Network { pm, err := newPeersManager(addr, addrBook, true) if err != nil { log.Fatalf("[ERROR] Error initializing rainTreeNetwork peersManager: %v", err) @@ -51,11 +52,8 @@ func NewRainTreeNetwork(addr cryptoPocket.Address, addrBook typesP2P.AddrBook, p return typesP2P.Network(n) } -func NewRainTreeNetworkWithAddrBookProvider(addr cryptoPocket.Address, addrBookProvider typesP2P.AddrBookProvider, height uint64, p2pCfg modules.P2PConfig) typesP2P.Network { - addrBook, err := addrBookProvider(height) - if err != nil { - log.Fatalf("[ERROR] Error getting addrBook from addrBookProvider: %v", err) - } +func NewRainTreeNetwork(addr cryptoPocket.Address, bus modules.Bus, p2pCfg modules.P2PConfig, addrBookProvider typesP2P.AddrBookProvider) typesP2P.Network { + addrBook := addrbook_provider.GetAddrBook(bus, addrBookProvider) pm, err := newPeersManager(addr, addrBook, true) if err != nil { @@ -64,12 +62,12 @@ func NewRainTreeNetworkWithAddrBookProvider(addr cryptoPocket.Address, addrBookP n := &rainTreeNetwork{ selfAddr: addr, - addrBookProvider: addrBookProvider, peersManager: pm, nonceSet: make(map[uint64]struct{}), nonceList: make([]uint64, 0, p2pCfg.GetMaxMempoolCount()), + addrBookProvider: addrBookProvider, } - + n.SetBus(bus) return typesP2P.Network(n) } From 0e45a5b7abf3bc4c8691e41f80f4e1ec7252bd7e Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 22:29:08 +0000 Subject: [PATCH 063/143] refactor(P2P): using addrBook_provider in stdnetwork --- p2p/stdnetwork/network.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/p2p/stdnetwork/network.go b/p2p/stdnetwork/network.go index 718daa1f3..03b7c5e27 100644 --- a/p2p/stdnetwork/network.go +++ b/p2p/stdnetwork/network.go @@ -6,21 +6,23 @@ import ( "fmt" "log" - types "github.com/pokt-network/pocket/p2p/types" - + "github.com/pokt-network/pocket/p2p/addrbook_provider" + typesP2P "github.com/pokt-network/pocket/p2p/types" cryptoPocket "github.com/pokt-network/pocket/shared/crypto" "github.com/pokt-network/pocket/shared/modules" ) -var _ types.Network = &network{} +var _ typesP2P.Network = &network{} var _ modules.IntegratableModule = &network{} type network struct { - addrBookMap types.AddrBookMap + addrBookMap typesP2P.AddrBookMap } -func NewNetwork(addrBook types.AddrBook) (n types.Network) { - addrBookMap := make(types.AddrBookMap) +func NewNetwork(bus modules.Bus, p2pCfg modules.P2PConfig, addrBookProvider typesP2P.AddrBookProvider) (n typesP2P.Network) { + addrBook := addrbook_provider.GetAddrBook(bus, addrBookProvider) + + addrBookMap := make(typesP2P.AddrBookMap) for _, peer := range addrBook { addrBookMap[peer.Address.String()] = peer } @@ -58,20 +60,20 @@ func (n *network) HandleNetworkData(data []byte) ([]byte, error) { return data, nil // intentional passthrough } -func (n *network) GetAddrBook() types.AddrBook { - addrBook := make(types.AddrBook, 0) +func (n *network) GetAddrBook() typesP2P.AddrBook { + addrBook := make(typesP2P.AddrBook, 0) for _, p := range n.addrBookMap { addrBook = append(addrBook, p) } return addrBook } -func (n *network) AddPeerToAddrBook(peer *types.NetworkPeer) error { +func (n *network) AddPeerToAddrBook(peer *typesP2P.NetworkPeer) error { n.addrBookMap[peer.Address.String()] = peer return nil } -func (n *network) RemovePeerToAddrBook(peer *types.NetworkPeer) error { +func (n *network) RemovePeerToAddrBook(peer *typesP2P.NetworkPeer) error { delete(n.addrBookMap, peer.Address.String()) return nil } From 1fe30a3deadb70ff367020f5bcac3f3c20092d0a Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 22:29:32 +0000 Subject: [PATCH 064/143] refactor(P2P): simplified module init --- p2p/module.go | 51 ++++++--------------------------------------------- 1 file changed, 6 insertions(+), 45 deletions(-) diff --git a/p2p/module.go b/p2p/module.go index 360e60ebd..1822c3112 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -4,8 +4,10 @@ import ( "fmt" "log" + "github.com/pokt-network/pocket/p2p/addrbook_provider" "github.com/pokt-network/pocket/p2p/raintree" "github.com/pokt-network/pocket/p2p/stdnetwork" + "github.com/pokt-network/pocket/p2p/transport" typesP2P "github.com/pokt-network/pocket/p2p/types" "github.com/pokt-network/pocket/shared/codec" cryptoPocket "github.com/pokt-network/pocket/shared/crypto" @@ -74,7 +76,7 @@ func (*p2pModule) Create(runtimeMgr modules.RuntimeMgr) (modules.Module, error) } p2pCfg := cfg.GetP2PConfig() - l, err := CreateListener(p2pCfg) + l, err := transport.CreateListener(p2pCfg) if err != nil { return nil, err } @@ -120,33 +122,13 @@ func (m *p2pModule) Start() error { telemetry.P2P_NODE_STARTED_TIMESERIES_METRIC_DESCRIPTION, ) - currentHeight := m.GetBus().GetConsensusModule().CurrentHeight() - var ( - addrBook typesP2P.AddrBook - err error - ) - - if m.GetBus().GetPersistenceModule() == nil { - // TODO (#203): refactor this. - addrBook, err = ValidatorMapToAddrBook(m.p2pCfg, m.GetBus().GetConsensusModule().ValidatorMap()) - } else { - addrBook, err = m.getStakedAddrBookAtHeight(currentHeight) - } - if err != nil { - return err - } + addrbookProvider := addrbook_provider.NewPersistenceAddrBookProvider(m.GetBus(), m.p2pCfg) if m.p2pCfg.GetUseRainTree() { - if m.GetBus().GetPersistenceModule() == nil { - // TODO (#203): refactor this. - m.network = raintree.NewRainTreeNetwork(m.address, addrBook, m.p2pCfg) - } else { - m.network = raintree.NewRainTreeNetworkWithAddrBookProvider(m.address, m.getStakedAddrBookAtHeight, currentHeight, m.p2pCfg) - } + m.network = raintree.NewRainTreeNetwork(m.address, m.GetBus(), m.p2pCfg, addrbookProvider) } else { - m.network = stdnetwork.NewNetwork(addrBook) + m.network = stdnetwork.NewNetwork(m.GetBus(), m.p2pCfg, addrbookProvider) } - m.network.SetBus(m.GetBus()) go func() { for { @@ -167,27 +149,6 @@ func (m *p2pModule) Start() error { return nil } -func (m *p2pModule) getStakedAddrBookAtHeight(height uint64) (typesP2P.AddrBook, error) { - persistenceReadContext, err := m.GetBus().GetPersistenceModule().NewReadContext(int64(height)) - if err != nil { - return nil, err - } - stakedActors, err := persistenceReadContext.GetAllStakedActors(int64(height)) - if err != nil { - return nil, err - } - // TODO(#203): refactor `ValidatorMap`` - validatorMap := make(modules.ValidatorMap, len(stakedActors)) - for _, v := range stakedActors { - validatorMap[v.GetAddress()] = v - } - addrBook, err := ValidatorMapToAddrBook(m.p2pCfg, validatorMap) - if err != nil { - return nil, err - } - return addrBook, nil -} - func (m *p2pModule) Stop() error { log.Println("Stopping network module") if err := m.listener.Close(); err != nil { From 005ecfbdd21c863c0b085b1c6530a544d390684c Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 22:30:00 +0000 Subject: [PATCH 065/143] feat(P2P): AddrBookProvider interface --- p2p/types/addr_book.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/p2p/types/addr_book.go b/p2p/types/addr_book.go index 912ee7265..2a13de64d 100644 --- a/p2p/types/addr_book.go +++ b/p2p/types/addr_book.go @@ -1,5 +1,9 @@ package types +//go:generate mockgen -source=$GOFILE -destination=./mocks/addrbook_provider_mock.go github.com/pokt-network/pocket/p2p/types AddrBookProvider + +import "github.com/pokt-network/pocket/shared/modules" + // AddrBook is a way of representing NetworkPeer sets type AddrBook []*NetworkPeer @@ -8,5 +12,9 @@ type AddrBook []*NetworkPeer // Since maps cannot be sorted arbitrarily in Go, to achieve sorting, we need to rely on `addrList` which is a slice of addresses/strings and therefore we can sort it the way we want. type AddrBookMap map[string]*NetworkPeer -// AddrBookProvider is a way of accessing the AddrBook per height -type AddrBookProvider func(height uint64) (AddrBook, error) +// AddrBookProvider is an interface that provides AddrBook accessors +type AddrBookProvider interface { + GetStakedAddrBookAtHeight(height uint64) (AddrBook, error) + ValidatorMapToAddrBook(validators map[string]modules.Actor) (AddrBook, error) + ValidatorToNetworkPeer(v modules.Actor) (*NetworkPeer, error) +} From adc2783bf46f0375a258d04160af10fce15217ed Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 22:30:33 +0000 Subject: [PATCH 066/143] test(P2P): updated raintree tests and mocks --- p2p/raintree/network_test.go | 13 +++++++++++-- p2p/raintree/peers_manager_test.go | 19 ++++++++++++++++--- p2p/raintree/utils_test.go | 25 +++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 p2p/raintree/utils_test.go diff --git a/p2p/raintree/network_test.go b/p2p/raintree/network_test.go index be812c5d9..c9c1860ca 100644 --- a/p2p/raintree/network_test.go +++ b/p2p/raintree/network_test.go @@ -23,7 +23,11 @@ func TestRainTreeNetwork_AddPeerToAddrBook(t *testing.T) { addrBook := getAddrBook(nil, 0) addrBook = append(addrBook, &typesP2P.NetworkPeer{Address: selfAddr}) - network := NewRainTreeNetwork(selfAddr, addrBook, mockP2PCfg).(*rainTreeNetwork) + + busMock := mockDummyBus(ctrl) + addrBookProviderMock := mockAddrBookProvider(ctrl, addrBook) + + network := NewRainTreeNetwork(selfAddr, busMock, mockP2PCfg, addrBookProviderMock).(*rainTreeNetwork) peerAddr, err := cryptoPocket.GenerateAddress() require.NoError(t, err) @@ -47,6 +51,7 @@ func TestRainTreeNetwork_AddPeerToAddrBook(t *testing.T) { func TestRainTreeNetwork_RemovePeerToAddrBook(t *testing.T) { ctrl := gomock.NewController(t) + mockP2PCfg := mockModules.NewMockP2PConfig(ctrl) mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() @@ -57,7 +62,11 @@ func TestRainTreeNetwork_RemovePeerToAddrBook(t *testing.T) { require.NoError(t, err) selfPeer := &typesP2P.NetworkPeer{Address: selfAddr} addrBook = append(addrBook, &typesP2P.NetworkPeer{Address: selfAddr}) - network := NewRainTreeNetwork(selfAddr, addrBook, mockP2PCfg).(*rainTreeNetwork) + + busMock := mockDummyBus(ctrl) + addrBookProviderMock := mockAddrBookProvider(ctrl, addrBook) + + network := NewRainTreeNetwork(selfAddr, busMock, mockP2PCfg, addrBookProviderMock).(*rainTreeNetwork) stateView := network.peersManager.getNetworkView() require.Equal(t, numAddressesInAddressBook+1, len(stateView.addrList)) // +1 to account for self in the addrBook as well diff --git a/p2p/raintree/peers_manager_test.go b/p2p/raintree/peers_manager_test.go index 8697075aa..3b0ee20bc 100644 --- a/p2p/raintree/peers_manager_test.go +++ b/p2p/raintree/peers_manager_test.go @@ -77,7 +77,11 @@ func TestRainTreeAddrBookUtilsHandleUpdate(t *testing.T) { t.Run(fmt.Sprintf("n=%d", n), func(t *testing.T) { addrBook := getAddrBook(t, n-1) addrBook = append(addrBook, &types.NetworkPeer{Address: addr}) - network := NewRainTreeNetwork(addr, addrBook, mockP2PCfg).(*rainTreeNetwork) + + mockBus := mockDummyBus(ctrl) + mockAddrBookProvider := mockAddrBookProvider(ctrl, addrBook) + + network := NewRainTreeNetwork(addr, mockBus, mockP2PCfg, mockAddrBookProvider).(*rainTreeNetwork) peersManagerStateView := network.peersManager.getNetworkView() @@ -115,7 +119,11 @@ func BenchmarkAddrBookUpdates(b *testing.B) { b.Run(fmt.Sprintf("n=%d", n), func(b *testing.B) { addrBook := getAddrBook(nil, n-1) addrBook = append(addrBook, &types.NetworkPeer{Address: addr}) - network := NewRainTreeNetwork(addr, addrBook, mockP2PCfg).(*rainTreeNetwork) + + mockBus := mockDummyBus(ctrl) + mockAddrBookProvider := mockAddrBookProvider(ctrl, addrBook) + + network := NewRainTreeNetwork(addr, mockBus, mockP2PCfg, mockAddrBookProvider).(*rainTreeNetwork) peersManagerStateView := network.peersManager.getNetworkView() @@ -198,11 +206,16 @@ func testRainTreeMessageTargets(t *testing.T, expectedMsgProp *ExpectedRainTreeM consensusMock := modulesMock.NewMockConsensusModule(ctrl) consensusMock.EXPECT().CurrentHeight().Return(uint64(1)).AnyTimes() busMock.EXPECT().GetConsensusModule().Return(consensusMock).AnyTimes() + persistenceMock := modulesMock.NewMockPersistenceModule(ctrl) + busMock.EXPECT().GetPersistenceModule().Return(persistenceMock).AnyTimes() mockP2PCfg := modulesMock.NewMockP2PConfig(ctrl) mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() addrBook := getAlphabetAddrBook(expectedMsgProp.numNodes) - network := NewRainTreeNetwork([]byte{expectedMsgProp.orig}, addrBook, mockP2PCfg).(*rainTreeNetwork) + mockAddrBookProvider := mockAddrBookProvider(ctrl, addrBook) + + network := NewRainTreeNetwork([]byte{expectedMsgProp.orig}, busMock, mockP2PCfg, mockAddrBookProvider).(*rainTreeNetwork) + network.SetBus(busMock) peersManagerStateView := network.peersManager.getNetworkView() diff --git a/p2p/raintree/utils_test.go b/p2p/raintree/utils_test.go new file mode 100644 index 000000000..d81fc2237 --- /dev/null +++ b/p2p/raintree/utils_test.go @@ -0,0 +1,25 @@ +package raintree + +import ( + "github.com/golang/mock/gomock" + typesP2P "github.com/pokt-network/pocket/p2p/types" + mocksP2P "github.com/pokt-network/pocket/p2p/types/mocks" + mockModules "github.com/pokt-network/pocket/shared/modules/mocks" +) + +func mockDummyBus(ctrl *gomock.Controller) *mockModules.MockBus { + busMock := mockModules.NewMockBus(ctrl) + busMock.EXPECT().GetPersistenceModule().Return(nil).AnyTimes() + consensusMock := mockModules.NewMockConsensusModule(ctrl) + consensusMock.EXPECT().CurrentHeight().Return(uint64(0)).AnyTimes() + consensusMock.EXPECT().ValidatorMap().Return(nil).AnyTimes() + busMock.EXPECT().GetConsensusModule().Return(consensusMock).AnyTimes() + return busMock +} + +func mockAddrBookProvider(ctrl *gomock.Controller, addrBook typesP2P.AddrBook) *mocksP2P.MockAddrBookProvider { + addrBookProviderMock := mocksP2P.NewMockAddrBookProvider(ctrl) + addrBookProviderMock.EXPECT().ValidatorMapToAddrBook(gomock.Any()).Return(addrBook, nil).AnyTimes() + addrBookProviderMock.EXPECT().GetStakedAddrBookAtHeight(gomock.Any()).Return(addrBook, nil).AnyTimes() + return addrBookProviderMock +} From d4b5f7d3a67eb86d240d9a7be63f613388169989 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 22:42:24 +0000 Subject: [PATCH 067/143] refactor(P2P): removed event handling (currently unused) --- consensus/consensus_tests/utils_test.go | 1 - p2p/module.go | 24 ------------------------ 2 files changed, 25 deletions(-) diff --git a/consensus/consensus_tests/utils_test.go b/consensus/consensus_tests/utils_test.go index 0570a87d0..208224177 100644 --- a/consensus/consensus_tests/utils_test.go +++ b/consensus/consensus_tests/utils_test.go @@ -342,7 +342,6 @@ func baseP2PMock(t *testing.T, testChannel modules.EventsChannel) *modulesMock.M testChannel <- *e }). AnyTimes() - p2pMock.EXPECT().HandleEvent(gomock.Any()).Return(nil).AnyTimes() return p2pMock } diff --git a/p2p/module.go b/p2p/module.go index 1822c3112..54f5a52bb 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -9,7 +9,6 @@ import ( "github.com/pokt-network/pocket/p2p/stdnetwork" "github.com/pokt-network/pocket/p2p/transport" typesP2P "github.com/pokt-network/pocket/p2p/types" - "github.com/pokt-network/pocket/shared/codec" cryptoPocket "github.com/pokt-network/pocket/shared/crypto" "github.com/pokt-network/pocket/shared/messaging" "github.com/pokt-network/pocket/shared/modules" @@ -34,29 +33,6 @@ type p2pModule struct { network typesP2P.Network } -// HandleEvent implements modules.P2PModule -func (m *p2pModule) HandleEvent(message *anypb.Any) error { - switch message.MessageName() { - case messaging.BeforeHeightChangedEventType: - msg, err := codec.GetCodec().FromAny(message) - if err != nil { - return err - } - _, ok := msg.(*messaging.BeforeHeightChangedEvent) - if !ok { - return fmt.Errorf("failed to cast message to BeforeHeightChangedEvent") - } - - // DISCUSS (https://github.com/pokt-network/pocket/pull/374#issuecomment-1341350786): decide if we want a pull or push model for integrating with persistence - // I am leaving this code while we are in code-review as a placeholder but it will be either removed or implemented fully - // with P2P handling the message and adjusting the addrBook accordingly - - default: - return typesP2P.ErrUnknownEventType(message.MessageName()) - } - return nil -} - // TECHDEBT(drewsky): Discuss how to best expose/access `Address` throughout the codebase. func (m *p2pModule) GetAddress() (cryptoPocket.Address, error) { return m.address, nil From 911d01b106d2d4d2cb0b5ddd0ef48150bde0f8a3 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 22:43:03 +0000 Subject: [PATCH 068/143] refactor(shared): updated event handling --- shared/modules/p2p_module.go | 2 -- shared/node.go | 5 ++--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/shared/modules/p2p_module.go b/shared/modules/p2p_module.go index 9b1b079d5..d3ece2fe7 100644 --- a/shared/modules/p2p_module.go +++ b/shared/modules/p2p_module.go @@ -11,8 +11,6 @@ type P2PModule interface { Module ConfigurableModule - HandleEvent(*anypb.Any) error - Broadcast(msg *anypb.Any) error Send(addr cryptoPocket.Address, msg *anypb.Any) error GetAddress() (cryptoPocket.Address, error) diff --git a/shared/node.go b/shared/node.go index 076880fe2..869694b07 100644 --- a/shared/node.go +++ b/shared/node.go @@ -160,10 +160,9 @@ func (node *Node) handleEvent(message *messaging.PocketEnvelope) error { case messaging.NodeStartedEventType: log.Println("[NOOP] Received NodeStartedEvent") case messaging.BeforeHeightChangedEventType: - log.Println("Received BeforeNewHeightEvent") - node.GetBus().GetP2PModule().HandleEvent(message.Content) + log.Println("[NOOP] Received BeforeNewHeightEvent") case messaging.HeightChangedEventType: - log.Println("[NOOP] Received HeightChangedEventType") + log.Println("[NOOP] Received HeightChangedEvent") case consensus.HotstuffMessageContentType: return node.GetBus().GetConsensusModule().HandleMessage(message.Content) case utility.TransactionGossipMessageContentType: From d53f40a7c9c2e5ee7f727d4f7107c539b1313836 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 22:55:16 +0000 Subject: [PATCH 069/143] refactor(P2P): Validator -> Actor --- p2p/addrbook_provider/getter.go | 2 +- p2p/addrbook_provider/persistence.go | 12 ++++-------- p2p/types/addr_book.go | 4 ++-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/p2p/addrbook_provider/getter.go b/p2p/addrbook_provider/getter.go index ac0f8b105..109287f37 100644 --- a/p2p/addrbook_provider/getter.go +++ b/p2p/addrbook_provider/getter.go @@ -17,7 +17,7 @@ func GetAddrBook(bus modules.Bus, addrBookProvider typesP2P.AddrBookProvider) ty ) if bus.GetPersistenceModule() == nil { // TODO (#203): refactor this. - addrBook, err = addrBookProvider.ValidatorMapToAddrBook(bus.GetConsensusModule().ValidatorMap()) + addrBook, err = addrBookProvider.ActorToAddrBook(bus.GetConsensusModule().ValidatorMap()) } else { addrBook, err = addrBookProvider.GetStakedAddrBookAtHeight(bus.GetConsensusModule().CurrentHeight()) } diff --git a/p2p/addrbook_provider/persistence.go b/p2p/addrbook_provider/persistence.go index f3451664b..f130fdee1 100644 --- a/p2p/addrbook_provider/persistence.go +++ b/p2p/addrbook_provider/persistence.go @@ -62,19 +62,17 @@ func (pabp *persistenceAddrBookProvider) GetStakedAddrBookAtHeight(height uint64 for _, v := range stakedActors { validatorMap[v.GetAddress()] = v } - addrBook, err := pabp.ValidatorMapToAddrBook(validatorMap) + addrBook, err := pabp.ActorToAddrBook(validatorMap) if err != nil { return nil, err } return addrBook, nil } -// TODO(#270): These functions will turn into more of a "ActorToAddrBook" when we have a closer -// integration with utility. -func (pabp *persistenceAddrBookProvider) ValidatorMapToAddrBook(validators map[string]modules.Actor) (typesP2P.AddrBook, error) { +func (pabp *persistenceAddrBookProvider) ActorToAddrBook(validators map[string]modules.Actor) (typesP2P.AddrBook, error) { book := make(typesP2P.AddrBook, 0) for _, v := range validators { - networkPeer, err := pabp.ValidatorToNetworkPeer(v) + networkPeer, err := pabp.ActorToNetworkPeer(v) if err != nil { log.Println("[WARN] Error connecting to validator: ", err) continue @@ -84,9 +82,7 @@ func (pabp *persistenceAddrBookProvider) ValidatorMapToAddrBook(validators map[s return book, nil } -// TODO(#270): These functions will turn into more of a "ActorToAddrBook" when we have a closer -// integration with utility. -func (pabp *persistenceAddrBookProvider) ValidatorToNetworkPeer(v modules.Actor) (*typesP2P.NetworkPeer, error) { +func (pabp *persistenceAddrBookProvider) ActorToNetworkPeer(v modules.Actor) (*typesP2P.NetworkPeer, error) { conn, err := pabp.connFactory(pabp.p2pCfg, v.GetGenericParam()) // service url if err != nil { return nil, fmt.Errorf("error resolving addr: %v", err) diff --git a/p2p/types/addr_book.go b/p2p/types/addr_book.go index 2a13de64d..4cd17947a 100644 --- a/p2p/types/addr_book.go +++ b/p2p/types/addr_book.go @@ -15,6 +15,6 @@ type AddrBookMap map[string]*NetworkPeer // AddrBookProvider is an interface that provides AddrBook accessors type AddrBookProvider interface { GetStakedAddrBookAtHeight(height uint64) (AddrBook, error) - ValidatorMapToAddrBook(validators map[string]modules.Actor) (AddrBook, error) - ValidatorToNetworkPeer(v modules.Actor) (*NetworkPeer, error) + ActorToAddrBook(validators map[string]modules.Actor) (AddrBook, error) + ActorToNetworkPeer(v modules.Actor) (*NetworkPeer, error) } From 0823894b0d1dca62220df68fe61910725b81eadc Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 13 Dec 2022 22:58:20 +0000 Subject: [PATCH 070/143] test(P2P): fix tests post renaming --- p2p/raintree/utils_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p2p/raintree/utils_test.go b/p2p/raintree/utils_test.go index d81fc2237..2117126f2 100644 --- a/p2p/raintree/utils_test.go +++ b/p2p/raintree/utils_test.go @@ -19,7 +19,7 @@ func mockDummyBus(ctrl *gomock.Controller) *mockModules.MockBus { func mockAddrBookProvider(ctrl *gomock.Controller, addrBook typesP2P.AddrBook) *mocksP2P.MockAddrBookProvider { addrBookProviderMock := mocksP2P.NewMockAddrBookProvider(ctrl) - addrBookProviderMock.EXPECT().ValidatorMapToAddrBook(gomock.Any()).Return(addrBook, nil).AnyTimes() + addrBookProviderMock.EXPECT().ActorToAddrBook(gomock.Any()).Return(addrBook, nil).AnyTimes() addrBookProviderMock.EXPECT().GetStakedAddrBookAtHeight(gomock.Any()).Return(addrBook, nil).AnyTimes() return addrBookProviderMock } From 86ae4d8a5cb16f2d06edeaff02336f627a0faec4 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 14 Dec 2022 21:34:38 +0000 Subject: [PATCH 071/143] Update p2p/addrbook_provider/getter.go Co-authored-by: Daniel Olshansky --- p2p/addrbook_provider/getter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p2p/addrbook_provider/getter.go b/p2p/addrbook_provider/getter.go index ac0f8b105..88ac72f14 100644 --- a/p2p/addrbook_provider/getter.go +++ b/p2p/addrbook_provider/getter.go @@ -9,7 +9,7 @@ import ( // GetAddrBook is a helper function that returns the addrBook depending on the availability of the persistence module // -// this is a temporary solution simply used to centralize the logic that is going to be refactored in #331 and #203 +// HACK: This is a temporary solution simply used to centralize the logic that is going to be refactored in #331 and #203 func GetAddrBook(bus modules.Bus, addrBookProvider typesP2P.AddrBookProvider) typesP2P.AddrBook { var ( addrBook typesP2P.AddrBook From 11a41eb419ad8f0dd76124a0849caf8e031efb07 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 14 Dec 2022 21:40:02 +0000 Subject: [PATCH 072/143] chore(P2P): improved TODO --- p2p/addrbook_provider/getter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p2p/addrbook_provider/getter.go b/p2p/addrbook_provider/getter.go index 88ac72f14..2f587e7bc 100644 --- a/p2p/addrbook_provider/getter.go +++ b/p2p/addrbook_provider/getter.go @@ -16,7 +16,7 @@ func GetAddrBook(bus modules.Bus, addrBookProvider typesP2P.AddrBookProvider) ty err error ) if bus.GetPersistenceModule() == nil { - // TODO (#203): refactor this. + // TODO(#203): refactor or remove this once `ValidatorMap` logic is encapsulated. addrBook, err = addrBookProvider.ValidatorMapToAddrBook(bus.GetConsensusModule().ValidatorMap()) } else { addrBook, err = addrBookProvider.GetStakedAddrBookAtHeight(bus.GetConsensusModule().CurrentHeight()) From 7c9fe8c1db76e44230f684bfdb730c670bb19644 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 14 Dec 2022 21:40:16 +0000 Subject: [PATCH 073/143] refactor(P2P): improved error handling --- p2p/addrbook_provider/getter.go | 13 ++----------- p2p/raintree/network.go | 5 ++++- p2p/stdnetwork/network.go | 5 ++++- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/p2p/addrbook_provider/getter.go b/p2p/addrbook_provider/getter.go index 2f587e7bc..d08704e81 100644 --- a/p2p/addrbook_provider/getter.go +++ b/p2p/addrbook_provider/getter.go @@ -1,8 +1,6 @@ package addrbook_provider import ( - "log" - typesP2P "github.com/pokt-network/pocket/p2p/types" "github.com/pokt-network/pocket/shared/modules" ) @@ -10,19 +8,12 @@ import ( // GetAddrBook is a helper function that returns the addrBook depending on the availability of the persistence module // // HACK: This is a temporary solution simply used to centralize the logic that is going to be refactored in #331 and #203 -func GetAddrBook(bus modules.Bus, addrBookProvider typesP2P.AddrBookProvider) typesP2P.AddrBook { - var ( - addrBook typesP2P.AddrBook - err error - ) +func GetAddrBook(bus modules.Bus, addrBookProvider typesP2P.AddrBookProvider) (addrBook typesP2P.AddrBook, err error) { if bus.GetPersistenceModule() == nil { // TODO(#203): refactor or remove this once `ValidatorMap` logic is encapsulated. addrBook, err = addrBookProvider.ValidatorMapToAddrBook(bus.GetConsensusModule().ValidatorMap()) } else { addrBook, err = addrBookProvider.GetStakedAddrBookAtHeight(bus.GetConsensusModule().CurrentHeight()) } - if err != nil { - log.Fatalf("[ERROR] Error getting addrBook: %v", err) - } - return addrBook + return addrBook, err } diff --git a/p2p/raintree/network.go b/p2p/raintree/network.go index 1559fe98d..2251d282a 100644 --- a/p2p/raintree/network.go +++ b/p2p/raintree/network.go @@ -53,7 +53,10 @@ func NewRainTreeNetworkWithAddrBook(addr cryptoPocket.Address, addrBook typesP2P } func NewRainTreeNetwork(addr cryptoPocket.Address, bus modules.Bus, p2pCfg modules.P2PConfig, addrBookProvider typesP2P.AddrBookProvider) typesP2P.Network { - addrBook := addrbook_provider.GetAddrBook(bus, addrBookProvider) + addrBook, err := addrbook_provider.GetAddrBook(bus, addrBookProvider) + if err != nil { + log.Fatalf("[ERROR] Error getting addrBook: %v", err) + } pm, err := newPeersManager(addr, addrBook, true) if err != nil { diff --git a/p2p/stdnetwork/network.go b/p2p/stdnetwork/network.go index 03b7c5e27..aa69a579e 100644 --- a/p2p/stdnetwork/network.go +++ b/p2p/stdnetwork/network.go @@ -20,7 +20,10 @@ type network struct { } func NewNetwork(bus modules.Bus, p2pCfg modules.P2PConfig, addrBookProvider typesP2P.AddrBookProvider) (n typesP2P.Network) { - addrBook := addrbook_provider.GetAddrBook(bus, addrBookProvider) + addrBook, err := addrbook_provider.GetAddrBook(bus, addrBookProvider) + if err != nil { + log.Fatalf("[ERROR] Error getting addrBook: %v", err) + } addrBookMap := make(typesP2P.AddrBookMap) for _, peer := range addrBook { From 1c65cb97ff9396211bd1be4a72f6afa308dfed49 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 14 Dec 2022 21:41:53 +0000 Subject: [PATCH 074/143] refactor(P2P): renamed DefaultP2PMempoolMaxNonces to DefaultP2PMempoolMaxNonceCount --- p2p/raintree/network_test.go | 4 ++-- p2p/raintree/peers_manager_test.go | 6 +++--- runtime/defaults/defaults.go | 34 +++++++++++++++--------------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/p2p/raintree/network_test.go b/p2p/raintree/network_test.go index c9c1860ca..41bba6567 100644 --- a/p2p/raintree/network_test.go +++ b/p2p/raintree/network_test.go @@ -14,7 +14,7 @@ import ( func TestRainTreeNetwork_AddPeerToAddrBook(t *testing.T) { ctrl := gomock.NewController(t) mockP2PCfg := mockModules.NewMockP2PConfig(ctrl) - mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() + mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonceCount).AnyTimes() // starting with an empty address book and only self selfAddr, err := cryptoPocket.GenerateAddress() @@ -53,7 +53,7 @@ func TestRainTreeNetwork_RemovePeerToAddrBook(t *testing.T) { ctrl := gomock.NewController(t) mockP2PCfg := mockModules.NewMockP2PConfig(ctrl) - mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() + mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonceCount).AnyTimes() // starting with an address book having only self and an arbitrary number of peers `numAddressesInAddressBook`` numAddressesInAddressBook := 3 diff --git a/p2p/raintree/peers_manager_test.go b/p2p/raintree/peers_manager_test.go index 3b0ee20bc..27b4a2dbd 100644 --- a/p2p/raintree/peers_manager_test.go +++ b/p2p/raintree/peers_manager_test.go @@ -38,7 +38,7 @@ type ExpectedRainTreeMessageProp struct { func TestRainTreeAddrBookUtilsHandleUpdate(t *testing.T) { ctrl := gomock.NewController(t) mockP2PCfg := modulesMock.NewMockP2PConfig(ctrl) - mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() + mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonceCount).AnyTimes() addr, err := cryptoPocket.GenerateAddress() require.NoError(t, err) @@ -95,7 +95,7 @@ func TestRainTreeAddrBookUtilsHandleUpdate(t *testing.T) { func BenchmarkAddrBookUpdates(b *testing.B) { ctrl := gomock.NewController(gomock.TestReporter(b)) mockP2PCfg := modulesMock.NewMockP2PConfig(ctrl) - mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() + mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonceCount).AnyTimes() addr, err := cryptoPocket.GenerateAddress() require.NoError(b, err) @@ -209,7 +209,7 @@ func testRainTreeMessageTargets(t *testing.T, expectedMsgProp *ExpectedRainTreeM persistenceMock := modulesMock.NewMockPersistenceModule(ctrl) busMock.EXPECT().GetPersistenceModule().Return(persistenceMock).AnyTimes() mockP2PCfg := modulesMock.NewMockP2PConfig(ctrl) - mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonces).AnyTimes() + mockP2PCfg.EXPECT().GetMaxMempoolCount().Return(defaults.DefaultP2PMempoolMaxNonceCount).AnyTimes() addrBook := getAlphabetAddrBook(expectedMsgProp.numNodes) mockAddrBookProvider := mockAddrBookProvider(ctrl, addrBook) diff --git a/runtime/defaults/defaults.go b/runtime/defaults/defaults.go index ee5c7b970..d127d7e71 100644 --- a/runtime/defaults/defaults.go +++ b/runtime/defaults/defaults.go @@ -15,21 +15,21 @@ const ( // TODO: some of these defaults are used for production while others are used for testing. Need to separate them. var ( - DefaultChains = []string{"0001"} - DefaultServiceURL = "" - DefaultStakeAmount = big.NewInt(1000000000000) - DefaultStakeAmountString = converters.BigIntToString(DefaultStakeAmount) - DefaultMaxRelays = big.NewInt(1000000) - DefaultMaxRelaysString = converters.BigIntToString(DefaultMaxRelays) - DefaultAccountAmount = big.NewInt(100000000000000) - DefaultAccountAmountString = converters.BigIntToString(DefaultAccountAmount) - DefaultPauseHeight = int64(-1) - DefaultUnstakingHeight = int64(-1) - DefaultChainID = "testnet" - DefaultMaxBlockBytes = uint64(4000000) - ServiceUrlFormat = "node%d.consensus:8080" - DefaultRpcPort = defaultRPCPort - DefaultRpcTimeout = uint64(defaultRPCTimeout) - DefaultRemoteCLIURL = fmt.Sprintf("http://%s:%s", defaultRPCHost, defaultRPCPort) - DefaultP2PMempoolMaxNonces = uint64(1e6) + DefaultChains = []string{"0001"} + DefaultServiceURL = "" + DefaultStakeAmount = big.NewInt(1000000000000) + DefaultStakeAmountString = converters.BigIntToString(DefaultStakeAmount) + DefaultMaxRelays = big.NewInt(1000000) + DefaultMaxRelaysString = converters.BigIntToString(DefaultMaxRelays) + DefaultAccountAmount = big.NewInt(100000000000000) + DefaultAccountAmountString = converters.BigIntToString(DefaultAccountAmount) + DefaultPauseHeight = int64(-1) + DefaultUnstakingHeight = int64(-1) + DefaultChainID = "testnet" + DefaultMaxBlockBytes = uint64(4000000) + ServiceUrlFormat = "node%d.consensus:8080" + DefaultRpcPort = defaultRPCPort + DefaultRpcTimeout = uint64(defaultRPCTimeout) + DefaultRemoteCLIURL = fmt.Sprintf("http://%s:%s", defaultRPCHost, defaultRPCPort) + DefaultP2PMempoolMaxNonceCount = uint64(1e6) ) From d8fbd3574eae27d197fd311c134fe3b399239e05 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 14 Dec 2022 21:48:23 +0000 Subject: [PATCH 075/143] =?UTF-8?q?refactor(Shared):=20removed=20height=20?= =?UTF-8?q?related=20events,=20premature.=20KISS=20=F0=9F=92=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- consensus/pacemaker.go | 21 --------------------- shared/messaging/events.go | 4 +--- shared/messaging/messages_test.go | 8 -------- shared/messaging/proto/events.proto | 8 -------- shared/node.go | 4 ---- 5 files changed, 1 insertion(+), 44 deletions(-) diff --git a/consensus/pacemaker.go b/consensus/pacemaker.go index 7995150ac..bb7b3c3ca 100644 --- a/consensus/pacemaker.go +++ b/consensus/pacemaker.go @@ -8,7 +8,6 @@ import ( consensusTelemetry "github.com/pokt-network/pocket/consensus/telemetry" typesCons "github.com/pokt-network/pocket/consensus/types" - "github.com/pokt-network/pocket/shared/messaging" "github.com/pokt-network/pocket/shared/modules" ) @@ -205,15 +204,11 @@ func (p *paceMaker) InterruptRound() { func (p *paceMaker) NewHeight() { p.consensusMod.nodeLog(typesCons.PacemakerNewHeight(p.consensusMod.CurrentHeight() + 1)) - p.onBeforeNewHeight() - p.consensusMod.height++ p.consensusMod.resetForNewHeight() p.startNextView(nil, false) // TODO(design): We are omitting CommitQC and TimeoutQC here. - p.onAfterNewHeight() - p.consensusMod. GetBus(). GetTelemetryModule(). @@ -267,19 +262,3 @@ func (p *paceMaker) getStepTimeout(round uint64) timePkg.Duration { baseTimeout := timePkg.Duration(int64(timePkg.Millisecond) * int64(p.pacemakerCfg.GetTimeoutMsec())) return baseTimeout } - -func (p *paceMaker) onBeforeNewHeight() { - event, err := messaging.PackMessage(&messaging.BeforeHeightChangedEvent{CurrentHeight: p.consensusMod.CurrentHeight()}) - if err != nil { - log.Printf("[WARN] error packing message: %v\n", err) - } - p.GetBus().PublishEventToBus(event) -} - -func (p *paceMaker) onAfterNewHeight() { - event, err := messaging.PackMessage(&messaging.HeightChangedEvent{NewHeight: p.consensusMod.CurrentHeight()}) - if err != nil { - log.Printf("[WARN] error packing message: %v\n", err) - } - p.GetBus().PublishEventToBus(event) -} diff --git a/shared/messaging/events.go b/shared/messaging/events.go index 7c38a599b..1ccfdf0c0 100644 --- a/shared/messaging/events.go +++ b/shared/messaging/events.go @@ -1,7 +1,5 @@ package messaging const ( - NodeStartedEventType = "pocket.NodeStartedEvent" - BeforeHeightChangedEventType = "pocket.BeforeHeightChangedEvent" - HeightChangedEventType = "pocket.HeightChangedEvent" + NodeStartedEventType = "pocket.NodeStartedEvent" ) diff --git a/shared/messaging/messages_test.go b/shared/messaging/messages_test.go index 6c26ac67c..9e6b12254 100644 --- a/shared/messaging/messages_test.go +++ b/shared/messaging/messages_test.go @@ -30,14 +30,6 @@ func TestPocketEnvelope_GetContentType(t *testing.T) { msg: &typesCons.HotstuffMessage{}, wantContentType: consensus.HotstuffMessageContentType, }, - { - msg: &messaging.BeforeHeightChangedEvent{}, - wantContentType: messaging.BeforeHeightChangedEventType, - }, - { - msg: &messaging.HeightChangedEvent{}, - wantContentType: messaging.HeightChangedEventType, - }, { msg: &typesUtil.TransactionGossipMessage{}, wantContentType: utility.TransactionGossipMessageContentType, diff --git a/shared/messaging/proto/events.proto b/shared/messaging/proto/events.proto index 5840d335a..22356bcc7 100644 --- a/shared/messaging/proto/events.proto +++ b/shared/messaging/proto/events.proto @@ -5,11 +5,3 @@ package pocket; option go_package = "github.com/pokt-network/pocket/shared/messaging"; message NodeStartedEvent {} - -message BeforeHeightChangedEvent { - uint64 current_height = 1; -} - -message HeightChangedEvent { - uint64 new_height = 1; -} diff --git a/shared/node.go b/shared/node.go index 869694b07..3b4dac2a7 100644 --- a/shared/node.go +++ b/shared/node.go @@ -159,10 +159,6 @@ func (node *Node) handleEvent(message *messaging.PocketEnvelope) error { switch contentType { case messaging.NodeStartedEventType: log.Println("[NOOP] Received NodeStartedEvent") - case messaging.BeforeHeightChangedEventType: - log.Println("[NOOP] Received BeforeNewHeightEvent") - case messaging.HeightChangedEventType: - log.Println("[NOOP] Received HeightChangedEvent") case consensus.HotstuffMessageContentType: return node.GetBus().GetConsensusModule().HandleMessage(message.Content) case utility.TransactionGossipMessageContentType: From b2fa44fd725999f45cddd4eff6cd2ddfc394102c Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 14 Dec 2022 22:36:29 +0000 Subject: [PATCH 076/143] refactor(persistence): improved GetAllStakedActors, moved from genesis.go to actor.go --- persistence/actor.go | 138 +++++++++++++++++++++++++++++++++++++++ persistence/genesis.go | 143 ----------------------------------------- 2 files changed, 138 insertions(+), 143 deletions(-) create mode 100644 persistence/actor.go diff --git a/persistence/actor.go b/persistence/actor.go new file mode 100644 index 000000000..c1c1db365 --- /dev/null +++ b/persistence/actor.go @@ -0,0 +1,138 @@ +package persistence + +import ( + "github.com/pokt-network/pocket/persistence/types" + "github.com/pokt-network/pocket/shared/modules" +) + +// TODO(pocket/issues/149): All of the functions below following a structure similar to `GetAll` +// can easily be refactored and condensed into a single function using a generic type or a common +// interface. +func (p PostgresContext) GetAllApps(height int64) (apps []modules.Actor, err error) { + ctx, tx, err := p.getCtxAndTx() + if err != nil { + return nil, err + } + rows, err := tx.Query(ctx, types.ApplicationActor.GetAllQuery(height)) + if err != nil { + return nil, err + } + var actors []*types.Actor + for rows.Next() { + var actor *types.Actor + actor, height, err = p.getActorFromRow(rows) + if err != nil { + return + } + actors = append(actors, actor) + } + rows.Close() + for _, actor := range actors { + actorWithChains, err := p.getChainsForActor(ctx, tx, types.ApplicationActor, actor, height) + if err != nil { + return nil, err + } + apps = append(apps, actorWithChains) + } + return +} + +func (p PostgresContext) GetAllValidators(height int64) (vals []modules.Actor, err error) { + ctx, tx, err := p.getCtxAndTx() + if err != nil { + return nil, err + } + rows, err := tx.Query(ctx, types.ValidatorActor.GetAllQuery(height)) + if err != nil { + return nil, err + } + var actors []*types.Actor + for rows.Next() { + var actor *types.Actor + actor, height, err = p.getActorFromRow(rows) + if err != nil { + return + } + actors = append(actors, actor) + } + rows.Close() + for _, actor := range actors { + actor, err = p.getChainsForActor(ctx, tx, types.ValidatorActor, actor, height) + if err != nil { + return + } + vals = append(vals, actor) + } + return +} + +func (p PostgresContext) GetAllServiceNodes(height int64) (sn []modules.Actor, err error) { + ctx, tx, err := p.getCtxAndTx() + if err != nil { + return nil, err + } + rows, err := tx.Query(ctx, types.ServiceNodeActor.GetAllQuery(height)) + if err != nil { + return nil, err + } + var actors []*types.Actor + for rows.Next() { + var actor *types.Actor + actor, height, err = p.getActorFromRow(rows) + if err != nil { + return + } + actors = append(actors, actor) + } + rows.Close() + for _, actor := range actors { + actor, err = p.getChainsForActor(ctx, tx, types.ServiceNodeActor, actor, height) + if err != nil { + return + } + sn = append(sn, actor) + } + return +} + +func (p PostgresContext) GetAllFishermen(height int64) (f []modules.Actor, err error) { + ctx, tx, err := p.getCtxAndTx() + if err != nil { + return nil, err + } + rows, err := tx.Query(ctx, types.FishermanActor.GetAllQuery(height)) + if err != nil { + return nil, err + } + var actors []*types.Actor + for rows.Next() { + var actor *types.Actor + actor, height, err = p.getActorFromRow(rows) + if err != nil { + return + } + actors = append(actors, actor) + } + rows.Close() + for _, actor := range actors { + actor, err = p.getChainsForActor(ctx, tx, types.FishermanActor, actor, height) + if err != nil { + return + } + f = append(f, actor) + } + return +} + +// IMPROVE: This is a proof of concept. Ideally we should have a single query that returns all actors. +func (p PostgresContext) GetAllStakedActors(height int64) (allActors []modules.Actor, err error) { + type actorGetter func(height int64) ([]modules.Actor, error) + actorGetters := []actorGetter{p.GetAllValidators, p.GetAllServiceNodes, p.GetAllFishermen, p.GetAllApps} + for _, actorGetter := range actorGetters { + actors, err := actorGetter(height) + if err != nil { + allActors = append(allActors, actors...) + } + } + return +} diff --git a/persistence/genesis.go b/persistence/genesis.go index c515f543f..ffd42e21e 100644 --- a/persistence/genesis.go +++ b/persistence/genesis.go @@ -205,146 +205,3 @@ func (p PostgresContext) GetAllPools(height int64) (accs []modules.Account, err } return } - -func (p PostgresContext) GetAllApps(height int64) (apps []modules.Actor, err error) { - ctx, tx, err := p.getCtxAndTx() - if err != nil { - return nil, err - } - rows, err := tx.Query(ctx, types.ApplicationActor.GetAllQuery(height)) - if err != nil { - return nil, err - } - var actors []*types.Actor - for rows.Next() { - var actor *types.Actor - actor, height, err = p.getActorFromRow(rows) - if err != nil { - return - } - actors = append(actors, actor) - } - rows.Close() - for _, actor := range actors { - actorWithChains, err := p.getChainsForActor(ctx, tx, types.ApplicationActor, actor, height) - if err != nil { - return nil, err - } - apps = append(apps, actorWithChains) - } - return -} - -func (p PostgresContext) GetAllValidators(height int64) (vals []modules.Actor, err error) { - ctx, tx, err := p.getCtxAndTx() - if err != nil { - return nil, err - } - rows, err := tx.Query(ctx, types.ValidatorActor.GetAllQuery(height)) - if err != nil { - return nil, err - } - var actors []*types.Actor - for rows.Next() { - var actor *types.Actor - actor, height, err = p.getActorFromRow(rows) - if err != nil { - return - } - actors = append(actors, actor) - } - rows.Close() - for _, actor := range actors { - actor, err = p.getChainsForActor(ctx, tx, types.ApplicationActor, actor, height) - if err != nil { - return - } - vals = append(vals, actor) - } - return -} - -func (p PostgresContext) GetAllServiceNodes(height int64) (sn []modules.Actor, err error) { - ctx, tx, err := p.getCtxAndTx() - if err != nil { - return nil, err - } - rows, err := tx.Query(ctx, types.ServiceNodeActor.GetAllQuery(height)) - if err != nil { - return nil, err - } - var actors []*types.Actor - for rows.Next() { - var actor *types.Actor - actor, height, err = p.getActorFromRow(rows) - if err != nil { - return - } - actors = append(actors, actor) - } - rows.Close() - for _, actor := range actors { - actor, err = p.getChainsForActor(ctx, tx, types.ServiceNodeActor, actor, height) - if err != nil { - return - } - sn = append(sn, actor) - } - return -} - -func (p PostgresContext) GetAllFishermen(height int64) (f []modules.Actor, err error) { - ctx, tx, err := p.getCtxAndTx() - if err != nil { - return nil, err - } - rows, err := tx.Query(ctx, types.FishermanActor.GetAllQuery(height)) - if err != nil { - return nil, err - } - var actors []*types.Actor - for rows.Next() { - var actor *types.Actor - actor, height, err = p.getActorFromRow(rows) - if err != nil { - return - } - actors = append(actors, actor) - } - rows.Close() - for _, actor := range actors { - actor, err = p.getChainsForActor(ctx, tx, types.FishermanActor, actor, height) - if err != nil { - return - } - f = append(f, actor) - } - return -} - -// IMPROVE: This is a proof of concept. Ideally we should have a single query that returns all actors. -func (p PostgresContext) GetAllStakedActors(height int64) (actors []modules.Actor, err error) { - actors = make([]modules.Actor, 0) - var allActors []modules.Actor - allActors, err = p.GetAllValidators(height) - if err != nil { - return - } - actors = append(actors, allActors...) - allActors, err = p.GetAllServiceNodes(height) - if err != nil { - return - } - actors = append(actors, allActors...) - allActors, err = p.GetAllFishermen(height) - if err != nil { - return - } - actors = append(actors, allActors...) - allActors, err = p.GetAllApps(height) - if err != nil { - return - } - actors = append(actors, allActors...) - return -} From 908af80b820ec9e82bd74cdb8945676319eeecb6 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 14 Dec 2022 22:51:55 +0000 Subject: [PATCH 077/143] Update consensus/consensus_tests/utils_test.go Co-authored-by: Daniel Olshansky --- consensus/consensus_tests/utils_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/consensus/consensus_tests/utils_test.go b/consensus/consensus_tests/utils_test.go index 9f39f957a..7bbefc16a 100644 --- a/consensus/consensus_tests/utils_test.go +++ b/consensus/consensus_tests/utils_test.go @@ -318,7 +318,6 @@ func basePersistenceMock(t *testing.T, _ modules.EventsChannel) *modulesMock.Moc // state; hence the `-1` expectation in the call above. persistenceContextMock.EXPECT().Close().Return(nil).AnyTimes() persistenceReadContextMock.EXPECT().GetLatestBlockHeight().Return(uint64(0), nil).AnyTimes() - persistenceReadContextMock.EXPECT().GetAllValidators(gomock.Any()).Return(makeMockActors(numValidators), nil).AnyTimes() persistenceReadContextMock.EXPECT().Close().Return(nil).AnyTimes() From da0e77c0e8885fa70b45bb23be92eaa3d55778e7 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 14 Dec 2022 23:29:22 +0000 Subject: [PATCH 078/143] refactor(persistence): actor -> validator --- p2p/addrbook_provider/persistence.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/p2p/addrbook_provider/persistence.go b/p2p/addrbook_provider/persistence.go index f130fdee1..af816a528 100644 --- a/p2p/addrbook_provider/persistence.go +++ b/p2p/addrbook_provider/persistence.go @@ -69,9 +69,9 @@ func (pabp *persistenceAddrBookProvider) GetStakedAddrBookAtHeight(height uint64 return addrBook, nil } -func (pabp *persistenceAddrBookProvider) ActorToAddrBook(validators map[string]modules.Actor) (typesP2P.AddrBook, error) { +func (pabp *persistenceAddrBookProvider) ActorToAddrBook(actors map[string]modules.Actor) (typesP2P.AddrBook, error) { book := make(typesP2P.AddrBook, 0) - for _, v := range validators { + for _, v := range actors { networkPeer, err := pabp.ActorToNetworkPeer(v) if err != nil { log.Println("[WARN] Error connecting to validator: ", err) From cd8bffe654c9aaf70b8f4eeddfd6f10b1d82fc4c Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 14 Dec 2022 23:35:39 +0000 Subject: [PATCH 079/143] refactor(P2P): moar validator -> actor --- p2p/addrbook_provider/getter.go | 2 +- p2p/types/addr_book.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/p2p/addrbook_provider/getter.go b/p2p/addrbook_provider/getter.go index 5accf1927..ed9304221 100644 --- a/p2p/addrbook_provider/getter.go +++ b/p2p/addrbook_provider/getter.go @@ -11,7 +11,7 @@ import ( func GetAddrBook(bus modules.Bus, addrBookProvider typesP2P.AddrBookProvider) (addrBook typesP2P.AddrBook, err error) { if bus.GetPersistenceModule() == nil { // TODO(#203): refactor or remove this once `ValidatorMap` logic is encapsulated. - addrBook, err = addrBookProvider.ActorToAddrBook(bus.GetConsensusModule().ValidatorMap()) + addrBook, err = addrBookProvider.ActorsToAddrBook(bus.GetConsensusModule().ValidatorMap()) } else { addrBook, err = addrBookProvider.GetStakedAddrBookAtHeight(bus.GetConsensusModule().CurrentHeight()) } diff --git a/p2p/types/addr_book.go b/p2p/types/addr_book.go index 4cd17947a..8c246e231 100644 --- a/p2p/types/addr_book.go +++ b/p2p/types/addr_book.go @@ -15,6 +15,6 @@ type AddrBookMap map[string]*NetworkPeer // AddrBookProvider is an interface that provides AddrBook accessors type AddrBookProvider interface { GetStakedAddrBookAtHeight(height uint64) (AddrBook, error) - ActorToAddrBook(validators map[string]modules.Actor) (AddrBook, error) - ActorToNetworkPeer(v modules.Actor) (*NetworkPeer, error) + ActorsToAddrBook(actors map[string]modules.Actor) (AddrBook, error) + ActorToNetworkPeer(actor modules.Actor) (*NetworkPeer, error) } From 14e8d48640a4fa83318d9d6f5b19a09b92f64ed6 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 14 Dec 2022 23:35:39 +0000 Subject: [PATCH 080/143] refactor(P2P): moar validator -> actor --- p2p/addrbook_provider/getter.go | 2 +- p2p/types/addr_book.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/p2p/addrbook_provider/getter.go b/p2p/addrbook_provider/getter.go index 5accf1927..ed9304221 100644 --- a/p2p/addrbook_provider/getter.go +++ b/p2p/addrbook_provider/getter.go @@ -11,7 +11,7 @@ import ( func GetAddrBook(bus modules.Bus, addrBookProvider typesP2P.AddrBookProvider) (addrBook typesP2P.AddrBook, err error) { if bus.GetPersistenceModule() == nil { // TODO(#203): refactor or remove this once `ValidatorMap` logic is encapsulated. - addrBook, err = addrBookProvider.ActorToAddrBook(bus.GetConsensusModule().ValidatorMap()) + addrBook, err = addrBookProvider.ActorsToAddrBook(bus.GetConsensusModule().ValidatorMap()) } else { addrBook, err = addrBookProvider.GetStakedAddrBookAtHeight(bus.GetConsensusModule().CurrentHeight()) } diff --git a/p2p/types/addr_book.go b/p2p/types/addr_book.go index 4cd17947a..8c246e231 100644 --- a/p2p/types/addr_book.go +++ b/p2p/types/addr_book.go @@ -15,6 +15,6 @@ type AddrBookMap map[string]*NetworkPeer // AddrBookProvider is an interface that provides AddrBook accessors type AddrBookProvider interface { GetStakedAddrBookAtHeight(height uint64) (AddrBook, error) - ActorToAddrBook(validators map[string]modules.Actor) (AddrBook, error) - ActorToNetworkPeer(v modules.Actor) (*NetworkPeer, error) + ActorsToAddrBook(actors map[string]modules.Actor) (AddrBook, error) + ActorToNetworkPeer(actor modules.Actor) (*NetworkPeer, error) } From 70b7a75dafa8cf7edd07a7c5f447bfc009b0fada Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 14 Dec 2022 23:42:54 +0000 Subject: [PATCH 081/143] fix(P2P): validator -> actor --- p2p/addrbook_provider/persistence.go | 4 ++-- p2p/raintree/utils_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/p2p/addrbook_provider/persistence.go b/p2p/addrbook_provider/persistence.go index af816a528..ace9667b2 100644 --- a/p2p/addrbook_provider/persistence.go +++ b/p2p/addrbook_provider/persistence.go @@ -62,14 +62,14 @@ func (pabp *persistenceAddrBookProvider) GetStakedAddrBookAtHeight(height uint64 for _, v := range stakedActors { validatorMap[v.GetAddress()] = v } - addrBook, err := pabp.ActorToAddrBook(validatorMap) + addrBook, err := pabp.ActorsToAddrBook(validatorMap) if err != nil { return nil, err } return addrBook, nil } -func (pabp *persistenceAddrBookProvider) ActorToAddrBook(actors map[string]modules.Actor) (typesP2P.AddrBook, error) { +func (pabp *persistenceAddrBookProvider) ActorsToAddrBook(actors map[string]modules.Actor) (typesP2P.AddrBook, error) { book := make(typesP2P.AddrBook, 0) for _, v := range actors { networkPeer, err := pabp.ActorToNetworkPeer(v) diff --git a/p2p/raintree/utils_test.go b/p2p/raintree/utils_test.go index 2117126f2..b5128d043 100644 --- a/p2p/raintree/utils_test.go +++ b/p2p/raintree/utils_test.go @@ -19,7 +19,7 @@ func mockDummyBus(ctrl *gomock.Controller) *mockModules.MockBus { func mockAddrBookProvider(ctrl *gomock.Controller, addrBook typesP2P.AddrBook) *mocksP2P.MockAddrBookProvider { addrBookProviderMock := mocksP2P.NewMockAddrBookProvider(ctrl) - addrBookProviderMock.EXPECT().ActorToAddrBook(gomock.Any()).Return(addrBook, nil).AnyTimes() + addrBookProviderMock.EXPECT().ActorsToAddrBook(gomock.Any()).Return(addrBook, nil).AnyTimes() addrBookProviderMock.EXPECT().GetStakedAddrBookAtHeight(gomock.Any()).Return(addrBook, nil).AnyTimes() return addrBookProviderMock } From 7b0eb8c6d63beb0343d6836ee4d69d3400839a14 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 15 Dec 2022 00:00:13 +0000 Subject: [PATCH 082/143] refactor(Shared): ValidatorMap() ConsensusModule iface no more --- consensus/module.go | 4 ---- shared/modules/consensus_module.go | 4 ---- 2 files changed, 8 deletions(-) diff --git a/consensus/module.go b/consensus/module.go index 271ef6d4d..c3a29ca3e 100644 --- a/consensus/module.go +++ b/consensus/module.go @@ -303,10 +303,6 @@ func (m *consensusModule) CurrentStep() uint64 { return uint64(m.step) } -func (m *consensusModule) ValidatorMap() modules.ValidatorMap { // TODO: This needs to be dynamically updated during various operations and network changes. - return typesCons.ValidatorMapToModulesValidatorMap(m.validatorMap) -} - // TODO: Populate the entire state from the persistence module: validator set, quorum cert, last block hash, etc... func (m *consensusModule) loadPersistedState() error { persistenceContext, err := m.GetBus().GetPersistenceModule().NewReadContext(-1) // Unknown height diff --git a/shared/modules/consensus_module.go b/shared/modules/consensus_module.go index 689b8ec47..057cbef40 100644 --- a/shared/modules/consensus_module.go +++ b/shared/modules/consensus_module.go @@ -7,9 +7,6 @@ import ( "google.golang.org/protobuf/types/known/anypb" ) -// TODO(olshansky): deprecate ValidatorMap or populate from persistence module -type ValidatorMap map[string]Actor - // NOTE: Consensus is the core of the replicated state machine and is driven by various asynchronous events. // Consider adding a mutex lock to your implementation that is acquired at the beginning of each entrypoint/function implemented in this interface. // Make sure that you are not locking again within the same call to avoid deadlocks (for example when the methods below call each other in your implementation). @@ -28,5 +25,4 @@ type ConsensusModule interface { CurrentHeight() uint64 CurrentRound() uint64 CurrentStep() uint64 - ValidatorMap() ValidatorMap } From 92c6050e882cbab0427ba039d431427a3dee99e5 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 15 Dec 2022 00:01:51 +0000 Subject: [PATCH 083/143] refactor(P2P): addrBookProvider cleanup --- p2p/addrbook_provider/getter.go | 19 ------------------- p2p/addrbook_provider/persistence.go | 17 ++++++----------- 2 files changed, 6 insertions(+), 30 deletions(-) delete mode 100644 p2p/addrbook_provider/getter.go diff --git a/p2p/addrbook_provider/getter.go b/p2p/addrbook_provider/getter.go deleted file mode 100644 index ed9304221..000000000 --- a/p2p/addrbook_provider/getter.go +++ /dev/null @@ -1,19 +0,0 @@ -package addrbook_provider - -import ( - typesP2P "github.com/pokt-network/pocket/p2p/types" - "github.com/pokt-network/pocket/shared/modules" -) - -// GetAddrBook is a helper function that returns the addrBook depending on the availability of the persistence module -// -// HACK: This is a temporary solution simply used to centralize the logic that is going to be refactored in #331 and #203 -func GetAddrBook(bus modules.Bus, addrBookProvider typesP2P.AddrBookProvider) (addrBook typesP2P.AddrBook, err error) { - if bus.GetPersistenceModule() == nil { - // TODO(#203): refactor or remove this once `ValidatorMap` logic is encapsulated. - addrBook, err = addrBookProvider.ActorsToAddrBook(bus.GetConsensusModule().ValidatorMap()) - } else { - addrBook, err = addrBookProvider.GetStakedAddrBookAtHeight(bus.GetConsensusModule().CurrentHeight()) - } - return addrBook, err -} diff --git a/p2p/addrbook_provider/persistence.go b/p2p/addrbook_provider/persistence.go index ace9667b2..84f73d201 100644 --- a/p2p/addrbook_provider/persistence.go +++ b/p2p/addrbook_provider/persistence.go @@ -57,19 +57,14 @@ func (pabp *persistenceAddrBookProvider) GetStakedAddrBookAtHeight(height uint64 if err != nil { return nil, err } - // TODO(#203): refactor `ValidatorMap`` - validatorMap := make(modules.ValidatorMap, len(stakedActors)) - for _, v := range stakedActors { - validatorMap[v.GetAddress()] = v - } - addrBook, err := pabp.ActorsToAddrBook(validatorMap) + addrBook, err := pabp.ActorsToAddrBook(stakedActors) if err != nil { return nil, err } return addrBook, nil } -func (pabp *persistenceAddrBookProvider) ActorsToAddrBook(actors map[string]modules.Actor) (typesP2P.AddrBook, error) { +func (pabp *persistenceAddrBookProvider) ActorsToAddrBook(actors []modules.Actor) (typesP2P.AddrBook, error) { book := make(typesP2P.AddrBook, 0) for _, v := range actors { networkPeer, err := pabp.ActorToNetworkPeer(v) @@ -82,13 +77,13 @@ func (pabp *persistenceAddrBookProvider) ActorsToAddrBook(actors map[string]modu return book, nil } -func (pabp *persistenceAddrBookProvider) ActorToNetworkPeer(v modules.Actor) (*typesP2P.NetworkPeer, error) { - conn, err := pabp.connFactory(pabp.p2pCfg, v.GetGenericParam()) // service url +func (pabp *persistenceAddrBookProvider) ActorToNetworkPeer(actor modules.Actor) (*typesP2P.NetworkPeer, error) { + conn, err := pabp.connFactory(pabp.p2pCfg, actor.GetGenericParam()) // service url if err != nil { return nil, fmt.Errorf("error resolving addr: %v", err) } - pubKey, err := cryptoPocket.NewPublicKey(v.GetPublicKey()) + pubKey, err := cryptoPocket.NewPublicKey(actor.GetPublicKey()) if err != nil { return nil, err } @@ -97,7 +92,7 @@ func (pabp *persistenceAddrBookProvider) ActorToNetworkPeer(v modules.Actor) (*t Dialer: conn, PublicKey: pubKey, Address: pubKey.Address(), - ServiceUrl: v.GetGenericParam(), // service url + ServiceUrl: actor.GetGenericParam(), // service url } return peer, nil From 30c18c5ee40762f331b67376c7c2d0891e7136ae Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 15 Dec 2022 00:02:13 +0000 Subject: [PATCH 084/143] refactor(Consensus): removed ValidatorMapToModulesValidatorMap --- consensus/types/types.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/consensus/types/types.go b/consensus/types/types.go index 67f3af523..e2b74ca19 100644 --- a/consensus/types/types.go +++ b/consensus/types/types.go @@ -45,14 +45,6 @@ func (x *PacemakerConfig) SetTimeoutMsec(u uint64) { x.TimeoutMsec = u } -func ValidatorMapToModulesValidatorMap(validatorMap ValidatorMap) (vm modules.ValidatorMap) { - vm = make(modules.ValidatorMap) - for _, v := range validatorMap { - vm[v.GetAddress()] = v - } - return -} - func ActorListToValidatorMap(actors []modules.Actor) (m ValidatorMap) { m = make(ValidatorMap, len(actors)) for _, a := range actors { From 4f43b5deee0446c6d367ced113f57e6181d386c5 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 15 Dec 2022 00:02:47 +0000 Subject: [PATCH 085/143] refactor(P2P): updated to source addresses via persistence only --- p2p/raintree/network.go | 3 +-- p2p/stdnetwork/network.go | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/p2p/raintree/network.go b/p2p/raintree/network.go index 2251d282a..8da4e4ccf 100644 --- a/p2p/raintree/network.go +++ b/p2p/raintree/network.go @@ -6,7 +6,6 @@ import ( "math/rand" "time" - "github.com/pokt-network/pocket/p2p/addrbook_provider" typesP2P "github.com/pokt-network/pocket/p2p/types" "github.com/pokt-network/pocket/shared/codec" cryptoPocket "github.com/pokt-network/pocket/shared/crypto" @@ -53,7 +52,7 @@ func NewRainTreeNetworkWithAddrBook(addr cryptoPocket.Address, addrBook typesP2P } func NewRainTreeNetwork(addr cryptoPocket.Address, bus modules.Bus, p2pCfg modules.P2PConfig, addrBookProvider typesP2P.AddrBookProvider) typesP2P.Network { - addrBook, err := addrbook_provider.GetAddrBook(bus, addrBookProvider) + addrBook, err := addrBookProvider.GetStakedAddrBookAtHeight(bus.GetConsensusModule().CurrentHeight()) if err != nil { log.Fatalf("[ERROR] Error getting addrBook: %v", err) } diff --git a/p2p/stdnetwork/network.go b/p2p/stdnetwork/network.go index aa69a579e..bed961b06 100644 --- a/p2p/stdnetwork/network.go +++ b/p2p/stdnetwork/network.go @@ -6,7 +6,6 @@ import ( "fmt" "log" - "github.com/pokt-network/pocket/p2p/addrbook_provider" typesP2P "github.com/pokt-network/pocket/p2p/types" cryptoPocket "github.com/pokt-network/pocket/shared/crypto" "github.com/pokt-network/pocket/shared/modules" @@ -20,7 +19,7 @@ type network struct { } func NewNetwork(bus modules.Bus, p2pCfg modules.P2PConfig, addrBookProvider typesP2P.AddrBookProvider) (n typesP2P.Network) { - addrBook, err := addrbook_provider.GetAddrBook(bus, addrBookProvider) + addrBook, err := addrBookProvider.GetStakedAddrBookAtHeight(bus.GetConsensusModule().CurrentHeight()) if err != nil { log.Fatalf("[ERROR] Error getting addrBook: %v", err) } From b62365a54460dbfc2640ab170f74a8f9d81f4a67 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 15 Dec 2022 00:03:14 +0000 Subject: [PATCH 086/143] fix(P2P): fixed tests after ValidatorMap removal --- p2p/raintree/utils_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/p2p/raintree/utils_test.go b/p2p/raintree/utils_test.go index b5128d043..d63b2977b 100644 --- a/p2p/raintree/utils_test.go +++ b/p2p/raintree/utils_test.go @@ -12,7 +12,6 @@ func mockDummyBus(ctrl *gomock.Controller) *mockModules.MockBus { busMock.EXPECT().GetPersistenceModule().Return(nil).AnyTimes() consensusMock := mockModules.NewMockConsensusModule(ctrl) consensusMock.EXPECT().CurrentHeight().Return(uint64(0)).AnyTimes() - consensusMock.EXPECT().ValidatorMap().Return(nil).AnyTimes() busMock.EXPECT().GetConsensusModule().Return(consensusMock).AnyTimes() return busMock } From 0f18c5b505f5f6e0725c2a55407b3551c1c3861f Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 15 Dec 2022 00:03:41 +0000 Subject: [PATCH 087/143] test(P2P): updated mocks --- p2p/utils_test.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/p2p/utils_test.go b/p2p/utils_test.go index fb279db64..ab0e31c1f 100644 --- a/p2p/utils_test.go +++ b/p2p/utils_test.go @@ -185,14 +185,6 @@ func prepareBusMock(t *testing.T, func prepareConsensusMock(t *testing.T, genesisState modules.GenesisState) *modulesMock.MockConsensusModule { ctrl := gomock.NewController(t) consensusMock := modulesMock.NewMockConsensusModule(ctrl) - - validators := genesisState.GetPersistenceGenesisState().GetVals() - m := make(modules.ValidatorMap, len(validators)) - for _, v := range validators { - m[v.GetAddress()] = v - } - - consensusMock.EXPECT().ValidatorMap().Return(m).AnyTimes() consensusMock.EXPECT().CurrentHeight().Return(uint64(1)).AnyTimes() return consensusMock From b41f5b1c4bd529fbb408ad463eb0f05904b842d8 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 15 Dec 2022 00:04:10 +0000 Subject: [PATCH 088/143] refactor(P2P): updated AddrBookProvider --- p2p/types/addr_book.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p2p/types/addr_book.go b/p2p/types/addr_book.go index 8c246e231..d282a7a81 100644 --- a/p2p/types/addr_book.go +++ b/p2p/types/addr_book.go @@ -15,6 +15,6 @@ type AddrBookMap map[string]*NetworkPeer // AddrBookProvider is an interface that provides AddrBook accessors type AddrBookProvider interface { GetStakedAddrBookAtHeight(height uint64) (AddrBook, error) - ActorsToAddrBook(actors map[string]modules.Actor) (AddrBook, error) + ActorsToAddrBook(actors []modules.Actor) (AddrBook, error) ActorToNetworkPeer(actor modules.Actor) (*NetworkPeer, error) } From 3131e00e4ad73f96503af03e1d389b5dbf4e6abd Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 15 Dec 2022 00:45:28 +0000 Subject: [PATCH 089/143] docs(Persistence): updated TODO --- persistence/actor.go | 2 +- persistence/genesis.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/persistence/actor.go b/persistence/actor.go index c1c1db365..42c07d595 100644 --- a/persistence/actor.go +++ b/persistence/actor.go @@ -5,7 +5,7 @@ import ( "github.com/pokt-network/pocket/shared/modules" ) -// TODO(pocket/issues/149): All of the functions below following a structure similar to `GetAll` +// TODO (#399): All of the functions below following a structure similar to `GetAll` // can easily be refactored and condensed into a single function using a generic type or a common // interface. func (p PostgresContext) GetAllApps(height int64) (apps []modules.Actor, err error) { diff --git a/persistence/genesis.go b/persistence/genesis.go index ffd42e21e..25d7e5ea5 100644 --- a/persistence/genesis.go +++ b/persistence/genesis.go @@ -160,7 +160,7 @@ func (m *persistenceModule) populateGenesisState(state modules.PersistenceGenesi } } -// TODO(pocket/issues/149): All of the functions below following a structure similar to `GetAll` +// TODO (#399): All of the functions below following a structure similar to `GetAll` // can easily be refactored and condensed into a single function using a generic type or a common // interface. func (p PostgresContext) GetAllAccounts(height int64) (accs []modules.Account, err error) { From b5f2ef5a58c7ff5105fc284cbadb24dd31f4bbda Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 15 Dec 2022 00:52:44 +0000 Subject: [PATCH 090/143] Update p2p/addrbook_provider/persistence.go Co-authored-by: Daniel Olshansky --- p2p/addrbook_provider/persistence.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p2p/addrbook_provider/persistence.go b/p2p/addrbook_provider/persistence.go index f3451664b..eee396d5d 100644 --- a/p2p/addrbook_provider/persistence.go +++ b/p2p/addrbook_provider/persistence.go @@ -57,7 +57,7 @@ func (pabp *persistenceAddrBookProvider) GetStakedAddrBookAtHeight(height uint64 if err != nil { return nil, err } - // TODO(#203): refactor `ValidatorMap`` + // TODO(#203): refactor `ValidatorMap` validatorMap := make(modules.ValidatorMap, len(stakedActors)) for _, v := range stakedActors { validatorMap[v.GetAddress()] = v From 9eb06466b84c0c468bbb004a0837158520104873 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 15 Dec 2022 00:55:17 +0000 Subject: [PATCH 091/143] refactor(P2P): renamed mockDummyBus to mockBus --- p2p/raintree/network_test.go | 4 ++-- p2p/raintree/peers_manager_test.go | 4 ++-- p2p/raintree/utils_test.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/p2p/raintree/network_test.go b/p2p/raintree/network_test.go index 41bba6567..288f9ed06 100644 --- a/p2p/raintree/network_test.go +++ b/p2p/raintree/network_test.go @@ -24,7 +24,7 @@ func TestRainTreeNetwork_AddPeerToAddrBook(t *testing.T) { addrBook := getAddrBook(nil, 0) addrBook = append(addrBook, &typesP2P.NetworkPeer{Address: selfAddr}) - busMock := mockDummyBus(ctrl) + busMock := mockBus(ctrl) addrBookProviderMock := mockAddrBookProvider(ctrl, addrBook) network := NewRainTreeNetwork(selfAddr, busMock, mockP2PCfg, addrBookProviderMock).(*rainTreeNetwork) @@ -63,7 +63,7 @@ func TestRainTreeNetwork_RemovePeerToAddrBook(t *testing.T) { selfPeer := &typesP2P.NetworkPeer{Address: selfAddr} addrBook = append(addrBook, &typesP2P.NetworkPeer{Address: selfAddr}) - busMock := mockDummyBus(ctrl) + busMock := mockBus(ctrl) addrBookProviderMock := mockAddrBookProvider(ctrl, addrBook) network := NewRainTreeNetwork(selfAddr, busMock, mockP2PCfg, addrBookProviderMock).(*rainTreeNetwork) diff --git a/p2p/raintree/peers_manager_test.go b/p2p/raintree/peers_manager_test.go index 27b4a2dbd..760ecd6fc 100644 --- a/p2p/raintree/peers_manager_test.go +++ b/p2p/raintree/peers_manager_test.go @@ -78,7 +78,7 @@ func TestRainTreeAddrBookUtilsHandleUpdate(t *testing.T) { addrBook := getAddrBook(t, n-1) addrBook = append(addrBook, &types.NetworkPeer{Address: addr}) - mockBus := mockDummyBus(ctrl) + mockBus := mockBus(ctrl) mockAddrBookProvider := mockAddrBookProvider(ctrl, addrBook) network := NewRainTreeNetwork(addr, mockBus, mockP2PCfg, mockAddrBookProvider).(*rainTreeNetwork) @@ -120,7 +120,7 @@ func BenchmarkAddrBookUpdates(b *testing.B) { addrBook := getAddrBook(nil, n-1) addrBook = append(addrBook, &types.NetworkPeer{Address: addr}) - mockBus := mockDummyBus(ctrl) + mockBus := mockBus(ctrl) mockAddrBookProvider := mockAddrBookProvider(ctrl, addrBook) network := NewRainTreeNetwork(addr, mockBus, mockP2PCfg, mockAddrBookProvider).(*rainTreeNetwork) diff --git a/p2p/raintree/utils_test.go b/p2p/raintree/utils_test.go index d81fc2237..b953d80fa 100644 --- a/p2p/raintree/utils_test.go +++ b/p2p/raintree/utils_test.go @@ -7,7 +7,7 @@ import ( mockModules "github.com/pokt-network/pocket/shared/modules/mocks" ) -func mockDummyBus(ctrl *gomock.Controller) *mockModules.MockBus { +func mockBus(ctrl *gomock.Controller) *mockModules.MockBus { busMock := mockModules.NewMockBus(ctrl) busMock.EXPECT().GetPersistenceModule().Return(nil).AnyTimes() consensusMock := mockModules.NewMockConsensusModule(ctrl) From 5899337d5c0669b900956368cca2cb8d9a815fa3 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 15 Dec 2022 01:07:13 +0000 Subject: [PATCH 092/143] docs(Consensus): CHANGELOG --- consensus/doc/CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/consensus/doc/CHANGELOG.md b/consensus/doc/CHANGELOG.md index 1fd45aad6..b4211d402 100644 --- a/consensus/doc/CHANGELOG.md +++ b/consensus/doc/CHANGELOG.md @@ -10,8 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.0.0.13] - 2022-12-14 -- The `Pacemaker` now emits `BeforeHeightChangedEvent` events when the height is about to change. -- The `Pacemaker` now emits `HeightChangedEvent` events when the height changes. +- Consolidated number of validators in tests in a single constant: `numValidators` +- Fixed typo in `make test_consensus_concurrent_tests` so that we can run the correct test matrix +- Using `GetBus()` instead of `bus` wherever possible ## [0.0.0.12] - 2022-12-12 From ac11ed159dc4f31fc4e31df16de24c1f8098eecf Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 15 Dec 2022 01:26:47 +0000 Subject: [PATCH 093/143] docs(Shared): CHANGELOGs --- p2p/CHANGELOG.md | 10 ++++++++-- persistence/CHANGELOG.md | 5 +++++ rpc/doc/CHANGELOG.md | 4 ++++ runtime/docs/CHANGELOG.md | 4 ++++ shared/CHANGELOG.md | 4 ++-- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/p2p/CHANGELOG.md b/p2p/CHANGELOG.md index 362a71015..3136e82ab 100644 --- a/p2p/CHANGELOG.md +++ b/p2p/CHANGELOG.md @@ -7,14 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.10] 2022-12-08 +## [0.0.0.10] 2022-12-14 - mempool cap is now configurable via P2PConfig. Tests implement the mock accordingly. +- Introduced the concept of a `addrbookProvider` that abstracts the fetching and the mapping from `Actor` to `NetworkPeer` +- Temporary hack to allow access to the `addrBook` to the debug client (will be removed in an upcoming PR already in the works for issues [#203](https://github.com/pokt-network/pocket/issues/203) and [#331](https://github.com/pokt-network/pocket/issues/331)) +- Transport related functions are now in the `transport` package +- Updated tests to source the `addrBook` from the `addrbookProvider` and therefore `Persistence` +- Updated Raintree network constructur with dependency injection +- Updated stdNetwork constructur with dependency injection +- Improved documentation for the `peersManager` ## [0.0.0.9] - 2022-12-04 - Raintree mempool cannot grow unbounded anymore. It's now bounded by a constant limit and when new nonces are inserted the oldest ones are removed. -- Reacting to the `BeforeHeightChanged` event to broadcast the addressBook to the other modules via the bus. - Raintree is now capable of fetching the address book for a previous height and to instantiate an ephemeral `peersManager` with it. ## [0.0.0.8] - 2022-11-14 diff --git a/persistence/CHANGELOG.md b/persistence/CHANGELOG.md index cda6e172d..6f84f983b 100644 --- a/persistence/CHANGELOG.md +++ b/persistence/CHANGELOG.md @@ -9,6 +9,11 @@ TODO: consolidate `persistence/docs/CHANGELOG` and `persistence/CHANGELOG.md` ## [Unreleased] +## [0.0.0.11] - 2022-15-14 + +- Moved Actor related getters from `genesis.go` to `actor.go` +- Added `GetAllStakedActors()` that returns all Actors + ## [0.0.0.10] - 2022-12-06 - Changed the scope of `TransactionExists` from the `PostgresContext` to the `PersistenceModule` diff --git a/rpc/doc/CHANGELOG.md b/rpc/doc/CHANGELOG.md index ae51affc8..0e7d19dd4 100644 --- a/rpc/doc/CHANGELOG.md +++ b/rpc/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.3] - 2022-12-14 + +- Updated to use `GetBus()` instead of `bus` wherever possible + ## [0.0.0.2] - 2022-12-06 - Updated `PostV1ClientBroadcastTxSync` to broadcast the transaction it receives diff --git a/runtime/docs/CHANGELOG.md b/runtime/docs/CHANGELOG.md index 16725f07d..1e7e65633 100644 --- a/runtime/docs/CHANGELOG.md +++ b/runtime/docs/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.0.1] - 2022-12-14 + +- Added `DefaultP2PMempoolMaxNonceCount` + ## [0.0.0] - 2022-09-30 ### [#235](https://github.com/pokt-network/pocket/pull/235) Config and genesis handling diff --git a/shared/CHANGELOG.md b/shared/CHANGELOG.md index 6dee588ec..657e3ccc1 100644 --- a/shared/CHANGELOG.md +++ b/shared/CHANGELOG.md @@ -7,9 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.6] - 2022-12-04 +## [0.0.0.6] - 2022-12-14 -- Added `BeforeHeightChangedEvent` and `HeightChangedEvent` events that respectively signal the other modules that we are about to change the Height and that we have changed the Height. +- Added `GetMaxMempoolCount` ## [0.0.0.5] - 2022-12-06 From 9a32d513cfc860847c7d718fe5c9459a156f3ca5 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 15 Dec 2022 01:34:13 +0000 Subject: [PATCH 094/143] fix(P2P): changelog missing --- p2p/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p2p/CHANGELOG.md b/p2p/CHANGELOG.md index 3136e82ab..33b3b780a 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.10] 2022-12-14 +## [0.0.0.10] - 2022-12-14 - mempool cap is now configurable via P2PConfig. Tests implement the mock accordingly. - Introduced the concept of a `addrbookProvider` that abstracts the fetching and the mapping from `Actor` to `NetworkPeer` From e5fd2ad84a2fa53eeac9b25c97f5c397293fc7c1 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Fri, 16 Dec 2022 16:09:02 +0000 Subject: [PATCH 095/143] fix(P2P): removed getter --- p2p/addrbook_provider/getter.go | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 p2p/addrbook_provider/getter.go diff --git a/p2p/addrbook_provider/getter.go b/p2p/addrbook_provider/getter.go deleted file mode 100644 index ed9304221..000000000 --- a/p2p/addrbook_provider/getter.go +++ /dev/null @@ -1,19 +0,0 @@ -package addrbook_provider - -import ( - typesP2P "github.com/pokt-network/pocket/p2p/types" - "github.com/pokt-network/pocket/shared/modules" -) - -// GetAddrBook is a helper function that returns the addrBook depending on the availability of the persistence module -// -// HACK: This is a temporary solution simply used to centralize the logic that is going to be refactored in #331 and #203 -func GetAddrBook(bus modules.Bus, addrBookProvider typesP2P.AddrBookProvider) (addrBook typesP2P.AddrBook, err error) { - if bus.GetPersistenceModule() == nil { - // TODO(#203): refactor or remove this once `ValidatorMap` logic is encapsulated. - addrBook, err = addrBookProvider.ActorsToAddrBook(bus.GetConsensusModule().ValidatorMap()) - } else { - addrBook, err = addrBookProvider.GetStakedAddrBookAtHeight(bus.GetConsensusModule().CurrentHeight()) - } - return addrBook, err -} From 185b429b0741a093185ded5838eed58e10550e5f Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Fri, 16 Dec 2022 16:09:28 +0000 Subject: [PATCH 096/143] chore(Consensus): typo --- consensus/consensus_tests/utils_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/consensus/consensus_tests/utils_test.go b/consensus/consensus_tests/utils_test.go index c1ce8c838..9cf3c2de1 100644 --- a/consensus/consensus_tests/utils_test.go +++ b/consensus/consensus_tests/utils_test.go @@ -48,8 +48,6 @@ var ( const numValidators = 4 -const numValidators = 4 - // Initialize certain unit test configurations on startup. func init() { flag.BoolVar(&failOnExtraMessages, "failOnExtraMessages", false, "Fail if unexpected additional messages are received") From bc8d8ae8624b2e81413f18f154a942a59fd68cd0 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 21 Dec 2022 21:07:23 +0000 Subject: [PATCH 097/143] chore(shared): nits --- p2p/addrbook_provider/persistence.go | 4 ++-- persistence/actor.go | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/p2p/addrbook_provider/persistence.go b/p2p/addrbook_provider/persistence.go index 84f73d201..13d2413b6 100644 --- a/p2p/addrbook_provider/persistence.go +++ b/p2p/addrbook_provider/persistence.go @@ -66,8 +66,8 @@ func (pabp *persistenceAddrBookProvider) GetStakedAddrBookAtHeight(height uint64 func (pabp *persistenceAddrBookProvider) ActorsToAddrBook(actors []modules.Actor) (typesP2P.AddrBook, error) { book := make(typesP2P.AddrBook, 0) - for _, v := range actors { - networkPeer, err := pabp.ActorToNetworkPeer(v) + for _, a := range actors { + networkPeer, err := pabp.ActorToNetworkPeer(a) if err != nil { log.Println("[WARN] Error connecting to validator: ", err) continue diff --git a/persistence/actor.go b/persistence/actor.go index a0f7eab98..6f2eda716 100644 --- a/persistence/actor.go +++ b/persistence/actor.go @@ -6,9 +6,8 @@ import ( ) // TODO (#399): All of the functions below following a structure similar to `GetAll` -// -// can easily be refactored and condensed into a single function using a generic type or a common -// interface. +// can easily be refactored and condensed into a single function using a generic type or a common +// interface. func (p PostgresContext) GetAllApps(height int64) (apps []modules.Actor, err error) { ctx, tx, err := p.getCtxAndTx() if err != nil { From bd25a730d8918417c8dd44d30c5e5ce36b4f7aad Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 22 Dec 2022 16:38:54 +0000 Subject: [PATCH 098/143] refactor(CLI): hardcoded addressbook --- app/client/cli/debug.go | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/app/client/cli/debug.go b/app/client/cli/debug.go index 2aeb64a2d..cd7492abe 100644 --- a/app/client/cli/debug.go +++ b/app/client/cli/debug.go @@ -50,6 +50,17 @@ var ( PromptTogglePacemakerMode, PromptShowLatestBlockInStore, } + + // HACK: this is a temporary solution that guarantees backward compatibility while we implement peer discovery (#416). + // these addresses are simply copied over from the genesis file. + // We could read them from there as well but it would be just a uselessly more sophisticated HACK :) + // the goal is to keep it so ugly to look at that we are forced to fix it as soon as possible (already in progress) + validatorAddresses = []string{ + "6f66574e1f50f0ef72dff748c3f11b9e0e89d32a", + "67eb3f0a50ae459fecf666be0e93176e92441317", + "3f52e08c4b3b65ab7cf098d77df5bf8cedcf5f99", + "113fdb095d42d6e09327ab5b8df13fd8197a1eaf", + } ) func init() { @@ -148,8 +159,8 @@ func broadcastDebugMessage(debugMsg *messaging.DebugMessage) { // address book of the actual validator nodes, so `node1.consensus` never receives the message. // p2pMod.Broadcast(anyProto, messaging.PocketTopic_DEBUG_TOPIC) - for _, val := range consensusMod.ValidatorMap() { - addr, err := pocketCrypto.NewAddress(val.GetAddress()) + for _, valAddr := range validatorAddresses { + addr, err := pocketCrypto.NewAddress(valAddr) if err != nil { log.Fatalf("[ERROR] Failed to convert validator address into pocketCrypto.Address: %v", err) } @@ -165,12 +176,13 @@ func sendDebugMessage(debugMsg *messaging.DebugMessage) { } var validatorAddress []byte - for _, val := range consensusMod.ValidatorMap() { - validatorAddress, err = pocketCrypto.NewAddress(val.GetAddress()) - if err != nil { - log.Fatalf("[ERROR] Failed to convert validator address into pocketCrypto.Address: %v", err) - } - break + if len(validatorAddresses) == 0 { + log.Fatalf("[ERROR] No validator addresses found") + } + + validatorAddress, err = pocketCrypto.NewAddress(validatorAddresses[0]) + if err != nil { + log.Fatalf("[ERROR] Failed to convert validator address into pocketCrypto.Address: %v", err) } p2pMod.Send(validatorAddress, anyProto) From 843f1b4359ce54ed96641f9de1990f1ee83e32a3 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 22 Dec 2022 23:11:55 +0000 Subject: [PATCH 099/143] feat(P2P): providers for addressbook and currentheight --- p2p/addrbook_provider/persistence.go | 99 ------------------- .../addrbook_provider/addrbook_provider.go | 61 ++++++++++++ .../debug/addrbook_provider.go | 71 +++++++++++++ .../persistence/addrbook_provider.go | 67 +++++++++++++ .../current_height_provider.go | 7 ++ .../debug/debug_current_height_provider.go | 21 ++++ p2p/providers/providers.go | 9 ++ 7 files changed, 236 insertions(+), 99 deletions(-) delete mode 100644 p2p/addrbook_provider/persistence.go create mode 100644 p2p/providers/addrbook_provider/addrbook_provider.go create mode 100644 p2p/providers/addrbook_provider/debug/addrbook_provider.go create mode 100644 p2p/providers/addrbook_provider/persistence/addrbook_provider.go create mode 100644 p2p/providers/current_height_provider/current_height_provider.go create mode 100644 p2p/providers/current_height_provider/debug/debug_current_height_provider.go create mode 100644 p2p/providers/providers.go diff --git a/p2p/addrbook_provider/persistence.go b/p2p/addrbook_provider/persistence.go deleted file mode 100644 index 13d2413b6..000000000 --- a/p2p/addrbook_provider/persistence.go +++ /dev/null @@ -1,99 +0,0 @@ -package addrbook_provider - -import ( - "fmt" - "log" - - "github.com/pokt-network/pocket/p2p/transport" - typesP2P "github.com/pokt-network/pocket/p2p/types" - cryptoPocket "github.com/pokt-network/pocket/shared/crypto" - "github.com/pokt-network/pocket/shared/modules" -) - -var _ modules.IntegratableModule = &persistenceAddrBookProvider{} -var _ typesP2P.AddrBookProvider = &persistenceAddrBookProvider{} - -type persistenceAddrBookProvider struct { - bus modules.Bus - p2pCfg modules.P2PConfig - connFactory typesP2P.ConnectionFactory -} - -func NewPersistenceAddrBookProvider(bus modules.Bus, p2pCfg modules.P2PConfig, options ...func(*persistenceAddrBookProvider)) *persistenceAddrBookProvider { - pabp := &persistenceAddrBookProvider{ - bus: bus, - p2pCfg: p2pCfg, - connFactory: transport.CreateDialer, // default connection factory, overridable with WithConnectionFactory() - } - - for _, o := range options { - o(pabp) - } - - return pabp -} - -// WithConnectionFactory allows the user to specify a custom connection factory -func WithConnectionFactory(connFactory typesP2P.ConnectionFactory) func(*persistenceAddrBookProvider) { - return func(pabp *persistenceAddrBookProvider) { - pabp.connFactory = connFactory - } -} - -func (pabp *persistenceAddrBookProvider) GetBus() modules.Bus { - return pabp.bus -} - -func (pabp *persistenceAddrBookProvider) SetBus(bus modules.Bus) { - pabp.bus = bus -} - -func (pabp *persistenceAddrBookProvider) GetStakedAddrBookAtHeight(height uint64) (typesP2P.AddrBook, error) { - persistenceReadContext, err := pabp.GetBus().GetPersistenceModule().NewReadContext(int64(height)) - if err != nil { - return nil, err - } - stakedActors, err := persistenceReadContext.GetAllStakedActors(int64(height)) - if err != nil { - return nil, err - } - addrBook, err := pabp.ActorsToAddrBook(stakedActors) - if err != nil { - return nil, err - } - return addrBook, nil -} - -func (pabp *persistenceAddrBookProvider) ActorsToAddrBook(actors []modules.Actor) (typesP2P.AddrBook, error) { - book := make(typesP2P.AddrBook, 0) - for _, a := range actors { - networkPeer, err := pabp.ActorToNetworkPeer(a) - if err != nil { - log.Println("[WARN] Error connecting to validator: ", err) - continue - } - book = append(book, networkPeer) - } - return book, nil -} - -func (pabp *persistenceAddrBookProvider) ActorToNetworkPeer(actor modules.Actor) (*typesP2P.NetworkPeer, error) { - conn, err := pabp.connFactory(pabp.p2pCfg, actor.GetGenericParam()) // service url - if err != nil { - return nil, fmt.Errorf("error resolving addr: %v", err) - } - - pubKey, err := cryptoPocket.NewPublicKey(actor.GetPublicKey()) - if err != nil { - return nil, err - } - - peer := &typesP2P.NetworkPeer{ - Dialer: conn, - PublicKey: pubKey, - Address: pubKey.Address(), - ServiceUrl: actor.GetGenericParam(), // service url - } - - return peer, nil -} diff --git a/p2p/providers/addrbook_provider/addrbook_provider.go b/p2p/providers/addrbook_provider/addrbook_provider.go new file mode 100644 index 000000000..eb3ec863d --- /dev/null +++ b/p2p/providers/addrbook_provider/addrbook_provider.go @@ -0,0 +1,61 @@ +package addrbook_provider + +//go:generate mockgen -source=$GOFILE -destination=../../types/mocks/addrbook_provider_mock.go -package=mock_types github.com/pokt-network/pocket/p2p/types AddrBookProvider + +import ( + "fmt" + "log" + + typesP2P "github.com/pokt-network/pocket/p2p/types" + cryptoPocket "github.com/pokt-network/pocket/shared/crypto" + "github.com/pokt-network/pocket/shared/modules" +) + +// AddrBookProvider is an interface that provides AddrBook accessors +type AddrBookProvider interface { + GetStakedAddrBookAtHeight(height uint64) (typesP2P.AddrBook, error) + GetConnFactory() typesP2P.ConnectionFactory + GetP2PConfig() modules.P2PConfig + SetConnectionFactory(typesP2P.ConnectionFactory) +} + +func ActorsToAddrBook(abp AddrBookProvider, actors []modules.Actor) (typesP2P.AddrBook, error) { + book := make(typesP2P.AddrBook, 0) + for _, a := range actors { + networkPeer, err := ActorToNetworkPeer(abp, a) + if err != nil { + log.Println("[WARN] Error connecting to validator: ", err) + continue + } + book = append(book, networkPeer) + } + return book, nil +} + +func ActorToNetworkPeer(abp AddrBookProvider, actor modules.Actor) (*typesP2P.NetworkPeer, error) { + conn, err := abp.GetConnFactory()(abp.GetP2PConfig(), actor.GetGenericParam()) // service url + if err != nil { + return nil, fmt.Errorf("error resolving addr: %v", err) + } + + pubKey, err := cryptoPocket.NewPublicKey(actor.GetPublicKey()) + if err != nil { + return nil, err + } + + peer := &typesP2P.NetworkPeer{ + Dialer: conn, + PublicKey: pubKey, + Address: pubKey.Address(), + ServiceUrl: actor.GetGenericParam(), // service url + } + + return peer, nil +} + +// WithConnectionFactory allows the user to specify a custom connection factory +func WithConnectionFactory(connFactory typesP2P.ConnectionFactory) func(AddrBookProvider) { + return func(ap AddrBookProvider) { + ap.SetConnectionFactory(connFactory) + } +} diff --git a/p2p/providers/addrbook_provider/debug/addrbook_provider.go b/p2p/providers/addrbook_provider/debug/addrbook_provider.go new file mode 100644 index 000000000..84002a464 --- /dev/null +++ b/p2p/providers/addrbook_provider/debug/addrbook_provider.go @@ -0,0 +1,71 @@ +package debug + +import ( + "github.com/pokt-network/pocket/p2p/providers/addrbook_provider" + "github.com/pokt-network/pocket/p2p/transport" + typesP2P "github.com/pokt-network/pocket/p2p/types" + "github.com/pokt-network/pocket/shared/modules" +) + +const ( + // ALL_HEIGHTS is a special height that will be used to indicate that the actors are valid for all heights (including future heights) + ALL_HEIGHTS = -1 +) + +var _ addrbook_provider.AddrBookProvider = &debugAddrBookProvider{} + +type debugAddrBookProvider struct { + p2pCfg modules.P2PConfig + actorsByHeight map[int64][]modules.Actor + connFactory typesP2P.ConnectionFactory +} + +func NewDebugAddrBookProvider(p2pCfg modules.P2PConfig, options ...func(*debugAddrBookProvider)) *debugAddrBookProvider { + dabp := &debugAddrBookProvider{ + p2pCfg: p2pCfg, + connFactory: transport.CreateDialer, // default connection factory, overridable with WithConnectionFactory() + } + + for _, o := range options { + o(dabp) + } + + return dabp +} + +func WithActorsByHeight(actorsByHeight map[int64][]modules.Actor) func(*debugAddrBookProvider) { + return func(pabp *debugAddrBookProvider) { + pabp.actorsByHeight = actorsByHeight + } +} + +func (dabp *debugAddrBookProvider) getActorsByHeight(height uint64) []modules.Actor { + var stakedActors []modules.Actor + stakedActors, ok := dabp.actorsByHeight[ALL_HEIGHTS] + if ok { + return stakedActors + } + stakedActors = dabp.actorsByHeight[int64(height)] + return stakedActors +} + +func (dabp *debugAddrBookProvider) GetStakedAddrBookAtHeight(height uint64) (typesP2P.AddrBook, error) { + stakedActors := dabp.getActorsByHeight(height) + addrBook, err := addrbook_provider.ActorsToAddrBook(dabp, stakedActors) + if err != nil { + return nil, err + } + return addrBook, nil +} + +func (dabp *debugAddrBookProvider) GetConnFactory() typesP2P.ConnectionFactory { + return dabp.connFactory +} + +func (dabp *debugAddrBookProvider) GetP2PConfig() modules.P2PConfig { + return dabp.p2pCfg +} + +func (dabp *debugAddrBookProvider) SetConnectionFactory(connFactory typesP2P.ConnectionFactory) { + dabp.connFactory = connFactory +} diff --git a/p2p/providers/addrbook_provider/persistence/addrbook_provider.go b/p2p/providers/addrbook_provider/persistence/addrbook_provider.go new file mode 100644 index 000000000..c4cfd7ba4 --- /dev/null +++ b/p2p/providers/addrbook_provider/persistence/addrbook_provider.go @@ -0,0 +1,67 @@ +package persistence + +import ( + "github.com/pokt-network/pocket/p2p/providers/addrbook_provider" + "github.com/pokt-network/pocket/p2p/transport" + typesP2P "github.com/pokt-network/pocket/p2p/types" + "github.com/pokt-network/pocket/shared/modules" +) + +var _ modules.IntegratableModule = &persistenceAddrBookProvider{} +var _ addrbook_provider.AddrBookProvider = &persistenceAddrBookProvider{} + +type persistenceAddrBookProvider struct { + bus modules.Bus + p2pCfg modules.P2PConfig + connFactory typesP2P.ConnectionFactory +} + +func NewPersistenceAddrBookProvider(bus modules.Bus, p2pCfg modules.P2PConfig, options ...func(*persistenceAddrBookProvider)) *persistenceAddrBookProvider { + pabp := &persistenceAddrBookProvider{ + bus: bus, + p2pCfg: p2pCfg, + connFactory: transport.CreateDialer, // default connection factory, overridable with WithConnectionFactory() + } + + for _, o := range options { + o(pabp) + } + + return pabp +} + +func (pabp *persistenceAddrBookProvider) GetBus() modules.Bus { + return pabp.bus +} + +func (pabp *persistenceAddrBookProvider) SetBus(bus modules.Bus) { + pabp.bus = bus +} + +func (pabp *persistenceAddrBookProvider) GetStakedAddrBookAtHeight(height uint64) (typesP2P.AddrBook, error) { + persistenceReadContext, err := pabp.GetBus().GetPersistenceModule().NewReadContext(int64(height)) + if err != nil { + return nil, err + } + stakedActors, err := persistenceReadContext.GetAllStakedActors(int64(height)) + if err != nil { + return nil, err + } + addrBook, err := addrbook_provider.ActorsToAddrBook(pabp, stakedActors) + if err != nil { + return nil, err + } + return addrBook, nil +} + +func (pabp *persistenceAddrBookProvider) GetConnFactory() typesP2P.ConnectionFactory { + return pabp.connFactory +} + +func (pabp *persistenceAddrBookProvider) GetP2PConfig() modules.P2PConfig { + return pabp.p2pCfg +} + +func (pabp *persistenceAddrBookProvider) SetConnectionFactory(connFactory typesP2P.ConnectionFactory) { + pabp.connFactory = connFactory +} diff --git a/p2p/providers/current_height_provider/current_height_provider.go b/p2p/providers/current_height_provider/current_height_provider.go new file mode 100644 index 000000000..feb858bc2 --- /dev/null +++ b/p2p/providers/current_height_provider/current_height_provider.go @@ -0,0 +1,7 @@ +package current_height_provider + +//go:generate mockgen -source=$GOFILE -destination=../../types/mocks/current_height_provider_mock.go -package=mock_types github.com/pokt-network/pocket/p2p/types CurrentHeightProvider + +type CurrentHeightProvider interface { + CurrentHeight() uint64 +} diff --git a/p2p/providers/current_height_provider/debug/debug_current_height_provider.go b/p2p/providers/current_height_provider/debug/debug_current_height_provider.go new file mode 100644 index 000000000..7575cdd9e --- /dev/null +++ b/p2p/providers/current_height_provider/debug/debug_current_height_provider.go @@ -0,0 +1,21 @@ +package debug + +import "github.com/pokt-network/pocket/p2p/providers/current_height_provider" + +var _ current_height_provider.CurrentHeightProvider = &debugCurrentHeightProvider{} + +type debugCurrentHeightProvider struct { + currentHeight uint64 +} + +func (dchp *debugCurrentHeightProvider) CurrentHeight() uint64 { + return dchp.currentHeight +} + +func NewDebugCurrentHeightProvider(height uint64) *debugCurrentHeightProvider { + dchp := &debugCurrentHeightProvider{ + currentHeight: height, + } + + return dchp +} diff --git a/p2p/providers/providers.go b/p2p/providers/providers.go new file mode 100644 index 000000000..05dfdfe62 --- /dev/null +++ b/p2p/providers/providers.go @@ -0,0 +1,9 @@ +package providers + +import ( + "github.com/pokt-network/pocket/p2p/providers/addrbook_provider" + "github.com/pokt-network/pocket/p2p/providers/current_height_provider" +) + +type AddrBookProvider = addrbook_provider.AddrBookProvider +type CurrentHeightProvider = current_height_provider.CurrentHeightProvider From fe3418bd31bdaf2b3b58eb07bdde5e46912c6186 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 22 Dec 2022 23:12:23 +0000 Subject: [PATCH 100/143] fix(build): updated configs with missing value --- build/config/config1.json | 4 +++- build/config/config2.json | 3 ++- build/config/config3.json | 3 ++- build/config/config4.json | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/build/config/config1.json b/build/config/config1.json index 359328cb5..38ee7688f 100644 --- a/build/config/config1.json +++ b/build/config/config1.json @@ -27,7 +27,9 @@ "consensus_port": 8080, "use_rain_tree": true, "is_empty_connection_type": false, - "private_key": "6fd0bc54cc2dd205eaf226eebdb0451629b321f11d279013ce6fdd5a33059256b2eda2232ffb2750bf761141f70f75a03a025f65b2b2b417c7f8b3c9ca91e8e4" + "private_key": "6fd0bc54cc2dd205eaf226eebdb0451629b321f11d279013ce6fdd5a33059256b2eda2232ffb2750bf761141f70f75a03a025f65b2b2b417c7f8b3c9ca91e8e4", + "max_mempool_count": 10000, + "is_client_only": false }, "telemetry": { "enabled": true, diff --git a/build/config/config2.json b/build/config/config2.json index 3b60ffa62..c060f4108 100644 --- a/build/config/config2.json +++ b/build/config/config2.json @@ -27,7 +27,8 @@ "consensus_port": 8080, "use_rain_tree": true, "is_empty_connection_type": false, - "private_key": "5db3e9d97d04d6d70359de924bb02039c602080d6bf01a692bad31ad5ef93524c16043323c83ffd901a8bf7d73543814b8655aa4695f7bfb49d01926fc161cdb" + "private_key": "5db3e9d97d04d6d70359de924bb02039c602080d6bf01a692bad31ad5ef93524c16043323c83ffd901a8bf7d73543814b8655aa4695f7bfb49d01926fc161cdb", + "max_mempool_count": 10000 }, "telemetry": { "enabled": true, diff --git a/build/config/config3.json b/build/config/config3.json index 54140b350..6de76c22c 100644 --- a/build/config/config3.json +++ b/build/config/config3.json @@ -27,7 +27,8 @@ "consensus_port": 8080, "use_rain_tree": true, "is_empty_connection_type": false, - "private_key": "b37d3ba2f232060c41ba1177fea6008d885fcccad6826d64ee7d49f94d1dbc49a8b6be75d7551da093f788f7286c3a9cb885cfc8e52710eac5f1d5e5b4bf19b2" + "private_key": "b37d3ba2f232060c41ba1177fea6008d885fcccad6826d64ee7d49f94d1dbc49a8b6be75d7551da093f788f7286c3a9cb885cfc8e52710eac5f1d5e5b4bf19b2", + "max_mempool_count": 10000 }, "telemetry": { "enabled": true, diff --git a/build/config/config4.json b/build/config/config4.json index 333ebad2e..9595b4ccf 100644 --- a/build/config/config4.json +++ b/build/config/config4.json @@ -27,7 +27,8 @@ "consensus_port": 8080, "use_rain_tree": true, "is_empty_connection_type": false, - "private_key": "c6c136d010d07d7f5e9944aa3594a10f9210dd3e26ebc1bc1516a6d957fd0df353ee26c82826694ffe1773d7b60d5f20dd9e91bdf8745544711bec5ff9c6fb4a" + "private_key": "c6c136d010d07d7f5e9944aa3594a10f9210dd3e26ebc1bc1516a6d957fd0df353ee26c82826694ffe1773d7b60d5f20dd9e91bdf8745544711bec5ff9c6fb4a", + "max_mempool_count": 10000 }, "telemetry": { "enabled": true, From eff0afb8862b2bff19bd4072b090b89b2db64ca9 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 22 Dec 2022 23:13:13 +0000 Subject: [PATCH 101/143] feat(P2P): updated raintree to use the providers --- p2p/raintree/network.go | 16 ++++++++++++---- p2p/raintree/network_test.go | 6 ++++-- p2p/raintree/peers_manager.go | 3 ++- p2p/raintree/peers_manager_test.go | 9 ++++++--- p2p/raintree/utils_test.go | 7 ++++++- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/p2p/raintree/network.go b/p2p/raintree/network.go index 8da4e4ccf..ff6802005 100644 --- a/p2p/raintree/network.go +++ b/p2p/raintree/network.go @@ -6,6 +6,8 @@ import ( "math/rand" "time" + "github.com/pokt-network/pocket/p2p/providers" + "github.com/pokt-network/pocket/p2p/providers/addrbook_provider" typesP2P "github.com/pokt-network/pocket/p2p/types" "github.com/pokt-network/pocket/shared/codec" cryptoPocket "github.com/pokt-network/pocket/shared/crypto" @@ -22,7 +24,7 @@ type rainTreeNetwork struct { bus modules.Bus selfAddr cryptoPocket.Address - addrBookProvider typesP2P.AddrBookProvider + addrBookProvider addrbook_provider.AddrBookProvider peersManager *peersManager @@ -51,8 +53,8 @@ func NewRainTreeNetworkWithAddrBook(addr cryptoPocket.Address, addrBook typesP2P return typesP2P.Network(n) } -func NewRainTreeNetwork(addr cryptoPocket.Address, bus modules.Bus, p2pCfg modules.P2PConfig, addrBookProvider typesP2P.AddrBookProvider) typesP2P.Network { - addrBook, err := addrBookProvider.GetStakedAddrBookAtHeight(bus.GetConsensusModule().CurrentHeight()) +func NewRainTreeNetwork(addr cryptoPocket.Address, bus modules.Bus, p2pCfg modules.P2PConfig, addrBookProvider providers.AddrBookProvider, currentHeightProvider providers.CurrentHeightProvider) typesP2P.Network { + addrBook, err := addrBookProvider.GetStakedAddrBookAtHeight(currentHeightProvider.CurrentHeight()) if err != nil { log.Fatalf("[ERROR] Error getting addrBook: %v", err) } @@ -147,7 +149,13 @@ func (n *rainTreeNetwork) networkSendInternal(data []byte, address cryptoPocket. return err } - n.GetBus(). + // this is because in client mode there's no bus + bus := n.GetBus() + if bus == nil { + return nil + } + + bus. GetTelemetryModule(). GetEventMetricsAgent(). EmitEvent( diff --git a/p2p/raintree/network_test.go b/p2p/raintree/network_test.go index 732f982b9..3d4819471 100644 --- a/p2p/raintree/network_test.go +++ b/p2p/raintree/network_test.go @@ -26,8 +26,9 @@ func TestRainTreeNetwork_AddPeerToAddrBook(t *testing.T) { busMock := mockBus(ctrl) addrBookProviderMock := mockAddrBookProvider(ctrl, addrBook) + currentHeightProviderMock := mockCurrentHeightProvider(ctrl, 0) - network := NewRainTreeNetwork(selfAddr, busMock, mockP2PCfg, addrBookProviderMock).(*rainTreeNetwork) + network := NewRainTreeNetwork(selfAddr, busMock, mockP2PCfg, addrBookProviderMock, currentHeightProviderMock).(*rainTreeNetwork) peerAddr, err := cryptoPocket.GenerateAddress() require.NoError(t, err) @@ -65,8 +66,9 @@ func TestRainTreeNetwork_RemovePeerToAddrBook(t *testing.T) { busMock := mockBus(ctrl) addrBookProviderMock := mockAddrBookProvider(ctrl, addrBook) + currentHeightProviderMock := mockCurrentHeightProvider(ctrl, 0) - network := NewRainTreeNetwork(selfAddr, busMock, mockP2PCfg, addrBookProviderMock).(*rainTreeNetwork) + network := NewRainTreeNetwork(selfAddr, busMock, mockP2PCfg, addrBookProviderMock, currentHeightProviderMock).(*rainTreeNetwork) stateView := network.peersManager.getNetworkView() require.Equal(t, numAddressesInAddressBook+1, len(stateView.addrList)) // +1 to account for self in the addrBook as well diff --git a/p2p/raintree/peers_manager.go b/p2p/raintree/peers_manager.go index 6bbba74a2..67c07a1e4 100644 --- a/p2p/raintree/peers_manager.go +++ b/p2p/raintree/peers_manager.go @@ -6,6 +6,7 @@ import ( "sort" "sync" + "github.com/pokt-network/pocket/p2p/providers/addrbook_provider" "github.com/pokt-network/pocket/p2p/types" typesP2P "github.com/pokt-network/pocket/p2p/types" cryptoPocket "github.com/pokt-network/pocket/shared/crypto" @@ -30,7 +31,7 @@ type peersManager struct { maxNumLevels uint32 } -func newPeersManagerWithAddrBookProvider(selfAddr cryptoPocket.Address, addrBookProvider typesP2P.AddrBookProvider, height uint64) (*peersManager, error) { +func newPeersManagerWithAddrBookProvider(selfAddr cryptoPocket.Address, addrBookProvider addrbook_provider.AddrBookProvider, height uint64) (*peersManager, error) { addrBook, err := addrBookProvider.GetStakedAddrBookAtHeight(height) if err != nil { return nil, err diff --git a/p2p/raintree/peers_manager_test.go b/p2p/raintree/peers_manager_test.go index 25a71530c..5baf933a8 100644 --- a/p2p/raintree/peers_manager_test.go +++ b/p2p/raintree/peers_manager_test.go @@ -80,8 +80,9 @@ func TestRainTreeAddrBookUtilsHandleUpdate(t *testing.T) { mockBus := mockBus(ctrl) mockAddrBookProvider := mockAddrBookProvider(ctrl, addrBook) + currentHeightProviderMock := mockCurrentHeightProvider(ctrl, 0) - network := NewRainTreeNetwork(addr, mockBus, mockP2PCfg, mockAddrBookProvider).(*rainTreeNetwork) + network := NewRainTreeNetwork(addr, mockBus, mockP2PCfg, mockAddrBookProvider, currentHeightProviderMock).(*rainTreeNetwork) peersManagerStateView := network.peersManager.getNetworkView() @@ -122,8 +123,9 @@ func BenchmarkAddrBookUpdates(b *testing.B) { mockBus := mockBus(ctrl) mockAddrBookProvider := mockAddrBookProvider(ctrl, addrBook) + currentHeightProviderMock := mockCurrentHeightProvider(ctrl, 0) - network := NewRainTreeNetwork(addr, mockBus, mockP2PCfg, mockAddrBookProvider).(*rainTreeNetwork) + network := NewRainTreeNetwork(addr, mockBus, mockP2PCfg, mockAddrBookProvider, currentHeightProviderMock).(*rainTreeNetwork) peersManagerStateView := network.peersManager.getNetworkView() @@ -213,8 +215,9 @@ func testRainTreeMessageTargets(t *testing.T, expectedMsgProp *ExpectedRainTreeM addrBook := getAlphabetAddrBook(expectedMsgProp.numNodes) mockAddrBookProvider := mockAddrBookProvider(ctrl, addrBook) + currentHeightProviderMock := mockCurrentHeightProvider(ctrl, 1) - network := NewRainTreeNetwork([]byte{expectedMsgProp.orig}, busMock, mockP2PCfg, mockAddrBookProvider).(*rainTreeNetwork) + network := NewRainTreeNetwork([]byte{expectedMsgProp.orig}, busMock, mockP2PCfg, mockAddrBookProvider, currentHeightProviderMock).(*rainTreeNetwork) network.SetBus(busMock) diff --git a/p2p/raintree/utils_test.go b/p2p/raintree/utils_test.go index 44cc76c50..342905cf0 100644 --- a/p2p/raintree/utils_test.go +++ b/p2p/raintree/utils_test.go @@ -18,7 +18,12 @@ func mockBus(ctrl *gomock.Controller) *mockModules.MockBus { func mockAddrBookProvider(ctrl *gomock.Controller, addrBook typesP2P.AddrBook) *mocksP2P.MockAddrBookProvider { addrBookProviderMock := mocksP2P.NewMockAddrBookProvider(ctrl) - addrBookProviderMock.EXPECT().ActorsToAddrBook(gomock.Any()).Return(addrBook, nil).AnyTimes() addrBookProviderMock.EXPECT().GetStakedAddrBookAtHeight(gomock.Any()).Return(addrBook, nil).AnyTimes() return addrBookProviderMock } + +func mockCurrentHeightProvider(ctrl *gomock.Controller, height uint64) *mocksP2P.MockCurrentHeightProvider { + currentHeightProviderMock := mocksP2P.NewMockCurrentHeightProvider(ctrl) + currentHeightProviderMock.EXPECT().CurrentHeight().Return(height).AnyTimes() + return currentHeightProviderMock +} From a4ea7df07685ddfe22fa72ddc0afdc4cd0ae2452 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 22 Dec 2022 23:14:06 +0000 Subject: [PATCH 102/143] feat(CLI): updated to spin up only P2P --- app/client/cli/debug.go | 75 ++++++++++++----------------------------- 1 file changed, 22 insertions(+), 53 deletions(-) diff --git a/app/client/cli/debug.go b/app/client/cli/debug.go index cd7492abe..ae190663a 100644 --- a/app/client/cli/debug.go +++ b/app/client/cli/debug.go @@ -1,6 +1,3 @@ -//go:build debug -// +build debug - package cli import ( @@ -9,16 +6,13 @@ import ( "sync" "github.com/manifoldco/promptui" - "github.com/pokt-network/pocket/consensus" - "github.com/pokt-network/pocket/logger" "github.com/pokt-network/pocket/p2p" - "github.com/pokt-network/pocket/rpc" + debugABP "github.com/pokt-network/pocket/p2p/providers/addrbook_provider/debug" + debugCHP "github.com/pokt-network/pocket/p2p/providers/current_height_provider/debug" "github.com/pokt-network/pocket/runtime" - "github.com/pokt-network/pocket/shared" pocketCrypto "github.com/pokt-network/pocket/shared/crypto" "github.com/pokt-network/pocket/shared/messaging" "github.com/pokt-network/pocket/shared/modules" - "github.com/pokt-network/pocket/telemetry" "github.com/spf13/cobra" "google.golang.org/protobuf/types/known/anypb" ) @@ -51,16 +45,7 @@ var ( PromptShowLatestBlockInStore, } - // HACK: this is a temporary solution that guarantees backward compatibility while we implement peer discovery (#416). - // these addresses are simply copied over from the genesis file. - // We could read them from there as well but it would be just a uselessly more sophisticated HACK :) - // the goal is to keep it so ugly to look at that we are forced to fix it as soon as possible (already in progress) - validatorAddresses = []string{ - "6f66574e1f50f0ef72dff748c3f11b9e0e89d32a", - "67eb3f0a50ae459fecf666be0e93176e92441317", - "3f52e08c4b3b65ab7cf098d77df5bf8cedcf5f99", - "113fdb095d42d6e09327ab5b8df13fd8197a1eaf", - } + validators []modules.Actor ) func init() { @@ -159,8 +144,8 @@ func broadcastDebugMessage(debugMsg *messaging.DebugMessage) { // address book of the actual validator nodes, so `node1.consensus` never receives the message. // p2pMod.Broadcast(anyProto, messaging.PocketTopic_DEBUG_TOPIC) - for _, valAddr := range validatorAddresses { - addr, err := pocketCrypto.NewAddress(valAddr) + for _, valAddr := range validators { + addr, err := pocketCrypto.NewAddress(valAddr.GetAddress()) if err != nil { log.Fatalf("[ERROR] Failed to convert validator address into pocketCrypto.Address: %v", err) } @@ -176,11 +161,11 @@ func sendDebugMessage(debugMsg *messaging.DebugMessage) { } var validatorAddress []byte - if len(validatorAddresses) == 0 { - log.Fatalf("[ERROR] No validator addresses found") + if len(validators) == 0 { + log.Fatalf("[ERROR] No validators found") } - validatorAddress, err = pocketCrypto.NewAddress(validatorAddresses[0]) + validatorAddress, err = pocketCrypto.NewAddress(validators[0].GetAddress()) if err != nil { log.Fatalf("[ERROR] Failed to convert validator address into pocketCrypto.Address: %v", err) } @@ -193,41 +178,25 @@ func initDebug(remoteCLIURL string) { var err error runtimeMgr := runtime.NewManagerFromFiles(defaultConfigPath, defaultGenesisPath, runtime.WithRandomPK()) - consM, err := consensus.Create(runtimeMgr) - if err != nil { - logger.Global.Fatal().Err(err).Msg("Failed to create consensus module") - } - consensusMod = consM.(modules.ConsensusModule) - - p2pM, err := p2p.Create(runtimeMgr) - if err != nil { - log.Fatalf("[ERROR] Failed to create p2p module: %v", err.Error()) - } - p2pMod = p2pM.(modules.P2PModule) + // HACK: this is a temporary solution that guarantees backward compatibility while we implement peer discovery (#416). + validators = runtimeMgr.GetGenesis().GetConsensusGenesisState().GetVals() - // This telemetry module instance is a NOOP because the 'enable_telemetry' flag in the `cfg` above is set to false. - // Since this client mimics partial - networking only - functionality of a full node, some of the telemetry-related - // code paths are executed. To avoid those messages interfering with the telemetry data collected, a non-nil telemetry - // module that NOOPs (per the configs above) is injected. - telemetryM, err := telemetry.Create(runtimeMgr) - if err != nil { - logger.Global.Fatal().Err(err).Msg("Failed to create telemetry module") - } - telemetryMod := telemetryM.(modules.TelemetryModule) + debugAddressBookProvider := debugABP.NewDebugAddrBookProvider( + runtimeMgr.GetConfig().GetP2PConfig(), + debugABP.WithActorsByHeight( + map[int64][]modules.Actor{ + debugABP.ALL_HEIGHTS: validators, + }, + ), + ) - loggerM, err := logger.Create(runtimeMgr) - if err != nil { - logger.Global.Fatal().Err(err).Msg("Failed to create logger module") - } - loggerMod := loggerM.(modules.LoggerModule) + debugCurrentHeightProvider := debugCHP.NewDebugCurrentHeightProvider(0) - rpcM, err := rpc.Create(runtimeMgr) + p2pM, err := p2p.CreateWithProviders(runtimeMgr, debugAddressBookProvider, debugCurrentHeightProvider) if err != nil { - logger.Global.Fatal().Err(err).Msg("Failed to create rpc module") + log.Fatalf("[ERROR] Failed to create p2p module: %v", err.Error()) } - rpcMod := rpcM.(modules.RPCModule) - - _ = shared.CreateBusWithOptionalModules(runtimeMgr, nil, p2pMod, nil, consensusMod, telemetryMod, loggerMod, rpcMod) // REFACTOR: use the `WithXXXModule()` pattern accepting a slice of IntegratableModule + p2pMod = p2pM.(modules.P2PModule) p2pMod.Start() }) From 2eea763874c4c1486c383ebad0a7ef7473594d02 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 22 Dec 2022 23:14:32 +0000 Subject: [PATCH 103/143] refactor(P2P): updated stdnetwork to use providers --- p2p/stdnetwork/network.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/p2p/stdnetwork/network.go b/p2p/stdnetwork/network.go index bed961b06..8e66a2d60 100644 --- a/p2p/stdnetwork/network.go +++ b/p2p/stdnetwork/network.go @@ -6,6 +6,7 @@ import ( "fmt" "log" + "github.com/pokt-network/pocket/p2p/providers/addrbook_provider" typesP2P "github.com/pokt-network/pocket/p2p/types" cryptoPocket "github.com/pokt-network/pocket/shared/crypto" "github.com/pokt-network/pocket/shared/modules" @@ -18,7 +19,7 @@ type network struct { addrBookMap typesP2P.AddrBookMap } -func NewNetwork(bus modules.Bus, p2pCfg modules.P2PConfig, addrBookProvider typesP2P.AddrBookProvider) (n typesP2P.Network) { +func NewNetwork(bus modules.Bus, p2pCfg modules.P2PConfig, addrBookProvider addrbook_provider.AddrBookProvider) (n typesP2P.Network) { addrBook, err := addrBookProvider.GetStakedAddrBookAtHeight(bus.GetConsensusModule().CurrentHeight()) if err != nil { log.Fatalf("[ERROR] Error getting addrBook: %v", err) From 77586e4b94a7d32ce5e300cc9c8d25a9933885da Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 22 Dec 2022 23:15:08 +0000 Subject: [PATCH 104/143] feat(P2P): isClientOnly flag --- p2p/types/proto/p2p_config.proto | 1 + shared/modules/types.go | 1 + 2 files changed, 2 insertions(+) diff --git a/p2p/types/proto/p2p_config.proto b/p2p/types/proto/p2p_config.proto index 6b4700a55..c6f6e5999 100644 --- a/p2p/types/proto/p2p_config.proto +++ b/p2p/types/proto/p2p_config.proto @@ -10,6 +10,7 @@ message P2PConfig { bool use_rain_tree = 3; bool is_empty_connection_type = 4; // TODO (Drewsky) switch back to enum uint64 max_mempool_count = 5; // this is used to limit the number of nonces that can be stored in the mempool, after which a FIFO mechanism is used to remove the oldest nonces and make space for the new ones + bool is_client_only = 6; } enum ConnectionType { diff --git a/shared/modules/types.go b/shared/modules/types.go index f224fd9d1..8a1976cbb 100644 --- a/shared/modules/types.go +++ b/shared/modules/types.go @@ -56,6 +56,7 @@ type P2PConfig interface { GetUseRainTree() bool GetIsEmptyConnectionType() bool // TODO : make enum GetMaxMempoolCount() uint64 + GetIsClientOnly() bool } type TelemetryConfig interface { From 7b3b7c54f48792733350373b7fbe06232141baa3 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 22 Dec 2022 23:15:51 +0000 Subject: [PATCH 105/143] refactor(P2P): injected providers . --- p2p/module.go | 101 +++++++++++++++++++++++++++++++++-------- p2p/types/addr_book.go | 11 ----- 2 files changed, 83 insertions(+), 29 deletions(-) diff --git a/p2p/module.go b/p2p/module.go index 54f5a52bb..da51bde00 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -4,7 +4,8 @@ import ( "fmt" "log" - "github.com/pokt-network/pocket/p2p/addrbook_provider" + "github.com/pokt-network/pocket/p2p/providers" + persABP "github.com/pokt-network/pocket/p2p/providers/addrbook_provider/persistence" "github.com/pokt-network/pocket/p2p/raintree" "github.com/pokt-network/pocket/p2p/stdnetwork" "github.com/pokt-network/pocket/p2p/transport" @@ -31,18 +32,17 @@ type p2pModule struct { address cryptoPocket.Address network typesP2P.Network -} -// TECHDEBT(drewsky): Discuss how to best expose/access `Address` throughout the codebase. -func (m *p2pModule) GetAddress() (cryptoPocket.Address, error) { - return m.address, nil + injectedAddrBookProvider providers.AddrBookProvider + injectedCurrentHeightProvider providers.CurrentHeightProvider } func Create(runtimeMgr modules.RuntimeMgr) (modules.Module, error) { return new(p2pModule).Create(runtimeMgr) } -func (*p2pModule) Create(runtimeMgr modules.RuntimeMgr) (modules.Module, error) { +// IMPROVE: need to define a better pattern for dependency injection. Currently we are probably limiting ourselves by having a common constructor `Create(runtimeMgr modules.RuntimeMgr) (modules.Module, error)` for all modules. +func CreateWithProviders(runtimeMgr modules.RuntimeMgr, addrBookProvider providers.AddrBookProvider, currentHeightProvider providers.CurrentHeightProvider) (modules.Module, error) { log.Println("Creating network module") var m *p2pModule @@ -52,20 +52,55 @@ func (*p2pModule) Create(runtimeMgr modules.RuntimeMgr) (modules.Module, error) } p2pCfg := cfg.GetP2PConfig() - l, err := transport.CreateListener(p2pCfg) + privateKey, err := cryptoPocket.NewPrivateKey(p2pCfg.GetPrivateKey()) if err != nil { return nil, err } + m = &p2pModule{ + p2pCfg: p2pCfg, + address: privateKey.Address(), + injectedAddrBookProvider: addrBookProvider, + injectedCurrentHeightProvider: currentHeightProvider, + } + + if !p2pCfg.GetIsClientOnly() { + l, err := transport.CreateListener(p2pCfg) + if err != nil { + return nil, err + } + m.listener = l + } + + return m, nil +} + +func (*p2pModule) Create(runtimeMgr modules.RuntimeMgr) (modules.Module, error) { + log.Println("Creating network module") + var m *p2pModule + + cfg := runtimeMgr.GetConfig() + if err := m.ValidateConfig(cfg); err != nil { + return nil, fmt.Errorf("config validation failed: %w", err) + } + p2pCfg := cfg.GetP2PConfig() + privateKey, err := cryptoPocket.NewPrivateKey(p2pCfg.GetPrivateKey()) if err != nil { return nil, err } m = &p2pModule{ - p2pCfg: p2pCfg, + p2pCfg: p2pCfg, + address: privateKey.Address(), + } - listener: l, - address: privateKey.Address(), + if !p2pCfg.GetIsClientOnly() { + l, err := transport.CreateListener(p2pCfg) + if err != nil { + return nil, err + } + m.listener = l } + return m, nil } @@ -90,6 +125,19 @@ func (m *p2pModule) GetModuleName() string { func (m *p2pModule) Start() error { log.Println("Starting network module") + addrbookProvider := getAddrBookProvider(m) + currentHeightProvider := getCurrentHeightProvider(m) + + if m.p2pCfg.GetUseRainTree() { + m.network = raintree.NewRainTreeNetwork(m.address, m.GetBus(), m.p2pCfg, addrbookProvider, currentHeightProvider) + } else { + m.network = stdnetwork.NewNetwork(m.GetBus(), m.p2pCfg, addrbookProvider) + } + + if m.p2pCfg.GetIsClientOnly() { + return nil + } + m.GetBus(). GetTelemetryModule(). GetTimeSeriesAgent(). @@ -98,14 +146,6 @@ func (m *p2pModule) Start() error { telemetry.P2P_NODE_STARTED_TIMESERIES_METRIC_DESCRIPTION, ) - addrbookProvider := addrbook_provider.NewPersistenceAddrBookProvider(m.GetBus(), m.p2pCfg) - - if m.p2pCfg.GetUseRainTree() { - m.network = raintree.NewRainTreeNetwork(m.address, m.GetBus(), m.p2pCfg, addrbookProvider) - } else { - m.network = stdnetwork.NewNetwork(m.GetBus(), m.p2pCfg, addrbookProvider) - } - go func() { for { data, err := m.listener.Read() @@ -125,6 +165,26 @@ func (m *p2pModule) Start() error { return nil } +func getAddrBookProvider(m *p2pModule) providers.AddrBookProvider { + var addrbookProvider providers.AddrBookProvider + if m.injectedAddrBookProvider == nil { + addrbookProvider = persABP.NewPersistenceAddrBookProvider(m.GetBus(), m.p2pCfg) + } else { + addrbookProvider = m.injectedAddrBookProvider + } + return addrbookProvider +} + +func getCurrentHeightProvider(m *p2pModule) providers.CurrentHeightProvider { + var currentHeightProvider providers.CurrentHeightProvider + if m.injectedCurrentHeightProvider == nil { + currentHeightProvider = m.GetBus().GetConsensusModule() + } else { + currentHeightProvider = m.injectedCurrentHeightProvider + } + return currentHeightProvider +} + func (m *p2pModule) Stop() error { log.Println("Stopping network module") if err := m.listener.Close(); err != nil { @@ -158,6 +218,11 @@ func (m *p2pModule) Send(addr cryptoPocket.Address, msg *anypb.Any) error { return m.network.NetworkSend(data, addr) } +// TECHDEBT(drewsky): Discuss how to best expose/access `Address` throughout the codebase. +func (m *p2pModule) GetAddress() (cryptoPocket.Address, error) { + return m.address, nil +} + func (*p2pModule) ValidateConfig(cfg modules.Config) error { // TODO (#334): implement this return nil diff --git a/p2p/types/addr_book.go b/p2p/types/addr_book.go index d282a7a81..3a317b18b 100644 --- a/p2p/types/addr_book.go +++ b/p2p/types/addr_book.go @@ -1,9 +1,5 @@ package types -//go:generate mockgen -source=$GOFILE -destination=./mocks/addrbook_provider_mock.go github.com/pokt-network/pocket/p2p/types AddrBookProvider - -import "github.com/pokt-network/pocket/shared/modules" - // AddrBook is a way of representing NetworkPeer sets type AddrBook []*NetworkPeer @@ -11,10 +7,3 @@ type AddrBook []*NetworkPeer // // Since maps cannot be sorted arbitrarily in Go, to achieve sorting, we need to rely on `addrList` which is a slice of addresses/strings and therefore we can sort it the way we want. type AddrBookMap map[string]*NetworkPeer - -// AddrBookProvider is an interface that provides AddrBook accessors -type AddrBookProvider interface { - GetStakedAddrBookAtHeight(height uint64) (AddrBook, error) - ActorsToAddrBook(actors []modules.Actor) (AddrBook, error) - ActorToNetworkPeer(actor modules.Actor) (*NetworkPeer, error) -} From 6213789fb796162f835f0f51fcda0fabf5e2f5ef Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 22 Dec 2022 23:16:07 +0000 Subject: [PATCH 106/143] chore(go.mod): tidy --- go.mod | 29 ++++++++++++++------------- go.sum | 62 ++++++++++++++++++++++++++++++++++++---------------------- 2 files changed, 54 insertions(+), 37 deletions(-) diff --git a/go.mod b/go.mod index b0f541362..1782ea860 100644 --- a/go.mod +++ b/go.mod @@ -11,8 +11,8 @@ require ( github.com/golang/mock v1.6.0 github.com/jackc/pgx/v4 v4.17.2 github.com/ory/dockertest v3.3.5+incompatible - github.com/stretchr/testify v1.8.0 - golang.org/x/crypto v0.0.0-20221012134737-56aed061732a + github.com/stretchr/testify v1.8.1 + golang.org/x/crypto v0.1.0 golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 gonum.org/v1/gonum v0.12.0 google.golang.org/protobuf v1.28.1 @@ -60,7 +60,7 @@ require ( github.com/prometheus/client_golang v1.13.0 github.com/sirupsen/logrus v1.9.0 // indirect go.opencensus.io v0.23.0 // indirect - golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect + golang.org/x/net v0.2.0 // indirect gotest.tools v2.2.0+incompatible // indirect ) @@ -72,7 +72,7 @@ require ( github.com/prometheus/common v0.37.0 // indirect github.com/prometheus/procfs v0.8.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - golang.org/x/term v0.0.0-20220919170432-7a66f970e087 // indirect + golang.org/x/term v0.2.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) @@ -83,7 +83,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect - github.com/go-openapi/swag v0.19.5 // indirect + github.com/go-openapi/swag v0.21.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/hashicorp/hcl v1.0.0 // indirect @@ -94,11 +94,12 @@ require ( github.com/jackc/pgproto3/v2 v2.3.1 // indirect github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect github.com/jackc/pgtype v1.12.0 // indirect + github.com/josharian/intern v1.0.0 // indirect github.com/labstack/gommon v0.4.0 // indirect github.com/magiconair/properties v1.8.6 // indirect - github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e // indirect - github.com/mattn/go-colorable v0.1.12 // indirect - github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mailru/easyjson v0.7.7 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.16 // indirect github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml/v2 v2.0.5 // indirect @@ -109,12 +110,12 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/subosito/gotenv v1.4.1 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect - github.com/valyala/fasttemplate v1.2.1 // indirect - golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect - golang.org/x/sys v0.0.0-20221013171732-95e765b1cc43 // indirect - golang.org/x/text v0.3.8 // indirect - golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect - golang.org/x/tools v0.1.12 // indirect + github.com/valyala/fasttemplate v1.2.2 // indirect + golang.org/x/mod v0.7.0 // indirect + golang.org/x/sys v0.2.0 // indirect + golang.org/x/text v0.4.0 // indirect + golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect + golang.org/x/tools v0.3.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 71f1933cc..0197be791 100644 --- a/go.sum +++ b/go.sum @@ -102,6 +102,7 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:ma github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -145,8 +146,9 @@ github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= -github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.21.1 h1:wm0rhTb5z7qpJRHBdPOMuY4QjVUMbF6/kwoYeRAOrKU= +github.com/go-openapi/swag v0.21.1/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.0.6/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= @@ -293,6 +295,8 @@ github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dv github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jordanorelli/lexnum v0.0.0-20141216151731-460eeb125754 h1:ovgRFhVUYZWz6KnWPrnV7HBxrK0ErOeyXtlVvh0Rr5k= github.com/jordanorelli/lexnum v0.0.0-20141216151731-460eeb125754/go.mod h1:f1WdQhB98V35bULPsZUMFP9U1XWhpaHrO6myMijgMhU= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -319,6 +323,7 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/labstack/echo/v4 v4.9.1 h1:GliPYSpzGKlyOhqIbG8nmHBo3i1saKWFOgh41AN3b+Y= github.com/labstack/echo/v4 v4.9.1/go.mod h1:Pop5HLc+xoc4qhTZ1ip6C0RtP7Z+4VzRLWZZFKqbbjo= github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8= @@ -332,20 +337,23 @@ github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA= github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= -github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= -github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.2 h1:hAHbPm5IJGijwng3PWk09JkG9WeqChjprR5s9bBZ+OM= github.com/matttproud/golang_protobuf_extensions v1.0.2/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= @@ -364,6 +372,7 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwd github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM= @@ -461,6 +470,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -468,8 +478,9 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs= github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= @@ -477,8 +488,9 @@ github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljT github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4= github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= +github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= +github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE= github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= @@ -522,8 +534,8 @@ golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20221012134737-56aed061732a h1:NmSIgad6KjE6VvHciPZuNRTKxGhlPfD6OA87W/PLkqg= -golang.org/x/crypto v0.0.0-20221012134737-56aed061732a/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= +golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -560,8 +572,8 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA= +golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -602,8 +614,8 @@ golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.0.0-20221014081412-f15817d10f9b h1:tvrvnPFcdzp294diPnrdZZZ8XUt2Tyj7svb7X52iDuU= -golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= +golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU= +golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -626,6 +638,7 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -690,15 +703,16 @@ golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20221013171732-95e765b1cc43 h1:OK7RB6t2WQX54srQQYSXMW8dF5C6/8+oA/s5QBmmto4= -golang.org/x/sys v0.0.0-20221013171732-95e765b1cc43/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= +golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.0.0-20220919170432-7a66f970e087 h1:tPwmk4vmvVCMdr98VgL4JH+qZxPL8fqlUOHnyOM8N3w= -golang.org/x/term v0.0.0-20220919170432-7a66f970e087/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.2.0 h1:z85xZCsEl7bi/KwbNADeBYoOP0++7W1ipu+aGnpwzRM= +golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -707,13 +721,13 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= -golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE= -golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20220411224347-583f2d630306 h1:+gHMid33q6pen7kv9xvT+JRinntgeXO2AeZVd0AWD3w= +golang.org/x/time v0.0.0-20220411224347-583f2d630306/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= @@ -769,8 +783,8 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.3.0 h1:SrNbZl6ECOS1qFzgTdQfWXZM9XBkiA6tkFrH9YSTPHM= +golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -876,6 +890,7 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= @@ -890,6 +905,7 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= From 3c026f7feda5cd6c4f017b6067aac5292ddc6995 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 22 Dec 2022 23:16:29 +0000 Subject: [PATCH 107/143] feat(Makefile): flag override for isClientOnly --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 4c74fae79..42610938b 100644 --- a/Makefile +++ b/Makefile @@ -137,7 +137,7 @@ client_start: docker_check .PHONY: client_connect ## Connect to the running client debugging daemon client_connect: docker_check - docker exec -it client /bin/bash -c "go run -tags=debug app/client/*.go debug" + docker exec -it client /bin/bash -c "POCKET_P2P_IS_CLIENT_ONLY=true go run -tags=debug app/client/*.go debug" .PHONY: build_and_watch ## Continous build Pocket's main entrypoint as files change @@ -249,11 +249,11 @@ mockgen: clean_mocks go generate ./${modules_dir} echo "Mocks generated in ${modules_dir}/mocks" - $(eval p2p_types_dir = "p2p/types") + $(eval p2p_dir = "p2p") $(eval p2p_type_mocks_dir = "p2p/types/mocks") find ${p2p_type_mocks_dir} -type f ! -name "mocks.go" -exec rm {} \; - go generate ./${p2p_types_dir} - echo "P2P mocks generated in ${p2p_types_dir}/mocks" + go generate ./${p2p_dir}/... + echo "P2P mocks generated in ${p2p_type_mocks_dir}" # TODO(team): Tested locally with `protoc` version `libprotoc 3.19.4`. In the near future, only the Dockerfiles will be used to compile protos. From c9b27eeaa3a6f0b21326a50220281f2f463da416 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 22 Dec 2022 23:18:31 +0000 Subject: [PATCH 108/143] fix(P2P): stdnetwork uses currentHeightProvider as well --- p2p/module.go | 2 +- p2p/stdnetwork/network.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/p2p/module.go b/p2p/module.go index da51bde00..d71d256aa 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -131,7 +131,7 @@ func (m *p2pModule) Start() error { if m.p2pCfg.GetUseRainTree() { m.network = raintree.NewRainTreeNetwork(m.address, m.GetBus(), m.p2pCfg, addrbookProvider, currentHeightProvider) } else { - m.network = stdnetwork.NewNetwork(m.GetBus(), m.p2pCfg, addrbookProvider) + m.network = stdnetwork.NewNetwork(m.GetBus(), m.p2pCfg, addrbookProvider, currentHeightProvider) } if m.p2pCfg.GetIsClientOnly() { diff --git a/p2p/stdnetwork/network.go b/p2p/stdnetwork/network.go index 8e66a2d60..b76f8e8cb 100644 --- a/p2p/stdnetwork/network.go +++ b/p2p/stdnetwork/network.go @@ -6,7 +6,7 @@ import ( "fmt" "log" - "github.com/pokt-network/pocket/p2p/providers/addrbook_provider" + "github.com/pokt-network/pocket/p2p/providers" typesP2P "github.com/pokt-network/pocket/p2p/types" cryptoPocket "github.com/pokt-network/pocket/shared/crypto" "github.com/pokt-network/pocket/shared/modules" @@ -19,8 +19,8 @@ type network struct { addrBookMap typesP2P.AddrBookMap } -func NewNetwork(bus modules.Bus, p2pCfg modules.P2PConfig, addrBookProvider addrbook_provider.AddrBookProvider) (n typesP2P.Network) { - addrBook, err := addrBookProvider.GetStakedAddrBookAtHeight(bus.GetConsensusModule().CurrentHeight()) +func NewNetwork(bus modules.Bus, p2pCfg modules.P2PConfig, addrBookProvider providers.AddrBookProvider, currentHeightProvider providers.CurrentHeightProvider) (n typesP2P.Network) { + addrBook, err := addrBookProvider.GetStakedAddrBookAtHeight(currentHeightProvider.CurrentHeight()) if err != nil { log.Fatalf("[ERROR] Error getting addrBook: %v", err) } From ec59138fffbb9f41b2602f5fb8082931adc1965c Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 22 Dec 2022 23:30:14 +0000 Subject: [PATCH 109/143] docs(P2P): changelog --- p2p/CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/p2p/CHANGELOG.md b/p2p/CHANGELOG.md index a54dfd530..817ffb15f 100644 --- a/p2p/CHANGELOG.md +++ b/p2p/CHANGELOG.md @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.0.0.13] - 2022-12-22 + +- Refactored `AddrBookProvider` to support multiple implementations +- Added `CurrentHeightProvider` +- Dependency injection of the aforementioned provider into the module creation (used by the debug-client) +- Updated implementation to use the providers +- Updated tests and mocks + ## [0.0.0.12] - 2022-12-16 - `ValidatorMapToAddrBook` renamed to `ActorToAddrBook` From 981da2ce4195594b57d0ebc53a345c759e17ffac Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 22 Dec 2022 23:32:39 +0000 Subject: [PATCH 110/143] docs(shared): changelog --- shared/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/shared/CHANGELOG.md b/shared/CHANGELOG.md index 657e3ccc1..a6e4c1e1c 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.7] - 2022-12-22 + +- Removed `ValidatorMap() ValidatorMap` from `ConsensusModule` interface +- Added `GetIsClientOnly()` to `P2PConfig` + ## [0.0.0.6] - 2022-12-14 - Added `GetMaxMempoolCount` From cc221b6d85d7813a47c5b154a7aed53951d79970 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 22 Dec 2022 23:33:44 +0000 Subject: [PATCH 111/143] docs(consensus): changelog --- consensus/doc/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/consensus/doc/CHANGELOG.md b/consensus/doc/CHANGELOG.md index 7c4267f40..bb6ddd54c 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.14] - 2022-12-22 + +- Removed `ValidatorMap() ValidatorMap` + ## [0.0.0.13] - 2022-12-14 - Consolidated number of validators in tests in a single constant: `numValidators` From 4a820dc6f1576bf7bdaf7ef5b3549771059d3458 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 22 Dec 2022 23:43:36 +0000 Subject: [PATCH 112/143] docs(CLI): changelog --- app/client/cli/doc/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/client/cli/doc/CHANGELOG.md b/app/client/cli/doc/CHANGELOG.md index 3f8516c53..3b1dc71a0 100644 --- a/app/client/cli/doc/CHANGELOG.md +++ b/app/client/cli/doc/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.0.3] - 2022-12-22 + +- The `client` now doesn't instantiate a `P2P` module and compose a bus with optional modules anymore. It insteads instantiates a `client-only` `P2P` module that is disconnected from consensus and persistence. These interactions happen via RPC. +- Replaced previous implementation reliant on `ValidatorMap` with a temporary fetch from genesis. This will be replaced with a lightweight peer discovery mechanism (#416) + ## [0.0.2] - 2022-11-02 ### Added From 2abd96bf5a8c1c0cd75ac89f5541c1ec8adb3695 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 22 Dec 2022 23:47:48 +0000 Subject: [PATCH 113/143] docs(build): changelog --- build/doc/CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 build/doc/CHANGELOG.md diff --git a/build/doc/CHANGELOG.md b/build/doc/CHANGELOG.md new file mode 100644 index 000000000..da1ae4b30 --- /dev/null +++ b/build/doc/CHANGELOG.md @@ -0,0 +1,14 @@ +# Changelog + +All notable changes to this module will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +## [0.0.0.0] - 2022-12-22 + +- introduced this `CHANGELOG.md` +- Updated configs with the missing value `max_mempool_count` +- Added `is_client_only` to `config1.json` so that Viper knows it can be overridden. Done in the Makefile in `make client_connect`. Setting this can be avoided if we merge the changes in https://github.com/pokt-network/pocket/compare/main...issue/cli-viper-environment-vars-fix From 9efa129c6e08ad6eeb250b66bcf7e9d2bed7a6ac Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 22 Dec 2022 23:49:58 +0000 Subject: [PATCH 114/143] fix(build): changelog... --- build/doc/CHANGELOG.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/build/doc/CHANGELOG.md b/build/doc/CHANGELOG.md index da1ae4b30..17bcf4045 100644 --- a/build/doc/CHANGELOG.md +++ b/build/doc/CHANGELOG.md @@ -7,8 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.0] - 2022-12-22 +## [0.0.0.1] - 2022-12-22 -- introduced this `CHANGELOG.md` - Updated configs with the missing value `max_mempool_count` - Added `is_client_only` to `config1.json` so that Viper knows it can be overridden. Done in the Makefile in `make client_connect`. Setting this can be avoided if we merge the changes in https://github.com/pokt-network/pocket/compare/main...issue/cli-viper-environment-vars-fix + +## [0.0.0.0] - 2022-12-22 + +- Introduced this `CHANGELOG.md` From 21f182ddda1011dc942b689f2050fc8fd9a712b1 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 22 Dec 2022 23:51:07 +0000 Subject: [PATCH 115/143] fix(CLI): changelog --- app/client/cli/doc/CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/client/cli/doc/CHANGELOG.md b/app/client/cli/doc/CHANGELOG.md index 3b1dc71a0..94e0b008a 100644 --- a/app/client/cli/doc/CHANGELOG.md +++ b/app/client/cli/doc/CHANGELOG.md @@ -7,12 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.3] - 2022-12-22 +## [0.0.0.3] - 2022-12-22 - The `client` now doesn't instantiate a `P2P` module and compose a bus with optional modules anymore. It insteads instantiates a `client-only` `P2P` module that is disconnected from consensus and persistence. These interactions happen via RPC. - Replaced previous implementation reliant on `ValidatorMap` with a temporary fetch from genesis. This will be replaced with a lightweight peer discovery mechanism (#416) -## [0.0.2] - 2022-11-02 +## [0.0.0.2] - 2022-11-02 ### Added @@ -21,13 +21,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - System commands working end-to-end - Added Consensus State commands -## [0.0.1] - 2022-09-09 +## [0.0.0.1] - 2022-09-09 ### Added - Commands documentation generator -## [0.0.0] - 2022-09-07 +## [0.0.0.0] - 2022-09-07 ### Added From 7972285ab8ba5cab403664a77e765f46ba2d0583 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 28 Dec 2022 23:56:30 +0000 Subject: [PATCH 116/143] fix(P2P): addrbook_provider persistence read context close --- .../addrbook_provider/persistence/addrbook_provider.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/p2p/providers/addrbook_provider/persistence/addrbook_provider.go b/p2p/providers/addrbook_provider/persistence/addrbook_provider.go index c4cfd7ba4..bc79eff38 100644 --- a/p2p/providers/addrbook_provider/persistence/addrbook_provider.go +++ b/p2p/providers/addrbook_provider/persistence/addrbook_provider.go @@ -43,6 +43,8 @@ func (pabp *persistenceAddrBookProvider) GetStakedAddrBookAtHeight(height uint64 if err != nil { return nil, err } + defer persistenceReadContext.Close() + stakedActors, err := persistenceReadContext.GetAllStakedActors(int64(height)) if err != nil { return nil, err From fc2a042b8d9161dc8cc6328bd9f7a7ca98b1d627 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 29 Dec 2022 00:00:28 +0000 Subject: [PATCH 117/143] docs(P2P): CHANGELOG --- p2p/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/p2p/CHANGELOG.md b/p2p/CHANGELOG.md index 817ffb15f..8bb538561 100644 --- a/p2p/CHANGELOG.md +++ b/p2p/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.0.0.14] - 2022-12-28 + +- Added missing `Close()` call to `persistenceReadContext` + ## [0.0.0.13] - 2022-12-22 - Refactored `AddrBookProvider` to support multiple implementations From 46d6fb156efa34ad0883659b4c9a34028d22cf91 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 29 Dec 2022 00:03:46 +0000 Subject: [PATCH 118/143] docs(shared): CHANGELOGs dates update... --- app/client/cli/doc/CHANGELOG.md | 2 +- build/doc/CHANGELOG.md | 2 +- consensus/doc/CHANGELOG.md | 2 +- p2p/CHANGELOG.md | 2 +- shared/CHANGELOG.md | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/client/cli/doc/CHANGELOG.md b/app/client/cli/doc/CHANGELOG.md index 94e0b008a..d831ea279 100644 --- a/app/client/cli/doc/CHANGELOG.md +++ b/app/client/cli/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.3] - 2022-12-22 +## [0.0.0.3] - 2022-12-29 - The `client` now doesn't instantiate a `P2P` module and compose a bus with optional modules anymore. It insteads instantiates a `client-only` `P2P` module that is disconnected from consensus and persistence. These interactions happen via RPC. - Replaced previous implementation reliant on `ValidatorMap` with a temporary fetch from genesis. This will be replaced with a lightweight peer discovery mechanism (#416) diff --git a/build/doc/CHANGELOG.md b/build/doc/CHANGELOG.md index 17bcf4045..c86ed1db6 100644 --- a/build/doc/CHANGELOG.md +++ b/build/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.1] - 2022-12-22 +## [0.0.0.1] - 2022-12-29 - Updated configs with the missing value `max_mempool_count` - Added `is_client_only` to `config1.json` so that Viper knows it can be overridden. Done in the Makefile in `make client_connect`. Setting this can be avoided if we merge the changes in https://github.com/pokt-network/pocket/compare/main...issue/cli-viper-environment-vars-fix diff --git a/consensus/doc/CHANGELOG.md b/consensus/doc/CHANGELOG.md index bb6ddd54c..92d4dbcbe 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.14] - 2022-12-22 +## [0.0.0.14] - 2022-12-29 - Removed `ValidatorMap() ValidatorMap` diff --git a/p2p/CHANGELOG.md b/p2p/CHANGELOG.md index 8bb538561..225f2ec99 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.14] - 2022-12-28 +## [0.0.0.14] - 2022-12-29 - Added missing `Close()` call to `persistenceReadContext` diff --git a/shared/CHANGELOG.md b/shared/CHANGELOG.md index a6e4c1e1c..e81430a9c 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.7] - 2022-12-22 +## [0.0.0.7] - 2022-12-29 - Removed `ValidatorMap() ValidatorMap` from `ConsensusModule` interface - Added `GetIsClientOnly()` to `P2PConfig` From 59847fa64b571803fec3c5993512d6245241ec7d Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 29 Dec 2022 00:18:02 +0000 Subject: [PATCH 119/143] test(P2P): fixed tests, added missing expected call to Close --- p2p/utils_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/p2p/utils_test.go b/p2p/utils_test.go index ab0e31c1f..9f7fb4863 100644 --- a/p2p/utils_test.go +++ b/p2p/utils_test.go @@ -199,6 +199,7 @@ func preparePersistenceMock(t *testing.T, genesisState modules.GenesisState) *mo readContextMock.EXPECT().GetAllStakedActors(gomock.Any()).Return(genesisState.GetPersistenceGenesisState().GetVals(), nil).AnyTimes() persistenceMock.EXPECT().NewReadContext(gomock.Any()).Return(readContextMock, nil).AnyTimes() + readContextMock.EXPECT().Close().Return(nil).AnyTimes() return persistenceMock } From 3eeef0dfaf74f1adac359b29a7ed4d0b217245cd Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 4 Jan 2023 00:14:58 +0000 Subject: [PATCH 120/143] chore(shared): merge fixes --- app/client/cli/debug.go | 9 +++++---- build/config/config1.json | 2 +- build/config/config2.json | 2 +- build/config/config3.json | 2 +- build/config/config4.json | 2 +- p2p/module.go | 11 ++++++----- .../addrbook_provider/addrbook_provider.go | 9 +++++---- .../debug/addrbook_provider.go | 17 +++++++++-------- .../persistence/addrbook_provider.go | 7 ++++--- 9 files changed, 33 insertions(+), 28 deletions(-) diff --git a/app/client/cli/debug.go b/app/client/cli/debug.go index ae190663a..8d272598f 100644 --- a/app/client/cli/debug.go +++ b/app/client/cli/debug.go @@ -10,6 +10,7 @@ import ( debugABP "github.com/pokt-network/pocket/p2p/providers/addrbook_provider/debug" debugCHP "github.com/pokt-network/pocket/p2p/providers/current_height_provider/debug" "github.com/pokt-network/pocket/runtime" + coreTypes "github.com/pokt-network/pocket/shared/core/types" pocketCrypto "github.com/pokt-network/pocket/shared/crypto" "github.com/pokt-network/pocket/shared/messaging" "github.com/pokt-network/pocket/shared/modules" @@ -45,7 +46,7 @@ var ( PromptShowLatestBlockInStore, } - validators []modules.Actor + validators []*coreTypes.Actor ) func init() { @@ -179,12 +180,12 @@ func initDebug(remoteCLIURL string) { runtimeMgr := runtime.NewManagerFromFiles(defaultConfigPath, defaultGenesisPath, runtime.WithRandomPK()) // HACK: this is a temporary solution that guarantees backward compatibility while we implement peer discovery (#416). - validators = runtimeMgr.GetGenesis().GetConsensusGenesisState().GetVals() + validators = runtimeMgr.GetGenesis().Validators debugAddressBookProvider := debugABP.NewDebugAddrBookProvider( - runtimeMgr.GetConfig().GetP2PConfig(), + runtimeMgr.GetConfig().P2P, debugABP.WithActorsByHeight( - map[int64][]modules.Actor{ + map[int64][]*coreTypes.Actor{ debugABP.ALL_HEIGHTS: validators, }, ), diff --git a/build/config/config1.json b/build/config/config1.json index f38d48822..9eef908af 100644 --- a/build/config/config1.json +++ b/build/config/config1.json @@ -26,7 +26,7 @@ "use_rain_tree": true, "is_empty_connection_type": false, "private_key": "6fd0bc54cc2dd205eaf226eebdb0451629b321f11d279013ce6fdd5a33059256b2eda2232ffb2750bf761141f70f75a03a025f65b2b2b417c7f8b3c9ca91e8e4", - "max_mempool_count": 10000, + "max_mempool_count": 100000, "is_client_only": false }, "telemetry": { diff --git a/build/config/config2.json b/build/config/config2.json index 87795fe10..ab67a2de5 100644 --- a/build/config/config2.json +++ b/build/config/config2.json @@ -26,7 +26,7 @@ "use_rain_tree": true, "is_empty_connection_type": false, "private_key": "5db3e9d97d04d6d70359de924bb02039c602080d6bf01a692bad31ad5ef93524c16043323c83ffd901a8bf7d73543814b8655aa4695f7bfb49d01926fc161cdb", - "max_mempool_count": 10000 + "max_mempool_count": 100000 }, "telemetry": { "enabled": true, diff --git a/build/config/config3.json b/build/config/config3.json index 1ea2711b4..ee6f63652 100644 --- a/build/config/config3.json +++ b/build/config/config3.json @@ -26,7 +26,7 @@ "use_rain_tree": true, "is_empty_connection_type": false, "private_key": "b37d3ba2f232060c41ba1177fea6008d885fcccad6826d64ee7d49f94d1dbc49a8b6be75d7551da093f788f7286c3a9cb885cfc8e52710eac5f1d5e5b4bf19b2", - "max_mempool_count": 10000 + "max_mempool_count": 100000 }, "telemetry": { "enabled": true, diff --git a/build/config/config4.json b/build/config/config4.json index 7209be1d6..36fb8f7ff 100644 --- a/build/config/config4.json +++ b/build/config/config4.json @@ -26,7 +26,7 @@ "use_rain_tree": true, "is_empty_connection_type": false, "private_key": "c6c136d010d07d7f5e9944aa3594a10f9210dd3e26ebc1bc1516a6d957fd0df353ee26c82826694ffe1773d7b60d5f20dd9e91bdf8745544711bec5ff9c6fb4a", - "max_mempool_count": 10000 + "max_mempool_count": 100000 }, "telemetry": { "enabled": true, diff --git a/p2p/module.go b/p2p/module.go index 6e33308ff..c248b939b 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -1,7 +1,6 @@ package p2p import ( - "fmt" "log" "github.com/pokt-network/pocket/p2p/providers" @@ -77,10 +76,7 @@ func (*p2pModule) Create(runtimeMgr modules.RuntimeMgr) (modules.Module, error) var m *p2pModule cfg := runtimeMgr.GetConfig() - if err := m.ValidateConfig(cfg); err != nil { - return nil, fmt.Errorf("config validation failed: %w", err) - } - p2pCfg := cfg.GetP2PConfig() + p2pCfg := cfg.P2P privateKey, err := cryptoPocket.NewPrivateKey(p2pCfg.PrivateKey) if err != nil { @@ -216,6 +212,11 @@ func (m *p2pModule) Send(addr cryptoPocket.Address, msg *anypb.Any) error { return m.network.NetworkSend(data, addr) } +// TECHDEBT(drewsky): Discuss how to best expose/access `Address` throughout the codebase. +func (m *p2pModule) GetAddress() (cryptoPocket.Address, error) { + return m.address, nil +} + func (m *p2pModule) handleNetworkMessage(networkMsgData []byte) { appMsgData, err := m.network.HandleNetworkData(networkMsgData) if err != nil { diff --git a/p2p/providers/addrbook_provider/addrbook_provider.go b/p2p/providers/addrbook_provider/addrbook_provider.go index eb3ec863d..abdee4611 100644 --- a/p2p/providers/addrbook_provider/addrbook_provider.go +++ b/p2p/providers/addrbook_provider/addrbook_provider.go @@ -7,19 +7,20 @@ import ( "log" 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" ) // AddrBookProvider is an interface that provides AddrBook accessors type AddrBookProvider interface { GetStakedAddrBookAtHeight(height uint64) (typesP2P.AddrBook, error) GetConnFactory() typesP2P.ConnectionFactory - GetP2PConfig() modules.P2PConfig + GetP2PConfig() *configs.P2PConfig SetConnectionFactory(typesP2P.ConnectionFactory) } -func ActorsToAddrBook(abp AddrBookProvider, actors []modules.Actor) (typesP2P.AddrBook, error) { +func ActorsToAddrBook(abp AddrBookProvider, actors []*coreTypes.Actor) (typesP2P.AddrBook, error) { book := make(typesP2P.AddrBook, 0) for _, a := range actors { networkPeer, err := ActorToNetworkPeer(abp, a) @@ -32,7 +33,7 @@ func ActorsToAddrBook(abp AddrBookProvider, actors []modules.Actor) (typesP2P.Ad return book, nil } -func ActorToNetworkPeer(abp AddrBookProvider, actor modules.Actor) (*typesP2P.NetworkPeer, error) { +func ActorToNetworkPeer(abp AddrBookProvider, actor *coreTypes.Actor) (*typesP2P.NetworkPeer, error) { conn, err := abp.GetConnFactory()(abp.GetP2PConfig(), actor.GetGenericParam()) // service url if err != nil { return nil, fmt.Errorf("error resolving addr: %v", err) diff --git a/p2p/providers/addrbook_provider/debug/addrbook_provider.go b/p2p/providers/addrbook_provider/debug/addrbook_provider.go index 84002a464..d41bdb0a4 100644 --- a/p2p/providers/addrbook_provider/debug/addrbook_provider.go +++ b/p2p/providers/addrbook_provider/debug/addrbook_provider.go @@ -4,7 +4,8 @@ import ( "github.com/pokt-network/pocket/p2p/providers/addrbook_provider" "github.com/pokt-network/pocket/p2p/transport" typesP2P "github.com/pokt-network/pocket/p2p/types" - "github.com/pokt-network/pocket/shared/modules" + "github.com/pokt-network/pocket/runtime/configs" + coreTypes "github.com/pokt-network/pocket/shared/core/types" ) const ( @@ -15,12 +16,12 @@ const ( var _ addrbook_provider.AddrBookProvider = &debugAddrBookProvider{} type debugAddrBookProvider struct { - p2pCfg modules.P2PConfig - actorsByHeight map[int64][]modules.Actor + p2pCfg *configs.P2PConfig + actorsByHeight map[int64][]*coreTypes.Actor connFactory typesP2P.ConnectionFactory } -func NewDebugAddrBookProvider(p2pCfg modules.P2PConfig, options ...func(*debugAddrBookProvider)) *debugAddrBookProvider { +func NewDebugAddrBookProvider(p2pCfg *configs.P2PConfig, options ...func(*debugAddrBookProvider)) *debugAddrBookProvider { dabp := &debugAddrBookProvider{ p2pCfg: p2pCfg, connFactory: transport.CreateDialer, // default connection factory, overridable with WithConnectionFactory() @@ -33,14 +34,14 @@ func NewDebugAddrBookProvider(p2pCfg modules.P2PConfig, options ...func(*debugAd return dabp } -func WithActorsByHeight(actorsByHeight map[int64][]modules.Actor) func(*debugAddrBookProvider) { +func WithActorsByHeight(actorsByHeight map[int64][]*coreTypes.Actor) func(*debugAddrBookProvider) { return func(pabp *debugAddrBookProvider) { pabp.actorsByHeight = actorsByHeight } } -func (dabp *debugAddrBookProvider) getActorsByHeight(height uint64) []modules.Actor { - var stakedActors []modules.Actor +func (dabp *debugAddrBookProvider) getActorsByHeight(height uint64) []*coreTypes.Actor { + var stakedActors []*coreTypes.Actor stakedActors, ok := dabp.actorsByHeight[ALL_HEIGHTS] if ok { return stakedActors @@ -62,7 +63,7 @@ func (dabp *debugAddrBookProvider) GetConnFactory() typesP2P.ConnectionFactory { return dabp.connFactory } -func (dabp *debugAddrBookProvider) GetP2PConfig() modules.P2PConfig { +func (dabp *debugAddrBookProvider) GetP2PConfig() *configs.P2PConfig { return dabp.p2pCfg } diff --git a/p2p/providers/addrbook_provider/persistence/addrbook_provider.go b/p2p/providers/addrbook_provider/persistence/addrbook_provider.go index bc79eff38..2d4f5c1c1 100644 --- a/p2p/providers/addrbook_provider/persistence/addrbook_provider.go +++ b/p2p/providers/addrbook_provider/persistence/addrbook_provider.go @@ -4,6 +4,7 @@ import ( "github.com/pokt-network/pocket/p2p/providers/addrbook_provider" "github.com/pokt-network/pocket/p2p/transport" typesP2P "github.com/pokt-network/pocket/p2p/types" + "github.com/pokt-network/pocket/runtime/configs" "github.com/pokt-network/pocket/shared/modules" ) @@ -12,11 +13,11 @@ var _ addrbook_provider.AddrBookProvider = &persistenceAddrBookProvider{} type persistenceAddrBookProvider struct { bus modules.Bus - p2pCfg modules.P2PConfig + p2pCfg *configs.P2PConfig connFactory typesP2P.ConnectionFactory } -func NewPersistenceAddrBookProvider(bus modules.Bus, p2pCfg modules.P2PConfig, options ...func(*persistenceAddrBookProvider)) *persistenceAddrBookProvider { +func NewPersistenceAddrBookProvider(bus modules.Bus, p2pCfg *configs.P2PConfig, options ...func(*persistenceAddrBookProvider)) *persistenceAddrBookProvider { pabp := &persistenceAddrBookProvider{ bus: bus, p2pCfg: p2pCfg, @@ -60,7 +61,7 @@ func (pabp *persistenceAddrBookProvider) GetConnFactory() typesP2P.ConnectionFac return pabp.connFactory } -func (pabp *persistenceAddrBookProvider) GetP2PConfig() modules.P2PConfig { +func (pabp *persistenceAddrBookProvider) GetP2PConfig() *configs.P2PConfig { return pabp.p2pCfg } From bd9fc6b155983cfc935b7e4acc2822836e578c19 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 4 Jan 2023 00:23:42 +0000 Subject: [PATCH 121/143] docs(shared): CHANGELOG --- app/client/cli/doc/CHANGELOG.md | 2 +- build/doc/CHANGELOG.md | 17 ----------------- build/docs/CHANGELOG.md | 7 ++++++- consensus/doc/CHANGELOG.md | 2 +- p2p/CHANGELOG.md | 2 +- runtime/docs/CHANGELOG.md | 4 ++++ shared/CHANGELOG.md | 2 +- 7 files changed, 14 insertions(+), 22 deletions(-) delete mode 100644 build/doc/CHANGELOG.md diff --git a/app/client/cli/doc/CHANGELOG.md b/app/client/cli/doc/CHANGELOG.md index 9131c925b..a9dc70f5e 100644 --- a/app/client/cli/doc/CHANGELOG.md +++ b/app/client/cli/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.4] - 2023-01-03 +## [0.0.0.4] - 2023-01-04 - The `client` now doesn't instantiate a `P2P` module and compose a bus with optional modules anymore. It insteads instantiates a `client-only` `P2P` module that is disconnected from consensus and persistence. These interactions happen via RPC. - Replaced previous implementation reliant on `ValidatorMap` with a temporary fetch from genesis. This will be replaced with a lightweight peer discovery mechanism (#416) diff --git a/build/doc/CHANGELOG.md b/build/doc/CHANGELOG.md deleted file mode 100644 index c86ed1db6..000000000 --- a/build/doc/CHANGELOG.md +++ /dev/null @@ -1,17 +0,0 @@ -# Changelog - -All notable changes to this module will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [Unreleased] - -## [0.0.0.1] - 2022-12-29 - -- Updated configs with the missing value `max_mempool_count` -- Added `is_client_only` to `config1.json` so that Viper knows it can be overridden. Done in the Makefile in `make client_connect`. Setting this can be avoided if we merge the changes in https://github.com/pokt-network/pocket/compare/main...issue/cli-viper-environment-vars-fix - -## [0.0.0.0] - 2022-12-22 - -- Introduced this `CHANGELOG.md` diff --git a/build/docs/CHANGELOG.md b/build/docs/CHANGELOG.md index aa092940b..caeb12754 100644 --- a/build/docs/CHANGELOG.md +++ b/build/docs/CHANGELOG.md @@ -7,11 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.1] - 2023-01-03 +## [0.0.0.2] - 2023-01-04 - Removed `BaseConfig` from `configs` - Centralized `PersistenceGenesisState` and `ConsensusGenesisState` into `GenesisState` +## [0.0.0.1] - 2022-12-29 + +- Updated configs with the missing value `max_mempool_count` +- Added `is_client_only` to `config1.json` so that Viper knows it can be overridden. Done in the Makefile in `make client_connect`. Setting this can be avoided if we merge the changes in https://github.com/pokt-network/pocket/compare/main...issue/cli-viper-environment-vars-fix + ## [0.0.0.0] - 2022-12-22 - Introduced this `CHANGELOG.md` diff --git a/consensus/doc/CHANGELOG.md b/consensus/doc/CHANGELOG.md index e16455be4..9cd2e7d2f 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.16] - 2023-01-03 +## [0.0.0.16] - 2023-01-04 - Added protobuf message definitions for requests related to sharing state sync metadata and blocks - Defined the interface for `StateSyncServerModule`, `StateSyncModule` (moving the old interface to `StateSyncModuleLEGACY` as a reference only) diff --git a/p2p/CHANGELOG.md b/p2p/CHANGELOG.md index c28c3df5a..15a56060b 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.16] - 2023-01-03 +## [0.0.0.16] - 2023-01-04 - Added missing `Close()` call to `persistenceReadContext` diff --git a/runtime/docs/CHANGELOG.md b/runtime/docs/CHANGELOG.md index 945232db7..fc6a9e0c2 100644 --- a/runtime/docs/CHANGELOG.md +++ b/runtime/docs/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.0.0.4] - 2023-01-04 + +- Added 'is_client_only' to `P2PConfig` + ## [0.0.0.3] - 2023-01-03 - Split testing/development configs into separate files diff --git a/shared/CHANGELOG.md b/shared/CHANGELOG.md index 90dfb60d8..8765a93f9 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.9] - 2023-01-03 +## [0.0.0.9] - 2023-01-04 - Removed `ValidatorMap() ValidatorMap` from `ConsensusModule` interface - Added `GetIsClientOnly()` to `P2PConfig` From 2b8016cab69a8908d1b3ed86705dfc9f48dfcb52 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 4 Jan 2023 16:54:59 +0000 Subject: [PATCH 122/143] refactor(CLI): simplified init --- app/client/cli/debug.go | 59 +++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/app/client/cli/debug.go b/app/client/cli/debug.go index 8d272598f..64220bc4d 100644 --- a/app/client/cli/debug.go +++ b/app/client/cli/debug.go @@ -3,7 +3,6 @@ package cli import ( "log" "os" - "sync" "github.com/manifoldco/promptui" "github.com/pokt-network/pocket/p2p" @@ -34,10 +33,6 @@ var ( // A P2P module is initialized in order to broadcast a message to the local network p2pMod modules.P2PModule - // A consensus module is initialized in order to get a list of the validator network - consensusMod modules.ConsensusModule - modInitOnce sync.Once - items = []string{ PromptResetToGenesis, PromptPrintNodeState, @@ -59,7 +54,30 @@ func NewDebugCommand() *cobra.Command { Short: "Debug utility for rapid development", Args: cobra.ExactArgs(0), PersistentPreRun: func(cmd *cobra.Command, args []string) { - initDebug(remoteCLIURL) + var err error + runtimeMgr := runtime.NewManagerFromFiles(defaultConfigPath, defaultGenesisPath, runtime.WithRandomPK()) + + // HACK: this is a temporary solution that guarantees backward compatibility while we implement peer discovery (#416). + validators = runtimeMgr.GetGenesis().Validators + + debugAddressBookProvider := debugABP.NewDebugAddrBookProvider( + runtimeMgr.GetConfig().P2P, + debugABP.WithActorsByHeight( + map[int64][]*coreTypes.Actor{ + debugABP.ALL_HEIGHTS: validators, + }, + ), + ) + + debugCurrentHeightProvider := debugCHP.NewDebugCurrentHeightProvider(0) + + p2pM, err := p2p.CreateWithProviders(runtimeMgr, debugAddressBookProvider, debugCurrentHeightProvider) + if err != nil { + log.Fatalf("[ERROR] Failed to create p2p module: %v", err.Error()) + } + p2pMod = p2pM.(modules.P2PModule) + + p2pMod.Start() }, RunE: runDebug, } @@ -173,32 +191,3 @@ func sendDebugMessage(debugMsg *messaging.DebugMessage) { p2pMod.Send(validatorAddress, anyProto) } - -func initDebug(remoteCLIURL string) { - modInitOnce.Do(func() { - var err error - runtimeMgr := runtime.NewManagerFromFiles(defaultConfigPath, defaultGenesisPath, runtime.WithRandomPK()) - - // HACK: this is a temporary solution that guarantees backward compatibility while we implement peer discovery (#416). - validators = runtimeMgr.GetGenesis().Validators - - debugAddressBookProvider := debugABP.NewDebugAddrBookProvider( - runtimeMgr.GetConfig().P2P, - debugABP.WithActorsByHeight( - map[int64][]*coreTypes.Actor{ - debugABP.ALL_HEIGHTS: validators, - }, - ), - ) - - debugCurrentHeightProvider := debugCHP.NewDebugCurrentHeightProvider(0) - - p2pM, err := p2p.CreateWithProviders(runtimeMgr, debugAddressBookProvider, debugCurrentHeightProvider) - if err != nil { - log.Fatalf("[ERROR] Failed to create p2p module: %v", err.Error()) - } - p2pMod = p2pM.(modules.P2PModule) - - p2pMod.Start() - }) -} From d54634c1fc782d0341ff933d0d5b2b102e75bf3c Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 4 Jan 2023 16:59:12 +0000 Subject: [PATCH 123/143] docs(CLI): comments + changelog --- app/client/cli/debug.go | 2 ++ app/client/cli/doc/CHANGELOG.md | 1 + 2 files changed, 3 insertions(+) diff --git a/app/client/cli/debug.go b/app/client/cli/debug.go index 64220bc4d..17695e1e3 100644 --- a/app/client/cli/debug.go +++ b/app/client/cli/debug.go @@ -41,6 +41,8 @@ var ( PromptShowLatestBlockInStore, } + // validators holds the list of the validators at genesis time so that we can use it to create a debug address book provider. + // This is a temporary solution that guarantees backward compatibility while we implement peer discovery (#416). validators []*coreTypes.Actor ) diff --git a/app/client/cli/doc/CHANGELOG.md b/app/client/cli/doc/CHANGELOG.md index a9dc70f5e..6f39bcf3a 100644 --- a/app/client/cli/doc/CHANGELOG.md +++ b/app/client/cli/doc/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The `client` now doesn't instantiate a `P2P` module and compose a bus with optional modules anymore. It insteads instantiates a `client-only` `P2P` module that is disconnected from consensus and persistence. These interactions happen via RPC. - Replaced previous implementation reliant on `ValidatorMap` with a temporary fetch from genesis. This will be replaced with a lightweight peer discovery mechanism (#416) +- Simplified debug CLI initialization ## [0.0.0.3] - 2023-01-03 From 8a4294143399309f5839ea24d77f3e3d1ea9dff3 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 4 Jan 2023 17:01:35 +0000 Subject: [PATCH 124/143] docs(CLI): clarification --- app/client/cli/debug.go | 1 + 1 file changed, 1 insertion(+) diff --git a/app/client/cli/debug.go b/app/client/cli/debug.go index 17695e1e3..ec8dc9ea4 100644 --- a/app/client/cli/debug.go +++ b/app/client/cli/debug.go @@ -42,6 +42,7 @@ var ( } // validators holds the list of the validators at genesis time so that we can use it to create a debug address book provider. + // Its purpose is to allow the CLI to "discover" the nodes in the network. Since currently we don't have churn and we run nodes only in LocalNet, we can rely on the genesis state. // This is a temporary solution that guarantees backward compatibility while we implement peer discovery (#416). validators []*coreTypes.Actor ) From 79d668cec032856afca4d3a935ef20e6f6a25523 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 4 Jan 2023 17:11:24 +0000 Subject: [PATCH 125/143] Update app/client/cli/doc/CHANGELOG.md Co-authored-by: Daniel Olshansky --- app/client/cli/doc/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/client/cli/doc/CHANGELOG.md b/app/client/cli/doc/CHANGELOG.md index a9dc70f5e..00c62c989 100644 --- a/app/client/cli/doc/CHANGELOG.md +++ b/app/client/cli/doc/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.0.0.4] - 2023-01-04 -- The `client` now doesn't instantiate a `P2P` module and compose a bus with optional modules anymore. It insteads instantiates a `client-only` `P2P` module that is disconnected from consensus and persistence. These interactions happen via RPC. +- The `client` (i.e. CLI) no longer instantiates a `P2P` module along with a bus of optional modules. Instead, it instantiates a `client-only` `P2P` module that is disconnected from consensus and persistence. Interactions with the persistence & consensus layer happen via RPC. - Replaced previous implementation reliant on `ValidatorMap` with a temporary fetch from genesis. This will be replaced with a lightweight peer discovery mechanism (#416) ## [0.0.0.3] - 2023-01-03 From 3d3d0b348e00c14261cac844a1147db62fa665a7 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 4 Jan 2023 17:12:50 +0000 Subject: [PATCH 126/143] docs(CLI): todo link --- app/client/cli/debug.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/client/cli/debug.go b/app/client/cli/debug.go index ec8dc9ea4..d7bb37740 100644 --- a/app/client/cli/debug.go +++ b/app/client/cli/debug.go @@ -43,7 +43,7 @@ var ( // validators holds the list of the validators at genesis time so that we can use it to create a debug address book provider. // Its purpose is to allow the CLI to "discover" the nodes in the network. Since currently we don't have churn and we run nodes only in LocalNet, we can rely on the genesis state. - // This is a temporary solution that guarantees backward compatibility while we implement peer discovery (#416). + // HACK(#416): This is a temporary solution that guarantees backward compatibility while we implement peer discovery validators []*coreTypes.Actor ) @@ -60,7 +60,7 @@ func NewDebugCommand() *cobra.Command { var err error runtimeMgr := runtime.NewManagerFromFiles(defaultConfigPath, defaultGenesisPath, runtime.WithRandomPK()) - // HACK: this is a temporary solution that guarantees backward compatibility while we implement peer discovery (#416). + // HACK(#416): this is a temporary solution that guarantees backward compatibility while we implement peer discovery. validators = runtimeMgr.GetGenesis().Validators debugAddressBookProvider := debugABP.NewDebugAddrBookProvider( From b32e865c495327a21d68fd64ed6eafe48f10a885 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 4 Jan 2023 17:15:35 +0000 Subject: [PATCH 127/143] Update app/client/cli/debug.go Co-authored-by: Daniel Olshansky --- app/client/cli/debug.go | 1 + 1 file changed, 1 insertion(+) diff --git a/app/client/cli/debug.go b/app/client/cli/debug.go index d7bb37740..88a54f028 100644 --- a/app/client/cli/debug.go +++ b/app/client/cli/debug.go @@ -187,6 +187,7 @@ func sendDebugMessage(debugMsg *messaging.DebugMessage) { log.Fatalf("[ERROR] No validators found") } + // if the message needs to be broadcast, it'll be handled by the business logic of the message handler validatorAddress, err = pocketCrypto.NewAddress(validators[0].GetAddress()) if err != nil { log.Fatalf("[ERROR] Failed to convert validator address into pocketCrypto.Address: %v", err) From ef5c8b930875cb086eb635ab688e15a40820e887 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 4 Jan 2023 17:16:26 +0000 Subject: [PATCH 128/143] Update build/docs/CHANGELOG.md Co-authored-by: Daniel Olshansky --- build/docs/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/docs/CHANGELOG.md b/build/docs/CHANGELOG.md index caeb12754..6b7305030 100644 --- a/build/docs/CHANGELOG.md +++ b/build/docs/CHANGELOG.md @@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.0.0.1] - 2022-12-29 - Updated configs with the missing value `max_mempool_count` -- Added `is_client_only` to `config1.json` so that Viper knows it can be overridden. Done in the Makefile in `make client_connect`. Setting this can be avoided if we merge the changes in https://github.com/pokt-network/pocket/compare/main...issue/cli-viper-environment-vars-fix +- Added `is_client_only` to `config1.json` so Viper knows it can be overridden. The config override is done in the Makefile's `client_connect` target. Setting this can be avoided if we merge the changes in https://github.com/pokt-network/pocket/compare/main...issue/cli-viper-environment-vars-fix ## [0.0.0.0] - 2022-12-22 From cd1ff1537a76f91be21e46fd524d701bcab3325c Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 4 Jan 2023 17:16:37 +0000 Subject: [PATCH 129/143] Update build/docs/CHANGELOG.md Co-authored-by: Daniel Olshansky --- build/docs/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/docs/CHANGELOG.md b/build/docs/CHANGELOG.md index 6b7305030..967249b08 100644 --- a/build/docs/CHANGELOG.md +++ b/build/docs/CHANGELOG.md @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.0.0.1] - 2022-12-29 -- Updated configs with the missing value `max_mempool_count` +- Updated all `config*.json` files with the missing `max_mempool_count` value - Added `is_client_only` to `config1.json` so Viper knows it can be overridden. The config override is done in the Makefile's `client_connect` target. Setting this can be avoided if we merge the changes in https://github.com/pokt-network/pocket/compare/main...issue/cli-viper-environment-vars-fix ## [0.0.0.0] - 2022-12-22 From f33fa305f3751f1dfc4e64827642a86a2cf67dda Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 4 Jan 2023 17:24:00 +0000 Subject: [PATCH 130/143] refactor(addrbook_provider): ALL_HEIGHTS --- app/client/cli/debug.go | 4 ++-- p2p/providers/addrbook_provider/debug/addrbook_provider.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/client/cli/debug.go b/app/client/cli/debug.go index 88a54f028..d3870a150 100644 --- a/app/client/cli/debug.go +++ b/app/client/cli/debug.go @@ -67,7 +67,7 @@ func NewDebugCommand() *cobra.Command { runtimeMgr.GetConfig().P2P, debugABP.WithActorsByHeight( map[int64][]*coreTypes.Actor{ - debugABP.ALL_HEIGHTS: validators, + debugABP.ANY_HEIGHT: validators, }, ), ) @@ -187,7 +187,7 @@ func sendDebugMessage(debugMsg *messaging.DebugMessage) { log.Fatalf("[ERROR] No validators found") } - // if the message needs to be broadcast, it'll be handled by the business logic of the message handler + // if the message needs to be broadcast, it'll be handled by the business logic of the message handler validatorAddress, err = pocketCrypto.NewAddress(validators[0].GetAddress()) if err != nil { log.Fatalf("[ERROR] Failed to convert validator address into pocketCrypto.Address: %v", err) diff --git a/p2p/providers/addrbook_provider/debug/addrbook_provider.go b/p2p/providers/addrbook_provider/debug/addrbook_provider.go index d41bdb0a4..c1309d878 100644 --- a/p2p/providers/addrbook_provider/debug/addrbook_provider.go +++ b/p2p/providers/addrbook_provider/debug/addrbook_provider.go @@ -9,8 +9,8 @@ import ( ) const ( - // ALL_HEIGHTS is a special height that will be used to indicate that the actors are valid for all heights (including future heights) - ALL_HEIGHTS = -1 + // ANY_HEIGHT is a special height that will be used to indicate that the actors are valid for all heights (including future heights) + ANY_HEIGHT = -1 ) var _ addrbook_provider.AddrBookProvider = &debugAddrBookProvider{} @@ -42,7 +42,7 @@ func WithActorsByHeight(actorsByHeight map[int64][]*coreTypes.Actor) func(*debug func (dabp *debugAddrBookProvider) getActorsByHeight(height uint64) []*coreTypes.Actor { var stakedActors []*coreTypes.Actor - stakedActors, ok := dabp.actorsByHeight[ALL_HEIGHTS] + stakedActors, ok := dabp.actorsByHeight[ANY_HEIGHT] if ok { return stakedActors } From 4f06f567d2272a3c99c9e696bdc5d10d000a3686 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 4 Jan 2023 17:25:44 +0000 Subject: [PATCH 131/143] Update app/client/cli/doc/CHANGELOG.md Co-authored-by: Daniel Olshansky --- app/client/cli/doc/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/client/cli/doc/CHANGELOG.md b/app/client/cli/doc/CHANGELOG.md index e25bf8e03..be2ad6f5f 100644 --- a/app/client/cli/doc/CHANGELOG.md +++ b/app/client/cli/doc/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.0.0.4] - 2023-01-04 - The `client` (i.e. CLI) no longer instantiates a `P2P` module along with a bus of optional modules. Instead, it instantiates a `client-only` `P2P` module that is disconnected from consensus and persistence. Interactions with the persistence & consensus layer happen via RPC. -- Replaced previous implementation reliant on `ValidatorMap` with a temporary fetch from genesis. This will be replaced with a lightweight peer discovery mechanism (#416) +- Replaced previous implementation, reliant on `ValidatorMap`, with a temporary fetch from genesis. This will be replaced with a lightweight peer discovery mechanism in #416 - Simplified debug CLI initialization ## [0.0.0.3] - 2023-01-03 From 307c137a00f2aa0b73276cb587be37cbd450cda7 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Wed, 4 Jan 2023 17:26:53 +0000 Subject: [PATCH 132/143] Update runtime/configs/proto/p2p_config.proto Co-authored-by: Daniel Olshansky --- runtime/configs/proto/p2p_config.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/configs/proto/p2p_config.proto b/runtime/configs/proto/p2p_config.proto index b95d4bbfa..67c3ab30d 100644 --- a/runtime/configs/proto/p2p_config.proto +++ b/runtime/configs/proto/p2p_config.proto @@ -8,7 +8,7 @@ message P2PConfig { string private_key = 1; uint32 consensus_port = 2; bool use_rain_tree = 3; - bool is_empty_connection_type = 4; // TODO (Drewsky) switch back to enum + bool is_empty_connection_type = 4; // TODO: Switch back to enum uint64 max_mempool_count = 5; // this is used to limit the number of nonces that can be stored in the mempool, after which a FIFO mechanism is used to remove the oldest nonces and make space for the new ones bool is_client_only = 6; } From 9d0c61b2c3181cc8afa9fb9fd9630772560d1e23 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 9 Jan 2023 11:04:05 +0000 Subject: [PATCH 133/143] Update p2p/raintree/network.go Co-authored-by: Daniel Olshansky --- p2p/raintree/network.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p2p/raintree/network.go b/p2p/raintree/network.go index d76d018b0..065e663be 100644 --- a/p2p/raintree/network.go +++ b/p2p/raintree/network.go @@ -150,7 +150,7 @@ func (n *rainTreeNetwork) networkSendInternal(data []byte, address cryptoPocket. return err } - // this is because in client mode there's no bus + // A bus is not available In client debug mode bus := n.GetBus() if bus == nil { return nil From d7b9577726707bb30c20275031f7c790ee7ada22 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 9 Jan 2023 11:20:49 +0000 Subject: [PATCH 134/143] refactor(P2P): provider.go --- .../addrbook_provider/debug/{addrbook_provider.go => provider.go} | 0 .../persistence/{addrbook_provider.go => provider.go} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename p2p/providers/addrbook_provider/debug/{addrbook_provider.go => provider.go} (100%) rename p2p/providers/addrbook_provider/persistence/{addrbook_provider.go => provider.go} (100%) diff --git a/p2p/providers/addrbook_provider/debug/addrbook_provider.go b/p2p/providers/addrbook_provider/debug/provider.go similarity index 100% rename from p2p/providers/addrbook_provider/debug/addrbook_provider.go rename to p2p/providers/addrbook_provider/debug/provider.go diff --git a/p2p/providers/addrbook_provider/persistence/addrbook_provider.go b/p2p/providers/addrbook_provider/persistence/provider.go similarity index 100% rename from p2p/providers/addrbook_provider/persistence/addrbook_provider.go rename to p2p/providers/addrbook_provider/persistence/provider.go From 2e1dccbaf3e3d10e47eb6cd4503115a39e93f516 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 9 Jan 2023 11:23:53 +0000 Subject: [PATCH 135/143] refactor(P2P): addrbook_provider cleanup --- p2p/providers/addrbook_provider/debug/provider.go | 13 +++---------- .../addrbook_provider/persistence/provider.go | 6 +----- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/p2p/providers/addrbook_provider/debug/provider.go b/p2p/providers/addrbook_provider/debug/provider.go index c1309d878..72446aadd 100644 --- a/p2p/providers/addrbook_provider/debug/provider.go +++ b/p2p/providers/addrbook_provider/debug/provider.go @@ -41,22 +41,15 @@ func WithActorsByHeight(actorsByHeight map[int64][]*coreTypes.Actor) func(*debug } func (dabp *debugAddrBookProvider) getActorsByHeight(height uint64) []*coreTypes.Actor { - var stakedActors []*coreTypes.Actor - stakedActors, ok := dabp.actorsByHeight[ANY_HEIGHT] - if ok { + if stakedActors, ok := dabp.actorsByHeight[ANY_HEIGHT]; ok { return stakedActors } - stakedActors = dabp.actorsByHeight[int64(height)] - return stakedActors + return nil } func (dabp *debugAddrBookProvider) GetStakedAddrBookAtHeight(height uint64) (typesP2P.AddrBook, error) { stakedActors := dabp.getActorsByHeight(height) - addrBook, err := addrbook_provider.ActorsToAddrBook(dabp, stakedActors) - if err != nil { - return nil, err - } - return addrBook, nil + return addrbook_provider.ActorsToAddrBook(dabp, stakedActors) } func (dabp *debugAddrBookProvider) GetConnFactory() typesP2P.ConnectionFactory { diff --git a/p2p/providers/addrbook_provider/persistence/provider.go b/p2p/providers/addrbook_provider/persistence/provider.go index 2d4f5c1c1..7f12a5671 100644 --- a/p2p/providers/addrbook_provider/persistence/provider.go +++ b/p2p/providers/addrbook_provider/persistence/provider.go @@ -50,11 +50,7 @@ func (pabp *persistenceAddrBookProvider) GetStakedAddrBookAtHeight(height uint64 if err != nil { return nil, err } - addrBook, err := addrbook_provider.ActorsToAddrBook(pabp, stakedActors) - if err != nil { - return nil, err - } - return addrBook, nil + return addrbook_provider.ActorsToAddrBook(pabp, stakedActors) } func (pabp *persistenceAddrBookProvider) GetConnFactory() typesP2P.ConnectionFactory { From c9e1940a5b731b94d16933e858b2ba09226e4da3 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 9 Jan 2023 14:34:04 +0000 Subject: [PATCH 136/143] Update p2p/providers/addrbook_provider/addrbook_provider.go Co-authored-by: Daniel Olshansky --- p2p/providers/addrbook_provider/addrbook_provider.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p2p/providers/addrbook_provider/addrbook_provider.go b/p2p/providers/addrbook_provider/addrbook_provider.go index abdee4611..1820259cd 100644 --- a/p2p/providers/addrbook_provider/addrbook_provider.go +++ b/p2p/providers/addrbook_provider/addrbook_provider.go @@ -34,7 +34,7 @@ func ActorsToAddrBook(abp AddrBookProvider, actors []*coreTypes.Actor) (typesP2P } func ActorToNetworkPeer(abp AddrBookProvider, actor *coreTypes.Actor) (*typesP2P.NetworkPeer, error) { - conn, err := abp.GetConnFactory()(abp.GetP2PConfig(), actor.GetGenericParam()) // service url + conn, err := abp.GetConnFactory()(abp.GetP2PConfig(), actor.GetGenericParam()) // generic param is service url if err != nil { return nil, fmt.Errorf("error resolving addr: %v", err) } From c76a391755f517b59ca214695b7485ea893a7719 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 9 Jan 2023 14:40:14 +0000 Subject: [PATCH 137/143] docs(P2P): marking todo #429 --- p2p/module.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p2p/module.go b/p2p/module.go index c248b939b..2b363e13e 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -41,7 +41,7 @@ func Create(runtimeMgr modules.RuntimeMgr) (modules.Module, error) { return new(p2pModule).Create(runtimeMgr) } -// IMPROVE: need to define a better pattern for dependency injection. Currently we are probably limiting ourselves by having a common constructor `Create(runtimeMgr modules.RuntimeMgr) (modules.Module, error)` for all modules. +// TODO(#429): need to define a better pattern for dependency injection. Currently we are probably limiting ourselves by having a common constructor `Create(bus modules.Bus) (modules.Module, error)` for all modules. func CreateWithProviders(runtimeMgr modules.RuntimeMgr, addrBookProvider providers.AddrBookProvider, currentHeightProvider providers.CurrentHeightProvider) (modules.Module, error) { log.Println("Creating network module") var m *p2pModule From 343dea3ad8a4c9c12f0fa6709d41cbe5baf4bdaf Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 9 Jan 2023 14:41:41 +0000 Subject: [PATCH 138/143] refactor(P2P): current_height_provider.go -> provider.go --- .../debug/{debug_current_height_provider.go => provider.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename p2p/providers/current_height_provider/debug/{debug_current_height_provider.go => provider.go} (100%) diff --git a/p2p/providers/current_height_provider/debug/debug_current_height_provider.go b/p2p/providers/current_height_provider/debug/provider.go similarity index 100% rename from p2p/providers/current_height_provider/debug/debug_current_height_provider.go rename to p2p/providers/current_height_provider/debug/provider.go From 90d331d337bae037c12b2e08f44887ca304ee6ea Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 9 Jan 2023 14:44:57 +0000 Subject: [PATCH 139/143] docs(P2P): cleanup (#429) --- p2p/module.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/p2p/module.go b/p2p/module.go index 2b363e13e..97bd3c1d0 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -159,6 +159,7 @@ func (m *p2pModule) Start() error { return nil } +// CLEANUP(#429): marked for removal since we'll implement a better pattern for dependency injection func getAddrBookProvider(m *p2pModule) providers.AddrBookProvider { var addrbookProvider providers.AddrBookProvider if m.injectedAddrBookProvider == nil { @@ -169,6 +170,7 @@ func getAddrBookProvider(m *p2pModule) providers.AddrBookProvider { return addrbookProvider } +// CLEANUP(#429): marked for removal since we'll implement a better pattern for dependency injection func getCurrentHeightProvider(m *p2pModule) providers.CurrentHeightProvider { var currentHeightProvider providers.CurrentHeightProvider if m.injectedCurrentHeightProvider == nil { From baa3aab3389aa42400aa535d9f664979aa9d426b Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 9 Jan 2023 17:02:52 +0000 Subject: [PATCH 140/143] fix(P2P): fixed (*debugAddrBookProvider) getActorsByHeight --- p2p/providers/addrbook_provider/debug/provider.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/p2p/providers/addrbook_provider/debug/provider.go b/p2p/providers/addrbook_provider/debug/provider.go index 72446aadd..70b010763 100644 --- a/p2p/providers/addrbook_provider/debug/provider.go +++ b/p2p/providers/addrbook_provider/debug/provider.go @@ -1,6 +1,8 @@ package debug import ( + "log" + "github.com/pokt-network/pocket/p2p/providers/addrbook_provider" "github.com/pokt-network/pocket/p2p/transport" typesP2P "github.com/pokt-network/pocket/p2p/types" @@ -40,10 +42,17 @@ func WithActorsByHeight(actorsByHeight map[int64][]*coreTypes.Actor) func(*debug } } +// getActorsByHeight returns the actors that are valid for the given height but in this case func (dabp *debugAddrBookProvider) getActorsByHeight(height uint64) []*coreTypes.Actor { if stakedActors, ok := dabp.actorsByHeight[ANY_HEIGHT]; ok { return stakedActors } + + if stakedActors, ok := dabp.actorsByHeight[int64(height)]; ok { + return stakedActors + } + + log.Fatalf("No actors found for height %d. Make sure you configured the provider via WithActorsByHeight", height) return nil } From 69d060c4b08fa57b4c67312620e208d3a66cd23c Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 9 Jan 2023 17:05:34 +0000 Subject: [PATCH 141/143] =?UTF-8?q?chore(P2P):=20=F0=9F=A7=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- p2p/providers/addrbook_provider/debug/provider.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/p2p/providers/addrbook_provider/debug/provider.go b/p2p/providers/addrbook_provider/debug/provider.go index 70b010763..07e71d8d0 100644 --- a/p2p/providers/addrbook_provider/debug/provider.go +++ b/p2p/providers/addrbook_provider/debug/provider.go @@ -42,7 +42,6 @@ func WithActorsByHeight(actorsByHeight map[int64][]*coreTypes.Actor) func(*debug } } -// getActorsByHeight returns the actors that are valid for the given height but in this case func (dabp *debugAddrBookProvider) getActorsByHeight(height uint64) []*coreTypes.Actor { if stakedActors, ok := dabp.actorsByHeight[ANY_HEIGHT]; ok { return stakedActors @@ -52,7 +51,7 @@ func (dabp *debugAddrBookProvider) getActorsByHeight(height uint64) []*coreTypes return stakedActors } - log.Fatalf("No actors found for height %d. Make sure you configured the provider via WithActorsByHeight", height) + log.Fatalf("No actors found for height %d. Please make sure you configured the provider via WithActorsByHeight", height) return nil } From 01a609b397c73fe72b009dd12f2e6d4f56ed59f0 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 9 Jan 2023 18:57:49 +0000 Subject: [PATCH 142/143] feat(P2P): debug addrbook_provider log on ANY_HEIGHT --- p2p/providers/addrbook_provider/debug/provider.go | 1 + 1 file changed, 1 insertion(+) diff --git a/p2p/providers/addrbook_provider/debug/provider.go b/p2p/providers/addrbook_provider/debug/provider.go index 07e71d8d0..a5afa14f0 100644 --- a/p2p/providers/addrbook_provider/debug/provider.go +++ b/p2p/providers/addrbook_provider/debug/provider.go @@ -44,6 +44,7 @@ func WithActorsByHeight(actorsByHeight map[int64][]*coreTypes.Actor) func(*debug func (dabp *debugAddrBookProvider) getActorsByHeight(height uint64) []*coreTypes.Actor { if stakedActors, ok := dabp.actorsByHeight[ANY_HEIGHT]; ok { + log.Println("[DEBUG] Ignoring height param in debugAddrBookProvider") return stakedActors } From 185b5246ce8dc7a10392a1876ecba692ee6d4767 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 9 Jan 2023 18:59:42 +0000 Subject: [PATCH 143/143] docs(shared): CHANGELOGs --- app/client/cli/doc/CHANGELOG.md | 2 +- build/docs/CHANGELOG.md | 2 +- consensus/doc/CHANGELOG.md | 2 +- p2p/CHANGELOG.md | 2 +- runtime/docs/CHANGELOG.md | 2 +- shared/CHANGELOG.md | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/client/cli/doc/CHANGELOG.md b/app/client/cli/doc/CHANGELOG.md index be2ad6f5f..3773711e4 100644 --- a/app/client/cli/doc/CHANGELOG.md +++ b/app/client/cli/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.4] - 2023-01-04 +## [0.0.0.4] - 2023-01-09 - The `client` (i.e. CLI) no longer instantiates a `P2P` module along with a bus of optional modules. Instead, it instantiates a `client-only` `P2P` module that is disconnected from consensus and persistence. Interactions with the persistence & consensus layer happen via RPC. - Replaced previous implementation, reliant on `ValidatorMap`, with a temporary fetch from genesis. This will be replaced with a lightweight peer discovery mechanism in #416 diff --git a/build/docs/CHANGELOG.md b/build/docs/CHANGELOG.md index 967249b08..7c553c1f6 100644 --- a/build/docs/CHANGELOG.md +++ b/build/docs/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.2] - 2023-01-04 +## [0.0.0.2] - 2023-01-09 - Removed `BaseConfig` from `configs` - Centralized `PersistenceGenesisState` and `ConsensusGenesisState` into `GenesisState` diff --git a/consensus/doc/CHANGELOG.md b/consensus/doc/CHANGELOG.md index 9cd2e7d2f..9426c1e1e 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.16] - 2023-01-04 +## [0.0.0.16] - 2023-01-09 - Added protobuf message definitions for requests related to sharing state sync metadata and blocks - Defined the interface for `StateSyncServerModule`, `StateSyncModule` (moving the old interface to `StateSyncModuleLEGACY` as a reference only) diff --git a/p2p/CHANGELOG.md b/p2p/CHANGELOG.md index 15a56060b..18e07cbf1 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.16] - 2023-01-04 +## [0.0.0.16] - 2023-01-09 - Added missing `Close()` call to `persistenceReadContext` diff --git a/runtime/docs/CHANGELOG.md b/runtime/docs/CHANGELOG.md index fc6a9e0c2..d8dde29d1 100644 --- a/runtime/docs/CHANGELOG.md +++ b/runtime/docs/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.4] - 2023-01-04 +## [0.0.0.4] - 2023-01-09 - Added 'is_client_only' to `P2PConfig` diff --git a/shared/CHANGELOG.md b/shared/CHANGELOG.md index 8765a93f9..a59a3ff01 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.9] - 2023-01-04 +## [0.0.0.9] - 2023-01-09 - Removed `ValidatorMap() ValidatorMap` from `ConsensusModule` interface - Added `GetIsClientOnly()` to `P2PConfig`