Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[P2P] [Tooling] Peer discovery peer connections subcommand #801

Open
wants to merge 2 commits into
base: feat/peer-discovery-list
Choose a base branch
from

Conversation

bryanchriswhite
Copy link
Contributor

@bryanchriswhite bryanchriswhite commented Jun 2, 2023

@Reviewer

This PR may be more digestible / reviewable on a commit-by-commit basis. Commits are organized logically and any given line is only modified in a single commit, with few exceptions*.

*(In the interest of preserving the git-time-continuum 👮🚨, this applies in batches of commits between comments or reviews by humans, only once "in review")


Description

Adds the following subcommands:

Print open peer connections

Usage:
  p1 peer connections [flags]

Flags:
  -h, --help   help for connections

Global Flags:
  -a, --all                     operations apply to both staked & unstaked router peerstores (default)
      --config string           Path to config
      --data_dir string         Path to store pocket related data (keybase etc.) (default "/home/bwhite/.pocket")
  -l, --local                   operations apply to the local (CLI binary's) P2P module instead of being broadcast
      --non_interactive         if true skips the interactive prompts wherever possible (useful for scripting & automation)
      --remote_cli_url string   takes a remote endpoint in the form of <protocol>://<host>:<port> (uses RPC Port) (default "http://localhost:50832")
  -s, --staked                  operations only apply to staked router peerstore (i.e. raintree)
  -u, --unstaked                operations only apply to unstaked router peerstore (i.e. gossipsub)
      --verbose                 Show verbose output

Issue

Related:

Dependencies:

Type of change

Please mark the relevant option(s):

  • New feature, functionality or library
  • Bug fix
  • Code health or cleanup
  • Major breaking change
  • Documentation
  • Other

List of changes

  • Added peer connections subcommand
  • Added P2PModule#GetConnections() interface method & implementation

Testing

  • make develop_test; if any code changes were made
  • make test_e2e on k8s LocalNet; if any code changes were made
  • e2e-devnet-test passes tests on DevNet; if any code was changed
  • Docker Compose LocalNet; if any major functionality was changed or introduced
  • k8s LocalNet; if any infrastructure or configuration changes were made

Required Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added, or updated, godoc format comments on touched members (see: tip.golang.org/doc/comment)
  • I have tested my changes using the available tooling
  • 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 diagrams in the corresponding README(s)
  • I have added, or updated, documentation and mermaid.js diagrams in shared/docs/* if I updated shared/*README(s)

@bryanchriswhite bryanchriswhite added the p2p P2P specific changes label Jun 2, 2023
@bryanchriswhite bryanchriswhite self-assigned this Jun 2, 2023
@reviewpad reviewpad bot added the large Pull request is large label Jun 2, 2023
@codecov
Copy link

codecov bot commented Jun 2, 2023

Codecov Report

❗ No coverage uploaded for pull request base (re/refactor/cli@a18c047). Click here to learn what that means.
Patch has no changes to coverable lines.

❗ Current head 10e00d0 differs from pull request most recent head ca2e971. Consider uploading reports for the commit ca2e971 to get more accurate results

Additional details and impacted files
@@                Coverage Diff                 @@
##             re/refactor/cli     #801   +/-   ##
==================================================
  Coverage                   ?   29.96%           
==================================================
  Files                      ?      108           
  Lines                      ?     8829           
  Branches                   ?        0           
==================================================
  Hits                       ?     2646           
  Misses                     ?     5873           
  Partials                   ?      310           

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@bryanchriswhite bryanchriswhite force-pushed the feat/peer-discovery-debug-cli branch from 3784b14 to 1c23be5 Compare June 5, 2023 08:04
@reviewpad reviewpad bot added medium Pull request is medium and removed large Pull request is large labels Jun 5, 2023
@bryanchriswhite bryanchriswhite force-pushed the feat/peer-discovery-debug-cli branch from ce1b1bd to 80aec49 Compare June 5, 2023 08:12
@bryanchriswhite bryanchriswhite changed the base branch from feat/kad-peer-discovery to refactor/peerstore-provider June 5, 2023 08:14
@bryanchriswhite bryanchriswhite added the do not merge Prevent merging even with sufficient approvals label Jun 5, 2023
@bryanchriswhite bryanchriswhite force-pushed the refactor/peerstore-provider branch from 9209358 to 968be5f Compare June 5, 2023 11:01
@bryanchriswhite bryanchriswhite force-pushed the feat/peer-discovery-debug-cli branch from 0cdc40d to c78193d Compare June 5, 2023 11:18
@bryanchriswhite bryanchriswhite changed the base branch from refactor/peerstore-provider to re/refactor/peerstore-provider June 5, 2023 11:23
@bryanchriswhite bryanchriswhite force-pushed the feat/peer-discovery-debug-cli branch from c6e8447 to 39a2f3e Compare June 6, 2023 07:21
@reviewpad reviewpad bot added large Pull request is large and removed medium Pull request is medium labels Jun 6, 2023
@bryanchriswhite bryanchriswhite force-pushed the feat/peer-discovery-debug-cli branch from 592eee8 to e56bc6e Compare June 6, 2023 08:56
@bryanchriswhite bryanchriswhite changed the base branch from re/refactor/peerstore-provider to re/refactor/cli June 6, 2023 13:51
@bryanchriswhite bryanchriswhite force-pushed the feat/peer-discovery-debug-cli branch from 6ba979e to 4716bf7 Compare June 6, 2023 13:51
@reviewpad reviewpad bot added medium Pull request is medium and removed large Pull request is large labels Jun 6, 2023
@bryanchriswhite bryanchriswhite linked an issue Jun 6, 2023 that may be closed by this pull request
10 tasks
@bryanchriswhite bryanchriswhite force-pushed the feat/peer-discovery-debug-cli branch from f498196 to 10e00d0 Compare June 6, 2023 14:30
@reviewpad reviewpad bot added large Pull request is large and removed medium Pull request is medium labels Jun 6, 2023
@bryanchriswhite bryanchriswhite added the tooling tooling to support development, testing et al label Jun 6, 2023
@bryanchriswhite bryanchriswhite changed the title [P2P] Peer discovery CLI commands [P2P] [Tooling] Peer discovery CLI commands Jun 6, 2023
@bryanchriswhite bryanchriswhite changed the base branch from re/refactor/cli to chore/introduce-submodule July 6, 2023 10:07
@bryanchriswhite bryanchriswhite added push-image Build and push a container image on non-main builds e2e-devnet-test Runs E2E tests on devnet labels Jul 13, 2023
@bryanchriswhite bryanchriswhite force-pushed the feat/peer-discovery-debug-cli branch from 8213d38 to a4b12df Compare July 13, 2023 15:09
@reviewpad reviewpad bot added large Pull request is large and removed small Pull request is small labels Jul 13, 2023
@bryanchriswhite bryanchriswhite force-pushed the feat/peer-discovery-list branch from 0d9d930 to 380e7d5 Compare July 13, 2023 15:10
@reviewpad reviewpad bot added medium Pull request is medium and removed large Pull request is large labels Jul 13, 2023
@bryanchriswhite bryanchriswhite force-pushed the feat/peer-discovery-list branch from ed9ed31 to 1bbad38 Compare July 13, 2023 15:26
@reviewpad reviewpad bot added large Pull request is large and removed medium Pull request is medium labels Jul 13, 2023
@bryanchriswhite bryanchriswhite force-pushed the feat/peer-discovery-debug-cli branch from b64c8f4 to 59449b0 Compare July 13, 2023 15:37
@reviewpad reviewpad bot added medium Pull request is medium and removed large Pull request is large labels Jul 13, 2023
@bryanchriswhite bryanchriswhite force-pushed the feat/peer-discovery-debug-cli branch 2 times, most recently from ea50366 to 2bd789c Compare July 13, 2023 15:43
@bryanchriswhite bryanchriswhite marked this pull request as ready for review July 13, 2023 15:43
@bryanchriswhite bryanchriswhite requested a review from Olshansk July 13, 2023 15:43
@bryanchriswhite bryanchriswhite marked this pull request as draft July 13, 2023 15:46
@bryanchriswhite bryanchriswhite force-pushed the feat/peer-discovery-debug-cli branch from 2bd789c to 4df2da8 Compare July 13, 2023 15:52
@bryanchriswhite bryanchriswhite marked this pull request as ready for review July 13, 2023 15:52
@@ -10,7 +10,8 @@ import (

func (m *p2pModule) handleDebugMessage(msg *messaging.DebugMessage) error {
switch msg.Action {
case messaging.DebugMessageAction_DEBUG_P2P_PEER_LIST:
case messaging.DebugMessageAction_DEBUG_P2P_PEER_LIST,
messaging.DebugMessageAction_DEBUG_P2P_PEER_CONNECTIONS:
if !m.cfg.EnablePeerDiscoveryDebugRpc {
Copy link
Member

Choose a reason for hiding this comment

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

I feel like we can skip the first switch statement and just return (with a debug log or error) if if !m.cfg.EnablePeerDiscoveryDebugRpc {

@@ -100,6 +100,7 @@ config:
use_rain_tree: true
is_empty_connection_type: false
private_key: "" # @ignored This value is needed but ignored - use privateKeySecretKeyRef instead
# TODO: I think this has been renamed to `max_nonces`
Copy link
Member

Choose a reason for hiding this comment

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

Cna you please update it everywhere else as well?

Screenshot 2023-07-13 at 4 14 38 PM
Screenshot 2023-07-13 at 4 14 31 PM
Screenshot 2023-07-13 at 4 14 23 PM

)

var (
connectionsCmd = &cobra.Command{
Copy link
Member

Choose a reason for hiding this comment

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

Everywhere else we have a function that returns a new instance of cobra.Command.

I think we should either:

  1. Stay consisstent
  2. Stay consistent + add a TODO to change the others
  3. Change all of them

@@ -0,0 +1,149 @@
package debug
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a debug build tag?

return nil
}

func PrintConnectionsTable(conns []libp2pNetwork.Conn) error {
Copy link
Member

Choose a reason for hiding this comment

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

does PrintConnectionsTable need to be publically exposed given that we use PrintPeerConnections in the cli?

func peerConnsRowConsumerFactory(conns []libp2pNetwork.Conn) utils.RowConsumer {
return func(provideRow utils.RowProvider) error {
for _, conn := range conns {
if err := provideRow(
Copy link
Member

Choose a reason for hiding this comment

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

what happens if we don't return an error when provideRow errors? Is a partial list not an option?

Comment on lines +16 to +17
Use: "connections",
Short: "Print open peer connections",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Use: "connections",
Short: "Print open peer connections",
Use: "Connections",
Short: "Print open peer connections",
Long: "Prints ..." // list out printConnectionsHeader
Aliases: []string{"conns"},

}

switch {
case stakedFlag:
Copy link
Member

Choose a reason for hiding this comment

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

OPTIONAL: The way I would've done this is by having a smaller private helper function like below that returns the router typ:

func foo() routerType {
	switch
	case stakedFlag && !unstakedFlag && !allFlag {
		return debug.StakeRouterType
	}
	case unstakedFlag && !stakedFlag && !allFlag {
		return debug.UnstakedRouterType
	}
	case stakedFlag || unstakedFlag {
		return ErrRouterType
	}
	// even if `allFlag` is false, we still want to print all connections
	default:
		return debug.AllRouterTypes
	}
}

Wdyt?


// TECHDEBT(#810, #811): will need to wait for DHT bootstrapping to complete before
// p2p broadcast can be used with to reach unstaked actors.
// CONSIDERATION: add the peer commands to the interactive CLI as the P2P module
Copy link
Member

Choose a reason for hiding this comment

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

So why don't we do this?

return fmt.Errorf("creating anypb from debug message: %w", err)
}

if localFlag {
Copy link
Member

Choose a reason for hiding this comment

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

So if this is false we don't print anything?

I don't fully understand its use. Is it like a "verbose" flag?

Copy link
Contributor

Choose a reason for hiding this comment

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

This localFlag determines whether we print locally ie to the terminal that ran the command or on the node itself AFAIK. With -l we will see the output in our terminal, otherwise it will be logged by the node

@Olshansk
Copy link
Member

@bryanchriswhite Can you pick this up when you're back?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge Prevent merging even with sufficient approvals e2e-devnet-test Runs E2E tests on devnet medium Pull request is medium p2p P2P specific changes push-image Build and push a container image on non-main builds tooling tooling to support development, testing et al waiting-for-review
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

[P2P] Peer discovery debug CLI sub-commands
3 participants