@subql/node-ethereum 0.1.0

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.
Files changed (118) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +201 -0
  3. package/README.md +76 -0
  4. package/bin/run +4 -0
  5. package/bin/run.cmd +3 -0
  6. package/dist/.tsbuildinfo +1 -0
  7. package/dist/app.module.d.ts +2 -0
  8. package/dist/app.module.js +35 -0
  9. package/dist/app.module.js.map +1 -0
  10. package/dist/configure/SubqueryProject.d.ts +38 -0
  11. package/dist/configure/SubqueryProject.js +133 -0
  12. package/dist/configure/SubqueryProject.js.map +1 -0
  13. package/dist/configure/configure.module.d.ts +7 -0
  14. package/dist/configure/configure.module.js +172 -0
  15. package/dist/configure/configure.module.js.map +1 -0
  16. package/dist/configure/configure.module.spec.d.ts +1 -0
  17. package/dist/configure/configure.module.spec.js +26 -0
  18. package/dist/configure/configure.module.spec.js.map +1 -0
  19. package/dist/ethereum/api.ethereum.d.ts +24 -0
  20. package/dist/ethereum/api.ethereum.js +177 -0
  21. package/dist/ethereum/api.ethereum.js.map +1 -0
  22. package/dist/ethereum/api.service.ethereum.d.ts +8 -0
  23. package/dist/ethereum/api.service.ethereum.js +57 -0
  24. package/dist/ethereum/api.service.ethereum.js.map +1 -0
  25. package/dist/ethereum/block.ethereum.d.ts +15 -0
  26. package/dist/ethereum/block.ethereum.js +87 -0
  27. package/dist/ethereum/block.ethereum.js.map +1 -0
  28. package/dist/ethereum/index.d.ts +2 -0
  29. package/dist/ethereum/index.js +21 -0
  30. package/dist/ethereum/index.js.map +1 -0
  31. package/dist/ethereum/utils.ethereum.d.ts +6 -0
  32. package/dist/ethereum/utils.ethereum.js +131 -0
  33. package/dist/ethereum/utils.ethereum.js.map +1 -0
  34. package/dist/indexer/dictionary.service.d.ts +7 -0
  35. package/dist/indexer/dictionary.service.js +29 -0
  36. package/dist/indexer/dictionary.service.js.map +1 -0
  37. package/dist/indexer/ds-processor.service.d.ts +26 -0
  38. package/dist/indexer/ds-processor.service.js +133 -0
  39. package/dist/indexer/ds-processor.service.js.map +1 -0
  40. package/dist/indexer/dynamic-ds.service.d.ts +25 -0
  41. package/dist/indexer/dynamic-ds.service.js +124 -0
  42. package/dist/indexer/dynamic-ds.service.js.map +1 -0
  43. package/dist/indexer/fetch.module.d.ts +2 -0
  44. package/dist/indexer/fetch.module.js +68 -0
  45. package/dist/indexer/fetch.module.js.map +1 -0
  46. package/dist/indexer/fetch.service.d.ts +44 -0
  47. package/dist/indexer/fetch.service.js +369 -0
  48. package/dist/indexer/fetch.service.js.map +1 -0
  49. package/dist/indexer/indexer.manager.d.ts +36 -0
  50. package/dist/indexer/indexer.manager.js +266 -0
  51. package/dist/indexer/indexer.manager.js.map +1 -0
  52. package/dist/indexer/indexer.module.d.ts +2 -0
  53. package/dist/indexer/indexer.module.js +52 -0
  54. package/dist/indexer/indexer.module.js.map +1 -0
  55. package/dist/indexer/project.service.d.ts +40 -0
  56. package/dist/indexer/project.service.js +259 -0
  57. package/dist/indexer/project.service.js.map +1 -0
  58. package/dist/indexer/sandbox.service.d.ts +12 -0
  59. package/dist/indexer/sandbox.service.js +58 -0
  60. package/dist/indexer/sandbox.service.js.map +1 -0
  61. package/dist/indexer/types.d.ts +10 -0
  62. package/dist/indexer/types.js +11 -0
  63. package/dist/indexer/types.js.map +1 -0
  64. package/dist/indexer/worker/block-dispatcher.service.d.ts +69 -0
  65. package/dist/indexer/worker/block-dispatcher.service.js +356 -0
  66. package/dist/indexer/worker/block-dispatcher.service.js.map +1 -0
  67. package/dist/indexer/worker/worker.d.ts +14 -0
  68. package/dist/indexer/worker/worker.js +85 -0
  69. package/dist/indexer/worker/worker.js.map +1 -0
  70. package/dist/indexer/worker/worker.module.d.ts +2 -0
  71. package/dist/indexer/worker/worker.module.js +33 -0
  72. package/dist/indexer/worker/worker.module.js.map +1 -0
  73. package/dist/indexer/worker/worker.service.d.ts +28 -0
  74. package/dist/indexer/worker/worker.service.js +79 -0
  75. package/dist/indexer/worker/worker.service.js.map +1 -0
  76. package/dist/init.d.ts +1 -0
  77. package/dist/init.js +54 -0
  78. package/dist/init.js.map +1 -0
  79. package/dist/main.d.ts +1 -0
  80. package/dist/main.js +14 -0
  81. package/dist/main.js.map +1 -0
  82. package/dist/meta/meta.controller.d.ts +23 -0
  83. package/dist/meta/meta.controller.js +36 -0
  84. package/dist/meta/meta.controller.js.map +1 -0
  85. package/dist/meta/meta.module.d.ts +2 -0
  86. package/dist/meta/meta.module.js +77 -0
  87. package/dist/meta/meta.module.js.map +1 -0
  88. package/dist/meta/meta.service.d.ts +42 -0
  89. package/dist/meta/meta.service.js +110 -0
  90. package/dist/meta/meta.service.js.map +1 -0
  91. package/dist/subcommands/forceClean.init.d.ts +1 -0
  92. package/dist/subcommands/forceClean.init.js +25 -0
  93. package/dist/subcommands/forceClean.init.js.map +1 -0
  94. package/dist/subcommands/forceClean.module.d.ts +4 -0
  95. package/dist/subcommands/forceClean.module.js +38 -0
  96. package/dist/subcommands/forceClean.module.js.map +1 -0
  97. package/dist/subcommands/forceClean.service.d.ts +8 -0
  98. package/dist/subcommands/forceClean.service.js +65 -0
  99. package/dist/subcommands/forceClean.service.js.map +1 -0
  100. package/dist/subcommands/reindex.init.d.ts +1 -0
  101. package/dist/subcommands/reindex.init.js +25 -0
  102. package/dist/subcommands/reindex.init.js.map +1 -0
  103. package/dist/subcommands/reindex.module.d.ts +4 -0
  104. package/dist/subcommands/reindex.module.js +39 -0
  105. package/dist/subcommands/reindex.module.js.map +1 -0
  106. package/dist/subcommands/reindex.service.d.ts +24 -0
  107. package/dist/subcommands/reindex.service.js +114 -0
  108. package/dist/subcommands/reindex.service.js.map +1 -0
  109. package/dist/utils/project.d.ts +13 -0
  110. package/dist/utils/project.js +191 -0
  111. package/dist/utils/project.js.map +1 -0
  112. package/dist/utils/string.d.ts +4 -0
  113. package/dist/utils/string.js +32 -0
  114. package/dist/utils/string.js.map +1 -0
  115. package/dist/yargs.d.ts +154 -0
  116. package/dist/yargs.js +193 -0
  117. package/dist/yargs.js.map +1 -0
  118. package/package.json +77 -0
