-
Notifications
You must be signed in to change notification settings - Fork 237
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
[Feature] Add a CachedReqwestProvider
to cache RPC requests using a ReqwestProvider
#770
Comments
Could this be a tower layer? Seeing https://docs.rs/tower/latest/tower/ready_cache/cache/struct.ReadyCache.html - cc @mattsse does this work? |
I'm not fully sure I understand how the |
We won't add caching at the This is blocked by #736 (which is pretty straightforward to resolve) Is the use case here making a high volume of requests against specific deep historical states? It sounds like you actually don't want to cache to a file. You want an in-memory cache that is persisted to a file when your program stops? I'm in general not in favor of caching to/from a file directly, as responses get invalidated so regularly, fs access degrades perf, and the target user for alloy doesn't have an archive node and doesn't make queries against the deep state. Would it be enough to have the cache internals be (de)serializable and a way to instantiate the cache with data in it? |
Good point, supportive.
@puma314 basically this means:
|
Yup that sounds great. @prestwich our use-case is that we are querying @gakonst's proposed suggestion looks great to me as a potential devex. |
serialization and fs ops are fallible and cant be reliably used in a Drop. so I wouldnt recommend this approach More broadly tho, a file system-backed cache of finalized responses is not broadly applicable and requires us to make decisions about the user's fs. I am not in favor of including it in the main alloy crates. A memory cache that can be loaded from fs at runtime and serialized to fs on demand is applicable to a lot of users, and could be in the main provider crate. Would that fit your need? Assuming you're running your own infra, the need may also be better served by accessing reth db or staticfiles directly? If running alongside reth, retrieving proofs and then storing them to the file system is duplicating data that's already in the file system, no? |
I've used this method before multiple times for debugging (e.g in MEV Inspect) and it's generally been fine, so I personally don't worry about the fallibility, but OK with doing this as a separate crate.
How should the cache be populated in this case? Still via
Proofs aren't part of the Reth DB, they get generated on the fly, don't think this would work |
A memory cache that can be loaded from
seems totally fine to me. |
SG re: the API above! Confirming that if you
|
Panics in drops cause aborts, so you can do it, but it's not a decision we want to make on behalf of all users, as we don't know what conditions they're running in
instantiation should run through the builder API, so the sketch here is something like:
do you have a ballpark for number of proofs/etc you intend to cache? |
I think we would need low 100s of proofs per block, since it's all accounts/state that was touched during a block. |
so i think actionable steps for implementing this are:
|
Component
provider, pubsub
Describe the feature you would like
For use-cases like
SP1-Reth
orKona
, we often want to execute a (historical) block, but we don't have the entire state in memory and we execute this block with aProviderDb
that fetches accounts, storage, etc. using an RPC. Fetching from the network is slow and often takes minutes for all of the accesses required for an entire block.Often we re-run these blocks to debug things or tune performance, etc. and each time the feedback loop on iteration is very slow because it requires waiting for all the network requests each time. It would be nice to add a very simple caching layer on top of
ReqwestProvider
that can cache the results of RPC calls to a file (or some other easy to set up format) and then first check the cache before sending a network request.This would speed up iteration time for use-cases like
Kona
andSP1-Reth
tremendously.An interface like this might make sense:
In our case, we are usually querying old blocks (not near the tip of the chain), so re-org awareness is not important for our use-case. We just want a really simple caching layer.
Additional context
No response
The text was updated successfully, but these errors were encountered: