@typeberry/jam 0.2.0-e767e74 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2753,7 +2753,7 @@ module.exports = __nccwpck_require__.p + "e2fdc1b646378dd96eda.js?ed25519_wasm_b
2753
2753
 
2754
2754
  /***/ }),
2755
2755
 
2756
- /***/ 566:
2756
+ /***/ 185:
2757
2757
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
2758
2758
 
2759
2759
  module.exports = __nccwpck_require__.p + "ccf8ada94096a8f232f5.js?reed_solomon_wasm_bg.wasm";
@@ -3452,7 +3452,7 @@ async function __wbg_init(module_or_path) {
3452
3452
  if (wasm !== void 0) return wasm;
3453
3453
  if (typeof module_or_path !== "undefined") if (Object.getPrototypeOf(module_or_path) === Object.prototype) ({module_or_path} = module_or_path);
3454
3454
  else console.warn("using deprecated parameters for the initialization function; pass a single object instead");
3455
- if (typeof module_or_path === "undefined") module_or_path = new URL(/* asset import */ __nccwpck_require__(566), __nccwpck_require__.b);
3455
+ if (typeof module_or_path === "undefined") module_or_path = new URL(/* asset import */ __nccwpck_require__(185), __nccwpck_require__.b);
3456
3456
  const imports = __wbg_get_imports();
3457
3457
  if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) module_or_path = fetch(module_or_path);
3458
3458
  __wbg_init_memory(imports);
@@ -4521,7 +4521,7 @@ const BANDERSNATCH_KEY_BYTES = 32;
4521
4521
  /** Bandersnatch VRF signature size */
4522
4522
  const BANDERSNATCH_VRF_SIGNATURE_BYTES = 96;
4523
4523
  /** Bandersnatch ring commitment size */
4524
- const bandersnatch_BANDERSNATCH_RING_ROOT_BYTES = 144;
4524
+ const BANDERSNATCH_RING_ROOT_BYTES = 144;
4525
4525
  /** Bandersnatch proof size */
4526
4526
  const BANDERSNATCH_PROOF_BYTES = 784;
4527
4527
  /** BLS public key size. */
@@ -6198,9 +6198,6 @@ class ObjectView {
6198
6198
  toString() {
6199
6199
  return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
6200
6200
  }
6201
- [TEST_COMPARE_USING]() {
6202
- return this.materialize();
6203
- }
6204
6201
  }
6205
6202
  /**
6206
6203
  * A lazy-evaluated decoder of a sequence.
@@ -6333,7 +6330,7 @@ const TYPICAL_DICTIONARY_LENGTH = 32;
6333
6330
  * It's not true in a general case, but should be good enough for us.
6334
6331
  *
6335
6332
  */
6336
- function descriptors_readonlyArray(desc) {
6333
+ function readonlyArray(desc) {
6337
6334
  return desc.convert((x) => {
6338
6335
  debug_check `
6339
6336
  ${Array.isArray(x)}
@@ -6495,15 +6492,7 @@ var descriptors_codec;
6495
6492
  /** Custom encoding / decoding logic. */
6496
6493
  codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
6497
6494
  /** Choose a descriptor depending on the encoding/decoding context. */
6498
- codec.select = ({ name, sizeHint, }, chooser) => {
6499
- const Self = chooser(null);
6500
- 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)
6501
- ? codec.select({
6502
- name: Self.View.name,
6503
- sizeHint: Self.View.sizeHint,
6504
- }, (ctx) => chooser(ctx).View)
6505
- : Self.View);
6506
- };
6495
+ 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);
6507
6496
  /**
6508
6497
  * A descriptor for a more complex POJO.
6509
6498
  *
@@ -7621,9 +7610,9 @@ function codecWithContext(chooser) {
7621
7610
  /** Codec for a known-size array with length validation. */
7622
7611
  const codecKnownSizeArray = (val, options, _id) => {
7623
7612
  if ("fixedLength" in options) {
7624
- return descriptors_readonlyArray(descriptors_codec.sequenceFixLen(val, options.fixedLength)).convert(seeThrough, sized_array_asKnownSize);
7613
+ return readonlyArray(descriptors_codec.sequenceFixLen(val, options.fixedLength)).convert(seeThrough, sized_array_asKnownSize);
7625
7614
  }
7626
- return descriptors_readonlyArray(descriptors_codec.sequenceVarLen(val, options)).convert(seeThrough, sized_array_asKnownSize);
7615
+ return readonlyArray(descriptors_codec.sequenceVarLen(val, options)).convert(seeThrough, sized_array_asKnownSize);
7627
7616
  };
7628
7617
  /** Codec for a fixed-size array with length validation. */
7629
7618
  const codecFixedSizeArray = (val, len) => {
@@ -7760,7 +7749,7 @@ function tryAsPerValidator(array, spec) {
7760
7749
  `;
7761
7750
  return sized_array_asKnownSize(array);
7762
7751
  }
7763
- const common_codecPerValidator = (val) => codecWithContext((context) => {
7752
+ const codecPerValidator = (val) => codecWithContext((context) => {
7764
7753
  return codecKnownSizeArray(val, {
7765
7754
  fixedLength: context.validatorsCount,
7766
7755
  });
@@ -7887,7 +7876,7 @@ class Verdict extends WithDebug {
7887
7876
  workReportHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
7888
7877
  votesEpoch: descriptors_codec.u32.asOpaque(),
7889
7878
  votes: codecWithContext((context) => {
7890
- return descriptors_readonlyArray(descriptors_codec.sequenceFixLen(Judgement.Codec, context.validatorsSuperMajority)).convert(seeThrough, sized_array_asKnownSize);
7879
+ return readonlyArray(descriptors_codec.sequenceFixLen(Judgement.Codec, context.validatorsSuperMajority)).convert(seeThrough, sized_array_asKnownSize);
7891
7880
  }),
7892
7881
  });
7893
7882
  static create({ workReportHash, votesEpoch, votes }) {
@@ -8579,7 +8568,7 @@ const WorkReportCodec = descriptors_codec.Class(WorkReportNoCodec, {
8579
8568
  authorizerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
8580
8569
  authorizationGasUsed: descriptors_codec.varU64.asOpaque(),
8581
8570
  authorizationOutput: descriptors_codec.blob,
8582
- segmentRootLookup: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
8571
+ segmentRootLookup: readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
8583
8572
  results: descriptors_codec.sequenceVarLen(WorkResult.Codec).convert((x) => x, (items) => FixedSizeArray.new(items, tryAsWorkItemsCount(items.length))),
8584
8573
  });
8585
8574
  const WorkReportCodecPre070 = descriptors_codec.Class(WorkReportNoCodec, {
@@ -8593,7 +8582,7 @@ const WorkReportCodecPre070 = descriptors_codec.Class(WorkReportNoCodec, {
8593
8582
  }),
8594
8583
  authorizerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
8595
8584
  authorizationOutput: descriptors_codec.blob,
8596
- segmentRootLookup: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
8585
+ segmentRootLookup: readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
8597
8586
  results: descriptors_codec.sequenceVarLen(WorkResult.Codec).convert((x) => x, (items) => FixedSizeArray.new(items, tryAsWorkItemsCount(items.length))),
8598
8587
  authorizationGasUsed: descriptors_codec.varU64.asOpaque(),
8599
8588
  });
@@ -8711,16 +8700,16 @@ class SignedTicket extends WithDebug {
8711
8700
  }
8712
8701
  }
8713
8702
  /** Anonymous? entry into the ticket contest. */
8714
- class tickets_Ticket extends WithDebug {
8703
+ class Ticket extends WithDebug {
8715
8704
  id;
8716
8705
  attempt;
8717
- static Codec = descriptors_codec.Class(tickets_Ticket, {
8706
+ static Codec = descriptors_codec.Class(Ticket, {
8718
8707
  id: descriptors_codec.bytes(hash_HASH_SIZE),
8719
8708
  // TODO [ToDr] we should verify that attempt is either 0|1|2.
8720
8709
  attempt: descriptors_codec.u8.asOpaque(),
8721
8710
  });
8722
8711
  static create({ id, attempt }) {
8723
- return new tickets_Ticket(id, attempt);
8712
+ return new Ticket(id, attempt);
8724
8713
  }
8725
8714
  constructor(
8726
8715
  /**
@@ -8789,7 +8778,7 @@ class ValidatorKeys extends WithDebug {
8789
8778
  class TicketsMarker extends WithDebug {
8790
8779
  tickets;
8791
8780
  static Codec = descriptors_codec.Class(TicketsMarker, {
8792
- tickets: codecPerEpochBlock(tickets_Ticket.Codec),
8781
+ tickets: codecPerEpochBlock(Ticket.Codec),
8793
8782
  });
8794
8783
  static create({ tickets }) {
8795
8784
  return new TicketsMarker(tickets);
@@ -8813,7 +8802,7 @@ class EpochMarker extends WithDebug {
8813
8802
  static Codec = descriptors_codec.Class(EpochMarker, {
8814
8803
  entropy: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
8815
8804
  ticketsEntropy: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
8816
- validators: common_codecPerValidator(ValidatorKeys.Codec),
8805
+ validators: codecPerValidator(ValidatorKeys.Codec),
8817
8806
  });
8818
8807
  static create({ entropy, ticketsEntropy, validators }) {
8819
8808
  return new EpochMarker(entropy, ticketsEntropy, validators);
@@ -9085,19 +9074,6 @@ function emptyBlock(slot = tryAsTimeSlot(0)) {
9085
9074
  });
9086
9075
  }
9087
9076
 
9088
- ;// CONCATENATED MODULE: ./packages/jam/block/utils.ts
9089
-
9090
- /**
9091
- * Take an input data and re-encode that data as view.
9092
- *
9093
- * NOTE: this function should NEVER be used in any production code,
9094
- * it's only a test helper.
9095
- */
9096
- function reencodeAsView(codec, object, chainSpec) {
9097
- const encoded = encoder_Encoder.encodeObject(codec, object, chainSpec);
9098
- return decoder_Decoder.decodeObject(codec.View, encoded, chainSpec);
9099
- }
9100
-
9101
9077
  ;// CONCATENATED MODULE: ./packages/jam/block/index.ts
9102
9078
 
9103
9079
 
@@ -9116,7 +9092,6 @@ function reencodeAsView(codec, object, chainSpec) {
9116
9092
 
9117
9093
 
9118
9094
 
9119
-
9120
9095
  ;// CONCATENATED MODULE: ./packages/jam/database-lmdb/blocks.ts
9121
9096
 
9122
9097
 
@@ -9468,128 +9443,10 @@ function accumulationOutputComparator(a, b) {
9468
9443
  return Ordering.Equal;
9469
9444
  }
9470
9445
 
9471
- ;// CONCATENATED MODULE: ./packages/jam/block/gp-constants.ts
9472
-
9473
- /**
9474
- * This file lists all of the constants defined in the GrayPaper appendix.
9475
- *
9476
- * NOTE: Avoid using the constants directly, prefer "named" constants defined
9477
- * in a semantical proximity to where they are used.
9478
- *
9479
- * NOTE: This file will most likely be removed in the future. The constants
9480
- * here are only temporarily for convenience. When we figure out better names
9481
- * and places for these this file will be eradicated.
9482
- *
9483
- * https://graypaper.fluffylabs.dev/#/579bd12/413000413000
9484
- */
9485
- /** `G_I`: The gas allocated to invoke a work-package’s Is-Authorized logic. */
9486
- const G_I = 50_000_000;
9487
- /** `I`: Maximum number of work items in a package. */
9488
- const gp_constants_I = (/* unused pure expression or super */ null && (MAX_NUMBER_OF_WORK_ITEMS));
9489
- /** `O`: Maximum number of items in the authorizations pool. */
9490
- const O = 8;
9491
- /** `Q`: The number of items in the authorizations queue. */
9492
- const Q = 80;
9493
- /** `S`: The maximum number of entries in the accumulation queue. */
9494
- const S = 1024;
9495
- /** `T`: The maximum number of extrinsics in a work-package. */
9496
- const T = 128;
9497
- /** `W_A`: The maximum size of is-authorized code in octets. */
9498
- const W_A = 64_000;
9499
- /** `W_B`: The maximum size of an encoded work-package with extrinsic data and imports. */
9500
- const W_B = 13_794_305;
9501
- /** `W_C`: The maximum size of service code in octets. */
9502
- const W_C = 4_000_000;
9503
- /** `W_M`: The maximum number of imports in a work-package. */
9504
- const W_M = 3_072;
9505
- /** `W_R`: The maximum total size of all output blobs in a work-report, in octets. */
9506
- const W_R = 49_152;
9507
- /** `W_T`: The size of a transfer memo in octets. */
9508
- const W_T = 128;
9509
- /** `W_M`: The maximum number of exports in a work-package. */
9510
- const W_X = 3_072;
9511
- // TODO [ToDr] Not sure where these should live yet :(
9512
- /**
9513
- * `S`: The minimum public service index.
9514
- * Services of indices below these may only be created by the Registrar.
9515
- *
9516
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
9517
- */
9518
- const MIN_PUBLIC_SERVICE_INDEX = 2 ** 16;
9519
- /**
9520
- * `J`: The maximum sum of dependency items in a work-report.
9521
- *
9522
- * https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
9523
- */
9524
- const MAX_REPORT_DEPENDENCIES = 8;
9525
-
9526
- ;// CONCATENATED MODULE: ./packages/jam/state/accumulation-queue.ts
9527
-
9528
-
9529
-
9530
-
9531
-
9532
-
9533
-
9534
- /**
9535
- * Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
9536
- *
9537
- * https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
9538
- */
9539
- class NotYetAccumulatedReport extends WithDebug {
9540
- report;
9541
- dependencies;
9542
- static Codec = descriptors_codec.Class(NotYetAccumulatedReport, {
9543
- report: WorkReport.Codec,
9544
- dependencies: codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
9545
- typicalLength: MAX_REPORT_DEPENDENCIES / 2,
9546
- maxLength: MAX_REPORT_DEPENDENCIES,
9547
- minLength: 0,
9548
- }),
9549
- });
9550
- static create({ report, dependencies }) {
9551
- return new NotYetAccumulatedReport(report, dependencies);
9552
- }
9553
- constructor(
9554
- /**
9555
- * Each of these were made available at most one epoch ago
9556
- * but have or had unfulfilled dependencies.
9557
- */
9558
- report,
9559
- /**
9560
- * Alongside the work-report itself, we retain its un-accumulated
9561
- * dependencies, a set of work-package hashes.
9562
- *
9563
- * https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
9564
- */
9565
- dependencies) {
9566
- super();
9567
- this.report = report;
9568
- this.dependencies = dependencies;
9569
- }
9570
- }
9571
- const accumulationQueueCodec = codecPerEpochBlock(descriptors_readonlyArray(descriptors_codec.sequenceVarLen(NotYetAccumulatedReport.Codec)));
9572
-
9573
- ;// CONCATENATED MODULE: ./packages/jam/state/common.ts
9574
-
9575
-
9576
- /** Check if given array has correct length before casting to the opaque type. */
9577
- function tryAsPerCore(array, spec) {
9578
- debug_check `
9579
- ${array.length === spec.coresCount}
9580
- Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
9581
- `;
9582
- return opaque_asOpaqueType(array);
9583
- }
9584
- const codecPerCore = (val) => codecWithContext((context) => {
9585
- return codecKnownSizeArray(val, { fixedLength: context.coresCount });
9586
- });
9587
-
9588
9446
  ;// CONCATENATED MODULE: ./packages/jam/state/assurances.ts
9589
9447
 
9590
9448
 
9591
9449
 
9592
-
9593
9450
  /**
9594
9451
  * Assignment of particular work report to a core.
9595
9452
  *
@@ -9618,30 +9475,27 @@ class AvailabilityAssignment extends WithDebug {
9618
9475
  this.timeout = timeout;
9619
9476
  }
9620
9477
  }
9621
- const availabilityAssignmentsCodec = codecPerCore(descriptors_codec.optional(AvailabilityAssignment.Codec));
9622
-
9623
- ;// CONCATENATED MODULE: ./packages/jam/state/auth.ts
9624
-
9625
-
9626
9478
 
9479
+ ;// CONCATENATED MODULE: ./packages/jam/state/common.ts
9627
9480
 
9628
9481
 
9629
- /** `O`: Maximal authorization pool size. */
9630
- const MAX_AUTH_POOL_SIZE = O;
9631
- /** `Q`: Size of the authorization queue. */
9632
- const AUTHORIZATION_QUEUE_SIZE = Q;
9633
- const authPoolsCodec = codecPerCore(codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
9634
- minLength: 0,
9635
- maxLength: MAX_AUTH_POOL_SIZE,
9636
- typicalLength: MAX_AUTH_POOL_SIZE,
9637
- }));
9638
- const authQueuesCodec = codecPerCore(codecFixedSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE));
9482
+ /** Check if given array has correct length before casting to the opaque type. */
9483
+ function tryAsPerCore(array, spec) {
9484
+ debug_check `
9485
+ ${array.length === spec.coresCount}
9486
+ Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
9487
+ `;
9488
+ return opaque_asOpaqueType(array);
9489
+ }
9490
+ const codecPerCore = (val) => codecWithContext((context) => {
9491
+ return codecKnownSizeArray(val, { fixedLength: context.coresCount });
9492
+ });
9639
9493
 
9640
9494
  ;// CONCATENATED MODULE: ./packages/jam/state/disputes.ts
9641
9495
 
9642
9496
 
9643
9497
 
9644
- const sortedSetCodec = () => descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE))).convert((input) => input.array, (output) => {
9498
+ const sortedSetCodec = () => readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE))).convert((input) => input.array, (output) => {
9645
9499
  const typed = output.map((x) => x.asOpaque());
9646
9500
  return SortedSet.fromSortedArray(hashComparator, typed);
9647
9501
  });
@@ -9703,6 +9557,65 @@ function hashComparator(a, b) {
9703
9557
  return a.compare(b);
9704
9558
  }
9705
9559
 
9560
+ ;// CONCATENATED MODULE: ./packages/jam/block/gp-constants.ts
9561
+
9562
+ /**
9563
+ * This file lists all of the constants defined in the GrayPaper appendix.
9564
+ *
9565
+ * NOTE: Avoid using the constants directly, prefer "named" constants defined
9566
+ * in a semantical proximity to where they are used.
9567
+ *
9568
+ * NOTE: This file will most likely be removed in the future. The constants
9569
+ * here are only temporarily for convenience. When we figure out better names
9570
+ * and places for these this file will be eradicated.
9571
+ *
9572
+ * https://graypaper.fluffylabs.dev/#/579bd12/413000413000
9573
+ */
9574
+ /** `G_I`: The gas allocated to invoke a work-package’s Is-Authorized logic. */
9575
+ const G_I = 50_000_000;
9576
+ /** `I`: Maximum number of work items in a package. */
9577
+ const gp_constants_I = (/* unused pure expression or super */ null && (MAX_NUMBER_OF_WORK_ITEMS));
9578
+ /** `O`: Maximum number of items in the authorizations pool. */
9579
+ const O = 8;
9580
+ /** `Q`: The number of items in the authorizations queue. */
9581
+ const Q = 80;
9582
+ /** `S`: The maximum number of entries in the accumulation queue. */
9583
+ const S = 1024;
9584
+ /** `T`: The maximum number of extrinsics in a work-package. */
9585
+ const T = 128;
9586
+ /** `W_A`: The maximum size of is-authorized code in octets. */
9587
+ const W_A = 64_000;
9588
+ /** `W_B`: The maximum size of an encoded work-package with extrinsic data and imports. */
9589
+ const W_B = 13_794_305;
9590
+ /** `W_C`: The maximum size of service code in octets. */
9591
+ const W_C = 4_000_000;
9592
+ /** `W_M`: The maximum number of imports in a work-package. */
9593
+ const W_M = 3_072;
9594
+ /** `W_R`: The maximum total size of all output blobs in a work-report, in octets. */
9595
+ const W_R = 49_152;
9596
+ /** `W_T`: The size of a transfer memo in octets. */
9597
+ const W_T = 128;
9598
+ /** `W_M`: The maximum number of exports in a work-package. */
9599
+ const W_X = 3_072;
9600
+ // TODO [ToDr] Not sure where these should live yet :(
9601
+ /**
9602
+ * `S`: The minimum public service index.
9603
+ * Services of indices below these may only be created by the Registrar.
9604
+ *
9605
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
9606
+ */
9607
+ const MIN_PUBLIC_SERVICE_INDEX = 2 ** 16;
9608
+ /**
9609
+ * `J`: The maximum sum of dependency items in a work-report.
9610
+ *
9611
+ * https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
9612
+ */
9613
+ const MAX_REPORT_DEPENDENCIES = 8;
9614
+ /** `Q`: Size of the authorization queue. */
9615
+ const AUTHORIZATION_QUEUE_SIZE = Q;
9616
+ /** `O`: Maximal authorization pool size. */
9617
+ const MAX_AUTH_POOL_SIZE = O;
9618
+
9706
9619
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
9707
9620
  const MAX_VALUE = 4294967295;
9708
9621
  const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
@@ -9710,7 +9623,7 @@ const MIN_VALUE = -(2 ** 31);
9710
9623
  const MAX_SHIFT_U32 = 32;
9711
9624
  const MAX_SHIFT_U64 = 64n;
9712
9625
 
9713
- ;// CONCATENATED MODULE: ./packages/jam/state/recent-blocks.ts
9626
+ ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
9714
9627
 
9715
9628
 
9716
9629
 
@@ -9718,259 +9631,15 @@ const MAX_SHIFT_U64 = 64n;
9718
9631
 
9719
9632
 
9720
9633
  /**
9721
- * `H = 8`: The size of recent history, in blocks.
9634
+ * `B_S`: The basic minimum balance which all services require.
9722
9635
  *
9723
- * https://graypaper.fluffylabs.dev/#/579bd12/416300416500
9636
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
9724
9637
  */
9725
- const MAX_RECENT_HISTORY = 8;
9726
- /** Recent history of a single block. */
9727
- class BlockState extends WithDebug {
9728
- headerHash;
9729
- accumulationResult;
9730
- postStateRoot;
9731
- reported;
9732
- static Codec = descriptors_codec.Class(BlockState, {
9733
- headerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
9734
- accumulationResult: descriptors_codec.bytes(hash_HASH_SIZE),
9735
- postStateRoot: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
9736
- reported: codecHashDictionary(WorkPackageInfo.Codec, (x) => x.workPackageHash),
9737
- });
9738
- static create({ headerHash, accumulationResult, postStateRoot, reported }) {
9739
- return new BlockState(headerHash, accumulationResult, postStateRoot, reported);
9740
- }
9741
- constructor(
9742
- /** Header hash. */
9743
- headerHash,
9744
- /** Merkle mountain belt of accumulation result. */
9745
- accumulationResult,
9746
- /** Posterior state root filled in with a 1-block delay. */
9747
- postStateRoot,
9748
- /** Reported work packages (no more than number of cores). */
9749
- reported) {
9750
- super();
9751
- this.headerHash = headerHash;
9752
- this.accumulationResult = accumulationResult;
9753
- this.postStateRoot = postStateRoot;
9754
- this.reported = reported;
9755
- }
9756
- }
9638
+ const BASE_SERVICE_BALANCE = 100n;
9757
9639
  /**
9758
- * Recent history of blocks.
9640
+ * `B_I`: The additional minimum balance required per item of elective service state.
9759
9641
  *
9760
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
9761
- */
9762
- class RecentBlocks extends WithDebug {
9763
- blocks;
9764
- accumulationLog;
9765
- static Codec = descriptors_codec.Class(RecentBlocks, {
9766
- blocks: codecKnownSizeArray(BlockState.Codec, {
9767
- minLength: 0,
9768
- maxLength: MAX_RECENT_HISTORY,
9769
- typicalLength: MAX_RECENT_HISTORY,
9770
- }),
9771
- accumulationLog: descriptors_codec.object({
9772
- peaks: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.optional(descriptors_codec.bytes(hash_HASH_SIZE)))),
9773
- }),
9774
- });
9775
- static empty() {
9776
- return new RecentBlocks(sized_array_asKnownSize([]), {
9777
- peaks: [],
9778
- });
9779
- }
9780
- static create(a) {
9781
- return new RecentBlocks(a.blocks, a.accumulationLog);
9782
- }
9783
- constructor(
9784
- /**
9785
- * Most recent blocks.
9786
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fea010fea01?v=0.6.7
9787
- */
9788
- blocks,
9789
- /**
9790
- * Accumulation output log.
9791
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/0f02020f0202?v=0.6.7
9792
- */
9793
- accumulationLog) {
9794
- super();
9795
- this.blocks = blocks;
9796
- this.accumulationLog = accumulationLog;
9797
- }
9798
- }
9799
-
9800
- ;// CONCATENATED MODULE: ./packages/jam/state/recently-accumulated.ts
9801
-
9802
-
9803
-
9804
-
9805
- const recentlyAccumulatedCodec = codecPerEpochBlock(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque()).convert((x) => Array.from(x), (x) => HashSet.from(x)));
9806
-
9807
- ;// CONCATENATED MODULE: ./packages/jam/state/validator-data.ts
9808
-
9809
-
9810
-
9811
-
9812
- /**
9813
- * Fixed size of validator metadata.
9814
- *
9815
- * https://graypaper.fluffylabs.dev/#/5f542d7/0d55010d5501
9816
- */
9817
- const VALIDATOR_META_BYTES = 128;
9818
- /**
9819
- * Details about validators' identity.
9820
- *
9821
- * https://graypaper.fluffylabs.dev/#/5f542d7/0d4b010d4c01
9822
- */
9823
- class validator_data_ValidatorData extends WithDebug {
9824
- bandersnatch;
9825
- ed25519;
9826
- bls;
9827
- metadata;
9828
- static Codec = descriptors_codec.Class(validator_data_ValidatorData, {
9829
- bandersnatch: descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque(),
9830
- ed25519: descriptors_codec.bytes(ED25519_KEY_BYTES).asOpaque(),
9831
- bls: descriptors_codec.bytes(BLS_KEY_BYTES).asOpaque(),
9832
- metadata: descriptors_codec.bytes(VALIDATOR_META_BYTES),
9833
- });
9834
- static create({ ed25519, bandersnatch, bls, metadata }) {
9835
- return new validator_data_ValidatorData(bandersnatch, ed25519, bls, metadata);
9836
- }
9837
- constructor(
9838
- /** Bandersnatch public key. */
9839
- bandersnatch,
9840
- /** ED25519 key data. */
9841
- ed25519,
9842
- /** BLS public key. */
9843
- bls,
9844
- /** Validator-defined additional metdata. */
9845
- metadata) {
9846
- super();
9847
- this.bandersnatch = bandersnatch;
9848
- this.ed25519 = ed25519;
9849
- this.bls = bls;
9850
- this.metadata = metadata;
9851
- }
9852
- }
9853
- const validatorsDataCodec = common_codecPerValidator(validator_data_ValidatorData.Codec);
9854
-
9855
- ;// CONCATENATED MODULE: ./packages/jam/state/safrole-data.ts
9856
-
9857
-
9858
-
9859
-
9860
-
9861
-
9862
-
9863
-
9864
-
9865
-
9866
-
9867
- var SafroleSealingKeysKind;
9868
- (function (SafroleSealingKeysKind) {
9869
- SafroleSealingKeysKind[SafroleSealingKeysKind["Tickets"] = 0] = "Tickets";
9870
- SafroleSealingKeysKind[SafroleSealingKeysKind["Keys"] = 1] = "Keys";
9871
- })(SafroleSealingKeysKind || (SafroleSealingKeysKind = {}));
9872
- const codecBandersnatchKey = descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque();
9873
- class safrole_data_SafroleSealingKeysData extends WithDebug {
9874
- kind;
9875
- keys;
9876
- tickets;
9877
- static Codec = codecWithContext((context) => {
9878
- return descriptors_codec.custom({
9879
- name: "SafroleSealingKeys",
9880
- sizeHint: { bytes: 1 + hash_HASH_SIZE * context.epochLength, isExact: false },
9881
- }, (e, x) => {
9882
- e.varU32(numbers_tryAsU32(x.kind));
9883
- if (x.kind === SafroleSealingKeysKind.Keys) {
9884
- e.sequenceFixLen(codecBandersnatchKey, x.keys);
9885
- }
9886
- else {
9887
- e.sequenceFixLen(tickets_Ticket.Codec, x.tickets);
9888
- }
9889
- }, (d) => {
9890
- const epochLength = context.epochLength;
9891
- const kind = d.varU32();
9892
- if (kind === SafroleSealingKeysKind.Keys) {
9893
- const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
9894
- return safrole_data_SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
9895
- }
9896
- if (kind === SafroleSealingKeysKind.Tickets) {
9897
- const tickets = d.sequenceFixLen(tickets_Ticket.Codec, epochLength);
9898
- return safrole_data_SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
9899
- }
9900
- throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
9901
- }, (s) => {
9902
- const kind = s.decoder.varU32();
9903
- if (kind === SafroleSealingKeysKind.Keys) {
9904
- s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
9905
- return;
9906
- }
9907
- if (kind === SafroleSealingKeysKind.Tickets) {
9908
- s.sequenceFixLen(tickets_Ticket.Codec, context.epochLength);
9909
- return;
9910
- }
9911
- throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
9912
- });
9913
- });
9914
- static keys(keys) {
9915
- return new safrole_data_SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
9916
- }
9917
- static tickets(tickets) {
9918
- return new safrole_data_SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
9919
- }
9920
- constructor(kind, keys, tickets) {
9921
- super();
9922
- this.kind = kind;
9923
- this.keys = keys;
9924
- this.tickets = tickets;
9925
- }
9926
- }
9927
- class SafroleData {
9928
- nextValidatorData;
9929
- epochRoot;
9930
- sealingKeySeries;
9931
- ticketsAccumulator;
9932
- static Codec = descriptors_codec.Class(SafroleData, {
9933
- nextValidatorData: common_codecPerValidator(validator_data_ValidatorData.Codec),
9934
- epochRoot: descriptors_codec.bytes(bandersnatch_BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
9935
- sealingKeySeries: safrole_data_SafroleSealingKeysData.Codec,
9936
- ticketsAccumulator: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(tickets_Ticket.Codec)).convert(seeThrough, sized_array_asKnownSize),
9937
- });
9938
- static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
9939
- return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
9940
- }
9941
- constructor(
9942
- /** gamma_k */
9943
- nextValidatorData,
9944
- /** gamma_z */
9945
- epochRoot,
9946
- /** gamma_s */
9947
- sealingKeySeries,
9948
- /** gamma_a */
9949
- ticketsAccumulator) {
9950
- this.nextValidatorData = nextValidatorData;
9951
- this.epochRoot = epochRoot;
9952
- this.sealingKeySeries = sealingKeySeries;
9953
- this.ticketsAccumulator = ticketsAccumulator;
9954
- }
9955
- }
9956
-
9957
- ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
9958
-
9959
-
9960
-
9961
-
9962
-
9963
-
9964
- /**
9965
- * `B_S`: The basic minimum balance which all services require.
9966
- *
9967
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
9968
- */
9969
- const BASE_SERVICE_BALANCE = 100n;
9970
- /**
9971
- * `B_I`: The additional minimum balance required per item of elective service state.
9972
- *
9973
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
9642
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
9974
9643
  */
