@typeberry/jam 0.1.3-8fd7637 → 0.1.3-b0374a8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3569,8 +3569,9 @@ function parseCurrentVersion(env) {
3569
3569
  }
3570
3570
  }
3571
3571
  function parseCurrentSuite(env) {
3572
- if (env === undefined)
3572
+ if (env === undefined) {
3573
3573
  return undefined;
3574
+ }
3574
3575
  switch (env) {
3575
3576
  case TestSuite.W3F_DAVXY:
3576
3577
  case TestSuite.JAMDUNA:
@@ -4001,10 +4002,12 @@ function deepEqual(actual, expected, { context = [], errorsCollector, ignore = [
4001
4002
  .sort((a, b) => {
4002
4003
  const aKey = `${a.key}`;
4003
4004
  const bKey = `${b.key}`;
4004
- if (aKey < bKey)
4005
+ if (aKey < bKey) {
4005
4006
  return -1;
4006
- if (bKey < aKey)
4007
+ }
4008
+ if (bKey < aKey) {
4007
4009
  return 1;
4010
+ }
4008
4011
  return 0;
4009
4012
  });
4010
4013
  };
@@ -5604,7 +5607,7 @@ class Skipper {
5604
5607
  *
5605
5608
  * Descriptors can be composed to form more complex typings.
5606
5609
  */
5607
- class descriptor_Descriptor {
5610
+ class Descriptor {
5608
5611
  name;
5609
5612
  sizeHint;
5610
5613
  encode;
@@ -5614,11 +5617,11 @@ class descriptor_Descriptor {
5614
5617
  View;
5615
5618
  /** New descriptor with specialized `View`. */
5616
5619
  static withView(name, sizeHint, encode, decode, skip, view) {
5617
- return new descriptor_Descriptor(name, sizeHint, encode, decode, skip, view);
5620
+ return new Descriptor(name, sizeHint, encode, decode, skip, view);
5618
5621
  }
5619
5622
  /** Create a new descriptor without a specialized `View`. */
5620
5623
  static new(name, sizeHint, encode, decode, skip) {
5621
- return new descriptor_Descriptor(name, sizeHint, encode, decode, skip, null);
5624
+ return new Descriptor(name, sizeHint, encode, decode, skip, null);
5622
5625
  }
5623
5626
  constructor(
5624
5627
  /** Descriptive name of the coded data. */
@@ -5655,7 +5658,7 @@ class descriptor_Descriptor {
5655
5658
  }
5656
5659
  /** Return a new descriptor that converts data into some other type. */
5657
5660
  convert(input, output) {
5658
- return new descriptor_Descriptor(this.name, this.sizeHint, (e, elem) => this.encode(e, input(elem)), (d) => output(this.decode(d)), this.skip, this.View);
5661
+ return new Descriptor(this.name, this.sizeHint, (e, elem) => this.encode(e, input(elem)), (d) => output(this.decode(d)), this.skip, this.View);
5659
5662
  }
5660
5663
  /** Safely cast the descriptor value to a opaque type. */
5661
5664
  asOpaque() {
@@ -6353,51 +6356,51 @@ var descriptors_codec;
6353
6356
  return (len) => {
6354
6357
  let ret = cache.get(len);
6355
6358
  if (ret === undefined) {
6356
- ret = descriptor_Descriptor.new(`Bytes<${len}>`, exactHint(len), (e, v) => e.bytes(v), (d) => d.bytes(len), (s) => s.bytes(len));
6359
+ ret = Descriptor.new(`Bytes<${len}>`, exactHint(len), (e, v) => e.bytes(v), (d) => d.bytes(len), (s) => s.bytes(len));
6357
6360
  cache.set(len, ret);
6358
6361
  }
6359
6362
  return ret;
6360
6363
  };
6361
6364
  })();
6362
6365
  /** Variable-length U32. */
6363
- codec.varU32 = descriptor_Descriptor.new("var_u32", { bytes: 4, isExact: false }, (e, v) => e.varU32(v), (d) => d.varU32(), (d) => d.varU32());
6366
+ codec.varU32 = Descriptor.new("var_u32", { bytes: 4, isExact: false }, (e, v) => e.varU32(v), (d) => d.varU32(), (d) => d.varU32());
6364
6367
  /** Variable-length U64. */
6365
- codec.varU64 = descriptor_Descriptor.new("var_u64", { bytes: 8, isExact: false }, (e, v) => e.varU64(v), (d) => d.varU64(), (d) => d.varU64());
6368
+ codec.varU64 = Descriptor.new("var_u64", { bytes: 8, isExact: false }, (e, v) => e.varU64(v), (d) => d.varU64(), (d) => d.varU64());
6366
6369
  /** Unsigned 64-bit number. */
6367
- codec.u64 = descriptor_Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.u64(), (d) => d.u64(), codec.bytes(8));
6370
+ codec.u64 = Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.u64(), (d) => d.u64(), codec.bytes(8));
6368
6371
  /** Unsigned 32-bit number. */
6369
- codec.u32 = descriptor_Descriptor.withView("u32", exactHint(4), (e, v) => e.i32(v), (d) => d.u32(), (d) => d.u32(), codec.bytes(4));
6372
+ codec.u32 = Descriptor.withView("u32", exactHint(4), (e, v) => e.i32(v), (d) => d.u32(), (d) => d.u32(), codec.bytes(4));
6370
6373
  /** Unsigned 24-bit number. */
6371
- codec.u24 = descriptor_Descriptor.withView("u24", exactHint(3), (e, v) => e.i24(v), (d) => d.u24(), (d) => d.u24(), codec.bytes(3));
6374
+ codec.u24 = Descriptor.withView("u24", exactHint(3), (e, v) => e.i24(v), (d) => d.u24(), (d) => d.u24(), codec.bytes(3));
6372
6375
  /** Unsigned 16-bit number. */
6373
- codec.u16 = descriptor_Descriptor.withView("u16", exactHint(2), (e, v) => e.i16(v), (d) => d.u16(), (d) => d.u16(), codec.bytes(2));
6376
+ codec.u16 = Descriptor.withView("u16", exactHint(2), (e, v) => e.i16(v), (d) => d.u16(), (d) => d.u16(), codec.bytes(2));
6374
6377
  /** Unsigned 8-bit number. */
6375
- codec.u8 = descriptor_Descriptor.new("u8", exactHint(1), (e, v) => e.i8(v), (d) => d.u8(), (d) => d.u8());
6378
+ codec.u8 = Descriptor.new("u8", exactHint(1), (e, v) => e.i8(v), (d) => d.u8(), (d) => d.u8());
6376
6379
  /** Signed 64-bit number. */
6377
- codec.i64 = descriptor_Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.i64(), (s) => s.u64(), codec.bytes(8));
6380
+ codec.i64 = Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.i64(), (s) => s.u64(), codec.bytes(8));
6378
6381
  /** Signed 32-bit number. */
6379
- codec.i32 = descriptor_Descriptor.withView("i32", exactHint(4), (e, v) => e.i32(v), (d) => d.i32(), (s) => s.u32(), codec.bytes(4));
6382
+ codec.i32 = Descriptor.withView("i32", exactHint(4), (e, v) => e.i32(v), (d) => d.i32(), (s) => s.u32(), codec.bytes(4));
6380
6383
  /** Signed 24-bit number. */
6381
- codec.i24 = descriptor_Descriptor.withView("i24", exactHint(3), (e, v) => e.i24(v), (d) => d.i24(), (s) => s.u24(), codec.bytes(3));
6384
+ codec.i24 = Descriptor.withView("i24", exactHint(3), (e, v) => e.i24(v), (d) => d.i24(), (s) => s.u24(), codec.bytes(3));
6382
6385
  /** Signed 16-bit number. */
6383
- codec.i16 = descriptor_Descriptor.withView("i16", exactHint(2), (e, v) => e.i16(v), (d) => d.i16(), (s) => s.u16(), codec.bytes(2));
6386
+ codec.i16 = Descriptor.withView("i16", exactHint(2), (e, v) => e.i16(v), (d) => d.i16(), (s) => s.u16(), codec.bytes(2));
6384
6387
  /** Signed 8-bit number. */
6385
- codec.i8 = descriptor_Descriptor.new("i8", exactHint(1), (e, v) => e.i8(v), (d) => d.i8(), (s) => s.u8());
6388
+ codec.i8 = Descriptor.new("i8", exactHint(1), (e, v) => e.i8(v), (d) => d.i8(), (s) => s.u8());
6386
6389
  /** 1-byte boolean value. */
6387
- codec.bool = descriptor_Descriptor.new("bool", exactHint(1), (e, v) => e.bool(v), (d) => d.bool(), (s) => s.bool());
6390
+ codec.bool = Descriptor.new("bool", exactHint(1), (e, v) => e.bool(v), (d) => d.bool(), (s) => s.bool());
6388
6391
  /** Variable-length bytes blob. */
6389
- codec.blob = descriptor_Descriptor.new("BytesBlob", { bytes: TYPICAL_SEQUENCE_LENGTH, isExact: false }, (e, v) => e.bytesBlob(v), (d) => d.bytesBlob(), (s) => s.bytesBlob());
6392
+ codec.blob = Descriptor.new("BytesBlob", { bytes: TYPICAL_SEQUENCE_LENGTH, isExact: false }, (e, v) => e.bytesBlob(v), (d) => d.bytesBlob(), (s) => s.bytesBlob());
6390
6393
  /** String encoded as variable-length bytes blob. */
6391
- 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);
6394
+ codec.string = Descriptor.withView("string", { bytes: TYPICAL_SEQUENCE_LENGTH, isExact: false }, (e, v) => e.bytesBlob(bytes_BytesBlob.blobFrom(new TextEncoder().encode(v))), (d) => new TextDecoder("utf8", { fatal: true }).decode(d.bytesBlob().raw), (s) => s.bytesBlob(), codec.blob);
6392
6395
  /** Variable-length bit vector. */
6393
- codec.bitVecVarLen = descriptor_Descriptor.new("BitVec[?]", { bytes: TYPICAL_SEQUENCE_LENGTH >>> 3, isExact: false }, (e, v) => e.bitVecVarLen(v), (d) => d.bitVecVarLen(), (s) => s.bitVecVarLen());
6396
+ codec.bitVecVarLen = Descriptor.new("BitVec[?]", { bytes: TYPICAL_SEQUENCE_LENGTH >>> 3, isExact: false }, (e, v) => e.bitVecVarLen(v), (d) => d.bitVecVarLen(), (s) => s.bitVecVarLen());
6394
6397
  /** Fixed-length bit vector. */
6395
- codec.bitVecFixLen = (bitLen) => descriptor_Descriptor.new(`BitVec[${bitLen}]`, exactHint(bitLen >>> 3), (e, v) => e.bitVecFixLen(v), (d) => d.bitVecFixLen(bitLen), (s) => s.bitVecFixLen(bitLen));
6398
+ codec.bitVecFixLen = (bitLen) => Descriptor.new(`BitVec[${bitLen}]`, exactHint(bitLen >>> 3), (e, v) => e.bitVecFixLen(v), (d) => d.bitVecFixLen(bitLen), (s) => s.bitVecFixLen(bitLen));
6396
6399
  /** Optionality wrapper for given type. */
6397
6400
  codec.optional = (type) => {
6398
- 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));
6401
+ const self = Descriptor.new(`Optional<${type.name}>`, addSizeHints({ bytes: 1, isExact: false }, type.sizeHint), (e, v) => e.optional(type, v), (d) => d.optional(type), (s) => s.optional(type));
6399
6402
  if (hasUniqueView(type)) {
6400
- return descriptor_Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.optional(type.View));
6403
+ return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.optional(type.View));
6401
6404
  }
