@typeberry/lib 0.1.3-8258907 → 0.1.3-a6eda68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/index.cjs +268 -226
  2. package/index.d.ts +324 -258
  3. package/index.js +268 -226
  4. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -9245,8 +9245,6 @@ declare function hashComparator<V extends OpaqueHash>(a: V, b: V) {
9245
9245
  return a.compare(b);
9246
9246
  }
9247
9247
 
9248
- // TODO [ToDr] Not sure where these should live yet :(
9249
-
9250
9248
  /**
9251
9249
  * `J`: The maximum sum of dependency items in a work-report.
9252
9250
  *
@@ -9300,6 +9298,215 @@ declare class NotYetAccumulatedReport extends WithDebug {
9300
9298
  }
9301
9299
  }
9302
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
+
9303
9510
  /** Dictionary entry of services that auto-accumulate every block. */
9304
9511
  declare class AutoAccumulate {
9305
9512
  static Codec = codec.Class(AutoAccumulate, {
@@ -9320,33 +9527,42 @@ declare class AutoAccumulate {
9320
9527
  }
9321
9528
 
9322
9529
  /**
9323
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11da0111da01?v=0.6.7
9530
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
9324
9531
  */
9325
9532
  declare class PrivilegedServices {
9533
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
9326
9534
  static Codec = codec.Class(PrivilegedServices, {
9327
9535
  manager: codec.u32.asOpaque<ServiceId>(),
9328
- authManager: codecPerCore(codec.u32.asOpaque<ServiceId>()),
9329
- 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)),
9330
9541
  autoAccumulateServices: readonlyArray(codec.sequenceVarLen(AutoAccumulate.Codec)),
9331
9542
  });
9332
9543
 
9333
- static create({ manager, authManager, validatorsManager, autoAccumulateServices }: CodecRecord<PrivilegedServices>) {
9334
- 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);
9335
9546
  }
9336
9547
 
9337
9548
  private constructor(
9338
9549
  /**
9339
- * `chi_m`: The first, χm, is the index of the manager service which is
9340
- * the service able to effect an alteration of χ from block to block,
9550
+ * `χ_M`: Manages alteration of χ from block to block,
9341
9551
  * as well as bestow services with storage deposit credits.
9342
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/11a40111a801?v=0.6.7
9552
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
9343
9553
  */
9344
9554
  readonly manager: ServiceId,
9345
- /** `chi_a`: Manages authorization queue one for each core. */
9346
- readonly authManager: PerCore<ServiceId>,
9347
- /** `chi_v`: Managers validator keys. */
9348
- readonly validatorsManager: ServiceId,
9349
- /** `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. */
9350
9566
  readonly autoAccumulateServices: readonly AutoAccumulate[],
9351
9567
  ) {}
9352
9568
  }
@@ -9795,215 +10011,6 @@ declare class SafroleData {
9795
10011
  ) {}
9796
10012
  }
9797
10013
 
