Skip to content

Commit

Permalink
*: Merge Epoch, Network and Tap subgraph client classes
Browse files Browse the repository at this point in the history
- For user, this change effectively adds support for local querying on
epoch and tap subgraphs (previously only supported on network subgraph).
- For contributors, this simplifies the codebase to have 1
SubgraphClient class instead of 3 separate implementations:
EpochSubgraph, NetworkSubgraph and TapSubgraph.
  • Loading branch information
fordN committed Dec 13, 2024
1 parent 0f99796 commit b1bdaf6
Show file tree
Hide file tree
Showing 20 changed files with 112 additions and 232 deletions.
4 changes: 2 additions & 2 deletions packages/indexer-agent/src/syncing-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { Logger } from '@graphprotocol/common-ts'
import { parse } from 'graphql'
import {
NetworkMapped,
NetworkSubgraph,
SubgraphClient,
resolveChainId,
} from '@graphprotocol/indexer-common'

export interface CreateSyncingServerOptions {
logger: Logger
networkSubgraphs: NetworkMapped<NetworkSubgraph>
networkSubgraphs: NetworkMapped<SubgraphClient>
port: number
}

Expand Down
2 changes: 1 addition & 1 deletion packages/indexer-common/src/__tests__/subgraph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ProviderInterface,
SubgraphQueryInterface,
} from '../subgraphs'
import { QueryResult } from '../network-subgraph'
import { QueryResult } from '../subgraph-client'
import gql from 'graphql-tag'
import { mergeSelectionSets } from '../utils'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Address, Eventual, createLogger, createMetrics } from '@graphprotocol/c
import {
Allocation,
AllocationsResponse,
NetworkSubgraph,
SubgraphClient,
QueryFeeModels,
QueryResult,
TapCollector,
Expand All @@ -11,7 +11,6 @@ import {
TransactionManager,
} from '@graphprotocol/indexer-common'
import { NetworkContracts as TapContracts } from '@semiotic-labs/tap-contracts-bindings'
import { TAPSubgraph } from '../../tap-subgraph'
import { NetworkSpecification } from 'indexer-common/src/network-specification'
import { createMockAllocation } from '../../indexer-management/__tests__/helpers.test'
import { getContractAddress } from 'ethers/lib/utils'
Expand Down Expand Up @@ -155,10 +154,10 @@ const setup = () => {

const tapSubgraph = {
query: mockQueryTapSubgraph,
} as unknown as TAPSubgraph
} as unknown as SubgraphClient
const networkSubgraph = {
query: mockQueryNetworkSubgraph,
} as unknown as NetworkSubgraph
} as unknown as SubgraphClient