6402
6405
  return self;
6403
6406
  };
@@ -6408,7 +6411,7 @@ var descriptors_codec;
6408
6411
  }) => {
6409
6412
  const name = `Sequence<${type.name}>[?]`;
6410
6413
  const typicalLength = options.typicalLength ?? TYPICAL_SEQUENCE_LENGTH;
6411
- return descriptor_Descriptor.withView(name, { bytes: typicalLength * type.sizeHint.bytes, isExact: false }, (e, v) => {
6414
+ return Descriptor.withView(name, { bytes: typicalLength * type.sizeHint.bytes, isExact: false }, (e, v) => {
6412
6415
  validateLength(options, v.length, name);
6413
6416
  e.sequenceVarLen(type, v);
6414
6417
  }, (d) => {
@@ -6422,10 +6425,10 @@ var descriptors_codec;
6422
6425
  }, sequenceViewVarLen(type, options));
6423
6426
  };
6424
6427
  /** Fixed-length sequence of given type. */
6425
- 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 }));
6428
+ codec.sequenceFixLen = (type, len) => Descriptor.withView(`Sequence<${type.name}>[${len}]`, { bytes: len * type.sizeHint.bytes, isExact: type.sizeHint.isExact }, (e, v) => e.sequenceFixLen(type, v), (d) => d.sequenceFixLen(type, len), (s) => s.sequenceFixLen(type, len), sequenceViewFixLen(type, { fixedLength: len }));
6426
6429
  /** Small dictionary codec. */
6427
6430
  codec.dictionary = (key, value, { sortKeys, fixedLength, }) => {
6428
- const self = descriptor_Descriptor.new(`Dictionary<${key.name}, ${value.name}>[${fixedLength ?? "?"}]`, {
6431
+ const self = Descriptor.new(`Dictionary<${key.name}, ${value.name}>[${fixedLength ?? "?"}]`, {
6429
6432
  bytes: fixedLength !== undefined
6430
6433
  ? fixedLength * addSizeHints(key.sizeHint, value.sizeHint).bytes
6431
6434
  : TYPICAL_DICTIONARY_LENGTH * (addSizeHints(key.sizeHint, value.sizeHint).bytes ?? 0),
@@ -6464,13 +6467,13 @@ var descriptors_codec;
6464
6467
  s.sequenceFixLen(value, len);
6465
6468
  });
6466
6469
  if (hasUniqueView(value)) {
6467
- return descriptor_Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.dictionary(key, value.View, { sortKeys, fixedLength }));
6470
+ return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.dictionary(key, value.View, { sortKeys, fixedLength }));
6468
6471
  }
6469
6472
  return self;
6470
6473
  };
6471
6474
  /** Encoding of pair of two values. */
6472
6475
  codec.pair = (a, b) => {
6473
- const self = descriptor_Descriptor.new(`Pair<${a.name}, ${b.name}>`, addSizeHints(a.sizeHint, b.sizeHint), (e, elem) => {
6476
+ const self = Descriptor.new(`Pair<${a.name}, ${b.name}>`, addSizeHints(a.sizeHint, b.sizeHint), (e, elem) => {
6474
6477
  a.encode(e, elem[0]);
6475
6478
  b.encode(e, elem[1]);
6476
6479
  }, (d) => {
@@ -6482,14 +6485,14 @@ var descriptors_codec;
6482
6485
  b.skip(s);
6483
6486
  });
6484
6487
  if (hasUniqueView(a) && hasUniqueView(b)) {
6485
- return descriptor_Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.pair(a.View, b.View));
6488
+ return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.pair(a.View, b.View));
6486
6489
  }
6487
6490
  return self;
6488
6491
  };
6489
6492
  /** Custom encoding / decoding logic. */
6490
- codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => descriptor_Descriptor.new(name, sizeHint, encode, decode, skip);
6493
+ codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
6491
6494
  /** Choose a descriptor depending on the encoding/decoding context. */
