add guard to avoid underflow and deleting needed nodesConfig#7908
Conversation
There was a problem hiding this comment.
Pull request overview
This PR prevents an unsigned integer underflow in removeOlderEpochs when epoch < maxDelta, which previously could cause unintended deletion of nodesConfig entries. It also adds focused unit tests to lock in the expected retention behavior for early epochs and normal pruning.
Changes:
- Added a guard in
removeOlderEpochsto avoidepoch - maxDeltaunderflow and to prevent erroneous deletions. - Refactored the deletion threshold into an
epochToRemovevariable for clarity. - Added unit tests covering the “epoch < maxDelta” no-op case and the normal “remove only older epochs” case.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| sharding/nodesCoordinator/indexHashedNodesCoordinatorLite.go | Adds an early return to avoid underflow and uses a precomputed epochToRemove for correct pruning. |
| sharding/nodesCoordinator/indexHashedNodesCoordinatorLite_test.go | Adds tests validating no removals for early epochs and correct removal of only the oldest epoch once the delta threshold is reached. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## feat/testnet-fixes #7908 +/- ##
===================================================
Coverage 77.69% 77.70%
===================================================
Files 885 885
Lines 126020 126023 +3
===================================================
+ Hits 97914 97921 +7
+ Misses 21626 21624 -2
+ Partials 6480 6478 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Reasoning behind the pull request
Proposed changes
Testing procedure
Pre-requisites
Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:
featbranch created?featbranch merging, do all satellite projects have a proper tag insidego.mod?