Skip to content

Conversation

@parzival1821
Copy link
Contributor

Related Issue

Closes 252 ( Once completed)

Current Progress

I've implemented the updated looping algorithm in validatePayment as described in the issue

  • Replaced the existing loop with new algorithm
  • Convert provenPeriods to a bitmap
  • Remove provenThisPeriod

What I Need Feedback On

Before I continue with the rest of the issue, I'd like to get feedback on my implementation of the looping algorithm.

Since there were no existing tests for this specific part of the code, I want to make sure my approach is correct before implementing the remaining parts of the issue. Also I would love to help you guys write some tests for the same if required

Questions for Maintainers

  • Does the new looping logic match what you had in mind?
  • Are there any edge cases I should consider?
  • Any suggestions for improvement before I move forward?

Changes Made

  • Modified FilecoinWarmStorageService.sol to implement the new loop structure

Next Steps (after approval)

Once you confirm this approach is correct, I'll:

Note: This is a WIP/Draft PR specifically for early feedback on the algorithm implementation.
(Also, just a heads-up, I changed my username from dev-n-dough to parzival1821

@FilOzzy FilOzzy added this to FS Oct 8, 2025
@github-project-automation github-project-automation bot moved this to 📌 Triage in FS Oct 8, 2025
@parzival1821
Copy link
Contributor Author

@wjmelements @rjan90 Would love to get your thoughts on this draft PR

@rjan90 rjan90 moved this from 📌 Triage to 🔎 Awaiting review in FS Oct 8, 2025
@rjan90 rjan90 linked an issue Oct 8, 2025 that may be closed by this pull request
@rjan90 rjan90 added this to the M4: Filecoin Service Liftoff milestone Oct 8, 2025
@parzival1821
Copy link
Contributor Author

Some workflow checks are failing, sorry about that, let me just fix them real quick

@github-project-automation github-project-automation bot moved this from 🔎 Awaiting review to ⌨️ In Progress in FS Oct 8, 2025
@parzival1821 parzival1821 force-pushed the validate-payment-loop branch from bf33be6 to 54d5f4d Compare October 9, 2025 10:52
@wjmelements
Copy link
Contributor

Please add some tests to check the edge cases, verifying that the IValidator.validatePayment behavior is the same as before.

@parzival1821
Copy link
Contributor Author

I am fixing some issues, will soon start writing the tests. Will push my commits soon

@wjmelements
Copy link
Contributor

wjmelements commented Oct 16, 2025

Are you able to finish this week? We are planning to code freeze this repo Friday and we want to include this change.

@parzival1821
Copy link
Contributor Author

@wjmelements I am actively working on this issue and will try my best to finish it this week

@wjmelements
Copy link
Contributor

Looks like you did a bad merge and reverted a bunch of our recent changes by mistake.

@parzival1821
Copy link
Contributor Author

Yes I think something went wrong with the rebasing, I am trying to fix that

@parzival1821 parzival1821 force-pushed the validate-payment-loop branch from ec22cb9 to ab96798 Compare October 17, 2025 08:01
@rjan90
Copy link
Collaborator

rjan90 commented Oct 17, 2025

@parzival1821 Some smaller Lint Check failures to fix up here

@parzival1821
Copy link
Contributor Author

Working on the tests now, will push soon

@rjan90
Copy link
Collaborator

rjan90 commented Oct 17, 2025

Great! Let us know when it is ready for another round of review - we will try to get these changes across the line today

@parzival1821
Copy link
Contributor Author

Hi @rjan90 @wjmelements I have added the tests and made a few changes to the algorithm. One thing which is kind of unusual is that in the tests, is that I am using uint256 activationEpoch = block.number , but upon using vm.roll , the block.number is changing as expected, but the activationEpoch variable is also getting updated. I will further look into this, but for now I have assigned uint256 activationEpoch = 1 since block number in foundry test starts from 1. The tests are passing and the algo is working as expected

Please review my changes and lmk is any changes/improvement is required!

@wjmelements
Copy link
Contributor

I am using uint256 activationEpoch = block.number , but upon using vm.roll , the block.number is changing as expected, but the activationEpoch variable is also getting updated. I will further look into this, but for now I have assigned uint256 activationEpoch = 1 since block number in foundry test starts from 1. The tests are passing and the algo is working as expected

In forge tests, use vm.getBlockNumber() instead of block.number

@parzival1821 parzival1821 force-pushed the validate-payment-loop branch from 17eee48 to 01555fe Compare October 21, 2025 18:26
Copy link
Contributor

Choose a reason for hiding this comment

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

you still haven't reverted your changes to the submodules

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, fixed it now

@github-project-automation github-project-automation bot moved this from 🔎 Awaiting review to ✔️ Approved by reviewer in FS Oct 22, 2025
@wjmelements wjmelements merged commit af644df into FilOzone:main Oct 22, 2025
6 checks passed
@github-project-automation github-project-automation bot moved this from ✔️ Approved by reviewer to 🎉 Done in FS Oct 22, 2025
}

uint256 startingPeriod = getProvingPeriodForEpoch(dataSetId, fromEpoch + 1);
uint256 endingPeriod = getProvingPeriodForEpoch(dataSetId, toEpoch);
Copy link
Contributor

Choose a reason for hiding this comment

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

I changed it so we only calculate endingPeriod if we will use it

}

function _calcPeriodDeadline(uint256 dataSetId, uint256 periodId) private view returns (uint256) {
return provingActivationEpoch[dataSetId] + (periodId + 1) * maxProvingPeriod;
Copy link
Contributor

Choose a reason for hiding this comment

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

I pass the activationEpoch from the parent function instead of looking it up again with the dataSetId

for (uint256 period = startingPeriod + 1; period < endingPeriod; period++) {
if (_isPeriodProven(dataSetId, period, currentPeriod)) {
provenEpochCount += maxProvingPeriod;
lastProvenEpoch = _calcPeriodDeadline(dataSetId, period);
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead I calculate this once, from the ending period deadline

Comment on lines 1478 to 1479
uint256 provenEpochCount,
uint256 lastProvenEpoch,
Copy link
Contributor

Choose a reason for hiding this comment

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

I remove these parameters since they are the outvars

In the case where lastProvenEpoch is unchanged, we revert so it is unimportant to initialize it

Copy link
Contributor

Choose a reason for hiding this comment

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

In the case where lastProvenEpoch is unchanged, we revert so it is unimportant to initialize it

This isn't quite true because we don't revert. But the uninitialized outvar is unused in that case.

Still I think we should be able to settle the rail over periods of inactivity.

Copy link
Contributor

Choose a reason for hiding this comment

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

@parzival1821
Copy link
Contributor Author

Thank you very much @wjmelements @rjan90 for guiding me through this PR. Would love to keep contributing to FilOzone and the Filecoin ecosystem as a whole!

wjmelements added a commit that referenced this pull request Oct 24, 2025
Reviewer @rvagg
It is only important to block forward progress through the current
proving period.
Currently we don't allow forward progress through unsettled periods
without proofs.
This could be a problem if there was a rail unproven for a long time but
proofs were later resumed.
Though much less likely after #258 and #267, we would not want it to be
possible for the gap to exceed the block gas limit.

Also important to recall that the `fromEpoch` is an exclusive index
while `toEpoch` is an inclusive index.
#### Changes
* allow to settleUpTo previous period when unproven
* define settledUpTo in previously irrelevant case
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.

perf(validatePayment): loop over proving periods instead of epochs

4 participants