Skip to content

Commit

Permalink
Problem: no way to disable nonce checking in benchmark (backport: #495)…
Browse files Browse the repository at this point in the history
… (#541)

* Problem: no way to disable nonce checking in benchmark

* test
  • Loading branch information
mmsqe authored Oct 10, 2024
1 parent 5ed832f commit 36adc9c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
24 changes: 14 additions & 10 deletions app/ante/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions app/ante/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion app/ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
}
Expand Down

0 comments on commit 36adc9c

Please sign in to comment.