@typeberry/jam 0.1.3-8258907 → 0.1.3-b0374a8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4349,7 +4349,7 @@ class Skipper {
4349
4349
  *
4350
4350
  * Descriptors can be composed to form more complex typings.
4351
4351
  */
4352
- class descriptor_Descriptor {
4352
+ class Descriptor {
4353
4353
  name;
4354
4354
  sizeHint;
4355
4355
  encode;
@@ -4359,11 +4359,11 @@ class descriptor_Descriptor {
4359
4359
  View;
4360
4360
  /** New descriptor with specialized `View`. */
4361
4361
  static withView(name, sizeHint, encode, decode, skip, view) {
4362
- return new descriptor_Descriptor(name, sizeHint, encode, decode, skip, view);
4362
+ return new Descriptor(name, sizeHint, encode, decode, skip, view);
4363
4363
  }
4364
4364
  /** Create a new descriptor without a specialized `View`. */
4365
4365
  static new(name, sizeHint, encode, decode, skip) {
4366
- return new descriptor_Descriptor(name, sizeHint, encode, decode, skip, null);
4366
+ return new Descriptor(name, sizeHint, encode, decode, skip, null);
4367
4367
  }
4368
4368
  constructor(
4369
4369
  /** Descriptive name of the coded data. */
@@ -4400,7 +4400,7 @@ class descriptor_Descriptor {
4400
4400
  }
4401
4401
  /** Return a new descriptor that converts data into some other type. */
4402
4402
  convert(input, output) {
4403
- return new descriptor_Descriptor(this.name, this.sizeHint, (e, elem) => this.encode(e, input(elem)), (d) => output(this.decode(d)), this.skip, this.View);
4403
+ return new Descriptor(this.name, this.sizeHint, (e, elem) => this.encode(e, input(elem)), (d) => output(this.decode(d)), this.skip, this.View);
4404
4404
  }
4405
4405
  /** Safely cast the descriptor value to a opaque type. */
4406
4406
  asOpaque() {
@@ -5098,51 +5098,51 @@ var descriptors_codec;
5098
5098
  return (len) => {
5099
5099
  let ret = cache.get(len);
5100
5100
  if (ret === undefined) {
5101
- ret = descriptor_Descriptor.new(`Bytes<${len}>`, exactHint(len), (e, v) => e.bytes(v), (d) => d.bytes(len), (s) => s.bytes(len));
5101
+ ret = Descriptor.new(`Bytes<${len}>`, exactHint(len), (e, v) => e.bytes(v), (d) => d.bytes(len), (s) => s.bytes(len));
5102
5102
  cache.set(len, ret);
5103
5103
  }
5104
5104
  return ret;
5105
5105
  };
5106
5106
  })();
5107
5107
  /** Variable-length U32. */
5108
- codec.varU32 = descriptor_Descriptor.new("var_u32", { bytes: 4, isExact: false }, (e, v) => e.varU32(v), (d) => d.varU32(), (d) => d.varU32());
5108
+ codec.varU32 = Descriptor.new("var_u32", { bytes: 4, isExact: false }, (e, v) => e.varU32(v), (d) => d.varU32(), (d) => d.varU32());
5109
5109
  /** Variable-length U64. */
5110
- codec.varU64 = descriptor_Descriptor.new("var_u64", { bytes: 8, isExact: false }, (e, v) => e.varU64(v), (d) => d.varU64(), (d) => d.varU64());
5110
+ codec.varU64 = Descriptor.new("var_u64", { bytes: 8, isExact: false }, (e, v) => e.varU64(v), (d) => d.varU64(), (d) => d.varU64());
5111
5111
  /** Unsigned 64-bit number. */
5112
- codec.u64 = descriptor_Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.u64(), (d) => d.u64(), codec.bytes(8));
5112
+ codec.u64 = Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.u64(), (d) => d.u64(), codec.bytes(8));
5113
5113
  /** Unsigned 32-bit number. */
5114
- codec.u32 = descriptor_Descriptor.withView("u32", exactHint(4), (e, v) => e.i32(v), (d) => d.u32(), (d) => d.u32(), codec.bytes(4));
5114
+ codec.u32 = Descriptor.withView("u32", exactHint(4), (e, v) => e.i32(v), (d) => d.u32(), (d) => d.u32(), codec.bytes(4));
5115
5115
  /** Unsigned 24-bit number. */
5116
- codec.u24 = descriptor_Descriptor.withView("u24", exactHint(3), (e, v) => e.i24(v), (d) => d.u24(), (d) => d.u24(), codec.bytes(3));
5116
+ codec.u24 = Descriptor.withView("u24", exactHint(3), (e, v) => e.i24(v), (d) => d.u24(), (d) => d.u24(), codec.bytes(3));
5117
5117
  /** Unsigned 16-bit number. */
5118
- codec.u16 = descriptor_Descriptor.withView("u16", exactHint(2), (e, v) => e.i16(v), (d) => d.u16(), (d) => d.u16(), codec.bytes(2));
5118
+ codec.u16 = Descriptor.withView("u16", exactHint(2), (e, v) => e.i16(v), (d) => d.u16(), (d) => d.u16(), codec.bytes(2));
5119
5119
  /** Unsigned 8-bit number. */
5120
- codec.u8 = descriptor_Descriptor.new("u8", exactHint(1), (e, v) => e.i8(v), (d) => d.u8(), (d) => d.u8());
5120
+ codec.u8 = Descriptor.new("u8", exactHint(1), (e, v) => e.i8(v), (d) => d.u8(), (d) => d.u8());
5121
5121
  /** Signed 64-bit number. */
5122
- codec.i64 = descriptor_Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.i64(), (s) => s.u64(), codec.bytes(8));
5122
+ codec.i64 = Descriptor.withView("u64", exactHint(8), (e, v) => e.i64(v), (d) => d.i64(), (s) => s.u64(), codec.bytes(8));
5123
5123
  /** Signed 32-bit number. */
5124
- codec.i32 = descriptor_Descriptor.withView("i32", exactHint(4), (e, v) => e.i32(v), (d) => d.i32(), (s) => s.u32(), codec.bytes(4));
5124
+ codec.i32 = Descriptor.withView("i32", exactHint(4), (e, v) => e.i32(v), (d) => d.i32(), (s) => s.u32(), codec.bytes(4));
5125
5125
  /** Signed 24-bit number. */
5126
- codec.i24 = descriptor_Descriptor.withView("i24", exactHint(3), (e, v) => e.i24(v), (d) => d.i24(), (s) => s.u24(), codec.bytes(3));
5126
+ codec.i24 = Descriptor.withView("i24", exactHint(3), (e, v) => e.i24(v), (d) => d.i24(), (s) => s.u24(), codec.bytes(3));
5127
5127
  /** Signed 16-bit number. */
5128
- codec.i16 = descriptor_Descriptor.withView("i16", exactHint(2), (e, v) => e.i16(v), (d) => d.i16(), (s) => s.u16(), codec.bytes(2));
5128
+ codec.i16 = Descriptor.withView("i16", exactHint(2), (e, v) => e.i16(v), (d) => d.i16(), (s) => s.u16(), codec.bytes(2));
5129
5129
  /** Signed 8-bit number. */
5130
- codec.i8 = descriptor_Descriptor.new("i8", exactHint(1), (e, v) => e.i8(v), (d) => d.i8(), (s) => s.u8());
5130
+ codec.i8 = Descriptor.new("i8", exactHint(1), (e, v) => e.i8(v), (d) => d.i8(), (s) => s.u8());
5131
5131
  /** 1-byte boolean value. */
5132
- codec.bool = descriptor_Descriptor.new("bool", exactHint(1), (e, v) => e.bool(v), (d) => d.bool(), (s) => s.bool());
5132
+ codec.bool = Descriptor.new("bool", exactHint(1), (e, v) => e.bool(v), (d) => d.bool(), (s) => s.bool());
5133
5133
  /** Variable-length bytes blob. */
5134
- codec.blob = descriptor_Descriptor.new("BytesBlob", { bytes: TYPICAL_SEQUENCE_LENGTH, isExact: false }, (e, v) => e.bytesBlob(v), (d) => d.bytesBlob(), (s) => s.bytesBlob());
5134
+ codec.blob = Descriptor.new("BytesBlob", { bytes: TYPICAL_SEQUENCE_LENGTH, isExact: false }, (e, v) => e.bytesBlob(v), (d) => d.bytesBlob(), (s) => s.bytesBlob());
5135
5135
  /** String encoded as variable-length bytes blob. */
5136
- 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);
5136
+ 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);
5137
5137
  /** Variable-length bit vector. */
