@typeberry/jam 0.1.3-8258907 → 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 +279 -249
- package/bootstrap-generator.mjs.map +1 -1
- package/bootstrap-importer.mjs +408 -323
- package/bootstrap-importer.mjs.map +1 -1
- package/bootstrap-network.mjs +279 -249
- package/bootstrap-network.mjs.map +1 -1
- package/index.js +408 -323
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -25782,7 +25782,7 @@ class Skipper {
|
|
|
25782
25782
|
*
|
|
25783
25783
|
* Descriptors can be composed to form more complex typings.
|
|
25784
25784
|
*/
|
|
25785
|
-
class
|
|
25785
|
+
class Descriptor {
|
|
25786
25786
|
name;
|
|
25787
25787
|
sizeHint;
|
|
25788
25788
|
encode;
|
|
@@ -25792,11 +25792,11 @@ class descriptor_Descriptor {
|
|
|
25792
25792
|
View;
|
|
25793
25793
|
/** New descriptor with specialized `View`. */
|
|
25794
25794
|
static withView(name, sizeHint, encode, decode, skip, view) {
|
|
25795
|
-
return new
|
|
25795
|
+
return new Descriptor(name, sizeHint, encode, decode, skip, view);
|
|
25796
25796
|
}
|
|
25797
25797
|
/** Create a new descriptor without a specialized `View`. */
|
|
25798
25798
|
static new(name, sizeHint, encode, decode, skip) {
|
|
25799
|
-
return new
|
|
25799
|
+
return new Descriptor(name, sizeHint, encode, decode, skip, null);
|
|
25800
25800
|
}
|
|
25801
25801
|
constructor(
|
|
25802
25802
|
/** Descriptive name of the coded data. */
|
|
@@ -25833,7 +25833,7 @@ class descriptor_Descriptor {
|
|
|
25833
25833
|
}
|
|
25834
25834
|
/** Return a new descriptor that converts data into some other type. */
|
|
25835
25835
|
convert(input, output) {
|
|
25836
|
-
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);
|
|
25837
25837
|
}
|
|
25838
25838
|
/** Safely cast the descriptor value to a opaque type. */
|
|
25839
25839
|
asOpaque() {
|
|
@@ -26531,51 +26531,51 @@ var descriptors_codec;
|
|
|
26531
26531
|
return (len) => {
|
|
26532
26532
|
let ret = cache.get(len);
|
|
26533
26533
|
if (ret === undefined) {
|
|
26534
|
-
ret =
|
|
26534
|
+
ret = Descriptor.new(`Bytes<${len}>`, exactHint(len), (e, v) => e.bytes(v), (d) => d.bytes(len), (s) => s.bytes(len));
|
|
26535
26535
|
cache.set(len, ret);
|
|
26536
26536
|
}
|
|
26537
26537
|
return ret;
|
|
26538
26538
|
};
|
|
26539
26539
|
})();
|
|
26540
26540
|
/** Variable-length U32. */
|
|
26541
|
-
codec.varU32 =
|
|
26541
|
+
codec.varU32 = Descriptor.new("var_u32", { bytes: 4, isExact: false }, (e, v) => e.varU32(v), (d) => d.varU32(), (d) => d.varU32());
|
|
26542
26542
|
/** Variable-length U64. */
|
|
26543
|
-
codec.varU64 =
|
|
26543
|
+
codec.varU64 = Descriptor.new("var_u64", { bytes: 8, isExact: false }, (e, v) => e.varU64(v), (d) => d.varU64(), (d) => d.varU64());
|
|
26544
26544
|
/** Unsigned 64-bit number. */
|
|
26545
|
-
codec.u64 =
|
|
26545
|
+
codec.u64 = Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.u64(), (d) => d.u64(), codec.bytes(8));
|
|
26546
26546
|
/** Unsigned 32-bit number. */
|
|
26547
|
-
codec.u32 =
|
|
26547
|
+
codec.u32 = Descriptor.withView("u32", exactHint(4), (e, v) => e.i32(v), (d) => d.u32(), (d) => d.u32(), codec.bytes(4));
|
|
26548
26548
|
/** Unsigned 24-bit number. */
|
|
26549
|
-
codec.u24 =
|
|
26549
|
+
codec.u24 = Descriptor.withView("u24", exactHint(3), (e, v) => e.i24(v), (d) => d.u24(), (d) => d.u24(), codec.bytes(3));
|
|
26550
26550
|
/** Unsigned 16-bit number. */
|
|
26551
|
-
codec.u16 =
|
|
26551
|
+
codec.u16 = Descriptor.withView("u16", exactHint(2), (e, v) => e.i16(v), (d) => d.u16(), (d) => d.u16(), codec.bytes(2));
|
|
26552
26552
|
/** Unsigned 8-bit number. */
|
|
26553
|
-
codec.u8 =
|
|
26553
|
+
codec.u8 = Descriptor.new("u8", exactHint(1), (e, v) => e.i8(v), (d) => d.u8(), (d) => d.u8());
|
|
26554
26554
|
/** Signed 64-bit number. */
|
|
26555
|
-
codec.i64 =
|
|
26555
|
+
codec.i64 = Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.i64(), (s) => s.u64(), codec.bytes(8));
|
|
26556
26556
|
/** Signed 32-bit number. */
|
|
26557
|
-
codec.i32 =
|
|
26557
|
+
codec.i32 = Descriptor.withView("i32", exactHint(4), (e, v) => e.i32(v), (d) => d.i32(), (s) => s.u32(), codec.bytes(4));
|
|
26558
26558
|
/** Signed 24-bit number. */
|
|
26559
|
-
codec.i24 =
|
|
26559
|
+
codec.i24 = Descriptor.withView("i24", exactHint(3), (e, v) => e.i24(v), (d) => d.i24(), (s) => s.u24(), codec.bytes(3));
|
|
26560
26560
|
/** Signed 16-bit number. */
|
|
26561
|
-
codec.i16 =
|
|
26561
|
+
codec.i16 = Descriptor.withView("i16", exactHint(2), (e, v) => e.i16(v), (d) => d.i16(), (s) => s.u16(), codec.bytes(2));
|
|
26562
26562
|
/** Signed 8-bit number. */
|
|
26563
|
-
codec.i8 =
|
|
26563
|
+
codec.i8 = Descriptor.new("i8", exactHint(1), (e, v) => e.i8(v), (d) => d.i8(), (s) => s.u8());
|
|
26564
26564
|
/** 1-byte boolean value. */
|
|
26565
|
-
codec.bool =
|
|
26565
|
+
codec.bool = Descriptor.new("bool", exactHint(1), (e, v) => e.bool(v), (d) => d.bool(), (s) => s.bool());
|
|
26566
26566
|
/** Variable-length bytes blob. */
|
|
26567
|
-
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());
|
|
26568
26568
|
/** String encoded as variable-length bytes blob. */
|
|
26569
|
-
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);
|
|
26570
26570
|
/** Variable-length bit vector. */
|
|
26571
|
-
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());
|
|
26572
26572
|
/** Fixed-length bit vector. */
|
|
26573
|
-
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));
|
|
26574
26574
|
/** Optionality wrapper for given type. */
|
|
26575
26575
|
codec.optional = (type) => {
|
|
26576
|
-
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));
|
|
26577
26577
|
if (hasUniqueView(type)) {
|
|
26578
|
-
return
|
|
26578
|
+
return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.optional(type.View));
|
|
26579
26579
|
}
|
|
26580
26580
|
return self;
|
|
26581
26581
|
};
|
|
@@ -26586,7 +26586,7 @@ var descriptors_codec;
|
|
|
26586
26586
|
}) => {
|
|
26587
26587
|
const name = `Sequence<${type.name}>[?]`;
|
|
26588
26588
|
const typicalLength = options.typicalLength ?? TYPICAL_SEQUENCE_LENGTH;
|
|
26589
|
-
return
|
|
26589
|
+
return Descriptor.withView(name, { bytes: typicalLength * type.sizeHint.bytes, isExact: false }, (e, v) => {
|
|
26590
26590
|
validateLength(options, v.length, name);
|
|
26591
26591
|
e.sequenceVarLen(type, v);
|
|
26592
26592
|
}, (d) => {
|
|
@@ -26600,10 +26600,10 @@ var descriptors_codec;
|
|
|
26600
26600
|
}, sequenceViewVarLen(type, options));
|
|
26601
26601
|
};
|
|
26602
26602
|
/** Fixed-length sequence of given type. */
|
|
26603
|
-
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 }));
|
|
26604
26604
|
/** Small dictionary codec. */
|
|
26605
26605
|
codec.dictionary = (key, value, { sortKeys, fixedLength, }) => {
|
|
26606
|
-
const self =
|
|
26606
|
+
const self = Descriptor.new(`Dictionary<${key.name}, ${value.name}>[${fixedLength ?? "?"}]`, {
|
|
26607
26607
|
bytes: fixedLength !== undefined
|
|
26608
26608
|
? fixedLength * addSizeHints(key.sizeHint, value.sizeHint).bytes
|
|
26609
26609
|
: TYPICAL_DICTIONARY_LENGTH * (addSizeHints(key.sizeHint, value.sizeHint).bytes ?? 0),
|
|
@@ -26642,13 +26642,13 @@ var descriptors_codec;
|
|
|
26642
26642
|
s.sequenceFixLen(value, len);
|
|
26643
26643
|
});
|
|
26644
26644
|
if (hasUniqueView(value)) {
|
|
26645
|
-
return
|
|
26645
|
+
return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.dictionary(key, value.View, { sortKeys, fixedLength }));
|
|
26646
26646
|
}
|
|
26647
26647
|
return self;
|
|
26648
26648
|
};
|
|
26649
26649
|
/** Encoding of pair of two values. */
|
|
26650
26650
|
codec.pair = (a, b) => {
|
|
26651
|
-
const self =
|
|
26651
|
+
const self = Descriptor.new(`Pair<${a.name}, ${b.name}>`, addSizeHints(a.sizeHint, b.sizeHint), (e, elem) => {
|
|
26652
26652
|
a.encode(e, elem[0]);
|
|
26653
26653
|
b.encode(e, elem[1]);
|
|
26654
26654
|
}, (d) => {
|
|
@@ -26660,14 +26660,14 @@ var descriptors_codec;
|
|
|
26660
26660
|
b.skip(s);
|
|
26661
26661
|
});
|
|
26662
26662
|
if (hasUniqueView(a) && hasUniqueView(b)) {
|
|
26663
|
-
return
|
|
26663
|
+
return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.pair(a.View, b.View));
|
|
26664
26664
|
}
|
|
26665
26665
|
return self;
|
|
26666
26666
|
};
|
|
26667
26667
|
/** Custom encoding / decoding logic. */
|
|
26668
|
-
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);
|
|
26669
26669
|
/** Choose a descriptor depending on the encoding/decoding context. */
|
|
26670
|
-
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);
|
|
26671
26671
|
/**
|
|
26672
26672
|
* A descriptor for a more complex POJO.
|
|
26673
26673
|
*
|
|
@@ -26704,7 +26704,7 @@ var descriptors_codec;
|
|
|
26704
26704
|
};
|
|
26705
26705
|
const view = objectView(Class, descriptors, sizeHint, skipper);
|
|
26706
26706
|
// and create the descriptor for the entire class.
|
|
26707
|
-
return
|
|
26707
|
+
return Descriptor.withView(Class.name, sizeHint, (e, t) => {
|
|
26708
26708
|
forEachDescriptor(descriptors, (key, descriptor) => {
|
|
26709
26709
|
const value = t[key];
|
|
26710
26710
|
descriptor.encode(e, value);
|
|
@@ -26755,7 +26755,7 @@ function objectView(Class, descriptors, sizeHint, skipper) {
|
|
|
26755
26755
|
});
|
|
26756
26756
|
}
|
|
26757
26757
|
});
|
|
26758
|
-
return
|
|
26758
|
+
return Descriptor.new(`View<${Class.name}>`, sizeHint, (e, t) => {
|
|
26759
26759
|
const encoded = t.encoded();
|
|
26760
26760
|
e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
|
|
26761
26761
|
}, (d) => {
|
|
@@ -26774,7 +26774,7 @@ function sequenceViewVarLen(type, options) {
|
|
|
26774
26774
|
validateLength(options, length, name);
|
|
26775
26775
|
return s.sequenceFixLen(type, length);
|
|
26776
26776
|
};
|
|
26777
|
-
return
|
|
26777
|
+
return Descriptor.new(name, sizeHint, (e, t) => {
|
|
26778
26778
|
validateLength(options, t.length, name);
|
|
26779
26779
|
const encoded = t.encoded();
|
|
26780
26780
|
e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
|
|
@@ -26790,7 +26790,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
|
|
|
26790
26790
|
const skipper = (s) => s.sequenceFixLen(type, fixedLength);
|
|
26791
26791
|
const view = type.name !== type.View.name ? `, ${type.View.name}` : "";
|
|
26792
26792
|
const name = `SeqView<${type.name}${view}>[${fixedLength}]`;
|
|
26793
|
-
return
|
|
26793
|
+
return Descriptor.new(name, sizeHint, (e, t) => {
|
|
26794
26794
|
const encoded = t.encoded();
|
|
26795
26795
|
e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
|
|
26796
26796
|
}, (d) => {
|
|
@@ -29091,7 +29091,7 @@ const codecFixedSizeArray = (val, len) => {
|
|
|
29091
29091
|
};
|
|
29092
29092
|
/** Codec for a hash-dictionary. */
|
|
29093
29093
|
const codecHashDictionary = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH, compare = (a, b) => extractKey(a).compare(extractKey(b)), } = {}) => {
|
|
29094
|
-
return
|
|
29094
|
+
return Descriptor.new(`HashDictionary<${value.name}>[?]`, {
|
|
29095
29095
|
bytes: typicalLength * value.sizeHint.bytes,
|
|
29096
29096
|
isExact: false,
|
|
29097
29097
|
}, (e, v) => {
|
|
@@ -32154,6 +32154,13 @@ const W_T = 128;
|
|
|
32154
32154
|
/** `W_M`: The maximum number of exports in a work-package. */
|
|
32155
32155
|
const W_X = 3_072;
|
|
32156
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;
|
|
32157
32164
|
/**
|
|
32158
32165
|
* `J`: The maximum sum of dependency items in a work-report.
|
|
32159
32166
|
*
|
|
@@ -32165,9 +32172,209 @@ const AUTHORIZATION_QUEUE_SIZE = Q;
|
|
|
32165
32172
|
/** `O`: Maximal authorization pool size. */
|
|
32166
32173
|
const MAX_AUTH_POOL_SIZE = O;
|
|
32167
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
|
+
|
|
32168
32372
|
;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
|
|
32169
32373
|
|
|
32170
32374
|
|
|
32375
|
+
|
|
32376
|
+
|
|
32377
|
+
|
|
32171
32378
|
/** Dictionary entry of services that auto-accumulate every block. */
|
|
32172
32379
|
class AutoAccumulate {
|
|
32173
32380
|
service;
|
|
@@ -32189,39 +32396,50 @@ class AutoAccumulate {
|
|
|
32189
32396
|
}
|
|
32190
32397
|
}
|
|
32191
32398
|
/**
|
|
32192
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
32399
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
|
|
32193
32400
|
*/
|
|
32194
32401
|
class PrivilegedServices {
|
|
32195
32402
|
manager;
|
|
32196
|
-
|
|
32197
|
-
|
|
32403
|
+
delegator;
|
|
32404
|
+
registrar;
|
|
32405
|
+
assigners;
|
|
32198
32406
|
autoAccumulateServices;
|
|
32407
|
+
/** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
|
|
32199
32408
|
static Codec = descriptors_codec.Class(PrivilegedServices, {
|
|
32200
32409
|
manager: descriptors_codec.u32.asOpaque(),
|
|
32201
|
-
|
|
32202
|
-
|
|
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)),
|
|
32203
32415
|
autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
|
|
32204
32416
|
});
|
|
32205
|
-
static create(
|
|
32206
|
-
return new PrivilegedServices(manager,
|
|
32417
|
+
static create(a) {
|
|
32418
|
+
return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
32207
32419
|
}
|
|
32208
32420
|
constructor(
|
|
32209
32421
|
/**
|
|
32210
|
-
*
|
|
32211
|
-
* the service able to effect an alteration of χ from block to block,
|
|
32422
|
+
* `χ_M`: Manages alteration of χ from block to block,
|
|
32212
32423
|
* as well as bestow services with storage deposit credits.
|
|
32213
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
32424
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
32214
32425
|
*/
|
|
32215
32426
|
manager,
|
|
32216
|
-
/**
|
|
32217
|
-
|
|
32218
|
-
/**
|
|
32219
|
-
|
|
32220
|
-
|
|
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. */
|
|
32221
32438
|
autoAccumulateServices) {
|
|
32222
32439
|
this.manager = manager;
|
|
32223
|
-
this.
|
|
32224
|
-
this.
|
|
32440
|
+
this.delegator = delegator;
|
|
32441
|
+
this.registrar = registrar;
|
|
32442
|
+
this.assigners = assigners;
|
|
32225
32443
|
this.autoAccumulateServices = autoAccumulateServices;
|
|
32226
32444
|
}
|
|
32227
32445
|
}
|
|
@@ -32309,7 +32527,7 @@ class RecentBlocks extends WithDebug {
|
|
|
32309
32527
|
*/
|
|
32310
32528
|
class RecentBlocksHistory extends WithDebug {
|
|
32311
32529
|
current;
|
|
32312
|
-
static Codec =
|
|
32530
|
+
static Codec = Descriptor.new("RecentBlocksHistory", RecentBlocks.Codec.sizeHint, (encoder, value) => RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
|
|
32313
32531
|
const recentBlocks = RecentBlocks.Codec.decode(decoder);
|
|
32314
32532
|
return RecentBlocksHistory.create(recentBlocks);
|
|
32315
32533
|
}, (skip) => {
|
|
@@ -32506,196 +32724,6 @@ class SafroleData {
|
|
|
32506
32724
|
}
|
|
32507
32725
|
}
|
|
32508
32726
|
|
|
32509
|
-
;// CONCATENATED MODULE: ./packages/jam/state/service.ts
|
|
32510
|
-
|
|
32511
|
-
|
|
32512
|
-
|
|
32513
|
-
|
|
32514
|
-
|
|
32515
|
-
|
|
32516
|
-
/**
|
|
32517
|
-
* `B_S`: The basic minimum balance which all services require.
|
|
32518
|
-
*
|
|
32519
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
32520
|
-
*/
|
|
32521
|
-
const BASE_SERVICE_BALANCE = 100n;
|
|
32522
|
-
/**
|
|
32523
|
-
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
32524
|
-
*
|
|
32525
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
32526
|
-
*/
|
|
32527
|
-
const ELECTIVE_ITEM_BALANCE = 10n;
|
|
32528
|
-
/**
|
|
32529
|
-
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
32530
|
-
*
|
|
32531
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
32532
|
-
*/
|
|
32533
|
-
const ELECTIVE_BYTE_BALANCE = 1n;
|
|
32534
|
-
const zeroSizeHint = {
|
|
32535
|
-
bytes: 0,
|
|
32536
|
-
isExact: true,
|
|
32537
|
-
};
|
|
32538
|
-
/** 0-byte read, return given default value */
|
|
32539
|
-
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
32540
|
-
/** Encode and decode object with leading version number. */
|
|
32541
|
-
const codecWithVersion = (val) => descriptor_Descriptor.new("withVersion", {
|
|
32542
|
-
bytes: val.sizeHint.bytes + 8,
|
|
32543
|
-
isExact: false,
|
|
32544
|
-
}, (e, v) => {
|
|
32545
|
-
e.varU64(0n);
|
|
32546
|
-
val.encode(e, v);
|
|
32547
|
-
}, (d) => {
|
|
32548
|
-
const version = d.varU64();
|
|
32549
|
-
if (version !== 0n) {
|
|
32550
|
-
throw new Error("Non-zero version is not supported!");
|
|
32551
|
-
}
|
|
32552
|
-
return val.decode(d);
|
|
32553
|
-
}, (s) => {
|
|
32554
|
-
s.varU64();
|
|
32555
|
-
val.skip(s);
|
|
32556
|
-
});
|
|
32557
|
-
/**
|
|
32558
|
-
* Service account details.
|
|
32559
|
-
*
|
|
32560
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
|
|
32561
|
-
*/
|
|
32562
|
-
class ServiceAccountInfo extends WithDebug {
|
|
32563
|
-
codeHash;
|
|
32564
|
-
balance;
|
|
32565
|
-
accumulateMinGas;
|
|
32566
|
-
onTransferMinGas;
|
|
32567
|
-
storageUtilisationBytes;
|
|
32568
|
-
gratisStorage;
|
|
32569
|
-
storageUtilisationCount;
|
|
32570
|
-
created;
|
|
32571
|
-
lastAccumulation;
|
|
32572
|
-
parentService;
|
|
32573
|
-
static Codec = descriptors_codec.Class(ServiceAccountInfo, {
|
|
32574
|
-
codeHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
32575
|
-
balance: descriptors_codec.u64,
|
|
32576
|
-
accumulateMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
|
|
32577
|
-
onTransferMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
|
|
32578
|
-
storageUtilisationBytes: descriptors_codec.u64,
|
|
32579
|
-
gratisStorage: descriptors_codec.u64,
|
|
32580
|
-
storageUtilisationCount: descriptors_codec.u32,
|
|
32581
|
-
created: descriptors_codec.u32.convert((x) => x, tryAsTimeSlot),
|
|
32582
|
-
lastAccumulation: descriptors_codec.u32.convert((x) => x, tryAsTimeSlot),
|
|
32583
|
-
parentService: descriptors_codec.u32.convert((x) => x, tryAsServiceId),
|
|
32584
|
-
});
|
|
32585
|
-
static create(a) {
|
|
32586
|
-
return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
|
|
32587
|
-
}
|
|
32588
|
-
/**
|
|
32589
|
-
* `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
|
|
32590
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
|
|
32591
|
-
*/
|
|
32592
|
-
static calculateThresholdBalance(items, bytes, gratisStorage) {
|
|
32593
|
-
const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
|
|
32594
|
-
if (storageCost < 0n) {
|
|
32595
|
-
return numbers_tryAsU64(0);
|
|
32596
|
-
}
|
|
32597
|
-
if (storageCost >= 2n ** 64n) {
|
|
32598
|
-
return numbers_tryAsU64(2n ** 64n - 1n);
|
|
32599
|
-
}
|
|
32600
|
-
return numbers_tryAsU64(storageCost);
|
|
32601
|
-
}
|
|
32602
|
-
constructor(
|
|
32603
|
-
/** `a_c`: Hash of the service code. */
|
|
32604
|
-
codeHash,
|
|
32605
|
-
/** `a_b`: Current account balance. */
|
|
32606
|
-
balance,
|
|
32607
|
-
/** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
|
|
32608
|
-
accumulateMinGas,
|
|
32609
|
-
/** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
|
|
32610
|
-
onTransferMinGas,
|
|
32611
|
-
/** `a_o`: Total number of octets in storage. */
|
|
32612
|
-
storageUtilisationBytes,
|
|
32613
|
-
/** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
|
|
32614
|
-
gratisStorage,
|
|
32615
|
-
/** `a_i`: Number of items in storage. */
|
|
32616
|
-
storageUtilisationCount,
|
|
32617
|
-
/** `a_r`: Creation account time slot. */
|
|
32618
|
-
created,
|
|
32619
|
-
/** `a_a`: Most recent accumulation time slot. */
|
|
32620
|
-
lastAccumulation,
|
|
32621
|
-
/** `a_p`: Parent service ID. */
|
|
32622
|
-
parentService) {
|
|
32623
|
-
super();
|
|
32624
|
-
this.codeHash = codeHash;
|
|
32625
|
-
this.balance = balance;
|
|
32626
|
-
this.accumulateMinGas = accumulateMinGas;
|
|
32627
|
-
this.onTransferMinGas = onTransferMinGas;
|
|
32628
|
-
this.storageUtilisationBytes = storageUtilisationBytes;
|
|
32629
|
-
this.gratisStorage = gratisStorage;
|
|
32630
|
-
this.storageUtilisationCount = storageUtilisationCount;
|
|
32631
|
-
this.created = created;
|
|
32632
|
-
this.lastAccumulation = lastAccumulation;
|
|
32633
|
-
this.parentService = parentService;
|
|
32634
|
-
}
|
|
32635
|
-
}
|
|
32636
|
-
class PreimageItem extends WithDebug {
|
|
32637
|
-
hash;
|
|
32638
|
-
blob;
|
|
32639
|
-
static Codec = descriptors_codec.Class(PreimageItem, {
|
|
32640
|
-
hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
32641
|
-
blob: descriptors_codec.blob,
|
|
32642
|
-
});
|
|
32643
|
-
static create({ hash, blob }) {
|
|
32644
|
-
return new PreimageItem(hash, blob);
|
|
32645
|
-
}
|
|
32646
|
-
constructor(hash, blob) {
|
|
32647
|
-
super();
|
|
32648
|
-
this.hash = hash;
|
|
32649
|
-
this.blob = blob;
|
|
32650
|
-
}
|
|
32651
|
-
}
|
|
32652
|
-
class StorageItem extends WithDebug {
|
|
32653
|
-
key;
|
|
32654
|
-
value;
|
|
32655
|
-
static Codec = descriptors_codec.Class(StorageItem, {
|
|
32656
|
-
key: descriptors_codec.blob.convert((i) => i, (o) => opaque_asOpaqueType(o)),
|
|
32657
|
-
value: descriptors_codec.blob,
|
|
32658
|
-
});
|
|
32659
|
-
static create({ key, value }) {
|
|
32660
|
-
return new StorageItem(key, value);
|
|
32661
|
-
}
|
|
32662
|
-
constructor(key, value) {
|
|
32663
|
-
super();
|
|
32664
|
-
this.key = key;
|
|
32665
|
-
this.value = value;
|
|
32666
|
-
}
|
|
32667
|
-
}
|
|
32668
|
-
const MAX_LOOKUP_HISTORY_SLOTS = 3;
|
|
32669
|
-
function tryAsLookupHistorySlots(items) {
|
|
32670
|
-
const knownSize = sized_array_asKnownSize(items);
|
|
32671
|
-
if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
|
|
32672
|
-
throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
|
|
32673
|
-
}
|
|
32674
|
-
return knownSize;
|
|
32675
|
-
}
|
|
32676
|
-
/** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
|
|
32677
|
-
class LookupHistoryItem {
|
|
32678
|
-
hash;
|
|
32679
|
-
length;
|
|
32680
|
-
slots;
|
|
32681
|
-
constructor(hash, length,
|
|
32682
|
-
/**
|
|
32683
|
-
* Preimage availability history as a sequence of time slots.
|
|
32684
|
-
* See PreimageStatus and the following GP fragment for more details.
|
|
32685
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
|
|
32686
|
-
slots) {
|
|
32687
|
-
this.hash = hash;
|
|
32688
|
-
this.length = length;
|
|
32689
|
-
this.slots = slots;
|
|
32690
|
-
}
|
|
32691
|
-
static isRequested(item) {
|
|
32692
|
-
if ("slots" in item) {
|
|
32693
|
-
return item.slots.length === 0;
|
|
32694
|
-
}
|
|
32695
|
-
return item.length === 0;
|
|
32696
|
-
}
|
|
32697
|
-
}
|
|
32698
|
-
|
|
32699
32727
|
;// CONCATENATED MODULE: ./packages/jam/state/state.ts
|
|
32700
32728
|
/**
|
|
32701
32729
|
* In addition to the entropy accumulator η_0, we retain
|
|
@@ -33132,6 +33160,7 @@ class StatisticsData {
|
|
|
33132
33160
|
|
|
33133
33161
|
|
|
33134
33162
|
|
|
33163
|
+
|
|
33135
33164
|
|
|
33136
33165
|
|
|
33137
33166
|
var in_memory_state_UpdateError;
|
|
@@ -33535,8 +33564,9 @@ class InMemoryState extends WithDebug {
|
|
|
33535
33564
|
epochRoot: bytes_Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
33536
33565
|
privilegedServices: PrivilegedServices.create({
|
|
33537
33566
|
manager: tryAsServiceId(0),
|
|
33538
|
-
|
|
33539
|
-
|
|
33567
|
+
assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
|
|
33568
|
+
delegator: tryAsServiceId(0),
|
|
33569
|
+
registrar: tryAsServiceId(MAX_VALUE),
|
|
33540
33570
|
autoAccumulateServices: [],
|
|
33541
33571
|
}),
|
|
33542
33572
|
accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
|
|
@@ -33772,7 +33802,7 @@ var serialize;
|
|
|
33772
33802
|
* determine the boundary of the bytes, so it can only be used
|
|
33773
33803
|
* as the last element of the codec and can't be used in sequences!
|
|
33774
33804
|
*/
|
|
33775
|
-
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()));
|
|
33776
33806
|
|
|
33777
33807
|
;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
|
|
33778
33808
|
|
|
@@ -35083,7 +35113,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
|
|
|
35083
35113
|
}
|
|
35084
35114
|
return Ordering.Equal;
|
|
35085
35115
|
}, } = {}) => {
|
|
35086
|
-
return
|
|
35116
|
+
return Descriptor.new(`Map<${value.name}>[?]`, {
|
|
35087
35117
|
bytes: typicalLength * value.sizeHint.bytes,
|
|
35088
35118
|
isExact: false,
|
|
35089
35119
|
}, (e, v) => {
|
|
@@ -41908,7 +41938,7 @@ class AccumulationStateUpdate {
|
|
|
41908
41938
|
if (from.privilegedServices !== null) {
|
|
41909
41939
|
update.privilegedServices = PrivilegedServices.create({
|
|
41910
41940
|
...from.privilegedServices,
|
|
41911
|
-
|
|
41941
|
+
assigners: sized_array_asKnownSize([...from.privilegedServices.assigners]),
|
|
41912
41942
|
});
|
|
41913
41943
|
}
|
|
41914
41944
|
return update;
|
|
@@ -44047,13 +44077,6 @@ class BitOps {
|
|
|
44047
44077
|
}
|
|
44048
44078
|
}
|
|
44049
44079
|
|
|
44050
|
-
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
|
|
44051
|
-
const MAX_VALUE = 4294967295;
|
|
44052
|
-
const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
|
|
44053
|
-
const MIN_VALUE = -(2 ** 31);
|
|
44054
|
-
const MAX_SHIFT_U32 = 32;
|
|
44055
|
-
const MAX_SHIFT_U64 = 64n;
|
|
44056
|
-
|
|
44057
44080
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-utils.ts
|
|
44058
44081
|
|
|
44059
44082
|
|
|
@@ -46083,6 +46106,8 @@ var NewServiceError;
|
|
|
46083
46106
|
NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
|
|
46084
46107
|
/** Service is not privileged to set gratis storage. */
|
|
46085
46108
|
NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
|
|
46109
|
+
/** Registrar attempting to create a service with already existing id. */
|
|
46110
|
+
NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
|
|
46086
46111
|
})(NewServiceError || (NewServiceError = {}));
|
|
46087
46112
|
var UpdatePrivilegesError;
|
|
46088
46113
|
(function (UpdatePrivilegesError) {
|
|
@@ -46219,7 +46244,7 @@ const HostCallResult = {
|
|
|
46219
46244
|
OOB: numbers_tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
|
|
46220
46245
|
/** Index unknown. */
|
|
46221
46246
|
WHO: numbers_tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
|
|
46222
|
-
/** Storage full. */
|
|
46247
|
+
/** Storage full or resource already allocated. */
|
|
46223
46248
|
FULL: numbers_tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
|
|
46224
46249
|
/** Core index unknown. */
|
|
46225
46250
|
CORE: numbers_tryAsU64(0xfffffffffffffffan), // 2**64 - 6
|
|
@@ -46227,7 +46252,7 @@ const HostCallResult = {
|
|
|
46227
46252
|
CASH: numbers_tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
|
|
46228
46253
|
/** Gas limit too low. */
|
|
46229
46254
|
LOW: numbers_tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
|
|
46230
|
-
/** The item is already solicited
|
|
46255
|
+
/** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
|
|
46231
46256
|
HUH: numbers_tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
|
|
46232
46257
|
/** The return value indicating general success. */
|
|
46233
46258
|
OK: numbers_tryAsU64(0n),
|
|
@@ -46281,6 +46306,7 @@ function clampU64ToU32(value) {
|
|
|
46281
46306
|
|
|
46282
46307
|
|
|
46283
46308
|
|
|
46309
|
+
|
|
46284
46310
|
/**
|
|
46285
46311
|
* Number of storage items required for ejection of the service.
|
|
46286
46312
|
*
|
|
@@ -46372,10 +46398,13 @@ class AccumulateExternalities {
|
|
|
46372
46398
|
const isExpired = status.data[1] < t - this.chainSpec.preimageExpungePeriod;
|
|
46373
46399
|
return [isExpired, isExpired ? "" : "not expired"];
|
|
46374
46400
|
}
|
|
46375
|
-
/** `check`: https://graypaper.fluffylabs.dev/#/
|
|
46401
|
+
/** `check`: https://graypaper.fluffylabs.dev/#/ab2cdbd/30c60330c603?v=0.7.2 */
|
|
46376
46402
|
getNextAvailableServiceId(serviceId) {
|
|
46377
46403
|
let currentServiceId = serviceId;
|
|
46378
|
-
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;
|
|
46379
46408
|
for (;;) {
|
|
46380
46409
|
const service = this.getServiceInfo(currentServiceId);
|
|
46381
46410
|
// we found an empty id
|
|
@@ -46383,7 +46412,7 @@ class AccumulateExternalities {
|
|
|
46383
46412
|
return currentServiceId;
|
|
46384
46413
|
}
|
|
46385
46414
|
// keep trying
|
|
46386
|
-
currentServiceId = tryAsServiceId(((currentServiceId -
|
|
46415
|
+
currentServiceId = tryAsServiceId(((currentServiceId - offset + 1 + mod) % mod) + offset);
|
|
46387
46416
|
}
|
|
46388
46417
|
}
|
|
46389
46418
|
checkPreimageStatus(hash, length) {
|
|
@@ -46540,8 +46569,7 @@ class AccumulateExternalities {
|
|
|
46540
46569
|
}));
|
|
46541
46570
|
return result_Result.ok(result_OK);
|
|
46542
46571
|
}
|
|
46543
|
-
newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage) {
|
|
46544
|
-
const newServiceId = this.nextNewServiceId;
|
|
46572
|
+
newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage, wantedServiceId) {
|
|
46545
46573
|
// calculate the threshold. Storage is empty, one preimage requested.
|
|
46546
46574
|
// https://graypaper.fluffylabs.dev/#/7e6ff6a/115901115901?v=0.6.7
|
|
46547
46575
|
const items = numbers_tryAsU32(2 * 1 + 0);
|
|
@@ -46562,30 +46590,59 @@ class AccumulateExternalities {
|
|
|
46562
46590
|
if (balanceLeftForCurrent < thresholdForCurrent || bytes.overflow) {
|
|
46563
46591
|
return result_Result.error(NewServiceError.InsufficientFunds);
|
|
46564
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;
|
|
46565
46636
|
// add the new service
|
|
46566
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
46637
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36e70336e903?v=0.7.2
|
|
46567
46638
|
this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
|
|
46568
46639
|
serviceId: newServiceId,
|
|
46569
|
-
serviceInfo:
|
|
46570
|
-
|
|
46571
|
-
balance: thresholdForNew,
|
|
46572
|
-
accumulateMinGas,
|
|
46573
|
-
onTransferMinGas,
|
|
46574
|
-
storageUtilisationBytes: bytes.value,
|
|
46575
|
-
storageUtilisationCount: items,
|
|
46576
|
-
gratisStorage,
|
|
46577
|
-
created: this.currentTimeslot,
|
|
46578
|
-
lastAccumulation: tryAsTimeSlot(0),
|
|
46579
|
-
parentService: this.currentServiceId,
|
|
46580
|
-
}),
|
|
46581
|
-
lookupHistory: new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([])),
|
|
46640
|
+
serviceInfo: newAccount,
|
|
46641
|
+
lookupHistory: newLookupItem,
|
|
46582
46642
|
}));
|
|
46583
46643
|
// update the balance of current service
|
|
46584
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
46585
|
-
this.updatedState.updateServiceInfo(this.currentServiceId,
|
|
46586
|
-
...currentService,
|
|
46587
|
-
balance: numbers_tryAsU64(balanceLeftForCurrent),
|
|
46588
|
-
}));
|
|
46644
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36ec0336ee03?v=0.7.2
|
|
46645
|
+
this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
|
|
46589
46646
|
// update the next service id we are going to create next
|
|
46590
46647
|
// https://graypaper.fluffylabs.dev/#/7e6ff6a/36a70336a703?v=0.6.7
|
|
46591
46648
|
this.nextNewServiceId = this.getNextAvailableServiceId(bumpServiceId(newServiceId));
|
|
@@ -46603,9 +46660,9 @@ class AccumulateExternalities {
|
|
|
46603
46660
|
}
|
|
46604
46661
|
updateValidatorsData(validatorsData) {
|
|
46605
46662
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/362802362d02?v=0.6.7 */
|
|
46606
|
-
const
|
|
46607
|
-
if (
|
|
46608
|
-
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`;
|
|
46609
46666
|
return result_Result.error(UnprivilegedError);
|
|
46610
46667
|
}
|
|
46611
46668
|
this.updatedState.stateUpdate.validatorsData = validatorsData;
|
|
@@ -46615,34 +46672,38 @@ class AccumulateExternalities {
|
|
|
46615
46672
|
/** https://graypaper.fluffylabs.dev/#/9a08063/362202362202?v=0.6.6 */
|
|
46616
46673
|
this.checkpointedState = AccumulationStateUpdate.copyFrom(this.updatedState.stateUpdate);
|
|
46617
46674
|
}
|
|
46618
|
-
updateAuthorizationQueue(coreIndex, authQueue,
|
|
46675
|
+
updateAuthorizationQueue(coreIndex, authQueue, assigners) {
|
|
46619
46676
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/36a40136a401?v=0.6.7 */
|
|
46620
46677
|
// NOTE `coreIndex` is already verified in the HC, so this is infallible.
|
|
46621
|
-
const
|
|
46622
|
-
if (
|
|
46623
|
-
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.`;
|
|
46624
46681
|
return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
|
|
46625
46682
|
}
|
|
46626
|
-
if (
|
|
46627
|
-
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.`;
|
|
46628
46685
|
return result_Result.error(UpdatePrivilegesError.InvalidServiceId);
|
|
46629
46686
|
}
|
|
46630
46687
|
this.updatedState.stateUpdate.authorizationQueues.set(coreIndex, authQueue);
|
|
46631
46688
|
return result_Result.ok(result_OK);
|
|
46632
46689
|
}
|
|
46633
|
-
updatePrivilegedServices(manager, authorizers,
|
|
46690
|
+
updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate) {
|
|
46634
46691
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/36d90036de00?v=0.6.7 */
|
|
46635
46692
|
const currentManager = this.updatedState.getPrivilegedServices().manager;
|
|
46636
46693
|
if (currentManager !== this.currentServiceId) {
|
|
46637
46694
|
return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
|
|
46638
46695
|
}
|
|
46639
|
-
if (manager === null ||
|
|
46640
|
-
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.");
|
|
46641
46701
|
}
|
|
46642
46702
|
this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
|
|
46643
46703
|
manager,
|
|
46644
|
-
|
|
46645
|
-
|
|
46704
|
+
assigners: authorizers,
|
|
46705
|
+
delegator,
|
|
46706
|
+
registrar: registrar ?? tryAsServiceId(0), // introduced in 0.7.1
|
|
46646
46707
|
autoAccumulateServices: autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit })),
|
|
46647
46708
|
});
|
|
46648
46709
|
return result_Result.ok(result_OK);
|
|
@@ -46758,8 +46819,11 @@ class AccumulateExternalities {
|
|
|
46758
46819
|
}
|
|
46759
46820
|
}
|
|
46760
46821
|
function bumpServiceId(serviceId) {
|
|
46761
|
-
const mod =
|
|
46762
|
-
|
|
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));
|
|
46763
46827
|
}
|
|
46764
46828
|
|
|
46765
46829
|
;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-state.ts
|
|
@@ -47415,6 +47479,8 @@ class AccumulateData {
|
|
|
47415
47479
|
|
|
47416
47480
|
|
|
47417
47481
|
|
|
47482
|
+
|
|
47483
|
+
|
|
47418
47484
|
/**
|
|
47419
47485
|
* A function that removes duplicates but does not change order - it keeps the first occurence.
|
|
47420
47486
|
*/
|
|
@@ -47444,7 +47510,7 @@ const NEXT_ID_CODEC = descriptors_codec.object({
|
|
|
47444
47510
|
*
|
|
47445
47511
|
* Please not that it does not call `check` function!
|
|
47446
47512
|
*
|
|
47447
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
47513
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/2fa9042fc304?v=0.7.2
|
|
47448
47514
|
*/
|
|
47449
47515
|
function generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blake2b) {
|
|
47450
47516
|
const encoded = encoder_Encoder.encodeObject(NEXT_ID_CODEC, {
|
|
@@ -47454,7 +47520,11 @@ function generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blak
|
|
|
47454
47520
|
}, chainSpec);
|
|
47455
47521
|
const result = blake2b.hashBytes(encoded).raw.subarray(0, 4);
|
|
47456
47522
|
const number = leBytesAsU32(result) >>> 0;
|
|
47457
|
-
|
|
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);
|
|
47458
47528
|
}
|
|
47459
47529
|
|
|
47460
47530
|
;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-queue.ts
|
|
@@ -47866,7 +47936,7 @@ class Assign {
|
|
|
47866
47936
|
// o
|
|
47867
47937
|
const authorizationQueueStart = regs.get(8);
|
|
47868
47938
|
// a
|
|
47869
|
-
const
|
|
47939
|
+
const assigners = getServiceId(regs.get(9));
|
|
47870
47940
|
const res = safeAllocUint8Array(hash_HASH_SIZE * AUTHORIZATION_QUEUE_SIZE);
|
|
47871
47941
|
const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
|
|
47872
47942
|
// error while reading the memory.
|
|
@@ -47883,7 +47953,7 @@ class Assign {
|
|
|
47883
47953
|
const decoder = decoder_Decoder.fromBlob(res);
|
|
47884
47954
|
const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE), AUTHORIZATION_QUEUE_SIZE);
|
|
47885
47955
|
const fixedSizeAuthQueue = FixedSizeArray.new(authQueue, AUTHORIZATION_QUEUE_SIZE);
|
|
47886
|
-
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue,
|
|
47956
|
+
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
|
|
47887
47957
|
if (result.isOk) {
|
|
47888
47958
|
regs.set(IN_OUT_REG, HostCallResult.OK);
|
|
47889
47959
|
logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
|
|
@@ -47932,7 +48002,9 @@ class Bless {
|
|
|
47932
48002
|
chainSpec;
|
|
47933
48003
|
index = host_call_handler_tryAsHostCallIndex(14);
|
|
47934
48004
|
basicGasCost = gas_tryAsSmallGas(10);
|
|
47935
|
-
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);
|
|
47936
48008
|
constructor(currentServiceId, partialState, chainSpec) {
|
|
47937
48009
|
this.currentServiceId = currentServiceId;
|
|
47938
48010
|
this.partialState = partialState;
|
|
@@ -47942,14 +48014,17 @@ class Bless {
|
|
|
47942
48014
|
// `m`: manager service (can change privileged services)
|
|
47943
48015
|
const manager = getServiceId(regs.get(bless_IN_OUT_REG));
|
|
47944
48016
|
// `a`: manages authorization queue
|
|
47945
|
-
// NOTE It can be either ServiceId (pre GP 067) or memory index (GP ^067)
|
|
47946
48017
|
const authorization = regs.get(8);
|
|
47947
48018
|
// `v`: manages validator keys
|
|
47948
|
-
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);
|
|
47949
48024
|
// `o`: memory offset
|
|
47950
|
-
const sourceStart = regs.get(10);
|
|
48025
|
+
const sourceStart = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? regs.get(11) : regs.get(10);
|
|
47951
48026
|
// `n`: number of items in the auto-accumulate dictionary
|
|
47952
|
-
const numberOfItems = regs.get(11);
|
|
48027
|
+
const numberOfItems = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? regs.get(12) : regs.get(11);
|
|
47953
48028
|
/*
|
|
47954
48029
|
* `z`: array of key-value pairs serviceId -> gas that auto-accumulate every block
|
|
47955
48030
|
* https://graypaper.fluffylabs.dev/#/7e6ff6a/368100368100?v=0.6.7
|
|
@@ -47963,7 +48038,7 @@ class Bless {
|
|
|
47963
48038
|
decoder.resetTo(0);
|
|
47964
48039
|
const memoryReadResult = memory.loadInto(result, memIndex);
|
|
47965
48040
|
if (memoryReadResult.isError) {
|
|
47966
|
-
logger_logger.trace `BLESS(${manager}, ${
|
|
48041
|
+
logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}) <- PANIC`;
|
|
47967
48042
|
return PvmExecution.Panic;
|
|
47968
48043
|
}
|
|
47969
48044
|
const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
|
|
@@ -47976,24 +48051,25 @@ class Bless {
|
|
|
47976
48051
|
const authorizersDecoder = decoder_Decoder.fromBlob(res);
|
|
47977
48052
|
const memoryReadResult = memory.loadInto(res, authorization);
|
|
47978
48053
|
if (memoryReadResult.isError) {
|
|
47979
|
-
logger_logger.trace `BLESS(${manager}, ${
|
|
48054
|
+
logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- PANIC`;
|
|
47980
48055
|
return PvmExecution.Panic;
|
|
47981
48056
|
}
|
|
48057
|
+
// `a`
|
|
47982
48058
|
const authorizers = tryAsPerCore(authorizersDecoder.sequenceFixLen(descriptors_codec.u32.asOpaque(), this.chainSpec.coresCount), this.chainSpec);
|
|
47983
|
-
const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers,
|
|
48059
|
+
const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulateEntries);
|
|
47984
48060
|
if (updateResult.isOk) {
|
|
47985
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
48061
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- OK`;
|
|
47986
48062
|
regs.set(bless_IN_OUT_REG, HostCallResult.OK);
|
|
47987
48063
|
return;
|
|
47988
48064
|
}
|
|
47989
48065
|
const e = updateResult.error;
|
|
47990
48066
|
if (e === UpdatePrivilegesError.UnprivilegedService) {
|
|
47991
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
48067
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- HUH`;
|
|
47992
48068
|
regs.set(bless_IN_OUT_REG, HostCallResult.HUH);
|
|
47993
48069
|
return;
|
|
47994
48070
|
}
|
|
47995
48071
|
if (e === UpdatePrivilegesError.InvalidServiceId) {
|
|
47996
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
48072
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- WHO`;
|
|
47997
48073
|
regs.set(bless_IN_OUT_REG, HostCallResult.WHO);
|
|
47998
48074
|
return;
|
|
47999
48075
|
}
|
|
@@ -48245,7 +48321,9 @@ class New {
|
|
|
48245
48321
|
partialState;
|
|
48246
48322
|
index = host_call_handler_tryAsHostCallIndex(18);
|
|
48247
48323
|
basicGasCost = gas_tryAsSmallGas(10);
|
|
48248
|
-
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);
|
|
48249
48327
|
constructor(currentServiceId, partialState) {
|
|
48250
48328
|
this.currentServiceId = currentServiceId;
|
|
48251
48329
|
this.partialState = partialState;
|
|
@@ -48261,16 +48339,18 @@ class New {
|
|
|
48261
48339
|
const allowance = tryAsServiceGas(regs.get(10));
|
|
48262
48340
|
// `f`
|
|
48263
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);
|
|
48264
48344
|
// `c`
|
|
48265
48345
|
const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
48266
48346
|
const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
|
|
48267
48347
|
// error while reading the memory.
|
|
48268
48348
|
if (memoryReadResult.isError) {
|
|
48269
|
-
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- PANIC`;
|
|
48349
|
+
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
|
|
48270
48350
|
return PvmExecution.Panic;
|
|
48271
48351
|
}
|
|
48272
|
-
const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage);
|
|
48273
|
-
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)}`;
|
|
48274
48354
|
if (assignedId.isOk) {
|
|
48275
48355
|
regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
|
|
48276
48356
|
return;
|
|
@@ -48284,6 +48364,11 @@ class New {
|
|
|
48284
48364
|
regs.set(new_IN_OUT_REG, HostCallResult.HUH);
|
|
48285
48365
|
return;
|
|
48286
48366
|
}
|
|
48367
|
+
// Post 0.7.1
|
|
48368
|
+
if (e === NewServiceError.RegistrarServiceIdAlreadyTaken) {
|
|
48369
|
+
regs.set(new_IN_OUT_REG, HostCallResult.FULL);
|
|
48370
|
+
return;
|
|
48371
|
+
}
|
|
48287
48372
|
debug_assertNever(e);
|
|
48288
48373
|
}
|
|
48289
48374
|
}
|
|
@@ -49692,17 +49777,17 @@ class Accumulate {
|
|
|
49692
49777
|
statistics.set(serviceId, serviceStatistics);
|
|
49693
49778
|
currentState = stateUpdate === null ? checkpoint : stateUpdate;
|
|
49694
49779
|
if (Compatibility.is(GpVersion.V0_7_0) && serviceId === currentManager) {
|
|
49695
|
-
const newV = currentState.privilegedServices?.
|
|
49780
|
+
const newV = currentState.privilegedServices?.delegator;
|
|
49696
49781
|
if (currentState.privilegedServices !== null && newV !== undefined && serviceIds.includes(newV)) {
|
|
49697
|
-
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+`;
|
|
49698
49783
|
// Since serviceIds already contains newV, this service gets accumulated twice.
|
|
49699
49784
|
// To avoid double-counting, we skip stats and gas cost tracking here.
|
|
49700
|
-
// We need this accumulation to get the correct `
|
|
49785
|
+
// We need this accumulation to get the correct `delegator`
|
|
49701
49786
|
const { stateUpdate } = await this.accumulateSingleService(newV, [], accumulateData.getOperands(newV), accumulateData.getGasCost(newV), slot, entropy, checkpoint);
|
|
49702
|
-
const correctV = stateUpdate?.privilegedServices?.
|
|
49787
|
+
const correctV = stateUpdate?.privilegedServices?.delegator ?? this.state.privilegedServices.delegator;
|
|
49703
49788
|
currentState.privilegedServices = PrivilegedServices.create({
|
|
49704
49789
|
...currentState.privilegedServices,
|
|
49705
|
-
|
|
49790
|
+
delegator: correctV,
|
|
49706
49791
|
});
|
|
49707
49792
|
}
|
|
49708
49793
|
}
|