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

feat: static gas #331

Merged
merged 6 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions cmd/price-feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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{})
Expand All @@ -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 {
Expand Down
22 changes: 17 additions & 5 deletions oracle/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type (
Encoding testutil.TestEncodingConfig
GasPrices string
GasAdjustment float64
Gas uint64
GRPCEndpoint string
KeyringPassphrase string
ChainHeight *ChainHeight
Expand All @@ -66,6 +67,7 @@ func NewOracleClient(
validatorAddrString string,
grpcEndpoint string,
gasAdjustment float64,
gas uint64,
) (OracleClient, error) {
oracleAddr, err := sdk.AccAddressFromBech32(oracleAddrString)
if err != nil {
Expand All @@ -86,6 +88,7 @@ func NewOracleClient(
ValidatorAddrString: validatorAddrString,
Encoding: ojoparams.MakeEncodingConfig(),
GasAdjustment: gasAdjustment,
Gas: gas,
GRPCEndpoint: grpcEndpoint,
}

Expand Down Expand Up @@ -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
}
12 changes: 7 additions & 5 deletions oracle/client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading