Skip to content

Commit 8b454df

Browse files
hopeyenhopeyen
authored andcommitted
indexer-agent, indexer-cli, indexer-common: reject unsupported subgraphs
1 parent 7015498 commit 8b454df

21 files changed

+189
-41
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ dist
104104
.tern-port
105105
.npmrc
106106
.yarnrc
107+
.envrc
107108

108109
# Terraform state files
109110
*.tfstate*

packages/indexer-agent/src/agent.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
IndexingRuleAttributes,
2121
NetworkSubgraph,
2222
POIDisputeAttributes,
23-
RewardsPool,
2423
Subgraph,
2524
SubgraphIdentifierType,
2625
} from '@graphprotocol/indexer-common'
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { Logger } from '@graphprotocol/common-ts'
2+
import { DataTypes, QueryInterface } from 'sequelize'
3+
4+
interface MigrationContext {
5+
queryInterface: QueryInterface
6+
logger: Logger
7+
}
8+
9+
interface Context {
10+
context: MigrationContext
11+
}
12+
13+
export async function up({ context }: Context): Promise<void> {
14+
const { queryInterface, logger } = context
15+
16+
logger.debug(`Checking if indexing rules table exists`)
17+
const tables = await queryInterface.showAllTables()
18+
if (!tables.includes('IndexingRules')) {
19+
logger.info(`Indexing rules table does not exist, migration not necessary`)
20+
return
21+
}
22+
23+
logger.debug(`Checking if 'IndexingRules' table needs to be migrated`)
24+
const table = await queryInterface.describeTable('IndexingRules')
25+
const requireSupportedColumn = table.requireSupported
26+
if (requireSupportedColumn) {
27+
logger.info(
28+
`'requireSupported' columns already exist, migration not necessary`,
29+
)
30+
return
31+
}
32+
33+
logger.info(`Add 'requireSupported' column to 'IndexingRules' table`)
34+
await queryInterface.addColumn('IndexingRules', 'requireSupported', {
35+
type: DataTypes.BOOLEAN,
36+
defaultValue: true,
37+
})
38+
}
39+
40+
export async function down({ context }: Context): Promise<void> {
41+
const { queryInterface, logger } = context
42+
43+
return await queryInterface.sequelize.transaction({}, async transaction => {
44+
const tables = await queryInterface.showAllTables()
45+
46+
if (tables.includes('IndexingRules')) {
47+
logger.info(`Remove 'requireSupported' column`)
48+
await context.queryInterface.removeColumn(
49+
'IndexingRules',
50+
'requireSupported',
51+
{ transaction },
52+
)
53+
54+
logger.info(`Remove 'enum_IndexingRules_identifierType' custom type`)
55+
await queryInterface.sequelize.query(
56+
`delete from pg_type where typname = 'bool_IndexingRules_requireSupported'`,
57+
)
58+
}
59+
})
60+
}

packages/indexer-agent/src/indexer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ export class Indexer {
227227
minAverageQueryFees
228228
custom
229229
decisionBasis
230+
requireSupported
230231
}
231232
}
232233
`,
@@ -266,6 +267,7 @@ export class Indexer {
266267
identifierType
267268
allocationAmount
268269
decisionBasis
270+
requireSupported
269271
}
270272
}
271273
`,
@@ -282,6 +284,7 @@ export class Indexer {
282284
allocationAmount: this.defaultAllocationAmount.toString(),
283285
parallelAllocations: 1,
284286
decisionBasis: 'rules',
287+
requireSupported: true,
285288
}
286289

