Skip to content

Commit 4335837

Browse files
committed
fixup! feat: add ipniPeerId to PDPOffering in ServiceProviderRegistry
1 parent c1ac78f commit 4335837

8 files changed

+41
-46
lines changed

service_contracts/src/ServiceProviderRegistry.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ contract ServiceProviderRegistry is
4747
/// @notice Maximum length for location field
4848
uint256 private constant MAX_LOCATION_LENGTH = 128;
4949

50-
/// @notice Maximum length for IPNI peer ID
51-
uint256 private constant MAX_IPNI_PEER_ID_LENGTH = 128;
50+
/// @notice Maximum length for IPNI peer ID string (supports at least CIDv1 base32 encoding over an expected 127 bytes max)
51+
uint256 private constant MAX_IPNI_PEER_ID_LENGTH = 256;
5252

5353
/// @notice Burn actor address for burning FIL
5454
address public constant BURN_ACTOR = 0xff00000000000000000000000000000000000063;
@@ -848,7 +848,7 @@ contract ServiceProviderRegistry is
848848
require(pdpOffering.minProvingPeriodInEpochs > 0, "Min proving period must be greater than 0");
849849
require(bytes(pdpOffering.location).length > 0, "Location cannot be empty");
850850
require(bytes(pdpOffering.location).length <= MAX_LOCATION_LENGTH, "Location too long");
851-
require(pdpOffering.ipniPeerId.length <= MAX_IPNI_PEER_ID_LENGTH, "IPNI peer ID too long");
851+
require(bytes(pdpOffering.ipniPeerId).length <= MAX_IPNI_PEER_ID_LENGTH, "IPNI peer ID too long");
852852
}
853853

854854
/// @notice Validate capability key-value pairs

service_contracts/src/ServiceProviderRegistryStorage.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ contract ServiceProviderRegistryStorage {
4444
uint256 minProvingPeriodInEpochs; // Minimum proving period in epochs
4545
string location; // Geographic location of the service provider
4646
IERC20 paymentTokenAddress; // Token contract for payment (IERC20(address(0)) for FIL)
47-
bytes ipniPeerId; // IPNI peer ID (max 128 bytes, can be empty)
47+
string ipniPeerId; // IPNI peer ID as CID string (max 256 chars, can be empty)
4848
}
4949

5050
/// @notice Combined provider and product information for detailed queries

service_contracts/test/FilecoinWarmStorageService.t.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ contract FilecoinWarmStorageServiceTest is Test {
166166
minProvingPeriodInEpochs: 2880,
167167
location: "US-Central",
168168
paymentTokenAddress: IERC20(address(0)), // Payment in FIL
169-
ipniPeerId: hex""
169+
ipniPeerId: ""
170170
})
171171
),
172172
new string[](0),
@@ -190,7 +190,7 @@ contract FilecoinWarmStorageServiceTest is Test {
190190
minProvingPeriodInEpochs: 2880,
191191
location: "US-Central",
192192
paymentTokenAddress: IERC20(address(0)), // Payment in FIL
193-
ipniPeerId: hex""
193+
ipniPeerId: ""
194194
})
195195
),
196196
new string[](0),
@@ -214,7 +214,7 @@ contract FilecoinWarmStorageServiceTest is Test {
214214
minProvingPeriodInEpochs: 2880,
215215
location: "US-Central",
216216
paymentTokenAddress: IERC20(address(0)), // Payment in FIL
217-
ipniPeerId: hex""
217+
ipniPeerId: ""
218218
})
219219
),
220220
new string[](0),
@@ -238,7 +238,7 @@ contract FilecoinWarmStorageServiceTest is Test {
238238
minProvingPeriodInEpochs: 2880,
239239
location: "US-Central",
240240
paymentTokenAddress: IERC20(address(0)), // Payment in FIL
241-
ipniPeerId: hex""
241+
ipniPeerId: ""
242242
})
243243
),
244244
new string[](0),

service_contracts/test/FilecoinWarmStorageServiceOwner.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ contract FilecoinWarmStorageServiceOwnerTest is Test {
150150
minProvingPeriodInEpochs: 2880,
151151
location: "US",
152152
paymentTokenAddress: IERC20(address(0)),
153-
ipniPeerId: hex""
153+
ipniPeerId: ""
154154
})
155155
),
156156
capabilityKeys,

