Skip to content

Commit 2b6db80

Browse files
committed
agent, common: Add support for local querying of TAP and Epoch subgraphs
1 parent 77e2575 commit 2b6db80

File tree

3 files changed

+85
-35
lines changed

3 files changed

+85
-35
lines changed

packages/indexer-agent/src/agent.ts

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export class Agent {
232232
async ({ network, operator }: NetworkAndOperator) => {
233233
try {
234234
await operator.ensureGlobalIndexingRule()
235-
await this.ensureNetworkSubgraphIsIndexing(network)
235+
await this.ensureAllSubgraphsIndexing(network)
236236
await network.register()
237237
} catch (err) {
238238
this.logger.critical(
@@ -1265,38 +1265,56 @@ export class Agent {
12651265
)
12661266
}
12671267

1268-
// TODO: This could be a initialization check inside Network.create() once/if the Indexer Service
1269-
// uses Network instances.
1270-
async ensureNetworkSubgraphIsIndexing(network: Network) {
1268+
// TODO: After indexer-service deprecation: Move to be an initialization check inside Network.create()
1269+
async ensureSubgraphIndexing(deployment: string, networkIdentifier: string) {
1270+
try {
1271+
// TODO: Check both the local deployment and the external subgraph endpoint
1272+
// Make sure the subgraph is being indexed
1273+
await this.graphNode.ensure(
1274+
`indexer-agent/${deployment.slice(-10)}`,
1275+
new SubgraphDeploymentID(deployment),
1276+
)
1277+
1278+
// Validate if the Network Subgraph belongs to the current provider's network.
1279+
// This check must be performed after we ensure the Network Subgraph is being indexed.
1280+
await validateProviderNetworkIdentifier(
1281+
networkIdentifier,
1282+
deployment,
1283+
this.graphNode,
1284+
this.logger,
1285+
)
1286+
} catch (e) {
1287+
this.logger.warn(
1288+
'Failed to deploy and validate Network Subgraph on index-nodes. Will use external subgraph endpoint instead',
1289+
e,
1290+
)
1291+
}
1292+
}
1293+
async ensureAllSubgraphsIndexing(network: Network) {
1294+
// Network subgraph
12711295
if (
12721296
network.specification.subgraphs.networkSubgraph.deployment !== undefined
12731297
) {
1274-
try {
1275-
// TODO: Check both the local deployment and the external subgraph endpoint
1276-
// Make sure the network subgraph is being indexed
1277-
await this.graphNode.ensure(
1278-
`indexer-agent/${network.specification.subgraphs.networkSubgraph.deployment.slice(
1279-
-10,
1280-
)}`,
1281-
new SubgraphDeploymentID(
1282-
network.specification.subgraphs.networkSubgraph.deployment,
1283-
),
1284-
)
1285-
1286-
// Validate if the Network Subgraph belongs to the current provider's network.
1287-
// This check must be performed after we ensure the Network Subgraph is being indexed.
1288-
await validateProviderNetworkIdentifier(
1289-
network.specification.networkIdentifier,
1290-
network.specification.subgraphs.networkSubgraph.deployment,
1291-
this.graphNode,
1292-
this.logger,
1293-
)
1294-
} catch (e) {
1295-
this.logger.warn(
1296-
'Failed to deploy and validate Network Subgraph on index-nodes. Will use external subgraph endpoint instead',
1297-
e,
1298-
)
1299-
}
1298+
await this.ensureSubgraphIndexing(
1299+
network.specification.subgraphs.networkSubgraph.deployment,
1300+
network.specification.networkIdentifier,
1301+
)
1302+
}
1303+
// Epoch subgraph
1304+
if (
1305+
network.specification.subgraphs.epochSubgraph.deployment !== undefined
1306+
) {
1307+
await this.ensureSubgraphIndexing(
1308+
network.specification.subgraphs.epochSubgraph.deployment,
1309+
network.specification.networkIdentifier,
1310+
)
1311+
}
1312+
// TAP subgraph
1313+
if (network.specification.subgraphs.tapSubgraph?.deployment !== undefined) {
1314+
await this.ensureSubgraphIndexing(
1315+
network.specification.subgraphs.tapSubgraph.deployment,
1316+
network.specification.networkIdentifier,
1317+
)
13001318
}
13011319
}
13021320
}

packages/indexer-agent/src/commands/start.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export const start = {
140140
},
141141
})
142142
.option('network-subgraph-deployment', {
143-
description: 'Network subgraph deployment',
143+
description: 'Network subgraph deployment (for local hosting)',
144144
array: false,
145145
type: 'string',
146146
group: 'Network Subgraph',
@@ -151,6 +151,12 @@ export const start = {
151151
type: 'string',
152152
group: 'Network Subgraph',
153153
})
154+
.option('tap-subgraph-deployment', {
155+
description: 'TAP subgraph deployment (for local hosting)',
156+
array: false,
157+
type: 'string',
158+
group: 'TAP Subgraph',
159+
})
154160
.option('tap-subgraph-endpoint', {
155161
description: 'Endpoint to query the tap subgraph from',
156162
array: false,
@@ -163,6 +169,12 @@ export const start = {
163169
default: false,
164170
group: 'Network Subgraph',
165171
})
172+
.option('epoch-subgraph-deployment', {
173+
description: 'Epoch subgraph deployment (for local hosting)',
174+
array: false,
175+
type: 'string',
176+
group: 'Network Subgraph',
177+
})
166178
.option('epoch-subgraph-endpoint', {
167179
description: 'Endpoint to query the epoch block oracle subgraph from',
168180
array: false,
@@ -370,11 +382,11 @@ export async function createNetworkSpecification(
370382
url: argv.networkSubgraphEndpoint,
371383
},
372384
epochSubgraph: {
373-
// TODO: We should consider indexing the Epoch Subgraph, similar
374-
// to how we currently do it for the Network Subgraph.
385+
deployment: argv.epochSubgraphDeployment,
375386
url: argv.epochSubgraphEndpoint,
376387
},
377388
tapSubgraph: {
389+
deployment: argv.tapSubgraphDeployment,
378390
url: argv.tapSubgraphEndpoint,
379391
},
380392
}

packages/indexer-common/src/network.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,21 @@ export class Network {
145145
)
146146

147147
let tapSubgraph: SubgraphClient | undefined = undefined
148-
if (specification.subgraphs.tapSubgraph && specification.subgraphs.tapSubgraph.url) {
148+
if (specification.subgraphs.tapSubgraph) {
149+
const tapSubgraphDeploymentId = specification.subgraphs.tapSubgraph.deployment
150+
? new SubgraphDeploymentID(specification.subgraphs.tapSubgraph.deployment)
151+
: undefined
149152
tapSubgraph = await SubgraphClient.create({
150153
name: 'TapSubgraph',
151154
logger,
152-
endpoint: specification.subgraphs.tapSubgraph!.url!,
155+
deployment:
156+
tapSubgraphDeploymentId !== undefined
157+
? {
158+
graphNode,
159+
deployment: tapSubgraphDeploymentId,
160+
}
161+
: undefined,
162+
endpoint: specification.subgraphs.tapSubgraph!.url,
153163
subgraphFreshnessChecker: tapSubgraphFreshnessChecker,
154164
})
155165
}
@@ -191,9 +201,19 @@ export class Network {
191201
Infinity,
192202
)
193203

204+
const epochSubgraphDeploymentId = specification.subgraphs.epochSubgraph.deployment
205+
? new SubgraphDeploymentID(specification.subgraphs.epochSubgraph.deployment)
206+
: undefined
194207
const epochSubgraph = await SubgraphClient.create({
195208
name: 'EpochSubgraph',
196209
logger,
210+
deployment:
211+
epochSubgraphDeploymentId !== undefined
212+
? {
213+
graphNode,
214+
deployment: epochSubgraphDeploymentId,
215+
}
216+
: undefined,
197217
endpoint: specification.subgraphs.epochSubgraph.url,
198218
subgraphFreshnessChecker: epochSubgraphFreshnessChecker,
199219
})

0 commit comments

Comments
 (0)