diff --git a/app/ante/eth.go b/app/ante/eth.go index dfa8dc9347..5f78f414ed 100644 --- a/app/ante/eth.go +++ b/app/ante/eth.go @@ -311,12 +311,15 @@ func canTransfer(ctx sdk.Context, evmKeeper EVMKeeper, denom string, from common // EthIncrementSenderSequenceDecorator increments the sequence of the signers. type EthIncrementSenderSequenceDecorator struct { ak evmtypes.AccountKeeper + + unsafeUnOrderedTx bool } // NewEthIncrementSenderSequenceDecorator creates a new EthIncrementSenderSequenceDecorator. -func NewEthIncrementSenderSequenceDecorator(ak evmtypes.AccountKeeper) EthIncrementSenderSequenceDecorator { +func NewEthIncrementSenderSequenceDecorator(ak evmtypes.AccountKeeper, unsafeUnOrderedTx bool) EthIncrementSenderSequenceDecorator { return EthIncrementSenderSequenceDecorator{ - ak: ak, + ak: ak, + unsafeUnOrderedTx: unsafeUnOrderedTx, } } @@ -344,14 +347,15 @@ func (issd EthIncrementSenderSequenceDecorator) AnteHandle(ctx sdk.Context, tx s ) } nonce := acc.GetSequence() - - // we merged the nonce verification to nonce increment, so when tx includes multiple messages - // with same sender, they'll be accepted. - if txData.GetNonce() != nonce { - return ctx, errorsmod.Wrapf( - errortypes.ErrInvalidSequence, - "invalid nonce; got %d, expected %d", txData.GetNonce(), nonce, - ) + if !issd.unsafeUnOrderedTx { + // we merged the nonce verification to nonce increment, so when tx includes multiple messages + // with same sender, they'll be accepted. + if txData.GetNonce() != nonce { + return ctx, errorsmod.Wrapf( + errortypes.ErrInvalidSequence, + "invalid nonce; got %d, expected %d", txData.GetNonce(), nonce, + ) + } } if err := acc.SetSequence(nonce + 1); err != nil { diff --git a/app/ante/eth_test.go b/app/ante/eth_test.go index 134ccfd680..64026ad2b9 100644 --- a/app/ante/eth_test.go +++ b/app/ante/eth_test.go @@ -106,7 +106,7 @@ func (suite *AnteTestSuite) TestNewEthAccountVerificationDecorator() { func (suite *AnteTestSuite) TestEthNonceVerificationDecorator() { suite.SetupTest() - dec := ante.NewEthIncrementSenderSequenceDecorator(suite.app.AccountKeeper) + dec := ante.NewEthIncrementSenderSequenceDecorator(suite.app.AccountKeeper, false) addr := tests.GenerateAddress() @@ -408,7 +408,7 @@ func (suite *AnteTestSuite) TestCanTransferDecorator() { } func (suite *AnteTestSuite) TestEthIncrementSenderSequenceDecorator() { - dec := ante.NewEthIncrementSenderSequenceDecorator(suite.app.AccountKeeper) + dec := ante.NewEthIncrementSenderSequenceDecorator(suite.app.AccountKeeper, false) addr, privKey := tests.NewAddrKey() contract := evmtypes.NewTxContract(suite.app.EvmKeeper.ChainID(), 0, big.NewInt(10), 1000, big.NewInt(1), nil, nil, nil, nil) diff --git a/app/ante/handler_options.go b/app/ante/handler_options.go index 2e6933a829..d30b7ceae7 100644 --- a/app/ante/handler_options.go +++ b/app/ante/handler_options.go @@ -47,6 +47,9 @@ type HandlerOptions struct { DisabledAuthzMsgs []string ExtraDecorators []sdk.AnteDecorator PendingTxListener PendingTxListener + + // see #494, just for benchmark, don't turn on on production + UnsafeUnorderedTx bool } func (options HandlerOptions) validate() error { @@ -84,7 +87,7 @@ func newEthAnteHandler(ctx sdk.Context, options HandlerOptions, extra ...sdk.Ant NewEthAccountVerificationDecorator(options.AccountKeeper, options.EvmKeeper, evmDenom), NewCanTransferDecorator(options.EvmKeeper, baseFee, &evmParams, ethCfg), NewEthGasConsumeDecorator(options.EvmKeeper, options.MaxTxGasWanted, ethCfg, evmDenom, baseFee), - NewEthIncrementSenderSequenceDecorator(options.AccountKeeper), // innermost AnteDecorator. + NewEthIncrementSenderSequenceDecorator(options.AccountKeeper, options.UnsafeUnorderedTx), // innermost AnteDecorator. NewGasWantedDecorator(options.FeeMarketKeeper, ethCfg), NewEthEmitEventDecorator(options.EvmKeeper), // emit eth tx hash and index at the very last ante handler. }