diff --git a/packages/indexer-agent/src/agent.ts b/packages/indexer-agent/src/agent.ts index 055b5d046..8f6aa4863 100644 --- a/packages/indexer-agent/src/agent.ts +++ b/packages/indexer-agent/src/agent.ts @@ -908,28 +908,42 @@ class Agent { ) if (expiredAllocations.length > 0) { - logger.info(`Reallocating expired allocations`, { - number: expiredAllocations.length, - expiredAllocations: expiredAllocations.map(allocation => allocation.id), - }) + if (rule?.autoRenewal) { + logger.info(`Reallocating expired allocations`, { + number: expiredAllocations.length, + expiredAllocations: expiredAllocations.map( + allocation => allocation.id, + ), + }) - // We do a synchronous for-loop and await each iteration so that we can patch the contents - // of activeAllocations with new allocations as they are made. This is important so that each - // iteration gets an up to date copy of activeAllocations - for (let i = 0; i <= activeAllocations.length - 1; i++) { - const oldAllocation = activeAllocations[i] - if (allocationInList(expiredAllocations, oldAllocation)) { - const { newAllocation, reallocated } = await this.reallocate( - epochStartBlock, - oldAllocation, - desiredAllocationAmount, - activeAllocations, - ) - if (reallocated) { - // Patch existing index with new allocation - activeAllocations[i] = newAllocation as Allocation + // We do a synchronous for-loop and await each iteration so that we can patch the contents + // of activeAllocations with new allocations as they are made. This is important so that each + // iteration gets an up to date copy of activeAllocations + for (let i = 0; i <= activeAllocations.length - 1; i++) { + const oldAllocation = activeAllocations[i] + if (allocationInList(expiredAllocations, oldAllocation)) { + const { newAllocation, reallocated } = await this.reallocate( + epochStartBlock, + oldAllocation, + desiredAllocationAmount, + activeAllocations, + ) + if (reallocated) { + // Patch existing index with new allocation + activeAllocations[i] = newAllocation as Allocation + } } } + } else { + logger.info( + `Skipping reallocating of expired allocations since the corresponding rule has 'autoRenewal' = False`, + { + number: expiredAllocations.length, + expiredAllocations: expiredAllocations.map( + allocation => allocation.id, + ), + }, + ) } } } diff --git a/packages/indexer-agent/src/db/migrations/06-indexing-rules-add-max-lifetime.ts b/packages/indexer-agent/src/db/migrations/06-indexing-rules-add-max-lifetime.ts index 86e8190a3..ffa54ec26 100644 --- a/packages/indexer-agent/src/db/migrations/06-indexing-rules-add-max-lifetime.ts +++ b/packages/indexer-agent/src/db/migrations/06-indexing-rules-add-max-lifetime.ts @@ -51,11 +51,6 @@ export async function down({ context }: Context): Promise { 'allocationLifetime', { transaction }, ) - - logger.info(`Remove 'int_IndexingRules_allocationLifetime' custom type`) - await queryInterface.sequelize.query( - `delete from pg_type where typname = 'int_IndexingRules_allocationLifetime'`, - ) } }) } diff --git a/packages/indexer-agent/src/db/migrations/07-indexing-rules-add-require-supported.ts b/packages/indexer-agent/src/db/migrations/07-indexing-rules-add-require-supported.ts index 96072250c..a67b5c4e4 100644 --- a/packages/indexer-agent/src/db/migrations/07-indexing-rules-add-require-supported.ts +++ b/packages/indexer-agent/src/db/migrations/07-indexing-rules-add-require-supported.ts @@ -50,11 +50,6 @@ export async function down({ context }: Context): Promise { 'requireSupported', { transaction }, ) - - logger.info(`Remove 'bool_IndexingRules_requireSupported' custom type`) - await queryInterface.sequelize.query( - `delete from pg_type where typname = 'bool_IndexingRules_requireSupported'`, - ) } }) } diff --git a/packages/indexer-agent/src/db/migrations/08-indexing-rules-add-auto-renewal.ts b/packages/indexer-agent/src/db/migrations/08-indexing-rules-add-auto-renewal.ts new file mode 100644 index 000000000..edf897490 --- /dev/null +++ b/packages/indexer-agent/src/db/migrations/08-indexing-rules-add-auto-renewal.ts @@ -0,0 +1,54 @@ +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 { + 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 autoRenewal = table.autoRenewal + if (autoRenewal) { + logger.info(`'autoRenewal' columns already exist, migration not necessary`) + return + } + + logger.info(`Add 'autoRenewal' column to 'IndexingRules' table`) + await queryInterface.addColumn('IndexingRules', 'autoRenewal', { + type: DataTypes.BOOLEAN, + allowNull: false, + defaultValue: true, + }) +} + +export async function down({ context }: Context): Promise { + const { queryInterface, logger } = context + + return await queryInterface.sequelize.transaction({}, async transaction => { + const tables = await queryInterface.showAllTables() + + if (tables.includes('IndexingRules')) { + logger.info(`Remove 'autoRenewal' column`) + await context.queryInterface.removeColumn( + 'IndexingRules', + 'autoRenewal', + { transaction }, + ) + } + }) +} diff --git a/packages/indexer-agent/src/indexer.ts b/packages/indexer-agent/src/indexer.ts index f941e31a7..4e1e3d301 100644 --- a/packages/indexer-agent/src/indexer.ts +++ b/packages/indexer-agent/src/indexer.ts @@ -220,6 +220,7 @@ export class Indexer { identifierType allocationAmount allocationLifetime + autoRenewal parallelAllocations maxAllocationPercentage minSignal @@ -297,6 +298,7 @@ export class Indexer { identifierType allocationAmount allocationLifetime + autoRenewal parallelAllocations maxAllocationPercentage minSignal diff --git a/packages/indexer-cli/src/__tests__/indexer/rules.test.ts b/packages/indexer-cli/src/__tests__/indexer/rules.test.ts index c5daa6914..c710f367d 100644 --- a/packages/indexer-cli/src/__tests__/indexer/rules.test.ts +++ b/packages/indexer-cli/src/__tests__/indexer/rules.test.ts @@ -325,6 +325,8 @@ describe('Indexer rules tests', () => { 'offchain', 'allocationLifetime', '21', + 'autoRenewal', + 'false', ], 'references/indexer-rule-deployment-lifetime', { diff --git a/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-always.stdout b/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-always.stdout index be9ae701f..a5bcdb0c3 100644 --- a/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-always.stdout +++ b/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-always.stdout @@ -1,5 +1,5 @@ -┌────────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ -│ 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 │ -└────────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ +┌────────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ +│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ autoRenewal │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │ +├────────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────┤ +│ QmZZtzZkfzCWMNrajxBf22q7BC9HzoT5iJUK3S8qA6zNZr │ deployment │ null │ null │ true │ null │ null │ null │ null │ null │ null │ null │ always │ true │ +└────────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ diff --git a/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-lifetime.stdout b/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-lifetime.stdout index 6db31456e..fd1e733c9 100644 --- a/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-lifetime.stdout +++ b/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-lifetime.stdout @@ -1,5 +1,5 @@ -┌────────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ -│ 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 │ -└────────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ +┌────────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ +│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ autoRenewal │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │ +├────────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────┤ +│ QmZfeJYR86UARzp9HiXbURWunYgC9ywvPvoePNbuaATrEK │ deployment │ null │ 21 │ false │ null │ null │ null │ null │ null │ null │ null │ offchain │ true │ +└────────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ diff --git a/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-never.stdout b/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-never.stdout index 6ae1f2893..0777546c3 100644 --- a/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-never.stdout +++ b/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-never.stdout @@ -1,5 +1,5 @@ -┌────────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ -│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │ -├────────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────┤ -│ QmZZtzZkfzCWMNrajxBf22q7BC9HzoT5iJUK3S8qA6zNZr │ deployment │ null │ null │ null │ null │ null │ null │ null │ null │ null │ never │ true │ -└────────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ +┌────────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ +│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ autoRenewal │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │ +├────────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────┤ +│ QmZZtzZkfzCWMNrajxBf22q7BC9HzoT5iJUK3S8qA6zNZr │ deployment │ null │ null │ true │ null │ null │ null │ null │ null │ null │ null │ never │ true │ +└────────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ diff --git a/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-offchain.stdout b/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-offchain.stdout index 6ee517399..87223206d 100644 --- a/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-offchain.stdout +++ b/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-offchain.stdout @@ -1,5 +1,5 @@ -┌────────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ -│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │ -├────────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────┤ -│ QmZfeJYR86UARzp9HiXbURWunYgC9ywvPvoePNbuaATrEK │ deployment │ null │ null │ null │ null │ null │ null │ null │ null │ null │ offchain │ true │ -└────────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ +┌────────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ +│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ autoRenewal │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │ +├────────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────┤ +│ QmZfeJYR86UARzp9HiXbURWunYgC9ywvPvoePNbuaATrEK │ deployment │ null │ null │ true │ null │ null │ null │ null │ null │ null │ null │ offchain │ true │ +└────────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ diff --git a/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-rules.stdout b/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-rules.stdout index 87bf334b6..7721e8b4c 100644 --- a/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-rules.stdout +++ b/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-rules.stdout @@ -1,5 +1,5 @@ -┌────────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ -│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │ -├────────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────┤ -│ QmZZtzZkfzCWMNrajxBf22q7BC9HzoT5iJUK3S8qA6zNZr │ deployment │ null │ null │ null │ null │ null │ null │ null │ null │ null │ rules │ true │ -└────────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ +┌────────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ +│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ autoRenewal │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │ +├────────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────┤ +│ QmZZtzZkfzCWMNrajxBf22q7BC9HzoT5iJUK3S8qA6zNZr │ deployment │ null │ null │ true │ null │ null │ null │ null │ null │ null │ null │ rules │ true │ +└────────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ diff --git a/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-supported.stdout b/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-supported.stdout index 6f26882f9..78c05f717 100644 --- a/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-supported.stdout +++ b/packages/indexer-cli/src/__tests__/references/indexer-rule-deployment-supported.stdout @@ -1,5 +1,5 @@ -┌────────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ -│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │ -├────────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────┤ -│ QmVEV7RA2U6BJT9Ssjxcfyrk4YQUnVqSRNX4TvYagjzh9h │ deployment │ null │ null │ null │ null │ null │ null │ null │ null │ null │ rules │ false │ -└────────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ +┌────────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ +│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ autoRenewal │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │ +├────────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────┤ +│ QmVEV7RA2U6BJT9Ssjxcfyrk4YQUnVqSRNX4TvYagjzh9h │ deployment │ null │ null │ true │ null │ null │ null │ null │ null │ null │ null │ rules │ false │ +└────────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ diff --git a/packages/indexer-cli/src/__tests__/references/indexer-rule-global-rules.stdout b/packages/indexer-cli/src/__tests__/references/indexer-rule-global-rules.stdout index 57ec855dd..b141131f6 100644 --- a/packages/indexer-cli/src/__tests__/references/indexer-rule-global-rules.stdout +++ b/packages/indexer-cli/src/__tests__/references/indexer-rule-global-rules.stdout @@ -1,5 +1,5 @@ -┌────────────┬────────────────┬──────────────────┬────────────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ -│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │ -├────────────┼────────────────┼──────────────────┼────────────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────┤ -│ global │ group │ 0.01 │ null │ null │ null │ 500.0 │ null │ null │ null │ null │ rules │ true │ -└────────────┴────────────────┴──────────────────┴────────────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ +┌────────────┬────────────────┬──────────────────┬────────────────────┬─────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ +│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ autoRenewal │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │ +├────────────┼────────────────┼──────────────────┼────────────────────┼─────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────┤ +│ global │ group │ 0.01 │ null │ true │ null │ null │ 500.0 │ null │ null │ null │ null │ rules │ true │ +└────────────┴────────────────┴──────────────────┴────────────────────┴─────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ diff --git a/packages/indexer-cli/src/__tests__/references/indexer-rule-subgraph-offchain.stdout b/packages/indexer-cli/src/__tests__/references/indexer-rule-subgraph-offchain.stdout index 2c903f3cd..0ec2117aa 100644 --- a/packages/indexer-cli/src/__tests__/references/indexer-rule-subgraph-offchain.stdout +++ b/packages/indexer-cli/src/__tests__/references/indexer-rule-subgraph-offchain.stdout @@ -1,5 +1,5 @@ -┌──────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ -│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │ -├──────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────┤ -│ 0x0000000000000000000000000000000000000000-1 │ subgraph │ 1,000.0 │ 12 │ null │ null │ null │ null │ null │ null │ null │ offchain │ true │ -└──────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ +┌──────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ +│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ autoRenewal │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │ +├──────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────┤ +│ 0x0000000000000000000000000000000000000000-1 │ subgraph │ 1,000.0 │ 12 │ true │ null │ null │ null │ null │ null │ null │ null │ offchain │ true │ +└──────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ diff --git a/packages/indexer-cli/src/__tests__/references/indexer-rule-subgraph-options.stdout b/packages/indexer-cli/src/__tests__/references/indexer-rule-subgraph-options.stdout index f797b7250..93f7fcdbd 100644 --- a/packages/indexer-cli/src/__tests__/references/indexer-rule-subgraph-options.stdout +++ b/packages/indexer-cli/src/__tests__/references/indexer-rule-subgraph-options.stdout @@ -1,5 +1,5 @@ -┌──────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ -│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │ -├──────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────┤ -│ 0x0000000000000000000000000000000000000000-2 │ subgraph │ 1,000.0 │ 12 │ null │ null │ null │ null │ null │ null │ null │ offchain │ true │ -└──────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ +┌──────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ +│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ autoRenewal │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │ +├──────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────┤ +│ 0x0000000000000000000000000000000000000000-2 │ subgraph │ 1,000.0 │ 12 │ true │ null │ null │ null │ null │ null │ null │ null │ offchain │ true │ +└──────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ diff --git a/packages/indexer-cli/src/__tests__/references/indexer-rule-subgraph-rules.stdout b/packages/indexer-cli/src/__tests__/references/indexer-rule-subgraph-rules.stdout index 136ce58bd..3940bfa24 100644 --- a/packages/indexer-cli/src/__tests__/references/indexer-rule-subgraph-rules.stdout +++ b/packages/indexer-cli/src/__tests__/references/indexer-rule-subgraph-rules.stdout @@ -1,5 +1,5 @@ -┌──────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ -│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │ -├──────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────┤ -│ 0x0000000000000000000000000000000000000000-0 │ subgraph │ 1,000.0 │ null │ null │ null │ null │ null │ null │ null │ null │ rules │ true │ -└──────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ +┌──────────────────────────────────────────────┬────────────────┬──────────────────┬────────────────────┬─────────────┬─────────────────────┬─────────────────────────┬───────────┬───────────┬──────────┬─────────────────────┬────────┬───────────────┬──────────────────┐ +│ identifier │ identifierType │ allocationAmount │ allocationLifetime │ autoRenewal │ parallelAllocations │ maxAllocationPercentage │ minSignal │ maxSignal │ minStake │ minAverageQueryFees │ custom │ decisionBasis │ requireSupported │ +├──────────────────────────────────────────────┼────────────────┼──────────────────┼────────────────────┼─────────────┼─────────────────────┼─────────────────────────┼───────────┼───────────┼──────────┼─────────────────────┼────────┼───────────────┼──────────────────┤ +│ 0x0000000000000000000000000000000000000000-0 │ subgraph │ 1,000.0 │ null │ true │ null │ null │ null │ null │ null │ null │ null │ rules │ true │ +└──────────────────────────────────────────────┴────────────────┴──────────────────┴────────────────────┴─────────────┴─────────────────────┴─────────────────────────┴───────────┴───────────┴──────────┴─────────────────────┴────────┴───────────────┴──────────────────┘ diff --git a/packages/indexer-cli/src/commands/indexer/rules/clear.ts b/packages/indexer-cli/src/commands/indexer/rules/clear.ts index bbfaa6103..f604f08eb 100644 --- a/packages/indexer-cli/src/commands/indexer/rules/clear.ts +++ b/packages/indexer-cli/src/commands/indexer/rules/clear.ts @@ -55,6 +55,7 @@ module.exports = { keys.push( 'allocationAmount', 'allocationLifetime', + 'autoRenewal', 'parallelAllocations', 'minSignal', 'maxSignal', @@ -85,6 +86,7 @@ module.exports = { ), identifier, identifierType, + autoRenewal: true, }) const client = await createIndexerManagementClient({ url: config.api }) diff --git a/packages/indexer-cli/src/commands/indexer/status.ts b/packages/indexer-cli/src/commands/indexer/status.ts index 4d05e9d13..25e8a82b1 100644 --- a/packages/indexer-cli/src/commands/indexer/status.ts +++ b/packages/indexer-cli/src/commands/indexer/status.ts @@ -119,6 +119,7 @@ module.exports = { identifierType allocationAmount allocationLifetime + autoRenewal parallelAllocations maxAllocationPercentage minSignal diff --git a/packages/indexer-cli/src/rules.ts b/packages/indexer-cli/src/rules.ts index 996807db4..7577d12e8 100644 --- a/packages/indexer-cli/src/rules.ts +++ b/packages/indexer-cli/src/rules.ts @@ -30,12 +30,14 @@ export const parseDecisionBasis = (s: string): IndexingDecisionBasis => { return s as IndexingDecisionBasis } } + export const parseBoolean = ( val: string | boolean | number | undefined | null, ): boolean => { const s = val && val.toString().toLowerCase().trim() return s != 'false' && s != 'f' && s != '0' } + function nullPassThrough(fn: (x: T) => U): (x: T | null) => U | null { return (x: T | null) => (x === null ? null : fn(x)) } @@ -47,6 +49,7 @@ const INDEXING_RULE_PARSERS: Record identifierType: x => x, allocationAmount: nullPassThrough(parseGRT), allocationLifetime: nullPassThrough(parseInt), + autoRenewal: nullPassThrough(parseBoolean), parallelAllocations: nullPassThrough(parseInt), minSignal: nullPassThrough(parseGRT), maxSignal: nullPassThrough(parseGRT), @@ -68,6 +71,7 @@ const INDEXING_RULE_FORMATTERS: Record< identifierType: x => x, allocationAmount: nullPassThrough(x => utils.commify(formatGRT(x))), allocationLifetime: nullPassThrough((x: number) => x.toString()), + autoRenewal: x => x, parallelAllocations: nullPassThrough((x: number) => x.toString()), maxSignal: nullPassThrough(x => utils.commify(formatGRT(x))), minSignal: nullPassThrough(x => utils.commify(formatGRT(x))), @@ -89,6 +93,7 @@ const INDEXING_RULE_CONVERTERS_FROM_GRAPHQL: Record< identifierType: x => x, allocationAmount: nullPassThrough((x: string) => BigNumber.from(x)), allocationLifetime: nullPassThrough((x: string) => parseInt(x)), + autoRenewal: x => x, parallelAllocations: nullPassThrough((x: string) => parseInt(x)), minSignal: nullPassThrough((x: string) => BigNumber.from(x)), maxSignal: nullPassThrough((x: string) => BigNumber.from(x)), @@ -110,6 +115,7 @@ const INDEXING_RULE_CONVERTERS_TO_GRAPHQL: Record< identifierType: x => x, allocationAmount: nullPassThrough((x: BigNumber) => x.toString()), allocationLifetime: nullPassThrough((x: number) => x), + autoRenewal: x => x, parallelAllocations: nullPassThrough((x: number) => x), minSignal: nullPassThrough((x: BigNumber) => x.toString()), maxSignal: nullPassThrough((x: BigNumber) => x.toString()), @@ -257,6 +263,7 @@ export const indexingRules = async ( identifierType allocationAmount allocationLifetime + autoRenewal parallelAllocations maxAllocationPercentage minSignal @@ -294,6 +301,7 @@ export const indexingRule = async ( identifierType allocationAmount allocationLifetime + autoRenewal parallelAllocations maxAllocationPercentage minSignal @@ -334,6 +342,7 @@ export const setIndexingRule = async ( identifierType allocationAmount allocationLifetime + autoRenewal parallelAllocations maxAllocationPercentage minSignal diff --git a/packages/indexer-common/src/indexer-management/__tests__/indexing-rules.ts b/packages/indexer-common/src/indexer-management/__tests__/indexing-rules.ts index 1e39efa2d..c165eec08 100644 --- a/packages/indexer-common/src/indexer-management/__tests__/indexing-rules.ts +++ b/packages/indexer-common/src/indexer-management/__tests__/indexing-rules.ts @@ -38,6 +38,7 @@ const SET_INDEXING_RULE_MUTATION = gql` identifierType allocationAmount allocationLifetime + autoRenewal parallelAllocations maxAllocationPercentage minSignal @@ -70,6 +71,7 @@ const INDEXING_RULE_QUERY = gql` identifierType allocationAmount allocationLifetime + autoRenewal parallelAllocations maxAllocationPercentage minSignal @@ -90,6 +92,7 @@ const INDEXING_RULES_QUERY = gql` identifierType allocationAmount allocationLifetime + autoRenewal parallelAllocations maxAllocationPercentage minSignal @@ -166,6 +169,7 @@ describe('Indexing rules', () => { const expected = { ...input, allocationLifetime: null, + autoRenewal: true, parallelAllocations: null, maxAllocationPercentage: null, minSignal: null, @@ -195,7 +199,8 @@ describe('Indexing rules', () => { identifier: INDEXING_RULE_GLOBAL, identifierType: SubgraphIdentifierType.GROUP, allocationAmount: '1', - allocationLifetime: 2, + allocationLifetime: 10, + autoRenewal: true, parallelAllocations: 1, maxAllocationPercentage: 0.5, minSignal: '2', @@ -235,6 +240,7 @@ describe('Indexing rules', () => { const original = { ...originalInput, allocationLifetime: null, + autoRenewal: true, parallelAllocations: null, maxAllocationPercentage: null, maxSignal: null, @@ -256,7 +262,7 @@ describe('Indexing rules', () => { allocationAmount: null, maxSignal: '3', decisionBasis: IndexingDecisionBasis.OFFCHAIN, - allocationLifetime: 7, + autoRenewal: true, } const expected = { @@ -289,6 +295,7 @@ describe('Indexing rules', () => { const original = { ...originalInput, allocationLifetime: null, + autoRenewal: true, parallelAllocations: null, maxAllocationPercentage: null, maxSignal: null, @@ -311,6 +318,7 @@ describe('Indexing rules', () => { maxSignal: '3', decisionBasis: IndexingDecisionBasis.ALWAYS, allocationLifetime: 2, + autoRenewal: false, requireSupported: false, } @@ -338,7 +346,9 @@ describe('Indexing rules', () => { const updateAgain = { identifier: '0xa4e311bfa7edabed7b31d93e0b3e751659669852ef46adbedd44dc2454db4bf3', identifierType: SubgraphIdentifierType.DEPLOYMENT, + allocationLifetime: null, decisionBasis: IndexingDecisionBasis.NEVER, + autoRenewal: true, } const expectedAgain = { @@ -380,11 +390,13 @@ describe('Indexing rules', () => { minSignal: '2', decisionBasis: IndexingDecisionBasis.OFFCHAIN, requireSupported: false, + autoRenewal: false, } const globalExpected = { ...globalInput, allocationLifetime: null, + autoRenewal: true, parallelAllocations: null, maxAllocationPercentage: null, maxSignal: null, @@ -398,6 +410,7 @@ describe('Indexing rules', () => { const deploymentExpected = { ...deploymentInput, allocationLifetime: null, + autoRenewal: false, parallelAllocations: null, maxAllocationPercentage: null, maxSignal: null, @@ -449,12 +462,14 @@ describe('Indexing rules', () => { identifierType: SubgraphIdentifierType.DEPLOYMENT, allocationAmount: '1', minSignal: '2', - allocationLifetime: 13, + allocationLifetime: 20, + autoRenewal: false, } const expected = { ...input, - allocationLifetime: 13, + allocationLifetime: 20, + autoRenewal: false, parallelAllocations: null, maxAllocationPercentage: null, maxSignal: null, @@ -499,6 +514,7 @@ describe('Indexing rules', () => { const expectedBefore = { ...input, allocationLifetime: null, + autoRenewal: true, parallelAllocations: null, maxAllocationPercentage: null, minSignal: null, @@ -549,6 +565,7 @@ describe('Indexing rules', () => { minAverageQueryFees: '1', allocationLifetime: 15, requireSupported: true, + autoRenewal: true, } const deploymentInput = { @@ -557,12 +574,15 @@ describe('Indexing rules', () => { allocationAmount: '1', minSignal: '2', decisionBasis: IndexingDecisionBasis.OFFCHAIN, + allocationLifetime: 10, + autoRenewal: false, requireSupported: false, } const globalExpected = { ...globalInput, allocationLifetime: 15, + autoRenewal: true, parallelAllocations: null, maxAllocationPercentage: null, maxSignal: null, @@ -574,7 +594,8 @@ describe('Indexing rules', () => { const deploymentExpected = { ...deploymentInput, - allocationLifetime: null, + allocationLifetime: 10, + autoRenewal: false, parallelAllocations: null, maxAllocationPercentage: null, maxSignal: null, @@ -587,7 +608,8 @@ describe('Indexing rules', () => { const deploymentMergedExpected = { ...deploymentInput, - allocationLifetime: 15, + allocationLifetime: 10, + autoRenewal: false, parallelAllocations: null, maxAllocationPercentage: null, maxSignal: null, @@ -672,6 +694,7 @@ describe('Indexing rules', () => { identifier: 'global', identifierType: SubgraphIdentifierType.GROUP, allocationLifetime: null, + autoRenewal: true, maxAllocationPercentage: null, maxSignal: null, minAverageQueryFees: null, @@ -727,6 +750,7 @@ describe('Indexing rules', () => { identifier: 'global', identifierType: SubgraphIdentifierType.GROUP, allocationLifetime: null, + autoRenewal: true, maxAllocationPercentage: null, maxSignal: null, minAverageQueryFees: null, diff --git a/packages/indexer-common/src/indexer-management/client.ts b/packages/indexer-common/src/indexer-management/client.ts index 234ab7296..d28df6d84 100644 --- a/packages/indexer-common/src/indexer-management/client.ts +++ b/packages/indexer-common/src/indexer-management/client.ts @@ -91,6 +91,7 @@ const SCHEMA_SDL = gql` identifierType: IdentifierType! allocationAmount: BigInt allocationLifetime: Int + autoRenewal: Boolean! parallelAllocations: Int maxAllocationPercentage: Float minSignal: BigInt @@ -107,6 +108,7 @@ const SCHEMA_SDL = gql` identifierType: IdentifierType! allocationAmount: BigInt allocationLifetime: Int + autoRenewal: Boolean parallelAllocations: Int maxAllocationPercentage: Float minSignal: BigInt diff --git a/packages/indexer-common/src/indexer-management/models/indexing-rule.ts b/packages/indexer-common/src/indexer-management/models/indexing-rule.ts index 3b0e870ee..74f8de42c 100644 --- a/packages/indexer-common/src/indexer-management/models/indexing-rule.ts +++ b/packages/indexer-common/src/indexer-management/models/indexing-rule.ts @@ -18,6 +18,7 @@ export interface IndexingRuleAttributes { identifierType: SubgraphIdentifierType allocationAmount: string | null allocationLifetime: number | null + autoRenewal: boolean parallelAllocations: number | null maxAllocationPercentage: number | null minSignal: string | null @@ -37,6 +38,7 @@ export interface IndexingRuleCreationAttributes | 'identifierType' | 'allocationAmount' | 'allocationLifetime' + | 'autoRenewal' | 'parallelAllocations' | 'maxAllocationPercentage' | 'minSignal' @@ -57,6 +59,7 @@ export class IndexingRule public identifierType!: SubgraphIdentifierType public allocationAmount!: string | null public allocationLifetime!: number | null + public autoRenewal!: boolean public parallelAllocations!: number | null public maxAllocationPercentage!: number | null public minSignal!: string | null @@ -143,6 +146,11 @@ export const defineIndexingRuleModels = (sequelize: Sequelize): IndexingRuleMode min: 1, }, }, + autoRenewal: { + type: DataTypes.BOOLEAN, + allowNull: false, + defaultValue: true, + }, parallelAllocations: { type: DataTypes.INTEGER, allowNull: true,