@subql/node-ethereum 0.4.1-8 → 0.4.1-storeCache-0.0.3
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/CHANGELOG.md +1 -0
- package/README.md +3 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/ethereum/api.ethereum.d.ts +8 -4
- package/dist/ethereum/api.ethereum.js +70 -49
- package/dist/ethereum/api.ethereum.js.map +1 -1
- package/dist/ethereum/api.service.ethereum.js +1 -1
- package/dist/ethereum/api.service.ethereum.js.map +1 -1
- package/dist/ethereum/block.ethereum.d.ts +1 -1
- package/dist/ethereum/block.ethereum.js +9 -12
- package/dist/ethereum/block.ethereum.js.map +1 -1
- package/dist/ethereum/ethers/json-rpc-batch-provider.d.ts +21 -0
- package/dist/ethereum/ethers/json-rpc-batch-provider.js +102 -0
- package/dist/ethereum/ethers/json-rpc-batch-provider.js.map +1 -0
- package/dist/ethereum/ethers/json-rpc-provider.d.ts +7 -0
- package/dist/ethereum/ethers/json-rpc-provider.js +68 -0
- package/dist/ethereum/ethers/json-rpc-provider.js.map +1 -0
- package/dist/ethereum/ethers/web/_version.d.ts +1 -0
- package/dist/ethereum/ethers/web/_version.js +6 -0
- package/dist/ethereum/ethers/web/_version.js.map +1 -0
- package/dist/ethereum/ethers/web/geturl.d.ts +3 -0
- package/dist/ethereum/ethers/web/geturl.js +116 -0
- package/dist/ethereum/ethers/web/geturl.js.map +1 -0
- package/dist/ethereum/ethers/web/index.d.ts +49 -0
- package/dist/ethereum/ethers/web/index.js +433 -0
- package/dist/ethereum/ethers/web/index.js.map +1 -0
- package/dist/ethereum/ethers/web/types.d.ts +26 -0
- package/dist/ethereum/ethers/web/types.js +4 -0
- package/dist/ethereum/ethers/web/types.js.map +1 -0
- package/dist/ethereum/utils.ethereum.d.ts +1 -1
- package/dist/ethereum/utils.ethereum.js +16 -3
- package/dist/ethereum/utils.ethereum.js.map +1 -1
- package/dist/indexer/blockDispatcher/block-dispatcher.service.d.ts +8 -15
- package/dist/indexer/blockDispatcher/block-dispatcher.service.js +20 -108
- package/dist/indexer/blockDispatcher/block-dispatcher.service.js.map +1 -1
- package/dist/indexer/blockDispatcher/ethereum-block-dispatcher.d.ts +4 -0
- package/dist/indexer/blockDispatcher/ethereum-block-dispatcher.js +5 -0
- package/dist/indexer/blockDispatcher/ethereum-block-dispatcher.js.map +1 -0
- package/dist/indexer/blockDispatcher/index.d.ts +2 -2
- package/dist/indexer/blockDispatcher/index.js.map +1 -1
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.d.ts +12 -17
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js +48 -134
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js.map +1 -1
- package/dist/indexer/dynamic-ds.service.d.ts +3 -22
- package/dist/indexer/dynamic-ds.service.js +4 -91
- package/dist/indexer/dynamic-ds.service.js.map +1 -1
- package/dist/indexer/fetch.module.js +24 -6
- package/dist/indexer/fetch.module.js.map +1 -1
- package/dist/indexer/fetch.service.d.ts +3 -3
- package/dist/indexer/fetch.service.js +40 -39
- package/dist/indexer/fetch.service.js.map +1 -1
- package/dist/indexer/indexer.manager.d.ts +5 -17
- package/dist/indexer/indexer.manager.js +25 -70
- package/dist/indexer/indexer.manager.js.map +1 -1
- package/dist/indexer/indexer.module.js +25 -2
- package/dist/indexer/indexer.module.js.map +1 -1
- package/dist/indexer/project.service.d.ts +5 -10
- package/dist/indexer/project.service.js +49 -100
- package/dist/indexer/project.service.js.map +1 -1
- package/dist/indexer/sandbox.service.js +6 -1
- package/dist/indexer/sandbox.service.js.map +1 -1
- package/dist/indexer/unfinalizedBlocks.service.d.ts +12 -12
- package/dist/indexer/unfinalizedBlocks.service.js +33 -38
- package/dist/indexer/unfinalizedBlocks.service.js.map +1 -1
- package/dist/indexer/unfinalizedBlocks.spec.js +41 -34
- package/dist/indexer/unfinalizedBlocks.spec.js.map +1 -1
- package/dist/indexer/worker/worker.d.ts +22 -8
- package/dist/indexer/worker/worker.js +14 -7
- package/dist/indexer/worker/worker.js.map +1 -1
- package/dist/indexer/worker/worker.service.d.ts +2 -2
- package/dist/indexer/worker/worker.service.js +11 -4
- package/dist/indexer/worker/worker.service.js.map +1 -1
- package/dist/indexer/worker/worker.unfinalizedBlocks.service.d.ts +11 -0
- package/dist/indexer/worker/worker.unfinalizedBlocks.service.js +32 -0
- package/dist/indexer/worker/worker.unfinalizedBlocks.service.js.map +1 -0
- package/dist/init.js +2 -2
- package/dist/init.js.map +1 -1
- package/dist/meta/meta.module.js +8 -0
- package/dist/meta/meta.module.js.map +1 -1
- package/dist/meta/meta.service.d.ts +18 -3
- package/dist/meta/meta.service.js +89 -5
- package/dist/meta/meta.service.js.map +1 -1
- package/dist/subcommands/forceClean.service.js +8 -4
- package/dist/subcommands/forceClean.service.js.map +1 -1
- package/dist/subcommands/reindex.init.js +5 -1
- package/dist/subcommands/reindex.init.js.map +1 -1
- package/dist/subcommands/reindex.module.js +8 -0
- package/dist/subcommands/reindex.module.js.map +1 -1
- package/dist/subcommands/reindex.service.d.ts +4 -1
- package/dist/subcommands/reindex.service.js +21 -10
- package/dist/subcommands/reindex.service.js.map +1 -1
- package/dist/utils/project.d.ts +1 -0
- package/dist/utils/project.js +13 -1
- package/dist/utils/project.js.map +1 -1
- package/dist/utils/reindex.d.ts +2 -1
- package/dist/utils/reindex.js +6 -2
- package/dist/utils/reindex.js.map +1 -1
- package/dist/utils/string.js +10 -2
- package/dist/utils/string.js.map +1 -1
- package/dist/yargs.d.ts +85 -53
- package/dist/yargs.js +103 -71
- package/dist/yargs.js.map +1 -1
- package/package.json +9 -9
- package/dist/indexer/blockDispatcher/base-block-dispatcher.d.ts +0 -40
- package/dist/indexer/blockDispatcher/base-block-dispatcher.js +0 -99
- package/dist/indexer/blockDispatcher/base-block-dispatcher.js.map +0 -1
|
@@ -51,6 +51,7 @@ function eventFilterToQueryEntry(filter, dsOptions) {
|
|
|
51
51
|
conditions.push({
|
|
52
52
|
field: 'address',
|
|
53
53
|
value: dsOptions.address.toLowerCase(),
|
|
54
|
+
// matcher: 'equals',
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
57
|
}
|
|
@@ -61,7 +62,11 @@ function eventFilterToQueryEntry(filter, dsOptions) {
|
|
|
61
62
|
continue;
|
|
62
63
|
}
|
|
63
64
|
const field = `topics${i}`;
|
|
64
|
-
conditions.push({
|
|
65
|
+
conditions.push({
|
|
66
|
+
field,
|
|
67
|
+
value: (0, string_1.eventToTopic)(topic),
|
|
68
|
+
matcher: 'equalTo',
|
|
69
|
+
});
|
|
65
70
|
}
|
|
66
71
|
}
|
|
67
72
|
return {
|
|
@@ -87,6 +92,7 @@ function callFilterToQueryEntry(filter) {
|
|
|
87
92
|
conditions.push({
|
|
88
93
|
field: 'func',
|
|
89
94
|
value: (0, string_1.functionToSighash)(filter.function),
|
|
95
|
+
matcher: 'equalTo',
|
|
90
96
|
});
|
|
91
97
|
}
|
|
92
98
|
return {
|
|
@@ -136,38 +142,34 @@ let FetchService = class FetchService {
|
|
|
136
142
|
.sort((a, b) => a.startBlock - b.startBlock);
|
|
137
143
|
for (const ds of filteredDs) {
|
|
138
144
|
for (const handler of ds.mapping.handlers) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
filterList = filterList.filter((f) => f);
|
|
142
|
-
if (!filterList.length)
|
|
145
|
+
// No filters, cant use dictionary
|
|
146
|
+
if (!handler.filter)
|
|
143
147
|
return [];
|
|
144
148
|
switch (handler.kind) {
|
|
145
149
|
case common_ethereum_1.EthereumHandlerKind.Block:
|
|
146
150
|
return [];
|
|
147
151
|
case common_ethereum_1.EthereumHandlerKind.Call: {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
152
|
+
const filter = handler.filter;
|
|
153
|
+
if (filter.from !== undefined ||
|
|
154
|
+
filter.to !== undefined ||
|
|
155
|
+
filter.function) {
|
|
156
|
+
queryEntries.push(callFilterToQueryEntry(filter));
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
return [];
|
|
157
160
|
}
|
|
158
161
|
break;
|
|
159
162
|
}
|
|
160
163
|
case common_ethereum_1.EthereumHandlerKind.Event: {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
164
|
+
const filter = handler.filter;
|
|
165
|
+
if (ds.groupedOptions) {
|
|
166
|
+
queryEntries.push(eventFilterToQueryEntry(filter, ds.groupedOptions));
|
|
167
|
+
}
|
|
168
|
+
else if (((_a = ds.options) === null || _a === void 0 ? void 0 : _a.address) || filter.topics) {
|
|
169
|
+
queryEntries.push(eventFilterToQueryEntry(filter, ds.options));
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
return [];
|
|
171
173
|
}
|
|
172
174
|
break;
|
|
173
175
|
}
|
|
@@ -326,7 +328,11 @@ let FetchService = class FetchService {
|
|
|
326
328
|
}
|
|
327
329
|
while (!this.isShutdown) {
|
|
328
330
|
startBlockHeight = getStartBlockHeight();
|
|
329
|
-
scaledBatchSize =
|
|
331
|
+
scaledBatchSize = this.blockDispatcher.smartBatchSize;
|
|
332
|
+
if (scaledBatchSize === 0) {
|
|
333
|
+
await (0, node_core_1.waitForBatchSize)(this.blockDispatcher.minimumHeapLimit);
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
330
336
|
const latestHeight = this.nodeConfig.unfinalizedBlocks
|
|
331
337
|
? this.latestBestHeight
|
|
332
338
|
: this.latestFinalizedHeight;
|
|
@@ -353,13 +359,13 @@ let FetchService = class FetchService {
|
|
|
353
359
|
.sort((a, b) => a - b);
|
|
354
360
|
if (batchBlocks.length === 0) {
|
|
355
361
|
// There we're no blocks in this query range, we can set a new height we're up to
|
|
356
|
-
this.blockDispatcher.enqueueBlocks([], Math.min(queryEndBlock - 1, dictionary._metadata.lastProcessedHeight));
|
|
362
|
+
await this.blockDispatcher.enqueueBlocks([], Math.min(queryEndBlock - 1, dictionary._metadata.lastProcessedHeight));
|
|
357
363
|
}
|
|
358
364
|
else {
|
|
359
365
|
const maxBlockSize = Math.min(batchBlocks.length, this.blockDispatcher.freeSize);
|
|
360
366
|
const enqueuingBlocks = batchBlocks.slice(0, maxBlockSize);
|
|
361
367
|
const cleanedBatchBlocks = this.filteredBlockBatch(enqueuingBlocks);
|
|
362
|
-
this.blockDispatcher.enqueueBlocks(cleanedBatchBlocks, this.getLatestBufferHeight(cleanedBatchBlocks, enqueuingBlocks));
|
|
368
|
+
await this.blockDispatcher.enqueueBlocks(cleanedBatchBlocks, this.getLatestBufferHeight(cleanedBatchBlocks, enqueuingBlocks));
|
|
363
369
|
}
|
|
364
370
|
continue; // skip nextBlockRange() way
|
|
365
371
|
}
|
|
@@ -371,16 +377,11 @@ let FetchService = class FetchService {
|
|
|
371
377
|
}
|
|
372
378
|
}
|
|
373
379
|
const endHeight = this.nextEndBlockHeight(startBlockHeight, scaledBatchSize);
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
else {
|
|
380
|
-
const enqueuingBlocks = (0, lodash_1.range)(startBlockHeight, endHeight + 1);
|
|
381
|
-
const cleanedBatchBlocks = this.filteredBlockBatch(enqueuingBlocks);
|
|
382
|
-
this.blockDispatcher.enqueueBlocks(cleanedBatchBlocks, this.getLatestBufferHeight(cleanedBatchBlocks, enqueuingBlocks));
|
|
383
|
-
}
|
|
380
|
+
const enqueuingBlocks = handlers.length && this.getModulos().length === handlers.length
|
|
381
|
+
? this.getEnqueuedModuloBlocks(startBlockHeight)
|
|
382
|
+
: (0, lodash_1.range)(startBlockHeight, endHeight + 1);
|
|
383
|
+
const cleanedBatchBlocks = this.filteredBlockBatch(enqueuingBlocks);
|
|
384
|
+
await this.blockDispatcher.enqueueBlocks(cleanedBatchBlocks, this.getLatestBufferHeight(cleanedBatchBlocks, enqueuingBlocks));
|
|
384
385
|
}
|
|
385
386
|
}
|
|
386
387
|
getLatestBufferHeight(cleanedBatchBlocks, rawBatchBlocks) {
|
|
@@ -455,13 +456,13 @@ __decorate([
|
|
|
455
456
|
__metadata("design:returntype", void 0)
|
|
456
457
|
], FetchService.prototype, "checkBatchScale", null);
|
|
457
458
|
__decorate([
|
|
458
|
-
(0, schedule_1.Interval)(BLOCK_TIME_VARIANCE
|
|
459
|
+
(0, schedule_1.Interval)(BLOCK_TIME_VARIANCE),
|
|
459
460
|
__metadata("design:type", Function),
|
|
460
461
|
__metadata("design:paramtypes", []),
|
|
461
462
|
__metadata("design:returntype", Promise)
|
|
462
463
|
], FetchService.prototype, "getFinalizedBlockHead", null);
|
|
463
464
|
__decorate([
|
|
464
|
-
(0, schedule_1.Interval)(BLOCK_TIME_VARIANCE
|
|
465
|
+
(0, schedule_1.Interval)(BLOCK_TIME_VARIANCE),
|
|
465
466
|
__metadata("design:type", Function),
|
|
466
467
|
__metadata("design:paramtypes", []),
|
|
467
468
|
__metadata("design:returntype", Promise)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.service.js","sourceRoot":"","sources":["../../src/indexer/fetch.service.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;;;;;;;AAEtC,2CAA2E;AAC3E,yDAAsD;AACtD,+CAA+D;AAC/D,4DAIgC;AAChC,gDAU0B;AAU1B,mCAAsE;AACtE,kEAA+E;AAC/E,+DAA0D;AAC1D,4CAAkE;AAElE,6DAAyD;AACzD,6DAAwD;AACxD,2EAAuE;AAEvE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,OAAO,CAAC,CAAC;AAClC,IAAI,mBAAmB,GAAG,IAAI,CAAC;AAC/B,MAAM,yBAAyB,GAAG,KAAK,CAAC;AACxC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AACpC,MAAM,kBAAkB,GAAG,C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Q,EAAC,qBAAqB,CAAC;;;;mDAS/B;AAGK;IADL,IAAA,mBAAQ,EAAC,mBAAmB,GAAG,IAAI,CAAC;;;;yDA0BpC;AAGK;IADL,IAAA,mBAAQ,EAAC,mBAAmB,GAAG,IAAI,CAAC;;;;oDAwBpC;AAzPU,YAAY;IADxB,IAAA,mBAAU,GAAE;IAcR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;IAC1B,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;qCAHP,sBAAU;QACV,sBAAU;QACe,iCAAe,UAEjC,sCAAiB;QAClB,qCAAgB;QACR,oDAAwB;QACpC,6BAAa;QACR,4BAAiB;GAnBnC,YAAY,CAigBxB;AAjgBY,oCAAY","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { Interval, SchedulerRegistry } from '@nestjs/schedule';\nimport {\n isCustomDs,\n EthereumHandlerKind,\n SubqlHandlerFilter,\n} from '@subql/common-ethereum';\nimport {\n ApiService,\n Dictionary,\n checkMemoryUsage,\n delay,\n getLogger,\n IndexerEvent,\n NodeConfig,\n transformBypassBlocks,\n cleanedBatchBlocks,\n} from '@subql/node-core';\nimport {\n DictionaryQueryEntry,\n ApiWrapper,\n EthereumLogFilter,\n EthereumTransactionFilter,\n SubqlEthereumProcessorOptions,\n DictionaryQueryCondition,\n} from '@subql/types-ethereum';\nimport { MetaData } from '@subql/utils';\nimport { range, sortBy, uniqBy, without, groupBy, add } from 'lodash';\nimport { SubqlProjectDs, SubqueryProject } from '../configure/SubqueryProject';\nimport { calcInterval } from '../ethereum/utils.ethereum';\nimport { eventToTopic, functionToSighash } from '../utils/string';\nimport { IBlockDispatcher } from './blockDispatcher';\nimport { DictionaryService } from './dictionary.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { UnfinalizedBlocksService } from './unfinalizedBlocks.service';\n\nconst logger = getLogger('fetch');\nlet BLOCK_TIME_VARIANCE = 5000;\nconst DICTIONARY_MAX_QUERY_SIZE = 10000;\nconst CHECK_MEMORY_INTERVAL = 60000;\nconst MINIMUM_BATCH_SIZE = 5;\nconst INTERVAL_PERCENT = 0.9;\nconst QUERY_ADDRESS_LIMIT = 50;\n\nfunction eventFilterToQueryEntry(\n filter: EthereumLogFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): DictionaryQueryEntry {\n const conditions = [];\n\n if (Array.isArray(dsOptions)) {\n const addresses = dsOptions.map((option) => option.address).filter(Boolean);\n\n if (addresses.length !== 0 && addresses.length <= QUERY_ADDRESS_LIMIT) {\n conditions.push({\n field: 'address',\n value: addresses,\n matcher: 'inInsensitive',\n });\n }\n } else {\n if (dsOptions?.address) {\n conditions.push({\n field: 'address',\n value: dsOptions.address.toLowerCase(),\n });\n }\n }\n if (filter.topics) {\n for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {\n const topic = filter.topics[i];\n if (!topic) {\n continue;\n }\n const field = `topics${i}`;\n conditions.push({ field, value: eventToTopic(topic) });\n }\n }\n return {\n entity: 'evmLogs',\n conditions,\n };\n}\n\nfunction callFilterToQueryEntry(\n filter: EthereumTransactionFilter,\n): DictionaryQueryEntry {\n const conditions = [];\n if (filter.from) {\n conditions.push({\n field: 'from',\n value: filter.from.toLowerCase(),\n });\n }\n if (filter.to) {\n conditions.push({\n field: 'to',\n value: filter.to.toLowerCase(),\n });\n }\n if (filter.function) {\n conditions.push({\n field: 'func',\n value: functionToSighash(filter.function),\n });\n }\n return {\n entity: 'evmTransactions',\n conditions,\n };\n}\n\n@Injectable()\nexport class FetchService implements OnApplicationShutdown {\n private latestBestHeight: number;\n private latestFinalizedHeight: number;\n private isShutdown = false;\n private batchSizeScale: number;\n private templateDynamicDatasouces: SubqlProjectDs[];\n private dictionaryGenesisMatches = true;\n private evmChainId: string;\n private bypassBlocks: number[] = [];\n\n constructor(\n private apiService: ApiService,\n private nodeConfig: NodeConfig,\n @Inject('ISubqueryProject') private project: SubqueryProject,\n @Inject('IBlockDispatcher') private blockDispatcher: IBlockDispatcher,\n private dictionaryService: DictionaryService,\n private dynamicDsService: DynamicDsService,\n private unfinalizedBlocksService: UnfinalizedBlocksService,\n private eventEmitter: EventEmitter2,\n private schedulerRegistry: SchedulerRegistry,\n ) {\n this.batchSizeScale = 1;\n }\n\n onApplicationShutdown(): void {\n this.isShutdown = true;\n }\n\n get api(): ApiWrapper {\n return this.apiService.api;\n }\n\n async syncDynamicDatascourcesFromMeta(): Promise<void> {\n this.templateDynamicDatasouces =\n await this.dynamicDsService.getDynamicDatasources();\n }\n\n buildDictionaryQueryEntries(startBlock: number): DictionaryQueryEntry[] {\n const queryEntries: DictionaryQueryEntry[] = [];\n\n type GroupedSubqlProjectDs = SubqlProjectDs & {\n groupedOptions?: SubqlEthereumProcessorOptions[];\n };\n\n const groupdDynamicDs: GroupedSubqlProjectDs[] = Object.values(\n groupBy(this.templateDynamicDatasouces, (ds) => ds.name),\n ).map((grouped: SubqlProjectDs[]) => {\n const options = grouped.map((ds) => ds.options);\n const ref = grouped[0];\n\n return {\n ...ref,\n groupedOptions: options,\n };\n });\n\n // Only run the ds that is equal or less than startBlock\n // sort array from lowest ds.startBlock to highest\n const filteredDs: GroupedSubqlProjectDs[] = this.project.dataSources\n .concat(groupdDynamicDs)\n .filter((ds) => ds.startBlock <= startBlock)\n .sort((a, b) => a.startBlock - b.startBlock);\n\n for (const ds of filteredDs) {\n for (const handler of ds.mapping.handlers) {\n let filterList: SubqlHandlerFilter[];\n filterList = [handler.filter];\n filterList = filterList.filter((f) => f);\n if (!filterList.length) return [];\n switch (handler.kind) {\n case EthereumHandlerKind.Block:\n return [];\n case EthereumHandlerKind.Call: {\n for (const filter of filterList as EthereumTransactionFilter[]) {\n if (\n filter.from !== undefined ||\n filter.to !== undefined ||\n filter.function\n ) {\n queryEntries.push(callFilterToQueryEntry(filter));\n } else {\n return [];\n }\n }\n break;\n }\n case EthereumHandlerKind.Event: {\n for (const filter of filterList as EthereumLogFilter[]) {\n if (ds.groupedOptions) {\n queryEntries.push(\n eventFilterToQueryEntry(filter, ds.groupedOptions),\n );\n } else if (ds.options?.address || filter.topics) {\n queryEntries.push(eventFilterToQueryEntry(filter, ds.options));\n } else {\n return [];\n }\n }\n break;\n }\n default:\n }\n }\n }\n\n return uniqBy(\n queryEntries,\n (item) =>\n `${item.entity}|${JSON.stringify(\n sortBy(item.conditions, (c) => c.field),\n )}`,\n );\n }\n\n updateDictionary(): void {\n this.dictionaryService.buildDictionaryEntryMap<SubqlProjectDs>(\n this.project.dataSources.concat(this.templateDynamicDatasouces),\n this.buildDictionaryQueryEntries.bind(this),\n );\n }\n\n private get useDictionary(): boolean {\n return (\n !!this.project.network.dictionary &&\n this.dictionaryGenesisMatches &&\n !!this.dictionaryService.getDictionaryQueryEntries(\n this.blockDispatcher.latestBufferedHeight ??\n Math.min(...this.project.dataSources.map((ds) => ds.startBlock)),\n ).length\n );\n }\n\n async init(startHeight: number): Promise<void> {\n if (this.project.network?.bypassBlocks !== undefined) {\n this.bypassBlocks = transformBypassBlocks(\n this.project.network.bypassBlocks,\n ).filter((blk) => blk >= startHeight);\n }\n if (this.api) {\n const CHAIN_INTERVAL = calcInterval(this.api) * INTERVAL_PERCENT;\n\n BLOCK_TIME_VARIANCE = Math.min(BLOCK_TIME_VARIANCE, CHAIN_INTERVAL);\n\n this.schedulerRegistry.addInterval(\n 'getLatestBlockHead',\n setInterval(() => void this.getBestBlockHead(), BLOCK_TIME_VARIANCE),\n );\n }\n await this.syncDynamicDatascourcesFromMeta();\n\n this.updateDictionary();\n this.eventEmitter.emit(IndexerEvent.UsingDictionary, {\n value: Number(this.useDictionary),\n });\n\n if (this.project.network.dictionary) {\n this.evmChainId = await this.dictionaryService.getEvmChainId();\n }\n\n await this.getFinalizedBlockHead();\n await this.getBestBlockHead();\n\n // Call metadata here, other network should align with this\n // For substrate, we might use the specVersion metadata in future if we have same error handling as in node-core\n const metadata = await this.dictionaryService.getMetadata();\n\n const validChecker = this.dictionaryValidation(metadata);\n\n if (validChecker) {\n this.dictionaryService.setDictionaryStartHeight(\n metadata._metadata.startHeight,\n );\n }\n\n await this.blockDispatcher.init(this.resetForNewDs.bind(this));\n void this.startLoop(startHeight);\n }\n\n getUseDictionary(): boolean {\n return this.useDictionary;\n }\n\n getLatestFinalizedHeight(): number {\n return this.latestFinalizedHeight;\n }\n\n @Interval(CHECK_MEMORY_INTERVAL)\n checkBatchScale(): void {\n if (this.nodeConfig['scale-batch-size']) {\n const scale = checkMemoryUsage(this.batchSizeScale, this.nodeConfig);\n\n if (this.batchSizeScale !== scale) {\n this.batchSizeScale = scale;\n }\n }\n }\n\n @Interval(BLOCK_TIME_VARIANCE * 1000)\n async getFinalizedBlockHead(): Promise<void> {\n if (!this.api) {\n logger.debug(`Skip fetch finalized block until API is ready`);\n return;\n }\n try {\n const currentFinalizedHeight = await this.api.getFinalizedBlockHeight();\n logger.debug(`finalized:${currentFinalizedHeight.toString()}`);\n const finalizedHeader = await this.api.getBlockByHeightOrHash(\n currentFinalizedHeight,\n );\n if (this.latestFinalizedHeight !== currentFinalizedHeight) {\n this.latestFinalizedHeight = currentFinalizedHeight;\n this.unfinalizedBlocksService.registerFinalizedBlock(finalizedHeader);\n if (!this.nodeConfig.unfinalizedBlocks) {\n if (!this.nodeConfig.unfinalizedBlocks) {\n this.eventEmitter.emit(IndexerEvent.BlockTarget, {\n height: this.latestFinalizedHeight,\n });\n }\n }\n }\n } catch (e) {\n logger.warn(e, `Having a problem when get finalized block`);\n }\n }\n\n @Interval(BLOCK_TIME_VARIANCE * 1000)\n async getBestBlockHead(): Promise<void> {\n if (!this.api) {\n logger.debug(`Skip fetch best block until API is ready`);\n return;\n }\n try {\n const currentBestHeight = await this.api.getBestBlockHeight();\n logger.debug(`best:${currentBestHeight.toString()}`);\n if (this.latestBestHeight !== currentBestHeight) {\n this.latestBestHeight = currentBestHeight;\n this.eventEmitter.emit(IndexerEvent.BlockBest, {\n height: this.latestBestHeight,\n });\n\n if (this.nodeConfig.unfinalizedBlocks) {\n this.eventEmitter.emit(IndexerEvent.BlockTarget, {\n height: this.latestBestHeight,\n });\n }\n }\n } catch (e) {\n logger.warn(e, `Having a problem when get best block`);\n }\n }\n private async startLoop(initBlockHeight: number): Promise<void> {\n await this.fillNextBlockBuffer(initBlockHeight);\n }\n\n getModulos(): number[] {\n const modulos: number[] = [];\n for (const ds of this.project.dataSources) {\n if (isCustomDs(ds)) {\n continue;\n }\n for (const handler of ds.mapping.handlers) {\n if (\n handler.kind === EthereumHandlerKind.Block &&\n handler.filter &&\n handler.filter.modulo\n ) {\n modulos.push(handler.filter.modulo);\n }\n }\n }\n return modulos;\n }\n\n getModuloBlocks(startHeight: number, endHeight: number): number[] {\n const modulos = this.getModulos();\n const moduloBlocks: number[] = [];\n for (let i = startHeight; i < endHeight; i++) {\n if (modulos.find((m) => i % m === 0)) {\n moduloBlocks.push(i);\n }\n }\n return moduloBlocks;\n }\n\n getEnqueuedModuloBlocks(startBlockHeight: number): number[] {\n return this.getModuloBlocks(\n startBlockHeight,\n this.nodeConfig.batchSize * Math.max(...this.getModulos()) +\n startBlockHeight,\n ).slice(0, this.nodeConfig.batchSize);\n }\n\n async fillNextBlockBuffer(initBlockHeight: number): Promise<void> {\n let startBlockHeight: number;\n let scaledBatchSize: number;\n const handlers = [].concat(\n ...this.project.dataSources.map((ds) => ds.mapping.handlers),\n );\n\n const getStartBlockHeight = (): number => {\n return this.blockDispatcher.latestBufferedHeight\n ? this.blockDispatcher.latestBufferedHeight + 1\n : initBlockHeight;\n };\n\n if (this.dictionaryService.startHeight > getStartBlockHeight()) {\n logger.warn(\n `Dictionary start height ${\n this.dictionaryService.startHeight\n } is beyond indexing height ${getStartBlockHeight()}, skipping dictionary for now`,\n );\n }\n\n while (!this.isShutdown) {\n startBlockHeight = getStartBlockHeight();\n\n scaledBatchSize = Math.max(\n Math.round(this.batchSizeScale * this.nodeConfig.batchSize),\n Math.min(MINIMUM_BATCH_SIZE, this.nodeConfig.batchSize * 3),\n );\n const latestHeight = this.nodeConfig.unfinalizedBlocks\n ? this.latestBestHeight\n : this.latestFinalizedHeight;\n\n if (\n this.blockDispatcher.freeSize < scaledBatchSize ||\n startBlockHeight > latestHeight\n ) {\n await delay(1);\n continue;\n }\n\n if (\n this.useDictionary &&\n startBlockHeight >= this.dictionaryService.startHeight\n ) {\n const queryEndBlock = startBlockHeight + DICTIONARY_MAX_QUERY_SIZE;\n const moduloBlocks = this.getModuloBlocks(\n startBlockHeight,\n queryEndBlock,\n );\n\n try {\n const dictionary =\n await this.dictionaryService.scopedDictionaryEntries(\n startBlockHeight,\n queryEndBlock,\n scaledBatchSize,\n );\n\n if (startBlockHeight !== getStartBlockHeight()) {\n logger.debug(\n `Queue was reset for new DS, discarding dictionary query result`,\n );\n continue;\n }\n\n if (\n dictionary &&\n this.dictionaryValidation(dictionary, startBlockHeight)\n ) {\n let { batchBlocks } = dictionary;\n\n batchBlocks = batchBlocks\n .concat(moduloBlocks)\n .sort((a, b) => a - b);\n if (batchBlocks.length === 0) {\n // There we're no blocks in this query range, we can set a new height we're up to\n this.blockDispatcher.enqueueBlocks(\n [],\n Math.min(\n queryEndBlock - 1,\n dictionary._metadata.lastProcessedHeight,\n ),\n );\n } else {\n const maxBlockSize = Math.min(\n batchBlocks.length,\n this.blockDispatcher.freeSize,\n );\n const enqueuingBlocks = batchBlocks.slice(0, maxBlockSize);\n const cleanedBatchBlocks =\n this.filteredBlockBatch(enqueuingBlocks);\n\n this.blockDispatcher.enqueueBlocks(\n cleanedBatchBlocks,\n this.getLatestBufferHeight(cleanedBatchBlocks, enqueuingBlocks),\n );\n }\n continue; // skip nextBlockRange() way\n }\n // else use this.nextBlockRange()\n } catch (e) {\n logger.debug(`Fetch dictionary stopped: ${e.message}`);\n this.eventEmitter.emit(IndexerEvent.SkipDictionary);\n }\n }\n\n const endHeight = this.nextEndBlockHeight(\n startBlockHeight,\n scaledBatchSize,\n );\n\n if (handlers.length && this.getModulos().length === handlers.length) {\n const enqueuingBlocks = this.getEnqueuedModuloBlocks(startBlockHeight);\n const cleanedBatchBlocks = this.filteredBlockBatch(enqueuingBlocks);\n this.blockDispatcher.enqueueBlocks(\n cleanedBatchBlocks,\n this.getLatestBufferHeight(cleanedBatchBlocks, enqueuingBlocks),\n );\n } else {\n const enqueuingBlocks = range(startBlockHeight, endHeight + 1);\n const cleanedBatchBlocks = this.filteredBlockBatch(enqueuingBlocks);\n this.blockDispatcher.enqueueBlocks(\n cleanedBatchBlocks,\n this.getLatestBufferHeight(cleanedBatchBlocks, enqueuingBlocks),\n );\n }\n }\n }\n\n private getLatestBufferHeight(\n cleanedBatchBlocks: number[],\n rawBatchBlocks: number[],\n ): number {\n return Math.max(...cleanedBatchBlocks, ...rawBatchBlocks);\n }\n private filteredBlockBatch(currentBatchBlocks: number[]): number[] {\n if (!this.bypassBlocks.length || !currentBatchBlocks) {\n return currentBatchBlocks;\n }\n\n const cleanedBatch = cleanedBatchBlocks(\n this.bypassBlocks,\n currentBatchBlocks,\n );\n\n const pollutedBlocks = this.bypassBlocks.filter(\n (b) => b < Math.max(...currentBatchBlocks),\n );\n if (pollutedBlocks.length) {\n logger.info(`Bypassing blocks: ${pollutedBlocks}`);\n }\n this.bypassBlocks = without(this.bypassBlocks, ...pollutedBlocks);\n return cleanedBatch;\n }\n\n private nextEndBlockHeight(\n startBlockHeight: number,\n scaledBatchSize: number,\n ): number {\n let endBlockHeight = startBlockHeight + scaledBatchSize - 1;\n\n if (endBlockHeight > this.latestFinalizedHeight) {\n if (this.nodeConfig.unfinalizedBlocks) {\n if (endBlockHeight >= this.latestBestHeight) {\n endBlockHeight = this.latestBestHeight;\n }\n } else {\n endBlockHeight = this.latestFinalizedHeight;\n }\n }\n return endBlockHeight;\n }\n\n private dictionaryValidation(\n dictionary: { _metadata: MetaData },\n startBlockHeight?: number,\n ): boolean {\n if (dictionary !== undefined) {\n const { _metadata: metaData } = dictionary;\n\n if (\n metaData.genesisHash !== this.api.getGenesisHash() &&\n this.evmChainId !== this.api.getChainId().toString()\n ) {\n logger.error(\n 'The dictionary that you have specified does not match the chain you are indexing, it will be ignored. Please update your project manifest to reference the correct dictionary',\n );\n this.dictionaryGenesisMatches = false;\n this.eventEmitter.emit(IndexerEvent.UsingDictionary, {\n value: Number(this.useDictionary),\n });\n this.eventEmitter.emit(IndexerEvent.SkipDictionary);\n return false;\n }\n\n if (startBlockHeight !== undefined) {\n if (metaData.lastProcessedHeight < startBlockHeight) {\n logger.warn(\n `Dictionary indexed block is behind current indexing block height`,\n );\n this.eventEmitter.emit(IndexerEvent.SkipDictionary);\n return false;\n }\n }\n return true;\n }\n return false;\n }\n\n async resetForNewDs(blockHeight: number): Promise<void> {\n await this.syncDynamicDatascourcesFromMeta();\n this.dynamicDsService.deleteTempDsRecords(blockHeight);\n this.updateDictionary();\n this.blockDispatcher.flushQueue(blockHeight);\n }\n\n async resetForIncorrectBestBlock(blockHeight: number): Promise<void> {\n await this.syncDynamicDatascourcesFromMeta();\n this.updateDictionary();\n this.blockDispatcher.flushQueue(blockHeight);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fetch.service.js","sourceRoot":"","sources":["../../src/indexer/fetch.service.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;;;;;;;AAEtC,2CAA2E;AAC3E,yDAAsD;AACtD,+CAA+D;AAE/D,4DAMgC;AAChC,gDAU0B;AAO1B,mCAAiE;AACjE,kEAA+E;AAC/E,+DAA0D;AAC1D,4CAAkE;AAElE,6DAAyD;AACzD,6DAAwD;AACxD,2EAAuE;AAEvE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,OAAO,CAAC,CAAC;AAClC,IAAI,mBAAmB,GAAG,IAAI,CAAC;AAC/B,MAAM,yBAAyB,GAAG,KAAK,CAAC;AACxC,MAAM,qBAAqB,GAA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,sBAAU;QACV,sBAAU;QACe,iCAAe,UAGjC,sCAAiB;QAClB,qCAAgB;QACR,oDAAwB;QACpC,6BAAa;QACR,4BAAiB;GApBnC,YAAY,CA4fxB;AA5fY,oCAAY","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { Interval, SchedulerRegistry } from '@nestjs/schedule';\n\nimport {\n isCustomDs,\n EthereumHandlerKind,\n EthereumLogFilter,\n SubqlEthereumProcessorOptions,\n EthereumTransactionFilter,\n} from '@subql/common-ethereum';\nimport {\n ApiService,\n cleanedBatchBlocks,\n checkMemoryUsage,\n delay,\n getLogger,\n IndexerEvent,\n NodeConfig,\n transformBypassBlocks,\n waitForBatchSize,\n} from '@subql/node-core';\nimport {\n ApiWrapper,\n DictionaryQueryCondition,\n DictionaryQueryEntry,\n} from '@subql/types-ethereum';\nimport { MetaData } from '@subql/utils';\nimport { groupBy, range, sortBy, uniqBy, without } from 'lodash';\nimport { SubqlProjectDs, SubqueryProject } from '../configure/SubqueryProject';\nimport { calcInterval } from '../ethereum/utils.ethereum';\nimport { eventToTopic, functionToSighash } from '../utils/string';\nimport { IEthereumBlockDispatcher } from './blockDispatcher';\nimport { DictionaryService } from './dictionary.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { UnfinalizedBlocksService } from './unfinalizedBlocks.service';\n\nconst logger = getLogger('fetch');\nlet BLOCK_TIME_VARIANCE = 5000;\nconst DICTIONARY_MAX_QUERY_SIZE = 10000;\nconst CHECK_MEMORY_INTERVAL = 60000;\nconst MINIMUM_BATCH_SIZE = 5;\nconst INTERVAL_PERCENT = 0.9;\nconst QUERY_ADDRESS_LIMIT = 50;\n\nfunction eventFilterToQueryEntry(\n filter: EthereumLogFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): DictionaryQueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n\n if (Array.isArray(dsOptions)) {\n const addresses = dsOptions.map((option) => option.address).filter(Boolean);\n\n if (addresses.length !== 0 && addresses.length <= QUERY_ADDRESS_LIMIT) {\n conditions.push({\n field: 'address',\n value: addresses,\n matcher: 'inInsensitive',\n });\n }\n } else {\n if (dsOptions?.address) {\n conditions.push({\n field: 'address',\n value: dsOptions.address.toLowerCase(),\n // matcher: 'equals',\n });\n }\n }\n if (filter.topics) {\n for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {\n const topic = filter.topics[i];\n if (!topic) {\n continue;\n }\n const field = `topics${i}`;\n conditions.push({\n field,\n value: eventToTopic(topic),\n matcher: 'equalTo',\n });\n }\n }\n return {\n entity: 'evmLogs',\n conditions,\n };\n}\n\nfunction callFilterToQueryEntry(\n filter: EthereumTransactionFilter,\n): DictionaryQueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n if (filter.from) {\n conditions.push({\n field: 'from',\n value: filter.from.toLowerCase(),\n });\n }\n if (filter.to) {\n conditions.push({\n field: 'to',\n value: filter.to.toLowerCase(),\n });\n }\n if (filter.function) {\n conditions.push({\n field: 'func',\n value: functionToSighash(filter.function),\n matcher: 'equalTo',\n });\n }\n return {\n entity: 'evmTransactions',\n conditions,\n };\n}\n\n@Injectable()\nexport class FetchService implements OnApplicationShutdown {\n private latestBestHeight: number;\n private latestFinalizedHeight: number;\n private isShutdown = false;\n private batchSizeScale: number;\n private templateDynamicDatasouces: SubqlProjectDs[];\n private dictionaryGenesisMatches = true;\n private evmChainId: string;\n private bypassBlocks: number[] = [];\n\n constructor(\n private apiService: ApiService,\n private nodeConfig: NodeConfig,\n @Inject('ISubqueryProject') private project: SubqueryProject,\n @Inject('IBlockDispatcher')\n private blockDispatcher: IEthereumBlockDispatcher,\n private dictionaryService: DictionaryService,\n private dynamicDsService: DynamicDsService,\n private unfinalizedBlocksService: UnfinalizedBlocksService,\n private eventEmitter: EventEmitter2,\n private schedulerRegistry: SchedulerRegistry,\n ) {\n this.batchSizeScale = 1;\n }\n\n onApplicationShutdown(): void {\n this.isShutdown = true;\n }\n\n get api(): ApiWrapper {\n return this.apiService.api;\n }\n\n async syncDynamicDatascourcesFromMeta(): Promise<void> {\n this.templateDynamicDatasouces =\n await this.dynamicDsService.getDynamicDatasources();\n }\n\n buildDictionaryQueryEntries(startBlock: number): DictionaryQueryEntry[] {\n const queryEntries: DictionaryQueryEntry[] = [];\n\n type GroupedSubqlProjectDs = SubqlProjectDs & {\n groupedOptions?: SubqlEthereumProcessorOptions[];\n };\n\n const groupdDynamicDs: GroupedSubqlProjectDs[] = Object.values(\n groupBy(this.templateDynamicDatasouces, (ds) => ds.name),\n ).map((grouped: SubqlProjectDs[]) => {\n const options = grouped.map((ds) => ds.options);\n const ref = grouped[0];\n\n return {\n ...ref,\n groupedOptions: options,\n };\n });\n\n // Only run the ds that is equal or less than startBlock\n // sort array from lowest ds.startBlock to highest\n const filteredDs: GroupedSubqlProjectDs[] = this.project.dataSources\n .concat(groupdDynamicDs)\n .filter((ds) => ds.startBlock <= startBlock)\n .sort((a, b) => a.startBlock - b.startBlock);\n\n for (const ds of filteredDs) {\n for (const handler of ds.mapping.handlers) {\n // No filters, cant use dictionary\n if (!handler.filter) return [];\n\n switch (handler.kind) {\n case EthereumHandlerKind.Block:\n return [];\n case EthereumHandlerKind.Call: {\n const filter = handler.filter as EthereumTransactionFilter;\n if (\n filter.from !== undefined ||\n filter.to !== undefined ||\n filter.function\n ) {\n queryEntries.push(callFilterToQueryEntry(filter));\n } else {\n return [];\n }\n break;\n }\n case EthereumHandlerKind.Event: {\n const filter = handler.filter as EthereumLogFilter;\n if (ds.groupedOptions) {\n queryEntries.push(\n eventFilterToQueryEntry(filter, ds.groupedOptions),\n );\n } else if (ds.options?.address || filter.topics) {\n queryEntries.push(eventFilterToQueryEntry(filter, ds.options));\n } else {\n return [];\n }\n break;\n }\n default:\n }\n }\n }\n\n return uniqBy(\n queryEntries,\n (item) =>\n `${item.entity}|${JSON.stringify(\n sortBy(item.conditions, (c) => c.field),\n )}`,\n );\n }\n\n updateDictionary(): void {\n this.dictionaryService.buildDictionaryEntryMap<SubqlProjectDs>(\n this.project.dataSources.concat(this.templateDynamicDatasouces),\n this.buildDictionaryQueryEntries.bind(this),\n );\n }\n\n private get useDictionary(): boolean {\n return (\n !!this.project.network.dictionary &&\n this.dictionaryGenesisMatches &&\n !!this.dictionaryService.getDictionaryQueryEntries(\n this.blockDispatcher.latestBufferedHeight ??\n Math.min(...this.project.dataSources.map((ds) => ds.startBlock)),\n ).length\n );\n }\n\n async init(startHeight: number): Promise<void> {\n if (this.project.network?.bypassBlocks !== undefined) {\n this.bypassBlocks = transformBypassBlocks(\n this.project.network.bypassBlocks,\n ).filter((blk) => blk >= startHeight);\n }\n if (this.api) {\n const CHAIN_INTERVAL = calcInterval(this.api) * INTERVAL_PERCENT;\n\n BLOCK_TIME_VARIANCE = Math.min(BLOCK_TIME_VARIANCE, CHAIN_INTERVAL);\n\n this.schedulerRegistry.addInterval(\n 'getLatestBlockHead',\n setInterval(() => void this.getBestBlockHead(), BLOCK_TIME_VARIANCE),\n );\n }\n await this.syncDynamicDatascourcesFromMeta();\n\n this.updateDictionary();\n this.eventEmitter.emit(IndexerEvent.UsingDictionary, {\n value: Number(this.useDictionary),\n });\n\n if (this.project.network.dictionary) {\n this.evmChainId = await this.dictionaryService.getEvmChainId();\n }\n\n await this.getFinalizedBlockHead();\n await this.getBestBlockHead();\n\n // Call metadata here, other network should align with this\n // For substrate, we might use the specVersion metadata in future if we have same error handling as in node-core\n const metadata = await this.dictionaryService.getMetadata();\n\n const validChecker = this.dictionaryValidation(metadata);\n\n if (validChecker) {\n this.dictionaryService.setDictionaryStartHeight(\n metadata._metadata.startHeight,\n );\n }\n\n await this.blockDispatcher.init(this.resetForNewDs.bind(this));\n void this.startLoop(startHeight);\n }\n\n getUseDictionary(): boolean {\n return this.useDictionary;\n }\n\n getLatestFinalizedHeight(): number {\n return this.latestFinalizedHeight;\n }\n\n @Interval(CHECK_MEMORY_INTERVAL)\n checkBatchScale(): void {\n if (this.nodeConfig['scale-batch-size']) {\n const scale = checkMemoryUsage(this.batchSizeScale, this.nodeConfig);\n\n if (this.batchSizeScale !== scale) {\n this.batchSizeScale = scale;\n }\n }\n }\n\n @Interval(BLOCK_TIME_VARIANCE)\n async getFinalizedBlockHead(): Promise<void> {\n if (!this.api) {\n logger.debug(`Skip fetch finalized block until API is ready`);\n return;\n }\n try {\n const currentFinalizedHeight = await this.api.getFinalizedBlockHeight();\n logger.debug(`finalized:${currentFinalizedHeight.toString()}`);\n const finalizedHeader = await this.api.getBlockByHeightOrHash(\n currentFinalizedHeight,\n );\n if (this.latestFinalizedHeight !== currentFinalizedHeight) {\n this.latestFinalizedHeight = currentFinalizedHeight;\n this.unfinalizedBlocksService.registerFinalizedBlock(finalizedHeader);\n if (!this.nodeConfig.unfinalizedBlocks) {\n if (!this.nodeConfig.unfinalizedBlocks) {\n this.eventEmitter.emit(IndexerEvent.BlockTarget, {\n height: this.latestFinalizedHeight,\n });\n }\n }\n }\n } catch (e) {\n logger.warn(e, `Having a problem when get finalized block`);\n }\n }\n\n @Interval(BLOCK_TIME_VARIANCE)\n async getBestBlockHead(): Promise<void> {\n if (!this.api) {\n logger.debug(`Skip fetch best block until API is ready`);\n return;\n }\n try {\n const currentBestHeight = await this.api.getBestBlockHeight();\n logger.debug(`best:${currentBestHeight.toString()}`);\n if (this.latestBestHeight !== currentBestHeight) {\n this.latestBestHeight = currentBestHeight;\n this.eventEmitter.emit(IndexerEvent.BlockBest, {\n height: this.latestBestHeight,\n });\n\n if (this.nodeConfig.unfinalizedBlocks) {\n this.eventEmitter.emit(IndexerEvent.BlockTarget, {\n height: this.latestBestHeight,\n });\n }\n }\n } catch (e) {\n logger.warn(e, `Having a problem when get best block`);\n }\n }\n private async startLoop(initBlockHeight: number): Promise<void> {\n await this.fillNextBlockBuffer(initBlockHeight);\n }\n\n getModulos(): number[] {\n const modulos: number[] = [];\n for (const ds of this.project.dataSources) {\n if (isCustomDs(ds)) {\n continue;\n }\n for (const handler of ds.mapping.handlers) {\n if (\n handler.kind === EthereumHandlerKind.Block &&\n handler.filter &&\n handler.filter.modulo\n ) {\n modulos.push(handler.filter.modulo);\n }\n }\n }\n return modulos;\n }\n\n getModuloBlocks(startHeight: number, endHeight: number): number[] {\n const modulos = this.getModulos();\n const moduloBlocks: number[] = [];\n for (let i = startHeight; i < endHeight; i++) {\n if (modulos.find((m) => i % m === 0)) {\n moduloBlocks.push(i);\n }\n }\n return moduloBlocks;\n }\n\n getEnqueuedModuloBlocks(startBlockHeight: number): number[] {\n return this.getModuloBlocks(\n startBlockHeight,\n this.nodeConfig.batchSize * Math.max(...this.getModulos()) +\n startBlockHeight,\n ).slice(0, this.nodeConfig.batchSize);\n }\n\n async fillNextBlockBuffer(initBlockHeight: number): Promise<void> {\n let startBlockHeight: number;\n let scaledBatchSize: number;\n const handlers = [].concat(\n ...this.project.dataSources.map((ds) => ds.mapping.handlers),\n );\n\n const getStartBlockHeight = (): number => {\n return this.blockDispatcher.latestBufferedHeight\n ? this.blockDispatcher.latestBufferedHeight + 1\n : initBlockHeight;\n };\n\n if (this.dictionaryService.startHeight > getStartBlockHeight()) {\n logger.warn(\n `Dictionary start height ${\n this.dictionaryService.startHeight\n } is beyond indexing height ${getStartBlockHeight()}, skipping dictionary for now`,\n );\n }\n\n while (!this.isShutdown) {\n startBlockHeight = getStartBlockHeight();\n\n scaledBatchSize = this.blockDispatcher.smartBatchSize;\n\n if (scaledBatchSize === 0) {\n await waitForBatchSize(this.blockDispatcher.minimumHeapLimit);\n continue;\n }\n\n const latestHeight = this.nodeConfig.unfinalizedBlocks\n ? this.latestBestHeight\n : this.latestFinalizedHeight;\n\n if (\n this.blockDispatcher.freeSize < scaledBatchSize ||\n startBlockHeight > latestHeight\n ) {\n await delay(1);\n continue;\n }\n\n if (\n this.useDictionary &&\n startBlockHeight >= this.dictionaryService.startHeight\n ) {\n const queryEndBlock = startBlockHeight + DICTIONARY_MAX_QUERY_SIZE;\n const moduloBlocks = this.getModuloBlocks(\n startBlockHeight,\n queryEndBlock,\n );\n\n try {\n const dictionary =\n await this.dictionaryService.scopedDictionaryEntries(\n startBlockHeight,\n queryEndBlock,\n scaledBatchSize,\n );\n\n if (startBlockHeight !== getStartBlockHeight()) {\n logger.debug(\n `Queue was reset for new DS, discarding dictionary query result`,\n );\n continue;\n }\n\n if (\n dictionary &&\n this.dictionaryValidation(dictionary, startBlockHeight)\n ) {\n let { batchBlocks } = dictionary;\n\n batchBlocks = batchBlocks\n .concat(moduloBlocks)\n .sort((a, b) => a - b);\n if (batchBlocks.length === 0) {\n // There we're no blocks in this query range, we can set a new height we're up to\n await this.blockDispatcher.enqueueBlocks(\n [],\n Math.min(\n queryEndBlock - 1,\n dictionary._metadata.lastProcessedHeight,\n ),\n );\n } else {\n const maxBlockSize = Math.min(\n batchBlocks.length,\n this.blockDispatcher.freeSize,\n );\n const enqueuingBlocks = batchBlocks.slice(0, maxBlockSize);\n const cleanedBatchBlocks =\n this.filteredBlockBatch(enqueuingBlocks);\n await this.blockDispatcher.enqueueBlocks(\n cleanedBatchBlocks,\n this.getLatestBufferHeight(cleanedBatchBlocks, enqueuingBlocks),\n );\n }\n continue; // skip nextBlockRange() way\n }\n // else use this.nextBlockRange()\n } catch (e) {\n logger.debug(`Fetch dictionary stopped: ${e.message}`);\n this.eventEmitter.emit(IndexerEvent.SkipDictionary);\n }\n }\n\n const endHeight = this.nextEndBlockHeight(\n startBlockHeight,\n scaledBatchSize,\n );\n\n const enqueuingBlocks =\n handlers.length && this.getModulos().length === handlers.length\n ? this.getEnqueuedModuloBlocks(startBlockHeight)\n : range(startBlockHeight, endHeight + 1);\n\n const cleanedBatchBlocks = this.filteredBlockBatch(enqueuingBlocks);\n await this.blockDispatcher.enqueueBlocks(\n cleanedBatchBlocks,\n this.getLatestBufferHeight(cleanedBatchBlocks, enqueuingBlocks),\n );\n }\n }\n\n private getLatestBufferHeight(\n cleanedBatchBlocks: number[],\n rawBatchBlocks: number[],\n ): number {\n return Math.max(...cleanedBatchBlocks, ...rawBatchBlocks);\n }\n private filteredBlockBatch(currentBatchBlocks: number[]): number[] {\n if (!this.bypassBlocks.length || !currentBatchBlocks) {\n return currentBatchBlocks;\n }\n\n const cleanedBatch = cleanedBatchBlocks(\n this.bypassBlocks,\n currentBatchBlocks,\n );\n\n const pollutedBlocks = this.bypassBlocks.filter(\n (b) => b < Math.max(...currentBatchBlocks),\n );\n if (pollutedBlocks.length) {\n logger.info(`Bypassing blocks: ${pollutedBlocks}`);\n }\n this.bypassBlocks = without(this.bypassBlocks, ...pollutedBlocks);\n return cleanedBatch;\n }\n\n private nextEndBlockHeight(\n startBlockHeight: number,\n scaledBatchSize: number,\n ): number {\n let endBlockHeight = startBlockHeight + scaledBatchSize - 1;\n\n if (endBlockHeight > this.latestFinalizedHeight) {\n if (this.nodeConfig.unfinalizedBlocks) {\n if (endBlockHeight >= this.latestBestHeight) {\n endBlockHeight = this.latestBestHeight;\n }\n } else {\n endBlockHeight = this.latestFinalizedHeight;\n }\n }\n return endBlockHeight;\n }\n\n private dictionaryValidation(\n dictionary: { _metadata: MetaData },\n startBlockHeight?: number,\n ): boolean {\n if (dictionary !== undefined) {\n const { _metadata: metaData } = dictionary;\n\n if (\n metaData.genesisHash !== this.api.getGenesisHash() &&\n this.evmChainId !== this.api.getChainId().toString()\n ) {\n logger.error(\n 'The dictionary that you have specified does not match the chain you are indexing, it will be ignored. Please update your project manifest to reference the correct dictionary',\n );\n this.dictionaryGenesisMatches = false;\n this.eventEmitter.emit(IndexerEvent.UsingDictionary, {\n value: Number(this.useDictionary),\n });\n this.eventEmitter.emit(IndexerEvent.SkipDictionary);\n return false;\n }\n\n if (startBlockHeight !== undefined) {\n if (metaData.lastProcessedHeight < startBlockHeight) {\n logger.warn(\n `Dictionary indexed block is behind current indexing block height`,\n );\n this.eventEmitter.emit(IndexerEvent.SkipDictionary);\n return false;\n }\n }\n return true;\n }\n return false;\n }\n\n async resetForNewDs(blockHeight: number): Promise<void> {\n await this.syncDynamicDatascourcesFromMeta();\n this.dynamicDsService.deleteTempDsRecords(blockHeight);\n this.updateDictionary();\n this.blockDispatcher.flushQueue(blockHeight);\n }\n\n async resetForIncorrectBestBlock(blockHeight: number): Promise<void> {\n await this.syncDynamicDatascourcesFromMeta();\n this.updateDictionary();\n this.blockDispatcher.flushQueue(blockHeight);\n }\n}\n"]}
|
|
@@ -1,38 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NodeConfig, ProcessBlockResponse, ApiService } from '@subql/node-core';
|
|
2
2
|
import { EthereumBlockWrapper } from '@subql/types-ethereum';
|
|
3
|
-
import { Sequelize } from 'sequelize';
|
|
4
|
-
import { SubqueryProject } from '../configure/SubqueryProject';
|
|
5
3
|
import { DsProcessorService } from './ds-processor.service';
|
|
6
4
|
import { DynamicDsService } from './dynamic-ds.service';
|
|
7
5
|
import { ProjectService } from './project.service';
|
|
8
6
|
import { SandboxService } from './sandbox.service';
|
|
9
7
|
import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
|
|
10
8
|
export declare class IndexerManager {
|
|
11
|
-
private storeService;
|
|
12
9
|
private apiService;
|
|
13
|
-
private poiService;
|
|
14
|
-
private sequelize;
|
|
15
|
-
private readonly project;
|
|
16
10
|
private nodeConfig;
|
|
17
11
|
private sandboxService;
|
|
18
12
|
private dynamicDsService;
|
|
19
13
|
private unfinalizedBlocksService;
|
|
20
14
|
private dsProcessorService;
|
|
21
15
|
private projectService;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
constructor(storeService: StoreService, apiService: ApiService, poiService: PoiService, sequelize: Sequelize, project: SubqueryProject, nodeConfig: NodeConfig, sandboxService: SandboxService, dynamicDsService: DynamicDsService, unfinalizedBlocksService: UnfinalizedBlocksService, dsProcessorService: DsProcessorService, projectService: ProjectService);
|
|
25
|
-
indexBlock(blockContent: EthereumBlockWrapper): Promise<{
|
|
26
|
-
dynamicDsCreated: boolean;
|
|
27
|
-
operationHash: Uint8Array;
|
|
28
|
-
reindexBlockHeight: null;
|
|
29
|
-
}>;
|
|
16
|
+
constructor(apiService: ApiService, nodeConfig: NodeConfig, sandboxService: SandboxService, dynamicDsService: DynamicDsService, unfinalizedBlocksService: UnfinalizedBlocksService, dsProcessorService: DsProcessorService, projectService: ProjectService);
|
|
17
|
+
indexBlock(blockContent: EthereumBlockWrapper): Promise<ProcessBlockResponse>;
|
|
30
18
|
start(): Promise<void>;
|
|
31
19
|
private processUnfinalizedBlocks;
|
|
32
|
-
private
|
|
20
|
+
private assertDataSources;
|
|
33
21
|
private indexBlockData;
|
|
34
22
|
private indexBlockContent;
|
|
35
|
-
private
|
|
23
|
+
private indexTransaction;
|
|
36
24
|
private indexEvent;
|
|
37
25
|
private indexData;
|
|
38
26
|
private filterCustomDsHandlers;
|
|
@@ -16,11 +16,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.IndexerManager = void 0;
|
|
18
18
|
const common_1 = require("@nestjs/common");
|
|
19
|
-
const util_1 = require("@polkadot/util");
|
|
20
19
|
const common_ethereum_1 = require("@subql/common-ethereum");
|
|
21
20
|
const node_core_1 = require("@subql/node-core");
|
|
22
|
-
const sequelize_1 = require("sequelize");
|
|
23
|
-
const SubqueryProject_1 = require("../configure/SubqueryProject");
|
|
24
21
|
const block_ethereum_1 = require("../ethereum/block.ethereum");
|
|
25
22
|
const yargs_1 = require("../yargs");
|
|
26
23
|
const ds_processor_service_1 = require("./ds-processor.service");
|
|
@@ -28,15 +25,10 @@ const dynamic_ds_service_1 = require("./dynamic-ds.service");
|
|
|
28
25
|
const project_service_1 = require("./project.service");
|
|
29
26
|
const sandbox_service_1 = require("./sandbox.service");
|
|
30
27
|
const unfinalizedBlocks_service_1 = require("./unfinalizedBlocks.service");
|
|
31
|
-
const NULL_MERKEL_ROOT = (0, util_1.hexToU8a)('0x00');
|
|
32
28
|
const logger = (0, node_core_1.getLogger)('indexer');
|
|
33
29
|
let IndexerManager = class IndexerManager {
|
|
34
|
-
constructor(
|
|
35
|
-
this.storeService = storeService;
|
|
30
|
+
constructor(apiService, nodeConfig, sandboxService, dynamicDsService, unfinalizedBlocksService, dsProcessorService, projectService) {
|
|
36
31
|
this.apiService = apiService;
|
|
37
|
-
this.poiService = poiService;
|
|
38
|
-
this.sequelize = sequelize;
|
|
39
|
-
this.project = project;
|
|
40
32
|
this.nodeConfig = nodeConfig;
|
|
41
33
|
this.sandboxService = sandboxService;
|
|
42
34
|
this.dynamicDsService = dynamicDsService;
|
|
@@ -44,65 +36,38 @@ let IndexerManager = class IndexerManager {
|
|
|
44
36
|
this.dsProcessorService = dsProcessorService;
|
|
45
37
|
this.projectService = projectService;
|
|
46
38
|
logger.info('indexer manager start');
|
|
47
|
-
this.api = this.apiService.api;
|
|
48
39
|
}
|
|
49
40
|
async indexBlock(blockContent) {
|
|
50
41
|
const { block, blockHeight } = blockContent;
|
|
51
42
|
let dynamicDsCreated = false;
|
|
52
43
|
let reindexBlockHeight = null;
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
this.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this.filteredDataSources = this.filterDataSources(blockHeight);
|
|
60
|
-
const datasources = this.filteredDataSources.concat(...(await this.dynamicDsService.getDynamicDatasources()));
|
|
61
|
-
reindexBlockHeight = await this.processUnfinalizedBlocks(block, tx);
|
|
44
|
+
const datasources = await this.projectService.getAllDataSources(blockHeight);
|
|
45
|
+
// Check that we have valid datasources
|
|
46
|
+
this.assertDataSources(datasources, blockHeight);
|
|
47
|
+
reindexBlockHeight = await this.processUnfinalizedBlocks(block);
|
|
48
|
+
// Only index block if we're not going to reindex
|
|
49
|
+
if (!reindexBlockHeight) {
|
|
62
50
|
await this.indexBlockData(blockContent, datasources,
|
|
63
51
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
64
52
|
async (ds) => {
|
|
65
|
-
const vm = this.sandboxService.getDsProcessorWrapper(ds, this.api, blockContent);
|
|
53
|
+
const vm = this.sandboxService.getDsProcessorWrapper(ds, this.apiService.api, blockContent);
|
|
66
54
|
// Inject function to create ds into vm
|
|
67
55
|
vm.freeze(async (templateName, args) => {
|
|
68
56
|
const newDs = await this.dynamicDsService.createDynamicDatasource({
|
|
69
57
|
templateName,
|
|
70
58
|
args,
|
|
71
59
|
startBlock: blockHeight,
|
|
72
|
-
}
|
|
60
|
+
});
|
|
73
61
|
// Push the newly created dynamic ds to be processed this block on any future extrinsics/events
|
|
74
62
|
datasources.push(newDs);
|
|
75
63
|
dynamicDsCreated = true;
|
|
76
64
|
}, 'createDynamicDatasource');
|
|
77
65
|
return vm;
|
|
78
66
|
});
|
|
79
|
-
await this.storeService.setMetadataBatch([
|
|
80
|
-
{ key: 'lastProcessedHeight', value: blockHeight },
|
|
81
|
-
{ key: 'lastProcessedTimestamp', value: Date.now() },
|
|
82
|
-
], { transaction: tx });
|
|
83
|
-
// Db Metadata increase BlockCount, in memory ref to block-dispatcher _processedBlockCount
|
|
84
|
-
await this.storeService.incrementJsonbCount('processedBlockCount', tx);
|
|
85
|
-
// Need calculate operationHash to ensure correct offset insert all time
|
|
86
|
-
operationHash = this.storeService.getOperationMerkleRoot();
|
|
87
|
-
if (this.nodeConfig.proofOfIndex) {
|
|
88
|
-
//check if operation is null, then poi will not be inserted
|
|
89
|
-
if (!(0, util_1.u8aEq)(operationHash, NULL_MERKEL_ROOT)) {
|
|
90
|
-
const poiBlock = node_core_1.PoiBlock.create(blockHeight, blockContent.block.hash, operationHash, await this.poiService.getLatestPoiBlockHash(), this.project.id);
|
|
91
|
-
poiBlockHash = poiBlock.hash;
|
|
92
|
-
await this.storeService.setPoi(poiBlock, { transaction: tx });
|
|
93
|
-
this.poiService.setLatestPoiBlockHash(poiBlockHash);
|
|
94
|
-
await this.storeService.setMetadataBatch([{ key: 'lastPoiHeight', value: blockHeight }], { transaction: tx });
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
catch (e) {
|
|
99
|
-
await tx.rollback();
|
|
100
|
-
throw e;
|
|
101
67
|
}
|
|
102
|
-
await tx.commit();
|
|
103
68
|
return {
|
|
104
69
|
dynamicDsCreated,
|
|
105
|
-
|
|
70
|
+
blockHash: block.hash,
|
|
106
71
|
reindexBlockHeight,
|
|
107
72
|
};
|
|
108
73
|
}
|
|
@@ -110,31 +75,25 @@ let IndexerManager = class IndexerManager {
|
|
|
110
75
|
await this.projectService.init();
|
|
111
76
|
logger.info('indexer manager started');
|
|
112
77
|
}
|
|
113
|
-
async processUnfinalizedBlocks(block
|
|
78
|
+
async processUnfinalizedBlocks(block) {
|
|
114
79
|
if (this.nodeConfig.unfinalizedBlocks) {
|
|
115
|
-
return this.unfinalizedBlocksService.processUnfinalizedBlocks(block
|
|
80
|
+
return this.unfinalizedBlocksService.processUnfinalizedBlocks(block);
|
|
116
81
|
}
|
|
117
82
|
return null;
|
|
118
83
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
logger.error(`Your start block is greater than the current indexed block height in your database. Either change your startBlock (project.yaml) to <= ${nextProcessingHeight}
|
|
84
|
+
assertDataSources(ds, blockHeight) {
|
|
85
|
+
if (!ds.length) {
|
|
86
|
+
logger.error(`Your start block is greater than the current indexed block height in your database. Either change your startBlock (project.yaml) to <= ${blockHeight}
|
|
123
87
|
or delete your database and start again from the currently specified startBlock`);
|
|
124
88
|
process.exit(1);
|
|
125
89
|
}
|
|
126
|
-
// perform filter for custom ds
|
|
127
|
-
if (!filteredDs.length) {
|
|
128
|
-
logger.error(`Did not find any datasources with associated processor`);
|
|
129
|
-
process.exit(1);
|
|
130
|
-
}
|
|
131
|
-
return filteredDs;
|
|
132
90
|
}
|
|
133
|
-
async indexBlockData({ block,
|
|
91
|
+
async indexBlockData({ block, transactions }, dataSources, getVM) {
|
|
92
|
+
var _a;
|
|
134
93
|
await this.indexBlockContent(block, dataSources, getVM);
|
|
135
94
|
for (const tx of transactions) {
|
|
136
|
-
await this.
|
|
137
|
-
for (const log of
|
|
95
|
+
await this.indexTransaction(tx, dataSources, getVM);
|
|
96
|
+
for (const log of (_a = tx.logs) !== null && _a !== void 0 ? _a : []) {
|
|
138
97
|
await this.indexEvent(log, dataSources, getVM);
|
|
139
98
|
}
|
|
140
99
|
}
|
|
@@ -144,7 +103,7 @@ let IndexerManager = class IndexerManager {
|
|
|
144
103
|
await this.indexData(common_ethereum_1.EthereumHandlerKind.Block, block, ds, getVM);
|
|
145
104
|
}
|
|
146
105
|
}
|
|
147
|
-
async
|
|
106
|
+
async indexTransaction(tx, dataSources, getVM) {
|
|
148
107
|
for (const ds of dataSources) {
|
|
149
108
|
await this.indexData(common_ethereum_1.EthereumHandlerKind.Call, tx, ds, getVM);
|
|
150
109
|
}
|
|
@@ -165,7 +124,7 @@ let IndexerManager = class IndexerManager {
|
|
|
165
124
|
if (!handlers.length) {
|
|
166
125
|
return;
|
|
167
126
|
}
|
|
168
|
-
const parsedData = await DataAbiParser[kind](this.api)(data, ds);
|
|
127
|
+
const parsedData = await DataAbiParser[kind](this.apiService.api)(data, ds);
|
|
169
128
|
for (const handler of handlers) {
|
|
170
129
|
vm = vm !== null && vm !== void 0 ? vm : (await getVM(ds));
|
|
171
130
|
this.nodeConfig.profiler
|
|
@@ -189,7 +148,7 @@ let IndexerManager = class IndexerManager {
|
|
|
189
148
|
if (!handlers.length) {
|
|
190
149
|
return;
|
|
191
150
|
}
|
|
192
|
-
const parsedData = await DataAbiParser[kind](this.api)(data, ds);
|
|
151
|
+
const parsedData = await DataAbiParser[kind](this.apiService.api)(data, ds);
|
|
193
152
|
for (const handler of handlers) {
|
|
194
153
|
vm = vm !== null && vm !== void 0 ? vm : (await getVM(ds));
|
|
195
154
|
await this.transformAndExecuteCustomDs(ds, vm, handler, parsedData);
|
|
@@ -230,7 +189,7 @@ let IndexerManager = class IndexerManager {
|
|
|
230
189
|
.transformer({
|
|
231
190
|
input: data,
|
|
232
191
|
ds,
|
|
233
|
-
api: this.api,
|
|
192
|
+
api: this.apiService.api,
|
|
234
193
|
filter: handler.filter,
|
|
235
194
|
assets,
|
|
236
195
|
})
|
|
@@ -253,12 +212,8 @@ __decorate([
|
|
|
253
212
|
], IndexerManager.prototype, "indexBlock", null);
|
|
254
213
|
IndexerManager = __decorate([
|
|
255
214
|
(0, common_1.Injectable)(),
|
|
256
|
-
__param(
|
|
257
|
-
__metadata("design:paramtypes", [node_core_1.
|
|
258
|
-
node_core_1.ApiService,
|
|
259
|
-
node_core_1.PoiService,
|
|
260
|
-
sequelize_1.Sequelize,
|
|
261
|
-
SubqueryProject_1.SubqueryProject,
|
|
215
|
+
__param(6, (0, common_1.Inject)('IProjectService')),
|
|
216
|
+
__metadata("design:paramtypes", [node_core_1.ApiService,
|
|
262
217
|
node_core_1.NodeConfig,
|
|
263
218
|
sandbox_service_1.SandboxService,
|
|
264
219
|
dynamic_ds_service_1.DynamicDsService,
|