@typeberry/jam 0.1.0-08a9db1 → 0.1.0-b2d0b72
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/block-generator/index.js +200 -122
- package/block-generator/index.js.map +1 -1
- package/importer/index.js +207 -129
- package/importer/index.js.map +1 -1
- package/index.js +207 -129
- package/index.js.map +1 -1
- package/jam-network/index.js +127 -90
- package/jam-network/index.js.map +1 -1
- package/package.json +1 -1
package/jam-network/index.js
CHANGED
|
@@ -25323,29 +25323,17 @@ function isBrowser() {
|
|
|
25323
25323
|
* We avoid using `node:assert` to keep compatibility with a browser environment.
|
|
25324
25324
|
* Note the checks should not have any side effects, since we might decide
|
|
25325
25325
|
* to remove all of them in a post-processing step.
|
|
25326
|
-
*/
|
|
25327
|
-
function debug_check(condition, message) {
|
|
25328
|
-
if (!condition) {
|
|
25329
|
-
throw new Error(`Assertion failure: ${message ?? ""}`);
|
|
25330
|
-
}
|
|
25331
|
-
}
|
|
25332
|
-
function cast(_a, condition) {
|
|
25333
|
-
return condition;
|
|
25334
|
-
}
|
|
25335
|
-
/**
|
|
25336
|
-
* Yet another function to perform runtime assertions.
|
|
25337
|
-
* This function returns a new type to mark in the code that this value was checked and you don't have to do it again.
|
|
25338
25326
|
*
|
|
25339
|
-
*
|
|
25340
|
-
*
|
|
25341
|
-
* should be replaced with:
|
|
25342
|
-
* const x = y as CheckedNumber;
|
|
25327
|
+
* NOTE the function is intended to be used as tagged template string for the performance
|
|
25328
|
+
* reasons.
|
|
25343
25329
|
*/
|
|
25344
|
-
function
|
|
25345
|
-
if (
|
|
25346
|
-
|
|
25330
|
+
function debug_check(strings, condition, ...data) {
|
|
25331
|
+
if (!condition) {
|
|
25332
|
+
// add an empty value so that `data.length === strings.length`
|
|
25333
|
+
data.unshift("");
|
|
25334
|
+
const message = strings.map((v, index) => `${v}${data[index] ?? ""}`);
|
|
25335
|
+
throw new Error(`Assertion failure:${message.join("")}`);
|
|
25347
25336
|
}
|
|
25348
|
-
throw new Error(`Assertion failure: ${message ?? ""}`);
|
|
25349
25337
|
}
|
|
25350
25338
|
/**
|
|
25351
25339
|
* The function can be used to make sure that a particular type is `never`
|
|
@@ -25515,7 +25503,7 @@ function result_resultToString(res) {
|
|
|
25515
25503
|
const result_Result = {
|
|
25516
25504
|
/** Create new [`Result`] with `Ok` status. */
|
|
25517
25505
|
ok: (ok) => {
|
|
25518
|
-
debug_check
|
|
25506
|
+
debug_check `${ok !== undefined} 'ok' type cannot be undefined.`;
|
|
25519
25507
|
return {
|
|
25520
25508
|
isOk: true,
|
|
25521
25509
|
isError: false,
|
|
@@ -25524,7 +25512,7 @@ const result_Result = {
|
|
|
25524
25512
|
},
|
|
25525
25513
|
/** Create new [`Result`] with `Error` status. */
|
|
25526
25514
|
error: (error, details = "") => {
|
|
25527
|
-
debug_check
|
|
25515
|
+
debug_check `${error !== undefined} 'Error' type cannot be undefined.`;
|
|
25528
25516
|
return {
|
|
25529
25517
|
isOk: false,
|
|
25530
25518
|
isError: true,
|
|
@@ -25808,7 +25796,10 @@ class bitvec_BitVec {
|
|
|
25808
25796
|
constructor(data, bitLength) {
|
|
25809
25797
|
this.data = data;
|
|
25810
25798
|
this.bitLength = bitLength;
|
|
25811
|
-
debug_check
|
|
25799
|
+
debug_check `
|
|
25800
|
+
${data.length * 8 >= bitLength}
|
|
25801
|
+
Not enough bytes in the data array. Need ${data.length * 8} has ${bitLength}.
|
|
25802
|
+
`;
|
|
25812
25803
|
this.byteLength = Math.ceil(bitLength / 8);
|
|
25813
25804
|
}
|
|
25814
25805
|
/** Return a raw in-memory representation of this [`BitVec`]. */
|
|
@@ -25817,7 +25808,10 @@ class bitvec_BitVec {
|
|
|
25817
25808
|
}
|
|
25818
25809
|
/** Perform OR operation on all bits in place. */
|
|
25819
25810
|
sumWith(other) {
|
|
25820
|
-
debug_check
|
|
25811
|
+
debug_check `
|
|
25812
|
+
${other.bitLength === this.bitLength}
|
|
25813
|
+
Invalid bit length for sumWith: ${other.bitLength} vs ${this.bitLength}
|
|
25814
|
+
`;
|
|
25821
25815
|
const otherRaw = other.raw;
|
|
25822
25816
|
for (let i = 0; i < this.byteLength; i++) {
|
|
25823
25817
|
this.data[i] |= otherRaw[i];
|
|
@@ -25827,7 +25821,7 @@ class bitvec_BitVec {
|
|
|
25827
25821
|
* Set the bit at index `idx` to value `val`.
|
|
25828
25822
|
*/
|
|
25829
25823
|
setBit(idx, val) {
|
|
25830
|
-
debug_check
|
|
25824
|
+
debug_check `${idx >= 0 && idx < this.bitLength} Index out of bounds. Need ${idx} has ${this.bitLength}.`;
|
|
25831
25825
|
const byteIndex = Math.floor(idx / 8);
|
|
25832
25826
|
const bitIndexInByte = idx % 8;
|
|
25833
25827
|
const mask = 1 << bitIndexInByte;
|
|
@@ -25842,7 +25836,7 @@ class bitvec_BitVec {
|
|
|
25842
25836
|
* Return `true` if the bit at index `idx` is set.
|
|
25843
25837
|
*/
|
|
25844
25838
|
isSet(idx) {
|
|
25845
|
-
debug_check
|
|
25839
|
+
debug_check `${idx >= 0 && idx < this.bitLength} Index out of bounds. Need ${idx} has ${this.bitLength}.`;
|
|
25846
25840
|
const byteIndex = Math.floor(idx / 8);
|
|
25847
25841
|
const bitIndexInByte = idx % 8;
|
|
25848
25842
|
const mask = 1 << bitIndexInByte;
|
|
@@ -26009,7 +26003,7 @@ class bytes_BytesBlob {
|
|
|
26009
26003
|
}
|
|
26010
26004
|
/** Create a new [`BytesBlob`] from an array of bytes. */
|
|
26011
26005
|
static blobFromNumbers(v) {
|
|
26012
|
-
debug_check
|
|
26006
|
+
debug_check `${v.find((x) => (x & 0xff) !== x) === undefined} BytesBlob.blobFromNumbers used with non-byte number array.`;
|
|
26013
26007
|
const arr = new Uint8Array(v);
|
|
26014
26008
|
return new bytes_BytesBlob(arr);
|
|
26015
26009
|
}
|
|
@@ -26053,7 +26047,7 @@ class bytes_Bytes extends bytes_BytesBlob {
|
|
|
26053
26047
|
length;
|
|
26054
26048
|
constructor(raw, len) {
|
|
26055
26049
|
super(raw);
|
|
26056
|
-
debug_check
|
|
26050
|
+
debug_check `${raw.byteLength === len} Given buffer has incorrect size ${raw.byteLength} vs expected ${len}`;
|
|
26057
26051
|
this.length = len;
|
|
26058
26052
|
}
|
|
26059
26053
|
/** Create new [`Bytes<X>`] given a backing buffer and it's length. */
|
|
@@ -26062,7 +26056,7 @@ class bytes_Bytes extends bytes_BytesBlob {
|
|
|
26062
26056
|
}
|
|
26063
26057
|
/** Create new [`Bytes<X>`] given an array of bytes and it's length. */
|
|
26064
26058
|
static fromNumbers(v, len) {
|
|
26065
|
-
debug_check
|
|
26059
|
+
debug_check `${v.find((x) => (x & 0xff) !== x) === undefined} Bytes.fromNumbers used with non-byte number array.`;
|
|
26066
26060
|
const x = new Uint8Array(v);
|
|
26067
26061
|
return new bytes_Bytes(x, len);
|
|
26068
26062
|
}
|
|
@@ -26073,7 +26067,7 @@ class bytes_Bytes extends bytes_BytesBlob {
|
|
|
26073
26067
|
// TODO [ToDr] `fill` should have the argments swapped to align with the rest.
|
|
26074
26068
|
/** Create a [`Bytes<X>`] with all bytes filled with given input number. */
|
|
26075
26069
|
static fill(len, input) {
|
|
26076
|
-
debug_check(
|
|
26070
|
+
debug_check `${(input & 0xff) === input} Input has to be a byte.`;
|
|
26077
26071
|
const bytes = bytes_Bytes.zero(len);
|
|
26078
26072
|
bytes.raw.fill(input, 0, len);
|
|
26079
26073
|
return bytes;
|
|
@@ -26096,7 +26090,7 @@ class bytes_Bytes extends bytes_BytesBlob {
|
|
|
26096
26090
|
}
|
|
26097
26091
|
/** Compare the sequence to another one. */
|
|
26098
26092
|
isEqualTo(other) {
|
|
26099
|
-
debug_check
|
|
26093
|
+
debug_check `${this.length === other.length} Comparing incorrectly typed bytes!`;
|
|
26100
26094
|
return u8ArraySameLengthEqual(this.raw, other.raw);
|
|
26101
26095
|
}
|
|
26102
26096
|
/** Converts current type into some opaque extension. */
|
|
@@ -26105,7 +26099,7 @@ class bytes_Bytes extends bytes_BytesBlob {
|
|
|
26105
26099
|
}
|
|
26106
26100
|
}
|
|
26107
26101
|
function byteFromString(s) {
|
|
26108
|
-
debug_check
|
|
26102
|
+
debug_check `${s.length === 2} Two-character string expected`;
|
|
26109
26103
|
const a = numberFromCharCode(s.charCodeAt(0));
|
|
26110
26104
|
const b = numberFromCharCode(s.charCodeAt(1));
|
|
26111
26105
|
return (a << 4) | b;
|
|
@@ -26159,42 +26153,53 @@ const bytesBlobComparator = (a, b) => a.compare(b);
|
|
|
26159
26153
|
|
|
26160
26154
|
;// CONCATENATED MODULE: ./packages/core/numbers/index.ts
|
|
26161
26155
|
|
|
26162
|
-
const
|
|
26156
|
+
const asTypedNumber = (v) => v;
|
|
26163
26157
|
const MAX_VALUE_U8 = 0xff;
|
|
26164
26158
|
const MAX_VALUE_U16 = 0xffff;
|
|
26165
26159
|
const MAX_VALUE_U32 = 0xffff_ffff;
|
|
26166
26160
|
const MAX_VALUE_U64 = 0xffffffffffffffffn;
|
|
26167
26161
|
/** Attempt to cast an input number into U8. */
|
|
26168
|
-
const tryAsU8 = (v) =>
|
|
26162
|
+
const tryAsU8 = (v) => {
|
|
26163
|
+
debug_check `${isU8(v)} input must have one-byte representation, got ${v}`;
|
|
26164
|
+
return asTypedNumber(v);
|
|
26165
|
+
};
|
|
26169
26166
|
/** Check if given number is a valid U8 number. */
|
|
26170
26167
|
const isU8 = (v) => (v & MAX_VALUE_U8) === v;
|
|
26171
26168
|
/** Attempt to cast an input number into U16. */
|
|
26172
|
-
const numbers_tryAsU16 = (v) =>
|
|
26169
|
+
const numbers_tryAsU16 = (v) => {
|
|
26170
|
+
debug_check `${isU16(v)} input must have two-byte representation, got ${v}`;
|
|
26171
|
+
return asTypedNumber(v);
|
|
26172
|
+
};
|
|
26173
26173
|
/** Check if given number is a valid U16 number. */
|
|
26174
26174
|
const isU16 = (v) => (v & MAX_VALUE_U16) === v;
|
|
26175
26175
|
/** Attempt to cast an input number into U32. */
|
|
26176
|
-
const numbers_tryAsU32 = (v) =>
|
|
26176
|
+
const numbers_tryAsU32 = (v) => {
|
|
26177
|
+
debug_check `${isU32(v)} input must have four-byte representation, got ${v}`;
|
|
26178
|
+
return asTypedNumber(v);
|
|
26179
|
+
};
|
|
26177
26180
|
/** Check if given number is a valid U32 number. */
|
|
26178
26181
|
const isU32 = (v) => (v & MAX_VALUE_U32) >>> 0 === v;
|
|
26179
26182
|
/** Attempt to cast an input number into U64. */
|
|
26180
26183
|
const tryAsU64 = (x) => {
|
|
26181
26184
|
const v = BigInt(x);
|
|
26182
|
-
|
|
26185
|
+
debug_check `${isU64(v)} input must have eight-byte representation, got ${x}`;
|
|
26186
|
+
return asTypedNumber(v);
|
|
26183
26187
|
};
|
|
26184
26188
|
/** Check if given number is a valid U64 number. */
|
|
26185
26189
|
const isU64 = (v) => (v & MAX_VALUE_U64) === v;
|
|
26186
26190
|
/** Collate two U32 parts into one U64. */
|
|
26187
26191
|
const u64FromParts = ({ lower, upper }) => {
|
|
26188
26192
|
const val = (BigInt(upper) << 32n) + BigInt(lower);
|
|
26189
|
-
return
|
|
26193
|
+
return asTypedNumber(val);
|
|
26190
26194
|
};
|
|
26191
26195
|
/** Split U64 into lower & upper parts. */
|
|
26192
26196
|
const u64IntoParts = (v) => {
|
|
26193
|
-
|
|
26194
|
-
const
|
|
26197
|
+
// Number(...) safe: both parts are <= 0xffffffff
|
|
26198
|
+
const lower = Number(v & (2n ** 32n - 1n));
|
|
26199
|
+
const upper = Number(v >> 32n);
|
|
26195
26200
|
return {
|
|
26196
|
-
lower:
|
|
26197
|
-
upper:
|
|
26201
|
+
lower: asTypedNumber(lower),
|
|
26202
|
+
upper: asTypedNumber(upper),
|
|
26198
26203
|
};
|
|
26199
26204
|
};
|
|
26200
26205
|
/**
|
|
@@ -26234,8 +26239,8 @@ function numbers_u32AsLeBytes(value) {
|
|
|
26234
26239
|
* Interpret 4-byte `Uint8Array` as U32 written as little endian.
|
|
26235
26240
|
*/
|
|
26236
26241
|
function leBytesAsU32(uint8Array) {
|
|
26237
|
-
check
|
|
26238
|
-
return
|
|
26242
|
+
check `${uint8Array.length === 4} Input must be a Uint8Array of length 4`;
|
|
26243
|
+
return asTypedNumber(uint8Array[0] | (uint8Array[1] << 8) | (uint8Array[2] << 16) | (uint8Array[3] << 24));
|
|
26239
26244
|
}
|
|
26240
26245
|
/** Get the smallest value between U64 a and values given as input parameters. */
|
|
26241
26246
|
const minU64 = (a, ...values) => values.reduce((min, value) => (value > min ? min : value), a);
|
|
@@ -26526,7 +26531,7 @@ class decoder_Decoder {
|
|
|
26526
26531
|
this.skip(newOffset - this.offset);
|
|
26527
26532
|
}
|
|
26528
26533
|
else {
|
|
26529
|
-
debug_check
|
|
26534
|
+
debug_check `${newOffset >= 0} The offset has to be positive`;
|
|
26530
26535
|
this.offset = newOffset;
|
|
26531
26536
|
}
|
|
26532
26537
|
}
|
|
@@ -26554,7 +26559,7 @@ class decoder_Decoder {
|
|
|
26554
26559
|
return num;
|
|
26555
26560
|
}
|
|
26556
26561
|
ensureHasBytes(bytes) {
|
|
26557
|
-
debug_check
|
|
26562
|
+
debug_check `${bytes >= 0} Negative number of bytes given.`;
|
|
26558
26563
|
if (this.offset + bytes > this.source.length) {
|
|
26559
26564
|
throw new Error(`Attempting to decode more data than there is left. Need ${bytes}, left: ${this.source.length - this.offset}.`);
|
|
26560
26565
|
}
|
|
@@ -26562,7 +26567,7 @@ class decoder_Decoder {
|
|
|
26562
26567
|
}
|
|
26563
26568
|
const MASKS = [0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80];
|
|
26564
26569
|
function decodeVariableLengthExtraBytes(firstByte) {
|
|
26565
|
-
debug_check
|
|
26570
|
+
debug_check `${firstByte >= 0 && firstByte < 256} Incorrect byte value: ${firstByte}`;
|
|
26566
26571
|
for (let i = 0; i < MASKS.length; i++) {
|
|
26567
26572
|
if (firstByte >= MASKS[i]) {
|
|
26568
26573
|
return 8 - i;
|
|
@@ -26717,7 +26722,7 @@ class descriptor_Descriptor {
|
|
|
26717
26722
|
|
|
26718
26723
|
|
|
26719
26724
|
function tryAsExactBytes(a) {
|
|
26720
|
-
check
|
|
26725
|
+
check `${a.isExact} The value is not exact size estimation!`;
|
|
26721
26726
|
return a.bytes;
|
|
26722
26727
|
}
|
|
26723
26728
|
function addSizeHints(a, b) {
|
|
@@ -26824,8 +26829,8 @@ class encoder_Encoder {
|
|
|
26824
26829
|
// we still allow positive numbers from `[maxNum / 2, maxNum)`.
|
|
26825
26830
|
// So it does not matter if the argument is a negative value,
|
|
26826
26831
|
// OR if someone just gave us two-complement already.
|
|
26827
|
-
debug_check
|
|
26828
|
-
debug_check
|
|
26832
|
+
debug_check `${num < maxNum} Only for numbers up to 2**64 - 1`;
|
|
26833
|
+
debug_check `${-num <= maxNum / 2n} Only for numbers down to -2**63`;
|
|
26829
26834
|
this.ensureBigEnough(8);
|
|
26830
26835
|
this.dataView.setBigInt64(this.offset, num, true);
|
|
26831
26836
|
this.offset += 8;
|
|
@@ -26889,8 +26894,8 @@ class encoder_Encoder {
|
|
|
26889
26894
|
// we still allow positive numbers from `[maxNum / 2, maxNum)`.
|
|
26890
26895
|
// So it does not matter if the argument is a negative value,
|
|
26891
26896
|
// OR if someone just gave us two-complement already.
|
|
26892
|
-
debug_check
|
|
26893
|
-
debug_check
|
|
26897
|
+
debug_check `${num < maxNum} Only for numbers up to 2**${BITS * bytesToEncode} - 1`;
|
|
26898
|
+
debug_check `${-num <= maxNum / 2} Only for numbers down to -2**${BITS * bytesToEncode - 1}`;
|
|
26894
26899
|
this.ensureBigEnough(bytesToEncode);
|
|
26895
26900
|
}
|
|
26896
26901
|
/**
|
|
@@ -26901,8 +26906,8 @@ class encoder_Encoder {
|
|
|
26901
26906
|
* https://graypaper.fluffylabs.dev/#/579bd12/365202365202
|
|
26902
26907
|
*/
|
|
26903
26908
|
varU32(num) {
|
|
26904
|
-
debug_check
|
|
26905
|
-
debug_check
|
|
26909
|
+
debug_check `${num >= 0} Only for natural numbers.`;
|
|
26910
|
+
debug_check `${num < 2 ** 32} Only for numbers up to 2**32`;
|
|
26906
26911
|
this.varU64(BigInt(num));
|
|
26907
26912
|
}
|
|
26908
26913
|
/**
|
|
@@ -27053,7 +27058,7 @@ class encoder_Encoder {
|
|
|
27053
27058
|
* https://graypaper.fluffylabs.dev/#/579bd12/374400374400
|
|
27054
27059
|
*/
|
|
27055
27060
|
sequenceVarLen(encode, elements) {
|
|
27056
|
-
debug_check
|
|
27061
|
+
debug_check `${elements.length <= 2 ** 32} Wow, that's a nice long sequence you've got here.`;
|
|
27057
27062
|
this.varU32(numbers_tryAsU32(elements.length));
|
|
27058
27063
|
this.sequenceFixLen(encode, elements);
|
|
27059
27064
|
}
|
|
@@ -27074,7 +27079,7 @@ class encoder_Encoder {
|
|
|
27074
27079
|
* anyway, so if we really should throw we will.
|
|
27075
27080
|
*/
|
|
27076
27081
|
ensureBigEnough(length, options = { silent: false }) {
|
|
27077
|
-
debug_check
|
|
27082
|
+
debug_check `${length >= 0} Negative length given`;
|
|
27078
27083
|
const newLength = this.offset + length;
|
|
27079
27084
|
if (newLength > MAX_LENGTH) {
|
|
27080
27085
|
if (options.silent) {
|
|
@@ -27210,10 +27215,12 @@ class ObjectView {
|
|
|
27210
27215
|
decodeUpTo(field) {
|
|
27211
27216
|
const index = this.descriptorsKeys.indexOf(field);
|
|
27212
27217
|
const lastField = this.descriptorsKeys[this.lastDecodedFieldIdx];
|
|
27213
|
-
debug_check
|
|
27218
|
+
debug_check `
|
|
27219
|
+
${this.lastDecodedFieldIdx < index}
|
|
27220
|
+
Unjustified call to 'decodeUpTo' -
|
|
27214
27221
|
the index ($Blobindex}, ${String(field)})
|
|
27215
27222
|
is already decoded (${this.lastDecodedFieldIdx}, ${String(lastField)}).
|
|
27216
|
-
|
|
27223
|
+
`;
|
|
27217
27224
|
let lastItem = this.cache.get(lastField);
|
|
27218
27225
|
const skipper = new Skipper(this.decoder);
|
|
27219
27226
|
// now skip all of the fields and further populate the cache.
|
|
@@ -27229,8 +27236,10 @@ class ObjectView {
|
|
|
27229
27236
|
this.cache.set(field, lastItem);
|
|
27230
27237
|
this.lastDecodedFieldIdx = i;
|
|
27231
27238
|
}
|
|
27232
|
-
|
|
27233
|
-
|
|
27239
|
+
if (lastItem === undefined) {
|
|
27240
|
+
throw new Error("Last item must be set, since the loop turns at least once.");
|
|
27241
|
+
}
|
|
27242
|
+
return lastItem;
|
|
27234
27243
|
}
|
|
27235
27244
|
}
|
|
27236
27245
|
/**
|
|
@@ -27263,8 +27272,10 @@ class SequenceView {
|
|
|
27263
27272
|
*[Symbol.iterator]() {
|
|
27264
27273
|
for (let i = 0; i < this.length; i++) {
|
|
27265
27274
|
const val = this.get(i);
|
|
27266
|
-
|
|
27267
|
-
|
|
27275
|
+
if (val === undefined) {
|
|
27276
|
+
throw new Error("We are within 0..this.length so all items are defined.");
|
|
27277
|
+
}
|
|
27278
|
+
yield val;
|
|
27268
27279
|
}
|
|
27269
27280
|
}
|
|
27270
27281
|
/** Create an array of all views mapped to some particular value. */
|
|
@@ -27307,7 +27318,10 @@ class SequenceView {
|
|
|
27307
27318
|
return bytes_BytesBlob.blobFrom(this.decoder.source.subarray(this.initialDecoderOffset, this.decoder.bytesRead()));
|
|
27308
27319
|
}
|
|
27309
27320
|
decodeUpTo(index) {
|
|
27310
|
-
debug_check
|
|
27321
|
+
debug_check `
|
|
27322
|
+
${this.lastDecodedIdx < index}
|
|
27323
|
+
Unjustified call to 'decodeUpTo' - the index (${index}) is already decoded (${this.lastDecodedIdx}).
|
|
27324
|
+
`;
|
|
27311
27325
|
let lastItem = this.cache.get(this.lastDecodedIdx);
|
|
27312
27326
|
const skipper = new Skipper(this.decoder);
|
|
27313
27327
|
// now skip all of the fields and further populate the cache.
|
|
@@ -27322,8 +27336,10 @@ class SequenceView {
|
|
|
27322
27336
|
this.cache.set(i, lastItem);
|
|
27323
27337
|
this.lastDecodedIdx = i;
|
|
27324
27338
|
}
|
|
27325
|
-
|
|
27326
|
-
|
|
27339
|
+
if (lastItem === undefined) {
|
|
27340
|
+
throw new Error("Last item must be set, since the loop turns at least once.");
|
|
27341
|
+
}
|
|
27342
|
+
return lastItem;
|
|
27327
27343
|
}
|
|
27328
27344
|
}
|
|
27329
27345
|
|
|
@@ -27356,7 +27372,10 @@ const TYPICAL_DICTIONARY_LENGTH = 32;
|
|
|
27356
27372
|
*/
|
|
27357
27373
|
function readonlyArray(desc) {
|
|
27358
27374
|
return desc.convert((x) => {
|
|
27359
|
-
debug_check
|
|
27375
|
+
debug_check `
|
|
27376
|
+
${Array.isArray(x)}
|
|
27377
|
+
Non-arrays are not supported as 'readonly': got ${typeof x}, ${x}
|
|
27378
|
+
`;
|
|
27360
27379
|
// NOTE [ToDr] This assumption is incorrect in general, but it's documented
|
|
27361
27380
|
// in the general note. We avoid `.slice()` the array for performance reasons.
|
|
27362
27381
|
return x;
|
|
@@ -28343,7 +28362,7 @@ const BLS_KEY_BYTES = 144;
|
|
|
28343
28362
|
/** Derive a Bandersnatch public key from a seed. */
|
|
28344
28363
|
function bandersnatch_publicKey(seed) {
|
|
28345
28364
|
const key = bandersnatch.derive_public_key(seed);
|
|
28346
|
-
check
|
|
28365
|
+
check `${key[0] === 0} Invalid Bandersnatch public key derived from seed`;
|
|
28347
28366
|
return Bytes.fromBlob(key.subarray(1), BANDERSNATCH_KEY_BYTES).asOpaque();
|
|
28348
28367
|
}
|
|
28349
28368
|
|
|
@@ -28831,7 +28850,7 @@ async function ed25519_verify(input) {
|
|
|
28831
28850
|
data.set(signature.raw, offset);
|
|
28832
28851
|
offset += ED25519_SIGNATURE_BYTES;
|
|
28833
28852
|
const messageLength = message.length;
|
|
28834
|
-
debug_check
|
|
28853
|
+
debug_check `${messageLength < 256} Message needs to be shorter than 256 bytes. Got: ${messageLength}`;
|
|
28835
28854
|
data[offset] = messageLength;
|
|
28836
28855
|
offset += 1;
|
|
28837
28856
|
data.set(message.raw, offset);
|
|
@@ -28915,7 +28934,7 @@ class PageAllocator {
|
|
|
28915
28934
|
// TODO [ToDr] Benchmark the performance!
|
|
28916
28935
|
constructor(hashesPerPage) {
|
|
28917
28936
|
this.hashesPerPage = hashesPerPage;
|
|
28918
|
-
check
|
|
28937
|
+
check `${hashesPerPage > 0 && hashesPerPage >>> 0 === hashesPerPage} Expected a non-zero integer.`;
|
|
28919
28938
|
this.resetPage();
|
|
28920
28939
|
}
|
|
28921
28940
|
resetPage() {
|
|
@@ -29212,8 +29231,8 @@ class MultiMap {
|
|
|
29212
29231
|
* if needed.
|
|
29213
29232
|
*/
|
|
29214
29233
|
constructor(keysLength, keyMappers) {
|
|
29215
|
-
check
|
|
29216
|
-
check
|
|
29234
|
+
check `${keysLength > 0} Keys cannot be empty.`;
|
|
29235
|
+
check `${keyMappers === undefined || keyMappers.length === keysLength} Incorrect number of key mappers given!`;
|
|
29217
29236
|
this.data = new Map();
|
|
29218
29237
|
this.keyMappers = keyMappers === undefined ? Array(keysLength).fill(null) : keyMappers;
|
|
29219
29238
|
}
|
|
@@ -29314,7 +29333,7 @@ class FixedSizeArray extends Array {
|
|
|
29314
29333
|
this.fixedLength = this.length;
|
|
29315
29334
|
}
|
|
29316
29335
|
static new(data, len) {
|
|
29317
|
-
debug_check
|
|
29336
|
+
debug_check `${data.length === len} Expected an array of size: ${len}, got: ${data.length}`;
|
|
29318
29337
|
const arr = new FixedSizeArray(len);
|
|
29319
29338
|
for (let i = 0; i < len; i++) {
|
|
29320
29339
|
arr[i] = data[i];
|
|
@@ -29448,7 +29467,7 @@ class SortedArray {
|
|
|
29448
29467
|
}
|
|
29449
29468
|
/** Create a new SortedSet from two sorted collections. */
|
|
29450
29469
|
static fromTwoSortedCollections(first, second) {
|
|
29451
|
-
debug_check
|
|
29470
|
+
debug_check `${first.comparator === second.comparator} Cannot merge arrays if they do not use the same comparator`;
|
|
29452
29471
|
const comparator = first.comparator;
|
|
29453
29472
|
const arr1 = first.array;
|
|
29454
29473
|
const arr1Length = arr1.length;
|
|
@@ -29568,7 +29587,7 @@ class sorted_set_SortedSet extends SortedArray {
|
|
|
29568
29587
|
}
|
|
29569
29588
|
/** Create a new SortedSet from two sorted collections. */
|
|
29570
29589
|
static fromTwoSortedCollections(first, second) {
|
|
29571
|
-
debug_check
|
|
29590
|
+
debug_check `${first.comparator === second.comparator} Cannot merge arrays if they do not use the same comparator`;
|
|
29572
29591
|
const comparator = first.comparator;
|
|
29573
29592
|
if (first.length === 0) {
|
|
29574
29593
|
return sorted_set_SortedSet.fromSortedArray(comparator, second.array);
|
|
@@ -30589,7 +30608,10 @@ const tryAsCoreIndex = (v) => opaque_asOpaqueType(numbers_tryAsU16(v));
|
|
|
30589
30608
|
/** Attempt to convert a number into `Epoch`. */
|
|
30590
30609
|
const tryAsEpoch = (v) => asOpaqueType(tryAsU32(v));
|
|
30591
30610
|
function tryAsPerValidator(array, spec) {
|
|
30592
|
-
debug_check
|
|
30611
|
+
debug_check `
|
|
30612
|
+
${array.length === spec.validatorsCount}
|
|
30613
|
+
Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}
|
|
30614
|
+
`;
|
|
30593
30615
|
return sized_array_asKnownSize(array);
|
|
30594
30616
|
}
|
|
30595
30617
|
const codecPerValidator = (val) => codecWithContext((context) => {
|
|
@@ -30598,7 +30620,10 @@ const codecPerValidator = (val) => codecWithContext((context) => {
|
|
|
30598
30620
|
});
|
|
30599
30621
|
});
|
|
30600
30622
|
function tryAsPerEpochBlock(array, spec) {
|
|
30601
|
-
debug_check
|
|
30623
|
+
debug_check `
|
|
30624
|
+
${array.length === spec.epochLength}
|
|
30625
|
+
Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}
|
|
30626
|
+
`;
|
|
30602
30627
|
return sized_array_asKnownSize(array);
|
|
30603
30628
|
}
|
|
30604
30629
|
const codecPerEpochBlock = (val) => codecWithContext((context) => {
|
|
@@ -30869,9 +30894,14 @@ class WorkItem extends WithDebug {
|
|
|
30869
30894
|
|
|
30870
30895
|
|
|
30871
30896
|
|
|
30897
|
+
|
|
30872
30898
|
/** Verify the value is within the `WorkItemsCount` bounds. */
|
|
30873
30899
|
function tryAsWorkItemsCount(len) {
|
|
30874
|
-
|
|
30900
|
+
debug_check `
|
|
30901
|
+
${len >= MIN_NUMBER_OF_WORK_ITEMS && len <= work_package_MAX_NUMBER_OF_WORK_ITEMS}
|
|
30902
|
+
WorkItemsCount: Expected '${MIN_NUMBER_OF_WORK_ITEMS} <= count <= ${work_package_MAX_NUMBER_OF_WORK_ITEMS}' got ${len}
|
|
30903
|
+
`;
|
|
30904
|
+
return tryAsU8(len);
|
|
30875
30905
|
}
|
|
30876
30906
|
/** Minimal number of work items in the work package or results in work report. */
|
|
30877
30907
|
const MIN_NUMBER_OF_WORK_ITEMS = 1;
|
|
@@ -32844,7 +32874,10 @@ class AvailabilityAssignment extends WithDebug {
|
|
|
32844
32874
|
|
|
32845
32875
|
/** Check if given array has correct length before casting to the opaque type. */
|
|
32846
32876
|
function tryAsPerCore(array, spec) {
|
|
32847
|
-
debug_check
|
|
32877
|
+
debug_check `
|
|
32878
|
+
${array.length === spec.coresCount}
|
|
32879
|
+
Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
|
|
32880
|
+
`;
|
|
32848
32881
|
return opaque_asOpaqueType(array);
|
|
32849
32882
|
}
|
|
32850
32883
|
const codecPerCore = (val) => codecWithContext((context) => {
|
|
@@ -34095,7 +34128,7 @@ class InMemoryState extends WithDebug {
|
|
|
34095
34128
|
}
|
|
34096
34129
|
removeServices(servicesRemoved) {
|
|
34097
34130
|
for (const serviceId of servicesRemoved ?? []) {
|
|
34098
|
-
debug_check
|
|
34131
|
+
debug_check `${this.services.has(serviceId)} Attempting to remove non-existing service: ${serviceId}`;
|
|
34099
34132
|
this.services.delete(serviceId);
|
|
34100
34133
|
}
|
|
34101
34134
|
}
|
|
@@ -34112,7 +34145,10 @@ class InMemoryState extends WithDebug {
|
|
|
34112
34145
|
}
|
|
34113
34146
|
else if (kind === state_update_UpdateStorageKind.Remove) {
|
|
34114
34147
|
const { key } = action;
|
|
34115
|
-
debug_check
|
|
34148
|
+
debug_check `
|
|
34149
|
+
${service.data.storage.has(key.toString())}
|
|
34150
|
+
Attempting to remove non-existing storage item at ${serviceId}: ${action.key}
|
|
34151
|
+
`;
|
|
34116
34152
|
service.data.storage.delete(key.toString());
|
|
34117
34153
|
}
|
|
34118
34154
|
else {
|
|
@@ -34795,12 +34831,12 @@ class nodes_TrieNode {
|
|
|
34795
34831
|
}
|
|
34796
34832
|
/** View this node as a branch node */
|
|
34797
34833
|
asBranchNode() {
|
|
34798
|
-
debug_check
|
|
34834
|
+
debug_check `${this.getNodeType() === nodes_NodeType.Branch} not a branch!`;
|
|
34799
34835
|
return new BranchNode(this);
|
|
34800
34836
|
}
|
|
34801
34837
|
/** View this node as a leaf node */
|
|
34802
34838
|
asLeafNode() {
|
|
34803
|
-
debug_check
|
|
34839
|
+
debug_check `${this.getNodeType() !== nodes_NodeType.Branch} not a leaf!`;
|
|
34804
34840
|
return new LeafNode(this);
|
|
34805
34841
|
}
|
|
34806
34842
|
toString() {
|
|
@@ -35288,7 +35324,7 @@ function createSubtreeForBothLeaves(traversedPath, nodes, leafToReplace, leaf) {
|
|
|
35288
35324
|
* Return a single bit from `key` located at `bitIndex`.
|
|
35289
35325
|
*/
|
|
35290
35326
|
function getBit(key, bitIndex) {
|
|
35291
|
-
debug_check
|
|
35327
|
+
debug_check `${bitIndex < TRUNCATED_KEY_BITS} invalid bit index passed ${bitIndex}`;
|
|
35292
35328
|
const byte = bitIndex >>> 3;
|
|
35293
35329
|
const bit = bitIndex - (byte << 3);
|
|
35294
35330
|
const mask = 0b10_00_00_00 >>> bit;
|
|
@@ -36295,7 +36331,7 @@ class TypedPort {
|
|
|
36295
36331
|
* Send a response given the worker that has previously requested something.
|
|
36296
36332
|
*/
|
|
36297
36333
|
respond(localState, request, data, transferList) {
|
|
36298
|
-
debug_check
|
|
36334
|
+
debug_check `${request.kind === "request"}`;
|
|
36299
36335
|
this.postMessage({
|
|
36300
36336
|
kind: "response",
|
|
36301
36337
|
id: request.id,
|
|
@@ -36326,10 +36362,11 @@ class TypedPort {
|
|
|
36326
36362
|
throw new Error(`Invalid message: ${JSON.stringify(msg)}.`);
|
|
36327
36363
|
}
|
|
36328
36364
|
switch (msg.kind) {
|
|
36329
|
-
case "response":
|
|
36330
|
-
debug_check
|
|
36365
|
+
case "response": {
|
|
36366
|
+
debug_check `${this.responseListeners.eventNames().indexOf(reqEvent(msg.id)) !== -1}`;
|
|
36331
36367
|
this.responseListeners.emit(reqEvent(msg.id), null, msg.data, msg.name, msg.localState, msg);
|
|
36332
36368
|
break;
|
|
36369
|
+
}
|
|
36333
36370
|
case "signal":
|
|
36334
36371
|
this.listeners.emit("signal", msg.name, msg.data, msg.localState, msg);
|
|
36335
36372
|
break;
|
|
@@ -36544,9 +36581,9 @@ class MessageChannelStateMachine {
|
|
|
36544
36581
|
const promise = new Promise((resolve, reject) => {
|
|
36545
36582
|
parentPort.once("message", (value) => {
|
|
36546
36583
|
try {
|
|
36547
|
-
debug_check
|
|
36548
|
-
debug_check
|
|
36549
|
-
debug_check
|
|
36584
|
+
debug_check `${value.kind === "request"} The initial message should be a request with channel.`;
|
|
36585
|
+
debug_check `${value.name === CHANNEL_MESSAGE}`;
|
|
36586
|
+
debug_check `${value.data instanceof external_node_worker_threads_namespaceObject.MessagePort}`;
|
|
36550
36587
|
const port = new TypedPort(value.data);
|
|
36551
36588
|
port.respond(machine.currentState().stateName, value, Ok);
|
|
36552
36589
|
resolve(port);
|
|
@@ -36626,7 +36663,7 @@ class StateMachine {
|
|
|
36626
36663
|
/** Get state object by name. */
|
|
36627
36664
|
getState(name) {
|
|
36628
36665
|
const state = this.allStates.get(name);
|
|
36629
|
-
debug_check
|
|
36666
|
+
debug_check `${state !== undefined} Unable to retrieve state object for ${name}.`;
|
|
36630
36667
|
return state;
|
|
36631
36668
|
}
|
|
36632
36669
|
/** Get the currently active state object. */
|