Update getFullBlocks usage (#213)

* Update getFullBlocks usage to add block number arg

* Add skipStateFieldsUpdate config for uniswap-watcher

Co-authored-by: nabarun <nabarun@deepstacksoft.com>
This commit is contained in:
prathamesh0 2022-11-03 06:19:41 -05:00 committed by GitHub
parent be65ca45ea
commit 266442a6d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 18 additions and 13 deletions

View File

@ -390,9 +390,9 @@ export class Indexer implements IndexerInterface {
}
{{#if (subgraphPath)}}
async processBlockAfterEvents (blockHash: string): Promise<void> {
async processBlockAfterEvents (blockHash: string, blockNumber: number): Promise<void> {
// Call subgraph handler for block.
await this._graphWatcher.handleBlock(blockHash);
await this._graphWatcher.handleBlock(blockHash, blockNumber);
// Persist subgraph state to the DB.
await this.dumpSubgraphState(blockHash);

View File

@ -310,11 +310,11 @@ export class Indexer implements IndexerInterface {
this._graphWatcher.updateEntityCacheFrothyBlocks(blockProgress);
}
async processBlockAfterEvents (blockHash: string): Promise<void> {
async processBlockAfterEvents (blockHash: string, blockNumber: number): Promise<void> {
console.time('time:indexer#processBlockAfterEvents-mapping_code');
// Call subgraph handler for block.
await this._graphWatcher.handleBlock(blockHash);
await this._graphWatcher.handleBlock(blockHash, blockNumber);
console.timeEnd('time:indexer#processBlockAfterEvents-mapping_code');

View File

@ -131,7 +131,7 @@ export class GraphWatcher {
// Check if block data is already fetched by a previous event in the same block.
if (!this._context.block || this._context.block.blockHash !== block.hash) {
this._context.block = await getFullBlock(this._ethClient, this._ethProvider, block.hash);
this._context.block = await getFullBlock(this._ethClient, this._ethProvider, block.hash, block.number);
}
const blockData = this._context.block;
@ -194,10 +194,10 @@ export class GraphWatcher {
}
}
async handleBlock (blockHash: string) {
async handleBlock (blockHash: string, blockNumber: number) {
// Check if block data is already fetched in handleEvent method for the same block.
if (!this._context.block || this._context.block.blockHash !== blockHash) {
this._context.block = await getFullBlock(this._ethClient, this._ethProvider, blockHash);
this._context.block = await getFullBlock(this._ethClient, this._ethProvider, blockHash, blockNumber);
}
const blockData = this._context.block;

View File

@ -216,6 +216,7 @@ class ServerConfig implements ServerConfigInterface {
filterLogs: boolean;
maxEventsBlockRange: number;
clearEntitiesCacheInterval: number;
skipStateFieldsUpdate: boolean;
constructor () {
this.host = '';
@ -230,5 +231,6 @@ class ServerConfig implements ServerConfigInterface {
this.filterLogs = false;
this.maxEventsBlockRange = 0;
this.clearEntitiesCacheInterval = 0;
this.skipStateFieldsUpdate = false;
}
}

View File

@ -319,9 +319,9 @@ export class Indexer implements IndexerInterface {
this._graphWatcher.updateEntityCacheFrothyBlocks(blockProgress);
}
async processBlockAfterEvents (blockHash: string): Promise<void> {
async processBlockAfterEvents (blockHash: string, blockNumber: number): Promise<void> {
// Call subgraph handler for block.
await this._graphWatcher.handleBlock(blockHash);
await this._graphWatcher.handleBlock(blockHash, blockNumber);
// Persist subgraph state to the DB.
await this.dumpSubgraphState(blockHash);

View File

@ -294,7 +294,7 @@ export const processBatchEvents = async (indexer: IndexerInterface, block: Block
if (indexer.processBlockAfterEvents) {
if (!block.isComplete) {
await indexer.processBlockAfterEvents(block.blockHash);
await indexer.processBlockAfterEvents(block.blockHash, block.blockNumber);
}
}

View File

@ -42,6 +42,9 @@ export interface ServerConfig {
filterLogs: boolean;
maxEventsBlockRange: number;
clearEntitiesCacheInterval: number;
// Boolean to skip updating entity fields required in state creation and not required in the frontend.
skipStateFieldsUpdate: boolean;
}
export interface UpstreamConfig {

View File

@ -179,14 +179,14 @@ class CustomFormatter extends providers.Formatter {
}
}
export const getFullBlock = async (ethClient: EthClient, ethProvider: providers.BaseProvider, blockHash: string): Promise<any> => {
export const getFullBlock = async (ethClient: EthClient, ethProvider: providers.BaseProvider, blockHash: string, blockNumber: number): Promise<any> => {
const {
allEthHeaderCids: {
nodes: [
fullBlock
]
}
} = await ethClient.getFullBlocks({ blockHash });
} = await ethClient.getFullBlocks({ blockHash, blockNumber });
assert(fullBlock.blockByMhKey);

View File

@ -113,7 +113,7 @@ export interface IndexerInterface {
processInitialState?: (contractAddress: string, blockHash: string) => Promise<any>
processStateCheckpoint?: (contractAddress: string, blockHash: string) => Promise<boolean>
processBlock: (blockProgres: BlockProgressInterface) => Promise<void>
processBlockAfterEvents?: (blockHash: string) => Promise<void>
processBlockAfterEvents?: (blockHash: string, blockNumber: number) => Promise<void>
processCanonicalBlock (blockHash: string, blockNumber: number): Promise<void>
processCheckpoint (blockHash: string): Promise<void>
getStorageValue (storageLayout: StorageLayout, blockHash: string, contractAddress: string, variable: string, ...mappingKeys: MappingKey[]): Promise<ValueResult>