@typeberry/convert 0.1.3-8258907 → 0.1.3-a6eda68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +457 -333
  2. package/index.js.map +1 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -5728,7 +5728,7 @@ class Skipper {
5728
5728
  *
5729
5729
  * Descriptors can be composed to form more complex typings.
5730
5730
  */
5731
- class descriptor_Descriptor {
5731
+ class Descriptor {
5732
5732
  name;
5733
5733
  sizeHint;
5734
5734
  encode;
@@ -5738,11 +5738,11 @@ class descriptor_Descriptor {
5738
5738
  View;
5739
5739
  /** New descriptor with specialized `View`. */
5740
5740
  static withView(name, sizeHint, encode, decode, skip, view) {
5741
- return new descriptor_Descriptor(name, sizeHint, encode, decode, skip, view);
5741
+ return new Descriptor(name, sizeHint, encode, decode, skip, view);
5742
5742
  }
5743
5743
  /** Create a new descriptor without a specialized `View`. */
5744
5744
  static new(name, sizeHint, encode, decode, skip) {
5745
- return new descriptor_Descriptor(name, sizeHint, encode, decode, skip, null);
5745
+ return new Descriptor(name, sizeHint, encode, decode, skip, null);
5746
5746
  }
5747
5747
  constructor(
5748
5748
  /** Descriptive name of the coded data. */
@@ -5779,7 +5779,7 @@ class descriptor_Descriptor {
5779
5779
  }
5780
5780
  /** Return a new descriptor that converts data into some other type. */
5781
5781
  convert(input, output) {
5782
- 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);
5783
5783
  }
5784
5784
  /** Safely cast the descriptor value to a opaque type. */
5785
5785
  asOpaque() {
@@ -6477,51 +6477,51 @@ var descriptors_codec;
6477
6477
  return (len) => {
6478
6478
  let ret = cache.get(len);
6479
6479
  if (ret === undefined) {
6480
- 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));
6481
6481
  cache.set(len, ret);
6482
6482
  }
6483
6483
  return ret;
6484
6484
  };
6485
6485
  })();
6486
6486
  /** Variable-length U32. */
6487
- 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());
6488
6488
  /** Variable-length U64. */
6489
- 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());
6490
6490
  /** Unsigned 64-bit number. */
6491
- 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));
6492
6492
  /** Unsigned 32-bit number. */
6493
- 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));
6494
6494
  /** Unsigned 24-bit number. */
6495
- 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));
6496
6496
  /** Unsigned 16-bit number. */
6497
- 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));
6498
6498
  /** Unsigned 8-bit number. */
6499
- 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());
6500
6500
  /** Signed 64-bit number. */
6501
- 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));
6502
6502
  /** Signed 32-bit number. */
6503
- 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));
6504
6504
  /** Signed 24-bit number. */
6505
- 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));
6506
6506
  /** Signed 16-bit number. */
6507
- 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));
6508
6508
  /** Signed 8-bit number. */
6509
- 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());
6510
6510
  /** 1-byte boolean value. */
6511
- 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());
6512
6512
  /** Variable-length bytes blob. */
6513
- 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());
6514
6514
  /** String encoded as variable-length bytes blob. */
6515
- 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);
6516
6516
  /** Variable-length bit vector. */
6517
- 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());
6518
6518
  /** Fixed-length bit vector. */
6519
- 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));
6520
6520
  /** Optionality wrapper for given type. */
6521
6521
  codec.optional = (type) => {
6522
- 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));
6523
6523
  if (hasUniqueView(type)) {
6524
- 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));
6525
6525
  }
6526
6526
  return self;
6527
6527
  };
@@ -6532,7 +6532,7 @@ var descriptors_codec;
6532
6532
  }) => {
6533
6533
  const name = `Sequence<${type.name}>[?]`;
6534
6534
  const typicalLength = options.typicalLength ?? TYPICAL_SEQUENCE_LENGTH;
6535
- 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) => {
6536
6536
  validateLength(options, v.length, name);
6537
6537
  e.sequenceVarLen(type, v);
6538
6538
  }, (d) => {
@@ -6546,10 +6546,10 @@ var descriptors_codec;
6546
6546
  }, sequenceViewVarLen(type, options));
6547
6547
  };
6548
6548
  /** Fixed-length sequence of given type. */
6549
- 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 }));
6550
6550
  /** Small dictionary codec. */
6551
6551
  codec.dictionary = (key, value, { sortKeys, fixedLength, }) => {
6552
- const self = descriptor_Descriptor.new(`Dictionary<${key.name}, ${value.name}>[${fixedLength ?? "?"}]`, {
6552
+ const self = Descriptor.new(`Dictionary<${key.name}, ${value.name}>[${fixedLength ?? "?"}]`, {
6553
6553
  bytes: fixedLength !== undefined
6554
6554
  ? fixedLength * addSizeHints(key.sizeHint, value.sizeHint).bytes
6555
6555
  : TYPICAL_DICTIONARY_LENGTH * (addSizeHints(key.sizeHint, value.sizeHint).bytes ?? 0),
@@ -6588,13 +6588,13 @@ var descriptors_codec;
6588
6588
  s.sequenceFixLen(value, len);
6589
6589
  });
6590
6590
  if (hasUniqueView(value)) {
6591
- 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 }));
6592
6592
  }
6593
6593
  return self;
6594
6594
  };
6595
6595
  /** Encoding of pair of two values. */
6596
6596
  codec.pair = (a, b) => {
6597
- 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) => {
6598
6598
  a.encode(e, elem[0]);
6599
6599
  b.encode(e, elem[1]);
6600
6600
  }, (d) => {
@@ -6606,14 +6606,14 @@ var descriptors_codec;
6606
6606
  b.skip(s);
6607
6607
  });
6608
6608
  if (hasUniqueView(a) && hasUniqueView(b)) {
6609
- 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));
6610
6610
  }
6611
6611
  return self;
6612
6612
  };
6613
6613
  /** Custom encoding / decoding logic. */
