@sentio/runtime 2.59.5-rc.1 → 2.60.0-rc.10

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.
@@ -1,7 +1,7 @@
1
1
  import { createRequire as createRequireShim } from 'module'; const require = createRequireShim(import.meta.url);
2
2
  import {
3
3
  setupLogger
4
- } from "./chunk-U5UZYRQ4.js";
4
+ } from "./chunk-CYS2DAE4.js";
5
5
  import {
6
6
  ProcessorServiceImpl,
7
7
  configureEndpoints,
@@ -10,10 +10,10 @@ import {
10
10
  require_cjs,
11
11
  require_lib3 as require_lib,
12
12
  require_lib4 as require_lib2
13
- } from "./chunk-L7MQIWIO.js";
13
+ } from "./chunk-BOHR42T4.js";
14
14
  import {
15
15
  __toESM
16
- } from "./chunk-LCS6SRJY.js";
16
+ } from "./chunk-TC6OWLVA.js";
17
17
 
18
18
  // src/service-worker.ts
19
19
  var import_nice_grpc = __toESM(require_lib(), 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentio/runtime",
3
- "version": "2.59.5-rc.1",
3
+ "version": "2.60.0-rc.10",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
package/src/db-context.ts CHANGED
@@ -5,7 +5,10 @@ import {
5
5
  DBResponse,
6
6
  DeepPartial,
7
7
  ProcessResult,
8
- ProcessStreamResponse
8
+ ProcessStreamResponse,
9
+ ProcessStreamResponseV2,
10
+ TemplateInstance,
11
+ TimeseriesResult
9
12
  } from '@sentio/protos'
10
13
  import * as process from 'node:process'
11
14
  import { dbMetrics } from './metrics.js'
@@ -38,6 +41,11 @@ export interface IStoreContext {
38
41
  close(): void
39
42
  }
40
43
 
44
+ export interface IDataBindingContext extends IStoreContext {
45
+ sendTemplateRequest(templates: Array<TemplateInstance>): void
46
+ sendTimeseriesRequest(timeseries: Array<TimeseriesResult>): void
47
+ }
48
+
41
49
  export abstract class AbstractStoreContext implements IStoreContext {
42
50
  private static opCounter = 0n
43
51
  protected defers = new Map<
@@ -244,3 +252,37 @@ export class StoreContext extends AbstractStoreContext {
244
252
  })
245
253
  }
246
254
  }
255
+
256
+ // for service v2
257
+ export class DataBindingContext extends AbstractStoreContext implements IDataBindingContext {
258
+ constructor(
259
+ readonly processId: number,
260
+ readonly subject: Subject<DeepPartial<ProcessStreamResponseV2>>
261
+ ) {
262
+ super(processId)
263
+ }
264
+
265
+ sendTemplateRequest(templates: Array<TemplateInstance>) {
266
+ this.subject.next({
267
+ processId: this.processId,
268
+ tplRequest: {
269
+ templates
270
+ }
271
+ })
272
+ }
273
+ sendTimeseriesRequest(timeseries: Array<TimeseriesResult>) {
274
+ this.subject.next({
275
+ processId: this.processId,
276
+ tsRequest: {
277
+ data: timeseries
278
+ }
279
+ })
280
+ }
281
+
282
+ doSend(resp: DeepPartial<ProcessStreamResponseV2>) {
283
+ this.subject.next({
284
+ ...resp,
285
+ processId: this.processId
286
+ })
287
+ }
288
+ }
@@ -2,19 +2,22 @@ import { CallContext } from 'nice-grpc'
2
2
  import { createRequire } from 'module'
3
3
  // Different than the simple one which
4
4
  import {
5
+ ConfigureHandlersRequest,
5
6
  DataBinding,
6
7
  ExecutionConfig,
7
8
  HandlerType,
9
+ InitResponse,
8
10
  PreprocessStreamRequest,
9
11
  ProcessBindingsRequest,
10
12
  ProcessConfigRequest,
13
+ ProcessConfigResponse,
11
14
  ProcessorServiceImplementation,
12
15
  ProcessResult,
13
16
  ProcessStreamRequest,
14
17
  StartRequest
15
18
  } from './gen/processor/protos/processor.js'
16
19
 
