Skip to content

Commit 8cece67

Browse files
authored
Modify CDN payment rails and add methods for usage-based payments (#237)
1 parent d21495a commit 8cece67

10 files changed

+1000
-140
lines changed

service_contracts/abi/FilecoinWarmStorageService.abi.json

Lines changed: 125 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,29 @@
679679
"outputs": [],
680680
"stateMutability": "nonpayable"
681681
},
682+
{
683+
"type": "function",
684+
"name": "settleFilBeamPaymentRails",
685+
"inputs": [
686+
{
687+
"name": "dataSetId",
688+
"type": "uint256",
689+
"internalType": "uint256"
690+
},
691+
{
692+
"name": "cdnAmount",
693+
"type": "uint256",
694+
"internalType": "uint256"
695+
},
696+
{
697+
"name": "cacheMissAmount",
698+
"type": "uint256",
699+
"internalType": "uint256"
700+
}
701+
],
702+
"outputs": [],
703+
"stateMutability": "nonpayable"
704+
},
682705
{
683706
"type": "function",
684707
"name": "storageProviderChanged",
@@ -733,6 +756,29 @@
733756
"outputs": [],
734757
"stateMutability": "nonpayable"
735758
},
759+
{
760+
"type": "function",
761+
"name": "topUpCDNPaymentRails",
762+
"inputs": [
763+
{
764+
"name": "dataSetId",
765+
"type": "uint256",
766+
"internalType": "uint256"
767+
},
768+
{
769+
"name": "cdnAmountToAdd",
770+
"type": "uint256",
771+
"internalType": "uint256"
772+
},
773+
{
774+
"name": "cacheMissAmountToAdd",
775+
"type": "uint256",
776+
"internalType": "uint256"
777+
}
778+
],
779+
"outputs": [],
780+
"stateMutability": "nonpayable"
781+
},
736782
{
737783
"type": "function",
738784
"name": "transferFilBeamController",
@@ -872,6 +918,31 @@
872918
],
873919
"stateMutability": "view"
874920
},
921+
{
922+
"type": "event",
923+
"name": "CDNPaymentRailsToppedUp",
924+
"inputs": [
925+
{
926+
"name": "dataSetId",
927+
"type": "uint256",
928+
"indexed": true,
929+
"internalType": "uint256"
930+
},
931+
{
932+
"name": "totalCdnLockup",
933+
"type": "uint256",
934+
"indexed": false,
935+
"internalType": "uint256"
936+
},
937+
{
938+
"name": "totalCacheMissLockup",
939+
"type": "uint256",
940+
"indexed": false,
941+
"internalType": "uint256"
942+
}
943+
],
944+
"anonymous": false
945+
},
875946
{
876947
"type": "event",
877948
"name": "CDNPaymentTerminated",
@@ -1377,6 +1448,49 @@
13771448
}
13781449
]
13791450
},
1451+
{
1452+
"type": "error",
1453+
"name": "CDNPaymentAlreadyTerminated",
1454+
"inputs": [
1455+
{
1456+
"name": "dataSetId",
1457+
"type": "uint256",
1458+
"internalType": "uint256"
1459+
}
1460+
]
1461+
},
1462+
{
1463+
"type": "error",
1464+
"name": "CacheMissPaymentAlreadyTerminated",
1465+
"inputs": [
1466+
{
1467+
"name": "dataSetId",
1468+
"type": "uint256",
1469+
"internalType": "uint256"
1470+
}
1471+
]
1472+
},
1473+
{
1474+
"type": "error",
1475+
"name": "CallerNotPayer",
1476+
"inputs": [
1477+
{
1478+
"name": "dataSetId",
1479+
"type": "uint256",
1480+
"internalType": "uint256"
1481+
},
1482+
{
1483+
"name": "expectedPayer",
1484+
"type": "address",
1485+
"internalType": "address"
1486+
},
1487+
{
1488+
"name": "caller",
1489+
"type": "address",
1490+
"internalType": "address"
1491+
}
1492+
]
1493+
},
13801494
{
13811495
"type": "error",
13821496
"name": "CallerNotPayerOrPayee",
@@ -1562,17 +1676,6 @@
15621676
"name": "FailedCall",
15631677
"inputs": []
15641678
},
1565-
{
1566-
"type": "error",
1567-
"name": "FilBeamPaymentAlreadyTerminated",
1568-
"inputs": [
1569-
{
1570-
"name": "dataSetId",
1571-
"type": "uint256",
1572-
"internalType": "uint256"
1573-
}
1574-
]
1575-
},
15761679
{
15771680
"type": "error",
15781681
"name": "FilBeamServiceNotConfigured",
@@ -1711,6 +1814,17 @@
17111814
}
17121815
]
17131816
},
1817+
{
1818+
"type": "error",
1819+
"name": "InvalidTopUpAmount",
1820+
"inputs": [
1821+
{
1822+
"name": "dataSetId",
1823+
"type": "uint256",
1824+
"internalType": "uint256"
1825+
}
1826+
]
1827+
},
17141828
{
17151829
"type": "error",
17161830
"name": "MaxProvingPeriodZero",
@@ -1931,11 +2045,6 @@
19312045
"name": "pdpEndEpoch",
19322046
"type": "uint256",
19332047
"internalType": "uint256"
1934-
},
1935-
{
1936-
"name": "cdnEndEpoch",
1937-
"type": "uint256",
1938-
"internalType": "uint256"
19392048
}
19402049
]
19412050
},

