@sentio/runtime 2.57.12-rc.h → 2.57.12-rc.j
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-PDTC7P7O.js} +2287 -142
- package/lib/chunk-PDTC7P7O.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 -2201
- package/lib/processor-runner.js.map +1 -1
- package/lib/service-worker.d.ts +3 -2
- package/lib/service-worker.js +31 -43
- package/lib/service-worker.js.map +1 -1
- package/package.json +1 -1
- package/src/endpoints.ts +35 -0
- package/src/processor-runner.ts +2 -29
- package/src/service-manager.ts +0 -1
- package/src/service-worker.ts +30 -52
- 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-PDTC7P7O.js";
|
9
10
|
import {
|
10
11
|
PluginManager,
|
11
12
|
ProcessConfigResponse,
|
@@ -63,50 +64,37 @@ 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
|
-
console.info("worker started");
|
73
|
-
} catch (e) {
|
74
|
-
console.log("worker start failed", e);
|
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");
|
86
73
|
}
|
87
|
-
if (
|
88
|
-
|
89
|
-
|
90
|
-
"Unhandled exception/rejection in previous request: " + errorString(unhandled),
|
91
|
-
[
|
92
|
-
import_nice_grpc_error_details.DebugInfo.fromPartial({
|
93
|
-
detail: unhandled.message,
|
94
|
-
stackEntries: unhandled.stack?.split("\n")
|
95
|
-
})
|
96
|
-
]
|
97
|
-
);
|
74
|
+
if (configRequest) {
|
75
|
+
await getConfig(configRequest);
|
76
|
+
console.debug("worker configured");
|
98
77
|
}
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
78
|
+
}
|
79
|
+
if (unhandled) {
|
80
|
+
throw new import_nice_grpc_error_details.RichServerError(
|
81
|
+
import_nice_grpc.Status.UNAVAILABLE,
|
82
|
+
"Unhandled exception/rejection in previous request: " + errorString(unhandled),
|
83
|
+
[
|
84
|
+
import_nice_grpc_error_details.DebugInfo.fromPartial({
|
85
|
+
detail: unhandled.message,
|
86
|
+
stackEntries: unhandled.stack?.split("\n")
|
87
|
+
})
|
88
|
+
]
|
103
89
|
);
|
104
|
-
recordRuntimeInfo(result, request.handlerType);
|
105
|
-
return result;
|
106
|
-
} catch (e) {
|
107
|
-
console.log("worker process binding failed", e);
|
108
|
-
throw e;
|
109
90
|
}
|
91
|
+
const result = await PluginManager.INSTANCE.processBinding(
|
92
|
+
request,
|
93
|
+
void 0
|
94
|
+
// PluginManager.INSTANCE.dbContextLocalStorage.getStore()
|
95
|
+
);
|
96
|
+
recordRuntimeInfo(result, request.handlerType);
|
97
|
+
return result;
|
110
98
|
}
|
111
99
|
import("node:process").then((p) => p.stdout.write(""));
|
112
100
|
export {
|
@@ -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 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}\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,MA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cAAc,UAAU,OAAO,MAAM,IAAI;AAAA,QAC3C,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,MAAM,cAAc,SAAS;AAAA,IAC1C;AAAA,IACA;AAAA;AAAA,EAEF;AACA,oBAAkB,QAAQ,QAAQ,WAAW;AAC7C,SAAO;AACT;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,34 @@ export class Endpoints {
|
|
9
13
|
|
10
14
|
batchCount = 1
|
11
15
|
}
|
16
|
+
|
17
|
+
export function configureEndpoints(options: any) {
|
18
|
+
const fullPath = path.resolve(options['chains-config'])
|
19
|
+
const chainsConfig = fs.readJsonSync(fullPath)
|
20
|
+
|
21
|
+
const concurrencyOverride = process.env['OVERRIDE_CONCURRENCY']
|
22
|
+
? parseInt(process.env['OVERRIDE_CONCURRENCY'])
|
23
|
+
: undefined
|
24
|
+
const batchCountOverride = process.env['OVERRIDE_BATCH_COUNT']
|
25
|
+
? parseInt(process.env['OVERRIDE_BATCH_COUNT'])
|
26
|
+
: undefined
|
27
|
+
|
28
|
+
Endpoints.INSTANCE.concurrency = concurrencyOverride ?? options.concurrency
|
29
|
+
Endpoints.INSTANCE.batchCount = batchCountOverride ?? options['batch-count']
|
30
|
+
Endpoints.INSTANCE.chainQueryAPI = options['chainquery-server']
|
31
|
+
Endpoints.INSTANCE.priceFeedAPI = options['pricefeed-server']
|
32
|
+
|
33
|
+
for (const [id, config] of Object.entries(chainsConfig)) {
|
34
|
+
const chainConfig = config as ChainConfig
|
35
|
+
if (chainConfig.ChainServer) {
|
36
|
+
Endpoints.INSTANCE.chainServer.set(id, chainConfig.ChainServer)
|
37
|
+
} else {
|
38
|
+
const http = chainConfig.Https?.[0]
|
39
|
+
if (http) {
|
40
|
+
Endpoints.INSTANCE.chainServer.set(id, http)
|
41
|
+
} else {
|
42
|
+
console.error('not valid config for chain', id)
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
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-manager.ts
CHANGED
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,51 +69,39 @@ 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
|
-
if (startRequest) {
|
86
|
-
try {
|
87
|
-
await start(startRequest, options)
|
88
|
-
console.info('worker started')
|
89
|
-
} catch (e) {
|
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)
|
94
75
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
console.info('worker configured')
|
99
|
-
} catch (e) {
|
100
|
-
console.log('worker configure failed', e)
|
101
|
-
}
|
102
|
-
}
|
76
|
+
if (startRequest) {
|
77
|
+
await start(startRequest, options)
|
78
|
+
console.debug('worker started')
|
103
79
|
}
|
104
80
|
|
105
|
-
if (
|
106
|
-
|
107
|
-
|
108
|
-
'Unhandled exception/rejection in previous request: ' + errorString(unhandled),
|
109
|
-
[
|
110
|
-
DebugInfo.fromPartial({
|
111
|
-
detail: unhandled.message,
|
112
|
-
stackEntries: unhandled.stack?.split('\n')
|
113
|
-
})
|
114
|
-
]
|
115
|
-
)
|
81
|
+
if (configRequest) {
|
82
|
+
await getConfig(configRequest)
|
83
|
+
console.debug('worker configured')
|
116
84
|
}
|
85
|
+
}
|
117
86
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
87
|
+
if (unhandled) {
|
88
|
+
throw new RichServerError(
|
89
|
+
Status.UNAVAILABLE,
|
90
|
+
'Unhandled exception/rejection in previous request: ' + errorString(unhandled),
|
91
|
+
[
|
92
|
+
DebugInfo.fromPartial({
|
93
|
+
detail: unhandled.message,
|
94
|
+
stackEntries: unhandled.stack?.split('\n')
|
95
|
+
})
|
96
|
+
]
|
122
97
|
)
|
123
|
-
recordRuntimeInfo(result, request.handlerType)
|
124
|
-
return result
|
125
|
-
} catch (e) {
|
126
|
-
console.log('worker process binding failed', e)
|
127
|
-
throw e
|
128
98
|
}
|
99
|
+
|
100
|
+
const result = await PluginManager.INSTANCE.processBinding(
|
101
|
+
request,
|
102
|
+
undefined
|
103
|
+
// PluginManager.INSTANCE.dbContextLocalStorage.getStore()
|
104
|
+
)
|
105
|
+
recordRuntimeInfo(result, request.handlerType)
|
106
|
+
return result
|
129
107
|
}
|