From 5debecd323fe94cb20ddf118ee1b1583530aaa78 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 22 Sep 2022 00:43:53 +0700 Subject: [PATCH] Revert fixed gas cost for v12 (#2808) * remove fix gas constant & related test * format --- x/gamm/keeper/swap_test.go | 8 -------- x/gamm/pool-models/balancer/pool.go | 2 -- x/gamm/types/constants.go | 3 +-- 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/x/gamm/keeper/swap_test.go b/x/gamm/keeper/swap_test.go index fd0cd8497..f2c578350 100644 --- a/x/gamm/keeper/swap_test.go +++ b/x/gamm/keeper/swap_test.go @@ -97,13 +97,9 @@ func (suite *KeeperTestSuite) TestBalancerPoolSimpleSwapExactAmountIn() { spotPriceBefore, err := keeper.CalculateSpotPrice(ctx, poolId, test.param.tokenIn.Denom, test.param.tokenOutDenom) suite.NoError(err, "test: %v", test.name) - prevGasConsumed := suite.Ctx.GasMeter().GasConsumed() tokenOutAmount, err := keeper.SwapExactAmountIn(ctx, suite.TestAccs[0], poolId, test.param.tokenIn, test.param.tokenOutDenom, test.param.tokenOutMinAmount) suite.NoError(err, "test: %v", test.name) suite.True(tokenOutAmount.Equal(test.param.expectedTokenOut), "test: %v", test.name) - gasConsumedForSwap := suite.Ctx.GasMeter().GasConsumed() - prevGasConsumed - // We consume `types.GasFeeForSwap` directly, so the extra I/O operation mean we end up consuming more. - suite.Assert().Greater(gasConsumedForSwap, uint64(types.BalancerGasFeeForSwap)) suite.AssertEventEmitted(ctx, types.TypeEvtTokenSwapped, 1) @@ -205,15 +201,11 @@ func (suite *KeeperTestSuite) TestBalancerPoolSimpleSwapExactAmountOut() { spotPriceBefore, err := keeper.CalculateSpotPrice(ctx, poolId, test.param.tokenInDenom, test.param.tokenOut.Denom) suite.NoError(err, "test: %v", test.name) - prevGasConsumed := suite.Ctx.GasMeter().GasConsumed() tokenInAmount, err := keeper.SwapExactAmountOut(ctx, suite.TestAccs[0], poolId, test.param.tokenInDenom, test.param.tokenInMaxAmount, test.param.tokenOut) suite.NoError(err, "test: %v", test.name) suite.True(tokenInAmount.Equal(test.param.expectedTokenInAmount), "test: %v\n expect_eq actual: %s, expected: %s", test.name, tokenInAmount, test.param.expectedTokenInAmount) - gasConsumedForSwap := suite.Ctx.GasMeter().GasConsumed() - prevGasConsumed - // We consume `types.GasFeeForSwap` directly, so the extra I/O operation mean we end up consuming more. - suite.Assert().Greater(gasConsumedForSwap, uint64(types.BalancerGasFeeForSwap)) suite.AssertEventEmitted(ctx, types.TypeEvtTokenSwapped, 1) diff --git a/x/gamm/pool-models/balancer/pool.go b/x/gamm/pool-models/balancer/pool.go index 510502d8e..b49b83451 100644 --- a/x/gamm/pool-models/balancer/pool.go +++ b/x/gamm/pool-models/balancer/pool.go @@ -583,8 +583,6 @@ func (p *Pool) SwapInAmtGivenOut( // ApplySwap. func (p *Pool) applySwap(ctx sdk.Context, tokensIn sdk.Coins, tokensOut sdk.Coins) error { - // Fixed gas consumption per swap to prevent spam - ctx.GasMeter().ConsumeGas(types.BalancerGasFeeForSwap, "balancer swap computation") // Also ensures that len(tokensIn) = 1 = len(tokensOut) inPoolAsset, outPoolAsset, err := p.parsePoolAssetsCoins(tokensIn, tokensOut) if err != nil { diff --git a/x/gamm/types/constants.go b/x/gamm/types/constants.go index 537939d96..a019135e2 100644 --- a/x/gamm/types/constants.go +++ b/x/gamm/types/constants.go @@ -11,8 +11,7 @@ const ( OneShareExponent = 18 // Raise 10 to the power of SigFigsExponent to determine number of significant figures. // i.e. SigFigExponent = 8 is 10^8 which is 100000000. This gives 8 significant figures. - SigFigsExponent = 8 - BalancerGasFeeForSwap = 10_000 + SigFigsExponent = 8 ) var ( -- GitLab