Skip to content

Commit 8ffc573

Browse files
committed
fix failing test,formatting, and some minor code quality improvements
1 parent 3d78a36 commit 8ffc573

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
@@ -1445,7 +1445,8 @@ contract FilecoinWarmStorageService is
14451445
uint256 provenEpochCount = 0;
14461446
uint256 lastProvenEpoch = fromEpoch;
14471447

1448-
(provenEpochCount, lastProvenEpoch) = _findProvenEpochs(dataSetId, fromEpoch, toEpoch, provenEpochCount, lastProvenEpoch);
1448+
(provenEpochCount, lastProvenEpoch) =
1449+
_findProvenEpochs(dataSetId, fromEpoch, toEpoch, provenEpochCount, lastProvenEpoch);
14491450

14501451
// If no epochs are proven, we can't settle anything
14511452
if (provenEpochCount == 0) {
@@ -1469,16 +1470,18 @@ contract FilecoinWarmStorageService is
14691470
});
14701471
}
14711472

1472-
function _findProvenEpochs(uint256 dataSetId, uint256 fromEpoch, uint256 toEpoch, uint256 provenEpochCount, uint256 lastProvenEpoch)
1473-
internal
1474-
view
1475-
returns (uint256, uint256)
1476-
{
1473+
function _findProvenEpochs(
1474+
uint256 dataSetId,
1475+
uint256 fromEpoch,
1476+
uint256 toEpoch,
1477+
uint256 provenEpochCount,
1478+
uint256 lastProvenEpoch
1479+
) internal view returns (uint256, uint256) {
14771480
uint256 activationEpoch = provingActivationEpoch[dataSetId];
1478-
if (toEpoch < activationEpoch){
1481+
if (toEpoch < activationEpoch) {
14791482
revert Errors.InvalidEpochRange(fromEpoch, toEpoch);
14801483
}
1481-
if(toEpoch > block.number){
1484+
if (toEpoch > block.number) {
14821485
revert Errors.InvalidEpochRange(fromEpoch, toEpoch);
14831486
}
14841487
uint256 currentPeriod = getProvingPeriodForEpoch(dataSetId, block.number);
@@ -1506,7 +1509,7 @@ contract FilecoinWarmStorageService is
15061509
}
15071510

15081511
// now loop through the proving periods between endingPeriod and startingPeriod.
1509-
for (uint256 period = startingPeriod + 1; period <= endingPeriod - 1; period++) {
1512+
for (uint256 period = startingPeriod + 1; period < endingPeriod; period++) {
15101513
if (_isPeriodProven(dataSetId, period, currentPeriod)) {
15111514
provenEpochCount += maxProvingPeriod;
15121515
lastProvenEpoch = _calcPeriodDeadline(dataSetId, period);
@@ -1515,7 +1518,7 @@ contract FilecoinWarmStorageService is
15151518

15161519
// now handle the last period separately
15171520
if (_isPeriodProven(dataSetId, endingPeriod, currentPeriod)) {
1518-
// 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`)
1521+
// 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`)
15191522
provenEpochCount += (toEpoch - _calcPeriodDeadline(dataSetId, endingPeriod - 1));
15201523
lastProvenEpoch = toEpoch;
15211524
}
@@ -1533,7 +1536,7 @@ contract FilecoinWarmStorageService is
15331536
}
15341537

15351538
function _calcPeriodDeadline(uint256 dataSetId, uint256 periodId) private view returns (uint256) {
1536-
return provingActivationEpoch[dataSetId] + ((periodId + 1) * maxProvingPeriod); // we need to do `periodId + 1` since it starts from 0
1539+
return provingActivationEpoch[dataSetId] + (periodId + 1) * maxProvingPeriod;
15371540
}
15381541

15391542
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
@@ -4432,11 +4432,11 @@ contract ValidatePaymentTest is FilecoinWarmStorageServiceTest {
44324432
uint256 proposedAmount = 1000e6;
44334433

44344434
vm.prank(address(payments));
4435+
vm.expectRevert(abi.encodeWithSelector(Errors.InvalidEpochRange.selector, fromEpoch, toEpoch));
44354436
IValidator.ValidationResult memory result =
44364437
pdpServiceWithPayments.validatePayment(info.pdpRailId, proposedAmount, fromEpoch, toEpoch, 0);
44374438

44384439
assertEq(result.modifiedAmount, 0, "Should pay nothing for pre-activation epochs");
4439-
assertEq(result.settleUpto, fromEpoch, "Should not settle");
44404440
}
44414441

44424442
/**

0 commit comments

Comments
 (0)