-
Notifications
You must be signed in to change notification settings - Fork 17
SHARD-2475 - Problematic Fixes #544
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: dev
Are you sure you want to change the base?
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
let maxConsecutive = 1 // At least 1 if we have any refutes | ||
let currentConsecutive = 1 | ||
|
||
// Iterate through sorted refutes to find all consecutive sequences | ||
for (let i = 1; i < sortedRefutes.length; i++) { | ||
const currentCycle = sortedRefutes[i] | ||
const prevCycle = sortedRefutes[i - 1] | ||
|
||
if (currentCycle === prevCycle + 1) { | ||
// Consecutive with previous cycle | ||
currentConsecutive++ | ||
} else { | ||
// Check if consecutive with next cycle | ||
const nextCycle = sortedRefutes[i + 1] | ||
if (cycle === nextCycle - 1) { | ||
count++ | ||
} else { | ||
break | ||
} | ||
// Gap found, update max and reset current count | ||
maxConsecutive = Math.max(maxConsecutive, currentConsecutive) | ||
currentConsecutive = 1 | ||
} | ||
} | ||
|
||
return count | ||
// Update max with final sequence | ||
maxConsecutive = Math.max(maxConsecutive, currentConsecutive) | ||
|
||
return maxConsecutive |
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.
Suggestion: Initializing maxConsecutive
and currentConsecutive
to 1 can produce incorrect results when sortedRefutes
has only one element, or when there are gaps at the start. Set both variables to 0 and increment only when a sequence is found to avoid overcounting. [possible issue, importance: 8]
let maxConsecutive = 1 // At least 1 if we have any refutes | |
let currentConsecutive = 1 | |
// Iterate through sorted refutes to find all consecutive sequences | |
for (let i = 1; i < sortedRefutes.length; i++) { | |
const currentCycle = sortedRefutes[i] | |
const prevCycle = sortedRefutes[i - 1] | |
if (currentCycle === prevCycle + 1) { | |
// Consecutive with previous cycle | |
currentConsecutive++ | |
} else { | |
// Check if consecutive with next cycle | |
const nextCycle = sortedRefutes[i + 1] | |
if (cycle === nextCycle - 1) { | |
count++ | |
} else { | |
break | |
} | |
// Gap found, update max and reset current count | |
maxConsecutive = Math.max(maxConsecutive, currentConsecutive) | |
currentConsecutive = 1 | |
} | |
} | |
return count | |
// Update max with final sequence | |
maxConsecutive = Math.max(maxConsecutive, currentConsecutive) | |
return maxConsecutive | |
let maxConsecutive = 0 | |
let currentConsecutive = 0 | |
// Iterate through sorted refutes to find all consecutive sequences | |
for (let i = 0; i < sortedRefutes.length; i++) { | |
if (i === 0 || sortedRefutes[i] === sortedRefutes[i - 1] + 1) { | |
currentConsecutive++ | |
} else { | |
maxConsecutive = Math.max(maxConsecutive, currentConsecutive) | |
currentConsecutive = 1 | |
} | |
} | |
// Update max with final sequence | |
maxConsecutive = Math.max(maxConsecutive, currentConsecutive) | |
return maxConsecutive |
PR Type
Bug fix, Enhancement, Tests
Description
Refactored consecutive refutes logic to track maximum streaks
Updated parameter defaults for debug simulation endpoints
Adjusted tests to validate new consecutive refutes calculation
Replaced compressed JSON export with standard JSON for cache
Changes walkthrough 📝
debug.ts
Use max consecutive refutes and update debug simulation defaults
src/debug/debug.ts
getConsecutiveRefutes
withgetMaxConsecutiveRefutes
for nodemetrics.
ProblemNodeHandler.ts
Refactor and rename consecutive refutes logic
src/p2p/ProblemNodeHandler.ts
toJSON
instead oftoCompressedJSON
.getMaxConsecutiveRefutes
.ProblematicNodeCache.ts
Track maximum consecutive refutes in node cache
src/p2p/ProblematicNodeCache.ts
getConsecutiveRefutes
withgetMaxConsecutiveRefutes
.index.test.ts
Update mocks for renamed consecutive refutes function
test/unit/debug/index.test.ts
getMaxConsecutiveRefutes
instead of old function.debug.test.ts
Adjust debug test mocks for refutes function rename
test/unit/src/debug/debug.test.ts
getMaxConsecutiveRefutes
.ProblematicNodeCache.test.ts
Update tests for max consecutive refutes calculation
test/unit/src/p2p/ProblematicNodeCache.test.ts