refactor(lru): switch LRU implementation to golang-lru#3674
Open
brbrr wants to merge 3 commits into
Open
Conversation
Rationale is that LRU returns a error if the size is <= 0, and in our case, all the size parameters are comptime known constants, so discarding a error is fine at the moment, but panics (hopefully) protect us in the future in case of mis-use
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the codebase’s LRU cache usage to rely on github.com/hashicorp/golang-lru/v2 (and simplelru) instead of the previous go-ethereum LRU helpers, centralizing construction logic in utils.
Changes:
- Added
utils.NewLRUandutils.NewSimpleLRUhelpers to standardize LRU construction. - Migrated RPC trace caches and pending pre-latest caching to HashiCorp LRU implementations.
- Updated aggregated bloom filter cache to use the new LRU and adjusted its constructor/tests accordingly.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| utils/lru.go | Introduces shared constructors for thread-safe and non-thread-safe LRU caches. |
| sync/pending_polling.go | Switches the pre-latest “seen-by-parent” cache to simplelru via utils.NewSimpleLRU. |
| rpc/v8/handlers.go | Updates RPC v8 handler trace cache construction to use utils.NewLRU. |
| rpc/v9/handlers.go | Updates RPC v9 handler trace cache construction to use utils.NewLRU. |
| rpc/v10/handlers.go | Updates RPC v10 handler trace cache construction to use utils.NewLRU. |
| blockchain/aggregated_bloom_filter_cache.go | Replaces the previous LRU cache with HashiCorp’s cache and uses utils.NewLRU; changes constructor signature. |
| blockchain/blockchain.go | Adjusts blockchain initialization to match the aggregated bloom cache constructor change. |
| blockchain/aggregated_bloom_filter_cache_test.go | Updates tests to use the new aggregated bloom cache constructor and constant size. |
| go.mod | Adds github.com/hashicorp/golang-lru/v2 as a direct dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3674 +/- ##
==========================================
+ Coverage 76.16% 76.30% +0.14%
==========================================
Files 396 397 +1
Lines 36585 36540 -45
==========================================
+ Hits 27865 27882 +17
+ Misses 6743 6681 -62
Partials 1977 1977 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.