@sentio/runtime 2.58.1 → 2.58.2-rc.2
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-6XHWJ2VS.js +92 -0
- package/lib/{chunk-WHWNPZZ3.js.map → chunk-6XHWJ2VS.js.map} +1 -1
- package/lib/chunk-BPGFX5S5.js +10975 -0
- package/lib/{chunk-QVIDLAYP.js.map → chunk-BPGFX5S5.js.map} +1 -1
- package/lib/chunk-GAHZFTVC.js +59726 -0
- package/lib/{chunk-LHDBKJ2B.js.map → chunk-GAHZFTVC.js.map} +1 -1
- package/lib/chunk-ZUTD563J.js +23006 -0
- package/lib/{chunk-NEX6GJVW.js.map → chunk-ZUTD563J.js.map} +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +70 -1
- package/lib/index.js.map +1 -1
- package/lib/processor-runner.js +26592 -21
- package/lib/processor-runner.js.map +1 -1
- package/lib/service-worker.js +128 -2
- package/lib/service-worker.js.map +1 -1
- package/lib/test-processor.test.js.map +1 -1
- package/package.json +1 -1
- package/src/processor-runner.ts +6 -2
- package/src/provider.ts +2 -2
- package/lib/chunk-LHDBKJ2B.js +0 -116
- package/lib/chunk-NEX6GJVW.js +0 -26
- package/lib/chunk-QVIDLAYP.js +0 -38
- package/lib/chunk-WHWNPZZ3.js +0 -3
package/lib/service-worker.js
CHANGED
@@ -1,4 +1,130 @@
|
|
1
1
|
import { createRequire as createRequireShim } from 'module'; const require = createRequireShim(import.meta.url);
|
2
|
-
import
|
3
|
-
|
2
|
+
import {
|
3
|
+
setupLogger
|
4
|
+
} from "./chunk-BPGFX5S5.js";
|
5
|
+
import {
|
6
|
+
AbstractStoreContext,
|
7
|
+
configureEndpoints,
|
8
|
+
errorString,
|
9
|
+
freezeGlobalConfig,
|
10
|
+
recordRuntimeInfo,
|
11
|
+
require_lib3 as require_lib,
|
12
|
+
require_lib4 as require_lib2
|
13
|
+
} from "./chunk-GAHZFTVC.js";
|
14
|
+
import {
|
15
|
+
PluginManager,
|
16
|
+
ProcessConfigResponse,
|
17
|
+
__toESM
|
18
|
+
} from "./chunk-ZUTD563J.js";
|
19
|
+
|
20
|
+
// src/service-worker.ts
|
21
|
+
var import_nice_grpc = __toESM(require_lib(), 1);
|
22
|
+
var import_nice_grpc_error_details = __toESM(require_lib2(), 1);
|
23
|
+
import { BroadcastChannel, threadId } from "worker_threads";
|
24
|
+
import { Piscina } from "piscina";
|
25
|
+
var started = false;
|
26
|
+
var unhandled;
|
27
|
+
process.on("uncaughtException", (err) => {
|
28
|
+
console.error("Uncaught Exception, please checking if await is properly used", err);
|
29
|
+
unhandled = err;
|
30
|
+
}).on("unhandledRejection", (reason, p) => {
|
31
|
+
if (reason?.message.startsWith('invalid ENS name (disallowed character: "*"')) {
|
32
|
+
return;
|
33
|
+
}
|
34
|
+
console.error("Unhandled Rejection, please checking if await is properly", reason);
|
35
|
+
unhandled = reason;
|
36
|
+
});
|
37
|
+
async function getConfig(request, context) {
|
38
|
+
if (!started) {
|
39
|
+
throw new import_nice_grpc.ServerError(import_nice_grpc.Status.UNAVAILABLE, "Service Not started.");
|
40
|
+
}
|
41
|
+
const newConfig = ProcessConfigResponse.fromPartial({});
|
42
|
+
await PluginManager.INSTANCE.configure(newConfig);
|
43
|
+
return newConfig;
|
44
|
+
}
|
45
|
+
var loader = async (options) => {
|
46
|
+
if (options.target) {
|
47
|
+
const m = await import(options.target);
|
48
|
+
console.debug("Module loaded, path:", options.target, "module:", m);
|
49
|
+
return m;
|
50
|
+
}
|
51
|
+
};
|
52
|
+
var configureChannel = new BroadcastChannel("configure_channel");
|
53
|
+
configureChannel.onmessage = (request) => {
|
54
|
+
getConfig(request);
|
55
|
+
};
|
56
|
+
async function start(request, options) {
|
57
|
+
if (started) {
|
58
|
+
return {};
|
59
|
+
}
|
60
|
+
freezeGlobalConfig();
|
61
|
+
try {
|
62
|
+
await loader(options);
|
63
|
+
} catch (e) {
|
64
|
+
throw new import_nice_grpc.ServerError(import_nice_grpc.Status.INVALID_ARGUMENT, "Failed to load processor: " + errorString(e));
|
65
|
+
}
|
66
|
+
await PluginManager.INSTANCE.start(request);
|
67
|
+
started = true;
|
68
|
+
return {};
|
69
|
+
}
|
70
|
+
async function service_worker_default({
|
71
|
+
request,
|
72
|
+
processId,
|
73
|
+
workerPort
|
74
|
+
}) {
|
75
|
+
const { startRequest, configRequest, options } = Piscina.workerData;
|
76
|
+
if (!started) {
|
77
|
+
const logLevel = process.env["LOG_LEVEL"]?.toUpperCase();
|
78
|
+
setupLogger(options["log-format"] === "json", logLevel === "debug" ? true : options.debug, threadId);
|
79
|
+
configureEndpoints(options);
|
80
|
+
if (startRequest) {
|
81
|
+
await start(startRequest, options);
|
82
|
+
console.debug("worker started, template instance:", startRequest.templateInstances?.length);
|
83
|
+
}
|
84
|
+
if (configRequest) {
|
85
|
+
await getConfig(configRequest);
|
86
|
+
console.debug("worker configured");
|
87
|
+
}
|
88
|
+
}
|
89
|
+
if (unhandled) {
|
90
|
+
const err = unhandled;
|
91
|
+
unhandled = void 0;
|
92
|
+
throw new import_nice_grpc_error_details.RichServerError(
|
93
|
+
import_nice_grpc.Status.UNAVAILABLE,
|
94
|
+
"Unhandled exception/rejection in previous request: " + errorString(err),
|
95
|
+
[
|
96
|
+
import_nice_grpc_error_details.DebugInfo.fromPartial({
|
97
|
+
detail: err.message,
|
98
|
+
stackEntries: err.stack?.split("\n")
|
99
|
+
})
|
100
|
+
]
|
101
|
+
);
|
102
|
+
}
|
103
|
+
const result = await PluginManager.INSTANCE.processBinding(
|
104
|
+
request,
|
105
|
+
void 0,
|
106
|
+
workerPort ? new WorkerStoreContext(workerPort, processId) : void 0
|
107
|
+
);
|
108
|
+
recordRuntimeInfo(result, request.handlerType);
|
109
|
+
return result;
|
110
|
+
}
|
111
|
+
var WorkerStoreContext = class extends AbstractStoreContext {
|
112
|
+
constructor(port, processId) {
|
113
|
+
super(processId);
|
114
|
+
this.port = port;
|
115
|
+
this.port.on("message", (resp) => {
|
116
|
+
this.result(resp);
|
117
|
+
});
|
118
|
+
this.port.on("close", () => {
|
119
|
+
this.close();
|
120
|
+
});
|
121
|
+
}
|
122
|
+
doSend(req) {
|
123
|
+
this.port.postMessage(req);
|
124
|
+
}
|
125
|
+
};
|
126
|
+
import("node:process").then((p) => p.stdout.write(""));
|
127
|
+
export {
|
128
|
+
service_worker_default as default
|
129
|
+
};
|
4
130
|
//# sourceMappingURL=service-worker.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/service-worker.ts"],"sourcesContent":["import {\n DataBinding,\n DBResponse,\n DeepPartial,\n Empty,\n ProcessConfigRequest,\n ProcessConfigResponse,\n ProcessStreamResponse,\n StartRequest\n} 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, MessagePort, threadId } from 'worker_threads'\nimport { Piscina } from 'piscina'\nimport { configureEndpoints } from './endpoints.js'\nimport { setupLogger } from './logger.js'\nimport { AbstractStoreContext } from './db-context.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 ({\n request,\n processId,\n workerPort\n}: {\n request: DataBinding\n processId: number\n workerPort?: MessagePort\n}) {\n const { startRequest, configRequest, options } = Piscina.workerData\n if (!started) {\n const logLevel = process.env['LOG_LEVEL']?.toUpperCase()\n setupLogger(options['log-format'] === 'json', logLevel === 'debug' ? true : options.debug, threadId)\n\n configureEndpoints(options)\n\n if (startRequest) {\n await start(startRequest, options)\n console.debug('worker started, template instance:', startRequest.templateInstances?.length)\n }\n\n if (configRequest) {\n await getConfig(configRequest)\n console.debug('worker configured')\n }\n }\n\n if (unhandled) {\n const err = unhandled\n unhandled = undefined\n throw new RichServerError(\n Status.UNAVAILABLE,\n 'Unhandled exception/rejection in previous request: ' + errorString(err),\n [\n DebugInfo.fromPartial({\n detail: err.message,\n stackEntries: err.stack?.split('\\n')\n })\n ]\n )\n }\n\n const result = await PluginManager.INSTANCE.processBinding(\n request,\n undefined,\n workerPort ? new WorkerStoreContext(workerPort, processId) : undefined\n )\n recordRuntimeInfo(result, request.handlerType)\n return result\n}\n\nclass WorkerStoreContext extends AbstractStoreContext {\n constructor(\n readonly port: MessagePort,\n processId: number\n ) {\n super(processId)\n this.port.on('message', (resp: DBResponse) => {\n this.result(resp)\n })\n this.port.on('close', () => {\n this.close()\n })\n }\n\n doSend(req: DeepPartial<ProcessStreamResponse>): void {\n this.port.postMessage(req)\n }\n}\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":";
|
1
|
+
{"version":3,"sources":["../src/service-worker.ts"],"sourcesContent":["import {\n DataBinding,\n DBResponse,\n DeepPartial,\n Empty,\n ProcessConfigRequest,\n ProcessConfigResponse,\n ProcessStreamResponse,\n StartRequest\n} 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, MessagePort, threadId } from 'worker_threads'\nimport { Piscina } from 'piscina'\nimport { configureEndpoints } from './endpoints.js'\nimport { setupLogger } from './logger.js'\nimport { AbstractStoreContext } from './db-context.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 ({\n request,\n processId,\n workerPort\n}: {\n request: DataBinding\n processId: number\n workerPort?: MessagePort\n}) {\n const { startRequest, configRequest, options } = Piscina.workerData\n if (!started) {\n const logLevel = process.env['LOG_LEVEL']?.toUpperCase()\n setupLogger(options['log-format'] === 'json', logLevel === 'debug' ? true : options.debug, threadId)\n\n configureEndpoints(options)\n\n if (startRequest) {\n await start(startRequest, options)\n console.debug('worker started, template instance:', startRequest.templateInstances?.length)\n }\n\n if (configRequest) {\n await getConfig(configRequest)\n console.debug('worker configured')\n }\n }\n\n if (unhandled) {\n const err = unhandled\n unhandled = undefined\n throw new RichServerError(\n Status.UNAVAILABLE,\n 'Unhandled exception/rejection in previous request: ' + errorString(err),\n [\n DebugInfo.fromPartial({\n detail: err.message,\n stackEntries: err.stack?.split('\\n')\n })\n ]\n )\n }\n\n const result = await PluginManager.INSTANCE.processBinding(\n request,\n undefined,\n workerPort ? new WorkerStoreContext(workerPort, processId) : undefined\n )\n recordRuntimeInfo(result, request.handlerType)\n return result\n}\n\nclass WorkerStoreContext extends AbstractStoreContext {\n constructor(\n readonly port: MessagePort,\n processId: number\n ) {\n super(processId)\n this.port.on('message', (resp: DBResponse) => {\n this.result(resp)\n })\n this.port.on('close', () => {\n this.close()\n })\n }\n\n doSend(req: DeepPartial<ProcessStreamResponse>): void {\n this.port.postMessage(req)\n }\n}\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":"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","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/test-processor.test.ts"],"sourcesContent":["import { Plugin, PluginManager } from './plugin.js'\nimport { DataBinding, HandlerType, ProcessResult } from './gen/processor/protos/processor.js'\n\nclass TestPlugin extends Plugin {\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n const dbContext = PluginManager.INSTANCE.dbContextLocalStorage.getStore()\n if (dbContext) {\n await dbContext.sendRequest({\n get: {\n entity: 'Test',\n id: '1'\n }\n })\n }\n\n return ProcessResult.fromPartial({\n states: {\n configUpdated: true\n }\n })\n }\n supportedHandlers = [HandlerType.UNKNOWN, HandlerType.ETH_LOG]\n}\n\nPluginManager.INSTANCE.plugins = []\nPluginManager.INSTANCE.register(new TestPlugin())\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":"
|
1
|
+
{"version":3,"sources":["../src/test-processor.test.ts"],"sourcesContent":["import { Plugin, PluginManager } from './plugin.js'\nimport { DataBinding, HandlerType, ProcessResult } from './gen/processor/protos/processor.js'\n\nclass TestPlugin extends Plugin {\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n const dbContext = PluginManager.INSTANCE.dbContextLocalStorage.getStore()\n if (dbContext) {\n await dbContext.sendRequest({\n get: {\n entity: 'Test',\n id: '1'\n }\n })\n }\n\n return ProcessResult.fromPartial({\n states: {\n configUpdated: true\n }\n })\n }\n supportedHandlers = [HandlerType.UNKNOWN, HandlerType.ETH_LOG]\n}\n\nPluginManager.INSTANCE.plugins = []\nPluginManager.INSTANCE.register(new TestPlugin())\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":";;;;;;;;AAGA,IAAM,aAAN,cAAyB,OAAO;AAAA,EAC9B,MAAM,eAAe,SAA8C;AACjE,UAAM,YAAY,cAAc,SAAS,sBAAsB,SAAS;AACxE,QAAI,WAAW;AACb,YAAM,UAAU,YAAY;AAAA,QAC1B,KAAK;AAAA,UACH,QAAQ;AAAA,UACR,IAAI;AAAA,QACN;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO,cAAc,YAAY;AAAA,MAC/B,QAAQ;AAAA,QACN,eAAe;AAAA,MACjB;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EACA,oBAAoB,iCAAyC;AAC/D;AAEA,cAAc,SAAS,UAAU,CAAC;AAClC,cAAc,SAAS,SAAS,IAAI,WAAW,CAAC;AAC/C,OAAO,cAAc,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,EAAE,CAAC;","names":[]}
|
package/package.json
CHANGED
package/src/processor-runner.ts
CHANGED
@@ -21,6 +21,7 @@ import { setupLogger } from './logger.js'
|
|
21
21
|
import { setupOTLP } from './otlp.js'
|
22
22
|
import { ActionServer } from './action-server.js'
|
23
23
|
import { ServiceManager } from './service-manager.js'
|
24
|
+
import path from 'path'
|
24
25
|
|
25
26
|
// const mergedRegistry = Registry.merge([globalRegistry, niceGrpcRegistry])
|
26
27
|
|
@@ -185,13 +186,15 @@ process
|
|
185
186
|
|
186
187
|
if (process.env['OOM_DUMP_MEMORY_SIZE_GB']) {
|
187
188
|
let dumping = false
|
188
|
-
const memorySize =
|
189
|
+
const memorySize = parseFloat(process.env['OOM_DUMP_MEMORY_SIZE_GB'])
|
189
190
|
console.log('heap dumping is enabled, limit set to ', memorySize, 'gb')
|
191
|
+
const dir = process.env['OOM_DUMP_DIR'] || '/tmp'
|
190
192
|
setInterval(async () => {
|
191
193
|
const mem = process.memoryUsage()
|
194
|
+
console.log('Current Memory Usage', mem)
|
192
195
|
// if memory usage is greater this size, dump heap and exit
|
193
196
|
if (mem.heapTotal > memorySize * 1024 * 1024 * 1024 && !dumping) {
|
194
|
-
const file =
|
197
|
+
const file = path.join(dir, `${Date.now()}.heapsnapshot`)
|
195
198
|
dumping = true
|
196
199
|
await dumpHeap(file)
|
197
200
|
// force exit and keep pod running
|
@@ -203,6 +206,7 @@ if (process.env['OOM_DUMP_MEMORY_SIZE_GB']) {
|
|
203
206
|
async function dumpHeap(file: string) {
|
204
207
|
console.log('Heap dumping to', file)
|
205
208
|
const session = new Session()
|
209
|
+
fs.mkdirSync(path.dirname(file), { recursive: true })
|
206
210
|
const fd = fs.openSync(file, 'w')
|
207
211
|
try {
|
208
212
|
session.connect()
|
package/src/provider.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { JsonRpcProvider, Network
|
1
|
+
import { JsonRpcProvider, Network } from 'ethers'
|
2
2
|
|
3
3
|
import PQueue from 'p-queue'
|
4
4
|
import { Endpoints } from './endpoints.js'
|
@@ -22,7 +22,7 @@ const providers = new Map<string, JsonRpcProvider>()
|
|
22
22
|
// return networkish
|
23
23
|
// }
|
24
24
|
|
25
|
-
export function getProvider(chainId?: EthChainId):
|
25
|
+
export function getProvider(chainId?: EthChainId): JsonRpcProvider {
|
26
26
|
// const network = getNetworkFromCtxOrNetworkish(networkish)
|
27
27
|
if (!chainId) {
|
28
28
|
chainId = EthChainId.ETHEREUM
|