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: slow VerifyEthSig on large number of messages #518

Closed
wants to merge 1 commit into from
Closed
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
25 changes: 18 additions & 7 deletions app/ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/gogoproto/proto"
ethtypes "github.com/ethereum/go-ethereum/core/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
)
Expand All @@ -29,16 +30,26 @@
// Failure in RecheckTx will prevent tx to be included into block, especially when CheckTx succeed, in which case user
// won't see the error message.
func VerifyEthSig(tx sdk.Tx, signer ethtypes.Signer) error {
errChan := make(chan error, len(tx.GetMsgs()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use errgroup?

for _, msg := range tx.GetMsgs() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yihuang could reduce from 2s to 0.2s for 3k msgs when parallel

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only for large batch tx?

Copy link
Collaborator

@yihuang yihuang Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do this conditionally, so we can avoid extra overhead for normal cases where tx has single msg.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be same for small batch, but I only filter out when CheckTx > 1s

Copy link
Collaborator

@yihuang yihuang Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean at least for tx that has a single msg, this change is pure overhead, no benifit.

msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
if !ok {
return errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil))
}
go func(msg proto.Message) {
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
if !ok {
errChan <- errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil))
return
}

if err := msgEthTx.VerifySender(signer); err != nil {
return errorsmod.Wrapf(errortypes.ErrorInvalidSigner, "signature verification failed: %s", err.Error())
err := msgEthTx.VerifySender(signer)
if err != nil {
err = errorsmod.Wrapf(errortypes.ErrorInvalidSigner, "signature verification failed: %s", err.Error())
}
errChan <- err
}(msg)
Comment on lines +35 to +47

Check notice

Code scanning / CodeQL

Spawning a Go routine Note

Spawning a Go routine may be a possible source of non-determinism
}
for i := 0; i < cap(errChan); i++ {
if err := <-errChan; err != nil {
return err
}
}

return nil
}
Loading