@typeberry/lib 0.4.1-bb6dbac → 0.4.1-d3b18b3
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/index.cjs +980 -104
- package/index.d.ts +37 -4
- package/index.js +980 -104
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -98,6 +98,15 @@ class Compatibility {
|
|
|
98
98
|
function isBrowser() {
|
|
99
99
|
return typeof process === "undefined" || typeof process.abort === "undefined";
|
|
100
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Get current time in milliseconds (works in both Node and browser).
|
|
103
|
+
*
|
|
104
|
+
* Node.js implementation converts hrtime bigint nanoseconds to milliseconds.
|
|
105
|
+
* This is safe because dividing nanoseconds by 1_000_000 yields milliseconds,
|
|
106
|
+
* which remain well below Number.MAX_SAFE_INTEGER for practical runtimes
|
|
107
|
+
* (would take ~285 years to overflow).
|
|
108
|
+
*/
|
|
109
|
+
const now = isBrowser() ? () => performance.now() : () => Number(process.hrtime.bigint() / 1000000n);
|
|
101
110
|
/**
|
|
102
111
|
* A function to perform runtime assertions.
|
|
103
112
|
*
|
|
@@ -186,19 +195,10 @@ function inspect(val) {
|
|
|
186
195
|
return v;
|
|
187
196
|
}
|
|
188
197
|
/** Utility function to measure time taken for some operation [ms]. */
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
: (id) => {
|
|
195
|
-
const start = process.hrtime.bigint();
|
|
196
|
-
return () => {
|
|
197
|
-
const tookNano = process.hrtime.bigint() - start;
|
|
198
|
-
const tookMilli = Number(tookNano / 1000000n).toFixed(2);
|
|
199
|
-
return `${id} took ${tookMilli}ms`;
|
|
200
|
-
};
|
|
201
|
-
};
|
|
198
|
+
function measure(id) {
|
|
199
|
+
const start = now();
|
|
200
|
+
return () => `${id} took ${(now() - start).toFixed(2)}ms`;
|
|
201
|
+
}
|
|
202
202
|
/** A class that adds `toString` method that prints all properties of an object. */
|
|
203
203
|
class WithDebug {
|
|
204
204
|
toString() {
|
|
@@ -603,10 +603,12 @@ var index$y = /*#__PURE__*/Object.freeze({
|
|
|
603
603
|
assertNever: assertNever,
|
|
604
604
|
check: check,
|
|
605
605
|
deepEqual: deepEqual,
|
|
606
|
+
env: env,
|
|
606
607
|
inspect: inspect,
|
|
607
608
|
isBrowser: isBrowser,
|
|
608
609
|
lazyInspect: lazyInspect,
|
|
609
610
|
measure: measure,
|
|
611
|
+
now: now,
|
|
610
612
|
resultToString: resultToString,
|
|
611
613
|
safeAllocUint8Array: safeAllocUint8Array,
|
|
612
614
|
seeThrough: seeThrough,
|
|
@@ -3845,7 +3847,7 @@ class Mutex {
|
|
|
3845
3847
|
}
|
|
3846
3848
|
|
|
3847
3849
|
var _a;
|
|
3848
|
-
function getGlobal() {
|
|
3850
|
+
function getGlobal$1() {
|
|
3849
3851
|
if (typeof globalThis !== "undefined")
|
|
3850
3852
|
return globalThis;
|
|
3851
3853
|
if (typeof self !== "undefined")
|
|
@@ -3854,7 +3856,7 @@ function getGlobal() {
|
|
|
3854
3856
|
return window;
|
|
3855
3857
|
return global;
|
|
3856
3858
|
}
|
|
3857
|
-
const globalObject = getGlobal();
|
|
3859
|
+
const globalObject = getGlobal$1();
|
|
3858
3860
|
const nodeBuffer = (_a = globalObject.Buffer) !== null && _a !== void 0 ? _a : null;
|
|
3859
3861
|
const textEncoder = globalObject.TextEncoder
|
|
3860
3862
|
? new globalObject.TextEncoder()
|
|
@@ -7791,7 +7793,7 @@ class JipChainSpec extends WithDebug {
|
|
|
7791
7793
|
}
|
|
7792
7794
|
|
|
7793
7795
|
var $schema$1 = "https://fluffylabs.dev/typeberry/schemas/config-v1.schema.json";
|
|
7794
|
-
var version$
|
|
7796
|
+
var version$2 = 1;
|
|
7795
7797
|
var flavor$1 = "tiny";
|
|
7796
7798
|
var authorship$1 = {
|
|
7797
7799
|
omit_seal_verification: false
|
|
@@ -7830,7 +7832,7 @@ var chain_spec$1 = {
|
|
|
7830
7832
|
var database_base_path$1 = "./database";
|
|
7831
7833
|
var defaultConfig = {
|
|
7832
7834
|
$schema: $schema$1,
|
|
7833
|
-
version: version$
|
|
7835
|
+
version: version$2,
|
|
7834
7836
|
flavor: flavor$1,
|
|
7835
7837
|
authorship: authorship$1,
|
|
7836
7838
|
chain_spec: chain_spec$1,
|
|
@@ -7838,7 +7840,7 @@ var defaultConfig = {
|
|
|
7838
7840
|
};
|
|
7839
7841
|
|
|
7840
7842
|
var $schema = "https://fluffylabs.dev/typeberry/schemas/config-v1.schema.json";
|
|
7841
|
-
var version = 1;
|
|
7843
|
+
var version$1 = 1;
|
|
7842
7844
|
var flavor = "tiny";
|
|
7843
7845
|
var authorship = {
|
|
7844
7846
|
omit_seal_verification: true
|
|
@@ -7876,7 +7878,7 @@ var chain_spec = {
|
|
|
7876
7878
|
var database_base_path = "./database";
|
|
7877
7879
|
var devConfig = {
|
|
7878
7880
|
$schema: $schema,
|
|
7879
|
-
version: version,
|
|
7881
|
+
version: version$1,
|
|
7880
7882
|
flavor: flavor,
|
|
7881
7883
|
authorship: authorship,
|
|
7882
7884
|
chain_spec: chain_spec,
|
|
@@ -18114,7 +18116,7 @@ function emptyRegistersBuffer() {
|
|
|
18114
18116
|
return safeAllocUint8Array(NO_OF_REGISTERS$1 * REGISTER_BYTE_SIZE);
|
|
18115
18117
|
}
|
|
18116
18118
|
|
|
18117
|
-
const IN_OUT_REG$
|
|
18119
|
+
const IN_OUT_REG$g = 7;
|
|
18118
18120
|
const OFFSET_REG = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isGreaterOrEqual(GpVersion.V0_7_2) ? 9 : 11;
|
|
18119
18121
|
const LEN_REG = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isGreaterOrEqual(GpVersion.V0_7_2) ? 10 : 12;
|
|
18120
18122
|
/**
|
|
@@ -18140,14 +18142,14 @@ class Info {
|
|
|
18140
18142
|
account;
|
|
18141
18143
|
index = tryAsHostCallIndex(5);
|
|
18142
18144
|
basicGasCost = tryAsSmallGas(10);
|
|
18143
|
-
tracedRegisters = traceRegisters(IN_OUT_REG$
|
|
18145
|
+
tracedRegisters = traceRegisters(IN_OUT_REG$g, 8, OFFSET_REG, LEN_REG);
|
|
18144
18146
|
constructor(currentServiceId, account) {
|
|
18145
18147
|
this.currentServiceId = currentServiceId;
|
|
18146
18148
|
this.account = account;
|
|
18147
18149
|
}
|
|
18148
18150
|
async execute(_gas, regs, memory) {
|
|
18149
18151
|
// t
|
|
18150
|
-
const serviceId = getServiceIdOrCurrent(IN_OUT_REG$
|
|
18152
|
+
const serviceId = getServiceIdOrCurrent(IN_OUT_REG$g, regs, this.currentServiceId);
|
|
18151
18153
|
// o
|
|
18152
18154
|
const outputStart = regs.get(8);
|
|
18153
18155
|
// v
|
|
@@ -18173,10 +18175,10 @@ class Info {
|
|
|
18173
18175
|
}
|
|
18174
18176
|
logger$7.trace `[${this.currentServiceId}] INFO(${serviceId}, off: ${offset}, len: ${length}) <- ${BytesBlob.blobFrom(chunk)}`;
|
|
18175
18177
|
if (accountInfo === null) {
|
|
18176
|
-
regs.set(IN_OUT_REG$
|
|
18178
|
+
regs.set(IN_OUT_REG$g, HostCallResult.NONE);
|
|
18177
18179
|
return;
|
|
18178
18180
|
}
|
|
18179
|
-
regs.set(IN_OUT_REG$
|
|
18181
|
+
regs.set(IN_OUT_REG$g, valueLength);
|
|
18180
18182
|
}
|
|
18181
18183
|
}
|
|
18182
18184
|
/**
|
|
@@ -19720,7 +19722,7 @@ function finalize(mergeContext) {
|
|
|
19720
19722
|
};
|
|
19721
19723
|
}
|
|
19722
19724
|
|
|
19723
|
-
const IN_OUT_REG$
|
|
19725
|
+
const IN_OUT_REG$f = 7;
|
|
19724
19726
|
/**
|
|
19725
19727
|
* Assign new fixed-length authorization queue to some core and authorize a service for this core.
|
|
19726
19728
|
*
|
|
@@ -19732,7 +19734,7 @@ class Assign {
|
|
|
19732
19734
|
chainSpec;
|
|
19733
19735
|
index = tryAsHostCallIndex(15);
|
|
19734
19736
|
basicGasCost = tryAsSmallGas(10);
|
|
19735
|
-
tracedRegisters = traceRegisters(IN_OUT_REG$
|
|
19737
|
+
tracedRegisters = traceRegisters(IN_OUT_REG$f, 8);
|
|
19736
19738
|
constructor(currentServiceId, partialState, chainSpec) {
|
|
19737
19739
|
this.currentServiceId = currentServiceId;
|
|
19738
19740
|
this.partialState = partialState;
|
|
@@ -19740,7 +19742,7 @@ class Assign {
|
|
|
19740
19742
|
}
|
|
19741
19743
|
async execute(_gas, regs, memory) {
|
|
19742
19744
|
// c
|
|
19743
|
-
const maybeCoreIndex = regs.get(IN_OUT_REG$
|
|
19745
|
+
const maybeCoreIndex = regs.get(IN_OUT_REG$f);
|
|
19744
19746
|
// o
|
|
19745
19747
|
const authorizationQueueStart = regs.get(8);
|
|
19746
19748
|
// a
|
|
@@ -19753,7 +19755,7 @@ class Assign {
|
|
|
19753
19755
|
return PvmExecution.Panic;
|
|
19754
19756
|
}
|
|
19755
19757
|
if (maybeCoreIndex >= this.chainSpec.coresCount) {
|
|
19756
|
-
regs.set(IN_OUT_REG$
|
|
19758
|
+
regs.set(IN_OUT_REG$f, HostCallResult.CORE);
|
|
19757
19759
|
return;
|
|
19758
19760
|
}
|
|
19759
19761
|
// NOTE: Here we know the core index is valid
|
|
@@ -19763,18 +19765,18 @@ class Assign {
|
|
|
19763
19765
|
const fixedSizeAuthQueue = FixedSizeArray.new(authQueue, AUTHORIZATION_QUEUE_SIZE);
|
|
19764
19766
|
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
|
|
19765
19767
|
if (result.isOk) {
|
|
19766
|
-
regs.set(IN_OUT_REG$
|
|
19768
|
+
regs.set(IN_OUT_REG$f, HostCallResult.OK);
|
|
19767
19769
|
logger$7.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
|
|
19768
19770
|
return;
|
|
19769
19771
|
}
|
|
19770
19772
|
const e = result.error;
|
|
19771
19773
|
if (e === UpdatePrivilegesError.UnprivilegedService) {
|
|
19772
|
-
regs.set(IN_OUT_REG$
|
|
19774
|
+
regs.set(IN_OUT_REG$f, HostCallResult.HUH);
|
|
19773
19775
|
logger$7.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
|
|
19774
19776
|
return;
|
|
19775
19777
|
}
|
|
19776
19778
|
if (e === UpdatePrivilegesError.InvalidServiceId) {
|
|
19777
|
-
regs.set(IN_OUT_REG$
|
|
19779
|
+
regs.set(IN_OUT_REG$f, HostCallResult.WHO);
|
|
19778
19780
|
logger$7.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
|
|
19779
19781
|
return;
|
|
19780
19782
|
}
|
|
@@ -19782,7 +19784,7 @@ class Assign {
|
|
|
19782
19784
|
}
|
|
19783
19785
|
}
|
|
19784
19786
|
|
|
19785
|
-
const IN_OUT_REG$
|
|
19787
|
+
const IN_OUT_REG$e = 7;
|
|
19786
19788
|
const serviceIdAndGasCodec = object({
|
|
19787
19789
|
serviceId: u32.convert((i) => i, (o) => asOpaqueType(o)),
|
|
19788
19790
|
gas: u64.convert((i) => tryAsU64(i), (o) => tryAsServiceGas(o)),
|
|
@@ -19799,8 +19801,8 @@ class Bless {
|
|
|
19799
19801
|
index = tryAsHostCallIndex(14);
|
|
19800
19802
|
basicGasCost = tryAsSmallGas(10);
|
|
19801
19803
|
tracedRegisters = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
19802
|
-
? traceRegisters(IN_OUT_REG$
|
|
19803
|
-
: traceRegisters(IN_OUT_REG$
|
|
19804
|
+
? traceRegisters(IN_OUT_REG$e, 8, 9, 10, 11, 12)
|
|
19805
|
+
: traceRegisters(IN_OUT_REG$e, 8, 9, 10, 11);
|
|
19804
19806
|
constructor(currentServiceId, partialState, chainSpec) {
|
|
19805
19807
|
this.currentServiceId = currentServiceId;
|
|
19806
19808
|
this.partialState = partialState;
|
|
@@ -19808,7 +19810,7 @@ class Bless {
|
|
|
19808
19810
|
}
|
|
19809
19811
|
async execute(_gas, regs, memory) {
|
|
19810
19812
|
// `m`: manager service (can change privileged services)
|
|
19811
|
-
const manager = getServiceId(regs.get(IN_OUT_REG$
|
|
19813
|
+
const manager = getServiceId(regs.get(IN_OUT_REG$e));
|
|
19812
19814
|
// `a`: manages authorization queue
|
|
19813
19815
|
const authorization = regs.get(8);
|
|
19814
19816
|
// `v`: manages validator keys
|
|
@@ -19855,19 +19857,19 @@ class Bless {
|
|
|
19855
19857
|
const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate);
|
|
19856
19858
|
if (updateResult.isOk) {
|
|
19857
19859
|
logger$7.trace `[${this.currentServiceId}] BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- OK`;
|
|
19858
|
-
regs.set(IN_OUT_REG$
|
|
19860
|
+
regs.set(IN_OUT_REG$e, HostCallResult.OK);
|
|
19859
19861
|
return;
|
|
19860
19862
|
}
|
|
19861
19863
|
const e = updateResult.error;
|
|
19862
19864
|
// NOTE: `UpdatePrivilegesError.UnprivilegedService` won't happen in 0.7.1+
|
|
19863
19865
|
if (e === UpdatePrivilegesError.UnprivilegedService) {
|
|
19864
19866
|
logger$7.trace `[${this.currentServiceId}] BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- HUH`;
|
|
19865
|
-
regs.set(IN_OUT_REG$
|
|
19867
|
+
regs.set(IN_OUT_REG$e, HostCallResult.HUH);
|
|
19866
19868
|
return;
|
|
19867
19869
|
}
|
|
19868
19870
|
if (e === UpdatePrivilegesError.InvalidServiceId) {
|
|
19869
19871
|
logger$7.trace `[${this.currentServiceId}] BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- WHO`;
|
|
19870
|
-
regs.set(IN_OUT_REG$
|
|
19872
|
+
regs.set(IN_OUT_REG$e, HostCallResult.WHO);
|
|
19871
19873
|
return;
|
|
19872
19874
|
}
|
|
19873
19875
|
assertNever(e);
|
|
@@ -19923,7 +19925,7 @@ class Checkpoint {
|
|
|
19923
19925
|
}
|
|
19924
19926
|
}
|
|
19925
19927
|
|
|
19926
|
-
const IN_OUT_REG$
|
|
19928
|
+
const IN_OUT_REG$d = 7;
|
|
19927
19929
|
const VALIDATOR_DATA_BYTES = tryAsExactBytes(ValidatorData.Codec.sizeHint);
|
|
19928
19930
|
/**
|
|
19929
19931
|
* Designate a new set of validator keys.
|
|
@@ -19936,7 +19938,7 @@ class Designate {
|
|
|
19936
19938
|
chainSpec;
|
|
19937
19939
|
index = tryAsHostCallIndex(16);
|
|
19938
19940
|
basicGasCost = tryAsSmallGas(10);
|
|
19939
|
-
tracedRegisters = traceRegisters(IN_OUT_REG$
|
|
19941
|
+
tracedRegisters = traceRegisters(IN_OUT_REG$d);
|
|
19940
19942
|
constructor(currentServiceId, partialState, chainSpec) {
|
|
19941
19943
|
this.currentServiceId = currentServiceId;
|
|
19942
19944
|
this.partialState = partialState;
|
|
@@ -19944,7 +19946,7 @@ class Designate {
|
|
|
19944
19946
|
}
|
|
19945
19947
|
async execute(_gas, regs, memory) {
|
|
19946
19948
|
// `o`
|
|
19947
|
-
const validatorsStart = regs.get(IN_OUT_REG$
|
|
19949
|
+
const validatorsStart = regs.get(IN_OUT_REG$d);
|
|
19948
19950
|
const res = safeAllocUint8Array(VALIDATOR_DATA_BYTES * this.chainSpec.validatorsCount);
|
|
19949
19951
|
const memoryReadResult = memory.loadInto(res, validatorsStart);
|
|
19950
19952
|
// error while reading the memory.
|
|
@@ -19957,16 +19959,16 @@ class Designate {
|
|
|
19957
19959
|
const result = this.partialState.updateValidatorsData(tryAsPerValidator(validatorsData, this.chainSpec));
|
|
19958
19960
|
if (result.isError) {
|
|
19959
19961
|
logger$7.trace `[${this.currentServiceId}] DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- HUH`;
|
|
19960
|
-
regs.set(IN_OUT_REG$
|
|
19962
|
+
regs.set(IN_OUT_REG$d, HostCallResult.HUH);
|
|
19961
19963
|
}
|
|
19962
19964
|
else {
|
|
19963
19965
|
logger$7.trace `[${this.currentServiceId}] DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- OK`;
|
|
19964
|
-
regs.set(IN_OUT_REG$
|
|
19966
|
+
regs.set(IN_OUT_REG$d, HostCallResult.OK);
|
|
19965
19967
|
}
|
|
19966
19968
|
}
|
|
19967
19969
|
}
|
|
19968
19970
|
|
|
19969
|
-
const IN_OUT_REG$
|
|
19971
|
+
const IN_OUT_REG$c = 7;
|
|
19970
19972
|
/**
|
|
19971
19973
|
* Remove the provided service account and transfer the remaining balance to current service account.
|
|
19972
19974
|
*
|
|
@@ -19977,14 +19979,14 @@ class Eject {
|
|
|
19977
19979
|
partialState;
|
|
19978
19980
|
index = tryAsHostCallIndex(21);
|
|
19979
19981
|
basicGasCost = tryAsSmallGas(10);
|
|
19980
|
-
tracedRegisters = traceRegisters(IN_OUT_REG$
|
|
19982
|
+
tracedRegisters = traceRegisters(IN_OUT_REG$c, 8);
|
|
19981
19983
|
constructor(currentServiceId, partialState) {
|
|
19982
19984
|
this.currentServiceId = currentServiceId;
|
|
19983
19985
|
this.partialState = partialState;
|
|
19984
19986
|
}
|
|
19985
19987
|
async execute(_gas, regs, memory) {
|
|
19986
19988
|
// `d`: account to eject from (source)
|
|
19987
|
-
const serviceId = getServiceId(regs.get(IN_OUT_REG$
|
|
19989
|
+
const serviceId = getServiceId(regs.get(IN_OUT_REG$c));
|
|
19988
19990
|
// `o`: preimage hash start memory index
|
|
19989
19991
|
const preimageHashStart = regs.get(8);
|
|
19990
19992
|
// `h`: hash
|
|
@@ -19996,7 +19998,7 @@ class Eject {
|
|
|
19996
19998
|
}
|
|
19997
19999
|
// cannot eject self
|
|
19998
20000
|
if (serviceId === this.currentServiceId) {
|
|
19999
|
-
regs.set(IN_OUT_REG$
|
|
20001
|
+
regs.set(IN_OUT_REG$c, HostCallResult.WHO);
|
|
20000
20002
|
logger$7.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- WHO`;
|
|
20001
20003
|
return;
|
|
20002
20004
|
}
|
|
@@ -20004,17 +20006,17 @@ class Eject {
|
|
|
20004
20006
|
// All good!
|
|
20005
20007
|
if (result.isOk) {
|
|
20006
20008
|
logger$7.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- OK`;
|
|
20007
|
-
regs.set(IN_OUT_REG$
|
|
20009
|
+
regs.set(IN_OUT_REG$c, HostCallResult.OK);
|
|
20008
20010
|
return;
|
|
20009
20011
|
}
|
|
20010
20012
|
const e = result.error;
|
|
20011
20013
|
if (e === EjectError.InvalidService) {
|
|
20012
20014
|
logger$7.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- WHO ${resultToString(result)}`;
|
|
20013
|
-
regs.set(IN_OUT_REG$
|
|
20015
|
+
regs.set(IN_OUT_REG$c, HostCallResult.WHO);
|
|
20014
20016
|
}
|
|
20015
20017
|
else if (e === EjectError.InvalidPreimage) {
|
|
20016
20018
|
logger$7.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- HUH ${resultToString(result)}`;
|
|
20017
|
-
regs.set(IN_OUT_REG$
|
|
20019
|
+
regs.set(IN_OUT_REG$c, HostCallResult.HUH);
|
|
20018
20020
|
}
|
|
20019
20021
|
else {
|
|
20020
20022
|
assertNever(e);
|
|
@@ -20022,7 +20024,7 @@ class Eject {
|
|
|
20022
20024
|
}
|
|
20023
20025
|
}
|
|
20024
20026
|
|
|
20025
|
-
const IN_OUT_REG$
|
|
20027
|
+
const IN_OUT_REG$b = 7;
|
|
20026
20028
|
/**
|
|
20027
20029
|
* Delete preimage hash or mark as unavailable if it was available.
|
|
20028
20030
|
*
|
|
@@ -20033,14 +20035,14 @@ class Forget {
|
|
|
20033
20035
|
partialState;
|
|
20034
20036
|
index = tryAsHostCallIndex(24);
|
|
20035
20037
|
basicGasCost = tryAsSmallGas(10);
|
|
20036
|
-
tracedRegisters = traceRegisters(IN_OUT_REG$
|
|
20038
|
+
tracedRegisters = traceRegisters(IN_OUT_REG$b, 8);
|
|
20037
20039
|
constructor(currentServiceId, partialState) {
|
|
20038
20040
|
this.currentServiceId = currentServiceId;
|
|
20039
20041
|
this.partialState = partialState;
|
|
20040
20042
|
}
|
|
20041
20043
|
async execute(_gas, regs, memory) {
|
|
20042
20044
|
// `o`
|
|
20043
|
-
const hashStart = regs.get(IN_OUT_REG$
|
|
20045
|
+
const hashStart = regs.get(IN_OUT_REG$b);
|
|
20044
20046
|
// `z`
|
|
20045
20047
|
const length = regs.get(8);
|
|
20046
20048
|
const hash = Bytes.zero(HASH_SIZE);
|
|
@@ -20053,15 +20055,15 @@ class Forget {
|
|
|
20053
20055
|
const result = this.partialState.forgetPreimage(hash.asOpaque(), length);
|
|
20054
20056
|
logger$7.trace `[${this.currentServiceId}] FORGET(${hash}, ${length}) <- ${resultToString(result)}`;
|
|
20055
20057
|
if (result.isOk) {
|
|
20056
|
-
regs.set(IN_OUT_REG$
|
|
20058
|
+
regs.set(IN_OUT_REG$b, HostCallResult.OK);
|
|
20057
20059
|
}
|
|
20058
20060
|
else {
|
|
20059
|
-
regs.set(IN_OUT_REG$
|
|
20061
|
+
regs.set(IN_OUT_REG$b, HostCallResult.HUH);
|
|
20060
20062
|
}
|
|
20061
20063
|
}
|
|
20062
20064
|
}
|
|
20063
20065
|
|
|
20064
|
-
const IN_OUT_REG$
|
|
20066
|
+
const IN_OUT_REG$a = 7;
|
|
20065
20067
|
/**
|
|
20066
20068
|
* Create a new service account.
|
|
20067
20069
|
*
|
|
@@ -20073,15 +20075,15 @@ class New {
|
|
|
20073
20075
|
index = tryAsHostCallIndex(18);
|
|
20074
20076
|
basicGasCost = tryAsSmallGas(10);
|
|
20075
20077
|
tracedRegisters = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
20076
|
-
? traceRegisters(IN_OUT_REG$
|
|
20077
|
-
: traceRegisters(IN_OUT_REG$
|
|
20078
|
+
? traceRegisters(IN_OUT_REG$a, 8, 9, 10, 11, 12)
|
|
20079
|
+
: traceRegisters(IN_OUT_REG$a, 8, 9, 10, 11);
|
|
20078
20080
|
constructor(currentServiceId, partialState) {
|
|
20079
20081
|
this.currentServiceId = currentServiceId;
|
|
20080
20082
|
this.partialState = partialState;
|
|
20081
20083
|
}
|
|
20082
20084
|
async execute(_gas, regs, memory) {
|
|
20083
20085
|
// `o`
|
|
20084
|
-
const codeHashStart = regs.get(IN_OUT_REG$
|
|
20086
|
+
const codeHashStart = regs.get(IN_OUT_REG$a);
|
|
20085
20087
|
// `l`
|
|
20086
20088
|
const codeLength = regs.get(8);
|
|
20087
20089
|
// `g`
|
|
@@ -20103,28 +20105,28 @@ class New {
|
|
|
20103
20105
|
const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage, requestedServiceId);
|
|
20104
20106
|
logger$7.trace `[${this.currentServiceId}] NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${resultToString(assignedId)}`;
|
|
20105
20107
|
if (assignedId.isOk) {
|
|
20106
|
-
regs.set(IN_OUT_REG$
|
|
20108
|
+
regs.set(IN_OUT_REG$a, tryAsU64(assignedId.ok));
|
|
20107
20109
|
return;
|
|
20108
20110
|
}
|
|
20109
20111
|
const e = assignedId.error;
|
|
20110
20112
|
if (e === NewServiceError.InsufficientFunds) {
|
|
20111
|
-
regs.set(IN_OUT_REG$
|
|
20113
|
+
regs.set(IN_OUT_REG$a, HostCallResult.CASH);
|
|
20112
20114
|
return;
|
|
20113
20115
|
}
|
|
20114
20116
|
if (e === NewServiceError.UnprivilegedService) {
|
|
20115
|
-
regs.set(IN_OUT_REG$
|
|
20117
|
+
regs.set(IN_OUT_REG$a, HostCallResult.HUH);
|
|
20116
20118
|
return;
|
|
20117
20119
|
}
|
|
20118
20120
|
// Post 0.7.1
|
|
20119
20121
|
if (e === NewServiceError.RegistrarServiceIdAlreadyTaken) {
|
|
20120
|
-
regs.set(IN_OUT_REG$
|
|
20122
|
+
regs.set(IN_OUT_REG$a, HostCallResult.FULL);
|
|
20121
20123
|
return;
|
|
20122
20124
|
}
|
|
20123
20125
|
assertNever(e);
|
|
20124
20126
|
}
|
|
20125
20127
|
}
|
|
20126
20128
|
|
|
20127
|
-
const IN_OUT_REG$
|
|
20129
|
+
const IN_OUT_REG$9 = 7;
|
|
20128
20130
|
/**
|
|
20129
20131
|
* Provide a preimage for a given service.
|
|
20130
20132
|
*
|
|
@@ -20135,14 +20137,14 @@ class Provide {
|
|
|
20135
20137
|
partialState;
|
|
20136
20138
|
index = tryAsHostCallIndex(26);
|
|
20137
20139
|
basicGasCost = tryAsSmallGas(10);
|
|
20138
|
-
tracedRegisters = traceRegisters(IN_OUT_REG$
|
|
20140
|
+
tracedRegisters = traceRegisters(IN_OUT_REG$9, 8, 9);
|
|
20139
20141
|
constructor(currentServiceId, partialState) {
|
|
20140
20142
|
this.currentServiceId = currentServiceId;
|
|
20141
20143
|
this.partialState = partialState;
|
|
20142
20144
|
}
|
|
20143
20145
|
async execute(_gas, regs, memory) {
|
|
20144
20146
|
// `s`
|
|
20145
|
-
const serviceId = getServiceIdOrCurrent(IN_OUT_REG$
|
|
20147
|
+
const serviceId = getServiceIdOrCurrent(IN_OUT_REG$9, regs, this.currentServiceId);
|
|
20146
20148
|
// `o`
|
|
20147
20149
|
const preimageStart = regs.get(8);
|
|
20148
20150
|
// `z`
|
|
@@ -20158,16 +20160,16 @@ class Provide {
|
|
|
20158
20160
|
const result = this.partialState.providePreimage(serviceId, preimage);
|
|
20159
20161
|
logger$7.trace `[${this.currentServiceId}] PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- ${resultToString(result)}`;
|
|
20160
20162
|
if (result.isOk) {
|
|
20161
|
-
regs.set(IN_OUT_REG$
|
|
20163
|
+
regs.set(IN_OUT_REG$9, HostCallResult.OK);
|
|
20162
20164
|
return;
|
|
20163
20165
|
}
|
|
20164
20166
|
const e = result.error;
|
|
20165
20167
|
if (e === ProvidePreimageError.ServiceNotFound) {
|
|
20166
|
-
regs.set(IN_OUT_REG$
|
|
20168
|
+
regs.set(IN_OUT_REG$9, HostCallResult.WHO);
|
|
20167
20169
|
return;
|
|
20168
20170
|
}
|
|
20169
20171
|
if (e === ProvidePreimageError.WasNotRequested || e === ProvidePreimageError.AlreadyProvided) {
|
|
20170
|
-
regs.set(IN_OUT_REG$
|
|
20172
|
+
regs.set(IN_OUT_REG$9, HostCallResult.HUH);
|
|
20171
20173
|
return;
|
|
20172
20174
|
}
|
|
20173
20175
|
assertNever(e);
|
|
@@ -20239,7 +20241,7 @@ class Query {
|
|
|
20239
20241
|
}
|
|
20240
20242
|
}
|
|
20241
20243
|
|
|
20242
|
-
const IN_OUT_REG$
|
|
20244
|
+
const IN_OUT_REG$8 = 7;
|
|
20243
20245
|
/**
|
|
20244
20246
|
* Request a preimage to be available.
|
|
20245
20247
|
*
|
|
@@ -20250,14 +20252,14 @@ class Solicit {
|
|
|
20250
20252
|
partialState;
|
|
20251
20253
|
index = tryAsHostCallIndex(23);
|
|
20252
20254
|
basicGasCost = tryAsSmallGas(10);
|
|
20253
|
-
tracedRegisters = traceRegisters(IN_OUT_REG$
|
|
20255
|
+
tracedRegisters = traceRegisters(IN_OUT_REG$8, 8);
|
|
20254
20256
|
constructor(currentServiceId, partialState) {
|
|
20255
20257
|
this.currentServiceId = currentServiceId;
|
|
20256
20258
|
this.partialState = partialState;
|
|
20257
20259
|
}
|
|
20258
20260
|
async execute(_gas, regs, memory) {
|
|
20259
20261
|
// `o`
|
|
20260
|
-
const hashStart = regs.get(IN_OUT_REG$
|
|
20262
|
+
const hashStart = regs.get(IN_OUT_REG$8);
|
|
20261
20263
|
// `z`
|
|
20262
20264
|
const length = regs.get(8);
|
|
20263
20265
|
const hash = Bytes.zero(HASH_SIZE);
|
|
@@ -20269,23 +20271,23 @@ class Solicit {
|
|
|
20269
20271
|
const result = this.partialState.requestPreimage(hash.asOpaque(), length);
|
|
20270
20272
|
logger$7.trace `[${this.currentServiceId}] SOLICIT(${hash}, ${length}) <- ${resultToString(result)}`;
|
|
20271
20273
|
if (result.isOk) {
|
|
20272
|
-
regs.set(IN_OUT_REG$
|
|
20274
|
+
regs.set(IN_OUT_REG$8, HostCallResult.OK);
|
|
20273
20275
|
return;
|
|
20274
20276
|
}
|
|
20275
20277
|
const e = result.error;
|
|
20276
20278
|
if (e === RequestPreimageError.AlreadyAvailable || e === RequestPreimageError.AlreadyRequested) {
|
|
20277
|
-
regs.set(IN_OUT_REG$
|
|
20279
|
+
regs.set(IN_OUT_REG$8, HostCallResult.HUH);
|
|
20278
20280
|
return;
|
|
20279
20281
|
}
|
|
20280
20282
|
if (e === RequestPreimageError.InsufficientFunds) {
|
|
20281
|
-
regs.set(IN_OUT_REG$
|
|
20283
|
+
regs.set(IN_OUT_REG$8, HostCallResult.FULL);
|
|
20282
20284
|
return;
|
|
20283
20285
|
}
|
|
20284
20286
|
assertNever(e);
|
|
20285
20287
|
}
|
|
20286
20288
|
}
|
|
20287
20289
|
|
|
20288
|
-
const IN_OUT_REG$
|
|
20290
|
+
const IN_OUT_REG$7 = 7; // `d`
|
|
20289
20291
|
const AMOUNT_REG = 8; // `a`
|
|
20290
20292
|
const TRANSFER_GAS_FEE_REG = 9; // `l`
|
|
20291
20293
|
const MEMO_START_REG = 10; // `o`
|
|
@@ -20316,14 +20318,14 @@ class Transfer {
|
|
|
20316
20318
|
basicGasCost = Compatibility.isGreaterOrEqual(GpVersion.V0_7_2)
|
|
20317
20319
|
? tryAsSmallGas(10)
|
|
20318
20320
|
: (regs) => tryAsGas(10n + regs.get(TRANSFER_GAS_FEE_REG));
|
|
20319
|
-
tracedRegisters = traceRegisters(IN_OUT_REG$
|
|
20321
|
+
tracedRegisters = traceRegisters(IN_OUT_REG$7, AMOUNT_REG, TRANSFER_GAS_FEE_REG, MEMO_START_REG);
|
|
20320
20322
|
constructor(currentServiceId, partialState) {
|
|
20321
20323
|
this.currentServiceId = currentServiceId;
|
|
20322
20324
|
this.partialState = partialState;
|
|
20323
20325
|
}
|
|
20324
20326
|
async execute(gas, regs, memory) {
|
|
20325
20327
|
// `d`: destination
|
|
20326
|
-
const destination = getServiceId(regs.get(IN_OUT_REG$
|
|
20328
|
+
const destination = getServiceId(regs.get(IN_OUT_REG$7));
|
|
20327
20329
|
// `a`: amount
|
|
20328
20330
|
const amount = regs.get(AMOUNT_REG);
|
|
20329
20331
|
// `l`: gas
|
|
@@ -20348,27 +20350,27 @@ class Transfer {
|
|
|
20348
20350
|
return PvmExecution.OOG;
|
|
20349
20351
|
}
|
|
20350
20352
|
}
|
|
20351
|
-
regs.set(IN_OUT_REG$
|
|
20353
|
+
regs.set(IN_OUT_REG$7, HostCallResult.OK);
|
|
20352
20354
|
return;
|
|
20353
20355
|
}
|
|
20354
20356
|
const e = transferResult.error;
|
|
20355
20357
|
if (e === TransferError.DestinationNotFound) {
|
|
20356
|
-
regs.set(IN_OUT_REG$
|
|
20358
|
+
regs.set(IN_OUT_REG$7, HostCallResult.WHO);
|
|
20357
20359
|
return;
|
|
20358
20360
|
}
|
|
20359
20361
|
if (e === TransferError.GasTooLow) {
|
|
20360
|
-
regs.set(IN_OUT_REG$
|
|
20362
|
+
regs.set(IN_OUT_REG$7, HostCallResult.LOW);
|
|
20361
20363
|
return;
|
|
20362
20364
|
}
|
|
20363
20365
|
if (e === TransferError.BalanceBelowThreshold) {
|
|
20364
|
-
regs.set(IN_OUT_REG$
|
|
20366
|
+
regs.set(IN_OUT_REG$7, HostCallResult.CASH);
|
|
20365
20367
|
return;
|
|
20366
20368
|
}
|
|
20367
20369
|
assertNever(e);
|
|
20368
20370
|
}
|
|
20369
20371
|
}
|
|
20370
20372
|
|
|
20371
|
-
const IN_OUT_REG$
|
|
20373
|
+
const IN_OUT_REG$6 = 7; // `o`
|
|
20372
20374
|
const GAS_REG = 8; // `g`
|
|
20373
20375
|
const ALLOWANCE_REG = 9; // `m`
|
|
20374
20376
|
/**
|
|
@@ -20381,14 +20383,14 @@ class Upgrade {
|
|
|
20381
20383
|
partialState;
|
|
20382
20384
|
index = tryAsHostCallIndex(19);
|
|
20383
20385
|
basicGasCost = tryAsSmallGas(10);
|
|
20384
|
-
tracedRegisters = traceRegisters(IN_OUT_REG$
|
|
20386
|
+
tracedRegisters = traceRegisters(IN_OUT_REG$6, GAS_REG, ALLOWANCE_REG);
|
|
20385
20387
|
constructor(currentServiceId, partialState) {
|
|
20386
20388
|
this.currentServiceId = currentServiceId;
|
|
20387
20389
|
this.partialState = partialState;
|
|
20388
20390
|
}
|
|
20389
20391
|
async execute(_gas, regs, memory) {
|
|
20390
20392
|
// `o`
|
|
20391
|
-
const codeHashStart = regs.get(IN_OUT_REG$
|
|
20393
|
+
const codeHashStart = regs.get(IN_OUT_REG$6);
|
|
20392
20394
|
// `g`
|
|
20393
20395
|
const gas = regs.get(GAS_REG);
|
|
20394
20396
|
// `m`
|
|
@@ -20402,11 +20404,11 @@ class Upgrade {
|
|
|
20402
20404
|
}
|
|
20403
20405
|
this.partialState.upgradeService(codeHash.asOpaque(), gas, allowance);
|
|
20404
20406
|
logger$7.trace `[${this.currentServiceId}] UPGRADE(${codeHash}, ${gas}, ${allowance})`;
|
|
20405
|
-
regs.set(IN_OUT_REG$
|
|
20407
|
+
regs.set(IN_OUT_REG$6, HostCallResult.OK);
|
|
20406
20408
|
}
|
|
20407
20409
|
}
|
|
20408
20410
|
|
|
20409
|
-
const IN_OUT_REG$
|
|
20411
|
+
const IN_OUT_REG$5 = 7;
|
|
20410
20412
|
/**
|
|
20411
20413
|
* Yield accumulation trie result.
|
|
20412
20414
|
*
|
|
@@ -20417,14 +20419,14 @@ class Yield {
|
|
|
20417
20419
|
partialState;
|
|
20418
20420
|
index = tryAsHostCallIndex(25);
|
|
20419
20421
|
basicGasCost = tryAsSmallGas(10);
|
|
20420
|
-
tracedRegisters = traceRegisters(IN_OUT_REG$
|
|
20422
|
+
tracedRegisters = traceRegisters(IN_OUT_REG$5);
|
|
20421
20423
|
constructor(currentServiceId, partialState) {
|
|
20422
20424
|
this.currentServiceId = currentServiceId;
|
|
20423
20425
|
this.partialState = partialState;
|
|
20424
20426
|
}
|
|
20425
20427
|
async execute(_gas, regs, memory) {
|
|
20426
20428
|
// `o`
|
|
20427
|
-
const hashStart = regs.get(IN_OUT_REG$
|
|
20429
|
+
const hashStart = regs.get(IN_OUT_REG$5);
|
|
20428
20430
|
const hash = Bytes.zero(HASH_SIZE);
|
|
20429
20431
|
const memoryReadResult = memory.loadInto(hash.raw, hashStart);
|
|
20430
20432
|
if (memoryReadResult.isError) {
|
|
@@ -20433,11 +20435,11 @@ class Yield {
|
|
|
20433
20435
|
}
|
|
20434
20436
|
this.partialState.yield(hash);
|
|
20435
20437
|
logger$7.trace `[${this.currentServiceId}] YIELD(${hash})`;
|
|
20436
|
-
regs.set(IN_OUT_REG$
|
|
20438
|
+
regs.set(IN_OUT_REG$5, HostCallResult.OK);
|
|
20437
20439
|
}
|
|
20438
20440
|
}
|
|
20439
20441
|
|
|
20440
|
-
const IN_OUT_REG$
|
|
20442
|
+
const IN_OUT_REG$4 = 7;
|
|
20441
20443
|
/**
|
|
20442
20444
|
* https://graypaper.fluffylabs.dev/#/7e6ff6a/324000324000?v=0.6.7
|
|
20443
20445
|
*/
|
|
@@ -20446,7 +20448,7 @@ class Fetch {
|
|
|
20446
20448
|
fetch;
|
|
20447
20449
|
index = tryAsHostCallIndex(1);
|
|
20448
20450
|
basicGasCost = tryAsSmallGas(10);
|
|
20449
|
-
tracedRegisters = traceRegisters(IN_OUT_REG$
|
|
20451
|
+
tracedRegisters = traceRegisters(IN_OUT_REG$4, 8, 9, 10, 11, 12);
|
|
20450
20452
|
constructor(currentServiceId, fetch) {
|
|
20451
20453
|
this.currentServiceId = currentServiceId;
|
|
20452
20454
|
this.fetch = fetch;
|
|
@@ -20456,7 +20458,7 @@ class Fetch {
|
|
|
20456
20458
|
const kind = clampU64ToU32(fetchKindU64);
|
|
20457
20459
|
const value = this.getValue(kind, regs);
|
|
20458
20460
|
// o
|
|
20459
|
-
const output = regs.get(IN_OUT_REG$
|
|
20461
|
+
const output = regs.get(IN_OUT_REG$4);
|
|
20460
20462
|
const valueLength = tryAsU64(value?.length ?? 0);
|
|
20461
20463
|
// f
|
|
20462
20464
|
const offset = minU64(regs.get(8), valueLength);
|
|
@@ -20472,7 +20474,7 @@ class Fetch {
|
|
|
20472
20474
|
}
|
|
20473
20475
|
logger$7.trace `[${this.currentServiceId}] FETCH(${kind}) <- ${value?.toStringTruncated()}`;
|
|
20474
20476
|
// write result
|
|
20475
|
-
regs.set(IN_OUT_REG$
|
|
20477
|
+
regs.set(IN_OUT_REG$4, value === null ? HostCallResult.NONE : valueLength);
|
|
20476
20478
|
}
|
|
20477
20479
|
getValue(kind, regs) {
|
|
20478
20480
|
if (kind === FetchKind.Constants) {
|
|
@@ -20587,6 +20589,7 @@ var Levels;
|
|
|
20587
20589
|
Levels[Levels["NIT"] = 4] = "NIT";
|
|
20588
20590
|
Levels[Levels["UNKNOWN"] = 5] = "UNKNOWN";
|
|
20589
20591
|
})(Levels || (Levels = {}));
|
|
20592
|
+
const IN_OUT_REG$3 = 7;
|
|
20590
20593
|
/**
|
|
20591
20594
|
* Log message to the console
|
|
20592
20595
|
*
|
|
@@ -20595,13 +20598,13 @@ var Levels;
|
|
|
20595
20598
|
class LogHostCall {
|
|
20596
20599
|
currentServiceId;
|
|
20597
20600
|
index = tryAsHostCallIndex(100);
|
|
20598
|
-
basicGasCost = tryAsSmallGas(0);
|
|
20601
|
+
basicGasCost = Compatibility.isGreaterOrEqual(GpVersion.V0_7_2) ? tryAsSmallGas(10) : tryAsSmallGas(0);
|
|
20599
20602
|
// intentionally not tracing anything here, since the message will be printed anyway.
|
|
20600
20603
|
tracedRegisters = traceRegisters();
|
|
20601
20604
|
constructor(currentServiceId) {
|
|
20602
20605
|
this.currentServiceId = currentServiceId;
|
|
20603
20606
|
}
|
|
20604
|
-
execute(_gas, regs, memory) {
|
|
20607
|
+
async execute(_gas, regs, memory) {
|
|
20605
20608
|
const lvl = regs.get(7);
|
|
20606
20609
|
const targetStart = regs.get(8);
|
|
20607
20610
|
const targetLength = regs.get(9);
|
|
@@ -20615,7 +20618,9 @@ class LogHostCall {
|
|
|
20615
20618
|
memory.loadInto(message, msgStart);
|
|
20616
20619
|
const level = clampU64ToU32(lvl);
|
|
20617
20620
|
logger$7.trace `[${this.currentServiceId}] LOG(${this.currentServiceId}, ${level < Levels.UNKNOWN ? Levels[level] : Levels[Levels.UNKNOWN]}(${lvl}), ${decoder.decode(target)}, ${decoder.decode(message)})`;
|
|
20618
|
-
|
|
20621
|
+
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_2)) {
|
|
20622
|
+
regs.set(IN_OUT_REG$3, HostCallResult.WHAT);
|
|
20623
|
+
}
|
|
20619
20624
|
}
|
|
20620
20625
|
}
|
|
20621
20626
|
|
|
@@ -24163,6 +24168,863 @@ var index$4 = /*#__PURE__*/Object.freeze({
|
|
|
24163
24168
|
stfError: stfError
|
|
24164
24169
|
});
|
|
24165
24170
|
|
|
24171
|
+
/*
|
|
24172
|
+
* Copyright The OpenTelemetry Authors
|
|
24173
|
+
*
|
|
24174
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
24175
|
+
* you may not use this file except in compliance with the License.
|
|
24176
|
+
* You may obtain a copy of the License at
|
|
24177
|
+
*
|
|
24178
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
24179
|
+
*
|
|
24180
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
24181
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
24182
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24183
|
+
* See the License for the specific language governing permissions and
|
|
24184
|
+
* limitations under the License.
|
|
24185
|
+
*/
|
|
24186
|
+
/** only globals that common to node and browsers are allowed */
|
|
24187
|
+
// eslint-disable-next-line node/no-unsupported-features/es-builtins
|
|
24188
|
+
var _globalThis = typeof globalThis === 'object' ? globalThis : global;
|
|
24189
|
+
|
|
24190
|
+
/*
|
|
24191
|
+
* Copyright The OpenTelemetry Authors
|
|
24192
|
+
*
|
|
24193
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
24194
|
+
* you may not use this file except in compliance with the License.
|
|
24195
|
+
* You may obtain a copy of the License at
|
|
24196
|
+
*
|
|
24197
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
24198
|
+
*
|
|
24199
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
24200
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
24201
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24202
|
+
* See the License for the specific language governing permissions and
|
|
24203
|
+
* limitations under the License.
|
|
24204
|
+
*/
|
|
24205
|
+
// this is autogenerated file, see scripts/version-update.js
|
|
24206
|
+
var VERSION = '1.9.0';
|
|
24207
|
+
|
|
24208
|
+
/*
|
|
24209
|
+
* Copyright The OpenTelemetry Authors
|
|
24210
|
+
*
|
|
24211
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
24212
|
+
* you may not use this file except in compliance with the License.
|
|
24213
|
+
* You may obtain a copy of the License at
|
|
24214
|
+
*
|
|
24215
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
24216
|
+
*
|
|
24217
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
24218
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
24219
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24220
|
+
* See the License for the specific language governing permissions and
|
|
24221
|
+
* limitations under the License.
|
|
24222
|
+
*/
|
|
24223
|
+
var re = /^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;
|
|
24224
|
+
/**
|
|
24225
|
+
* Create a function to test an API version to see if it is compatible with the provided ownVersion.
|
|
24226
|
+
*
|
|
24227
|
+
* The returned function has the following semantics:
|
|
24228
|
+
* - Exact match is always compatible
|
|
24229
|
+
* - Major versions must match exactly
|
|
24230
|
+
* - 1.x package cannot use global 2.x package
|
|
24231
|
+
* - 2.x package cannot use global 1.x package
|
|
24232
|
+
* - The minor version of the API module requesting access to the global API must be less than or equal to the minor version of this API
|
|
24233
|
+
* - 1.3 package may use 1.4 global because the later global contains all functions 1.3 expects
|
|
24234
|
+
* - 1.4 package may NOT use 1.3 global because it may try to call functions which don't exist on 1.3
|
|
24235
|
+
* - If the major version is 0, the minor version is treated as the major and the patch is treated as the minor
|
|
24236
|
+
* - Patch and build tag differences are not considered at this time
|
|
24237
|
+
*
|
|
24238
|
+
* @param ownVersion version which should be checked against
|
|
24239
|
+
*/
|
|
24240
|
+
function _makeCompatibilityCheck(ownVersion) {
|
|
24241
|
+
var acceptedVersions = new Set([ownVersion]);
|
|
24242
|
+
var rejectedVersions = new Set();
|
|
24243
|
+
var myVersionMatch = ownVersion.match(re);
|
|
24244
|
+
if (!myVersionMatch) {
|
|
24245
|
+
// we cannot guarantee compatibility so we always return noop
|
|
24246
|
+
return function () { return false; };
|
|
24247
|
+
}
|
|
24248
|
+
var ownVersionParsed = {
|
|
24249
|
+
major: +myVersionMatch[1],
|
|
24250
|
+
minor: +myVersionMatch[2],
|
|
24251
|
+
patch: +myVersionMatch[3],
|
|
24252
|
+
prerelease: myVersionMatch[4],
|
|
24253
|
+
};
|
|
24254
|
+
// if ownVersion has a prerelease tag, versions must match exactly
|
|
24255
|
+
if (ownVersionParsed.prerelease != null) {
|
|
24256
|
+
return function isExactmatch(globalVersion) {
|
|
24257
|
+
return globalVersion === ownVersion;
|
|
24258
|
+
};
|
|
24259
|
+
}
|
|
24260
|
+
function _reject(v) {
|
|
24261
|
+
rejectedVersions.add(v);
|
|
24262
|
+
return false;
|
|
24263
|
+
}
|
|
24264
|
+
function _accept(v) {
|
|
24265
|
+
acceptedVersions.add(v);
|
|
24266
|
+
return true;
|
|
24267
|
+
}
|
|
24268
|
+
return function isCompatible(globalVersion) {
|
|
24269
|
+
if (acceptedVersions.has(globalVersion)) {
|
|
24270
|
+
return true;
|
|
24271
|
+
}
|
|
24272
|
+
if (rejectedVersions.has(globalVersion)) {
|
|
24273
|
+
return false;
|
|
24274
|
+
}
|
|
24275
|
+
var globalVersionMatch = globalVersion.match(re);
|
|
24276
|
+
if (!globalVersionMatch) {
|
|
24277
|
+
// cannot parse other version
|
|
24278
|
+
// we cannot guarantee compatibility so we always noop
|
|
24279
|
+
return _reject(globalVersion);
|
|
24280
|
+
}
|
|
24281
|
+
var globalVersionParsed = {
|
|
24282
|
+
major: +globalVersionMatch[1],
|
|
24283
|
+
minor: +globalVersionMatch[2],
|
|
24284
|
+
patch: +globalVersionMatch[3],
|
|
24285
|
+
prerelease: globalVersionMatch[4],
|
|
24286
|
+
};
|
|
24287
|
+
// if globalVersion has a prerelease tag, versions must match exactly
|
|
24288
|
+
if (globalVersionParsed.prerelease != null) {
|
|
24289
|
+
return _reject(globalVersion);
|
|
24290
|
+
}
|
|
24291
|
+
// major versions must match
|
|
24292
|
+
if (ownVersionParsed.major !== globalVersionParsed.major) {
|
|
24293
|
+
return _reject(globalVersion);
|
|
24294
|
+
}
|
|
24295
|
+
if (ownVersionParsed.major === 0) {
|
|
24296
|
+
if (ownVersionParsed.minor === globalVersionParsed.minor &&
|
|
24297
|
+
ownVersionParsed.patch <= globalVersionParsed.patch) {
|
|
24298
|
+
return _accept(globalVersion);
|
|
24299
|
+
}
|
|
24300
|
+
return _reject(globalVersion);
|
|
24301
|
+
}
|
|
24302
|
+
if (ownVersionParsed.minor <= globalVersionParsed.minor) {
|
|
24303
|
+
return _accept(globalVersion);
|
|
24304
|
+
}
|
|
24305
|
+
return _reject(globalVersion);
|
|
24306
|
+
};
|
|
24307
|
+
}
|
|
24308
|
+
/**
|
|
24309
|
+
* Test an API version to see if it is compatible with this API.
|
|
24310
|
+
*
|
|
24311
|
+
* - Exact match is always compatible
|
|
24312
|
+
* - Major versions must match exactly
|
|
24313
|
+
* - 1.x package cannot use global 2.x package
|
|
24314
|
+
* - 2.x package cannot use global 1.x package
|
|
24315
|
+
* - The minor version of the API module requesting access to the global API must be less than or equal to the minor version of this API
|
|
24316
|
+
* - 1.3 package may use 1.4 global because the later global contains all functions 1.3 expects
|
|
24317
|
+
* - 1.4 package may NOT use 1.3 global because it may try to call functions which don't exist on 1.3
|
|
24318
|
+
* - If the major version is 0, the minor version is treated as the major and the patch is treated as the minor
|
|
24319
|
+
* - Patch and build tag differences are not considered at this time
|
|
24320
|
+
*
|
|
24321
|
+
* @param version version of the API requesting an instance of the global API
|
|
24322
|
+
*/
|
|
24323
|
+
var isCompatible = _makeCompatibilityCheck(VERSION);
|
|
24324
|
+
|
|
24325
|
+
/*
|
|
24326
|
+
* Copyright The OpenTelemetry Authors
|
|
24327
|
+
*
|
|
24328
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
24329
|
+
* you may not use this file except in compliance with the License.
|
|
24330
|
+
* You may obtain a copy of the License at
|
|
24331
|
+
*
|
|
24332
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
24333
|
+
*
|
|
24334
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
24335
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
24336
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24337
|
+
* See the License for the specific language governing permissions and
|
|
24338
|
+
* limitations under the License.
|
|
24339
|
+
*/
|
|
24340
|
+
var major = VERSION.split('.')[0];
|
|
24341
|
+
var GLOBAL_OPENTELEMETRY_API_KEY = Symbol.for("opentelemetry.js.api." + major);
|
|
24342
|
+
var _global = _globalThis;
|
|
24343
|
+
function registerGlobal(type, instance, diag, allowOverride) {
|
|
24344
|
+
var _a;
|
|
24345
|
+
if (allowOverride === void 0) { allowOverride = false; }
|
|
24346
|
+
var api = (_global[GLOBAL_OPENTELEMETRY_API_KEY] = (_a = _global[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a !== void 0 ? _a : {
|
|
24347
|
+
version: VERSION,
|
|
24348
|
+
});
|
|
24349
|
+
if (!allowOverride && api[type]) {
|
|
24350
|
+
// already registered an API of this type
|
|
24351
|
+
var err = new Error("@opentelemetry/api: Attempted duplicate registration of API: " + type);
|
|
24352
|
+
diag.error(err.stack || err.message);
|
|
24353
|
+
return false;
|
|
24354
|
+
}
|
|
24355
|
+
if (api.version !== VERSION) {
|
|
24356
|
+
// All registered APIs must be of the same version exactly
|
|
24357
|
+
var err = new Error("@opentelemetry/api: Registration of version v" + api.version + " for " + type + " does not match previously registered API v" + VERSION);
|
|
24358
|
+
diag.error(err.stack || err.message);
|
|
24359
|
+
return false;
|
|
24360
|
+
}
|
|
24361
|
+
api[type] = instance;
|
|
24362
|
+
diag.debug("@opentelemetry/api: Registered a global for " + type + " v" + VERSION + ".");
|
|
24363
|
+
return true;
|
|
24364
|
+
}
|
|
24365
|
+
function getGlobal(type) {
|
|
24366
|
+
var _a, _b;
|
|
24367
|
+
var globalVersion = (_a = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _a === void 0 ? void 0 : _a.version;
|
|
24368
|
+
if (!globalVersion || !isCompatible(globalVersion)) {
|
|
24369
|
+
return;
|
|
24370
|
+
}
|
|
24371
|
+
return (_b = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _b === void 0 ? void 0 : _b[type];
|
|
24372
|
+
}
|
|
24373
|
+
function unregisterGlobal(type, diag) {
|
|
24374
|
+
diag.debug("@opentelemetry/api: Unregistering a global for " + type + " v" + VERSION + ".");
|
|
24375
|
+
var api = _global[GLOBAL_OPENTELEMETRY_API_KEY];
|
|
24376
|
+
if (api) {
|
|
24377
|
+
delete api[type];
|
|
24378
|
+
}
|
|
24379
|
+
}
|
|
24380
|
+
|
|
24381
|
+
/*
|
|
24382
|
+
* Copyright The OpenTelemetry Authors
|
|
24383
|
+
*
|
|
24384
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
24385
|
+
* you may not use this file except in compliance with the License.
|
|
24386
|
+
* You may obtain a copy of the License at
|
|
24387
|
+
*
|
|
24388
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
24389
|
+
*
|
|
24390
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
24391
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
24392
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24393
|
+
* See the License for the specific language governing permissions and
|
|
24394
|
+
* limitations under the License.
|
|
24395
|
+
*/
|
|
24396
|
+
var __read$1 = (undefined && undefined.__read) || function (o, n) {
|
|
24397
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
24398
|
+
if (!m) return o;
|
|
24399
|
+
var i = m.call(o), r, ar = [], e;
|
|
24400
|
+
try {
|
|
24401
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
24402
|
+
}
|
|
24403
|
+
catch (error) { e = { error: error }; }
|
|
24404
|
+
finally {
|
|
24405
|
+
try {
|
|
24406
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24407
|
+
}
|
|
24408
|
+
finally { if (e) throw e.error; }
|
|
24409
|
+
}
|
|
24410
|
+
return ar;
|
|
24411
|
+
};
|
|
24412
|
+
var __spreadArray$1 = (undefined && undefined.__spreadArray) || function (to, from, pack) {
|
|
24413
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
24414
|
+
if (ar || !(i in from)) {
|
|
24415
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
24416
|
+
ar[i] = from[i];
|
|
24417
|
+
}
|
|
24418
|
+
}
|
|
24419
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
24420
|
+
};
|
|
24421
|
+
/**
|
|
24422
|
+
* Component Logger which is meant to be used as part of any component which
|
|
24423
|
+
* will add automatically additional namespace in front of the log message.
|
|
24424
|
+
* It will then forward all message to global diag logger
|
|
24425
|
+
* @example
|
|
24426
|
+
* const cLogger = diag.createComponentLogger({ namespace: '@opentelemetry/instrumentation-http' });
|
|
24427
|
+
* cLogger.debug('test');
|
|
24428
|
+
* // @opentelemetry/instrumentation-http test
|
|
24429
|
+
*/
|
|
24430
|
+
var DiagComponentLogger = /** @class */ (function () {
|
|
24431
|
+
function DiagComponentLogger(props) {
|
|
24432
|
+
this._namespace = props.namespace || 'DiagComponentLogger';
|
|
24433
|
+
}
|
|
24434
|
+
DiagComponentLogger.prototype.debug = function () {
|
|
24435
|
+
var args = [];
|
|
24436
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
24437
|
+
args[_i] = arguments[_i];
|
|
24438
|
+
}
|
|
24439
|
+
return logProxy('debug', this._namespace, args);
|
|
24440
|
+
};
|
|
24441
|
+
DiagComponentLogger.prototype.error = function () {
|
|
24442
|
+
var args = [];
|
|
24443
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
24444
|
+
args[_i] = arguments[_i];
|
|
24445
|
+
}
|
|
24446
|
+
return logProxy('error', this._namespace, args);
|
|
24447
|
+
};
|
|
24448
|
+
DiagComponentLogger.prototype.info = function () {
|
|
24449
|
+
var args = [];
|
|
24450
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
24451
|
+
args[_i] = arguments[_i];
|
|
24452
|
+
}
|
|
24453
|
+
return logProxy('info', this._namespace, args);
|
|
24454
|
+
};
|
|
24455
|
+
DiagComponentLogger.prototype.warn = function () {
|
|
24456
|
+
var args = [];
|
|
24457
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
24458
|
+
args[_i] = arguments[_i];
|
|
24459
|
+
}
|
|
24460
|
+
return logProxy('warn', this._namespace, args);
|
|
24461
|
+
};
|
|
24462
|
+
DiagComponentLogger.prototype.verbose = function () {
|
|
24463
|
+
var args = [];
|
|
24464
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
24465
|
+
args[_i] = arguments[_i];
|
|
24466
|
+
}
|
|
24467
|
+
return logProxy('verbose', this._namespace, args);
|
|
24468
|
+
};
|
|
24469
|
+
return DiagComponentLogger;
|
|
24470
|
+
}());
|
|
24471
|
+
function logProxy(funcName, namespace, args) {
|
|
24472
|
+
var logger = getGlobal('diag');
|
|
24473
|
+
// shortcut if logger not set
|
|
24474
|
+
if (!logger) {
|
|
24475
|
+
return;
|
|
24476
|
+
}
|
|
24477
|
+
args.unshift(namespace);
|
|
24478
|
+
return logger[funcName].apply(logger, __spreadArray$1([], __read$1(args), false));
|
|
24479
|
+
}
|
|
24480
|
+
|
|
24481
|
+
/*
|
|
24482
|
+
* Copyright The OpenTelemetry Authors
|
|
24483
|
+
*
|
|
24484
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
24485
|
+
* you may not use this file except in compliance with the License.
|
|
24486
|
+
* You may obtain a copy of the License at
|
|
24487
|
+
*
|
|
24488
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
24489
|
+
*
|
|
24490
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
24491
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
24492
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24493
|
+
* See the License for the specific language governing permissions and
|
|
24494
|
+
* limitations under the License.
|
|
24495
|
+
*/
|
|
24496
|
+
/**
|
|
24497
|
+
* Defines the available internal logging levels for the diagnostic logger, the numeric values
|
|
24498
|
+
* of the levels are defined to match the original values from the initial LogLevel to avoid
|
|
24499
|
+
* compatibility/migration issues for any implementation that assume the numeric ordering.
|
|
24500
|
+
*/
|
|
24501
|
+
var DiagLogLevel;
|
|
24502
|
+
(function (DiagLogLevel) {
|
|
24503
|
+
/** Diagnostic Logging level setting to disable all logging (except and forced logs) */
|
|
24504
|
+
DiagLogLevel[DiagLogLevel["NONE"] = 0] = "NONE";
|
|
24505
|
+
/** Identifies an error scenario */
|
|
24506
|
+
DiagLogLevel[DiagLogLevel["ERROR"] = 30] = "ERROR";
|
|
24507
|
+
/** Identifies a warning scenario */
|
|
24508
|
+
DiagLogLevel[DiagLogLevel["WARN"] = 50] = "WARN";
|
|
24509
|
+
/** General informational log message */
|
|
24510
|
+
DiagLogLevel[DiagLogLevel["INFO"] = 60] = "INFO";
|
|
24511
|
+
/** General debug log message */
|
|
24512
|
+
DiagLogLevel[DiagLogLevel["DEBUG"] = 70] = "DEBUG";
|
|
24513
|
+
/**
|
|
24514
|
+
* Detailed trace level logging should only be used for development, should only be set
|
|
24515
|
+
* in a development environment.
|
|
24516
|
+
*/
|
|
24517
|
+
DiagLogLevel[DiagLogLevel["VERBOSE"] = 80] = "VERBOSE";
|
|
24518
|
+
/** Used to set the logging level to include all logging */
|
|
24519
|
+
DiagLogLevel[DiagLogLevel["ALL"] = 9999] = "ALL";
|
|
24520
|
+
})(DiagLogLevel || (DiagLogLevel = {}));
|
|
24521
|
+
|
|
24522
|
+
/*
|
|
24523
|
+
* Copyright The OpenTelemetry Authors
|
|
24524
|
+
*
|
|
24525
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
24526
|
+
* you may not use this file except in compliance with the License.
|
|
24527
|
+
* You may obtain a copy of the License at
|
|
24528
|
+
*
|
|
24529
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
24530
|
+
*
|
|
24531
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
24532
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
24533
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24534
|
+
* See the License for the specific language governing permissions and
|
|
24535
|
+
* limitations under the License.
|
|
24536
|
+
*/
|
|
24537
|
+
function createLogLevelDiagLogger(maxLevel, logger) {
|
|
24538
|
+
if (maxLevel < DiagLogLevel.NONE) {
|
|
24539
|
+
maxLevel = DiagLogLevel.NONE;
|
|
24540
|
+
}
|
|
24541
|
+
else if (maxLevel > DiagLogLevel.ALL) {
|
|
24542
|
+
maxLevel = DiagLogLevel.ALL;
|
|
24543
|
+
}
|
|
24544
|
+
// In case the logger is null or undefined
|
|
24545
|
+
logger = logger || {};
|
|
24546
|
+
function _filterFunc(funcName, theLevel) {
|
|
24547
|
+
var theFunc = logger[funcName];
|
|
24548
|
+
if (typeof theFunc === 'function' && maxLevel >= theLevel) {
|
|
24549
|
+
return theFunc.bind(logger);
|
|
24550
|
+
}
|
|
24551
|
+
return function () { };
|
|
24552
|
+
}
|
|
24553
|
+
return {
|
|
24554
|
+
error: _filterFunc('error', DiagLogLevel.ERROR),
|
|
24555
|
+
warn: _filterFunc('warn', DiagLogLevel.WARN),
|
|
24556
|
+
info: _filterFunc('info', DiagLogLevel.INFO),
|
|
24557
|
+
debug: _filterFunc('debug', DiagLogLevel.DEBUG),
|
|
24558
|
+
verbose: _filterFunc('verbose', DiagLogLevel.VERBOSE),
|
|
24559
|
+
};
|
|
24560
|
+
}
|
|
24561
|
+
|
|
24562
|
+
/*
|
|
24563
|
+
* Copyright The OpenTelemetry Authors
|
|
24564
|
+
*
|
|
24565
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
24566
|
+
* you may not use this file except in compliance with the License.
|
|
24567
|
+
* You may obtain a copy of the License at
|
|
24568
|
+
*
|
|
24569
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
24570
|
+
*
|
|
24571
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
24572
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
24573
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24574
|
+
* See the License for the specific language governing permissions and
|
|
24575
|
+
* limitations under the License.
|
|
24576
|
+
*/
|
|
24577
|
+
var __read = (undefined && undefined.__read) || function (o, n) {
|
|
24578
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
24579
|
+
if (!m) return o;
|
|
24580
|
+
var i = m.call(o), r, ar = [], e;
|
|
24581
|
+
try {
|
|
24582
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
24583
|
+
}
|
|
24584
|
+
catch (error) { e = { error: error }; }
|
|
24585
|
+
finally {
|
|
24586
|
+
try {
|
|
24587
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24588
|
+
}
|
|
24589
|
+
finally { if (e) throw e.error; }
|
|
24590
|
+
}
|
|
24591
|
+
return ar;
|
|
24592
|
+
};
|
|
24593
|
+
var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from, pack) {
|
|
24594
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
24595
|
+
if (ar || !(i in from)) {
|
|
24596
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
24597
|
+
ar[i] = from[i];
|
|
24598
|
+
}
|
|
24599
|
+
}
|
|
24600
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
24601
|
+
};
|
|
24602
|
+
var API_NAME$1 = 'diag';
|
|
24603
|
+
/**
|
|
24604
|
+
* Singleton object which represents the entry point to the OpenTelemetry internal
|
|
24605
|
+
* diagnostic API
|
|
24606
|
+
*/
|
|
24607
|
+
var DiagAPI = /** @class */ (function () {
|
|
24608
|
+
/**
|
|
24609
|
+
* Private internal constructor
|
|
24610
|
+
* @private
|
|
24611
|
+
*/
|
|
24612
|
+
function DiagAPI() {
|
|
24613
|
+
function _logProxy(funcName) {
|
|
24614
|
+
return function () {
|
|
24615
|
+
var args = [];
|
|
24616
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
24617
|
+
args[_i] = arguments[_i];
|
|
24618
|
+
}
|
|
24619
|
+
var logger = getGlobal('diag');
|
|
24620
|
+
// shortcut if logger not set
|
|
24621
|
+
if (!logger)
|
|
24622
|
+
return;
|
|
24623
|
+
return logger[funcName].apply(logger, __spreadArray([], __read(args), false));
|
|
24624
|
+
};
|
|
24625
|
+
}
|
|
24626
|
+
// Using self local variable for minification purposes as 'this' cannot be minified
|
|
24627
|
+
var self = this;
|
|
24628
|
+
// DiagAPI specific functions
|
|
24629
|
+
var setLogger = function (logger, optionsOrLogLevel) {
|
|
24630
|
+
var _a, _b, _c;
|
|
24631
|
+
if (optionsOrLogLevel === void 0) { optionsOrLogLevel = { logLevel: DiagLogLevel.INFO }; }
|
|
24632
|
+
if (logger === self) {
|
|
24633
|
+
// There isn't much we can do here.
|
|
24634
|
+
// Logging to the console might break the user application.
|
|
24635
|
+
// Try to log to self. If a logger was previously registered it will receive the log.
|
|
24636
|
+
var err = new Error('Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation');
|
|
24637
|
+
self.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
|
|
24638
|
+
return false;
|
|
24639
|
+
}
|
|
24640
|
+
if (typeof optionsOrLogLevel === 'number') {
|
|
24641
|
+
optionsOrLogLevel = {
|
|
24642
|
+
logLevel: optionsOrLogLevel,
|
|
24643
|
+
};
|
|
24644
|
+
}
|
|
24645
|
+
var oldLogger = getGlobal('diag');
|
|
24646
|
+
var newLogger = createLogLevelDiagLogger((_b = optionsOrLogLevel.logLevel) !== null && _b !== void 0 ? _b : DiagLogLevel.INFO, logger);
|
|
24647
|
+
// There already is an logger registered. We'll let it know before overwriting it.
|
|
24648
|
+
if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {
|
|
24649
|
+
var stack = (_c = new Error().stack) !== null && _c !== void 0 ? _c : '<failed to generate stacktrace>';
|
|
24650
|
+
oldLogger.warn("Current logger will be overwritten from " + stack);
|
|
24651
|
+
newLogger.warn("Current logger will overwrite one already registered from " + stack);
|
|
24652
|
+
}
|
|
24653
|
+
return registerGlobal('diag', newLogger, self, true);
|
|
24654
|
+
};
|
|
24655
|
+
self.setLogger = setLogger;
|
|
24656
|
+
self.disable = function () {
|
|
24657
|
+
unregisterGlobal(API_NAME$1, self);
|
|
24658
|
+
};
|
|
24659
|
+
self.createComponentLogger = function (options) {
|
|
24660
|
+
return new DiagComponentLogger(options);
|
|
24661
|
+
};
|
|
24662
|
+
self.verbose = _logProxy('verbose');
|
|
24663
|
+
self.debug = _logProxy('debug');
|
|
24664
|
+
self.info = _logProxy('info');
|
|
24665
|
+
self.warn = _logProxy('warn');
|
|
24666
|
+
self.error = _logProxy('error');
|
|
24667
|
+
}
|
|
24668
|
+
/** Get the singleton instance of the DiagAPI API */
|
|
24669
|
+
DiagAPI.instance = function () {
|
|
24670
|
+
if (!this._instance) {
|
|
24671
|
+
this._instance = new DiagAPI();
|
|
24672
|
+
}
|
|
24673
|
+
return this._instance;
|
|
24674
|
+
};
|
|
24675
|
+
return DiagAPI;
|
|
24676
|
+
}());
|
|
24677
|
+
|
|
24678
|
+
/*
|
|
24679
|
+
* Copyright The OpenTelemetry Authors
|
|
24680
|
+
*
|
|
24681
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
24682
|
+
* you may not use this file except in compliance with the License.
|
|
24683
|
+
* You may obtain a copy of the License at
|
|
24684
|
+
*
|
|
24685
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
24686
|
+
*
|
|
24687
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
24688
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
24689
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24690
|
+
* See the License for the specific language governing permissions and
|
|
24691
|
+
* limitations under the License.
|
|
24692
|
+
*/
|
|
24693
|
+
var __extends = (undefined && undefined.__extends) || (function () {
|
|
24694
|
+
var extendStatics = function (d, b) {
|
|
24695
|
+
extendStatics = Object.setPrototypeOf ||
|
|
24696
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
24697
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
24698
|
+
return extendStatics(d, b);
|
|
24699
|
+
};
|
|
24700
|
+
return function (d, b) {
|
|
24701
|
+
if (typeof b !== "function" && b !== null)
|
|
24702
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
24703
|
+
extendStatics(d, b);
|
|
24704
|
+
function __() { this.constructor = d; }
|
|
24705
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
24706
|
+
};
|
|
24707
|
+
})();
|
|
24708
|
+
/**
|
|
24709
|
+
* NoopMeter is a noop implementation of the {@link Meter} interface. It reuses
|
|
24710
|
+
* constant NoopMetrics for all of its methods.
|
|
24711
|
+
*/
|
|
24712
|
+
var NoopMeter = /** @class */ (function () {
|
|
24713
|
+
function NoopMeter() {
|
|
24714
|
+
}
|
|
24715
|
+
/**
|
|
24716
|
+
* @see {@link Meter.createGauge}
|
|
24717
|
+
*/
|
|
24718
|
+
NoopMeter.prototype.createGauge = function (_name, _options) {
|
|
24719
|
+
return NOOP_GAUGE_METRIC;
|
|
24720
|
+
};
|
|
24721
|
+
/**
|
|
24722
|
+
* @see {@link Meter.createHistogram}
|
|
24723
|
+
*/
|
|
24724
|
+
NoopMeter.prototype.createHistogram = function (_name, _options) {
|
|
24725
|
+
return NOOP_HISTOGRAM_METRIC;
|
|
24726
|
+
};
|
|
24727
|
+
/**
|
|
24728
|
+
* @see {@link Meter.createCounter}
|
|
24729
|
+
*/
|
|
24730
|
+
NoopMeter.prototype.createCounter = function (_name, _options) {
|
|
24731
|
+
return NOOP_COUNTER_METRIC;
|
|
24732
|
+
};
|
|
24733
|
+
/**
|
|
24734
|
+
* @see {@link Meter.createUpDownCounter}
|
|
24735
|
+
*/
|
|
24736
|
+
NoopMeter.prototype.createUpDownCounter = function (_name, _options) {
|
|
24737
|
+
return NOOP_UP_DOWN_COUNTER_METRIC;
|
|
24738
|
+
};
|
|
24739
|
+
/**
|
|
24740
|
+
* @see {@link Meter.createObservableGauge}
|
|
24741
|
+
*/
|
|
24742
|
+
NoopMeter.prototype.createObservableGauge = function (_name, _options) {
|
|
24743
|
+
return NOOP_OBSERVABLE_GAUGE_METRIC;
|
|
24744
|
+
};
|
|
24745
|
+
/**
|
|
24746
|
+
* @see {@link Meter.createObservableCounter}
|
|
24747
|
+
*/
|
|
24748
|
+
NoopMeter.prototype.createObservableCounter = function (_name, _options) {
|
|
24749
|
+
return NOOP_OBSERVABLE_COUNTER_METRIC;
|
|
24750
|
+
};
|
|
24751
|
+
/**
|
|
24752
|
+
* @see {@link Meter.createObservableUpDownCounter}
|
|
24753
|
+
*/
|
|
24754
|
+
NoopMeter.prototype.createObservableUpDownCounter = function (_name, _options) {
|
|
24755
|
+
return NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC;
|
|
24756
|
+
};
|
|
24757
|
+
/**
|
|
24758
|
+
* @see {@link Meter.addBatchObservableCallback}
|
|
24759
|
+
*/
|
|
24760
|
+
NoopMeter.prototype.addBatchObservableCallback = function (_callback, _observables) { };
|
|
24761
|
+
/**
|
|
24762
|
+
* @see {@link Meter.removeBatchObservableCallback}
|
|
24763
|
+
*/
|
|
24764
|
+
NoopMeter.prototype.removeBatchObservableCallback = function (_callback) { };
|
|
24765
|
+
return NoopMeter;
|
|
24766
|
+
}());
|
|
24767
|
+
var NoopMetric = /** @class */ (function () {
|
|
24768
|
+
function NoopMetric() {
|
|
24769
|
+
}
|
|
24770
|
+
return NoopMetric;
|
|
24771
|
+
}());
|
|
24772
|
+
var NoopCounterMetric = /** @class */ (function (_super) {
|
|
24773
|
+
__extends(NoopCounterMetric, _super);
|
|
24774
|
+
function NoopCounterMetric() {
|
|
24775
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
24776
|
+
}
|
|
24777
|
+
NoopCounterMetric.prototype.add = function (_value, _attributes) { };
|
|
24778
|
+
return NoopCounterMetric;
|
|
24779
|
+
}(NoopMetric));
|
|
24780
|
+
var NoopUpDownCounterMetric = /** @class */ (function (_super) {
|
|
24781
|
+
__extends(NoopUpDownCounterMetric, _super);
|
|
24782
|
+
function NoopUpDownCounterMetric() {
|
|
24783
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
24784
|
+
}
|
|
24785
|
+
NoopUpDownCounterMetric.prototype.add = function (_value, _attributes) { };
|
|
24786
|
+
return NoopUpDownCounterMetric;
|
|
24787
|
+
}(NoopMetric));
|
|
24788
|
+
var NoopGaugeMetric = /** @class */ (function (_super) {
|
|
24789
|
+
__extends(NoopGaugeMetric, _super);
|
|
24790
|
+
function NoopGaugeMetric() {
|
|
24791
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
24792
|
+
}
|
|
24793
|
+
NoopGaugeMetric.prototype.record = function (_value, _attributes) { };
|
|
24794
|
+
return NoopGaugeMetric;
|
|
24795
|
+
}(NoopMetric));
|
|
24796
|
+
var NoopHistogramMetric = /** @class */ (function (_super) {
|
|
24797
|
+
__extends(NoopHistogramMetric, _super);
|
|
24798
|
+
function NoopHistogramMetric() {
|
|
24799
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
24800
|
+
}
|
|
24801
|
+
NoopHistogramMetric.prototype.record = function (_value, _attributes) { };
|
|
24802
|
+
return NoopHistogramMetric;
|
|
24803
|
+
}(NoopMetric));
|
|
24804
|
+
var NoopObservableMetric = /** @class */ (function () {
|
|
24805
|
+
function NoopObservableMetric() {
|
|
24806
|
+
}
|
|
24807
|
+
NoopObservableMetric.prototype.addCallback = function (_callback) { };
|
|
24808
|
+
NoopObservableMetric.prototype.removeCallback = function (_callback) { };
|
|
24809
|
+
return NoopObservableMetric;
|
|
24810
|
+
}());
|
|
24811
|
+
var NoopObservableCounterMetric = /** @class */ (function (_super) {
|
|
24812
|
+
__extends(NoopObservableCounterMetric, _super);
|
|
24813
|
+
function NoopObservableCounterMetric() {
|
|
24814
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
24815
|
+
}
|
|
24816
|
+
return NoopObservableCounterMetric;
|
|
24817
|
+
}(NoopObservableMetric));
|
|
24818
|
+
var NoopObservableGaugeMetric = /** @class */ (function (_super) {
|
|
24819
|
+
__extends(NoopObservableGaugeMetric, _super);
|
|
24820
|
+
function NoopObservableGaugeMetric() {
|
|
24821
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
24822
|
+
}
|
|
24823
|
+
return NoopObservableGaugeMetric;
|
|
24824
|
+
}(NoopObservableMetric));
|
|
24825
|
+
var NoopObservableUpDownCounterMetric = /** @class */ (function (_super) {
|
|
24826
|
+
__extends(NoopObservableUpDownCounterMetric, _super);
|
|
24827
|
+
function NoopObservableUpDownCounterMetric() {
|
|
24828
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
24829
|
+
}
|
|
24830
|
+
return NoopObservableUpDownCounterMetric;
|
|
24831
|
+
}(NoopObservableMetric));
|
|
24832
|
+
var NOOP_METER = new NoopMeter();
|
|
24833
|
+
// Synchronous instruments
|
|
24834
|
+
var NOOP_COUNTER_METRIC = new NoopCounterMetric();
|
|
24835
|
+
var NOOP_GAUGE_METRIC = new NoopGaugeMetric();
|
|
24836
|
+
var NOOP_HISTOGRAM_METRIC = new NoopHistogramMetric();
|
|
24837
|
+
var NOOP_UP_DOWN_COUNTER_METRIC = new NoopUpDownCounterMetric();
|
|
24838
|
+
// Asynchronous instruments
|
|
24839
|
+
var NOOP_OBSERVABLE_COUNTER_METRIC = new NoopObservableCounterMetric();
|
|
24840
|
+
var NOOP_OBSERVABLE_GAUGE_METRIC = new NoopObservableGaugeMetric();
|
|
24841
|
+
var NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC = new NoopObservableUpDownCounterMetric();
|
|
24842
|
+
|
|
24843
|
+
/*
|
|
24844
|
+
* Copyright The OpenTelemetry Authors
|
|
24845
|
+
*
|
|
24846
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
24847
|
+
* you may not use this file except in compliance with the License.
|
|
24848
|
+
* You may obtain a copy of the License at
|
|
24849
|
+
*
|
|
24850
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
24851
|
+
*
|
|
24852
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
24853
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
24854
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24855
|
+
* See the License for the specific language governing permissions and
|
|
24856
|
+
* limitations under the License.
|
|
24857
|
+
*/
|
|
24858
|
+
/**
|
|
24859
|
+
* An implementation of the {@link MeterProvider} which returns an impotent Meter
|
|
24860
|
+
* for all calls to `getMeter`
|
|
24861
|
+
*/
|
|
24862
|
+
var NoopMeterProvider = /** @class */ (function () {
|
|
24863
|
+
function NoopMeterProvider() {
|
|
24864
|
+
}
|
|
24865
|
+
NoopMeterProvider.prototype.getMeter = function (_name, _version, _options) {
|
|
24866
|
+
return NOOP_METER;
|
|
24867
|
+
};
|
|
24868
|
+
return NoopMeterProvider;
|
|
24869
|
+
}());
|
|
24870
|
+
var NOOP_METER_PROVIDER = new NoopMeterProvider();
|
|
24871
|
+
|
|
24872
|
+
/*
|
|
24873
|
+
* Copyright The OpenTelemetry Authors
|
|
24874
|
+
*
|
|
24875
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
24876
|
+
* you may not use this file except in compliance with the License.
|
|
24877
|
+
* You may obtain a copy of the License at
|
|
24878
|
+
*
|
|
24879
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
24880
|
+
*
|
|
24881
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
24882
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
24883
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24884
|
+
* See the License for the specific language governing permissions and
|
|
24885
|
+
* limitations under the License.
|
|
24886
|
+
*/
|
|
24887
|
+
var API_NAME = 'metrics';
|
|
24888
|
+
/**
|
|
24889
|
+
* Singleton object which represents the entry point to the OpenTelemetry Metrics API
|
|
24890
|
+
*/
|
|
24891
|
+
var MetricsAPI = /** @class */ (function () {
|
|
24892
|
+
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
|
24893
|
+
function MetricsAPI() {
|
|
24894
|
+
}
|
|
24895
|
+
/** Get the singleton instance of the Metrics API */
|
|
24896
|
+
MetricsAPI.getInstance = function () {
|
|
24897
|
+
if (!this._instance) {
|
|
24898
|
+
this._instance = new MetricsAPI();
|
|
24899
|
+
}
|
|
24900
|
+
return this._instance;
|
|
24901
|
+
};
|
|
24902
|
+
/**
|
|
24903
|
+
* Set the current global meter provider.
|
|
24904
|
+
* Returns true if the meter provider was successfully registered, else false.
|
|
24905
|
+
*/
|
|
24906
|
+
MetricsAPI.prototype.setGlobalMeterProvider = function (provider) {
|
|
24907
|
+
return registerGlobal(API_NAME, provider, DiagAPI.instance());
|
|
24908
|
+
};
|
|
24909
|
+
/**
|
|
24910
|
+
* Returns the global meter provider.
|
|
24911
|
+
*/
|
|
24912
|
+
MetricsAPI.prototype.getMeterProvider = function () {
|
|
24913
|
+
return getGlobal(API_NAME) || NOOP_METER_PROVIDER;
|
|
24914
|
+
};
|
|
24915
|
+
/**
|
|
24916
|
+
* Returns a meter from the global meter provider.
|
|
24917
|
+
*/
|
|
24918
|
+
MetricsAPI.prototype.getMeter = function (name, version, options) {
|
|
24919
|
+
return this.getMeterProvider().getMeter(name, version, options);
|
|
24920
|
+
};
|
|
24921
|
+
/** Remove the global meter provider */
|
|
24922
|
+
MetricsAPI.prototype.disable = function () {
|
|
24923
|
+
unregisterGlobal(API_NAME, DiagAPI.instance());
|
|
24924
|
+
};
|
|
24925
|
+
return MetricsAPI;
|
|
24926
|
+
}());
|
|
24927
|
+
|
|
24928
|
+
/*
|
|
24929
|
+
* Copyright The OpenTelemetry Authors
|
|
24930
|
+
*
|
|
24931
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
24932
|
+
* you may not use this file except in compliance with the License.
|
|
24933
|
+
* You may obtain a copy of the License at
|
|
24934
|
+
*
|
|
24935
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
24936
|
+
*
|
|
24937
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
24938
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
24939
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24940
|
+
* See the License for the specific language governing permissions and
|
|
24941
|
+
* limitations under the License.
|
|
24942
|
+
*/
|
|
24943
|
+
// Split module-level variable definition into separate files to allow
|
|
24944
|
+
// tree-shaking on each api instance.
|
|
24945
|
+
/** Entrypoint for metrics API */
|
|
24946
|
+
var metrics = MetricsAPI.getInstance();
|
|
24947
|
+
|
|
24948
|
+
var name = "@typeberry/importer";
|
|
24949
|
+
var version = "0.4.1";
|
|
24950
|
+
var packageJson = {
|
|
24951
|
+
name: name,
|
|
24952
|
+
version: version};
|
|
24953
|
+
|
|
24954
|
+
/**
|
|
24955
|
+
* Block importer metrics for JAM implementation.
|
|
24956
|
+
*
|
|
24957
|
+
* https://github.com/polkadot-fellows/JIPs/blob/main/JIP-3.md#block-authoringimporting-events
|
|
24958
|
+
*/
|
|
24959
|
+
function createMetrics() {
|
|
24960
|
+
const meter = metrics.getMeter(packageJson.name, packageJson.version);
|
|
24961
|
+
const blockVerificationDuration = meter.createHistogram("jam.blockVerificationTime", {
|
|
24962
|
+
description: "Duration of block verification",
|
|
24963
|
+
unit: "ms",
|
|
24964
|
+
});
|
|
24965
|
+
const blockExecutionDuration = meter.createHistogram("jam.blockExecutionTime", {
|
|
24966
|
+
description: "Duration of block execution",
|
|
24967
|
+
unit: "ms",
|
|
24968
|
+
});
|
|
24969
|
+
const blockExecutionCost = meter.createHistogram("jam.blockExecutionGas", {
|
|
24970
|
+
description: "Block execution cost (gas)",
|
|
24971
|
+
unit: "gas",
|
|
24972
|
+
});
|
|
24973
|
+
const blockImportDuration = meter.createHistogram("jam.blockImportTime", {
|
|
24974
|
+
description: "Total duration of block import (verification + execution)",
|
|
24975
|
+
unit: "ms",
|
|
24976
|
+
});
|
|
24977
|
+
// JIP-3
|
|
24978
|
+
// 43
|
|
24979
|
+
const blockImportingCounter = meter.createCounter("jam.jip3.importing", {
|
|
24980
|
+
description: "Block importing started",
|
|
24981
|
+
unit: "blocks",
|
|
24982
|
+
});
|
|
24983
|
+
// 44
|
|
24984
|
+
const blockVerificationFailedCounter = meter.createCounter("jam.jip3.verification_failed", {
|
|
24985
|
+
description: "Block verification failed",
|
|
24986
|
+
unit: "errors",
|
|
24987
|
+
});
|
|
24988
|
+
// 45
|
|
24989
|
+
const blockVerifiedCounter = meter.createCounter("jam.jip3.verified", {
|
|
24990
|
+
description: "Block verified successfully",
|
|
24991
|
+
unit: "blocks",
|
|
24992
|
+
});
|
|
24993
|
+
// 46
|
|
24994
|
+
const blockExecutionFailedCounter = meter.createCounter("jam.jip3.execution_failed", {
|
|
24995
|
+
description: "Block execution failed",
|
|
24996
|
+
unit: "errors",
|
|
24997
|
+
});
|
|
24998
|
+
// 47
|
|
24999
|
+
const blockExecutedCounter = meter.createCounter("jam.jip3.executed", {
|
|
25000
|
+
description: "Block executed successfully",
|
|
25001
|
+
unit: "blocks",
|
|
25002
|
+
});
|
|
25003
|
+
return {
|
|
25004
|
+
recordBlockImportComplete(totalDurationMs, success) {
|
|
25005
|
+
blockImportDuration.record(totalDurationMs, { success });
|
|
25006
|
+
},
|
|
25007
|
+
recordBlockImportingStarted(slot) {
|
|
25008
|
+
blockImportingCounter.add(1, { slot });
|
|
25009
|
+
},
|
|
25010
|
+
recordBlockVerificationFailed(reason) {
|
|
25011
|
+
blockVerificationFailedCounter.add(1, { reason });
|
|
25012
|
+
},
|
|
25013
|
+
recordBlockVerified(durationMs) {
|
|
25014
|
+
blockVerifiedCounter.add(1);
|
|
25015
|
+
blockVerificationDuration.record(durationMs);
|
|
25016
|
+
},
|
|
25017
|
+
recordBlockExecutionFailed(reason) {
|
|
25018
|
+
blockExecutionFailedCounter.add(1, { reason });
|
|
25019
|
+
},
|
|
25020
|
+
recordBlockExecuted(durationMs, cost) {
|
|
25021
|
+
blockExecutedCounter.add(1);
|
|
25022
|
+
blockExecutionDuration.record(durationMs);
|
|
25023
|
+
blockExecutionCost.record(cost);
|
|
25024
|
+
},
|
|
25025
|
+
};
|
|
25026
|
+
}
|
|
25027
|
+
|
|
24166
25028
|
var ImporterErrorKind;
|
|
24167
25029
|
(function (ImporterErrorKind) {
|
|
24168
25030
|
ImporterErrorKind[ImporterErrorKind["Verifier"] = 0] = "Verifier";
|
|
@@ -24181,11 +25043,13 @@ class Importer {
|
|
|
24181
25043
|
state;
|
|
24182
25044
|
// Hash of the block that we have the posterior state for in `state`.
|
|
24183
25045
|
currentHash;
|
|
25046
|
+
metrics;
|
|
24184
25047
|
constructor(spec, pvm, hasher, logger, blocks, states) {
|
|
24185
25048
|
this.hasher = hasher;
|
|
24186
25049
|
this.logger = logger;
|
|
24187
25050
|
this.blocks = blocks;
|
|
24188
25051
|
this.states = states;
|
|
25052
|
+
this.metrics = createMetrics();
|
|
24189
25053
|
const currentBestHeaderHash = this.blocks.getBestHeaderHash();
|
|
24190
25054
|
const state = states.getState(currentBestHeaderHash);
|
|
24191
25055
|
if (state === null) {
|
|
@@ -24218,26 +25082,35 @@ class Importer {
|
|
|
24218
25082
|
async importBlock(block, omitSealVerification) {
|
|
24219
25083
|
const timer = measure("importBlock");
|
|
24220
25084
|
const timeSlot = extractTimeSlot(block);
|
|
25085
|
+
this.metrics.recordBlockImportingStarted(timeSlot);
|
|
25086
|
+
const startTime = now();
|
|
24221
25087
|
const maybeBestHeader = await this.importBlockInternal(block, omitSealVerification);
|
|
25088
|
+
const duration = now() - startTime;
|
|
24222
25089
|
if (maybeBestHeader.isOk) {
|
|
24223
25090
|
const bestHeader = maybeBestHeader.ok;
|
|
24224
25091
|
this.logger.info `🧊 Best block: #${timeSlot} (${bestHeader.hash})`;
|
|
24225
25092
|
this.logger.log `${timer()}`;
|
|
25093
|
+
this.metrics.recordBlockImportComplete(duration, true);
|
|
24226
25094
|
return maybeBestHeader;
|
|
24227
25095
|
}
|
|
24228
25096
|
this.logger.log `❌ Rejected block #${timeSlot}: ${resultToString(maybeBestHeader)}`;
|
|
24229
25097
|
this.logger.log `${timer()}`;
|
|
25098
|
+
this.metrics.recordBlockImportComplete(duration, false);
|
|
24230
25099
|
return maybeBestHeader;
|
|
24231
25100
|
}
|
|
24232
25101
|
async importBlockInternal(block, omitSealVerification = false) {
|
|
24233
25102
|
const logger = this.logger;
|
|
24234
25103
|
logger.log `🧱 Attempting to import a new block`;
|
|
24235
25104
|
const timerVerify = measure("import:verify");
|
|
25105
|
+
const verifyStart = now();
|
|
24236
25106
|
const hash = await this.verifier.verifyBlock(block);
|
|
25107
|
+
const verifyDuration = now() - verifyStart;
|
|
24237
25108
|
logger.log `${timerVerify()}`;
|
|
24238
25109
|
if (hash.isError) {
|
|
25110
|
+
this.metrics.recordBlockVerificationFailed(resultToString(hash));
|
|
24239
25111
|
return importerError(ImporterErrorKind.Verifier, hash);
|
|
24240
25112
|
}
|
|
25113
|
+
this.metrics.recordBlockVerified(verifyDuration);
|
|
24241
25114
|
// TODO [ToDr] This is incomplete/temporary fork support!
|
|
24242
25115
|
const parentHash = block.header.view().parentHeaderHash.materialize();
|
|
24243
25116
|
if (!this.currentHash.isEqualTo(parentHash)) {
|
|
@@ -24257,11 +25130,15 @@ class Importer {
|
|
|
24257
25130
|
const headerHash = hash.ok;
|
|
24258
25131
|
logger.log `🧱 Verified block: Got hash ${headerHash} for block at slot ${timeSlot}.`;
|
|
24259
25132
|
const timerStf = measure("import:stf");
|
|
25133
|
+
const stfStart = now();
|
|
24260
25134
|
const res = await this.stf.transition(block, headerHash, omitSealVerification);
|
|
25135
|
+
const stfDuration = now() - stfStart;
|
|
24261
25136
|
logger.log `${timerStf()}`;
|
|
24262
25137
|
if (res.isError) {
|
|
25138
|
+
this.metrics.recordBlockExecutionFailed(resultToString(res));
|
|
24263
25139
|
return importerError(ImporterErrorKind.Stf, res);
|
|
24264
25140
|
}
|
|
25141
|
+
this.metrics.recordBlockExecuted(stfDuration, 0);
|
|
24265
25142
|
// modify the state
|
|
24266
25143
|
const update = res.ok;
|
|
24267
25144
|
const timerState = measure("import:state");
|
|
@@ -24444,10 +25321,8 @@ class Channel {
|
|
|
24444
25321
|
// listen to request incoming to worker
|
|
24445
25322
|
this.port.on(key, val.request, async ({ responseId, data }) => {
|
|
24446
25323
|
try {
|
|
24447
|
-
console.log(`[${this.port.threadId}] handling ${key}. Responseid: ${responseId}`);
|
|
24448
25324
|
// handle them
|
|
24449
25325
|
const response = await handler(data);
|
|
24450
|
-
console.log(`[${this.port.threadId}] sending response: ${responseId}`);
|
|
24451
25326
|
// and send response back on dedicated event
|
|
24452
25327
|
this.port.postMessage(responseId, val.response, {
|
|
24453
25328
|
responseId,
|
|
@@ -24465,14 +25340,12 @@ class Channel {
|
|
|
24465
25340
|
return (data) => {
|
|
24466
25341
|
this.nextResponseId++;
|
|
24467
25342
|
const responseId = `${key}:${this.nextResponseId}`;
|
|
24468
|
-
console.log(`[${this.port.threadId}] will wait for ${key}`);
|
|
24469
25343
|
return new Promise((resolve, reject) => {
|
|
24470
25344
|
this.pendingPromises.add(reject);
|
|
24471
25345
|
// attach response listener first
|
|
24472
25346
|
this.port.once(responseId, val.response, (msg) => {
|
|
24473
25347
|
// we got response, so will resolve
|
|
24474
25348
|
this.pendingPromises.delete(reject);
|
|
24475
|
-
console.log(`[${this.port.threadId}] got ${key}`);
|
|
24476
25349
|
resolve(msg.data);
|
|
24477
25350
|
});
|
|
24478
25351
|
// send message to the port
|
|
@@ -24501,14 +25374,16 @@ function isMessageCodecs(val) {
|
|
|
24501
25374
|
* Worker config with in-thread database.
|
|
24502
25375
|
*/
|
|
24503
25376
|
class DirectWorkerConfig {
|
|
25377
|
+
nodeName;
|
|
24504
25378
|
chainSpec;
|
|
24505
25379
|
workerParams;
|
|
24506
25380
|
blocksDb;
|
|
24507
25381
|
statesDb;
|
|
24508
|
-
static new({ chainSpec, blocksDb, statesDb, params, }) {
|
|
24509
|
-
return new DirectWorkerConfig(chainSpec, params, blocksDb, statesDb);
|
|
25382
|
+
static new({ nodeName, chainSpec, blocksDb, statesDb, params, }) {
|
|
25383
|
+
return new DirectWorkerConfig(nodeName, chainSpec, params, blocksDb, statesDb);
|
|
24510
25384
|
}
|
|
24511
|
-
constructor(chainSpec, workerParams, blocksDb, statesDb) {
|
|
25385
|
+
constructor(nodeName, chainSpec, workerParams, blocksDb, statesDb) {
|
|
25386
|
+
this.nodeName = nodeName;
|
|
24512
25387
|
this.chainSpec = chainSpec;
|
|
24513
25388
|
this.workerParams = workerParams;
|
|
24514
25389
|
this.blocksDb = blocksDb;
|
|
@@ -25040,6 +25915,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
|
|
|
25040
25915
|
ImporterConfig: ImporterConfig,
|
|
25041
25916
|
WORKER: WORKER,
|
|
25042
25917
|
createImporter: createImporter,
|
|
25918
|
+
createMetrics: createMetrics,
|
|
25043
25919
|
main: main,
|
|
25044
25920
|
protocol: protocol
|
|
25045
25921
|
});
|