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

PRT-377 gas adjustments #268

Merged
merged 1 commit into from
Jan 29, 2023
Merged
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
23 changes: 1 addition & 22 deletions relayer/sentry/tx.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package sentry

import (
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -12,7 +10,6 @@ import (
const (
defaultGasPrice = "0.000000001ulava"
defaultGasAdjustment = 1.5
maximumGasAllowed = 5000000
)

func SimulateAndBroadCastTx(clientCtx client.Context, txf tx.Factory, msg sdk.Msg) error {
Expand All @@ -32,10 +29,6 @@ func SimulateAndBroadCastTx(clientCtx client.Context, txf tx.Factory, msg sdk.Ms
return err
}

if err := validateGas(gasUsed); err != nil {
return err
}

txf = txf.WithGas(gasUsed)

err = tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
Expand Down Expand Up @@ -72,16 +65,6 @@ func prepareFactory(clientCtx client.Context, txf tx.Factory) (tx.Factory, error
return txf, nil
}

func validateGas(gas uint64) error {
if gas > maximumGasAllowed {
return utils.LavaFormatError("SimulateAndBroadCastTx - Maximum gas allowed Reached", nil, &map[string]string{
"maximumGasAllowed": strconv.FormatUint(maximumGasAllowed, 10),
"gasUsed": strconv.FormatUint(gas, 10),
})
}
return nil
}

func CheckProfitabilityAndBroadCastTx(clientCtx client.Context, txf tx.Factory, msg sdk.Msg) error {
txf = txf.WithGasPrices(defaultGasPrice)
txf = txf.WithGasAdjustment(defaultGasAdjustment)
Expand Down Expand Up @@ -116,18 +99,14 @@ func CheckProfitabilityAndBroadCastTx(clientCtx client.Context, txf tx.Factory,
}
}

if err := validateGas(gasUsed); err != nil {
return err
}

txf = txf.WithGas(gasUsed)

gasFee := txf.GasPrices()[0]
gasFee.Amount = gasFee.Amount.MulInt64(int64(gasUsed))
lavaRewardDec := sdk.NewDecCoinFromCoin(lavaReward)

if gasFee.IsGTE(lavaRewardDec) {
utils.LavaFormatError("lava_relay_payment claim is not profitable", nil, &map[string]string{"gasFee": gasFee.String(), "lavareward:": lavaRewardDec.String(), "msg": msg.String()})
return utils.LavaFormatError("lava_relay_payment claim is not profitable", nil, &map[string]string{"gasFee": gasFee.String(), "lavareward:": lavaRewardDec.String(), "msg": msg.String()})
}

err = tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
Expand Down