@typeberry/lib 0.2.0-b6e3410 → 0.2.0-c3df163

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 +919 -767
  2. package/index.d.ts +1897 -1619
  3. package/index.js +919 -767
  4. package/package.json +1 -1
package/index.js CHANGED
@@ -2088,6 +2088,9 @@ class ObjectView {
2088
2088
  toString() {
2089
2089
  return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
2090
2090
  }
2091
+ [TEST_COMPARE_USING]() {
2092
+ return this.materialize();
2093
+ }
2091
2094
  }
2092
2095
  /**
2093
2096
  * A lazy-evaluated decoder of a sequence.
@@ -2373,7 +2376,15 @@ var codec$1;
2373
2376
  /** Custom encoding / decoding logic. */
2374
2377
  codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
2375
2378
  /** Choose a descriptor depending on the encoding/decoding context. */
2376
- codec.select = ({ name, sizeHint, }, chooser) => Descriptor.withView(name, sizeHint, (e, x) => chooser(e.getContext()).encode(e, x), (d) => chooser(d.getContext()).decode(d), (s) => chooser(s.decoder.getContext()).skip(s), chooser(null).View);
2379
+ codec.select = ({ name, sizeHint, }, chooser) => {
2380
+ const Self = chooser(null);
2381
+ return Descriptor.withView(name, sizeHint, (e, x) => chooser(e.getContext()).encode(e, x), (d) => chooser(d.getContext()).decode(d), (s) => chooser(s.decoder.getContext()).skip(s), hasUniqueView(Self)
2382
+ ? codec.select({
2383
+ name: Self.View.name,
2384
+ sizeHint: Self.View.sizeHint,
2385
+ }, (ctx) => chooser(ctx).View)
2386
+ : Self.View);
2387
+ };
2377
2388
  /**
2378
2389
  * A descriptor for a more complex POJO.
2379
2390
  *
@@ -6672,6 +6683,17 @@ function emptyBlock(slot = tryAsTimeSlot(0)) {
6672
6683
  });
6673
6684
  }
6674
6685
 
6686
+ /**
6687
+ * Take an input data and re-encode that data as view.
6688
+ *
6689
+ * NOTE: this function should NEVER be used in any production code,
6690
+ * it's only a test helper.
6691
+ */
6692
+ function reencodeAsView(codec, object, chainSpec) {
6693
+ const encoded = Encoder.encodeObject(codec, object, chainSpec);
6694
+ return Decoder.decodeObject(codec.View, encoded, chainSpec);
6695
+ }
6696
+
6675
6697
  var index$l = /*#__PURE__*/Object.freeze({
6676
6698
  __proto__: null,
6677
6699
  Block: Block,
@@ -6692,6 +6714,7 @@ var index$l = /*#__PURE__*/Object.freeze({
6692
6714
  guarantees: guarantees,
6693
6715
  headerViewWithHashCodec: headerViewWithHashCodec,
6694
6716
  preimage: preimage,
6717
+ reencodeAsView: reencodeAsView,
6695
6718
  refineContext: refineContext,
6696
6719
  tickets: tickets,
6697
6720
  tryAsCoreIndex: tryAsCoreIndex,
@@ -8042,6 +8065,72 @@ function accumulationOutputComparator(a, b) {
8042
8065
  return Ordering.Equal;
8043
8066
  }
8044
8067
 
8068
+ /** `O`: Maximum number of items in the authorizations pool. */
8069
+ const O = 8;
8070
+ /** `Q`: The number of items in the authorizations queue. */
8071
+ const Q = 80;
8072
+ /** `W_B`: The maximum size of the concatenated variable-size blobs, extrinsics and imported segments of a work-package, in octets */
8073
+ Compatibility.isGreaterOrEqual(GpVersion.V0_7_2) ? 13_791_360 : 13_794_305;
8074
+ /** `W_T`: The size of a transfer memo in octets. */
8075
+ const W_T = 128;
8076
+ /**
8077
+ * `J`: The maximum sum of dependency items in a work-report.
8078
+ *
8079
+ * https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
8080
+ */
8081
+ const MAX_REPORT_DEPENDENCIES = 8;
8082
+
8083
+ /**
8084
+ * Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
8085
+ *
8086
+ * https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
8087
+ */
8088
+ class NotYetAccumulatedReport extends WithDebug {
8089
+ report;
8090
+ dependencies;
8091
+ static Codec = codec$1.Class(NotYetAccumulatedReport, {
8092
+ report: WorkReport.Codec,
8093
+ dependencies: codecKnownSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), {
8094
+ typicalLength: MAX_REPORT_DEPENDENCIES / 2,
8095
+ maxLength: MAX_REPORT_DEPENDENCIES,
8096
+ minLength: 0,
8097
+ }),
8098
+ });
8099
+ static create({ report, dependencies }) {
8100
+ return new NotYetAccumulatedReport(report, dependencies);
8101
+ }
8102
+ constructor(
8103
+ /**
8104
+ * Each of these were made available at most one epoch ago
8105
+ * but have or had unfulfilled dependencies.
8106
+ */
8107
+ report,
8108
+ /**
8109
+ * Alongside the work-report itself, we retain its un-accumulated
8110
+ * dependencies, a set of work-package hashes.
8111
+ *
8112
+ * https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
8113
+ */
8114
+ dependencies) {
8115
+ super();
8116
+ this.report = report;
8117
+ this.dependencies = dependencies;
8118
+ }
8119
+ }
8120
+ const accumulationQueueCodec = codecPerEpochBlock(readonlyArray(codec$1.sequenceVarLen(NotYetAccumulatedReport.Codec)));
8121
+
8122
+ /** Check if given array has correct length before casting to the opaque type. */
8123
+ function tryAsPerCore(array, spec) {
8124
+ check `
8125
+ ${array.length === spec.coresCount}
8126
+ Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
8127
+ `;
8128
+ return asOpaqueType(array);
8129
+ }
8130
+ const codecPerCore = (val) => codecWithContext((context) => {
8131
+ return codecKnownSizeArray(val, { fixedLength: context.coresCount });
8132
+ });
8133
+
8045
8134
  /**
8046
8135
  * Assignment of particular work report to a core.
8047
8136
  *
@@ -8070,18 +8159,18 @@ class AvailabilityAssignment extends WithDebug {
8070
8159
  this.timeout = timeout;
8071
8160
  }
8072
8161
  }
8162
+ const availabilityAssignmentsCodec = codecPerCore(codec$1.optional(AvailabilityAssignment.Codec));
8073
8163
 
8074
- /** Check if given array has correct length before casting to the opaque type. */
8075
- function tryAsPerCore(array, spec) {
8076
- check `
8077
- ${array.length === spec.coresCount}
8078
- Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
8079
- `;
8080
- return asOpaqueType(array);
8081
- }
8082
- const codecPerCore = (val) => codecWithContext((context) => {
8083
- return codecKnownSizeArray(val, { fixedLength: context.coresCount });
8084
- });
8164
+ /** `O`: Maximal authorization pool size. */
8165
+ const MAX_AUTH_POOL_SIZE = O;
8166
+ /** `Q`: Size of the authorization queue. */
8167
+ const AUTHORIZATION_QUEUE_SIZE = Q;
8168
+ const authPoolsCodec = codecPerCore(codecKnownSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), {
8169
+ minLength: 0,
8170
+ maxLength: MAX_AUTH_POOL_SIZE,
8171
+ typicalLength: MAX_AUTH_POOL_SIZE,
8172
+ }));
8173
+ const authQueuesCodec = codecPerCore(codecFixedSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE));
8085
8174
 
