@typeberry/convert 0.1.3-8fd7637 → 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.
Files changed (3) hide show
  1. package/index.js +422 -321
  2. package/index.js.map +1 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -4273,8 +4273,9 @@ function parseCurrentVersion(env) {
4273
4273
  }
4274
4274
  }
4275
4275
  function parseCurrentSuite(env) {
4276
- if (env === undefined)
4276
+ if (env === undefined) {
4277
4277
  return undefined;
4278
+ }
4278
4279
  switch (env) {
4279
4280
  case TestSuite.W3F_DAVXY:
4280
4281
  case TestSuite.JAMDUNA:
@@ -4705,10 +4706,12 @@ function test_deepEqual(actual, expected, { context = [], errorsCollector, ignor
4705
4706
  .sort((a, b) => {
4706
4707
  const aKey = `${a.key}`;
4707
4708
  const bKey = `${b.key}`;
4708
- if (aKey < bKey)
4709
+ if (aKey < bKey) {
4709
4710
  return -1;
4710
- if (bKey < aKey)
4711
+ }
4712
+ if (bKey < aKey) {
4711
4713
  return 1;
4714
+ }
4712
4715
  return 0;
4713
4716
  });
4714
4717
  };
@@ -5725,7 +5728,7 @@ class Skipper {
5725
5728
  *
5726
5729
  * Descriptors can be composed to form more complex typings.
5727
5730
  */
5728
- class descriptor_Descriptor {
5731
+ class Descriptor {
5729
5732
  name;
5730
5733
  sizeHint;
5731
5734
  encode;
@@ -5735,11 +5738,11 @@ class descriptor_Descriptor {
5735
5738
  View;
5736
5739
  /** New descriptor with specialized `View`. */
5737
5740
  static withView(name, sizeHint, encode, decode, skip, view) {
5738
- return new descriptor_Descriptor(name, sizeHint, encode, decode, skip, view);
5741
+ return new Descriptor(name, sizeHint, encode, decode, skip, view);
5739
5742
  }
5740
5743
  /** Create a new descriptor without a specialized `View`. */
5741
5744
  static new(name, sizeHint, encode, decode, skip) {
5742
- return new descriptor_Descriptor(name, sizeHint, encode, decode, skip, null);
5745
+ return new Descriptor(name, sizeHint, encode, decode, skip, null);
5743
5746
  }
5744
5747
  constructor(
5745
5748
  /** Descriptive name of the coded data. */
@@ -5776,7 +5779,7 @@ class descriptor_Descriptor {
5776
5779
  }
5777
5780
  /** Return a new descriptor that converts data into some other type. */
5778
5781
  convert(input, output) {
5779
- return new descriptor_Descriptor(this.name, this.sizeHint, (e, elem) => this.encode(e, input(elem)), (d) => output(this.decode(d)), this.skip, this.View);
5782
+ return new Descriptor(this.name, this.sizeHint, (e, elem) => this.encode(e, input(elem)), (d) => output(this.decode(d)), this.skip, this.View);
5780
5783
  }
5781
5784
  /** Safely cast the descriptor value to a opaque type. */
5782
5785
  asOpaque() {
@@ -6474,51 +6477,51 @@ var descriptors_codec;
6474
6477
  return (len) => {
6475
6478
  let ret = cache.get(len);
6476
6479
  if (ret === undefined) {
6477
- ret = descriptor_Descriptor.new(`Bytes<${len}>`, exactHint(len), (e, v) => e.bytes(v), (d) => d.bytes(len), (s) => s.bytes(len));
6480
+ ret = Descriptor.new(`Bytes<${len}>`, exactHint(len), (e, v) => e.bytes(v), (d) => d.bytes(len), (s) => s.bytes(len));
6478
6481
  cache.set(len, ret);
6479
6482
  }
6480
6483
  return ret;
6481
6484
  };
6482
6485
  })();
6483
6486
  /** Variable-length U32. */
6484
- codec.varU32 = descriptor_Descriptor.new("var_u32", { bytes: 4, isExact: false }, (e, v) => e.varU32(v), (d) => d.varU32(), (d) => d.varU32());
6487
+ codec.varU32 = Descriptor.new("var_u32", { bytes: 4, isExact: false }, (e, v) => e.varU32(v), (d) => d.varU32(), (d) => d.varU32());
6485
6488
  /** Variable-length U64. */
6486
- codec.varU64 = descriptor_Descriptor.new("var_u64", { bytes: 8, isExact: false }, (e, v) => e.varU64(v), (d) => d.varU64(), (d) => d.varU64());
6489
+ codec.varU64 = Descriptor.new("var_u64", { bytes: 8, isExact: false }, (e, v) => e.varU64(v), (d) => d.varU64(), (d) => d.varU64());
6487
6490
  /** Unsigned 64-bit number. */
6488
- codec.u64 = descriptor_Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.u64(), (d) => d.u64(), codec.bytes(8));
6491
+ codec.u64 = Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.u64(), (d) => d.u64(), codec.bytes(8));
6489
6492
  /** Unsigned 32-bit number. */
6490
- codec.u32 = descriptor_Descriptor.withView("u32", exactHint(4), (e, v) => e.i32(v), (d) => d.u32(), (d) => d.u32(), codec.bytes(4));
6493
+ codec.u32 = Descriptor.withView("u32", exactHint(4), (e, v) => e.i32(v), (d) => d.u32(), (d) => d.u32(), codec.bytes(4));
6491
6494
  /** Unsigned 24-bit number. */
6492
- codec.u24 = descriptor_Descriptor.withView("u24", exactHint(3), (e, v) => e.i24(v), (d) => d.u24(), (d) => d.u24(), codec.bytes(3));
6495
+ codec.u24 = Descriptor.withView("u24", exactHint(3), (e, v) => e.i24(v), (d) => d.u24(), (d) => d.u24(), codec.bytes(3));
6493
6496
  /** Unsigned 16-bit number. */
6494
- codec.u16 = descriptor_Descriptor.withView("u16", exactHint(2), (e, v) => e.i16(v), (d) => d.u16(), (d) => d.u16(), codec.bytes(2));
6497
+ codec.u16 = Descriptor.withView("u16", exactHint(2), (e, v) => e.i16(v), (d) => d.u16(), (d) => d.u16(), codec.bytes(2));
6495
6498
  /** Unsigned 8-bit number. */
6496
- codec.u8 = descriptor_Descriptor.new("u8", exactHint(1), (e, v) => e.i8(v), (d) => d.u8(), (d) => d.u8());
6499
+ codec.u8 = Descriptor.new("u8", exactHint(1), (e, v) => e.i8(v), (d) => d.u8(), (d) => d.u8());
6497
6500
  /** Signed 64-bit number. */
6498
- codec.i64 = descriptor_Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.i64(), (s) => s.u64(), codec.bytes(8));
6501
+ codec.i64 = Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.i64(), (s) => s.u64(), codec.bytes(8));
6499
6502
  /** Signed 32-bit number. */
6500
- codec.i32 = descriptor_Descriptor.withView("i32", exactHint(4), (e, v) => e.i32(v), (d) => d.i32(), (s) => s.u32(), codec.bytes(4));
6503
+ codec.i32 = Descriptor.withView("i32", exactHint(4), (e, v) => e.i32(v), (d) => d.i32(), (s) => s.u32(), codec.bytes(4));
6501
6504
  /** Signed 24-bit number. */
6502
- codec.i24 = descriptor_Descriptor.withView("i24", exactHint(3), (e, v) => e.i24(v), (d) => d.i24(), (s) => s.u24(), codec.bytes(3));
6505
+ codec.i24 = Descriptor.withView("i24", exactHint(3), (e, v) => e.i24(v), (d) => d.i24(), (s) => s.u24(), codec.bytes(3));
6503
6506
  /** Signed 16-bit number. */
6504
- codec.i16 = descriptor_Descriptor.withView("i16", exactHint(2), (e, v) => e.i16(v), (d) => d.i16(), (s) => s.u16(), codec.bytes(2));
6507
+ codec.i16 = Descriptor.withView("i16", exactHint(2), (e, v) => e.i16(v), (d) => d.i16(), (s) => s.u16(), codec.bytes(2));
6505
6508
  /** Signed 8-bit number. */
6506
- codec.i8 = descriptor_Descriptor.new("i8", exactHint(1), (e, v) => e.i8(v), (d) => d.i8(), (s) => s.u8());
6509
+ codec.i8 = Descriptor.new("i8", exactHint(1), (e, v) => e.i8(v), (d) => d.i8(), (s) => s.u8());
6507
6510
  /** 1-byte boolean value. */
6508
- codec.bool = descriptor_Descriptor.new("bool", exactHint(1), (e, v) => e.bool(v), (d) => d.bool(), (s) => s.bool());
6511
+ codec.bool = Descriptor.new("bool", exactHint(1), (e, v) => e.bool(v), (d) => d.bool(), (s) => s.bool());
6509
6512
  /** Variable-length bytes blob. */
6510
- codec.blob = descriptor_Descriptor.new("BytesBlob", { bytes: TYPICAL_SEQUENCE_LENGTH, isExact: false }, (e, v) => e.bytesBlob(v), (d) => d.bytesBlob(), (s) => s.bytesBlob());
6513
+ codec.blob = Descriptor.new("BytesBlob", { bytes: TYPICAL_SEQUENCE_LENGTH, isExact: false }, (e, v) => e.bytesBlob(v), (d) => d.bytesBlob(), (s) => s.bytesBlob());
6511
6514
  /** String encoded as variable-length bytes blob. */
6512
- codec.string = descriptor_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);
6515
+ codec.string = Descriptor.withView("string", { bytes: TYPICAL_SEQUENCE_LENGTH, isExact: false }, (e, v) => e.bytesBlob(bytes_BytesBlob.blobFrom(new TextEncoder().encode(v))), (d) => new TextDecoder("utf8", { fatal: true }).decode(d.bytesBlob().raw), (s) => s.bytesBlob(), codec.blob);
6513
6516
  /** Variable-length bit vector. */
6514
- codec.bitVecVarLen = descriptor_Descriptor.new("BitVec[?]", { bytes: TYPICAL_SEQUENCE_LENGTH >>> 3, isExact: false }, (e, v) => e.bitVecVarLen(v), (d) => d.bitVecVarLen(), (s) => s.bitVecVarLen());
6517
+ codec.bitVecVarLen = Descriptor.new("BitVec[?]", { bytes: TYPICAL_SEQUENCE_LENGTH >>> 3, isExact: false }, (e, v) => e.bitVecVarLen(v), (d) => d.bitVecVarLen(), (s) => s.bitVecVarLen());
6515
6518
  /** Fixed-length bit vector. */
6516
- codec.bitVecFixLen = (bitLen) => descriptor_Descriptor.new(`BitVec[${bitLen}]`, exactHint(bitLen >>> 3), (e, v) => e.bitVecFixLen(v), (d) => d.bitVecFixLen(bitLen), (s) => s.bitVecFixLen(bitLen));
6519
+ codec.bitVecFixLen = (bitLen) => Descriptor.new(`BitVec[${bitLen}]`, exactHint(bitLen >>> 3), (e, v) => e.bitVecFixLen(v), (d) => d.bitVecFixLen(bitLen), (s) => s.bitVecFixLen(bitLen));
6517
6520
  /** Optionality wrapper for given type. */
6518
6521
  codec.optional = (type) => {
6519
- const self = descriptor_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));
6522
+ const self = Descriptor.new(`Optional<${type.name}>`, addSizeHints({ bytes: 1, isExact: false }, type.sizeHint), (e, v) => e.optional(type, v), (d) => d.optional(type), (s) => s.optional(type));
6520
6523
  if (hasUniqueView(type)) {
6521
- return descriptor_Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.optional(type.View));
6524
+ return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.optional(type.View));
6522
6525
  }
