@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.d.ts CHANGED
@@ -35,7 +35,9 @@ declare function parseCurrentVersion(env?: string): GpVersion | undefined {
35
35
  }
36
36
 
37
37
  declare function parseCurrentSuite(env?: string): TestSuite | undefined {
38
- if (env === undefined) return undefined;
38
+ if (env === undefined) {
39
+ return undefined;
40
+ }
39
41
  switch (env) {
40
42
  case TestSuite.W3F_DAVXY:
41
43
  case TestSuite.JAMDUNA:
@@ -587,8 +589,12 @@ declare function deepEqual<T>(
587
589
  const aKey = `${a.key}`;
588
590
  const bKey = `${b.key}`;
589
591
 
590
- if (aKey < bKey) return -1;
591
- if (bKey < aKey) return 1;
592
+ if (aKey < bKey) {
593
+ return -1;
594
+ }
595
+ if (bKey < aKey) {
596
+ return 1;
597
+ }
592
598
  return 0;
593
599
  });
594
600
  };
@@ -9239,8 +9245,6 @@ declare function hashComparator<V extends OpaqueHash>(a: V, b: V) {
9239
9245
  return a.compare(b);
9240
9246
  }
9241
9247
 
9242
- // TODO [ToDr] Not sure where these should live yet :(
9243
-
9244
9248
  /**
9245
9249
  * `J`: The maximum sum of dependency items in a work-report.
9246
9250
  *
@@ -9294,6 +9298,215 @@ declare class NotYetAccumulatedReport extends WithDebug {
9294
9298
  }
9295
9299
  }
9296
9300
 
9301
+ /**
9302
+ * `B_S`: The basic minimum balance which all services require.
9303
+ *
9304
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
9305
+ */
9306
+ declare const BASE_SERVICE_BALANCE = 100n;
9307
+ /**
9308
+ * `B_I`: The additional minimum balance required per item of elective service state.
9309
+ *
9310
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
9311
+ */
9312
+ declare const ELECTIVE_ITEM_BALANCE = 10n;
9313
+ /**
9314
+ * `B_L`: The additional minimum balance required per octet of elective service state.
9315
+ *
9316
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
9317
+ */
9318
+ declare const ELECTIVE_BYTE_BALANCE = 1n;
9319
+
9320
+ declare const zeroSizeHint: SizeHint = {
9321
+ bytes: 0,
9322
+ isExact: true,
9323
+ };
9324
+
9325
+ /** 0-byte read, return given default value */
9326
+ declare const ignoreValueWithDefault = <T>(defaultValue: T) =>
9327
+ Descriptor.new<T>(
9328
+ "ignoreValue",
9329
+ zeroSizeHint,
9330
+ (_e, _v) => {},
9331
+ (_d) => defaultValue,
9332
+ (_s) => {},
9333
+ );
9334
+
9335
+ /** Encode and decode object with leading version number. */
9336
+ declare const codecWithVersion = <T>(val: Descriptor<T>): Descriptor<T> =>
9337
+ Descriptor.new<T>(
9338
+ "withVersion",
9339
+ {
9340
+ bytes: val.sizeHint.bytes + 8,
9341
+ isExact: false,
9342
+ },
9343
+ (e, v) => {
9344
+ e.varU64(0n);
9345
+ val.encode(e, v);
9346
+ },
9347
+ (d) => {
9348
+ const version = d.varU64();
9349
+ if (version !== 0n) {
9350
+ throw new Error("Non-zero version is not supported!");
9351
+ }
9352
+ return val.decode(d);
9353
+ },
9354
+ (s) => {
9355
+ s.varU64();
9356
+ val.skip(s);
9357
+ },
9358
+ );
9359
+
9360
+ /**
9361
+ * Service account details.
9362
+ *
9363
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
9364
+ */
9365
+ declare class ServiceAccountInfo extends WithDebug {
9366
+ static Codec = codec.Class(ServiceAccountInfo, {
9367
+ codeHash: codec.bytes(HASH_SIZE).asOpaque<CodeHash>(),
9368
+ balance: codec.u64,
9369
+ accumulateMinGas: codec.u64.convert((x) => x, tryAsServiceGas),
9370
+ onTransferMinGas: codec.u64.convert((x) => x, tryAsServiceGas),
9371
+ storageUtilisationBytes: codec.u64,
9372
+ gratisStorage: codec.u64,
9373
+ storageUtilisationCount: codec.u32,
9374
+ created: codec.u32.convert((x) => x, tryAsTimeSlot),
9375
+ lastAccumulation: codec.u32.convert((x) => x, tryAsTimeSlot),
9376
+ parentService: codec.u32.convert((x) => x, tryAsServiceId),
9377
+ });
9378
+
9379
+ static create(a: CodecRecord<ServiceAccountInfo>) {
9380
+ return new ServiceAccountInfo(
9381
+ a.codeHash,
9382
+ a.balance,
9383
+ a.accumulateMinGas,
9384
+ a.onTransferMinGas,
9385
+ a.storageUtilisationBytes,
9386
+ a.gratisStorage,
9387
+ a.storageUtilisationCount,
9388
+ a.created,
9389
+ a.lastAccumulation,
9390
+ a.parentService,
9391
+ );
9392
+ }
9393
+
9394
+ /**
9395
+ * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
9396
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
9397
+ */
9398
+ static calculateThresholdBalance(items: U32, bytes: U64, gratisStorage: U64): U64 {
9399
+ const storageCost =
9400
+ BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
9401
+
9402
+ if (storageCost < 0n) {
9403
+ return tryAsU64(0);
9404
+ }
9405
+
9406
+ if (storageCost >= 2n ** 64n) {
9407
+ return tryAsU64(2n ** 64n - 1n);
9408
+ }
9409
+
9410
+ return tryAsU64(storageCost);
9411
+ }
9412
+
9413
+ private constructor(
9414
+ /** `a_c`: Hash of the service code. */
9415
+ public readonly codeHash: CodeHash,
9416
+ /** `a_b`: Current account balance. */
9417
+ public readonly balance: U64,
9418
+ /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
9419
+ public readonly accumulateMinGas: ServiceGas,
9420
+ /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
9421
+ public readonly onTransferMinGas: ServiceGas,
9422
+ /** `a_o`: Total number of octets in storage. */
9423
+ public readonly storageUtilisationBytes: U64,
9424
+ /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
9425
+ public readonly gratisStorage: U64,
9426
+ /** `a_i`: Number of items in storage. */
9427
+ public readonly storageUtilisationCount: U32,
9428
+ /** `a_r`: Creation account time slot. */
9429
+ public readonly created: TimeSlot,
9430
+ /** `a_a`: Most recent accumulation time slot. */
9431
+ public readonly lastAccumulation: TimeSlot,
9432
+ /** `a_p`: Parent service ID. */
9433
+ public readonly parentService: ServiceId,
9434
+ ) {
9435
+ super();
9436
+ }
9437
+ }
9438
+
9439
+ declare class PreimageItem extends WithDebug {
9440
+ static Codec = codec.Class(PreimageItem, {
9441
+ hash: codec.bytes(HASH_SIZE).asOpaque<PreimageHash>(),
9442
+ blob: codec.blob,
9443
+ });
9444
+
9445
+ static create({ hash, blob }: CodecRecord<PreimageItem>) {
9446
+ return new PreimageItem(hash, blob);
9447
+ }
9448
+
9449
+ private constructor(
9450
+ readonly hash: PreimageHash,
9451
+ readonly blob: BytesBlob,
9452
+ ) {
9453
+ super();
9454
+ }
9455
+ }
9456
+
9457
+ type StorageKey = Opaque<BytesBlob, "storage key">;
9458
+
9459
+ declare class StorageItem extends WithDebug {
9460
+ static Codec = codec.Class(StorageItem, {
9461
+ key: codec.blob.convert(
9462
+ (i) => i,
9463
+ (o) => asOpaqueType(o),
9464
+ ),
9465
+ value: codec.blob,
9466
+ });
9467
+
9468
+ static create({ key, value }: CodecRecord<StorageItem>) {
9469
+ return new StorageItem(key, value);
9470
+ }
9471
+
9472
+ private constructor(
9473
+ readonly key: StorageKey,
9474
+ readonly value: BytesBlob,
9475
+ ) {
9476
+ super();
9477
+ }
9478
+ }
9479
+
9480
+ declare const MAX_LOOKUP_HISTORY_SLOTS = 3;
9481
+ type LookupHistorySlots = KnownSizeArray<TimeSlot, `0-${typeof MAX_LOOKUP_HISTORY_SLOTS} timeslots`>;
9482
+ declare function tryAsLookupHistorySlots(items: readonly TimeSlot[]): LookupHistorySlots {
9483
+ const knownSize = asKnownSize(items) as LookupHistorySlots;
9484
+ if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
9485
+ throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
9486
+ }
9487
+ return knownSize;
9488
+ }
9489
+
9490
+ /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
9491
+ declare class LookupHistoryItem {
9492
+ constructor(
9493
+ public readonly hash: PreimageHash,
9494
+ public readonly length: U32,
9495
+ /**
9496
+ * Preimage availability history as a sequence of time slots.
9497
+ * See PreimageStatus and the following GP fragment for more details.
9498
+ * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
9499
+ public readonly slots: LookupHistorySlots,
9500
+ ) {}
9501
+
9502
+ static isRequested(item: LookupHistoryItem | LookupHistorySlots): boolean {
9503
+ if ("slots" in item) {
9504
+ return item.slots.length === 0;
9505
+ }
9506
+ return item.length === 0;
9507
+ }
9508
+ }
9509
+
9297
9510
  /** Dictionary entry of services that auto-accumulate every block. */
9298
9511
  declare class AutoAccumulate {
9299
9512
  static Codec = codec.Class(AutoAccumulate, {
@@ -9314,33 +9527,42 @@ declare class AutoAccumulate {
9314
9527
  }
9315
9528
 
9316
9529
  /**
9317
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11da0111da01?v=0.6.7
9530
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
9318
9531
  */
9319
9532
  declare class PrivilegedServices {
9533
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
9320
9534
  static Codec = codec.Class(PrivilegedServices, {
9321
9535
  manager: codec.u32.asOpaque<ServiceId>(),
9322
- authManager: codecPerCore(codec.u32.asOpaque<ServiceId>()),
9323
- validatorsManager: codec.u32.asOpaque<ServiceId>(),
9536
+ assigners: codecPerCore(codec.u32.asOpaque<ServiceId>()),
9537
+ delegator: codec.u32.asOpaque<ServiceId>(),
9538
+ registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
9539
+ ? codec.u32.asOpaque<ServiceId>()
9540
+ : ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
9324
9541
  autoAccumulateServices: readonlyArray(codec.sequenceVarLen(AutoAccumulate.Codec)),
9325
9542
  });
9326
9543
 
9327
- static create({ manager, authManager, validatorsManager, autoAccumulateServices }: CodecRecord<PrivilegedServices>) {
9328
- return new PrivilegedServices(manager, authManager, validatorsManager, autoAccumulateServices);
9544
+ static create(a: CodecRecord<PrivilegedServices>) {
9545
+ return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
9329
9546
  }
9330
9547
 
9331
9548
  private constructor(
9332
9549
  /**
9333
- * `chi_m`: The first, χm, is the index of the manager service which is
9334
- * the service able to effect an alteration of χ from block to block,
9550
+ * `χ_M`: Manages alteration of χ from block to block,
9335
9551
  * as well as bestow services with storage deposit credits.
9336
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11a40111a801?v=0.6.7
9552
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
9337
9553
  */
9338
9554
  readonly manager: ServiceId,
9339
- /** `chi_a`: Manages authorization queue one for each core. */
9340
- readonly authManager: PerCore<ServiceId>,
9341
- /** `chi_v`: Managers validator keys. */
9342
- readonly validatorsManager: ServiceId,
9343
- /** `chi_g`: Dictionary of services that auto-accumulate every block with their gas limit. */
9555
+ /** `χ_V`: Managers validator keys. */
9556
+ readonly delegator: ServiceId,
9557
+ /**
9558
+ * `χ_R`: Manages the creation of services in protected range.
9559
+ *
9560
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
9561
+ */
9562
+ readonly registrar: ServiceId,
9563
+ /** `χ_A`: Manages authorization queue one for each core. */
9564
+ readonly assigners: PerCore<ServiceId>,
9565
+ /** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
9344
9566
  readonly autoAccumulateServices: readonly AutoAccumulate[],
9345
9567
  ) {}
9346
9568
  }
@@ -9789,215 +10011,6 @@ declare class SafroleData {
9789
10011
  ) {}
9790
10012
  }
9791
10013
 
9792
- /**
9793
- * `B_S`: The basic minimum balance which all services require.
9794
- *
9795
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
9796
- */
9797
- declare const BASE_SERVICE_BALANCE = 100n;
9798
- /**
9799
- * `B_I`: The additional minimum balance required per item of elective service state.
9800
- *
9801
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
9802
- */
9803
- declare const ELECTIVE_ITEM_BALANCE = 10n;
9804
- /**
9805
- * `B_L`: The additional minimum balance required per octet of elective service state.
9806
- *
9807
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
9808
- */
9809
- declare const ELECTIVE_BYTE_BALANCE = 1n;
9810
-
9811
- declare const zeroSizeHint: SizeHint = {
9812
- bytes: 0,
9813
- isExact: true,
9814
- };
9815
-
9816
- /** 0-byte read, return given default value */
9817
- declare const ignoreValueWithDefault = <T>(defaultValue: T) =>
9818
- Descriptor.new<T>(
9819
- "ignoreValue",
9820
- zeroSizeHint,
9821
- (_e, _v) => {},
9822
- (_d) => defaultValue,
9823
- (_s) => {},
9824
- );
9825
-
9826
- /** Encode and decode object with leading version number. */
9827
- declare const codecWithVersion = <T>(val: Descriptor<T>): Descriptor<T> =>
9828
- Descriptor.new<T>(
9829
- "withVersion",
9830
- {
9831
- bytes: val.sizeHint.bytes + 8,
9832
- isExact: false,
9833
- },
9834
- (e, v) => {
9835
- e.varU64(0n);
9836
- val.encode(e, v);
9837
- },
9838
- (d) => {
9839
- const version = d.varU64();
9840
- if (version !== 0n) {
9841
- throw new Error("Non-zero version is not supported!");
9842
- }
9843
- return val.decode(d);
9844
- },
9845
- (s) => {
9846
- s.varU64();
9847
- val.skip(s);
9848
- },
9849
- );
9850
-
9851
- /**
9852
- * Service account details.
9853
- *
9854
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
9855
- */
9856
- declare class ServiceAccountInfo extends WithDebug {
9857
- static Codec = codec.Class(ServiceAccountInfo, {
9858
- codeHash: codec.bytes(HASH_SIZE).asOpaque<CodeHash>(),
9859
- balance: codec.u64,
9860
- accumulateMinGas: codec.u64.convert((x) => x, tryAsServiceGas),
9861
- onTransferMinGas: codec.u64.convert((x) => x, tryAsServiceGas),
9862
- storageUtilisationBytes: codec.u64,
9863
- gratisStorage: codec.u64,
9864
- storageUtilisationCount: codec.u32,
9865
- created: codec.u32.convert((x) => x, tryAsTimeSlot),
9866
- lastAccumulation: codec.u32.convert((x) => x, tryAsTimeSlot),
9867
- parentService: codec.u32.convert((x) => x, tryAsServiceId),
9868
- });
9869
-
9870
- static create(a: CodecRecord<ServiceAccountInfo>) {
9871
- return new ServiceAccountInfo(
9872
- a.codeHash,
9873
- a.balance,
9874
- a.accumulateMinGas,
9875
- a.onTransferMinGas,
9876
- a.storageUtilisationBytes,
9877
- a.gratisStorage,
9878
- a.storageUtilisationCount,
9879
- a.created,
9880
- a.lastAccumulation,
9881
- a.parentService,
9882
- );
9883
- }
9884
-
9885
- /**
9886
- * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
9887
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
9888
- */
9889
- static calculateThresholdBalance(items: U32, bytes: U64, gratisStorage: U64): U64 {
9890
- const storageCost =
9891
- BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
9892
-
9893
- if (storageCost < 0n) {
9894
- return tryAsU64(0);
9895
- }
9896
-
9897
- if (storageCost >= 2n ** 64n) {
9898
- return tryAsU64(2n ** 64n - 1n);
9899
- }
9900
-
9901
- return tryAsU64(storageCost);
9902
- }
9903
-
9904
- private constructor(
9905
- /** `a_c`: Hash of the service code. */
9906
- public readonly codeHash: CodeHash,
9907
- /** `a_b`: Current account balance. */
9908
- public readonly balance: U64,
9909
- /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
9910
- public readonly accumulateMinGas: ServiceGas,
9911
- /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
9912
- public readonly onTransferMinGas: ServiceGas,
9913
- /** `a_o`: Total number of octets in storage. */
9914
- public readonly storageUtilisationBytes: U64,
9915
- /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
9916
- public readonly gratisStorage: U64,
9917
- /** `a_i`: Number of items in storage. */
9918
- public readonly storageUtilisationCount: U32,
9919
- /** `a_r`: Creation account time slot. */
9920
- public readonly created: TimeSlot,
9921
- /** `a_a`: Most recent accumulation time slot. */
9922
- public readonly lastAccumulation: TimeSlot,
9923
- /** `a_p`: Parent service ID. */
9924
- public readonly parentService: ServiceId,
9925
- ) {
9926
- super();
9927
- }
9928
- }
9929
-
9930
- declare class PreimageItem extends WithDebug {
9931
- static Codec = codec.Class(PreimageItem, {
9932
- hash: codec.bytes(HASH_SIZE).asOpaque<PreimageHash>(),
9933
- blob: codec.blob,
9934
- });
9935
-
9936
- static create({ hash, blob }: CodecRecord<PreimageItem>) {
9937
- return new PreimageItem(hash, blob);
9938
- }
9939
-
9940
- private constructor(
9941
- readonly hash: PreimageHash,
9942
- readonly blob: BytesBlob,
9943
- ) {
9944
- super();
9945
- }
9946
- }
9947
-
9948
- type StorageKey = Opaque<BytesBlob, "storage key">;
9949
-
9950
- declare class StorageItem extends WithDebug {
9951
- static Codec = codec.Class(StorageItem, {
9952
- key: codec.blob.convert(
9953
- (i) => i,
9954
- (o) => asOpaqueType(o),
9955
- ),
9956
- value: codec.blob,
9957
- });
9958
-
9959
- static create({ key, value }: CodecRecord<StorageItem>) {
9960
- return new StorageItem(key, value);
9961
- }
9962
-
9963
- private constructor(
9964
- readonly key: StorageKey,
9965
- readonly value: BytesBlob,
9966
- ) {
9967
- super();
9968
- }
9969
- }
9970
-
9971
- declare const MAX_LOOKUP_HISTORY_SLOTS = 3;
9972
- type LookupHistorySlots = KnownSizeArray<TimeSlot, `0-${typeof MAX_LOOKUP_HISTORY_SLOTS} timeslots`>;
9973
- declare function tryAsLookupHistorySlots(items: readonly TimeSlot[]): LookupHistorySlots {
9974
- const knownSize = asKnownSize(items) as LookupHistorySlots;
9975
- if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
9976
- throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
9977
- }
9978
- return knownSize;
9979
- }
9980
-
9981
- /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
9982
- declare class LookupHistoryItem {
9983
- constructor(
9984
- public readonly hash: PreimageHash,
9985
- public readonly length: U32,
9986
- /**
9987
- * Preimage availability history as a sequence of time slots.
9988
- * See PreimageStatus and the following GP fragment for more details.
9989
- * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
9990
- public readonly slots: LookupHistorySlots,
9991
- ) {}
9992
-
9993
- static isRequested(item: LookupHistoryItem | LookupHistorySlots): boolean {
9994
- if ("slots" in item) {
9995
- return item.slots.length === 0;
9996
- }
9997
- return item.length === 0;
9998
- }
9999
- }
10000
-
10001
10014
  declare const codecServiceId: Descriptor<ServiceId> =
10002
10015
  Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
10003
10016
  ? codec.u32.asOpaque<ServiceId>()
@@ -11172,8 +11185,9 @@ declare class InMemoryState extends WithDebug implements State, EnumerableState
11172
11185
  epochRoot: Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
11173
11186
  privilegedServices: PrivilegedServices.create({
11174
11187
  manager: tryAsServiceId(0),
11175
- authManager: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
11176
- validatorsManager: tryAsServiceId(0),
11188
+ assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
11189
+ delegator: tryAsServiceId(0),
11190
+ registrar: tryAsServiceId(MAX_VALUE),
11177
11191
  autoAccumulateServices: [],
11178
11192
  }),
11179
11193
  accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
@@ -13678,6 +13692,8 @@ declare enum NewServiceError {
13678
13692
  InsufficientFunds = 0,
13679
13693
  /** Service is not privileged to set gratis storage. */
13680
13694
  UnprivilegedService = 1,
13695
+ /** Registrar attempting to create a service with already existing id. */
13696
+ RegistrarServiceIdAlreadyTaken = 2,
13681
13697
  }
13682
13698
 
13683
13699
  declare enum UpdatePrivilegesError {
@@ -13743,14 +13759,18 @@ interface PartialState {
13743
13759
  ): Result$2<OK, TransferError>;
13744
13760
 
13745
13761
  /**
13746
- * Create a new service with given codeHash, length, gas, allowance and gratisStorage.
13762
+ * Create a new service with given codeHash, length, gas, allowance, gratisStorage and wantedServiceId.
13747
13763
  *
13748
- * Returns a newly assigned id of that service.
13749
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/2f4c022f4c02?v=0.6.7
13764
+ * Returns a newly assigned id
13765
+ * or `wantedServiceId` if it's lower than `S`
13766
+ * and parent of that service is `Registrar`.
13767
+ *
13768
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/2fa9042fc304?v=0.7.2
13750
13769
  *
13751
13770
  * An error can be returned in case the account does not
13752
13771
  * have the required balance
13753
- * or tries to set gratis storage without being privileged.
13772
+ * or tries to set gratis storage without being `Manager`
13773
+ * or `Registrar` tries to set service id thats already taken.
13754
13774
  */
13755
13775
  newService(
13756
13776
  codeHash: CodeHash,
@@ -13758,6 +13778,7 @@ interface PartialState {
13758
13778
  gas: ServiceGas,
13759
13779
  allowance: ServiceGas,
13760
13780
  gratisStorage: U64,
13781
+ wantedServiceId: U64,
13761
13782
  ): Result$2<ServiceId, NewServiceError>;
13762
13783
 
13763
13784
  /** Upgrade code of currently running service. */
@@ -13779,7 +13800,7 @@ interface PartialState {
13779
13800
  updateAuthorizationQueue(
13780
13801
  coreIndex: CoreIndex,
13781
13802
  authQueue: FixedSizeArray<Blake2bHash, AUTHORIZATION_QUEUE_SIZE>,
13782
- authManager: ServiceId | null,
13803
+ assigners: ServiceId | null,
13783
13804
  ): Result$2<OK, UpdatePrivilegesError>;
13784
13805
 
13785
13806
  /**
@@ -13788,14 +13809,16 @@ interface PartialState {
13788
13809
  * `m`: manager service (can change privileged services)
13789
13810
  * `a`: manages authorization queue
13790
13811
  * `v`: manages validator keys
13791
- * `g`: collection of serviceId -> gas that auto-accumulate every block
13812
+ * `r`: manages create new services in protected id range.
13813
+ * `z`: collection of serviceId -> gas that auto-accumulate every block
13792
13814
  *
13793
13815
  */
13794
13816
  updatePrivilegedServices(
13795
13817
  m: ServiceId | null,
13796
13818
  a: PerCore<ServiceId>,
13797
13819
  v: ServiceId | null,
13798
- g: [ServiceId, ServiceGas][],
13820
+ r: ServiceId | null,
13821
+ z: [ServiceId, ServiceGas][],
13799
13822
  ): Result$2<OK, UpdatePrivilegesError>;
13800
13823
 
13801
13824
  /** Yield accumulation trie result hash. */
@@ -17713,7 +17736,7 @@ declare class AccumulationStateUpdate {
17713
17736
  /** Services state updates. */
17714
17737
  public readonly services: ServicesUpdate,
17715
17738
  /** Pending transfers. */
17716
- public readonly transfers: PendingTransfer[],
17739
+ public transfers: PendingTransfer[],
17717
17740
  /** Yielded accumulation root. */
17718
17741
  public readonly yieldedRoots: Map<ServiceId, OpaqueHash> = new Map(),
17719
17742
  ) {}
@@ -17764,11 +17787,18 @@ declare class AccumulationStateUpdate {
17764
17787
  if (from.privilegedServices !== null) {
17765
17788
  update.privilegedServices = PrivilegedServices.create({
17766
17789
  ...from.privilegedServices,
17767
- authManager: asKnownSize([...from.privilegedServices.authManager]),
17790
+ assigners: asKnownSize([...from.privilegedServices.assigners]),
17768
17791
  });
17769
17792
  }
17770
17793
  return update;
17771
17794
  }
17795
+
17796
+ /** Retrieve and clear pending transfers. */
17797
+ takeTransfers() {
17798
+ const transfers = this.transfers;
17799
+ this.transfers = [];
17800
+ return transfers;
17801
+ }
17772
17802
  }
17773
17803
 
17774
17804
  type StateSlice = Pick<State, "getService" | "privilegedServices">;
@@ -18035,7 +18065,7 @@ declare const HostCallResult = {
18035
18065
  OOB: tryAsU64(0xffff_ffff_ffff_fffdn), // 2**64 - 3
18036
18066
  /** Index unknown. */
18037
18067
  WHO: tryAsU64(0xffff_ffff_ffff_fffcn), // 2**64 - 4
18038
- /** Storage full. */
18068
+ /** Storage full or resource already allocated. */
18039
18069
  FULL: tryAsU64(0xffff_ffff_ffff_fffbn), // 2**64 - 5
18040
18070
  /** Core index unknown. */
18041
18071
  CORE: tryAsU64(0xffff_ffff_ffff_fffan), // 2**64 - 6
@@ -18043,7 +18073,7 @@ declare const HostCallResult = {
18043
18073
  CASH: tryAsU64(0xffff_ffff_ffff_fff9n), // 2**64 - 7
18044
18074
  /** Gas limit too low. */
18045
18075
  LOW: tryAsU64(0xffff_ffff_ffff_fff8n), // 2**64 - 8
18046
- /** The item is already solicited or cannot be forgotten. */
18076
+ /** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
18047
18077
  HUH: tryAsU64(0xffff_ffff_ffff_fff7n), // 2**64 - 9
18048
18078
  /** The return value indicating general success. */
18049
18079
  OK: tryAsU64(0n),
@@ -18948,6 +18978,7 @@ declare namespace index$2 {
18948
18978
  declare class JsonServiceInfo {
18949
18979
  static fromJson = json.object<JsonServiceInfo, ServiceAccountInfo>(
18950
18980
  {
18981
+ ...(Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? { version: "number" } : {}),
18951
18982
  code_hash: fromJson.bytes32(),
18952
18983
  balance: json.fromNumber((x) => tryAsU64(x)),
18953
18984
  min_item_gas: json.fromNumber((x) => tryAsServiceGas(x)),
@@ -18986,6 +19017,7 @@ declare class JsonServiceInfo {
18986
19017
  },
18987
19018
  );
18988
19019
 
19020
+ version?: number;
18989
19021
  code_hash!: CodeHash;
18990
19022
  balance!: U64;
18991
19023
  min_item_gas!: ServiceGas;
@@ -19032,6 +19064,19 @@ declare const lookupMetaFromJson = json.object<JsonLookupMeta, LookupHistoryItem
19032
19064
  ({ key, value }) => new LookupHistoryItem(key.hash, key.length, value),
19033
19065
  );
19034
19066
 
19067
+ declare const preimageStatusFromJson = json.object<JsonPreimageStatus, LookupHistoryItem>(
19068
+ {
19069
+ hash: fromJson.bytes32(),
19070
+ status: json.array("number"),
19071
+ },
19072
+ ({ hash, status }) => new LookupHistoryItem(hash, tryAsU32(0), status),
19073
+ );
19074
+
19075
+ type JsonPreimageStatus = {
19076
+ hash: PreimageHash;
19077
+ status: LookupHistorySlots;
19078
+ };
19079
+
19035
19080
  type JsonLookupMeta = {
19036
19081
  key: {
19037
19082
  hash: PreimageHash;
@@ -19044,21 +19089,34 @@ declare class JsonService {
19044
19089
  static fromJson = json.object<JsonService, InMemoryService>(
19045
19090
  {
19046
19091
  id: "number",
19047
- data: {
19048
- service: JsonServiceInfo.fromJson,
19049
- preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
19050
- storage: json.optional(json.array(JsonStorageItem.fromJson)),
19051
- lookup_meta: json.optional(json.array(lookupMetaFromJson)),
19052
- },
19092
+ data: Compatibility.isLessThan(GpVersion.V0_7_1)
19093
+ ? {
19094
+ service: JsonServiceInfo.fromJson,
19095
+ preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
19096
+ storage: json.optional(json.array(JsonStorageItem.fromJson)),
19097
+ lookup_meta: json.optional(json.array(lookupMetaFromJson)),
19098
+ }
19099
+ : {
19100
+ service: JsonServiceInfo.fromJson,
19101
+ storage: json.optional(json.array(JsonStorageItem.fromJson)),
19102
+ preimages_blob: json.optional(json.array(JsonPreimageItem.fromJson)),
19103
+ preimages_status: json.optional(json.array(preimageStatusFromJson)),
19104
+ },
19053
19105
  },
19054
19106
  ({ id, data }) => {
19107
+ const preimages = HashDictionary.fromEntries(
19108
+ (data.preimages ?? data.preimages_blob ?? []).map((x) => [x.hash, x]),
19109
+ );
19110
+
19055
19111
  const lookupHistory = HashDictionary.new<PreimageHash, LookupHistoryItem[]>();
19056
- for (const item of data.lookup_meta ?? []) {
19112
+
19113
+ for (const item of data.lookup_meta ?? data.preimages_status ?? []) {
19057
19114
  const data = lookupHistory.get(item.hash) ?? [];
19058
- data.push(item);
19115
+ const length = tryAsU32(preimages.get(item.hash)?.blob.length ?? item.length);
19116
+ data.push(new LookupHistoryItem(item.hash, length, item.slots));
19059
19117
  lookupHistory.set(item.hash, data);
19060
19118
  }
19061
- const preimages = HashDictionary.fromEntries((data.preimages ?? []).map((x) => [x.hash, x]));
19119
+
19062
19120
  const storage = new Map<string, StorageItem>();
19063
19121
 
19064
19122
  const entries = (data.storage ?? []).map(({ key, value }) => {
@@ -19085,6 +19143,8 @@ declare class JsonService {
19085
19143
  preimages?: JsonPreimageItem[];
19086
19144
  storage?: JsonStorageItem[];
19087
19145
  lookup_meta?: LookupHistoryItem[];
19146
+ preimages_blob?: JsonPreimageItem[];
19147
+ preimages_status?: LookupHistoryItem[];
19088
19148
  };
19089
19149
  }
19090
19150
 
@@ -19315,8 +19375,12 @@ declare class JsonServiceStatistics {
19315
19375
  extrinsic_count: "number",
19316
19376
  accumulate_count: "number",
19317
19377
  accumulate_gas_used: json.fromNumber(tryAsServiceGas),
19318
- on_transfers_count: "number",
19319
- on_transfers_gas_used: json.fromNumber(tryAsServiceGas),
19378
+ ...(Compatibility.isLessThan(GpVersion.V0_7_1)
19379
+ ? {
19380
+ on_transfers_count: "number",
19381
+ on_transfers_gas_used: json.fromNumber(tryAsServiceGas),
19382
+ }
19383
+ : {}),
19320
19384
  },
19321
19385
  ({
19322
19386
  provided_count,
@@ -19343,8 +19407,8 @@ declare class JsonServiceStatistics {
19343
19407
  extrinsicCount: extrinsic_count,
19344
19408
  accumulateCount: accumulate_count,
19345
19409
  accumulateGasUsed: accumulate_gas_used,
19346
- onTransfersCount: on_transfers_count,
19347
- onTransfersGasUsed: on_transfers_gas_used,
19410
+ onTransfersCount: on_transfers_count ?? tryAsU32(0),
19411
+ onTransfersGasUsed: on_transfers_gas_used ?? tryAsServiceGas(0),
19348
19412
  });
19349
19413
  },
19350
19414
  );
@@ -19359,8 +19423,8 @@ declare class JsonServiceStatistics {
19359
19423
  extrinsic_count!: U16;
19360
19424
  accumulate_count!: U32;
19361
19425
  accumulate_gas_used!: ServiceGas;
19362
- on_transfers_count!: U32;
19363
- on_transfers_gas_used!: ServiceGas;
19426
+ on_transfers_count?: U32;
19427
+ on_transfers_gas_used?: ServiceGas;
19364
19428
  }
19365
19429
 
19366
19430
  type ServiceStatisticsEntry = {
@@ -19432,8 +19496,9 @@ type JsonStateDump = {
19432
19496
  tau: State["timeslot"];
19433
19497
  chi: {
19434
19498
  chi_m: PrivilegedServices["manager"];
19435
- chi_a: PrivilegedServices["authManager"];
19436
- chi_v: PrivilegedServices["validatorsManager"];
19499
+ chi_a: PrivilegedServices["assigners"];
19500
+ chi_v: PrivilegedServices["delegator"];
19501
+ chi_r?: PrivilegedServices["registrar"];
19437
19502
  chi_g: PrivilegedServices["autoAccumulateServices"] | null;
19438
19503
  };
19439
19504
  pi: JsonStatisticsData;
@@ -19466,6 +19531,7 @@ declare const fullStateDumpFromJson = (spec: ChainSpec) =>
19466
19531
  chi_m: "number",
19467
19532
  chi_a: json.array("number"),
19468
19533
  chi_v: "number",
19534
+ chi_r: json.optional("number"),
19469
19535
  chi_g: json.nullable(
19470
19536
  json.array({
19471
19537
  service: "number",
@@ -19498,6 +19564,9 @@ declare const fullStateDumpFromJson = (spec: ChainSpec) =>
19498
19564
  theta,
19499
19565
  accounts,
19500
19566
  }): InMemoryState => {
19567
+ if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && chi.chi_r === undefined) {
19568
+ throw new Error("Registrar is required in Privileges GP ^0.7.1");
19569
+ }
19501
19570
  return InMemoryState.create({
19502
19571
  authPools: tryAsPerCore(
19503
19572
  alpha.map((perCore) => {
@@ -19531,8 +19600,9 @@ declare const fullStateDumpFromJson = (spec: ChainSpec) =>
19531
19600
  timeslot: tau,
19532
19601
  privilegedServices: PrivilegedServices.create({
19533
19602
  manager: chi.chi_m,
19534
- authManager: chi.chi_a,
19535
- validatorsManager: chi.chi_v,
19603
+ assigners: chi.chi_a,
19604
+ delegator: chi.chi_v,
19605
+ registrar: chi.chi_r ?? tryAsServiceId(2 ** 32 - 1),
19536
19606
  autoAccumulateServices: chi.chi_g ?? [],
19537
19607
  }),
19538
19608
  statistics: JsonStatisticsData.toStatisticsData(spec, pi),
@@ -19555,6 +19625,7 @@ declare const index$1_JsonDisputesRecords: typeof JsonDisputesRecords;
19555
19625
  type index$1_JsonLookupMeta = JsonLookupMeta;
19556
19626
  type index$1_JsonPreimageItem = JsonPreimageItem;
19557
19627
  declare const index$1_JsonPreimageItem: typeof JsonPreimageItem;
19628
+ type index$1_JsonPreimageStatus = JsonPreimageStatus;
19558
19629
  type index$1_JsonRecentBlockState = JsonRecentBlockState;
19559
19630
  type index$1_JsonRecentBlocks = JsonRecentBlocks;
19560
19631
  type index$1_JsonReportedWorkPackageInfo = JsonReportedWorkPackageInfo;
@@ -19579,6 +19650,7 @@ declare const index$1_disputesRecordsFromJson: typeof disputesRecordsFromJson;
19579
19650
  declare const index$1_fullStateDumpFromJson: typeof fullStateDumpFromJson;
19580
19651
  declare const index$1_lookupMetaFromJson: typeof lookupMetaFromJson;
19581
19652
  declare const index$1_notYetAccumulatedFromJson: typeof notYetAccumulatedFromJson;
19653
+ declare const index$1_preimageStatusFromJson: typeof preimageStatusFromJson;
19582
19654
  declare const index$1_recentBlockStateFromJson: typeof recentBlockStateFromJson;
19583
19655
  declare const index$1_recentBlocksHistoryFromJson: typeof recentBlocksHistoryFromJson;
19584
19656
  declare const index$1_reportedWorkPackageFromJson: typeof reportedWorkPackageFromJson;
@@ -19586,8 +19658,8 @@ declare const index$1_serviceStatisticsEntryFromJson: typeof serviceStatisticsEn
19586
19658
  declare const index$1_ticketFromJson: typeof ticketFromJson;
19587
19659
  declare const index$1_validatorDataFromJson: typeof validatorDataFromJson;
19588
19660
  declare namespace index$1 {
19589
- export { index$1_JsonCoreStatistics as JsonCoreStatistics, index$1_JsonDisputesRecords as JsonDisputesRecords, index$1_JsonPreimageItem as JsonPreimageItem, index$1_JsonService as JsonService, index$1_JsonServiceInfo as JsonServiceInfo, index$1_JsonServiceStatistics as JsonServiceStatistics, index$1_JsonStatisticsData as JsonStatisticsData, index$1_JsonStorageItem as JsonStorageItem, index$1_JsonValidatorStatistics as JsonValidatorStatistics, index$1_TicketsOrKeys as TicketsOrKeys, index$1_availabilityAssignmentFromJson as availabilityAssignmentFromJson, index$1_disputesRecordsFromJson as disputesRecordsFromJson, index$1_fullStateDumpFromJson as fullStateDumpFromJson, index$1_lookupMetaFromJson as lookupMetaFromJson, index$1_notYetAccumulatedFromJson as notYetAccumulatedFromJson, index$1_recentBlockStateFromJson as recentBlockStateFromJson, index$1_recentBlocksHistoryFromJson as recentBlocksHistoryFromJson, index$1_reportedWorkPackageFromJson as reportedWorkPackageFromJson, index$1_serviceStatisticsEntryFromJson as serviceStatisticsEntryFromJson, index$1_ticketFromJson as ticketFromJson, index$1_validatorDataFromJson as validatorDataFromJson };
19590
- export type { index$1_JsonAvailabilityAssignment as JsonAvailabilityAssignment, index$1_JsonLookupMeta as JsonLookupMeta, index$1_JsonRecentBlockState as JsonRecentBlockState, index$1_JsonRecentBlocks as JsonRecentBlocks, index$1_JsonReportedWorkPackageInfo as JsonReportedWorkPackageInfo, index$1_JsonStateDump as JsonStateDump, index$1_ServiceStatisticsEntry as ServiceStatisticsEntry };
19661
+ export { index$1_JsonCoreStatistics as JsonCoreStatistics, index$1_JsonDisputesRecords as JsonDisputesRecords, index$1_JsonPreimageItem as JsonPreimageItem, index$1_JsonService as JsonService, index$1_JsonServiceInfo as JsonServiceInfo, index$1_JsonServiceStatistics as JsonServiceStatistics, index$1_JsonStatisticsData as JsonStatisticsData, index$1_JsonStorageItem as JsonStorageItem, index$1_JsonValidatorStatistics as JsonValidatorStatistics, index$1_TicketsOrKeys as TicketsOrKeys, index$1_availabilityAssignmentFromJson as availabilityAssignmentFromJson, index$1_disputesRecordsFromJson as disputesRecordsFromJson, index$1_fullStateDumpFromJson as fullStateDumpFromJson, index$1_lookupMetaFromJson as lookupMetaFromJson, index$1_notYetAccumulatedFromJson as notYetAccumulatedFromJson, index$1_preimageStatusFromJson as preimageStatusFromJson, index$1_recentBlockStateFromJson as recentBlockStateFromJson, index$1_recentBlocksHistoryFromJson as recentBlocksHistoryFromJson, index$1_reportedWorkPackageFromJson as reportedWorkPackageFromJson, index$1_serviceStatisticsEntryFromJson as serviceStatisticsEntryFromJson, index$1_ticketFromJson as ticketFromJson, index$1_validatorDataFromJson as validatorDataFromJson };
19662
+ export type { index$1_JsonAvailabilityAssignment as JsonAvailabilityAssignment, index$1_JsonLookupMeta as JsonLookupMeta, index$1_JsonPreimageStatus as JsonPreimageStatus, index$1_JsonRecentBlockState as JsonRecentBlockState, index$1_JsonRecentBlocks as JsonRecentBlocks, index$1_JsonReportedWorkPackageInfo as JsonReportedWorkPackageInfo, index$1_JsonStateDump as JsonStateDump, index$1_ServiceStatisticsEntry as ServiceStatisticsEntry };
19591
19663
  }
19592
19664
 
19593
19665
  /** Helper function to create most used hashes in the block */