Skip to content

Commit

Permalink
[Libp2p] Plug it in (part 5) (#546)
Browse files Browse the repository at this point in the history
## 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)
  • Loading branch information
bryanchriswhite authored Mar 3, 2023
1 parent c80e630 commit ed83458
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
28 changes: 24 additions & 4 deletions app/client/cli/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import (
"os"

"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"google.golang.org/protobuf/types/known/anypb"

"github.com/pokt-network/pocket/libp2p"
"github.com/pokt-network/pocket/logger"
"github.com/pokt-network/pocket/p2p"
"github.com/pokt-network/pocket/p2p/providers/addrbook_provider"
Expand All @@ -16,8 +20,6 @@ import (
"github.com/pokt-network/pocket/runtime/defaults"
"github.com/pokt-network/pocket/shared/messaging"
"github.com/pokt-network/pocket/shared/modules"
"github.com/spf13/cobra"
"google.golang.org/protobuf/types/known/anypb"
)

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

setValueInCLIContext(cmd, busCLICtxKey, bus)
p2pM, err := p2p.Create(bus)

// TECHDEBT: simplify after P2P module consolidation.
var err error
p2pMod, err = getP2PModule(runtimeMgr)
if err != nil {
logger.Global.Fatal().Err(err).Msg("Failed to create p2p module")
}
p2pMod = p2pM.(modules.P2PModule)

if err := p2pMod.Start(); err != nil {
logger.Global.Fatal().Err(err).Msg("Failed to start p2p module")
Expand Down Expand Up @@ -271,3 +275,19 @@ func fetchAddressBook(cmd *cobra.Command) (types.AddrBook, error) {
}
return addrBook, err
}

func getP2PModule(runtimeMgr *runtime.Manager) (p2pModule modules.P2PModule, err error) {
bus := runtimeMgr.GetBus()

var mod modules.Module
if runtimeMgr.GetConfig().UseLibP2P {
mod, err = libp2p.Create(bus)
} else {
mod, err = p2p.Create(bus)
}
if err != nil {
return nil, err
}

return mod.(modules.P2PModule), nil
}
4 changes: 4 additions & 0 deletions app/client/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.0.20] - 2023-03-03

- Support libp2p module in debug CLI

## [0.0.0.19] - 2023-02-28

- Renamed the package names for some basic helpers
Expand Down
4 changes: 4 additions & 0 deletions shared/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.0.38] - 2023-03-03

- Support libp2p module in node

## [0.0.0.37] - 2023-03-01

- add pokt --> libp2p crypto helpers
Expand Down
10 changes: 9 additions & 1 deletion shared/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package shared

import (
"github.com/pokt-network/pocket/consensus"
"github.com/pokt-network/pocket/libp2p"
"github.com/pokt-network/pocket/logger"
"github.com/pokt-network/pocket/p2p"
"github.com/pokt-network/pocket/persistence"
Expand Down Expand Up @@ -33,6 +34,13 @@ func CreateNode(bus modules.Bus, options ...modules.ModuleOption) (modules.Modul
}

func (m *Node) Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) {
// TECHDEBT: simplify after P2P module consolidation.
useLibP2P := bus.GetRuntimeMgr().GetConfig().UseLibP2P
p2pCreate := p2p.Create
if useLibP2P {
p2pCreate = libp2p.Create
}

for _, mod := range []func(modules.Bus, ...modules.ModuleOption) (modules.Module, error){
state_machine.Create,
persistence.Create,
Expand All @@ -41,7 +49,7 @@ func (m *Node) Create(bus modules.Bus, options ...modules.ModuleOption) (modules
telemetry.Create,
logger.Create,
rpc.Create,
p2p.Create,
p2pCreate,
} {
if _, err := mod(bus); err != nil {
return nil, err
Expand Down

0 comments on commit ed83458

Please sign in to comment.