6523
6526
  return self;
6524
6527
  };
@@ -6529,7 +6532,7 @@ var descriptors_codec;
6529
6532
  }) => {
6530
6533
  const name = `Sequence<${type.name}>[?]`;
6531
6534
  const typicalLength = options.typicalLength ?? TYPICAL_SEQUENCE_LENGTH;
6532
- return descriptor_Descriptor.withView(name, { bytes: typicalLength * type.sizeHint.bytes, isExact: false }, (e, v) => {
6535
+ return Descriptor.withView(name, { bytes: typicalLength * type.sizeHint.bytes, isExact: false }, (e, v) => {
6533
6536
  validateLength(options, v.length, name);
6534
6537
  e.sequenceVarLen(type, v);
6535
6538
  }, (d) => {
@@ -6543,10 +6546,10 @@ var descriptors_codec;
6543
6546
  }, sequenceViewVarLen(type, options));
6544
6547
  };
6545
6548
  /** Fixed-length sequence of given type. */
6546
- codec.sequenceFixLen = (type, len) => descriptor_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 }));
6549
+ codec.sequenceFixLen = (type, len) => Descriptor.withView(`Sequence<${type.name}>[${len}]`, { bytes: len * type.sizeHint.bytes, isExact: type.sizeHint.isExact }, (e, v) => e.sequenceFixLen(type, v), (d) => d.sequenceFixLen(type, len), (s) => s.sequenceFixLen(type, len), sequenceViewFixLen(type, { fixedLength: len }));
6547
6550
  /** Small dictionary codec. */
6548
6551
  codec.dictionary = (key, value, { sortKeys, fixedLength, }) => {
6549
- const self = descriptor_Descriptor.new(`Dictionary<${key.name}, ${value.name}>[${fixedLength ?? "?"}]`, {
6552
+ const self = Descriptor.new(`Dictionary<${key.name}, ${value.name}>[${fixedLength ?? "?"}]`, {
6550
6553
  bytes: fixedLength !== undefined
6551
6554
  ? fixedLength * addSizeHints(key.sizeHint, value.sizeHint).bytes
6552
6555
  : TYPICAL_DICTIONARY_LENGTH * (addSizeHints(key.sizeHint, value.sizeHint).bytes ?? 0),
@@ -6585,13 +6588,13 @@ var descriptors_codec;
6585
6588
  s.sequenceFixLen(value, len);
6586
6589
  });
6587
6590
  if (hasUniqueView(value)) {
6588
- return descriptor_Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.dictionary(key, value.View, { sortKeys, fixedLength }));
6591
+ return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.dictionary(key, value.View, { sortKeys, fixedLength }));
6589
6592
  }
6590
6593
  return self;
6591
6594
  };
6592
6595
  /** Encoding of pair of two values. */
6593
6596
  codec.pair = (a, b) => {
6594
- const self = descriptor_Descriptor.new(`Pair<${a.name}, ${b.name}>`, addSizeHints(a.sizeHint, b.sizeHint), (e, elem) => {
6597
+ const self = Descriptor.new(`Pair<${a.name}, ${b.name}>`, addSizeHints(a.sizeHint, b.sizeHint), (e, elem) => {
6595
6598
  a.encode(e, elem[0]);
6596
6599
  b.encode(e, elem[1]);
6597
6600
  }, (d) => {
@@ -6603,14 +6606,14 @@ var descriptors_codec;
6603
6606
  b.skip(s);
6604
6607
  });
6605
6608
  if (hasUniqueView(a) && hasUniqueView(b)) {
6606
- return descriptor_Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.pair(a.View, b.View));
6609
+ return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.pair(a.View, b.View));
6607
6610
  }
6608
6611
  return self;
6609
6612
  };
6610
6613
  /** Custom encoding / decoding logic. */
6611
- codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => descriptor_Descriptor.new(name, sizeHint, encode, decode, skip);
6614
+ codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
6612
6615
  /** Choose a descriptor depending on the encoding/decoding context. */