tapCollector = TapCollector.create({
logger,
Expand Down
4 changes: 2 additions & 2 deletions packages/indexer-common/src/allocations/escrow-accounts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Address, toAddress } from '@graphprotocol/common-ts'
import { TAPSubgraph } from '../tap-subgraph'
import { SubgraphClient } from '../subgraph-client'
import gql from 'graphql-tag'

type U256 = bigint
Expand Down Expand Up @@ -44,7 +44,7 @@ export class EscrowAccounts {
}

export const getEscrowAccounts = async (
tapSubgraph: TAPSubgraph,
tapSubgraph: SubgraphClient,
indexer: Address,
): Promise<EscrowAccounts> => {
const result = await tapSubgraph.query<EscrowAccountResponse>(
Expand Down
6 changes: 3 additions & 3 deletions packages/indexer-common/src/allocations/query-fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import {
ensureAllocationSummary,
TransactionManager,
specification as spec,
SubgraphClient,
} from '..'
import { DHeap } from '@thi.ng/heaps'
import { BigNumber, BigNumberish, Contract } from 'ethers'
import { Op } from 'sequelize'
import pReduce from 'p-reduce'
import { NetworkSubgraph } from '../network-subgraph'

// Receipts are collected with a delay of 20 minutes after
// the corresponding allocation was closed
Expand Down Expand Up @@ -71,7 +71,7 @@ export interface AllocationReceiptCollectorOptions {
allocations: Eventual<Allocation[]>
models: QueryFeeModels
networkSpecification: spec.NetworkSpecification
networkSubgraph: NetworkSubgraph
networkSubgraph: SubgraphClient
}

export interface ReceiptCollector {
Expand All @@ -94,7 +94,7 @@ export class AllocationReceiptCollector implements ReceiptCollector {
declare voucherRedemptionBatchThreshold: BigNumber
declare voucherRedemptionMaxBatchSize: number
declare protocolNetwork: string
declare networkSubgraph: NetworkSubgraph
declare networkSubgraph: SubgraphClient

// eslint-disable-next-line @typescript-eslint/no-empty-function -- Private constructor to prevent direct instantiation
private constructor() {}
Expand Down
11 changes: 5 additions & 6 deletions packages/indexer-common/src/allocations/tap-collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import {
} from '..'
import { BigNumber } from 'ethers'
import pReduce from 'p-reduce'
import { TAPSubgraph } from '../tap-subgraph'
import { NetworkSubgraph, QueryResult } from '../network-subgraph'
import { SubgraphClient, QueryResult } from '../subgraph-client'
import gql from 'graphql-tag'
import { getEscrowAccounts } from './escrow-accounts'

Expand All @@ -52,8 +51,8 @@ interface TapCollectorOptions {
allocations: Eventual<Allocation[]>
models: QueryFeeModels
networkSpecification: spec.NetworkSpecification
tapSubgraph: TAPSubgraph
networkSubgraph: NetworkSubgraph
tapSubgraph: SubgraphClient
networkSubgraph: SubgraphClient
}

interface ValidRavs {
Expand Down Expand Up @@ -107,8 +106,8 @@ export class TapCollector {
declare allocations: Eventual<Allocation[]>
declare ravRedemptionThreshold: BigNumber
declare protocolNetwork: string
declare tapSubgraph: TAPSubgraph
declare networkSubgraph: NetworkSubgraph
declare tapSubgraph: SubgraphClient
declare networkSubgraph: SubgraphClient
declare finalityTime: number
declare indexerAddress: Address

Expand Down
4 changes: 2 additions & 2 deletions packages/indexer-common/src/allocations/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigNumber } from 'ethers'
import { NetworkSubgraph, SubgraphDeployment } from '@graphprotocol/indexer-common'
import { SubgraphClient, SubgraphDeployment } from '@graphprotocol/indexer-common'

import { Logger, Address } from '@graphprotocol/common-ts'

Expand Down Expand Up @@ -31,7 +31,7 @@ export enum AllocationStatus {
export interface MonitorEligibleAllocationsOptions {
indexer: Address
logger: Logger
networkSubgraph: NetworkSubgraph
networkSubgraph: SubgraphClient
interval: number
protocolNetwork: string
}
63 changes: 0 additions & 63 deletions packages/indexer-common/src/epoch-subgraph.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/indexer-common/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
export * from './actions'
export * from './allocations'
export * from './async-cache'
export * from './epoch-subgraph'
export * from './errors'
export * from './indexer-management'
export * from './graph-node'
export * from './operator'
export * from './network'
export * from './network-subgraph'
export * from './query-fees'
export * from './rules'
export * from './subgraphs'
export * from './subgraph-client'
export * from './transactions'
export * from './types'
export * from './utils'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ import { literal, Op, Sequelize } from 'sequelize'
import {
Allocation,
AllocationStatus,
EpochSubgraph,
indexerError,
IndexerErrorCode,
GraphNode,
NetworkMonitor,
NetworkSubgraph,
SubgraphClient,
resolveChainAlias,
resolveChainId,
SubgraphDeployment,
Expand All @@ -48,8 +47,8 @@ let models: IndexerManagementModels
let ethereum: ethers.providers.BaseProvider
let contracts: NetworkContracts
let graphNode: GraphNode
let networkSubgraph: NetworkSubgraph
let epochSubgraph: EpochSubgraph
let networkSubgraph: SubgraphClient
let epochSubgraph: SubgraphClient
let networkMonitor: NetworkMonitor
let logger: Logger

Expand Down Expand Up @@ -84,18 +83,22 @@ const setupMonitor = async () => {
)

const INDEXER_TEST_API_KEY: string = process.env['INDEXER_TEST_API_KEY'] || ''
networkSubgraph = await NetworkSubgraph.create({

networkSubgraph = await SubgraphClient.create({
name: 'NetworkSubgraph',
logger,
endpoint: `https://gateway-arbitrum.network.thegraph.com/api/${INDEXER_TEST_API_KEY}/subgraphs/id/3xQHhMudr1oh69ut36G2mbzpYmYxwqCeU6wwqyCDCnqV`,
deployment: undefined,
subgraphFreshnessChecker,
})

epochSubgraph = new EpochSubgraph(
`https://gateway-arbitrum.network.thegraph.com/api/${INDEXER_TEST_API_KEY}/subgraphs/id/BhnsdeZihU4SuokxZMLF4FQBVJ3jgtZf6v51gHvz3bSS`,
subgraphFreshnessChecker,
epochSubgraph = await SubgraphClient.create({
name: 'EpochSubgraph',
logger,
)
endpoint: `https://gateway-arbitrum.network.thegraph.com/api/${INDEXER_TEST_API_KEY}/subgraphs/id/BhnsdeZihU4SuokxZMLF4FQBVJ3jgtZf6v51gHvz3bSS`,
subgraphFreshnessChecker,
})

graphNode = new GraphNode(
logger,
'http://test-admin-endpoint.xyz',
Expand Down
9 changes: 4 additions & 5 deletions packages/indexer-common/src/indexer-management/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ import {
indexerError,
IndexerErrorCode,
GraphNode,
NetworkSubgraph,
parseGraphQLAllocation,
parseGraphQLEpochs,
parseGraphQLSubgraphDeployment,
Subgraph,
SubgraphDeployment,
SubgraphVersion,
NetworkEpoch,
EpochSubgraph,
BlockPointer,
resolveChainId,
resolveChainAlias,
Expand All @@ -37,6 +35,7 @@ import { providers, utils, Wallet } from 'ethers'
import pRetry, { Options } from 'p-retry'
import { IndexerOptions } from '../network-specification'
import pMap from 'p-map'
import { SubgraphClient } from '../subgraph-client'

// The new read only Network class
export class NetworkMonitor {
Expand All @@ -46,9 +45,9 @@ export class NetworkMonitor {
private indexerOptions: IndexerOptions,
private logger: Logger,
private graphNode: GraphNode,
private networkSubgraph: NetworkSubgraph,
private networkSubgraph: SubgraphClient,
private ethereum: providers.BaseProvider,
private epochSubgraph: EpochSubgraph,
private epochSubgraph: SubgraphClient,
) {}

async currentEpochNumber(): Promise<number> {
Expand Down Expand Up @@ -992,7 +991,7 @@ Please submit an issue at https://github.com/graphprotocol/block-oracle/issues/n
async monitorNetworkPauses(
logger: Logger,
contracts: NetworkContracts,
networkSubgraph: NetworkSubgraph,
networkSubgraph: SubgraphClient,
): Promise<Eventual<boolean>> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const initialPauseValue = await contracts.controller.paused().catch((_) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import {
IndexerManagementResolverContext,
IndexingDecisionBasis,
IndexingRuleAttributes,
NetworkSubgraph,
ReallocateAllocationResult,
SubgraphClient,
SubgraphIdentifierType,
uniqueAllocationID,
} from '@graphprotocol/indexer-common'
Expand Down Expand Up @@ -173,7 +173,7 @@ const ALLOCATION_QUERIES = {

async function queryAllocations(
logger: Logger,
networkSubgraph: NetworkSubgraph,
networkSubgraph: SubgraphClient,
variables: {
indexer: Address
allocation: Address | null
Expand Down
Loading

0 comments on commit b1bdaf6

Please sign in to comment.