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