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.
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

View File

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

View File

@ -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

View File

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

View File

@ -43,7 +43,7 @@ export const main = async (): Promise<any> => {
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);

View File

@ -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

View File

@ -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());

View File

@ -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;

View File

@ -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

View File

@ -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

View File

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

View File

@ -588,6 +588,10 @@ export class Indexer {
}
async processCheckpoint (indexer: IndexerInterface, blockHash: string, checkpointInterval: number): Promise<void> {
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<string | undefined> {
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<void> {
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<void> {
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<void> {
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<void> {
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<string | undefined> {
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<void> {
if (!this._serverConfig.enableState) {
return;
}
const contracts = Object.values(this._watchedContracts);
// TODO: Fire a single query for all contracts.