@typeberry/convert 0.1.3-b635981 → 0.1.3-ca63b35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +473 -335
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -4273,8 +4273,9 @@ function parseCurrentVersion(env) {
|
|
|
4273
4273
|
}
|
|
4274
4274
|
}
|
|
4275
4275
|
function parseCurrentSuite(env) {
|
|
4276
|
-
if (env === undefined)
|
|
4276
|
+
if (env === undefined) {
|
|
4277
4277
|
return undefined;
|
|
4278
|
+
}
|
|
4278
4279
|
switch (env) {
|
|
4279
4280
|
case TestSuite.W3F_DAVXY:
|
|
4280
4281
|
case TestSuite.JAMDUNA:
|
|
@@ -4705,10 +4706,12 @@ function test_deepEqual(actual, expected, { context = [], errorsCollector, ignor
|
|
|
4705
4706
|
.sort((a, b) => {
|
|
4706
4707
|
const aKey = `${a.key}`;
|
|
4707
4708
|
const bKey = `${b.key}`;
|
|
4708
|
-
if (aKey < bKey)
|
|
4709
|
+
if (aKey < bKey) {
|
|
4709
4710
|
return -1;
|
|
4710
|
-
|
|
4711
|
+
}
|
|
4712
|
+
if (bKey < aKey) {
|
|
4711
4713
|
return 1;
|
|
4714
|
+
}
|
|
4712
4715
|
return 0;
|
|
4713
4716
|
});
|
|
4714
4717
|
};
|
|
@@ -5725,7 +5728,7 @@ class Skipper {
|
|
|
5725
5728
|
*
|
|
5726
5729
|
* Descriptors can be composed to form more complex typings.
|
|
5727
5730
|
*/
|
|
5728
|
-
class
|
|
5731
|
+
class Descriptor {
|
|
5729
5732
|
name;
|
|
5730
5733
|
sizeHint;
|
|
5731
5734
|
encode;
|
|
@@ -5735,11 +5738,11 @@ class descriptor_Descriptor {
|
|
|
5735
5738
|
View;
|
|
5736
5739
|
/** New descriptor with specialized `View`. */
|
|
5737
5740
|
static withView(name, sizeHint, encode, decode, skip, view) {
|
|
5738
|
-
return new
|
|
5741
|
+
return new Descriptor(name, sizeHint, encode, decode, skip, view);
|
|
5739
5742
|
}
|
|
5740
5743
|
/** Create a new descriptor without a specialized `View`. */
|
|
5741
5744
|
static new(name, sizeHint, encode, decode, skip) {
|
|
5742
|
-
return new
|
|
5745
|
+
return new Descriptor(name, sizeHint, encode, decode, skip, null);
|
|
5743
5746
|
}
|
|
5744
5747
|
constructor(
|
|
5745
5748
|
/** Descriptive name of the coded data. */
|
|
@@ -5776,7 +5779,7 @@ class descriptor_Descriptor {
|
|
|
5776
5779
|
}
|
|
5777
5780
|
/** Return a new descriptor that converts data into some other type. */
|
|
5778
5781
|
convert(input, output) {
|
|
5779
|
-
return new
|
|
5782
|
+
return new Descriptor(this.name, this.sizeHint, (e, elem) => this.encode(e, input(elem)), (d) => output(this.decode(d)), this.skip, this.View);
|
|
5780
5783
|
}
|
|
5781
5784
|
/** Safely cast the descriptor value to a opaque type. */
|
|
5782
5785
|
asOpaque() {
|
|
@@ -6474,51 +6477,51 @@ var descriptors_codec;
|
|
|
6474
6477
|
return (len) => {
|
|
6475
6478
|
let ret = cache.get(len);
|
|
6476
6479
|
if (ret === undefined) {
|
|
6477
|
-
ret =
|
|
6480
|
+
ret = Descriptor.new(`Bytes<${len}>`, exactHint(len), (e, v) => e.bytes(v), (d) => d.bytes(len), (s) => s.bytes(len));
|
|
6478
6481
|
cache.set(len, ret);
|
|
6479
6482
|
}
|
|
6480
6483
|
return ret;
|
|
6481
6484
|
};
|
|
6482
6485
|
})();
|
|
6483
6486
|
/** Variable-length U32. */
|
|
6484
|
-
codec.varU32 =
|
|
6487
|
+
codec.varU32 = Descriptor.new("var_u32", { bytes: 4, isExact: false }, (e, v) => e.varU32(v), (d) => d.varU32(), (d) => d.varU32());
|
|
6485
6488
|
/** Variable-length U64. */
|
|
6486
|
-
codec.varU64 =
|
|
6489
|
+
codec.varU64 = Descriptor.new("var_u64", { bytes: 8, isExact: false }, (e, v) => e.varU64(v), (d) => d.varU64(), (d) => d.varU64());
|
|
6487
6490
|
/** Unsigned 64-bit number. */
|
|
6488
|
-
codec.u64 =
|
|
6491
|
+
codec.u64 = Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.u64(), (d) => d.u64(), codec.bytes(8));
|
|
6489
6492
|
/** Unsigned 32-bit number. */
|
|
6490
|
-
codec.u32 =
|
|
6493
|
+
codec.u32 = Descriptor.withView("u32", exactHint(4), (e, v) => e.i32(v), (d) => d.u32(), (d) => d.u32(), codec.bytes(4));
|
|
6491
6494
|
/** Unsigned 24-bit number. */
|
|
6492
|
-
codec.u24 =
|
|
6495
|
+
codec.u24 = Descriptor.withView("u24", exactHint(3), (e, v) => e.i24(v), (d) => d.u24(), (d) => d.u24(), codec.bytes(3));
|
|
6493
6496
|
/** Unsigned 16-bit number. */
|
|
6494
|
-
codec.u16 =
|
|
6497
|
+
codec.u16 = Descriptor.withView("u16", exactHint(2), (e, v) => e.i16(v), (d) => d.u16(), (d) => d.u16(), codec.bytes(2));
|
|
6495
6498
|
/** Unsigned 8-bit number. */
|
|
6496
|
-
codec.u8 =
|
|
6499
|
+
codec.u8 = Descriptor.new("u8", exactHint(1), (e, v) => e.i8(v), (d) => d.u8(), (d) => d.u8());
|
|
6497
6500
|
/** Signed 64-bit number. */
|
|
6498
|
-
codec.i64 =
|
|
6501
|
+
codec.i64 = Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.i64(), (s) => s.u64(), codec.bytes(8));
|
|
6499
6502
|
/** Signed 32-bit number. */
|
|
6500
|
-
codec.i32 =
|
|
6503
|
+
codec.i32 = Descriptor.withView("i32", exactHint(4), (e, v) => e.i32(v), (d) => d.i32(), (s) => s.u32(), codec.bytes(4));
|
|
6501
6504
|
/** Signed 24-bit number. */
|
|
6502
|
-
codec.i24 =
|
|
6505
|
+
codec.i24 = Descriptor.withView("i24", exactHint(3), (e, v) => e.i24(v), (d) => d.i24(), (s) => s.u24(), codec.bytes(3));
|
|
6503
6506
|
/** Signed 16-bit number. */
|
|
6504
|
-
codec.i16 =
|
|
6507
|
+
codec.i16 = Descriptor.withView("i16", exactHint(2), (e, v) => e.i16(v), (d) => d.i16(), (s) => s.u16(), codec.bytes(2));
|
|
6505
6508
|
/** Signed 8-bit number. */
|
|
6506
|
-
codec.i8 =
|
|
6509
|
+
codec.i8 = Descriptor.new("i8", exactHint(1), (e, v) => e.i8(v), (d) => d.i8(), (s) => s.u8());
|
|
6507
6510
|
/** 1-byte boolean value. */
|
|
6508
|
-
codec.bool =
|
|
6511
|
+
codec.bool = Descriptor.new("bool", exactHint(1), (e, v) => e.bool(v), (d) => d.bool(), (s) => s.bool());
|
|
6509
6512
|
/** Variable-length bytes blob. */
|
|
6510
|
-
codec.blob =
|
|
6513
|
+
codec.blob = Descriptor.new("BytesBlob", { bytes: TYPICAL_SEQUENCE_LENGTH, isExact: false }, (e, v) => e.bytesBlob(v), (d) => d.bytesBlob(), (s) => s.bytesBlob());
|
|
6511
6514
|
/** String encoded as variable-length bytes blob. */
|
|
6512
|
-
codec.string =
|
|
6515
|
+
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);
|
|
6513
6516
|
/** Variable-length bit vector. */
|
|
6514
|
-
codec.bitVecVarLen =
|
|
6517
|
+
codec.bitVecVarLen = Descriptor.new("BitVec[?]", { bytes: TYPICAL_SEQUENCE_LENGTH >>> 3, isExact: false }, (e, v) => e.bitVecVarLen(v), (d) => d.bitVecVarLen(), (s) => s.bitVecVarLen());
|
|
6515
6518
|
/** Fixed-length bit vector. */
|
|
6516
|
-
codec.bitVecFixLen = (bitLen) =>
|
|
6519
|
+
codec.bitVecFixLen = (bitLen) => Descriptor.new(`BitVec[${bitLen}]`, exactHint(bitLen >>> 3), (e, v) => e.bitVecFixLen(v), (d) => d.bitVecFixLen(bitLen), (s) => s.bitVecFixLen(bitLen));
|
|
6517
6520
|
/** Optionality wrapper for given type. */
|
|
6518
6521
|
codec.optional = (type) => {
|
|
6519
|
-
const self =
|
|
6522
|
+
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));
|
|
6520
6523
|
if (hasUniqueView(type)) {
|
|
6521
|
-
return
|
|
6524
|
+
return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.optional(type.View));
|
|
6522
6525
|
}
|
|
6523
6526
|
return self;
|
|
6524
6527
|
};
|
|
@@ -6529,7 +6532,7 @@ var descriptors_codec;
|
|
|
6529
6532
|
}) => {
|
|
6530
6533
|
const name = `Sequence<${type.name}>[?]`;
|
|
6531
6534
|
const typicalLength = options.typicalLength ?? TYPICAL_SEQUENCE_LENGTH;
|
|
6532
|
-
return
|
|
6535
|
+
return Descriptor.withView(name, { bytes: typicalLength * type.sizeHint.bytes, isExact: false }, (e, v) => {
|
|
6533
6536
|
validateLength(options, v.length, name);
|
|
6534
6537
|
e.sequenceVarLen(type, v);
|
|
6535
6538
|
}, (d) => {
|
|
@@ -6543,10 +6546,10 @@ var descriptors_codec;
|
|
|
6543
6546
|
}, sequenceViewVarLen(type, options));
|
|
6544
6547
|
};
|
|
6545
6548
|
/** Fixed-length sequence of given type. */
|
|
6546
|
-
codec.sequenceFixLen = (type, len) =>
|
|
6549
|
+
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 }));
|
|
6547
6550
|
/** Small dictionary codec. */
|
|
6548
6551
|
codec.dictionary = (key, value, { sortKeys, fixedLength, }) => {
|
|
6549
|
-
const self =
|
|
6552
|
+
const self = Descriptor.new(`Dictionary<${key.name}, ${value.name}>[${fixedLength ?? "?"}]`, {
|
|
6550
6553
|
bytes: fixedLength !== undefined
|
|
6551
6554
|
? fixedLength * addSizeHints(key.sizeHint, value.sizeHint).bytes
|
|
6552
6555
|
: TYPICAL_DICTIONARY_LENGTH * (addSizeHints(key.sizeHint, value.sizeHint).bytes ?? 0),
|
|
@@ -6585,13 +6588,13 @@ var descriptors_codec;
|
|
|
6585
6588
|
s.sequenceFixLen(value, len);
|
|
6586
6589
|
});
|
|
6587
6590
|
if (hasUniqueView(value)) {
|
|
6588
|
-
return
|
|
6591
|
+
return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.dictionary(key, value.View, { sortKeys, fixedLength }));
|
|
6589
6592
|
}
|
|
6590
6593
|
return self;
|
|
6591
6594
|
};
|
|
6592
6595
|
/** Encoding of pair of two values. */
|
|
6593
6596
|
codec.pair = (a, b) => {
|
|
6594
|
-
const self =
|
|
6597
|
+
const self = Descriptor.new(`Pair<${a.name}, ${b.name}>`, addSizeHints(a.sizeHint, b.sizeHint), (e, elem) => {
|
|
6595
6598
|
a.encode(e, elem[0]);
|
|
6596
6599
|
b.encode(e, elem[1]);
|
|
6597
6600
|
}, (d) => {
|
|
@@ -6603,14 +6606,14 @@ var descriptors_codec;
|
|
|
6603
6606
|
b.skip(s);
|
|
6604
6607
|
});
|
|
6605
6608
|
if (hasUniqueView(a) && hasUniqueView(b)) {
|
|
6606
|
-
return
|
|
6609
|
+
return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.pair(a.View, b.View));
|
|
6607
6610
|
}
|
|
6608
6611
|
return self;
|
|
6609
6612
|
};
|
|
6610
6613
|
/** Custom encoding / decoding logic. */
|
|
6611
|
-
codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) =>
|
|
6614
|
+
codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
|
|
6612
6615
|
/** Choose a descriptor depending on the encoding/decoding context. */
|
|
6613
|
-
codec.select = ({ name, sizeHint, }, chooser) =>
|
|
6616
|
+
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);
|
|
6614
6617
|
/**
|
|
6615
6618
|
* A descriptor for a more complex POJO.
|
|
6616
6619
|
*
|
|
@@ -6647,7 +6650,7 @@ var descriptors_codec;
|
|
|
6647
6650
|
};
|
|
6648
6651
|
const view = objectView(Class, descriptors, sizeHint, skipper);
|
|
6649
6652
|
// and create the descriptor for the entire class.
|
|
6650
|
-
return
|
|
6653
|
+
return Descriptor.withView(Class.name, sizeHint, (e, t) => {
|
|
6651
6654
|
forEachDescriptor(descriptors, (key, descriptor) => {
|
|
6652
6655
|
const value = t[key];
|
|
6653
6656
|
descriptor.encode(e, value);
|
|
@@ -6698,7 +6701,7 @@ function objectView(Class, descriptors, sizeHint, skipper) {
|
|
|
6698
6701
|
});
|
|
6699
6702
|
}
|
|
6700
6703
|
});
|
|
6701
|
-
return
|
|
6704
|
+
return Descriptor.new(`View<${Class.name}>`, sizeHint, (e, t) => {
|
|
6702
6705
|
const encoded = t.encoded();
|
|
6703
6706
|
e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
|
|
6704
6707
|
}, (d) => {
|
|
@@ -6717,7 +6720,7 @@ function sequenceViewVarLen(type, options) {
|
|
|
6717
6720
|
validateLength(options, length, name);
|
|
6718
6721
|
return s.sequenceFixLen(type, length);
|
|
6719
6722
|
};
|
|
6720
|
-
return
|
|
6723
|
+
return Descriptor.new(name, sizeHint, (e, t) => {
|
|
6721
6724
|
validateLength(options, t.length, name);
|
|
6722
6725
|
const encoded = t.encoded();
|
|
6723
6726
|
e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
|
|
@@ -6733,7 +6736,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
|
|
|
6733
6736
|
const skipper = (s) => s.sequenceFixLen(type, fixedLength);
|
|
6734
6737
|
const view = type.name !== type.View.name ? `, ${type.View.name}` : "";
|
|
6735
6738
|
const name = `SeqView<${type.name}${view}>[${fixedLength}]`;
|
|
6736
|
-
return
|
|
6739
|
+
return Descriptor.new(name, sizeHint, (e, t) => {
|
|
6737
6740
|
const encoded = t.encoded();
|
|
6738
6741
|
e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
|
|
6739
6742
|
}, (d) => {
|
|
@@ -8606,7 +8609,7 @@ const codecFixedSizeArray = (val, len) => {
|
|
|
8606
8609
|
};
|
|
8607
8610
|
/** Codec for a hash-dictionary. */
|
|
8608
8611
|
const codecHashDictionary = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH, compare = (a, b) => extractKey(a).compare(extractKey(b)), } = {}) => {
|
|
8609
|
-
return
|
|
8612
|
+
return Descriptor.new(`HashDictionary<${value.name}>[?]`, {
|
|
8610
8613
|
bytes: typicalLength * value.sizeHint.bytes,
|
|
8611
8614
|
isExact: false,
|
|
8612
8615
|
}, (e, v) => {
|
|
@@ -11590,6 +11593,13 @@ const gp_constants_W_T = 128;
|
|
|
11590
11593
|
/** `W_M`: The maximum number of exports in a work-package. */
|
|
11591
11594
|
const gp_constants_W_X = 3_072;
|
|
11592
11595
|
// TODO [ToDr] Not sure where these should live yet :(
|
|
11596
|
+
/**
|
|
11597
|
+
* `S`: The minimum public service index.
|
|
11598
|
+
* Services of indices below these may only be created by the Registrar.
|
|
11599
|
+
*
|
|
11600
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
|
|
11601
|
+
*/
|
|
11602
|
+
const gp_constants_MIN_PUBLIC_SERVICE_INDEX = (/* unused pure expression or super */ null && (2 ** 16));
|
|
11593
11603
|
/**
|
|
11594
11604
|
* `J`: The maximum sum of dependency items in a work-report.
|
|
11595
11605
|
*
|
|
@@ -11601,9 +11611,209 @@ const gp_constants_AUTHORIZATION_QUEUE_SIZE = gp_constants_Q;
|
|
|
11601
11611
|
/** `O`: Maximal authorization pool size. */
|
|
11602
11612
|
const gp_constants_MAX_AUTH_POOL_SIZE = gp_constants_O;
|
|
11603
11613
|
|
|
11614
|
+
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
|
|
11615
|
+
const math_consts_MAX_VALUE = 4294967295;
|
|
11616
|
+
const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
|
|
11617
|
+
const math_consts_MIN_VALUE = (/* unused pure expression or super */ null && (-(2 ** 31)));
|
|
11618
|
+
const math_consts_MAX_SHIFT_U32 = 32;
|
|
11619
|
+
const math_consts_MAX_SHIFT_U64 = 64n;
|
|
11620
|
+
|
|
11621
|
+
;// CONCATENATED MODULE: ./packages/jam/state/service.ts
|
|
11622
|
+
|
|
11623
|
+
|
|
11624
|
+
|
|
11625
|
+
|
|
11626
|
+
|
|
11627
|
+
|
|
11628
|
+
/**
|
|
11629
|
+
* `B_S`: The basic minimum balance which all services require.
|
|
11630
|
+
*
|
|
11631
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
11632
|
+
*/
|
|
11633
|
+
const service_BASE_SERVICE_BALANCE = 100n;
|
|
11634
|
+
/**
|
|
11635
|
+
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
11636
|
+
*
|
|
11637
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
11638
|
+
*/
|
|
11639
|
+
const service_ELECTIVE_ITEM_BALANCE = 10n;
|
|
11640
|
+
/**
|
|
11641
|
+
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
11642
|
+
*
|
|
11643
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
11644
|
+
*/
|
|
11645
|
+
const service_ELECTIVE_BYTE_BALANCE = 1n;
|
|
11646
|
+
const zeroSizeHint = {
|
|
11647
|
+
bytes: 0,
|
|
11648
|
+
isExact: true,
|
|
11649
|
+
};
|
|
11650
|
+
/** 0-byte read, return given default value */
|
|
11651
|
+
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
11652
|
+
/** Encode and decode object with leading version number. */
|
|
11653
|
+
const codecWithVersion = (val) => Descriptor.new("withVersion", {
|
|
11654
|
+
bytes: val.sizeHint.bytes + 8,
|
|
11655
|
+
isExact: false,
|
|
11656
|
+
}, (e, v) => {
|
|
11657
|
+
e.varU64(0n);
|
|
11658
|
+
val.encode(e, v);
|
|
11659
|
+
}, (d) => {
|
|
11660
|
+
const version = d.varU64();
|
|
11661
|
+
if (version !== 0n) {
|
|
11662
|
+
throw new Error("Non-zero version is not supported!");
|
|
11663
|
+
}
|
|
11664
|
+
return val.decode(d);
|
|
11665
|
+
}, (s) => {
|
|
11666
|
+
s.varU64();
|
|
11667
|
+
val.skip(s);
|
|
11668
|
+
});
|
|
11669
|
+
/**
|
|
11670
|
+
* Service account details.
|
|
11671
|
+
*
|
|
11672
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
|
|
11673
|
+
*/
|
|
11674
|
+
class service_ServiceAccountInfo extends WithDebug {
|
|
11675
|
+
codeHash;
|
|
11676
|
+
balance;
|
|
11677
|
+
accumulateMinGas;
|
|
11678
|
+
onTransferMinGas;
|
|
11679
|
+
storageUtilisationBytes;
|
|
11680
|
+
gratisStorage;
|
|
11681
|
+
storageUtilisationCount;
|
|
11682
|
+
created;
|
|
11683
|
+
lastAccumulation;
|
|
11684
|
+
parentService;
|
|
11685
|
+
static Codec = descriptors_codec.Class(service_ServiceAccountInfo, {
|
|
11686
|
+
codeHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
11687
|
+
balance: descriptors_codec.u64,
|
|
11688
|
+
accumulateMinGas: descriptors_codec.u64.convert((x) => x, common_tryAsServiceGas),
|
|
11689
|
+
onTransferMinGas: descriptors_codec.u64.convert((x) => x, common_tryAsServiceGas),
|
|
11690
|
+
storageUtilisationBytes: descriptors_codec.u64,
|
|
11691
|
+
gratisStorage: descriptors_codec.u64,
|
|
11692
|
+
storageUtilisationCount: descriptors_codec.u32,
|
|
11693
|
+
created: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
|
|
11694
|
+
lastAccumulation: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
|
|
11695
|
+
parentService: descriptors_codec.u32.convert((x) => x, common_tryAsServiceId),
|
|
11696
|
+
});
|
|
11697
|
+
static create(a) {
|
|
11698
|
+
return new service_ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
|
|
11699
|
+
}
|
|
11700
|
+
/**
|
|
11701
|
+
* `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
|
|
11702
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
|
|
11703
|
+
*/
|
|
11704
|
+
static calculateThresholdBalance(items, bytes, gratisStorage) {
|
|
11705
|
+
const storageCost = service_BASE_SERVICE_BALANCE + service_ELECTIVE_ITEM_BALANCE * BigInt(items) + service_ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
|
|
11706
|
+
if (storageCost < 0n) {
|
|
11707
|
+
return numbers_tryAsU64(0);
|
|
11708
|
+
}
|
|
11709
|
+
if (storageCost >= 2n ** 64n) {
|
|
11710
|
+
return numbers_tryAsU64(2n ** 64n - 1n);
|
|
11711
|
+
}
|
|
11712
|
+
return numbers_tryAsU64(storageCost);
|
|
11713
|
+
}
|
|
11714
|
+
constructor(
|
|
11715
|
+
/** `a_c`: Hash of the service code. */
|
|
11716
|
+
codeHash,
|
|
11717
|
+
/** `a_b`: Current account balance. */
|
|
11718
|
+
balance,
|
|
11719
|
+
/** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
|
|
11720
|
+
accumulateMinGas,
|
|
11721
|
+
/** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
|
|
11722
|
+
onTransferMinGas,
|
|
11723
|
+
/** `a_o`: Total number of octets in storage. */
|
|
11724
|
+
storageUtilisationBytes,
|
|
11725
|
+
/** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
|
|
11726
|
+
gratisStorage,
|
|
11727
|
+
/** `a_i`: Number of items in storage. */
|
|
11728
|
+
storageUtilisationCount,
|
|
11729
|
+
/** `a_r`: Creation account time slot. */
|
|
11730
|
+
created,
|
|
11731
|
+
/** `a_a`: Most recent accumulation time slot. */
|
|
11732
|
+
lastAccumulation,
|
|
11733
|
+
/** `a_p`: Parent service ID. */
|
|
11734
|
+
parentService) {
|
|
11735
|
+
super();
|
|
11736
|
+
this.codeHash = codeHash;
|
|
11737
|
+
this.balance = balance;
|
|
11738
|
+
this.accumulateMinGas = accumulateMinGas;
|
|
11739
|
+
this.onTransferMinGas = onTransferMinGas;
|
|
11740
|
+
this.storageUtilisationBytes = storageUtilisationBytes;
|
|
11741
|
+
this.gratisStorage = gratisStorage;
|
|
11742
|
+
this.storageUtilisationCount = storageUtilisationCount;
|
|
11743
|
+
this.created = created;
|
|
11744
|
+
this.lastAccumulation = lastAccumulation;
|
|
11745
|
+
this.parentService = parentService;
|
|
11746
|
+
}
|
|
11747
|
+
}
|
|
11748
|
+
class service_PreimageItem extends WithDebug {
|
|
11749
|
+
hash;
|
|
11750
|
+
blob;
|
|
11751
|
+
static Codec = descriptors_codec.Class(service_PreimageItem, {
|
|
11752
|
+
hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
11753
|
+
blob: descriptors_codec.blob,
|
|
11754
|
+
});
|
|
11755
|
+
static create({ hash, blob }) {
|
|
11756
|
+
return new service_PreimageItem(hash, blob);
|
|
11757
|
+
}
|
|
11758
|
+
constructor(hash, blob) {
|
|
11759
|
+
super();
|
|
11760
|
+
this.hash = hash;
|
|
11761
|
+
this.blob = blob;
|
|
11762
|
+
}
|
|
11763
|
+
}
|
|
11764
|
+
class service_StorageItem extends WithDebug {
|
|
11765
|
+
key;
|
|
11766
|
+
value;
|
|
11767
|
+
static Codec = descriptors_codec.Class(service_StorageItem, {
|
|
11768
|
+
key: descriptors_codec.blob.convert((i) => i, (o) => opaque_asOpaqueType(o)),
|
|
11769
|
+
value: descriptors_codec.blob,
|
|
11770
|
+
});
|
|
11771
|
+
static create({ key, value }) {
|
|
11772
|
+
return new service_StorageItem(key, value);
|
|
11773
|
+
}
|
|
11774
|
+
constructor(key, value) {
|
|
11775
|
+
super();
|
|
11776
|
+
this.key = key;
|
|
11777
|
+
this.value = value;
|
|
11778
|
+
}
|
|
11779
|
+
}
|
|
11780
|
+
const MAX_LOOKUP_HISTORY_SLOTS = 3;
|
|
11781
|
+
function service_tryAsLookupHistorySlots(items) {
|
|
11782
|
+
const knownSize = sized_array_asKnownSize(items);
|
|
11783
|
+
if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
|
|
11784
|
+
throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
|
|
11785
|
+
}
|
|
11786
|
+
return knownSize;
|
|
11787
|
+
}
|
|
11788
|
+
/** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
|
|
11789
|
+
class service_LookupHistoryItem {
|
|
11790
|
+
hash;
|
|
11791
|
+
length;
|
|
11792
|
+
slots;
|
|
11793
|
+
constructor(hash, length,
|
|
11794
|
+
/**
|
|
11795
|
+
* Preimage availability history as a sequence of time slots.
|
|
11796
|
+
* See PreimageStatus and the following GP fragment for more details.
|
|
11797
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
|
|
11798
|
+
slots) {
|
|
11799
|
+
this.hash = hash;
|
|
11800
|
+
this.length = length;
|
|
11801
|
+
this.slots = slots;
|
|
11802
|
+
}
|
|
11803
|
+
static isRequested(item) {
|
|
11804
|
+
if ("slots" in item) {
|
|
11805
|
+
return item.slots.length === 0;
|
|
11806
|
+
}
|
|
11807
|
+
return item.length === 0;
|
|
11808
|
+
}
|
|
11809
|
+
}
|
|
11810
|
+
|
|
11604
11811
|
;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
|
|
11605
11812
|
|
|
11606
11813
|
|
|
11814
|
+
|
|
11815
|
+
|
|
11816
|
+
|
|
11607
11817
|
/** Dictionary entry of services that auto-accumulate every block. */
|
|
11608
11818
|
class privileged_services_AutoAccumulate {
|
|
11609
11819
|
service;
|
|
@@ -11625,39 +11835,50 @@ class privileged_services_AutoAccumulate {
|
|
|
11625
11835
|
}
|
|
11626
11836
|
}
|
|
11627
11837
|
/**
|
|
11628
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
11838
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
|
|
11629
11839
|
*/
|
|
11630
11840
|
class privileged_services_PrivilegedServices {
|
|
11631
11841
|
manager;
|
|
11632
|
-
|
|
11633
|
-
|
|
11842
|
+
delegator;
|
|
11843
|
+
registrar;
|
|
11844
|
+
assigners;
|
|
11634
11845
|
autoAccumulateServices;
|
|
11846
|
+
/** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
|
|
11635
11847
|
static Codec = descriptors_codec.Class(privileged_services_PrivilegedServices, {
|
|
11636
11848
|
manager: descriptors_codec.u32.asOpaque(),
|
|
11637
|
-
|
|
11638
|
-
|
|
11849
|
+
assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
|
|
11850
|
+
delegator: descriptors_codec.u32.asOpaque(),
|
|
11851
|
+
registrar: compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1)
|
|
11852
|
+
? descriptors_codec.u32.asOpaque()
|
|
11853
|
+
: ignoreValueWithDefault(common_tryAsServiceId(2 ** 32 - 1)),
|
|
11639
11854
|
autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(privileged_services_AutoAccumulate.Codec)),
|
|
11640
11855
|
});
|
|
11641
|
-
static create(
|
|
11642
|
-
return new privileged_services_PrivilegedServices(manager,
|
|
11856
|
+
static create(a) {
|
|
11857
|
+
return new privileged_services_PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
11643
11858
|
}
|
|
11644
11859
|
constructor(
|
|
11645
11860
|
/**
|
|
11646
|
-
*
|
|
11647
|
-
* the service able to effect an alteration of χ from block to block,
|
|
11861
|
+
* `χ_M`: Manages alteration of χ from block to block,
|
|
11648
11862
|
* as well as bestow services with storage deposit credits.
|
|
11649
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
11863
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
11650
11864
|
*/
|
|
11651
11865
|
manager,
|
|
11652
|
-
/**
|
|
11653
|
-
|
|
11654
|
-
/**
|
|
11655
|
-
|
|
11656
|
-
|
|
11866
|
+
/** `χ_V`: Managers validator keys. */
|
|
11867
|
+
delegator,
|
|
11868
|
+
/**
|
|
11869
|
+
* `χ_R`: Manages the creation of services in protected range.
|
|
11870
|
+
*
|
|
11871
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
|
|
11872
|
+
*/
|
|
11873
|
+
registrar,
|
|
11874
|
+
/** `χ_A`: Manages authorization queue one for each core. */
|
|
11875
|
+
assigners,
|
|
11876
|
+
/** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
|
|
11657
11877
|
autoAccumulateServices) {
|
|
11658
11878
|
this.manager = manager;
|
|
11659
|
-
this.
|
|
11660
|
-
this.
|
|
11879
|
+
this.delegator = delegator;
|
|
11880
|
+
this.registrar = registrar;
|
|
11881
|
+
this.assigners = assigners;
|
|
11661
11882
|
this.autoAccumulateServices = autoAccumulateServices;
|
|
11662
11883
|
}
|
|
11663
11884
|
}
|
|
@@ -11745,7 +11966,7 @@ class recent_blocks_RecentBlocks extends WithDebug {
|
|
|
11745
11966
|
*/
|
|
11746
11967
|
class recent_blocks_RecentBlocksHistory extends WithDebug {
|
|
11747
11968
|
current;
|
|
11748
|
-
static Codec =
|
|
11969
|
+
static Codec = Descriptor.new("RecentBlocksHistory", recent_blocks_RecentBlocks.Codec.sizeHint, (encoder, value) => recent_blocks_RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
|
|
11749
11970
|
const recentBlocks = recent_blocks_RecentBlocks.Codec.decode(decoder);
|
|
11750
11971
|
return recent_blocks_RecentBlocksHistory.create(recentBlocks);
|
|
11751
11972
|
}, (skip) => {
|
|
@@ -11942,196 +12163,6 @@ class safrole_data_SafroleData {
|
|
|
11942
12163
|
}
|
|
11943
12164
|
}
|
|
11944
12165
|
|
|
11945
|
-
;// CONCATENATED MODULE: ./packages/jam/state/service.ts
|
|
11946
|
-
|
|
11947
|
-
|
|
11948
|
-
|
|
11949
|
-
|
|
11950
|
-
|
|
11951
|
-
|
|
11952
|
-
/**
|
|
11953
|
-
* `B_S`: The basic minimum balance which all services require.
|
|
11954
|
-
*
|
|
11955
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
11956
|
-
*/
|
|
11957
|
-
const service_BASE_SERVICE_BALANCE = 100n;
|
|
11958
|
-
/**
|
|
11959
|
-
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
11960
|
-
*
|
|
11961
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
11962
|
-
*/
|
|
11963
|
-
const service_ELECTIVE_ITEM_BALANCE = 10n;
|
|
11964
|
-
/**
|
|
11965
|
-
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
11966
|
-
*
|
|
11967
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
11968
|
-
*/
|
|
11969
|
-
const service_ELECTIVE_BYTE_BALANCE = 1n;
|
|
11970
|
-
const zeroSizeHint = {
|
|
11971
|
-
bytes: 0,
|
|
11972
|
-
isExact: true,
|
|
11973
|
-
};
|
|
11974
|
-
/** 0-byte read, return given default value */
|
|
11975
|
-
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
11976
|
-
/** Encode and decode object with leading version number. */
|
|
11977
|
-
const codecWithVersion = (val) => descriptor_Descriptor.new("withVersion", {
|
|
11978
|
-
bytes: val.sizeHint.bytes + 8,
|
|
11979
|
-
isExact: false,
|
|
11980
|
-
}, (e, v) => {
|
|
11981
|
-
e.varU64(0n);
|
|
11982
|
-
val.encode(e, v);
|
|
11983
|
-
}, (d) => {
|
|
11984
|
-
const version = d.varU64();
|
|
11985
|
-
if (version !== 0n) {
|
|
11986
|
-
throw new Error("Non-zero version is not supported!");
|
|
11987
|
-
}
|
|
11988
|
-
return val.decode(d);
|
|
11989
|
-
}, (s) => {
|
|
11990
|
-
s.varU64();
|
|
11991
|
-
val.skip(s);
|
|
11992
|
-
});
|
|
11993
|
-
/**
|
|
11994
|
-
* Service account details.
|
|
11995
|
-
*
|
|
11996
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
|
|
11997
|
-
*/
|
|
11998
|
-
class service_ServiceAccountInfo extends WithDebug {
|
|
11999
|
-
codeHash;
|
|
12000
|
-
balance;
|
|
12001
|
-
accumulateMinGas;
|
|
12002
|
-
onTransferMinGas;
|
|
12003
|
-
storageUtilisationBytes;
|
|
12004
|
-
gratisStorage;
|
|
12005
|
-
storageUtilisationCount;
|
|
12006
|
-
created;
|
|
12007
|
-
lastAccumulation;
|
|
12008
|
-
parentService;
|
|
12009
|
-
static Codec = descriptors_codec.Class(service_ServiceAccountInfo, {
|
|
12010
|
-
codeHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
12011
|
-
balance: descriptors_codec.u64,
|
|
12012
|
-
accumulateMinGas: descriptors_codec.u64.convert((x) => x, common_tryAsServiceGas),
|
|
12013
|
-
onTransferMinGas: descriptors_codec.u64.convert((x) => x, common_tryAsServiceGas),
|
|
12014
|
-
storageUtilisationBytes: descriptors_codec.u64,
|
|
12015
|
-
gratisStorage: descriptors_codec.u64,
|
|
12016
|
-
storageUtilisationCount: descriptors_codec.u32,
|
|
12017
|
-
created: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
|
|
12018
|
-
lastAccumulation: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
|
|
12019
|
-
parentService: descriptors_codec.u32.convert((x) => x, common_tryAsServiceId),
|
|
12020
|
-
});
|
|
12021
|
-
static create(a) {
|
|
12022
|
-
return new service_ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
|
|
12023
|
-
}
|
|
12024
|
-
/**
|
|
12025
|
-
* `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
|
|
12026
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
|
|
12027
|
-
*/
|
|
12028
|
-
static calculateThresholdBalance(items, bytes, gratisStorage) {
|
|
12029
|
-
const storageCost = service_BASE_SERVICE_BALANCE + service_ELECTIVE_ITEM_BALANCE * BigInt(items) + service_ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
|
|
12030
|
-
if (storageCost < 0n) {
|
|
12031
|
-
return numbers_tryAsU64(0);
|
|
12032
|
-
}
|
|
12033
|
-
if (storageCost >= 2n ** 64n) {
|
|
12034
|
-
return numbers_tryAsU64(2n ** 64n - 1n);
|
|
12035
|
-
}
|
|
12036
|
-
return numbers_tryAsU64(storageCost);
|
|
12037
|
-
}
|
|
12038
|
-
constructor(
|
|
12039
|
-
/** `a_c`: Hash of the service code. */
|
|
12040
|
-
codeHash,
|
|
12041
|
-
/** `a_b`: Current account balance. */
|
|
12042
|
-
balance,
|
|
12043
|
-
/** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
|
|
12044
|
-
accumulateMinGas,
|
|
12045
|
-
/** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
|
|
12046
|
-
onTransferMinGas,
|
|
12047
|
-
/** `a_o`: Total number of octets in storage. */
|
|
12048
|
-
storageUtilisationBytes,
|
|
12049
|
-
/** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
|
|
12050
|
-
gratisStorage,
|
|
12051
|
-
/** `a_i`: Number of items in storage. */
|
|
12052
|
-
storageUtilisationCount,
|
|
12053
|
-
/** `a_r`: Creation account time slot. */
|
|
12054
|
-
created,
|
|
12055
|
-
/** `a_a`: Most recent accumulation time slot. */
|
|
12056
|
-
lastAccumulation,
|
|
12057
|
-
/** `a_p`: Parent service ID. */
|
|
12058
|
-
parentService) {
|
|
12059
|
-
super();
|
|
12060
|
-
this.codeHash = codeHash;
|
|
12061
|
-
this.balance = balance;
|
|
12062
|
-
this.accumulateMinGas = accumulateMinGas;
|
|
12063
|
-
this.onTransferMinGas = onTransferMinGas;
|
|
12064
|
-
this.storageUtilisationBytes = storageUtilisationBytes;
|
|
12065
|
-
this.gratisStorage = gratisStorage;
|
|
12066
|
-
this.storageUtilisationCount = storageUtilisationCount;
|
|
12067
|
-
this.created = created;
|
|
12068
|
-
this.lastAccumulation = lastAccumulation;
|
|
12069
|
-
this.parentService = parentService;
|
|
12070
|
-
}
|
|
12071
|
-
}
|
|
12072
|
-
class service_PreimageItem extends WithDebug {
|
|
12073
|
-
hash;
|
|
12074
|
-
blob;
|
|
12075
|
-
static Codec = descriptors_codec.Class(service_PreimageItem, {
|
|
12076
|
-
hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
12077
|
-
blob: descriptors_codec.blob,
|
|
12078
|
-
});
|
|
12079
|
-
static create({ hash, blob }) {
|
|
12080
|
-
return new service_PreimageItem(hash, blob);
|
|
12081
|
-
}
|
|
12082
|
-
constructor(hash, blob) {
|
|
12083
|
-
super();
|
|
12084
|
-
this.hash = hash;
|
|
12085
|
-
this.blob = blob;
|
|
12086
|
-
}
|
|
12087
|
-
}
|
|
12088
|
-
class service_StorageItem extends WithDebug {
|
|
12089
|
-
key;
|
|
12090
|
-
value;
|
|
12091
|
-
static Codec = descriptors_codec.Class(service_StorageItem, {
|
|
12092
|
-
key: descriptors_codec.blob.convert((i) => i, (o) => opaque_asOpaqueType(o)),
|
|
12093
|
-
value: descriptors_codec.blob,
|
|
12094
|
-
});
|
|
12095
|
-
static create({ key, value }) {
|
|
12096
|
-
return new service_StorageItem(key, value);
|
|
12097
|
-
}
|
|
12098
|
-
constructor(key, value) {
|
|
12099
|
-
super();
|
|
12100
|
-
this.key = key;
|
|
12101
|
-
this.value = value;
|
|
12102
|
-
}
|
|
12103
|
-
}
|
|
12104
|
-
const MAX_LOOKUP_HISTORY_SLOTS = 3;
|
|
12105
|
-
function service_tryAsLookupHistorySlots(items) {
|
|
12106
|
-
const knownSize = sized_array_asKnownSize(items);
|
|
12107
|
-
if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
|
|
12108
|
-
throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
|
|
12109
|
-
}
|
|
12110
|
-
return knownSize;
|
|
12111
|
-
}
|
|
12112
|
-
/** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
|
|
12113
|
-
class service_LookupHistoryItem {
|
|
12114
|
-
hash;
|
|
12115
|
-
length;
|
|
12116
|
-
slots;
|
|
12117
|
-
constructor(hash, length,
|
|
12118
|
-
/**
|
|
12119
|
-
* Preimage availability history as a sequence of time slots.
|
|
12120
|
-
* See PreimageStatus and the following GP fragment for more details.
|
|
12121
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
|
|
12122
|
-
slots) {
|
|
12123
|
-
this.hash = hash;
|
|
12124
|
-
this.length = length;
|
|
12125
|
-
this.slots = slots;
|
|
12126
|
-
}
|
|
12127
|
-
static isRequested(item) {
|
|
12128
|
-
if ("slots" in item) {
|
|
12129
|
-
return item.slots.length === 0;
|
|
12130
|
-
}
|
|
12131
|
-
return item.length === 0;
|
|
12132
|
-
}
|
|
12133
|
-
}
|
|
12134
|
-
|
|
12135
12166
|
;// CONCATENATED MODULE: ./packages/jam/state/state.ts
|
|
12136
12167
|
/**
|
|
12137
12168
|
* In addition to the entropy accumulator η_0, we retain
|
|
@@ -12568,6 +12599,7 @@ class statistics_StatisticsData {
|
|
|
12568
12599
|
|
|
12569
12600
|
|
|
12570
12601
|
|
|
12602
|
+
|
|
12571
12603
|
|
|
12572
12604
|
|
|
12573
12605
|
var in_memory_state_UpdateError;
|
|
@@ -12971,8 +13003,9 @@ class InMemoryState extends WithDebug {
|
|
|
12971
13003
|
epochRoot: bytes_Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
12972
13004
|
privilegedServices: privileged_services_PrivilegedServices.create({
|
|
12973
13005
|
manager: common_tryAsServiceId(0),
|
|
12974
|
-
|
|
12975
|
-
|
|
13006
|
+
assigners: common_tryAsPerCore(new Array(spec.coresCount).fill(common_tryAsServiceId(0)), spec),
|
|
13007
|
+
delegator: common_tryAsServiceId(0),
|
|
13008
|
+
registrar: common_tryAsServiceId(math_consts_MAX_VALUE),
|
|
12976
13009
|
autoAccumulateServices: [],
|
|
12977
13010
|
}),
|
|
12978
13011
|
accumulationOutputLog: sorted_array_SortedArray.fromArray(accumulation_output_accumulationOutputComparator, []),
|
|
@@ -13018,6 +13051,7 @@ const serviceDataCodec = descriptors_codec.dictionary(descriptors_codec.u32.asOp
|
|
|
13018
13051
|
|
|
13019
13052
|
class JsonServiceInfo {
|
|
13020
13053
|
static fromJson = json.object({
|
|
13054
|
+
...(compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1) ? { version: "number" } : {}),
|
|
13021
13055
|
code_hash: fromJson.bytes32(),
|
|
13022
13056
|
balance: json.fromNumber((x) => numbers_tryAsU64(x)),
|
|
13023
13057
|
min_item_gas: json.fromNumber((x) => common_tryAsServiceGas(x)),
|
|
@@ -13042,6 +13076,7 @@ class JsonServiceInfo {
|
|
|
13042
13076
|
parentService: parent_service,
|
|
13043
13077
|
});
|
|
13044
13078
|
});
|
|
13079
|
+
version;
|
|
13045
13080
|
code_hash;
|
|
13046
13081
|
balance;
|
|
13047
13082
|
min_item_gas;
|
|
@@ -13076,23 +13111,35 @@ const lookupMetaFromJson = json.object({
|
|
|
13076
13111
|
},
|
|
13077
13112
|
value: json.array("number"),
|
|
13078
13113
|
}, ({ key, value }) => new service_LookupHistoryItem(key.hash, key.length, value));
|
|
13114
|
+
const preimageStatusFromJson = json.object({
|
|
13115
|
+
hash: fromJson.bytes32(),
|
|
13116
|
+
status: json.array("number"),
|
|
13117
|
+
}, ({ hash, status }) => new service_LookupHistoryItem(hash, numbers_tryAsU32(0), status));
|
|
13079
13118
|
class JsonService {
|
|
13080
13119
|
static fromJson = json.object({
|
|
13081
13120
|
id: "number",
|
|
13082
|
-
data:
|
|
13083
|
-
|
|
13084
|
-
|
|
13085
|
-
|
|
13086
|
-
|
|
13087
|
-
|
|
13121
|
+
data: compatibility_Compatibility.isLessThan(compatibility_GpVersion.V0_7_1)
|
|
13122
|
+
? {
|
|
13123
|
+
service: JsonServiceInfo.fromJson,
|
|
13124
|
+
preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
|
|
13125
|
+
storage: json.optional(json.array(JsonStorageItem.fromJson)),
|
|
13126
|
+
lookup_meta: json.optional(json.array(lookupMetaFromJson)),
|
|
13127
|
+
}
|
|
13128
|
+
: {
|
|
13129
|
+
service: JsonServiceInfo.fromJson,
|
|
13130
|
+
storage: json.optional(json.array(JsonStorageItem.fromJson)),
|
|
13131
|
+
preimages_blob: json.optional(json.array(JsonPreimageItem.fromJson)),
|
|
13132
|
+
preimages_status: json.optional(json.array(preimageStatusFromJson)),
|
|
13133
|
+
},
|
|
13088
13134
|
}, ({ id, data }) => {
|
|
13135
|
+
const preimages = hash_dictionary_HashDictionary.fromEntries((data.preimages ?? data.preimages_blob ?? []).map((x) => [x.hash, x]));
|
|
13089
13136
|
const lookupHistory = hash_dictionary_HashDictionary.new();
|
|
13090
|
-
for (const item of data.lookup_meta ?? []) {
|
|
13137
|
+
for (const item of data.lookup_meta ?? data.preimages_status ?? []) {
|
|
13091
13138
|
const data = lookupHistory.get(item.hash) ?? [];
|
|
13092
|
-
|
|
13139
|
+
const length = numbers_tryAsU32(preimages.get(item.hash)?.blob.length ?? item.length);
|
|
13140
|
+
data.push(new service_LookupHistoryItem(item.hash, length, item.slots));
|
|
13093
13141
|
lookupHistory.set(item.hash, data);
|
|
13094
13142
|
}
|
|
13095
|
-
const preimages = hash_dictionary_HashDictionary.fromEntries((data.preimages ?? []).map((x) => [x.hash, x]));
|
|
13096
13143
|
const storage = new Map();
|
|
13097
13144
|
const entries = (data.storage ?? []).map(({ key, value }) => {
|
|
13098
13145
|
const opaqueKey = opaque_asOpaqueType(key);
|
|
@@ -13287,6 +13334,8 @@ class TicketsOrKeys {
|
|
|
13287
13334
|
|
|
13288
13335
|
|
|
13289
13336
|
|
|
13337
|
+
|
|
13338
|
+
|
|
13290
13339
|
class JsonValidatorStatistics {
|
|
13291
13340
|
static fromJson = json.object({
|
|
13292
13341
|
blocks: "number",
|
|
@@ -13355,8 +13404,12 @@ class JsonServiceStatistics {
|
|
|
13355
13404
|
extrinsic_count: "number",
|
|
13356
13405
|
accumulate_count: "number",
|
|
13357
13406
|
accumulate_gas_used: json.fromNumber(common_tryAsServiceGas),
|
|
13358
|
-
|
|
13359
|
-
|
|
13407
|
+
...(compatibility_Compatibility.isLessThan(compatibility_GpVersion.V0_7_1)
|
|
13408
|
+
? {
|
|
13409
|
+
on_transfers_count: "number",
|
|
13410
|
+
on_transfers_gas_used: json.fromNumber(common_tryAsServiceGas),
|
|
13411
|
+
}
|
|
13412
|
+
: {}),
|
|
13360
13413
|
}, ({ provided_count, provided_size, refinement_count, refinement_gas_used, imports, exports, extrinsic_size, extrinsic_count, accumulate_count, accumulate_gas_used, on_transfers_count, on_transfers_gas_used, }) => {
|
|
13361
13414
|
return statistics_ServiceStatistics.create({
|
|
13362
13415
|
providedCount: provided_count,
|
|
@@ -13369,8 +13422,8 @@ class JsonServiceStatistics {
|
|
|
13369
13422
|
extrinsicCount: extrinsic_count,
|
|
13370
13423
|
accumulateCount: accumulate_count,
|
|
13371
13424
|
accumulateGasUsed: accumulate_gas_used,
|
|
13372
|
-
onTransfersCount: on_transfers_count,
|
|
13373
|
-
onTransfersGasUsed: on_transfers_gas_used,
|
|
13425
|
+
onTransfersCount: on_transfers_count ?? numbers_tryAsU32(0),
|
|
13426
|
+
onTransfersGasUsed: on_transfers_gas_used ?? common_tryAsServiceGas(0),
|
|
13374
13427
|
});
|
|
13375
13428
|
});
|
|
13376
13429
|
provided_count;
|
|
@@ -13444,6 +13497,7 @@ const validatorDataFromJson = json.object({
|
|
|
13444
13497
|
|
|
13445
13498
|
|
|
13446
13499
|
|
|
13500
|
+
|
|
13447
13501
|
const fullStateDumpFromJson = (spec) => json.object({
|
|
13448
13502
|
alpha: json.array(json.array(fromJson.bytes32())),
|
|
13449
13503
|
varphi: json.array(json.array(fromJson.bytes32())),
|
|
@@ -13465,6 +13519,7 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
13465
13519
|
chi_m: "number",
|
|
13466
13520
|
chi_a: json.array("number"),
|
|
13467
13521
|
chi_v: "number",
|
|
13522
|
+
chi_r: json.optional("number"),
|
|
13468
13523
|
chi_g: json.nullable(json.array({
|
|
13469
13524
|
service: "number",
|
|
13470
13525
|
gasLimit: json.fromNumber((v) => common_tryAsServiceGas(v)),
|
|
@@ -13476,6 +13531,9 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
13476
13531
|
theta: json.nullable(json.array(accumulationOutput)),
|
|
13477
13532
|
accounts: json.array(JsonService.fromJson),
|
|
13478
13533
|
}, ({ alpha, varphi, beta, gamma, psi, eta, iota, kappa, lambda, rho, tau, chi, pi, omega, xi, theta, accounts, }) => {
|
|
13534
|
+
if (compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1) && chi.chi_r === undefined) {
|
|
13535
|
+
throw new Error("Registrar is required in Privileges GP ^0.7.1");
|
|
13536
|
+
}
|
|
13479
13537
|
return InMemoryState.create({
|
|
13480
13538
|
authPools: common_tryAsPerCore(alpha.map((perCore) => {
|
|
13481
13539
|
if (perCore.length > gp_constants_MAX_AUTH_POOL_SIZE) {
|
|
@@ -13503,8 +13561,9 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
13503
13561
|
timeslot: tau,
|
|
13504
13562
|
privilegedServices: privileged_services_PrivilegedServices.create({
|
|
13505
13563
|
manager: chi.chi_m,
|
|
13506
|
-
|
|
13507
|
-
|
|
13564
|
+
assigners: chi.chi_a,
|
|
13565
|
+
delegator: chi.chi_v,
|
|
13566
|
+
registrar: chi.chi_r ?? common_tryAsServiceId(2 ** 32 - 1),
|
|
13508
13567
|
autoAccumulateServices: chi.chi_g ?? [],
|
|
13509
13568
|
}),
|
|
13510
13569
|
statistics: JsonStatisticsData.toStatisticsData(spec, pi),
|
|
@@ -13846,7 +13905,7 @@ var serialize_serialize;
|
|
|
13846
13905
|
* determine the boundary of the bytes, so it can only be used
|
|
13847
13906
|
* as the last element of the codec and can't be used in sequences!
|
|
13848
13907
|
*/
|
|
13849
|
-
const serialize_dumpCodec =
|
|
13908
|
+
const serialize_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()));
|
|
13850
13909
|
|
|
13851
13910
|
;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
|
|
13852
13911
|
|
|
@@ -15060,7 +15119,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
|
|
|
15060
15119
|
}
|
|
15061
15120
|
return Ordering.Equal;
|
|
15062
15121
|
}, } = {}) => {
|
|
15063
|
-
return
|
|
15122
|
+
return Descriptor.new(`Map<${value.name}>[?]`, {
|
|
15064
15123
|
bytes: typicalLength * value.sizeHint.bytes,
|
|
15065
15124
|
isExact: false,
|
|
15066
15125
|
}, (e, v) => {
|
|
@@ -16709,7 +16768,7 @@ class state_update_AccumulationStateUpdate {
|
|
|
16709
16768
|
if (from.privilegedServices !== null) {
|
|
16710
16769
|
update.privilegedServices = PrivilegedServices.create({
|
|
16711
16770
|
...from.privilegedServices,
|
|
16712
|
-
|
|
16771
|
+
assigners: asKnownSize([...from.privilegedServices.assigners]),
|
|
16713
16772
|
});
|
|
16714
16773
|
}
|
|
16715
16774
|
return update;
|
|
@@ -20577,6 +20636,8 @@ var partial_state_NewServiceError;
|
|
|
20577
20636
|
NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
|
|
20578
20637
|
/** Service is not privileged to set gratis storage. */
|
|
20579
20638
|
NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
|
|
20639
|
+
/** Registrar attempting to create a service with already existing id. */
|
|
20640
|
+
NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
|
|
20580
20641
|
})(partial_state_NewServiceError || (partial_state_NewServiceError = {}));
|
|
20581
20642
|
var partial_state_UpdatePrivilegesError;
|
|
20582
20643
|
(function (UpdatePrivilegesError) {
|
|
@@ -20713,7 +20774,7 @@ const results_HostCallResult = {
|
|
|
20713
20774
|
OOB: numbers_tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
|
|
20714
20775
|
/** Index unknown. */
|
|
20715
20776
|
WHO: numbers_tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
|
|
20716
|
-
/** Storage full. */
|
|
20777
|
+
/** Storage full or resource already allocated. */
|
|
20717
20778
|
FULL: numbers_tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
|
|
20718
20779
|
/** Core index unknown. */
|
|
20719
20780
|
CORE: numbers_tryAsU64(0xfffffffffffffffan), // 2**64 - 6
|
|
@@ -20721,7 +20782,7 @@ const results_HostCallResult = {
|
|
|
20721
20782
|
CASH: numbers_tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
|
|
20722
20783
|
/** Gas limit too low. */
|
|
20723
20784
|
LOW: numbers_tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
|
|
20724
|
-
/** The item is already solicited
|
|
20785
|
+
/** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
|
|
20725
20786
|
HUH: numbers_tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
|
|
20726
20787
|
/** The return value indicating general success. */
|
|
20727
20788
|
OK: numbers_tryAsU64(0n),
|
|
@@ -20775,6 +20836,7 @@ function utils_clampU64ToU32(value) {
|
|
|
20775
20836
|
|
|
20776
20837
|
|
|
20777
20838
|
|
|
20839
|
+
|
|
20778
20840
|
/**
|
|
20779
20841
|
* Number of storage items required for ejection of the service.
|
|
20780
20842
|
*
|
|
@@ -20866,10 +20928,13 @@ class accumulate_externalities_AccumulateExternalities {
|
|
|
20866
20928
|
const isExpired = status.data[1] < t - this.chainSpec.preimageExpungePeriod;
|
|
20867
20929
|
return [isExpired, isExpired ? "" : "not expired"];
|
|
20868
20930
|
}
|
|
20869
|
-
/** `check`: https://graypaper.fluffylabs.dev/#/
|
|
20931
|
+
/** `check`: https://graypaper.fluffylabs.dev/#/ab2cdbd/30c60330c603?v=0.7.2 */
|
|
20870
20932
|
getNextAvailableServiceId(serviceId) {
|
|
20871
20933
|
let currentServiceId = serviceId;
|
|
20872
|
-
const mod =
|
|
20934
|
+
const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
20935
|
+
? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
|
|
20936
|
+
: 2 ** 32 - 2 ** 9;
|
|
20937
|
+
const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
|
|
20873
20938
|
for (;;) {
|
|
20874
20939
|
const service = this.getServiceInfo(currentServiceId);
|
|
20875
20940
|
// we found an empty id
|
|
@@ -20877,7 +20942,7 @@ class accumulate_externalities_AccumulateExternalities {
|
|
|
20877
20942
|
return currentServiceId;
|
|
20878
20943
|
}
|
|
20879
20944
|
// keep trying
|
|
20880
|
-
currentServiceId = tryAsServiceId(((currentServiceId -
|
|
20945
|
+
currentServiceId = tryAsServiceId(((currentServiceId - offset + 1 + mod) % mod) + offset);
|
|
20881
20946
|
}
|
|
20882
20947
|
}
|
|
20883
20948
|
checkPreimageStatus(hash, length) {
|
|
@@ -21034,8 +21099,7 @@ class accumulate_externalities_AccumulateExternalities {
|
|
|
21034
21099
|
}));
|
|
21035
21100
|
return Result.ok(OK);
|
|
21036
21101
|
}
|
|
21037
|
-
newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage) {
|
|
21038
|
-
const newServiceId = this.nextNewServiceId;
|
|
21102
|
+
newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage, wantedServiceId) {
|
|
21039
21103
|
// calculate the threshold. Storage is empty, one preimage requested.
|
|
21040
21104
|
// https://graypaper.fluffylabs.dev/#/7e6ff6a/115901115901?v=0.6.7
|
|
21041
21105
|
const items = tryAsU32(2 * 1 + 0);
|
|
@@ -21056,30 +21120,59 @@ class accumulate_externalities_AccumulateExternalities {
|
|
|
21056
21120
|
if (balanceLeftForCurrent < thresholdForCurrent || bytes.overflow) {
|
|
21057
21121
|
return Result.error(NewServiceError.InsufficientFunds);
|
|
21058
21122
|
}
|
|
21123
|
+
// `a`: https://graypaper.fluffylabs.dev/#/ab2cdbd/366b02366d02?v=0.7.2
|
|
21124
|
+
const newAccount = ServiceAccountInfo.create({
|
|
21125
|
+
codeHash,
|
|
21126
|
+
balance: thresholdForNew,
|
|
21127
|
+
accumulateMinGas,
|
|
21128
|
+
onTransferMinGas,
|
|
21129
|
+
storageUtilisationBytes: bytes.value,
|
|
21130
|
+
storageUtilisationCount: items,
|
|
21131
|
+
gratisStorage,
|
|
21132
|
+
created: this.currentTimeslot,
|
|
21133
|
+
lastAccumulation: tryAsTimeSlot(0),
|
|
21134
|
+
parentService: this.currentServiceId,
|
|
21135
|
+
});
|
|
21136
|
+
const newLookupItem = new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([]));
|
|
21137
|
+
// `s`: https://graypaper.fluffylabs.dev/#/ab2cdbd/361003361003?v=0.7.2
|
|
21138
|
+
const updatedCurrentAccount = ServiceAccountInfo.create({
|
|
21139
|
+
...currentService,
|
|
21140
|
+
balance: tryAsU64(balanceLeftForCurrent),
|
|
21141
|
+
});
|
|
21142
|
+
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
|
|
21143
|
+
if (wantedServiceId < MIN_PUBLIC_SERVICE_INDEX &&
|
|
21144
|
+
this.currentServiceId === this.updatedState.getPrivilegedServices().registrar) {
|
|
21145
|
+
// NOTE: It's safe to cast to `Number` here, bcs here service ID cannot be bigger than 2**16
|
|
21146
|
+
const newServiceId = tryAsServiceId(Number(wantedServiceId));
|
|
21147
|
+
if (this.getServiceInfo(newServiceId) !== null) {
|
|
21148
|
+
return Result.error(NewServiceError.RegistrarServiceIdAlreadyTaken);
|
|
21149
|
+
}
|
|
21150
|
+
// add the new service with selected ID
|
|
21151
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36be0336c003?v=0.7.2
|
|
21152
|
+
this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
|
|
21153
|
+
serviceId: newServiceId,
|
|
21154
|
+
serviceInfo: newAccount,
|
|
21155
|
+
lookupHistory: newLookupItem,
|
|
21156
|
+
}));
|
|
21157
|
+
// update the balance of current service
|
|
21158
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36c20336c403?v=0.7.2
|
|
21159
|
+
this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
|
|
21160
|
+
return Result.ok(newServiceId);
|
|
21161
|
+
}
|
|
21162
|
+
// NOTE: in case the service is not a registrar or the requested serviceId is out of range,
|
|
21163
|
+
// we completely ignore the `wantedServiceId` and assign a random one
|
|
21164
|
+
}
|
|
21165
|
+
const newServiceId = this.nextNewServiceId;
|
|
21059
21166
|
// add the new service
|
|
21060
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
21167
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36e70336e903?v=0.7.2
|
|
21061
21168
|
this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
|
|
21062
21169
|
serviceId: newServiceId,
|
|
21063
|
-
serviceInfo:
|
|
21064
|
-
|
|
21065
|
-
balance: thresholdForNew,
|
|
21066
|
-
accumulateMinGas,
|
|
21067
|
-
onTransferMinGas,
|
|
21068
|
-
storageUtilisationBytes: bytes.value,
|
|
21069
|
-
storageUtilisationCount: items,
|
|
21070
|
-
gratisStorage,
|
|
21071
|
-
created: this.currentTimeslot,
|
|
21072
|
-
lastAccumulation: tryAsTimeSlot(0),
|
|
21073
|
-
parentService: this.currentServiceId,
|
|
21074
|
-
}),
|
|
21075
|
-
lookupHistory: new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([])),
|
|
21170
|
+
serviceInfo: newAccount,
|
|
21171
|
+
lookupHistory: newLookupItem,
|
|
21076
21172
|
}));
|
|
21077
21173
|
// update the balance of current service
|
|
21078
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
21079
|
-
this.updatedState.updateServiceInfo(this.currentServiceId,
|
|
21080
|
-
...currentService,
|
|
21081
|
-
balance: tryAsU64(balanceLeftForCurrent),
|
|
21082
|
-
}));
|
|
21174
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36ec0336ee03?v=0.7.2
|
|
21175
|
+
this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
|
|
21083
21176
|
// update the next service id we are going to create next
|
|
21084
21177
|
// https://graypaper.fluffylabs.dev/#/7e6ff6a/36a70336a703?v=0.6.7
|
|
21085
21178
|
this.nextNewServiceId = this.getNextAvailableServiceId(bumpServiceId(newServiceId));
|
|
@@ -21097,9 +21190,9 @@ class accumulate_externalities_AccumulateExternalities {
|
|
|
21097
21190
|
}
|
|
21098
21191
|
updateValidatorsData(validatorsData) {
|
|
21099
21192
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/362802362d02?v=0.6.7 */
|
|
21100
|
-
const
|
|
21101
|
-
if (
|
|
21102
|
-
accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${
|
|
21193
|
+
const currentDelegator = this.updatedState.getPrivilegedServices().delegator;
|
|
21194
|
+
if (currentDelegator !== this.currentServiceId) {
|
|
21195
|
+
accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${currentDelegator}) and cannot update validators data. Ignoring`;
|
|
21103
21196
|
return Result.error(UnprivilegedError);
|
|
21104
21197
|
}
|
|
21105
21198
|
this.updatedState.stateUpdate.validatorsData = validatorsData;
|
|
@@ -21109,34 +21202,38 @@ class accumulate_externalities_AccumulateExternalities {
|
|
|
21109
21202
|
/** https://graypaper.fluffylabs.dev/#/9a08063/362202362202?v=0.6.6 */
|
|
21110
21203
|
this.checkpointedState = AccumulationStateUpdate.copyFrom(this.updatedState.stateUpdate);
|
|
21111
21204
|
}
|
|
21112
|
-
updateAuthorizationQueue(coreIndex, authQueue,
|
|
21205
|
+
updateAuthorizationQueue(coreIndex, authQueue, assigners) {
|
|
21113
21206
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/36a40136a401?v=0.6.7 */
|
|
21114
21207
|
// NOTE `coreIndex` is already verified in the HC, so this is infallible.
|
|
21115
|
-
const
|
|
21116
|
-
if (
|
|
21117
|
-
accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not an auth manager of core ${coreIndex} (expected: ${
|
|
21208
|
+
const currentAssigners = this.updatedState.getPrivilegedServices().assigners[coreIndex];
|
|
21209
|
+
if (currentAssigners !== this.currentServiceId) {
|
|
21210
|
+
accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not an auth manager of core ${coreIndex} (expected: ${currentAssigners}) and cannot update authorization queue.`;
|
|
21118
21211
|
return Result.error(UpdatePrivilegesError.UnprivilegedService);
|
|
21119
21212
|
}
|
|
21120
|
-
if (
|
|
21121
|
-
accumulate_externalities_logger.trace `The new auth manager is not a valid service id
|
|
21213
|
+
if (assigners === null && Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
|
|
21214
|
+
accumulate_externalities_logger.trace `The new auth manager is not a valid service id.`;
|
|
21122
21215
|
return Result.error(UpdatePrivilegesError.InvalidServiceId);
|
|
21123
21216
|
}
|
|
21124
21217
|
this.updatedState.stateUpdate.authorizationQueues.set(coreIndex, authQueue);
|
|
21125
21218
|
return Result.ok(OK);
|
|
21126
21219
|
}
|
|
21127
|
-
updatePrivilegedServices(manager, authorizers,
|
|
21220
|
+
updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate) {
|
|
21128
21221
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/36d90036de00?v=0.6.7 */
|
|
21129
21222
|
const currentManager = this.updatedState.getPrivilegedServices().manager;
|
|
21130
21223
|
if (currentManager !== this.currentServiceId) {
|
|
21131
21224
|
return Result.error(UpdatePrivilegesError.UnprivilegedService);
|
|
21132
21225
|
}
|
|
21133
|
-
if (manager === null ||
|
|
21134
|
-
return Result.error(UpdatePrivilegesError.InvalidServiceId);
|
|
21226
|
+
if (manager === null || delegator === null) {
|
|
21227
|
+
return Result.error(UpdatePrivilegesError.InvalidServiceId, "Either manager or delegator is not valid service id.");
|
|
21228
|
+
}
|
|
21229
|
+
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && registrar === null) {
|
|
21230
|
+
return Result.error(UpdatePrivilegesError.InvalidServiceId, "Register manager is not valid service id.");
|
|
21135
21231
|
}
|
|
21136
21232
|
this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
|
|
21137
21233
|
manager,
|
|
21138
|
-
|
|
21139
|
-
|
|
21234
|
+
assigners: authorizers,
|
|
21235
|
+
delegator,
|
|
21236
|
+
registrar: registrar ?? tryAsServiceId(0), // introduced in 0.7.1
|
|
21140
21237
|
autoAccumulateServices: autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit })),
|
|
21141
21238
|
});
|
|
21142
21239
|
return Result.ok(OK);
|
|
@@ -21252,8 +21349,11 @@ class accumulate_externalities_AccumulateExternalities {
|
|
|
21252
21349
|
}
|
|
21253
21350
|
}
|
|
21254
21351
|
function bumpServiceId(serviceId) {
|
|
21255
|
-
const mod =
|
|
21256
|
-
|
|
21352
|
+
const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
21353
|
+
? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
|
|
21354
|
+
: 2 ** 32 - 2 ** 9;
|
|
21355
|
+
const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
|
|
21356
|
+
return tryAsServiceId(offset + ((serviceId - offset + 42 + mod) % mod));
|
|
21257
21357
|
}
|
|
21258
21358
|
|
|
21259
21359
|
;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/operand.ts
|
|
@@ -21905,6 +22005,8 @@ class accumulate_data_AccumulateData {
|
|
|
21905
22005
|
|
|
21906
22006
|
|
|
21907
22007
|
|
|
22008
|
+
|
|
22009
|
+
|
|
21908
22010
|
/**
|
|
21909
22011
|
* A function that removes duplicates but does not change order - it keeps the first occurence.
|
|
21910
22012
|
*/
|
|
@@ -21934,7 +22036,7 @@ const NEXT_ID_CODEC = descriptors_codec.object({
|
|
|
21934
22036
|
*
|
|
21935
22037
|
* Please not that it does not call `check` function!
|
|
21936
22038
|
*
|
|
21937
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
22039
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/2fa9042fc304?v=0.7.2
|
|
21938
22040
|
*/
|
|
21939
22041
|
function accumulate_utils_generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blake2b) {
|
|
21940
22042
|
const encoded = Encoder.encodeObject(NEXT_ID_CODEC, {
|
|
@@ -21944,7 +22046,11 @@ function accumulate_utils_generateNextServiceId({ serviceId, entropy, timeslot }
|
|
|
21944
22046
|
}, chainSpec);
|
|
21945
22047
|
const result = blake2b.hashBytes(encoded).raw.subarray(0, 4);
|
|
21946
22048
|
const number = leBytesAsU32(result) >>> 0;
|
|
21947
|
-
|
|
22049
|
+
const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
22050
|
+
? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
|
|
22051
|
+
: 2 ** 32 - 2 ** 9;
|
|
22052
|
+
const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
|
|
22053
|
+
return tryAsServiceId((number % mod) + offset);
|
|
21948
22054
|
}
|
|
21949
22055
|
|
|
21950
22056
|
;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-queue.ts
|
|
@@ -22356,7 +22462,7 @@ class Assign {
|
|
|
22356
22462
|
// o
|
|
22357
22463
|
const authorizationQueueStart = regs.get(8);
|
|
22358
22464
|
// a
|
|
22359
|
-
const
|
|
22465
|
+
const assigners = getServiceId(regs.get(9));
|
|
22360
22466
|
const res = safe_alloc_uint8array_safeAllocUint8Array(hash_HASH_SIZE * gp_constants_AUTHORIZATION_QUEUE_SIZE);
|
|
22361
22467
|
const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
|
|
22362
22468
|
// error while reading the memory.
|
|
@@ -22373,7 +22479,7 @@ class Assign {
|
|
|
22373
22479
|
const decoder = decoder_Decoder.fromBlob(res);
|
|
22374
22480
|
const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE), gp_constants_AUTHORIZATION_QUEUE_SIZE);
|
|
22375
22481
|
const fixedSizeAuthQueue = sized_array_FixedSizeArray.new(authQueue, gp_constants_AUTHORIZATION_QUEUE_SIZE);
|
|
22376
|
-
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue,
|
|
22482
|
+
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
|
|
22377
22483
|
if (result.isOk) {
|
|
22378
22484
|
regs.set(IN_OUT_REG, results_HostCallResult.OK);
|
|
22379
22485
|
logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
|
|
@@ -22422,7 +22528,9 @@ class Bless {
|
|
|
22422
22528
|
chainSpec;
|
|
22423
22529
|
index = host_call_handler_tryAsHostCallIndex(14);
|
|
22424
22530
|
basicGasCost = gas_tryAsSmallGas(10);
|
|
22425
|
-
tracedRegisters =
|
|
22531
|
+
tracedRegisters = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1)
|
|
22532
|
+
? host_call_handler_traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11, 12)
|
|
22533
|
+
: host_call_handler_traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11);
|
|
22426
22534
|
constructor(currentServiceId, partialState, chainSpec) {
|
|
22427
22535
|
this.currentServiceId = currentServiceId;
|
|
22428
22536
|
this.partialState = partialState;
|
|
@@ -22432,14 +22540,17 @@ class Bless {
|
|
|
22432
22540
|
// `m`: manager service (can change privileged services)
|
|
22433
22541
|
const manager = getServiceId(regs.get(bless_IN_OUT_REG));
|
|
22434
22542
|
// `a`: manages authorization queue
|
|
22435
|
-
// NOTE It can be either ServiceId (pre GP 067) or memory index (GP ^067)
|
|
22436
22543
|
const authorization = regs.get(8);
|
|
22437
22544
|
// `v`: manages validator keys
|
|
22438
|
-
const
|
|
22545
|
+
const delegator = getServiceId(regs.get(9));
|
|
22546
|
+
// `r`: manages creation of new services with id within protected range
|
|
22547
|
+
const registrar = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1)
|
|
22548
|
+
? getServiceId(regs.get(10))
|
|
22549
|
+
: common_tryAsServiceId(2 ** 32 - 1);
|
|
22439
22550
|
// `o`: memory offset
|
|
22440
|
-
const sourceStart = regs.get(10);
|
|
22551
|
+
const sourceStart = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1) ? regs.get(11) : regs.get(10);
|
|
22441
22552
|
// `n`: number of items in the auto-accumulate dictionary
|
|
22442
|
-
const numberOfItems = regs.get(11);
|
|
22553
|
+
const numberOfItems = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1) ? regs.get(12) : regs.get(11);
|
|
22443
22554
|
/*
|
|
22444
22555
|
* `z`: array of key-value pairs serviceId -> gas that auto-accumulate every block
|
|
22445
22556
|
* https://graypaper.fluffylabs.dev/#/7e6ff6a/368100368100?v=0.6.7
|
|
@@ -22453,7 +22564,7 @@ class Bless {
|
|
|
22453
22564
|
decoder.resetTo(0);
|
|
22454
22565
|
const memoryReadResult = memory.loadInto(result, memIndex);
|
|
22455
22566
|
if (memoryReadResult.isError) {
|
|
22456
|
-
logger_logger.trace `BLESS(${manager}, ${
|
|
22567
|
+
logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}) <- PANIC`;
|
|
22457
22568
|
return host_call_handler_PvmExecution.Panic;
|
|
22458
22569
|
}
|
|
22459
22570
|
const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
|
|
@@ -22466,24 +22577,25 @@ class Bless {
|
|
|
22466
22577
|
const authorizersDecoder = decoder_Decoder.fromBlob(res);
|
|
22467
22578
|
const memoryReadResult = memory.loadInto(res, authorization);
|
|
22468
22579
|
if (memoryReadResult.isError) {
|
|
22469
|
-
logger_logger.trace `BLESS(${manager}, ${
|
|
22580
|
+
logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- PANIC`;
|
|
22470
22581
|
return host_call_handler_PvmExecution.Panic;
|
|
22471
22582
|
}
|
|
22583
|
+
// `a`
|
|
22472
22584
|
const authorizers = common_tryAsPerCore(authorizersDecoder.sequenceFixLen(descriptors_codec.u32.asOpaque(), this.chainSpec.coresCount), this.chainSpec);
|
|
22473
|
-
const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers,
|
|
22585
|
+
const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulateEntries);
|
|
22474
22586
|
if (updateResult.isOk) {
|
|
22475
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
22587
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- OK`;
|
|
22476
22588
|
regs.set(bless_IN_OUT_REG, results_HostCallResult.OK);
|
|
22477
22589
|
return;
|
|
22478
22590
|
}
|
|
22479
22591
|
const e = updateResult.error;
|
|
22480
22592
|
if (e === partial_state_UpdatePrivilegesError.UnprivilegedService) {
|
|
22481
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
22593
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- HUH`;
|
|
22482
22594
|
regs.set(bless_IN_OUT_REG, results_HostCallResult.HUH);
|
|
22483
22595
|
return;
|
|
22484
22596
|
}
|
|
22485
22597
|
if (e === partial_state_UpdatePrivilegesError.InvalidServiceId) {
|
|
22486
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
22598
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- WHO`;
|
|
22487
22599
|
regs.set(bless_IN_OUT_REG, results_HostCallResult.WHO);
|
|
22488
22600
|
return;
|
|
22489
22601
|
}
|
|
@@ -22735,7 +22847,9 @@ class New {
|
|
|
22735
22847
|
partialState;
|
|
22736
22848
|
index = host_call_handler_tryAsHostCallIndex(18);
|
|
22737
22849
|
basicGasCost = gas_tryAsSmallGas(10);
|
|
22738
|
-
tracedRegisters =
|
|
22850
|
+
tracedRegisters = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1)
|
|
22851
|
+
? host_call_handler_traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11, 12)
|
|
22852
|
+
: host_call_handler_traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11);
|
|
22739
22853
|
constructor(currentServiceId, partialState) {
|
|
22740
22854
|
this.currentServiceId = currentServiceId;
|
|
22741
22855
|
this.partialState = partialState;
|
|
@@ -22751,16 +22865,18 @@ class New {
|
|
|
22751
22865
|
const allowance = common_tryAsServiceGas(regs.get(10));
|
|
22752
22866
|
// `f`
|
|
22753
22867
|
const gratisStorage = regs.get(11);
|
|
22868
|
+
// `i`: requested service id. Ignored if current service is not registrar or value is bigger than `S`.
|
|
22869
|
+
const requestedServiceId = regs.get(12);
|
|
22754
22870
|
// `c`
|
|
22755
22871
|
const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
22756
22872
|
const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
|
|
22757
22873
|
// error while reading the memory.
|
|
22758
22874
|
if (memoryReadResult.isError) {
|
|
22759
|
-
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- PANIC`;
|
|
22875
|
+
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
|
|
22760
22876
|
return host_call_handler_PvmExecution.Panic;
|
|
22761
22877
|
}
|
|
22762
|
-
const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage);
|
|
22763
|
-
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- ${result_resultToString(assignedId)}`;
|
|
22878
|
+
const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage, requestedServiceId);
|
|
22879
|
+
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${result_resultToString(assignedId)}`;
|
|
22764
22880
|
if (assignedId.isOk) {
|
|
22765
22881
|
regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
|
|
22766
22882
|
return;
|
|
@@ -22774,6 +22890,11 @@ class New {
|
|
|
22774
22890
|
regs.set(new_IN_OUT_REG, results_HostCallResult.HUH);
|
|
22775
22891
|
return;
|
|
22776
22892
|
}
|
|
22893
|
+
// Post 0.7.1
|
|
22894
|
+
if (e === partial_state_NewServiceError.RegistrarServiceIdAlreadyTaken) {
|
|
22895
|
+
regs.set(new_IN_OUT_REG, results_HostCallResult.FULL);
|
|
22896
|
+
return;
|
|
22897
|
+
}
|
|
22777
22898
|
debug_assertNever(e);
|
|
22778
22899
|
}
|
|
22779
22900
|
}
|
|
@@ -23897,7 +24018,7 @@ class accumulate_Accumulate {
|
|
|
23897
24018
|
}
|
|
23898
24019
|
const nextServiceId = generateNextServiceId({ serviceId, entropy, timeslot: slot }, this.chainSpec, this.blake2b);
|
|
23899
24020
|
const partialState = new AccumulateExternalities(this.chainSpec, this.blake2b, new PartiallyUpdatedState(this.state, inputStateUpdate), serviceId, nextServiceId, slot);
|
|
23900
|
-
const fetchExternalities = Compatibility.isGreaterOrEqual(GpVersion.
|
|
24021
|
+
const fetchExternalities = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
23901
24022
|
? FetchExternalities.createForAccumulate({ entropy, transfers, operands }, this.chainSpec)
|
|
23902
24023
|
: FetchExternalities.createForPre071Accumulate({ entropy, operands }, this.chainSpec);
|
|
23903
24024
|
const externalities = {
|
|
@@ -24048,17 +24169,17 @@ class accumulate_Accumulate {
|
|
|
24048
24169
|
statistics.set(serviceId, serviceStatistics);
|
|
24049
24170
|
currentState = stateUpdate === null ? checkpoint : stateUpdate;
|
|
24050
24171
|
if (Compatibility.is(GpVersion.V0_7_0) && serviceId === currentManager) {
|
|
24051
|
-
const newV = currentState.privilegedServices?.
|
|
24172
|
+
const newV = currentState.privilegedServices?.delegator;
|
|
24052
24173
|
if (currentState.privilegedServices !== null && newV !== undefined && serviceIds.includes(newV)) {
|
|
24053
|
-
accumulate_logger.info `Entering completely incorrect code that probably reverts
|
|
24174
|
+
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+`;
|
|
24054
24175
|
// Since serviceIds already contains newV, this service gets accumulated twice.
|
|
24055
24176
|
// To avoid double-counting, we skip stats and gas cost tracking here.
|
|
24056
|
-
// We need this accumulation to get the correct `
|
|
24177
|
+
// We need this accumulation to get the correct `delegator`
|
|
24057
24178
|
const { stateUpdate } = await this.accumulateSingleService(newV, [], accumulateData.getOperands(newV), accumulateData.getGasCost(newV), slot, entropy, checkpoint);
|
|
24058
|
-
const correctV = stateUpdate?.privilegedServices?.
|
|
24179
|
+
const correctV = stateUpdate?.privilegedServices?.delegator ?? this.state.privilegedServices.delegator;
|
|
24059
24180
|
currentState.privilegedServices = PrivilegedServices.create({
|
|
24060
24181
|
...currentState.privilegedServices,
|
|
24061
|
-
|
|
24182
|
+
delegator: correctV,
|
|
24062
24183
|
});
|
|
24063
24184
|
}
|
|
24064
24185
|
}
|
|
@@ -24122,6 +24243,20 @@ class accumulate_Accumulate {
|
|
|
24122
24243
|
const gasLimit = tryAsServiceGas(this.chainSpec.maxBlockGas > calculatedGasLimit ? this.chainSpec.maxBlockGas : calculatedGasLimit);
|
|
24123
24244
|
return tryAsServiceGas(gasLimit);
|
|
24124
24245
|
}
|
|
24246
|
+
hasDuplicatedServicesCreated(updateServices) {
|
|
24247
|
+
const createdServiceIds = new Set();
|
|
24248
|
+
for (const update of updateServices) {
|
|
24249
|
+
if (update.action.kind === UpdateServiceKind.Create) {
|
|
24250
|
+
const serviceId = update.serviceId;
|
|
24251
|
+
if (createdServiceIds.has(serviceId)) {
|
|
24252
|
+
accumulate_logger.log `Duplicated Service creation detected ${serviceId}. Block is invalid.`;
|
|
24253
|
+
return true;
|
|
24254
|
+
}
|
|
24255
|
+
createdServiceIds.add(serviceId);
|
|
24256
|
+
}
|
|
24257
|
+
}
|
|
24258
|
+
return false;
|
|
24259
|
+
}
|
|
24125
24260
|
async transition({ reports, slot, entropy }) {
|
|
24126
24261
|
const statistics = new Map();
|
|
24127
24262
|
const accumulateQueue = new AccumulateQueue(this.chainSpec, this.state);
|
|
@@ -24142,6 +24277,9 @@ class accumulate_Accumulate {
|
|
|
24142
24277
|
const accumulated = accumulatableReports.subview(0, accumulatedReports);
|
|
24143
24278
|
const { services, yieldedRoots, transfers, validatorsData, privilegedServices, authorizationQueues, ...stateUpdateRest } = state;
|
|
24144
24279
|
assertEmpty(stateUpdateRest);
|
|
24280
|
+
if (this.hasDuplicatedServicesCreated(services.servicesUpdates)) {
|
|
24281
|
+
return Result.error(ACCUMULATION_ERROR);
|
|
24282
|
+
}
|
|
24145
24283
|
const accStateUpdate = this.getAccumulationStateUpdate(accumulated.toArray(), toAccumulateLater, slot, Array.from(statistics.keys()), services);
|
|
24146
24284
|
const accumulationOutputUnsorted = Array.from(yieldedRoots.entries()).map(([serviceId, root]) => {
|
|
24147
24285
|
return { serviceId, output: root.asOpaque() };
|