6614
- 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);
6615
6615
  /** Choose a descriptor depending on the encoding/decoding context. */
6616
- 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);
6617
6617
  /**
6618
6618
  * A descriptor for a more complex POJO.
6619
6619
  *
@@ -6650,7 +6650,7 @@ var descriptors_codec;
6650
6650
  };
6651
6651
  const view = objectView(Class, descriptors, sizeHint, skipper);
6652
6652
  // and create the descriptor for the entire class.
6653
- return descriptor_Descriptor.withView(Class.name, sizeHint, (e, t) => {
6653
+ return Descriptor.withView(Class.name, sizeHint, (e, t) => {
6654
6654
  forEachDescriptor(descriptors, (key, descriptor) => {
6655
6655
  const value = t[key];
6656
6656
  descriptor.encode(e, value);
@@ -6701,7 +6701,7 @@ function objectView(Class, descriptors, sizeHint, skipper) {
6701
6701
  });
6702
6702
  }
6703
6703
  });
6704
- return descriptor_Descriptor.new(`View<${Class.name}>`, sizeHint, (e, t) => {
6704
+ return Descriptor.new(`View<${Class.name}>`, sizeHint, (e, t) => {
6705
6705
  const encoded = t.encoded();
6706
6706
  e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
6707
6707
  }, (d) => {
@@ -6720,7 +6720,7 @@ function sequenceViewVarLen(type, options) {
6720
6720
  validateLength(options, length, name);
6721
6721
  return s.sequenceFixLen(type, length);
6722
6722
  };
6723
- return descriptor_Descriptor.new(name, sizeHint, (e, t) => {
6723
+ return Descriptor.new(name, sizeHint, (e, t) => {
6724
6724
  validateLength(options, t.length, name);
6725
6725
  const encoded = t.encoded();
6726
6726
  e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
@@ -6736,7 +6736,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
6736
6736
  const skipper = (s) => s.sequenceFixLen(type, fixedLength);
6737
6737
  const view = type.name !== type.View.name ? `, ${type.View.name}` : "";
6738
6738
  const name = `SeqView<${type.name}${view}>[${fixedLength}]`;
6739
- return descriptor_Descriptor.new(name, sizeHint, (e, t) => {
6739
+ return Descriptor.new(name, sizeHint, (e, t) => {
6740
6740
  const encoded = t.encoded();
6741
6741
  e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
6742
6742
  }, (d) => {
@@ -8609,7 +8609,7 @@ const codecFixedSizeArray = (val, len) => {
8609
8609
  };
8610
8610
  /** Codec for a hash-dictionary. */
8611
8611
  const codecHashDictionary = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH, compare = (a, b) => extractKey(a).compare(extractKey(b)), } = {}) => {
8612
- return descriptor_Descriptor.new(`HashDictionary<${value.name}>[?]`, {
8612
+ return Descriptor.new(`HashDictionary<${value.name}>[?]`, {
8613
8613
  bytes: typicalLength * value.sizeHint.bytes,
8614
8614
  isExact: false,
8615
8615
  }, (e, v) => {
@@ -11593,6 +11593,13 @@ const gp_constants_W_T = 128;
11593
11593
  /** `W_M`: The maximum number of exports in a work-package. */
11594
11594
  const gp_constants_W_X = 3_072;
11595
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));
11596
11603
  /**
11597
11604
  * `J`: The maximum sum of dependency items in a work-report.
11598
11605
  *
@@ -11604,9 +11611,209 @@ const gp_constants_AUTHORIZATION_QUEUE_SIZE = gp_constants_Q;
11604
11611
  /** `O`: Maximal authorization pool size. */
11605
11612
  const gp_constants_MAX_AUTH_POOL_SIZE = gp_constants_O;
11606
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
+
11607
11811
  ;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
11608
11812
 
11609
11813
 
11814
+
11815
+
11816
+
11610
11817
  /** Dictionary entry of services that auto-accumulate every block. */
11611
11818
  class privileged_services_AutoAccumulate {
11612
11819
  service;
@@ -11628,39 +11835,50 @@ class privileged_services_AutoAccumulate {
11628
11835
  }
11629
11836
  }
11630
11837
  /**
11631
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11da0111da01?v=0.6.7
11838
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
11632
11839
  */
11633
11840
  class privileged_services_PrivilegedServices {
11634
11841
  manager;
11635
- authManager;
11636
- validatorsManager;
11842
+ delegator;
11843
+ registrar;
11844
+ assigners;
11637
11845
  autoAccumulateServices;
11846
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
11638
11847
  static Codec = descriptors_codec.Class(privileged_services_PrivilegedServices, {
11639
11848
  manager: descriptors_codec.u32.asOpaque(),
11640
- authManager: codecPerCore(descriptors_codec.u32.asOpaque()),
11641
- 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)),
11642
11854
  autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(privileged_services_AutoAccumulate.Codec)),
11643
11855
  });
11644
- static create({ manager, authManager, validatorsManager, autoAccumulateServices }) {
11645
- 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);
11646
11858
  }
11647
11859
  constructor(
11648
11860
  /**
11649
- * `chi_m`: The first, χm, is the index of the manager service which is
11650
- * the service able to effect an alteration of χ from block to block,
11861
+ * `χ_M`: Manages alteration of χ from block to block,
11651
11862
  * as well as bestow services with storage deposit credits.
11652
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11a40111a801?v=0.6.7
11863
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
11653
11864
  */
11654
11865
  manager,
11655
- /** `chi_a`: Manages authorization queue one for each core. */
11656
- authManager,
11657
- /** `chi_v`: Managers validator keys. */
11658
- validatorsManager,
11659
- /** `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. */
11660
11877
  autoAccumulateServices) {
11661
11878
  this.manager = manager;
11662
- this.authManager = authManager;
11663
- this.validatorsManager = validatorsManager;
11879
+ this.delegator = delegator;
11880
+ this.registrar = registrar;
11881
+ this.assigners = assigners;
11664
11882
  this.autoAccumulateServices = autoAccumulateServices;
11665
11883
  }
