imp(ante): refactor for increased AnteHandler performance (#1393)

This commit is contained in:
Vladislav Varadinov 2022-10-20 14:40:25 +03:00 committed by GitHub
parent 3ab761b8c4
commit 157f188b91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 12 deletions

View File

@ -438,6 +438,9 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
chainID := vbd.evmKeeper.ChainID() chainID := vbd.evmKeeper.ChainID()
ethCfg := chainCfg.EthereumConfig(chainID) ethCfg := chainCfg.EthereumConfig(chainID)
baseFee := vbd.evmKeeper.GetBaseFee(ctx, ethCfg) baseFee := vbd.evmKeeper.GetBaseFee(ctx, ethCfg)
enableCreate := vbd.evmKeeper.GetEnableCreate(ctx)
enableCall := vbd.evmKeeper.GetEnableCall(ctx)
evmDenom := vbd.evmKeeper.GetEVMDenom(ctx)
for _, msg := range protoTx.GetMsgs() { for _, msg := range protoTx.GetMsgs() {
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx) msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
@ -458,9 +461,6 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
} }
// return error if contract creation or call are disabled through governance // return error if contract creation or call are disabled through governance
enableCreate := vbd.evmKeeper.GetEnableCreate(ctx)
enableCall := vbd.evmKeeper.GetEnableCall(ctx)
if !enableCreate && txData.GetTo() == nil { if !enableCreate && txData.GetTo() == nil {
return ctx, sdkerrors.Wrap(evmtypes.ErrCreateDisabled, "failed to create new contract") return ctx, sdkerrors.Wrap(evmtypes.ErrCreateDisabled, "failed to create new contract")
} else if !enableCall && txData.GetTo() != nil { } else if !enableCall && txData.GetTo() != nil {
@ -471,7 +471,6 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
return ctx, sdkerrors.Wrap(ethtypes.ErrTxTypeNotSupported, "dynamic fee tx not supported") return ctx, sdkerrors.Wrap(ethtypes.ErrTxTypeNotSupported, "dynamic fee tx not supported")
} }
evmDenom := vbd.evmKeeper.GetEVMDenom(ctx)
txFee = txFee.Add(sdk.NewCoin(evmDenom, sdkmath.NewIntFromBigInt(txData.Fee()))) txFee = txFee.Add(sdk.NewCoin(evmDenom, sdkmath.NewIntFromBigInt(txData.Fee())))
} }
@ -551,6 +550,8 @@ func (mfd EthMempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat
chainCfg := mfd.evmKeeper.GetChainConfig(ctx) chainCfg := mfd.evmKeeper.GetChainConfig(ctx)
ethCfg := chainCfg.EthereumConfig(mfd.evmKeeper.ChainID()) ethCfg := chainCfg.EthereumConfig(mfd.evmKeeper.ChainID())
baseFee := mfd.evmKeeper.GetBaseFee(ctx, ethCfg) baseFee := mfd.evmKeeper.GetBaseFee(ctx, ethCfg)
evmDenom := mfd.evmKeeper.GetEVMDenom(ctx)
if baseFee == nil { if baseFee == nil {
for _, msg := range tx.GetMsgs() { for _, msg := range tx.GetMsgs() {
ethMsg, ok := msg.(*evmtypes.MsgEthereumTx) ethMsg, ok := msg.(*evmtypes.MsgEthereumTx)
@ -558,7 +559,6 @@ func (mfd EthMempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil))
} }
evmDenom := mfd.evmKeeper.GetEVMDenom(ctx)
feeAmt := ethMsg.GetFee() feeAmt := ethMsg.GetFee()
glDec := sdk.NewDec(int64(ethMsg.GetGas())) glDec := sdk.NewDec(int64(ethMsg.GetGas()))
requiredFee := ctx.MinGasPrices().AmountOf(evmDenom).Mul(glDec) requiredFee := ctx.MinGasPrices().AmountOf(evmDenom).Mul(glDec)

View File

@ -24,35 +24,35 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
// GetChainConfig returns the chain configuration parameter. // GetChainConfig returns the chain configuration parameter.
func (k Keeper) GetChainConfig(ctx sdk.Context) types.ChainConfig { func (k Keeper) GetChainConfig(ctx sdk.Context) types.ChainConfig {
chainCfg := types.ChainConfig{} var chainCfg types.ChainConfig
k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyChainConfig, &chainCfg) k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyChainConfig, &chainCfg)
return chainCfg return chainCfg
} }
// GetEVMDenom returns the EVM denom. // GetEVMDenom returns the EVM denom.
func (k Keeper) GetEVMDenom(ctx sdk.Context) string { func (k Keeper) GetEVMDenom(ctx sdk.Context) string {
evmDenom := "" var evmDenom string
k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyEVMDenom, &evmDenom) k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyEVMDenom, &evmDenom)
return evmDenom return evmDenom
} }
// GetEnableCall returns true if the EVM Call operation is enabled. // GetEnableCall returns true if the EVM Call operation is enabled.
func (k Keeper) GetEnableCall(ctx sdk.Context) bool { func (k Keeper) GetEnableCall(ctx sdk.Context) bool {
enableCall := false var enableCall bool
k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyEnableCall, &enableCall) k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyEnableCall, &enableCall)
return enableCall return enableCall
} }
// GetEnableCreate returns true if the EVM Create contract operation is enabled. // GetEnableCreate returns true if the EVM Create contract operation is enabled.
func (k Keeper) GetEnableCreate(ctx sdk.Context) bool { func (k Keeper) GetEnableCreate(ctx sdk.Context) bool {
enableCreate := false var enableCreate bool
k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyEnableCreate, &enableCreate) k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyEnableCreate, &enableCreate)
return enableCreate return enableCreate
} }
// GetAllowUnprotectedTxs returns true if unprotected txs (i.e non-replay protected as per EIP-155) are supported by the chain. // GetAllowUnprotectedTxs returns true if unprotected txs (i.e non-replay protected as per EIP-155) are supported by the chain.
func (k Keeper) GetAllowUnprotectedTxs(ctx sdk.Context) bool { func (k Keeper) GetAllowUnprotectedTxs(ctx sdk.Context) bool {
allowUnprotectedTx := false var allowUnprotectedTx bool
k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyAllowUnprotectedTxs, &allowUnprotectedTx) k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyAllowUnprotectedTxs, &allowUnprotectedTx)
return allowUnprotectedTx return allowUnprotectedTx
} }

View File

@ -30,8 +30,8 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
// GetBaseFeeEnabled returns true if base fee is enabled // GetBaseFeeEnabled returns true if base fee is enabled
func (k Keeper) GetBaseFeeEnabled(ctx sdk.Context) bool { func (k Keeper) GetBaseFeeEnabled(ctx sdk.Context) bool {
noBaseFee := false var noBaseFee bool
enableHeight := int64(0) var enableHeight int64
k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyNoBaseFee, &noBaseFee) k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyNoBaseFee, &noBaseFee)
k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyEnableHeight, &enableHeight) k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyEnableHeight, &enableHeight)
return !noBaseFee && ctx.BlockHeight() >= enableHeight return !noBaseFee && ctx.BlockHeight() >= enableHeight