Skip to content

Commit

Permalink
service: Stop using freshness checker on network subgraph
Browse files Browse the repository at this point in the history
- indexer-service can't afford to wait
  • Loading branch information
fordN committed Nov 16, 2023
1 parent 3743257 commit c52a4a8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 65 deletions.
15 changes: 11 additions & 4 deletions packages/indexer-common/src/network-subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface NetworkSubgraphCreateOptions {
graphNode: GraphNode
deployment: SubgraphDeploymentID
}
subgraphFreshnessChecker: SubgraphFreshnessChecker
subgraphFreshnessChecker?: SubgraphFreshnessChecker
}

interface DeploymentStatus {
Expand All @@ -32,7 +32,7 @@ interface NetworkSubgraphOptions {
status: Eventual<DeploymentStatus>
graphNode: GraphNode
}
subgraphFreshnessChecker: SubgraphFreshnessChecker
subgraphFreshnessChecker?: SubgraphFreshnessChecker
}

export type QueryResult<Data> = Pick<
Expand All @@ -42,7 +42,7 @@ export type QueryResult<Data> = Pick<

export class NetworkSubgraph {
logger: Logger
freshnessChecker: SubgraphFreshnessChecker
freshnessChecker: SubgraphFreshnessChecker | undefined
endpointClient?: AxiosInstance

public readonly deployment?: {
Expand Down Expand Up @@ -172,7 +172,14 @@ export class NetworkSubgraph {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
variables?: Record<string, any>,
): Promise<QueryResult<Data>> {
return this.freshnessChecker.checkedQuery(this, query, variables)
if (this.freshnessChecker) {
return this.freshnessChecker.checkedQuery(this, query, variables)
} else {
this.logger.warn(
`Cannot perform 'checkedQuery' as no freshnessChecker has been configured, falling back to standard 'query'`,
)
return this.query(query, variables)
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
8 changes: 5 additions & 3 deletions packages/indexer-service/src/allocations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ export const monitorEligibleAllocations = ({
const refreshAllocations = async (
currentAllocations: Allocation[],
): Promise<Allocation[]> => {
logger.debug('Refresh eligible allocations')
logger.debug('Refresh eligible allocations', {
protocolNetwork,
})

try {
const currentEpochResult = await networkSubgraph.checkedQuery(gql`
const currentEpochResult = await networkSubgraph.query(gql`
query {
graphNetwork(id: "1") {
currentEpoch
Expand All @@ -59,7 +61,7 @@ export const monitorEligibleAllocations = ({

const currentEpoch = currentEpochResult.data.graphNetwork.currentEpoch

const result = await networkSubgraph.checkedQuery(
const result = await networkSubgraph.query(
gql`
query allocations($indexer: String!, $closedAtEpochThreshold: Int!) {
indexer(id: $indexer) {
Expand Down
58 changes: 0 additions & 58 deletions packages/indexer-service/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import { BigNumber, Wallet } from 'ethers'
import fs from 'fs'
import { parse as yaml_parse } from 'yaml'

const DEFAULT_SUBGRAPH_MAX_BLOCK_DISTANCE = 0
const SUGGESTED_SUBGRAPH_MAX_BLOCK_DISTANCE_ON_L2 =
50 + DEFAULT_SUBGRAPH_MAX_BLOCK_DISTANCE
const DEFAULT_SUBGRAPH_FRESHNESS_SLEEP_MILLISECONDS = 5_000

import {
connectContracts,
connectDatabase,
Expand All @@ -31,7 +26,6 @@ import {
registerIndexerErrorMetrics,
resolveChainId,
validateProviderNetworkIdentifier,
SubgraphFreshnessChecker,
} from '@graphprotocol/indexer-common'

import { createServer } from '../server'
Expand Down Expand Up @@ -182,18 +176,6 @@ export default {
type: 'string',
required: false,
})
.option('subgraph-max-block-distance', {
description: 'How many blocks subgraphs are allowed to stay behind chain head',
type: 'number',
default: DEFAULT_SUBGRAPH_MAX_BLOCK_DISTANCE,
group: 'Protocol',
})
.option('subgraph-freshness-sleep-milliseconds', {
description: 'How long to wait before retrying subgraph query if it is not fresh',
type: 'number',
default: DEFAULT_SUBGRAPH_FRESHNESS_SLEEP_MILLISECONDS,
group: 'Protocol',
})

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

// Warn about inappropriate max block distance for subgraph threshold checks for given networks.
if (protocolNetwork.startsWith('eip155:42161')) {
// Arbitrum-One and Arbitrum-Goerli
if (argv.subgraphMaxBlockDistance <= SUGGESTED_SUBGRAPH_MAX_BLOCK_DISTANCE_ON_L2) {
logger.warn(
`Consider increasing 'subgraph-max-block-distance' for Arbitrum networks`,
{
problem:
'A low subgraph freshness threshold might cause the Agent to discard too many subgraph queries in fast-paced networks.',
hint: `Increase the 'subgraph-max-block-distance' parameter to a value that accomodates for block and indexing speeds.`,
configuredValue: argv.subgraphMaxBlockDistance,
},
)
}
if (
argv.subgraphFreshnessSleepMilliseconds <=
DEFAULT_SUBGRAPH_FRESHNESS_SLEEP_MILLISECONDS
) {
logger.warn(
`Consider increasing 'subgraph-freshness-sleep-milliseconds' for Arbitrum networks`,
{
problem:
'A short subgraph freshness wait time might be insufficient for the subgraph to sync with fast-paced networks.',
hint: `Increase the 'subgraph-freshness-sleep-milliseconds' parameter to a value that accomodates for block and indexing speeds.`,
configuredValue: argv.subgraphFreshnessSleepMilliseconds,
},
)
}
}

const subgraphFreshnessChecker = new SubgraphFreshnessChecker(
'Network Subgraph',
networkProvider,
argv.subgraphMaxBlockDistance,
argv.subgraphFreshnessSleepMilliseconds,
logger.child({ component: 'FreshnessChecker' }),
Infinity,
)

const networkSubgraph = await NetworkSubgraph.create({
logger,
endpoint: argv.networkSubgraphEndpoint,
Expand All @@ -365,7 +308,6 @@ export default {
deployment: new SubgraphDeploymentID(argv.networkSubgraphDeployment),
}
: undefined,
subgraphFreshnessChecker,
})
logger.info(`Successfully connected to network subgraph`)

Expand Down

0 comments on commit c52a4a8

Please sign in to comment.