-
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
feat!: add gas-related parameters to client config #12723
Conversation
nice! I think adding the log level and log format would be great too |
See my comment in the main issue. I think we should be extra careful about this. If we're gonna go with this approach, we should at least figure out a means to print a warning/diagnostic message saying, "Reading X value from confg.toml" or something similar. |
it turns out that log level/format are parameters for Tendermint (the "server"). the params in |
i see that currently the client prints gas estimation result to stderr (https://github.com/cosmos/cosmos-sdk/blob/v0.46.0/client/tx/tx.go#L78) is it ok with you, if i similarly print a warning message to stderr if any of the gas flag is not specified? i.e. like this: // client/tx/factory.go/NewFactoryCli
gasAdj, err := flagSet.GetFloat64(flags.FlagGasAdjustment)
if err != nil {
gasAdj = clientCtx.GasAdjustment
// print out warning 👇👇👇
_, _ = fmt.Fprintf(os.Stderr, "gas adjustment is not specified! using default value from client.toml: %f\n", gasAdj)
}
var gasSetting client.GasSetting
gasStr, err := flagSet.GetString(flags.FlagGas)
if err != nil {
gasSetting = clientCtx.GasSetting
// print out warning 👇👇👇
_, _ = fmt.Fprintf(os.Stderr, "gas setting is not specified! using default value from client.toml: %f\n", gasSetting)
} else {
gasSetting, _ = client.ParseGasSetting(gasStr)
}
var gasPrices sdk.DecCoins
gasPricesStr, _ := flagSet.GetString(flags.FlagGasPrices)
if err != nil {
gasPrices = clientCtx.GasPrices
// print out warning 👇👇👇
_, _ = fmt.Fprintf(os.Stderr, "gas prices is not specified! using default value from client.toml: %f\n", gasPrices)
} else {
gasPrices, _ = sdk.ParseDecCoins(gasPricesStr)
} |
on a separate topic: this PR breaks a test related to rosetta: https://github.com/cosmos/cosmos-sdk/runs/7514388710 i have very limited knowledge on what rosetta is and how it works. the test is also dockerized making it harder to debug. can i get some help in fixing this? |
@larry0x yes, that sounds reasonable to me! Re; rosetta failure, it seems like it can't read the client.toml -- perhaps it's a bug in the implementation and nothing to do with rosetta? |
turns out the reason is that the test data needs to be updated (contents in this tarball: https://github.com/cosmos/cosmos-sdk/blob/main/contrib/rosetta/rosetta-ci/data.tar.gz) |
|
actually, here's what i know: |
@@ -93,7 +93,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ | |||
|
|||
### CLI Breaking Changes | |||
|
|||
* / | |||
* (client) [#12723](https://github.com/cosmos/cosmos-sdk/pull/12723) The client config now includes default values for several gas-related parameters, which previously needed to be provided by `--gas`, `--gas-adjustment`, and `--gas-prices` flags. |
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.
Curious, why do you consider this CLI breaking and not a feature or improvement?
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.
because users need to add these three lines to their .simapp/config/client.toml
:
gas = "200000"
gas-adjustment = "1"
gas-prices = ""
either by running simd init
again or by manually editing the file, of the tx
command won't work.
this is because when creating the ClientCtx
the client will attempt to read these three params from client.toml
, and if not found it will throw an 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.
Can you add exactly that in the upgrading.md ? Under a Configuration section or something?
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.
Can you add exactly that in the upgrading.md ? Under a Configuration section or something?
done: 7c099f8
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.
Noooo, I don't think this is wise. We should not be requiring any fields in client.toml
whatsoever. I'm strongly opposed to this. client.toml
should be completely opt-in and read only when it exists.
AFAIU, the way client.toml
works is that if a supported field exists in that file, it takes precedence over a default value and a flag value. But in no circumstance should a field ever be required to exist in that file.
In general the order of precedence is:
env var > file > flag > default
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.
Noooo, I don't think this is wise. We should not be requiring any fields in
client.toml
whatsoever. I'm strongly opposed to this.client.toml
should be completely opt-in and read only when it exists.
this is in fact already the case for other fields currently in client.toml
. the chain id for example, if you neither have it configured in client.toml
nor specify it by the CLI flag, then the client won't be able to sign txs:
cosmos-sdk/client/tx/factory.go
Lines 251 to 253 in dc95e33
} else if f.chainID == "" { | |
return nil, fmt.Errorf("chain ID required but not specified") | |
} |
the gas parameters aren't different from this. you need to either configure them in client.toml
, or specify with CLI flags.
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.
@alexanderbez ok here's how i think we can make this work. currently, clientCtx
is created by parsing client.toml
:
// cosmos-sdk/client/config/config.go
func ReadFromClientConfig(ctx client.Context) (client.Context, err) {
// parse gas setting
gasSetting, err := client.ParseGasSetting(conf.Gas)
if err != nil {
return ctx, fmt.Errorf("couldn't get gas setting from client config: %v", err)
}
ctx = ctx.WithGasSetting(gasSetting)
// parse gas adjustment
gasAdj, err := strconv.ParseFloat(conf.GasAdjustment, 64)
if err != nil {
gasAdj, _ = strconv.ParseFloat(gasAdjustment, 64)
}
ctx = ctx.WithGasAdjustment(gasAdj)
// parse gas prices
gasPrices, err := sdk.ParseDecCoins(conf.GasPrices)
if err != nil {
return ctx, fmt.Errorf("couldn't get gas prices from client config: %v", err)
}
ctx = ctx.WithGasPrices(gasPrices)
// parse other client.toml fields, e.g. chain id, rpc node, sign mode, etc.
// ...
return ctx
}
take gas-adjustment
as an example: assume it is NOT present in client.toml
(e.g. if client.toml
was generated by an old version of SimApp). in this case conf.GasAdjustment
will be an empty string ""
, which causes strconv.ParseFloat
to fail.
this is the reason that the three gas parameters are mandatory in client.toml
.
however we can make them optional simply by, instead of returning err
here, we use some default values. this way, users won't need to update their client.toml
files. sounds good?
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.
In general the order of precedence is:
env var > file > flag > default
let me research how other config params are handled. i'll keep this PR as draft for now.
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.
however we can make them optional simply by, instead of returning err here, we use some default values. this way, users won't need to update their client.toml files. sounds good?
Yes, in general this is the idea. I would do whatever we do for all the values we support in client.toml
. I haven't looked at how that file is parsed and handled, but I imagine it only parses when non-empty.
@@ -112,7 +111,7 @@ func AddTxFlagsToCmd(cmd *cobra.Command) { | |||
cmd.Flags().String(FlagGasPrices, "", "Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom)") | |||
cmd.Flags().String(FlagNode, "tcp://localhost:26657", "<host>:<port> to tendermint rpc interface for this chain") | |||
cmd.Flags().Bool(FlagUseLedger, false, "Use a connected Ledger device") | |||
cmd.Flags().Float64(FlagGasAdjustment, DefaultGasAdjustment, "adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored ") | |||
cmd.Flags().Float64(FlagGasAdjustment, 0, "adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored ") |
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.
This should still be 1.0 IMO
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 client will now use the value in client.toml
as the default, instead of what's defined here. setting this to 0
means there is no default for the flag.
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.
in other words, if i have it as 1.0 here, the CLI help text will say (default: 1)
, while in fact the default value is taken from client.toml
and may not be 1
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.
Yes, so again, client.toml
should not be defining any defaults. The file should be completely opt-in. So ""
is treated as an OK value which means it would read the default value from the CLI flags.
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.
utACK
Codecov Report
@@ Coverage Diff @@
## main #12723 +/- ##
==========================================
+ Coverage 56.29% 56.31% +0.02%
==========================================
Files 639 643 +4
Lines 54457 54582 +125
==========================================
+ Hits 30657 30740 +83
- Misses 21356 21386 +30
- Partials 2444 2456 +12
|
@larry0x is there anything you need from us to complete this? |
i need to think about what @alexanderbez suggested previously (about the precedence between env var, config file, and flag) and make adjustments. sorry, have been too busy recently to work on this. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Reviving this. I talked with @larry0x and I will take a stab at continuing this work. I am currently looking into the precedence between env, config and flag to make sure it works as intended. Not sure how to practically continue this particular PR though, if anyone has any ideas (I can make a PR into larry's branch, he can merge it (if he thinks it is good enough :)) which would keep history and everything clean here. Let me know what you want) |
@bjaanes it might be best to start this PR from scratch honestly and it should be pretty straight forward. We just need to add these fields to the client configuration and read them (this structure already exists). Then it's simply a matter of setting precedence, which we already already do I believe (e.g. chain-id, which you can use as an example for what to do for this PR). |
gonna close this for now, we can add this to our next sprint as something to work on |
Description
Closes: #12722
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change