@typeberry/convert 0.1.3-8fd7637 → 0.1.3-a6eda68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +463 -336
  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, []),
@@ -13018,6 +13051,7 @@ const serviceDataCodec = descriptors_codec.dictionary(descriptors_codec.u32.asOp
13018
13051
 
13019
13052
  class JsonServiceInfo {
13020
13053
  static fromJson = json.object({
13054
+ ...(compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1) ? { version: "number" } : {}),
13021
13055
  code_hash: fromJson.bytes32(),
13022
13056
  balance: json.fromNumber((x) => numbers_tryAsU64(x)),
13023
13057
  min_item_gas: json.fromNumber((x) => common_tryAsServiceGas(x)),
@@ -13042,6 +13076,7 @@ class JsonServiceInfo {
13042
13076
  parentService: parent_service,
13043
13077
  });
13044
13078
  });
13079
+ version;
13045
13080
  code_hash;
13046
13081
  balance;
13047
13082
  min_item_gas;
@@ -13076,23 +13111,35 @@ const lookupMetaFromJson = json.object({
13076
13111
  },
13077
13112
  value: json.array("number"),
13078
13113
  }, ({ key, value }) => new service_LookupHistoryItem(key.hash, key.length, value));
13114
+ const preimageStatusFromJson = json.object({
13115
+ hash: fromJson.bytes32(),
13116
+ status: json.array("number"),
13117
+ }, ({ hash, status }) => new service_LookupHistoryItem(hash, numbers_tryAsU32(0), status));
13079
13118
  class JsonService {
13080
13119
  static fromJson = json.object({
13081
13120
  id: "number",
13082
- data: {
13083
- service: JsonServiceInfo.fromJson,
13084
- preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
13085
- storage: json.optional(json.array(JsonStorageItem.fromJson)),
13086
- lookup_meta: json.optional(json.array(lookupMetaFromJson)),
13087
- },
13121
+ data: compatibility_Compatibility.isLessThan(compatibility_GpVersion.V0_7_1)
13122
+ ? {
13123
+ service: JsonServiceInfo.fromJson,
13124
+ preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
13125
+ storage: json.optional(json.array(JsonStorageItem.fromJson)),
13126
+ lookup_meta: json.optional(json.array(lookupMetaFromJson)),
13127
+ }
13128
+ : {
13129
+ service: JsonServiceInfo.fromJson,
13130
+ storage: json.optional(json.array(JsonStorageItem.fromJson)),
13131
+ preimages_blob: json.optional(json.array(JsonPreimageItem.fromJson)),
13132
+ preimages_status: json.optional(json.array(preimageStatusFromJson)),
13133
+ },
13088
13134
  }, ({ id, data }) => {
13135
+ const preimages = hash_dictionary_HashDictionary.fromEntries((data.preimages ?? data.preimages_blob ?? []).map((x) => [x.hash, x]));
13089
13136
  const lookupHistory = hash_dictionary_HashDictionary.new();
13090
- for (const item of data.lookup_meta ?? []) {
13137
+ for (const item of data.lookup_meta ?? data.preimages_status ?? []) {
13091
13138
  const data = lookupHistory.get(item.hash) ?? [];
13092
- data.push(item);
13139
+ const length = numbers_tryAsU32(preimages.get(item.hash)?.blob.length ?? item.length);
13140
+ data.push(new service_LookupHistoryItem(item.hash, length, item.slots));
13093
13141
  lookupHistory.set(item.hash, data);
13094
13142
  }
13095
- const preimages = hash_dictionary_HashDictionary.fromEntries((data.preimages ?? []).map((x) => [x.hash, x]));
13096
13143
  const storage = new Map();
13097
13144
  const entries = (data.storage ?? []).map(({ key, value }) => {
13098
13145
  const opaqueKey = opaque_asOpaqueType(key);
@@ -13287,6 +13334,8 @@ class TicketsOrKeys {
13287
13334
 
13288
13335
 
13289
13336
 
13337
+
13338
+
13290
13339
  class JsonValidatorStatistics {
13291
13340
  static fromJson = json.object({
13292
13341
  blocks: "number",
@@ -13355,8 +13404,12 @@ class JsonServiceStatistics {
13355
13404
  extrinsic_count: "number",
13356
13405
  accumulate_count: "number",
13357
13406
  accumulate_gas_used: json.fromNumber(common_tryAsServiceGas),
13358
- on_transfers_count: "number",
13359
- on_transfers_gas_used: json.fromNumber(common_tryAsServiceGas),
13407
+ ...(compatibility_Compatibility.isLessThan(compatibility_GpVersion.V0_7_1)
13408
+ ? {
13409
+ on_transfers_count: "number",
13410
+ on_transfers_gas_used: json.fromNumber(common_tryAsServiceGas),
13411
+ }
13412
+ : {}),
13360
13413
  }, ({ provided_count, provided_size, refinement_count, refinement_gas_used, imports, exports, extrinsic_size, extrinsic_count, accumulate_count, accumulate_gas_used, on_transfers_count, on_transfers_gas_used, }) => {
13361
13414
  return statistics_ServiceStatistics.create({
13362
13415
  providedCount: provided_count,
@@ -13369,8 +13422,8 @@ class JsonServiceStatistics {
13369
13422
  extrinsicCount: extrinsic_count,
13370
13423
  accumulateCount: accumulate_count,
13371
13424
  accumulateGasUsed: accumulate_gas_used,
13372
- onTransfersCount: on_transfers_count,
13373
- onTransfersGasUsed: on_transfers_gas_used,
13425
+ onTransfersCount: on_transfers_count ?? numbers_tryAsU32(0),
13426
+ onTransfersGasUsed: on_transfers_gas_used ?? common_tryAsServiceGas(0),
13374
13427
  });
13375
13428
  });
13376
13429
  provided_count;
@@ -13444,6 +13497,7 @@ const validatorDataFromJson = json.object({
13444
13497
 
13445
13498
 
13446
13499
 
13500
+
13447
13501
  const fullStateDumpFromJson = (spec) => json.object({
13448
13502
  alpha: json.array(json.array(fromJson.bytes32())),
13449
13503
  varphi: json.array(json.array(fromJson.bytes32())),
@@ -13465,6 +13519,7 @@ const fullStateDumpFromJson = (spec) => json.object({
13465
13519
  chi_m: "number",
13466
13520
  chi_a: json.array("number"),
13467
13521
  chi_v: "number",
13522
+ chi_r: json.optional("number"),
13468
13523
  chi_g: json.nullable(json.array({
13469
13524
  service: "number",
13470
13525
  gasLimit: json.fromNumber((v) => common_tryAsServiceGas(v)),
@@ -13476,6 +13531,9 @@ const fullStateDumpFromJson = (spec) => json.object({
13476
13531
  theta: json.nullable(json.array(accumulationOutput)),
13477
13532
  accounts: json.array(JsonService.fromJson),
13478
13533
  }, ({ alpha, varphi, beta, gamma, psi, eta, iota, kappa, lambda, rho, tau, chi, pi, omega, xi, theta, accounts, }) => {
13534
+ if (compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1) && chi.chi_r === undefined) {
13535
+ throw new Error("Registrar is required in Privileges GP ^0.7.1");
13536
+ }
13479
13537
  return InMemoryState.create({
13480
13538
  authPools: common_tryAsPerCore(alpha.map((perCore) => {
13481
13539
  if (perCore.length > gp_constants_MAX_AUTH_POOL_SIZE) {
@@ -13503,8 +13561,9 @@ const fullStateDumpFromJson = (spec) => json.object({
13503
13561
  timeslot: tau,
13504
13562
  privilegedServices: privileged_services_PrivilegedServices.create({
13505
13563
  manager: chi.chi_m,
13506
- authManager: chi.chi_a,
13507
- validatorsManager: chi.chi_v,
13564
+ assigners: chi.chi_a,
13565
+ delegator: chi.chi_v,
13566
+ registrar: chi.chi_r ?? common_tryAsServiceId(2 ** 32 - 1),
13508
13567
  autoAccumulateServices: chi.chi_g ?? [],
13509
13568
  }),
13510
13569
  statistics: JsonStatisticsData.toStatisticsData(spec, pi),
@@ -13846,7 +13905,7 @@ var serialize_serialize;
13846
13905
  * determine the boundary of the bytes, so it can only be used
13847
13906
  * as the last element of the codec and can't be used in sequences!
13848
13907
  */
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()));
13908
+ 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
13909
 
13851
13910
  ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
13852
13911
 
@@ -15060,7 +15119,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
15060
15119
  }
15061
15120
  return Ordering.Equal;
15062
15121
  }, } = {}) => {
15063
- return descriptor_Descriptor.new(`Map<${value.name}>[?]`, {
15122
+ return Descriptor.new(`Map<${value.name}>[?]`, {
15064
15123
  bytes: typicalLength * value.sizeHint.bytes,
15065
15124
  isExact: false,
15066
15125
  }, (e, v) => {
@@ -16709,11 +16768,17 @@ class state_update_AccumulationStateUpdate {
16709
16768
  if (from.privilegedServices !== null) {
16710
16769
  update.privilegedServices = PrivilegedServices.create({
16711
16770
  ...from.privilegedServices,
16712
- authManager: asKnownSize([...from.privilegedServices.authManager]),
16771
+ assigners: asKnownSize([...from.privilegedServices.assigners]),
16713
16772
  });
16714
16773
  }
16715
16774
  return update;
16716
16775
  }
16776
+ /** Retrieve and clear pending transfers. */
16777
+ takeTransfers() {
16778
+ const transfers = this.transfers;
16779
+ this.transfers = [];
16780
+ return transfers;
16781
+ }
16717
16782
  }
16718
16783
  class state_update_PartiallyUpdatedState {
16719
16784
  state;
@@ -20577,6 +20642,8 @@ var partial_state_NewServiceError;
20577
20642
  NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
20578
20643
  /** Service is not privileged to set gratis storage. */
20579
20644
  NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
20645
+ /** Registrar attempting to create a service with already existing id. */
20646
+ NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
20580
20647
  })(partial_state_NewServiceError || (partial_state_NewServiceError = {}));
20581
20648
  var partial_state_UpdatePrivilegesError;
20582
20649
  (function (UpdatePrivilegesError) {
@@ -20713,7 +20780,7 @@ const results_HostCallResult = {
20713
20780
  OOB: numbers_tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
20714
20781
  /** Index unknown. */
20715
20782
  WHO: numbers_tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
20716
- /** Storage full. */
20783
+ /** Storage full or resource already allocated. */
20717
20784
  FULL: numbers_tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
20718
20785
  /** Core index unknown. */
20719
20786
  CORE: numbers_tryAsU64(0xfffffffffffffffan), // 2**64 - 6
@@ -20721,7 +20788,7 @@ const results_HostCallResult = {
20721
20788
  CASH: numbers_tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
20722
20789
  /** Gas limit too low. */
20723
20790
  LOW: numbers_tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
20724
- /** The item is already solicited or cannot be forgotten. */
20791
+ /** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
20725
20792
  HUH: numbers_tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
20726
20793
  /** The return value indicating general success. */
20727
20794
  OK: numbers_tryAsU64(0n),
@@ -20775,6 +20842,7 @@ function utils_clampU64ToU32(value) {
20775
20842
 
20776
20843
 
20777
20844
 
20845
+
20778
20846
  /**
20779
20847
  * Number of storage items required for ejection of the service.
20780
20848
  *
@@ -20866,10 +20934,13 @@ class accumulate_externalities_AccumulateExternalities {
20866
20934
  const isExpired = status.data[1] < t - this.chainSpec.preimageExpungePeriod;
20867
20935
  return [isExpired, isExpired ? "" : "not expired"];
20868
20936
  }
20869
- /** `check`: https://graypaper.fluffylabs.dev/#/9a08063/303f02303f02?v=0.6.6 */
20937
+ /** `check`: https://graypaper.fluffylabs.dev/#/ab2cdbd/30c60330c603?v=0.7.2 */
20870
20938
  getNextAvailableServiceId(serviceId) {
20871
20939
  let currentServiceId = serviceId;
20872
- const mod = 2 ** 32 - 2 ** 9;
20940
+ const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
20941
+ ? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
20942
+ : 2 ** 32 - 2 ** 9;
20943
+ const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
20873
20944
  for (;;) {
20874
20945
  const service = this.getServiceInfo(currentServiceId);
20875
20946
  // we found an empty id
@@ -20877,7 +20948,7 @@ class accumulate_externalities_AccumulateExternalities {
20877
20948
  return currentServiceId;
20878
20949
  }
20879
20950
  // keep trying
20880
- currentServiceId = tryAsServiceId(((currentServiceId - 2 ** 8 + 1 + mod) % mod) + 2 ** 8);
20951
+ currentServiceId = tryAsServiceId(((currentServiceId - offset + 1 + mod) % mod) + offset);
20881
20952
  }
20882
20953
  }
20883
20954
  checkPreimageStatus(hash, length) {
@@ -21034,8 +21105,7 @@ class accumulate_externalities_AccumulateExternalities {
21034
21105
  }));
21035
21106
  return Result.ok(OK);
21036
21107
  }
21037
- newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage) {
21038
- const newServiceId = this.nextNewServiceId;
21108
+ newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage, wantedServiceId) {
21039
21109
  // calculate the threshold. Storage is empty, one preimage requested.
21040
21110
  // https://graypaper.fluffylabs.dev/#/7e6ff6a/115901115901?v=0.6.7
21041
21111
  const items = tryAsU32(2 * 1 + 0);
@@ -21056,30 +21126,59 @@ class accumulate_externalities_AccumulateExternalities {
21056
21126
  if (balanceLeftForCurrent < thresholdForCurrent || bytes.overflow) {
21057
21127
  return Result.error(NewServiceError.InsufficientFunds);
21058
21128
  }
21129
+ // `a`: https://graypaper.fluffylabs.dev/#/ab2cdbd/366b02366d02?v=0.7.2
21130
+ const newAccount = ServiceAccountInfo.create({
21131
+ codeHash,
21132
+ balance: thresholdForNew,
21133
+ accumulateMinGas,
21134
+ onTransferMinGas,
21135
+ storageUtilisationBytes: bytes.value,
21136
+ storageUtilisationCount: items,
21137
+ gratisStorage,
21138
+ created: this.currentTimeslot,
21139
+ lastAccumulation: tryAsTimeSlot(0),
21140
+ parentService: this.currentServiceId,
21141
+ });
21142
+ const newLookupItem = new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([]));
21143
+ // `s`: https://graypaper.fluffylabs.dev/#/ab2cdbd/361003361003?v=0.7.2
21144
+ const updatedCurrentAccount = ServiceAccountInfo.create({
21145
+ ...currentService,
21146
+ balance: tryAsU64(balanceLeftForCurrent),
21147
+ });
21148
+ if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
21149
+ if (wantedServiceId < MIN_PUBLIC_SERVICE_INDEX &&
21150
+ this.currentServiceId === this.updatedState.getPrivilegedServices().registrar) {
21151
+ // NOTE: It's safe to cast to `Number` here, bcs here service ID cannot be bigger than 2**16
21152
+ const newServiceId = tryAsServiceId(Number(wantedServiceId));
21153
+ if (this.getServiceInfo(newServiceId) !== null) {
21154
+ return Result.error(NewServiceError.RegistrarServiceIdAlreadyTaken);
21155
+ }
21156
+ // add the new service with selected ID
21157
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36be0336c003?v=0.7.2
21158
+ this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
21159
+ serviceId: newServiceId,
21160
+ serviceInfo: newAccount,
21161
+ lookupHistory: newLookupItem,
21162
+ }));
21163
+ // update the balance of current service
21164
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36c20336c403?v=0.7.2
21165
+ this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
21166
+ return Result.ok(newServiceId);
21167
+ }
21168
+ // NOTE: in case the service is not a registrar or the requested serviceId is out of range,
21169
+ // we completely ignore the `wantedServiceId` and assign a random one
21170
+ }
21171
+ const newServiceId = this.nextNewServiceId;
21059
21172
  // add the new service
21060
- // https://graypaper.fluffylabs.dev/#/7e6ff6a/36cb0236cb02?v=0.6.7
21173
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36e70336e903?v=0.7.2
21061
21174
  this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
21062
21175
  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([])),
21176
+ serviceInfo: newAccount,
21177
+ lookupHistory: newLookupItem,
21076
21178
  }));
21077
21179
  // 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
- }));
21180
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36ec0336ee03?v=0.7.2
21181
+ this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
21083
21182
  // update the next service id we are going to create next
21084
21183
  // https://graypaper.fluffylabs.dev/#/7e6ff6a/36a70336a703?v=0.6.7
21085
21184
  this.nextNewServiceId = this.getNextAvailableServiceId(bumpServiceId(newServiceId));
@@ -21097,9 +21196,9 @@ class accumulate_externalities_AccumulateExternalities {
21097
21196
  }
21098
21197
  updateValidatorsData(validatorsData) {
21099
21198
  /** 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`;
21199
+ const currentDelegator = this.updatedState.getPrivilegedServices().delegator;
21200
+ if (currentDelegator !== this.currentServiceId) {
21201
+ accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${currentDelegator}) and cannot update validators data. Ignoring`;
21103
21202
  return Result.error(UnprivilegedError);
21104
21203
  }
21105
21204
  this.updatedState.stateUpdate.validatorsData = validatorsData;
@@ -21109,34 +21208,38 @@ class accumulate_externalities_AccumulateExternalities {
21109
21208
  /** https://graypaper.fluffylabs.dev/#/9a08063/362202362202?v=0.6.6 */
21110
21209
  this.checkpointedState = AccumulationStateUpdate.copyFrom(this.updatedState.stateUpdate);
21111
21210
  }
21112
- updateAuthorizationQueue(coreIndex, authQueue, authManager) {
21211
+ updateAuthorizationQueue(coreIndex, authQueue, assigners) {
21113
21212
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/36a40136a401?v=0.6.7 */
21114
21213
  // 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`;
21214
+ const currentAssigners = this.updatedState.getPrivilegedServices().assigners[coreIndex];
21215
+ if (currentAssigners !== this.currentServiceId) {
21216
+ 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
21217
  return Result.error(UpdatePrivilegesError.UnprivilegedService);
21119
21218
  }
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`;
21219
+ if (assigners === null && Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
21220
+ accumulate_externalities_logger.trace `The new auth manager is not a valid service id.`;
21122
21221
  return Result.error(UpdatePrivilegesError.InvalidServiceId);
21123
21222
  }
21124
21223
  this.updatedState.stateUpdate.authorizationQueues.set(coreIndex, authQueue);
21125
21224
  return Result.ok(OK);
21126
21225
  }
21127
- updatePrivilegedServices(manager, authorizers, validatorsManager, autoAccumulate) {
21226
+ updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate) {
21128
21227
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/36d90036de00?v=0.6.7 */
21129
21228
  const currentManager = this.updatedState.getPrivilegedServices().manager;
21130
21229
  if (currentManager !== this.currentServiceId) {
21131
21230
  return Result.error(UpdatePrivilegesError.UnprivilegedService);
21132
21231
  }
21133
- if (manager === null || validatorsManager === null) {
21134
- return Result.error(UpdatePrivilegesError.InvalidServiceId);
21232
+ if (manager === null || delegator === null) {
21233
+ return Result.error(UpdatePrivilegesError.InvalidServiceId, "Either manager or delegator is not valid service id.");
21234
+ }
21235
+ if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && registrar === null) {
21236
+ return Result.error(UpdatePrivilegesError.InvalidServiceId, "Register manager is not valid service id.");
21135
21237
  }
21136
21238
  this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
21137
21239
  manager,
21138
- authManager: authorizers,
21139
- validatorsManager,
21240
+ assigners: authorizers,
21241
+ delegator,
21242
+ registrar: registrar ?? tryAsServiceId(0), // introduced in 0.7.1
21140
21243
  autoAccumulateServices: autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit })),
21141
21244
  });
21142
21245
  return Result.ok(OK);
@@ -21252,8 +21355,11 @@ class accumulate_externalities_AccumulateExternalities {
21252
21355
  }
21253
21356
  }
21254
21357
  function bumpServiceId(serviceId) {
21255
- const mod = 2 ** 32 - 2 ** 9;
21256
- return tryAsServiceId(2 ** 8 + ((serviceId - 2 ** 8 + 42 + mod) % mod));
21358
+ const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
21359
+ ? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
21360
+ : 2 ** 32 - 2 ** 9;
21361
+ const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
21362
+ return tryAsServiceId(offset + ((serviceId - offset + 42 + mod) % mod));
21257
21363
  }
21258
21364
 
21259
21365
  ;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/operand.ts
@@ -21905,6 +22011,8 @@ class accumulate_data_AccumulateData {
21905
22011
 
21906
22012
 
21907
22013
 
22014
+
22015
+
21908
22016
  /**
21909
22017
  * A function that removes duplicates but does not change order - it keeps the first occurence.
21910
22018
  */
@@ -21934,7 +22042,7 @@ const NEXT_ID_CODEC = descriptors_codec.object({
21934
22042
  *
21935
22043
  * Please not that it does not call `check` function!
21936
22044
  *
21937
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/2f4c022f4c02?v=0.6.7
22045
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/2fa9042fc304?v=0.7.2
21938
22046
  */
21939
22047
  function accumulate_utils_generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blake2b) {
21940
22048
  const encoded = Encoder.encodeObject(NEXT_ID_CODEC, {
@@ -21944,7 +22052,11 @@ function accumulate_utils_generateNextServiceId({ serviceId, entropy, timeslot }
21944
22052
  }, chainSpec);
21945
22053
  const result = blake2b.hashBytes(encoded).raw.subarray(0, 4);
21946
22054
  const number = leBytesAsU32(result) >>> 0;
21947
- return tryAsServiceId((number % (2 ** 32 - 2 ** 9)) + 2 ** 8);
22055
+ const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
22056
+ ? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
22057
+ : 2 ** 32 - 2 ** 9;
22058
+ const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
22059
+ return tryAsServiceId((number % mod) + offset);
21948
22060
  }
21949
22061
 
21950
22062
  ;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-queue.ts
@@ -22356,7 +22468,7 @@ class Assign {
22356
22468
  // o
22357
22469
  const authorizationQueueStart = regs.get(8);
22358
22470
  // a
22359
- const authManager = getServiceId(regs.get(9));
22471
+ const assigners = getServiceId(regs.get(9));
22360
22472
  const res = safe_alloc_uint8array_safeAllocUint8Array(hash_HASH_SIZE * gp_constants_AUTHORIZATION_QUEUE_SIZE);
22361
22473
  const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
22362
22474
  // error while reading the memory.
@@ -22373,7 +22485,7 @@ class Assign {
22373
22485
  const decoder = decoder_Decoder.fromBlob(res);
22374
22486
  const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE), gp_constants_AUTHORIZATION_QUEUE_SIZE);
22375
22487
  const fixedSizeAuthQueue = sized_array_FixedSizeArray.new(authQueue, gp_constants_AUTHORIZATION_QUEUE_SIZE);
22376
- const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, authManager);
22488
+ const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
22377
22489
  if (result.isOk) {
22378
22490
  regs.set(IN_OUT_REG, results_HostCallResult.OK);
22379
22491
  logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
@@ -22422,7 +22534,9 @@ class Bless {
22422
22534
  chainSpec;
22423
22535
  index = host_call_handler_tryAsHostCallIndex(14);
22424
22536
  basicGasCost = gas_tryAsSmallGas(10);
22425
- tracedRegisters = host_call_handler_traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11);
22537
+ tracedRegisters = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1)
22538
+ ? host_call_handler_traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11, 12)
22539
+ : host_call_handler_traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11);
22426
22540
  constructor(currentServiceId, partialState, chainSpec) {
22427
22541
  this.currentServiceId = currentServiceId;
22428
22542
  this.partialState = partialState;
@@ -22432,14 +22546,17 @@ class Bless {
22432
22546
  // `m`: manager service (can change privileged services)
22433
22547
  const manager = getServiceId(regs.get(bless_IN_OUT_REG));
22434
22548
  // `a`: manages authorization queue
22435
- // NOTE It can be either ServiceId (pre GP 067) or memory index (GP ^067)
22436
22549
  const authorization = regs.get(8);
22437
22550
  // `v`: manages validator keys
22438
- const validator = getServiceId(regs.get(9));
22551
+ const delegator = getServiceId(regs.get(9));
22552
+ // `r`: manages creation of new services with id within protected range
22553
+ const registrar = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1)
22554
+ ? getServiceId(regs.get(10))
22555
+ : common_tryAsServiceId(2 ** 32 - 1);
22439
22556
  // `o`: memory offset
22440
- const sourceStart = regs.get(10);
22557
+ const sourceStart = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1) ? regs.get(11) : regs.get(10);
22441
22558
  // `n`: number of items in the auto-accumulate dictionary
22442
- const numberOfItems = regs.get(11);
22559
+ const numberOfItems = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1) ? regs.get(12) : regs.get(11);
22443
22560
  /*
22444
22561
  * `z`: array of key-value pairs serviceId -> gas that auto-accumulate every block
22445
22562
  * https://graypaper.fluffylabs.dev/#/7e6ff6a/368100368100?v=0.6.7
@@ -22453,7 +22570,7 @@ class Bless {
22453
22570
  decoder.resetTo(0);
22454
22571
  const memoryReadResult = memory.loadInto(result, memIndex);
22455
22572
  if (memoryReadResult.isError) {
22456
- logger_logger.trace `BLESS(${manager}, ${validator}) <- PANIC`;
22573
+ logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}) <- PANIC`;
22457
22574
  return host_call_handler_PvmExecution.Panic;
22458
22575
  }
22459
22576
  const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
@@ -22466,24 +22583,25 @@ class Bless {
22466
22583
  const authorizersDecoder = decoder_Decoder.fromBlob(res);
22467
22584
  const memoryReadResult = memory.loadInto(res, authorization);
22468
22585
  if (memoryReadResult.isError) {
22469
- logger_logger.trace `BLESS(${manager}, ${validator}, ${autoAccumulateEntries}) <- PANIC`;
22586
+ logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- PANIC`;
22470
22587
  return host_call_handler_PvmExecution.Panic;
22471
22588
  }
22589
+ // `a`
22472
22590
  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);
22591
+ const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulateEntries);
22474
22592
  if (updateResult.isOk) {
22475
- logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- OK`;
22593
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- OK`;
22476
22594
  regs.set(bless_IN_OUT_REG, results_HostCallResult.OK);
22477
22595
  return;
22478
22596
  }
22479
22597
  const e = updateResult.error;
22480
22598
  if (e === partial_state_UpdatePrivilegesError.UnprivilegedService) {
22481
- logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- HUH`;
22599
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- HUH`;
22482
22600
  regs.set(bless_IN_OUT_REG, results_HostCallResult.HUH);
22483
22601
  return;
22484
22602
  }
22485
22603
  if (e === partial_state_UpdatePrivilegesError.InvalidServiceId) {
22486
- logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- WHO`;
22604
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- WHO`;
22487
22605
  regs.set(bless_IN_OUT_REG, results_HostCallResult.WHO);
22488
22606
  return;
22489
22607
  }
@@ -22735,7 +22853,9 @@ class New {
22735
22853
  partialState;
22736
22854
  index = host_call_handler_tryAsHostCallIndex(18);
22737
22855
  basicGasCost = gas_tryAsSmallGas(10);
22738
- tracedRegisters = host_call_handler_traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11);
22856
+ tracedRegisters = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1)
22857
+ ? host_call_handler_traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11, 12)
22858
+ : host_call_handler_traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11);
22739
22859
  constructor(currentServiceId, partialState) {
22740
22860
  this.currentServiceId = currentServiceId;
22741
22861
  this.partialState = partialState;
@@ -22751,16 +22871,18 @@ class New {
22751
22871
  const allowance = common_tryAsServiceGas(regs.get(10));
22752
22872
  // `f`
22753
22873
  const gratisStorage = regs.get(11);
22874
+ // `i`: requested service id. Ignored if current service is not registrar or value is bigger than `S`.
22875
+ const requestedServiceId = regs.get(12);
22754
22876
  // `c`
22755
22877
  const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
22756
22878
  const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
22757
22879
  // error while reading the memory.
22758
22880
  if (memoryReadResult.isError) {
22759
- logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- PANIC`;
22881
+ logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
22760
22882
  return host_call_handler_PvmExecution.Panic;
22761
22883
  }
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)}`;
22884
+ const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage, requestedServiceId);
22885
+ logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${result_resultToString(assignedId)}`;
22764
22886
  if (assignedId.isOk) {
22765
22887
  regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
22766
22888
  return;
@@ -22774,6 +22896,11 @@ class New {
22774
22896
  regs.set(new_IN_OUT_REG, results_HostCallResult.HUH);
22775
22897
  return;
22776
22898
  }
22899
+ // Post 0.7.1
22900
+ if (e === partial_state_NewServiceError.RegistrarServiceIdAlreadyTaken) {
22901
+ regs.set(new_IN_OUT_REG, results_HostCallResult.FULL);
22902
+ return;
22903
+ }
22777
22904
  debug_assertNever(e);
22778
22905
  }
22779
22906
  }
@@ -23897,7 +24024,7 @@ class accumulate_Accumulate {
23897
24024
  }
23898
24025
  const nextServiceId = generateNextServiceId({ serviceId, entropy, timeslot: slot }, this.chainSpec, this.blake2b);
23899
24026
  const partialState = new AccumulateExternalities(this.chainSpec, this.blake2b, new PartiallyUpdatedState(this.state, inputStateUpdate), serviceId, nextServiceId, slot);
23900
- const fetchExternalities = Compatibility.isGreaterOrEqual(GpVersion.V0_7_2)
24027
+ const fetchExternalities = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
23901
24028
  ? FetchExternalities.createForAccumulate({ entropy, transfers, operands }, this.chainSpec)
23902
24029
  : FetchExternalities.createForPre071Accumulate({ entropy, operands }, this.chainSpec);
23903
24030
  const externalities = {
@@ -24012,7 +24139,7 @@ class accumulate_Accumulate {
24012
24139
  const accumulateData = new AccumulateData(reportsToAccumulateInParallel, transfers, autoAccumulateServices);
24013
24140
  const reportsToAccumulateSequentially = reports.subview(i);
24014
24141
  const { gasCost, state: stateAfterParallelAcc, ...rest } = await this.accumulateInParallel(accumulateData, slot, entropy, statistics, stateUpdate);
24015
- const newTransfers = stateAfterParallelAcc.transfers;
24142
+ const newTransfers = stateAfterParallelAcc.takeTransfers();
24016
24143
  assertEmpty(rest);
24017
24144
  // NOTE [ToDr] recursive invocation
24018
24145
  const { accumulatedReports, gasCost: seqGasCost, state, ...seqRest } = await this.accumulateSequentially(tryAsServiceGas(gasLimit - gasCost), reportsToAccumulateSequentially, newTransfers, slot, entropy, statistics, stateAfterParallelAcc, []);
@@ -24048,17 +24175,17 @@ class accumulate_Accumulate {
24048
24175
  statistics.set(serviceId, serviceStatistics);
24049
24176
  currentState = stateUpdate === null ? checkpoint : stateUpdate;
24050
24177
  if (Compatibility.is(GpVersion.V0_7_0) && serviceId === currentManager) {
24051
- const newV = currentState.privilegedServices?.validatorsManager;
24178
+ const newV = currentState.privilegedServices?.delegator;
24052
24179
  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+`;
24180
+ 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
24181
  // Since serviceIds already contains newV, this service gets accumulated twice.
24055
24182
  // To avoid double-counting, we skip stats and gas cost tracking here.
24056
- // We need this accumulation to get the correct `validatorsManager`
24183
+ // We need this accumulation to get the correct `delegator`
24057
24184
  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;
24185
+ const correctV = stateUpdate?.privilegedServices?.delegator ?? this.state.privilegedServices.delegator;
24059
24186
  currentState.privilegedServices = PrivilegedServices.create({
24060
24187
  ...currentState.privilegedServices,
24061
- validatorsManager: correctV,
24188
+ delegator: correctV,
24062
24189
  });
24063
24190
  }
24064
24191
  }