service_contracts/test/ProviderValidation.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ contract ProviderValidationTest is Test {
126126
minProvingPeriodInEpochs: 2880,
127127
location: "US-West",
128128
paymentTokenAddress: IERC20(address(0)), // Payment in FIL
129-
ipniPeerId: hex""
129+
ipniPeerId: ""
130130
})
131131
),
132132
new string[](0),
@@ -165,7 +165,7 @@ contract ProviderValidationTest is Test {
165165
minProvingPeriodInEpochs: 2880,
166166
location: "US-West",
167167
paymentTokenAddress: IERC20(address(0)), // Payment in FIL
168-
ipniPeerId: hex""
168+
ipniPeerId: ""
169169
})
170170
),
171171
new string[](0),

service_contracts/test/ServiceProviderRegistry.t.sol

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ contract ServiceProviderRegistryTest is Test {
6969
minProvingPeriodInEpochs: 2880,
7070
location: "US-East",
7171
paymentTokenAddress: IERC20(address(0)), // Payment in FIL
72-
ipniPeerId: hex""
72+
ipniPeerId: ""
7373
});
7474

7575
// Encode PDP data
@@ -113,7 +113,7 @@ contract ServiceProviderRegistryTest is Test {
113113
minProvingPeriodInEpochs: 2880,
114114
location: "US-East",
115115
paymentTokenAddress: IERC20(address(0)), // Payment in FIL
116-
ipniPeerId: hex""
116+
ipniPeerId: ""
117117
});
118118

119119
// Encode PDP data
@@ -185,7 +185,7 @@ contract ServiceProviderRegistryTest is Test {
185185
minProvingPeriodInEpochs: 2880,
186186
location: "US-East",
187187
paymentTokenAddress: IERC20(address(0)), // Payment in FIL
188-
ipniPeerId: hex""
188+
ipniPeerId: ""
189189
});
190190

191191
bytes memory encodedData = abi.encode(pdpData);
@@ -228,7 +228,7 @@ contract ServiceProviderRegistryTest is Test {
228228
minProvingPeriodInEpochs: 2880,
229229
location: "US-East",
230230
paymentTokenAddress: IERC20(address(0)),
231-
ipniPeerId: hex""
231+
ipniPeerId: ""
232232
});
233233

234234
bytes memory encodedData = abi.encode(pdpData);
@@ -264,7 +264,7 @@ contract ServiceProviderRegistryTest is Test {
264264
minProvingPeriodInEpochs: 2880,
265265
location: "US-East",
266266
paymentTokenAddress: IERC20(address(0)), // Payment in FIL
267-
ipniPeerId: hex""
267+
ipniPeerId: ""
268268
});
269269

270270
bytes memory encodedData = abi.encode(pdpData);
@@ -329,7 +329,7 @@ contract ServiceProviderRegistryTest is Test {
329329
minProvingPeriodInEpochs: 2880,
330330
location: "US-East",
331331
paymentTokenAddress: IERC20(address(0)), // Payment in FIL
332-
ipniPeerId: hex""
332+
ipniPeerId: ""
333333
});
334334

335335
// Encode PDP data
@@ -568,7 +568,7 @@ contract ServiceProviderRegistryTest is Test {
568568
minProvingPeriodInEpochs: 1,
569569
location: "US",
570570
paymentTokenAddress: IERC20(address(0)),
571-
ipniPeerId: hex""
571+
ipniPeerId: ""
572572
});
573573
return abi.encode(pdpOffering);
574574
}

service_contracts/test/ServiceProviderRegistryFull.t.sol

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ contract ServiceProviderRegistryFullTest is Test {
8383
minProvingPeriodInEpochs: 2880, // 1 day in epochs (30 second blocks)
8484
location: "North America",
8585
paymentTokenAddress: IERC20(address(0)), // Payment in FIL
86-
ipniPeerId: hex""
86+
ipniPeerId: ""
8787
});
8888

