@typeberry/jam 0.1.3-8fd7637 → 0.1.3-a6eda68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bootstrap-generator.mjs +285 -252
- package/bootstrap-generator.mjs.map +1 -1
- package/bootstrap-importer.mjs +422 -328
- package/bootstrap-importer.mjs.map +1 -1
- package/bootstrap-network.mjs +287 -253
- package/bootstrap-network.mjs.map +1 -1
- package/index.js +505 -331
- package/index.js.map +1 -1
- package/package.json +1 -1
package/bootstrap-importer.mjs
CHANGED
|
@@ -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) => {
|
|
@@ -7628,7 +7631,7 @@ const codecFixedSizeArray = (val, len) => {
|
|
|
7628
7631
|
};
|
|
7629
7632
|
/** Codec for a hash-dictionary. */
|
|
7630
7633
|
const codecHashDictionary = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH, compare = (a, b) => extractKey(a).compare(extractKey(b)), } = {}) => {
|
|
7631
|
-
return
|
|
7634
|
+
return Descriptor.new(`HashDictionary<${value.name}>[?]`, {
|
|
7632
7635
|
bytes: typicalLength * value.sizeHint.bytes,
|
|
7633
7636
|
isExact: false,
|
|
7634
7637
|
}, (e, v) => {
|
|
@@ -9595,6 +9598,13 @@ const W_T = 128;
|
|
|
9595
9598
|
/** `W_M`: The maximum number of exports in a work-package. */
|
|
9596
9599
|
const W_X = 3_072;
|
|
9597
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;
|
|
9598
9608
|
/**
|
|
9599
9609
|
* `J`: The maximum sum of dependency items in a work-report.
|
|
9600
9610
|
*
|
|
@@ -9606,9 +9616,209 @@ const AUTHORIZATION_QUEUE_SIZE = Q;
|
|
|
9606
9616
|
/** `O`: Maximal authorization pool size. */
|
|
9607
9617
|
const MAX_AUTH_POOL_SIZE = O;
|
|
9608
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
|
+
|
|
9609
9816
|
;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
|
|
9610
9817
|
|
|
9611
9818
|
|
|
9819
|
+
|
|
9820
|
+
|
|
9821
|
+
|
|
9612
9822
|
/** Dictionary entry of services that auto-accumulate every block. */
|
|
9613
9823
|
class AutoAccumulate {
|
|
9614
9824
|
service;
|
|
@@ -9630,39 +9840,50 @@ class AutoAccumulate {
|
|
|
9630
9840
|
}
|
|
9631
9841
|
}
|
|
9632
9842
|
/**
|
|
9633
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
9843
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
|
|
9634
9844
|
*/
|
|
9635
9845
|
class PrivilegedServices {
|
|
9636
9846
|
manager;
|
|
9637
|
-
|
|
9638
|
-
|
|
9847
|
+
delegator;
|
|
9848
|
+
registrar;
|
|
9849
|
+
assigners;
|
|
9639
9850
|
autoAccumulateServices;
|
|
9851
|
+
/** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
|
|
9640
9852
|
static Codec = descriptors_codec.Class(PrivilegedServices, {
|
|
9641
9853
|
manager: descriptors_codec.u32.asOpaque(),
|
|
9642
|
-
|
|
9643
|
-
|
|
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)),
|
|
9644
9859
|
autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
|
|
9645
9860
|
});
|
|
9646
|
-
static create(
|
|
9647
|
-
return new PrivilegedServices(manager,
|
|
9861
|
+
static create(a) {
|
|
9862
|
+
return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
9648
9863
|
}
|
|
9649
9864
|
constructor(
|
|
9650
9865
|
/**
|
|
9651
|
-
*
|
|
9652
|
-
* the service able to effect an alteration of χ from block to block,
|
|
9866
|
+
* `χ_M`: Manages alteration of χ from block to block,
|
|
9653
9867
|
* as well as bestow services with storage deposit credits.
|
|
9654
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
9868
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
9655
9869
|
*/
|
|
9656
9870
|
manager,
|
|
9657
|
-
/**
|
|
9658
|
-
|
|
9659
|
-
/**
|
|
9660
|
-
|
|
9661
|
-
|
|
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. */
|
|
9662
9882
|
autoAccumulateServices) {
|
|
9663
9883
|
this.manager = manager;
|
|
9664
|
-
this.
|
|
9665
|
-
this.
|
|
9884
|
+
this.delegator = delegator;
|
|
9885
|
+
this.registrar = registrar;
|
|
9886
|
+
this.assigners = assigners;
|
|
9666
9887
|
this.autoAccumulateServices = autoAccumulateServices;
|
|
9667
9888
|
}
|
|
9668
9889
|
}
|
|
@@ -9750,7 +9971,7 @@ class RecentBlocks extends WithDebug {
|
|
|
9750
9971
|
*/
|
|
9751
9972
|
class RecentBlocksHistory extends WithDebug {
|
|
9752
9973
|
current;
|
|
9753
|
-
static Codec =
|
|
9974
|
+
static Codec = Descriptor.new("RecentBlocksHistory", RecentBlocks.Codec.sizeHint, (encoder, value) => RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
|
|
9754
9975
|
const recentBlocks = RecentBlocks.Codec.decode(decoder);
|
|
9755
9976
|
return RecentBlocksHistory.create(recentBlocks);
|
|
9756
9977
|
}, (skip) => {
|
|
@@ -9947,196 +10168,6 @@ class SafroleData {
|
|
|
9947
10168
|
}
|
|
9948
10169
|
}
|
|
9949
10170
|
|
|
9950
|
-
;// CONCATENATED MODULE: ./packages/jam/state/service.ts
|
|
9951
|
-
|
|
9952
|
-
|
|
9953
|
-
|
|
9954
|
-
|
|
9955
|
-
|
|
9956
|
-
|
|
9957
|
-
/**
|
|
9958
|
-
* `B_S`: The basic minimum balance which all services require.
|
|
9959
|
-
*
|
|
9960
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
9961
|
-
*/
|
|
9962
|
-
const BASE_SERVICE_BALANCE = 100n;
|
|
9963
|
-
/**
|
|
9964
|
-
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
9965
|
-
*
|
|
9966
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
9967
|
-
*/
|
|
9968
|
-
const ELECTIVE_ITEM_BALANCE = 10n;
|
|
9969
|
-
/**
|
|
9970
|
-
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
9971
|
-
*
|
|
9972
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
9973
|
-
*/
|
|
9974
|
-
const ELECTIVE_BYTE_BALANCE = 1n;
|
|
9975
|
-
const zeroSizeHint = {
|
|
9976
|
-
bytes: 0,
|
|
9977
|
-
isExact: true,
|
|
9978
|
-
};
|
|
9979
|
-
/** 0-byte read, return given default value */
|
|
9980
|
-
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
9981
|
-
/** Encode and decode object with leading version number. */
|
|
9982
|
-
const codecWithVersion = (val) => descriptor_Descriptor.new("withVersion", {
|
|
9983
|
-
bytes: val.sizeHint.bytes + 8,
|
|
9984
|
-
isExact: false,
|
|
9985
|
-
}, (e, v) => {
|
|
9986
|
-
e.varU64(0n);
|
|
9987
|
-
val.encode(e, v);
|
|
9988
|
-
}, (d) => {
|
|
9989
|
-
const version = d.varU64();
|
|
9990
|
-
if (version !== 0n) {
|
|
9991
|
-
throw new Error("Non-zero version is not supported!");
|
|
9992
|
-
}
|
|
9993
|
-
return val.decode(d);
|
|
9994
|
-
}, (s) => {
|
|
9995
|
-
s.varU64();
|
|
9996
|
-
val.skip(s);
|
|
9997
|
-
});
|
|
9998
|
-
/**
|
|
9999
|
-
* Service account details.
|
|
10000
|
-
*
|
|
10001
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
|
|
10002
|
-
*/
|
|
10003
|
-
class ServiceAccountInfo extends WithDebug {
|
|
10004
|
-
codeHash;
|
|
10005
|
-
balance;
|
|
10006
|
-
accumulateMinGas;
|
|
10007
|
-
onTransferMinGas;
|
|
10008
|
-
storageUtilisationBytes;
|
|
10009
|
-
gratisStorage;
|
|
10010
|
-
storageUtilisationCount;
|
|
10011
|
-
created;
|
|
10012
|
-
lastAccumulation;
|
|
10013
|
-
parentService;
|
|
10014
|
-
static Codec = descriptors_codec.Class(ServiceAccountInfo, {
|
|
10015
|
-
codeHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
10016
|
-
balance: descriptors_codec.u64,
|
|
10017
|
-
accumulateMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
|
|
10018
|
-
onTransferMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
|
|
10019
|
-
storageUtilisationBytes: descriptors_codec.u64,
|
|
10020
|
-
gratisStorage: descriptors_codec.u64,
|
|
10021
|
-
storageUtilisationCount: descriptors_codec.u32,
|
|
10022
|
-
created: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
|
|
10023
|
-
lastAccumulation: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
|
|
10024
|
-
parentService: descriptors_codec.u32.convert((x) => x, tryAsServiceId),
|
|
10025
|
-
});
|
|
10026
|
-
static create(a) {
|
|
10027
|
-
return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
|
|
10028
|
-
}
|
|
10029
|
-
/**
|
|
10030
|
-
* `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
|
|
10031
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
|
|
10032
|
-
*/
|
|
10033
|
-
static calculateThresholdBalance(items, bytes, gratisStorage) {
|
|
10034
|
-
const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
|
|
10035
|
-
if (storageCost < 0n) {
|
|
10036
|
-
return numbers_tryAsU64(0);
|
|
10037
|
-
}
|
|
10038
|
-
if (storageCost >= 2n ** 64n) {
|
|
10039
|
-
return numbers_tryAsU64(2n ** 64n - 1n);
|
|
10040
|
-
}
|
|
10041
|
-
return numbers_tryAsU64(storageCost);
|
|
10042
|
-
}
|
|
10043
|
-
constructor(
|
|
10044
|
-
/** `a_c`: Hash of the service code. */
|
|
10045
|
-
codeHash,
|
|
10046
|
-
/** `a_b`: Current account balance. */
|
|
10047
|
-
balance,
|
|
10048
|
-
/** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
|
|
10049
|
-
accumulateMinGas,
|
|
10050
|
-
/** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
|
|
10051
|
-
onTransferMinGas,
|
|
10052
|
-
/** `a_o`: Total number of octets in storage. */
|
|
10053
|
-
storageUtilisationBytes,
|
|
10054
|
-
/** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
|
|
10055
|
-
gratisStorage,
|
|
10056
|
-
/** `a_i`: Number of items in storage. */
|
|
10057
|
-
storageUtilisationCount,
|
|
10058
|
-
/** `a_r`: Creation account time slot. */
|
|
10059
|
-
created,
|
|
10060
|
-
/** `a_a`: Most recent accumulation time slot. */
|
|
10061
|
-
lastAccumulation,
|
|
10062
|
-
/** `a_p`: Parent service ID. */
|
|
10063
|
-
parentService) {
|
|
10064
|
-
super();
|
|
10065
|
-
this.codeHash = codeHash;
|
|
10066
|
-
this.balance = balance;
|
|
10067
|
-
this.accumulateMinGas = accumulateMinGas;
|
|
10068
|
-
this.onTransferMinGas = onTransferMinGas;
|
|
10069
|
-
this.storageUtilisationBytes = storageUtilisationBytes;
|
|
10070
|
-
this.gratisStorage = gratisStorage;
|
|
10071
|
-
this.storageUtilisationCount = storageUtilisationCount;
|
|
10072
|
-
this.created = created;
|
|
10073
|
-
this.lastAccumulation = lastAccumulation;
|
|
10074
|
-
this.parentService = parentService;
|
|
10075
|
-
}
|
|
10076
|
-
}
|
|
10077
|
-
class PreimageItem extends WithDebug {
|
|
10078
|
-
hash;
|
|
10079
|
-
blob;
|
|
10080
|
-
static Codec = descriptors_codec.Class(PreimageItem, {
|
|
10081
|
-
hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
10082
|
-
blob: descriptors_codec.blob,
|
|
10083
|
-
});
|
|
10084
|
-
static create({ hash, blob }) {
|
|
10085
|
-
return new PreimageItem(hash, blob);
|
|
10086
|
-
}
|
|
10087
|
-
constructor(hash, blob) {
|
|
10088
|
-
super();
|
|
10089
|
-
this.hash = hash;
|
|
10090
|
-
this.blob = blob;
|
|
10091
|
-
}
|
|
10092
|
-
}
|
|
10093
|
-
class StorageItem extends WithDebug {
|
|
10094
|
-
key;
|
|
10095
|
-
value;
|
|
10096
|
-
static Codec = descriptors_codec.Class(StorageItem, {
|
|
10097
|
-
key: descriptors_codec.blob.convert((i) => i, (o) => opaque_asOpaqueType(o)),
|
|
10098
|
-
value: descriptors_codec.blob,
|
|
10099
|
-
});
|
|
10100
|
-
static create({ key, value }) {
|
|
10101
|
-
return new StorageItem(key, value);
|
|
10102
|
-
}
|
|
10103
|
-
constructor(key, value) {
|
|
10104
|
-
super();
|
|
10105
|
-
this.key = key;
|
|
10106
|
-
this.value = value;
|
|
10107
|
-
}
|
|
10108
|
-
}
|
|
10109
|
-
const MAX_LOOKUP_HISTORY_SLOTS = 3;
|
|
10110
|
-
function tryAsLookupHistorySlots(items) {
|
|
10111
|
-
const knownSize = sized_array_asKnownSize(items);
|
|
10112
|
-
if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
|
|
10113
|
-
throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
|
|
10114
|
-
}
|
|
10115
|
-
return knownSize;
|
|
10116
|
-
}
|
|
10117
|
-
/** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
|
|
10118
|
-
class LookupHistoryItem {
|
|
10119
|
-
hash;
|
|
10120
|
-
length;
|
|
10121
|
-
slots;
|
|
10122
|
-
constructor(hash, length,
|
|
10123
|
-
/**
|
|
10124
|
-
* Preimage availability history as a sequence of time slots.
|
|
10125
|
-
* See PreimageStatus and the following GP fragment for more details.
|
|
10126
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
|
|
10127
|
-
slots) {
|
|
10128
|
-
this.hash = hash;
|
|
10129
|
-
this.length = length;
|
|
10130
|
-
this.slots = slots;
|
|
10131
|
-
}
|
|
10132
|
-
static isRequested(item) {
|
|
10133
|
-
if ("slots" in item) {
|
|
10134
|
-
return item.slots.length === 0;
|
|
10135
|
-
}
|
|
10136
|
-
return item.length === 0;
|
|
10137
|
-
}
|
|
10138
|
-
}
|
|
10139
|
-
|
|
10140
10171
|
;// CONCATENATED MODULE: ./packages/jam/state/state.ts
|
|
10141
10172
|
/**
|
|
10142
10173
|
* In addition to the entropy accumulator η_0, we retain
|
|
@@ -10573,6 +10604,7 @@ class StatisticsData {
|
|
|
10573
10604
|
|
|
10574
10605
|
|
|
10575
10606
|
|
|
10607
|
+
|
|
10576
10608
|
|
|
10577
10609
|
|
|
10578
10610
|
var in_memory_state_UpdateError;
|
|
@@ -10976,8 +11008,9 @@ class InMemoryState extends WithDebug {
|
|
|
10976
11008
|
epochRoot: bytes_Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
10977
11009
|
privilegedServices: PrivilegedServices.create({
|
|
10978
11010
|
manager: tryAsServiceId(0),
|
|
10979
|
-
|
|
10980
|
-
|
|
11011
|
+
assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
|
|
11012
|
+
delegator: tryAsServiceId(0),
|
|
11013
|
+
registrar: tryAsServiceId(MAX_VALUE),
|
|
10981
11014
|
autoAccumulateServices: [],
|
|
10982
11015
|
}),
|
|
10983
11016
|
accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
|
|
@@ -11213,7 +11246,7 @@ var serialize;
|
|
|
11213
11246
|
* determine the boundary of the bytes, so it can only be used
|
|
11214
11247
|
* as the last element of the codec and can't be used in sequences!
|
|
11215
11248
|
*/
|
|
11216
|
-
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()));
|
|
11217
11250
|
|
|
11218
11251
|
;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
|
|
11219
11252
|
|
|
@@ -12524,7 +12557,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
|
|
|
12524
12557
|
}
|
|
12525
12558
|
return Ordering.Equal;
|
|
12526
12559
|
}, } = {}) => {
|
|
12527
|
-
return
|
|
12560
|
+
return Descriptor.new(`Map<${value.name}>[?]`, {
|
|
12528
12561
|
bytes: typicalLength * value.sizeHint.bytes,
|
|
12529
12562
|
isExact: false,
|
|
12530
12563
|
}, (e, v) => {
|
|
@@ -15113,11 +15146,17 @@ class AccumulationStateUpdate {
|
|
|
15113
15146
|
if (from.privilegedServices !== null) {
|
|
15114
15147
|
update.privilegedServices = PrivilegedServices.create({
|
|
15115
15148
|
...from.privilegedServices,
|
|
15116
|
-
|
|
15149
|
+
assigners: sized_array_asKnownSize([...from.privilegedServices.assigners]),
|
|
15117
15150
|
});
|
|
15118
15151
|
}
|
|
15119
15152
|
return update;
|
|
15120
15153
|
}
|
|
15154
|
+
/** Retrieve and clear pending transfers. */
|
|
15155
|
+
takeTransfers() {
|
|
15156
|
+
const transfers = this.transfers;
|
|
15157
|
+
this.transfers = [];
|
|
15158
|
+
return transfers;
|
|
15159
|
+
}
|
|
15121
15160
|
}
|
|
15122
15161
|
class PartiallyUpdatedState {
|
|
15123
15162
|
state;
|
|
@@ -17252,13 +17291,6 @@ class BitOps {
|
|
|
17252
17291
|
}
|
|
17253
17292
|
}
|
|
17254
17293
|
|
|
17255
|
-
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
|
|
17256
|
-
const MAX_VALUE = 4294967295;
|
|
17257
|
-
const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
|
|
17258
|
-
const MIN_VALUE = -(2 ** 31);
|
|
17259
|
-
const MAX_SHIFT_U32 = 32;
|
|
17260
|
-
const MAX_SHIFT_U64 = 64n;
|
|
17261
|
-
|
|
17262
17294
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-utils.ts
|
|
17263
17295
|
|
|
17264
17296
|
|
|
@@ -19288,6 +19320,8 @@ var NewServiceError;
|
|
|
19288
19320
|
NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
|
|
19289
19321
|
/** Service is not privileged to set gratis storage. */
|
|
19290
19322
|
NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
|
|
19323
|
+
/** Registrar attempting to create a service with already existing id. */
|
|
19324
|
+
NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
|
|
19291
19325
|
})(NewServiceError || (NewServiceError = {}));
|
|
19292
19326
|
var UpdatePrivilegesError;
|
|
19293
19327
|
(function (UpdatePrivilegesError) {
|
|
@@ -19424,7 +19458,7 @@ const HostCallResult = {
|
|
|
19424
19458
|
OOB: numbers_tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
|
|
19425
19459
|
/** Index unknown. */
|
|
19426
19460
|
WHO: numbers_tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
|
|
19427
|
-
/** Storage full. */
|
|
19461
|
+
/** Storage full or resource already allocated. */
|
|
19428
19462
|
FULL: numbers_tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
|
|
19429
19463
|
/** Core index unknown. */
|
|
19430
19464
|
CORE: numbers_tryAsU64(0xfffffffffffffffan), // 2**64 - 6
|
|
@@ -19432,7 +19466,7 @@ const HostCallResult = {
|
|
|
19432
19466
|
CASH: numbers_tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
|
|
19433
19467
|
/** Gas limit too low. */
|
|
19434
19468
|
LOW: numbers_tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
|
|
19435
|
-
/** The item is already solicited
|
|
19469
|
+
/** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
|
|
19436
19470
|
HUH: numbers_tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
|
|
19437
19471
|
/** The return value indicating general success. */
|
|
19438
19472
|
OK: numbers_tryAsU64(0n),
|
|
@@ -19486,6 +19520,7 @@ function clampU64ToU32(value) {
|
|
|
19486
19520
|
|
|
19487
19521
|
|
|
19488
19522
|
|
|
19523
|
+
|
|
19489
19524
|
/**
|
|
19490
19525
|
* Number of storage items required for ejection of the service.
|
|
19491
19526
|
*
|
|
@@ -19577,10 +19612,13 @@ class AccumulateExternalities {
|
|
|
19577
19612
|
const isExpired = status.data[1] < t - this.chainSpec.preimageExpungePeriod;
|
|
19578
19613
|
return [isExpired, isExpired ? "" : "not expired"];
|
|
19579
19614
|
}
|
|
19580
|
-
/** `check`: https://graypaper.fluffylabs.dev/#/
|
|
19615
|
+
/** `check`: https://graypaper.fluffylabs.dev/#/ab2cdbd/30c60330c603?v=0.7.2 */
|
|
19581
19616
|
getNextAvailableServiceId(serviceId) {
|
|
19582
19617
|
let currentServiceId = serviceId;
|
|
19583
|
-
const mod =
|
|
19618
|
+
const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
19619
|
+
? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
|
|
19620
|
+
: 2 ** 32 - 2 ** 9;
|
|
19621
|
+
const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
|
|
19584
19622
|
for (;;) {
|
|
19585
19623
|
const service = this.getServiceInfo(currentServiceId);
|
|
19586
19624
|
// we found an empty id
|
|
@@ -19588,7 +19626,7 @@ class AccumulateExternalities {
|
|
|
19588
19626
|
return currentServiceId;
|
|
19589
19627
|
}
|
|
19590
19628
|
// keep trying
|
|
19591
|
-
currentServiceId = tryAsServiceId(((currentServiceId -
|
|
19629
|
+
currentServiceId = tryAsServiceId(((currentServiceId - offset + 1 + mod) % mod) + offset);
|
|
19592
19630
|
}
|
|
19593
19631
|
}
|
|
19594
19632
|
checkPreimageStatus(hash, length) {
|
|
@@ -19745,8 +19783,7 @@ class AccumulateExternalities {
|
|
|
19745
19783
|
}));
|
|
19746
19784
|
return result_Result.ok(result_OK);
|
|
19747
19785
|
}
|
|
19748
|
-
newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage) {
|
|
19749
|
-
const newServiceId = this.nextNewServiceId;
|
|
19786
|
+
newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage, wantedServiceId) {
|
|
19750
19787
|
// calculate the threshold. Storage is empty, one preimage requested.
|
|
19751
19788
|
// https://graypaper.fluffylabs.dev/#/7e6ff6a/115901115901?v=0.6.7
|
|
19752
19789
|
const items = numbers_tryAsU32(2 * 1 + 0);
|
|
@@ -19767,30 +19804,59 @@ class AccumulateExternalities {
|
|
|
19767
19804
|
if (balanceLeftForCurrent < thresholdForCurrent || bytes.overflow) {
|
|
19768
19805
|
return result_Result.error(NewServiceError.InsufficientFunds);
|
|
19769
19806
|
}
|
|
19807
|
+
// `a`: https://graypaper.fluffylabs.dev/#/ab2cdbd/366b02366d02?v=0.7.2
|
|
19808
|
+
const newAccount = ServiceAccountInfo.create({
|
|
19809
|
+
codeHash,
|
|
19810
|
+
balance: thresholdForNew,
|
|
19811
|
+
accumulateMinGas,
|
|
19812
|
+
onTransferMinGas,
|
|
19813
|
+
storageUtilisationBytes: bytes.value,
|
|
19814
|
+
storageUtilisationCount: items,
|
|
19815
|
+
gratisStorage,
|
|
19816
|
+
created: this.currentTimeslot,
|
|
19817
|
+
lastAccumulation: common_tryAsTimeSlot(0),
|
|
19818
|
+
parentService: this.currentServiceId,
|
|
19819
|
+
});
|
|
19820
|
+
const newLookupItem = new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([]));
|
|
19821
|
+
// `s`: https://graypaper.fluffylabs.dev/#/ab2cdbd/361003361003?v=0.7.2
|
|
19822
|
+
const updatedCurrentAccount = ServiceAccountInfo.create({
|
|
19823
|
+
...currentService,
|
|
19824
|
+
balance: numbers_tryAsU64(balanceLeftForCurrent),
|
|
19825
|
+
});
|
|
19826
|
+
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
|
|
19827
|
+
if (wantedServiceId < MIN_PUBLIC_SERVICE_INDEX &&
|
|
19828
|
+
this.currentServiceId === this.updatedState.getPrivilegedServices().registrar) {
|
|
19829
|
+
// NOTE: It's safe to cast to `Number` here, bcs here service ID cannot be bigger than 2**16
|
|
19830
|
+
const newServiceId = tryAsServiceId(Number(wantedServiceId));
|
|
19831
|
+
if (this.getServiceInfo(newServiceId) !== null) {
|
|
19832
|
+
return result_Result.error(NewServiceError.RegistrarServiceIdAlreadyTaken);
|
|
19833
|
+
}
|
|
19834
|
+
// add the new service with selected ID
|
|
19835
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36be0336c003?v=0.7.2
|
|
19836
|
+
this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
|
|
19837
|
+
serviceId: newServiceId,
|
|
19838
|
+
serviceInfo: newAccount,
|
|
19839
|
+
lookupHistory: newLookupItem,
|
|
19840
|
+
}));
|
|
19841
|
+
// update the balance of current service
|
|
19842
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36c20336c403?v=0.7.2
|
|
19843
|
+
this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
|
|
19844
|
+
return result_Result.ok(newServiceId);
|
|
19845
|
+
}
|
|
19846
|
+
// NOTE: in case the service is not a registrar or the requested serviceId is out of range,
|
|
19847
|
+
// we completely ignore the `wantedServiceId` and assign a random one
|
|
19848
|
+
}
|
|
19849
|
+
const newServiceId = this.nextNewServiceId;
|
|
19770
19850
|
// add the new service
|
|
19771
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
19851
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36e70336e903?v=0.7.2
|
|
19772
19852
|
this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
|
|
19773
19853
|
serviceId: newServiceId,
|
|
19774
|
-
serviceInfo:
|
|
19775
|
-
|
|
19776
|
-
balance: thresholdForNew,
|
|
19777
|
-
accumulateMinGas,
|
|
19778
|
-
onTransferMinGas,
|
|
19779
|
-
storageUtilisationBytes: bytes.value,
|
|
19780
|
-
storageUtilisationCount: items,
|
|
19781
|
-
gratisStorage,
|
|
19782
|
-
created: this.currentTimeslot,
|
|
19783
|
-
lastAccumulation: common_tryAsTimeSlot(0),
|
|
19784
|
-
parentService: this.currentServiceId,
|
|
19785
|
-
}),
|
|
19786
|
-
lookupHistory: new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([])),
|
|
19854
|
+
serviceInfo: newAccount,
|
|
19855
|
+
lookupHistory: newLookupItem,
|
|
19787
19856
|
}));
|
|
19788
19857
|
// update the balance of current service
|
|
19789
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
19790
|
-
this.updatedState.updateServiceInfo(this.currentServiceId,
|
|
19791
|
-
...currentService,
|
|
19792
|
-
balance: numbers_tryAsU64(balanceLeftForCurrent),
|
|
19793
|
-
}));
|
|
19858
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36ec0336ee03?v=0.7.2
|
|
19859
|
+
this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
|
|
19794
19860
|
// update the next service id we are going to create next
|
|
19795
19861
|
// https://graypaper.fluffylabs.dev/#/7e6ff6a/36a70336a703?v=0.6.7
|
|
19796
19862
|
this.nextNewServiceId = this.getNextAvailableServiceId(bumpServiceId(newServiceId));
|
|
@@ -19808,9 +19874,9 @@ class AccumulateExternalities {
|
|
|
19808
19874
|
}
|
|
19809
19875
|
updateValidatorsData(validatorsData) {
|
|
19810
19876
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/362802362d02?v=0.6.7 */
|
|
19811
|
-
const
|
|
19812
|
-
if (
|
|
19813
|
-
accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${
|
|
19877
|
+
const currentDelegator = this.updatedState.getPrivilegedServices().delegator;
|
|
19878
|
+
if (currentDelegator !== this.currentServiceId) {
|
|
19879
|
+
accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${currentDelegator}) and cannot update validators data. Ignoring`;
|
|
19814
19880
|
return result_Result.error(UnprivilegedError);
|
|
19815
19881
|
}
|
|
19816
19882
|
this.updatedState.stateUpdate.validatorsData = validatorsData;
|
|
@@ -19820,34 +19886,38 @@ class AccumulateExternalities {
|
|
|
19820
19886
|
/** https://graypaper.fluffylabs.dev/#/9a08063/362202362202?v=0.6.6 */
|
|
19821
19887
|
this.checkpointedState = AccumulationStateUpdate.copyFrom(this.updatedState.stateUpdate);
|
|
19822
19888
|
}
|
|
19823
|
-
updateAuthorizationQueue(coreIndex, authQueue,
|
|
19889
|
+
updateAuthorizationQueue(coreIndex, authQueue, assigners) {
|
|
19824
19890
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/36a40136a401?v=0.6.7 */
|
|
19825
19891
|
// NOTE `coreIndex` is already verified in the HC, so this is infallible.
|
|
19826
|
-
const
|
|
19827
|
-
if (
|
|
19828
|
-
accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not an auth manager of core ${coreIndex} (expected: ${
|
|
19892
|
+
const currentAssigners = this.updatedState.getPrivilegedServices().assigners[coreIndex];
|
|
19893
|
+
if (currentAssigners !== this.currentServiceId) {
|
|
19894
|
+
accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not an auth manager of core ${coreIndex} (expected: ${currentAssigners}) and cannot update authorization queue.`;
|
|
19829
19895
|
return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
|
|
19830
19896
|
}
|
|
19831
|
-
if (
|
|
19832
|
-
accumulate_externalities_logger.trace `The new auth manager is not a valid service id
|
|
19897
|
+
if (assigners === null && Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
|
|
19898
|
+
accumulate_externalities_logger.trace `The new auth manager is not a valid service id.`;
|
|
19833
19899
|
return result_Result.error(UpdatePrivilegesError.InvalidServiceId);
|
|
19834
19900
|
}
|
|
19835
19901
|
this.updatedState.stateUpdate.authorizationQueues.set(coreIndex, authQueue);
|
|
19836
19902
|
return result_Result.ok(result_OK);
|
|
19837
19903
|
}
|
|
19838
|
-
updatePrivilegedServices(manager, authorizers,
|
|
19904
|
+
updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate) {
|
|
19839
19905
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/36d90036de00?v=0.6.7 */
|
|
19840
19906
|
const currentManager = this.updatedState.getPrivilegedServices().manager;
|
|
19841
19907
|
if (currentManager !== this.currentServiceId) {
|
|
19842
19908
|
return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
|
|
19843
19909
|
}
|
|
19844
|
-
if (manager === null ||
|
|
19845
|
-
return result_Result.error(UpdatePrivilegesError.InvalidServiceId);
|
|
19910
|
+
if (manager === null || delegator === null) {
|
|
19911
|
+
return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Either manager or delegator is not valid service id.");
|
|
19912
|
+
}
|
|
19913
|
+
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && registrar === null) {
|
|
19914
|
+
return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Register manager is not valid service id.");
|
|
19846
19915
|
}
|
|
19847
19916
|
this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
|
|
19848
19917
|
manager,
|
|
19849
|
-
|
|
19850
|
-
|
|
19918
|
+
assigners: authorizers,
|
|
19919
|
+
delegator,
|
|
19920
|
+
registrar: registrar ?? tryAsServiceId(0), // introduced in 0.7.1
|
|
19851
19921
|
autoAccumulateServices: autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit })),
|
|
19852
19922
|
});
|
|
19853
19923
|
return result_Result.ok(result_OK);
|
|
@@ -19963,8 +20033,11 @@ class AccumulateExternalities {
|
|
|
19963
20033
|
}
|
|
19964
20034
|
}
|
|
19965
20035
|
function bumpServiceId(serviceId) {
|
|
19966
|
-
const mod =
|
|
19967
|
-
|
|
20036
|
+
const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
20037
|
+
? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
|
|
20038
|
+
: 2 ** 32 - 2 ** 9;
|
|
20039
|
+
const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
|
|
20040
|
+
return tryAsServiceId(offset + ((serviceId - offset + 42 + mod) % mod));
|
|
19968
20041
|
}
|
|
19969
20042
|
|
|
19970
20043
|
;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-state.ts
|
|
@@ -20620,6 +20693,8 @@ class AccumulateData {
|
|
|
20620
20693
|
|
|
20621
20694
|
|
|
20622
20695
|
|
|
20696
|
+
|
|
20697
|
+
|
|
20623
20698
|
/**
|
|
20624
20699
|
* A function that removes duplicates but does not change order - it keeps the first occurence.
|
|
20625
20700
|
*/
|
|
@@ -20649,7 +20724,7 @@ const NEXT_ID_CODEC = descriptors_codec.object({
|
|
|
20649
20724
|
*
|
|
20650
20725
|
* Please not that it does not call `check` function!
|
|
20651
20726
|
*
|
|
20652
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
20727
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/2fa9042fc304?v=0.7.2
|
|
20653
20728
|
*/
|
|
20654
20729
|
function generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blake2b) {
|
|
20655
20730
|
const encoded = encoder_Encoder.encodeObject(NEXT_ID_CODEC, {
|
|
@@ -20659,7 +20734,11 @@ function generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blak
|
|
|
20659
20734
|
}, chainSpec);
|
|
20660
20735
|
const result = blake2b.hashBytes(encoded).raw.subarray(0, 4);
|
|
20661
20736
|
const number = leBytesAsU32(result) >>> 0;
|
|
20662
|
-
|
|
20737
|
+
const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
20738
|
+
? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
|
|
20739
|
+
: 2 ** 32 - 2 ** 9;
|
|
20740
|
+
const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
|
|
20741
|
+
return tryAsServiceId((number % mod) + offset);
|
|
20663
20742
|
}
|
|
20664
20743
|
|
|
20665
20744
|
;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-queue.ts
|
|
@@ -21071,7 +21150,7 @@ class Assign {
|
|
|
21071
21150
|
// o
|
|
21072
21151
|
const authorizationQueueStart = regs.get(8);
|
|
21073
21152
|
// a
|
|
21074
|
-
const
|
|
21153
|
+
const assigners = getServiceId(regs.get(9));
|
|
21075
21154
|
const res = safeAllocUint8Array(hash_HASH_SIZE * AUTHORIZATION_QUEUE_SIZE);
|
|
21076
21155
|
const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
|
|
21077
21156
|
// error while reading the memory.
|
|
@@ -21088,7 +21167,7 @@ class Assign {
|
|
|
21088
21167
|
const decoder = decoder_Decoder.fromBlob(res);
|
|
21089
21168
|
const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE), AUTHORIZATION_QUEUE_SIZE);
|
|
21090
21169
|
const fixedSizeAuthQueue = FixedSizeArray.new(authQueue, AUTHORIZATION_QUEUE_SIZE);
|
|
21091
|
-
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue,
|
|
21170
|
+
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
|
|
21092
21171
|
if (result.isOk) {
|
|
21093
21172
|
regs.set(IN_OUT_REG, HostCallResult.OK);
|
|
21094
21173
|
logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
|
|
@@ -21137,7 +21216,9 @@ class Bless {
|
|
|
21137
21216
|
chainSpec;
|
|
21138
21217
|
index = host_call_handler_tryAsHostCallIndex(14);
|
|
21139
21218
|
basicGasCost = gas_tryAsSmallGas(10);
|
|
21140
|
-
tracedRegisters =
|
|
21219
|
+
tracedRegisters = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
21220
|
+
? traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11, 12)
|
|
21221
|
+
: traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11);
|
|
21141
21222
|
constructor(currentServiceId, partialState, chainSpec) {
|
|
21142
21223
|
this.currentServiceId = currentServiceId;
|
|
21143
21224
|
this.partialState = partialState;
|
|
@@ -21147,14 +21228,17 @@ class Bless {
|
|
|
21147
21228
|
// `m`: manager service (can change privileged services)
|
|
21148
21229
|
const manager = getServiceId(regs.get(bless_IN_OUT_REG));
|
|
21149
21230
|
// `a`: manages authorization queue
|
|
21150
|
-
// NOTE It can be either ServiceId (pre GP 067) or memory index (GP ^067)
|
|
21151
21231
|
const authorization = regs.get(8);
|
|
21152
21232
|
// `v`: manages validator keys
|
|
21153
|
-
const
|
|
21233
|
+
const delegator = getServiceId(regs.get(9));
|
|
21234
|
+
// `r`: manages creation of new services with id within protected range
|
|
21235
|
+
const registrar = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
21236
|
+
? getServiceId(regs.get(10))
|
|
21237
|
+
: tryAsServiceId(2 ** 32 - 1);
|
|
21154
21238
|
// `o`: memory offset
|
|
21155
|
-
const sourceStart = regs.get(10);
|
|
21239
|
+
const sourceStart = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? regs.get(11) : regs.get(10);
|
|
21156
21240
|
// `n`: number of items in the auto-accumulate dictionary
|
|
21157
|
-
const numberOfItems = regs.get(11);
|
|
21241
|
+
const numberOfItems = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? regs.get(12) : regs.get(11);
|
|
21158
21242
|
/*
|
|
21159
21243
|
* `z`: array of key-value pairs serviceId -> gas that auto-accumulate every block
|
|
21160
21244
|
* https://graypaper.fluffylabs.dev/#/7e6ff6a/368100368100?v=0.6.7
|
|
@@ -21168,7 +21252,7 @@ class Bless {
|
|
|
21168
21252
|
decoder.resetTo(0);
|
|
21169
21253
|
const memoryReadResult = memory.loadInto(result, memIndex);
|
|
21170
21254
|
if (memoryReadResult.isError) {
|
|
21171
|
-
logger_logger.trace `BLESS(${manager}, ${
|
|
21255
|
+
logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}) <- PANIC`;
|
|
21172
21256
|
return PvmExecution.Panic;
|
|
21173
21257
|
}
|
|
21174
21258
|
const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
|
|
@@ -21181,24 +21265,25 @@ class Bless {
|
|
|
21181
21265
|
const authorizersDecoder = decoder_Decoder.fromBlob(res);
|
|
21182
21266
|
const memoryReadResult = memory.loadInto(res, authorization);
|
|
21183
21267
|
if (memoryReadResult.isError) {
|
|
21184
|
-
logger_logger.trace `BLESS(${manager}, ${
|
|
21268
|
+
logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- PANIC`;
|
|
21185
21269
|
return PvmExecution.Panic;
|
|
21186
21270
|
}
|
|
21271
|
+
// `a`
|
|
21187
21272
|
const authorizers = tryAsPerCore(authorizersDecoder.sequenceFixLen(descriptors_codec.u32.asOpaque(), this.chainSpec.coresCount), this.chainSpec);
|
|
21188
|
-
const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers,
|
|
21273
|
+
const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulateEntries);
|
|
21189
21274
|
if (updateResult.isOk) {
|
|
21190
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
21275
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- OK`;
|
|
21191
21276
|
regs.set(bless_IN_OUT_REG, HostCallResult.OK);
|
|
21192
21277
|
return;
|
|
21193
21278
|
}
|
|
21194
21279
|
const e = updateResult.error;
|
|
21195
21280
|
if (e === UpdatePrivilegesError.UnprivilegedService) {
|
|
21196
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
21281
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- HUH`;
|
|
21197
21282
|
regs.set(bless_IN_OUT_REG, HostCallResult.HUH);
|
|
21198
21283
|
return;
|
|
21199
21284
|
}
|
|
21200
21285
|
if (e === UpdatePrivilegesError.InvalidServiceId) {
|
|
21201
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
21286
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- WHO`;
|
|
21202
21287
|
regs.set(bless_IN_OUT_REG, HostCallResult.WHO);
|
|
21203
21288
|
return;
|
|
21204
21289
|
}
|
|
@@ -21450,7 +21535,9 @@ class New {
|
|
|
21450
21535
|
partialState;
|
|
21451
21536
|
index = host_call_handler_tryAsHostCallIndex(18);
|
|
21452
21537
|
basicGasCost = gas_tryAsSmallGas(10);
|
|
21453
|
-
tracedRegisters =
|
|
21538
|
+
tracedRegisters = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
21539
|
+
? traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11, 12)
|
|
21540
|
+
: traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11);
|
|
21454
21541
|
constructor(currentServiceId, partialState) {
|
|
21455
21542
|
this.currentServiceId = currentServiceId;
|
|
21456
21543
|
this.partialState = partialState;
|
|
@@ -21466,16 +21553,18 @@ class New {
|
|
|
21466
21553
|
const allowance = tryAsServiceGas(regs.get(10));
|
|
21467
21554
|
// `f`
|
|
21468
21555
|
const gratisStorage = regs.get(11);
|
|
21556
|
+
// `i`: requested service id. Ignored if current service is not registrar or value is bigger than `S`.
|
|
21557
|
+
const requestedServiceId = regs.get(12);
|
|
21469
21558
|
// `c`
|
|
21470
21559
|
const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
21471
21560
|
const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
|
|
21472
21561
|
// error while reading the memory.
|
|
21473
21562
|
if (memoryReadResult.isError) {
|
|
21474
|
-
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- PANIC`;
|
|
21563
|
+
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
|
|
21475
21564
|
return PvmExecution.Panic;
|
|
21476
21565
|
}
|
|
21477
|
-
const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage);
|
|
21478
|
-
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- ${resultToString(assignedId)}`;
|
|
21566
|
+
const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage, requestedServiceId);
|
|
21567
|
+
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${resultToString(assignedId)}`;
|
|
21479
21568
|
if (assignedId.isOk) {
|
|
21480
21569
|
regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
|
|
21481
21570
|
return;
|
|
@@ -21489,6 +21578,11 @@ class New {
|
|
|
21489
21578
|
regs.set(new_IN_OUT_REG, HostCallResult.HUH);
|
|
21490
21579
|
return;
|
|
21491
21580
|
}
|
|
21581
|
+
// Post 0.7.1
|
|
21582
|
+
if (e === NewServiceError.RegistrarServiceIdAlreadyTaken) {
|
|
21583
|
+
regs.set(new_IN_OUT_REG, HostCallResult.FULL);
|
|
21584
|
+
return;
|
|
21585
|
+
}
|
|
21492
21586
|
debug_assertNever(e);
|
|
21493
21587
|
}
|
|
21494
21588
|
}
|
|
@@ -22746,7 +22840,7 @@ class Accumulate {
|
|
|
22746
22840
|
}
|
|
22747
22841
|
const nextServiceId = generateNextServiceId({ serviceId, entropy, timeslot: slot }, this.chainSpec, this.blake2b);
|
|
22748
22842
|
const partialState = new AccumulateExternalities(this.chainSpec, this.blake2b, new PartiallyUpdatedState(this.state, inputStateUpdate), serviceId, nextServiceId, slot);
|
|
22749
|
-
const fetchExternalities = Compatibility.isGreaterOrEqual(GpVersion.
|
|
22843
|
+
const fetchExternalities = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
22750
22844
|
? FetchExternalities.createForAccumulate({ entropy, transfers, operands }, this.chainSpec)
|
|
22751
22845
|
: FetchExternalities.createForPre071Accumulate({ entropy, operands }, this.chainSpec);
|
|
22752
22846
|
const externalities = {
|
|
@@ -22861,7 +22955,7 @@ class Accumulate {
|
|
|
22861
22955
|
const accumulateData = new AccumulateData(reportsToAccumulateInParallel, transfers, autoAccumulateServices);
|
|
22862
22956
|
const reportsToAccumulateSequentially = reports.subview(i);
|
|
22863
22957
|
const { gasCost, state: stateAfterParallelAcc, ...rest } = await this.accumulateInParallel(accumulateData, slot, entropy, statistics, stateUpdate);
|
|
22864
|
-
const newTransfers = stateAfterParallelAcc.
|
|
22958
|
+
const newTransfers = stateAfterParallelAcc.takeTransfers();
|
|
22865
22959
|
assertEmpty(rest);
|
|
22866
22960
|
// NOTE [ToDr] recursive invocation
|
|
22867
22961
|
const { accumulatedReports, gasCost: seqGasCost, state, ...seqRest } = await this.accumulateSequentially(tryAsServiceGas(gasLimit - gasCost), reportsToAccumulateSequentially, newTransfers, slot, entropy, statistics, stateAfterParallelAcc, []);
|
|
@@ -22897,17 +22991,17 @@ class Accumulate {
|
|
|
22897
22991
|
statistics.set(serviceId, serviceStatistics);
|
|
22898
22992
|
currentState = stateUpdate === null ? checkpoint : stateUpdate;
|
|
22899
22993
|
if (Compatibility.is(GpVersion.V0_7_0) && serviceId === currentManager) {
|
|
22900
|
-
const newV = currentState.privilegedServices?.
|
|
22994
|
+
const newV = currentState.privilegedServices?.delegator;
|
|
22901
22995
|
if (currentState.privilegedServices !== null && newV !== undefined && serviceIds.includes(newV)) {
|
|
22902
|
-
accumulate_logger.info `Entering completely incorrect code that probably reverts
|
|
22996
|
+
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+`;
|
|
22903
22997
|
// Since serviceIds already contains newV, this service gets accumulated twice.
|
|
22904
22998
|
// To avoid double-counting, we skip stats and gas cost tracking here.
|
|
22905
|
-
// We need this accumulation to get the correct `
|
|
22999
|
+
// We need this accumulation to get the correct `delegator`
|
|
22906
23000
|
const { stateUpdate } = await this.accumulateSingleService(newV, [], accumulateData.getOperands(newV), accumulateData.getGasCost(newV), slot, entropy, checkpoint);
|
|
22907
|
-
const correctV = stateUpdate?.privilegedServices?.
|
|
23001
|
+
const correctV = stateUpdate?.privilegedServices?.delegator ?? this.state.privilegedServices.delegator;
|
|
22908
23002
|
currentState.privilegedServices = PrivilegedServices.create({
|
|
22909
23003
|
...currentState.privilegedServices,
|
|
22910
|
-
|
|
23004
|
+
delegator: correctV,
|
|
22911
23005
|
});
|
|
22912
23006
|
}
|
|
22913
23007
|
}
|