edr icon indicating copy to clipboard operation
edr copied to clipboard

Write to RPC cache in the background

Open agostbiro opened this issue 1 year ago • 0 comments

Problem

While resolving a write key for the RPC cache we sometimes need to fetch the latest block number. This is now amortized in https://github.com/NomicFoundation/hardhat/pull/4360 by caching the latest block number for the block time duration, but it'd be still preferable not to have to wait for fetching the latest block number before returning the RPC result in case of a cache miss for the latest block number. Writing to disk also has a small overhead, so ideally that'd be avoided as well before returning the RPC result.

Solution

Write to the RPC cache in a background thread. It'll need a refactoring as self will outlive the call method.

Definition of done

The RPC client returns the RPC result before resolving write keys and writing to the RPC cache.

agostbiro avatar Sep 06 '23 09:09 agostbiro