11666
11884
  }
@@ -11748,7 +11966,7 @@ class recent_blocks_RecentBlocks extends WithDebug {
11748
11966
  */
11749
11967
  class recent_blocks_RecentBlocksHistory extends WithDebug {
11750
11968
  current;
11751
- 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) => {
11752
11970
  const recentBlocks = recent_blocks_RecentBlocks.Codec.decode(decoder);
11753
11971
  return recent_blocks_RecentBlocksHistory.create(recentBlocks);
11754
11972
  }, (skip) => {
@@ -11945,196 +12163,6 @@ class safrole_data_SafroleData {
11945
12163
  }
11946
12164
  }
11947
12165
 
11948
- ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
11949
-
11950
-
11951
-
11952
-
11953
-
11954
-
11955
- /**
11956
- * `B_S`: The basic minimum balance which all services require.
11957
- *
11958
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
11959
- */
11960
- const service_BASE_SERVICE_BALANCE = 100n;
11961
- /**
11962
- * `B_I`: The additional minimum balance required per item of elective service state.
11963
- *
11964
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
11965
- */
11966
- const service_ELECTIVE_ITEM_BALANCE = 10n;
11967
- /**
11968
- * `B_L`: The additional minimum balance required per octet of elective service state.
11969
- *
11970
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
11971
- */
11972
- const service_ELECTIVE_BYTE_BALANCE = 1n;
11973
- const zeroSizeHint = {
11974
- bytes: 0,
11975
- isExact: true,
11976
- };
11977
- /** 0-byte read, return given default value */
11978
- const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
11979
- /** Encode and decode object with leading version number. */
11980
- const codecWithVersion = (val) => descriptor_Descriptor.new("withVersion", {
11981
- bytes: val.sizeHint.bytes + 8,
11982
- isExact: false,
11983
- }, (e, v) => {
11984
- e.varU64(0n);
11985
- val.encode(e, v);
11986
- }, (d) => {
11987
- const version = d.varU64();
11988
- if (version !== 0n) {
11989
- throw new Error("Non-zero version is not supported!");
11990
- }
11991
- return val.decode(d);
11992
- }, (s) => {
11993
- s.varU64();
11994
- val.skip(s);
11995
- });
11996
- /**
11997
- * Service account details.
11998
- *
11999
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
12000
- */
12001
- class service_ServiceAccountInfo extends WithDebug {
12002
- codeHash;
12003
- balance;
12004
- accumulateMinGas;
12005
- onTransferMinGas;
12006
- storageUtilisationBytes;
12007
- gratisStorage;
12008
- storageUtilisationCount;
12009
- created;
12010
- lastAccumulation;
12011
- parentService;
12012
- static Codec = descriptors_codec.Class(service_ServiceAccountInfo, {
12013
- codeHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
12014
- balance: descriptors_codec.u64,
12015
- accumulateMinGas: descriptors_codec.u64.convert((x) => x, common_tryAsServiceGas),
12016
- onTransferMinGas: descriptors_codec.u64.convert((x) => x, common_tryAsServiceGas),
12017
- storageUtilisationBytes: descriptors_codec.u64,
12018
- gratisStorage: descriptors_codec.u64,
12019
- storageUtilisationCount: descriptors_codec.u32,
12020
- created: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
12021
- lastAccumulation: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
12022
- parentService: descriptors_codec.u32.convert((x) => x, common_tryAsServiceId),
12023
- });
12024
- static create(a) {
12025
- return new service_ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
12026
- }
12027
- /**
12028
- * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
12029
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
12030
- */
12031
- static calculateThresholdBalance(items, bytes, gratisStorage) {
12032
- const storageCost = service_BASE_SERVICE_BALANCE + service_ELECTIVE_ITEM_BALANCE * BigInt(items) + service_ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
12033
- if (storageCost < 0n) {
12034
- return numbers_tryAsU64(0);
12035
- }
12036
- if (storageCost >= 2n ** 64n) {
12037
- return numbers_tryAsU64(2n ** 64n - 1n);
12038
- }
12039
- return numbers_tryAsU64(storageCost);
12040
- }
12041
- constructor(
12042
- /** `a_c`: Hash of the service code. */
12043
- codeHash,
12044
- /** `a_b`: Current account balance. */
12045
- balance,
12046
- /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
12047
- accumulateMinGas,
12048
- /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
12049
- onTransferMinGas,
12050
- /** `a_o`: Total number of octets in storage. */
12051
- storageUtilisationBytes,
12052
- /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
12053
- gratisStorage,
12054
- /** `a_i`: Number of items in storage. */
12055
- storageUtilisationCount,
12056
- /** `a_r`: Creation account time slot. */
12057
- created,
12058
- /** `a_a`: Most recent accumulation time slot. */
12059
- lastAccumulation,
12060
- /** `a_p`: Parent service ID. */
12061
- parentService) {
12062
- super();
12063
- this.codeHash = codeHash;
12064
- this.balance = balance;
12065
- this.accumulateMinGas = accumulateMinGas;
12066
- this.onTransferMinGas = onTransferMinGas;
12067
- this.storageUtilisationBytes = storageUtilisationBytes;
12068
- this.gratisStorage = gratisStorage;
12069
- this.storageUtilisationCount = storageUtilisationCount;
12070
- this.created = created;
12071
- this.lastAccumulation = lastAccumulation;
12072
- this.parentService = parentService;
12073
- }
12074
- }
12075
- class service_PreimageItem extends WithDebug {
12076
- hash;
12077
- blob;
12078
- static Codec = descriptors_codec.Class(service_PreimageItem, {
12079
- hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
12080
- blob: descriptors_codec.blob,
12081
- });
12082
- static create({ hash, blob }) {
12083
- return new service_PreimageItem(hash, blob);
12084
- }
12085
- constructor(hash, blob) {
12086
- super();
12087
- this.hash = hash;
12088
- this.blob = blob;
12089
- }
12090
- }
12091
- class service_StorageItem extends WithDebug {
12092
- key;
12093
- value;
12094
- static Codec = descriptors_codec.Class(service_StorageItem, {
12095
- key: descriptors_codec.blob.convert((i) => i, (o) => opaque_asOpaqueType(o)),
12096
- value: descriptors_codec.blob,
12097
- });
12098
- static create({ key, value }) {
12099
- return new service_StorageItem(key, value);
12100
- }
12101
- constructor(key, value) {
12102
- super();
12103
- this.key = key;
12104
- this.value = value;
12105
- }
12106
- }
12107
- const MAX_LOOKUP_HISTORY_SLOTS = 3;
12108
- function service_tryAsLookupHistorySlots(items) {
12109
- const knownSize = sized_array_asKnownSize(items);
12110
- if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
12111
- throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
12112
- }
12113
- return knownSize;
12114
- }
12115
- /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
12116
- class service_LookupHistoryItem {
12117
- hash;
12118
- length;
12119
- slots;
12120
- constructor(hash, length,
12121
- /**
12122
- * Preimage availability history as a sequence of time slots.
12123
- * See PreimageStatus and the following GP fragment for more details.
12124
- * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
12125
- slots) {
12126
- this.hash = hash;
12127
- this.length = length;
12128
- this.slots = slots;
12129
- }
12130
- static isRequested(item) {
12131
- if ("slots" in item) {
12132
- return item.slots.length === 0;
12133
- }
12134
- return item.length === 0;
12135
- }
12136
- }
12137
-
12138
12166
  ;// CONCATENATED MODULE: ./packages/jam/state/state.ts
12139
12167
  /**
12140
12168
  * In addition to the entropy accumulator η_0, we retain
@@ -12571,6 +12599,7 @@ class statistics_StatisticsData {
12571
12599
 
12572
12600
 
12573
12601
 
12602
+
12574
12603
 
12575
12604
 
12576
12605
  var in_memory_state_UpdateError;
@@ -12974,8 +13003,9 @@ class InMemoryState extends WithDebug {
12974
13003
  epochRoot: bytes_Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
12975
13004
  privilegedServices: privileged_services_PrivilegedServices.create({
12976
13005
  manager: common_tryAsServiceId(0),
12977
- authManager: common_tryAsPerCore(new Array(spec.coresCount).fill(common_tryAsServiceId(0)), spec),
12978
- 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),
12979
13009
  autoAccumulateServices: [],
12980
13010
  }),
12981
13011
  accumulationOutputLog: sorted_array_SortedArray.fromArray(accumulation_output_accumulationOutputComparator, []),
@@ -13021,6 +13051,7 @@ const serviceDataCodec = descriptors_codec.dictionary(descriptors_codec.u32.asOp
13021
13051
 
13022
13052
  class JsonServiceInfo {
13023
13053
  static fromJson = json.object({
13054
+ ...(compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1) ? { version: "number" } : {}),
13024
13055
  code_hash: fromJson.bytes32(),
13025
13056
  balance: json.fromNumber((x) => numbers_tryAsU64(x)),
13026
13057
  min_item_gas: json.fromNumber((x) => common_tryAsServiceGas(x)),
@@ -13045,6 +13076,7 @@ class JsonServiceInfo {
13045
13076
  parentService: parent_service,
13046
13077
  });
13047
13078
  });
13079
+ version;
13048
13080
  code_hash;
13049
13081
  balance;
13050
13082
  min_item_gas;
@@ -13079,23 +13111,35 @@ const lookupMetaFromJson = json.object({
13079
13111
  },
13080
13112
  value: json.array("number"),
13081
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));
13082
13118
  class JsonService {
13083
13119
  static fromJson = json.object({
13084
13120
  id: "number",
13085
- data: {
13086
- service: JsonServiceInfo.fromJson,
13087
- preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
13088
- storage: json.optional(json.array(JsonStorageItem.fromJson)),
13089
- lookup_meta: json.optional(json.array(lookupMetaFromJson)),
13090
- },
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
+ },
13091
13134
  }, ({ id, data }) => {
13135
+ const preimages = hash_dictionary_HashDictionary.fromEntries((data.preimages ?? data.preimages_blob ?? []).map((x) => [x.hash, x]));
13092
13136
  const lookupHistory = hash_dictionary_HashDictionary.new();
13093
- for (const item of data.lookup_meta ?? []) {
13137
+ for (const item of data.lookup_meta ?? data.preimages_status ?? []) {
13094
13138
  const data = lookupHistory.get(item.hash) ?? [];
13095
- 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));
13096
13141
  lookupHistory.set(item.hash, data);
13097
13142
  }
13098
- const preimages = hash_dictionary_HashDictionary.fromEntries((data.preimages ?? []).map((x) => [x.hash, x]));
13099
13143
  const storage = new Map();
13100
13144
  const entries = (data.storage ?? []).map(({ key, value }) => {
13101
13145
  const opaqueKey = opaque_asOpaqueType(key);
@@ -13290,6 +13334,8 @@ class TicketsOrKeys {
13290
13334
 
13291
13335
 
13292
13336
 
13337
+
13338
+
13293
13339
  class JsonValidatorStatistics {
13294
13340
  static fromJson = json.object({
13295
13341
  blocks: "number",
@@ -13358,8 +13404,12 @@ class JsonServiceStatistics {
13358
13404
  extrinsic_count: "number",
13359
13405
  accumulate_count: "number",
13360
13406
  accumulate_gas_used: json.fromNumber(common_tryAsServiceGas),
13361
- on_transfers_count: "number",
13362
- 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
+ : {}),
13363
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, }) => {
13364
13414
  return statistics_ServiceStatistics.create({
13365
13415
  providedCount: provided_count,
@@ -13372,8 +13422,8 @@ class JsonServiceStatistics {
13372
13422
  extrinsicCount: extrinsic_count,
13373
13423
  accumulateCount: accumulate_count,
13374
13424
  accumulateGasUsed: accumulate_gas_used,
13375
- onTransfersCount: on_transfers_count,
13376
- onTransfersGasUsed: on_transfers_gas_used,
13425
+ onTransfersCount: on_transfers_count ?? numbers_tryAsU32(0),
13426
+ onTransfersGasUsed: on_transfers_gas_used ?? common_tryAsServiceGas(0),
13377
13427
  });
13378
13428
  });
13379
13429
  provided_count;
@@ -13447,6 +13497,7 @@ const validatorDataFromJson = json.object({
13447
13497
 
13448
13498
 
13449
13499
 
13500
+
13450
13501
  const fullStateDumpFromJson = (spec) => json.object({
13451
13502
  alpha: json.array(json.array(fromJson.bytes32())),
13452
13503
  varphi: json.array(json.array(fromJson.bytes32())),
@@ -13468,6 +13519,7 @@ const fullStateDumpFromJson = (spec) => json.object({
13468
13519
  chi_m: "number",
13469
13520
  chi_a: json.array("number"),
13470
13521
  chi_v: "number",
13522
+ chi_r: json.optional("number"),
13471
13523
  chi_g: json.nullable(json.array({
13472
13524
  service: "number",
13473
13525
  gasLimit: json.fromNumber((v) => common_tryAsServiceGas(v)),
@@ -13479,6 +13531,9 @@ const fullStateDumpFromJson = (spec) => json.object({
13479
13531
  theta: json.nullable(json.array(accumulationOutput)),
13480
13532
  accounts: json.array(JsonService.fromJson),
13481
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
+ }
13482
13537
  return InMemoryState.create({
13483
13538
  authPools: common_tryAsPerCore(alpha.map((perCore) => {
13484
13539
  if (perCore.length > gp_constants_MAX_AUTH_POOL_SIZE) {
@@ -13506,8 +13561,9 @@ const fullStateDumpFromJson = (spec) => json.object({
13506
13561
  timeslot: tau,
13507
13562
  privilegedServices: privileged_services_PrivilegedServices.create({
13508
13563
  manager: chi.chi_m,
13509
- authManager: chi.chi_a,
13510
- validatorsManager: chi.chi_v,
13564
+ assigners: chi.chi_a,
13565
+ delegator: chi.chi_v,
13566
+ registrar: chi.chi_r ?? common_tryAsServiceId(2 ** 32 - 1),
13511
13567
  autoAccumulateServices: chi.chi_g ?? [],
13512
13568
  }),
13513
13569
  statistics: JsonStatisticsData.toStatisticsData(spec, pi),
@@ -13849,7 +13905,7 @@ var serialize_serialize;
13849
13905
  * determine the boundary of the bytes, so it can only be used
13850
13906
  * as the last element of the codec and can't be used in sequences!
13851
13907
  */
13852
- 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()));
13853
13909
 
