@typeberry/lib 0.1.2 → 0.1.3-135961b
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 +595 -92
- package/index.d.ts +1276 -664
- package/index.js +576 -74
- package/package.json +1 -1
- package/bin/lib/index.d.ts +0 -29
- package/configs/index.d.ts +0 -76
package/index.cjs
CHANGED
|
@@ -563,7 +563,7 @@ function isResult(x) {
|
|
|
563
563
|
* as an afterthought.
|
|
564
564
|
*/
|
|
565
565
|
|
|
566
|
-
var index$
|
|
566
|
+
var index$u = /*#__PURE__*/Object.freeze({
|
|
567
567
|
__proto__: null,
|
|
568
568
|
get CURRENT_SUITE () { return CURRENT_SUITE; },
|
|
569
569
|
get CURRENT_VERSION () { return CURRENT_VERSION; },
|
|
@@ -717,7 +717,7 @@ class Ordering {
|
|
|
717
717
|
}
|
|
718
718
|
}
|
|
719
719
|
|
|
720
|
-
var index$
|
|
720
|
+
var index$t = /*#__PURE__*/Object.freeze({
|
|
721
721
|
__proto__: null,
|
|
722
722
|
Ordering: Ordering
|
|
723
723
|
});
|
|
@@ -968,7 +968,7 @@ function u8ArraySameLengthEqual(self, other) {
|
|
|
968
968
|
}
|
|
969
969
|
const bytesBlobComparator = (a, b) => a.compare(b);
|
|
970
970
|
|
|
971
|
-
var index$
|
|
971
|
+
var index$s = /*#__PURE__*/Object.freeze({
|
|
972
972
|
__proto__: null,
|
|
973
973
|
BitVec: BitVec,
|
|
974
974
|
Bytes: Bytes,
|
|
@@ -1070,7 +1070,7 @@ const minU64 = (a, ...values) => values.reduce((min, value) => (value > min ? mi
|
|
|
1070
1070
|
/** Get the biggest value between U64 a and values given as input parameters. */
|
|
1071
1071
|
const maxU64 = (a, ...values) => values.reduce((max, value) => (value < max ? max : value), a);
|
|
1072
1072
|
|
|
1073
|
-
var index$
|
|
1073
|
+
var index$r = /*#__PURE__*/Object.freeze({
|
|
1074
1074
|
__proto__: null,
|
|
1075
1075
|
isU16: isU16,
|
|
1076
1076
|
isU32: isU32,
|
|
@@ -1947,13 +1947,15 @@ function validateLength(range, length, context) {
|
|
|
1947
1947
|
|
|
1948
1948
|
/** A caching wrapper for either object or sequence item. */
|
|
1949
1949
|
class ViewField {
|
|
1950
|
+
name;
|
|
1950
1951
|
getView;
|
|
1951
1952
|
getValue;
|
|
1952
1953
|
getEncoded;
|
|
1953
1954
|
cachedValue;
|
|
1954
1955
|
cachedView;
|
|
1955
1956
|
cachedBlob;
|
|
1956
|
-
constructor(getView, getValue, getEncoded) {
|
|
1957
|
+
constructor(name, getView, getValue, getEncoded) {
|
|
1958
|
+
this.name = name;
|
|
1957
1959
|
this.getView = getView;
|
|
1958
1960
|
this.getValue = getValue;
|
|
1959
1961
|
this.getEncoded = getEncoded;
|
|
@@ -1979,6 +1981,9 @@ class ViewField {
|
|
|
1979
1981
|
}
|
|
1980
1982
|
return this.cachedBlob;
|
|
1981
1983
|
}
|
|
1984
|
+
toString() {
|
|
1985
|
+
return `ViewField<${this.name}>`;
|
|
1986
|
+
}
|
|
1982
1987
|
}
|
|
1983
1988
|
/**
|
|
1984
1989
|
* A base class for all the lazy views.
|
|
@@ -2053,7 +2058,7 @@ class ObjectView {
|
|
|
2053
2058
|
const fieldDecoder = skipper.decoder.clone();
|
|
2054
2059
|
const field = this.descriptorsKeys[i];
|
|
2055
2060
|
const type = this.descriptors[field];
|
|
2056
|
-
lastItem = new ViewField(() => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2061
|
+
lastItem = new ViewField(`${this.toString()}.${String(field)}`, () => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2057
2062
|
// skip the field
|
|
2058
2063
|
type.skip(skipper);
|
|
2059
2064
|
// cache data
|
|
@@ -2065,6 +2070,9 @@ class ObjectView {
|
|
|
2065
2070
|
}
|
|
2066
2071
|
return lastItem;
|
|
2067
2072
|
}
|
|
2073
|
+
toString() {
|
|
2074
|
+
return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
|
|
2075
|
+
}
|
|
2068
2076
|
}
|
|
2069
2077
|
/**
|
|
2070
2078
|
* A lazy-evaluated decoder of a sequence.
|
|
@@ -2153,7 +2161,7 @@ class SequenceView {
|
|
|
2153
2161
|
// create new cached prop
|
|
2154
2162
|
const fieldDecoder = skipper.decoder.clone();
|
|
2155
2163
|
const type = this.descriptor;
|
|
2156
|
-
lastItem = new ViewField(() => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2164
|
+
lastItem = new ViewField(`${this.toString()}[${index}]`, () => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2157
2165
|
// skip the field
|
|
2158
2166
|
type.skip(skipper);
|
|
2159
2167
|
// cache data
|
|
@@ -2165,6 +2173,9 @@ class SequenceView {
|
|
|
2165
2173
|
}
|
|
2166
2174
|
return lastItem;
|
|
2167
2175
|
}
|
|
2176
|
+
toString() {
|
|
2177
|
+
return `SequenceView<${this.descriptor.name}>(cache: ${this.cache.size})`;
|
|
2178
|
+
}
|
|
2168
2179
|
}
|
|
2169
2180
|
|
|
2170
2181
|
/**
|
|
@@ -2480,7 +2491,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
|
|
|
2480
2491
|
}, skipper);
|
|
2481
2492
|
}
|
|
2482
2493
|
|
|
2483
|
-
var index$
|
|
2494
|
+
var index$q = /*#__PURE__*/Object.freeze({
|
|
2484
2495
|
__proto__: null,
|
|
2485
2496
|
Decoder: Decoder,
|
|
2486
2497
|
Descriptor: Descriptor,
|
|
@@ -4919,7 +4930,7 @@ var keccak = /*#__PURE__*/Object.freeze({
|
|
|
4919
4930
|
hashBlobs: hashBlobs
|
|
4920
4931
|
});
|
|
4921
4932
|
|
|
4922
|
-
var index$
|
|
4933
|
+
var index$p = /*#__PURE__*/Object.freeze({
|
|
4923
4934
|
__proto__: null,
|
|
4924
4935
|
HASH_SIZE: HASH_SIZE,
|
|
4925
4936
|
PageAllocator: PageAllocator,
|
|
@@ -4985,7 +4996,7 @@ var keyDerivation = /*#__PURE__*/Object.freeze({
|
|
|
4985
4996
|
trivialSeed: trivialSeed
|
|
4986
4997
|
});
|
|
4987
4998
|
|
|
4988
|
-
var index$
|
|
4999
|
+
var index$o = /*#__PURE__*/Object.freeze({
|
|
4989
5000
|
__proto__: null,
|
|
4990
5001
|
BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
|
|
4991
5002
|
BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
|
|
@@ -5589,7 +5600,7 @@ class TruncatedHashDictionary {
|
|
|
5589
5600
|
}
|
|
5590
5601
|
}
|
|
5591
5602
|
|
|
5592
|
-
var index$
|
|
5603
|
+
var index$n = /*#__PURE__*/Object.freeze({
|
|
5593
5604
|
__proto__: null,
|
|
5594
5605
|
FixedSizeArray: FixedSizeArray,
|
|
5595
5606
|
HashDictionary: HashDictionary,
|
|
@@ -5784,7 +5795,7 @@ class Bootnode {
|
|
|
5784
5795
|
}
|
|
5785
5796
|
}
|
|
5786
5797
|
|
|
5787
|
-
var index$
|
|
5798
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
5788
5799
|
__proto__: null,
|
|
5789
5800
|
Bootnode: Bootnode,
|
|
5790
5801
|
ChainSpec: ChainSpec,
|
|
@@ -5957,6 +5968,40 @@ var assurances = /*#__PURE__*/Object.freeze({
|
|
|
5957
5968
|
assurancesExtrinsicCodec: assurancesExtrinsicCodec
|
|
5958
5969
|
});
|
|
5959
5970
|
|
|
5971
|
+
/** Attempt to convert a number into `TimeSlot`. */
|
|
5972
|
+
const tryAsTimeSlot = (v) => asOpaqueType(tryAsU32(v));
|
|
5973
|
+
/** Attempt to convert a number into `ValidatorIndex`. */
|
|
5974
|
+
const tryAsValidatorIndex = (v) => asOpaqueType(tryAsU16(v));
|
|
5975
|
+
/** Attempt to convert a number into `ServiceId`. */
|
|
5976
|
+
const tryAsServiceId = (v) => asOpaqueType(tryAsU32(v));
|
|
5977
|
+
const tryAsServiceGas = (v) => asOpaqueType(tryAsU64(v));
|
|
5978
|
+
/** Attempt to convert a number into `CoreIndex`. */
|
|
5979
|
+
const tryAsCoreIndex = (v) => asOpaqueType(tryAsU16(v));
|
|
5980
|
+
/** Attempt to convert a number into `Epoch`. */
|
|
5981
|
+
const tryAsEpoch = (v) => asOpaqueType(tryAsU32(v));
|
|
5982
|
+
function tryAsPerValidator(array, spec) {
|
|
5983
|
+
check `
|
|
5984
|
+
${array.length === spec.validatorsCount}
|
|
5985
|
+
Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}
|
|
5986
|
+
`;
|
|
5987
|
+
return asKnownSize(array);
|
|
5988
|
+
}
|
|
5989
|
+
const codecPerValidator = (val) => codecWithContext((context) => {
|
|
5990
|
+
return codecKnownSizeArray(val, {
|
|
5991
|
+
fixedLength: context.validatorsCount,
|
|
5992
|
+
});
|
|
5993
|
+
});
|
|
5994
|
+
function tryAsPerEpochBlock(array, spec) {
|
|
5995
|
+
check `
|
|
5996
|
+
${array.length === spec.epochLength}
|
|
5997
|
+
Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}
|
|
5998
|
+
`;
|
|
5999
|
+
return asKnownSize(array);
|
|
6000
|
+
}
|
|
6001
|
+
const codecPerEpochBlock = (val) => codecWithContext((context) => {
|
|
6002
|
+
return codecKnownSizeArray(val, { fixedLength: context.epochLength });
|
|
6003
|
+
});
|
|
6004
|
+
|
|
5960
6005
|
/**
|
|
5961
6006
|
* Proof of signing a contradictory [`Judgement`] of a work report.
|
|
5962
6007
|
*/
|
|
@@ -6148,40 +6193,6 @@ var disputes = /*#__PURE__*/Object.freeze({
|
|
|
6148
6193
|
Verdict: Verdict
|
|
6149
6194
|
});
|
|
6150
6195
|
|
|
6151
|
-
/** Attempt to convert a number into `TimeSlot`. */
|
|
6152
|
-
const tryAsTimeSlot = (v) => asOpaqueType(tryAsU32(v));
|
|
6153
|
-
/** Attempt to convert a number into `ValidatorIndex`. */
|
|
6154
|
-
const tryAsValidatorIndex = (v) => asOpaqueType(tryAsU16(v));
|
|
6155
|
-
/** Attempt to convert a number into `ServiceId`. */
|
|
6156
|
-
const tryAsServiceId = (v) => asOpaqueType(tryAsU32(v));
|
|
6157
|
-
const tryAsServiceGas = (v) => asOpaqueType(tryAsU64(v));
|
|
6158
|
-
/** Attempt to convert a number into `CoreIndex`. */
|
|
6159
|
-
const tryAsCoreIndex = (v) => asOpaqueType(tryAsU16(v));
|
|
6160
|
-
/** Attempt to convert a number into `Epoch`. */
|
|
6161
|
-
const tryAsEpoch = (v) => asOpaqueType(tryAsU32(v));
|
|
6162
|
-
function tryAsPerValidator(array, spec) {
|
|
6163
|
-
check `
|
|
6164
|
-
${array.length === spec.validatorsCount}
|
|
6165
|
-
Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}
|
|
6166
|
-
`;
|
|
6167
|
-
return asKnownSize(array);
|
|
6168
|
-
}
|
|
6169
|
-
const codecPerValidator = (val) => codecWithContext((context) => {
|
|
6170
|
-
return codecKnownSizeArray(val, {
|
|
6171
|
-
fixedLength: context.validatorsCount,
|
|
6172
|
-
});
|
|
6173
|
-
});
|
|
6174
|
-
function tryAsPerEpochBlock(array, spec) {
|
|
6175
|
-
check `
|
|
6176
|
-
${array.length === spec.epochLength}
|
|
6177
|
-
Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}
|
|
6178
|
-
`;
|
|
6179
|
-
return asKnownSize(array);
|
|
6180
|
-
}
|
|
6181
|
-
const codecPerEpochBlock = (val) => codecWithContext((context) => {
|
|
6182
|
-
return codecKnownSizeArray(val, { fixedLength: context.epochLength });
|
|
6183
|
-
});
|
|
6184
|
-
|
|
6185
6196
|
/**
|
|
6186
6197
|
* Mapping between work package hash and root hash of it's exports.
|
|
6187
6198
|
*
|
|
@@ -7260,8 +7271,26 @@ class Block extends WithDebug {
|
|
|
7260
7271
|
this.extrinsic = extrinsic;
|
|
7261
7272
|
}
|
|
7262
7273
|
}
|
|
7274
|
+
function emptyBlock(slot = tryAsTimeSlot(0)) {
|
|
7275
|
+
const header = Header.empty();
|
|
7276
|
+
header.timeSlotIndex = slot;
|
|
7277
|
+
return Block.create({
|
|
7278
|
+
header,
|
|
7279
|
+
extrinsic: Extrinsic.create({
|
|
7280
|
+
tickets: asKnownSize([]),
|
|
7281
|
+
preimages: [],
|
|
7282
|
+
assurances: asKnownSize([]),
|
|
7283
|
+
guarantees: asKnownSize([]),
|
|
7284
|
+
disputes: {
|
|
7285
|
+
verdicts: [],
|
|
7286
|
+
culprits: [],
|
|
7287
|
+
faults: [],
|
|
7288
|
+
},
|
|
7289
|
+
}),
|
|
7290
|
+
});
|
|
7291
|
+
}
|
|
7263
7292
|
|
|
7264
|
-
var index$
|
|
7293
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
7265
7294
|
__proto__: null,
|
|
7266
7295
|
Block: Block,
|
|
7267
7296
|
EpochMarker: EpochMarker,
|
|
@@ -7276,6 +7305,7 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
7276
7305
|
codecPerValidator: codecPerValidator,
|
|
7277
7306
|
codecUtils: codec,
|
|
7278
7307
|
disputes: disputes,
|
|
7308
|
+
emptyBlock: emptyBlock,
|
|
7279
7309
|
encodeUnsealedHeader: encodeUnsealedHeader,
|
|
7280
7310
|
guarantees: guarantees,
|
|
7281
7311
|
headerViewWithHashCodec: headerViewWithHashCodec,
|
|
@@ -7516,7 +7546,7 @@ var json;
|
|
|
7516
7546
|
json.object = object;
|
|
7517
7547
|
})(json || (json = {}));
|
|
7518
7548
|
|
|
7519
|
-
var index$
|
|
7549
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
7520
7550
|
__proto__: null,
|
|
7521
7551
|
get json () { return json; },
|
|
7522
7552
|
parseFromJson: parseFromJson
|
|
@@ -7786,7 +7816,7 @@ const blockFromJson = (spec) => json.object({
|
|
|
7786
7816
|
extrinsic: getExtrinsicFromJson(spec),
|
|
7787
7817
|
}, ({ header, extrinsic }) => Block.create({ header, extrinsic }));
|
|
7788
7818
|
|
|
7789
|
-
var index$
|
|
7819
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
7790
7820
|
__proto__: null,
|
|
7791
7821
|
blockFromJson: blockFromJson,
|
|
7792
7822
|
disputesExtrinsicFromJson: disputesExtrinsicFromJson,
|
|
@@ -8052,8 +8082,8 @@ function print(level, levelAndName, strings, data) {
|
|
|
8052
8082
|
return;
|
|
8053
8083
|
}
|
|
8054
8084
|
const lvlText = Level[level].padEnd(5);
|
|
8055
|
-
const val = strings.map((v, idx) => `${v}${data[idx]}`);
|
|
8056
|
-
const msg = `${lvlText} [${levelAndName[1]}] ${val}`;
|
|
8085
|
+
const val = strings.map((v, idx) => `${v}${idx < data.length ? data[idx] : ""}`);
|
|
8086
|
+
const msg = `${lvlText} [${levelAndName[1]}] ${val.join("")}`;
|
|
8057
8087
|
if (level === Level.WARN) {
|
|
8058
8088
|
console.warn(msg);
|
|
8059
8089
|
}
|
|
@@ -8284,7 +8314,7 @@ class Logger {
|
|
|
8284
8314
|
}
|
|
8285
8315
|
}
|
|
8286
8316
|
|
|
8287
|
-
var index$
|
|
8317
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
8288
8318
|
__proto__: null,
|
|
8289
8319
|
get Level () { return Level; },
|
|
8290
8320
|
Logger: Logger,
|
|
@@ -8307,7 +8337,7 @@ class AuthorshipOptions {
|
|
|
8307
8337
|
}
|
|
8308
8338
|
}
|
|
8309
8339
|
|
|
8310
|
-
const logger$
|
|
8340
|
+
const logger$5 = Logger.new(undefined, "config");
|
|
8311
8341
|
/** Development config. Will accept unsealed blocks for now. */
|
|
8312
8342
|
const DEV_CONFIG = "dev";
|
|
8313
8343
|
/** Default config file. */
|
|
@@ -8366,15 +8396,15 @@ class NodeConfiguration {
|
|
|
8366
8396
|
}
|
|
8367
8397
|
function loadConfig(configPath) {
|
|
8368
8398
|
if (configPath === DEFAULT_CONFIG) {
|
|
8369
|
-
logger$
|
|
8399
|
+
logger$5.log `🔧 Loading DEFAULT config`;
|
|
8370
8400
|
return parseFromJson(configs.default, NodeConfiguration.fromJson);
|
|
8371
8401
|
}
|
|
8372
8402
|
if (configPath === DEV_CONFIG) {
|
|
8373
|
-
logger$
|
|
8403
|
+
logger$5.log `🔧 Loading DEV config`;
|
|
8374
8404
|
return parseFromJson(configs.dev, NodeConfiguration.fromJson);
|
|
8375
8405
|
}
|
|
8376
8406
|
try {
|
|
8377
|
-
logger$
|
|
8407
|
+
logger$5.log `🔧 Loading config from ${configPath}`;
|
|
8378
8408
|
const configFile = fs.readFileSync(configPath, "utf8");
|
|
8379
8409
|
const parsed = JSON.parse(configFile);
|
|
8380
8410
|
return parseFromJson(parsed, NodeConfiguration.fromJson);
|
|
@@ -8384,7 +8414,7 @@ function loadConfig(configPath) {
|
|
|
8384
8414
|
}
|
|
8385
8415
|
}
|
|
8386
8416
|
|
|
8387
|
-
var index$
|
|
8417
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
8388
8418
|
__proto__: null,
|
|
8389
8419
|
DEFAULT_CONFIG: DEFAULT_CONFIG,
|
|
8390
8420
|
DEV_CONFIG: DEV_CONFIG,
|
|
@@ -8701,6 +8731,10 @@ class DisputesRecords {
|
|
|
8701
8731
|
static create({ goodSet, badSet, wonkySet, punishSet }) {
|
|
8702
8732
|
return new DisputesRecords(goodSet, badSet, wonkySet, punishSet);
|
|
8703
8733
|
}
|
|
8734
|
+
goodSetDict;
|
|
8735
|
+
badSetDict;
|
|
8736
|
+
wonkySetDict;
|
|
8737
|
+
punishSetDict;
|
|
8704
8738
|
constructor(
|
|
8705
8739
|
/** `goodSet`: all work-reports hashes which were judged to be correct */
|
|
8706
8740
|
goodSet,
|
|
@@ -8714,6 +8748,18 @@ class DisputesRecords {
|
|
|
8714
8748
|
this.badSet = badSet;
|
|
8715
8749
|
this.wonkySet = wonkySet;
|
|
8716
8750
|
this.punishSet = punishSet;
|
|
8751
|
+
this.goodSetDict = HashSet.from(goodSet.array);
|
|
8752
|
+
this.badSetDict = HashSet.from(badSet.array);
|
|
8753
|
+
this.wonkySetDict = HashSet.from(wonkySet.array);
|
|
8754
|
+
this.punishSetDict = HashSet.from(punishSet.array);
|
|
8755
|
+
}
|
|
8756
|
+
asDictionaries() {
|
|
8757
|
+
return {
|
|
8758
|
+
goodSet: this.goodSetDict,
|
|
8759
|
+
badSet: this.badSetDict,
|
|
8760
|
+
wonkySet: this.wonkySetDict,
|
|
8761
|
+
punishSet: this.punishSetDict,
|
|
8762
|
+
};
|
|
8717
8763
|
}
|
|
8718
8764
|
static fromSortedArrays({ goodSet, badSet, wonkySet, punishSet, }) {
|
|
8719
8765
|
return new DisputesRecords(SortedSet.fromSortedArray(hashComparator, goodSet), SortedSet.fromSortedArray(hashComparator, badSet), SortedSet.fromSortedArray(hashComparator, wonkySet), SortedSet.fromSortedArray(hashComparator, punishSet));
|
|
@@ -10050,7 +10096,7 @@ const serviceDataCodec = codec$1.dictionary(codec$1.u32.asOpaque(), serviceEntri
|
|
|
10050
10096
|
sortKeys: (a, b) => a - b,
|
|
10051
10097
|
});
|
|
10052
10098
|
|
|
10053
|
-
var index$
|
|
10099
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
10054
10100
|
__proto__: null,
|
|
10055
10101
|
AccumulationOutput: AccumulationOutput,
|
|
10056
10102
|
AutoAccumulate: AutoAccumulate,
|
|
@@ -11060,7 +11106,7 @@ const bitLookup = [
|
|
|
11060
11106
|
[0b00000000, 8],
|
|
11061
11107
|
];
|
|
11062
11108
|
|
|
11063
|
-
var index$
|
|
11109
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
11064
11110
|
__proto__: null,
|
|
11065
11111
|
BranchNode: BranchNode,
|
|
11066
11112
|
InMemoryTrie: InMemoryTrie,
|
|
@@ -11406,7 +11452,7 @@ function loadState(spec, entries) {
|
|
|
11406
11452
|
* hashmap of `key -> value` entries.
|
|
11407
11453
|
*/
|
|
11408
11454
|
|
|
11409
|
-
var index$
|
|
11455
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
11410
11456
|
__proto__: null,
|
|
11411
11457
|
SerializedService: SerializedService,
|
|
11412
11458
|
SerializedState: SerializedState,
|
|
@@ -11692,7 +11738,7 @@ class InMemoryStates {
|
|
|
11692
11738
|
}
|
|
11693
11739
|
}
|
|
11694
11740
|
|
|
11695
|
-
var index$
|
|
11741
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
11696
11742
|
__proto__: null,
|
|
11697
11743
|
InMemoryBlocks: InMemoryBlocks,
|
|
11698
11744
|
InMemoryStates: InMemoryStates,
|
|
@@ -12054,7 +12100,7 @@ const initEc = async () => {
|
|
|
12054
12100
|
await init.reedSolomon();
|
|
12055
12101
|
};
|
|
12056
12102
|
|
|
12057
|
-
var index$
|
|
12103
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
12058
12104
|
__proto__: null,
|
|
12059
12105
|
N_CHUNKS_REDUNDANCY: N_CHUNKS_REDUNDANCY,
|
|
12060
12106
|
N_CHUNKS_REQUIRED: N_CHUNKS_REQUIRED,
|
|
@@ -12078,6 +12124,439 @@ var index$a = /*#__PURE__*/Object.freeze({
|
|
|
12078
12124
|
unzip: unzip
|
|
12079
12125
|
});
|
|
12080
12126
|
|
|
12127
|
+
/**
|
|
12128
|
+
* Version ::= SEQUENCE {
|
|
12129
|
+
* major INTEGER (0..255),
|
|
12130
|
+
* minor INTEGER (0..255),
|
|
12131
|
+
* patch INTEGER (0..255)
|
|
12132
|
+
* }
|
|
12133
|
+
*/
|
|
12134
|
+
class Version extends WithDebug {
|
|
12135
|
+
major;
|
|
12136
|
+
minor;
|
|
12137
|
+
patch;
|
|
12138
|
+
static Codec = codec$1.Class(Version, {
|
|
12139
|
+
major: codec$1.u8,
|
|
12140
|
+
minor: codec$1.u8,
|
|
12141
|
+
patch: codec$1.u8,
|
|
12142
|
+
});
|
|
12143
|
+
static tryFromString(str) {
|
|
12144
|
+
const parse = (v) => tryAsU8(Number(v));
|
|
12145
|
+
try {
|
|
12146
|
+
const [major, minor, patch] = str.trim().split(".").map(parse);
|
|
12147
|
+
return Version.create({
|
|
12148
|
+
major,
|
|
12149
|
+
minor,
|
|
12150
|
+
patch,
|
|
12151
|
+
});
|
|
12152
|
+
}
|
|
12153
|
+
catch (e) {
|
|
12154
|
+
throw new Error(`Unable to parse ${str} as Version: ${e}`);
|
|
12155
|
+
}
|
|
12156
|
+
}
|
|
12157
|
+
static create({ major, minor, patch }) {
|
|
12158
|
+
return new Version(major, minor, patch);
|
|
12159
|
+
}
|
|
12160
|
+
constructor(major, minor, patch) {
|
|
12161
|
+
super();
|
|
12162
|
+
this.major = major;
|
|
12163
|
+
this.minor = minor;
|
|
12164
|
+
this.patch = patch;
|
|
12165
|
+
}
|
|
12166
|
+
}
|
|
12167
|
+
/**
|
|
12168
|
+
* Fuzzer Protocol V1
|
|
12169
|
+
* Reference: https://github.com/davxy/jam-conformance/blob/main/fuzz-proto/fuzz.asn
|
|
12170
|
+
*/
|
|
12171
|
+
// Feature bit constants
|
|
12172
|
+
var Features;
|
|
12173
|
+
(function (Features) {
|
|
12174
|
+
Features[Features["Ancestry"] = 1] = "Ancestry";
|
|
12175
|
+
Features[Features["Fork"] = 2] = "Fork";
|
|
12176
|
+
Features[Features["Reserved"] = 2147483648] = "Reserved";
|
|
12177
|
+
})(Features || (Features = {}));
|
|
12178
|
+
/**
|
|
12179
|
+
* PeerInfo ::= SEQUENCE {
|
|
12180
|
+
* fuzz-version U8,
|
|
12181
|
+
* features Features,
|
|
12182
|
+
* jam-version Version,
|
|
12183
|
+
* app-version Version,
|
|
12184
|
+
* name UTF8String
|
|
12185
|
+
* }
|
|
12186
|
+
*/
|
|
12187
|
+
class PeerInfo extends WithDebug {
|
|
12188
|
+
fuzzVersion;
|
|
12189
|
+
features;
|
|
12190
|
+
jamVersion;
|
|
12191
|
+
appVersion;
|
|
12192
|
+
name;
|
|
12193
|
+
static Codec = codec$1.Class(PeerInfo, {
|
|
12194
|
+
fuzzVersion: codec$1.u8,
|
|
12195
|
+
features: codec$1.u32,
|
|
12196
|
+
jamVersion: Version.Codec,
|
|
12197
|
+
appVersion: Version.Codec,
|
|
12198
|
+
name: codec$1.string,
|
|
12199
|
+
});
|
|
12200
|
+
static create({ fuzzVersion, features, appVersion, jamVersion, name }) {
|
|
12201
|
+
return new PeerInfo(fuzzVersion, features, jamVersion, appVersion, name);
|
|
12202
|
+
}
|
|
12203
|
+
constructor(fuzzVersion, features, jamVersion, appVersion, name) {
|
|
12204
|
+
super();
|
|
12205
|
+
this.fuzzVersion = fuzzVersion;
|
|
12206
|
+
this.features = features;
|
|
12207
|
+
this.jamVersion = jamVersion;
|
|
12208
|
+
this.appVersion = appVersion;
|
|
12209
|
+
this.name = name;
|
|
12210
|
+
}
|
|
12211
|
+
}
|
|
12212
|
+
/**
|
|
12213
|
+
* AncestryItem ::= SEQUENCE {
|
|
12214
|
+
* slot TimeSlot,
|
|
12215
|
+
* header-hash HeaderHash
|
|
12216
|
+
* }
|
|
12217
|
+
*/
|
|
12218
|
+
class AncestryItem extends WithDebug {
|
|
12219
|
+
slot;
|
|
12220
|
+
headerHash;
|
|
12221
|
+
static Codec = codec$1.Class(AncestryItem, {
|
|
12222
|
+
slot: codec$1.u32.asOpaque(),
|
|
12223
|
+
headerHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
12224
|
+
});
|
|
12225
|
+
static create({ slot, headerHash }) {
|
|
12226
|
+
return new AncestryItem(slot, headerHash);
|
|
12227
|
+
}
|
|
12228
|
+
constructor(slot, headerHash) {
|
|
12229
|
+
super();
|
|
12230
|
+
this.slot = slot;
|
|
12231
|
+
this.headerHash = headerHash;
|
|
12232
|
+
}
|
|
12233
|
+
}
|
|
12234
|
+
/**
|
|
12235
|
+
* KeyValue ::= SEQUENCE {
|
|
12236
|
+
* key TrieKey,
|
|
12237
|
+
* value OCTET STRING
|
|
12238
|
+
* }
|
|
12239
|
+
*/
|
|
12240
|
+
class KeyValue extends WithDebug {
|
|
12241
|
+
key;
|
|
12242
|
+
value;
|
|
12243
|
+
static Codec = codec$1.Class(KeyValue, {
|
|
12244
|
+
key: codec$1.bytes(TRUNCATED_HASH_SIZE),
|
|
12245
|
+
value: codec$1.blob,
|
|
12246
|
+
});
|
|
12247
|
+
static create({ key, value }) {
|
|
12248
|
+
return new KeyValue(key, value);
|
|
12249
|
+
}
|
|
12250
|
+
constructor(key, value) {
|
|
12251
|
+
super();
|
|
12252
|
+
this.key = key;
|
|
12253
|
+
this.value = value;
|
|
12254
|
+
}
|
|
12255
|
+
}
|
|
12256
|
+
/** State ::= SEQUENCE OF KeyValue */
|
|
12257
|
+
const stateCodec = codec$1.sequenceVarLen(KeyValue.Codec);
|
|
12258
|
+
/**
|
|
12259
|
+
* Ancestry ::= SEQUENCE (SIZE(0..24)) OF AncestryItem
|
|
12260
|
+
* Empty when `feature-ancestry` is not supported by both parties
|
|
12261
|
+
*/
|
|
12262
|
+
const ancestryCodec = codec$1.sequenceVarLen(AncestryItem.Codec, {
|
|
12263
|
+
minLength: 0,
|
|
12264
|
+
maxLength: 24,
|
|
12265
|
+
});
|
|
12266
|
+
/**
|
|
12267
|
+
* Initialize ::= SEQUENCE {
|
|
12268
|
+
* header Header,
|
|
12269
|
+
* keyvals State,
|
|
12270
|
+
* ancestry Ancestry
|
|
12271
|
+
* }
|
|
12272
|
+
*/
|
|
12273
|
+
class Initialize extends WithDebug {
|
|
12274
|
+
header;
|
|
12275
|
+
keyvals;
|
|
12276
|
+
ancestry;
|
|
12277
|
+
static Codec = codec$1.Class(Initialize, {
|
|
12278
|
+
header: Header.Codec,
|
|
12279
|
+
keyvals: stateCodec,
|
|
12280
|
+
ancestry: ancestryCodec,
|
|
12281
|
+
});
|
|
12282
|
+
static create({ header, keyvals, ancestry }) {
|
|
12283
|
+
return new Initialize(header, keyvals, ancestry);
|
|
12284
|
+
}
|
|
12285
|
+
constructor(header, keyvals, ancestry) {
|
|
12286
|
+
super();
|
|
12287
|
+
this.header = header;
|
|
12288
|
+
this.keyvals = keyvals;
|
|
12289
|
+
this.ancestry = ancestry;
|
|
12290
|
+
}
|
|
12291
|
+
}
|
|
12292
|
+
/** GetState ::= HeaderHash */
|
|
12293
|
+
const getStateCodec = codec$1.bytes(HASH_SIZE).asOpaque();
|
|
12294
|
+
/** StateRoot ::= StateRootHash */
|
|
12295
|
+
const stateRootCodec = codec$1.bytes(HASH_SIZE).asOpaque();
|
|
12296
|
+
/** Error ::= UTF8String */
|
|
12297
|
+
class ErrorMessage extends WithDebug {
|
|
12298
|
+
message;
|
|
12299
|
+
static Codec = codec$1.Class(ErrorMessage, {
|
|
12300
|
+
message: codec$1.string,
|
|
12301
|
+
});
|
|
12302
|
+
static create({ message }) {
|
|
12303
|
+
return new ErrorMessage(message);
|
|
12304
|
+
}
|
|
12305
|
+
constructor(message) {
|
|
12306
|
+
super();
|
|
12307
|
+
this.message = message;
|
|
12308
|
+
}
|
|
12309
|
+
}
|
|
12310
|
+
/** Message choice type tags */
|
|
12311
|
+
var MessageType;
|
|
12312
|
+
(function (MessageType) {
|
|
12313
|
+
MessageType[MessageType["PeerInfo"] = 0] = "PeerInfo";
|
|
12314
|
+
MessageType[MessageType["Initialize"] = 1] = "Initialize";
|
|
12315
|
+
MessageType[MessageType["StateRoot"] = 2] = "StateRoot";
|
|
12316
|
+
MessageType[MessageType["ImportBlock"] = 3] = "ImportBlock";
|
|
12317
|
+
MessageType[MessageType["GetState"] = 4] = "GetState";
|
|
12318
|
+
MessageType[MessageType["State"] = 5] = "State";
|
|
12319
|
+
MessageType[MessageType["Error"] = 255] = "Error";
|
|
12320
|
+
})(MessageType || (MessageType = {}));
|
|
12321
|
+
/**
|
|
12322
|
+
* Message ::= CHOICE {
|
|
12323
|
+
* peer-info [0] PeerInfo,
|
|
12324
|
+
* initialize [1] Initialize,
|
|
12325
|
+
* state-root [2] StateRoot,
|
|
12326
|
+
* import-block [3] ImportBlock,
|
|
12327
|
+
* get-state [4] GetState,
|
|
12328
|
+
* state [5] State,
|
|
12329
|
+
* error [255] Error
|
|
12330
|
+
* }
|
|
12331
|
+
*/
|
|
12332
|
+
const messageCodec = codec$1.custom({
|
|
12333
|
+
name: "Message",
|
|
12334
|
+
sizeHint: { bytes: 1, isExact: false },
|
|
12335
|
+
}, (e, msg) => {
|
|
12336
|
+
e.i8(msg.type);
|
|
12337
|
+
switch (msg.type) {
|
|
12338
|
+
case MessageType.PeerInfo:
|
|
12339
|
+
PeerInfo.Codec.encode(e, msg.value);
|
|
12340
|
+
break;
|
|
12341
|
+
case MessageType.Initialize:
|
|
12342
|
+
Initialize.Codec.encode(e, msg.value);
|
|
12343
|
+
break;
|
|
12344
|
+
case MessageType.StateRoot:
|
|
12345
|
+
stateRootCodec.encode(e, msg.value);
|
|
12346
|
+
break;
|
|
12347
|
+
case MessageType.ImportBlock:
|
|
12348
|
+
Block.Codec.View.encode(e, msg.value);
|
|
12349
|
+
break;
|
|
12350
|
+
case MessageType.GetState:
|
|
12351
|
+
getStateCodec.encode(e, msg.value);
|
|
12352
|
+
break;
|
|
12353
|
+
case MessageType.State:
|
|
12354
|
+
stateCodec.encode(e, msg.value);
|
|
12355
|
+
break;
|
|
12356
|
+
case MessageType.Error:
|
|
12357
|
+
ErrorMessage.Codec.encode(e, msg.value);
|
|
12358
|
+
break;
|
|
12359
|
+
default:
|
|
12360
|
+
throw new Error(`Unknown message type: ${msg}`);
|
|
12361
|
+
}
|
|
12362
|
+
}, (d) => {
|
|
12363
|
+
const type = d.u8();
|
|
12364
|
+
switch (type) {
|
|
12365
|
+
case MessageType.PeerInfo:
|
|
12366
|
+
return { type: MessageType.PeerInfo, value: PeerInfo.Codec.decode(d) };
|
|
12367
|
+
case MessageType.Initialize:
|
|
12368
|
+
return { type: MessageType.Initialize, value: Initialize.Codec.decode(d) };
|
|
12369
|
+
case MessageType.StateRoot:
|
|
12370
|
+
return { type: MessageType.StateRoot, value: stateRootCodec.decode(d) };
|
|
12371
|
+
case MessageType.ImportBlock:
|
|
12372
|
+
return { type: MessageType.ImportBlock, value: Block.Codec.View.decode(d) };
|
|
12373
|
+
case MessageType.GetState:
|
|
12374
|
+
return { type: MessageType.GetState, value: getStateCodec.decode(d) };
|
|
12375
|
+
case MessageType.State:
|
|
12376
|
+
return { type: MessageType.State, value: stateCodec.decode(d) };
|
|
12377
|
+
case MessageType.Error:
|
|
12378
|
+
return { type: MessageType.Error, value: ErrorMessage.Codec.decode(d) };
|
|
12379
|
+
default:
|
|
12380
|
+
throw new Error(`Unknown message type: ${type}`);
|
|
12381
|
+
}
|
|
12382
|
+
}, (s) => {
|
|
12383
|
+
const type = s.decoder.u8();
|
|
12384
|
+
switch (type) {
|
|
12385
|
+
case MessageType.PeerInfo:
|
|
12386
|
+
PeerInfo.Codec.View.skip(s);
|
|
12387
|
+
break;
|
|
12388
|
+
case MessageType.Initialize:
|
|
12389
|
+
Initialize.Codec.View.skip(s);
|
|
12390
|
+
break;
|
|
12391
|
+
case MessageType.StateRoot:
|
|
12392
|
+
stateRootCodec.View.skip(s);
|
|
12393
|
+
break;
|
|
12394
|
+
case MessageType.ImportBlock:
|
|
12395
|
+
Block.Codec.View.skip(s);
|
|
12396
|
+
break;
|
|
12397
|
+
case MessageType.GetState:
|
|
12398
|
+
getStateCodec.View.skip(s);
|
|
12399
|
+
break;
|
|
12400
|
+
case MessageType.State:
|
|
12401
|
+
stateCodec.View.skip(s);
|
|
12402
|
+
break;
|
|
12403
|
+
case MessageType.Error:
|
|
12404
|
+
ErrorMessage.Codec.View.skip(s);
|
|
12405
|
+
break;
|
|
12406
|
+
default:
|
|
12407
|
+
throw new Error(`Unknown message type: ${type}`);
|
|
12408
|
+
}
|
|
12409
|
+
});
|
|
12410
|
+
|
|
12411
|
+
const logger$4 = Logger.new(undefined, "ext-ipc-fuzz-v1");
|
|
12412
|
+
class FuzzTarget {
|
|
12413
|
+
msgHandler;
|
|
12414
|
+
sender;
|
|
12415
|
+
spec;
|
|
12416
|
+
sessionFeatures = 0;
|
|
12417
|
+
constructor(msgHandler, sender, spec) {
|
|
12418
|
+
this.msgHandler = msgHandler;
|
|
12419
|
+
this.sender = sender;
|
|
12420
|
+
this.spec = spec;
|
|
12421
|
+
}
|
|
12422
|
+
async onSocketMessage(msg) {
|
|
12423
|
+
// attempt to decode the messsage
|
|
12424
|
+
try {
|
|
12425
|
+
const message = Decoder.decodeObject(messageCodec, msg, this.spec);
|
|
12426
|
+
logger$4.log `[${message.type}] incoming message`;
|
|
12427
|
+
await this.processAndRespond(message);
|
|
12428
|
+
}
|
|
12429
|
+
catch (e) {
|
|
12430
|
+
logger$4.error `Error while processing fuzz v1 message: ${e}`;
|
|
12431
|
+
logger$4.error `${e}`;
|
|
12432
|
+
if (e instanceof Error) {
|
|
12433
|
+
logger$4.error `${e.stack ?? ""}`;
|
|
12434
|
+
}
|
|
12435
|
+
this.sender.close();
|
|
12436
|
+
}
|
|
12437
|
+
}
|
|
12438
|
+
async processAndRespond(message) {
|
|
12439
|
+
let response = null;
|
|
12440
|
+
switch (message.type) {
|
|
12441
|
+
case MessageType.PeerInfo: {
|
|
12442
|
+
// only support V1
|
|
12443
|
+
if (message.value.fuzzVersion !== 1) {
|
|
12444
|
+
logger$4.warn `Unsupported fuzzer protocol version: ${message.value.fuzzVersion}. Closing`;
|
|
12445
|
+
this.sender.close();
|
|
12446
|
+
return;
|
|
12447
|
+
}
|
|
12448
|
+
// Handle handshake
|
|
12449
|
+
const ourPeerInfo = await this.msgHandler.getPeerInfo(message.value);
|
|
12450
|
+
// Calculate session features (intersection of both peer features)
|
|
12451
|
+
this.sessionFeatures = message.value.features & ourPeerInfo.features;
|
|
12452
|
+
logger$4.info `Handshake completed. Shared features: 0b${this.sessionFeatures.toString(2)}`;
|
|
12453
|
+
logger$4.log `Feature ancestry: ${(this.sessionFeatures & Features.Ancestry) !== 0}`;
|
|
12454
|
+
logger$4.log `Feature fork: ${(this.sessionFeatures & Features.Fork) !== 0}`;
|
|
12455
|
+
response = {
|
|
12456
|
+
type: MessageType.PeerInfo,
|
|
12457
|
+
value: ourPeerInfo,
|
|
12458
|
+
};
|
|
12459
|
+
break;
|
|
12460
|
+
}
|
|
12461
|
+
case MessageType.Initialize: {
|
|
12462
|
+
const stateRoot = await this.msgHandler.initialize(message.value);
|
|
12463
|
+
response = {
|
|
12464
|
+
type: MessageType.StateRoot,
|
|
12465
|
+
value: stateRoot,
|
|
12466
|
+
};
|
|
12467
|
+
break;
|
|
12468
|
+
}
|
|
12469
|
+
case MessageType.ImportBlock: {
|
|
12470
|
+
const result = await this.msgHandler.importBlock(message.value);
|
|
12471
|
+
if (result.isOk) {
|
|
12472
|
+
response = {
|
|
12473
|
+
type: MessageType.StateRoot,
|
|
12474
|
+
value: result.ok,
|
|
12475
|
+
};
|
|
12476
|
+
}
|
|
12477
|
+
else {
|
|
12478
|
+
response = {
|
|
12479
|
+
type: MessageType.Error,
|
|
12480
|
+
value: result.error,
|
|
12481
|
+
};
|
|
12482
|
+
}
|
|
12483
|
+
break;
|
|
12484
|
+
}
|
|
12485
|
+
case MessageType.GetState: {
|
|
12486
|
+
const state = await this.msgHandler.getSerializedState(message.value);
|
|
12487
|
+
response = {
|
|
12488
|
+
type: MessageType.State,
|
|
12489
|
+
value: state,
|
|
12490
|
+
};
|
|
12491
|
+
break;
|
|
12492
|
+
}
|
|
12493
|
+
case MessageType.StateRoot: {
|
|
12494
|
+
logger$4.log `--> Received unexpected 'StateRoot' message from the fuzzer. Closing.`;
|
|
12495
|
+
this.sender.close();
|
|
12496
|
+
return;
|
|
12497
|
+
}
|
|
12498
|
+
case MessageType.State: {
|
|
12499
|
+
logger$4.log `--> Received unexpected 'State' message from the fuzzer. Closing.`;
|
|
12500
|
+
this.sender.close();
|
|
12501
|
+
return;
|
|
12502
|
+
}
|
|
12503
|
+
case MessageType.Error: {
|
|
12504
|
+
logger$4.log `--> Received unexpected 'Error' message from the fuzzer. Closing.`;
|
|
12505
|
+
this.sender.close();
|
|
12506
|
+
return;
|
|
12507
|
+
}
|
|
12508
|
+
default: {
|
|
12509
|
+
logger$4.log `--> Received unexpected message type ${JSON.stringify(message)} from the fuzzer. Closing.`;
|
|
12510
|
+
this.sender.close();
|
|
12511
|
+
try {
|
|
12512
|
+
assertNever(message);
|
|
12513
|
+
}
|
|
12514
|
+
catch {
|
|
12515
|
+
return;
|
|
12516
|
+
}
|
|
12517
|
+
}
|
|
12518
|
+
}
|
|
12519
|
+
if (response !== null) {
|
|
12520
|
+
logger$4.trace `<-- responding with: ${response.type}`;
|
|
12521
|
+
const encoded = Encoder.encodeObject(messageCodec, response, this.spec);
|
|
12522
|
+
this.sender.send(encoded);
|
|
12523
|
+
}
|
|
12524
|
+
else {
|
|
12525
|
+
logger$4.warn `<-- no response generated for: ${message.type}`;
|
|
12526
|
+
}
|
|
12527
|
+
}
|
|
12528
|
+
onClose({ error }) {
|
|
12529
|
+
logger$4.log `Closing the v1 handler. Reason: ${error !== undefined ? error.message : "close"}.`;
|
|
12530
|
+
}
|
|
12531
|
+
/** Check if a specific feature is enabled in the session */
|
|
12532
|
+
hasFeature(feature) {
|
|
12533
|
+
return (this.sessionFeatures & feature) !== 0;
|
|
12534
|
+
}
|
|
12535
|
+
}
|
|
12536
|
+
|
|
12537
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
12538
|
+
__proto__: null,
|
|
12539
|
+
AncestryItem: AncestryItem,
|
|
12540
|
+
ErrorMessage: ErrorMessage,
|
|
12541
|
+
get Features () { return Features; },
|
|
12542
|
+
FuzzTarget: FuzzTarget,
|
|
12543
|
+
Initialize: Initialize,
|
|
12544
|
+
KeyValue: KeyValue,
|
|
12545
|
+
get MessageType () { return MessageType; },
|
|
12546
|
+
PeerInfo: PeerInfo,
|
|
12547
|
+
Version: Version,
|
|
12548
|
+
ancestryCodec: ancestryCodec,
|
|
12549
|
+
getStateCodec: getStateCodec,
|
|
12550
|
+
messageCodec: messageCodec,
|
|
12551
|
+
stateCodec: stateCodec,
|
|
12552
|
+
stateRootCodec: stateRootCodec
|
|
12553
|
+
});
|
|
12554
|
+
|
|
12555
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
12556
|
+
__proto__: null,
|
|
12557
|
+
v1: index$b
|
|
12558
|
+
});
|
|
12559
|
+
|
|
12081
12560
|
/** Size of the transfer memo. */
|
|
12082
12561
|
const TRANSFER_MEMO_BYTES = W_T;
|
|
12083
12562
|
/**
|
|
@@ -12864,10 +13343,16 @@ function signExtend32To64(value) {
|
|
|
12864
13343
|
|
|
12865
13344
|
/** Attempt to convert a number into `HostCallIndex`. */
|
|
12866
13345
|
const tryAsHostCallIndex = (v) => asOpaqueType(tryAsU32(v));
|
|
13346
|
+
/**
|
|
13347
|
+
* Host-call exit reason.
|
|
13348
|
+
*
|
|
13349
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/24a30124a501?v=0.7.2
|
|
13350
|
+
*/
|
|
12867
13351
|
var PvmExecution;
|
|
12868
13352
|
(function (PvmExecution) {
|
|
12869
13353
|
PvmExecution[PvmExecution["Halt"] = 0] = "Halt";
|
|
12870
13354
|
PvmExecution[PvmExecution["Panic"] = 1] = "Panic";
|
|
13355
|
+
PvmExecution[PvmExecution["OOG"] = 2] = "OOG";
|
|
12871
13356
|
})(PvmExecution || (PvmExecution = {}));
|
|
12872
13357
|
/** A utility function to easily trace a bunch of registers. */
|
|
12873
13358
|
function traceRegisters(...regs) {
|
|
@@ -14125,6 +14610,17 @@ class PageRange {
|
|
|
14125
14610
|
}
|
|
14126
14611
|
return new PageRange(start, length);
|
|
14127
14612
|
}
|
|
14613
|
+
/** Returns true if the page range is wrapped (`start` >= `end`) and is not empty */
|
|
14614
|
+
isWrapped() {
|
|
14615
|
+
return this.start >= this.end && !this.isEmpty();
|
|
14616
|
+
}
|
|
14617
|
+
/** Checks if given page number is within the range */
|
|
14618
|
+
isInRange(page) {
|
|
14619
|
+
if (this.isWrapped()) {
|
|
14620
|
+
return page >= this.start || page < this.end;
|
|
14621
|
+
}
|
|
14622
|
+
return page >= this.start && page < this.end;
|
|
14623
|
+
}
|
|
14128
14624
|
/** Checks if a range is empty (`length === 0`) */
|
|
14129
14625
|
isEmpty() {
|
|
14130
14626
|
return this.length === 0;
|
|
@@ -14465,10 +14961,11 @@ class MemoryBuilder {
|
|
|
14465
14961
|
startHeapIndex (${startHeapIndex}) has to be less than or equal to endHeapIndex (${endHeapIndex})
|
|
14466
14962
|
`;
|
|
14467
14963
|
this.ensureNotFinalized();
|
|
14468
|
-
const
|
|
14469
|
-
const
|
|
14470
|
-
|
|
14471
|
-
|
|
14964
|
+
const heapRange = MemoryRange.fromStartAndLength(startHeapIndex, endHeapIndex - startHeapIndex);
|
|
14965
|
+
const heapPagesRange = PageRange.fromMemoryRange(heapRange);
|
|
14966
|
+
const initializedPageNumbers = Array.from(this.initialMemory.keys());
|
|
14967
|
+
for (const pageNumber of initializedPageNumbers) {
|
|
14968
|
+
if (heapPagesRange.isInRange(pageNumber)) {
|
|
14472
14969
|
throw new IncorrectSbrkIndex();
|
|
14473
14970
|
}
|
|
14474
14971
|
}
|
|
@@ -16490,8 +16987,9 @@ class HostCalls {
|
|
|
16490
16987
|
const index = tryAsHostCallIndex(hostCallIndex);
|
|
16491
16988
|
const hostCall = this.hostCalls.get(index);
|
|
16492
16989
|
const gasBefore = gas.get();
|
|
16493
|
-
|
|
16494
|
-
const
|
|
16990
|
+
// NOTE: `basicGasCost(regs)` function is for compatibility reasons: pre GP 0.7.2
|
|
16991
|
+
const basicGasCost = typeof hostCall.basicGasCost === "number" ? hostCall.basicGasCost : hostCall.basicGasCost(regs);
|
|
16992
|
+
const underflow = gas.sub(basicGasCost);
|
|
16495
16993
|
const pcLog = `[PC: ${pvmInstance.getPC()}]`;
|
|
16496
16994
|
if (underflow) {
|
|
16497
16995
|
this.hostCalls.traceHostCall(`${pcLog} OOG`, index, hostCall, regs, gas.get());
|
|
@@ -16508,6 +17006,10 @@ class HostCalls {
|
|
|
16508
17006
|
status = Status.PANIC;
|
|
16509
17007
|
return this.getReturnValue(status, pvmInstance);
|
|
16510
17008
|
}
|
|
17009
|
+
if (result === PvmExecution.OOG) {
|
|
17010
|
+
status = Status.OOG;
|
|
17011
|
+
return this.getReturnValue(status, pvmInstance);
|
|
17012
|
+
}
|
|
16511
17013
|
if (result === undefined) {
|
|
16512
17014
|
pvmInstance.runProgram();
|
|
16513
17015
|
status = pvmInstance.getStatus();
|
|
@@ -16908,8 +17410,8 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
16908
17410
|
asOpaqueType: asOpaqueType,
|
|
16909
17411
|
assertEmpty: assertEmpty,
|
|
16910
17412
|
assertNever: assertNever,
|
|
16911
|
-
block: index$
|
|
16912
|
-
bytes: index$
|
|
17413
|
+
block: index$l,
|
|
17414
|
+
bytes: index$s,
|
|
16913
17415
|
check: check,
|
|
16914
17416
|
clampU64ToU32: clampU64ToU32,
|
|
16915
17417
|
createResults: createResults,
|
|
@@ -16917,13 +17419,13 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
16917
17419
|
extractCodeAndMetadata: extractCodeAndMetadata,
|
|
16918
17420
|
getServiceId: getServiceId,
|
|
16919
17421
|
getServiceIdOrCurrent: getServiceIdOrCurrent,
|
|
16920
|
-
hash: index$
|
|
17422
|
+
hash: index$p,
|
|
16921
17423
|
inspect: inspect,
|
|
16922
17424
|
instructionArgumentTypeMap: instructionArgumentTypeMap,
|
|
16923
17425
|
interpreter: index$7,
|
|
16924
17426
|
isBrowser: isBrowser,
|
|
16925
17427
|
measure: measure,
|
|
16926
|
-
numbers: index$
|
|
17428
|
+
numbers: index$r,
|
|
16927
17429
|
resultToString: resultToString,
|
|
16928
17430
|
seeThrough: seeThrough,
|
|
16929
17431
|
slotsToPreimageStatus: slotsToPreimageStatus,
|
|
@@ -17497,7 +17999,7 @@ class Preimages {
|
|
|
17497
17999
|
|
|
17498
18000
|
class Missing {
|
|
17499
18001
|
index = tryAsHostCallIndex(2 ** 32 - 1);
|
|
17500
|
-
|
|
18002
|
+
basicGasCost = tryAsSmallGas(10);
|
|
17501
18003
|
currentServiceId = CURRENT_SERVICE_ID;
|
|
17502
18004
|
tracedRegisters = traceRegisters(7);
|
|
17503
18005
|
execute(_gas, regs, _memory) {
|
|
@@ -17637,32 +18139,33 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
17637
18139
|
WorkPackageExecutor: WorkPackageExecutor
|
|
17638
18140
|
});
|
|
17639
18141
|
|
|
17640
|
-
exports.block = index$
|
|
17641
|
-
exports.block_json = index$
|
|
17642
|
-
exports.bytes = index$
|
|
17643
|
-
exports.codec = index$
|
|
17644
|
-
exports.collections = index$
|
|
17645
|
-
exports.config = index$
|
|
17646
|
-
exports.config_node = index$
|
|
17647
|
-
exports.crypto = index$
|
|
17648
|
-
exports.database = index$
|
|
17649
|
-
exports.erasure_coding = index$
|
|
17650
|
-
exports.
|
|
18142
|
+
exports.block = index$l;
|
|
18143
|
+
exports.block_json = index$j;
|
|
18144
|
+
exports.bytes = index$s;
|
|
18145
|
+
exports.codec = index$q;
|
|
18146
|
+
exports.collections = index$n;
|
|
18147
|
+
exports.config = index$m;
|
|
18148
|
+
exports.config_node = index$h;
|
|
18149
|
+
exports.crypto = index$o;
|
|
18150
|
+
exports.database = index$d;
|
|
18151
|
+
exports.erasure_coding = index$c;
|
|
18152
|
+
exports.fuzz_proto = index$a;
|
|
18153
|
+
exports.hash = index$p;
|
|
17651
18154
|
exports.jam_host_calls = index$9;
|
|
17652
|
-
exports.json_parser = index$
|
|
17653
|
-
exports.logger = index$
|
|
18155
|
+
exports.json_parser = index$k;
|
|
18156
|
+
exports.logger = index$i;
|
|
17654
18157
|
exports.mmr = index$8;
|
|
17655
|
-
exports.numbers = index$
|
|
17656
|
-
exports.ordering = index$
|
|
18158
|
+
exports.numbers = index$r;
|
|
18159
|
+
exports.ordering = index$t;
|
|
17657
18160
|
exports.pvm = index$3;
|
|
17658
18161
|
exports.pvm_host_calls = index$6;
|
|
17659
18162
|
exports.pvm_interpreter = index$7;
|
|
17660
18163
|
exports.pvm_program = index$4;
|
|
17661
18164
|
exports.pvm_spi_decoder = index$5;
|
|
17662
18165
|
exports.shuffling = index$2;
|
|
17663
|
-
exports.state = index$
|
|
18166
|
+
exports.state = index$g;
|
|
17664
18167
|
exports.state_json = index$1;
|
|
17665
|
-
exports.state_merkleization = index$
|
|
18168
|
+
exports.state_merkleization = index$e;
|
|
17666
18169
|
exports.transition = index;
|
|
17667
|
-
exports.trie = index$
|
|
17668
|
-
exports.utils = index$
|
|
18170
|
+
exports.trie = index$f;
|
|
18171
|
+
exports.utils = index$u;
|