@typeberry/jam 0.1.3-c2321fb → 0.1.3-ca63b35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -24332,8 +24332,9 @@ function parseCurrentVersion(env) {
24332
24332
  }
24333
24333
  }
24334
24334
  function parseCurrentSuite(env) {
24335
- if (env === undefined)
24335
+ if (env === undefined) {
24336
24336
  return undefined;
24337
+ }
24337
24338
  switch (env) {
24338
24339
  case TestSuite.W3F_DAVXY:
24339
24340
  case TestSuite.JAMDUNA:
@@ -24764,10 +24765,12 @@ function deepEqual(actual, expected, { context = [], errorsCollector, ignore = [
24764
24765
  .sort((a, b) => {
24765
24766
  const aKey = `${a.key}`;
24766
24767
  const bKey = `${b.key}`;
24767
- if (aKey < bKey)
24768
+ if (aKey < bKey) {
24768
24769
  return -1;
24769
- if (bKey < aKey)
24770
+ }
24771
+ if (bKey < aKey) {
24770
24772
  return 1;
24773
+ }
24771
24774
  return 0;
24772
24775
  });
24773
24776
  };
@@ -25779,7 +25782,7 @@ class Skipper {
25779
25782
  *
25780
25783
  * Descriptors can be composed to form more complex typings.
25781
25784
  */
25782
- class descriptor_Descriptor {
25785
+ class Descriptor {
25783
25786
  name;
25784
25787
  sizeHint;
25785
25788
  encode;
@@ -25789,11 +25792,11 @@ class descriptor_Descriptor {
25789
25792
  View;
25790
25793
  /** New descriptor with specialized `View`. */
25791
25794
  static withView(name, sizeHint, encode, decode, skip, view) {
25792
- return new descriptor_Descriptor(name, sizeHint, encode, decode, skip, view);
25795
+ return new Descriptor(name, sizeHint, encode, decode, skip, view);
25793
25796
  }
25794
25797
  /** Create a new descriptor without a specialized `View`. */
25795
25798
  static new(name, sizeHint, encode, decode, skip) {
25796
- return new descriptor_Descriptor(name, sizeHint, encode, decode, skip, null);
25799
+ return new Descriptor(name, sizeHint, encode, decode, skip, null);
25797
25800
  }
25798
25801
  constructor(
25799
25802
  /** Descriptive name of the coded data. */
@@ -25830,7 +25833,7 @@ class descriptor_Descriptor {
25830
25833
  }
25831
25834
  /** Return a new descriptor that converts data into some other type. */
25832
25835
  convert(input, output) {
25833
- return new descriptor_Descriptor(this.name, this.sizeHint, (e, elem) => this.encode(e, input(elem)), (d) => output(this.decode(d)), this.skip, this.View);
25836
+ return new Descriptor(this.name, this.sizeHint, (e, elem) => this.encode(e, input(elem)), (d) => output(this.decode(d)), this.skip, this.View);
25834
25837
  }
25835
25838
  /** Safely cast the descriptor value to a opaque type. */
25836
25839
  asOpaque() {
@@ -26528,51 +26531,51 @@ var descriptors_codec;
26528
26531
  return (len) => {
26529
26532
  let ret = cache.get(len);
26530
26533
  if (ret === undefined) {
26531
- ret = descriptor_Descriptor.new(`Bytes<${len}>`, exactHint(len), (e, v) => e.bytes(v), (d) => d.bytes(len), (s) => s.bytes(len));
26534
+ ret = Descriptor.new(`Bytes<${len}>`, exactHint(len), (e, v) => e.bytes(v), (d) => d.bytes(len), (s) => s.bytes(len));
26532
26535
  cache.set(len, ret);
26533
26536
  }
26534
26537
  return ret;
26535
26538
  };
26536
26539
  })();
26537
26540
  /** Variable-length U32. */
26538
- codec.varU32 = descriptor_Descriptor.new("var_u32", { bytes: 4, isExact: false }, (e, v) => e.varU32(v), (d) => d.varU32(), (d) => d.varU32());
26541
+ codec.varU32 = Descriptor.new("var_u32", { bytes: 4, isExact: false }, (e, v) => e.varU32(v), (d) => d.varU32(), (d) => d.varU32());
26539
26542
  /** Variable-length U64. */
26540
- codec.varU64 = descriptor_Descriptor.new("var_u64", { bytes: 8, isExact: false }, (e, v) => e.varU64(v), (d) => d.varU64(), (d) => d.varU64());
26543
+ codec.varU64 = Descriptor.new("var_u64", { bytes: 8, isExact: false }, (e, v) => e.varU64(v), (d) => d.varU64(), (d) => d.varU64());
26541
26544
  /** Unsigned 64-bit number. */
26542
- codec.u64 = descriptor_Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.u64(), (d) => d.u64(), codec.bytes(8));
26545
+ codec.u64 = Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.u64(), (d) => d.u64(), codec.bytes(8));
26543
26546
  /** Unsigned 32-bit number. */
26544
- codec.u32 = descriptor_Descriptor.withView("u32", exactHint(4), (e, v) => e.i32(v), (d) => d.u32(), (d) => d.u32(), codec.bytes(4));
26547
+ codec.u32 = Descriptor.withView("u32", exactHint(4), (e, v) => e.i32(v), (d) => d.u32(), (d) => d.u32(), codec.bytes(4));
26545
26548
  /** Unsigned 24-bit number. */
26546
- codec.u24 = descriptor_Descriptor.withView("u24", exactHint(3), (e, v) => e.i24(v), (d) => d.u24(), (d) => d.u24(), codec.bytes(3));
26549
+ codec.u24 = Descriptor.withView("u24", exactHint(3), (e, v) => e.i24(v), (d) => d.u24(), (d) => d.u24(), codec.bytes(3));
26547
26550
  /** Unsigned 16-bit number. */
26548
- codec.u16 = descriptor_Descriptor.withView("u16", exactHint(2), (e, v) => e.i16(v), (d) => d.u16(), (d) => d.u16(), codec.bytes(2));
26551
+ codec.u16 = Descriptor.withView("u16", exactHint(2), (e, v) => e.i16(v), (d) => d.u16(), (d) => d.u16(), codec.bytes(2));
26549
26552
  /** Unsigned 8-bit number. */
26550
- codec.u8 = descriptor_Descriptor.new("u8", exactHint(1), (e, v) => e.i8(v), (d) => d.u8(), (d) => d.u8());
26553
+ codec.u8 = Descriptor.new("u8", exactHint(1), (e, v) => e.i8(v), (d) => d.u8(), (d) => d.u8());
26551
26554
  /** Signed 64-bit number. */
26552
- codec.i64 = descriptor_Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.i64(), (s) => s.u64(), codec.bytes(8));
26555
+ codec.i64 = Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.i64(), (s) => s.u64(), codec.bytes(8));
26553
26556
  /** Signed 32-bit number. */
26554
- codec.i32 = descriptor_Descriptor.withView("i32", exactHint(4), (e, v) => e.i32(v), (d) => d.i32(), (s) => s.u32(), codec.bytes(4));
26557
+ codec.i32 = Descriptor.withView("i32", exactHint(4), (e, v) => e.i32(v), (d) => d.i32(), (s) => s.u32(), codec.bytes(4));
26555
26558
  /** Signed 24-bit number. */
26556
- codec.i24 = descriptor_Descriptor.withView("i24", exactHint(3), (e, v) => e.i24(v), (d) => d.i24(), (s) => s.u24(), codec.bytes(3));
26559
+ codec.i24 = Descriptor.withView("i24", exactHint(3), (e, v) => e.i24(v), (d) => d.i24(), (s) => s.u24(), codec.bytes(3));
26557
26560
  /** Signed 16-bit number. */
26558
- codec.i16 = descriptor_Descriptor.withView("i16", exactHint(2), (e, v) => e.i16(v), (d) => d.i16(), (s) => s.u16(), codec.bytes(2));
26561
+ codec.i16 = Descriptor.withView("i16", exactHint(2), (e, v) => e.i16(v), (d) => d.i16(), (s) => s.u16(), codec.bytes(2));
26559
26562
  /** Signed 8-bit number. */
26560
- codec.i8 = descriptor_Descriptor.new("i8", exactHint(1), (e, v) => e.i8(v), (d) => d.i8(), (s) => s.u8());
26563
+ codec.i8 = Descriptor.new("i8", exactHint(1), (e, v) => e.i8(v), (d) => d.i8(), (s) => s.u8());
26561
26564
  /** 1-byte boolean value. */
26562
- codec.bool = descriptor_Descriptor.new("bool", exactHint(1), (e, v) => e.bool(v), (d) => d.bool(), (s) => s.bool());
26565
+ codec.bool = Descriptor.new("bool", exactHint(1), (e, v) => e.bool(v), (d) => d.bool(), (s) => s.bool());
26563
26566
  /** Variable-length bytes blob. */
26564
- codec.blob = descriptor_Descriptor.new("BytesBlob", { bytes: TYPICAL_SEQUENCE_LENGTH, isExact: false }, (e, v) => e.bytesBlob(v), (d) => d.bytesBlob(), (s) => s.bytesBlob());
26567
+ codec.blob = Descriptor.new("BytesBlob", { bytes: TYPICAL_SEQUENCE_LENGTH, isExact: false }, (e, v) => e.bytesBlob(v), (d) => d.bytesBlob(), (s) => s.bytesBlob());
26565
26568
  /** String encoded as variable-length bytes blob. */
26566
- 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);
26569
+ 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);
26567
26570
  /** Variable-length bit vector. */
26568
- codec.bitVecVarLen = descriptor_Descriptor.new("BitVec[?]", { bytes: TYPICAL_SEQUENCE_LENGTH >>> 3, isExact: false }, (e, v) => e.bitVecVarLen(v), (d) => d.bitVecVarLen(), (s) => s.bitVecVarLen());
26571
+ codec.bitVecVarLen = Descriptor.new("BitVec[?]", { bytes: TYPICAL_SEQUENCE_LENGTH >>> 3, isExact: false }, (e, v) => e.bitVecVarLen(v), (d) => d.bitVecVarLen(), (s) => s.bitVecVarLen());
26569
26572
  /** Fixed-length bit vector. */
26570
- codec.bitVecFixLen = (bitLen) => descriptor_Descriptor.new(`BitVec[${bitLen}]`, exactHint(bitLen >>> 3), (e, v) => e.bitVecFixLen(v), (d) => d.bitVecFixLen(bitLen), (s) => s.bitVecFixLen(bitLen));
26573
+ codec.bitVecFixLen = (bitLen) => Descriptor.new(`BitVec[${bitLen}]`, exactHint(bitLen >>> 3), (e, v) => e.bitVecFixLen(v), (d) => d.bitVecFixLen(bitLen), (s) => s.bitVecFixLen(bitLen));
26571
26574
  /** Optionality wrapper for given type. */
26572
26575
  codec.optional = (type) => {
26573
- 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));
26576
+ 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));
26574
26577
  if (hasUniqueView(type)) {
26575
- return descriptor_Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.optional(type.View));
26578
+ return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.optional(type.View));
26576
26579
  }
26577
26580
  return self;
26578
26581
  };
@@ -26583,7 +26586,7 @@ var descriptors_codec;
26583
26586
  }) => {
26584
26587
  const name = `Sequence<${type.name}>[?]`;
26585
26588
  const typicalLength = options.typicalLength ?? TYPICAL_SEQUENCE_LENGTH;
26586
- return descriptor_Descriptor.withView(name, { bytes: typicalLength * type.sizeHint.bytes, isExact: false }, (e, v) => {
26589
+ return Descriptor.withView(name, { bytes: typicalLength * type.sizeHint.bytes, isExact: false }, (e, v) => {
26587
26590
  validateLength(options, v.length, name);
26588
26591
  e.sequenceVarLen(type, v);
26589
26592
  }, (d) => {
@@ -26597,10 +26600,10 @@ var descriptors_codec;
26597
26600
  }, sequenceViewVarLen(type, options));
26598
26601
  };
26599
26602
  /** Fixed-length sequence of given type. */
26600
- 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 }));
26603
+ 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 }));
26601
26604
  /** Small dictionary codec. */
26602
26605
  codec.dictionary = (key, value, { sortKeys, fixedLength, }) => {
26603
- const self = descriptor_Descriptor.new(`Dictionary<${key.name}, ${value.name}>[${fixedLength ?? "?"}]`, {
26606
+ const self = Descriptor.new(`Dictionary<${key.name}, ${value.name}>[${fixedLength ?? "?"}]`, {
26604
26607
  bytes: fixedLength !== undefined
26605
26608
  ? fixedLength * addSizeHints(key.sizeHint, value.sizeHint).bytes
26606
26609
  : TYPICAL_DICTIONARY_LENGTH * (addSizeHints(key.sizeHint, value.sizeHint).bytes ?? 0),
@@ -26639,13 +26642,13 @@ var descriptors_codec;
26639
26642
  s.sequenceFixLen(value, len);
26640
26643
  });
26641
26644
  if (hasUniqueView(value)) {
26642
- return descriptor_Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.dictionary(key, value.View, { sortKeys, fixedLength }));
26645
+ return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.dictionary(key, value.View, { sortKeys, fixedLength }));
26643
26646
  }
26644
26647
  return self;
26645
26648
  };
