Skip to content

Commit a91fcfe

Browse files
committed
fixed small errors in updated algo inside validatePayment
1 parent cb01e08 commit a91fcfe

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

service_contracts/src/FilecoinWarmStorageService.sol

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,25 +1545,24 @@ contract FilecoinWarmStorageService is
15451545

15461546
// Count proven epochs and find the last proven epoch
15471547
uint256 provenEpochCount = 0;
1548-
uint256 lastProvenEpoch = 0;
1548+
uint256 lastProvenEpoch = fromEpoch;
15491549

15501550

15511551
// Updated algorithm
15521552
uint256 activationEpoch = provingActivationEpoch[dataSetId];
1553-
if(activationEpoch != 0 && toEpoch >= activationEpoch && toEpoch < block.number){
1554-
// now, starting epoch - fromEpoch + 1. find period corres to it. find out how long that period lasts and add that many epochs. then keep adding 2880 epochs till period end passes the endEpoch
1555-
1553+
if(toEpoch >= activationEpoch && toEpoch < block.number){
1554+
// if `toEpoch` lies after activation, and `fromEpoch` lies before activation, then update the `fromEpoch`, as follows :
15561555
if(fromEpoch < activationEpoch){
1557-
fromEpoch = activationEpoch;
1556+
fromEpoch = activationEpoch - 1; // we have done -1 because starting epoch is considered as `fromEpoch + 1`
15581557
}
15591558

15601559
uint256 startingPeriod = getProvingPeriodForEpoch(dataSetId, fromEpoch + 1);
15611560
uint256 endingPeriod = getProvingPeriodForEpoch(dataSetId, toEpoch);
15621561

1563-
// lets handle first period separately
1562+
// lets handle first period separately
15641563
uint256 startingPeriod_deadline = _calcPeriodDeadline(dataSetId, startingPeriod);
15651564

1566-
if(toEpoch < startingPeriod_deadline){
1565+
if(toEpoch < startingPeriod_deadline){ // alternative way to check the same : `startingPeriod == endingPeriod`
15671566
if(_isPeriodProven(dataSetId, startingPeriod)){
15681567
provenEpochCount = (toEpoch - fromEpoch);
15691568
lastProvenEpoch = toEpoch;
@@ -1575,7 +1574,7 @@ contract FilecoinWarmStorageService is
15751574

15761575
// now loop through the proving periods between endingPeriod and startingPeriod.
15771576
for(uint256 period = startingPeriod + 1; period <= endingPeriod - 1; period++){
1578-
if(provenPeriods[dataSetId][period]){ // here to check if period is proven, we can simply access the mapping since a period in between cannot be the current period
1577+
if(_isPeriodProven(dataSetId, period)){
15791578
provenEpochCount += maxProvingPeriod;
15801579
lastProvenEpoch = _calcPeriodDeadline(dataSetId, period);
15811580
}

0 commit comments

Comments
 (0)