6613
- codec.select = ({ name, sizeHint, }, chooser) => descriptor_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);
6616
+ codec.select = ({ name, sizeHint, }, chooser) => Descriptor.withView(name, sizeHint, (e, x) => chooser(e.getContext()).encode(e, x), (d) => chooser(d.getContext()).decode(d), (s) => chooser(s.decoder.getContext()).skip(s), chooser(null).View);
6614
6617
  /**
6615
6618
  * A descriptor for a more complex POJO.
6616
6619
  *
@@ -6647,7 +6650,7 @@ var descriptors_codec;
6647
6650
  };
6648
6651
  const view = objectView(Class, descriptors, sizeHint, skipper);
6649
6652
  // and create the descriptor for the entire class.
6650
- return descriptor_Descriptor.withView(Class.name, sizeHint, (e, t) => {
6653
+ return Descriptor.withView(Class.name, sizeHint, (e, t) => {
6651
6654
  forEachDescriptor(descriptors, (key, descriptor) => {
6652
6655
  const value = t[key];
6653
6656
  descriptor.encode(e, value);
@@ -6698,7 +6701,7 @@ function objectView(Class, descriptors, sizeHint, skipper) {
6698
6701
  });
6699
6702
  }
6700
6703
  });
6701
- return descriptor_Descriptor.new(`View<${Class.name}>`, sizeHint, (e, t) => {
6704
+ return Descriptor.new(`View<${Class.name}>`, sizeHint, (e, t) => {
6702
6705
  const encoded = t.encoded();
6703
6706
  e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
6704
6707
  }, (d) => {
@@ -6717,7 +6720,7 @@ function sequenceViewVarLen(type, options) {
6717
6720
  validateLength(options, length, name);
6718
6721
  return s.sequenceFixLen(type, length);
6719
6722
  };
6720
- return descriptor_Descriptor.new(name, sizeHint, (e, t) => {
6723
+ return Descriptor.new(name, sizeHint, (e, t) => {
6721
6724
  validateLength(options, t.length, name);
6722
6725
  const encoded = t.encoded();
6723
6726
  e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
@@ -6733,7 +6736,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
6733
6736
  const skipper = (s) => s.sequenceFixLen(type, fixedLength);
6734
6737
  const view = type.name !== type.View.name ? `, ${type.View.name}` : "";
6735
6738
  const name = `SeqView<${type.name}${view}>[${fixedLength}]`;
6736
- return descriptor_Descriptor.new(name, sizeHint, (e, t) => {
6739
+ return Descriptor.new(name, sizeHint, (e, t) => {
6737
6740
  const encoded = t.encoded();
6738
6741
  e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
6739
6742
  }, (d) => {
@@ -8606,7 +8609,7 @@ const codecFixedSizeArray = (val, len) => {
8606
8609
  };
8607
8610
  /** Codec for a hash-dictionary. */
