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