@subql/node-ethereum 0.4.1-storeCache-0.0.4 → 0.4.1-storeCache-0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/ethereum/api.ethereum.js +20 -16
- package/dist/ethereum/api.ethereum.js.map +1 -1
- package/dist/ethereum/ethers/json-rpc-batch-provider.js +7 -2
- package/dist/ethereum/ethers/json-rpc-batch-provider.js.map +1 -1
- package/dist/indexer/project.service.js +0 -3
- package/dist/indexer/project.service.js.map +1 -1
- package/dist/indexer/worker/worker.service.js +1 -1
- package/dist/indexer/worker/worker.service.js.map +1 -1
- package/dist/subcommands/reindex.module.js +2 -0
- package/dist/subcommands/reindex.module.js.map +1 -1
- package/dist/yargs.d.ts +6 -1
- package/dist/yargs.js +5 -0
- package/dist/yargs.js.map +1 -1
- package/package.json +3 -2
|
@@ -12,6 +12,7 @@ const https_1 = __importDefault(require("https"));
|
|
|
12
12
|
const abi_1 = require("@ethersproject/abi");
|
|
13
13
|
const providers_1 = require("@ethersproject/providers");
|
|
14
14
|
const node_core_1 = require("@subql/node-core");
|
|
15
|
+
const cacheable_lookup_1 = __importDefault(require("cacheable-lookup"));
|
|
15
16
|
const utils_1 = require("ethers/lib/utils");
|
|
16
17
|
const project_1 = require("../utils/project");
|
|
17
18
|
const block_ethereum_1 = require("./block.ethereum");
|
|
@@ -36,6 +37,23 @@ async function loadAssets(ds) {
|
|
|
36
37
|
}
|
|
37
38
|
return res;
|
|
38
39
|
}
|
|
40
|
+
function getHttpAgents() {
|
|
41
|
+
// By default Nodejs doesn't cache DNS lookups
|
|
42
|
+
// https://httptoolkit.com/blog/configuring-nodejs-dns/
|
|
43
|
+
const lookup = new cacheable_lookup_1.default();
|
|
44
|
+
const options = {
|
|
45
|
+
keepAlive: true,
|
|
46
|
+
/*, maxSockets: 100*/
|
|
47
|
+
};
|
|
48
|
+
const httpAgent = new http_1.default.Agent(options);
|
|
49
|
+
const httpsAgent = new https_1.default.Agent(options);
|
|
50
|
+
lookup.install(httpAgent);
|
|
51
|
+
lookup.install(httpsAgent);
|
|
52
|
+
return {
|
|
53
|
+
http: httpAgent,
|
|
54
|
+
https: httpsAgent,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
39
57
|
class EthereumApi {
|
|
40
58
|
constructor(endpoint, eventEmitter) {
|
|
41
59
|
this.endpoint = endpoint;
|
|
@@ -55,10 +73,7 @@ class EthereumApi {
|
|
|
55
73
|
allowGzip: true,
|
|
56
74
|
throttleLimit: 5,
|
|
57
75
|
throttleSlotInterval: 1,
|
|
58
|
-
agents:
|
|
59
|
-
http: new http_1.default.Agent({ keepAlive: true /*, maxSockets: 100*/ }),
|
|
60
|
-
https: new https_1.default.Agent({ keepAlive: true /*, maxSockets: 100*/ }),
|
|
61
|
-
},
|
|
76
|
+
agents: getHttpAgents(),
|
|
62
77
|
};
|
|
63
78
|
searchParams.forEach((value, name, searchParams) => {
|
|
64
79
|
connection.headers[name] = value;
|
|
@@ -153,18 +168,7 @@ class EthereumApi {
|
|
|
153
168
|
return ret;
|
|
154
169
|
}
|
|
155
170
|
async fetchBlocks(bufferBlocks) {
|
|
156
|
-
return Promise.all(bufferBlocks.map(async (num) =>
|
|
157
|
-
try {
|
|
158
|
-
// Fetch Block
|
|
159
|
-
return await this.fetchBlock(num, true);
|
|
160
|
-
}
|
|
161
|
-
catch (e) {
|
|
162
|
-
// Wrap error from an axios error to fix issue with error being undefined
|
|
163
|
-
const error = new Error(e.message);
|
|
164
|
-
logger.error(e, `Failed to fetch block at height ${num}`);
|
|
165
|
-
throw error;
|
|
166
|
-
}
|
|
167
|
-
}));
|
|
171
|
+
return Promise.all(bufferBlocks.map(async (num) => this.fetchBlock(num, true)));
|
|
168
172
|
}
|
|
169
173
|
freezeApi(processor, blockContent) {
|
|
170
174
|
processor.freeze(new safe_api_1.default(this.client, blockContent.blockHeight), 'api');
|
|
@@ -1 +1 @@
|
|
|
1
|
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OAAO,CAAC,EAAE;YACV,MAAM,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YAC9D,OAAO,WAAW,CAAC;SACpB;IACH,CAAC;CACF;AA1PD,kCA0PC","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport fs from 'fs';\nimport http from 'http';\nimport https from 'https';\nimport { Interface } from '@ethersproject/abi';\nimport { Block, TransactionReceipt } from '@ethersproject/abstract-provider';\nimport { WebSocketProvider } from '@ethersproject/providers';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { RuntimeDataSourceV0_2_0 } from '@subql/common-ethereum';\nimport { getLogger } from '@subql/node-core';\nimport {\n ApiWrapper,\n BlockWrapper,\n EthereumBlockWrapper,\n EthereumTransaction,\n EthereumResult,\n EthereumLog,\n} from '@subql/types-ethereum';\nimport { hexDataSlice, hexValue } from 'ethers/lib/utils';\nimport { retryOnFailEth } from '../utils/project';\nimport { EthereumBlockWrapped } from './block.ethereum';\nimport { JsonRpcBatchProvider } from './ethers/json-rpc-batch-provider';\nimport { JsonRpcProvider } from './ethers/json-rpc-provider';\nimport { ConnectionInfo } from './ethers/web';\nimport SafeEthProvider from './safe-api';\nimport {\n formatBlock,\n formatLog,\n formatReceipt,\n formatTransaction,\n} from './utils.ethereum';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst logger = getLogger('api.ethereum');\n\nasync function loadAssets(\n ds: RuntimeDataSourceV0_2_0,\n): Promise<Record<string, string>> {\n if (!ds.assets) {\n return {};\n }\n const res: Record<string, string> = {};\n\n for (const [name, { file }] of Object.entries(ds.assets)) {\n try {\n res[name] = await fs.promises.readFile(file, { encoding: 'utf8' });\n } catch (e) {\n throw new Error(`Failed to load datasource asset ${file}`);\n }\n }\n\n return res;\n}\n\nexport class EthereumApi implements ApiWrapper<EthereumBlockWrapper> {\n private client: JsonRpcProvider;\n private genesisBlock: Record<string, any>;\n private contractInterfaces: Record<string, Interface> = {};\n private chainId: number;\n\n // Ethereum POS\n private supportsFinalization = true;\n\n constructor(private endpoint: string, private eventEmitter: EventEmitter2) {\n const { hostname, pathname, port, protocol, searchParams } = new URL(\n endpoint,\n );\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(`Api host: ${hostname}, method: ${protocolStr}`);\n if (protocolStr === 'https' || protocolStr === 'http') {\n const connection: ConnectionInfo = {\n url: this.endpoint.split('?')[0],\n headers: {\n 'User-Agent': `Subquery-Node ${packageVersion}`,\n },\n allowGzip: true,\n throttleLimit: 5,\n throttleSlotInterval: 1,\n agents: {\n http: new http.Agent({ keepAlive: true /*, maxSockets: 100*/ }),\n https: new https.Agent({ keepAlive: true /*, maxSockets: 100*/ }),\n },\n };\n searchParams.forEach((value, name, searchParams) => {\n (connection.headers as any)[name] = value;\n });\n this.client = new JsonRpcBatchProvider(connection);\n } else if (protocolStr === 'ws' || protocolStr === 'wss') {\n this.client = new WebSocketProvider(this.endpoint);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n this.injectClient();\n this.genesisBlock = await this.client.getBlock(0);\n\n this.chainId = (await this.client.getNetwork()).chainId;\n }\n\n private injectClient(): void {\n const orig = this.client.send.bind(this.client);\n Object.defineProperty(this.client, 'send', {\n value: (...args) => {\n this.eventEmitter.emit('rpcCall');\n return orig(...args);\n },\n });\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n try {\n if (this.supportsFinalization) {\n return (await this.client.getBlock('finalised')).number;\n } else {\n // TODO make number of blocks finalised configurable\n return (await this.getBestBlockHeight()) - 15; // Consider 15 blocks finalized\n }\n } catch (e) {\n // TODO handle specific error for this\n this.supportsFinalization = false;\n return this.getFinalizedBlockHeight();\n }\n }\n\n async getBestBlockHeight(): Promise<number> {\n const tag = this.supportsFinalization ? 'safe' : 'latest';\n return (await this.client.getBlock(tag)).number;\n }\n\n getRuntimeChain(): string {\n return 'ethereum';\n }\n\n getChainId(): number {\n return this.chainId;\n }\n\n getGenesisHash(): string {\n return this.genesisBlock.hash;\n }\n\n getSpecName(): string {\n return 'ethereum';\n }\n\n async getBlockByHeightOrHash(heightOrHash: number | string): Promise<Block> {\n if (typeof heightOrHash === 'number') {\n heightOrHash = hexValue(heightOrHash);\n }\n return this.client.getBlock(heightOrHash);\n }\n\n private async getBlockPromise(num: number, includeTx = true): Promise<any> {\n const rawBlock = await this.client.send('eth_getBlockByNumber', [\n hexValue(num),\n includeTx,\n ]);\n\n const block = formatBlock(rawBlock);\n\n block.stateRoot = this.client.formatter.hash(block.stateRoot);\n\n return block;\n }\n\n async getTransactionReceipt(\n transactionHash: string | Promise<string>,\n ): Promise<TransactionReceipt> {\n return retryOnFailEth<TransactionReceipt>(\n this.client.getTransactionReceipt.bind(this.client, transactionHash),\n );\n }\n\n async fetchBlock(\n blockNumber: number,\n includeTx?: boolean,\n ): Promise<EthereumBlockWrapped> {\n const [block, logs] = await Promise.all([\n this.getBlockPromise(blockNumber, includeTx),\n this.client.getLogs({\n fromBlock: hexValue(blockNumber),\n toBlock: hexValue(blockNumber),\n }),\n ]);\n\n const ret = new EthereumBlockWrapped(\n block,\n includeTx\n ? block.transactions.map((tx) => ({\n ...formatTransaction(tx),\n // TODO memoise\n receipt: () =>\n this.getTransactionReceipt(tx).then((r) =>\n formatReceipt(r, block),\n ),\n }))\n : [],\n logs.map((l) => formatLog(l, block)),\n );\n this.eventEmitter.emit('fetchBlock');\n return ret;\n }\n\n async fetchBlocks(bufferBlocks: number[]): Promise<EthereumBlockWrapper[]> {\n return Promise.all(\n bufferBlocks.map(async (num) => {\n try {\n // Fetch Block\n return await this.fetchBlock(num, true);\n } catch (e) {\n // Wrap error from an axios error to fix issue with error being undefined\n const error = new Error(e.message);\n logger.error(e, `Failed to fetch block at height ${num}`);\n throw error;\n }\n }),\n );\n }\n\n freezeApi(processor: any, blockContent: BlockWrapper): void {\n processor.freeze(\n new SafeEthProvider(this.client, blockContent.blockHeight),\n 'api',\n );\n }\n\n private buildInterface(\n abiName: string,\n assets: Record<string, string>,\n ): Interface | undefined {\n if (!assets[abiName]) {\n throw new Error(`ABI named \"${abiName}\" not referenced in assets`);\n }\n\n // This assumes that all datasources have a different abi name or they are the same abi\n if (!this.contractInterfaces[abiName]) {\n // Constructing the interface validates the ABI\n try {\n let abiObj = JSON.parse(assets[abiName]);\n\n /*\n * Allows parsing JSON artifacts as well as ABIs\n * https://trufflesuite.github.io/artifact-updates/background.html#what-are-artifacts\n */\n if (!Array.isArray(abiObj) && abiObj.abi) {\n abiObj = abiObj.abi;\n }\n\n this.contractInterfaces[abiName] = new Interface(abiObj);\n } catch (e) {\n logger.error(`Unable to parse ABI: ${e.message}`);\n throw new Error('ABI is invalid');\n }\n }\n\n return this.contractInterfaces[abiName];\n }\n\n async parseLog<T extends EthereumResult = EthereumResult>(\n log: EthereumLog,\n ds: RuntimeDataSourceV0_2_0,\n ): Promise<EthereumLog<T> | EthereumLog> {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return log;\n }\n const iface = this.buildInterface(ds.options.abi, await loadAssets(ds));\n return {\n ...log,\n args: iface?.parseLog(log).args as T,\n };\n } catch (e) {\n logger.warn(`Failed to parse log data: ${e.message}`);\n return log;\n }\n }\n\n async parseTransaction<T extends EthereumResult = EthereumResult>(\n transaction: EthereumTransaction,\n ds: RuntimeDataSourceV0_2_0,\n ): Promise<EthereumTransaction<T> | EthereumTransaction> {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return transaction;\n }\n const assets = await loadAssets(ds);\n const iface = this.buildInterface(ds.options.abi, assets);\n const func = iface.getFunction(hexDataSlice(transaction.input, 0, 4));\n const args = iface.decodeFunctionData(func, transaction.input) as T;\n return {\n ...transaction,\n args,\n };\n } catch (e) {\n logger.warn(`Failed to parse transaction data: ${e.message}`);\n return transaction;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"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AAW,KACd,IAAI,IACJ;SACH;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YAC9D,OAAO,WAAW,CAAC;SACpB;IACH,CAAC;CACF;AA7OD,kCA6OC","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport fs from 'fs';\nimport http from 'http';\nimport https from 'https';\nimport { Interface } from '@ethersproject/abi';\nimport { Block, TransactionReceipt } from '@ethersproject/abstract-provider';\nimport { WebSocketProvider } from '@ethersproject/providers';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { RuntimeDataSourceV0_2_0 } from '@subql/common-ethereum';\nimport { getLogger } from '@subql/node-core';\nimport {\n ApiWrapper,\n BlockWrapper,\n EthereumBlockWrapper,\n EthereumTransaction,\n EthereumResult,\n EthereumLog,\n} from '@subql/types-ethereum';\nimport CacheableLookup from 'cacheable-lookup';\nimport { hexDataSlice, hexValue } from 'ethers/lib/utils';\nimport { retryOnFailEth } from '../utils/project';\nimport { EthereumBlockWrapped } from './block.ethereum';\nimport { JsonRpcBatchProvider } from './ethers/json-rpc-batch-provider';\nimport { JsonRpcProvider } from './ethers/json-rpc-provider';\nimport { ConnectionInfo } from './ethers/web';\nimport SafeEthProvider from './safe-api';\nimport {\n formatBlock,\n formatLog,\n formatReceipt,\n formatTransaction,\n} from './utils.ethereum';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst logger = getLogger('api.ethereum');\n\nasync function loadAssets(\n ds: RuntimeDataSourceV0_2_0,\n): Promise<Record<string, string>> {\n if (!ds.assets) {\n return {};\n }\n const res: Record<string, string> = {};\n\n for (const [name, { file }] of Object.entries(ds.assets)) {\n try {\n res[name] = await fs.promises.readFile(file, { encoding: 'utf8' });\n } catch (e) {\n throw new Error(`Failed to load datasource asset ${file}`);\n }\n }\n\n return res;\n}\n\nfunction getHttpAgents() {\n // By default Nodejs doesn't cache DNS lookups\n // https://httptoolkit.com/blog/configuring-nodejs-dns/\n const lookup = new CacheableLookup();\n\n const options: http.AgentOptions = {\n keepAlive: true,\n /*, maxSockets: 100*/\n };\n\n const httpAgent = new http.Agent(options);\n const httpsAgent = new https.Agent(options);\n\n lookup.install(httpAgent);\n lookup.install(httpsAgent);\n\n return {\n http: httpAgent,\n https: httpsAgent,\n };\n}\n\nexport class EthereumApi implements ApiWrapper<EthereumBlockWrapper> {\n private client: JsonRpcProvider;\n private genesisBlock: Record<string, any>;\n private contractInterfaces: Record<string, Interface> = {};\n private chainId: number;\n\n // Ethereum POS\n private supportsFinalization = true;\n\n constructor(private endpoint: string, private eventEmitter: EventEmitter2) {\n const { hostname, pathname, port, protocol, searchParams } = new URL(\n endpoint,\n );\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(`Api host: ${hostname}, method: ${protocolStr}`);\n if (protocolStr === 'https' || protocolStr === 'http') {\n const connection: ConnectionInfo = {\n url: this.endpoint.split('?')[0],\n headers: {\n 'User-Agent': `Subquery-Node ${packageVersion}`,\n },\n allowGzip: true,\n throttleLimit: 5,\n throttleSlotInterval: 1,\n agents: getHttpAgents(),\n };\n searchParams.forEach((value, name, searchParams) => {\n (connection.headers as any)[name] = value;\n });\n this.client = new JsonRpcBatchProvider(connection);\n } else if (protocolStr === 'ws' || protocolStr === 'wss') {\n this.client = new WebSocketProvider(this.endpoint);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n this.injectClient();\n this.genesisBlock = await this.client.getBlock(0);\n\n this.chainId = (await this.client.getNetwork()).chainId;\n }\n\n private injectClient(): void {\n const orig = this.client.send.bind(this.client);\n Object.defineProperty(this.client, 'send', {\n value: (...args) => {\n this.eventEmitter.emit('rpcCall');\n return orig(...args);\n },\n });\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n try {\n if (this.supportsFinalization) {\n return (await this.client.getBlock('finalised')).number;\n } else {\n // TODO make number of blocks finalised configurable\n return (await this.getBestBlockHeight()) - 15; // Consider 15 blocks finalized\n }\n } catch (e) {\n // TODO handle specific error for this\n this.supportsFinalization = false;\n return this.getFinalizedBlockHeight();\n }\n }\n\n async getBestBlockHeight(): Promise<number> {\n const tag = this.supportsFinalization ? 'safe' : 'latest';\n return (await this.client.getBlock(tag)).number;\n }\n\n getRuntimeChain(): string {\n return 'ethereum';\n }\n\n getChainId(): number {\n return this.chainId;\n }\n\n getGenesisHash(): string {\n return this.genesisBlock.hash;\n }\n\n getSpecName(): string {\n return 'ethereum';\n }\n\n async getBlockByHeightOrHash(heightOrHash: number | string): Promise<Block> {\n if (typeof heightOrHash === 'number') {\n heightOrHash = hexValue(heightOrHash);\n }\n return this.client.getBlock(heightOrHash);\n }\n\n private async getBlockPromise(num: number, includeTx = true): Promise<any> {\n const rawBlock = await this.client.send('eth_getBlockByNumber', [\n hexValue(num),\n includeTx,\n ]);\n\n const block = formatBlock(rawBlock);\n\n block.stateRoot = this.client.formatter.hash(block.stateRoot);\n\n return block;\n }\n\n async getTransactionReceipt(\n transactionHash: string | Promise<string>,\n ): Promise<TransactionReceipt> {\n return retryOnFailEth<TransactionReceipt>(\n this.client.getTransactionReceipt.bind(this.client, transactionHash),\n );\n }\n\n async fetchBlock(\n blockNumber: number,\n includeTx?: boolean,\n ): Promise<EthereumBlockWrapped> {\n const [block, logs] = await Promise.all([\n this.getBlockPromise(blockNumber, includeTx),\n this.client.getLogs({\n fromBlock: hexValue(blockNumber),\n toBlock: hexValue(blockNumber),\n }),\n ]);\n\n const ret = new EthereumBlockWrapped(\n block,\n includeTx\n ? block.transactions.map((tx) => ({\n ...formatTransaction(tx),\n // TODO memoise\n receipt: () =>\n this.getTransactionReceipt(tx).then((r) =>\n formatReceipt(r, block),\n ),\n }))\n : [],\n logs.map((l) => formatLog(l, block)),\n );\n this.eventEmitter.emit('fetchBlock');\n return ret;\n }\n\n async fetchBlocks(bufferBlocks: number[]): Promise<EthereumBlockWrapper[]> {\n return Promise.all(\n bufferBlocks.map(async (num) => this.fetchBlock(num, true)),\n );\n }\n\n freezeApi(processor: any, blockContent: BlockWrapper): void {\n processor.freeze(\n new SafeEthProvider(this.client, blockContent.blockHeight),\n 'api',\n );\n }\n\n private buildInterface(\n abiName: string,\n assets: Record<string, string>,\n ): Interface | undefined {\n if (!assets[abiName]) {\n throw new Error(`ABI named \"${abiName}\" not referenced in assets`);\n }\n\n // This assumes that all datasources have a different abi name or they are the same abi\n if (!this.contractInterfaces[abiName]) {\n // Constructing the interface validates the ABI\n try {\n let abiObj = JSON.parse(assets[abiName]);\n\n /*\n * Allows parsing JSON artifacts as well as ABIs\n * https://trufflesuite.github.io/artifact-updates/background.html#what-are-artifacts\n */\n if (!Array.isArray(abiObj) && abiObj.abi) {\n abiObj = abiObj.abi;\n }\n\n this.contractInterfaces[abiName] = new Interface(abiObj);\n } catch (e) {\n logger.error(`Unable to parse ABI: ${e.message}`);\n throw new Error('ABI is invalid');\n }\n }\n\n return this.contractInterfaces[abiName];\n }\n\n async parseLog<T extends EthereumResult = EthereumResult>(\n log: EthereumLog,\n ds: RuntimeDataSourceV0_2_0,\n ): Promise<EthereumLog<T> | EthereumLog> {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return log;\n }\n const iface = this.buildInterface(ds.options.abi, await loadAssets(ds));\n return {\n ...log,\n args: iface?.parseLog(log).args as T,\n };\n } catch (e) {\n logger.warn(`Failed to parse log data: ${e.message}`);\n return log;\n }\n }\n\n async parseTransaction<T extends EthereumResult = EthereumResult>(\n transaction: EthereumTransaction,\n ds: RuntimeDataSourceV0_2_0,\n ): Promise<EthereumTransaction<T> | EthereumTransaction> {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return transaction;\n }\n const assets = await loadAssets(ds);\n const iface = this.buildInterface(ds.options.abi, assets);\n const func = iface.getFunction(hexDataSlice(transaction.input, 0, 4));\n const args = iface.decodeFunctionData(func, transaction.input) as T;\n return {\n ...transaction,\n args,\n };\n } catch (e) {\n logger.warn(`Failed to parse transaction data: ${e.message}`);\n return transaction;\n }\n }\n}\n"]}
|
|
@@ -5,6 +5,8 @@ exports.JsonRpcBatchProvider = void 0;
|
|
|
5
5
|
const properties_1 = require("@ethersproject/properties");
|
|
6
6
|
const web_1 = require("@ethersproject/web");
|
|
7
7
|
const providers_1 = require("@ethersproject/providers");
|
|
8
|
+
const node_core_1 = require("@subql/node-core");
|
|
9
|
+
const logger = (0, node_core_1.getLogger)('JsonRpcBatchProvider');
|
|
8
10
|
// Experimental
|
|
9
11
|
class JsonRpcBatchProvider extends providers_1.JsonRpcProvider {
|
|
10
12
|
constructor(url, network) {
|
|
@@ -56,7 +58,8 @@ class JsonRpcBatchProvider extends providers_1.JsonRpcProvider {
|
|
|
56
58
|
request: (0, properties_1.deepCopy)(request),
|
|
57
59
|
provider: this,
|
|
58
60
|
});
|
|
59
|
-
return (0, web_1.fetchJson)(this.connection, JSON.stringify(request))
|
|
61
|
+
return (0, web_1.fetchJson)(this.connection, JSON.stringify(request))
|
|
62
|
+
.then((result) => {
|
|
60
63
|
this.emit('debug', {
|
|
61
64
|
action: 'response',
|
|
62
65
|
request: request,
|
|
@@ -85,13 +88,15 @@ class JsonRpcBatchProvider extends providers_1.JsonRpcProvider {
|
|
|
85
88
|
inflightRequest.resolve(payload.result);
|
|
86
89
|
}
|
|
87
90
|
});
|
|
88
|
-
}
|
|
91
|
+
})
|
|
92
|
+
.catch((error) => {
|
|
89
93
|
this.emit('debug', {
|
|
90
94
|
action: 'response',
|
|
91
95
|
error: error,
|
|
92
96
|
request: request,
|
|
93
97
|
provider: this,
|
|
94
98
|
});
|
|
99
|
+
logger.error(error);
|
|
95
100
|
batch.forEach((inflightRequest) => {
|
|
96
101
|
inflightRequest.reject(error);
|
|
97
102
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc-batch-provider.js","sourceRoot":"","sources":["../../../src/ethereum/ethers/json-rpc-batch-provider.ts"],"names":[],"mappings":";;;AAAA,oBAAoB;AACpB,0DAAqD;AACrD,4CAA+C;AAE/C,wDAA2D;
|
|
1
|
+
{"version":3,"file":"json-rpc-batch-provider.js","sourceRoot":"","sources":["../../../src/ethereum/ethers/json-rpc-batch-provider.ts"],"names":[],"mappings":";;;AAAA,oBAAoB;AACpB,0DAAqD;AACrD,4CAA+C;AAE/C,wDAA2D;AAG3D,gDAA6C;AAE7C,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,sBAAsB,CAAC,CAAC;AAajD,eAAe;AAEf,MAAa,oBAAqB,SAAQ,2BAAe;IAQvD,YAAY,GAA4B,EAAE,OAAoB;QAC5D,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACtB,CAAC;IAED,IAAI,CAAC,MAAc,EAAE,MAAkB;QACrC,MAAM,OAAO,GAAG;YACd,MAAM,EAAE,MAAM;YACd,MAAM,EAAE,MAAM;YACd,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE;YAClB,OAAO,EAAE,KAAK;SACf,CAAC;QAEF,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,EAAE;YAC9B,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;SACzB;QAED,MAAM,eAAe,GAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QAEtE,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC9C,eAAe,CAAC,OAAO,GAAG,OAAO,CAAC;YAClC,eAAe,CAAC,MAAM,GAAG,MAAM,CAAC;QAClC,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAEzC,IAAI,CAAC,IAAI,CAAC,uBAAuB,EAAE;YACjC,sDAAsD;YACtD,IAAI,CAAC,uBAAuB,GAAG,UAAU,CAA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import { deepCopy } from '@ethersproject/properties';\nimport { fetchJson } from '@ethersproject/web';\n\nimport { JsonRpcProvider } from '@ethersproject/providers';\nimport { Networkish } from '@ethersproject/networks';\nimport { ConnectionInfo } from './web';\nimport { getLogger } from '@subql/node-core';\n\nconst logger = getLogger('JsonRpcBatchProvider');\n\ninterface RpcResult {\n jsonrpc: '2.0';\n id: number;\n result?: string;\n error?: {\n code: number;\n message: string;\n data?: any;\n };\n}\n\n// Experimental\n\nexport class JsonRpcBatchProvider extends JsonRpcProvider {\n _pendingBatchAggregator: NodeJS.Timer;\n _pendingBatch: Array<{\n request: { method: string; params: Array<any>; id: number; jsonrpc: '2.0' };\n resolve: (result: any) => void;\n reject: (error: Error) => void;\n }>;\n\n constructor(url: string | ConnectionInfo, network?: Networkish) {\n super(url, network);\n }\n\n send(method: string, params: Array<any>): Promise<any> {\n const request = {\n method: method,\n params: params,\n id: this._nextId++,\n jsonrpc: '2.0',\n };\n\n if (this._pendingBatch == null) {\n this._pendingBatch = [];\n }\n\n const inflightRequest: any = { request, resolve: null, reject: null };\n\n const promise = new Promise((resolve, reject) => {\n inflightRequest.resolve = resolve;\n inflightRequest.reject = reject;\n });\n\n this._pendingBatch.push(inflightRequest);\n\n if (!this._pendingBatchAggregator) {\n // Schedule batch for next event loop + short duration\n this._pendingBatchAggregator = setTimeout(() => {\n this.runRequests();\n }, 1);\n }\n\n if (this._pendingBatch.length > 10) {\n this.flush();\n }\n\n return promise;\n }\n\n flush(): void {\n if (this._pendingBatchAggregator) {\n clearTimeout(this._pendingBatchAggregator);\n this.runRequests();\n }\n }\n\n private runRequests() {\n // Get teh current batch and clear it, so new requests\n // go into the next batch\n const batch = this._pendingBatch;\n this._pendingBatch = null;\n this._pendingBatchAggregator = null;\n\n // Get the request as an array of requests\n const request = batch.map((inflight) => inflight.request);\n\n this.emit('debug', {\n action: 'requestBatch',\n request: deepCopy(request),\n provider: this,\n });\n\n return fetchJson(this.connection, JSON.stringify(request))\n .then((result: RpcResult[]) => {\n this.emit('debug', {\n action: 'response',\n request: request,\n response: result,\n provider: this,\n });\n\n // if (!Array.isArray(result)) {\n // result = [result];\n // }\n\n // https://github.com/ethers-io/ethers.js/pull/2657\n const resultMap = result.reduce((resultMap, payload) => {\n resultMap[payload.id] = payload;\n return resultMap;\n }, {} as Record<number, RpcResult>);\n\n // For each result, feed it to the correct Promise, depending\n // on whether it was a success or error\n batch.forEach((inflightRequest) => {\n const payload = resultMap[inflightRequest.request.id];\n if (payload.error) {\n const error = new Error(payload.error.message);\n (<any>error).code = payload.error.code;\n (<any>error).data = payload.error.data;\n inflightRequest.reject(error);\n } else {\n inflightRequest.resolve(payload.result);\n }\n });\n })\n .catch((error) => {\n this.emit('debug', {\n action: 'response',\n error: error,\n request: request,\n provider: this,\n });\n\n logger.error(error);\n\n batch.forEach((inflightRequest) => {\n inflightRequest.reject(error);\n });\n });\n }\n}\n"]}
|
|
@@ -190,9 +190,6 @@ let ProjectService = class ProjectService {
|
|
|
190
190
|
if (!existing.schemaMigrationCount) {
|
|
191
191
|
metadata.set('schemaMigrationCount', 0);
|
|
192
192
|
}
|
|
193
|
-
if (!existing.unfinalizedBlocks) {
|
|
194
|
-
metadata.set('unfinalizedBlocks', '{}');
|
|
195
|
-
}
|
|
196
193
|
if (!existing.startHeight) {
|
|
197
194
|
metadata.set('startHeight', this.getStartBlockFromDataSources());
|
|
198
195
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.service.js","sourceRoot":"","sources":["../../src/indexer/project.service.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;;;;;;;;;;AAEtC,oDAA4B;AAC5B,mDAA8C;AAC9C,2CAAoD;AACpD,yDAAsD;AACtD,gDAU0B;AAC1B,yCAAsC;AACtC,kEAIsC;AACtC,8CAAqE;AACrE,8CAA2C;AAC3C,iEAA4D;AAC5D,6DAAwD;AACxD,2EAAuE;AAEvE,8DAA8D;AAC9D,MAAM,EAAE,OAAO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IAYR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;qCALU,yCAAkB;QAC1B,sBAAU;QACV,sBAAU;QACR,sBAAU;QACb,qBAAS;QACiB,iCAAe;QACtC,wBAAY;QACd,sBAAU;QACJ,qCAAgB;QAC7B,6BAAa;QACF,oDAAwB;GAhBhD,cAAc,CA6R1B;AA7RY,wCAAc","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport assert from 'assert';\nimport { isMainThread } from 'worker_threads';\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ApiService,\n IProjectService,\n NodeConfig,\n IndexerEvent,\n StoreService,\n PoiService,\n MmrService,\n getLogger,\n getExistingProjectSchema,\n} from '@subql/node-core';\nimport { Sequelize } from 'sequelize';\nimport {\n generateTimestampReferenceForBlockFilters,\n SubqlProjectDs,\n SubqueryProject,\n} from '../configure/SubqueryProject';\nimport { initDbSchema, initHotSchemaReload } from '../utils/project';\nimport { reindex } from '../utils/reindex';\nimport { DsProcessorService } from './ds-processor.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { UnfinalizedBlocksService } from './unfinalizedBlocks.service';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst DEFAULT_DB_SCHEMA = 'public';\n\nconst logger = getLogger('Project');\n\n@Injectable()\nexport class ProjectService implements IProjectService {\n private _schema: string;\n private _startHeight: number;\n private _blockOffset: number;\n\n constructor(\n private readonly dsProcessorService: DsProcessorService,\n private readonly apiService: ApiService,\n private readonly poiService: PoiService,\n protected readonly mmrService: MmrService,\n private readonly sequelize: Sequelize,\n @Inject('ISubqueryProject') private readonly project: SubqueryProject,\n private readonly storeService: StoreService,\n private readonly nodeConfig: NodeConfig,\n private readonly dynamicDsService: DynamicDsService,\n private eventEmitter: EventEmitter2,\n private unfinalizedBlockService: UnfinalizedBlocksService,\n ) {}\n\n get schema(): string {\n return this._schema;\n }\n\n get dataSources(): SubqlProjectDs[] {\n return this.project.dataSources;\n }\n\n get blockOffset(): number {\n return this._blockOffset;\n }\n\n get startHeight(): number {\n return this._startHeight;\n }\n\n get isHistorical(): boolean {\n return this.storeService.historical;\n }\n\n private async getExistingProjectSchema(): Promise<string> {\n return getExistingProjectSchema(this.nodeConfig, this.sequelize);\n }\n\n async init(): Promise<void> {\n // Used to load assets into DS-processor, has to be done in any thread\n await this.dsProcessorService.validateProjectCustomDatasources();\n // Do extra work on main thread to setup stuff\n this.project.dataSources = await generateTimestampReferenceForBlockFilters(\n this.project.dataSources,\n this.apiService.api,\n );\n if (isMainThread) {\n this._schema = await this.ensureProject();\n await this.initDbSchema();\n await this.ensureMetadata();\n this.dynamicDsService.init(this.storeService.storeCache.metadata);\n\n await this.initHotSchemaReload();\n\n await this.initHotSchemaReload();\n\n if (this.nodeConfig.proofOfIndex) {\n const blockOffset = await this.getMetadataBlockOffset();\n void this.setBlockOffset(Number(blockOffset));\n await this.poiService.init();\n }\n\n this._startHeight = await this.getStartHeight();\n\n if (this.nodeConfig.unfinalizedBlocks && !this.isHistorical) {\n logger.error(\n 'Unfinalized blocks cannot be enabled without historical. You will need to reindex your project to enable historical',\n );\n process.exit(1);\n }\n\n const reindexedTo = await this.unfinalizedBlockService.init(\n this.reindex.bind(this),\n );\n\n if (reindexedTo !== undefined) {\n this._startHeight = reindexedTo;\n }\n\n // Flush any pending operations to setup DB\n await this.storeService.storeCache.flushCache();\n } else {\n this._schema = await this.getExistingProjectSchema();\n\n await this.sequelize.sync();\n\n assert(this._schema, 'Schema should be created in main thread');\n await this.initDbSchema();\n\n if (this.nodeConfig.proofOfIndex) {\n await this.poiService.init();\n }\n }\n }\n\n private async ensureProject(): Promise<string> {\n let schema = await this.getExistingProjectSchema();\n if (!schema) {\n schema = await this.createProjectSchema();\n }\n this.eventEmitter.emit(IndexerEvent.Ready, {\n value: true,\n });\n\n return schema;\n }\n\n private async createProjectSchema(): Promise<string> {\n let schema: string;\n if (this.nodeConfig.localMode) {\n // create tables in default schema if local mode is enabled\n schema = DEFAULT_DB_SCHEMA;\n } else {\n schema = this.nodeConfig.dbSchema;\n const schemas = await this.sequelize.showAllSchemas(undefined);\n if (!(schemas as unknown as string[]).includes(schema)) {\n await this.sequelize.createSchema(`\"${schema}\"`, undefined);\n }\n }\n\n return schema;\n }\n\n private async initHotSchemaReload(): Promise<void> {\n await initHotSchemaReload(this.schema, this.storeService);\n }\n private async initDbSchema(): Promise<void> {\n await initDbSchema(this.project, this.schema, this.storeService);\n }\n\n private async ensureMetadata(): Promise<void> {\n const metadata = this.storeService.storeCache.metadata;\n\n this.eventEmitter.emit(\n IndexerEvent.NetworkMetadata,\n this.apiService.networkMeta,\n );\n\n const keys = [\n 'lastProcessedHeight',\n 'blockOffset',\n 'indexerNodeVersion',\n 'chain',\n 'specName',\n 'genesisHash',\n 'startHeight',\n 'processedBlockCount',\n 'lastFinalizedVerifiedHeight',\n 'schemaMigrationCount',\n 'unfinalizedBlocks',\n ] as const;\n\n const existing = await metadata.findMany(keys);\n\n const { chain, genesisHash, specName } = this.apiService.networkMeta;\n\n if (this.project.runner) {\n const { node, query } = this.project.runner;\n\n metadata.setBulk([\n { key: 'runnerNode', value: node.name },\n { key: 'runnerNodeVersion', value: node.version },\n { key: 'runnerQuery', value: query.name },\n { key: 'runnerQueryVersion', value: query.version },\n ]);\n }\n if (!existing.genesisHash) {\n metadata.set('genesisHash', genesisHash);\n } else {\n // Check if the configured genesisHash matches the currently stored genesisHash\n assert(\n // Configured project yaml genesisHash only exists in specVersion v0.2.0, fallback to api fetched genesisHash on v0.0.1\n (this.project.network.genesisHash ?? genesisHash) ===\n existing.genesisHash,\n 'Specified project manifest chain id / genesis hash does not match database stored genesis hash, consider cleaning project schema using --force-clean',\n );\n }\n if (existing.chain !== chain) {\n metadata.set('chain', chain);\n }\n\n if (existing.specName !== specName) {\n metadata.set('specName', specName);\n }\n\n // If project was created before this feature, don't add the key. If it is project created after, add this key.\n if (!existing.processedBlockCount && !existing.lastProcessedHeight) {\n metadata.set('processedBlockCount', 0);\n }\n\n if (existing.indexerNodeVersion !== packageVersion) {\n metadata.set('indexerNodeVersion', packageVersion);\n }\n if (!existing.schemaMigrationCount) {\n metadata.set('schemaMigrationCount', 0);\n }\n\n if (!existing.unfinalizedBlocks) {\n metadata.set('unfinalizedBlocks', '{}');\n }\n\n if (!existing.startHeight) {\n metadata.set('startHeight', this.getStartBlockFromDataSources());\n }\n }\n\n private async getMetadataBlockOffset(): Promise<number | undefined> {\n return this.storeService.storeCache.metadata.find('blockOffset');\n }\n\n private async getLastProcessedHeight(): Promise<number | undefined> {\n return this.storeService.storeCache.metadata.find('lastProcessedHeight');\n }\n\n private async getStartHeight(): Promise<number> {\n let startHeight: number;\n const lastProcessedHeight = await this.getLastProcessedHeight();\n if (lastProcessedHeight !== null && lastProcessedHeight !== undefined) {\n startHeight = Number(lastProcessedHeight) + 1;\n } else {\n startHeight = this.getStartBlockFromDataSources();\n }\n return startHeight;\n }\n\n async setBlockOffset(offset: number): Promise<void> {\n if (\n this._blockOffset !== undefined ||\n offset === null ||\n offset === undefined ||\n isNaN(offset)\n ) {\n return;\n }\n logger.info(`set blockOffset to ${offset}`);\n this._blockOffset = offset;\n return this.mmrService.syncFileBaseFromPoi(offset).catch((err) => {\n logger.error(err, 'failed to sync poi to mmr');\n process.exit(1);\n });\n }\n\n private getStartBlockFromDataSources() {\n const startBlocksList = this.project.dataSources.map(\n (item) => item.startBlock ?? 1,\n );\n if (startBlocksList.length === 0) {\n logger.error(\n `Failed to find a valid datasource, Please check your endpoint if specName filter is used.`,\n );\n process.exit(1);\n } else {\n return Math.min(...startBlocksList);\n }\n }\n\n async reindex(targetBlockHeight: number): Promise<void> {\n const lastProcessedHeight = await this.getLastProcessedHeight();\n\n return reindex(\n this.getStartBlockFromDataSources(),\n await this.getMetadataBlockOffset(),\n targetBlockHeight,\n lastProcessedHeight,\n this.storeService,\n this.unfinalizedBlockService,\n this.dynamicDsService,\n this.mmrService,\n this.sequelize,\n /* Not providing force clean service, it should never be needed */\n );\n }\n\n async getAllDataSources(blockHeight: number): Promise<SubqlProjectDs[]> {\n const dynamicDs = await this.dynamicDsService.getDynamicDatasources();\n\n return [...this.dataSources, ...dynamicDs].filter(\n (ds) => ds.startBlock <= blockHeight,\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"project.service.js","sourceRoot":"","sources":["../../src/indexer/project.service.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;;;;;;;;;;AAEtC,oDAA4B;AAC5B,mDAA8C;AAC9C,2CAAoD;AACpD,yDAAsD;AACtD,gDAU0B;AAC1B,yCAAsC;AACtC,kEAIsC;AACtC,8CAAqE;AACrE,8CAA2C;AAC3C,iEAA4D;AAC5D,6DAAwD;AACxD,2EAAuE;AAEvE,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAM,iBAAiB,GAAG,QAAQ,CAAC;AAEnC,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,SAAS,CAAC,CAAC;AAG7B,IAAM,cAAc,GAApB,MAAM,cAAc;IAKzB,YACmB,kBAAsC,EACtC,UAAsB,EACtB,UAAsB,EACpB,UAAsB,EACxB,SAAoB,EACQ,OAAwB,EACpD,YAA0B,EAC1B,UAAsB,EACtB,gBAAkC,EAC3C,YAA2B,EAC3B,uBAAiD;QAVxC,uBAAkB,GAAlB,kBAAkB,CAAoB;QACtC,eAAU,GAAV,UAAU,CAAY;QACtB,eAAU,GAAV,UAAU,CAAY;QACpB,eAAU,GAAV,UAAU,CAAY;QACxB,cAAS,GAAT,SAAS,CAAW;QACQ,YAAO,GAAP,OAAO,CAAiB;QACpD,iBAAY,GAAZ,YAAY,CAAc;QAC1B,eAAU,GAAV,UAAU,CAAY;QACtB,qBAAgB,GAAhB,gBAAg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AI,CAAC,YAAY,EACjB,IAAI,CAAC,uBAAuB,EAC5B,IAAI,CAAC,gBAAgB,EACrB,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,SAAS,CAEf,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,WAAmB;QACzC,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,qBAAqB,EAAE,CAAC;QAEtE,OAAO,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,CAAC,MAAM,CAC/C,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,IAAI,WAAW,CACrC,CAAC;IACJ,CAAC;CACF,CAAA;AAxRY,cAAc;IAD1B,IAAA,mBAAU,GAAE;IAYR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;qCALU,yCAAkB;QAC1B,sBAAU;QACV,sBAAU;QACR,sBAAU;QACb,qBAAS;QACiB,iCAAe;QACtC,wBAAY;QACd,sBAAU;QACJ,qCAAgB;QAC7B,6BAAa;QACF,oDAAwB;GAhBhD,cAAc,CAwR1B;AAxRY,wCAAc","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport assert from 'assert';\nimport { isMainThread } from 'worker_threads';\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ApiService,\n IProjectService,\n NodeConfig,\n IndexerEvent,\n StoreService,\n PoiService,\n MmrService,\n getLogger,\n getExistingProjectSchema,\n} from '@subql/node-core';\nimport { Sequelize } from 'sequelize';\nimport {\n generateTimestampReferenceForBlockFilters,\n SubqlProjectDs,\n SubqueryProject,\n} from '../configure/SubqueryProject';\nimport { initDbSchema, initHotSchemaReload } from '../utils/project';\nimport { reindex } from '../utils/reindex';\nimport { DsProcessorService } from './ds-processor.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { UnfinalizedBlocksService } from './unfinalizedBlocks.service';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst DEFAULT_DB_SCHEMA = 'public';\n\nconst logger = getLogger('Project');\n\n@Injectable()\nexport class ProjectService implements IProjectService {\n private _schema: string;\n private _startHeight: number;\n private _blockOffset: number;\n\n constructor(\n private readonly dsProcessorService: DsProcessorService,\n private readonly apiService: ApiService,\n private readonly poiService: PoiService,\n protected readonly mmrService: MmrService,\n private readonly sequelize: Sequelize,\n @Inject('ISubqueryProject') private readonly project: SubqueryProject,\n private readonly storeService: StoreService,\n private readonly nodeConfig: NodeConfig,\n private readonly dynamicDsService: DynamicDsService,\n private eventEmitter: EventEmitter2,\n private unfinalizedBlockService: UnfinalizedBlocksService,\n ) {}\n\n get schema(): string {\n return this._schema;\n }\n\n get dataSources(): SubqlProjectDs[] {\n return this.project.dataSources;\n }\n\n get blockOffset(): number {\n return this._blockOffset;\n }\n\n get startHeight(): number {\n return this._startHeight;\n }\n\n get isHistorical(): boolean {\n return this.storeService.historical;\n }\n\n private async getExistingProjectSchema(): Promise<string> {\n return getExistingProjectSchema(this.nodeConfig, this.sequelize);\n }\n\n async init(): Promise<void> {\n // Used to load assets into DS-processor, has to be done in any thread\n await this.dsProcessorService.validateProjectCustomDatasources();\n // Do extra work on main thread to setup stuff\n this.project.dataSources = await generateTimestampReferenceForBlockFilters(\n this.project.dataSources,\n this.apiService.api,\n );\n if (isMainThread) {\n this._schema = await this.ensureProject();\n await this.initDbSchema();\n await this.ensureMetadata();\n this.dynamicDsService.init(this.storeService.storeCache.metadata);\n\n await this.initHotSchemaReload();\n\n await this.initHotSchemaReload();\n\n if (this.nodeConfig.proofOfIndex) {\n const blockOffset = await this.getMetadataBlockOffset();\n void this.setBlockOffset(Number(blockOffset));\n await this.poiService.init();\n }\n\n this._startHeight = await this.getStartHeight();\n\n if (this.nodeConfig.unfinalizedBlocks && !this.isHistorical) {\n logger.error(\n 'Unfinalized blocks cannot be enabled without historical. You will need to reindex your project to enable historical',\n );\n process.exit(1);\n }\n\n const reindexedTo = await this.unfinalizedBlockService.init(\n this.reindex.bind(this),\n );\n\n if (reindexedTo !== undefined) {\n this._startHeight = reindexedTo;\n }\n\n // Flush any pending operations to setup DB\n await this.storeService.storeCache.flushCache();\n } else {\n this._schema = await this.getExistingProjectSchema();\n\n await this.sequelize.sync();\n\n assert(this._schema, 'Schema should be created in main thread');\n await this.initDbSchema();\n\n if (this.nodeConfig.proofOfIndex) {\n await this.poiService.init();\n }\n }\n }\n\n private async ensureProject(): Promise<string> {\n let schema = await this.getExistingProjectSchema();\n if (!schema) {\n schema = await this.createProjectSchema();\n }\n this.eventEmitter.emit(IndexerEvent.Ready, {\n value: true,\n });\n\n return schema;\n }\n\n private async createProjectSchema(): Promise<string> {\n let schema: string;\n if (this.nodeConfig.localMode) {\n // create tables in default schema if local mode is enabled\n schema = DEFAULT_DB_SCHEMA;\n } else {\n schema = this.nodeConfig.dbSchema;\n const schemas = await this.sequelize.showAllSchemas(undefined);\n if (!(schemas as unknown as string[]).includes(schema)) {\n await this.sequelize.createSchema(`\"${schema}\"`, undefined);\n }\n }\n\n return schema;\n }\n\n private async initHotSchemaReload(): Promise<void> {\n await initHotSchemaReload(this.schema, this.storeService);\n }\n private async initDbSchema(): Promise<void> {\n await initDbSchema(this.project, this.schema, this.storeService);\n }\n\n private async ensureMetadata(): Promise<void> {\n const metadata = this.storeService.storeCache.metadata;\n\n this.eventEmitter.emit(\n IndexerEvent.NetworkMetadata,\n this.apiService.networkMeta,\n );\n\n const keys = [\n 'lastProcessedHeight',\n 'blockOffset',\n 'indexerNodeVersion',\n 'chain',\n 'specName',\n 'genesisHash',\n 'startHeight',\n 'processedBlockCount',\n 'lastFinalizedVerifiedHeight',\n 'schemaMigrationCount',\n 'unfinalizedBlocks',\n ] as const;\n\n const existing = await metadata.findMany(keys);\n\n const { chain, genesisHash, specName } = this.apiService.networkMeta;\n\n if (this.project.runner) {\n const { node, query } = this.project.runner;\n\n metadata.setBulk([\n { key: 'runnerNode', value: node.name },\n { key: 'runnerNodeVersion', value: node.version },\n { key: 'runnerQuery', value: query.name },\n { key: 'runnerQueryVersion', value: query.version },\n ]);\n }\n if (!existing.genesisHash) {\n metadata.set('genesisHash', genesisHash);\n } else {\n // Check if the configured genesisHash matches the currently stored genesisHash\n assert(\n // Configured project yaml genesisHash only exists in specVersion v0.2.0, fallback to api fetched genesisHash on v0.0.1\n (this.project.network.genesisHash ?? genesisHash) ===\n existing.genesisHash,\n 'Specified project manifest chain id / genesis hash does not match database stored genesis hash, consider cleaning project schema using --force-clean',\n );\n }\n if (existing.chain !== chain) {\n metadata.set('chain', chain);\n }\n\n if (existing.specName !== specName) {\n metadata.set('specName', specName);\n }\n\n // If project was created before this feature, don't add the key. If it is project created after, add this key.\n if (!existing.processedBlockCount && !existing.lastProcessedHeight) {\n metadata.set('processedBlockCount', 0);\n }\n\n if (existing.indexerNodeVersion !== packageVersion) {\n metadata.set('indexerNodeVersion', packageVersion);\n }\n if (!existing.schemaMigrationCount) {\n metadata.set('schemaMigrationCount', 0);\n }\n if (!existing.startHeight) {\n metadata.set('startHeight', this.getStartBlockFromDataSources());\n }\n }\n\n private async getMetadataBlockOffset(): Promise<number | undefined> {\n return this.storeService.storeCache.metadata.find('blockOffset');\n }\n\n private async getLastProcessedHeight(): Promise<number | undefined> {\n return this.storeService.storeCache.metadata.find('lastProcessedHeight');\n }\n\n private async getStartHeight(): Promise<number> {\n let startHeight: number;\n const lastProcessedHeight = await this.getLastProcessedHeight();\n if (lastProcessedHeight !== null && lastProcessedHeight !== undefined) {\n startHeight = Number(lastProcessedHeight) + 1;\n } else {\n startHeight = this.getStartBlockFromDataSources();\n }\n return startHeight;\n }\n\n async setBlockOffset(offset: number): Promise<void> {\n if (\n this._blockOffset !== undefined ||\n offset === null ||\n offset === undefined ||\n isNaN(offset)\n ) {\n return;\n }\n logger.info(`set blockOffset to ${offset}`);\n this._blockOffset = offset;\n return this.mmrService.syncFileBaseFromPoi(offset).catch((err) => {\n logger.error(err, 'failed to sync poi to mmr');\n process.exit(1);\n });\n }\n\n private getStartBlockFromDataSources() {\n const startBlocksList = this.project.dataSources.map(\n (item) => item.startBlock ?? 1,\n );\n if (startBlocksList.length === 0) {\n logger.error(\n `Failed to find a valid datasource, Please check your endpoint if specName filter is used.`,\n );\n process.exit(1);\n } else {\n return Math.min(...startBlocksList);\n }\n }\n\n async reindex(targetBlockHeight: number): Promise<void> {\n const lastProcessedHeight = await this.getLastProcessedHeight();\n\n return reindex(\n this.getStartBlockFromDataSources(),\n await this.getMetadataBlockOffset(),\n targetBlockHeight,\n lastProcessedHeight,\n this.storeService,\n this.unfinalizedBlockService,\n this.dynamicDsService,\n this.mmrService,\n this.sequelize,\n /* Not providing force clean service, it should never be needed */\n );\n }\n\n async getAllDataSources(blockHeight: number): Promise<SubqlProjectDs[]> {\n const dynamicDs = await this.dynamicDsService.getDynamicDatasources();\n\n return [...this.dataSources, ...dynamicDs].filter(\n (ds) => ds.startBlock <= blockHeight,\n );\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.service.js","sourceRoot":"","sources":["../../../src/indexer/worker/worker.service.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;;;;AAEtC,6DAA+C;AAC/C,2CAA4C;AAC5C,gDAM0B;AAE1B,wDAAoD;AAiBpD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,mBAAmB,8BAAQ,EAAE,CAAC,CAAC;AAGjD,IAAM,aAAa,GAAnB,MAAM,aAAa;IAMxB,YACU,UAAsB,EACtB,cAA8B,EACtC,UAAsB;QAFd,eAAU,GAAV,UAAU,CAAY;QACtB,mBAAc,GAAd,cAAc,CAAgB;QAPhC,kBAAa,GAAiC,EAAE,CAAC;QACjD,gBAAW,GAAG,KAAK,CAAC;QAS1B,IAAI,CAAC,KAAK,GAAG,IAAI,qBAAS,CAAC,SAAS,EAAE,UA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M,CAAyB,CAAC;YAEjE,IAAI,CAAC,KAAK,EAAE;gBACV,MAAM,IAAI,KAAK,CAAC,SAAS,MAAM,uBAAuB,CAAC,CAAC;aACzD;YAED,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;YAElC,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;SACpD;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,yBAAyB,MAAM,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;YAC/D,MAAM,CAAC,CAAC;SACT;gBAAS;YACR,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;SAC1B;IACH,CAAC;IAED,IAAI,gBAAgB;QAClB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC;IAChD,CAAC;IAED,IAAI,iBAAiB;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF,CAAA;AAvEY,aAAa;IADzB,IAAA,mBAAU,GAAE;qCAQW,sBAAU;QACN,gCAAc;QAC1B,sBAAU;GATb,aAAa,CAuEzB;AAvEY,sCAAa","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { threadId } from 'node:worker_threads';\nimport { Injectable } from '@nestjs/common';\nimport {\n NodeConfig,\n getLogger,\n AutoQueue,\n memoryLock,\n ApiService,\n} from '@subql/node-core';\nimport { BlockWrapper, EthereumBlockWrapper } from '@subql/types-ethereum';\nimport { IndexerManager } from '../indexer.manager';\n\nexport type FetchBlockResponse = { parentHash: string } | undefined;\n\nexport type ProcessBlockResponse = {\n dynamicDsCreated: boolean;\n blockHash: string;\n reindexBlockHeight: number;\n};\n\nexport type WorkerStatusResponse = {\n threadId: number;\n isIndexing: boolean;\n fetchedBlocks: number;\n toFetchBlocks: number;\n};\n\nconst logger = getLogger(`Worker Service #${threadId}`);\n\n@Injectable()\nexport class WorkerService {\n private fetchedBlocks: Record<string, BlockWrapper> = {};\n private _isIndexing = false;\n\n private queue: AutoQueue<FetchBlockResponse>;\n\n constructor(\n private apiService: ApiService,\n private indexerManager: IndexerManager,\n nodeConfig: NodeConfig,\n ) {\n this.queue = new AutoQueue(undefined, nodeConfig.batchSize);\n }\n\n async fetchBlock(height: number): Promise<FetchBlockResponse> {\n try {\n return await this.queue.put(async () => {\n // If a dynamic ds is created we might be asked to fetch blocks again, use existing result\n if (!this.fetchedBlocks[height]) {\n if (memoryLock.isLocked()) {\n const start = Date.now();\n await memoryLock.waitForUnlock();\n const end = Date.now();\n logger.debug(`memory lock wait time: ${end - start}ms`);\n }\n\n const [block] = await this.apiService.api.fetchBlocks([height]);\n this.fetchedBlocks[height] = block;\n }\n\n // const block = this.fetchedBlocks[height];\n\n // Return info to get the runtime version, this lets the worker thread know\n return undefined;\n });\n } catch (e) {\n logger.error(/*e, */ `Failed to fetch block ${height}`);\n }\n }\n\n async processBlock(height: number): Promise<ProcessBlockResponse> {\n try {\n this._isIndexing = true;\n const block = this.fetchedBlocks[height] as EthereumBlockWrapper;\n\n if (!block) {\n throw new Error(`Block ${height} has not been fetched`);\n }\n\n delete this.fetchedBlocks[height];\n\n return await this.indexerManager.indexBlock(block);\n } catch (e) {\n logger.error(e, `Failed to index block ${height}: ${e.stack}`);\n throw e;\n } finally {\n this._isIndexing = false;\n }\n }\n\n get numFetchedBlocks(): number {\n return Object.keys(this.fetchedBlocks).length;\n }\n\n get numFetchingBlocks(): number {\n return this.queue.size;\n }\n\n get isIndexing(): boolean {\n return this._isIndexing;\n }\n}\n"]}
|
|
@@ -10,6 +10,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.ReindexModule = exports.ReindexFeatureModule = void 0;
|
|
12
12
|
const common_1 = require("@nestjs/common");
|
|
13
|
+
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
13
14
|
const node_core_1 = require("@subql/node-core");
|
|
14
15
|
const configure_module_1 = require("../configure/configure.module");
|
|
15
16
|
const ds_processor_service_1 = require("../indexer/ds-processor.service");
|
|
@@ -48,6 +49,7 @@ ReindexModule = __decorate([
|
|
|
48
49
|
node_core_1.DbModule.forRoot(),
|
|
49
50
|
configure_module_1.ConfigureModule.register(),
|
|
50
51
|
ReindexFeatureModule,
|
|
52
|
+
event_emitter_1.EventEmitterModule.forRoot(),
|
|
51
53
|
],
|
|
52
54
|
controllers: [],
|
|
53
55
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reindex.module.js","sourceRoot":"","sources":["../../src/subcommands/reindex.module.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;AAEtC,2CAAwC;AACxC,gDAM0B;AAC1B,oEAAgE;AAChE,0EAAqE;AACrE,sEAAiE;AACjE,oFAAgF;AAChF,6DAAyD;AACzD,uDAAmD;AAoB5C,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;CAAG,CAAA;AAAvB,oBAAoB;IAlBhC,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT,6BAAiB;YACjB,wBAAY;YACZ,gCAAc;YACd,sBAAU;YACV,sCAAiB;YACjB,oDAAwB;YACxB,qCAAgB;YAChB,yCAAkB;YAClB;gBACE,8EAA8E;gBAC9E,OAAO,EAAE,sBAAU;gBACnB,UAAU,EAAE,GAAG,EAAE,CAAC,SAAS;aAC5B;SACF;QACD,WAAW,EAAE,EAAE;KAChB,CAAC;GACW,oBAAoB,CAAG;AAAvB,oDAAoB;
|
|
1
|
+
{"version":3,"file":"reindex.module.js","sourceRoot":"","sources":["../../src/subcommands/reindex.module.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;AAEtC,2CAAwC;AACxC,yDAA2D;AAC3D,gDAM0B;AAC1B,oEAAgE;AAChE,0EAAqE;AACrE,sEAAiE;AACjE,oFAAgF;AAChF,6DAAyD;AACzD,uDAAmD;AAoB5C,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;CAAG,CAAA;AAAvB,oBAAoB;IAlBhC,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT,6BAAiB;YACjB,wBAAY;YACZ,gCAAc;YACd,sBAAU;YACV,sCAAiB;YACjB,oDAAwB;YACxB,qCAAgB;YAChB,yCAAkB;YAClB;gBACE,8EAA8E;gBAC9E,OAAO,EAAE,sBAAU;gBACnB,UAAU,EAAE,GAAG,EAAE,CAAC,SAAS;aAC5B;SACF;QACD,WAAW,EAAE,EAAE;KAChB,CAAC;GACW,oBAAoB,CAAG;AAAvB,oDAAoB;AAW1B,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,aAAa;IATzB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,oBAAQ,CAAC,OAAO,EAAE;YAClB,kCAAe,CAAC,QAAQ,EAAE;YAC1B,oBAAoB;YACpB,kCAAkB,CAAC,OAAO,EAAE;SAC7B;QACD,WAAW,EAAE,EAAE;KAChB,CAAC;GACW,aAAa,CAAG;AAAhB,sCAAa","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Module } from '@nestjs/common';\nimport { EventEmitterModule } from '@nestjs/event-emitter';\nimport {\n ApiService,\n DbModule,\n MmrService,\n StoreCacheService,\n StoreService,\n} from '@subql/node-core';\nimport { ConfigureModule } from '../configure/configure.module';\nimport { DsProcessorService } from '../indexer/ds-processor.service';\nimport { DynamicDsService } from '../indexer/dynamic-ds.service';\nimport { UnfinalizedBlocksService } from '../indexer/unfinalizedBlocks.service';\nimport { ForceCleanService } from './forceClean.service';\nimport { ReindexService } from './reindex.service';\n\n@Module({\n providers: [\n StoreCacheService,\n StoreService,\n ReindexService,\n MmrService,\n ForceCleanService,\n UnfinalizedBlocksService,\n DynamicDsService,\n DsProcessorService,\n {\n // Used to work with DI for unfinalizedBlocksService but not used with reindex\n provide: ApiService,\n useFactory: () => undefined,\n },\n ],\n controllers: [],\n})\nexport class ReindexFeatureModule {}\n\n@Module({\n imports: [\n DbModule.forRoot(),\n ConfigureModule.register(),\n ReindexFeatureModule,\n EventEmitterModule.forRoot(),\n ],\n controllers: [],\n})\nexport class ReindexModule {}\n"]}
|
package/dist/yargs.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const yargsOptions: import("yargs").Argv<import("yargs").Omit<{
|
|
2
2
|
targetHeight: number;
|
|
3
|
-
}, "batch-size" | "config" | "db-schema" | "debug" | "dictionary-timeout" | "disable-historical" | "ipfs" | "local" | "log-level" | "mmr-path" | "multi-chain" | "network-dictionary" | "network-endpoint" | "output-fmt" | "port" | "profiler" | "proof-of-index" | "query-limit" | "scale-batch-size" | "dictionary-resolver" | "subquery" | "subquery-name" | "subscription" | "timeout" | "timestamp-field" | "unfinalized-blocks" | "unsafe" | "workers" | "pg-ca" | "pg-key" | "pg-cert" | "store-cache-threshold"> & import("yargs").InferredOptionTypes<{
|
|
3
|
+
}, "batch-size" | "config" | "db-schema" | "debug" | "dictionary-timeout" | "disable-historical" | "ipfs" | "local" | "log-level" | "mmr-path" | "multi-chain" | "network-dictionary" | "network-endpoint" | "output-fmt" | "port" | "profiler" | "proof-of-index" | "query-limit" | "scale-batch-size" | "dictionary-resolver" | "subquery" | "subquery-name" | "subscription" | "timeout" | "timestamp-field" | "unfinalized-blocks" | "unsafe" | "workers" | "pg-ca" | "pg-key" | "pg-cert" | "store-cache-threshold" | "store-get-cache-size"> & import("yargs").InferredOptionTypes<{
|
|
4
4
|
'batch-size': {
|
|
5
5
|
demandOption: false;
|
|
6
6
|
describe: string;
|
|
@@ -183,4 +183,9 @@ export declare const yargsOptions: import("yargs").Argv<import("yargs").Omit<{
|
|
|
183
183
|
describe: string;
|
|
184
184
|
type: "number";
|
|
185
185
|
};
|
|
186
|
+
'store-get-cache-size': {
|
|
187
|
+
demandOption: false;
|
|
188
|
+
describe: string;
|
|
189
|
+
type: "number";
|
|
190
|
+
};
|
|
186
191
|
}>>;
|
package/dist/yargs.js
CHANGED
|
@@ -222,5 +222,10 @@ exports.yargsOptions = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)
|
|
|
222
222
|
describe: 'Store cache will flush when number of records excess this threshold',
|
|
223
223
|
type: 'number',
|
|
224
224
|
},
|
|
225
|
+
'store-get-cache-size': {
|
|
226
|
+
demandOption: false,
|
|
227
|
+
describe: 'Store get cache size for each model',
|
|
228
|
+
type: 'number',
|
|
229
|
+
},
|
|
225
230
|
});
|
|
226
231
|
//# sourceMappingURL=yargs.js.map
|
package/dist/yargs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yargs.js","sourceRoot":"","sources":["../src/yargs.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;AAEtC,oDAAqD;AACrD,2CAAwC;AACxC,wDAAgC;AAEnB,QAAA,YAAY,GAAG,IAAA,eAAK,EAAC,IAAA,iBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KACrD,GAAG,CAAC,YAAY,CAAC;KACjB,OAAO,CAAC;IACP,OAAO,EAAE,aAAa;IACtB,QAAQ,EACN,mIAAmI;IACrI,OAAO,EAAE,EAAE;IACX,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;QAChB,IAAA,mBAAU,EACR,IAAI,CAAC,KAAgB,EACrB,IAAI,CAAC,SAA+B,EACpC,IAAI,CAAC,QAA8B,CACpC,CAAC;QAEF,4EAA4E;QAC5E,8DAA8D;QAC9D,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,+BAA+B,CAAC,CAAC;QACpE,OAAO,cAAc,EAAE,CAAC;IAC1B,CAAC;CACF,CAA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AAO,EAAE,KAAK;QACd,QAAQ,EAAE,8CAA8C;QACxD,IAAI,EAAE,SAAS;KAChB;IACD,MAAM,EAAE;QACN,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,KAAK;QACnB,QAAQ,EAAE,wDAAwD;KACnE;IACD,OAAO,EAAE;QACP,KAAK,EAAE,GAAG;QACV,YAAY,EAAE,KAAK;QACnB,QAAQ,EACN,0FAA0F;QAC5F,IAAI,EAAE,QAAQ;KACf;IACD,OAAO,EAAE;QACP,YAAY,EAAE,KAAK;QACnB,QAAQ,EACN,0KAA0K;QAC5K,IAAI,EAAE,QAAQ;KACf;IACD,QAAQ,EAAE;QACR,YAAY,EAAE,KAAK;QACnB,QAAQ,EACN,+EAA+E;QACjF,IAAI,EAAE,QAAQ;KACf;IACD,SAAS,EAAE;QACT,YAAY,EAAE,KAAK;QACnB,QAAQ,EACN,0GAA0G;QAC5G,IAAI,EAAE,QAAQ;KACf;IACD,uBAAuB,EAAE;QACvB,YAAY,EAAE,KAAK;QACnB,QAAQ,EACN,qEAAqE;QACvE,IAAI,EAAE,QAAQ;KACf;CACF,CAAC,CAAC","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { initLogger } from '@subql/node-core/logger';\nimport { hideBin } from 'yargs/helpers';\nimport yargs from 'yargs/yargs';\n\nexport const yargsOptions = yargs(hideBin(process.argv))\n .env('SUBQL_NODE')\n .command({\n command: 'force-clean',\n describe:\n 'Clean the database dropping project schemas and tables. Once the command is executed, the application would exit upon completion.',\n builder: {},\n handler: (argv) => {\n initLogger(\n argv.debug as boolean,\n argv.outputFmt as 'json' | 'colored',\n argv.logLevel as string | undefined,\n );\n\n // lazy import to make sure logger is instantiated before all other services\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { forceCleanInit } = require('./subcommands/forceClean.init');\n return forceCleanInit();\n },\n })\n .command({\n command: 'reindex',\n describe:\n 'Reindex to specified block height. Historical must be enabled for the targeted project (--disable-historical=false). Once the command is executed, the application would exit upon completion.',\n builder: (yargs) =>\n yargs.options('targetHeight', {\n type: 'number',\n description: 'set targetHeight',\n require: true,\n }),\n handler: (argv) => {\n initLogger(\n argv.debug as boolean,\n argv.outputFmt as 'json' | 'colored',\n argv.logLevel as string | undefined,\n );\n // lazy import to make sure logger is instantiated before all other services\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { reindexInit } = require('./subcommands/reindex.init');\n return reindexInit(argv.targetHeight);\n },\n })\n .options({\n 'batch-size': {\n demandOption: false,\n describe: 'Batch size of blocks to fetch in one round',\n type: 'number',\n },\n config: {\n alias: 'c',\n demandOption: false,\n describe: 'Specify configuration file',\n type: 'string',\n },\n 'db-schema': {\n demandOption: false,\n describe: 'Db schema name of the project',\n type: 'string',\n },\n debug: {\n demandOption: false,\n describe:\n 'Show debug information to console output. will forcefully set log level to debug',\n type: 'boolean',\n default: false,\n },\n 'dictionary-timeout': {\n demandOption: false,\n describe: 'Max timeout for dictionary query',\n type: 'number',\n },\n 'disable-historical': {\n demandOption: false,\n default: false,\n describe: 'Disable storing historical state entities',\n type: 'boolean',\n },\n ipfs: {\n demandOption: false,\n describe: 'IPFS gateway endpoint',\n type: 'string',\n },\n local: {\n deprecated: true,\n type: 'boolean',\n demandOption: false,\n describe: 'Use local mode',\n },\n 'log-level': {\n demandOption: false,\n describe: 'Specify log level to print. Ignored when --debug is used',\n type: 'string',\n choices: ['fatal', 'error', 'warn', 'info', 'debug', 'trace', 'silent'],\n },\n 'mmr-path': {\n alias: 'm',\n demandOption: false,\n describe: 'Local path of the merkle mountain range (.mmr) file',\n type: 'string',\n },\n 'multi-chain': {\n demandOption: false,\n default: false,\n describe:\n 'Enables indexing multiple subquery projects into the same database schema',\n type: 'boolean',\n },\n 'network-dictionary': {\n alias: 'd',\n demandOption: false,\n describe: 'Specify the dictionary api for this network',\n type: 'string',\n },\n 'network-endpoint': {\n demandOption: false,\n type: 'string',\n describe: 'Blockchain network endpoint to connect',\n },\n 'output-fmt': {\n demandOption: false,\n describe: 'Print log as json or plain text',\n type: 'string',\n choices: ['json', 'colored'],\n },\n port: {\n alias: 'p',\n demandOption: false,\n describe: 'The port the service will bind to',\n type: 'number',\n },\n profiler: {\n demandOption: false,\n describe: 'Show profiler information to console output',\n type: 'boolean',\n default: false,\n },\n 'proof-of-index': {\n demandOption: false,\n describe: 'Enable/disable proof of index',\n type: 'boolean',\n default: false,\n },\n 'query-limit': {\n demandOption: false,\n describe:\n 'The limit of items a project can query with store.getByField at once',\n type: 'number',\n default: 100,\n },\n 'scale-batch-size': {\n type: 'boolean',\n demandOption: false,\n describe: 'scale batch size based on memory usage',\n default: false,\n },\n 'dictionary-resolver': {\n demandOption: false,\n describe: 'Use subquery network dictionary resolver',\n type: 'boolean',\n default: false,\n },\n subquery: {\n alias: 'f',\n demandOption: true,\n default: process.cwd(),\n describe: 'Local path or IPFS cid of the subquery project',\n type: 'string',\n },\n 'subquery-name': {\n deprecated: true,\n demandOption: false,\n describe: 'Name of the subquery project',\n type: 'string',\n },\n subscription: {\n demandOption: false,\n describe: 'Enable subscription by create notification triggers',\n type: 'boolean',\n default: false,\n },\n timeout: {\n demandOption: false,\n describe: 'Timeout for indexer sandbox to execute the mapping functions',\n type: 'number',\n },\n 'timestamp-field': {\n demandOption: false,\n describe: 'Enable/disable created_at and updated_at in schema',\n type: 'boolean',\n default: false,\n },\n 'unfinalized-blocks': {\n demandOption: false,\n default: false,\n describe: 'Enable to fetch and index unfinalized blocks',\n type: 'boolean',\n },\n unsafe: {\n type: 'boolean',\n demandOption: false,\n describe: 'Allows usage of any built-in module within the sandbox',\n },\n workers: {\n alias: 'w',\n demandOption: false,\n describe:\n 'Number of worker threads to use for fetching and processing blocks. Disabled by default.',\n type: 'number',\n },\n 'pg-ca': {\n demandOption: false,\n describe:\n 'Postgres ca certificate - to enables TLS/SSL connections to your PostgreSQL, path to the server certificate file are required, e.g /path/to/server-certificates/root.crt',\n type: 'string',\n },\n 'pg-key': {\n demandOption: false,\n describe:\n 'Postgres client key - Path to key file e.g /path/to/client-key/postgresql.key',\n type: 'string',\n },\n 'pg-cert': {\n demandOption: false,\n describe:\n 'Postgres client certificate - Path to client certificate e.g /path/to/client-certificates/postgresql.crt',\n type: 'string',\n },\n 'store-cache-threshold': {\n demandOption: false,\n describe:\n 'Store cache will flush when number of records excess this threshold',\n type: 'number',\n },\n });\n"]}
|
|
1
|
+
{"version":3,"file":"yargs.js","sourceRoot":"","sources":["../src/yargs.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;AAEtC,oDAAqD;AACrD,2CAAwC;AACxC,wDAAgC;AAEnB,QAAA,YAAY,GAAG,IAAA,eAAK,EAAC,IAAA,iBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KACrD,GAAG,CAAC,YAAY,CAAC;KACjB,OAAO,CAAC;IACP,OAAO,EAAE,aAAa;IACtB,QAAQ,EACN,mIAAmI;IACrI,OAAO,EAAE,EAAE;IACX,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;QAChB,IAAA,mBAAU,EACR,IAAI,CAAC,KAAgB,EACrB,IAAI,CAAC,SAA+B,EACpC,IAAI,CAAC,QAA8B,CACpC,CAAC;QAEF,4EAA4E;QAC5E,8DAA8D;QAC9D,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,+BAA+B,CAAC,CAAC;QACpE,OAAO,cAAc,EAAE,CAAC;IAC1B,CAAC;CACF,CAAC;KACD,OAAO,CAAC;IACP,OAAO,EAAE,SAAS;IAClB,QAAQ,EACN,gMAAgM;IAClM,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CACjB,KAAK,CAAC,OAAO,CAAC,cAAc,EAAE;QAC5B,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,kBAAkB;QAC/B,OAAO,EAAE,IAAI;KACd,CAAC;IACJ,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;QAChB,IAAA,mBAAU,EACR,IAAI,CAAC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EAAE,KAAK;QACnB,QAAQ,EACN,0KAA0K;QAC5K,IAAI,EAAE,QAAQ;KACf;IACD,QAAQ,EAAE;QACR,YAAY,EAAE,KAAK;QACnB,QAAQ,EACN,+EAA+E;QACjF,IAAI,EAAE,QAAQ;KACf;IACD,SAAS,EAAE;QACT,YAAY,EAAE,KAAK;QACnB,QAAQ,EACN,0GAA0G;QAC5G,IAAI,EAAE,QAAQ;KACf;IACD,uBAAuB,EAAE;QACvB,YAAY,EAAE,KAAK;QACnB,QAAQ,EACN,qEAAqE;QACvE,IAAI,EAAE,QAAQ;KACf;IACD,sBAAsB,EAAE;QACtB,YAAY,EAAE,KAAK;QACnB,QAAQ,EAAE,qCAAqC;QAC/C,IAAI,EAAE,QAAQ;KACf;CACF,CAAC,CAAC","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { initLogger } from '@subql/node-core/logger';\nimport { hideBin } from 'yargs/helpers';\nimport yargs from 'yargs/yargs';\n\nexport const yargsOptions = yargs(hideBin(process.argv))\n .env('SUBQL_NODE')\n .command({\n command: 'force-clean',\n describe:\n 'Clean the database dropping project schemas and tables. Once the command is executed, the application would exit upon completion.',\n builder: {},\n handler: (argv) => {\n initLogger(\n argv.debug as boolean,\n argv.outputFmt as 'json' | 'colored',\n argv.logLevel as string | undefined,\n );\n\n // lazy import to make sure logger is instantiated before all other services\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { forceCleanInit } = require('./subcommands/forceClean.init');\n return forceCleanInit();\n },\n })\n .command({\n command: 'reindex',\n describe:\n 'Reindex to specified block height. Historical must be enabled for the targeted project (--disable-historical=false). Once the command is executed, the application would exit upon completion.',\n builder: (yargs) =>\n yargs.options('targetHeight', {\n type: 'number',\n description: 'set targetHeight',\n require: true,\n }),\n handler: (argv) => {\n initLogger(\n argv.debug as boolean,\n argv.outputFmt as 'json' | 'colored',\n argv.logLevel as string | undefined,\n );\n // lazy import to make sure logger is instantiated before all other services\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { reindexInit } = require('./subcommands/reindex.init');\n return reindexInit(argv.targetHeight);\n },\n })\n .options({\n 'batch-size': {\n demandOption: false,\n describe: 'Batch size of blocks to fetch in one round',\n type: 'number',\n },\n config: {\n alias: 'c',\n demandOption: false,\n describe: 'Specify configuration file',\n type: 'string',\n },\n 'db-schema': {\n demandOption: false,\n describe: 'Db schema name of the project',\n type: 'string',\n },\n debug: {\n demandOption: false,\n describe:\n 'Show debug information to console output. will forcefully set log level to debug',\n type: 'boolean',\n default: false,\n },\n 'dictionary-timeout': {\n demandOption: false,\n describe: 'Max timeout for dictionary query',\n type: 'number',\n },\n 'disable-historical': {\n demandOption: false,\n default: false,\n describe: 'Disable storing historical state entities',\n type: 'boolean',\n },\n ipfs: {\n demandOption: false,\n describe: 'IPFS gateway endpoint',\n type: 'string',\n },\n local: {\n deprecated: true,\n type: 'boolean',\n demandOption: false,\n describe: 'Use local mode',\n },\n 'log-level': {\n demandOption: false,\n describe: 'Specify log level to print. Ignored when --debug is used',\n type: 'string',\n choices: ['fatal', 'error', 'warn', 'info', 'debug', 'trace', 'silent'],\n },\n 'mmr-path': {\n alias: 'm',\n demandOption: false,\n describe: 'Local path of the merkle mountain range (.mmr) file',\n type: 'string',\n },\n 'multi-chain': {\n demandOption: false,\n default: false,\n describe:\n 'Enables indexing multiple subquery projects into the same database schema',\n type: 'boolean',\n },\n 'network-dictionary': {\n alias: 'd',\n demandOption: false,\n describe: 'Specify the dictionary api for this network',\n type: 'string',\n },\n 'network-endpoint': {\n demandOption: false,\n type: 'string',\n describe: 'Blockchain network endpoint to connect',\n },\n 'output-fmt': {\n demandOption: false,\n describe: 'Print log as json or plain text',\n type: 'string',\n choices: ['json', 'colored'],\n },\n port: {\n alias: 'p',\n demandOption: false,\n describe: 'The port the service will bind to',\n type: 'number',\n },\n profiler: {\n demandOption: false,\n describe: 'Show profiler information to console output',\n type: 'boolean',\n default: false,\n },\n 'proof-of-index': {\n demandOption: false,\n describe: 'Enable/disable proof of index',\n type: 'boolean',\n default: false,\n },\n 'query-limit': {\n demandOption: false,\n describe:\n 'The limit of items a project can query with store.getByField at once',\n type: 'number',\n default: 100,\n },\n 'scale-batch-size': {\n type: 'boolean',\n demandOption: false,\n describe: 'scale batch size based on memory usage',\n default: false,\n },\n 'dictionary-resolver': {\n demandOption: false,\n describe: 'Use subquery network dictionary resolver',\n type: 'boolean',\n default: false,\n },\n subquery: {\n alias: 'f',\n demandOption: true,\n default: process.cwd(),\n describe: 'Local path or IPFS cid of the subquery project',\n type: 'string',\n },\n 'subquery-name': {\n deprecated: true,\n demandOption: false,\n describe: 'Name of the subquery project',\n type: 'string',\n },\n subscription: {\n demandOption: false,\n describe: 'Enable subscription by create notification triggers',\n type: 'boolean',\n default: false,\n },\n timeout: {\n demandOption: false,\n describe: 'Timeout for indexer sandbox to execute the mapping functions',\n type: 'number',\n },\n 'timestamp-field': {\n demandOption: false,\n describe: 'Enable/disable created_at and updated_at in schema',\n type: 'boolean',\n default: false,\n },\n 'unfinalized-blocks': {\n demandOption: false,\n default: false,\n describe: 'Enable to fetch and index unfinalized blocks',\n type: 'boolean',\n },\n unsafe: {\n type: 'boolean',\n demandOption: false,\n describe: 'Allows usage of any built-in module within the sandbox',\n },\n workers: {\n alias: 'w',\n demandOption: false,\n describe:\n 'Number of worker threads to use for fetching and processing blocks. Disabled by default.',\n type: 'number',\n },\n 'pg-ca': {\n demandOption: false,\n describe:\n 'Postgres ca certificate - to enables TLS/SSL connections to your PostgreSQL, path to the server certificate file are required, e.g /path/to/server-certificates/root.crt',\n type: 'string',\n },\n 'pg-key': {\n demandOption: false,\n describe:\n 'Postgres client key - Path to key file e.g /path/to/client-key/postgresql.key',\n type: 'string',\n },\n 'pg-cert': {\n demandOption: false,\n describe:\n 'Postgres client certificate - Path to client certificate e.g /path/to/client-certificates/postgresql.crt',\n type: 'string',\n },\n 'store-cache-threshold': {\n demandOption: false,\n describe:\n 'Store cache will flush when number of records excess this threshold',\n type: 'number',\n },\n 'store-get-cache-size': {\n demandOption: false,\n describe: 'Store get cache size for each model',\n type: 'number',\n },\n });\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@subql/node-ethereum",
|
|
3
|
-
"version": "0.4.1-storeCache-0.0.
|
|
3
|
+
"version": "0.4.1-storeCache-0.0.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Ian He",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -26,13 +26,14 @@
|
|
|
26
26
|
"@nestjs/schedule": "^1.0.2",
|
|
27
27
|
"@subql/common": "^1.7.0",
|
|
28
28
|
"@subql/common-ethereum": "0.2.2-4",
|
|
29
|
-
"@subql/node-core": "1.10.1-storeCache-0.0.
|
|
29
|
+
"@subql/node-core": "1.10.1-storeCache-0.0.5",
|
|
30
30
|
"@subql/types-ethereum": "0.2.2-6",
|
|
31
31
|
"@subql/utils": "^1.4.1",
|
|
32
32
|
"@subql/x-merkle-mountain-range": "2.0.0-0.1.2",
|
|
33
33
|
"@willsoto/nestjs-prometheus": "^4.4.0",
|
|
34
34
|
"algosdk": "^1.13.1",
|
|
35
35
|
"app-module-path": "^2.2.0",
|
|
36
|
+
"cacheable-lookup": "6",
|
|
36
37
|
"cron-converter": "^1.0.2",
|
|
37
38
|
"dayjs": "^1.10.7",
|
|
38
39
|
"ethers": "^5.7.0",
|