@sentio/runtime 2.59.0-rc.3 → 2.59.0-rc.31

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-BPGFX5S5.js";
4
+ } from "./chunk-CPLWSUD7.js";
5
5
  import {
6
6
  AbstractStoreContext,
7
7
  configureEndpoints,
@@ -10,12 +10,12 @@ import {
10
10
  recordRuntimeInfo,
11
11
  require_lib3 as require_lib,
12
12
  require_lib4 as require_lib2
13
- } from "./chunk-QELD44EL.js";
13
+ } from "./chunk-X2VTMTYL.js";
14
14
  import {
15
15
  PluginManager,
16
16
  ProcessConfigResponse,
17
17
  __toESM
18
- } from "./chunk-ZUTD563J.js";
18
+ } from "./chunk-FO2V2K7T.js";
19
19
 
20
20
  // src/service-worker.ts
21
21
  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.0-rc.3",
3
+ "version": "2.59.0-rc.31",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -21,6 +21,7 @@ import os from 'os'
21
21
  import { GLOBAL_CONFIG } from './global-config.js'
22
22
  import { compareSemver, parseSemver, Semver } from './utils.js'
23
23
  import { LRUCache } from 'lru-cache'
24
+ import { createHash } from 'crypto'
24
25
 
25
26
  const require = createRequire(import.meta.url)
26
27
 
@@ -35,6 +36,37 @@ const PROCESSED_MOVE_EVENT_TX_HANDLER = new LRUCache<string, boolean>({
35
36
  max: 10000
36
37
  })
37
38
 
39
+ const enableTxCache = process.env.ENABLE_PARSE_CACHE === 'true'
40
+
41
+ // Cache for parsed JSON data
42
+ const PARSED_DATA_CACHE = new LRUCache<string, any>({
43
+ max: enableTxCache ? 5000 : 1
44
+ })
45
+
46
+ /**
47
+ * Gets parsed JSON data from a string, using a cache to avoid repeated parsing
48
+ * @param rawData The raw string data to parse
49
+ * @returns The parsed JSON object
50
+ */
51
+ function getParsedData(rawData: string): any {
52
+ if (!enableTxCache) {
53
+ return JSON.parse(rawData)
54
+ }
55
+
56
+ // Create a digest of the raw data for cache key
57
+ const digest = createHash('md5').update(rawData).digest('hex')
58
+
59
+ // Check if we already have this data parsed
60
+ let parsedData = PARSED_DATA_CACHE.get(digest)
61
+ if (!parsedData) {
62
+ // Parse and cache the data
63
+ parsedData = JSON.parse(rawData)
64
+ PARSED_DATA_CACHE.set(digest, parsedData)
65
+ }
66
+
67
+ return parsedData
68
+ }
69
+
38
70
  function locatePackageJson(pkgId: string) {
39
71
  const m = require.resolve(pkgId)
40
72
 
@@ -173,19 +205,32 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
173
205
  const ethLog = dataBinding.data?.ethLog
174
206
  if (ethLog?.log == null && ethLog?.rawLog) {
175
207
  ethLog.log = JSON.parse(ethLog.rawLog)
176
- ethLog.transaction = ethLog.rawTransaction ? JSON.parse(ethLog.rawTransaction) : undefined
177
- ethLog.block = ethLog.rawBlock ? JSON.parse(ethLog.rawBlock) : undefined
178
- ethLog.transactionReceipt = ethLog.rawTransactionReceipt
179
- ? JSON.parse(ethLog.rawTransactionReceipt)
180
- : undefined
208
+
209
+ if (ethLog.rawTransaction) {
210
+ ethLog.transaction = getParsedData(ethLog.rawTransaction)
211
+ }
212
+ if (ethLog.rawBlock) {
213
+ ethLog.block = getParsedData(ethLog.rawBlock)
214
+ }
215
+ if (ethLog.rawTransactionReceipt) {
216
+ ethLog.transactionReceipt = getParsedData(ethLog.rawTransactionReceipt)
217
+ }
181
218
  }
182
219
  break
183
220
  case HandlerType.ETH_TRANSACTION:
184
221
  const ethTx = dataBinding.data?.ethTransaction
185
222
  if (ethTx?.transaction == null && ethTx?.rawTransaction) {
186
- ethTx.transaction = JSON.parse(ethTx.rawTransaction)
187
- ethTx.block = ethTx.rawBlock ? JSON.parse(ethTx.rawBlock) : undefined
188
- ethTx.transactionReceipt = ethTx.rawTransactionReceipt ? JSON.parse(ethTx.rawTransactionReceipt) : undefined
223
+ ethTx.transaction = getParsedData(ethTx.rawTransaction)
224
+ if (ethTx.rawBlock) {
225
+ ethTx.block = getParsedData(ethTx.rawBlock)
226
+ } else {
227
+ ethTx.block = undefined
228
+ }
229
+ if (ethTx.rawTransactionReceipt) {
230
+ ethTx.transactionReceipt = getParsedData(ethTx.rawTransactionReceipt)
231
+ } else {
232
+ ethTx.transactionReceipt = undefined
233
+ }
189
234
  }
190
235
  break
191
236
  case HandlerType.FUEL_TRANSACTION:
@@ -209,7 +254,8 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
209
254
  const aptEvent = dataBinding.data?.aptEvent
210
255
  if (aptEvent) {
211
256
  if (isBeforeMoveUseRawVersion && aptEvent.rawTransaction) {
212
- const transaction = JSON.parse(aptEvent.rawTransaction)
257
+ const transaction = getParsedData(aptEvent.rawTransaction)
258
+
213
259
  const key = `${transaction.hash}-${dataBinding.handlerIds[0]}`
214
260
  if (PROCESSED_MOVE_EVENT_TX_HANDLER.has(key)) {
215
261
  console.debug('skip binding', key)
@@ -230,7 +276,7 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
230
276
  const aptCall = dataBinding.data?.aptCall
231
277
  if (aptCall) {
232
278
  if (isBeforeMoveUseRawVersion && aptCall.rawTransaction) {
233
- aptCall.transaction = JSON.parse(aptCall.rawTransaction)
279
+ aptCall.transaction = getParsedData(aptCall.rawTransaction)
234
280
  }
235
281
  }
236
282
  break
@@ -246,7 +292,8 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
246
292
  const suiEvent = dataBinding.data?.suiEvent
247
293
  if (suiEvent) {
248
294
  if (isBeforeMoveUseRawVersion && suiEvent.rawTransaction) {
249
- const transaction = JSON.parse(suiEvent.rawTransaction)
295
+ const transaction = getParsedData(suiEvent.rawTransaction)
296
+
250
297
  const key = `${transaction.digest}-${dataBinding.handlerIds[0]}`
251
298
  if (PROCESSED_MOVE_EVENT_TX_HANDLER.has(key)) {
252
299
  console.debug('skip binding', key)
@@ -267,7 +314,7 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
267
314
  const suiCall = dataBinding.data?.suiCall
268
315
  if (suiCall) {
269
316
  if (isBeforeMoveUseRawVersion && suiCall.rawTransaction) {
270
- suiCall.transaction = JSON.parse(suiCall.rawTransaction)
317
+ suiCall.transaction = getParsedData(suiCall.rawTransaction)
271
318
  }
272
319
  }
273
320
  break
@@ -336,4 +383,3 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
336
383
  // d.data?.ethTrace?.trace?.transactionPosition
337
384
  // )
338
385
  // }
339
- //