@typeberry/lib 0.1.3-8fd7637 → 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.
Files changed (4) hide show
  1. package/index.cjs +274 -229
  2. package/index.d.ts +333 -261
  3. package/index.js +274 -229
  4. package/package.json +1 -1
package/index.js CHANGED
@@ -35,8 +35,9 @@ function parseCurrentVersion(env) {
35
35
  }
36
36
  }
37
37
  function parseCurrentSuite(env) {
38
- if (env === undefined)
38
+ if (env === undefined) {
39
39
  return undefined;
40
+ }
40
41
  switch (env) {
41
42
  case TestSuite.W3F_DAVXY:
42
43
  case TestSuite.JAMDUNA:
@@ -456,10 +457,12 @@ function deepEqual(actual, expected, { context = [], errorsCollector, ignore = [
456
457
  .sort((a, b) => {
457
458
  const aKey = `${a.key}`;
458
459
  const bKey = `${b.key}`;
459
- if (aKey < bKey)
460
+ if (aKey < bKey) {
460
461
  return -1;
461
- if (bKey < aKey)
462
+ }
463
+ if (bKey < aKey) {
462
464
  return 1;
465
+ }
463
466
  return 0;
464
467
  });
465
468
  };
@@ -8148,7 +8151,6 @@ const O = 8;
8148
8151
  const Q = 80;
8149
8152
  /** `W_T`: The size of a transfer memo in octets. */
8150
8153
  const W_T = 128;
8151
- // TODO [ToDr] Not sure where these should live yet :(
8152
8154
  /**
8153
8155
  * `J`: The maximum sum of dependency items in a work-report.
8154
8156
  *
@@ -8160,6 +8162,194 @@ const AUTHORIZATION_QUEUE_SIZE = Q;
8160
8162
  /** `O`: Maximal authorization pool size. */
8161
8163
  const MAX_AUTH_POOL_SIZE = O;
8162
8164
 
8165
+ const MAX_VALUE = 4294967295;
8166
+ const MIN_VALUE = -2147483648;
8167
+ const MAX_SHIFT_U32 = 32;
8168
+ const MAX_SHIFT_U64 = 64n;
8169
+
8170
+ /**
8171
+ * `B_S`: The basic minimum balance which all services require.
8172
+ *
8173
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
8174
+ */
8175
+ const BASE_SERVICE_BALANCE = 100n;
8176
+ /**
8177
+ * `B_I`: The additional minimum balance required per item of elective service state.
8178
+ *
8179
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
8180
+ */
8181
+ const ELECTIVE_ITEM_BALANCE = 10n;
8182
+ /**
8183
+ * `B_L`: The additional minimum balance required per octet of elective service state.
8184
+ *
8185
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
8186
+ */
8187
+ const ELECTIVE_BYTE_BALANCE = 1n;
8188
+ const zeroSizeHint = {
8189
+ bytes: 0,
8190
+ isExact: true,
8191
+ };
8192
+ /** 0-byte read, return given default value */
8193
+ const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
8194
+ /** Encode and decode object with leading version number. */
8195
+ const codecWithVersion = (val) => Descriptor.new("withVersion", {
8196
+ bytes: val.sizeHint.bytes + 8,
8197
+ isExact: false,
8198
+ }, (e, v) => {
8199
+ e.varU64(0n);
8200
+ val.encode(e, v);
8201
+ }, (d) => {
8202
+ const version = d.varU64();
8203
+ if (version !== 0n) {
8204
+ throw new Error("Non-zero version is not supported!");
8205
+ }
8206
+ return val.decode(d);
8207
+ }, (s) => {
8208
+ s.varU64();
8209
+ val.skip(s);
8210
+ });
8211
+ /**
8212
+ * Service account details.
8213
+ *
8214
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
8215
+ */
8216
+ class ServiceAccountInfo extends WithDebug {
8217
+ codeHash;
8218
+ balance;
8219
+ accumulateMinGas;
8220
+ onTransferMinGas;
8221
+ storageUtilisationBytes;
8222
+ gratisStorage;
8223
+ storageUtilisationCount;
8224
+ created;
8225
+ lastAccumulation;
8226
+ parentService;
8227
+ static Codec = codec$1.Class(ServiceAccountInfo, {
8228
+ codeHash: codec$1.bytes(HASH_SIZE).asOpaque(),
8229
+ balance: codec$1.u64,
8230
+ accumulateMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
8231
+ onTransferMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
8232
+ storageUtilisationBytes: codec$1.u64,
8233
+ gratisStorage: codec$1.u64,
8234
+ storageUtilisationCount: codec$1.u32,
8235
+ created: codec$1.u32.convert((x) => x, tryAsTimeSlot),
8236
+ lastAccumulation: codec$1.u32.convert((x) => x, tryAsTimeSlot),
8237
+ parentService: codec$1.u32.convert((x) => x, tryAsServiceId),
8238
+ });
8239
+ static create(a) {
8240
+ return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
8241
+ }
8242
+ /**
8243
+ * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
8244
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
8245
+ */
8246
+ static calculateThresholdBalance(items, bytes, gratisStorage) {
8247
+ const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
8248
+ if (storageCost < 0n) {
8249
+ return tryAsU64(0);
8250
+ }
8251
+ if (storageCost >= 2n ** 64n) {
8252
+ return tryAsU64(2n ** 64n - 1n);
8253
+ }
8254
+ return tryAsU64(storageCost);
8255
+ }
8256
+ constructor(
8257
+ /** `a_c`: Hash of the service code. */
8258
+ codeHash,
8259
+ /** `a_b`: Current account balance. */
8260
+ balance,
8261
+ /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
8262
+ accumulateMinGas,
8263
+ /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
8264
+ onTransferMinGas,
8265
+ /** `a_o`: Total number of octets in storage. */
8266
+ storageUtilisationBytes,
8267
+ /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
8268
+ gratisStorage,
8269
+ /** `a_i`: Number of items in storage. */
8270
+ storageUtilisationCount,
8271
+ /** `a_r`: Creation account time slot. */
8272
+ created,
8273
+ /** `a_a`: Most recent accumulation time slot. */
8274
+ lastAccumulation,
8275
+ /** `a_p`: Parent service ID. */
8276
+ parentService) {
8277
+ super();
8278
+ this.codeHash = codeHash;
8279
+ this.balance = balance;
8280
+ this.accumulateMinGas = accumulateMinGas;
8281
+ this.onTransferMinGas = onTransferMinGas;
8282
+ this.storageUtilisationBytes = storageUtilisationBytes;
8283
+ this.gratisStorage = gratisStorage;
8284
+ this.storageUtilisationCount = storageUtilisationCount;
8285
+ this.created = created;
8286
+ this.lastAccumulation = lastAccumulation;
8287
+ this.parentService = parentService;
8288
+ }
8289
+ }
8290
+ class PreimageItem extends WithDebug {
8291
+ hash;
8292
+ blob;
8293
+ static Codec = codec$1.Class(PreimageItem, {
8294
+ hash: codec$1.bytes(HASH_SIZE).asOpaque(),
8295
+ blob: codec$1.blob,
8296
+ });
8297
+ static create({ hash, blob }) {
8298
+ return new PreimageItem(hash, blob);
8299
+ }
8300
+ constructor(hash, blob) {
8301
+ super();
8302
+ this.hash = hash;
8303
+ this.blob = blob;
8304
+ }
8305
+ }
8306
+ class StorageItem extends WithDebug {
8307
+ key;
8308
+ value;
8309
+ static Codec = codec$1.Class(StorageItem, {
8310
+ key: codec$1.blob.convert((i) => i, (o) => asOpaqueType(o)),
8311
+ value: codec$1.blob,
8312
+ });
8313
+ static create({ key, value }) {
8314
+ return new StorageItem(key, value);
8315
+ }
8316
+ constructor(key, value) {
8317
+ super();
8318
+ this.key = key;
8319
+ this.value = value;
8320
+ }
8321
+ }
8322
+ const MAX_LOOKUP_HISTORY_SLOTS = 3;
8323
+ function tryAsLookupHistorySlots(items) {
8324
+ const knownSize = asKnownSize(items);
8325
+ if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
8326
+ throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
8327
+ }
8328
+ return knownSize;
8329
+ }
8330
+ /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
8331
+ class LookupHistoryItem {
8332
+ hash;
8333
+ length;
8334
+ slots;
8335
+ constructor(hash, length,
8336
+ /**
8337
+ * Preimage availability history as a sequence of time slots.
8338
+ * See PreimageStatus and the following GP fragment for more details.
8339
+ * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
8340
+ slots) {
8341
+ this.hash = hash;
8342
+ this.length = length;
8343
+ this.slots = slots;
8344
+ }
8345
+ static isRequested(item) {
8346
+ if ("slots" in item) {
8347
+ return item.slots.length === 0;
8348
+ }
8349
+ return item.length === 0;
8350
+ }
8351
+ }
8352
+
8163
8353
  /** Dictionary entry of services that auto-accumulate every block. */
8164
8354
  class AutoAccumulate {
8165
8355
  service;
@@ -8181,39 +8371,50 @@ class AutoAccumulate {
8181
8371
  }
8182
8372
  }
8183
8373
  /**
8184
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11da0111da01?v=0.6.7
8374
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
8185
8375
  */
8186
8376
  class PrivilegedServices {
8187
8377
  manager;
8188
- authManager;
8189
- validatorsManager;
8378
+ delegator;
8379
+ registrar;
8380
+ assigners;
8190
8381
  autoAccumulateServices;
8382
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
8191
8383
  static Codec = codec$1.Class(PrivilegedServices, {
8192
8384
  manager: codec$1.u32.asOpaque(),
8193
- authManager: codecPerCore(codec$1.u32.asOpaque()),
8194
- validatorsManager: codec$1.u32.asOpaque(),
8385
+ assigners: codecPerCore(codec$1.u32.asOpaque()),
8386
+ delegator: codec$1.u32.asOpaque(),
8387
+ registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
8388
+ ? codec$1.u32.asOpaque()
8389
+ : ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
8195
8390
  autoAccumulateServices: readonlyArray(codec$1.sequenceVarLen(AutoAccumulate.Codec)),
8196
8391
  });
8197
- static create({ manager, authManager, validatorsManager, autoAccumulateServices }) {
8198
- return new PrivilegedServices(manager, authManager, validatorsManager, autoAccumulateServices);
8392
+ static create(a) {
8393
+ return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
8199
8394
  }
8200
8395
  constructor(
8201
8396
  /**
8202
- * `chi_m`: The first, χm, is the index of the manager service which is
8203
- * the service able to effect an alteration of χ from block to block,
8397
+ * `χ_M`: Manages alteration of χ from block to block,
8204
8398
  * as well as bestow services with storage deposit credits.
8205
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11a40111a801?v=0.6.7
8399
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
8206
8400
  */
8207
8401
  manager,
8208
- /** `chi_a`: Manages authorization queue one for each core. */
8209
- authManager,
8210
- /** `chi_v`: Managers validator keys. */
8211
- validatorsManager,
8212
- /** `chi_g`: Dictionary of services that auto-accumulate every block with their gas limit. */
8402
+ /** `χ_V`: Managers validator keys. */
8403
+ delegator,
8404
+ /**
8405
+ * `χ_R`: Manages the creation of services in protected range.
8406
+ *
8407
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
8408
+ */
8409
+ registrar,
8410
+ /** `χ_A`: Manages authorization queue one for each core. */
8411
+ assigners,
8412
+ /** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
8213
8413
  autoAccumulateServices) {
8214
8414
  this.manager = manager;
8215
- this.authManager = authManager;
8216
- this.validatorsManager = validatorsManager;
8415
+ this.delegator = delegator;
8416
+ this.registrar = registrar;
8417
+ this.assigners = assigners;
8217
8418
  this.autoAccumulateServices = autoAccumulateServices;
8218
8419
  }
8219
8420
  }
@@ -8475,189 +8676,6 @@ class SafroleData {
8475
8676
  }
8476
8677
  }
8477
8678
 
8478
- /**
8479
- * `B_S`: The basic minimum balance which all services require.
8480
- *
8481
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
8482
- */
8483
- const BASE_SERVICE_BALANCE = 100n;
8484
- /**
8485
- * `B_I`: The additional minimum balance required per item of elective service state.
8486
- *
8487
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
8488
- */
8489
- const ELECTIVE_ITEM_BALANCE = 10n;
8490
- /**
8491
- * `B_L`: The additional minimum balance required per octet of elective service state.
8492
- *
8493
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
8494
- */
8495
- const ELECTIVE_BYTE_BALANCE = 1n;
8496
- const zeroSizeHint = {
8497
- bytes: 0,
8498
- isExact: true,
8499
- };
8500
- /** 0-byte read, return given default value */
8501
- const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
8502
- /** Encode and decode object with leading version number. */
8503
- const codecWithVersion = (val) => Descriptor.new("withVersion", {
8504
- bytes: val.sizeHint.bytes + 8,
8505
- isExact: false,
8506
- }, (e, v) => {
8507
- e.varU64(0n);
8508
- val.encode(e, v);
8509
- }, (d) => {
8510
- const version = d.varU64();
8511
- if (version !== 0n) {
8512
- throw new Error("Non-zero version is not supported!");
8513
- }
8514
- return val.decode(d);
8515
- }, (s) => {
8516
- s.varU64();
8517
- val.skip(s);
8518
- });
8519
- /**
8520
- * Service account details.
8521
- *
8522
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
8523
- */
8524
- class ServiceAccountInfo extends WithDebug {
8525
- codeHash;
8526
- balance;
8527
- accumulateMinGas;
8528
- onTransferMinGas;
8529
- storageUtilisationBytes;
8530
- gratisStorage;
8531
- storageUtilisationCount;
8532
- created;
8533
- lastAccumulation;
8534
- parentService;
8535
- static Codec = codec$1.Class(ServiceAccountInfo, {
8536
- codeHash: codec$1.bytes(HASH_SIZE).asOpaque(),
8537
- balance: codec$1.u64,
8538
- accumulateMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
8539
- onTransferMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
8540
- storageUtilisationBytes: codec$1.u64,
8541
- gratisStorage: codec$1.u64,
8542
- storageUtilisationCount: codec$1.u32,
8543
- created: codec$1.u32.convert((x) => x, tryAsTimeSlot),
8544
- lastAccumulation: codec$1.u32.convert((x) => x, tryAsTimeSlot),
8545
- parentService: codec$1.u32.convert((x) => x, tryAsServiceId),
8546
- });
8547
- static create(a) {
8548
- return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
8549
- }
8550
- /**
8551
- * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
8552
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
8553
- */
8554
- static calculateThresholdBalance(items, bytes, gratisStorage) {
8555
- const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
8556
- if (storageCost < 0n) {
8557
- return tryAsU64(0);
8558
- }
8559
- if (storageCost >= 2n ** 64n) {
8560
- return tryAsU64(2n ** 64n - 1n);
8561
- }
8562
- return tryAsU64(storageCost);
8563
- }
8564
- constructor(
8565
- /** `a_c`: Hash of the service code. */
8566
- codeHash,
8567
- /** `a_b`: Current account balance. */
8568
- balance,
8569
- /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
8570
- accumulateMinGas,
8571
- /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
8572
- onTransferMinGas,
8573
- /** `a_o`: Total number of octets in storage. */
8574
- storageUtilisationBytes,
8575
- /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
8576
- gratisStorage,
8577
- /** `a_i`: Number of items in storage. */
8578
- storageUtilisationCount,
8579
- /** `a_r`: Creation account time slot. */
8580
- created,
8581
- /** `a_a`: Most recent accumulation time slot. */
8582
- lastAccumulation,
8583
- /** `a_p`: Parent service ID. */
8584
- parentService) {
8585
- super();
8586
- this.codeHash = codeHash;
8587
- this.balance = balance;
8588
- this.accumulateMinGas = accumulateMinGas;
8589
- this.onTransferMinGas = onTransferMinGas;
8590
- this.storageUtilisationBytes = storageUtilisationBytes;
8591
- this.gratisStorage = gratisStorage;
8592
- this.storageUtilisationCount = storageUtilisationCount;
8593
- this.created = created;
8594
- this.lastAccumulation = lastAccumulation;
8595
- this.parentService = parentService;
8596
- }
8597
- }
8598
- class PreimageItem extends WithDebug {
8599
- hash;
8600
- blob;
8601
- static Codec = codec$1.Class(PreimageItem, {
8602
- hash: codec$1.bytes(HASH_SIZE).asOpaque(),
8603
- blob: codec$1.blob,
8604
- });
8605
- static create({ hash, blob }) {
8606
- return new PreimageItem(hash, blob);
8607
- }
8608
- constructor(hash, blob) {
8609
- super();
8610
- this.hash = hash;
8611
- this.blob = blob;
8612
- }
8613
- }
8614
- class StorageItem extends WithDebug {
8615
- key;
8616
- value;
8617
- static Codec = codec$1.Class(StorageItem, {
8618
- key: codec$1.blob.convert((i) => i, (o) => asOpaqueType(o)),
8619
- value: codec$1.blob,
8620
- });
8621
- static create({ key, value }) {
8622
- return new StorageItem(key, value);
8623
- }
8624
- constructor(key, value) {
8625
- super();
8626
- this.key = key;
8627
- this.value = value;
8628
- }
8629
- }
8630
- const MAX_LOOKUP_HISTORY_SLOTS = 3;
8631
- function tryAsLookupHistorySlots(items) {
8632
- const knownSize = asKnownSize(items);
8633
- if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
8634
- throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
8635
- }
8636
- return knownSize;
8637
- }
8638
- /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
8639
- class LookupHistoryItem {
8640
- hash;
8641
- length;
8642
- slots;
8643
- constructor(hash, length,
8644
- /**
8645
- * Preimage availability history as a sequence of time slots.
8646
- * See PreimageStatus and the following GP fragment for more details.
8647
- * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
8648
- slots) {
8649
- this.hash = hash;
8650
- this.length = length;
8651
- this.slots = slots;
8652
- }
8653
- static isRequested(item) {
8654
- if ("slots" in item) {
8655
- return item.slots.length === 0;
8656
- }
8657
- return item.length === 0;
8658
- }
8659
- }
8660
-
8661
8679
  /**
8662
8680
  * In addition to the entropy accumulator η_0, we retain
8663
8681
  * three additional historical values of the accumulator at
@@ -9465,8 +9483,9 @@ class InMemoryState extends WithDebug {
9465
9483
  epochRoot: Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
9466
9484
  privilegedServices: PrivilegedServices.create({
9467
9485
  manager: tryAsServiceId(0),
9468
- authManager: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
9469
- validatorsManager: tryAsServiceId(0),
9486
+ assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
9487
+ delegator: tryAsServiceId(0),
9488
+ registrar: tryAsServiceId(MAX_VALUE),
9470
9489
  autoAccumulateServices: [],
9471
9490
  }),
9472
9491
  accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
@@ -12073,6 +12092,8 @@ var NewServiceError;
12073
12092
  NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
12074
12093
  /** Service is not privileged to set gratis storage. */
12075
12094
  NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
12095
+ /** Registrar attempting to create a service with already existing id. */
12096
+ NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
12076
12097
  })(NewServiceError || (NewServiceError = {}));
12077
12098
  var UpdatePrivilegesError;
12078
12099
  (function (UpdatePrivilegesError) {
@@ -12263,11 +12284,17 @@ class AccumulationStateUpdate {
12263
12284
  if (from.privilegedServices !== null) {
12264
12285
  update.privilegedServices = PrivilegedServices.create({
12265
12286
  ...from.privilegedServices,
12266
- authManager: asKnownSize([...from.privilegedServices.authManager]),
12287
+ assigners: asKnownSize([...from.privilegedServices.assigners]),
12267
12288
  });
12268
12289
  }
12269
12290
  return update;
12270
12291
  }
12292
+ /** Retrieve and clear pending transfers. */
12293
+ takeTransfers() {
12294
+ const transfers = this.transfers;
12295
+ this.transfers = [];
12296
+ return transfers;
12297
+ }
12271
12298
  }
12272
12299
  class PartiallyUpdatedState {
12273
12300
  state;
@@ -12464,7 +12491,7 @@ const HostCallResult = {
12464
12491
  OOB: tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
12465
12492
  /** Index unknown. */
12466
12493
  WHO: tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
12467
- /** Storage full. */
12494
+ /** Storage full or resource already allocated. */
12468
12495
  FULL: tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
12469
12496
  /** Core index unknown. */
12470
12497
  CORE: tryAsU64(0xfffffffffffffffan), // 2**64 - 6
@@ -12472,7 +12499,7 @@ const HostCallResult = {
12472
12499
  CASH: tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
12473
12500
  /** Gas limit too low. */
12474
12501
  LOW: tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
12475
- /** The item is already solicited or cannot be forgotten. */
12502
+ /** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
12476
12503
  HUH: tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
12477
12504
  /** The return value indicating general success. */
12478
12505
  OK: tryAsU64(0n),
@@ -14507,11 +14534,6 @@ class BitOps {
14507
14534
  }
14508
14535
  }
14509
14536
 
14510
- const MAX_VALUE = 4294967295;
14511
- const MIN_VALUE = -2147483648;
14512
- const MAX_SHIFT_U32 = 32;
14513
- const MAX_SHIFT_U64 = 64n;
14514
-
14515
14537
  /**
14516
14538
  * Overflowing addition for two-complement representation of 32-bit signed numbers.
14517
14539
  */
@@ -16881,6 +16903,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
16881
16903
 
16882
16904
  class JsonServiceInfo {
16883
16905
  static fromJson = json.object({
16906
+ ...(Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? { version: "number" } : {}),
16884
16907
  code_hash: fromJson.bytes32(),
16885
16908
  balance: json.fromNumber((x) => tryAsU64(x)),
16886
16909
  min_item_gas: json.fromNumber((x) => tryAsServiceGas(x)),
@@ -16905,6 +16928,7 @@ class JsonServiceInfo {
16905
16928
  parentService: parent_service,
16906
16929
  });
16907
16930
  });
16931
+ version;
16908
16932
  code_hash;
16909
16933
  balance;
16910
16934
  min_item_gas;
@@ -16939,23 +16963,35 @@ const lookupMetaFromJson = json.object({
16939
16963
  },
16940
16964
  value: json.array("number"),
16941
16965
  }, ({ key, value }) => new LookupHistoryItem(key.hash, key.length, value));
16966
+ const preimageStatusFromJson = json.object({
16967
+ hash: fromJson.bytes32(),
16968
+ status: json.array("number"),
16969
+ }, ({ hash, status }) => new LookupHistoryItem(hash, tryAsU32(0), status));
16942
16970
  class JsonService {
16943
16971
  static fromJson = json.object({
16944
16972
  id: "number",
16945
- data: {
16946
- service: JsonServiceInfo.fromJson,
16947
- preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
16948
- storage: json.optional(json.array(JsonStorageItem.fromJson)),
16949
- lookup_meta: json.optional(json.array(lookupMetaFromJson)),
16950
- },
16973
+ data: Compatibility.isLessThan(GpVersion.V0_7_1)
16974
+ ? {
16975
+ service: JsonServiceInfo.fromJson,
16976
+ preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
16977
+ storage: json.optional(json.array(JsonStorageItem.fromJson)),
16978
+ lookup_meta: json.optional(json.array(lookupMetaFromJson)),
16979
+ }
16980
+ : {
16981
+ service: JsonServiceInfo.fromJson,
16982
+ storage: json.optional(json.array(JsonStorageItem.fromJson)),
16983
+ preimages_blob: json.optional(json.array(JsonPreimageItem.fromJson)),
16984
+ preimages_status: json.optional(json.array(preimageStatusFromJson)),
16985
+ },
16951
16986
  }, ({ id, data }) => {
16987
+ const preimages = HashDictionary.fromEntries((data.preimages ?? data.preimages_blob ?? []).map((x) => [x.hash, x]));
16952
16988
  const lookupHistory = HashDictionary.new();
16953
- for (const item of data.lookup_meta ?? []) {
16989
+ for (const item of data.lookup_meta ?? data.preimages_status ?? []) {
16954
16990
  const data = lookupHistory.get(item.hash) ?? [];
16955
- data.push(item);
16991
+ const length = tryAsU32(preimages.get(item.hash)?.blob.length ?? item.length);
16992
+ data.push(new LookupHistoryItem(item.hash, length, item.slots));
16956
16993
  lookupHistory.set(item.hash, data);
16957
16994
  }
16958
- const preimages = HashDictionary.fromEntries((data.preimages ?? []).map((x) => [x.hash, x]));
16959
16995
  const storage = new Map();
16960
16996
  const entries = (data.storage ?? []).map(({ key, value }) => {
16961
16997
  const opaqueKey = asOpaqueType(key);
@@ -17127,8 +17163,12 @@ class JsonServiceStatistics {
17127
17163
  extrinsic_count: "number",
17128
17164
  accumulate_count: "number",
17129
17165
  accumulate_gas_used: json.fromNumber(tryAsServiceGas),
17130
- on_transfers_count: "number",
17131
- on_transfers_gas_used: json.fromNumber(tryAsServiceGas),
17166
+ ...(Compatibility.isLessThan(GpVersion.V0_7_1)
17167
+ ? {
17168
+ on_transfers_count: "number",
17169
+ on_transfers_gas_used: json.fromNumber(tryAsServiceGas),
17170
+ }
17171
+ : {}),
17132
17172
  }, ({ 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, }) => {
17133
17173
  return ServiceStatistics.create({
17134
17174
  providedCount: provided_count,
@@ -17141,8 +17181,8 @@ class JsonServiceStatistics {
17141
17181
  extrinsicCount: extrinsic_count,
17142
17182
  accumulateCount: accumulate_count,
17143
17183
  accumulateGasUsed: accumulate_gas_used,
17144
- onTransfersCount: on_transfers_count,
17145
- onTransfersGasUsed: on_transfers_gas_used,
17184
+ onTransfersCount: on_transfers_count ?? tryAsU32(0),
17185
+ onTransfersGasUsed: on_transfers_gas_used ?? tryAsServiceGas(0),
17146
17186
  });
17147
17187
  });
17148
17188
  provided_count;
@@ -17213,6 +17253,7 @@ const fullStateDumpFromJson = (spec) => json.object({
17213
17253
  chi_m: "number",
17214
17254
  chi_a: json.array("number"),
17215
17255
  chi_v: "number",
17256
+ chi_r: json.optional("number"),
17216
17257
  chi_g: json.nullable(json.array({
17217
17258
  service: "number",
17218
17259
  gasLimit: json.fromNumber((v) => tryAsServiceGas(v)),
@@ -17224,6 +17265,9 @@ const fullStateDumpFromJson = (spec) => json.object({
17224
17265
  theta: json.nullable(json.array(accumulationOutput)),
17225
17266
  accounts: json.array(JsonService.fromJson),
17226
17267
  }, ({ alpha, varphi, beta, gamma, psi, eta, iota, kappa, lambda, rho, tau, chi, pi, omega, xi, theta, accounts, }) => {
17268
+ if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && chi.chi_r === undefined) {
17269
+ throw new Error("Registrar is required in Privileges GP ^0.7.1");
17270
+ }
17227
17271
  return InMemoryState.create({
17228
17272
  authPools: tryAsPerCore(alpha.map((perCore) => {
17229
17273
  if (perCore.length > MAX_AUTH_POOL_SIZE) {
@@ -17251,8 +17295,9 @@ const fullStateDumpFromJson = (spec) => json.object({
17251
17295
  timeslot: tau,
17252
17296
  privilegedServices: PrivilegedServices.create({
17253
17297
  manager: chi.chi_m,
17254
- authManager: chi.chi_a,
17255
- validatorsManager: chi.chi_v,
17298
+ assigners: chi.chi_a,
17299
+ delegator: chi.chi_v,
17300
+ registrar: chi.chi_r ?? tryAsServiceId(2 ** 32 - 1),
17256
17301
  autoAccumulateServices: chi.chi_g ?? [],
17257
17302
  }),
17258
17303
  statistics: JsonStatisticsData.toStatisticsData(spec, pi),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typeberry/lib",
3
- "version": "0.1.3-8fd7637",
3
+ "version": "0.1.3-a6eda68",
4
4
  "main": "index.js",
5
5
  "author": "Fluffy Labs",
6
6
  "license": "MPL-2.0",