@typeberry/jam 0.1.3-8258907 → 0.1.3-b0374a8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bootstrap-generator.mjs +279 -249
- package/bootstrap-generator.mjs.map +1 -1
- package/bootstrap-importer.mjs +408 -323
- package/bootstrap-importer.mjs.map +1 -1
- package/bootstrap-network.mjs +279 -249
- package/bootstrap-network.mjs.map +1 -1
- package/index.js +408 -323
- package/index.js.map +1 -1
- package/package.json +1 -1
package/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,7 +15146,7 @@ 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;
|
|
@@ -17255,13 +17285,6 @@ class BitOps {
|
|
|
17255
17285
|
}
|
|
17256
17286
|
}
|
|
17257
17287
|
|
|
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
17288
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-utils.ts
|
|
17266
17289
|
|
|
17267
17290
|
|
|
@@ -19291,6 +19314,8 @@ var NewServiceError;
|
|
|
19291
19314
|
NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
|
|
19292
19315
|
/** Service is not privileged to set gratis storage. */
|
|
19293
19316
|
NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
|
|
19317
|
+
/** Registrar attempting to create a service with already existing id. */
|
|
19318
|
+
NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
|
|
19294
19319
|
})(NewServiceError || (NewServiceError = {}));
|
|
19295
19320
|
var UpdatePrivilegesError;
|
|
19296
19321
|
(function (UpdatePrivilegesError) {
|
|
@@ -19427,7 +19452,7 @@ const HostCallResult = {
|
|
|
19427
19452
|
OOB: numbers_tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
|
|
19428
19453
|
/** Index unknown. */
|
|
19429
19454
|
WHO: numbers_tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
|
|
19430
|
-
/** Storage full. */
|
|
19455
|
+
/** Storage full or resource already allocated. */
|
|
19431
19456
|
FULL: numbers_tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
|
|
19432
19457
|
/** Core index unknown. */
|
|
19433
19458
|
CORE: numbers_tryAsU64(0xfffffffffffffffan), // 2**64 - 6
|
|
@@ -19435,7 +19460,7 @@ const HostCallResult = {
|
|
|
19435
19460
|
CASH: numbers_tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
|
|
19436
19461
|
/** Gas limit too low. */
|
|
19437
19462
|
LOW: numbers_tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
|
|
19438
|
-
/** The item is already solicited
|
|
19463
|
+
/** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
|
|
19439
19464
|
HUH: numbers_tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
|
|
19440
19465
|
/** The return value indicating general success. */
|
|
19441
19466
|
OK: numbers_tryAsU64(0n),
|
|
@@ -19489,6 +19514,7 @@ function clampU64ToU32(value) {
|
|
|
19489
19514
|
|
|
19490
19515
|
|
|
19491
19516
|
|
|
19517
|
+
|
|
19492
19518
|
/**
|
|
19493
19519
|
* Number of storage items required for ejection of the service.
|
|
19494
19520
|
*
|
|
@@ -19580,10 +19606,13 @@ class AccumulateExternalities {
|
|
|
19580
19606
|
const isExpired = status.data[1] < t - this.chainSpec.preimageExpungePeriod;
|
|
19581
19607
|
return [isExpired, isExpired ? "" : "not expired"];
|
|
19582
19608
|
}
|
|
19583
|
-
/** `check`: https://graypaper.fluffylabs.dev/#/
|
|
19609
|
+
/** `check`: https://graypaper.fluffylabs.dev/#/ab2cdbd/30c60330c603?v=0.7.2 */
|
|
19584
19610
|
getNextAvailableServiceId(serviceId) {
|
|
19585
19611
|
let currentServiceId = serviceId;
|
|
19586
|
-
const mod =
|
|
19612
|
+
const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
19613
|
+
? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
|
|
19614
|
+
: 2 ** 32 - 2 ** 9;
|
|
19615
|
+
const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
|
|
19587
19616
|
for (;;) {
|
|
19588
19617
|
const service = this.getServiceInfo(currentServiceId);
|
|
19589
19618
|
// we found an empty id
|
|
@@ -19591,7 +19620,7 @@ class AccumulateExternalities {
|
|
|
19591
19620
|
return currentServiceId;
|
|
19592
19621
|
}
|
|
19593
19622
|
// keep trying
|
|
19594
|
-
currentServiceId = tryAsServiceId(((currentServiceId -
|
|
19623
|
+
currentServiceId = tryAsServiceId(((currentServiceId - offset + 1 + mod) % mod) + offset);
|
|
19595
19624
|
}
|
|
19596
19625
|
}
|
|
19597
19626
|
checkPreimageStatus(hash, length) {
|
|
@@ -19748,8 +19777,7 @@ class AccumulateExternalities {
|
|
|
19748
19777
|
}));
|
|
19749
19778
|
return result_Result.ok(result_OK);
|
|
19750
19779
|
}
|
|
19751
|
-
newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage) {
|
|
19752
|
-
const newServiceId = this.nextNewServiceId;
|
|
19780
|
+
newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage, wantedServiceId) {
|
|
19753
19781
|
// calculate the threshold. Storage is empty, one preimage requested.
|
|
19754
19782
|
// https://graypaper.fluffylabs.dev/#/7e6ff6a/115901115901?v=0.6.7
|
|
19755
19783
|
const items = numbers_tryAsU32(2 * 1 + 0);
|
|
@@ -19770,30 +19798,59 @@ class AccumulateExternalities {
|
|
|
19770
19798
|
if (balanceLeftForCurrent < thresholdForCurrent || bytes.overflow) {
|
|
19771
19799
|
return result_Result.error(NewServiceError.InsufficientFunds);
|
|
19772
19800
|
}
|
|
19801
|
+
// `a`: https://graypaper.fluffylabs.dev/#/ab2cdbd/366b02366d02?v=0.7.2
|
|
19802
|
+
const newAccount = ServiceAccountInfo.create({
|
|
19803
|
+
codeHash,
|
|
19804
|
+
balance: thresholdForNew,
|
|
19805
|
+
accumulateMinGas,
|
|
19806
|
+
onTransferMinGas,
|
|
19807
|
+
storageUtilisationBytes: bytes.value,
|
|
19808
|
+
storageUtilisationCount: items,
|
|
19809
|
+
gratisStorage,
|
|
19810
|
+
created: this.currentTimeslot,
|
|
19811
|
+
lastAccumulation: common_tryAsTimeSlot(0),
|
|
19812
|
+
parentService: this.currentServiceId,
|
|
19813
|
+
});
|
|
19814
|
+
const newLookupItem = new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([]));
|
|
19815
|
+
// `s`: https://graypaper.fluffylabs.dev/#/ab2cdbd/361003361003?v=0.7.2
|
|
19816
|
+
const updatedCurrentAccount = ServiceAccountInfo.create({
|
|
19817
|
+
...currentService,
|
|
19818
|
+
balance: numbers_tryAsU64(balanceLeftForCurrent),
|
|
19819
|
+
});
|
|
19820
|
+
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
|
|
19821
|
+
if (wantedServiceId < MIN_PUBLIC_SERVICE_INDEX &&
|
|
19822
|
+
this.currentServiceId === this.updatedState.getPrivilegedServices().registrar) {
|
|
19823
|
+
// NOTE: It's safe to cast to `Number` here, bcs here service ID cannot be bigger than 2**16
|
|
19824
|
+
const newServiceId = tryAsServiceId(Number(wantedServiceId));
|
|
19825
|
+
if (this.getServiceInfo(newServiceId) !== null) {
|
|
19826
|
+
return result_Result.error(NewServiceError.RegistrarServiceIdAlreadyTaken);
|
|
19827
|
+
}
|
|
19828
|
+
// add the new service with selected ID
|
|
19829
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36be0336c003?v=0.7.2
|
|
19830
|
+
this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
|
|
19831
|
+
serviceId: newServiceId,
|
|
19832
|
+
serviceInfo: newAccount,
|
|
19833
|
+
lookupHistory: newLookupItem,
|
|
19834
|
+
}));
|
|
19835
|
+
// update the balance of current service
|
|
19836
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36c20336c403?v=0.7.2
|
|
19837
|
+
this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
|
|
19838
|
+
return result_Result.ok(newServiceId);
|
|
19839
|
+
}
|
|
19840
|
+
// NOTE: in case the service is not a registrar or the requested serviceId is out of range,
|
|
19841
|
+
// we completely ignore the `wantedServiceId` and assign a random one
|
|
19842
|
+
}
|
|
19843
|
+
const newServiceId = this.nextNewServiceId;
|
|
19773
19844
|
// add the new service
|
|
19774
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
19845
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36e70336e903?v=0.7.2
|
|
19775
19846
|
this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
|
|
19776
19847
|
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([])),
|
|
19848
|
+
serviceInfo: newAccount,
|
|
19849
|
+
lookupHistory: newLookupItem,
|
|
19790
19850
|
}));
|
|
19791
19851
|
// 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
|
-
}));
|
|
19852
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36ec0336ee03?v=0.7.2
|
|
19853
|
+
this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
|
|
19797
19854
|
// update the next service id we are going to create next
|
|
19798
19855
|
// https://graypaper.fluffylabs.dev/#/7e6ff6a/36a70336a703?v=0.6.7
|
|
19799
19856
|
this.nextNewServiceId = this.getNextAvailableServiceId(bumpServiceId(newServiceId));
|
|
@@ -19811,9 +19868,9 @@ class AccumulateExternalities {
|
|
|
19811
19868
|
}
|
|
19812
19869
|
updateValidatorsData(validatorsData) {
|
|
19813
19870
|
/** 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: ${
|
|
19871
|
+
const currentDelegator = this.updatedState.getPrivilegedServices().delegator;
|
|
19872
|
+
if (currentDelegator !== this.currentServiceId) {
|
|
19873
|
+
accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${currentDelegator}) and cannot update validators data. Ignoring`;
|
|
19817
19874
|
return result_Result.error(UnprivilegedError);
|
|
19818
19875
|
}
|
|
19819
19876
|
this.updatedState.stateUpdate.validatorsData = validatorsData;
|
|
@@ -19823,34 +19880,38 @@ class AccumulateExternalities {
|
|
|
19823
19880
|
/** https://graypaper.fluffylabs.dev/#/9a08063/362202362202?v=0.6.6 */
|
|
19824
19881
|
this.checkpointedState = AccumulationStateUpdate.copyFrom(this.updatedState.stateUpdate);
|
|
19825
19882
|
}
|
|
19826
|
-
updateAuthorizationQueue(coreIndex, authQueue,
|
|
19883
|
+
updateAuthorizationQueue(coreIndex, authQueue, assigners) {
|
|
19827
19884
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/36a40136a401?v=0.6.7 */
|
|
19828
19885
|
// 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: ${
|
|
19886
|
+
const currentAssigners = this.updatedState.getPrivilegedServices().assigners[coreIndex];
|
|
19887
|
+
if (currentAssigners !== this.currentServiceId) {
|
|
19888
|
+
accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not an auth manager of core ${coreIndex} (expected: ${currentAssigners}) and cannot update authorization queue.`;
|
|
19832
19889
|
return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
|
|
19833
19890
|
}
|
|
19834
|
-
if (
|
|
19835
|
-
accumulate_externalities_logger.trace `The new auth manager is not a valid service id
|
|
19891
|
+
if (assigners === null && Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
|
|
19892
|
+
accumulate_externalities_logger.trace `The new auth manager is not a valid service id.`;
|
|
19836
19893
|
return result_Result.error(UpdatePrivilegesError.InvalidServiceId);
|
|
19837
19894
|
}
|
|
19838
19895
|
this.updatedState.stateUpdate.authorizationQueues.set(coreIndex, authQueue);
|
|
19839
19896
|
return result_Result.ok(result_OK);
|
|
19840
19897
|
}
|
|
19841
|
-
updatePrivilegedServices(manager, authorizers,
|
|
19898
|
+
updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate) {
|
|
19842
19899
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/36d90036de00?v=0.6.7 */
|
|
19843
19900
|
const currentManager = this.updatedState.getPrivilegedServices().manager;
|
|
19844
19901
|
if (currentManager !== this.currentServiceId) {
|
|
19845
19902
|
return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
|
|
19846
19903
|
}
|
|
19847
|
-
if (manager === null ||
|
|
19848
|
-
return result_Result.error(UpdatePrivilegesError.InvalidServiceId);
|
|
19904
|
+
if (manager === null || delegator === null) {
|
|
19905
|
+
return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Either manager or delegator is not valid service id.");
|
|
19906
|
+
}
|
|
19907
|
+
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && registrar === null) {
|
|
19908
|
+
return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Register manager is not valid service id.");
|
|
19849
19909
|
}
|
|
19850
19910
|
this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
|
|
19851
19911
|
manager,
|
|
19852
|
-
|
|
19853
|
-
|
|
19912
|
+
assigners: authorizers,
|
|
19913
|
+
delegator,
|
|
19914
|
+
registrar: registrar ?? tryAsServiceId(0), // introduced in 0.7.1
|
|
19854
19915
|
autoAccumulateServices: autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit })),
|
|
19855
19916
|
});
|
|
19856
19917
|
return result_Result.ok(result_OK);
|
|
@@ -19966,8 +20027,11 @@ class AccumulateExternalities {
|
|
|
19966
20027
|
}
|
|
19967
20028
|
}
|
|
19968
20029
|
function bumpServiceId(serviceId) {
|
|
19969
|
-
const mod =
|
|
19970
|
-
|
|
20030
|
+
const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
20031
|
+
? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
|
|
20032
|
+
: 2 ** 32 - 2 ** 9;
|
|
20033
|
+
const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
|
|
20034
|
+
return tryAsServiceId(offset + ((serviceId - offset + 42 + mod) % mod));
|
|
19971
20035
|
}
|
|
19972
20036
|
|
|
19973
20037
|
;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-state.ts
|
|
@@ -20623,6 +20687,8 @@ class AccumulateData {
|
|
|
20623
20687
|
|
|
20624
20688
|
|
|
20625
20689
|
|
|
20690
|
+
|
|
20691
|
+
|
|
20626
20692
|
/**
|
|
20627
20693
|
* A function that removes duplicates but does not change order - it keeps the first occurence.
|
|
20628
20694
|
*/
|
|
@@ -20652,7 +20718,7 @@ const NEXT_ID_CODEC = descriptors_codec.object({
|
|
|
20652
20718
|
*
|
|
20653
20719
|
* Please not that it does not call `check` function!
|
|
20654
20720
|
*
|
|
20655
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
20721
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/2fa9042fc304?v=0.7.2
|
|
20656
20722
|
*/
|
|
20657
20723
|
function generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blake2b) {
|
|
20658
20724
|
const encoded = encoder_Encoder.encodeObject(NEXT_ID_CODEC, {
|
|
@@ -20662,7 +20728,11 @@ function generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blak
|
|
|
20662
20728
|
}, chainSpec);
|
|
20663
20729
|
const result = blake2b.hashBytes(encoded).raw.subarray(0, 4);
|
|
20664
20730
|
const number = leBytesAsU32(result) >>> 0;
|
|
20665
|
-
|
|
20731
|
+
const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
20732
|
+
? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
|
|
20733
|
+
: 2 ** 32 - 2 ** 9;
|
|
20734
|
+
const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
|
|
20735
|
+
return tryAsServiceId((number % mod) + offset);
|
|
20666
20736
|
}
|
|
20667
20737
|
|
|
20668
20738
|
;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-queue.ts
|
|
@@ -21074,7 +21144,7 @@ class Assign {
|
|
|
21074
21144
|
// o
|
|
21075
21145
|
const authorizationQueueStart = regs.get(8);
|
|
21076
21146
|
// a
|
|
21077
|
-
const
|
|
21147
|
+
const assigners = getServiceId(regs.get(9));
|
|
21078
21148
|
const res = safeAllocUint8Array(hash_HASH_SIZE * AUTHORIZATION_QUEUE_SIZE);
|
|
21079
21149
|
const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
|
|
21080
21150
|
// error while reading the memory.
|
|
@@ -21091,7 +21161,7 @@ class Assign {
|
|
|
21091
21161
|
const decoder = decoder_Decoder.fromBlob(res);
|
|
21092
21162
|
const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE), AUTHORIZATION_QUEUE_SIZE);
|
|
21093
21163
|
const fixedSizeAuthQueue = FixedSizeArray.new(authQueue, AUTHORIZATION_QUEUE_SIZE);
|
|
21094
|
-
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue,
|
|
21164
|
+
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
|
|
21095
21165
|
if (result.isOk) {
|
|
21096
21166
|
regs.set(IN_OUT_REG, HostCallResult.OK);
|
|
21097
21167
|
logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
|
|
@@ -21140,7 +21210,9 @@ class Bless {
|
|
|
21140
21210
|
chainSpec;
|
|
21141
21211
|
index = host_call_handler_tryAsHostCallIndex(14);
|
|
21142
21212
|
basicGasCost = gas_tryAsSmallGas(10);
|
|
21143
|
-
tracedRegisters =
|
|
21213
|
+
tracedRegisters = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
21214
|
+
? traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11, 12)
|
|
21215
|
+
: traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11);
|
|
21144
21216
|
constructor(currentServiceId, partialState, chainSpec) {
|
|
21145
21217
|
this.currentServiceId = currentServiceId;
|
|
21146
21218
|
this.partialState = partialState;
|
|
@@ -21150,14 +21222,17 @@ class Bless {
|
|
|
21150
21222
|
// `m`: manager service (can change privileged services)
|
|
21151
21223
|
const manager = getServiceId(regs.get(bless_IN_OUT_REG));
|
|
21152
21224
|
// `a`: manages authorization queue
|
|
21153
|
-
// NOTE It can be either ServiceId (pre GP 067) or memory index (GP ^067)
|
|
21154
21225
|
const authorization = regs.get(8);
|
|
21155
21226
|
// `v`: manages validator keys
|
|
21156
|
-
const
|
|
21227
|
+
const delegator = getServiceId(regs.get(9));
|
|
21228
|
+
// `r`: manages creation of new services with id within protected range
|
|
21229
|
+
const registrar = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
21230
|
+
? getServiceId(regs.get(10))
|
|
21231
|
+
: tryAsServiceId(2 ** 32 - 1);
|
|
21157
21232
|
// `o`: memory offset
|
|
21158
|
-
const sourceStart = regs.get(10);
|
|
21233
|
+
const sourceStart = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? regs.get(11) : regs.get(10);
|
|
21159
21234
|
// `n`: number of items in the auto-accumulate dictionary
|
|
21160
|
-
const numberOfItems = regs.get(11);
|
|
21235
|
+
const numberOfItems = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? regs.get(12) : regs.get(11);
|
|
21161
21236
|
/*
|
|
21162
21237
|
* `z`: array of key-value pairs serviceId -> gas that auto-accumulate every block
|
|
21163
21238
|
* https://graypaper.fluffylabs.dev/#/7e6ff6a/368100368100?v=0.6.7
|
|
@@ -21171,7 +21246,7 @@ class Bless {
|
|
|
21171
21246
|
decoder.resetTo(0);
|
|
21172
21247
|
const memoryReadResult = memory.loadInto(result, memIndex);
|
|
21173
21248
|
if (memoryReadResult.isError) {
|
|
21174
|
-
logger_logger.trace `BLESS(${manager}, ${
|
|
21249
|
+
logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}) <- PANIC`;
|
|
21175
21250
|
return PvmExecution.Panic;
|
|
21176
21251
|
}
|
|
21177
21252
|
const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
|
|
@@ -21184,24 +21259,25 @@ class Bless {
|
|
|
21184
21259
|
const authorizersDecoder = decoder_Decoder.fromBlob(res);
|
|
21185
21260
|
const memoryReadResult = memory.loadInto(res, authorization);
|
|
21186
21261
|
if (memoryReadResult.isError) {
|
|
21187
|
-
logger_logger.trace `BLESS(${manager}, ${
|
|
21262
|
+
logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- PANIC`;
|
|
21188
21263
|
return PvmExecution.Panic;
|
|
21189
21264
|
}
|
|
21265
|
+
// `a`
|
|
21190
21266
|
const authorizers = tryAsPerCore(authorizersDecoder.sequenceFixLen(descriptors_codec.u32.asOpaque(), this.chainSpec.coresCount), this.chainSpec);
|
|
21191
|
-
const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers,
|
|
21267
|
+
const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulateEntries);
|
|
21192
21268
|
if (updateResult.isOk) {
|
|
21193
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
21269
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- OK`;
|
|
21194
21270
|
regs.set(bless_IN_OUT_REG, HostCallResult.OK);
|
|
21195
21271
|
return;
|
|
21196
21272
|
}
|
|
21197
21273
|
const e = updateResult.error;
|
|
21198
21274
|
if (e === UpdatePrivilegesError.UnprivilegedService) {
|
|
21199
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
21275
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- HUH`;
|
|
21200
21276
|
regs.set(bless_IN_OUT_REG, HostCallResult.HUH);
|
|
21201
21277
|
return;
|
|
21202
21278
|
}
|
|
21203
21279
|
if (e === UpdatePrivilegesError.InvalidServiceId) {
|
|
21204
|
-
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${
|
|
21280
|
+
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- WHO`;
|
|
21205
21281
|
regs.set(bless_IN_OUT_REG, HostCallResult.WHO);
|
|
21206
21282
|
return;
|
|
21207
21283
|
}
|
|
@@ -21453,7 +21529,9 @@ class New {
|
|
|
21453
21529
|
partialState;
|
|
21454
21530
|
index = host_call_handler_tryAsHostCallIndex(18);
|
|
21455
21531
|
basicGasCost = gas_tryAsSmallGas(10);
|
|
21456
|
-
tracedRegisters =
|
|
21532
|
+
tracedRegisters = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
21533
|
+
? traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11, 12)
|
|
21534
|
+
: traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11);
|
|
21457
21535
|
constructor(currentServiceId, partialState) {
|
|
21458
21536
|
this.currentServiceId = currentServiceId;
|
|
21459
21537
|
this.partialState = partialState;
|
|
@@ -21469,16 +21547,18 @@ class New {
|
|
|
21469
21547
|
const allowance = tryAsServiceGas(regs.get(10));
|
|
21470
21548
|
// `f`
|
|
21471
21549
|
const gratisStorage = regs.get(11);
|
|
21550
|
+
// `i`: requested service id. Ignored if current service is not registrar or value is bigger than `S`.
|
|
21551
|
+
const requestedServiceId = regs.get(12);
|
|
21472
21552
|
// `c`
|
|
21473
21553
|
const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
21474
21554
|
const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
|
|
21475
21555
|
// error while reading the memory.
|
|
21476
21556
|
if (memoryReadResult.isError) {
|
|
21477
|
-
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- PANIC`;
|
|
21557
|
+
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
|
|
21478
21558
|
return PvmExecution.Panic;
|
|
21479
21559
|
}
|
|
21480
|
-
const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage);
|
|
21481
|
-
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- ${resultToString(assignedId)}`;
|
|
21560
|
+
const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage, requestedServiceId);
|
|
21561
|
+
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${resultToString(assignedId)}`;
|
|
21482
21562
|
if (assignedId.isOk) {
|
|
21483
21563
|
regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
|
|
21484
21564
|
return;
|
|
@@ -21492,6 +21572,11 @@ class New {
|
|
|
21492
21572
|
regs.set(new_IN_OUT_REG, HostCallResult.HUH);
|
|
21493
21573
|
return;
|
|
21494
21574
|
}
|
|
21575
|
+
// Post 0.7.1
|
|
21576
|
+
if (e === NewServiceError.RegistrarServiceIdAlreadyTaken) {
|
|
21577
|
+
regs.set(new_IN_OUT_REG, HostCallResult.FULL);
|
|
21578
|
+
return;
|
|
21579
|
+
}
|
|
21495
21580
|
debug_assertNever(e);
|
|
21496
21581
|
}
|
|
21497
21582
|
}
|
|
@@ -22900,17 +22985,17 @@ class Accumulate {
|
|
|
22900
22985
|
statistics.set(serviceId, serviceStatistics);
|
|
22901
22986
|
currentState = stateUpdate === null ? checkpoint : stateUpdate;
|
|
22902
22987
|
if (Compatibility.is(GpVersion.V0_7_0) && serviceId === currentManager) {
|
|
22903
|
-
const newV = currentState.privilegedServices?.
|
|
22988
|
+
const newV = currentState.privilegedServices?.delegator;
|
|
22904
22989
|
if (currentState.privilegedServices !== null && newV !== undefined && serviceIds.includes(newV)) {
|
|
22905
|
-
accumulate_logger.info `Entering completely incorrect code that probably reverts
|
|
22990
|
+
accumulate_logger.info `Entering completely incorrect code that probably reverts delegator change. This is valid in 0.7.0 only and incorrect in 0.7.1+`;
|
|
22906
22991
|
// Since serviceIds already contains newV, this service gets accumulated twice.
|
|
22907
22992
|
// To avoid double-counting, we skip stats and gas cost tracking here.
|
|
22908
|
-
// We need this accumulation to get the correct `
|
|
22993
|
+
// We need this accumulation to get the correct `delegator`
|
|
22909
22994
|
const { stateUpdate } = await this.accumulateSingleService(newV, [], accumulateData.getOperands(newV), accumulateData.getGasCost(newV), slot, entropy, checkpoint);
|
|
22910
|
-
const correctV = stateUpdate?.privilegedServices?.
|
|
22995
|
+
const correctV = stateUpdate?.privilegedServices?.delegator ?? this.state.privilegedServices.delegator;
|
|
22911
22996
|
currentState.privilegedServices = PrivilegedServices.create({
|
|
22912
22997
|
...currentState.privilegedServices,
|
|
22913
|
-
|
|
22998
|
+
delegator: correctV,
|
|
22914
22999
|
});
|
|
22915
23000
|
}
|
|
22916
23001
|
}
|