@typeberry/jam 0.1.3-8258907 → 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 +279 -249
- package/bootstrap-generator.mjs.map +1 -1
- package/bootstrap-importer.mjs +416 -325
- package/bootstrap-importer.mjs.map +1 -1
- package/bootstrap-network.mjs +279 -249
- package/bootstrap-network.mjs.map +1 -1
- package/index.js +497 -327
- package/index.js.map +1 -1
- package/package.json +1 -1
package/bootstrap-importer.mjs
CHANGED
|
@@ -5607,7 +5607,7 @@ class Skipper {
|
|
|
5607
5607
|
*
|
|
5608
5608
|
* Descriptors can be composed to form more complex typings.
|
|
5609
5609
|
*/
|
|
5610
|
-
class
|
|
5610
|
+
class Descriptor {
|
|
5611
5611
|
name;
|
|
5612
5612
|
sizeHint;
|
|
5613
5613
|
encode;
|
|
@@ -5617,11 +5617,11 @@ class descriptor_Descriptor {
|
|
|
5617
5617
|
View;
|
|
5618
5618
|
/** New descriptor with specialized `View`. */
|
|
5619
5619
|
static withView(name, sizeHint, encode, decode, skip, view) {
|
|
5620
|
-
return new
|
|
5620
|
+
return new Descriptor(name, sizeHint, encode, decode, skip, view);
|
|
5621
5621
|
}
|
|
5622
5622
|
/** Create a new descriptor without a specialized `View`. */
|
|
5623
5623
|
static new(name, sizeHint, encode, decode, skip) {
|
|
5624
|
-
return new
|
|
5624
|
+
return new Descriptor(name, sizeHint, encode, decode, skip, null);
|
|
5625
5625
|
}
|
|
5626
5626
|
constructor(
|
|
5627
5627
|
/** Descriptive name of the coded data. */
|
|
@@ -5658,7 +5658,7 @@ class descriptor_Descriptor {
|
|
|
5658
5658
|
}
|
|
5659
5659
|
/** Return a new descriptor that converts data into some other type. */
|
|
5660
5660
|
convert(input, output) {
|
|
5661
|
-
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);
|
|
5662
5662
|
}
|
|
5663
5663
|
/** Safely cast the descriptor value to a opaque type. */
|
|
5664
5664
|
asOpaque() {
|
|
@@ -6356,51 +6356,51 @@ var descriptors_codec;
|
|
|
6356
6356
|
return (len) => {
|
|
6357
6357
|
let ret = cache.get(len);
|
|
6358
6358
|
if (ret === undefined) {
|
|
6359
|
-
ret =
|
|
6359
|
+
ret = Descriptor.new(`Bytes<${len}>`, exactHint(len), (e, v) => e.bytes(v), (d) => d.bytes(len), (s) => s.bytes(len));
|
|
6360
6360
|
cache.set(len, ret);
|
|
6361
6361
|
}
|
|
6362
6362
|
return ret;
|
|
6363
6363
|
};
|
|
6364
6364
|
})();
|
|
6365
6365
|
/** Variable-length U32. */
|
|
6366
|
-
codec.varU32 =
|
|
6366
|
+
codec.varU32 = Descriptor.new("var_u32", { bytes: 4, isExact: false }, (e, v) => e.varU32(v), (d) => d.varU32(), (d) => d.varU32());
|
|
6367
6367
|
/** Variable-length U64. */
|
|
6368
|
-
codec.varU64 =
|
|
6368
|
+
codec.varU64 = Descriptor.new("var_u64", { bytes: 8, isExact: false }, (e, v) => e.varU64(v), (d) => d.varU64(), (d) => d.varU64());
|
|
6369
6369
|
/** Unsigned 64-bit number. */
|
|
6370
|
-
codec.u64 =
|
|
6370
|
+
codec.u64 = Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.u64(), (d) => d.u64(), codec.bytes(8));
|
|
6371
6371
|
/** Unsigned 32-bit number. */
|
|
6372
|
-
codec.u32 =
|
|
6372
|
+
codec.u32 = Descriptor.withView("u32", exactHint(4), (e, v) => e.i32(v), (d) => d.u32(), (d) => d.u32(), codec.bytes(4));
|
|
6373
6373
|
/** Unsigned 24-bit number. */
|
|
6374
|
-
codec.u24 =
|
|
6374
|
+
codec.u24 = Descriptor.withView("u24", exactHint(3), (e, v) => e.i24(v), (d) => d.u24(), (d) => d.u24(), codec.bytes(3));
|
|
6375
6375
|
/** Unsigned 16-bit number. */
|
|
6376
|
-
codec.u16 =
|
|
6376
|
+
codec.u16 = Descriptor.withView("u16", exactHint(2), (e, v) => e.i16(v), (d) => d.u16(), (d) => d.u16(), codec.bytes(2));
|
|
6377
6377
|
/** Unsigned 8-bit number. */
|
|
6378
|
-
codec.u8 =
|
|
6378
|
+
codec.u8 = Descriptor.new("u8", exactHint(1), (e, v) => e.i8(v), (d) => d.u8(), (d) => d.u8());
|
|
6379
6379
|
/** Signed 64-bit number. */
|
|
6380
|
-
codec.i64 =
|
|
6380
|
+
codec.i64 = Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.i64(), (s) => s.u64(), codec.bytes(8));
|
|
6381
6381
|
/** Signed 32-bit number. */
|
|
6382
|
-
codec.i32 =
|
|
6382
|
+
codec.i32 = Descriptor.withView("i32", exactHint(4), (e, v) => e.i32(v), (d) => d.i32(), (s) => s.u32(), codec.bytes(4));
|
|
6383
6383
|
/** Signed 24-bit number. */
|
|
6384
|
-
codec.i24 =
|
|
6384
|
+
codec.i24 = Descriptor.withView("i24", exactHint(3), (e, v) => e.i24(v), (d) => d.i24(), (s) => s.u24(), codec.bytes(3));
|
|
6385
6385
|
/** Signed 16-bit number. */
|
|
6386
|
-
codec.i16 =
|
|
6386
|
+
codec.i16 = Descriptor.withView("i16", exactHint(2), (e, v) => e.i16(v), (d) => d.i16(), (s) => s.u16(), codec.bytes(2));
|
|
6387
6387
|
/** Signed 8-bit number. */
|
|
6388
|
-
codec.i8 =
|
|
6388
|
+
codec.i8 = Descriptor.new("i8", exactHint(1), (e, v) => e.i8(v), (d) => d.i8(), (s) => s.u8());
|
|
6389
6389
|
/** 1-byte boolean value. */
|
|
6390
|
-
codec.bool =
|
|
6390
|
+
codec.bool = Descriptor.new("bool", exactHint(1), (e, v) => e.bool(v), (d) => d.bool(), (s) => s.bool());
|
|
6391
6391
|
/** Variable-length bytes blob. */
|
|
6392
|
-
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());
|
|
6393
6393
|
/** String encoded as variable-length bytes blob. */
|
|
6394
|
-
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);
|
|
6395
6395
|
/** Variable-length bit vector. */
|
|
6396
|
-
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());
|
|
6397
6397
|
/** Fixed-length bit vector. */
|
|
6398
|
-
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));
|
|
6399
6399
|
/** Optionality wrapper for given type. */
|
|
6400
6400
|
codec.optional = (type) => {
|
|
6401
|
-
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));
|
|
6402
6402
|
if (hasUniqueView(type)) {
|
|
6403
|
-
return
|
|
6403
|
+
return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.optional(type.View));
|
|
6404
6404
|
}
|
|
6405
6405
|
return self;
|
|
6406
6406
|
};
|
|
@@ -6411,7 +6411,7 @@ var descriptors_codec;
|
|
|
6411
6411
|
}) => {
|
|
6412
6412
|
const name = `Sequence<${type.name}>[?]`;
|
|
6413
6413
|
const typicalLength = options.typicalLength ?? TYPICAL_SEQUENCE_LENGTH;
|
|
6414
|
-
return
|
|
6414
|
+
return Descriptor.withView(name, { bytes: typicalLength * type.sizeHint.bytes, isExact: false }, (e, v) => {
|
|
6415
6415
|
validateLength(options, v.length, name);
|
|
6416
6416
|
e.sequenceVarLen(type, v);
|
|
6417
6417
|
}, (d) => {
|
|
@@ -6425,10 +6425,10 @@ var descriptors_codec;
|
|
|
6425
6425
|
}, sequenceViewVarLen(type, options));
|
|
6426
6426
|
};
|
|
6427
6427
|
/** Fixed-length sequence of given type. */
|
|
6428
|
-
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 }));
|
|
6429
6429
|
/** Small dictionary codec. */
|
|
6430
6430
|
codec.dictionary = (key, value, { sortKeys, fixedLength, }) => {
|
|
6431
|
-
const self =
|
|
6431
|
+
const self = Descriptor.new(`Dictionary<${key.name}, ${value.name}>[${fixedLength ?? "?"}]`, {
|
|
6432
6432
|
bytes: fixedLength !== undefined
|
|
6433
6433
|
? fixedLength * addSizeHints(key.sizeHint, value.sizeHint).bytes
|
|
6434
6434
|
: TYPICAL_DICTIONARY_LENGTH * (addSizeHints(key.sizeHint, value.sizeHint).bytes ?? 0),
|
|
@@ -6467,13 +6467,13 @@ var descriptors_codec;
|
|
|
6467
6467
|
s.sequenceFixLen(value, len);
|
|
6468
6468
|
});
|
|
6469
6469
|
if (hasUniqueView(value)) {
|
|
6470
|
-
return
|
|
6470
|
+
return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.dictionary(key, value.View, { sortKeys, fixedLength }));
|
|
6471
6471
|
}
|
|
6472
6472
|
return self;
|
|
6473
6473
|
};
|
|
6474
6474
|
/** Encoding of pair of two values. */
|
|
6475
6475
|
codec.pair = (a, b) => {
|
|
6476
|
-
const self =
|
|
6476
|
+
const self = Descriptor.new(`Pair<${a.name}, ${b.name}>`, addSizeHints(a.sizeHint, b.sizeHint), (e, elem) => {
|
|
6477
6477
|
a.encode(e, elem[0]);
|
|
6478
6478
|
b.encode(e, elem[1]);
|
|
6479
6479
|
}, (d) => {
|
|
@@ -6485,14 +6485,14 @@ var descriptors_codec;
|
|
|
6485
6485
|
b.skip(s);
|
|
6486
6486
|
});
|
|
6487
6487
|
if (hasUniqueView(a) && hasUniqueView(b)) {
|
|
6488
|
-
return
|
|
6488
|
+
return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.pair(a.View, b.View));
|
|
6489
6489
|
}
|
|
6490
6490
|
return self;
|
|
6491
6491
|
};
|
|
6492
6492
|
/** Custom encoding / decoding logic. */
|
|
6493
|
-
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);
|
|
6494
6494
|
/** Choose a descriptor depending on the encoding/decoding context. */
|
|
6495
|
-
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);
|
|
6496
6496
|
/**
|
|
6497
6497
|
* A descriptor for a more complex POJO.
|
|
6498
6498
|
*
|
|
@@ -6529,7 +6529,7 @@ var descriptors_codec;
|
|
|
6529
6529
|
};
|
|
6530
6530
|
const view = objectView(Class, descriptors, sizeHint, skipper);
|
|
6531
6531
|
// and create the descriptor for the entire class.
|
|
6532
|
-
return
|
|
6532
|
+
return Descriptor.withView(Class.name, sizeHint, (e, t) => {
|
|
6533
6533
|
forEachDescriptor(descriptors, (key, descriptor) => {
|
|
6534
6534
|
const value = t[key];
|
|
6535
6535
|
descriptor.encode(e, value);
|
|
@@ -6580,7 +6580,7 @@ function objectView(Class, descriptors, sizeHint, skipper) {
|
|
|
6580
6580
|
});
|
|
6581
6581
|
}
|
|
6582
6582
|
});
|
|
6583
|
-
return
|
|
6583
|
+
return Descriptor.new(`View<${Class.name}>`, sizeHint, (e, t) => {
|
|
6584
6584
|
const encoded = t.encoded();
|
|
6585
6585
|
e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
|
|
6586
6586
|
}, (d) => {
|
|
@@ -6599,7 +6599,7 @@ function sequenceViewVarLen(type, options) {
|
|
|
6599
6599
|
validateLength(options, length, name);
|
|
6600
6600
|
return s.sequenceFixLen(type, length);
|
|
6601
6601
|
};
|
|
6602
|
-
return
|
|
6602
|
+
return Descriptor.new(name, sizeHint, (e, t) => {
|
|
6603
6603
|
validateLength(options, t.length, name);
|
|
6604
6604
|
const encoded = t.encoded();
|
|
6605
6605
|
e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
|
|
@@ -6615,7 +6615,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
|
|
|
6615
6615
|
const skipper = (s) => s.sequenceFixLen(type, fixedLength);
|
|
6616
6616
|
const view = type.name !== type.View.name ? `, ${type.View.name}` : "";
|
|
6617
6617
|
const name = `SeqView<${type.name}${view}>[${fixedLength}]`;
|
|
6618
|
-
return
|
|
6618
|
+
return Descriptor.new(name, sizeHint, (e, t) => {
|
|
6619
6619
|
const encoded = t.encoded();
|
|
6620
6620
|
e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
|
|
6621
6621
|
}, (d) => {
|
|
@@ -7631,7 +7631,7 @@ const codecFixedSizeArray = (val, len) => {
|
|
|
7631
7631
|
};
|
|
7632
7632
|
/** Codec for a hash-dictionary. */
|
|
7633
7633
|
const codecHashDictionary = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH, compare = (a, b) => extractKey(a).compare(extractKey(b)), } = {}) => {
|
|
7634
|
-
return
|
|
7634
|
+
return Descriptor.new(`HashDictionary<${value.name}>[?]`, {
|
|
7635
7635
|
bytes: typicalLength * value.sizeHint.bytes,
|
|
7636
7636
|
isExact: false,
|
|
7637
7637
|
}, (e, v) => {
|
|
@@ -9598,6 +9598,13 @@ const W_T = 128;
|
|
|
9598
9598
|
/** `W_M`: The maximum number of exports in a work-package. */
|
|
9599
9599
|
const W_X = 3_072;
|
|
9600
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;
|
|
9601
9608
|
/**
|
|
9602
9609
|
* `J`: The maximum sum of dependency items in a work-report.
|
|
9603
9610
|
*
|
|
@@ -9609,9 +9616,209 @@ const AUTHORIZATION_QUEUE_SIZE = Q;
|
|
|
9609
9616
|
/** `O`: Maximal authorization pool size. */
|
|
9610
9617
|
const MAX_AUTH_POOL_SIZE = O;
|
|
9611
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
|
+
|
|
9612
9816
|
;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
|
|
9613
9817
|
|
|
9614
9818
|
|
|
9819
|
+
|
|
9820
|
+
|
|
9821
|
+
|
|
9615
9822
|
/** Dictionary entry of services that auto-accumulate every block. */
|
|
9616
9823
|
class AutoAccumulate {
|
|
9617
9824
|
service;
|
|
@@ -9633,39 +9840,50 @@ class AutoAccumulate {
|
|
|
9633
9840
|
}
|
|
9634
9841
|
}
|
|
9635
9842
|
/**
|
|
9636
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
9843
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
|
|
9637
9844
|
*/
|
|
9638
9845
|
class PrivilegedServices {
|
|
9639
9846
|
manager;
|
|
9640
|
-
|
|
9641
|
-
|
|
9847
|
+
delegator;
|
|
9848
|
+
registrar;
|
|
9849
|
+
assigners;
|
|
9642
9850
|
autoAccumulateServices;
|
|
9851
|
+
/** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
|
|
9643
9852
|
static Codec = descriptors_codec.Class(PrivilegedServices, {
|
|
9644
9853
|
manager: descriptors_codec.u32.asOpaque(),
|
|
9645
|
-
|
|
9646
|
-
|
|
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)),
|
|
9647
9859
|
autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
|
|
9648
9860
|
});
|
|
9649
|
-
static create(
|
|
9650
|
-
return new PrivilegedServices(manager,
|
|
9861
|
+
static create(a) {
|
|
9862
|
+
return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
9651
9863
|
}
|
|
9652
9864
|
constructor(
|
|
9653
9865
|
/**
|
|
9654
|
-
*
|
|
9655
|
-
* the service able to effect an alteration of χ from block to block,
|
|
9866
|
+
* `χ_M`: Manages alteration of χ from block to block,
|
|
9656
9867
|
* as well as bestow services with storage deposit credits.
|
|
9657
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
9868
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
9658
9869
|
*/
|
|
9659
9870
|
manager,
|
|
9660
|
-
/**
|
|
9661
|
-
|
|
9662
|
-
/**
|
|
9663
|
-
|
|
9664
|
-
|
|
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. */
|
|
9665
9882
|
autoAccumulateServices) {
|
|
9666
9883
|
this.manager = manager;
|
|
9667
|
-
this.
|
|
9668
|
-
this.
|
|
9884
|
+
this.delegator = delegator;
|
|
9885
|
+
this.registrar = registrar;
|
|
9886
|
+
this.assigners = assigners;
|
|
9669
9887
|
this.autoAccumulateServices = autoAccumulateServices;
|
|
9670
9888
|
}
|
|
9671
9889
|
}
|
|
@@ -9753,7 +9971,7 @@ class RecentBlocks extends WithDebug {
|
|
|
9753
9971
|
*/
|
|
9754
9972
|
class RecentBlocksHistory extends WithDebug {
|
|
9755
9973
|
current;
|
|
9756
|
-
static Codec =
|
|
9974
|
+
static Codec = Descriptor.new("RecentBlocksHistory", RecentBlocks.Codec.sizeHint, (encoder, value) => RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
|
|
9757
9975
|
const recentBlocks = RecentBlocks.Codec.decode(decoder);
|
|
9758
9976
|
return RecentBlocksHistory.create(recentBlocks);
|
|
9759
9977
|
}, (skip) => {
|
|
@@ -9950,196 +10168,6 @@ class SafroleData {
|
|
|
9950
10168
|
}
|
|
9951
10169
|
}
|
|
9952
10170
|
|
|
9953
|
-
;// CONCATENATED MODULE: ./packages/jam/state/service.ts
|
|
9954
|
-
|
|
9955
|
-
|
|
9956
|
-
|
|
9957
|
-
|
|
9958
|
-
|
|
9959
|
-
|
|
9960
|
-
/**
|
|
9961
|
-
* `B_S`: The basic minimum balance which all services require.
|
|
9962
|
-
*
|
|
9963
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
9964
|
-
*/
|
|
9965
|
-
const BASE_SERVICE_BALANCE = 100n;
|
|
9966
|
-
/**
|
|
9967
|
-
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
9968
|
-
*
|
|
9969
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
9970
|
-
*/
|
|
9971
|
-
const ELECTIVE_ITEM_BALANCE = 10n;
|
|
9972
|
-
/**
|
|
9973
|
-
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
9974
|
-
*
|
|
9975
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
9976
|
-
*/
|
|
9977
|
-
const ELECTIVE_BYTE_BALANCE = 1n;
|
|
9978
|
-
const zeroSizeHint = {
|
|
9979
|
-
bytes: 0,
|
|
9980
|
-
isExact: true,
|
|
9981
|
-
};
|
|
9982
|
-
/** 0-byte read, return given default value */
|
|
9983
|
-
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
9984
|
-
/** Encode and decode object with leading version number. */
|
|
9985
|
-
const codecWithVersion = (val) => descriptor_Descriptor.new("withVersion", {
|
|
9986
|
-
bytes: val.sizeHint.bytes + 8,
|
|
9987
|
-
isExact: false,
|
|
9988
|
-
}, (e, v) => {
|
|
9989
|
-
e.varU64(0n);
|
|
9990
|
-
val.encode(e, v);
|
|
9991
|
-
}, (d) => {
|
|
9992
|
-
const version = d.varU64();
|
|
9993
|
-
if (version !== 0n) {
|
|
9994
|
-
throw new Error("Non-zero version is not supported!");
|
|
9995
|
-
}
|
|
9996
|
-
return val.decode(d);
|
|
9997
|
-
}, (s) => {
|
|
9998
|
-
s.varU64();
|
|
9999
|
-
val.skip(s);
|
|
10000
|
-
});
|
|
10001
|
-
/**
|
|
10002
|
-
* Service account details.
|
|
10003
|
-
*
|
|
10004
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
|
|
10005
|
-
*/
|
|
10006
|
-
class ServiceAccountInfo extends WithDebug {
|
|
10007
|
-
codeHash;
|
|
10008
|
-
balance;
|
|
10009
|
-
accumulateMinGas;
|
|
10010
|
-
onTransferMinGas;
|
|
10011
|
-
storageUtilisationBytes;
|
|
10012
|
-
gratisStorage;
|
|
10013
|
-
storageUtilisationCount;
|
|
10014
|
-
created;
|
|
10015
|
-
lastAccumulation;
|
|
10016
|
-
parentService;
|
|
10017
|
-
static Codec = descriptors_codec.Class(ServiceAccountInfo, {
|
|
10018
|
-
codeHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
10019
|
-
balance: descriptors_codec.u64,
|
|
10020
|
-
accumulateMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
|
|
10021
|
-
onTransferMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
|
|
10022
|
-
storageUtilisationBytes: descriptors_codec.u64,
|
|
10023
|
-
gratisStorage: descriptors_codec.u64,
|
|
10024
|
-
storageUtilisationCount: descriptors_codec.u32,
|
|
10025
|
-
created: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
|
|
10026
|
-
lastAccumulation: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
|
|
10027
|
-
parentService: descriptors_codec.u32.convert((x) => x, tryAsServiceId),
|
|
10028
|
-
});
|
|
10029
|
-
static create(a) {
|
|
10030
|
-
return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
|
|
10031
|
-
}
|
|
10032
|
-
/**
|
|
10033
|
-
* `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
|
|
10034
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
|
|
10035
|
-
*/
|
|
10036
|
-
static calculateThresholdBalance(items, bytes, gratisStorage) {
|
|
10037
|
-
const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
|
|
10038
|
-
if (storageCost < 0n) {
|
|
10039
|
-
return numbers_tryAsU64(0);
|
|
10040
|
-
}
|
|
10041
|
-
if (storageCost >= 2n ** 64n) {
|
|
10042
|
-
return numbers_tryAsU64(2n ** 64n - 1n);
|
|
10043
|
-
}
|
|
10044
|
-
return numbers_tryAsU64(storageCost);
|
|
10045
|
-
}
|
|
10046
|
-
constructor(
|
|
10047
|
-
/** `a_c`: Hash of the service code. */
|
|
10048
|
-
codeHash,
|
|
10049
|
-
/** `a_b`: Current account balance. */
|
|
10050
|
-
balance,
|
|
10051
|
-
/** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
|
|
10052
|
-
accumulateMinGas,
|
|
10053
|
-
/** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
|
|
10054
|
-
onTransferMinGas,
|
|
10055
|
-
/** `a_o`: Total number of octets in storage. */
|
|
10056
|
-
storageUtilisationBytes,
|
|
10057
|
-
/** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
|
|
10058
|
-
gratisStorage,
|
|
10059
|
-
/** `a_i`: Number of items in storage. */
|
|
10060
|
-
storageUtilisationCount,
|
|
10061
|
-
/** `a_r`: Creation account time slot. */
|
|
10062
|
-
created,
|
|
10063
|
-
/** `a_a`: Most recent accumulation time slot. */
|
|
10064
|
-
lastAccumulation,
|
|
10065
|
-
/** `a_p`: Parent service ID. */
|
|
10066
|
-
parentService) {
|
|
10067
|
-
super();
|
|
10068
|
-
this.codeHash = codeHash;
|
|
10069
|
-
this.balance = balance;
|
|
10070
|
-
this.accumulateMinGas = accumulateMinGas;
|
|
10071
|
-
this.onTransferMinGas = onTransferMinGas;
|
|
10072
|
-
this.storageUtilisationBytes = storageUtilisationBytes;
|
|
10073
|
-
this.gratisStorage = gratisStorage;
|
|
10074
|
-
this.storageUtilisationCount = storageUtilisationCount;
|
|
10075
|
-
this.created = created;
|
|
10076
|
-
this.lastAccumulation = lastAccumulation;
|
|
10077
|
-
this.parentService = parentService;
|
|
10078
|
-
}
|
|
10079
|
-
}
|
|
10080
|
-
class PreimageItem extends WithDebug {
|
|
10081
|
-
hash;
|
|
10082
|
-
blob;
|
|
10083
|
-
static Codec = descriptors_codec.Class(PreimageItem, {
|
|
10084
|
-
hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
10085
|
-
blob: descriptors_codec.blob,
|
|
10086
|
-
});
|
|
10087
|
-
static create({ hash, blob }) {
|
|
10088
|
-
return new PreimageItem(hash, blob);
|
|
10089
|
-
}
|
|
10090
|
-
constructor(hash, blob) {
|
|
10091
|
-
super();
|
|
10092
|
-
this.hash = hash;
|
|
10093
|
-
this.blob = blob;
|
|
10094
|
-
}
|
|
10095
|
-
}
|
|
10096
|
-
class StorageItem extends WithDebug {
|
|
10097
|
-
key;
|
|
10098
|
-
value;
|
|
10099
|
-
static Codec = descriptors_codec.Class(StorageItem, {
|
|
10100
|
-
key: descriptors_codec.blob.convert((i) => i, (o) => opaque_asOpaqueType(o)),
|
|
10101
|
-
value: descriptors_codec.blob,
|
|
10102
|
-
});
|
|
10103
|
-
static create({ key, value }) {
|
|
10104
|
-
return new StorageItem(key, value);
|
|
10105
|
-
}
|
|
10106
|
-
constructor(key, value) {
|
|
10107
|
-
super();
|
|
10108
|
-
this.key = key;
|
|
10109
|
-
this.value = value;
|
|
10110
|
-
}
|
|
10111
|
-
}
|
|
10112
|
-
const MAX_LOOKUP_HISTORY_SLOTS = 3;
|
|
10113
|
-
function tryAsLookupHistorySlots(items) {
|
|
10114
|
-
const knownSize = sized_array_asKnownSize(items);
|
|
10115
|
-
if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
|
|
10116
|
-
throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
|
|
10117
|
-
}
|
|
10118
|
-
return knownSize;
|
|
10119
|
-
}
|
|
10120
|
-
/** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
|
|
10121
|
-
class LookupHistoryItem {
|
|
10122
|
-
hash;
|
|
10123
|
-
length;
|
|
10124
|
-
slots;
|
|
10125
|
-
constructor(hash, length,
|
|
10126
|
-
/**
|
|
10127
|
-
* Preimage availability history as a sequence of time slots.
|
|
10128
|
-
* See PreimageStatus and the following GP fragment for more details.
|
|
10129
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
|
|
10130
|
-
slots) {
|
|
10131
|
-
this.hash = hash;
|
|
10132
|
-
this.length = length;
|
|
10133
|
-
this.slots = slots;
|
|
10134
|
-
}
|
|
10135
|
-
static isRequested(item) {
|
|
10136
|
-
if ("slots" in item) {
|
|
10137
|
-
return item.slots.length === 0;
|
|
10138
|
-
}
|
|
10139
|
-
return item.length === 0;
|
|
10140
|
-
}
|
|
10141
|
-
}
|
|
10142
|
-
|
|
10143
10171
|
;// CONCATENATED MODULE: ./packages/jam/state/state.ts
|
|
10144
10172
|
/**
|
|
10145
10173
|
* In addition to the entropy accumulator η_0, we retain
|
|
@@ -10576,6 +10604,7 @@ class StatisticsData {
|
|
|
10576
10604
|
|
|
10577
10605
|
|
|
10578
10606
|
|
|
10607
|
+
|
|
10579
10608
|
|
|
10580
10609
|
|
|
10581
10610
|
var in_memory_state_UpdateError;
|
|
@@ -10979,8 +11008,9 @@ class InMemoryState extends WithDebug {
|
|
|
10979
11008
|
epochRoot: bytes_Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
10980
11009
|
privilegedServices: PrivilegedServices.create({
|
|
10981
11010
|
manager: tryAsServiceId(0),
|
|
10982
|
-
|
|
10983
|
-
|
|
11011
|
+
assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
|
|
11012
|
+
delegator: tryAsServiceId(0),
|
|
11013
|
+
registrar: tryAsServiceId(MAX_VALUE),
|
|
10984
11014
|
autoAccumulateServices: [],
|
|
10985
11015
|
}),
|
|
10986
11016
|
accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
|
|
@@ -11216,7 +11246,7 @@ var serialize;
|
|
|
11216
11246
|
* determine the boundary of the bytes, so it can only be used
|
|
11217
11247
|
* as the last element of the codec and can't be used in sequences!
|
|
11218
11248
|
*/
|
|
11219
|
-
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()));
|
|
11220
11250
|
|
|
11221
11251
|
;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
|
|
11222
11252
|
|
|
@@ -12527,7 +12557,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
|
|
|
12527
12557
|
}
|
|
12528
12558
|
return Ordering.Equal;
|
|
12529
12559
|
}, } = {}) => {
|
|
12530
|
-
return
|
|
12560
|
+
return Descriptor.new(`Map<${value.name}>[?]`, {
|
|
12531
12561
|
bytes: typicalLength * value.sizeHint.bytes,
|
|
12532
12562
|
isExact: false,
|
|
12533
12563
|
}, (e, v) => {
|
|
@@ -15116,11 +15146,17 @@ class AccumulationStateUpdate {
|
|
|
15116
15146
|
if (from.privilegedServices !== null) {
|
|
15117
15147
|
update.privilegedServices = PrivilegedServices.create({
|
|
15118
15148
|
...from.privilegedServices,
|
|
15119
|
-
|
|
15149
|
+
assigners: sized_array_asKnownSize([...from.privilegedServices.assigners]),
|
|
15120
15150
|
});
|
|
15121
15151
|
}
|
|
15122
15152
|
return update;
|
|
15123
15153
|
}
|
|
15154
|
+
/** Retrieve and clear pending transfers. */
|
|
15155
|
+
takeTransfers() {
|
|
15156
|
+
const transfers = this.transfers;
|
|
15157
|
+
this.transfers = [];
|
|
15158
|
+
return transfers;
|
|
15159
|
+
}
|
|
15124
15160
|
}
|
|
15125
15161
|
class PartiallyUpdatedState {
|
|
15126
15162
|
state;
|
|
@@ -17255,13 +17291,6 @@ class BitOps {
|
|
|
17255
17291
|
}
|
|
17256
17292
|
}
|
|
17257
17293
|
|
|
17258
|
-
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
|
|
17259
|
-
const MAX_VALUE = 4294967295;
|
|
17260
|
-
const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
|
|
17261
|
-
const MIN_VALUE = -(2 ** 31);
|
|
17262
|
-
const MAX_SHIFT_U32 = 32;
|
|
17263
|
-
const MAX_SHIFT_U64 = 64n;
|
|
17264
|
-
|
|
17265
17294
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-utils.ts
|
|
17266
17295
|
|
|
17267
17296
|
|
|
@@ -19291,6 +19320,8 @@ var NewServiceError;
|
|
|
19291
19320
|
NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
|
|
19292
19321
|
/** Service is not privileged to set gratis storage. */
|
|
19293
19322
|
NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
|
|
19323
|
+
/** Registrar attempting to create a service with already existing id. */
|
|
19324
|
+
NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
|
|
19294
19325
|
})(NewServiceError || (NewServiceError = {}));
|
|
19295
19326
|
var UpdatePrivilegesError;
|
|
19296
19327
|
(function (UpdatePrivilegesError) {
|
|
@@ -19427,7 +19458,7 @@ const HostCallResult = {
|
|
|
19427
19458
|
OOB: numbers_tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
|
|
19428
19459
|
/** Index unknown. */
|
|
19429
19460
|
WHO: numbers_tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
|
|
19430
|
-
/** Storage full. */
|
|
19461
|
+
/** Storage full or resource already allocated. */
|
|
19431
19462
|
FULL: numbers_tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
|
|
19432
19463
|
/** Core index unknown. */
|
|
19433
19464
|
CORE: numbers_tryAsU64(0xfffffffffffffffan), // 2**64 - 6
|
|
@@ -19435,7 +19466,7 @@ const HostCallResult = {
|
|
|
19435
19466
|
CASH: numbers_tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
|
|
19436
19467
|
/** Gas limit too low. */
|
|
19437
19468
|
LOW: numbers_tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
|
|
19438
|
-
/** The item is already solicited
|
|
19469
|
+
/** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
|
|
19439
19470
|
HUH: numbers_tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
|
|
19440
19471
|
/** The return value indicating general success. */
|
|
19441
19472
|
OK: numbers_tryAsU64(0n),
|
|
@@ -19489,6 +19520,7 @@ function clampU64ToU32(value) {
|
|
|
19489
19520
|
|
|
19490
19521
|
|
|
19491
19522
|
|
|
19523
|
+
|
|
19492
19524
|
/**
|
|
19493
19525
|
* Number of storage items required for ejection of the service.
|
|
19494
19526
|
*
|
|
@@ -19580,10 +19612,13 @@ class AccumulateExternalities {
|
|
|
19580
19612
|
const isExpired = status.data[1] < t - this.chainSpec.preimageExpungePeriod;
|
|
19581
19613
|
return [isExpired, isExpired ? "" : "not expired"];
|
|
19582
19614
|
}
|
|
19583
|
-
/** `check`: https://graypaper.fluffylabs.dev/#/
|
|
19615
|
+
/** `check`: https://graypaper.fluffylabs.dev/#/ab2cdbd/30c60330c603?v=0.7.2 */
|
|
19584
19616
|
getNextAvailableServiceId(serviceId) {
|
|
19585
19617
|
let currentServiceId = serviceId;
|
|
19586
|
-
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;
|
|
19587
19622
|
for (;;) {
|
|
19588
19623
|
const service = this.getServiceInfo(currentServiceId);
|
|
19589
19624
|
// we found an empty id
|
|
@@ -19591,7 +19626,7 @@ class AccumulateExternalities {
|
|
|
19591
19626
|
return currentServiceId;
|
|
19592
19627
|
}
|
|
19593
19628
|
// keep trying
|
|
19594
|
-
currentServiceId = tryAsServiceId(((currentServiceId -
|
|
19629
|
+
currentServiceId = tryAsServiceId(((currentServiceId - offset + 1 + mod) % mod) + offset);
|
|
19595
19630
|
}
|
|
19596
19631
|
}
|
|
19597
19632
|
checkPreimageStatus(hash, length) {
|
|
@@ -19748,8 +19783,7 @@ class AccumulateExternalities {
|
|
|
19748
19783
|
}));
|
|
19749
19784
|
return result_Result.ok(result_OK);
|
|
19750
19785
|
}
|
|
19751
|
-
newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage) {
|
|
19752
|
-
const newServiceId = this.nextNewServiceId;
|
|
19786
|
+
newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage, wantedServiceId) {
|
|
19753
19787
|
// calculate the threshold. Storage is empty, one preimage requested.
|
|
19754
19788
|
// https://graypaper.fluffylabs.dev/#/7e6ff6a/115901115901?v=0.6.7
|
|
19755
19789
|
const items = numbers_tryAsU32(2 * 1 + 0);
|
|
@@ -19770,30 +19804,59 @@ class AccumulateExternalities {
|
|
|
19770
19804
|
if (balanceLeftForCurrent < thresholdForCurrent || bytes.overflow) {
|
|
19771
19805
|
return result_Result.error(NewServiceError.InsufficientFunds);
|
|
19772
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;
|
|
19773
19850
|
// add the new service
|
|
19774
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
19851
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36e70336e903?v=0.7.2
|
|
19775
19852
|
this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
|
|
19776
19853
|
serviceId: newServiceId,
|
|
19777
|
-
serviceInfo:
|
|
19778
|
-
|
|
19779
|
-
balance: thresholdForNew,
|
|
19780
|
-
accumulateMinGas,
|
|
19781
|
-
onTransferMinGas,
|
|
19782
|
-
storageUtilisationBytes: bytes.value,
|
|
19783
|
-
storageUtilisationCount: items,
|
|
19784
|
-
gratisStorage,
|
|
19785
|
-
created: this.currentTimeslot,
|
|
19786
|
-
lastAccumulation: common_tryAsTimeSlot(0),
|
|
19787
|
-
parentService: this.currentServiceId,
|
|
19788
|
-
}),
|
|
19789
|
-
lookupHistory: new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([])),
|
|
19854
|
+
serviceInfo: newAccount,
|
|
19855
|
+
lookupHistory: newLookupItem,
|
|
19790
19856
|
}));
|
|
19791
19857
|
// update the balance of current service
|
|
19792
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
19793
|
-
this.updatedState.updateServiceInfo(this.currentServiceId,
|
|
19794
|
-
...currentService,
|
|
19795
|
-
balance: numbers_tryAsU64(balanceLeftForCurrent),
|
|
19796
|
-
}));
|
|
19858
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36ec0336ee03?v=0.7.2
|
|
19859
|
+
this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
|
|
19797
19860
|
// update the next service id we are going to create next
|
|
19798
19861
|
// https://graypaper.fluffylabs.dev/#/7e6ff6a/36a70336a703?v=0.6.7
|
|
19799
19862
|
this.nextNewServiceId = this.getNextAvailableServiceId(bumpServiceId(newServiceId));
|
|
@@ -19811,9 +19874,9 @@ class AccumulateExternalities {
|
|
|
19811
19874
|
}
|
|
19812
19875
|
updateValidatorsData(validatorsData) {
|
|
19813
19876
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/362802362d02?v=0.6.7 */
|
|
19814
|
-
const
|
|
19815
|
-
if (
|
|
19816
|
-
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`;
|
|
19817
19880
|
return result_Result.error(UnprivilegedError);
|
|
19818
19881
|
}
|
|
19819
19882
|
this.updatedState.stateUpdate.validatorsData = validatorsData;
|
|
@@ -19823,34 +19886,38 @@ class AccumulateExternalities {
|
|
|
19823
19886
|
/** https://graypaper.fluffylabs.dev/#/9a08063/362202362202?v=0.6.6 */
|
|
19824
19887
|
this.checkpointedState = AccumulationStateUpdate.copyFrom(this.updatedState.stateUpdate);
|
|
19825
19888
|
}
|
|
19826
|
-
updateAuthorizationQueue(coreIndex, authQueue,
|
|
19889
|
+
updateAuthorizationQueue(coreIndex, authQueue, assigners) {
|
|
19827
19890
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/36a40136a401?v=0.6.7 */
|
|
19828
19891
|
// NOTE `coreIndex` is already verified in the HC, so this is infallible.
|
|
19829
|
-
const
|
|
19830
|
-
if (
|
|
19831
|
-
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.`;
|
|
19832
19895
|
return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
|
|
19833
19896
|
}
|
|
19834
|
-
if (
|
|
19835
|
-
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.`;
|
|
19836
19899
|
return result_Result.error(UpdatePrivilegesError.InvalidServiceId);
|
|
19837
19900
|
}
|
|
19838
19901
|
this.updatedState.stateUpdate.authorizationQueues.set(coreIndex, authQueue);
|
|
19839
19902
|
return result_Result.ok(result_OK);
|
|
19840
19903
|
}
|
|
19841
|
-
updatePrivilegedServices(manager, authorizers,
|
|
19904
|
+
updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate) {
|
|
19842
19905
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/36d90036de00?v=0.6.7 */
|
|
19843
19906
|
const currentManager = this.updatedState.getPrivilegedServices().manager;
|
|
19844
19907
|
if (currentManager !== this.currentServiceId) {
|
|
19845
19908
|
return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
|
|
19846
19909
|
}
|
|
19847
|
-
if (manager === null ||
|
|
19848
|
-
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.");
|
|
19849
19915
|
}
|
|
19850
19916
|
this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
|
|
19851
19917
|
manager,
|
|
19852
|
-
|
|
19853
|
-
|
|
19918
|
+
assigners: authorizers,
|
|
19919
|
+
delegator,
|
|
19920
|
+
registrar: registrar ?? tryAsServiceId(0), // introduced in 0.7.1
|
|
19854
19921
|
autoAccumulateServices: autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit })),
|
|
19855
19922
|
});
|
|
19856
19923
|
return result_Result.ok(result_OK);
|
|
@@ -19966,8 +20033,11 @@ class AccumulateExternalities {
|
|
|
19966
20033
|
}
|
|
19967
20034
|
}
|
|
19968
20035
|
function bumpServiceId(serviceId) {
|
|
19969
|
-
const mod =
|
|
19970
|
-
|
|
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));
|
|
19971
20041
|
}
|
|
19972
20042
|
|
|
19973
20043
|
;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-state.ts
|
|
@@ -20623,6 +20693,8 @@ class AccumulateData {
|
|
|
20623
20693
|
|
|
20624
20694
|
|
|
20625
20695
|
|
|
20696
|
+
|
|
20697
|
+
|
|
20626
20698
|
/**
|
|
20627
20699
|
* A function that removes duplicates but does not change order - it keeps the first occurence.
|
|
20628
20700
|
*/
|
|
@@ -20652,7 +20724,7 @@ const NEXT_ID_CODEC = descriptors_codec.object({
|
|
|
20652
20724
|
*
|
|
20653
20725
|
* Please not that it does not call `check` function!
|
|
20654
20726
|
*
|
|
20655
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
20727
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/2fa9042fc304?v=0.7.2
|
|
20656
20728
|
*/
|
|
20657
20729
|
function generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blake2b) {
|
|
20658
20730
|
const encoded = encoder_Encoder.encodeObject(NEXT_ID_CODEC, {
|
|
@@ -20662,7 +20734,11 @@ function generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blak
|
|
|
20662
20734
|
}, chainSpec);
|
|
20663
20735
|
const result = blake2b.hashBytes(encoded).raw.subarray(0, 4);
|
|
20664
20736
|
const number = leBytesAsU32(result) >>> 0;
|
|
20665
|
-
|
|
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);
|
|
20666
20742
|
}
|
|
20667
20743
|
|
|
20668
20744
|
;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-queue.ts
|
|
@@ -21074,7 +21150,7 @@ class Assign {
|
|
|
21074
21150
|
// o
|
|
21075
21151
|
const authorizationQueueStart = regs.get(8);
|
|
21076
21152
|
// a
|
|
21077
|
-
const
|
|
21153
|
+
const assigners = getServiceId(regs.get(9));
|
|
21078
21154
|
const res = safeAllocUint8Array(hash_HASH_SIZE * AUTHORIZATION_QUEUE_SIZE);
|
|
21079
21155
|
const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
|
|
21080
21156
|
// error while reading the memory.
|
|
@@ -21091,7 +21167,7 @@ class Assign {
|
|
|
21091
21167
|
const decoder = decoder_Decoder.fromBlob(res);
|
|
21092
21168
|
const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE), AUTHORIZATION_QUEUE_SIZE);
|
|
21093
21169
|
const fixedSizeAuthQueue = FixedSizeArray.new(authQueue, AUTHORIZATION_QUEUE_SIZE);
|
|
21094
|
-
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue,
|
|
21170
|
+
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
|
|
21095
21171
|
if (result.isOk) {
|
|
21096
21172
|
regs.set(IN_OUT_REG, HostCallResult.OK);
|
|
21097
21173
|
logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
|
|
@@ -21140,7 +21216,9 @@ class Bless {
|
|
|
21140
21216
|
chainSpec;
|
|
21141
21217
|
index = host_call_handler_tryAsHostCallIndex(14);
|
|
21142
21218
|
basicGasCost = gas_tryAsSmallGas(10);
|
|
21143
|
-
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);
|
|
21144
21222
|
constructor(currentServiceId, partialState, chainSpec) {
|
|
21145
21223
|
this.currentServiceId = currentServiceId;
|
|
21146
21224
|
this.partialState = partialState;
|
|
@@ -21150,14 +21228,17 @@ class Bless {
|
|
|
21150
21228
|
// `m`: manager service (can change privileged services)
|
|
21151
21229
|
const manager = getServiceId(regs.get(bless_IN_OUT_REG));
|
|
21152
21230
|
// `a`: manages authorization queue
|
|
21153
|
-
// NOTE It can be either ServiceId (pre GP 067) or memory index (GP ^067)
|
|
21154
21231
|
const authorization = regs.get(8);
|
|
21155
21232
|
// `v`: manages validator keys
|
|
21156
|
-
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);
|
|
21157
21238
|
// `o`: memory offset
|
|
21158
|
-
const sourceStart = regs.get(10);
|
|
21239
|
+
const sourceStart = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? regs.get(11) : regs.get(10);
|
|
21159
21240
|
// `n`: number of items in the auto-accumulate dictionary
|
|
21160
|
-
const numberOfItems = regs.get(11);
|
|
21241
|
+
const numberOfItems = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? regs.get(12) : regs.get(11);
|
|
21161
21242
|
/*
|
|
21162
21243
|
* `z`: array of key-value pairs serviceId -> gas that auto-accumulate every block
|
|
21163
21244
|
* https://graypaper.fluffylabs.dev/#/7e6ff6a/368100368100?v=0.6.7
|
|
@@ -21171,7 +21252,7 @@ class Bless {
|
|
|
21171
21252
|
decoder.resetTo(0);
|
|
21172
21253
|
const memoryReadResult = memory.loadInto(result, memIndex);
|
|
21173
21254
|
if (memoryReadResult.isError) {
|
|
21174
|
-
logger_logger.trace `BLESS(${manager}, ${
|
|
21255
|
+
logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}) <- PANIC`;
|
|
21175
21256
|
return PvmExecution.Panic;
|
|
21176
21257
|
}
|
|
21177
21258
|
const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
|
|
@@ -21184,24 +21265,25 @@ class Bless {
|
|
|
21184
21265
|
const authorizersDecoder = decoder_Decoder.fromBlob(res);
|
|
21185
21266
|
const memoryReadResult = memory.loadInto(res, authorization);
|
|
21186
21267
|
if (memoryReadResult.isError) {
|
|
21187
|
-
logger_logger.trace `BLESS(${manager}, ${
|
|
21268
|
+
logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- PANIC`;
|
|
21188
21269
|
return PvmExecution.Panic;
|
|
21189
21270
|
}
|
|
21271
|
+
// `a`
|
|
21190
21272
|
const authorizers = tryAsPerCore(authorizersDecoder.sequenceFixLen(descriptors_codec.u32.asOpaque(), this.chainSpec.coresCount), this.chainSpec);
|
|
21191
|
-
const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers,
|
|
21273
|
+
const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulateEntries);
|
|
21192
21274
|
if (updateResult.isOk) {
|
|
21193
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
21275
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- OK`;
|
|
21194
21276
|
regs.set(bless_IN_OUT_REG, HostCallResult.OK);
|
|
21195
21277
|
return;
|
|
21196
21278
|
}
|
|
21197
21279
|
const e = updateResult.error;
|
|
21198
21280
|
if (e === UpdatePrivilegesError.UnprivilegedService) {
|
|
21199
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
21281
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- HUH`;
|
|
21200
21282
|
regs.set(bless_IN_OUT_REG, HostCallResult.HUH);
|
|
21201
21283
|
return;
|
|
21202
21284
|
}
|
|
21203
21285
|
if (e === UpdatePrivilegesError.InvalidServiceId) {
|
|
21204
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
21286
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- WHO`;
|
|
21205
21287
|
regs.set(bless_IN_OUT_REG, HostCallResult.WHO);
|
|
21206
21288
|
return;
|
|
21207
21289
|
}
|
|
@@ -21453,7 +21535,9 @@ class New {
|
|
|
21453
21535
|
partialState;
|
|
21454
21536
|
index = host_call_handler_tryAsHostCallIndex(18);
|
|
21455
21537
|
basicGasCost = gas_tryAsSmallGas(10);
|
|
21456
|
-
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);
|
|
21457
21541
|
constructor(currentServiceId, partialState) {
|
|
21458
21542
|
this.currentServiceId = currentServiceId;
|
|
21459
21543
|
this.partialState = partialState;
|
|
@@ -21469,16 +21553,18 @@ class New {
|
|
|
21469
21553
|
const allowance = tryAsServiceGas(regs.get(10));
|
|
21470
21554
|
// `f`
|
|
21471
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);
|
|
21472
21558
|
// `c`
|
|
21473
21559
|
const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
21474
21560
|
const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
|
|
21475
21561
|
// error while reading the memory.
|
|
21476
21562
|
if (memoryReadResult.isError) {
|
|
21477
|
-
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- PANIC`;
|
|
21563
|
+
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
|
|
21478
21564
|
return PvmExecution.Panic;
|
|
21479
21565
|
}
|
|
21480
|
-
const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage);
|
|
21481
|
-
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)}`;
|
|
21482
21568
|
if (assignedId.isOk) {
|
|
21483
21569
|
regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
|
|
21484
21570
|
return;
|
|
@@ -21492,6 +21578,11 @@ class New {
|
|
|
21492
21578
|
regs.set(new_IN_OUT_REG, HostCallResult.HUH);
|
|
21493
21579
|
return;
|
|
21494
21580
|
}
|
|
21581
|
+
// Post 0.7.1
|
|
21582
|
+
if (e === NewServiceError.RegistrarServiceIdAlreadyTaken) {
|
|
21583
|
+
regs.set(new_IN_OUT_REG, HostCallResult.FULL);
|
|
21584
|
+
return;
|
|
21585
|
+
}
|
|
21495
21586
|
debug_assertNever(e);
|
|
21496
21587
|
}
|
|
21497
21588
|
}
|
|
@@ -22749,7 +22840,7 @@ class Accumulate {
|
|
|
22749
22840
|
}
|
|
22750
22841
|
const nextServiceId = generateNextServiceId({ serviceId, entropy, timeslot: slot }, this.chainSpec, this.blake2b);
|
|
22751
22842
|
const partialState = new AccumulateExternalities(this.chainSpec, this.blake2b, new PartiallyUpdatedState(this.state, inputStateUpdate), serviceId, nextServiceId, slot);
|
|
22752
|
-
const fetchExternalities = Compatibility.isGreaterOrEqual(GpVersion.
|
|
22843
|
+
const fetchExternalities = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
22753
22844
|
? FetchExternalities.createForAccumulate({ entropy, transfers, operands }, this.chainSpec)
|
|
22754
22845
|
: FetchExternalities.createForPre071Accumulate({ entropy, operands }, this.chainSpec);
|
|
22755
22846
|
const externalities = {
|
|
@@ -22864,7 +22955,7 @@ class Accumulate {
|
|
|
22864
22955
|
const accumulateData = new AccumulateData(reportsToAccumulateInParallel, transfers, autoAccumulateServices);
|
|
22865
22956
|
const reportsToAccumulateSequentially = reports.subview(i);
|
|
22866
22957
|
const { gasCost, state: stateAfterParallelAcc, ...rest } = await this.accumulateInParallel(accumulateData, slot, entropy, statistics, stateUpdate);
|
|
22867
|
-
const newTransfers = stateAfterParallelAcc.
|
|
22958
|
+
const newTransfers = stateAfterParallelAcc.takeTransfers();
|
|
22868
22959
|
assertEmpty(rest);
|
|
22869
22960
|
// NOTE [ToDr] recursive invocation
|
|
22870
22961
|
const { accumulatedReports, gasCost: seqGasCost, state, ...seqRest } = await this.accumulateSequentially(tryAsServiceGas(gasLimit - gasCost), reportsToAccumulateSequentially, newTransfers, slot, entropy, statistics, stateAfterParallelAcc, []);
|
|
@@ -22900,17 +22991,17 @@ class Accumulate {
|
|
|
22900
22991
|
statistics.set(serviceId, serviceStatistics);
|
|
22901
22992
|
currentState = stateUpdate === null ? checkpoint : stateUpdate;
|
|
22902
22993
|
if (Compatibility.is(GpVersion.V0_7_0) && serviceId === currentManager) {
|
|
22903
|
-
const newV = currentState.privilegedServices?.
|
|
22994
|
+
const newV = currentState.privilegedServices?.delegator;
|
|
22904
22995
|
if (currentState.privilegedServices !== null && newV !== undefined && serviceIds.includes(newV)) {
|
|
22905
|
-
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+`;
|
|
22906
22997
|
// Since serviceIds already contains newV, this service gets accumulated twice.
|
|
22907
22998
|
// To avoid double-counting, we skip stats and gas cost tracking here.
|
|
22908
|
-
// We need this accumulation to get the correct `
|
|
22999
|
+
// We need this accumulation to get the correct `delegator`
|
|
22909
23000
|
const { stateUpdate } = await this.accumulateSingleService(newV, [], accumulateData.getOperands(newV), accumulateData.getGasCost(newV), slot, entropy, checkpoint);
|
|
22910
|
-
const correctV = stateUpdate?.privilegedServices?.
|
|
23001
|
+
const correctV = stateUpdate?.privilegedServices?.delegator ?? this.state.privilegedServices.delegator;
|
|
22911
23002
|
currentState.privilegedServices = PrivilegedServices.create({
|
|
22912
23003
|
...currentState.privilegedServices,
|
|
22913
|
-
|
|
23004
|
+
delegator: correctV,
|
|
22914
23005
|
});
|
|
22915
23006
|
}
|
|
22916
23007
|
}
|