Skip to content

Commit 415bc5b

Browse files
f: reword and document onCloseAllocation
1 parent eb81d79 commit 415bc5b

File tree

2 files changed

+61
-15
lines changed

2 files changed

+61
-15
lines changed

packages/subgraph-service/contracts/SubgraphService.sol

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ contract SubgraphService is
235235
_allocations.get(allocationId).indexer == indexer,
236236
SubgraphServiceAllocationNotAuthorized(indexer, allocationId)
237237
);
238-
_cancelAllocationIndexingAgreement(allocationId, IRecurringCollector.CancelAgreementBy.ServiceProvider);
238+
_onCloseAllocation(allocationId, false);
239239
_closeAllocation(allocationId, false);
240240
emit ServiceStopped(indexer, data);
241241
}
@@ -319,7 +319,7 @@ contract SubgraphService is
319319
Allocation.State memory allocation = _allocations.get(allocationId);
320320
require(allocation.isStale(maxPOIStaleness), SubgraphServiceCannotForceCloseAllocation(allocationId));
321321
require(!allocation.isAltruistic(), SubgraphServiceAllocationIsAltruistic(allocationId));
322-
_cancelAllocationIndexingAgreement(allocationId, IRecurringCollector.CancelAgreementBy.ThirdParty);
322+
_onCloseAllocation(allocationId, true);
323323
_closeAllocation(allocationId, true);
324324
}
325325

@@ -553,11 +553,8 @@ contract SubgraphService is
553553
return address(_graphStaking());
554554
}
555555

556-
function _cancelAllocationIndexingAgreement(
557-
address _allocationId,
558-
IRecurringCollector.CancelAgreementBy _by
559-
) internal {
560-
IndexingAgreement._getStorageManager().cancelForAllocation(_allocationId, _by);
556+
function _onCloseAllocation(address _allocationId, bool _stale) internal {
557+
IndexingAgreement._getStorageManager().onCloseAllocation(_allocationId, _stale);
561558
}
562559

563560
/**

packages/subgraph-service/contracts/libraries/IndexingAgreement.sol

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ library IndexingAgreement {
286286
*
287287
* Emits {IndexingAgreementUpdated} event
288288
*
289-
* @param self The indexing agreement manager storage
289+
* @param self The indexing agreement storage manager
290290
* @param indexer The indexer address
291291
* @param signedRCAU The signed Recurring Collection Agreement Update
292292
*/
@@ -324,13 +324,15 @@ library IndexingAgreement {
324324
/**
325325
* @notice Cancel an indexing agreement.
326326
*
327+
* @dev This function allows the indexer to cancel an indexing agreement.
328+
*
327329
* Requirements:
328330
* - Agreement must be active
329331
* - The indexer must be the service provider of the agreement
330332
*
331333
* Emits {IndexingAgreementCanceled} event
332334
*
333-
* @param self The indexing agreement manager storage
335+
* @param self The indexing agreement storage manager
334336
* @param indexer The indexer address
335337
* @param agreementId The id of the agreement to cancel
336338
*/
@@ -350,11 +352,23 @@ library IndexingAgreement {
350352
);
351353
}
352354

353-
function cancelForAllocation(
354-
StorageManager storage self,
355-
address _allocationId,
356-
IRecurringCollector.CancelAgreementBy by
357-
) external {
355+
/**
356+
* @notice Cancel an allocation's indexing agreement if it exists.
357+
*
358+
* @dev This function is to be called by the data service when an allocation is closed.
359+
*
360+
* Requirements:
361+
* - The allocation must have an active agreement
362+
* - Agreement must be active
363+
*
364+
* Emits {IndexingAgreementCanceled} event
365+
*
366+
* @param self The indexing agreement storage manager
367+
* @param _allocationId The allocation ID
368+
* @param stale Whether the allocation is stale or not
369+
*
370+
*/
371+
function onCloseAllocation(StorageManager storage self, address _allocationId, bool stale) external {
358372
bytes16 agreementId = self.allocationToActiveAgreementId[_allocationId];
359373
if (agreementId == bytes16(0)) {
360374
return;
@@ -365,9 +379,31 @@ library IndexingAgreement {
365379
return;
366380
}
367381

368-
_cancel(self, agreementId, wrapper.agreement, wrapper.collectorAgreement, by);
382+
_cancel(
383+
self,
384+
agreementId,
385+
wrapper.agreement,
386+
wrapper.collectorAgreement,
387+
stale
388+
? IRecurringCollector.CancelAgreementBy.ThirdParty
389+
: IRecurringCollector.CancelAgreementBy.ServiceProvider
390+
);
369391
}
370392

393+
/**
394+
* @notice Cancel an indexing agreement by the payer.
395+
*
396+
* @dev This function allows the payer to cancel an indexing agreement.
397+
*
398+
* Requirements:
399+
* - Agreement must be active
400+
* - The caller must be authorized to cancel the agreement in the collector on the payer's behalf
401+
*
402+
* Emits {IndexingAgreementCanceled} event
403+
*
404+
* @param self The indexing agreement storage manager
405+
* @param agreementId The id of the agreement to cancel
406+
*/
371407
function cancelByPayer(StorageManager storage self, bytes16 agreementId) external {
372408
AgreementWrapper memory wrapper = _get(self, agreementId);
373409
require(_isActive(wrapper), IndexingAgreementNotActive(agreementId));
@@ -455,6 +491,19 @@ library IndexingAgreement {
455491
_manager.termsV1[_agreementId].tokensPerEntityPerSecond = newTerms.tokensPerEntityPerSecond;
456492
}
457493

494+
/**
495+
* @notice Cancel an indexing agreement.
496+
*
497+
* @dev This function does the actual agreement cancelation.
498+
*
499+
* Emits {IndexingAgreementCanceled} event
500+
*
501+
* @param _manager The indexing agreement storage manager
502+
* @param _agreementId The id of the agreement to cancel
503+
* @param _agreement The indexing agreement state
504+
* @param _collectorAgreement The collector agreement data
505+
* @param _cancelBy The entity that is canceling the agreement
506+
*/
458507
function _cancel(
459508
StorageManager storage _manager,
460509
bytes16 _agreementId,

0 commit comments

Comments
 (0)