@typeberry/lib 0.1.2-ef67dce → 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 +524 -52
- package/index.d.ts +1252 -661
- package/index.js +505 -34
- package/package.json +1 -1
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,
|
|
@@ -7276,7 +7287,7 @@ function emptyBlock(slot = tryAsTimeSlot(0)) {
|
|
|
7276
7287
|
});
|
|
7277
7288
|
}
|
|
7278
7289
|
|
|
7279
|
-
var index$
|
|
7290
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
7280
7291
|
__proto__: null,
|
|
7281
7292
|
Block: Block,
|
|
7282
7293
|
EpochMarker: EpochMarker,
|
|
@@ -7532,7 +7543,7 @@ var json;
|
|
|
7532
7543
|
json.object = object;
|
|
7533
7544
|
})(json || (json = {}));
|
|
7534
7545
|
|
|
7535
|
-
var index$
|
|
7546
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
7536
7547
|
__proto__: null,
|
|
7537
7548
|
get json () { return json; },
|
|
7538
7549
|
parseFromJson: parseFromJson
|
|
@@ -7802,7 +7813,7 @@ const blockFromJson = (spec) => json.object({
|
|
|
7802
7813
|
extrinsic: getExtrinsicFromJson(spec),
|
|
7803
7814
|
}, ({ header, extrinsic }) => Block.create({ header, extrinsic }));
|
|
7804
7815
|
|
|
7805
|
-
var index$
|
|
7816
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
7806
7817
|
__proto__: null,
|
|
7807
7818
|
blockFromJson: blockFromJson,
|
|
7808
7819
|
disputesExtrinsicFromJson: disputesExtrinsicFromJson,
|
|
@@ -8300,7 +8311,7 @@ class Logger {
|
|
|
8300
8311
|
}
|
|
8301
8312
|
}
|
|
8302
8313
|
|
|
8303
|
-
var index$
|
|
8314
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
8304
8315
|
__proto__: null,
|
|
8305
8316
|
get Level () { return Level; },
|
|
8306
8317
|
Logger: Logger,
|
|
@@ -8323,7 +8334,7 @@ class AuthorshipOptions {
|
|
|
8323
8334
|
}
|
|
8324
8335
|
}
|
|
8325
8336
|
|
|
8326
|
-
const logger$
|
|
8337
|
+
const logger$5 = Logger.new(import.meta.filename, "config");
|
|
8327
8338
|
/** Development config. Will accept unsealed blocks for now. */
|
|
8328
8339
|
const DEV_CONFIG = "dev";
|
|
8329
8340
|
/** Default config file. */
|
|
@@ -8382,15 +8393,15 @@ class NodeConfiguration {
|
|
|
8382
8393
|
}
|
|
8383
8394
|
function loadConfig(configPath) {
|
|
8384
8395
|
if (configPath === DEFAULT_CONFIG) {
|
|
8385
|
-
logger$
|
|
8396
|
+
logger$5.log `🔧 Loading DEFAULT config`;
|
|
8386
8397
|
return parseFromJson(configs.default, NodeConfiguration.fromJson);
|
|
8387
8398
|
}
|
|
8388
8399
|
if (configPath === DEV_CONFIG) {
|
|
8389
|
-
logger$
|
|
8400
|
+
logger$5.log `🔧 Loading DEV config`;
|
|
8390
8401
|
return parseFromJson(configs.dev, NodeConfiguration.fromJson);
|
|
8391
8402
|
}
|
|
8392
8403
|
try {
|
|
8393
|
-
logger$
|
|
8404
|
+
logger$5.log `🔧 Loading config from ${configPath}`;
|
|
8394
8405
|
const configFile = fs.readFileSync(configPath, "utf8");
|
|
8395
8406
|
const parsed = JSON.parse(configFile);
|
|
8396
8407
|
return parseFromJson(parsed, NodeConfiguration.fromJson);
|
|
@@ -8400,7 +8411,7 @@ function loadConfig(configPath) {
|
|
|
8400
8411
|
}
|
|
8401
8412
|
}
|
|
8402
8413
|
|
|
8403
|
-
var index$
|
|
8414
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
8404
8415
|
__proto__: null,
|
|
8405
8416
|
DEFAULT_CONFIG: DEFAULT_CONFIG,
|
|
8406
8417
|
DEV_CONFIG: DEV_CONFIG,
|
|
@@ -8717,6 +8728,10 @@ class DisputesRecords {
|
|
|
8717
8728
|
static create({ goodSet, badSet, wonkySet, punishSet }) {
|
|
8718
8729
|
return new DisputesRecords(goodSet, badSet, wonkySet, punishSet);
|
|
8719
8730
|
}
|
|
8731
|
+
goodSetDict;
|
|
8732
|
+
badSetDict;
|
|
8733
|
+
wonkySetDict;
|
|
8734
|
+
punishSetDict;
|
|
8720
8735
|
constructor(
|
|
8721
8736
|
/** `goodSet`: all work-reports hashes which were judged to be correct */
|
|
8722
8737
|
goodSet,
|
|
@@ -8730,6 +8745,18 @@ class DisputesRecords {
|
|
|
8730
8745
|
this.badSet = badSet;
|
|
8731
8746
|
this.wonkySet = wonkySet;
|
|
8732
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
|
+
};
|
|
8733
8760
|
}
|
|
8734
8761
|
static fromSortedArrays({ goodSet, badSet, wonkySet, punishSet, }) {
|
|
8735
8762
|
return new DisputesRecords(SortedSet.fromSortedArray(hashComparator, goodSet), SortedSet.fromSortedArray(hashComparator, badSet), SortedSet.fromSortedArray(hashComparator, wonkySet), SortedSet.fromSortedArray(hashComparator, punishSet));
|
|
@@ -10066,7 +10093,7 @@ const serviceDataCodec = codec$1.dictionary(codec$1.u32.asOpaque(), serviceEntri
|
|
|
10066
10093
|
sortKeys: (a, b) => a - b,
|
|
10067
10094
|
});
|
|
10068
10095
|
|
|
10069
|
-
var index$
|
|
10096
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
10070
10097
|
__proto__: null,
|
|
10071
10098
|
AccumulationOutput: AccumulationOutput,
|
|
10072
10099
|
AutoAccumulate: AutoAccumulate,
|
|
@@ -11076,7 +11103,7 @@ const bitLookup = [
|
|
|
11076
11103
|
[0b00000000, 8],
|
|
11077
11104
|
];
|
|
11078
11105
|
|
|
11079
|
-
var index$
|
|
11106
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
11080
11107
|
__proto__: null,
|
|
11081
11108
|
BranchNode: BranchNode,
|
|
11082
11109
|
InMemoryTrie: InMemoryTrie,
|
|
@@ -11422,7 +11449,7 @@ function loadState(spec, entries) {
|
|
|
11422
11449
|
* hashmap of `key -> value` entries.
|
|
11423
11450
|
*/
|
|
11424
11451
|
|
|
11425
|
-
var index$
|
|
11452
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
11426
11453
|
__proto__: null,
|
|
11427
11454
|
SerializedService: SerializedService,
|
|
11428
11455
|
SerializedState: SerializedState,
|
|
@@ -11708,7 +11735,7 @@ class InMemoryStates {
|
|
|
11708
11735
|
}
|
|
11709
11736
|
}
|
|
11710
11737
|
|
|
11711
|
-
var index$
|
|
11738
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
11712
11739
|
__proto__: null,
|
|
11713
11740
|
InMemoryBlocks: InMemoryBlocks,
|
|
11714
11741
|
InMemoryStates: InMemoryStates,
|
|
@@ -12070,7 +12097,7 @@ const initEc = async () => {
|
|
|
12070
12097
|
await init.reedSolomon();
|
|
12071
12098
|
};
|
|
12072
12099
|
|
|
12073
|
-
var index$
|
|
12100
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
12074
12101
|
__proto__: null,
|
|
12075
12102
|
N_CHUNKS_REDUNDANCY: N_CHUNKS_REDUNDANCY,
|
|
12076
12103
|
N_CHUNKS_REQUIRED: N_CHUNKS_REQUIRED,
|
|
@@ -12094,6 +12121,439 @@ var index$a = /*#__PURE__*/Object.freeze({
|
|
|
12094
12121
|
unzip: unzip
|
|
12095
12122
|
});
|
|
12096
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
|
+
|
|
12097
12557
|
/** Size of the transfer memo. */
|
|
12098
12558
|
const TRANSFER_MEMO_BYTES = W_T;
|
|
12099
12559
|
/**
|
|
@@ -12880,10 +13340,16 @@ function signExtend32To64(value) {
|
|
|
12880
13340
|
|
|
12881
13341
|
/** Attempt to convert a number into `HostCallIndex`. */
|
|
12882
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
|
+
*/
|
|
12883
13348
|
var PvmExecution;
|
|
12884
13349
|
(function (PvmExecution) {
|
|
12885
13350
|
PvmExecution[PvmExecution["Halt"] = 0] = "Halt";
|
|
12886
13351
|
PvmExecution[PvmExecution["Panic"] = 1] = "Panic";
|
|
13352
|
+
PvmExecution[PvmExecution["OOG"] = 2] = "OOG";
|
|
12887
13353
|
})(PvmExecution || (PvmExecution = {}));
|
|
12888
13354
|
/** A utility function to easily trace a bunch of registers. */
|
|
12889
13355
|
function traceRegisters(...regs) {
|
|
@@ -16518,8 +16984,9 @@ class HostCalls {
|
|
|
16518
16984
|
const index = tryAsHostCallIndex(hostCallIndex);
|
|
16519
16985
|
const hostCall = this.hostCalls.get(index);
|
|
16520
16986
|
const gasBefore = gas.get();
|
|
16521
|
-
|
|
16522
|
-
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);
|
|
16523
16990
|
const pcLog = `[PC: ${pvmInstance.getPC()}]`;
|
|
16524
16991
|
if (underflow) {
|
|
16525
16992
|
this.hostCalls.traceHostCall(`${pcLog} OOG`, index, hostCall, regs, gas.get());
|
|
@@ -16536,6 +17003,10 @@ class HostCalls {
|
|
|
16536
17003
|
status = Status.PANIC;
|
|
16537
17004
|
return this.getReturnValue(status, pvmInstance);
|
|
16538
17005
|
}
|
|
17006
|
+
if (result === PvmExecution.OOG) {
|
|
17007
|
+
status = Status.OOG;
|
|
17008
|
+
return this.getReturnValue(status, pvmInstance);
|
|
17009
|
+
}
|
|
16539
17010
|
if (result === undefined) {
|
|
16540
17011
|
pvmInstance.runProgram();
|
|
16541
17012
|
status = pvmInstance.getStatus();
|
|
@@ -16936,8 +17407,8 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
16936
17407
|
asOpaqueType: asOpaqueType,
|
|
16937
17408
|
assertEmpty: assertEmpty,
|
|
16938
17409
|
assertNever: assertNever,
|
|
16939
|
-
block: index$
|
|
16940
|
-
bytes: index$
|
|
17410
|
+
block: index$l,
|
|
17411
|
+
bytes: index$s,
|
|
16941
17412
|
check: check,
|
|
16942
17413
|
clampU64ToU32: clampU64ToU32,
|
|
16943
17414
|
createResults: createResults,
|
|
@@ -16945,13 +17416,13 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
16945
17416
|
extractCodeAndMetadata: extractCodeAndMetadata,
|
|
16946
17417
|
getServiceId: getServiceId,
|
|
16947
17418
|
getServiceIdOrCurrent: getServiceIdOrCurrent,
|
|
16948
|
-
hash: index$
|
|
17419
|
+
hash: index$p,
|
|
16949
17420
|
inspect: inspect,
|
|
16950
17421
|
instructionArgumentTypeMap: instructionArgumentTypeMap,
|
|
16951
17422
|
interpreter: index$7,
|
|
16952
17423
|
isBrowser: isBrowser,
|
|
16953
17424
|
measure: measure,
|
|
16954
|
-
numbers: index$
|
|
17425
|
+
numbers: index$r,
|
|
16955
17426
|
resultToString: resultToString,
|
|
16956
17427
|
seeThrough: seeThrough,
|
|
16957
17428
|
slotsToPreimageStatus: slotsToPreimageStatus,
|
|
@@ -17525,7 +17996,7 @@ class Preimages {
|
|
|
17525
17996
|
|
|
17526
17997
|
class Missing {
|
|
17527
17998
|
index = tryAsHostCallIndex(2 ** 32 - 1);
|
|
17528
|
-
|
|
17999
|
+
basicGasCost = tryAsSmallGas(10);
|
|
17529
18000
|
currentServiceId = CURRENT_SERVICE_ID;
|
|
17530
18001
|
tracedRegisters = traceRegisters(7);
|
|
17531
18002
|
execute(_gas, regs, _memory) {
|
|
@@ -17665,4 +18136,4 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
17665
18136
|
WorkPackageExecutor: WorkPackageExecutor
|
|
17666
18137
|
});
|
|
17667
18138
|
|
|
17668
|
-
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 };
|