diff --git a/packages/codegen/src/templates/config-template.handlebars b/packages/codegen/src/templates/config-template.handlebars index 87ec8e45..8c7f2b4d 100644 --- a/packages/codegen/src/templates/config-template.handlebars +++ b/packages/codegen/src/templates/config-template.handlebars @@ -9,13 +9,13 @@ # Checkpoint interval in number of blocks. checkpointInterval = 2000 + # Enable state creation + # CAUTION: Disable only if state creation is not desired or can be filled subsequently + enableState = true + {{#if (subgraphPath)}} subgraphPath = "{{subgraphPath}}" - # Disable creation of state from subgraph entity updates - # CAUTION: Disable only if subgraph state is not desired or can be filled subsequently - disableSubgraphState = false - # Interval to restart wasm instance periodically wasmRestartBlocksInterval = 20 diff --git a/packages/codegen/src/templates/fill-template.handlebars b/packages/codegen/src/templates/fill-template.handlebars index 97b95c87..96399b18 100644 --- a/packages/codegen/src/templates/fill-template.handlebars +++ b/packages/codegen/src/templates/fill-template.handlebars @@ -95,7 +95,9 @@ export const main = async (): Promise => { await graphWatcher.init(); if (argv.state) { + assert(config.server.enableState, 'State creation disabled'); await fillState(indexer, graphDb, graphWatcher.dataSources, argv); + return; } {{/if}} diff --git a/packages/eden-watcher/environments/local.toml b/packages/eden-watcher/environments/local.toml index c74299c6..4eeed2ca 100644 --- a/packages/eden-watcher/environments/local.toml +++ b/packages/eden-watcher/environments/local.toml @@ -11,9 +11,9 @@ subgraphPath = "../graph-node/test/subgraph/eden" - # Disable creation of state from subgraph entity updates - # CAUTION: Disable only if subgraph state is not desired or can be filled subsequently - disableSubgraphState = false + # Enable state creation + # CAUTION: Disable only if state creation is not desired or can be filled subsequently + enableState = true # Interval to restart wasm instance periodically wasmRestartBlocksInterval = 20 diff --git a/packages/eden-watcher/src/fill.ts b/packages/eden-watcher/src/fill.ts index 3c9fd809..b6f93651 100644 --- a/packages/eden-watcher/src/fill.ts +++ b/packages/eden-watcher/src/fill.ts @@ -86,7 +86,9 @@ export const main = async (): Promise => { await graphWatcher.init(); if (argv.state) { + assert(config.server.enableState, 'State creation disabled'); await fillState(indexer, graphDb, graphWatcher.dataSources, argv); + return; } diff --git a/packages/eden-watcher/src/server.ts b/packages/eden-watcher/src/server.ts index 4fa99b6d..102e20d7 100644 --- a/packages/eden-watcher/src/server.ts +++ b/packages/eden-watcher/src/server.ts @@ -43,7 +43,7 @@ export const main = async (): Promise => { const db = new Database(config.database); await db.init(); - const graphDb = new GraphDatabase(db._baseDatabase); + const graphDb = new GraphDatabase(db.baseDatabase); await graphDb.init(); const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server); diff --git a/packages/erc721-watcher/environments/local.toml b/packages/erc721-watcher/environments/local.toml index 837c5ae4..cb9c2929 100644 --- a/packages/erc721-watcher/environments/local.toml +++ b/packages/erc721-watcher/environments/local.toml @@ -9,6 +9,9 @@ # Checkpoint interval in number of blocks. checkpointInterval = 2000 + # Enable state creation + enableState = true + # Boolean to filter logs by contract. filterLogs = false diff --git a/packages/graph-node/src/loader.ts b/packages/graph-node/src/loader.ts index 2a30a301..80f6bb69 100644 --- a/packages/graph-node/src/loader.ts +++ b/packages/graph-node/src/loader.ts @@ -98,9 +98,8 @@ export const instantiate = async ( const dbEntity = await database.saveEntity(entityName, dbData); database.cacheUpdatedEntityByName(entityName, dbEntity); - // Update the in-memory subgraph state if not disabled. - // TODO: enableSubgraphState - if (!indexer.serverConfig.disableSubgraphState) { + // Update the in-memory subgraph state enabled + if (indexer.serverConfig.enableState) { // Prepare diff data for the entity update assert(indexer.getRelationsMap); const diffData = prepareEntityState(dbData, entityName, indexer.getRelationsMap()); diff --git a/packages/graph-node/test/utils/indexer.ts b/packages/graph-node/test/utils/indexer.ts index f468f0d2..7586b63a 100644 --- a/packages/graph-node/test/utils/indexer.ts +++ b/packages/graph-node/test/utils/indexer.ts @@ -211,7 +211,7 @@ class ServerConfig implements ServerConfigInterface { checkpointing: boolean; checkpointInterval: number; subgraphPath: string; - disableSubgraphState: boolean; + enableState: boolean; wasmRestartBlocksInterval: number; filterLogs: boolean; maxEventsBlockRange: number; @@ -226,7 +226,7 @@ class ServerConfig implements ServerConfigInterface { this.checkpointing = false; this.checkpointInterval = 0; this.subgraphPath = ''; - this.disableSubgraphState = false; + this.enableState = false; this.wasmRestartBlocksInterval = 0; this.filterLogs = false; this.maxEventsBlockRange = 0; diff --git a/packages/graph-test-watcher/environments/local.toml b/packages/graph-test-watcher/environments/local.toml index 17a472f4..5397e56a 100644 --- a/packages/graph-test-watcher/environments/local.toml +++ b/packages/graph-test-watcher/environments/local.toml @@ -9,6 +9,9 @@ # Checkpoint interval in number of blocks. checkpointInterval = 2000 + # Enable state creation + enableState = true + subgraphPath = "../graph-node/test/subgraph/example1/build" wasmRestartBlocksInterval = 20 diff --git a/packages/mobymask-watcher/environments/local.toml b/packages/mobymask-watcher/environments/local.toml index 625311d5..2c46f0f0 100644 --- a/packages/mobymask-watcher/environments/local.toml +++ b/packages/mobymask-watcher/environments/local.toml @@ -9,6 +9,9 @@ # Checkpoint interval in number of blocks. checkpointInterval = 2000 + # Enable state creation + enableState = true + # Boolean to filter logs by contract. filterLogs = true diff --git a/packages/util/src/config.ts b/packages/util/src/config.ts index 2b4787a7..277c9325 100644 --- a/packages/util/src/config.ts +++ b/packages/util/src/config.ts @@ -37,7 +37,7 @@ export interface ServerConfig { checkpointing: boolean; checkpointInterval: number; subgraphPath: string; - disableSubgraphState: boolean; + enableState: boolean; wasmRestartBlocksInterval: number; filterLogs: boolean; maxEventsBlockRange: number; diff --git a/packages/util/src/indexer.ts b/packages/util/src/indexer.ts index 3fa43d0d..f1529407 100644 --- a/packages/util/src/indexer.ts +++ b/packages/util/src/indexer.ts @@ -588,6 +588,10 @@ export class Indexer { } async processCheckpoint (indexer: IndexerInterface, blockHash: string, checkpointInterval: number): Promise { + if (!this._serverConfig.enableState) { + return; + } + // Get all the contracts. const contracts = Object.values(this._watchedContracts); @@ -615,6 +619,10 @@ export class Indexer { } async processCLICheckpoint (indexer: IndexerInterface, contractAddress: string, blockHash?: string): Promise { + if (!this._serverConfig.enableState) { + return; + } + // Getting the block for checkpoint. let block; @@ -634,6 +642,10 @@ export class Indexer { } async createStateCheckpoint (contractAddress: string, block: BlockProgressInterface, data: any): Promise { + if (!this._serverConfig.enableState) { + return; + } + // Get the contract. const contract = this._watchedContracts[contractAddress]; assert(contract, `Contract ${contractAddress} not watched`); @@ -652,6 +664,10 @@ export class Indexer { blockHash: string, blockNumber: number ): Promise { + if (!this._serverConfig.enableState) { + return; + } + // Get all the contracts. const contracts = Object.values(this._watchedContracts); @@ -694,6 +710,10 @@ export class Indexer { } async createDiffStaged (contractAddress: string, blockHash: string, data: any): Promise { + if (!this._serverConfig.enableState) { + return; + } + const block = await this.getBlockProgress(blockHash); assert(block); @@ -729,6 +749,10 @@ export class Indexer { } async createDiff (contractAddress: string, block: BlockProgressInterface, data: any): Promise { + if (!this._serverConfig.enableState) { + return; + } + // Get the contract. const contract = this._watchedContracts[contractAddress]; assert(contract, `Contract ${contractAddress} not watched`); @@ -763,6 +787,10 @@ export class Indexer { } async createCheckpoint (indexer: IndexerInterface, contractAddress: string, currentBlock: BlockProgressInterface): Promise { + if (!this._serverConfig.enableState) { + return; + } + // Get the contract. const contract = this._watchedContracts[contractAddress]; assert(contract, `Contract ${contractAddress} not watched`); @@ -964,6 +992,10 @@ export class Indexer { } async fetchStateStatus (): Promise { + if (!this._serverConfig.enableState) { + return; + } + const contracts = Object.values(this._watchedContracts); // TODO: Fire a single query for all contracts.