-
Notifications
You must be signed in to change notification settings - Fork 33
[CLI] Consistent config/flag parsing & common helpers #891
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4badf3a
chore: simplify debug message broadcasting
bryanchriswhite eac7695
refactor: common CLI helpers
bryanchriswhite 440b59a
chore: ensure flag and config parsing
bryanchriswhite fcfa837
chore: add `GetBusFromCmd()` CLI helper
bryanchriswhite 04dc0aa
chore: consistent debug CLI identity
bryanchriswhite d8b6296
squash: merge refactor/cli with main
h5law 9ecc9e5
chore: address review comments
h5law 1cbc249
Merge branch 'main' into refactor/cli
h5law ffbc539
fix merge error
h5law 434f253
Update app/client/cli/debug.go
Olshansk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,56 @@ | ||
| package helpers | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/pokt-network/pocket/logger" | ||
| "github.com/pokt-network/pocket/p2p/providers/peerstore_provider" | ||
| "github.com/pokt-network/pocket/p2p/types" | ||
| "github.com/pokt-network/pocket/runtime" | ||
| "github.com/pokt-network/pocket/shared/messaging" | ||
| "github.com/pokt-network/pocket/shared/modules" | ||
| ) | ||
|
|
||
| var ( | ||
| // TECHDEBT: Accept reading this from `Datadir` and/or as a flag. | ||
| genesisPath = runtime.GetEnv("GENESIS_PATH", "build/config/genesis.json") | ||
| // TECHDEBT: Accept reading this from `Datadir` and/or as a flag. | ||
| var genesisPath = runtime.GetEnv("GENESIS_PATH", "build/config/genesis.json") | ||
|
|
||
| // P2PMod is initialized in order to broadcast a message to the local network | ||
| P2PMod modules.P2PModule | ||
| ) | ||
| // FetchPeerstore retrieves the providers from the CLI context and uses them to retrieve the address book for the current height | ||
| func FetchPeerstore(cmd *cobra.Command) (types.Peerstore, error) { | ||
| bus, err := GetBusFromCmd(cmd) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| // TECHDEBT(#811): use `bus.GetPeerstoreProvider()` after peerstore provider | ||
| // is retrievable as a proper submodule | ||
| pstoreProvider, err := bus.GetModulesRegistry().GetModule(peerstore_provider.PeerstoreProviderSubmoduleName) | ||
| if err != nil { | ||
| return nil, errors.New("retrieving peerstore provider") | ||
| } | ||
| currentHeightProvider := bus.GetCurrentHeightProvider() | ||
| height := currentHeightProvider.CurrentHeight() | ||
| pstore, err := pstoreProvider.(peerstore_provider.PeerstoreProvider).GetStakedPeerstoreAtHeight(height) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("retrieving peerstore at height %d", height) | ||
| } | ||
| // Inform the client's main P2P that a the blockchain is at a new height so it can, if needed, update its view of the validator set | ||
| if err := sendConsensusNewHeightEventToP2PModule(height, bus); err != nil { | ||
| return nil, errors.New("sending consensus new height event") | ||
| } | ||
| return pstore, nil | ||
| } | ||
|
|
||
| // sendConsensusNewHeightEventToP2PModule mimicks the consensus module sending a ConsensusNewHeightEvent to the p2p module | ||
| // This is necessary because the debug client is not a validator and has no consensus module but it has to update the peerstore | ||
| // depending on the changes in the validator set. | ||
| // TODO(#613): Make the debug client mimic a full node. | ||
| // TECHDEBT: This may no longer be required (https://github.com/pokt-network/pocket/pull/891/files#r1262710098) | ||
| func sendConsensusNewHeightEventToP2PModule(height uint64, bus modules.Bus) error { | ||
h5law marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| newHeightEvent, err := messaging.PackMessage(&messaging.ConsensusNewHeightEvent{Height: height}) | ||
| if err != nil { | ||
| logger.Global.Fatal().Err(err).Msg("Failed to pack consensus new height event") | ||
| } | ||
| return bus.GetP2PModule().HandleEvent(newHeightEvent.Content) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.