6492
- 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);
6495
+ codec.select = ({ name, sizeHint, }, chooser) => Descriptor.withView(name, sizeHint, (e, x) => chooser(e.getContext()).encode(e, x), (d) => chooser(d.getContext()).decode(d), (s) => chooser(s.decoder.getContext()).skip(s), chooser(null).View);
6493
6496
  /**
6494
6497
  * A descriptor for a more complex POJO.
6495
6498
  *
@@ -6526,7 +6529,7 @@ var descriptors_codec;
6526
6529
  };
6527
6530
  const view = objectView(Class, descriptors, sizeHint, skipper);
6528
6531
  // and create the descriptor for the entire class.
6529
- return descriptor_Descriptor.withView(Class.name, sizeHint, (e, t) => {
6532
+ return Descriptor.withView(Class.name, sizeHint, (e, t) => {
6530
6533
  forEachDescriptor(descriptors, (key, descriptor) => {
6531
6534
  const value = t[key];
6532
6535
  descriptor.encode(e, value);
@@ -6577,7 +6580,7 @@ function objectView(Class, descriptors, sizeHint, skipper) {
6577
6580
  });
6578
6581
  }
6579
6582
  });
6580
- return descriptor_Descriptor.new(`View<${Class.name}>`, sizeHint, (e, t) => {
6583
+ return Descriptor.new(`View<${Class.name}>`, sizeHint, (e, t) => {
6581
6584
  const encoded = t.encoded();
6582
6585
  e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
6583
6586
  }, (d) => {
@@ -6596,7 +6599,7 @@ function sequenceViewVarLen(type, options) {
6596
6599
  validateLength(options, length, name);
6597
6600
  return s.sequenceFixLen(type, length);
6598
6601
  };
6599
- return descriptor_Descriptor.new(name, sizeHint, (e, t) => {
6602
+ return Descriptor.new(name, sizeHint, (e, t) => {
6600
6603
  validateLength(options, t.length, name);
6601
6604
  const encoded = t.encoded();
6602
6605
  e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
@@ -6612,7 +6615,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
6612
6615
  const skipper = (s) => s.sequenceFixLen(type, fixedLength);
6613
6616
  const view = type.name !== type.View.name ? `, ${type.View.name}` : "";
6614
6617
  const name = `SeqView<${type.name}${view}>[${fixedLength}]`;
6615
- return descriptor_Descriptor.new(name, sizeHint, (e, t) => {
6618
+ return Descriptor.new(name, sizeHint, (e, t) => {
6616
6619
  const encoded = t.encoded();
6617
6620
  e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
6618
6621
  }, (d) => {
@@ -7628,7 +7631,7 @@ const codecFixedSizeArray = (val, len) => {
7628
7631
  };
7629
7632
  /** Codec for a hash-dictionary. */
