@sentio/runtime 2.40.0-rc.20 → 2.40.0-rc.21
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-WN27EZMT.js → chunk-HF2KLDBY.js} +165 -64
- package/lib/index.js +1 -1
- package/lib/processor-runner.js +3 -2
- package/package.json +1 -1
- package/src/db-context.ts +15 -36
- package/src/metrics.ts +138 -0
- package/src/processor-runner.ts +3 -1
- package/src/provider.ts +2 -9
- package/src/service.ts +4 -6
@@ -59567,38 +59567,147 @@ function deepFreeze(object2) {
|
|
59567
59567
|
}
|
59568
59568
|
|
59569
59569
|
// src/db-context.ts
|
59570
|
-
init_esm2();
|
59571
59570
|
import * as process2 from "process";
|
59572
|
-
|
59573
|
-
|
59574
|
-
|
59575
|
-
var
|
59576
|
-
|
59577
|
-
|
59578
|
-
|
59579
|
-
|
59571
|
+
|
59572
|
+
// src/metrics.ts
|
59573
|
+
init_esm2();
|
59574
|
+
var meter = metrics.getMeter("processor");
|
59575
|
+
var C = class {
|
59576
|
+
counter;
|
59577
|
+
value = 0;
|
59578
|
+
constructor(name) {
|
59579
|
+
this.counter = meter.createCounter(name);
|
59580
|
+
}
|
59581
|
+
add(value, attributes) {
|
59582
|
+
this.counter.add(value, attributes);
|
59583
|
+
this.value += value;
|
59584
|
+
}
|
59585
|
+
get() {
|
59586
|
+
return this.value;
|
59587
|
+
}
|
59580
59588
|
};
|
59581
|
-
var
|
59582
|
-
|
59583
|
-
|
59584
|
-
|
59585
|
-
|
59589
|
+
var G = class {
|
59590
|
+
gauge;
|
59591
|
+
value = 0;
|
59592
|
+
constructor(name) {
|
59593
|
+
this.gauge = meter.createGauge(name);
|
59594
|
+
}
|
59595
|
+
record(value, attributes) {
|
59596
|
+
this.gauge.record(value, attributes);
|
59597
|
+
this.value = value;
|
59598
|
+
}
|
59599
|
+
get() {
|
59600
|
+
return this.value;
|
59601
|
+
}
|
59586
59602
|
};
|
59587
|
-
var
|
59588
|
-
|
59589
|
-
|
59590
|
-
|
59591
|
-
|
59603
|
+
var dbMetrics = {
|
59604
|
+
send_counts: {
|
59605
|
+
get: new C("store_get_count"),
|
59606
|
+
upsert: new C("store_upsert_count"),
|
59607
|
+
list: new C("store_list_count"),
|
59608
|
+
delete: new C("store_delete_count")
|
59609
|
+
},
|
59610
|
+
recv_counts: {
|
59611
|
+
get: new C("store_get_count"),
|
59612
|
+
upsert: new C("store_upsert_count"),
|
59613
|
+
list: new C("store_list_count"),
|
59614
|
+
delete: new C("store_delete_count")
|
59615
|
+
},
|
59616
|
+
request_times: {
|
59617
|
+
get: new C("store_get_time"),
|
59618
|
+
upsert: new C("store_upsert_time"),
|
59619
|
+
list: new C("store_list_time"),
|
59620
|
+
delete: new C("store_delete_time")
|
59621
|
+
},
|
59622
|
+
request_errors: {
|
59623
|
+
get: new C("store_get_error"),
|
59624
|
+
upsert: new C("store_upsert_error"),
|
59625
|
+
list: new C("store_list_error"),
|
59626
|
+
delete: new C("store_delete_error")
|
59627
|
+
},
|
59628
|
+
batched_total_count: new C("batched_total_count"),
|
59629
|
+
batched_request_count: new C("batched_request_count"),
|
59630
|
+
unsolved_requests: new G("store_unsolved_requests"),
|
59631
|
+
stats() {
|
59632
|
+
return {
|
59633
|
+
send_counts: {
|
59634
|
+
get: this.send_counts.get.get(),
|
59635
|
+
upsert: this.send_counts.upsert.get(),
|
59636
|
+
list: this.send_counts.list.get(),
|
59637
|
+
delete: this.send_counts.delete.get()
|
59638
|
+
},
|
59639
|
+
recv_counts: {
|
59640
|
+
get: this.recv_counts.get.get(),
|
59641
|
+
upsert: this.recv_counts.upsert.get(),
|
59642
|
+
list: this.recv_counts.list.get(),
|
59643
|
+
delete: this.recv_counts.delete.get()
|
59644
|
+
},
|
59645
|
+
request_times: {
|
59646
|
+
get: this.request_times.get.get(),
|
59647
|
+
upsert: this.request_times.upsert.get(),
|
59648
|
+
list: this.request_times.list.get(),
|
59649
|
+
delete: this.request_times.delete.get()
|
59650
|
+
},
|
59651
|
+
request_errors: {
|
59652
|
+
get: this.request_errors.get.get(),
|
59653
|
+
upsert: this.request_errors.upsert.get(),
|
59654
|
+
list: this.request_errors.list.get(),
|
59655
|
+
delete: this.request_errors.delete.get()
|
59656
|
+
},
|
59657
|
+
batched_total_count: this.batched_total_count.get(),
|
59658
|
+
batched_request_count: this.batched_request_count.get(),
|
59659
|
+
unsolved_requests: this.unsolved_requests.get(),
|
59660
|
+
average_request_time: {
|
59661
|
+
get: this.request_times.get.get() / this.send_counts.get.get(),
|
59662
|
+
upsert: this.request_times.upsert.get() / this.send_counts.upsert.get(),
|
59663
|
+
list: this.request_times.list.get() / this.send_counts.list.get()
|
59664
|
+
}
|
59665
|
+
};
|
59666
|
+
}
|
59592
59667
|
};
|
59593
|
-
var
|
59594
|
-
|
59595
|
-
|
59596
|
-
|
59597
|
-
|
59668
|
+
var providerMetrics = {
|
59669
|
+
hit_count: new C("provider_hit_count"),
|
59670
|
+
miss_count: new C("provider_miss_count"),
|
59671
|
+
queue_size: new G("provider_queue_size"),
|
59672
|
+
total_duration: new C("provider_total_duration"),
|
59673
|
+
total_queued: new C("provider_total_queued"),
|
59674
|
+
stats() {
|
59675
|
+
return {
|
59676
|
+
hit_count: this.hit_count.get(),
|
59677
|
+
miss_count: this.miss_count.get(),
|
59678
|
+
queue_size: this.queue_size.get(),
|
59679
|
+
total_duration: this.total_duration.get(),
|
59680
|
+
total_queued: this.total_queued.get(),
|
59681
|
+
average_queue_time: this.total_queued.get() / (this.hit_count.get() + this.miss_count.get()),
|
59682
|
+
average_duration: this.total_duration.get() / (this.hit_count.get() + this.miss_count.get())
|
59683
|
+
};
|
59684
|
+
}
|
59685
|
+
};
|
59686
|
+
var processMetrics = {
|
59687
|
+
process_binding_count: new C("process_binding_count"),
|
59688
|
+
process_binding_time: new C("process_binding_time"),
|
59689
|
+
process_binding_error: new C("process_binding_error"),
|
59690
|
+
stats() {
|
59691
|
+
return {
|
59692
|
+
process_binding_count: this.process_binding_count.get(),
|
59693
|
+
process_binding_time: this.process_binding_time.get(),
|
59694
|
+
process_binding_error: this.process_binding_error.get()
|
59695
|
+
};
|
59696
|
+
}
|
59598
59697
|
};
|
59599
|
-
|
59600
|
-
|
59601
|
-
var
|
59698
|
+
|
59699
|
+
// src/db-context.ts
|
59700
|
+
var {
|
59701
|
+
request_errors,
|
59702
|
+
unsolved_requests,
|
59703
|
+
request_times,
|
59704
|
+
batched_request_count,
|
59705
|
+
batched_total_count,
|
59706
|
+
send_counts,
|
59707
|
+
recv_counts
|
59708
|
+
} = dbMetrics;
|
59709
|
+
var STORE_BATCH_IDLE = process2.env["STORE_BATCH_MAX_IDLE"] ? parseInt(process2.env["STORE_BATCH_MAX_IDLE"]) : 1;
|
59710
|
+
var STORE_BATCH_SIZE = process2.env["STORE_BATCH_SIZE"] ? parseInt(process2.env["STORE_BATCH_SIZE"]) : 10;
|
59602
59711
|
var timeoutError = Symbol();
|
59603
59712
|
var _StoreContext = class {
|
59604
59713
|
constructor(subject, processId) {
|
@@ -59622,7 +59731,6 @@ var _StoreContext = class {
|
|
59622
59731
|
const promise = this.newPromise(opId, requestType);
|
59623
59732
|
const start = Date.now();
|
59624
59733
|
const promises = [promise];
|
59625
|
-
console.debug("sending db request ", opId, request);
|
59626
59734
|
let timer;
|
59627
59735
|
if (timeoutSecs) {
|
59628
59736
|
const timeoutPromise = new Promise((_r, rej) => timer = setTimeout(rej, timeoutSecs * 1e3, timeoutError));
|
@@ -59637,7 +59745,9 @@ var _StoreContext = class {
|
|
59637
59745
|
});
|
59638
59746
|
send_counts[requestType]?.add(1);
|
59639
59747
|
return Promise.race(promises).then((result) => {
|
59640
|
-
|
59748
|
+
if (timeoutSecs) {
|
59749
|
+
console.debug("db request", requestType, "op", opId, " took", Date.now() - start, "ms");
|
59750
|
+
}
|
59641
59751
|
request_times[requestType]?.add(Date.now() - start);
|
59642
59752
|
return result;
|
59643
59753
|
}).catch((e) => {
|
@@ -59655,7 +59765,6 @@ var _StoreContext = class {
|
|
59655
59765
|
result(dbResult) {
|
59656
59766
|
const opId = dbResult.opId;
|
59657
59767
|
const defer = this.defers.get(opId);
|
59658
|
-
console.debug("received db result ", opId, dbResult);
|
59659
59768
|
if (defer) {
|
59660
59769
|
if (defer.requestType) {
|
59661
59770
|
recv_counts[defer.requestType]?.add(1);
|
@@ -59745,7 +59854,6 @@ var import_nice_grpc_error_details = __toESM(require_lib3(), 1);
|
|
59745
59854
|
var import_Ix_dom_asynciterable = __toESM(require_Ix_dom_asynciterable(), 1);
|
59746
59855
|
var import_Ix_dom_asynciterable_operators = __toESM(require_Ix_dom_asynciterable_operators(), 1);
|
59747
59856
|
var import_rxjs = __toESM(require_cjs(), 1);
|
59748
|
-
init_esm2();
|
59749
59857
|
|
59750
59858
|
// ../../node_modules/.pnpm/@sentio+ethers@6.13.1_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/@sentio/ethers/lib.esm/_version.js
|
59751
59859
|
var version = "6.13.1";
|
@@ -62325,18 +62433,18 @@ var SHA256 = class extends SHA2 {
|
|
62325
62433
|
this.H = IV[7] | 0;
|
62326
62434
|
}
|
62327
62435
|
get() {
|
62328
|
-
const { A, B, C, D, E, F, G, H } = this;
|
62329
|
-
return [A, B,
|
62436
|
+
const { A, B, C: C2, D, E, F, G: G2, H } = this;
|
62437
|
+
return [A, B, C2, D, E, F, G2, H];
|
62330
62438
|
}
|
62331
62439
|
// prettier-ignore
|
62332
|
-
set(A, B,
|
62440
|
+
set(A, B, C2, D, E, F, G2, H) {
|
62333
62441
|
this.A = A | 0;
|
62334
62442
|
this.B = B | 0;
|
62335
|
-
this.C =
|
62443
|
+
this.C = C2 | 0;
|
62336
62444
|
this.D = D | 0;
|
62337
62445
|
this.E = E | 0;
|
62338
62446
|
this.F = F | 0;
|
62339
|
-
this.G =
|
62447
|
+
this.G = G2 | 0;
|
62340
62448
|
this.H = H | 0;
|
62341
62449
|
}
|
62342
62450
|
process(view, offset) {
|
@@ -62349,30 +62457,30 @@ var SHA256 = class extends SHA2 {
|
|
62349
62457
|
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
62350
62458
|
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
62351
62459
|
}
|
62352
|
-
let { A, B, C, D, E, F, G, H } = this;
|
62460
|
+
let { A, B, C: C2, D, E, F, G: G2, H } = this;
|
62353
62461
|
for (let i = 0; i < 64; i++) {
|
62354
62462
|
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
62355
|
-
const T12 = H + sigma1 + Chi(E, F,
|
62463
|
+
const T12 = H + sigma1 + Chi(E, F, G2) + SHA256_K[i] + SHA256_W[i] | 0;
|
62356
62464
|
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
62357
|
-
const T2 = sigma0 + Maj(A, B,
|
62358
|
-
H =
|
62359
|
-
|
62465
|
+
const T2 = sigma0 + Maj(A, B, C2) | 0;
|
62466
|
+
H = G2;
|
62467
|
+
G2 = F;
|
62360
62468
|
F = E;
|
62361
62469
|
E = D + T12 | 0;
|
62362
|
-
D =
|
62363
|
-
|
62470
|
+
D = C2;
|
62471
|
+
C2 = B;
|
62364
62472
|
B = A;
|
62365
62473
|
A = T12 + T2 | 0;
|
62366
62474
|
}
|
62367
62475
|
A = A + this.A | 0;
|
62368
62476
|
B = B + this.B | 0;
|
62369
|
-
|
62477
|
+
C2 = C2 + this.C | 0;
|
62370
62478
|
D = D + this.D | 0;
|
62371
62479
|
E = E + this.E | 0;
|
62372
62480
|
F = F + this.F | 0;
|
62373
|
-
|
62481
|
+
G2 = G2 + this.G | 0;
|
62374
62482
|
H = H + this.H | 0;
|
62375
|
-
this.set(A, B,
|
62483
|
+
this.set(A, B, C2, D, E, F, G2, H);
|
62376
62484
|
}
|
62377
62485
|
roundClean() {
|
62378
62486
|
SHA256_W.fill(0);
|
@@ -63505,8 +63613,8 @@ function weierstrassPoints(opts) {
|
|
63505
63613
|
* @returns non-zero affine point
|
63506
63614
|
*/
|
63507
63615
|
multiplyAndAddUnsafe(Q, a, b2) {
|
63508
|
-
const
|
63509
|
-
const mul = (P, a2) => a2 === _0n5 || a2 === _1n5 || !P.equals(
|
63616
|
+
const G2 = Point2.BASE;
|
63617
|
+
const mul = (P, a2) => a2 === _0n5 || a2 === _1n5 || !P.equals(G2) ? P.multiplyUnsafe(a2) : P.multiply(a2);
|
63510
63618
|
const sum = mul(this, a).add(mul(Q, b2));
|
63511
63619
|
return sum.is0() ? void 0 : sum;
|
63512
63620
|
}
|
@@ -63820,8 +63928,8 @@ function weierstrass(curveDef) {
|
|
63820
63928
|
const defaultVerOpts = { lowS: CURVE.lowS, prehash: false };
|
63821
63929
|
function sign(msgHash, privKey, opts = defaultSigOpts) {
|
63822
63930
|
const { seed, k2sig } = prepSig(msgHash, privKey, opts);
|
63823
|
-
const
|
63824
|
-
const drbg = createHmacDrbg(
|
63931
|
+
const C2 = CURVE;
|
63932
|
+
const drbg = createHmacDrbg(C2.hash.outputLen, C2.nByteLength, C2.hmac);
|
63825
63933
|
return drbg(seed, k2sig);
|
63826
63934
|
}
|
63827
63935
|
Point2.BASE._setWindowSize(8);
|
@@ -66205,7 +66313,7 @@ function init() {
|
|
66205
66313
|
let recs = [];
|
66206
66314
|
for (let cp of V) {
|
66207
66315
|
let gs = GROUPS.filter((g) => group_has_cp(g, cp));
|
66208
|
-
let rec = recs.find(({ G }) => gs.some((g) =>
|
66316
|
+
let rec = recs.find(({ G: G2 }) => gs.some((g) => G2.has(g)));
|
66209
66317
|
if (!rec) {
|
66210
66318
|
rec = { G: /* @__PURE__ */ new Set(), V: [] };
|
66211
66319
|
recs.push(rec);
|
@@ -66214,8 +66322,8 @@ function init() {
|
|
66214
66322
|
set_add_many(rec.G, gs);
|
66215
66323
|
}
|
66216
66324
|
let union = recs.flatMap((x) => Array_from(x.G));
|
66217
|
-
for (let { G, V: V2 } of recs) {
|
66218
|
-
let complement = new Set(union.filter((g) => !
|
66325
|
+
for (let { G: G2, V: V2 } of recs) {
|
66326
|
+
let complement = new Set(union.filter((g) => !G2.has(g)));
|
66219
66327
|
for (let cp of V2) {
|
66220
66328
|
M.set(cp, complement);
|
66221
66329
|
}
|
@@ -78290,14 +78398,8 @@ var LRUCache = class {
|
|
78290
78398
|
};
|
78291
78399
|
|
78292
78400
|
// src/provider.ts
|
78293
|
-
|
78401
|
+
var { miss_count, hit_count, total_duration, total_queued, queue_size } = providerMetrics;
|
78294
78402
|
var DummyProvider = new JsonRpcProvider("", Network.from(1));
|
78295
|
-
var meter2 = metrics.getMeter("processor_provider");
|
78296
|
-
var hit_count = meter2.createCounter("provider_hit_count");
|
78297
|
-
var miss_count = meter2.createCounter("provider_miss_count");
|
78298
|
-
var queue_size = meter2.createGauge("provider_queue_size");
|
78299
|
-
var total_duration = meter2.createCounter("provider_total_duration");
|
78300
|
-
var total_queued = meter2.createCounter("provider_total_queued");
|
78301
78403
|
var providers = /* @__PURE__ */ new Map();
|
78302
78404
|
function getProvider2(chainId) {
|
78303
78405
|
if (!chainId) {
|
@@ -78414,10 +78516,7 @@ var QueuedStaticJsonRpcProvider = class extends JsonRpcProvider {
|
|
78414
78516
|
};
|
78415
78517
|
|
78416
78518
|
// src/service.ts
|
78417
|
-
var
|
78418
|
-
var process_binding_count = meter3.createCounter("process_binding_count");
|
78419
|
-
var process_binding_time = meter3.createCounter("process_binding_time");
|
78420
|
-
var process_binding_error = meter3.createCounter("process_binding_error");
|
78519
|
+
var { process_binding_count, process_binding_time, process_binding_error } = processMetrics;
|
78421
78520
|
BigInt.prototype.toJSON = function() {
|
78422
78521
|
return this.toString();
|
78423
78522
|
};
|
@@ -78667,6 +78766,8 @@ var ProcessorServiceImpl = class {
|
|
78667
78766
|
console.debug("processBinding", request.processId, " took", cost, "ms");
|
78668
78767
|
process_binding_time.add(cost);
|
78669
78768
|
contexts.delete(request.processId);
|
78769
|
+
console.debug("db stats", JSON.stringify(dbMetrics.stats()));
|
78770
|
+
console.debug("provider stats", JSON.stringify(providerMetrics.stats()));
|
78670
78771
|
});
|
78671
78772
|
}
|
78672
78773
|
if (request.dbResult) {
|
package/lib/index.js
CHANGED
package/lib/processor-runner.js
CHANGED
@@ -40,7 +40,7 @@ import {
|
|
40
40
|
require_minimal,
|
41
41
|
require_src,
|
42
42
|
trace
|
43
|
-
} from "./chunk-
|
43
|
+
} from "./chunk-HF2KLDBY.js";
|
44
44
|
|
45
45
|
// ../../node_modules/.pnpm/universalify@2.0.1/node_modules/universalify/index.js
|
46
46
|
var require_universalify = __commonJS({
|
@@ -51373,7 +51373,8 @@ var optionDefinitions = [
|
|
51373
51373
|
{ name: "debug", type: Boolean, defaultValue: false }
|
51374
51374
|
];
|
51375
51375
|
var options = (0, import_command_line_args.default)(optionDefinitions, { partial: true });
|
51376
|
-
|
51376
|
+
var logLevel = process.env["LOG_LEVEL"]?.toUpperCase();
|
51377
|
+
setupLogger(options["log-format"] === "json", logLevel === "debug" ? true : options.debug);
|
51377
51378
|
console.debug("Starting with", options.target);
|
51378
51379
|
Error.stackTraceLimit = 20;
|
51379
51380
|
var fullPath = path4.resolve(options["chains-config"]);
|
package/package.json
CHANGED
package/src/db-context.ts
CHANGED
@@ -8,45 +8,22 @@ import {
|
|
8
8
|
ProcessStreamResponse
|
9
9
|
} from '@sentio/protos'
|
10
10
|
import * as process from 'node:process'
|
11
|
-
import {
|
12
|
-
|
11
|
+
import { dbMetrics } from './metrics.js'
|
12
|
+
const {
|
13
|
+
request_errors,
|
14
|
+
unsolved_requests,
|
15
|
+
request_times,
|
16
|
+
batched_request_count,
|
17
|
+
batched_total_count,
|
18
|
+
send_counts,
|
19
|
+
recv_counts
|
20
|
+
} = dbMetrics
|
13
21
|
const STORE_BATCH_IDLE = process.env['STORE_BATCH_MAX_IDLE'] ? parseInt(process.env['STORE_BATCH_MAX_IDLE']) : 1
|
14
22
|
const STORE_BATCH_SIZE = process.env['STORE_BATCH_SIZE'] ? parseInt(process.env['STORE_BATCH_SIZE']) : 10
|
15
23
|
|
16
24
|
type Request = Omit<DBRequest, 'opId'>
|
17
25
|
type RequestType = keyof Request
|
18
26
|
|
19
|
-
const meter = metrics.getMeter('processor_store')
|
20
|
-
const send_counts: Record<RequestType, Counter<Attributes>> = {
|
21
|
-
get: meter.createCounter('store_get_count'),
|
22
|
-
upsert: meter.createCounter('store_upsert_count'),
|
23
|
-
list: meter.createCounter('store_list_count'),
|
24
|
-
delete: meter.createCounter('store_delete_count')
|
25
|
-
}
|
26
|
-
const recv_counts: Record<RequestType, Counter<Attributes>> = {
|
27
|
-
get: meter.createCounter('store_get_count'),
|
28
|
-
upsert: meter.createCounter('store_upsert_count'),
|
29
|
-
list: meter.createCounter('store_list_count'),
|
30
|
-
delete: meter.createCounter('store_delete_count')
|
31
|
-
}
|
32
|
-
const request_times: Record<RequestType, Counter<Attributes>> = {
|
33
|
-
get: meter.createCounter('store_get_time'),
|
34
|
-
upsert: meter.createCounter('store_upsert_time'),
|
35
|
-
list: meter.createCounter('store_list_time'),
|
36
|
-
delete: meter.createCounter('store_delete_time')
|
37
|
-
}
|
38
|
-
const request_errors: Record<RequestType, Counter<Attributes>> = {
|
39
|
-
get: meter.createCounter('store_get_error'),
|
40
|
-
upsert: meter.createCounter('store_upsert_error'),
|
41
|
-
list: meter.createCounter('store_list_error'),
|
42
|
-
delete: meter.createCounter('store_delete_error')
|
43
|
-
}
|
44
|
-
|
45
|
-
const batched_total_count = meter.createCounter('batched_total_count')
|
46
|
-
const batched_request_count = meter.createCounter('batched_request_count')
|
47
|
-
|
48
|
-
const unsolved_requests = meter.createGauge('store_unsolved_requests')
|
49
|
-
|
50
27
|
export const timeoutError = Symbol()
|
51
28
|
|
52
29
|
export class StoreContext {
|
@@ -82,7 +59,7 @@ export class StoreContext {
|
|
82
59
|
|
83
60
|
const start = Date.now()
|
84
61
|
const promises = [promise]
|
85
|
-
console.debug('sending db request ', opId, request)
|
62
|
+
// console.debug('sending db request ', opId, request)
|
86
63
|
let timer: NodeJS.Timeout | undefined
|
87
64
|
if (timeoutSecs) {
|
88
65
|
const timeoutPromise = new Promise((_r, rej) => (timer = setTimeout(rej, timeoutSecs * 1000, timeoutError)))
|
@@ -101,7 +78,9 @@ export class StoreContext {
|
|
101
78
|
|
102
79
|
return Promise.race(promises)
|
103
80
|
.then((result: DBResponse) => {
|
104
|
-
|
81
|
+
if (timeoutSecs) {
|
82
|
+
console.debug('db request', requestType, 'op', opId, ' took', Date.now() - start, 'ms')
|
83
|
+
}
|
105
84
|
request_times[requestType]?.add(Date.now() - start)
|
106
85
|
return result
|
107
86
|
})
|
@@ -122,7 +101,7 @@ export class StoreContext {
|
|
122
101
|
result(dbResult: DBResponse) {
|
123
102
|
const opId = dbResult.opId
|
124
103
|
const defer = this.defers.get(opId)
|
125
|
-
console.debug('received db result ', opId, dbResult)
|
104
|
+
// console.debug('received db result ', opId, dbResult)
|
126
105
|
if (defer) {
|
127
106
|
if (defer.requestType) {
|
128
107
|
recv_counts[defer.requestType]?.add(1)
|
package/src/metrics.ts
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
import { Attributes, Counter, metrics, Gauge } from '@opentelemetry/api'
|
2
|
+
|
3
|
+
const meter = metrics.getMeter('processor')
|
4
|
+
|
5
|
+
class C {
|
6
|
+
private counter: Counter<Attributes>
|
7
|
+
private value: number = 0
|
8
|
+
|
9
|
+
constructor(name: string) {
|
10
|
+
this.counter = meter.createCounter(name)
|
11
|
+
}
|
12
|
+
|
13
|
+
add(value: number, attributes?: Attributes) {
|
14
|
+
this.counter.add(value, attributes)
|
15
|
+
this.value += value
|
16
|
+
}
|
17
|
+
|
18
|
+
get() {
|
19
|
+
return this.value
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
class G {
|
24
|
+
private gauge: Gauge<Attributes>
|
25
|
+
private value: number = 0
|
26
|
+
|
27
|
+
constructor(name: string) {
|
28
|
+
this.gauge = meter.createGauge(name)
|
29
|
+
}
|
30
|
+
|
31
|
+
record(value: number, attributes?: Attributes) {
|
32
|
+
this.gauge.record(value, attributes)
|
33
|
+
this.value = value
|
34
|
+
}
|
35
|
+
|
36
|
+
get() {
|
37
|
+
return this.value
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
export const dbMetrics = {
|
42
|
+
send_counts: {
|
43
|
+
get: new C('store_get_count'),
|
44
|
+
upsert: new C('store_upsert_count'),
|
45
|
+
list: new C('store_list_count'),
|
46
|
+
delete: new C('store_delete_count')
|
47
|
+
},
|
48
|
+
recv_counts: {
|
49
|
+
get: new C('store_get_count'),
|
50
|
+
upsert: new C('store_upsert_count'),
|
51
|
+
list: new C('store_list_count'),
|
52
|
+
delete: new C('store_delete_count')
|
53
|
+
},
|
54
|
+
request_times: {
|
55
|
+
get: new C('store_get_time'),
|
56
|
+
upsert: new C('store_upsert_time'),
|
57
|
+
list: new C('store_list_time'),
|
58
|
+
delete: new C('store_delete_time')
|
59
|
+
},
|
60
|
+
request_errors: {
|
61
|
+
get: new C('store_get_error'),
|
62
|
+
upsert: new C('store_upsert_error'),
|
63
|
+
list: new C('store_list_error'),
|
64
|
+
delete: new C('store_delete_error')
|
65
|
+
},
|
66
|
+
batched_total_count: new C('batched_total_count'),
|
67
|
+
batched_request_count: new C('batched_request_count'),
|
68
|
+
unsolved_requests: new G('store_unsolved_requests'),
|
69
|
+
|
70
|
+
stats() {
|
71
|
+
return {
|
72
|
+
send_counts: {
|
73
|
+
get: this.send_counts.get.get(),
|
74
|
+
upsert: this.send_counts.upsert.get(),
|
75
|
+
list: this.send_counts.list.get(),
|
76
|
+
delete: this.send_counts.delete.get()
|
77
|
+
},
|
78
|
+
recv_counts: {
|
79
|
+
get: this.recv_counts.get.get(),
|
80
|
+
upsert: this.recv_counts.upsert.get(),
|
81
|
+
list: this.recv_counts.list.get(),
|
82
|
+
delete: this.recv_counts.delete.get()
|
83
|
+
},
|
84
|
+
request_times: {
|
85
|
+
get: this.request_times.get.get(),
|
86
|
+
upsert: this.request_times.upsert.get(),
|
87
|
+
list: this.request_times.list.get(),
|
88
|
+
delete: this.request_times.delete.get()
|
89
|
+
},
|
90
|
+
request_errors: {
|
91
|
+
get: this.request_errors.get.get(),
|
92
|
+
upsert: this.request_errors.upsert.get(),
|
93
|
+
list: this.request_errors.list.get(),
|
94
|
+
delete: this.request_errors.delete.get()
|
95
|
+
},
|
96
|
+
batched_total_count: this.batched_total_count.get(),
|
97
|
+
batched_request_count: this.batched_request_count.get(),
|
98
|
+
unsolved_requests: this.unsolved_requests.get(),
|
99
|
+
average_request_time: {
|
100
|
+
get: this.request_times.get.get() / this.send_counts.get.get(),
|
101
|
+
upsert: this.request_times.upsert.get() / this.send_counts.upsert.get(),
|
102
|
+
list: this.request_times.list.get() / this.send_counts.list.get()
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
export const providerMetrics = {
|
109
|
+
hit_count: new C('provider_hit_count'),
|
110
|
+
miss_count: new C('provider_miss_count'),
|
111
|
+
queue_size: new G('provider_queue_size'),
|
112
|
+
total_duration: new C('provider_total_duration'),
|
113
|
+
total_queued: new C('provider_total_queued'),
|
114
|
+
stats() {
|
115
|
+
return {
|
116
|
+
hit_count: this.hit_count.get(),
|
117
|
+
miss_count: this.miss_count.get(),
|
118
|
+
queue_size: this.queue_size.get(),
|
119
|
+
total_duration: this.total_duration.get(),
|
120
|
+
total_queued: this.total_queued.get(),
|
121
|
+
average_queue_time: this.total_queued.get() / (this.hit_count.get() + this.miss_count.get()),
|
122
|
+
average_duration: this.total_duration.get() / (this.hit_count.get() + this.miss_count.get())
|
123
|
+
}
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
export const processMetrics = {
|
128
|
+
process_binding_count: new C('process_binding_count'),
|
129
|
+
process_binding_time: new C('process_binding_time'),
|
130
|
+
process_binding_error: new C('process_binding_error'),
|
131
|
+
stats() {
|
132
|
+
return {
|
133
|
+
process_binding_count: this.process_binding_count.get(),
|
134
|
+
process_binding_time: this.process_binding_time.get(),
|
135
|
+
process_binding_error: this.process_binding_error.get()
|
136
|
+
}
|
137
|
+
}
|
138
|
+
}
|
package/src/processor-runner.ts
CHANGED
@@ -58,7 +58,9 @@ const optionDefinitions = [
|
|
58
58
|
|
59
59
|
const options = commandLineArgs(optionDefinitions, { partial: true })
|
60
60
|
|
61
|
-
|
61
|
+
const logLevel = process.env['LOG_LEVEL']?.toUpperCase()
|
62
|
+
|
63
|
+
setupLogger(options['log-format'] === 'json', logLevel === 'debug' ? true : options.debug)
|
62
64
|
console.debug('Starting with', options.target)
|
63
65
|
|
64
66
|
Error.stackTraceLimit = 20
|
package/src/provider.ts
CHANGED
@@ -4,17 +4,10 @@ import PQueue from 'p-queue'
|
|
4
4
|
import { Endpoints } from './endpoints.js'
|
5
5
|
import { EthChainId } from '@sentio/chain'
|
6
6
|
import { LRUCache } from 'lru-cache'
|
7
|
-
import {
|
8
|
-
|
7
|
+
import { providerMetrics } from './metrics.js'
|
8
|
+
const { miss_count, hit_count, total_duration, total_queued, queue_size } = providerMetrics
|
9
9
|
export const DummyProvider = new JsonRpcProvider('', Network.from(1))
|
10
10
|
|
11
|
-
const meter = metrics.getMeter('processor_provider')
|
12
|
-
const hit_count = meter.createCounter('provider_hit_count')
|
13
|
-
const miss_count = meter.createCounter('provider_miss_count')
|
14
|
-
const queue_size = meter.createGauge('provider_queue_size')
|
15
|
-
const total_duration = meter.createCounter('provider_total_duration')
|
16
|
-
const total_queued = meter.createCounter('provider_total_queued')
|
17
|
-
|
18
11
|
const providers = new Map<string, JsonRpcProvider>()
|
19
12
|
|
20
13
|
// export function getEthChainId(networkish?: EthContext | EthChainId): EthChainId {
|
package/src/service.ts
CHANGED
@@ -30,15 +30,11 @@ import { freezeGlobalConfig, GLOBAL_CONFIG } from './global-config.js'
|
|
30
30
|
|
31
31
|
import { StoreContext } from './db-context.js'
|
32
32
|
import { Subject } from 'rxjs'
|
33
|
-
import { metrics } from '@opentelemetry/api'
|
34
33
|
import { getProvider } from './provider.js'
|
35
34
|
import { EthChainId } from '@sentio/chain'
|
36
35
|
import { Provider } from 'ethers'
|
37
|
-
|
38
|
-
const
|
39
|
-
const process_binding_count = meter.createCounter('process_binding_count')
|
40
|
-
const process_binding_time = meter.createCounter('process_binding_time')
|
41
|
-
const process_binding_error = meter.createCounter('process_binding_error')
|
36
|
+
import { processMetrics, providerMetrics, dbMetrics } from './metrics.js'
|
37
|
+
const { process_binding_count, process_binding_time, process_binding_error } = processMetrics
|
42
38
|
|
43
39
|
;(BigInt.prototype as any).toJSON = function () {
|
44
40
|
return this.toString()
|
@@ -383,6 +379,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
383
379
|
console.debug('processBinding', request.processId, ' took', cost, 'ms')
|
384
380
|
process_binding_time.add(cost)
|
385
381
|
contexts.delete(request.processId)
|
382
|
+
console.debug('db stats', JSON.stringify(dbMetrics.stats()))
|
383
|
+
console.debug('provider stats', JSON.stringify(providerMetrics.stats()))
|
386
384
|
})
|
387
385
|
}
|
388
386
|
if (request.dbResult) {
|