-
Notifications
You must be signed in to change notification settings - Fork 43
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
) | ||
|
@@ -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())) | ||
for _, msg := range tx.GetMsgs() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only for large batch tx? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use errgroup?