prysm icon indicating copy to clipboard operation
prysm copied to clipboard

Committees cache rework (remove double lock)

Open v4lproik opened this issue 1 year ago • 0 comments

What type of PR is this?

  • Enhancement

What does this PR do? Why is it needed?

  • This PR reworks the beacon-chain caches implementation by leveraging the latest lru/v2 from Hashicorp.
  • It removes the "double lock" case where the BN locks the mutex in the caller (here, committee cache) and in the cache library.
  • It provides better readability, fewer type assertions, and avoids using the pattern interface{} as a function argument.
  • Better API: the cache key (the "seed") cannot be passed as a string in some methods or a [32]byte in others. Thus, the generation of the cache key stays in the caller.
  • It is more resilient as it prevents the case where a caller tries to insert a key associated with a nil value into the cache. This will ultimately result in less bugs / checks between the callers and the cache.
  • It enforces the use of "miss" and "hit" metrics across for the caches implementing the private interface LRUCache for better fine performance tuning. Also, it avoids the caller to manually handle the hit or miss increment itself making all the caches implementing the private interface to have the same behaviour.

Which issues(s) does this PR fix? #13723

Other notes for review I will keep opening PRs for the other caches (hashicorp lru) once the implementation is reviewed and accepted by the team. Referencing this PR #13794

v4lproik avatar Mar 27 '24 11:03 v4lproik