9975
9644
  const ELECTIVE_ITEM_BALANCE = 10n;
9976
9645
  /**
@@ -10144,418 +9813,358 @@ class LookupHistoryItem {
10144
9813
  }
10145
9814
  }
10146
9815
 
10147
- ;// CONCATENATED MODULE: ./packages/jam/state/statistics.ts
10148
-
9816
+ ;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
10149
9817
 
10150
9818
 
10151
9819
 
10152
9820
 
10153
9821
 
10154
- const codecServiceId = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
10155
- ? descriptors_codec.u32.asOpaque()
10156
- : descriptors_codec.varU32.convert((s) => numbers_tryAsU32(s), (i) => tryAsServiceId(i));
10157
- /**
10158
- * Activity Record of a single validator.
10159
- *
10160
- * https://graypaper.fluffylabs.dev/#/579bd12/183701183701
10161
- */
10162
- class ValidatorStatistics {
10163
- blocks;
10164
- tickets;
10165
- preImages;
10166
- preImagesSize;
10167
- guarantees;
10168
- assurances;
10169
- static Codec = descriptors_codec.Class(ValidatorStatistics, {
10170
- blocks: descriptors_codec.u32,
10171
- tickets: descriptors_codec.u32,
10172
- preImages: descriptors_codec.u32,
10173
- preImagesSize: descriptors_codec.u32,
10174
- guarantees: descriptors_codec.u32,
10175
- assurances: descriptors_codec.u32,
9822
+ /** Dictionary entry of services that auto-accumulate every block. */
9823
+ class AutoAccumulate {
9824
+ service;
9825
+ gasLimit;
9826
+ static Codec = descriptors_codec.Class(AutoAccumulate, {
9827
+ service: descriptors_codec.u32.asOpaque(),
9828
+ gasLimit: descriptors_codec.u64.asOpaque(),
10176
9829
  });
10177
- static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
10178
- return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
9830
+ static create({ service, gasLimit }) {
9831
+ return new AutoAccumulate(service, gasLimit);
10179
9832
  }
10180
9833
  constructor(
10181
- /** The number of blocks produced by the validator. */
10182
- blocks,
10183
- /** The number of tickets introduced by the validator. */
10184
- tickets,
10185
- /** The number of preimages introduced by the validator. */
10186
- preImages,
10187
- /** The total number of octets across all preimages introduced by the validator. */
10188
- preImagesSize,
10189
- /** The number of reports guaranteed by the validator. */
10190
- guarantees,
10191
- /** The number of availability assurances made by the validator. */
10192
- assurances) {
10193
- this.blocks = blocks;
10194
- this.tickets = tickets;
10195
- this.preImages = preImages;
10196
- this.preImagesSize = preImagesSize;
10197
- this.guarantees = guarantees;
10198
- this.assurances = assurances;
10199
- }
10200
- static empty() {
10201
- const zero = numbers_tryAsU32(0);
10202
- return new ValidatorStatistics(zero, zero, zero, zero, zero, zero);
9834
+ /** Service id that auto-accumulates. */
9835
+ service,
9836
+ /** Gas limit for auto-accumulation. */
9837
+ gasLimit) {
9838
+ this.service = service;
9839
+ this.gasLimit = gasLimit;
10203
9840
  }
10204
9841
  }
10205
- const codecVarU16 = descriptors_codec.varU32.convert((i) => numbers_tryAsU32(i), (o) => numbers_tryAsU16(o));
10206
- /** Encode/decode unsigned gas. */
10207
- const codecVarGas = descriptors_codec.varU64.convert((g) => numbers_tryAsU64(g), (i) => tryAsServiceGas(i));
10208
9842
  /**
10209
- * Single core statistics.
10210
- * Updated per block, based on incoming work reports (`w`).
10211
- *
10212
- * https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
10213
- * https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
9843
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
10214
9844
  */
10215
- class CoreStatistics {
10216
- dataAvailabilityLoad;
10217
- popularity;
10218
- imports;
10219
- exports;
10220
- extrinsicSize;
10221
- extrinsicCount;
10222
- bundleSize;
10223
- gasUsed;
10224
- static Codec = Compatibility.isGreaterOrEqual(GpVersion.V0_7_0)
10225
- ? descriptors_codec.Class(CoreStatistics, {
10226
- dataAvailabilityLoad: descriptors_codec.varU32,
10227
- popularity: codecVarU16,
10228
- imports: codecVarU16,
10229
- extrinsicCount: codecVarU16,
10230
- extrinsicSize: descriptors_codec.varU32,
10231
- exports: codecVarU16,
10232
- bundleSize: descriptors_codec.varU32,
10233
- gasUsed: codecVarGas,
10234
- })
10235
- : descriptors_codec.Class(CoreStatistics, {
10236
- dataAvailabilityLoad: descriptors_codec.varU32,
10237
- popularity: codecVarU16,
10238
- imports: codecVarU16,
10239
- exports: codecVarU16,
10240
- extrinsicSize: descriptors_codec.varU32,
10241
- extrinsicCount: codecVarU16,
10242
- bundleSize: descriptors_codec.varU32,
10243
- gasUsed: codecVarGas,
10244
- });
10245
- static create(v) {
10246
- return new CoreStatistics(v.dataAvailabilityLoad, v.popularity, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.bundleSize, v.gasUsed);
9845
+ class PrivilegedServices {
9846
+ manager;
9847
+ delegator;
9848
+ registrar;
9849
+ assigners;
9850
+ autoAccumulateServices;
9851
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
9852
+ static Codec = descriptors_codec.Class(PrivilegedServices, {
9853
+ manager: descriptors_codec.u32.asOpaque(),
9854
+ assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
9855
+ delegator: descriptors_codec.u32.asOpaque(),
9856
+ registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
9857
+ ? descriptors_codec.u32.asOpaque()
9858
+ : ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
9859
+ autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
9860
+ });
9861
+ static create(a) {
9862
+ return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
10247
9863
  }
10248
9864
  constructor(
10249
- /** `d` */
10250
- dataAvailabilityLoad,
10251
- /** `p` */
10252
- popularity,
10253
- /** `i` */
10254
- imports,
10255
- /** `e` */
10256
- exports,
10257
- /** `z` */
10258
- extrinsicSize,
10259
- /** `x` */
10260
- extrinsicCount,
10261
- /** `b` */
10262
- bundleSize,
10263
- /** `u` */
10264
- gasUsed) {
10265
- this.dataAvailabilityLoad = dataAvailabilityLoad;
10266
- this.popularity = popularity;
10267
- this.imports = imports;
10268
- this.exports = exports;
10269
- this.extrinsicSize = extrinsicSize;
10270
- this.extrinsicCount = extrinsicCount;
10271
- this.bundleSize = bundleSize;
10272
- this.gasUsed = gasUsed;
10273
- }
10274
- static empty() {
10275
- const zero = numbers_tryAsU32(0);
10276
- const zero16 = numbers_tryAsU16(0);
10277
- const zeroGas = tryAsServiceGas(0);
10278
- return new CoreStatistics(zero, zero16, zero16, zero16, zero, zero16, zero, zeroGas);
9865
+ /**
9866
+ * `χ_M`: Manages alteration of χ from block to block,
9867
+ * as well as bestow services with storage deposit credits.
9868
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
9869
+ */
9870
+ manager,
9871
+ /** `χ_V`: Managers validator keys. */
9872
+ delegator,
9873
+ /**
9874
+ * `χ_R`: Manages the creation of services in protected range.
9875
+ *
9876
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
9877
+ */
9878
+ registrar,
9879
+ /** `χ_A`: Manages authorization queue one for each core. */
9880
+ assigners,
9881
+ /** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
9882
+ autoAccumulateServices) {
9883
+ this.manager = manager;
9884
+ this.delegator = delegator;
9885
+ this.registrar = registrar;
9886
+ this.assigners = assigners;
9887
+ this.autoAccumulateServices = autoAccumulateServices;
10279
9888
  }
10280
9889
  }
9890
+
9891
+ ;// CONCATENATED MODULE: ./packages/jam/state/recent-blocks.ts
9892
+
9893
+
9894
+
9895
+
9896
+
9897
+
10281
9898
  /**
10282
- * Service statistics.
10283
- * Updated per block, based on available work reports (`W`).
9899
+ * `H = 8`: The size of recent history, in blocks.
10284
9900
  *
10285
- * https://graypaper.fluffylabs.dev/#/1c979cb/199802199802?v=0.7.1
9901
+ * https://graypaper.fluffylabs.dev/#/579bd12/416300416500
10286
9902
  */
10287
- class ServiceStatistics {
10288
- providedCount;
10289
- providedSize;
10290
- refinementCount;
10291
- refinementGasUsed;
10292
- imports;
10293
- exports;
10294
- extrinsicSize;
10295
- extrinsicCount;
10296
- accumulateCount;
10297
- accumulateGasUsed;
10298
- onTransfersCount;
10299
- onTransfersGasUsed;
10300
- static Codec = Compatibility.selectIfGreaterOrEqual({
10301
- fallback: descriptors_codec.Class(ServiceStatistics, {
10302
- providedCount: codecVarU16,
10303
- providedSize: descriptors_codec.varU32,
10304
- refinementCount: descriptors_codec.varU32,
10305
- refinementGasUsed: codecVarGas,
10306
- imports: codecVarU16,
10307
- exports: codecVarU16,
10308
- extrinsicSize: descriptors_codec.varU32,
10309
- extrinsicCount: codecVarU16,
10310
- accumulateCount: descriptors_codec.varU32,
10311
- accumulateGasUsed: codecVarGas,
10312
- onTransfersCount: descriptors_codec.varU32,
10313
- onTransfersGasUsed: codecVarGas,
10314
- }),
10315
- versions: {
10316
- [GpVersion.V0_7_0]: descriptors_codec.Class(ServiceStatistics, {
10317
- providedCount: codecVarU16,
10318
- providedSize: descriptors_codec.varU32,
10319
- refinementCount: descriptors_codec.varU32,
10320
- refinementGasUsed: codecVarGas,
10321
- imports: codecVarU16,
10322
- extrinsicCount: codecVarU16,
10323
- extrinsicSize: descriptors_codec.varU32,
10324
- exports: codecVarU16,
10325
- accumulateCount: descriptors_codec.varU32,
10326
- accumulateGasUsed: codecVarGas,
10327
- onTransfersCount: descriptors_codec.varU32,
10328
- onTransfersGasUsed: codecVarGas,
10329
- }),
10330
- [GpVersion.V0_7_1]: descriptors_codec.Class(ServiceStatistics, {
10331
- providedCount: codecVarU16,
10332
- providedSize: descriptors_codec.varU32,
10333
- refinementCount: descriptors_codec.varU32,
10334
- refinementGasUsed: codecVarGas,
10335
- imports: codecVarU16,
10336
- extrinsicCount: codecVarU16,
10337
- extrinsicSize: descriptors_codec.varU32,
10338
- exports: codecVarU16,
10339
- accumulateCount: descriptors_codec.varU32,
10340
- accumulateGasUsed: codecVarGas,
10341
- onTransfersCount: ignoreValueWithDefault(numbers_tryAsU32(0)),
10342
- onTransfersGasUsed: ignoreValueWithDefault(tryAsServiceGas(0)),
10343
- }),
10344
- },
9903
+ const MAX_RECENT_HISTORY = 8;
9904
+ /** Recent history of a single block. */
9905
+ class BlockState extends WithDebug {
9906
+ headerHash;
9907
+ accumulationResult;
9908
+ postStateRoot;
9909
+ reported;
9910
+ static Codec = descriptors_codec.Class(BlockState, {
9911
+ headerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
9912
+ accumulationResult: descriptors_codec.bytes(hash_HASH_SIZE),
9913
+ postStateRoot: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
9914
+ reported: codecHashDictionary(WorkPackageInfo.Codec, (x) => x.workPackageHash),
10345
9915
  });
10346
- static create(v) {
10347
- 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);
9916
+ static create({ headerHash, accumulationResult, postStateRoot, reported }) {
9917
+ return new BlockState(headerHash, accumulationResult, postStateRoot, reported);
10348
9918
  }
10349
9919
  constructor(
10350
- /** `p.0` */
10351
- providedCount,
10352
- /** `p.1` */
10353
- providedSize,
10354
- /** `r.0` */
10355
- refinementCount,
10356
- /** `r.1` */
10357
- refinementGasUsed,
10358
- /** `i` */
10359
- imports,
10360
- /** `e` */
10361
- exports,
10362
- /** `z` */
10363
- extrinsicSize,
10364
- /** `x` */
10365
- extrinsicCount,
10366
- /** `a.0` */
10367
- accumulateCount,
10368
- /** `a.1` */
10369
- accumulateGasUsed,
10370
- /** `t.0` @deprecated since 0.7.1 */
10371
- onTransfersCount,
10372
- /** `t.1` @deprecated since 0.7.1 */
10373
- onTransfersGasUsed) {
10374
- this.providedCount = providedCount;
10375
- this.providedSize = providedSize;
10376
- this.refinementCount = refinementCount;
10377
- this.refinementGasUsed = refinementGasUsed;
10378
- this.imports = imports;
10379
- this.exports = exports;
10380
- this.extrinsicSize = extrinsicSize;
10381
- this.extrinsicCount = extrinsicCount;
10382
- this.accumulateCount = accumulateCount;
10383
- this.accumulateGasUsed = accumulateGasUsed;
10384
- this.onTransfersCount = onTransfersCount;
10385
- this.onTransfersGasUsed = onTransfersGasUsed;
9920
+ /** Header hash. */
9921
+ headerHash,
9922
+ /** Merkle mountain belt of accumulation result. */
9923
+ accumulationResult,
9924
+ /** Posterior state root filled in with a 1-block delay. */
9925
+ postStateRoot,
9926
+ /** Reported work packages (no more than number of cores). */
9927
+ reported) {
9928
+ super();
9929
+ this.headerHash = headerHash;
9930
+ this.accumulationResult = accumulationResult;
9931
+ this.postStateRoot = postStateRoot;
9932
+ this.reported = reported;
10386
9933
  }
10387
- static empty() {
10388
- const zero = numbers_tryAsU32(0);
10389
- const zero16 = numbers_tryAsU16(0);
10390
- const zeroGas = tryAsServiceGas(0);
10391
- return new ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
9934
+ }
9935
+ class RecentBlocks extends WithDebug {
9936
+ blocks;
9937
+ accumulationLog;
9938
+ static Codec = descriptors_codec.Class(RecentBlocks, {
9939
+ blocks: codecKnownSizeArray(BlockState.Codec, {
9940
+ minLength: 0,
9941
+ maxLength: MAX_RECENT_HISTORY,
9942
+ typicalLength: MAX_RECENT_HISTORY,
9943
+ }),
9944
+ accumulationLog: descriptors_codec.object({
9945
+ peaks: readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.optional(descriptors_codec.bytes(hash_HASH_SIZE)))),
9946
+ }),
9947
+ });
9948
+ static create(a) {
9949
+ return new RecentBlocks(a.blocks, a.accumulationLog);
9950
+ }
9951
+ constructor(
9952
+ /**
9953
+ * Most recent blocks.
9954
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fea010fea01?v=0.6.7
9955
+ */
9956
+ blocks,
9957
+ /**
9958
+ * Accumulation output log.
9959
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/0f02020f0202?v=0.6.7
9960
+ */
9961
+ accumulationLog) {
9962
+ super();
9963
+ this.blocks = blocks;
9964
+ this.accumulationLog = accumulationLog;
10392
9965
  }
10393
9966
  }
10394
- /** `pi`: Statistics of each validator, cores statistics and services statistics. */
10395
- class StatisticsData {
9967
+ /**
9968
+ * Recent history of blocks.
9969
+ *
9970
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
9971
+ */
9972
+ class RecentBlocksHistory extends WithDebug {
10396
9973
  current;
10397
- previous;
10398
- cores;
10399
- services;
10400
- static Codec = descriptors_codec.Class(StatisticsData, {
10401
- current: common_codecPerValidator(ValidatorStatistics.Codec),
10402
- previous: common_codecPerValidator(ValidatorStatistics.Codec),
10403
- cores: codecPerCore(CoreStatistics.Codec),
10404
- services: descriptors_codec.dictionary(codecServiceId, ServiceStatistics.Codec, {
10405
- sortKeys: (a, b) => a - b,
10406
- }),
9974
+ static Codec = Descriptor.new("RecentBlocksHistory", RecentBlocks.Codec.sizeHint, (encoder, value) => RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
9975
+ const recentBlocks = RecentBlocks.Codec.decode(decoder);
9976
+ return RecentBlocksHistory.create(recentBlocks);
9977
+ }, (skip) => {
9978
+ return RecentBlocks.Codec.skip(skip);
10407
9979
  });
10408
- static create(v) {
10409
- return new StatisticsData(v.current, v.previous, v.cores, v.services);
9980
+ static create(recentBlocks) {
9981
+ return new RecentBlocksHistory(recentBlocks);
10410
9982
  }
10411
- constructor(current, previous, cores, services) {
9983
+ static empty() {
9984
+ return RecentBlocksHistory.create(RecentBlocks.create({
9985
+ blocks: sized_array_asKnownSize([]),
9986
+ accumulationLog: { peaks: [] },
9987
+ }));
9988
+ }
9989
+ /**
9990
+ * Returns the block's BEEFY super peak.
9991
+ */
9992
+ static accumulationResult(block) {
9993
+ return block.accumulationResult;
9994
+ }
9995
+ constructor(current) {
9996
+ super();
10412
9997
  this.current = current;
10413
- this.previous = previous;
10414
- this.cores = cores;
10415
- this.services = services;
9998
+ }
9999
+ /** History of recent blocks with maximum size of `MAX_RECENT_HISTORY` */
10000
+ get blocks() {
10001
+ if (this.current !== null) {
10002
+ return this.current.blocks;
10003
+ }
10004
+ throw new Error("RecentBlocksHistory is in invalid state");
10005
+ }
10006
+ asCurrent() {
10007
+ if (this.current === null) {
10008
+ throw new Error("Cannot access current RecentBlocks format");
10009
+ }
10010
+ return this.current;
10011
+ }
10012
+ updateBlocks(blocks) {
10013
+ if (this.current !== null) {
10014
+ return RecentBlocksHistory.create(RecentBlocks.create({
10015
+ ...this.current,
10016
+ blocks: opaque_asOpaqueType(blocks),
10017
+ }));
10018
+ }
10019
+ throw new Error("RecentBlocksHistory is in invalid state. Cannot be updated!");
10416
10020
  }
10417
10021
  }
10418
10022
 
10419
- ;// CONCATENATED MODULE: ./packages/jam/state/in-memory-state-view.ts
10420
-
10023
+ ;// CONCATENATED MODULE: ./packages/jam/state/validator-data.ts
10421
10024
 
10422
10025
 
10423
10026
 
10027
+ /**
10028
+ * Fixed size of validator metadata.
10029
+ *
10030
+ * https://graypaper.fluffylabs.dev/#/5f542d7/0d55010d5501
10031
+ */
10032
+ const VALIDATOR_META_BYTES = 128;
10033
+ /**
10034
+ * Details about validators' identity.
10035
+ *
10036
+ * https://graypaper.fluffylabs.dev/#/5f542d7/0d4b010d4c01
10037
+ */
10038
+ class ValidatorData extends WithDebug {
10039
+ bandersnatch;
10040
+ ed25519;
10041
+ bls;
10042
+ metadata;
10043
+ static Codec = descriptors_codec.Class(ValidatorData, {
10044
+ bandersnatch: descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque(),
10045
+ ed25519: descriptors_codec.bytes(ED25519_KEY_BYTES).asOpaque(),
10046
+ bls: descriptors_codec.bytes(BLS_KEY_BYTES).asOpaque(),
10047
+ metadata: descriptors_codec.bytes(VALIDATOR_META_BYTES),
10048
+ });
10049
+ static create({ ed25519, bandersnatch, bls, metadata }) {
10050
+ return new ValidatorData(bandersnatch, ed25519, bls, metadata);
10051
+ }
10052
+ constructor(
10053
+ /** Bandersnatch public key. */
10054
+ bandersnatch,
10055
+ /** ED25519 key data. */
10056
+ ed25519,
10057
+ /** BLS public key. */
10058
+ bls,
10059
+ /** Validator-defined additional metdata. */
10060
+ metadata) {
10061
+ super();
10062
+ this.bandersnatch = bandersnatch;
10063
+ this.ed25519 = ed25519;
10064
+ this.bls = bls;
10065
+ this.metadata = metadata;
10066
+ }
10067
+ }
10424
10068
 
10069
+ ;// CONCATENATED MODULE: ./packages/jam/state/safrole-data.ts
10425
10070
 
10426
10071
 
10427
10072
 
10428
10073
 
10429
10074
 
10430
- class InMemoryStateView {
10431
- chainSpec;
10432
- state;
10433
- constructor(chainSpec, state) {
10434
- this.chainSpec = chainSpec;
10435
- this.state = state;
10436
- }
10437
- availabilityAssignmentView() {
10438
- return reencodeAsView(availabilityAssignmentsCodec, this.state.availabilityAssignment, this.chainSpec);
10439
- }
10440
- designatedValidatorDataView() {
10441
- return reencodeAsView(validatorsDataCodec, this.state.designatedValidatorData, this.chainSpec);
10442
- }
10443
- currentValidatorDataView() {
10444
- return reencodeAsView(validatorsDataCodec, this.state.currentValidatorData, this.chainSpec);
10445
- }
10446
- previousValidatorDataView() {
10447
- return reencodeAsView(validatorsDataCodec, this.state.previousValidatorData, this.chainSpec);
10448
- }
10449
- authPoolsView() {
10450
- return reencodeAsView(authPoolsCodec, this.state.authPools, this.chainSpec);
10451
- }
10452
- authQueuesView() {
10453
- return reencodeAsView(authQueuesCodec, this.state.authQueues, this.chainSpec);
10454
- }
10455
- recentBlocksView() {
10456
- return reencodeAsView(RecentBlocks.Codec, this.state.recentBlocks, this.chainSpec);
10457
- }
10458
- statisticsView() {
10459
- return reencodeAsView(StatisticsData.Codec, this.state.statistics, this.chainSpec);
10460
- }
10461
- accumulationQueueView() {
10462
- return reencodeAsView(accumulationQueueCodec, this.state.accumulationQueue, this.chainSpec);
10463
- }
10464
- recentlyAccumulatedView() {
10465
- return reencodeAsView(recentlyAccumulatedCodec, this.state.recentlyAccumulated, this.chainSpec);
10466
- }
10467
- safroleDataView() {
10468
- // TODO [ToDr] Consider exposting `safrole` from state
10469
- // instead of individual fields
10470
- const safrole = SafroleData.create({
10471
- nextValidatorData: this.state.nextValidatorData,
10472
- epochRoot: this.state.epochRoot,
10473
- sealingKeySeries: this.state.sealingKeySeries,
10474
- ticketsAccumulator: this.state.ticketsAccumulator,
10475
- });
10476
- return reencodeAsView(SafroleData.Codec, safrole, this.chainSpec);
10477
- }
10478
- getServiceInfoView(id) {
10479
- const service = this.state.getService(id);
10480
- if (service === null) {
10481
- return null;
10482
- }
10483
- return reencodeAsView(ServiceAccountInfo.Codec, service.getInfo(), this.chainSpec);
10484
- }
10485
- }
10486
10075
 
10487
- ;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
10488
10076
 
10489
10077
 
10490
10078
 
10491
10079
 
10492
10080
 
10493
- /** Dictionary entry of services that auto-accumulate every block. */
10494
- class AutoAccumulate {
10495
- service;
10496
- gasLimit;
10497
- static Codec = descriptors_codec.Class(AutoAccumulate, {
10498
- service: descriptors_codec.u32.asOpaque(),
10499
- gasLimit: descriptors_codec.u64.asOpaque(),
10081
+ var SafroleSealingKeysKind;
10082
+ (function (SafroleSealingKeysKind) {
10083
+ SafroleSealingKeysKind[SafroleSealingKeysKind["Tickets"] = 0] = "Tickets";
10084
+ SafroleSealingKeysKind[SafroleSealingKeysKind["Keys"] = 1] = "Keys";
10085
+ })(SafroleSealingKeysKind || (SafroleSealingKeysKind = {}));
10086
+ const codecBandersnatchKey = descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque();
10087
+ class SafroleSealingKeysData extends WithDebug {
10088
+ kind;
10089
+ keys;
10090
+ tickets;
10091
+ static Codec = codecWithContext((context) => {
10092
+ return descriptors_codec.custom({
10093
+ name: "SafroleSealingKeys",
10094
+ sizeHint: { bytes: 1 + hash_HASH_SIZE * context.epochLength, isExact: false },
10095
+ }, (e, x) => {
10096
+ e.varU32(numbers_tryAsU32(x.kind));
10097
+ if (x.kind === SafroleSealingKeysKind.Keys) {
10098
+ e.sequenceFixLen(codecBandersnatchKey, x.keys);
10099
+ }
10100
+ else {
10101
+ e.sequenceFixLen(Ticket.Codec, x.tickets);
10102
+ }
10103
+ }, (d) => {
10104
+ const epochLength = context.epochLength;
10105
+ const kind = d.varU32();
10106
+ if (kind === SafroleSealingKeysKind.Keys) {
10107
+ const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
10108
+ return SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
10109
+ }
10110
+ if (kind === SafroleSealingKeysKind.Tickets) {
10111
+ const tickets = d.sequenceFixLen(Ticket.Codec, epochLength);
10112
+ return SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
10113
+ }
10114
+ throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
10115
+ }, (s) => {
10116
+ const kind = s.decoder.varU32();
10117
+ if (kind === SafroleSealingKeysKind.Keys) {
10118
+ s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
10119
+ return;
10120
+ }
10121
+ if (kind === SafroleSealingKeysKind.Tickets) {
10122
+ s.sequenceFixLen(Ticket.Codec, context.epochLength);
10123
+ return;
10124
+ }
10125
+ throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
10126
+ });
10500
10127
  });
10501
- static create({ service, gasLimit }) {
10502
- return new AutoAccumulate(service, gasLimit);
10128
+ static keys(keys) {
10129
+ return new SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
10503
10130
  }
10504
- constructor(
10505
- /** Service id that auto-accumulates. */
10506
- service,
10507
- /** Gas limit for auto-accumulation. */
10508
- gasLimit) {
10509
- this.service = service;
10510
- this.gasLimit = gasLimit;
10131
+ static tickets(tickets) {
10132
+ return new SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
10133
+ }
10134
+ constructor(kind, keys, tickets) {
10135
+ super();
10136
+ this.kind = kind;
10137
+ this.keys = keys;
10138
+ this.tickets = tickets;
10511
10139
  }
10512
10140
  }
10513
- /**
10514
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
10515
- */
10516
- class PrivilegedServices {
10517
- manager;
10518
- delegator;
10519
- registrar;
10520
- assigners;
10521
- autoAccumulateServices;
10522
- /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
10523
- static Codec = descriptors_codec.Class(PrivilegedServices, {
10524
- manager: descriptors_codec.u32.asOpaque(),
10525
- assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
10526
- delegator: descriptors_codec.u32.asOpaque(),
10527
- registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
10528
- ? descriptors_codec.u32.asOpaque()
10529
- : ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
10530
- autoAccumulateServices: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
10141
+ class SafroleData {
10142
+ nextValidatorData;
10143
+ epochRoot;
10144
+ sealingKeySeries;
10145
+ ticketsAccumulator;
10146
+ static Codec = descriptors_codec.Class(SafroleData, {
10147
+ nextValidatorData: codecPerValidator(ValidatorData.Codec),
10148
+ epochRoot: descriptors_codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
10149
+ sealingKeySeries: SafroleSealingKeysData.Codec,
10150
+ ticketsAccumulator: readonlyArray(descriptors_codec.sequenceVarLen(Ticket.Codec)).convert(seeThrough, sized_array_asKnownSize),
10531
10151
  });
10532
- static create(a) {
10533
- return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
10152
+ static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
10153
+ return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
10534
10154
  }
10535
10155
  constructor(
10536
- /**
10537
- * `χ_M`: Manages alteration of χ from block to block,
10538
- * as well as bestow services with storage deposit credits.
10539
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
10540
- */
10541
- manager,
10542
- /** `χ_V`: Managers validator keys. */
10543
- delegator,
10544
- /**
10545
- * `χ_R`: Manages the creation of services in protected range.
10546
- *
10547
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
10548
- */
10549
- registrar,
10550
- /** `χ_A`: Manages authorization queue one for each core. */
10551
- assigners,
10552
- /** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
10553
- autoAccumulateServices) {
10554
- this.manager = manager;
10555
- this.delegator = delegator;
10556
- this.registrar = registrar;
10557
- this.assigners = assigners;
10558
- this.autoAccumulateServices = autoAccumulateServices;
10156
+ /** gamma_k */
10157
+ nextValidatorData,
10158
+ /** gamma_z */
10159
+ epochRoot,
10160
+ /** gamma_s */
10161
+ sealingKeySeries,
10162
+ /** gamma_a */
10163
+ ticketsAccumulator) {
10164
+ this.nextValidatorData = nextValidatorData;
10165
+ this.epochRoot = epochRoot;
10166
+ this.sealingKeySeries = sealingKeySeries;
10167
+ this.ticketsAccumulator = ticketsAccumulator;
10559
10168
  }
10560
10169
  }
10561
10170
 
@@ -10680,43 +10289,315 @@ class UpdateService {
10680
10289
  });
10681
10290
  }
10682
10291
  }
10683
- /** Update service storage kind. */
10684
- var UpdateStorageKind;
10685
- (function (UpdateStorageKind) {
10686
- /** Set a storage value. */
10687
- UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
10688
- /** Remove a storage value. */
10689
- UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
10690
- })(UpdateStorageKind || (UpdateStorageKind = {}));
10292
+ /** Update service storage kind. */
10293
+ var UpdateStorageKind;
10294
+ (function (UpdateStorageKind) {
10295
+ /** Set a storage value. */
10296
+ UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
10297
+ /** Remove a storage value. */
10298
+ UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
10299
+ })(UpdateStorageKind || (UpdateStorageKind = {}));
10300
+ /**
10301
+ * Update service storage item.
10302
+ *
10303
+ * Can either create/modify an entry or remove it.
10304
+ */
10305
+ class UpdateStorage {
10306
+ serviceId;
10307
+ action;
10308
+ constructor(serviceId, action) {
10309
+ this.serviceId = serviceId;
10310
+ this.action = action;
10311
+ }
10312
+ static set({ serviceId, storage }) {
10313
+ return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Set, storage });
10314
+ }
10315
+ static remove({ serviceId, key }) {
10316
+ return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Remove, key });
10317
+ }
10318
+ get key() {
10319
+ if (this.action.kind === UpdateStorageKind.Remove) {
10320
+ return this.action.key;
10321
+ }
10322
+ return this.action.storage.key;
10323
+ }
10324
+ get value() {
10325
+ if (this.action.kind === UpdateStorageKind.Remove) {
10326
+ return null;
10327
+ }
10328
+ return this.action.storage.value;
10329
+ }
10330
+ }
10331
+
10332
+ ;// CONCATENATED MODULE: ./packages/jam/state/statistics.ts
10333
+
10334
+
10335
+
10336
+
10337
+
10338
+
10339
+ const codecServiceId = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
10340
+ ? descriptors_codec.u32.asOpaque()
10341
+ : descriptors_codec.varU32.convert((s) => numbers_tryAsU32(s), (i) => tryAsServiceId(i));
10342
+ /**
10343
+ * Activity Record of a single validator.
10344
+ *
10345
+ * https://graypaper.fluffylabs.dev/#/579bd12/183701183701
10346
+ */
10347
+ class ValidatorStatistics {
10348
+ blocks;
10349
+ tickets;
10350
+ preImages;
10351
+ preImagesSize;
10352
+ guarantees;
10353
+ assurances;
10354
+ static Codec = descriptors_codec.Class(ValidatorStatistics, {
10355
+ blocks: descriptors_codec.u32,
10356
+ tickets: descriptors_codec.u32,
10357
+ preImages: descriptors_codec.u32,
10358
+ preImagesSize: descriptors_codec.u32,
10359
+ guarantees: descriptors_codec.u32,
10360
+ assurances: descriptors_codec.u32,
10361
+ });
10362
+ static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
10363
+ return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
10364
+ }
10365
+ constructor(
10366
+ /** The number of blocks produced by the validator. */
10367
+ blocks,
10368
+ /** The number of tickets introduced by the validator. */
10369
+ tickets,
10370
+ /** The number of preimages introduced by the validator. */
10371
+ preImages,
10372
+ /** The total number of octets across all preimages introduced by the validator. */
10373
+ preImagesSize,
10374
+ /** The number of reports guaranteed by the validator. */
10375
+ guarantees,
10376
+ /** The number of availability assurances made by the validator. */
10377
+ assurances) {
10378
+ this.blocks = blocks;
10379
+ this.tickets = tickets;
10380
+ this.preImages = preImages;
10381
+ this.preImagesSize = preImagesSize;
10382
+ this.guarantees = guarantees;
10383
+ this.assurances = assurances;
10384
+ }
10385
+ static empty() {
10386
+ const zero = numbers_tryAsU32(0);
10387
+ return new ValidatorStatistics(zero, zero, zero, zero, zero, zero);
10388
+ }
10389
+ }
10390
+ const codecVarU16 = descriptors_codec.varU32.convert((i) => numbers_tryAsU32(i), (o) => numbers_tryAsU16(o));
10391
+ /** Encode/decode unsigned gas. */
10392
+ const codecVarGas = descriptors_codec.varU64.convert((g) => numbers_tryAsU64(g), (i) => tryAsServiceGas(i));
10393
+ /**
10394
+ * Single core statistics.
10395
+ * Updated per block, based on incoming work reports (`w`).
10396
+ *
10397
+ * https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
10398
+ * https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
10399
+ */
10400
+ class CoreStatistics {
10401
+ dataAvailabilityLoad;
10402
+ popularity;
10403
+ imports;
10404
+ exports;
10405
+ extrinsicSize;
10406
+ extrinsicCount;
10407
+ bundleSize;
10408
+ gasUsed;
10409
+ static Codec = Compatibility.isGreaterOrEqual(GpVersion.V0_7_0)
10410
+ ? descriptors_codec.Class(CoreStatistics, {
10411
+ dataAvailabilityLoad: descriptors_codec.varU32,
10412
+ popularity: codecVarU16,
10413
+ imports: codecVarU16,
10414
+ extrinsicCount: codecVarU16,
10415
+ extrinsicSize: descriptors_codec.varU32,
10416
+ exports: codecVarU16,
10417
+ bundleSize: descriptors_codec.varU32,
10418
+ gasUsed: codecVarGas,
10419
+ })
10420
+ : descriptors_codec.Class(CoreStatistics, {
10421
+ dataAvailabilityLoad: descriptors_codec.varU32,
10422
+ popularity: codecVarU16,
10423
+ imports: codecVarU16,
10424
+ exports: codecVarU16,
10425
+ extrinsicSize: descriptors_codec.varU32,
10426
+ extrinsicCount: codecVarU16,
10427
+ bundleSize: descriptors_codec.varU32,
10428
+ gasUsed: codecVarGas,
10429
+ });
10430
+ static create(v) {
10431
+ return new CoreStatistics(v.dataAvailabilityLoad, v.popularity, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.bundleSize, v.gasUsed);
10432
+ }
10433
+ constructor(
10434
+ /** `d` */
10435
+ dataAvailabilityLoad,
10436
+ /** `p` */
10437
+ popularity,
10438
+ /** `i` */
10439
+ imports,
10440
+ /** `e` */
10441
+ exports,
10442
+ /** `z` */
10443
+ extrinsicSize,
10444
+ /** `x` */
10445
+ extrinsicCount,
10446
+ /** `b` */
10447
+ bundleSize,
10448
+ /** `u` */
10449
+ gasUsed) {
10450
+ this.dataAvailabilityLoad = dataAvailabilityLoad;
10451
+ this.popularity = popularity;
10452
+ this.imports = imports;
10453
+ this.exports = exports;
10454
+ this.extrinsicSize = extrinsicSize;
10455
+ this.extrinsicCount = extrinsicCount;
10456
+ this.bundleSize = bundleSize;
10457
+ this.gasUsed = gasUsed;
10458
+ }
10459
+ static empty() {
10460
+ const zero = numbers_tryAsU32(0);
10461
+ const zero16 = numbers_tryAsU16(0);
10462
+ const zeroGas = tryAsServiceGas(0);
10463
+ return new CoreStatistics(zero, zero16, zero16, zero16, zero, zero16, zero, zeroGas);
10464
+ }
10465
+ }
10691
10466
  /**
10692
- * Update service storage item.
10467
+ * Service statistics.
10468
+ * Updated per block, based on available work reports (`W`).
10693
10469
  *
10694
- * Can either create/modify an entry or remove it.
10470
+ * https://graypaper.fluffylabs.dev/#/1c979cb/199802199802?v=0.7.1
10695
10471
  */
10696
- class UpdateStorage {
10697
- serviceId;
10698
- action;
10699
- constructor(serviceId, action) {
10700
- this.serviceId = serviceId;
10701
- this.action = action;
10472
+ class ServiceStatistics {
10473
+ providedCount;
10474
+ providedSize;
10475
+ refinementCount;
10476
+ refinementGasUsed;
10477
+ imports;
10478
+ exports;
10479
+ extrinsicSize;
10480
+ extrinsicCount;
10481
+ accumulateCount;
10482
+ accumulateGasUsed;
10483
+ onTransfersCount;
10484
+ onTransfersGasUsed;
10485
+ static Codec = Compatibility.selectIfGreaterOrEqual({
10486
+ fallback: descriptors_codec.Class(ServiceStatistics, {
10487
+ providedCount: codecVarU16,
10488
+ providedSize: descriptors_codec.varU32,
10489
+ refinementCount: descriptors_codec.varU32,
10490
+ refinementGasUsed: codecVarGas,
10491
+ imports: codecVarU16,
10492
+ exports: codecVarU16,
10493
+ extrinsicSize: descriptors_codec.varU32,
10494
+ extrinsicCount: codecVarU16,
10495
+ accumulateCount: descriptors_codec.varU32,
10496
+ accumulateGasUsed: codecVarGas,
10497
+ onTransfersCount: descriptors_codec.varU32,
10498
+ onTransfersGasUsed: codecVarGas,
10499
+ }),
10500
+ versions: {
10501
+ [GpVersion.V0_7_0]: descriptors_codec.Class(ServiceStatistics, {
10502
+ providedCount: codecVarU16,
10503
+ providedSize: descriptors_codec.varU32,
10504
+ refinementCount: descriptors_codec.varU32,
10505
+ refinementGasUsed: codecVarGas,
10506
+ imports: codecVarU16,
10507
+ extrinsicCount: codecVarU16,
10508
+ extrinsicSize: descriptors_codec.varU32,
10509
+ exports: codecVarU16,
10510
+ accumulateCount: descriptors_codec.varU32,
10511
+ accumulateGasUsed: codecVarGas,
10512
+ onTransfersCount: descriptors_codec.varU32,
10513
+ onTransfersGasUsed: codecVarGas,
10514
+ }),
10515
+ [GpVersion.V0_7_1]: descriptors_codec.Class(ServiceStatistics, {
10516
+ providedCount: codecVarU16,
10517
+ providedSize: descriptors_codec.varU32,
10518
+ refinementCount: descriptors_codec.varU32,
10519
+ refinementGasUsed: codecVarGas,
10520
+ imports: codecVarU16,
10521
+ extrinsicCount: codecVarU16,
10522
+ extrinsicSize: descriptors_codec.varU32,
10523
+ exports: codecVarU16,
10524
+ accumulateCount: descriptors_codec.varU32,
10525
+ accumulateGasUsed: codecVarGas,
10526
+ onTransfersCount: ignoreValueWithDefault(numbers_tryAsU32(0)),
10527
+ onTransfersGasUsed: ignoreValueWithDefault(tryAsServiceGas(0)),
10528
+ }),
10529
+ },
10530
+ });
10531
+ static create(v) {
10532
+ 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);
10702
10533
  }
10703
- static set({ serviceId, storage }) {
10704
- return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Set, storage });
10534
+ constructor(
10535
+ /** `p.0` */
10536
+ providedCount,
10537
+ /** `p.1` */
10538
+ providedSize,
10539
+ /** `r.0` */
10540
+ refinementCount,
10541
+ /** `r.1` */
10542
+ refinementGasUsed,
10543
+ /** `i` */
10544
+ imports,
10545
+ /** `e` */
10546
+ exports,
10547
+ /** `z` */
10548
+ extrinsicSize,
10549
+ /** `x` */
10550
+ extrinsicCount,
10551
+ /** `a.0` */
10552
+ accumulateCount,
10553
+ /** `a.1` */
10554
+ accumulateGasUsed,
10555
+ /** `t.0` @deprecated since 0.7.1 */
10556
+ onTransfersCount,
10557
+ /** `t.1` @deprecated since 0.7.1 */
10558
+ onTransfersGasUsed) {
10559
+ this.providedCount = providedCount;
10560
+ this.providedSize = providedSize;
10561
+ this.refinementCount = refinementCount;
10562
+ this.refinementGasUsed = refinementGasUsed;
10563
+ this.imports = imports;
10564
+ this.exports = exports;
10565
+ this.extrinsicSize = extrinsicSize;
10566
+ this.extrinsicCount = extrinsicCount;
10567
+ this.accumulateCount = accumulateCount;
10568
+ this.accumulateGasUsed = accumulateGasUsed;
10569
+ this.onTransfersCount = onTransfersCount;
10570
+ this.onTransfersGasUsed = onTransfersGasUsed;
10705
10571
  }
10706
- static remove({ serviceId, key }) {
10707
- return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Remove, key });
10572
+ static empty() {
10573
+ const zero = numbers_tryAsU32(0);
10574
+ const zero16 = numbers_tryAsU16(0);
10575
+ const zeroGas = tryAsServiceGas(0);
10576
+ return new ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
10708
10577
  }
10709
- get key() {
10710
- if (this.action.kind === UpdateStorageKind.Remove) {
10711
- return this.action.key;
10712
- }
10713
- return this.action.storage.key;
10578
+ }
10579
+ /** `pi`: Statistics of each validator, cores statistics and services statistics. */
10580
+ class StatisticsData {
10581
+ current;
10582
+ previous;
10583
+ cores;
10584
+ services;
10585
+ static Codec = descriptors_codec.Class(StatisticsData, {
10586
+ current: codecPerValidator(ValidatorStatistics.Codec),
10587
+ previous: codecPerValidator(ValidatorStatistics.Codec),
10588
+ cores: codecPerCore(CoreStatistics.Codec),
10589
+ services: descriptors_codec.dictionary(codecServiceId, ServiceStatistics.Codec, {
10590
+ sortKeys: (a, b) => a - b,
10591
+ }),
10592
+ });
10593
+ static create(v) {
10594
+ return new StatisticsData(v.current, v.previous, v.cores, v.services);
10714
10595
  }
10715
- get value() {
10716
- if (this.action.kind === UpdateStorageKind.Remove) {
10717
- return null;
10718
- }
10719
- return this.action.storage.value;
10596
+ constructor(current, previous, cores, services) {
10597
+ this.current = current;
10598
+ this.previous = previous;
10599
+ this.cores = cores;
10600
+ this.services = services;
10720
10601
  }
10721
10602
  }
10722
10603
 
@@ -10741,7 +10622,6 @@ class UpdateStorage {
10741
10622
 
10742
10623
 
10743
10624
 
10744
-
10745
10625
 
10746
10626
 
10747
10627
  var in_memory_state_UpdateError;
@@ -10842,11 +10722,10 @@ class InMemoryService extends WithDebug {
10842
10722
  /**
10843
10723
  * A special version of state, stored fully in-memory.
10844
10724
  */
10845
- class in_memory_state_InMemoryState extends WithDebug {
10846
- chainSpec;
10725
+ class InMemoryState extends WithDebug {
10847
10726
  /** Create a new `InMemoryState` by providing all required fields. */
10848
- static new(chainSpec, state) {
10849
- return new in_memory_state_InMemoryState(chainSpec, state);
10727
+ static create(state) {
10728
+ return new InMemoryState(state);
10850
10729
  }
10851
10730
  /**
10852
10731
  * Create a new `InMemoryState` with a partial state override.
@@ -10855,14 +10734,14 @@ class in_memory_state_InMemoryState extends WithDebug {
10855
10734
  * not-necessarily coherent values.
10856
10735
  */
10857
10736
  static partial(spec, partial) {
10858
- const state = in_memory_state_InMemoryState.empty(spec);
10737
+ const state = InMemoryState.empty(spec);
10859
10738
  Object.assign(state, partial);
10860
10739
  return state;
10861
10740
  }
10862
10741
  /**
10863
10742
  * Create a new `InMemoryState` from some other state object.
10864
10743
  */
10865
- static copyFrom(chainSpec, other, servicesData) {
10744
+ static copyFrom(other, servicesData) {
10866
10745
  const services = new Map();
10867
10746
  for (const [id, entries] of servicesData.entries()) {
10868
10747
  const service = other.getService(id);
@@ -10872,7 +10751,7 @@ class in_memory_state_InMemoryState extends WithDebug {
10872
10751
  const inMemService = InMemoryService.copyFrom(service, entries);
10873
10752
  services.set(id, inMemService);
10874
10753
  }
10875
- return in_memory_state_InMemoryState.new(chainSpec, {
10754
+ return InMemoryState.create({
10876
10755
  availabilityAssignment: other.availabilityAssignment,
10877
10756
  accumulationQueue: other.accumulationQueue,
10878
10757
  designatedValidatorData: other.designatedValidatorData,
@@ -11069,9 +10948,8 @@ class in_memory_state_InMemoryState extends WithDebug {
11069
10948
  getService(id) {
11070
10949
  return this.services.get(id) ?? null;
11071
10950
  }
11072
- constructor(chainSpec, s) {
10951
+ constructor(s) {
11073
10952
  super();
11074
- this.chainSpec = chainSpec;
11075
10953
  this.availabilityAssignment = s.availabilityAssignment;
11076
10954
  this.designatedValidatorData = s.designatedValidatorData;
11077
10955
  this.nextValidatorData = s.nextValidatorData;
@@ -11093,34 +10971,31 @@ class in_memory_state_InMemoryState extends WithDebug {
11093
10971
  this.accumulationOutputLog = s.accumulationOutputLog;
11094
10972
  this.services = s.services;
11095
10973
  }
11096
- view() {
11097
- return new InMemoryStateView(this.chainSpec, this);
11098
- }
11099
10974
  /**
11100
10975
  * Create an empty and possibly incoherent `InMemoryState`.
11101
10976
  */
11102
10977
  static empty(spec) {
11103
- return new in_memory_state_InMemoryState(spec, {
10978
+ return new InMemoryState({
11104
10979
  availabilityAssignment: tryAsPerCore(Array.from({ length: spec.coresCount }, () => null), spec),
11105
- designatedValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
10980
+ designatedValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
11106
10981
  bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
11107
10982
  bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
11108
10983
  ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
11109
10984
  metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
11110
10985
  })), spec),
11111
- nextValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
10986
+ nextValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
11112
10987
  bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
11113
10988
  bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
11114
10989
  ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
11115
10990
  metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
11116
10991
  })), spec),
11117
- currentValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
10992
+ currentValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
11118
10993
  bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
11119
10994
  bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
11120
10995
  ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
11121
10996
  metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
11122
10997
  })), spec),
11123
- previousValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
10998
+ previousValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
11124
10999
  bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
11125
11000
  bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
11126
11001
  ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
@@ -11136,7 +11011,7 @@ class in_memory_state_InMemoryState extends WithDebug {
11136
11011
  entropy: FixedSizeArray.fill(() => bytes_Bytes.zero(hash_HASH_SIZE).asOpaque(), ENTROPY_ENTRIES),
11137
11012
  authPools: tryAsPerCore(Array.from({ length: spec.coresCount }, () => sized_array_asKnownSize([])), spec),
11138
11013
  authQueues: tryAsPerCore(Array.from({ length: spec.coresCount }, () => FixedSizeArray.fill(() => bytes_Bytes.zero(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE)), spec),
11139
- recentBlocks: RecentBlocks.empty(),
11014
+ recentBlocks: RecentBlocksHistory.empty(),
11140
11015
  statistics: StatisticsData.create({
11141
11016
  current: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
11142
11017
  previous: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
@@ -11146,8 +11021,8 @@ class in_memory_state_InMemoryState extends WithDebug {
11146
11021
  accumulationQueue: tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => []), spec),
11147
11022
  recentlyAccumulated: tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => HashSet.new()), spec),
11148
11023
  ticketsAccumulator: sized_array_asKnownSize([]),
11149
- sealingKeySeries: safrole_data_SafroleSealingKeysData.keys(tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque()), spec)),
11150
- epochRoot: bytes_Bytes.zero(bandersnatch_BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
11024
+ sealingKeySeries: SafroleSealingKeysData.keys(tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque()), spec)),
11025
+ epochRoot: bytes_Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
11151
11026
  privilegedServices: PrivilegedServices.create({
11152
11027
  manager: tryAsServiceId(0),
11153
11028
  assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
@@ -11187,10 +11062,51 @@ const serviceDataCodec = descriptors_codec.dictionary(descriptors_codec.u32.asOp
11187
11062
 
11188
11063
 
11189
11064
 
11065
+ ;// CONCATENATED MODULE: ./packages/jam/state/not-yet-accumulated.ts
11066
+
11067
+
11190
11068
 
11191
11069
 
11192
11070
 
11193
11071
 
11072
+ /**
11073
+ * Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
11074
+ *
11075
+ * https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
11076
+ */
11077
+ class NotYetAccumulatedReport extends WithDebug {
11078
+ report;
11079
+ dependencies;
11080
+ static Codec = descriptors_codec.Class(NotYetAccumulatedReport, {
11081
+ report: WorkReport.Codec,
11082
+ dependencies: codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
11083
+ typicalLength: MAX_REPORT_DEPENDENCIES / 2,
11084
+ maxLength: MAX_REPORT_DEPENDENCIES,
11085
+ minLength: 0,
11086
+ }),
11087
+ });
11088
+ static create({ report, dependencies }) {
11089
+ return new NotYetAccumulatedReport(report, dependencies);
11090
+ }
11091
+ constructor(
11092
+ /**
11093
+ * Each of these were made available at most one epoch ago
11094
+ * but have or had unfulfilled dependencies.
11095
+ */
11096
+ report,
11097
+ /**
11098
+ * Alongside the work-report itself, we retain its un-accumulated
11099
+ * dependencies, a set of work-package hashes.
11100
+ *
11101
+ * https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
11102
+ */
11103
+ dependencies) {
11104
+ super();
11105
+ this.report = report;
11106
+ this.dependencies = dependencies;
11107
+ }
11108
+ }
11109
+
11194
11110
  ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialize.ts
11195
11111
 
11196
11112
 
@@ -11203,19 +11119,26 @@ const serviceDataCodec = descriptors_codec.dictionary(descriptors_codec.u32.asOp
11203
11119
 
11204
11120
 
11205
11121
 
11122
+
11123
+
11124
+
11206
11125
  /** Serialization for particular state entries. */
11207
- var serialize_serialize;
11126
+ var serialize;
11208
11127
  (function (serialize) {
11209
11128
  /** C(1): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b15013b1501?v=0.6.7 */
11210
11129
  serialize.authPools = {
11211
11130
  key: stateKeys.index(StateKeyIdx.Alpha),
11212
- Codec: authPoolsCodec,
11131
+ Codec: codecPerCore(codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
11132
+ minLength: 0,
11133
+ maxLength: MAX_AUTH_POOL_SIZE,
11134
+ typicalLength: MAX_AUTH_POOL_SIZE,
11135
+ })),
11213
11136
  extract: (s) => s.authPools,
11214
11137
  };
11215
11138
  /** C(2): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b31013b3101?v=0.6.7 */
11216
11139
  serialize.authQueues = {
11217
11140
  key: stateKeys.index(StateKeyIdx.Phi),
11218
- Codec: authQueuesCodec,
11141
+ Codec: codecPerCore(codecFixedSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE)),
11219
11142
  extract: (s) => s.authQueues,
11220
11143
  };
11221
11144
  /**
@@ -11224,7 +11147,7 @@ var serialize_serialize;
11224
11147
  */
11225
11148
  serialize.recentBlocks = {
11226
11149
  key: stateKeys.index(StateKeyIdx.Beta),
11227
- Codec: RecentBlocks.Codec,
11150
+ Codec: RecentBlocksHistory.Codec,
11228
11151
  extract: (s) => s.recentBlocks,
11229
11152
  };
11230
11153
  /** C(4): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b63013b6301?v=0.6.7 */
@@ -11253,25 +11176,25 @@ var serialize_serialize;
11253
11176
  /** C(7): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b00023b0002?v=0.6.7 */
11254
11177
  serialize.designatedValidators = {
11255
11178
  key: stateKeys.index(StateKeyIdx.Iota),
11256
- Codec: validatorsDataCodec,
11179
+ Codec: codecPerValidator(ValidatorData.Codec),
11257
11180
  extract: (s) => s.designatedValidatorData,
11258
11181
  };
11259
11182
  /** C(8): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b0d023b0d02?v=0.6.7 */
11260
11183
  serialize.currentValidators = {
11261
11184
  key: stateKeys.index(StateKeyIdx.Kappa),
11262
- Codec: validatorsDataCodec,
11185
+ Codec: codecPerValidator(ValidatorData.Codec),
11263
11186
  extract: (s) => s.currentValidatorData,
11264
11187
  };
11265
11188
  /** C(9): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b1a023b1a02?v=0.6.7 */
11266
11189
  serialize.previousValidators = {
11267
11190
  key: stateKeys.index(StateKeyIdx.Lambda),
11268
- Codec: validatorsDataCodec,
11191
+ Codec: codecPerValidator(ValidatorData.Codec),
11269
11192
  extract: (s) => s.previousValidatorData,
11270
11193
  };
11271
11194
  /** C(10): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b27023b2702?v=0.6.7 */
11272
11195
  serialize.availabilityAssignment = {
11273
11196
  key: stateKeys.index(StateKeyIdx.Rho),
11274
- Codec: availabilityAssignmentsCodec,
11197
+ Codec: codecPerCore(descriptors_codec.optional(AvailabilityAssignment.Codec)),
11275
11198
  extract: (s) => s.availabilityAssignment,
11276
11199
  };
11277
11200
  /** C(11): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b3e023b3e02?v=0.6.7 */
@@ -11295,13 +11218,13 @@ var serialize_serialize;
11295
11218
  /** C(14): https://graypaper.fluffylabs.dev/#/1c979cb/3bf0023bf002?v=0.7.1 */
11296
11219
  serialize.accumulationQueue = {
11297
11220
  key: stateKeys.index(StateKeyIdx.Omega),
11298
- Codec: accumulationQueueCodec,
11221
+ Codec: codecPerEpochBlock(readonlyArray(descriptors_codec.sequenceVarLen(NotYetAccumulatedReport.Codec))),
11299
11222
  extract: (s) => s.accumulationQueue,
11300
11223
  };
11301
11224
  /** C(15): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b96023b9602?v=0.6.7 */
11302
11225
  serialize.recentlyAccumulated = {
11303
11226
  key: stateKeys.index(StateKeyIdx.Xi),
11304
- Codec: recentlyAccumulatedCodec,
11227
+ Codec: codecPerEpochBlock(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque()).convert((x) => Array.from(x), (x) => HashSet.from(x))),
11305
11228
  extract: (s) => s.recentlyAccumulated,
11306
11229
  };
11307
11230
  /** C(16): https://graypaper.fluffylabs.dev/#/38c4e62/3b46033b4603?v=0.7.0 */
@@ -11330,9 +11253,9 @@ var serialize_serialize;
11330
11253
  /** https://graypaper.fluffylabs.dev/#/85129da/387603387603?v=0.6.3 */
11331
11254
  serialize.serviceLookupHistory = (blake2b, serviceId, hash, len) => ({
11332
11255
  key: stateKeys.serviceLookupHistory(blake2b, serviceId, hash, len),
11333
- Codec: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32)),
11256
+ Codec: readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32)),
11334
11257
  });
11335
- })(serialize_serialize || (serialize_serialize = {}));
11258
+ })(serialize || (serialize = {}));
11336
11259
  /**
11337
11260
  * Just dump the entire terminal blob as-is.
11338
11261
  *
@@ -11342,87 +11265,6 @@ var serialize_serialize;
11342
11265
  */
11343
11266
  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()));
11344
11267
 
11345
- ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state-view.ts
11346
-
11347
-
11348
- class SerializedStateView {
11349
- spec;
11350
- backend;
11351
- recentlyUsedServices;
11352
- viewCache;
11353
- constructor(spec, backend,
11354
- /** Best-effort list of recently active services. */
11355
- recentlyUsedServices, viewCache) {
11356
- this.spec = spec;
11357
- this.backend = backend;
11358
- this.recentlyUsedServices = recentlyUsedServices;
11359
- this.viewCache = viewCache;
11360
- }
11361
- retrieveView({ key, Codec }, description) {
11362
- const cached = this.viewCache.get(key);
11363
- if (cached !== undefined) {
11364
- return cached;
11365
- }
11366
- const bytes = this.backend.get(key);
11367
- if (bytes === null) {
11368
- throw new Error(`Required state entry for ${description} is missing!. Accessing view of key: ${key}`);
11369
- }
11370
- // NOTE [ToDr] we are not using `Decoder.decodeObject` here because
11371
- // it needs to get to the end of the data (skip), yet that's expensive.
11372
- // we assume that the state data is correct and coherent anyway, so
11373
- // for performance reasons we simply create the view here.
11374
- const d = decoder_Decoder.fromBytesBlob(bytes);
11375
- d.attachContext(this.spec);
11376
- const view = Codec.View.decode(d);
11377
- this.viewCache.set(key, view);
11378
- return view;
11379
- }
11380
- availabilityAssignmentView() {
11381
- return this.retrieveView(serialize_serialize.availabilityAssignment, "availabilityAssignmentView");
11382
- }
11383
- designatedValidatorDataView() {
11384
- return this.retrieveView(serialize_serialize.designatedValidators, "designatedValidatorsView");
11385
- }
11386
- currentValidatorDataView() {
11387
- return this.retrieveView(serialize_serialize.currentValidators, "currentValidatorsView");
11388
- }
11389
- previousValidatorDataView() {
11390
- return this.retrieveView(serialize_serialize.previousValidators, "previousValidatorsView");
11391
- }
11392
- authPoolsView() {
11393
- return this.retrieveView(serialize_serialize.authPools, "authPoolsView");
11394
- }
11395
- authQueuesView() {
11396
- return this.retrieveView(serialize_serialize.authQueues, "authQueuesView");
11397
- }
11398
- recentBlocksView() {
11399
- return this.retrieveView(serialize_serialize.recentBlocks, "recentBlocksView");
11400
- }
11401
- statisticsView() {
11402
- return this.retrieveView(serialize_serialize.statistics, "statisticsView");
11403
- }
11404
- accumulationQueueView() {
11405
- return this.retrieveView(serialize_serialize.accumulationQueue, "accumulationQueueView");
11406
- }
11407
- recentlyAccumulatedView() {
11408
- return this.retrieveView(serialize_serialize.recentlyAccumulated, "recentlyAccumulatedView");
11409
- }
11410
- safroleDataView() {
11411
- return this.retrieveView(serialize_serialize.safrole, "safroleDataView");
11412
- }
11413
- getServiceInfoView(id) {
11414
- const serviceData = serialize_serialize.serviceData(id);
11415
- const bytes = this.backend.get(serviceData.key);
11416
- if (bytes === null) {
11417
- return null;
11418
- }
11419
- if (!this.recentlyUsedServices.includes(id)) {
11420
- this.recentlyUsedServices.push(id);
11421
- }
11422
- return decoder_Decoder.decodeObject(serviceData.Codec.View, bytes, this.spec);
11423
- }
11424
- }
11425
-
11426
11268
  ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
11427
11269
 
11428
11270
 
@@ -11431,8 +11273,6 @@ class SerializedStateView {
11431
11273
 
11432
11274
 
11433
11275
 
11434
-
11435
-
11436
11276
  /**
11437
11277
  * State object which reads it's entries from some backend.
11438
11278
  *
@@ -11445,7 +11285,7 @@ class serialized_state_SerializedState {
11445
11285
  spec;
11446
11286
  blake2b;
11447
11287
  backend;
11448
- recentlyUsedServices;
11288
+ _recentServiceIds;
11449
11289
  /** Create a state-like object from collection of serialized entries. */
11450
11290
  static fromStateEntries(spec, blake2b, state, recentServices = []) {
11451
11291
  return new serialized_state_SerializedState(spec, blake2b, state, recentServices);
@@ -11454,120 +11294,106 @@ class serialized_state_SerializedState {
11454
11294
  static new(spec, blake2b, db, recentServices = []) {
11455
11295
  return new serialized_state_SerializedState(spec, blake2b, db, recentServices);
11456
11296
  }
11457
- dataCache = hash_dictionary_HashDictionary.new();
11458
- viewCache = hash_dictionary_HashDictionary.new();
11459
11297
  constructor(spec, blake2b, backend,
11460
11298
  /** Best-effort list of recently active services. */
11461
- recentlyUsedServices) {
11299
+ _recentServiceIds) {
11462
11300
  this.spec = spec;
11463
11301
  this.blake2b = blake2b;
11464
11302
  this.backend = backend;
11465
- this.recentlyUsedServices = recentlyUsedServices;
11303
+ this._recentServiceIds = _recentServiceIds;
11466
11304
  }
11467
11305
  /** Comparing the serialized states, just means comparing their backends. */
11468
11306
  [TEST_COMPARE_USING]() {
11469
11307
  return this.backend;
11470
11308
  }
11471
- /** Return a non-decoding version of the state. */
11472
- view() {
11473
- return new SerializedStateView(this.spec, this.backend, this.recentlyUsedServices, this.viewCache);
11474
- }
11475
11309
  // TODO [ToDr] Temporary method to update the state,
11476
11310
  // without changing references.
11477
11311
  updateBackend(newBackend) {
11478
11312
  this.backend = newBackend;
11479
- this.dataCache = hash_dictionary_HashDictionary.new();
11480
- this.viewCache = hash_dictionary_HashDictionary.new();
11481
11313
  }
11482
11314
  recentServiceIds() {
11483
- return this.recentlyUsedServices;
11315
+ return this._recentServiceIds;
11484
11316
  }
11485
11317
  getService(id) {
11486
- const serviceData = this.retrieveOptional(serialize_serialize.serviceData(id));
11318
+ const serviceData = this.retrieveOptional(serialize.serviceData(id));
11487
11319
  if (serviceData === undefined) {
11488
11320
  return null;
11489
11321
  }
11490
- if (!this.recentlyUsedServices.includes(id)) {
11491
- this.recentlyUsedServices.push(id);
11322
+ if (!this._recentServiceIds.includes(id)) {
11323
+ this._recentServiceIds.push(id);
11492
11324
  }
11493
11325
  return new SerializedService(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
11494
11326
  }
11495
- retrieve(k, description) {
11496
- const data = this.retrieveOptional(k);
11497
- if (data === undefined) {
11498
- throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${k.key}`);
11327
+ retrieve({ key, Codec }, description) {
11328
+ const bytes = this.backend.get(key);
11329
+ if (bytes === null) {
11330
+ throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${key}`);
11499
11331
  }
11500
- return data;
11332
+ return decoder_Decoder.decodeObject(Codec, bytes, this.spec);
11501
11333
  }
11502
11334
  retrieveOptional({ key, Codec }) {
11503
- const cached = this.dataCache.get(key);
11504
- if (cached !== undefined) {
11505
- return cached;
11506
- }
11507
11335
  const bytes = this.backend.get(key);
11508
11336
  if (bytes === null) {
11509
11337
  return undefined;
11510
11338
  }
11511
- const data = decoder_Decoder.decodeObject(Codec, bytes, this.spec);
11512
- this.dataCache.set(key, data);
11513
- return data;
11339
+ return decoder_Decoder.decodeObject(Codec, bytes, this.spec);
11514
11340
  }
11515
11341
  get availabilityAssignment() {
11516
- return this.retrieve(serialize_serialize.availabilityAssignment, "availabilityAssignment");
11342
+ return this.retrieve(serialize.availabilityAssignment, "availabilityAssignment");
11517
11343
  }
11518
11344
  get designatedValidatorData() {
11519
- return this.retrieve(serialize_serialize.designatedValidators, "designatedValidatorData");
11345
+ return this.retrieve(serialize.designatedValidators, "designatedValidatorData");
11520
11346
  }
11521
11347
  get nextValidatorData() {
11522
- return this.retrieve(serialize_serialize.safrole, "safroleData.nextValidatorData").nextValidatorData;
11348
+ return this.retrieve(serialize.safrole, "safroleData.nextValidatorData").nextValidatorData;
11523
11349
  }
11524
11350
  get currentValidatorData() {
11525
- return this.retrieve(serialize_serialize.currentValidators, "currentValidators");
11351
+ return this.retrieve(serialize.currentValidators, "currentValidators");
11526
11352
  }
11527
11353
  get previousValidatorData() {
11528
- return this.retrieve(serialize_serialize.previousValidators, "previousValidators");
11354
+ return this.retrieve(serialize.previousValidators, "previousValidators");
11529
11355
  }
11530
11356
  get disputesRecords() {
11531
- return this.retrieve(serialize_serialize.disputesRecords, "disputesRecords");
11357
+ return this.retrieve(serialize.disputesRecords, "disputesRecords");
11532
11358
  }
11533
11359
  get timeslot() {
11534
- return this.retrieve(serialize_serialize.timeslot, "timeslot");
11360
+ return this.retrieve(serialize.timeslot, "timeslot");
11535
11361
  }
11536
11362
  get entropy() {
11537
- return this.retrieve(serialize_serialize.entropy, "entropy");
11363
+ return this.retrieve(serialize.entropy, "entropy");
11538
11364
  }
11539
11365
  get authPools() {
11540
- return this.retrieve(serialize_serialize.authPools, "authPools");
11366
+ return this.retrieve(serialize.authPools, "authPools");
11541
11367
  }
11542
11368
  get authQueues() {
11543
- return this.retrieve(serialize_serialize.authQueues, "authQueues");
11369
+ return this.retrieve(serialize.authQueues, "authQueues");
11544
11370
  }
11545
11371
  get recentBlocks() {
11546
- return this.retrieve(serialize_serialize.recentBlocks, "recentBlocks");
11372
+ return this.retrieve(serialize.recentBlocks, "recentBlocks");
11547
11373
  }
11548
11374
  get statistics() {
11549
- return this.retrieve(serialize_serialize.statistics, "statistics");
11375
+ return this.retrieve(serialize.statistics, "statistics");
11550
11376
  }
11551
11377
  get accumulationQueue() {
11552
- return this.retrieve(serialize_serialize.accumulationQueue, "accumulationQueue");
11378
+ return this.retrieve(serialize.accumulationQueue, "accumulationQueue");
11553
11379
  }
11554
11380
  get recentlyAccumulated() {
11555
- return this.retrieve(serialize_serialize.recentlyAccumulated, "recentlyAccumulated");
11381
+ return this.retrieve(serialize.recentlyAccumulated, "recentlyAccumulated");
11556
11382
  }
11557
11383
  get ticketsAccumulator() {
11558
- return this.retrieve(serialize_serialize.safrole, "safroleData.ticketsAccumulator").ticketsAccumulator;
11384
+ return this.retrieve(serialize.safrole, "safroleData.ticketsAccumulator").ticketsAccumulator;
11559
11385
  }
11560
11386
  get sealingKeySeries() {
11561
- return this.retrieve(serialize_serialize.safrole, "safrole.sealingKeySeries").sealingKeySeries;
11387
+ return this.retrieve(serialize.safrole, "safrole.sealingKeySeries").sealingKeySeries;
11562
11388
  }
11563
11389
  get epochRoot() {
11564
- return this.retrieve(serialize_serialize.safrole, "safrole.epochRoot").epochRoot;
11390
+ return this.retrieve(serialize.safrole, "safrole.epochRoot").epochRoot;
11565
11391
  }
11566
11392
  get privilegedServices() {
11567
- return this.retrieve(serialize_serialize.privilegedServices, "privilegedServices");
11393
+ return this.retrieve(serialize.privilegedServices, "privilegedServices");
11568
11394
  }
11569
11395
  get accumulationOutputLog() {
11570
- return this.retrieve(serialize_serialize.accumulationOutputLog, "accumulationOutputLog");
11396
+ return this.retrieve(serialize.accumulationOutputLog, "accumulationOutputLog");
11571
11397
  }
11572
11398
  }
11573
11399
  /** Service data representation on a serialized state. */
@@ -11596,9 +11422,9 @@ class SerializedService {
11596
11422
  serviceIdAndKey.set(numbers_u32AsLeBytes(this.serviceId));
11597
11423
  serviceIdAndKey.set(rawKey.raw, SERVICE_ID_BYTES);
11598
11424
  const key = opaque_asOpaqueType(bytes_BytesBlob.blobFrom(this.blake2b.hashBytes(serviceIdAndKey).raw));
11599
- return this.retrieveOptional(serialize_serialize.serviceStorage(this.blake2b, this.serviceId, key)) ?? null;
11425
+ return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, key)) ?? null;
11600
11426
  }
11601
- return this.retrieveOptional(serialize_serialize.serviceStorage(this.blake2b, this.serviceId, rawKey)) ?? null;
11427
+ return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, rawKey)) ?? null;
11602
11428
  }
11603
11429
  /**
11604
11430
  * Check if preimage is present in the DB.
@@ -11607,15 +11433,15 @@ class SerializedService {
11607
11433
  */
11608
11434
  hasPreimage(hash) {
11609
11435
  // TODO [ToDr] consider optimizing to avoid fetching the whole data.
11610
- return this.retrieveOptional(serialize_serialize.servicePreimages(this.blake2b, this.serviceId, hash)) !== undefined;
11436
+ return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) !== undefined;
11611
11437
  }
11612
11438
  /** Retrieve preimage from the DB. */
11613
11439
  getPreimage(hash) {
11614
- return this.retrieveOptional(serialize_serialize.servicePreimages(this.blake2b, this.serviceId, hash)) ?? null;
11440
+ return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) ?? null;
11615
11441
  }
11616
11442
  /** Retrieve preimage lookup history. */
11617
11443
  getLookupHistory(hash, len) {
11618
- const rawSlots = this.retrieveOptional(serialize_serialize.serviceLookupHistory(this.blake2b, this.serviceId, hash, len));
11444
+ const rawSlots = this.retrieveOptional(serialize.serviceLookupHistory(this.blake2b, this.serviceId, hash, len));
11619
11445
  if (rawSlots === undefined) {
11620
11446
  return null;
11621
11447
  }
@@ -12304,7 +12130,7 @@ function* serializeStateUpdate(spec, blake2b, update) {
12304
12130
  function* serializeRemovedServices(servicesRemoved) {
12305
12131
  for (const serviceId of servicesRemoved ?? []) {
12306
12132
  // TODO [ToDr] what about all data associated with a service?
12307
- const codec = serialize_serialize.serviceData(serviceId);
12133
+ const codec = serialize.serviceData(serviceId);
12308
12134
  yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
12309
12135
  }
12310
12136
  }
@@ -12313,13 +12139,13 @@ function* serializeStorage(storage, blake2b) {
12313
12139
  switch (action.kind) {
12314
12140
  case UpdateStorageKind.Set: {
12315
12141
  const key = action.storage.key;
12316
- const codec = serialize_serialize.serviceStorage(blake2b, serviceId, key);
12142
+ const codec = serialize.serviceStorage(blake2b, serviceId, key);
12317
12143
  yield [StateEntryUpdateAction.Insert, codec.key, action.storage.value];
12318
12144
  break;
12319
12145
  }
12320
12146
  case UpdateStorageKind.Remove: {
12321
12147
  const key = action.key;
12322
- const codec = serialize_serialize.serviceStorage(blake2b, serviceId, key);
12148
+ const codec = serialize.serviceStorage(blake2b, serviceId, key);
12323
12149
  yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
12324
12150
  break;
12325
12151
  }
@@ -12333,10 +12159,10 @@ function* serializePreimages(preimages, encode, blake2b) {
12333
12159
  switch (action.kind) {
12334
12160
  case UpdatePreimageKind.Provide: {
12335
12161
  const { hash, blob } = action.preimage;
12336
- const codec = serialize_serialize.servicePreimages(blake2b, serviceId, hash);
12162
+ const codec = serialize.servicePreimages(blake2b, serviceId, hash);
12337
12163
  yield [StateEntryUpdateAction.Insert, codec.key, blob];
12338
12164
  if (action.slot !== null) {
12339
- const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, numbers_tryAsU32(blob.length));
12165
+ const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, numbers_tryAsU32(blob.length));
12340
12166
  yield [
12341
12167
  StateEntryUpdateAction.Insert,
12342
12168
  codec2.key,
@@ -12347,15 +12173,15 @@ function* serializePreimages(preimages, encode, blake2b) {
12347
12173
  }
12348
12174
  case UpdatePreimageKind.UpdateOrAdd: {
12349
12175
  const { hash, length, slots } = action.item;
12350
- const codec = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
12176
+ const codec = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
12351
12177
  yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, slots)];
12352
12178
  break;
12353
12179
  }
12354
12180
  case UpdatePreimageKind.Remove: {
12355
12181
  const { hash, length } = action;
12356
- const codec = serialize_serialize.servicePreimages(blake2b, serviceId, hash);
12182
+ const codec = serialize.servicePreimages(blake2b, serviceId, hash);
12357
12183
  yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
12358
- const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
12184
+ const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
12359
12185
  yield [StateEntryUpdateAction.Remove, codec2.key, EMPTY_BLOB];
12360
12186
  break;
12361
12187
  }
@@ -12367,12 +12193,12 @@ function* serializePreimages(preimages, encode, blake2b) {
12367
12193
  function* serializeServiceUpdates(servicesUpdates, encode, blake2b) {
12368
12194
  for (const { action, serviceId } of servicesUpdates ?? []) {
12369
12195
  // new service being created or updated
12370
- const codec = serialize_serialize.serviceData(serviceId);
12196
+ const codec = serialize.serviceData(serviceId);
12371
12197
  yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, action.account)];
12372
12198
  // additional lookup history update
12373
12199
  if (action.kind === UpdateServiceKind.Create && action.lookupHistory !== null) {
12374
12200
  const { lookupHistory } = action;
12375
- const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
12201
+ const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
12376
12202
  yield [StateEntryUpdateAction.Insert, codec2.key, encode(codec2.Codec, lookupHistory.slots)];
12377
12203
  }
12378
12204
  }
@@ -12382,53 +12208,53 @@ function* serializeBasicKeys(spec, update) {
12382
12208
  return [StateEntryUpdateAction.Insert, codec.key, encoder_Encoder.encodeObject(codec.Codec, val, spec)];
12383
12209
  }
12384
12210
  if (update.authPools !== undefined) {
12385
- yield doSerialize(update.authPools, serialize_serialize.authPools); // C(1)
12211
+ yield doSerialize(update.authPools, serialize.authPools); // C(1)
12386
12212
  }
12387
12213
  if (update.authQueues !== undefined) {
12388
- yield doSerialize(update.authQueues, serialize_serialize.authQueues); // C(2)
12214
+ yield doSerialize(update.authQueues, serialize.authQueues); // C(2)
12389
12215
  }
12390
12216
  if (update.recentBlocks !== undefined) {
12391
- yield doSerialize(update.recentBlocks, serialize_serialize.recentBlocks); // C(3)
12217
+ yield doSerialize(update.recentBlocks, serialize.recentBlocks); // C(3)
12392
12218
  }
12393
12219
  const safroleData = getSafroleData(update.nextValidatorData, update.epochRoot, update.sealingKeySeries, update.ticketsAccumulator);
12394
12220
  if (safroleData !== undefined) {
12395
- yield doSerialize(safroleData, serialize_serialize.safrole); // C(4)
12221
+ yield doSerialize(safroleData, serialize.safrole); // C(4)
12396
12222
  }
12397
12223
  if (update.disputesRecords !== undefined) {
12398
- yield doSerialize(update.disputesRecords, serialize_serialize.disputesRecords); // C(5)
12224
+ yield doSerialize(update.disputesRecords, serialize.disputesRecords); // C(5)
12399
12225
  }
12400
12226
  if (update.entropy !== undefined) {
12401
- yield doSerialize(update.entropy, serialize_serialize.entropy); // C(6)
12227
+ yield doSerialize(update.entropy, serialize.entropy); // C(6)
12402
12228
  }
12403
12229
  if (update.designatedValidatorData !== undefined) {
12404
- yield doSerialize(update.designatedValidatorData, serialize_serialize.designatedValidators); // C(7)
12230
+ yield doSerialize(update.designatedValidatorData, serialize.designatedValidators); // C(7)
12405
12231
  }
12406
12232
  if (update.currentValidatorData !== undefined) {
12407
- yield doSerialize(update.currentValidatorData, serialize_serialize.currentValidators); // C(8)
12233
+ yield doSerialize(update.currentValidatorData, serialize.currentValidators); // C(8)
12408
12234
  }
12409
12235
  if (update.previousValidatorData !== undefined) {
12410
- yield doSerialize(update.previousValidatorData, serialize_serialize.previousValidators); // C(9)
12236
+ yield doSerialize(update.previousValidatorData, serialize.previousValidators); // C(9)
12411
12237
  }
12412
12238
  if (update.availabilityAssignment !== undefined) {
12413
- yield doSerialize(update.availabilityAssignment, serialize_serialize.availabilityAssignment); // C(10)
12239
+ yield doSerialize(update.availabilityAssignment, serialize.availabilityAssignment); // C(10)
12414
12240
  }
12415
12241
  if (update.timeslot !== undefined) {
12416
- yield doSerialize(update.timeslot, serialize_serialize.timeslot); // C(11)
12242
+ yield doSerialize(update.timeslot, serialize.timeslot); // C(11)
12417
12243
  }
12418
12244
  if (update.privilegedServices !== undefined) {
12419
- yield doSerialize(update.privilegedServices, serialize_serialize.privilegedServices); // C(12)
12245
+ yield doSerialize(update.privilegedServices, serialize.privilegedServices); // C(12)
12420
12246
  }
12421
12247
  if (update.statistics !== undefined) {
12422
- yield doSerialize(update.statistics, serialize_serialize.statistics); // C(13)
12248
+ yield doSerialize(update.statistics, serialize.statistics); // C(13)
12423
12249
  }
12424
12250
  if (update.accumulationQueue !== undefined) {
12425
- yield doSerialize(update.accumulationQueue, serialize_serialize.accumulationQueue); // C(14)
12251
+ yield doSerialize(update.accumulationQueue, serialize.accumulationQueue); // C(14)
12426
12252
  }
12427
12253
  if (update.recentlyAccumulated !== undefined) {
12428
- yield doSerialize(update.recentlyAccumulated, serialize_serialize.recentlyAccumulated); // C(15)
12254
+ yield doSerialize(update.recentlyAccumulated, serialize.recentlyAccumulated); // C(15)
12429
12255
  }
12430
12256
  if (update.accumulationOutputLog !== undefined) {
12431
- yield doSerialize(update.accumulationOutputLog, serialize_serialize.accumulationOutputLog); // C(16)
12257
+ yield doSerialize(update.accumulationOutputLog, serialize.accumulationOutputLog); // C(16)
12432
12258
  }
12433
12259
  }
12434
12260
  function getSafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator) {
@@ -12541,41 +12367,41 @@ function convertInMemoryStateToDictionary(spec, blake2b, state) {
12541
12367
  function doSerialize(codec) {
12542
12368
  serialized.set(codec.key, encoder_Encoder.encodeObject(codec.Codec, codec.extract(state), spec));
12543
12369
  }
12544
- doSerialize(serialize_serialize.authPools); // C(1)
12545
- doSerialize(serialize_serialize.authQueues); // C(2)
12546
- doSerialize(serialize_serialize.recentBlocks); // C(3)
12547
- doSerialize(serialize_serialize.safrole); // C(4)
12548
- doSerialize(serialize_serialize.disputesRecords); // C(5)
12549
- doSerialize(serialize_serialize.entropy); // C(6)
12550
- doSerialize(serialize_serialize.designatedValidators); // C(7)
12551
- doSerialize(serialize_serialize.currentValidators); // C(8)
12552
- doSerialize(serialize_serialize.previousValidators); // C(9)
12553
- doSerialize(serialize_serialize.availabilityAssignment); // C(10)
12554
- doSerialize(serialize_serialize.timeslot); // C(11)
12555
- doSerialize(serialize_serialize.privilegedServices); // C(12)
12556
- doSerialize(serialize_serialize.statistics); // C(13)
12557
- doSerialize(serialize_serialize.accumulationQueue); // C(14)
12558
- doSerialize(serialize_serialize.recentlyAccumulated); // C(15)
12559
- doSerialize(serialize_serialize.accumulationOutputLog); // C(16)
12370
+ doSerialize(serialize.authPools); // C(1)
12371
+ doSerialize(serialize.authQueues); // C(2)
12372
+ doSerialize(serialize.recentBlocks); // C(3)
12373
+ doSerialize(serialize.safrole); // C(4)
12374
+ doSerialize(serialize.disputesRecords); // C(5)
12375
+ doSerialize(serialize.entropy); // C(6)
12376
+ doSerialize(serialize.designatedValidators); // C(7)
12377
+ doSerialize(serialize.currentValidators); // C(8)
12378
+ doSerialize(serialize.previousValidators); // C(9)
12379
+ doSerialize(serialize.availabilityAssignment); // C(10)
12380
+ doSerialize(serialize.timeslot); // C(11)
12381
+ doSerialize(serialize.privilegedServices); // C(12)
12382
+ doSerialize(serialize.statistics); // C(13)
12383
+ doSerialize(serialize.accumulationQueue); // C(14)
12384
+ doSerialize(serialize.recentlyAccumulated); // C(15)
12385
+ doSerialize(serialize.accumulationOutputLog); // C(16)
12560
12386
  // services
12561
12387
  for (const [serviceId, service] of state.services.entries()) {
12562
12388
  // data
12563
- const { key, Codec } = serialize_serialize.serviceData(serviceId);
12389
+ const { key, Codec } = serialize.serviceData(serviceId);
12564
12390
  serialized.set(key, encoder_Encoder.encodeObject(Codec, service.getInfo()));
12565
12391
  // preimages
12566
12392
  for (const preimage of service.data.preimages.values()) {
12567
- const { key, Codec } = serialize_serialize.servicePreimages(blake2b, serviceId, preimage.hash);
12393
+ const { key, Codec } = serialize.servicePreimages(blake2b, serviceId, preimage.hash);
12568
12394
  serialized.set(key, encoder_Encoder.encodeObject(Codec, preimage.blob));
12569
12395
  }
12570
12396
  // storage
12571
12397
  for (const storage of service.data.storage.values()) {
12572
- const { key, Codec } = serialize_serialize.serviceStorage(blake2b, serviceId, storage.key);
12398
+ const { key, Codec } = serialize.serviceStorage(blake2b, serviceId, storage.key);
12573
12399
  serialized.set(key, encoder_Encoder.encodeObject(Codec, storage.value));
12574
12400
  }
12575
12401
  // lookup history
12576
12402
  for (const lookupHistoryList of service.data.lookupHistory.values()) {
12577
12403
  for (const lookupHistory of lookupHistoryList) {
12578
- const { key, Codec } = serialize_serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
12404
+ const { key, Codec } = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
12579
12405
  serialized.set(key, encoder_Encoder.encodeObject(Codec, lookupHistory.slots.slice()));
12580
12406
  }
12581
12407
  }
@@ -12625,7 +12451,6 @@ function loadState(spec, blake2b, entries) {
12625
12451
 
12626
12452
 
12627
12453
 
12628
-
12629
12454
  ;// CONCATENATED MODULE: ./packages/jam/database/leaf-db.ts
12630
12455
 
12631
12456
 
@@ -12784,7 +12609,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
12784
12609
  const lookupHistoryItemCodec = descriptors_codec.object({
12785
12610
  hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
12786
12611
  length: descriptors_codec.u32,
12787
- slots: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32.asOpaque())).convert(seeThrough, tryAsLookupHistorySlots),
12612
+ slots: readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32.asOpaque())).convert(seeThrough, tryAsLookupHistorySlots),
12788
12613
  }, "LookupHistoryItem", ({ hash, length, slots }) => new LookupHistoryItem(hash, length, slots));
12789
12614
  const lookupHistoryEntryCodec = descriptors_codec.object({
12790
12615
  key: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
@@ -12827,11 +12652,7 @@ class ServiceWithCodec extends InMemoryService {
12827
12652
  return new ServiceWithCodec(serviceId, data);
12828
12653
  }
12829
12654
  }
12830
- const in_memory_state_codec_inMemoryStateCodec = (spec) => codec.Class(class State extends InMemoryState {
12831
- static create(data) {
12832
- return InMemoryState.new(spec, data);
12833
- }
12834
- }, {
12655
+ const in_memory_state_codec_inMemoryStateCodec = descriptors_codec.Class(InMemoryState, {
12835
12656
  // alpha
12836
12657
  authPools: serialize.authPools.Codec,
12837
12658
  // phi
@@ -12841,11 +12662,11 @@ const in_memory_state_codec_inMemoryStateCodec = (spec) => codec.Class(class Sta
12841
12662
  // gamma_k
12842
12663
  nextValidatorData: codecPerValidator(ValidatorData.Codec),
12843
12664
  // gamma_z
12844
- epochRoot: codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
12665
+ epochRoot: descriptors_codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
12845
12666
  // gamma_s
12846
12667
  sealingKeySeries: SafroleSealingKeysData.Codec,
12847
12668
  // gamma_a
12848
- ticketsAccumulator: readonlyArray(codec.sequenceVarLen(Ticket.Codec)).convert((x) => x, asKnownSize),
12669
+ ticketsAccumulator: readonlyArray(descriptors_codec.sequenceVarLen(Ticket.Codec)).convert((x) => x, sized_array_asKnownSize),
12849
12670
  // psi
12850
12671
  disputesRecords: serialize.disputesRecords.Codec,
12851
12672
  // eta
@@ -12871,7 +12692,7 @@ const in_memory_state_codec_inMemoryStateCodec = (spec) => codec.Class(class Sta
12871
12692
  // theta
12872
12693
  accumulationOutputLog: serialize.accumulationOutputLog.Codec,
12873
12694
  // delta
12874
- services: codec.dictionary(codec.u32.asOpaque(), ServiceWithCodec.Codec, {
12695
+ services: descriptors_codec.dictionary(descriptors_codec.u32.asOpaque(), ServiceWithCodec.Codec, {
12875
12696
  sortKeys: (a, b) => a - b,
12876
12697
  }),
12877
12698
  });
@@ -12918,7 +12739,7 @@ class InMemoryStates {
12918
12739
  }
12919
12740
  /** Insert a full state into the database. */
12920
12741
  async insertState(headerHash, state) {
12921
- const encoded = Encoder.encodeObject(inMemoryStateCodec(this.spec), state, this.spec);
12742
+ const encoded = Encoder.encodeObject(inMemoryStateCodec, state, this.spec);
12922
12743
  this.db.set(headerHash, encoded);
12923
12744
  return Result.ok(OK);
12924
12745
  }
@@ -12927,7 +12748,7 @@ class InMemoryStates {
12927
12748
  if (encodedState === undefined) {
12928
12749
  return null;
12929
12750
  }
12930
- return Decoder.decodeObject(inMemoryStateCodec(this.spec), encodedState, this.spec);
12751
+ return Decoder.decodeObject(inMemoryStateCodec, encodedState, this.spec);
12931
12752
  }
12932
12753
  }
12933
12754
 
@@ -14035,21 +13856,21 @@ class TransitionHasher {
14035
13856
  */
14036
13857
  extrinsic(extrinsicView) {
14037
13858
  // https://graypaper.fluffylabs.dev/#/cc517d7/0cfb000cfb00?v=0.6.5
14038
- const guaranteesCount = numbers_tryAsU32(extrinsicView.guarantees.view().length);
14039
- const countEncoded = encoder_Encoder.encodeObject(descriptors_codec.varU32, guaranteesCount);
14040
- const guaranteesBlobs = extrinsicView.guarantees
13859
+ const guarantees = extrinsicView.guarantees
14041
13860
  .view()
14042
13861
  .map((g) => g.view())
14043
- .reduce((aggregated, guarantee) => {
13862
+ .map((guarantee) => {
14044
13863
  const reportHash = this.blake2b.hashBytes(guarantee.report.encoded()).asOpaque();
14045
- aggregated.push(reportHash.raw);
14046
- aggregated.push(guarantee.slot.encoded().raw);
14047
- aggregated.push(guarantee.credentials.encoded().raw);
14048
- return aggregated;
14049
- }, [countEncoded.raw]);
13864
+ return bytes_BytesBlob.blobFromParts([
13865
+ reportHash.raw,
13866
+ guarantee.slot.encoded().raw,
13867
+ guarantee.credentials.encoded().raw,
13868
+ ]);
13869
+ });
13870
+ const guaranteeBlob = encoder_Encoder.encodeObject(descriptors_codec.sequenceVarLen(dumpCodec), guarantees, this.context);
14050
13871
  const et = this.blake2b.hashBytes(extrinsicView.tickets.encoded()).asOpaque();
14051
13872
  const ep = this.blake2b.hashBytes(extrinsicView.preimages.encoded()).asOpaque();
14052
- const eg = this.blake2b.hashBlobs(guaranteesBlobs).asOpaque();
13873
+ const eg = this.blake2b.hashBytes(guaranteeBlob).asOpaque();
14053
13874
  const ea = this.blake2b.hashBytes(extrinsicView.assurances.encoded()).asOpaque();
14054
13875
  const ed = this.blake2b.hashBytes(extrinsicView.disputes.encoded()).asOpaque();
14055
13876
  const encoded = bytes_BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);
@@ -14708,7 +14529,7 @@ async function getRingCommitmentNoCache(bandersnatch, keys) {
14708
14529
  if (commitmentResult[RESULT_INDEX] === ResultValues.Error) {
14709
14530
  return result_Result.error(null);
14710
14531
  }
14711
- return result_Result.ok(bytes_Bytes.fromBlob(commitmentResult.subarray(1), bandersnatch_BANDERSNATCH_RING_ROOT_BYTES).asOpaque());
14532
+ return result_Result.ok(bytes_Bytes.fromBlob(commitmentResult.subarray(1), BANDERSNATCH_RING_ROOT_BYTES).asOpaque());
14712
14533
  }
14713
14534
  // One byte for result discriminator (`ResultValues`) and the rest is entropy hash.
14714
14535
  const TICKET_RESULT_LENGTH = 1 + hash_HASH_SIZE;
@@ -14862,7 +14683,7 @@ class Safrole {
14862
14683
  * https://graypaper.fluffylabs.dev/#/5f542d7/0ea2000ea200
14863
14684
  */
14864
14685
  if (isOffender) {
14865
- return validator_data_ValidatorData.create({
14686
+ return ValidatorData.create({
14866
14687
  bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
14867
14688
  ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
14868
14689
  bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
@@ -14940,13 +14761,13 @@ class Safrole {
14940
14761
  if (this.isNextEpoch(timeslot) &&
14941
14762
  m >= this.chainSpec.contestLength &&
14942
14763
  this.state.ticketsAccumulator.length === this.chainSpec.epochLength) {
14943
- return safrole_data_SafroleSealingKeysData.tickets(this.outsideInSequencer(this.state.ticketsAccumulator).tickets);
14764
+ return SafroleSealingKeysData.tickets(this.outsideInSequencer(this.state.ticketsAccumulator).tickets);
14944
14765
  }
14945
14766
  if (this.isSameEpoch(timeslot)) {
14946
14767
  return this.state.sealingKeySeries;
14947
14768
  }
14948
14769
  // TODO [MaSi]: the result of fallback sequencer should be cached
14949
- return safrole_data_SafroleSealingKeysData.keys(this.fallbackKeySequencer(newEntropy, newValidators));
14770
+ return SafroleSealingKeysData.keys(this.fallbackKeySequencer(newEntropy, newValidators));
14950
14771
  }
14951
14772
  /**
14952
14773
  * Returns epoch markers if the epoch is changed and null otherwise
@@ -15196,46 +15017,47 @@ class SafroleSeal {
15196
15017
  }
15197
15018
  async verifySeal(headerView, state) {
15198
15019
  // we use transitioned keys already
15020
+ const validators = state.currentValidatorData;
15199
15021
  const validatorIndex = headerView.bandersnatchBlockAuthorIndex.materialize();
15200
- const authorKeys = state.currentValidatorData.at(validatorIndex);
15201
- if (authorKeys === undefined) {
15022
+ const authorKey = validators[validatorIndex];
15023
+ if (authorKey === undefined) {
15202
15024
  return result_Result.error(SafroleSealError.InvalidValidatorIndex);
15203
15025
  }
15204
15026
  const timeSlot = headerView.timeSlotIndex.materialize();
15205
15027
  const sealingKeys = state.sealingKeySeries;
15206
15028
  const entropy = state.currentEntropy;
15207
15029
  if (sealingKeys.kind === SafroleSealingKeysKind.Tickets) {
15208
- return await this.verifySealWithTicket(sealingKeys.tickets, timeSlot, entropy, authorKeys, headerView);
15030
+ return await this.verifySealWithTicket(sealingKeys.tickets, timeSlot, entropy, validators, validatorIndex, headerView);
15209
15031
  }
15210
- return await this.verifySealWithKeys(sealingKeys.keys, timeSlot, entropy, authorKeys, headerView);
15032
+ return await this.verifySealWithKeys(sealingKeys.keys, authorKey, timeSlot, entropy, validators, validatorIndex, headerView);
15211
15033
  }
15212
15034
  /** Regular (non-fallback) mode of Safrole. */
15213
- async verifySealWithTicket(tickets, timeSlot, entropy, validatorData, headerView) {
15035
+ async verifySealWithTicket(tickets, timeSlot, entropy, validators, validatorIndex, headerView) {
15214
15036
  const index = timeSlot % tickets.length;
15215
- const ticket = tickets.at(index);
15216
- const payload = bytes_BytesBlob.blobFromParts(JAM_TICKET_SEAL, entropy.raw, new Uint8Array([ticket?.attempt ?? 0]));
15037
+ const { id, attempt } = tickets[index];
15038
+ const payload = bytes_BytesBlob.blobFromParts(JAM_TICKET_SEAL, entropy.raw, new Uint8Array([attempt]));
15217
15039
  // verify seal correctness
15218
- const authorKey = validatorData.bandersnatch;
15040
+ const authorKey = validators.at(validatorIndex)?.bandersnatch;
15219
15041
  const result = await bandersnatch_vrf.verifySeal(await this.bandersnatch, authorKey ?? BANDERSNATCH_ZERO_KEY, headerView.seal.materialize(), payload, encodeUnsealedHeader(headerView));
15220
15042
  if (result.isError) {
15221
15043
  return result_Result.error(SafroleSealError.IncorrectSeal);
15222
15044
  }
15223
- if (ticket === undefined || !ticket.id.isEqualTo(result.ok)) {
15045
+ if (!id.isEqualTo(result.ok)) {
15224
15046
  return result_Result.error(SafroleSealError.InvalidTicket);
15225
15047
  }
15226
15048
  return result_Result.ok(result.ok);
15227
15049
  }
15228
15050
  /** Fallback mode of Safrole. */
15229
- async verifySealWithKeys(keys, timeSlot, entropy, authorKey, headerView) {
15051
+ async verifySealWithKeys(keys, authorKey, timeSlot, entropy, validators, validatorIndex, headerView) {
15230
15052
  const index = timeSlot % keys.length;
15231
- const sealingKey = keys.at(index);
15232
- const authorBandersnatchKey = authorKey.bandersnatch;
15233
- if (sealingKey === undefined || !sealingKey.isEqualTo(authorBandersnatchKey)) {
15053
+ const sealingKey = keys[index];
15054
+ if (!sealingKey.isEqualTo(authorKey.bandersnatch)) {
15234
15055
  return result_Result.error(SafroleSealError.InvalidValidator, `Invalid Validator. Expected: ${sealingKey}, got: ${authorKey.bandersnatch}`);
15235
15056
  }
15236
15057
  // verify seal correctness
15237
15058
  const payload = bytes_BytesBlob.blobFromParts(JAM_FALLBACK_SEAL, entropy.raw);
15238
- const result = await bandersnatch_vrf.verifySeal(await this.bandersnatch, authorBandersnatchKey, headerView.seal.materialize(), payload, encodeUnsealedHeader(headerView));
15059
+ const blockAuthorKey = validators.at(validatorIndex)?.bandersnatch;
15060
+ const result = await bandersnatch_vrf.verifySeal(await this.bandersnatch, blockAuthorKey ?? BANDERSNATCH_ZERO_KEY, headerView.seal.materialize(), payload, encodeUnsealedHeader(headerView));
15239
15061
  if (result.isError) {
15240
15062
  return result_Result.error(SafroleSealError.IncorrectSeal);
15241
15063
  }
@@ -21432,7 +21254,7 @@ class Assign {
21432
21254
  // NOTE: Here we know the core index is valid
21433
21255
  const coreIndex = tryAsCoreIndex(Number(maybeCoreIndex));
21434
21256
  const decoder = decoder_Decoder.fromBlob(res);
21435
- const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE);
21257
+ const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE), AUTHORIZATION_QUEUE_SIZE);
21436
21258
  const fixedSizeAuthQueue = FixedSizeArray.new(authQueue, AUTHORIZATION_QUEUE_SIZE);
21437
21259
  const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
21438
21260
  if (result.isOk) {
@@ -21628,7 +21450,7 @@ class Checkpoint {
21628
21450
 
21629
21451
 
21630
21452
  const designate_IN_OUT_REG = 7;
21631
- const VALIDATOR_DATA_BYTES = tryAsExactBytes(validator_data_ValidatorData.Codec.sizeHint);
21453
+ const VALIDATOR_DATA_BYTES = tryAsExactBytes(ValidatorData.Codec.sizeHint);
21632
21454
  /**
21633
21455
  * Designate a new set of validator keys.
21634
21456
  *
@@ -21657,7 +21479,7 @@ class Designate {
21657
21479
  return PvmExecution.Panic;
21658
21480
  }
21659
21481
  const decoder = decoder_Decoder.fromBlob(res);
21660
- const validatorsData = decoder.sequenceFixLen(validator_data_ValidatorData.Codec, this.chainSpec.validatorsCount);
21482
+ const validatorsData = decoder.sequenceFixLen(ValidatorData.Codec, this.chainSpec.validatorsCount);
21661
21483
  const result = this.partialState.updateValidatorsData(tryAsPerValidator(validatorsData, this.chainSpec));
21662
21484
  if (result.isError) {
21663
21485
  logger_logger.trace `DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- HUH`;
@@ -23313,10 +23135,9 @@ class Accumulate {
23313
23135
  const recentlyAccumulated = tryAsPerEpochBlock(newRecentlyAccumulated, this.chainSpec);
23314
23136
  const accumulationQueue = this.state.accumulationQueue.slice();
23315
23137
  accumulationQueue[phaseIndex] = pruneQueue(toAccumulateLater, accumulatedSet);
23316
- const timeslot = this.state.timeslot;
23317
23138
  for (let i = 1; i < epochLength; i++) {
23318
23139
  const queueIndex = (phaseIndex + epochLength - i) % epochLength;
23319
- if (i < slot - timeslot) {
23140
+ if (i < slot - this.state.timeslot) {
23320
23141
  accumulationQueue[queueIndex] = [];
23321
23142
  }
23322
23143
  else {
@@ -23528,6 +23349,7 @@ class DeferredTransfers {
23528
23349
 
23529
23350
 
23530
23351
 
23352
+
23531
23353
  /**
23532
23354
  * Maintain a list of available authorizations per core.
23533
23355
  *
@@ -23556,12 +23378,11 @@ class Authorization {
23556
23378
  */
23557
23379
  transition(input) {
23558
23380
  const authPoolsUpdate = this.state.authPools.slice();
23559
- const authQueues = this.state.authQueues;
23560
23381
  // we transition authorizations for each core.
23561
23382
  for (let coreIndex = tryAsCoreIndex(0); coreIndex < this.chainSpec.coresCount; coreIndex++) {
23562
23383
  let pool = authPoolsUpdate[coreIndex].slice();
23563
23384
  // the queue is only read (we should most likely use `ArrayView` here).
23564
- const queue = authQueues[coreIndex];
23385
+ const queue = this.state.authQueues[coreIndex];
23565
23386
  // if there were any used hashes - remove them
23566
23387
  const usedHashes = input.used.get(coreIndex);
23567
23388
  if (usedHashes !== undefined) {
@@ -23735,18 +23556,14 @@ class RecentHistory {
23735
23556
  * https://graypaper.fluffylabs.dev/#/1c979cb/0f55020f5502?v=0.7.1
23736
23557
  */
23737
23558
  partialTransition(input) {
23738
- const stateBlocks = this.state.recentBlocks;
23739
- const recentBlocks = stateBlocks.blocks.slice();
23559
+ const recentBlocks = this.state.recentBlocks.blocks.slice();
23740
23560
  const lastState = recentBlocks.length > 0 ? recentBlocks[recentBlocks.length - 1] : null;
23741
23561
  // update the posterior root of previous state.
23742
23562
  if (lastState !== null) {
23743
23563
  lastState.postStateRoot = input.priorStateRoot;
23744
23564
  }
23745
23565
  return {
23746
- recentBlocks: RecentBlocks.create({
23747
- blocks: sized_array_asKnownSize(recentBlocks),
23748
- accumulationLog: stateBlocks.accumulationLog,
23749
- }), // β_H†
23566
+ recentBlocks: this.state.recentBlocks.updateBlocks(recentBlocks), // β_H†
23750
23567
  };
23751
23568
  }
23752
23569
  /**
@@ -23758,8 +23575,8 @@ class RecentHistory {
23758
23575
  transition(input) {
23759
23576
  const recentBlocks = input.partial.recentBlocks.blocks.slice();
23760
23577
  // `β′_B`
23761
- const mmr = this.state.recentBlocks.accumulationLog !== null
23762
- ? MerkleMountainRange.fromPeaks(this.hasher, this.state.recentBlocks.accumulationLog)
23578
+ const mmr = this.state.recentBlocks.asCurrent().accumulationLog !== null
23579
+ ? MerkleMountainRange.fromPeaks(this.hasher, this.state.recentBlocks.asCurrent().accumulationLog)
23763
23580
  : MerkleMountainRange.empty(this.hasher);
23764
23581
  // append the accumulation root
23765
23582
  mmr.append(input.accumulateRoot);
@@ -23777,7 +23594,7 @@ class RecentHistory {
23777
23594
  }
23778
23595
  // write back to the state.
23779
23596
  return {
23780
- recentBlocks: RecentBlocks.create(RecentBlocks.create({
23597
+ recentBlocks: RecentBlocksHistory.create(RecentBlocks.create({
23781
23598
  blocks: sized_array_asKnownSize(recentBlocks),
23782
23599
  accumulationLog: peaks,
23783
23600
  })),
@@ -23989,6 +23806,7 @@ function verifyReportsBasic(input) {
23989
23806
 
23990
23807
 
23991
23808
 
23809
+
23992
23810
  const verify_contextual_logger = Logger.new(import.meta.filename, "stf:reports");
23993
23811
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/15eb0115eb01?v=0.6.7 */
23994
23812
  function verifyContextualValidity(input, state, headerChain, maxLookupAnchorAge) {
@@ -24101,7 +23919,7 @@ function verifyRefineContexts(minLookupSlot, contexts, recentBlocksPartialUpdate
24101
23919
  return result_Result.error(ReportsError.BadStateRoot, `Anchor state root mismatch. Got: ${context.stateRoot}, expected: ${recentBlock.postStateRoot}.`);
24102
23920
  }
24103
23921
  // check beefy root
24104
- const beefyRoot = recentBlock.accumulationResult;
23922
+ const beefyRoot = RecentBlocksHistory.accumulationResult(recentBlock);
24105
23923
  if (!beefyRoot.isEqualTo(context.beefyRoot)) {
24106
23924
  return result_Result.error(ReportsError.BadBeefyMmrRoot, `Invalid BEEFY super peak hash. Got: ${context.beefyRoot}, expected: ${beefyRoot}. Anchor: ${recentBlock.headerHash}`);
24107
23925
  }
@@ -24343,9 +24161,8 @@ function verifyPostSignatureChecks(input, availabilityAssignment, authPools, ser
24343
24161
  * https://graypaper.fluffylabs.dev/#/5f542d7/15eb0015ed00
24344
24162
  */
24345
24163
  const authorizerHash = report.authorizerHash;
24346
- const authorizerPool = authPools.get(coreIndex);
24347
- const pool = authorizerPool?.materialize() ?? [];
24348
- if (pool.find((hash) => hash.isEqualTo(authorizerHash)) === undefined) {
24164
+ const authorizerPool = authPools[coreIndex];
24165
+ if (authorizerPool.find((hash) => hash.isEqualTo(authorizerHash)) === undefined) {
24349
24166
  return result_Result.error(ReportsError.CoreUnauthorized, `Authorizer hash not found in the pool of core ${coreIndex}: ${authorizerHash}`);
24350
24167
  }
24351
24168
  /**
@@ -24475,8 +24292,7 @@ class Reports {
24475
24292
  return verifyCredentials(input.guarantees, workReportHashes, input.slot, (headerTimeSlot, guaranteeTimeSlot) => this.getGuarantorAssignment(headerTimeSlot, guaranteeTimeSlot, input.newEntropy));
24476
24293
  }
24477
24294
  verifyPostSignatureChecks(input, assurancesAvailAssignment) {
24478
- const authPoolsView = this.state.view().authPoolsView();
24479
- return verifyPostSignatureChecks(input, assurancesAvailAssignment, authPoolsView, (id) => this.state.getService(id));
24295
+ return verifyPostSignatureChecks(input, assurancesAvailAssignment, this.state.authPools, (id) => this.state.getService(id));
24480
24296
  }
24481
24297
  verifyContextualValidity(input) {
24482
24298
  return verifyContextualValidity(input, this.state, this.headerChain, this.chainSpec.maxLookupAnchorAge);