9798
- /**
9799
- * `B_S`: The basic minimum balance which all services require.
9800
- *
9801
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
9802
- */
9803
- declare const BASE_SERVICE_BALANCE = 100n;
9804
- /**
9805
- * `B_I`: The additional minimum balance required per item of elective service state.
9806
- *
9807
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
9808
- */
9809
- declare const ELECTIVE_ITEM_BALANCE = 10n;
9810
- /**
9811
- * `B_L`: The additional minimum balance required per octet of elective service state.
9812
- *
9813
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
9814
- */
9815
- declare const ELECTIVE_BYTE_BALANCE = 1n;
9816
-
9817
- declare const zeroSizeHint: SizeHint = {
9818
- bytes: 0,
9819
- isExact: true,
9820
- };
9821
-
9822
- /** 0-byte read, return given default value */
9823
- declare const ignoreValueWithDefault = <T>(defaultValue: T) =>
9824
- Descriptor.new<T>(
9825
- "ignoreValue",
9826
- zeroSizeHint,
9827
- (_e, _v) => {},
9828
- (_d) => defaultValue,
9829
- (_s) => {},
9830
- );
9831
-
9832
- /** Encode and decode object with leading version number. */
9833
- declare const codecWithVersion = <T>(val: Descriptor<T>): Descriptor<T> =>
9834
- Descriptor.new<T>(
9835
- "withVersion",
9836
- {
9837
- bytes: val.sizeHint.bytes + 8,
9838
- isExact: false,
9839
- },
9840
- (e, v) => {
9841
- e.varU64(0n);
9842
- val.encode(e, v);
9843
- },
9844
- (d) => {
9845
- const version = d.varU64();
9846
- if (version !== 0n) {
9847
- throw new Error("Non-zero version is not supported!");
9848
- }
9849
- return val.decode(d);
9850
- },
9851
- (s) => {
9852
- s.varU64();
9853
- val.skip(s);
9854
- },
9855
- );
9856
-
9857
- /**
9858
- * Service account details.
9859
- *
9860
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
9861
- */
9862
- declare class ServiceAccountInfo extends WithDebug {
9863
- static Codec = codec.Class(ServiceAccountInfo, {
9864
- codeHash: codec.bytes(HASH_SIZE).asOpaque<CodeHash>(),
9865
- balance: codec.u64,
9866
- accumulateMinGas: codec.u64.convert((x) => x, tryAsServiceGas),
9867
- onTransferMinGas: codec.u64.convert((x) => x, tryAsServiceGas),
9868
- storageUtilisationBytes: codec.u64,
9869
- gratisStorage: codec.u64,
9870
- storageUtilisationCount: codec.u32,
9871
- created: codec.u32.convert((x) => x, tryAsTimeSlot),
9872
- lastAccumulation: codec.u32.convert((x) => x, tryAsTimeSlot),
9873
- parentService: codec.u32.convert((x) => x, tryAsServiceId),
9874
- });
9875
-
9876
- static create(a: CodecRecord<ServiceAccountInfo>) {
9877
- return new ServiceAccountInfo(
9878
- a.codeHash,
9879
- a.balance,
9880
- a.accumulateMinGas,
9881
- a.onTransferMinGas,
9882
- a.storageUtilisationBytes,
9883
- a.gratisStorage,
9884
- a.storageUtilisationCount,
9885
- a.created,
9886
- a.lastAccumulation,
9887
- a.parentService,
9888
- );
9889
- }
9890
-
9891
- /**
9892
- * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
9893
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
9894
- */
9895
- static calculateThresholdBalance(items: U32, bytes: U64, gratisStorage: U64): U64 {
9896
- const storageCost =
9897
- BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
9898
-
9899
- if (storageCost < 0n) {
9900
- return tryAsU64(0);
9901
- }
9902
-
9903
- if (storageCost >= 2n ** 64n) {
9904
- return tryAsU64(2n ** 64n - 1n);
9905
- }
9906
-
9907
- return tryAsU64(storageCost);
9908
- }
9909
-
9910
- private constructor(
9911
- /** `a_c`: Hash of the service code. */
9912
- public readonly codeHash: CodeHash,
9913
- /** `a_b`: Current account balance. */
9914
- public readonly balance: U64,
9915
- /** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
9916
- public readonly accumulateMinGas: ServiceGas,
9917
- /** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
9918
- public readonly onTransferMinGas: ServiceGas,
9919
- /** `a_o`: Total number of octets in storage. */
9920
- public readonly storageUtilisationBytes: U64,
9921
- /** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
9922
- public readonly gratisStorage: U64,
9923
- /** `a_i`: Number of items in storage. */
9924
- public readonly storageUtilisationCount: U32,
9925
- /** `a_r`: Creation account time slot. */
9926
- public readonly created: TimeSlot,
9927
- /** `a_a`: Most recent accumulation time slot. */
9928
- public readonly lastAccumulation: TimeSlot,
9929
- /** `a_p`: Parent service ID. */
9930
- public readonly parentService: ServiceId,
9931
- ) {
9932
- super();
9933
- }
9934
- }
9935
-
9936
- declare class PreimageItem extends WithDebug {
9937
- static Codec = codec.Class(PreimageItem, {
9938
- hash: codec.bytes(HASH_SIZE).asOpaque<PreimageHash>(),
9939
- blob: codec.blob,
9940
- });
9941
-
9942
- static create({ hash, blob }: CodecRecord<PreimageItem>) {
9943
- return new PreimageItem(hash, blob);
9944
- }
9945
-
9946
- private constructor(
9947
- readonly hash: PreimageHash,
9948
- readonly blob: BytesBlob,
9949
- ) {
9950
- super();
9951
- }
9952
- }
9953
-
9954
- type StorageKey = Opaque<BytesBlob, "storage key">;
9955
-
9956
- declare class StorageItem extends WithDebug {
9957
- static Codec = codec.Class(StorageItem, {
9958
- key: codec.blob.convert(
9959
- (i) => i,
9960
- (o) => asOpaqueType(o),
9961
- ),
9962
- value: codec.blob,
9963
- });
9964
-
9965
- static create({ key, value }: CodecRecord<StorageItem>) {
9966
- return new StorageItem(key, value);
9967
- }
9968
-
9969
- private constructor(
9970
- readonly key: StorageKey,
9971
- readonly value: BytesBlob,
9972
- ) {
9973
- super();
9974
- }
9975
- }
9976
-
9977
- declare const MAX_LOOKUP_HISTORY_SLOTS = 3;
9978
- type LookupHistorySlots = KnownSizeArray<TimeSlot, `0-${typeof MAX_LOOKUP_HISTORY_SLOTS} timeslots`>;
9979
- declare function tryAsLookupHistorySlots(items: readonly TimeSlot[]): LookupHistorySlots {
9980
- const knownSize = asKnownSize(items) as LookupHistorySlots;
9981
- if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
9982
- throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
9983
- }
9984
- return knownSize;
9985
- }
9986
-
9987
- /** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
9988
- declare class LookupHistoryItem {
9989
- constructor(
9990
- public readonly hash: PreimageHash,
9991
- public readonly length: U32,
9992
- /**
9993
- * Preimage availability history as a sequence of time slots.
9994
- * See PreimageStatus and the following GP fragment for more details.
9995
- * https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
9996
- public readonly slots: LookupHistorySlots,
9997
- ) {}
9998
-
9999
- static isRequested(item: LookupHistoryItem | LookupHistorySlots): boolean {
10000
- if ("slots" in item) {
10001
- return item.slots.length === 0;
10002
- }
10003
- return item.length === 0;
10004
- }
10005
- }
10006
-
10007
10014
  declare const codecServiceId: Descriptor<ServiceId> =
10008
10015
  Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
10009
10016
  ? codec.u32.asOpaque<ServiceId>()
@@ -11178,8 +11185,9 @@ declare class InMemoryState extends WithDebug implements State, EnumerableState
11178
11185
  epochRoot: Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
11179
11186
  privilegedServices: PrivilegedServices.create({
11180
11187
  manager: tryAsServiceId(0),
11181
- authManager: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
11182
- validatorsManager: tryAsServiceId(0),
11188
+ assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
11189
+ delegator: tryAsServiceId(0),
11190
+ registrar: tryAsServiceId(MAX_VALUE),
11183
11191
  autoAccumulateServices: [],
11184
11192
  }),
11185
11193
  accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
@@ -13684,6 +13692,8 @@ declare enum NewServiceError {
13684
13692
  InsufficientFunds = 0,
13685
13693
  /** Service is not privileged to set gratis storage. */
