-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add client config #8820
Add client config #8820
Conversation
0071d76
to
aecceec
Compare
client/config/config.go
Outdated
@@ -92,220 +48,104 @@ func Cmd(defaultCLIHome string) *cobra.Command { | |||
|
|||
cmd.Flags().String(flags.FlagHome, defaultCLIHome, | |||
"set client's home directory for configuration") | |||
cmd.Flags().Bool(flagGet, false, | |||
"print configuration value or its default if unset") | |||
// cmd.Flags().Bool(flagGet, false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we dont need a flagGet flag here, do we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's correct! as per Alessio's proposal #8820 (comment)
client/config/config.go
Outdated
if err != nil { | ||
return fmt.Errorf("Unable to get client config %v", err) | ||
fmt.Fprintf(os.Stderr, "Unable to get client config: %v\n", err) | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alessio Following your suggestion, I print an error here to os.Stderr. I am unable to add os.Exit(1) cause the runConfigCmd is supposed to return an error.
af6f2a1
to
8dbc688
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client/config/config.go
Outdated
@@ -92,220 +48,104 @@ func Cmd(defaultCLIHome string) *cobra.Command { | |||
|
|||
cmd.Flags().String(flags.FlagHome, defaultCLIHome, | |||
"set client's home directory for configuration") | |||
cmd.Flags().Bool(flagGet, false, | |||
"print configuration value or its default if unset") | |||
// cmd.Flags().Bool(flagGet, false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's correct! as per Alessio's proposal #8820 (comment)
To improve code readability I would like to move all cmd logic to new cmd.go file . In config.go I leave only logic associated with client config. Does it sound good? |
I tried to test my code . I removed everything from ~/.simapp and ran this shell script. Unfortunately, |
On Fri, Mar 12, 2021 at 6:33 PM Andrei Ivasko ***@***.***> wrote:
I tried to test my code . I removed everything from ~/.simapp and ran this shell script. Unfortunately, client.toml has not been created. Is it proper way to test it or there is another way to do it(e.g. integration testing)?
The old `config` command used to create the `toml` file upon execution
if the file had not yet been created.
…--
Alessio Treglia
VicePresident of Engineering at Tendermint
Cosmonaut at Cosmos
@tendermint_team · @cosmos · We're hiring!
|
|
f9f22da
to
f4f6dde
Compare
@alessio I have question regarding interceptConfigs. I use viper field rootViper from serverCtx here . This is my code associated with my client config inserted into interceptConfigs. Does it make sense to decouple server config and client config logic? Should I use different Viper fields for server and client config? |
@alessio @AmauryM mentioned here:
I would like to start working on Step 2 (second PR) . I need more context regarding it. which dependency on singleton should be removed? |
flags > env vars > config file, this is typically the standard. |
Example: cosmos-sdk/x/auth/client/cli/tx_multisign.go Line 356 in 5f71e93
|
Mmm... I think flags should override env vars, and both override config files. Is that correct? |
Priority rule flags > env vars > config file I have performed some manual tests. I hope I have performed them right. Otherwise, please advice. This is my initial client config
Conclusion: Test does not pass, it should dial tcp://localhost:26658 cause env variable has higher priority than config
Conclusion : test pass cause flag has the highest priority
Conclusion: test pass cause flag has the highest priority
Conclusion: test does not pass cause it should dial the node from config file tcp://localhost:26500 |
rootCmd := &cobra.Command{ | ||
Use: "simd", | ||
Short: "simulation app", | ||
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have also tried to put clicfg.UpdateClientContextFromClientConfig(initClientCtx) inside PersistentPreRunE. In this case I can handle an error occured by reading from client.toml file. I have got the same test results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put inside PersistentPreRunE
then.
The docs say that this function:
PersistentPreRun: children of this command will inherit and execute.
So I guess it's what we want.
It seems, Vyper does not read env variables from linux terminal. It has AutomaticEnv() function which can read env variables from the config file only. Alternatively, os.GetEnv(varname) can be used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The manual tests you performed looks good to me.
I think with the UpdateClientContextFromClientConfig
function, we're getting close! Thanks @cyberbono3
Inside that function, imo we also need to add a logic saying:
- make sure the config path & file exist
- if the config file doesn't exist, create a new one and populate it with default values
I can have a look at the viper reading from terminal env vars issue.
@@ -0,0 +1,189 @@ | |||
# This is a TOML config file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong committed file?
rootCmd := &cobra.Command{ | ||
Use: "simd", | ||
Short: "simulation app", | ||
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put inside PersistentPreRunE
then.
The docs say that this function:
PersistentPreRun: children of this command will inherit and execute.
So I guess it's what we want.
@@ -323,7 +334,7 @@ func GetFromFields(kr keyring.Keyring, from string, genOnly bool) (sdk.AccAddres | |||
return info.GetAddress(), info.GetName(), info.GetType(), nil | |||
} | |||
|
|||
func newKeyringFromFlags(ctx Context, backend string) (keyring.Keyring, error) { | |||
func NewKeyringFromFlags(ctx Context, backend string) (keyring.Keyring, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe NewKeyringFromString
or NewKeyringFromBackend
are both more correct names, and can be used in the toml file logic without sounding confusing.
f49f07a
to
8125d5e
Compare
Manual testing 2 0.
TODO |
client/config/cmd.go
Outdated
if err := ensureConfigPath(configPath); err != nil { | ||
return fmt.Errorf("couldn't make client config: %v", err) | ||
} | ||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we dont need ensureConfigPath anymore, cause ~/.simapp/config directory will exist in any way due to ReadFromClientConfig logic
cd test/config there is no client.toml configuration file | ||
*/ | ||
|
||
func (ctx Context) WithHomeFlag(cmd *cobra.Command) Context { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a bug by executing this command ./build/simd init andrei --home ./test
. There is no client.toml
created inside ./test/config. WithHomeFlag fixes this bug.
@@ -56,11 +55,12 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { | |||
Short: "simulation app", | |||
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { | |||
|
|||
initClientCtx = initClientCtx.WithHomeFlag(cmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I move WithHomeFlag(cmd) inside config.ReadFromClientConfig to make our code a little bit cleaner?
super seeded by #8953 |
Description
This is draft PR that implements Step1 from #8529
Step 1 Creating a new $NODE_DIR/config/client.toml file to hold all client-side configuration (e.g. keyring-backend, node, chain-id etc...).
Questions:
@AmauryM Could you leave your feedback, please?
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
docs/
) or specification (x/<module>/spec/
)godoc
comments.Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorerCodecov Report
in the comment section below once CI passes