Skip to content

Commit

Permalink
Applying diff
Browse files Browse the repository at this point in the history
  • Loading branch information
Olshansk committed Jul 13, 2023
1 parent 021d90f commit 158f8fb
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ rebuild_client_start: docker_check ## Rebuild and run a client daemon which is o

.PHONY: client_connect
client_connect: docker_check ## Connect to the running client debugging daemon
docker exec -it client /bin/bash -c "POCKET_P2P_IS_CLIENT_ONLY=true go run -tags=debug app/client/*.go debug --remote_cli_url=http://validator1:50832"
docker exec -it client /bin/bash -c "POCKET_REMOTE_CLI_URL=http://validator1:50832 go run -tags=debug app/client/*.go debug_ui"

.PHONY: build_and_watch
build_and_watch: ## Continous build Pocket's main entrypoint as files change
Expand Down Expand Up @@ -526,7 +526,7 @@ localnet_client_debug: ## Opens a `client debug` cli to interact with blockchain

.PHONY: localnet_shell
localnet_shell: ## Opens a shell in the pod that has the `client` cli available. The binary updates automatically whenever the code changes (i.e. hot reloads).
kubectl exec -it deploy/dev-cli-client --container pocket -- /bin/bash
kubectl exec -it deploy/dev-cli-client --container pocket -- /bin/bash -c "export POCKET_REMOTE_CLI_URL=http://pocket-validators:50832; bash"

