@sentio/runtime 2.55.0-rc.4 → 2.55.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentio/runtime",
3
- "version": "2.55.0-rc.4",
3
+ "version": "2.55.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -20,11 +20,18 @@ import path from 'path'
20
20
  import os from 'os'
21
21
  import { GLOBAL_CONFIG } from './global-config.js'
22
22
  import { compareSemver, parseSemver, Semver } from './utils.js'
23
+ import { LRUCache } from 'lru-cache'
23
24
 
24
25
  const require = createRequire(import.meta.url)
25
26
 
26
27
  const FUEL_PROTO_UPDATE_VERSION = parseSemver('2.54.0-rc.7')
28
+
27
29
  const MOVE_USE_RAW_VERSION = parseSemver('2.55.0-rc.1')
30
+ // new driver (after MOVE_USE_RAW_VERSION) will sent the same event multiple times when fetch all true
31
+ // so we need to cache it, key will be tx-handler_id
32
+ const PROCESSED_MOVE_EVENT_TX_HANDLER = new LRUCache<string, boolean>({
33
+ max: 10000
34
+ })
28
35
 
29
36
  function locatePackageJson(pkgId: string) {
30
37
  const m = require.resolve(pkgId)
@@ -154,11 +161,20 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
154
161
  case HandlerType.APT_EVENT:
155
162
  const aptEvent = dataBinding.data?.aptEvent
156
163
  if (aptEvent) {
157
- if (isBeforeMoveUseRawVersion) {
158
- aptEvent.transaction = JSON.parse(aptEvent.rawTransaction)
159
- if (!aptEvent.transaction?.events?.length) {
164
+ if (isBeforeMoveUseRawVersion && aptEvent.rawTransaction) {
165
+ const transaction = JSON.parse(aptEvent.rawTransaction)
166
+ const key = `${transaction.hash}-${dataBinding.handlerIds[0]}`
167
+ if (PROCESSED_MOVE_EVENT_TX_HANDLER.has(key)) {
168
+ console.debug('skip binding', key)
169
+ dataBinding.handlerType = HandlerType.UNKNOWN
170
+ return
171
+ }
172
+ PROCESSED_MOVE_EVENT_TX_HANDLER.set(key, true)
173
+
174
+ aptEvent.transaction = transaction
175
+ if (!transaction.events?.length) {
160
176
  // when fetch all is not true, then events is empty, we need to fill it to old format
161
- aptEvent.transaction!.events = [JSON.parse(aptEvent.rawEvent)]
177
+ transaction.events = [JSON.parse(aptEvent.rawEvent)]
162
178
  }
163
179
  }
164
180
  }
@@ -166,7 +182,7 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
166
182
  case HandlerType.APT_CALL:
167
183
  const aptCall = dataBinding.data?.aptCall
168
184
  if (aptCall) {
169
- if (isBeforeMoveUseRawVersion) {
185
+ if (isBeforeMoveUseRawVersion && aptCall.rawTransaction) {
170
186
  aptCall.transaction = JSON.parse(aptCall.rawTransaction)
171
187
  }
172
188
  }
@@ -174,7 +190,7 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
174
190
  case HandlerType.APT_RESOURCE:
175
191
  const aptResource = dataBinding.data?.aptResource
176
192
  if (aptResource) {
177
- if (isBeforeMoveUseRawVersion) {
193
+ if (isBeforeMoveUseRawVersion && aptResource.rawResources) {
178
194
  aptResource.resources = aptResource.rawResources.map((e) => JSON.parse(e))
179
195
  }
180
196
  }
@@ -182,11 +198,20 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
182
198
  case HandlerType.SUI_EVENT:
183
199
  const suiEvent = dataBinding.data?.suiEvent
184
200
  if (suiEvent) {
185
- if (isBeforeMoveUseRawVersion) {
186
- suiEvent.transaction = JSON.parse(suiEvent.rawTransaction)
187
- if (!suiEvent.transaction?.events?.length) {
201
+ if (isBeforeMoveUseRawVersion && suiEvent.rawTransaction) {
202
+ const transaction = JSON.parse(suiEvent.rawTransaction)
203
+ const key = `${transaction.digest}-${dataBinding.handlerIds[0]}`
204
+ if (PROCESSED_MOVE_EVENT_TX_HANDLER.has(key)) {
205
+ console.debug('skip binding', key)
206
+ dataBinding.handlerType = HandlerType.UNKNOWN
207
+ return
208
+ }
209
+ PROCESSED_MOVE_EVENT_TX_HANDLER.set(key, true)
210
+
211
+ suiEvent.transaction = transaction
212
+ if (!transaction.events?.length) {
188
213
  // when fetch all is not true, then events is empty, we need to fill it to old format
189
- suiEvent.transaction!.events = [JSON.parse(suiEvent.rawEvent)]
214
+ transaction.events = [JSON.parse(suiEvent.rawEvent)]
190
215
  }
191
216
  }
192
217
  }
@@ -194,7 +219,7 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
194
219
  case HandlerType.SUI_CALL:
195
220
  const suiCall = dataBinding.data?.suiCall
196
221
  if (suiCall) {
197
- if (isBeforeMoveUseRawVersion) {
222
+ if (isBeforeMoveUseRawVersion && suiCall.rawTransaction) {
198
223
  suiCall.transaction = JSON.parse(suiCall.rawTransaction)
199
224
  }
200
225
  }
@@ -202,7 +227,7 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
202
227
  case HandlerType.SUI_OBJECT:
203
228
  const suiObject = dataBinding.data?.suiObject
204
229
  if (suiObject) {
205
- if (isBeforeMoveUseRawVersion) {
230
+ if (isBeforeMoveUseRawVersion && (suiObject.rawSelf || suiObject.rawObjects)) {
206
231
  if (suiObject.rawSelf) {
207
232
  suiObject.self = JSON.parse(suiObject.rawSelf)
208
233
  }
@@ -213,7 +238,7 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
213
238
  case HandlerType.SUI_OBJECT_CHANGE:
214
239
  const suiObjectChange = dataBinding.data?.suiObjectChange
215
240
  if (suiObjectChange) {
216
- if (isBeforeMoveUseRawVersion) {
241
+ if (isBeforeMoveUseRawVersion && suiObjectChange.rawChanges) {
217
242
  suiObjectChange.changes = suiObjectChange.rawChanges.map((e) => JSON.parse(e))
218
243
  }
219
244
  }
package/src/service.ts CHANGED
@@ -35,7 +35,8 @@ import { EthChainId } from '@sentio/chain'
35
35
  import { Provider } from 'ethers'
36
36
  import { decodeMulticallResult, encodeMulticallData, getMulticallAddress, Multicall3Call } from './multicall.js'
37
37
 
38
- import { processMetrics, providerMetrics, dbMetrics } from './metrics.js'
38
+ import { dbMetrics, processMetrics, providerMetrics } from './metrics.js'
39
+
39
40
  const { process_binding_count, process_binding_time, process_binding_error } = processMetrics
40
41
 
41
42
  ;(BigInt.prototype as any).toJSON = function () {
@@ -418,6 +419,17 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
418
419
  // console.debug('received request:', request)
419
420
  if (request.binding) {
420
421
  process_binding_count.add(1)
422
+
423
+ // Adjust binding will make some request become invalid by setting UNKNOWN HandlerType
424
+ // for older SDK version, so we just return empty result for them here
425
+ if (request.binding.handlerType === HandlerType.UNKNOWN) {
426
+ subject.next({
427
+ processId: request.processId,
428
+ result: ProcessResult.create()
429
+ })
430
+ continue
431
+ }
432
+
421
433
  const binding = request.binding
422
434
  const dbContext = contexts.new(request.processId, subject)
423
435
  const start = Date.now()