-
Notifications
You must be signed in to change notification settings - Fork 31
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: signature verification cache #41
Conversation
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
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
x/auth/ante/sigverify.go
Outdated
if !pubKey.VerifyBytes(sigTx.GetSignBytes(ctx, signerAcc), sig) { | ||
return false | ||
} | ||
svd.txHashCache.Store(sigKey, txHash) |
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.
It seems like some tx's signature will not be removed from the cache if it does not meet DeliverTx
. If the mempool is full, the tx will not be able to enter the mempool after passing checkTx
, so it will not be able to meet DeliverTx
.
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.
You're correct. A tx couldn't be removed from the cache if the tx is not added to mempool
. But I'd like to care it w/ missing transaction
issue. Currently, I assume that the tx must be added to mempool
if it passes checkTx
.
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.
As another approach, we could remove a tx from the cache when we fail to add a tx to mempool.
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.
Another thought, even though we fail to add a tx to mempool after adding it to the cache, it could be removed when same account w/ the same sequence broadcasts a tx again. So, finally after thinking deeply, I have a conclusion that it's not a big deal. Could you agree on it?
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 👍
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.
I am afraid 2 point.
- a cached key may not be removed
-> can we add ttl feature to the cache? - the assumption cause potential fault
-> please see the details in the below comment
I strongly recommend you get a review from @whylee259 before merging it. |
I've thrown During the review, I worried about cache clear logic.
From the mempool logic.
From the Ante Chain
For these two reason, I've clicked the However, after hearing @egonspace's comments, I agree with his opinion. |
I think it's a key topic to discuss.
|
The problem I raised is relatively easy to reproduce. If we fire a large number of txs continuously with a client such as a vulcan after setting the mempool small, it will continue to accumulate signatures in the cache, but txs will fail to reach the |
As I already said, I couldn't agree on it especially on If it's really easy to produce it and impact on the memory, please could you give me an example? I think it might really help me to try to defense it. Thanks! |
If |
No ( |
Isn't that exactly how the |
I don't think so because |
I think we could remove the signature verification cache when a tx is removed from mempool by a |
# Conflicts: # x/auth/ante/sigverify.go
w/ https://github.com/line/link/issues/1153, a tx must be added to mempool if checkTx is passed so we don't need to care of missing tx case any more. The only case that we should revert cache is failure of Please take a look at again. |
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.
Good job!
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
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
* feat: signature verification cache * chore: recover to skip to sigverify * chore: rename `ok` to `exist` of `checkCache()` return var * chore: remove txHashCash if got an error * chore: revise `verifySignatureWithCache()` for readability * chore: remove naked return * fix: lint error Co-authored-by: KIm, JinSan <jinsan@linecorp.com>
Closes: https://github.com/line/link/issues/1135,
https://github.com/line/link/issues/1136Description
txHashCache
as [account_number
:sequence
]:tx_hash
txHashCache
to check whether it's already verified.txHashCache
doesn't have a entry or thetxHash
is not same, we'll verify it again w/VerifyBytes()
When rechecking a tx,SigVerificationDecorator
is executed as well for https://github.com/line/link/issues/1136Motivation and context
Signature verification is cpu intensive task. It could be executed repeatedly for the same transaction so, if we keep the verified the transactions, it could save cpu time and improve the performance.
How has this been tested?
I'll revisecli_test/multi_test.TestMultiValidatorAddNodeAndFailedTransactions()
inlink
for https://github.com/line/link/issues/1136Checklist: