1
- import { formatGRT , Logger , SubgraphDeploymentID } from "@graphprotocol/common-ts" ;
2
- import { AllocationManager , GraphNode , IndexerManagementModels , IndexingDecisionBasis , IndexingRuleAttributes , Network , SubgraphIdentifierType , upsertIndexingRule } from '@graphprotocol/indexer-common'
3
- import { Op } from "sequelize" ;
1
+ import { formatGRT , Logger , SubgraphDeploymentID } from '@graphprotocol/common-ts'
2
+ import {
3
+ AllocationManager ,
4
+ GraphNode ,
5
+ IndexerManagementModels ,
6
+ IndexingDecisionBasis ,
7
+ IndexingRuleAttributes ,
8
+ Network ,
9
+ SubgraphIdentifierType ,
10
+ upsertIndexingRule ,
11
+ } from '@graphprotocol/indexer-common'
12
+ import { Op } from 'sequelize'
4
13
5
14
export class DipsManager {
6
15
constructor (
@@ -20,12 +29,14 @@ export class DipsManager {
20
29
} )
21
30
if ( agreement ) {
22
31
// TODO use dips-proto to cancel agreement via grpc
23
-
24
32
// Mark the agreement as cancelled
25
33
}
26
34
}
27
35
// Update the current and last allocation ids for an agreement if it exists
28
- async tryUpdateAgreementAllocation ( oldAllocationId : string , newAllocationId : string | null ) {
36
+ async tryUpdateAgreementAllocation (
37
+ oldAllocationId : string ,
38
+ newAllocationId : string | null ,
39
+ ) {
29
40
const agreement = await this . models . IndexingAgreement . findOne ( {
30
41
where : {
31
42
current_allocation_id : oldAllocationId ,
@@ -65,17 +76,22 @@ export class DipsManager {
65
76
// (tap-agent will take care of aggregating it into a RAV)
66
77
67
78
// Mark the agreement as having had a payment collected
68
- await this . models . IndexingAgreement . update ( {
69
- last_payment_collected_at : new Date ( ) ,
70
- } , {
71
- where : {
72
- last_allocation_id : lastAllocationId ,
79
+ await this . models . IndexingAgreement . update (
80
+ {
81
+ last_payment_collected_at : new Date ( ) ,
73
82
} ,
74
- } )
83
+ {
84
+ where : {
85
+ last_allocation_id : lastAllocationId ,
86
+ } ,
87
+ } ,
88
+ )
75
89
}
76
90
async ensureAgreementRules ( ) {
77
91
if ( ! this . parent ) {
78
- this . logger . error ( 'DipsManager has no parent AllocationManager, cannot ensure agreement rules' )
92
+ this . logger . error (
93
+ 'DipsManager has no parent AllocationManager, cannot ensure agreement rules' ,
94
+ )
79
95
return
80
96
}
81
97
// Get all the indexing agreements that are not cancelled
@@ -87,20 +103,26 @@ export class DipsManager {
87
103
// For each agreement, check that there is an indexing rule to always
88
104
// allocate to the agreement's subgraphDeploymentId, and if not, create one
89
105
for ( const agreement of indexingAgreements ) {
90
- const subgraphDeploymentID = new SubgraphDeploymentID ( agreement . subgraph_deployment_id )
106
+ const subgraphDeploymentID = new SubgraphDeploymentID (
107
+ agreement . subgraph_deployment_id ,
108
+ )
91
109
// If there is not yet an indexingRule that deems this deployment worth allocating to, make one
92
110
if ( ! ( await this . parent . matchingRuleExists ( this . logger , subgraphDeploymentID ) ) ) {
93
- this . logger . debug (
94
- `Creating indexing rule for agreement ${ agreement . id } ` ,
95
- )
111
+ this . logger . debug ( `Creating indexing rule for agreement ${ agreement . id } ` )
96
112
const indexingRule = {
97
113
identifier : agreement . subgraph_deployment_id ,
98
- allocationAmount : formatGRT ( this . network . specification . indexerOptions . dipsAllocationAmount ) ,
114
+ allocationAmount : formatGRT (
115
+ this . network . specification . indexerOptions . dipsAllocationAmount ,
116
+ ) ,
99
117
identifierType : SubgraphIdentifierType . DEPLOYMENT ,
100
118
decisionBasis : IndexingDecisionBasis . ALWAYS ,
101
119
protocolNetwork : this . network . specification . networkIdentifier ,
102
120
autoRenewal : true ,
103
- allocationLifetime : Math . max ( Number ( agreement . min_epochs_per_collection ) , Number ( agreement . max_epochs_per_collection ) - this . network . specification . indexerOptions . dipsEpochsMargin ) ,
121
+ allocationLifetime : Math . max (
122
+ Number ( agreement . min_epochs_per_collection ) ,
123
+ Number ( agreement . max_epochs_per_collection ) -
124
+ this . network . specification . indexerOptions . dipsEpochsMargin ,
125
+ ) ,
104
126
} as Partial < IndexingRuleAttributes >
105
127
106
128
await upsertIndexingRule ( this . logger , this . models , indexingRule )
0 commit comments