8086
8175
  const sortedSetCodec = () => readonlyArray(codec$1.sequenceVarLen(codec$1.bytes(HASH_SIZE))).convert((input) => input.array, (output) => {
8087
8176
  const typed = output.map((x) => x.asOpaque());
@@ -8145,103 +8234,301 @@ function hashComparator(a, b) {
8145
8234
  return a.compare(b);
8146
8235
  }
8147
8236
 
8148
- /** `O`: Maximum number of items in the authorizations pool. */
8149
- const O = 8;
8150
- /** `Q`: The number of items in the authorizations queue. */
8151
- const Q = 80;
8152
- /** `W_T`: The size of a transfer memo in octets. */
8153
- const W_T = 128;
8154
- /**
8155
- * `J`: The maximum sum of dependency items in a work-report.
8156
- *
8157
- * https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
8158
- */
8159
- const MAX_REPORT_DEPENDENCIES = 8;
8160
- /** `Q`: Size of the authorization queue. */
8161
- const AUTHORIZATION_QUEUE_SIZE = Q;
8162
- /** `O`: Maximal authorization pool size. */
8163
- const MAX_AUTH_POOL_SIZE = O;
8164
-
8165
8237
  const MAX_VALUE = 4294967295;
8166
8238
  const MIN_VALUE = -2147483648;
8167
8239
  const MAX_SHIFT_U32 = 32;
8168
8240
  const MAX_SHIFT_U64 = 64n;
8169
8241
 
8170
8242
  /**
8171
- * `B_S`: The basic minimum balance which all services require.
8243
+ * `H = 8`: The size of recent history, in blocks.
8172
8244
  *
8173
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
8245
+ * https://graypaper.fluffylabs.dev/#/579bd12/416300416500
8174
8246
  */
8175
- const BASE_SERVICE_BALANCE = 100n;
8247
+ const MAX_RECENT_HISTORY = 8;
8248
+ /** Recent history of a single block. */
8249
+ class BlockState extends WithDebug {
8250
+ headerHash;
8251
+ accumulationResult;
8252
+ postStateRoot;
8253
+ reported;
8254
+ static Codec = codec$1.Class(BlockState, {
8255
+ headerHash: codec$1.bytes(HASH_SIZE).asOpaque(),
8256
+ accumulationResult: codec$1.bytes(HASH_SIZE),
8257
+ postStateRoot: codec$1.bytes(HASH_SIZE).asOpaque(),
8258
+ reported: codecHashDictionary(WorkPackageInfo.Codec, (x) => x.workPackageHash),
8259
+ });
8260
+ static create({ headerHash, accumulationResult, postStateRoot, reported }) {
8261
+ return new BlockState(headerHash, accumulationResult, postStateRoot, reported);
8262
+ }
8263
+ constructor(
8264
+ /** Header hash. */
8265
+ headerHash,
8266
+ /** Merkle mountain belt of accumulation result. */
8267
+ accumulationResult,
8268
+ /** Posterior state root filled in with a 1-block delay. */
8269
+ postStateRoot,
8270
+ /** Reported work packages (no more than number of cores). */
8271
+ reported) {
8272
+ super();
8273
+ this.headerHash = headerHash;
8274
+ this.accumulationResult = accumulationResult;
8275
+ this.postStateRoot = postStateRoot;
8276
+ this.reported = reported;
8277
+ }
8278
+ }
8176
8279
  /**
8177
- * `B_I`: The additional minimum balance required per item of elective service state.
8280
+ * Recent history of blocks.
8178
8281
  *
8179
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
8282
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
8180
8283
  */
8181
- const ELECTIVE_ITEM_BALANCE = 10n;
8284
+ class RecentBlocks extends WithDebug {
8285
+ blocks;
8286
+ accumulationLog;
8287
+ static Codec = codec$1.Class(RecentBlocks, {
8288
+ blocks: codecKnownSizeArray(BlockState.Codec, {
8289
+ minLength: 0,
8290
+ maxLength: MAX_RECENT_HISTORY,
8291
+ typicalLength: MAX_RECENT_HISTORY,
8292
+ }),
8293
+ accumulationLog: codec$1.object({
8294
+ peaks: readonlyArray(codec$1.sequenceVarLen(codec$1.optional(codec$1.bytes(HASH_SIZE)))),
8295
+ }),
8296
+ });
8297
+ static empty() {
8298
+ return new RecentBlocks(asKnownSize([]), {
8299
+ peaks: [],
8300
+ });
8301
+ }
8302
+ static create(a) {
8303
+ return new RecentBlocks(a.blocks, a.accumulationLog);
8304
+ }
8305
+ constructor(
8306
+ /**
8307
+ * Most recent blocks.
8308
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fea010fea01?v=0.6.7
8309
+ */
8310
+ blocks,
8311
+ /**
8312
+ * Accumulation output log.
8313
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/0f02020f0202?v=0.6.7
8314
+ */
8315
+ accumulationLog) {
8316
+ super();
8317
+ this.blocks = blocks;
8318
+ this.accumulationLog = accumulationLog;
8319
+ }
8320
+ }
8321
+
8322
+ const recentlyAccumulatedCodec = codecPerEpochBlock(codec$1.sequenceVarLen(codec$1.bytes(HASH_SIZE).asOpaque()).convert((x) => Array.from(x), (x) => HashSet.from(x)));
8323
+
8182
8324
  /**
8183
- * `B_L`: The additional minimum balance required per octet of elective service state.
8325
+ * Fixed size of validator metadata.
8184
8326
  *
8185
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
8327
+ * https://graypaper.fluffylabs.dev/#/5f542d7/0d55010d5501
8186
8328
  */
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
- });
8329
+ const VALIDATOR_META_BYTES = 128;
8211
8330
  /**
8212
- * Service account details.
8331
+ * Details about validators' identity.
8213
8332
  *
8214
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
8333
+ * https://graypaper.fluffylabs.dev/#/5f542d7/0d4b010d4c01
8215
8334
  */
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),
8335
+ class ValidatorData extends WithDebug {
8336
+ bandersnatch;
8337
+ ed25519;
8338
+ bls;
8339
+ metadata;
8340
+ static Codec = codec$1.Class(ValidatorData, {
8341
+ bandersnatch: codec$1.bytes(BANDERSNATCH_KEY_BYTES).asOpaque(),
8342
+ ed25519: codec$1.bytes(ED25519_KEY_BYTES).asOpaque(),
8343
+ bls: codec$1.bytes(BLS_KEY_BYTES).asOpaque(),
8344
+ metadata: codec$1.bytes(VALIDATOR_META_BYTES),
8238
8345
  });
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);
8346
+ static create({ ed25519, bandersnatch, bls, metadata }) {
8347
+ return new ValidatorData(bandersnatch, ed25519, bls, metadata);
8241
8348
  }
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
8349
+ constructor(
8350
+ /** Bandersnatch public key. */
8351
+ bandersnatch,
8352
+ /** ED25519 key data. */
8353
+ ed25519,
8354
+ /** BLS public key. */
8355
+ bls,
8356
+ /** Validator-defined additional metdata. */
8357
+ metadata) {
8358
+ super();
8359
+ this.bandersnatch = bandersnatch;
8360
+ this.ed25519 = ed25519;
8361
+ this.bls = bls;
8362
+ this.metadata = metadata;
8363
+ }
8364
+ }
8365
+ const validatorsDataCodec = codecPerValidator(ValidatorData.Codec);
8366
+
8367
+ var SafroleSealingKeysKind;
8368
+ (function (SafroleSealingKeysKind) {
8369
+ SafroleSealingKeysKind[SafroleSealingKeysKind["Tickets"] = 0] = "Tickets";
8370
+ SafroleSealingKeysKind[SafroleSealingKeysKind["Keys"] = 1] = "Keys";
8371
+ })(SafroleSealingKeysKind || (SafroleSealingKeysKind = {}));
8372
+ const codecBandersnatchKey = codec$1.bytes(BANDERSNATCH_KEY_BYTES).asOpaque();
8373
+ class SafroleSealingKeysData extends WithDebug {
8374
+ kind;
8375
+ keys;
8376
+ tickets;
8377
+ static Codec = codecWithContext((context) => {
8378
+ return codec$1.custom({
8379
+ name: "SafroleSealingKeys",
8380
+ sizeHint: { bytes: 1 + HASH_SIZE * context.epochLength, isExact: false },
8381
+ }, (e, x) => {
8382
+ e.varU32(tryAsU32(x.kind));
8383
+ if (x.kind === SafroleSealingKeysKind.Keys) {
8384
+ e.sequenceFixLen(codecBandersnatchKey, x.keys);
8385
+ }
8386
+ else {
8387
+ e.sequenceFixLen(Ticket.Codec, x.tickets);
8388
+ }
8389
+ }, (d) => {
8390
+ const epochLength = context.epochLength;
8391
+ const kind = d.varU32();
8392
+ if (kind === SafroleSealingKeysKind.Keys) {
8393
+ const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
8394
+ return SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
8395
+ }
8396
+ if (kind === SafroleSealingKeysKind.Tickets) {
8397
+ const tickets = d.sequenceFixLen(Ticket.Codec, epochLength);
8398
+ return SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
8399
+ }
8400
+ throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
8401
+ }, (s) => {
8402
+ const kind = s.decoder.varU32();
8403
+ if (kind === SafroleSealingKeysKind.Keys) {
8404
+ s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
8405
+ return;
8406
+ }
8407
+ if (kind === SafroleSealingKeysKind.Tickets) {
8408
+ s.sequenceFixLen(Ticket.Codec, context.epochLength);
8409
+ return;
8410
+ }
8411
+ throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
8412
+ });
8413
+ });
8414
+ static keys(keys) {
8415
+ return new SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
8416
+ }
8417
+ static tickets(tickets) {
8418
+ return new SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
8419
+ }
8420
+ constructor(kind, keys, tickets) {
8421
+ super();
8422
+ this.kind = kind;
8423
+ this.keys = keys;
8424
+ this.tickets = tickets;
8425
+ }
8426
+ }
8427
+ class SafroleData {
8428
+ nextValidatorData;
8429
+ epochRoot;
8430
+ sealingKeySeries;
8431
+ ticketsAccumulator;
8432
+ static Codec = codec$1.Class(SafroleData, {
8433
+ nextValidatorData: codecPerValidator(ValidatorData.Codec),
8434
+ epochRoot: codec$1.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
8435
+ sealingKeySeries: SafroleSealingKeysData.Codec,
8436
+ ticketsAccumulator: readonlyArray(codec$1.sequenceVarLen(Ticket.Codec)).convert(seeThrough, asKnownSize),
8437
+ });
8438
+ static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
8439
+ return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
8440
+ }
8441
+ constructor(
8442
+ /** gamma_k */
8443
+ nextValidatorData,
8444
+ /** gamma_z */
8445
+ epochRoot,
8446
+ /** gamma_s */
8447
+ sealingKeySeries,
8448
+ /** gamma_a */
8449
+ ticketsAccumulator) {
8450
+ this.nextValidatorData = nextValidatorData;
8451
+ this.epochRoot = epochRoot;
8452
+ this.sealingKeySeries = sealingKeySeries;
8453
+ this.ticketsAccumulator = ticketsAccumulator;
8454
+ }
8455
+ }
8456
+
8457
+ /**
8458
+ * `B_S`: The basic minimum balance which all services require.
8459
+ *
8460
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
8461
+ */
8462
+ const BASE_SERVICE_BALANCE = 100n;
8463
+ /**
8464
+ * `B_I`: The additional minimum balance required per item of elective service state.
8465
+ *
8466
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
8467
+ */
8468
+ const ELECTIVE_ITEM_BALANCE = 10n;
8469
+ /**
8470
+ * `B_L`: The additional minimum balance required per octet of elective service state.
8471
+ *
8472
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
8473
+ */
8474
+ const ELECTIVE_BYTE_BALANCE = 1n;
8475
+ const zeroSizeHint = {
8476
+ bytes: 0,
8477
+ isExact: true,
8478
+ };
8479
+ /** 0-byte read, return given default value */
8480
+ const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
8481
+ /** Encode and decode object with leading version number. */
8482
+ const codecWithVersion = (val) => Descriptor.new("withVersion", {
8483
+ bytes: val.sizeHint.bytes + 8,
8484
+ isExact: false,
8485
+ }, (e, v) => {
8486
+ e.varU64(0n);
8487
+ val.encode(e, v);
8488
+ }, (d) => {
8489
+ const version = d.varU64();
8490
+ if (version !== 0n) {
8491
+ throw new Error("Non-zero version is not supported!");
8492
+ }
8493
+ return val.decode(d);
8494
+ }, (s) => {
8495
+ s.varU64();
8496
+ val.skip(s);
8497
+ });
8498
+ /**
8499
+ * Service account details.
8500
+ *
8501
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
8502
+ */
8503
+ class ServiceAccountInfo extends WithDebug {
8504
+ codeHash;
8505
+ balance;
8506
+ accumulateMinGas;
8507
+ onTransferMinGas;
8508
+ storageUtilisationBytes;
8509
+ gratisStorage;
8510
+ storageUtilisationCount;
8511
+ created;
8512
+ lastAccumulation;
8513
+ parentService;
8514
+ static Codec = codec$1.Class(ServiceAccountInfo, {
8515
+ codeHash: codec$1.bytes(HASH_SIZE).asOpaque(),
8516
+ balance: codec$1.u64,
8517
+ accumulateMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
8518
+ onTransferMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
8519
+ storageUtilisationBytes: codec$1.u64,
8520
+ gratisStorage: codec$1.u64,
8521
+ storageUtilisationCount: codec$1.u32,
8522
+ created: codec$1.u32.convert((x) => x, tryAsTimeSlot),
8523
+ lastAccumulation: codec$1.u32.convert((x) => x, tryAsTimeSlot),
8524
+ parentService: codec$1.u32.convert((x) => x, tryAsServiceId),
8525
+ });
8526
+ static create(a) {
8527
+ return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
8528
+ }
8529
+ /**
8530
+ * `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
8531
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
8245
8532
  */
8246
8533
  static calculateThresholdBalance(items, bytes, gratisStorage) {
8247
8534
  const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
@@ -8350,329 +8637,394 @@ class LookupHistoryItem {
8350
8637
  }
8351
8638
  }
8352
8639
 
8353
- /** Dictionary entry of services that auto-accumulate every block. */
8354
- class AutoAccumulate {
8355
- service;
8356
- gasLimit;
8357
- static Codec = codec$1.Class(AutoAccumulate, {
8358
- service: codec$1.u32.asOpaque(),
8359
- gasLimit: codec$1.u64.asOpaque(),
8640
+ const codecServiceId = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
8641
+ ? codec$1.u32.asOpaque()
8642
+ : codec$1.varU32.convert((s) => tryAsU32(s), (i) => tryAsServiceId(i));
8643
+ /**
8644
+ * Activity Record of a single validator.
8645
+ *
8646
+ * https://graypaper.fluffylabs.dev/#/579bd12/183701183701
8647
+ */
8648
+ class ValidatorStatistics {
8649
+ blocks;
8650
+ tickets;
8651
+ preImages;
8652
+ preImagesSize;
8653
+ guarantees;
8654
+ assurances;
8655
+ static Codec = codec$1.Class(ValidatorStatistics, {
8656
+ blocks: codec$1.u32,
8657
+ tickets: codec$1.u32,
8658
+ preImages: codec$1.u32,
8659
+ preImagesSize: codec$1.u32,
8660
+ guarantees: codec$1.u32,
8661
+ assurances: codec$1.u32,
8360
8662
  });
8361
- static create({ service, gasLimit }) {
8362
- return new AutoAccumulate(service, gasLimit);
8663
+ static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
8664
+ return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
8363
8665
  }
8364
8666
  constructor(
8365
- /** Service id that auto-accumulates. */
8366
- service,
8367
- /** Gas limit for auto-accumulation. */
8368
- gasLimit) {
8369
- this.service = service;
8370
- this.gasLimit = gasLimit;
8667
+ /** The number of blocks produced by the validator. */
8668
+ blocks,
8669
+ /** The number of tickets introduced by the validator. */
8670
+ tickets,
8671
+ /** The number of preimages introduced by the validator. */
8672
+ preImages,
8673
+ /** The total number of octets across all preimages introduced by the validator. */
8674
+ preImagesSize,
8675
+ /** The number of reports guaranteed by the validator. */
8676
+ guarantees,
8677
+ /** The number of availability assurances made by the validator. */
8678
+ assurances) {
8679
+ this.blocks = blocks;
8680
+ this.tickets = tickets;
8681
+ this.preImages = preImages;
8682
+ this.preImagesSize = preImagesSize;
8683
+ this.guarantees = guarantees;
8684
+ this.assurances = assurances;
8685
+ }
8686
+ static empty() {
8687
+ const zero = tryAsU32(0);
8688
+ return new ValidatorStatistics(zero, zero, zero, zero, zero, zero);
8371
8689
  }
8372
8690
  }
8691
+ const codecVarU16 = codec$1.varU32.convert((i) => tryAsU32(i), (o) => tryAsU16(o));
8692
+ /** Encode/decode unsigned gas. */
8693
+ const codecVarGas = codec$1.varU64.convert((g) => tryAsU64(g), (i) => tryAsServiceGas(i));
8373
8694
  /**
8374
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
8695
+ * Single core statistics.
8696
+ * Updated per block, based on incoming work reports (`w`).
8697
+ *
8698
+ * https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
8699
+ * https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
8375
8700
  */
8376
- class PrivilegedServices {
8377
- manager;
8378
- delegator;
8379
- registrar;
8380
- assigners;
8381
- autoAccumulateServices;
8382
- /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
8383
- static Codec = codec$1.Class(PrivilegedServices, {
8384
- manager: codec$1.u32.asOpaque(),
8385
- assigners: codecPerCore(codec$1.u32.asOpaque()),
8386
- delegator: codec$1.u32.asOpaque(),
8387
- registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
8388
- ? codec$1.u32.asOpaque()
8389
- : ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
8390
- autoAccumulateServices: readonlyArray(codec$1.sequenceVarLen(AutoAccumulate.Codec)),
8391
- });
8392
- static create(a) {
8393
- return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
8701
+ class CoreStatistics {
8702
+ dataAvailabilityLoad;
8703
+ popularity;
8704
+ imports;
8705
+ exports;
8706
+ extrinsicSize;
8707
+ extrinsicCount;
8708
+ bundleSize;
8709
+ gasUsed;
8710
+ static Codec = Compatibility.isGreaterOrEqual(GpVersion.V0_7_0)
8711
+ ? codec$1.Class(CoreStatistics, {
8712
+ dataAvailabilityLoad: codec$1.varU32,
8713
+ popularity: codecVarU16,
8714
+ imports: codecVarU16,
8715
+ extrinsicCount: codecVarU16,
8716
+ extrinsicSize: codec$1.varU32,
8717
+ exports: codecVarU16,
8718
+ bundleSize: codec$1.varU32,
8719
+ gasUsed: codecVarGas,
8720
+ })
8721
+ : codec$1.Class(CoreStatistics, {
8722
+ dataAvailabilityLoad: codec$1.varU32,
8723
+ popularity: codecVarU16,
8724
+ imports: codecVarU16,
8725
+ exports: codecVarU16,
8726
+ extrinsicSize: codec$1.varU32,
8727
+ extrinsicCount: codecVarU16,
8728
+ bundleSize: codec$1.varU32,
8729
+ gasUsed: codecVarGas,
8730
+ });
8731
+ static create(v) {
8732
+ return new CoreStatistics(v.dataAvailabilityLoad, v.popularity, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.bundleSize, v.gasUsed);
8394
8733
  }
8395
8734
  constructor(
8396
- /**
8397
- * `χ_M`: Manages alteration of χ from block to block,
8398
- * as well as bestow services with storage deposit credits.
8399
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
8400
- */
8401
- manager,
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. */
8413
- autoAccumulateServices) {
8414
- this.manager = manager;
8415
- this.delegator = delegator;
8416
- this.registrar = registrar;
8417
- this.assigners = assigners;
8418
- this.autoAccumulateServices = autoAccumulateServices;
8735
+ /** `d` */
8736
+ dataAvailabilityLoad,
8737
+ /** `p` */
8738
+ popularity,
8739
+ /** `i` */
8740
+ imports,
8741
+ /** `e` */
8742
+ exports,
8743
+ /** `z` */
8744
+ extrinsicSize,
8745
+ /** `x` */
8746
+ extrinsicCount,
8747
+ /** `b` */
8748
+ bundleSize,
8749
+ /** `u` */
8750
+ gasUsed) {
8751
+ this.dataAvailabilityLoad = dataAvailabilityLoad;
8752
+ this.popularity = popularity;
8753
+ this.imports = imports;
8754
+ this.exports = exports;
8755
+ this.extrinsicSize = extrinsicSize;
8756
+ this.extrinsicCount = extrinsicCount;
8757
+ this.bundleSize = bundleSize;
8758
+ this.gasUsed = gasUsed;
8759
+ }
8760
+ static empty() {
8761
+ const zero = tryAsU32(0);
8762
+ const zero16 = tryAsU16(0);
8763
+ const zeroGas = tryAsServiceGas(0);
8764
+ return new CoreStatistics(zero, zero16, zero16, zero16, zero, zero16, zero, zeroGas);
8419
8765
  }
8420
8766
  }
8421
-
8422
8767
  /**
8423
- * `H = 8`: The size of recent history, in blocks.
8768
+ * Service statistics.
8769
+ * Updated per block, based on available work reports (`W`).
8424
8770
  *
8425
- * https://graypaper.fluffylabs.dev/#/579bd12/416300416500
8771
+ * https://graypaper.fluffylabs.dev/#/1c979cb/199802199802?v=0.7.1
8426
8772
  */
8427
- const MAX_RECENT_HISTORY = 8;
8428
- /** Recent history of a single block. */
8429
- class BlockState extends WithDebug {
8430
- headerHash;
8431
- accumulationResult;
8432
- postStateRoot;
8433
- reported;
8434
- static Codec = codec$1.Class(BlockState, {
8435
- headerHash: codec$1.bytes(HASH_SIZE).asOpaque(),
8436
- accumulationResult: codec$1.bytes(HASH_SIZE),
8437
- postStateRoot: codec$1.bytes(HASH_SIZE).asOpaque(),
8438
- reported: codecHashDictionary(WorkPackageInfo.Codec, (x) => x.workPackageHash),
8773
+ class ServiceStatistics {
8774
+ providedCount;
8775
+ providedSize;
8776
+ refinementCount;
8777
+ refinementGasUsed;
8778
+ imports;
8779
+ exports;
8780
+ extrinsicSize;
8781
+ extrinsicCount;
8782
+ accumulateCount;
8783
+ accumulateGasUsed;
8784
+ onTransfersCount;
8785
+ onTransfersGasUsed;
8786
+ static Codec = Compatibility.selectIfGreaterOrEqual({
8787
+ fallback: codec$1.Class(ServiceStatistics, {
8788
+ providedCount: codecVarU16,
8789
+ providedSize: codec$1.varU32,
8790
+ refinementCount: codec$1.varU32,
8791
+ refinementGasUsed: codecVarGas,
8792
+ imports: codecVarU16,
8793
+ exports: codecVarU16,
8794
+ extrinsicSize: codec$1.varU32,
8795
+ extrinsicCount: codecVarU16,
8796
+ accumulateCount: codec$1.varU32,
8797
+ accumulateGasUsed: codecVarGas,
8798
+ onTransfersCount: codec$1.varU32,
8799
+ onTransfersGasUsed: codecVarGas,
8800
+ }),
8801
+ versions: {
8802
+ [GpVersion.V0_7_0]: codec$1.Class(ServiceStatistics, {
8803
+ providedCount: codecVarU16,
8804
+ providedSize: codec$1.varU32,
8805
+ refinementCount: codec$1.varU32,
8806
+ refinementGasUsed: codecVarGas,
8807
+ imports: codecVarU16,
8808
+ extrinsicCount: codecVarU16,
8809
+ extrinsicSize: codec$1.varU32,
8810
+ exports: codecVarU16,
8811
+ accumulateCount: codec$1.varU32,
8812
+ accumulateGasUsed: codecVarGas,
8813
+ onTransfersCount: codec$1.varU32,
8814
+ onTransfersGasUsed: codecVarGas,
8815
+ }),
8816
+ [GpVersion.V0_7_1]: codec$1.Class(ServiceStatistics, {
8817
+ providedCount: codecVarU16,
8818
+ providedSize: codec$1.varU32,
8819
+ refinementCount: codec$1.varU32,
8820
+ refinementGasUsed: codecVarGas,
8821
+ imports: codecVarU16,
8822
+ extrinsicCount: codecVarU16,
8823
+ extrinsicSize: codec$1.varU32,
8824
+ exports: codecVarU16,
8825
+ accumulateCount: codec$1.varU32,
8826
+ accumulateGasUsed: codecVarGas,
8827
+ onTransfersCount: ignoreValueWithDefault(tryAsU32(0)),
8828
+ onTransfersGasUsed: ignoreValueWithDefault(tryAsServiceGas(0)),
8829
+ }),
8830
+ },
8439
8831
  });
8440
- static create({ headerHash, accumulationResult, postStateRoot, reported }) {
8441
- return new BlockState(headerHash, accumulationResult, postStateRoot, reported);
8832
+ static create(v) {
8833
+ return new ServiceStatistics(v.providedCount, v.providedSize, v.refinementCount, v.refinementGasUsed, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.accumulateCount, v.accumulateGasUsed, v.onTransfersCount, v.onTransfersGasUsed);
8442
8834
  }
8443
8835
  constructor(
8444
- /** Header hash. */
8445
- headerHash,
8446
- /** Merkle mountain belt of accumulation result. */
8447
- accumulationResult,
8448
- /** Posterior state root filled in with a 1-block delay. */
8449
- postStateRoot,
8450
- /** Reported work packages (no more than number of cores). */
8451
- reported) {
8452
- super();
8453
- this.headerHash = headerHash;
8454
- this.accumulationResult = accumulationResult;
8455
- this.postStateRoot = postStateRoot;
8456
- this.reported = reported;
8836
+ /** `p.0` */
8837
+ providedCount,
8838
+ /** `p.1` */
8839
+ providedSize,
8840
+ /** `r.0` */
8841
+ refinementCount,
8842
+ /** `r.1` */
8843
+ refinementGasUsed,
8844
+ /** `i` */
8845
+ imports,
8846
+ /** `e` */
8847
+ exports,
8848
+ /** `z` */
8849
+ extrinsicSize,
8850
+ /** `x` */
8851
+ extrinsicCount,
8852
+ /** `a.0` */
8853
+ accumulateCount,
8854
+ /** `a.1` */
8855
+ accumulateGasUsed,
8856
+ /** `t.0` @deprecated since 0.7.1 */
8857
+ onTransfersCount,
8858
+ /** `t.1` @deprecated since 0.7.1 */
8859
+ onTransfersGasUsed) {
8860
+ this.providedCount = providedCount;
8861
+ this.providedSize = providedSize;
8862
+ this.refinementCount = refinementCount;
8863
+ this.refinementGasUsed = refinementGasUsed;
8864
+ this.imports = imports;
8865
+ this.exports = exports;
8866
+ this.extrinsicSize = extrinsicSize;
8867
+ this.extrinsicCount = extrinsicCount;
8868
+ this.accumulateCount = accumulateCount;
8869
+ this.accumulateGasUsed = accumulateGasUsed;
8870
+ this.onTransfersCount = onTransfersCount;
8871
+ this.onTransfersGasUsed = onTransfersGasUsed;
8872
+ }
8873
+ static empty() {
8874
+ const zero = tryAsU32(0);
8875
+ const zero16 = tryAsU16(0);
8876
+ const zeroGas = tryAsServiceGas(0);
8877
+ return new ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
8457
8878
  }
8458
8879
  }
8459
- class RecentBlocks extends WithDebug {
8460
- blocks;
8461
- accumulationLog;
8462
- static Codec = codec$1.Class(RecentBlocks, {
8463
- blocks: codecKnownSizeArray(BlockState.Codec, {
8464
- minLength: 0,
8465
- maxLength: MAX_RECENT_HISTORY,
8466
- typicalLength: MAX_RECENT_HISTORY,
8467
- }),
8468
- accumulationLog: codec$1.object({
8469
- peaks: readonlyArray(codec$1.sequenceVarLen(codec$1.optional(codec$1.bytes(HASH_SIZE)))),
8880
+ /** `pi`: Statistics of each validator, cores statistics and services statistics. */
8881
+ class StatisticsData {
8882
+ current;
8883
+ previous;
8884
+ cores;
8885
+ services;
8886
+ static Codec = codec$1.Class(StatisticsData, {
8887
+ current: codecPerValidator(ValidatorStatistics.Codec),
8888
+ previous: codecPerValidator(ValidatorStatistics.Codec),
8889
+ cores: codecPerCore(CoreStatistics.Codec),
8890
+ services: codec$1.dictionary(codecServiceId, ServiceStatistics.Codec, {
8891
+ sortKeys: (a, b) => a - b,
8470
8892
  }),
8471
8893
  });
8472
- static create(a) {
8473
- return new RecentBlocks(a.blocks, a.accumulationLog);
8894
+ static create(v) {
8895
+ return new StatisticsData(v.current, v.previous, v.cores, v.services);
8474
8896
  }
8475
- constructor(
8476
- /**
8477
- * Most recent blocks.
8478
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fea010fea01?v=0.6.7
8479
- */
8480
- blocks,
8481
- /**
8482
- * Accumulation output log.
8483
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/0f02020f0202?v=0.6.7
8484
- */
8485
- accumulationLog) {
8486
- super();
8487
- this.blocks = blocks;
8488
- this.accumulationLog = accumulationLog;
8897
+ constructor(current, previous, cores, services) {
8898
+ this.current = current;
8899
+ this.previous = previous;
8900
+ this.cores = cores;
8901
+ this.services = services;
8489
8902
  }
8490
8903
  }
8491
- /**
8492
- * Recent history of blocks.
8493
- *
8494
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
8495
- */
8496
- class RecentBlocksHistory extends WithDebug {
8497
- current;
8498
- static Codec = Descriptor.new("RecentBlocksHistory", RecentBlocks.Codec.sizeHint, (encoder, value) => RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
8499
- const recentBlocks = RecentBlocks.Codec.decode(decoder);
8500
- return RecentBlocksHistory.create(recentBlocks);
8501
- }, (skip) => {
8502
- return RecentBlocks.Codec.skip(skip);
8503
- });
8504
- static create(recentBlocks) {
8505
- return new RecentBlocksHistory(recentBlocks);
8904
+
8905
+ class InMemoryStateView {
8906
+ chainSpec;
8907
+ state;
8908
+ constructor(chainSpec, state) {
8909
+ this.chainSpec = chainSpec;
8910
+ this.state = state;
8506
8911
  }
8507
- static empty() {
8508
- return RecentBlocksHistory.create(RecentBlocks.create({
8509
- blocks: asKnownSize([]),
8510
- accumulationLog: { peaks: [] },
8511
- }));
8912
+ availabilityAssignmentView() {
8913
+ return reencodeAsView(availabilityAssignmentsCodec, this.state.availabilityAssignment, this.chainSpec);
8512
8914
  }
8513
- /**
8514
- * Returns the block's BEEFY super peak.
8515
- */
8516
- static accumulationResult(block) {
8517
- return block.accumulationResult;
8915
+ designatedValidatorDataView() {
8916
+ return reencodeAsView(validatorsDataCodec, this.state.designatedValidatorData, this.chainSpec);
8518
8917
  }
8519
- constructor(current) {
8520
- super();
8521
- this.current = current;
8918
+ currentValidatorDataView() {
8919
+ return reencodeAsView(validatorsDataCodec, this.state.currentValidatorData, this.chainSpec);
8522
8920
  }
8523
- /** History of recent blocks with maximum size of `MAX_RECENT_HISTORY` */
8524
- get blocks() {
8525
- if (this.current !== null) {
8526
- return this.current.blocks;
8527
- }
8528
- throw new Error("RecentBlocksHistory is in invalid state");
8921
+ previousValidatorDataView() {
8922
+ return reencodeAsView(validatorsDataCodec, this.state.previousValidatorData, this.chainSpec);
8529
8923
  }
8530
- asCurrent() {
8531
- if (this.current === null) {
8532
- throw new Error("Cannot access current RecentBlocks format");
8533
- }
8534
- return this.current;
8924
+ authPoolsView() {
8925
+ return reencodeAsView(authPoolsCodec, this.state.authPools, this.chainSpec);
8535
8926
  }
8536
- updateBlocks(blocks) {
8537
- if (this.current !== null) {
8538
- return RecentBlocksHistory.create(RecentBlocks.create({
8539
- ...this.current,
8540
- blocks: asOpaqueType(blocks),
8541
- }));
8542
- }
8543
- throw new Error("RecentBlocksHistory is in invalid state. Cannot be updated!");
8927
+ authQueuesView() {
8928
+ return reencodeAsView(authQueuesCodec, this.state.authQueues, this.chainSpec);
8544
8929
  }
8545
- }
8546
-
8547
- /**
8548
- * Fixed size of validator metadata.
8549
- *
8550
- * https://graypaper.fluffylabs.dev/#/5f542d7/0d55010d5501
8551
- */
8552
- const VALIDATOR_META_BYTES = 128;
8553
- /**
8554
- * Details about validators' identity.
8555
- *
8556
- * https://graypaper.fluffylabs.dev/#/5f542d7/0d4b010d4c01
8557
- */
8558
- class ValidatorData extends WithDebug {
8559
- bandersnatch;
8560
- ed25519;
8561
- bls;
8562
- metadata;
8563
- static Codec = codec$1.Class(ValidatorData, {
8564
- bandersnatch: codec$1.bytes(BANDERSNATCH_KEY_BYTES).asOpaque(),
8565
- ed25519: codec$1.bytes(ED25519_KEY_BYTES).asOpaque(),
8566
- bls: codec$1.bytes(BLS_KEY_BYTES).asOpaque(),
8567
- metadata: codec$1.bytes(VALIDATOR_META_BYTES),
8568
- });
8569
- static create({ ed25519, bandersnatch, bls, metadata }) {
8570
- return new ValidatorData(bandersnatch, ed25519, bls, metadata);
8930
+ recentBlocksView() {
8931
+ return reencodeAsView(RecentBlocks.Codec, this.state.recentBlocks, this.chainSpec);
8571
8932
  }
8572
- constructor(
8573
- /** Bandersnatch public key. */
8574
- bandersnatch,
8575
- /** ED25519 key data. */
8576
- ed25519,
8577
- /** BLS public key. */
8578
- bls,
8579
- /** Validator-defined additional metdata. */
8580
- metadata) {
8581
- super();
8582
- this.bandersnatch = bandersnatch;
8583
- this.ed25519 = ed25519;
8584
- this.bls = bls;
8585
- this.metadata = metadata;
8933
+ statisticsView() {
8934
+ return reencodeAsView(StatisticsData.Codec, this.state.statistics, this.chainSpec);
8935
+ }
8936
+ accumulationQueueView() {
8937
+ return reencodeAsView(accumulationQueueCodec, this.state.accumulationQueue, this.chainSpec);
8938
+ }
8939
+ recentlyAccumulatedView() {
8940
+ return reencodeAsView(recentlyAccumulatedCodec, this.state.recentlyAccumulated, this.chainSpec);
8941
+ }
8942
+ safroleDataView() {
8943
+ // TODO [ToDr] Consider exposting `safrole` from state
8944
+ // instead of individual fields
8945
+ const safrole = SafroleData.create({
8946
+ nextValidatorData: this.state.nextValidatorData,
8947
+ epochRoot: this.state.epochRoot,
8948
+ sealingKeySeries: this.state.sealingKeySeries,
8949
+ ticketsAccumulator: this.state.ticketsAccumulator,
8950
+ });
8951
+ return reencodeAsView(SafroleData.Codec, safrole, this.chainSpec);
8952
+ }
8953
+ getServiceInfoView(id) {
8954
+ const service = this.state.getService(id);
8955
+ if (service === null) {
8956
+ return null;
8957
+ }
8958
+ return reencodeAsView(ServiceAccountInfo.Codec, service.getInfo(), this.chainSpec);
8586
8959
  }
8587
8960
  }
8588
8961
 
8589
- var SafroleSealingKeysKind;
8590
- (function (SafroleSealingKeysKind) {
8591
- SafroleSealingKeysKind[SafroleSealingKeysKind["Tickets"] = 0] = "Tickets";
8592
- SafroleSealingKeysKind[SafroleSealingKeysKind["Keys"] = 1] = "Keys";
8593
- })(SafroleSealingKeysKind || (SafroleSealingKeysKind = {}));
8594
- const codecBandersnatchKey = codec$1.bytes(BANDERSNATCH_KEY_BYTES).asOpaque();
8595
- class SafroleSealingKeysData extends WithDebug {
8596
- kind;
8597
- keys;
8598
- tickets;
8599
- static Codec = codecWithContext((context) => {
8600
- return codec$1.custom({
8601
- name: "SafroleSealingKeys",
8602
- sizeHint: { bytes: 1 + HASH_SIZE * context.epochLength, isExact: false },
8603
- }, (e, x) => {
8604
- e.varU32(tryAsU32(x.kind));
8605
- if (x.kind === SafroleSealingKeysKind.Keys) {
8606
- e.sequenceFixLen(codecBandersnatchKey, x.keys);
8607
- }
8608
- else {
8609
- e.sequenceFixLen(Ticket.Codec, x.tickets);
8610
- }
8611
- }, (d) => {
8612
- const epochLength = context.epochLength;
8613
- const kind = d.varU32();
8614
- if (kind === SafroleSealingKeysKind.Keys) {
8615
- const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
8616
- return SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
8617
- }
8618
- if (kind === SafroleSealingKeysKind.Tickets) {
8619
- const tickets = d.sequenceFixLen(Ticket.Codec, epochLength);
8620
- return SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
8621
- }
8622
- throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
8623
- }, (s) => {
8624
- const kind = s.decoder.varU32();
8625
- if (kind === SafroleSealingKeysKind.Keys) {
8626
- s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
8627
- return;
8628
- }
8629
- if (kind === SafroleSealingKeysKind.Tickets) {
8630
- s.sequenceFixLen(Ticket.Codec, context.epochLength);
8631
- return;
8632
- }
8633
- throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
8634
- });
8962
+ /** Dictionary entry of services that auto-accumulate every block. */
8963
+ class AutoAccumulate {
8964
+ service;
8965
+ gasLimit;
8966
+ static Codec = codec$1.Class(AutoAccumulate, {
8967
+ service: codec$1.u32.asOpaque(),
8968
+ gasLimit: codec$1.u64.asOpaque(),
8635
8969
  });
8636
- static keys(keys) {
8637
- return new SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
8638
- }
8639
- static tickets(tickets) {
8640
- return new SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
8970
+ static create({ service, gasLimit }) {
8971
+ return new AutoAccumulate(service, gasLimit);
8641
8972
  }
8642
- constructor(kind, keys, tickets) {
8643
- super();
8644
- this.kind = kind;
8645
- this.keys = keys;
8646
- this.tickets = tickets;
8973
+ constructor(
8974
+ /** Service id that auto-accumulates. */
8975
+ service,
8976
+ /** Gas limit for auto-accumulation. */
8977
+ gasLimit) {
8978
+ this.service = service;
8979
+ this.gasLimit = gasLimit;
8647
8980
  }
8648
8981
  }
8649
- class SafroleData {
8650
- nextValidatorData;
8651
- epochRoot;
8652
- sealingKeySeries;
8653
- ticketsAccumulator;
8654
- static Codec = codec$1.Class(SafroleData, {
8655
- nextValidatorData: codecPerValidator(ValidatorData.Codec),
8656
- epochRoot: codec$1.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
8657
- sealingKeySeries: SafroleSealingKeysData.Codec,
8658
- ticketsAccumulator: readonlyArray(codec$1.sequenceVarLen(Ticket.Codec)).convert(seeThrough, asKnownSize),
8982
+ /**
8983
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
8984
+ */
8985
+ class PrivilegedServices {
8986
+ manager;
8987
+ delegator;
8988
+ registrar;
8989
+ assigners;
8990
+ autoAccumulateServices;
8991
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
8992
+ static Codec = codec$1.Class(PrivilegedServices, {
8993
+ manager: codec$1.u32.asOpaque(),
8994
+ assigners: codecPerCore(codec$1.u32.asOpaque()),
8995
+ delegator: codec$1.u32.asOpaque(),
8996
+ registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
8997
+ ? codec$1.u32.asOpaque()
8998
+ : ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
8999
+ autoAccumulateServices: readonlyArray(codec$1.sequenceVarLen(AutoAccumulate.Codec)),
8659
9000
  });
8660
- static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
8661
- return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
9001
+ static create(a) {
9002
+ return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
8662
9003
  }
8663
9004
  constructor(
8664
- /** gamma_k */
8665
- nextValidatorData,
8666
- /** gamma_z */
8667
- epochRoot,
8668
- /** gamma_s */
8669
- sealingKeySeries,
8670
- /** gamma_a */
8671
- ticketsAccumulator) {
8672
- this.nextValidatorData = nextValidatorData;
8673
- this.epochRoot = epochRoot;
8674
- this.sealingKeySeries = sealingKeySeries;
8675
- this.ticketsAccumulator = ticketsAccumulator;
9005
+ /**
9006
+ * `χ_M`: Manages alteration of χ from block to block,
9007
+ * as well as bestow services with storage deposit credits.
9008
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
9009
+ */
9010
+ manager,
9011
+ /** `χ_V`: Managers validator keys. */
9012
+ delegator,
9013
+ /**
9014
+ * `χ_R`: Manages the creation of services in protected range.
9015
+ *
9016
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
9017
+ */
9018
+ registrar,
9019
+ /** `χ_A`: Manages authorization queue one for each core. */
9020
+ assigners,
9021
+ /** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
9022
+ autoAccumulateServices) {
9023
+ this.manager = manager;
9024
+ this.delegator = delegator;
9025
+ this.registrar = registrar;
9026
+ this.assigners = assigners;
9027
+ this.autoAccumulateServices = autoAccumulateServices;
8676
9028
  }
8677
9029
  }
8678
9030
 
@@ -8782,319 +9134,54 @@ class UpdateService {
8782
9134
  static update({ serviceId, serviceInfo }) {
8783
9135
  return new UpdateService(serviceId, {
8784
9136
  kind: UpdateServiceKind.Update,
8785
- account: serviceInfo,
8786
- });
8787
- }
8788
- static create({ serviceId, serviceInfo, lookupHistory, }) {
8789
- return new UpdateService(serviceId, {
8790
- kind: UpdateServiceKind.Create,
8791
- account: serviceInfo,
8792
- lookupHistory,
8793
- });
8794
- }
8795
- }
8796
- /** Update service storage kind. */
8797
- var UpdateStorageKind;
8798
- (function (UpdateStorageKind) {
8799
- /** Set a storage value. */
8800
- UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
8801
- /** Remove a storage value. */
8802
- UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
8803
- })(UpdateStorageKind || (UpdateStorageKind = {}));
8804
- /**
8805
- * Update service storage item.
8806
- *
8807
- * Can either create/modify an entry or remove it.
8808
- */
8809
- class UpdateStorage {
8810
- serviceId;
8811
- action;
8812
- constructor(serviceId, action) {
8813
- this.serviceId = serviceId;
8814
- this.action = action;
8815
- }
8816
- static set({ serviceId, storage }) {
8817
- return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Set, storage });
8818
- }
8819
- static remove({ serviceId, key }) {
8820
- return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Remove, key });
8821
- }
8822
- get key() {
8823
- if (this.action.kind === UpdateStorageKind.Remove) {
8824
- return this.action.key;
8825
- }
8826
- return this.action.storage.key;
8827
- }
8828
- get value() {
8829
- if (this.action.kind === UpdateStorageKind.Remove) {
8830
- return null;
8831
- }
8832
- return this.action.storage.value;
8833
- }
8834
- }
8835
-
8836
- const codecServiceId = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
8837
- ? codec$1.u32.asOpaque()
8838
- : codec$1.varU32.convert((s) => tryAsU32(s), (i) => tryAsServiceId(i));
8839
- /**
8840
- * Activity Record of a single validator.
8841
- *
8842
- * https://graypaper.fluffylabs.dev/#/579bd12/183701183701
8843
- */
8844
- class ValidatorStatistics {
8845
- blocks;
8846
- tickets;
8847
- preImages;
8848
- preImagesSize;
8849
- guarantees;
8850
- assurances;
8851
- static Codec = codec$1.Class(ValidatorStatistics, {
8852
- blocks: codec$1.u32,
8853
- tickets: codec$1.u32,
8854
- preImages: codec$1.u32,
8855
- preImagesSize: codec$1.u32,
8856
- guarantees: codec$1.u32,
8857
- assurances: codec$1.u32,
8858
- });
8859
- static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
8860
- return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
8861
- }
8862
- constructor(
8863
- /** The number of blocks produced by the validator. */
8864
- blocks,
8865
- /** The number of tickets introduced by the validator. */
8866
- tickets,
8867
- /** The number of preimages introduced by the validator. */
8868
- preImages,
8869
- /** The total number of octets across all preimages introduced by the validator. */
8870
- preImagesSize,
8871
- /** The number of reports guaranteed by the validator. */
8872
- guarantees,
8873
- /** The number of availability assurances made by the validator. */
8874
- assurances) {
8875
- this.blocks = blocks;
8876
- this.tickets = tickets;
8877
- this.preImages = preImages;
8878
- this.preImagesSize = preImagesSize;
8879
- this.guarantees = guarantees;
8880
- this.assurances = assurances;
8881
- }
8882
- static empty() {
8883
- const zero = tryAsU32(0);
8884
- return new ValidatorStatistics(zero, zero, zero, zero, zero, zero);
8885
- }
8886
- }
8887
- const codecVarU16 = codec$1.varU32.convert((i) => tryAsU32(i), (o) => tryAsU16(o));
8888
- /** Encode/decode unsigned gas. */
8889
- const codecVarGas = codec$1.varU64.convert((g) => tryAsU64(g), (i) => tryAsServiceGas(i));
8890
- /**
8891
- * Single core statistics.
8892
- * Updated per block, based on incoming work reports (`w`).
8893
- *
8894
- * https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
8895
- * https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
8896
- */
8897
- class CoreStatistics {
8898
- dataAvailabilityLoad;
8899
- popularity;
8900
- imports;
8901
- exports;
8902
- extrinsicSize;
8903
- extrinsicCount;
8904
- bundleSize;
8905
- gasUsed;
8906
- static Codec = Compatibility.isGreaterOrEqual(GpVersion.V0_7_0)
8907
- ? codec$1.Class(CoreStatistics, {
8908
- dataAvailabilityLoad: codec$1.varU32,
8909
- popularity: codecVarU16,
8910
- imports: codecVarU16,
8911
- extrinsicCount: codecVarU16,
8912
- extrinsicSize: codec$1.varU32,
8913
- exports: codecVarU16,
8914
- bundleSize: codec$1.varU32,
8915
- gasUsed: codecVarGas,
8916
- })
8917
- : codec$1.Class(CoreStatistics, {
8918
- dataAvailabilityLoad: codec$1.varU32,
8919
- popularity: codecVarU16,
8920
- imports: codecVarU16,
8921
- exports: codecVarU16,
8922
- extrinsicSize: codec$1.varU32,
8923
- extrinsicCount: codecVarU16,
8924
- bundleSize: codec$1.varU32,
8925
- gasUsed: codecVarGas,
8926
- });
8927
- static create(v) {
8928
- return new CoreStatistics(v.dataAvailabilityLoad, v.popularity, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.bundleSize, v.gasUsed);
8929
- }
8930
- constructor(
8931
- /** `d` */
8932
- dataAvailabilityLoad,
8933
- /** `p` */
8934
- popularity,
8935
- /** `i` */
8936
- imports,
8937
- /** `e` */
8938
- exports,
8939
- /** `z` */
8940
- extrinsicSize,
8941
- /** `x` */
8942
- extrinsicCount,
8943
- /** `b` */
8944
- bundleSize,
8945
- /** `u` */
8946
- gasUsed) {
8947
- this.dataAvailabilityLoad = dataAvailabilityLoad;
8948
- this.popularity = popularity;
8949
- this.imports = imports;
8950
- this.exports = exports;
8951
- this.extrinsicSize = extrinsicSize;
8952
- this.extrinsicCount = extrinsicCount;
8953
- this.bundleSize = bundleSize;
8954
- this.gasUsed = gasUsed;
8955
- }
8956
- static empty() {
8957
- const zero = tryAsU32(0);
8958
- const zero16 = tryAsU16(0);
8959
- const zeroGas = tryAsServiceGas(0);
8960
- return new CoreStatistics(zero, zero16, zero16, zero16, zero, zero16, zero, zeroGas);
9137
+ account: serviceInfo,
9138
+ });
9139
+ }
9140
+ static create({ serviceId, serviceInfo, lookupHistory, }) {
9141
+ return new UpdateService(serviceId, {
9142
+ kind: UpdateServiceKind.Create,
9143
+ account: serviceInfo,
9144
+ lookupHistory,
9145
+ });
8961
9146
  }
8962
9147
  }
9148
+ /** Update service storage kind. */
9149
+ var UpdateStorageKind;
9150
+ (function (UpdateStorageKind) {
9151
+ /** Set a storage value. */
9152
+ UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
9153
+ /** Remove a storage value. */
9154
+ UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
9155
+ })(UpdateStorageKind || (UpdateStorageKind = {}));
8963
9156
  /**
8964
- * Service statistics.
8965
- * Updated per block, based on available work reports (`W`).
9157
+ * Update service storage item.
8966
9158
  *
8967
- * https://graypaper.fluffylabs.dev/#/1c979cb/199802199802?v=0.7.1
9159
+ * Can either create/modify an entry or remove it.
8968
9160
  */
8969
- class ServiceStatistics {
8970
- providedCount;
8971
- providedSize;
8972
- refinementCount;
8973
- refinementGasUsed;
8974
- imports;
8975
- exports;
8976
- extrinsicSize;
8977
- extrinsicCount;
8978
- accumulateCount;
8979
- accumulateGasUsed;
8980
- onTransfersCount;
8981
- onTransfersGasUsed;
8982
- static Codec = Compatibility.selectIfGreaterOrEqual({
8983
- fallback: codec$1.Class(ServiceStatistics, {
8984
- providedCount: codecVarU16,
8985
- providedSize: codec$1.varU32,
8986
- refinementCount: codec$1.varU32,
8987
- refinementGasUsed: codecVarGas,
8988
- imports: codecVarU16,
8989
- exports: codecVarU16,
8990
- extrinsicSize: codec$1.varU32,
8991
- extrinsicCount: codecVarU16,
8992
- accumulateCount: codec$1.varU32,
8993
- accumulateGasUsed: codecVarGas,
8994
- onTransfersCount: codec$1.varU32,
8995
- onTransfersGasUsed: codecVarGas,
8996
- }),
8997
- versions: {
8998
- [GpVersion.V0_7_0]: codec$1.Class(ServiceStatistics, {
8999
- providedCount: codecVarU16,
9000
- providedSize: codec$1.varU32,
9001
- refinementCount: codec$1.varU32,
9002
- refinementGasUsed: codecVarGas,
9003
- imports: codecVarU16,
9004
- extrinsicCount: codecVarU16,
9005
- extrinsicSize: codec$1.varU32,
9006
- exports: codecVarU16,
9007
- accumulateCount: codec$1.varU32,
9008
- accumulateGasUsed: codecVarGas,
9009
- onTransfersCount: codec$1.varU32,
9010
- onTransfersGasUsed: codecVarGas,
9011
- }),
9012
- [GpVersion.V0_7_1]: codec$1.Class(ServiceStatistics, {
9013
- providedCount: codecVarU16,
9014
- providedSize: codec$1.varU32,
9015
- refinementCount: codec$1.varU32,
9016
- refinementGasUsed: codecVarGas,
9017
- imports: codecVarU16,
9018
- extrinsicCount: codecVarU16,
9019
- extrinsicSize: codec$1.varU32,
9020
- exports: codecVarU16,
9021
- accumulateCount: codec$1.varU32,
9022
- accumulateGasUsed: codecVarGas,
9023
- onTransfersCount: ignoreValueWithDefault(tryAsU32(0)),
9024
- onTransfersGasUsed: ignoreValueWithDefault(tryAsServiceGas(0)),
9025
- }),
9026
- },
9027
- });
9028
- static create(v) {
9029
- return new ServiceStatistics(v.providedCount, v.providedSize, v.refinementCount, v.refinementGasUsed, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.accumulateCount, v.accumulateGasUsed, v.onTransfersCount, v.onTransfersGasUsed);
9161
+ class UpdateStorage {
9162
+ serviceId;
9163
+ action;
9164
+ constructor(serviceId, action) {
9165
+ this.serviceId = serviceId;
9166
+ this.action = action;
9030
9167
  }
9031
- constructor(
9032
- /** `p.0` */
9033
- providedCount,
9034
- /** `p.1` */
9035
- providedSize,
9036
- /** `r.0` */
9037
- refinementCount,
9038
- /** `r.1` */
9039
- refinementGasUsed,
9040
- /** `i` */
9041
- imports,
9042
- /** `e` */
9043
- exports,
9044
- /** `z` */
9045
- extrinsicSize,
9046
- /** `x` */
9047
- extrinsicCount,
9048
- /** `a.0` */
9049
- accumulateCount,
9050
- /** `a.1` */
9051
- accumulateGasUsed,
9052
- /** `t.0` @deprecated since 0.7.1 */
9053
- onTransfersCount,
9054
- /** `t.1` @deprecated since 0.7.1 */
9055
- onTransfersGasUsed) {
9056
- this.providedCount = providedCount;
9057
- this.providedSize = providedSize;
9058
- this.refinementCount = refinementCount;
9059
- this.refinementGasUsed = refinementGasUsed;
9060
- this.imports = imports;
9061
- this.exports = exports;
9062
- this.extrinsicSize = extrinsicSize;
9063
- this.extrinsicCount = extrinsicCount;
9064
- this.accumulateCount = accumulateCount;
9065
- this.accumulateGasUsed = accumulateGasUsed;
9066
- this.onTransfersCount = onTransfersCount;
9067
- this.onTransfersGasUsed = onTransfersGasUsed;
9168
+ static set({ serviceId, storage }) {
9169
+ return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Set, storage });
9068
9170
  }
9069
- static empty() {
9070
- const zero = tryAsU32(0);
9071
- const zero16 = tryAsU16(0);
9072
- const zeroGas = tryAsServiceGas(0);
9073
- return new ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
9171
+ static remove({ serviceId, key }) {
9172
+ return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Remove, key });
9074
9173
  }
9075
- }
9076
- /** `pi`: Statistics of each validator, cores statistics and services statistics. */
9077
- class StatisticsData {
9078
- current;
9079
- previous;
9080
- cores;
9081
- services;
9082
- static Codec = codec$1.Class(StatisticsData, {
9083
- current: codecPerValidator(ValidatorStatistics.Codec),
9084
- previous: codecPerValidator(ValidatorStatistics.Codec),
9085
- cores: codecPerCore(CoreStatistics.Codec),
9086
- services: codec$1.dictionary(codecServiceId, ServiceStatistics.Codec, {
9087
- sortKeys: (a, b) => a - b,
9088
- }),
9089
- });
9090
- static create(v) {
9091
- return new StatisticsData(v.current, v.previous, v.cores, v.services);
9174
+ get key() {
9175
+ if (this.action.kind === UpdateStorageKind.Remove) {
9176
+ return this.action.key;
9177
+ }
9178
+ return this.action.storage.key;
9092
9179
  }
9093
- constructor(current, previous, cores, services) {
9094
- this.current = current;
9095
- this.previous = previous;
9096
- this.cores = cores;
9097
- this.services = services;
9180
+ get value() {
9181
+ if (this.action.kind === UpdateStorageKind.Remove) {
9182
+ return null;
9183
+ }
9184
+ return this.action.storage.value;
9098
9185
  }
9099
9186
  }
9100
9187
 
@@ -9197,9 +9284,10 @@ class InMemoryService extends WithDebug {
9197
9284
  * A special version of state, stored fully in-memory.
9198
9285
  */
9199
9286
  class InMemoryState extends WithDebug {
9287
+ chainSpec;
9200
9288
  /** Create a new `InMemoryState` by providing all required fields. */
9201
- static create(state) {
9202
- return new InMemoryState(state);
9289
+ static new(chainSpec, state) {
9290
+ return new InMemoryState(chainSpec, state);
9203
9291
  }
9204
9292
  /**
9205
9293
  * Create a new `InMemoryState` with a partial state override.
@@ -9215,7 +9303,7 @@ class InMemoryState extends WithDebug {
9215
9303
  /**
9216
9304
  * Create a new `InMemoryState` from some other state object.
9217
9305
  */
9218
- static copyFrom(other, servicesData) {
9306
+ static copyFrom(chainSpec, other, servicesData) {
9219
9307
  const services = new Map();
9220
9308
  for (const [id, entries] of servicesData.entries()) {
9221
9309
  const service = other.getService(id);
@@ -9225,7 +9313,7 @@ class InMemoryState extends WithDebug {
9225
9313
  const inMemService = InMemoryService.copyFrom(service, entries);
9226
9314
  services.set(id, inMemService);
9227
9315
  }
9228
- return InMemoryState.create({
9316
+ return InMemoryState.new(chainSpec, {
9229
9317
  availabilityAssignment: other.availabilityAssignment,
9230
9318
  accumulationQueue: other.accumulationQueue,
9231
9319
  designatedValidatorData: other.designatedValidatorData,
@@ -9422,8 +9510,9 @@ class InMemoryState extends WithDebug {
9422
9510
  getService(id) {
9423
9511
  return this.services.get(id) ?? null;
9424
9512
  }
9425
- constructor(s) {
9513
+ constructor(chainSpec, s) {
9426
9514
  super();
9515
+ this.chainSpec = chainSpec;
9427
9516
  this.availabilityAssignment = s.availabilityAssignment;
9428
9517
  this.designatedValidatorData = s.designatedValidatorData;
9429
9518
  this.nextValidatorData = s.nextValidatorData;
@@ -9445,11 +9534,14 @@ class InMemoryState extends WithDebug {
9445
9534
  this.accumulationOutputLog = s.accumulationOutputLog;
9446
9535
  this.services = s.services;
9447
9536
  }
9537
+ view() {
9538
+ return new InMemoryStateView(this.chainSpec, this);
9539
+ }
9448
9540
  /**
9449
9541
  * Create an empty and possibly incoherent `InMemoryState`.
9450
9542
  */
9451
9543
  static empty(spec) {
9452
- return new InMemoryState({
9544
+ return new InMemoryState(spec, {
9453
9545
  availabilityAssignment: tryAsPerCore(Array.from({ length: spec.coresCount }, () => null), spec),
9454
9546
  designatedValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
9455
9547
  bandersnatch: Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
@@ -9485,7 +9577,7 @@ class InMemoryState extends WithDebug {
9485
9577
  entropy: FixedSizeArray.fill(() => Bytes.zero(HASH_SIZE).asOpaque(), ENTROPY_ENTRIES),
9486
9578
  authPools: tryAsPerCore(Array.from({ length: spec.coresCount }, () => asKnownSize([])), spec),
9487
9579
  authQueues: tryAsPerCore(Array.from({ length: spec.coresCount }, () => FixedSizeArray.fill(() => Bytes.zero(HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE)), spec),
9488
- recentBlocks: RecentBlocksHistory.empty(),
9580
+ recentBlocks: RecentBlocks.empty(),
9489
9581
  statistics: StatisticsData.create({
9490
9582
  current: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
9491
9583
  previous: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
@@ -9523,6 +9615,7 @@ const serviceDataCodec = codec$1.dictionary(codec$1.u32.asOpaque(), serviceEntri
9523
9615
 
9524
9616
  var index$g = /*#__PURE__*/Object.freeze({
9525
9617
  __proto__: null,
9618
+ AUTHORIZATION_QUEUE_SIZE: AUTHORIZATION_QUEUE_SIZE,
9526
9619
  AccumulationOutput: AccumulationOutput,
9527
9620
  AutoAccumulate: AutoAccumulate,
9528
9621
  AvailabilityAssignment: AvailabilityAssignment,
@@ -9536,11 +9629,12 @@ var index$g = /*#__PURE__*/Object.freeze({
9536
9629
  InMemoryService: InMemoryService,
9537
9630
  InMemoryState: InMemoryState,
9538
9631
  LookupHistoryItem: LookupHistoryItem,
9632
+ MAX_AUTH_POOL_SIZE: MAX_AUTH_POOL_SIZE,
9539
9633
  MAX_RECENT_HISTORY: MAX_RECENT_HISTORY,
9634
+ NotYetAccumulatedReport: NotYetAccumulatedReport,
9540
9635
  PreimageItem: PreimageItem,
9541
9636
  PrivilegedServices: PrivilegedServices,
9542
9637
  RecentBlocks: RecentBlocks,
9543
- RecentBlocksHistory: RecentBlocksHistory,
9544
9638
  SafroleData: SafroleData,
9545
9639
  SafroleSealingKeysData: SafroleSealingKeysData,
9546
9640
  get SafroleSealingKeysKind () { return SafroleSealingKeysKind; },
@@ -9559,71 +9653,35 @@ var index$g = /*#__PURE__*/Object.freeze({
9559
9653
  ValidatorData: ValidatorData,
9560
9654
  ValidatorStatistics: ValidatorStatistics,
9561
9655
  accumulationOutputComparator: accumulationOutputComparator,
9656
+ accumulationQueueCodec: accumulationQueueCodec,
9657
+ authPoolsCodec: authPoolsCodec,
9658
+ authQueuesCodec: authQueuesCodec,
9659
+ availabilityAssignmentsCodec: availabilityAssignmentsCodec,
9562
9660
  codecPerCore: codecPerCore,
9563
9661
  codecWithVersion: codecWithVersion,
9564
9662
  hashComparator: hashComparator,
9565
9663
  ignoreValueWithDefault: ignoreValueWithDefault,
9664
+ recentlyAccumulatedCodec: recentlyAccumulatedCodec,
9566
9665
  serviceDataCodec: serviceDataCodec,
9567
9666
  serviceEntriesCodec: serviceEntriesCodec,
9568
9667
  tryAsLookupHistorySlots: tryAsLookupHistorySlots,
9569
- tryAsPerCore: tryAsPerCore
9668
+ tryAsPerCore: tryAsPerCore,
9669
+ validatorsDataCodec: validatorsDataCodec
9570
9670
  });
9571
9671
 
9572
- /**
9573
- * Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
9574
- *
9575
- * https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
9576
- */
9577
- class NotYetAccumulatedReport extends WithDebug {
9578
- report;
9579
- dependencies;
9580
- static Codec = codec$1.Class(NotYetAccumulatedReport, {
9581
- report: WorkReport.Codec,
9582
- dependencies: codecKnownSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), {
9583
- typicalLength: MAX_REPORT_DEPENDENCIES / 2,
9584
- maxLength: MAX_REPORT_DEPENDENCIES,
9585
- minLength: 0,
9586
- }),
9587
- });
9588
- static create({ report, dependencies }) {
9589
- return new NotYetAccumulatedReport(report, dependencies);
9590
- }
9591
- constructor(
9592
- /**
9593
- * Each of these were made available at most one epoch ago
9594
- * but have or had unfulfilled dependencies.
9595
- */
9596
- report,
9597
- /**
9598
- * Alongside the work-report itself, we retain its un-accumulated
9599
- * dependencies, a set of work-package hashes.
9600
- *
9601
- * https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
9602
- */
9603
- dependencies) {
9604
- super();
9605
- this.report = report;
9606
- this.dependencies = dependencies;
9607
- }
9608
- }
9609
-
9610
9672
  /** Serialization for particular state entries. */
9611
9673
  var serialize;
9612
9674
  (function (serialize) {
9613
9675
  /** C(1): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b15013b1501?v=0.6.7 */
9614
9676
  serialize.authPools = {
9615
9677
  key: stateKeys.index(StateKeyIdx.Alpha),
9616
- Codec: codecPerCore(codecKnownSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), {
9617
- minLength: 0,
9618
- maxLength: MAX_AUTH_POOL_SIZE,
9619
- typicalLength: MAX_AUTH_POOL_SIZE,
9620
- })),
9678
+ Codec: authPoolsCodec,
9621
9679
  extract: (s) => s.authPools,
9622
9680
  };
9623
9681
  /** C(2): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b31013b3101?v=0.6.7 */
9624
9682
  serialize.authQueues = {
9625
9683
  key: stateKeys.index(StateKeyIdx.Phi),
9626
- Codec: codecPerCore(codecFixedSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE)),
9684
+ Codec: authQueuesCodec,
9627
9685
  extract: (s) => s.authQueues,
9628
9686
  };
9629
9687
  /**
@@ -9632,7 +9690,7 @@ var serialize;
9632
9690
  */
9633
9691
  serialize.recentBlocks = {
9634
9692
  key: stateKeys.index(StateKeyIdx.Beta),
9635
- Codec: RecentBlocksHistory.Codec,
9693
+ Codec: RecentBlocks.Codec,
9636
9694
  extract: (s) => s.recentBlocks,
9637
9695
  };
9638
9696
  /** C(4): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b63013b6301?v=0.6.7 */
@@ -9661,25 +9719,25 @@ var serialize;
9661
9719
  /** C(7): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b00023b0002?v=0.6.7 */
9662
9720
  serialize.designatedValidators = {
9663
9721
  key: stateKeys.index(StateKeyIdx.Iota),
9664
- Codec: codecPerValidator(ValidatorData.Codec),
9722
+ Codec: validatorsDataCodec,
9665
9723
  extract: (s) => s.designatedValidatorData,
9666
9724
  };
9667
9725
  /** C(8): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b0d023b0d02?v=0.6.7 */
9668
9726
  serialize.currentValidators = {
9669
9727
  key: stateKeys.index(StateKeyIdx.Kappa),
9670
- Codec: codecPerValidator(ValidatorData.Codec),
9728
+ Codec: validatorsDataCodec,
9671
9729
  extract: (s) => s.currentValidatorData,
9672
9730
  };
9673
9731
  /** C(9): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b1a023b1a02?v=0.6.7 */
9674
9732
  serialize.previousValidators = {
9675
9733
  key: stateKeys.index(StateKeyIdx.Lambda),
9676
- Codec: codecPerValidator(ValidatorData.Codec),
9734
+ Codec: validatorsDataCodec,
9677
9735
  extract: (s) => s.previousValidatorData,
9678
9736
  };
9679
9737
  /** C(10): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b27023b2702?v=0.6.7 */
9680
9738
  serialize.availabilityAssignment = {
9681
9739
  key: stateKeys.index(StateKeyIdx.Rho),
9682
- Codec: codecPerCore(codec$1.optional(AvailabilityAssignment.Codec)),
9740
+ Codec: availabilityAssignmentsCodec,
9683
9741
  extract: (s) => s.availabilityAssignment,
9684
9742
  };
9685
9743
  /** C(11): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b3e023b3e02?v=0.6.7 */
@@ -9703,13 +9761,13 @@ var serialize;
9703
9761
  /** C(14): https://graypaper.fluffylabs.dev/#/1c979cb/3bf0023bf002?v=0.7.1 */
9704
9762
  serialize.accumulationQueue = {
9705
9763
  key: stateKeys.index(StateKeyIdx.Omega),
9706
- Codec: codecPerEpochBlock(readonlyArray(codec$1.sequenceVarLen(NotYetAccumulatedReport.Codec))),
9764
+ Codec: accumulationQueueCodec,
9707
9765
  extract: (s) => s.accumulationQueue,
9708
9766
  };
9709
9767
  /** C(15): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b96023b9602?v=0.6.7 */
9710
9768
  serialize.recentlyAccumulated = {
9711
9769
  key: stateKeys.index(StateKeyIdx.Xi),
9712
- Codec: codecPerEpochBlock(codec$1.sequenceVarLen(codec$1.bytes(HASH_SIZE).asOpaque()).convert((x) => Array.from(x), (x) => HashSet.from(x))),
9770
+ Codec: recentlyAccumulatedCodec,
9713
9771
  extract: (s) => s.recentlyAccumulated,
9714
9772
  };
9715
9773
  /** C(16): https://graypaper.fluffylabs.dev/#/38c4e62/3b46033b4603?v=0.7.0 */
@@ -9750,6 +9808,84 @@ var serialize;
9750
9808
  */
9751
9809
  const dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }, (e, v) => e.bytes(Bytes.fromBlob(v.raw, v.raw.length)), (d) => BytesBlob.blobFrom(d.bytes(d.source.length - d.bytesRead()).raw), (s) => s.bytes(s.decoder.source.length - s.decoder.bytesRead()));
9752
9810
 
9811
+ class SerializedStateView {
9812
+ spec;
9813
+ backend;
9814
+ recentlyUsedServices;
9815
+ viewCache;
9816
+ constructor(spec, backend,
9817
+ /** Best-effort list of recently active services. */
9818
+ recentlyUsedServices, viewCache) {
9819
+ this.spec = spec;
9820
+ this.backend = backend;
9821
+ this.recentlyUsedServices = recentlyUsedServices;
9822
+ this.viewCache = viewCache;
9823
+ }
9824
+ retrieveView({ key, Codec }, description) {
9825
+ const cached = this.viewCache.get(key);
9826
+ if (cached !== undefined) {
9827
+ return cached;
9828
+ }
9829
+ const bytes = this.backend.get(key);
9830
+ if (bytes === null) {
9831
+ throw new Error(`Required state entry for ${description} is missing!. Accessing view of key: ${key}`);
9832
+ }
9833
+ // NOTE [ToDr] we are not using `Decoder.decodeObject` here because
9834
+ // it needs to get to the end of the data (skip), yet that's expensive.
9835
+ // we assume that the state data is correct and coherent anyway, so
9836
+ // for performance reasons we simply create the view here.
9837
+ const d = Decoder.fromBytesBlob(bytes);
9838
+ d.attachContext(this.spec);
9839
+ const view = Codec.View.decode(d);
9840
+ this.viewCache.set(key, view);
9841
+ return view;
9842
+ }
9843
+ availabilityAssignmentView() {
9844
+ return this.retrieveView(serialize.availabilityAssignment, "availabilityAssignmentView");
9845
+ }
9846
+ designatedValidatorDataView() {
9847
+ return this.retrieveView(serialize.designatedValidators, "designatedValidatorsView");
9848
+ }
9849
+ currentValidatorDataView() {
9850
+ return this.retrieveView(serialize.currentValidators, "currentValidatorsView");
9851
+ }
9852
+ previousValidatorDataView() {
9853
+ return this.retrieveView(serialize.previousValidators, "previousValidatorsView");
9854
+ }
9855
+ authPoolsView() {
9856
+ return this.retrieveView(serialize.authPools, "authPoolsView");
9857
+ }
9858
+ authQueuesView() {
9859
+ return this.retrieveView(serialize.authQueues, "authQueuesView");
9860
+ }
9861
+ recentBlocksView() {
9862
+ return this.retrieveView(serialize.recentBlocks, "recentBlocksView");
9863
+ }
9864
+ statisticsView() {
9865
+ return this.retrieveView(serialize.statistics, "statisticsView");
9866
+ }
9867
+ accumulationQueueView() {
9868
+ return this.retrieveView(serialize.accumulationQueue, "accumulationQueueView");
9869
+ }
9870
+ recentlyAccumulatedView() {
9871
+ return this.retrieveView(serialize.recentlyAccumulated, "recentlyAccumulatedView");
9872
+ }
9873
+ safroleDataView() {
9874
+ return this.retrieveView(serialize.safrole, "safroleDataView");
9875
+ }
9876
+ getServiceInfoView(id) {
9877
+ const serviceData = serialize.serviceData(id);
9878
+ const bytes = this.backend.get(serviceData.key);
9879
+ if (bytes === null) {
9880
+ return null;
9881
+ }
9882
+ if (!this.recentlyUsedServices.includes(id)) {
9883
+ this.recentlyUsedServices.push(id);
9884
+ }
9885
+ return Decoder.decodeObject(serviceData.Codec.View, bytes, this.spec);
9886
+ }
9887
+ }
9888
+
9753
9889
  /**
9754
9890
  * State object which reads it's entries from some backend.
9755
9891
  *
@@ -9762,7 +9898,7 @@ class SerializedState {
9762
9898
  spec;
9763
9899
  blake2b;
9764
9900
  backend;
9765
- _recentServiceIds;
9901
+ recentlyUsedServices;
9766
9902
  /** Create a state-like object from collection of serialized entries. */
9767
9903
  static fromStateEntries(spec, blake2b, state, recentServices = []) {
9768
9904
  return new SerializedState(spec, blake2b, state, recentServices);
@@ -9771,49 +9907,63 @@ class SerializedState {
9771
9907
  static new(spec, blake2b, db, recentServices = []) {
9772
9908
  return new SerializedState(spec, blake2b, db, recentServices);
9773
9909
  }
9910
+ dataCache = HashDictionary.new();
9911
+ viewCache = HashDictionary.new();
9774
9912
  constructor(spec, blake2b, backend,
9775
9913
  /** Best-effort list of recently active services. */
9776
- _recentServiceIds) {
9914
+ recentlyUsedServices) {
9777
9915
  this.spec = spec;
9778
9916
  this.blake2b = blake2b;
9779
9917
  this.backend = backend;
9780
- this._recentServiceIds = _recentServiceIds;
9918
+ this.recentlyUsedServices = recentlyUsedServices;
9781
9919
  }
9782
9920
  /** Comparing the serialized states, just means comparing their backends. */
9783
9921
  [TEST_COMPARE_USING]() {
9784
9922
  return this.backend;
9785
9923
  }
9924
+ /** Return a non-decoding version of the state. */
9925
+ view() {
9926
+ return new SerializedStateView(this.spec, this.backend, this.recentlyUsedServices, this.viewCache);
9927
+ }
9786
9928
  // TODO [ToDr] Temporary method to update the state,
9787
9929
  // without changing references.
9788
9930
  updateBackend(newBackend) {
9789
9931
  this.backend = newBackend;
9932
+ this.dataCache = HashDictionary.new();
9933
+ this.viewCache = HashDictionary.new();
9790
9934
  }
9791
9935
  recentServiceIds() {
9792
- return this._recentServiceIds;
9936
+ return this.recentlyUsedServices;
9793
9937
  }
9794
9938
  getService(id) {
9795
9939
  const serviceData = this.retrieveOptional(serialize.serviceData(id));
9796
9940
  if (serviceData === undefined) {
9797
9941
  return null;
9798
9942
  }
9799
- if (!this._recentServiceIds.includes(id)) {
9800
- this._recentServiceIds.push(id);
9943
+ if (!this.recentlyUsedServices.includes(id)) {
9944
+ this.recentlyUsedServices.push(id);
9801
9945
  }
9802
9946
  return new SerializedService(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
9803
9947
  }
9804
- retrieve({ key, Codec }, description) {
9805
- const bytes = this.backend.get(key);
9806
- if (bytes === null) {
9807
- throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${key}`);
9948
+ retrieve(k, description) {
9949
+ const data = this.retrieveOptional(k);
9950
+ if (data === undefined) {
9951
+ throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${k.key}`);
9808
9952
  }
9809
- return Decoder.decodeObject(Codec, bytes, this.spec);
9953
+ return data;
9810
9954
  }
9811
9955
  retrieveOptional({ key, Codec }) {
9956
+ const cached = this.dataCache.get(key);
9957
+ if (cached !== undefined) {
9958
+ return cached;
9959
+ }
9812
9960
  const bytes = this.backend.get(key);
9813
9961
  if (bytes === null) {
9814
9962
  return undefined;
9815
9963
  }
9816
- return Decoder.decodeObject(Codec, bytes, this.spec);
9964
+ const data = Decoder.decodeObject(Codec, bytes, this.spec);
9965
+ this.dataCache.set(key, data);
9966
+ return data;
9817
9967
  }
9818
9968
  get availabilityAssignment() {
9819
9969
  return this.retrieve(serialize.availabilityAssignment, "availabilityAssignment");
@@ -10891,6 +11041,7 @@ var index$e = /*#__PURE__*/Object.freeze({
10891
11041
  __proto__: null,
10892
11042
  SerializedService: SerializedService,
10893
11043
  SerializedState: SerializedState,
11044
+ SerializedStateView: SerializedStateView,
10894
11045
  StateEntries: StateEntries,
10895
11046
  get StateEntryUpdateAction () { return StateEntryUpdateAction; },
10896
11047
  get StateKeyIdx () { return StateKeyIdx; },
@@ -11083,7 +11234,11 @@ class ServiceWithCodec extends InMemoryService {
11083
11234
  return new ServiceWithCodec(serviceId, data);
11084
11235
  }
11085
11236
  }
11086
- const inMemoryStateCodec = codec$1.Class(InMemoryState, {
11237
+ const inMemoryStateCodec = (spec) => codec$1.Class(class State extends InMemoryState {
11238
+ static create(data) {
11239
+ return InMemoryState.new(spec, data);
11240
+ }
11241
+ }, {
11087
11242
  // alpha
11088
11243
  authPools: serialize.authPools.Codec,
11089
11244
  // phi
@@ -11162,7 +11317,7 @@ class InMemoryStates {
11162
11317
  }
11163
11318
  /** Insert a full state into the database. */
11164
11319
  async insertState(headerHash, state) {
11165
- const encoded = Encoder.encodeObject(inMemoryStateCodec, state, this.spec);
11320
+ const encoded = Encoder.encodeObject(inMemoryStateCodec(this.spec), state, this.spec);
11166
11321
  this.db.set(headerHash, encoded);
11167
11322
  return Result$1.ok(OK);
11168
11323
  }
@@ -11171,7 +11326,7 @@ class InMemoryStates {
11171
11326
  if (encodedState === undefined) {
11172
11327
  return null;
11173
11328
  }
11174
- return Decoder.decodeObject(inMemoryStateCodec, encodedState, this.spec);
11329
+ return Decoder.decodeObject(inMemoryStateCodec(this.spec), encodedState, this.spec);
11175
11330
  }
11176
11331
  }
11177
11332
 
@@ -16356,9 +16511,6 @@ class HostCallMemory {
16356
16511
  }
16357
16512
  return this.memory.loadInto(result, tryAsMemoryIndex(Number(startAddress)));
16358
16513
  }
16359
- getMemory() {
16360
- return this.memory;
16361
- }
16362
16514
  }
16363
16515
 
16364
16516
  class HostCallRegisters {
@@ -17101,10 +17253,10 @@ const recentBlocksHistoryFromJson = json.object({
17101
17253
  peaks: json.array(json.nullable(fromJson.bytes32())),
17102
17254
  },
17103
17255
  }, ({ history, mmr }) => {
17104
- return RecentBlocksHistory.create(RecentBlocks.create({
17256
+ return RecentBlocks.create({
17105
17257
  blocks: history,
17106
17258
  accumulationLog: mmr,
17107
- }));
17259
+ });
17108
17260
  });
17109
17261
 
17110
17262
  const ticketFromJson = json.object({
@@ -17302,7 +17454,7 @@ const fullStateDumpFromJson = (spec) => json.object({
17302
17454
  if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && chi.chi_r === undefined) {
17303
17455
  throw new Error("Registrar is required in Privileges GP ^0.7.1");
17304
17456
  }
17305
- return InMemoryState.create({
17457
+ return InMemoryState.new(spec, {
17306
17458
  authPools: tryAsPerCore(alpha.map((perCore) => {
17307
17459
  if (perCore.length > MAX_AUTH_POOL_SIZE) {
17308
17460
  throw new Error(`AuthPools: expected less than ${MAX_AUTH_POOL_SIZE}, got ${perCore.length}`);
@@ -17315,7 +17467,7 @@ const fullStateDumpFromJson = (spec) => json.object({
17315
17467
  }
17316
17468
  return asKnownSize(perCore);
17317
17469
  }), spec),
17318
- recentBlocks: beta ?? RecentBlocksHistory.empty(),
17470
+ recentBlocks: beta ?? RecentBlocks.empty(),
17319
17471
  nextValidatorData: gamma.gamma_k,
17320
17472
  epochRoot: gamma.gamma_z,
17321
17473
  sealingKeySeries: TicketsOrKeys.toSafroleSealingKeys(gamma.gamma_s, spec),
@@ -17388,21 +17540,21 @@ class TransitionHasher {
17388
17540
  */
17389
17541
  extrinsic(extrinsicView) {
17390
17542
  // https://graypaper.fluffylabs.dev/#/cc517d7/0cfb000cfb00?v=0.6.5
17391
- const guarantees = extrinsicView.guarantees
17543
+ const guaranteesCount = tryAsU32(extrinsicView.guarantees.view().length);
17544
+ const countEncoded = Encoder.encodeObject(codec$1.varU32, guaranteesCount);
17545
+ const guaranteesBlobs = extrinsicView.guarantees
17392
17546
  .view()
17393
17547
  .map((g) => g.view())
17394
- .map((guarantee) => {
17548
+ .reduce((aggregated, guarantee) => {
17395
17549
  const reportHash = this.blake2b.hashBytes(guarantee.report.encoded()).asOpaque();
17396
- return BytesBlob.blobFromParts([
17397
- reportHash.raw,
17398
- guarantee.slot.encoded().raw,
17399
- guarantee.credentials.encoded().raw,
17400
- ]);
17401
- });
17402
- const guaranteeBlob = Encoder.encodeObject(codec$1.sequenceVarLen(dumpCodec), guarantees, this.context);
17550
+ aggregated.push(reportHash.raw);
17551
+ aggregated.push(guarantee.slot.encoded().raw);
17552
+ aggregated.push(guarantee.credentials.encoded().raw);
17553
+ return aggregated;
17554
+ }, [countEncoded.raw]);
17403
17555
  const et = this.blake2b.hashBytes(extrinsicView.tickets.encoded()).asOpaque();
17404
17556
  const ep = this.blake2b.hashBytes(extrinsicView.preimages.encoded()).asOpaque();
17405
- const eg = this.blake2b.hashBytes(guaranteeBlob).asOpaque();
17557
+ const eg = this.blake2b.hashBlobs(guaranteesBlobs).asOpaque();
17406
17558
  const ea = this.blake2b.hashBytes(extrinsicView.assurances.encoded()).asOpaque();
17407
17559
  const ed = this.blake2b.hashBytes(extrinsicView.disputes.encoded()).asOpaque();
17408
17560
  const encoded = BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);