-
Notifications
You must be signed in to change notification settings - Fork 17
Closed
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers
Description
When we settle a Payment segment, FilecoinWarmStorageService.validatePayment loops over epochs like this:
// Check each epoch in the range
for (uint256 epoch = fromEpoch + 1; epoch <= toEpoch; epoch++) {
bool isProven = isEpochProven(dataSetId, epoch);
if (isProven) {
provenEpochCount++;
lastProvenEpoch = epoch;
}
}
isEpochProven ultimately does
// Get the period this epoch belongs to
uint256 periodId = getProvingPeriodForEpoch(dataSetId, epoch);
// Special case: current ongoing proving period
uint256 currentPeriod = getProvingPeriodForEpoch(dataSetId, block.number);
if (periodId == currentPeriod) {
// For the current period, check if it has been proven already
return provenThisPeriod[dataSetId];
}
// For past periods, check the provenPeriods mapping
return provenPeriods[dataSetId][periodId];
getProvingPeriodForEpoch calculates periodId this way:
return (epoch - activationEpoch) / maxProvingPeriod;
So the top level loop can be optimized by looping over proving periods instead of over epochs. The first and last epochs might need special handling, but for the other proving periods, can count like provenEpochCount += maxProvingPeriod.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers
Type
Projects
Status
🎉 Done