Skip to content

Commit 2af2e68

Browse files
committed
chore: rename collectorId to collectionId
Signed-off-by: Tomás Migone <[email protected]>
1 parent fe025c3 commit 2af2e68

File tree

9 files changed

+42
-32
lines changed

9 files changed

+42
-32
lines changed

packages/horizon/contracts/interfaces/IPaymentsCollector.sol

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ interface IPaymentsCollector {
1717
/**
1818
* @notice Emitted when a payment is collected
1919
* @param paymentType The payment type collected as defined by {IGraphPayments}
20+
* @param collectionId The id for the collection. Can be used at the discretion of the collector to group multiple payments.
2021
* @param payer The address of the payer
2122
* @param receiver The address of the receiver
2223
* @param dataService The address of the data service
2324
* @param tokens The amount of tokens being collected
2425
*/
2526
event PaymentCollected(
2627
IGraphPayments.PaymentTypes paymentType,
27-
bytes32 indexed collectorId,
28+
bytes32 indexed collectionId,
2829
address indexed payer,
2930
address receiver,
3031
address indexed dataService,

packages/horizon/contracts/interfaces/ITAPCollector.sol

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ interface ITAPCollector is IPaymentsCollector {
2525

2626
/// @notice The Receipt Aggregate Voucher (RAV) struct
2727
struct ReceiptAggregateVoucher {
28-
// The ID of the payment
29-
bytes32 collectorId;
28+
// The ID of the collection "bucket" the RAV belongs to. Note that multiple RAVs can be collected for the same collection id.
29+
bytes32 collectionId;
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
@@ -82,6 +82,7 @@ interface ITAPCollector is IPaymentsCollector {
8282

8383
/**
8484
* @notice Emitted when a RAV is collected
85+
* @param collectionId The ID of the collection "bucket" the RAV belongs to.
8586
* @param payer The address of the payer
8687
* @param dataService The address of the data service
8788
* @param serviceProvider The address of the service provider
@@ -91,9 +92,10 @@ interface ITAPCollector is IPaymentsCollector {
9192
* @param signature The signature of the RAV
9293
*/
9394
event RAVCollected(
95+
bytes32 indexed collectionId,
9496
address indexed payer,
97+
address serviceProvider,
9598
address indexed dataService,
96-
address indexed serviceProvider,
9799
uint64 timestampNs,
98100
uint128 valueAggregate,
99101
bytes metadata,

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

+13-7
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ contract TAPCollector is EIP712, GraphDirectory, ITAPCollector {
3535
/// @notice Authorization details for payer-signer pairs
3636
mapping(address signer => PayerAuthorization authorizedSigner) public authorizedSigners;
3737

38-
/// @notice Tracks the amount of tokens already collected by a data service from a payer to a receiver
39-
mapping(address dataService => mapping(bytes32 collectorId => mapping(address receiver => mapping(address payer => uint256 tokens))))
38+
/// @notice Tracks the amount of tokens already collected by a data service from a payer to a receiver.
39+
/// @dev The collectionId provides a secondary key for grouping payment tracking if needed. Data services that do not require
40+
/// grouping can use the same collectionId for all payments (0x00 or some other default value).
41+
mapping(address dataService => mapping(bytes32 collectionId => mapping(address receiver => mapping(address payer => uint256 tokens))))
4042
public tokensCollected;
4143

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

185-
bytes32 collectorId = signedRAV.rav.collectorId;
187+
bytes32 collectionId = signedRAV.rav.collectionId;
186188
address dataService = signedRAV.rav.dataService;
187189
address receiver = signedRAV.rav.serviceProvider;
188190

@@ -200,7 +202,7 @@ contract TAPCollector is EIP712, GraphDirectory, ITAPCollector {
200202
uint256 tokensToCollect = 0;
201203
{
202204
uint256 tokensRAV = signedRAV.rav.valueAggregate;
203-
uint256 tokensAlreadyCollected = tokensCollected[dataService][collectorId][receiver][payer];
205+
uint256 tokensAlreadyCollected = tokensCollected[dataService][collectionId][receiver][payer];
204206
require(
205207
tokensRAV > tokensAlreadyCollected,
206208
TAPCollectorInconsistentRAVTokens(tokensRAV, tokensAlreadyCollected)
@@ -218,20 +220,24 @@ contract TAPCollector is EIP712, GraphDirectory, ITAPCollector {
218220
}
219221

220222
if (tokensToCollect > 0) {
221-
tokensCollected[dataService][collectorId][receiver][payer] += tokensToCollect;
223+
tokensCollected[dataService][collectionId][receiver][payer] += tokensToCollect;
222224
_graphPaymentsEscrow().collect(_paymentType, payer, receiver, tokensToCollect, dataService, dataServiceCut);
223225
}
224226

225-
emit PaymentCollected(_paymentType, collectorId, payer, receiver, dataService, tokensToCollect);
227+
emit PaymentCollected(_paymentType, collectionId, payer, receiver, dataService, tokensToCollect);
228+
229+
// This event is emitted to allow reconstructing RAV history with onchain data.
226230
emit RAVCollected(
231+
collectionId,
227232
payer,
228-
dataService,
229233
receiver,
234+
dataService,
230235
signedRAV.rav.timestampNs,
231236
signedRAV.rav.valueAggregate,
232237
signedRAV.rav.metadata,
233238
signedRAV.signature
234239
);
240+
235241
return tokensToCollect;
236242
}
237243

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

+5-4
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.collectorId,
145+
signedRAV.rav.collectionId,
146146
signedRAV.rav.serviceProvider,
147147
_payer
148148
);
@@ -153,17 +153,18 @@ contract TAPCollectorTest is HorizonStakingSharedTest, PaymentsEscrowSharedTest
153153
vm.expectEmit(address(tapCollector));
154154
emit IPaymentsCollector.PaymentCollected(
155155
_paymentType,
156-
signedRAV.rav.collectorId,
156+
signedRAV.rav.collectionId,
157157
_payer,
158158
signedRAV.rav.serviceProvider,
159159
signedRAV.rav.dataService,
160160
tokensToCollect
161161
);
162162
vm.expectEmit(address(tapCollector));
163163
emit ITAPCollector.RAVCollected(
164+
signedRAV.rav.collectionId,
164165
_payer,
165-
signedRAV.rav.dataService,
166166
signedRAV.rav.serviceProvider,
167+
signedRAV.rav.dataService,
167168
signedRAV.rav.timestampNs,
168169
signedRAV.rav.valueAggregate,
169170
signedRAV.rav.metadata,
@@ -175,7 +176,7 @@ contract TAPCollectorTest is HorizonStakingSharedTest, PaymentsEscrowSharedTest
175176

176177
uint256 tokensCollectedAfter = tapCollector.tokensCollected(
177178
signedRAV.rav.dataService,
178-
signedRAV.rav.collectorId,
179+
signedRAV.rav.collectionId,
179180
signedRAV.rav.serviceProvider,
180181
_payer
181182
);

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

+1-1
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-
collectorId: bytes32(uint256(uint160(_allocationId))),
51+
collectionId: bytes32(uint256(uint160(_allocationId))),
5252
payer: _payer,
5353
dataService: _collector,
5454
serviceProvider: _indexer,

packages/subgraph-service/contracts/SubgraphService.sol

+4-4
Original file line numberDiff line numberDiff line change
@@ -537,12 +537,12 @@ contract SubgraphService is
537537
function _collectQueryFees(ITAPCollector.SignedRAV memory _signedRav) private returns (uint256 feesCollected) {
538538
address indexer = _signedRav.rav.serviceProvider;
539539

540-
// Check that the collectorId fits in an address (160 bits)
540+
// Check that collectionId (256 bits) is a valid address (160 bits)
541541
require(
542-
uint256(_signedRav.rav.collectorId) < (1 << 160),
543-
SubgraphServiceInvalidCollectorId(_signedRav.rav.collectorId)
542+
uint256(_signedRav.rav.collectionId) <= type(uint160).max,
543+
SubgraphServiceInvalidCollectionId(_signedRav.rav.collectionId)
544544
);
545-
address allocationId = address(uint160(uint256(_signedRav.rav.collectorId)));
545+
address allocationId = address(uint160(uint256(_signedRav.rav.collectionId)));
546546
Allocation.State memory allocation = _allocations.get(allocationId);
547547

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

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ interface ISubgraphService is IDataServiceFees {
125125
error SubgraphServiceInvalidZeroStakeToFeesRatio();
126126

127127
/**
128-
* @notice Thrown when collectorId is too large for an address
129-
* @param collectorId The collectorId that is too large
128+
* @notice Thrown when collectionId is not a valid address
129+
* @param collectionId The collectionId
130130
*/
131-
error SubgraphServiceInvalidCollectorId(bytes32 collectorId);
131+
error SubgraphServiceInvalidCollectionId(bytes32 collectionId);
132132

133133
/**
134134
* @notice Force close a stale allocation

packages/subgraph-service/test/subgraphService/SubgraphService.t.sol

+3-3
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,12 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest {
264264

265265
function _handleQueryFeeCollection(address _indexer, bytes memory _data) private returns (uint256 paymentCollected) {
266266
ITAPCollector.SignedRAV memory signedRav = abi.decode(_data, (ITAPCollector.SignedRAV));
267-
Allocation.State memory allocation = subgraphService.getAllocation(address(uint160(uint256(signedRav.rav.collectorId))));
267+
Allocation.State memory allocation = subgraphService.getAllocation(address(uint160(uint256(signedRav.rav.collectionId))));
268268
(address payer, , ) = tapCollector.authorizedSigners(_recoverRAVSigner(signedRav));
269269

270270
uint256 tokensCollected = tapCollector.tokensCollected(
271271
address(subgraphService),
272-
signedRav.rav.collectorId,
272+
signedRav.rav.collectionId,
273273
_indexer,
274274
payer
275275
);
@@ -334,7 +334,7 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest {
334334
CollectPaymentData memory collectPaymentDataAfter
335335
) private view {
336336
ITAPCollector.SignedRAV memory signedRav = abi.decode(_data, (ITAPCollector.SignedRAV));
337-
Allocation.State memory allocation = subgraphService.getAllocation(address(uint160(uint256(signedRav.rav.collectorId))));
337+
Allocation.State memory allocation = subgraphService.getAllocation(address(uint160(uint256(signedRav.rav.collectionId))));
338338
QueryFeeData memory queryFeeData = _queryFeeData(allocation.subgraphDeploymentId);
339339
uint256 tokensProtocol = _paymentCollected.mulPPMRoundUp(queryFeeData.protocolPaymentCut);
340340
uint256 curationTokens = (_paymentCollected - tokensProtocol).mulPPMRoundUp(queryFeeData.curationCut);

packages/subgraph-service/test/subgraphService/collect/query/query.t.sol

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ contract SubgraphServiceRegisterTest is SubgraphServiceTest {
4242

4343
function _getRAV(
4444
address indexer,
45-
bytes32 collectorId,
45+
bytes32 collectionId,
4646
uint128 tokens
4747
) private view returns (ITAPCollector.ReceiptAggregateVoucher memory rav) {
4848
return
4949
ITAPCollector.ReceiptAggregateVoucher({
50-
collectorId: collectorId,
50+
collectionId: collectionId,
5151
payer: users.gateway,
5252
dataService: address(subgraphService),
5353
serviceProvider: indexer,
@@ -172,15 +172,15 @@ contract SubgraphServiceRegisterTest is SubgraphServiceTest {
172172
subgraphService.collect(newIndexer, paymentType, data);
173173
}
174174

175-
function testCollect_QueryFees_RevertWhen_CollectorIdTooLarge() public useIndexer useAllocation(1000 ether) {
176-
bytes32 collectorId = keccak256(abi.encodePacked("Large collector id, longer than 160 bits"));
177-
ITAPCollector.ReceiptAggregateVoucher memory rav = _getRAV(users.indexer, collectorId, 1000 ether);
175+
function testCollect_QueryFees_RevertWhen_CollectionIdTooLarge() public useIndexer useAllocation(1000 ether) {
176+
bytes32 collectionId = keccak256(abi.encodePacked("Large collection id, longer than 160 bits"));
177+
ITAPCollector.ReceiptAggregateVoucher memory rav = _getRAV(users.indexer, collectionId, 1000 ether);
178178
bytes32 messageHash = tapCollector.encodeRAV(rav);
179179
(uint8 v, bytes32 r, bytes32 s) = vm.sign(signerPrivateKey, messageHash);
180180
bytes memory signature = abi.encodePacked(r, s, v);
181181
ITAPCollector.SignedRAV memory signedRAV = ITAPCollector.SignedRAV(rav, signature);
182182
bytes memory data = abi.encode(signedRAV);
183-
vm.expectRevert(abi.encodeWithSelector(ISubgraphService.SubgraphServiceInvalidCollectorId.selector, collectorId));
183+
vm.expectRevert(abi.encodeWithSelector(ISubgraphService.SubgraphServiceInvalidCollectionId.selector, collectionId));
184184
subgraphService.collect(users.indexer, IGraphPayments.PaymentTypes.QueryFee, data);
185185
}
186186
}

0 commit comments

Comments
 (0)