-
Notifications
You must be signed in to change notification settings - Fork 149
feat: stop unpaid indexing after a DIPs agreement is canceled #1225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MoonBoi9001
merged 5 commits into
main-dips
from
mb9/close-dips-allocations-after-cancel-once-fees-drained
Jun 1, 2026
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1a97e23
feat(dips): close canceled allocations once final fees are collected
MoonBoi9001 f43f633
refactor(dips): rename agreement check to reflect collectability
MoonBoi9001 f1a78f9
docs(dips): move allocation-protection rationale to its call site
MoonBoi9001 9e7bcf7
fix(dips): correct close-refusal wording for canceled agreements
MoonBoi9001 fb17365
docs(actions): shorten two comment blocks to the 3-line density limit
MoonBoi9001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
packages/indexer-common/src/__tests__/dips-agreement-collection-protection.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
| import { NetworkMonitor } from '../indexer-management/monitor' | ||
|
|
||
| const ALLOCATION_ID = '0x1234567890123456789012345678901234567890' | ||
| const AGREEMENT_ID = '0xabcdef000000000000000000000000ab' | ||
|
|
||
| const createLogger = () => | ||
| ({ | ||
| warn: jest.fn(), | ||
| info: jest.fn(), | ||
| debug: jest.fn(), | ||
| error: jest.fn(), | ||
| trace: jest.fn(), | ||
| child: jest.fn().mockReturnThis(), | ||
| }) as any | ||
|
|
||
| const createMonitor = (opts: { | ||
| agreements?: { id: string; state: string }[] | null | ||
| getCollectionInfo?: jest.Mock | ||
| }) => { | ||
| // agreements === null models "no indexing-payments subgraph configured". | ||
| const indexingPaymentsSubgraph = | ||
| opts.agreements === null | ||
| ? undefined | ||
| : ({ | ||
| checkedQuery: jest | ||
| .fn() | ||
| .mockResolvedValue({ data: { indexingAgreements: opts.agreements } }), | ||
| } as any) | ||
| const contracts = { | ||
| RecurringCollector: { | ||
| getCollectionInfo: | ||
| opts.getCollectionInfo ?? jest.fn().mockResolvedValue([false, 0n, 0]), | ||
| }, | ||
| } as any | ||
| return new NetworkMonitor( | ||
| 'eip155:421614', | ||
| contracts, | ||
| {} as any, // indexerOptions | ||
| createLogger(), | ||
| {} as any, // graphNode | ||
| {} as any, // networkSubgraph | ||
| {} as any, // ethereum provider | ||
| {} as any, // epochSubgraph | ||
| indexingPaymentsSubgraph, | ||
| ) | ||
| } | ||
|
|
||
| describe('NetworkMonitor.hasActiveDipsAgreement', () => { | ||
| it('returns false when no indexing-payments subgraph is configured', async () => { | ||
| const monitor = createMonitor({ agreements: null }) | ||
| expect(await monitor.hasActiveDipsAgreement(ALLOCATION_ID)).toBe(false) | ||
| }) | ||
|
|
||
| it('protects an Accepted agreement without consulting the collector', async () => { | ||
| const getCollectionInfo = jest.fn() | ||
| const monitor = createMonitor({ | ||
| agreements: [{ id: AGREEMENT_ID, state: 'Accepted' }], | ||
| getCollectionInfo, | ||
| }) | ||
| expect(await monitor.hasActiveDipsAgreement(ALLOCATION_ID)).toBe(true) | ||
| expect(getCollectionInfo).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('protects a payer-canceled agreement while the collector reports collectable fees', async () => { | ||
| const getCollectionInfo = jest.fn().mockResolvedValue([true, 120n, 0]) | ||
| const monitor = createMonitor({ | ||
| agreements: [{ id: AGREEMENT_ID, state: 'CanceledByPayer' }], | ||
| getCollectionInfo, | ||
| }) | ||
| expect(await monitor.hasActiveDipsAgreement(ALLOCATION_ID)).toBe(true) | ||
| expect(getCollectionInfo).toHaveBeenCalledWith(AGREEMENT_ID) | ||
| }) | ||
|
|
||
| it('releases a payer-canceled agreement once the collector reports it fully drained', async () => { | ||
| const getCollectionInfo = jest.fn().mockResolvedValue([false, 0n, 1]) | ||
| const monitor = createMonitor({ | ||
| agreements: [{ id: AGREEMENT_ID, state: 'CanceledByPayer' }], | ||
| getCollectionInfo, | ||
| }) | ||
| expect(await monitor.hasActiveDipsAgreement(ALLOCATION_ID)).toBe(false) | ||
| }) | ||
|
|
||
| it('keeps protecting when the collector call fails, to avoid stranding fees', async () => { | ||
| const getCollectionInfo = jest.fn().mockRejectedValue(new Error('rpc down')) | ||
| const monitor = createMonitor({ | ||
| agreements: [{ id: AGREEMENT_ID, state: 'CanceledByPayer' }], | ||
| getCollectionInfo, | ||
| }) | ||
| expect(await monitor.hasActiveDipsAgreement(ALLOCATION_ID)).toBe(true) | ||
| }) | ||
|
|
||
| it('returns false when there are no protecting agreements for the allocation', async () => { | ||
| const monitor = createMonitor({ agreements: [] }) | ||
| expect(await monitor.hasActiveDipsAgreement(ALLOCATION_ID)).toBe(false) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this entire comment feels out of place, maybe we can move to where
hasActiveDipsAgreementis called.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in follow up commits, also tightened this block