@sentio/runtime 3.1.0-rc.2 → 3.1.0-rc.4
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-Z33FXCEF.js → chunk-TYDHN4Z6.js} +487 -473
- package/lib/{chunk-Z33FXCEF.js.map → chunk-TYDHN4Z6.js.map} +1 -1
- 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 +136 -138
- package/lib/processor-runner.js.map +1 -1
- package/package.json +2 -2
- package/src/full-service.ts +1 -25
- package/src/processor-runner.ts +64 -46
- package/src/utils.ts +16 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentio/runtime",
|
|
3
|
-
"version": "3.1.0-rc.
|
|
3
|
+
"version": "3.1.0-rc.4",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"run": "tsx src/processor-runner.ts --log-format=json",
|
|
33
33
|
"run-benchmark": "tsx src/decode-benchmark.ts",
|
|
34
34
|
"start_js": "tsx ./lib/processor-runner.js $PWD/../../debug/dist/lib.js",
|
|
35
|
-
"start_ts": "tsx src/processor-runner.ts --debug --
|
|
35
|
+
"start_ts": "tsx src/processor-runner.ts --debug --worker 3 --port 4000 --chains-config chains-config.json $PWD/../../examples/x2y2/src/processor.ts",
|
|
36
36
|
"test": "glob -c 'tsx --test' '**/*.test.ts'"
|
|
37
37
|
}
|
|
38
38
|
}
|
package/src/full-service.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CallContext } from 'nice-grpc'
|
|
2
|
-
import { createRequire } from 'module'
|
|
3
2
|
// Different than the simple one which
|
|
4
3
|
import {
|
|
5
4
|
DataBinding,
|
|
@@ -16,16 +15,12 @@ import {
|
|
|
16
15
|
} from './gen/processor/protos/processor.js'
|
|
17
16
|
|
|
18
17
|
import { DeepPartial, Empty, ProcessorV3ServiceImplementation, UpdateTemplatesRequest } from '@sentio/protos'
|
|
19
|
-
import fs from 'fs-extra'
|
|
20
|
-
import path from 'path'
|
|
21
18
|
import os from 'os'
|
|
22
19
|
import { GLOBAL_CONFIG } from './global-config.js'
|
|
23
|
-
import { compareSemver, parseSemver, Semver } from './utils.js'
|
|
20
|
+
import { compareSemver, locatePackageJson, parseSemver, Semver } from './utils.js'
|
|
24
21
|
import { LRUCache } from 'lru-cache'
|
|
25
22
|
import { createHash } from 'crypto'
|
|
26
23
|
|
|
27
|
-
const require = createRequire(import.meta.url)
|
|
28
|
-
|
|
29
24
|
const FUEL_PROTO_UPDATE_VERSION = parseSemver('2.54.0-rc.7')
|
|
30
25
|
const FUEL_PROTO_NO_FUEL_TRANSACTION_AS_CALL_VERSION = parseSemver('2.55.0-rc.1')
|
|
31
26
|
|
|
@@ -68,17 +63,6 @@ function getParsedData(rawData: string): any {
|
|
|
68
63
|
return parsedData
|
|
69
64
|
}
|
|
70
65
|
|
|
71
|
-
function locatePackageJson(pkgId: string) {
|
|
72
|
-
const m = require.resolve(pkgId)
|
|
73
|
-
|
|
74
|
-
let dir = path.dirname(m)
|
|
75
|
-
while (!fs.existsSync(path.join(dir, 'package.json'))) {
|
|
76
|
-
dir = path.dirname(dir)
|
|
77
|
-
}
|
|
78
|
-
const content = fs.readFileSync(path.join(dir, 'package.json'), 'utf-8')
|
|
79
|
-
return JSON.parse(content)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
66
|
/**
|
|
83
67
|
* The RuntimeServicePatcher class is responsible for providing backward compatibility
|
|
84
68
|
* patches for different SDK versions. It ensures that the runtime can adapt to changes
|
|
@@ -89,10 +73,6 @@ export class RuntimeServicePatcher {
|
|
|
89
73
|
|
|
90
74
|
constructor() {
|
|
91
75
|
const sdkPackageJson = locatePackageJson('@sentio/sdk')
|
|
92
|
-
const runtimePackageJson = locatePackageJson('@sentio/runtime')
|
|
93
|
-
|
|
94
|
-
console.log('Runtime version:', runtimePackageJson.version, 'SDK version:', sdkPackageJson.version)
|
|
95
|
-
|
|
96
76
|
this.sdkVersion = parseSemver(sdkPackageJson.version)
|
|
97
77
|
}
|
|
98
78
|
|
|
@@ -298,10 +278,6 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
|
|
|
298
278
|
constructor(instance: ProcessorServiceImplementation) {
|
|
299
279
|
this.instance = instance
|
|
300
280
|
const sdkPackageJson = locatePackageJson('@sentio/sdk')
|
|
301
|
-
const runtimePackageJson = locatePackageJson('@sentio/runtime')
|
|
302
|
-
|
|
303
|
-
console.log('Runtime version:', runtimePackageJson.version, 'SDK version:', sdkPackageJson.version)
|
|
304
|
-
|
|
305
281
|
this.sdkVersion = parseSemver(sdkPackageJson.version)
|
|
306
282
|
}
|
|
307
283
|
|
package/src/processor-runner.ts
CHANGED
|
@@ -24,6 +24,7 @@ import { ProcessorV3Definition } from '@sentio/protos'
|
|
|
24
24
|
import { ProcessorServiceImplV3 } from './service-v3.js'
|
|
25
25
|
import { dirname, join } from 'path'
|
|
26
26
|
import { program, ProcessorRuntimeOptions } from 'processor-runner-program.js'
|
|
27
|
+
import { locatePackageJson } from './utils.js'
|
|
27
28
|
|
|
28
29
|
program.parse()
|
|
29
30
|
|
|
@@ -46,52 +47,14 @@ configureEndpoints(options)
|
|
|
46
47
|
console.debug('Starting Server', options)
|
|
47
48
|
|
|
48
49
|
// Check if this is a child process spawned for multi-server mode
|
|
49
|
-
const isChildProcess = process.env['
|
|
50
|
-
const childServerPort = process.env['SENTIO_CHILD_SERVER_PORT']
|
|
50
|
+
const isChildProcess = process.env['IS_CHILD'] === 'true'
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// Spawn child processes for ports basePort+1 to basePort+(multiServer-1)
|
|
58
|
-
for (let i = 1; i < options.worker; i++) {
|
|
59
|
-
const childPort = basePort + i
|
|
60
|
-
const child = fork(fileURLToPath(import.meta.url), process.argv.slice(2), {
|
|
61
|
-
env: {
|
|
62
|
-
...process.env,
|
|
63
|
-
SENTIO_MULTI_SERVER_CHILD: 'true',
|
|
64
|
-
SENTIO_CHILD_SERVER_PORT: String(childPort)
|
|
65
|
-
},
|
|
66
|
-
stdio: 'inherit'
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
child.on('error', (err) => {
|
|
70
|
-
console.error(`Child process on port ${childPort} error:`, err)
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
child.on('exit', (code) => {
|
|
74
|
-
console.log(`Child process on port ${childPort} exited with code ${code}`)
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
childProcesses.push(child)
|
|
78
|
-
console.log(`Spawned child server process for port ${childPort}`)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Handle parent process shutdown - kill all children
|
|
82
|
-
const shutdownChildren = () => {
|
|
83
|
-
for (const child of childProcesses) {
|
|
84
|
-
child.kill('SIGINT')
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
process.on('SIGINT', shutdownChildren)
|
|
89
|
-
process.on('SIGTERM', shutdownChildren)
|
|
52
|
+
if (!isChildProcess) {
|
|
53
|
+
const sdkPackageJson = locatePackageJson('@sentio/sdk')
|
|
54
|
+
const runtimePackageJson = locatePackageJson('@sentio/runtime')
|
|
55
|
+
console.log('Runtime version:', runtimePackageJson.version, 'SDK version:', sdkPackageJson.version)
|
|
90
56
|
}
|
|
91
57
|
|
|
92
|
-
// Determine the actual port for this process
|
|
93
|
-
const actualPort = isChildProcess && childServerPort ? childServerPort : options.port
|
|
94
|
-
|
|
95
58
|
let server: any
|
|
96
59
|
let baseService: ProcessorServiceImpl
|
|
97
60
|
let httpServer: http.Server | undefined
|
|
@@ -104,7 +67,7 @@ const loader = async () => {
|
|
|
104
67
|
|
|
105
68
|
if (options.startActionServer) {
|
|
106
69
|
server = new ActionServer(loader)
|
|
107
|
-
server.listen(
|
|
70
|
+
server.listen(options.port)
|
|
108
71
|
} else {
|
|
109
72
|
server = createServer({
|
|
110
73
|
'grpc.max_send_message_length': 768 * 1024 * 1024,
|
|
@@ -127,8 +90,8 @@ if (options.startActionServer) {
|
|
|
127
90
|
new FullProcessorServiceV3Impl(new ProcessorServiceImplV3(loader, options, server.shutdown))
|
|
128
91
|
)
|
|
129
92
|
|
|
130
|
-
server.listen('0.0.0.0:' +
|
|
131
|
-
console.log('Processor Server Started at:',
|
|
93
|
+
server.listen('0.0.0.0:' + options.port)
|
|
94
|
+
console.log('Processor Server Started at:', options.port)
|
|
132
95
|
}
|
|
133
96
|
|
|
134
97
|
// Only start metrics server on the main process (not child processes)
|
|
@@ -268,3 +231,58 @@ function shutdownServers(exitCode: number): void {
|
|
|
268
231
|
process.exit(exitCode)
|
|
269
232
|
}
|
|
270
233
|
}
|
|
234
|
+
|
|
235
|
+
// Multi-worker mode: spawn child processes for additional servers
|
|
236
|
+
if (options.worker > 1 && !isChildProcess) {
|
|
237
|
+
const childProcesses: ChildProcess[] = []
|
|
238
|
+
const basePort = parseInt(options.port)
|
|
239
|
+
|
|
240
|
+
// Spawn child processes for ports basePort+1 to basePort+(worker-1)
|
|
241
|
+
for (let i = 1; i < options.worker; i++) {
|
|
242
|
+
const childPort = basePort + i
|
|
243
|
+
const args = process.argv.slice(2)
|
|
244
|
+
const childArgs: string[] = ['--port=' + String(childPort)]
|
|
245
|
+
// Ignore port argument for child process
|
|
246
|
+
// handle both '-p 4000' and '--port=4000' styles
|
|
247
|
+
// ignore '--inspect=0.0.0.0:9229'
|
|
248
|
+
for (let j = 0; j < args.length; j++) {
|
|
249
|
+
const arg = args[j]
|
|
250
|
+
if (arg === '-p' || arg === '--port') {
|
|
251
|
+
j++ // skip next arg
|
|
252
|
+
continue
|
|
253
|
+
} else if (arg.startsWith('--port=') || arg.startsWith('--inspect=')) {
|
|
254
|
+
continue
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
childArgs.push(arg)
|
|
258
|
+
}
|
|
259
|
+
const child = fork(fileURLToPath(import.meta.url), childArgs, {
|
|
260
|
+
env: {
|
|
261
|
+
...process.env,
|
|
262
|
+
IS_CHILD: 'true'
|
|
263
|
+
},
|
|
264
|
+
stdio: 'inherit'
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
child.on('error', (err) => {
|
|
268
|
+
console.error(`Child process on port ${childPort} error:`, err)
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
child.on('exit', (code) => {
|
|
272
|
+
console.log(`Child process on port ${childPort} exited with code ${code}`)
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
childProcesses.push(child)
|
|
276
|
+
console.log(`Spawned child server process for port ${childPort}`)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Handle parent process shutdown - kill all children
|
|
280
|
+
const shutdownChildren = () => {
|
|
281
|
+
for (const child of childProcesses) {
|
|
282
|
+
child.kill('SIGINT')
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
process.on('SIGINT', shutdownChildren)
|
|
287
|
+
process.on('SIGTERM', shutdownChildren)
|
|
288
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { EthCallParam, ProcessResult } from '@sentio/protos'
|
|
2
|
+
import { createRequire } from 'module'
|
|
2
3
|
|
|
3
4
|
// TODO better handling this, because old proto doesn't have this
|
|
4
5
|
import { StateResult, ProcessResult as ProcessResultFull } from './gen/processor/protos/processor.js'
|
|
5
6
|
|
|
6
7
|
import { Required } from 'utility-types'
|
|
8
|
+
import path from 'path'
|
|
9
|
+
import fs from 'fs'
|
|
7
10
|
|
|
8
11
|
export function mergeProcessResults(results: ProcessResult[]): Required<ProcessResult, 'states'> {
|
|
9
12
|
const res = {
|
|
@@ -112,3 +115,16 @@ export function compareSemver(a: Semver, b: Semver) {
|
|
|
112
115
|
}
|
|
113
116
|
return 0
|
|
114
117
|
}
|
|
118
|
+
|
|
119
|
+
const require = createRequire(import.meta.url)
|
|
120
|
+
|
|
121
|
+
export function locatePackageJson(pkgId: string) {
|
|
122
|
+
const m = require.resolve(pkgId)
|
|
123
|
+
|
|
124
|
+
let dir = path.dirname(m)
|
|
125
|
+
while (!fs.existsSync(path.join(dir, 'package.json'))) {
|
|
126
|
+
dir = path.dirname(dir)
|
|
127
|
+
}
|
|
128
|
+
const content = fs.readFileSync(path.join(dir, 'package.json'), 'utf-8')
|
|
129
|
+
return JSON.parse(content)
|
|
130
|
+
}
|