-
Notifications
You must be signed in to change notification settings - Fork 31
chore: merge main to develop post release v2.1.0 #1273
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
* refactor: added tests for RPC module * Revert "refactor: added tests for RPC module" This reverts commit bac5b3b. * reafctor: added tests for rpc module using httpstest servers * ci: updated artifact version for binary downloads and uploads * ci: fixed ci by updateing action versions * reafctor: replaced ts.cancel() with t.Cleanup(func() { ts1.Close() })
…er (#1264) * fix: switch RPC if block number is less than last recorded block number * refactor: added tests for block module
…ocess (#1269) * refactor: fetched block number from block monitor in voting * refactor: fixed tests * fix: added nil check for header from block monitor * refactor: replaced empty block monitor reference with nil in case of error
…1271) * hotfix: removed getConfigData() call from setConfig command * chore: update version to v2.1.0 * refactor: removed unwanted 'InitializeCommandDependencies()' from import and create command
Releases/v2.1.0
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.
Error during code review: 'NoneType' object is not subscriptable
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.
Error during code review: 'NoneType' object is not subscriptable
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
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.
Error during code review: 'NoneType' object is not subscriptable
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.
🚀 Aldrin's Code Review 🌕
Overall Summary
This PR introduces RPC endpoint switching, stale block detection, and comprehensive testing. Key enhancements include improved fault tolerance in block monitoring and updated CI workflows. The changes align with the goals of boosting reliability and test coverage. Let's dive into the details!
Issues Found
🚨 1. Potential Race Condition in RPCManager Switch (rpc.go)
Code Snippet:
func (m *RPCManager) SwitchToNextBestRPCClient() (bool, error) {
// ...
for i, endpoint := range m.Endpoints {
if endpoint.URL == m.BestEndpoint.URL {
startIdx = i + 1
break
}
}
// Iterate remaining endpoints to find the next best
}
Commentary:
The SwitchToNextBestRPCClient
method isn’t thread-safe. Concurrent calls could lead to inconsistent BestEndpoint
state. In production, this might cause nodes to switch to suboptimal endpoints under high load.
Fix Suggestion:
Wrap the method body with a mutex to ensure atomicity:
var switchMutex sync.Mutex
func (m *RPCManager) SwitchToNextBestRPCClient() (bool, error) {
switchMutex.Lock()
defer switchMutex.Unlock()
// ... existing logic ...
}
🔥 2. Missing Context Cancellation in RPC Client Setup (rpc.go)
Code Snippet:
ctx, cancel := context.WithTimeout(...)
client, err := ethclient.DialContext(ctx, nextEndpoint.URL)
if err != nil {
cancel()
// ...
}
// ... block fetch ...
cancel()
Commentary:
🔥 Critical (3/5)
Calling cancel()
only on error risks leaving the context active if the block fetch succeeds but later operations hang. This could lead to resource leaks.
Fix Suggestion:
Use defer cancel()
immediately after context creation:
ctx, cancel := context.WithTimeout(...)
defer cancel()
// ... rest of the code ...
⚠️ 3. Unvalidated Block Header in Vote Logic (vote.go)
Code Snippet:
latestHeader := blockMonitor.GetLatestBlock()
if latestHeader == nil {
log.Error("Block monitor returned nil header")
continue
}
Commentary:
While nil checks are present, a nil header could stall voting indefinitely. Add a retry-with-timeout mechanism to recover from transient monitor failures.
Fix Suggestion:
retries := 3
for i := 0; i < retries; i++ {
latestHeader := blockMonitor.GetLatestBlock()
if latestHeader != nil {
break
}
time.Sleep(2 * time.Second)
}
if latestHeader == nil {
return errors.New("failed to fetch block after retries")
}
⚠️ 4. Hardcoded Context Timeout in RPC Manager (rpc.go)
Code Snippet:
ctx, cancel := context.WithTimeout(context.Background(), core.EndpointsContextTimeout*time.Second)
Commentary:
The timeout is hardcoded via core.EndpointsContextTimeout
. If this value isn’t configurable, operators can’t adjust it for varying network conditions.
Fix Suggestion:
Make the timeout configurable via environment variables or CLI parameters.
Reviewed Files
block.go
,rpc.go
,propose.go
,vote.go
,cmd-utils.go
- CI files:
ci.yml
,develop.yml
,release.yml
- Tests:
block_test.go
,rpc_test.go
,propose_test.go
Positive Feedback
🌈 Well Done!
- Tests: The
block_test.go
andrpc_test.go
are stellar! Mock servers and atomic counters for RPC switching? Brilliant. - Stale Handling: The block monitor’s RPC failover logic is clean and production-grade.
- Safety Checks: Adding validation in
propose.go
for proposed blocks count is a proactive move against index errors 👏.
Keep those tests coming—they’re the astronaut’s safety harness! 👨🚀🔗
Review generated by: perplexity/r1-1776
User description
Description
Merging main to develop post releasing v2.1.0.
PR Type
Enhancement, Bug fix, Tests, CI/CD
Description
Enhanced block monitoring with RPC endpoint switching and stale block detection.
Fixed bugs in command dependency initialization and block fetching logic.
Added comprehensive tests for block monitoring and RPC manager functionality.
Updated CI workflows to use newer action versions and improved artifact handling.
Changes walkthrough 📝
28 files
Add RPC endpoint switching and stale block detection
Update command dependencies to include block monitor
Update command dependencies to include block monitor
Update command dependencies to include block monitor
Modify InitializeCommandDependencies to return block monitor
Update command dependencies to include block monitor
Update command dependencies to include block monitor
Simplify command dependencies for create command
Update command dependencies to include block monitor
Update command dependencies to include block monitor
Update command dependencies to include block monitor
Simplify command dependencies for import command
Update command dependencies to include block monitor
Update interface to include block monitor in voting
Update command dependencies to include block monitor
Update command dependencies to include block monitor
Update command dependencies to include block monitor
Simplify command dependencies for setConfig command
Update command dependencies to include block monitor
Update command dependencies to include block monitor
Update command dependencies to include block monitor
Update command dependencies to include block monitor
Update command dependencies to include block monitor
Update command dependencies to include block monitor
Update command dependencies to include block monitor
Update command dependencies to include block monitor
Integrate block monitor into voting logic
Improve RPC endpoint switching logic
5 files
Add tests for block monitoring logic
Update mocks to include block monitor in voting
Add test for proposed blocks count mismatch
Update tests for voting logic with block monitor
Add tests for RPC manager functionality
1 files
Add validation for proposed blocks count
1 files
Update version to 2.1.0
3 files
Update CI workflows to use newer action versions
Update CI workflows to use newer action versions
Update CI workflows to use newer action versions