@typeberry/jam 0.1.3-c2321fb → 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/bootstrap-generator.mjs +333 -236
- package/bootstrap-generator.mjs.map +1 -1
- package/bootstrap-importer.mjs +794 -474
- package/bootstrap-importer.mjs.map +1 -1
- package/bootstrap-network.mjs +335 -237
- package/bootstrap-network.mjs.map +1 -1
- package/index.js +793 -472
- package/index.js.map +1 -1
- package/package.json +1 -1
package/bootstrap-importer.mjs
CHANGED
|
@@ -2753,7 +2753,7 @@ module.exports = __nccwpck_require__.p + "e2fdc1b646378dd96eda.js?ed25519_wasm_b
|
|
|
2753
2753
|
|
|
2754
2754
|
/***/ }),
|
|
2755
2755
|
|
|
2756
|
-
/***/
|
|
2756
|
+
/***/ 185:
|
|
2757
2757
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
2758
2758
|
|
|
2759
2759
|
module.exports = __nccwpck_require__.p + "ccf8ada94096a8f232f5.js?reed_solomon_wasm_bg.wasm";
|
|
@@ -3452,7 +3452,7 @@ async function __wbg_init(module_or_path) {
|
|
|
3452
3452
|
if (wasm !== void 0) return wasm;
|
|
3453
3453
|
if (typeof module_or_path !== "undefined") if (Object.getPrototypeOf(module_or_path) === Object.prototype) ({module_or_path} = module_or_path);
|
|
3454
3454
|
else console.warn("using deprecated parameters for the initialization function; pass a single object instead");
|
|
3455
|
-
if (typeof module_or_path === "undefined") module_or_path = new URL(/* asset import */ __nccwpck_require__(
|
|
3455
|
+
if (typeof module_or_path === "undefined") module_or_path = new URL(/* asset import */ __nccwpck_require__(185), __nccwpck_require__.b);
|
|
3456
3456
|
const imports = __wbg_get_imports();
|
|
3457
3457
|
if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) module_or_path = fetch(module_or_path);
|
|
3458
3458
|
__wbg_init_memory(imports);
|
|
@@ -3569,8 +3569,9 @@ function parseCurrentVersion(env) {
|
|
|
3569
3569
|
}
|
|
3570
3570
|
}
|
|
3571
3571
|
function parseCurrentSuite(env) {
|
|
3572
|
-
if (env === undefined)
|
|
3572
|
+
if (env === undefined) {
|
|
3573
3573
|
return undefined;
|
|
3574
|
+
}
|
|
3574
3575
|
switch (env) {
|
|
3575
3576
|
case TestSuite.W3F_DAVXY:
|
|
3576
3577
|
case TestSuite.JAMDUNA:
|
|
@@ -4001,10 +4002,12 @@ function deepEqual(actual, expected, { context = [], errorsCollector, ignore = [
|
|
|
4001
4002
|
.sort((a, b) => {
|
|
4002
4003
|
const aKey = `${a.key}`;
|
|
4003
4004
|
const bKey = `${b.key}`;
|
|
4004
|
-
if (aKey < bKey)
|
|
4005
|
+
if (aKey < bKey) {
|
|
4005
4006
|
return -1;
|
|
4006
|
-
|
|
4007
|
+
}
|
|
4008
|
+
if (bKey < aKey) {
|
|
4007
4009
|
return 1;
|
|
4010
|
+
}
|
|
4008
4011
|
return 0;
|
|
4009
4012
|
});
|
|
4010
4013
|
};
|
|
@@ -5604,7 +5607,7 @@ class Skipper {
|
|
|
5604
5607
|
*
|
|
5605
5608
|
* Descriptors can be composed to form more complex typings.
|
|
5606
5609
|
*/
|
|
5607
|
-
class
|
|
5610
|
+
class Descriptor {
|
|
5608
5611
|
name;
|
|
5609
5612
|
sizeHint;
|
|
5610
5613
|
encode;
|
|
@@ -5614,11 +5617,11 @@ class descriptor_Descriptor {
|
|
|
5614
5617
|
View;
|
|
5615
5618
|
/** New descriptor with specialized `View`. */
|
|
5616
5619
|
static withView(name, sizeHint, encode, decode, skip, view) {
|
|
5617
|
-
return new
|
|
5620
|
+
return new Descriptor(name, sizeHint, encode, decode, skip, view);
|
|
5618
5621
|
}
|
|
5619
5622
|
/** Create a new descriptor without a specialized `View`. */
|
|
5620
5623
|
static new(name, sizeHint, encode, decode, skip) {
|
|
5621
|
-
return new
|
|
5624
|
+
return new Descriptor(name, sizeHint, encode, decode, skip, null);
|
|
5622
5625
|
}
|
|
5623
5626
|
constructor(
|
|
5624
5627
|
/** Descriptive name of the coded data. */
|
|
@@ -5655,7 +5658,7 @@ class descriptor_Descriptor {
|
|
|
5655
5658
|
}
|
|
5656
5659
|
/** Return a new descriptor that converts data into some other type. */
|
|
5657
5660
|
convert(input, output) {
|
|
5658
|
-
return new
|
|
5661
|
+
return new Descriptor(this.name, this.sizeHint, (e, elem) => this.encode(e, input(elem)), (d) => output(this.decode(d)), this.skip, this.View);
|
|
5659
5662
|
}
|
|
5660
5663
|
/** Safely cast the descriptor value to a opaque type. */
|
|
5661
5664
|
asOpaque() {
|
|
@@ -6353,51 +6356,51 @@ var descriptors_codec;
|
|
|
6353
6356
|
return (len) => {
|
|
6354
6357
|
let ret = cache.get(len);
|
|
6355
6358
|
if (ret === undefined) {
|
|
6356
|
-
ret =
|
|
6359
|
+
ret = Descriptor.new(`Bytes<${len}>`, exactHint(len), (e, v) => e.bytes(v), (d) => d.bytes(len), (s) => s.bytes(len));
|
|
6357
6360
|
cache.set(len, ret);
|
|
6358
6361
|
}
|
|
6359
6362
|
return ret;
|
|
6360
6363
|
};
|
|
6361
6364
|
})();
|
|
6362
6365
|
/** Variable-length U32. */
|
|
6363
|
-
codec.varU32 =
|
|
6366
|
+
codec.varU32 = Descriptor.new("var_u32", { bytes: 4, isExact: false }, (e, v) => e.varU32(v), (d) => d.varU32(), (d) => d.varU32());
|
|
6364
6367
|
/** Variable-length U64. */
|
|
6365
|
-
codec.varU64 =
|
|
6368
|
+
codec.varU64 = Descriptor.new("var_u64", { bytes: 8, isExact: false }, (e, v) => e.varU64(v), (d) => d.varU64(), (d) => d.varU64());
|
|
6366
6369
|
/** Unsigned 64-bit number. */
|
|
6367
|
-
codec.u64 =
|
|
6370
|
+
codec.u64 = Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.u64(), (d) => d.u64(), codec.bytes(8));
|
|
6368
6371
|
/** Unsigned 32-bit number. */
|
|
6369
|
-
codec.u32 =
|
|
6372
|
+
codec.u32 = Descriptor.withView("u32", exactHint(4), (e, v) => e.i32(v), (d) => d.u32(), (d) => d.u32(), codec.bytes(4));
|
|
6370
6373
|
/** Unsigned 24-bit number. */
|
|
6371
|
-
codec.u24 =
|
|
6374
|
+
codec.u24 = Descriptor.withView("u24", exactHint(3), (e, v) => e.i24(v), (d) => d.u24(), (d) => d.u24(), codec.bytes(3));
|
|
6372
6375
|
/** Unsigned 16-bit number. */
|
|
6373
|
-
codec.u16 =
|
|
6376
|
+
codec.u16 = Descriptor.withView("u16", exactHint(2), (e, v) => e.i16(v), (d) => d.u16(), (d) => d.u16(), codec.bytes(2));
|
|
6374
6377
|
/** Unsigned 8-bit number. */
|
|
6375
|
-
codec.u8 =
|
|
6378
|
+
codec.u8 = Descriptor.new("u8", exactHint(1), (e, v) => e.i8(v), (d) => d.u8(), (d) => d.u8());
|
|
6376
6379
|
/** Signed 64-bit number. */
|
|
6377
|
-
codec.i64 =
|
|
6380
|
+
codec.i64 = Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.i64(), (s) => s.u64(), codec.bytes(8));
|
|
6378
6381
|
/** Signed 32-bit number. */
|
|
6379
|
-
codec.i32 =
|
|
6382
|
+
codec.i32 = Descriptor.withView("i32", exactHint(4), (e, v) => e.i32(v), (d) => d.i32(), (s) => s.u32(), codec.bytes(4));
|
|
6380
6383
|
/** Signed 24-bit number. */
|
|
6381
|
-
codec.i24 =
|
|
6384
|
+
codec.i24 = Descriptor.withView("i24", exactHint(3), (e, v) => e.i24(v), (d) => d.i24(), (s) => s.u24(), codec.bytes(3));
|
|
6382
6385
|
/** Signed 16-bit number. */
|
|
6383
|
-
codec.i16 =
|
|
6386
|
+
codec.i16 = Descriptor.withView("i16", exactHint(2), (e, v) => e.i16(v), (d) => d.i16(), (s) => s.u16(), codec.bytes(2));
|
|
6384
6387
|
/** Signed 8-bit number. */
|
|
6385
|
-
codec.i8 =
|
|
6388
|
+
codec.i8 = Descriptor.new("i8", exactHint(1), (e, v) => e.i8(v), (d) => d.i8(), (s) => s.u8());
|
|
6386
6389
|
/** 1-byte boolean value. */
|
|
6387
|
-
codec.bool =
|
|
6390
|
+
codec.bool = Descriptor.new("bool", exactHint(1), (e, v) => e.bool(v), (d) => d.bool(), (s) => s.bool());
|
|
6388
6391
|
/** Variable-length bytes blob. */
|
|
6389
|
-
codec.blob =
|
|
6392
|
+
codec.blob = Descriptor.new("BytesBlob", { bytes: TYPICAL_SEQUENCE_LENGTH, isExact: false }, (e, v) => e.bytesBlob(v), (d) => d.bytesBlob(), (s) => s.bytesBlob());
|
|
6390
6393
|
/** String encoded as variable-length bytes blob. */
|
|
6391
|
-
codec.string =
|
|
6394
|
+
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);
|
|
6392
6395
|
/** Variable-length bit vector. */
|
|
6393
|
-
codec.bitVecVarLen =
|
|
6396
|
+
codec.bitVecVarLen = Descriptor.new("BitVec[?]", { bytes: TYPICAL_SEQUENCE_LENGTH >>> 3, isExact: false }, (e, v) => e.bitVecVarLen(v), (d) => d.bitVecVarLen(), (s) => s.bitVecVarLen());
|
|
6394
6397
|
/** Fixed-length bit vector. */
|
|
6395
|
-
codec.bitVecFixLen = (bitLen) =>
|
|
6398
|
+
codec.bitVecFixLen = (bitLen) => Descriptor.new(`BitVec[${bitLen}]`, exactHint(bitLen >>> 3), (e, v) => e.bitVecFixLen(v), (d) => d.bitVecFixLen(bitLen), (s) => s.bitVecFixLen(bitLen));
|
|
6396
6399
|
/** Optionality wrapper for given type. */
|
|
6397
6400
|
codec.optional = (type) => {
|
|
6398
|
-
const self =
|
|
6401
|
+
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));
|
|
6399
6402
|
if (hasUniqueView(type)) {
|
|
6400
|
-
return
|
|
6403
|
+
return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.optional(type.View));
|
|
6401
6404
|
}
|
|
6402
6405
|
return self;
|
|
6403
6406
|
};
|
|
@@ -6408,7 +6411,7 @@ var descriptors_codec;
|
|
|
6408
6411
|
}) => {
|
|
6409
6412
|
const name = `Sequence<${type.name}>[?]`;
|
|
6410
6413
|
const typicalLength = options.typicalLength ?? TYPICAL_SEQUENCE_LENGTH;
|
|
6411
|
-
return
|
|
6414
|
+
return Descriptor.withView(name, { bytes: typicalLength * type.sizeHint.bytes, isExact: false }, (e, v) => {
|
|
6412
6415
|
validateLength(options, v.length, name);
|
|
6413
6416
|
e.sequenceVarLen(type, v);
|
|
6414
6417
|
}, (d) => {
|
|
@@ -6422,10 +6425,10 @@ var descriptors_codec;
|
|
|
6422
6425
|
}, sequenceViewVarLen(type, options));
|
|
6423
6426
|
};
|
|
6424
6427
|
/** Fixed-length sequence of given type. */
|
|
6425
|
-
codec.sequenceFixLen = (type, len) =>
|
|
6428
|
+
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 }));
|
|
6426
6429
|
/** Small dictionary codec. */
|
|
6427
6430
|
codec.dictionary = (key, value, { sortKeys, fixedLength, }) => {
|
|
6428
|
-
const self =
|
|
6431
|
+
const self = Descriptor.new(`Dictionary<${key.name}, ${value.name}>[${fixedLength ?? "?"}]`, {
|
|
6429
6432
|
bytes: fixedLength !== undefined
|
|
6430
6433
|
? fixedLength * addSizeHints(key.sizeHint, value.sizeHint).bytes
|
|
6431
6434
|
: TYPICAL_DICTIONARY_LENGTH * (addSizeHints(key.sizeHint, value.sizeHint).bytes ?? 0),
|
|
@@ -6464,13 +6467,13 @@ var descriptors_codec;
|
|
|
6464
6467
|
s.sequenceFixLen(value, len);
|
|
6465
6468
|
});
|
|
6466
6469
|
if (hasUniqueView(value)) {
|
|
6467
|
-
return
|
|
6470
|
+
return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.dictionary(key, value.View, { sortKeys, fixedLength }));
|
|
6468
6471
|
}
|
|
6469
6472
|
return self;
|
|
6470
6473
|
};
|
|
6471
6474
|
/** Encoding of pair of two values. */
|
|
6472
6475
|
codec.pair = (a, b) => {
|
|
6473
|
-
const self =
|
|
6476
|
+
const self = Descriptor.new(`Pair<${a.name}, ${b.name}>`, addSizeHints(a.sizeHint, b.sizeHint), (e, elem) => {
|
|
6474
6477
|
a.encode(e, elem[0]);
|
|
6475
6478
|
b.encode(e, elem[1]);
|
|
6476
6479
|
}, (d) => {
|
|
@@ -6482,14 +6485,14 @@ var descriptors_codec;
|
|
|
6482
6485
|
b.skip(s);
|
|
6483
6486
|
});
|
|
6484
6487
|
if (hasUniqueView(a) && hasUniqueView(b)) {
|
|
6485
|
-
return
|
|
6488
|
+
return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.pair(a.View, b.View));
|
|
6486
6489
|
}
|
|
6487
6490
|
return self;
|
|
6488
6491
|
};
|
|
6489
6492
|
/** Custom encoding / decoding logic. */
|
|
6490
|
-
codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) =>
|
|
6493
|
+
codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
|
|
6491
6494
|
/** Choose a descriptor depending on the encoding/decoding context. */
|
|
6492
|
-
codec.select = ({ name, sizeHint, }, chooser) =>
|
|
6495
|
+
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);
|
|
6493
6496
|
/**
|
|
6494
6497
|
* A descriptor for a more complex POJO.
|
|
6495
6498
|
*
|
|
@@ -6526,7 +6529,7 @@ var descriptors_codec;
|
|
|
6526
6529
|
};
|
|
6527
6530
|
const view = objectView(Class, descriptors, sizeHint, skipper);
|
|
6528
6531
|
// and create the descriptor for the entire class.
|
|
6529
|
-
return
|
|
6532
|
+
return Descriptor.withView(Class.name, sizeHint, (e, t) => {
|
|
6530
6533
|
forEachDescriptor(descriptors, (key, descriptor) => {
|
|
6531
6534
|
const value = t[key];
|
|
6532
6535
|
descriptor.encode(e, value);
|
|
@@ -6577,7 +6580,7 @@ function objectView(Class, descriptors, sizeHint, skipper) {
|
|
|
6577
6580
|
});
|
|
6578
6581
|
}
|
|
6579
6582
|
});
|
|
6580
|
-
return
|
|
6583
|
+
return Descriptor.new(`View<${Class.name}>`, sizeHint, (e, t) => {
|
|
6581
6584
|
const encoded = t.encoded();
|
|
6582
6585
|
e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
|
|
6583
6586
|
}, (d) => {
|
|
@@ -6596,7 +6599,7 @@ function sequenceViewVarLen(type, options) {
|
|
|
6596
6599
|
validateLength(options, length, name);
|
|
6597
6600
|
return s.sequenceFixLen(type, length);
|
|
6598
6601
|
};
|
|
6599
|
-
return
|
|
6602
|
+
return Descriptor.new(name, sizeHint, (e, t) => {
|
|
6600
6603
|
validateLength(options, t.length, name);
|
|
6601
6604
|
const encoded = t.encoded();
|
|
6602
6605
|
e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
|
|
@@ -6612,7 +6615,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
|
|
|
6612
6615
|
const skipper = (s) => s.sequenceFixLen(type, fixedLength);
|
|
6613
6616
|
const view = type.name !== type.View.name ? `, ${type.View.name}` : "";
|
|
6614
6617
|
const name = `SeqView<${type.name}${view}>[${fixedLength}]`;
|
|
6615
|
-
return
|
|
6618
|
+
return Descriptor.new(name, sizeHint, (e, t) => {
|
|
6616
6619
|
const encoded = t.encoded();
|
|
6617
6620
|
e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
|
|
6618
6621
|
}, (d) => {
|
|
@@ -6741,6 +6744,49 @@ function hashBlobs(hasher, blobs) {
|
|
|
6741
6744
|
|
|
6742
6745
|
|
|
6743
6746
|
|
|
6747
|
+
;// CONCATENATED MODULE: ./packages/core/collections/array-view.ts
|
|
6748
|
+
|
|
6749
|
+
/**
|
|
6750
|
+
* A utility class providing a readonly view over a portion of an array without copying it.
|
|
6751
|
+
*/
|
|
6752
|
+
class ArrayView {
|
|
6753
|
+
start;
|
|
6754
|
+
end;
|
|
6755
|
+
source;
|
|
6756
|
+
length;
|
|
6757
|
+
constructor(source, start, end) {
|
|
6758
|
+
this.start = start;
|
|
6759
|
+
this.end = end;
|
|
6760
|
+
this.source = source;
|
|
6761
|
+
this.length = end - start;
|
|
6762
|
+
}
|
|
6763
|
+
static from(source, start = 0, end = source.length) {
|
|
6764
|
+
debug_check `
|
|
6765
|
+
${start >= 0 && end <= source.length && start <= end}
|
|
6766
|
+
Invalid start (${start})/end (${end}) for ArrayView
|
|
6767
|
+
`;
|
|
6768
|
+
return new ArrayView(source, start, end);
|
|
6769
|
+
}
|
|
6770
|
+
get(i) {
|
|
6771
|
+
debug_check `
|
|
6772
|
+
${i >= 0 && i < this.length}
|
|
6773
|
+
Index out of bounds: ${i} < ${this.length}
|
|
6774
|
+
`;
|
|
6775
|
+
return this.source[this.start + i];
|
|
6776
|
+
}
|
|
6777
|
+
subview(from, to = this.length) {
|
|
6778
|
+
return ArrayView.from(this.source, this.start + from, this.start + to);
|
|
6779
|
+
}
|
|
6780
|
+
toArray() {
|
|
6781
|
+
return this.source.slice(this.start, this.end);
|
|
6782
|
+
}
|
|
6783
|
+
*[Symbol.iterator]() {
|
|
6784
|
+
for (let i = this.start; i < this.end; i++) {
|
|
6785
|
+
yield this.source[i];
|
|
6786
|
+
}
|
|
6787
|
+
}
|
|
6788
|
+
}
|
|
6789
|
+
|
|
6744
6790
|
;// CONCATENATED MODULE: ./packages/core/collections/hash-dictionary.ts
|
|
6745
6791
|
/** A map which uses hashes as keys. */
|
|
6746
6792
|
class hash_dictionary_HashDictionary {
|
|
@@ -7352,6 +7398,7 @@ class TruncatedHashDictionary {
|
|
|
7352
7398
|
|
|
7353
7399
|
|
|
7354
7400
|
|
|
7401
|
+
|
|
7355
7402
|
;// CONCATENATED MODULE: ./packages/jam/config/chain-spec.ts
|
|
7356
7403
|
|
|
7357
7404
|
|
|
@@ -7584,7 +7631,7 @@ const codecFixedSizeArray = (val, len) => {
|
|
|
7584
7631
|
};
|
|
7585
7632
|
/** Codec for a hash-dictionary. */
|
|
7586
7633
|
const codecHashDictionary = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH, compare = (a, b) => extractKey(a).compare(extractKey(b)), } = {}) => {
|
|
7587
|
-
return
|
|
7634
|
+
return Descriptor.new(`HashDictionary<${value.name}>[?]`, {
|
|
7588
7635
|
bytes: typicalLength * value.sizeHint.bytes,
|
|
7589
7636
|
isExact: false,
|
|
7590
7637
|
}, (e, v) => {
|
|
@@ -9551,6 +9598,13 @@ const W_T = 128;
|
|
|
9551
9598
|
/** `W_M`: The maximum number of exports in a work-package. */
|
|
9552
9599
|
const W_X = 3_072;
|
|
9553
9600
|
// TODO [ToDr] Not sure where these should live yet :(
|
|
9601
|
+
/**
|
|
9602
|
+
* `S`: The minimum public service index.
|
|
9603
|
+
* Services of indices below these may only be created by the Registrar.
|
|
9604
|
+
*
|
|
9605
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
|
|
9606
|
+
*/
|
|
9607
|
+
const MIN_PUBLIC_SERVICE_INDEX = 2 ** 16;
|
|
9554
9608
|
/**
|
|
9555
9609
|
* `J`: The maximum sum of dependency items in a work-report.
|
|
9556
9610
|
*
|
|
@@ -9562,9 +9616,209 @@ const AUTHORIZATION_QUEUE_SIZE = Q;
|
|
|
9562
9616
|
/** `O`: Maximal authorization pool size. */
|
|
9563
9617
|
const MAX_AUTH_POOL_SIZE = O;
|
|
9564
9618
|
|
|
9619
|
+
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
|
|
9620
|
+
const MAX_VALUE = 4294967295;
|
|
9621
|
+
const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
|
|
9622
|
+
const MIN_VALUE = -(2 ** 31);
|
|
9623
|
+
const MAX_SHIFT_U32 = 32;
|
|
9624
|
+
const MAX_SHIFT_U64 = 64n;
|
|
9625
|
+
|
|
9626
|
+
;// CONCATENATED MODULE: ./packages/jam/state/service.ts
|
|
9627
|
+
|
|
9628
|
+
|
|
9629
|
+
|
|
9630
|
+
|
|
9631
|
+
|
|
9632
|
+
|
|
9633
|
+
/**
|
|
9634
|
+
* `B_S`: The basic minimum balance which all services require.
|
|
9635
|
+
*
|
|
9636
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
9637
|
+
*/
|
|
9638
|
+
const BASE_SERVICE_BALANCE = 100n;
|
|
9639
|
+
/**
|
|
9640
|
+
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
9641
|
+
*
|
|
9642
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
9643
|
+
*/
|
|
9644
|
+
const ELECTIVE_ITEM_BALANCE = 10n;
|
|
9645
|
+
/**
|
|
9646
|
+
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
9647
|
+
*
|
|
9648
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
9649
|
+
*/
|
|
9650
|
+
const ELECTIVE_BYTE_BALANCE = 1n;
|
|
9651
|
+
const zeroSizeHint = {
|
|
9652
|
+
bytes: 0,
|
|
9653
|
+
isExact: true,
|
|
9654
|
+
};
|
|
9655
|
+
/** 0-byte read, return given default value */
|
|
9656
|
+
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
9657
|
+
/** Encode and decode object with leading version number. */
|
|
9658
|
+
const codecWithVersion = (val) => Descriptor.new("withVersion", {
|
|
9659
|
+
bytes: val.sizeHint.bytes + 8,
|
|
9660
|
+
isExact: false,
|
|
9661
|
+
}, (e, v) => {
|
|
9662
|
+
e.varU64(0n);
|
|
9663
|
+
val.encode(e, v);
|
|
9664
|
+
}, (d) => {
|
|
9665
|
+
const version = d.varU64();
|
|
9666
|
+
if (version !== 0n) {
|
|
9667
|
+
throw new Error("Non-zero version is not supported!");
|
|
9668
|
+
}
|
|
9669
|
+
return val.decode(d);
|
|
9670
|
+
}, (s) => {
|
|
9671
|
+
s.varU64();
|
|
9672
|
+
val.skip(s);
|
|
9673
|
+
});
|
|
9674
|
+
/**
|
|
9675
|
+
* Service account details.
|
|
9676
|
+
*
|
|
9677
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
|
|
9678
|
+
*/
|
|
9679
|
+
class ServiceAccountInfo extends WithDebug {
|
|
9680
|
+
codeHash;
|
|
9681
|
+
balance;
|
|
9682
|
+
accumulateMinGas;
|
|
9683
|
+
onTransferMinGas;
|
|
9684
|
+
storageUtilisationBytes;
|
|
9685
|
+
gratisStorage;
|
|
9686
|
+
storageUtilisationCount;
|
|
9687
|
+
created;
|
|
9688
|
+
lastAccumulation;
|
|
9689
|
+
parentService;
|
|
9690
|
+
static Codec = descriptors_codec.Class(ServiceAccountInfo, {
|
|
9691
|
+
codeHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
9692
|
+
balance: descriptors_codec.u64,
|
|
9693
|
+
accumulateMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
|
|
9694
|
+
onTransferMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
|
|
9695
|
+
storageUtilisationBytes: descriptors_codec.u64,
|
|
9696
|
+
gratisStorage: descriptors_codec.u64,
|
|
9697
|
+
storageUtilisationCount: descriptors_codec.u32,
|
|
9698
|
+
created: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
|
|
9699
|
+
lastAccumulation: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
|
|
9700
|
+
parentService: descriptors_codec.u32.convert((x) => x, tryAsServiceId),
|
|
9701
|
+
});
|
|
9702
|
+
static create(a) {
|
|
9703
|
+
return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
|
|
9704
|
+
}
|
|
9705
|
+
/**
|
|
9706
|
+
* `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
|
|
9707
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
|
|
9708
|
+
*/
|
|
9709
|
+
static calculateThresholdBalance(items, bytes, gratisStorage) {
|
|
9710
|
+
const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
|
|
9711
|
+
if (storageCost < 0n) {
|
|
9712
|
+
return numbers_tryAsU64(0);
|
|
9713
|
+
}
|
|
9714
|
+
if (storageCost >= 2n ** 64n) {
|
|
9715
|
+
return numbers_tryAsU64(2n ** 64n - 1n);
|
|
9716
|
+
}
|
|
9717
|
+
return numbers_tryAsU64(storageCost);
|
|
9718
|
+
}
|
|
9719
|
+
constructor(
|
|
9720
|
+
/** `a_c`: Hash of the service code. */
|
|
9721
|
+
codeHash,
|
|
9722
|
+
/** `a_b`: Current account balance. */
|
|
9723
|
+
balance,
|
|
9724
|
+
/** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
|
|
9725
|
+
accumulateMinGas,
|
|
9726
|
+
/** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
|
|
9727
|
+
onTransferMinGas,
|
|
9728
|
+
/** `a_o`: Total number of octets in storage. */
|
|
9729
|
+
storageUtilisationBytes,
|
|
9730
|
+
/** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
|
|
9731
|
+
gratisStorage,
|
|
9732
|
+
/** `a_i`: Number of items in storage. */
|
|
9733
|
+
storageUtilisationCount,
|
|
9734
|
+
/** `a_r`: Creation account time slot. */
|
|
9735
|
+
created,
|
|
9736
|
+
/** `a_a`: Most recent accumulation time slot. */
|
|
9737
|
+
lastAccumulation,
|
|
9738
|
+
/** `a_p`: Parent service ID. */
|
|
9739
|
+
parentService) {
|
|
9740
|
+
super();
|
|
9741
|
+
this.codeHash = codeHash;
|
|
9742
|
+
this.balance = balance;
|
|
9743
|
+
this.accumulateMinGas = accumulateMinGas;
|
|
9744
|
+
this.onTransferMinGas = onTransferMinGas;
|
|
9745
|
+
this.storageUtilisationBytes = storageUtilisationBytes;
|
|
9746
|
+
this.gratisStorage = gratisStorage;
|
|
9747
|
+
this.storageUtilisationCount = storageUtilisationCount;
|
|
9748
|
+
this.created = created;
|
|
9749
|
+
this.lastAccumulation = lastAccumulation;
|
|
9750
|
+
this.parentService = parentService;
|
|
9751
|
+
}
|
|
9752
|
+
}
|
|
9753
|
+
class PreimageItem extends WithDebug {
|
|
9754
|
+
hash;
|
|
9755
|
+
blob;
|
|
9756
|
+
static Codec = descriptors_codec.Class(PreimageItem, {
|
|
9757
|
+
hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
9758
|
+
blob: descriptors_codec.blob,
|
|
9759
|
+
});
|
|
9760
|
+
static create({ hash, blob }) {
|
|
9761
|
+
return new PreimageItem(hash, blob);
|
|
9762
|
+
}
|
|
9763
|
+
constructor(hash, blob) {
|
|
9764
|
+
super();
|
|
9765
|
+
this.hash = hash;
|
|
9766
|
+
this.blob = blob;
|
|
9767
|
+
}
|
|
9768
|
+
}
|
|
9769
|
+
class StorageItem extends WithDebug {
|
|
9770
|
+
key;
|
|
9771
|
+
value;
|
|
9772
|
+
static Codec = descriptors_codec.Class(StorageItem, {
|
|
9773
|
+
key: descriptors_codec.blob.convert((i) => i, (o) => opaque_asOpaqueType(o)),
|
|
9774
|
+
value: descriptors_codec.blob,
|
|
9775
|
+
});
|
|
9776
|
+
static create({ key, value }) {
|
|
9777
|
+
return new StorageItem(key, value);
|
|
9778
|
+
}
|
|
9779
|
+
constructor(key, value) {
|
|
9780
|
+
super();
|
|
9781
|
+
this.key = key;
|
|
9782
|
+
this.value = value;
|
|
9783
|
+
}
|
|
9784
|
+
}
|
|
9785
|
+
const MAX_LOOKUP_HISTORY_SLOTS = 3;
|
|
9786
|
+
function tryAsLookupHistorySlots(items) {
|
|
9787
|
+
const knownSize = sized_array_asKnownSize(items);
|
|
9788
|
+
if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
|
|
9789
|
+
throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
|
|
9790
|
+
}
|
|
9791
|
+
return knownSize;
|
|
9792
|
+
}
|
|
9793
|
+
/** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
|
|
9794
|
+
class LookupHistoryItem {
|
|
9795
|
+
hash;
|
|
9796
|
+
length;
|
|
9797
|
+
slots;
|
|
9798
|
+
constructor(hash, length,
|
|
9799
|
+
/**
|
|
9800
|
+
* Preimage availability history as a sequence of time slots.
|
|
9801
|
+
* See PreimageStatus and the following GP fragment for more details.
|
|
9802
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
|
|
9803
|
+
slots) {
|
|
9804
|
+
this.hash = hash;
|
|
9805
|
+
this.length = length;
|
|
9806
|
+
this.slots = slots;
|
|
9807
|
+
}
|
|
9808
|
+
static isRequested(item) {
|
|
9809
|
+
if ("slots" in item) {
|
|
9810
|
+
return item.slots.length === 0;
|
|
9811
|
+
}
|
|
9812
|
+
return item.length === 0;
|
|
9813
|
+
}
|
|
9814
|
+
}
|
|
9815
|
+
|
|
9565
9816
|
;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
|
|
9566
9817
|
|
|
9567
9818
|
|
|
9819
|
+
|
|
9820
|
+
|
|
9821
|
+
|
|
9568
9822
|
/** Dictionary entry of services that auto-accumulate every block. */
|
|
9569
9823
|
class AutoAccumulate {
|
|
9570
9824
|
service;
|
|
@@ -9586,39 +9840,50 @@ class AutoAccumulate {
|
|
|
9586
9840
|
}
|
|
9587
9841
|
}
|
|
9588
9842
|
/**
|
|
9589
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
9843
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
|
|
9590
9844
|
*/
|
|
9591
9845
|
class PrivilegedServices {
|
|
9592
9846
|
manager;
|
|
9593
|
-
|
|
9594
|
-
|
|
9847
|
+
delegator;
|
|
9848
|
+
registrar;
|
|
9849
|
+
assigners;
|
|
9595
9850
|
autoAccumulateServices;
|
|
9851
|
+
/** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
|
|
9596
9852
|
static Codec = descriptors_codec.Class(PrivilegedServices, {
|
|
9597
9853
|
manager: descriptors_codec.u32.asOpaque(),
|
|
9598
|
-
|
|
9599
|
-
|
|
9854
|
+
assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
|
|
9855
|
+
delegator: descriptors_codec.u32.asOpaque(),
|
|
9856
|
+
registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
9857
|
+
? descriptors_codec.u32.asOpaque()
|
|
9858
|
+
: ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
|
|
9600
9859
|
autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
|
|
9601
9860
|
});
|
|
9602
|
-
static create(
|
|
9603
|
-
return new PrivilegedServices(manager,
|
|
9861
|
+
static create(a) {
|
|
9862
|
+
return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
9604
9863
|
}
|
|
9605
9864
|
constructor(
|
|
9606
9865
|
/**
|
|
9607
|
-
*
|
|
9608
|
-
* the service able to effect an alteration of χ from block to block,
|
|
9866
|
+
* `χ_M`: Manages alteration of χ from block to block,
|
|
9609
9867
|
* as well as bestow services with storage deposit credits.
|
|
9610
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
9868
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
9611
9869
|
*/
|
|
9612
9870
|
manager,
|
|
9613
|
-
/**
|
|
9614
|
-
|
|
9615
|
-
/**
|
|
9616
|
-
|
|
9617
|
-
|
|
9871
|
+
/** `χ_V`: Managers validator keys. */
|
|
9872
|
+
delegator,
|
|
9873
|
+
/**
|
|
9874
|
+
* `χ_R`: Manages the creation of services in protected range.
|
|
9875
|
+
*
|
|
9876
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
|
|
9877
|
+
*/
|
|
9878
|
+
registrar,
|
|
9879
|
+
/** `χ_A`: Manages authorization queue one for each core. */
|
|
9880
|
+
assigners,
|
|
9881
|
+
/** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
|
|
9618
9882
|
autoAccumulateServices) {
|
|
9619
9883
|
this.manager = manager;
|
|
9620
|
-
this.
|
|
9621
|
-
this.
|
|
9884
|
+
this.delegator = delegator;
|
|
9885
|
+
this.registrar = registrar;
|
|
9886
|
+
this.assigners = assigners;
|
|
9622
9887
|
this.autoAccumulateServices = autoAccumulateServices;
|
|
9623
9888
|
}
|
|
9624
9889
|
}
|
|
@@ -9706,7 +9971,7 @@ class RecentBlocks extends WithDebug {
|
|
|
9706
9971
|
*/
|
|
9707
9972
|
class RecentBlocksHistory extends WithDebug {
|
|
9708
9973
|
current;
|
|
9709
|
-
static Codec =
|
|
9974
|
+
static Codec = Descriptor.new("RecentBlocksHistory", RecentBlocks.Codec.sizeHint, (encoder, value) => RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
|
|
9710
9975
|
const recentBlocks = RecentBlocks.Codec.decode(decoder);
|
|
9711
9976
|
return RecentBlocksHistory.create(recentBlocks);
|
|
9712
9977
|
}, (skip) => {
|
|
@@ -9821,258 +10086,85 @@ var SafroleSealingKeysKind;
|
|
|
9821
10086
|
const codecBandersnatchKey = descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque();
|
|
9822
10087
|
class SafroleSealingKeysData extends WithDebug {
|
|
9823
10088
|
kind;
|
|
9824
|
-
keys;
|
|
9825
|
-
tickets;
|
|
9826
|
-
static Codec = codecWithContext((context) => {
|
|
9827
|
-
return descriptors_codec.custom({
|
|
9828
|
-
name: "SafroleSealingKeys",
|
|
9829
|
-
sizeHint: { bytes: 1 + hash_HASH_SIZE * context.epochLength, isExact: false },
|
|
9830
|
-
}, (e, x) => {
|
|
9831
|
-
e.varU32(numbers_tryAsU32(x.kind));
|
|
9832
|
-
if (x.kind === SafroleSealingKeysKind.Keys) {
|
|
9833
|
-
e.sequenceFixLen(codecBandersnatchKey, x.keys);
|
|
9834
|
-
}
|
|
9835
|
-
else {
|
|
9836
|
-
e.sequenceFixLen(Ticket.Codec, x.tickets);
|
|
9837
|
-
}
|
|
9838
|
-
}, (d) => {
|
|
9839
|
-
const epochLength = context.epochLength;
|
|
9840
|
-
const kind = d.varU32();
|
|
9841
|
-
if (kind === SafroleSealingKeysKind.Keys) {
|
|
9842
|
-
const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
|
|
9843
|
-
return SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
|
|
9844
|
-
}
|
|
9845
|
-
if (kind === SafroleSealingKeysKind.Tickets) {
|
|
9846
|
-
const tickets = d.sequenceFixLen(Ticket.Codec, epochLength);
|
|
9847
|
-
return SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
|
|
9848
|
-
}
|
|
9849
|
-
throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
|
|
9850
|
-
}, (s) => {
|
|
9851
|
-
const kind = s.decoder.varU32();
|
|
9852
|
-
if (kind === SafroleSealingKeysKind.Keys) {
|
|
9853
|
-
s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
|
|
9854
|
-
return;
|
|
9855
|
-
}
|
|
9856
|
-
if (kind === SafroleSealingKeysKind.Tickets) {
|
|
9857
|
-
s.sequenceFixLen(Ticket.Codec, context.epochLength);
|
|
9858
|
-
return;
|
|
9859
|
-
}
|
|
9860
|
-
throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
|
|
9861
|
-
});
|
|
9862
|
-
});
|
|
9863
|
-
static keys(keys) {
|
|
9864
|
-
return new SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
|
|
9865
|
-
}
|
|
9866
|
-
static tickets(tickets) {
|
|
9867
|
-
return new SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
|
|
9868
|
-
}
|
|
9869
|
-
constructor(kind, keys, tickets) {
|
|
9870
|
-
super();
|
|
9871
|
-
this.kind = kind;
|
|
9872
|
-
this.keys = keys;
|
|
9873
|
-
this.tickets = tickets;
|
|
9874
|
-
}
|
|
9875
|
-
}
|
|
9876
|
-
class SafroleData {
|
|
9877
|
-
nextValidatorData;
|
|
9878
|
-
epochRoot;
|
|
9879
|
-
sealingKeySeries;
|
|
9880
|
-
ticketsAccumulator;
|
|
9881
|
-
static Codec = descriptors_codec.Class(SafroleData, {
|
|
9882
|
-
nextValidatorData: codecPerValidator(ValidatorData.Codec),
|
|
9883
|
-
epochRoot: descriptors_codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
9884
|
-
sealingKeySeries: SafroleSealingKeysData.Codec,
|
|
9885
|
-
ticketsAccumulator: readonlyArray(descriptors_codec.sequenceVarLen(Ticket.Codec)).convert(seeThrough, sized_array_asKnownSize),
|
|
9886
|
-
});
|
|
9887
|
-
static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
|
|
9888
|
-
return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
|
|
9889
|
-
}
|
|
9890
|
-
constructor(
|
|
9891
|
-
/** gamma_k */
|
|
9892
|
-
nextValidatorData,
|
|
9893
|
-
/** gamma_z */
|
|
9894
|
-
epochRoot,
|
|
9895
|
-
/** gamma_s */
|
|
9896
|
-
sealingKeySeries,
|
|
9897
|
-
/** gamma_a */
|
|
9898
|
-
ticketsAccumulator) {
|
|
9899
|
-
this.nextValidatorData = nextValidatorData;
|
|
9900
|
-
this.epochRoot = epochRoot;
|
|
9901
|
-
this.sealingKeySeries = sealingKeySeries;
|
|
9902
|
-
this.ticketsAccumulator = ticketsAccumulator;
|
|
9903
|
-
}
|
|
9904
|
-
}
|
|
9905
|
-
|
|
9906
|
-
;// CONCATENATED MODULE: ./packages/jam/state/service.ts
|
|
9907
|
-
|
|
9908
|
-
|
|
9909
|
-
|
|
9910
|
-
|
|
9911
|
-
|
|
9912
|
-
|
|
9913
|
-
/**
|
|
9914
|
-
* `B_S`: The basic minimum balance which all services require.
|
|
9915
|
-
*
|
|
9916
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
9917
|
-
*/
|
|
9918
|
-
const BASE_SERVICE_BALANCE = 100n;
|
|
9919
|
-
/**
|
|
9920
|
-
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
9921
|
-
*
|
|
9922
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
9923
|
-
*/
|
|
9924
|
-
const ELECTIVE_ITEM_BALANCE = 10n;
|
|
9925
|
-
/**
|
|
9926
|
-
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
9927
|
-
*
|
|
9928
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
9929
|
-
*/
|
|
9930
|
-
const ELECTIVE_BYTE_BALANCE = 1n;
|
|
9931
|
-
const zeroSizeHint = {
|
|
9932
|
-
bytes: 0,
|
|
9933
|
-
isExact: true,
|
|
9934
|
-
};
|
|
9935
|
-
/** 0-byte read, return given default value */
|
|
9936
|
-
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
9937
|
-
/**
|
|
9938
|
-
* Service account details.
|
|
9939
|
-
*
|
|
9940
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
|
|
9941
|
-
*/
|
|
9942
|
-
class ServiceAccountInfo extends WithDebug {
|
|
9943
|
-
codeHash;
|
|
9944
|
-
balance;
|
|
9945
|
-
accumulateMinGas;
|
|
9946
|
-
onTransferMinGas;
|
|
9947
|
-
storageUtilisationBytes;
|
|
9948
|
-
gratisStorage;
|
|
9949
|
-
storageUtilisationCount;
|
|
9950
|
-
created;
|
|
9951
|
-
lastAccumulation;
|
|
9952
|
-
parentService;
|
|
9953
|
-
static Codec = descriptors_codec.Class(ServiceAccountInfo, {
|
|
9954
|
-
codeHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
9955
|
-
balance: descriptors_codec.u64,
|
|
9956
|
-
accumulateMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
|
|
9957
|
-
onTransferMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
|
|
9958
|
-
storageUtilisationBytes: descriptors_codec.u64,
|
|
9959
|
-
gratisStorage: descriptors_codec.u64,
|
|
9960
|
-
storageUtilisationCount: descriptors_codec.u32,
|
|
9961
|
-
created: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
|
|
9962
|
-
lastAccumulation: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
|
|
9963
|
-
parentService: descriptors_codec.u32.convert((x) => x, tryAsServiceId),
|
|
9964
|
-
});
|
|
9965
|
-
static create(a) {
|
|
9966
|
-
return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
|
|
9967
|
-
}
|
|
9968
|
-
/**
|
|
9969
|
-
* `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
|
|
9970
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
|
|
9971
|
-
*/
|
|
9972
|
-
static calculateThresholdBalance(items, bytes, gratisStorage) {
|
|
9973
|
-
const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
|
|
9974
|
-
if (storageCost < 0n) {
|
|
9975
|
-
return numbers_tryAsU64(0);
|
|
9976
|
-
}
|
|
9977
|
-
if (storageCost >= 2n ** 64n) {
|
|
9978
|
-
return numbers_tryAsU64(2n ** 64n - 1n);
|
|
9979
|
-
}
|
|
9980
|
-
return numbers_tryAsU64(storageCost);
|
|
9981
|
-
}
|
|
9982
|
-
constructor(
|
|
9983
|
-
/** `a_c`: Hash of the service code. */
|
|
9984
|
-
codeHash,
|
|
9985
|
-
/** `a_b`: Current account balance. */
|
|
9986
|
-
balance,
|
|
9987
|
-
/** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
|
|
9988
|
-
accumulateMinGas,
|
|
9989
|
-
/** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
|
|
9990
|
-
onTransferMinGas,
|
|
9991
|
-
/** `a_o`: Total number of octets in storage. */
|
|
9992
|
-
storageUtilisationBytes,
|
|
9993
|
-
/** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
|
|
9994
|
-
gratisStorage,
|
|
9995
|
-
/** `a_i`: Number of items in storage. */
|
|
9996
|
-
storageUtilisationCount,
|
|
9997
|
-
/** `a_r`: Creation account time slot. */
|
|
9998
|
-
created,
|
|
9999
|
-
/** `a_a`: Most recent accumulation time slot. */
|
|
10000
|
-
lastAccumulation,
|
|
10001
|
-
/** `a_p`: Parent service ID. */
|
|
10002
|
-
parentService) {
|
|
10003
|
-
super();
|
|
10004
|
-
this.codeHash = codeHash;
|
|
10005
|
-
this.balance = balance;
|
|
10006
|
-
this.accumulateMinGas = accumulateMinGas;
|
|
10007
|
-
this.onTransferMinGas = onTransferMinGas;
|
|
10008
|
-
this.storageUtilisationBytes = storageUtilisationBytes;
|
|
10009
|
-
this.gratisStorage = gratisStorage;
|
|
10010
|
-
this.storageUtilisationCount = storageUtilisationCount;
|
|
10011
|
-
this.created = created;
|
|
10012
|
-
this.lastAccumulation = lastAccumulation;
|
|
10013
|
-
this.parentService = parentService;
|
|
10014
|
-
}
|
|
10015
|
-
}
|
|
10016
|
-
class PreimageItem extends WithDebug {
|
|
10017
|
-
hash;
|
|
10018
|
-
blob;
|
|
10019
|
-
static Codec = descriptors_codec.Class(PreimageItem, {
|
|
10020
|
-
hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
10021
|
-
blob: descriptors_codec.blob,
|
|
10089
|
+
keys;
|
|
10090
|
+
tickets;
|
|
10091
|
+
static Codec = codecWithContext((context) => {
|
|
10092
|
+
return descriptors_codec.custom({
|
|
10093
|
+
name: "SafroleSealingKeys",
|
|
10094
|
+
sizeHint: { bytes: 1 + hash_HASH_SIZE * context.epochLength, isExact: false },
|
|
10095
|
+
}, (e, x) => {
|
|
10096
|
+
e.varU32(numbers_tryAsU32(x.kind));
|
|
10097
|
+
if (x.kind === SafroleSealingKeysKind.Keys) {
|
|
10098
|
+
e.sequenceFixLen(codecBandersnatchKey, x.keys);
|
|
10099
|
+
}
|
|
10100
|
+
else {
|
|
10101
|
+
e.sequenceFixLen(Ticket.Codec, x.tickets);
|
|
10102
|
+
}
|
|
10103
|
+
}, (d) => {
|
|
10104
|
+
const epochLength = context.epochLength;
|
|
10105
|
+
const kind = d.varU32();
|
|
10106
|
+
if (kind === SafroleSealingKeysKind.Keys) {
|
|
10107
|
+
const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
|
|
10108
|
+
return SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
|
|
10109
|
+
}
|
|
10110
|
+
if (kind === SafroleSealingKeysKind.Tickets) {
|
|
10111
|
+
const tickets = d.sequenceFixLen(Ticket.Codec, epochLength);
|
|
10112
|
+
return SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
|
|
10113
|
+
}
|
|
10114
|
+
throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
|
|
10115
|
+
}, (s) => {
|
|
10116
|
+
const kind = s.decoder.varU32();
|
|
10117
|
+
if (kind === SafroleSealingKeysKind.Keys) {
|
|
10118
|
+
s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
|
|
10119
|
+
return;
|
|
10120
|
+
}
|
|
10121
|
+
if (kind === SafroleSealingKeysKind.Tickets) {
|
|
10122
|
+
s.sequenceFixLen(Ticket.Codec, context.epochLength);
|
|
10123
|
+
return;
|
|
10124
|
+
}
|
|
10125
|
+
throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
|
|
10126
|
+
});
|
|
10022
10127
|
});
|
|
10023
|
-
static
|
|
10024
|
-
return new
|
|
10025
|
-
}
|
|
10026
|
-
constructor(hash, blob) {
|
|
10027
|
-
super();
|
|
10028
|
-
this.hash = hash;
|
|
10029
|
-
this.blob = blob;
|
|
10128
|
+
static keys(keys) {
|
|
10129
|
+
return new SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
|
|
10030
10130
|
}
|
|
10031
|
-
|
|
10032
|
-
|
|
10033
|
-
key;
|
|
10034
|
-
value;
|
|
10035
|
-
static Codec = descriptors_codec.Class(StorageItem, {
|
|
10036
|
-
key: descriptors_codec.blob.convert((i) => i, (o) => opaque_asOpaqueType(o)),
|
|
10037
|
-
value: descriptors_codec.blob,
|
|
10038
|
-
});
|
|
10039
|
-
static create({ key, value }) {
|
|
10040
|
-
return new StorageItem(key, value);
|
|
10131
|
+
static tickets(tickets) {
|
|
10132
|
+
return new SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
|
|
10041
10133
|
}
|
|
10042
|
-
constructor(
|
|
10134
|
+
constructor(kind, keys, tickets) {
|
|
10043
10135
|
super();
|
|
10044
|
-
this.
|
|
10045
|
-
this.
|
|
10046
|
-
|
|
10047
|
-
}
|
|
10048
|
-
const MAX_LOOKUP_HISTORY_SLOTS = 3;
|
|
10049
|
-
function tryAsLookupHistorySlots(items) {
|
|
10050
|
-
const knownSize = sized_array_asKnownSize(items);
|
|
10051
|
-
if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
|
|
10052
|
-
throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
|
|
10136
|
+
this.kind = kind;
|
|
10137
|
+
this.keys = keys;
|
|
10138
|
+
this.tickets = tickets;
|
|
10053
10139
|
}
|
|
10054
|
-
return knownSize;
|
|
10055
10140
|
}
|
|
10056
|
-
|
|
10057
|
-
|
|
10058
|
-
|
|
10059
|
-
|
|
10060
|
-
|
|
10061
|
-
|
|
10062
|
-
|
|
10063
|
-
|
|
10064
|
-
|
|
10065
|
-
|
|
10066
|
-
|
|
10067
|
-
|
|
10068
|
-
|
|
10069
|
-
this.slots = slots;
|
|
10141
|
+
class SafroleData {
|
|
10142
|
+
nextValidatorData;
|
|
10143
|
+
epochRoot;
|
|
10144
|
+
sealingKeySeries;
|
|
10145
|
+
ticketsAccumulator;
|
|
10146
|
+
static Codec = descriptors_codec.Class(SafroleData, {
|
|
10147
|
+
nextValidatorData: codecPerValidator(ValidatorData.Codec),
|
|
10148
|
+
epochRoot: descriptors_codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
10149
|
+
sealingKeySeries: SafroleSealingKeysData.Codec,
|
|
10150
|
+
ticketsAccumulator: readonlyArray(descriptors_codec.sequenceVarLen(Ticket.Codec)).convert(seeThrough, sized_array_asKnownSize),
|
|
10151
|
+
});
|
|
10152
|
+
static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
|
|
10153
|
+
return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
|
|
10070
10154
|
}
|
|
10071
|
-
|
|
10072
|
-
|
|
10073
|
-
|
|
10074
|
-
|
|
10075
|
-
|
|
10155
|
+
constructor(
|
|
10156
|
+
/** gamma_k */
|
|
10157
|
+
nextValidatorData,
|
|
10158
|
+
/** gamma_z */
|
|
10159
|
+
epochRoot,
|
|
10160
|
+
/** gamma_s */
|
|
10161
|
+
sealingKeySeries,
|
|
10162
|
+
/** gamma_a */
|
|
10163
|
+
ticketsAccumulator) {
|
|
10164
|
+
this.nextValidatorData = nextValidatorData;
|
|
10165
|
+
this.epochRoot = epochRoot;
|
|
10166
|
+
this.sealingKeySeries = sealingKeySeries;
|
|
10167
|
+
this.ticketsAccumulator = ticketsAccumulator;
|
|
10076
10168
|
}
|
|
10077
10169
|
}
|
|
10078
10170
|
|
|
@@ -10512,6 +10604,7 @@ class StatisticsData {
|
|
|
10512
10604
|
|
|
10513
10605
|
|
|
10514
10606
|
|
|
10607
|
+
|
|
10515
10608
|
|
|
10516
10609
|
|
|
10517
10610
|
var in_memory_state_UpdateError;
|
|
@@ -10915,8 +11008,9 @@ class InMemoryState extends WithDebug {
|
|
|
10915
11008
|
epochRoot: bytes_Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
10916
11009
|
privilegedServices: PrivilegedServices.create({
|
|
10917
11010
|
manager: tryAsServiceId(0),
|
|
10918
|
-
|
|
10919
|
-
|
|
11011
|
+
assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
|
|
11012
|
+
delegator: tryAsServiceId(0),
|
|
11013
|
+
registrar: tryAsServiceId(MAX_VALUE),
|
|
10920
11014
|
autoAccumulateServices: [],
|
|
10921
11015
|
}),
|
|
10922
11016
|
accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
|
|
@@ -11010,6 +11104,7 @@ class NotYetAccumulatedReport extends WithDebug {
|
|
|
11010
11104
|
|
|
11011
11105
|
|
|
11012
11106
|
|
|
11107
|
+
|
|
11013
11108
|
/** Serialization for particular state entries. */
|
|
11014
11109
|
var serialize;
|
|
11015
11110
|
(function (serialize) {
|
|
@@ -11124,7 +11219,9 @@ var serialize;
|
|
|
11124
11219
|
/** C(255, s): https://graypaper.fluffylabs.dev/#/85129da/383103383103?v=0.6.3 */
|
|
11125
11220
|
serialize.serviceData = (serviceId) => ({
|
|
11126
11221
|
key: stateKeys.serviceInfo(serviceId),
|
|
11127
|
-
Codec:
|
|
11222
|
+
Codec: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
11223
|
+
? codecWithVersion(ServiceAccountInfo.Codec)
|
|
11224
|
+
: ServiceAccountInfo.Codec,
|
|
11128
11225
|
});
|
|
11129
11226
|
/** https://graypaper.fluffylabs.dev/#/85129da/384803384803?v=0.6.3 */
|
|
11130
11227
|
serialize.serviceStorage = (blake2b, serviceId, key) => ({
|
|
@@ -11149,7 +11246,7 @@ var serialize;
|
|
|
11149
11246
|
* determine the boundary of the bytes, so it can only be used
|
|
11150
11247
|
* as the last element of the codec and can't be used in sequences!
|
|
11151
11248
|
*/
|
|
11152
|
-
const dumpCodec =
|
|
11249
|
+
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()));
|
|
11153
11250
|
|
|
11154
11251
|
;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
|
|
11155
11252
|
|
|
@@ -12460,7 +12557,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
|
|
|
12460
12557
|
}
|
|
12461
12558
|
return Ordering.Equal;
|
|
12462
12559
|
}, } = {}) => {
|
|
12463
|
-
return
|
|
12560
|
+
return Descriptor.new(`Map<${value.name}>[?]`, {
|
|
12464
12561
|
bytes: typicalLength * value.sizeHint.bytes,
|
|
12465
12562
|
isExact: false,
|
|
12466
12563
|
}, (e, v) => {
|
|
@@ -15049,7 +15146,7 @@ class AccumulationStateUpdate {
|
|
|
15049
15146
|
if (from.privilegedServices !== null) {
|
|
15050
15147
|
update.privilegedServices = PrivilegedServices.create({
|
|
15051
15148
|
...from.privilegedServices,
|
|
15052
|
-
|
|
15149
|
+
assigners: sized_array_asKnownSize([...from.privilegedServices.assigners]),
|
|
15053
15150
|
});
|
|
15054
15151
|
}
|
|
15055
15152
|
return update;
|
|
@@ -17188,13 +17285,6 @@ class BitOps {
|
|
|
17188
17285
|
}
|
|
17189
17286
|
}
|
|
17190
17287
|
|
|
17191
|
-
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
|
|
17192
|
-
const MAX_VALUE = 4294967295;
|
|
17193
|
-
const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
|
|
17194
|
-
const MIN_VALUE = -(2 ** 31);
|
|
17195
|
-
const MAX_SHIFT_U32 = 32;
|
|
17196
|
-
const MAX_SHIFT_U64 = 64n;
|
|
17197
|
-
|
|
17198
17288
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-utils.ts
|
|
17199
17289
|
|
|
17200
17290
|
|
|
@@ -19224,6 +19314,8 @@ var NewServiceError;
|
|
|
19224
19314
|
NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
|
|
19225
19315
|
/** Service is not privileged to set gratis storage. */
|
|
19226
19316
|
NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
|
|
19317
|
+
/** Registrar attempting to create a service with already existing id. */
|
|
19318
|
+
NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
|
|
19227
19319
|
})(NewServiceError || (NewServiceError = {}));
|
|
19228
19320
|
var UpdatePrivilegesError;
|
|
19229
19321
|
(function (UpdatePrivilegesError) {
|
|
@@ -19360,7 +19452,7 @@ const HostCallResult = {
|
|
|
19360
19452
|
OOB: numbers_tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
|
|
19361
19453
|
/** Index unknown. */
|
|
19362
19454
|
WHO: numbers_tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
|
|
19363
|
-
/** Storage full. */
|
|
19455
|
+
/** Storage full or resource already allocated. */
|
|
19364
19456
|
FULL: numbers_tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
|
|
19365
19457
|
/** Core index unknown. */
|
|
19366
19458
|
CORE: numbers_tryAsU64(0xfffffffffffffffan), // 2**64 - 6
|
|
@@ -19368,7 +19460,7 @@ const HostCallResult = {
|
|
|
19368
19460
|
CASH: numbers_tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
|
|
19369
19461
|
/** Gas limit too low. */
|
|
19370
19462
|
LOW: numbers_tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
|
|
19371
|
-
/** The item is already solicited
|
|
19463
|
+
/** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
|
|
19372
19464
|
HUH: numbers_tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
|
|
19373
19465
|
/** The return value indicating general success. */
|
|
19374
19466
|
OK: numbers_tryAsU64(0n),
|
|
@@ -19422,6 +19514,7 @@ function clampU64ToU32(value) {
|
|
|
19422
19514
|
|
|
19423
19515
|
|
|
19424
19516
|
|
|
19517
|
+
|
|
19425
19518
|
/**
|
|
19426
19519
|
* Number of storage items required for ejection of the service.
|
|
19427
19520
|
*
|
|
@@ -19513,10 +19606,13 @@ class AccumulateExternalities {
|
|
|
19513
19606
|
const isExpired = status.data[1] < t - this.chainSpec.preimageExpungePeriod;
|
|
19514
19607
|
return [isExpired, isExpired ? "" : "not expired"];
|
|
19515
19608
|
}
|
|
19516
|
-
/** `check`: https://graypaper.fluffylabs.dev/#/
|
|
19609
|
+
/** `check`: https://graypaper.fluffylabs.dev/#/ab2cdbd/30c60330c603?v=0.7.2 */
|
|
19517
19610
|
getNextAvailableServiceId(serviceId) {
|
|
19518
19611
|
let currentServiceId = serviceId;
|
|
19519
|
-
const mod =
|
|
19612
|
+
const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
19613
|
+
? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
|
|
19614
|
+
: 2 ** 32 - 2 ** 9;
|
|
19615
|
+
const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
|
|
19520
19616
|
for (;;) {
|
|
19521
19617
|
const service = this.getServiceInfo(currentServiceId);
|
|
19522
19618
|
// we found an empty id
|
|
@@ -19524,7 +19620,7 @@ class AccumulateExternalities {
|
|
|
19524
19620
|
return currentServiceId;
|
|
19525
19621
|
}
|
|
19526
19622
|
// keep trying
|
|
19527
|
-
currentServiceId = tryAsServiceId(((currentServiceId -
|
|
19623
|
+
currentServiceId = tryAsServiceId(((currentServiceId - offset + 1 + mod) % mod) + offset);
|
|
19528
19624
|
}
|
|
19529
19625
|
}
|
|
19530
19626
|
checkPreimageStatus(hash, length) {
|
|
@@ -19681,8 +19777,7 @@ class AccumulateExternalities {
|
|
|
19681
19777
|
}));
|
|
19682
19778
|
return result_Result.ok(result_OK);
|
|
19683
19779
|
}
|
|
19684
|
-
newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage) {
|
|
19685
|
-
const newServiceId = this.nextNewServiceId;
|
|
19780
|
+
newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage, wantedServiceId) {
|
|
19686
19781
|
// calculate the threshold. Storage is empty, one preimage requested.
|
|
19687
19782
|
// https://graypaper.fluffylabs.dev/#/7e6ff6a/115901115901?v=0.6.7
|
|
19688
19783
|
const items = numbers_tryAsU32(2 * 1 + 0);
|
|
@@ -19703,30 +19798,59 @@ class AccumulateExternalities {
|
|
|
19703
19798
|
if (balanceLeftForCurrent < thresholdForCurrent || bytes.overflow) {
|
|
19704
19799
|
return result_Result.error(NewServiceError.InsufficientFunds);
|
|
19705
19800
|
}
|
|
19801
|
+
// `a`: https://graypaper.fluffylabs.dev/#/ab2cdbd/366b02366d02?v=0.7.2
|
|
19802
|
+
const newAccount = ServiceAccountInfo.create({
|
|
19803
|
+
codeHash,
|
|
19804
|
+
balance: thresholdForNew,
|
|
19805
|
+
accumulateMinGas,
|
|
19806
|
+
onTransferMinGas,
|
|
19807
|
+
storageUtilisationBytes: bytes.value,
|
|
19808
|
+
storageUtilisationCount: items,
|
|
19809
|
+
gratisStorage,
|
|
19810
|
+
created: this.currentTimeslot,
|
|
19811
|
+
lastAccumulation: common_tryAsTimeSlot(0),
|
|
19812
|
+
parentService: this.currentServiceId,
|
|
19813
|
+
});
|
|
19814
|
+
const newLookupItem = new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([]));
|
|
19815
|
+
// `s`: https://graypaper.fluffylabs.dev/#/ab2cdbd/361003361003?v=0.7.2
|
|
19816
|
+
const updatedCurrentAccount = ServiceAccountInfo.create({
|
|
19817
|
+
...currentService,
|
|
19818
|
+
balance: numbers_tryAsU64(balanceLeftForCurrent),
|
|
19819
|
+
});
|
|
19820
|
+
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
|
|
19821
|
+
if (wantedServiceId < MIN_PUBLIC_SERVICE_INDEX &&
|
|
19822
|
+
this.currentServiceId === this.updatedState.getPrivilegedServices().registrar) {
|
|
19823
|
+
// NOTE: It's safe to cast to `Number` here, bcs here service ID cannot be bigger than 2**16
|
|
19824
|
+
const newServiceId = tryAsServiceId(Number(wantedServiceId));
|
|
19825
|
+
if (this.getServiceInfo(newServiceId) !== null) {
|
|
19826
|
+
return result_Result.error(NewServiceError.RegistrarServiceIdAlreadyTaken);
|
|
19827
|
+
}
|
|
19828
|
+
// add the new service with selected ID
|
|
19829
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36be0336c003?v=0.7.2
|
|
19830
|
+
this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
|
|
19831
|
+
serviceId: newServiceId,
|
|
19832
|
+
serviceInfo: newAccount,
|
|
19833
|
+
lookupHistory: newLookupItem,
|
|
19834
|
+
}));
|
|
19835
|
+
// update the balance of current service
|
|
19836
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36c20336c403?v=0.7.2
|
|
19837
|
+
this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
|
|
19838
|
+
return result_Result.ok(newServiceId);
|
|
19839
|
+
}
|
|
19840
|
+
// NOTE: in case the service is not a registrar or the requested serviceId is out of range,
|
|
19841
|
+
// we completely ignore the `wantedServiceId` and assign a random one
|
|
19842
|
+
}
|
|
19843
|
+
const newServiceId = this.nextNewServiceId;
|
|
19706
19844
|
// add the new service
|
|
19707
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
19845
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36e70336e903?v=0.7.2
|
|
19708
19846
|
this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
|
|
19709
19847
|
serviceId: newServiceId,
|
|
19710
|
-
serviceInfo:
|
|
19711
|
-
|
|
19712
|
-
balance: thresholdForNew,
|
|
19713
|
-
accumulateMinGas,
|
|
19714
|
-
onTransferMinGas,
|
|
19715
|
-
storageUtilisationBytes: bytes.value,
|
|
19716
|
-
storageUtilisationCount: items,
|
|
19717
|
-
gratisStorage,
|
|
19718
|
-
created: this.currentTimeslot,
|
|
19719
|
-
lastAccumulation: common_tryAsTimeSlot(0),
|
|
19720
|
-
parentService: this.currentServiceId,
|
|
19721
|
-
}),
|
|
19722
|
-
lookupHistory: new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([])),
|
|
19848
|
+
serviceInfo: newAccount,
|
|
19849
|
+
lookupHistory: newLookupItem,
|
|
19723
19850
|
}));
|
|
19724
19851
|
// update the balance of current service
|
|
19725
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
19726
|
-
this.updatedState.updateServiceInfo(this.currentServiceId,
|
|
19727
|
-
...currentService,
|
|
19728
|
-
balance: numbers_tryAsU64(balanceLeftForCurrent),
|
|
19729
|
-
}));
|
|
19852
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36ec0336ee03?v=0.7.2
|
|
19853
|
+
this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
|
|
19730
19854
|
// update the next service id we are going to create next
|
|
19731
19855
|
// https://graypaper.fluffylabs.dev/#/7e6ff6a/36a70336a703?v=0.6.7
|
|
19732
19856
|
this.nextNewServiceId = this.getNextAvailableServiceId(bumpServiceId(newServiceId));
|
|
@@ -19744,9 +19868,9 @@ class AccumulateExternalities {
|
|
|
19744
19868
|
}
|
|
19745
19869
|
updateValidatorsData(validatorsData) {
|
|
19746
19870
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/362802362d02?v=0.6.7 */
|
|
19747
|
-
const
|
|
19748
|
-
if (
|
|
19749
|
-
accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${
|
|
19871
|
+
const currentDelegator = this.updatedState.getPrivilegedServices().delegator;
|
|
19872
|
+
if (currentDelegator !== this.currentServiceId) {
|
|
19873
|
+
accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${currentDelegator}) and cannot update validators data. Ignoring`;
|
|
19750
19874
|
return result_Result.error(UnprivilegedError);
|
|
19751
19875
|
}
|
|
19752
19876
|
this.updatedState.stateUpdate.validatorsData = validatorsData;
|
|
@@ -19756,34 +19880,38 @@ class AccumulateExternalities {
|
|
|
19756
19880
|
/** https://graypaper.fluffylabs.dev/#/9a08063/362202362202?v=0.6.6 */
|
|
19757
19881
|
this.checkpointedState = AccumulationStateUpdate.copyFrom(this.updatedState.stateUpdate);
|
|
19758
19882
|
}
|
|
19759
|
-
updateAuthorizationQueue(coreIndex, authQueue,
|
|
19883
|
+
updateAuthorizationQueue(coreIndex, authQueue, assigners) {
|
|
19760
19884
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/36a40136a401?v=0.6.7 */
|
|
19761
19885
|
// NOTE `coreIndex` is already verified in the HC, so this is infallible.
|
|
19762
|
-
const
|
|
19763
|
-
if (
|
|
19764
|
-
accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not an auth manager of core ${coreIndex} (expected: ${
|
|
19886
|
+
const currentAssigners = this.updatedState.getPrivilegedServices().assigners[coreIndex];
|
|
19887
|
+
if (currentAssigners !== this.currentServiceId) {
|
|
19888
|
+
accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not an auth manager of core ${coreIndex} (expected: ${currentAssigners}) and cannot update authorization queue.`;
|
|
19765
19889
|
return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
|
|
19766
19890
|
}
|
|
19767
|
-
if (
|
|
19768
|
-
accumulate_externalities_logger.trace `The new auth manager is not a valid service id
|
|
19891
|
+
if (assigners === null && Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
|
|
19892
|
+
accumulate_externalities_logger.trace `The new auth manager is not a valid service id.`;
|
|
19769
19893
|
return result_Result.error(UpdatePrivilegesError.InvalidServiceId);
|
|
19770
19894
|
}
|
|
19771
19895
|
this.updatedState.stateUpdate.authorizationQueues.set(coreIndex, authQueue);
|
|
19772
19896
|
return result_Result.ok(result_OK);
|
|
19773
19897
|
}
|
|
19774
|
-
updatePrivilegedServices(manager, authorizers,
|
|
19898
|
+
updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate) {
|
|
19775
19899
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/36d90036de00?v=0.6.7 */
|
|
19776
19900
|
const currentManager = this.updatedState.getPrivilegedServices().manager;
|
|
19777
19901
|
if (currentManager !== this.currentServiceId) {
|
|
19778
19902
|
return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
|
|
19779
19903
|
}
|
|
19780
|
-
if (manager === null ||
|
|
19781
|
-
return result_Result.error(UpdatePrivilegesError.InvalidServiceId);
|
|
19904
|
+
if (manager === null || delegator === null) {
|
|
19905
|
+
return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Either manager or delegator is not valid service id.");
|
|
19906
|
+
}
|
|
19907
|
+
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && registrar === null) {
|
|
19908
|
+
return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Register manager is not valid service id.");
|
|
19782
19909
|
}
|
|
19783
19910
|
this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
|
|
19784
19911
|
manager,
|
|
19785
|
-
|
|
19786
|
-
|
|
19912
|
+
assigners: authorizers,
|
|
19913
|
+
delegator,
|
|
19914
|
+
registrar: registrar ?? tryAsServiceId(0), // introduced in 0.7.1
|
|
19787
19915
|
autoAccumulateServices: autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit })),
|
|
19788
19916
|
});
|
|
19789
19917
|
return result_Result.ok(result_OK);
|
|
@@ -19899,8 +20027,11 @@ class AccumulateExternalities {
|
|
|
19899
20027
|
}
|
|
19900
20028
|
}
|
|
19901
20029
|
function bumpServiceId(serviceId) {
|
|
19902
|
-
const mod =
|
|
19903
|
-
|
|
20030
|
+
const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
20031
|
+
? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
|
|
20032
|
+
: 2 ** 32 - 2 ** 9;
|
|
20033
|
+
const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
|
|
20034
|
+
return tryAsServiceId(offset + ((serviceId - offset + 42 + mod) % mod));
|
|
19904
20035
|
}
|
|
19905
20036
|
|
|
19906
20037
|
;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-state.ts
|
|
@@ -20143,6 +20274,44 @@ function signingPayload(blake2b, anchor, blob) {
|
|
|
20143
20274
|
|
|
20144
20275
|
|
|
20145
20276
|
|
|
20277
|
+
var TransferOperandKind;
|
|
20278
|
+
(function (TransferOperandKind) {
|
|
20279
|
+
TransferOperandKind[TransferOperandKind["OPERAND"] = 0] = "OPERAND";
|
|
20280
|
+
TransferOperandKind[TransferOperandKind["TRANSFER"] = 1] = "TRANSFER";
|
|
20281
|
+
})(TransferOperandKind || (TransferOperandKind = {}));
|
|
20282
|
+
const TRANSFER_OR_OPERAND = descriptors_codec.custom({
|
|
20283
|
+
name: "TransferOrOperand",
|
|
20284
|
+
sizeHint: { bytes: 1, isExact: false },
|
|
20285
|
+
}, (e, x) => {
|
|
20286
|
+
e.varU32(numbers_tryAsU32(x.kind));
|
|
20287
|
+
if (x.kind === TransferOperandKind.OPERAND) {
|
|
20288
|
+
e.object(Operand.Codec, x.value);
|
|
20289
|
+
}
|
|
20290
|
+
if (x.kind === TransferOperandKind.TRANSFER) {
|
|
20291
|
+
e.object(PendingTransfer.Codec, x.value);
|
|
20292
|
+
}
|
|
20293
|
+
}, (d) => {
|
|
20294
|
+
const kind = d.varU32();
|
|
20295
|
+
if (kind === TransferOperandKind.OPERAND) {
|
|
20296
|
+
return {
|
|
20297
|
+
kind: TransferOperandKind.OPERAND,
|
|
20298
|
+
value: d.object(Operand.Codec),
|
|
20299
|
+
};
|
|
20300
|
+
}
|
|
20301
|
+
if (kind === TransferOperandKind.TRANSFER) {
|
|
20302
|
+
return { kind: TransferOperandKind.TRANSFER, value: d.object(PendingTransfer.Codec) };
|
|
20303
|
+
}
|
|
20304
|
+
throw new Error(`Unable to decode TransferOrOperand. Invalid kind: ${kind}.`);
|
|
20305
|
+
}, (s) => {
|
|
20306
|
+
const kind = s.decoder.varU32();
|
|
20307
|
+
if (kind === TransferOperandKind.OPERAND) {
|
|
20308
|
+
s.object(Operand.Codec);
|
|
20309
|
+
}
|
|
20310
|
+
if (kind === TransferOperandKind.TRANSFER) {
|
|
20311
|
+
s.object(PendingTransfer.Codec);
|
|
20312
|
+
}
|
|
20313
|
+
});
|
|
20314
|
+
const TRANSFERS_AND_OPERANDS = descriptors_codec.sequenceVarLen(TRANSFER_OR_OPERAND);
|
|
20146
20315
|
// https://github.com/gavofyork/graypaper/pull/414
|
|
20147
20316
|
// 0.7.0 encoding is used for prior versions as well.
|
|
20148
20317
|
const CONSTANTS_CODEC = descriptors_codec.object({
|
|
@@ -20227,7 +20396,10 @@ function getEncodedConstants(chainSpec) {
|
|
|
20227
20396
|
var FetchContext;
|
|
20228
20397
|
(function (FetchContext) {
|
|
20229
20398
|
FetchContext[FetchContext["Accumulate"] = 0] = "Accumulate";
|
|
20230
|
-
|
|
20399
|
+
/** @deprecated since 0.7.1 */
|
|
20400
|
+
FetchContext[FetchContext["LegacyAccumulate"] = 1] = "LegacyAccumulate";
|
|
20401
|
+
/** @deprecated since 0.7.1 */
|
|
20402
|
+
FetchContext[FetchContext["LegacyOnTransfer"] = 2] = "LegacyOnTransfer";
|
|
20231
20403
|
})(FetchContext || (FetchContext = {}));
|
|
20232
20404
|
class FetchExternalities {
|
|
20233
20405
|
fetchData;
|
|
@@ -20236,11 +20408,14 @@ class FetchExternalities {
|
|
|
20236
20408
|
this.fetchData = fetchData;
|
|
20237
20409
|
this.chainSpec = chainSpec;
|
|
20238
20410
|
}
|
|
20411
|
+
static createForPre071Accumulate(fetchData, chainSpec) {
|
|
20412
|
+
return new FetchExternalities({ context: FetchContext.LegacyAccumulate, ...fetchData }, chainSpec);
|
|
20413
|
+
}
|
|
20239
20414
|
static createForAccumulate(fetchData, chainSpec) {
|
|
20240
20415
|
return new FetchExternalities({ context: FetchContext.Accumulate, ...fetchData }, chainSpec);
|
|
20241
20416
|
}
|
|
20242
20417
|
static createForOnTransfer(fetchData, chainSpec) {
|
|
20243
|
-
return new FetchExternalities({ context: FetchContext.
|
|
20418
|
+
return new FetchExternalities({ context: FetchContext.LegacyOnTransfer, ...fetchData }, chainSpec);
|
|
20244
20419
|
}
|
|
20245
20420
|
constants() {
|
|
20246
20421
|
return getEncodedConstants(this.chainSpec);
|
|
@@ -20283,46 +20458,73 @@ class FetchExternalities {
|
|
|
20283
20458
|
return null;
|
|
20284
20459
|
}
|
|
20285
20460
|
allOperands() {
|
|
20286
|
-
if (this.fetchData.context
|
|
20287
|
-
|
|
20461
|
+
if (this.fetchData.context === FetchContext.LegacyAccumulate) {
|
|
20462
|
+
const operands = this.fetchData.operands;
|
|
20463
|
+
return encoder_Encoder.encodeObject(descriptors_codec.sequenceVarLen(Operand.Codec), operands, this.chainSpec);
|
|
20288
20464
|
}
|
|
20289
|
-
|
|
20290
|
-
return encoder_Encoder.encodeObject(descriptors_codec.sequenceVarLen(Operand.Codec), operands, this.chainSpec);
|
|
20465
|
+
return null;
|
|
20291
20466
|
}
|
|
20292
20467
|
oneOperand(operandIndex) {
|
|
20293
|
-
if (this.fetchData.context
|
|
20294
|
-
|
|
20295
|
-
|
|
20296
|
-
|
|
20297
|
-
|
|
20298
|
-
|
|
20299
|
-
|
|
20300
|
-
|
|
20301
|
-
|
|
20302
|
-
return
|
|
20468
|
+
if (this.fetchData.context === FetchContext.LegacyAccumulate) {
|
|
20469
|
+
const { operands } = this.fetchData;
|
|
20470
|
+
if (operandIndex >= 2n ** 32n) {
|
|
20471
|
+
return null;
|
|
20472
|
+
}
|
|
20473
|
+
const operand = operands[Number(operandIndex)];
|
|
20474
|
+
if (operand === undefined) {
|
|
20475
|
+
return null;
|
|
20476
|
+
}
|
|
20477
|
+
return encoder_Encoder.encodeObject(Operand.Codec, operand, this.chainSpec);
|
|
20303
20478
|
}
|
|
20304
|
-
return
|
|
20479
|
+
return null;
|
|
20305
20480
|
}
|
|
20306
20481
|
allTransfers() {
|
|
20307
|
-
if (this.fetchData.context
|
|
20308
|
-
|
|
20482
|
+
if (this.fetchData.context === FetchContext.LegacyOnTransfer) {
|
|
20483
|
+
const { transfers } = this.fetchData;
|
|
20484
|
+
return encoder_Encoder.encodeObject(descriptors_codec.sequenceVarLen(PendingTransfer.Codec), transfers, this.chainSpec);
|
|
20309
20485
|
}
|
|
20310
|
-
|
|
20311
|
-
return encoder_Encoder.encodeObject(descriptors_codec.sequenceVarLen(PendingTransfer.Codec), transfers, this.chainSpec);
|
|
20486
|
+
return null;
|
|
20312
20487
|
}
|
|
20313
20488
|
oneTransfer(transferIndex) {
|
|
20314
|
-
if (this.fetchData.context
|
|
20315
|
-
|
|
20489
|
+
if (this.fetchData.context === FetchContext.LegacyOnTransfer) {
|
|
20490
|
+
const { transfers } = this.fetchData;
|
|
20491
|
+
if (transferIndex >= 2n ** 32n) {
|
|
20492
|
+
return null;
|
|
20493
|
+
}
|
|
20494
|
+
const transfer = transfers[Number(transferIndex)];
|
|
20495
|
+
if (transfer === undefined) {
|
|
20496
|
+
return null;
|
|
20497
|
+
}
|
|
20498
|
+
return encoder_Encoder.encodeObject(PendingTransfer.Codec, transfer, this.chainSpec);
|
|
20316
20499
|
}
|
|
20317
|
-
|
|
20318
|
-
|
|
20319
|
-
|
|
20500
|
+
return null;
|
|
20501
|
+
}
|
|
20502
|
+
allTransfersAndOperands() {
|
|
20503
|
+
if (this.fetchData.context === FetchContext.Accumulate) {
|
|
20504
|
+
const { transfers, operands } = this.fetchData;
|
|
20505
|
+
const transfersAndOperands = transfers
|
|
20506
|
+
.map((transfer) => ({ kind: TransferOperandKind.TRANSFER, value: transfer }))
|
|
20507
|
+
.concat(operands.map((operand) => ({ kind: TransferOperandKind.OPERAND, value: operand })));
|
|
20508
|
+
return encoder_Encoder.encodeObject(TRANSFERS_AND_OPERANDS, transfersAndOperands, this.chainSpec);
|
|
20320
20509
|
}
|
|
20321
|
-
|
|
20322
|
-
|
|
20323
|
-
|
|
20510
|
+
return null;
|
|
20511
|
+
}
|
|
20512
|
+
oneTransferOrOperand(index) {
|
|
20513
|
+
if (this.fetchData.context === FetchContext.Accumulate) {
|
|
20514
|
+
const { operands, transfers } = this.fetchData;
|
|
20515
|
+
if (index >= operands.length + transfers.length) {
|
|
20516
|
+
return null;
|
|
20517
|
+
}
|
|
20518
|
+
const kind = index < operands.length ? TransferOperandKind.OPERAND : TransferOperandKind.TRANSFER;
|
|
20519
|
+
const transferOrOperand = kind === TransferOperandKind.OPERAND
|
|
20520
|
+
? { kind: TransferOperandKind.OPERAND, value: operands[Number(index)] }
|
|
20521
|
+
: { kind: TransferOperandKind.TRANSFER, value: transfers[Number(index) - operands.length] };
|
|
20522
|
+
if (transferOrOperand.value === undefined) {
|
|
20523
|
+
return null;
|
|
20524
|
+
}
|
|
20525
|
+
return encoder_Encoder.encodeObject(TRANSFER_OR_OPERAND, transferOrOperand, this.chainSpec);
|
|
20324
20526
|
}
|
|
20325
|
-
return
|
|
20527
|
+
return null;
|
|
20326
20528
|
}
|
|
20327
20529
|
}
|
|
20328
20530
|
|
|
@@ -20355,31 +20557,45 @@ class AccumulateDataItem {
|
|
|
20355
20557
|
*/
|
|
20356
20558
|
class AccumulateData {
|
|
20357
20559
|
reportsDataByServiceId;
|
|
20560
|
+
transfersByServiceId;
|
|
20358
20561
|
autoAccumulateServicesByServiceId;
|
|
20359
20562
|
serviceIds;
|
|
20360
|
-
constructor(reports, autoAccumulateServices) {
|
|
20563
|
+
constructor(reports, transfers, autoAccumulateServices) {
|
|
20361
20564
|
const { autoAccumulateServicesByServiceId, serviceIds: serviceIdsFromAutoAccumulate } = this.transformAutoAccumulateServices(autoAccumulateServices);
|
|
20362
20565
|
this.autoAccumulateServicesByServiceId = autoAccumulateServicesByServiceId;
|
|
20363
20566
|
const { reportsDataByServiceId, serviceIds: serviceIdsFromReports } = this.transformReports(reports);
|
|
20364
20567
|
this.reportsDataByServiceId = reportsDataByServiceId;
|
|
20568
|
+
const { transfersByServiceId, serviceIds: serviceIdsFromTransfers } = this.transformTransfers(transfers);
|
|
20569
|
+
this.transfersByServiceId = transfersByServiceId;
|
|
20365
20570
|
/**
|
|
20366
|
-
* Merge service ids from reports
|
|
20571
|
+
* Merge service ids from reports, auto-accumulate services and transfers.
|
|
20367
20572
|
*
|
|
20368
20573
|
* https://graypaper.fluffylabs.dev/#/68eaa1f/175f01175f01?v=0.6.4
|
|
20369
20574
|
*/
|
|
20370
|
-
this.serviceIds = this.mergeServiceIds(serviceIdsFromReports, serviceIdsFromAutoAccumulate);
|
|
20575
|
+
this.serviceIds = this.mergeServiceIds(serviceIdsFromReports, serviceIdsFromAutoAccumulate, serviceIdsFromTransfers);
|
|
20371
20576
|
}
|
|
20372
20577
|
/** Merge two sets of service ids */
|
|
20373
|
-
mergeServiceIds(
|
|
20578
|
+
mergeServiceIds(...sources) {
|
|
20374
20579
|
const merged = new Set();
|
|
20375
|
-
for (const
|
|
20376
|
-
|
|
20377
|
-
|
|
20378
|
-
|
|
20379
|
-
merged.add(serviceId);
|
|
20580
|
+
for (const source of sources) {
|
|
20581
|
+
for (const serviceId of source) {
|
|
20582
|
+
merged.add(serviceId);
|
|
20583
|
+
}
|
|
20380
20584
|
}
|
|
20381
20585
|
return Array.from(merged);
|
|
20382
20586
|
}
|
|
20587
|
+
transformTransfers(transfersToTransform) {
|
|
20588
|
+
const transfersByServiceId = new Map();
|
|
20589
|
+
const serviceIds = new Set();
|
|
20590
|
+
for (const transfer of transfersToTransform) {
|
|
20591
|
+
const serviceId = transfer.destination;
|
|
20592
|
+
const transfers = transfersByServiceId.get(serviceId) ?? [];
|
|
20593
|
+
transfers.push(transfer);
|
|
20594
|
+
transfersByServiceId.set(serviceId, transfers);
|
|
20595
|
+
serviceIds.add(serviceId);
|
|
20596
|
+
}
|
|
20597
|
+
return { transfersByServiceId, serviceIds };
|
|
20598
|
+
}
|
|
20383
20599
|
/** Transform the list of auto-accumulate services into a map by service id. */
|
|
20384
20600
|
transformAutoAccumulateServices(autoAccumulateServices) {
|
|
20385
20601
|
const serviceIds = new Set();
|
|
@@ -20443,6 +20659,10 @@ class AccumulateData {
|
|
|
20443
20659
|
getOperands(serviceId) {
|
|
20444
20660
|
return this.reportsDataByServiceId.get(serviceId)?.operands ?? [];
|
|
20445
20661
|
}
|
|
20662
|
+
/** Returns the list of transfers for a given service id */
|
|
20663
|
+
getTransfers(serviceId) {
|
|
20664
|
+
return this.transfersByServiceId.get(serviceId) ?? [];
|
|
20665
|
+
}
|
|
20446
20666
|
/** Returns the number of reports to acccumulate for a given service id */
|
|
20447
20667
|
getReportsLength(serviceId) {
|
|
20448
20668
|
return this.reportsDataByServiceId.get(serviceId)?.reportsLength ?? numbers_tryAsU32(0);
|
|
@@ -20467,6 +20687,8 @@ class AccumulateData {
|
|
|
20467
20687
|
|
|
20468
20688
|
|
|
20469
20689
|
|
|
20690
|
+
|
|
20691
|
+
|
|
20470
20692
|
/**
|
|
20471
20693
|
* A function that removes duplicates but does not change order - it keeps the first occurence.
|
|
20472
20694
|
*/
|
|
@@ -20496,7 +20718,7 @@ const NEXT_ID_CODEC = descriptors_codec.object({
|
|
|
20496
20718
|
*
|
|
20497
20719
|
* Please not that it does not call `check` function!
|
|
20498
20720
|
*
|
|
20499
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
20721
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/2fa9042fc304?v=0.7.2
|
|
20500
20722
|
*/
|
|
20501
20723
|
function generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blake2b) {
|
|
20502
20724
|
const encoded = encoder_Encoder.encodeObject(NEXT_ID_CODEC, {
|
|
@@ -20506,7 +20728,11 @@ function generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blak
|
|
|
20506
20728
|
}, chainSpec);
|
|
20507
20729
|
const result = blake2b.hashBytes(encoded).raw.subarray(0, 4);
|
|
20508
20730
|
const number = leBytesAsU32(result) >>> 0;
|
|
20509
|
-
|
|
20731
|
+
const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
20732
|
+
? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
|
|
20733
|
+
: 2 ** 32 - 2 ** 9;
|
|
20734
|
+
const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
|
|
20735
|
+
return tryAsServiceId((number % mod) + offset);
|
|
20510
20736
|
}
|
|
20511
20737
|
|
|
20512
20738
|
;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-queue.ts
|
|
@@ -20918,7 +21144,7 @@ class Assign {
|
|
|
20918
21144
|
// o
|
|
20919
21145
|
const authorizationQueueStart = regs.get(8);
|
|
20920
21146
|
// a
|
|
20921
|
-
const
|
|
21147
|
+
const assigners = getServiceId(regs.get(9));
|
|
20922
21148
|
const res = safeAllocUint8Array(hash_HASH_SIZE * AUTHORIZATION_QUEUE_SIZE);
|
|
20923
21149
|
const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
|
|
20924
21150
|
// error while reading the memory.
|
|
@@ -20935,7 +21161,7 @@ class Assign {
|
|
|
20935
21161
|
const decoder = decoder_Decoder.fromBlob(res);
|
|
20936
21162
|
const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE), AUTHORIZATION_QUEUE_SIZE);
|
|
20937
21163
|
const fixedSizeAuthQueue = FixedSizeArray.new(authQueue, AUTHORIZATION_QUEUE_SIZE);
|
|
20938
|
-
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue,
|
|
21164
|
+
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
|
|
20939
21165
|
if (result.isOk) {
|
|
20940
21166
|
regs.set(IN_OUT_REG, HostCallResult.OK);
|
|
20941
21167
|
logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
|
|
@@ -20984,7 +21210,9 @@ class Bless {
|
|
|
20984
21210
|
chainSpec;
|
|
20985
21211
|
index = host_call_handler_tryAsHostCallIndex(14);
|
|
20986
21212
|
basicGasCost = gas_tryAsSmallGas(10);
|
|
20987
|
-
tracedRegisters =
|
|
21213
|
+
tracedRegisters = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
21214
|
+
? traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11, 12)
|
|
21215
|
+
: traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11);
|
|
20988
21216
|
constructor(currentServiceId, partialState, chainSpec) {
|
|
20989
21217
|
this.currentServiceId = currentServiceId;
|
|
20990
21218
|
this.partialState = partialState;
|
|
@@ -20994,14 +21222,17 @@ class Bless {
|
|
|
20994
21222
|
// `m`: manager service (can change privileged services)
|
|
20995
21223
|
const manager = getServiceId(regs.get(bless_IN_OUT_REG));
|
|
20996
21224
|
// `a`: manages authorization queue
|
|
20997
|
-
// NOTE It can be either ServiceId (pre GP 067) or memory index (GP ^067)
|
|
20998
21225
|
const authorization = regs.get(8);
|
|
20999
21226
|
// `v`: manages validator keys
|
|
21000
|
-
const
|
|
21227
|
+
const delegator = getServiceId(regs.get(9));
|
|
21228
|
+
// `r`: manages creation of new services with id within protected range
|
|
21229
|
+
const registrar = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
21230
|
+
? getServiceId(regs.get(10))
|
|
21231
|
+
: tryAsServiceId(2 ** 32 - 1);
|
|
21001
21232
|
// `o`: memory offset
|
|
21002
|
-
const sourceStart = regs.get(10);
|
|
21233
|
+
const sourceStart = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? regs.get(11) : regs.get(10);
|
|
21003
21234
|
// `n`: number of items in the auto-accumulate dictionary
|
|
21004
|
-
const numberOfItems = regs.get(11);
|
|
21235
|
+
const numberOfItems = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? regs.get(12) : regs.get(11);
|
|
21005
21236
|
/*
|
|
21006
21237
|
* `z`: array of key-value pairs serviceId -> gas that auto-accumulate every block
|
|
21007
21238
|
* https://graypaper.fluffylabs.dev/#/7e6ff6a/368100368100?v=0.6.7
|
|
@@ -21015,7 +21246,7 @@ class Bless {
|
|
|
21015
21246
|
decoder.resetTo(0);
|
|
21016
21247
|
const memoryReadResult = memory.loadInto(result, memIndex);
|
|
21017
21248
|
if (memoryReadResult.isError) {
|
|
21018
|
-
logger_logger.trace `BLESS(${manager}, ${
|
|
21249
|
+
logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}) <- PANIC`;
|
|
21019
21250
|
return PvmExecution.Panic;
|
|
21020
21251
|
}
|
|
21021
21252
|
const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
|
|
@@ -21028,24 +21259,25 @@ class Bless {
|
|
|
21028
21259
|
const authorizersDecoder = decoder_Decoder.fromBlob(res);
|
|
21029
21260
|
const memoryReadResult = memory.loadInto(res, authorization);
|
|
21030
21261
|
if (memoryReadResult.isError) {
|
|
21031
|
-
logger_logger.trace `BLESS(${manager}, ${
|
|
21262
|
+
logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- PANIC`;
|
|
21032
21263
|
return PvmExecution.Panic;
|
|
21033
21264
|
}
|
|
21265
|
+
// `a`
|
|
21034
21266
|
const authorizers = tryAsPerCore(authorizersDecoder.sequenceFixLen(descriptors_codec.u32.asOpaque(), this.chainSpec.coresCount), this.chainSpec);
|
|
21035
|
-
const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers,
|
|
21267
|
+
const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulateEntries);
|
|
21036
21268
|
if (updateResult.isOk) {
|
|
21037
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
21269
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- OK`;
|
|
21038
21270
|
regs.set(bless_IN_OUT_REG, HostCallResult.OK);
|
|
21039
21271
|
return;
|
|
21040
21272
|
}
|
|
21041
21273
|
const e = updateResult.error;
|
|
21042
21274
|
if (e === UpdatePrivilegesError.UnprivilegedService) {
|
|
21043
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
21275
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- HUH`;
|
|
21044
21276
|
regs.set(bless_IN_OUT_REG, HostCallResult.HUH);
|
|
21045
21277
|
return;
|
|
21046
21278
|
}
|
|
21047
21279
|
if (e === UpdatePrivilegesError.InvalidServiceId) {
|
|
21048
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
21280
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- WHO`;
|
|
21049
21281
|
regs.set(bless_IN_OUT_REG, HostCallResult.WHO);
|
|
21050
21282
|
return;
|
|
21051
21283
|
}
|
|
@@ -21297,7 +21529,9 @@ class New {
|
|
|
21297
21529
|
partialState;
|
|
21298
21530
|
index = host_call_handler_tryAsHostCallIndex(18);
|
|
21299
21531
|
basicGasCost = gas_tryAsSmallGas(10);
|
|
21300
|
-
tracedRegisters =
|
|
21532
|
+
tracedRegisters = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
21533
|
+
? traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11, 12)
|
|
21534
|
+
: traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11);
|
|
21301
21535
|
constructor(currentServiceId, partialState) {
|
|
21302
21536
|
this.currentServiceId = currentServiceId;
|
|
21303
21537
|
this.partialState = partialState;
|
|
@@ -21313,16 +21547,18 @@ class New {
|
|
|
21313
21547
|
const allowance = tryAsServiceGas(regs.get(10));
|
|
21314
21548
|
// `f`
|
|
21315
21549
|
const gratisStorage = regs.get(11);
|
|
21550
|
+
// `i`: requested service id. Ignored if current service is not registrar or value is bigger than `S`.
|
|
21551
|
+
const requestedServiceId = regs.get(12);
|
|
21316
21552
|
// `c`
|
|
21317
21553
|
const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
21318
21554
|
const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
|
|
21319
21555
|
// error while reading the memory.
|
|
21320
21556
|
if (memoryReadResult.isError) {
|
|
21321
|
-
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- PANIC`;
|
|
21557
|
+
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
|
|
21322
21558
|
return PvmExecution.Panic;
|
|
21323
21559
|
}
|
|
21324
|
-
const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage);
|
|
21325
|
-
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- ${resultToString(assignedId)}`;
|
|
21560
|
+
const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage, requestedServiceId);
|
|
21561
|
+
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${resultToString(assignedId)}`;
|
|
21326
21562
|
if (assignedId.isOk) {
|
|
21327
21563
|
regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
|
|
21328
21564
|
return;
|
|
@@ -21336,6 +21572,11 @@ class New {
|
|
|
21336
21572
|
regs.set(new_IN_OUT_REG, HostCallResult.HUH);
|
|
21337
21573
|
return;
|
|
21338
21574
|
}
|
|
21575
|
+
// Post 0.7.1
|
|
21576
|
+
if (e === NewServiceError.RegistrarServiceIdAlreadyTaken) {
|
|
21577
|
+
regs.set(new_IN_OUT_REG, HostCallResult.FULL);
|
|
21578
|
+
return;
|
|
21579
|
+
}
|
|
21339
21580
|
debug_assertNever(e);
|
|
21340
21581
|
}
|
|
21341
21582
|
}
|
|
@@ -21705,6 +21946,7 @@ class Yield {
|
|
|
21705
21946
|
|
|
21706
21947
|
|
|
21707
21948
|
|
|
21949
|
+
|
|
21708
21950
|
const fetch_IN_OUT_REG = 7;
|
|
21709
21951
|
/**
|
|
21710
21952
|
* https://graypaper.fluffylabs.dev/#/7e6ff6a/324000324000?v=0.6.7
|
|
@@ -21793,19 +22035,30 @@ class Fetch {
|
|
|
21793
22035
|
const workItem = regs.get(11);
|
|
21794
22036
|
return this.fetch.workItemPayload(workItem);
|
|
21795
22037
|
}
|
|
21796
|
-
if (
|
|
21797
|
-
|
|
21798
|
-
|
|
21799
|
-
|
|
21800
|
-
|
|
21801
|
-
|
|
21802
|
-
|
|
21803
|
-
|
|
21804
|
-
return this.fetch.allTransfers();
|
|
22038
|
+
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
|
|
22039
|
+
if (kind === FetchKind.AllTransfersAndOperands) {
|
|
22040
|
+
return this.fetch.allTransfersAndOperands();
|
|
22041
|
+
}
|
|
22042
|
+
if (kind === FetchKind.OneTransferOrOperand) {
|
|
22043
|
+
const index = regs.get(11);
|
|
22044
|
+
return this.fetch.oneTransferOrOperand(index);
|
|
22045
|
+
}
|
|
21805
22046
|
}
|
|
21806
|
-
|
|
21807
|
-
|
|
21808
|
-
|
|
22047
|
+
else {
|
|
22048
|
+
if (kind === FetchKind.LegacyAllOperands) {
|
|
22049
|
+
return this.fetch.allOperands();
|
|
22050
|
+
}
|
|
22051
|
+
if (kind === FetchKind.LegacyOneOperand) {
|
|
22052
|
+
const index = regs.get(11);
|
|
22053
|
+
return this.fetch.oneOperand(index);
|
|
22054
|
+
}
|
|
22055
|
+
if (kind === FetchKind.LegacyAllTransfers) {
|
|
22056
|
+
return this.fetch.allTransfers();
|
|
22057
|
+
}
|
|
22058
|
+
if (kind === FetchKind.LegacyOneTransfer) {
|
|
22059
|
+
const index = regs.get(11);
|
|
22060
|
+
return this.fetch.oneTransfer(index);
|
|
22061
|
+
}
|
|
21809
22062
|
}
|
|
21810
22063
|
return null;
|
|
21811
22064
|
}
|
|
@@ -21826,10 +22079,12 @@ var FetchKind;
|
|
|
21826
22079
|
FetchKind[FetchKind["AllWorkItems"] = 11] = "AllWorkItems";
|
|
21827
22080
|
FetchKind[FetchKind["OneWorkItem"] = 12] = "OneWorkItem";
|
|
21828
22081
|
FetchKind[FetchKind["WorkItemPayload"] = 13] = "WorkItemPayload";
|
|
21829
|
-
FetchKind[FetchKind["
|
|
21830
|
-
FetchKind[FetchKind["
|
|
21831
|
-
FetchKind[FetchKind["
|
|
21832
|
-
FetchKind[FetchKind["
|
|
22082
|
+
FetchKind[FetchKind["LegacyAllOperands"] = 14] = "LegacyAllOperands";
|
|
22083
|
+
FetchKind[FetchKind["AllTransfersAndOperands"] = 14] = "AllTransfersAndOperands";
|
|
22084
|
+
FetchKind[FetchKind["LegacyOneOperand"] = 15] = "LegacyOneOperand";
|
|
22085
|
+
FetchKind[FetchKind["OneTransferOrOperand"] = 15] = "OneTransferOrOperand";
|
|
22086
|
+
FetchKind[FetchKind["LegacyAllTransfers"] = 16] = "LegacyAllTransfers";
|
|
22087
|
+
FetchKind[FetchKind["LegacyOneTransfer"] = 17] = "LegacyOneTransfer";
|
|
21833
22088
|
})(FetchKind || (FetchKind = {}));
|
|
21834
22089
|
|
|
21835
22090
|
;// CONCATENATED MODULE: ./packages/jam/jam-host-calls/info.ts
|
|
@@ -22526,7 +22781,7 @@ const accumulate_logger = Logger.new(import.meta.filename, "accumulate");
|
|
|
22526
22781
|
const ARGS_CODEC = descriptors_codec.object({
|
|
22527
22782
|
slot: descriptors_codec.varU32.asOpaque(),
|
|
22528
22783
|
serviceId: descriptors_codec.varU32.asOpaque(),
|
|
22529
|
-
|
|
22784
|
+
argsLength: descriptors_codec.varU32,
|
|
22530
22785
|
});
|
|
22531
22786
|
class Accumulate {
|
|
22532
22787
|
chainSpec;
|
|
@@ -22546,7 +22801,7 @@ class Accumulate {
|
|
|
22546
22801
|
const reportsLength = reports.length;
|
|
22547
22802
|
let currentGas = 0n;
|
|
22548
22803
|
for (let i = 0; i < reportsLength; i++) {
|
|
22549
|
-
const report = reports
|
|
22804
|
+
const report = reports.get(i);
|
|
22550
22805
|
const resultsGas = report.results.map((result) => result.gas).reduce((a, b) => a + b, 0n);
|
|
22551
22806
|
if (currentGas + resultsGas > gasLimit) {
|
|
22552
22807
|
return i;
|
|
@@ -22560,7 +22815,7 @@ class Accumulate {
|
|
|
22560
22815
|
*
|
|
22561
22816
|
* https://graypaper.fluffylabs.dev/#/7e6ff6a/2fdb012fdb01?v=0.6.7
|
|
22562
22817
|
*/
|
|
22563
|
-
async pvmAccumulateInvocation(slot, serviceId, operands, gas, entropy, inputStateUpdate) {
|
|
22818
|
+
async pvmAccumulateInvocation(slot, serviceId, transfers, operands, gas, entropy, inputStateUpdate) {
|
|
22564
22819
|
const service = this.state.getService(serviceId);
|
|
22565
22820
|
if (service === null) {
|
|
22566
22821
|
accumulate_logger.log `Service with id ${serviceId} not found.`;
|
|
@@ -22579,14 +22834,21 @@ class Accumulate {
|
|
|
22579
22834
|
}
|
|
22580
22835
|
const nextServiceId = generateNextServiceId({ serviceId, entropy, timeslot: slot }, this.chainSpec, this.blake2b);
|
|
22581
22836
|
const partialState = new AccumulateExternalities(this.chainSpec, this.blake2b, new PartiallyUpdatedState(this.state, inputStateUpdate), serviceId, nextServiceId, slot);
|
|
22837
|
+
const fetchExternalities = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
22838
|
+
? FetchExternalities.createForAccumulate({ entropy, transfers, operands }, this.chainSpec)
|
|
22839
|
+
: FetchExternalities.createForPre071Accumulate({ entropy, operands }, this.chainSpec);
|
|
22582
22840
|
const externalities = {
|
|
22583
22841
|
partialState,
|
|
22584
22842
|
serviceExternalities: partialState,
|
|
22585
|
-
fetchExternalities
|
|
22843
|
+
fetchExternalities,
|
|
22586
22844
|
};
|
|
22587
22845
|
const executor = PvmExecutor.createAccumulateExecutor(serviceId, code, externalities, this.chainSpec);
|
|
22588
|
-
const
|
|
22589
|
-
|
|
22846
|
+
const invocationArgs = encoder_Encoder.encodeObject(ARGS_CODEC, {
|
|
22847
|
+
slot,
|
|
22848
|
+
serviceId,
|
|
22849
|
+
argsLength: numbers_tryAsU32(transfers.length + operands.length),
|
|
22850
|
+
});
|
|
22851
|
+
const result = await executor.run(invocationArgs, tryAsGas(gas));
|
|
22590
22852
|
const [newState, checkpoint] = partialState.getStateUpdates();
|
|
22591
22853
|
/**
|
|
22592
22854
|
* PVM invocation returned and error so we return the checkpoint
|
|
@@ -22623,9 +22885,9 @@ class Accumulate {
|
|
|
22623
22885
|
*
|
|
22624
22886
|
* https://graypaper.fluffylabs.dev/#/7e6ff6a/18d70118d701?v=0.6.7
|
|
22625
22887
|
*/
|
|
22626
|
-
async accumulateSingleService(serviceId, operands, gasCost, slot, entropy, inputStateUpdate) {
|
|
22627
|
-
accumulate_logger.log `Accumulating service ${serviceId},
|
|
22628
|
-
const result = await this.pvmAccumulateInvocation(slot, serviceId, operands, gasCost, entropy, inputStateUpdate);
|
|
22888
|
+
async accumulateSingleService(serviceId, transfers, operands, gasCost, slot, entropy, inputStateUpdate) {
|
|
22889
|
+
accumulate_logger.log `Accumulating service ${serviceId}, transfers: ${transfers.length} operands: ${operands.length} at slot: ${slot}.`;
|
|
22890
|
+
const result = await this.pvmAccumulateInvocation(slot, serviceId, transfers, operands, gasCost, entropy, inputStateUpdate);
|
|
22629
22891
|
if (result.isError) {
|
|
22630
22892
|
// https://graypaper.fluffylabs.dev/#/7e6ff6a/2fb6012fb601?v=0.6.7
|
|
22631
22893
|
accumulate_logger.log `Accumulation failed for ${serviceId}.`;
|
|
@@ -22642,7 +22904,7 @@ class Accumulate {
|
|
|
22642
22904
|
*
|
|
22643
22905
|
* https://graypaper.fluffylabs.dev/#/7e6ff6a/179d00179d00?v=0.6.7
|
|
22644
22906
|
*/
|
|
22645
|
-
async
|
|
22907
|
+
async accumulateSequentiallyLegacy(gasLimit, reports, slot, entropy, statistics, stateUpdate, autoAccumulateServices) {
|
|
22646
22908
|
const i = this.findReportCutoffIndex(gasLimit, reports);
|
|
22647
22909
|
if (i === 0) {
|
|
22648
22910
|
return {
|
|
@@ -22651,14 +22913,46 @@ class Accumulate {
|
|
|
22651
22913
|
state: stateUpdate,
|
|
22652
22914
|
};
|
|
22653
22915
|
}
|
|
22654
|
-
const reportsToAccumulateInParallel = reports.
|
|
22655
|
-
const
|
|
22656
|
-
const
|
|
22657
|
-
const
|
|
22916
|
+
const reportsToAccumulateInParallel = reports.subview(0, i);
|
|
22917
|
+
const accumulateData = new AccumulateData(reportsToAccumulateInParallel, [], autoAccumulateServices);
|
|
22918
|
+
const reportsToAccumulateSequentially = reports.subview(i);
|
|
22919
|
+
const { gasCost, state: stateAfterParallelAcc, ...rest } = await this.accumulateInParallel(accumulateData, slot, entropy, statistics, stateUpdate);
|
|
22920
|
+
assertEmpty(rest);
|
|
22921
|
+
// NOTE [ToDr] recursive invocation
|
|
22922
|
+
const { accumulatedReports, gasCost: seqGasCost, state, ...seqRest } = await this.accumulateSequentiallyLegacy(tryAsServiceGas(gasLimit - gasCost), reportsToAccumulateSequentially, slot, entropy, statistics, stateAfterParallelAcc, []);
|
|
22923
|
+
assertEmpty(seqRest);
|
|
22924
|
+
return {
|
|
22925
|
+
accumulatedReports: numbers_tryAsU32(i + accumulatedReports),
|
|
22926
|
+
gasCost: tryAsServiceGas(gasCost + seqGasCost),
|
|
22927
|
+
state,
|
|
22928
|
+
};
|
|
22929
|
+
}
|
|
22930
|
+
/**
|
|
22931
|
+
* The outer accumulation function ∆+ which transforms a gas-limit, a sequence of work-reports,
|
|
22932
|
+
* an initial partial-state and a dictionary of services enjoying free accumulation,
|
|
22933
|
+
* into a tuple of the number of work-results accumulated, a posterior state-context,
|
|
22934
|
+
* the resultant deferred-transfers and accumulation-output pairing.
|
|
22935
|
+
*
|
|
22936
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/172901172901?v=0.7.2
|
|
22937
|
+
*/
|
|
22938
|
+
async accumulateSequentially(gasLimit, reports, transfers, slot, entropy, statistics, stateUpdate, autoAccumulateServices) {
|
|
22939
|
+
const i = this.findReportCutoffIndex(gasLimit, reports);
|
|
22940
|
+
const n = transfers.length + i + reports.length;
|
|
22941
|
+
if (n === 0) {
|
|
22942
|
+
return {
|
|
22943
|
+
accumulatedReports: numbers_tryAsU32(0),
|
|
22944
|
+
gasCost: tryAsServiceGas(0),
|
|
22945
|
+
state: stateUpdate,
|
|
22946
|
+
};
|
|
22947
|
+
}
|
|
22948
|
+
const reportsToAccumulateInParallel = reports.subview(0, i);
|
|
22949
|
+
const accumulateData = new AccumulateData(reportsToAccumulateInParallel, transfers, autoAccumulateServices);
|
|
22950
|
+
const reportsToAccumulateSequentially = reports.subview(i);
|
|
22658
22951
|
const { gasCost, state: stateAfterParallelAcc, ...rest } = await this.accumulateInParallel(accumulateData, slot, entropy, statistics, stateUpdate);
|
|
22952
|
+
const newTransfers = stateAfterParallelAcc.transfers;
|
|
22659
22953
|
assertEmpty(rest);
|
|
22660
22954
|
// NOTE [ToDr] recursive invocation
|
|
22661
|
-
const { accumulatedReports, gasCost: seqGasCost, state, ...seqRest } = await this.accumulateSequentially(tryAsServiceGas(gasLimit - gasCost), reportsToAccumulateSequentially, slot, entropy, statistics, stateAfterParallelAcc);
|
|
22955
|
+
const { accumulatedReports, gasCost: seqGasCost, state, ...seqRest } = await this.accumulateSequentially(tryAsServiceGas(gasLimit - gasCost), reportsToAccumulateSequentially, newTransfers, slot, entropy, statistics, stateAfterParallelAcc, []);
|
|
22662
22956
|
assertEmpty(seqRest);
|
|
22663
22957
|
return {
|
|
22664
22958
|
accumulatedReports: numbers_tryAsU32(i + accumulatedReports),
|
|
@@ -22674,7 +22968,7 @@ class Accumulate {
|
|
|
22674
22968
|
* into a tuple of the total gas utilized in pvm execution u, a posterior state-context
|
|
22675
22969
|
* and the resultant accumulation-output pairings b and deferred-transfers.
|
|
22676
22970
|
*
|
|
22677
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
22971
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/174602174602?v=0.7.2
|
|
22678
22972
|
*/
|
|
22679
22973
|
async accumulateInParallel(accumulateData, slot, entropy, statistics, inputStateUpdate) {
|
|
22680
22974
|
const serviceIds = accumulateData.getServiceIds();
|
|
@@ -22683,7 +22977,7 @@ class Accumulate {
|
|
|
22683
22977
|
const currentManager = (inputStateUpdate.privilegedServices ?? this.state.privilegedServices).manager;
|
|
22684
22978
|
for (const serviceId of serviceIds) {
|
|
22685
22979
|
const checkpoint = AccumulationStateUpdate.copyFrom(currentState);
|
|
22686
|
-
const { consumedGas, stateUpdate } = await this.accumulateSingleService(serviceId, accumulateData.getOperands(serviceId), accumulateData.getGasCost(serviceId), slot, entropy, currentState);
|
|
22980
|
+
const { consumedGas, stateUpdate } = await this.accumulateSingleService(serviceId, accumulateData.getTransfers(serviceId), accumulateData.getOperands(serviceId), accumulateData.getGasCost(serviceId), slot, entropy, currentState);
|
|
22687
22981
|
gasCost = tryAsServiceGas(gasCost + consumedGas);
|
|
22688
22982
|
const serviceStatistics = statistics.get(serviceId) ?? { count: numbers_tryAsU32(0), gasUsed: tryAsServiceGas(0) };
|
|
22689
22983
|
serviceStatistics.count = numbers_tryAsU32(serviceStatistics.count + accumulateData.getReportsLength(serviceId));
|
|
@@ -22691,17 +22985,17 @@ class Accumulate {
|
|
|
22691
22985
|
statistics.set(serviceId, serviceStatistics);
|
|
22692
22986
|
currentState = stateUpdate === null ? checkpoint : stateUpdate;
|
|
22693
22987
|
if (Compatibility.is(GpVersion.V0_7_0) && serviceId === currentManager) {
|
|
22694
|
-
const newV = currentState.privilegedServices?.
|
|
22988
|
+
const newV = currentState.privilegedServices?.delegator;
|
|
22695
22989
|
if (currentState.privilegedServices !== null && newV !== undefined && serviceIds.includes(newV)) {
|
|
22696
|
-
accumulate_logger.info `Entering completely incorrect code that probably reverts
|
|
22990
|
+
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+`;
|
|
22697
22991
|
// Since serviceIds already contains newV, this service gets accumulated twice.
|
|
22698
22992
|
// To avoid double-counting, we skip stats and gas cost tracking here.
|
|
22699
|
-
// We need this accumulation to get the correct `
|
|
22700
|
-
const { stateUpdate } = await this.accumulateSingleService(newV, accumulateData.getOperands(newV), accumulateData.getGasCost(newV), slot, entropy, checkpoint);
|
|
22701
|
-
const correctV = stateUpdate?.privilegedServices?.
|
|
22993
|
+
// We need this accumulation to get the correct `delegator`
|
|
22994
|
+
const { stateUpdate } = await this.accumulateSingleService(newV, [], accumulateData.getOperands(newV), accumulateData.getGasCost(newV), slot, entropy, checkpoint);
|
|
22995
|
+
const correctV = stateUpdate?.privilegedServices?.delegator ?? this.state.privilegedServices.delegator;
|
|
22702
22996
|
currentState.privilegedServices = PrivilegedServices.create({
|
|
22703
22997
|
...currentState.privilegedServices,
|
|
22704
|
-
|
|
22998
|
+
delegator: correctV,
|
|
22705
22999
|
});
|
|
22706
23000
|
}
|
|
22707
23001
|
}
|
|
@@ -22757,7 +23051,7 @@ class Accumulate {
|
|
|
22757
23051
|
*
|
|
22758
23052
|
* Please note it cannot overflow because we use `BigInt`, and the final result is clamped to `maxBlockGas` (W_G).
|
|
22759
23053
|
*
|
|
22760
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
23054
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/183402184502?v=0.7.2
|
|
22761
23055
|
*/
|
|
22762
23056
|
getGasLimit() {
|
|
22763
23057
|
const calculatedGasLimit = GAS_TO_INVOKE_WORK_REPORT * BigInt(this.chainSpec.coresCount) +
|
|
@@ -22765,6 +23059,20 @@ class Accumulate {
|
|
|
22765
23059
|
const gasLimit = tryAsServiceGas(this.chainSpec.maxBlockGas > calculatedGasLimit ? this.chainSpec.maxBlockGas : calculatedGasLimit);
|
|
22766
23060
|
return tryAsServiceGas(gasLimit);
|
|
22767
23061
|
}
|
|
23062
|
+
hasDuplicatedServicesCreated(updateServices) {
|
|
23063
|
+
const createdServiceIds = new Set();
|
|
23064
|
+
for (const update of updateServices) {
|
|
23065
|
+
if (update.action.kind === UpdateServiceKind.Create) {
|
|
23066
|
+
const serviceId = update.serviceId;
|
|
23067
|
+
if (createdServiceIds.has(serviceId)) {
|
|
23068
|
+
accumulate_logger.log `Duplicated Service creation detected ${serviceId}. Block is invalid.`;
|
|
23069
|
+
return true;
|
|
23070
|
+
}
|
|
23071
|
+
createdServiceIds.add(serviceId);
|
|
23072
|
+
}
|
|
23073
|
+
}
|
|
23074
|
+
return false;
|
|
23075
|
+
}
|
|
22768
23076
|
async transition({ reports, slot, entropy }) {
|
|
22769
23077
|
const statistics = new Map();
|
|
22770
23078
|
const accumulateQueue = new AccumulateQueue(this.chainSpec, this.state);
|
|
@@ -22773,16 +23081,22 @@ class Accumulate {
|
|
|
22773
23081
|
const queueFromState = accumulateQueue.getQueueFromState(slot);
|
|
22774
23082
|
const toEnqueue = pruneQueue(queueFromState.concat(toAccumulateLater), getWorkPackageHashes(toAccumulateImmediately));
|
|
22775
23083
|
const queue = accumulateQueue.enqueueReports(toEnqueue);
|
|
22776
|
-
const accumulatableReports = toAccumulateImmediately.concat(queue);
|
|
23084
|
+
const accumulatableReports = ArrayView.from(toAccumulateImmediately.concat(queue));
|
|
22777
23085
|
const gasLimit = this.getGasLimit();
|
|
22778
|
-
const
|
|
23086
|
+
const autoAccumulateServices = this.state.privilegedServices.autoAccumulateServices;
|
|
23087
|
+
const { accumulatedReports, gasCost, state, ...rest } = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
23088
|
+
? await this.accumulateSequentially(gasLimit, accumulatableReports, [], slot, entropy, statistics, AccumulationStateUpdate.empty(), autoAccumulateServices)
|
|
23089
|
+
: await this.accumulateSequentiallyLegacy(gasLimit, accumulatableReports, slot, entropy, statistics, AccumulationStateUpdate.empty(), autoAccumulateServices);
|
|
22779
23090
|
// we can safely ignore top-level gas cost from accSequentially.
|
|
22780
23091
|
const _gasCost = gasCost;
|
|
22781
23092
|
assertEmpty(rest);
|
|
22782
|
-
const accumulated = accumulatableReports.
|
|
23093
|
+
const accumulated = accumulatableReports.subview(0, accumulatedReports);
|
|
22783
23094
|
const { services, yieldedRoots, transfers, validatorsData, privilegedServices, authorizationQueues, ...stateUpdateRest } = state;
|
|
22784
23095
|
assertEmpty(stateUpdateRest);
|
|
22785
|
-
|
|
23096
|
+
if (this.hasDuplicatedServicesCreated(services.servicesUpdates)) {
|
|
23097
|
+
return result_Result.error(ACCUMULATION_ERROR);
|
|
23098
|
+
}
|
|
23099
|
+
const accStateUpdate = this.getAccumulationStateUpdate(accumulated.toArray(), toAccumulateLater, slot, Array.from(statistics.keys()), services);
|
|
22786
23100
|
const accumulationOutputUnsorted = Array.from(yieldedRoots.entries()).map(([serviceId, root]) => {
|
|
22787
23101
|
return { serviceId, output: root.asOpaque() };
|
|
22788
23102
|
});
|
|
@@ -24414,18 +24728,24 @@ class OnChain {
|
|
|
24414
24728
|
}
|
|
24415
24729
|
const { stateUpdate: accumulateUpdate, accumulationStatistics, pendingTransfers, accumulationOutputLog, ...accumulateRest } = accumulateResult.ok;
|
|
24416
24730
|
assertEmpty(accumulateRest);
|
|
24417
|
-
const { privilegedServices: maybePrivilegedServices, authQueues: maybeAuthorizationQueues, designatedValidatorData: maybeDesignatedValidatorData, preimages: accumulatePreimages, accumulationQueue, recentlyAccumulated, ...
|
|
24418
|
-
|
|
24419
|
-
|
|
24420
|
-
|
|
24421
|
-
|
|
24422
|
-
|
|
24423
|
-
|
|
24424
|
-
|
|
24425
|
-
|
|
24731
|
+
const { privilegedServices: maybePrivilegedServices, authQueues: maybeAuthorizationQueues, designatedValidatorData: maybeDesignatedValidatorData, preimages: accumulatePreimages, accumulationQueue, recentlyAccumulated, ...servicesUpdateFromAccumulate } = accumulateUpdate;
|
|
24732
|
+
let transferStatistics = new Map();
|
|
24733
|
+
let servicesUpdate = { ...servicesUpdateFromAccumulate, preimages: accumulatePreimages };
|
|
24734
|
+
if (Compatibility.isLessThan(GpVersion.V0_7_1)) {
|
|
24735
|
+
const deferredTransfersResult = await this.deferredTransfers.transition({
|
|
24736
|
+
entropy: entropy[0],
|
|
24737
|
+
pendingTransfers,
|
|
24738
|
+
servicesUpdate,
|
|
24739
|
+
timeslot: timeSlot,
|
|
24740
|
+
});
|
|
24741
|
+
if (deferredTransfersResult.isError) {
|
|
24742
|
+
return stfError(StfErrorKind.DeferredTransfers, deferredTransfersResult);
|
|
24743
|
+
}
|
|
24744
|
+
const { servicesUpdate: servicesUpdateFromDeferredTransfers, transferStatistics: transferStatisticsFromDeferredTransfers, ...deferredTransfersRest } = deferredTransfersResult.ok;
|
|
24745
|
+
transferStatistics = transferStatisticsFromDeferredTransfers;
|
|
24746
|
+
servicesUpdate = servicesUpdateFromDeferredTransfers;
|
|
24747
|
+
assertEmpty(deferredTransfersRest);
|
|
24426
24748
|
}
|
|
24427
|
-
const { servicesUpdate: newServicesUpdate, transferStatistics, ...deferredTransfersRest } = deferredTransfersResult.ok;
|
|
24428
|
-
assertEmpty(deferredTransfersRest);
|
|
24429
24749
|
const accumulateRoot = await this.accumulateOutput.transition({ accumulationOutputLog });
|
|
24430
24750
|
// recent history
|
|
24431
24751
|
const recentHistoryUpdate = this.recentHistory.transition({
|
|
@@ -24475,7 +24795,7 @@ class OnChain {
|
|
|
24475
24795
|
accumulationQueue,
|
|
24476
24796
|
recentlyAccumulated,
|
|
24477
24797
|
accumulationOutputLog,
|
|
24478
|
-
...
|
|
24798
|
+
...servicesUpdate,
|
|
24479
24799
|
preimages: preimages.concat(accumulatePreimages),
|
|
24480
24800
|
});
|
|
24481
24801
|
}
|