7630
7633
  const codecHashDictionary = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH, compare = (a, b) => extractKey(a).compare(extractKey(b)), } = {}) => {
7631
- return descriptor_Descriptor.new(`HashDictionary<${value.name}>[?]`, {
7634
+ return Descriptor.new(`HashDictionary<${value.name}>[?]`, {
7632
7635
  bytes: typicalLength * value.sizeHint.bytes,
7633
7636
  isExact: false,
7634
7637
  }, (e, v) => {
@@ -9595,6 +9598,13 @@ const W_T = 128;
9595
9598
  /** `W_M`: The maximum number of exports in a work-package. */
9596
9599
  const W_X = 3_072;
9597
9600
  // TODO [ToDr] Not sure where these should live yet :(
9601
+ /**
9602
+ * `S`: The minimum public service index.
9603
+ * Services of indices below these may only be created by the Registrar.
9604
+ *
9605
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
9606
+ */
9607
+ const MIN_PUBLIC_SERVICE_INDEX = 2 ** 16;
9598
9608
  /**
9599
9609
  * `J`: The maximum sum of dependency items in a work-report.
9600
9610
  *
@@ -9606,9 +9616,209 @@ const AUTHORIZATION_QUEUE_SIZE = Q;
9606
9616
  /** `O`: Maximal authorization pool size. */
9607
9617
  const MAX_AUTH_POOL_SIZE = O;
9608
9618
 
9619
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
9620
+ const MAX_VALUE = 4294967295;
9621
+ const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
9622
+ const MIN_VALUE = -(2 ** 31);
9623
+ const MAX_SHIFT_U32 = 32;
9624
+ const MAX_SHIFT_U64 = 64n;
9625
+
9626
+ ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
9627
+
9628
+
9629
+
9630
+
9631
+
9632
+
9633
+ /**
9634
+ * `B_S`: The basic minimum balance which all services require.
9635
+ *
9636
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
9637
+ */
9638
+ const BASE_SERVICE_BALANCE = 100n;
9639
+ /**
9640
+ * `B_I`: The additional minimum balance required per item of elective service state.
9641
+ *
9642
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
9643
+ */
9644
+ const ELECTIVE_ITEM_BALANCE = 10n;
9645
+ /**
9646
+ * `B_L`: The additional minimum balance required per octet of elective service state.
9647
+ *
9648
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
9649
+ */
9650
+ const ELECTIVE_BYTE_BALANCE = 1n;
9651
+ const zeroSizeHint = {
9652
+ bytes: 0,
9653
+ isExact: true,
9654
+ };
9655
+ /** 0-byte read, return given default value */
9656
+ const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
9657
+ /** Encode and decode object with leading version number. */
9658
+ const codecWithVersion = (val) => Descriptor.new("withVersion", {
9659
+ bytes: val.sizeHint.bytes + 8,
9660
+ isExact: false,
9661
+ }, (e, v) => {
9662
+ e.varU64(0n);
9663
+ val.encode(e, v);
9664
+ }, (d) => {
9665
+ const version = d.varU64();
9666
+ if (version !== 0n) {
9667
+ throw new Error("Non-zero version is not supported!");
9668
+ }
9669
+ return val.decode(d);
9670
+ }, (s) => {
9671
+ s.varU64();
9672
+ val.skip(s);
9673
+ });
9674
+ /**
9675
+ * Service account details.
9676
+ *
9677
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
9678
+ */
9679
+ class ServiceAccountInfo extends WithDebug {
9680
+ codeHash;
9681
+ balance;
9682
+ accumulateMinGas;
9683
+ onTransferMinGas;
9684
+ storageUtilisationBytes;
9685
+ gratisStorage;
9686
+ storageUtilisationCount;
9687
+ created;
9688
+ lastAccumulation;
9689
+ parentService;
9690
+ static Codec = descriptors_codec.Class(ServiceAccountInfo, {
9691
+ codeHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
9692
+ balance: descriptors_codec.u64,
9693
+ accumulateMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
9694
+ onTransferMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
9695
+ storageUtilisationBytes: descriptors_codec.u64,
9696
+ gratisStorage: descriptors_codec.u64,
9697
+ storageUtilisationCount: descriptors_codec.u32,
9698
+ created: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
9699
+ lastAccumulation: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
9700
+ parentService: descriptors_codec.u32.convert((x) => x, tryAsServiceId),
9701
+ });
9702
+ static create(a) {
9703
+ return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
9704
+ }
9705
+ /**
9706
+ * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
9707
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
9708
+ */
9709
+ static calculateThresholdBalance(items, bytes, gratisStorage) {
9710
+ const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
9711
+ if (storageCost < 0n) {
9712
+ return numbers_tryAsU64(0);
9713
+ }
9714
+ if (storageCost >= 2n ** 64n) {
9715
+ return numbers_tryAsU64(2n ** 64n - 1n);
9716
+ }
9717
+ return numbers_tryAsU64(storageCost);
9718
+ }
9719
+ constructor(
9720
+ /** `a_c`: Hash of the service code. */
9721
+ codeHash,
9722
+ /** `a_b`: Current account balance. */
9723
+ balance,
9724
+ /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
9725
+ accumulateMinGas,
9726
+ /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
9727
+ onTransferMinGas,
9728
+ /** `a_o`: Total number of octets in storage. */
9729
+ storageUtilisationBytes,
9730
+ /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
9731
+ gratisStorage,
9732
+ /** `a_i`: Number of items in storage. */
9733
+ storageUtilisationCount,
9734
+ /** `a_r`: Creation account time slot. */
9735
+ created,
9736
+ /** `a_a`: Most recent accumulation time slot. */
9737
+ lastAccumulation,
9738
+ /** `a_p`: Parent service ID. */
9739
+ parentService) {
9740
+ super();
9741
+ this.codeHash = codeHash;
9742
+ this.balance = balance;
9743
+ this.accumulateMinGas = accumulateMinGas;
9744
+ this.onTransferMinGas = onTransferMinGas;
9745
+ this.storageUtilisationBytes = storageUtilisationBytes;
9746
+ this.gratisStorage = gratisStorage;
9747
+ this.storageUtilisationCount = storageUtilisationCount;
9748
+ this.created = created;
9749
+ this.lastAccumulation = lastAccumulation;
9750
+ this.parentService = parentService;
9751
+ }
9752
+ }
9753
+ class PreimageItem extends WithDebug {
9754
+ hash;
9755
+ blob;
9756
+ static Codec = descriptors_codec.Class(PreimageItem, {
9757
+ hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
9758
+ blob: descriptors_codec.blob,
9759
+ });
9760
+ static create({ hash, blob }) {
9761
+ return new PreimageItem(hash, blob);
9762
+ }
9763
+ constructor(hash, blob) {
9764
+ super();
9765
+ this.hash = hash;
9766
+ this.blob = blob;
9767
+ }
9768
+ }
9769
+ class StorageItem extends WithDebug {
9770
+ key;
9771
+ value;
9772
+ static Codec = descriptors_codec.Class(StorageItem, {
9773
+ key: descriptors_codec.blob.convert((i) => i, (o) => opaque_asOpaqueType(o)),
9774
+ value: descriptors_codec.blob,
9775
+ });
9776
+ static create({ key, value }) {
9777
+ return new StorageItem(key, value);
9778
+ }
9779
+ constructor(key, value) {
9780
+ super();
9781
+ this.key = key;
9782
+ this.value = value;
9783
+ }
9784
+ }
9785
+ const MAX_LOOKUP_HISTORY_SLOTS = 3;
9786
+ function tryAsLookupHistorySlots(items) {
9787
+ const knownSize = sized_array_asKnownSize(items);
9788
+ if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
9789
+ throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
9790
+ }
9791
+ return knownSize;
9792
+ }
9793
+ /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
9794
+ class LookupHistoryItem {
9795
+ hash;
9796
+ length;
9797
+ slots;
9798
+ constructor(hash, length,
9799
+ /**
9800
+ * Preimage availability history as a sequence of time slots.
9801
+ * See PreimageStatus and the following GP fragment for more details.
9802
+ * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
9803
+ slots) {
9804
+ this.hash = hash;
9805
+ this.length = length;
9806
+ this.slots = slots;
9807
+ }
9808
+ static isRequested(item) {
9809
+ if ("slots" in item) {
9810
+ return item.slots.length === 0;
9811
+ }
9812
+ return item.length === 0;
9813
+ }
9814
+ }
9815
+
9609
9816
  ;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
9610
9817
 
9611
9818
 
9819
+
9820
+
9821
+
9612
9822
  /** Dictionary entry of services that auto-accumulate every block. */
9613
9823
  class AutoAccumulate {
9614
9824
  service;
@@ -9630,39 +9840,50 @@ class AutoAccumulate {
9630
9840
  }
9631
9841
  }
9632
9842
  /**
9633
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11da0111da01?v=0.6.7
9843
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
9634
9844
  */
9635
9845
  class PrivilegedServices {
9636
9846
  manager;
9637
- authManager;
9638
- validatorsManager;
9847
+ delegator;
9848
+ registrar;
9849
+ assigners;
9639
9850
  autoAccumulateServices;
9851
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
9640
9852
  static Codec = descriptors_codec.Class(PrivilegedServices, {
9641
9853
  manager: descriptors_codec.u32.asOpaque(),
9642
- authManager: codecPerCore(descriptors_codec.u32.asOpaque()),
9643
- validatorsManager: descriptors_codec.u32.asOpaque(),
9854
+ assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
9855
+ delegator: descriptors_codec.u32.asOpaque(),
9856
+ registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
9857
+ ? descriptors_codec.u32.asOpaque()
9858
+ : ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
9644
9859
  autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
9645
9860
  });
9646
- static create({ manager, authManager, validatorsManager, autoAccumulateServices }) {
9647
- return new PrivilegedServices(manager, authManager, validatorsManager, autoAccumulateServices);
9861
+ static create(a) {
9862
+ return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
9648
9863
  }
9649
9864
  constructor(
9650
9865
  /**
9651
- * `chi_m`: The first, χm, is the index of the manager service which is
9652
- * the service able to effect an alteration of χ from block to block,
9866
+ * `χ_M`: Manages alteration of χ from block to block,
9653
9867
  * as well as bestow services with storage deposit credits.
9654
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11a40111a801?v=0.6.7
9868
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
9655
9869
  */
9656
9870
  manager,
9657
- /** `chi_a`: Manages authorization queue one for each core. */
9658
- authManager,
9659
- /** `chi_v`: Managers validator keys. */
9660
- validatorsManager,
9661
- /** `chi_g`: Dictionary of services that auto-accumulate every block with their gas limit. */
9871
+ /** `χ_V`: Managers validator keys. */
9872
+ delegator,
9873
+ /**
9874
+ * `χ_R`: Manages the creation of services in protected range.
9875
+ *
9876
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
9877
+ */
9878
+ registrar,
9879
+ /** `χ_A`: Manages authorization queue one for each core. */
9880
+ assigners,
9881
+ /** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
9662
9882
  autoAccumulateServices) {
9663
9883
  this.manager = manager;
9664
- this.authManager = authManager;
9665
- this.validatorsManager = validatorsManager;
9884
+ this.delegator = delegator;
9885
+ this.registrar = registrar;
9886
+ this.assigners = assigners;
9666
9887
  this.autoAccumulateServices = autoAccumulateServices;
9667
9888
  }
9668
9889
  }
@@ -9750,7 +9971,7 @@ class RecentBlocks extends WithDebug {
9750
9971
  */
9751
9972
  class RecentBlocksHistory extends WithDebug {
9752
9973
  current;
9753
- static Codec = descriptor_Descriptor.new("RecentBlocksHistory", RecentBlocks.Codec.sizeHint, (encoder, value) => RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
9974
+ static Codec = Descriptor.new("RecentBlocksHistory", RecentBlocks.Codec.sizeHint, (encoder, value) => RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
9754
9975
  const recentBlocks = RecentBlocks.Codec.decode(decoder);
9755
9976
  return RecentBlocksHistory.create(recentBlocks);
9756
9977
  }, (skip) => {
@@ -9947,196 +10168,6 @@ class SafroleData {
9947
10168
  }
9948
10169
  }
9949
10170
 
9950
- ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
9951
-
9952
-
9953
-
9954
-
9955
-
9956
-
9957
- /**
9958
- * `B_S`: The basic minimum balance which all services require.
9959
- *
9960
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
9961
- */
9962
- const BASE_SERVICE_BALANCE = 100n;
9963
- /**
9964
- * `B_I`: The additional minimum balance required per item of elective service state.
9965
- *
9966
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
9967
- */
9968
- const ELECTIVE_ITEM_BALANCE = 10n;
9969
- /**
9970
- * `B_L`: The additional minimum balance required per octet of elective service state.
9971
- *
9972
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
9973
- */
9974
- const ELECTIVE_BYTE_BALANCE = 1n;
9975
- const zeroSizeHint = {
9976
- bytes: 0,
9977
- isExact: true,
9978
- };
9979
- /** 0-byte read, return given default value */
9980
- const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
9981
- /** Encode and decode object with leading version number. */
9982
- const codecWithVersion = (val) => descriptor_Descriptor.new("withVersion", {
9983
- bytes: val.sizeHint.bytes + 8,
9984
- isExact: false,
9985
- }, (e, v) => {
9986
- e.varU64(0n);
9987
- val.encode(e, v);
9988
- }, (d) => {
9989
- const version = d.varU64();
9990
- if (version !== 0n) {
9991
- throw new Error("Non-zero version is not supported!");
9992
- }
9993
- return val.decode(d);
9994
- }, (s) => {
9995
- s.varU64();
9996
- val.skip(s);
9997
- });
9998
- /**
9999
- * Service account details.
10000
- *
10001
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
10002
- */
10003
- class ServiceAccountInfo extends WithDebug {
10004
- codeHash;
10005
- balance;
10006
- accumulateMinGas;
10007
- onTransferMinGas;
10008
- storageUtilisationBytes;
10009
- gratisStorage;
10010
- storageUtilisationCount;
10011
- created;
10012
- lastAccumulation;
10013
- parentService;
10014
- static Codec = descriptors_codec.Class(ServiceAccountInfo, {
10015
- codeHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
10016
- balance: descriptors_codec.u64,
10017
- accumulateMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
10018
- onTransferMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
10019
- storageUtilisationBytes: descriptors_codec.u64,
10020
- gratisStorage: descriptors_codec.u64,
10021
- storageUtilisationCount: descriptors_codec.u32,
10022
- created: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
10023
- lastAccumulation: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
10024
- parentService: descriptors_codec.u32.convert((x) => x, tryAsServiceId),
10025
- });
10026
- static create(a) {
10027
- return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
10028
- }
10029
- /**
10030
- * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
10031
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
10032
- */
10033
- static calculateThresholdBalance(items, bytes, gratisStorage) {
10034
- const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
10035
- if (storageCost < 0n) {
10036
- return numbers_tryAsU64(0);
10037
- }
10038
- if (storageCost >= 2n ** 64n) {
10039
- return numbers_tryAsU64(2n ** 64n - 1n);
10040
- }
10041
- return numbers_tryAsU64(storageCost);
10042
- }
10043
- constructor(
10044
- /** `a_c`: Hash of the service code. */
10045
- codeHash,
10046
- /** `a_b`: Current account balance. */
10047
- balance,
10048
- /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
10049
- accumulateMinGas,
10050
- /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
10051
- onTransferMinGas,
10052
- /** `a_o`: Total number of octets in storage. */
10053
- storageUtilisationBytes,
10054
- /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
10055
- gratisStorage,
10056
- /** `a_i`: Number of items in storage. */
10057
- storageUtilisationCount,
10058
- /** `a_r`: Creation account time slot. */
10059
- created,
10060
- /** `a_a`: Most recent accumulation time slot. */
10061
- lastAccumulation,
10062
- /** `a_p`: Parent service ID. */
10063
- parentService) {
10064
- super();
10065
- this.codeHash = codeHash;
10066
- this.balance = balance;
10067
- this.accumulateMinGas = accumulateMinGas;
10068
- this.onTransferMinGas = onTransferMinGas;
10069
- this.storageUtilisationBytes = storageUtilisationBytes;
10070
- this.gratisStorage = gratisStorage;
10071
- this.storageUtilisationCount = storageUtilisationCount;
10072
- this.created = created;
10073
- this.lastAccumulation = lastAccumulation;
10074
- this.parentService = parentService;
10075
- }
10076
- }
10077
- class PreimageItem extends WithDebug {
10078
- hash;
10079
- blob;
10080
- static Codec = descriptors_codec.Class(PreimageItem, {
10081
- hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
10082
- blob: descriptors_codec.blob,
10083
- });
10084
- static create({ hash, blob }) {
10085
- return new PreimageItem(hash, blob);
10086
- }
10087
- constructor(hash, blob) {
10088
- super();
10089
- this.hash = hash;
10090
- this.blob = blob;
10091
- }
10092
- }
10093
- class StorageItem extends WithDebug {
10094
- key;
10095
- value;
10096
- static Codec = descriptors_codec.Class(StorageItem, {
10097
- key: descriptors_codec.blob.convert((i) => i, (o) => opaque_asOpaqueType(o)),
10098
- value: descriptors_codec.blob,
10099
- });
10100
- static create({ key, value }) {
10101
- return new StorageItem(key, value);
10102
- }
10103
- constructor(key, value) {
10104
- super();
10105
- this.key = key;
10106
- this.value = value;
10107
- }
10108
- }
10109
- const MAX_LOOKUP_HISTORY_SLOTS = 3;
10110
- function tryAsLookupHistorySlots(items) {
10111
- const knownSize = sized_array_asKnownSize(items);
10112
- if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
10113
- throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
10114
- }
10115
- return knownSize;
10116
- }
10117
- /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
10118
- class LookupHistoryItem {
10119
- hash;
10120
- length;
10121
- slots;
10122
- constructor(hash, length,
10123
- /**
10124
- * Preimage availability history as a sequence of time slots.
10125
- * See PreimageStatus and the following GP fragment for more details.
10126
- * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
10127
- slots) {
10128
- this.hash = hash;
10129
- this.length = length;
10130
- this.slots = slots;
10131
- }
10132
- static isRequested(item) {
10133
- if ("slots" in item) {
10134
- return item.slots.length === 0;
10135
- }
10136
- return item.length === 0;
10137
- }
10138
- }
10139
-
10140
10171
  ;// CONCATENATED MODULE: ./packages/jam/state/state.ts
10141
10172
  /**
10142
10173
  * In addition to the entropy accumulator η_0, we retain
@@ -10573,6 +10604,7 @@ class StatisticsData {
10573
10604
 
10574
10605
 
10575
10606
 
10607
+
10576
10608
 
10577
10609
 
10578
10610
  var in_memory_state_UpdateError;
@@ -10976,8 +11008,9 @@ class InMemoryState extends WithDebug {
10976
11008
  epochRoot: bytes_Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
10977
11009
  privilegedServices: PrivilegedServices.create({
10978
11010
  manager: tryAsServiceId(0),
10979
- authManager: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
10980
- validatorsManager: tryAsServiceId(0),
11011
+ assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
11012
+ delegator: tryAsServiceId(0),
11013
+ registrar: tryAsServiceId(MAX_VALUE),
10981
11014
  autoAccumulateServices: [],
10982
11015
  }),
10983
11016
  accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
@@ -11213,7 +11246,7 @@ var serialize;
11213
11246
  * determine the boundary of the bytes, so it can only be used
11214
11247
  * as the last element of the codec and can't be used in sequences!
11215
11248
  */
11216
- const 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()));
11249
+ const dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }, (e, v) => e.bytes(bytes_Bytes.fromBlob(v.raw, v.raw.length)), (d) => bytes_BytesBlob.blobFrom(d.bytes(d.source.length - d.bytesRead()).raw), (s) => s.bytes(s.decoder.source.length - s.decoder.bytesRead()));
11217
11250
 
11218
11251
  ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
11219
11252
 
@@ -12524,7 +12557,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
12524
12557
  }
12525
12558
  return Ordering.Equal;
12526
12559
  }, } = {}) => {
12527
- return descriptor_Descriptor.new(`Map<${value.name}>[?]`, {
12560
+ return Descriptor.new(`Map<${value.name}>[?]`, {
12528
12561
  bytes: typicalLength * value.sizeHint.bytes,
12529
12562
  isExact: false,
12530
12563
  }, (e, v) => {
@@ -15113,7 +15146,7 @@ class AccumulationStateUpdate {
15113
15146
  if (from.privilegedServices !== null) {
15114
15147
  update.privilegedServices = PrivilegedServices.create({
15115
15148
  ...from.privilegedServices,
15116
- authManager: sized_array_asKnownSize([...from.privilegedServices.authManager]),
15149
+ assigners: sized_array_asKnownSize([...from.privilegedServices.assigners]),
15117
15150
  });
15118
15151
  }
15119
15152
  return update;
@@ -17252,13 +17285,6 @@ class BitOps {
17252
17285
  }
17253
17286
  }
17254
17287
 
17255
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
17256
- const MAX_VALUE = 4294967295;
17257
- const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
17258
- const MIN_VALUE = -(2 ** 31);
17259
- const MAX_SHIFT_U32 = 32;
17260
- const MAX_SHIFT_U64 = 64n;
17261
-
17262
17288
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-utils.ts
17263
17289
 
17264
17290
 
@@ -19288,6 +19314,8 @@ var NewServiceError;
19288
19314
  NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
19289
19315
  /** Service is not privileged to set gratis storage. */
19290
19316
  NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
19317
+ /** Registrar attempting to create a service with already existing id. */
19318
+ NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
19291
19319
  })(NewServiceError || (NewServiceError = {}));
19292
19320
  var UpdatePrivilegesError;
19293
19321
  (function (UpdatePrivilegesError) {
@@ -19424,7 +19452,7 @@ const HostCallResult = {
19424
19452
  OOB: numbers_tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
19425
19453
  /** Index unknown. */
19426
19454
  WHO: numbers_tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
19427
- /** Storage full. */
19455
+ /** Storage full or resource already allocated. */
19428
19456
  FULL: numbers_tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
19429
19457
  /** Core index unknown. */
19430
19458
  CORE: numbers_tryAsU64(0xfffffffffffffffan), // 2**64 - 6
@@ -19432,7 +19460,7 @@ const HostCallResult = {
19432
19460
  CASH: numbers_tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
19433
19461
  /** Gas limit too low. */
19434
19462
  LOW: numbers_tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
19435
- /** The item is already solicited or cannot be forgotten. */
19463
+ /** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
19436
19464
  HUH: numbers_tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
19437
19465
  /** The return value indicating general success. */
19438
19466
  OK: numbers_tryAsU64(0n),
@@ -19486,6 +19514,7 @@ function clampU64ToU32(value) {
19486
19514
 
19487
19515
 
19488
19516
 
19517
+
19489
19518
  /**
19490
19519
  * Number of storage items required for ejection of the service.
19491
19520
  *
@@ -19577,10 +19606,13 @@ class AccumulateExternalities {
19577
19606
  const isExpired = status.data[1] < t - this.chainSpec.preimageExpungePeriod;
19578
19607
  return [isExpired, isExpired ? "" : "not expired"];
19579
19608
  }
19580
- /** `check`: https://graypaper.fluffylabs.dev/#/9a08063/303f02303f02?v=0.6.6 */
19609
+ /** `check`: https://graypaper.fluffylabs.dev/#/ab2cdbd/30c60330c603?v=0.7.2 */
19581
19610
  getNextAvailableServiceId(serviceId) {
19582
19611
  let currentServiceId = serviceId;
19583
- const mod = 2 ** 32 - 2 ** 9;
19612
+ const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
19613
+ ? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
19614
+ : 2 ** 32 - 2 ** 9;
19615
+ const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
19584
19616
  for (;;) {
19585
19617
  const service = this.getServiceInfo(currentServiceId);
19586
19618
  // we found an empty id
@@ -19588,7 +19620,7 @@ class AccumulateExternalities {
19588
19620
  return currentServiceId;
19589
19621
  }
19590
19622
  // keep trying
19591
- currentServiceId = tryAsServiceId(((currentServiceId - 2 ** 8 + 1 + mod) % mod) + 2 ** 8);
19623
+ currentServiceId = tryAsServiceId(((currentServiceId - offset + 1 + mod) % mod) + offset);
19592
19624
  }
19593
19625
  }
19594
19626
  checkPreimageStatus(hash, length) {
@@ -19745,8 +19777,7 @@ class AccumulateExternalities {
19745
19777
  }));
19746
19778
  return result_Result.ok(result_OK);
19747
19779
  }
19748
- newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage) {
19749
- const newServiceId = this.nextNewServiceId;
19780
+ newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage, wantedServiceId) {
19750
19781
  // calculate the threshold. Storage is empty, one preimage requested.
19751
19782
  // https://graypaper.fluffylabs.dev/#/7e6ff6a/115901115901?v=0.6.7
19752
19783
  const items = numbers_tryAsU32(2 * 1 + 0);
@@ -19767,30 +19798,59 @@ class AccumulateExternalities {
19767
19798
  if (balanceLeftForCurrent < thresholdForCurrent || bytes.overflow) {
19768
19799
  return result_Result.error(NewServiceError.InsufficientFunds);
19769
19800
  }
19801
+ // `a`: https://graypaper.fluffylabs.dev/#/ab2cdbd/366b02366d02?v=0.7.2
19802
+ const newAccount = ServiceAccountInfo.create({
19803
+ codeHash,
19804
+ balance: thresholdForNew,
19805
+ accumulateMinGas,
19806
+ onTransferMinGas,
19807
+ storageUtilisationBytes: bytes.value,
19808
+ storageUtilisationCount: items,
19809
+ gratisStorage,
19810
+ created: this.currentTimeslot,
19811
+ lastAccumulation: common_tryAsTimeSlot(0),
19812
+ parentService: this.currentServiceId,
19813
+ });
19814
+ const newLookupItem = new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([]));
19815
+ // `s`: https://graypaper.fluffylabs.dev/#/ab2cdbd/361003361003?v=0.7.2
19816
+ const updatedCurrentAccount = ServiceAccountInfo.create({
19817
+ ...currentService,
19818
+ balance: numbers_tryAsU64(balanceLeftForCurrent),
19819
+ });
19820
+ if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
19821
+ if (wantedServiceId < MIN_PUBLIC_SERVICE_INDEX &&
19822
+ this.currentServiceId === this.updatedState.getPrivilegedServices().registrar) {
19823
+ // NOTE: It's safe to cast to `Number` here, bcs here service ID cannot be bigger than 2**16
19824
+ const newServiceId = tryAsServiceId(Number(wantedServiceId));
19825
+ if (this.getServiceInfo(newServiceId) !== null) {
19826
+ return result_Result.error(NewServiceError.RegistrarServiceIdAlreadyTaken);
19827
+ }
19828
+ // add the new service with selected ID
19829
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36be0336c003?v=0.7.2
19830
+ this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
19831
+ serviceId: newServiceId,
19832
+ serviceInfo: newAccount,
19833
+ lookupHistory: newLookupItem,
19834
+ }));
19835
+ // update the balance of current service
19836
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36c20336c403?v=0.7.2
19837
+ this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
19838
+ return result_Result.ok(newServiceId);
19839
+ }
19840
+ // NOTE: in case the service is not a registrar or the requested serviceId is out of range,
19841
+ // we completely ignore the `wantedServiceId` and assign a random one
19842
+ }
19843
+ const newServiceId = this.nextNewServiceId;
19770
19844
  // add the new service
19771
- // https://graypaper.fluffylabs.dev/#/7e6ff6a/36cb0236cb02?v=0.6.7
19845
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36e70336e903?v=0.7.2
19772
19846
  this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
19773
19847
  serviceId: newServiceId,
19774
- serviceInfo: ServiceAccountInfo.create({
19775
- codeHash,
19776
- balance: thresholdForNew,
19777
- accumulateMinGas,
19778
- onTransferMinGas,
19779
- storageUtilisationBytes: bytes.value,
19780
- storageUtilisationCount: items,
19781
- gratisStorage,
19782
- created: this.currentTimeslot,
19783
- lastAccumulation: common_tryAsTimeSlot(0),
19784
- parentService: this.currentServiceId,
19785
- }),
19786
- lookupHistory: new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([])),
19848
+ serviceInfo: newAccount,
19849
+ lookupHistory: newLookupItem,
19787
19850
  }));
19788
19851
  // update the balance of current service
19789
- // https://graypaper.fluffylabs.dev/#/7e6ff6a/364d03364d03?v=0.6.7
19790
- this.updatedState.updateServiceInfo(this.currentServiceId, ServiceAccountInfo.create({
19791
- ...currentService,
19792
- balance: numbers_tryAsU64(balanceLeftForCurrent),
19793
- }));
19852
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36ec0336ee03?v=0.7.2
19853
+ this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
19794
19854
  // update the next service id we are going to create next
19795
19855
  // https://graypaper.fluffylabs.dev/#/7e6ff6a/36a70336a703?v=0.6.7
19796
19856
  this.nextNewServiceId = this.getNextAvailableServiceId(bumpServiceId(newServiceId));
@@ -19808,9 +19868,9 @@ class AccumulateExternalities {
19808
19868
  }
19809
19869
  updateValidatorsData(validatorsData) {
19810
19870
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/362802362d02?v=0.6.7 */
19811
- const validatorsManager = this.updatedState.getPrivilegedServices().validatorsManager;
19812
- if (validatorsManager !== this.currentServiceId) {
19813
- accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${validatorsManager}) and cannot update validators data. Ignoring`;
19871
+ const currentDelegator = this.updatedState.getPrivilegedServices().delegator;
19872
+ if (currentDelegator !== this.currentServiceId) {
19873
+ accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${currentDelegator}) and cannot update validators data. Ignoring`;
19814
19874
  return result_Result.error(UnprivilegedError);
19815
19875
  }
19816
19876
  this.updatedState.stateUpdate.validatorsData = validatorsData;
@@ -19820,34 +19880,38 @@ class AccumulateExternalities {
19820
19880
  /** https://graypaper.fluffylabs.dev/#/9a08063/362202362202?v=0.6.6 */
19821
19881
  this.checkpointedState = AccumulationStateUpdate.copyFrom(this.updatedState.stateUpdate);
19822
19882
  }
19823
- updateAuthorizationQueue(coreIndex, authQueue, authManager) {
19883
+ updateAuthorizationQueue(coreIndex, authQueue, assigners) {
19824
19884
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/36a40136a401?v=0.6.7 */
19825
19885
  // NOTE `coreIndex` is already verified in the HC, so this is infallible.
19826
- const currentAuthManager = this.updatedState.getPrivilegedServices().authManager[coreIndex];
19827
- if (currentAuthManager !== this.currentServiceId) {
19828
- 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`;
19886
+ const currentAssigners = this.updatedState.getPrivilegedServices().assigners[coreIndex];
19887
+ if (currentAssigners !== this.currentServiceId) {
19888
+ accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not an auth manager of core ${coreIndex} (expected: ${currentAssigners}) and cannot update authorization queue.`;
19829
19889
  return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
19830
19890
  }
19831
- if (authManager === null && Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
19832
- accumulate_externalities_logger.trace `The new auth manager is not a valid service id. Ignoring`;
19891
+ if (assigners === null && Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
19892
+ accumulate_externalities_logger.trace `The new auth manager is not a valid service id.`;
19833
19893
  return result_Result.error(UpdatePrivilegesError.InvalidServiceId);
19834
19894
  }
19835
19895
  this.updatedState.stateUpdate.authorizationQueues.set(coreIndex, authQueue);
19836
19896
  return result_Result.ok(result_OK);
19837
19897
  }
19838
- updatePrivilegedServices(manager, authorizers, validatorsManager, autoAccumulate) {
19898
+ updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate) {
19839
19899
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/36d90036de00?v=0.6.7 */
19840
19900
  const currentManager = this.updatedState.getPrivilegedServices().manager;
19841
19901
  if (currentManager !== this.currentServiceId) {
19842
19902
  return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
19843
19903
  }
19844
- if (manager === null || validatorsManager === null) {
19845
- return result_Result.error(UpdatePrivilegesError.InvalidServiceId);
19904
+ if (manager === null || delegator === null) {
19905
+ return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Either manager or delegator is not valid service id.");
19906
+ }
19907
+ if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && registrar === null) {
19908
+ return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Register manager is not valid service id.");
19846
19909
  }
19847
19910
  this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
19848
19911
  manager,
19849
- authManager: authorizers,
19850
- validatorsManager,
19912
+ assigners: authorizers,
19913
+ delegator,
19914
+ registrar: registrar ?? tryAsServiceId(0), // introduced in 0.7.1
19851
19915
  autoAccumulateServices: autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit })),
19852
19916
  });
