Unverified Commit 5debecd3 authored by Hieu Vu's avatar Hieu Vu Committed by GitHub
Browse files

Revert fixed gas cost for v12 (#2808)

* remove fix gas constant & related test

* format
parent 8dfd9e27
Showing with 1 addition and 12 deletions
+1 -12
...@@ -97,13 +97,9 @@ func (suite *KeeperTestSuite) TestBalancerPoolSimpleSwapExactAmountIn() { ...@@ -97,13 +97,9 @@ func (suite *KeeperTestSuite) TestBalancerPoolSimpleSwapExactAmountIn() {
spotPriceBefore, err := keeper.CalculateSpotPrice(ctx, poolId, test.param.tokenIn.Denom, test.param.tokenOutDenom) spotPriceBefore, err := keeper.CalculateSpotPrice(ctx, poolId, test.param.tokenIn.Denom, test.param.tokenOutDenom)
suite.NoError(err, "test: %v", test.name) 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) 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.NoError(err, "test: %v", test.name)
suite.True(tokenOutAmount.Equal(test.param.expectedTokenOut), "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) suite.AssertEventEmitted(ctx, types.TypeEvtTokenSwapped, 1)
...@@ -205,15 +201,11 @@ func (suite *KeeperTestSuite) TestBalancerPoolSimpleSwapExactAmountOut() { ...@@ -205,15 +201,11 @@ func (suite *KeeperTestSuite) TestBalancerPoolSimpleSwapExactAmountOut() {
spotPriceBefore, err := keeper.CalculateSpotPrice(ctx, poolId, test.param.tokenInDenom, test.param.tokenOut.Denom) spotPriceBefore, err := keeper.CalculateSpotPrice(ctx, poolId, test.param.tokenInDenom, test.param.tokenOut.Denom)
suite.NoError(err, "test: %v", test.name) 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) 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.NoError(err, "test: %v", test.name)
suite.True(tokenInAmount.Equal(test.param.expectedTokenInAmount), suite.True(tokenInAmount.Equal(test.param.expectedTokenInAmount),
"test: %v\n expect_eq actual: %s, expected: %s", "test: %v\n expect_eq actual: %s, expected: %s",
test.name, tokenInAmount, test.param.expectedTokenInAmount) 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) suite.AssertEventEmitted(ctx, types.TypeEvtTokenSwapped, 1)
......
...@@ -583,8 +583,6 @@ func (p *Pool) SwapInAmtGivenOut( ...@@ -583,8 +583,6 @@ func (p *Pool) SwapInAmtGivenOut(
// ApplySwap. // ApplySwap.
func (p *Pool) applySwap(ctx sdk.Context, tokensIn sdk.Coins, tokensOut sdk.Coins) error { 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) // Also ensures that len(tokensIn) = 1 = len(tokensOut)
inPoolAsset, outPoolAsset, err := p.parsePoolAssetsCoins(tokensIn, tokensOut) inPoolAsset, outPoolAsset, err := p.parsePoolAssetsCoins(tokensIn, tokensOut)
if err != nil { if err != nil {
......
...@@ -11,8 +11,7 @@ const ( ...@@ -11,8 +11,7 @@ const (
OneShareExponent = 18 OneShareExponent = 18
// Raise 10 to the power of SigFigsExponent to determine number of significant figures. // 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. // i.e. SigFigExponent = 8 is 10^8 which is 100000000. This gives 8 significant figures.
SigFigsExponent = 8 SigFigsExponent = 8
BalancerGasFeeForSwap = 10_000
) )
var ( var (
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment