-
Notifications
You must be signed in to change notification settings - Fork 246
refactor: retrieve highest da height in cache #2870
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
Conversation
|
Claude finished @julienrbrt's task —— View job Code Review CompleteI've reviewed the PR "refactor: retrieve highest da height in cache" and analyzed the changes across 6 files. This refactoring improves DA height tracking by caching the maximum DA height atomically rather than iterating through all items. SummaryOverall Assessment: ✅ Approved with Minor Suggestions This is a well-implemented performance optimization that replaces O(n) iteration with O(1) atomic operations for DA height retrieval. The changes are clean, well-tested, and maintain backward compatibility. Detailed Review1. Code Quality & Architecture ✅Strengths:
Observations:
Minor Suggestion: // maxDAHeight tracks the maximum DA height seen
// Cached atomically to avoid O(n) iteration over daIncluded map
maxDAHeight *atomic.Uint642. Error Handling & Resilience ✅Strengths:
Observations:
3. Security ✅No security concerns identified:
4. Performance & Resource Efficiency ⭐ ExcellentMajor Improvement:
Observations:
Potential Concern:
5. Testing & Reliability ✅Strengths:
Test Quality:
Observation: 6. Documentation & Developer Experience ✅Strengths:
Minor Issue: Specific Code Analysisgeneric_cache.go (lines 95-103)// Update max DA height if necessary
current := c.maxDAHeight.Load()
if daHeight >= current {
_ = c.maxDAHeight.CompareAndSwap(current, daHeight)
}Analysis:
generic_cache.go (lines 247-254)for k, v := range daIncludedMap {
c.daIncluded.Store(k, v)
// Update max DA height during load
current := c.maxDAHeight.Load()
if v > current {
_ = c.maxDAHeight.CompareAndSwap(current, v)
}
}Analysis:
for k, v := range daIncludedMap {
c.daIncluded.Store(k, v)
}
// Find and set max DA height in one pass
var maxDA uint64
for _, v := range daIncludedMap {
if v > maxDA {
maxDA = v
}
}
c.maxDAHeight.Store(maxDA)This eliminates CAS contention during load (when there's no concurrency anyway). syncer.go (lines 180, 220)// Line 180
return max(s.daHeight.Load(), s.cache.DaHeight())
// Line 220
s.SetDAHeight(max(s.genesis.DAStartHeight, s.cache.DaHeight()))Analysis:
syncer_test.go (line 436)- require.Equal(t, myFutureDAHeight, syncerInst1.GetDAHeight())
- lastStateDAHeight := syncerInst1.GetLastState().DAHeight
+ require.Equal(t, myFutureDAHeight, syncerInst1.GetDAHeight())Analysis:
RecommendationsHigh Priority: NoneThe PR is production-ready as-is. Medium Priority
Low Priority
ConclusionThis is a high-quality refactoring that delivers a meaningful performance improvement (O(n) → O(1)) while maintaining code clarity and test coverage. The atomic operations are correctly implemented, persistence is handled properly, and the changes integrate cleanly with the existing architecture. The PR is approved for merge. The suggestions above are minor optimizations that could be addressed in a follow-up if desired. Files Reviewed
|
|
The latest Buf updates on your PR. Results from workflow CI / buf-check (pull_request).
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2870 +/- ##
==========================================
+ Coverage 64.80% 64.83% +0.02%
==========================================
Files 81 81
Lines 7243 7254 +11
==========================================
+ Hits 4694 4703 +9
- Misses 2005 2007 +2
Partials 544 544
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
* main: chore: fix some comments (#2874) chore: bump node in evm-single (#2875) refactor(syncer,cache): use compare and swap loop and add comments (#2873) refactor: use state da height as well (#2872) refactor: retrieve highest da height in cache (#2870) chore: change from event count to start and end height (#2871)
Overview
Retrieve highest da height in cache.
We should still remove DaHeight from state to avoid confusion.Actually we should keep it, to have a fallback in case of user errors.