Skip to content

Commit 59c094b

Browse files
committed
feature
1 parent b37e54c commit 59c094b

File tree

1 file changed

+56
-21
lines changed

1 file changed

+56
-21
lines changed

src/Client.sol

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,24 @@ contract Client is Initializable, AccessControlUpgradeable, UUPSUpgradeable {
145145
* @notice Thrown if beneficiary expiration is insufficient
146146
*/
147147
error InsufficientBeneficiaryExpiration(
148-
CommonTypes.FilActorId provider, int64 beneficiaryExpiration, int128 requiredExpiration
148+
CommonTypes.FilActorId provider, int64 beneficiaryExpiration, int64 requiredExpiration
149149
);
150150

151+
/**
152+
* @notice Thrown if no allocation or claim is found
153+
*/
154+
error NoAllocationOrClaim();
155+
151156
struct ProviderAllocation {
152157
CommonTypes.FilActorId provider;
153158
uint64 size;
154-
int128 allocationTime;
159+
int64 allocationTime;
155160
}
156161

157162
struct ProviderClaim {
158163
CommonTypes.FilActorId provider;
159164
CommonTypes.FilActorId claim;
165+
int64 termMax;
160166
}
161167

162168
struct ClientDataUsage {
@@ -243,10 +249,11 @@ contract Client is Initializable, AccessControlUpgradeable, UUPSUpgradeable {
243249
(
244250
ProviderAllocation[] memory allocations,
245251
ProviderClaim[] memory claimExtensions,
246-
ProviderAllocation memory longestAllocation
252+
ProviderAllocation memory longestAllocation,
253+
ProviderClaim memory longestClaimExtension
247254
) = _deserializeVerifregOperatorData(params.operator_data);
248255

249-
_verifyBeneficiaryExpiration(longestAllocation);
256+
_verifyBeneficiaryExpiration(longestAllocation, longestClaimExtension);
250257
_verifyAndRegisterAllocations(allocations);
251258
_verifyAndRegisterClaimExtensions(claimExtensions);
252259
emit DatacapSpent(msg.sender, datacapAmount);
@@ -346,19 +353,42 @@ contract Client is Initializable, AccessControlUpgradeable, UUPSUpgradeable {
346353
* @param longestAllocation The longest allocation.
347354
* @dev Reverts with InsufficientBeneficiaryExpiration if the beneficiary expiration is insufficient.
348355
*/
349-
function _verifyBeneficiaryExpiration(ProviderAllocation memory longestAllocation) internal {
350-
MinerTypes.GetBeneficiaryReturn memory beneficiary =
351-
MinerUtils.getBeneficiaryWithChecks(longestAllocation.provider, beneficiaryFactory, true, true, true);
352-
if (
353-
longestAllocation.allocationTime
354-
> int128(CommonTypes.ChainEpoch.unwrap(beneficiary.active.term.expiration) + 180 days)
355-
) {
356-
revert InsufficientBeneficiaryExpiration(
357-
longestAllocation.provider,
358-
CommonTypes.ChainEpoch.unwrap(beneficiary.active.term.expiration),
359-
longestAllocation.allocationTime
356+
function _verifyBeneficiaryExpiration(
357+
ProviderAllocation memory longestAllocation,
358+
ProviderClaim memory longestClaimExtension
359+
) internal {
360+
MinerTypes.GetBeneficiaryReturn memory beneficiary;
361+
int64 beneficiaryExpiration;
362+
363+
if (longestClaimExtension.termMax != 0) {
364+
beneficiary = MinerUtils.getBeneficiaryWithChecks(
365+
longestClaimExtension.provider, beneficiaryFactory, true, true, true
360366
);
367+
int64 beneficiaryExpiration = CommonTypes.ChainEpoch.unwrap(beneficiary.active.term.expiration);
368+
369+
if (int64(longestClaimExtension.termMax) > beneficiaryExpiration + 250 weeks) {
370+
revert InsufficientBeneficiaryExpiration(
371+
longestClaimExtension.provider, beneficiaryExpiration, longestClaimExtension.termMax
372+
);
373+
}
374+
return;
375+
}
376+
377+
if (longestAllocation.allocationTime != 0) {
378+
beneficiary =
379+
MinerUtils.getBeneficiaryWithChecks(longestAllocation.provider, beneficiaryFactory, true, true, true);
380+
beneficiaryExpiration = CommonTypes.ChainEpoch.unwrap(beneficiary.active.term.expiration);
381+
382+
if (int64(longestAllocation.allocationTime) > beneficiaryExpiration + 180 days) {
383+
revert InsufficientBeneficiaryExpiration(
384+
longestAllocation.provider, beneficiaryExpiration, longestAllocation.allocationTime
385+
);
386+
}
387+
388+
return;
361389
}
390+
391+
revert NoAllocationOrClaim();
362392
}
363393

364394
// solhint-disable function-max-lines
@@ -368,14 +398,16 @@ contract Client is Initializable, AccessControlUpgradeable, UUPSUpgradeable {
368398
* @return allocations Array of provider allocations.
369399
* @return claimExtensions Array of provider claims.
370400
* @return longestAllocation Allocation with the longest term.
401+
* @return longestClaimExtension Claim extension with the longest term.
371402
*/
372403
function _deserializeVerifregOperatorData(bytes memory cborData)
373404
internal
374405
pure
375406
returns (
376407
ProviderAllocation[] memory allocations,
377408
ProviderClaim[] memory claimExtensions,
378-
ProviderAllocation memory longestAllocation
409+
ProviderAllocation memory longestAllocation,
410+
ProviderClaim memory longestClaimExtension
379411
)
380412
{
381413
uint256 operatorDataLength;
@@ -406,13 +438,13 @@ contract Client is Initializable, AccessControlUpgradeable, UUPSUpgradeable {
406438
(, byteIdx) = CBORDecoder.readBytes(cborData, byteIdx); // data (CID)
407439
(size, byteIdx) = CBORDecoder.readUInt64(cborData, byteIdx);
408440
(, byteIdx) = CBORDecoder.readInt64(cborData, byteIdx); // termMin
441+
// slither-disable-end unused-return
409442
(termMax, byteIdx) = CBORDecoder.readInt64(cborData, byteIdx);
410443
(expiration, byteIdx) = CBORDecoder.readInt64(cborData, byteIdx);
411-
// slither-disable-end unused-return
412444

413445
allocations[i].provider = CommonTypes.FilActorId.wrap(provider);
414446
allocations[i].size = size;
415-
allocations[i].allocationTime = int128(termMax + expiration);
447+
allocations[i].allocationTime = termMax + expiration;
416448

417449
if (allocations[i].allocationTime > longestAllocation.allocationTime) {
418450
longestAllocation = allocations[i];
@@ -431,12 +463,15 @@ contract Client is Initializable, AccessControlUpgradeable, UUPSUpgradeable {
431463

432464
(provider, byteIdx) = CBORDecoder.readUInt64(cborData, byteIdx);
433465
(claimId, byteIdx) = CBORDecoder.readUInt64(cborData, byteIdx);
434-
// slither-disable-start unused-return
435-
(, byteIdx) = CBORDecoder.readInt64(cborData, byteIdx); // termMax
436-
// slither-disable-end unused-return
466+
(termMax, byteIdx) = CBORDecoder.readInt64(cborData, byteIdx);
437467

438468
claimExtensions[i].provider = CommonTypes.FilActorId.wrap(provider);
439469
claimExtensions[i].claim = CommonTypes.FilActorId.wrap(claimId);
470+
claimExtensions[i].termMax = termMax;
471+
472+
if (termMax > longestClaimExtension.termMax) {
473+
longestClaimExtension = claimExtensions[i];
474+
}
440475
}
441476
}
442477

0 commit comments

Comments
 (0)