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

[Client] [Tooling] refactor: CLI #806

Merged
merged 71 commits into from
Jun 13, 2023
Merged

[Client] [Tooling] refactor: CLI #806

merged 71 commits into from
Jun 13, 2023

Conversation

bryanchriswhite
Copy link
Contributor

@bryanchriswhite bryanchriswhite commented Jun 6, 2023

Description

Summary generated by Reviewpad on 13 Jun 23 12:53 UTC

This pull request includes various updates across the codebase, including changes to CLI flags, import statements, and default values. It also involves refactoring code to use shared helper functions, removing unused code, and improving error handling. Some variables have been renamed to be more descriptive. The specific changes include modifications to files such as validator.go, cluster-manager.yaml, cli-client.yaml, utils.go, and runtime_defaults.go. For example, the RPC_HOST variable has been replaced with POCKET_REMOTE_CLI_URL. A new helper package has been added, and a new flags package contains several CLI flags. Code has also been updated to use flags.RemoteCLIURL instead of remoteCLIURL. Some constants have been renamed to include Hostname, and there are updates to endpoint hostnames for some validators.

Issue

Dependants:

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

  • Exported rootCmd to support cross-package usage (i.e. subcommands w/ own pkgs)
  • Refactored common CLI code
    • Moved & refactored PersistentPreRunE() helper
    • Moved & exported busCLICtxKey
    • Exported GetValueFromCLIContext() and SetValueInCLIContext()
    • Moved setupAndStartP2PModule
    • Moved setupCurrentHeightProvider
    • Moved setupPeerstoreProvider
  • Refactored CLI flags to own package for cross-package use
  • Replaced RPC_HOST with POCKET_REMOTE_CLI_URL where appropriate
  • Added remote-cli-url flag to cluster manager & refactor
  • Added support for overriding of remote-cli-url flag with env var
  • Append "Hostname" to validator endpoint hostname constants
  • Promoted string literal to RandomValidatorEndpointK8SHostname constant
  • Improved e2e tests error messaging
  • Simplify e2e debug command calls
  • Improve error handling in client CLI

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 tooling tooling to support development, testing et al do not merge Prevent merging even with sufficient approvals client work needed to interface with the node (rpc, cli, etc..) labels Jun 6, 2023
@bryanchriswhite bryanchriswhite self-assigned this Jun 6, 2023
@reviewpad reviewpad bot added the large Pull request is large label Jun 6, 2023
@codecov
Copy link

codecov bot commented Jun 6, 2023

Codecov Report

Patch coverage: 18.05% and project coverage change: +0.15 🎉

Comparison is base (9cb0ee9) 31.37% compared to head (413589f) 31.52%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #806      +/-   ##
==========================================
+ Coverage   31.37%   31.52%   +0.15%     
==========================================
  Files         107      107              
  Lines        9085     9034      -51     
==========================================
- Hits         2850     2848       -2     
+ Misses       5895     5846      -49     
  Partials      340      340              
Impacted Files Coverage Δ
app/client/cli/account.go 39.06% <0.00%> (ø)
app/client/cli/actor.go 30.32% <0.00%> (ø)
app/client/cli/consensus.go 34.37% <0.00%> (ø)
app/client/cli/gov.go 36.11% <0.00%> (ø)
app/client/cli/keys.go 29.11% <0.00%> (ø)
app/client/cli/query.go 12.35% <0.00%> (ø)
app/client/cli/system.go 42.30% <0.00%> (ø)
app/client/cli/utils.go 35.77% <0.00%> (+0.80%) ⬆️
app/client/cli/cmd.go 30.00% <40.00%> (-8.10%) ⬇️
app/client/cli/debug.go 11.37% <70.00%> (+1.46%) ⬆️

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