287290
const defaultGlobalRule = await this.indexerManagement
@@ -300,6 +303,7 @@ export class Indexer {
300303
minAverageQueryFees
301304
custom
302305
decisionBasis
306+
requireSupported
303307
}
304308
}
305309
`,

packages/indexer-agent/src/network.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ export class Network {
619619
) {
620620
id
621621
ipfsHash
622+
deniedAt
622623
stakedTokens
623624
signalAmount
624625
queryFeesAmount
@@ -689,7 +690,8 @@ export class Network {
689690

690691
this.logger.trace('Deciding whether to allocate and index', {
691692
deployment: {
692-
id: deployment.id,
693+
id: deployment.id.display,
694+
deniedAt: deployment.deniedAt,
693695
stakedTokens: stakedTokens.toString(),
694696
signalAmount: signalAmount.toString(),
695697
avgQueryFees: avgQueryFees.toString(),
@@ -711,16 +713,28 @@ export class Network {
711713
deploymentRule.minAverageQueryFees,
712714
).toString()
713715
: null,
716+
requireSupported: deploymentRule.requireSupported,
714717
},
715718
})
719+
720+
// Reject unsupported subgraph by default
721+
if (
722+
deployment.deniedAt > 0 &&
723+
deploymentRule.requireSupported
724+
) {
725+
return false
726+
}
716727

717728
// Skip the indexing rules checks if the decision basis is 'always' or 'never'
718729
if (
719-
deploymentRule.decisionBasis === IndexingDecisionBasis.ALWAYS
730+
deploymentRule?.decisionBasis === IndexingDecisionBasis.ALWAYS
720731
) {
721732
return true
722733
} else if (
723-
deploymentRule.decisionBasis === IndexingDecisionBasis.NEVER
734+
deploymentRule?.decisionBasis ===
735+
IndexingDecisionBasis.NEVER ||
736+
deploymentRule?.decisionBasis ===
737+
IndexingDecisionBasis.OFFCHAIN
724738
) {
725739
return false
726740
}

packages/indexer-cli/src/__tests__/indexer/rules.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ describe('Indexer rules tests', () => {
267267
},
268268
)
269269
cliTest(
270-
'Indexer rules set subgraph id - success - offchain',
270+
'Indexer rules set subgraph id offchain - success',
271271
[
272272
'indexer',
273273
'rules',
@@ -295,6 +295,23 @@ describe('Indexer rules tests', () => {
295295
timeout: 10000,
296296
},
297297
)
298+
cliTest(
299+
'Indexer rules set deployment id supported - success',
300+
[
301+
'indexer',
302+
'rules',
303+
'set',
304+
'QmVEV7RA2U6BJT9Ssjxcfyrk4YQUnVqSRNX4TvYagjzh9h',
305+
'requireSupported',
306+
'false',
307+
],
308+
'references/indexer-rule-deployment-supported',
309+
{
310+
expectedExitCode: 0,
311+
cwd: baseDir,
312+
timeout: 10000,
313+
},
314+
)
298315
cliTest(
299316
'Indexer rules set deployment id - success - offchain',
300317
[
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
┌────────────────────────────────────────────────┬────────────────┬──────────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┐
2-
│ identifier │ identifierType │ allocationAmount │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │
3-
├────────────────────────────────────────────────┼────────────────┼──────────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┤
4-
│ QmZZtzZkfzCWMNrajxBf22q7BC9HzoT5iJUK3S8qA6zNZr │ deployment │ null │ null │ null │ null │ null │ null │ null │ null │ always │
5-
└────────────────────────────────────────────────┴────────────────┴──────────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┘
1+
┌────────────────────────────────────────────────┬────────────────┬──────────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────
2+
│ identifier │ identifierType │ allocationAmount │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │
3+
├────────────────────────────────────────────────┼────────────────┼──────────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────
4+
│ QmZZtzZkfzCWMNrajxBf22q7BC9HzoT5iJUK3S8qA6zNZr │ deployment │ null │ null │ null │ null │ null │ null │ null │ null │ always │ true │
5+
└────────────────────────────────────────────────┴────────────────┴──────────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
┌────────────────────────────────────────────────┬────────────────┬──────────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┐
2-
│ identifier │ identifierType │ allocationAmount │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │
3-
├────────────────────────────────────────────────┼────────────────┼──────────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┤
4-
│ QmZZtzZkfzCWMNrajxBf22q7BC9HzoT5iJUK3S8qA6zNZr │ deployment │ null │ null │ null │ null │ null │ null │ null │ null │ never │
5-
└────────────────────────────────────────────────┴────────────────┴──────────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┘
1+
┌────────────────────────────────────────────────┬────────────────┬──────────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────
2+
│ identifier │ identifierType │ allocationAmount │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │
3+
├────────────────────────────────────────────────┼────────────────┼──────────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────
4+
│ QmZZtzZkfzCWMNrajxBf22q7BC9HzoT5iJUK3S8qA6zNZr │ deployment │ null │ null │ null │ null │ null │ null │ null │ null │ never │ true │
5+
└────────────────────────────────────────────────┴────────────────┴──────────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────

0 commit comments

Comments
 (0)