5138
- codec.bitVecVarLen = descriptor_Descriptor.new("BitVec[?]", { bytes: TYPICAL_SEQUENCE_LENGTH >>> 3, isExact: false }, (e, v) => e.bitVecVarLen(v), (d) => d.bitVecVarLen(), (s) => s.bitVecVarLen());
5138
+ codec.bitVecVarLen = Descriptor.new("BitVec[?]", { bytes: TYPICAL_SEQUENCE_LENGTH >>> 3, isExact: false }, (e, v) => e.bitVecVarLen(v), (d) => d.bitVecVarLen(), (s) => s.bitVecVarLen());
5139
5139
  /** Fixed-length bit vector. */
5140
- codec.bitVecFixLen = (bitLen) => descriptor_Descriptor.new(`BitVec[${bitLen}]`, exactHint(bitLen >>> 3), (e, v) => e.bitVecFixLen(v), (d) => d.bitVecFixLen(bitLen), (s) => s.bitVecFixLen(bitLen));
5140
+ codec.bitVecFixLen = (bitLen) => Descriptor.new(`BitVec[${bitLen}]`, exactHint(bitLen >>> 3), (e, v) => e.bitVecFixLen(v), (d) => d.bitVecFixLen(bitLen), (s) => s.bitVecFixLen(bitLen));
5141
5141
  /** Optionality wrapper for given type. */
