Skip to content

Commit c52a4a8

Browse files
committed
service: Stop using freshness checker on network subgraph
- indexer-service can't afford to wait
1 parent 3743257 commit c52a4a8

File tree

3 files changed

+16
-65
lines changed

3 files changed

+16
-65
lines changed

packages/indexer-common/src/network-subgraph.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface NetworkSubgraphCreateOptions {
1313
graphNode: GraphNode
1414
deployment: SubgraphDeploymentID
1515
}
16-
subgraphFreshnessChecker: SubgraphFreshnessChecker
16+
subgraphFreshnessChecker?: SubgraphFreshnessChecker
1717
}
1818

1919
interface DeploymentStatus {
@@ -32,7 +32,7 @@ interface NetworkSubgraphOptions {
3232
status: Eventual<DeploymentStatus>
3333
graphNode: GraphNode
3434
}
35-
subgraphFreshnessChecker: SubgraphFreshnessChecker
35+
subgraphFreshnessChecker?: SubgraphFreshnessChecker
3636
}
3737

3838
export type QueryResult<Data> = Pick<
@@ -42,7 +42,7 @@ export type QueryResult<Data> = Pick<
4242

4343
export class NetworkSubgraph {
4444
logger: Logger
45-
freshnessChecker: SubgraphFreshnessChecker
45+
freshnessChecker: SubgraphFreshnessChecker | undefined
4646
endpointClient?: AxiosInstance
4747

4848
public readonly deployment?: {
@@ -172,7 +172,14 @@ export class NetworkSubgraph {
172172
// eslint-disable-next-line @typescript-eslint/no-explicit-any
173173
variables?: Record<string, any>,
174174
): Promise<QueryResult<Data>> {
175-
return this.freshnessChecker.checkedQuery(this, query, variables)
175+
if (this.freshnessChecker) {
176+
return this.freshnessChecker.checkedQuery(this, query, variables)
177+
} else {
178+
this.logger.warn(
179+
`Cannot perform 'checkedQuery' as no freshnessChecker has been configured, falling back to standard 'query'`,
180+
)
181+
return this.query(query, variables)
182+
}
176183
}
177184

178185
// eslint-disable-next-line @typescript-eslint/no-explicit-any

packages/indexer-service/src/allocations.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ export const monitorEligibleAllocations = ({
3535
const refreshAllocations = async (
3636
currentAllocations: Allocation[],
3737
): Promise<Allocation[]> => {
38-
logger.debug('Refresh eligible allocations')
38+
logger.debug('Refresh eligible allocations', {
39+
protocolNetwork,
40+
})
3941

4042
try {
41-
const currentEpochResult = await networkSubgraph.checkedQuery(gql`
43+
const currentEpochResult = await networkSubgraph.query(gql`
4244
query {
4345
graphNetwork(id: "1") {
4446
currentEpoch
@@ -59,7 +61,7 @@ export const monitorEligibleAllocations = ({
5961

6062
const currentEpoch = currentEpochResult.data.graphNetwork.currentEpoch
6163

62-
const result = await networkSubgraph.checkedQuery(
64+
const result = await networkSubgraph.query(
6365
gql`
6466
query allocations($indexer: String!, $closedAtEpochThreshold: Int!) {
6567
indexer(id: $indexer) {

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

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ import { BigNumber, Wallet } from 'ethers'
55
import fs from 'fs'
66
import { parse as yaml_parse } from 'yaml'
77

8-
const DEFAULT_SUBGRAPH_MAX_BLOCK_DISTANCE = 0
9-
const SUGGESTED_SUBGRAPH_MAX_BLOCK_DISTANCE_ON_L2 =
10-
50 + DEFAULT_SUBGRAPH_MAX_BLOCK_DISTANCE
11-
const DEFAULT_SUBGRAPH_FRESHNESS_SLEEP_MILLISECONDS = 5_000
12-
138
import {
149
connectContracts,
1510
connectDatabase,
@@ -31,7 +26,6 @@ import {
3126
registerIndexerErrorMetrics,
3227
resolveChainId,
3328
validateProviderNetworkIdentifier,
34-
SubgraphFreshnessChecker,
3529
} from '@graphprotocol/indexer-common'
3630

3731
import { createServer } from '../server'
@@ -182,18 +176,6 @@ export default {
182176
type: 'string',
183177
required: false,
184178
})
185-
.option('subgraph-max-block-distance', {
186-
description: 'How many blocks subgraphs are allowed to stay behind chain head',
187-
type: 'number',
188-
default: DEFAULT_SUBGRAPH_MAX_BLOCK_DISTANCE,
189-
group: 'Protocol',
190-
})
191-
.option('subgraph-freshness-sleep-milliseconds', {
192-
description: 'How long to wait before retrying subgraph query if it is not fresh',
193-
type: 'number',
194-
default: DEFAULT_SUBGRAPH_FRESHNESS_SLEEP_MILLISECONDS,
195-
group: 'Protocol',
196-
})
197179

198180
.check(argv => {
199181
if (!argv['network-subgraph-endpoint'] && !argv['network-subgraph-deployment']) {
@@ -317,45 +299,6 @@ export default {
317299
const networkIdentifier = await networkProvider.getNetwork()
318300
const protocolNetwork = resolveChainId(networkIdentifier.chainId)
319301

320-
// Warn about inappropriate max block distance for subgraph threshold checks for given networks.
321-
if (protocolNetwork.startsWith('eip155:42161')) {
322-
// Arbitrum-One and Arbitrum-Goerli
323-
if (argv.subgraphMaxBlockDistance <= SUGGESTED_SUBGRAPH_MAX_BLOCK_DISTANCE_ON_L2) {
324-
logger.warn(
325-
`Consider increasing 'subgraph-max-block-distance' for Arbitrum networks`,
326-
{
327-
problem:
328-
'A low subgraph freshness threshold might cause the Agent to discard too many subgraph queries in fast-paced networks.',
329-
hint: `Increase the 'subgraph-max-block-distance' parameter to a value that accomodates for block and indexing speeds.`,
330-
configuredValue: argv.subgraphMaxBlockDistance,
331-
},
332-
)
333-
}
334-
if (
335-
argv.subgraphFreshnessSleepMilliseconds <=
336-
DEFAULT_SUBGRAPH_FRESHNESS_SLEEP_MILLISECONDS
337-
) {
338-
logger.warn(
339-
`Consider increasing 'subgraph-freshness-sleep-milliseconds' for Arbitrum networks`,
340-
{
341-
problem:
342-
'A short subgraph freshness wait time might be insufficient for the subgraph to sync with fast-paced networks.',
343-
hint: `Increase the 'subgraph-freshness-sleep-milliseconds' parameter to a value that accomodates for block and indexing speeds.`,
344-
configuredValue: argv.subgraphFreshnessSleepMilliseconds,
345-
},
346-
)
347-
}
348-
}
349-
350-
const subgraphFreshnessChecker = new SubgraphFreshnessChecker(
351-
'Network Subgraph',
352-
networkProvider,
353-
argv.subgraphMaxBlockDistance,
354-
argv.subgraphFreshnessSleepMilliseconds,
355-
logger.child({ component: 'FreshnessChecker' }),
356-
Infinity,
357-
)
358-
359302
const networkSubgraph = await NetworkSubgraph.create({
360303
logger,
361304
endpoint: argv.networkSubgraphEndpoint,
@@ -365,7 +308,6 @@ export default {
365308
deployment: new SubgraphDeploymentID(argv.networkSubgraphDeployment),
366309
}
367310
: undefined,
368-
subgraphFreshnessChecker,
369311
})
370312
logger.info(`Successfully connected to network subgraph`)
371313

0 commit comments

Comments
 (0)