@typeberry/lib 0.1.3-8fd7637 → 0.1.3-b0374a8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +237 -216
- package/index.d.ts +272 -243
- package/index.js +237 -216
- 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)
|
|
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)
|
|
591
|
-
|
|
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/#/
|
|
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
|
-
|
|
9323
|
-
|
|
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(
|
|
9328
|
-
return new PrivilegedServices(manager,
|
|
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
|
-
*
|
|
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/#/
|
|
9552
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
9337
9553
|
*/
|
|
9338
9554
|
readonly manager: ServiceId,
|
|
9339
|
-
/**
|
|
9340
|
-
readonly
|
|
9341
|
-
/**
|
|
9342
|
-
|
|
9343
|
-
|
|
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
|
-
|
|
11176
|
-
|
|
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
|
|
13762
|
+
* Create a new service with given codeHash, length, gas, allowance, gratisStorage and wantedServiceId.
|
|
13763
|
+
*
|
|
13764
|
+
* Returns a newly assigned id
|
|
13765
|
+
* or `wantedServiceId` if it's lower than `S`
|
|
13766
|
+
* and parent of that service is `Registrar`.
|
|
13747
13767
|
*
|
|
13748
|
-
*
|
|
13749
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/2f4c022f4c02?v=0.6.7
|
|
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
|
|
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
|
-
|
|
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
|
-
* `
|
|
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
|
-
|
|
13820
|
+
r: ServiceId | null,
|
|
13821
|
+
z: [ServiceId, ServiceGas][],
|
|
13799
13822
|
): Result$2<OK, UpdatePrivilegesError>;
|
|
13800
13823
|
|
|
13801
13824
|
/** Yield accumulation trie result hash. */
|
|
@@ -17764,7 +17787,7 @@ declare class AccumulationStateUpdate {
|
|
|
17764
17787
|
if (from.privilegedServices !== null) {
|
|
17765
17788
|
update.privilegedServices = PrivilegedServices.create({
|
|
17766
17789
|
...from.privilegedServices,
|
|
17767
|
-
|
|
17790
|
+
assigners: asKnownSize([...from.privilegedServices.assigners]),
|
|
17768
17791
|
});
|
|
17769
17792
|
}
|
|
17770
17793
|
return update;
|
|
@@ -18035,7 +18058,7 @@ declare const HostCallResult = {
|
|
|
18035
18058
|
OOB: tryAsU64(0xffff_ffff_ffff_fffdn), // 2**64 - 3
|
|
18036
18059
|
/** Index unknown. */
|
|
18037
18060
|
WHO: tryAsU64(0xffff_ffff_ffff_fffcn), // 2**64 - 4
|
|
18038
|
-
/** Storage full. */
|
|
18061
|
+
/** Storage full or resource already allocated. */
|
|
18039
18062
|
FULL: tryAsU64(0xffff_ffff_ffff_fffbn), // 2**64 - 5
|
|
18040
18063
|
/** Core index unknown. */
|
|
18041
18064
|
CORE: tryAsU64(0xffff_ffff_ffff_fffan), // 2**64 - 6
|
|
@@ -18043,7 +18066,7 @@ declare const HostCallResult = {
|
|
|
18043
18066
|
CASH: tryAsU64(0xffff_ffff_ffff_fff9n), // 2**64 - 7
|
|
18044
18067
|
/** Gas limit too low. */
|
|
18045
18068
|
LOW: tryAsU64(0xffff_ffff_ffff_fff8n), // 2**64 - 8
|
|
18046
|
-
/** The item is already solicited
|
|
18069
|
+
/** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
|
|
18047
18070
|
HUH: tryAsU64(0xffff_ffff_ffff_fff7n), // 2**64 - 9
|
|
18048
18071
|
/** The return value indicating general success. */
|
|
18049
18072
|
OK: tryAsU64(0n),
|
|
@@ -19432,8 +19455,9 @@ type JsonStateDump = {
|
|
|
19432
19455
|
tau: State["timeslot"];
|
|
19433
19456
|
chi: {
|
|
19434
19457
|
chi_m: PrivilegedServices["manager"];
|
|
19435
|
-
chi_a: PrivilegedServices["
|
|
19436
|
-
chi_v: PrivilegedServices["
|
|
19458
|
+
chi_a: PrivilegedServices["assigners"];
|
|
19459
|
+
chi_v: PrivilegedServices["delegator"];
|
|
19460
|
+
chi_r?: PrivilegedServices["registrar"];
|
|
19437
19461
|
chi_g: PrivilegedServices["autoAccumulateServices"] | null;
|
|
19438
19462
|
};
|
|
19439
19463
|
pi: JsonStatisticsData;
|
|
@@ -19466,6 +19490,7 @@ declare const fullStateDumpFromJson = (spec: ChainSpec) =>
|
|
|
19466
19490
|
chi_m: "number",
|
|
19467
19491
|
chi_a: json.array("number"),
|
|
19468
19492
|
chi_v: "number",
|
|
19493
|
+
chi_r: json.optional("number"),
|
|
19469
19494
|
chi_g: json.nullable(
|
|
19470
19495
|
json.array({
|
|
19471
19496
|
service: "number",
|
|
@@ -19498,6 +19523,9 @@ declare const fullStateDumpFromJson = (spec: ChainSpec) =>
|
|
|
19498
19523
|
theta,
|
|
19499
19524
|
accounts,
|
|
19500
19525
|
}): InMemoryState => {
|
|
19526
|
+
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && chi.chi_r === undefined) {
|
|
19527
|
+
throw new Error("Registrar is required in Privileges GP ^0.7.1");
|
|
19528
|
+
}
|
|
19501
19529
|
return InMemoryState.create({
|
|
19502
19530
|
authPools: tryAsPerCore(
|
|
19503
19531
|
alpha.map((perCore) => {
|
|
@@ -19531,8 +19559,9 @@ declare const fullStateDumpFromJson = (spec: ChainSpec) =>
|
|
|
19531
19559
|
timeslot: tau,
|
|
19532
19560
|
privilegedServices: PrivilegedServices.create({
|
|
19533
19561
|
manager: chi.chi_m,
|
|
19534
|
-
|
|
19535
|
-
|
|
19562
|
+
assigners: chi.chi_a,
|
|
19563
|
+
delegator: chi.chi_v,
|
|
19564
|
+
registrar: chi.chi_r ?? tryAsServiceId(2 ** 32 - 1),
|
|
19536
19565
|
autoAccumulateServices: chi.chi_g ?? [],
|
|
19537
19566
|
}),
|
|
19538
19567
|
statistics: JsonStatisticsData.toStatisticsData(spec, pi),
|