-
Notifications
You must be signed in to change notification settings - Fork 4
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
Fix caching eth calls #731
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.
uACK
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 don't think we even need to call isWithdrawalEthCall
within the resolver. If the calls are made through an SDK/library, those will have the proper structure.
It is a minor safeguard to avoid trying to |
65089b8
to
fa1de87
Compare
After discussing online with @gabmontes , I proceed to remove the |
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
Description
It's been a while since I've noticed that the caching wasn't properly working for the RPC calls for withdrawals. I took some time to debug and found the bug. This PR fixes this, so the
eth_call
methods that we defined some time ago as cacheable can be cached again.Context
The process of syncing deposits and withdrawals requires lots of requests. Many of them can be cached at block level, and some of them can be cached in memory as long as the user doesn't close the tab.
Many of the requests are run in the form of an
eth_call
, so the request body looks like thisThat
data
field maps to callingversion()
in the bridge contract (The data field is the hash that comes from doingkeccak256(toHex('version()')).slice(0, 10))
Some time ago, I defined (with Gabriel's help) some methods to be cached - the list can be found here.
There's an in-memory object that indexes a strategy for each method that states how long a response should be stored (Basically, per-block basis or permanently)
The bug
The cache was not working
Root cause
In order to cache only those methods in the list, there was this method
which verifies the
eth_call
is indeed aneth_call
. However, this check had a problem, which becomes evident by looking at the viem's source code of isHash() function:~~The function returns
true
if the string is ahex
string and if size (do not confuse with length) is 32...This is valid for Transaction hashes, but not for the hashes of
eth_call
!! As these are hashes (in the sense of computational hashes) but not transaction hashes from the blockchain.. (you can check the body of theeth_call
again above)This also means that the caching never worked properly 🤦🏽
The solution
The correct check was to verify that the string was a hex usingisHex(data)
, instead of usingisHash(data)
As the library
eth-rpc-cache
ensures onlyeth_call
are forwarded to the strategy, and alleth_call
have the same structure (with thedata
field), we can remove the functionisWithdrawalEthCall
altogether, so the buggy code doesn't execute anymorecacheProvider
outside ofui-common
, again, in another effort of completely removingui-common
package (As this is only used by the Portal)Screenshots
No changes are visible to the user... though now many requests are cached and will be skipped 🎉
Checklist