EscanBE / evermint

Evermint is a fork of open source Evmos, maintains bug fixes, customization and enable developers to fork and transform to their chain, fully customized naming, in just 2 steps. For research and development purpose.
GNU Lesser General Public License v3.0
3 stars 3 forks source link

feat(ante): introduce Dual-Lane AnteHandler #164

Closed VictorTrustyDev closed 2 months ago

VictorTrustyDev commented 2 months ago

This PR introduces Dual-Lane AnteHandler, that means each ante supposed to handle both EVM Tx and Cosmos Tx based on tx type.

Terms:

Additional changes:

func NewAnteHandler(options HandlerOptions) sdk.AnteHandler {
    return func(
        ctx sdk.Context, tx sdk.Tx, sim bool,
    ) (newCtx sdk.Context, err error) {
        // SDK ante plus dual-lane logic
        anteDecorators := []sdk.AnteDecorator{
            duallane.NewDualLaneSetupContextDecorator(*options.EvmKeeper, sdkauthante.NewSetUpContextDecorator()), // outermost AnteDecorator. SetUpContext must be called first
            duallane.NewDualLaneExtensionOptionsDecorator(sdkauthante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker)),
            duallane.NewDualLaneValidateBasicDecorator(*options.EvmKeeper, sdkauthante.NewValidateBasicDecorator()),
            /*EVM-only lane*/ evmlane.NewEvmLaneValidateBasicEoaDecorator(*options.AccountKeeper, *options.EvmKeeper),
            duallane.NewDualLaneTxTimeoutHeightDecorator(sdkauthante.NewTxTimeoutHeightDecorator()),
            duallane.NewDualLaneValidateMemoDecorator(sdkauthante.NewValidateMemoDecorator(options.AccountKeeper)),
            duallane.NewDualLaneConsumeTxSizeGasDecorator(sdkauthante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper)),
            duallane.NewDualLaneDeductFeeDecorator(sdkauthante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker)),
            duallane.NewDualLaneSetPubKeyDecorator(sdkauthante.NewSetPubKeyDecorator(options.AccountKeeper)), // SetPubKeyDecorator must be called before all signature verification decorators
            duallane.NewDualLaneValidateSigCountDecorator(sdkauthante.NewValidateSigCountDecorator(options.AccountKeeper)),
            duallane.NewDualLaneSigGasConsumeDecorator(sdkauthante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer)),
            duallane.NewDualLaneSigVerificationDecorator(*options.AccountKeeper, *options.EvmKeeper, sdkauthante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler)),
            duallane.NewDualLaneIncrementSequenceDecorator(*options.AccountKeeper, *options.EvmKeeper, sdkauthante.NewIncrementSequenceDecorator(options.AccountKeeper)),
            duallane.NewDualLaneRedundantRelayDecorator(ibcante.NewRedundantRelayDecorator(options.IBCKeeper)),
            // from here, there is no longer any SDK ante

            // EVM-only lane
            evmlane.NewEvmLaneSetupExecutionDecorator(*options.EvmKeeper),
            evmlane.NewEvmLaneEmitEventDecorator(*options.EvmKeeper), // must be the last effective Ante

            // Cosmos-only lane
            cosmoslane.NewCosmosLaneRejectEthereumMsgsDecorator(),
            cosmoslane.NewCosmosLaneRejectAuthzMsgsDecorator(options.DisabledNestedMsgs),
            cosmoslane.NewCosmosLaneVestingMessagesAuthorizationDecorator(*options.VAuthKeeper),
        }

        anteHandler := sdk.ChainAnteDecorators(anteDecorators...)

        return anteHandler(ctx, tx, sim)
    }
}