diff --git a/lerna.json b/lerna.json index 638998e7..de924ed2 100644 --- a/lerna.json +++ b/lerna.json @@ -2,7 +2,7 @@ "packages": [ "packages/*" ], - "version": "0.2.17", + "version": "0.2.18", "npmClient": "yarn", "useWorkspaces": true, "command": { diff --git a/packages/address-watcher/package.json b/packages/address-watcher/package.json index 89e43fc8..8fe1080f 100644 --- a/packages/address-watcher/package.json +++ b/packages/address-watcher/package.json @@ -1,6 +1,6 @@ { "name": "@cerc-io/address-watcher", - "version": "0.2.17", + "version": "0.2.18", "description": "Address Watcher", "private": true, "scripts": { @@ -26,11 +26,11 @@ "homepage": "https://github.com/cerc-io/watcher-ts#readme", "dependencies": { "@apollo/client": "^3.3.19", - "@cerc-io/cache": "^0.2.17", - "@cerc-io/ipld-eth-client": "^0.2.17", - "@cerc-io/solidity-mapper": "^0.2.17", - "@cerc-io/tracing-client": "^0.2.17", - "@cerc-io/util": "^0.2.17", + "@cerc-io/cache": "^0.2.18", + "@cerc-io/ipld-eth-client": "^0.2.18", + "@cerc-io/solidity-mapper": "^0.2.18", + "@cerc-io/tracing-client": "^0.2.18", + "@cerc-io/util": "^0.2.18", "@types/lodash": "^4.14.168", "debug": "^4.3.1", "ethers": "^5.4.4", diff --git a/packages/cache/package.json b/packages/cache/package.json index 12e1ed5b..d50dfc9c 100644 --- a/packages/cache/package.json +++ b/packages/cache/package.json @@ -1,6 +1,6 @@ { "name": "@cerc-io/cache", - "version": "0.2.17", + "version": "0.2.18", "description": "Generic object cache", "main": "dist/index.js", "scripts": { diff --git a/packages/cli/package.json b/packages/cli/package.json index c917e011..805c3b11 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@cerc-io/cli", - "version": "0.2.17", + "version": "0.2.18", "main": "dist/index.js", "license": "AGPL-3.0", "scripts": { @@ -10,7 +10,7 @@ "copy-assets": "copyfiles -u 1 src/**/*.gql dist/" }, "dependencies": { - "@cerc-io/util": "^0.2.17", + "@cerc-io/util": "^0.2.18", "@ethersproject/providers": "^5.4.4", "@graphql-tools/utils": "^9.1.1", "@ipld/dag-cbor": "^6.0.12", diff --git a/packages/codegen/package.json b/packages/codegen/package.json index cc9ff852..45baf84f 100644 --- a/packages/codegen/package.json +++ b/packages/codegen/package.json @@ -1,6 +1,6 @@ { "name": "@cerc-io/codegen", - "version": "0.2.17", + "version": "0.2.18", "description": "Code generator", "private": true, "main": "index.js", @@ -20,7 +20,7 @@ }, "homepage": "https://github.com/cerc-io/watcher-ts#readme", "dependencies": { - "@cerc-io/util": "^0.2.17", + "@cerc-io/util": "^0.2.18", "@graphql-tools/load-files": "^6.5.2", "@poanet/solidity-flattener": "https://github.com/vulcanize/solidity-flattener.git", "@solidity-parser/parser": "^0.13.2", diff --git a/packages/codegen/src/templates/package-template.handlebars b/packages/codegen/src/templates/package-template.handlebars index 09988954..cb5f3c28 100644 --- a/packages/codegen/src/templates/package-template.handlebars +++ b/packages/codegen/src/templates/package-template.handlebars @@ -41,12 +41,12 @@ "dependencies": { "@apollo/client": "^3.3.19", "@ethersproject/providers": "^5.4.4", - "@cerc-io/cli": "^0.2.17", - "@cerc-io/ipld-eth-client": "^0.2.17", - "@cerc-io/solidity-mapper": "^0.2.17", - "@cerc-io/util": "^0.2.17", + "@cerc-io/cli": "^0.2.18", + "@cerc-io/ipld-eth-client": "^0.2.18", + "@cerc-io/solidity-mapper": "^0.2.18", + "@cerc-io/util": "^0.2.18", {{#if (subgraphPath)}} - "@cerc-io/graph-node": "^0.2.17", + "@cerc-io/graph-node": "^0.2.18", {{/if}} "apollo-type-bigint": "^0.1.3", "debug": "^4.3.1", diff --git a/packages/eden-watcher/package.json b/packages/eden-watcher/package.json index 873b1587..bed21a7e 100644 --- a/packages/eden-watcher/package.json +++ b/packages/eden-watcher/package.json @@ -1,6 +1,6 @@ { "name": "@cerc-io/eden-watcher", - "version": "0.2.17", + "version": "0.2.18", "description": "eden-watcher", "private": true, "main": "dist/index.js", @@ -38,11 +38,11 @@ "homepage": "https://github.com/cerc-io/watcher-ts#readme", "dependencies": { "@apollo/client": "^3.3.19", - "@cerc-io/cli": "^0.2.17", - "@cerc-io/graph-node": "^0.2.17", - "@cerc-io/ipld-eth-client": "^0.2.17", - "@cerc-io/solidity-mapper": "^0.2.17", - "@cerc-io/util": "^0.2.17", + "@cerc-io/cli": "^0.2.18", + "@cerc-io/graph-node": "^0.2.18", + "@cerc-io/ipld-eth-client": "^0.2.18", + "@cerc-io/solidity-mapper": "^0.2.18", + "@cerc-io/util": "^0.2.18", "@ethersproject/providers": "^5.4.4", "apollo-type-bigint": "^0.1.3", "debug": "^4.3.1", diff --git a/packages/erc20-watcher/package.json b/packages/erc20-watcher/package.json index 1a6e4892..43d13da6 100644 --- a/packages/erc20-watcher/package.json +++ b/packages/erc20-watcher/package.json @@ -1,6 +1,6 @@ { "name": "@cerc-io/erc20-watcher", - "version": "0.2.17", + "version": "0.2.18", "description": "ERC20 Watcher", "private": true, "main": "dist/index.js", @@ -40,10 +40,10 @@ "homepage": "https://github.com/cerc-io/watcher-ts#readme", "dependencies": { "@apollo/client": "^3.3.19", - "@cerc-io/cli": "^0.2.17", - "@cerc-io/ipld-eth-client": "^0.2.17", - "@cerc-io/solidity-mapper": "^0.2.17", - "@cerc-io/util": "^0.2.17", + "@cerc-io/cli": "^0.2.18", + "@cerc-io/ipld-eth-client": "^0.2.18", + "@cerc-io/solidity-mapper": "^0.2.18", + "@cerc-io/util": "^0.2.18", "@ethersproject/providers": "^5.4.4", "apollo-type-bigint": "^0.1.3", "debug": "^4.3.1", diff --git a/packages/erc721-watcher/package.json b/packages/erc721-watcher/package.json index 2493aedb..6fa6909d 100644 --- a/packages/erc721-watcher/package.json +++ b/packages/erc721-watcher/package.json @@ -1,6 +1,6 @@ { "name": "@cerc-io/erc721-watcher", - "version": "0.2.17", + "version": "0.2.18", "description": "erc721-watcher", "private": true, "main": "dist/index.js", @@ -46,10 +46,10 @@ "homepage": "https://github.com/cerc-io/watcher-ts#readme", "dependencies": { "@apollo/client": "^3.3.19", - "@cerc-io/cli": "^0.2.17", - "@cerc-io/ipld-eth-client": "^0.2.17", - "@cerc-io/solidity-mapper": "^0.2.17", - "@cerc-io/util": "^0.2.17", + "@cerc-io/cli": "^0.2.18", + "@cerc-io/ipld-eth-client": "^0.2.18", + "@cerc-io/solidity-mapper": "^0.2.18", + "@cerc-io/util": "^0.2.18", "@ethersproject/providers": "^5.4.4", "apollo-type-bigint": "^0.1.3", "debug": "^4.3.1", diff --git a/packages/graph-node/package.json b/packages/graph-node/package.json index f83a5c88..763a35f8 100644 --- a/packages/graph-node/package.json +++ b/packages/graph-node/package.json @@ -1,10 +1,10 @@ { "name": "@cerc-io/graph-node", - "version": "0.2.17", + "version": "0.2.18", "main": "dist/index.js", "license": "AGPL-3.0", "devDependencies": { - "@cerc-io/solidity-mapper": "^0.2.17", + "@cerc-io/solidity-mapper": "^0.2.18", "@ethersproject/providers": "^5.4.4", "@graphprotocol/graph-ts": "^0.22.0", "@nomiclabs/hardhat-ethers": "^2.0.2", @@ -49,11 +49,11 @@ }, "dependencies": { "@apollo/client": "^3.3.19", - "@cerc-io/cache": "^0.2.17", - "@cerc-io/ipld-eth-client": "^0.2.17", - "@cerc-io/util": "^0.2.17", - "@types/json-diff": "^0.5.2", "@cerc-io/assemblyscript": "0.19.10-watcher-ts-0.1.2", + "@cerc-io/cache": "^0.2.18", + "@cerc-io/ipld-eth-client": "^0.2.18", + "@cerc-io/util": "^0.2.18", + "@types/json-diff": "^0.5.2", "bn.js": "^4.11.9", "debug": "^4.3.1", "fs-extra": "^10.0.0", diff --git a/packages/graph-test-watcher/package.json b/packages/graph-test-watcher/package.json index 6c4b2fa0..79d369a5 100644 --- a/packages/graph-test-watcher/package.json +++ b/packages/graph-test-watcher/package.json @@ -1,6 +1,6 @@ { "name": "@cerc-io/graph-test-watcher", - "version": "0.2.17", + "version": "0.2.18", "description": "graph-test-watcher", "private": true, "main": "dist/index.js", @@ -38,11 +38,11 @@ "homepage": "https://github.com/cerc-io/watcher-ts#readme", "dependencies": { "@apollo/client": "^3.3.19", - "@cerc-io/cli": "^0.2.17", - "@cerc-io/graph-node": "^0.2.17", - "@cerc-io/ipld-eth-client": "^0.2.17", - "@cerc-io/solidity-mapper": "^0.2.17", - "@cerc-io/util": "^0.2.17", + "@cerc-io/cli": "^0.2.18", + "@cerc-io/graph-node": "^0.2.18", + "@cerc-io/ipld-eth-client": "^0.2.18", + "@cerc-io/solidity-mapper": "^0.2.18", + "@cerc-io/util": "^0.2.18", "@ethersproject/providers": "^5.4.4", "apollo-type-bigint": "^0.1.3", "debug": "^4.3.1", diff --git a/packages/ipld-eth-client/package.json b/packages/ipld-eth-client/package.json index c6586674..a9fbcab2 100644 --- a/packages/ipld-eth-client/package.json +++ b/packages/ipld-eth-client/package.json @@ -1,6 +1,6 @@ { "name": "@cerc-io/ipld-eth-client", - "version": "0.2.17", + "version": "0.2.18", "description": "IPLD ETH Client", "main": "dist/index.js", "scripts": { @@ -20,7 +20,7 @@ "homepage": "https://github.com/cerc-io/watcher-ts#readme", "dependencies": { "@apollo/client": "^3.7.1", - "@cerc-io/cache": "^0.2.17", + "@cerc-io/cache": "^0.2.18", "cross-fetch": "^3.1.4", "debug": "^4.3.1", "ethers": "^5.4.4", diff --git a/packages/mobymask-watcher/package.json b/packages/mobymask-watcher/package.json index 9f800908..4d621e9f 100644 --- a/packages/mobymask-watcher/package.json +++ b/packages/mobymask-watcher/package.json @@ -1,6 +1,6 @@ { "name": "@cerc-io/mobymask-watcher", - "version": "0.2.17", + "version": "0.2.18", "description": "mobymask-watcher", "private": true, "main": "dist/index.js", @@ -37,10 +37,10 @@ "homepage": "https://github.com/cerc-io/watcher-ts#readme", "dependencies": { "@apollo/client": "^3.3.19", - "@cerc-io/cli": "^0.2.17", - "@cerc-io/ipld-eth-client": "^0.2.17", - "@cerc-io/solidity-mapper": "^0.2.17", - "@cerc-io/util": "^0.2.17", + "@cerc-io/cli": "^0.2.18", + "@cerc-io/ipld-eth-client": "^0.2.18", + "@cerc-io/solidity-mapper": "^0.2.18", + "@cerc-io/util": "^0.2.18", "@ethersproject/providers": "^5.4.4", "apollo-type-bigint": "^0.1.3", "debug": "^4.3.1", diff --git a/packages/solidity-mapper/package.json b/packages/solidity-mapper/package.json index 09a62cad..63fed68a 100644 --- a/packages/solidity-mapper/package.json +++ b/packages/solidity-mapper/package.json @@ -1,10 +1,10 @@ { "name": "@cerc-io/solidity-mapper", - "version": "0.2.17", + "version": "0.2.18", "main": "dist/index.js", "license": "AGPL-3.0", "devDependencies": { - "@cerc-io/ipld-eth-client": "^0.2.17", + "@cerc-io/ipld-eth-client": "^0.2.18", "@ethersproject/abi": "^5.3.0", "@nomiclabs/hardhat-ethers": "^2.0.2", "@nomiclabs/hardhat-waffle": "^2.0.1", diff --git a/packages/test/package.json b/packages/test/package.json index 8326efb1..a43576af 100644 --- a/packages/test/package.json +++ b/packages/test/package.json @@ -1,6 +1,6 @@ { "name": "@cerc-io/test", - "version": "0.2.17", + "version": "0.2.18", "main": "dist/index.js", "license": "AGPL-3.0", "private": true, diff --git a/packages/tracing-client/package.json b/packages/tracing-client/package.json index 843ec889..05815eb9 100644 --- a/packages/tracing-client/package.json +++ b/packages/tracing-client/package.json @@ -1,6 +1,6 @@ { "name": "@cerc-io/tracing-client", - "version": "0.2.17", + "version": "0.2.18", "description": "ETH VM tracing client", "private": true, "main": "dist/index.js", diff --git a/packages/util/package.json b/packages/util/package.json index 47e0f0b2..333e40aa 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -1,11 +1,11 @@ { "name": "@cerc-io/util", - "version": "0.2.17", + "version": "0.2.18", "main": "dist/index.js", "license": "AGPL-3.0", "dependencies": { "@apollo/utils.keyvaluecache": "^1.0.1", - "@cerc-io/solidity-mapper": "^0.2.17", + "@cerc-io/solidity-mapper": "^0.2.18", "@ethersproject/providers": "^5.4.4", "@graphql-tools/schema": "^9.0.10", "@graphql-tools/utils": "^9.1.1", @@ -37,8 +37,8 @@ "yargs": "^17.0.1" }, "devDependencies": { - "@cerc-io/cache": "^0.2.17", - "@cerc-io/ipld-eth-client": "^0.2.17", + "@cerc-io/cache": "^0.2.18", + "@cerc-io/ipld-eth-client": "^0.2.18", "@nomiclabs/hardhat-waffle": "^2.0.1", "@types/express": "^4.17.14", "@types/fs-extra": "^9.0.11", diff --git a/packages/util/src/common.ts b/packages/util/src/common.ts index f0ec8a7b..cf611a36 100644 --- a/packages/util/src/common.ts +++ b/packages/util/src/common.ts @@ -55,12 +55,11 @@ export const processBlockByNumber = async ( * @param blockAndEventsMap */ export const fetchBlocksAtHeight = async ( - job: any, + blockNumber: number, indexer: IndexerInterface, jobQueueConfig: JobQueueConfig, blockAndEventsMap: Map ): Promise[]> => { - const { blockNumber } = job.data; let blocks = []; // Check for blocks in cache if prefetchBlocksInMem flag set. diff --git a/packages/util/src/job-runner.ts b/packages/util/src/job-runner.ts index 6cd2c848..47f2a4f1 100644 --- a/packages/util/src/job-runner.ts +++ b/packages/util/src/job-runner.ts @@ -4,7 +4,7 @@ import assert from 'assert'; import debug from 'debug'; -import { In } from 'typeorm'; +import { DeepPartial, In } from 'typeorm'; import { JobQueueConfig } from './config'; import { @@ -19,7 +19,7 @@ import { QUEUE_HOOKS } from './constants'; import { JobQueue } from './job-queue'; -import { EventInterface, IndexerInterface } from './types'; +import { BlockProgressInterface, EventInterface, IndexerInterface } from './types'; import { wait } from './misc'; import { createPruningJob, @@ -79,14 +79,30 @@ export class JobRunner { switch (kind) { case JOB_KIND_INDEX: { - const blocksToBeIndexed = await fetchBlocksAtHeight( - job, - this._indexer, - this._jobQueueConfig, - this._blockAndEventsMap - ); - const indexBlockPromises = blocksToBeIndexed.map(blockToBeIndexed => this._indexBlock(job, blockToBeIndexed)); - await Promise.all(indexBlockPromises); + const { data: { cid, blockHash, blockNumber, parentHash, timestamp } } = job; + + // Check if blockHash present in job. + if (blockHash) { + // If blockHash is present it is a job for indexing missing parent block. + await this._indexBlock(job, { + blockTimestamp: timestamp, + cid, + blockHash, + blockNumber, + parentHash + }); + } else { + // If blockHash is not present, it is a job to index the next consecutive blockNumber. + const blocksToBeIndexed = await fetchBlocksAtHeight( + blockNumber, + this._indexer, + this._jobQueueConfig, + this._blockAndEventsMap + ); + const indexBlockPromises = blocksToBeIndexed.map(blockToBeIndexed => this._indexBlock(job, blockToBeIndexed)); + await Promise.all(indexBlockPromises); + } + break; } @@ -277,12 +293,15 @@ export class JobRunner { console.timeEnd('time:job-runner#_pruneChain'); } - async _indexBlock (job: any, blockToBeIndexed: any): Promise { + async _indexBlock (job: any, blockToBeIndexed: DeepPartial): Promise { const syncStatus = await this._indexer.getSyncStatus(); assert(syncStatus); const { data: { priority } } = job; const { cid, blockHash, blockNumber, parentHash, blockTimestamp } = blockToBeIndexed; + assert(blockNumber); + assert(blockHash); + assert(parentHash); const indexBlockStartTime = new Date(); @@ -350,7 +369,8 @@ export class JobRunner { const message = `Parent block number ${parentBlockNumber} hash ${parentHash} of block number ${blockNumber} hash ${blockHash} not fetched yet, aborting`; log(message); - throw new Error(message); + // Do not throw error and complete the job as block will be processed after parent block processing. + return; } if (!parentBlock.isComplete) { @@ -368,7 +388,8 @@ export class JobRunner { priority: newPriority }, { priority: newPriority }); - throw new Error(message); + // Do not throw error and complete the job as block will be processed after parent block processing. + return; } else { // Remove the unknown events of the parent block if it is marked complete. console.time('time:job-runner#_indexBlock-remove-unknown-events');