Skip to content

Conversation

@Chaitu-Tatipamula
Copy link
Contributor

Fix: Prevent duplicate piece IDs in schedulePieceDeletions

Problem

The schedulePieceDeletions function didn't check for duplicate piece IDs, allowing the same piece to be scheduled for removal multiple times. This could happen within a single call or across multiple calls.

Changes

  • Added isScheduledForRemoval mapping for O(1) lookups for duplicate checking
  • Updated schedulePieceDeletions to validate against existing scheduled removals
  • Added mapping cleanup in nextProvingPeriod to prevent stale state
  • Added comprehensive test coverage for duplicate prevention

Tests

  • testSchedulePieceDeletionsDuplicatePrevention: Verifies duplicate detection works for both within-call and cross-call scenarios
  • testMappingClearedAfterRemoval: Ensures mapping is properly cleared after removals are processed
  • All existing tests continue to pass

Fixes #227

- Add descriptive names to mapping keys for better readability
- Optimize array processing by copying elements and deleting entire array
- Replace individual pop() calls with bulk array deletion
@rjan90 rjan90 requested a review from Kubuxu October 24, 2025 07:01
@rjan90 rjan90 moved this to 🔎 Awaiting review in PDP Oct 24, 2025
@Kubuxu Kubuxu force-pushed the fix/duplicate-piece-id-prevention branch from c9b4cb5 to bdb1ce7 Compare October 24, 2025 13:23
Also add a redudant but explicit case that zero sized pieces won't be
added to the data set

Signed-off-by: Jakub Sztandera <[email protected]>
@Kubuxu Kubuxu force-pushed the fix/duplicate-piece-id-prevention branch from bdb1ce7 to fa640b3 Compare October 24, 2025 13:23
@Kubuxu
Copy link
Collaborator

Kubuxu commented Oct 24, 2025

Hey, @Chaitu-Tatipamula, I pushed two commits, one of which removes the whole slots when clearing out the list.
The second one doesn't allow the addition of non-live pieces into the list (across multiple proving instances).

Copy link
Collaborator

@Kubuxu Kubuxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGWM, but would like a second set of eyes from @wjmelements given that I pushed some code into this branch

// This is a redudant check as Cids.isPaddingExcessive already checks for pieces which would result in leafCount == 0
// but we keep it here for clarity
revert IndexedError(callIdx, "Leaf count of the pieece must be greater than 0");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm for removing redundant checks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They become untestable branches in the codecoverage

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added it because I spent a good 15 minutes verifying that it is actually true.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I get that, hmmm

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can leave your comment about the assumption to preserve your hard work

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the redundant check and just improved docstrings.

@Kubuxu Kubuxu merged commit 186a1ba into FilOzone:main Oct 24, 2025
3 checks passed
@github-project-automation github-project-automation bot moved this from 🔎 Awaiting review to 🎉 Done in PDP Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🎉 Done

Development

Successfully merging this pull request may close these issues.

schedulePieceDeletions doesn't check for duplicate piece IDs

4 participants