8989
updatedPDPData = ServiceProviderRegistryStorage.PDPOffering({
@@ -96,7 +96,7 @@ contract ServiceProviderRegistryFullTest is Test {
9696
minProvingPeriodInEpochs: 1440, // 12 hours in epochs
9797
location: "Europe",
9898
paymentTokenAddress: IERC20(address(0)), // Payment in FIL
99-
ipniPeerId: hex""
99+
ipniPeerId: ""
100100
});
101101

102102
// Encode PDP data
@@ -1807,11 +1807,12 @@ contract ServiceProviderRegistryFullTest is Test {
18071807
assertEq(clearedTier, "", "Tier key should be cleared after update");
18081808
}
18091809

1810+
// ========== IPNI Peer ID Validation Tests ==========
18101811
// ========== IPNI Peer ID Validation Tests ==========
18111812

18121813
function testRegisterWithEmptyIpniPeerId() public {
18131814
ServiceProviderRegistryStorage.PDPOffering memory validPDP = defaultPDPData;
1814-
validPDP.ipniPeerId = hex"";
1815+
validPDP.ipniPeerId = "";
18151816
bytes memory encodedPDP = abi.encode(validPDP);
18161817
string[] memory emptyKeys = new string[](0);
18171818
string[] memory emptyValues = new string[](0);
@@ -1830,14 +1831,13 @@ contract ServiceProviderRegistryFullTest is Test {
18301831

18311832
// Verify it was stored correctly
18321833
(ServiceProviderRegistryStorage.PDPOffering memory stored,,) = registry.getPDPService(providerId);
1833-
assertEq(stored.ipniPeerId.length, 0, "Empty IPNI peer ID should be stored");
1834+
assertEq(bytes(stored.ipniPeerId).length, 0, "Empty IPNI peer ID should be stored");
18341835
}
18351836

18361837
function testRegisterWithMaxLengthIpniPeerId() public {
1837-
bytes memory maxPeerId = new bytes(128);
1838-
for (uint256 i = 0; i < 128; i++) {
1839-
maxPeerId[i] = 0xFF;
1840-
}
1838+
// Create a 256-character string (max length for CIDv1 base32)
1839+
string memory maxPeerId = "bafzbeiaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
1840+
require(bytes(maxPeerId).length == 256, "Test string should be exactly 256 chars");
18411841

18421842
ServiceProviderRegistryStorage.PDPOffering memory validPDP = defaultPDPData;
18431843
validPDP.ipniPeerId = maxPeerId;
@@ -1855,19 +1855,18 @@ contract ServiceProviderRegistryFullTest is Test {
18551855
emptyKeys,
18561856
emptyValues
18571857
);
1858-
assertEq(providerId, 1, "Should succeed with 128-byte ipniPeerId");
1858+
assertEq(providerId, 1, "Should succeed with 256-char ipniPeerId");
18591859

18601860
// Verify it was stored correctly
18611861
(ServiceProviderRegistryStorage.PDPOffering memory stored,,) = registry.getPDPService(providerId);
1862-
assertEq(stored.ipniPeerId.length, 128, "128-byte IPNI peer ID should be stored");
1862+
assertEq(bytes(stored.ipniPeerId).length, 256, "256-char IPNI peer ID should be stored");
18631863
assertEq(stored.ipniPeerId, maxPeerId, "IPNI peer ID should match");
18641864
}
18651865

18661866
function testRegisterWithTooLongIpniPeerId() public {
1867-
bytes memory longPeerId = new bytes(129);
1868-
for (uint256 i = 0; i < 129; i++) {
1869-
longPeerId[i] = 0xFF;
1870-
}
1867+
// Create a 257-character string (exceeds max)
1868+
string memory longPeerId = "bafzbeiaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
1869+
require(bytes(longPeerId).length == 257, "Test string should be exactly 257 chars");
18711870

18721871
ServiceProviderRegistryStorage.PDPOffering memory invalidPDP = defaultPDPData;
18731872
invalidPDP.ipniPeerId = longPeerId;
@@ -1889,9 +1888,8 @@ contract ServiceProviderRegistryFullTest is Test {
18891888
}
18901889

18911890
function testRegisterWithRealisticIpniPeerId() public {
1892-
// Typical libp2p peer ID is ~38 bytes (multihash of public key)
1893-
// Format: 0x1220<32-byte sha256 hash> for a total of 34 bytes
1894-
bytes memory realisticPeerId = hex"12205f8bb7e5e0e8e5f8e5e0e8e5f8e5e0e8e5f8e5e0e8e5f8e5e0e8e5f8abcdef01";
1891+
// Typical CIDv0 peer ID (base58btc) - 46 characters
1892+
string memory realisticPeerId = "QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5N";
18951893

18961894
ServiceProviderRegistryStorage.PDPOffering memory validPDP = defaultPDPData;
18971895
validPDP.ipniPeerId = realisticPeerId;
@@ -1913,7 +1911,7 @@ contract ServiceProviderRegistryFullTest is Test {
19131911
// Verify it was stored correctly
19141912
(ServiceProviderRegistryStorage.PDPOffering memory stored,,) = registry.getPDPService(providerId);
19151913
assertEq(stored.ipniPeerId, realisticPeerId, "IPNI peer ID should be stored correctly");
1916-
assertEq(stored.ipniPeerId.length, 34, "Realistic IPNI peer ID should be 34 bytes");
1914+
assertEq(bytes(stored.ipniPeerId).length, 46, "Realistic IPNI peer ID should be 46 chars");
19171915
}
19181916

19191917
function testUpdateIpniPeerId() public {
@@ -1934,10 +1932,10 @@ contract ServiceProviderRegistryFullTest is Test {
19341932

19351933
// Verify initial state
19361934
(ServiceProviderRegistryStorage.PDPOffering memory initialStored,,) = registry.getPDPService(providerId);
1937-
assertEq(initialStored.ipniPeerId.length, 0, "Initial IPNI peer ID should be empty");
1935+
assertEq(bytes(initialStored.ipniPeerId).length, 0, "Initial IPNI peer ID should be empty");
19381936

1939-
// Update with a peer ID
1940-
bytes memory newPeerId = hex"12205f8bb7e5e0e8e5f8e5e0e8e5f8e5e0e8e5f8e5e0e8e5f8e5e0e8e5f8abcdef01";
1937+
// Update with a peer ID (CIDv1 base32)
1938+
string memory newPeerId = "bafzbeic5w7yp4ha4g5dppc7wf4ha4g5dppc7wf4ha4g5d";
19411939
ServiceProviderRegistryStorage.PDPOffering memory updatedData = updatedPDPData;
19421940
updatedData.ipniPeerId = newPeerId;
19431941
bytes memory encodedUpdatedData = abi.encode(updatedData);
@@ -1948,7 +1946,7 @@ contract ServiceProviderRegistryFullTest is Test {
19481946
// Verify update
19491947
(ServiceProviderRegistryStorage.PDPOffering memory updatedStored,,) = registry.getPDPService(providerId);
19501948
assertEq(updatedStored.ipniPeerId, newPeerId, "IPNI peer ID should be updated");
1951-
assertEq(updatedStored.ipniPeerId.length, 34, "Updated IPNI peer ID should be 34 bytes");
1949+
assertEq(bytes(updatedStored.ipniPeerId).length, 46, "Updated IPNI peer ID should be 46 chars");
19521950
}
19531951

19541952
function testUpdateWithTooLongIpniPeerId() public {
@@ -1967,11 +1965,8 @@ contract ServiceProviderRegistryFullTest is Test {
19671965
emptyValues
19681966
);
19691967

1970-
// Try to update with too long peer ID
1971-
bytes memory longPeerId = new bytes(129);
1972-
for (uint256 i = 0; i < 129; i++) {
1973-
longPeerId[i] = 0xAB;
1974-
}
1968+
// Try to update with too long peer ID (257 chars)
1969+
string memory longPeerId = "bafzbeiaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
19751970

19761971
ServiceProviderRegistryStorage.PDPOffering memory invalidData = updatedPDPData;
19771972
invalidData.ipniPeerId = longPeerId;

service_contracts/test/ServiceProviderRegistryPagination.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ contract ServiceProviderRegistryPaginationTest is Test {
4949
minProvingPeriodInEpochs: 10,
5050
location: "US-WEST",
5151
paymentTokenAddress: IERC20(address(0)),
52-
ipniPeerId: hex""
52+
ipniPeerId: ""
5353
});
5454

5555
encodedDefaultPDPData = registry.encodePDPOffering(defaultPDPData);

0 commit comments

Comments
 (0)