@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.
package/index.js CHANGED
@@ -26373,9 +26373,6 @@ class ObjectView {
26373
26373
  toString() {
26374
26374
  return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
26375
26375
  }
26376
- [TEST_COMPARE_USING]() {
26377
- return this.materialize();
26378
- }
26379
26376
  }
26380
26377
  /**
26381
26378
  * A lazy-evaluated decoder of a sequence.
@@ -26508,7 +26505,7 @@ const TYPICAL_DICTIONARY_LENGTH = 32;
26508
26505
  * It's not true in a general case, but should be good enough for us.
26509
26506
  *
26510
26507
  */
26511
- function descriptors_readonlyArray(desc) {
26508
+ function readonlyArray(desc) {
26512
26509
  return desc.convert((x) => {
26513
26510
  debug_check `
26514
26511
  ${Array.isArray(x)}
@@ -26670,15 +26667,7 @@ var descriptors_codec;
26670
26667
  /** Custom encoding / decoding logic. */
26671
26668
  codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
26672
26669
  /** Choose a descriptor depending on the encoding/decoding context. */
26673
- codec.select = ({ name, sizeHint, }, chooser) => {
26674
- const Self = chooser(null);
26675
- 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)
26676
- ? codec.select({
26677
- name: Self.View.name,
26678
- sizeHint: Self.View.sizeHint,
26679
- }, (ctx) => chooser(ctx).View)
26680
- : Self.View);
26681
- };
26670
+ 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);
26682
26671
  /**
26683
26672
  * A descriptor for a more complex POJO.
26684
26673
  *
@@ -27500,7 +27489,7 @@ const BANDERSNATCH_KEY_BYTES = 32;
27500
27489
  /** Bandersnatch VRF signature size */
27501
27490
  const BANDERSNATCH_VRF_SIGNATURE_BYTES = 96;
27502
27491
  /** Bandersnatch ring commitment size */
27503
- const bandersnatch_BANDERSNATCH_RING_ROOT_BYTES = 144;
27492
+ const BANDERSNATCH_RING_ROOT_BYTES = 144;
27504
27493
  /** Bandersnatch proof size */
27505
27494
  const BANDERSNATCH_PROOF_BYTES = 784;
27506
27495
  /** BLS public key size. */
@@ -29081,9 +29070,9 @@ function codecWithContext(chooser) {
29081
29070
  /** Codec for a known-size array with length validation. */
29082
29071
  const codecKnownSizeArray = (val, options, _id) => {
29083
29072
  if ("fixedLength" in options) {
29084
- return descriptors_readonlyArray(descriptors_codec.sequenceFixLen(val, options.fixedLength)).convert(seeThrough, sized_array_asKnownSize);
29073
+ return readonlyArray(descriptors_codec.sequenceFixLen(val, options.fixedLength)).convert(seeThrough, sized_array_asKnownSize);
29085
29074
  }
29086
- return descriptors_readonlyArray(descriptors_codec.sequenceVarLen(val, options)).convert(seeThrough, sized_array_asKnownSize);
29075
+ return readonlyArray(descriptors_codec.sequenceVarLen(val, options)).convert(seeThrough, sized_array_asKnownSize);
29087
29076
  };
29088
29077
  /** Codec for a fixed-size array with length validation. */
29089
29078
  const codecFixedSizeArray = (val, len) => {
@@ -29457,16 +29446,16 @@ class SignedTicket extends WithDebug {
29457
29446
  }
29458
29447
  }
29459
29448
  /** Anonymous? entry into the ticket contest. */
29460
- class tickets_Ticket extends WithDebug {
29449
+ class Ticket extends WithDebug {
29461
29450
  id;
29462
29451
  attempt;
29463
- static Codec = descriptors_codec.Class(tickets_Ticket, {
29452
+ static Codec = descriptors_codec.Class(Ticket, {
29464
29453
  id: descriptors_codec.bytes(hash_HASH_SIZE),
29465
29454
  // TODO [ToDr] we should verify that attempt is either 0|1|2.
29466
29455
  attempt: descriptors_codec.u8.asOpaque(),
29467
29456
  });
29468
29457
  static create({ id, attempt }) {
29469
- return new tickets_Ticket(id, attempt);
29458
+ return new Ticket(id, attempt);
29470
29459
  }
29471
29460
  constructor(
29472
29461
  /**
@@ -29578,7 +29567,7 @@ function tryAsPerValidator(array, spec) {
29578
29567
  `;
29579
29568
  return sized_array_asKnownSize(array);
29580
29569
  }
29581
- const common_codecPerValidator = (val) => codecWithContext((context) => {
29570
+ const codecPerValidator = (val) => codecWithContext((context) => {
29582
29571
  return codecKnownSizeArray(val, {
29583
29572
  fixedLength: context.validatorsCount,
29584
29573
  });
@@ -29705,7 +29694,7 @@ class Verdict extends WithDebug {
29705
29694
  workReportHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
29706
29695
  votesEpoch: descriptors_codec.u32.asOpaque(),
29707
29696
  votes: codecWithContext((context) => {
29708
- return descriptors_readonlyArray(descriptors_codec.sequenceFixLen(Judgement.Codec, context.validatorsSuperMajority)).convert(seeThrough, sized_array_asKnownSize);
29697
+ return readonlyArray(descriptors_codec.sequenceFixLen(Judgement.Codec, context.validatorsSuperMajority)).convert(seeThrough, sized_array_asKnownSize);
29709
29698
  }),
29710
29699
  });
29711
29700
  static create({ workReportHash, votesEpoch, votes }) {
@@ -30397,7 +30386,7 @@ const WorkReportCodec = descriptors_codec.Class(WorkReportNoCodec, {
30397
30386
  authorizerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
30398
30387
  authorizationGasUsed: descriptors_codec.varU64.asOpaque(),
30399
30388
  authorizationOutput: descriptors_codec.blob,
30400
- segmentRootLookup: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
30389
+ segmentRootLookup: readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
30401
30390
  results: descriptors_codec.sequenceVarLen(WorkResult.Codec).convert((x) => x, (items) => FixedSizeArray.new(items, tryAsWorkItemsCount(items.length))),
30402
30391
  });
30403
30392
  const WorkReportCodecPre070 = descriptors_codec.Class(WorkReportNoCodec, {
@@ -30411,7 +30400,7 @@ const WorkReportCodecPre070 = descriptors_codec.Class(WorkReportNoCodec, {
30411
30400
  }),
30412
30401
  authorizerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
30413
30402
  authorizationOutput: descriptors_codec.blob,
30414
- segmentRootLookup: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
30403
+ segmentRootLookup: readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
30415
30404
  results: descriptors_codec.sequenceVarLen(WorkResult.Codec).convert((x) => x, (items) => FixedSizeArray.new(items, tryAsWorkItemsCount(items.length))),
30416
30405
  authorizationGasUsed: descriptors_codec.varU64.asOpaque(),
30417
30406
  });
@@ -30532,7 +30521,7 @@ class ValidatorKeys extends WithDebug {
30532
30521
  class TicketsMarker extends WithDebug {
30533
30522
  tickets;
30534
30523
  static Codec = descriptors_codec.Class(TicketsMarker, {
30535
- tickets: codecPerEpochBlock(tickets_Ticket.Codec),
30524
+ tickets: codecPerEpochBlock(Ticket.Codec),
30536
30525
  });
30537
30526
  static create({ tickets }) {
30538
30527
  return new TicketsMarker(tickets);
@@ -30556,7 +30545,7 @@ class EpochMarker extends WithDebug {
30556
30545
  static Codec = descriptors_codec.Class(EpochMarker, {
30557
30546
  entropy: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
30558
30547
  ticketsEntropy: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
30559
- validators: common_codecPerValidator(ValidatorKeys.Codec),
30548
+ validators: codecPerValidator(ValidatorKeys.Codec),
30560
30549
  });
30561
30550
  static create({ entropy, ticketsEntropy, validators }) {
30562
30551
  return new EpochMarker(entropy, ticketsEntropy, validators);
@@ -30828,19 +30817,6 @@ function emptyBlock(slot = tryAsTimeSlot(0)) {
30828
30817
  });
30829
30818
  }
30830
30819
 
30831
- ;// CONCATENATED MODULE: ./packages/jam/block/utils.ts
30832
-
30833
- /**
30834
- * Take an input data and re-encode that data as view.
30835
- *
30836
- * NOTE: this function should NEVER be used in any production code,
30837
- * it's only a test helper.
30838
- */
30839
- function reencodeAsView(codec, object, chainSpec) {
30840
- const encoded = encoder_Encoder.encodeObject(codec, object, chainSpec);
30841
- return decoder_Decoder.decodeObject(codec.View, encoded, chainSpec);
30842
- }
30843
-
30844
30820
  ;// CONCATENATED MODULE: ./packages/jam/block/index.ts
30845
30821
 
30846
30822
 
@@ -30859,7 +30835,6 @@ function reencodeAsView(codec, object, chainSpec) {
30859
30835
 
30860
30836
 
30861
30837
 
30862
-
30863
30838
  ;// CONCATENATED MODULE: ./packages/jam/block-json/disputes-extrinsic.ts
30864
30839
 
30865
30840
 
@@ -31099,7 +31074,7 @@ const epochMark = json.object({
31099
31074
  const ticket = json.object({
31100
31075
  id: fromJson.bytes32(),
31101
31076
  attempt: fromJson.ticketAttempt,
31102
- }, (x) => tickets_Ticket.create({ id: x.id, attempt: x.attempt }));
31077
+ }, (x) => Ticket.create({ id: x.id, attempt: x.attempt }));
31103
31078
  const headerFromJson = json.object({
31104
31079
  parent: fromJson.bytes32(),
31105
31080
  parent_state_root: fromJson.bytes32(),
@@ -32024,128 +31999,10 @@ function accumulationOutputComparator(a, b) {
32024
31999
  return Ordering.Equal;
32025
32000
  }
32026
32001
 
32027
- ;// CONCATENATED MODULE: ./packages/jam/block/gp-constants.ts
32028
-
32029
- /**
32030
- * This file lists all of the constants defined in the GrayPaper appendix.
32031
- *
32032
- * NOTE: Avoid using the constants directly, prefer "named" constants defined
32033
- * in a semantical proximity to where they are used.
32034
- *
32035
- * NOTE: This file will most likely be removed in the future. The constants
32036
- * here are only temporarily for convenience. When we figure out better names
32037
- * and places for these this file will be eradicated.
32038
- *
32039
- * https://graypaper.fluffylabs.dev/#/579bd12/413000413000
32040
- */
32041
- /** `G_I`: The gas allocated to invoke a work-package’s Is-Authorized logic. */
32042
- const G_I = 50_000_000;
32043
- /** `I`: Maximum number of work items in a package. */
32044
- const gp_constants_I = (/* unused pure expression or super */ null && (MAX_NUMBER_OF_WORK_ITEMS));
32045
- /** `O`: Maximum number of items in the authorizations pool. */
32046
- const O = 8;
32047
- /** `Q`: The number of items in the authorizations queue. */
32048
- const Q = 80;
32049
- /** `S`: The maximum number of entries in the accumulation queue. */
32050
- const S = 1024;
32051
- /** `T`: The maximum number of extrinsics in a work-package. */
32052
- const T = 128;
32053
- /** `W_A`: The maximum size of is-authorized code in octets. */
32054
- const W_A = 64_000;
32055
- /** `W_B`: The maximum size of an encoded work-package with extrinsic data and imports. */
32056
- const W_B = 13_794_305;
32057
- /** `W_C`: The maximum size of service code in octets. */
32058
- const W_C = 4_000_000;
32059
- /** `W_M`: The maximum number of imports in a work-package. */
32060
- const W_M = 3_072;
32061
- /** `W_R`: The maximum total size of all output blobs in a work-report, in octets. */
32062
- const W_R = 49_152;
32063
- /** `W_T`: The size of a transfer memo in octets. */
32064
- const W_T = 128;
32065
- /** `W_M`: The maximum number of exports in a work-package. */
32066
- const W_X = 3_072;
32067
- // TODO [ToDr] Not sure where these should live yet :(
32068
- /**
32069
- * `S`: The minimum public service index.
32070
- * Services of indices below these may only be created by the Registrar.
32071
- *
32072
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
32073
- */
32074
- const MIN_PUBLIC_SERVICE_INDEX = 2 ** 16;
32075
- /**
32076
- * `J`: The maximum sum of dependency items in a work-report.
32077
- *
32078
- * https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
32079
- */
32080
- const MAX_REPORT_DEPENDENCIES = 8;
32081
-
32082
- ;// CONCATENATED MODULE: ./packages/jam/state/accumulation-queue.ts
32083
-
32084
-
32085
-
32086
-
32087
-
32088
-
32089
-
32090
- /**
32091
- * Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
32092
- *
32093
- * https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
32094
- */
32095
- class NotYetAccumulatedReport extends WithDebug {
32096
- report;
32097
- dependencies;
32098
- static Codec = descriptors_codec.Class(NotYetAccumulatedReport, {
32099
- report: WorkReport.Codec,
32100
- dependencies: codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
32101
- typicalLength: MAX_REPORT_DEPENDENCIES / 2,
32102
- maxLength: MAX_REPORT_DEPENDENCIES,
32103
- minLength: 0,
32104
- }),
32105
- });
32106
- static create({ report, dependencies }) {
32107
- return new NotYetAccumulatedReport(report, dependencies);
32108
- }
32109
- constructor(
32110
- /**
32111
- * Each of these were made available at most one epoch ago
32112
- * but have or had unfulfilled dependencies.
32113
- */
32114
- report,
32115
- /**
32116
- * Alongside the work-report itself, we retain its un-accumulated
32117
- * dependencies, a set of work-package hashes.
32118
- *
32119
- * https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
32120
- */
32121
- dependencies) {
32122
- super();
32123
- this.report = report;
32124
- this.dependencies = dependencies;
32125
- }
32126
- }
32127
- const accumulationQueueCodec = codecPerEpochBlock(descriptors_readonlyArray(descriptors_codec.sequenceVarLen(NotYetAccumulatedReport.Codec)));
32128
-
32129
- ;// CONCATENATED MODULE: ./packages/jam/state/common.ts
32130
-
32131
-
32132
- /** Check if given array has correct length before casting to the opaque type. */
32133
- function tryAsPerCore(array, spec) {
32134
- debug_check `
32135
- ${array.length === spec.coresCount}
32136
- Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
32137
- `;
32138
- return opaque_asOpaqueType(array);
32139
- }
32140
- const codecPerCore = (val) => codecWithContext((context) => {
32141
- return codecKnownSizeArray(val, { fixedLength: context.coresCount });
32142
- });
32143
-
32144
32002
  ;// CONCATENATED MODULE: ./packages/jam/state/assurances.ts
32145
32003
 
32146
32004
 
32147
32005
 
32148
-
32149
32006
  /**
32150
32007
  * Assignment of particular work report to a core.
32151
32008
  *
@@ -32174,30 +32031,27 @@ class AvailabilityAssignment extends WithDebug {
32174
32031
  this.timeout = timeout;
32175
32032
  }
32176
32033
  }
32177
- const availabilityAssignmentsCodec = codecPerCore(descriptors_codec.optional(AvailabilityAssignment.Codec));
32178
-
32179
- ;// CONCATENATED MODULE: ./packages/jam/state/auth.ts
32180
-
32181
-
32182
32034
 
32035
+ ;// CONCATENATED MODULE: ./packages/jam/state/common.ts
32183
32036
 
32184
32037
 
32185
- /** `O`: Maximal authorization pool size. */
32186
- const MAX_AUTH_POOL_SIZE = O;
32187
- /** `Q`: Size of the authorization queue. */
32188
- const AUTHORIZATION_QUEUE_SIZE = Q;
32189
- const authPoolsCodec = codecPerCore(codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
32190
- minLength: 0,
32191
- maxLength: MAX_AUTH_POOL_SIZE,
32192
- typicalLength: MAX_AUTH_POOL_SIZE,
32193
- }));
32194
- const authQueuesCodec = codecPerCore(codecFixedSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE));
32038
+ /** Check if given array has correct length before casting to the opaque type. */
32039
+ function tryAsPerCore(array, spec) {
32040
+ debug_check `
32041
+ ${array.length === spec.coresCount}
32042
+ Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
32043
+ `;
32044
+ return opaque_asOpaqueType(array);
32045
+ }
32046
+ const codecPerCore = (val) => codecWithContext((context) => {
32047
+ return codecKnownSizeArray(val, { fixedLength: context.coresCount });
32048
+ });
32195
32049
 
32196
32050
  ;// CONCATENATED MODULE: ./packages/jam/state/disputes.ts
32197
32051
 
32198
32052
 
32199
32053
 
32200
- const sortedSetCodec = () => descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE))).convert((input) => input.array, (output) => {
32054
+ const sortedSetCodec = () => readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE))).convert((input) => input.array, (output) => {
32201
32055
  const typed = output.map((x) => x.asOpaque());
32202
32056
  return SortedSet.fromSortedArray(hashComparator, typed);
32203
32057
  });
@@ -32259,6 +32113,65 @@ function hashComparator(a, b) {
32259
32113
  return a.compare(b);
32260
32114
  }
32261
32115
 
32116
+ ;// CONCATENATED MODULE: ./packages/jam/block/gp-constants.ts
32117
+
32118
+ /**
32119
+ * This file lists all of the constants defined in the GrayPaper appendix.
32120
+ *
32121
+ * NOTE: Avoid using the constants directly, prefer "named" constants defined
32122
+ * in a semantical proximity to where they are used.
32123
+ *
32124
+ * NOTE: This file will most likely be removed in the future. The constants
32125
+ * here are only temporarily for convenience. When we figure out better names
32126
+ * and places for these this file will be eradicated.
32127
+ *
32128
+ * https://graypaper.fluffylabs.dev/#/579bd12/413000413000
32129
+ */
32130
+ /** `G_I`: The gas allocated to invoke a work-package’s Is-Authorized logic. */
32131
+ const G_I = 50_000_000;
32132
+ /** `I`: Maximum number of work items in a package. */
32133
+ const gp_constants_I = (/* unused pure expression or super */ null && (MAX_NUMBER_OF_WORK_ITEMS));
32134
+ /** `O`: Maximum number of items in the authorizations pool. */
32135
+ const O = 8;
32136
+ /** `Q`: The number of items in the authorizations queue. */
32137
+ const Q = 80;
32138
+ /** `S`: The maximum number of entries in the accumulation queue. */
32139
+ const S = 1024;
32140
+ /** `T`: The maximum number of extrinsics in a work-package. */
32141
+ const T = 128;
32142
+ /** `W_A`: The maximum size of is-authorized code in octets. */
32143
+ const W_A = 64_000;
32144
+ /** `W_B`: The maximum size of an encoded work-package with extrinsic data and imports. */
32145
+ const W_B = 13_794_305;
32146
+ /** `W_C`: The maximum size of service code in octets. */
32147
+ const W_C = 4_000_000;
32148
+ /** `W_M`: The maximum number of imports in a work-package. */
32149
+ const W_M = 3_072;
32150
+ /** `W_R`: The maximum total size of all output blobs in a work-report, in octets. */
32151
+ const W_R = 49_152;
32152
+ /** `W_T`: The size of a transfer memo in octets. */
32153
+ const W_T = 128;
32154
+ /** `W_M`: The maximum number of exports in a work-package. */
32155
+ const W_X = 3_072;
32156
+ // TODO [ToDr] Not sure where these should live yet :(
32157
+ /**
32158
+ * `S`: The minimum public service index.
32159
+ * Services of indices below these may only be created by the Registrar.
32160
+ *
32161
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
32162
+ */
32163
+ const MIN_PUBLIC_SERVICE_INDEX = 2 ** 16;
32164
+ /**
32165
+ * `J`: The maximum sum of dependency items in a work-report.
32166
+ *
32167
+ * https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
32168
+ */
32169
+ const MAX_REPORT_DEPENDENCIES = 8;
32170
+ /** `Q`: Size of the authorization queue. */
32171
+ const AUTHORIZATION_QUEUE_SIZE = Q;
32172
+ /** `O`: Maximal authorization pool size. */
32173
+ const MAX_AUTH_POOL_SIZE = O;
32174
+
32262
32175
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
32263
32176
  const MAX_VALUE = 4294967295;
32264
32177
  const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
@@ -32266,7 +32179,7 @@ const MIN_VALUE = -(2 ** 31);
32266
32179
  const MAX_SHIFT_U32 = 32;
32267
32180
  const MAX_SHIFT_U64 = 64n;
32268
32181
 
32269
- ;// CONCATENATED MODULE: ./packages/jam/state/recent-blocks.ts
32182
+ ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
32270
32183
 
32271
32184
 
32272
32185
 
@@ -32274,259 +32187,15 @@ const MAX_SHIFT_U64 = 64n;
32274
32187
 
32275
32188
 
32276
32189
  /**
32277
- * `H = 8`: The size of recent history, in blocks.
32190
+ * `B_S`: The basic minimum balance which all services require.
32278
32191
  *
32279
- * https://graypaper.fluffylabs.dev/#/579bd12/416300416500
32192
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
32280
32193
  */
32281
- const MAX_RECENT_HISTORY = 8;
32282
- /** Recent history of a single block. */
32283
- class BlockState extends WithDebug {
32284
- headerHash;
32285
- accumulationResult;
32286
- postStateRoot;
32287
- reported;
32288
- static Codec = descriptors_codec.Class(BlockState, {
32289
- headerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
32290
- accumulationResult: descriptors_codec.bytes(hash_HASH_SIZE),
32291
- postStateRoot: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
32292
- reported: codecHashDictionary(WorkPackageInfo.Codec, (x) => x.workPackageHash),
32293
- });
32294
- static create({ headerHash, accumulationResult, postStateRoot, reported }) {
32295
- return new BlockState(headerHash, accumulationResult, postStateRoot, reported);
32296
- }
32297
- constructor(
32298
- /** Header hash. */
32299
- headerHash,
32300
- /** Merkle mountain belt of accumulation result. */
32301
- accumulationResult,
32302
- /** Posterior state root filled in with a 1-block delay. */
32303
- postStateRoot,
32304
- /** Reported work packages (no more than number of cores). */
32305
- reported) {
32306
- super();
32307
- this.headerHash = headerHash;
32308
- this.accumulationResult = accumulationResult;
32309
- this.postStateRoot = postStateRoot;
32310
- this.reported = reported;
32311
- }
32312
- }
32194
+ const BASE_SERVICE_BALANCE = 100n;
32313
32195
  /**
32314
- * Recent history of blocks.
32196
+ * `B_I`: The additional minimum balance required per item of elective service state.
32315
32197
  *
32316
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
32317
- */
32318
- class RecentBlocks extends WithDebug {
32319
- blocks;
32320
- accumulationLog;
32321
- static Codec = descriptors_codec.Class(RecentBlocks, {
32322
- blocks: codecKnownSizeArray(BlockState.Codec, {
32323
- minLength: 0,
32324
- maxLength: MAX_RECENT_HISTORY,
32325
- typicalLength: MAX_RECENT_HISTORY,
32326
- }),
32327
- accumulationLog: descriptors_codec.object({
32328
- peaks: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.optional(descriptors_codec.bytes(hash_HASH_SIZE)))),
32329
- }),
32330
- });
32331
- static empty() {
32332
- return new RecentBlocks(sized_array_asKnownSize([]), {
32333
- peaks: [],
32334
- });
32335
- }
32336
- static create(a) {
32337
- return new RecentBlocks(a.blocks, a.accumulationLog);
32338
- }
32339
- constructor(
32340
- /**
32341
- * Most recent blocks.
32342
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fea010fea01?v=0.6.7
32343
- */
32344
- blocks,
32345
- /**
32346
- * Accumulation output log.
32347
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/0f02020f0202?v=0.6.7
32348
- */
32349
- accumulationLog) {
32350
- super();
32351
- this.blocks = blocks;
32352
- this.accumulationLog = accumulationLog;
32353
- }
32354
- }
32355
-
32356
- ;// CONCATENATED MODULE: ./packages/jam/state/recently-accumulated.ts
32357
-
32358
-
32359
-
32360
-
32361
- const recentlyAccumulatedCodec = codecPerEpochBlock(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque()).convert((x) => Array.from(x), (x) => HashSet.from(x)));
32362
-
32363
- ;// CONCATENATED MODULE: ./packages/jam/state/validator-data.ts
32364
-
32365
-
32366
-
32367
-
32368
- /**
32369
- * Fixed size of validator metadata.
32370
- *
32371
- * https://graypaper.fluffylabs.dev/#/5f542d7/0d55010d5501
32372
- */
32373
- const VALIDATOR_META_BYTES = 128;
32374
- /**
32375
- * Details about validators' identity.
32376
- *
32377
- * https://graypaper.fluffylabs.dev/#/5f542d7/0d4b010d4c01
32378
- */
32379
- class validator_data_ValidatorData extends WithDebug {
32380
- bandersnatch;
32381
- ed25519;
32382
- bls;
32383
- metadata;
32384
- static Codec = descriptors_codec.Class(validator_data_ValidatorData, {
32385
- bandersnatch: descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque(),
32386
- ed25519: descriptors_codec.bytes(ED25519_KEY_BYTES).asOpaque(),
32387
- bls: descriptors_codec.bytes(BLS_KEY_BYTES).asOpaque(),
32388
- metadata: descriptors_codec.bytes(VALIDATOR_META_BYTES),
32389
- });
32390
- static create({ ed25519, bandersnatch, bls, metadata }) {
32391
- return new validator_data_ValidatorData(bandersnatch, ed25519, bls, metadata);
32392
- }
32393
- constructor(
32394
- /** Bandersnatch public key. */
32395
- bandersnatch,
32396
- /** ED25519 key data. */
32397
- ed25519,
32398
- /** BLS public key. */
32399
- bls,
32400
- /** Validator-defined additional metdata. */
32401
- metadata) {
32402
- super();
32403
- this.bandersnatch = bandersnatch;
32404
- this.ed25519 = ed25519;
32405
- this.bls = bls;
32406
- this.metadata = metadata;
32407
- }
32408
- }
32409
- const validatorsDataCodec = common_codecPerValidator(validator_data_ValidatorData.Codec);
32410
-
32411
- ;// CONCATENATED MODULE: ./packages/jam/state/safrole-data.ts
32412
-
32413
-
32414
-
32415
-
32416
-
32417
-
32418
-
32419
-
32420
-
32421
-
32422
-
32423
- var SafroleSealingKeysKind;
32424
- (function (SafroleSealingKeysKind) {
32425
- SafroleSealingKeysKind[SafroleSealingKeysKind["Tickets"] = 0] = "Tickets";
32426
- SafroleSealingKeysKind[SafroleSealingKeysKind["Keys"] = 1] = "Keys";
32427
- })(SafroleSealingKeysKind || (SafroleSealingKeysKind = {}));
32428
- const codecBandersnatchKey = descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque();
32429
- class safrole_data_SafroleSealingKeysData extends WithDebug {
32430
- kind;
32431
- keys;
32432
- tickets;
32433
- static Codec = codecWithContext((context) => {
32434
- return descriptors_codec.custom({
32435
- name: "SafroleSealingKeys",
32436
- sizeHint: { bytes: 1 + hash_HASH_SIZE * context.epochLength, isExact: false },
32437
- }, (e, x) => {
32438
- e.varU32(numbers_tryAsU32(x.kind));
32439
- if (x.kind === SafroleSealingKeysKind.Keys) {
32440
- e.sequenceFixLen(codecBandersnatchKey, x.keys);
32441
- }
32442
- else {
32443
- e.sequenceFixLen(tickets_Ticket.Codec, x.tickets);
32444
- }
32445
- }, (d) => {
32446
- const epochLength = context.epochLength;
32447
- const kind = d.varU32();
32448
- if (kind === SafroleSealingKeysKind.Keys) {
32449
- const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
32450
- return safrole_data_SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
32451
- }
32452
- if (kind === SafroleSealingKeysKind.Tickets) {
32453
- const tickets = d.sequenceFixLen(tickets_Ticket.Codec, epochLength);
32454
- return safrole_data_SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
32455
- }
32456
- throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
32457
- }, (s) => {
32458
- const kind = s.decoder.varU32();
32459
- if (kind === SafroleSealingKeysKind.Keys) {
32460
- s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
32461
- return;
32462
- }
32463
- if (kind === SafroleSealingKeysKind.Tickets) {
32464
- s.sequenceFixLen(tickets_Ticket.Codec, context.epochLength);
32465
- return;
32466
- }
32467
- throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
32468
- });
32469
- });
32470
- static keys(keys) {
32471
- return new safrole_data_SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
32472
- }
32473
- static tickets(tickets) {
32474
- return new safrole_data_SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
32475
- }
32476
- constructor(kind, keys, tickets) {
32477
- super();
32478
- this.kind = kind;
32479
- this.keys = keys;
32480
- this.tickets = tickets;
32481
- }
32482
- }
32483
- class SafroleData {
32484
- nextValidatorData;
32485
- epochRoot;
32486
- sealingKeySeries;
32487
- ticketsAccumulator;
32488
- static Codec = descriptors_codec.Class(SafroleData, {
32489
- nextValidatorData: common_codecPerValidator(validator_data_ValidatorData.Codec),
32490
- epochRoot: descriptors_codec.bytes(bandersnatch_BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
32491
- sealingKeySeries: safrole_data_SafroleSealingKeysData.Codec,
32492
- ticketsAccumulator: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(tickets_Ticket.Codec)).convert(seeThrough, sized_array_asKnownSize),
32493
- });
32494
- static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
32495
- return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
32496
- }
32497
- constructor(
32498
- /** gamma_k */
32499
- nextValidatorData,
32500
- /** gamma_z */
32501
- epochRoot,
32502
- /** gamma_s */
32503
- sealingKeySeries,
32504
- /** gamma_a */
32505
- ticketsAccumulator) {
32506
- this.nextValidatorData = nextValidatorData;
32507
- this.epochRoot = epochRoot;
32508
- this.sealingKeySeries = sealingKeySeries;
32509
- this.ticketsAccumulator = ticketsAccumulator;
32510
- }
32511
- }
32512
-
32513
- ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
32514
-
32515
-
32516
-
32517
-
32518
-
32519
-
32520
- /**
32521
- * `B_S`: The basic minimum balance which all services require.
32522
- *
32523
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
32524
- */
32525
- const BASE_SERVICE_BALANCE = 100n;
32526
- /**
32527
- * `B_I`: The additional minimum balance required per item of elective service state.
32528
- *
32529
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
32198
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
32530
32199
  */