19853
19917
  return result_Result.ok(result_OK);
@@ -19963,8 +20027,11 @@ class AccumulateExternalities {
19963
20027
  }
19964
20028
  }
19965
20029
  function bumpServiceId(serviceId) {
19966
- const mod = 2 ** 32 - 2 ** 9;
19967
- return tryAsServiceId(2 ** 8 + ((serviceId - 2 ** 8 + 42 + mod) % mod));
20030
+ const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
20031
+ ? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
20032
+ : 2 ** 32 - 2 ** 9;
20033
+ const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
20034
+ return tryAsServiceId(offset + ((serviceId - offset + 42 + mod) % mod));
19968
20035
  }
19969
20036
 
19970
20037
  ;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-state.ts
@@ -20620,6 +20687,8 @@ class AccumulateData {
20620
20687
 
20621
20688
 
20622
20689
 
20690
+
20691
+
20623
20692
  /**
20624
20693
  * A function that removes duplicates but does not change order - it keeps the first occurence.
20625
20694
  */
@@ -20649,7 +20718,7 @@ const NEXT_ID_CODEC = descriptors_codec.object({
20649
20718
  *
20650
20719
  * Please not that it does not call `check` function!
20651
20720
  *
20652
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/2f4c022f4c02?v=0.6.7
20721
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/2fa9042fc304?v=0.7.2
20653
20722
  */
20654
20723
  function generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blake2b) {
20655
20724
  const encoded = encoder_Encoder.encodeObject(NEXT_ID_CODEC, {
@@ -20659,7 +20728,11 @@ function generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blak
20659
20728
  }, chainSpec);
20660
20729
  const result = blake2b.hashBytes(encoded).raw.subarray(0, 4);
20661
20730
  const number = leBytesAsU32(result) >>> 0;
20662
- return tryAsServiceId((number % (2 ** 32 - 2 ** 9)) + 2 ** 8);
20731
+ const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
20732
+ ? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
20733
+ : 2 ** 32 - 2 ** 9;
20734
+ const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
20735
+ return tryAsServiceId((number % mod) + offset);
20663
20736
  }
20664
20737
 
20665
20738
  ;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-queue.ts
@@ -21071,7 +21144,7 @@ class Assign {
21071
21144
  // o
21072
21145
  const authorizationQueueStart = regs.get(8);
21073
21146
  // a
21074
- const authManager = getServiceId(regs.get(9));
21147
+ const assigners = getServiceId(regs.get(9));
21075
21148
  const res = safeAllocUint8Array(hash_HASH_SIZE * AUTHORIZATION_QUEUE_SIZE);
21076
21149
  const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
21077
21150
  // error while reading the memory.
@@ -21088,7 +21161,7 @@ class Assign {
21088
21161
  const decoder = decoder_Decoder.fromBlob(res);
21089
21162
  const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE), AUTHORIZATION_QUEUE_SIZE);
21090
21163
  const fixedSizeAuthQueue = FixedSizeArray.new(authQueue, AUTHORIZATION_QUEUE_SIZE);
21091
- const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, authManager);
21164
+ const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
21092
21165
  if (result.isOk) {
21093
21166
  regs.set(IN_OUT_REG, HostCallResult.OK);
21094
21167
  logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
@@ -21137,7 +21210,9 @@ class Bless {
21137
21210
  chainSpec;
21138
21211
  index = host_call_handler_tryAsHostCallIndex(14);
21139
21212
  basicGasCost = gas_tryAsSmallGas(10);
21140
- tracedRegisters = traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11);
21213
+ tracedRegisters = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
21214
+ ? traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11, 12)
21215
+ : traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11);
21141
21216
  constructor(currentServiceId, partialState, chainSpec) {
21142
21217
  this.currentServiceId = currentServiceId;
21143
21218
  this.partialState = partialState;
@@ -21147,14 +21222,17 @@ class Bless {
21147
21222
  // `m`: manager service (can change privileged services)
21148
21223
  const manager = getServiceId(regs.get(bless_IN_OUT_REG));
21149
21224
  // `a`: manages authorization queue
21150
- // NOTE It can be either ServiceId (pre GP 067) or memory index (GP ^067)
21151
21225
  const authorization = regs.get(8);
21152
21226
  // `v`: manages validator keys
21153
- const validator = getServiceId(regs.get(9));
21227
+ const delegator = getServiceId(regs.get(9));
21228
+ // `r`: manages creation of new services with id within protected range
21229
+ const registrar = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
21230
+ ? getServiceId(regs.get(10))
21231
+ : tryAsServiceId(2 ** 32 - 1);
21154
21232
  // `o`: memory offset
21155
- const sourceStart = regs.get(10);
21233
+ const sourceStart = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? regs.get(11) : regs.get(10);
21156
21234
  // `n`: number of items in the auto-accumulate dictionary
21157
- const numberOfItems = regs.get(11);
21235
+ const numberOfItems = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? regs.get(12) : regs.get(11);
21158
21236
  /*
21159
21237
  * `z`: array of key-value pairs serviceId -> gas that auto-accumulate every block
21160
21238
  * https://graypaper.fluffylabs.dev/#/7e6ff6a/368100368100?v=0.6.7
@@ -21168,7 +21246,7 @@ class Bless {
21168
21246
  decoder.resetTo(0);
21169
21247
  const memoryReadResult = memory.loadInto(result, memIndex);
21170
21248
  if (memoryReadResult.isError) {
21171
- logger_logger.trace `BLESS(${manager}, ${validator}) <- PANIC`;
21249
+ logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}) <- PANIC`;
21172
21250
  return PvmExecution.Panic;
21173
21251
  }
21174
21252
  const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
@@ -21181,24 +21259,25 @@ class Bless {
21181
21259
  const authorizersDecoder = decoder_Decoder.fromBlob(res);
21182
21260
  const memoryReadResult = memory.loadInto(res, authorization);
21183
21261
  if (memoryReadResult.isError) {
21184
- logger_logger.trace `BLESS(${manager}, ${validator}, ${autoAccumulateEntries}) <- PANIC`;
21262
+ logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- PANIC`;
21185
21263
  return PvmExecution.Panic;
21186
21264
  }
21265
+ // `a`
21187
21266
  const authorizers = tryAsPerCore(authorizersDecoder.sequenceFixLen(descriptors_codec.u32.asOpaque(), this.chainSpec.coresCount), this.chainSpec);
21188
- const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, validator, autoAccumulateEntries);
21267
+ const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulateEntries);
21189
21268
  if (updateResult.isOk) {
21190
- logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- OK`;
21269
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- OK`;
21191
21270
  regs.set(bless_IN_OUT_REG, HostCallResult.OK);
21192
21271
  return;
21193
21272
  }
21194
21273
  const e = updateResult.error;
21195
21274
  if (e === UpdatePrivilegesError.UnprivilegedService) {
21196
- logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- HUH`;
21275
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- HUH`;
21197
21276
  regs.set(bless_IN_OUT_REG, HostCallResult.HUH);
21198
21277
  return;
21199
21278
  }
21200
21279
  if (e === UpdatePrivilegesError.InvalidServiceId) {
21201
- logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- WHO`;
21280
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- WHO`;
21202
21281
  regs.set(bless_IN_OUT_REG, HostCallResult.WHO);
21203
21282
  return;
21204
21283
  }
@@ -21450,7 +21529,9 @@ class New {
21450
21529
  partialState;
21451
21530
  index = host_call_handler_tryAsHostCallIndex(18);
21452
21531
  basicGasCost = gas_tryAsSmallGas(10);
21453
- tracedRegisters = traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11);
21532
+ tracedRegisters = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
21533
+ ? traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11, 12)
21534
+ : traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11);
21454
21535
  constructor(currentServiceId, partialState) {
21455
21536
  this.currentServiceId = currentServiceId;
21456
21537
  this.partialState = partialState;
@@ -21466,16 +21547,18 @@ class New {
21466
21547
  const allowance = tryAsServiceGas(regs.get(10));
21467
21548
  // `f`
21468
21549
  const gratisStorage = regs.get(11);
21550
+ // `i`: requested service id. Ignored if current service is not registrar or value is bigger than `S`.
21551
+ const requestedServiceId = regs.get(12);
21469
21552
  // `c`
21470
21553
  const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
21471
21554
  const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
21472
21555
  // error while reading the memory.
21473
21556
  if (memoryReadResult.isError) {
21474
- logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- PANIC`;
21557
+ logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
21475
21558
  return PvmExecution.Panic;
21476
21559
  }
21477
- const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage);
21478
- logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- ${resultToString(assignedId)}`;
21560
+ const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage, requestedServiceId);
21561
+ logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${resultToString(assignedId)}`;
21479
21562
  if (assignedId.isOk) {
21480
21563
  regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
21481
21564
  return;
@@ -21489,6 +21572,11 @@ class New {
21489
21572
  regs.set(new_IN_OUT_REG, HostCallResult.HUH);
21490
21573
  return;
21491
21574
  }
21575
+ // Post 0.7.1
21576
+ if (e === NewServiceError.RegistrarServiceIdAlreadyTaken) {
21577
+ regs.set(new_IN_OUT_REG, HostCallResult.FULL);
21578
+ return;
21579
+ }
21492
21580
  debug_assertNever(e);
21493
21581
  }
21494
21582
  }
@@ -22897,17 +22985,17 @@ class Accumulate {
22897
22985
  statistics.set(serviceId, serviceStatistics);
22898
22986
  currentState = stateUpdate === null ? checkpoint : stateUpdate;
22899
22987
  if (Compatibility.is(GpVersion.V0_7_0) && serviceId === currentManager) {
22900
- const newV = currentState.privilegedServices?.validatorsManager;
22988
+ const newV = currentState.privilegedServices?.delegator;
22901
22989
  if (currentState.privilegedServices !== null && newV !== undefined && serviceIds.includes(newV)) {
22902
- 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+`;
22990
+ accumulate_logger.info `Entering completely incorrect code that probably reverts delegator change. This is valid in 0.7.0 only and incorrect in 0.7.1+`;
22903
22991
  // Since serviceIds already contains newV, this service gets accumulated twice.
22904
22992
  // To avoid double-counting, we skip stats and gas cost tracking here.
22905
- // We need this accumulation to get the correct `validatorsManager`
22993
+ // We need this accumulation to get the correct `delegator`
22906
22994
  const { stateUpdate } = await this.accumulateSingleService(newV, [], accumulateData.getOperands(newV), accumulateData.getGasCost(newV), slot, entropy, checkpoint);
22907
- const correctV = stateUpdate?.privilegedServices?.validatorsManager ?? this.state.privilegedServices.validatorsManager;
22995
+ const correctV = stateUpdate?.privilegedServices?.delegator ?? this.state.privilegedServices.delegator;
22908
22996
  currentState.privilegedServices = PrivilegedServices.create({
22909
22997
  ...currentState.privilegedServices,
22910
- validatorsManager: correctV,
22998
+ delegator: correctV,
22911
22999
  });
22912
23000
  }
22913
23001
  }