@typeberry/jam 0.2.0-b6e3410 → 0.2.0-c3df163

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