@sentio/sdk 1.18.1 → 1.19.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/lib/cli/webpack.config.js +1 -1
- package/lib/core/aptos-processor.js +1 -1
- package/lib/core/aptos-processor.js.map +1 -1
- package/lib/core/base-processor.js +3 -3
- package/lib/core/base-processor.js.map +1 -1
- package/lib/core/context.d.ts +2 -0
- package/lib/core/context.js +4 -1
- package/lib/core/context.js.map +1 -1
- package/lib/core/logger.d.ts +12 -0
- package/lib/core/logger.js +37 -0
- package/lib/core/logger.js.map +1 -0
- package/lib/core/metadata.d.ts +7 -0
- package/lib/core/metadata.js +95 -0
- package/lib/core/metadata.js.map +1 -0
- package/lib/core/meter.d.ts +1 -3
- package/lib/core/meter.js +3 -87
- package/lib/core/meter.js.map +1 -1
- package/lib/core/solana-processor.js +1 -1
- package/lib/core/solana-processor.js.map +1 -1
- package/lib/core/sui-processor.js +1 -1
- package/lib/core/sui-processor.js.map +1 -1
- package/lib/service.js +27 -39
- package/lib/service.js.map +1 -1
- package/lib/tests/logger.test.d.ts +1 -0
- package/lib/tests/logger.test.js +40 -0
- package/lib/tests/logger.test.js.map +1 -0
- package/package.json +1 -1
- package/src/cli/webpack.config.js +1 -1
- package/src/core/aptos-processor.ts +1 -1
- package/src/core/base-processor.ts +3 -3
- package/src/core/context.ts +4 -2
- package/src/core/logger.ts +42 -0
- package/src/core/metadata.ts +92 -0
- package/src/core/meter.ts +3 -88
- package/src/core/solana-processor.ts +1 -1
- package/src/core/sui-processor.ts +1 -1
- package/src/service.ts +30 -45
- package/src/tests/logger.test.ts +46 -0
package/src/core/meter.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { MetricDescriptor
|
|
2
|
-
import {
|
|
1
|
+
import { MetricDescriptor } from '../gen/processor/protos/processor'
|
|
2
|
+
import { BaseContext } from './context'
|
|
3
3
|
import { toMetricValue, Numberish } from './numberish'
|
|
4
|
-
import {
|
|
4
|
+
import { GetRecordMetaData, Labels } from './metadata'
|
|
5
5
|
|
|
6
6
|
export function normalizeName(name: string): string {
|
|
7
7
|
const regex = new RegExp('![_.a-zA-Z0-9]')
|
|
@@ -27,91 +27,6 @@ export function normalizeLabels(labels: Labels): Labels {
|
|
|
27
27
|
return normLabels
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
function GetRecordMetaData(ctx: BaseContext, metric: Metric, labels: Labels): RecordMetaData {
|
|
31
|
-
let descriptor = metric.descriptor
|
|
32
|
-
if (metric.usage > 0) {
|
|
33
|
-
// Other setting don't need to be write multiple times
|
|
34
|
-
descriptor = MetricDescriptor.fromPartial({ name: descriptor.name })
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
descriptor.name = normalizeName(descriptor.name)
|
|
38
|
-
|
|
39
|
-
if (ctx instanceof Context) {
|
|
40
|
-
if (ctx.log) {
|
|
41
|
-
return {
|
|
42
|
-
contractAddress: ctx.contract.rawContract.address,
|
|
43
|
-
blockNumber: ctx.blockNumber,
|
|
44
|
-
transactionIndex: ctx.log.transactionIndex,
|
|
45
|
-
transactionHash: ctx.transactionHash || '',
|
|
46
|
-
logIndex: ctx.log.logIndex,
|
|
47
|
-
chainId: ctx.chainId.toString(),
|
|
48
|
-
descriptor: descriptor,
|
|
49
|
-
labels: normalizeLabels(labels),
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (ctx.block) {
|
|
53
|
-
return {
|
|
54
|
-
contractAddress: ctx.contract.rawContract.address,
|
|
55
|
-
blockNumber: ctx.blockNumber,
|
|
56
|
-
transactionIndex: -1,
|
|
57
|
-
transactionHash: '',
|
|
58
|
-
logIndex: -1,
|
|
59
|
-
chainId: ctx.chainId.toString(),
|
|
60
|
-
descriptor: descriptor,
|
|
61
|
-
labels: normalizeLabels(labels),
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (ctx.trace) {
|
|
65
|
-
return {
|
|
66
|
-
contractAddress: ctx.contract.rawContract.address,
|
|
67
|
-
blockNumber: ctx.blockNumber,
|
|
68
|
-
transactionIndex: ctx.trace.transactionPosition,
|
|
69
|
-
transactionHash: ctx.transactionHash || '',
|
|
70
|
-
logIndex: -1,
|
|
71
|
-
chainId: ctx.chainId.toString(),
|
|
72
|
-
descriptor: descriptor,
|
|
73
|
-
labels: normalizeLabels(labels),
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
} else if (ctx instanceof SolanaContext) {
|
|
77
|
-
return {
|
|
78
|
-
contractAddress: ctx.address,
|
|
79
|
-
blockNumber: ctx.blockNumber,
|
|
80
|
-
transactionIndex: 0,
|
|
81
|
-
transactionHash: '', // TODO add
|
|
82
|
-
logIndex: 0,
|
|
83
|
-
chainId: SOL_MAINMET_ID, // TODO set in context
|
|
84
|
-
descriptor: descriptor,
|
|
85
|
-
labels: normalizeLabels(labels),
|
|
86
|
-
}
|
|
87
|
-
} else if (ctx instanceof SuiContext) {
|
|
88
|
-
return {
|
|
89
|
-
contractAddress: ctx.address,
|
|
90
|
-
blockNumber: ctx.blockNumber,
|
|
91
|
-
transactionIndex: 0,
|
|
92
|
-
transactionHash: '', // TODO
|
|
93
|
-
logIndex: 0,
|
|
94
|
-
chainId: SUI_DEVNET_ID, // TODO set in context
|
|
95
|
-
descriptor: descriptor,
|
|
96
|
-
labels: normalizeLabels(labels),
|
|
97
|
-
}
|
|
98
|
-
} else if (ctx instanceof AptosContext) {
|
|
99
|
-
return {
|
|
100
|
-
contractAddress: ctx.address,
|
|
101
|
-
blockNumber: ctx.blockNumber,
|
|
102
|
-
transactionIndex: 0,
|
|
103
|
-
transactionHash: '', // TODO
|
|
104
|
-
logIndex: 0,
|
|
105
|
-
chainId: APTOS_TESTNET_ID, // TODO set in context
|
|
106
|
-
descriptor: descriptor,
|
|
107
|
-
labels: normalizeLabels(labels),
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
throw new Error("This can't happen")
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export type Labels = { [key: string]: string }
|
|
114
|
-
|
|
115
30
|
export class MetricDescriptorOption {
|
|
116
31
|
unit?: string
|
|
117
32
|
description?: string
|
package/src/service.ts
CHANGED
|
@@ -269,12 +269,6 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
269
269
|
throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
-
const resp: ProcessResult = {
|
|
273
|
-
gauges: [],
|
|
274
|
-
counters: [],
|
|
275
|
-
logs: [],
|
|
276
|
-
}
|
|
277
|
-
|
|
278
272
|
const promises: Promise<ProcessResult>[] = []
|
|
279
273
|
for (const l of request.logBindings) {
|
|
280
274
|
if (!l.log) {
|
|
@@ -297,11 +291,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
297
291
|
}
|
|
298
292
|
}
|
|
299
293
|
|
|
300
|
-
const
|
|
301
|
-
for (const res of results) {
|
|
302
|
-
resp.counters = resp.counters.concat(res.counters)
|
|
303
|
-
resp.gauges = resp.gauges.concat(res.gauges)
|
|
304
|
-
}
|
|
294
|
+
const result = mergeProcessResults(await Promise.all(promises))
|
|
305
295
|
|
|
306
296
|
let updated = false
|
|
307
297
|
if (
|
|
@@ -312,9 +302,9 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
312
302
|
updated = true
|
|
313
303
|
}
|
|
314
304
|
|
|
315
|
-
recordRuntimeInfo(
|
|
305
|
+
recordRuntimeInfo(result, HandlerType.LOG)
|
|
316
306
|
return {
|
|
317
|
-
result
|
|
307
|
+
result,
|
|
318
308
|
configUpdated: updated,
|
|
319
309
|
}
|
|
320
310
|
}
|
|
@@ -346,6 +336,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
346
336
|
if (res) {
|
|
347
337
|
res.gauges.forEach((g) => result.gauges.push(g))
|
|
348
338
|
res.counters.forEach((c) => result.counters.push(c))
|
|
339
|
+
res.logs.forEach((l) => result.logs.push(l))
|
|
349
340
|
}
|
|
350
341
|
}
|
|
351
342
|
resolve()
|
|
@@ -369,6 +360,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
369
360
|
if (res) {
|
|
370
361
|
res.gauges.forEach((g) => result.gauges.push(g))
|
|
371
362
|
res.counters.forEach((c) => result.counters.push(c))
|
|
363
|
+
res.logs.forEach((l) => result.logs.push(l))
|
|
372
364
|
}
|
|
373
365
|
}
|
|
374
366
|
}
|
|
@@ -425,6 +417,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
425
417
|
if (res) {
|
|
426
418
|
res.gauges.forEach((g) => result.gauges.push(g))
|
|
427
419
|
res.counters.forEach((c) => result.counters.push(c))
|
|
420
|
+
res.logs.forEach((l) => result.logs.push(l))
|
|
428
421
|
} else {
|
|
429
422
|
console.warn(
|
|
430
423
|
`Failed to decode the instruction: ${instruction.instructionData} with slot: ${instruction.slot}`
|
|
@@ -452,18 +445,11 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
452
445
|
}
|
|
453
446
|
|
|
454
447
|
const promises = request.blockBindings.map((binding) => this.processBlock(binding))
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
const res = ProcessResult.fromPartial({})
|
|
448
|
+
const result = mergeProcessResults(await Promise.all(promises))
|
|
458
449
|
|
|
459
|
-
|
|
460
|
-
res.counters = res.counters.concat(r.counters)
|
|
461
|
-
res.gauges = res.gauges.concat(r.gauges)
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
recordRuntimeInfo(res, HandlerType.BLOCK)
|
|
450
|
+
recordRuntimeInfo(result, HandlerType.BLOCK)
|
|
465
451
|
return {
|
|
466
|
-
result
|
|
452
|
+
result,
|
|
467
453
|
}
|
|
468
454
|
}
|
|
469
455
|
|
|
@@ -475,12 +461,6 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
475
461
|
|
|
476
462
|
const block: Block = JSON.parse(jsonString)
|
|
477
463
|
|
|
478
|
-
const resp: ProcessResult = {
|
|
479
|
-
gauges: [],
|
|
480
|
-
counters: [],
|
|
481
|
-
logs: [],
|
|
482
|
-
}
|
|
483
|
-
|
|
484
464
|
const promises: Promise<ProcessResult>[] = []
|
|
485
465
|
for (const handlerId of binding.handlerIds) {
|
|
486
466
|
const promise = this.blockHandlers[handlerId](block).catch((e) => {
|
|
@@ -488,12 +468,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
488
468
|
})
|
|
489
469
|
promises.push(promise)
|
|
490
470
|
}
|
|
491
|
-
|
|
492
|
-
for (const res of allRes) {
|
|
493
|
-
resp.counters = resp.counters.concat(res.counters)
|
|
494
|
-
resp.gauges = resp.gauges.concat(res.gauges)
|
|
495
|
-
}
|
|
496
|
-
return resp
|
|
471
|
+
return mergeProcessResults(await Promise.all(promises))
|
|
497
472
|
}
|
|
498
473
|
|
|
499
474
|
async processTraces(request: ProcessTracesRequest, context: CallContext): Promise<ProcessTracesResponse> {
|
|
@@ -502,18 +477,11 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
502
477
|
}
|
|
503
478
|
|
|
504
479
|
const promises = request.traceBindings.map((binding) => this.processTrace(binding))
|
|
505
|
-
const
|
|
506
|
-
|
|
507
|
-
const res = ProcessResult.fromPartial({})
|
|
508
|
-
|
|
509
|
-
for (const r of results) {
|
|
510
|
-
res.counters = res.counters.concat(r.counters)
|
|
511
|
-
res.gauges = res.gauges.concat(r.gauges)
|
|
512
|
-
}
|
|
480
|
+
const result = mergeProcessResults(await Promise.all(promises))
|
|
513
481
|
|
|
514
|
-
recordRuntimeInfo(
|
|
482
|
+
recordRuntimeInfo(result, HandlerType.TRACE)
|
|
515
483
|
return {
|
|
516
|
-
result
|
|
484
|
+
result,
|
|
517
485
|
}
|
|
518
486
|
}
|
|
519
487
|
|
|
@@ -571,6 +539,17 @@ function Utf8ArrayToStr(array: Uint8Array) {
|
|
|
571
539
|
return out
|
|
572
540
|
}
|
|
573
541
|
|
|
542
|
+
function mergeProcessResults(results: ProcessResult[]): ProcessResult {
|
|
543
|
+
const res = ProcessResult.fromPartial({})
|
|
544
|
+
|
|
545
|
+
for (const r of results) {
|
|
546
|
+
res.counters = res.counters.concat(r.counters)
|
|
547
|
+
res.gauges = res.gauges.concat(r.gauges)
|
|
548
|
+
res.logs = res.logs.concat(r.logs)
|
|
549
|
+
}
|
|
550
|
+
return res
|
|
551
|
+
}
|
|
552
|
+
|
|
574
553
|
function recordRuntimeInfo(results: ProcessResult, handlerType: HandlerType) {
|
|
575
554
|
results.gauges.forEach((e) => {
|
|
576
555
|
e.runtimeInfo = {
|
|
@@ -583,6 +562,12 @@ function recordRuntimeInfo(results: ProcessResult, handlerType: HandlerType) {
|
|
|
583
562
|
from: handlerType,
|
|
584
563
|
}
|
|
585
564
|
})
|
|
565
|
+
|
|
566
|
+
results.logs.forEach((e) => {
|
|
567
|
+
e.runtimeInfo = {
|
|
568
|
+
from: handlerType,
|
|
569
|
+
}
|
|
570
|
+
})
|
|
586
571
|
}
|
|
587
572
|
|
|
588
573
|
function errorString(e: Error): string {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { assert, expect } from 'chai'
|
|
2
|
+
|
|
3
|
+
import { TestProcessorServer } from '../testing'
|
|
4
|
+
import { BigNumber } from 'ethers'
|
|
5
|
+
import { mockApprovalLog, mockTransferLog } from '../builtin/erc20/test-utils'
|
|
6
|
+
import { ERC20Processor } from '../builtin/internal/erc20_processor'
|
|
7
|
+
|
|
8
|
+
describe('Test Error Capture', () => {
|
|
9
|
+
const service = new TestProcessorServer(() => {
|
|
10
|
+
ERC20Processor.bind({ address: '0x80009ff8154bd5653c6dda2fa5f5053e5a5c1a91' })
|
|
11
|
+
.onEventApproval((evt, ctx) => {
|
|
12
|
+
ctx.logger.info(`approve ${evt.args}`)
|
|
13
|
+
})
|
|
14
|
+
.onEventTransfer((evt, ctx) => {
|
|
15
|
+
ctx.logger.warn('transferred ' + evt.args.value, { from: evt.args.from })
|
|
16
|
+
})
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
beforeAll(async () => {
|
|
20
|
+
await service.start()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('Check approve', async () => {
|
|
24
|
+
const res = await service.testLog(
|
|
25
|
+
mockApprovalLog('0x80009ff8154bd5653c6dda2fa5f5053e5a5c1a91', {
|
|
26
|
+
owner: '0x80009ff8154bd5653c6dda2fa5f5053e5a5c1a91',
|
|
27
|
+
spender: '0x0000000000000000000000000000000000000000',
|
|
28
|
+
value: BigNumber.from(0),
|
|
29
|
+
})
|
|
30
|
+
)
|
|
31
|
+
assert(res.result?.logs?.[0].message.includes('approve '))
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('Check transfer', async () => {
|
|
35
|
+
const res = await service.testLog(
|
|
36
|
+
mockTransferLog('0x80009ff8154bd5653c6dda2fa5f5053e5a5c1a91', {
|
|
37
|
+
from: '0x80009ff8154bd5653c6dda2fa5f5053e5a5c1a91',
|
|
38
|
+
to: '0x0000000000000000000000000000000000000000',
|
|
39
|
+
value: BigNumber.from(0),
|
|
40
|
+
})
|
|
41
|
+
)
|
|
42
|
+
const log = res.result?.logs?.[0]
|
|
43
|
+
expect(log?.message).eq('transferred 0')
|
|
44
|
+
expect(log?.metadata?.labels['from'].toLowerCase()).eq('0x80009ff8154bd5653c6dda2fa5f5053e5a5c1a91')
|
|
45
|
+
})
|
|
46
|
+
})
|