@typeberry/lib 0.1.3-c2321fb → 0.1.3-ca63b35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/index.cjs +314 -213
  2. package/index.d.ts +380 -238
  3. package/index.js +314 -213
  4. package/package.json +1 -1
package/index.cjs CHANGED
@@ -38,8 +38,9 @@ function parseCurrentVersion(env) {
38
38
  }
39
39
  }
40
40
  function parseCurrentSuite(env) {
41
- if (env === undefined)
41
+ if (env === undefined) {
42
42
  return undefined;
43
+ }
43
44
  switch (env) {
44
45
  case TestSuite.W3F_DAVXY:
45
46
  case TestSuite.JAMDUNA:
@@ -459,10 +460,12 @@ function deepEqual(actual, expected, { context = [], errorsCollector, ignore = [
459
460
  .sort((a, b) => {
460
461
  const aKey = `${a.key}`;
461
462
  const bKey = `${b.key}`;
462
- if (aKey < bKey)
463
+ if (aKey < bKey) {
463
464
  return -1;
464
- if (bKey < aKey)
465
+ }
466
+ if (bKey < aKey) {
465
467
  return 1;
468
+ }
466
469
  return 0;
467
470
  });
468
471
  };
@@ -4355,6 +4358,47 @@ var index$o = /*#__PURE__*/Object.freeze({
4355
4358
  keccak: keccak
4356
4359
  });
4357
4360
 
4361
+ /**
4362
+ * A utility class providing a readonly view over a portion of an array without copying it.
4363
+ */
4364
+ class ArrayView {
4365
+ start;
4366
+ end;
4367
+ source;
4368
+ length;
4369
+ constructor(source, start, end) {
4370
+ this.start = start;
4371
+ this.end = end;
4372
+ this.source = source;
4373
+ this.length = end - start;
4374
+ }
4375
+ static from(source, start = 0, end = source.length) {
4376
+ check `
4377
+ ${start >= 0 && end <= source.length && start <= end}
4378
+ Invalid start (${start})/end (${end}) for ArrayView
4379
+ `;
4380
+ return new ArrayView(source, start, end);
4381
+ }
4382
+ get(i) {
4383
+ check `
4384
+ ${i >= 0 && i < this.length}
4385
+ Index out of bounds: ${i} < ${this.length}
4386
+ `;
4387
+ return this.source[this.start + i];
4388
+ }
4389
+ subview(from, to = this.length) {
4390
+ return ArrayView.from(this.source, this.start + from, this.start + to);
4391
+ }
4392
+ toArray() {
4393
+ return this.source.slice(this.start, this.end);
4394
+ }
4395
+ *[Symbol.iterator]() {
4396
+ for (let i = this.start; i < this.end; i++) {
4397
+ yield this.source[i];
4398
+ }
4399
+ }
4400
+ }
4401
+
4358
4402
  /** A map which uses hashes as keys. */
4359
4403
  class HashDictionary {
4360
4404
  // TODO [ToDr] [crit] We can't use `TrieHash` directly in the map,
@@ -4942,6 +4986,7 @@ class TruncatedHashDictionary {
4942
4986
 
4943
4987
  var index$n = /*#__PURE__*/Object.freeze({
4944
4988
  __proto__: null,
4989
+ ArrayView: ArrayView,
4945
4990
  FixedSizeArray: FixedSizeArray,
4946
4991
  HashDictionary: HashDictionary,
4947
4992
  HashSet: HashSet,
@@ -8109,7 +8154,6 @@ const O = 8;
8109
8154
  const Q = 80;
8110
8155
  /** `W_T`: The size of a transfer memo in octets. */
8111
8156
  const W_T = 128;
8112
- // TODO [ToDr] Not sure where these should live yet :(
8113
8157
  /**
8114
8158
  * `J`: The maximum sum of dependency items in a work-report.
8115
8159
  *
@@ -8121,6 +8165,194 @@ const AUTHORIZATION_QUEUE_SIZE = Q;
8121
8165
  /** `O`: Maximal authorization pool size. */
8122
8166
  const MAX_AUTH_POOL_SIZE = O;
8123
8167
 
8168
+ const MAX_VALUE = 4294967295;
8169
+ const MIN_VALUE = -2147483648;
8170
+ const MAX_SHIFT_U32 = 32;
8171
+ const MAX_SHIFT_U64 = 64n;
8172
+
8173
+ /**
8174
+ * `B_S`: The basic minimum balance which all services require.
8175
+ *
8176
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
8177
+ */
8178
+ const BASE_SERVICE_BALANCE = 100n;
8179
+ /**
8180
+ * `B_I`: The additional minimum balance required per item of elective service state.
8181
+ *
8182
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
8183
+ */
8184
+ const ELECTIVE_ITEM_BALANCE = 10n;
8185
+ /**
8186
+ * `B_L`: The additional minimum balance required per octet of elective service state.
8187
+ *
8188
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
8189
+ */
8190
+ const ELECTIVE_BYTE_BALANCE = 1n;
8191
+ const zeroSizeHint = {
8192
+ bytes: 0,
8193
+ isExact: true,
8194
+ };
8195
+ /** 0-byte read, return given default value */
8196
+ const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
8197
+ /** Encode and decode object with leading version number. */
8198
+ const codecWithVersion = (val) => Descriptor.new("withVersion", {
8199
+ bytes: val.sizeHint.bytes + 8,
8200
+ isExact: false,
8201
+ }, (e, v) => {
8202
+ e.varU64(0n);
8203
+ val.encode(e, v);
8204
+ }, (d) => {
8205
+ const version = d.varU64();
8206
+ if (version !== 0n) {
8207
+ throw new Error("Non-zero version is not supported!");
8208
+ }
8209
+ return val.decode(d);
8210
+ }, (s) => {
8211
+ s.varU64();
8212
+ val.skip(s);
8213
+ });
8214
+ /**
8215
+ * Service account details.
8216
+ *
8217
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
8218
+ */
8219
+ class ServiceAccountInfo extends WithDebug {
8220
+ codeHash;
8221
+ balance;
8222
+ accumulateMinGas;
8223
+ onTransferMinGas;
8224
+ storageUtilisationBytes;
8225
+ gratisStorage;
8226
+ storageUtilisationCount;
8227
+ created;
8228
+ lastAccumulation;
8229
+ parentService;
8230
+ static Codec = codec$1.Class(ServiceAccountInfo, {
8231
+ codeHash: codec$1.bytes(HASH_SIZE).asOpaque(),
8232
+ balance: codec$1.u64,
8233
+ accumulateMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
8234
+ onTransferMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
8235
+ storageUtilisationBytes: codec$1.u64,
8236
+ gratisStorage: codec$1.u64,
8237
+ storageUtilisationCount: codec$1.u32,
8238
+ created: codec$1.u32.convert((x) => x, tryAsTimeSlot),
8239
+ lastAccumulation: codec$1.u32.convert((x) => x, tryAsTimeSlot),
8240
+ parentService: codec$1.u32.convert((x) => x, tryAsServiceId),
8241
+ });
8242
+ static create(a) {
8243
+ return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
8244
+ }
8245
+ /**
8246
+ * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
8247
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
8248
+ */
8249
+ static calculateThresholdBalance(items, bytes, gratisStorage) {
8250
+ const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
8251
+ if (storageCost < 0n) {
8252
+ return tryAsU64(0);
8253
+ }
8254
+ if (storageCost >= 2n ** 64n) {
8255
+ return tryAsU64(2n ** 64n - 1n);
8256
+ }
8257
+ return tryAsU64(storageCost);
8258
+ }
8259
+ constructor(
8260
+ /** `a_c`: Hash of the service code. */
8261
+ codeHash,
8262
+ /** `a_b`: Current account balance. */
8263
+ balance,
8264
+ /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
8265
+ accumulateMinGas,
8266
+ /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
8267
+ onTransferMinGas,
8268
+ /** `a_o`: Total number of octets in storage. */
8269
+ storageUtilisationBytes,
8270
+ /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
8271
+ gratisStorage,
8272
+ /** `a_i`: Number of items in storage. */
8273
+ storageUtilisationCount,
8274
+ /** `a_r`: Creation account time slot. */
8275
+ created,
8276
+ /** `a_a`: Most recent accumulation time slot. */
8277
+ lastAccumulation,
8278
+ /** `a_p`: Parent service ID. */
8279
+ parentService) {
8280
+ super();
8281
+ this.codeHash = codeHash;
8282
+ this.balance = balance;
8283
+ this.accumulateMinGas = accumulateMinGas;
8284
+ this.onTransferMinGas = onTransferMinGas;
8285
+ this.storageUtilisationBytes = storageUtilisationBytes;
8286
+ this.gratisStorage = gratisStorage;
8287
+ this.storageUtilisationCount = storageUtilisationCount;
8288
+ this.created = created;
8289
+ this.lastAccumulation = lastAccumulation;
8290
+ this.parentService = parentService;
8291
+ }
8292
+ }
8293
+ class PreimageItem extends WithDebug {
8294
+ hash;
8295
+ blob;
8296
+ static Codec = codec$1.Class(PreimageItem, {
8297
+ hash: codec$1.bytes(HASH_SIZE).asOpaque(),
8298
+ blob: codec$1.blob,
8299
+ });
8300
+ static create({ hash, blob }) {
8301
+ return new PreimageItem(hash, blob);
8302
+ }
8303
+ constructor(hash, blob) {
8304
+ super();
8305
+ this.hash = hash;
8306
+ this.blob = blob;
8307
+ }
8308
+ }
8309
+ class StorageItem extends WithDebug {
8310
+ key;
8311
+ value;
8312
+ static Codec = codec$1.Class(StorageItem, {
8313
+ key: codec$1.blob.convert((i) => i, (o) => asOpaqueType(o)),
8314
+ value: codec$1.blob,
8315
+ });
8316
+ static create({ key, value }) {
8317
+ return new StorageItem(key, value);
8318
+ }
8319
+ constructor(key, value) {
8320
+ super();
8321
+ this.key = key;
8322
+ this.value = value;
8323
+ }
8324
+ }
8325
+ const MAX_LOOKUP_HISTORY_SLOTS = 3;
8326
+ function tryAsLookupHistorySlots(items) {
8327
+ const knownSize = asKnownSize(items);
8328
+ if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
8329
+ throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
8330
+ }
8331
+ return knownSize;
8332
+ }
8333
+ /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
8334
+ class LookupHistoryItem {
8335
+ hash;
8336
+ length;
8337
+ slots;
8338
+ constructor(hash, length,
8339
+ /**
8340
+ * Preimage availability history as a sequence of time slots.
8341
+ * See PreimageStatus and the following GP fragment for more details.
8342
+ * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
8343
+ slots) {
8344
+ this.hash = hash;
8345
+ this.length = length;
8346
+ this.slots = slots;
8347
+ }
8348
+ static isRequested(item) {
8349
+ if ("slots" in item) {
8350
+ return item.slots.length === 0;
8351
+ }
8352
+ return item.length === 0;
8353
+ }
8354
+ }
8355
+
8124
8356
  /** Dictionary entry of services that auto-accumulate every block. */
8125
8357
  class AutoAccumulate {
8126
8358
  service;
@@ -8142,39 +8374,50 @@ class AutoAccumulate {
8142
8374
  }
8143
8375
  }
8144
8376
  /**
8145
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11da0111da01?v=0.6.7
8377
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
8146
8378
  */
8147
8379
  class PrivilegedServices {
8148
8380
  manager;
8149
- authManager;
8150
- validatorsManager;
8381
+ delegator;
8382
+ registrar;
8383
+ assigners;
8151
8384
  autoAccumulateServices;
8385
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
8152
8386
  static Codec = codec$1.Class(PrivilegedServices, {
8153
8387
  manager: codec$1.u32.asOpaque(),
8154
- authManager: codecPerCore(codec$1.u32.asOpaque()),
8155
- validatorsManager: codec$1.u32.asOpaque(),
8388
+ assigners: codecPerCore(codec$1.u32.asOpaque()),
8389
+ delegator: codec$1.u32.asOpaque(),
8390
+ registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
8391
+ ? codec$1.u32.asOpaque()
8392
+ : ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
8156
8393
  autoAccumulateServices: readonlyArray(codec$1.sequenceVarLen(AutoAccumulate.Codec)),
8157
8394
  });
8158
- static create({ manager, authManager, validatorsManager, autoAccumulateServices }) {
8159
- return new PrivilegedServices(manager, authManager, validatorsManager, autoAccumulateServices);
8395
+ static create(a) {
8396
+ return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
8160
8397
  }
8161
8398
  constructor(
8162
8399
  /**
8163
- * `chi_m`: The first, χm, is the index of the manager service which is
8164
- * the service able to effect an alteration of χ from block to block,
8400
+ * `χ_M`: Manages alteration of χ from block to block,
8165
8401
  * as well as bestow services with storage deposit credits.
8166
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11a40111a801?v=0.6.7
8402
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
8167
8403
  */
8168
8404
  manager,
8169
- /** `chi_a`: Manages authorization queue one for each core. */
8170
- authManager,
8171
- /** `chi_v`: Managers validator keys. */
8172
- validatorsManager,
8173
- /** `chi_g`: Dictionary of services that auto-accumulate every block with their gas limit. */
8405
+ /** `χ_V`: Managers validator keys. */
8406
+ delegator,
8407
+ /**
8408
+ * `χ_R`: Manages the creation of services in protected range.
8409
+ *
8410
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
8411
+ */
8412
+ registrar,
8413
+ /** `χ_A`: Manages authorization queue one for each core. */
8414
+ assigners,
8415
+ /** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
8174
8416
  autoAccumulateServices) {
8175
8417
  this.manager = manager;
8176
- this.authManager = authManager;
8177
- this.validatorsManager = validatorsManager;
8418
+ this.delegator = delegator;
8419
+ this.registrar = registrar;
8420
+ this.assigners = assigners;
8178
8421
  this.autoAccumulateServices = autoAccumulateServices;
8179
8422
  }
8180
8423
  }
@@ -8436,172 +8679,6 @@ class SafroleData {
8436
8679
  }
8437
8680
  }
8438
8681
 
8439
- /**
8440
- * `B_S`: The basic minimum balance which all services require.
8441
- *
8442
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
8443
- */
8444
- const BASE_SERVICE_BALANCE = 100n;
8445
- /**
8446
- * `B_I`: The additional minimum balance required per item of elective service state.
8447
- *
8448
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
8449
- */
8450
- const ELECTIVE_ITEM_BALANCE = 10n;
8451
- /**
8452
- * `B_L`: The additional minimum balance required per octet of elective service state.
8453
- *
8454
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
8455
- */
8456
- const ELECTIVE_BYTE_BALANCE = 1n;
8457
- const zeroSizeHint = {
8458
- bytes: 0,
8459
- isExact: true,
8460
- };
8461
- /** 0-byte read, return given default value */
8462
- const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
8463
- /**
8464
- * Service account details.
8465
- *
8466
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
8467
- */
8468
- class ServiceAccountInfo extends WithDebug {
8469
- codeHash;
8470
- balance;
8471
- accumulateMinGas;
8472
- onTransferMinGas;
8473
- storageUtilisationBytes;
8474
- gratisStorage;
8475
- storageUtilisationCount;
8476
- created;
8477
- lastAccumulation;
8478
- parentService;
8479
- static Codec = codec$1.Class(ServiceAccountInfo, {
8480
- codeHash: codec$1.bytes(HASH_SIZE).asOpaque(),
8481
- balance: codec$1.u64,
8482
- accumulateMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
8483
- onTransferMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
8484
- storageUtilisationBytes: codec$1.u64,
8485
- gratisStorage: codec$1.u64,
8486
- storageUtilisationCount: codec$1.u32,
8487
- created: codec$1.u32.convert((x) => x, tryAsTimeSlot),
8488
- lastAccumulation: codec$1.u32.convert((x) => x, tryAsTimeSlot),
8489
- parentService: codec$1.u32.convert((x) => x, tryAsServiceId),
8490
- });
8491
- static create(a) {
8492
- return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
8493
- }
8494
- /**
8495
- * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
8496
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
8497
- */
8498
- static calculateThresholdBalance(items, bytes, gratisStorage) {
8499
- const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
8500
- if (storageCost < 0n) {
8501
- return tryAsU64(0);
8502
- }
8503
- if (storageCost >= 2n ** 64n) {
8504
- return tryAsU64(2n ** 64n - 1n);
8505
- }
8506
- return tryAsU64(storageCost);
8507
- }
8508
- constructor(
8509
- /** `a_c`: Hash of the service code. */
8510
- codeHash,
8511
- /** `a_b`: Current account balance. */
8512
- balance,
8513
- /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
8514
- accumulateMinGas,
8515
- /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
8516
- onTransferMinGas,
8517
- /** `a_o`: Total number of octets in storage. */
8518
- storageUtilisationBytes,
8519
- /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
8520
- gratisStorage,
8521
- /** `a_i`: Number of items in storage. */
8522
- storageUtilisationCount,
8523
- /** `a_r`: Creation account time slot. */
8524
- created,
8525
- /** `a_a`: Most recent accumulation time slot. */
8526
- lastAccumulation,
8527
- /** `a_p`: Parent service ID. */
8528
- parentService) {
8529
- super();
8530
- this.codeHash = codeHash;
8531
- this.balance = balance;
8532
- this.accumulateMinGas = accumulateMinGas;
8533
- this.onTransferMinGas = onTransferMinGas;
8534
- this.storageUtilisationBytes = storageUtilisationBytes;
8535
- this.gratisStorage = gratisStorage;
8536
- this.storageUtilisationCount = storageUtilisationCount;
8537
- this.created = created;
8538
- this.lastAccumulation = lastAccumulation;
8539
- this.parentService = parentService;
8540
- }
8541
- }
8542
- class PreimageItem extends WithDebug {
8543
- hash;
8544
- blob;
8545
- static Codec = codec$1.Class(PreimageItem, {
8546
- hash: codec$1.bytes(HASH_SIZE).asOpaque(),
8547
- blob: codec$1.blob,
8548
- });
8549
- static create({ hash, blob }) {
8550
- return new PreimageItem(hash, blob);
8551
- }
8552
- constructor(hash, blob) {
8553
- super();
8554
- this.hash = hash;
8555
- this.blob = blob;
8556
- }
8557
- }
8558
- class StorageItem extends WithDebug {
8559
- key;
8560
- value;
8561
- static Codec = codec$1.Class(StorageItem, {
8562
- key: codec$1.blob.convert((i) => i, (o) => asOpaqueType(o)),
8563
- value: codec$1.blob,
8564
- });
8565
- static create({ key, value }) {
8566
- return new StorageItem(key, value);
8567
- }
8568
- constructor(key, value) {
8569
- super();
8570
- this.key = key;
8571
- this.value = value;
8572
- }
8573
- }
8574
- const MAX_LOOKUP_HISTORY_SLOTS = 3;
8575
- function tryAsLookupHistorySlots(items) {
8576
- const knownSize = asKnownSize(items);
8577
- if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
8578
- throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
8579
- }
8580
- return knownSize;
8581
- }
8582
- /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
8583
- class LookupHistoryItem {
8584
- hash;
8585
- length;
8586
- slots;
8587
- constructor(hash, length,
8588
- /**
8589
- * Preimage availability history as a sequence of time slots.
8590
- * See PreimageStatus and the following GP fragment for more details.
8591
- * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
8592
- slots) {
8593
- this.hash = hash;
8594
- this.length = length;
8595
- this.slots = slots;
8596
- }
8597
- static isRequested(item) {
8598
- if ("slots" in item) {
8599
- return item.slots.length === 0;
8600
- }
8601
- return item.length === 0;
8602
- }
8603
- }
8604
-
8605
8682
  /**
8606
8683
  * In addition to the entropy accumulator η_0, we retain
8607
8684
  * three additional historical values of the accumulator at
@@ -9409,8 +9486,9 @@ class InMemoryState extends WithDebug {
9409
9486
  epochRoot: Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
9410
9487
  privilegedServices: PrivilegedServices.create({
9411
9488
  manager: tryAsServiceId(0),
9412
- authManager: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
9413
- validatorsManager: tryAsServiceId(0),
9489
+ assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
9490
+ delegator: tryAsServiceId(0),
9491
+ registrar: tryAsServiceId(MAX_VALUE),
9414
9492
  autoAccumulateServices: [],
9415
9493
  }),
9416
9494
  accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
@@ -9469,6 +9547,7 @@ var index$g = /*#__PURE__*/Object.freeze({
9469
9547
  ValidatorStatistics: ValidatorStatistics,
9470
9548
  accumulationOutputComparator: accumulationOutputComparator,
9471
9549
  codecPerCore: codecPerCore,
9550
+ codecWithVersion: codecWithVersion,
9472
9551
  hashComparator: hashComparator,
9473
9552
  ignoreValueWithDefault: ignoreValueWithDefault,
9474
9553
  serviceDataCodec: serviceDataCodec,
@@ -9629,7 +9708,9 @@ var serialize;
9629
9708
  /** C(255, s): https://graypaper.fluffylabs.dev/#/85129da/383103383103?v=0.6.3 */
9630
9709
  serialize.serviceData = (serviceId) => ({
9631
9710
  key: stateKeys.serviceInfo(serviceId),
9632
- Codec: ServiceAccountInfo.Codec,
9711
+ Codec: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
9712
+ ? codecWithVersion(ServiceAccountInfo.Codec)
9713
+ : ServiceAccountInfo.Codec,
9633
9714
  });
9634
9715
  /** https://graypaper.fluffylabs.dev/#/85129da/384803384803?v=0.6.3 */
9635
9716
  serialize.serviceStorage = (blake2b, serviceId, key) => ({
@@ -12014,6 +12095,8 @@ var NewServiceError;
12014
12095
  NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
12015
12096
  /** Service is not privileged to set gratis storage. */
12016
12097
  NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
12098
+ /** Registrar attempting to create a service with already existing id. */
12099
+ NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
12017
12100
  })(NewServiceError || (NewServiceError = {}));
12018
12101
  var UpdatePrivilegesError;
12019
12102
  (function (UpdatePrivilegesError) {
@@ -12204,7 +12287,7 @@ class AccumulationStateUpdate {
12204
12287
  if (from.privilegedServices !== null) {
12205
12288
  update.privilegedServices = PrivilegedServices.create({
12206
12289
  ...from.privilegedServices,
12207
- authManager: asKnownSize([...from.privilegedServices.authManager]),
12290
+ assigners: asKnownSize([...from.privilegedServices.assigners]),
12208
12291
  });
12209
12292
  }
12210
12293
  return update;
@@ -12405,7 +12488,7 @@ const HostCallResult = {
12405
12488
  OOB: tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
12406
12489
  /** Index unknown. */
12407
12490
  WHO: tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
12408
- /** Storage full. */
12491
+ /** Storage full or resource already allocated. */
12409
12492
  FULL: tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
12410
12493
  /** Core index unknown. */
12411
12494
  CORE: tryAsU64(0xfffffffffffffffan), // 2**64 - 6
@@ -12413,7 +12496,7 @@ const HostCallResult = {
12413
12496
  CASH: tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
12414
12497
  /** Gas limit too low. */
12415
12498
  LOW: tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
12416
- /** The item is already solicited or cannot be forgotten. */
12499
+ /** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
12417
12500
  HUH: tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
12418
12501
  /** The return value indicating general success. */
12419
12502
  OK: tryAsU64(0n),
@@ -14448,11 +14531,6 @@ class BitOps {
14448
14531
  }
14449
14532
  }
14450
14533
 
14451
- const MAX_VALUE = 4294967295;
14452
- const MIN_VALUE = -2147483648;
14453
- const MAX_SHIFT_U32 = 32;
14454
- const MAX_SHIFT_U64 = 64n;
14455
-
14456
14534
  /**
14457
14535
  * Overflowing addition for two-complement representation of 32-bit signed numbers.
14458
14536
  */
@@ -16822,6 +16900,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
16822
16900
 
16823
16901
  class JsonServiceInfo {
16824
16902
  static fromJson = json.object({
16903
+ ...(Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? { version: "number" } : {}),
16825
16904
  code_hash: fromJson.bytes32(),
16826
16905
  balance: json.fromNumber((x) => tryAsU64(x)),
16827
16906
  min_item_gas: json.fromNumber((x) => tryAsServiceGas(x)),
@@ -16846,6 +16925,7 @@ class JsonServiceInfo {
16846
16925
  parentService: parent_service,
16847
16926
  });
16848
16927
  });
16928
+ version;
16849
16929
  code_hash;
16850
16930
  balance;
16851
16931
  min_item_gas;
@@ -16880,23 +16960,35 @@ const lookupMetaFromJson = json.object({
16880
16960
  },
16881
16961
  value: json.array("number"),
16882
16962
  }, ({ key, value }) => new LookupHistoryItem(key.hash, key.length, value));
16963
+ const preimageStatusFromJson = json.object({
16964
+ hash: fromJson.bytes32(),
16965
+ status: json.array("number"),
16966
+ }, ({ hash, status }) => new LookupHistoryItem(hash, tryAsU32(0), status));
16883
16967
  class JsonService {
16884
16968
  static fromJson = json.object({
16885
16969
  id: "number",
16886
- data: {
16887
- service: JsonServiceInfo.fromJson,
16888
- preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
16889
- storage: json.optional(json.array(JsonStorageItem.fromJson)),
16890
- lookup_meta: json.optional(json.array(lookupMetaFromJson)),
16891
- },
16970
+ data: Compatibility.isLessThan(GpVersion.V0_7_1)
16971
+ ? {
16972
+ service: JsonServiceInfo.fromJson,
16973
+ preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
16974
+ storage: json.optional(json.array(JsonStorageItem.fromJson)),
16975
+ lookup_meta: json.optional(json.array(lookupMetaFromJson)),
16976
+ }
16977
+ : {
16978
+ service: JsonServiceInfo.fromJson,
16979
+ storage: json.optional(json.array(JsonStorageItem.fromJson)),
16980
+ preimages_blob: json.optional(json.array(JsonPreimageItem.fromJson)),
16981
+ preimages_status: json.optional(json.array(preimageStatusFromJson)),
16982
+ },
16892
16983
  }, ({ id, data }) => {
16984
+ const preimages = HashDictionary.fromEntries((data.preimages ?? data.preimages_blob ?? []).map((x) => [x.hash, x]));
16893
16985
  const lookupHistory = HashDictionary.new();
16894
- for (const item of data.lookup_meta ?? []) {
16986
+ for (const item of data.lookup_meta ?? data.preimages_status ?? []) {
16895
16987
  const data = lookupHistory.get(item.hash) ?? [];
16896
- data.push(item);
16988
+ const length = tryAsU32(preimages.get(item.hash)?.blob.length ?? item.length);
16989
+ data.push(new LookupHistoryItem(item.hash, length, item.slots));
16897
16990
  lookupHistory.set(item.hash, data);
16898
16991
  }
16899
- const preimages = HashDictionary.fromEntries((data.preimages ?? []).map((x) => [x.hash, x]));
16900
16992
  const storage = new Map();
16901
16993
  const entries = (data.storage ?? []).map(({ key, value }) => {
16902
16994
  const opaqueKey = asOpaqueType(key);
@@ -17068,8 +17160,12 @@ class JsonServiceStatistics {
17068
17160
  extrinsic_count: "number",
17069
17161
  accumulate_count: "number",
17070
17162
  accumulate_gas_used: json.fromNumber(tryAsServiceGas),
17071
- on_transfers_count: "number",
17072
- on_transfers_gas_used: json.fromNumber(tryAsServiceGas),
17163
+ ...(Compatibility.isLessThan(GpVersion.V0_7_1)
17164
+ ? {
17165
+ on_transfers_count: "number",
17166
+ on_transfers_gas_used: json.fromNumber(tryAsServiceGas),
17167
+ }
17168
+ : {}),
17073
17169
  }, ({ provided_count, provided_size, refinement_count, refinement_gas_used, imports, exports, extrinsic_size, extrinsic_count, accumulate_count, accumulate_gas_used, on_transfers_count, on_transfers_gas_used, }) => {
17074
17170
  return ServiceStatistics.create({
17075
17171
  providedCount: provided_count,
@@ -17082,8 +17178,8 @@ class JsonServiceStatistics {
17082
17178
  extrinsicCount: extrinsic_count,
17083
17179
  accumulateCount: accumulate_count,
17084
17180
  accumulateGasUsed: accumulate_gas_used,
17085
- onTransfersCount: on_transfers_count,
17086
- onTransfersGasUsed: on_transfers_gas_used,
17181
+ onTransfersCount: on_transfers_count ?? tryAsU32(0),
17182
+ onTransfersGasUsed: on_transfers_gas_used ?? tryAsServiceGas(0),
17087
17183
  });
17088
17184
  });
17089
17185
  provided_count;
@@ -17154,6 +17250,7 @@ const fullStateDumpFromJson = (spec) => json.object({
17154
17250
  chi_m: "number",
17155
17251
  chi_a: json.array("number"),
17156
17252
  chi_v: "number",
17253
+ chi_r: json.optional("number"),
17157
17254
  chi_g: json.nullable(json.array({
17158
17255
  service: "number",
17159
17256
  gasLimit: json.fromNumber((v) => tryAsServiceGas(v)),
@@ -17165,6 +17262,9 @@ const fullStateDumpFromJson = (spec) => json.object({
17165
17262
  theta: json.nullable(json.array(accumulationOutput)),
17166
17263
  accounts: json.array(JsonService.fromJson),
17167
17264
  }, ({ alpha, varphi, beta, gamma, psi, eta, iota, kappa, lambda, rho, tau, chi, pi, omega, xi, theta, accounts, }) => {
17265
+ if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && chi.chi_r === undefined) {
17266
+ throw new Error("Registrar is required in Privileges GP ^0.7.1");
17267
+ }
17168
17268
  return InMemoryState.create({
17169
17269
  authPools: tryAsPerCore(alpha.map((perCore) => {
17170
17270
  if (perCore.length > MAX_AUTH_POOL_SIZE) {
@@ -17192,8 +17292,9 @@ const fullStateDumpFromJson = (spec) => json.object({
17192
17292
  timeslot: tau,
17193
17293
  privilegedServices: PrivilegedServices.create({
17194
17294
  manager: chi.chi_m,
17195
- authManager: chi.chi_a,
17196
- validatorsManager: chi.chi_v,
17295
+ assigners: chi.chi_a,
17296
+ delegator: chi.chi_v,
17297
+ registrar: chi.chi_r ?? tryAsServiceId(2 ** 32 - 1),
17197
17298
  autoAccumulateServices: chi.chi_g ?? [],
17198
17299
  }),
17199
17300
  statistics: JsonStatisticsData.toStatisticsData(spec, pi),