Skip to content

Commit eac3300

Browse files
committed
implemented required changes
1 parent 8b31e9e commit eac3300

File tree

3 files changed

+40
-40
lines changed

3 files changed

+40
-40
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
# VIM
22
*.swp
3-
4-
# Foundry
5-
foundry.lock

service_contracts/src/Errors.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ library Errors {
201201
/// @param railId The rail ID
202202
error RailNotAssociated(uint256 railId);
203203

204-
/// @notice The epoch range is invalid (toEpoch must be > fromEpoch)
204+
/// @notice The epoch range is invalid
205+
/// @notice Will be emitted if any of the following conditions is NOT met - (fromEpoch must be less than toEpoch), (toEpoch must be greater than block number), (toEpoch must be greater than the activation epoch)
205206
/// @param fromEpoch The starting epoch (exclusive)
206207
/// @param toEpoch The ending epoch (inclusive)
207208
error InvalidEpochRange(uint256 fromEpoch, uint256 toEpoch);

service_contracts/src/FilecoinWarmStorageService.sol

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ contract FilecoinWarmStorageService is
14621462
uint256 provenEpochCount = 0;
14631463
uint256 lastProvenEpoch = fromEpoch;
14641464

1465-
(provenEpochCount, lastProvenEpoch) = _findProvenEpochs(dataSetId, fromEpoch, toEpoch);
1465+
(provenEpochCount, lastProvenEpoch) = _findProvenEpochs(dataSetId, fromEpoch, toEpoch, provenEpochCount, lastProvenEpoch);
14661466

14671467
// If no epochs are proven, we can't settle anything
14681468
if (provenEpochCount == 0) {
@@ -1486,53 +1486,56 @@ contract FilecoinWarmStorageService is
14861486
});
14871487
}
14881488