26646
26649
  /** Encoding of pair of two values. */
26647
26650
  codec.pair = (a, b) => {
26648
- const self = descriptor_Descriptor.new(`Pair<${a.name}, ${b.name}>`, addSizeHints(a.sizeHint, b.sizeHint), (e, elem) => {
26651
+ const self = Descriptor.new(`Pair<${a.name}, ${b.name}>`, addSizeHints(a.sizeHint, b.sizeHint), (e, elem) => {
26649
26652
  a.encode(e, elem[0]);
26650
26653
  b.encode(e, elem[1]);
26651
26654
  }, (d) => {
@@ -26657,14 +26660,14 @@ var descriptors_codec;
26657
26660
  b.skip(s);
26658
26661
  });
26659
26662
  if (hasUniqueView(a) && hasUniqueView(b)) {
26660
- return descriptor_Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.pair(a.View, b.View));
26663
+ return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.pair(a.View, b.View));
26661
26664
  }
26662
26665
  return self;
26663
26666
  };
26664
26667
  /** Custom encoding / decoding logic. */
26665
- codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => descriptor_Descriptor.new(name, sizeHint, encode, decode, skip);
26668
+ codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
26666
26669
  /** Choose a descriptor depending on the encoding/decoding context. */
26667
- 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);
26670
+ 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);
26668
26671
  /**
26669
26672
  * A descriptor for a more complex POJO.
26670
26673
  *
@@ -26701,7 +26704,7 @@ var descriptors_codec;
26701
26704
  };
26702
26705
  const view = objectView(Class, descriptors, sizeHint, skipper);
26703
26706
  // and create the descriptor for the entire class.
26704
- return descriptor_Descriptor.withView(Class.name, sizeHint, (e, t) => {
26707
+ return Descriptor.withView(Class.name, sizeHint, (e, t) => {
26705
26708
  forEachDescriptor(descriptors, (key, descriptor) => {
26706
26709
  const value = t[key];
26707
26710
  descriptor.encode(e, value);
@@ -26752,7 +26755,7 @@ function objectView(Class, descriptors, sizeHint, skipper) {
26752
26755
  });
26753
26756
  }
26754
26757
  });
26755
- return descriptor_Descriptor.new(`View<${Class.name}>`, sizeHint, (e, t) => {
26758
+ return Descriptor.new(`View<${Class.name}>`, sizeHint, (e, t) => {
26756
26759
  const encoded = t.encoded();
26757
26760
  e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
26758
26761
  }, (d) => {
@@ -26771,7 +26774,7 @@ function sequenceViewVarLen(type, options) {
26771
26774
  validateLength(options, length, name);
26772
26775
  return s.sequenceFixLen(type, length);
26773
26776
  };
26774
- return descriptor_Descriptor.new(name, sizeHint, (e, t) => {
26777
+ return Descriptor.new(name, sizeHint, (e, t) => {
26775
26778
  validateLength(options, t.length, name);
26776
26779
  const encoded = t.encoded();
26777
26780
  e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
@@ -26787,7 +26790,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
26787
26790
  const skipper = (s) => s.sequenceFixLen(type, fixedLength);
26788
26791
  const view = type.name !== type.View.name ? `, ${type.View.name}` : "";
26789
26792
  const name = `SeqView<${type.name}${view}>[${fixedLength}]`;
26790
- return descriptor_Descriptor.new(name, sizeHint, (e, t) => {
26793
+ return Descriptor.new(name, sizeHint, (e, t) => {
26791
26794
  const encoded = t.encoded();
26792
26795
  e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
26793
26796
  }, (d) => {
@@ -28176,6 +28179,49 @@ function hashBlobs(hasher, blobs) {
28176
28179
 
28177
28180
 
28178
28181
 
28182
+ ;// CONCATENATED MODULE: ./packages/core/collections/array-view.ts
28183
+
28184
+ /**
28185
+ * A utility class providing a readonly view over a portion of an array without copying it.
28186
+ */
28187
+ class ArrayView {
28188
+ start;
28189
+ end;
28190
+ source;
28191
+ length;
28192
+ constructor(source, start, end) {
28193
+ this.start = start;
28194
+ this.end = end;
28195
+ this.source = source;
28196
+ this.length = end - start;
28197
+ }
28198
+ static from(source, start = 0, end = source.length) {
28199
+ debug_check `
28200
+ ${start >= 0 && end <= source.length && start <= end}
28201
+ Invalid start (${start})/end (${end}) for ArrayView
28202
+ `;
28203
+ return new ArrayView(source, start, end);
28204
+ }
28205
+ get(i) {
28206
+ debug_check `
28207
+ ${i >= 0 && i < this.length}
28208
+ Index out of bounds: ${i} < ${this.length}
28209
+ `;
28210
+ return this.source[this.start + i];
28211
+ }
28212
+ subview(from, to = this.length) {
28213
+ return ArrayView.from(this.source, this.start + from, this.start + to);
28214
+ }
28215
+ toArray() {
28216
+ return this.source.slice(this.start, this.end);
28217
+ }
28218
+ *[Symbol.iterator]() {
28219
+ for (let i = this.start; i < this.end; i++) {
28220
+ yield this.source[i];
28221
+ }
28222
+ }
28223
+ }
28224
+
28179
28225
  ;// CONCATENATED MODULE: ./packages/core/collections/hash-dictionary.ts
28180
28226
  /** A map which uses hashes as keys. */