.PHONY: localnet_logs_validators
localnet_logs_validators: ## Outputs logs from all validators
Expand Down
1 change: 0 additions & 1 deletion app/client/cli/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ var rootCmd = &cobra.Command{
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
// by this time, the config path should be set
cfg = configs.ParseConfig(flags.ConfigPath)

// set final `remote_cli_url` value; order of precedence: flag > env var > config > default
flags.RemoteCLIURL = viper.GetString("remote_cli_url")
return nil
Expand Down
68 changes: 60 additions & 8 deletions app/client/cli/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,20 @@ var (
)

func init() {
dbg := NewDebugCommand()
dbg.AddCommand(NewDebugSubCommands()...)
dbgUI := newDebugUICommand()
dbgUI.AddCommand(newDebugUISubCommands()...)
rootCmd.AddCommand(dbgUI)

dbg := newDebugCommand()
dbg.AddCommand(debugCommands()...)
rootCmd.AddCommand(dbg)
}

// NewDebugSubCommands builds out the list of debug subcommands by matching the
// newDebugUISubCommands builds out the list of debug subcommands by matching the
// handleSelect dispatch to the appropriate command.
// * To add a debug subcommand, you must add it to the `items` array and then
// write a function handler to match for it in `handleSelect`.
func NewDebugSubCommands() []*cobra.Command {
func newDebugUISubCommands() []*cobra.Command {
commands := make([]*cobra.Command, len(items))
for idx, promptItem := range items {
commands[idx] = &cobra.Command{
Expand All @@ -66,17 +70,65 @@ func NewDebugSubCommands() []*cobra.Command {
return commands
}

// NewDebugCommand returns the cobra CLI for the Debug command.
func NewDebugCommand() *cobra.Command {
// newDebugUICommand returns the cobra CLI for the Debug UI interface.
func newDebugUICommand() *cobra.Command {
return &cobra.Command{
Use: "debug",
Short: "Debug utility for rapid development",
Use: "debug_ui",
Short: "Debug selection ui for rapid development",
Args: cobra.MaximumNArgs(0),
PersistentPreRunE: helpers.P2PDependenciesPreRunE,
RunE: runDebug,
}
}

// newDebugCommand returns the cobra CLI for the Debug command.
func newDebugCommand() *cobra.Command {
return &cobra.Command{
Use: "debug",
Short: "Debug utility for rapid development",
Args: cobra.MaximumNArgs(1),
PersistentPreRunE: helpers.P2PDependenciesPreRunE,
}
}

func debugCommands() []*cobra.Command {
cmds := []*cobra.Command{
{
Use: "TriggerView",
Short: "Trigger the next view in consensus",
Long: "Sends a message to all visible nodes on the network to start the next view (height/step/round) in consensus",
Aliases: []string{"triggerView"},
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
m := &messaging.DebugMessage{
Action: messaging.DebugMessageAction_DEBUG_CONSENSUS_TRIGGER_NEXT_VIEW,
Type: messaging.DebugMessageRoutingType_DEBUG_MESSAGE_TYPE_BROADCAST,
Message: nil,
}
broadcastDebugMessage(cmd, m)
return nil
},
},
{
Use: "TogglePacemakerMode",
Short: "Toggle the pacemaker",
Long: "Toggle the consensus pacemaker either on or off so the chain progresses on its own or loses liveness",
Aliases: []string{"togglePaceMaker"},
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
m := &messaging.DebugMessage{
Action: messaging.DebugMessageAction_DEBUG_CONSENSUS_TOGGLE_PACE_MAKER_MODE,
Type: messaging.DebugMessageRoutingType_DEBUG_MESSAGE_TYPE_BROADCAST,
Message: nil,
}
broadcastDebugMessage(cmd, m)
return nil
},
},
}
return cmds
}

func runDebug(cmd *cobra.Command, args []string) (err error) {
for {
if selection, err := promptGetInput(); err == nil {
Expand Down
7 changes: 7 additions & 0 deletions app/client/cli/helpers/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package helpers

import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/pokt-network/pocket/app/client/cli/flags"
"github.com/pokt-network/pocket/logger"
"github.com/pokt-network/pocket/p2p"
rpcCHP "github.com/pokt-network/pocket/p2p/providers/current_height_provider/rpc"
rpcPSP "github.com/pokt-network/pocket/p2p/providers/peerstore_provider/rpc"
"github.com/pokt-network/pocket/runtime"
"github.com/pokt-network/pocket/runtime/configs"
"github.com/pokt-network/pocket/shared/modules"
)

Expand All @@ -18,6 +20,11 @@ func P2PDependenciesPreRunE(cmd *cobra.Command, _ []string) error {
// TECHDEBT: this is to keep backwards compatibility with localnet
flags.ConfigPath = runtime.GetEnv("CONFIG_PATH", "build/config/config.validator1.json")

// by this time, the config path should be set
configs.ParseConfig(flags.ConfigPath)
// set final `remote_cli_url` value; order of precedence: flag > env var > config > default
flags.RemoteCLIURL = viper.GetString("remote_cli_url")

runtimeMgr := runtime.NewManagerFromFiles(
flags.ConfigPath, genesisPath,
runtime.WithClientDebugMode(),
Expand Down
2 changes: 2 additions & 0 deletions build/deployments/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ services:
security_opt:
- "seccomp:unconfined"
environment:
# BUG: The `SERVICER1_SERVICER_ENABLED` env var is not currnetly visible in the `command` above and needs to be investigate
- SERVICER1_SERVICER_ENABLED=true
- POCKET_RPC_USE_CORS=true
# Uncomment to enable DLV debugging
# - DEBUG_PORT=7085
Expand Down
5 changes: 1 addition & 4 deletions build/localnet/manifests/cli-client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ spec:
memory: "512Mi"
cpu: "4"
env:
- name: POCKET_P2P_IS_CLIENT_ONLY
value: "true"
- name: CONFIG_PATH
value: "/var/pocket/config/config.json"
- name: GENESIS_PATH
Expand Down Expand Up @@ -76,8 +74,7 @@ spec:
# Any host that is visible and connected to the cluster can be arbitrarily selected as the RPC host
- name: POCKET_REMOTE_CLI_URL
value: http://full-node-001-pocket:50832
# TECHDEBT(#678): debug client requires hostname to participate
# in P2P networking.
# TECHDEBT(#678): debug client requires hostname to participate in P2P networking.
- name: POCKET_P2P_HOSTNAME
value: "127.0.0.1"
volumeMounts:
Expand Down
11 changes: 6 additions & 5 deletions e2e/tests/steps_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
var e2eLogger = pocketLogger.Global.CreateLoggerForModule("e2e")

const (
// defines the host & port scheme that LocalNet uses for naming validators.
// e.g. validator-001 thru validator-999
// Each actor is represented e.g. validator-001 thru validator-999
// Defines the host & port scheme that LocalNet uses for naming actors.
validatorServiceURLTmpl = "validator-%s-pocket:%d"
// validatorA maps to suffix ID 001 and is also used by the cluster-manager
// though it has no special permissions.
Expand All @@ -43,6 +43,7 @@ type rootSuite struct {
// clientset is the kubernetes API we acquire from the user's $HOME/.kube/config
clientset *kubernetes.Clientset
// validator holds command results between runs and reports errors to the test suite
// TECHDEBT: Rename `validator` to something more appropriate
validator *validatorPod
// validatorA maps to suffix ID 001 of the kube pod that we use as our control agent
}
Expand Down Expand Up @@ -148,9 +149,7 @@ func (s *rootSuite) unstakeValidator() {
}

// getPrivateKey generates a new keypair from the private hex key that we get from the clientset
func (s *rootSuite) getPrivateKey(
validatorId string,
) cryptoPocket.PrivateKey {
func (s *rootSuite) getPrivateKey(validatorId string) cryptoPocket.PrivateKey {
privHexString := s.validatorKeys[validatorId]
privateKey, err := cryptoPocket.NewPrivateKey(privHexString)
require.NoErrorf(s, err, "failed to extract privkey")
Expand All @@ -161,6 +160,8 @@ func (s *rootSuite) getPrivateKey(
// getClientset uses the default path `$HOME/.kube/config` to build a kubeconfig
// and then connects to that cluster and returns a *Clientset or an error
func getClientset(t gocuke.TestingT) (*kubernetes.Clientset, error) {
t.Helper()

userHomeDir, err := os.UserHomeDir()
if err != nil {
return nil, fmt.Errorf("failed to get home dir: %w", err)
Expand Down
26 changes: 25 additions & 1 deletion p2p/background/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package background
import (
"context"
"fmt"
"time"

dht "github.com/libp2p/go-libp2p-kad-dht"
pubsub "github.com/libp2p/go-libp2p-pubsub"
Expand Down Expand Up @@ -32,6 +33,12 @@ var (
_ backgroundRouterFactory = &backgroundRouter{}
)

// TECHDEBT: Make these values configurable
const (
connectMaxRetries = 5
connectRetryTimeout = time.Second * 2
)

type backgroundRouterFactory = modules.FactoryWithConfig[typesP2P.Router, *config.BackgroundConfig]

// backgroundRouter implements `typesP2P.Router` for use with all P2P participants.
Expand Down Expand Up @@ -342,13 +349,30 @@ func (rtr *backgroundRouter) bootstrap(ctx context.Context) error {
return nil
}

if err := rtr.host.Connect(ctx, libp2pAddrInfo); err != nil {
if err := rtr.connectWithRetry(ctx, libp2pAddrInfo); err != nil {
return fmt.Errorf("connecting to peer: %w", err)
}
}
return nil
}

// connectWithRetry attempts to connect to the given peer, retrying up to connectMaxRetries times
// and waiting connectRetryTimeout between each attempt.
func (rtr *backgroundRouter) connectWithRetry(ctx context.Context, libp2pAddrInfo libp2pPeer.AddrInfo) error {
var err error
for i := 0; i < connectMaxRetries; i++ {
err = rtr.host.Connect(ctx, libp2pAddrInfo)
if err == nil {
return nil
}

fmt.Printf("Failed to connect (attempt %d), retrying in %v...\n", i+1, connectRetryTimeout)
time.Sleep(connectRetryTimeout)
}

return fmt.Errorf("failed to connect after %d attempts, last error: %w", 5, err)
}

// topicValidator is used in conjunction with libp2p-pubsub's notion of "topic
// validaton". It is used for arbitrary and concurrent pre-propagation validation
// of messages.
Expand Down
1 change: 1 addition & 0 deletions persistence/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func (p *persistenceModule) TransactionExists(transactionHash string) (bool, err
}
return false, err
}

return true, nil
}

Expand Down

0 comments on commit 158f8fb

Please sign in to comment.