@@ -0,0 +1,369 @@
1
+ "use strict";
2
+ // Copyright 2020-2022 OnFinality Limited authors & contributors
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
5
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
8
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
9
+ };
10
+ var __metadata = (this && this.__metadata) || function (k, v) {
11
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
12
+ };
13
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
14
+ return function (target, key) { decorator(target, key, paramIndex); }
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.FetchService = void 0;
18
+ const common_1 = require("@nestjs/common");
19
+ const event_emitter_1 = require("@nestjs/event-emitter");
20
+ const schedule_1 = require("@nestjs/schedule");
21
+ const common_ethereum_1 = require("@subql/common-ethereum");
22
+ const node_core_1 = require("@subql/node-core");
23
+ const lodash_1 = require("lodash");
24
+ const SubqueryProject_1 = require("../configure/SubqueryProject");
25
+ const utils_ethereum_1 = require("../ethereum/utils.ethereum");
26
+ const string_1 = require("../utils/string");
27
+ const dictionary_service_1 = require("./dictionary.service");
28
+ const dynamic_ds_service_1 = require("./dynamic-ds.service");
29
+ const logger = (0, node_core_1.getLogger)('fetch');
30
+ let BLOCK_TIME_VARIANCE = 5000;
31
+ const DICTIONARY_MAX_QUERY_SIZE = 10000;
32
+ const CHECK_MEMORY_INTERVAL = 60000;
33
+ const MINIMUM_BATCH_SIZE = 5;
34
+ const INTERVAL_PERCENT = 0.9;
35
+ function eventFilterToQueryEntry(filter) {
36
+ const conditions = [];
37
+ if (filter.address) {
38
+ conditions.push({
39
+ field: 'address',
40
+ value: filter.address.toLowerCase(),
41
+ });
42
+ }
43
+ if (filter.topics) {
44
+ for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {
45
+ const topic = filter.topics[i];
46
+ if (!topic) {
47
+ continue;
48
+ }
49
+ const field = `topics${i}`;
50
+ conditions.push({ field, value: (0, string_1.eventToTopic)(topic) });
51
+ }
52
+ }
53
+ return {
54
+ entity: 'evmLogs',
55
+ conditions,
56
+ };
57
+ }
58
+ function callFilterToQueryEntry(filter) {
59
+ const conditions = [];
60
+ if (filter.from) {
61
+ conditions.push({
62
+ field: 'from',
63
+ value: filter.from.toLowerCase(),
64
+ });
65
+ }
66
+ if (filter.to) {
67
+ conditions.push({
68
+ field: 'to',
69
+ value: filter.to.toLowerCase(),
70
+ });
71
+ }
72
+ if (filter.function) {
73
+ conditions.push({
74
+ field: 'func',
75
+ value: (0, string_1.functionToSighash)(filter.function),
76
+ });
77
+ }
78
+ return {
79
+ entity: 'evmTransactions',
80
+ conditions,
81
+ };
82
+ }
83
+ let FetchService = class FetchService {
84
+ constructor(apiService, nodeConfig, project, blockDispatcher, dictionaryService, dynamicDsService, eventEmitter, schedulerRegistry) {
85
+ this.apiService = apiService;
86
+ this.nodeConfig = nodeConfig;
87
+ this.project = project;
88
+ this.blockDispatcher = blockDispatcher;
89
+ this.dictionaryService = dictionaryService;
90
+ this.dynamicDsService = dynamicDsService;
91
+ this.eventEmitter = eventEmitter;
92
+ this.schedulerRegistry = schedulerRegistry;
93
+ this.isShutdown = false;
94
+ this.batchSizeScale = 1;
95
+ }
96
+ onApplicationShutdown() {
97
+ this.isShutdown = true;
98
+ }
99
+ get api() {
100
+ return this.apiService.api;
101
+ }
102
+ async syncDynamicDatascourcesFromMeta() {
103
+ this.templateDynamicDatasouces =
104
+ await this.dynamicDsService.getDynamicDatasources();
105
+ }
106
+ // TODO: if custom ds doesn't support dictionary, use baseFilter, if yes, let
107
+ getDictionaryQueryEntries() {
108
+ const queryEntries = [];
109
+ const dataSources = this.project.dataSources;
110
+ for (const ds of dataSources.concat(this.templateDynamicDatasouces)) {
111
+ for (const handler of ds.mapping.handlers) {
112
+ let filterList;
113
+ filterList = [handler.filter];
114
+ filterList = filterList.filter((f) => f);
115
+ if (!filterList.length)
116
+ return [];
117
+ switch (handler.kind) {
118
+ case common_ethereum_1.EthereumHandlerKind.Block:
119
+ return [];
120
+ case common_ethereum_1.EthereumHandlerKind.Call: {
121
+ for (const filter of filterList) {
122
+ if (filter.from !== undefined ||
123
+ filter.to !== undefined ||
124
+ filter.function) {
125
+ queryEntries.push(callFilterToQueryEntry(filter));
126
+ }
127
+ else {
128
+ return [];
129
+ }
130
+ }
131
+ break;
132
+ }
133
+ case common_ethereum_1.EthereumHandlerKind.Event: {
134
+ for (const filter of filterList) {
135
+ if (filter.address || filter.topics) {
136
+ queryEntries.push(eventFilterToQueryEntry(filter));
137
+ }
138
+ else {
139
+ return [];
140
+ }
141
+ }
142
+ break;
143
+ }
144
+ default:
145
+ }
146
+ }
147
+ }
148
+ return (0, lodash_1.uniqBy)(queryEntries, (item) => `${item.entity}|${JSON.stringify((0, lodash_1.sortBy)(item.conditions, (c) => c.field))}`);
149
+ }
150
+ updateDictionary() {
151
+ var _a;
152
+ this.dictionaryQueryEntries = this.getDictionaryQueryEntries();
153
+ this.useDictionary =
154
+ !!((_a = this.dictionaryQueryEntries) === null || _a === void 0 ? void 0 : _a.length) &&
155
+ !!this.project.network.dictionary;
156
+ }
157
+ async init(startHeight) {
158
+ if (this.api) {
159
+ const CHAIN_INTERVAL = (0, utils_ethereum_1.calcInterval)(this.api) * INTERVAL_PERCENT;
160
+ BLOCK_TIME_VARIANCE = Math.min(BLOCK_TIME_VARIANCE, CHAIN_INTERVAL);
161
+ this.schedulerRegistry.addInterval('getLatestBlockHead', setInterval(() => void this.getBestBlockHead(), BLOCK_TIME_VARIANCE));
162
+ }
163
+ await this.syncDynamicDatascourcesFromMeta();
164
+ this.updateDictionary();
165
+ this.eventEmitter.emit(node_core_1.IndexerEvent.UsingDictionary, {
166
+ value: Number(this.useDictionary),
167
+ });
168
+ await this.getFinalizedBlockHead();
169
+ await this.getBestBlockHead();
170
+ await this.blockDispatcher.init(this.resetForNewDs.bind(this));
171
+ void this.startLoop(startHeight);
172
+ }
173
+ checkBatchScale() {
174
+ if (this.nodeConfig['scale-batch-size']) {
175
+ const scale = (0, node_core_1.checkMemoryUsage)(this.batchSizeScale, this.nodeConfig);
176
+ if (this.batchSizeScale !== scale) {
177
+ this.batchSizeScale = scale;
178
+ }
179
+ }
180
+ }
181
+ async getFinalizedBlockHead() {
182
+ if (!this.api) {
183
+ logger.debug(`Skip fetch finalized block until API is ready`);
184
+ return;
185
+ }
186
+ try {
187
+ const currentFinalizedHeight = await this.api.getFinalizedBlockHeight();
188
+ if (this.latestFinalizedHeight !== currentFinalizedHeight) {
189
+ this.latestFinalizedHeight = currentFinalizedHeight;
190
+ this.eventEmitter.emit(node_core_1.IndexerEvent.BlockTarget, {
191
+ height: this.latestFinalizedHeight,
192
+ });
193
+ }
194
+ }
195
+ catch (e) {
196
+ logger.error(e, `Having a problem when get finalized block`);
197
+ }
198
+ }
199
+ async getBestBlockHead() {
200
+ if (!this.api) {
201
+ logger.debug(`Skip fetch best block until API is ready`);
202
+ return;
203
+ }
204
+ try {
205
+ const currentBestHeight = await this.api.getLastHeight();
206
+ if (this.latestBestHeight !== currentBestHeight) {
207
+ this.latestBestHeight = currentBestHeight;
208
+ this.eventEmitter.emit(node_core_1.IndexerEvent.BlockBest, {
209
+ height: this.latestBestHeight,
210
+ });
211
+ }
212
+ }
213
+ catch (e) {
214
+ logger.error(e, `Having a problem when get best block`);
215
+ }
216
+ }
217
+ async startLoop(initBlockHeight) {
218
+ await this.fillNextBlockBuffer(initBlockHeight);
219
+ }
220
+ getModulos() {
221
+ const modulos = [];
222
+ for (const ds of this.project.dataSources) {
223
+ if ((0, common_ethereum_1.isCustomDs)(ds)) {
224
+ continue;
225
+ }
226
+ for (const handler of ds.mapping.handlers) {
227
+ if (handler.kind === common_ethereum_1.EthereumHandlerKind.Block &&
228
+ handler.filter &&
229
+ handler.filter.modulo) {
230
+ modulos.push(handler.filter.modulo);
231
+ }
232
+ }
233
+ }
234
+ return modulos;
235
+ }
236
+ getModuloBlocks(startHeight, endHeight) {
237
+ const modulos = this.getModulos();
238
+ const moduloBlocks = [];
239
+ for (let i = startHeight; i < endHeight; i++) {
240
+ if (modulos.find((m) => i % m === 0)) {
241
+ moduloBlocks.push(i);
242
+ }
243
+ }
244
+ return moduloBlocks;
245
+ }
246
+ getEnqueuedModuloBlocks(startBlockHeight) {
247
+ return this.getModuloBlocks(startBlockHeight, this.nodeConfig.batchSize * Math.max(...this.getModulos()) +
248
+ startBlockHeight).slice(0, this.nodeConfig.batchSize);
249
+ }
250
+ async fillNextBlockBuffer(initBlockHeight) {
251
+ let startBlockHeight;
252
+ let scaledBatchSize;
253
+ const handlers = [].concat(...this.project.dataSources.map((ds) => ds.mapping.handlers));
254
+ const getStartBlockHeight = () => {
255
+ return this.blockDispatcher.latestBufferedHeight
256
+ ? this.blockDispatcher.latestBufferedHeight + 1
257
+ : initBlockHeight;
258
+ };
259
+ while (!this.isShutdown) {
260
+ startBlockHeight = getStartBlockHeight();
261
+ scaledBatchSize = Math.max(Math.round(this.batchSizeScale * this.nodeConfig.batchSize), Math.min(MINIMUM_BATCH_SIZE, this.nodeConfig.batchSize * 3));
262
+ if (this.blockDispatcher.freeSize < scaledBatchSize ||
263
+ startBlockHeight > this.latestFinalizedHeight) {
264
+ await (0, node_core_1.delay)(1);
265
+ continue;
266
+ }
267
+ if (this.useDictionary) {
268
+ const queryEndBlock = startBlockHeight + DICTIONARY_MAX_QUERY_SIZE;
269
+ const moduloBlocks = this.getModuloBlocks(startBlockHeight, queryEndBlock);
270
+ try {
271
+ const dictionary = await this.dictionaryService.getDictionary(startBlockHeight, queryEndBlock, scaledBatchSize, this.dictionaryQueryEntries);
272
+ if (startBlockHeight !== getStartBlockHeight()) {
273
+ logger.debug(`Queue was reset for new DS, discarding dictionary query result`);
274
+ continue;
275
+ }
276
+ if (dictionary &&
277
+ this.dictionaryValidation(dictionary, startBlockHeight)) {
278
+ let { batchBlocks } = dictionary;
279
+ batchBlocks = batchBlocks
280
+ .concat(moduloBlocks)
281
+ .sort((a, b) => a - b);
282
+ if (batchBlocks.length === 0) {
283
+ // There we're no blocks in this query range, we can set a new height we're up to
284
+ this.blockDispatcher.latestBufferedHeight = Math.min(queryEndBlock - 1, dictionary._metadata.lastProcessedHeight);
285
+ }
286
+ else {
287
+ const maxBlockSize = Math.min(batchBlocks.length, this.blockDispatcher.freeSize);
288
+ batchBlocks = batchBlocks.slice(0, maxBlockSize);
289
+ this.blockDispatcher.enqueueBlocks(batchBlocks);
290
+ }
291
+ continue; // skip nextBlockRange() way
292
+ }
293
+ // else use this.nextBlockRange()
294
+ }
295
+ catch (e) {
296
+ logger.debug(`Fetch dictionary stopped: ${e.message}`);
297
+ this.eventEmitter.emit(node_core_1.IndexerEvent.SkipDictionary);
298
+ }
299
+ }
300
+ const endHeight = this.nextEndBlockHeight(startBlockHeight, scaledBatchSize);
301
+ if (this.getModulos().length === handlers.length) {
302
+ this.blockDispatcher.enqueueBlocks(this.getEnqueuedModuloBlocks(startBlockHeight));
303
+ }
304
+ else {
305
+ this.blockDispatcher.enqueueBlocks((0, lodash_1.range)(startBlockHeight, endHeight + 1));
306
+ }
307
+ }
308
+ }
309
+ nextEndBlockHeight(startBlockHeight, scaledBatchSize) {
310
+ let endBlockHeight = startBlockHeight + scaledBatchSize - 1;
311
+ if (endBlockHeight > this.latestFinalizedHeight) {
312
+ endBlockHeight = this.latestFinalizedHeight;
313
+ }
314
+ return endBlockHeight;
315
+ }
316
+ dictionaryValidation({ _metadata: metaData }, startBlockHeight) {
317
+ if (metaData.genesisHash !== this.api.getGenesisHash()) {
318
+ logger.error('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');
319
+ this.useDictionary = false;
320
+ this.eventEmitter.emit(node_core_1.IndexerEvent.UsingDictionary, {
321
+ value: Number(this.useDictionary),
322
+ });
323
+ this.eventEmitter.emit(node_core_1.IndexerEvent.SkipDictionary);
324
+ return false;
325
+ }
326
+ if (metaData.lastProcessedHeight < startBlockHeight) {
327
+ logger.warn(`Dictionary indexed block is behind current indexing block height`);
328
+ this.eventEmitter.emit(node_core_1.IndexerEvent.SkipDictionary);
329
+ return false;
330
+ }
331
+ return true;
332
+ }
333
+ async resetForNewDs(blockHeight) {
334
+ await this.syncDynamicDatascourcesFromMeta();
335
+ this.dynamicDsService.deleteTempDsRecords(blockHeight);
336
+ this.updateDictionary();
337
+ this.blockDispatcher.flushQueue(blockHeight);
338
+ }
339
+ };
340
+ __decorate([
341
+ (0, schedule_1.Interval)(CHECK_MEMORY_INTERVAL),
342
+ __metadata("design:type", Function),
343
+ __metadata("design:paramtypes", []),
344
+ __metadata("design:returntype", void 0)
345
+ ], FetchService.prototype, "checkBatchScale", null);
346
+ __decorate([
347
+ (0, schedule_1.Interval)(BLOCK_TIME_VARIANCE * 1000),
348
+ __metadata("design:type", Function),
349
+ __metadata("design:paramtypes", []),
350
+ __metadata("design:returntype", Promise)
351
+ ], FetchService.prototype, "getFinalizedBlockHead", null);
352
+ __decorate([
353
+ (0, schedule_1.Interval)(BLOCK_TIME_VARIANCE * 1000),
354
+ __metadata("design:type", Function),
355
+ __metadata("design:paramtypes", []),
356
+ __metadata("design:returntype", Promise)
357
+ ], FetchService.prototype, "getBestBlockHead", null);
358
+ FetchService = __decorate([
359
+ (0, common_1.Injectable)(),
360
+ __param(3, (0, common_1.Inject)('IBlockDispatcher')),
361
+ __metadata("design:paramtypes", [node_core_1.ApiService,
362
+ node_core_1.NodeConfig,
363
+ SubqueryProject_1.SubqueryProject, Object, dictionary_service_1.DictionaryService,
364
+ dynamic_ds_service_1.DynamicDsService,
365
+ event_emitter_1.EventEmitter2,
366
+ schedule_1.SchedulerRegistry])
367
+ ], FetchService);
368
+ exports.FetchService = FetchService;
369
+ //# sourceMappingURL=fetch.service.js.map
@@ -0,0 +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,gDAQ0B;AAO1B,mCAA+C;AAC/C,kEAA+E;AAC/E,+DAA0D;AAC1D,4CAAkE;AAClE,6DAAyD;AACzD,6DAAwD;AAGxD,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,CAAC,CAAC;AAC7B,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAE7B,SAAS,uBAAuB,CAC9B,MAAyB;IAEzB,MAAM,UAAU,GAAG,EAAE,CAAC;IACtB,IAAI,MAAM,CAAC,OAAO,EAAE;QAClB,UAAU,CAAC,IAAI,CAAC;YACd,KAAK,EAAE,SAAS;YAChB,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE;SACpC,CAAC,CAAC;KACJ;IACD,IAAI,MAAM,CAAC,MAAM,EAAE;QACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YAC1D,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAC/B,IAA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,WAAW,CAAC,CAAC;IAC/C,CAAC;CACF,CAAA;AAtOC;IAAC,IAAA,mBAAQ,EAAC,qBAAqB,CAAC;;;;mDAS/B;AAGK;IADL,IAAA,mBAAQ,EAAC,mBAAmB,GAAG,IAAI,CAAC;;;;yDAiBpC;AAGK;IADL,IAAA,mBAAQ,EAAC,mBAAmB,GAAG,IAAI,CAAC;;;;oDAiBpC;AArKU,YAAY;IADxB,IAAA,mBAAU,GAAE;IAcR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;qCAHP,sBAAU;QACV,sBAAU;QACb,iCAAe,UAEL,sCAAiB;QAClB,qCAAgB;QACpB,6BAAa;QACR,4BAAiB;GAjBnC,YAAY,CA4VxB;AA5VY,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} from '@subql/node-core';\nimport {\n DictionaryQueryEntry,\n ApiWrapper,\n EthereumLogFilter,\n EthereumTransactionFilter,\n} from '@subql/types-ethereum';\nimport { range, sortBy, uniqBy } from 'lodash';\nimport { SubqlProjectDs, SubqueryProject } from '../configure/SubqueryProject';\nimport { calcInterval } from '../ethereum/utils.ethereum';\nimport { eventToTopic, functionToSighash } from '../utils/string';\nimport { DictionaryService } from './dictionary.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { IBlockDispatcher } from './worker/block-dispatcher.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;\n\nfunction eventFilterToQueryEntry(\n filter: EthereumLogFilter,\n): DictionaryQueryEntry {\n const conditions = [];\n if (filter.address) {\n conditions.push({\n field: 'address',\n value: filter.address.toLowerCase(),\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 useDictionary: boolean;\n private dictionaryQueryEntries?: DictionaryQueryEntry[];\n private batchSizeScale: number;\n private templateDynamicDatasouces: SubqlProjectDs[];\n\n constructor(\n private apiService: ApiService,\n private nodeConfig: NodeConfig,\n private project: SubqueryProject,\n @Inject('IBlockDispatcher') private blockDispatcher: IBlockDispatcher,\n private dictionaryService: DictionaryService,\n private dynamicDsService: DynamicDsService,\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 // TODO: if custom ds doesn't support dictionary, use baseFilter, if yes, let\n getDictionaryQueryEntries(): DictionaryQueryEntry[] {\n const queryEntries: DictionaryQueryEntry[] = [];\n\n const dataSources = this.project.dataSources;\n for (const ds of dataSources.concat(this.templateDynamicDatasouces)) {\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 (filter.address || filter.topics) {\n queryEntries.push(eventFilterToQueryEntry(filter));\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.dictionaryQueryEntries = this.getDictionaryQueryEntries();\n this.useDictionary =\n !!this.dictionaryQueryEntries?.length &&\n !!this.project.network.dictionary;\n }\n\n async init(startHeight: number): Promise<void> {\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 this.updateDictionary();\n this.eventEmitter.emit(IndexerEvent.UsingDictionary, {\n value: Number(this.useDictionary),\n });\n await this.getFinalizedBlockHead();\n await this.getBestBlockHead();\n\n await this.blockDispatcher.init(this.resetForNewDs.bind(this));\n\n void this.startLoop(startHeight);\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 if (this.latestFinalizedHeight !== currentFinalizedHeight) {\n this.latestFinalizedHeight = currentFinalizedHeight;\n this.eventEmitter.emit(IndexerEvent.BlockTarget, {\n height: this.latestFinalizedHeight,\n });\n }\n } catch (e) {\n logger.error(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.getLastHeight();\n if (this.latestBestHeight !== currentBestHeight) {\n this.latestBestHeight = currentBestHeight;\n this.eventEmitter.emit(IndexerEvent.BlockBest, {\n height: this.latestBestHeight,\n });\n }\n } catch (e) {\n logger.error(e, `Having a problem when get best block`);\n }\n }\n\n 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 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 if (\n this.blockDispatcher.freeSize < scaledBatchSize ||\n startBlockHeight > this.latestFinalizedHeight\n ) {\n await delay(1);\n continue;\n }\n if (this.useDictionary) {\n const queryEndBlock = startBlockHeight + DICTIONARY_MAX_QUERY_SIZE;\n const moduloBlocks = this.getModuloBlocks(\n startBlockHeight,\n queryEndBlock,\n );\n try {\n const dictionary = await this.dictionaryService.getDictionary(\n startBlockHeight,\n queryEndBlock,\n scaledBatchSize,\n this.dictionaryQueryEntries,\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.latestBufferedHeight = Math.min(\n queryEndBlock - 1,\n dictionary._metadata.lastProcessedHeight,\n );\n } else {\n const maxBlockSize = Math.min(\n batchBlocks.length,\n this.blockDispatcher.freeSize,\n );\n batchBlocks = batchBlocks.slice(0, maxBlockSize);\n this.blockDispatcher.enqueueBlocks(batchBlocks);\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 const endHeight = this.nextEndBlockHeight(\n startBlockHeight,\n scaledBatchSize,\n );\n\n if (this.getModulos().length === handlers.length) {\n this.blockDispatcher.enqueueBlocks(\n this.getEnqueuedModuloBlocks(startBlockHeight),\n );\n } else {\n this.blockDispatcher.enqueueBlocks(\n range(startBlockHeight, endHeight + 1),\n );\n }\n }\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 endBlockHeight = this.latestFinalizedHeight;\n }\n return endBlockHeight;\n }\n\n private dictionaryValidation(\n { _metadata: metaData }: Dictionary,\n startBlockHeight: number,\n ): boolean {\n if (metaData.genesisHash !== this.api.getGenesisHash()) {\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.useDictionary = false;\n this.eventEmitter.emit(IndexerEvent.UsingDictionary, {\n value: Number(this.useDictionary),\n });\n this.eventEmitter.emit(IndexerEvent.SkipDictionary);\n return false;\n }\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 return true;\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"]}
@@ -0,0 +1,36 @@
1
+ import { ApiService, StoreService, PoiService, NodeConfig } from '@subql/node-core';
2
+ import { EthereumBlockWrapper } from '@subql/types-ethereum';
3
+ import { Sequelize } from 'sequelize';
4
+ import { SubqueryProject } from '../configure/SubqueryProject';
5
+ import { DsProcessorService } from './ds-processor.service';
6
+ import { DynamicDsService } from './dynamic-ds.service';
7
+ import { ProjectService } from './project.service';
8
+ import { SandboxService } from './sandbox.service';
9
+ export declare class IndexerManager {
10
+ private storeService;
11
+ private apiService;
12
+ private poiService;
13
+ private sequelize;
14
+ private project;
15
+ private nodeConfig;
16
+ private sandboxService;
17
+ private dynamicDsService;
18
+ private dsProcessorService;
19
+ private projectService;
20
+ private api;
21
+ private filteredDataSources;
22
+ constructor(storeService: StoreService, apiService: ApiService, poiService: PoiService, sequelize: Sequelize, project: SubqueryProject, nodeConfig: NodeConfig, sandboxService: SandboxService, dynamicDsService: DynamicDsService, dsProcessorService: DsProcessorService, projectService: ProjectService);
23
+ indexBlock(blockContent: EthereumBlockWrapper): Promise<{
24
+ dynamicDsCreated: boolean;
25
+ operationHash: Uint8Array;
26
+ }>;
27
+ start(): Promise<void>;
28
+ private filterDataSources;
29
+ private indexBlockData;
30
+ private indexBlockContent;
31
+ private indexExtrinsic;
32
+ private indexEvent;
33
+ private indexData;
34
+ private filterCustomDsHandlers;
35
+ private transformAndExecuteCustomDs;
36
+ }