8608
8611
  const codecHashDictionary = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH, compare = (a, b) => extractKey(a).compare(extractKey(b)), } = {}) => {
8609
- return descriptor_Descriptor.new(`HashDictionary<${value.name}>[?]`, {
8612
+ return Descriptor.new(`HashDictionary<${value.name}>[?]`, {
8610
8613
  bytes: typicalLength * value.sizeHint.bytes,
8611
8614
  isExact: false,
8612
8615
  }, (e, v) => {
@@ -11590,6 +11593,13 @@ const gp_constants_W_T = 128;
11590
11593
  /** `W_M`: The maximum number of exports in a work-package. */
11591
11594
  const gp_constants_W_X = 3_072;
11592
11595
  // TODO [ToDr] Not sure where these should live yet :(
11596
+ /**
11597
+ * `S`: The minimum public service index.
11598
+ * Services of indices below these may only be created by the Registrar.
11599
+ *
11600
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
11601
+ */
11602
+ const gp_constants_MIN_PUBLIC_SERVICE_INDEX = (/* unused pure expression or super */ null && (2 ** 16));
11593
11603
  /**
11594
11604
  * `J`: The maximum sum of dependency items in a work-report.
11595
11605
  *
@@ -11601,9 +11611,209 @@ const gp_constants_AUTHORIZATION_QUEUE_SIZE = gp_constants_Q;
11601
11611
  /** `O`: Maximal authorization pool size. */
11602
11612
  const gp_constants_MAX_AUTH_POOL_SIZE = gp_constants_O;
11603
11613
 
11614
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
11615
+ const math_consts_MAX_VALUE = 4294967295;
11616
+ const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
11617
+ const math_consts_MIN_VALUE = (/* unused pure expression or super */ null && (-(2 ** 31)));
11618
+ const math_consts_MAX_SHIFT_U32 = 32;
11619
+ const math_consts_MAX_SHIFT_U64 = 64n;
11620
+
11621
+ ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
11622
+
11623
+
11624
+
11625
+
11626
+
11627
+
11628
+ /**
11629
+ * `B_S`: The basic minimum balance which all services require.
11630
+ *
11631
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
11632
+ */
11633
+ const service_BASE_SERVICE_BALANCE = 100n;
11634
+ /**
11635
+ * `B_I`: The additional minimum balance required per item of elective service state.
11636
+ *
11637
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
11638
+ */
11639
+ const service_ELECTIVE_ITEM_BALANCE = 10n;
11640
+ /**
11641
+ * `B_L`: The additional minimum balance required per octet of elective service state.
11642
+ *
11643
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
11644
+ */
11645
+ const service_ELECTIVE_BYTE_BALANCE = 1n;
11646
+ const zeroSizeHint = {
11647
+ bytes: 0,
11648
+ isExact: true,
11649
+ };
11650
+ /** 0-byte read, return given default value */
11651
+ const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
11652
+ /** Encode and decode object with leading version number. */
11653
+ const codecWithVersion = (val) => Descriptor.new("withVersion", {
11654
+ bytes: val.sizeHint.bytes + 8,
11655
+ isExact: false,
11656
+ }, (e, v) => {
11657
+ e.varU64(0n);
11658
+ val.encode(e, v);
11659
+ }, (d) => {
11660
+ const version = d.varU64();
11661
+ if (version !== 0n) {
11662
+ throw new Error("Non-zero version is not supported!");
11663
+ }
11664
+ return val.decode(d);
11665
+ }, (s) => {
11666
+ s.varU64();
11667
+ val.skip(s);
11668
+ });
11669
+ /**
11670
+ * Service account details.
11671
+ *
11672
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
11673
+ */
11674
+ class service_ServiceAccountInfo extends WithDebug {
11675
+ codeHash;
11676
+ balance;
11677
+ accumulateMinGas;
11678
+ onTransferMinGas;
11679
+ storageUtilisationBytes;
11680
+ gratisStorage;
11681
+ storageUtilisationCount;
11682
+ created;
11683
+ lastAccumulation;
11684
+ parentService;
11685
+ static Codec = descriptors_codec.Class(service_ServiceAccountInfo, {
11686
+ codeHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
11687
+ balance: descriptors_codec.u64,
11688
+ accumulateMinGas: descriptors_codec.u64.convert((x) => x, common_tryAsServiceGas),
11689
+ onTransferMinGas: descriptors_codec.u64.convert((x) => x, common_tryAsServiceGas),
11690
+ storageUtilisationBytes: descriptors_codec.u64,
11691
+ gratisStorage: descriptors_codec.u64,
11692
+ storageUtilisationCount: descriptors_codec.u32,
11693
+ created: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
11694
+ lastAccumulation: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
11695
+ parentService: descriptors_codec.u32.convert((x) => x, common_tryAsServiceId),
11696
+ });
11697
+ static create(a) {
11698
+ return new service_ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
11699
+ }
11700
+ /**
11701
+ * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
11702
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
11703
+ */
11704
+ static calculateThresholdBalance(items, bytes, gratisStorage) {
11705
+ const storageCost = service_BASE_SERVICE_BALANCE + service_ELECTIVE_ITEM_BALANCE * BigInt(items) + service_ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
11706
+ if (storageCost < 0n) {
11707
+ return numbers_tryAsU64(0);
11708
+ }
11709
+ if (storageCost >= 2n ** 64n) {
11710
+ return numbers_tryAsU64(2n ** 64n - 1n);
11711
+ }
11712
+ return numbers_tryAsU64(storageCost);
11713
+ }
11714
+ constructor(
11715
+ /** `a_c`: Hash of the service code. */
11716
+ codeHash,
11717
+ /** `a_b`: Current account balance. */
11718
+ balance,
11719
+ /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
11720
+ accumulateMinGas,
11721
+ /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
11722
+ onTransferMinGas,
11723
+ /** `a_o`: Total number of octets in storage. */
11724
+ storageUtilisationBytes,
11725
+ /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
11726
+ gratisStorage,
11727
+ /** `a_i`: Number of items in storage. */
11728
+ storageUtilisationCount,
11729
+ /** `a_r`: Creation account time slot. */
11730
+ created,
11731
+ /** `a_a`: Most recent accumulation time slot. */
11732
+ lastAccumulation,
11733
+ /** `a_p`: Parent service ID. */
11734
+ parentService) {
11735
+ super();
11736
+ this.codeHash = codeHash;
11737
+ this.balance = balance;
11738
+ this.accumulateMinGas = accumulateMinGas;
11739
+ this.onTransferMinGas = onTransferMinGas;
11740
+ this.storageUtilisationBytes = storageUtilisationBytes;
11741
+ this.gratisStorage = gratisStorage;
11742
+ this.storageUtilisationCount = storageUtilisationCount;
11743
+ this.created = created;
11744
+ this.lastAccumulation = lastAccumulation;
11745
+ this.parentService = parentService;
11746
+ }
11747
+ }
11748
+ class service_PreimageItem extends WithDebug {
11749
+ hash;
11750
+ blob;
11751
+ static Codec = descriptors_codec.Class(service_PreimageItem, {
11752
+ hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
11753
+ blob: descriptors_codec.blob,
11754
+ });
11755
+ static create({ hash, blob }) {
11756
+ return new service_PreimageItem(hash, blob);
11757
+ }
11758
+ constructor(hash, blob) {
11759
+ super();
11760
+ this.hash = hash;
11761
+ this.blob = blob;
11762
+ }
11763
+ }
11764
+ class service_StorageItem extends WithDebug {
11765
+ key;
11766
+ value;
11767
+ static Codec = descriptors_codec.Class(service_StorageItem, {
11768
+ key: descriptors_codec.blob.convert((i) => i, (o) => opaque_asOpaqueType(o)),
11769
+ value: descriptors_codec.blob,
11770
+ });
11771
+ static create({ key, value }) {
11772
+ return new service_StorageItem(key, value);
11773
+ }
11774
+ constructor(key, value) {
11775
+ super();
11776
+ this.key = key;
11777
+ this.value = value;
11778
+ }
11779
+ }
11780
+ const MAX_LOOKUP_HISTORY_SLOTS = 3;
11781
+ function service_tryAsLookupHistorySlots(items) {
11782
+ const knownSize = sized_array_asKnownSize(items);
11783
+ if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
11784
+ throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
11785
+ }
11786
+ return knownSize;
11787
+ }
11788
+ /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
11789
+ class service_LookupHistoryItem {
11790
+ hash;
11791
+ length;
11792
+ slots;
11793
+ constructor(hash, length,
11794
+ /**
11795
+ * Preimage availability history as a sequence of time slots.
11796
+ * See PreimageStatus and the following GP fragment for more details.
11797
+ * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
11798
+ slots) {
11799
+ this.hash = hash;
11800
+ this.length = length;
11801
+ this.slots = slots;
11802
+ }
11803
+ static isRequested(item) {
11804
+ if ("slots" in item) {
11805
+ return item.slots.length === 0;
11806
+ }
11807
+ return item.length === 0;
11808
+ }
11809
+ }
11810
+
11604
11811
  ;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
11605
11812
 
11606
11813
 
11814
+
11815
+
11816
+
11607
11817
  /** Dictionary entry of services that auto-accumulate every block. */
11608
11818
  class privileged_services_AutoAccumulate {
11609
11819
  service;
@@ -11625,39 +11835,50 @@ class privileged_services_AutoAccumulate {
11625
11835
  }
11626
11836
  }
11627
11837
  /**
11628
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11da0111da01?v=0.6.7
11838
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
11629
11839
  */
11630
11840
  class privileged_services_PrivilegedServices {
11631
11841
  manager;
11632
- authManager;
11633
- validatorsManager;
11842
+ delegator;
11843
+ registrar;
11844
+ assigners;
11634
11845
  autoAccumulateServices;
11846
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
11635
11847
  static Codec = descriptors_codec.Class(privileged_services_PrivilegedServices, {
11636
11848
  manager: descriptors_codec.u32.asOpaque(),
11637
- authManager: codecPerCore(descriptors_codec.u32.asOpaque()),
11638
- validatorsManager: descriptors_codec.u32.asOpaque(),
11849
+ assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
11850
+ delegator: descriptors_codec.u32.asOpaque(),
11851
+ registrar: compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1)
11852
+ ? descriptors_codec.u32.asOpaque()
11853
+ : ignoreValueWithDefault(common_tryAsServiceId(2 ** 32 - 1)),
11639
11854
  autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(privileged_services_AutoAccumulate.Codec)),
11640
11855
  });
11641
- static create({ manager, authManager, validatorsManager, autoAccumulateServices }) {
11642
- return new privileged_services_PrivilegedServices(manager, authManager, validatorsManager, autoAccumulateServices);
11856
+ static create(a) {
11857
+ return new privileged_services_PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
11643
11858
  }
11644
11859
  constructor(
11645
11860
  /**
11646
- * `chi_m`: The first, χm, is the index of the manager service which is
11647
- * the service able to effect an alteration of χ from block to block,
11861
+ * `χ_M`: Manages alteration of χ from block to block,
11648
11862
  * as well as bestow services with storage deposit credits.
11649
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11a40111a801?v=0.6.7
11863
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
11650
11864
  */
11651
11865
  manager,
11652
- /** `chi_a`: Manages authorization queue one for each core. */
11653
- authManager,
11654
- /** `chi_v`: Managers validator keys. */
11655
- validatorsManager,
11656
- /** `chi_g`: Dictionary of services that auto-accumulate every block with their gas limit. */
11866
+ /** `χ_V`: Managers validator keys. */
11867
+ delegator,
11868
+ /**
11869
+ * `χ_R`: Manages the creation of services in protected range.
11870
+ *
11871
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
11872
+ */
11873
+ registrar,
11874
+ /** `χ_A`: Manages authorization queue one for each core. */
11875
+ assigners,
11876
+ /** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
11657
11877
  autoAccumulateServices) {
11658
11878
  this.manager = manager;
11659
- this.authManager = authManager;
11660
- this.validatorsManager = validatorsManager;
11879
+ this.delegator = delegator;
11880
+ this.registrar = registrar;
11881
+ this.assigners = assigners;
11661
11882
  this.autoAccumulateServices = autoAccumulateServices;
11662
11883
  }
11663
11884
  }
@@ -11745,7 +11966,7 @@ class recent_blocks_RecentBlocks extends WithDebug {
11745
11966
  */
11746
11967
  class recent_blocks_RecentBlocksHistory extends WithDebug {
11747
11968
  current;
11748
- static Codec = descriptor_Descriptor.new("RecentBlocksHistory", recent_blocks_RecentBlocks.Codec.sizeHint, (encoder, value) => recent_blocks_RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
11969
+ static Codec = Descriptor.new("RecentBlocksHistory", recent_blocks_RecentBlocks.Codec.sizeHint, (encoder, value) => recent_blocks_RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
11749
11970
  const recentBlocks = recent_blocks_RecentBlocks.Codec.decode(decoder);
11750
11971
  return recent_blocks_RecentBlocksHistory.create(recentBlocks);
11751
11972
  }, (skip) => {
@@ -11942,196 +12163,6 @@ class safrole_data_SafroleData {
11942
12163
  }
11943
12164
  }
11944
12165
 
11945
- ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
11946
-
11947
-
11948
-
11949
-
11950
-
11951
-
11952
- /**
11953
- * `B_S`: The basic minimum balance which all services require.
11954
- *
11955
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
11956
- */
11957
- const service_BASE_SERVICE_BALANCE = 100n;
11958
- /**
11959
- * `B_I`: The additional minimum balance required per item of elective service state.
11960
- *
11961
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
11962
- */
11963
- const service_ELECTIVE_ITEM_BALANCE = 10n;
11964
- /**
11965
- * `B_L`: The additional minimum balance required per octet of elective service state.
11966
- *
11967
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
11968
- */
11969
- const service_ELECTIVE_BYTE_BALANCE = 1n;
11970
- const zeroSizeHint = {
11971
- bytes: 0,
11972
- isExact: true,
11973
- };
11974
- /** 0-byte read, return given default value */
11975
- const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
11976
- /** Encode and decode object with leading version number. */
11977
- const codecWithVersion = (val) => descriptor_Descriptor.new("withVersion", {
11978
- bytes: val.sizeHint.bytes + 8,
11979
- isExact: false,
11980
- }, (e, v) => {
11981
- e.varU64(0n);
11982
- val.encode(e, v);
11983
- }, (d) => {
11984
- const version = d.varU64();
11985
- if (version !== 0n) {
11986
- throw new Error("Non-zero version is not supported!");
11987
- }
11988
- return val.decode(d);
11989
- }, (s) => {
11990
- s.varU64();
11991
- val.skip(s);
11992
- });
11993
- /**
11994
- * Service account details.
11995
- *
11996
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
11997
- */
11998
- class service_ServiceAccountInfo extends WithDebug {
11999
- codeHash;
12000
- balance;
12001
- accumulateMinGas;
12002
- onTransferMinGas;
12003
- storageUtilisationBytes;
12004
- gratisStorage;
12005
- storageUtilisationCount;
12006
- created;
12007
- lastAccumulation;
12008
- parentService;
12009
- static Codec = descriptors_codec.Class(service_ServiceAccountInfo, {
12010
- codeHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
12011
- balance: descriptors_codec.u64,
12012
- accumulateMinGas: descriptors_codec.u64.convert((x) => x, common_tryAsServiceGas),
12013
- onTransferMinGas: descriptors_codec.u64.convert((x) => x, common_tryAsServiceGas),
12014
- storageUtilisationBytes: descriptors_codec.u64,
12015
- gratisStorage: descriptors_codec.u64,
12016
- storageUtilisationCount: descriptors_codec.u32,
12017
- created: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
12018
- lastAccumulation: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
12019
- parentService: descriptors_codec.u32.convert((x) => x, common_tryAsServiceId),
12020
- });
12021
- static create(a) {
12022
- return new service_ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
12023
- }
12024
- /**
12025
- * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
12026
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
12027
- */
12028
- static calculateThresholdBalance(items, bytes, gratisStorage) {
12029
- const storageCost = service_BASE_SERVICE_BALANCE + service_ELECTIVE_ITEM_BALANCE * BigInt(items) + service_ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
12030
- if (storageCost < 0n) {
12031
- return numbers_tryAsU64(0);
12032
- }
12033
- if (storageCost >= 2n ** 64n) {
12034
- return numbers_tryAsU64(2n ** 64n - 1n);
12035
- }
12036
- return numbers_tryAsU64(storageCost);
12037
- }
12038
- constructor(
12039
- /** `a_c`: Hash of the service code. */
12040
- codeHash,
12041
- /** `a_b`: Current account balance. */
12042
- balance,
12043
- /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
12044
- accumulateMinGas,
12045
- /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
12046
- onTransferMinGas,
12047
- /** `a_o`: Total number of octets in storage. */
12048
- storageUtilisationBytes,
12049
- /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
12050
- gratisStorage,
12051
- /** `a_i`: Number of items in storage. */
12052
- storageUtilisationCount,
12053
- /** `a_r`: Creation account time slot. */
12054
- created,
12055
- /** `a_a`: Most recent accumulation time slot. */
12056
- lastAccumulation,
12057
- /** `a_p`: Parent service ID. */
12058
- parentService) {
12059
- super();
12060
- this.codeHash = codeHash;
12061
- this.balance = balance;
12062
- this.accumulateMinGas = accumulateMinGas;
12063
- this.onTransferMinGas = onTransferMinGas;
12064
- this.storageUtilisationBytes = storageUtilisationBytes;
12065
- this.gratisStorage = gratisStorage;
12066
- this.storageUtilisationCount = storageUtilisationCount;
12067
- this.created = created;
12068
- this.lastAccumulation = lastAccumulation;
12069
- this.parentService = parentService;
12070
- }
12071
- }
12072
- class service_PreimageItem extends WithDebug {
12073
- hash;
12074
- blob;
12075
- static Codec = descriptors_codec.Class(service_PreimageItem, {
12076
- hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
12077
- blob: descriptors_codec.blob,
12078
- });
12079
- static create({ hash, blob }) {
12080
- return new service_PreimageItem(hash, blob);
12081
- }
12082
- constructor(hash, blob) {
12083
- super();
12084
- this.hash = hash;
12085
- this.blob = blob;
12086
- }
12087
- }
12088
- class service_StorageItem extends WithDebug {
12089
- key;
12090
- value;
12091
- static Codec = descriptors_codec.Class(service_StorageItem, {
12092
- key: descriptors_codec.blob.convert((i) => i, (o) => opaque_asOpaqueType(o)),
12093
- value: descriptors_codec.blob,
12094
- });
12095
- static create({ key, value }) {
12096
- return new service_StorageItem(key, value);
12097
- }
12098
- constructor(key, value) {
12099
- super();
12100
- this.key = key;
12101
- this.value = value;
12102
- }
12103
- }
12104
- const MAX_LOOKUP_HISTORY_SLOTS = 3;
12105
- function service_tryAsLookupHistorySlots(items) {
12106
- const knownSize = sized_array_asKnownSize(items);
12107
- if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
12108
- throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
12109
- }
12110
- return knownSize;
12111
- }
12112
- /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
12113
- class service_LookupHistoryItem {
12114
- hash;
12115
- length;
12116
- slots;
12117
- constructor(hash, length,
12118
- /**
12119
- * Preimage availability history as a sequence of time slots.
12120
- * See PreimageStatus and the following GP fragment for more details.
12121
- * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
12122
- slots) {
12123
- this.hash = hash;
12124
- this.length = length;
12125
- this.slots = slots;
12126
- }
12127
- static isRequested(item) {
12128
- if ("slots" in item) {
12129
- return item.slots.length === 0;
12130
- }
12131
- return item.length === 0;
12132
- }
12133
- }
12134
-
12135
12166
  ;// CONCATENATED MODULE: ./packages/jam/state/state.ts
12136
12167
  /**
12137
12168
  * In addition to the entropy accumulator η_0, we retain
@@ -12568,6 +12599,7 @@ class statistics_StatisticsData {
12568
12599
 
12569
12600
 
12570
12601
 
12602
+
12571
12603
 
12572
12604
 
12573
12605
  var in_memory_state_UpdateError;
@@ -12971,8 +13003,9 @@ class InMemoryState extends WithDebug {
12971
13003
  epochRoot: bytes_Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
12972
13004
  privilegedServices: privileged_services_PrivilegedServices.create({
12973
13005
  manager: common_tryAsServiceId(0),
12974
- authManager: common_tryAsPerCore(new Array(spec.coresCount).fill(common_tryAsServiceId(0)), spec),
12975
- validatorsManager: common_tryAsServiceId(0),
13006
+ assigners: common_tryAsPerCore(new Array(spec.coresCount).fill(common_tryAsServiceId(0)), spec),
13007
+ delegator: common_tryAsServiceId(0),
13008
+ registrar: common_tryAsServiceId(math_consts_MAX_VALUE),
12976
13009
  autoAccumulateServices: [],
12977
13010
  }),
12978
13011
  accumulationOutputLog: sorted_array_SortedArray.fromArray(accumulation_output_accumulationOutputComparator, []),
@@ -13444,6 +13477,7 @@ const validatorDataFromJson = json.object({
13444
13477
 
13445
13478
 
13446
13479
 
13480
+
13447
13481
  const fullStateDumpFromJson = (spec) => json.object({
13448
13482
  alpha: json.array(json.array(fromJson.bytes32())),
13449
13483
  varphi: json.array(json.array(fromJson.bytes32())),
@@ -13465,6 +13499,7 @@ const fullStateDumpFromJson = (spec) => json.object({
13465
13499
  chi_m: "number",
13466
13500
  chi_a: json.array("number"),
13467
13501
  chi_v: "number",
13502
+ chi_r: json.optional("number"),
13468
13503
  chi_g: json.nullable(json.array({
13469
13504
  service: "number",
13470
13505
  gasLimit: json.fromNumber((v) => common_tryAsServiceGas(v)),
@@ -13476,6 +13511,9 @@ const fullStateDumpFromJson = (spec) => json.object({
13476
13511
  theta: json.nullable(json.array(accumulationOutput)),
13477
13512
  accounts: json.array(JsonService.fromJson),
13478
13513
  }, ({ alpha, varphi, beta, gamma, psi, eta, iota, kappa, lambda, rho, tau, chi, pi, omega, xi, theta, accounts, }) => {
13514
+ if (compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1) && chi.chi_r === undefined) {
13515
+ throw new Error("Registrar is required in Privileges GP ^0.7.1");
13516
+ }
13479
13517
  return InMemoryState.create({
13480
13518
  authPools: common_tryAsPerCore(alpha.map((perCore) => {
13481
13519
  if (perCore.length > gp_constants_MAX_AUTH_POOL_SIZE) {
@@ -13503,8 +13541,9 @@ const fullStateDumpFromJson = (spec) => json.object({
13503
13541
  timeslot: tau,
13504
13542
  privilegedServices: privileged_services_PrivilegedServices.create({
13505
13543
  manager: chi.chi_m,
13506
- authManager: chi.chi_a,
13507
- validatorsManager: chi.chi_v,
13544
+ assigners: chi.chi_a,
13545
+ delegator: chi.chi_v,
13546
+ registrar: chi.chi_r ?? common_tryAsServiceId(2 ** 32 - 1),
13508
13547
  autoAccumulateServices: chi.chi_g ?? [],
13509
13548
  }),
13510
13549
  statistics: JsonStatisticsData.toStatisticsData(spec, pi),
@@ -13846,7 +13885,7 @@ var serialize_serialize;
13846
13885
  * determine the boundary of the bytes, so it can only be used
13847
13886
  * as the last element of the codec and can't be used in sequences!
13848
13887
  */
13849
- const serialize_dumpCodec = descriptor_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()));
13888
+ const serialize_dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }, (e, v) => e.bytes(bytes_Bytes.fromBlob(v.raw, v.raw.length)), (d) => bytes_BytesBlob.blobFrom(d.bytes(d.source.length - d.bytesRead()).raw), (s) => s.bytes(s.decoder.source.length - s.decoder.bytesRead()));
13850
13889
 
13851
13890
  ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
13852
13891
 
@@ -15060,7 +15099,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
15060
15099
  }
15061
15100
  return Ordering.Equal;
15062
15101
  }, } = {}) => {
15063
- return descriptor_Descriptor.new(`Map<${value.name}>[?]`, {
15102
+ return Descriptor.new(`Map<${value.name}>[?]`, {
15064
15103
  bytes: typicalLength * value.sizeHint.bytes,
15065
15104
  isExact: false,
15066
15105
  }, (e, v) => {
@@ -16709,7 +16748,7 @@ class state_update_AccumulationStateUpdate {
16709
16748
  if (from.privilegedServices !== null) {
16710
16749
  update.privilegedServices = PrivilegedServices.create({
16711
16750
  ...from.privilegedServices,
16712
- authManager: asKnownSize([...from.privilegedServices.authManager]),
16751
+ assigners: asKnownSize([...from.privilegedServices.assigners]),
16713
16752
  });
16714
16753
  }
16715
16754
  return update;
@@ -20577,6 +20616,8 @@ var partial_state_NewServiceError;
20577
20616
  NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
20578
20617
  /** Service is not privileged to set gratis storage. */
20579
20618
  NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
20619
+ /** Registrar attempting to create a service with already existing id. */
20620
+ NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
20580
20621
  })(partial_state_NewServiceError || (partial_state_NewServiceError = {}));
20581
20622
  var partial_state_UpdatePrivilegesError;
20582
20623
  (function (UpdatePrivilegesError) {
@@ -20713,7 +20754,7 @@ const results_HostCallResult = {
20713
20754
  OOB: numbers_tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
20714
20755
  /** Index unknown. */
20715
20756
  WHO: numbers_tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
20716
- /** Storage full. */
20757
+ /** Storage full or resource already allocated. */
20717
20758
  FULL: numbers_tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
20718
20759
  /** Core index unknown. */
20719
20760
  CORE: numbers_tryAsU64(0xfffffffffffffffan), // 2**64 - 6
@@ -20721,7 +20762,7 @@ const results_HostCallResult = {
20721
20762
  CASH: numbers_tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
20722
20763
  /** Gas limit too low. */
20723
20764
  LOW: numbers_tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
20724
- /** The item is already solicited or cannot be forgotten. */
20765
+ /** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
20725
20766
  HUH: numbers_tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
20726
20767
  /** The return value indicating general success. */
20727
20768
  OK: numbers_tryAsU64(0n),
@@ -20775,6 +20816,7 @@ function utils_clampU64ToU32(value) {
20775
20816
 
20776
20817
 
20777
20818
 
20819
+
20778
20820
  /**
20779
20821
  * Number of storage items required for ejection of the service.
20780
20822
  *
@@ -20866,10 +20908,13 @@ class accumulate_externalities_AccumulateExternalities {
20866
20908
  const isExpired = status.data[1] < t - this.chainSpec.preimageExpungePeriod;
20867
20909
  return [isExpired, isExpired ? "" : "not expired"];
20868
20910
  }
20869
- /** `check`: https://graypaper.fluffylabs.dev/#/9a08063/303f02303f02?v=0.6.6 */
20911
+ /** `check`: https://graypaper.fluffylabs.dev/#/ab2cdbd/30c60330c603?v=0.7.2 */
20870
20912
  getNextAvailableServiceId(serviceId) {
20871
20913
  let currentServiceId = serviceId;
20872
- const mod = 2 ** 32 - 2 ** 9;
20914
+ const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
20915
+ ? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
20916
+ : 2 ** 32 - 2 ** 9;
20917
+ const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
20873
20918
  for (;;) {
20874
20919
  const service = this.getServiceInfo(currentServiceId);
20875
20920
  // we found an empty id
@@ -20877,7 +20922,7 @@ class accumulate_externalities_AccumulateExternalities {
20877
20922
  return currentServiceId;
20878
20923
  }
20879
20924
  // keep trying
20880
- currentServiceId = tryAsServiceId(((currentServiceId - 2 ** 8 + 1 + mod) % mod) + 2 ** 8);
20925
+ currentServiceId = tryAsServiceId(((currentServiceId - offset + 1 + mod) % mod) + offset);
20881
20926
  }
20882
20927
  }
20883
20928
  checkPreimageStatus(hash, length) {
@@ -21034,8 +21079,7 @@ class accumulate_externalities_AccumulateExternalities {
21034
21079
  }));
21035
21080
  return Result.ok(OK);
21036
21081
  }
21037
- newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage) {
21038
- const newServiceId = this.nextNewServiceId;
21082
+ newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage, wantedServiceId) {
21039
21083
  // calculate the threshold. Storage is empty, one preimage requested.
21040
21084
  // https://graypaper.fluffylabs.dev/#/7e6ff6a/115901115901?v=0.6.7
21041
21085
  const items = tryAsU32(2 * 1 + 0);
@@ -21056,30 +21100,59 @@ class accumulate_externalities_AccumulateExternalities {
21056
21100
  if (balanceLeftForCurrent < thresholdForCurrent || bytes.overflow) {
21057
21101
  return Result.error(NewServiceError.InsufficientFunds);
21058
21102
  }
21103
+ // `a`: https://graypaper.fluffylabs.dev/#/ab2cdbd/366b02366d02?v=0.7.2
21104
+ const newAccount = ServiceAccountInfo.create({
21105
+ codeHash,
21106
+ balance: thresholdForNew,
21107
+ accumulateMinGas,
21108
+ onTransferMinGas,
21109
+ storageUtilisationBytes: bytes.value,
21110
+ storageUtilisationCount: items,
21111
+ gratisStorage,
21112
+ created: this.currentTimeslot,
21113
+ lastAccumulation: tryAsTimeSlot(0),
21114
+ parentService: this.currentServiceId,
21115
+ });
21116
+ const newLookupItem = new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([]));
21117
+ // `s`: https://graypaper.fluffylabs.dev/#/ab2cdbd/361003361003?v=0.7.2
21118
+ const updatedCurrentAccount = ServiceAccountInfo.create({
21119
+ ...currentService,
21120
+ balance: tryAsU64(balanceLeftForCurrent),
21121
+ });
21122
+ if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
21123
+ if (wantedServiceId < MIN_PUBLIC_SERVICE_INDEX &&
21124
+ this.currentServiceId === this.updatedState.getPrivilegedServices().registrar) {
21125
+ // NOTE: It's safe to cast to `Number` here, bcs here service ID cannot be bigger than 2**16
21126
+ const newServiceId = tryAsServiceId(Number(wantedServiceId));
21127
+ if (this.getServiceInfo(newServiceId) !== null) {
21128
+ return Result.error(NewServiceError.RegistrarServiceIdAlreadyTaken);
21129
+ }
21130
+ // add the new service with selected ID
21131
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36be0336c003?v=0.7.2
21132
+ this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
21133
+ serviceId: newServiceId,
21134
+ serviceInfo: newAccount,
21135
+ lookupHistory: newLookupItem,
21136
+ }));
21137
+ // update the balance of current service
21138
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36c20336c403?v=0.7.2
21139
+ this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
21140
+ return Result.ok(newServiceId);
21141
+ }
21142
+ // NOTE: in case the service is not a registrar or the requested serviceId is out of range,
21143
+ // we completely ignore the `wantedServiceId` and assign a random one
21144
+ }
21145
+ const newServiceId = this.nextNewServiceId;
21059
21146
  // add the new service
21060
- // https://graypaper.fluffylabs.dev/#/7e6ff6a/36cb0236cb02?v=0.6.7
21147
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36e70336e903?v=0.7.2
21061
21148
  this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
21062
21149
  serviceId: newServiceId,
21063
- serviceInfo: ServiceAccountInfo.create({
21064
- codeHash,
21065
- balance: thresholdForNew,
21066
- accumulateMinGas,
21067
- onTransferMinGas,
21068
- storageUtilisationBytes: bytes.value,
21069
- storageUtilisationCount: items,
21070
- gratisStorage,
21071
- created: this.currentTimeslot,
21072
- lastAccumulation: tryAsTimeSlot(0),
21073
- parentService: this.currentServiceId,
21074
- }),
21075
- lookupHistory: new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([])),
21150
+ serviceInfo: newAccount,
21151
+ lookupHistory: newLookupItem,
21076
21152
  }));
21077
21153
  // update the balance of current service
21078
- // https://graypaper.fluffylabs.dev/#/7e6ff6a/364d03364d03?v=0.6.7
21079
- this.updatedState.updateServiceInfo(this.currentServiceId, ServiceAccountInfo.create({
21080
- ...currentService,
21081
- balance: tryAsU64(balanceLeftForCurrent),
21082
- }));
21154
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36ec0336ee03?v=0.7.2
21155
+ this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
21083
21156
  // update the next service id we are going to create next
21084
21157
  // https://graypaper.fluffylabs.dev/#/7e6ff6a/36a70336a703?v=0.6.7
21085
21158
  this.nextNewServiceId = this.getNextAvailableServiceId(bumpServiceId(newServiceId));
@@ -21097,9 +21170,9 @@ class accumulate_externalities_AccumulateExternalities {
21097
21170
  }
21098
21171
  updateValidatorsData(validatorsData) {
21099
21172
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/362802362d02?v=0.6.7 */
21100
- const validatorsManager = this.updatedState.getPrivilegedServices().validatorsManager;
21101
- if (validatorsManager !== this.currentServiceId) {
21102
- accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${validatorsManager}) and cannot update validators data. Ignoring`;
21173
+ const currentDelegator = this.updatedState.getPrivilegedServices().delegator;
21174
+ if (currentDelegator !== this.currentServiceId) {
21175
+ accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${currentDelegator}) and cannot update validators data. Ignoring`;
21103
21176
  return Result.error(UnprivilegedError);
21104
21177
  }
21105
21178
  this.updatedState.stateUpdate.validatorsData = validatorsData;
@@ -21109,34 +21182,38 @@ class accumulate_externalities_AccumulateExternalities {
21109
21182
  /** https://graypaper.fluffylabs.dev/#/9a08063/362202362202?v=0.6.6 */
21110
21183
  this.checkpointedState = AccumulationStateUpdate.copyFrom(this.updatedState.stateUpdate);
21111
21184
  }
21112
- updateAuthorizationQueue(coreIndex, authQueue, authManager) {
21185
+ updateAuthorizationQueue(coreIndex, authQueue, assigners) {
21113
21186
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/36a40136a401?v=0.6.7 */
21114
21187
  // NOTE `coreIndex` is already verified in the HC, so this is infallible.
21115
- const currentAuthManager = this.updatedState.getPrivilegedServices().authManager[coreIndex];
21116
- if (currentAuthManager !== this.currentServiceId) {
21117
- accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not an auth manager of core ${coreIndex} (expected: ${currentAuthManager}) and cannot update authorization queue. Ignoring`;
21188
+ const currentAssigners = this.updatedState.getPrivilegedServices().assigners[coreIndex];
21189
+ if (currentAssigners !== this.currentServiceId) {
21190
+ accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not an auth manager of core ${coreIndex} (expected: ${currentAssigners}) and cannot update authorization queue.`;
21118
21191
  return Result.error(UpdatePrivilegesError.UnprivilegedService);
21119
21192
  }
21120
- if (authManager === null && Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
21121
- accumulate_externalities_logger.trace `The new auth manager is not a valid service id. Ignoring`;
21193
+ if (assigners === null && Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
21194
+ accumulate_externalities_logger.trace `The new auth manager is not a valid service id.`;
21122
21195
  return Result.error(UpdatePrivilegesError.InvalidServiceId);
21123
21196
  }
21124
21197
  this.updatedState.stateUpdate.authorizationQueues.set(coreIndex, authQueue);
21125
21198
  return Result.ok(OK);
21126
21199
  }
21127
- updatePrivilegedServices(manager, authorizers, validatorsManager, autoAccumulate) {
21200
+ updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate) {
21128
21201
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/36d90036de00?v=0.6.7 */
21129
21202
  const currentManager = this.updatedState.getPrivilegedServices().manager;
21130
21203
  if (currentManager !== this.currentServiceId) {
21131
21204
  return Result.error(UpdatePrivilegesError.UnprivilegedService);
21132
21205
  }
21133
- if (manager === null || validatorsManager === null) {
21134
- return Result.error(UpdatePrivilegesError.InvalidServiceId);
21206
+ if (manager === null || delegator === null) {
21207
+ return Result.error(UpdatePrivilegesError.InvalidServiceId, "Either manager or delegator is not valid service id.");
21208
+ }
21209
+ if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && registrar === null) {
21210
+ return Result.error(UpdatePrivilegesError.InvalidServiceId, "Register manager is not valid service id.");
21135
21211
  }
21136
21212
  this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
21137
21213
  manager,
21138
- authManager: authorizers,
21139
- validatorsManager,
21214
+ assigners: authorizers,
21215
+ delegator,
21216
+ registrar: registrar ?? tryAsServiceId(0), // introduced in 0.7.1
21140
21217
  autoAccumulateServices: autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit })),
21141
21218
  });
