From c52a4a86dde8c774ac9ec4842e2e53bd27c479e7 Mon Sep 17 00:00:00 2001 From: Ford Date: Thu, 16 Nov 2023 11:35:36 -0800 Subject: [PATCH] service: Stop using freshness checker on network subgraph - indexer-service can't afford to wait --- .../indexer-common/src/network-subgraph.ts | 15 +++-- packages/indexer-service/src/allocations.ts | 8 ++- .../indexer-service/src/commands/start.ts | 58 ------------------- 3 files changed, 16 insertions(+), 65 deletions(-) diff --git a/packages/indexer-common/src/network-subgraph.ts b/packages/indexer-common/src/network-subgraph.ts index 589732272..8a41390a4 100644 --- a/packages/indexer-common/src/network-subgraph.ts +++ b/packages/indexer-common/src/network-subgraph.ts @@ -13,7 +13,7 @@ export interface NetworkSubgraphCreateOptions { graphNode: GraphNode deployment: SubgraphDeploymentID } - subgraphFreshnessChecker: SubgraphFreshnessChecker + subgraphFreshnessChecker?: SubgraphFreshnessChecker } interface DeploymentStatus { @@ -32,7 +32,7 @@ interface NetworkSubgraphOptions { status: Eventual graphNode: GraphNode } - subgraphFreshnessChecker: SubgraphFreshnessChecker + subgraphFreshnessChecker?: SubgraphFreshnessChecker } export type QueryResult = Pick< @@ -42,7 +42,7 @@ export type QueryResult = Pick< export class NetworkSubgraph { logger: Logger - freshnessChecker: SubgraphFreshnessChecker + freshnessChecker: SubgraphFreshnessChecker | undefined endpointClient?: AxiosInstance public readonly deployment?: { @@ -172,7 +172,14 @@ export class NetworkSubgraph { // eslint-disable-next-line @typescript-eslint/no-explicit-any variables?: Record, ): Promise> { - 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 diff --git a/packages/indexer-service/src/allocations.ts b/packages/indexer-service/src/allocations.ts index 321e4a525..c002b0122 100644 --- a/packages/indexer-service/src/allocations.ts +++ b/packages/indexer-service/src/allocations.ts @@ -35,10 +35,12 @@ export const monitorEligibleAllocations = ({ const refreshAllocations = async ( currentAllocations: Allocation[], ): Promise => { - 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 @@ -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) { diff --git a/packages/indexer-service/src/commands/start.ts b/packages/indexer-service/src/commands/start.ts index 37b373df4..bd8b72135 100644 --- a/packages/indexer-service/src/commands/start.ts +++ b/packages/indexer-service/src/commands/start.ts @@ -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, @@ -31,7 +26,6 @@ import { registerIndexerErrorMetrics, resolveChainId, validateProviderNetworkIdentifier, - SubgraphFreshnessChecker, } from '@graphprotocol/indexer-common' import { createServer } from '../server' @@ -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']) { @@ -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, @@ -365,7 +308,6 @@ export default { deployment: new SubgraphDeploymentID(argv.networkSubgraphDeployment), } : undefined, - subgraphFreshnessChecker, }) logger.info(`Successfully connected to network subgraph`)