diff --git a/README.md b/README.md index 67c107b0..7ffbeb8d 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,8 @@ Chain rules for checking the free oracle transactions are: So, if you don't want to pay for gas, TX must be below `MaxMsgGasUsage`. If you set too much gas (which is what is happening when when you set `gas_adjustment` to 2), then the tx will allocate 2x gas, and hence will go above the free quota, so you would need to attach fee to pay for that gas. The easiest is to just set constant gas. We recommend 10k below the `MaxMsgGasUsage`. +Note that either `gas_adjustment` or `gas` can be used. Both can not be set. + ## Configuration ### `telemetry` diff --git a/cmd/price-feeder.go b/cmd/price-feeder.go index ff07b9e8..9a48fc6c 100644 --- a/cmd/price-feeder.go +++ b/cmd/price-feeder.go @@ -162,6 +162,7 @@ func priceFeederCmdHandler(cmd *cobra.Command, args []string) error { cfg.Account.Validator, cfg.RPC.GRPCEndpoint, cfg.GasAdjustment, + cfg.Gas, ) if err != nil { return err diff --git a/config/config.go b/config/config.go index f4ff66c0..8ee91f48 100644 --- a/config/config.go +++ b/config/config.go @@ -46,7 +46,8 @@ type ( Keyring Keyring `mapstructure:"keyring" validate:"required,gt=0,dive,required"` RPC RPC `mapstructure:"rpc" validate:"required,gt=0,dive,required"` Telemetry telemetry.Config `mapstructure:"telemetry"` - GasAdjustment float64 `mapstructure:"gas_adjustment" validate:"required"` + GasAdjustment float64 `mapstructure:"gas_adjustment"` + Gas uint64 `mapstructure:"gas"` ProviderTimeout string `mapstructure:"provider_timeout"` ProviderMinOverride bool `mapstructure:"provider_min_override"` ProviderEndpoints []provider.Endpoint `mapstructure:"provider_endpoints" validate:"dive"` @@ -141,10 +142,12 @@ func (c Config) Validate() (err error) { if err = c.validateCurrencyPairs(); err != nil { return err } - if err = c.validateDeviations(); err != nil { return err } + if err = c.validateGas(); err != nil { + return err + } validate.RegisterStructValidation(telemetryValidation, telemetry.Config{}) validate.RegisterStructValidation(endpointValidation, provider.Endpoint{}) @@ -165,6 +168,16 @@ func (c Config) validateDeviations() error { return nil } +func (c Config) validateGas() error { + if c.Gas <= 0 && c.GasAdjustment <= 0 { + return fmt.Errorf("gas or gas adjustment must be set") + } + if c.GasAdjustment > 0 && c.Gas > 0 { + return fmt.Errorf("gas and gas adjustment may not both be set") + } + return nil +} + func (c Config) validateCurrencyPairs() error { OUTER: for _, cp := range c.CurrencyPairs { diff --git a/oracle/client/client.go b/oracle/client/client.go index f855b92c..e4de2203 100644 --- a/oracle/client/client.go +++ b/oracle/client/client.go @@ -42,6 +42,7 @@ type ( Encoding testutil.TestEncodingConfig GasPrices string GasAdjustment float64 + Gas uint64 GRPCEndpoint string KeyringPassphrase string ChainHeight *ChainHeight @@ -66,6 +67,7 @@ func NewOracleClient( validatorAddrString string, grpcEndpoint string, gasAdjustment float64, + gas uint64, ) (OracleClient, error) { oracleAddr, err := sdk.AccAddressFromBech32(oracleAddrString) if err != nil { @@ -86,6 +88,7 @@ func NewOracleClient( ValidatorAddrString: validatorAddrString, Encoding: ojoparams.MakeEncodingConfig(), GasAdjustment: gasAdjustment, + Gas: gas, GRPCEndpoint: grpcEndpoint, } @@ -268,15 +271,24 @@ func (oc OracleClient) CreateTxFactory() (tx.Factory, error) { return tx.Factory{}, err } - txFactory := tx.Factory{}. + if oc.GasAdjustment > 0 { + return tx.Factory{}. + WithAccountRetriever(clientCtx.AccountRetriever). + WithChainID(oc.ChainID). + WithTxConfig(clientCtx.TxConfig). + WithGasAdjustment(oc.GasAdjustment). + WithGasPrices(oc.GasPrices). + WithKeybase(clientCtx.Keyring). + WithSignMode(signing.SignMode_SIGN_MODE_DIRECT). + WithSimulateAndExecute(true), nil + } + return tx.Factory{}. WithAccountRetriever(clientCtx.AccountRetriever). WithChainID(oc.ChainID). WithTxConfig(clientCtx.TxConfig). - WithGasAdjustment(oc.GasAdjustment). + WithGas(oc.Gas). WithGasPrices(oc.GasPrices). WithKeybase(clientCtx.Keyring). WithSignMode(signing.SignMode_SIGN_MODE_DIRECT). - WithSimulateAndExecute(true) - - return txFactory, nil + WithSimulateAndExecute(true), nil } diff --git a/oracle/client/tx.go b/oracle/client/tx.go index 43c5f591..c42b04b6 100644 --- a/oracle/client/tx.go +++ b/oracle/client/tx.go @@ -19,12 +19,14 @@ func BroadcastTx(clientCtx client.Context, txf tx.Factory, msgs ...sdk.Msg) (*sd return nil, err } - _, adjusted, err := tx.CalculateGas(clientCtx, txf, msgs...) - if err != nil { - return nil, err - } + if txf.GasAdjustment() > 0 { + _, adjusted, err := tx.CalculateGas(clientCtx, txf, msgs...) + if err != nil { + return nil, err + } - txf = txf.WithGas(adjusted) + txf = txf.WithGas(adjusted) + } unsignedTx, err := txf.BuildUnsignedTx(msgs...) if err != nil {