Skip to content

Commit 42a7895

Browse files
committed
fixed small errors in updated algo inside validatePayment
1 parent 7146027 commit 42a7895

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
@@ -1511,25 +1511,24 @@ contract FilecoinWarmStorageService is
15111511

15121512
// Count proven epochs and find the last proven epoch
15131513
uint256 provenEpochCount = 0;
1514-
uint256 lastProvenEpoch = 0;
1514+
uint256 lastProvenEpoch = fromEpoch;
15151515

15161516

15171517
// Updated algorithm
15181518
uint256 activationEpoch = provingActivationEpoch[dataSetId];
1519-
if(activationEpoch != 0 && toEpoch >= activationEpoch && toEpoch < block.number){
1520-
// 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
1521-
1519+
if(toEpoch >= activationEpoch && toEpoch < block.number){
1520+
// if `toEpoch` lies after activation, and `fromEpoch` lies before activation, then update the `fromEpoch`, as follows :
15221521
if(fromEpoch < activationEpoch){
1523-
fromEpoch = activationEpoch;
1522+
fromEpoch = activationEpoch - 1; // we have done -1 because starting epoch is considered as `fromEpoch + 1`
15241523
}
15251524

15261525
uint256 startingPeriod = getProvingPeriodForEpoch(dataSetId, fromEpoch + 1);
15271526
uint256 endingPeriod = getProvingPeriodForEpoch(dataSetId, toEpoch);
15281527

1529-
// lets handle first period separately
1528+
// lets handle first period separately
15301529
uint256 startingPeriod_deadline = _calcPeriodDeadline(dataSetId, startingPeriod);
15311530

1532-
if(toEpoch < startingPeriod_deadline){
1531+
if(toEpoch < startingPeriod_deadline){ // alternative way to check the same : `startingPeriod == endingPeriod`
15331532
if(_isPeriodProven(dataSetId, startingPeriod)){
15341533
provenEpochCount = (toEpoch - fromEpoch);
15351534
lastProvenEpoch = toEpoch;
@@ -1541,7 +1540,7 @@ contract FilecoinWarmStorageService is
15411540

15421541
// now loop through the proving periods between endingPeriod and startingPeriod.
15431542
for(uint256 period = startingPeriod + 1; period <= endingPeriod - 1; period++){
1544-
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
1543+
if(_isPeriodProven(dataSetId, period)){
15451544
provenEpochCount += maxProvingPeriod;
15461545
lastProvenEpoch = _calcPeriodDeadline(dataSetId, period);
15471546
}

0 commit comments

Comments
 (0)