32531
32200
  const ELECTIVE_ITEM_BALANCE = 10n;
32532
32201
  /**
@@ -32700,418 +32369,358 @@ class LookupHistoryItem {
32700
32369
  }
32701
32370
  }
32702
32371
 
32703
- ;// CONCATENATED MODULE: ./packages/jam/state/statistics.ts
32704
-
32372
+ ;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
32705
32373
 
32706
32374
 
32707
32375
 
32708
32376
 
32709
32377
 
32710
- const codecServiceId = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
32711
- ? descriptors_codec.u32.asOpaque()
32712
- : descriptors_codec.varU32.convert((s) => numbers_tryAsU32(s), (i) => tryAsServiceId(i));
32713
- /**
32714
- * Activity Record of a single validator.
32715
- *
32716
- * https://graypaper.fluffylabs.dev/#/579bd12/183701183701
32717
- */
32718
- class ValidatorStatistics {
32719
- blocks;
32720
- tickets;
32721
- preImages;
32722
- preImagesSize;
32723
- guarantees;
32724
- assurances;
32725
- static Codec = descriptors_codec.Class(ValidatorStatistics, {
32726
- blocks: descriptors_codec.u32,
32727
- tickets: descriptors_codec.u32,
32728
- preImages: descriptors_codec.u32,
32729
- preImagesSize: descriptors_codec.u32,
32730
- guarantees: descriptors_codec.u32,
32731
- assurances: descriptors_codec.u32,
32378
+ /** Dictionary entry of services that auto-accumulate every block. */
32379
+ class AutoAccumulate {
32380
+ service;
32381
+ gasLimit;
32382
+ static Codec = descriptors_codec.Class(AutoAccumulate, {
32383
+ service: descriptors_codec.u32.asOpaque(),
32384
+ gasLimit: descriptors_codec.u64.asOpaque(),
32732
32385
  });
32733
- static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
32734
- return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
32386
+ static create({ service, gasLimit }) {
32387
+ return new AutoAccumulate(service, gasLimit);
32735
32388
  }
32736
32389
  constructor(
32737
- /** The number of blocks produced by the validator. */
32738
- blocks,
32739
- /** The number of tickets introduced by the validator. */
32740
- tickets,
32741
- /** The number of preimages introduced by the validator. */
32742
- preImages,
32743
- /** The total number of octets across all preimages introduced by the validator. */
32744
- preImagesSize,
32745
- /** The number of reports guaranteed by the validator. */
32746
- guarantees,
32747
- /** The number of availability assurances made by the validator. */
32748
- assurances) {
32749
- this.blocks = blocks;
32750
- this.tickets = tickets;
32751
- this.preImages = preImages;
32752
- this.preImagesSize = preImagesSize;
32753
- this.guarantees = guarantees;
32754
- this.assurances = assurances;
32755
- }
32756
- static empty() {
32757
- const zero = numbers_tryAsU32(0);
32758
- return new ValidatorStatistics(zero, zero, zero, zero, zero, zero);
32390
+ /** Service id that auto-accumulates. */
32391
+ service,
32392
+ /** Gas limit for auto-accumulation. */
32393
+ gasLimit) {
32394
+ this.service = service;
32395
+ this.gasLimit = gasLimit;
32759
32396
  }
32760
32397
  }
32761
- const codecVarU16 = descriptors_codec.varU32.convert((i) => numbers_tryAsU32(i), (o) => numbers_tryAsU16(o));
32762
- /** Encode/decode unsigned gas. */
32763
- const codecVarGas = descriptors_codec.varU64.convert((g) => numbers_tryAsU64(g), (i) => tryAsServiceGas(i));
32764
32398
  /**
32765
- * Single core statistics.
32766
- * Updated per block, based on incoming work reports (`w`).
32767
- *
32768
- * https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
32769
- * https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
32399
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
32770
32400
  */
32771
- class CoreStatistics {
32772
- dataAvailabilityLoad;
32773
- popularity;
32774
- imports;
32775
- exports;
32776
- extrinsicSize;
32777
- extrinsicCount;
32778
- bundleSize;
32779
- gasUsed;
32780
- static Codec = Compatibility.isGreaterOrEqual(GpVersion.V0_7_0)
32781
- ? descriptors_codec.Class(CoreStatistics, {
32782
- dataAvailabilityLoad: descriptors_codec.varU32,
32783
- popularity: codecVarU16,
32784
- imports: codecVarU16,
32785
- extrinsicCount: codecVarU16,
32786
- extrinsicSize: descriptors_codec.varU32,
32787
- exports: codecVarU16,
32788
- bundleSize: descriptors_codec.varU32,
32789
- gasUsed: codecVarGas,
32790
- })
32791
- : descriptors_codec.Class(CoreStatistics, {
32792
- dataAvailabilityLoad: descriptors_codec.varU32,
32793
- popularity: codecVarU16,
32794
- imports: codecVarU16,
32795
- exports: codecVarU16,
32796
- extrinsicSize: descriptors_codec.varU32,
32797
- extrinsicCount: codecVarU16,
32798
- bundleSize: descriptors_codec.varU32,
32799
- gasUsed: codecVarGas,
32800
- });
32801
- static create(v) {
32802
- return new CoreStatistics(v.dataAvailabilityLoad, v.popularity, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.bundleSize, v.gasUsed);
32401
+ class PrivilegedServices {
32402
+ manager;
32403
+ delegator;
32404
+ registrar;
32405
+ assigners;
32406
+ autoAccumulateServices;
32407
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
32408
+ static Codec = descriptors_codec.Class(PrivilegedServices, {
32409
+ manager: descriptors_codec.u32.asOpaque(),
32410
+ assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
32411
+ delegator: descriptors_codec.u32.asOpaque(),
32412
+ registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
32413
+ ? descriptors_codec.u32.asOpaque()
32414
+ : ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
32415
+ autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
32416
+ });
32417
+ static create(a) {
32418
+ return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
32803
32419
  }
32804
32420
  constructor(
32805
- /** `d` */
32806
- dataAvailabilityLoad,
32807
- /** `p` */
32808
- popularity,
32809
- /** `i` */
32810
- imports,
32811
- /** `e` */
32812
- exports,
32813
- /** `z` */
32814
- extrinsicSize,
32815
- /** `x` */
32816
- extrinsicCount,
32817
- /** `b` */
32818
- bundleSize,
32819
- /** `u` */
32820
- gasUsed) {
32821
- this.dataAvailabilityLoad = dataAvailabilityLoad;
32822
- this.popularity = popularity;
32823
- this.imports = imports;
32824
- this.exports = exports;
32825
- this.extrinsicSize = extrinsicSize;
32826
- this.extrinsicCount = extrinsicCount;
32827
- this.bundleSize = bundleSize;
32828
- this.gasUsed = gasUsed;
32829
- }
32830
- static empty() {
32831
- const zero = numbers_tryAsU32(0);
32832
- const zero16 = numbers_tryAsU16(0);
32833
- const zeroGas = tryAsServiceGas(0);
32834
- return new CoreStatistics(zero, zero16, zero16, zero16, zero, zero16, zero, zeroGas);
32421
+ /**
32422
+ * `χ_M`: Manages alteration of χ from block to block,
32423
+ * as well as bestow services with storage deposit credits.
32424
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
32425
+ */
32426
+ manager,
32427
+ /** `χ_V`: Managers validator keys. */
32428
+ delegator,
32429
+ /**
32430
+ * `χ_R`: Manages the creation of services in protected range.
32431
+ *
32432
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
32433
+ */
32434
+ registrar,
32435
+ /** `χ_A`: Manages authorization queue one for each core. */
32436
+ assigners,
32437
+ /** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
32438
+ autoAccumulateServices) {
32439
+ this.manager = manager;
32440
+ this.delegator = delegator;
32441
+ this.registrar = registrar;
32442
+ this.assigners = assigners;
32443
+ this.autoAccumulateServices = autoAccumulateServices;
32835
32444
  }
32836
32445
  }
32446
+
32447
+ ;// CONCATENATED MODULE: ./packages/jam/state/recent-blocks.ts
32448
+
32449
+
32450
+
32451
+
32452
+
32453
+
32837
32454
  /**
32838
- * Service statistics.
32839
- * Updated per block, based on available work reports (`W`).
32455
+ * `H = 8`: The size of recent history, in blocks.
32840
32456
  *
32841
- * https://graypaper.fluffylabs.dev/#/1c979cb/199802199802?v=0.7.1
32457
+ * https://graypaper.fluffylabs.dev/#/579bd12/416300416500
32842
32458
  */
32843
- class ServiceStatistics {
32844
- providedCount;
32845
- providedSize;
32846
- refinementCount;
32847
- refinementGasUsed;
32848
- imports;
32849
- exports;
32850
- extrinsicSize;
32851
- extrinsicCount;
32852
- accumulateCount;
32853
- accumulateGasUsed;
32854
- onTransfersCount;
32855
- onTransfersGasUsed;
32856
- static Codec = Compatibility.selectIfGreaterOrEqual({
32857
- fallback: descriptors_codec.Class(ServiceStatistics, {
32858
- providedCount: codecVarU16,
32859
- providedSize: descriptors_codec.varU32,
32860
- refinementCount: descriptors_codec.varU32,
32861
- refinementGasUsed: codecVarGas,
32862
- imports: codecVarU16,
32863
- exports: codecVarU16,
32864
- extrinsicSize: descriptors_codec.varU32,
32865
- extrinsicCount: codecVarU16,
32866
- accumulateCount: descriptors_codec.varU32,
32867
- accumulateGasUsed: codecVarGas,
32868
- onTransfersCount: descriptors_codec.varU32,
32869
- onTransfersGasUsed: codecVarGas,
32870
- }),
32871
- versions: {
32872
- [GpVersion.V0_7_0]: descriptors_codec.Class(ServiceStatistics, {
32873
- providedCount: codecVarU16,
32874
- providedSize: descriptors_codec.varU32,
32875
- refinementCount: descriptors_codec.varU32,
32876
- refinementGasUsed: codecVarGas,
32877
- imports: codecVarU16,
32878
- extrinsicCount: codecVarU16,
32879
- extrinsicSize: descriptors_codec.varU32,
32880
- exports: codecVarU16,
32881
- accumulateCount: descriptors_codec.varU32,
32882
- accumulateGasUsed: codecVarGas,
32883
- onTransfersCount: descriptors_codec.varU32,
32884
- onTransfersGasUsed: codecVarGas,
32885
- }),
32886
- [GpVersion.V0_7_1]: descriptors_codec.Class(ServiceStatistics, {
32887
- providedCount: codecVarU16,
32888
- providedSize: descriptors_codec.varU32,
32889
- refinementCount: descriptors_codec.varU32,
32890
- refinementGasUsed: codecVarGas,
32891
- imports: codecVarU16,
32892
- extrinsicCount: codecVarU16,
32893
- extrinsicSize: descriptors_codec.varU32,
32894
- exports: codecVarU16,
32895
- accumulateCount: descriptors_codec.varU32,
32896
- accumulateGasUsed: codecVarGas,
32897
- onTransfersCount: ignoreValueWithDefault(numbers_tryAsU32(0)),
32898
- onTransfersGasUsed: ignoreValueWithDefault(tryAsServiceGas(0)),
32899
- }),
32900
- },
32459
+ const MAX_RECENT_HISTORY = 8;
32460
+ /** Recent history of a single block. */
32461
+ class BlockState extends WithDebug {
32462
+ headerHash;
32463
+ accumulationResult;
32464
+ postStateRoot;
32465
+ reported;
32466
+ static Codec = descriptors_codec.Class(BlockState, {
32467
+ headerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
32468
+ accumulationResult: descriptors_codec.bytes(hash_HASH_SIZE),
32469
+ postStateRoot: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
32470
+ reported: codecHashDictionary(WorkPackageInfo.Codec, (x) => x.workPackageHash),
32901
32471
  });
32902
- static create(v) {
32903
- 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);
32472
+ static create({ headerHash, accumulationResult, postStateRoot, reported }) {
32473
+ return new BlockState(headerHash, accumulationResult, postStateRoot, reported);
32904
32474
  }
32905
32475
  constructor(
32906
- /** `p.0` */
32907
- providedCount,
32908
- /** `p.1` */
32909
- providedSize,
32910
- /** `r.0` */
32911
- refinementCount,
32912
- /** `r.1` */
32913
- refinementGasUsed,
32914
- /** `i` */
32915
- imports,
32916
- /** `e` */
32917
- exports,
32918
- /** `z` */
32919
- extrinsicSize,
32920
- /** `x` */
32921
- extrinsicCount,
32922
- /** `a.0` */
32923
- accumulateCount,
32924
- /** `a.1` */
32925
- accumulateGasUsed,
32926
- /** `t.0` @deprecated since 0.7.1 */
32927
- onTransfersCount,
32928
- /** `t.1` @deprecated since 0.7.1 */
32929
- onTransfersGasUsed) {
32930
- this.providedCount = providedCount;
32931
- this.providedSize = providedSize;
32932
- this.refinementCount = refinementCount;
32933
- this.refinementGasUsed = refinementGasUsed;
32934
- this.imports = imports;
32935
- this.exports = exports;
32936
- this.extrinsicSize = extrinsicSize;
32937
- this.extrinsicCount = extrinsicCount;
32938
- this.accumulateCount = accumulateCount;
32939
- this.accumulateGasUsed = accumulateGasUsed;
32940
- this.onTransfersCount = onTransfersCount;
32941
- this.onTransfersGasUsed = onTransfersGasUsed;
32476
+ /** Header hash. */
32477
+ headerHash,
32478
+ /** Merkle mountain belt of accumulation result. */
32479
+ accumulationResult,
32480
+ /** Posterior state root filled in with a 1-block delay. */
32481
+ postStateRoot,
32482
+ /** Reported work packages (no more than number of cores). */
32483
+ reported) {
32484
+ super();
32485
+ this.headerHash = headerHash;
32486
+ this.accumulationResult = accumulationResult;
32487
+ this.postStateRoot = postStateRoot;
32488
+ this.reported = reported;
32942
32489
  }
32943
- static empty() {
32944
- const zero = numbers_tryAsU32(0);
32945
- const zero16 = numbers_tryAsU16(0);
32946
- const zeroGas = tryAsServiceGas(0);
32947
- return new ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
32490
+ }
32491
+ class RecentBlocks extends WithDebug {
32492
+ blocks;
32493
+ accumulationLog;
32494
+ static Codec = descriptors_codec.Class(RecentBlocks, {
32495
+ blocks: codecKnownSizeArray(BlockState.Codec, {
32496
+ minLength: 0,
32497
+ maxLength: MAX_RECENT_HISTORY,
32498
+ typicalLength: MAX_RECENT_HISTORY,
32499
+ }),
32500
+ accumulationLog: descriptors_codec.object({
32501
+ peaks: readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.optional(descriptors_codec.bytes(hash_HASH_SIZE)))),
32502
+ }),
32503
+ });
32504
+ static create(a) {
32505
+ return new RecentBlocks(a.blocks, a.accumulationLog);
32506
+ }
32507
+ constructor(
32508
+ /**
32509
+ * Most recent blocks.
32510
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fea010fea01?v=0.6.7
32511
+ */
32512
+ blocks,
32513
+ /**
32514
+ * Accumulation output log.
32515
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/0f02020f0202?v=0.6.7
32516
+ */
32517
+ accumulationLog) {
32518
+ super();
32519
+ this.blocks = blocks;
32520
+ this.accumulationLog = accumulationLog;
32948
32521
  }
32949
32522
  }
32950
- /** `pi`: Statistics of each validator, cores statistics and services statistics. */
32951
- class StatisticsData {
32523
+ /**
32524
+ * Recent history of blocks.
32525
+ *
32526
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
32527
+ */
32528
+ class RecentBlocksHistory extends WithDebug {
32952
32529
  current;
32953
- previous;
32954
- cores;
32955
- services;
32956
- static Codec = descriptors_codec.Class(StatisticsData, {
32957
- current: common_codecPerValidator(ValidatorStatistics.Codec),
32958
- previous: common_codecPerValidator(ValidatorStatistics.Codec),
32959
- cores: codecPerCore(CoreStatistics.Codec),
32960
- services: descriptors_codec.dictionary(codecServiceId, ServiceStatistics.Codec, {
32961
- sortKeys: (a, b) => a - b,
32962
- }),
32530
+ static Codec = Descriptor.new("RecentBlocksHistory", RecentBlocks.Codec.sizeHint, (encoder, value) => RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
32531
+ const recentBlocks = RecentBlocks.Codec.decode(decoder);
32532
+ return RecentBlocksHistory.create(recentBlocks);
32533
+ }, (skip) => {
32534
+ return RecentBlocks.Codec.skip(skip);
32963
32535
  });
32964
- static create(v) {
32965
- return new StatisticsData(v.current, v.previous, v.cores, v.services);
32536
+ static create(recentBlocks) {
32537
+ return new RecentBlocksHistory(recentBlocks);
32966
32538
  }
32967
- constructor(current, previous, cores, services) {
32539
+ static empty() {
32540
+ return RecentBlocksHistory.create(RecentBlocks.create({
32541
+ blocks: sized_array_asKnownSize([]),
32542
+ accumulationLog: { peaks: [] },
32543
+ }));
32544
+ }
32545
+ /**
32546
+ * Returns the block's BEEFY super peak.
32547
+ */
32548
+ static accumulationResult(block) {
32549
+ return block.accumulationResult;
32550
+ }
32551
+ constructor(current) {
32552
+ super();
32968
32553
  this.current = current;
32969
- this.previous = previous;
32970
- this.cores = cores;
32971
- this.services = services;
32554
+ }
32555
+ /** History of recent blocks with maximum size of `MAX_RECENT_HISTORY` */
32556
+ get blocks() {
32557
+ if (this.current !== null) {
32558
+ return this.current.blocks;
32559
+ }
32560
+ throw new Error("RecentBlocksHistory is in invalid state");
32561
+ }
32562
+ asCurrent() {
32563
+ if (this.current === null) {
32564
+ throw new Error("Cannot access current RecentBlocks format");
32565
+ }
32566
+ return this.current;
32567
+ }
32568
+ updateBlocks(blocks) {
32569
+ if (this.current !== null) {
32570
+ return RecentBlocksHistory.create(RecentBlocks.create({
32571
+ ...this.current,
32572
+ blocks: opaque_asOpaqueType(blocks),
32573
+ }));
32574
+ }
32575
+ throw new Error("RecentBlocksHistory is in invalid state. Cannot be updated!");
32972
32576
  }
32973
32577
  }
32974
32578
 
32975
- ;// CONCATENATED MODULE: ./packages/jam/state/in-memory-state-view.ts
32579
+ ;// CONCATENATED MODULE: ./packages/jam/state/validator-data.ts
32976
32580
 
32977
32581
 
32978
32582
 
32583
+ /**
32584
+ * Fixed size of validator metadata.
32585
+ *
32586
+ * https://graypaper.fluffylabs.dev/#/5f542d7/0d55010d5501
32587
+ */
32588
+ const VALIDATOR_META_BYTES = 128;
32589
+ /**
32590
+ * Details about validators' identity.
32591
+ *
32592
+ * https://graypaper.fluffylabs.dev/#/5f542d7/0d4b010d4c01
32593
+ */
32594
+ class ValidatorData extends WithDebug {
32595
+ bandersnatch;
32596
+ ed25519;
32597
+ bls;
32598
+ metadata;
32599
+ static Codec = descriptors_codec.Class(ValidatorData, {
32600
+ bandersnatch: descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque(),
32601
+ ed25519: descriptors_codec.bytes(ED25519_KEY_BYTES).asOpaque(),
32602
+ bls: descriptors_codec.bytes(BLS_KEY_BYTES).asOpaque(),
32603
+ metadata: descriptors_codec.bytes(VALIDATOR_META_BYTES),
32604
+ });
32605
+ static create({ ed25519, bandersnatch, bls, metadata }) {
32606
+ return new ValidatorData(bandersnatch, ed25519, bls, metadata);
32607
+ }
32608
+ constructor(
32609
+ /** Bandersnatch public key. */
32610
+ bandersnatch,
32611
+ /** ED25519 key data. */
32612
+ ed25519,
32613
+ /** BLS public key. */
32614
+ bls,
32615
+ /** Validator-defined additional metdata. */
32616
+ metadata) {
32617
+ super();
32618
+ this.bandersnatch = bandersnatch;
32619
+ this.ed25519 = ed25519;
32620
+ this.bls = bls;
32621
+ this.metadata = metadata;
32622
+ }
32623
+ }
32979
32624
 
32625
+ ;// CONCATENATED MODULE: ./packages/jam/state/safrole-data.ts
32980
32626
 
32981
32627
 
32982
32628
 
32983
32629
 
32984
32630
 
32985
32631
 
32986
- class InMemoryStateView {
32987
- chainSpec;
32988
- state;
32989
- constructor(chainSpec, state) {
32990
- this.chainSpec = chainSpec;
32991
- this.state = state;
32992
- }
32993
- availabilityAssignmentView() {
32994
- return reencodeAsView(availabilityAssignmentsCodec, this.state.availabilityAssignment, this.chainSpec);
32995
- }
32996
- designatedValidatorDataView() {
32997
- return reencodeAsView(validatorsDataCodec, this.state.designatedValidatorData, this.chainSpec);
32998
- }
32999
- currentValidatorDataView() {
33000
- return reencodeAsView(validatorsDataCodec, this.state.currentValidatorData, this.chainSpec);
33001
- }
33002
- previousValidatorDataView() {
33003
- return reencodeAsView(validatorsDataCodec, this.state.previousValidatorData, this.chainSpec);
33004
- }
33005
- authPoolsView() {
33006
- return reencodeAsView(authPoolsCodec, this.state.authPools, this.chainSpec);
33007
- }
33008
- authQueuesView() {
33009
- return reencodeAsView(authQueuesCodec, this.state.authQueues, this.chainSpec);
33010
- }
33011
- recentBlocksView() {
33012
- return reencodeAsView(RecentBlocks.Codec, this.state.recentBlocks, this.chainSpec);
33013
- }
33014
- statisticsView() {
33015
- return reencodeAsView(StatisticsData.Codec, this.state.statistics, this.chainSpec);
33016
- }
33017
- accumulationQueueView() {
33018
- return reencodeAsView(accumulationQueueCodec, this.state.accumulationQueue, this.chainSpec);
33019
- }
33020
- recentlyAccumulatedView() {
33021
- return reencodeAsView(recentlyAccumulatedCodec, this.state.recentlyAccumulated, this.chainSpec);
33022
- }
33023
- safroleDataView() {
33024
- // TODO [ToDr] Consider exposting `safrole` from state
33025
- // instead of individual fields
33026
- const safrole = SafroleData.create({
33027
- nextValidatorData: this.state.nextValidatorData,
33028
- epochRoot: this.state.epochRoot,
33029
- sealingKeySeries: this.state.sealingKeySeries,
33030
- ticketsAccumulator: this.state.ticketsAccumulator,
33031
- });
33032
- return reencodeAsView(SafroleData.Codec, safrole, this.chainSpec);
33033
- }
33034
- getServiceInfoView(id) {
33035
- const service = this.state.getService(id);
33036
- if (service === null) {
33037
- return null;
33038
- }
33039
- return reencodeAsView(ServiceAccountInfo.Codec, service.getInfo(), this.chainSpec);
33040
- }
33041
- }
33042
-
33043
- ;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
33044
32632
 
33045
32633
 
33046
32634
 
33047
32635
 
33048
32636
 
33049
- /** Dictionary entry of services that auto-accumulate every block. */
33050
- class AutoAccumulate {
33051
- service;
33052
- gasLimit;
33053
- static Codec = descriptors_codec.Class(AutoAccumulate, {
33054
- service: descriptors_codec.u32.asOpaque(),
33055
- gasLimit: descriptors_codec.u64.asOpaque(),
32637
+ var SafroleSealingKeysKind;
32638
+ (function (SafroleSealingKeysKind) {
32639
+ SafroleSealingKeysKind[SafroleSealingKeysKind["Tickets"] = 0] = "Tickets";
32640
+ SafroleSealingKeysKind[SafroleSealingKeysKind["Keys"] = 1] = "Keys";
32641
+ })(SafroleSealingKeysKind || (SafroleSealingKeysKind = {}));
32642
+ const codecBandersnatchKey = descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque();
32643
+ class SafroleSealingKeysData extends WithDebug {
32644
+ kind;
32645
+ keys;
32646
+ tickets;
32647
+ static Codec = codecWithContext((context) => {
32648
+ return descriptors_codec.custom({
32649
+ name: "SafroleSealingKeys",
32650
+ sizeHint: { bytes: 1 + hash_HASH_SIZE * context.epochLength, isExact: false },
32651
+ }, (e, x) => {
32652
+ e.varU32(numbers_tryAsU32(x.kind));
32653
+ if (x.kind === SafroleSealingKeysKind.Keys) {
32654
+ e.sequenceFixLen(codecBandersnatchKey, x.keys);
32655
+ }
32656
+ else {
32657
+ e.sequenceFixLen(Ticket.Codec, x.tickets);
32658
+ }
32659
+ }, (d) => {
32660
+ const epochLength = context.epochLength;
32661
+ const kind = d.varU32();
32662
+ if (kind === SafroleSealingKeysKind.Keys) {
32663
+ const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
32664
+ return SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
32665
+ }
32666
+ if (kind === SafroleSealingKeysKind.Tickets) {
32667
+ const tickets = d.sequenceFixLen(Ticket.Codec, epochLength);
32668
+ return SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
32669
+ }
32670
+ throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
32671
+ }, (s) => {
32672
+ const kind = s.decoder.varU32();
32673
+ if (kind === SafroleSealingKeysKind.Keys) {
32674
+ s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
32675
+ return;
32676
+ }
32677
+ if (kind === SafroleSealingKeysKind.Tickets) {
32678
+ s.sequenceFixLen(Ticket.Codec, context.epochLength);
32679
+ return;
32680
+ }
32681
+ throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
32682
+ });
33056
32683
  });
33057
- static create({ service, gasLimit }) {
33058
- return new AutoAccumulate(service, gasLimit);
32684
+ static keys(keys) {
32685
+ return new SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
33059
32686
  }
33060
- constructor(
33061
- /** Service id that auto-accumulates. */
33062
- service,
33063
- /** Gas limit for auto-accumulation. */
33064
- gasLimit) {
33065
- this.service = service;
33066
- this.gasLimit = gasLimit;
32687
+ static tickets(tickets) {
32688
+ return new SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
32689
+ }
32690
+ constructor(kind, keys, tickets) {
32691
+ super();
32692
+ this.kind = kind;
32693
+ this.keys = keys;
32694
+ this.tickets = tickets;
33067
32695
  }
33068
32696
  }
33069
- /**
33070
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
33071
- */
33072
- class PrivilegedServices {
33073
- manager;
33074
- delegator;
33075
- registrar;
33076
- assigners;
33077
- autoAccumulateServices;
33078
- /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
33079
- static Codec = descriptors_codec.Class(PrivilegedServices, {
33080
- manager: descriptors_codec.u32.asOpaque(),
33081
- assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
33082
- delegator: descriptors_codec.u32.asOpaque(),
33083
- registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
33084
- ? descriptors_codec.u32.asOpaque()
33085
- : ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
33086
- autoAccumulateServices: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
32697
+ class SafroleData {
32698
+ nextValidatorData;
32699
+ epochRoot;
32700
+ sealingKeySeries;
32701
+ ticketsAccumulator;
32702
+ static Codec = descriptors_codec.Class(SafroleData, {
32703
+ nextValidatorData: codecPerValidator(ValidatorData.Codec),
32704
+ epochRoot: descriptors_codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
32705
+ sealingKeySeries: SafroleSealingKeysData.Codec,
32706
+ ticketsAccumulator: readonlyArray(descriptors_codec.sequenceVarLen(Ticket.Codec)).convert(seeThrough, sized_array_asKnownSize),
33087
32707
  });
33088
- static create(a) {
33089
- return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
32708
+ static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
32709
+ return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
33090
32710
  }
33091
32711
  constructor(
33092
- /**
33093
- * `χ_M`: Manages alteration of χ from block to block,
33094
- * as well as bestow services with storage deposit credits.
33095
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
33096
- */
33097
- manager,
33098
- /** `χ_V`: Managers validator keys. */
33099
- delegator,
33100
- /**
33101
- * `χ_R`: Manages the creation of services in protected range.
33102
- *
33103
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
33104
- */
33105
- registrar,
33106
- /** `χ_A`: Manages authorization queue one for each core. */
33107
- assigners,
33108
- /** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
33109
- autoAccumulateServices) {
33110
- this.manager = manager;
33111
- this.delegator = delegator;
33112
- this.registrar = registrar;
33113
- this.assigners = assigners;
33114
- this.autoAccumulateServices = autoAccumulateServices;
32712
+ /** gamma_k */
32713
+ nextValidatorData,
32714
+ /** gamma_z */
32715
+ epochRoot,
32716
+ /** gamma_s */
32717
+ sealingKeySeries,
32718
+ /** gamma_a */
32719
+ ticketsAccumulator) {
32720
+ this.nextValidatorData = nextValidatorData;
32721
+ this.epochRoot = epochRoot;
32722
+ this.sealingKeySeries = sealingKeySeries;
32723
+ this.ticketsAccumulator = ticketsAccumulator;
33115
32724
  }
33116
32725
  }
33117
32726
 
@@ -33245,34 +32854,306 @@ var UpdateStorageKind;
33245
32854
  UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
33246
32855
  })(UpdateStorageKind || (UpdateStorageKind = {}));
33247
32856
  /**
33248
- * Update service storage item.
32857
+ * Update service storage item.
32858
+ *
32859
+ * Can either create/modify an entry or remove it.
32860
+ */
32861
+ class UpdateStorage {
32862
+ serviceId;
32863
+ action;
32864
+ constructor(serviceId, action) {
32865
+ this.serviceId = serviceId;
32866
+ this.action = action;
32867
+ }
32868
+ static set({ serviceId, storage }) {
32869
+ return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Set, storage });
32870
+ }
32871
+ static remove({ serviceId, key }) {
32872
+ return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Remove, key });
32873
+ }
32874
+ get key() {
32875
+ if (this.action.kind === UpdateStorageKind.Remove) {
32876
+ return this.action.key;
32877
+ }
32878
+ return this.action.storage.key;
32879
+ }
32880
+ get value() {
32881
+ if (this.action.kind === UpdateStorageKind.Remove) {
32882
+ return null;
32883
+ }
32884
+ return this.action.storage.value;
32885
+ }
32886
+ }
32887
+
32888
+ ;// CONCATENATED MODULE: ./packages/jam/state/statistics.ts
32889
+
32890
+
32891
+
32892
+
32893
+
32894
+
32895
+ const codecServiceId = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
32896
+ ? descriptors_codec.u32.asOpaque()
32897
+ : descriptors_codec.varU32.convert((s) => numbers_tryAsU32(s), (i) => tryAsServiceId(i));
32898
+ /**
32899
+ * Activity Record of a single validator.
32900
+ *
32901
+ * https://graypaper.fluffylabs.dev/#/579bd12/183701183701
32902
+ */
32903
+ class ValidatorStatistics {
32904
+ blocks;
32905
+ tickets;
32906
+ preImages;
32907
+ preImagesSize;
32908
+ guarantees;
32909
+ assurances;
32910
+ static Codec = descriptors_codec.Class(ValidatorStatistics, {
32911
+ blocks: descriptors_codec.u32,
32912
+ tickets: descriptors_codec.u32,
32913
+ preImages: descriptors_codec.u32,
32914
+ preImagesSize: descriptors_codec.u32,
32915
+ guarantees: descriptors_codec.u32,
32916
+ assurances: descriptors_codec.u32,
32917
+ });
32918
+ static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
32919
+ return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
32920
+ }
32921
+ constructor(
32922
+ /** The number of blocks produced by the validator. */
32923
+ blocks,
32924
+ /** The number of tickets introduced by the validator. */
32925
+ tickets,
32926
+ /** The number of preimages introduced by the validator. */
32927
+ preImages,
32928
+ /** The total number of octets across all preimages introduced by the validator. */
32929
+ preImagesSize,
32930
+ /** The number of reports guaranteed by the validator. */
32931
+ guarantees,
32932
+ /** The number of availability assurances made by the validator. */
32933
+ assurances) {
32934
+ this.blocks = blocks;
32935
+ this.tickets = tickets;
32936
+ this.preImages = preImages;
32937
+ this.preImagesSize = preImagesSize;
32938
+ this.guarantees = guarantees;
32939
+ this.assurances = assurances;
32940
+ }
32941
+ static empty() {
32942
+ const zero = numbers_tryAsU32(0);
32943
+ return new ValidatorStatistics(zero, zero, zero, zero, zero, zero);
32944
+ }
32945
+ }
32946
+ const codecVarU16 = descriptors_codec.varU32.convert((i) => numbers_tryAsU32(i), (o) => numbers_tryAsU16(o));
32947
+ /** Encode/decode unsigned gas. */
32948
+ const codecVarGas = descriptors_codec.varU64.convert((g) => numbers_tryAsU64(g), (i) => tryAsServiceGas(i));
32949
+ /**
32950
+ * Single core statistics.
32951
+ * Updated per block, based on incoming work reports (`w`).
32952
+ *
32953
+ * https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
32954
+ * https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
32955
+ */
32956
+ class CoreStatistics {
32957
+ dataAvailabilityLoad;
32958
+ popularity;
32959
+ imports;
32960
+ exports;
32961
+ extrinsicSize;
32962
+ extrinsicCount;
32963
+ bundleSize;
32964
+ gasUsed;
32965
+ static Codec = Compatibility.isGreaterOrEqual(GpVersion.V0_7_0)
32966
+ ? descriptors_codec.Class(CoreStatistics, {
32967
+ dataAvailabilityLoad: descriptors_codec.varU32,
32968
+ popularity: codecVarU16,
32969
+ imports: codecVarU16,
32970
+ extrinsicCount: codecVarU16,
32971
+ extrinsicSize: descriptors_codec.varU32,
32972
+ exports: codecVarU16,
32973
+ bundleSize: descriptors_codec.varU32,
32974
+ gasUsed: codecVarGas,
32975
+ })
32976
+ : descriptors_codec.Class(CoreStatistics, {
32977
+ dataAvailabilityLoad: descriptors_codec.varU32,
32978
+ popularity: codecVarU16,
32979
+ imports: codecVarU16,
32980
+ exports: codecVarU16,
32981
+ extrinsicSize: descriptors_codec.varU32,
32982
+ extrinsicCount: codecVarU16,
32983
+ bundleSize: descriptors_codec.varU32,
32984
+ gasUsed: codecVarGas,
32985
+ });
32986
+ static create(v) {
32987
+ return new CoreStatistics(v.dataAvailabilityLoad, v.popularity, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.bundleSize, v.gasUsed);
32988
+ }
32989
+ constructor(
32990
+ /** `d` */
32991
+ dataAvailabilityLoad,
32992
+ /** `p` */
32993
+ popularity,
32994
+ /** `i` */
32995
+ imports,
32996
+ /** `e` */
32997
+ exports,
32998
+ /** `z` */
32999
+ extrinsicSize,
33000
+ /** `x` */
33001
+ extrinsicCount,
33002
+ /** `b` */
33003
+ bundleSize,
33004
+ /** `u` */
33005
+ gasUsed) {
33006
+ this.dataAvailabilityLoad = dataAvailabilityLoad;
33007
+ this.popularity = popularity;
33008
+ this.imports = imports;
33009
+ this.exports = exports;
33010
+ this.extrinsicSize = extrinsicSize;
33011
+ this.extrinsicCount = extrinsicCount;
33012
+ this.bundleSize = bundleSize;
33013
+ this.gasUsed = gasUsed;
33014
+ }
33015
+ static empty() {
33016
+ const zero = numbers_tryAsU32(0);
33017
+ const zero16 = numbers_tryAsU16(0);
33018
+ const zeroGas = tryAsServiceGas(0);
33019
+ return new CoreStatistics(zero, zero16, zero16, zero16, zero, zero16, zero, zeroGas);
33020
+ }
33021
+ }
33022
+ /**
33023
+ * Service statistics.
33024
+ * Updated per block, based on available work reports (`W`).
33249
33025
  *
33250
- * Can either create/modify an entry or remove it.
33026
+ * https://graypaper.fluffylabs.dev/#/1c979cb/199802199802?v=0.7.1
33251
33027
  */
33252
- class UpdateStorage {
33253
- serviceId;
33254
- action;
33255
- constructor(serviceId, action) {
33256
- this.serviceId = serviceId;
33257
- this.action = action;
33028
+ class ServiceStatistics {
33029
+ providedCount;
33030
+ providedSize;
33031
+ refinementCount;
33032
+ refinementGasUsed;
33033
+ imports;
33034
+ exports;
33035
+ extrinsicSize;
33036
+ extrinsicCount;
33037
+ accumulateCount;
33038
+ accumulateGasUsed;
33039
+ onTransfersCount;
33040
+ onTransfersGasUsed;
33041
+ static Codec = Compatibility.selectIfGreaterOrEqual({
33042
+ fallback: descriptors_codec.Class(ServiceStatistics, {
33043
+ providedCount: codecVarU16,
33044
+ providedSize: descriptors_codec.varU32,
33045
+ refinementCount: descriptors_codec.varU32,
33046
+ refinementGasUsed: codecVarGas,
33047
+ imports: codecVarU16,
33048
+ exports: codecVarU16,
33049
+ extrinsicSize: descriptors_codec.varU32,
33050
+ extrinsicCount: codecVarU16,
33051
+ accumulateCount: descriptors_codec.varU32,
33052
+ accumulateGasUsed: codecVarGas,
33053
+ onTransfersCount: descriptors_codec.varU32,
33054
+ onTransfersGasUsed: codecVarGas,
33055
+ }),
33056
+ versions: {
33057
+ [GpVersion.V0_7_0]: descriptors_codec.Class(ServiceStatistics, {
33058
+ providedCount: codecVarU16,
33059
+ providedSize: descriptors_codec.varU32,
33060
+ refinementCount: descriptors_codec.varU32,
33061
+ refinementGasUsed: codecVarGas,
33062
+ imports: codecVarU16,
33063
+ extrinsicCount: codecVarU16,
33064
+ extrinsicSize: descriptors_codec.varU32,
33065
+ exports: codecVarU16,
33066
+ accumulateCount: descriptors_codec.varU32,
33067
+ accumulateGasUsed: codecVarGas,
33068
+ onTransfersCount: descriptors_codec.varU32,
33069
+ onTransfersGasUsed: codecVarGas,
33070
+ }),
33071
+ [GpVersion.V0_7_1]: descriptors_codec.Class(ServiceStatistics, {
33072
+ providedCount: codecVarU16,
33073
+ providedSize: descriptors_codec.varU32,
33074
+ refinementCount: descriptors_codec.varU32,
33075
+ refinementGasUsed: codecVarGas,
33076
+ imports: codecVarU16,
33077
+ extrinsicCount: codecVarU16,
33078
+ extrinsicSize: descriptors_codec.varU32,
33079
+ exports: codecVarU16,
33080
+ accumulateCount: descriptors_codec.varU32,
33081
+ accumulateGasUsed: codecVarGas,
33082
+ onTransfersCount: ignoreValueWithDefault(numbers_tryAsU32(0)),
33083
+ onTransfersGasUsed: ignoreValueWithDefault(tryAsServiceGas(0)),
33084
+ }),
33085
+ },
33086
+ });
33087
+ static create(v) {
33088
+ 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);
33258
33089
  }
33259
- static set({ serviceId, storage }) {
33260
- return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Set, storage });
33090
+ constructor(
33091
+ /** `p.0` */
33092
+ providedCount,
33093
+ /** `p.1` */
33094
+ providedSize,
33095
+ /** `r.0` */
33096
+ refinementCount,
33097
+ /** `r.1` */
33098
+ refinementGasUsed,
33099
+ /** `i` */
33100
+ imports,
33101
+ /** `e` */
33102
+ exports,
33103
+ /** `z` */
33104
+ extrinsicSize,
33105
+ /** `x` */
33106
+ extrinsicCount,
33107
+ /** `a.0` */
33108
+ accumulateCount,
33109
+ /** `a.1` */
33110
+ accumulateGasUsed,
33111
+ /** `t.0` @deprecated since 0.7.1 */
33112
+ onTransfersCount,
33113
+ /** `t.1` @deprecated since 0.7.1 */
33114
+ onTransfersGasUsed) {
33115
+ this.providedCount = providedCount;
33116
+ this.providedSize = providedSize;
33117
+ this.refinementCount = refinementCount;
33118
+ this.refinementGasUsed = refinementGasUsed;
33119
+ this.imports = imports;
33120
+ this.exports = exports;
33121
+ this.extrinsicSize = extrinsicSize;
33122
+ this.extrinsicCount = extrinsicCount;
33123
+ this.accumulateCount = accumulateCount;
33124
+ this.accumulateGasUsed = accumulateGasUsed;
33125
+ this.onTransfersCount = onTransfersCount;
33126
+ this.onTransfersGasUsed = onTransfersGasUsed;
33261
33127
  }
33262
- static remove({ serviceId, key }) {
33263
- return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Remove, key });
33128
+ static empty() {
33129
+ const zero = numbers_tryAsU32(0);
33130
+ const zero16 = numbers_tryAsU16(0);
33131
+ const zeroGas = tryAsServiceGas(0);
33132
+ return new ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
33264
33133
  }
33265
- get key() {
33266
- if (this.action.kind === UpdateStorageKind.Remove) {
33267
- return this.action.key;
33268
- }
33269
- return this.action.storage.key;
33134
+ }
33135
+ /** `pi`: Statistics of each validator, cores statistics and services statistics. */
33136
+ class StatisticsData {
33137
+ current;
33138
+ previous;
33139
+ cores;
33140
+ services;
33141
+ static Codec = descriptors_codec.Class(StatisticsData, {
33142
+ current: codecPerValidator(ValidatorStatistics.Codec),
33143
+ previous: codecPerValidator(ValidatorStatistics.Codec),
33144
+ cores: codecPerCore(CoreStatistics.Codec),
33145
+ services: descriptors_codec.dictionary(codecServiceId, ServiceStatistics.Codec, {
33146
+ sortKeys: (a, b) => a - b,
33147
+ }),
33148
+ });
33149
+ static create(v) {
33150
+ return new StatisticsData(v.current, v.previous, v.cores, v.services);
33270
33151
  }
33271
- get value() {
33272
- if (this.action.kind === UpdateStorageKind.Remove) {
33273
- return null;
33274
- }
33275
- return this.action.storage.value;
33152
+ constructor(current, previous, cores, services) {
33153
+ this.current = current;
33154
+ this.previous = previous;
33155
+ this.cores = cores;
33156
+ this.services = services;
33276
33157
  }
33277
33158
  }
33278
33159
 
@@ -33297,7 +33178,6 @@ class UpdateStorage {
33297
33178
 
33298
33179
 
33299
33180
 
33300
-
33301
33181
 
33302
33182
 
33303
33183
  var in_memory_state_UpdateError;
@@ -33398,11 +33278,10 @@ class InMemoryService extends WithDebug {
33398
33278
  /**
33399
33279
  * A special version of state, stored fully in-memory.
33400
33280
  */
33401
- class in_memory_state_InMemoryState extends WithDebug {
33402
- chainSpec;
33281
+ class InMemoryState extends WithDebug {
33403
33282
  /** Create a new `InMemoryState` by providing all required fields. */
33404
- static new(chainSpec, state) {
33405
- return new in_memory_state_InMemoryState(chainSpec, state);
33283
+ static create(state) {
33284
+ return new InMemoryState(state);
33406
33285
  }
33407
33286
  /**
33408
33287
  * Create a new `InMemoryState` with a partial state override.
@@ -33411,14 +33290,14 @@ class in_memory_state_InMemoryState extends WithDebug {
33411
33290
  * not-necessarily coherent values.
33412
33291
  */
33413
33292
  static partial(spec, partial) {
33414
- const state = in_memory_state_InMemoryState.empty(spec);
33293
+ const state = InMemoryState.empty(spec);
33415
33294
  Object.assign(state, partial);
33416
33295
  return state;
33417
33296
  }
33418
33297
  /**
33419
33298
  * Create a new `InMemoryState` from some other state object.
33420
33299
  */
33421
- static copyFrom(chainSpec, other, servicesData) {
33300
+ static copyFrom(other, servicesData) {
33422
33301
  const services = new Map();
33423
33302
  for (const [id, entries] of servicesData.entries()) {
33424
33303
  const service = other.getService(id);
@@ -33428,7 +33307,7 @@ class in_memory_state_InMemoryState extends WithDebug {
33428
33307
  const inMemService = InMemoryService.copyFrom(service, entries);
33429
33308
  services.set(id, inMemService);
33430
33309
  }
33431
- return in_memory_state_InMemoryState.new(chainSpec, {
33310
+ return InMemoryState.create({
33432
33311
  availabilityAssignment: other.availabilityAssignment,
33433
33312
  accumulationQueue: other.accumulationQueue,
33434
33313
  designatedValidatorData: other.designatedValidatorData,
@@ -33625,9 +33504,8 @@ class in_memory_state_InMemoryState extends WithDebug {
33625
33504
  getService(id) {
33626
33505
  return this.services.get(id) ?? null;
33627
33506
  }
33628
- constructor(chainSpec, s) {
33507
+ constructor(s) {
33629
33508
  super();
33630
- this.chainSpec = chainSpec;
33631
33509
  this.availabilityAssignment = s.availabilityAssignment;
33632
33510
  this.designatedValidatorData = s.designatedValidatorData;
33633
33511
  this.nextValidatorData = s.nextValidatorData;
@@ -33649,34 +33527,31 @@ class in_memory_state_InMemoryState extends WithDebug {
33649
33527
  this.accumulationOutputLog = s.accumulationOutputLog;
33650
33528
  this.services = s.services;
33651
33529
  }
33652
- view() {
33653
- return new InMemoryStateView(this.chainSpec, this);
33654
- }
33655
33530
  /**
33656
33531
  * Create an empty and possibly incoherent `InMemoryState`.
33657
33532
  */
33658
33533
  static empty(spec) {
33659
- return new in_memory_state_InMemoryState(spec, {
33534
+ return new InMemoryState({
33660
33535
  availabilityAssignment: tryAsPerCore(Array.from({ length: spec.coresCount }, () => null), spec),
33661
- designatedValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
33536
+ designatedValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
33662
33537
  bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
33663
33538
  bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
33664
33539
  ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
33665
33540
  metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
33666
33541
  })), spec),
33667
- nextValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
33542
+ nextValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
33668
33543
  bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
33669
33544
  bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
33670
33545
  ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
33671
33546
  metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
33672
33547
  })), spec),
33673
- currentValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
33548
+ currentValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
33674
33549
  bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
33675
33550
  bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
33676
33551
  ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
33677
33552
  metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
33678
33553
  })), spec),
33679
- previousValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
33554
+ previousValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
33680
33555
  bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
33681
33556
  bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
33682
33557
  ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
@@ -33692,7 +33567,7 @@ class in_memory_state_InMemoryState extends WithDebug {
33692
33567
  entropy: FixedSizeArray.fill(() => bytes_Bytes.zero(hash_HASH_SIZE).asOpaque(), ENTROPY_ENTRIES),
33693
33568
  authPools: tryAsPerCore(Array.from({ length: spec.coresCount }, () => sized_array_asKnownSize([])), spec),
33694
33569
  authQueues: tryAsPerCore(Array.from({ length: spec.coresCount }, () => FixedSizeArray.fill(() => bytes_Bytes.zero(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE)), spec),
33695
- recentBlocks: RecentBlocks.empty(),
33570
+ recentBlocks: RecentBlocksHistory.empty(),
33696
33571
  statistics: StatisticsData.create({
33697
33572
  current: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
33698
33573
  previous: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
@@ -33702,8 +33577,8 @@ class in_memory_state_InMemoryState extends WithDebug {
33702
33577
  accumulationQueue: tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => []), spec),
33703
33578
  recentlyAccumulated: tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => HashSet.new()), spec),
33704
33579
  ticketsAccumulator: sized_array_asKnownSize([]),
33705
- sealingKeySeries: safrole_data_SafroleSealingKeysData.keys(tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque()), spec)),
33706
- epochRoot: bytes_Bytes.zero(bandersnatch_BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
33580
+ sealingKeySeries: SafroleSealingKeysData.keys(tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque()), spec)),
33581
+ epochRoot: bytes_Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
33707
33582
  privilegedServices: PrivilegedServices.create({
33708
33583
  manager: tryAsServiceId(0),
33709
33584
  assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
@@ -33743,10 +33618,51 @@ const serviceDataCodec = descriptors_codec.dictionary(descriptors_codec.u32.asOp
33743
33618
 
33744
33619
 
33745
33620
 
33621
+ ;// CONCATENATED MODULE: ./packages/jam/state/not-yet-accumulated.ts
33746
33622
 
33747
33623
 
33748
33624
 
33749
33625
 
33626
+
33627
+
33628
+ /**
33629
+ * Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
33630
+ *
33631
+ * https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
33632
+ */
33633
+ class NotYetAccumulatedReport extends WithDebug {
33634
+ report;
33635
+ dependencies;
33636
+ static Codec = descriptors_codec.Class(NotYetAccumulatedReport, {
33637
+ report: WorkReport.Codec,
33638
+ dependencies: codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
33639
+ typicalLength: MAX_REPORT_DEPENDENCIES / 2,
33640
+ maxLength: MAX_REPORT_DEPENDENCIES,
33641
+ minLength: 0,
33642
+ }),
33643
+ });
33644
+ static create({ report, dependencies }) {
33645
+ return new NotYetAccumulatedReport(report, dependencies);
33646
+ }
33647
+ constructor(
33648
+ /**
33649
+ * Each of these were made available at most one epoch ago
33650
+ * but have or had unfulfilled dependencies.
33651
+ */
33652
+ report,
33653
+ /**
33654
+ * Alongside the work-report itself, we retain its un-accumulated
33655
+ * dependencies, a set of work-package hashes.
33656
+ *
33657
+ * https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
33658
+ */
33659
+ dependencies) {
33660
+ super();
33661
+ this.report = report;
33662
+ this.dependencies = dependencies;
33663
+ }
33664
+ }
33665
+
33750
33666
  ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialize.ts
33751
33667
 
33752
33668
 
@@ -33759,19 +33675,26 @@ const serviceDataCodec = descriptors_codec.dictionary(descriptors_codec.u32.asOp
33759
33675
 
33760
33676
 
33761
33677
 
33678
+
33679
+
33680
+
33762
33681
  /** Serialization for particular state entries. */
33763
- var serialize_serialize;
33682
+ var serialize;
33764
33683
  (function (serialize) {
33765
33684
  /** C(1): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b15013b1501?v=0.6.7 */
33766
33685
  serialize.authPools = {
33767
33686
  key: stateKeys.index(StateKeyIdx.Alpha),
33768
- Codec: authPoolsCodec,
33687
+ Codec: codecPerCore(codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
33688
+ minLength: 0,
33689
+ maxLength: MAX_AUTH_POOL_SIZE,
33690
+ typicalLength: MAX_AUTH_POOL_SIZE,
33691
+ })),
33769
33692
  extract: (s) => s.authPools,
33770
33693
  };
33771
33694
  /** C(2): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b31013b3101?v=0.6.7 */
33772
33695
  serialize.authQueues = {
33773
33696
  key: stateKeys.index(StateKeyIdx.Phi),
33774
- Codec: authQueuesCodec,
33697
+ Codec: codecPerCore(codecFixedSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE)),
33775
33698
  extract: (s) => s.authQueues,
33776
33699
  };
33777
33700
  /**
@@ -33780,7 +33703,7 @@ var serialize_serialize;
33780
33703
  */
33781
33704
  serialize.recentBlocks = {
33782
33705
  key: stateKeys.index(StateKeyIdx.Beta),
33783
- Codec: RecentBlocks.Codec,
33706
+ Codec: RecentBlocksHistory.Codec,
33784
33707
  extract: (s) => s.recentBlocks,
33785
33708
  };
33786
33709
  /** C(4): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b63013b6301?v=0.6.7 */
@@ -33809,25 +33732,25 @@ var serialize_serialize;
33809
33732
  /** C(7): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b00023b0002?v=0.6.7 */
33810
33733
  serialize.designatedValidators = {
33811
33734
  key: stateKeys.index(StateKeyIdx.Iota),
33812
- Codec: validatorsDataCodec,
33735
+ Codec: codecPerValidator(ValidatorData.Codec),
33813
33736
  extract: (s) => s.designatedValidatorData,
33814
33737
  };
33815
33738
  /** C(8): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b0d023b0d02?v=0.6.7 */
33816
33739
  serialize.currentValidators = {
33817
33740
  key: stateKeys.index(StateKeyIdx.Kappa),
33818
- Codec: validatorsDataCodec,
33741
+ Codec: codecPerValidator(ValidatorData.Codec),
33819
33742
  extract: (s) => s.currentValidatorData,
33820
33743
  };
33821
33744
  /** C(9): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b1a023b1a02?v=0.6.7 */
33822
33745
  serialize.previousValidators = {
33823
33746
  key: stateKeys.index(StateKeyIdx.Lambda),
33824
- Codec: validatorsDataCodec,
33747
+ Codec: codecPerValidator(ValidatorData.Codec),
33825
33748
  extract: (s) => s.previousValidatorData,
33826
33749
  };
33827
33750
  /** C(10): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b27023b2702?v=0.6.7 */
33828
33751
  serialize.availabilityAssignment = {
33829
33752
  key: stateKeys.index(StateKeyIdx.Rho),
33830
- Codec: availabilityAssignmentsCodec,
33753
+ Codec: codecPerCore(descriptors_codec.optional(AvailabilityAssignment.Codec)),
33831
33754
  extract: (s) => s.availabilityAssignment,
33832
33755
  };
33833
33756
  /** C(11): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b3e023b3e02?v=0.6.7 */
@@ -33851,13 +33774,13 @@ var serialize_serialize;
33851
33774
  /** C(14): https://graypaper.fluffylabs.dev/#/1c979cb/3bf0023bf002?v=0.7.1 */
33852
33775
  serialize.accumulationQueue = {
33853
33776
  key: stateKeys.index(StateKeyIdx.Omega),
33854
- Codec: accumulationQueueCodec,
33777
+ Codec: codecPerEpochBlock(readonlyArray(descriptors_codec.sequenceVarLen(NotYetAccumulatedReport.Codec))),
33855
33778
  extract: (s) => s.accumulationQueue,
33856
33779
  };
33857
33780
  /** C(15): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b96023b9602?v=0.6.7 */
33858
33781
  serialize.recentlyAccumulated = {
33859
33782
  key: stateKeys.index(StateKeyIdx.Xi),
33860
- Codec: recentlyAccumulatedCodec,
33783
+ Codec: codecPerEpochBlock(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque()).convert((x) => Array.from(x), (x) => HashSet.from(x))),
33861
33784
  extract: (s) => s.recentlyAccumulated,
33862
33785
  };
33863
33786
  /** C(16): https://graypaper.fluffylabs.dev/#/38c4e62/3b46033b4603?v=0.7.0 */
@@ -33886,9 +33809,9 @@ var serialize_serialize;
33886
33809
  /** https://graypaper.fluffylabs.dev/#/85129da/387603387603?v=0.6.3 */
33887
33810
  serialize.serviceLookupHistory = (blake2b, serviceId, hash, len) => ({
33888
33811
  key: stateKeys.serviceLookupHistory(blake2b, serviceId, hash, len),
33889
- Codec: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32)),
33812
+ Codec: readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32)),
33890
33813
  });
33891
- })(serialize_serialize || (serialize_serialize = {}));
33814
+ })(serialize || (serialize = {}));
33892
33815
  /**
33893
33816
  * Just dump the entire terminal blob as-is.
33894
33817
  *
@@ -33898,87 +33821,6 @@ var serialize_serialize;
33898
33821
  */
33899
33822
  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()));
33900
33823
 
33901
- ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state-view.ts
33902
-
33903
-
33904
- class SerializedStateView {
33905
- spec;
33906
- backend;
33907
- recentlyUsedServices;
33908
- viewCache;
33909
- constructor(spec, backend,
33910
- /** Best-effort list of recently active services. */
33911
- recentlyUsedServices, viewCache) {
33912
- this.spec = spec;
33913
- this.backend = backend;
33914
- this.recentlyUsedServices = recentlyUsedServices;
33915
- this.viewCache = viewCache;
33916
- }
33917
- retrieveView({ key, Codec }, description) {
33918
- const cached = this.viewCache.get(key);
33919
- if (cached !== undefined) {
33920
- return cached;
33921
- }
33922
- const bytes = this.backend.get(key);
33923
- if (bytes === null) {
33924
- throw new Error(`Required state entry for ${description} is missing!. Accessing view of key: ${key}`);
33925
- }
33926
- // NOTE [ToDr] we are not using `Decoder.decodeObject` here because
33927
- // it needs to get to the end of the data (skip), yet that's expensive.
33928
- // we assume that the state data is correct and coherent anyway, so
33929
- // for performance reasons we simply create the view here.
33930
- const d = decoder_Decoder.fromBytesBlob(bytes);
33931
- d.attachContext(this.spec);
33932
- const view = Codec.View.decode(d);
33933
- this.viewCache.set(key, view);
33934
- return view;
33935
- }
33936
- availabilityAssignmentView() {
33937
- return this.retrieveView(serialize_serialize.availabilityAssignment, "availabilityAssignmentView");
33938
- }
33939
- designatedValidatorDataView() {
33940
- return this.retrieveView(serialize_serialize.designatedValidators, "designatedValidatorsView");
33941
- }
33942
- currentValidatorDataView() {
33943
- return this.retrieveView(serialize_serialize.currentValidators, "currentValidatorsView");
33944
- }
33945
- previousValidatorDataView() {
33946
- return this.retrieveView(serialize_serialize.previousValidators, "previousValidatorsView");
33947
- }
33948
- authPoolsView() {
33949
- return this.retrieveView(serialize_serialize.authPools, "authPoolsView");
33950
- }
33951
- authQueuesView() {
33952
- return this.retrieveView(serialize_serialize.authQueues, "authQueuesView");
33953
- }
33954
- recentBlocksView() {
33955
- return this.retrieveView(serialize_serialize.recentBlocks, "recentBlocksView");
33956
- }
33957
- statisticsView() {
33958
- return this.retrieveView(serialize_serialize.statistics, "statisticsView");
33959
- }
33960
- accumulationQueueView() {
33961
- return this.retrieveView(serialize_serialize.accumulationQueue, "accumulationQueueView");
33962
- }
33963
- recentlyAccumulatedView() {
33964
- return this.retrieveView(serialize_serialize.recentlyAccumulated, "recentlyAccumulatedView");
33965
- }
33966
- safroleDataView() {
33967
- return this.retrieveView(serialize_serialize.safrole, "safroleDataView");
33968
- }
33969
- getServiceInfoView(id) {
33970
- const serviceData = serialize_serialize.serviceData(id);
33971
- const bytes = this.backend.get(serviceData.key);
33972
- if (bytes === null) {
33973
- return null;
33974
- }
33975
- if (!this.recentlyUsedServices.includes(id)) {
33976
- this.recentlyUsedServices.push(id);
33977
- }
33978
- return decoder_Decoder.decodeObject(serviceData.Codec.View, bytes, this.spec);
33979
- }
33980
- }
33981
-
33982
33824
  ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
33983
33825
 
33984
33826
 
@@ -33987,8 +33829,6 @@ class SerializedStateView {
33987
33829
 
33988
33830
 
33989
33831
 
33990
-
33991
-
33992
33832
  /**
33993
33833
  * State object which reads it's entries from some backend.
33994
33834
  *
@@ -34001,7 +33841,7 @@ class serialized_state_SerializedState {
34001
33841
  spec;
34002
33842
  blake2b;
34003
33843
  backend;
34004
- recentlyUsedServices;
33844
+ _recentServiceIds;
34005
33845
  /** Create a state-like object from collection of serialized entries. */
34006
33846
  static fromStateEntries(spec, blake2b, state, recentServices = []) {
34007
33847
  return new serialized_state_SerializedState(spec, blake2b, state, recentServices);
@@ -34010,120 +33850,106 @@ class serialized_state_SerializedState {
34010
33850
  static new(spec, blake2b, db, recentServices = []) {
34011
33851
  return new serialized_state_SerializedState(spec, blake2b, db, recentServices);
34012
33852
  }
34013
- dataCache = hash_dictionary_HashDictionary.new();
34014
- viewCache = hash_dictionary_HashDictionary.new();
34015
33853
  constructor(spec, blake2b, backend,
34016
33854
  /** Best-effort list of recently active services. */
34017
- recentlyUsedServices) {
33855
+ _recentServiceIds) {
34018
33856
  this.spec = spec;
34019
33857
  this.blake2b = blake2b;
34020
33858
  this.backend = backend;
34021
- this.recentlyUsedServices = recentlyUsedServices;
33859
+ this._recentServiceIds = _recentServiceIds;
34022
33860
  }
34023
33861
  /** Comparing the serialized states, just means comparing their backends. */
34024
33862
  [TEST_COMPARE_USING]() {
34025
33863
  return this.backend;
34026
33864
  }
34027
- /** Return a non-decoding version of the state. */
34028
- view() {
34029
- return new SerializedStateView(this.spec, this.backend, this.recentlyUsedServices, this.viewCache);
34030
- }
34031
33865
  // TODO [ToDr] Temporary method to update the state,
34032
33866
  // without changing references.
34033
33867
  updateBackend(newBackend) {
34034
33868
  this.backend = newBackend;
34035
- this.dataCache = hash_dictionary_HashDictionary.new();
34036
- this.viewCache = hash_dictionary_HashDictionary.new();
34037
33869
  }
34038
33870
  recentServiceIds() {
34039
- return this.recentlyUsedServices;
33871
+ return this._recentServiceIds;
34040
33872
  }
34041
33873
  getService(id) {
34042
- const serviceData = this.retrieveOptional(serialize_serialize.serviceData(id));
33874
+ const serviceData = this.retrieveOptional(serialize.serviceData(id));
34043
33875
  if (serviceData === undefined) {
34044
33876
  return null;
34045
33877
  }
34046
- if (!this.recentlyUsedServices.includes(id)) {
34047
- this.recentlyUsedServices.push(id);
33878
+ if (!this._recentServiceIds.includes(id)) {
33879
+ this._recentServiceIds.push(id);
34048
33880
  }
34049
33881
  return new SerializedService(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
34050
33882
  }
34051
- retrieve(k, description) {
34052
- const data = this.retrieveOptional(k);
34053
- if (data === undefined) {
34054
- throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${k.key}`);
33883
+ retrieve({ key, Codec }, description) {
33884
+ const bytes = this.backend.get(key);
33885
+ if (bytes === null) {
33886
+ throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${key}`);
34055
33887
  }
34056
- return data;
33888
+ return decoder_Decoder.decodeObject(Codec, bytes, this.spec);
34057
33889
  }
34058
33890
  retrieveOptional({ key, Codec }) {
34059
- const cached = this.dataCache.get(key);
34060
- if (cached !== undefined) {
34061
- return cached;
34062
- }
34063
33891
  const bytes = this.backend.get(key);
34064
33892
  if (bytes === null) {
34065
33893
  return undefined;
34066
33894
  }
34067
- const data = decoder_Decoder.decodeObject(Codec, bytes, this.spec);
34068
- this.dataCache.set(key, data);
34069
- return data;
33895
+ return decoder_Decoder.decodeObject(Codec, bytes, this.spec);
34070
33896
  }
34071
33897
  get availabilityAssignment() {
34072
- return this.retrieve(serialize_serialize.availabilityAssignment, "availabilityAssignment");
33898
+ return this.retrieve(serialize.availabilityAssignment, "availabilityAssignment");
34073
33899
  }
34074
33900
  get designatedValidatorData() {
34075
- return this.retrieve(serialize_serialize.designatedValidators, "designatedValidatorData");
33901
+ return this.retrieve(serialize.designatedValidators, "designatedValidatorData");
34076
33902
  }
34077
33903
  get nextValidatorData() {
34078
- return this.retrieve(serialize_serialize.safrole, "safroleData.nextValidatorData").nextValidatorData;
33904
+ return this.retrieve(serialize.safrole, "safroleData.nextValidatorData").nextValidatorData;
34079
33905
  }
34080
33906
  get currentValidatorData() {
34081
- return this.retrieve(serialize_serialize.currentValidators, "currentValidators");
33907
+ return this.retrieve(serialize.currentValidators, "currentValidators");
34082
33908
  }
34083
33909
  get previousValidatorData() {
34084
- return this.retrieve(serialize_serialize.previousValidators, "previousValidators");
33910
+ return this.retrieve(serialize.previousValidators, "previousValidators");
34085
33911
  }
34086
33912
  get disputesRecords() {
34087
- return this.retrieve(serialize_serialize.disputesRecords, "disputesRecords");
33913
+ return this.retrieve(serialize.disputesRecords, "disputesRecords");
34088
33914
  }
34089
33915
  get timeslot() {
34090
- return this.retrieve(serialize_serialize.timeslot, "timeslot");
33916
+ return this.retrieve(serialize.timeslot, "timeslot");
34091
33917
  }
34092
33918
  get entropy() {
34093
- return this.retrieve(serialize_serialize.entropy, "entropy");
33919
+ return this.retrieve(serialize.entropy, "entropy");
34094
33920
  }
34095
33921
  get authPools() {
34096
- return this.retrieve(serialize_serialize.authPools, "authPools");
33922
+ return this.retrieve(serialize.authPools, "authPools");
34097
33923
  }
34098
33924
  get authQueues() {
34099
- return this.retrieve(serialize_serialize.authQueues, "authQueues");
33925
+ return this.retrieve(serialize.authQueues, "authQueues");
34100
33926
  }
34101
33927
  get recentBlocks() {
34102
- return this.retrieve(serialize_serialize.recentBlocks, "recentBlocks");
33928
+ return this.retrieve(serialize.recentBlocks, "recentBlocks");
34103
33929
  }
34104
33930
  get statistics() {
34105
- return this.retrieve(serialize_serialize.statistics, "statistics");
33931
+ return this.retrieve(serialize.statistics, "statistics");
34106
33932
  }
34107
33933
  get accumulationQueue() {
34108
- return this.retrieve(serialize_serialize.accumulationQueue, "accumulationQueue");
33934
+ return this.retrieve(serialize.accumulationQueue, "accumulationQueue");
34109
33935
  }
34110
33936
  get recentlyAccumulated() {
34111
- return this.retrieve(serialize_serialize.recentlyAccumulated, "recentlyAccumulated");
33937
+ return this.retrieve(serialize.recentlyAccumulated, "recentlyAccumulated");
34112
33938
  }
34113
33939
  get ticketsAccumulator() {
34114
- return this.retrieve(serialize_serialize.safrole, "safroleData.ticketsAccumulator").ticketsAccumulator;
33940
+ return this.retrieve(serialize.safrole, "safroleData.ticketsAccumulator").ticketsAccumulator;
34115
33941
  }
34116
33942
  get sealingKeySeries() {
34117
- return this.retrieve(serialize_serialize.safrole, "safrole.sealingKeySeries").sealingKeySeries;
33943
+ return this.retrieve(serialize.safrole, "safrole.sealingKeySeries").sealingKeySeries;
34118
33944
  }
34119
33945
  get epochRoot() {
34120
- return this.retrieve(serialize_serialize.safrole, "safrole.epochRoot").epochRoot;
33946
+ return this.retrieve(serialize.safrole, "safrole.epochRoot").epochRoot;
34121
33947
  }
34122
33948
  get privilegedServices() {
34123
- return this.retrieve(serialize_serialize.privilegedServices, "privilegedServices");
33949
+ return this.retrieve(serialize.privilegedServices, "privilegedServices");
34124
33950
  }
34125
33951
  get accumulationOutputLog() {
34126
- return this.retrieve(serialize_serialize.accumulationOutputLog, "accumulationOutputLog");
33952
+ return this.retrieve(serialize.accumulationOutputLog, "accumulationOutputLog");
34127
33953
  }
34128
33954
  }
34129
33955
  /** Service data representation on a serialized state. */
@@ -34152,9 +33978,9 @@ class SerializedService {
34152
33978
  serviceIdAndKey.set(numbers_u32AsLeBytes(this.serviceId));
34153
33979
  serviceIdAndKey.set(rawKey.raw, SERVICE_ID_BYTES);
34154
33980
  const key = opaque_asOpaqueType(bytes_BytesBlob.blobFrom(this.blake2b.hashBytes(serviceIdAndKey).raw));
34155
- return this.retrieveOptional(serialize_serialize.serviceStorage(this.blake2b, this.serviceId, key)) ?? null;
33981
+ return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, key)) ?? null;
34156
33982
  }
34157
- return this.retrieveOptional(serialize_serialize.serviceStorage(this.blake2b, this.serviceId, rawKey)) ?? null;
33983
+ return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, rawKey)) ?? null;
34158
33984
  }
34159
33985
  /**
34160
33986
  * Check if preimage is present in the DB.
@@ -34163,15 +33989,15 @@ class SerializedService {
34163
33989
  */
34164
33990
  hasPreimage(hash) {
34165
33991
  // TODO [ToDr] consider optimizing to avoid fetching the whole data.
34166
- return this.retrieveOptional(serialize_serialize.servicePreimages(this.blake2b, this.serviceId, hash)) !== undefined;
33992
+ return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) !== undefined;
34167
33993
  }
34168
33994
  /** Retrieve preimage from the DB. */
34169
33995
  getPreimage(hash) {
34170
- return this.retrieveOptional(serialize_serialize.servicePreimages(this.blake2b, this.serviceId, hash)) ?? null;
33996
+ return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) ?? null;
34171
33997
  }
34172
33998
  /** Retrieve preimage lookup history. */
34173
33999
  getLookupHistory(hash, len) {
34174
- const rawSlots = this.retrieveOptional(serialize_serialize.serviceLookupHistory(this.blake2b, this.serviceId, hash, len));
34000
+ const rawSlots = this.retrieveOptional(serialize.serviceLookupHistory(this.blake2b, this.serviceId, hash, len));
34175
34001
  if (rawSlots === undefined) {
34176
34002
  return null;
34177
34003
  }
@@ -34860,7 +34686,7 @@ function* serializeStateUpdate(spec, blake2b, update) {
34860
34686
  function* serializeRemovedServices(servicesRemoved) {
34861
34687
  for (const serviceId of servicesRemoved ?? []) {
34862
34688
  // TODO [ToDr] what about all data associated with a service?
34863
- const codec = serialize_serialize.serviceData(serviceId);
34689
+ const codec = serialize.serviceData(serviceId);
34864
34690
  yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
34865
34691
  }
34866
34692
  }
@@ -34869,13 +34695,13 @@ function* serializeStorage(storage, blake2b) {
34869
34695
  switch (action.kind) {
34870
34696
  case UpdateStorageKind.Set: {
34871
34697
  const key = action.storage.key;
34872
- const codec = serialize_serialize.serviceStorage(blake2b, serviceId, key);
34698
+ const codec = serialize.serviceStorage(blake2b, serviceId, key);
34873
34699
  yield [StateEntryUpdateAction.Insert, codec.key, action.storage.value];
34874
34700
  break;
34875
34701
  }
34876
34702
  case UpdateStorageKind.Remove: {
34877
34703
  const key = action.key;
34878
- const codec = serialize_serialize.serviceStorage(blake2b, serviceId, key);
34704
+ const codec = serialize.serviceStorage(blake2b, serviceId, key);
34879
34705
  yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
34880
34706
  break;
34881
34707
  }
@@ -34889,10 +34715,10 @@ function* serializePreimages(preimages, encode, blake2b) {
34889
34715
  switch (action.kind) {
34890
34716
  case UpdatePreimageKind.Provide: {
34891
34717
  const { hash, blob } = action.preimage;
34892
- const codec = serialize_serialize.servicePreimages(blake2b, serviceId, hash);
34718
+ const codec = serialize.servicePreimages(blake2b, serviceId, hash);
34893
34719
  yield [StateEntryUpdateAction.Insert, codec.key, blob];
34894
34720
  if (action.slot !== null) {
34895
- const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, numbers_tryAsU32(blob.length));
34721
+ const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, numbers_tryAsU32(blob.length));
34896
34722
  yield [
34897
34723
  StateEntryUpdateAction.Insert,
34898
34724
  codec2.key,
@@ -34903,15 +34729,15 @@ function* serializePreimages(preimages, encode, blake2b) {
34903
34729
  }
34904
34730
  case UpdatePreimageKind.UpdateOrAdd: {
34905
34731
  const { hash, length, slots } = action.item;
34906
- const codec = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
34732
+ const codec = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
34907
34733
  yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, slots)];
34908
34734
  break;
34909
34735
  }
34910
34736
  case UpdatePreimageKind.Remove: {
34911
34737
  const { hash, length } = action;
34912
- const codec = serialize_serialize.servicePreimages(blake2b, serviceId, hash);
34738
+ const codec = serialize.servicePreimages(blake2b, serviceId, hash);
34913
34739
  yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
34914
- const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
34740
+ const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
34915
34741
  yield [StateEntryUpdateAction.Remove, codec2.key, EMPTY_BLOB];
34916
34742
  break;
34917
34743
  }
@@ -34923,12 +34749,12 @@ function* serializePreimages(preimages, encode, blake2b) {
34923
34749
  function* serializeServiceUpdates(servicesUpdates, encode, blake2b) {
34924
34750
  for (const { action, serviceId } of servicesUpdates ?? []) {
34925
34751
  // new service being created or updated
34926
- const codec = serialize_serialize.serviceData(serviceId);
34752
+ const codec = serialize.serviceData(serviceId);
34927
34753
  yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, action.account)];
34928
34754
  // additional lookup history update
34929
34755
  if (action.kind === UpdateServiceKind.Create && action.lookupHistory !== null) {
34930
34756
  const { lookupHistory } = action;
34931
- const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
34757
+ const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
34932
34758
  yield [StateEntryUpdateAction.Insert, codec2.key, encode(codec2.Codec, lookupHistory.slots)];
34933
34759
  }
34934
34760
  }
@@ -34938,53 +34764,53 @@ function* serializeBasicKeys(spec, update) {
34938
34764
  return [StateEntryUpdateAction.Insert, codec.key, encoder_Encoder.encodeObject(codec.Codec, val, spec)];
34939
34765
  }
34940
34766
  if (update.authPools !== undefined) {
34941
- yield doSerialize(update.authPools, serialize_serialize.authPools); // C(1)
34767
+ yield doSerialize(update.authPools, serialize.authPools); // C(1)
34942
34768
  }
34943
34769
  if (update.authQueues !== undefined) {
34944
- yield doSerialize(update.authQueues, serialize_serialize.authQueues); // C(2)
34770
+ yield doSerialize(update.authQueues, serialize.authQueues); // C(2)
34945
34771
  }
34946
34772
  if (update.recentBlocks !== undefined) {
34947
- yield doSerialize(update.recentBlocks, serialize_serialize.recentBlocks); // C(3)
34773
+ yield doSerialize(update.recentBlocks, serialize.recentBlocks); // C(3)
34948
34774
  }
34949
34775
  const safroleData = getSafroleData(update.nextValidatorData, update.epochRoot, update.sealingKeySeries, update.ticketsAccumulator);
34950
34776
  if (safroleData !== undefined) {
34951
- yield doSerialize(safroleData, serialize_serialize.safrole); // C(4)
34777
+ yield doSerialize(safroleData, serialize.safrole); // C(4)
34952
34778
  }
34953
34779
  if (update.disputesRecords !== undefined) {
34954
- yield doSerialize(update.disputesRecords, serialize_serialize.disputesRecords); // C(5)
34780
+ yield doSerialize(update.disputesRecords, serialize.disputesRecords); // C(5)
34955
34781
  }
34956
34782
  if (update.entropy !== undefined) {
34957
- yield doSerialize(update.entropy, serialize_serialize.entropy); // C(6)
34783
+ yield doSerialize(update.entropy, serialize.entropy); // C(6)
34958
34784
  }
34959
34785
  if (update.designatedValidatorData !== undefined) {
34960
- yield doSerialize(update.designatedValidatorData, serialize_serialize.designatedValidators); // C(7)
34786
+ yield doSerialize(update.designatedValidatorData, serialize.designatedValidators); // C(7)
34961
34787
  }
34962
34788
  if (update.currentValidatorData !== undefined) {
34963
- yield doSerialize(update.currentValidatorData, serialize_serialize.currentValidators); // C(8)
34789
+ yield doSerialize(update.currentValidatorData, serialize.currentValidators); // C(8)
34964
34790
  }
34965
34791
  if (update.previousValidatorData !== undefined) {
34966
- yield doSerialize(update.previousValidatorData, serialize_serialize.previousValidators); // C(9)
34792
+ yield doSerialize(update.previousValidatorData, serialize.previousValidators); // C(9)
34967
34793
  }
34968
34794
  if (update.availabilityAssignment !== undefined) {
34969
- yield doSerialize(update.availabilityAssignment, serialize_serialize.availabilityAssignment); // C(10)
34795
+ yield doSerialize(update.availabilityAssignment, serialize.availabilityAssignment); // C(10)
34970
34796
  }
34971
34797
  if (update.timeslot !== undefined) {
34972
- yield doSerialize(update.timeslot, serialize_serialize.timeslot); // C(11)
34798
+ yield doSerialize(update.timeslot, serialize.timeslot); // C(11)
34973
34799
  }
34974
34800
  if (update.privilegedServices !== undefined) {
34975
- yield doSerialize(update.privilegedServices, serialize_serialize.privilegedServices); // C(12)
34801
+ yield doSerialize(update.privilegedServices, serialize.privilegedServices); // C(12)
34976
34802
  }
34977
34803
  if (update.statistics !== undefined) {
34978
- yield doSerialize(update.statistics, serialize_serialize.statistics); // C(13)
34804
+ yield doSerialize(update.statistics, serialize.statistics); // C(13)
34979
34805
  }
34980
34806
  if (update.accumulationQueue !== undefined) {
34981
- yield doSerialize(update.accumulationQueue, serialize_serialize.accumulationQueue); // C(14)
34807
+ yield doSerialize(update.accumulationQueue, serialize.accumulationQueue); // C(14)
34982
34808
  }
34983
34809
  if (update.recentlyAccumulated !== undefined) {
34984
- yield doSerialize(update.recentlyAccumulated, serialize_serialize.recentlyAccumulated); // C(15)
34810
+ yield doSerialize(update.recentlyAccumulated, serialize.recentlyAccumulated); // C(15)
34985
34811
  }
34986
34812
  if (update.accumulationOutputLog !== undefined) {
34987
- yield doSerialize(update.accumulationOutputLog, serialize_serialize.accumulationOutputLog); // C(16)
34813
+ yield doSerialize(update.accumulationOutputLog, serialize.accumulationOutputLog); // C(16)
34988
34814
  }
34989
34815
  }
34990
34816
  function getSafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator) {
@@ -35097,41 +34923,41 @@ function convertInMemoryStateToDictionary(spec, blake2b, state) {
35097
34923
  function doSerialize(codec) {
35098
34924
  serialized.set(codec.key, encoder_Encoder.encodeObject(codec.Codec, codec.extract(state), spec));
35099
34925
  }
35100
- doSerialize(serialize_serialize.authPools); // C(1)
35101
- doSerialize(serialize_serialize.authQueues); // C(2)
35102
- doSerialize(serialize_serialize.recentBlocks); // C(3)
35103
- doSerialize(serialize_serialize.safrole); // C(4)
35104
- doSerialize(serialize_serialize.disputesRecords); // C(5)
35105
- doSerialize(serialize_serialize.entropy); // C(6)
35106
- doSerialize(serialize_serialize.designatedValidators); // C(7)
35107
- doSerialize(serialize_serialize.currentValidators); // C(8)
35108
- doSerialize(serialize_serialize.previousValidators); // C(9)
35109
- doSerialize(serialize_serialize.availabilityAssignment); // C(10)
35110
- doSerialize(serialize_serialize.timeslot); // C(11)
35111
- doSerialize(serialize_serialize.privilegedServices); // C(12)
35112
- doSerialize(serialize_serialize.statistics); // C(13)
35113
- doSerialize(serialize_serialize.accumulationQueue); // C(14)
35114
- doSerialize(serialize_serialize.recentlyAccumulated); // C(15)
35115
- doSerialize(serialize_serialize.accumulationOutputLog); // C(16)
34926
+ doSerialize(serialize.authPools); // C(1)
34927
+ doSerialize(serialize.authQueues); // C(2)
34928
+ doSerialize(serialize.recentBlocks); // C(3)
34929
+ doSerialize(serialize.safrole); // C(4)
34930
+ doSerialize(serialize.disputesRecords); // C(5)
34931
+ doSerialize(serialize.entropy); // C(6)
34932
+ doSerialize(serialize.designatedValidators); // C(7)
34933
+ doSerialize(serialize.currentValidators); // C(8)
34934
+ doSerialize(serialize.previousValidators); // C(9)
34935
+ doSerialize(serialize.availabilityAssignment); // C(10)
34936
+ doSerialize(serialize.timeslot); // C(11)
34937
+ doSerialize(serialize.privilegedServices); // C(12)
34938
+ doSerialize(serialize.statistics); // C(13)
34939
+ doSerialize(serialize.accumulationQueue); // C(14)
34940
+ doSerialize(serialize.recentlyAccumulated); // C(15)
34941
+ doSerialize(serialize.accumulationOutputLog); // C(16)
35116
34942
  // services
35117
34943
  for (const [serviceId, service] of state.services.entries()) {
35118
34944
  // data
35119
- const { key, Codec } = serialize_serialize.serviceData(serviceId);
34945
+ const { key, Codec } = serialize.serviceData(serviceId);
35120
34946
  serialized.set(key, encoder_Encoder.encodeObject(Codec, service.getInfo()));
35121
34947
  // preimages
35122
34948
  for (const preimage of service.data.preimages.values()) {
35123
- const { key, Codec } = serialize_serialize.servicePreimages(blake2b, serviceId, preimage.hash);
34949
+ const { key, Codec } = serialize.servicePreimages(blake2b, serviceId, preimage.hash);
35124
34950
  serialized.set(key, encoder_Encoder.encodeObject(Codec, preimage.blob));
35125
34951
  }
35126
34952
  // storage
35127
34953
  for (const storage of service.data.storage.values()) {
35128
- const { key, Codec } = serialize_serialize.serviceStorage(blake2b, serviceId, storage.key);
34954
+ const { key, Codec } = serialize.serviceStorage(blake2b, serviceId, storage.key);
35129
34955
  serialized.set(key, encoder_Encoder.encodeObject(Codec, storage.value));
35130
34956
  }
35131
34957
  // lookup history
35132
34958
  for (const lookupHistoryList of service.data.lookupHistory.values()) {
35133
34959
  for (const lookupHistory of lookupHistoryList) {
35134
- const { key, Codec } = serialize_serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
34960
+ const { key, Codec } = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
35135
34961
  serialized.set(key, encoder_Encoder.encodeObject(Codec, lookupHistory.slots.slice()));
35136
34962
  }
35137
34963
  }
@@ -35181,7 +35007,6 @@ function loadState(spec, blake2b, entries) {
35181
35007
 
35182
35008
 
35183
35009
 
35184
-
35185
35010
  ;// CONCATENATED MODULE: ./packages/jam/database/leaf-db.ts
35186
35011
 
35187
35012
 
@@ -35340,7 +35165,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
35340
35165
  const lookupHistoryItemCodec = descriptors_codec.object({
35341
35166
  hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
35342
35167
  length: descriptors_codec.u32,
35343
- slots: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32.asOpaque())).convert(seeThrough, tryAsLookupHistorySlots),
35168
+ slots: readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32.asOpaque())).convert(seeThrough, tryAsLookupHistorySlots),
35344
35169
  }, "LookupHistoryItem", ({ hash, length, slots }) => new LookupHistoryItem(hash, length, slots));
35345
35170
  const lookupHistoryEntryCodec = descriptors_codec.object({
35346
35171
  key: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
@@ -35383,11 +35208,7 @@ class ServiceWithCodec extends InMemoryService {
35383
35208
  return new ServiceWithCodec(serviceId, data);
35384
35209
  }
35385
35210
  }
35386
- const in_memory_state_codec_inMemoryStateCodec = (spec) => codec.Class(class State extends InMemoryState {
35387
- static create(data) {
35388
- return InMemoryState.new(spec, data);
35389
- }
35390
- }, {
35211
+ const in_memory_state_codec_inMemoryStateCodec = descriptors_codec.Class(InMemoryState, {
35391
35212
  // alpha
35392
35213
  authPools: serialize.authPools.Codec,
35393
35214
  // phi
@@ -35397,11 +35218,11 @@ const in_memory_state_codec_inMemoryStateCodec = (spec) => codec.Class(class Sta
35397
35218
  // gamma_k
35398
35219
  nextValidatorData: codecPerValidator(ValidatorData.Codec),
35399
35220
  // gamma_z
35400
- epochRoot: codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
35221
+ epochRoot: descriptors_codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
35401
35222
  // gamma_s
35402
35223
  sealingKeySeries: SafroleSealingKeysData.Codec,
35403
35224
  // gamma_a
35404
- ticketsAccumulator: readonlyArray(codec.sequenceVarLen(Ticket.Codec)).convert((x) => x, asKnownSize),
35225
+ ticketsAccumulator: readonlyArray(descriptors_codec.sequenceVarLen(Ticket.Codec)).convert((x) => x, sized_array_asKnownSize),
35405
35226
  // psi
35406
35227
  disputesRecords: serialize.disputesRecords.Codec,
35407
35228
  // eta
@@ -35427,7 +35248,7 @@ const in_memory_state_codec_inMemoryStateCodec = (spec) => codec.Class(class Sta
35427
35248
  // theta
35428
35249
  accumulationOutputLog: serialize.accumulationOutputLog.Codec,
35429
35250
  // delta
35430
- services: codec.dictionary(codec.u32.asOpaque(), ServiceWithCodec.Codec, {
35251
+ services: descriptors_codec.dictionary(descriptors_codec.u32.asOpaque(), ServiceWithCodec.Codec, {
35431
35252
  sortKeys: (a, b) => a - b,
35432
35253
  }),
35433
35254
  });
@@ -35474,7 +35295,7 @@ class InMemoryStates {
35474
35295
  }
35475
35296
  /** Insert a full state into the database. */
35476
35297
  async insertState(headerHash, state) {
35477
- const encoded = Encoder.encodeObject(inMemoryStateCodec(this.spec), state, this.spec);
35298
+ const encoded = Encoder.encodeObject(inMemoryStateCodec, state, this.spec);
35478
35299
  this.db.set(headerHash, encoded);
35479
35300
  return Result.ok(OK);
35480
35301
  }
@@ -35483,7 +35304,7 @@ class InMemoryStates {
35483
35304
  if (encodedState === undefined) {
35484
35305
  return null;
35485
35306
  }
35486
- return Decoder.decodeObject(inMemoryStateCodec(this.spec), encodedState, this.spec);
35307
+ return Decoder.decodeObject(inMemoryStateCodec, encodedState, this.spec);
35487
35308
  }
35488
35309
  }
35489
35310
 
@@ -35709,14 +35530,14 @@ async function initializeDatabase(spec, blake2b, genesisHeaderHash, rootDb, conf
35709
35530
  const genesisHeader = decoder_Decoder.decodeObject(Header.Codec, config.genesisHeader, spec);
35710
35531
  const genesisExtrinsic = emptyBlock().extrinsic;
35711
35532
  const genesisBlock = Block.create({ header: genesisHeader, extrinsic: genesisExtrinsic });
35712
- const blockView = reencodeAsView(Block.Codec, genesisBlock, spec);
35533
+ const blockView = blockAsView(genesisBlock, spec);
35713
35534
  common_logger.log `🧬 Writing genesis block #${genesisHeader.timeSlotIndex}: ${genesisHeaderHash}`;
35714
35535
  const { genesisStateSerialized, genesisStateRootHash } = loadGenesisState(spec, blake2b, config.genesisState);
35715
35536
  // write to db
35716
35537
  await blocks.insertBlock(new WithHash(genesisHeaderHash, blockView));
35717
35538
  // insert fake blocks for ancestry data
35718
35539
  for (const [hash, slot] of ancestry) {
35719
- await blocks.insertBlock(new WithHash(hash, reencodeAsView(Block.Codec, emptyBlock(slot), spec)));
35540
+ await blocks.insertBlock(new WithHash(hash, blockAsView(emptyBlock(slot), spec)));
35720
35541
  }
35721
35542
  await states.insertState(genesisHeaderHash, genesisStateSerialized);
35722
35543
  await blocks.setPostStateRoot(genesisHeaderHash, genesisStateRootHash);
@@ -35735,6 +35556,9 @@ function loadGenesisState(spec, blake2b, data) {
35735
35556
  genesisStateRootHash,
35736
35557
  };
35737
35558
  }
35559
+ function blockAsView(block, spec) {
35560
+ return decoder_Decoder.decodeObject(Block.Codec.View, encoder_Encoder.encodeObject(Block.Codec, block, spec), spec);
35561
+ }
35738
35562
 
35739
35563
  ;// CONCATENATED MODULE: external "node:path"
35740
35564
  const external_node_path_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:path");
@@ -36924,21 +36748,21 @@ class TransitionHasher {
36924
36748
  */
36925
36749
  extrinsic(extrinsicView) {
36926
36750
  // https://graypaper.fluffylabs.dev/#/cc517d7/0cfb000cfb00?v=0.6.5
36927
- const guaranteesCount = numbers_tryAsU32(extrinsicView.guarantees.view().length);
36928
- const countEncoded = encoder_Encoder.encodeObject(descriptors_codec.varU32, guaranteesCount);
36929
- const guaranteesBlobs = extrinsicView.guarantees
36751
+ const guarantees = extrinsicView.guarantees
36930
36752
  .view()
36931
36753
  .map((g) => g.view())
36932
- .reduce((aggregated, guarantee) => {
36754
+ .map((guarantee) => {
36933
36755
  const reportHash = this.blake2b.hashBytes(guarantee.report.encoded()).asOpaque();
36934
- aggregated.push(reportHash.raw);
36935
- aggregated.push(guarantee.slot.encoded().raw);
36936
- aggregated.push(guarantee.credentials.encoded().raw);
36937
- return aggregated;
36938
- }, [countEncoded.raw]);
36756
+ return bytes_BytesBlob.blobFromParts([
36757
+ reportHash.raw,
36758
+ guarantee.slot.encoded().raw,
36759
+ guarantee.credentials.encoded().raw,
36760
+ ]);
36761
+ });
36762
+ const guaranteeBlob = encoder_Encoder.encodeObject(descriptors_codec.sequenceVarLen(dumpCodec), guarantees, this.context);
36939
36763
  const et = this.blake2b.hashBytes(extrinsicView.tickets.encoded()).asOpaque();
36940
36764
  const ep = this.blake2b.hashBytes(extrinsicView.preimages.encoded()).asOpaque();
36941
- const eg = this.blake2b.hashBlobs(guaranteesBlobs).asOpaque();
36765
+ const eg = this.blake2b.hashBytes(guaranteeBlob).asOpaque();
36942
36766
  const ea = this.blake2b.hashBytes(extrinsicView.assurances.encoded()).asOpaque();
36943
36767
  const ed = this.blake2b.hashBytes(extrinsicView.disputes.encoded()).asOpaque();
36944
36768
  const encoded = bytes_BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);
@@ -41554,7 +41378,7 @@ async function getRingCommitmentNoCache(bandersnatch, keys) {
41554
41378
  if (commitmentResult[RESULT_INDEX] === ResultValues.Error) {
41555
41379
  return result_Result.error(null);
41556
41380
  }
41557
- return result_Result.ok(bytes_Bytes.fromBlob(commitmentResult.subarray(1), bandersnatch_BANDERSNATCH_RING_ROOT_BYTES).asOpaque());
41381
+ return result_Result.ok(bytes_Bytes.fromBlob(commitmentResult.subarray(1), BANDERSNATCH_RING_ROOT_BYTES).asOpaque());
41558
41382
  }
41559
41383
  // One byte for result discriminator (`ResultValues`) and the rest is entropy hash.
41560
41384
  const TICKET_RESULT_LENGTH = 1 + hash_HASH_SIZE;
@@ -41708,7 +41532,7 @@ class Safrole {
41708
41532
  * https://graypaper.fluffylabs.dev/#/5f542d7/0ea2000ea200
41709
41533
  */
41710
41534
  if (isOffender) {
41711
- return validator_data_ValidatorData.create({
41535
+ return ValidatorData.create({
41712
41536
  bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
41713
41537
  ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
41714
41538
  bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
@@ -41786,13 +41610,13 @@ class Safrole {
41786
41610
  if (this.isNextEpoch(timeslot) &&
41787
41611
  m >= this.chainSpec.contestLength &&
41788
41612
  this.state.ticketsAccumulator.length === this.chainSpec.epochLength) {
41789
- return safrole_data_SafroleSealingKeysData.tickets(this.outsideInSequencer(this.state.ticketsAccumulator).tickets);
41613
+ return SafroleSealingKeysData.tickets(this.outsideInSequencer(this.state.ticketsAccumulator).tickets);
41790
41614
  }
41791
41615
  if (this.isSameEpoch(timeslot)) {
41792
41616
  return this.state.sealingKeySeries;
41793
41617
  }
41794
41618
  // TODO [MaSi]: the result of fallback sequencer should be cached
41795
- return safrole_data_SafroleSealingKeysData.keys(this.fallbackKeySequencer(newEntropy, newValidators));
41619
+ return SafroleSealingKeysData.keys(this.fallbackKeySequencer(newEntropy, newValidators));
41796
41620
  }
41797
41621
  /**
41798
41622
  * Returns epoch markers if the epoch is changed and null otherwise
@@ -42042,46 +41866,47 @@ class SafroleSeal {
42042
41866
  }
42043
41867
  async verifySeal(headerView, state) {
42044
41868
  // we use transitioned keys already
41869
+ const validators = state.currentValidatorData;
42045
41870
  const validatorIndex = headerView.bandersnatchBlockAuthorIndex.materialize();
42046
- const authorKeys = state.currentValidatorData.at(validatorIndex);
42047
- if (authorKeys === undefined) {
41871
+ const authorKey = validators[validatorIndex];
41872
+ if (authorKey === undefined) {
42048
41873
  return result_Result.error(SafroleSealError.InvalidValidatorIndex);
42049
41874
  }
42050
41875
  const timeSlot = headerView.timeSlotIndex.materialize();
42051
41876
  const sealingKeys = state.sealingKeySeries;
42052
41877
  const entropy = state.currentEntropy;
42053
41878
  if (sealingKeys.kind === SafroleSealingKeysKind.Tickets) {
42054
- return await this.verifySealWithTicket(sealingKeys.tickets, timeSlot, entropy, authorKeys, headerView);
41879
+ return await this.verifySealWithTicket(sealingKeys.tickets, timeSlot, entropy, validators, validatorIndex, headerView);
42055
41880
  }
42056
- return await this.verifySealWithKeys(sealingKeys.keys, timeSlot, entropy, authorKeys, headerView);
41881
+ return await this.verifySealWithKeys(sealingKeys.keys, authorKey, timeSlot, entropy, validators, validatorIndex, headerView);
42057
41882
  }
42058
41883
  /** Regular (non-fallback) mode of Safrole. */
42059
- async verifySealWithTicket(tickets, timeSlot, entropy, validatorData, headerView) {
41884
+ async verifySealWithTicket(tickets, timeSlot, entropy, validators, validatorIndex, headerView) {
42060
41885
  const index = timeSlot % tickets.length;
42061
- const ticket = tickets.at(index);
42062
- const payload = bytes_BytesBlob.blobFromParts(JAM_TICKET_SEAL, entropy.raw, new Uint8Array([ticket?.attempt ?? 0]));
41886
+ const { id, attempt } = tickets[index];
41887
+ const payload = bytes_BytesBlob.blobFromParts(JAM_TICKET_SEAL, entropy.raw, new Uint8Array([attempt]));
42063
41888
  // verify seal correctness
42064
- const authorKey = validatorData.bandersnatch;
41889
+ const authorKey = validators.at(validatorIndex)?.bandersnatch;
42065
41890
  const result = await bandersnatch_vrf.verifySeal(await this.bandersnatch, authorKey ?? BANDERSNATCH_ZERO_KEY, headerView.seal.materialize(), payload, encodeUnsealedHeader(headerView));
42066
41891
  if (result.isError) {
42067
41892
  return result_Result.error(SafroleSealError.IncorrectSeal);
42068
41893
  }
42069
- if (ticket === undefined || !ticket.id.isEqualTo(result.ok)) {
41894
+ if (!id.isEqualTo(result.ok)) {
42070
41895
  return result_Result.error(SafroleSealError.InvalidTicket);
42071
41896
  }
42072
41897
  return result_Result.ok(result.ok);
42073
41898
  }
42074
41899
  /** Fallback mode of Safrole. */
42075
- async verifySealWithKeys(keys, timeSlot, entropy, authorKey, headerView) {
41900
+ async verifySealWithKeys(keys, authorKey, timeSlot, entropy, validators, validatorIndex, headerView) {
42076
41901
  const index = timeSlot % keys.length;
42077
- const sealingKey = keys.at(index);
42078
- const authorBandersnatchKey = authorKey.bandersnatch;
42079
- if (sealingKey === undefined || !sealingKey.isEqualTo(authorBandersnatchKey)) {
41902
+ const sealingKey = keys[index];
41903
+ if (!sealingKey.isEqualTo(authorKey.bandersnatch)) {
42080
41904
  return result_Result.error(SafroleSealError.InvalidValidator, `Invalid Validator. Expected: ${sealingKey}, got: ${authorKey.bandersnatch}`);
42081
41905
  }
42082
41906
  // verify seal correctness
42083
41907
  const payload = bytes_BytesBlob.blobFromParts(JAM_FALLBACK_SEAL, entropy.raw);
42084
- const result = await bandersnatch_vrf.verifySeal(await this.bandersnatch, authorBandersnatchKey, headerView.seal.materialize(), payload, encodeUnsealedHeader(headerView));
41908
+ const blockAuthorKey = validators.at(validatorIndex)?.bandersnatch;
41909
+ const result = await bandersnatch_vrf.verifySeal(await this.bandersnatch, blockAuthorKey ?? BANDERSNATCH_ZERO_KEY, headerView.seal.materialize(), payload, encodeUnsealedHeader(headerView));
42085
41910
  if (result.isError) {
42086
41911
  return result_Result.error(SafroleSealError.IncorrectSeal);
42087
41912
  }
@@ -48278,7 +48103,7 @@ class Assign {
48278
48103
  // NOTE: Here we know the core index is valid
48279
48104
  const coreIndex = tryAsCoreIndex(Number(maybeCoreIndex));
48280
48105
  const decoder = decoder_Decoder.fromBlob(res);
48281
- const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE);
48106
+ const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE), AUTHORIZATION_QUEUE_SIZE);
48282
48107
  const fixedSizeAuthQueue = FixedSizeArray.new(authQueue, AUTHORIZATION_QUEUE_SIZE);
48283
48108
  const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
48284
48109
  if (result.isOk) {
@@ -48474,7 +48299,7 @@ class Checkpoint {
48474
48299
 
48475
48300
 
48476
48301
  const designate_IN_OUT_REG = 7;
48477
- const VALIDATOR_DATA_BYTES = tryAsExactBytes(validator_data_ValidatorData.Codec.sizeHint);
48302
+ const VALIDATOR_DATA_BYTES = tryAsExactBytes(ValidatorData.Codec.sizeHint);
48478
48303
  /**
48479
48304
  * Designate a new set of validator keys.
48480
48305
  *
@@ -48503,7 +48328,7 @@ class Designate {
48503
48328
  return PvmExecution.Panic;
48504
48329
  }
48505
48330
  const decoder = decoder_Decoder.fromBlob(res);
48506
- const validatorsData = decoder.sequenceFixLen(validator_data_ValidatorData.Codec, this.chainSpec.validatorsCount);
48331
+ const validatorsData = decoder.sequenceFixLen(ValidatorData.Codec, this.chainSpec.validatorsCount);
48507
48332
  const result = this.partialState.updateValidatorsData(tryAsPerValidator(validatorsData, this.chainSpec));
48508
48333
  if (result.isError) {
48509
48334
  logger_logger.trace `DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- HUH`;
@@ -50159,10 +49984,9 @@ class Accumulate {
50159
49984
  const recentlyAccumulated = tryAsPerEpochBlock(newRecentlyAccumulated, this.chainSpec);
50160
49985
  const accumulationQueue = this.state.accumulationQueue.slice();
50161
49986
  accumulationQueue[phaseIndex] = pruneQueue(toAccumulateLater, accumulatedSet);
50162
- const timeslot = this.state.timeslot;
50163
49987
  for (let i = 1; i < epochLength; i++) {
50164
49988
  const queueIndex = (phaseIndex + epochLength - i) % epochLength;
50165
- if (i < slot - timeslot) {
49989
+ if (i < slot - this.state.timeslot) {
50166
49990
  accumulationQueue[queueIndex] = [];
50167
49991
  }
50168
49992
  else {
@@ -50374,6 +50198,7 @@ class DeferredTransfers {
50374
50198
 
50375
50199
 
50376
50200
 
50201
+
50377
50202
  /**
50378
50203
  * Maintain a list of available authorizations per core.
50379
50204
  *
@@ -50402,12 +50227,11 @@ class Authorization {
50402
50227
  */
50403
50228
  transition(input) {
50404
50229
  const authPoolsUpdate = this.state.authPools.slice();
50405
- const authQueues = this.state.authQueues;
50406
50230
  // we transition authorizations for each core.
50407
50231
  for (let coreIndex = tryAsCoreIndex(0); coreIndex < this.chainSpec.coresCount; coreIndex++) {
50408
50232
  let pool = authPoolsUpdate[coreIndex].slice();
50409
50233
  // the queue is only read (we should most likely use `ArrayView` here).
50410
- const queue = authQueues[coreIndex];
50234
+ const queue = this.state.authQueues[coreIndex];
50411
50235
  // if there were any used hashes - remove them
50412
50236
  const usedHashes = input.used.get(coreIndex);
50413
50237
  if (usedHashes !== undefined) {
@@ -50581,18 +50405,14 @@ class RecentHistory {
50581
50405
  * https://graypaper.fluffylabs.dev/#/1c979cb/0f55020f5502?v=0.7.1
50582
50406
  */
50583
50407
  partialTransition(input) {
50584
- const stateBlocks = this.state.recentBlocks;
50585
- const recentBlocks = stateBlocks.blocks.slice();
50408
+ const recentBlocks = this.state.recentBlocks.blocks.slice();
50586
50409
  const lastState = recentBlocks.length > 0 ? recentBlocks[recentBlocks.length - 1] : null;
50587
50410
  // update the posterior root of previous state.
50588
50411
  if (lastState !== null) {
50589
50412
  lastState.postStateRoot = input.priorStateRoot;
50590
50413
  }
50591
50414
  return {
50592
- recentBlocks: RecentBlocks.create({
50593
- blocks: sized_array_asKnownSize(recentBlocks),
50594
- accumulationLog: stateBlocks.accumulationLog,
50595
- }), // β_H†
50415
+ recentBlocks: this.state.recentBlocks.updateBlocks(recentBlocks), // β_H†
50596
50416
  };
50597
50417
  }
50598
50418
  /**
@@ -50604,8 +50424,8 @@ class RecentHistory {
50604
50424
  transition(input) {
50605
50425
  const recentBlocks = input.partial.recentBlocks.blocks.slice();
50606
50426
  // `β′_B`
50607
- const mmr = this.state.recentBlocks.accumulationLog !== null
50608
- ? MerkleMountainRange.fromPeaks(this.hasher, this.state.recentBlocks.accumulationLog)
50427
+ const mmr = this.state.recentBlocks.asCurrent().accumulationLog !== null
50428
+ ? MerkleMountainRange.fromPeaks(this.hasher, this.state.recentBlocks.asCurrent().accumulationLog)
50609
50429
  : MerkleMountainRange.empty(this.hasher);
50610
50430
  // append the accumulation root
50611
50431
  mmr.append(input.accumulateRoot);
@@ -50623,7 +50443,7 @@ class RecentHistory {
50623
50443
  }
50624
50444
  // write back to the state.
50625
50445
  return {
50626
- recentBlocks: RecentBlocks.create(RecentBlocks.create({
50446
+ recentBlocks: RecentBlocksHistory.create(RecentBlocks.create({
50627
50447
  blocks: sized_array_asKnownSize(recentBlocks),
50628
50448
  accumulationLog: peaks,
50629
50449
  })),
@@ -50835,6 +50655,7 @@ function verifyReportsBasic(input) {
50835
50655
 
50836
50656
 
50837
50657
 
50658
+
50838
50659
  const verify_contextual_logger = Logger.new(import.meta.filename, "stf:reports");
50839
50660
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/15eb0115eb01?v=0.6.7 */
50840
50661
  function verifyContextualValidity(input, state, headerChain, maxLookupAnchorAge) {
@@ -50947,7 +50768,7 @@ function verifyRefineContexts(minLookupSlot, contexts, recentBlocksPartialUpdate
50947
50768
  return result_Result.error(ReportsError.BadStateRoot, `Anchor state root mismatch. Got: ${context.stateRoot}, expected: ${recentBlock.postStateRoot}.`);
50948
50769
  }
50949
50770
  // check beefy root
50950
- const beefyRoot = recentBlock.accumulationResult;
50771
+ const beefyRoot = RecentBlocksHistory.accumulationResult(recentBlock);
50951
50772
  if (!beefyRoot.isEqualTo(context.beefyRoot)) {
50952
50773
  return result_Result.error(ReportsError.BadBeefyMmrRoot, `Invalid BEEFY super peak hash. Got: ${context.beefyRoot}, expected: ${beefyRoot}. Anchor: ${recentBlock.headerHash}`);
50953
50774
  }
@@ -51189,9 +51010,8 @@ function verifyPostSignatureChecks(input, availabilityAssignment, authPools, ser
51189
51010
  * https://graypaper.fluffylabs.dev/#/5f542d7/15eb0015ed00
51190
51011
  */
51191
51012
  const authorizerHash = report.authorizerHash;
51192
- const authorizerPool = authPools.get(coreIndex);
51193
- const pool = authorizerPool?.materialize() ?? [];
51194
- if (pool.find((hash) => hash.isEqualTo(authorizerHash)) === undefined) {
51013
+ const authorizerPool = authPools[coreIndex];
51014
+ if (authorizerPool.find((hash) => hash.isEqualTo(authorizerHash)) === undefined) {
51195
51015
  return result_Result.error(ReportsError.CoreUnauthorized, `Authorizer hash not found in the pool of core ${coreIndex}: ${authorizerHash}`);
51196
51016
  }
51197
51017
  /**
@@ -51321,8 +51141,7 @@ class Reports {
51321
51141
  return verifyCredentials(input.guarantees, workReportHashes, input.slot, (headerTimeSlot, guaranteeTimeSlot) => this.getGuarantorAssignment(headerTimeSlot, guaranteeTimeSlot, input.newEntropy));
51322
51142
  }
51323
51143
  verifyPostSignatureChecks(input, assurancesAvailAssignment) {
51324
- const authPoolsView = this.state.view().authPoolsView();
51325
- return verifyPostSignatureChecks(input, assurancesAvailAssignment, authPoolsView, (id) => this.state.getService(id));
51144
+ return verifyPostSignatureChecks(input, assurancesAvailAssignment, this.state.authPools, (id) => this.state.getService(id));
51326
51145
  }
51327
51146
  verifyContextualValidity(input) {
51328
51147
  return verifyContextualValidity(input, this.state, this.headerChain, this.chainSpec.maxLookupAnchorAge);