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

Problem: packet get relayed even estimated gas is higher than max gas #1302

Merged
merged 5 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* [\#1221](https://github.com/cosmos/relayer/pull/1221) Update cometbft to v0.37.2 and ibc-go to v7.2.0.
* [\#1226](https://github.com/cosmos/relayer/pull/1226) Avoid invalid Bech32 prefix error in parallel tests when sdk Config get overwritten by each other in single process.
* [\#1231](https://github.com/cosmos/relayer/pull/1231) Reduce get bech32 prefix when get signer.
* [\#](https://github.com/cosmos/relayer/pull/) Avoid packet get relayed when estimated gas is higher than max gas.
mmsqe marked this conversation as resolved.
Show resolved Hide resolved

## v0.9.3

Expand Down
13 changes: 3 additions & 10 deletions relayer/chains/cosmos/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"math"
"math/big"
"math/rand"
"regexp"
Expand Down Expand Up @@ -267,8 +266,6 @@ func (cc *CosmosProvider) SendMsgsWith(ctx context.Context, msgs []sdk.Msg, memo
if err != nil {
return nil, err
}

adjusted = uint64(float64(adjusted) * cc.PCfg.GasAdjustment)
jtieri marked this conversation as resolved.
Show resolved Hide resolved
}

//Cannot feegrant your own TX
Expand Down Expand Up @@ -1683,14 +1680,10 @@ func (cc *CosmosProvider) AdjustEstimatedGas(gasUsed uint64) (uint64, error) {
if gasUsed == 0 {
return gasUsed, nil
}
gas := cc.PCfg.GasAdjustment * float64(gasUsed)
if math.IsInf(gas, 1) {
return 0, fmt.Errorf("infinite gas used")
}
// Bound the gas estimate by the max_gas option
if cc.PCfg.MaxGasAmount > 0 {
gas = math.Min(gas, float64(cc.PCfg.MaxGasAmount))
if cc.PCfg.MaxGasAmount > 0 && gasUsed > cc.PCfg.MaxGasAmount {
return 0, fmt.Errorf("estimated gas %d is higher than max gas %d", gasUsed, cc.PCfg.MaxGasAmount)
}
gas := cc.PCfg.GasAdjustment * float64(gasUsed)
jtieri marked this conversation as resolved.
Show resolved Hide resolved
return uint64(gas), nil
}

Expand Down
17 changes: 8 additions & 9 deletions relayer/chains/cosmos/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cosmos

import (
"fmt"
"math"
"testing"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -52,14 +51,6 @@ func TestCosmosProvider_AdjustEstimatedGas(t *testing.T) {
expectedGas: 75000,
expectedErr: nil,
},
{
name: "gas used is infinite",
gasUsed: 10000,
gasAdjustment: math.Inf(1),
maxGasAmount: 0,
expectedGas: 0,
expectedErr: fmt.Errorf("infinite gas used"),
},
{
name: "gas used is non-zero with zero max gas amount as default",
gasUsed: 50000,
Expand All @@ -68,6 +59,14 @@ func TestCosmosProvider_AdjustEstimatedGas(t *testing.T) {
expectedGas: 75000,
expectedErr: nil,
},
{
name: "estimated gas is higher than max gas",
gasUsed: 50000,
gasAdjustment: 1.5,
maxGasAmount: 70000,
expectedGas: 75000,
expectedErr: fmt.Errorf("estimated gas 75000 is higher than max gas 70000"),
},
}

for _, tc := range testCases {
Expand Down
Loading