Skip to content

Commit

Permalink
Consensus min gas fee of .0025 uosmo (#4244) (#4347)
Browse files Browse the repository at this point in the history
* Refactor tests a bit

* Add consensus min gas fee

* Fix tests

* Delete more crud

* Cleanup more duplicate test cases

* flip isCheckTx sign

* One more test needed

* Run invalid fee denom test across both check & deliver

* Remove extra line

* Add hack to get around txfee problem in ibctesting

* Handle genesis

* Minor code cleanup

* tryfix simulation

* Fix for legacy simulator

* Update x/txfees/keeper/feedecorator_test.go

Co-authored-by: Matt, Park <[email protected]>

* Apply matt comments

* See what happens by adding fees

* Add genesis logic update

* Try fixing e2e

* Add some better logging to find error

* remove stat, fix typo

* fix(e2e): fix e2e test for consensus min gas fee #4244 (#4317)

* chore(e2e): update init image on main for #4244

* changes

* fix more problems

* more fixes

* lint

* twap gebug logs

* arithmetic fix

* skip twap test

* link issue

* Temp disable geo twap E2E

---------

Co-authored-by: Matt, Park <[email protected]>
Co-authored-by: Roman <[email protected]>
(cherry picked from commit 05fda4d)

Co-authored-by: Dev Ojha <[email protected]>
  • Loading branch information
mergify[bot] and ValarDragon authored Feb 16, 2023
1 parent 5213515 commit fcd77ab
Show file tree
Hide file tree
Showing 18 changed files with 348 additions and 194 deletions.
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
26 changes: 26 additions & 0 deletions tests/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,32 @@ This section contains common "gotchas" that is sometimes very good to know when

To fix that, check the docker container and see if you node is working. Or remove all related container then rerun e2e test

3. Transaction fees.

Consensus min fee is set to "0.0025". This is how much is charged for 1 unit of gas. By default, we specify the gas limit
of `40000`. Therefore, each transaction should take `fee = 0.0025 uosmo / gas * 400000 gas = 1000 fee token.
The fee denom is set in `tests/e2e/initialization/config.go` by the value of `E2EFeeToken`.
See "Hermes Relayer - Consensus Min Fee" section for the relevant relayer configuration.
## Hermes Relayer
The configuration is built using the script in `tests/e2e/scripts/hermes_bootstrap.sh`
Repository: <https://github.dev/informalsystems/hermes>
### Consensus Min Fee
We set the following parameters Hermes configs to enable the consensus min fee in Osmosis:
- `gas_price` - Specifies the price per gas used of the fee to submit a transaction and
the denomination of the fee. The specified gas price should always be greater or equal to the `min-gas-price`
configured on the chain. This is to ensure that at least some minimal price is
paid for each unit of gas per transaction.
In Osmosis, we set consensus min fee = .0025 uosmo / gas * 400000 gas = 1000
See ConsensusMinFee in x/txfees/types/constants.go
- `default_gas` - the gas amount to use when simulation fails.
## Debugging
This section contains information about debugging osmosis's `e2e` tests.
Expand Down
16 changes: 14 additions & 2 deletions tests/e2e/configurer/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,30 @@ func (c *Config) SendIBC(dstChain *Config, recipient string, token sdk.Coin) {
dstNode, err := dstChain.GetDefaultNode()
require.NoError(c.t, err)

balancesDstPre, err := dstNode.QueryBalances(recipient)
// removes the fee token from balances for calculating the difference in other tokens
// before and after the IBC send.
removeFeeTokenFromBalance := func(balance sdk.Coins) sdk.Coins {
feeTokenBalance := balance.FilterDenoms([]string{initialization.E2EFeeToken})
return balance.Sub(feeTokenBalance)
}

balancesDstPreWithTxFeeBalance, err := dstNode.QueryBalances(recipient)
require.NoError(c.t, err)

balancesDstPre := removeFeeTokenFromBalance(balancesDstPreWithTxFeeBalance)

cmd := []string{"hermes", "tx", "raw", "ft-transfer", dstChain.Id, c.Id, "transfer", "channel-0", token.Amount.String(), fmt.Sprintf("--denom=%s", token.Denom), fmt.Sprintf("--receiver=%s", recipient), "--timeout-height-offset=1000"}
_, _, err = c.containerManager.ExecHermesCmd(c.t, cmd, "Success")
require.NoError(c.t, err)

require.Eventually(
c.t,
func() bool {
balancesDstPost, err := dstNode.QueryBalances(recipient)
balancesDstPostWithTxFeeBalance, err := dstNode.QueryBalances(recipient)
require.NoError(c.t, err)

balancesDstPost := removeFeeTokenFromBalance(balancesDstPostWithTxFeeBalance)

ibcCoin := balancesDstPost.Sub(balancesDstPre)
if ibcCoin.Len() == 1 {
tokenPre := balancesDstPre.AmountOfNoDenomValidation(ibcCoin[0].Denom)
Expand Down
23 changes: 16 additions & 7 deletions tests/e2e/configurer/chain/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
app "github.com/osmosis-labs/osmosis/v14/app"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/p2p"
coretypes "github.com/tendermint/tendermint/rpc/core/types"

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

func (n *NodeConfig) CreateBalancerPool(poolFile, from string) uint64 {
Expand Down Expand Up @@ -127,7 +128,7 @@ func (n *NodeConfig) SendIBCTransfer(from, recipient, amount, memo string) {

cmd := []string{"osmosisd", "tx", "ibc-transfer", "transfer", "transfer", "channel-0", recipient, amount, fmt.Sprintf("--from=%s", from), "--memo", memo}

_, _, err := n.containerManager.ExecTxCmdWithSuccessString(n.t, n.chainId, n.Name, cmd, "code: 0")
_, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, cmd)
require.NoError(n.t, err)

n.LogActionF("successfully submitted sent IBC transfer")
Expand Down Expand Up @@ -277,6 +278,8 @@ func (n *NodeConfig) BankSend(amount string, sendAddress string, receiveAddress
n.LogActionF("successfully sent bank sent %s from address %s to %s", amount, sendAddress, receiveAddress)
}

// This method also funds fee tokens from the `initialization.ValidatorWalletName` account.
// TODO: Abstract this to be a fee token provider account.
func (n *NodeConfig) CreateWallet(walletName string) string {
n.LogActionF("creating wallet %s", walletName)
cmd := []string{"osmosisd", "keys", "add", walletName, "--keyring-backend=test"}
Expand All @@ -285,19 +288,25 @@ func (n *NodeConfig) CreateWallet(walletName string) string {
re := regexp.MustCompile("osmo1(.{38})")
walletAddr := fmt.Sprintf("%s\n", re.FindString(outBuf.String()))
walletAddr = strings.TrimSuffix(walletAddr, "\n")
n.LogActionF("created wallet %s, waller address - %s", walletName, walletAddr)
n.LogActionF("created wallet %s, wallet address - %s", walletName, walletAddr)
n.BankSend(initialization.WalletFeeTokens.String(), initialization.ValidatorWalletName, walletAddr)
n.LogActionF("Sent fee tokens from %s", initialization.ValidatorWalletName)
return walletAddr
}

func (n *NodeConfig) CreateWalletAndFund(walletName string, tokensToFund []string) string {
n.LogActionF("Sending tokens to %s", walletName)
return n.CreateWalletAndFundFrom(walletName, initialization.ValidatorWalletName, tokensToFund)
}

func (n *NodeConfig) CreateWalletAndFundFrom(newWalletName string, fundingWalletName string, tokensToFund []string) string {
n.LogActionF("Sending tokens to %s", newWalletName)

walletAddr := n.CreateWallet(walletName)
walletAddr := n.CreateWallet(newWalletName)
for _, tokenToFund := range tokensToFund {
n.BankSend(tokenToFund, initialization.ValidatorWalletName, walletAddr)
n.BankSend(tokenToFund, fundingWalletName, walletAddr)
}

n.LogActionF("Successfully sent tokens to %s", walletName)
n.LogActionF("Successfully sent tokens to %s", newWalletName)
return walletAddr
}

Expand Down
9 changes: 9 additions & 0 deletions tests/e2e/configurer/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ var (
InitialMinDeposit = MinDepositValue / 4
// Minimum expedited deposit value for proposal to be submitted.
InitialMinExpeditedDeposit = MinExpeditedDepositValue / 4
// The first id of a pool create via CLI before starting an
// upgrade.
// Note: that we create a pool with id 1 via genesis
// in the initialization package. As a result, the first
// pre-upgrade should have id 2.
// This value gets mutated during the pre-upgrade pool
// creation in case more pools are added to genesis
// in the future
PreUpgradePoolId uint64 = 2
)
11 changes: 6 additions & 5 deletions tests/e2e/configurer/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,20 @@ func (uc *UpgradeConfigurer) CreatePreUpgradeState() error {
chainA.SendIBC(chainB, chainB.NodeConfigs[0].PublicAddress, initialization.StakeToken)
chainB.SendIBC(chainA, chainA.NodeConfigs[0].PublicAddress, initialization.StakeToken)

chainANode.CreateBalancerPool("pool1A.json", initialization.ValidatorWalletName)
config.PreUpgradePoolId = chainANode.CreateBalancerPool("pool1A.json", initialization.ValidatorWalletName)
poolShareDenom := fmt.Sprintf("gamm/pool/%d", config.PreUpgradePoolId)
chainBNode.CreateBalancerPool("pool1B.json", initialization.ValidatorWalletName)

// enable superfluid assets on chainA
chainA.EnableSuperfluidAsset("gamm/pool/1")
chainA.EnableSuperfluidAsset(poolShareDenom)

// setup wallets and send gamm tokens to these wallets (only chainA)
lockupWalletAddrA, lockupWalletSuperfluidAddrA := chainANode.CreateWallet(lockupWallet), chainANode.CreateWallet(lockupWalletSuperfluid)
chainANode.BankSend("10000000000000000000gamm/pool/1", chainA.NodeConfigs[0].PublicAddress, lockupWalletAddrA)
chainANode.BankSend("10000000000000000000gamm/pool/1", chainA.NodeConfigs[0].PublicAddress, lockupWalletSuperfluidAddrA)
chainANode.BankSend("10000000000000000000"+poolShareDenom, chainA.NodeConfigs[0].PublicAddress, lockupWalletAddrA)
chainANode.BankSend("10000000000000000000"+poolShareDenom, chainA.NodeConfigs[0].PublicAddress, lockupWalletSuperfluidAddrA)

// test lock and add to existing lock for both regular and superfluid lockups (only chainA)
chainA.LockAndAddToExistingLock(sdk.NewInt(1000000000000000000), "gamm/pool/1", lockupWalletAddrA, lockupWalletSuperfluidAddrA)
chainA.LockAndAddToExistingLock(sdk.NewInt(1000000000000000000), poolShareDenom, lockupWalletAddrA, lockupWalletSuperfluidAddrA)

return nil
}
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/containers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ const (
// It should be uploaded to Docker Hub. OSMOSIS_E2E_SKIP_UPGRADE should be unset
// for this functionality to be used.
previousVersionOsmoRepository = "osmolabs/osmosis-dev"
previousVersionOsmoTag = "v14.x-6b742c84-1675172347"
previousVersionOsmoTag = "v14.x-4d4583fa-1676370337"
// Pre-upgrade repo/tag for osmosis initialization (this should be one version below upgradeVersion)
previousVersionInitRepository = "osmolabs/osmosis-e2e-init-chain"
previousVersionInitTag = "v14.x-f6813bcb-1674140667-manual"
previousVersionInitTag = "v14.x-4d4583fa-1676370337-manual"
// Hermes repo/version for relayer
relayerRepository = "osmolabs/hermes"
relayerTag = "0.13.0"
Expand Down
34 changes: 31 additions & 3 deletions tests/e2e/containers/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,33 @@ import (
"github.com/ory/dockertest/v3"
"github.com/ory/dockertest/v3/docker"
"github.com/stretchr/testify/require"

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

"github.com/osmosis-labs/osmosis/v14/tests/e2e/initialization"
txfeestypes "github.com/osmosis-labs/osmosis/v14/x/txfees/types"
)

const (
hermesContainerName = "hermes-relayer"
// The maximum number of times debug logs are printed to console
// per CLI command.
maxDebugLogsPerCommand = 3

GasLimit = 400000
)

var defaultErrRegex = regexp.MustCompile(`(E|e)rror`)
var (
// We set consensus min fee = .0025 uosmo / gas * 400000 gas = 1000
Fees = txfeestypes.ConsensusMinFee.Mul(sdk.NewDec(GasLimit)).Ceil().TruncateInt64()

defaultErrRegex = regexp.MustCompile(`(E|e)rror`)

txArgs = []string{"-b=block", "--yes", "--keyring-backend=test", "--log_format=json"}

// See ConsensusMinFee in x/txfees/types/constants.go
txDefaultGasArgs = []string{fmt.Sprintf("--gas=%d", GasLimit), fmt.Sprintf("--fees=%d", Fees) + initialization.E2EFeeToken}
)

// Manager is a wrapper around all Docker instances, and the Docker API.
// It provides utilities to run and interact with all Docker containers used within e2e testing.
Expand Down Expand Up @@ -59,10 +76,21 @@ func (m *Manager) ExecTxCmd(t *testing.T, chainId string, containerName string,
}

// ExecTxCmdWithSuccessString Runs ExecCmd, with flags for txs added.
// namely adding flags `--chain-id={chain-id} -b=block --yes --keyring-backend=test "--log_format=json"`,
// namely adding flags `--chain-id={chain-id} -b=block --yes --keyring-backend=test "--log_format=json" --gas=400000`,
// 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)}
allTxArgs = append(allTxArgs, txArgs...)
// parse to see if command has gas flags. If not, add default gas flags.
addGasFlags := true
for _, cmd := range command {
if strings.HasPrefix(cmd, "--gas") || strings.HasPrefix(cmd, "--fees") {
addGasFlags = false
}
}
if addGasFlags {
allTxArgs = append(allTxArgs, txDefaultGasArgs...)
}
txCommand := append(command, allTxArgs...)
return m.ExecCmd(t, containerName, txCommand, successStr)
}
Expand Down
Loading

0 comments on commit fcd77ab

Please sign in to comment.