@bryanchriswhite bryanchriswhite marked this pull request as ready for review June 6, 2023 15:14
@bryanchriswhite bryanchriswhite force-pushed the refactor/peerstore-provider branch from 0749b80 to 4589585 Compare June 12, 2023 12:37
@bryanchriswhite bryanchriswhite force-pushed the refactor/peerstore-provider branch from 4589585 to 22ff0fd Compare June 12, 2023 12:55
* refactor/peerstore-provider:
  chore: update changelogs
  fix: p2p test
  chore: fix consensus test
  chore: persistence peerstore provider includes all staked actors
  refactor: rename `NewPersistencePeerstoreProvider()` to `Create()`
  chore: combine `NewRPCPeerstoreProvider()` & `Create()`
  chore: add TECHDEBT comments
@bryanchriswhite bryanchriswhite linked an issue Jun 12, 2023 that may be closed by this pull request
3 tasks
Copy link
Member

@Olshansk Olshansk left a comment

Choose a reason for hiding this comment

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

@bryanchriswhite Aside from the failing E2E tests, this LGTM and I don't have much feedback to provide.

I know you still have to resolve some E2E failures but doing a "soft approval" in the meantime so we can get this over the finish line.

@@ -43,6 +48,9 @@ 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
Copy link
Member

Choose a reason for hiding this comment

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

Should this be something we do for every flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would probably be a good idea, for consistency across the CLI UX, to do that, yea.

@@ -1,13 +1,24 @@
package flags

var (
// RemoveCLIURL is the URL of the remote RPC node which the CLI will interact with.
// Formatted as <protocol>://<host>:<port> (uses RPC Port).
// (see: --help the root command for more info).
Copy link
Member

Choose a reason for hiding this comment

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

NIT: I think adding (see: --help the root command for more info). once above var ( would be sufficient.

Copy link
Contributor Author

@bryanchriswhite bryanchriswhite Jun 13, 2023

Choose a reason for hiding this comment

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

Fair enough, I was imagining browsing the godoc. Perhaps a package-level comment would be more appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Adding this to my list of TODOs in a downstream PR to avoid another round with CI)

e2e/tests/validator.go Outdated Show resolved Hide resolved
e2e/tests/validator.go Outdated Show resolved Hide resolved
"takes a remote endpoint in the form of <protocol>://<host>:<port> (uses RPC Port)",
)

// ensure that the env var can override the flag
Copy link
Member

Choose a reason for hiding this comment

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

I know we've had a lot of issues with viper and flag binding in the past.

I don't have much feedback on this as I'd have to dive in really deep, but have to be honest that I have lost context on where/how this variable binding is working.

Anything I should focus on or provide feedback in particular? If not, LGTM

Copy link
Contributor Author

@bryanchriswhite bryanchriswhite Jun 13, 2023

Choose a reason for hiding this comment

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

What I think I've learned regarding bindings: cobra takes the default values and handles updating bound flag variables/pointers based on any actual flag values which are present during invocation (i.e. --remote_cli_url someValue). Separately from that, viper can track a key of the same name, the value of which (independent of the flag vars/ptrs) will default to its respective config value (if present/applicable) but can be overridden by a respective env var and/or the flag value.

