From 136361ded5547051c1c17278fd2ba6a65f5ebce0 Mon Sep 17 00:00:00 2001 From: Ray Pierre <974741468@qq.com> Date: Fri, 19 Feb 2021 15:37:02 +0800 Subject: [PATCH] Merge PR: Improve the accuracy of gas estimation (#657) --- x/evm/handler.go | 4 ++-- x/evm/handler_test.go | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/x/evm/handler.go b/x/evm/handler.go index 9868d31a0d..4f8fcae549 100644 --- a/x/evm/handler.go +++ b/x/evm/handler.go @@ -128,7 +128,7 @@ func handleMsgEthereumTx(ctx sdk.Context, k *Keeper, msg types.MsgEthereumTx) (* k.Bloom.Or(k.Bloom, executionResult.Bloom) // update transaction logs in KVStore - err = k.SetLogs(ctx, common.BytesToHash(txHash), executionResult.Logs) + err = k.SetLogs(ctx.WithGasMeter(sdk.NewInfiniteGasMeter()), common.BytesToHash(txHash), executionResult.Logs) if err != nil { panic(err) } @@ -225,7 +225,7 @@ func handleMsgEthermint(ctx sdk.Context, k *Keeper, msg types.MsgEthermint) (*sd k.Bloom.Or(k.Bloom, executionResult.Bloom) // update transaction logs in KVStore - err = k.SetLogs(ctx, common.BytesToHash(txHash), executionResult.Logs) + err = k.SetLogs(ctx.WithGasMeter(sdk.NewInfiniteGasMeter()), common.BytesToHash(txHash), executionResult.Logs) if err != nil { panic(err) } diff --git a/x/evm/handler_test.go b/x/evm/handler_test.go index 4558393ee8..e2d16c82ca 100644 --- a/x/evm/handler_test.go +++ b/x/evm/handler_test.go @@ -450,9 +450,12 @@ func (suite *EvmTestSuite) TestSendTransaction() { err = tx.Sign(big.NewInt(3), priv.ToECDSA()) suite.Require().NoError(err) + suite.ctx = suite.ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) result, err := suite.handler(suite.ctx, tx) suite.Require().NoError(err) suite.Require().NotNil(result) + var expectedGas uint64 = 5387 + suite.Require().EqualValues(expectedGas, suite.ctx.GasMeter().GasConsumed()) } func (suite *EvmTestSuite) TestOutOfGasWhenDeployContract() {