Skip to content

Commit 225f020

Browse files
committed
feat: Allow deletion of terminated dataset, Add getDataSetStatus
This PR allows providers to terminate a dataset that has been terminated without further approval from the client. After the rail period elapses, the provider can call PDP.deleteDataSet It also adds a `getDataSetStatus(dataSetId)` which returns an enum with the following states: - NotFound - dataset either didn't exist, or was terminated - Active - dataset and rails are active - Terminating - dataset is in pthe rocess of being terminated The logic of `getDataSetStatus` can easily be reproduced on the client side using `getDataSet`: - if `pdpRailId == 0` then `NotFound - if `pdpEndEpoch != 0` then `Terminating` - else `Active` Signed-off-by: Jakub Sztandera <[email protected]>
1 parent 3d42886 commit 225f020

8 files changed

+126
-12
lines changed

service_contracts/abi/FilecoinWarmStorageService.abi.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
"internalType": "uint256"
160160
},
161161
{
162-
"name": "extraData",
162+
"name": "",
163163
"type": "bytes",
164164
"internalType": "bytes"
165165
}

service_contracts/abi/FilecoinWarmStorageServiceStateLibrary.abi.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,30 @@
434434
],
435435
"stateMutability": "pure"
436436
},
437+
{
438+
"type": "function",
439+
"name": "getDataSetStatus",
440+
"inputs": [
441+
{
442+
"name": "service",
443+
"type": "FilecoinWarmStorageService",
444+
"internalType": "contract FilecoinWarmStorageService"
445+
},
446+
{
447+
"name": "dataSetId",
448+
"type": "uint256",
449+
"internalType": "uint256"
450+
}
451+
],
452+
"outputs": [
453+
{
454+
"name": "status",
455+
"type": "FilecoinWarmStorageService.DataSetStatus",
456+
"internalType": "enum FilecoinWarmStorageService.DataSetStatus"
457+
}
458+
],
459+
"stateMutability": "view"
460+
},
437461
{
438462
"type": "function",
439463
"name": "getMaxProvingPeriod",

service_contracts/abi/FilecoinWarmStorageServiceStateView.abi.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,25 @@
387387
],
388388
"stateMutability": "pure"
389389
},
390+
{
391+
"type": "function",
392+
"name": "getDataSetStatus",
393+
"inputs": [
394+
{
395+
"name": "dataSetId",
396+
"type": "uint256",
397+
"internalType": "uint256"
398+
}
399+
],
400+
"outputs": [
401+
{
402+
"name": "status",
403+
"type": "uint8",
404+
"internalType": "enum FilecoinWarmStorageService.DataSetStatus"
405+
}
406+
],
407+
"stateMutability": "view"
408+
},
390409
{
391410
"type": "function",
392411
"name": "getMaxProvingPeriod",

service_contracts/src/FilecoinWarmStorageService.sol

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ contract FilecoinWarmStorageService is
126126
uint256 dataSetId; // DataSet ID
127127
}
128128

129+
enum DataSetStatus {
130+
// Data set doesn't yet exist or has been deleted
131+
NotFound,
132+
// Data set is active
133+
Active,
134+
// Data set is in the process of being terminated
135+
Terminating
136+
}
137+
129138
// Decode structure for data set creation extra data
130139
struct DataSetCreateData {
131140
address payer;
@@ -611,27 +620,22 @@ contract FilecoinWarmStorageService is
611620
}
612621

