refactor(syncer,cache): use compare and swap loop and add comments#2873
refactor(syncer,cache): use compare and swap loop and add comments#2873julienrbrt merged 9 commits intomainfrom
Conversation
|
Claude finished @julienrbrt's task —— View job Code Review Complete ✓SummaryThis PR implements a fix for cache entry management and refactors DA height tracking in the syncer. The changes improve code clarity and fix a race condition in atomic operations. Overall, the changes are solid with good test coverage improvements. Key Changes
Detailed Findings1. Code Quality & Architecture ✅Strengths:
Observations:
2. Error Handling & Resilience ✅Strengths:
Observations:
3. Security 🔒No Issues Found:
4. Performance & Resource Efficiency ⚡Improvements:
Concerns:
5. Testing & Reliability ✅Strengths:
Observations:
6. Documentation & Comments 📝Strengths:
Minor Issues:
RecommendationsHigh PriorityNone - the PR is solid. Medium Priority
Low Priority
ConclusionVerdict: ✅ Approved with minor suggestions This PR successfully addresses cache entry management issues and improves code clarity. The atomic operation fix in Changes are production-ready with good test coverage and no breaking changes. The suggestions above are optional improvements that could be addressed in a follow-up PR. |
|
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 #2873 +/- ##
==========================================
+ Coverage 64.94% 64.97% +0.03%
==========================================
Files 81 81
Lines 7262 7250 -12
==========================================
- Hits 4716 4711 -5
+ Misses 2001 1998 -3
+ Partials 545 541 -4
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:
|
alpe
left a comment
There was a problem hiding this comment.
Nice change.
Some tests are still failing.
| require.Len(b, fixt.s.heightInCh, 0) | ||
|
|
||
| assert.Equal(b, spec.heights+daHeightOffset, fixt.s.daHeight) | ||
| assert.Equal(b, spec.heights+daHeightOffset, fixt.s.daRetrieverHeight) |
There was a problem hiding this comment.
| assert.Equal(b, spec.heights+daHeightOffset, fixt.s.daRetrieverHeight) | |
| assert.Equal(b, spec.heights+daHeightOffset, fixt.s.daRetrieverHeight.Load()) |
There was a problem hiding this comment.
have this test ever passed? benchmarks aren't run in CI 😅
|
|
||
| // processLoop is the main coordination loop for processing events | ||
| func (s *Syncer) processLoop() { | ||
| s.wg.Add(1) |
There was a problem hiding this comment.
It is not likely in our use case that start and stop are called immediately but this would cause a race between Add/Wait. The previous version was safe.
There was a problem hiding this comment.
oh true, because this is in the go routine. I was trying to make it consistent with startSyncWorkers
| current := c.maxDAHeight.Load() | ||
| if daHeight >= current { | ||
| _ = c.maxDAHeight.CompareAndSwap(current, daHeight) | ||
| for { |
There was a problem hiding this comment.
personal preference: not likely to loop forever but why not put a reasonable max times here?
There was a problem hiding this comment.
consistency with SetProcessedHeight that uses the same pattern. wouldn't be the max an arbitrary number?
| if daHeight <= current { | ||
| return | ||
| } | ||
| if c.maxDAHeight.CompareAndSwap(current, daHeight) { |
There was a problem hiding this comment.
👍 best effort to store the highest value
| current := c.maxDAHeight.Load() | ||
| if v > current { | ||
| _ = c.maxDAHeight.CompareAndSwap(current, v) | ||
| c.maxDAHeight.Store(v) |
There was a problem hiding this comment.
👍 better!
Could even move this out of the loop and update the value at the end?
* main: refactor(syncer,cache): use compare and swap loop and add comments (#2873)
* 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
Small cleanups, adding more comments to describe cache behavior.
Make sure CompareAndSwap succeeds for da height setting in cache.