@typeberry/jam 0.1.3-8fd7637 → 0.1.3-b0374a8
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/bootstrap-generator.mjs +285 -252
- package/bootstrap-generator.mjs.map +1 -1
- package/bootstrap-importer.mjs +414 -326
- package/bootstrap-importer.mjs.map +1 -1
- package/bootstrap-network.mjs +287 -253
- package/bootstrap-network.mjs.map +1 -1
- package/index.js +416 -327
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -24332,8 +24332,9 @@ function parseCurrentVersion(env) {
|
|
|
24332
24332
|
}
|
|
24333
24333
|
}
|
|
24334
24334
|
function parseCurrentSuite(env) {
|
|
24335
|
-
if (env === undefined)
|
|
24335
|
+
if (env === undefined) {
|
|
24336
24336
|
return undefined;
|
|
24337
|
+
}
|
|
24337
24338
|
switch (env) {
|
|
24338
24339
|
case TestSuite.W3F_DAVXY:
|
|
24339
24340
|
case TestSuite.JAMDUNA:
|
|
@@ -24764,10 +24765,12 @@ function deepEqual(actual, expected, { context = [], errorsCollector, ignore = [
|
|
|
24764
24765
|
.sort((a, b) => {
|
|
24765
24766
|
const aKey = `${a.key}`;
|
|
24766
24767
|
const bKey = `${b.key}`;
|
|
24767
|
-
if (aKey < bKey)
|
|
24768
|
+
if (aKey < bKey) {
|
|
24768
24769
|
return -1;
|
|
24769
|
-
|
|
24770
|
+
}
|
|
24771
|
+
if (bKey < aKey) {
|
|
24770
24772
|
return 1;
|
|
24773
|
+
}
|
|
24771
24774
|
return 0;
|
|
24772
24775
|
});
|
|
24773
24776
|
};
|
|
@@ -25779,7 +25782,7 @@ class Skipper {
|
|
|
25779
25782
|
*
|
|
25780
25783
|
* Descriptors can be composed to form more complex typings.
|
|
25781
25784
|
*/
|
|
25782
|
-
class
|
|
25785
|
+
class Descriptor {
|
|
25783
25786
|
name;
|
|
25784
25787
|
sizeHint;
|
|
25785
25788
|
encode;
|
|
@@ -25789,11 +25792,11 @@ class descriptor_Descriptor {
|
|
|
25789
25792
|
View;
|
|
25790
25793
|
/** New descriptor with specialized `View`. */
|
|
25791
25794
|
static withView(name, sizeHint, encode, decode, skip, view) {
|
|
25792
|
-
return new
|
|
25795
|
+
return new Descriptor(name, sizeHint, encode, decode, skip, view);
|
|
25793
25796
|
}
|
|
25794
25797
|
/** Create a new descriptor without a specialized `View`. */
|
|
25795
25798
|
static new(name, sizeHint, encode, decode, skip) {
|
|
25796
|
-
return new
|
|
25799
|
+
return new Descriptor(name, sizeHint, encode, decode, skip, null);
|
|
25797
25800
|
}
|
|
25798
25801
|
constructor(
|
|
25799
25802
|
/** Descriptive name of the coded data. */
|
|
@@ -25830,7 +25833,7 @@ class descriptor_Descriptor {
|
|
|
25830
25833
|
}
|
|
25831
25834
|
/** Return a new descriptor that converts data into some other type. */
|
|
25832
25835
|
convert(input, output) {
|
|
25833
|
-
return new
|
|
25836
|
+
return new Descriptor(this.name, this.sizeHint, (e, elem) => this.encode(e, input(elem)), (d) => output(this.decode(d)), this.skip, this.View);
|
|
25834
25837
|
}
|
|
25835
25838
|
/** Safely cast the descriptor value to a opaque type. */
|
|
25836
25839
|
asOpaque() {
|
|
@@ -26528,51 +26531,51 @@ var descriptors_codec;
|
|
|
26528
26531
|
return (len) => {
|
|
26529
26532
|
let ret = cache.get(len);
|
|
26530
26533
|
if (ret === undefined) {
|
|
26531
|
-
ret =
|
|
26534
|
+
ret = Descriptor.new(`Bytes<${len}>`, exactHint(len), (e, v) => e.bytes(v), (d) => d.bytes(len), (s) => s.bytes(len));
|
|
26532
26535
|
cache.set(len, ret);
|
|
26533
26536
|
}
|
|
26534
26537
|
return ret;
|
|
26535
26538
|
};
|
|
26536
26539
|
})();
|
|
26537
26540
|
/** Variable-length U32. */
|
|
26538
|
-
codec.varU32 =
|
|
26541
|
+
codec.varU32 = Descriptor.new("var_u32", { bytes: 4, isExact: false }, (e, v) => e.varU32(v), (d) => d.varU32(), (d) => d.varU32());
|
|
26539
26542
|
/** Variable-length U64. */
|
|
26540
|
-
codec.varU64 =
|
|
26543
|
+
codec.varU64 = Descriptor.new("var_u64", { bytes: 8, isExact: false }, (e, v) => e.varU64(v), (d) => d.varU64(), (d) => d.varU64());
|
|
26541
26544
|
/** Unsigned 64-bit number. */
|
|
26542
|
-
codec.u64 =
|
|
26545
|
+
codec.u64 = Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.u64(), (d) => d.u64(), codec.bytes(8));
|
|
26543
26546
|
/** Unsigned 32-bit number. */
|
|
26544
|
-
codec.u32 =
|
|
26547
|
+
codec.u32 = Descriptor.withView("u32", exactHint(4), (e, v) => e.i32(v), (d) => d.u32(), (d) => d.u32(), codec.bytes(4));
|
|
26545
26548
|
/** Unsigned 24-bit number. */
|
|
26546
|
-
codec.u24 =
|
|
26549
|
+
codec.u24 = Descriptor.withView("u24", exactHint(3), (e, v) => e.i24(v), (d) => d.u24(), (d) => d.u24(), codec.bytes(3));
|
|
26547
26550
|
/** Unsigned 16-bit number. */
|
|
26548
|
-
codec.u16 =
|
|
26551
|
+
codec.u16 = Descriptor.withView("u16", exactHint(2), (e, v) => e.i16(v), (d) => d.u16(), (d) => d.u16(), codec.bytes(2));
|
|
26549
26552
|
/** Unsigned 8-bit number. */
|
|
26550
|
-
codec.u8 =
|
|
26553
|
+
codec.u8 = Descriptor.new("u8", exactHint(1), (e, v) => e.i8(v), (d) => d.u8(), (d) => d.u8());
|
|
26551
26554
|
/** Signed 64-bit number. */
|
|
26552
|
-
codec.i64 =
|
|
26555
|
+
codec.i64 = Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.i64(), (s) => s.u64(), codec.bytes(8));
|
|
26553
26556
|
/** Signed 32-bit number. */
|
|
26554
|
-
codec.i32 =
|
|
26557
|
+
codec.i32 = Descriptor.withView("i32", exactHint(4), (e, v) => e.i32(v), (d) => d.i32(), (s) => s.u32(), codec.bytes(4));
|
|
26555
26558
|
/** Signed 24-bit number. */
|
|
26556
|
-
codec.i24 =
|
|
26559
|
+
codec.i24 = Descriptor.withView("i24", exactHint(3), (e, v) => e.i24(v), (d) => d.i24(), (s) => s.u24(), codec.bytes(3));
|
|
26557
26560
|
/** Signed 16-bit number. */
|
|
26558
|
-
codec.i16 =
|
|
26561
|
+
codec.i16 = Descriptor.withView("i16", exactHint(2), (e, v) => e.i16(v), (d) => d.i16(), (s) => s.u16(), codec.bytes(2));
|
|
26559
26562
|
/** Signed 8-bit number. */
|
|
26560
|
-
codec.i8 =
|
|
26563
|
+
codec.i8 = Descriptor.new("i8", exactHint(1), (e, v) => e.i8(v), (d) => d.i8(), (s) => s.u8());
|
|
26561
26564
|
/** 1-byte boolean value. */
|
|
26562
|
-
codec.bool =
|
|
26565
|
+
codec.bool = Descriptor.new("bool", exactHint(1), (e, v) => e.bool(v), (d) => d.bool(), (s) => s.bool());
|
|
26563
26566
|
/** Variable-length bytes blob. */
|
|
26564
|
-
codec.blob =
|
|
26567
|
+
codec.blob = Descriptor.new("BytesBlob", { bytes: TYPICAL_SEQUENCE_LENGTH, isExact: false }, (e, v) => e.bytesBlob(v), (d) => d.bytesBlob(), (s) => s.bytesBlob());
|
|
26565
26568
|
/** String encoded as variable-length bytes blob. */
|
|
26566
|
-
codec.string =
|
|
26569
|
+
codec.string = Descriptor.withView("string", { bytes: TYPICAL_SEQUENCE_LENGTH, isExact: false }, (e, v) => e.bytesBlob(bytes_BytesBlob.blobFrom(new TextEncoder().encode(v))), (d) => new TextDecoder("utf8", { fatal: true }).decode(d.bytesBlob().raw), (s) => s.bytesBlob(), codec.blob);
|
|
26567
26570
|
/** Variable-length bit vector. */
|
|
26568
|
-
codec.bitVecVarLen =
|
|
26571
|
+
codec.bitVecVarLen = Descriptor.new("BitVec[?]", { bytes: TYPICAL_SEQUENCE_LENGTH >>> 3, isExact: false }, (e, v) => e.bitVecVarLen(v), (d) => d.bitVecVarLen(), (s) => s.bitVecVarLen());
|
|
26569
26572
|
/** Fixed-length bit vector. */
|
|
26570
|
-
codec.bitVecFixLen = (bitLen) =>
|
|
26573
|
+
codec.bitVecFixLen = (bitLen) => Descriptor.new(`BitVec[${bitLen}]`, exactHint(bitLen >>> 3), (e, v) => e.bitVecFixLen(v), (d) => d.bitVecFixLen(bitLen), (s) => s.bitVecFixLen(bitLen));
|
|
26571
26574
|
/** Optionality wrapper for given type. */
|
|
26572
26575
|
codec.optional = (type) => {
|
|
26573
|
-
const self =
|
|
26576
|
+
const self = Descriptor.new(`Optional<${type.name}>`, addSizeHints({ bytes: 1, isExact: false }, type.sizeHint), (e, v) => e.optional(type, v), (d) => d.optional(type), (s) => s.optional(type));
|
|
26574
26577
|
if (hasUniqueView(type)) {
|
|
26575
|
-
return
|
|
26578
|
+
return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.optional(type.View));
|
|
26576
26579
|
}
|
|
26577
26580
|
return self;
|
|
26578
26581
|
};
|
|
@@ -26583,7 +26586,7 @@ var descriptors_codec;
|
|
|
26583
26586
|
}) => {
|
|
26584
26587
|
const name = `Sequence<${type.name}>[?]`;
|
|
26585
26588
|
const typicalLength = options.typicalLength ?? TYPICAL_SEQUENCE_LENGTH;
|
|
26586
|
-
return
|
|
26589
|
+
return Descriptor.withView(name, { bytes: typicalLength * type.sizeHint.bytes, isExact: false }, (e, v) => {
|
|
26587
26590
|
validateLength(options, v.length, name);
|
|
26588
26591
|
e.sequenceVarLen(type, v);
|
|
26589
26592
|
}, (d) => {
|
|
@@ -26597,10 +26600,10 @@ var descriptors_codec;
|
|
|
26597
26600
|
}, sequenceViewVarLen(type, options));
|
|
26598
26601
|
};
|
|
26599
26602
|
/** Fixed-length sequence of given type. */
|
|
26600
|
-
codec.sequenceFixLen = (type, len) =>
|
|
26603
|
+
codec.sequenceFixLen = (type, len) => Descriptor.withView(`Sequence<${type.name}>[${len}]`, { bytes: len * type.sizeHint.bytes, isExact: type.sizeHint.isExact }, (e, v) => e.sequenceFixLen(type, v), (d) => d.sequenceFixLen(type, len), (s) => s.sequenceFixLen(type, len), sequenceViewFixLen(type, { fixedLength: len }));
|
|
26601
26604
|
/** Small dictionary codec. */
|
|
26602
26605
|
codec.dictionary = (key, value, { sortKeys, fixedLength, }) => {
|
|
26603
|
-
const self =
|
|
26606
|
+
const self = Descriptor.new(`Dictionary<${key.name}, ${value.name}>[${fixedLength ?? "?"}]`, {
|
|
26604
26607
|
bytes: fixedLength !== undefined
|
|
26605
26608
|
? fixedLength * addSizeHints(key.sizeHint, value.sizeHint).bytes
|
|
26606
26609
|
: TYPICAL_DICTIONARY_LENGTH * (addSizeHints(key.sizeHint, value.sizeHint).bytes ?? 0),
|
|
@@ -26639,13 +26642,13 @@ var descriptors_codec;
|
|
|
26639
26642
|
s.sequenceFixLen(value, len);
|
|
26640
26643
|
});
|
|
26641
26644
|
if (hasUniqueView(value)) {
|
|
26642
|
-
return
|
|
26645
|
+
return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.dictionary(key, value.View, { sortKeys, fixedLength }));
|
|
26643
26646
|
}
|
|
26644
26647
|
return self;
|
|
26645
26648
|
};
|
|
26646
26649
|
/** Encoding of pair of two values. */
|
|
26647
26650
|
codec.pair = (a, b) => {
|
|
26648
|
-
const self =
|
|
26651
|
+
const self = Descriptor.new(`Pair<${a.name}, ${b.name}>`, addSizeHints(a.sizeHint, b.sizeHint), (e, elem) => {
|
|
26649
26652
|
a.encode(e, elem[0]);
|
|
26650
26653
|
b.encode(e, elem[1]);
|
|
26651
26654
|
}, (d) => {
|
|
@@ -26657,14 +26660,14 @@ var descriptors_codec;
|
|
|
26657
26660
|
b.skip(s);
|
|
26658
26661
|
});
|
|
26659
26662
|
if (hasUniqueView(a) && hasUniqueView(b)) {
|
|
26660
|
-
return
|
|
26663
|
+
return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.pair(a.View, b.View));
|
|
26661
26664
|
}
|
|
26662
26665
|
return self;
|
|
26663
26666
|
};
|
|
26664
26667
|
/** Custom encoding / decoding logic. */
|
|
26665
|
-
codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) =>
|
|
26668
|
+
codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
|
|
26666
26669
|
/** Choose a descriptor depending on the encoding/decoding context. */
|
|
26667
|
-
codec.select = ({ name, sizeHint, }, chooser) =>
|
|
26670
|
+
codec.select = ({ name, sizeHint, }, chooser) => Descriptor.withView(name, sizeHint, (e, x) => chooser(e.getContext()).encode(e, x), (d) => chooser(d.getContext()).decode(d), (s) => chooser(s.decoder.getContext()).skip(s), chooser(null).View);
|
|
26668
26671
|
/**
|
|
26669
26672
|
* A descriptor for a more complex POJO.
|
|
26670
26673
|
*
|
|
@@ -26701,7 +26704,7 @@ var descriptors_codec;
|
|
|
26701
26704
|
};
|
|
26702
26705
|
const view = objectView(Class, descriptors, sizeHint, skipper);
|
|
26703
26706
|
// and create the descriptor for the entire class.
|
|
26704
|
-
return
|
|
26707
|
+
return Descriptor.withView(Class.name, sizeHint, (e, t) => {
|
|
26705
26708
|
forEachDescriptor(descriptors, (key, descriptor) => {
|
|
26706
26709
|
const value = t[key];
|
|
26707
26710
|
descriptor.encode(e, value);
|
|
@@ -26752,7 +26755,7 @@ function objectView(Class, descriptors, sizeHint, skipper) {
|
|
|
26752
26755
|
});
|
|
26753
26756
|
}
|
|
26754
26757
|
});
|
|
26755
|
-
return
|
|
26758
|
+
return Descriptor.new(`View<${Class.name}>`, sizeHint, (e, t) => {
|
|
26756
26759
|
const encoded = t.encoded();
|
|
26757
26760
|
e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
|
|
26758
26761
|
}, (d) => {
|
|
@@ -26771,7 +26774,7 @@ function sequenceViewVarLen(type, options) {
|
|
|
26771
26774
|
validateLength(options, length, name);
|
|
26772
26775
|
return s.sequenceFixLen(type, length);
|
|
26773
26776
|
};
|
|
26774
|
-
return
|
|
26777
|
+
return Descriptor.new(name, sizeHint, (e, t) => {
|
|
26775
26778
|
validateLength(options, t.length, name);
|
|
26776
26779
|
const encoded = t.encoded();
|
|
26777
26780
|
e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
|
|
@@ -26787,7 +26790,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
|
|
|
26787
26790
|
const skipper = (s) => s.sequenceFixLen(type, fixedLength);
|
|
26788
26791
|
const view = type.name !== type.View.name ? `, ${type.View.name}` : "";
|
|
26789
26792
|
const name = `SeqView<${type.name}${view}>[${fixedLength}]`;
|
|
26790
|
-
return
|
|
26793
|
+
return Descriptor.new(name, sizeHint, (e, t) => {
|
|
26791
26794
|
const encoded = t.encoded();
|
|
26792
26795
|
e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
|
|
26793
26796
|
}, (d) => {
|
|
@@ -29088,7 +29091,7 @@ const codecFixedSizeArray = (val, len) => {
|
|
|
29088
29091
|
};
|
|
29089
29092
|
/** Codec for a hash-dictionary. */
|
|
29090
29093
|
const codecHashDictionary = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH, compare = (a, b) => extractKey(a).compare(extractKey(b)), } = {}) => {
|
|
29091
|
-
return
|
|
29094
|
+
return Descriptor.new(`HashDictionary<${value.name}>[?]`, {
|
|
29092
29095
|
bytes: typicalLength * value.sizeHint.bytes,
|
|
29093
29096
|
isExact: false,
|
|
29094
29097
|
}, (e, v) => {
|
|
@@ -32151,6 +32154,13 @@ const W_T = 128;
|
|
|
32151
32154
|
/** `W_M`: The maximum number of exports in a work-package. */
|
|
32152
32155
|
const W_X = 3_072;
|
|
32153
32156
|
// TODO [ToDr] Not sure where these should live yet :(
|
|
32157
|
+
/**
|
|
32158
|
+
* `S`: The minimum public service index.
|
|
32159
|
+
* Services of indices below these may only be created by the Registrar.
|
|
32160
|
+
*
|
|
32161
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
|
|
32162
|
+
*/
|
|
32163
|
+
const MIN_PUBLIC_SERVICE_INDEX = 2 ** 16;
|
|
32154
32164
|
/**
|
|
32155
32165
|
* `J`: The maximum sum of dependency items in a work-report.
|
|
32156
32166
|
*
|
|
@@ -32162,9 +32172,209 @@ const AUTHORIZATION_QUEUE_SIZE = Q;
|
|
|
32162
32172
|
/** `O`: Maximal authorization pool size. */
|
|
32163
32173
|
const MAX_AUTH_POOL_SIZE = O;
|
|
32164
32174
|
|
|
32175
|
+
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
|
|
32176
|
+
const MAX_VALUE = 4294967295;
|
|
32177
|
+
const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
|
|
32178
|
+
const MIN_VALUE = -(2 ** 31);
|
|
32179
|
+
const MAX_SHIFT_U32 = 32;
|
|
32180
|
+
const MAX_SHIFT_U64 = 64n;
|
|
32181
|
+
|
|
32182
|
+
;// CONCATENATED MODULE: ./packages/jam/state/service.ts
|
|
32183
|
+
|
|
32184
|
+
|
|
32185
|
+
|
|
32186
|
+
|
|
32187
|
+
|
|
32188
|
+
|
|
32189
|
+
/**
|
|
32190
|
+
* `B_S`: The basic minimum balance which all services require.
|
|
32191
|
+
*
|
|
32192
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
32193
|
+
*/
|
|
32194
|
+
const BASE_SERVICE_BALANCE = 100n;
|
|
32195
|
+
/**
|
|
32196
|
+
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
32197
|
+
*
|
|
32198
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
32199
|
+
*/
|
|
32200
|
+
const ELECTIVE_ITEM_BALANCE = 10n;
|
|
32201
|
+
/**
|
|
32202
|
+
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
32203
|
+
*
|
|
32204
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
32205
|
+
*/
|
|
32206
|
+
const ELECTIVE_BYTE_BALANCE = 1n;
|
|
32207
|
+
const zeroSizeHint = {
|
|
32208
|
+
bytes: 0,
|
|
32209
|
+
isExact: true,
|
|
32210
|
+
};
|
|
32211
|
+
/** 0-byte read, return given default value */
|
|
32212
|
+
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
32213
|
+
/** Encode and decode object with leading version number. */
|
|
32214
|
+
const codecWithVersion = (val) => Descriptor.new("withVersion", {
|
|
32215
|
+
bytes: val.sizeHint.bytes + 8,
|
|
32216
|
+
isExact: false,
|
|
32217
|
+
}, (e, v) => {
|
|
32218
|
+
e.varU64(0n);
|
|
32219
|
+
val.encode(e, v);
|
|
32220
|
+
}, (d) => {
|
|
32221
|
+
const version = d.varU64();
|
|
32222
|
+
if (version !== 0n) {
|
|
32223
|
+
throw new Error("Non-zero version is not supported!");
|
|
32224
|
+
}
|
|
32225
|
+
return val.decode(d);
|
|
32226
|
+
}, (s) => {
|
|
32227
|
+
s.varU64();
|
|
32228
|
+
val.skip(s);
|
|
32229
|
+
});
|
|
32230
|
+
/**
|
|
32231
|
+
* Service account details.
|
|
32232
|
+
*
|
|
32233
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
|
|
32234
|
+
*/
|
|
32235
|
+
class ServiceAccountInfo extends WithDebug {
|
|
32236
|
+
codeHash;
|
|
32237
|
+
balance;
|
|
32238
|
+
accumulateMinGas;
|
|
32239
|
+
onTransferMinGas;
|
|
32240
|
+
storageUtilisationBytes;
|
|
32241
|
+
gratisStorage;
|
|
32242
|
+
storageUtilisationCount;
|
|
32243
|
+
created;
|
|
32244
|
+
lastAccumulation;
|
|
32245
|
+
parentService;
|
|
32246
|
+
static Codec = descriptors_codec.Class(ServiceAccountInfo, {
|
|
32247
|
+
codeHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
32248
|
+
balance: descriptors_codec.u64,
|
|
32249
|
+
accumulateMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
|
|
32250
|
+
onTransferMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
|
|
32251
|
+
storageUtilisationBytes: descriptors_codec.u64,
|
|
32252
|
+
gratisStorage: descriptors_codec.u64,
|
|
32253
|
+
storageUtilisationCount: descriptors_codec.u32,
|
|
32254
|
+
created: descriptors_codec.u32.convert((x) => x, tryAsTimeSlot),
|
|
32255
|
+
lastAccumulation: descriptors_codec.u32.convert((x) => x, tryAsTimeSlot),
|
|
32256
|
+
parentService: descriptors_codec.u32.convert((x) => x, tryAsServiceId),
|
|
32257
|
+
});
|
|
32258
|
+
static create(a) {
|
|
32259
|
+
return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
|
|
32260
|
+
}
|
|
32261
|
+
/**
|
|
32262
|
+
* `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
|
|
32263
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
|
|
32264
|
+
*/
|
|
32265
|
+
static calculateThresholdBalance(items, bytes, gratisStorage) {
|
|
32266
|
+
const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
|
|
32267
|
+
if (storageCost < 0n) {
|
|
32268
|
+
return numbers_tryAsU64(0);
|
|
32269
|
+
}
|
|
32270
|
+
if (storageCost >= 2n ** 64n) {
|
|
32271
|
+
return numbers_tryAsU64(2n ** 64n - 1n);
|
|
32272
|
+
}
|
|
32273
|
+
return numbers_tryAsU64(storageCost);
|
|
32274
|
+
}
|
|
32275
|
+
constructor(
|
|
32276
|
+
/** `a_c`: Hash of the service code. */
|
|
32277
|
+
codeHash,
|
|
32278
|
+
/** `a_b`: Current account balance. */
|
|
32279
|
+
balance,
|
|
32280
|
+
/** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
|
|
32281
|
+
accumulateMinGas,
|
|
32282
|
+
/** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
|
|
32283
|
+
onTransferMinGas,
|
|
32284
|
+
/** `a_o`: Total number of octets in storage. */
|
|
32285
|
+
storageUtilisationBytes,
|
|
32286
|
+
/** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
|
|
32287
|
+
gratisStorage,
|
|
32288
|
+
/** `a_i`: Number of items in storage. */
|
|
32289
|
+
storageUtilisationCount,
|
|
32290
|
+
/** `a_r`: Creation account time slot. */
|
|
32291
|
+
created,
|
|
32292
|
+
/** `a_a`: Most recent accumulation time slot. */
|
|
32293
|
+
lastAccumulation,
|
|
32294
|
+
/** `a_p`: Parent service ID. */
|
|
32295
|
+
parentService) {
|
|
32296
|
+
super();
|
|
32297
|
+
this.codeHash = codeHash;
|
|
32298
|
+
this.balance = balance;
|
|
32299
|
+
this.accumulateMinGas = accumulateMinGas;
|
|
32300
|
+
this.onTransferMinGas = onTransferMinGas;
|
|
32301
|
+
this.storageUtilisationBytes = storageUtilisationBytes;
|
|
32302
|
+
this.gratisStorage = gratisStorage;
|
|
32303
|
+
this.storageUtilisationCount = storageUtilisationCount;
|
|
32304
|
+
this.created = created;
|
|
32305
|
+
this.lastAccumulation = lastAccumulation;
|
|
32306
|
+
this.parentService = parentService;
|
|
32307
|
+
}
|
|
32308
|
+
}
|
|
32309
|
+
class PreimageItem extends WithDebug {
|
|
32310
|
+
hash;
|
|
32311
|
+
blob;
|
|
32312
|
+
static Codec = descriptors_codec.Class(PreimageItem, {
|
|
32313
|
+
hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
32314
|
+
blob: descriptors_codec.blob,
|
|
32315
|
+
});
|
|
32316
|
+
static create({ hash, blob }) {
|
|
32317
|
+
return new PreimageItem(hash, blob);
|
|
32318
|
+
}
|
|
32319
|
+
constructor(hash, blob) {
|
|
32320
|
+
super();
|
|
32321
|
+
this.hash = hash;
|
|
32322
|
+
this.blob = blob;
|
|
32323
|
+
}
|
|
32324
|
+
}
|
|
32325
|
+
class StorageItem extends WithDebug {
|
|
32326
|
+
key;
|
|
32327
|
+
value;
|
|
32328
|
+
static Codec = descriptors_codec.Class(StorageItem, {
|
|
32329
|
+
key: descriptors_codec.blob.convert((i) => i, (o) => opaque_asOpaqueType(o)),
|
|
32330
|
+
value: descriptors_codec.blob,
|
|
32331
|
+
});
|
|
32332
|
+
static create({ key, value }) {
|
|
32333
|
+
return new StorageItem(key, value);
|
|
32334
|
+
}
|
|
32335
|
+
constructor(key, value) {
|
|
32336
|
+
super();
|
|
32337
|
+
this.key = key;
|
|
32338
|
+
this.value = value;
|
|
32339
|
+
}
|
|
32340
|
+
}
|
|
32341
|
+
const MAX_LOOKUP_HISTORY_SLOTS = 3;
|
|
32342
|
+
function tryAsLookupHistorySlots(items) {
|
|
32343
|
+
const knownSize = sized_array_asKnownSize(items);
|
|
32344
|
+
if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
|
|
32345
|
+
throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
|
|
32346
|
+
}
|
|
32347
|
+
return knownSize;
|
|
32348
|
+
}
|
|
32349
|
+
/** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
|
|
32350
|
+
class LookupHistoryItem {
|
|
32351
|
+
hash;
|
|
32352
|
+
length;
|
|
32353
|
+
slots;
|
|
32354
|
+
constructor(hash, length,
|
|
32355
|
+
/**
|
|
32356
|
+
* Preimage availability history as a sequence of time slots.
|
|
32357
|
+
* See PreimageStatus and the following GP fragment for more details.
|
|
32358
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
|
|
32359
|
+
slots) {
|
|
32360
|
+
this.hash = hash;
|
|
32361
|
+
this.length = length;
|
|
32362
|
+
this.slots = slots;
|
|
32363
|
+
}
|
|
32364
|
+
static isRequested(item) {
|
|
32365
|
+
if ("slots" in item) {
|
|
32366
|
+
return item.slots.length === 0;
|
|
32367
|
+
}
|
|
32368
|
+
return item.length === 0;
|
|
32369
|
+
}
|
|
32370
|
+
}
|
|
32371
|
+
|
|
32165
32372
|
;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
|
|
32166
32373
|
|
|
32167
32374
|
|
|
32375
|
+
|
|
32376
|
+
|
|
32377
|
+
|
|
32168
32378
|
/** Dictionary entry of services that auto-accumulate every block. */
|
|
32169
32379
|
class AutoAccumulate {
|
|
32170
32380
|
service;
|
|
@@ -32186,39 +32396,50 @@ class AutoAccumulate {
|
|
|
32186
32396
|
}
|
|
32187
32397
|
}
|
|
32188
32398
|
/**
|
|
32189
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
32399
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
|
|
32190
32400
|
*/
|
|
32191
32401
|
class PrivilegedServices {
|
|
32192
32402
|
manager;
|
|
32193
|
-
|
|
32194
|
-
|
|
32403
|
+
delegator;
|
|
32404
|
+
registrar;
|
|
32405
|
+
assigners;
|
|
32195
32406
|
autoAccumulateServices;
|
|
32407
|
+
/** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
|
|
32196
32408
|
static Codec = descriptors_codec.Class(PrivilegedServices, {
|
|
32197
32409
|
manager: descriptors_codec.u32.asOpaque(),
|
|
32198
|
-
|
|
32199
|
-
|
|
32410
|
+
assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
|
|
32411
|
+
delegator: descriptors_codec.u32.asOpaque(),
|
|
32412
|
+
registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
32413
|
+
? descriptors_codec.u32.asOpaque()
|
|
32414
|
+
: ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
|
|
32200
32415
|
autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
|
|
32201
32416
|
});
|
|
32202
|
-
static create(
|
|
32203
|
-
return new PrivilegedServices(manager,
|
|
32417
|
+
static create(a) {
|
|
32418
|
+
return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
32204
32419
|
}
|
|
32205
32420
|
constructor(
|
|
32206
32421
|
/**
|
|
32207
|
-
*
|
|
32208
|
-
* the service able to effect an alteration of χ from block to block,
|
|
32422
|
+
* `χ_M`: Manages alteration of χ from block to block,
|
|
32209
32423
|
* as well as bestow services with storage deposit credits.
|
|
32210
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
32424
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
32211
32425
|
*/
|
|
32212
32426
|
manager,
|
|
32213
|
-
/**
|
|
32214
|
-
|
|
32215
|
-
/**
|
|
32216
|
-
|
|
32217
|
-
|
|
32427
|
+
/** `χ_V`: Managers validator keys. */
|
|
32428
|
+
delegator,
|
|
32429
|
+
/**
|
|
32430
|
+
* `χ_R`: Manages the creation of services in protected range.
|
|
32431
|
+
*
|
|
32432
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
|
|
32433
|
+
*/
|
|
32434
|
+
registrar,
|
|
32435
|
+
/** `χ_A`: Manages authorization queue one for each core. */
|
|
32436
|
+
assigners,
|
|
32437
|
+
/** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
|
|
32218
32438
|
autoAccumulateServices) {
|
|
32219
32439
|
this.manager = manager;
|
|
32220
|
-
this.
|
|
32221
|
-
this.
|
|
32440
|
+
this.delegator = delegator;
|
|
32441
|
+
this.registrar = registrar;
|
|
32442
|
+
this.assigners = assigners;
|
|
32222
32443
|
this.autoAccumulateServices = autoAccumulateServices;
|
|
32223
32444
|
}
|
|
32224
32445
|
}
|
|
@@ -32306,7 +32527,7 @@ class RecentBlocks extends WithDebug {
|
|
|
32306
32527
|
*/
|
|
32307
32528
|
class RecentBlocksHistory extends WithDebug {
|
|
32308
32529
|
current;
|
|
32309
|
-
static Codec =
|
|
32530
|
+
static Codec = Descriptor.new("RecentBlocksHistory", RecentBlocks.Codec.sizeHint, (encoder, value) => RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
|
|
32310
32531
|
const recentBlocks = RecentBlocks.Codec.decode(decoder);
|
|
32311
32532
|
return RecentBlocksHistory.create(recentBlocks);
|
|
32312
32533
|
}, (skip) => {
|
|
@@ -32503,196 +32724,6 @@ class SafroleData {
|
|
|
32503
32724
|
}
|
|
32504
32725
|
}
|
|
32505
32726
|
|
|
32506
|
-
;// CONCATENATED MODULE: ./packages/jam/state/service.ts
|
|
32507
|
-
|
|
32508
|
-
|
|
32509
|
-
|
|
32510
|
-
|
|
32511
|
-
|
|
32512
|
-
|
|
32513
|
-
/**
|
|
32514
|
-
* `B_S`: The basic minimum balance which all services require.
|
|
32515
|
-
*
|
|
32516
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
32517
|
-
*/
|
|
32518
|
-
const BASE_SERVICE_BALANCE = 100n;
|
|
32519
|
-
/**
|
|
32520
|
-
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
32521
|
-
*
|
|
32522
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
32523
|
-
*/
|
|
32524
|
-
const ELECTIVE_ITEM_BALANCE = 10n;
|
|
32525
|
-
/**
|
|
32526
|
-
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
32527
|
-
*
|
|
32528
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
32529
|
-
*/
|
|
32530
|
-
const ELECTIVE_BYTE_BALANCE = 1n;
|
|
32531
|
-
const zeroSizeHint = {
|
|
32532
|
-
bytes: 0,
|
|
32533
|
-
isExact: true,
|
|
32534
|
-
};
|
|
32535
|
-
/** 0-byte read, return given default value */
|
|
32536
|
-
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
32537
|
-
/** Encode and decode object with leading version number. */
|
|
32538
|
-
const codecWithVersion = (val) => descriptor_Descriptor.new("withVersion", {
|
|
32539
|
-
bytes: val.sizeHint.bytes + 8,
|
|
32540
|
-
isExact: false,
|
|
32541
|
-
}, (e, v) => {
|
|
32542
|
-
e.varU64(0n);
|
|
32543
|
-
val.encode(e, v);
|
|
32544
|
-
}, (d) => {
|
|
32545
|
-
const version = d.varU64();
|
|
32546
|
-
if (version !== 0n) {
|
|
32547
|
-
throw new Error("Non-zero version is not supported!");
|
|
32548
|
-
}
|
|
32549
|
-
return val.decode(d);
|
|
32550
|
-
}, (s) => {
|
|
32551
|
-
s.varU64();
|
|
32552
|
-
val.skip(s);
|
|
32553
|
-
});
|
|
32554
|
-
/**
|
|
32555
|
-
* Service account details.
|
|
32556
|
-
*
|
|
32557
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
|
|
32558
|
-
*/
|
|
32559
|
-
class ServiceAccountInfo extends WithDebug {
|
|
32560
|
-
codeHash;
|
|
32561
|
-
balance;
|
|
32562
|
-
accumulateMinGas;
|
|
32563
|
-
onTransferMinGas;
|
|
32564
|
-
storageUtilisationBytes;
|
|
32565
|
-
gratisStorage;
|
|
32566
|
-
storageUtilisationCount;
|
|
32567
|
-
created;
|
|
32568
|
-
lastAccumulation;
|
|
32569
|
-
parentService;
|
|
32570
|
-
static Codec = descriptors_codec.Class(ServiceAccountInfo, {
|
|
32571
|
-
codeHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
32572
|
-
balance: descriptors_codec.u64,
|
|
32573
|
-
accumulateMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
|
|
32574
|
-
onTransferMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
|
|
32575
|
-
storageUtilisationBytes: descriptors_codec.u64,
|
|
32576
|
-
gratisStorage: descriptors_codec.u64,
|
|
32577
|
-
storageUtilisationCount: descriptors_codec.u32,
|
|
32578
|
-
created: descriptors_codec.u32.convert((x) => x, tryAsTimeSlot),
|
|
32579
|
-
lastAccumulation: descriptors_codec.u32.convert((x) => x, tryAsTimeSlot),
|
|
32580
|
-
parentService: descriptors_codec.u32.convert((x) => x, tryAsServiceId),
|
|
32581
|
-
});
|
|
32582
|
-
static create(a) {
|
|
32583
|
-
return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
|
|
32584
|
-
}
|
|
32585
|
-
/**
|
|
32586
|
-
* `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
|
|
32587
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
|
|
32588
|
-
*/
|
|
32589
|
-
static calculateThresholdBalance(items, bytes, gratisStorage) {
|
|
32590
|
-
const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
|
|
32591
|
-
if (storageCost < 0n) {
|
|
32592
|
-
return numbers_tryAsU64(0);
|
|
32593
|
-
}
|
|
32594
|
-
if (storageCost >= 2n ** 64n) {
|
|
32595
|
-
return numbers_tryAsU64(2n ** 64n - 1n);
|
|
32596
|
-
}
|
|
32597
|
-
return numbers_tryAsU64(storageCost);
|
|
32598
|
-
}
|
|
32599
|
-
constructor(
|
|
32600
|
-
/** `a_c`: Hash of the service code. */
|
|
32601
|
-
codeHash,
|
|
32602
|
-
/** `a_b`: Current account balance. */
|
|
32603
|
-
balance,
|
|
32604
|
-
/** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
|
|
32605
|
-
accumulateMinGas,
|
|
32606
|
-
/** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
|
|
32607
|
-
onTransferMinGas,
|
|
32608
|
-
/** `a_o`: Total number of octets in storage. */
|
|
32609
|
-
storageUtilisationBytes,
|
|
32610
|
-
/** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
|
|
32611
|
-
gratisStorage,
|
|
32612
|
-
/** `a_i`: Number of items in storage. */
|
|
32613
|
-
storageUtilisationCount,
|
|
32614
|
-
/** `a_r`: Creation account time slot. */
|
|
32615
|
-
created,
|
|
32616
|
-
/** `a_a`: Most recent accumulation time slot. */
|
|
32617
|
-
lastAccumulation,
|
|
32618
|
-
/** `a_p`: Parent service ID. */
|
|
32619
|
-
parentService) {
|
|
32620
|
-
super();
|
|
32621
|
-
this.codeHash = codeHash;
|
|
32622
|
-
this.balance = balance;
|
|
32623
|
-
this.accumulateMinGas = accumulateMinGas;
|
|
32624
|
-
this.onTransferMinGas = onTransferMinGas;
|
|
32625
|
-
this.storageUtilisationBytes = storageUtilisationBytes;
|
|
32626
|
-
this.gratisStorage = gratisStorage;
|
|
32627
|
-
this.storageUtilisationCount = storageUtilisationCount;
|
|
32628
|
-
this.created = created;
|
|
32629
|
-
this.lastAccumulation = lastAccumulation;
|
|
32630
|
-
this.parentService = parentService;
|
|
32631
|
-
}
|
|
32632
|
-
}
|
|
32633
|
-
class PreimageItem extends WithDebug {
|
|
32634
|
-
hash;
|
|
32635
|
-
blob;
|
|
32636
|
-
static Codec = descriptors_codec.Class(PreimageItem, {
|
|
32637
|
-
hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
32638
|
-
blob: descriptors_codec.blob,
|
|
32639
|
-
});
|
|
32640
|
-
static create({ hash, blob }) {
|
|
32641
|
-
return new PreimageItem(hash, blob);
|
|
32642
|
-
}
|
|
32643
|
-
constructor(hash, blob) {
|
|
32644
|
-
super();
|
|
32645
|
-
this.hash = hash;
|
|
32646
|
-
this.blob = blob;
|
|
32647
|
-
}
|
|
32648
|
-
}
|
|
32649
|
-
class StorageItem extends WithDebug {
|
|
32650
|
-
key;
|
|
32651
|
-
value;
|
|
32652
|
-
static Codec = descriptors_codec.Class(StorageItem, {
|
|
32653
|
-
key: descriptors_codec.blob.convert((i) => i, (o) => opaque_asOpaqueType(o)),
|
|
32654
|
-
value: descriptors_codec.blob,
|
|
32655
|
-
});
|
|
32656
|
-
static create({ key, value }) {
|
|
32657
|
-
return new StorageItem(key, value);
|
|
32658
|
-
}
|
|
32659
|
-
constructor(key, value) {
|
|
32660
|
-
super();
|
|
32661
|
-
this.key = key;
|
|
32662
|
-
this.value = value;
|
|
32663
|
-
}
|
|
32664
|
-
}
|
|
32665
|
-
const MAX_LOOKUP_HISTORY_SLOTS = 3;
|
|
32666
|
-
function tryAsLookupHistorySlots(items) {
|
|
32667
|
-
const knownSize = sized_array_asKnownSize(items);
|
|
32668
|
-
if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
|
|
32669
|
-
throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
|
|
32670
|
-
}
|
|
32671
|
-
return knownSize;
|
|
32672
|
-
}
|
|
32673
|
-
/** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
|
|
32674
|
-
class LookupHistoryItem {
|
|
32675
|
-
hash;
|
|
32676
|
-
length;
|
|
32677
|
-
slots;
|
|
32678
|
-
constructor(hash, length,
|
|
32679
|
-
/**
|
|
32680
|
-
* Preimage availability history as a sequence of time slots.
|
|
32681
|
-
* See PreimageStatus and the following GP fragment for more details.
|
|
32682
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
|
|
32683
|
-
slots) {
|
|
32684
|
-
this.hash = hash;
|
|
32685
|
-
this.length = length;
|
|
32686
|
-
this.slots = slots;
|
|
32687
|
-
}
|
|
32688
|
-
static isRequested(item) {
|
|
32689
|
-
if ("slots" in item) {
|
|
32690
|
-
return item.slots.length === 0;
|
|
32691
|
-
}
|
|
32692
|
-
return item.length === 0;
|
|
32693
|
-
}
|
|
32694
|
-
}
|
|
32695
|
-
|
|
32696
32727
|
;// CONCATENATED MODULE: ./packages/jam/state/state.ts
|
|
32697
32728
|
/**
|
|
32698
32729
|
* In addition to the entropy accumulator η_0, we retain
|
|
@@ -33129,6 +33160,7 @@ class StatisticsData {
|
|
|
33129
33160
|
|
|
33130
33161
|
|
|
33131
33162
|
|
|
33163
|
+
|
|
33132
33164
|
|
|
33133
33165
|
|
|
33134
33166
|
var in_memory_state_UpdateError;
|
|
@@ -33532,8 +33564,9 @@ class InMemoryState extends WithDebug {
|
|
|
33532
33564
|
epochRoot: bytes_Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
33533
33565
|
privilegedServices: PrivilegedServices.create({
|
|
33534
33566
|
manager: tryAsServiceId(0),
|
|
33535
|
-
|
|
33536
|
-
|
|
33567
|
+
assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
|
|
33568
|
+
delegator: tryAsServiceId(0),
|
|
33569
|
+
registrar: tryAsServiceId(MAX_VALUE),
|
|
33537
33570
|
autoAccumulateServices: [],
|
|
33538
33571
|
}),
|
|
33539
33572
|
accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
|
|
@@ -33769,7 +33802,7 @@ var serialize;
|
|
|
33769
33802
|
* determine the boundary of the bytes, so it can only be used
|
|
33770
33803
|
* as the last element of the codec and can't be used in sequences!
|
|
33771
33804
|
*/
|
|
33772
|
-
const dumpCodec =
|
|
33805
|
+
const dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }, (e, v) => e.bytes(bytes_Bytes.fromBlob(v.raw, v.raw.length)), (d) => bytes_BytesBlob.blobFrom(d.bytes(d.source.length - d.bytesRead()).raw), (s) => s.bytes(s.decoder.source.length - s.decoder.bytesRead()));
|
|
33773
33806
|
|
|
33774
33807
|
;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
|
|
33775
33808
|
|
|
@@ -35080,7 +35113,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
|
|
|
35080
35113
|
}
|
|
35081
35114
|
return Ordering.Equal;
|
|
35082
35115
|
}, } = {}) => {
|
|
35083
|
-
return
|
|
35116
|
+
return Descriptor.new(`Map<${value.name}>[?]`, {
|
|
35084
35117
|
bytes: typicalLength * value.sizeHint.bytes,
|
|
35085
35118
|
isExact: false,
|
|
35086
35119
|
}, (e, v) => {
|
|
@@ -39178,8 +39211,9 @@ class ce_129_state_request_Handler {
|
|
|
39178
39211
|
onStreamMessage(sender, message) {
|
|
39179
39212
|
if (this.isServer) {
|
|
39180
39213
|
ce_129_state_request_logger.info `[${sender.streamId}][server]: Received request.`;
|
|
39181
|
-
if (this.getBoundaryNodes === undefined || this.getKeyValuePairs === undefined)
|
|
39214
|
+
if (this.getBoundaryNodes === undefined || this.getKeyValuePairs === undefined) {
|
|
39182
39215
|
return;
|
|
39216
|
+
}
|
|
39183
39217
|
const request = decoder_Decoder.decodeObject(StateRequest.Codec, message);
|
|
39184
39218
|
const boundaryNodes = this.getBoundaryNodes(request.headerHash, request.startKey, request.endKey);
|
|
39185
39219
|
const keyValuePairs = this.getKeyValuePairs(request.headerHash, request.startKey, request.endKey);
|
|
@@ -41904,7 +41938,7 @@ class AccumulationStateUpdate {
|
|
|
41904
41938
|
if (from.privilegedServices !== null) {
|
|
41905
41939
|
update.privilegedServices = PrivilegedServices.create({
|
|
41906
41940
|
...from.privilegedServices,
|
|
41907
|
-
|
|
41941
|
+
assigners: sized_array_asKnownSize([...from.privilegedServices.assigners]),
|
|
41908
41942
|
});
|
|
41909
41943
|
}
|
|
41910
41944
|
return update;
|
|
@@ -44043,13 +44077,6 @@ class BitOps {
|
|
|
44043
44077
|
}
|
|
44044
44078
|
}
|
|
44045
44079
|
|
|
44046
|
-
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
|
|
44047
|
-
const MAX_VALUE = 4294967295;
|
|
44048
|
-
const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
|
|
44049
|
-
const MIN_VALUE = -(2 ** 31);
|
|
44050
|
-
const MAX_SHIFT_U32 = 32;
|
|
44051
|
-
const MAX_SHIFT_U64 = 64n;
|
|
44052
|
-
|
|
44053
44080
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-utils.ts
|
|
44054
44081
|
|
|
44055
44082
|
|
|
@@ -46079,6 +46106,8 @@ var NewServiceError;
|
|
|
46079
46106
|
NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
|
|
46080
46107
|
/** Service is not privileged to set gratis storage. */
|
|
46081
46108
|
NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
|
|
46109
|
+
/** Registrar attempting to create a service with already existing id. */
|
|
46110
|
+
NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
|
|
46082
46111
|
})(NewServiceError || (NewServiceError = {}));
|
|
46083
46112
|
var UpdatePrivilegesError;
|
|
46084
46113
|
(function (UpdatePrivilegesError) {
|
|
@@ -46215,7 +46244,7 @@ const HostCallResult = {
|
|
|
46215
46244
|
OOB: numbers_tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
|
|
46216
46245
|
/** Index unknown. */
|
|
46217
46246
|
WHO: numbers_tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
|
|
46218
|
-
/** Storage full. */
|
|
46247
|
+
/** Storage full or resource already allocated. */
|
|
46219
46248
|
FULL: numbers_tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
|
|
46220
46249
|
/** Core index unknown. */
|
|
46221
46250
|
CORE: numbers_tryAsU64(0xfffffffffffffffan), // 2**64 - 6
|
|
@@ -46223,7 +46252,7 @@ const HostCallResult = {
|
|
|
46223
46252
|
CASH: numbers_tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
|
|
46224
46253
|
/** Gas limit too low. */
|
|
46225
46254
|
LOW: numbers_tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
|
|
46226
|
-
/** The item is already solicited
|
|
46255
|
+
/** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
|
|
46227
46256
|
HUH: numbers_tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
|
|
46228
46257
|
/** The return value indicating general success. */
|
|
46229
46258
|
OK: numbers_tryAsU64(0n),
|
|
@@ -46277,6 +46306,7 @@ function clampU64ToU32(value) {
|
|
|
46277
46306
|
|
|
46278
46307
|
|
|
46279
46308
|
|
|
46309
|
+
|
|
46280
46310
|
/**
|
|
46281
46311
|
* Number of storage items required for ejection of the service.
|
|
46282
46312
|
*
|
|
@@ -46368,10 +46398,13 @@ class AccumulateExternalities {
|
|
|
46368
46398
|
const isExpired = status.data[1] < t - this.chainSpec.preimageExpungePeriod;
|
|
46369
46399
|
return [isExpired, isExpired ? "" : "not expired"];
|
|
46370
46400
|
}
|
|
46371
|
-
/** `check`: https://graypaper.fluffylabs.dev/#/
|
|
46401
|
+
/** `check`: https://graypaper.fluffylabs.dev/#/ab2cdbd/30c60330c603?v=0.7.2 */
|
|
46372
46402
|
getNextAvailableServiceId(serviceId) {
|
|
46373
46403
|
let currentServiceId = serviceId;
|
|
46374
|
-
const mod =
|
|
46404
|
+
const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
46405
|
+
? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
|
|
46406
|
+
: 2 ** 32 - 2 ** 9;
|
|
46407
|
+
const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
|
|
46375
46408
|
for (;;) {
|
|
46376
46409
|
const service = this.getServiceInfo(currentServiceId);
|
|
46377
46410
|
// we found an empty id
|
|
@@ -46379,7 +46412,7 @@ class AccumulateExternalities {
|
|
|
46379
46412
|
return currentServiceId;
|
|
46380
46413
|
}
|
|
46381
46414
|
// keep trying
|
|
46382
|
-
currentServiceId = tryAsServiceId(((currentServiceId -
|
|
46415
|
+
currentServiceId = tryAsServiceId(((currentServiceId - offset + 1 + mod) % mod) + offset);
|
|
46383
46416
|
}
|
|
46384
46417
|
}
|
|
46385
46418
|
checkPreimageStatus(hash, length) {
|
|
@@ -46536,8 +46569,7 @@ class AccumulateExternalities {
|
|
|
46536
46569
|
}));
|
|
46537
46570
|
return result_Result.ok(result_OK);
|
|
46538
46571
|
}
|
|
46539
|
-
newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage) {
|
|
46540
|
-
const newServiceId = this.nextNewServiceId;
|
|
46572
|
+
newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage, wantedServiceId) {
|
|
46541
46573
|
// calculate the threshold. Storage is empty, one preimage requested.
|
|
46542
46574
|
// https://graypaper.fluffylabs.dev/#/7e6ff6a/115901115901?v=0.6.7
|
|
46543
46575
|
const items = numbers_tryAsU32(2 * 1 + 0);
|
|
@@ -46558,30 +46590,59 @@ class AccumulateExternalities {
|
|
|
46558
46590
|
if (balanceLeftForCurrent < thresholdForCurrent || bytes.overflow) {
|
|
46559
46591
|
return result_Result.error(NewServiceError.InsufficientFunds);
|
|
46560
46592
|
}
|
|
46593
|
+
// `a`: https://graypaper.fluffylabs.dev/#/ab2cdbd/366b02366d02?v=0.7.2
|
|
46594
|
+
const newAccount = ServiceAccountInfo.create({
|
|
46595
|
+
codeHash,
|
|
46596
|
+
balance: thresholdForNew,
|
|
46597
|
+
accumulateMinGas,
|
|
46598
|
+
onTransferMinGas,
|
|
46599
|
+
storageUtilisationBytes: bytes.value,
|
|
46600
|
+
storageUtilisationCount: items,
|
|
46601
|
+
gratisStorage,
|
|
46602
|
+
created: this.currentTimeslot,
|
|
46603
|
+
lastAccumulation: tryAsTimeSlot(0),
|
|
46604
|
+
parentService: this.currentServiceId,
|
|
46605
|
+
});
|
|
46606
|
+
const newLookupItem = new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([]));
|
|
46607
|
+
// `s`: https://graypaper.fluffylabs.dev/#/ab2cdbd/361003361003?v=0.7.2
|
|
46608
|
+
const updatedCurrentAccount = ServiceAccountInfo.create({
|
|
46609
|
+
...currentService,
|
|
46610
|
+
balance: numbers_tryAsU64(balanceLeftForCurrent),
|
|
46611
|
+
});
|
|
46612
|
+
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
|
|
46613
|
+
if (wantedServiceId < MIN_PUBLIC_SERVICE_INDEX &&
|
|
46614
|
+
this.currentServiceId === this.updatedState.getPrivilegedServices().registrar) {
|
|
46615
|
+
// NOTE: It's safe to cast to `Number` here, bcs here service ID cannot be bigger than 2**16
|
|
46616
|
+
const newServiceId = tryAsServiceId(Number(wantedServiceId));
|
|
46617
|
+
if (this.getServiceInfo(newServiceId) !== null) {
|
|
46618
|
+
return result_Result.error(NewServiceError.RegistrarServiceIdAlreadyTaken);
|
|
46619
|
+
}
|
|
46620
|
+
// add the new service with selected ID
|
|
46621
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36be0336c003?v=0.7.2
|
|
46622
|
+
this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
|
|
46623
|
+
serviceId: newServiceId,
|
|
46624
|
+
serviceInfo: newAccount,
|
|
46625
|
+
lookupHistory: newLookupItem,
|
|
46626
|
+
}));
|
|
46627
|
+
// update the balance of current service
|
|
46628
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36c20336c403?v=0.7.2
|
|
46629
|
+
this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
|
|
46630
|
+
return result_Result.ok(newServiceId);
|
|
46631
|
+
}
|
|
46632
|
+
// NOTE: in case the service is not a registrar or the requested serviceId is out of range,
|
|
46633
|
+
// we completely ignore the `wantedServiceId` and assign a random one
|
|
46634
|
+
}
|
|
46635
|
+
const newServiceId = this.nextNewServiceId;
|
|
46561
46636
|
// add the new service
|
|
46562
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
46637
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36e70336e903?v=0.7.2
|
|
46563
46638
|
this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
|
|
46564
46639
|
serviceId: newServiceId,
|
|
46565
|
-
serviceInfo:
|
|
46566
|
-
|
|
46567
|
-
balance: thresholdForNew,
|
|
46568
|
-
accumulateMinGas,
|
|
46569
|
-
onTransferMinGas,
|
|
46570
|
-
storageUtilisationBytes: bytes.value,
|
|
46571
|
-
storageUtilisationCount: items,
|
|
46572
|
-
gratisStorage,
|
|
46573
|
-
created: this.currentTimeslot,
|
|
46574
|
-
lastAccumulation: tryAsTimeSlot(0),
|
|
46575
|
-
parentService: this.currentServiceId,
|
|
46576
|
-
}),
|
|
46577
|
-
lookupHistory: new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([])),
|
|
46640
|
+
serviceInfo: newAccount,
|
|
46641
|
+
lookupHistory: newLookupItem,
|
|
46578
46642
|
}));
|
|
46579
46643
|
// update the balance of current service
|
|
46580
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
46581
|
-
this.updatedState.updateServiceInfo(this.currentServiceId,
|
|
46582
|
-
...currentService,
|
|
46583
|
-
balance: numbers_tryAsU64(balanceLeftForCurrent),
|
|
46584
|
-
}));
|
|
46644
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36ec0336ee03?v=0.7.2
|
|
46645
|
+
this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
|
|
46585
46646
|
// update the next service id we are going to create next
|
|
46586
46647
|
// https://graypaper.fluffylabs.dev/#/7e6ff6a/36a70336a703?v=0.6.7
|
|
46587
46648
|
this.nextNewServiceId = this.getNextAvailableServiceId(bumpServiceId(newServiceId));
|
|
@@ -46599,9 +46660,9 @@ class AccumulateExternalities {
|
|
|
46599
46660
|
}
|
|
46600
46661
|
updateValidatorsData(validatorsData) {
|
|
46601
46662
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/362802362d02?v=0.6.7 */
|
|
46602
|
-
const
|
|
46603
|
-
if (
|
|
46604
|
-
accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${
|
|
46663
|
+
const currentDelegator = this.updatedState.getPrivilegedServices().delegator;
|
|
46664
|
+
if (currentDelegator !== this.currentServiceId) {
|
|
46665
|
+
accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${currentDelegator}) and cannot update validators data. Ignoring`;
|
|
46605
46666
|
return result_Result.error(UnprivilegedError);
|
|
46606
46667
|
}
|
|
46607
46668
|
this.updatedState.stateUpdate.validatorsData = validatorsData;
|
|
@@ -46611,34 +46672,38 @@ class AccumulateExternalities {
|
|
|
46611
46672
|
/** https://graypaper.fluffylabs.dev/#/9a08063/362202362202?v=0.6.6 */
|
|
46612
46673
|
this.checkpointedState = AccumulationStateUpdate.copyFrom(this.updatedState.stateUpdate);
|
|
46613
46674
|
}
|
|
46614
|
-
updateAuthorizationQueue(coreIndex, authQueue,
|
|
46675
|
+
updateAuthorizationQueue(coreIndex, authQueue, assigners) {
|
|
46615
46676
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/36a40136a401?v=0.6.7 */
|
|
46616
46677
|
// NOTE `coreIndex` is already verified in the HC, so this is infallible.
|
|
46617
|
-
const
|
|
46618
|
-
if (
|
|
46619
|
-
accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not an auth manager of core ${coreIndex} (expected: ${
|
|
46678
|
+
const currentAssigners = this.updatedState.getPrivilegedServices().assigners[coreIndex];
|
|
46679
|
+
if (currentAssigners !== this.currentServiceId) {
|
|
46680
|
+
accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not an auth manager of core ${coreIndex} (expected: ${currentAssigners}) and cannot update authorization queue.`;
|
|
46620
46681
|
return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
|
|
46621
46682
|
}
|
|
46622
|
-
if (
|
|
46623
|
-
accumulate_externalities_logger.trace `The new auth manager is not a valid service id
|
|
46683
|
+
if (assigners === null && Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
|
|
46684
|
+
accumulate_externalities_logger.trace `The new auth manager is not a valid service id.`;
|
|
46624
46685
|
return result_Result.error(UpdatePrivilegesError.InvalidServiceId);
|
|
46625
46686
|
}
|
|
46626
46687
|
this.updatedState.stateUpdate.authorizationQueues.set(coreIndex, authQueue);
|
|
46627
46688
|
return result_Result.ok(result_OK);
|
|
46628
46689
|
}
|
|
46629
|
-
updatePrivilegedServices(manager, authorizers,
|
|
46690
|
+
updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate) {
|
|
46630
46691
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/36d90036de00?v=0.6.7 */
|
|
46631
46692
|
const currentManager = this.updatedState.getPrivilegedServices().manager;
|
|
46632
46693
|
if (currentManager !== this.currentServiceId) {
|
|
46633
46694
|
return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
|
|
46634
46695
|
}
|
|
46635
|
-
if (manager === null ||
|
|
46636
|
-
return result_Result.error(UpdatePrivilegesError.InvalidServiceId);
|
|
46696
|
+
if (manager === null || delegator === null) {
|
|
46697
|
+
return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Either manager or delegator is not valid service id.");
|
|
46698
|
+
}
|
|
46699
|
+
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && registrar === null) {
|
|
46700
|
+
return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Register manager is not valid service id.");
|
|
46637
46701
|
}
|
|
46638
46702
|
this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
|
|
46639
46703
|
manager,
|
|
46640
|
-
|
|
46641
|
-
|
|
46704
|
+
assigners: authorizers,
|
|
46705
|
+
delegator,
|
|
46706
|
+
registrar: registrar ?? tryAsServiceId(0), // introduced in 0.7.1
|
|
46642
46707
|
autoAccumulateServices: autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit })),
|
|
46643
46708
|
});
|
|
46644
46709
|
return result_Result.ok(result_OK);
|
|
@@ -46754,8 +46819,11 @@ class AccumulateExternalities {
|
|
|
46754
46819
|
}
|
|
46755
46820
|
}
|
|
46756
46821
|
function bumpServiceId(serviceId) {
|
|
46757
|
-
const mod =
|
|
46758
|
-
|
|
46822
|
+
const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
46823
|
+
? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
|
|
46824
|
+
: 2 ** 32 - 2 ** 9;
|
|
46825
|
+
const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
|
|
46826
|
+
return tryAsServiceId(offset + ((serviceId - offset + 42 + mod) % mod));
|
|
46759
46827
|
}
|
|
46760
46828
|
|
|
46761
46829
|
;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-state.ts
|
|
@@ -47411,6 +47479,8 @@ class AccumulateData {
|
|
|
47411
47479
|
|
|
47412
47480
|
|
|
47413
47481
|
|
|
47482
|
+
|
|
47483
|
+
|
|
47414
47484
|
/**
|
|
47415
47485
|
* A function that removes duplicates but does not change order - it keeps the first occurence.
|
|
47416
47486
|
*/
|
|
@@ -47440,7 +47510,7 @@ const NEXT_ID_CODEC = descriptors_codec.object({
|
|
|
47440
47510
|
*
|
|
47441
47511
|
* Please not that it does not call `check` function!
|
|
47442
47512
|
*
|
|
47443
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
47513
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/2fa9042fc304?v=0.7.2
|
|
47444
47514
|
*/
|
|
47445
47515
|
function generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blake2b) {
|
|
47446
47516
|
const encoded = encoder_Encoder.encodeObject(NEXT_ID_CODEC, {
|
|
@@ -47450,7 +47520,11 @@ function generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blak
|
|
|
47450
47520
|
}, chainSpec);
|
|
47451
47521
|
const result = blake2b.hashBytes(encoded).raw.subarray(0, 4);
|
|
47452
47522
|
const number = leBytesAsU32(result) >>> 0;
|
|
47453
|
-
|
|
47523
|
+
const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
47524
|
+
? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
|
|
47525
|
+
: 2 ** 32 - 2 ** 9;
|
|
47526
|
+
const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
|
|
47527
|
+
return tryAsServiceId((number % mod) + offset);
|
|
47454
47528
|
}
|
|
47455
47529
|
|
|
47456
47530
|
;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-queue.ts
|
|
@@ -47862,7 +47936,7 @@ class Assign {
|
|
|
47862
47936
|
// o
|
|
47863
47937
|
const authorizationQueueStart = regs.get(8);
|
|
47864
47938
|
// a
|
|
47865
|
-
const
|
|
47939
|
+
const assigners = getServiceId(regs.get(9));
|
|
47866
47940
|
const res = safeAllocUint8Array(hash_HASH_SIZE * AUTHORIZATION_QUEUE_SIZE);
|
|
47867
47941
|
const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
|
|
47868
47942
|
// error while reading the memory.
|
|
@@ -47879,7 +47953,7 @@ class Assign {
|
|
|
47879
47953
|
const decoder = decoder_Decoder.fromBlob(res);
|
|
47880
47954
|
const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE), AUTHORIZATION_QUEUE_SIZE);
|
|
47881
47955
|
const fixedSizeAuthQueue = FixedSizeArray.new(authQueue, AUTHORIZATION_QUEUE_SIZE);
|
|
47882
|
-
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue,
|
|
47956
|
+
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
|
|
47883
47957
|
if (result.isOk) {
|
|
47884
47958
|
regs.set(IN_OUT_REG, HostCallResult.OK);
|
|
47885
47959
|
logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
|
|
@@ -47928,7 +48002,9 @@ class Bless {
|
|
|
47928
48002
|
chainSpec;
|
|
47929
48003
|
index = host_call_handler_tryAsHostCallIndex(14);
|
|
47930
48004
|
basicGasCost = gas_tryAsSmallGas(10);
|
|
47931
|
-
tracedRegisters =
|
|
48005
|
+
tracedRegisters = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
48006
|
+
? traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11, 12)
|
|
48007
|
+
: traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11);
|
|
47932
48008
|
constructor(currentServiceId, partialState, chainSpec) {
|
|
47933
48009
|
this.currentServiceId = currentServiceId;
|
|
47934
48010
|
this.partialState = partialState;
|
|
@@ -47938,14 +48014,17 @@ class Bless {
|
|
|
47938
48014
|
// `m`: manager service (can change privileged services)
|
|
47939
48015
|
const manager = getServiceId(regs.get(bless_IN_OUT_REG));
|
|
47940
48016
|
// `a`: manages authorization queue
|
|
47941
|
-
// NOTE It can be either ServiceId (pre GP 067) or memory index (GP ^067)
|
|
47942
48017
|
const authorization = regs.get(8);
|
|
47943
48018
|
// `v`: manages validator keys
|
|
47944
|
-
const
|
|
48019
|
+
const delegator = getServiceId(regs.get(9));
|
|
48020
|
+
// `r`: manages creation of new services with id within protected range
|
|
48021
|
+
const registrar = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
48022
|
+
? getServiceId(regs.get(10))
|
|
48023
|
+
: tryAsServiceId(2 ** 32 - 1);
|
|
47945
48024
|
// `o`: memory offset
|
|
47946
|
-
const sourceStart = regs.get(10);
|
|
48025
|
+
const sourceStart = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? regs.get(11) : regs.get(10);
|
|
47947
48026
|
// `n`: number of items in the auto-accumulate dictionary
|
|
47948
|
-
const numberOfItems = regs.get(11);
|
|
48027
|
+
const numberOfItems = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? regs.get(12) : regs.get(11);
|
|
47949
48028
|
/*
|
|
47950
48029
|
* `z`: array of key-value pairs serviceId -> gas that auto-accumulate every block
|
|
47951
48030
|
* https://graypaper.fluffylabs.dev/#/7e6ff6a/368100368100?v=0.6.7
|
|
@@ -47959,7 +48038,7 @@ class Bless {
|
|
|
47959
48038
|
decoder.resetTo(0);
|
|
47960
48039
|
const memoryReadResult = memory.loadInto(result, memIndex);
|
|
47961
48040
|
if (memoryReadResult.isError) {
|
|
47962
|
-
logger_logger.trace `BLESS(${manager}, ${
|
|
48041
|
+
logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}) <- PANIC`;
|
|
47963
48042
|
return PvmExecution.Panic;
|
|
47964
48043
|
}
|
|
47965
48044
|
const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
|
|
@@ -47972,24 +48051,25 @@ class Bless {
|
|
|
47972
48051
|
const authorizersDecoder = decoder_Decoder.fromBlob(res);
|
|
47973
48052
|
const memoryReadResult = memory.loadInto(res, authorization);
|
|
47974
48053
|
if (memoryReadResult.isError) {
|
|
47975
|
-
logger_logger.trace `BLESS(${manager}, ${
|
|
48054
|
+
logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- PANIC`;
|
|
47976
48055
|
return PvmExecution.Panic;
|
|
47977
48056
|
}
|
|
48057
|
+
// `a`
|
|
47978
48058
|
const authorizers = tryAsPerCore(authorizersDecoder.sequenceFixLen(descriptors_codec.u32.asOpaque(), this.chainSpec.coresCount), this.chainSpec);
|
|
47979
|
-
const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers,
|
|
48059
|
+
const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulateEntries);
|
|
47980
48060
|
if (updateResult.isOk) {
|
|
47981
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
48061
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- OK`;
|
|
47982
48062
|
regs.set(bless_IN_OUT_REG, HostCallResult.OK);
|
|
47983
48063
|
return;
|
|
47984
48064
|
}
|
|
47985
48065
|
const e = updateResult.error;
|
|
47986
48066
|
if (e === UpdatePrivilegesError.UnprivilegedService) {
|
|
47987
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
48067
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- HUH`;
|
|
47988
48068
|
regs.set(bless_IN_OUT_REG, HostCallResult.HUH);
|
|
47989
48069
|
return;
|
|
47990
48070
|
}
|
|
47991
48071
|
if (e === UpdatePrivilegesError.InvalidServiceId) {
|
|
47992
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
48072
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- WHO`;
|
|
47993
48073
|
regs.set(bless_IN_OUT_REG, HostCallResult.WHO);
|
|
47994
48074
|
return;
|
|
47995
48075
|
}
|
|
@@ -48241,7 +48321,9 @@ class New {
|
|
|
48241
48321
|
partialState;
|
|
48242
48322
|
index = host_call_handler_tryAsHostCallIndex(18);
|
|
48243
48323
|
basicGasCost = gas_tryAsSmallGas(10);
|
|
48244
|
-
tracedRegisters =
|
|
48324
|
+
tracedRegisters = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
48325
|
+
? traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11, 12)
|
|
48326
|
+
: traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11);
|
|
48245
48327
|
constructor(currentServiceId, partialState) {
|
|
48246
48328
|
this.currentServiceId = currentServiceId;
|
|
48247
48329
|
this.partialState = partialState;
|
|
@@ -48257,16 +48339,18 @@ class New {
|
|
|
48257
48339
|
const allowance = tryAsServiceGas(regs.get(10));
|
|
48258
48340
|
// `f`
|
|
48259
48341
|
const gratisStorage = regs.get(11);
|
|
48342
|
+
// `i`: requested service id. Ignored if current service is not registrar or value is bigger than `S`.
|
|
48343
|
+
const requestedServiceId = regs.get(12);
|
|
48260
48344
|
// `c`
|
|
48261
48345
|
const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
48262
48346
|
const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
|
|
48263
48347
|
// error while reading the memory.
|
|
48264
48348
|
if (memoryReadResult.isError) {
|
|
48265
|
-
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- PANIC`;
|
|
48349
|
+
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
|
|
48266
48350
|
return PvmExecution.Panic;
|
|
48267
48351
|
}
|
|
48268
|
-
const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage);
|
|
48269
|
-
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- ${resultToString(assignedId)}`;
|
|
48352
|
+
const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage, requestedServiceId);
|
|
48353
|
+
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${resultToString(assignedId)}`;
|
|
48270
48354
|
if (assignedId.isOk) {
|
|
48271
48355
|
regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
|
|
48272
48356
|
return;
|
|
@@ -48280,6 +48364,11 @@ class New {
|
|
|
48280
48364
|
regs.set(new_IN_OUT_REG, HostCallResult.HUH);
|
|
48281
48365
|
return;
|
|
48282
48366
|
}
|
|
48367
|
+
// Post 0.7.1
|
|
48368
|
+
if (e === NewServiceError.RegistrarServiceIdAlreadyTaken) {
|
|
48369
|
+
regs.set(new_IN_OUT_REG, HostCallResult.FULL);
|
|
48370
|
+
return;
|
|
48371
|
+
}
|
|
48283
48372
|
debug_assertNever(e);
|
|
48284
48373
|
}
|
|
48285
48374
|
}
|
|
@@ -49688,17 +49777,17 @@ class Accumulate {
|
|
|
49688
49777
|
statistics.set(serviceId, serviceStatistics);
|
|
49689
49778
|
currentState = stateUpdate === null ? checkpoint : stateUpdate;
|
|
49690
49779
|
if (Compatibility.is(GpVersion.V0_7_0) && serviceId === currentManager) {
|
|
49691
|
-
const newV = currentState.privilegedServices?.
|
|
49780
|
+
const newV = currentState.privilegedServices?.delegator;
|
|
49692
49781
|
if (currentState.privilegedServices !== null && newV !== undefined && serviceIds.includes(newV)) {
|
|
49693
|
-
accumulate_logger.info `Entering completely incorrect code that probably reverts
|
|
49782
|
+
accumulate_logger.info `Entering completely incorrect code that probably reverts delegator change. This is valid in 0.7.0 only and incorrect in 0.7.1+`;
|
|
49694
49783
|
// Since serviceIds already contains newV, this service gets accumulated twice.
|
|
49695
49784
|
// To avoid double-counting, we skip stats and gas cost tracking here.
|
|
49696
|
-
// We need this accumulation to get the correct `
|
|
49785
|
+
// We need this accumulation to get the correct `delegator`
|
|
49697
49786
|
const { stateUpdate } = await this.accumulateSingleService(newV, [], accumulateData.getOperands(newV), accumulateData.getGasCost(newV), slot, entropy, checkpoint);
|
|
49698
|
-
const correctV = stateUpdate?.privilegedServices?.
|
|
49787
|
+
const correctV = stateUpdate?.privilegedServices?.delegator ?? this.state.privilegedServices.delegator;
|
|
49699
49788
|
currentState.privilegedServices = PrivilegedServices.create({
|
|
49700
49789
|
...currentState.privilegedServices,
|
|
49701
|
-
|
|
49790
|
+
delegator: correctV,
|
|
49702
49791
|
});
|
|
49703
49792
|
}
|
|
49704
49793
|
}
|