Skip to content

Commit

Permalink
indexer-agent, indexer-cli, indexer-common: reject unsupported subgraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen authored and hopeyen committed Feb 22, 2022
1 parent ba14ae7 commit 144996e
Show file tree
Hide file tree
Showing 23 changed files with 201 additions and 52 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ dist
.tern-port
.npmrc
.yarnrc
.envrc

# Terraform state files
*.tfstate*
Expand Down
2 changes: 1 addition & 1 deletion packages/indexer-agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Allocation,
allocationRewardsPool,
AllocationStatus,
RewardsPool,
BlockPointer,
IndexingDecisionBasis,
indexerError,
Expand All @@ -20,7 +21,6 @@ import {
IndexingRuleAttributes,
NetworkSubgraph,
POIDisputeAttributes,
RewardsPool,
Subgraph,
SubgraphIdentifierType,
} from '@graphprotocol/indexer-common'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Logger } from '@graphprotocol/common-ts'
import { DataTypes, QueryInterface } from 'sequelize'

interface MigrationContext {
queryInterface: QueryInterface
logger: Logger
}

interface Context {
context: MigrationContext
}

export async function up({ context }: Context): Promise<void> {
const { queryInterface, logger } = context

logger.debug(`Checking if indexing rules table exists`)
const tables = await queryInterface.showAllTables()
if (!tables.includes('IndexingRules')) {
logger.info(`Indexing rules table does not exist, migration not necessary`)
return
}

logger.debug(`Checking if 'IndexingRules' table needs to be migrated`)
const table = await queryInterface.describeTable('IndexingRules')
const requireSupportedColumn = table.requireSupported
if (requireSupportedColumn) {
logger.info(
`'requireSupported' columns already exist, migration not necessary`,
)
return
}

logger.info(`Add 'requireSupported' column to 'IndexingRules' table`)
await queryInterface.addColumn('IndexingRules', 'requireSupported', {
type: DataTypes.BOOLEAN,
defaultValue: false,
})
}

export async function down({ context }: Context): Promise<void> {
const { queryInterface, logger } = context

return await queryInterface.sequelize.transaction({}, async transaction => {
const tables = await queryInterface.showAllTables()

if (tables.includes('IndexingRules')) {
logger.info(`Remove 'requireSupported' column`)
await context.queryInterface.removeColumn(
'IndexingRules',
'requireSupported',
{ transaction },
)

logger.info(`Remove 'bool_IndexingRules_requireSupported' custom type`)
await queryInterface.sequelize.query(
`delete from pg_type where typname = 'bool_IndexingRules_requireSupported'`,
)
}
})
}
4 changes: 4 additions & 0 deletions packages/indexer-agent/src/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export class Indexer {
minAverageQueryFees
custom
decisionBasis
requireSupported
}
}
`,
Expand Down Expand Up @@ -267,6 +268,7 @@ export class Indexer {
identifierType
allocationAmount
decisionBasis
requireSupported
}
}
`,
Expand All @@ -283,6 +285,7 @@ export class Indexer {
allocationAmount: this.defaultAllocationAmount.toString(),
parallelAllocations: 1,
decisionBasis: 'rules',
requireSupported: true,
}

const defaultGlobalRule = await this.indexerManagement
Expand All @@ -302,6 +305,7 @@ export class Indexer {
minAverageQueryFees
custom
decisionBasis
requireSupported
}
}
`,
Expand Down
22 changes: 18 additions & 4 deletions packages/indexer-agent/src/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ export class Network {
) {
id
ipfsHash
deniedAt
stakedTokens
signalAmount
queryFeesAmount
Expand Down Expand Up @@ -694,7 +695,8 @@ export class Network {

this.logger.trace('Deciding whether to allocate and index', {
deployment: {
id: deployment.id,
id: deployment.id.display,
deniedAt: deployment.deniedAt,
stakedTokens: stakedTokens.toString(),
signalAmount: signalAmount.toString(),
avgQueryFees: avgQueryFees.toString(),
Expand All @@ -716,16 +718,28 @@ export class Network {
deploymentRule.minAverageQueryFees,
).toString()
: null,
requireSupported: deploymentRule.requireSupported,
},
})

// Skip the indexing rules checks if the decision basis is 'always' or 'never'
// Reject unsupported subgraph by default
if (
deploymentRule.decisionBasis === IndexingDecisionBasis.ALWAYS
deployment.deniedAt > 0 &&
deploymentRule.requireSupported
) {
return false
}

// Skip the indexing rules checks if the decision basis is 'always', 'never', or 'offchain'
if (
deploymentRule?.decisionBasis === IndexingDecisionBasis.ALWAYS
) {
return true
} else if (
deploymentRule.decisionBasis === IndexingDecisionBasis.NEVER
deploymentRule?.decisionBasis ===
IndexingDecisionBasis.NEVER ||
deploymentRule?.decisionBasis ===
IndexingDecisionBasis.OFFCHAIN
) {
return false
}
Expand Down
19 changes: 18 additions & 1 deletion packages/indexer-cli/src/__tests__/indexer/rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,24 @@ describe('Indexer rules tests', () => {
},
)
cliTest(
'Indexer rules set deployment lifetime - success',
'Indexer rules set deployment id supported - success',
[
'indexer',
'rules',
'set',
'QmVEV7RA2U6BJT9Ssjxcfyrk4YQUnVqSRNX4TvYagjzh9h',
'requireSupported',
'false',
],
'references/indexer-rule-deployment-supported',
{
expectedExitCode: 0,
cwd: baseDir,
timeout: 10000,
},
)
cliTest(
'Indexer rules set deployment id - success - offchain',
[
'indexer',
'rules',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
┌────────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┐
│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │
├────────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┤
│ QmZZtzZkfzCWMNrajxBf22q7BC9HzoT5iJUK3S8qA6zNZr │ deployment │ null │ null │ null │ null │ null │ null │ null │ null │ null │ always │
└────────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┘
┌────────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────
│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │
├────────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────
│ QmZZtzZkfzCWMNrajxBf22q7BC9HzoT5iJUK3S8qA6zNZr │ deployment │ null │ null │ null │ null │ null │ null │ null │ null │ null │ always │ true │
└────────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
┌────────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┐
│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │
├────────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┤
│ QmZfeJYR86UARzp9HiXbURWunYgC9ywvPvoePNbuaATrEK │ deployment │ null │ 21 │ null │ null │ null │ null │ null │ null │ null │ offchain │
└────────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┘
┌────────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────
│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │
├────────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────
│ QmZfeJYR86UARzp9HiXbURWunYgC9ywvPvoePNbuaATrEK │ deployment │ null │ 21 │ null │ null │ null │ null │ null │ null │ null │ offchain │ true │
└────────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────
Loading

0 comments on commit 144996e

Please sign in to comment.