Skip to content

Commit e3be080

Browse files
committed
fix failing test,formatting, and some minor code quality improvements
1 parent 26bf52e commit e3be080

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

service_contracts/src/Errors.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ library Errors {
202202
error RailNotAssociated(uint256 railId);
203203

204204
/// @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)
205+
/// @notice Will be emitted if any of the following conditions is NOT met :
206+
/// @notice 1. fromEpoch must be less than toEpoch
207+
/// @notice 2. toEpoch must be greater than block number
208+
/// @notice 3. toEpoch must be greater than the activation epoch
206209
/// @param fromEpoch The starting epoch (exclusive)
207210
/// @param toEpoch The ending epoch (inclusive)
208211
error InvalidEpochRange(uint256 fromEpoch, uint256 toEpoch);

service_contracts/src/FilecoinWarmStorageService.sol

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

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

14671468
// If no epochs are proven, we can't settle anything
14681469
if (provenEpochCount == 0) {
@@ -1486,16 +1487,18 @@ contract FilecoinWarmStorageService is
14861487
});
14871488
}
14881489

1489-
function _findProvenEpochs(uint256 dataSetId, uint256 fromEpoch, uint256 toEpoch, uint256 provenEpochCount, uint256 lastProvenEpoch)
1490-
internal
1491-
view
1492-
returns (uint256, uint256)
1493-
{
1490+
function _findProvenEpochs(
1491+
uint256 dataSetId,
1492+
uint256 fromEpoch,
1493+
uint256 toEpoch,
1494+
uint256 provenEpochCount,
1495+
uint256 lastProvenEpoch
1496+
) internal view returns (uint256, uint256) {
14941497
uint256 activationEpoch = provingActivationEpoch[dataSetId];
1495-
if (toEpoch < activationEpoch){
1498+
if (toEpoch < activationEpoch) {
14961499
revert Errors.InvalidEpochRange(fromEpoch, toEpoch);
14971500
}
1498-
if(toEpoch > block.number){
1501+
if (toEpoch > block.number) {
14991502
revert Errors.InvalidEpochRange(fromEpoch, toEpoch);
15001503
}
15011504
uint256 currentPeriod = getProvingPeriodForEpoch(dataSetId, block.number);
@@ -1523,7 +1526,7 @@ contract FilecoinWarmStorageService is
15231526
}
15241527

15251528
// now loop through the proving periods between endingPeriod and startingPeriod.
1526-
for (uint256 period = startingPeriod + 1; period <= endingPeriod - 1; period++) {
1529+
for (uint256 period = startingPeriod + 1; period < endingPeriod; period++) {
15271530
if (_isPeriodProven(dataSetId, period, currentPeriod)) {
15281531
provenEpochCount += maxProvingPeriod;
15291532
lastProvenEpoch = _calcPeriodDeadline(dataSetId, period);
@@ -1532,7 +1535,7 @@ contract FilecoinWarmStorageService is
15321535

15331536
// now handle the last period separately
15341537
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`)
1538+
// then the epochs to add = `endingPeriodStarting` to `toEpoch`. But since `endingPeriodStarting` is simply the ending of its previous period + 1, so epochs : (`deadline + 1` -> `to`)
15361539
provenEpochCount += (toEpoch - _calcPeriodDeadline(dataSetId, endingPeriod - 1));
15371540
lastProvenEpoch = toEpoch;
15381541
}
@@ -1550,7 +1553,7 @@ contract FilecoinWarmStorageService is
15501553
}
15511554

15521555
function _calcPeriodDeadline(uint256 dataSetId, uint256 periodId) private view returns (uint256) {
1553-
return provingActivationEpoch[dataSetId] + ((periodId + 1) * maxProvingPeriod); // we need to do `periodId + 1` since it starts from 0
1556+
return provingActivationEpoch[dataSetId] + (periodId + 1) * maxProvingPeriod;
15541557
}
15551558

15561559
function railTerminated(uint256 railId, address terminator, uint256 endEpoch) external override {

service_contracts/test/FilecoinWarmStorageService.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4470,11 +4470,11 @@ contract ValidatePaymentTest is FilecoinWarmStorageServiceTest {
44704470
uint256 proposedAmount = 1000e6;
44714471

44724472
vm.prank(address(payments));
4473+
vm.expectRevert(abi.encodeWithSelector(Errors.InvalidEpochRange.selector, fromEpoch, toEpoch));
44734474
IValidator.ValidationResult memory result =
44744475
pdpServiceWithPayments.validatePayment(info.pdpRailId, proposedAmount, fromEpoch, toEpoch, 0);
44754476

44764477
assertEq(result.modifiedAmount, 0, "Should pay nothing for pre-activation epochs");
4477-
assertEq(result.settleUpto, fromEpoch, "Should not settle");
44784478
}
44794479

44804480
/**

0 commit comments

Comments
 (0)