Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

## Unreleased

* (deps) [#776](https://github.com/crypto-org-chain/ethermint/pull/776) fix: Optimize staking endblocker with an in-memory KV store and standardize gas consumption for staking related messages
* (evm) [#725](https://github.com/crypto-org-chain/ethermint/pull/725) feat(RPC): add authorizationList from eth_getTransactionByHash response for EIP-7702 transactions
* (evm) [#740](https://github.com/crypto-org-chain/ethermint/pull/740) fix: missing tx context during vm initialisation
* (evm) [#742](https://github.com/crypto-org-chain/ethermint/pull/742) fix: prevent nil pointer dereference in tracer hooks
Expand Down
66 changes: 66 additions & 0 deletions ante/cosmos/fixed_gas.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package cosmos

import (
storetypes "cosmossdk.io/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

// FixedGasConsumedDecorator consumes a fixed amount of gas for whitelisted messages
// and then replaces the gas meter with a fixed gas meter to prevent additional gas consumption
type FixedGasConsumedDecorator struct{}

var WhitelistedMessages = map[string]uint64{
sdk.MsgTypeURL(&stakingtypes.MsgUndelegate{}): 200000,
sdk.MsgTypeURL(&stakingtypes.MsgBeginRedelegate{}): 232000,
}

// NewFixedGasConsumedDecorator creates a new FixedGasConsumedDecorator
func NewFixedGasConsumedDecorator() FixedGasConsumedDecorator {
return FixedGasConsumedDecorator{}
}

type fixedGasMeter struct {
consumed storetypes.Gas
}

// NewFixedGasMeter returns a new gas meter with a fixed amount of consumed gas.
func NewFixedGasMeter(consumed storetypes.Gas) storetypes.GasMeter {
return &fixedGasMeter{
consumed: consumed,
}
}

var _ storetypes.GasMeter = &fixedGasMeter{}

func (fgm *fixedGasMeter) GasConsumed() storetypes.Gas { return fgm.consumed }
func (fgm *fixedGasMeter) GasConsumedToLimit() storetypes.Gas { return fgm.consumed }
func (fgm *fixedGasMeter) GasRemaining() storetypes.Gas { return 0 }
func (fgm *fixedGasMeter) Limit() storetypes.Gas { return fgm.consumed }
func (fgm *fixedGasMeter) ConsumeGas(storetypes.Gas, string) {}
func (fgm *fixedGasMeter) RefundGas(storetypes.Gas, string) {}
func (fgm *fixedGasMeter) IsPastLimit() bool { return false }
func (fgm *fixedGasMeter) IsOutOfGas() bool { return false }
func (fgm *fixedGasMeter) String() string { return "fixedGasMeter" }

func (fgcd FixedGasConsumedDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
msgs := tx.GetMsgs()
totalFixedGas := uint64(0)
whitelistedMsgsPresent := false

for _, msg := range msgs {
msgTypeURL := sdk.MsgTypeURL(msg)
if fixedGas, found := WhitelistedMessages[msgTypeURL]; found {
whitelistedMsgsPresent = true
totalFixedGas += fixedGas
}
}

if whitelistedMsgsPresent {
ctx.GasMeter().ConsumeGas(totalFixedGas, "fixed gas for whitelisted messages")
consumedGas := ctx.GasMeter().GasConsumed()
ctx = ctx.WithGasMeter(NewFixedGasMeter(consumedGas))
}

return next(ctx, tx, simulate)
}
6 changes: 3 additions & 3 deletions evmd/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
"success - DeliverTx EIP712 signed Cosmos Tx with DelegateMsg",
func() sdk.Tx {
from := acc.GetAddress()
gas := uint64(200000)
gas := uint64(300000)
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdkmath.NewInt(100*int64(gas)))
amount := sdk.NewCoins(coinAmount)
txBuilder := suite.CreateTestEIP712TxBuilderMsgDelegate(from, privKey, "ethermint_9000-1", gas, amount)
Expand All @@ -369,7 +369,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdkmath.NewInt(20))
amount := sdk.NewCoins(coinAmount)
gas := uint64(200000)
gas := uint64(300000)
txBuilder := suite.CreateTestEIP712MsgCreateValidator(from, privKey, "ethermint_9000-1", gas, amount)
return txBuilder.GetTx()
}, false, false, true,
Expand All @@ -380,7 +380,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdkmath.NewInt(20))
amount := sdk.NewCoins(coinAmount)
gas := uint64(200000)
gas := uint64(300000)
txBuilder := suite.CreateTestEIP712MsgCreateValidator2(from, privKey, "ethermint_9000-1", gas, amount)
return txBuilder.GetTx()
}, false, false, true,
Expand Down
1 change: 1 addition & 0 deletions evmd/ante/evm_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func newLegacyCosmosAnteHandlerEip712(ctx sdk.Context, options HandlerOptions, e
cosmos.NewLegacyEip712SigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
authante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
cosmos.NewFixedGasConsumedDecorator(),
}
decorators = append(decorators, extra...)
return sdk.ChainAnteDecorators(decorators...)
Expand Down
Loading
Loading