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

Problem: no way to disable nonce checking in benchmark (backport: #495) #541

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading