@typeberry/jam 0.1.3-8258907 → 0.1.3-a6eda68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -25782,7 +25782,7 @@ class Skipper {
25782
25782
  *
25783
25783
  * Descriptors can be composed to form more complex typings.
25784
25784
  */
25785
- class descriptor_Descriptor {
25785
+ class Descriptor {
25786
25786
  name;
25787
25787
  sizeHint;
25788
25788
  encode;
@@ -25792,11 +25792,11 @@ class descriptor_Descriptor {
25792
25792
  View;
25793
25793
  /** New descriptor with specialized `View`. */
25794
25794
  static withView(name, sizeHint, encode, decode, skip, view) {
25795
- return new descriptor_Descriptor(name, sizeHint, encode, decode, skip, view);
25795
+ return new Descriptor(name, sizeHint, encode, decode, skip, view);
25796
25796
  }
25797
25797
  /** Create a new descriptor without a specialized `View`. */
25798
25798
  static new(name, sizeHint, encode, decode, skip) {
25799
- return new descriptor_Descriptor(name, sizeHint, encode, decode, skip, null);
25799
+ return new Descriptor(name, sizeHint, encode, decode, skip, null);
25800
25800
  }
25801
25801
  constructor(
25802
25802
  /** Descriptive name of the coded data. */
@@ -25833,7 +25833,7 @@ class descriptor_Descriptor {
25833
25833
  }
25834
25834
  /** Return a new descriptor that converts data into some other type. */
25835
25835
  convert(input, output) {
25836
- 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);
25837
25837
  }
25838
25838
  /** Safely cast the descriptor value to a opaque type. */
25839
25839
  asOpaque() {
@@ -26531,51 +26531,51 @@ var descriptors_codec;
26531
26531
  return (len) => {
26532
26532
  let ret = cache.get(len);
26533
26533
  if (ret === undefined) {
26534
- 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));
26535
26535
  cache.set(len, ret);
26536
26536
  }
26537
26537
  return ret;
26538
26538
  };
26539
26539
  })();
26540
26540
  /** Variable-length U32. */
26541
- 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());
26542
26542
  /** Variable-length U64. */
26543
- 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());
26544
26544
  /** Unsigned 64-bit number. */
26545
- 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));
26546
26546
  /** Unsigned 32-bit number. */
26547
- 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));
26548
26548
  /** Unsigned 24-bit number. */
26549
- 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));
26550
26550
  /** Unsigned 16-bit number. */
26551
- 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));
26552
26552
  /** Unsigned 8-bit number. */
26553
- 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());
26554
26554
  /** Signed 64-bit number. */
26555
- 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));
26556
26556
  /** Signed 32-bit number. */
26557
- 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));
26558
26558
  /** Signed 24-bit number. */
26559
- 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));
26560
26560
  /** Signed 16-bit number. */
26561
- 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));
26562
26562
  /** Signed 8-bit number. */
26563
- 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());
26564
26564
  /** 1-byte boolean value. */
26565
- 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());
26566
26566
  /** Variable-length bytes blob. */
26567
- 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());
26568
26568
  /** String encoded as variable-length bytes blob. */
26569
- 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);
26570
26570
  /** Variable-length bit vector. */
26571
- 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());
26572
26572
  /** Fixed-length bit vector. */
26573
- 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));
26574
26574
  /** Optionality wrapper for given type. */
26575
26575
  codec.optional = (type) => {
26576
- 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));
26577
26577
  if (hasUniqueView(type)) {
26578
- 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));
26579
26579
  }
26580
26580
  return self;
26581
26581
  };
@@ -26586,7 +26586,7 @@ var descriptors_codec;
26586
26586
  }) => {
26587
26587
  const name = `Sequence<${type.name}>[?]`;
26588
26588
  const typicalLength = options.typicalLength ?? TYPICAL_SEQUENCE_LENGTH;
26589
- 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) => {
26590
26590
  validateLength(options, v.length, name);
26591
26591
  e.sequenceVarLen(type, v);
26592
26592
  }, (d) => {
@@ -26600,10 +26600,10 @@ var descriptors_codec;
26600
26600
  }, sequenceViewVarLen(type, options));
26601
26601
  };
26602
26602
  /** Fixed-length sequence of given type. */
26603
- 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 }));
26604
26604
  /** Small dictionary codec. */
26605
26605
  codec.dictionary = (key, value, { sortKeys, fixedLength, }) => {
26606
- const self = descriptor_Descriptor.new(`Dictionary<${key.name}, ${value.name}>[${fixedLength ?? "?"}]`, {
26606
+ const self = Descriptor.new(`Dictionary<${key.name}, ${value.name}>[${fixedLength ?? "?"}]`, {
26607
26607
  bytes: fixedLength !== undefined
26608
26608
  ? fixedLength * addSizeHints(key.sizeHint, value.sizeHint).bytes
26609
26609
  : TYPICAL_DICTIONARY_LENGTH * (addSizeHints(key.sizeHint, value.sizeHint).bytes ?? 0),
@@ -26642,13 +26642,13 @@ var descriptors_codec;
26642
26642
  s.sequenceFixLen(value, len);
26643
26643
  });
26644
26644
  if (hasUniqueView(value)) {
26645
- 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 }));
26646
26646
  }
26647
26647
  return self;
26648
26648
  };
26649
26649
  /** Encoding of pair of two values. */
26650
26650
  codec.pair = (a, b) => {
26651
- 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) => {
26652
26652
  a.encode(e, elem[0]);
26653
26653
  b.encode(e, elem[1]);
26654
26654
  }, (d) => {
@@ -26660,14 +26660,14 @@ var descriptors_codec;
26660
26660
  b.skip(s);
26661
26661
  });
26662
26662
  if (hasUniqueView(a) && hasUniqueView(b)) {
26663
- 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));
26664
26664
  }
26665
26665
  return self;
26666
26666
  };
26667
26667
  /** Custom encoding / decoding logic. */
26668
- 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);
26669
26669
  /** Choose a descriptor depending on the encoding/decoding context. */
26670
- 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);
26671
26671
  /**
26672
26672
  * A descriptor for a more complex POJO.
26673
26673
  *
@@ -26704,7 +26704,7 @@ var descriptors_codec;
26704
26704
  };
26705
26705
  const view = objectView(Class, descriptors, sizeHint, skipper);
26706
26706
  // and create the descriptor for the entire class.
26707
- return descriptor_Descriptor.withView(Class.name, sizeHint, (e, t) => {
26707
+ return Descriptor.withView(Class.name, sizeHint, (e, t) => {
26708
26708
  forEachDescriptor(descriptors, (key, descriptor) => {
26709
26709
  const value = t[key];
26710
26710
  descriptor.encode(e, value);
@@ -26755,7 +26755,7 @@ function objectView(Class, descriptors, sizeHint, skipper) {
26755
26755
  });
26756
26756
  }
26757
26757
  });
26758
- return descriptor_Descriptor.new(`View<${Class.name}>`, sizeHint, (e, t) => {
26758
+ return Descriptor.new(`View<${Class.name}>`, sizeHint, (e, t) => {
26759
26759
  const encoded = t.encoded();
26760
26760
  e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
26761
26761
  }, (d) => {
@@ -26774,7 +26774,7 @@ function sequenceViewVarLen(type, options) {
26774
26774
  validateLength(options, length, name);
26775
26775
  return s.sequenceFixLen(type, length);
26776
26776
  };
26777
- return descriptor_Descriptor.new(name, sizeHint, (e, t) => {
26777
+ return Descriptor.new(name, sizeHint, (e, t) => {
26778
26778
  validateLength(options, t.length, name);
26779
26779
  const encoded = t.encoded();
26780
26780
  e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
@@ -26790,7 +26790,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
26790
26790
  const skipper = (s) => s.sequenceFixLen(type, fixedLength);
26791
26791
  const view = type.name !== type.View.name ? `, ${type.View.name}` : "";
26792
26792
  const name = `SeqView<${type.name}${view}>[${fixedLength}]`;
26793
- return descriptor_Descriptor.new(name, sizeHint, (e, t) => {
26793
+ return Descriptor.new(name, sizeHint, (e, t) => {
26794
26794
  const encoded = t.encoded();
26795
26795
  e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
26796
26796
  }, (d) => {
@@ -29091,7 +29091,7 @@ const codecFixedSizeArray = (val, len) => {
29091
29091
  };
29092
29092
  /** Codec for a hash-dictionary. */
29093
29093
  const codecHashDictionary = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH, compare = (a, b) => extractKey(a).compare(extractKey(b)), } = {}) => {
29094
- return descriptor_Descriptor.new(`HashDictionary<${value.name}>[?]`, {
29094
+ return Descriptor.new(`HashDictionary<${value.name}>[?]`, {
29095
29095
  bytes: typicalLength * value.sizeHint.bytes,
29096
29096
  isExact: false,
29097
29097
  }, (e, v) => {
@@ -32154,6 +32154,13 @@ const W_T = 128;
32154
32154
  /** `W_M`: The maximum number of exports in a work-package. */
32155
32155
  const W_X = 3_072;
32156
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;
32157
32164
  /**
32158
32165
  * `J`: The maximum sum of dependency items in a work-report.
32159
32166
  *
@@ -32165,9 +32172,209 @@ const AUTHORIZATION_QUEUE_SIZE = Q;
32165
32172
  /** `O`: Maximal authorization pool size. */
32166
32173
  const MAX_AUTH_POOL_SIZE = O;
32167
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
+
32168
32372
  ;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
32169
32373
 
32170
32374
 
32375
+
32376
+
32377
+
32171
32378
  /** Dictionary entry of services that auto-accumulate every block. */
32172
32379
  class AutoAccumulate {
32173
32380
  service;
@@ -32189,39 +32396,50 @@ class AutoAccumulate {
32189
32396
  }
32190
32397
  }
32191
32398
  /**
32192
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11da0111da01?v=0.6.7
32399
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
32193
32400
  */
32194
32401
  class PrivilegedServices {
32195
32402
  manager;
32196
- authManager;
32197
- validatorsManager;
32403
+ delegator;
32404
+ registrar;
32405
+ assigners;
32198
32406
  autoAccumulateServices;
32407
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
32199
32408
  static Codec = descriptors_codec.Class(PrivilegedServices, {
32200
32409
  manager: descriptors_codec.u32.asOpaque(),
32201
- authManager: codecPerCore(descriptors_codec.u32.asOpaque()),
32202
- 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)),
32203
32415
  autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
32204
32416
  });
32205
- static create({ manager, authManager, validatorsManager, autoAccumulateServices }) {
32206
- 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);
32207
32419
  }
32208
32420
  constructor(
32209
32421
  /**
32210
- * `chi_m`: The first, χm, is the index of the manager service which is
32211
- * the service able to effect an alteration of χ from block to block,
32422
+ * `χ_M`: Manages alteration of χ from block to block,
32212
32423
  * as well as bestow services with storage deposit credits.
32213
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11a40111a801?v=0.6.7
32424
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
32214
32425
  */
32215
32426
  manager,
32216
- /** `chi_a`: Manages authorization queue one for each core. */
32217
- authManager,
32218
- /** `chi_v`: Managers validator keys. */
32219
- validatorsManager,
32220
- /** `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. */
32221
32438
  autoAccumulateServices) {
32222
32439
  this.manager = manager;
32223
- this.authManager = authManager;
32224
- this.validatorsManager = validatorsManager;
32440
+ this.delegator = delegator;
32441
+ this.registrar = registrar;
32442
+ this.assigners = assigners;
32225
32443
  this.autoAccumulateServices = autoAccumulateServices;
32226
32444
  }
32227
32445
  }
@@ -32309,7 +32527,7 @@ class RecentBlocks extends WithDebug {
32309
32527
  */
32310
32528
  class RecentBlocksHistory extends WithDebug {
32311
32529
  current;
32312
- 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) => {
32313
32531
  const recentBlocks = RecentBlocks.Codec.decode(decoder);
32314
32532
  return RecentBlocksHistory.create(recentBlocks);
32315
32533
  }, (skip) => {
@@ -32506,196 +32724,6 @@ class SafroleData {
32506
32724
  }
32507
32725
  }
32508
32726
 
32509
- ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
32510
-
32511
-
32512
-
32513
-
32514
-
32515
-
32516
- /**
32517
- * `B_S`: The basic minimum balance which all services require.
32518
- *
32519
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
32520
- */
32521
- const BASE_SERVICE_BALANCE = 100n;
32522
- /**
32523
- * `B_I`: The additional minimum balance required per item of elective service state.
32524
- *
32525
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
32526
- */
32527
- const ELECTIVE_ITEM_BALANCE = 10n;
32528
- /**
32529
- * `B_L`: The additional minimum balance required per octet of elective service state.
32530
- *
32531
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
32532
- */
32533
- const ELECTIVE_BYTE_BALANCE = 1n;
32534
- const zeroSizeHint = {
32535
- bytes: 0,
32536
- isExact: true,
32537
- };
32538
- /** 0-byte read, return given default value */
32539
- const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
32540
- /** Encode and decode object with leading version number. */
32541
- const codecWithVersion = (val) => descriptor_Descriptor.new("withVersion", {
32542
- bytes: val.sizeHint.bytes + 8,
32543
- isExact: false,
32544
- }, (e, v) => {
32545
- e.varU64(0n);
32546
- val.encode(e, v);
32547
- }, (d) => {
32548
- const version = d.varU64();
32549
- if (version !== 0n) {
32550
- throw new Error("Non-zero version is not supported!");
32551
- }
32552
- return val.decode(d);
32553
- }, (s) => {
32554
- s.varU64();
32555
- val.skip(s);
32556
- });
32557
- /**
32558
- * Service account details.
32559
- *
32560
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
32561
- */
32562
- class ServiceAccountInfo extends WithDebug {
32563
- codeHash;
32564
- balance;
32565
- accumulateMinGas;
32566
- onTransferMinGas;
32567
- storageUtilisationBytes;
32568
- gratisStorage;
32569
- storageUtilisationCount;
32570
- created;
32571
- lastAccumulation;
32572
- parentService;
32573
- static Codec = descriptors_codec.Class(ServiceAccountInfo, {
32574
- codeHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
32575
- balance: descriptors_codec.u64,
32576
- accumulateMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
32577
- onTransferMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
32578
- storageUtilisationBytes: descriptors_codec.u64,
32579
- gratisStorage: descriptors_codec.u64,
32580
- storageUtilisationCount: descriptors_codec.u32,
32581
- created: descriptors_codec.u32.convert((x) => x, tryAsTimeSlot),
32582
- lastAccumulation: descriptors_codec.u32.convert((x) => x, tryAsTimeSlot),
32583
- parentService: descriptors_codec.u32.convert((x) => x, tryAsServiceId),
32584
- });
32585
- static create(a) {
32586
- return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
32587
- }
32588
- /**
32589
- * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
32590
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
32591
- */
32592
- static calculateThresholdBalance(items, bytes, gratisStorage) {
32593
- const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
32594
- if (storageCost < 0n) {
32595
- return numbers_tryAsU64(0);
32596
- }
32597
- if (storageCost >= 2n ** 64n) {
32598
- return numbers_tryAsU64(2n ** 64n - 1n);
32599
- }
32600
- return numbers_tryAsU64(storageCost);
32601
- }
32602
- constructor(
32603
- /** `a_c`: Hash of the service code. */
32604
- codeHash,
32605
- /** `a_b`: Current account balance. */
32606
- balance,
32607
- /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
32608
- accumulateMinGas,
32609
- /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
32610
- onTransferMinGas,
32611
- /** `a_o`: Total number of octets in storage. */
32612
- storageUtilisationBytes,
32613
- /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
32614
- gratisStorage,
32615
- /** `a_i`: Number of items in storage. */
32616
- storageUtilisationCount,
32617
- /** `a_r`: Creation account time slot. */
32618
- created,
32619
- /** `a_a`: Most recent accumulation time slot. */
32620
- lastAccumulation,
32621
- /** `a_p`: Parent service ID. */
32622
- parentService) {
32623
- super();
32624
- this.codeHash = codeHash;
32625
- this.balance = balance;
32626
- this.accumulateMinGas = accumulateMinGas;
32627
- this.onTransferMinGas = onTransferMinGas;
32628
- this.storageUtilisationBytes = storageUtilisationBytes;
32629
- this.gratisStorage = gratisStorage;
32630
- this.storageUtilisationCount = storageUtilisationCount;
32631
- this.created = created;
32632
- this.lastAccumulation = lastAccumulation;
32633
- this.parentService = parentService;
32634
- }
32635
- }
32636
- class PreimageItem extends WithDebug {
32637
- hash;
32638
- blob;
32639
- static Codec = descriptors_codec.Class(PreimageItem, {
32640
- hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
32641
- blob: descriptors_codec.blob,
32642
- });
32643
- static create({ hash, blob }) {
32644
- return new PreimageItem(hash, blob);
32645
- }
32646
- constructor(hash, blob) {
32647
- super();
32648
- this.hash = hash;
32649
- this.blob = blob;
32650
- }
32651
- }
32652
- class StorageItem extends WithDebug {
32653
- key;
32654
- value;
32655
- static Codec = descriptors_codec.Class(StorageItem, {
32656
- key: descriptors_codec.blob.convert((i) => i, (o) => opaque_asOpaqueType(o)),
32657
- value: descriptors_codec.blob,
32658
- });
32659
- static create({ key, value }) {
32660
- return new StorageItem(key, value);
32661
- }
32662
- constructor(key, value) {
32663
- super();
32664
- this.key = key;
32665
- this.value = value;
32666
- }
32667
- }
32668
- const MAX_LOOKUP_HISTORY_SLOTS = 3;
32669
- function tryAsLookupHistorySlots(items) {
32670
- const knownSize = sized_array_asKnownSize(items);
32671
- if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
32672
- throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
32673
- }
32674
- return knownSize;
32675
- }
32676
- /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
32677
- class LookupHistoryItem {
32678
- hash;
32679
- length;
32680
- slots;
32681
- constructor(hash, length,
32682
- /**
32683
- * Preimage availability history as a sequence of time slots.
32684
- * See PreimageStatus and the following GP fragment for more details.
32685
- * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
32686
- slots) {
32687
- this.hash = hash;
32688
- this.length = length;
32689
- this.slots = slots;
32690
- }
32691
- static isRequested(item) {
32692
- if ("slots" in item) {
32693
- return item.slots.length === 0;
32694
- }
32695
- return item.length === 0;
32696
- }
32697
- }
32698
-
32699
32727
  ;// CONCATENATED MODULE: ./packages/jam/state/state.ts
32700
32728
  /**
32701
32729
  * In addition to the entropy accumulator η_0, we retain
@@ -33132,6 +33160,7 @@ class StatisticsData {
33132
33160
 
33133
33161
 
33134
33162
 
33163
+
33135
33164
 
33136
33165
 
33137
33166
  var in_memory_state_UpdateError;
@@ -33535,8 +33564,9 @@ class InMemoryState extends WithDebug {
33535
33564
  epochRoot: bytes_Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
33536
33565
  privilegedServices: PrivilegedServices.create({
33537
33566
  manager: tryAsServiceId(0),
33538
- authManager: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
33539
- validatorsManager: tryAsServiceId(0),
33567
+ assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
33568
+ delegator: tryAsServiceId(0),
33569
+ registrar: tryAsServiceId(MAX_VALUE),
33540
33570
  autoAccumulateServices: [],
33541
33571
  }),
33542
33572
  accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
@@ -33772,7 +33802,7 @@ var serialize;
33772
33802
  * determine the boundary of the bytes, so it can only be used
33773
33803
  * as the last element of the codec and can't be used in sequences!
33774
33804
  */
33775
- 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()));
33776
33806
 
33777
33807
  ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
33778
33808
 
@@ -35083,7 +35113,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
35083
35113
  }
35084
35114
  return Ordering.Equal;
35085
35115
  }, } = {}) => {
35086
- return descriptor_Descriptor.new(`Map<${value.name}>[?]`, {
35116
+ return Descriptor.new(`Map<${value.name}>[?]`, {
35087
35117
  bytes: typicalLength * value.sizeHint.bytes,
35088
35118
  isExact: false,
35089
35119
  }, (e, v) => {
@@ -35513,6 +35543,65 @@ function blockAsView(block, spec) {
35513
35543
  return decoder_Decoder.decodeObject(Block.Codec.View, encoder_Encoder.encodeObject(Block.Codec, block, spec), spec);
35514
35544
  }
35515
35545
 
35546
+ ;// CONCATENATED MODULE: external "node:path"
35547
+ const external_node_path_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:path");
35548
+ var external_node_path_default = /*#__PURE__*/__nccwpck_require__.n(external_node_path_namespaceObject);
35549
+ ;// CONCATENATED MODULE: ./packages/jam/node/export.ts
35550
+
35551
+
35552
+
35553
+
35554
+
35555
+
35556
+
35557
+
35558
+
35559
+ async function exportBlocks(jamNodeConfig, outputDir, withRelPath) {
35560
+ const logger = Logger.new(import.meta.filename, "export");
35561
+ logger.info `📤 Exporting blocks to ${outputDir}`;
35562
+ if (!external_node_fs_default().existsSync(outputDir)) {
35563
+ external_node_fs_default().mkdirSync(outputDir, { recursive: true });
35564
+ }
35565
+ const blake2b = await blake2b_Blake2b.createHasher();
35566
+ const chainSpec = getChainSpec(jamNodeConfig.node.flavor);
35567
+ const { rootDb } = openDatabase(blake2b, jamNodeConfig.nodeName, jamNodeConfig.node.chainSpec.genesisHeader, withRelPath(jamNodeConfig.node.databaseBasePath), { readOnly: true });
35568
+ const blocks = new LmdbBlocks(chainSpec, rootDb);
35569
+ logger.info `📖 Gathering blocks...`;
35570
+ const hashes = [];
35571
+ let currentHash = blocks.getBestHeaderHash();
35572
+ while (currentHash.isEqualTo(bytes_Bytes.zero(hash_HASH_SIZE)) !== true) {
35573
+ const header = blocks.getHeader(currentHash);
35574
+ if (header !== null) {
35575
+ hashes.push(currentHash);
35576
+ currentHash = header.parentHeaderHash.materialize();
35577
+ }
35578
+ else {
35579
+ break;
35580
+ }
35581
+ }
35582
+ // reverse to export in chronological order
35583
+ hashes.reverse();
35584
+ logger.info `📕 ${hashes.length} blocks gathered.`;
35585
+ for (let i = 0; i < hashes.length; i++) {
35586
+ const header = blocks.getHeader(hashes[i]);
35587
+ const extrinsic = blocks.getExtrinsic(hashes[i]);
35588
+ if (header === null || extrinsic === null) {
35589
+ throw new Error(`❌ Block ${currentHash} could not be read from the database.`);
35590
+ }
35591
+ const filename = `${header.timeSlotIndex.materialize().toString().padStart(8, "0")}.bin`;
35592
+ const filepath = external_node_path_default().join(outputDir, filename);
35593
+ const block = Block.create({
35594
+ header: header.materialize(),
35595
+ extrinsic: extrinsic.materialize(),
35596
+ });
35597
+ const encodedBlock = encoder_Encoder.encodeObject(Block.Codec, block, chainSpec);
35598
+ external_node_fs_default().writeFileSync(filepath, encodedBlock.raw);
35599
+ logger.log `✅ Exported block ${i + 1}/${hashes.length}: ${filename}`;
35600
+ }
35601
+ await rootDb.close();
35602
+ logger.info `🫡 Export completed successfully: ${hashes.length} blocks exported to ${outputDir}`;
35603
+ }
35604
+
35516
35605
  ;// CONCATENATED MODULE: ./packages/jam/node/jam-config.ts
35517
35606
 
35518
35607
  const DEFAULT_DEV_CONFIG = {
@@ -40044,8 +40133,6 @@ function setupPeerListeners(syncTask, network, streamManager) {
40044
40133
 
40045
40134
  ;// CONCATENATED MODULE: external "node:net"
40046
40135
  const external_node_net_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:net");
40047
- ;// CONCATENATED MODULE: external "node:path"
40048
- const external_node_path_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:path");
40049
40136
  ;// CONCATENATED MODULE: ./packages/extensions/ipc/server.ts
40050
40137
 
40051
40138
 
@@ -41908,11 +41995,17 @@ class AccumulationStateUpdate {
41908
41995
  if (from.privilegedServices !== null) {
41909
41996
  update.privilegedServices = PrivilegedServices.create({
41910
41997
  ...from.privilegedServices,
41911
- authManager: sized_array_asKnownSize([...from.privilegedServices.authManager]),
41998
+ assigners: sized_array_asKnownSize([...from.privilegedServices.assigners]),
41912
41999
  });
41913
42000
  }
41914
42001
  return update;
41915
42002
  }
42003
+ /** Retrieve and clear pending transfers. */
42004
+ takeTransfers() {
42005
+ const transfers = this.transfers;
42006
+ this.transfers = [];
42007
+ return transfers;
42008
+ }
41916
42009
  }
41917
42010
  class PartiallyUpdatedState {
41918
42011
  state;
@@ -44047,13 +44140,6 @@ class BitOps {
44047
44140
  }
44048
44141
  }
44049
44142
 
44050
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
44051
- const MAX_VALUE = 4294967295;
44052
- const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
44053
- const MIN_VALUE = -(2 ** 31);
44054
- const MAX_SHIFT_U32 = 32;
44055
- const MAX_SHIFT_U64 = 64n;
44056
-
44057
44143
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-utils.ts
44058
44144
 
44059
44145
 
@@ -46083,6 +46169,8 @@ var NewServiceError;
46083
46169
  NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
46084
46170
  /** Service is not privileged to set gratis storage. */
46085
46171
  NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
46172
+ /** Registrar attempting to create a service with already existing id. */
46173
+ NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
46086
46174
  })(NewServiceError || (NewServiceError = {}));
46087
46175
  var UpdatePrivilegesError;
46088
46176
  (function (UpdatePrivilegesError) {
@@ -46219,7 +46307,7 @@ const HostCallResult = {
46219
46307
  OOB: numbers_tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
46220
46308
  /** Index unknown. */
46221
46309
  WHO: numbers_tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
46222
- /** Storage full. */
46310
+ /** Storage full or resource already allocated. */
46223
46311
  FULL: numbers_tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
46224
46312
  /** Core index unknown. */
46225
46313
  CORE: numbers_tryAsU64(0xfffffffffffffffan), // 2**64 - 6
@@ -46227,7 +46315,7 @@ const HostCallResult = {
46227
46315
  CASH: numbers_tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
46228
46316
  /** Gas limit too low. */
46229
46317
  LOW: numbers_tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
46230
- /** The item is already solicited or cannot be forgotten. */
46318
+ /** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
46231
46319
  HUH: numbers_tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
46232
46320
  /** The return value indicating general success. */
46233
46321
  OK: numbers_tryAsU64(0n),
@@ -46281,6 +46369,7 @@ function clampU64ToU32(value) {
46281
46369
 
46282
46370
 
46283
46371
 
46372
+
46284
46373
  /**
46285
46374
  * Number of storage items required for ejection of the service.
46286
46375
  *
@@ -46372,10 +46461,13 @@ class AccumulateExternalities {
46372
46461
  const isExpired = status.data[1] < t - this.chainSpec.preimageExpungePeriod;
46373
46462
  return [isExpired, isExpired ? "" : "not expired"];
46374
46463
  }
46375
- /** `check`: https://graypaper.fluffylabs.dev/#/9a08063/303f02303f02?v=0.6.6 */
46464
+ /** `check`: https://graypaper.fluffylabs.dev/#/ab2cdbd/30c60330c603?v=0.7.2 */
46376
46465
  getNextAvailableServiceId(serviceId) {
46377
46466
  let currentServiceId = serviceId;
46378
- const mod = 2 ** 32 - 2 ** 9;
46467
+ const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
46468
+ ? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
46469
+ : 2 ** 32 - 2 ** 9;
46470
+ const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
46379
46471
  for (;;) {
46380
46472
  const service = this.getServiceInfo(currentServiceId);
46381
46473
  // we found an empty id
@@ -46383,7 +46475,7 @@ class AccumulateExternalities {
46383
46475
  return currentServiceId;
46384
46476
  }
46385
46477
  // keep trying
46386
- currentServiceId = tryAsServiceId(((currentServiceId - 2 ** 8 + 1 + mod) % mod) + 2 ** 8);
46478
+ currentServiceId = tryAsServiceId(((currentServiceId - offset + 1 + mod) % mod) + offset);
46387
46479
  }
46388
46480
  }
46389
46481
  checkPreimageStatus(hash, length) {
@@ -46540,8 +46632,7 @@ class AccumulateExternalities {
46540
46632
  }));
46541
46633
  return result_Result.ok(result_OK);
46542
46634
  }
46543
- newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage) {
46544
- const newServiceId = this.nextNewServiceId;
46635
+ newService(codeHash, codeLength, accumulateMinGas, onTransferMinGas, gratisStorage, wantedServiceId) {
46545
46636
  // calculate the threshold. Storage is empty, one preimage requested.
46546
46637
  // https://graypaper.fluffylabs.dev/#/7e6ff6a/115901115901?v=0.6.7
46547
46638
  const items = numbers_tryAsU32(2 * 1 + 0);
@@ -46562,30 +46653,59 @@ class AccumulateExternalities {
46562
46653
  if (balanceLeftForCurrent < thresholdForCurrent || bytes.overflow) {
46563
46654
  return result_Result.error(NewServiceError.InsufficientFunds);
46564
46655
  }
46656
+ // `a`: https://graypaper.fluffylabs.dev/#/ab2cdbd/366b02366d02?v=0.7.2
46657
+ const newAccount = ServiceAccountInfo.create({
46658
+ codeHash,
46659
+ balance: thresholdForNew,
46660
+ accumulateMinGas,
46661
+ onTransferMinGas,
46662
+ storageUtilisationBytes: bytes.value,
46663
+ storageUtilisationCount: items,
46664
+ gratisStorage,
46665
+ created: this.currentTimeslot,
46666
+ lastAccumulation: tryAsTimeSlot(0),
46667
+ parentService: this.currentServiceId,
46668
+ });
46669
+ const newLookupItem = new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([]));
46670
+ // `s`: https://graypaper.fluffylabs.dev/#/ab2cdbd/361003361003?v=0.7.2
46671
+ const updatedCurrentAccount = ServiceAccountInfo.create({
46672
+ ...currentService,
46673
+ balance: numbers_tryAsU64(balanceLeftForCurrent),
46674
+ });
46675
+ if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
46676
+ if (wantedServiceId < MIN_PUBLIC_SERVICE_INDEX &&
46677
+ this.currentServiceId === this.updatedState.getPrivilegedServices().registrar) {
46678
+ // NOTE: It's safe to cast to `Number` here, bcs here service ID cannot be bigger than 2**16
46679
+ const newServiceId = tryAsServiceId(Number(wantedServiceId));
46680
+ if (this.getServiceInfo(newServiceId) !== null) {
46681
+ return result_Result.error(NewServiceError.RegistrarServiceIdAlreadyTaken);
46682
+ }
46683
+ // add the new service with selected ID
46684
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36be0336c003?v=0.7.2
46685
+ this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
46686
+ serviceId: newServiceId,
46687
+ serviceInfo: newAccount,
46688
+ lookupHistory: newLookupItem,
46689
+ }));
46690
+ // update the balance of current service
46691
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36c20336c403?v=0.7.2
46692
+ this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
46693
+ return result_Result.ok(newServiceId);
46694
+ }
46695
+ // NOTE: in case the service is not a registrar or the requested serviceId is out of range,
46696
+ // we completely ignore the `wantedServiceId` and assign a random one
46697
+ }
46698
+ const newServiceId = this.nextNewServiceId;
46565
46699
  // add the new service
46566
- // https://graypaper.fluffylabs.dev/#/7e6ff6a/36cb0236cb02?v=0.6.7
46700
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36e70336e903?v=0.7.2
46567
46701
  this.updatedState.stateUpdate.services.servicesUpdates.push(UpdateService.create({
46568
46702
  serviceId: newServiceId,
46569
- serviceInfo: ServiceAccountInfo.create({
46570
- codeHash,
46571
- balance: thresholdForNew,
46572
- accumulateMinGas,
46573
- onTransferMinGas,
46574
- storageUtilisationBytes: bytes.value,
46575
- storageUtilisationCount: items,
46576
- gratisStorage,
46577
- created: this.currentTimeslot,
46578
- lastAccumulation: tryAsTimeSlot(0),
46579
- parentService: this.currentServiceId,
46580
- }),
46581
- lookupHistory: new LookupHistoryItem(codeHash.asOpaque(), clampedLength, tryAsLookupHistorySlots([])),
46703
+ serviceInfo: newAccount,
46704
+ lookupHistory: newLookupItem,
46582
46705
  }));
46583
46706
  // update the balance of current service
46584
- // https://graypaper.fluffylabs.dev/#/7e6ff6a/364d03364d03?v=0.6.7
46585
- this.updatedState.updateServiceInfo(this.currentServiceId, ServiceAccountInfo.create({
46586
- ...currentService,
46587
- balance: numbers_tryAsU64(balanceLeftForCurrent),
46588
- }));
46707
+ // https://graypaper.fluffylabs.dev/#/ab2cdbd/36ec0336ee03?v=0.7.2
46708
+ this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
46589
46709
  // update the next service id we are going to create next
46590
46710
  // https://graypaper.fluffylabs.dev/#/7e6ff6a/36a70336a703?v=0.6.7
46591
46711
  this.nextNewServiceId = this.getNextAvailableServiceId(bumpServiceId(newServiceId));
@@ -46603,9 +46723,9 @@ class AccumulateExternalities {
46603
46723
  }
46604
46724
  updateValidatorsData(validatorsData) {
46605
46725
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/362802362d02?v=0.6.7 */
46606
- const validatorsManager = this.updatedState.getPrivilegedServices().validatorsManager;
46607
- if (validatorsManager !== this.currentServiceId) {
46608
- accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${validatorsManager}) and cannot update validators data. Ignoring`;
46726
+ const currentDelegator = this.updatedState.getPrivilegedServices().delegator;
46727
+ if (currentDelegator !== this.currentServiceId) {
46728
+ accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${currentDelegator}) and cannot update validators data. Ignoring`;
46609
46729
  return result_Result.error(UnprivilegedError);
46610
46730
  }
46611
46731
  this.updatedState.stateUpdate.validatorsData = validatorsData;
@@ -46615,34 +46735,38 @@ class AccumulateExternalities {
46615
46735
  /** https://graypaper.fluffylabs.dev/#/9a08063/362202362202?v=0.6.6 */
46616
46736
  this.checkpointedState = AccumulationStateUpdate.copyFrom(this.updatedState.stateUpdate);
46617
46737
  }
46618
- updateAuthorizationQueue(coreIndex, authQueue, authManager) {
46738
+ updateAuthorizationQueue(coreIndex, authQueue, assigners) {
46619
46739
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/36a40136a401?v=0.6.7 */
46620
46740
  // NOTE `coreIndex` is already verified in the HC, so this is infallible.
46621
- const currentAuthManager = this.updatedState.getPrivilegedServices().authManager[coreIndex];
46622
- if (currentAuthManager !== this.currentServiceId) {
46623
- 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`;
46741
+ const currentAssigners = this.updatedState.getPrivilegedServices().assigners[coreIndex];
46742
+ if (currentAssigners !== this.currentServiceId) {
46743
+ accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not an auth manager of core ${coreIndex} (expected: ${currentAssigners}) and cannot update authorization queue.`;
46624
46744
  return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
46625
46745
  }
46626
- if (authManager === null && Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
46627
- accumulate_externalities_logger.trace `The new auth manager is not a valid service id. Ignoring`;
46746
+ if (assigners === null && Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
46747
+ accumulate_externalities_logger.trace `The new auth manager is not a valid service id.`;
46628
46748
  return result_Result.error(UpdatePrivilegesError.InvalidServiceId);
46629
46749
  }
46630
46750
  this.updatedState.stateUpdate.authorizationQueues.set(coreIndex, authQueue);
46631
46751
  return result_Result.ok(result_OK);
46632
46752
  }
46633
- updatePrivilegedServices(manager, authorizers, validatorsManager, autoAccumulate) {
46753
+ updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate) {
46634
46754
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/36d90036de00?v=0.6.7 */
46635
46755
  const currentManager = this.updatedState.getPrivilegedServices().manager;
46636
46756
  if (currentManager !== this.currentServiceId) {
46637
46757
  return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
46638
46758
  }
46639
- if (manager === null || validatorsManager === null) {
46640
- return result_Result.error(UpdatePrivilegesError.InvalidServiceId);
46759
+ if (manager === null || delegator === null) {
46760
+ return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Either manager or delegator is not valid service id.");
46761
+ }
46762
+ if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && registrar === null) {
46763
+ return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Register manager is not valid service id.");
46641
46764
  }
46642
46765
  this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
46643
46766
  manager,
46644
- authManager: authorizers,
46645
- validatorsManager,
46767
+ assigners: authorizers,
46768
+ delegator,
46769
+ registrar: registrar ?? tryAsServiceId(0), // introduced in 0.7.1
46646
46770
  autoAccumulateServices: autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit })),
46647
46771
  });
46648
46772
  return result_Result.ok(result_OK);
@@ -46758,8 +46882,11 @@ class AccumulateExternalities {
46758
46882
  }
46759
46883
  }
46760
46884
  function bumpServiceId(serviceId) {
46761
- const mod = 2 ** 32 - 2 ** 9;
46762
- return tryAsServiceId(2 ** 8 + ((serviceId - 2 ** 8 + 42 + mod) % mod));
46885
+ const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
46886
+ ? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
46887
+ : 2 ** 32 - 2 ** 9;
46888
+ const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
46889
+ return tryAsServiceId(offset + ((serviceId - offset + 42 + mod) % mod));
46763
46890
  }
46764
46891
 
46765
46892
  ;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-state.ts
@@ -47415,6 +47542,8 @@ class AccumulateData {
47415
47542
 
47416
47543
 
47417
47544
 
47545
+
47546
+
47418
47547
  /**
47419
47548
  * A function that removes duplicates but does not change order - it keeps the first occurence.
47420
47549
  */
@@ -47444,7 +47573,7 @@ const NEXT_ID_CODEC = descriptors_codec.object({
47444
47573
  *
47445
47574
  * Please not that it does not call `check` function!
47446
47575
  *
47447
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/2f4c022f4c02?v=0.6.7
47576
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/2fa9042fc304?v=0.7.2
47448
47577
  */
47449
47578
  function generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blake2b) {
47450
47579
  const encoded = encoder_Encoder.encodeObject(NEXT_ID_CODEC, {
@@ -47454,7 +47583,11 @@ function generateNextServiceId({ serviceId, entropy, timeslot }, chainSpec, blak
47454
47583
  }, chainSpec);
47455
47584
  const result = blake2b.hashBytes(encoded).raw.subarray(0, 4);
47456
47585
  const number = leBytesAsU32(result) >>> 0;
47457
- return tryAsServiceId((number % (2 ** 32 - 2 ** 9)) + 2 ** 8);
47586
+ const mod = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
47587
+ ? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
47588
+ : 2 ** 32 - 2 ** 9;
47589
+ const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
47590
+ return tryAsServiceId((number % mod) + offset);
47458
47591
  }
47459
47592
 
47460
47593
  ;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-queue.ts
@@ -47866,7 +47999,7 @@ class Assign {
47866
47999
  // o
47867
48000
  const authorizationQueueStart = regs.get(8);
47868
48001
  // a
47869
- const authManager = getServiceId(regs.get(9));
48002
+ const assigners = getServiceId(regs.get(9));
47870
48003
  const res = safeAllocUint8Array(hash_HASH_SIZE * AUTHORIZATION_QUEUE_SIZE);
47871
48004
  const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
47872
48005
  // error while reading the memory.
@@ -47883,7 +48016,7 @@ class Assign {
47883
48016
  const decoder = decoder_Decoder.fromBlob(res);
47884
48017
  const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE), AUTHORIZATION_QUEUE_SIZE);
47885
48018
  const fixedSizeAuthQueue = FixedSizeArray.new(authQueue, AUTHORIZATION_QUEUE_SIZE);
47886
- const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, authManager);
48019
+ const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
47887
48020
  if (result.isOk) {
47888
48021
  regs.set(IN_OUT_REG, HostCallResult.OK);
47889
48022
  logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
@@ -47932,7 +48065,9 @@ class Bless {
47932
48065
  chainSpec;
47933
48066
  index = host_call_handler_tryAsHostCallIndex(14);
47934
48067
  basicGasCost = gas_tryAsSmallGas(10);
47935
- tracedRegisters = traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11);
48068
+ tracedRegisters = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
48069
+ ? traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11, 12)
48070
+ : traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11);
47936
48071
  constructor(currentServiceId, partialState, chainSpec) {
47937
48072
  this.currentServiceId = currentServiceId;
47938
48073
  this.partialState = partialState;
@@ -47942,14 +48077,17 @@ class Bless {
47942
48077
  // `m`: manager service (can change privileged services)
47943
48078
  const manager = getServiceId(regs.get(bless_IN_OUT_REG));
47944
48079
  // `a`: manages authorization queue
47945
- // NOTE It can be either ServiceId (pre GP 067) or memory index (GP ^067)
47946
48080
  const authorization = regs.get(8);
47947
48081
  // `v`: manages validator keys
47948
- const validator = getServiceId(regs.get(9));
48082
+ const delegator = getServiceId(regs.get(9));
48083
+ // `r`: manages creation of new services with id within protected range
48084
+ const registrar = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
48085
+ ? getServiceId(regs.get(10))
48086
+ : tryAsServiceId(2 ** 32 - 1);
47949
48087
  // `o`: memory offset
47950
- const sourceStart = regs.get(10);
48088
+ const sourceStart = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? regs.get(11) : regs.get(10);
47951
48089
  // `n`: number of items in the auto-accumulate dictionary
47952
- const numberOfItems = regs.get(11);
48090
+ const numberOfItems = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? regs.get(12) : regs.get(11);
47953
48091
  /*
47954
48092
  * `z`: array of key-value pairs serviceId -> gas that auto-accumulate every block
47955
48093
  * https://graypaper.fluffylabs.dev/#/7e6ff6a/368100368100?v=0.6.7
@@ -47963,7 +48101,7 @@ class Bless {
47963
48101
  decoder.resetTo(0);
47964
48102
  const memoryReadResult = memory.loadInto(result, memIndex);
47965
48103
  if (memoryReadResult.isError) {
47966
- logger_logger.trace `BLESS(${manager}, ${validator}) <- PANIC`;
48104
+ logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}) <- PANIC`;
47967
48105
  return PvmExecution.Panic;
47968
48106
  }
47969
48107
  const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
@@ -47976,24 +48114,25 @@ class Bless {
47976
48114
  const authorizersDecoder = decoder_Decoder.fromBlob(res);
47977
48115
  const memoryReadResult = memory.loadInto(res, authorization);
47978
48116
  if (memoryReadResult.isError) {
47979
- logger_logger.trace `BLESS(${manager}, ${validator}, ${autoAccumulateEntries}) <- PANIC`;
48117
+ logger_logger.trace `BLESS(${manager}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- PANIC`;
47980
48118
  return PvmExecution.Panic;
47981
48119
  }
48120
+ // `a`
47982
48121
  const authorizers = tryAsPerCore(authorizersDecoder.sequenceFixLen(descriptors_codec.u32.asOpaque(), this.chainSpec.coresCount), this.chainSpec);
47983
- const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, validator, autoAccumulateEntries);
48122
+ const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulateEntries);
47984
48123
  if (updateResult.isOk) {
47985
- logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- OK`;
48124
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- OK`;
47986
48125
  regs.set(bless_IN_OUT_REG, HostCallResult.OK);
47987
48126
  return;
47988
48127
  }
47989
48128
  const e = updateResult.error;
47990
48129
  if (e === UpdatePrivilegesError.UnprivilegedService) {
47991
- logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- HUH`;
48130
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- HUH`;
47992
48131
  regs.set(bless_IN_OUT_REG, HostCallResult.HUH);
47993
48132
  return;
47994
48133
  }
47995
48134
  if (e === UpdatePrivilegesError.InvalidServiceId) {
47996
- logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- WHO`;
48135
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- WHO`;
47997
48136
  regs.set(bless_IN_OUT_REG, HostCallResult.WHO);
47998
48137
  return;
47999
48138
  }
@@ -48245,7 +48384,9 @@ class New {
48245
48384
  partialState;
48246
48385
  index = host_call_handler_tryAsHostCallIndex(18);
48247
48386
  basicGasCost = gas_tryAsSmallGas(10);
48248
- tracedRegisters = traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11);
48387
+ tracedRegisters = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
48388
+ ? traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11, 12)
48389
+ : traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11);
48249
48390
  constructor(currentServiceId, partialState) {
48250
48391
  this.currentServiceId = currentServiceId;
48251
48392
  this.partialState = partialState;
@@ -48261,16 +48402,18 @@ class New {
48261
48402
  const allowance = tryAsServiceGas(regs.get(10));
48262
48403
  // `f`
48263
48404
  const gratisStorage = regs.get(11);
48405
+ // `i`: requested service id. Ignored if current service is not registrar or value is bigger than `S`.
48406
+ const requestedServiceId = regs.get(12);
48264
48407
  // `c`
48265
48408
  const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
48266
48409
  const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
48267
48410
  // error while reading the memory.
48268
48411
  if (memoryReadResult.isError) {
48269
- logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- PANIC`;
48412
+ logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
48270
48413
  return PvmExecution.Panic;
48271
48414
  }
48272
- const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage);
48273
- logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- ${resultToString(assignedId)}`;
48415
+ const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage, requestedServiceId);
48416
+ logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${resultToString(assignedId)}`;
48274
48417
  if (assignedId.isOk) {
48275
48418
  regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
48276
48419
  return;
@@ -48284,6 +48427,11 @@ class New {
48284
48427
  regs.set(new_IN_OUT_REG, HostCallResult.HUH);
48285
48428
  return;
48286
48429
  }
48430
+ // Post 0.7.1
48431
+ if (e === NewServiceError.RegistrarServiceIdAlreadyTaken) {
48432
+ regs.set(new_IN_OUT_REG, HostCallResult.FULL);
48433
+ return;
48434
+ }
48287
48435
  debug_assertNever(e);
48288
48436
  }
48289
48437
  }
@@ -49541,7 +49689,7 @@ class Accumulate {
49541
49689
  }
49542
49690
  const nextServiceId = generateNextServiceId({ serviceId, entropy, timeslot: slot }, this.chainSpec, this.blake2b);
49543
49691
  const partialState = new AccumulateExternalities(this.chainSpec, this.blake2b, new PartiallyUpdatedState(this.state, inputStateUpdate), serviceId, nextServiceId, slot);
49544
- const fetchExternalities = Compatibility.isGreaterOrEqual(GpVersion.V0_7_2)
49692
+ const fetchExternalities = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
49545
49693
  ? FetchExternalities.createForAccumulate({ entropy, transfers, operands }, this.chainSpec)
49546
49694
  : FetchExternalities.createForPre071Accumulate({ entropy, operands }, this.chainSpec);
49547
49695
  const externalities = {
@@ -49656,7 +49804,7 @@ class Accumulate {
49656
49804
  const accumulateData = new AccumulateData(reportsToAccumulateInParallel, transfers, autoAccumulateServices);
49657
49805
  const reportsToAccumulateSequentially = reports.subview(i);
49658
49806
  const { gasCost, state: stateAfterParallelAcc, ...rest } = await this.accumulateInParallel(accumulateData, slot, entropy, statistics, stateUpdate);
49659
- const newTransfers = stateAfterParallelAcc.transfers;
49807
+ const newTransfers = stateAfterParallelAcc.takeTransfers();
49660
49808
  assertEmpty(rest);
49661
49809
  // NOTE [ToDr] recursive invocation
49662
49810
  const { accumulatedReports, gasCost: seqGasCost, state, ...seqRest } = await this.accumulateSequentially(tryAsServiceGas(gasLimit - gasCost), reportsToAccumulateSequentially, newTransfers, slot, entropy, statistics, stateAfterParallelAcc, []);
@@ -49692,17 +49840,17 @@ class Accumulate {
49692
49840
  statistics.set(serviceId, serviceStatistics);
49693
49841
  currentState = stateUpdate === null ? checkpoint : stateUpdate;
49694
49842
  if (Compatibility.is(GpVersion.V0_7_0) && serviceId === currentManager) {
49695
- const newV = currentState.privilegedServices?.validatorsManager;
49843
+ const newV = currentState.privilegedServices?.delegator;
49696
49844
  if (currentState.privilegedServices !== null && newV !== undefined && serviceIds.includes(newV)) {
49697
- 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+`;
49845
+ 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+`;
49698
49846
  // Since serviceIds already contains newV, this service gets accumulated twice.
49699
49847
  // To avoid double-counting, we skip stats and gas cost tracking here.
49700
- // We need this accumulation to get the correct `validatorsManager`
49848
+ // We need this accumulation to get the correct `delegator`
49701
49849
  const { stateUpdate } = await this.accumulateSingleService(newV, [], accumulateData.getOperands(newV), accumulateData.getGasCost(newV), slot, entropy, checkpoint);
49702
- const correctV = stateUpdate?.privilegedServices?.validatorsManager ?? this.state.privilegedServices.validatorsManager;
49850
+ const correctV = stateUpdate?.privilegedServices?.delegator ?? this.state.privilegedServices.delegator;
49703
49851
  currentState.privilegedServices = PrivilegedServices.create({
49704
49852
  ...currentState.privilegedServices,
49705
- validatorsManager: correctV,
49853
+ delegator: correctV,
49706
49854
  });
49707
49855
  }
49708
49856
  }
@@ -51941,6 +52089,7 @@ function readJsonBlock(file, chainSpec) {
51941
52089
 
51942
52090
 
51943
52091
 
52092
+
51944
52093
  // EXTERNAL MODULE: ./node_modules/minimist/index.js
51945
52094
  var minimist = __nccwpck_require__(8595);
51946
52095
  var minimist_default = /*#__PURE__*/__nccwpck_require__.n(minimist);
@@ -51958,6 +52107,7 @@ Usage:
51958
52107
  jam [options]
51959
52108
  jam [options] dev <dev-validator-index>
51960
52109
  jam [options] import <bin-or-json-blocks>
52110
+ jam [options] export <output-directory>
51961
52111
  jam [options] [--version=1] fuzz-target [socket-path=/tmp/jam_target.sock]
51962
52112
 
51963
52113
  Options:
@@ -51975,6 +52125,8 @@ var Command;
51975
52125
  Command["Dev"] = "dev";
51976
52126
  /** Import the blocks from CLI and finish. */
51977
52127
  Command["Import"] = "import";
52128
+ /** Export blocks to .bin files. */
52129
+ Command["Export"] = "export";
51978
52130
  /** Run as a Fuzz Target. */
51979
52131
  Command["FuzzTarget"] = "fuzz-target";
51980
52132
  })(Command || (Command = {}));
@@ -52039,6 +52191,21 @@ function parseArgs(input, withRelPath) {
52039
52191
  },
52040
52192
  };
52041
52193
  }
52194
+ case Command.Export: {
52195
+ const data = parseSharedOptions(args, withRelPath);
52196
+ const outputDir = args._.shift();
52197
+ if (outputDir === undefined) {
52198
+ throw new Error("Missing output directory.");
52199
+ }
52200
+ assertNoMoreArgs(args);
52201
+ return {
52202
+ command: Command.Export,
52203
+ args: {
52204
+ ...data,
52205
+ outputDir: withRelPath(outputDir),
52206
+ },
52207
+ };
52208
+ }
52042
52209
  default: {
52043
52210
  args._.unshift(command);
52044
52211
  assertNoMoreArgs(args);
@@ -52168,6 +52335,9 @@ async function startNode(args, withRelPath) {
52168
52335
  }, withRelPath);
52169
52336
  return await importBlocks(node, args.args.files);
52170
52337
  }
52338
+ if (args.command === Command.Export) {
52339
+ return await exportBlocks(jamNodeConfig, args.args.outputDir, withRelPath);
52340
+ }
52171
52341
  // Run regular node.
52172
52342
  return main_main(jamNodeConfig, withRelPath);
52173
52343
  }