diff --git a/CHANGELOG.md b/CHANGELOG.md index 580d2fde7..cced5ac24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,6 +85,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#1962](https://github.com/NibiruChain/nibiru/pull/1962) - chore(evm): code cleanup, unused code, typos, styles, warnings - [#1963](https://github.com/NibiruChain/nibiru/pull/1963) - feat(evm): Deduct a fee during the creation of a FunToken mapping. Implemented by `deductCreateFunTokenFee` inside of the `eth.evm.v1.MsgCreateFunToken` transaction. - [#1965](https://github.com/NibiruChain/nibiru/pull/1965) - refactor(evm): remove evm post-processing hooks +- [#1966](https://github.com/NibiruChain/nibiru/pull/1966) - refactor(evm): clean up AnteHandler setup - [#1967](https://github.com/NibiruChain/nibiru/pull/1967) - feat(evm): export genesis - [#1968](https://github.com/NibiruChain/nibiru/pull/1968) - refactor(evm): funtoken events, cli commands and queries - [#1970](https://github.com/NibiruChain/nibiru/pull/1970) - refactor(evm): move evm antehandlers to separate package. Remove "gosdk/sequence_test.go", which causes a race condition in CI. diff --git a/app/ante.go b/app/ante.go index 0f8282d29..df8ecce92 100644 --- a/app/ante.go +++ b/app/ante.go @@ -11,9 +11,7 @@ import ( "github.com/NibiruChain/nibiru/app/ante" "github.com/NibiruChain/nibiru/app/evmante" - "github.com/NibiruChain/nibiru/eth" devgasante "github.com/NibiruChain/nibiru/x/devgas/v1/ante" - "github.com/NibiruChain/nibiru/x/evm" ) // NewAnteHandler returns and AnteHandler that checks and increments sequence @@ -21,25 +19,36 @@ import ( // first signer. func NewAnteHandler( keepers AppKeepers, - opts ante.AnteHandlerOptions, + options ante.AnteHandlerOptions, ) sdk.AnteHandler { return func( ctx sdk.Context, tx sdk.Tx, sim bool, ) (newCtx sdk.Context, err error) { - if err := opts.ValidateAndClean(); err != nil { + if err := options.ValidateAndClean(); err != nil { return ctx, err } var anteHandler sdk.AnteHandler - hasExt, typeUrl := TxHasExtensions(tx) - if hasExt && typeUrl != "" { - anteHandler = AnteHandlerExtendedTx(typeUrl, keepers, opts) - return anteHandler(ctx, tx, sim) + txWithExtensions, ok := tx.(authante.HasExtensionOptionsTx) + if ok { + opts := txWithExtensions.GetExtensionOptions() + if len(opts) > 0 { + switch typeURL := opts[0].GetTypeUrl(); typeURL { + case "/eth.evm.v1.ExtensionOptionsEthereumTx": + // handle as *evmtypes.MsgEthereumTx + anteHandler = evmante.NewAnteHandlerEVM(options) + default: + return ctx, fmt.Errorf( + "rejecting tx with unsupported extension option: %s", typeURL) + } + + return anteHandler(ctx, tx, sim) + } } switch tx.(type) { case sdk.Tx: - anteHandler = NewAnteHandlerNonEVM(opts) + anteHandler = NewAnteHandlerNonEVM(options) default: return ctx, fmt.Errorf("invalid tx type (%T) in AnteHandler", tx) } @@ -47,28 +56,6 @@ func NewAnteHandler( } } -func AnteHandlerExtendedTx( - typeUrl string, - keepers AppKeepers, - opts ante.AnteHandlerOptions, -) (anteHandler sdk.AnteHandler) { - switch typeUrl { - case evm.TYPE_URL_ETHEREUM_TX: - anteHandler = evmante.NewAnteHandlerEVM(opts) - case eth.TYPE_URL_DYNAMIC_FEE_TX: - anteHandler = NewAnteHandlerNonEVM(opts) - default: - errUnsupported := fmt.Errorf( - `encountered tx with unsupported extension option, "%s"`, typeUrl) - return func( - ctx sdk.Context, tx sdk.Tx, simulate bool, - ) (newCtx sdk.Context, err error) { - return ctx, errUnsupported - } - } - return anteHandler -} - // NewAnteHandlerNonEVM: Default ante handler for non-EVM transactions. func NewAnteHandlerNonEVM( opts ante.AnteHandlerOptions, @@ -91,11 +78,9 @@ func NewAnteHandlerNonEVM( authante.NewConsumeGasForTxSizeDecorator(opts.AccountKeeper), // TODO: spike(security): Does minimum gas price of 0 pose a risk? // ticket: https://github.com/NibiruChain/nibiru/issues/1916 - authante.NewDeductFeeDecorator( - opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, opts.TxFeeChecker), + authante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, opts.TxFeeChecker), // ----------- Ante Handlers: devgas - devgasante.NewDevGasPayoutDecorator( - opts.DevGasBankKeeper, opts.DevGasKeeper), + devgasante.NewDevGasPayoutDecorator(opts.DevGasBankKeeper, opts.DevGasKeeper), // ----------- Ante Handlers: Keys and signatures // NOTE: SetPubKeyDecorator must be called before all signature verification decorators authante.NewSetPubKeyDecorator(opts.AccountKeeper), @@ -107,17 +92,3 @@ func NewAnteHandlerNonEVM( ante.AnteDecoratorGasWanted{}, ) } - -func TxHasExtensions(tx sdk.Tx) (hasExt bool, typeUrl string) { - extensionTx, ok := tx.(authante.HasExtensionOptionsTx) - if !ok { - return false, "" - } - - extOpts := extensionTx.GetExtensionOptions() - if len(extOpts) == 0 { - return false, "" - } - - return true, extOpts[0].GetTypeUrl() -} diff --git a/eth/codec.go b/eth/codec.go index 6fd7fc346..df0e39494 100644 --- a/eth/codec.go +++ b/eth/codec.go @@ -28,8 +28,7 @@ const ( // Transaction extension protobuf type URLs const ( - TYPE_URL_WEB3_TX = "/eth.types.v1.ExtensionOptionsWeb3Tx" - TYPE_URL_DYNAMIC_FEE_TX = "/eth.types.v1.ExtensionOptionDynamicFeeTx" + TYPE_URL_WEB3_TX = "/eth.types.v1.ExtensionOptionsWeb3Tx" ) // RegisterInterfaces registers the tendermint concrete client-related @@ -59,6 +58,5 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { registry.RegisterImplementations( (*sdktx.TxExtensionOptionI)(nil), &ExtensionOptionsWeb3Tx{}, - &ExtensionOptionDynamicFeeTx{}, ) } diff --git a/eth/codec_test.go b/eth/codec_test.go index 18a7cea36..d295954cb 100644 --- a/eth/codec_test.go +++ b/eth/codec_test.go @@ -49,7 +49,6 @@ func (suite *CodecTestSuite) TestRegisterInterfaces() { Interface: new(sdktx.TxExtensionOptionI), WantImpls: []string{ TYPE_URL_WEB3_TX, - TYPE_URL_DYNAMIC_FEE_TX, }, }, } diff --git a/x/evm/codec.go b/x/evm/codec.go index 42fec4565..a8dff5d4e 100644 --- a/x/evm/codec.go +++ b/x/evm/codec.go @@ -18,12 +18,6 @@ var ( AminoCdc = codec.NewAminoCodec(amino) ) -const ( - // Protobuf type URL for a consensus tx holding Ethereum transaction msgs. - // Corresponds with [ExtensionOptionsEthereumTx]. - TYPE_URL_ETHEREUM_TX = "/eth.evm.v1.ExtensionOptionsEthereumTx" -) - // NOTE: This is required for the GetSignBytes function func init() { RegisterLegacyAminoCodec(amino)