@subql/node-ethereum 3.11.0 → 3.11.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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/ethereum/api.connection.d.ts +4 -4
- package/dist/ethereum/api.connection.js.map +1 -1
- package/dist/ethereum/api.ethereum.d.ts +4 -3
- package/dist/ethereum/api.ethereum.js +6 -3
- package/dist/ethereum/api.ethereum.js.map +1 -1
- package/dist/ethereum/api.ethereum.test.js +13 -1
- package/dist/ethereum/api.ethereum.test.js.map +1 -1
- package/dist/ethereum/api.service.ethereum.d.ts +2 -2
- package/dist/ethereum/api.service.ethereum.js.map +1 -1
- package/dist/ethereum/block.ethereum.js +6 -2
- package/dist/ethereum/block.ethereum.js.map +1 -1
- package/dist/ethereum/utils.ethereum.d.ts +8 -1
- package/dist/ethereum/utils.ethereum.js +17 -1
- package/dist/ethereum/utils.ethereum.js.map +1 -1
- package/dist/indexer/blockDispatcher/block-dispatcher.service.d.ts +2 -3
- package/dist/indexer/blockDispatcher/block-dispatcher.service.js +1 -4
- package/dist/indexer/blockDispatcher/block-dispatcher.service.js.map +1 -1
- package/dist/indexer/blockDispatcher/ethereum-block-dispatcher.d.ts +2 -1
- package/dist/indexer/blockDispatcher/ethereum-block-dispatcher.js.map +1 -1
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.d.ts +2 -1
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js +0 -12
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js.map +1 -1
- package/dist/indexer/dictionary/ethDictionary.service.d.ts +9 -0
- package/dist/indexer/dictionary/ethDictionary.service.js +59 -0
- package/dist/indexer/dictionary/ethDictionary.service.js.map +1 -0
- package/dist/indexer/dictionary/utils.d.ts +3 -0
- package/dist/indexer/dictionary/utils.js +24 -0
- package/dist/indexer/dictionary/utils.js.map +1 -0
- package/dist/indexer/dictionary/utils.spec.js +83 -0
- package/dist/indexer/dictionary/utils.spec.js.map +1 -0
- package/dist/indexer/dictionary/v1/ethDictionaryV1.d.ts +16 -0
- package/dist/indexer/dictionary/v1/ethDictionaryV1.js +202 -0
- package/dist/indexer/dictionary/v1/ethDictionaryV1.js.map +1 -0
- package/dist/indexer/{fetch.service.spec.js → dictionary/v1/ethDictionaryV1.spec.js} +45 -23
- package/dist/indexer/dictionary/v1/ethDictionaryV1.spec.js.map +1 -0
- package/dist/indexer/dictionary/v1/index.d.ts +1 -0
- package/dist/indexer/dictionary/v1/index.js +20 -0
- package/dist/indexer/dictionary/v1/index.js.map +1 -0
- package/dist/indexer/dictionary/v2/ethDictionaryV2.d.ts +14 -0
- package/dist/indexer/dictionary/v2/ethDictionaryV2.js +188 -0
- package/dist/indexer/dictionary/v2/ethDictionaryV2.js.map +1 -0
- package/dist/indexer/dictionary/v2/ethDictionaryV2.spec.d.ts +1 -0
- package/dist/indexer/dictionary/v2/ethDictionaryV2.spec.js +232 -0
- package/dist/indexer/dictionary/v2/ethDictionaryV2.spec.js.map +1 -0
- package/dist/indexer/dictionary/v2/index.d.ts +2 -0
- package/dist/indexer/dictionary/v2/index.js +21 -0
- package/dist/indexer/dictionary/v2/index.js.map +1 -0
- package/dist/indexer/dictionary/v2/types.d.ts +75 -0
- package/dist/indexer/dictionary/v2/types.js +5 -0
- package/dist/indexer/dictionary/v2/types.js.map +1 -0
- package/dist/indexer/dictionary/v2/utils.d.ts +4 -0
- package/dist/indexer/dictionary/v2/utils.js +22 -0
- package/dist/indexer/dictionary/v2/utils.js.map +1 -0
- package/dist/indexer/dictionary/v2/utils.spec.d.ts +1 -0
- package/dist/indexer/dictionary/v2/utils.spec.js +98 -0
- package/dist/indexer/dictionary/v2/utils.spec.js.map +1 -0
- package/dist/indexer/fetch.module.js +4 -3
- package/dist/indexer/fetch.module.js.map +1 -1
- package/dist/indexer/fetch.service.d.ts +4 -14
- package/dist/indexer/fetch.service.js +4 -177
- package/dist/indexer/fetch.service.js.map +1 -1
- package/dist/indexer/indexer.manager.d.ts +5 -5
- package/dist/indexer/indexer.manager.js +3 -3
- package/dist/indexer/indexer.manager.js.map +1 -1
- package/dist/indexer/unfinalizedBlocks.service.d.ts +1 -5
- package/dist/indexer/unfinalizedBlocks.service.js +5 -21
- package/dist/indexer/unfinalizedBlocks.service.js.map +1 -1
- package/dist/indexer/worker/worker.service.d.ts +4 -4
- package/dist/indexer/worker/worker.service.js +1 -1
- package/dist/indexer/worker/worker.service.js.map +1 -1
- package/dist/indexer/worker/worker.unfinalizedBlocks.service.d.ts +2 -2
- package/dist/indexer/worker/worker.unfinalizedBlocks.service.js +2 -6
- package/dist/indexer/worker/worker.unfinalizedBlocks.service.js.map +1 -1
- package/dist/subcommands/testing.service.d.ts +2 -2
- package/dist/subcommands/testing.service.js.map +1 -1
- package/package.json +8 -7
- package/dist/indexer/dictionary.service.d.ts +0 -11
- package/dist/indexer/dictionary.service.js +0 -72
- package/dist/indexer/dictionary.service.js.map +0 -1
- package/dist/indexer/dictionary.service.spec.js +0 -15
- package/dist/indexer/dictionary.service.spec.js.map +0 -1
- package/dist/indexer/fetch.service.spec.js.map +0 -1
- /package/dist/indexer/{dictionary.service.spec.d.ts → dictionary/utils.spec.d.ts} +0 -0
- /package/dist/indexer/{fetch.service.spec.d.ts → dictionary/v1/ethDictionaryV1.spec.d.ts} +0 -0
|
@@ -1,28 +1,19 @@
|
|
|
1
1
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
|
2
2
|
import { SchedulerRegistry } from '@nestjs/schedule';
|
|
3
|
-
import { SubqlEthereumProcessorOptions } from '@subql/common-ethereum';
|
|
4
3
|
import { NodeConfig, BaseFetchService, ApiService } from '@subql/node-core';
|
|
5
|
-
import {
|
|
6
|
-
import { SubqlDatasource } from '@subql/types-ethereum';
|
|
4
|
+
import { EthereumBlock, SubqlDatasource } from '@subql/types-ethereum';
|
|
7
5
|
import { SubqueryProject } from '../configure/SubqueryProject';
|
|
8
6
|
import { EthereumApi } from '../ethereum';
|
|
9
7
|
import { IEthereumBlockDispatcher } from './blockDispatcher';
|
|
10
|
-
import {
|
|
8
|
+
import { EthDictionaryService } from './dictionary/ethDictionary.service';
|
|
11
9
|
import { DynamicDsService } from './dynamic-ds.service';
|
|
12
10
|
import { ProjectService } from './project.service';
|
|
13
11
|
import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
|
|
14
|
-
|
|
15
|
-
groupedOptions?: SubqlEthereumProcessorOptions[];
|
|
16
|
-
};
|
|
17
|
-
export declare function buildDictionaryQueryEntries(dataSources: GroupedEthereumProjectDs[]): DictionaryQueryEntry[];
|
|
18
|
-
export declare class FetchService extends BaseFetchService<SubqlDatasource, IEthereumBlockDispatcher, DictionaryService> {
|
|
12
|
+
export declare class FetchService extends BaseFetchService<SubqlDatasource, IEthereumBlockDispatcher, EthereumBlock> {
|
|
19
13
|
private apiService;
|
|
20
14
|
private unfinalizedBlocksService;
|
|
21
|
-
constructor(apiService: ApiService, nodeConfig: NodeConfig, projectService: ProjectService, project: SubqueryProject, blockDispatcher: IEthereumBlockDispatcher, dictionaryService:
|
|
15
|
+
constructor(apiService: ApiService, nodeConfig: NodeConfig, projectService: ProjectService, project: SubqueryProject, blockDispatcher: IEthereumBlockDispatcher, dictionaryService: EthDictionaryService, dynamicDsService: DynamicDsService, unfinalizedBlocksService: UnfinalizedBlocksService, eventEmitter: EventEmitter2, schedulerRegistry: SchedulerRegistry);
|
|
22
16
|
get api(): EthereumApi;
|
|
23
|
-
protected buildDictionaryQueryEntries(dataSources: (SubqlDatasource & {
|
|
24
|
-
name?: string;
|
|
25
|
-
})[]): DictionaryQueryEntry[];
|
|
26
17
|
protected getGenesisHash(): string;
|
|
27
18
|
protected getFinalizedHeight(): Promise<number>;
|
|
28
19
|
protected getBestHeight(): Promise<number>;
|
|
@@ -31,4 +22,3 @@ export declare class FetchService extends BaseFetchService<SubqlDatasource, IEth
|
|
|
31
22
|
protected initBlockDispatcher(): Promise<void>;
|
|
32
23
|
protected preLoopHook(): Promise<void>;
|
|
33
24
|
}
|
|
34
|
-
export {};
|
|
@@ -14,177 +14,20 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
14
14
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.FetchService =
|
|
17
|
+
exports.FetchService = void 0;
|
|
18
18
|
const common_1 = require("@nestjs/common");
|
|
19
19
|
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
20
20
|
const schedule_1 = require("@nestjs/schedule");
|
|
21
21
|
const common_ethereum_1 = require("@subql/common-ethereum");
|
|
22
22
|
const node_core_1 = require("@subql/node-core");
|
|
23
|
-
const lodash_1 = require("lodash");
|
|
24
23
|
const SubqueryProject_1 = require("../configure/SubqueryProject");
|
|
25
24
|
const utils_ethereum_1 = require("../ethereum/utils.ethereum");
|
|
26
|
-
const
|
|
27
|
-
const yargs_1 = require("../yargs");
|
|
28
|
-
const dictionary_service_1 = require("./dictionary.service");
|
|
25
|
+
const ethDictionary_service_1 = require("./dictionary/ethDictionary.service");
|
|
29
26
|
const dynamic_ds_service_1 = require("./dynamic-ds.service");
|
|
30
27
|
const project_service_1 = require("./project.service");
|
|
31
28
|
const unfinalizedBlocks_service_1 = require("./unfinalizedBlocks.service");
|
|
32
|
-
const logger = (0, node_core_1.getLogger)('fetch.service');
|
|
33
29
|
const BLOCK_TIME_VARIANCE = 5000;
|
|
34
30
|
const INTERVAL_PERCENT = 0.9;
|
|
35
|
-
function appendDsOptions(dsOptions, conditions) {
|
|
36
|
-
const queryAddressLimit = yargs_1.yargsOptions.argv['query-address-limit'];
|
|
37
|
-
if (Array.isArray(dsOptions)) {
|
|
38
|
-
const addresses = dsOptions.map((option) => option.address).filter(Boolean);
|
|
39
|
-
if (addresses.length > queryAddressLimit) {
|
|
40
|
-
logger.debug(`Addresses length: ${addresses.length} is exceeding limit: ${queryAddressLimit}. Consider increasing this value with the flag --query-address-limit `);
|
|
41
|
-
}
|
|
42
|
-
if (addresses.length !== 0 && addresses.length <= queryAddressLimit) {
|
|
43
|
-
conditions.push({
|
|
44
|
-
field: 'address',
|
|
45
|
-
value: addresses,
|
|
46
|
-
matcher: 'in',
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
if (dsOptions === null || dsOptions === void 0 ? void 0 : dsOptions.address) {
|
|
52
|
-
conditions.push({
|
|
53
|
-
field: 'address',
|
|
54
|
-
value: dsOptions.address.toLowerCase(),
|
|
55
|
-
matcher: 'equalTo',
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function eventFilterToQueryEntry(filter, dsOptions) {
|
|
61
|
-
const conditions = [];
|
|
62
|
-
appendDsOptions(dsOptions, conditions);
|
|
63
|
-
if (filter.topics) {
|
|
64
|
-
for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {
|
|
65
|
-
const topic = filter.topics[i];
|
|
66
|
-
if (!topic) {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
const field = `topics${i}`;
|
|
70
|
-
if (topic === '!null') {
|
|
71
|
-
conditions.push({
|
|
72
|
-
field,
|
|
73
|
-
value: false,
|
|
74
|
-
matcher: 'isNull',
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
conditions.push({
|
|
79
|
-
field,
|
|
80
|
-
value: (0, string_1.eventToTopic)(topic),
|
|
81
|
-
matcher: 'equalTo',
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return {
|
|
87
|
-
entity: 'evmLogs',
|
|
88
|
-
conditions,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
function callFilterToQueryEntry(filter, dsOptions) {
|
|
92
|
-
const conditions = [];
|
|
93
|
-
appendDsOptions(dsOptions, conditions);
|
|
94
|
-
for (const condition of conditions) {
|
|
95
|
-
if (condition.field === 'address') {
|
|
96
|
-
condition.field = 'to';
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (filter.from) {
|
|
100
|
-
conditions.push({
|
|
101
|
-
field: 'from',
|
|
102
|
-
value: filter.from.toLowerCase(),
|
|
103
|
-
matcher: 'equalTo',
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
const optionsAddresses = conditions.find((c) => c.field === 'to');
|
|
107
|
-
if (!optionsAddresses) {
|
|
108
|
-
if (filter.to) {
|
|
109
|
-
conditions.push({
|
|
110
|
-
field: 'to',
|
|
111
|
-
value: filter.to.toLowerCase(),
|
|
112
|
-
matcher: 'equalTo',
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
else if (filter.to === null) {
|
|
116
|
-
conditions.push({
|
|
117
|
-
field: 'to',
|
|
118
|
-
value: true,
|
|
119
|
-
matcher: 'isNull',
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
else if (optionsAddresses && (filter.to || filter.to === null)) {
|
|
124
|
-
logger.warn(`TransactionFilter 'to' conflict with 'address' in data source options`);
|
|
125
|
-
}
|
|
126
|
-
if (filter.function === null || filter.function === '0x') {
|
|
127
|
-
conditions.push({
|
|
128
|
-
field: 'func',
|
|
129
|
-
value: true,
|
|
130
|
-
matcher: 'isNull',
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
else if (filter.function) {
|
|
134
|
-
conditions.push({
|
|
135
|
-
field: 'func',
|
|
136
|
-
value: (0, string_1.functionToSighash)(filter.function),
|
|
137
|
-
matcher: 'equalTo',
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
return {
|
|
141
|
-
entity: 'evmTransactions',
|
|
142
|
-
conditions,
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
function buildDictionaryQueryEntries(dataSources) {
|
|
146
|
-
var _a;
|
|
147
|
-
const queryEntries = [];
|
|
148
|
-
for (const ds of dataSources) {
|
|
149
|
-
for (const handler of ds.mapping.handlers) {
|
|
150
|
-
// No filters, cant use dictionary
|
|
151
|
-
if (!handler.filter)
|
|
152
|
-
return [];
|
|
153
|
-
switch (handler.kind) {
|
|
154
|
-
case common_ethereum_1.EthereumHandlerKind.Block:
|
|
155
|
-
return [];
|
|
156
|
-
case common_ethereum_1.EthereumHandlerKind.Call: {
|
|
157
|
-
const filter = handler.filter;
|
|
158
|
-
if (filter.from !== undefined ||
|
|
159
|
-
filter.to !== undefined ||
|
|
160
|
-
filter.function !== undefined) {
|
|
161
|
-
queryEntries.push(callFilterToQueryEntry(filter, ds.options));
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
return [];
|
|
165
|
-
}
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
case common_ethereum_1.EthereumHandlerKind.Event: {
|
|
169
|
-
const filter = handler.filter;
|
|
170
|
-
if (ds.groupedOptions) {
|
|
171
|
-
queryEntries.push(eventFilterToQueryEntry(filter, ds.groupedOptions));
|
|
172
|
-
}
|
|
173
|
-
else if (((_a = ds.options) === null || _a === void 0 ? void 0 : _a.address) || filter.topics) {
|
|
174
|
-
queryEntries.push(eventFilterToQueryEntry(filter, ds.options));
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
return [];
|
|
178
|
-
}
|
|
179
|
-
break;
|
|
180
|
-
}
|
|
181
|
-
default:
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return (0, lodash_1.uniqBy)(queryEntries, (item) => `${item.entity}|${JSON.stringify((0, lodash_1.sortBy)(item.conditions, (c) => c.field))}`);
|
|
186
|
-
}
|
|
187
|
-
exports.buildDictionaryQueryEntries = buildDictionaryQueryEntries;
|
|
188
31
|
let FetchService = class FetchService extends node_core_1.BaseFetchService {
|
|
189
32
|
constructor(apiService, nodeConfig, projectService, project, blockDispatcher, dictionaryService, dynamicDsService, unfinalizedBlocksService, eventEmitter, schedulerRegistry) {
|
|
190
33
|
super(nodeConfig, projectService, project.network, blockDispatcher, dictionaryService, dynamicDsService, eventEmitter, schedulerRegistry);
|
|
@@ -194,28 +37,12 @@ let FetchService = class FetchService extends node_core_1.BaseFetchService {
|
|
|
194
37
|
get api() {
|
|
195
38
|
return this.apiService.unsafeApi;
|
|
196
39
|
}
|
|
197
|
-
buildDictionaryQueryEntries(
|
|
198
|
-
// Add name to dataousrces as templates have this set
|
|
199
|
-
dataSources) {
|
|
200
|
-
const [normalDataSources, templateDataSources] = (0, lodash_1.partition)(dataSources, (ds) => !ds.name);
|
|
201
|
-
// Group templ
|
|
202
|
-
const groupedDataSources = Object.values((0, lodash_1.groupBy)(templateDataSources, (ds) => ds.name)).map((grouped) => {
|
|
203
|
-
if (grouped.length === 1) {
|
|
204
|
-
return grouped[0];
|
|
205
|
-
}
|
|
206
|
-
const options = grouped.map((ds) => ds.options);
|
|
207
|
-
const ref = grouped[0];
|
|
208
|
-
return Object.assign(Object.assign({}, ref), { groupedOptions: options });
|
|
209
|
-
});
|
|
210
|
-
const filteredDs = [...normalDataSources, ...groupedDataSources];
|
|
211
|
-
return buildDictionaryQueryEntries(filteredDs);
|
|
212
|
-
}
|
|
213
40
|
getGenesisHash() {
|
|
214
41
|
return this.apiService.networkMeta.genesisHash;
|
|
215
42
|
}
|
|
216
43
|
async getFinalizedHeight() {
|
|
217
44
|
const block = await this.api.getFinalizedBlock();
|
|
218
|
-
const header = (0,
|
|
45
|
+
const header = (0, utils_ethereum_1.ethereumBlockToHeader)(block);
|
|
219
46
|
this.unfinalizedBlocksService.registerFinalizedBlock(header);
|
|
220
47
|
return header.blockHeight;
|
|
221
48
|
}
|
|
@@ -246,7 +73,7 @@ FetchService = __decorate([
|
|
|
246
73
|
__metadata("design:paramtypes", [node_core_1.ApiService,
|
|
247
74
|
node_core_1.NodeConfig,
|
|
248
75
|
project_service_1.ProjectService,
|
|
249
|
-
SubqueryProject_1.SubqueryProject, Object,
|
|
76
|
+
SubqueryProject_1.SubqueryProject, Object, ethDictionary_service_1.EthDictionaryService,
|
|
250
77
|
dynamic_ds_service_1.DynamicDsService,
|
|
251
78
|
unfinalizedBlocks_service_1.UnfinalizedBlocksService,
|
|
252
79
|
event_emitter_1.EventEmitter2,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.service.js","sourceRoot":"","sources":["../../src/indexer/fetch.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,yDAAsD;AACtD,+CAAqD;AAErD,4DAMgC;AAChC,gDAM0B;AAM1B,mCAA4D;AAC5D,kEAA+D;AAE/D,+DAA0D;AAC1D,4CAAkE;AAClE,oCAAwC;AAExC,6DAAyD;AACzD,6DAAwD;AACxD,uDAAmD;AACnD,2EAGqC;AAErC,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,eAAe,CAAC,CAAC;AAE1C,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAEjC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAE7B,SAAS,eAAe,CACtB,SAA0E,EAC1E,UAAsC;IAEtC,MAAM,iBAAiB,GAAG,oBAAY,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACnE,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;QAC5B,MAAM,SAAS,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAE5E,IAAI,SAAS,CAAC,MAAM,GAAG,iBAAiB,EAAE;YACxC,MAAM,CAAC,KAAK,CACV,qBAAqB,SAAS,CAAC,MAAM,wBAAwB,iBAAiB,wEAAwE,CACvJ,CAAC;SACH;QAED,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,SAAS,CAAC,MAAM,IAAI,iBAAiB,EAAE;YACnE,UAAU,CAAC,IAAI,CAAC;gBACd,KAAK,EAAE,SAAS;gBAChB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,gBAAgB;QAC9B,MAAM,cAAc,GAAG,IAAA,6BAAY,EAAC,IAAI,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC;QAEjE,OAAO,IAAI,CAAC,GAAG,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAC;IACvD,CAAC;IAES,UAAU;QAClB,OAAO,IAAA,sBAAU,EACf,IAAI,CAAC,cAAc,CAAC,iBAAiB,EAAE,EACvC,4BAAU,EACV,qCAAmB,CAAC,KAAK,CAC1B,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,mBAAmB;QACjC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACjE,CAAC;IAES,KAAK,CAAC,WAAW;QACzB,4CAA4C;QAC5C,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF,CAAA;AAzGY,YAAY;IADxB,IAAA,mBAAU,GAAE;IASR,WAAA,IAAA,eAAM,EAAC,iBAAiB,CAAC,CAAA;IACzB,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;IAC1B,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;qCAJP,sBAAU;QAClB,sBAAU;QACqB,gCAAc;QACpB,iCAAe,UAGjC,sCAAiB;QAClB,qCAAgB;QACA,oDAAwB;QAC5C,6BAAa;QACR,4BAAiB;GAhB3B,YAAY,CAyGxB;AAzGY,oCAAY","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { SchedulerRegistry } from '@nestjs/schedule';\n\nimport {\n isCustomDs,\n EthereumHandlerKind,\n EthereumLogFilter,\n SubqlEthereumProcessorOptions,\n EthereumTransactionFilter,\n} from '@subql/common-ethereum';\nimport {\n NodeConfig,\n BaseFetchService,\n ApiService,\n getLogger,\n getModulos,\n} from '@subql/node-core';\nimport {\n DictionaryQueryCondition,\n DictionaryQueryEntry,\n} from '@subql/types-core';\nimport { SubqlDatasource } from '@subql/types-ethereum';\nimport { groupBy, partition, sortBy, uniqBy } from 'lodash';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { EthereumApi } from '../ethereum';\nimport { calcInterval } from '../ethereum/utils.ethereum';\nimport { eventToTopic, functionToSighash } from '../utils/string';\nimport { yargsOptions } from '../yargs';\nimport { IEthereumBlockDispatcher } from './blockDispatcher';\nimport { DictionaryService } from './dictionary.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { ProjectService } from './project.service';\nimport {\n blockToHeader,\n UnfinalizedBlocksService,\n} from './unfinalizedBlocks.service';\n\nconst logger = getLogger('fetch.service');\n\nconst BLOCK_TIME_VARIANCE = 5000;\n\nconst INTERVAL_PERCENT = 0.9;\n\nfunction appendDsOptions(\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n conditions: DictionaryQueryCondition[],\n): void {\n const queryAddressLimit = yargsOptions.argv['query-address-limit'];\n if (Array.isArray(dsOptions)) {\n const addresses = dsOptions.map((option) => option.address).filter(Boolean);\n\n if (addresses.length > queryAddressLimit) {\n logger.debug(\n `Addresses length: ${addresses.length} is exceeding limit: ${queryAddressLimit}. Consider increasing this value with the flag --query-address-limit `,\n );\n }\n\n if (addresses.length !== 0 && addresses.length <= queryAddressLimit) {\n conditions.push({\n field: 'address',\n value: addresses,\n matcher: 'in',\n });\n }\n } else {\n if (dsOptions?.address) {\n conditions.push({\n field: 'address',\n value: dsOptions.address.toLowerCase(),\n matcher: 'equalTo',\n });\n }\n }\n}\n\nfunction eventFilterToQueryEntry(\n filter: EthereumLogFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): DictionaryQueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n appendDsOptions(dsOptions, conditions);\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\n if (topic === '!null') {\n conditions.push({\n field,\n value: false as any, // TODO update types to allow boolean\n matcher: 'isNull',\n });\n } else {\n conditions.push({\n field,\n value: eventToTopic(topic),\n matcher: 'equalTo',\n });\n }\n }\n }\n return {\n entity: 'evmLogs',\n conditions,\n };\n}\n\nfunction callFilterToQueryEntry(\n filter: EthereumTransactionFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): DictionaryQueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n appendDsOptions(dsOptions, conditions);\n\n for (const condition of conditions) {\n if (condition.field === 'address') {\n condition.field = 'to';\n }\n }\n if (filter.from) {\n conditions.push({\n field: 'from',\n value: filter.from.toLowerCase(),\n matcher: 'equalTo',\n });\n }\n const optionsAddresses = conditions.find((c) => c.field === 'to');\n if (!optionsAddresses) {\n if (filter.to) {\n conditions.push({\n field: 'to',\n value: filter.to.toLowerCase(),\n matcher: 'equalTo',\n });\n } else if (filter.to === null) {\n conditions.push({\n field: 'to',\n value: true as any, // TODO update types to allow boolean\n matcher: 'isNull',\n });\n }\n } else if (optionsAddresses && (filter.to || filter.to === null)) {\n logger.warn(\n `TransactionFilter 'to' conflict with 'address' in data source options`,\n );\n }\n\n if (filter.function === null || filter.function === '0x') {\n conditions.push({\n field: 'func',\n value: true,\n matcher: 'isNull',\n });\n } else if (filter.function) {\n conditions.push({\n field: 'func',\n value: functionToSighash(filter.function),\n matcher: 'equalTo',\n });\n }\n\n return {\n entity: 'evmTransactions',\n conditions,\n };\n}\n\ntype GroupedEthereumProjectDs = SubqlDatasource & {\n groupedOptions?: SubqlEthereumProcessorOptions[];\n};\nexport function buildDictionaryQueryEntries(\n dataSources: GroupedEthereumProjectDs[],\n): DictionaryQueryEntry[] {\n const queryEntries: DictionaryQueryEntry[] = [];\n\n for (const ds of dataSources) {\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 !== undefined\n ) {\n queryEntries.push(callFilterToQueryEntry(filter, ds.options));\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@Injectable()\nexport class FetchService extends BaseFetchService<\n SubqlDatasource,\n IEthereumBlockDispatcher,\n DictionaryService\n> {\n constructor(\n private apiService: ApiService,\n nodeConfig: NodeConfig,\n @Inject('IProjectService') projectService: ProjectService,\n @Inject('ISubqueryProject') project: SubqueryProject,\n @Inject('IBlockDispatcher')\n blockDispatcher: IEthereumBlockDispatcher,\n dictionaryService: DictionaryService,\n dynamicDsService: DynamicDsService,\n private unfinalizedBlocksService: UnfinalizedBlocksService,\n eventEmitter: EventEmitter2,\n schedulerRegistry: SchedulerRegistry,\n ) {\n super(\n nodeConfig,\n projectService,\n project.network,\n blockDispatcher,\n dictionaryService,\n dynamicDsService,\n eventEmitter,\n schedulerRegistry,\n );\n }\n\n get api(): EthereumApi {\n return this.apiService.unsafeApi;\n }\n\n protected buildDictionaryQueryEntries(\n // Add name to dataousrces as templates have this set\n dataSources: (SubqlDatasource & { name?: string })[],\n ): DictionaryQueryEntry[] {\n const [normalDataSources, templateDataSources] = partition(\n dataSources,\n (ds) => !ds.name,\n );\n\n // Group templ\n const groupedDataSources = Object.values(\n groupBy(templateDataSources, (ds) => ds.name),\n ).map((grouped) => {\n if (grouped.length === 1) {\n return grouped[0];\n }\n\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 const filteredDs = [...normalDataSources, ...groupedDataSources];\n\n return buildDictionaryQueryEntries(filteredDs);\n }\n\n protected getGenesisHash(): string {\n return this.apiService.networkMeta.genesisHash;\n }\n\n protected async getFinalizedHeight(): Promise<number> {\n const block = await this.api.getFinalizedBlock();\n\n const header = blockToHeader(block);\n\n this.unfinalizedBlocksService.registerFinalizedBlock(header);\n return header.blockHeight;\n }\n\n protected async getBestHeight(): Promise<number> {\n return this.api.getBestBlockHeight();\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n protected async getChainInterval(): Promise<number> {\n const CHAIN_INTERVAL = calcInterval(this.api) * INTERVAL_PERCENT;\n\n return Math.min(BLOCK_TIME_VARIANCE, CHAIN_INTERVAL);\n }\n\n protected getModulos(): number[] {\n return getModulos(\n this.projectService.getAllDataSources(),\n isCustomDs,\n EthereumHandlerKind.Block,\n );\n }\n\n protected async initBlockDispatcher(): Promise<void> {\n await this.blockDispatcher.init(this.resetForNewDs.bind(this));\n }\n\n protected async preLoopHook(): Promise<void> {\n // Ethereum doesn't need to do anything here\n return Promise.resolve();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fetch.service.js","sourceRoot":"","sources":["../../src/indexer/fetch.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,yDAAsD;AACtD,+CAAqD;AAErD,4DAAyE;AACzE,gDAK0B;AAE1B,kEAA+D;AAE/D,+DAGoC;AAEpC,8EAA0E;AAC1E,6DAAwD;AACxD,uDAAmD;AACnD,2EAAuE;AAEvE,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAEjC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAGtB,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EACvC,4BAAU,EACV,qCAAmB,CAAC,KAAK,CAC1B,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,mBAAmB;QACjC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACjE,CAAC;IAES,KAAK,CAAC,WAAW;QACzB,4CAA4C;QAC5C,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF,CAAA;AA1EY,YAAY;IADxB,IAAA,mBAAU,GAAE;IASR,WAAA,IAAA,eAAM,EAAC,iBAAiB,CAAC,CAAA;IACzB,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;IAC1B,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;qCAJP,sBAAU;QAClB,sBAAU;QACqB,gCAAc;QACpB,iCAAe,UAGjC,4CAAoB;QACrB,qCAAgB;QACA,oDAAwB;QAC5C,6BAAa;QACR,4BAAiB;GAhB3B,YAAY,CA0ExB;AA1EY,oCAAY","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { SchedulerRegistry } from '@nestjs/schedule';\n\nimport { isCustomDs, EthereumHandlerKind } from '@subql/common-ethereum';\nimport {\n NodeConfig,\n BaseFetchService,\n ApiService,\n getModulos,\n} from '@subql/node-core';\nimport { EthereumBlock, SubqlDatasource } from '@subql/types-ethereum';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { EthereumApi } from '../ethereum';\nimport {\n calcInterval,\n ethereumBlockToHeader,\n} from '../ethereum/utils.ethereum';\nimport { IEthereumBlockDispatcher } from './blockDispatcher';\nimport { EthDictionaryService } from './dictionary/ethDictionary.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { ProjectService } from './project.service';\nimport { UnfinalizedBlocksService } from './unfinalizedBlocks.service';\n\nconst BLOCK_TIME_VARIANCE = 5000;\n\nconst INTERVAL_PERCENT = 0.9;\n\n@Injectable()\nexport class FetchService extends BaseFetchService<\n SubqlDatasource,\n IEthereumBlockDispatcher,\n EthereumBlock\n> {\n constructor(\n private apiService: ApiService,\n nodeConfig: NodeConfig,\n @Inject('IProjectService') projectService: ProjectService,\n @Inject('ISubqueryProject') project: SubqueryProject,\n @Inject('IBlockDispatcher')\n blockDispatcher: IEthereumBlockDispatcher,\n dictionaryService: EthDictionaryService,\n dynamicDsService: DynamicDsService,\n private unfinalizedBlocksService: UnfinalizedBlocksService,\n eventEmitter: EventEmitter2,\n schedulerRegistry: SchedulerRegistry,\n ) {\n super(\n nodeConfig,\n projectService,\n project.network,\n blockDispatcher,\n dictionaryService,\n dynamicDsService,\n eventEmitter,\n schedulerRegistry,\n );\n }\n\n get api(): EthereumApi {\n return this.apiService.unsafeApi;\n }\n\n protected getGenesisHash(): string {\n return this.apiService.networkMeta.genesisHash;\n }\n\n protected async getFinalizedHeight(): Promise<number> {\n const block = await this.api.getFinalizedBlock();\n\n const header = ethereumBlockToHeader(block);\n\n this.unfinalizedBlocksService.registerFinalizedBlock(header);\n return header.blockHeight;\n }\n\n protected async getBestHeight(): Promise<number> {\n return this.api.getBestBlockHeight();\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n protected async getChainInterval(): Promise<number> {\n const CHAIN_INTERVAL = calcInterval(this.api) * INTERVAL_PERCENT;\n\n return Math.min(BLOCK_TIME_VARIANCE, CHAIN_INTERVAL);\n }\n\n protected getModulos(): number[] {\n return getModulos(\n this.projectService.getAllDataSources(),\n isCustomDs,\n EthereumHandlerKind.Block,\n );\n }\n\n protected async initBlockDispatcher(): Promise<void> {\n await this.blockDispatcher.init(this.resetForNewDs.bind(this));\n }\n\n protected async preLoopHook(): Promise<void> {\n // Ethereum doesn't need to do anything here\n return Promise.resolve();\n }\n}\n"]}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { isBlockHandlerProcessor, isCallHandlerProcessor, isEventHandlerProcessor, isCustomDs, isRuntimeDs, SubqlEthereumCustomDataSource, EthereumHandlerKind, EthereumRuntimeHandlerInputMap, SubqlEthereumDataSource } from '@subql/common-ethereum';
|
|
2
|
-
import { NodeConfig, IndexerSandbox, ProcessBlockResponse, BaseIndexerManager,
|
|
2
|
+
import { NodeConfig, IndexerSandbox, ProcessBlockResponse, BaseIndexerManager, IBlock } from '@subql/node-core';
|
|
3
3
|
import { EthereumTransaction, EthereumLog, EthereumBlock, SubqlRuntimeDatasource, EthereumBlockFilter, EthereumLogFilter, EthereumTransactionFilter, LightEthereumLog } from '@subql/types-ethereum';
|
|
4
4
|
import { EthereumProjectDs } from '../configure/SubqueryProject';
|
|
5
|
-
import { EthereumApi } from '../ethereum';
|
|
5
|
+
import { EthereumApi, EthereumApiService } from '../ethereum';
|
|
6
6
|
import SafeEthProvider from '../ethereum/safe-api';
|
|
7
7
|
import { asSecondLayerHandlerProcessor_1_0_0, DsProcessorService } from './ds-processor.service';
|
|
8
8
|
import { DynamicDsService } from './dynamic-ds.service';
|
|
9
9
|
import { SandboxService } from './sandbox.service';
|
|
10
10
|
import { BlockContent } from './types';
|
|
11
11
|
import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
|
|
12
|
-
export declare class IndexerManager extends BaseIndexerManager<SafeEthProvider, EthereumApi, BlockContent,
|
|
12
|
+
export declare class IndexerManager extends BaseIndexerManager<SafeEthProvider, EthereumApi, BlockContent, EthereumApiService, SubqlEthereumDataSource, SubqlEthereumCustomDataSource, typeof FilterTypeMap, typeof ProcessorTypeMap, EthereumRuntimeHandlerInputMap> {
|
|
13
13
|
protected isRuntimeDs: typeof isRuntimeDs;
|
|
14
14
|
protected isCustomDs: typeof isCustomDs;
|
|
15
15
|
protected updateCustomProcessor: typeof asSecondLayerHandlerProcessor_1_0_0;
|
|
16
|
-
constructor(apiService:
|
|
17
|
-
indexBlock(block: BlockContent
|
|
16
|
+
constructor(apiService: EthereumApiService, nodeConfig: NodeConfig, sandboxService: SandboxService, dsProcessorService: DsProcessorService, dynamicDsService: DynamicDsService, unfinalizedBlocksService: UnfinalizedBlocksService);
|
|
17
|
+
indexBlock(block: IBlock<BlockContent>, dataSources: SubqlEthereumDataSource[]): Promise<ProcessBlockResponse>;
|
|
18
18
|
getBlockHeight(block: BlockContent): number;
|
|
19
19
|
getBlockHash(block: BlockContent): string;
|
|
20
20
|
private getApi;
|
|
@@ -15,12 +15,12 @@ exports.IndexerManager = void 0;
|
|
|
15
15
|
const common_1 = require("@nestjs/common");
|
|
16
16
|
const common_ethereum_1 = require("@subql/common-ethereum");
|
|
17
17
|
const node_core_1 = require("@subql/node-core");
|
|
18
|
+
const ethereum_1 = require("../ethereum");
|
|
18
19
|
const block_ethereum_1 = require("../ethereum/block.ethereum");
|
|
19
20
|
const ds_processor_service_1 = require("./ds-processor.service");
|
|
20
21
|
const dynamic_ds_service_1 = require("./dynamic-ds.service");
|
|
21
22
|
const sandbox_service_1 = require("./sandbox.service");
|
|
22
23
|
const unfinalizedBlocks_service_1 = require("./unfinalizedBlocks.service");
|
|
23
|
-
const logger = (0, node_core_1.getLogger)('indexer');
|
|
24
24
|
let IndexerManager = class IndexerManager extends node_core_1.BaseIndexerManager {
|
|
25
25
|
constructor(apiService, nodeConfig, sandboxService, dsProcessorService, dynamicDsService, unfinalizedBlocksService) {
|
|
26
26
|
super(apiService, nodeConfig, sandboxService, dsProcessorService, dynamicDsService, unfinalizedBlocksService, FilterTypeMap, ProcessorTypeMap);
|
|
@@ -29,7 +29,7 @@ let IndexerManager = class IndexerManager extends node_core_1.BaseIndexerManager
|
|
|
29
29
|
this.updateCustomProcessor = ds_processor_service_1.asSecondLayerHandlerProcessor_1_0_0;
|
|
30
30
|
}
|
|
31
31
|
async indexBlock(block, dataSources) {
|
|
32
|
-
return super.internalIndexBlock(block, dataSources, () => this.getApi(block));
|
|
32
|
+
return super.internalIndexBlock(block, dataSources, () => this.getApi(block.block));
|
|
33
33
|
}
|
|
34
34
|
getBlockHeight(block) {
|
|
35
35
|
return block.number;
|
|
@@ -86,7 +86,7 @@ __decorate([
|
|
|
86
86
|
], IndexerManager.prototype, "indexBlock", null);
|
|
87
87
|
IndexerManager = __decorate([
|
|
88
88
|
(0, common_1.Injectable)(),
|
|
89
|
-
__metadata("design:paramtypes", [
|
|
89
|
+
__metadata("design:paramtypes", [ethereum_1.EthereumApiService,
|
|
90
90
|
node_core_1.NodeConfig,
|
|
91
91
|
sandbox_service_1.SandboxService,
|
|
92
92
|
ds_processor_service_1.DsProcessorService,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexer.manager.js","sourceRoot":"","sources":["../../src/indexer/indexer.manager.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,4DAUgC;AAChC,gDAQ0B;AAa1B,+DAKoC;AAEpC,iEAGgC;AAChC,6DAAwD;AACxD,uDAAmD;AAEnD,2EAAuE;AAEvE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,SAAS,CAAC,CAAC;AAG7B,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,8BAUnC;IAKC,YACE,UAAsB,EACtB,UAAsB,EACtB,cAA8B,EAC9B,kBAAsC,EACtC,gBAAkC,EAClC,wBAAkD;QAElD,KAAK,CACH,UAAU,EACV,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,wBAAwB,EACxB,aAAa,EACb,gBAAgB,CACjB,CAAC;QArBM,gBAAW,GAAG,6BAAW,CAAC;QAC1B,eAAU,GAAG,4BAAU,CAAC;QACxB,0BAAqB,GAAG,0DAAmC,CAAC;IAoBtE,CAAC;IAGK,AAAN,KAAK,CAAC,UAAU,CACd,KAAmB,EACnB,WAAsC;QAEtC,OAAO,KAAK,CAAC,kBAAkB,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,CACvD,IAAI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,EAC3B,EAAE,WAAC,OAAA,IAAA,sCAAqB,EAAC,IAAI,EAAE,MAAM,EAAE,MAAA,EAAE,CAAC,OAAO,0CAAE,OAAO,CAAC,CAAA,EAAA;IAC7D,CAAC,qCAAmB,CAAC,KAAK,CAAC,EAAE,CAC3B,IAAoC,EACpC,MAAyB,EACzB,EAA2B,EAC3B,EAAE,WAAC,OAAA,IAAA,oCAAmB,EAAC,IAAI,EAAE,MAAM,EAAE,MAAA,EAAE,CAAC,OAAO,0CAAE,OAAO,CAAC,CAAA,EAAA;IAC3D,CAAC,qCAAmB,CAAC,IAAI,CAAC,EAAE,CAC1B,IAAyB,EACzB,MAAiC,EACjC,EAA2B,EAC3B,EAAE,WAAC,OAAA,IAAA,4CAA2B,EAAC,IAAI,EAAE,MAAM,EAAE,MAAA,EAAE,CAAC,OAAO,0CAAE,OAAO,CAAC,CAAA,EAAA;CACpE,CAAC;AAEF,MAAM,aAAa,GAAG;IACpB,CAAC,qCAAmB,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,IAAmB,EAAE,EAAE,CAAC,IAAI;IAChE,CAAC,qCAAmB,CAAC,KAAK,CAAC,EACzB,CAAC,GAAgB,EAAE,EAAE,CACrB,CAAC,IAAoC,EAAE,EAA0B,EAAE,EAAE,CACnE,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC;IAC1B,CAAC,qCAAmB,CAAC,IAAI,CAAC,EACxB,CAAC,GAAgB,EAAE,EAAE,CACrB,CAAC,IAAyB,EAAE,EAA0B,EAAE,EAAE,CACxD,GAAG,CAAC,gBAAgB,CAAC,IAAI,EAAE,EAAE,CAAC;CACnC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport {\n isBlockHandlerProcessor,\n isCallHandlerProcessor,\n isEventHandlerProcessor,\n isCustomDs,\n isRuntimeDs,\n SubqlEthereumCustomDataSource,\n EthereumHandlerKind,\n EthereumRuntimeHandlerInputMap,\n SubqlEthereumDataSource,\n} from '@subql/common-ethereum';\nimport {\n NodeConfig,\n getLogger,\n profiler,\n IndexerSandbox,\n ProcessBlockResponse,\n BaseIndexerManager,\n ApiService,\n} from '@subql/node-core';\nimport {\n EthereumTransaction,\n EthereumLog,\n EthereumBlock,\n SubqlRuntimeDatasource,\n EthereumBlockFilter,\n EthereumLogFilter,\n EthereumTransactionFilter,\n LightEthereumLog,\n} from '@subql/types-ethereum';\nimport { EthereumProjectDs } from '../configure/SubqueryProject';\nimport { EthereumApi } from '../ethereum';\nimport {\n filterBlocksProcessor,\n filterLogsProcessor,\n filterTransactionsProcessor,\n isFullBlock,\n} from '../ethereum/block.ethereum';\nimport SafeEthProvider from '../ethereum/safe-api';\nimport {\n asSecondLayerHandlerProcessor_1_0_0,\n DsProcessorService,\n} from './ds-processor.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { SandboxService } from './sandbox.service';\nimport { BlockContent } from './types';\nimport { UnfinalizedBlocksService } from './unfinalizedBlocks.service';\n\nconst logger = getLogger('indexer');\n\n@Injectable()\nexport class IndexerManager extends BaseIndexerManager<\n SafeEthProvider,\n EthereumApi,\n BlockContent,\n ApiService,\n SubqlEthereumDataSource,\n SubqlEthereumCustomDataSource,\n typeof FilterTypeMap,\n typeof ProcessorTypeMap,\n EthereumRuntimeHandlerInputMap\n> {\n protected isRuntimeDs = isRuntimeDs;\n protected isCustomDs = isCustomDs;\n protected updateCustomProcessor = asSecondLayerHandlerProcessor_1_0_0;\n\n constructor(\n apiService: ApiService,\n nodeConfig: NodeConfig,\n sandboxService: SandboxService,\n dsProcessorService: DsProcessorService,\n dynamicDsService: DynamicDsService,\n unfinalizedBlocksService: UnfinalizedBlocksService,\n ) {\n super(\n apiService,\n nodeConfig,\n sandboxService,\n dsProcessorService,\n dynamicDsService,\n unfinalizedBlocksService,\n FilterTypeMap,\n ProcessorTypeMap,\n );\n }\n\n @profiler()\n async indexBlock(\n block: BlockContent,\n dataSources: SubqlEthereumDataSource[],\n ): Promise<ProcessBlockResponse> {\n return super.internalIndexBlock(block, dataSources, () =>\n this.getApi(block),\n );\n }\n\n getBlockHeight(block: BlockContent): number {\n return block.number;\n }\n\n getBlockHash(block: BlockContent): string {\n return block.hash;\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n private async getApi(block: BlockContent): Promise<SafeEthProvider> {\n return this.apiService.safeApi(this.getBlockHeight(block));\n }\n\n protected async indexBlockData(\n block: BlockContent,\n dataSources: EthereumProjectDs[],\n getVM: (d: EthereumProjectDs) => Promise<IndexerSandbox>,\n ): Promise<void> {\n if (isFullBlock(block)) {\n await this.indexBlockContent(block, dataSources, getVM);\n\n for (const tx of block.transactions) {\n await this.indexTransaction(tx, dataSources, getVM);\n\n for (const log of tx.logs ?? []) {\n await this.indexEvent(log, dataSources, getVM);\n }\n }\n } else {\n for (const log of block.logs ?? []) {\n await this.indexEvent(log, dataSources, getVM);\n }\n }\n }\n\n private async indexBlockContent(\n block: EthereumBlock,\n dataSources: EthereumProjectDs[],\n getVM: (d: EthereumProjectDs) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(EthereumHandlerKind.Block, block, ds, getVM);\n }\n }\n\n private async indexTransaction(\n tx: EthereumTransaction,\n dataSources: EthereumProjectDs[],\n getVM: (d: EthereumProjectDs) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(EthereumHandlerKind.Call, tx, ds, getVM);\n }\n }\n\n private async indexEvent(\n log: EthereumLog | LightEthereumLog,\n dataSources: EthereumProjectDs[],\n getVM: (d: EthereumProjectDs) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(EthereumHandlerKind.Event, log, ds, getVM);\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n protected async prepareFilteredData(\n kind: EthereumHandlerKind,\n data: any,\n ds: SubqlRuntimeDatasource,\n ): Promise<any> {\n return DataAbiParser[kind](this.apiService.api)(data, ds);\n }\n}\n\ntype ProcessorTypeMap = {\n [EthereumHandlerKind.Block]: typeof isBlockHandlerProcessor;\n [EthereumHandlerKind.Event]: typeof isEventHandlerProcessor;\n [EthereumHandlerKind.Call]: typeof isCallHandlerProcessor;\n};\n\nconst ProcessorTypeMap = {\n [EthereumHandlerKind.Block]: isBlockHandlerProcessor,\n [EthereumHandlerKind.Event]: isEventHandlerProcessor,\n [EthereumHandlerKind.Call]: isCallHandlerProcessor,\n};\n\nconst FilterTypeMap = {\n [EthereumHandlerKind.Block]: (\n data: EthereumBlock,\n filter: EthereumBlockFilter,\n ds: SubqlEthereumDataSource,\n ) => filterBlocksProcessor(data, filter, ds.options?.address),\n [EthereumHandlerKind.Event]: (\n data: EthereumLog | LightEthereumLog,\n filter: EthereumLogFilter,\n ds: SubqlEthereumDataSource,\n ) => filterLogsProcessor(data, filter, ds.options?.address),\n [EthereumHandlerKind.Call]: (\n data: EthereumTransaction,\n filter: EthereumTransactionFilter,\n ds: SubqlEthereumDataSource,\n ) => filterTransactionsProcessor(data, filter, ds.options?.address),\n};\n\nconst DataAbiParser = {\n [EthereumHandlerKind.Block]: () => (data: EthereumBlock) => data,\n [EthereumHandlerKind.Event]:\n (api: EthereumApi) =>\n (data: EthereumLog | LightEthereumLog, ds: SubqlRuntimeDatasource) =>\n api.parseLog(data, ds),\n [EthereumHandlerKind.Call]:\n (api: EthereumApi) =>\n (data: EthereumTransaction, ds: SubqlRuntimeDatasource) =>\n api.parseTransaction(data, ds),\n};\n"]}
|
|
1
|
+
{"version":3,"file":"indexer.manager.js","sourceRoot":"","sources":["../../src/indexer/indexer.manager.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;AAEnC,2CAA4C;AAC5C,4DAUgC;AAChC,gDAQ0B;AAY1B,0CAA8D;AAC9D,+DAKoC;AAEpC,iEAGgC;AAChC,6DAAwD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EAAE,EAAE,CAAC,IAAI;IAChE,CAAC,qCAAmB,CAAC,KAAK,CAAC,EACzB,CAAC,GAAgB,EAAE,EAAE,CACrB,CAAC,IAAoC,EAAE,EAA0B,EAAE,EAAE,CACnE,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC;IAC1B,CAAC,qCAAmB,CAAC,IAAI,CAAC,EACxB,CAAC,GAAgB,EAAE,EAAE,CACrB,CAAC,IAAyB,EAAE,EAA0B,EAAE,EAAE,CACxD,GAAG,CAAC,gBAAgB,CAAC,IAAI,EAAE,EAAE,CAAC;CACnC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Injectable } from '@nestjs/common';\nimport {\n isBlockHandlerProcessor,\n isCallHandlerProcessor,\n isEventHandlerProcessor,\n isCustomDs,\n isRuntimeDs,\n SubqlEthereumCustomDataSource,\n EthereumHandlerKind,\n EthereumRuntimeHandlerInputMap,\n SubqlEthereumDataSource,\n} from '@subql/common-ethereum';\nimport {\n NodeConfig,\n getLogger,\n profiler,\n IndexerSandbox,\n ProcessBlockResponse,\n BaseIndexerManager,\n IBlock,\n} from '@subql/node-core';\nimport {\n EthereumTransaction,\n EthereumLog,\n EthereumBlock,\n SubqlRuntimeDatasource,\n EthereumBlockFilter,\n EthereumLogFilter,\n EthereumTransactionFilter,\n LightEthereumLog,\n} from '@subql/types-ethereum';\nimport { EthereumProjectDs } from '../configure/SubqueryProject';\nimport { EthereumApi, EthereumApiService } from '../ethereum';\nimport {\n filterBlocksProcessor,\n filterLogsProcessor,\n filterTransactionsProcessor,\n isFullBlock,\n} from '../ethereum/block.ethereum';\nimport SafeEthProvider from '../ethereum/safe-api';\nimport {\n asSecondLayerHandlerProcessor_1_0_0,\n DsProcessorService,\n} from './ds-processor.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { SandboxService } from './sandbox.service';\nimport { BlockContent } from './types';\nimport { UnfinalizedBlocksService } from './unfinalizedBlocks.service';\n\n@Injectable()\nexport class IndexerManager extends BaseIndexerManager<\n SafeEthProvider,\n EthereumApi,\n BlockContent,\n EthereumApiService,\n SubqlEthereumDataSource,\n SubqlEthereumCustomDataSource,\n typeof FilterTypeMap,\n typeof ProcessorTypeMap,\n EthereumRuntimeHandlerInputMap\n> {\n protected isRuntimeDs = isRuntimeDs;\n protected isCustomDs = isCustomDs;\n protected updateCustomProcessor = asSecondLayerHandlerProcessor_1_0_0;\n\n constructor(\n apiService: EthereumApiService,\n nodeConfig: NodeConfig,\n sandboxService: SandboxService,\n dsProcessorService: DsProcessorService,\n dynamicDsService: DynamicDsService,\n unfinalizedBlocksService: UnfinalizedBlocksService,\n ) {\n super(\n apiService,\n nodeConfig,\n sandboxService,\n dsProcessorService,\n dynamicDsService,\n unfinalizedBlocksService,\n FilterTypeMap,\n ProcessorTypeMap,\n );\n }\n\n @profiler()\n async indexBlock(\n block: IBlock<BlockContent>,\n dataSources: SubqlEthereumDataSource[],\n ): Promise<ProcessBlockResponse> {\n return super.internalIndexBlock(block, dataSources, () =>\n this.getApi(block.block),\n );\n }\n\n getBlockHeight(block: BlockContent): number {\n return block.number;\n }\n\n getBlockHash(block: BlockContent): string {\n return block.hash;\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n private async getApi(block: BlockContent): Promise<SafeEthProvider> {\n return this.apiService.safeApi(this.getBlockHeight(block));\n }\n\n protected async indexBlockData(\n block: BlockContent,\n dataSources: EthereumProjectDs[],\n getVM: (d: EthereumProjectDs) => Promise<IndexerSandbox>,\n ): Promise<void> {\n if (isFullBlock(block)) {\n await this.indexBlockContent(block, dataSources, getVM);\n\n for (const tx of block.transactions) {\n await this.indexTransaction(tx, dataSources, getVM);\n\n for (const log of tx.logs ?? []) {\n await this.indexEvent(log, dataSources, getVM);\n }\n }\n } else {\n for (const log of block.logs ?? []) {\n await this.indexEvent(log, dataSources, getVM);\n }\n }\n }\n\n private async indexBlockContent(\n block: EthereumBlock,\n dataSources: EthereumProjectDs[],\n getVM: (d: EthereumProjectDs) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(EthereumHandlerKind.Block, block, ds, getVM);\n }\n }\n\n private async indexTransaction(\n tx: EthereumTransaction,\n dataSources: EthereumProjectDs[],\n getVM: (d: EthereumProjectDs) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(EthereumHandlerKind.Call, tx, ds, getVM);\n }\n }\n\n private async indexEvent(\n log: EthereumLog | LightEthereumLog,\n dataSources: EthereumProjectDs[],\n getVM: (d: EthereumProjectDs) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(EthereumHandlerKind.Event, log, ds, getVM);\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n protected async prepareFilteredData(\n kind: EthereumHandlerKind,\n data: any,\n ds: SubqlRuntimeDatasource,\n ): Promise<any> {\n return DataAbiParser[kind](this.apiService.api)(data, ds);\n }\n}\n\ntype ProcessorTypeMap = {\n [EthereumHandlerKind.Block]: typeof isBlockHandlerProcessor;\n [EthereumHandlerKind.Event]: typeof isEventHandlerProcessor;\n [EthereumHandlerKind.Call]: typeof isCallHandlerProcessor;\n};\n\nconst ProcessorTypeMap = {\n [EthereumHandlerKind.Block]: isBlockHandlerProcessor,\n [EthereumHandlerKind.Event]: isEventHandlerProcessor,\n [EthereumHandlerKind.Call]: isCallHandlerProcessor,\n};\n\nconst FilterTypeMap = {\n [EthereumHandlerKind.Block]: (\n data: EthereumBlock,\n filter: EthereumBlockFilter,\n ds: SubqlEthereumDataSource,\n ) => filterBlocksProcessor(data, filter, ds.options?.address),\n [EthereumHandlerKind.Event]: (\n data: EthereumLog | LightEthereumLog,\n filter: EthereumLogFilter,\n ds: SubqlEthereumDataSource,\n ) => filterLogsProcessor(data, filter, ds.options?.address),\n [EthereumHandlerKind.Call]: (\n data: EthereumTransaction,\n filter: EthereumTransactionFilter,\n ds: SubqlEthereumDataSource,\n ) => filterTransactionsProcessor(data, filter, ds.options?.address),\n};\n\nconst DataAbiParser = {\n [EthereumHandlerKind.Block]: () => (data: EthereumBlock) => data,\n [EthereumHandlerKind.Event]:\n (api: EthereumApi) =>\n (data: EthereumLog | LightEthereumLog, ds: SubqlRuntimeDatasource) =>\n api.parseLog(data, ds),\n [EthereumHandlerKind.Call]:\n (api: EthereumApi) =>\n (data: EthereumTransaction, ds: SubqlRuntimeDatasource) =>\n api.parseTransaction(data, ds),\n};\n"]}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { Block } from '@ethersproject/abstract-provider';
|
|
2
1
|
import { ApiService, BaseUnfinalizedBlocksService, Header, NodeConfig, StoreCacheService } from '@subql/node-core';
|
|
3
|
-
import { EthereumBlock } from '@subql/types-ethereum';
|
|
4
2
|
import { BlockContent } from './types';
|
|
5
|
-
export declare
|
|
6
|
-
export declare class UnfinalizedBlocksService extends BaseUnfinalizedBlocksService<EthereumBlock> {
|
|
3
|
+
export declare class UnfinalizedBlocksService extends BaseUnfinalizedBlocksService<BlockContent> {
|
|
7
4
|
private readonly apiService;
|
|
8
5
|
private supportsFinalization?;
|
|
9
6
|
private startupCheck;
|
|
@@ -23,7 +20,6 @@ export declare class UnfinalizedBlocksService extends BaseUnfinalizedBlocksServi
|
|
|
23
20
|
* @return (number | undefined) - The block height to rewind to to remove forked data
|
|
24
21
|
**/
|
|
25
22
|
protected getLastCorrectFinalizedBlock(forkedHeader: Header): Promise<number | undefined>;
|
|
26
|
-
protected blockToHeader(block: BlockContent): Header;
|
|
27
23
|
protected getFinalizedHead(): Promise<Header>;
|
|
28
24
|
protected getHeaderForHash(hash: string): Promise<Header>;
|
|
29
25
|
protected getHeaderForHeight(height: number): Promise<Header>;
|
|
@@ -11,20 +11,13 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.UnfinalizedBlocksService =
|
|
14
|
+
exports.UnfinalizedBlocksService = void 0;
|
|
15
15
|
const common_1 = require("@nestjs/common");
|
|
16
16
|
const node_core_1 = require("@subql/node-core");
|
|
17
17
|
const lodash_1 = require("lodash");
|
|
18
18
|
const NodeConfig_1 = require("../configure/NodeConfig");
|
|
19
|
+
const utils_ethereum_1 = require("../ethereum/utils.ethereum");
|
|
19
20
|
const logger = (0, node_core_1.getLogger)('UnfinalizedBlocksService');
|
|
20
|
-
function blockToHeader(block) {
|
|
21
|
-
return {
|
|
22
|
-
blockHeight: block.number,
|
|
23
|
-
blockHash: block.hash,
|
|
24
|
-
parentHash: block.parentHash,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
exports.blockToHeader = blockToHeader;
|
|
28
21
|
let UnfinalizedBlocksService = class UnfinalizedBlocksService extends node_core_1.BaseUnfinalizedBlocksService {
|
|
29
22
|
constructor(apiService, nodeConfig, storeCache) {
|
|
30
23
|
super(new NodeConfig_1.EthereumNodeConfig(nodeConfig), storeCache);
|
|
@@ -104,20 +97,17 @@ let UnfinalizedBlocksService = class UnfinalizedBlocksService extends node_core_
|
|
|
104
97
|
throw e;
|
|
105
98
|
}
|
|
106
99
|
}
|
|
107
|
-
blockToHeader(block) {
|
|
108
|
-
return blockToHeader(block);
|
|
109
|
-
}
|
|
110
100
|
async getFinalizedHead() {
|
|
111
101
|
const finalizedBlock = await this.apiService.api.getFinalizedBlock();
|
|
112
|
-
return
|
|
102
|
+
return (0, utils_ethereum_1.ethereumBlockToHeader)(finalizedBlock);
|
|
113
103
|
}
|
|
114
104
|
async getHeaderForHash(hash) {
|
|
115
105
|
const block = await this.apiService.api.getBlockByHeightOrHash(hash);
|
|
116
|
-
return
|
|
106
|
+
return (0, utils_ethereum_1.ethereumBlockToHeader)(block);
|
|
117
107
|
}
|
|
118
108
|
async getHeaderForHeight(height) {
|
|
119
109
|
const block = await this.apiService.api.getBlockByHeightOrHash(height);
|
|
120
|
-
return
|
|
110
|
+
return (0, utils_ethereum_1.ethereumBlockToHeader)(block);
|
|
121
111
|
}
|
|
122
112
|
};
|
|
123
113
|
__decorate([
|
|
@@ -126,12 +116,6 @@ __decorate([
|
|
|
126
116
|
__metadata("design:paramtypes", []),
|
|
127
117
|
__metadata("design:returntype", Promise)
|
|
128
118
|
], UnfinalizedBlocksService.prototype, "hasForked", null);
|
|
129
|
-
__decorate([
|
|
130
|
-
(0, node_core_1.mainThreadOnly)(),
|
|
131
|
-
__metadata("design:type", Function),
|
|
132
|
-
__metadata("design:paramtypes", [Object]),
|
|
133
|
-
__metadata("design:returntype", Object)
|
|
134
|
-
], UnfinalizedBlocksService.prototype, "blockToHeader", null);
|
|
135
119
|
__decorate([
|
|
136
120
|
(0, node_core_1.mainThreadOnly)(),
|
|
137
121
|
__metadata("design:type", Function),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unfinalizedBlocks.service.js","sourceRoot":"","sources":["../../src/indexer/unfinalizedBlocks.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"unfinalizedBlocks.service.js","sourceRoot":"","sources":["../../src/indexer/unfinalizedBlocks.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;AAEnC,2CAA4C;AAC5C,gDAU0B;AAC1B,mCAA8B;AAC9B,wDAA6D;AAC7D,+DAAmE;AAGnE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,0BAA0B,CAAC,CAAC;AAG9C,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,wCAA0C;IAItF,YACmB,UAAsB,EACvC,UAAsB,EACtB,UAA6B;QAE7B,KAAK,CAAC,IAAI,+BAAkB,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,CAAC;QAJrC,eAAU,GAAV,UAAU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,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC;QACrE,OAAO,IAAA,sCAAqB,EAAC,cAAc,CAAC,CAAC;IAC/C,CAAC;IAGe,AAAN,KAAK,CAAC,gBAAgB,CAAC,IAAY;QAC3C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;QACrE,OAAO,IAAA,sCAAqB,EAAC,KAAK,CAAC,CAAC;IACtC,CAAC;IAGe,AAAN,KAAK,CAAC,kBAAkB,CAAC,MAAc;QAC/C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;QACvE,OAAO,IAAA,sCAAqB,EAAC,KAAK,CAAC,CAAC;IACtC,CAAC;CACF,CAAA;AAxGiB;IADf,IAAA,oBAAQ,GAAE;;;;yDAuCV;AAkDe;IADf,IAAA,0BAAc,GAAE;;;;gEAIhB;AAGe;IADf,IAAA,0BAAc,GAAE;;;;gEAIhB;AAGe;IADf,IAAA,0BAAc,GAAE;;;;kEAIhB;AAnIU,wBAAwB;IADpC,IAAA,mBAAU,GAAE;qCAMoB,sBAAU;QAC3B,sBAAU;QACV,6BAAiB;GAPpB,wBAAwB,CAoIpC;AApIY,4DAAwB","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Injectable } from '@nestjs/common';\nimport {\n ApiService,\n BaseUnfinalizedBlocksService,\n Header,\n mainThreadOnly,\n NodeConfig,\n StoreCacheService,\n getLogger,\n profiler,\n POI_NOT_ENABLED_ERROR_MESSAGE,\n} from '@subql/node-core';\nimport { last } from 'lodash';\nimport { EthereumNodeConfig } from '../configure/NodeConfig';\nimport { ethereumBlockToHeader } from '../ethereum/utils.ethereum';\nimport { BlockContent } from './types';\n\nconst logger = getLogger('UnfinalizedBlocksService');\n\n@Injectable()\nexport class UnfinalizedBlocksService extends BaseUnfinalizedBlocksService<BlockContent> {\n private supportsFinalization?: boolean;\n private startupCheck = true;\n\n constructor(\n private readonly apiService: ApiService,\n nodeConfig: NodeConfig,\n storeCache: StoreCacheService,\n ) {\n super(new EthereumNodeConfig(nodeConfig), storeCache);\n }\n\n /**\n * @param reindex - the function to reindex back before a fork\n * @param supportsFinalization - If the chain supports the 'finalized' block tag this should be true.\n * */\n async init(\n reindex: (targetHeight: number) => Promise<void>,\n supportsFinalisation?: boolean,\n ): Promise<number | undefined> {\n this.supportsFinalization = supportsFinalisation;\n return super.init(reindex);\n }\n /**\n * Checks if a fork has happened, this doesn't find the start of the fork just where it was detected\n * @returns (Header | undefined) - The header may be the forked header but will most likely be the main header. Either way it should be used just for the block height\n * */\n @profiler()\n protected async hasForked(): Promise<Header | undefined> {\n if (this.supportsFinalization) {\n return super.hasForked();\n }\n\n // Startup check helps speed up finding a fork by checking the hash of the last unfinalized block\n if (this.startupCheck) {\n this.startupCheck = false;\n const lastUnfinalized = last(this.unfinalizedBlocks);\n if (lastUnfinalized) {\n const checkUnfinalized = await this.getHeaderForHeight(\n lastUnfinalized.blockHeight,\n );\n\n if (lastUnfinalized.blockHash !== checkUnfinalized.blockHash) {\n return checkUnfinalized;\n }\n }\n }\n\n if (this.unfinalizedBlocks.length <= 2) {\n return;\n }\n\n const i = this.unfinalizedBlocks.length - 1;\n const current = this.unfinalizedBlocks[i];\n const parent = this.unfinalizedBlocks[i - 1];\n\n if (current.parentHash !== parent.blockHash) {\n // We've found a fork now we need to find where the fork happened\n logger.warn(\n `Block fork detected at ${current.blockHeight}. Parent hash ${current.parentHash} doesn't match indexed parent ${parent.blockHash}.`,\n );\n\n return current;\n }\n\n return;\n }\n\n /**\n * Finds the height before the fork occurred based on the result of hasForked\n * @return (number | undefined) - The block height to rewind to to remove forked data\n **/\n protected async getLastCorrectFinalizedBlock(\n forkedHeader: Header,\n ): Promise<number | undefined> {\n if (this.supportsFinalization) {\n return super.getLastCorrectFinalizedBlock(forkedHeader);\n }\n\n const bestVerifiableBlocks = this.unfinalizedBlocks.filter(\n ({ blockHeight }) => blockHeight < forkedHeader.blockHeight,\n );\n\n let checkingHeader = forkedHeader;\n\n // Work backwards through the blocks until we find a matching hash\n for (const { blockHash, blockHeight } of bestVerifiableBlocks.reverse()) {\n if (\n blockHash === checkingHeader.blockHash ||\n blockHash === checkingHeader.parentHash\n ) {\n return blockHeight;\n }\n\n // Get the new parent\n checkingHeader = await this.getHeaderForHash(checkingHeader.parentHash);\n }\n\n try {\n const poiHeader = await this.findFinalizedUsingPOI(checkingHeader);\n return poiHeader.blockHeight;\n } catch (e) {\n if (e.message === POI_NOT_ENABLED_ERROR_MESSAGE) {\n return Math.max(\n 0,\n forkedHeader.blockHeight -\n (this.nodeConfig as EthereumNodeConfig).blockForkReindex,\n );\n }\n // TODO rewind back 1000+ blocks\n logger.info('Failed to use POI to rewind block');\n throw e;\n }\n }\n\n @mainThreadOnly()\n protected async getFinalizedHead(): Promise<Header> {\n const finalizedBlock = await this.apiService.api.getFinalizedBlock();\n return ethereumBlockToHeader(finalizedBlock);\n }\n\n @mainThreadOnly()\n protected async getHeaderForHash(hash: string): Promise<Header> {\n const block = await this.apiService.api.getBlockByHeightOrHash(hash);\n return ethereumBlockToHeader(block);\n }\n\n @mainThreadOnly()\n protected async getHeaderForHeight(height: number): Promise<Header> {\n const block = await this.apiService.api.getBlockByHeightOrHash(height);\n return ethereumBlockToHeader(block);\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SubqlEthereumDataSource } from '@subql/common-ethereum';
|
|
2
|
-
import { NodeConfig, IProjectService, ProcessBlockResponse, ApiService, BaseWorkerService, IProjectUpgradeService } from '@subql/node-core';
|
|
2
|
+
import { NodeConfig, IProjectService, ProcessBlockResponse, ApiService, BaseWorkerService, IProjectUpgradeService, IBlock } from '@subql/node-core';
|
|
3
3
|
import { EthereumProjectDs } from '../../configure/SubqueryProject';
|
|
4
4
|
import { IndexerManager } from '../indexer.manager';
|
|
5
5
|
import { BlockContent } from '../types';
|
|
@@ -15,10 +15,10 @@ export type WorkerStatusResponse = {
|
|
|
15
15
|
export declare class WorkerService extends BaseWorkerService<BlockContent, FetchBlockResponse, SubqlEthereumDataSource, {}> {
|
|
16
16
|
private apiService;
|
|
17
17
|
private indexerManager;
|
|
18
|
-
constructor(apiService: ApiService, indexerManager: IndexerManager, projectService: IProjectService<EthereumProjectDs>, projectUpgradeService: IProjectUpgradeService, nodeConfig: NodeConfig);
|
|
19
|
-
protected fetchChainBlock(heights: number, extra: {}): Promise<BlockContent
|
|
18
|
+
constructor(apiService: ApiService<any, any, IBlock<any>[]>, indexerManager: IndexerManager, projectService: IProjectService<EthereumProjectDs>, projectUpgradeService: IProjectUpgradeService, nodeConfig: NodeConfig);
|
|
19
|
+
protected fetchChainBlock(heights: number, extra: {}): Promise<IBlock<BlockContent>>;
|
|
20
20
|
protected toBlockResponse(block: BlockContent): {
|
|
21
21
|
parentHash: string;
|
|
22
22
|
};
|
|
23
|
-
protected processFetchedBlock(block: BlockContent
|
|
23
|
+
protected processFetchedBlock(block: IBlock<BlockContent>, dataSources: SubqlEthereumDataSource[]): Promise<ProcessBlockResponse>;
|
|
24
24
|
}
|
|
@@ -26,7 +26,7 @@ let WorkerService = class WorkerService extends node_core_1.BaseWorkerService {
|
|
|
26
26
|
}
|
|
27
27
|
async fetchChainBlock(heights, extra) {
|
|
28
28
|
const [block] = await this.apiService.fetchBlocks([heights]);
|
|
29
|
-
return block;
|
|
29
|
+
return block.block;
|
|
30
30
|
}
|
|
31
31
|
toBlockResponse(block) {
|
|
32
32
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.service.js","sourceRoot":"","sources":["../../../src/indexer/worker/worker.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AAEpD,
|
|
1
|
+
{"version":3,"file":"worker.service.js","sourceRoot":"","sources":["../../../src/indexer/worker/worker.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AAEpD,gDAQ0B;AAE1B,wDAAoD;AAa7C,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,6BAKlC;IACC,YACU,UAA+C,EAC/C,cAA8B,EAEtC,cAAkD,EAElD,qBAA6C,EAC7C,UAAsB;QAEtB,KAAK,CAAC,cAAc,EAAE,qBAAqB,EAAE,UAAU,CAAC,CAAC;QARjD,eAAU,GAAV,UAAU,CAAqC;QAC/C,mBAAc,GAAd,cAAc,CAAgB;IAQxC,CAAC;IAES,KAAK,CAAC,eAAe,CAC7B,OAAe,EACf,KAAS;QAET,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;QAC7D,OAAO,KAAK,CAAC,KAAK,CAAC;IACrB,CAAC;IAES,eAAe,CAAC,KAAmB;QAC3C,OAAO;YACL,UAAU,EAAE,KAAK,CAAC,UAAU;SAC7B,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,mBAAmB,CACjC,KAA2B,EAC3B,WAAsC;QAEtC,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAC5D,CAAC;CACF,CAAA;AAtCY,aAAa;IADzB,IAAA,mBAAU,GAAE;IAUR,WAAA,IAAA,eAAM,EAAC,iBAAiB,CAAC,CAAA;IAEzB,WAAA,IAAA,eAAM,EAAC,wBAAwB,CAAC,CAAA;qCAJb,sBAAU;QACN,gCAAc,kBAK1B,sBAAU;GAbb,aAAa,CAsCzB;AAtCY,sCAAa","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { SubqlEthereumDataSource } from '@subql/common-ethereum';\nimport {\n NodeConfig,\n IProjectService,\n ProcessBlockResponse,\n ApiService,\n BaseWorkerService,\n IProjectUpgradeService,\n IBlock,\n} from '@subql/node-core';\nimport { EthereumProjectDs } from '../../configure/SubqueryProject';\nimport { IndexerManager } from '../indexer.manager';\nimport { BlockContent } from '../types';\n\nexport type FetchBlockResponse = { parentHash: string } | undefined;\n\nexport type WorkerStatusResponse = {\n threadId: number;\n isIndexing: boolean;\n fetchedBlocks: number;\n toFetchBlocks: number;\n};\n\n@Injectable()\nexport class WorkerService extends BaseWorkerService<\n BlockContent,\n FetchBlockResponse,\n SubqlEthereumDataSource,\n {}\n> {\n constructor(\n private apiService: ApiService<any, any, IBlock<any>[]>,\n private indexerManager: IndexerManager,\n @Inject('IProjectService')\n projectService: IProjectService<EthereumProjectDs>,\n @Inject('IProjectUpgradeService')\n projectUpgradeService: IProjectUpgradeService,\n nodeConfig: NodeConfig,\n ) {\n super(projectService, projectUpgradeService, nodeConfig);\n }\n\n protected async fetchChainBlock(\n heights: number,\n extra: {},\n ): Promise<IBlock<BlockContent>> {\n const [block] = await this.apiService.fetchBlocks([heights]);\n return block.block;\n }\n\n protected toBlockResponse(block: BlockContent): { parentHash: string } {\n return {\n parentHash: block.parentHash,\n };\n }\n\n protected async processFetchedBlock(\n block: IBlock<BlockContent>,\n dataSources: SubqlEthereumDataSource[],\n ): Promise<ProcessBlockResponse> {\n return this.indexerManager.indexBlock(block, dataSources);\n }\n}\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Header, HostUnfinalizedBlocks, IUnfinalizedBlocksService } from '@subql/node-core';
|
|
1
|
+
import { Header, HostUnfinalizedBlocks, IBlock, IUnfinalizedBlocksService } from '@subql/node-core';
|
|
2
2
|
import { BlockContent } from '../types';
|
|
3
3
|
export declare class WorkerUnfinalizedBlocksService implements IUnfinalizedBlocksService<BlockContent> {
|
|
4
4
|
private host;
|
|
5
5
|
constructor(host: HostUnfinalizedBlocks);
|
|
6
6
|
processUnfinalizedBlockHeader(header: Header): Promise<number | null>;
|
|
7
|
-
processUnfinalizedBlocks(
|
|
7
|
+
processUnfinalizedBlocks(block: IBlock<BlockContent>): Promise<number | null>;
|
|
8
8
|
init(reindex: (targetHeight: number) => Promise<void>): Promise<number>;
|
|
9
9
|
resetUnfinalizedBlocks(): void;
|
|
10
10
|
resetLastFinalizedVerifiedHeight(): void;
|
|
@@ -24,12 +24,8 @@ let WorkerUnfinalizedBlocksService = class WorkerUnfinalizedBlocksService {
|
|
|
24
24
|
async processUnfinalizedBlockHeader(header) {
|
|
25
25
|
return this.host.unfinalizedBlocksProcess(header);
|
|
26
26
|
}
|
|
27
|
-
async processUnfinalizedBlocks(
|
|
28
|
-
return this.host.unfinalizedBlocksProcess(
|
|
29
|
-
blockHash: hash,
|
|
30
|
-
blockHeight: number,
|
|
31
|
-
parentHash,
|
|
32
|
-
});
|
|
27
|
+
async processUnfinalizedBlocks(block) {
|
|
28
|
+
return this.host.unfinalizedBlocksProcess(block.getHeader());
|
|
33
29
|
}
|
|
34
30
|
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
35
31
|
init(reindex) {
|