service_contracts/abi/FilecoinWarmStorageServiceStateLibrary.abi.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,6 @@
280280
"type": "uint256",
281281
"internalType": "uint256"
282282
},
283-
{
284-
"name": "cdnEndEpoch",
285-
"type": "uint256",
286-
"internalType": "uint256"
287-
},
288283
{
289284
"name": "dataSetId",
290285
"type": "uint256",
@@ -366,11 +361,6 @@
366361
"type": "uint256",
367362
"internalType": "uint256"
368363
},
369-
{
370-
"name": "cdnEndEpoch",
371-
"type": "uint256",
372-
"internalType": "uint256"
373-
},
374364
{
375365
"name": "dataSetId",
376366
"type": "uint256",

service_contracts/abi/FilecoinWarmStorageServiceStateView.abi.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,6 @@
243243
"type": "uint256",
244244
"internalType": "uint256"
245245
},
246-
{
247-
"name": "cdnEndEpoch",
248-
"type": "uint256",
249-
"internalType": "uint256"
250-
},
251246
{
252247
"name": "dataSetId",
253248
"type": "uint256",
@@ -324,11 +319,6 @@
324319
"type": "uint256",
325320
"internalType": "uint256"
326321
},
327-
{
328-
"name": "cdnEndEpoch",
329-
"type": "uint256",
330-
"internalType": "uint256"
331-
},
332322
{
333323
"name": "dataSetId",
334324
"type": "uint256",

service_contracts/src/Errors.sol

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ library Errors {
128128
/// @param dataSetId The data set ID
129129
error DataSetPaymentAlreadyTerminated(uint256 dataSetId);
130130

131+
/// @notice CDN payment is already terminated
132+
/// @param dataSetId The data set ID
133+
error CDNPaymentAlreadyTerminated(uint256 dataSetId);
134+
135+
/// @notice Cache-miss payment is already terminated
136+
/// @param dataSetId The data set ID
137+
error CacheMissPaymentAlreadyTerminated(uint256 dataSetId);
138+
139+
/// @notice Invalid top-up amount - both CDN and cache miss amounts are zero
140+
/// @param dataSetId The data set ID
141+
error InvalidTopUpAmount(uint256 dataSetId);
142+
131143
/// @notice The specified data set does not exist or is not valid
132144
/// @param dataSetId The data set ID that was invalid or unregistered
133145
error InvalidDataSetId(uint256 dataSetId);
@@ -139,6 +151,12 @@ library Errors {
139151
/// @param caller The actual caller
140152
error CallerNotPayerOrPayee(uint256 dataSetId, address expectedPayer, address expectedPayee, address caller);
141153

154+
/// @notice Only payer can top-up CDN payment rail balance
155+
/// @param dataSetId The data set ID
156+
/// @param expectedPayer The payer address
157+
/// @param caller The actual caller
158+
error CallerNotPayer(uint256 dataSetId, address expectedPayer, address caller);
159+
142160
/// @notice Data set is beyond its payment end epoch
143161
/// @param dataSetId The data set ID
144162
/// @param pdpEndEpoch The payment end epoch for the data set
@@ -246,13 +264,8 @@ library Errors {
246264
/// @param actual The caller address
247265
error OnlyFilBeamControllerAllowed(address expected, address actual);
248266

249-
/// @notice CDN payment is already terminated
250-
/// @param dataSetId The data set ID
251-
error FilBeamPaymentAlreadyTerminated(uint256 dataSetId);
252-
253267
/// @notice Payment rails have not finalized yet, so the data set can't be deleted
254268
/// @param dataSetId The data set ID
255269
/// @param pdpEndEpoch The end epoch when the PDP payment rail will finalize
256-
/// @param cdnEndEpoch The end epoch when the CDN payment rail will finalize (0 if no CDN)
257-
error PaymentRailsNotFinalized(uint256 dataSetId, uint256 pdpEndEpoch, uint256 cdnEndEpoch);
270+
error PaymentRailsNotFinalized(uint256 dataSetId, uint256 pdpEndEpoch);
258271
}

0 commit comments

Comments
 (0)