Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 14 commits into from
Sep 16, 2024

Conversation

VictorTrustyDev
Copy link
Member

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

Terms:

  • Dual-Lane decorators are decorators that wrap sdk ante, will:
    • Routing to sdk ante if the tx is a Cosmos tx
    • Process internal logic if the tx is an Ethereum tx or just move to next ante.
  • Evm-Lane decorators will:
    • Routing to next ante if the tx is a Cosmos tx
    • Process internal logic for Ethereum tx
  • Cosmos-Lane decorators are similar to Evm-Lane decorators but reverse.

Additional changes:

  • Adjust priority calculation logic, priority now = effective gas prices (previous only 0/1)
  • Extensions (ExtensionOptionsEthereumTx/ExtensionOptionDynamicFeeTx) are now optional for backward compatible to clients.
  • Remove any local-maintained logic if SDK already have it, if applicable.
    The main purpose is take advantage of security bug fixes maintained by Cosmos team.
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)
	}
}

@VictorTrustyDev VictorTrustyDev added the new-feature New feature/request label Sep 16, 2024
@VictorTrustyDev VictorTrustyDev self-assigned this Sep 16, 2024
@VictorTrustyDev VictorTrustyDev merged commit fcd5d86 into main Sep 16, 2024
@VictorTrustyDev VictorTrustyDev deleted the feat/dual-lane-ante-handle branch September 16, 2024 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature New feature/request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants