-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
feat: cache for signature verification #18422
Conversation
Warning Rate Limit Exceeded@tac0turtle has exceeded the limit for the number of files or commits that can be reviewed per hour. Please wait 2 minutes and 47 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the @coderabbitai review command. Alternatively, push new commits to this PR. We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. WalkthroughThe changes involve the implementation of a Changes
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on X ? TipsChat with CodeRabbit Bot (
|
c37023f
to
d6f5195
Compare
rocksdb is failing to build because nix adds thousands of lines, cant make it work properly |
This comment has been minimized.
This comment has been minimized.
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.
Review Status
Actionable comments generated: 4
Configuration used: CodeRabbit UI
Files selected for processing (2)
- x/auth/CHANGELOG.md (1 hunks)
- x/auth/signing/cache.go (1 hunks)
Additional comments: 3
x/auth/CHANGELOG.md (1)
- 34-34: The summary states there are no modifications to function signatures, which is inconsistent with the changelog entry that documents a new parameter for
NewSigVerificationDecorator
. This is an API breaking change and should be reflected accurately in the summary.x/auth/signing/cache.go (2)
17-28: The
NewSignatureCache
function is designed to be called once to initialize the cache. Ensure that this behavior is documented and understood by the developers to prevent multiple initializations.59-65: The
validate
method currently only checks for an empty string. Consider if additional validation is needed for keys, such as length or format constraints, depending on the use case.
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.
Review Status
Actionable comments generated: 3
Configuration used: CodeRabbit UI
Files selected for processing (4)
- crypto/types/cache.go (1 hunks)
- x/auth/ante/sigverify.go (2 hunks)
- x/auth/signing/bench_test.go (1 hunks)
- x/auth/signing/verify.go (4 hunks)
Additional comments: 7
crypto/types/cache.go (1)
- 12-83: The code does not show any synchronization mechanisms for the
Cache
methods, which could lead to race conditions if accessed concurrently. The summary mentions the use ofsync.Once
for thread safety, but it is not visible in the provided code. Please ensure that the cache is thread-safe if it is intended to be accessed from multiple goroutines.x/auth/ante/sigverify.go (4)
229-246: The addition of the
cacheVerification
field and the conditional initialization of thecryptotypes.Cache
in theNewSigVerificationDecorator
function are correctly implemented to support the new signature caching feature.234-234: Verify that the
cryptotypes.Cache
is implemented using an LRU strategy as mentioned in the summary, and ensure it is compatible with thehashicorp/golang-lru/v2
package.383-383: The update to the
authsigning.VerifySignature
function call to include thecacheVerification
parameter aligns with the new caching mechanism.237-237: Ensure that the
NewAnteHandler
function is updated to pass the appropriate boolean value toNewSigVerificationDecorator
to enable or disable signature caching as intended.x/auth/signing/bench_test.go (2)
204-228: The benchmark test
BenchmarkVerifySignature
correctly includes the new cache parameter in theVerifySignature
function call, which aligns with the changes described in the summary.179-192: The mismatched signature test cases are intentionally designed to produce a bad signature mismatch, and the linter changes have been addressed as per the existing comments.
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.
Looks good, left a few comments 👍
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.
Some superfulous comments we can remove, but otherwise, LGTM! Nice work @tac0turtle
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.
Review Status
Actionable comments generated: 4
Configuration used: CodeRabbit UI
Files selected for processing (4)
- crypto/types/cache.go (1 hunks)
- x/auth/ante/sigverify.go (2 hunks)
- x/auth/signing/bench_test.go (1 hunks)
- x/auth/signing/verify.go (4 hunks)
Additional comments: 5
x/auth/ante/sigverify.go (2)
229-254: The
SigVerificationDecorator
struct andNewSigVerificationDecorator
function have been updated to include acacheVerification
field and parameter, respectively. This aligns with the PR's objective to introduce a caching mechanism for signature verification. ThecacheVerification
field is of type*cryptotypes.SignatureCache
, which suggests that it is a pointer to a cache object. TheNewSigVerificationDecorator
function initializes this cache if thecacheVerification
parameter istrue
. The use ofpanic
in the error handling ofcryptotypes.NewSignatureCache()
is appropriate here because it's a critical error that should not occur during normal operation, and if it does, it indicates a non-recoverable error that should stop the program execution.386-392: The
AnteHandle
method ofSigVerificationDecorator
has been updated to include the use of the signature cache when verifying signatures. Theauthsigning.VerifySignature
function now accepts thecacheVerification
field as an argument. This change is crucial for the performance improvement targeted by the PR, as it allows for the reuse of signature verification results, reducing the computational overhead of redundant checks. The error handling within this method is robust, providing clear error messages that include account number, sequence, and chain-id when signature verification fails. This is important for debugging and user feedback.x/auth/signing/bench_test.go (3)
209-210: The code correctly initializes the new
SignatureCache
and checks for errors, which aligns with the PR's objective to introduce a caching mechanism for signature verification.180-193: The test cases for mismatched signatures are still present, which is consistent with the previous review comments that intentional mismatches were used to produce bad signature errors for testing purposes.
205-230: The
BenchmarkVerifySignature
function has been updated to include the new signature cache in the benchmark tests, which is in line with the PR's objective and the AI-generated summary.
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.
lgtm, I left a single comment
@@ -20,6 +20,7 @@ type HandlerOptions struct { | |||
SignModeHandler *txsigning.HandlerMap | |||
SigGasConsumer func(meter storetypes.GasMeter, sig signing.SignatureV2, params types.Params) error | |||
TxFeeChecker TxFeeChecker | |||
Cachesignature bool |
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.
Cachesignature bool | |
CacheSignature bool |
|
||
// sigkey is the key used to store the signature in the cache | ||
type sigkey struct { | ||
signbytes []byte |
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.
signbytes []byte | |
signBytes []byte |
return pubKey.VerifySignature(signBytes, sig) | ||
} | ||
|
||
bz := cryptotypes.NewSigKey(signBytes, sig).String() |
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.
bz := cryptotypes.NewSigKey(signBytes, sig).String() | |
sigKey := cryptotypes.NewSigKey(signBytes, sig).String() |
} | ||
|
||
// Add adds a signature to the cache | ||
func (c *SignatureCache) Add(key string, value []byte) { |
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.
My only gripe with this is that I think Add
should actually take a cryptotypes.SIgKey
as an argument instead of a string
. The reason I recommend this is that the SignatureCache
doesn't really pertain to a signature cache, the API suggests it can be used for any [string,[]byte] mapping. So I'd recommend either changing the argument.
Note, this isn't to block, but just a suggestion.
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Description
Closes: #15780
This pr adds a cache for signature verification. Since signature verification is one of, if not the most expensive part in the antehandler, caching sig verification to avoid checking it twice lends to greater performance. I set the cache size at 500, this only adds a potential for 37.5KB in size.
I did not set the signature verification cache to the multisig to avoid extra imports in auth, and since onchain multisigs are around the corner
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
make lint
andmake test
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change