Skip to content

Commit

Permalink
feat: static gas (#331)
Browse files Browse the repository at this point in the history
(cherry picked from commit c8537cc)

# Conflicts:
#	README.md
  • Loading branch information
adamewozniak authored and mergify[bot] committed Jan 17, 2024
1 parent fa73366 commit 7789522
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 12 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ The files in the provider-config folder define what exchange rates to fetch and
$ price-feeder /path/to/price_feeder_config.toml
```

<<<<<<< HEAD
=======
Chain rules for checking the free oracle transactions are:

- must be only prevote or vote
- gas is limited to [`MaxMsgGasUsage`](https://github.com/ojo-network/ojo/blob/main/ante/fee.go#L13) constant.

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.

>>>>>>> c8537cc (feat: static gas (#331))
## 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 @@ -150,6 +150,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 @@ -43,6 +43,7 @@ type (
Encoding testutil.TestEncodingConfig
GasPrices string
GasAdjustment float64
Gas uint64
GRPCEndpoint string
KeyringPassphrase string
ChainHeight *ChainHeight
Expand All @@ -67,6 +68,7 @@ func NewOracleClient(
validatorAddrString string,
grpcEndpoint string,
gasAdjustment float64,
gas uint64,
) (OracleClient, error) {
oracleAddr, err := sdk.AccAddressFromBech32(oracleAddrString)
if err != nil {
Expand All @@ -87,6 +89,7 @@ func NewOracleClient(
ValidatorAddrString: validatorAddrString,
Encoding: umeeapp.MakeEncodingConfig(),
GasAdjustment: gasAdjustment,
Gas: gas,
GRPCEndpoint: grpcEndpoint,
}

Expand Down Expand Up @@ -269,15 +272,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

0 comments on commit 7789522

Please sign in to comment.