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