@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.js
CHANGED
|
@@ -560,7 +560,7 @@ function isResult(x) {
|
|
|
560
560
|
* as an afterthought.
|
|
561
561
|
*/
|
|
562
562
|
|
|
563
|
-
var index$
|
|
563
|
+
var index$u = /*#__PURE__*/Object.freeze({
|
|
564
564
|
__proto__: null,
|
|
565
565
|
get CURRENT_SUITE () { return CURRENT_SUITE; },
|
|
566
566
|
get CURRENT_VERSION () { return CURRENT_VERSION; },
|
|
@@ -714,7 +714,7 @@ class Ordering {
|
|
|
714
714
|
}
|
|
715
715
|
}
|
|
716
716
|
|
|
717
|
-
var index$
|
|
717
|
+
var index$t = /*#__PURE__*/Object.freeze({
|
|
718
718
|
__proto__: null,
|
|
719
719
|
Ordering: Ordering
|
|
720
720
|
});
|
|
@@ -965,7 +965,7 @@ function u8ArraySameLengthEqual(self, other) {
|
|
|
965
965
|
}
|
|
966
966
|
const bytesBlobComparator = (a, b) => a.compare(b);
|
|
967
967
|
|
|
968
|
-
var index$
|
|
968
|
+
var index$s = /*#__PURE__*/Object.freeze({
|
|
969
969
|
__proto__: null,
|
|
970
970
|
BitVec: BitVec,
|
|
971
971
|
Bytes: Bytes,
|
|
@@ -1067,7 +1067,7 @@ const minU64 = (a, ...values) => values.reduce((min, value) => (value > min ? mi
|
|
|
1067
1067
|
/** Get the biggest value between U64 a and values given as input parameters. */
|
|
1068
1068
|
const maxU64 = (a, ...values) => values.reduce((max, value) => (value < max ? max : value), a);
|
|
1069
1069
|
|
|
1070
|
-
var index$
|
|
1070
|
+
var index$r = /*#__PURE__*/Object.freeze({
|
|
1071
1071
|
__proto__: null,
|
|
1072
1072
|
isU16: isU16,
|
|
1073
1073
|
isU32: isU32,
|
|
@@ -1944,13 +1944,15 @@ function validateLength(range, length, context) {
|
|
|
1944
1944
|
|
|
1945
1945
|
/** A caching wrapper for either object or sequence item. */
|
|
1946
1946
|
class ViewField {
|
|
1947
|
+
name;
|
|
1947
1948
|
getView;
|
|
1948
1949
|
getValue;
|
|
1949
1950
|
getEncoded;
|
|
1950
1951
|
cachedValue;
|
|
1951
1952
|
cachedView;
|
|
1952
1953
|
cachedBlob;
|
|
1953
|
-
constructor(getView, getValue, getEncoded) {
|
|
1954
|
+
constructor(name, getView, getValue, getEncoded) {
|
|
1955
|
+
this.name = name;
|
|
1954
1956
|
this.getView = getView;
|
|
1955
1957
|
this.getValue = getValue;
|
|
1956
1958
|
this.getEncoded = getEncoded;
|
|
@@ -1976,6 +1978,9 @@ class ViewField {
|
|
|
1976
1978
|
}
|
|
1977
1979
|
return this.cachedBlob;
|
|
1978
1980
|
}
|
|
1981
|
+
toString() {
|
|
1982
|
+
return `ViewField<${this.name}>`;
|
|
1983
|
+
}
|
|
1979
1984
|
}
|
|
1980
1985
|
/**
|
|
1981
1986
|
* A base class for all the lazy views.
|
|
@@ -2050,7 +2055,7 @@ class ObjectView {
|
|
|
2050
2055
|
const fieldDecoder = skipper.decoder.clone();
|
|
2051
2056
|
const field = this.descriptorsKeys[i];
|
|
2052
2057
|
const type = this.descriptors[field];
|
|
2053
|
-
lastItem = new ViewField(() => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2058
|
+
lastItem = new ViewField(`${this.toString()}.${String(field)}`, () => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2054
2059
|
// skip the field
|
|
2055
2060
|
type.skip(skipper);
|
|
2056
2061
|
// cache data
|
|
@@ -2062,6 +2067,9 @@ class ObjectView {
|
|
|
2062
2067
|
}
|
|
2063
2068
|
return lastItem;
|
|
2064
2069
|
}
|
|
2070
|
+
toString() {
|
|
2071
|
+
return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
|
|
2072
|
+
}
|
|
2065
2073
|
}
|
|
2066
2074
|
/**
|
|
2067
2075
|
* A lazy-evaluated decoder of a sequence.
|
|
@@ -2150,7 +2158,7 @@ class SequenceView {
|
|
|
2150
2158
|
// create new cached prop
|
|
2151
2159
|
const fieldDecoder = skipper.decoder.clone();
|
|
2152
2160
|
const type = this.descriptor;
|
|
2153
|
-
lastItem = new ViewField(() => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2161
|
+
lastItem = new ViewField(`${this.toString()}[${index}]`, () => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2154
2162
|
// skip the field
|
|
2155
2163
|
type.skip(skipper);
|
|
2156
2164
|
// cache data
|
|
@@ -2162,6 +2170,9 @@ class SequenceView {
|
|
|
2162
2170
|
}
|
|
2163
2171
|
return lastItem;
|
|
2164
2172
|
}
|
|
2173
|
+
toString() {
|
|
2174
|
+
return `SequenceView<${this.descriptor.name}>(cache: ${this.cache.size})`;
|
|
2175
|
+
}
|
|
2165
2176
|
}
|
|
2166
2177
|
|
|
2167
2178
|
/**
|
|
@@ -2477,7 +2488,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
|
|
|
2477
2488
|
}, skipper);
|
|
2478
2489
|
}
|
|
2479
2490
|
|
|
2480
|
-
var index$
|
|
2491
|
+
var index$q = /*#__PURE__*/Object.freeze({
|
|
2481
2492
|
__proto__: null,
|
|
2482
2493
|
Decoder: Decoder,
|
|
2483
2494
|
Descriptor: Descriptor,
|
|
@@ -4916,7 +4927,7 @@ var keccak = /*#__PURE__*/Object.freeze({
|
|
|
4916
4927
|
hashBlobs: hashBlobs
|
|
4917
4928
|
});
|
|
4918
4929
|
|
|
4919
|
-
var index$
|
|
4930
|
+
var index$p = /*#__PURE__*/Object.freeze({
|
|
4920
4931
|
__proto__: null,
|
|
4921
4932
|
HASH_SIZE: HASH_SIZE,
|
|
4922
4933
|
PageAllocator: PageAllocator,
|
|
@@ -4982,7 +4993,7 @@ var keyDerivation = /*#__PURE__*/Object.freeze({
|
|
|
4982
4993
|
trivialSeed: trivialSeed
|
|
4983
4994
|
});
|
|
4984
4995
|
|
|
4985
|
-
var index$
|
|
4996
|
+
var index$o = /*#__PURE__*/Object.freeze({
|
|
4986
4997
|
__proto__: null,
|
|
4987
4998
|
BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
|
|
4988
4999
|
BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
|
|
@@ -5586,7 +5597,7 @@ class TruncatedHashDictionary {
|
|
|
5586
5597
|
}
|
|
5587
5598
|
}
|
|
5588
5599
|
|
|
5589
|
-
var index$
|
|
5600
|
+
var index$n = /*#__PURE__*/Object.freeze({
|
|
5590
5601
|
__proto__: null,
|
|
5591
5602
|
FixedSizeArray: FixedSizeArray,
|
|
5592
5603
|
HashDictionary: HashDictionary,
|
|
@@ -5781,7 +5792,7 @@ class Bootnode {
|
|
|
5781
5792
|
}
|
|
5782
5793
|
}
|
|
5783
5794
|
|
|
5784
|
-
var index$
|
|
5795
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
5785
5796
|
__proto__: null,
|
|
5786
5797
|
Bootnode: Bootnode,
|
|
5787
5798
|
ChainSpec: ChainSpec,
|
|
@@ -5954,6 +5965,40 @@ var assurances = /*#__PURE__*/Object.freeze({
|
|
|
5954
5965
|
assurancesExtrinsicCodec: assurancesExtrinsicCodec
|
|
5955
5966
|
});
|
|
5956
5967
|
|
|
5968
|
+
/** Attempt to convert a number into `TimeSlot`. */
|
|
5969
|
+
const tryAsTimeSlot = (v) => asOpaqueType(tryAsU32(v));
|
|
5970
|
+
/** Attempt to convert a number into `ValidatorIndex`. */
|
|
5971
|
+
const tryAsValidatorIndex = (v) => asOpaqueType(tryAsU16(v));
|
|
5972
|
+
/** Attempt to convert a number into `ServiceId`. */
|
|
5973
|
+
const tryAsServiceId = (v) => asOpaqueType(tryAsU32(v));
|
|
5974
|
+
const tryAsServiceGas = (v) => asOpaqueType(tryAsU64(v));
|
|
5975
|
+
/** Attempt to convert a number into `CoreIndex`. */
|
|
5976
|
+
const tryAsCoreIndex = (v) => asOpaqueType(tryAsU16(v));
|
|
5977
|
+
/** Attempt to convert a number into `Epoch`. */
|
|
5978
|
+
const tryAsEpoch = (v) => asOpaqueType(tryAsU32(v));
|
|
5979
|
+
function tryAsPerValidator(array, spec) {
|
|
5980
|
+
check `
|
|
5981
|
+
${array.length === spec.validatorsCount}
|
|
5982
|
+
Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}
|
|
5983
|
+
`;
|
|
5984
|
+
return asKnownSize(array);
|
|
5985
|
+
}
|
|
5986
|
+
const codecPerValidator = (val) => codecWithContext((context) => {
|
|
5987
|
+
return codecKnownSizeArray(val, {
|
|
5988
|
+
fixedLength: context.validatorsCount,
|
|
5989
|
+
});
|
|
5990
|
+
});
|
|
5991
|
+
function tryAsPerEpochBlock(array, spec) {
|
|
5992
|
+
check `
|
|
5993
|
+
${array.length === spec.epochLength}
|
|
5994
|
+
Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}
|
|
5995
|
+
`;
|
|
5996
|
+
return asKnownSize(array);
|
|
5997
|
+
}
|
|
5998
|
+
const codecPerEpochBlock = (val) => codecWithContext((context) => {
|
|
5999
|
+
return codecKnownSizeArray(val, { fixedLength: context.epochLength });
|
|
6000
|
+
});
|
|
6001
|
+
|
|
5957
6002
|
/**
|
|
5958
6003
|
* Proof of signing a contradictory [`Judgement`] of a work report.
|
|
5959
6004
|
*/
|
|
@@ -6145,40 +6190,6 @@ var disputes = /*#__PURE__*/Object.freeze({
|
|
|
6145
6190
|
Verdict: Verdict
|
|
6146
6191
|
});
|
|
6147
6192
|
|
|
6148
|
-
/** Attempt to convert a number into `TimeSlot`. */
|
|
6149
|
-
const tryAsTimeSlot = (v) => asOpaqueType(tryAsU32(v));
|
|
6150
|
-
/** Attempt to convert a number into `ValidatorIndex`. */
|
|
6151
|
-
const tryAsValidatorIndex = (v) => asOpaqueType(tryAsU16(v));
|
|
6152
|
-
/** Attempt to convert a number into `ServiceId`. */
|
|
6153
|
-
const tryAsServiceId = (v) => asOpaqueType(tryAsU32(v));
|
|
6154
|
-
const tryAsServiceGas = (v) => asOpaqueType(tryAsU64(v));
|
|
6155
|
-
/** Attempt to convert a number into `CoreIndex`. */
|
|
6156
|
-
const tryAsCoreIndex = (v) => asOpaqueType(tryAsU16(v));
|
|
6157
|
-
/** Attempt to convert a number into `Epoch`. */
|
|
6158
|
-
const tryAsEpoch = (v) => asOpaqueType(tryAsU32(v));
|
|
6159
|
-
function tryAsPerValidator(array, spec) {
|
|
6160
|
-
check `
|
|
6161
|
-
${array.length === spec.validatorsCount}
|
|
6162
|
-
Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}
|
|
6163
|
-
`;
|
|
6164
|
-
return asKnownSize(array);
|
|
6165
|
-
}
|
|
6166
|
-
const codecPerValidator = (val) => codecWithContext((context) => {
|
|
6167
|
-
return codecKnownSizeArray(val, {
|
|
6168
|
-
fixedLength: context.validatorsCount,
|
|
6169
|
-
});
|
|
6170
|
-
});
|
|
6171
|
-
function tryAsPerEpochBlock(array, spec) {
|
|
6172
|
-
check `
|
|
6173
|
-
${array.length === spec.epochLength}
|
|
6174
|
-
Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}
|
|
6175
|
-
`;
|
|
6176
|
-
return asKnownSize(array);
|
|
6177
|
-
}
|
|
6178
|
-
const codecPerEpochBlock = (val) => codecWithContext((context) => {
|
|
6179
|
-
return codecKnownSizeArray(val, { fixedLength: context.epochLength });
|
|
6180
|
-
});
|
|
6181
|
-
|
|
6182
6193
|
/**
|
|
6183
6194
|
* Mapping between work package hash and root hash of it's exports.
|
|
6184
6195
|
*
|
|
@@ -7257,8 +7268,26 @@ class Block extends WithDebug {
|
|
|
7257
7268
|
this.extrinsic = extrinsic;
|
|
7258
7269
|
}
|
|
7259
7270
|
}
|
|
7271
|
+
function emptyBlock(slot = tryAsTimeSlot(0)) {
|
|
7272
|
+
const header = Header.empty();
|
|
7273
|
+
header.timeSlotIndex = slot;
|
|
7274
|
+
return Block.create({
|
|
7275
|
+
header,
|
|
7276
|
+
extrinsic: Extrinsic.create({
|
|
7277
|
+
tickets: asKnownSize([]),
|
|
7278
|
+
preimages: [],
|
|
7279
|
+
assurances: asKnownSize([]),
|
|
7280
|
+
guarantees: asKnownSize([]),
|
|
7281
|
+
disputes: {
|
|
7282
|
+
verdicts: [],
|
|
7283
|
+
culprits: [],
|
|
7284
|
+
faults: [],
|
|
7285
|
+
},
|
|
7286
|
+
}),
|
|
7287
|
+
});
|
|
7288
|
+
}
|
|
7260
7289
|
|
|
7261
|
-
var index$
|
|
7290
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
7262
7291
|
__proto__: null,
|
|
7263
7292
|
Block: Block,
|
|
7264
7293
|
EpochMarker: EpochMarker,
|
|
@@ -7273,6 +7302,7 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
7273
7302
|
codecPerValidator: codecPerValidator,
|
|
7274
7303
|
codecUtils: codec,
|
|
7275
7304
|
disputes: disputes,
|
|
7305
|
+
emptyBlock: emptyBlock,
|
|
7276
7306
|
encodeUnsealedHeader: encodeUnsealedHeader,
|
|
7277
7307
|
guarantees: guarantees,
|
|
7278
7308
|
headerViewWithHashCodec: headerViewWithHashCodec,
|
|
@@ -7513,7 +7543,7 @@ var json;
|
|
|
7513
7543
|
json.object = object;
|
|
7514
7544
|
})(json || (json = {}));
|
|
7515
7545
|
|
|
7516
|
-
var index$
|
|
7546
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
7517
7547
|
__proto__: null,
|
|
7518
7548
|
get json () { return json; },
|
|
7519
7549
|
parseFromJson: parseFromJson
|
|
@@ -7783,7 +7813,7 @@ const blockFromJson = (spec) => json.object({
|
|
|
7783
7813
|
extrinsic: getExtrinsicFromJson(spec),
|
|
7784
7814
|
}, ({ header, extrinsic }) => Block.create({ header, extrinsic }));
|
|
7785
7815
|
|
|
7786
|
-
var index$
|
|
7816
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
7787
7817
|
__proto__: null,
|
|
7788
7818
|
blockFromJson: blockFromJson,
|
|
7789
7819
|
disputesExtrinsicFromJson: disputesExtrinsicFromJson,
|
|
@@ -8049,8 +8079,8 @@ function print(level, levelAndName, strings, data) {
|
|
|
8049
8079
|
return;
|
|
8050
8080
|
}
|
|
8051
8081
|
const lvlText = Level[level].padEnd(5);
|
|
8052
|
-
const val = strings.map((v, idx) => `${v}${data[idx]}`);
|
|
8053
|
-
const msg = `${lvlText} [${levelAndName[1]}] ${val}`;
|
|
8082
|
+
const val = strings.map((v, idx) => `${v}${idx < data.length ? data[idx] : ""}`);
|
|
8083
|
+
const msg = `${lvlText} [${levelAndName[1]}] ${val.join("")}`;
|
|
8054
8084
|
if (level === Level.WARN) {
|
|
8055
8085
|
console.warn(msg);
|
|
8056
8086
|
}
|
|
@@ -8281,7 +8311,7 @@ class Logger {
|
|
|
8281
8311
|
}
|
|
8282
8312
|
}
|
|
8283
8313
|
|
|
8284
|
-
var index$
|
|
8314
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
8285
8315
|
__proto__: null,
|
|
8286
8316
|
get Level () { return Level; },
|
|
8287
8317
|
Logger: Logger,
|
|
@@ -8304,7 +8334,7 @@ class AuthorshipOptions {
|
|
|
8304
8334
|
}
|
|
8305
8335
|
}
|
|
8306
8336
|
|
|
8307
|
-
const logger$
|
|
8337
|
+
const logger$5 = Logger.new(import.meta.filename, "config");
|
|
8308
8338
|
/** Development config. Will accept unsealed blocks for now. */
|
|
8309
8339
|
const DEV_CONFIG = "dev";
|
|
8310
8340
|
/** Default config file. */
|
|
@@ -8363,15 +8393,15 @@ class NodeConfiguration {
|
|
|
8363
8393
|
}
|
|
8364
8394
|
function loadConfig(configPath) {
|
|
8365
8395
|
if (configPath === DEFAULT_CONFIG) {
|
|
8366
|
-
logger$
|
|
8396
|
+
logger$5.log `🔧 Loading DEFAULT config`;
|
|
8367
8397
|
return parseFromJson(configs.default, NodeConfiguration.fromJson);
|
|
8368
8398
|
}
|
|
8369
8399
|
if (configPath === DEV_CONFIG) {
|
|
8370
|
-
logger$
|
|
8400
|
+
logger$5.log `🔧 Loading DEV config`;
|
|
8371
8401
|
return parseFromJson(configs.dev, NodeConfiguration.fromJson);
|
|
8372
8402
|
}
|
|
8373
8403
|
try {
|
|
8374
|
-
logger$
|
|
8404
|
+
logger$5.log `🔧 Loading config from ${configPath}`;
|
|
8375
8405
|
const configFile = fs.readFileSync(configPath, "utf8");
|
|
8376
8406
|
const parsed = JSON.parse(configFile);
|
|
8377
8407
|
return parseFromJson(parsed, NodeConfiguration.fromJson);
|
|
@@ -8381,7 +8411,7 @@ function loadConfig(configPath) {
|
|
|
8381
8411
|
}
|
|
8382
8412
|
}
|
|
8383
8413
|
|
|
8384
|
-
var index$
|
|
8414
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
8385
8415
|
__proto__: null,
|
|
8386
8416
|
DEFAULT_CONFIG: DEFAULT_CONFIG,
|
|
8387
8417
|
DEV_CONFIG: DEV_CONFIG,
|
|
@@ -8698,6 +8728,10 @@ class DisputesRecords {
|
|
|
8698
8728
|
static create({ goodSet, badSet, wonkySet, punishSet }) {
|
|
8699
8729
|
return new DisputesRecords(goodSet, badSet, wonkySet, punishSet);
|
|
8700
8730
|
}
|
|
8731
|
+
goodSetDict;
|
|
8732
|
+
badSetDict;
|
|
8733
|
+
wonkySetDict;
|
|
8734
|
+
punishSetDict;
|
|
8701
8735
|
constructor(
|
|
8702
8736
|
/** `goodSet`: all work-reports hashes which were judged to be correct */
|
|
8703
8737
|
goodSet,
|
|
@@ -8711,6 +8745,18 @@ class DisputesRecords {
|
|
|
8711
8745
|
this.badSet = badSet;
|
|
8712
8746
|
this.wonkySet = wonkySet;
|
|
8713
8747
|
this.punishSet = punishSet;
|
|
8748
|
+
this.goodSetDict = HashSet.from(goodSet.array);
|
|
8749
|
+
this.badSetDict = HashSet.from(badSet.array);
|
|
8750
|
+
this.wonkySetDict = HashSet.from(wonkySet.array);
|
|
8751
|
+
this.punishSetDict = HashSet.from(punishSet.array);
|
|
8752
|
+
}
|
|
8753
|
+
asDictionaries() {
|
|
8754
|
+
return {
|
|
8755
|
+
goodSet: this.goodSetDict,
|
|
8756
|
+
badSet: this.badSetDict,
|
|
8757
|
+
wonkySet: this.wonkySetDict,
|
|
8758
|
+
punishSet: this.punishSetDict,
|
|
8759
|
+
};
|
|
8714
8760
|
}
|
|
8715
8761
|
static fromSortedArrays({ goodSet, badSet, wonkySet, punishSet, }) {
|
|
8716
8762
|
return new DisputesRecords(SortedSet.fromSortedArray(hashComparator, goodSet), SortedSet.fromSortedArray(hashComparator, badSet), SortedSet.fromSortedArray(hashComparator, wonkySet), SortedSet.fromSortedArray(hashComparator, punishSet));
|
|
@@ -10047,7 +10093,7 @@ const serviceDataCodec = codec$1.dictionary(codec$1.u32.asOpaque(), serviceEntri
|
|
|
10047
10093
|
sortKeys: (a, b) => a - b,
|
|
10048
10094
|
});
|
|
10049
10095
|
|
|
10050
|
-
var index$
|
|
10096
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
10051
10097
|
__proto__: null,
|
|
10052
10098
|
AccumulationOutput: AccumulationOutput,
|
|
10053
10099
|
AutoAccumulate: AutoAccumulate,
|
|
@@ -11057,7 +11103,7 @@ const bitLookup = [
|
|
|
11057
11103
|
[0b00000000, 8],
|
|
11058
11104
|
];
|
|
11059
11105
|
|
|
11060
|
-
var index$
|
|
11106
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
11061
11107
|
__proto__: null,
|
|
11062
11108
|
BranchNode: BranchNode,
|
|
11063
11109
|
InMemoryTrie: InMemoryTrie,
|
|
@@ -11403,7 +11449,7 @@ function loadState(spec, entries) {
|
|
|
11403
11449
|
* hashmap of `key -> value` entries.
|
|
11404
11450
|
*/
|
|
11405
11451
|
|
|
11406
|
-
var index$
|
|
11452
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
11407
11453
|
__proto__: null,
|
|
11408
11454
|
SerializedService: SerializedService,
|
|
11409
11455
|
SerializedState: SerializedState,
|
|
@@ -11689,7 +11735,7 @@ class InMemoryStates {
|
|
|
11689
11735
|
}
|
|
11690
11736
|
}
|
|
11691
11737
|
|
|
11692
|
-
var index$
|
|
11738
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
11693
11739
|
__proto__: null,
|
|
11694
11740
|
InMemoryBlocks: InMemoryBlocks,
|
|
11695
11741
|
InMemoryStates: InMemoryStates,
|
|
@@ -12051,7 +12097,7 @@ const initEc = async () => {
|
|
|
12051
12097
|
await init.reedSolomon();
|
|
12052
12098
|
};
|
|
12053
12099
|
|
|
12054
|
-
var index$
|
|
12100
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
12055
12101
|
__proto__: null,
|
|
12056
12102
|
N_CHUNKS_REDUNDANCY: N_CHUNKS_REDUNDANCY,
|
|
12057
12103
|
N_CHUNKS_REQUIRED: N_CHUNKS_REQUIRED,
|
|
@@ -12075,6 +12121,439 @@ var index$a = /*#__PURE__*/Object.freeze({
|
|
|
12075
12121
|
unzip: unzip
|
|
12076
12122
|
});
|
|
12077
12123
|
|
|
12124
|
+
/**
|
|
12125
|
+
* Version ::= SEQUENCE {
|
|
12126
|
+
* major INTEGER (0..255),
|
|
12127
|
+
* minor INTEGER (0..255),
|
|
12128
|
+
* patch INTEGER (0..255)
|
|
12129
|
+
* }
|
|
12130
|
+
*/
|
|
12131
|
+
class Version extends WithDebug {
|
|
12132
|
+
major;
|
|
12133
|
+
minor;
|
|
12134
|
+
patch;
|
|
12135
|
+
static Codec = codec$1.Class(Version, {
|
|
12136
|
+
major: codec$1.u8,
|
|
12137
|
+
minor: codec$1.u8,
|
|
12138
|
+
patch: codec$1.u8,
|
|
12139
|
+
});
|
|
12140
|
+
static tryFromString(str) {
|
|
12141
|
+
const parse = (v) => tryAsU8(Number(v));
|
|
12142
|
+
try {
|
|
12143
|
+
const [major, minor, patch] = str.trim().split(".").map(parse);
|
|
12144
|
+
return Version.create({
|
|
12145
|
+
major,
|
|
12146
|
+
minor,
|
|
12147
|
+
patch,
|
|
12148
|
+
});
|
|
12149
|
+
}
|
|
12150
|
+
catch (e) {
|
|
12151
|
+
throw new Error(`Unable to parse ${str} as Version: ${e}`);
|
|
12152
|
+
}
|
|
12153
|
+
}
|
|
12154
|
+
static create({ major, minor, patch }) {
|
|
12155
|
+
return new Version(major, minor, patch);
|
|
12156
|
+
}
|
|
12157
|
+
constructor(major, minor, patch) {
|
|
12158
|
+
super();
|
|
12159
|
+
this.major = major;
|
|
12160
|
+
this.minor = minor;
|
|
12161
|
+
this.patch = patch;
|
|
12162
|
+
}
|
|
12163
|
+
}
|
|
12164
|
+
/**
|
|
12165
|
+
* Fuzzer Protocol V1
|
|
12166
|
+
* Reference: https://github.com/davxy/jam-conformance/blob/main/fuzz-proto/fuzz.asn
|
|
12167
|
+
*/
|
|
12168
|
+
// Feature bit constants
|
|
12169
|
+
var Features;
|
|
12170
|
+
(function (Features) {
|
|
12171
|
+
Features[Features["Ancestry"] = 1] = "Ancestry";
|
|
12172
|
+
Features[Features["Fork"] = 2] = "Fork";
|
|
12173
|
+
Features[Features["Reserved"] = 2147483648] = "Reserved";
|
|
12174
|
+
})(Features || (Features = {}));
|
|
12175
|
+
/**
|
|
12176
|
+
* PeerInfo ::= SEQUENCE {
|
|
12177
|
+
* fuzz-version U8,
|
|
12178
|
+
* features Features,
|
|
12179
|
+
* jam-version Version,
|
|
12180
|
+
* app-version Version,
|
|
12181
|
+
* name UTF8String
|
|
12182
|
+
* }
|
|
12183
|
+
*/
|
|
12184
|
+
class PeerInfo extends WithDebug {
|
|
12185
|
+
fuzzVersion;
|
|
12186
|
+
features;
|
|
12187
|
+
jamVersion;
|
|
12188
|
+
appVersion;
|
|
12189
|
+
name;
|
|
12190
|
+
static Codec = codec$1.Class(PeerInfo, {
|
|
12191
|
+
fuzzVersion: codec$1.u8,
|
|
12192
|
+
features: codec$1.u32,
|
|
12193
|
+
jamVersion: Version.Codec,
|
|
12194
|
+
appVersion: Version.Codec,
|
|
12195
|
+
name: codec$1.string,
|
|
12196
|
+
});
|
|
12197
|
+
static create({ fuzzVersion, features, appVersion, jamVersion, name }) {
|
|
12198
|
+
return new PeerInfo(fuzzVersion, features, jamVersion, appVersion, name);
|
|
12199
|
+
}
|
|
12200
|
+
constructor(fuzzVersion, features, jamVersion, appVersion, name) {
|
|
12201
|
+
super();
|
|
12202
|
+
this.fuzzVersion = fuzzVersion;
|
|
12203
|
+
this.features = features;
|
|
12204
|
+
this.jamVersion = jamVersion;
|
|
12205
|
+
this.appVersion = appVersion;
|
|
12206
|
+
this.name = name;
|
|
12207
|
+
}
|
|
12208
|
+
}
|
|
12209
|
+
/**
|
|
12210
|
+
* AncestryItem ::= SEQUENCE {
|
|
12211
|
+
* slot TimeSlot,
|
|
12212
|
+
* header-hash HeaderHash
|
|
12213
|
+
* }
|
|
12214
|
+
*/
|
|
12215
|
+
class AncestryItem extends WithDebug {
|
|
12216
|
+
slot;
|
|
12217
|
+
headerHash;
|
|
12218
|
+
static Codec = codec$1.Class(AncestryItem, {
|
|
12219
|
+
slot: codec$1.u32.asOpaque(),
|
|
12220
|
+
headerHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
12221
|
+
});
|
|
12222
|
+
static create({ slot, headerHash }) {
|
|
12223
|
+
return new AncestryItem(slot, headerHash);
|
|
12224
|
+
}
|
|
12225
|
+
constructor(slot, headerHash) {
|
|
12226
|
+
super();
|
|
12227
|
+
this.slot = slot;
|
|
12228
|
+
this.headerHash = headerHash;
|
|
12229
|
+
}
|
|
12230
|
+
}
|
|
12231
|
+
/**
|
|
12232
|
+
* KeyValue ::= SEQUENCE {
|
|
12233
|
+
* key TrieKey,
|
|
12234
|
+
* value OCTET STRING
|
|
12235
|
+
* }
|
|
12236
|
+
*/
|
|
12237
|
+
class KeyValue extends WithDebug {
|
|
12238
|
+
key;
|
|
12239
|
+
value;
|
|
12240
|
+
static Codec = codec$1.Class(KeyValue, {
|
|
12241
|
+
key: codec$1.bytes(TRUNCATED_HASH_SIZE),
|
|
12242
|
+
value: codec$1.blob,
|
|
12243
|
+
});
|
|
12244
|
+
static create({ key, value }) {
|
|
12245
|
+
return new KeyValue(key, value);
|
|
12246
|
+
}
|
|
12247
|
+
constructor(key, value) {
|
|
12248
|
+
super();
|
|
12249
|
+
this.key = key;
|
|
12250
|
+
this.value = value;
|
|
12251
|
+
}
|
|
12252
|
+
}
|
|
12253
|
+
/** State ::= SEQUENCE OF KeyValue */
|
|
12254
|
+
const stateCodec = codec$1.sequenceVarLen(KeyValue.Codec);
|
|
12255
|
+
/**
|
|
12256
|
+
* Ancestry ::= SEQUENCE (SIZE(0..24)) OF AncestryItem
|
|
12257
|
+
* Empty when `feature-ancestry` is not supported by both parties
|
|
12258
|
+
*/
|
|
12259
|
+
const ancestryCodec = codec$1.sequenceVarLen(AncestryItem.Codec, {
|
|
12260
|
+
minLength: 0,
|
|
12261
|
+
maxLength: 24,
|
|
12262
|
+
});
|
|
12263
|
+
/**
|
|
12264
|
+
* Initialize ::= SEQUENCE {
|
|
12265
|
+
* header Header,
|
|
12266
|
+
* keyvals State,
|
|
12267
|
+
* ancestry Ancestry
|
|
12268
|
+
* }
|
|
12269
|
+
*/
|
|
12270
|
+
class Initialize extends WithDebug {
|
|
12271
|
+
header;
|
|
12272
|
+
keyvals;
|
|
12273
|
+
ancestry;
|
|
12274
|
+
static Codec = codec$1.Class(Initialize, {
|
|
12275
|
+
header: Header.Codec,
|
|
12276
|
+
keyvals: stateCodec,
|
|
12277
|
+
ancestry: ancestryCodec,
|
|
12278
|
+
});
|
|
12279
|
+
static create({ header, keyvals, ancestry }) {
|
|
12280
|
+
return new Initialize(header, keyvals, ancestry);
|
|
12281
|
+
}
|
|
12282
|
+
constructor(header, keyvals, ancestry) {
|
|
12283
|
+
super();
|
|
12284
|
+
this.header = header;
|
|
12285
|
+
this.keyvals = keyvals;
|
|
12286
|
+
this.ancestry = ancestry;
|
|
12287
|
+
}
|
|
12288
|
+
}
|
|
12289
|
+
/** GetState ::= HeaderHash */
|
|
12290
|
+
const getStateCodec = codec$1.bytes(HASH_SIZE).asOpaque();
|
|
12291
|
+
/** StateRoot ::= StateRootHash */
|
|
12292
|
+
const stateRootCodec = codec$1.bytes(HASH_SIZE).asOpaque();
|
|
12293
|
+
/** Error ::= UTF8String */
|
|
12294
|
+
class ErrorMessage extends WithDebug {
|
|
12295
|
+
message;
|
|
12296
|
+
static Codec = codec$1.Class(ErrorMessage, {
|
|
12297
|
+
message: codec$1.string,
|
|
12298
|
+
});
|
|
12299
|
+
static create({ message }) {
|
|
12300
|
+
return new ErrorMessage(message);
|
|
12301
|
+
}
|
|
12302
|
+
constructor(message) {
|
|
12303
|
+
super();
|
|
12304
|
+
this.message = message;
|
|
12305
|
+
}
|
|
12306
|
+
}
|
|
12307
|
+
/** Message choice type tags */
|
|
12308
|
+
var MessageType;
|
|
12309
|
+
(function (MessageType) {
|
|
12310
|
+
MessageType[MessageType["PeerInfo"] = 0] = "PeerInfo";
|
|
12311
|
+
MessageType[MessageType["Initialize"] = 1] = "Initialize";
|
|
12312
|
+
MessageType[MessageType["StateRoot"] = 2] = "StateRoot";
|
|
12313
|
+
MessageType[MessageType["ImportBlock"] = 3] = "ImportBlock";
|
|
12314
|
+
MessageType[MessageType["GetState"] = 4] = "GetState";
|
|
12315
|
+
MessageType[MessageType["State"] = 5] = "State";
|
|
12316
|
+
MessageType[MessageType["Error"] = 255] = "Error";
|
|
12317
|
+
})(MessageType || (MessageType = {}));
|
|
12318
|
+
/**
|
|
12319
|
+
* Message ::= CHOICE {
|
|
12320
|
+
* peer-info [0] PeerInfo,
|
|
12321
|
+
* initialize [1] Initialize,
|
|
12322
|
+
* state-root [2] StateRoot,
|
|
12323
|
+
* import-block [3] ImportBlock,
|
|
12324
|
+
* get-state [4] GetState,
|
|
12325
|
+
* state [5] State,
|
|
12326
|
+
* error [255] Error
|
|
12327
|
+
* }
|
|
12328
|
+
*/
|
|
12329
|
+
const messageCodec = codec$1.custom({
|
|
12330
|
+
name: "Message",
|
|
12331
|
+
sizeHint: { bytes: 1, isExact: false },
|
|
12332
|
+
}, (e, msg) => {
|
|
12333
|
+
e.i8(msg.type);
|
|
12334
|
+
switch (msg.type) {
|
|
12335
|
+
case MessageType.PeerInfo:
|
|
12336
|
+
PeerInfo.Codec.encode(e, msg.value);
|
|
12337
|
+
break;
|
|
12338
|
+
case MessageType.Initialize:
|
|
12339
|
+
Initialize.Codec.encode(e, msg.value);
|
|
12340
|
+
break;
|
|
12341
|
+
case MessageType.StateRoot:
|
|
12342
|
+
stateRootCodec.encode(e, msg.value);
|
|
12343
|
+
break;
|
|
12344
|
+
case MessageType.ImportBlock:
|
|
12345
|
+
Block.Codec.View.encode(e, msg.value);
|
|
12346
|
+
break;
|
|
12347
|
+
case MessageType.GetState:
|
|
12348
|
+
getStateCodec.encode(e, msg.value);
|
|
12349
|
+
break;
|
|
12350
|
+
case MessageType.State:
|
|
12351
|
+
stateCodec.encode(e, msg.value);
|
|
12352
|
+
break;
|
|
12353
|
+
case MessageType.Error:
|
|
12354
|
+
ErrorMessage.Codec.encode(e, msg.value);
|
|
12355
|
+
break;
|
|
12356
|
+
default:
|
|
12357
|
+
throw new Error(`Unknown message type: ${msg}`);
|
|
12358
|
+
}
|
|
12359
|
+
}, (d) => {
|
|
12360
|
+
const type = d.u8();
|
|
12361
|
+
switch (type) {
|
|
12362
|
+
case MessageType.PeerInfo:
|
|
12363
|
+
return { type: MessageType.PeerInfo, value: PeerInfo.Codec.decode(d) };
|
|
12364
|
+
case MessageType.Initialize:
|
|
12365
|
+
return { type: MessageType.Initialize, value: Initialize.Codec.decode(d) };
|
|
12366
|
+
case MessageType.StateRoot:
|
|
12367
|
+
return { type: MessageType.StateRoot, value: stateRootCodec.decode(d) };
|
|
12368
|
+
case MessageType.ImportBlock:
|
|
12369
|
+
return { type: MessageType.ImportBlock, value: Block.Codec.View.decode(d) };
|
|
12370
|
+
case MessageType.GetState:
|
|
12371
|
+
return { type: MessageType.GetState, value: getStateCodec.decode(d) };
|
|
12372
|
+
case MessageType.State:
|
|
12373
|
+
return { type: MessageType.State, value: stateCodec.decode(d) };
|
|
12374
|
+
case MessageType.Error:
|
|
12375
|
+
return { type: MessageType.Error, value: ErrorMessage.Codec.decode(d) };
|
|
12376
|
+
default:
|
|
12377
|
+
throw new Error(`Unknown message type: ${type}`);
|
|
12378
|
+
}
|
|
12379
|
+
}, (s) => {
|
|
12380
|
+
const type = s.decoder.u8();
|
|
12381
|
+
switch (type) {
|
|
12382
|
+
case MessageType.PeerInfo:
|
|
12383
|
+
PeerInfo.Codec.View.skip(s);
|
|
12384
|
+
break;
|
|
12385
|
+
case MessageType.Initialize:
|
|
12386
|
+
Initialize.Codec.View.skip(s);
|
|
12387
|
+
break;
|
|
12388
|
+
case MessageType.StateRoot:
|
|
12389
|
+
stateRootCodec.View.skip(s);
|
|
12390
|
+
break;
|
|
12391
|
+
case MessageType.ImportBlock:
|
|
12392
|
+
Block.Codec.View.skip(s);
|
|
12393
|
+
break;
|
|
12394
|
+
case MessageType.GetState:
|
|
12395
|
+
getStateCodec.View.skip(s);
|
|
12396
|
+
break;
|
|
12397
|
+
case MessageType.State:
|
|
12398
|
+
stateCodec.View.skip(s);
|
|
12399
|
+
break;
|
|
12400
|
+
case MessageType.Error:
|
|
12401
|
+
ErrorMessage.Codec.View.skip(s);
|
|
12402
|
+
break;
|
|
12403
|
+
default:
|
|
12404
|
+
throw new Error(`Unknown message type: ${type}`);
|
|
12405
|
+
}
|
|
12406
|
+
});
|
|
12407
|
+
|
|
12408
|
+
const logger$4 = Logger.new(import.meta.filename, "ext-ipc-fuzz-v1");
|
|
12409
|
+
class FuzzTarget {
|
|
12410
|
+
msgHandler;
|
|
12411
|
+
sender;
|
|
12412
|
+
spec;
|
|
12413
|
+
sessionFeatures = 0;
|
|
12414
|
+
constructor(msgHandler, sender, spec) {
|
|
12415
|
+
this.msgHandler = msgHandler;
|
|
12416
|
+
this.sender = sender;
|
|
12417
|
+
this.spec = spec;
|
|
12418
|
+
}
|
|
12419
|
+
async onSocketMessage(msg) {
|
|
12420
|
+
// attempt to decode the messsage
|
|
12421
|
+
try {
|
|
12422
|
+
const message = Decoder.decodeObject(messageCodec, msg, this.spec);
|
|
12423
|
+
logger$4.log `[${message.type}] incoming message`;
|
|
12424
|
+
await this.processAndRespond(message);
|
|
12425
|
+
}
|
|
12426
|
+
catch (e) {
|
|
12427
|
+
logger$4.error `Error while processing fuzz v1 message: ${e}`;
|
|
12428
|
+
logger$4.error `${e}`;
|
|
12429
|
+
if (e instanceof Error) {
|
|
12430
|
+
logger$4.error `${e.stack ?? ""}`;
|
|
12431
|
+
}
|
|
12432
|
+
this.sender.close();
|
|
12433
|
+
}
|
|
12434
|
+
}
|
|
12435
|
+
async processAndRespond(message) {
|
|
12436
|
+
let response = null;
|
|
12437
|
+
switch (message.type) {
|
|
12438
|
+
case MessageType.PeerInfo: {
|
|
12439
|
+
// only support V1
|
|
12440
|
+
if (message.value.fuzzVersion !== 1) {
|
|
12441
|
+
logger$4.warn `Unsupported fuzzer protocol version: ${message.value.fuzzVersion}. Closing`;
|
|
12442
|
+
this.sender.close();
|
|
12443
|
+
return;
|
|
12444
|
+
}
|
|
12445
|
+
// Handle handshake
|
|
12446
|
+
const ourPeerInfo = await this.msgHandler.getPeerInfo(message.value);
|
|
12447
|
+
// Calculate session features (intersection of both peer features)
|
|
12448
|
+
this.sessionFeatures = message.value.features & ourPeerInfo.features;
|
|
12449
|
+
logger$4.info `Handshake completed. Shared features: 0b${this.sessionFeatures.toString(2)}`;
|
|
12450
|
+
logger$4.log `Feature ancestry: ${(this.sessionFeatures & Features.Ancestry) !== 0}`;
|
|
12451
|
+
logger$4.log `Feature fork: ${(this.sessionFeatures & Features.Fork) !== 0}`;
|
|
12452
|
+
response = {
|
|
12453
|
+
type: MessageType.PeerInfo,
|
|
12454
|
+
value: ourPeerInfo,
|
|
12455
|
+
};
|
|
12456
|
+
break;
|
|
12457
|
+
}
|
|
12458
|
+
case MessageType.Initialize: {
|
|
12459
|
+
const stateRoot = await this.msgHandler.initialize(message.value);
|
|
12460
|
+
response = {
|
|
12461
|
+
type: MessageType.StateRoot,
|
|
12462
|
+
value: stateRoot,
|
|
12463
|
+
};
|
|
12464
|
+
break;
|
|
12465
|
+
}
|
|
12466
|
+
case MessageType.ImportBlock: {
|
|
12467
|
+
const result = await this.msgHandler.importBlock(message.value);
|
|
12468
|
+
if (result.isOk) {
|
|
12469
|
+
response = {
|
|
12470
|
+
type: MessageType.StateRoot,
|
|
12471
|
+
value: result.ok,
|
|
12472
|
+
};
|
|
12473
|
+
}
|
|
12474
|
+
else {
|
|
12475
|
+
response = {
|
|
12476
|
+
type: MessageType.Error,
|
|
12477
|
+
value: result.error,
|
|
12478
|
+
};
|
|
12479
|
+
}
|
|
12480
|
+
break;
|
|
12481
|
+
}
|
|
12482
|
+
case MessageType.GetState: {
|
|
12483
|
+
const state = await this.msgHandler.getSerializedState(message.value);
|
|
12484
|
+
response = {
|
|
12485
|
+
type: MessageType.State,
|
|
12486
|
+
value: state,
|
|
12487
|
+
};
|
|
12488
|
+
break;
|
|
12489
|
+
}
|
|
12490
|
+
case MessageType.StateRoot: {
|
|
12491
|
+
logger$4.log `--> Received unexpected 'StateRoot' message from the fuzzer. Closing.`;
|
|
12492
|
+
this.sender.close();
|
|
12493
|
+
return;
|
|
12494
|
+
}
|
|
12495
|
+
case MessageType.State: {
|
|
12496
|
+
logger$4.log `--> Received unexpected 'State' message from the fuzzer. Closing.`;
|
|
12497
|
+
this.sender.close();
|
|
12498
|
+
return;
|
|
12499
|
+
}
|
|
12500
|
+
case MessageType.Error: {
|
|
12501
|
+
logger$4.log `--> Received unexpected 'Error' message from the fuzzer. Closing.`;
|
|
12502
|
+
this.sender.close();
|
|
12503
|
+
return;
|
|
12504
|
+
}
|
|
12505
|
+
default: {
|
|
12506
|
+
logger$4.log `--> Received unexpected message type ${JSON.stringify(message)} from the fuzzer. Closing.`;
|
|
12507
|
+
this.sender.close();
|
|
12508
|
+
try {
|
|
12509
|
+
assertNever(message);
|
|
12510
|
+
}
|
|
12511
|
+
catch {
|
|
12512
|
+
return;
|
|
12513
|
+
}
|
|
12514
|
+
}
|
|
12515
|
+
}
|
|
12516
|
+
if (response !== null) {
|
|
12517
|
+
logger$4.trace `<-- responding with: ${response.type}`;
|
|
12518
|
+
const encoded = Encoder.encodeObject(messageCodec, response, this.spec);
|
|
12519
|
+
this.sender.send(encoded);
|
|
12520
|
+
}
|
|
12521
|
+
else {
|
|
12522
|
+
logger$4.warn `<-- no response generated for: ${message.type}`;
|
|
12523
|
+
}
|
|
12524
|
+
}
|
|
12525
|
+
onClose({ error }) {
|
|
12526
|
+
logger$4.log `Closing the v1 handler. Reason: ${error !== undefined ? error.message : "close"}.`;
|
|
12527
|
+
}
|
|
12528
|
+
/** Check if a specific feature is enabled in the session */
|
|
12529
|
+
hasFeature(feature) {
|
|
12530
|
+
return (this.sessionFeatures & feature) !== 0;
|
|
12531
|
+
}
|
|
12532
|
+
}
|
|
12533
|
+
|
|
12534
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
12535
|
+
__proto__: null,
|
|
12536
|
+
AncestryItem: AncestryItem,
|
|
12537
|
+
ErrorMessage: ErrorMessage,
|
|
12538
|
+
get Features () { return Features; },
|
|
12539
|
+
FuzzTarget: FuzzTarget,
|
|
12540
|
+
Initialize: Initialize,
|
|
12541
|
+
KeyValue: KeyValue,
|
|
12542
|
+
get MessageType () { return MessageType; },
|
|
12543
|
+
PeerInfo: PeerInfo,
|
|
12544
|
+
Version: Version,
|
|
12545
|
+
ancestryCodec: ancestryCodec,
|
|
12546
|
+
getStateCodec: getStateCodec,
|
|
12547
|
+
messageCodec: messageCodec,
|
|
12548
|
+
stateCodec: stateCodec,
|
|
12549
|
+
stateRootCodec: stateRootCodec
|
|
12550
|
+
});
|
|
12551
|
+
|
|
12552
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
12553
|
+
__proto__: null,
|
|
12554
|
+
v1: index$b
|
|
12555
|
+
});
|
|
12556
|
+
|
|
12078
12557
|
/** Size of the transfer memo. */
|
|
12079
12558
|
const TRANSFER_MEMO_BYTES = W_T;
|
|
12080
12559
|
/**
|
|
@@ -12861,10 +13340,16 @@ function signExtend32To64(value) {
|
|
|
12861
13340
|
|
|
12862
13341
|
/** Attempt to convert a number into `HostCallIndex`. */
|
|
12863
13342
|
const tryAsHostCallIndex = (v) => asOpaqueType(tryAsU32(v));
|
|
13343
|
+
/**
|
|
13344
|
+
* Host-call exit reason.
|
|
13345
|
+
*
|
|
13346
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/24a30124a501?v=0.7.2
|
|
13347
|
+
*/
|
|
12864
13348
|
var PvmExecution;
|
|
12865
13349
|
(function (PvmExecution) {
|
|
12866
13350
|
PvmExecution[PvmExecution["Halt"] = 0] = "Halt";
|
|
12867
13351
|
PvmExecution[PvmExecution["Panic"] = 1] = "Panic";
|
|
13352
|
+
PvmExecution[PvmExecution["OOG"] = 2] = "OOG";
|
|
12868
13353
|
})(PvmExecution || (PvmExecution = {}));
|
|
12869
13354
|
/** A utility function to easily trace a bunch of registers. */
|
|
12870
13355
|
function traceRegisters(...regs) {
|
|
@@ -14122,6 +14607,17 @@ class PageRange {
|
|
|
14122
14607
|
}
|
|
14123
14608
|
return new PageRange(start, length);
|
|
14124
14609
|
}
|
|
14610
|
+
/** Returns true if the page range is wrapped (`start` >= `end`) and is not empty */
|
|
14611
|
+
isWrapped() {
|
|
14612
|
+
return this.start >= this.end && !this.isEmpty();
|
|
14613
|
+
}
|
|
14614
|
+
/** Checks if given page number is within the range */
|
|
14615
|
+
isInRange(page) {
|
|
14616
|
+
if (this.isWrapped()) {
|
|
14617
|
+
return page >= this.start || page < this.end;
|
|
14618
|
+
}
|
|
14619
|
+
return page >= this.start && page < this.end;
|
|
14620
|
+
}
|
|
14125
14621
|
/** Checks if a range is empty (`length === 0`) */
|
|
14126
14622
|
isEmpty() {
|
|
14127
14623
|
return this.length === 0;
|
|
@@ -14462,10 +14958,11 @@ class MemoryBuilder {
|
|
|
14462
14958
|
startHeapIndex (${startHeapIndex}) has to be less than or equal to endHeapIndex (${endHeapIndex})
|
|
14463
14959
|
`;
|
|
14464
14960
|
this.ensureNotFinalized();
|
|
14465
|
-
const
|
|
14466
|
-
const
|
|
14467
|
-
|
|
14468
|
-
|
|
14961
|
+
const heapRange = MemoryRange.fromStartAndLength(startHeapIndex, endHeapIndex - startHeapIndex);
|
|
14962
|
+
const heapPagesRange = PageRange.fromMemoryRange(heapRange);
|
|
14963
|
+
const initializedPageNumbers = Array.from(this.initialMemory.keys());
|
|
14964
|
+
for (const pageNumber of initializedPageNumbers) {
|
|
14965
|
+
if (heapPagesRange.isInRange(pageNumber)) {
|
|
14469
14966
|
throw new IncorrectSbrkIndex();
|
|
14470
14967
|
}
|
|
14471
14968
|
}
|
|
@@ -16487,8 +16984,9 @@ class HostCalls {
|
|
|
16487
16984
|
const index = tryAsHostCallIndex(hostCallIndex);
|
|
16488
16985
|
const hostCall = this.hostCalls.get(index);
|
|
16489
16986
|
const gasBefore = gas.get();
|
|
16490
|
-
|
|
16491
|
-
const
|
|
16987
|
+
// NOTE: `basicGasCost(regs)` function is for compatibility reasons: pre GP 0.7.2
|
|
16988
|
+
const basicGasCost = typeof hostCall.basicGasCost === "number" ? hostCall.basicGasCost : hostCall.basicGasCost(regs);
|
|
16989
|
+
const underflow = gas.sub(basicGasCost);
|
|
16492
16990
|
const pcLog = `[PC: ${pvmInstance.getPC()}]`;
|
|
16493
16991
|
if (underflow) {
|
|
16494
16992
|
this.hostCalls.traceHostCall(`${pcLog} OOG`, index, hostCall, regs, gas.get());
|
|
@@ -16505,6 +17003,10 @@ class HostCalls {
|
|
|
16505
17003
|
status = Status.PANIC;
|
|
16506
17004
|
return this.getReturnValue(status, pvmInstance);
|
|
16507
17005
|
}
|
|
17006
|
+
if (result === PvmExecution.OOG) {
|
|
17007
|
+
status = Status.OOG;
|
|
17008
|
+
return this.getReturnValue(status, pvmInstance);
|
|
17009
|
+
}
|
|
16508
17010
|
if (result === undefined) {
|
|
16509
17011
|
pvmInstance.runProgram();
|
|
16510
17012
|
status = pvmInstance.getStatus();
|
|
@@ -16905,8 +17407,8 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
16905
17407
|
asOpaqueType: asOpaqueType,
|
|
16906
17408
|
assertEmpty: assertEmpty,
|
|
16907
17409
|
assertNever: assertNever,
|
|
16908
|
-
block: index$
|
|
16909
|
-
bytes: index$
|
|
17410
|
+
block: index$l,
|
|
17411
|
+
bytes: index$s,
|
|
16910
17412
|
check: check,
|
|
16911
17413
|
clampU64ToU32: clampU64ToU32,
|
|
16912
17414
|
createResults: createResults,
|
|
@@ -16914,13 +17416,13 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
16914
17416
|
extractCodeAndMetadata: extractCodeAndMetadata,
|
|
16915
17417
|
getServiceId: getServiceId,
|
|
16916
17418
|
getServiceIdOrCurrent: getServiceIdOrCurrent,
|
|
16917
|
-
hash: index$
|
|
17419
|
+
hash: index$p,
|
|
16918
17420
|
inspect: inspect,
|
|
16919
17421
|
instructionArgumentTypeMap: instructionArgumentTypeMap,
|
|
16920
17422
|
interpreter: index$7,
|
|
16921
17423
|
isBrowser: isBrowser,
|
|
16922
17424
|
measure: measure,
|
|
16923
|
-
numbers: index$
|
|
17425
|
+
numbers: index$r,
|
|
16924
17426
|
resultToString: resultToString,
|
|
16925
17427
|
seeThrough: seeThrough,
|
|
16926
17428
|
slotsToPreimageStatus: slotsToPreimageStatus,
|
|
@@ -17494,7 +17996,7 @@ class Preimages {
|
|
|
17494
17996
|
|
|
17495
17997
|
class Missing {
|
|
17496
17998
|
index = tryAsHostCallIndex(2 ** 32 - 1);
|
|
17497
|
-
|
|
17999
|
+
basicGasCost = tryAsSmallGas(10);
|
|
17498
18000
|
currentServiceId = CURRENT_SERVICE_ID;
|
|
17499
18001
|
tracedRegisters = traceRegisters(7);
|
|
17500
18002
|
execute(_gas, regs, _memory) {
|
|
@@ -17634,4 +18136,4 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
17634
18136
|
WorkPackageExecutor: WorkPackageExecutor
|
|
17635
18137
|
});
|
|
17636
18138
|
|
|
17637
|
-
export { index$
|
|
18139
|
+
export { index$l as block, index$j as block_json, index$s as bytes, index$q as codec, index$n as collections, index$m as config, index$h as config_node, index$o as crypto, index$d as database, index$c as erasure_coding, index$a as fuzz_proto, index$p as hash, index$9 as jam_host_calls, index$k as json_parser, index$i as logger, index$8 as mmr, index$r as numbers, index$t as ordering, index$3 as pvm, index$6 as pvm_host_calls, index$7 as pvm_interpreter, index$4 as pvm_program, index$5 as pvm_spi_decoder, index$2 as shuffling, index$g as state, index$1 as state_json, index$e as state_merkleization, index as transition, index$f as trie, index$u as utils };
|