@sentio/runtime 2.57.12-rc.h → 2.57.12-rc.i
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/lib/{chunk-IAGVEBAE.js → chunk-CAKQS6AI.js} +2287 -142
- package/lib/chunk-CAKQS6AI.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/processor-runner.js +62 -2200
- package/lib/processor-runner.js.map +1 -1
- package/lib/service-worker.d.ts +3 -2
- package/lib/service-worker.js +17 -24
- package/lib/service-worker.js.map +1 -1
- package/package.json +1 -1
- package/src/endpoints.ts +37 -0
- package/src/processor-runner.ts +2 -29
- package/src/service-worker.ts +16 -33
- package/lib/chunk-IAGVEBAE.js.map +0 -1
package/lib/service-worker.d.ts
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
import
|
1
|
+
import * as _sentio_protos from '@sentio/protos';
|
2
|
+
import { DataBinding } from '@sentio/protos';
|
2
3
|
|
3
4
|
declare function export_default({ request }: {
|
4
5
|
request: DataBinding;
|
5
|
-
}): Promise<ProcessResult>;
|
6
|
+
}): Promise<_sentio_protos.ProcessResult>;
|
6
7
|
|
7
8
|
export { export_default as default };
|
package/lib/service-worker.js
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
import { createRequire as createRequireShim } from 'module'; const require = createRequireShim(import.meta.url);
|
2
2
|
import {
|
3
|
+
configureEndpoints,
|
3
4
|
errorString,
|
4
5
|
freezeGlobalConfig,
|
5
6
|
recordRuntimeInfo,
|
6
|
-
|
7
|
-
|
8
|
-
} from "./chunk-
|
7
|
+
require_lib3 as require_lib,
|
8
|
+
require_lib4 as require_lib2
|
9
|
+
} from "./chunk-CAKQS6AI.js";
|
9
10
|
import {
|
10
11
|
PluginManager,
|
11
12
|
ProcessConfigResponse,
|
@@ -63,27 +64,19 @@ async function start(request, options) {
|
|
63
64
|
return {};
|
64
65
|
}
|
65
66
|
async function service_worker_default({ request }) {
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
}
|
77
|
-
console.info("new processor worker started");
|
78
|
-
if (configRequest) {
|
79
|
-
try {
|
80
|
-
await getConfig(configRequest);
|
81
|
-
console.info("worker configured");
|
82
|
-
} catch (e) {
|
83
|
-
console.log("worker configure failed", e);
|
84
|
-
}
|
85
|
-
}
|
67
|
+
const { startRequest, configRequest, options } = Piscina.workerData;
|
68
|
+
if (!started) {
|
69
|
+
configureEndpoints(options);
|
70
|
+
if (startRequest) {
|
71
|
+
await start(startRequest, options);
|
72
|
+
console.debug("worker started");
|
73
|
+
}
|
74
|
+
if (configRequest) {
|
75
|
+
await getConfig(configRequest);
|
76
|
+
console.debug("worker configured");
|
86
77
|
}
|
78
|
+
}
|
79
|
+
try {
|
87
80
|
if (unhandled) {
|
88
81
|
throw new import_nice_grpc_error_details.RichServerError(
|
89
82
|
import_nice_grpc.Status.UNAVAILABLE,
|
@@ -104,7 +97,7 @@ async function service_worker_default({ request }) {
|
|
104
97
|
recordRuntimeInfo(result, request.handlerType);
|
105
98
|
return result;
|
106
99
|
} catch (e) {
|
107
|
-
console.
|
100
|
+
console.error("worker process binding failed", e);
|
108
101
|
throw e;
|
109
102
|
}
|
110
103
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/service-worker.ts"],"sourcesContent":["import {
|
1
|
+
{"version":3,"sources":["../src/service-worker.ts"],"sourcesContent":["import { DataBinding, Empty, ProcessConfigRequest, ProcessConfigResponse, StartRequest } from '@sentio/protos'\nimport { CallContext, ServerError, Status } from 'nice-grpc'\nimport { PluginManager } from './plugin.js'\nimport { errorString } from './utils.js'\nimport { freezeGlobalConfig } from './global-config.js'\nimport { DebugInfo, RichServerError } from 'nice-grpc-error-details'\nimport { recordRuntimeInfo } from './service.js'\nimport { BroadcastChannel } from 'worker_threads'\nimport { Piscina } from 'piscina'\nimport { configureEndpoints } from './endpoints.js'\n\nlet started = false\n\nlet unhandled: Error | undefined\n\nprocess\n .on('uncaughtException', (err) => {\n console.error('Uncaught Exception, please checking if await is properly used', err)\n unhandled = err\n })\n .on('unhandledRejection', (reason, p) => {\n // @ts-ignore ignore invalid ens error\n if (reason?.message.startsWith('invalid ENS name (disallowed character: \"*\"')) {\n return\n }\n console.error('Unhandled Rejection, please checking if await is properly', reason)\n unhandled = reason as Error\n // shutdownServers(1)\n })\n\nasync function getConfig(request: ProcessConfigRequest, context?: CallContext): Promise<ProcessConfigResponse> {\n if (!started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')\n }\n\n const newConfig = ProcessConfigResponse.fromPartial({})\n await PluginManager.INSTANCE.configure(newConfig)\n return newConfig\n}\n\nconst loader = async (options: any) => {\n if (options.target) {\n const m = await import(options.target)\n console.debug('Module loaded, path:', options.target, 'module:', m)\n return m\n }\n}\n\nconst configureChannel = new BroadcastChannel('configure_channel')\nconfigureChannel.onmessage = (request: ProcessConfigRequest) => {\n getConfig(request)\n}\n\nasync function start(request: StartRequest, options: any): Promise<Empty> {\n if (started) {\n return {}\n }\n freezeGlobalConfig()\n\n try {\n await loader(options)\n } catch (e) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e))\n }\n\n await PluginManager.INSTANCE.start(request)\n started = true\n return {}\n}\n\nexport default async function ({ request }: { request: DataBinding }) {\n const { startRequest, configRequest, options } = Piscina.workerData\n if (!started) {\n configureEndpoints(options)\n\n if (startRequest) {\n await start(startRequest, options)\n console.debug('worker started')\n }\n\n if (configRequest) {\n await getConfig(configRequest)\n console.debug('worker configured')\n }\n }\n\n try {\n if (unhandled) {\n throw new RichServerError(\n Status.UNAVAILABLE,\n 'Unhandled exception/rejection in previous request: ' + errorString(unhandled),\n [\n DebugInfo.fromPartial({\n detail: unhandled.message,\n stackEntries: unhandled.stack?.split('\\n')\n })\n ]\n )\n }\n\n const result = await PluginManager.INSTANCE.processBinding(\n request,\n undefined\n // PluginManager.INSTANCE.dbContextLocalStorage.getStore()\n )\n recordRuntimeInfo(result, request.handlerType)\n return result\n } catch (e) {\n console.error('worker process binding failed', e)\n throw e\n }\n}\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":";;;;;;;;;;;;;;;;AACA,uBAAiD;AAIjD,qCAA2C;AAE3C,SAAS,wBAAwB;AACjC,SAAS,eAAe;AAGxB,IAAI,UAAU;AAEd,IAAI;AAEJ,QACG,GAAG,qBAAqB,CAAC,QAAQ;AAChC,UAAQ,MAAM,iEAAiE,GAAG;AAClF,cAAY;AACd,CAAC,EACA,GAAG,sBAAsB,CAAC,QAAQ,MAAM;AAEvC,MAAI,QAAQ,QAAQ,WAAW,6CAA6C,GAAG;AAC7E;AAAA,EACF;AACA,UAAQ,MAAM,6DAA6D,MAAM;AACjF,cAAY;AAEd,CAAC;AAEH,eAAe,UAAU,SAA+B,SAAuD;AAC7G,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,6BAAY,wBAAO,aAAa,sBAAsB;AAAA,EAClE;AAEA,QAAM,YAAY,sBAAsB,YAAY,CAAC,CAAC;AACtD,QAAM,cAAc,SAAS,UAAU,SAAS;AAChD,SAAO;AACT;AAEA,IAAM,SAAS,OAAO,YAAiB;AACrC,MAAI,QAAQ,QAAQ;AAClB,UAAM,IAAI,MAAM,OAAO,QAAQ;AAC/B,YAAQ,MAAM,wBAAwB,QAAQ,QAAQ,WAAW,CAAC;AAClE,WAAO;AAAA,EACT;AACF;AAEA,IAAM,mBAAmB,IAAI,iBAAiB,mBAAmB;AACjE,iBAAiB,YAAY,CAAC,YAAkC;AAC9D,YAAU,OAAO;AACnB;AAEA,eAAe,MAAM,SAAuB,SAA8B;AACxE,MAAI,SAAS;AACX,WAAO,CAAC;AAAA,EACV;AACA,qBAAmB;AAEnB,MAAI;AACF,UAAM,OAAO,OAAO;AAAA,EACtB,SAAS,GAAG;AACV,UAAM,IAAI,6BAAY,wBAAO,kBAAkB,+BAA+B,YAAY,CAAC,CAAC;AAAA,EAC9F;AAEA,QAAM,cAAc,SAAS,MAAM,OAAO;AAC1C,YAAU;AACV,SAAO,CAAC;AACV;AAEA,eAAO,uBAAwB,EAAE,QAAQ,GAA6B;AACpE,QAAM,EAAE,cAAc,eAAe,QAAQ,IAAI,QAAQ;AACzD,MAAI,CAAC,SAAS;AACZ,uBAAmB,OAAO;AAE1B,QAAI,cAAc;AAChB,YAAM,MAAM,cAAc,OAAO;AACjC,cAAQ,MAAM,gBAAgB;AAAA,IAChC;AAEA,QAAI,eAAe;AACjB,YAAM,UAAU,aAAa;AAC7B,cAAQ,MAAM,mBAAmB;AAAA,IACnC;AAAA,EACF;AAEA,MAAI;AACF,QAAI,WAAW;AACb,YAAM,IAAI;AAAA,QACR,wBAAO;AAAA,QACP,wDAAwD,YAAY,SAAS;AAAA,QAC7E;AAAA,UACE,yCAAU,YAAY;AAAA,YACpB,QAAQ,UAAU;AAAA,YAClB,cAAc,UAAU,OAAO,MAAM,IAAI;AAAA,UAC3C,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAEA,UAAM,SAAS,MAAM,cAAc,SAAS;AAAA,MAC1C;AAAA,MACA;AAAA;AAAA,IAEF;AACA,sBAAkB,QAAQ,QAAQ,WAAW;AAC7C,WAAO;AAAA,EACT,SAAS,GAAG;AACV,YAAQ,MAAM,iCAAiC,CAAC;AAChD,UAAM;AAAA,EACR;AACF;AACC,OAAO,cAAc,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,EAAE,CAAC;","names":[]}
|
package/package.json
CHANGED
package/src/endpoints.ts
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
import path from 'path'
|
2
|
+
import fs from 'fs-extra'
|
3
|
+
import { ChainConfig } from './chain-config.js'
|
4
|
+
|
1
5
|
export class Endpoints {
|
2
6
|
static INSTANCE: Endpoints = new Endpoints()
|
3
7
|
|
@@ -9,3 +13,36 @@ export class Endpoints {
|
|
9
13
|
|
10
14
|
batchCount = 1
|
11
15
|
}
|
16
|
+
|
17
|
+
|
18
|
+
export function configureEndpoints(options:any) {
|
19
|
+
|
20
|
+
const fullPath = path.resolve(options['chains-config'])
|
21
|
+
const chainsConfig = fs.readJsonSync(fullPath)
|
22
|
+
|
23
|
+
const concurrencyOverride = process.env['OVERRIDE_CONCURRENCY']
|
24
|
+
? parseInt(process.env['OVERRIDE_CONCURRENCY'])
|
25
|
+
: undefined
|
26
|
+
const batchCountOverride = process.env['OVERRIDE_BATCH_COUNT']
|
27
|
+
? parseInt(process.env['OVERRIDE_BATCH_COUNT'])
|
28
|
+
: undefined
|
29
|
+
|
30
|
+
Endpoints.INSTANCE.concurrency = concurrencyOverride ?? options.concurrency
|
31
|
+
Endpoints.INSTANCE.batchCount = batchCountOverride ?? options['batch-count']
|
32
|
+
Endpoints.INSTANCE.chainQueryAPI = options['chainquery-server']
|
33
|
+
Endpoints.INSTANCE.priceFeedAPI = options['pricefeed-server']
|
34
|
+
|
35
|
+
for (const [id, config] of Object.entries(chainsConfig)) {
|
36
|
+
const chainConfig = config as ChainConfig
|
37
|
+
if (chainConfig.ChainServer) {
|
38
|
+
Endpoints.INSTANCE.chainServer.set(id, chainConfig.ChainServer)
|
39
|
+
} else {
|
40
|
+
const http = chainConfig.Https?.[0]
|
41
|
+
if (http) {
|
42
|
+
Endpoints.INSTANCE.chainServer.set(id, http)
|
43
|
+
} else {
|
44
|
+
console.error('not valid config for chain', id)
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
package/src/processor-runner.ts
CHANGED
@@ -15,7 +15,7 @@ import { Session } from 'node:inspector/promises'
|
|
15
15
|
|
16
16
|
import { ProcessorDefinition } from './gen/processor/protos/processor.js'
|
17
17
|
import { ProcessorServiceImpl } from './service.js'
|
18
|
-
import { Endpoints } from './endpoints.js'
|
18
|
+
import { configureEndpoints, Endpoints } from './endpoints.js'
|
19
19
|
import { FullProcessorServiceImpl } from './full-service.js'
|
20
20
|
import { ChainConfig } from './chain-config.js'
|
21
21
|
import { setupLogger } from './logger.js'
|
@@ -58,34 +58,7 @@ await setupOTLP(options['otlp-debug'])
|
|
58
58
|
|
59
59
|
Error.stackTraceLimit = 20
|
60
60
|
|
61
|
-
|
62
|
-
const chainsConfig = fs.readJsonSync(fullPath)
|
63
|
-
|
64
|
-
const concurrencyOverride = process.env['OVERRIDE_CONCURRENCY']
|
65
|
-
? parseInt(process.env['OVERRIDE_CONCURRENCY'])
|
66
|
-
: undefined
|
67
|
-
const batchCountOverride = process.env['OVERRIDE_BATCH_COUNT']
|
68
|
-
? parseInt(process.env['OVERRIDE_BATCH_COUNT'])
|
69
|
-
: undefined
|
70
|
-
|
71
|
-
Endpoints.INSTANCE.concurrency = concurrencyOverride ?? options.concurrency
|
72
|
-
Endpoints.INSTANCE.batchCount = batchCountOverride ?? options['batch-count']
|
73
|
-
Endpoints.INSTANCE.chainQueryAPI = options['chainquery-server']
|
74
|
-
Endpoints.INSTANCE.priceFeedAPI = options['pricefeed-server']
|
75
|
-
|
76
|
-
for (const [id, config] of Object.entries(chainsConfig)) {
|
77
|
-
const chainConfig = config as ChainConfig
|
78
|
-
if (chainConfig.ChainServer) {
|
79
|
-
Endpoints.INSTANCE.chainServer.set(id, chainConfig.ChainServer)
|
80
|
-
} else {
|
81
|
-
const http = chainConfig.Https?.[0]
|
82
|
-
if (http) {
|
83
|
-
Endpoints.INSTANCE.chainServer.set(id, http)
|
84
|
-
} else {
|
85
|
-
console.error('not valid config for chain', id)
|
86
|
-
}
|
87
|
-
}
|
88
|
-
}
|
61
|
+
configureEndpoints(options)
|
89
62
|
|
90
63
|
console.debug('Starting Server', options)
|
91
64
|
|
package/src/service-worker.ts
CHANGED
@@ -1,23 +1,13 @@
|
|
1
|
-
import {
|
2
|
-
DataBinding,
|
3
|
-
Empty,
|
4
|
-
HandlerType,
|
5
|
-
PreparedData,
|
6
|
-
ProcessConfigRequest,
|
7
|
-
ProcessConfigResponse,
|
8
|
-
ProcessResult,
|
9
|
-
StartRequest
|
10
|
-
} from '@sentio/protos'
|
1
|
+
import { DataBinding, Empty, ProcessConfigRequest, ProcessConfigResponse, StartRequest } from '@sentio/protos'
|
11
2
|
import { CallContext, ServerError, Status } from 'nice-grpc'
|
12
3
|
import { PluginManager } from './plugin.js'
|
13
|
-
import commandLineArgs from 'command-line-args'
|
14
|
-
import { optionDefinitions } from './processor-runner.js'
|
15
4
|
import { errorString } from './utils.js'
|
16
5
|
import { freezeGlobalConfig } from './global-config.js'
|
17
6
|
import { DebugInfo, RichServerError } from 'nice-grpc-error-details'
|
18
7
|
import { recordRuntimeInfo } from './service.js'
|
19
8
|
import { BroadcastChannel } from 'worker_threads'
|
20
9
|
import { Piscina } from 'piscina'
|
10
|
+
import { configureEndpoints } from './endpoints.js'
|
21
11
|
|
22
12
|
let started = false
|
23
13
|
|
@@ -79,29 +69,22 @@ async function start(request: StartRequest, options: any): Promise<Empty> {
|
|
79
69
|
}
|
80
70
|
|
81
71
|
export default async function ({ request }: { request: DataBinding }) {
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
console.log('worker start failed', e)
|
91
|
-
}
|
92
|
-
}
|
93
|
-
console.info('new processor worker started')
|
72
|
+
const { startRequest, configRequest, options } = Piscina.workerData
|
73
|
+
if (!started) {
|
74
|
+
configureEndpoints(options)
|
75
|
+
|
76
|
+
if (startRequest) {
|
77
|
+
await start(startRequest, options)
|
78
|
+
console.debug('worker started')
|
79
|
+
}
|
94
80
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
console.info('worker configured')
|
99
|
-
} catch (e) {
|
100
|
-
console.log('worker configure failed', e)
|
101
|
-
}
|
102
|
-
}
|
81
|
+
if (configRequest) {
|
82
|
+
await getConfig(configRequest)
|
83
|
+
console.debug('worker configured')
|
103
84
|
}
|
85
|
+
}
|
104
86
|
|
87
|
+
try {
|
105
88
|
if (unhandled) {
|
106
89
|
throw new RichServerError(
|
107
90
|
Status.UNAVAILABLE,
|
@@ -123,7 +106,7 @@ export default async function ({ request }: { request: DataBinding }) {
|
|
123
106
|
recordRuntimeInfo(result, request.handlerType)
|
124
107
|
return result
|
125
108
|
} catch (e) {
|
126
|
-
console.
|
109
|
+
console.error('worker process binding failed', e)
|
127
110
|
throw e
|
128
111
|
}
|
129
112
|
}
|