Skip to content

Commit ed83458

Browse files
[Libp2p] Plug it in (part 5) (#546)
## Description This is another (last, probably) in a series of PRs split out from #500. Here we finally enable support for use of the new libp2p module (and dependent packages) by considering the config changes made in #535 in the node and debug CLI. ## Issue #347 ## Type of change Please mark the relevant option(s): - [x] New feature, functionality or library - [ ] Bug fix - [ ] Code health or cleanup - [ ] Major breaking change - [ ] Documentation - [ ] Other <!-- add details here if it a different type of change --> ## List of changes - Support libp2p module in node - Support libp2p module in debug CLI ## Testing - [x] `make develop_test` - [x] [LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md) w/ all of the steps outlined in the `README` <!-- REMOVE this comment block after following the instructions If you added additional tests or infrastructure, describe it here. Bonus points for images and videos or gifs. --> ## Required Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have tested my changes using the available tooling - [x] I have updated the corresponding CHANGELOG ### If Applicable Checklist - [ ] I have updated the corresponding README(s); local and/or global - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have added, or updated, [mermaid.js](https://mermaid-js.github.io) diagrams in the corresponding README(s) - [ ] I have added, or updated, documentation and [mermaid.js](https://mermaid-js.github.io) diagrams in `shared/docs/*` if I updated `shared/*`README(s)
1 parent c80e630 commit ed83458

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

app/client/cli/debug.go

+24-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import (
55
"os"
66

77
"github.com/manifoldco/promptui"
8+
"github.com/spf13/cobra"
9+
"google.golang.org/protobuf/types/known/anypb"
10+
11+
"github.com/pokt-network/pocket/libp2p"
812
"github.com/pokt-network/pocket/logger"
913
"github.com/pokt-network/pocket/p2p"
1014
"github.com/pokt-network/pocket/p2p/providers/addrbook_provider"
@@ -16,8 +20,6 @@ import (
1620
"github.com/pokt-network/pocket/runtime/defaults"
1721
"github.com/pokt-network/pocket/shared/messaging"
1822
"github.com/pokt-network/pocket/shared/modules"
19-
"github.com/spf13/cobra"
20-
"google.golang.org/protobuf/types/known/anypb"
2123
)
2224

2325
// TECHDEBT: Lowercase variables / constants that do not need to be exported.
@@ -101,11 +103,13 @@ func NewDebugCommand() *cobra.Command {
101103
modulesRegistry.RegisterModule(currentHeightProvider)
102104

103105
setValueInCLIContext(cmd, busCLICtxKey, bus)
104-
p2pM, err := p2p.Create(bus)
106+
107+
// TECHDEBT: simplify after P2P module consolidation.
108+
var err error
109+
p2pMod, err = getP2PModule(runtimeMgr)
105110
if err != nil {
106111
logger.Global.Fatal().Err(err).Msg("Failed to create p2p module")
107112
}
108-
p2pMod = p2pM.(modules.P2PModule)
109113

110114
if err := p2pMod.Start(); err != nil {
111115
logger.Global.Fatal().Err(err).Msg("Failed to start p2p module")
@@ -271,3 +275,19 @@ func fetchAddressBook(cmd *cobra.Command) (types.AddrBook, error) {
271275
}
272276
return addrBook, err
273277
}
278+
279+
func getP2PModule(runtimeMgr *runtime.Manager) (p2pModule modules.P2PModule, err error) {
280+
bus := runtimeMgr.GetBus()
281+
282+
var mod modules.Module
283+
if runtimeMgr.GetConfig().UseLibP2P {
284+
mod, err = libp2p.Create(bus)
285+
} else {
286+
mod, err = p2p.Create(bus)
287+
}
288+
if err != nil {
289+
return nil, err
290+
}
291+
292+
return mod.(modules.P2PModule), nil
293+
}

app/client/doc/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.0.0.20] - 2023-03-03
11+
12+
- Support libp2p module in debug CLI
13+
1014
## [0.0.0.19] - 2023-02-28
1115

1216
- Renamed the package names for some basic helpers

shared/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.0.0.38] - 2023-03-03
11+
12+
- Support libp2p module in node
13+
1014
## [0.0.0.37] - 2023-03-01
1115

1216
- add pokt --> libp2p crypto helpers

shared/node.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package shared
22

33
import (
44
"github.com/pokt-network/pocket/consensus"
5+
"github.com/pokt-network/pocket/libp2p"
56
"github.com/pokt-network/pocket/logger"
67
"github.com/pokt-network/pocket/p2p"
78
"github.com/pokt-network/pocket/persistence"
@@ -33,6 +34,13 @@ func CreateNode(bus modules.Bus, options ...modules.ModuleOption) (modules.Modul
3334
}
3435

3536
func (m *Node) Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) {
37+
// TECHDEBT: simplify after P2P module consolidation.
38+
useLibP2P := bus.GetRuntimeMgr().GetConfig().UseLibP2P
39+
p2pCreate := p2p.Create
40+
if useLibP2P {
41+
p2pCreate = libp2p.Create
42+
}
43+
3644
for _, mod := range []func(modules.Bus, ...modules.ModuleOption) (modules.Module, error){
3745
state_machine.Create,
3846
persistence.Create,
@@ -41,7 +49,7 @@ func (m *Node) Create(bus modules.Bus, options ...modules.ModuleOption) (modules
4149
telemetry.Create,
4250
logger.Create,
4351
rpc.Create,
44-
p2p.Create,
52+
p2pCreate,
4553
} {
4654
if _, err := mod(bus); err != nil {
4755
return nil, err

0 commit comments

Comments
 (0)