13686
13694
  UnprivilegedService = 1,
13695
+ /** Registrar attempting to create a service with already existing id. */
13696
+ RegistrarServiceIdAlreadyTaken = 2,
13687
13697
  }
13688
13698
 
13689
13699
  declare enum UpdatePrivilegesError {
@@ -13749,14 +13759,18 @@ interface PartialState {
13749
13759
  ): Result$2<OK, TransferError>;
13750
13760
 
13751
13761
  /**
13752
- * 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.
13753
13763
  *
13754
- * Returns a newly assigned id of that service.
13755
- * 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
13756
13769
  *
13757
13770
  * An error can be returned in case the account does not
13758
13771
  * have the required balance
13759
- * 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.
13760
13774
  */
13761
13775
  newService(
13762
13776
  codeHash: CodeHash,
@@ -13764,6 +13778,7 @@ interface PartialState {
13764
13778
  gas: ServiceGas,
13765
13779
  allowance: ServiceGas,
13766
13780
  gratisStorage: U64,
13781
+ wantedServiceId: U64,
13767
13782
  ): Result$2<ServiceId, NewServiceError>;
13768
13783
 
13769
13784
  /** Upgrade code of currently running service. */
@@ -13785,7 +13800,7 @@ interface PartialState {
13785
13800
  updateAuthorizationQueue(
13786
13801
  coreIndex: CoreIndex,
13787
13802
  authQueue: FixedSizeArray<Blake2bHash, AUTHORIZATION_QUEUE_SIZE>,
13788
- authManager: ServiceId | null,
13803
+ assigners: ServiceId | null,
13789
13804
  ): Result$2<OK, UpdatePrivilegesError>;
13790
13805
 
13791
13806
  /**
@@ -13794,14 +13809,16 @@ interface PartialState {
13794
13809
  * `m`: manager service (can change privileged services)
13795
13810
  * `a`: manages authorization queue
13796
13811
  * `v`: manages validator keys
13797
- * `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
13798
13814
  *
13799
13815
  */
13800
13816
  updatePrivilegedServices(
13801
13817
  m: ServiceId | null,
13802
13818
  a: PerCore<ServiceId>,
13803
13819
  v: ServiceId | null,
13804
- g: [ServiceId, ServiceGas][],
13820
+ r: ServiceId | null,
13821
+ z: [ServiceId, ServiceGas][],
13805
13822
  ): Result$2<OK, UpdatePrivilegesError>;
13806
13823
 
13807
13824
  /** Yield accumulation trie result hash. */
@@ -17719,7 +17736,7 @@ declare class AccumulationStateUpdate {
17719
17736
  /** Services state updates. */
17720
17737
  public readonly services: ServicesUpdate,
17721
17738
  /** Pending transfers. */
17722
- public readonly transfers: PendingTransfer[],
17739
+ public transfers: PendingTransfer[],
17723
17740
  /** Yielded accumulation root. */
17724
17741
  public readonly yieldedRoots: Map<ServiceId, OpaqueHash> = new Map(),
17725
17742
  ) {}
@@ -17770,11 +17787,18 @@ declare class AccumulationStateUpdate {
17770
17787
  if (from.privilegedServices !== null) {
17771
17788
  update.privilegedServices = PrivilegedServices.create({
17772
17789
  ...from.privilegedServices,
17773
- authManager: asKnownSize([...from.privilegedServices.authManager]),
17790
+ assigners: asKnownSize([...from.privilegedServices.assigners]),
17774
17791
  });
17775
17792
  }
17776
17793
  return update;
17777
17794
  }
17795
+
17796
+ /** Retrieve and clear pending transfers. */
17797
+ takeTransfers() {
17798
+ const transfers = this.transfers;
17799
+ this.transfers = [];
17800
+ return transfers;
17801
+ }
17778
17802
  }
17779
17803
 
17780
17804
  type StateSlice = Pick<State, "getService" | "privilegedServices">;
@@ -18041,7 +18065,7 @@ declare const HostCallResult = {
18041
18065
  OOB: tryAsU64(0xffff_ffff_ffff_fffdn), // 2**64 - 3
18042
18066
  /** Index unknown. */
18043
18067
  WHO: tryAsU64(0xffff_ffff_ffff_fffcn), // 2**64 - 4
18044
- /** Storage full. */
18068
+ /** Storage full or resource already allocated. */
18045
18069
  FULL: tryAsU64(0xffff_ffff_ffff_fffbn), // 2**64 - 5
18046
18070
  /** Core index unknown. */
18047
18071
  CORE: tryAsU64(0xffff_ffff_ffff_fffan), // 2**64 - 6
@@ -18049,7 +18073,7 @@ declare const HostCallResult = {
18049
18073
  CASH: tryAsU64(0xffff_ffff_ffff_fff9n), // 2**64 - 7
18050
18074
  /** Gas limit too low. */
18051
18075
  LOW: tryAsU64(0xffff_ffff_ffff_fff8n), // 2**64 - 8
18052
- /** 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. */
18053
18077
  HUH: tryAsU64(0xffff_ffff_ffff_fff7n), // 2**64 - 9
18054
18078
  /** The return value indicating general success. */
18055
18079
  OK: tryAsU64(0n),
@@ -18954,6 +18978,7 @@ declare namespace index$2 {
18954
18978
  declare class JsonServiceInfo {
18955
18979
  static fromJson = json.object<JsonServiceInfo, ServiceAccountInfo>(
18956
18980
  {
18981
+ ...(Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? { version: "number" } : {}),
18957
18982
  code_hash: fromJson.bytes32(),
18958
18983
  balance: json.fromNumber((x) => tryAsU64(x)),
18959
18984
  min_item_gas: json.fromNumber((x) => tryAsServiceGas(x)),
@@ -18992,6 +19017,7 @@ declare class JsonServiceInfo {
18992
19017
  },
18993
19018
  );
18994
19019
 
19020
+ version?: number;
18995
19021
  code_hash!: CodeHash;
18996
19022
  balance!: U64;
18997
19023
  min_item_gas!: ServiceGas;
@@ -19038,6 +19064,19 @@ declare const lookupMetaFromJson = json.object<JsonLookupMeta, LookupHistoryItem
19038
19064
  ({ key, value }) => new LookupHistoryItem(key.hash, key.length, value),
19039
19065
  );
19040
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
+
19041
19080
  type JsonLookupMeta = {
19042
19081
  key: {
19043
19082
  hash: PreimageHash;
@@ -19050,21 +19089,34 @@ declare class JsonService {
19050
19089
  static fromJson = json.object<JsonService, InMemoryService>(
19051
19090
  {
19052
19091
  id: "number",
19053
- data: {
19054
- service: JsonServiceInfo.fromJson,
19055
- preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
19056
- storage: json.optional(json.array(JsonStorageItem.fromJson)),
19057
- lookup_meta: json.optional(json.array(lookupMetaFromJson)),
19058
- },
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
+ },
19059
19105
  },
19060
19106
  ({ id, data }) => {
19107
+ const preimages = HashDictionary.fromEntries(
19108
+ (data.preimages ?? data.preimages_blob ?? []).map((x) => [x.hash, x]),
19109
+ );
19110
+
19061
19111
  const lookupHistory = HashDictionary.new<PreimageHash, LookupHistoryItem[]>();
19062
- for (const item of data.lookup_meta ?? []) {
19112
+
19113
+ for (const item of data.lookup_meta ?? data.preimages_status ?? []) {
19063
19114
  const data = lookupHistory.get(item.hash) ?? [];
19064
- 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));
19065
19117
  lookupHistory.set(item.hash, data);
19066
19118
  }
19067
- const preimages = HashDictionary.fromEntries((data.preimages ?? []).map((x) => [x.hash, x]));
19119
+
19068
19120
  const storage = new Map<string, StorageItem>();
19069
19121
 
19070
19122
  const entries = (data.storage ?? []).map(({ key, value }) => {
@@ -19091,6 +19143,8 @@ declare class JsonService {
19091
19143
  preimages?: JsonPreimageItem[];
19092
19144
  storage?: JsonStorageItem[];
19093
19145
  lookup_meta?: LookupHistoryItem[];
19146
+ preimages_blob?: JsonPreimageItem[];
19147
+ preimages_status?: LookupHistoryItem[];
19094
19148
  };
19095
19149
  }
19096
19150
 
@@ -19321,8 +19375,12 @@ declare class JsonServiceStatistics {
19321
19375
  extrinsic_count: "number",
19322
19376
  accumulate_count: "number",
19323
19377
  accumulate_gas_used: json.fromNumber(tryAsServiceGas),
19324
- on_transfers_count: "number",
19325
- 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
+ : {}),
19326
19384
  },
19327
19385
  ({
19328
19386
  provided_count,
@@ -19349,8 +19407,8 @@ declare class JsonServiceStatistics {
19349
19407
  extrinsicCount: extrinsic_count,
19350
19408
  accumulateCount: accumulate_count,
19351
19409
  accumulateGasUsed: accumulate_gas_used,
19352
- onTransfersCount: on_transfers_count,
19353
- onTransfersGasUsed: on_transfers_gas_used,
19410
+ onTransfersCount: on_transfers_count ?? tryAsU32(0),
19411
+ onTransfersGasUsed: on_transfers_gas_used ?? tryAsServiceGas(0),
19354
19412
  });
19355
19413
  },
19356
19414
  );
@@ -19365,8 +19423,8 @@ declare class JsonServiceStatistics {
19365
19423
  extrinsic_count!: U16;
19366
19424
  accumulate_count!: U32;
19367
19425
  accumulate_gas_used!: ServiceGas;
19368
- on_transfers_count!: U32;
19369
- on_transfers_gas_used!: ServiceGas;
19426
+ on_transfers_count?: U32;
19427
+ on_transfers_gas_used?: ServiceGas;
19370
19428
  }
19371
19429
 
19372
19430
  type ServiceStatisticsEntry = {
@@ -19438,8 +19496,9 @@ type JsonStateDump = {
19438
19496
  tau: State["timeslot"];
19439
19497
  chi: {
19440
19498
  chi_m: PrivilegedServices["manager"];
19441
- chi_a: PrivilegedServices["authManager"];
19442
- chi_v: PrivilegedServices["validatorsManager"];
19499
+ chi_a: PrivilegedServices["assigners"];
19500
+ chi_v: PrivilegedServices["delegator"];
19501
+ chi_r?: PrivilegedServices["registrar"];
19443
19502
  chi_g: PrivilegedServices["autoAccumulateServices"] | null;
19444
19503
  };
19445
19504
  pi: JsonStatisticsData;
@@ -19472,6 +19531,7 @@ declare const fullStateDumpFromJson = (spec: ChainSpec) =>
19472
19531
  chi_m: "number",
19473
19532
  chi_a: json.array("number"),
19474
19533
  chi_v: "number",
19534
+ chi_r: json.optional("number"),
19475
19535
  chi_g: json.nullable(
19476
19536
  json.array({
19477
19537
  service: "number",
@@ -19504,6 +19564,9 @@ declare const fullStateDumpFromJson = (spec: ChainSpec) =>
19504
19564
  theta,
19505
19565
  accounts,
19506
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
+ }
19507
19570
  return InMemoryState.create({
19508
19571
  authPools: tryAsPerCore(
19509
19572
  alpha.map((perCore) => {
@@ -19537,8 +19600,9 @@ declare const fullStateDumpFromJson = (spec: ChainSpec) =>
19537
19600
  timeslot: tau,
19538
19601
  privilegedServices: PrivilegedServices.create({
19539
19602
  manager: chi.chi_m,
19540
- authManager: chi.chi_a,
19541
- validatorsManager: chi.chi_v,
19603
+ assigners: chi.chi_a,
19604
+ delegator: chi.chi_v,
19605
+ registrar: chi.chi_r ?? tryAsServiceId(2 ** 32 - 1),
19542
19606
  autoAccumulateServices: chi.chi_g ?? [],
19543
19607
  }),
19544
19608
  statistics: JsonStatisticsData.toStatisticsData(spec, pi),
@@ -19561,6 +19625,7 @@ declare const index$1_JsonDisputesRecords: typeof JsonDisputesRecords;
19561
19625
  type index$1_JsonLookupMeta = JsonLookupMeta;
19562
19626
  type index$1_JsonPreimageItem = JsonPreimageItem;
19563
19627
  declare const index$1_JsonPreimageItem: typeof JsonPreimageItem;
19628
+ type index$1_JsonPreimageStatus = JsonPreimageStatus;
19564
19629
  type index$1_JsonRecentBlockState = JsonRecentBlockState;
19565
19630
  type index$1_JsonRecentBlocks = JsonRecentBlocks;
19566
19631
  type index$1_JsonReportedWorkPackageInfo = JsonReportedWorkPackageInfo;
@@ -19585,6 +19650,7 @@ declare const index$1_disputesRecordsFromJson: typeof disputesRecordsFromJson;
19585
19650
  declare const index$1_fullStateDumpFromJson: typeof fullStateDumpFromJson;
19586
19651
  declare const index$1_lookupMetaFromJson: typeof lookupMetaFromJson;
19587
19652
  declare const index$1_notYetAccumulatedFromJson: typeof notYetAccumulatedFromJson;
19653
+ declare const index$1_preimageStatusFromJson: typeof preimageStatusFromJson;
19588
19654
  declare const index$1_recentBlockStateFromJson: typeof recentBlockStateFromJson;
19589
19655
  declare const index$1_recentBlocksHistoryFromJson: typeof recentBlocksHistoryFromJson;
19590
19656
  declare const index$1_reportedWorkPackageFromJson: typeof reportedWorkPackageFromJson;
@@ -19592,8 +19658,8 @@ declare const index$1_serviceStatisticsEntryFromJson: typeof serviceStatisticsEn
19592
19658
  declare const index$1_ticketFromJson: typeof ticketFromJson;
19593
19659
  declare const index$1_validatorDataFromJson: typeof validatorDataFromJson;
19594
19660
  declare namespace index$1 {
19595
- 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 };
19596
- 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 };
19597
19663
  }
19598
19664
 
19599
19665
  /** Helper function to create most used hashes in the block */