21142
21219
  return Result.ok(OK);
@@ -21252,8 +21329,11 @@ class accumulate_externalities_AccumulateExternalities {
21252
21329
  }
21253
21330
  }
21254
21331
  function bumpServiceId(serviceId) {
21255
- const mod = 2 ** 32 - 2 ** 9;
21256
- return tryAsServiceId(2 ** 8 + ((serviceId - 2 ** 8 + 42 + mod) % mod));
21332
+ const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
21333
+ ? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
21334
+ : 2 ** 32 - 2 ** 9;
21335
+ const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
21336
+ return tryAsServiceId(offset + ((serviceId - offset + 42 + mod) % mod));
21257
21337
  }
21258
21338
 
21259
21339
  ;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/operand.ts
@@ -21905,6 +21985,8 @@ class accumulate_data_AccumulateData {
21905
21985
 
21906
21986
 
21907
21987
 
21988
+
21989
+
21908
21990
  /**
21909
21991
  * A function that removes duplicates but does not change order - it keeps the first occurence.
21910
21992
  */
@@ -21934,7 +22016,7 @@ const NEXT_ID_CODEC = descriptors_codec.object({
21934
22016
  *
21935
22017
  * Please not that it does not call `check` function!
21936
22018
  *
21937
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/2f4c022f4c02?v=0.6.7
22019
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/2fa9042fc304?v=0.7.2
21938
22020
  */
21939
22021
  function accumulate_utils_generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blake2b) {
21940
22022
  const encoded = Encoder.encodeObject(NEXT_ID_CODEC, {
@@ -21944,7 +22026,11 @@ function accumulate_utils_generateNextServiceId({ serviceId, entropy, timeslot }
21944
22026
  }, chainSpec);
21945
22027
  const result = blake2b.hashBytes(encoded).raw.subarray(0, 4);
21946
22028
  const number = leBytesAsU32(result) >>> 0;
21947
- return tryAsServiceId((number % (2 ** 32 - 2 ** 9)) + 2 ** 8);
22029
+ const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
22030
+ ? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
22031
+ : 2 ** 32 - 2 ** 9;
22032
+ const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
22033
+ return tryAsServiceId((number % mod) + offset);
21948
22034
  }
21949
22035
 
21950
22036
  ;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-queue.ts
@@ -22356,7 +22442,7 @@ class Assign {
22356
22442
  // o
22357
22443
  const authorizationQueueStart = regs.get(8);
22358
22444
  // a
22359
- const authManager = getServiceId(regs.get(9));
22445
+ const assigners = getServiceId(regs.get(9));
22360
22446
  const res = safe_alloc_uint8array_safeAllocUint8Array(hash_HASH_SIZE * gp_constants_AUTHORIZATION_QUEUE_SIZE);
22361
22447
  const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
22362
22448
  // error while reading the memory.
@@ -22373,7 +22459,7 @@ class Assign {
22373
22459
  const decoder = decoder_Decoder.fromBlob(res);
22374
22460
  const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE), gp_constants_AUTHORIZATION_QUEUE_SIZE);
22375
22461
  const fixedSizeAuthQueue = sized_array_FixedSizeArray.new(authQueue, gp_constants_AUTHORIZATION_QUEUE_SIZE);
22376
- const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, authManager);
22462
+ const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
22377
22463
  if (result.isOk) {
22378
22464
  regs.set(IN_OUT_REG, results_HostCallResult.OK);
22379
22465
  logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
@@ -22422,7 +22508,9 @@ class Bless {
22422
22508
  chainSpec;
22423
22509
  index = host_call_handler_tryAsHostCallIndex(14);
22424
22510
  basicGasCost = gas_tryAsSmallGas(10);
22425
- tracedRegisters = host_call_handler_traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11);
22511
+ tracedRegisters = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1)
22512
+ ? host_call_handler_traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11, 12)
22513
+ : host_call_handler_traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11);
22426
22514
  constructor(currentServiceId, partialState, chainSpec) {
22427
22515
  this.currentServiceId = currentServiceId;
22428
22516
  this.partialState = partialState;
@@ -22432,14 +22520,17 @@ class Bless {
22432
22520
  // `m`: manager service (can change privileged services)
22433
22521
  const manager = getServiceId(regs.get(bless_IN_OUT_REG));
22434
22522
  // `a`: manages authorization queue
22435
- // NOTE It can be either ServiceId (pre GP 067) or memory index (GP ^067)
22436
22523
  const authorization = regs.get(8);
22437
22524
  // `v`: manages validator keys
22438
- const validator = getServiceId(regs.get(9));
22525
+ const delegator = getServiceId(regs.get(9));
22526
+ // `r`: manages creation of new services with id within protected range
22527
+ const registrar = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1)
22528
+ ? getServiceId(regs.get(10))
22529
+ : common_tryAsServiceId(2 ** 32 - 1);
22439
22530
  // `o`: memory offset
22440
- const sourceStart = regs.get(10);
22531
+ const sourceStart = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1) ? regs.get(11) : regs.get(10);
22441
22532
  // `n`: number of items in the auto-accumulate dictionary
