Skip to content

Commit fe025c3

Browse files
committed
fix: rename to collectorId and use collectorId on subgraph service
1 parent 09a6fa8 commit fe025c3

File tree

9 files changed

+233
-160
lines changed

9 files changed

+233
-160
lines changed

packages/horizon/contracts/interfaces/IPaymentsCollector.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface IPaymentsCollector {
2424
*/
2525
event PaymentCollected(
2626
IGraphPayments.PaymentTypes paymentType,
27-
address indexed paymentId,
27+
bytes32 indexed collectorId,
2828
address indexed payer,
2929
address receiver,
3030
address indexed dataService,

packages/horizon/contracts/interfaces/ITAPCollector.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface ITAPCollector is IPaymentsCollector {
2626
/// @notice The Receipt Aggregate Voucher (RAV) struct
2727
struct ReceiptAggregateVoucher {
2828
// The ID of the payment
29-
address paymentId;
29+
bytes32 collectorId;
3030
// The address of the payer the RAV was issued by
3131
address payer;
3232
// The address of the data service the RAV was issued to

packages/horizon/contracts/payments/collectors/TAPCollector.sol

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ contract TAPCollector is EIP712, GraphDirectory, ITAPCollector {
3636
mapping(address signer => PayerAuthorization authorizedSigner) public authorizedSigners;
3737

3838
/// @notice Tracks the amount of tokens already collected by a data service from a payer to a receiver
39-
mapping(address dataService => mapping(address paymentId => mapping(address receiver => mapping(address payer => uint256 tokens))))
39+
mapping(address dataService => mapping(bytes32 collectorId => mapping(address receiver => mapping(address payer => uint256 tokens))))
4040
public tokensCollected;
4141

4242
/// @notice The duration (in seconds) in which a signer is thawing before they can be revoked
@@ -182,7 +182,7 @@ contract TAPCollector is EIP712, GraphDirectory, ITAPCollector {
182182
address payer = authorizedSigners[signer].payer;
183183
require(signedRAV.rav.payer == payer, TAPCollectorInvalidRAVPayer(payer, signedRAV.rav.payer));
184184

185-
address paymentId = signedRAV.rav.paymentId;
185+
bytes32 collectorId = signedRAV.rav.collectorId;
186186
address dataService = signedRAV.rav.dataService;
187187
address receiver = signedRAV.rav.serviceProvider;
188188

@@ -200,7 +200,7 @@ contract TAPCollector is EIP712, GraphDirectory, ITAPCollector {
200200
uint256 tokensToCollect = 0;
201201
{
202202
uint256 tokensRAV = signedRAV.rav.valueAggregate;
203-
uint256 tokensAlreadyCollected = tokensCollected[dataService][paymentId][receiver][payer];
203+
uint256 tokensAlreadyCollected = tokensCollected[dataService][collectorId][receiver][payer];
204204
require(
205205
tokensRAV > tokensAlreadyCollected,
206206
TAPCollectorInconsistentRAVTokens(tokensRAV, tokensAlreadyCollected)
@@ -218,11 +218,11 @@ contract TAPCollector is EIP712, GraphDirectory, ITAPCollector {
218218
}
219219

220220
if (tokensToCollect > 0) {
221-
tokensCollected[dataService][paymentId][receiver][payer] += tokensToCollect;
221+
tokensCollected[dataService][collectorId][receiver][payer] += tokensToCollect;
222222
_graphPaymentsEscrow().collect(_paymentType, payer, receiver, tokensToCollect, dataService, dataServiceCut);
223223
}
224224

225-
emit PaymentCollected(_paymentType, paymentId, payer, receiver, dataService, tokensToCollect);
225+
emit PaymentCollected(_paymentType, collectorId, payer, receiver, dataService, tokensToCollect);
226226
emit RAVCollected(
227227
payer,
228228
dataService,

packages/horizon/test/payments/tap-collector/TAPCollector.t.sol

+3-3
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ contract TAPCollectorTest is HorizonStakingSharedTest, PaymentsEscrowSharedTest
142142
(address _payer, , ) = tapCollector.authorizedSigners(_signer);
143143
uint256 tokensAlreadyCollected = tapCollector.tokensCollected(
144144
signedRAV.rav.dataService,
145-
signedRAV.rav.paymentId,
145+
signedRAV.rav.collectorId,
146146
signedRAV.rav.serviceProvider,
147147
_payer
148148
);
@@ -153,7 +153,7 @@ contract TAPCollectorTest is HorizonStakingSharedTest, PaymentsEscrowSharedTest
153153
vm.expectEmit(address(tapCollector));
154154
emit IPaymentsCollector.PaymentCollected(
155155
_paymentType,
156-
signedRAV.rav.paymentId,
156+
signedRAV.rav.collectorId,
157157
_payer,
158158
signedRAV.rav.serviceProvider,
159159
signedRAV.rav.dataService,
@@ -175,7 +175,7 @@ contract TAPCollectorTest is HorizonStakingSharedTest, PaymentsEscrowSharedTest
175175

176176
uint256 tokensCollectedAfter = tapCollector.tokensCollected(
177177
signedRAV.rav.dataService,
178-
signedRAV.rav.paymentId,
178+
signedRAV.rav.collectorId,
179179
signedRAV.rav.serviceProvider,
180180
_payer
181181
);

packages/horizon/test/payments/tap-collector/collect/collect.t.sol

+13-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ contract TAPCollectorCollectTest is TAPCollectorTest {
4848
) private pure returns (ITAPCollector.ReceiptAggregateVoucher memory rav) {
4949
return
5050
ITAPCollector.ReceiptAggregateVoucher({
51-
paymentId: _allocationId,
51+
collectorId: bytes32(uint256(uint160(_allocationId))),
5252
payer: _payer,
5353
dataService: _collector,
5454
serviceProvider: _indexer,
@@ -408,7 +408,12 @@ contract TAPCollectorCollectTest is TAPCollectorTest {
408408
bytes memory data = _getQueryFeeEncodedData(signerPrivateKey, params);
409409

410410
resetPrank(users.verifier);
411-
uint256 tokensAlreadyCollected = tapCollector.tokensCollected(users.verifier, _allocationId, users.indexer, users.gateway);
411+
uint256 tokensAlreadyCollected = tapCollector.tokensCollected(
412+
users.verifier,
413+
bytes32(uint256(uint160(_allocationId))),
414+
users.indexer,
415+
users.gateway
416+
);
412417
tokensToCollect = bound(tokensToCollect, tokens - tokensAlreadyCollected + 1, type(uint128).max);
413418

414419
vm.expectRevert(
@@ -448,7 +453,12 @@ contract TAPCollectorCollectTest is TAPCollectorTest {
448453

449454
for (uint256 i = 0; i < numAllocations; i++) {
450455
assertEq(
451-
tapCollector.tokensCollected(collectTestParams[i].collector, collectTestParams[i].allocationId, collectTestParams[i].indexer, collectTestParams[i].payer),
456+
tapCollector.tokensCollected(
457+
collectTestParams[i].collector,
458+
bytes32(uint256(uint160(collectTestParams[i].allocationId))),
459+
collectTestParams[i].indexer,
460+
collectTestParams[i].payer
461+
),
452462
collectTestParams[i].tokens,
453463
"Incorrect tokens collected for allocation"
454464
);

packages/subgraph-service/contracts/SubgraphService.sol

+7-1
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,13 @@ contract SubgraphService is
536536
*/
537537
function _collectQueryFees(ITAPCollector.SignedRAV memory _signedRav) private returns (uint256 feesCollected) {
538538
address indexer = _signedRav.rav.serviceProvider;
539-
address allocationId = abi.decode(_signedRav.rav.metadata, (address));
539+
540+
// Check that the collectorId fits in an address (160 bits)
541+
require(
542+
uint256(_signedRav.rav.collectorId) < (1 << 160),
543+
SubgraphServiceInvalidCollectorId(_signedRav.rav.collectorId)
544+
);
545+
address allocationId = address(uint160(uint256(_signedRav.rav.collectorId)));
540546
Allocation.State memory allocation = _allocations.get(allocationId);
541547

542548
// Check RAV is consistent - RAV indexer must match the allocation's indexer

packages/subgraph-service/contracts/interfaces/ISubgraphService.sol

+6
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ interface ISubgraphService is IDataServiceFees {
124124
*/
125125
error SubgraphServiceInvalidZeroStakeToFeesRatio();
126126

127+
/**
128+
* @notice Thrown when collectorId is too large for an address
129+
* @param collectorId The collectorId that is too large
130+
*/
131+
error SubgraphServiceInvalidCollectorId(bytes32 collectorId);
132+
127133
/**
128134
* @notice Force close a stale allocation
129135
* @dev This function can be permissionlessly called when the allocation is stale. This

0 commit comments

Comments
 (0)