hyperlane-xyz / hyperlane-monorepo

The home for Hyperlane core contracts, sdk packages, and other infrastructure
https://hyperlane.xyz
Other
308 stars 339 forks source link

Caching middleware to reduce RPC provider utilization #1304

Open mattiekat opened 1 year ago

mattiekat commented 1 year ago

Create a new middleware that wraps the Quorum provider and caches certain things such as last_block_number for a period of time and joins duplicate queries in a short period into a single future. The goal would be to dedup any queries which we know must have the same answer and to reduce the queries that don't change rapidly.

mattiekat commented 1 year ago

I did play around with doing something along these lines a while ago. My main warning for anyone implementing this is that you will need some form of static state that is tracked for a given URL. Some queries will be cacheable, some will not be.

Things like backoffs can be respected globally this way (429 Too Many Requests cases), and should be a goal of this ticket. Ideally this is not just to reduce RPC calls but to reduce thrash when the provider is in a transient failure state.

Actually, now that I think about it, it might no longer require static state because I think we are creating only a single provider instance per chain in the omniscient relayer.