22442
- const numberOfItems = regs.get(11);
22533
+ const numberOfItems = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1) ? regs.get(12) : regs.get(11);
22443
22534
  /*
22444
22535
  * `z`: array of key-value pairs serviceId -> gas that auto-accumulate every block
22445
22536
  * https://graypaper.fluffylabs.dev/#/7e6ff6a/368100368100?v=0.6.7
@@ -22453,7 +22544,7 @@ class Bless {
22453
22544
  decoder.resetTo(0);
22454
22545
  const memoryReadResult = memory.loadInto(result, memIndex);
22455
22546
  if (memoryReadResult.isError) {
22456
- logger_logger.trace `BLESS(${manager}, ${validator}) <- PANIC`;
22547
+ logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}) <- PANIC`;
22457
22548
  return host_call_handler_PvmExecution.Panic;
22458
22549
  }
22459
22550
  const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
@@ -22466,24 +22557,25 @@ class Bless {
22466
22557
  const authorizersDecoder = decoder_Decoder.fromBlob(res);
22467
22558
  const memoryReadResult = memory.loadInto(res, authorization);
22468
22559
  if (memoryReadResult.isError) {
22469
- logger_logger.trace `BLESS(${manager}, ${validator}, ${autoAccumulateEntries}) <- PANIC`;
22560
+ logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- PANIC`;
22470
22561
  return host_call_handler_PvmExecution.Panic;
22471
22562
  }
22563
+ // `a`
22472
22564
  const authorizers = common_tryAsPerCore(authorizersDecoder.sequenceFixLen(descriptors_codec.u32.asOpaque(), this.chainSpec.coresCount), this.chainSpec);
22473
- const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, validator, autoAccumulateEntries);
22565
+ const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulateEntries);
22474
22566
  if (updateResult.isOk) {
22475
- logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- OK`;
22567
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- OK`;
22476
22568
  regs.set(bless_IN_OUT_REG, results_HostCallResult.OK);
22477
22569
  return;
22478
22570
  }
22479
22571
  const e = updateResult.error;
22480
22572
  if (e === partial_state_UpdatePrivilegesError.UnprivilegedService) {
22481
- logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- HUH`;
22573
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- HUH`;
22482
22574
  regs.set(bless_IN_OUT_REG, results_HostCallResult.HUH);
22483
22575
  return;
22484
22576
  }
22485
22577
  if (e === partial_state_UpdatePrivilegesError.InvalidServiceId) {
22486
- logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- WHO`;
22578
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- WHO`;
22487
22579
  regs.set(bless_IN_OUT_REG, results_HostCallResult.WHO);
22488
22580
  return;
22489
22581
  }
@@ -22735,7 +22827,9 @@ class New {
22735
22827
  partialState;
22736
22828
  index = host_call_handler_tryAsHostCallIndex(18);
22737
22829
  basicGasCost = gas_tryAsSmallGas(10);
22738
- tracedRegisters = host_call_handler_traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11);
22830
+ tracedRegisters = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1)
22831
+ ? host_call_handler_traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11, 12)
22832
+ : host_call_handler_traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11);
22739
22833
  constructor(currentServiceId, partialState) {
22740
22834
  this.currentServiceId = currentServiceId;
22741
22835
  this.partialState = partialState;
@@ -22751,16 +22845,18 @@ class New {
22751
22845
  const allowance = common_tryAsServiceGas(regs.get(10));
22752
22846
  // `f`
22753
22847
  const gratisStorage = regs.get(11);
22848
+ // `i`: requested service id. Ignored if current service is not registrar or value is bigger than `S`.
22849
+ const requestedServiceId = regs.get(12);
22754
22850
  // `c`
22755
22851
  const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
22756
22852
  const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
22757
22853
  // error while reading the memory.
22758
22854
  if (memoryReadResult.isError) {
22759
- logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- PANIC`;
22855
+ logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
22760
22856
  return host_call_handler_PvmExecution.Panic;
22761
22857
  }
22762
- const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage);
22763
- logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- ${result_resultToString(assignedId)}`;
22858
+ const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage, requestedServiceId);
22859
+ logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${result_resultToString(assignedId)}`;
22764
22860
  if (assignedId.isOk) {
22765
22861
  regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
22766
22862
  return;
@@ -22774,6 +22870,11 @@ class New {
22774
22870
  regs.set(new_IN_OUT_REG, results_HostCallResult.HUH);
22775
22871
  return;
22776
22872
  }
22873
+ // Post 0.7.1
22874
+ if (e === partial_state_NewServiceError.RegistrarServiceIdAlreadyTaken) {
22875
+ regs.set(new_IN_OUT_REG, results_HostCallResult.FULL);
22876
+ return;
22877
+ }
22777
22878
  debug_assertNever(e);
22778
22879
  }
22779
22880
  }
@@ -24048,17 +24149,17 @@ class accumulate_Accumulate {
24048
24149
  statistics.set(serviceId, serviceStatistics);
24049
24150
  currentState = stateUpdate === null ? checkpoint : stateUpdate;
24050
24151
  if (Compatibility.is(GpVersion.V0_7_0) && serviceId === currentManager) {
24051
- const newV = currentState.privilegedServices?.validatorsManager;
24152
+ const newV = currentState.privilegedServices?.delegator;
24052
24153
  if (currentState.privilegedServices !== null && newV !== undefined && serviceIds.includes(newV)) {
24053
- accumulate_logger.info `Entering completely incorrect code that probably reverts validatorsManager change. This is valid in 0.7.0 only and incorrect in 0.7.1+`;
24154
+ accumulate_logger.info `Entering completely incorrect code that probably reverts delegator change. This is valid in 0.7.0 only and incorrect in 0.7.1+`;
24054
24155
  // Since serviceIds already contains newV, this service gets accumulated twice.
24055
24156
  // To avoid double-counting, we skip stats and gas cost tracking here.
24056
- // We need this accumulation to get the correct `validatorsManager`
24157
+ // We need this accumulation to get the correct `delegator`
24057
24158
  const { stateUpdate } = await this.accumulateSingleService(newV, [], accumulateData.getOperands(newV), accumulateData.getGasCost(newV), slot, entropy, checkpoint);
24058
- const correctV = stateUpdate?.privilegedServices?.validatorsManager ?? this.state.privilegedServices.validatorsManager;
24159
+ const correctV = stateUpdate?.privilegedServices?.delegator ?? this.state.privilegedServices.delegator;
24059
24160
  currentState.privilegedServices = PrivilegedServices.create({
24060
24161
  ...currentState.privilegedServices,
24061
- validatorsManager: correctV,
24162
+ delegator: correctV,
24062
24163
  });
24063
24164
  }
24064
24165
  }