17
- import { Empty } from '@sentio/protos'
20
+ import { ConfigureHandlersResponse, DeepPartial, Empty, ProcessorV3ServiceImplementation } from '@sentio/protos'
18
21
  import fs from 'fs-extra'
19
22
  import path from 'path'
20
23
  import os from 'os'
@@ -78,9 +81,15 @@ function locatePackageJson(pkgId: string) {
78
81
  return JSON.parse(content)
79
82
  }
80
83
 
81
- export class FullProcessorServiceImpl implements ProcessorServiceImplementation {
82
- constructor(instance: ProcessorServiceImplementation) {
83
- this.instance = instance
84
+ /**
85
+ * The RuntimeServicePatcher class is responsible for providing backward compatibility
86
+ * patches for different SDK versions. It ensures that the runtime can adapt to changes
87
+ * in the SDK by applying necessary adjustments to data bindings and other configurations.
88
+ */
89
+ export class RuntimeServicePatcher {
90
+ sdkVersion: Semver
91
+
92
+ constructor() {
84
93
  const sdkPackageJson = locatePackageJson('@sentio/sdk')
85
94
  const runtimePackageJson = locatePackageJson('@sentio/runtime')
86
95
 
@@ -89,111 +98,7 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
89
98
  this.sdkVersion = parseSemver(sdkPackageJson.version)
90
99
  }
91
100
 
92
- instance: ProcessorServiceImplementation
93
- sdkVersion: Semver
94
-
95
- async getConfig(request: ProcessConfigRequest, context: CallContext) {
96
- const config = await this.instance.getConfig(request, context)
97
- config.executionConfig = ExecutionConfig.fromPartial(GLOBAL_CONFIG.execution)
98
-
99
- if (config.contractConfigs) {
100
- for (const contract of config.contractConfigs) {
101
- // for old fuel processor
102
- if (
103
- compareSemver(this.sdkVersion, FUEL_PROTO_NO_FUEL_TRANSACTION_AS_CALL_VERSION) < 0 &&
104
- contract.fuelCallConfigs
105
- ) {
106
- contract.fuelTransactionConfigs = contract.fuelCallConfigs
107
- contract.fuelCallConfigs = undefined
108
- }
109
-
110
- // @ts-ignore convert old fuelLogConfigs to fuelReceiptConfigs
111
- if (contract.fuelLogConfigs) {
112
- contract.fuelReceiptConfigs = contract.fuelLogConfigs.map((e) => ({
113
- handlerId: e.handlerId,
114
- handlerName: e.handlerName,
115
- log: {
116
- logIds: e.logIds
117
- }
118
- }))
119
- }
120
-
121
- // @ts-ignore old fields
122
- if (contract.aptosCallConfigs) {
123
- // @ts-ignore old fields
124
- contract.moveCallConfigs = contract.aptosCallConfigs
125
- }
126
- // @ts-ignore old fields
127
- if (contract.aptosEventConfigs) {
128
- // @ts-ignore old fields
129
- contract.moveEventConfigs = contract.aptosEventConfigs
130
- }
131
- }
132
- }
133
-
134
- if (compareSemver(this.sdkVersion, MOVE_USE_RAW_VERSION) < 0) {
135
- PROCESSED_MOVE_EVENT_TX_HANDLER.clear()
136
- }
137
-
138
- return config
139
- }
140
-
141
- async start(request: StartRequest, context: CallContext) {
142
- return await this.instance.start(request, context)
143
- }
144
-
145
- async stop(request: Empty, context: CallContext) {
146
- return await this.instance.stop(request, context)
147
- }
148
-
149
- async processBindings(request: ProcessBindingsRequest, options: CallContext) {
150
- // if (GLOBAL_CONFIG.execution.sequential) {
151
- // request.bindings = request.bindings.sort(dataCompare)
152
- // }
153
-
154
- for (const binding of request.bindings) {
155
- this.adjustDataBinding(binding)
156
- }
157
- try {
158
- const result = await this.instance.processBindings(request, options)
159
- this.adjustResult(result.result as ProcessResult)
160
- if (!result.configUpdated && result.result?.states?.configUpdated) {
161
- result.configUpdated = result.result?.states?.configUpdated
162
- }
163
- return result
164
- } catch (e) {
165
- if (this.sdkVersion.minor <= 16) {
166
- // Old sdk doesn't handle this well
167
- if (
168
- e.code === os.constants.errno.ECONNRESET ||
169
- e.code === os.constants.errno.ECONNREFUSED ||
170
- e.code === os.constants.errno.ECONNABORTED
171
- ) {
172
- process.exit(1)
173
- }
174
- }
175
- throw e
176
- }
177
- }
178
-
179
- async *adjustBindingsStream(requests: AsyncIterable<ProcessStreamRequest>): AsyncIterable<ProcessStreamRequest> {
180
- for await (const request of requests) {
181
- this.adjustDataBinding(request.binding)
182
- yield request
183
- }
184
- }
185
-
186
- async *processBindingsStream(requests: AsyncIterable<ProcessStreamRequest>, context: CallContext) {
187
- yield* this.instance.processBindingsStream(this.adjustBindingsStream(requests), context)
188
- }
189
-
190
- async *preprocessBindingsStream(requests: AsyncIterable<PreprocessStreamRequest>, context: CallContext) {
191
- yield* this.instance.preprocessBindingsStream(this.adjustBindingsStream(requests), context)
192
- }
193
-
194
- private adjustResult(res: ProcessResult): void {}
195
-
196
- private adjustDataBinding(dataBinding?: DataBinding): void {
101
+ adjustDataBinding(dataBinding?: DataBinding): void {
197
102
  const isBeforeMoveUseRawVersion = compareSemver(this.sdkVersion, MOVE_USE_RAW_VERSION) < 0
198
103
  // const isBeforeEthUseRawVersion = compareSemver(this.sdkVersion,ETH_USE_RAW_VERSION) < 0
199
104
 
@@ -350,6 +255,127 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
350
255
  break
351
256
  }
352
257
  }
258
+
259
+ patchConfig(config: DeepPartial<ProcessConfigResponse>): void {
260
+ config.executionConfig = ExecutionConfig.fromPartial(GLOBAL_CONFIG.execution)
261
+
262
+ if (config.contractConfigs) {
263
+ for (const contract of config.contractConfigs) {
264
+ // for old fuel processor
265
+ if (
266
+ compareSemver(this.sdkVersion, FUEL_PROTO_NO_FUEL_TRANSACTION_AS_CALL_VERSION) < 0 &&
267
+ contract.fuelCallConfigs
268
+ ) {
269
+ contract.fuelTransactionConfigs = contract.fuelCallConfigs
270
+ contract.fuelCallConfigs = undefined
271
+ }
272
+
273
+ // @ts-ignore convert old fuelLogConfigs to fuelReceiptConfigs
274
+ if (contract.fuelLogConfigs) {
275
+ contract.fuelReceiptConfigs = contract.fuelLogConfigs.map((e) => ({
276
+ handlerId: e.handlerId,
277
+ handlerName: e.handlerName,
278
+ log: {
279
+ logIds: e.logIds
280
+ }
281
+ }))
282
+ }
283
+
284
+ // @ts-ignore old fields
285
+ if (contract.aptosCallConfigs) {
286
+ // @ts-ignore old fields
287
+ contract.moveCallConfigs = contract.aptosCallConfigs
288
+ }
289
+ // @ts-ignore old fields
290
+ if (contract.aptosEventConfigs) {
291
+ // @ts-ignore old fields
292
+ contract.moveEventConfigs = contract.aptosEventConfigs
293
+ }
294
+ }
295
+ }
296
+ }
297
+ }
298
+
299
+ export class FullProcessorServiceImpl implements ProcessorServiceImplementation {
300
+ constructor(instance: ProcessorServiceImplementation) {
301
+ this.instance = instance
302
+ const sdkPackageJson = locatePackageJson('@sentio/sdk')
303
+ const runtimePackageJson = locatePackageJson('@sentio/runtime')
304
+
305
+ console.log('Runtime version:', runtimePackageJson.version, 'SDK version:', sdkPackageJson.version)
306
+
307
+ this.sdkVersion = parseSemver(sdkPackageJson.version)
308
+ }
309
+
310
+ instance: ProcessorServiceImplementation
311
+ sdkVersion: Semver
312
+ patcher: RuntimeServicePatcher = new RuntimeServicePatcher()
313
+
314
+ async getConfig(request: ProcessConfigRequest, context: CallContext) {
315
+ const config = await this.instance.getConfig(request, context)
316
+ this.patcher.patchConfig(config)
317
+
318
+ if (compareSemver(this.sdkVersion, MOVE_USE_RAW_VERSION) < 0) {
319
+ PROCESSED_MOVE_EVENT_TX_HANDLER.clear()
320
+ }
321
+
322
+ return config
323
+ }
324
+
325
+ async start(request: StartRequest, context: CallContext) {
326
+ return await this.instance.start(request, context)
327
+ }
328
+
329
+ async stop(request: Empty, context: CallContext) {
330
+ return await this.instance.stop(request, context)
331
+ }
332
+
333
+ async processBindings(request: ProcessBindingsRequest, options: CallContext) {
334
+ // if (GLOBAL_CONFIG.execution.sequential) {
335
+ // request.bindings = request.bindings.sort(dataCompare)
336
+ // }
337
+
338
+ for (const binding of request.bindings) {
339
+ this.patcher.adjustDataBinding(binding)
340
+ }
341
+ try {
342
+ const result = await this.instance.processBindings(request, options)
343
+ this.adjustResult(result.result as ProcessResult)
344
+ if (!result.configUpdated && result.result?.states?.configUpdated) {
345
+ result.configUpdated = result.result?.states?.configUpdated
346
+ }
347
+ return result
348
+ } catch (e) {
349
+ if (this.sdkVersion.minor <= 16) {
350
+ // Old sdk doesn't handle this well
351
+ if (
352
+ e.code === os.constants.errno.ECONNRESET ||
353
+ e.code === os.constants.errno.ECONNREFUSED ||
354
+ e.code === os.constants.errno.ECONNABORTED
355
+ ) {
356
+ process.exit(1)
357
+ }
358
+ }
359
+ throw e
360
+ }
361
+ }
362
+
363
+ async *adjustBindingsStream(requests: AsyncIterable<ProcessStreamRequest>): AsyncIterable<ProcessStreamRequest> {
364
+ for await (const request of requests) {
365
+ this.patcher.adjustDataBinding(request.binding)
366
+ yield request
367
+ }
368
+ }
369
+
370
+ async *processBindingsStream(requests: AsyncIterable<ProcessStreamRequest>, context: CallContext) {
371
+ yield* this.instance.processBindingsStream(this.adjustBindingsStream(requests), context)
372
+ }
373
+
374
+ async *preprocessBindingsStream(requests: AsyncIterable<PreprocessStreamRequest>, context: CallContext) {
375
+ yield* this.instance.preprocessBindingsStream(this.adjustBindingsStream(requests), context)
376
+ }
377
+
378
+ private adjustResult(res: ProcessResult): void {}
353
379
  }
354
380
 
355
381
  // function dataCompare(a: DataBinding, b: DataBinding): number {
@@ -383,3 +409,35 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
383
409
  // d.data?.ethTrace?.trace?.transactionPosition
384
410
  // )
385
411
  // }
412
+
413
+ export class FullProcessorServiceV3Impl implements ProcessorV3ServiceImplementation {
414
+ patcher: RuntimeServicePatcher = new RuntimeServicePatcher()
415
+
416
+ constructor(readonly instance: ProcessorV3ServiceImplementation) {}
417
+
418
+ async init(request: Empty, context: CallContext): Promise<DeepPartial<InitResponse>> {
419
+ const resp = await this.instance.init(request, context)
420
+ resp.executionConfig = ExecutionConfig.fromPartial(GLOBAL_CONFIG.execution)
421
+ return resp
422
+ }
423
+
424
+ async configureHandlers(
425
+ request: ConfigureHandlersRequest,
426
+ context: CallContext
427
+ ): Promise<DeepPartial<ConfigureHandlersResponse>> {
428
+ const config = await this.instance.configureHandlers(request, context)
429
+ this.patcher.patchConfig(config)
430
+ return config
431
+ }
432
+
433
+ async *processBindingsStream(requests: AsyncIterable<ProcessStreamRequest>, context: CallContext) {
434
+ yield* this.instance.processBindingsStream(this.adjustBindingsStream(requests), context)
435
+ }
436
+
437
+ async *adjustBindingsStream(requests: AsyncIterable<ProcessStreamRequest>): AsyncIterable<ProcessStreamRequest> {
438
+ for await (const request of requests) {
439
+ this.patcher.adjustDataBinding(request.binding)
440
+ yield request
441
+ }
442
+ }
443
+ }