28181
28227
  class hash_dictionary_HashDictionary {
@@ -28787,6 +28833,7 @@ class TruncatedHashDictionary {
28787
28833
 
28788
28834
 
28789
28835
 
28836
+
28790
28837
  ;// CONCATENATED MODULE: ./packages/jam/config/chain-spec.ts
28791
28838
 
28792
28839
 
@@ -29044,7 +29091,7 @@ const codecFixedSizeArray = (val, len) => {
29044
29091
  };
29045
29092
  /** Codec for a hash-dictionary. */
29046
29093
  const codecHashDictionary = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH, compare = (a, b) => extractKey(a).compare(extractKey(b)), } = {}) => {
29047
- return descriptor_Descriptor.new(`HashDictionary<${value.name}>[?]`, {
29094
+ return Descriptor.new(`HashDictionary<${value.name}>[?]`, {
29048
29095
  bytes: typicalLength * value.sizeHint.bytes,
29049
29096
  isExact: false,
29050
29097
  }, (e, v) => {
@@ -32107,6 +32154,13 @@ const W_T = 128;
32107
32154
  /** `W_M`: The maximum number of exports in a work-package. */
32108
32155
  const W_X = 3_072;
32109
32156
  // TODO [ToDr] Not sure where these should live yet :(
32157
+ /**
32158
+ * `S`: The minimum public service index.
32159
+ * Services of indices below these may only be created by the Registrar.
32160
+ *
32161
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
32162
+ */
32163
+ const MIN_PUBLIC_SERVICE_INDEX = 2 ** 16;
32110
32164
  /**
32111
32165
  * `J`: The maximum sum of dependency items in a work-report.
32112
32166
  *
@@ -32118,9 +32172,209 @@ const AUTHORIZATION_QUEUE_SIZE = Q;
32118
32172
  /** `O`: Maximal authorization pool size. */
32119
32173
  const MAX_AUTH_POOL_SIZE = O;
32120
32174
 
32175
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
32176
+ const MAX_VALUE = 4294967295;
32177
+ const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
32178
+ const MIN_VALUE = -(2 ** 31);
32179
+ const MAX_SHIFT_U32 = 32;
32180
+ const MAX_SHIFT_U64 = 64n;
32181
+
32182
+ ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
32183
+
32184
+
32185
+
32186
+
32187
+
32188
+
32189
+ /**
32190
+ * `B_S`: The basic minimum balance which all services require.
32191
+ *
32192
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
32193
+ */
32194
+ const BASE_SERVICE_BALANCE = 100n;
32195
+ /**
32196
+ * `B_I`: The additional minimum balance required per item of elective service state.
32197
+ *
32198
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
32199
+ */
32200
+ const ELECTIVE_ITEM_BALANCE = 10n;
32201
+ /**
32202
+ * `B_L`: The additional minimum balance required per octet of elective service state.
32203
+ *
32204
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
32205
+ */
32206
+ const ELECTIVE_BYTE_BALANCE = 1n;
32207
+ const zeroSizeHint = {
32208
+ bytes: 0,
32209
+ isExact: true,
32210
+ };
32211
+ /** 0-byte read, return given default value */
32212
+ const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
32213
+ /** Encode and decode object with leading version number. */
32214
+ const codecWithVersion = (val) => Descriptor.new("withVersion", {
32215
+ bytes: val.sizeHint.bytes + 8,
32216
+ isExact: false,
32217
+ }, (e, v) => {
32218
+ e.varU64(0n);
32219
+ val.encode(e, v);
32220
+ }, (d) => {
32221
+ const version = d.varU64();
32222
+ if (version !== 0n) {
32223
+ throw new Error("Non-zero version is not supported!");
32224
+ }
32225
+ return val.decode(d);
32226
+ }, (s) => {
32227
+ s.varU64();
32228
+ val.skip(s);
32229
+ });
32230
+ /**
32231
+ * Service account details.
32232
+ *
32233
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
32234
+ */
32235
+ class ServiceAccountInfo extends WithDebug {
32236
+ codeHash;
32237
+ balance;
32238
+ accumulateMinGas;
32239
+ onTransferMinGas;
32240
+ storageUtilisationBytes;
32241
+ gratisStorage;
32242
+ storageUtilisationCount;
32243
+ created;
32244
+ lastAccumulation;
32245
+ parentService;
32246
+ static Codec = descriptors_codec.Class(ServiceAccountInfo, {
32247
+ codeHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
32248
+ balance: descriptors_codec.u64,
32249
+ accumulateMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
32250
+ onTransferMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
32251
+ storageUtilisationBytes: descriptors_codec.u64,
32252
+ gratisStorage: descriptors_codec.u64,
32253
+ storageUtilisationCount: descriptors_codec.u32,
32254
+ created: descriptors_codec.u32.convert((x) => x, tryAsTimeSlot),
32255
+ lastAccumulation: descriptors_codec.u32.convert((x) => x, tryAsTimeSlot),
32256
+ parentService: descriptors_codec.u32.convert((x) => x, tryAsServiceId),
32257
+ });
32258
+ static create(a) {
32259
+ return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
32260
+ }
32261
+ /**
32262
+ * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
32263
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
32264
+ */
32265
+ static calculateThresholdBalance(items, bytes, gratisStorage) {
32266
+ const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
32267
+ if (storageCost < 0n) {
32268
+ return numbers_tryAsU64(0);
32269
+ }
32270
+ if (storageCost >= 2n ** 64n) {
32271
+ return numbers_tryAsU64(2n ** 64n - 1n);
32272
+ }
32273
+ return numbers_tryAsU64(storageCost);
32274
+ }
32275
+ constructor(
32276
+ /** `a_c`: Hash of the service code. */
32277
+ codeHash,
32278
+ /** `a_b`: Current account balance. */
32279
+ balance,
32280
+ /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
32281
+ accumulateMinGas,
32282
+ /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
32283
+ onTransferMinGas,
32284
+ /** `a_o`: Total number of octets in storage. */
32285
+ storageUtilisationBytes,
32286
+ /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
32287
+ gratisStorage,
32288
+ /** `a_i`: Number of items in storage. */
32289
+ storageUtilisationCount,
32290
+ /** `a_r`: Creation account time slot. */
32291
+ created,
32292
+ /** `a_a`: Most recent accumulation time slot. */
32293
+ lastAccumulation,
32294
+ /** `a_p`: Parent service ID. */
32295
+ parentService) {
32296
+ super();
32297
+ this.codeHash = codeHash;
32298
+ this.balance = balance;
32299
+ this.accumulateMinGas = accumulateMinGas;
32300
+ this.onTransferMinGas = onTransferMinGas;
32301
+ this.storageUtilisationBytes = storageUtilisationBytes;
32302
+ this.gratisStorage = gratisStorage;
32303
+ this.storageUtilisationCount = storageUtilisationCount;
32304
+ this.created = created;
32305
+ this.lastAccumulation = lastAccumulation;
32306
+ this.parentService = parentService;
32307
+ }
32308
+ }
32309
+ class PreimageItem extends WithDebug {
32310
+ hash;
32311
+ blob;
32312
+ static Codec = descriptors_codec.Class(PreimageItem, {
32313
+ hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
32314
+ blob: descriptors_codec.blob,
32315
+ });
32316
+ static create({ hash, blob }) {
32317
+ return new PreimageItem(hash, blob);
32318
+ }
32319
+ constructor(hash, blob) {
32320
+ super();
32321
+ this.hash = hash;
32322
+ this.blob = blob;
32323
+ }
32324
+ }
32325
+ class StorageItem extends WithDebug {
32326
+ key;
32327
+ value;
32328
+ static Codec = descriptors_codec.Class(StorageItem, {
32329
+ key: descriptors_codec.blob.convert((i) => i, (o) => opaque_asOpaqueType(o)),
32330
+ value: descriptors_codec.blob,
32331
+ });
32332
+ static create({ key, value }) {
32333
+ return new StorageItem(key, value);
32334
+ }
32335
+ constructor(key, value) {
32336
+ super();
32337
+ this.key = key;
32338
+ this.value = value;
32339
+ }
32340
+ }
32341
+ const MAX_LOOKUP_HISTORY_SLOTS = 3;
32342
+ function tryAsLookupHistorySlots(items) {
32343
+ const knownSize = sized_array_asKnownSize(items);
32344
+ if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
32345
+ throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
32346
+ }
32347
+ return knownSize;
32348
+ }
32349
+ /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
32350
+ class LookupHistoryItem {
32351
+ hash;
32352
+ length;
32353
+ slots;
32354
+ constructor(hash, length,
32355
+ /**
32356
+ * Preimage availability history as a sequence of time slots.
32357
+ * See PreimageStatus and the following GP fragment for more details.
32358
+ * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
32359
+ slots) {
32360
+ this.hash = hash;
32361
+ this.length = length;
32362
+ this.slots = slots;
32363
+ }
32364
+ static isRequested(item) {
32365
+ if ("slots" in item) {
32366
+ return item.slots.length === 0;
32367
+ }
32368
+ return item.length === 0;
32369
+ }
32370
+ }
32371
+
32121
32372
  ;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
32122
32373
 
32123
32374
 
32375
+
32376
+
32377
+
32124
32378
  /** Dictionary entry of services that auto-accumulate every block. */
32125
32379
  class AutoAccumulate {
32126
32380
  service;
@@ -32142,39 +32396,50 @@ class AutoAccumulate {
32142
32396
  }
32143
32397
  }
32144
32398
  /**
32145
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11da0111da01?v=0.6.7
32399
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
32146
32400
  */
32147
32401
  class PrivilegedServices {
32148
32402
  manager;
32149
- authManager;
32150
- validatorsManager;
32403
+ delegator;
32404
+ registrar;
32405
+ assigners;
32151
32406
  autoAccumulateServices;
32407
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
32152
32408
  static Codec = descriptors_codec.Class(PrivilegedServices, {
32153
32409
  manager: descriptors_codec.u32.asOpaque(),
32154
- authManager: codecPerCore(descriptors_codec.u32.asOpaque()),
32155
- validatorsManager: descriptors_codec.u32.asOpaque(),
32410
+ assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
32411
+ delegator: descriptors_codec.u32.asOpaque(),
32412
+ registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
32413
+ ? descriptors_codec.u32.asOpaque()
32414
+ : ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
32156
32415
  autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
32157
32416
  });
32158
- static create({ manager, authManager, validatorsManager, autoAccumulateServices }) {
32159
- return new PrivilegedServices(manager, authManager, validatorsManager, autoAccumulateServices);
32417
+ static create(a) {
32418
+ return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
32160
32419
  }
32161
32420
  constructor(
32162
32421
  /**
32163
- * `chi_m`: The first, χm, is the index of the manager service which is
32164
- * the service able to effect an alteration of χ from block to block,
32422
+ * `χ_M`: Manages alteration of χ from block to block,
32165
32423
  * as well as bestow services with storage deposit credits.
32166
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11a40111a801?v=0.6.7
32424
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
32167
32425
  */
32168
32426
  manager,
32169
- /** `chi_a`: Manages authorization queue one for each core. */
32170
- authManager,
32171
- /** `chi_v`: Managers validator keys. */
32172
- validatorsManager,
32173
- /** `chi_g`: Dictionary of services that auto-accumulate every block with their gas limit. */
32427
+ /** `χ_V`: Managers validator keys. */
32428
+ delegator,
32429
+ /**
32430
+ * `χ_R`: Manages the creation of services in protected range.
32431
+ *
32432
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
32433
+ */
32434
+ registrar,
32435
+ /** `χ_A`: Manages authorization queue one for each core. */
32436
+ assigners,
32437
+ /** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
32174
32438
  autoAccumulateServices) {
32175
32439
  this.manager = manager;
32176
- this.authManager = authManager;
32177
- this.validatorsManager = validatorsManager;
32440
+ this.delegator = delegator;
32441
+ this.registrar = registrar;
32442
+ this.assigners = assigners;
32178
32443
  this.autoAccumulateServices = autoAccumulateServices;
32179
32444
  }
32180
32445
  }
@@ -32262,7 +32527,7 @@ class RecentBlocks extends WithDebug {
32262
32527
  */
32263
32528
  class RecentBlocksHistory extends WithDebug {
32264
32529
  current;
32265
- static Codec = descriptor_Descriptor.new("RecentBlocksHistory", RecentBlocks.Codec.sizeHint, (encoder, value) => RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
32530
+ static Codec = Descriptor.new("RecentBlocksHistory", RecentBlocks.Codec.sizeHint, (encoder, value) => RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
32266
32531
  const recentBlocks = RecentBlocks.Codec.decode(decoder);
32267
32532
  return RecentBlocksHistory.create(recentBlocks);
32268
32533
  }, (skip) => {
@@ -32378,257 +32643,84 @@ const codecBandersnatchKey = descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asO
32378
32643
  class SafroleSealingKeysData extends WithDebug {
32379
32644
  kind;
32380
32645
  keys;
32381
- tickets;
32382
- static Codec = codecWithContext((context) => {
32383
- return descriptors_codec.custom({
32384
- name: "SafroleSealingKeys",
32385
- sizeHint: { bytes: 1 + hash_HASH_SIZE * context.epochLength, isExact: false },
32386
- }, (e, x) => {
32387
- e.varU32(numbers_tryAsU32(x.kind));
32388
- if (x.kind === SafroleSealingKeysKind.Keys) {
32389
- e.sequenceFixLen(codecBandersnatchKey, x.keys);
32390
- }
32391
- else {
32392
- e.sequenceFixLen(Ticket.Codec, x.tickets);
32393
- }
32394
- }, (d) => {
32395
- const epochLength = context.epochLength;
32396
- const kind = d.varU32();
32397
- if (kind === SafroleSealingKeysKind.Keys) {
32398
- const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
32399
- return SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
32400
- }
32401
- if (kind === SafroleSealingKeysKind.Tickets) {
32402
- const tickets = d.sequenceFixLen(Ticket.Codec, epochLength);
32403
- return SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
32404
- }
32405
- throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
32406
- }, (s) => {
32407
- const kind = s.decoder.varU32();
32408
- if (kind === SafroleSealingKeysKind.Keys) {
32409
- s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
32410
- return;
32411
- }
32412
- if (kind === SafroleSealingKeysKind.Tickets) {
32413
- s.sequenceFixLen(Ticket.Codec, context.epochLength);
32414
- return;
32415
- }
32416
- throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
32417
- });
32418
- });
32419
- static keys(keys) {
32420
- return new SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
32421
- }
32422
- static tickets(tickets) {
32423
- return new SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
32424
- }
32425
- constructor(kind, keys, tickets) {
32426
- super();
32427
- this.kind = kind;
32428
- this.keys = keys;
32429
- this.tickets = tickets;
32430
- }
32431
- }
32432
- class SafroleData {
32433
- nextValidatorData;
32434
- epochRoot;
32435
- sealingKeySeries;
32436
- ticketsAccumulator;
32437
- static Codec = descriptors_codec.Class(SafroleData, {
32438
- nextValidatorData: codecPerValidator(ValidatorData.Codec),
32439
- epochRoot: descriptors_codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
32440
- sealingKeySeries: SafroleSealingKeysData.Codec,
32441
- ticketsAccumulator: readonlyArray(descriptors_codec.sequenceVarLen(Ticket.Codec)).convert(seeThrough, sized_array_asKnownSize),
32442
- });
32443
- static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
32444
- return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
32445
- }
32446
- constructor(
32447
- /** gamma_k */
32448
- nextValidatorData,
32449
- /** gamma_z */
32450
- epochRoot,
32451
- /** gamma_s */
32452
- sealingKeySeries,
32453
- /** gamma_a */
32454
- ticketsAccumulator) {
32455
- this.nextValidatorData = nextValidatorData;
32456
- this.epochRoot = epochRoot;
32457
- this.sealingKeySeries = sealingKeySeries;
32458
- this.ticketsAccumulator = ticketsAccumulator;
32459
- }
32460
- }
32461
-
32462
- ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
32463
-
32464
-
32465
-
32466
-
32467
-
32468
-
32469
- /**
32470
- * `B_S`: The basic minimum balance which all services require.
32471
- *
32472
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
32473
- */
32474
- const BASE_SERVICE_BALANCE = 100n;
32475
- /**
32476
- * `B_I`: The additional minimum balance required per item of elective service state.
32477
- *
32478
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
32479
- */
32480
- const ELECTIVE_ITEM_BALANCE = 10n;
32481
- /**
32482
- * `B_L`: The additional minimum balance required per octet of elective service state.
32483
- *
32484
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
32485
- */
32486
- const ELECTIVE_BYTE_BALANCE = 1n;
32487
- const zeroSizeHint = {
32488
- bytes: 0,
32489
- isExact: true,
32490
- };
32491
- /** 0-byte read, return given default value */
32492
- const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
32493
- /**
32494
- * Service account details.
32495
- *
32496
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
32497
- */
32498
- class ServiceAccountInfo extends WithDebug {
32499
- codeHash;
32500
- balance;
32501
- accumulateMinGas;
32502
- onTransferMinGas;
32503
- storageUtilisationBytes;
32504
- gratisStorage;
32505
- storageUtilisationCount;
32506
- created;
32507
- lastAccumulation;
32508
- parentService;
32509
- static Codec = descriptors_codec.Class(ServiceAccountInfo, {
32510
- codeHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
32511
- balance: descriptors_codec.u64,
32512
- accumulateMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
32513
- onTransferMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
32514
- storageUtilisationBytes: descriptors_codec.u64,
32515
- gratisStorage: descriptors_codec.u64,
32516
- storageUtilisationCount: descriptors_codec.u32,
32517
- created: descriptors_codec.u32.convert((x) => x, tryAsTimeSlot),
32518
- lastAccumulation: descriptors_codec.u32.convert((x) => x, tryAsTimeSlot),
32519
- parentService: descriptors_codec.u32.convert((x) => x, tryAsServiceId),
32520
- });
32521
- static create(a) {
32522
- return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
32523
- }
32524
- /**
32525
- * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
32526
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
32527
- */
32528
- static calculateThresholdBalance(items, bytes, gratisStorage) {
32529
- const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
32530
- if (storageCost < 0n) {
32531
- return numbers_tryAsU64(0);
32532
- }
32533
- if (storageCost >= 2n ** 64n) {
32534
- return numbers_tryAsU64(2n ** 64n - 1n);
32535
- }
32536
- return numbers_tryAsU64(storageCost);
32537
- }
32538
- constructor(
32539
- /** `a_c`: Hash of the service code. */
32540
- codeHash,
32541
- /** `a_b`: Current account balance. */
32542
- balance,
32543
- /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
32544
- accumulateMinGas,
32545
- /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
32546
- onTransferMinGas,
32547
- /** `a_o`: Total number of octets in storage. */
32548
- storageUtilisationBytes,
32549
- /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
32550
- gratisStorage,
32551
- /** `a_i`: Number of items in storage. */
32552
- storageUtilisationCount,
32553
- /** `a_r`: Creation account time slot. */
32554
- created,
32555
- /** `a_a`: Most recent accumulation time slot. */
32556
- lastAccumulation,
32557
- /** `a_p`: Parent service ID. */
32558
- parentService) {
32559
- super();
32560
- this.codeHash = codeHash;
32561
- this.balance = balance;
32562
- this.accumulateMinGas = accumulateMinGas;
32563
- this.onTransferMinGas = onTransferMinGas;
32564
- this.storageUtilisationBytes = storageUtilisationBytes;
32565
- this.gratisStorage = gratisStorage;
32566
- this.storageUtilisationCount = storageUtilisationCount;
32567
- this.created = created;
32568
- this.lastAccumulation = lastAccumulation;
32569
- this.parentService = parentService;
32570
- }
32571
- }
32572
- class PreimageItem extends WithDebug {
32573
- hash;
32574
- blob;
32575
- static Codec = descriptors_codec.Class(PreimageItem, {
32576
- hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
32577
- blob: descriptors_codec.blob,
32646
+ tickets;
32647
+ static Codec = codecWithContext((context) => {
32648
+ return descriptors_codec.custom({
32649
+ name: "SafroleSealingKeys",
32650
+ sizeHint: { bytes: 1 + hash_HASH_SIZE * context.epochLength, isExact: false },
32651
+ }, (e, x) => {
32652
+ e.varU32(numbers_tryAsU32(x.kind));
32653
+ if (x.kind === SafroleSealingKeysKind.Keys) {
32654
+ e.sequenceFixLen(codecBandersnatchKey, x.keys);
32655
+ }
32656
+ else {
32657
+ e.sequenceFixLen(Ticket.Codec, x.tickets);
32658
+ }
32659
+ }, (d) => {
32660
+ const epochLength = context.epochLength;
32661
+ const kind = d.varU32();
32662
+ if (kind === SafroleSealingKeysKind.Keys) {
32663
+ const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
32664
+ return SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
32665
+ }
32666
+ if (kind === SafroleSealingKeysKind.Tickets) {
32667
+ const tickets = d.sequenceFixLen(Ticket.Codec, epochLength);
32668
+ return SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
32669
+ }
32670
+ throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
32671
+ }, (s) => {
32672
+ const kind = s.decoder.varU32();
32673
+ if (kind === SafroleSealingKeysKind.Keys) {
32674
+ s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
32675
+ return;
32676
+ }
32677
+ if (kind === SafroleSealingKeysKind.Tickets) {
32678
+ s.sequenceFixLen(Ticket.Codec, context.epochLength);
32679
+ return;
32680
+ }
32681
+ throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
32682
+ });
32578
32683
  });
32579
- static create({ hash, blob }) {
32580
- return new PreimageItem(hash, blob);
32581
- }
32582
- constructor(hash, blob) {
32583
- super();
32584
- this.hash = hash;
32585
- this.blob = blob;
32684
+ static keys(keys) {
32685
+ return new SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
32586
32686
  }
32587
- }
32588
- class StorageItem extends WithDebug {
32589
- key;
32590
- value;
32591
- static Codec = descriptors_codec.Class(StorageItem, {
32592
- key: descriptors_codec.blob.convert((i) => i, (o) => opaque_asOpaqueType(o)),
32593
- value: descriptors_codec.blob,
32594
- });
32595
- static create({ key, value }) {
32596
- return new StorageItem(key, value);
32687
+ static tickets(tickets) {
32688
+ return new SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
32597
32689
  }
32598
- constructor(key, value) {
32690
+ constructor(kind, keys, tickets) {
32599
32691
  super();
32600
- this.key = key;
32601
- this.value = value;
32602
- }
32603
- }
32604
- const MAX_LOOKUP_HISTORY_SLOTS = 3;
32605
- function tryAsLookupHistorySlots(items) {
32606
- const knownSize = sized_array_asKnownSize(items);
32607
- if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
32608
- throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
32692
+ this.kind = kind;
32693
+ this.keys = keys;
32694
+ this.tickets = tickets;
32609
32695
  }
32610
- return knownSize;
32611
32696
  }
32612
- /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
32613
- class LookupHistoryItem {
32614
- hash;
32615
- length;
32616
- slots;
32617
- constructor(hash, length,
32618
- /**
32619
- * Preimage availability history as a sequence of time slots.
32620
- * See PreimageStatus and the following GP fragment for more details.
32621
- * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
32622
- slots) {
32623
- this.hash = hash;
32624
- this.length = length;
32625
- this.slots = slots;
32697
+ class SafroleData {
32698
+ nextValidatorData;
32699
+ epochRoot;
32700
+ sealingKeySeries;
32701
+ ticketsAccumulator;
32702
+ static Codec = descriptors_codec.Class(SafroleData, {
32703
+ nextValidatorData: codecPerValidator(ValidatorData.Codec),
32704
+ epochRoot: descriptors_codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
32705
+ sealingKeySeries: SafroleSealingKeysData.Codec,
32706
+ ticketsAccumulator: readonlyArray(descriptors_codec.sequenceVarLen(Ticket.Codec)).convert(seeThrough, sized_array_asKnownSize),
32707
+ });
32708
+ static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
32709
+ return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
32626
32710
  }
32627
- static isRequested(item) {
32628
- if ("slots" in item) {
32629
- return item.slots.length === 0;
32630
- }
32631
- return item.length === 0;
32711
+ constructor(
32712
+ /** gamma_k */
32713
+ nextValidatorData,
32714
+ /** gamma_z */
32715
+ epochRoot,
32716
+ /** gamma_s */
32717
+ sealingKeySeries,
32718
+ /** gamma_a */
32719
+ ticketsAccumulator) {
32720
+ this.nextValidatorData = nextValidatorData;
32721
+ this.epochRoot = epochRoot;
32722
+ this.sealingKeySeries = sealingKeySeries;
32723
+ this.ticketsAccumulator = ticketsAccumulator;
32632
32724
  }
32633
32725
  }
32634
32726
 
@@ -33068,6 +33160,7 @@ class StatisticsData {
33068
33160
 
33069
33161
 
33070
33162
 
33163
+
33071
33164
 
33072
33165
 
33073
33166
  var in_memory_state_UpdateError;
@@ -33471,8 +33564,9 @@ class InMemoryState extends WithDebug {
33471
33564
  epochRoot: bytes_Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
33472
33565
  privilegedServices: PrivilegedServices.create({
33473
33566
  manager: tryAsServiceId(0),
33474
- authManager: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
33475
- validatorsManager: tryAsServiceId(0),
33567
+ assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
33568
+ delegator: tryAsServiceId(0),
33569
+ registrar: tryAsServiceId(MAX_VALUE),
33476
33570
  autoAccumulateServices: [],
33477
33571
  }),
33478
33572
  accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
@@ -33566,6 +33660,7 @@ class NotYetAccumulatedReport extends WithDebug {
33566
33660
 
33567
33661
 
33568
33662
 
33663
+
33569
33664
  /** Serialization for particular state entries. */
33570
33665
  var serialize;
33571
33666
  (function (serialize) {
@@ -33680,7 +33775,9 @@ var serialize;
33680
33775
  /** C(255, s): https://graypaper.fluffylabs.dev/#/85129da/383103383103?v=0.6.3 */
33681
33776
  serialize.serviceData = (serviceId) => ({
33682
33777
  key: stateKeys.serviceInfo(serviceId),
33683
- Codec: ServiceAccountInfo.Codec,
33778
+ Codec: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
33779
+ ? codecWithVersion(ServiceAccountInfo.Codec)
33780
+ : ServiceAccountInfo.Codec,
33684
33781
  });
33685
33782
  /** https://graypaper.fluffylabs.dev/#/85129da/384803384803?v=0.6.3 */
33686
33783
  serialize.serviceStorage = (blake2b, serviceId, key) => ({
@@ -33705,7 +33802,7 @@ var serialize;
33705
33802
  * determine the boundary of the bytes, so it can only be used
33706
33803
  * as the last element of the codec and can't be used in sequences!
33707
33804
  */
33708
- 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()));
33805
+ 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()));
33709
33806
 
33710
33807
  ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
33711
33808
 
@@ -35016,7 +35113,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
35016
35113
  }
35017
35114
  return Ordering.Equal;
35018
35115
  }, } = {}) => {
35019
- return descriptor_Descriptor.new(`Map<${value.name}>[?]`, {
35116
+ return Descriptor.new(`Map<${value.name}>[?]`, {
35020
35117
  bytes: typicalLength * value.sizeHint.bytes,
35021
35118
  isExact: false,
35022
35119
  }, (e, v) => {
@@ -39114,8 +39211,9 @@ class ce_129_state_request_Handler {
39114
39211
  onStreamMessage(sender, message) {
39115
39212
  if (this.isServer) {
39116
39213
  ce_129_state_request_logger.info `[${sender.streamId}][server]: Received request.`;
39117
- if (this.getBoundaryNodes === undefined || this.getKeyValuePairs === undefined)
39214
+ if (this.getBoundaryNodes === undefined || this.getKeyValuePairs === undefined) {
39118
39215
  return;
39216
+ }
39119
39217
  const request = decoder_Decoder.decodeObject(StateRequest.Codec, message);
39120
39218
  const boundaryNodes = this.getBoundaryNodes(request.headerHash, request.startKey, request.endKey);
39121
39219
  const keyValuePairs = this.getKeyValuePairs(request.headerHash, request.startKey, request.endKey);
@@ -41840,7 +41938,7 @@ class AccumulationStateUpdate {
41840
41938
  if (from.privilegedServices !== null) {
41841
41939
  update.privilegedServices = PrivilegedServices.create({
41842
41940
  ...from.privilegedServices,
41843
- authManager: sized_array_asKnownSize([...from.privilegedServices.authManager]),
41941
+ assigners: sized_array_asKnownSize([...from.privilegedServices.assigners]),
41844
41942
  });
41845
41943
  }
41846
41944
  return update;
@@ -43979,13 +44077,6 @@ class BitOps {
43979
44077
  }
43980
44078
  }
43981
44079
 
43982
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
43983
- const MAX_VALUE = 4294967295;
43984
- const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
43985
- const MIN_VALUE = -(2 ** 31);
43986
- const MAX_SHIFT_U32 = 32;
43987
- const MAX_SHIFT_U64 = 64n;
43988
-
43989
44080
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-utils.ts
43990
44081
 
43991
44082
 
@@ -46015,6 +46106,8 @@ var NewServiceError;
46015
46106
  NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
46016
46107
  /** Service is not privileged to set gratis storage. */
46017
46108
  NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
46109
+ /** Registrar attempting to create a service with already existing id. */
46110
+ NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
46018
46111
  })(NewServiceError || (NewServiceError = {}));
46019
46112
  var UpdatePrivilegesError;
46020
46113
  (function (UpdatePrivilegesError) {
@@ -46151,7 +46244,7 @@ const HostCallResult = {
46151
46244
  OOB: numbers_tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
46152
46245
  /** Index unknown. */
46153
46246
  WHO: numbers_tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
46154
- /** Storage full. */
46247
+ /** Storage full or resource already allocated. */
46155
46248
  FULL: numbers_tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
46156
46249
  /** Core index unknown. */
46157
46250
  CORE: numbers_tryAsU64(0xfffffffffffffffan), // 2**64 - 6
@@ -46159,7 +46252,7 @@ const HostCallResult = {
46159
46252
  CASH: numbers_tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
46160
46253
  /** Gas limit too low. */
46161
46254
  LOW: numbers_tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
46162
- /** The item is already solicited or cannot be forgotten. */
46255
+ /** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
46163
46256
  HUH: numbers_tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
46164
46257
  /** The return value indicating general success. */
46165
46258
  OK: numbers_tryAsU64(0n),
@@ -46213,6 +46306,7 @@ function clampU64ToU32(value) {
46213
46306
 
46214
46307
 
46215
46308
 
46309
+
46216
46310
  /**
46217
46311
  * Number of storage items required for ejection of the service.
46218
46312
  *
@@ -46304,10 +46398,13 @@ class AccumulateExternalities {
46304
46398
  const isExpired = status.data[1] < t - this.chainSpec.preimageExpungePeriod;
46305
46399
  return [isExpired, isExpired ? "" : "not expired"];
46306
46400
  }
46307
- /** `check`: https://graypaper.fluffylabs.dev/#/9a08063/303f02303f02?v=0.6.6 */
46401
+ /** `check`: https://graypaper.fluffylabs.dev/#/ab2cdbd/30c60330c603?v=0.7.2 */
46308
46402
  getNextAvailableServiceId(serviceId) {
46309
46403
  let currentServiceId = serviceId;
46310
- const mod = 2 ** 32 - 2 ** 9;
46404
+ const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
46405
+ ? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
46406
+ : 2 ** 32 - 2 ** 9;
46407
+ const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
46311
46408
  for (;;) {
46312
46409
  const service = this.getServiceInfo(currentServiceId);
46313
46410
  // we found an empty id
@@ -46315,7 +46412,7 @@ class AccumulateExternalities {
46315
46412
  return currentServiceId;
46316
46413
  }
46317
46414
  // keep trying
46318
- currentServiceId = tryAsServiceId(((currentServiceId - 2 ** 8 + 1 + mod) % mod) + 2 ** 8);
46415
+ currentServiceId = tryAsServiceId(((currentServiceId - offset + 1 + mod) % mod) + offset);
46319
46416
  }
46320
46417
  }
46321
46418
  checkPreimageStatus(hash, length) {
@@ -46472,8 +46569,7 @@ class AccumulateExternalities {
46472
46569
  }));
46473
46570
  return result_Result.ok(result_OK);
46474
46571
  }
46475
- newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage) {
46476
- const newServiceId = this.nextNewServiceId;
46572
+ newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage, wantedServiceId) {
46477
46573
  // calculate the threshold. Storage is empty, one preimage requested.
46478
46574
  // https://graypaper.fluffylabs.dev/#/7e6ff6a/115901115901?v=0.6.7
46479
46575
  const items = numbers_tryAsU32(2 * 1 + 0);
@@ -46494,30 +46590,59 @@ class AccumulateExternalities {
46494
46590
  if (balanceLeftForCurrent < thresholdForCurrent || bytes.overflow) {
46495
46591
  return result_Result.error(NewServiceError.InsufficientFunds);
46496
46592
  }
46593
+ // `a`: https://graypaper.fluffylabs.dev/#/ab2cdbd/366b02366d02?v=0.7.2
46594
+ const newAccount = ServiceAccountInfo.create({
46595
+ codeHash,
46596
+ balance: thresholdForNew,
46597
+ accumulateMinGas,
46598
+ onTransferMinGas,
46599
+ storageUtilisationBytes: bytes.value,
46600
+ storageUtilisationCount: items,
46601
+ gratisStorage,
46602
+ created: this.currentTimeslot,
46603
+ lastAccumulation: tryAsTimeSlot(0),
46604
+ parentService: this.currentServiceId,
46605
+ });
46606
+ const newLookupItem = new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([]));
46607
+ // `s`: https://graypaper.fluffylabs.dev/#/ab2cdbd/361003361003?v=0.7.2
46608
+ const updatedCurrentAccount = ServiceAccountInfo.create({
46609
+ ...currentService,
46610
+ balance: numbers_tryAsU64(balanceLeftForCurrent),
46611
+ });
46612
+ if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
46613
+ if (wantedServiceId < MIN_PUBLIC_SERVICE_INDEX &&
46614
+ this.currentServiceId === this.updatedState.getPrivilegedServices().registrar) {
46615
+ // NOTE: It's safe to cast to `Number` here, bcs here service ID cannot be bigger than 2**16
46616
+ const newServiceId = tryAsServiceId(Number(wantedServiceId));
46617
+ if (this.getServiceInfo(newServiceId) !== null) {
46618
+ return result_Result.error(NewServiceError.RegistrarServiceIdAlreadyTaken);
46619
+ }
46620
+ // add the new service with selected ID
46621
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36be0336c003?v=0.7.2
46622
+ this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
46623
+ serviceId: newServiceId,
46624
+ serviceInfo: newAccount,
46625
+ lookupHistory: newLookupItem,
46626
+ }));
46627
+ // update the balance of current service
46628
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36c20336c403?v=0.7.2
46629
+ this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
46630
+ return result_Result.ok(newServiceId);
46631
+ }
46632
+ // NOTE: in case the service is not a registrar or the requested serviceId is out of range,
46633
+ // we completely ignore the `wantedServiceId` and assign a random one
46634
+ }
46635
+ const newServiceId = this.nextNewServiceId;
46497
46636
  // add the new service
46498
- // https://graypaper.fluffylabs.dev/#/7e6ff6a/36cb0236cb02?v=0.6.7
46637
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36e70336e903?v=0.7.2
46499
46638
  this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
46500
46639
  serviceId: newServiceId,
46501
- serviceInfo: ServiceAccountInfo.create({
46502
- codeHash,
46503
- balance: thresholdForNew,
46504
- accumulateMinGas,
46505
- onTransferMinGas,
46506
- storageUtilisationBytes: bytes.value,
46507
- storageUtilisationCount: items,
46508
- gratisStorage,
46509
- created: this.currentTimeslot,
46510
- lastAccumulation: tryAsTimeSlot(0),
46511
- parentService: this.currentServiceId,
46512
- }),
46513
- lookupHistory: new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([])),
46640
+ serviceInfo: newAccount,
46641
+ lookupHistory: newLookupItem,
46514
46642
  }));
46515
46643
  // update the balance of current service
46516
- // https://graypaper.fluffylabs.dev/#/7e6ff6a/364d03364d03?v=0.6.7
46517
- this.updatedState.updateServiceInfo(this.currentServiceId, ServiceAccountInfo.create({
46518
- ...currentService,
46519
- balance: numbers_tryAsU64(balanceLeftForCurrent),
46520
- }));
46644
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36ec0336ee03?v=0.7.2
46645
+ this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
46521
46646
  // update the next service id we are going to create next
46522
46647
  // https://graypaper.fluffylabs.dev/#/7e6ff6a/36a70336a703?v=0.6.7
46523
46648
  this.nextNewServiceId = this.getNextAvailableServiceId(bumpServiceId(newServiceId));
@@ -46535,9 +46660,9 @@ class AccumulateExternalities {
46535
46660
  }
46536
46661
  updateValidatorsData(validatorsData) {
46537
46662
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/362802362d02?v=0.6.7 */
46538
- const validatorsManager = this.updatedState.getPrivilegedServices().validatorsManager;
46539
- if (validatorsManager !== this.currentServiceId) {
46540
- accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${validatorsManager}) and cannot update validators data. Ignoring`;
46663
+ const currentDelegator = this.updatedState.getPrivilegedServices().delegator;
46664
+ if (currentDelegator !== this.currentServiceId) {
46665
+ accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${currentDelegator}) and cannot update validators data. Ignoring`;
46541
46666
  return result_Result.error(UnprivilegedError);
46542
46667
  }
46543
46668
  this.updatedState.stateUpdate.validatorsData = validatorsData;
@@ -46547,34 +46672,38 @@ class AccumulateExternalities {
46547
46672
  /** https://graypaper.fluffylabs.dev/#/9a08063/362202362202?v=0.6.6 */
46548
46673
  this.checkpointedState = AccumulationStateUpdate.copyFrom(this.updatedState.stateUpdate);
46549
46674
  }
46550
- updateAuthorizationQueue(coreIndex, authQueue, authManager) {
46675
+ updateAuthorizationQueue(coreIndex, authQueue, assigners) {
46551
46676
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/36a40136a401?v=0.6.7 */
46552
46677
  // NOTE `coreIndex` is already verified in the HC, so this is infallible.
46553
- const currentAuthManager = this.updatedState.getPrivilegedServices().authManager[coreIndex];
46554
- if (currentAuthManager !== this.currentServiceId) {
46555
- 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`;
46678
+ const currentAssigners = this.updatedState.getPrivilegedServices().assigners[coreIndex];
46679
+ if (currentAssigners !== this.currentServiceId) {
46680
+ accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not an auth manager of core ${coreIndex} (expected: ${currentAssigners}) and cannot update authorization queue.`;
46556
46681
  return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
46557
46682
  }
46558
- if (authManager === null && Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
46559
- accumulate_externalities_logger.trace `The new auth manager is not a valid service id. Ignoring`;
46683
+ if (assigners === null && Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
46684
+ accumulate_externalities_logger.trace `The new auth manager is not a valid service id.`;
46560
46685
  return result_Result.error(UpdatePrivilegesError.InvalidServiceId);
46561
46686
  }
46562
46687
  this.updatedState.stateUpdate.authorizationQueues.set(coreIndex, authQueue);
46563
46688
  return result_Result.ok(result_OK);
46564
46689
  }
46565
- updatePrivilegedServices(manager, authorizers, validatorsManager, autoAccumulate) {
46690
+ updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate) {
46566
46691
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/36d90036de00?v=0.6.7 */
46567
46692
  const currentManager = this.updatedState.getPrivilegedServices().manager;
46568
46693
  if (currentManager !== this.currentServiceId) {
46569
46694
  return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
46570
46695
  }
46571
- if (manager === null || validatorsManager === null) {
46572
- return result_Result.error(UpdatePrivilegesError.InvalidServiceId);
46696
+ if (manager === null || delegator === null) {
46697
+ return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Either manager or delegator is not valid service id.");
46698
+ }
46699
+ if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && registrar === null) {
46700
+ return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Register manager is not valid service id.");
46573
46701
  }
46574
46702
  this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
46575
46703
  manager,
46576
- authManager: authorizers,
46577
- validatorsManager,
46704
+ assigners: authorizers,
46705
+ delegator,
46706
+ registrar: registrar ?? tryAsServiceId(0), // introduced in 0.7.1
46578
46707
  autoAccumulateServices: autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit })),
46579
46708
  });
46580
46709
  return result_Result.ok(result_OK);
@@ -46690,8 +46819,11 @@ class AccumulateExternalities {
46690
46819
  }
46691
46820
  }
46692
46821
  function bumpServiceId(serviceId) {
46693
- const mod = 2 ** 32 - 2 ** 9;
46694
- return tryAsServiceId(2 ** 8 + ((serviceId - 2 ** 8 + 42 + mod) % mod));
46822
+ const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
46823
+ ? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
46824
+ : 2 ** 32 - 2 ** 9;
46825
+ const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
46826
+ return tryAsServiceId(offset + ((serviceId - offset + 42 + mod) % mod));
46695
46827
  }
46696
46828
 
46697
46829
  ;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-state.ts
@@ -46934,6 +47066,44 @@ function signingPayload(blake2b, anchor, blob) {
46934
47066
 
46935
47067
 
46936
47068
 
47069
+ var TransferOperandKind;
47070
+ (function (TransferOperandKind) {
47071
+ TransferOperandKind[TransferOperandKind["OPERAND"] = 0] = "OPERAND";
47072
+ TransferOperandKind[TransferOperandKind["TRANSFER"] = 1] = "TRANSFER";
47073
+ })(TransferOperandKind || (TransferOperandKind = {}));
47074
+ const TRANSFER_OR_OPERAND = descriptors_codec.custom({
47075
+ name: "TransferOrOperand",
47076
+ sizeHint: { bytes: 1, isExact: false },
47077
+ }, (e, x) => {
47078
+ e.varU32(numbers_tryAsU32(x.kind));
47079
+ if (x.kind === TransferOperandKind.OPERAND) {
47080
+ e.object(Operand.Codec, x.value);
47081
+ }
47082
+ if (x.kind === TransferOperandKind.TRANSFER) {
47083
+ e.object(PendingTransfer.Codec, x.value);
47084
+ }
47085
+ }, (d) => {
47086
+ const kind = d.varU32();
47087
+ if (kind === TransferOperandKind.OPERAND) {
47088
+ return {
47089
+ kind: TransferOperandKind.OPERAND,
47090
+ value: d.object(Operand.Codec),
47091
+ };
47092
+ }
47093
+ if (kind === TransferOperandKind.TRANSFER) {
47094
+ return { kind: TransferOperandKind.TRANSFER, value: d.object(PendingTransfer.Codec) };
47095
+ }
47096
+ throw new Error(`Unable to decode TransferOrOperand. Invalid kind: ${kind}.`);
47097
+ }, (s) => {
47098
+ const kind = s.decoder.varU32();
47099
+ if (kind === TransferOperandKind.OPERAND) {
47100
+ s.object(Operand.Codec);
47101
+ }
47102
+ if (kind === TransferOperandKind.TRANSFER) {
47103
+ s.object(PendingTransfer.Codec);
47104
+ }
47105
+ });
47106
+ const TRANSFERS_AND_OPERANDS = descriptors_codec.sequenceVarLen(TRANSFER_OR_OPERAND);
46937
47107
  // https://github.com/gavofyork/graypaper/pull/414
46938
47108
  // 0.7.0 encoding is used for prior versions as well.
46939
47109
  const CONSTANTS_CODEC = descriptors_codec.object({
@@ -47018,7 +47188,10 @@ function getEncodedConstants(chainSpec) {
47018
47188
  var FetchContext;
47019
47189
  (function (FetchContext) {
47020
47190
  FetchContext[FetchContext["Accumulate"] = 0] = "Accumulate";
47021
- FetchContext[FetchContext["OnTransfer"] = 1] = "OnTransfer";
47191
+ /** @deprecated since 0.7.1 */
47192
+ FetchContext[FetchContext["LegacyAccumulate"] = 1] = "LegacyAccumulate";
47193
+ /** @deprecated since 0.7.1 */
47194
+ FetchContext[FetchContext["LegacyOnTransfer"] = 2] = "LegacyOnTransfer";
47022
47195
  })(FetchContext || (FetchContext = {}));
47023
47196
  class FetchExternalities {
47024
47197
  fetchData;
@@ -47027,11 +47200,14 @@ class FetchExternalities {
47027
47200
  this.fetchData = fetchData;
47028
47201
  this.chainSpec = chainSpec;
47029
47202
  }
47203
+ static createForPre071Accumulate(fetchData, chainSpec) {
47204
+ return new FetchExternalities({ context: FetchContext.LegacyAccumulate, ...fetchData }, chainSpec);
47205
+ }
47030
47206
  static createForAccumulate(fetchData, chainSpec) {
47031
47207
  return new FetchExternalities({ context: FetchContext.Accumulate, ...fetchData }, chainSpec);
47032
47208
  }
47033
47209
  static createForOnTransfer(fetchData, chainSpec) {
47034
- return new FetchExternalities({ context: FetchContext.OnTransfer, ...fetchData }, chainSpec);
47210
+ return new FetchExternalities({ context: FetchContext.LegacyOnTransfer, ...fetchData }, chainSpec);
47035
47211
  }
47036
47212
  constants() {
47037
47213
  return getEncodedConstants(this.chainSpec);
@@ -47074,46 +47250,73 @@ class FetchExternalities {
47074
47250
  return null;
47075
47251
  }
47076
47252
  allOperands() {
47077
- if (this.fetchData.context !== FetchContext.Accumulate) {
47078
- return null;
47253
+ if (this.fetchData.context === FetchContext.LegacyAccumulate) {
47254
+ const operands = this.fetchData.operands;
47255
+ return encoder_Encoder.encodeObject(descriptors_codec.sequenceVarLen(Operand.Codec), operands, this.chainSpec);
47079
47256
  }
47080
- const operands = this.fetchData.operands;
47081
- return encoder_Encoder.encodeObject(descriptors_codec.sequenceVarLen(Operand.Codec), operands, this.chainSpec);
47257
+ return null;
47082
47258
  }
47083
47259
  oneOperand(operandIndex) {
47084
- if (this.fetchData.context !== FetchContext.Accumulate) {
47085
- return null;
47086
- }
47087
- const { operands } = this.fetchData;
47088
- if (operandIndex >= 2n ** 32n) {
47089
- return null;
47090
- }
47091
- const operand = operands[Number(operandIndex)];
47092
- if (operand === undefined) {
47093
- return null;
47260
+ if (this.fetchData.context === FetchContext.LegacyAccumulate) {
47261
+ const { operands } = this.fetchData;
47262
+ if (operandIndex >= 2n ** 32n) {
47263
+ return null;
47264
+ }
47265
+ const operand = operands[Number(operandIndex)];
47266
+ if (operand === undefined) {
47267
+ return null;
47268
+ }
47269
+ return encoder_Encoder.encodeObject(Operand.Codec, operand, this.chainSpec);
47094
47270
  }
47095
- return encoder_Encoder.encodeObject(Operand.Codec, operand, this.chainSpec);
47271
+ return null;
47096
47272
  }
47097
47273
  allTransfers() {
47098
- if (this.fetchData.context !== FetchContext.OnTransfer) {
47099
- return null;
47274
+ if (this.fetchData.context === FetchContext.LegacyOnTransfer) {
47275
+ const { transfers } = this.fetchData;
47276
+ return encoder_Encoder.encodeObject(descriptors_codec.sequenceVarLen(PendingTransfer.Codec), transfers, this.chainSpec);
47100
47277
  }
47101
- const { transfers } = this.fetchData;
47102
- return encoder_Encoder.encodeObject(descriptors_codec.sequenceVarLen(PendingTransfer.Codec), transfers, this.chainSpec);
47278
+ return null;
47103
47279
  }
47104
47280
  oneTransfer(transferIndex) {
47105
- if (this.fetchData.context !== FetchContext.OnTransfer) {
47106
- return null;
47281
+ if (this.fetchData.context === FetchContext.LegacyOnTransfer) {
47282
+ const { transfers } = this.fetchData;
47283
+ if (transferIndex >= 2n ** 32n) {
47284
+ return null;
47285
+ }
47286
+ const transfer = transfers[Number(transferIndex)];
47287
+ if (transfer === undefined) {
47288
+ return null;
47289
+ }
47290
+ return encoder_Encoder.encodeObject(PendingTransfer.Codec, transfer, this.chainSpec);
47107
47291
  }
47108
- const { transfers } = this.fetchData;
47109
- if (transferIndex >= 2n ** 32n) {
47110
- return null;
47292
+ return null;
47293
+ }
47294
+ allTransfersAndOperands() {
47295
+ if (this.fetchData.context === FetchContext.Accumulate) {
47296
+ const { transfers, operands } = this.fetchData;
47297
+ const transfersAndOperands = transfers
47298
+ .map((transfer) => ({ kind: TransferOperandKind.TRANSFER, value: transfer }))
47299
+ .concat(operands.map((operand) => ({ kind: TransferOperandKind.OPERAND, value: operand })));
47300
+ return encoder_Encoder.encodeObject(TRANSFERS_AND_OPERANDS, transfersAndOperands, this.chainSpec);
47111
47301
  }
47112
- const transfer = transfers[Number(transferIndex)];
47113
- if (transfer === undefined) {
47114
- return null;
47302
+ return null;
47303
+ }
47304
+ oneTransferOrOperand(index) {
47305
+ if (this.fetchData.context === FetchContext.Accumulate) {
47306
+ const { operands, transfers } = this.fetchData;
47307
+ if (index >= operands.length + transfers.length) {
47308
+ return null;
47309
+ }
47310
+ const kind = index < operands.length ? TransferOperandKind.OPERAND : TransferOperandKind.TRANSFER;
47311
+ const transferOrOperand = kind === TransferOperandKind.OPERAND
47312
+ ? { kind: TransferOperandKind.OPERAND, value: operands[Number(index)] }
47313
+ : { kind: TransferOperandKind.TRANSFER, value: transfers[Number(index) - operands.length] };
47314
+ if (transferOrOperand.value === undefined) {
47315
+ return null;
47316
+ }
47317
+ return encoder_Encoder.encodeObject(TRANSFER_OR_OPERAND, transferOrOperand, this.chainSpec);
47115
47318
  }
47116
- return encoder_Encoder.encodeObject(PendingTransfer.Codec, transfer, this.chainSpec);
47319
+ return null;
47117
47320
  }
47118
47321
  }
47119
47322
 
@@ -47146,31 +47349,45 @@ class AccumulateDataItem {
47146
47349
  */
47147
47350
  class AccumulateData {
47148
47351
  reportsDataByServiceId;
47352
+ transfersByServiceId;
47149
47353
  autoAccumulateServicesByServiceId;
47150
47354
  serviceIds;
47151
- constructor(reports, autoAccumulateServices) {
47355
+ constructor(reports, transfers, autoAccumulateServices) {
47152
47356
  const { autoAccumulateServicesByServiceId, serviceIds: serviceIdsFromAutoAccumulate } = this.transformAutoAccumulateServices(autoAccumulateServices);
47153
47357
  this.autoAccumulateServicesByServiceId = autoAccumulateServicesByServiceId;
47154
47358
  const { reportsDataByServiceId, serviceIds: serviceIdsFromReports } = this.transformReports(reports);
47155
47359
  this.reportsDataByServiceId = reportsDataByServiceId;
47360
+ const { transfersByServiceId, serviceIds: serviceIdsFromTransfers } = this.transformTransfers(transfers);
47361
+ this.transfersByServiceId = transfersByServiceId;
47156
47362
  /**
47157
- * Merge service ids from reports and auto-accumulate services.
47363
+ * Merge service ids from reports, auto-accumulate services and transfers.
47158
47364
  *
47159
47365
  * https://graypaper.fluffylabs.dev/#/68eaa1f/175f01175f01?v=0.6.4
47160
47366
  */
47161
- this.serviceIds = this.mergeServiceIds(serviceIdsFromReports, serviceIdsFromAutoAccumulate);
47367
+ this.serviceIds = this.mergeServiceIds(serviceIdsFromReports, serviceIdsFromAutoAccumulate, serviceIdsFromTransfers);
47162
47368
  }
47163
47369
  /** Merge two sets of service ids */
47164
- mergeServiceIds(source1, source2) {
47370
+ mergeServiceIds(...sources) {
47165
47371
  const merged = new Set();
47166
- for (const serviceId of source1) {
47167
- merged.add(serviceId);
47168
- }
47169
- for (const serviceId of source2) {
47170
- merged.add(serviceId);
47372
+ for (const source of sources) {
47373
+ for (const serviceId of source) {
47374
+ merged.add(serviceId);
47375
+ }
47171
47376
  }
47172
47377
  return Array.from(merged);
47173
47378
  }
47379
+ transformTransfers(transfersToTransform) {
47380
+ const transfersByServiceId = new Map();
47381
+ const serviceIds = new Set();
47382
+ for (const transfer of transfersToTransform) {
47383
+ const serviceId = transfer.destination;
47384
+ const transfers = transfersByServiceId.get(serviceId) ?? [];
47385
+ transfers.push(transfer);
47386
+ transfersByServiceId.set(serviceId, transfers);
47387
+ serviceIds.add(serviceId);
47388
+ }
47389
+ return { transfersByServiceId, serviceIds };
47390
+ }
47174
47391
  /** Transform the list of auto-accumulate services into a map by service id. */
47175
47392
  transformAutoAccumulateServices(autoAccumulateServices) {
47176
47393
  const serviceIds = new Set();
@@ -47234,6 +47451,10 @@ class AccumulateData {
47234
47451
  getOperands(serviceId) {
47235
47452
  return this.reportsDataByServiceId.get(serviceId)?.operands ?? [];
47236
47453
  }
47454
+ /** Returns the list of transfers for a given service id */
47455
+ getTransfers(serviceId) {
47456
+ return this.transfersByServiceId.get(serviceId) ?? [];
47457
+ }
47237
47458
  /** Returns the number of reports to acccumulate for a given service id */
47238
47459
  getReportsLength(serviceId) {
47239
47460
  return this.reportsDataByServiceId.get(serviceId)?.reportsLength ?? numbers_tryAsU32(0);
@@ -47258,6 +47479,8 @@ class AccumulateData {
47258
47479
 
47259
47480
 
47260
47481
 
47482
+
47483
+
47261
47484
  /**
47262
47485
  * A function that removes duplicates but does not change order - it keeps the first occurence.
47263
47486
  */
@@ -47287,7 +47510,7 @@ const NEXT_ID_CODEC = descriptors_codec.object({
47287
47510
  *
47288
47511
  * Please not that it does not call `check` function!
47289
47512
  *
47290
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/2f4c022f4c02?v=0.6.7
47513
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/2fa9042fc304?v=0.7.2
47291
47514
  */
47292
47515
  function generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blake2b) {
47293
47516
  const encoded = encoder_Encoder.encodeObject(NEXT_ID_CODEC, {
@@ -47297,7 +47520,11 @@ function generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blak
47297
47520
  }, chainSpec);
47298
47521
  const result = blake2b.hashBytes(encoded).raw.subarray(0, 4);
47299
47522
  const number = leBytesAsU32(result) >>> 0;
47300
- return tryAsServiceId((number % (2 ** 32 - 2 ** 9)) + 2 ** 8);
47523
+ const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
47524
+ ? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
47525
+ : 2 ** 32 - 2 ** 9;
47526
+ const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
47527
+ return tryAsServiceId((number % mod) + offset);
47301
47528
  }
47302
47529
 
47303
47530
  ;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-queue.ts
@@ -47709,7 +47936,7 @@ class Assign {
47709
47936
  // o
47710
47937
  const authorizationQueueStart = regs.get(8);
47711
47938
  // a
47712
- const authManager = getServiceId(regs.get(9));
47939
+ const assigners = getServiceId(regs.get(9));
47713
47940
  const res = safeAllocUint8Array(hash_HASH_SIZE * AUTHORIZATION_QUEUE_SIZE);
47714
47941
  const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
47715
47942
  // error while reading the memory.
@@ -47726,7 +47953,7 @@ class Assign {
47726
47953
  const decoder = decoder_Decoder.fromBlob(res);
47727
47954
  const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE), AUTHORIZATION_QUEUE_SIZE);
47728
47955
  const fixedSizeAuthQueue = FixedSizeArray.new(authQueue, AUTHORIZATION_QUEUE_SIZE);
47729
- const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, authManager);
47956
+ const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
47730
47957
  if (result.isOk) {
47731
47958
  regs.set(IN_OUT_REG, HostCallResult.OK);
47732
47959
  logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
@@ -47775,7 +48002,9 @@ class Bless {
47775
48002
  chainSpec;
47776
48003
  index = host_call_handler_tryAsHostCallIndex(14);
47777
48004
  basicGasCost = gas_tryAsSmallGas(10);
47778
- tracedRegisters = traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11);
48005
+ tracedRegisters = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
48006
+ ? traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11, 12)
48007
+ : traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11);
47779
48008
  constructor(currentServiceId, partialState, chainSpec) {
47780
48009
  this.currentServiceId = currentServiceId;
47781
48010
  this.partialState = partialState;
@@ -47785,14 +48014,17 @@ class Bless {
47785
48014
  // `m`: manager service (can change privileged services)
47786
48015
  const manager = getServiceId(regs.get(bless_IN_OUT_REG));
47787
48016
  // `a`: manages authorization queue
47788
- // NOTE It can be either ServiceId (pre GP 067) or memory index (GP ^067)
47789
48017
  const authorization = regs.get(8);
47790
48018
  // `v`: manages validator keys
47791
- const validator = getServiceId(regs.get(9));
48019
+ const delegator = getServiceId(regs.get(9));
48020
+ // `r`: manages creation of new services with id within protected range
48021
+ const registrar = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
48022
+ ? getServiceId(regs.get(10))
48023
+ : tryAsServiceId(2 ** 32 - 1);
47792
48024
  // `o`: memory offset
47793
- const sourceStart = regs.get(10);
48025
+ const sourceStart = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? regs.get(11) : regs.get(10);
47794
48026
  // `n`: number of items in the auto-accumulate dictionary
47795
- const numberOfItems = regs.get(11);
48027
+ const numberOfItems = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? regs.get(12) : regs.get(11);
47796
48028
  /*
47797
48029
  * `z`: array of key-value pairs serviceId -> gas that auto-accumulate every block
47798
48030
  * https://graypaper.fluffylabs.dev/#/7e6ff6a/368100368100?v=0.6.7
@@ -47806,7 +48038,7 @@ class Bless {
47806
48038
  decoder.resetTo(0);
47807
48039
  const memoryReadResult = memory.loadInto(result, memIndex);
47808
48040
  if (memoryReadResult.isError) {
47809
- logger_logger.trace `BLESS(${manager}, ${validator}) <- PANIC`;
48041
+ logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}) <- PANIC`;
47810
48042
  return PvmExecution.Panic;
47811
48043
  }
47812
48044
  const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
@@ -47819,24 +48051,25 @@ class Bless {
47819
48051
  const authorizersDecoder = decoder_Decoder.fromBlob(res);
47820
48052
  const memoryReadResult = memory.loadInto(res, authorization);
47821
48053
  if (memoryReadResult.isError) {
47822
- logger_logger.trace `BLESS(${manager}, ${validator}, ${autoAccumulateEntries}) <- PANIC`;
48054
+ logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- PANIC`;
47823
48055
  return PvmExecution.Panic;
47824
48056
  }
48057
+ // `a`
47825
48058
  const authorizers = tryAsPerCore(authorizersDecoder.sequenceFixLen(descriptors_codec.u32.asOpaque(), this.chainSpec.coresCount), this.chainSpec);
47826
- const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, validator, autoAccumulateEntries);
48059
+ const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulateEntries);
47827
48060
  if (updateResult.isOk) {
47828
- logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- OK`;
48061
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- OK`;
47829
48062
  regs.set(bless_IN_OUT_REG, HostCallResult.OK);
47830
48063
  return;
47831
48064
  }
47832
48065
  const e = updateResult.error;
47833
48066
  if (e === UpdatePrivilegesError.UnprivilegedService) {
47834
- logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- HUH`;
48067
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- HUH`;
47835
48068
  regs.set(bless_IN_OUT_REG, HostCallResult.HUH);
47836
48069
  return;
47837
48070
  }
47838
48071
  if (e === UpdatePrivilegesError.InvalidServiceId) {
47839
- logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- WHO`;
48072
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- WHO`;
47840
48073
  regs.set(bless_IN_OUT_REG, HostCallResult.WHO);
47841
48074
  return;
47842
48075
  }
@@ -48088,7 +48321,9 @@ class New {
48088
48321
  partialState;
48089
48322
  index = host_call_handler_tryAsHostCallIndex(18);
48090
48323
  basicGasCost = gas_tryAsSmallGas(10);
48091
- tracedRegisters = traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11);
48324
+ tracedRegisters = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
48325
+ ? traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11, 12)
48326
+ : traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11);
48092
48327
  constructor(currentServiceId, partialState) {
48093
48328
  this.currentServiceId = currentServiceId;
48094
48329
  this.partialState = partialState;
@@ -48104,16 +48339,18 @@ class New {
48104
48339
  const allowance = tryAsServiceGas(regs.get(10));
48105
48340
  // `f`
48106
48341
  const gratisStorage = regs.get(11);
48342
+ // `i`: requested service id. Ignored if current service is not registrar or value is bigger than `S`.
48343
+ const requestedServiceId = regs.get(12);
48107
48344
  // `c`
48108
48345
  const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
48109
48346
  const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
48110
48347
  // error while reading the memory.
48111
48348
  if (memoryReadResult.isError) {
48112
- logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- PANIC`;
48349
+ logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
48113
48350
  return PvmExecution.Panic;
48114
48351
  }
48115
- const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage);
48116
- logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- ${resultToString(assignedId)}`;
48352
+ const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage, requestedServiceId);
48353
+ logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${resultToString(assignedId)}`;
48117
48354
  if (assignedId.isOk) {
48118
48355
  regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
48119
48356
  return;
@@ -48127,6 +48364,11 @@ class New {
48127
48364
  regs.set(new_IN_OUT_REG, HostCallResult.HUH);
48128
48365
  return;
48129
48366
  }
48367
+ // Post 0.7.1
48368
+ if (e === NewServiceError.RegistrarServiceIdAlreadyTaken) {
48369
+ regs.set(new_IN_OUT_REG, HostCallResult.FULL);
48370
+ return;
48371
+ }
48130
48372
  debug_assertNever(e);
48131
48373
  }
48132
48374
  }
@@ -48496,6 +48738,7 @@ class Yield {
48496
48738
 
48497
48739
 
48498
48740
 
48741
+
48499
48742
  const fetch_IN_OUT_REG = 7;
48500
48743
  /**
48501
48744
  * https://graypaper.fluffylabs.dev/#/7e6ff6a/324000324000?v=0.6.7
@@ -48584,19 +48827,30 @@ class Fetch {
48584
48827
  const workItem = regs.get(11);
48585
48828
  return this.fetch.workItemPayload(workItem);
48586
48829
  }
48587
- if (kind === FetchKind.AllOperands) {
48588
- return this.fetch.allOperands();
48589
- }
48590
- if (kind === FetchKind.OneOperand) {
48591
- const index = regs.get(11);
48592
- return this.fetch.oneOperand(index);
48593
- }
48594
- if (kind === FetchKind.AllTransfers) {
48595
- return this.fetch.allTransfers();
48830
+ if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
48831
+ if (kind === FetchKind.AllTransfersAndOperands) {
48832
+ return this.fetch.allTransfersAndOperands();
48833
+ }
48834
+ if (kind === FetchKind.OneTransferOrOperand) {
48835
+ const index = regs.get(11);
48836
+ return this.fetch.oneTransferOrOperand(index);
48837
+ }
48596
48838
  }
48597
- if (kind === FetchKind.OneTransfer) {
48598
- const index = regs.get(11);
48599
- return this.fetch.oneTransfer(index);
48839
+ else {
48840
+ if (kind === FetchKind.LegacyAllOperands) {
48841
+ return this.fetch.allOperands();
48842
+ }
48843
+ if (kind === FetchKind.LegacyOneOperand) {
48844
+ const index = regs.get(11);
48845
+ return this.fetch.oneOperand(index);
48846
+ }
48847
+ if (kind === FetchKind.LegacyAllTransfers) {
48848
+ return this.fetch.allTransfers();
48849
+ }
48850
+ if (kind === FetchKind.LegacyOneTransfer) {
48851
+ const index = regs.get(11);
48852
+ return this.fetch.oneTransfer(index);
48853
+ }
48600
48854
  }
48601
48855
  return null;
48602
48856
  }
@@ -48617,10 +48871,12 @@ var FetchKind;
48617
48871
  FetchKind[FetchKind["AllWorkItems"] = 11] = "AllWorkItems";
48618
48872
  FetchKind[FetchKind["OneWorkItem"] = 12] = "OneWorkItem";
48619
48873
  FetchKind[FetchKind["WorkItemPayload"] = 13] = "WorkItemPayload";
48620
- FetchKind[FetchKind["AllOperands"] = 14] = "AllOperands";
48621
- FetchKind[FetchKind["OneOperand"] = 15] = "OneOperand";
48622
- FetchKind[FetchKind["AllTransfers"] = 16] = "AllTransfers";
48623
- FetchKind[FetchKind["OneTransfer"] = 17] = "OneTransfer";
48874
+ FetchKind[FetchKind["LegacyAllOperands"] = 14] = "LegacyAllOperands";
48875
+ FetchKind[FetchKind["AllTransfersAndOperands"] = 14] = "AllTransfersAndOperands";
48876
+ FetchKind[FetchKind["LegacyOneOperand"] = 15] = "LegacyOneOperand";
48877
+ FetchKind[FetchKind["OneTransferOrOperand"] = 15] = "OneTransferOrOperand";
48878
+ FetchKind[FetchKind["LegacyAllTransfers"] = 16] = "LegacyAllTransfers";
48879
+ FetchKind[FetchKind["LegacyOneTransfer"] = 17] = "LegacyOneTransfer";
48624
48880
  })(FetchKind || (FetchKind = {}));
48625
48881
 
48626
48882
  ;// CONCATENATED MODULE: ./packages/jam/jam-host-calls/info.ts
@@ -49317,7 +49573,7 @@ const accumulate_logger = Logger.new(import.meta.filename, "accumulate");
49317
49573
  const ARGS_CODEC = descriptors_codec.object({
49318
49574
  slot: descriptors_codec.varU32.asOpaque(),
49319
49575
  serviceId: descriptors_codec.varU32.asOpaque(),
49320
- operands: descriptors_codec.varU32,
49576
+ argsLength: descriptors_codec.varU32,
49321
49577
  });
49322
49578
  class Accumulate {
49323
49579
  chainSpec;
@@ -49337,7 +49593,7 @@ class Accumulate {
49337
49593
  const reportsLength = reports.length;
49338
49594
  let currentGas = 0n;
49339
49595
  for (let i = 0; i < reportsLength; i++) {
49340
- const report = reports[i];
49596
+ const report = reports.get(i);
49341
49597
  const resultsGas = report.results.map((result) => result.gas).reduce((a, b) => a + b, 0n);
49342
49598
  if (currentGas + resultsGas > gasLimit) {
49343
49599
  return i;
@@ -49351,7 +49607,7 @@ class Accumulate {
49351
49607
  *
49352
49608
  * https://graypaper.fluffylabs.dev/#/7e6ff6a/2fdb012fdb01?v=0.6.7
49353
49609
  */
49354
- async pvmAccumulateInvocation(slot, serviceId, operands, gas, entropy, inputStateUpdate) {
49610
+ async pvmAccumulateInvocation(slot, serviceId, transfers, operands, gas, entropy, inputStateUpdate) {
49355
49611
  const service = this.state.getService(serviceId);
49356
49612
  if (service === null) {
49357
49613
  accumulate_logger.log `Service with id ${serviceId} not found.`;
@@ -49370,14 +49626,21 @@ class Accumulate {
49370
49626
  }
49371
49627
  const nextServiceId = generateNextServiceId({ serviceId, entropy, timeslot: slot }, this.chainSpec, this.blake2b);
49372
49628
  const partialState = new AccumulateExternalities(this.chainSpec, this.blake2b, new PartiallyUpdatedState(this.state, inputStateUpdate), serviceId, nextServiceId, slot);
49629
+ const fetchExternalities = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
49630
+ ? FetchExternalities.createForAccumulate({ entropy, transfers, operands }, this.chainSpec)
49631
+ : FetchExternalities.createForPre071Accumulate({ entropy, operands }, this.chainSpec);
49373
49632
  const externalities = {
49374
49633
  partialState,
49375
49634
  serviceExternalities: partialState,
49376
- fetchExternalities: FetchExternalities.createForAccumulate({ entropy, operands }, this.chainSpec),
49635
+ fetchExternalities,
49377
49636
  };
49378
49637
  const executor = PvmExecutor.createAccumulateExecutor(serviceId, code, externalities, this.chainSpec);
49379
- const args = encoder_Encoder.encodeObject(ARGS_CODEC, { slot, serviceId, operands: numbers_tryAsU32(operands.length) });
49380
- const result = await executor.run(args, tryAsGas(gas));
49638
+ const invocationArgs = encoder_Encoder.encodeObject(ARGS_CODEC, {
49639
+ slot,
49640
+ serviceId,
49641
+ argsLength: numbers_tryAsU32(transfers.length + operands.length),
49642
+ });
49643
+ const result = await executor.run(invocationArgs, tryAsGas(gas));
49381
49644
  const [newState, checkpoint] = partialState.getStateUpdates();
49382
49645
  /**
49383
49646
  * PVM invocation returned and error so we return the checkpoint
@@ -49414,9 +49677,9 @@ class Accumulate {
49414
49677
  *
49415
49678
  * https://graypaper.fluffylabs.dev/#/7e6ff6a/18d70118d701?v=0.6.7
49416
49679
  */
49417
- async accumulateSingleService(serviceId, operands, gasCost, slot, entropy, inputStateUpdate) {
49418
- accumulate_logger.log `Accumulating service ${serviceId}, items: ${operands.length} at slot: ${slot}.`;
49419
- const result = await this.pvmAccumulateInvocation(slot, serviceId, operands, gasCost, entropy, inputStateUpdate);
49680
+ async accumulateSingleService(serviceId, transfers, operands, gasCost, slot, entropy, inputStateUpdate) {
49681
+ accumulate_logger.log `Accumulating service ${serviceId}, transfers: ${transfers.length} operands: ${operands.length} at slot: ${slot}.`;
49682
+ const result = await this.pvmAccumulateInvocation(slot, serviceId, transfers, operands, gasCost, entropy, inputStateUpdate);
49420
49683
  if (result.isError) {
49421
49684
  // https://graypaper.fluffylabs.dev/#/7e6ff6a/2fb6012fb601?v=0.6.7
49422
49685
  accumulate_logger.log `Accumulation failed for ${serviceId}.`;
@@ -49433,7 +49696,7 @@ class Accumulate {
49433
49696
  *
49434
49697
  * https://graypaper.fluffylabs.dev/#/7e6ff6a/179d00179d00?v=0.6.7
49435
49698
  */
49436
- async accumulateSequentially(gasLimit, reports, slot, entropy, statistics, stateUpdate) {
49699
+ async accumulateSequentiallyLegacy(gasLimit, reports, slot, entropy, statistics, stateUpdate, autoAccumulateServices) {
49437
49700
  const i = this.findReportCutoffIndex(gasLimit, reports);
49438
49701
  if (i === 0) {
49439
49702
  return {
@@ -49442,14 +49705,46 @@ class Accumulate {
49442
49705
  state: stateUpdate,
49443
49706
  };
49444
49707
  }
49445
- const reportsToAccumulateInParallel = reports.slice(0, i);
49446
- const autoAccumulateServices = this.state.privilegedServices.autoAccumulateServices;
49447
- const accumulateData = new AccumulateData(reportsToAccumulateInParallel, autoAccumulateServices);
49448
- const reportsToAccumulateSequentially = reports.slice(i);
49708
+ const reportsToAccumulateInParallel = reports.subview(0, i);
49709
+ const accumulateData = new AccumulateData(reportsToAccumulateInParallel, [], autoAccumulateServices);
49710
+ const reportsToAccumulateSequentially = reports.subview(i);
49711
+ const { gasCost, state: stateAfterParallelAcc, ...rest } = await this.accumulateInParallel(accumulateData, slot, entropy, statistics, stateUpdate);
49712
+ assertEmpty(rest);
49713
+ // NOTE [ToDr] recursive invocation
49714
+ const { accumulatedReports, gasCost: seqGasCost, state, ...seqRest } = await this.accumulateSequentiallyLegacy(tryAsServiceGas(gasLimit - gasCost), reportsToAccumulateSequentially, slot, entropy, statistics, stateAfterParallelAcc, []);
49715
+ assertEmpty(seqRest);
49716
+ return {
49717
+ accumulatedReports: numbers_tryAsU32(i + accumulatedReports),
49718
+ gasCost: tryAsServiceGas(gasCost + seqGasCost),
49719
+ state,
49720
+ };
49721
+ }
49722
+ /**
49723
+ * The outer accumulation function ∆+ which transforms a gas-limit, a sequence of work-reports,
49724
+ * an initial partial-state and a dictionary of services enjoying free accumulation,
49725
+ * into a tuple of the number of work-results accumulated, a posterior state-context,
49726
+ * the resultant deferred-transfers and accumulation-output pairing.
49727
+ *
49728
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/172901172901?v=0.7.2
49729
+ */
49730
+ async accumulateSequentially(gasLimit, reports, transfers, slot, entropy, statistics, stateUpdate, autoAccumulateServices) {
49731
+ const i = this.findReportCutoffIndex(gasLimit, reports);
49732
+ const n = transfers.length + i + reports.length;
49733
+ if (n === 0) {
49734
+ return {
49735
+ accumulatedReports: numbers_tryAsU32(0),
49736
+ gasCost: tryAsServiceGas(0),
49737
+ state: stateUpdate,
49738
+ };
49739
+ }
49740
+ const reportsToAccumulateInParallel = reports.subview(0, i);
49741
+ const accumulateData = new AccumulateData(reportsToAccumulateInParallel, transfers, autoAccumulateServices);
49742
+ const reportsToAccumulateSequentially = reports.subview(i);
49449
49743
  const { gasCost, state: stateAfterParallelAcc, ...rest } = await this.accumulateInParallel(accumulateData, slot, entropy, statistics, stateUpdate);
49744
+ const newTransfers = stateAfterParallelAcc.transfers;
49450
49745
  assertEmpty(rest);
49451
49746
  // NOTE [ToDr] recursive invocation
49452
- const { accumulatedReports, gasCost: seqGasCost, state, ...seqRest } = await this.accumulateSequentially(tryAsServiceGas(gasLimit - gasCost), reportsToAccumulateSequentially, slot, entropy, statistics, stateAfterParallelAcc);
49747
+ const { accumulatedReports, gasCost: seqGasCost, state, ...seqRest } = await this.accumulateSequentially(tryAsServiceGas(gasLimit - gasCost), reportsToAccumulateSequentially, newTransfers, slot, entropy, statistics, stateAfterParallelAcc, []);
49453
49748
  assertEmpty(seqRest);
49454
49749
  return {
49455
49750
  accumulatedReports: numbers_tryAsU32(i + accumulatedReports),
@@ -49465,7 +49760,7 @@ class Accumulate {
49465
49760
  * into a tuple of the total gas utilized in pvm execution u, a posterior state-context
49466
49761
  * and the resultant accumulation-output pairings b and deferred-transfers.
49467
49762
  *
49468
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/175501175501?v=0.6.7
49763
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/174602174602?v=0.7.2
49469
49764
  */
49470
49765
  async accumulateInParallel(accumulateData, slot, entropy, statistics, inputStateUpdate) {
49471
49766
  const serviceIds = accumulateData.getServiceIds();
@@ -49474,7 +49769,7 @@ class Accumulate {
49474
49769
  const currentManager = (inputStateUpdate.privilegedServices ?? this.state.privilegedServices).manager;
49475
49770
  for (const serviceId of serviceIds) {
49476
49771
  const checkpoint = AccumulationStateUpdate.copyFrom(currentState);
49477
- const { consumedGas, stateUpdate } = await this.accumulateSingleService(serviceId, accumulateData.getOperands(serviceId), accumulateData.getGasCost(serviceId), slot, entropy, currentState);
49772
+ const { consumedGas, stateUpdate } = await this.accumulateSingleService(serviceId, accumulateData.getTransfers(serviceId), accumulateData.getOperands(serviceId), accumulateData.getGasCost(serviceId), slot, entropy, currentState);
49478
49773
  gasCost = tryAsServiceGas(gasCost + consumedGas);
49479
49774
  const serviceStatistics = statistics.get(serviceId) ?? { count: numbers_tryAsU32(0), gasUsed: tryAsServiceGas(0) };
49480
49775
  serviceStatistics.count = numbers_tryAsU32(serviceStatistics.count + accumulateData.getReportsLength(serviceId));
@@ -49482,17 +49777,17 @@ class Accumulate {
49482
49777
  statistics.set(serviceId, serviceStatistics);
49483
49778
  currentState = stateUpdate === null ? checkpoint : stateUpdate;
49484
49779
  if (Compatibility.is(GpVersion.V0_7_0) && serviceId === currentManager) {
49485
- const newV = currentState.privilegedServices?.validatorsManager;
49780
+ const newV = currentState.privilegedServices?.delegator;
49486
49781
  if (currentState.privilegedServices !== null && newV !== undefined && serviceIds.includes(newV)) {
49487
- 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+`;
49782
+ 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+`;
49488
49783
  // Since serviceIds already contains newV, this service gets accumulated twice.
49489
49784
  // To avoid double-counting, we skip stats and gas cost tracking here.
49490
- // We need this accumulation to get the correct `validatorsManager`
49491
- const { stateUpdate } = await this.accumulateSingleService(newV, accumulateData.getOperands(newV), accumulateData.getGasCost(newV), slot, entropy, checkpoint);
49492
- const correctV = stateUpdate?.privilegedServices?.validatorsManager ?? this.state.privilegedServices.validatorsManager;
49785
+ // We need this accumulation to get the correct `delegator`
49786
+ const { stateUpdate } = await this.accumulateSingleService(newV, [], accumulateData.getOperands(newV), accumulateData.getGasCost(newV), slot, entropy, checkpoint);
49787
+ const correctV = stateUpdate?.privilegedServices?.delegator ?? this.state.privilegedServices.delegator;
49493
49788
  currentState.privilegedServices = PrivilegedServices.create({
49494
49789
  ...currentState.privilegedServices,
49495
- validatorsManager: correctV,
49790
+ delegator: correctV,
49496
49791
  });
49497
49792
  }
49498
49793
  }
@@ -49548,7 +49843,7 @@ class Accumulate {
49548
49843
  *
49549
49844
  * Please note it cannot overflow because we use `BigInt`, and the final result is clamped to `maxBlockGas` (W_G).
49550
49845
  *
49551
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/18f40118f401?v=0.6.7
49846
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/183402184502?v=0.7.2
49552
49847
  */
49553
49848
  getGasLimit() {
49554
49849
  const calculatedGasLimit = GAS_TO_INVOKE_WORK_REPORT * BigInt(this.chainSpec.coresCount) +
@@ -49556,6 +49851,20 @@ class Accumulate {
49556
49851
  const gasLimit = tryAsServiceGas(this.chainSpec.maxBlockGas > calculatedGasLimit ? this.chainSpec.maxBlockGas : calculatedGasLimit);
49557
49852
  return tryAsServiceGas(gasLimit);
49558
49853
  }
49854
+ hasDuplicatedServicesCreated(updateServices) {
49855
+ const createdServiceIds = new Set();
49856
+ for (const update of updateServices) {
49857
+ if (update.action.kind === UpdateServiceKind.Create) {
49858
+ const serviceId = update.serviceId;
49859
+ if (createdServiceIds.has(serviceId)) {
49860
+ accumulate_logger.log `Duplicated Service creation detected ${serviceId}. Block is invalid.`;
49861
+ return true;
49862
+ }
49863
+ createdServiceIds.add(serviceId);
49864
+ }
49865
+ }
49866
+ return false;
49867
+ }
49559
49868
  async transition({ reports, slot, entropy }) {
49560
49869
  const statistics = new Map();
49561
49870
  const accumulateQueue = new AccumulateQueue(this.chainSpec, this.state);
@@ -49564,16 +49873,22 @@ class Accumulate {
49564
49873
  const queueFromState = accumulateQueue.getQueueFromState(slot);
49565
49874
  const toEnqueue = pruneQueue(queueFromState.concat(toAccumulateLater), getWorkPackageHashes(toAccumulateImmediately));
49566
49875
  const queue = accumulateQueue.enqueueReports(toEnqueue);
49567
- const accumulatableReports = toAccumulateImmediately.concat(queue);
49876
+ const accumulatableReports = ArrayView.from(toAccumulateImmediately.concat(queue));
49568
49877
  const gasLimit = this.getGasLimit();
49569
- const { accumulatedReports, gasCost, state, ...rest } = await this.accumulateSequentially(gasLimit, accumulatableReports, slot, entropy, statistics, AccumulationStateUpdate.empty());
49878
+ const autoAccumulateServices = this.state.privilegedServices.autoAccumulateServices;
49879
+ const { accumulatedReports, gasCost, state, ...rest } = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
49880
+ ? await this.accumulateSequentially(gasLimit, accumulatableReports, [], slot, entropy, statistics, AccumulationStateUpdate.empty(), autoAccumulateServices)
49881
+ : await this.accumulateSequentiallyLegacy(gasLimit, accumulatableReports, slot, entropy, statistics, AccumulationStateUpdate.empty(), autoAccumulateServices);
49570
49882
  // we can safely ignore top-level gas cost from accSequentially.
49571
49883
  const _gasCost = gasCost;
49572
49884
  assertEmpty(rest);
49573
- const accumulated = accumulatableReports.slice(0, accumulatedReports);
49885
+ const accumulated = accumulatableReports.subview(0, accumulatedReports);
49574
49886
  const { services, yieldedRoots, transfers, validatorsData, privilegedServices, authorizationQueues, ...stateUpdateRest } = state;
49575
49887
  assertEmpty(stateUpdateRest);
49576
- const accStateUpdate = this.getAccumulationStateUpdate(accumulated, toAccumulateLater, slot, Array.from(statistics.keys()), services);
49888
+ if (this.hasDuplicatedServicesCreated(services.servicesUpdates)) {
49889
+ return result_Result.error(ACCUMULATION_ERROR);
49890
+ }
49891
+ const accStateUpdate = this.getAccumulationStateUpdate(accumulated.toArray(), toAccumulateLater, slot, Array.from(statistics.keys()), services);
49577
49892
  const accumulationOutputUnsorted = Array.from(yieldedRoots.entries()).map(([serviceId, root]) => {
49578
49893
  return { serviceId, output: root.asOpaque() };
49579
49894
  });
@@ -51205,18 +51520,24 @@ class OnChain {
51205
51520
  }
51206
51521
  const { stateUpdate: accumulateUpdate, accumulationStatistics, pendingTransfers, accumulationOutputLog, ...accumulateRest } = accumulateResult.ok;
51207
51522
  assertEmpty(accumulateRest);
51208
- const { privilegedServices: maybePrivilegedServices, authQueues: maybeAuthorizationQueues, designatedValidatorData: maybeDesignatedValidatorData, preimages: accumulatePreimages, accumulationQueue, recentlyAccumulated, ...servicesUpdate } = accumulateUpdate;
51209
- const deferredTransfersResult = await this.deferredTransfers.transition({
51210
- entropy: entropy[0],
51211
- pendingTransfers,
51212
- servicesUpdate: { ...servicesUpdate, preimages: accumulatePreimages },
51213
- timeslot: timeSlot,
51214
- });
51215
- if (deferredTransfersResult.isError) {
51216
- return stfError(StfErrorKind.DeferredTransfers, deferredTransfersResult);
51523
+ const { privilegedServices: maybePrivilegedServices, authQueues: maybeAuthorizationQueues, designatedValidatorData: maybeDesignatedValidatorData, preimages: accumulatePreimages, accumulationQueue, recentlyAccumulated, ...servicesUpdateFromAccumulate } = accumulateUpdate;
51524
+ let transferStatistics = new Map();
51525
+ let servicesUpdate = { ...servicesUpdateFromAccumulate, preimages: accumulatePreimages };
51526
+ if (Compatibility.isLessThan(GpVersion.V0_7_1)) {
51527
+ const deferredTransfersResult = await this.deferredTransfers.transition({
51528
+ entropy: entropy[0],
51529
+ pendingTransfers,
51530
+ servicesUpdate,
51531
+ timeslot: timeSlot,
51532
+ });
51533
+ if (deferredTransfersResult.isError) {
51534
+ return stfError(StfErrorKind.DeferredTransfers, deferredTransfersResult);
51535
+ }
51536
+ const { servicesUpdate: servicesUpdateFromDeferredTransfers, transferStatistics: transferStatisticsFromDeferredTransfers, ...deferredTransfersRest } = deferredTransfersResult.ok;
51537
+ transferStatistics = transferStatisticsFromDeferredTransfers;
51538
+ servicesUpdate = servicesUpdateFromDeferredTransfers;
51539
+ assertEmpty(deferredTransfersRest);
51217
51540
  }
51218
- const { servicesUpdate: newServicesUpdate, transferStatistics, ...deferredTransfersRest } = deferredTransfersResult.ok;
51219
- assertEmpty(deferredTransfersRest);
51220
51541
  const accumulateRoot = await this.accumulateOutput.transition({ accumulationOutputLog });
51221
51542
  // recent history
51222
51543
  const recentHistoryUpdate = this.recentHistory.transition({
@@ -51266,7 +51587,7 @@ class OnChain {
51266
51587
  accumulationQueue,
51267
51588
  recentlyAccumulated,
51268
51589
  accumulationOutputLog,
51269
- ...newServicesUpdate,
51590
+ ...servicesUpdate,
51270
51591
  preimages: preimages.concat(accumulatePreimages),
51271
51592
  });
51272
51593
  }