-
Notifications
You must be signed in to change notification settings - Fork 234
refactor: try CN approach #2812
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
base: marko/p2p_refactor
Are you sure you want to change the base?
Conversation
|
Claude finished @tac0turtle's task —— View job Comprehensive Code Review: P2P RefactoringI've completed a thorough review of this PR which removes the notifier pattern and simplifies the P2P synchronization architecture. This is a significant refactoring with +246/-1351 lines across 14 files. Executive SummaryOverall Assessment: ✅ Strong refactoring that significantly simplifies the codebase while maintaining functionality. The removal of 663 lines from the notifier package and consolidation of logic is a clear improvement. However, there are several areas requiring attention around error handling, concurrency safety, and resource management. Key Changes:
1. Code Quality & Architecture
|
|
The latest Buf updates on your PR. Results from workflow CI and Release / buf-check (pull_request).
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## marko/p2p_refactor #2812 +/- ##
======================================================
+ Coverage 64.33% 64.47% +0.14%
======================================================
Files 81 80 -1
Lines 7250 7153 -97
======================================================
- Hits 4664 4612 -52
+ Misses 2044 2005 -39
+ Partials 542 536 -6
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:
|
|
I generally prefer this over the notifer and current main. The simplification makes sense to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice work. Much cleaner code and easier to follow.
With the changes, I believe that we can reduce heightInCh size to save some memory.
The P2P loop can only move 1 message ahead of the consumer now.
| } | ||
|
|
||
| if waitCtx.Err() == nil { | ||
| logger.Warn().Err(err).Uint64("height", targetHeight).Msg("P2P handler failed to process height") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would assume that we run into this quite often when the height is not available, yet. IMHO it is worth to ignore the not found error
| s.p2pWaitMu.Lock() | ||
| defer s.p2pWaitMu.Unlock() | ||
|
|
||
| if s.p2pWaitState.cancel != nil && (height == 0 || s.p2pWaitState.height == height) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO it would be safe to cancel p2pWaitState.height <= height, just in case p2p is falling behind
|
|
||
| func (s *Syncer) clearP2PWaitState(height uint64) { | ||
| s.p2pWaitMu.Lock() | ||
| if s.p2pWaitState.height == height { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering, is the height important? There should not be concurrent calls
|
|
||
| err = s.p2pHandler.ProcessHeight(waitCtx, targetHeight, s.heightInCh) | ||
| s.clearP2PWaitState(targetHeight) | ||
| cancel() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personal preference: cancelP2PWait could be used to clear the state
| } | ||
|
|
||
| // Cancel any P2P wait that might still be blocked on this height | ||
| s.cancelP2PWait(height) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it also make sense to cancel in the error case? We have the block in the cache now. 🤔 But the p2p handler height was not updated so it would return the block again
Overview