Add a flag to enable state creation (#222)

* Add a flag to enable state creation

* Update flag in mock config for testing
This commit is contained in:
prathamesh0 2022-11-10 05:26:06 -06:00 committed by GitHub
parent 8d3c68873b
commit 861420a10f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 58 additions and 14 deletions

View File

@ -9,13 +9,13 @@
# Checkpoint interval in number of blocks. # Checkpoint interval in number of blocks.
checkpointInterval = 2000 checkpointInterval = 2000
# Enable state creation
# CAUTION: Disable only if state creation is not desired or can be filled subsequently
enableState = true
{{#if (subgraphPath)}} {{#if (subgraphPath)}}
subgraphPath = "{{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 # Interval to restart wasm instance periodically
wasmRestartBlocksInterval = 20 wasmRestartBlocksInterval = 20

View File

@ -95,7 +95,9 @@ export const main = async (): Promise<any> => {
await graphWatcher.init(); await graphWatcher.init();
if (argv.state) { if (argv.state) {
assert(config.server.enableState, 'State creation disabled');
await fillState(indexer, graphDb, graphWatcher.dataSources, argv); await fillState(indexer, graphDb, graphWatcher.dataSources, argv);
return; return;
} }
{{/if}} {{/if}}

View File

@ -11,9 +11,9 @@
subgraphPath = "../graph-node/test/subgraph/eden" subgraphPath = "../graph-node/test/subgraph/eden"
# Disable creation of state from subgraph entity updates # Enable state creation
# CAUTION: Disable only if subgraph state is not desired or can be filled subsequently # CAUTION: Disable only if state creation is not desired or can be filled subsequently
disableSubgraphState = false enableState = true
# Interval to restart wasm instance periodically # Interval to restart wasm instance periodically
wasmRestartBlocksInterval = 20 wasmRestartBlocksInterval = 20

View File

@ -86,7 +86,9 @@ export const main = async (): Promise<any> => {
await graphWatcher.init(); await graphWatcher.init();
if (argv.state) { if (argv.state) {
assert(config.server.enableState, 'State creation disabled');
await fillState(indexer, graphDb, graphWatcher.dataSources, argv); await fillState(indexer, graphDb, graphWatcher.dataSources, argv);
return; return;
} }

View File

@ -43,7 +43,7 @@ export const main = async (): Promise<any> => {
const db = new Database(config.database); const db = new Database(config.database);
await db.init(); await db.init();
const graphDb = new GraphDatabase(db._baseDatabase); const graphDb = new GraphDatabase(db.baseDatabase);
await graphDb.init(); await graphDb.init();
const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server); const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);

View File

@ -9,6 +9,9 @@
# Checkpoint interval in number of blocks. # Checkpoint interval in number of blocks.
checkpointInterval = 2000 checkpointInterval = 2000
# Enable state creation
enableState = true
# Boolean to filter logs by contract. # Boolean to filter logs by contract.
filterLogs = false filterLogs = false

View File

@ -98,9 +98,8 @@ export const instantiate = async (
const dbEntity = await database.saveEntity(entityName, dbData); const dbEntity = await database.saveEntity(entityName, dbData);
database.cacheUpdatedEntityByName(entityName, dbEntity); database.cacheUpdatedEntityByName(entityName, dbEntity);
// Update the in-memory subgraph state if not disabled. // Update the in-memory subgraph state enabled
// TODO: enableSubgraphState if (indexer.serverConfig.enableState) {
if (!indexer.serverConfig.disableSubgraphState) {
// Prepare diff data for the entity update // Prepare diff data for the entity update
assert(indexer.getRelationsMap); assert(indexer.getRelationsMap);
const diffData = prepareEntityState(dbData, entityName, indexer.getRelationsMap()); const diffData = prepareEntityState(dbData, entityName, indexer.getRelationsMap());

View File

@ -211,7 +211,7 @@ class ServerConfig implements ServerConfigInterface {
checkpointing: boolean; checkpointing: boolean;
checkpointInterval: number; checkpointInterval: number;
subgraphPath: string; subgraphPath: string;
disableSubgraphState: boolean; enableState: boolean;
wasmRestartBlocksInterval: number; wasmRestartBlocksInterval: number;
filterLogs: boolean; filterLogs: boolean;
maxEventsBlockRange: number; maxEventsBlockRange: number;
@ -226,7 +226,7 @@ class ServerConfig implements ServerConfigInterface {
this.checkpointing = false; this.checkpointing = false;
this.checkpointInterval = 0; this.checkpointInterval = 0;
this.subgraphPath = ''; this.subgraphPath = '';
this.disableSubgraphState = false; this.enableState = false;
this.wasmRestartBlocksInterval = 0; this.wasmRestartBlocksInterval = 0;
this.filterLogs = false; this.filterLogs = false;
this.maxEventsBlockRange = 0; this.maxEventsBlockRange = 0;

View File

@ -9,6 +9,9 @@
# Checkpoint interval in number of blocks. # Checkpoint interval in number of blocks.
checkpointInterval = 2000 checkpointInterval = 2000
# Enable state creation
enableState = true
subgraphPath = "../graph-node/test/subgraph/example1/build" subgraphPath = "../graph-node/test/subgraph/example1/build"
wasmRestartBlocksInterval = 20 wasmRestartBlocksInterval = 20

View File

@ -9,6 +9,9 @@
# Checkpoint interval in number of blocks. # Checkpoint interval in number of blocks.
checkpointInterval = 2000 checkpointInterval = 2000
# Enable state creation
enableState = true
# Boolean to filter logs by contract. # Boolean to filter logs by contract.
filterLogs = true filterLogs = true

View File

@ -37,7 +37,7 @@ export interface ServerConfig {
checkpointing: boolean; checkpointing: boolean;
checkpointInterval: number; checkpointInterval: number;
subgraphPath: string; subgraphPath: string;
disableSubgraphState: boolean; enableState: boolean;
wasmRestartBlocksInterval: number; wasmRestartBlocksInterval: number;
filterLogs: boolean; filterLogs: boolean;
maxEventsBlockRange: number; maxEventsBlockRange: number;

View File

@ -588,6 +588,10 @@ export class Indexer {
} }
async processCheckpoint (indexer: IndexerInterface, blockHash: string, checkpointInterval: number): Promise<void> { async processCheckpoint (indexer: IndexerInterface, blockHash: string, checkpointInterval: number): Promise<void> {
if (!this._serverConfig.enableState) {
return;
}
// Get all the contracts. // Get all the contracts.
const contracts = Object.values(this._watchedContracts); const contracts = Object.values(this._watchedContracts);
@ -615,6 +619,10 @@ export class Indexer {
} }
async processCLICheckpoint (indexer: IndexerInterface, contractAddress: string, blockHash?: string): Promise<string | undefined> { async processCLICheckpoint (indexer: IndexerInterface, contractAddress: string, blockHash?: string): Promise<string | undefined> {
if (!this._serverConfig.enableState) {
return;
}
// Getting the block for checkpoint. // Getting the block for checkpoint.
let block; let block;
@ -634,6 +642,10 @@ export class Indexer {
} }
async createStateCheckpoint (contractAddress: string, block: BlockProgressInterface, data: any): Promise<void> { async createStateCheckpoint (contractAddress: string, block: BlockProgressInterface, data: any): Promise<void> {
if (!this._serverConfig.enableState) {
return;
}
// Get the contract. // Get the contract.
const contract = this._watchedContracts[contractAddress]; const contract = this._watchedContracts[contractAddress];
assert(contract, `Contract ${contractAddress} not watched`); assert(contract, `Contract ${contractAddress} not watched`);
@ -652,6 +664,10 @@ export class Indexer {
blockHash: string, blockHash: string,
blockNumber: number blockNumber: number
): Promise<void> { ): Promise<void> {
if (!this._serverConfig.enableState) {
return;
}
// Get all the contracts. // Get all the contracts.
const contracts = Object.values(this._watchedContracts); const contracts = Object.values(this._watchedContracts);
@ -694,6 +710,10 @@ export class Indexer {
} }
async createDiffStaged (contractAddress: string, blockHash: string, data: any): Promise<void> { async createDiffStaged (contractAddress: string, blockHash: string, data: any): Promise<void> {
if (!this._serverConfig.enableState) {
return;
}
const block = await this.getBlockProgress(blockHash); const block = await this.getBlockProgress(blockHash);
assert(block); assert(block);
@ -729,6 +749,10 @@ export class Indexer {
} }
async createDiff (contractAddress: string, block: BlockProgressInterface, data: any): Promise<void> { async createDiff (contractAddress: string, block: BlockProgressInterface, data: any): Promise<void> {
if (!this._serverConfig.enableState) {
return;
}
// Get the contract. // Get the contract.
const contract = this._watchedContracts[contractAddress]; const contract = this._watchedContracts[contractAddress];
assert(contract, `Contract ${contractAddress} not watched`); assert(contract, `Contract ${contractAddress} not watched`);
@ -763,6 +787,10 @@ export class Indexer {
} }
async createCheckpoint (indexer: IndexerInterface, contractAddress: string, currentBlock: BlockProgressInterface): Promise<string | undefined> { async createCheckpoint (indexer: IndexerInterface, contractAddress: string, currentBlock: BlockProgressInterface): Promise<string | undefined> {
if (!this._serverConfig.enableState) {
return;
}
// Get the contract. // Get the contract.
const contract = this._watchedContracts[contractAddress]; const contract = this._watchedContracts[contractAddress];
assert(contract, `Contract ${contractAddress} not watched`); assert(contract, `Contract ${contractAddress} not watched`);
@ -964,6 +992,10 @@ export class Indexer {
} }
async fetchStateStatus (): Promise<void> { async fetchStateStatus (): Promise<void> {
if (!this._serverConfig.enableState) {
return;
}
const contracts = Object.values(this._watchedContracts); const contracts = Object.values(this._watchedContracts);
// TODO: Fire a single query for all contracts. // TODO: Fire a single query for all contracts.