5142
5142
  codec.optional = (type) => {
5143
- 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));
5143
+ 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));
5144
5144
  if (hasUniqueView(type)) {
5145
- return descriptor_Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.optional(type.View));
5145
+ return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.optional(type.View));
5146
5146
  }
5147
5147
  return self;
5148
5148
  };
@@ -5153,7 +5153,7 @@ var descriptors_codec;
5153
5153
  }) => {
5154
5154
  const name = `Sequence<${type.name}>[?]`;
5155
5155
  const typicalLength = options.typicalLength ?? TYPICAL_SEQUENCE_LENGTH;
5156
- return descriptor_Descriptor.withView(name, { bytes: typicalLength * type.sizeHint.bytes, isExact: false }, (e, v) => {
5156
+ return Descriptor.withView(name, { bytes: typicalLength * type.sizeHint.bytes, isExact: false }, (e, v) => {
5157
5157
  validateLength(options, v.length, name);
5158
5158
  e.sequenceVarLen(type, v);
5159
5159
  }, (d) => {
@@ -5167,10 +5167,10 @@ var descriptors_codec;
5167
5167
  }, sequenceViewVarLen(type, options));
5168
5168
  };
5169
5169
  /** Fixed-length sequence of given type. */
5170
- 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 }));
5170
+ 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 }));
5171
5171
  /** Small dictionary codec. */
5172
5172
  codec.dictionary = (key, value, { sortKeys, fixedLength, }) => {
5173
- const self = descriptor_Descriptor.new(`Dictionary<${key.name}, ${value.name}>[${fixedLength ?? "?"}]`, {
5173
+ const self = Descriptor.new(`Dictionary<${key.name}, ${value.name}>[${fixedLength ?? "?"}]`, {
5174
5174
  bytes: fixedLength !== undefined
5175
5175
  ? fixedLength * addSizeHints(key.sizeHint, value.sizeHint).bytes
5176
5176
  : TYPICAL_DICTIONARY_LENGTH * (addSizeHints(key.sizeHint, value.sizeHint).bytes ?? 0),
@@ -5209,13 +5209,13 @@ var descriptors_codec;
5209
5209
  s.sequenceFixLen(value, len);
5210
5210
  });
5211
5211
  if (hasUniqueView(value)) {
5212
- return descriptor_Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.dictionary(key, value.View, { sortKeys, fixedLength }));
5212
+ return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.dictionary(key, value.View, { sortKeys, fixedLength }));
5213
5213
  }
5214
5214
  return self;
5215
5215
  };
5216
5216
  /** Encoding of pair of two values. */