613622
/**
614-
* @notice Handles data set deletion and terminates the payment rail
623+
* @notice Handles data set deletion after the payment rails were terminated
615624
* @dev Called by the PDPVerifier contract when a data set is deleted
616625
* @param dataSetId The ID of the data set being deleted
617-
* @param extraData Signature for authentication
618626
*/
619627
function dataSetDeleted(
620628
uint256 dataSetId,
621629
uint256, // deletedLeafCount, - not used
622-
bytes calldata extraData
630+
bytes calldata // extraData, - not used
623631
) external onlyPDPVerifier {
624632
// Verify the data set exists in our mapping
625633
DataSetInfo storage info = dataSetInfo[dataSetId];
626634
require(info.pdpRailId != 0, Errors.DataSetNotRegistered(dataSetId));
627-
(bytes memory signature) = abi.decode(extraData, (bytes));
628635

629636
// Get the payer address for this data set
630637
address payer = dataSetInfo[dataSetId].payer;
631638

632-
// Verify the client's signature
633-
verifyDeleteDataSetSignature(payer, info.clientDataSetId, signature);
634-
635639
// Check if the data set's payment rails have finalized
636640
require(
637641
info.pdpEndEpoch != 0 && block.number > info.pdpEndEpoch,

service_contracts/src/FilecoinWarmStorageServiceStateView.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ contract FilecoinWarmStorageServiceStateView is IPDPProvingSchedule {
9090
return FilecoinWarmStorageServiceStateInternalLibrary.getDataSetSizeInBytes(leafCount);
9191
}
9292

93+
function getDataSetStatus(uint256 dataSetId)
94+
external
95+
view
96+
returns (FilecoinWarmStorageService.DataSetStatus status)
97+
{
98+
return service.getDataSetStatus(dataSetId);
99+
}
100+
93101
function getMaxProvingPeriod() external view returns (uint64) {
94102
return service.getMaxProvingPeriod();
95103
}

service_contracts/src/lib/FilecoinWarmStorageServiceStateInternalLibrary.sol

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,21 @@ library FilecoinWarmStorageServiceStateInternalLibrary {
112112
info.dataSetId = dataSetId;
113113
}
114114

115+
function getDataSetStatus(FilecoinWarmStorageService service, uint256 dataSetId)
116+
internal
117+
view
118+
returns (FilecoinWarmStorageService.DataSetStatus status)
119+
{
120+
FilecoinWarmStorageService.DataSetInfoView memory info = getDataSet(service, dataSetId);
121+
if (info.pdpRailId == 0) {
122+
return FilecoinWarmStorageService.DataSetStatus.NotFound;
123+
}
124+
if (info.pdpEndEpoch != 0) {
125+
return FilecoinWarmStorageService.DataSetStatus.Terminating;
126+
}
127+
return FilecoinWarmStorageService.DataSetStatus.Active;
128+
}
129+
115130
function clientDataSets(FilecoinWarmStorageService service, address payer)
116131
internal
117132
view

service_contracts/src/lib/FilecoinWarmStorageServiceStateLibrary.sol

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ library FilecoinWarmStorageServiceStateLibrary {
108108
info.dataSetId = dataSetId;
109109
}
110110

111+
function getDataSetStatus(FilecoinWarmStorageService service, uint256 dataSetId)
112+
public
113+
view
114+
returns (FilecoinWarmStorageService.DataSetStatus status)
115+
{
116+
FilecoinWarmStorageService.DataSetInfoView memory info = getDataSet(service, dataSetId);
117+
if (info.pdpRailId == 0) {
118+
return FilecoinWarmStorageService.DataSetStatus.NotFound;
119+
}
120+
if (info.pdpEndEpoch != 0) {
121+
return FilecoinWarmStorageService.DataSetStatus.Terminating;
122+
}
123+
return FilecoinWarmStorageService.DataSetStatus.Active;
124+
}
125+
111126
function clientDataSets(FilecoinWarmStorageService service, address payer)
112127
public
113128
view

service_contracts/test/FilecoinWarmStorageService.t.sol

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -877,12 +877,9 @@ contract FilecoinWarmStorageServiceTest is Test {
877877
* @param dataSetId The ID of the data set to delete
878878
*/
879879
function deleteDataSetForClient(address provider, address clientAddress, uint256 dataSetId) internal {
880-
bytes memory signature = abi.encode(FAKE_SIGNATURE);
881-
882-
makeSignaturePass(clientAddress);
883880
// Delete the data set as the provider
884881
vm.prank(provider);
885-
mockPDPVerifier.deleteDataSet(address(pdpServiceWithPayments), dataSetId, signature);
882+
mockPDPVerifier.deleteDataSet(address(pdpServiceWithPayments), dataSetId, bytes(""));
886883
}
887884

888885
function testGetClientDataSets_EmptyClient() public view {
@@ -1160,6 +1157,10 @@ contract FilecoinWarmStorageServiceTest is Test {
11601157
function testTerminateServiceLifecycle() public {
11611158
console.log("=== Test: Data Set Payment Termination Lifecycle ===");
11621159

1160+
// 0. Verify that DataSet with ID 1 is not found
1161+
FilecoinWarmStorageService.DataSetStatus status = viewContract.getDataSetStatus(1);
1162+
assertEq(uint256(status), uint256(FilecoinWarmStorageService.DataSetStatus.NotFound), "expected NotFound");
1163+
11631164
// 1. Setup: Create a dataset with CDN enabled.
11641165
console.log("1. Setting up: Creating dataset with service provider");
11651166

@@ -1197,6 +1198,9 @@ contract FilecoinWarmStorageServiceTest is Test {
11971198
uint256 dataSetId = mockPDPVerifier.createDataSet(pdpServiceWithPayments, encodedData);
11981199
console.log("Created data set with ID:", dataSetId);
11991200

1201+
status = viewContract.getDataSetStatus(dataSetId);
1202+
assertEq(uint256(status), uint256(FilecoinWarmStorageService.DataSetStatus.Active), "expected Active");
1203+
12001204
// 2. Submit a valid proof.
12011205
console.log("\n2. Starting proving period and submitting proof");
12021206
// Start proving period
@@ -1228,6 +1232,9 @@ contract FilecoinWarmStorageServiceTest is Test {
12281232
);
12291233
console.log("Proof submitted successfully");
12301234

1235+
status = viewContract.getDataSetStatus(dataSetId);
1236+
assertEq(uint256(status), uint256(FilecoinWarmStorageService.DataSetStatus.Active), "expected Active");
1237+
12311238
// 3. Terminate payment
12321239
console.log("\n3. Terminating payment rails");
12331240
console.log("Current block:", block.number);
@@ -1247,6 +1254,10 @@ contract FilecoinWarmStorageServiceTest is Test {
12471254
assertFalse(exists, "withCDN metadata should not exist after termination");
12481255
assertEq(withCDN, "", "withCDN value should be cleared for dataset");
12491256

1257+
// check status is terminating
1258+
status = viewContract.getDataSetStatus(dataSetId);
1259+
assertEq(uint256(status), uint256(FilecoinWarmStorageService.DataSetStatus.Terminating), "expected Terminating");
1260+
12501261
// Ensure piecesAdded reverts
12511262
console.log("\n4. Testing operations after termination");
12521263
console.log("Testing piecesAdded - should revert (payment terminated)");
@@ -1261,12 +1272,25 @@ contract FilecoinWarmStorageServiceTest is Test {
12611272
pdpServiceWithPayments.piecesAdded(dataSetId, 0, pieces, addPiecesExtraData);
12621273
console.log("[OK] piecesAdded correctly reverted after termination");
12631274

1275+
console.log("Testing dataSetDeleted - should revert (in grace period)");
1276+
vm.prank(address(mockPDPVerifier));
1277+
vm.expectRevert(
1278+
abi.encodeWithSelector(
1279+
Errors.PaymentRailsNotFinalized.selector, dataSetId, info.pdpEndEpoch, info.cdnEndEpoch
1280+
)
1281+
);
1282+
pdpServiceWithPayments.dataSetDeleted(dataSetId, 10, bytes(""));
1283+
12641284
// Wait for payment end epoch to elapse
12651285
console.log("\n5. Rolling past payment end epoch");
12661286
console.log("Current block:", block.number);
12671287
console.log("Rolling to block:", info.pdpEndEpoch + 1);
12681288
vm.roll(info.pdpEndEpoch + 1);
12691289

1290+
// check status is still Terminating as data set is not yet deleted from PDP
1291+
status = viewContract.getDataSetStatus(dataSetId);
1292+
assertEq(uint256(status), uint256(FilecoinWarmStorageService.DataSetStatus.Terminating), "expected Terminating");
1293+
12701294
// Ensure other functions also revert now
12711295
console.log("\n6. Testing operations after payment end epoch");
12721296
// piecesScheduledRemove
@@ -1305,7 +1329,12 @@ contract FilecoinWarmStorageServiceTest is Test {
13051329
);
13061330
pdpServiceWithPayments.nextProvingPeriod(dataSetId, block.number + maxProvingPeriod, 100, "");
13071331
console.log("[OK] nextProvingPeriod correctly reverted");
1332+
console.log("\n7. Testring dataSetDeleted");
1333+
vm.prank(address(mockPDPVerifier));
1334+
pdpServiceWithPayments.dataSetDeleted(dataSetId, 10, bytes(""));
13081335

1336+
status = viewContract.getDataSetStatus(dataSetId);
1337+
assertEq(uint256(status), uint256(FilecoinWarmStorageService.DataSetStatus.NotFound), "expected NotFound");
13091338
console.log("\n=== Test completed successfully! ===");
13101339
}
13111340

0 commit comments

Comments
 (0)