Skip to content

Commit d9c07c5

Browse files
f - simplify deadline, reduce errors
1 parent 8d8695d commit d9c07c5

File tree

12 files changed

+62
-75
lines changed

12 files changed

+62
-75
lines changed

IndexingPaymentsTodo.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
* Support a way for gateway to shop an agreement around? Deadline + dedup key? So only one agreement with the dedupe key can be accepted?
1414
* If an indexer closes an allocation, what should happen to the accepeted agreement?
1515
* test_SubgraphService_CollectIndexingFee_Integration fails with PaymentsEscrowInconsistentCollection
16-
* Reduce the number of errors declared and returned
1716
* Switch `duration` for `endsAt`?
17+
* Check that UUID-v4 fits in `bytes16`
18+
* Test `upgrade` paths
19+
* Test lock stake
1820

1921
# Done
2022

23+
* DONE: ~~Reduce the number of errors declared and returned~~
2124
* DONE: ~~Support `DisputeManager`~~
2225
* DONE: ~~Check upgrade conditions. Support indexing agreement upgradability, so that there is a mechanism to adjust the rates without having to cancel and start over.~~
2326
* DONE: ~~Maybe check that the epoch the indexer is sending is the one the transaction will be run in?~~

packages/horizon/contracts/interfaces/IRecurringCollector.sol

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface IRecurringCollector is IAuthorizable, IPaymentsCollector {
2626
// The agreement ID of the RCA
2727
bytes16 agreementId;
2828
// The deadline for accepting the RCA
29-
uint256 acceptDeadline;
29+
uint256 deadline;
3030
// The duration of the RCA in seconds
3131
uint256 duration;
3232
// The address of the payer the RCA was issued by
@@ -61,7 +61,7 @@ interface IRecurringCollector is IAuthorizable, IPaymentsCollector {
6161
// The agreement ID
6262
bytes16 agreementId;
6363
// The deadline for upgrading
64-
uint256 upgradeDeadline;
64+
uint256 deadline;
6565
// The duration of the agreement in seconds
6666
uint256 duration;
6767
// The maximum amount of tokens that can be collected in the first collection
@@ -184,23 +184,17 @@ interface IRecurringCollector is IAuthorizable, IPaymentsCollector {
184184
);
185185

186186
/**
187-
* Thrown when calling cancel() for an agreement not owned by the calling data service
187+
* Thrown when interacting with an agreement not owned by the message sender
188188
* @param agreementId The agreement ID
189-
* @param dataService The address of the data service
189+
* @param unauthorizedDataService The address of the unauthorized data service
190190
*/
191-
error RecurringCollectorDataServiceNotAuthorized(bytes16 agreementId, address dataService);
191+
error RecurringCollectorDataServiceNotAuthorized(bytes16 agreementId, address unauthorizedDataService);
192192

193193
/**
194-
* Thrown when calling accept() for an agreement with an elapsed acceptance deadline
195-
* @param elapsedAt The timestamp when the acceptance deadline elapsed
194+
* Thrown when interacting with an agreement with an elapsed deadline
195+
* @param elapsedAt The timestamp when the deadline elapsed
196196
*/
197-
error RecurringCollectorAgreementAcceptanceElapsed(uint256 elapsedAt);
198-
199-
/**
200-
* Thrown when calling upgrade() for an agreement with an elapsed upgrade deadline
201-
* @param elapsedAt The timestamp when the upgrade deadline elapsed
202-
*/
203-
error RecurringCollectorAgreementUpgradeElapsed(uint256 elapsedAt);
197+
error RecurringCollectorAgreementDeadlineElapsed(uint256 elapsedAt);
204198

205199
/**
206200
* Thrown when the signer is invalid
@@ -209,22 +203,22 @@ interface IRecurringCollector is IAuthorizable, IPaymentsCollector {
209203

210204
/**
211205
* Thrown when the payment type is not IndexingFee
212-
* @param paymentType The provided payment type
206+
* @param invalidPaymentType The invalid payment type
213207
*/
214-
error RecurringCollectorInvalidPaymentType(IGraphPayments.PaymentTypes paymentType);
208+
error RecurringCollectorInvalidPaymentType(IGraphPayments.PaymentTypes invalidPaymentType);
215209

216210
/**
217211
* Thrown when the caller is not the data service the RCA was issued to
218-
* @param caller The address of the caller
212+
* @param unauthorizedCaller The address of the caller
219213
* @param dataService The address of the data service
220214
*/
221-
error RecurringCollectorCallerNotDataService(address caller, address dataService);
215+
error RecurringCollectorUnauthorizedCaller(address unauthorizedCaller, address dataService);
222216

223217
/**
224218
* Thrown when calling collect() with invalid data
225-
* @param data The invalid data
219+
* @param invalidData The invalid data
226220
*/
227-
error RecurringCollectorInvalidCollectData(bytes data);
221+
error RecurringCollectorInvalidCollectData(bytes invalidData);
228222

229223
/**
230224
* Thrown when calling accept() for an already accepted agreement
@@ -233,23 +227,21 @@ interface IRecurringCollector is IAuthorizable, IPaymentsCollector {
233227
error RecurringCollectorAgreementAlreadyAccepted(bytes16 agreementId);
234228

235229
/**
236-
* Thrown when calling cancel() for a never accepted agreement
230+
* Thrown when interacting with an agreement that was never accepted
237231
* @param agreementId The agreement ID
238232
*/
239233
error RecurringCollectorAgreementNeverAccepted(bytes16 agreementId);
240234

241235
/**
242-
* Thrown when calling collect() on an invalid agreement
236+
* Thrown when interacting with an agreement that was canceled
243237
* @param agreementId The agreement ID
244-
* @param acceptedAt The agreement accepted timestamp
245238
*/
246-
error RecurringCollectorAgreementInvalid(bytes16 agreementId, uint256 acceptedAt);
239+
error RecurringCollectorAgreementCanceled(bytes16 agreementId);
247240

248241
/**
249-
* Thrown when accepting or upgrading an agreement with invalid params
250-
* @param agreementId The agreement ID
242+
* Thrown when accepting or upgrading an agreement with invalid parameters
251243
*/
252-
error RecurringCollectorAgreementInvalidParams(bytes16 agreementId);
244+
error RecurringCollectorAgreementInvalidParameters();
253245

254246
/**
255247
* Thrown when calling collect() on an elapsed agreement

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

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
2323
/// @notice The EIP712 typehash for the RecurringCollectionAgreement struct
2424
bytes32 public constant EIP712_RCA_TYPEHASH =
2525
keccak256(
26-
"RecurringCollectionAgreement(bytes16 agreementId,uint256 acceptDeadline,uint256 duration,address payer,address dataService,address serviceProvider,uint256 maxInitialTokens,uint256 maxOngoingTokensPerSecond,uint32 minSecondsPerCollection,uint32 maxSecondsPerCollection,bytes metadata)"
26+
"RecurringCollectionAgreement(bytes16 agreementId,uint256 deadline,uint256 duration,address payer,address dataService,address serviceProvider,uint256 maxInitialTokens,uint256 maxOngoingTokensPerSecond,uint32 minSecondsPerCollection,uint32 maxSecondsPerCollection,bytes metadata)"
2727
);
2828

2929
/// @notice The EIP712 typehash for the RecurringCollectionAgreementUpgrade struct
3030
bytes32 public constant EIP712_RCAU_TYPEHASH =
3131
keccak256(
32-
"RecurringCollectionAgreementUpgrade(bytes16 agreementId,uint256 upgradeDeadline,uint256 duration,uint256 maxInitialTokens,uint256 maxOngoingTokensPerSecond,uint32 minSecondsPerCollection,uint32 maxSecondsPerCollection,bytes metadata)"
32+
"RecurringCollectionAgreementUpgrade(bytes16 agreementId,uint256 deadline,uint256 duration,uint256 maxInitialTokens,uint256 maxOngoingTokensPerSecond,uint32 minSecondsPerCollection,uint32 maxSecondsPerCollection,bytes metadata)"
3333
);
3434

3535
/// @notice Sentinel value to indicate an agreement has been canceled
@@ -77,11 +77,11 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
7777
function accept(SignedRCA calldata signedRCA) external {
7878
require(
7979
msg.sender == signedRCA.rca.dataService,
80-
RecurringCollectorCallerNotDataService(msg.sender, signedRCA.rca.dataService)
80+
RecurringCollectorUnauthorizedCaller(msg.sender, signedRCA.rca.dataService)
8181
);
8282
require(
83-
signedRCA.rca.acceptDeadline >= block.timestamp,
84-
RecurringCollectorAgreementAcceptanceElapsed(signedRCA.rca.acceptDeadline)
83+
signedRCA.rca.deadline >= block.timestamp,
84+
RecurringCollectorAgreementDeadlineElapsed(signedRCA.rca.deadline)
8585
);
8686

8787
// check that the voucher is signed by the payer (or proxy)
@@ -101,7 +101,7 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
101101
agreement.maxOngoingTokensPerSecond = signedRCA.rca.maxOngoingTokensPerSecond;
102102
agreement.minSecondsPerCollection = signedRCA.rca.minSecondsPerCollection;
103103
agreement.maxSecondsPerCollection = signedRCA.rca.maxSecondsPerCollection;
104-
_requireValidAgreement(agreement, signedRCA.rca.agreementId);
104+
_requireValidAgreement(agreement);
105105

106106
emit AgreementAccepted(
107107
agreement.dataService,
@@ -147,8 +147,8 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
147147
*/
148148
function upgrade(SignedRCAU calldata signedRCAU) external {
149149
require(
150-
signedRCAU.rcau.upgradeDeadline >= block.timestamp,
151-
RecurringCollectorAgreementUpgradeElapsed(signedRCAU.rcau.upgradeDeadline)
150+
signedRCAU.rcau.deadline >= block.timestamp,
151+
RecurringCollectorAgreementDeadlineElapsed(signedRCAU.rcau.deadline)
152152
);
153153

154154
AgreementData storage agreement = _getForUpdateAgreement(signedRCAU.rcau.agreementId);
@@ -167,7 +167,7 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
167167
agreement.maxOngoingTokensPerSecond = signedRCAU.rcau.maxOngoingTokensPerSecond;
168168
agreement.minSecondsPerCollection = signedRCAU.rcau.minSecondsPerCollection;
169169
agreement.maxSecondsPerCollection = signedRCAU.rcau.maxSecondsPerCollection;
170-
_requireValidAgreement(agreement, signedRCAU.rcau.agreementId);
170+
_requireValidAgreement(agreement);
171171

172172
emit AgreementUpgraded(
173173
agreement.dataService,
@@ -236,10 +236,7 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
236236
*/
237237
function _collect(CollectParams memory _params) private returns (uint256) {
238238
AgreementData storage agreement = _getForUpdateAgreement(_params.agreementId);
239-
require(
240-
agreement.acceptedAt > 0,
241-
RecurringCollectorAgreementInvalid(_params.agreementId, agreement.acceptedAt)
242-
);
239+
require(agreement.acceptedAt > 0, RecurringCollectorAgreementNeverAccepted(_params.agreementId));
243240
require(
244241
msg.sender == agreement.dataService,
245242
RecurringCollectorDataServiceNotAuthorized(_params.agreementId, msg.sender)
@@ -283,36 +280,33 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
283280
return _params.tokens;
284281
}
285282

286-
function _requireValidAgreement(AgreementData memory _agreement, bytes16 _agreementId) private view {
283+
function _requireValidAgreement(AgreementData memory _agreement) private view {
287284
require(
288285
_agreement.dataService != address(0) &&
289286
_agreement.payer != address(0) &&
290287
_agreement.serviceProvider != address(0),
291-
RecurringCollectorAgreementInvalidParams(_agreementId)
288+
RecurringCollectorAgreementInvalidParameters()
292289
);
293290

294291
// Agreement needs to end in the future
295-
require(_agreementEndsAt(_agreement) > block.timestamp, RecurringCollectorAgreementInvalidParams(_agreementId));
292+
require(_agreementEndsAt(_agreement) > block.timestamp, RecurringCollectorAgreementInvalidParameters());
296293

297294
// Collection window needs to be at least 2 hours
298295
require(
299296
_agreement.maxSecondsPerCollection > _agreement.minSecondsPerCollection &&
300297
(_agreement.maxSecondsPerCollection - _agreement.minSecondsPerCollection >= 7200),
301-
RecurringCollectorAgreementInvalidParams(_agreementId)
298+
RecurringCollectorAgreementInvalidParameters()
302299
);
303300

304301
// Agreement needs to last at least one min collection window
305302
require(
306303
_agreement.duration >= _agreement.minSecondsPerCollection + 7200,
307-
RecurringCollectorAgreementInvalidParams(_agreementId)
304+
RecurringCollectorAgreementInvalidParameters()
308305
);
309306
}
310307

311308
function _requireCollectableAgreement(AgreementData memory _agreement, bytes16 _agreementId) private view {
312-
require(
313-
_agreement.acceptedAt > 0 && _agreement.acceptedAt != CANCELED,
314-
RecurringCollectorAgreementInvalid(_agreementId, _agreement.acceptedAt)
315-
);
309+
require(_agreement.acceptedAt != CANCELED, RecurringCollectorAgreementCanceled(_agreementId));
316310

317311
uint256 agreementEnd = _agreement.duration < type(uint256).max - _agreement.acceptedAt
318312
? _agreement.acceptedAt + _agreement.duration
@@ -367,7 +361,7 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
367361
abi.encode(
368362
EIP712_RCA_TYPEHASH,
369363
_rca.agreementId,
370-
_rca.acceptDeadline,
364+
_rca.deadline,
371365
_rca.duration,
372366
_rca.payer,
373367
_rca.dataService,
@@ -392,7 +386,7 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
392386
abi.encode(
393387
EIP712_RCAU_TYPEHASH,
394388
_rcau.agreementId,
395-
_rcau.upgradeDeadline,
389+
_rcau.deadline,
396390
_rcau.duration,
397391
_rcau.maxInitialTokens,
398392
_rcau.maxOngoingTokensPerSecond,

packages/horizon/test/payments/recurring-collector/RecurringCollectorHelper.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ contract RecurringCollectorHelper is AuthorizableHelper, Bounder {
4949
IRecurringCollector.RecurringCollectionAgreement memory rca
5050
) public view returns (IRecurringCollector.RecurringCollectionAgreement memory) {
5151
require(block.timestamp > 0, "block.timestamp can't be zero");
52-
rca.acceptDeadline = bound(rca.acceptDeadline, 0, block.timestamp - 1);
52+
rca.deadline = bound(rca.deadline, 0, block.timestamp - 1);
5353
return rca;
5454
}
5555

5656
function withOKAcceptDeadline(
5757
IRecurringCollector.RecurringCollectionAgreement memory rca
5858
) public view returns (IRecurringCollector.RecurringCollectionAgreement memory) {
59-
rca.acceptDeadline = boundTimestampMin(rca.acceptDeadline, block.timestamp);
59+
rca.deadline = boundTimestampMin(rca.deadline, block.timestamp);
6060
return rca;
6161
}
6262
}

packages/horizon/test/payments/recurring-collector/accept.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ contract RecurringCollectorAcceptTest is RecurringCollectorSharedTest {
2424
fuzzySignedRCA.rca = _recurringCollectorHelper.withElapsedAcceptDeadline(fuzzySignedRCA.rca);
2525

2626
bytes memory expectedErr = abi.encodeWithSelector(
27-
IRecurringCollector.RecurringCollectorAgreementAcceptanceElapsed.selector,
28-
fuzzySignedRCA.rca.acceptDeadline
27+
IRecurringCollector.RecurringCollectorAgreementDeadlineElapsed.selector,
28+
fuzzySignedRCA.rca.deadline
2929
);
3030
vm.expectRevert(expectedErr);
3131
vm.prank(fuzzySignedRCA.rca.dataService);

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ contract RecurringCollectorCollectTest is RecurringCollectorSharedTest {
7272
bytes memory data = _generateCollectData(params.collectData);
7373

7474
bytes memory expectedErr = abi.encodeWithSelector(
75-
IRecurringCollector.RecurringCollectorAgreementInvalid.selector,
76-
params.collectData.agreementId,
77-
0
75+
IRecurringCollector.RecurringCollectorAgreementNeverAccepted.selector,
76+
params.collectData.agreementId
7877
);
7978
vm.expectRevert(expectedErr);
8079
vm.prank(params.dataService);
@@ -100,9 +99,8 @@ contract RecurringCollectorCollectTest is RecurringCollectorSharedTest {
10099
bytes memory data = _generateCollectData(collectParams);
101100

102101
bytes memory expectedErr = abi.encodeWithSelector(
103-
IRecurringCollector.RecurringCollectorAgreementInvalid.selector,
104-
collectParams.agreementId,
105-
type(uint256).max
102+
IRecurringCollector.RecurringCollectorAgreementCanceled.selector,
103+
collectParams.agreementId
106104
);
107105
vm.expectRevert(expectedErr);
108106
vm.prank(rca.dataService);

packages/horizon/test/payments/recurring-collector/shared.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ contract RecurringCollectorSharedTest is Test, Bounder {
5252
uint256 _signerKey
5353
) internal returns (IRecurringCollector.SignedRCA memory) {
5454
vm.assume(_rca.payer != address(0));
55-
_rca.acceptDeadline = boundTimestampMin(_rca.acceptDeadline, block.timestamp + 1);
55+
_rca.deadline = boundTimestampMin(_rca.deadline, block.timestamp + 1);
5656
return _authorizeAndAcceptV2(_rca, _signerKey);
5757
}
5858

packages/horizon/test/payments/recurring-collector/upgrade.t.sol

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ contract RecurringCollectorUpgradeTest is RecurringCollectorSharedTest {
2020
IRecurringCollector.RecurringCollectionAgreementUpgrade memory rcau = _sensibleRCAU(rca);
2121

2222
boundSkipCeil(unboundedUpgradeSkip, type(uint256).max);
23-
rcau.upgradeDeadline = bound(rcau.upgradeDeadline, 0, block.timestamp - 1);
23+
rcau.deadline = bound(rcau.deadline, 0, block.timestamp - 1);
2424
IRecurringCollector.SignedRCAU memory signedRCAU = IRecurringCollector.SignedRCAU({
2525
rcau: rcau,
2626
signature: ""
2727
});
2828

2929
bytes memory expectedErr = abi.encodeWithSelector(
30-
IRecurringCollector.RecurringCollectorAgreementUpgradeElapsed.selector,
31-
rcau.upgradeDeadline
30+
IRecurringCollector.RecurringCollectorAgreementDeadlineElapsed.selector,
31+
rcau.deadline
3232
);
3333
vm.expectRevert(expectedErr);
3434
vm.prank(rca.dataService);
@@ -39,7 +39,7 @@ contract RecurringCollectorUpgradeTest is RecurringCollectorSharedTest {
3939
rca = _sensibleRCA(rca);
4040
IRecurringCollector.RecurringCollectionAgreementUpgrade memory rcau = _sensibleRCAU(rca);
4141

42-
rcau.upgradeDeadline = block.timestamp;
42+
rcau.deadline = block.timestamp;
4343
IRecurringCollector.SignedRCAU memory signedRCAU = IRecurringCollector.SignedRCAU({
4444
rcau: rcau,
4545
signature: ""
@@ -67,7 +67,7 @@ contract RecurringCollectorUpgradeTest is RecurringCollectorSharedTest {
6767
_authorizeAndAccept(rca, signerKey);
6868

6969
boundSkipCeil(unboundedUpgradeSkip, type(uint256).max);
70-
rcau.upgradeDeadline = boundTimestampMin(rcau.upgradeDeadline, block.timestamp + 1);
70+
rcau.deadline = boundTimestampMin(rcau.deadline, block.timestamp + 1);
7171
IRecurringCollector.SignedRCAU memory signedRCAU = _recurringCollectorHelper.generateSignedRCAU(
7272
rcau,
7373
signerKey
@@ -98,7 +98,7 @@ contract RecurringCollectorUpgradeTest is RecurringCollectorSharedTest {
9898
_authorizeAndAccept(rca, signerKey);
9999

100100
boundSkipCeil(unboundedUpgradeSkip, type(uint256).max);
101-
rcau.upgradeDeadline = boundTimestampMin(rcau.upgradeDeadline, block.timestamp + 1);
101+
rcau.deadline = boundTimestampMin(rcau.deadline, block.timestamp + 1);
102102

103103
IRecurringCollector.SignedRCAU memory signedRCAU = _recurringCollectorHelper.generateSignedRCAU(
104104
rcau,
@@ -121,7 +121,7 @@ contract RecurringCollectorUpgradeTest is RecurringCollectorSharedTest {
121121
_authorizeAndAccept(rca, signerKey);
122122

123123
boundSkipCeil(unboundedUpgradeSkip, type(uint256).max);
124-
rcau.upgradeDeadline = boundTimestampMin(rcau.upgradeDeadline, block.timestamp + 1);
124+
rcau.deadline = boundTimestampMin(rcau.deadline, block.timestamp + 1);
125125
IRecurringCollector.SignedRCAU memory signedRCAU = _recurringCollectorHelper.generateSignedRCAU(
126126
rcau,
127127
signerKey

packages/subgraph-service/contracts/SubgraphService.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ contract SubgraphService is
593593
{
594594
require(
595595
signedRCA.rca.dataService == address(this),
596-
SubgraphServiceIndexingAgreementDataServiceMismatch(signedRCA.rca.dataService)
596+
SubgraphServiceIndexingAgreementWrongDataService(signedRCA.rca.dataService)
597597
);
598598

599599
AcceptIndexingAgreementMetadata memory metadata = _decodeRCAMetadata(signedRCA.rca.metadata);

0 commit comments

Comments
 (0)