Skip to content

Commit

Permalink
Partially reverts PR #615
Browse files Browse the repository at this point in the history
Partially reverts PR #615
  • Loading branch information
tilacog committed Apr 14, 2023
1 parent 25b9ac1 commit 260e9fc
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 207 deletions.
4 changes: 0 additions & 4 deletions packages/indexer-agent/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.20.14] - 2023-03-29
### Changed
- Subgraph deployment names are now format as: `<SUBGRAPH_NAME>/<IPFS_HASH>/<OWNER_ADDRESSS>`

## [0.20.12] - 2023-02-19
### Changed
- Only require network current epoch resolutio if indexing a subgraph on network chain
Expand Down
8 changes: 2 additions & 6 deletions packages/indexer-agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
SubgraphIdentifierType,
evaluateDeployments,
AllocationDecision,
formatDeploymentName,
} from '@graphprotocol/indexer-common'
import { Indexer } from './indexer'
import { AgentConfig } from './types'
Expand Down Expand Up @@ -689,11 +688,8 @@ class Agent {
// Index all new deployments worth indexing
await queue.addAll(
deploy.map(deployment => async () => {
const subgraphDeployment =
await this.networkMonitor.requireSubgraphDeployment(
deployment.ipfsHash,
)
const name = formatDeploymentName(subgraphDeployment)
const name = `indexer-agent/${deployment.ipfsHash.slice(-10)}`

this.logger.info(`Index subgraph deployment`, {
name,
deployment: deployment.display,
Expand Down
5 changes: 1 addition & 4 deletions packages/indexer-agent/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,8 @@ export default {

if (networkSubgraphDeploymentId !== undefined) {
// Make sure the network subgraph is being indexed
//
// TODO: once the Network Subgraph is published to the Network, we can use the
// `formatDeploymentName` function instead of using a hardcoded deployment name.
await indexer.ensure(
`graphprotocol/network-subgraph/${networkSubgraphDeploymentId.ipfsHash}`,
`indexer-agent/${networkSubgraphDeploymentId.ipfsHash.slice(-10)}`,
networkSubgraphDeploymentId,
)

Expand Down
31 changes: 30 additions & 1 deletion packages/indexer-agent/src/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,36 @@ export class Indexer {
}

async subgraphDeployments(): Promise<SubgraphDeploymentID[]> {
return await this.statusResolver.subgraphDeployments()
try {
const result = await this.statusResolver.statuses
.query(
gql`
{
indexingStatuses {
subgraphDeployment: subgraph
node
}
}
`,
)
.toPromise()

if (result.error) {
throw result.error
}

return result.data.indexingStatuses
.filter((status: { subgraphDeployment: string; node: string }) => {
return status.node && status.node !== 'removed'
})
.map((status: { subgraphDeployment: string; node: string }) => {
return new SubgraphDeploymentID(status.subgraphDeployment)
})
} catch (error) {
const err = indexerError(IndexerErrorCode.IE018, error)
this.logger.error(`Failed to query indexing status API`, { err })
throw err
}
}

async indexNodes(): Promise<indexNode[]> {
Expand Down
88 changes: 0 additions & 88 deletions packages/indexer-common/src/__tests__/subgraphs.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1077,8 +1077,6 @@ describe('Allocation Manager', () => {
const mapper = (x: Action) => allocationManager.resolveActionDelta(x)
const balances = await Promise.all(actions.map(mapper))

console.table(balances)

const allocate = balances[0]
const unallocate = balances[1]
const reallocate = balances[2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
CloseAllocationResult,
CreateAllocationResult,
fetchIndexingRules,
formatDeploymentName,
indexerError,
IndexerError,
IndexerErrorCode,
Expand Down Expand Up @@ -332,15 +331,11 @@ export class AllocationManager {
)
}

const subgraphDeployment = await this.networkMonitor.requireSubgraphDeployment(
deployment.ipfsHash,
)

// Ensure subgraph is deployed before allocating
await this.subgraphManager.ensure(
logger,
this.models,
formatDeploymentName(subgraphDeployment),
`indexer-agent/${deployment.ipfsHash.slice(-10)}`,
deployment,
indexNode,
)
Expand Down
24 changes: 0 additions & 24 deletions packages/indexer-common/src/indexer-management/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,6 @@ export class NetworkMonitor {
id
}
}
versions(first: 1, orderBy: version, orderDirection: desc) {
subgraph {
displayName
creatorAddress
}
}
}
}
`,
Expand Down Expand Up @@ -483,18 +477,6 @@ export class NetworkMonitor {
}
}

// Wrapper function over this.subgraphDeployment that will throw an
// error on missing subgraph deployments
async requireSubgraphDeployment(ipfsHash: string): Promise<SubgraphDeployment> {
const subgraphDeployment = await this.subgraphDeployment(ipfsHash)
if (!subgraphDeployment) {
const errorMessage = `Failed to locate subgraph deployment with id ${ipfsHash} in the Network Subgraph`
this.logger.error(errorMessage, { ipfsHash })
throw indexerError(IndexerErrorCode.IE020, errorMessage)
}
return subgraphDeployment
}

async subgraphDeployments(): Promise<SubgraphDeployment[]> {
const deployments = []
const queryProgress = {
Expand Down Expand Up @@ -531,12 +513,6 @@ export class NetworkMonitor {
id
}
}
versions(first: 1, orderBy: version, orderDirection: desc) {
subgraph {
displayName
creatorAddress
}
}
}
}
`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
NetworkMonitor,
epochElapsedBlocks,
formatDeploymentName,
} from '@graphprotocol/indexer-common'
import { NetworkMonitor, epochElapsedBlocks } from '@graphprotocol/indexer-common'
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable @typescript-eslint/ban-types */

Expand Down Expand Up @@ -425,13 +421,13 @@ export default {
logger.debug('Execute createAllocation() mutation', { deployment, amount })

const allocationAmount = parseGRT(amount)
const subgraphDeploymentID = new SubgraphDeploymentID(deployment)
const subgraphDeployment = new SubgraphDeploymentID(deployment)

const activeAllocations = await networkMonitor.allocations(AllocationStatus.ACTIVE)

const allocation = activeAllocations.find(
(allocation) =>
allocation.subgraphDeployment.id.toString() === subgraphDeploymentID.toString(),
allocation.subgraphDeployment.id.toString() === subgraphDeployment.toString(),
)
if (allocation) {
logger.warn('Already allocated to deployment', {
Expand Down Expand Up @@ -479,16 +475,12 @@ export default {
)
}

const subgraphDeployment = await networkMonitor.requireSubgraphDeployment(
subgraphDeploymentID.ipfsHash,
)

// Ensure subgraph is deployed before allocating
await subgraphManager.ensure(
logger,
models,
formatDeploymentName(subgraphDeployment),
subgraphDeploymentID,
`indexer-agent/${subgraphDeployment.ipfsHash.slice(-10)}`,
subgraphDeployment,
indexNode,
)

Expand All @@ -498,7 +490,7 @@ export default {
const { allocationSigner, allocationId } = uniqueAllocationID(
transactionManager.wallet.mnemonic.phrase,
currentEpoch.toNumber(),
subgraphDeploymentID,
subgraphDeployment,
activeAllocations.map((allocation) => allocation.id),
)

Expand Down Expand Up @@ -536,7 +528,7 @@ export default {

logger.debug(`Sending allocateFrom transaction`, {
indexer: address,
subgraphDeployment: subgraphDeploymentID.ipfsHash,
subgraphDeployment: subgraphDeployment.ipfsHash,
amount: formatGRT(allocationAmount),
allocation: allocationId,
proof,
Expand All @@ -546,7 +538,7 @@ export default {
async () =>
contracts.staking.estimateGas.allocateFrom(
address,
subgraphDeploymentID.bytes32,
subgraphDeployment.bytes32,
allocationAmount,
allocationId,
utils.hexlify(Array(32).fill(0)),
Expand All @@ -555,7 +547,7 @@ export default {
async (gasLimit) =>
contracts.staking.allocateFrom(
address,
subgraphDeploymentID.bytes32,
subgraphDeployment.bytes32,
allocationAmount,
allocationId,
utils.hexlify(Array(32).fill(0)),
Expand Down Expand Up @@ -602,7 +594,7 @@ export default {
`Updating indexing rules, so indexer-agent will now manage the active allocation`,
)
const indexingRule = {
identifier: subgraphDeploymentID.ipfsHash,
identifier: subgraphDeployment.ipfsHash,
allocationAmount: allocationAmount.toString(),
identifierType: SubgraphIdentifierType.DEPLOYMENT,
decisionBasis: IndexingDecisionBasis.ALWAYS,
Expand Down
2 changes: 0 additions & 2 deletions packages/indexer-common/src/indexer-management/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ export const parseGraphQLSubgraphDeployment = (
signalledTokens: BigNumber.from(subgraphDeployment.signalledTokens),
queryFeesAmount: BigNumber.from(subgraphDeployment.queryFeesAmount),
activeAllocations: subgraphDeployment.indexerAllocations.length,
name: subgraphDeployment.versions[0].subgraph.displayName,
creatorAddress: toAddress(subgraphDeployment.versions[0].subgraph.creatorAddress),
})

/* eslint-disable @typescript-eslint/no-explicit-any */
Expand Down
Loading

0 comments on commit 260e9fc

Please sign in to comment.