13854
13910
  ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
13855
13911
 
@@ -15063,7 +15119,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
15063
15119
  }
15064
15120
  return Ordering.Equal;
15065
15121
  }, } = {}) => {
15066
- return descriptor_Descriptor.new(`Map<${value.name}>[?]`, {
15122
+ return Descriptor.new(`Map<${value.name}>[?]`, {
15067
15123
  bytes: typicalLength * value.sizeHint.bytes,
15068
15124
  isExact: false,
15069
15125
  }, (e, v) => {
@@ -16712,11 +16768,17 @@ class state_update_AccumulationStateUpdate {
16712
16768
  if (from.privilegedServices !== null) {
16713
16769
  update.privilegedServices = PrivilegedServices.create({
16714
16770
  ...from.privilegedServices,
16715
- authManager: asKnownSize([...from.privilegedServices.authManager]),
16771
+ assigners: asKnownSize([...from.privilegedServices.assigners]),
16716
16772
  });
16717
16773
  }
16718
16774
  return update;
16719
16775
  }
16776
+ /** Retrieve and clear pending transfers. */
16777
+ takeTransfers() {
16778
+ const transfers = this.transfers;
16779
+ this.transfers = [];
16780
+ return transfers;
16781
+ }
16720
16782
  }
16721
16783
  class state_update_PartiallyUpdatedState {
16722
16784
  state;
@@ -20580,6 +20642,8 @@ var partial_state_NewServiceError;
20580
20642
  NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
20581
20643
  /** Service is not privileged to set gratis storage. */
20582
20644
  NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
20645
+ /** Registrar attempting to create a service with already existing id. */
20646
+ NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
20583
20647
  })(partial_state_NewServiceError || (partial_state_NewServiceError = {}));
20584
20648
  var partial_state_UpdatePrivilegesError;
20585
20649
  (function (UpdatePrivilegesError) {
@@ -20716,7 +20780,7 @@ const results_HostCallResult = {
20716
20780
  OOB: numbers_tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
20717
20781
  /** Index unknown. */
20718
20782
  WHO: numbers_tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
20719
- /** Storage full. */
20783
+ /** Storage full or resource already allocated. */
20720
20784
  FULL: numbers_tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
20721
20785
  /** Core index unknown. */
20722
20786
  CORE: numbers_tryAsU64(0xfffffffffffffffan), // 2**64 - 6
@@ -20724,7 +20788,7 @@ const results_HostCallResult = {
20724
20788
  CASH: numbers_tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
20725
20789
  /** Gas limit too low. */
20726
20790
  LOW: numbers_tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
20727
- /** 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. */
20728
20792
  HUH: numbers_tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
20729
20793
  /** The return value indicating general success. */
20730
20794
  OK: numbers_tryAsU64(0n),
@@ -20778,6 +20842,7 @@ function utils_clampU64ToU32(value) {
20778
20842
 
20779
20843
 
20780
20844
 
20845
+
20781
20846
  /**
20782
20847
  * Number of storage items required for ejection of the service.
20783
20848
  *
@@ -20869,10 +20934,13 @@ class accumulate_externalities_AccumulateExternalities {
20869
20934
  const isExpired = status.data[1] < t - this.chainSpec.preimageExpungePeriod;
20870
20935
  return [isExpired, isExpired ? "" : "not expired"];
20871
20936
  }
20872
- /** `check`: https://graypaper.fluffylabs.dev/#/9a08063/303f02303f02?v=0.6.6 */
20937
+ /** `check`: https://graypaper.fluffylabs.dev/#/ab2cdbd/30c60330c603?v=0.7.2 */
20873
20938
  getNextAvailableServiceId(serviceId) {
20874
20939
  let currentServiceId = serviceId;
20875
- 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;
20876
20944
  for (;;) {
20877
20945
  const service = this.getServiceInfo(currentServiceId);
20878
20946
  // we found an empty id
@@ -20880,7 +20948,7 @@ class accumulate_externalities_AccumulateExternalities {
20880
20948
  return currentServiceId;
20881
20949
  }
20882
20950
  // keep trying
20883
- currentServiceId = tryAsServiceId(((currentServiceId - 2 ** 8 + 1 + mod) % mod) + 2 ** 8);
20951
+ currentServiceId = tryAsServiceId(((currentServiceId - offset + 1 + mod) % mod) + offset);
20884
20952
  }
20885
20953
  }
20886
20954
  checkPreimageStatus(hash, length) {
@@ -21037,8 +21105,7 @@ class accumulate_externalities_AccumulateExternalities {
21037
21105
  }));
21038
21106
  return Result.ok(OK);
21039
21107
  }
21040
- newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage) {
21041
- const newServiceId = this.nextNewServiceId;
21108
+ newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage, wantedServiceId) {
21042
21109
  // calculate the threshold. Storage is empty, one preimage requested.
21043
21110
  // https://graypaper.fluffylabs.dev/#/7e6ff6a/115901115901?v=0.6.7
21044
21111
  const items = tryAsU32(2 * 1 + 0);
@@ -21059,30 +21126,59 @@ class accumulate_externalities_AccumulateExternalities {
21059
21126
  if (balanceLeftForCurrent < thresholdForCurrent || bytes.overflow) {
21060
21127
  return Result.error(NewServiceError.InsufficientFunds);
21061
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;
21062
21172
  // add the new service
21063
- // https://graypaper.fluffylabs.dev/#/7e6ff6a/36cb0236cb02?v=0.6.7
21173
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36e70336e903?v=0.7.2
21064
21174
  this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
21065
21175
  serviceId: newServiceId,
21066
- serviceInfo: ServiceAccountInfo.create({
21067
- codeHash,
21068
- balance: thresholdForNew,
21069
- accumulateMinGas,
21070
- onTransferMinGas,
21071
- storageUtilisationBytes: bytes.value,
21072
- storageUtilisationCount: items,
21073
- gratisStorage,
21074
- created: this.currentTimeslot,
21075
- lastAccumulation: tryAsTimeSlot(0),
21076
- parentService: this.currentServiceId,
21077
- }),
21078
- lookupHistory: new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([])),
21176
+ serviceInfo: newAccount,
21177
+ lookupHistory: newLookupItem,
21079
21178
  }));
21080
21179
  // update the balance of current service
21081
- // https://graypaper.fluffylabs.dev/#/7e6ff6a/364d03364d03?v=0.6.7
21082
- this.updatedState.updateServiceInfo(this.currentServiceId, ServiceAccountInfo.create({
21083
- ...currentService,
21084
- balance: tryAsU64(balanceLeftForCurrent),
21085
- }));
21180
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36ec0336ee03?v=0.7.2
21181
+ this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
21086
21182
  // update the next service id we are going to create next
21087
21183
  // https://graypaper.fluffylabs.dev/#/7e6ff6a/36a70336a703?v=0.6.7
21088
21184
  this.nextNewServiceId = this.getNextAvailableServiceId(bumpServiceId(newServiceId));
@@ -21100,9 +21196,9 @@ class accumulate_externalities_AccumulateExternalities {
21100
21196
  }
21101
21197
  updateValidatorsData(validatorsData) {
21102
21198
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/362802362d02?v=0.6.7 */
21103
- const validatorsManager = this.updatedState.getPrivilegedServices().validatorsManager;
21104
- if (validatorsManager !== this.currentServiceId) {
21105
- 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`;
21106
21202
  return Result.error(UnprivilegedError);
21107
21203
  }
21108
21204
  this.updatedState.stateUpdate.validatorsData = validatorsData;
@@ -21112,34 +21208,38 @@ class accumulate_externalities_AccumulateExternalities {
21112
21208
  /** https://graypaper.fluffylabs.dev/#/9a08063/362202362202?v=0.6.6 */
21113
21209
  this.checkpointedState = AccumulationStateUpdate.copyFrom(this.updatedState.stateUpdate);
21114
21210
  }
21115
- updateAuthorizationQueue(coreIndex, authQueue, authManager) {
21211
+ updateAuthorizationQueue(coreIndex, authQueue, assigners) {
21116
21212
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/36a40136a401?v=0.6.7 */
21117
21213
  // NOTE `coreIndex` is already verified in the HC, so this is infallible.
21118
- const currentAuthManager = this.updatedState.getPrivilegedServices().authManager[coreIndex];
21119
- if (currentAuthManager !== this.currentServiceId) {
21120
- 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.`;
21121
21217
  return Result.error(UpdatePrivilegesError.UnprivilegedService);
21122
21218
  }
21123
- if (authManager === null && Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
21124
- 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.`;
21125
21221
  return Result.error(UpdatePrivilegesError.InvalidServiceId);
21126
21222
  }
21127
21223
  this.updatedState.stateUpdate.authorizationQueues.set(coreIndex, authQueue);
21128
21224
  return Result.ok(OK);
21129
21225
  }
21130
- updatePrivilegedServices(manager, authorizers, validatorsManager, autoAccumulate) {
21226
+ updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate) {
21131
21227
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/36d90036de00?v=0.6.7 */
21132
21228
  const currentManager = this.updatedState.getPrivilegedServices().manager;
21133
21229
  if (currentManager !== this.currentServiceId) {
21134
21230
  return Result.error(UpdatePrivilegesError.UnprivilegedService);
21135
21231
  }
21136
- if (manager === null || validatorsManager === null) {
21137
- 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.");
21138
21237
  }
21139
21238
  this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
21140
21239
  manager,
21141
- authManager: authorizers,
21142
- validatorsManager,
21240
+ assigners: authorizers,
21241
+ delegator,
21242
+ registrar: registrar ?? tryAsServiceId(0), // introduced in 0.7.1
21143
21243
  autoAccumulateServices: autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit })),
21144
21244
  });
21145
21245
  return Result.ok(OK);
@@ -21255,8 +21355,11 @@ class accumulate_externalities_AccumulateExternalities {
21255
21355
  }
21256
21356
  }
21257
21357
  function bumpServiceId(serviceId) {
21258
- const mod = 2 ** 32 - 2 ** 9;
21259
- 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));
21260
21363
  }
21261
21364
 
21262
21365
  ;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/operand.ts
@@ -21908,6 +22011,8 @@ class accumulate_data_AccumulateData {
21908
22011
 
21909
22012
 
21910
22013
 
22014
+
22015
+
21911
22016
  /**
21912
22017
  * A function that removes duplicates but does not change order - it keeps the first occurence.
21913
22018
  */
@@ -21937,7 +22042,7 @@ const NEXT_ID_CODEC = descriptors_codec.object({
21937
22042
  *
21938
22043
  * Please not that it does not call `check` function!
21939
22044
  *
21940
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/2f4c022f4c02?v=0.6.7
22045
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/2fa9042fc304?v=0.7.2
21941
22046
  */
21942
22047
  function accumulate_utils_generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blake2b) {
21943
22048
  const encoded = Encoder.encodeObject(NEXT_ID_CODEC, {
@@ -21947,7 +22052,11 @@ function accumulate_utils_generateNextServiceId({ serviceId, entropy, timeslot }
21947
22052
  }, chainSpec);
21948
22053
  const result = blake2b.hashBytes(encoded).raw.subarray(0, 4);
21949
22054
  const number = leBytesAsU32(result) >>> 0;
21950
- 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);
21951
22060
  }
21952
22061
 
21953
22062
  ;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-queue.ts
@@ -22359,7 +22468,7 @@ class Assign {
22359
22468
  // o
22360
22469
  const authorizationQueueStart = regs.get(8);
22361
22470
  // a
22362
- const authManager = getServiceId(regs.get(9));
22471
+ const assigners = getServiceId(regs.get(9));
22363
22472
  const res = safe_alloc_uint8array_safeAllocUint8Array(hash_HASH_SIZE * gp_constants_AUTHORIZATION_QUEUE_SIZE);
22364
22473
  const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
22365
22474
  // error while reading the memory.
@@ -22376,7 +22485,7 @@ class Assign {
22376
22485
  const decoder = decoder_Decoder.fromBlob(res);
22377
22486
  const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE), gp_constants_AUTHORIZATION_QUEUE_SIZE);
22378
22487
  const fixedSizeAuthQueue = sized_array_FixedSizeArray.new(authQueue, gp_constants_AUTHORIZATION_QUEUE_SIZE);
22379
- const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, authManager);
22488
+ const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
22380
22489
  if (result.isOk) {
22381
22490
  regs.set(IN_OUT_REG, results_HostCallResult.OK);
22382
22491
  logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
@@ -22425,7 +22534,9 @@ class Bless {
22425
22534
  chainSpec;
22426
22535
  index = host_call_handler_tryAsHostCallIndex(14);
22427
22536
  basicGasCost = gas_tryAsSmallGas(10);
22428
- 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);
22429
22540
  constructor(currentServiceId, partialState, chainSpec) {
22430
22541
  this.currentServiceId = currentServiceId;
22431
22542
  this.partialState = partialState;
@@ -22435,14 +22546,17 @@ class Bless {
22435
22546
  // `m`: manager service (can change privileged services)
22436
22547
  const manager = getServiceId(regs.get(bless_IN_OUT_REG));
22437
22548
  // `a`: manages authorization queue
22438
- // NOTE It can be either ServiceId (pre GP 067) or memory index (GP ^067)
22439
22549
  const authorization = regs.get(8);
22440
22550
  // `v`: manages validator keys
22441
- 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);
22442
22556
  // `o`: memory offset
22443
- const sourceStart = regs.get(10);
22557
+ const sourceStart = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1) ? regs.get(11) : regs.get(10);
22444
22558
  // `n`: number of items in the auto-accumulate dictionary
22445
- const numberOfItems = regs.get(11);
22559
+ const numberOfItems = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1) ? regs.get(12) : regs.get(11);
22446
22560
  /*
22447
22561
  * `z`: array of key-value pairs serviceId -> gas that auto-accumulate every block
22448
22562
  * https://graypaper.fluffylabs.dev/#/7e6ff6a/368100368100?v=0.6.7
@@ -22456,7 +22570,7 @@ class Bless {
22456
22570
  decoder.resetTo(0);
22457
22571
  const memoryReadResult = memory.loadInto(result, memIndex);
22458
22572
  if (memoryReadResult.isError) {
22459
- logger_logger.trace `BLESS(${manager}, ${validator}) <- PANIC`;
22573
+ logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}) <- PANIC`;
22460
22574
  return host_call_handler_PvmExecution.Panic;
22461
22575
  }
22462
22576
  const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
@@ -22469,24 +22583,25 @@ class Bless {
22469
22583
  const authorizersDecoder = decoder_Decoder.fromBlob(res);
22470
22584
  const memoryReadResult = memory.loadInto(res, authorization);
22471
22585
  if (memoryReadResult.isError) {
22472
- logger_logger.trace `BLESS(${manager}, ${validator}, ${autoAccumulateEntries}) <- PANIC`;
22586
+ logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- PANIC`;
22473
22587
  return host_call_handler_PvmExecution.Panic;
22474
22588
  }
22589
+ // `a`
22475
22590
  const authorizers = common_tryAsPerCore(authorizersDecoder.sequenceFixLen(descriptors_codec.u32.asOpaque(), this.chainSpec.coresCount), this.chainSpec);
22476
- const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, validator, autoAccumulateEntries);
22591
+ const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulateEntries);
22477
22592
  if (updateResult.isOk) {
22478
- logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- OK`;
22593
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- OK`;
22479
22594
  regs.set(bless_IN_OUT_REG, results_HostCallResult.OK);
22480
22595
  return;
22481
22596
  }
22482
22597
  const e = updateResult.error;
22483
22598
  if (e === partial_state_UpdatePrivilegesError.UnprivilegedService) {
22484
- logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- HUH`;
22599
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- HUH`;
22485
22600
  regs.set(bless_IN_OUT_REG, results_HostCallResult.HUH);
22486
22601
  return;
22487
22602
  }
22488
22603
  if (e === partial_state_UpdatePrivilegesError.InvalidServiceId) {
22489
- logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- WHO`;
22604
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- WHO`;
22490
22605
  regs.set(bless_IN_OUT_REG, results_HostCallResult.WHO);
22491
22606
  return;
22492
22607
  }
@@ -22738,7 +22853,9 @@ class New {
22738
22853
  partialState;
22739
22854
  index = host_call_handler_tryAsHostCallIndex(18);
22740
22855
  basicGasCost = gas_tryAsSmallGas(10);
22741
- 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);
22742
22859
  constructor(currentServiceId, partialState) {
22743
22860
  this.currentServiceId = currentServiceId;
22744
22861
  this.partialState = partialState;
@@ -22754,16 +22871,18 @@ class New {
22754
22871
  const allowance = common_tryAsServiceGas(regs.get(10));
22755
22872
  // `f`
22756
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);
22757
22876
  // `c`
22758
22877
  const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
22759
22878
  const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
22760
22879
  // error while reading the memory.
22761
22880
  if (memoryReadResult.isError) {
22762
- logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- PANIC`;
22881
+ logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
22763
22882
  return host_call_handler_PvmExecution.Panic;
22764
22883
  }
22765
- const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage);
22766
- 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)}`;
22767
22886
  if (assignedId.isOk) {
22768
22887
  regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
22769
22888
  return;
@@ -22777,6 +22896,11 @@ class New {
22777
22896
  regs.set(new_IN_OUT_REG, results_HostCallResult.HUH);
22778
22897
  return;
22779
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
+ }
22780
22904
  debug_assertNever(e);
22781
22905
  }
22782
22906
  }
@@ -23900,7 +24024,7 @@ class accumulate_Accumulate {
23900
24024
  }
23901
24025
  const nextServiceId = generateNextServiceId({ serviceId, entropy, timeslot: slot }, this.chainSpec, this.blake2b);
23902
24026
  const partialState = new AccumulateExternalities(this.chainSpec, this.blake2b, new PartiallyUpdatedState(this.state, inputStateUpdate), serviceId, nextServiceId, slot);
23903
- const fetchExternalities = Compatibility.isGreaterOrEqual(GpVersion.V0_7_2)
24027
+ const fetchExternalities = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
23904
24028
  ? FetchExternalities.createForAccumulate({ entropy, transfers, operands }, this.chainSpec)
23905
24029
  : FetchExternalities.createForPre071Accumulate({ entropy, operands }, this.chainSpec);
23906
24030
  const externalities = {
@@ -24015,7 +24139,7 @@ class accumulate_Accumulate {
24015
24139
  const accumulateData = new AccumulateData(reportsToAccumulateInParallel, transfers, autoAccumulateServices);
24016
24140
  const reportsToAccumulateSequentially = reports.subview(i);
24017
24141
  const { gasCost, state: stateAfterParallelAcc, ...rest } = await this.accumulateInParallel(accumulateData, slot, entropy, statistics, stateUpdate);
24018
- const newTransfers = stateAfterParallelAcc.transfers;
24142
+ const newTransfers = stateAfterParallelAcc.takeTransfers();
24019
24143
  assertEmpty(rest);
24020
24144
  // NOTE [ToDr] recursive invocation
24021
24145
  const { accumulatedReports, gasCost: seqGasCost, state, ...seqRest } = await this.accumulateSequentially(tryAsServiceGas(gasLimit - gasCost), reportsToAccumulateSequentially, newTransfers, slot, entropy, statistics, stateAfterParallelAcc, []);
@@ -24051,17 +24175,17 @@ class accumulate_Accumulate {
24051
24175
  statistics.set(serviceId, serviceStatistics);
24052
24176
  currentState = stateUpdate === null ? checkpoint : stateUpdate;
24053
24177
  if (Compatibility.is(GpVersion.V0_7_0) && serviceId === currentManager) {
24054
- const newV = currentState.privilegedServices?.validatorsManager;
24178
+ const newV = currentState.privilegedServices?.delegator;
24055
24179
  if (currentState.privilegedServices !== null && newV !== undefined && serviceIds.includes(newV)) {
24056
- 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+`;
24057
24181
  // Since serviceIds already contains newV, this service gets accumulated twice.
24058
24182
  // To avoid double-counting, we skip stats and gas cost tracking here.
24059
- // We need this accumulation to get the correct `validatorsManager`
24183
+ // We need this accumulation to get the correct `delegator`
24060
24184
  const { stateUpdate } = await this.accumulateSingleService(newV, [], accumulateData.getOperands(newV), accumulateData.getGasCost(newV), slot, entropy, checkpoint);
24061
- const correctV = stateUpdate?.privilegedServices?.validatorsManager ?? this.state.privilegedServices.validatorsManager;
24185
+ const correctV = stateUpdate?.privilegedServices?.delegator ?? this.state.privilegedServices.delegator;
24062
24186
  currentState.privilegedServices = PrivilegedServices.create({
24063
24187
  ...currentState.privilegedServices,
24064
- validatorsManager: correctV,
24188
+ delegator: correctV,
24065
24189
  });
24066
24190
  }
24067
24191
  }