1489-
function _findProvenEpochs(uint256 dataSetId, uint256 fromEpoch, uint256 toEpoch)
1489+
function _findProvenEpochs(uint256 dataSetId, uint256 fromEpoch, uint256 toEpoch, uint256 provenEpochCount, uint256 lastProvenEpoch)
14901490
internal
14911491
view
14921492
returns (uint256, uint256)
14931493
{
1494-
uint256 provenEpochCount = 0;
1495-
uint256 lastProvenEpoch = fromEpoch;
14961494
uint256 activationEpoch = provingActivationEpoch[dataSetId];
1495+
if (toEpoch < activationEpoch){
1496+
revert Errors.InvalidEpochRange(fromEpoch, toEpoch);
1497+
}
1498+
if(toEpoch > block.number){
1499+
revert Errors.InvalidEpochRange(fromEpoch, toEpoch);
1500+
}
14971501
uint256 currentPeriod = getProvingPeriodForEpoch(dataSetId, block.number);
1498-
if (toEpoch >= activationEpoch && toEpoch < block.number) {
1499-
// if `toEpoch` lies after activation, and `fromEpoch` lies before activation, then update the `fromEpoch`, as follows :
1500-
if (fromEpoch < activationEpoch - 1) {
1501-
fromEpoch = activationEpoch - 1;
1502-
}
15031502

1504-
uint256 startingPeriod = getProvingPeriodForEpoch(dataSetId, fromEpoch + 1);
1505-
uint256 endingPeriod = getProvingPeriodForEpoch(dataSetId, toEpoch);
1503+
// if `toEpoch` lies after activation, and `fromEpoch` lies before activation, then update the `fromEpoch`, as follows :
1504+
if (fromEpoch < activationEpoch - 1) {
1505+
fromEpoch = activationEpoch - 1;
1506+
}
15061507

1507-
// lets handle first period separately
1508-
uint256 startingPeriod_deadline = _calcPeriodDeadline(dataSetId, startingPeriod);
1508+
uint256 startingPeriod = getProvingPeriodForEpoch(dataSetId, fromEpoch + 1);
1509+
uint256 endingPeriod = getProvingPeriodForEpoch(dataSetId, toEpoch);
15091510

1510-
if (toEpoch < startingPeriod_deadline) {
1511-
// alternative way to check the same : `startingPeriod == endingPeriod`
1512-
if (_isPeriodProven(dataSetId, startingPeriod, currentPeriod)) {
1513-
provenEpochCount = (toEpoch - fromEpoch); // epochs : (`from + 1` -> `to`) (both inclusive)
1514-
lastProvenEpoch = toEpoch;
1515-
}
1516-
} else {
1517-
if (_isPeriodProven(dataSetId, startingPeriod, currentPeriod)) {
1518-
provenEpochCount += (startingPeriod_deadline - fromEpoch); // epochs : (`from + 1` -> `deadline`)
1519-
}
1511+
// handle first period separately
1512+
uint256 startingPeriodDeadline = _calcPeriodDeadline(dataSetId, startingPeriod);
15201513

1521-
// now loop through the proving periods between endingPeriod and startingPeriod.
1522-
for (uint256 period = startingPeriod + 1; period <= endingPeriod - 1; period++) {
1523-
if (_isPeriodProven(dataSetId, period, currentPeriod)) {
1524-
provenEpochCount += maxProvingPeriod;
1525-
lastProvenEpoch = _calcPeriodDeadline(dataSetId, period);
1526-
}
1527-
}
1514+
if (toEpoch < startingPeriodDeadline) {
1515+
// alternative way to check the same : `startingPeriod == endingPeriod`
1516+
if (_isPeriodProven(dataSetId, startingPeriod, currentPeriod)) {
1517+
provenEpochCount = (toEpoch - fromEpoch); // epochs : (`from + 1` -> `to`) (both inclusive)
1518+
lastProvenEpoch = toEpoch;
1519+
}
1520+
} else {
1521+
if (_isPeriodProven(dataSetId, startingPeriod, currentPeriod)) {
1522+
provenEpochCount += (startingPeriodDeadline - fromEpoch); // epochs : (`from + 1` -> `deadline`)
1523+
}
15281524

1529-
// now handle the last period separately
1530-
if (_isPeriodProven(dataSetId, endingPeriod, currentPeriod)) {
1531-
// then the epochs to add = `endingPeriod_starting` to `toEpoch`. But since `endingPeriod_starting` is simply the ending of its previous period + 1, so epochs : (`deadline + 1` -> `to`)
1532-
provenEpochCount += (toEpoch - _calcPeriodDeadline(dataSetId, endingPeriod - 1));
1533-
lastProvenEpoch = toEpoch;
1525+
// now loop through the proving periods between endingPeriod and startingPeriod.
1526+
for (uint256 period = startingPeriod + 1; period <= endingPeriod - 1; period++) {
1527+
if (_isPeriodProven(dataSetId, period, currentPeriod)) {
1528+
provenEpochCount += maxProvingPeriod;
1529+
lastProvenEpoch = _calcPeriodDeadline(dataSetId, period);
15341530
}
15351531
}
1532+
1533+
// now handle the last period separately
1534+
if (_isPeriodProven(dataSetId, endingPeriod, currentPeriod)) {
1535+
// then the epochs to add = `endingPeriod_starting` to `toEpoch`. But since `endingPeriod_starting` is simply the ending of its previous period + 1, so epochs : (`deadline + 1` -> `to`)
1536+
provenEpochCount += (toEpoch - _calcPeriodDeadline(dataSetId, endingPeriod - 1));
1537+
lastProvenEpoch = toEpoch;
1538+
}
15361539
}
15371540

15381541
return (provenEpochCount, lastProvenEpoch);
@@ -1542,7 +1545,6 @@ contract FilecoinWarmStorageService is
15421545
if (periodId == currentPeriod) {
15431546
return provenThisPeriod[dataSetId];
15441547
}
1545-
// return provenPeriods[dataSetId][periodId];
15461548
uint256 isProven = provenPeriods[dataSetId][periodId >> 8] & (1 << (periodId & 255));
15471549
return isProven != 0;
15481550
}

0 commit comments

Comments
 (0)