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

Consensus min gas fee of .0025 uosmo #4244

Merged
merged 25 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
dfe43ca
Refactor tests a bit
ValarDragon Feb 7, 2023
38946b7
Add consensus min gas fee
ValarDragon Feb 7, 2023
c676d48
Fix tests
ValarDragon Feb 7, 2023
923b45e
Delete more crud
ValarDragon Feb 7, 2023
7a82e14
Cleanup more duplicate test cases
ValarDragon Feb 7, 2023
125d59d
flip isCheckTx sign
ValarDragon Feb 7, 2023
13679ce
One more test needed
ValarDragon Feb 7, 2023
295aebb
Run invalid fee denom test across both check & deliver
ValarDragon Feb 7, 2023
a374529
Remove extra line
ValarDragon Feb 7, 2023
8c7f27d
Merge branch 'main' into dev/consensus_min_gas_fee
ValarDragon Feb 7, 2023
e42e675
Add hack to get around txfee problem in ibctesting
ValarDragon Feb 8, 2023
f40b0c7
Handle genesis
ValarDragon Feb 8, 2023
b278a48
Minor code cleanup
ValarDragon Feb 8, 2023
5db078c
tryfix simulation
ValarDragon Feb 8, 2023
a8b5c4c
Fix for legacy simulator
ValarDragon Feb 8, 2023
275cfb8
Update x/txfees/keeper/feedecorator_test.go
ValarDragon Feb 8, 2023
e7db7e1
Apply matt comments
ValarDragon Feb 8, 2023
1896d2e
See what happens by adding fees
ValarDragon Feb 8, 2023
f3ffdcb
Merge branch 'main' into dev/consensus_min_gas_fee
ValarDragon Feb 13, 2023
bf1b8bc
Add genesis logic update
ValarDragon Feb 13, 2023
81ea3fd
Try fixing e2e
ValarDragon Feb 13, 2023
efe1326
Add some better logging to find error
ValarDragon Feb 13, 2023
540eaff
remove stat, fix typo
ValarDragon Feb 13, 2023
63c07fa
fix(e2e): fix e2e test for consensus min gas fee #4244 (#4317)
p0mvn Feb 16, 2023
af6f4a0
Temp disable geo twap E2E
ValarDragon Feb 16, 2023
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: 1 addition & 1 deletion simulation/simtypes/txbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (sim *SimCtx) defaultTxBuilder(
txConfig := params.MakeEncodingConfig().TxConfig // TODO: unhardcode
// TODO: Consider making a default tx builder that charges some random fees
// Low value for amount of work right now though.
fees := sdk.Coins{}
fees := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 25000))
tx, err := genTx(
txConfig,
[]sdk.Msg{msg},
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/containers/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (m *Manager) ExecTxCmd(t *testing.T, chainId string, containerName string,
// namely adding flags `--chain-id={chain-id} -b=block --yes --keyring-backend=test "--log_format=json"`,
// and searching for `successStr`
func (m *Manager) ExecTxCmdWithSuccessString(t *testing.T, chainId string, containerName string, command []string, successStr string) (bytes.Buffer, bytes.Buffer, error) {
allTxArgs := []string{fmt.Sprintf("--chain-id=%s", chainId), "-b=block", "--yes", "--keyring-backend=test", "--log_format=json"}
allTxArgs := []string{fmt.Sprintf("--chain-id=%s", chainId), "-b=block", "--yes", "--keyring-backend=test", "--log_format=json", "--fees=875uosmo"}
ValarDragon marked this conversation as resolved.
Show resolved Hide resolved
txCommand := append(command, allTxArgs...)
return m.ExecCmd(t, containerName, txCommand, successStr)
}
Expand Down
10 changes: 10 additions & 0 deletions tests/ibc-hooks/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/osmosis-labs/osmosis/v14/x/gamm/pool-models/balancer"
gammtypes "github.com/osmosis-labs/osmosis/v14/x/gamm/types"
minttypes "github.com/osmosis-labs/osmosis/v14/x/mint/types"
txfeetypes "github.com/osmosis-labs/osmosis/v14/x/txfees/types"

"github.com/osmosis-labs/osmosis/v14/app/apptesting"

Expand Down Expand Up @@ -42,7 +43,11 @@ type HooksTestSuite struct {
path *ibctesting.Path
}

var oldConsensusMinFee = txfeetypes.ConsensusMinFee

func (suite *HooksTestSuite) SetupTest() {
// TODO: This needs to get removed. Waiting on https://github.com/cosmos/ibc-go/issues/3123
txfeetypes.ConsensusMinFee = sdk.ZeroDec()
suite.Setup()
ibctesting.DefaultTestingAppInit = osmosisibctesting.SetupTestingApp
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2)
Expand All @@ -60,6 +65,11 @@ func (suite *HooksTestSuite) SetupTest() {
suite.coordinator.Setup(suite.path)
}

// TODO: This needs to get removed. Waiting on https://github.com/cosmos/ibc-go/issues/3123
func (suite *HooksTestSuite) TearDownSuite() {
txfeetypes.ConsensusMinFee = oldConsensusMinFee
}

func TestIBCHooksTestSuite(t *testing.T) {
suite.Run(t, new(HooksTestSuite))
}
Expand Down
2 changes: 1 addition & 1 deletion tests/osmosisibctesting/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func SetupTestingApp() (ibctesting.TestingApp, map[string]json.RawMessage) {
return osmosisApp, app.NewDefaultGenesisState()
}

// SendMsgsNoCheck overrides ibctesting.TestChain.SendMsgs so that it doesn't check for errors. That should be handled by the caller
// SendMsgsNoCheck is an alternative to ibctesting.TestChain.SendMsgs so that it doesn't check for errors. That should be handled by the caller
func (chain *TestChain) SendMsgsNoCheck(msgs ...sdk.Msg) (*sdk.Result, error) {
// ensure the chain has the latest time
chain.Coordinator.UpdateTimeForChain(chain.TestChain)
Expand Down
6 changes: 6 additions & 0 deletions tests/simulator/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/simapp/helpers"
sdk "github.com/cosmos/cosmos-sdk/types"

osmosim "github.com/osmosis-labs/osmosis/v14/simulation/executor"
"github.com/osmosis-labs/osmosis/v14/simulation/simtypes/simlogger"
txfeetypes "github.com/osmosis-labs/osmosis/v14/x/txfees/types"
)

// Profile with:
Expand Down Expand Up @@ -45,6 +47,8 @@ func TestFullAppSimulation(t *testing.T) {
}

func fullAppSimulation(tb testing.TB, is_testing bool) {
// TODO: Get SDK simulator fixed to have min fees possible
txfeetypes.ConsensusMinFee = sdk.ZeroDec()
config, db, logger, cleanup, err := osmosim.SetupSimulation("goleveldb-app-sim", "Simulation")
if err != nil {
tb.Fatalf("simulation setup failed: %s", err.Error())
Expand Down Expand Up @@ -79,6 +83,8 @@ func TestAppStateDeterminism(t *testing.T) {
// if !osmosim.FlagEnabledValue {
// t.Skip("skipping application simulation")
// }
// TODO: Get SDK simulator fixed to have min fees possible
txfeetypes.ConsensusMinFee = sdk.ZeroDec()

config := osmosim.NewConfigFromFlags()
config.ExportConfig.ExportParamsPath = ""
Expand Down
11 changes: 11 additions & 0 deletions x/ibc-rate-limit/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
ibctesting "github.com/cosmos/ibc-go/v4/testing"
"github.com/stretchr/testify/suite"

txfeetypes "github.com/osmosis-labs/osmosis/v14/x/txfees/types"

"github.com/osmosis-labs/osmosis/v14/app/apptesting"
"github.com/osmosis-labs/osmosis/v14/tests/osmosisibctesting"
"github.com/osmosis-labs/osmosis/v14/x/ibc-rate-limit/types"
Expand All @@ -31,6 +33,8 @@ type MiddlewareTestSuite struct {
path *ibctesting.Path
}

var oldConsensusMinFee = txfeetypes.ConsensusMinFee

// Setup
func TestMiddlewareTestSuite(t *testing.T) {
suite.Run(t, new(MiddlewareTestSuite))
Expand All @@ -46,6 +50,8 @@ func NewTransferPath(chainA, chainB *osmosisibctesting.TestChain) *ibctesting.Pa
}

func (suite *MiddlewareTestSuite) SetupTest() {
// TODO: This needs to get removed. Waiting on https://github.com/cosmos/ibc-go/issues/3123
txfeetypes.ConsensusMinFee = sdk.ZeroDec()
suite.Setup()
ibctesting.DefaultTestingAppInit = osmosisibctesting.SetupTestingApp
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2)
Expand All @@ -64,6 +70,11 @@ func (suite *MiddlewareTestSuite) SetupTest() {
suite.coordinator.Setup(suite.path)
}

// TODO: This needs to get removed. Waiting on https://github.com/cosmos/ibc-go/issues/3123
func (suite *MiddlewareTestSuite) TearDownSuite() {
txfeetypes.ConsensusMinFee = oldConsensusMinFee
}

// Helpers
func (suite *MiddlewareTestSuite) MessageFromAToB(denom string, amount sdk.Int) sdk.Msg {
coin := sdk.NewCoin(denom, amount)
Expand Down
49 changes: 33 additions & 16 deletions x/txfees/keeper/feedecorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,44 @@ func (mfd MempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b
}
}

// If we are in CheckTx, this function is ran locally to determine if these fees are sufficient
// to enter our mempool.
// So we ensure that the provided fees meet a minimum threshold for the validator,
// converting every non-osmo specified asset into an osmo-equivalent amount, to determine sufficiency.
if (ctx.IsCheckTx() || ctx.IsReCheckTx()) && !simulate {
minBaseGasPrice := mfd.GetMinBaseGasPriceForTx(ctx, baseDenom, feeTx)
if !(minBaseGasPrice.IsZero()) {
// You should only be able to pay with one fee token in a single tx
if len(feeCoins) != 1 {
return ctx, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "no fee attached")
}
err = mfd.TxFeesKeeper.IsSufficientFee(ctx, minBaseGasPrice, feeTx.GetGas(), feeCoins[0])
if err != nil {
return ctx, err
}
}
// Determine if these fees are sufficient for the tx to pass.
// Once ABCI++ Process Proposal lands, we can have block validity conditions enforce this.
minBaseGasPrice := mfd.getMinBaseGasPrice(ctx, baseDenom, simulate, feeTx)

// If minBaseGasPrice is zero, then we don't need to check the fee. Continue
if minBaseGasPrice.IsZero() {
return next(ctx, tx, simulate)
}
// You should only be able to pay with one fee token in a single tx
if len(feeCoins) != 1 {
return ctx, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee,
"Expected 1 fee denom attached, got %d", len(feeCoins))
}
// The minimum base gas price is in uosmo, convert the fee denom's worth to uosmo terms.
// Then compare if its sufficient for paying the tx fee.
err = mfd.TxFeesKeeper.IsSufficientFee(ctx, minBaseGasPrice, feeTx.GetGas(), feeCoins[0])
if err != nil {
return ctx, err
}

return next(ctx, tx, simulate)
}

func (mfd MempoolFeeDecorator) getMinBaseGasPrice(ctx sdk.Context, baseDenom string, simulate bool, feeTx sdk.FeeTx) sdk.Dec {
// In block execution (DeliverTx), its set to the governance decided upon consensus min fee.
minBaseGasPrice := types.ConsensusMinFee
// If we are in CheckTx, a separate function is ran locally to ensure sufficient fees for entering our mempool.
// So we ensure that the provided fees meet a minimum threshold for the validator
if (ctx.IsCheckTx() || ctx.IsReCheckTx()) && !simulate {
minBaseGasPrice = sdk.MaxDec(minBaseGasPrice, mfd.GetMinBaseGasPriceForTx(ctx, baseDenom, feeTx))
}
// If we are in genesis, then we actually override all of the above, to set it to 0.
if ctx.IsGenesis() {
minBaseGasPrice = sdk.ZeroDec()
}
return minBaseGasPrice
}

// IsSufficientFee checks if the feeCoin provided (in any asset), is worth enough osmo at current spot prices
// to pay the gas cost of this tx.
func (k Keeper) IsSufficientFee(ctx sdk.Context, minBaseGasPrice sdk.Dec, gasRequested uint64, feeCoin sdk.Coin) error {
Expand Down
Loading