5217
5217
  codec.pair = (a, b) => {
5218
- const self = descriptor_Descriptor.new(`Pair<${a.name}, ${b.name}>`, addSizeHints(a.sizeHint, b.sizeHint), (e, elem) => {
5218
+ const self = Descriptor.new(`Pair<${a.name}, ${b.name}>`, addSizeHints(a.sizeHint, b.sizeHint), (e, elem) => {
5219
5219
  a.encode(e, elem[0]);
5220
5220
  b.encode(e, elem[1]);
5221
5221
  }, (d) => {
@@ -5227,14 +5227,14 @@ var descriptors_codec;
5227
5227
  b.skip(s);
5228
5228
  });
5229
5229
  if (hasUniqueView(a) && hasUniqueView(b)) {
5230
- return descriptor_Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.pair(a.View, b.View));
5230
+ return Descriptor.withView(self.name, self.sizeHint, self.encode, self.decode, self.skip, codec.pair(a.View, b.View));
5231
5231
  }
5232
5232
  return self;
5233
5233
  };
5234
5234
  /** Custom encoding / decoding logic. */
5235
- codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => descriptor_Descriptor.new(name, sizeHint, encode, decode, skip);
5235
+ codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
5236
5236
  /** Choose a descriptor depending on the encoding/decoding context. */
5237
- 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);
5237
+ 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);
5238
5238
  /**
5239
5239
  * A descriptor for a more complex POJO.
5240
5240
  *
@@ -5271,7 +5271,7 @@ var descriptors_codec;
5271
5271
  };
5272
5272
  const view = objectView(Class, descriptors, sizeHint, skipper);
5273
5273
  // and create the descriptor for the entire class.
5274
- return descriptor_Descriptor.withView(Class.name, sizeHint, (e, t) => {
5274
+ return Descriptor.withView(Class.name, sizeHint, (e, t) => {
5275
5275
  forEachDescriptor(descriptors, (key, descriptor) => {
5276
5276
  const value = t[key];
5277
5277
  descriptor.encode(e, value);
@@ -5322,7 +5322,7 @@ function objectView(Class, descriptors, sizeHint, skipper) {
5322
5322
  });
5323
5323
  }
5324
5324
  });
5325
- return descriptor_Descriptor.new(`View<${Class.name}>`, sizeHint, (e, t) => {
5325
+ return Descriptor.new(`View<${Class.name}>`, sizeHint, (e, t) => {
5326
5326
  const encoded = t.encoded();
5327
5327
  e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
5328
5328
  }, (d) => {
@@ -5341,7 +5341,7 @@ function sequenceViewVarLen(type, options) {
5341
5341
  validateLength(options, length, name);
5342
5342
  return s.sequenceFixLen(type, length);
5343
5343
  };
5344
- return descriptor_Descriptor.new(name, sizeHint, (e, t) => {
5344
+ return Descriptor.new(name, sizeHint, (e, t) => {
5345
5345
  validateLength(options, t.length, name);
5346
5346
  const encoded = t.encoded();
5347
5347
  e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
@@ -5357,7 +5357,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
5357
5357
  const skipper = (s) => s.sequenceFixLen(type, fixedLength);
5358
5358
  const view = type.name !== type.View.name ? `, ${type.View.name}` : "";
5359
5359
  const name = `SeqView<${type.name}${view}>[${fixedLength}]`;
5360
- return descriptor_Descriptor.new(name, sizeHint, (e, t) => {
5360
+ return Descriptor.new(name, sizeHint, (e, t) => {
5361
5361
  const encoded = t.encoded();
5362
5362
  e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
5363
5363
  }, (d) => {
@@ -7205,7 +7205,7 @@ const codecFixedSizeArray = (val, len) => {
7205
7205
  };
7206
7206
  /** Codec for a hash-dictionary. */
