@typeberry/jam 0.2.0-e767e74 → 0.2.0

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.
@@ -26103,9 +26103,6 @@ class ObjectView {
26103
26103
  toString() {
26104
26104
  return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
26105
26105
  }
26106
- [TEST_COMPARE_USING]() {
26107
- return this.materialize();
26108
- }
26109
26106
  }
26110
26107
  /**
26111
26108
  * A lazy-evaluated decoder of a sequence.
@@ -26238,7 +26235,7 @@ const TYPICAL_DICTIONARY_LENGTH = 32;
26238
26235
  * It's not true in a general case, but should be good enough for us.
26239
26236
  *
26240
26237
  */
26241
- function descriptors_readonlyArray(desc) {
26238
+ function readonlyArray(desc) {
26242
26239
  return desc.convert((x) => {
26243
26240
  debug_check `
26244
26241
  ${Array.isArray(x)}
@@ -26400,15 +26397,7 @@ var descriptors_codec;
26400
26397
  /** Custom encoding / decoding logic. */
26401
26398
  codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
26402
26399
  /** Choose a descriptor depending on the encoding/decoding context. */
26403
- codec.select = ({ name, sizeHint, }, chooser) => {
26404
- const Self = chooser(null);
26405
- 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)
26406
- ? codec.select({
26407
- name: Self.View.name,
26408
- sizeHint: Self.View.sizeHint,
26409
- }, (ctx) => chooser(ctx).View)
26410
- : Self.View);
26411
- };
26400
+ 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);
26412
26401
  /**
26413
26402
  * A descriptor for a more complex POJO.
26414
26403
  *
@@ -27230,7 +27219,7 @@ const BANDERSNATCH_KEY_BYTES = 32;
27230
27219
  /** Bandersnatch VRF signature size */
27231
27220
  const bandersnatch_BANDERSNATCH_VRF_SIGNATURE_BYTES = 96;
27232
27221
  /** Bandersnatch ring commitment size */
27233
- const bandersnatch_BANDERSNATCH_RING_ROOT_BYTES = 144;
27222
+ const BANDERSNATCH_RING_ROOT_BYTES = 144;
27234
27223
  /** Bandersnatch proof size */
27235
27224
  const BANDERSNATCH_PROOF_BYTES = 784;
27236
27225
  /** BLS public key size. */
@@ -28811,9 +28800,9 @@ function codecWithContext(chooser) {
28811
28800
  /** Codec for a known-size array with length validation. */
28812
28801
  const codecKnownSizeArray = (val, options, _id) => {
28813
28802
  if ("fixedLength" in options) {
28814
- return descriptors_readonlyArray(descriptors_codec.sequenceFixLen(val, options.fixedLength)).convert(seeThrough, sized_array_asKnownSize);
28803
+ return readonlyArray(descriptors_codec.sequenceFixLen(val, options.fixedLength)).convert(seeThrough, sized_array_asKnownSize);
28815
28804
  }
28816
- return descriptors_readonlyArray(descriptors_codec.sequenceVarLen(val, options)).convert(seeThrough, sized_array_asKnownSize);
28805
+ return readonlyArray(descriptors_codec.sequenceVarLen(val, options)).convert(seeThrough, sized_array_asKnownSize);
28817
28806
  };
28818
28807
  /** Codec for a fixed-size array with length validation. */
28819
28808
  const codecFixedSizeArray = (val, len) => {
@@ -29187,16 +29176,16 @@ class SignedTicket extends WithDebug {
29187
29176
  }
29188
29177
  }
29189
29178
  /** Anonymous? entry into the ticket contest. */
29190
- class tickets_Ticket extends WithDebug {
29179
+ class Ticket extends WithDebug {
29191
29180
  id;
29192
29181
  attempt;
29193
- static Codec = descriptors_codec.Class(tickets_Ticket, {
29182
+ static Codec = descriptors_codec.Class(Ticket, {
29194
29183
  id: descriptors_codec.bytes(hash_HASH_SIZE),
29195
29184
  // TODO [ToDr] we should verify that attempt is either 0|1|2.
29196
29185
  attempt: descriptors_codec.u8.asOpaque(),
29197
29186
  });
29198
29187
  static create({ id, attempt }) {
29199
- return new tickets_Ticket(id, attempt);
29188
+ return new Ticket(id, attempt);
29200
29189
  }
29201
29190
  constructor(
29202
29191
  /**
@@ -29308,7 +29297,7 @@ function tryAsPerValidator(array, spec) {
29308
29297
  `;
29309
29298
  return sized_array_asKnownSize(array);
29310
29299
  }
29311
- const common_codecPerValidator = (val) => codecWithContext((context) => {
29300
+ const codecPerValidator = (val) => codecWithContext((context) => {
29312
29301
  return codecKnownSizeArray(val, {
29313
29302
  fixedLength: context.validatorsCount,
29314
29303
  });
@@ -29435,7 +29424,7 @@ class Verdict extends WithDebug {
29435
29424
  workReportHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
29436
29425
  votesEpoch: descriptors_codec.u32.asOpaque(),
29437
29426
  votes: codecWithContext((context) => {
29438
- return descriptors_readonlyArray(descriptors_codec.sequenceFixLen(Judgement.Codec, context.validatorsSuperMajority)).convert(seeThrough, sized_array_asKnownSize);
29427
+ return readonlyArray(descriptors_codec.sequenceFixLen(Judgement.Codec, context.validatorsSuperMajority)).convert(seeThrough, sized_array_asKnownSize);
29439
29428
  }),
29440
29429
  });
29441
29430
  static create({ workReportHash, votesEpoch, votes }) {
@@ -30127,7 +30116,7 @@ const WorkReportCodec = descriptors_codec.Class(WorkReportNoCodec, {
30127
30116
  authorizerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
30128
30117
  authorizationGasUsed: descriptors_codec.varU64.asOpaque(),
30129
30118
  authorizationOutput: descriptors_codec.blob,
30130
- segmentRootLookup: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
30119
+ segmentRootLookup: readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
30131
30120
  results: descriptors_codec.sequenceVarLen(WorkResult.Codec).convert((x) => x, (items) => FixedSizeArray.new(items, tryAsWorkItemsCount(items.length))),
30132
30121
  });
30133
30122
  const WorkReportCodecPre070 = descriptors_codec.Class(WorkReportNoCodec, {
@@ -30141,7 +30130,7 @@ const WorkReportCodecPre070 = descriptors_codec.Class(WorkReportNoCodec, {
30141
30130
  }),
30142
30131
  authorizerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
30143
30132
  authorizationOutput: descriptors_codec.blob,
30144
- segmentRootLookup: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
30133
+ segmentRootLookup: readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
30145
30134
  results: descriptors_codec.sequenceVarLen(WorkResult.Codec).convert((x) => x, (items) => FixedSizeArray.new(items, tryAsWorkItemsCount(items.length))),
30146
30135
  authorizationGasUsed: descriptors_codec.varU64.asOpaque(),
30147
30136
  });
@@ -30262,7 +30251,7 @@ class ValidatorKeys extends WithDebug {
30262
30251
  class TicketsMarker extends WithDebug {
30263
30252
  tickets;
30264
30253
  static Codec = descriptors_codec.Class(TicketsMarker, {
30265
- tickets: codecPerEpochBlock(tickets_Ticket.Codec),
30254
+ tickets: codecPerEpochBlock(Ticket.Codec),
30266
30255
  });
30267
30256
  static create({ tickets }) {
30268
30257
  return new TicketsMarker(tickets);
@@ -30286,7 +30275,7 @@ class EpochMarker extends WithDebug {
30286
30275
  static Codec = descriptors_codec.Class(EpochMarker, {
30287
30276
  entropy: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
30288
30277
  ticketsEntropy: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
30289
- validators: common_codecPerValidator(ValidatorKeys.Codec),
30278
+ validators: codecPerValidator(ValidatorKeys.Codec),
30290
30279
  });
30291
30280
  static create({ entropy, ticketsEntropy, validators }) {
30292
30281
  return new EpochMarker(entropy, ticketsEntropy, validators);
@@ -30558,19 +30547,6 @@ function emptyBlock(slot = tryAsTimeSlot(0)) {
30558
30547
  });
30559
30548
  }
30560
30549
 
30561
- ;// CONCATENATED MODULE: ./packages/jam/block/utils.ts
30562
-
30563
- /**
30564
- * Take an input data and re-encode that data as view.
30565
- *
30566
- * NOTE: this function should NEVER be used in any production code,
30567
- * it's only a test helper.
30568
- */
30569
- function reencodeAsView(codec, object, chainSpec) {
30570
- const encoded = encoder_Encoder.encodeObject(codec, object, chainSpec);
30571
- return decoder_Decoder.decodeObject(codec.View, encoded, chainSpec);
30572
- }
30573
-
30574
30550
  ;// CONCATENATED MODULE: ./packages/jam/block/index.ts
30575
30551
 
30576
30552
 
@@ -30589,7 +30565,6 @@ function reencodeAsView(codec, object, chainSpec) {
30589
30565
 
30590
30566
 
30591
30567
 
30592
-
30593
30568
  ;// CONCATENATED MODULE: ./packages/jam/block-json/disputes-extrinsic.ts
30594
30569
 
30595
30570
 
@@ -30829,7 +30804,7 @@ const epochMark = descriptors_json.object({
30829
30804
  const ticket = descriptors_json.object({
30830
30805
  id: common_fromJson.bytes32(),
30831
30806
  attempt: common_fromJson.ticketAttempt,
30832
- }, (x) => tickets_Ticket.create({ id: x.id, attempt: x.attempt }));
30807
+ }, (x) => Ticket.create({ id: x.id, attempt: x.attempt }));
30833
30808
  const header_headerFromJson = descriptors_json.object({
30834
30809
  parent: common_fromJson.bytes32(),
30835
30810
  parent_state_root: common_fromJson.bytes32(),
@@ -31753,128 +31728,10 @@ function accumulationOutputComparator(a, b) {
31753
31728
  return Ordering.Equal;
31754
31729
  }
31755
31730
 
31756
- ;// CONCATENATED MODULE: ./packages/jam/block/gp-constants.ts
31757
-
31758
- /**
31759
- * This file lists all of the constants defined in the GrayPaper appendix.
31760
- *
31761
- * NOTE: Avoid using the constants directly, prefer "named" constants defined
31762
- * in a semantical proximity to where they are used.
31763
- *
31764
- * NOTE: This file will most likely be removed in the future. The constants
31765
- * here are only temporarily for convenience. When we figure out better names
31766
- * and places for these this file will be eradicated.
31767
- *
31768
- * https://graypaper.fluffylabs.dev/#/579bd12/413000413000
31769
- */
31770
- /** `G_I`: The gas allocated to invoke a work-package’s Is-Authorized logic. */
31771
- const G_I = 50_000_000;
31772
- /** `I`: Maximum number of work items in a package. */
31773
- const gp_constants_I = (/* unused pure expression or super */ null && (MAX_NUMBER_OF_WORK_ITEMS));
31774
- /** `O`: Maximum number of items in the authorizations pool. */
31775
- const O = 8;
31776
- /** `Q`: The number of items in the authorizations queue. */
31777
- const Q = 80;
31778
- /** `S`: The maximum number of entries in the accumulation queue. */
31779
- const S = 1024;
31780
- /** `T`: The maximum number of extrinsics in a work-package. */
31781
- const T = 128;
31782
- /** `W_A`: The maximum size of is-authorized code in octets. */
31783
- const W_A = 64_000;
31784
- /** `W_B`: The maximum size of an encoded work-package with extrinsic data and imports. */
31785
- const W_B = 13_794_305;
31786
- /** `W_C`: The maximum size of service code in octets. */
31787
- const W_C = 4_000_000;
31788
- /** `W_M`: The maximum number of imports in a work-package. */
31789
- const W_M = 3_072;
31790
- /** `W_R`: The maximum total size of all output blobs in a work-report, in octets. */
31791
- const W_R = 49_152;
31792
- /** `W_T`: The size of a transfer memo in octets. */
31793
- const W_T = 128;
31794
- /** `W_M`: The maximum number of exports in a work-package. */
31795
- const W_X = 3_072;
31796
- // TODO [ToDr] Not sure where these should live yet :(
31797
- /**
31798
- * `S`: The minimum public service index.
31799
- * Services of indices below these may only be created by the Registrar.
31800
- *
31801
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
31802
- */
31803
- const MIN_PUBLIC_SERVICE_INDEX = (/* unused pure expression or super */ null && (2 ** 16));
31804
- /**
31805
- * `J`: The maximum sum of dependency items in a work-report.
31806
- *
31807
- * https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
31808
- */
31809
- const MAX_REPORT_DEPENDENCIES = 8;
31810
-
31811
- ;// CONCATENATED MODULE: ./packages/jam/state/accumulation-queue.ts
31812
-
31813
-
31814
-
31815
-
31816
-
31817
-
31818
-
31819
- /**
31820
- * Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
31821
- *
31822
- * https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
31823
- */
31824
- class NotYetAccumulatedReport extends WithDebug {
31825
- report;
31826
- dependencies;
31827
- static Codec = descriptors_codec.Class(NotYetAccumulatedReport, {
31828
- report: WorkReport.Codec,
31829
- dependencies: codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
31830
- typicalLength: MAX_REPORT_DEPENDENCIES / 2,
31831
- maxLength: MAX_REPORT_DEPENDENCIES,
31832
- minLength: 0,
31833
- }),
31834
- });
31835
- static create({ report, dependencies }) {
31836
- return new NotYetAccumulatedReport(report, dependencies);
31837
- }
31838
- constructor(
31839
- /**
31840
- * Each of these were made available at most one epoch ago
31841
- * but have or had unfulfilled dependencies.
31842
- */
31843
- report,
31844
- /**
31845
- * Alongside the work-report itself, we retain its un-accumulated
31846
- * dependencies, a set of work-package hashes.
31847
- *
31848
- * https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
31849
- */
31850
- dependencies) {
31851
- super();
31852
- this.report = report;
31853
- this.dependencies = dependencies;
31854
- }
31855
- }
31856
- const accumulationQueueCodec = codecPerEpochBlock(descriptors_readonlyArray(descriptors_codec.sequenceVarLen(NotYetAccumulatedReport.Codec)));
31857
-
31858
- ;// CONCATENATED MODULE: ./packages/jam/state/common.ts
31859
-
31860
-
31861
- /** Check if given array has correct length before casting to the opaque type. */
31862
- function tryAsPerCore(array, spec) {
31863
- debug_check `
31864
- ${array.length === spec.coresCount}
31865
- Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
31866
- `;
31867
- return opaque_asOpaqueType(array);
31868
- }
31869
- const codecPerCore = (val) => codecWithContext((context) => {
31870
- return codecKnownSizeArray(val, { fixedLength: context.coresCount });
31871
- });
31872
-
31873
31731
  ;// CONCATENATED MODULE: ./packages/jam/state/assurances.ts
31874
31732
 
31875
31733
 
31876
31734
 
31877
-
31878
31735
  /**
31879
31736
  * Assignment of particular work report to a core.
31880
31737
  *
@@ -31903,30 +31760,27 @@ class AvailabilityAssignment extends WithDebug {
31903
31760
  this.timeout = timeout;
31904
31761
  }
31905
31762
  }
31906
- const availabilityAssignmentsCodec = codecPerCore(descriptors_codec.optional(AvailabilityAssignment.Codec));
31907
-
31908
- ;// CONCATENATED MODULE: ./packages/jam/state/auth.ts
31909
-
31910
-
31911
31763
 
31764
+ ;// CONCATENATED MODULE: ./packages/jam/state/common.ts
31912
31765
 
31913
31766
 
31914
- /** `O`: Maximal authorization pool size. */
31915
- const MAX_AUTH_POOL_SIZE = O;
31916
- /** `Q`: Size of the authorization queue. */
31917
- const AUTHORIZATION_QUEUE_SIZE = Q;
31918
- const authPoolsCodec = codecPerCore(codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
31919
- minLength: 0,
31920
- maxLength: MAX_AUTH_POOL_SIZE,
31921
- typicalLength: MAX_AUTH_POOL_SIZE,
31922
- }));
31923
- const authQueuesCodec = codecPerCore(codecFixedSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE));
31767
+ /** Check if given array has correct length before casting to the opaque type. */
31768
+ function tryAsPerCore(array, spec) {
31769
+ debug_check `
31770
+ ${array.length === spec.coresCount}
31771
+ Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
31772
+ `;
31773
+ return opaque_asOpaqueType(array);
31774
+ }
31775
+ const codecPerCore = (val) => codecWithContext((context) => {
31776
+ return codecKnownSizeArray(val, { fixedLength: context.coresCount });
31777
+ });
31924
31778
 
31925
31779
  ;// CONCATENATED MODULE: ./packages/jam/state/disputes.ts
31926
31780
 
31927
31781
 
31928
31782
 
31929
- const sortedSetCodec = () => descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE))).convert((input) => input.array, (output) => {
31783
+ const sortedSetCodec = () => readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE))).convert((input) => input.array, (output) => {
31930
31784
  const typed = output.map((x) => x.asOpaque());
31931
31785
  return sorted_set_SortedSet.fromSortedArray(hashComparator, typed);
31932
31786
  });
@@ -31988,6 +31842,65 @@ function hashComparator(a, b) {
31988
31842
  return a.compare(b);
31989
31843
  }
31990
31844
 
31845
+ ;// CONCATENATED MODULE: ./packages/jam/block/gp-constants.ts
31846
+
31847
+ /**
31848
+ * This file lists all of the constants defined in the GrayPaper appendix.
31849
+ *
31850
+ * NOTE: Avoid using the constants directly, prefer "named" constants defined
31851
+ * in a semantical proximity to where they are used.
31852
+ *
31853
+ * NOTE: This file will most likely be removed in the future. The constants
31854
+ * here are only temporarily for convenience. When we figure out better names
31855
+ * and places for these this file will be eradicated.
31856
+ *
31857
+ * https://graypaper.fluffylabs.dev/#/579bd12/413000413000
31858
+ */
31859
+ /** `G_I`: The gas allocated to invoke a work-package’s Is-Authorized logic. */
31860
+ const G_I = 50_000_000;
31861
+ /** `I`: Maximum number of work items in a package. */
31862
+ const gp_constants_I = (/* unused pure expression or super */ null && (MAX_NUMBER_OF_WORK_ITEMS));
31863
+ /** `O`: Maximum number of items in the authorizations pool. */
31864
+ const O = 8;
31865
+ /** `Q`: The number of items in the authorizations queue. */
31866
+ const Q = 80;
31867
+ /** `S`: The maximum number of entries in the accumulation queue. */
31868
+ const S = 1024;
31869
+ /** `T`: The maximum number of extrinsics in a work-package. */
31870
+ const T = 128;
31871
+ /** `W_A`: The maximum size of is-authorized code in octets. */
31872
+ const W_A = 64_000;
31873
+ /** `W_B`: The maximum size of an encoded work-package with extrinsic data and imports. */
31874
+ const W_B = 13_794_305;
31875
+ /** `W_C`: The maximum size of service code in octets. */
31876
+ const W_C = 4_000_000;
31877
+ /** `W_M`: The maximum number of imports in a work-package. */
31878
+ const W_M = 3_072;
31879
+ /** `W_R`: The maximum total size of all output blobs in a work-report, in octets. */
31880
+ const W_R = 49_152;
31881
+ /** `W_T`: The size of a transfer memo in octets. */
31882
+ const W_T = 128;
31883
+ /** `W_M`: The maximum number of exports in a work-package. */
31884
+ const W_X = 3_072;
31885
+ // TODO [ToDr] Not sure where these should live yet :(
31886
+ /**
31887
+ * `S`: The minimum public service index.
31888
+ * Services of indices below these may only be created by the Registrar.
31889
+ *
31890
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
31891
+ */
31892
+ const MIN_PUBLIC_SERVICE_INDEX = (/* unused pure expression or super */ null && (2 ** 16));
31893
+ /**
31894
+ * `J`: The maximum sum of dependency items in a work-report.
31895
+ *
31896
+ * https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
31897
+ */
31898
+ const MAX_REPORT_DEPENDENCIES = 8;
31899
+ /** `Q`: Size of the authorization queue. */
31900
+ const AUTHORIZATION_QUEUE_SIZE = Q;
31901
+ /** `O`: Maximal authorization pool size. */
31902
+ const MAX_AUTH_POOL_SIZE = O;
31903
+
31991
31904
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
31992
31905
  const MAX_VALUE = 4294967295;
31993
31906
  const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
@@ -31995,7 +31908,7 @@ const MIN_VALUE = (/* unused pure expression or super */ null && (-(2 ** 31)));
31995
31908
  const MAX_SHIFT_U32 = 32;
31996
31909
  const MAX_SHIFT_U64 = 64n;
31997
31910
 
31998
- ;// CONCATENATED MODULE: ./packages/jam/state/recent-blocks.ts
31911
+ ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
31999
31912
 
32000
31913
 
32001
31914
 
@@ -32003,259 +31916,15 @@ const MAX_SHIFT_U64 = 64n;
32003
31916
 
32004
31917
 
32005
31918
  /**
32006
- * `H = 8`: The size of recent history, in blocks.
31919
+ * `B_S`: The basic minimum balance which all services require.
32007
31920
  *
32008
- * https://graypaper.fluffylabs.dev/#/579bd12/416300416500
31921
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
32009
31922
  */
32010
- const MAX_RECENT_HISTORY = 8;
32011
- /** Recent history of a single block. */
32012
- class BlockState extends WithDebug {
32013
- headerHash;
32014
- accumulationResult;
32015
- postStateRoot;
32016
- reported;
32017
- static Codec = descriptors_codec.Class(BlockState, {
32018
- headerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
32019
- accumulationResult: descriptors_codec.bytes(hash_HASH_SIZE),
32020
- postStateRoot: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
32021
- reported: codecHashDictionary(WorkPackageInfo.Codec, (x) => x.workPackageHash),
32022
- });
32023
- static create({ headerHash, accumulationResult, postStateRoot, reported }) {
32024
- return new BlockState(headerHash, accumulationResult, postStateRoot, reported);
32025
- }
32026
- constructor(
32027
- /** Header hash. */
32028
- headerHash,
32029
- /** Merkle mountain belt of accumulation result. */
32030
- accumulationResult,
32031
- /** Posterior state root filled in with a 1-block delay. */
32032
- postStateRoot,
32033
- /** Reported work packages (no more than number of cores). */
32034
- reported) {
32035
- super();
32036
- this.headerHash = headerHash;
32037
- this.accumulationResult = accumulationResult;
32038
- this.postStateRoot = postStateRoot;
32039
- this.reported = reported;
32040
- }
32041
- }
31923
+ const BASE_SERVICE_BALANCE = 100n;
32042
31924
  /**
32043
- * Recent history of blocks.
31925
+ * `B_I`: The additional minimum balance required per item of elective service state.
32044
31926
  *
32045
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
32046
- */
32047
- class RecentBlocks extends WithDebug {
32048
- blocks;
32049
- accumulationLog;
32050
- static Codec = descriptors_codec.Class(RecentBlocks, {
32051
- blocks: codecKnownSizeArray(BlockState.Codec, {
32052
- minLength: 0,
32053
- maxLength: MAX_RECENT_HISTORY,
32054
- typicalLength: MAX_RECENT_HISTORY,
32055
- }),
32056
- accumulationLog: descriptors_codec.object({
32057
- peaks: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.optional(descriptors_codec.bytes(hash_HASH_SIZE)))),
32058
- }),
32059
- });
32060
- static empty() {
32061
- return new RecentBlocks(sized_array_asKnownSize([]), {
32062
- peaks: [],
32063
- });
32064
- }
32065
- static create(a) {
32066
- return new RecentBlocks(a.blocks, a.accumulationLog);
32067
- }
32068
- constructor(
32069
- /**
32070
- * Most recent blocks.
32071
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fea010fea01?v=0.6.7
32072
- */
32073
- blocks,
32074
- /**
32075
- * Accumulation output log.
32076
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/0f02020f0202?v=0.6.7
32077
- */
32078
- accumulationLog) {
32079
- super();
32080
- this.blocks = blocks;
32081
- this.accumulationLog = accumulationLog;
32082
- }
32083
- }
32084
-
32085
- ;// CONCATENATED MODULE: ./packages/jam/state/recently-accumulated.ts
32086
-
32087
-
32088
-
32089
-
32090
- const recentlyAccumulatedCodec = codecPerEpochBlock(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque()).convert((x) => Array.from(x), (x) => HashSet.from(x)));
32091
-
32092
- ;// CONCATENATED MODULE: ./packages/jam/state/validator-data.ts
32093
-
32094
-
32095
-
32096
-
32097
- /**
32098
- * Fixed size of validator metadata.
32099
- *
32100
- * https://graypaper.fluffylabs.dev/#/5f542d7/0d55010d5501
32101
- */
32102
- const VALIDATOR_META_BYTES = 128;
32103
- /**
32104
- * Details about validators' identity.
32105
- *
32106
- * https://graypaper.fluffylabs.dev/#/5f542d7/0d4b010d4c01
32107
- */
32108
- class validator_data_ValidatorData extends WithDebug {
32109
- bandersnatch;
32110
- ed25519;
32111
- bls;
32112
- metadata;
32113
- static Codec = descriptors_codec.Class(validator_data_ValidatorData, {
32114
- bandersnatch: descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque(),
32115
- ed25519: descriptors_codec.bytes(ED25519_KEY_BYTES).asOpaque(),
32116
- bls: descriptors_codec.bytes(BLS_KEY_BYTES).asOpaque(),
32117
- metadata: descriptors_codec.bytes(VALIDATOR_META_BYTES),
32118
- });
32119
- static create({ ed25519, bandersnatch, bls, metadata }) {
32120
- return new validator_data_ValidatorData(bandersnatch, ed25519, bls, metadata);
32121
- }
32122
- constructor(
32123
- /** Bandersnatch public key. */
32124
- bandersnatch,
32125
- /** ED25519 key data. */
32126
- ed25519,
32127
- /** BLS public key. */
32128
- bls,
32129
- /** Validator-defined additional metdata. */
32130
- metadata) {
32131
- super();
32132
- this.bandersnatch = bandersnatch;
32133
- this.ed25519 = ed25519;
32134
- this.bls = bls;
32135
- this.metadata = metadata;
32136
- }
32137
- }
32138
- const validatorsDataCodec = common_codecPerValidator(validator_data_ValidatorData.Codec);
32139
-
32140
- ;// CONCATENATED MODULE: ./packages/jam/state/safrole-data.ts
32141
-
32142
-
32143
-
32144
-
32145
-
32146
-
32147
-
32148
-
32149
-
32150
-
32151
-
32152
- var SafroleSealingKeysKind;
32153
- (function (SafroleSealingKeysKind) {
32154
- SafroleSealingKeysKind[SafroleSealingKeysKind["Tickets"] = 0] = "Tickets";
32155
- SafroleSealingKeysKind[SafroleSealingKeysKind["Keys"] = 1] = "Keys";
32156
- })(SafroleSealingKeysKind || (SafroleSealingKeysKind = {}));
32157
- const codecBandersnatchKey = descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque();
32158
- class safrole_data_SafroleSealingKeysData extends WithDebug {
32159
- kind;
32160
- keys;
32161
- tickets;
32162
- static Codec = codecWithContext((context) => {
32163
- return descriptors_codec.custom({
32164
- name: "SafroleSealingKeys",
32165
- sizeHint: { bytes: 1 + hash_HASH_SIZE * context.epochLength, isExact: false },
32166
- }, (e, x) => {
32167
- e.varU32(numbers_tryAsU32(x.kind));
32168
- if (x.kind === SafroleSealingKeysKind.Keys) {
32169
- e.sequenceFixLen(codecBandersnatchKey, x.keys);
32170
- }
32171
- else {
32172
- e.sequenceFixLen(tickets_Ticket.Codec, x.tickets);
32173
- }
32174
- }, (d) => {
32175
- const epochLength = context.epochLength;
32176
- const kind = d.varU32();
32177
- if (kind === SafroleSealingKeysKind.Keys) {
32178
- const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
32179
- return safrole_data_SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
32180
- }
32181
- if (kind === SafroleSealingKeysKind.Tickets) {
32182
- const tickets = d.sequenceFixLen(tickets_Ticket.Codec, epochLength);
32183
- return safrole_data_SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
32184
- }
32185
- throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
32186
- }, (s) => {
32187
- const kind = s.decoder.varU32();
32188
- if (kind === SafroleSealingKeysKind.Keys) {
32189
- s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
32190
- return;
32191
- }
32192
- if (kind === SafroleSealingKeysKind.Tickets) {
32193
- s.sequenceFixLen(tickets_Ticket.Codec, context.epochLength);
32194
- return;
32195
- }
32196
- throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
32197
- });
32198
- });
32199
- static keys(keys) {
32200
- return new safrole_data_SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
32201
- }
32202
- static tickets(tickets) {
32203
- return new safrole_data_SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
32204
- }
32205
- constructor(kind, keys, tickets) {
32206
- super();
32207
- this.kind = kind;
32208
- this.keys = keys;
32209
- this.tickets = tickets;
32210
- }
32211
- }
32212
- class safrole_data_SafroleData {
32213
- nextValidatorData;
32214
- epochRoot;
32215
- sealingKeySeries;
32216
- ticketsAccumulator;
32217
- static Codec = descriptors_codec.Class(safrole_data_SafroleData, {
32218
- nextValidatorData: common_codecPerValidator(validator_data_ValidatorData.Codec),
32219
- epochRoot: descriptors_codec.bytes(bandersnatch_BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
32220
- sealingKeySeries: safrole_data_SafroleSealingKeysData.Codec,
32221
- ticketsAccumulator: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(tickets_Ticket.Codec)).convert(seeThrough, sized_array_asKnownSize),
32222
- });
32223
- static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
32224
- return new safrole_data_SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
32225
- }
32226
- constructor(
32227
- /** gamma_k */
32228
- nextValidatorData,
32229
- /** gamma_z */
32230
- epochRoot,
32231
- /** gamma_s */
32232
- sealingKeySeries,
32233
- /** gamma_a */
32234
- ticketsAccumulator) {
32235
- this.nextValidatorData = nextValidatorData;
32236
- this.epochRoot = epochRoot;
32237
- this.sealingKeySeries = sealingKeySeries;
32238
- this.ticketsAccumulator = ticketsAccumulator;
32239
- }
32240
- }
32241
-
32242
- ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
32243
-
32244
-
32245
-
32246
-
32247
-
32248
-
32249
- /**
32250
- * `B_S`: The basic minimum balance which all services require.
32251
- *
32252
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
32253
- */
32254
- const BASE_SERVICE_BALANCE = 100n;
32255
- /**
32256
- * `B_I`: The additional minimum balance required per item of elective service state.
32257
- *
32258
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
31927
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
32259
31928
  */
32260
31929
  const ELECTIVE_ITEM_BALANCE = 10n;
32261
31930
  /**
@@ -32429,418 +32098,358 @@ class LookupHistoryItem {
32429
32098
  }
32430
32099
  }
32431
32100
 
32432
- ;// CONCATENATED MODULE: ./packages/jam/state/statistics.ts
32433
-
32101
+ ;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
32434
32102
 
32435
32103
 
32436
32104
 
32437
32105
 
32438
32106
 
32439
- const codecServiceId = compatibility_Compatibility.isSuite(TestSuite.W3F_DAVXY) || compatibility_Compatibility.isSuite(TestSuite.JAMDUNA, compatibility_GpVersion.V0_6_7)
32440
- ? descriptors_codec.u32.asOpaque()
32441
- : descriptors_codec.varU32.convert((s) => numbers_tryAsU32(s), (i) => tryAsServiceId(i));
32442
- /**
32443
- * Activity Record of a single validator.
32444
- *
32445
- * https://graypaper.fluffylabs.dev/#/579bd12/183701183701
32446
- */
32447
- class ValidatorStatistics {
32448
- blocks;
32449
- tickets;
32450
- preImages;
32451
- preImagesSize;
32452
- guarantees;
32453
- assurances;
32454
- static Codec = descriptors_codec.Class(ValidatorStatistics, {
32455
- blocks: descriptors_codec.u32,
32456
- tickets: descriptors_codec.u32,
32457
- preImages: descriptors_codec.u32,
32458
- preImagesSize: descriptors_codec.u32,
32459
- guarantees: descriptors_codec.u32,
32460
- assurances: descriptors_codec.u32,
32107
+ /** Dictionary entry of services that auto-accumulate every block. */
32108
+ class AutoAccumulate {
32109
+ service;
32110
+ gasLimit;
32111
+ static Codec = descriptors_codec.Class(AutoAccumulate, {
32112
+ service: descriptors_codec.u32.asOpaque(),
32113
+ gasLimit: descriptors_codec.u64.asOpaque(),
32461
32114
  });
32462
- static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
32463
- return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
32115
+ static create({ service, gasLimit }) {
32116
+ return new AutoAccumulate(service, gasLimit);
32464
32117
  }
32465
32118
  constructor(
32466
- /** The number of blocks produced by the validator. */
32467
- blocks,
32468
- /** The number of tickets introduced by the validator. */
32469
- tickets,
32470
- /** The number of preimages introduced by the validator. */
32471
- preImages,
32472
- /** The total number of octets across all preimages introduced by the validator. */
32473
- preImagesSize,
32474
- /** The number of reports guaranteed by the validator. */
32475
- guarantees,
32476
- /** The number of availability assurances made by the validator. */
32477
- assurances) {
32478
- this.blocks = blocks;
32479
- this.tickets = tickets;
32480
- this.preImages = preImages;
32481
- this.preImagesSize = preImagesSize;
32482
- this.guarantees = guarantees;
32483
- this.assurances = assurances;
32484
- }
32485
- static empty() {
32486
- const zero = numbers_tryAsU32(0);
32487
- return new ValidatorStatistics(zero, zero, zero, zero, zero, zero);
32119
+ /** Service id that auto-accumulates. */
32120
+ service,
32121
+ /** Gas limit for auto-accumulation. */
32122
+ gasLimit) {
32123
+ this.service = service;
32124
+ this.gasLimit = gasLimit;
32488
32125
  }
32489
32126
  }
32490
- const codecVarU16 = descriptors_codec.varU32.convert((i) => numbers_tryAsU32(i), (o) => numbers_tryAsU16(o));
32491
- /** Encode/decode unsigned gas. */
32492
- const codecVarGas = descriptors_codec.varU64.convert((g) => tryAsU64(g), (i) => tryAsServiceGas(i));
32493
32127
  /**
32494
- * Single core statistics.
32495
- * Updated per block, based on incoming work reports (`w`).
32496
- *
32497
- * https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
32498
- * https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
32128
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
32499
32129
  */
32500
- class CoreStatistics {
32501
- dataAvailabilityLoad;
32502
- popularity;
32503
- imports;
32504
- exports;
32505
- extrinsicSize;
32506
- extrinsicCount;
32507
- bundleSize;
32508
- gasUsed;
32509
- static Codec = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_0)
32510
- ? descriptors_codec.Class(CoreStatistics, {
32511
- dataAvailabilityLoad: descriptors_codec.varU32,
32512
- popularity: codecVarU16,
32513
- imports: codecVarU16,
32514
- extrinsicCount: codecVarU16,
32515
- extrinsicSize: descriptors_codec.varU32,
32516
- exports: codecVarU16,
32517
- bundleSize: descriptors_codec.varU32,
32518
- gasUsed: codecVarGas,
32519
- })
32520
- : descriptors_codec.Class(CoreStatistics, {
32521
- dataAvailabilityLoad: descriptors_codec.varU32,
32522
- popularity: codecVarU16,
32523
- imports: codecVarU16,
32524
- exports: codecVarU16,
32525
- extrinsicSize: descriptors_codec.varU32,
32526
- extrinsicCount: codecVarU16,
32527
- bundleSize: descriptors_codec.varU32,
32528
- gasUsed: codecVarGas,
32529
- });
32530
- static create(v) {
32531
- return new CoreStatistics(v.dataAvailabilityLoad, v.popularity, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.bundleSize, v.gasUsed);
32130
+ class PrivilegedServices {
32131
+ manager;
32132
+ delegator;
32133
+ registrar;
32134
+ assigners;
32135
+ autoAccumulateServices;
32136
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
32137
+ static Codec = descriptors_codec.Class(PrivilegedServices, {
32138
+ manager: descriptors_codec.u32.asOpaque(),
32139
+ assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
32140
+ delegator: descriptors_codec.u32.asOpaque(),
32141
+ registrar: compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1)
32142
+ ? descriptors_codec.u32.asOpaque()
32143
+ : ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
32144
+ autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
32145
+ });
32146
+ static create(a) {
32147
+ return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
32532
32148
  }
32533
32149
  constructor(
32534
- /** `d` */
32535
- dataAvailabilityLoad,
32536
- /** `p` */
32537
- popularity,
32538
- /** `i` */
32539
- imports,
32540
- /** `e` */
32541
- exports,
32542
- /** `z` */
32543
- extrinsicSize,
32544
- /** `x` */
32545
- extrinsicCount,
32546
- /** `b` */
32547
- bundleSize,
32548
- /** `u` */
32549
- gasUsed) {
32550
- this.dataAvailabilityLoad = dataAvailabilityLoad;
32551
- this.popularity = popularity;
32552
- this.imports = imports;
32553
- this.exports = exports;
32554
- this.extrinsicSize = extrinsicSize;
32555
- this.extrinsicCount = extrinsicCount;
32556
- this.bundleSize = bundleSize;
32557
- this.gasUsed = gasUsed;
32558
- }
32559
- static empty() {
32560
- const zero = numbers_tryAsU32(0);
32561
- const zero16 = numbers_tryAsU16(0);
32562
- const zeroGas = tryAsServiceGas(0);
32563
- return new CoreStatistics(zero, zero16, zero16, zero16, zero, zero16, zero, zeroGas);
32150
+ /**
32151
+ * `χ_M`: Manages alteration of χ from block to block,
32152
+ * as well as bestow services with storage deposit credits.
32153
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
32154
+ */
32155
+ manager,
32156
+ /** `χ_V`: Managers validator keys. */
32157
+ delegator,
32158
+ /**
32159
+ * `χ_R`: Manages the creation of services in protected range.
32160
+ *
32161
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
32162
+ */
32163
+ registrar,
32164
+ /** `χ_A`: Manages authorization queue one for each core. */
32165
+ assigners,
32166
+ /** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
32167
+ autoAccumulateServices) {
32168
+ this.manager = manager;
32169
+ this.delegator = delegator;
32170
+ this.registrar = registrar;
32171
+ this.assigners = assigners;
32172
+ this.autoAccumulateServices = autoAccumulateServices;
32564
32173
  }
32565
32174
  }
32175
+
32176
+ ;// CONCATENATED MODULE: ./packages/jam/state/recent-blocks.ts
32177
+
32178
+
32179
+
32180
+
32181
+
32182
+
32566
32183
  /**
32567
- * Service statistics.
32568
- * Updated per block, based on available work reports (`W`).
32184
+ * `H = 8`: The size of recent history, in blocks.
32569
32185
  *
32570
- * https://graypaper.fluffylabs.dev/#/1c979cb/199802199802?v=0.7.1
32186
+ * https://graypaper.fluffylabs.dev/#/579bd12/416300416500
32571
32187
  */
32572
- class ServiceStatistics {
32573
- providedCount;
32574
- providedSize;
32575
- refinementCount;
32576
- refinementGasUsed;
32577
- imports;
32578
- exports;
32579
- extrinsicSize;
32580
- extrinsicCount;
32581
- accumulateCount;
32582
- accumulateGasUsed;
32583
- onTransfersCount;
32584
- onTransfersGasUsed;
32585
- static Codec = compatibility_Compatibility.selectIfGreaterOrEqual({
32586
- fallback: descriptors_codec.Class(ServiceStatistics, {
32587
- providedCount: codecVarU16,
32588
- providedSize: descriptors_codec.varU32,
32589
- refinementCount: descriptors_codec.varU32,
32590
- refinementGasUsed: codecVarGas,
32591
- imports: codecVarU16,
32592
- exports: codecVarU16,
32593
- extrinsicSize: descriptors_codec.varU32,
32594
- extrinsicCount: codecVarU16,
32595
- accumulateCount: descriptors_codec.varU32,
32596
- accumulateGasUsed: codecVarGas,
32597
- onTransfersCount: descriptors_codec.varU32,
32598
- onTransfersGasUsed: codecVarGas,
32599
- }),
32600
- versions: {
32601
- [compatibility_GpVersion.V0_7_0]: descriptors_codec.Class(ServiceStatistics, {
32602
- providedCount: codecVarU16,
32603
- providedSize: descriptors_codec.varU32,
32604
- refinementCount: descriptors_codec.varU32,
32605
- refinementGasUsed: codecVarGas,
32606
- imports: codecVarU16,
32607
- extrinsicCount: codecVarU16,
32608
- extrinsicSize: descriptors_codec.varU32,
32609
- exports: codecVarU16,
32610
- accumulateCount: descriptors_codec.varU32,
32611
- accumulateGasUsed: codecVarGas,
32612
- onTransfersCount: descriptors_codec.varU32,
32613
- onTransfersGasUsed: codecVarGas,
32614
- }),
32615
- [compatibility_GpVersion.V0_7_1]: descriptors_codec.Class(ServiceStatistics, {
32616
- providedCount: codecVarU16,
32617
- providedSize: descriptors_codec.varU32,
32618
- refinementCount: descriptors_codec.varU32,
32619
- refinementGasUsed: codecVarGas,
32620
- imports: codecVarU16,
32621
- extrinsicCount: codecVarU16,
32622
- extrinsicSize: descriptors_codec.varU32,
32623
- exports: codecVarU16,
32624
- accumulateCount: descriptors_codec.varU32,
32625
- accumulateGasUsed: codecVarGas,
32626
- onTransfersCount: ignoreValueWithDefault(numbers_tryAsU32(0)),
32627
- onTransfersGasUsed: ignoreValueWithDefault(tryAsServiceGas(0)),
32628
- }),
32629
- },
32188
+ const MAX_RECENT_HISTORY = 8;
32189
+ /** Recent history of a single block. */
32190
+ class BlockState extends WithDebug {
32191
+ headerHash;
32192
+ accumulationResult;
32193
+ postStateRoot;
32194
+ reported;
32195
+ static Codec = descriptors_codec.Class(BlockState, {
32196
+ headerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
32197
+ accumulationResult: descriptors_codec.bytes(hash_HASH_SIZE),
32198
+ postStateRoot: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
32199
+ reported: codecHashDictionary(WorkPackageInfo.Codec, (x) => x.workPackageHash),
32630
32200
  });
32631
- static create(v) {
32632
- 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);
32201
+ static create({ headerHash, accumulationResult, postStateRoot, reported }) {
32202
+ return new BlockState(headerHash, accumulationResult, postStateRoot, reported);
32633
32203
  }
32634
32204
  constructor(
32635
- /** `p.0` */
32636
- providedCount,
32637
- /** `p.1` */
32638
- providedSize,
32639
- /** `r.0` */
32640
- refinementCount,
32641
- /** `r.1` */
32642
- refinementGasUsed,
32643
- /** `i` */
32644
- imports,
32645
- /** `e` */
32646
- exports,
32647
- /** `z` */
32648
- extrinsicSize,
32649
- /** `x` */
32650
- extrinsicCount,
32651
- /** `a.0` */
32652
- accumulateCount,
32653
- /** `a.1` */
32654
- accumulateGasUsed,
32655
- /** `t.0` @deprecated since 0.7.1 */
32656
- onTransfersCount,
32657
- /** `t.1` @deprecated since 0.7.1 */
32658
- onTransfersGasUsed) {
32659
- this.providedCount = providedCount;
32660
- this.providedSize = providedSize;
32661
- this.refinementCount = refinementCount;
32662
- this.refinementGasUsed = refinementGasUsed;
32663
- this.imports = imports;
32664
- this.exports = exports;
32665
- this.extrinsicSize = extrinsicSize;
32666
- this.extrinsicCount = extrinsicCount;
32667
- this.accumulateCount = accumulateCount;
32668
- this.accumulateGasUsed = accumulateGasUsed;
32669
- this.onTransfersCount = onTransfersCount;
32670
- this.onTransfersGasUsed = onTransfersGasUsed;
32205
+ /** Header hash. */
32206
+ headerHash,
32207
+ /** Merkle mountain belt of accumulation result. */
32208
+ accumulationResult,
32209
+ /** Posterior state root filled in with a 1-block delay. */
32210
+ postStateRoot,
32211
+ /** Reported work packages (no more than number of cores). */
32212
+ reported) {
32213
+ super();
32214
+ this.headerHash = headerHash;
32215
+ this.accumulationResult = accumulationResult;
32216
+ this.postStateRoot = postStateRoot;
32217
+ this.reported = reported;
32671
32218
  }
32672
- static empty() {
32673
- const zero = numbers_tryAsU32(0);
32674
- const zero16 = numbers_tryAsU16(0);
32675
- const zeroGas = tryAsServiceGas(0);
32676
- return new ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
32219
+ }
32220
+ class RecentBlocks extends WithDebug {
32221
+ blocks;
32222
+ accumulationLog;
32223
+ static Codec = descriptors_codec.Class(RecentBlocks, {
32224
+ blocks: codecKnownSizeArray(BlockState.Codec, {
32225
+ minLength: 0,
32226
+ maxLength: MAX_RECENT_HISTORY,
32227
+ typicalLength: MAX_RECENT_HISTORY,
32228
+ }),
32229
+ accumulationLog: descriptors_codec.object({
32230
+ peaks: readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.optional(descriptors_codec.bytes(hash_HASH_SIZE)))),
32231
+ }),
32232
+ });
32233
+ static create(a) {
32234
+ return new RecentBlocks(a.blocks, a.accumulationLog);
32235
+ }
32236
+ constructor(
32237
+ /**
32238
+ * Most recent blocks.
32239
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fea010fea01?v=0.6.7
32240
+ */
32241
+ blocks,
32242
+ /**
32243
+ * Accumulation output log.
32244
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/0f02020f0202?v=0.6.7
32245
+ */
32246
+ accumulationLog) {
32247
+ super();
32248
+ this.blocks = blocks;
32249
+ this.accumulationLog = accumulationLog;
32677
32250
  }
32678
32251
  }
32679
- /** `pi`: Statistics of each validator, cores statistics and services statistics. */
32680
- class StatisticsData {
32252
+ /**
32253
+ * Recent history of blocks.
32254
+ *
32255
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
32256
+ */
32257
+ class RecentBlocksHistory extends WithDebug {
32681
32258
  current;
32682
- previous;
32683
- cores;
32684
- services;
32685
- static Codec = descriptors_codec.Class(StatisticsData, {
32686
- current: common_codecPerValidator(ValidatorStatistics.Codec),
32687
- previous: common_codecPerValidator(ValidatorStatistics.Codec),
32688
- cores: codecPerCore(CoreStatistics.Codec),
32689
- services: descriptors_codec.dictionary(codecServiceId, ServiceStatistics.Codec, {
32690
- sortKeys: (a, b) => a - b,
32691
- }),
32259
+ static Codec = Descriptor.new("RecentBlocksHistory", RecentBlocks.Codec.sizeHint, (encoder, value) => RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
32260
+ const recentBlocks = RecentBlocks.Codec.decode(decoder);
32261
+ return RecentBlocksHistory.create(recentBlocks);
32262
+ }, (skip) => {
32263
+ return RecentBlocks.Codec.skip(skip);
32692
32264
  });
32693
- static create(v) {
32694
- return new StatisticsData(v.current, v.previous, v.cores, v.services);
32265
+ static create(recentBlocks) {
32266
+ return new RecentBlocksHistory(recentBlocks);
32695
32267
  }
32696
- constructor(current, previous, cores, services) {
32268
+ static empty() {
32269
+ return RecentBlocksHistory.create(RecentBlocks.create({
32270
+ blocks: sized_array_asKnownSize([]),
32271
+ accumulationLog: { peaks: [] },
32272
+ }));
32273
+ }
32274
+ /**
32275
+ * Returns the block's BEEFY super peak.
32276
+ */
32277
+ static accumulationResult(block) {
32278
+ return block.accumulationResult;
32279
+ }
32280
+ constructor(current) {
32281
+ super();
32697
32282
  this.current = current;
32698
- this.previous = previous;
32699
- this.cores = cores;
32700
- this.services = services;
32283
+ }
32284
+ /** History of recent blocks with maximum size of `MAX_RECENT_HISTORY` */
32285
+ get blocks() {
32286
+ if (this.current !== null) {
32287
+ return this.current.blocks;
32288
+ }
32289
+ throw new Error("RecentBlocksHistory is in invalid state");
32290
+ }
32291
+ asCurrent() {
32292
+ if (this.current === null) {
32293
+ throw new Error("Cannot access current RecentBlocks format");
32294
+ }
32295
+ return this.current;
32296
+ }
32297
+ updateBlocks(blocks) {
32298
+ if (this.current !== null) {
32299
+ return RecentBlocksHistory.create(RecentBlocks.create({
32300
+ ...this.current,
32301
+ blocks: opaque_asOpaqueType(blocks),
32302
+ }));
32303
+ }
32304
+ throw new Error("RecentBlocksHistory is in invalid state. Cannot be updated!");
32701
32305
  }
32702
32306
  }
32703
32307
 
32704
- ;// CONCATENATED MODULE: ./packages/jam/state/in-memory-state-view.ts
32705
-
32308
+ ;// CONCATENATED MODULE: ./packages/jam/state/validator-data.ts
32706
32309
 
32707
32310
 
32708
32311
 
32312
+ /**
32313
+ * Fixed size of validator metadata.
32314
+ *
32315
+ * https://graypaper.fluffylabs.dev/#/5f542d7/0d55010d5501
32316
+ */
32317
+ const VALIDATOR_META_BYTES = 128;
32318
+ /**
32319
+ * Details about validators' identity.
32320
+ *
32321
+ * https://graypaper.fluffylabs.dev/#/5f542d7/0d4b010d4c01
32322
+ */
32323
+ class ValidatorData extends WithDebug {
32324
+ bandersnatch;
32325
+ ed25519;
32326
+ bls;
32327
+ metadata;
32328
+ static Codec = descriptors_codec.Class(ValidatorData, {
32329
+ bandersnatch: descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque(),
32330
+ ed25519: descriptors_codec.bytes(ED25519_KEY_BYTES).asOpaque(),
32331
+ bls: descriptors_codec.bytes(BLS_KEY_BYTES).asOpaque(),
32332
+ metadata: descriptors_codec.bytes(VALIDATOR_META_BYTES),
32333
+ });
32334
+ static create({ ed25519, bandersnatch, bls, metadata }) {
32335
+ return new ValidatorData(bandersnatch, ed25519, bls, metadata);
32336
+ }
32337
+ constructor(
32338
+ /** Bandersnatch public key. */
32339
+ bandersnatch,
32340
+ /** ED25519 key data. */
32341
+ ed25519,
32342
+ /** BLS public key. */
32343
+ bls,
32344
+ /** Validator-defined additional metdata. */
32345
+ metadata) {
32346
+ super();
32347
+ this.bandersnatch = bandersnatch;
32348
+ this.ed25519 = ed25519;
32349
+ this.bls = bls;
32350
+ this.metadata = metadata;
32351
+ }
32352
+ }
32709
32353
 
32354
+ ;// CONCATENATED MODULE: ./packages/jam/state/safrole-data.ts
32710
32355
 
32711
32356
 
32712
32357
 
32713
32358
 
32714
32359
 
32715
- class InMemoryStateView {
32716
- chainSpec;
32717
- state;
32718
- constructor(chainSpec, state) {
32719
- this.chainSpec = chainSpec;
32720
- this.state = state;
32721
- }
32722
- availabilityAssignmentView() {
32723
- return reencodeAsView(availabilityAssignmentsCodec, this.state.availabilityAssignment, this.chainSpec);
32724
- }
32725
- designatedValidatorDataView() {
32726
- return reencodeAsView(validatorsDataCodec, this.state.designatedValidatorData, this.chainSpec);
32727
- }
32728
- currentValidatorDataView() {
32729
- return reencodeAsView(validatorsDataCodec, this.state.currentValidatorData, this.chainSpec);
32730
- }
32731
- previousValidatorDataView() {
32732
- return reencodeAsView(validatorsDataCodec, this.state.previousValidatorData, this.chainSpec);
32733
- }
32734
- authPoolsView() {
32735
- return reencodeAsView(authPoolsCodec, this.state.authPools, this.chainSpec);
32736
- }
32737
- authQueuesView() {
32738
- return reencodeAsView(authQueuesCodec, this.state.authQueues, this.chainSpec);
32739
- }
32740
- recentBlocksView() {
32741
- return reencodeAsView(RecentBlocks.Codec, this.state.recentBlocks, this.chainSpec);
32742
- }
32743
- statisticsView() {
32744
- return reencodeAsView(StatisticsData.Codec, this.state.statistics, this.chainSpec);
32745
- }
32746
- accumulationQueueView() {
32747
- return reencodeAsView(accumulationQueueCodec, this.state.accumulationQueue, this.chainSpec);
32748
- }
32749
- recentlyAccumulatedView() {
32750
- return reencodeAsView(recentlyAccumulatedCodec, this.state.recentlyAccumulated, this.chainSpec);
32751
- }
32752
- safroleDataView() {
32753
- // TODO [ToDr] Consider exposting `safrole` from state
32754
- // instead of individual fields
32755
- const safrole = safrole_data_SafroleData.create({
32756
- nextValidatorData: this.state.nextValidatorData,
32757
- epochRoot: this.state.epochRoot,
32758
- sealingKeySeries: this.state.sealingKeySeries,
32759
- ticketsAccumulator: this.state.ticketsAccumulator,
32760
- });
32761
- return reencodeAsView(safrole_data_SafroleData.Codec, safrole, this.chainSpec);
32762
- }
32763
- getServiceInfoView(id) {
32764
- const service = this.state.getService(id);
32765
- if (service === null) {
32766
- return null;
32767
- }
32768
- return reencodeAsView(ServiceAccountInfo.Codec, service.getInfo(), this.chainSpec);
32769
- }
32770
- }
32771
32360
 
32772
- ;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
32773
32361
 
32774
32362
 
32775
32363
 
32776
32364
 
32777
32365
 
32778
- /** Dictionary entry of services that auto-accumulate every block. */
32779
- class AutoAccumulate {
32780
- service;
32781
- gasLimit;
32782
- static Codec = descriptors_codec.Class(AutoAccumulate, {
32783
- service: descriptors_codec.u32.asOpaque(),
32784
- gasLimit: descriptors_codec.u64.asOpaque(),
32366
+ var SafroleSealingKeysKind;
32367
+ (function (SafroleSealingKeysKind) {
32368
+ SafroleSealingKeysKind[SafroleSealingKeysKind["Tickets"] = 0] = "Tickets";
32369
+ SafroleSealingKeysKind[SafroleSealingKeysKind["Keys"] = 1] = "Keys";
32370
+ })(SafroleSealingKeysKind || (SafroleSealingKeysKind = {}));
32371
+ const codecBandersnatchKey = descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque();
32372
+ class SafroleSealingKeysData extends WithDebug {
32373
+ kind;
32374
+ keys;
32375
+ tickets;
32376
+ static Codec = codecWithContext((context) => {
32377
+ return descriptors_codec.custom({
32378
+ name: "SafroleSealingKeys",
32379
+ sizeHint: { bytes: 1 + hash_HASH_SIZE * context.epochLength, isExact: false },
32380
+ }, (e, x) => {
32381
+ e.varU32(numbers_tryAsU32(x.kind));
32382
+ if (x.kind === SafroleSealingKeysKind.Keys) {
32383
+ e.sequenceFixLen(codecBandersnatchKey, x.keys);
32384
+ }
32385
+ else {
32386
+ e.sequenceFixLen(Ticket.Codec, x.tickets);
32387
+ }
32388
+ }, (d) => {
32389
+ const epochLength = context.epochLength;
32390
+ const kind = d.varU32();
32391
+ if (kind === SafroleSealingKeysKind.Keys) {
32392
+ const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
32393
+ return SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
32394
+ }
32395
+ if (kind === SafroleSealingKeysKind.Tickets) {
32396
+ const tickets = d.sequenceFixLen(Ticket.Codec, epochLength);
32397
+ return SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
32398
+ }
32399
+ throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
32400
+ }, (s) => {
32401
+ const kind = s.decoder.varU32();
32402
+ if (kind === SafroleSealingKeysKind.Keys) {
32403
+ s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
32404
+ return;
32405
+ }
32406
+ if (kind === SafroleSealingKeysKind.Tickets) {
32407
+ s.sequenceFixLen(Ticket.Codec, context.epochLength);
32408
+ return;
32409
+ }
32410
+ throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
32411
+ });
32785
32412
  });
32786
- static create({ service, gasLimit }) {
32787
- return new AutoAccumulate(service, gasLimit);
32413
+ static keys(keys) {
32414
+ return new SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
32788
32415
  }
32789
- constructor(
32790
- /** Service id that auto-accumulates. */
32791
- service,
32792
- /** Gas limit for auto-accumulation. */
32793
- gasLimit) {
32794
- this.service = service;
32795
- this.gasLimit = gasLimit;
32416
+ static tickets(tickets) {
32417
+ return new SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
32418
+ }
32419
+ constructor(kind, keys, tickets) {
32420
+ super();
32421
+ this.kind = kind;
32422
+ this.keys = keys;
32423
+ this.tickets = tickets;
32796
32424
  }
32797
32425
  }
32798
- /**
32799
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
32800
- */
32801
- class PrivilegedServices {
32802
- manager;
32803
- delegator;
32804
- registrar;
32805
- assigners;
32806
- autoAccumulateServices;
32807
- /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
32808
- static Codec = descriptors_codec.Class(PrivilegedServices, {
32809
- manager: descriptors_codec.u32.asOpaque(),
32810
- assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
32811
- delegator: descriptors_codec.u32.asOpaque(),
32812
- registrar: compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1)
32813
- ? descriptors_codec.u32.asOpaque()
32814
- : ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
32815
- autoAccumulateServices: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
32426
+ class safrole_data_SafroleData {
32427
+ nextValidatorData;
32428
+ epochRoot;
32429
+ sealingKeySeries;
32430
+ ticketsAccumulator;
32431
+ static Codec = descriptors_codec.Class(safrole_data_SafroleData, {
32432
+ nextValidatorData: codecPerValidator(ValidatorData.Codec),
32433
+ epochRoot: descriptors_codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
32434
+ sealingKeySeries: SafroleSealingKeysData.Codec,
32435
+ ticketsAccumulator: readonlyArray(descriptors_codec.sequenceVarLen(Ticket.Codec)).convert(seeThrough, sized_array_asKnownSize),
32816
32436
  });
32817
- static create(a) {
32818
- return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
32437
+ static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
32438
+ return new safrole_data_SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
32819
32439
  }
32820
32440
  constructor(
32821
- /**
32822
- * `χ_M`: Manages alteration of χ from block to block,
32823
- * as well as bestow services with storage deposit credits.
32824
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
32825
- */
32826
- manager,
32827
- /** `χ_V`: Managers validator keys. */
32828
- delegator,
32829
- /**
32830
- * `χ_R`: Manages the creation of services in protected range.
32831
- *
32832
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
32833
- */
32834
- registrar,
32835
- /** `χ_A`: Manages authorization queue one for each core. */
32836
- assigners,
32837
- /** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
32838
- autoAccumulateServices) {
32839
- this.manager = manager;
32840
- this.delegator = delegator;
32841
- this.registrar = registrar;
32842
- this.assigners = assigners;
32843
- this.autoAccumulateServices = autoAccumulateServices;
32441
+ /** gamma_k */
32442
+ nextValidatorData,
32443
+ /** gamma_z */
32444
+ epochRoot,
32445
+ /** gamma_s */
32446
+ sealingKeySeries,
32447
+ /** gamma_a */
32448
+ ticketsAccumulator) {
32449
+ this.nextValidatorData = nextValidatorData;
32450
+ this.epochRoot = epochRoot;
32451
+ this.sealingKeySeries = sealingKeySeries;
32452
+ this.ticketsAccumulator = ticketsAccumulator;
32844
32453
  }
32845
32454
  }
32846
32455
 
@@ -32965,43 +32574,315 @@ class UpdateService {
32965
32574
  });
32966
32575
  }
32967
32576
  }
32968
- /** Update service storage kind. */
32969
- var state_update_UpdateStorageKind;
32970
- (function (UpdateStorageKind) {
32971
- /** Set a storage value. */
32972
- UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
32973
- /** Remove a storage value. */
32974
- UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
32975
- })(state_update_UpdateStorageKind || (state_update_UpdateStorageKind = {}));
32577
+ /** Update service storage kind. */
32578
+ var state_update_UpdateStorageKind;
32579
+ (function (UpdateStorageKind) {
32580
+ /** Set a storage value. */
32581
+ UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
32582
+ /** Remove a storage value. */
32583
+ UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
32584
+ })(state_update_UpdateStorageKind || (state_update_UpdateStorageKind = {}));
32585
+ /**
32586
+ * Update service storage item.
32587
+ *
32588
+ * Can either create/modify an entry or remove it.
32589
+ */
32590
+ class UpdateStorage {
32591
+ serviceId;
32592
+ action;
32593
+ constructor(serviceId, action) {
32594
+ this.serviceId = serviceId;
32595
+ this.action = action;
32596
+ }
32597
+ static set({ serviceId, storage }) {
32598
+ return new UpdateStorage(serviceId, { kind: state_update_UpdateStorageKind.Set, storage });
32599
+ }
32600
+ static remove({ serviceId, key }) {
32601
+ return new UpdateStorage(serviceId, { kind: state_update_UpdateStorageKind.Remove, key });
32602
+ }
32603
+ get key() {
32604
+ if (this.action.kind === state_update_UpdateStorageKind.Remove) {
32605
+ return this.action.key;
32606
+ }
32607
+ return this.action.storage.key;
32608
+ }
32609
+ get value() {
32610
+ if (this.action.kind === state_update_UpdateStorageKind.Remove) {
32611
+ return null;
32612
+ }
32613
+ return this.action.storage.value;
32614
+ }
32615
+ }
32616
+
32617
+ ;// CONCATENATED MODULE: ./packages/jam/state/statistics.ts
32618
+
32619
+
32620
+
32621
+
32622
+
32623
+
32624
+ const codecServiceId = compatibility_Compatibility.isSuite(TestSuite.W3F_DAVXY) || compatibility_Compatibility.isSuite(TestSuite.JAMDUNA, compatibility_GpVersion.V0_6_7)
32625
+ ? descriptors_codec.u32.asOpaque()
32626
+ : descriptors_codec.varU32.convert((s) => numbers_tryAsU32(s), (i) => tryAsServiceId(i));
32627
+ /**
32628
+ * Activity Record of a single validator.
32629
+ *
32630
+ * https://graypaper.fluffylabs.dev/#/579bd12/183701183701
32631
+ */
32632
+ class ValidatorStatistics {
32633
+ blocks;
32634
+ tickets;
32635
+ preImages;
32636
+ preImagesSize;
32637
+ guarantees;
32638
+ assurances;
32639
+ static Codec = descriptors_codec.Class(ValidatorStatistics, {
32640
+ blocks: descriptors_codec.u32,
32641
+ tickets: descriptors_codec.u32,
32642
+ preImages: descriptors_codec.u32,
32643
+ preImagesSize: descriptors_codec.u32,
32644
+ guarantees: descriptors_codec.u32,
32645
+ assurances: descriptors_codec.u32,
32646
+ });
32647
+ static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
32648
+ return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
32649
+ }
32650
+ constructor(
32651
+ /** The number of blocks produced by the validator. */
32652
+ blocks,
32653
+ /** The number of tickets introduced by the validator. */
32654
+ tickets,
32655
+ /** The number of preimages introduced by the validator. */
32656
+ preImages,
32657
+ /** The total number of octets across all preimages introduced by the validator. */
32658
+ preImagesSize,
32659
+ /** The number of reports guaranteed by the validator. */
32660
+ guarantees,
32661
+ /** The number of availability assurances made by the validator. */
32662
+ assurances) {
32663
+ this.blocks = blocks;
32664
+ this.tickets = tickets;
32665
+ this.preImages = preImages;
32666
+ this.preImagesSize = preImagesSize;
32667
+ this.guarantees = guarantees;
32668
+ this.assurances = assurances;
32669
+ }
32670
+ static empty() {
32671
+ const zero = numbers_tryAsU32(0);
32672
+ return new ValidatorStatistics(zero, zero, zero, zero, zero, zero);
32673
+ }
32674
+ }
32675
+ const codecVarU16 = descriptors_codec.varU32.convert((i) => numbers_tryAsU32(i), (o) => numbers_tryAsU16(o));
32676
+ /** Encode/decode unsigned gas. */
32677
+ const codecVarGas = descriptors_codec.varU64.convert((g) => tryAsU64(g), (i) => tryAsServiceGas(i));
32678
+ /**
32679
+ * Single core statistics.
32680
+ * Updated per block, based on incoming work reports (`w`).
32681
+ *
32682
+ * https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
32683
+ * https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
32684
+ */
32685
+ class CoreStatistics {
32686
+ dataAvailabilityLoad;
32687
+ popularity;
32688
+ imports;
32689
+ exports;
32690
+ extrinsicSize;
32691
+ extrinsicCount;
32692
+ bundleSize;
32693
+ gasUsed;
32694
+ static Codec = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_0)
32695
+ ? descriptors_codec.Class(CoreStatistics, {
32696
+ dataAvailabilityLoad: descriptors_codec.varU32,
32697
+ popularity: codecVarU16,
32698
+ imports: codecVarU16,
32699
+ extrinsicCount: codecVarU16,
32700
+ extrinsicSize: descriptors_codec.varU32,
32701
+ exports: codecVarU16,
32702
+ bundleSize: descriptors_codec.varU32,
32703
+ gasUsed: codecVarGas,
32704
+ })
32705
+ : descriptors_codec.Class(CoreStatistics, {
32706
+ dataAvailabilityLoad: descriptors_codec.varU32,
32707
+ popularity: codecVarU16,
32708
+ imports: codecVarU16,
32709
+ exports: codecVarU16,
32710
+ extrinsicSize: descriptors_codec.varU32,
32711
+ extrinsicCount: codecVarU16,
32712
+ bundleSize: descriptors_codec.varU32,
32713
+ gasUsed: codecVarGas,
32714
+ });
32715
+ static create(v) {
32716
+ return new CoreStatistics(v.dataAvailabilityLoad, v.popularity, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.bundleSize, v.gasUsed);
32717
+ }
32718
+ constructor(
32719
+ /** `d` */
32720
+ dataAvailabilityLoad,
32721
+ /** `p` */
32722
+ popularity,
32723
+ /** `i` */
32724
+ imports,
32725
+ /** `e` */
32726
+ exports,
32727
+ /** `z` */
32728
+ extrinsicSize,
32729
+ /** `x` */
32730
+ extrinsicCount,
32731
+ /** `b` */
32732
+ bundleSize,
32733
+ /** `u` */
32734
+ gasUsed) {
32735
+ this.dataAvailabilityLoad = dataAvailabilityLoad;
32736
+ this.popularity = popularity;
32737
+ this.imports = imports;
32738
+ this.exports = exports;
32739
+ this.extrinsicSize = extrinsicSize;
32740
+ this.extrinsicCount = extrinsicCount;
32741
+ this.bundleSize = bundleSize;
32742
+ this.gasUsed = gasUsed;
32743
+ }
32744
+ static empty() {
32745
+ const zero = numbers_tryAsU32(0);
32746
+ const zero16 = numbers_tryAsU16(0);
32747
+ const zeroGas = tryAsServiceGas(0);
32748
+ return new CoreStatistics(zero, zero16, zero16, zero16, zero, zero16, zero, zeroGas);
32749
+ }
32750
+ }
32976
32751
  /**
32977
- * Update service storage item.
32752
+ * Service statistics.
32753
+ * Updated per block, based on available work reports (`W`).
32978
32754
  *
32979
- * Can either create/modify an entry or remove it.
32755
+ * https://graypaper.fluffylabs.dev/#/1c979cb/199802199802?v=0.7.1
32980
32756
  */
32981
- class UpdateStorage {
32982
- serviceId;
32983
- action;
32984
- constructor(serviceId, action) {
32985
- this.serviceId = serviceId;
32986
- this.action = action;
32757
+ class ServiceStatistics {
32758
+ providedCount;
32759
+ providedSize;
32760
+ refinementCount;
32761
+ refinementGasUsed;
32762
+ imports;
32763
+ exports;
32764
+ extrinsicSize;
32765
+ extrinsicCount;
32766
+ accumulateCount;
32767
+ accumulateGasUsed;
32768
+ onTransfersCount;
32769
+ onTransfersGasUsed;
32770
+ static Codec = compatibility_Compatibility.selectIfGreaterOrEqual({
32771
+ fallback: descriptors_codec.Class(ServiceStatistics, {
32772
+ providedCount: codecVarU16,
32773
+ providedSize: descriptors_codec.varU32,
32774
+ refinementCount: descriptors_codec.varU32,
32775
+ refinementGasUsed: codecVarGas,
32776
+ imports: codecVarU16,
32777
+ exports: codecVarU16,
32778
+ extrinsicSize: descriptors_codec.varU32,
32779
+ extrinsicCount: codecVarU16,
32780
+ accumulateCount: descriptors_codec.varU32,
32781
+ accumulateGasUsed: codecVarGas,
32782
+ onTransfersCount: descriptors_codec.varU32,
32783
+ onTransfersGasUsed: codecVarGas,
32784
+ }),
32785
+ versions: {
32786
+ [compatibility_GpVersion.V0_7_0]: descriptors_codec.Class(ServiceStatistics, {
32787
+ providedCount: codecVarU16,
32788
+ providedSize: descriptors_codec.varU32,
32789
+ refinementCount: descriptors_codec.varU32,
32790
+ refinementGasUsed: codecVarGas,
32791
+ imports: codecVarU16,
32792
+ extrinsicCount: codecVarU16,
32793
+ extrinsicSize: descriptors_codec.varU32,
32794
+ exports: codecVarU16,
32795
+ accumulateCount: descriptors_codec.varU32,
32796
+ accumulateGasUsed: codecVarGas,
32797
+ onTransfersCount: descriptors_codec.varU32,
32798
+ onTransfersGasUsed: codecVarGas,
32799
+ }),
32800
+ [compatibility_GpVersion.V0_7_1]: descriptors_codec.Class(ServiceStatistics, {
32801
+ providedCount: codecVarU16,
32802
+ providedSize: descriptors_codec.varU32,
32803
+ refinementCount: descriptors_codec.varU32,
32804
+ refinementGasUsed: codecVarGas,
32805
+ imports: codecVarU16,
32806
+ extrinsicCount: codecVarU16,
32807
+ extrinsicSize: descriptors_codec.varU32,
32808
+ exports: codecVarU16,
32809
+ accumulateCount: descriptors_codec.varU32,
32810
+ accumulateGasUsed: codecVarGas,
32811
+ onTransfersCount: ignoreValueWithDefault(numbers_tryAsU32(0)),
32812
+ onTransfersGasUsed: ignoreValueWithDefault(tryAsServiceGas(0)),
32813
+ }),
32814
+ },
32815
+ });
32816
+ static create(v) {
32817
+ 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);
32987
32818
  }
32988
- static set({ serviceId, storage }) {
32989
- return new UpdateStorage(serviceId, { kind: state_update_UpdateStorageKind.Set, storage });
32819
+ constructor(
32820
+ /** `p.0` */
32821
+ providedCount,
32822
+ /** `p.1` */
32823
+ providedSize,
32824
+ /** `r.0` */
32825
+ refinementCount,
32826
+ /** `r.1` */
32827
+ refinementGasUsed,
32828
+ /** `i` */
32829
+ imports,
32830
+ /** `e` */
32831
+ exports,
32832
+ /** `z` */
32833
+ extrinsicSize,
32834
+ /** `x` */
32835
+ extrinsicCount,
32836
+ /** `a.0` */
32837
+ accumulateCount,
32838
+ /** `a.1` */
32839
+ accumulateGasUsed,
32840
+ /** `t.0` @deprecated since 0.7.1 */
32841
+ onTransfersCount,
32842
+ /** `t.1` @deprecated since 0.7.1 */
32843
+ onTransfersGasUsed) {
32844
+ this.providedCount = providedCount;
32845
+ this.providedSize = providedSize;
32846
+ this.refinementCount = refinementCount;
32847
+ this.refinementGasUsed = refinementGasUsed;
32848
+ this.imports = imports;
32849
+ this.exports = exports;
32850
+ this.extrinsicSize = extrinsicSize;
32851
+ this.extrinsicCount = extrinsicCount;
32852
+ this.accumulateCount = accumulateCount;
32853
+ this.accumulateGasUsed = accumulateGasUsed;
32854
+ this.onTransfersCount = onTransfersCount;
32855
+ this.onTransfersGasUsed = onTransfersGasUsed;
32990
32856
  }
32991
- static remove({ serviceId, key }) {
32992
- return new UpdateStorage(serviceId, { kind: state_update_UpdateStorageKind.Remove, key });
32857
+ static empty() {
32858
+ const zero = numbers_tryAsU32(0);
32859
+ const zero16 = numbers_tryAsU16(0);
32860
+ const zeroGas = tryAsServiceGas(0);
32861
+ return new ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
32993
32862
  }
32994
- get key() {
32995
- if (this.action.kind === state_update_UpdateStorageKind.Remove) {
32996
- return this.action.key;
32997
- }
32998
- return this.action.storage.key;
32863
+ }
32864
+ /** `pi`: Statistics of each validator, cores statistics and services statistics. */
32865
+ class StatisticsData {
32866
+ current;
32867
+ previous;
32868
+ cores;
32869
+ services;
32870
+ static Codec = descriptors_codec.Class(StatisticsData, {
32871
+ current: codecPerValidator(ValidatorStatistics.Codec),
32872
+ previous: codecPerValidator(ValidatorStatistics.Codec),
32873
+ cores: codecPerCore(CoreStatistics.Codec),
32874
+ services: descriptors_codec.dictionary(codecServiceId, ServiceStatistics.Codec, {
32875
+ sortKeys: (a, b) => a - b,
32876
+ }),
32877
+ });
32878
+ static create(v) {
32879
+ return new StatisticsData(v.current, v.previous, v.cores, v.services);
32999
32880
  }
33000
- get value() {
33001
- if (this.action.kind === state_update_UpdateStorageKind.Remove) {
33002
- return null;
33003
- }
33004
- return this.action.storage.value;
32881
+ constructor(current, previous, cores, services) {
32882
+ this.current = current;
32883
+ this.previous = previous;
32884
+ this.cores = cores;
32885
+ this.services = services;
33005
32886
  }
33006
32887
  }
33007
32888
 
@@ -33026,7 +32907,6 @@ class UpdateStorage {
33026
32907
 
33027
32908
 
33028
32909
 
33029
-
33030
32910
 
33031
32911
 
33032
32912
  var in_memory_state_UpdateError;
@@ -33127,11 +33007,10 @@ class InMemoryService extends WithDebug {
33127
33007
  /**
33128
33008
  * A special version of state, stored fully in-memory.
33129
33009
  */
33130
- class in_memory_state_InMemoryState extends WithDebug {
33131
- chainSpec;
33010
+ class InMemoryState extends WithDebug {
33132
33011
  /** Create a new `InMemoryState` by providing all required fields. */
33133
- static new(chainSpec, state) {
33134
- return new in_memory_state_InMemoryState(chainSpec, state);
33012
+ static create(state) {
33013
+ return new InMemoryState(state);
33135
33014
  }
33136
33015
  /**
33137
33016
  * Create a new `InMemoryState` with a partial state override.
@@ -33140,14 +33019,14 @@ class in_memory_state_InMemoryState extends WithDebug {
33140
33019
  * not-necessarily coherent values.
33141
33020
  */
33142
33021
  static partial(spec, partial) {
33143
- const state = in_memory_state_InMemoryState.empty(spec);
33022
+ const state = InMemoryState.empty(spec);
33144
33023
  Object.assign(state, partial);
33145
33024
  return state;
33146
33025
  }
33147
33026
  /**
33148
33027
  * Create a new `InMemoryState` from some other state object.
33149
33028
  */
33150
- static copyFrom(chainSpec, other, servicesData) {
33029
+ static copyFrom(other, servicesData) {
33151
33030
  const services = new Map();
33152
33031
  for (const [id, entries] of servicesData.entries()) {
33153
33032
  const service = other.getService(id);
@@ -33157,7 +33036,7 @@ class in_memory_state_InMemoryState extends WithDebug {
33157
33036
  const inMemService = InMemoryService.copyFrom(service, entries);
33158
33037
  services.set(id, inMemService);
33159
33038
  }
33160
- return in_memory_state_InMemoryState.new(chainSpec, {
33039
+ return InMemoryState.create({
33161
33040
  availabilityAssignment: other.availabilityAssignment,
33162
33041
  accumulationQueue: other.accumulationQueue,
33163
33042
  designatedValidatorData: other.designatedValidatorData,
@@ -33354,9 +33233,8 @@ class in_memory_state_InMemoryState extends WithDebug {
33354
33233
  getService(id) {
33355
33234
  return this.services.get(id) ?? null;
33356
33235
  }
33357
- constructor(chainSpec, s) {
33236
+ constructor(s) {
33358
33237
  super();
33359
- this.chainSpec = chainSpec;
33360
33238
  this.availabilityAssignment = s.availabilityAssignment;
33361
33239
  this.designatedValidatorData = s.designatedValidatorData;
33362
33240
  this.nextValidatorData = s.nextValidatorData;
@@ -33378,34 +33256,31 @@ class in_memory_state_InMemoryState extends WithDebug {
33378
33256
  this.accumulationOutputLog = s.accumulationOutputLog;
33379
33257
  this.services = s.services;
33380
33258
  }
33381
- view() {
33382
- return new InMemoryStateView(this.chainSpec, this);
33383
- }
33384
33259
  /**
33385
33260
  * Create an empty and possibly incoherent `InMemoryState`.
33386
33261
  */
33387
33262
  static empty(spec) {
33388
- return new in_memory_state_InMemoryState(spec, {
33263
+ return new InMemoryState({
33389
33264
  availabilityAssignment: tryAsPerCore(Array.from({ length: spec.coresCount }, () => null), spec),
33390
- designatedValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
33265
+ designatedValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
33391
33266
  bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
33392
33267
  bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
33393
33268
  ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
33394
33269
  metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
33395
33270
  })), spec),
33396
- nextValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
33271
+ nextValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
33397
33272
  bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
33398
33273
  bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
33399
33274
  ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
33400
33275
  metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
33401
33276
  })), spec),
33402
- currentValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
33277
+ currentValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
33403
33278
  bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
33404
33279
  bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
33405
33280
  ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
33406
33281
  metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
33407
33282
  })), spec),
33408
- previousValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
33283
+ previousValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
33409
33284
  bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
33410
33285
  bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
33411
33286
  ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
@@ -33421,7 +33296,7 @@ class in_memory_state_InMemoryState extends WithDebug {
33421
33296
  entropy: FixedSizeArray.fill(() => bytes_Bytes.zero(hash_HASH_SIZE).asOpaque(), ENTROPY_ENTRIES),
33422
33297
  authPools: tryAsPerCore(Array.from({ length: spec.coresCount }, () => sized_array_asKnownSize([])), spec),
33423
33298
  authQueues: tryAsPerCore(Array.from({ length: spec.coresCount }, () => FixedSizeArray.fill(() => bytes_Bytes.zero(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE)), spec),
33424
- recentBlocks: RecentBlocks.empty(),
33299
+ recentBlocks: RecentBlocksHistory.empty(),
33425
33300
  statistics: StatisticsData.create({
33426
33301
  current: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
33427
33302
  previous: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
@@ -33431,8 +33306,8 @@ class in_memory_state_InMemoryState extends WithDebug {
33431
33306
  accumulationQueue: tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => []), spec),
33432
33307
  recentlyAccumulated: tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => HashSet.new()), spec),
33433
33308
  ticketsAccumulator: sized_array_asKnownSize([]),
33434
- sealingKeySeries: safrole_data_SafroleSealingKeysData.keys(tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque()), spec)),
33435
- epochRoot: bytes_Bytes.zero(bandersnatch_BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
33309
+ sealingKeySeries: SafroleSealingKeysData.keys(tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque()), spec)),
33310
+ epochRoot: bytes_Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
33436
33311
  privilegedServices: PrivilegedServices.create({
33437
33312
  manager: tryAsServiceId(0),
33438
33313
  assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
@@ -33472,10 +33347,51 @@ const serviceDataCodec = descriptors_codec.dictionary(descriptors_codec.u32.asOp
33472
33347
 
33473
33348
 
33474
33349
 
33350
+ ;// CONCATENATED MODULE: ./packages/jam/state/not-yet-accumulated.ts
33351
+
33352
+
33475
33353
 
33476
33354
 
33477
33355
 
33478
33356
 
33357
+ /**
33358
+ * Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
33359
+ *
33360
+ * https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
33361
+ */
33362
+ class NotYetAccumulatedReport extends WithDebug {
33363
+ report;
33364
+ dependencies;
33365
+ static Codec = descriptors_codec.Class(NotYetAccumulatedReport, {
33366
+ report: WorkReport.Codec,
33367
+ dependencies: codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
33368
+ typicalLength: MAX_REPORT_DEPENDENCIES / 2,
33369
+ maxLength: MAX_REPORT_DEPENDENCIES,
33370
+ minLength: 0,
33371
+ }),
33372
+ });
33373
+ static create({ report, dependencies }) {
33374
+ return new NotYetAccumulatedReport(report, dependencies);
33375
+ }
33376
+ constructor(
33377
+ /**
33378
+ * Each of these were made available at most one epoch ago
33379
+ * but have or had unfulfilled dependencies.
33380
+ */
33381
+ report,
33382
+ /**
33383
+ * Alongside the work-report itself, we retain its un-accumulated
33384
+ * dependencies, a set of work-package hashes.
33385
+ *
33386
+ * https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
33387
+ */
33388
+ dependencies) {
33389
+ super();
33390
+ this.report = report;
33391
+ this.dependencies = dependencies;
33392
+ }
33393
+ }
33394
+
33479
33395
  ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialize.ts
33480
33396
 
33481
33397
 
@@ -33488,19 +33404,26 @@ const serviceDataCodec = descriptors_codec.dictionary(descriptors_codec.u32.asOp
33488
33404
 
33489
33405
 
33490
33406
 
33407
+
33408
+
33409
+
33491
33410
  /** Serialization for particular state entries. */
33492
33411
  var serialize_serialize;
33493
33412
  (function (serialize) {
33494
33413
  /** C(1): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b15013b1501?v=0.6.7 */
33495
33414
  serialize.authPools = {
33496
33415
  key: stateKeys.index(StateKeyIdx.Alpha),
33497
- Codec: authPoolsCodec,
33416
+ Codec: codecPerCore(codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
33417
+ minLength: 0,
33418
+ maxLength: MAX_AUTH_POOL_SIZE,
33419
+ typicalLength: MAX_AUTH_POOL_SIZE,
33420
+ })),
33498
33421
  extract: (s) => s.authPools,
33499
33422
  };
33500
33423
  /** C(2): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b31013b3101?v=0.6.7 */
33501
33424
  serialize.authQueues = {
33502
33425
  key: stateKeys.index(StateKeyIdx.Phi),
33503
- Codec: authQueuesCodec,
33426
+ Codec: codecPerCore(codecFixedSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE)),
33504
33427
  extract: (s) => s.authQueues,
33505
33428
  };
33506
33429
  /**
@@ -33509,7 +33432,7 @@ var serialize_serialize;
33509
33432
  */
33510
33433
  serialize.recentBlocks = {
33511
33434
  key: stateKeys.index(StateKeyIdx.Beta),
33512
- Codec: RecentBlocks.Codec,
33435
+ Codec: RecentBlocksHistory.Codec,
33513
33436
  extract: (s) => s.recentBlocks,
33514
33437
  };
33515
33438
  /** C(4): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b63013b6301?v=0.6.7 */
@@ -33538,25 +33461,25 @@ var serialize_serialize;
33538
33461
  /** C(7): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b00023b0002?v=0.6.7 */
33539
33462
  serialize.designatedValidators = {
33540
33463
  key: stateKeys.index(StateKeyIdx.Iota),
33541
- Codec: validatorsDataCodec,
33464
+ Codec: codecPerValidator(ValidatorData.Codec),
33542
33465
  extract: (s) => s.designatedValidatorData,
33543
33466
  };
33544
33467
  /** C(8): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b0d023b0d02?v=0.6.7 */
33545
33468
  serialize.currentValidators = {
33546
33469
  key: stateKeys.index(StateKeyIdx.Kappa),
33547
- Codec: validatorsDataCodec,
33470
+ Codec: codecPerValidator(ValidatorData.Codec),
33548
33471
  extract: (s) => s.currentValidatorData,
33549
33472
  };
33550
33473
  /** C(9): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b1a023b1a02?v=0.6.7 */
33551
33474
  serialize.previousValidators = {
33552
33475
  key: stateKeys.index(StateKeyIdx.Lambda),
33553
- Codec: validatorsDataCodec,
33476
+ Codec: codecPerValidator(ValidatorData.Codec),
33554
33477
  extract: (s) => s.previousValidatorData,
33555
33478
  };
33556
33479
  /** C(10): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b27023b2702?v=0.6.7 */
33557
33480
  serialize.availabilityAssignment = {
33558
33481
  key: stateKeys.index(StateKeyIdx.Rho),
33559
- Codec: availabilityAssignmentsCodec,
33482
+ Codec: codecPerCore(descriptors_codec.optional(AvailabilityAssignment.Codec)),
33560
33483
  extract: (s) => s.availabilityAssignment,
33561
33484
  };
33562
33485
  /** C(11): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b3e023b3e02?v=0.6.7 */
@@ -33580,13 +33503,13 @@ var serialize_serialize;
33580
33503
  /** C(14): https://graypaper.fluffylabs.dev/#/1c979cb/3bf0023bf002?v=0.7.1 */
33581
33504
  serialize.accumulationQueue = {
33582
33505
  key: stateKeys.index(StateKeyIdx.Omega),
33583
- Codec: accumulationQueueCodec,
33506
+ Codec: codecPerEpochBlock(readonlyArray(descriptors_codec.sequenceVarLen(NotYetAccumulatedReport.Codec))),
33584
33507
  extract: (s) => s.accumulationQueue,
33585
33508
  };
33586
33509
  /** C(15): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b96023b9602?v=0.6.7 */
33587
33510
  serialize.recentlyAccumulated = {
33588
33511
  key: stateKeys.index(StateKeyIdx.Xi),
33589
- Codec: recentlyAccumulatedCodec,
33512
+ Codec: codecPerEpochBlock(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque()).convert((x) => Array.from(x), (x) => HashSet.from(x))),
33590
33513
  extract: (s) => s.recentlyAccumulated,
33591
33514
  };
33592
33515
  /** C(16): https://graypaper.fluffylabs.dev/#/38c4e62/3b46033b4603?v=0.7.0 */
@@ -33615,7 +33538,7 @@ var serialize_serialize;
33615
33538
  /** https://graypaper.fluffylabs.dev/#/85129da/387603387603?v=0.6.3 */
33616
33539
  serialize.serviceLookupHistory = (blake2b, serviceId, hash, len) => ({
33617
33540
  key: stateKeys.serviceLookupHistory(blake2b, serviceId, hash, len),
33618
- Codec: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32)),
33541
+ Codec: readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32)),
33619
33542
  });
33620
33543
  })(serialize_serialize || (serialize_serialize = {}));
33621
33544
  /**
@@ -33627,87 +33550,6 @@ var serialize_serialize;
33627
33550
  */
33628
33551
  const dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }, (e, v) => e.bytes(bytes_Bytes.fromBlob(v.raw, v.raw.length)), (d) => bytes_BytesBlob.blobFrom(d.bytes(d.source.length - d.bytesRead()).raw), (s) => s.bytes(s.decoder.source.length - s.decoder.bytesRead()));
33629
33552
 
33630
- ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state-view.ts
33631
-
33632
-
33633
- class serialized_state_view_SerializedStateView {
33634
- spec;
33635
- backend;
33636
- recentlyUsedServices;
33637
- viewCache;
33638
- constructor(spec, backend,
33639
- /** Best-effort list of recently active services. */
33640
- recentlyUsedServices, viewCache) {
33641
- this.spec = spec;
33642
- this.backend = backend;
33643
- this.recentlyUsedServices = recentlyUsedServices;
33644
- this.viewCache = viewCache;
33645
- }
33646
- retrieveView({ key, Codec }, description) {
33647
- const cached = this.viewCache.get(key);
33648
- if (cached !== undefined) {
33649
- return cached;
33650
- }
33651
- const bytes = this.backend.get(key);
33652
- if (bytes === null) {
33653
- throw new Error(`Required state entry for ${description} is missing!. Accessing view of key: ${key}`);
33654
- }
33655
- // NOTE [ToDr] we are not using `Decoder.decodeObject` here because
33656
- // it needs to get to the end of the data (skip), yet that's expensive.
33657
- // we assume that the state data is correct and coherent anyway, so
33658
- // for performance reasons we simply create the view here.
33659
- const d = Decoder.fromBytesBlob(bytes);
33660
- d.attachContext(this.spec);
33661
- const view = Codec.View.decode(d);
33662
- this.viewCache.set(key, view);
33663
- return view;
33664
- }
33665
- availabilityAssignmentView() {
33666
- return this.retrieveView(serialize.availabilityAssignment, "availabilityAssignmentView");
33667
- }
33668
- designatedValidatorDataView() {
33669
- return this.retrieveView(serialize.designatedValidators, "designatedValidatorsView");
33670
- }
33671
- currentValidatorDataView() {
33672
- return this.retrieveView(serialize.currentValidators, "currentValidatorsView");
33673
- }
33674
- previousValidatorDataView() {
33675
- return this.retrieveView(serialize.previousValidators, "previousValidatorsView");
33676
- }
33677
- authPoolsView() {
33678
- return this.retrieveView(serialize.authPools, "authPoolsView");
33679
- }
33680
- authQueuesView() {
33681
- return this.retrieveView(serialize.authQueues, "authQueuesView");
33682
- }
33683
- recentBlocksView() {
33684
- return this.retrieveView(serialize.recentBlocks, "recentBlocksView");
33685
- }
33686
- statisticsView() {
33687
- return this.retrieveView(serialize.statistics, "statisticsView");
33688
- }
33689
- accumulationQueueView() {
33690
- return this.retrieveView(serialize.accumulationQueue, "accumulationQueueView");
33691
- }
33692
- recentlyAccumulatedView() {
33693
- return this.retrieveView(serialize.recentlyAccumulated, "recentlyAccumulatedView");
33694
- }
33695
- safroleDataView() {
33696
- return this.retrieveView(serialize.safrole, "safroleDataView");
33697
- }
33698
- getServiceInfoView(id) {
33699
- const serviceData = serialize.serviceData(id);
33700
- const bytes = this.backend.get(serviceData.key);
33701
- if (bytes === null) {
33702
- return null;
33703
- }
33704
- if (!this.recentlyUsedServices.includes(id)) {
33705
- this.recentlyUsedServices.push(id);
33706
- }
33707
- return Decoder.decodeObject(serviceData.Codec.View, bytes, this.spec);
33708
- }
33709
- }
33710
-
33711
33553
  ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
33712
33554
 
33713
33555
 
@@ -33716,8 +33558,6 @@ class serialized_state_view_SerializedStateView {
33716
33558
 
33717
33559
 
33718
33560
 
33719
-
33720
-
33721
33561
  /**
33722
33562
  * State object which reads it's entries from some backend.
33723
33563
  *
@@ -33730,7 +33570,7 @@ class serialized_state_SerializedState {
33730
33570
  spec;
33731
33571
  blake2b;
33732
33572
  backend;
33733
- recentlyUsedServices;
33573
+ _recentServiceIds;
33734
33574
  /** Create a state-like object from collection of serialized entries. */
33735
33575
  static fromStateEntries(spec, blake2b, state, recentServices = []) {
33736
33576
  return new serialized_state_SerializedState(spec, blake2b, state, recentServices);
@@ -33739,63 +33579,49 @@ class serialized_state_SerializedState {
33739
33579
  static new(spec, blake2b, db, recentServices = []) {
33740
33580
  return new serialized_state_SerializedState(spec, blake2b, db, recentServices);
33741
33581
  }
33742
- dataCache = HashDictionary.new();
33743
- viewCache = HashDictionary.new();
33744
33582
  constructor(spec, blake2b, backend,
33745
33583
  /** Best-effort list of recently active services. */
33746
- recentlyUsedServices) {
33584
+ _recentServiceIds) {
33747
33585
  this.spec = spec;
33748
33586
  this.blake2b = blake2b;
33749
33587
  this.backend = backend;
33750
- this.recentlyUsedServices = recentlyUsedServices;
33588
+ this._recentServiceIds = _recentServiceIds;
33751
33589
  }
33752
33590
  /** Comparing the serialized states, just means comparing their backends. */
33753
33591
  [TEST_COMPARE_USING]() {
33754
33592
  return this.backend;
33755
33593
  }
33756
- /** Return a non-decoding version of the state. */
33757
- view() {
33758
- return new SerializedStateView(this.spec, this.backend, this.recentlyUsedServices, this.viewCache);
33759
- }
33760
33594
  // TODO [ToDr] Temporary method to update the state,
33761
33595
  // without changing references.
33762
33596
  updateBackend(newBackend) {
33763
33597
  this.backend = newBackend;
33764
- this.dataCache = HashDictionary.new();
33765
- this.viewCache = HashDictionary.new();
33766
33598
  }
33767
33599
  recentServiceIds() {
33768
- return this.recentlyUsedServices;
33600
+ return this._recentServiceIds;
33769
33601
  }
33770
33602
  getService(id) {
33771
33603
  const serviceData = this.retrieveOptional(serialize.serviceData(id));
33772
33604
  if (serviceData === undefined) {
33773
33605
  return null;
33774
33606
  }
33775
- if (!this.recentlyUsedServices.includes(id)) {
33776
- this.recentlyUsedServices.push(id);
33607
+ if (!this._recentServiceIds.includes(id)) {
33608
+ this._recentServiceIds.push(id);
33777
33609
  }
33778
33610
  return new SerializedService(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
33779
33611
  }
33780
- retrieve(k, description) {
33781
- const data = this.retrieveOptional(k);
33782
- if (data === undefined) {
33783
- throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${k.key}`);
33612
+ retrieve({ key, Codec }, description) {
33613
+ const bytes = this.backend.get(key);
33614
+ if (bytes === null) {
33615
+ throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${key}`);
33784
33616
  }
33785
- return data;
33617
+ return Decoder.decodeObject(Codec, bytes, this.spec);
33786
33618
  }
33787
33619
  retrieveOptional({ key, Codec }) {
33788
- const cached = this.dataCache.get(key);
33789
- if (cached !== undefined) {
33790
- return cached;
33791
- }
33792
33620
  const bytes = this.backend.get(key);
33793
33621
  if (bytes === null) {
33794
33622
  return undefined;
33795
33623
  }
33796
- const data = Decoder.decodeObject(Codec, bytes, this.spec);
33797
- this.dataCache.set(key, data);
33798
- return data;
33624
+ return Decoder.decodeObject(Codec, bytes, this.spec);
33799
33625
  }
33800
33626
  get availabilityAssignment() {
33801
33627
  return this.retrieve(serialize.availabilityAssignment, "availabilityAssignment");
@@ -34910,7 +34736,6 @@ function loadState(spec, blake2b, entries) {
34910
34736
 
34911
34737
 
34912
34738
 
34913
-
34914
34739
  ;// CONCATENATED MODULE: ./packages/jam/database/leaf-db.ts
34915
34740
 
34916
34741
 
@@ -35069,7 +34894,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
35069
34894
  const lookupHistoryItemCodec = descriptors_codec.object({
35070
34895
  hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
35071
34896
  length: descriptors_codec.u32,
35072
- slots: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32.asOpaque())).convert(seeThrough, service_tryAsLookupHistorySlots),
34897
+ slots: readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32.asOpaque())).convert(seeThrough, service_tryAsLookupHistorySlots),
35073
34898
  }, "LookupHistoryItem", ({ hash, length, slots }) => new LookupHistoryItem(hash, length, slots));
35074
34899
  const lookupHistoryEntryCodec = descriptors_codec.object({
35075
34900
  key: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
@@ -35112,51 +34937,47 @@ class ServiceWithCodec extends InMemoryService {
35112
34937
  return new ServiceWithCodec(serviceId, data);
35113
34938
  }
35114
34939
  }
35115
- const in_memory_state_codec_inMemoryStateCodec = (spec) => codec.Class(class State extends InMemoryState {
35116
- static create(data) {
35117
- return InMemoryState.new(spec, data);
35118
- }
35119
- }, {
34940
+ const in_memory_state_codec_inMemoryStateCodec = descriptors_codec.Class(InMemoryState, {
35120
34941
  // alpha
35121
- authPools: serialize.authPools.Codec,
34942
+ authPools: serialize_serialize.authPools.Codec,
35122
34943
  // phi
35123
- authQueues: serialize.authQueues.Codec,
34944
+ authQueues: serialize_serialize.authQueues.Codec,
35124
34945
  // beta
35125
- recentBlocks: serialize.recentBlocks.Codec,
34946
+ recentBlocks: serialize_serialize.recentBlocks.Codec,
35126
34947
  // gamma_k
35127
34948
  nextValidatorData: codecPerValidator(ValidatorData.Codec),
35128
34949
  // gamma_z
35129
- epochRoot: codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
34950
+ epochRoot: descriptors_codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
35130
34951
  // gamma_s
35131
34952
  sealingKeySeries: SafroleSealingKeysData.Codec,
35132
34953
  // gamma_a
35133
- ticketsAccumulator: readonlyArray(codec.sequenceVarLen(Ticket.Codec)).convert((x) => x, asKnownSize),
34954
+ ticketsAccumulator: readonlyArray(descriptors_codec.sequenceVarLen(Ticket.Codec)).convert((x) => x, sized_array_asKnownSize),
35134
34955
  // psi
35135
- disputesRecords: serialize.disputesRecords.Codec,
34956
+ disputesRecords: serialize_serialize.disputesRecords.Codec,
35136
34957
  // eta
35137
- entropy: serialize.entropy.Codec,
34958
+ entropy: serialize_serialize.entropy.Codec,
35138
34959
  // iota
35139
- designatedValidatorData: serialize.designatedValidators.Codec,
34960
+ designatedValidatorData: serialize_serialize.designatedValidators.Codec,
35140
34961
  // kappa
35141
- currentValidatorData: serialize.currentValidators.Codec,
34962
+ currentValidatorData: serialize_serialize.currentValidators.Codec,
35142
34963
  // lambda
35143
- previousValidatorData: serialize.previousValidators.Codec,
34964
+ previousValidatorData: serialize_serialize.previousValidators.Codec,
35144
34965
  // rho
35145
- availabilityAssignment: serialize.availabilityAssignment.Codec,
34966
+ availabilityAssignment: serialize_serialize.availabilityAssignment.Codec,
35146
34967
  // tau
35147
- timeslot: serialize.timeslot.Codec,
34968
+ timeslot: serialize_serialize.timeslot.Codec,
35148
34969
  // chi
35149
- privilegedServices: serialize.privilegedServices.Codec,
34970
+ privilegedServices: serialize_serialize.privilegedServices.Codec,
35150
34971
  // pi
35151
- statistics: serialize.statistics.Codec,
34972
+ statistics: serialize_serialize.statistics.Codec,
35152
34973
  // omega
35153
- accumulationQueue: serialize.accumulationQueue.Codec,
34974
+ accumulationQueue: serialize_serialize.accumulationQueue.Codec,
35154
34975
  // xi
35155
- recentlyAccumulated: serialize.recentlyAccumulated.Codec,
34976
+ recentlyAccumulated: serialize_serialize.recentlyAccumulated.Codec,
35156
34977
  // theta
35157
- accumulationOutputLog: serialize.accumulationOutputLog.Codec,
34978
+ accumulationOutputLog: serialize_serialize.accumulationOutputLog.Codec,
35158
34979
  // delta
35159
- services: codec.dictionary(codec.u32.asOpaque(), ServiceWithCodec.Codec, {
34980
+ services: descriptors_codec.dictionary(descriptors_codec.u32.asOpaque(), ServiceWithCodec.Codec, {
35160
34981
  sortKeys: (a, b) => a - b,
35161
34982
  }),
35162
34983
  });
@@ -35203,7 +35024,7 @@ class InMemoryStates {
35203
35024
  }
35204
35025
  /** Insert a full state into the database. */
35205
35026
  async insertState(headerHash, state) {
35206
- const encoded = Encoder.encodeObject(inMemoryStateCodec(this.spec), state, this.spec);
35027
+ const encoded = Encoder.encodeObject(inMemoryStateCodec, state, this.spec);
35207
35028
  this.db.set(headerHash, encoded);
35208
35029
  return Result.ok(OK);
35209
35030
  }
@@ -35212,7 +35033,7 @@ class InMemoryStates {
35212
35033
  if (encodedState === undefined) {
35213
35034
  return null;
35214
35035
  }
35215
- return Decoder.decodeObject(inMemoryStateCodec(this.spec), encodedState, this.spec);
35036
+ return Decoder.decodeObject(inMemoryStateCodec, encodedState, this.spec);
35216
35037
  }
35217
35038
  }
35218
35039