Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Comment on lines 7 to +11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not actionable: 💯 I like this. I guess we should start doing this across the board and separate external/internal imports. Maybe we should create an issue to tackle it in one scoop also to create team awareness since it's gonna be discussed at least once in standup at some point.

Probably too boring to be outsourced to the community 🤔 and however low priority, something to do to kill boredom with more... boredom 😆. Wdyt?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have summoned the community in #185

"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