@@ -12,7 +12,6 @@ import { BlockPointer, ChainIndexingStatus, IndexingStatus } from './types'
12
12
import pRetry , { Options } from 'p-retry'
13
13
import axios , { AxiosInstance } from 'axios'
14
14
import fetch from 'isomorphic-fetch'
15
- import { Action } from './indexer-management'
16
15
17
16
interface indexNode {
18
17
id : string
@@ -103,15 +102,11 @@ export class GraphNode {
103
102
this . logger . info ( `Check if indexing status API is available` )
104
103
await pRetry (
105
104
async ( ) => {
106
- const deployments = await this . subgraphDeployments ( )
107
- if ( deployments . length < 100 ) {
108
- this . logger . info ( `Successfully connected to indexing status API` , {
109
- currentDeployments : deployments . map ( ( deployment ) => deployment . display ) ,
110
- } )
105
+ if ( await this . statusEndpointConnected ( ) ) {
106
+ this . logger . info ( `Successfully connected to indexing status API` , { } )
111
107
} else {
112
- this . logger . info ( `Successfully connected to indexing status API` , {
113
- currentDeploymentCount : deployments . length ,
114
- } )
108
+ this . logger . error ( `Failed to connect to indexing status API` )
109
+ throw new Error ( 'Indexing status API not available' )
115
110
}
116
111
} ,
117
112
{
@@ -149,97 +144,120 @@ export class GraphNode {
149
144
return new URL ( deploymentIpfsHash , this . queryBaseURL ) . toString ( )
150
145
}
151
146
152
- public async subgraphDeployments ( ) : Promise < SubgraphDeploymentID [ ] > {
153
- return ( await this . subgraphDeploymentsAssignments ( SubgraphStatus . ACTIVE ) ) . map (
154
- ( details ) => details . id ,
155
- )
147
+ // Simple query to make sure the status endpoint is connected
148
+ public async statusEndpointConnected ( ) : Promise < boolean > {
149
+ try {
150
+ const result = await this . status
151
+ . query (
152
+ gql `
153
+ query {
154
+ __typename
155
+ }
156
+ ` ,
157
+ undefined ,
158
+ )
159
+ . toPromise ( )
160
+
161
+ if ( result . error ) {
162
+ throw result . error
163
+ }
164
+
165
+ return ! ! result . data
166
+ } catch ( error ) {
167
+ this . logger . error ( `Failed to query status endpoint` , { error } )
168
+ return false
169
+ }
156
170
}
157
171
158
- public async subgraphDeploymentAssignmentsForAllocateActions (
172
+ public async subgraphDeploymentAssignmentsByDeploymentID (
159
173
subgraphStatus : SubgraphStatus ,
160
- actions : Action [ ] ,
174
+ deploymentIDs : string [ ] ,
161
175
) : Promise < SubgraphDeploymentAssignment [ ] > {
162
- const deploymentIDs = actions . map ( ( action ) => action . deploymentID )
163
-
164
- const nodeOnlyResult = await this . status
165
- . query (
166
- gql `
167
- query indexingStatuses($ subgraphs: [String!]! ) {
168
- indexingStatuses(subgraphs: $subgraphs) {
169
- subgraphDeployment: subgraph
170
- node
176
+ try {
177
+ const nodeOnlyResult = await this . status
178
+ . query (
179
+ gql `
180
+ query indexingStatuses($subgraphs: [String!]!) {
181
+ indexingStatuses(subgraphs: $subgraphs ) {
182
+ subgraphDeployment: subgraph
183
+ node
184
+ }
171
185
}
172
- }
173
- ` ,
174
- { subgraphs : deploymentIDs } ,
175
- )
176
- . toPromise ( )
186
+ ` ,
187
+ { subgraphs : deploymentIDs } ,
188
+ )
189
+ . toPromise ( )
177
190
178
- if ( nodeOnlyResult . error ) {
179
- throw nodeOnlyResult . error
180
- }
191
+ if ( nodeOnlyResult . error ) {
192
+ throw nodeOnlyResult . error
193
+ }
181
194
182
- const withAssignments : string [ ] = nodeOnlyResult . data . indexingStatuses
183
- . filter (
184
- ( result : { node : string | null } ) =>
185
- result . node !== null && result . node !== undefined ,
186
- )
187
- . map ( ( result : { subgraphDeployment : string } ) => result . subgraphDeployment )
188
-
189
- const result = await this . status
190
- . query (
191
- gql `
192
- query indexingStatuses($subgraphs: [String!]!) {
193
- indexingStatuses(subgraphs: $subgraphs) {
194
- subgraphDeployment: subgraph
195
- node
196
- paused
195
+ const withAssignments : string [ ] = nodeOnlyResult . data . indexingStatuses
196
+ . filter (
197
+ ( result : { node : string | null } ) =>
198
+ result . node !== null && result . node !== undefined ,
199
+ )
200
+ . map ( ( result : { subgraphDeployment : string } ) => result . subgraphDeployment )
201
+
202
+ const result = await this . status
203
+ . query (
204
+ gql `
205
+ query indexingStatuses($subgraphs: [String!]!) {
206
+ indexingStatuses(subgraphs: $subgraphs) {
207
+ subgraphDeployment: subgraph
208
+ node
209
+ paused
210
+ }
197
211
}
198
- }
199
- ` ,
200
- { subgraphs : withAssignments } ,
201
- )
202
- . toPromise ( )
212
+ ` ,
213
+ { subgraphs : withAssignments } ,
214
+ )
215
+ . toPromise ( )
203
216
204
- if ( result . error ) {
205
- throw result . error
206
- }
217
+ if ( result . error ) {
218
+ throw result . error
219
+ }
207
220
208
- if ( ! result . data . indexingStatuses || result . data . length === 0 ) {
209
- this . logger . warn ( `No 'indexingStatuses' data returned from index nodes` , {
210
- data : result . data ,
211
- } )
212
- return [ ]
213
- }
221
+ if ( ! result . data . indexingStatuses || result . data . length === 0 ) {
222
+ this . logger . warn ( `No 'indexingStatuses' data returned from index nodes` , {
223
+ data : result . data ,
224
+ } )
225
+ return [ ]
226
+ }
214
227
215
- type QueryResult = {
216
- subgraphDeployment : string
217
- node : string | undefined
218
- paused : boolean | undefined
219
- }
228
+ type QueryResult = {
229
+ subgraphDeployment : string
230
+ node : string | undefined
231
+ paused : boolean | undefined
232
+ }
220
233
221
- const results = result . data . indexingStatuses
222
- . filter ( ( status : QueryResult ) => {
223
- if ( subgraphStatus === SubgraphStatus . ACTIVE ) {
224
- return (
225
- status . paused === false ||
226
- ( status . paused === undefined && status . node !== 'removed' )
227
- )
228
- } else if ( subgraphStatus === SubgraphStatus . PAUSED ) {
229
- return status . node === 'removed' || status . paused === true
230
- } else if ( subgraphStatus === SubgraphStatus . ALL ) {
231
- return true
232
- }
233
- } )
234
- . map ( ( status : QueryResult ) => {
235
- return {
236
- id : new SubgraphDeploymentID ( status . subgraphDeployment ) ,
237
- node : status . node ,
238
- paused : status . paused ?? status . node === 'removed' ,
239
- }
240
- } )
234
+ const results = result . data . indexingStatuses
235
+ . filter ( ( status : QueryResult ) => {
236
+ if ( subgraphStatus === SubgraphStatus . ACTIVE ) {
237
+ return (
238
+ status . paused === false ||
239
+ ( status . paused === undefined && status . node !== 'removed' )
240
+ )
241
+ } else if ( subgraphStatus === SubgraphStatus . PAUSED ) {
242
+ return status . node === 'removed' || status . paused === true
243
+ } else if ( subgraphStatus === SubgraphStatus . ALL ) {
244
+ return true
245
+ }
246
+ } )
247
+ . map ( ( status : QueryResult ) => {
248
+ return {
249
+ id : new SubgraphDeploymentID ( status . subgraphDeployment ) ,
250
+ node : status . node ,
251
+ paused : status . paused ?? status . node === 'removed' ,
252
+ }
253
+ } )
241
254
242
- return results
255
+ return results
256
+ } catch ( error ) {
257
+ const err = indexerError ( IndexerErrorCode . IE018 , error )
258
+ this . logger . error ( `Failed to query indexing status API` , { err } )
259
+ throw err
260
+ }
243
261
}
244
262
245
263
public async subgraphDeploymentsAssignments (
@@ -265,8 +283,11 @@ export class GraphNode {
265
283
)
266
284
. toPromise ( )
267
285
286
+ const deploymentCount = nodeOnlyResult . data ?. indexingStatuses ?. length ?? 0
268
287
this . logger . debug (
269
- `Fetch subgraph deployment assignments took ${ Date . now ( ) - startTimeMs } ms` ,
288
+ `Fetch subgraph deployment assignments (1/2, node only) took ${
289
+ Date . now ( ) - startTimeMs
290
+ } ms for ${ deploymentCount } deployments`,
270
291
)
271
292
272
293
if ( nodeOnlyResult . error ) {
@@ -313,6 +334,12 @@ export class GraphNode {
313
334
paused : boolean | undefined
314
335
}
315
336
337
+ const deploymentCount2 = result . data ?. indexingStatuses ?. length ?? 0
338
+ this . logger . debug (
339
+ `Fetch subgraph deployment assignments (2/2, with paused) took ${
340
+ Date . now ( ) - startTimeMs
341
+ } ms and returned ${ deploymentCount } /${ deploymentCount2 } deployments`,
342
+ )
316
343
const results = result . data . indexingStatuses
317
344
. filter ( ( status : QueryResult ) => {
318
345
if ( subgraphStatus === SubgraphStatus . ACTIVE ) {
@@ -557,7 +584,9 @@ export class GraphNode {
557
584
try {
558
585
const deploymentAssignments =
559
586
currentAssignments ??
560
- ( await this . subgraphDeploymentsAssignments ( SubgraphStatus . ALL ) )
587
+ ( await this . subgraphDeploymentAssignmentsByDeploymentID ( SubgraphStatus . ALL , [
588
+ deployment . ipfsHash ,
589
+ ] ) )
561
590
const matchingAssignment = deploymentAssignments . find (
562
591
( deploymentAssignment ) => deploymentAssignment . id . ipfsHash == deployment . ipfsHash ,
563
592
)
0 commit comments