7207
7207
  const codecHashDictionary = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH, compare = (a, b) => extractKey(a).compare(extractKey(b)), } = {}) => {
7208
- return descriptor_Descriptor.new(`HashDictionary<${value.name}>[?]`, {
7208
+ return Descriptor.new(`HashDictionary<${value.name}>[?]`, {
7209
7209
  bytes: typicalLength * value.sizeHint.bytes,
7210
7210
  isExact: false,
7211
7211
  }, (e, v) => {
@@ -9172,6 +9172,13 @@ const W_T = 128;
9172
9172
  /** `W_M`: The maximum number of exports in a work-package. */
9173
9173
  const W_X = 3_072;
9174
9174
  // TODO [ToDr] Not sure where these should live yet :(
9175
+ /**
9176
+ * `S`: The minimum public service index.
9177
+ * Services of indices below these may only be created by the Registrar.
9178
+ *
9179
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
9180
+ */
9181
+ const MIN_PUBLIC_SERVICE_INDEX = (/* unused pure expression or super */ null && (2 ** 16));
9175
9182
  /**
9176
9183
  * `J`: The maximum sum of dependency items in a work-report.
9177
9184
  *
@@ -9183,9 +9190,209 @@ const AUTHORIZATION_QUEUE_SIZE = Q;
9183
9190
  /** `O`: Maximal authorization pool size. */
9184
9191
  const MAX_AUTH_POOL_SIZE = O;
9185
9192
 
9193
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
9194
+ const MAX_VALUE = 4294967295;
9195
+ const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
9196
+ const MIN_VALUE = (/* unused pure expression or super */ null && (-(2 ** 31)));
9197
+ const MAX_SHIFT_U32 = 32;
9198
+ const MAX_SHIFT_U64 = 64n;
9199
+
9200
+ ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
9201
+
9202
+
9203
+
9204
+
9205
+
9206
+
9207
+ /**
9208
+ * `B_S`: The basic minimum balance which all services require.
9209
+ *
9210
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
9211
+ */
9212
+ const BASE_SERVICE_BALANCE = 100n;
9213
+ /**
9214
+ * `B_I`: The additional minimum balance required per item of elective service state.
9215
+ *
9216
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
9217
+ */
9218
+ const ELECTIVE_ITEM_BALANCE = 10n;
9219
+ /**
9220
+ * `B_L`: The additional minimum balance required per octet of elective service state.
9221
+ *
9222
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
9223
+ */
9224
+ const ELECTIVE_BYTE_BALANCE = 1n;
9225
+ const zeroSizeHint = {
9226
+ bytes: 0,
9227
+ isExact: true,
9228
+ };
9229
+ /** 0-byte read, return given default value */
9230
+ const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
9231
+ /** Encode and decode object with leading version number. */
9232
+ const codecWithVersion = (val) => Descriptor.new("withVersion", {
9233
+ bytes: val.sizeHint.bytes + 8,
9234
+ isExact: false,
9235
+ }, (e, v) => {
9236
+ e.varU64(0n);
9237
+ val.encode(e, v);
9238
+ }, (d) => {
9239
+ const version = d.varU64();
9240
+ if (version !== 0n) {
9241
+ throw new Error("Non-zero version is not supported!");
9242
+ }
9243
+ return val.decode(d);
9244
+ }, (s) => {
9245
+ s.varU64();
9246
+ val.skip(s);
9247
+ });
9248
+ /**
9249
+ * Service account details.
9250
+ *
9251
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
9252
+ */
9253
+ class ServiceAccountInfo extends WithDebug {
9254
+ codeHash;
9255
+ balance;
9256
+ accumulateMinGas;
9257
+ onTransferMinGas;
9258
+ storageUtilisationBytes;
9259
+ gratisStorage;
9260
+ storageUtilisationCount;
9261
+ created;
9262
+ lastAccumulation;
9263
+ parentService;
9264
+ static Codec = descriptors_codec.Class(ServiceAccountInfo, {
9265
+ codeHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
9266
+ balance: descriptors_codec.u64,
9267
+ accumulateMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
9268
+ onTransferMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
9269
+ storageUtilisationBytes: descriptors_codec.u64,
9270
+ gratisStorage: descriptors_codec.u64,
9271
+ storageUtilisationCount: descriptors_codec.u32,
9272
+ created: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
9273
+ lastAccumulation: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
9274
+ parentService: descriptors_codec.u32.convert((x) => x, tryAsServiceId),
9275
+ });
9276
+ static create(a) {
9277
+ return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
9278
+ }
9279
+ /**
9280
+ * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
9281
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
9282
+ */
9283
+ static calculateThresholdBalance(items, bytes, gratisStorage) {
9284
+ const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
9285
+ if (storageCost < 0n) {
9286
+ return tryAsU64(0);
9287
+ }
9288
+ if (storageCost >= 2n ** 64n) {
9289
+ return tryAsU64(2n ** 64n - 1n);
9290
+ }
9291
+ return tryAsU64(storageCost);
9292
+ }
9293
+ constructor(
9294
+ /** `a_c`: Hash of the service code. */
9295
+ codeHash,
9296
+ /** `a_b`: Current account balance. */
9297
+ balance,
9298
+ /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
9299
+ accumulateMinGas,
9300
+ /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
9301
+ onTransferMinGas,
9302
+ /** `a_o`: Total number of octets in storage. */
9303
+ storageUtilisationBytes,
9304
+ /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
9305
+ gratisStorage,
9306
+ /** `a_i`: Number of items in storage. */
9307
+ storageUtilisationCount,
9308
+ /** `a_r`: Creation account time slot. */
9309
+ created,
9310
+ /** `a_a`: Most recent accumulation time slot. */
9311
+ lastAccumulation,
9312
+ /** `a_p`: Parent service ID. */
9313
+ parentService) {
9314
+ super();
9315
+ this.codeHash = codeHash;
9316
+ this.balance = balance;
9317
+ this.accumulateMinGas = accumulateMinGas;
9318
+ this.onTransferMinGas = onTransferMinGas;
9319
+ this.storageUtilisationBytes = storageUtilisationBytes;
9320
+ this.gratisStorage = gratisStorage;
9321
+ this.storageUtilisationCount = storageUtilisationCount;
9322
+ this.created = created;
9323
+ this.lastAccumulation = lastAccumulation;
9324
+ this.parentService = parentService;
9325
+ }
9326
+ }
9327
+ class service_PreimageItem extends WithDebug {
9328
+ hash;
9329
+ blob;
9330
+ static Codec = descriptors_codec.Class(service_PreimageItem, {
9331
+ hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
9332
+ blob: descriptors_codec.blob,
9333
+ });
9334
+ static create({ hash, blob }) {
9335
+ return new service_PreimageItem(hash, blob);
9336
+ }
9337
+ constructor(hash, blob) {
9338
+ super();
9339
+ this.hash = hash;
9340
+ this.blob = blob;
9341
+ }
9342
+ }
9343
+ class StorageItem extends WithDebug {
9344
+ key;
9345
+ value;
9346
+ static Codec = descriptors_codec.Class(StorageItem, {
9347
+ key: descriptors_codec.blob.convert((i) => i, (o) => opaque_asOpaqueType(o)),
9348
+ value: descriptors_codec.blob,
9349
+ });
9350
+ static create({ key, value }) {
9351
+ return new StorageItem(key, value);
9352
+ }
9353
+ constructor(key, value) {
9354
+ super();
9355
+ this.key = key;
9356
+ this.value = value;
9357
+ }
9358
+ }
9359
+ const MAX_LOOKUP_HISTORY_SLOTS = 3;
9360
+ function tryAsLookupHistorySlots(items) {
9361
+ const knownSize = sized_array_asKnownSize(items);
9362
+ if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
9363
+ throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
9364
+ }
9365
+ return knownSize;
9366
+ }
9367
+ /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
9368
+ class service_LookupHistoryItem {
9369
+ hash;
9370
+ length;
9371
+ slots;
9372
+ constructor(hash, length,
9373
+ /**
9374
+ * Preimage availability history as a sequence of time slots.
9375
+ * See PreimageStatus and the following GP fragment for more details.
9376
+ * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
9377
+ slots) {
9378
+ this.hash = hash;
9379
+ this.length = length;
9380
+ this.slots = slots;
9381
+ }
9382
+ static isRequested(item) {
9383
+ if ("slots" in item) {
9384
+ return item.slots.length === 0;
9385
+ }
9386
+ return item.length === 0;
9387
+ }
9388
+ }
9389
+
9186
9390
  ;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
9187
9391
 
9188
9392
 
9393
+
9394
+
9395
+
9189
9396
  /** Dictionary entry of services that auto-accumulate every block. */
9190
9397
  class AutoAccumulate {
9191
9398
  service;
@@ -9207,39 +9414,50 @@ class AutoAccumulate {
9207
9414
  }
9208
9415
  }
9209
9416
  /**
9210
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11da0111da01?v=0.6.7
9417
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
9211
9418
  */
9212
9419
  class PrivilegedServices {
9213
9420
  manager;
9214
- authManager;
9215
- validatorsManager;
9421
+ delegator;
9422
+ registrar;
9423
+ assigners;
9216
9424
  autoAccumulateServices;
9425
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
9217
9426
  static Codec = descriptors_codec.Class(PrivilegedServices, {
9218
9427
  manager: descriptors_codec.u32.asOpaque(),
9219
- authManager: codecPerCore(descriptors_codec.u32.asOpaque()),
9220
- validatorsManager: descriptors_codec.u32.asOpaque(),
9428
+ assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
9429
+ delegator: descriptors_codec.u32.asOpaque(),
9430
+ registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
9431
+ ? descriptors_codec.u32.asOpaque()
9432
+ : ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
9221
9433
  autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
9222
9434
  });
9223
- static create({ manager, authManager, validatorsManager, autoAccumulateServices }) {
9224
- return new PrivilegedServices(manager, authManager, validatorsManager, autoAccumulateServices);
9435
+ static create(a) {
9436
+ return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
9225
9437
  }
9226
9438
  constructor(
9227
9439
  /**
9228
- * `chi_m`: The first, χm, is the index of the manager service which is
9229
- * the service able to effect an alteration of χ from block to block,
9440
+ * `χ_M`: Manages alteration of χ from block to block,
9230
9441
  * as well as bestow services with storage deposit credits.
9231
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11a40111a801?v=0.6.7
9442
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
9232
9443
  */
9233
9444
  manager,
9234
- /** `chi_a`: Manages authorization queue one for each core. */
9235
- authManager,
9236
- /** `chi_v`: Managers validator keys. */
9237
- validatorsManager,
9238
- /** `chi_g`: Dictionary of services that auto-accumulate every block with their gas limit. */
9445
+ /** `χ_V`: Managers validator keys. */
9446
+ delegator,
9447
+ /**
9448
+ * `χ_R`: Manages the creation of services in protected range.
9449
+ *
9450
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
9451
+ */
9452
+ registrar,
9453
+ /** `χ_A`: Manages authorization queue one for each core. */
9454
+ assigners,
9455
+ /** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
9239
9456
  autoAccumulateServices) {
9240
9457
  this.manager = manager;
9241
- this.authManager = authManager;
9242
- this.validatorsManager = validatorsManager;
9458
+ this.delegator = delegator;
9459
+ this.registrar = registrar;
9460
+ this.assigners = assigners;
9243
9461
  this.autoAccumulateServices = autoAccumulateServices;
9244
9462
  }
9245
9463
  }
@@ -9327,7 +9545,7 @@ class RecentBlocks extends WithDebug {
9327
9545
  */
9328
9546
  class RecentBlocksHistory extends WithDebug {
9329
9547
  current;
9330
- static Codec = descriptor_Descriptor.new("RecentBlocksHistory", RecentBlocks.Codec.sizeHint, (encoder, value) => RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
9548
+ static Codec = Descriptor.new("RecentBlocksHistory", RecentBlocks.Codec.sizeHint, (encoder, value) => RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
9331
9549
  const recentBlocks = RecentBlocks.Codec.decode(decoder);
9332
9550
  return RecentBlocksHistory.create(recentBlocks);
9333
9551
  }, (skip) => {
@@ -9524,196 +9742,6 @@ class SafroleData {
9524
9742
  }
9525
9743
  }
9526
9744
 
9527
- ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
9528
-
9529
-
9530
-
9531
-
9532
-
9533
-
9534
- /**
9535
- * `B_S`: The basic minimum balance which all services require.
9536
- *
9537
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
9538
- */
9539
- const BASE_SERVICE_BALANCE = 100n;
9540
- /**
9541
- * `B_I`: The additional minimum balance required per item of elective service state.
9542
- *
9543
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
9544
- */
9545
- const ELECTIVE_ITEM_BALANCE = 10n;
9546
- /**
9547
- * `B_L`: The additional minimum balance required per octet of elective service state.
9548
- *
9549
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
9550
- */
9551
- const ELECTIVE_BYTE_BALANCE = 1n;
9552
- const zeroSizeHint = {
9553
- bytes: 0,
9554
- isExact: true,
9555
- };
9556
- /** 0-byte read, return given default value */
9557
- const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
9558
- /** Encode and decode object with leading version number. */
9559
- const codecWithVersion = (val) => descriptor_Descriptor.new("withVersion", {
9560
- bytes: val.sizeHint.bytes + 8,
9561
- isExact: false,
9562
- }, (e, v) => {
9563
- e.varU64(0n);
9564
- val.encode(e, v);
9565
- }, (d) => {
9566
- const version = d.varU64();
9567
- if (version !== 0n) {
9568
- throw new Error("Non-zero version is not supported!");
9569
- }
9570
- return val.decode(d);
9571
- }, (s) => {
9572
- s.varU64();
9573
- val.skip(s);
9574
- });
9575
- /**
9576
- * Service account details.
9577
- *
9578
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
9579
- */
9580
- class ServiceAccountInfo extends WithDebug {
9581
- codeHash;
9582
- balance;
9583
- accumulateMinGas;
9584
- onTransferMinGas;
9585
- storageUtilisationBytes;
9586
- gratisStorage;
9587
- storageUtilisationCount;
9588
- created;
9589
- lastAccumulation;
9590
- parentService;
9591
- static Codec = descriptors_codec.Class(ServiceAccountInfo, {
9592
- codeHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
9593
- balance: descriptors_codec.u64,
9594
- accumulateMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
9595
- onTransferMinGas: descriptors_codec.u64.convert((x) => x, tryAsServiceGas),
9596
- storageUtilisationBytes: descriptors_codec.u64,
9597
- gratisStorage: descriptors_codec.u64,
9598
- storageUtilisationCount: descriptors_codec.u32,
9599
- created: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
9600
- lastAccumulation: descriptors_codec.u32.convert((x) => x, common_tryAsTimeSlot),
9601
- parentService: descriptors_codec.u32.convert((x) => x, tryAsServiceId),
9602
- });
9603
- static create(a) {
9604
- return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
9605
- }
9606
- /**
9607
- * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
9608
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
9609
- */
9610
- static calculateThresholdBalance(items, bytes, gratisStorage) {
9611
- const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
9612
- if (storageCost < 0n) {
9613
- return tryAsU64(0);
9614
- }
9615
- if (storageCost >= 2n ** 64n) {
9616
- return tryAsU64(2n ** 64n - 1n);
9617
- }
9618
- return tryAsU64(storageCost);
9619
- }
9620
- constructor(
9621
- /** `a_c`: Hash of the service code. */
9622
- codeHash,
9623
- /** `a_b`: Current account balance. */
9624
- balance,
9625
- /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
9626
- accumulateMinGas,
9627
- /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
9628
- onTransferMinGas,
9629
- /** `a_o`: Total number of octets in storage. */
9630
- storageUtilisationBytes,
9631
- /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
9632
- gratisStorage,
9633
- /** `a_i`: Number of items in storage. */
9634
- storageUtilisationCount,
9635
- /** `a_r`: Creation account time slot. */
9636
- created,
9637
- /** `a_a`: Most recent accumulation time slot. */
9638
- lastAccumulation,
9639
- /** `a_p`: Parent service ID. */
9640
- parentService) {
9641
- super();
9642
- this.codeHash = codeHash;
9643
- this.balance = balance;
9644
- this.accumulateMinGas = accumulateMinGas;
9645
- this.onTransferMinGas = onTransferMinGas;
9646
- this.storageUtilisationBytes = storageUtilisationBytes;
9647
- this.gratisStorage = gratisStorage;
9648
- this.storageUtilisationCount = storageUtilisationCount;
9649
- this.created = created;
9650
- this.lastAccumulation = lastAccumulation;
9651
- this.parentService = parentService;
9652
- }
9653
- }
9654
- class service_PreimageItem extends WithDebug {
9655
- hash;
9656
- blob;
9657
- static Codec = descriptors_codec.Class(service_PreimageItem, {
9658
- hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
9659
- blob: descriptors_codec.blob,
9660
- });
9661
- static create({ hash, blob }) {
9662
- return new service_PreimageItem(hash, blob);
9663
- }
9664
- constructor(hash, blob) {
9665
- super();
9666
- this.hash = hash;
9667
- this.blob = blob;
9668
- }
9669
- }
9670
- class StorageItem extends WithDebug {
9671
- key;
9672
- value;
9673
- static Codec = descriptors_codec.Class(StorageItem, {
9674
- key: descriptors_codec.blob.convert((i) => i, (o) => opaque_asOpaqueType(o)),
9675
- value: descriptors_codec.blob,
9676
- });
9677
- static create({ key, value }) {
9678
- return new StorageItem(key, value);
9679
- }
9680
- constructor(key, value) {
9681
- super();
9682
- this.key = key;
9683
- this.value = value;
9684
- }
9685
- }
9686
- const MAX_LOOKUP_HISTORY_SLOTS = 3;
9687
- function tryAsLookupHistorySlots(items) {
9688
- const knownSize = sized_array_asKnownSize(items);
9689
- if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
9690
- throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
9691
- }
9692
- return knownSize;
9693
- }
9694
- /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
9695
- class service_LookupHistoryItem {
9696
- hash;
9697
- length;
9698
- slots;
9699
- constructor(hash, length,
9700
- /**
9701
- * Preimage availability history as a sequence of time slots.
9702
- * See PreimageStatus and the following GP fragment for more details.
9703
- * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
9704
- slots) {
9705
- this.hash = hash;
9706
- this.length = length;
9707
- this.slots = slots;
9708
- }
9709
- static isRequested(item) {
9710
- if ("slots" in item) {
9711
- return item.slots.length === 0;
9712
- }
9713
- return item.length === 0;
9714
- }
9715
- }
9716
-
9717
9745
  ;// CONCATENATED MODULE: ./packages/jam/state/state.ts
9718
9746
  /**
9719
9747
  * In addition to the entropy accumulator η_0, we retain
@@ -10150,6 +10178,7 @@ class StatisticsData {
10150
10178
 
10151
10179
 
10152
10180
 
10181
+
10153
10182
 
10154
10183
 
10155
10184
  var in_memory_state_UpdateError;
@@ -10553,8 +10582,9 @@ class InMemoryState extends WithDebug {
10553
10582
  epochRoot: bytes_Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
10554
10583
  privilegedServices: PrivilegedServices.create({
10555
10584
  manager: tryAsServiceId(0),
10556
- authManager: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
10557
- validatorsManager: tryAsServiceId(0),
10585
+ assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
10586
+ delegator: tryAsServiceId(0),
10587
+ registrar: tryAsServiceId(MAX_VALUE),
10558
10588
  autoAccumulateServices: [],
10559
10589
  }),
10560
10590
  accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
@@ -10790,7 +10820,7 @@ var serialize;
10790
10820
  * determine the boundary of the bytes, so it can only be used
10791
10821
  * as the last element of the codec and can't be used in sequences!
10792
10822
  */
10793
- 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()));
10823
+ 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()));
10794
10824
 
10795
10825
  ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
10796
10826
 
@@ -12101,7 +12131,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
12101
12131
  }
12102
12132
  return Ordering.Equal;
12103
12133
  }, } = {}) => {
12104
- return descriptor_Descriptor.new(`Map<${value.name}>[?]`, {
12134
+ return Descriptor.new(`Map<${value.name}>[?]`, {
12105
12135
  bytes: typicalLength * value.sizeHint.bytes,
12106
12136
  isExact: false,
12107
12137
  }, (e, v) => {