TLDR; the viper/cobra API dynamic is such that:

  1. Viper key/values are separate (in memory) from viper flags.
  2. Viper key/values can be overridden by cobra flags but not the other way around.
  3. For consistency we should either:
  • Ensure we're updating flag vars (i.e. bound to a cobra flag) with their respective viper overrides
  • Stop using flag vars (e.g. do #PersistentFlags.String(...) instead of #PersistentFlags.StringVar(&flagVar, ...) and treat viper as the single source of truth (e.g. viper.GetString(...))

(cherry picked from commit 5254967bbe067e30c02fb63d40bc263f3d6def22)
* refactor/peerstore-provider:
  chore: fix nit
  chore: update changelogs
  revert: `readCtx.GetAllStakedActors()`
bryanchriswhite added a commit that referenced this pull request Jun 13, 2023
## Description

1. Simplify `PeerstoreProvider` interface
2. Extend it to support retrieval of the unstaked actor peerstore
3. Implement the extended interface in `persistencePeerstoreProvider`

### Before

```mermaid
classDiagram 

class InterruptableModule {
    <<interface>>
    Start() error
    Stop() error
}
class IntegratableModule {
    <<interface>>
    +SetBus(bus Bus)
    +GetBus() Bus
}
class InitializableModule {
    <<interface>>
    +GetModuleName() string
    +Create(bus Bus, opts ...Option) (Module, error)
}
class Module {
    <<interface>>
}

Module --|> InitializableModule
Module --|> IntegratableModule
Module --|> InterruptableModule


class PeerstoreProvider {
    <<interface>>
    +GetStakedPeerstoreAtHeight(height int) (Peerstore, error)
    +GetP2PConfig() *P2PConfig
}

class persistencePeerstoreProvider

class rpcPeerstoreProvider

persistencePeerstoreProvider --|> PeerstoreProvider

rpcPeerstoreProvider --|> PeerstoreProvider
PeerstoreProvider --|> Module
```

### After

```mermaid
classDiagram 

class IntegratableModule {
    <<interface>>
    +GetBus() Bus
    +SetBus(bus Bus)
}

class PeerstoreProvider {
    <<interface>>
    +GetStakedPeerstoreAtHeight(height int) (Peerstore, error)
    +GetUnstakedPeerstore() (Peerstore, error)
}

class persistencePeerstoreProvider
class rpcPeerstoreProvider
class p2pModule

class unstakedPeerstoreProvider {
    <<interface>>
    +GetUnstakedPeerstore() (Peerstore, error)
}

persistencePeerstoreProvider --|> PeerstoreProvider
persistencePeerstoreProvider --> p2pModule : from Bus
rpcPeerstoreProvider --> p2pModule : from Bus
p2pModule --|> unstakedPeerstoreProvider

rpcPeerstoreProvider --|> PeerstoreProvider
rpcPeerstoreProvider --|> Module
PeerstoreProvider --|> IntegratableModule

class Module {
    <<interface>>
}

Module --|> InitializableModule
Module --|> IntegratableModule
Module --|> InterruptableModule
```

## Issue

Realted:
- #810

Dependants:
- #505 
- #806

## 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 <!-- add details here if it a different type of change -->

## List of changes

- Replaced embedded `modules.Module` with simpler
`modules.IntegratableModule` in `PeerstoreProvider` interface
- Removed unused `PeerstoreProvider#GetP2PConfig()` method
- Added `PeerstoreProvider#GetUnstakedPeerstore()` method
- Added `p2pPeerstoreProvider` implementation of `PeerstoreProvider`
interface
- Added `Factory` generic type 

## Testing

- [ ] `make develop_test`; if any code changes were made
- [x] `make test_e2e` on [k8s
LocalNet](https://github.com/pokt-network/pocket/blob/main/build/localnet/README.md);
if any code changes were made
- [ ] `e2e-devnet-test` passes tests on
[DevNet](https://pocketnetwork.notion.site/How-to-DevNet-ff1598f27efe44c09f34e2aa0051f0dd);
if any code was changed
- [x] [Docker Compose
LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md);
if any major functionality was changed or introduced
- [x] [k8s
LocalNet](https://github.com/pokt-network/pocket/blob/main/build/localnet/README.md);
if any infrastructure or configuration changes were made

<!-- 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 added, or updated, [`godoc` format
comments](https://go.dev/blog/godoc) on touched members (see:
[tip.golang.org/doc/comment](https://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](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)
* pokt/main:
  [P2P] refactor: peerstore provider (part 1) (#804)
(cherry picked from commit 9d608ec)
@bryanchriswhite bryanchriswhite changed the base branch from refactor/peerstore-provider to main June 13, 2023 10:35
@bryanchriswhite bryanchriswhite removed do not merge Prevent merging even with sufficient approvals waiting-for-review labels Jun 13, 2023
@bryanchriswhite bryanchriswhite merged commit 12f9f49 into main Jun 13, 2023
@bryanchriswhite

This comment was marked as outdated.

@bryanchriswhite bryanchriswhite deleted the refactor/cli branch July 6, 2023 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client work needed to interface with the node (rpc, cli, etc..) e2e-devnet-test Runs E2E tests on devnet large Pull request is large tooling tooling to support development, testing et al
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Tooling] make localnet_shell doesn't work out of the box
4 participants