Skip to content

Commit

Permalink
Problem: benchmark logic don't increase nonce (#502)
Browse files Browse the repository at this point in the history
Solution:
- keep the benchmark logic closer to real one, only removing the nonce
  check part
  • Loading branch information
yihuang authored Jul 29, 2024
1 parent f3e62cb commit 3509552
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
18 changes: 10 additions & 8 deletions app/ante/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func canTransfer(ctx sdk.Context, evmKeeper EVMKeeper, denom string, from common
// contract creation, the nonce will be incremented during the transaction execution and not within
// this AnteHandler decorator.
func CheckEthSenderNonce(
ctx sdk.Context, tx sdk.Tx, ak evmtypes.AccountKeeper,
ctx sdk.Context, tx sdk.Tx, ak evmtypes.AccountKeeper, unsafeUnOrderedTx bool,
) error {
for _, msg := range tx.GetMsgs() {
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
Expand All @@ -269,13 +269,15 @@ func CheckEthSenderNonce(
}
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 tx.Nonce() != nonce {
return errorsmod.Wrapf(
errortypes.ErrInvalidSequence,
"invalid nonce; got %d, expected %d", tx.Nonce(), nonce,
)
if !unsafeUnOrderedTx {
// we merged the nonce verification to nonce increment, so when tx includes multiple messages
// with same sender, they'll be accepted.
if tx.Nonce() != nonce {
return errorsmod.Wrapf(
errortypes.ErrInvalidSequence,
"invalid nonce; got %d, expected %d", tx.Nonce(), nonce,
)
}
}

if err := acc.SetSequence(nonce + 1); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions app/ante/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (suite *AnteTestSuite) TestEthNonceVerificationDecorator() {
for _, tc := range testCases {
suite.Run(tc.name, func() {
tc.malleate()
err := ante.CheckEthSenderNonce(suite.ctx.WithIsReCheckTx(tc.reCheckTx), tc.tx, suite.app.AccountKeeper)
err := ante.CheckEthSenderNonce(suite.ctx.WithIsReCheckTx(tc.reCheckTx), tc.tx, suite.app.AccountKeeper, false)

if tc.expPass {
suite.Require().NoError(err)
Expand Down Expand Up @@ -539,12 +539,12 @@ func (suite *AnteTestSuite) TestEthIncrementSenderSequenceDecorator() {

if tc.expPanic {
suite.Require().Panics(func() {
_ = ante.CheckEthSenderNonce(suite.ctx, tc.tx, suite.app.AccountKeeper)
_ = ante.CheckEthSenderNonce(suite.ctx, tc.tx, suite.app.AccountKeeper, false)
})
return
}

err := ante.CheckEthSenderNonce(suite.ctx, tc.tx, suite.app.AccountKeeper)
err := ante.CheckEthSenderNonce(suite.ctx, tc.tx, suite.app.AccountKeeper, false)

if tc.expPass {
suite.Require().NoError(err)
Expand Down
6 changes: 2 additions & 4 deletions app/ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,8 @@ func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler {
return ctx, err
}

if !options.UnsafeUnorderedTx {
if err := CheckEthSenderNonce(ctx, tx, options.AccountKeeper); err != nil {
return ctx, err
}
if err := CheckEthSenderNonce(ctx, tx, options.AccountKeeper, options.UnsafeUnorderedTx); err != nil {
return ctx, err
}

extraDecorators := options.ExtraDecorators
Expand Down

0 comments on commit 3509552

Please sign in to comment.