@typeberry/jam 0.2.0-b6e3410 → 0.2.0-c3df163

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4940,6 +4940,9 @@ class ObjectView {
4940
4940
  toString() {
4941
4941
  return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
4942
4942
  }
4943
+ [TEST_COMPARE_USING]() {
4944
+ return this.materialize();
4945
+ }
4943
4946
  }
4944
4947
  /**
4945
4948
  * A lazy-evaluated decoder of a sequence.
@@ -5072,7 +5075,7 @@ const TYPICAL_DICTIONARY_LENGTH = 32;
5072
5075
  * It's not true in a general case, but should be good enough for us.
5073
5076
  *
5074
5077
  */
5075
- function readonlyArray(desc) {
5078
+ function descriptors_readonlyArray(desc) {
5076
5079
  return desc.convert((x) => {
5077
5080
  debug_check `
5078
5081
  ${Array.isArray(x)}
@@ -5234,7 +5237,15 @@ var descriptors_codec;
5234
5237
  /** Custom encoding / decoding logic. */
5235
5238
  codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
5236
5239
  /** Choose a descriptor depending on the encoding/decoding context. */
5237
- 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);
5240
+ codec.select = ({ name, sizeHint, }, chooser) => {
5241
+ const Self = chooser(null);
5242
+ 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)
5243
+ ? codec.select({
5244
+ name: Self.View.name,
5245
+ sizeHint: Self.View.sizeHint,
5246
+ }, (ctx) => chooser(ctx).View)
5247
+ : Self.View);
5248
+ };
5238
5249
  /**
5239
5250
  * A descriptor for a more complex POJO.
5240
5251
  *
@@ -6056,7 +6067,7 @@ const BANDERSNATCH_KEY_BYTES = 32;
6056
6067
  /** Bandersnatch VRF signature size */
6057
6068
  const bandersnatch_BANDERSNATCH_VRF_SIGNATURE_BYTES = 96;
6058
6069
  /** Bandersnatch ring commitment size */
6059
- const BANDERSNATCH_RING_ROOT_BYTES = 144;
6070
+ const bandersnatch_BANDERSNATCH_RING_ROOT_BYTES = 144;
6060
6071
  /** Bandersnatch proof size */
6061
6072
  const BANDERSNATCH_PROOF_BYTES = 784;
6062
6073
  /** BLS public key size. */
@@ -7184,9 +7195,9 @@ function codecWithContext(chooser) {
7184
7195
  /** Codec for a known-size array with length validation. */
7185
7196
  const codecKnownSizeArray = (val, options, _id) => {
7186
7197
  if ("fixedLength" in options) {
7187
- return readonlyArray(descriptors_codec.sequenceFixLen(val, options.fixedLength)).convert(seeThrough, sized_array_asKnownSize);
7198
+ return descriptors_readonlyArray(descriptors_codec.sequenceFixLen(val, options.fixedLength)).convert(seeThrough, sized_array_asKnownSize);
7188
7199
  }
7189
- return readonlyArray(descriptors_codec.sequenceVarLen(val, options)).convert(seeThrough, sized_array_asKnownSize);
7200
+ return descriptors_readonlyArray(descriptors_codec.sequenceVarLen(val, options)).convert(seeThrough, sized_array_asKnownSize);
7190
7201
  };
7191
7202
  /** Codec for a fixed-size array with length validation. */
7192
7203
  const codecFixedSizeArray = (val, len) => {
@@ -7323,7 +7334,7 @@ function tryAsPerValidator(array, spec) {
7323
7334
  `;
7324
7335
  return sized_array_asKnownSize(array);
7325
7336
  }
7326
- const codecPerValidator = (val) => codecWithContext((context) => {
7337
+ const common_codecPerValidator = (val) => codecWithContext((context) => {
7327
7338
  return codecKnownSizeArray(val, {
7328
7339
  fixedLength: context.validatorsCount,
7329
7340
  });
@@ -7450,7 +7461,7 @@ class Verdict extends WithDebug {
7450
7461
  workReportHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
7451
7462
  votesEpoch: descriptors_codec.u32.asOpaque(),
7452
7463
  votes: codecWithContext((context) => {
7453
- return readonlyArray(descriptors_codec.sequenceFixLen(Judgement.Codec, context.validatorsSuperMajority)).convert(seeThrough, sized_array_asKnownSize);
7464
+ return descriptors_readonlyArray(descriptors_codec.sequenceFixLen(Judgement.Codec, context.validatorsSuperMajority)).convert(seeThrough, sized_array_asKnownSize);
7454
7465
  }),
7455
7466
  });
7456
7467
  static create({ workReportHash, votesEpoch, votes }) {
@@ -8142,7 +8153,7 @@ const WorkReportCodec = descriptors_codec.Class(WorkReportNoCodec, {
8142
8153
  authorizerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
8143
8154
  authorizationGasUsed: descriptors_codec.varU64.asOpaque(),
8144
8155
  authorizationOutput: descriptors_codec.blob,
8145
- segmentRootLookup: readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
8156
+ segmentRootLookup: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
8146
8157
  results: descriptors_codec.sequenceVarLen(WorkResult.Codec).convert((x) => x, (items) => FixedSizeArray.new(items, tryAsWorkItemsCount(items.length))),
8147
8158
  });
8148
8159
  const WorkReportCodecPre070 = descriptors_codec.Class(WorkReportNoCodec, {
@@ -8156,7 +8167,7 @@ const WorkReportCodecPre070 = descriptors_codec.Class(WorkReportNoCodec, {
8156
8167
  }),
8157
8168
  authorizerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
8158
8169
  authorizationOutput: descriptors_codec.blob,
8159
- segmentRootLookup: readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
8170
+ segmentRootLookup: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
8160
8171
  results: descriptors_codec.sequenceVarLen(WorkResult.Codec).convert((x) => x, (items) => FixedSizeArray.new(items, tryAsWorkItemsCount(items.length))),
8161
8172
  authorizationGasUsed: descriptors_codec.varU64.asOpaque(),
8162
8173
  });
@@ -8274,16 +8285,16 @@ class SignedTicket extends WithDebug {
8274
8285
  }
8275
8286
  }
8276
8287
  /** Anonymous? entry into the ticket contest. */
8277
- class Ticket extends WithDebug {
8288
+ class tickets_Ticket extends WithDebug {
8278
8289
  id;
8279
8290
  attempt;
8280
- static Codec = descriptors_codec.Class(Ticket, {
8291
+ static Codec = descriptors_codec.Class(tickets_Ticket, {
8281
8292
  id: descriptors_codec.bytes(hash_HASH_SIZE),
8282
8293
  // TODO [ToDr] we should verify that attempt is either 0|1|2.
8283
8294
  attempt: descriptors_codec.u8.asOpaque(),
8284
8295
  });
8285
8296
  static create({ id, attempt }) {
8286
- return new Ticket(id, attempt);
8297
+ return new tickets_Ticket(id, attempt);
8287
8298
  }
8288
8299
  constructor(
8289
8300
  /**
@@ -8352,7 +8363,7 @@ class ValidatorKeys extends WithDebug {
8352
8363
  class TicketsMarker extends WithDebug {
8353
8364
  tickets;
8354
8365
  static Codec = descriptors_codec.Class(TicketsMarker, {
8355
- tickets: codecPerEpochBlock(Ticket.Codec),
8366
+ tickets: codecPerEpochBlock(tickets_Ticket.Codec),
8356
8367
  });
8357
8368
  static create({ tickets }) {
8358
8369
  return new TicketsMarker(tickets);
@@ -8376,7 +8387,7 @@ class EpochMarker extends WithDebug {
8376
8387
  static Codec = descriptors_codec.Class(EpochMarker, {
8377
8388
  entropy: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
8378
8389
  ticketsEntropy: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
8379
- validators: codecPerValidator(ValidatorKeys.Codec),
8390
+ validators: common_codecPerValidator(ValidatorKeys.Codec),
8380
8391
  });
8381
8392
  static create({ entropy, ticketsEntropy, validators }) {
8382
8393
  return new EpochMarker(entropy, ticketsEntropy, validators);
@@ -8648,6 +8659,19 @@ function emptyBlock(slot = tryAsTimeSlot(0)) {
8648
8659
  });
8649
8660
  }
8650
8661
 
8662
+ ;// CONCATENATED MODULE: ./packages/jam/block/utils.ts
8663
+
8664
+ /**
8665
+ * Take an input data and re-encode that data as view.
8666
+ *
8667
+ * NOTE: this function should NEVER be used in any production code,
8668
+ * it's only a test helper.
8669
+ */
8670
+ function reencodeAsView(codec, object, chainSpec) {
8671
+ const encoded = encoder_Encoder.encodeObject(codec, object, chainSpec);
8672
+ return decoder_Decoder.decodeObject(codec.View, encoded, chainSpec);
8673
+ }
8674
+
8651
8675
  ;// CONCATENATED MODULE: ./packages/jam/block/index.ts
8652
8676
 
8653
8677
 
@@ -8666,6 +8690,7 @@ function emptyBlock(slot = tryAsTimeSlot(0)) {
8666
8690
 
8667
8691
 
8668
8692
 
8693
+
8669
8694
  ;// CONCATENATED MODULE: ./packages/jam/database-lmdb/blocks.ts
8670
8695
 
8671
8696
 
@@ -9017,10 +9042,129 @@ function accumulationOutputComparator(a, b) {
9017
9042
  return Ordering.Equal;
9018
9043
  }
9019
9044
 
9045
+ ;// CONCATENATED MODULE: ./packages/jam/block/gp-constants.ts
9046
+
9047
+
9048
+ /**
9049
+ * This file lists all of the constants defined in the GrayPaper appendix.
9050
+ *
9051
+ * NOTE: Avoid using the constants directly, prefer "named" constants defined
9052
+ * in a semantical proximity to where they are used.
9053
+ *
9054
+ * NOTE: This file will most likely be removed in the future. The constants
9055
+ * here are only temporarily for convenience. When we figure out better names
9056
+ * and places for these this file will be eradicated.
9057
+ *
9058
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/442300442300?v=0.7.2
9059
+ */
9060
+ /** `G_I`: The gas allocated to invoke a work-package’s Is-Authorized logic. */
9061
+ const G_I = 50_000_000;
9062
+ /** `I`: Maximum number of work items in a package. */
9063
+ const I = (/* unused pure expression or super */ null && (MAX_NUMBER_OF_WORK_ITEMS));
9064
+ /** `O`: Maximum number of items in the authorizations pool. */
9065
+ const O = 8;
9066
+ /** `Q`: The number of items in the authorizations queue. */
9067
+ const Q = 80;
9068
+ /** `S`: The maximum number of entries in the accumulation queue. */
9069
+ const S = 1024;
9070
+ /** `T`: The maximum number of extrinsics in a work-package. */
9071
+ const T = 128;
9072
+ /** `W_A`: The maximum size of is-authorized code in octets. */
9073
+ const W_A = 64_000;
9074
+ /** `W_B`: The maximum size of the concatenated variable-size blobs, extrinsics and imported segments of a work-package, in octets */
9075
+ const W_B = Compatibility.isGreaterOrEqual(GpVersion.V0_7_2) ? 13_791_360 : 13_794_305;
9076
+ /** `W_C`: The maximum size of service code in octets. */
9077
+ const W_C = 4_000_000;
9078
+ /** `W_M`: The maximum number of imports in a work-package. */
9079
+ const W_M = 3_072;
9080
+ /** `W_R`: The maximum total size of all output blobs in a work-report, in octets. */
9081
+ const W_R = 49_152;
9082
+ /** `W_T`: The size of a transfer memo in octets. */
9083
+ const W_T = 128;
9084
+ /** `W_M`: The maximum number of exports in a work-package. */
9085
+ const W_X = 3_072;
9086
+ // TODO [ToDr] Not sure where these should live yet :(
9087
+ /**
9088
+ * `S`: The minimum public service index.
9089
+ * Services of indices below these may only be created by the Registrar.
9090
+ *
9091
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
9092
+ */
9093
+ const MIN_PUBLIC_SERVICE_INDEX = (/* unused pure expression or super */ null && (2 ** 16));
9094
+ /**
9095
+ * `J`: The maximum sum of dependency items in a work-report.
9096
+ *
9097
+ * https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
9098
+ */
9099
+ const MAX_REPORT_DEPENDENCIES = 8;
9100
+
9101
+ ;// CONCATENATED MODULE: ./packages/jam/state/accumulation-queue.ts
9102
+
9103
+
9104
+
9105
+
9106
+
9107
+
9108
+
9109
+ /**
9110
+ * Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
9111
+ *
9112
+ * https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
9113
+ */
9114
+ class NotYetAccumulatedReport extends WithDebug {
9115
+ report;
9116
+ dependencies;
9117
+ static Codec = descriptors_codec.Class(NotYetAccumulatedReport, {
9118
+ report: WorkReport.Codec,
9119
+ dependencies: codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
9120
+ typicalLength: MAX_REPORT_DEPENDENCIES / 2,
9121
+ maxLength: MAX_REPORT_DEPENDENCIES,
9122
+ minLength: 0,
9123
+ }),
9124
+ });
9125
+ static create({ report, dependencies }) {
9126
+ return new NotYetAccumulatedReport(report, dependencies);
9127
+ }
9128
+ constructor(
9129
+ /**
9130
+ * Each of these were made available at most one epoch ago
9131
+ * but have or had unfulfilled dependencies.
9132
+ */
9133
+ report,
9134
+ /**
9135
+ * Alongside the work-report itself, we retain its un-accumulated
9136
+ * dependencies, a set of work-package hashes.
9137
+ *
9138
+ * https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
9139
+ */
9140
+ dependencies) {
9141
+ super();
9142
+ this.report = report;
9143
+ this.dependencies = dependencies;
9144
+ }
9145
+ }
9146
+ const accumulationQueueCodec = codecPerEpochBlock(descriptors_readonlyArray(descriptors_codec.sequenceVarLen(NotYetAccumulatedReport.Codec)));
9147
+
9148
+ ;// CONCATENATED MODULE: ./packages/jam/state/common.ts
9149
+
9150
+
9151
+ /** Check if given array has correct length before casting to the opaque type. */
9152
+ function tryAsPerCore(array, spec) {
9153
+ debug_check `
9154
+ ${array.length === spec.coresCount}
9155
+ Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
9156
+ `;
9157
+ return opaque_asOpaqueType(array);
9158
+ }
9159
+ const codecPerCore = (val) => codecWithContext((context) => {
9160
+ return codecKnownSizeArray(val, { fixedLength: context.coresCount });
9161
+ });
9162
+
9020
9163
  ;// CONCATENATED MODULE: ./packages/jam/state/assurances.ts
9021
9164
 
9022
9165
 
9023
9166
 
9167
+
9024
9168
  /**
9025
9169
  * Assignment of particular work report to a core.
9026
9170
  *
@@ -9049,27 +9193,30 @@ class AvailabilityAssignment extends WithDebug {
9049
9193
  this.timeout = timeout;
9050
9194
  }
9051
9195
  }
9196
+ const availabilityAssignmentsCodec = codecPerCore(descriptors_codec.optional(AvailabilityAssignment.Codec));
9052
9197
 
9053
- ;// CONCATENATED MODULE: ./packages/jam/state/common.ts
9198
+ ;// CONCATENATED MODULE: ./packages/jam/state/auth.ts
9054
9199
 
9055
9200
 
9056
- /** Check if given array has correct length before casting to the opaque type. */
9057
- function tryAsPerCore(array, spec) {
9058
- debug_check `
9059
- ${array.length === spec.coresCount}
9060
- Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
9061
- `;
9062
- return opaque_asOpaqueType(array);
9063
- }
9064
- const codecPerCore = (val) => codecWithContext((context) => {
9065
- return codecKnownSizeArray(val, { fixedLength: context.coresCount });
9066
- });
9201
+
9202
+
9203
+
9204
+ /** `O`: Maximal authorization pool size. */
9205
+ const MAX_AUTH_POOL_SIZE = O;
9206
+ /** `Q`: Size of the authorization queue. */
9207
+ const AUTHORIZATION_QUEUE_SIZE = Q;
9208
+ const authPoolsCodec = codecPerCore(codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
9209
+ minLength: 0,
9210
+ maxLength: MAX_AUTH_POOL_SIZE,
9211
+ typicalLength: MAX_AUTH_POOL_SIZE,
9212
+ }));
9213
+ const authQueuesCodec = codecPerCore(codecFixedSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE));
9067
9214
 
9068
9215
  ;// CONCATENATED MODULE: ./packages/jam/state/disputes.ts
9069
9216
 
9070
9217
 
9071
9218
 
9072
- const sortedSetCodec = () => readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE))).convert((input) => input.array, (output) => {
9219
+ const sortedSetCodec = () => descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE))).convert((input) => input.array, (output) => {
9073
9220
  const typed = output.map((x) => x.asOpaque());
9074
9221
  return SortedSet.fromSortedArray(hashComparator, typed);
9075
9222
  });
@@ -9131,65 +9278,6 @@ function hashComparator(a, b) {
9131
9278
  return a.compare(b);
9132
9279
  }
9133
9280
 
9134
- ;// CONCATENATED MODULE: ./packages/jam/block/gp-constants.ts
9135
-
9136
- /**
9137
- * This file lists all of the constants defined in the GrayPaper appendix.
9138
- *
9139
- * NOTE: Avoid using the constants directly, prefer "named" constants defined
9140
- * in a semantical proximity to where they are used.
9141
- *
9142
- * NOTE: This file will most likely be removed in the future. The constants
9143
- * here are only temporarily for convenience. When we figure out better names
9144
- * and places for these this file will be eradicated.
9145
- *
9146
- * https://graypaper.fluffylabs.dev/#/579bd12/413000413000
9147
- */
9148
- /** `G_I`: The gas allocated to invoke a work-package’s Is-Authorized logic. */
9149
- const G_I = 50_000_000;
9150
- /** `I`: Maximum number of work items in a package. */
9151
- const I = (/* unused pure expression or super */ null && (MAX_NUMBER_OF_WORK_ITEMS));
9152
- /** `O`: Maximum number of items in the authorizations pool. */
9153
- const O = 8;
9154
- /** `Q`: The number of items in the authorizations queue. */
9155
- const Q = 80;
9156
- /** `S`: The maximum number of entries in the accumulation queue. */
9157
- const S = 1024;
9158
- /** `T`: The maximum number of extrinsics in a work-package. */
9159
- const T = 128;
9160
- /** `W_A`: The maximum size of is-authorized code in octets. */
9161
- const W_A = 64_000;
9162
- /** `W_B`: The maximum size of an encoded work-package with extrinsic data and imports. */
9163
- const W_B = 13_794_305;
9164
- /** `W_C`: The maximum size of service code in octets. */
9165
- const W_C = 4_000_000;
9166
- /** `W_M`: The maximum number of imports in a work-package. */
9167
- const W_M = 3_072;
9168
- /** `W_R`: The maximum total size of all output blobs in a work-report, in octets. */
9169
- const W_R = 49_152;
9170
- /** `W_T`: The size of a transfer memo in octets. */
9171
- const W_T = 128;
9172
- /** `W_M`: The maximum number of exports in a work-package. */
9173
- const W_X = 3_072;
9174
- // TODO [ToDr] Not sure where these should live yet :(
9175
- /**
9176
- * `S`: The minimum public service index.
9177
- * Services of indices below these may only be created by the Registrar.
9178
- *
9179
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
9180
- */
9181
- const MIN_PUBLIC_SERVICE_INDEX = (/* unused pure expression or super */ null && (2 ** 16));
9182
- /**
9183
- * `J`: The maximum sum of dependency items in a work-report.
9184
- *
9185
- * https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
9186
- */
9187
- const MAX_REPORT_DEPENDENCIES = 8;
9188
- /** `Q`: Size of the authorization queue. */
9189
- const AUTHORIZATION_QUEUE_SIZE = Q;
9190
- /** `O`: Maximal authorization pool size. */
9191
- const MAX_AUTH_POOL_SIZE = O;
9192
-
9193
9281
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
9194
9282
  const MAX_VALUE = 4294967295;
9195
9283
  const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
@@ -9197,7 +9285,7 @@ const MIN_VALUE = (/* unused pure expression or super */ null && (-(2 ** 31)));
9197
9285
  const MAX_SHIFT_U32 = 32;
9198
9286
  const MAX_SHIFT_U64 = 64n;
9199
9287
 
9200
- ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
9288
+ ;// CONCATENATED MODULE: ./packages/jam/state/recent-blocks.ts
9201
9289
 
9202
9290
 
9203
9291
 
@@ -9205,28 +9293,272 @@ const MAX_SHIFT_U64 = 64n;
9205
9293
 
9206
9294
 
9207
9295
  /**
9208
- * `B_S`: The basic minimum balance which all services require.
9209
- *
9210
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
9211
- */
9212
- const BASE_SERVICE_BALANCE = 100n;
9213
- /**
9214
- * `B_I`: The additional minimum balance required per item of elective service state.
9296
+ * `H = 8`: The size of recent history, in blocks.
9215
9297
  *
9216
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
9298
+ * https://graypaper.fluffylabs.dev/#/579bd12/416300416500
9217
9299
  */
9218
- const ELECTIVE_ITEM_BALANCE = 10n;
9300
+ const MAX_RECENT_HISTORY = 8;
9301
+ /** Recent history of a single block. */
9302
+ class BlockState extends WithDebug {
9303
+ headerHash;
9304
+ accumulationResult;
9305
+ postStateRoot;
9306
+ reported;
9307
+ static Codec = descriptors_codec.Class(BlockState, {
9308
+ headerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
9309
+ accumulationResult: descriptors_codec.bytes(hash_HASH_SIZE),
9310
+ postStateRoot: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
9311
+ reported: codecHashDictionary(WorkPackageInfo.Codec, (x) => x.workPackageHash),
9312
+ });
9313
+ static create({ headerHash, accumulationResult, postStateRoot, reported }) {
9314
+ return new BlockState(headerHash, accumulationResult, postStateRoot, reported);
9315
+ }
9316
+ constructor(
9317
+ /** Header hash. */
9318
+ headerHash,
9319
+ /** Merkle mountain belt of accumulation result. */
9320
+ accumulationResult,
9321
+ /** Posterior state root filled in with a 1-block delay. */
9322
+ postStateRoot,
9323
+ /** Reported work packages (no more than number of cores). */
9324
+ reported) {
9325
+ super();
9326
+ this.headerHash = headerHash;
9327
+ this.accumulationResult = accumulationResult;
9328
+ this.postStateRoot = postStateRoot;
9329
+ this.reported = reported;
9330
+ }
9331
+ }
9219
9332
  /**
9220
- * `B_L`: The additional minimum balance required per octet of elective service state.
9333
+ * Recent history of blocks.
9221
9334
  *
9222
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
9335
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
9223
9336
  */
9224
- const ELECTIVE_BYTE_BALANCE = 1n;
9225
- const zeroSizeHint = {
9226
- bytes: 0,
9227
- isExact: true,
9228
- };
9229
- /** 0-byte read, return given default value */
9337
+ class RecentBlocks extends WithDebug {
9338
+ blocks;
9339
+ accumulationLog;
9340
+ static Codec = descriptors_codec.Class(RecentBlocks, {
9341
+ blocks: codecKnownSizeArray(BlockState.Codec, {
9342
+ minLength: 0,
9343
+ maxLength: MAX_RECENT_HISTORY,
9344
+ typicalLength: MAX_RECENT_HISTORY,
9345
+ }),
9346
+ accumulationLog: descriptors_codec.object({
9347
+ peaks: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.optional(descriptors_codec.bytes(hash_HASH_SIZE)))),
9348
+ }),
9349
+ });
9350
+ static empty() {
9351
+ return new RecentBlocks(sized_array_asKnownSize([]), {
9352
+ peaks: [],
9353
+ });
9354
+ }
9355
+ static create(a) {
9356
+ return new RecentBlocks(a.blocks, a.accumulationLog);
9357
+ }
9358
+ constructor(
9359
+ /**
9360
+ * Most recent blocks.
9361
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fea010fea01?v=0.6.7
9362
+ */
9363
+ blocks,
9364
+ /**
9365
+ * Accumulation output log.
9366
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/0f02020f0202?v=0.6.7
9367
+ */
9368
+ accumulationLog) {
9369
+ super();
9370
+ this.blocks = blocks;
9371
+ this.accumulationLog = accumulationLog;
9372
+ }
9373
+ }
9374
+
9375
+ ;// CONCATENATED MODULE: ./packages/jam/state/recently-accumulated.ts
9376
+
9377
+
9378
+
9379
+
9380
+ const recentlyAccumulatedCodec = codecPerEpochBlock(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque()).convert((x) => Array.from(x), (x) => HashSet.from(x)));
9381
+
9382
+ ;// CONCATENATED MODULE: ./packages/jam/state/validator-data.ts
9383
+
9384
+
9385
+
9386
+
9387
+ /**
9388
+ * Fixed size of validator metadata.
9389
+ *
9390
+ * https://graypaper.fluffylabs.dev/#/5f542d7/0d55010d5501
9391
+ */
9392
+ const VALIDATOR_META_BYTES = 128;
9393
+ /**
9394
+ * Details about validators' identity.
9395
+ *
9396
+ * https://graypaper.fluffylabs.dev/#/5f542d7/0d4b010d4c01
9397
+ */
9398
+ class validator_data_ValidatorData extends WithDebug {
9399
+ bandersnatch;
9400
+ ed25519;
9401
+ bls;
9402
+ metadata;
9403
+ static Codec = descriptors_codec.Class(validator_data_ValidatorData, {
9404
+ bandersnatch: descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque(),
9405
+ ed25519: descriptors_codec.bytes(ED25519_KEY_BYTES).asOpaque(),
9406
+ bls: descriptors_codec.bytes(BLS_KEY_BYTES).asOpaque(),
9407
+ metadata: descriptors_codec.bytes(VALIDATOR_META_BYTES),
9408
+ });
9409
+ static create({ ed25519, bandersnatch, bls, metadata }) {
9410
+ return new validator_data_ValidatorData(bandersnatch, ed25519, bls, metadata);
9411
+ }
9412
+ constructor(
9413
+ /** Bandersnatch public key. */
9414
+ bandersnatch,
9415
+ /** ED25519 key data. */
9416
+ ed25519,
9417
+ /** BLS public key. */
9418
+ bls,
9419
+ /** Validator-defined additional metdata. */
9420
+ metadata) {
9421
+ super();
9422
+ this.bandersnatch = bandersnatch;
9423
+ this.ed25519 = ed25519;
9424
+ this.bls = bls;
9425
+ this.metadata = metadata;
9426
+ }
9427
+ }
9428
+ const validatorsDataCodec = common_codecPerValidator(validator_data_ValidatorData.Codec);
9429
+
9430
+ ;// CONCATENATED MODULE: ./packages/jam/state/safrole-data.ts
9431
+
9432
+
9433
+
9434
+
9435
+
9436
+
9437
+
9438
+
9439
+
9440
+
9441
+
9442
+ var SafroleSealingKeysKind;
9443
+ (function (SafroleSealingKeysKind) {
9444
+ SafroleSealingKeysKind[SafroleSealingKeysKind["Tickets"] = 0] = "Tickets";
9445
+ SafroleSealingKeysKind[SafroleSealingKeysKind["Keys"] = 1] = "Keys";
9446
+ })(SafroleSealingKeysKind || (SafroleSealingKeysKind = {}));
9447
+ const codecBandersnatchKey = descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque();
9448
+ class safrole_data_SafroleSealingKeysData extends WithDebug {
9449
+ kind;
9450
+ keys;
9451
+ tickets;
9452
+ static Codec = codecWithContext((context) => {
9453
+ return descriptors_codec.custom({
9454
+ name: "SafroleSealingKeys",
9455
+ sizeHint: { bytes: 1 + hash_HASH_SIZE * context.epochLength, isExact: false },
9456
+ }, (e, x) => {
9457
+ e.varU32(numbers_tryAsU32(x.kind));
9458
+ if (x.kind === SafroleSealingKeysKind.Keys) {
9459
+ e.sequenceFixLen(codecBandersnatchKey, x.keys);
9460
+ }
9461
+ else {
9462
+ e.sequenceFixLen(tickets_Ticket.Codec, x.tickets);
9463
+ }
9464
+ }, (d) => {
9465
+ const epochLength = context.epochLength;
9466
+ const kind = d.varU32();
9467
+ if (kind === SafroleSealingKeysKind.Keys) {
9468
+ const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
9469
+ return safrole_data_SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
9470
+ }
9471
+ if (kind === SafroleSealingKeysKind.Tickets) {
9472
+ const tickets = d.sequenceFixLen(tickets_Ticket.Codec, epochLength);
9473
+ return safrole_data_SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
9474
+ }
9475
+ throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
9476
+ }, (s) => {
9477
+ const kind = s.decoder.varU32();
9478
+ if (kind === SafroleSealingKeysKind.Keys) {
9479
+ s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
9480
+ return;
9481
+ }
9482
+ if (kind === SafroleSealingKeysKind.Tickets) {
9483
+ s.sequenceFixLen(tickets_Ticket.Codec, context.epochLength);
9484
+ return;
9485
+ }
9486
+ throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
9487
+ });
9488
+ });
9489
+ static keys(keys) {
9490
+ return new safrole_data_SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
9491
+ }
9492
+ static tickets(tickets) {
9493
+ return new safrole_data_SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
9494
+ }
9495
+ constructor(kind, keys, tickets) {
9496
+ super();
9497
+ this.kind = kind;
9498
+ this.keys = keys;
9499
+ this.tickets = tickets;
9500
+ }
9501
+ }
9502
+ class SafroleData {
9503
+ nextValidatorData;
9504
+ epochRoot;
9505
+ sealingKeySeries;
9506
+ ticketsAccumulator;
9507
+ static Codec = descriptors_codec.Class(SafroleData, {
9508
+ nextValidatorData: common_codecPerValidator(validator_data_ValidatorData.Codec),
9509
+ epochRoot: descriptors_codec.bytes(bandersnatch_BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
9510
+ sealingKeySeries: safrole_data_SafroleSealingKeysData.Codec,
9511
+ ticketsAccumulator: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(tickets_Ticket.Codec)).convert(seeThrough, sized_array_asKnownSize),
9512
+ });
9513
+ static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
9514
+ return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
9515
+ }
9516
+ constructor(
9517
+ /** gamma_k */
9518
+ nextValidatorData,
9519
+ /** gamma_z */
9520
+ epochRoot,
9521
+ /** gamma_s */
9522
+ sealingKeySeries,
9523
+ /** gamma_a */
9524
+ ticketsAccumulator) {
9525
+ this.nextValidatorData = nextValidatorData;
9526
+ this.epochRoot = epochRoot;
9527
+ this.sealingKeySeries = sealingKeySeries;
9528
+ this.ticketsAccumulator = ticketsAccumulator;
9529
+ }
9530
+ }
9531
+
9532
+ ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
9533
+
9534
+
9535
+
9536
+
9537
+
9538
+
9539
+ /**
9540
+ * `B_S`: The basic minimum balance which all services require.
9541
+ *
9542
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
9543
+ */
9544
+ const BASE_SERVICE_BALANCE = 100n;
9545
+ /**
9546
+ * `B_I`: The additional minimum balance required per item of elective service state.
9547
+ *
9548
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
9549
+ */
9550
+ const ELECTIVE_ITEM_BALANCE = 10n;
9551
+ /**
9552
+ * `B_L`: The additional minimum balance required per octet of elective service state.
9553
+ *
9554
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
9555
+ */
9556
+ const ELECTIVE_BYTE_BALANCE = 1n;
9557
+ const zeroSizeHint = {
9558
+ bytes: 0,
9559
+ isExact: true,
9560
+ };
9561
+ /** 0-byte read, return given default value */
9230
9562
  const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
9231
9563
  /** Encode and decode object with leading version number. */
9232
9564
  const codecWithVersion = (val) => Descriptor.new("withVersion", {
@@ -9387,358 +9719,418 @@ class service_LookupHistoryItem {
9387
9719
  }
9388
9720
  }
9389
9721
 
9390
- ;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
9722
+ ;// CONCATENATED MODULE: ./packages/jam/state/statistics.ts
9391
9723
 
9392
9724
 
9393
9725
 
9394
9726
 
9395
9727
 
9396
- /** Dictionary entry of services that auto-accumulate every block. */
9397
- class AutoAccumulate {
9398
- service;
9399
- gasLimit;
9400
- static Codec = descriptors_codec.Class(AutoAccumulate, {
9401
- service: descriptors_codec.u32.asOpaque(),
9402
- gasLimit: descriptors_codec.u64.asOpaque(),
9728
+
9729
+ const codecServiceId = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
9730
+ ? descriptors_codec.u32.asOpaque()
9731
+ : descriptors_codec.varU32.convert((s) => numbers_tryAsU32(s), (i) => tryAsServiceId(i));
9732
+ /**
9733
+ * Activity Record of a single validator.
9734
+ *
9735
+ * https://graypaper.fluffylabs.dev/#/579bd12/183701183701
9736
+ */
9737
+ class ValidatorStatistics {
9738
+ blocks;
9739
+ tickets;
9740
+ preImages;
9741
+ preImagesSize;
9742
+ guarantees;
9743
+ assurances;
9744
+ static Codec = descriptors_codec.Class(ValidatorStatistics, {
9745
+ blocks: descriptors_codec.u32,
9746
+ tickets: descriptors_codec.u32,
9747
+ preImages: descriptors_codec.u32,
9748
+ preImagesSize: descriptors_codec.u32,
9749
+ guarantees: descriptors_codec.u32,
9750
+ assurances: descriptors_codec.u32,
9403
9751
  });
9404
- static create({ service, gasLimit }) {
9405
- return new AutoAccumulate(service, gasLimit);
9752
+ static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
9753
+ return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
9406
9754
  }
9407
9755
  constructor(
9408
- /** Service id that auto-accumulates. */
9409
- service,
9410
- /** Gas limit for auto-accumulation. */
9411
- gasLimit) {
9412
- this.service = service;
9413
- this.gasLimit = gasLimit;
9414
- }
9415
- }
9416
- /**
9417
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
9418
- */
9419
- class PrivilegedServices {
9420
- manager;
9421
- delegator;
9422
- registrar;
9423
- assigners;
9424
- autoAccumulateServices;
9425
- /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
9426
- static Codec = descriptors_codec.Class(PrivilegedServices, {
9427
- manager: descriptors_codec.u32.asOpaque(),
9428
- assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
9429
- delegator: descriptors_codec.u32.asOpaque(),
9430
- registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
9431
- ? descriptors_codec.u32.asOpaque()
9432
- : ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
9433
- autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
9434
- });
9435
- static create(a) {
9436
- return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
9756
+ /** The number of blocks produced by the validator. */
9757
+ blocks,
9758
+ /** The number of tickets introduced by the validator. */
9759
+ tickets,
9760
+ /** The number of preimages introduced by the validator. */
9761
+ preImages,
9762
+ /** The total number of octets across all preimages introduced by the validator. */
9763
+ preImagesSize,
9764
+ /** The number of reports guaranteed by the validator. */
9765
+ guarantees,
9766
+ /** The number of availability assurances made by the validator. */
9767
+ assurances) {
9768
+ this.blocks = blocks;
9769
+ this.tickets = tickets;
9770
+ this.preImages = preImages;
9771
+ this.preImagesSize = preImagesSize;
9772
+ this.guarantees = guarantees;
9773
+ this.assurances = assurances;
9437
9774
  }
9438
- constructor(
9439
- /**
9440
- * `χ_M`: Manages alteration of χ from block to block,
9441
- * as well as bestow services with storage deposit credits.
9442
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
9443
- */
9444
- manager,
9445
- /** `χ_V`: Managers validator keys. */
9446
- delegator,
9447
- /**
9448
- * `χ_R`: Manages the creation of services in protected range.
9449
- *
9450
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
9451
- */
9452
- registrar,
9453
- /** `χ_A`: Manages authorization queue one for each core. */
9454
- assigners,
9455
- /** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
9456
- autoAccumulateServices) {
9457
- this.manager = manager;
9458
- this.delegator = delegator;
9459
- this.registrar = registrar;
9460
- this.assigners = assigners;
9461
- this.autoAccumulateServices = autoAccumulateServices;
9775
+ static empty() {
9776
+ const zero = numbers_tryAsU32(0);
9777
+ return new ValidatorStatistics(zero, zero, zero, zero, zero, zero);
9462
9778
  }
9463
9779
  }
9464
-
9465
- ;// CONCATENATED MODULE: ./packages/jam/state/recent-blocks.ts
9466
-
9467
-
9468
-
9469
-
9470
-
9471
-
9780
+ const codecVarU16 = descriptors_codec.varU32.convert((i) => numbers_tryAsU32(i), (o) => numbers_tryAsU16(o));
9781
+ /** Encode/decode unsigned gas. */
9782
+ const codecVarGas = descriptors_codec.varU64.convert((g) => tryAsU64(g), (i) => tryAsServiceGas(i));
9472
9783
  /**
9473
- * `H = 8`: The size of recent history, in blocks.
9784
+ * Single core statistics.
9785
+ * Updated per block, based on incoming work reports (`w`).
9474
9786
  *
9475
- * https://graypaper.fluffylabs.dev/#/579bd12/416300416500
9787
+ * https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
9788
+ * https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
9476
9789
  */
9477
- const MAX_RECENT_HISTORY = 8;
9478
- /** Recent history of a single block. */
9479
- class BlockState extends WithDebug {
9480
- headerHash;
9481
- accumulationResult;
9482
- postStateRoot;
9483
- reported;
9484
- static Codec = descriptors_codec.Class(BlockState, {
9485
- headerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
9486
- accumulationResult: descriptors_codec.bytes(hash_HASH_SIZE),
9487
- postStateRoot: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
9488
- reported: codecHashDictionary(WorkPackageInfo.Codec, (x) => x.workPackageHash),
9489
- });
9490
- static create({ headerHash, accumulationResult, postStateRoot, reported }) {
9491
- return new BlockState(headerHash, accumulationResult, postStateRoot, reported);
9790
+ class CoreStatistics {
9791
+ dataAvailabilityLoad;
9792
+ popularity;
9793
+ imports;
9794
+ exports;
9795
+ extrinsicSize;
9796
+ extrinsicCount;
9797
+ bundleSize;
9798
+ gasUsed;
9799
+ static Codec = Compatibility.isGreaterOrEqual(GpVersion.V0_7_0)
9800
+ ? descriptors_codec.Class(CoreStatistics, {
9801
+ dataAvailabilityLoad: descriptors_codec.varU32,
9802
+ popularity: codecVarU16,
9803
+ imports: codecVarU16,
9804
+ extrinsicCount: codecVarU16,
9805
+ extrinsicSize: descriptors_codec.varU32,
9806
+ exports: codecVarU16,
9807
+ bundleSize: descriptors_codec.varU32,
9808
+ gasUsed: codecVarGas,
9809
+ })
9810
+ : descriptors_codec.Class(CoreStatistics, {
9811
+ dataAvailabilityLoad: descriptors_codec.varU32,
9812
+ popularity: codecVarU16,
9813
+ imports: codecVarU16,
9814
+ exports: codecVarU16,
9815
+ extrinsicSize: descriptors_codec.varU32,
9816
+ extrinsicCount: codecVarU16,
9817
+ bundleSize: descriptors_codec.varU32,
9818
+ gasUsed: codecVarGas,
9819
+ });
9820
+ static create(v) {
9821
+ return new CoreStatistics(v.dataAvailabilityLoad, v.popularity, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.bundleSize, v.gasUsed);
9492
9822
  }
9493
9823
  constructor(
9494
- /** Header hash. */
9495
- headerHash,
9496
- /** Merkle mountain belt of accumulation result. */
9497
- accumulationResult,
9498
- /** Posterior state root filled in with a 1-block delay. */
9499
- postStateRoot,
9500
- /** Reported work packages (no more than number of cores). */
9501
- reported) {
9502
- super();
9503
- this.headerHash = headerHash;
9504
- this.accumulationResult = accumulationResult;
9505
- this.postStateRoot = postStateRoot;
9506
- this.reported = reported;
9507
- }
9508
- }
9509
- class RecentBlocks extends WithDebug {
9510
- blocks;
9511
- accumulationLog;
9512
- static Codec = descriptors_codec.Class(RecentBlocks, {
9513
- blocks: codecKnownSizeArray(BlockState.Codec, {
9514
- minLength: 0,
9515
- maxLength: MAX_RECENT_HISTORY,
9516
- typicalLength: MAX_RECENT_HISTORY,
9517
- }),
9518
- accumulationLog: descriptors_codec.object({
9519
- peaks: readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.optional(descriptors_codec.bytes(hash_HASH_SIZE)))),
9520
- }),
9521
- });
9522
- static create(a) {
9523
- return new RecentBlocks(a.blocks, a.accumulationLog);
9824
+ /** `d` */
9825
+ dataAvailabilityLoad,
9826
+ /** `p` */
9827
+ popularity,
9828
+ /** `i` */
9829
+ imports,
9830
+ /** `e` */
9831
+ exports,
9832
+ /** `z` */
9833
+ extrinsicSize,
9834
+ /** `x` */
9835
+ extrinsicCount,
9836
+ /** `b` */
9837
+ bundleSize,
9838
+ /** `u` */
9839
+ gasUsed) {
9840
+ this.dataAvailabilityLoad = dataAvailabilityLoad;
9841
+ this.popularity = popularity;
9842
+ this.imports = imports;
9843
+ this.exports = exports;
9844
+ this.extrinsicSize = extrinsicSize;
9845
+ this.extrinsicCount = extrinsicCount;
9846
+ this.bundleSize = bundleSize;
9847
+ this.gasUsed = gasUsed;
9524
9848
  }
9525
- constructor(
9526
- /**
9527
- * Most recent blocks.
9528
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fea010fea01?v=0.6.7
9529
- */
9530
- blocks,
9531
- /**
9532
- * Accumulation output log.
9533
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/0f02020f0202?v=0.6.7
9534
- */
9535
- accumulationLog) {
9536
- super();
9537
- this.blocks = blocks;
9538
- this.accumulationLog = accumulationLog;
9849
+ static empty() {
9850
+ const zero = numbers_tryAsU32(0);
9851
+ const zero16 = numbers_tryAsU16(0);
9852
+ const zeroGas = tryAsServiceGas(0);
9853
+ return new CoreStatistics(zero, zero16, zero16, zero16, zero, zero16, zero, zeroGas);
9539
9854
  }
9540
9855
  }
9541
9856
  /**
9542
- * Recent history of blocks.
9857
+ * Service statistics.
9858
+ * Updated per block, based on available work reports (`W`).
9543
9859
  *
9544
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
9860
+ * https://graypaper.fluffylabs.dev/#/1c979cb/199802199802?v=0.7.1
9545
9861
  */
9546
- class RecentBlocksHistory extends WithDebug {
9547
- current;
9548
- static Codec = Descriptor.new("RecentBlocksHistory", RecentBlocks.Codec.sizeHint, (encoder, value) => RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
9549
- const recentBlocks = RecentBlocks.Codec.decode(decoder);
9550
- return RecentBlocksHistory.create(recentBlocks);
9551
- }, (skip) => {
9552
- return RecentBlocks.Codec.skip(skip);
9862
+ class ServiceStatistics {
9863
+ providedCount;
9864
+ providedSize;
9865
+ refinementCount;
9866
+ refinementGasUsed;
9867
+ imports;
9868
+ exports;
9869
+ extrinsicSize;
9870
+ extrinsicCount;
9871
+ accumulateCount;
9872
+ accumulateGasUsed;
9873
+ onTransfersCount;
9874
+ onTransfersGasUsed;
9875
+ static Codec = Compatibility.selectIfGreaterOrEqual({
9876
+ fallback: descriptors_codec.Class(ServiceStatistics, {
9877
+ providedCount: codecVarU16,
9878
+ providedSize: descriptors_codec.varU32,
9879
+ refinementCount: descriptors_codec.varU32,
9880
+ refinementGasUsed: codecVarGas,
9881
+ imports: codecVarU16,
9882
+ exports: codecVarU16,
9883
+ extrinsicSize: descriptors_codec.varU32,
9884
+ extrinsicCount: codecVarU16,
9885
+ accumulateCount: descriptors_codec.varU32,
9886
+ accumulateGasUsed: codecVarGas,
9887
+ onTransfersCount: descriptors_codec.varU32,
9888
+ onTransfersGasUsed: codecVarGas,
9889
+ }),
9890
+ versions: {
9891
+ [GpVersion.V0_7_0]: descriptors_codec.Class(ServiceStatistics, {
9892
+ providedCount: codecVarU16,
9893
+ providedSize: descriptors_codec.varU32,
9894
+ refinementCount: descriptors_codec.varU32,
9895
+ refinementGasUsed: codecVarGas,
9896
+ imports: codecVarU16,
9897
+ extrinsicCount: codecVarU16,
9898
+ extrinsicSize: descriptors_codec.varU32,
9899
+ exports: codecVarU16,
9900
+ accumulateCount: descriptors_codec.varU32,
9901
+ accumulateGasUsed: codecVarGas,
9902
+ onTransfersCount: descriptors_codec.varU32,
9903
+ onTransfersGasUsed: codecVarGas,
9904
+ }),
9905
+ [GpVersion.V0_7_1]: descriptors_codec.Class(ServiceStatistics, {
9906
+ providedCount: codecVarU16,
9907
+ providedSize: descriptors_codec.varU32,
9908
+ refinementCount: descriptors_codec.varU32,
9909
+ refinementGasUsed: codecVarGas,
9910
+ imports: codecVarU16,
9911
+ extrinsicCount: codecVarU16,
9912
+ extrinsicSize: descriptors_codec.varU32,
9913
+ exports: codecVarU16,
9914
+ accumulateCount: descriptors_codec.varU32,
9915
+ accumulateGasUsed: codecVarGas,
9916
+ onTransfersCount: ignoreValueWithDefault(numbers_tryAsU32(0)),
9917
+ onTransfersGasUsed: ignoreValueWithDefault(tryAsServiceGas(0)),
9918
+ }),
9919
+ },
9553
9920
  });
9554
- static create(recentBlocks) {
9555
- return new RecentBlocksHistory(recentBlocks);
9921
+ static create(v) {
9922
+ 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);
9923
+ }
9924
+ constructor(
9925
+ /** `p.0` */
9926
+ providedCount,
9927
+ /** `p.1` */
9928
+ providedSize,
9929
+ /** `r.0` */
9930
+ refinementCount,
9931
+ /** `r.1` */
9932
+ refinementGasUsed,
9933
+ /** `i` */
9934
+ imports,
9935
+ /** `e` */
9936
+ exports,
9937
+ /** `z` */
9938
+ extrinsicSize,
9939
+ /** `x` */
9940
+ extrinsicCount,
9941
+ /** `a.0` */
9942
+ accumulateCount,
9943
+ /** `a.1` */
9944
+ accumulateGasUsed,
9945
+ /** `t.0` @deprecated since 0.7.1 */
9946
+ onTransfersCount,
9947
+ /** `t.1` @deprecated since 0.7.1 */
9948
+ onTransfersGasUsed) {
9949
+ this.providedCount = providedCount;
9950
+ this.providedSize = providedSize;
9951
+ this.refinementCount = refinementCount;
9952
+ this.refinementGasUsed = refinementGasUsed;
9953
+ this.imports = imports;
9954
+ this.exports = exports;
9955
+ this.extrinsicSize = extrinsicSize;
9956
+ this.extrinsicCount = extrinsicCount;
9957
+ this.accumulateCount = accumulateCount;
9958
+ this.accumulateGasUsed = accumulateGasUsed;
9959
+ this.onTransfersCount = onTransfersCount;
9960
+ this.onTransfersGasUsed = onTransfersGasUsed;
9556
9961
  }
9557
9962
  static empty() {
9558
- return RecentBlocksHistory.create(RecentBlocks.create({
9559
- blocks: sized_array_asKnownSize([]),
9560
- accumulationLog: { peaks: [] },
9561
- }));
9963
+ const zero = numbers_tryAsU32(0);
9964
+ const zero16 = numbers_tryAsU16(0);
9965
+ const zeroGas = tryAsServiceGas(0);
9966
+ return new ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
9562
9967
  }
9563
- /**
9564
- * Returns the block's BEEFY super peak.
9565
- */
9566
- static accumulationResult(block) {
9567
- return block.accumulationResult;
9968
+ }
9969
+ /** `pi`: Statistics of each validator, cores statistics and services statistics. */
9970
+ class StatisticsData {
9971
+ current;
9972
+ previous;
9973
+ cores;
9974
+ services;
9975
+ static Codec = descriptors_codec.Class(StatisticsData, {
9976
+ current: common_codecPerValidator(ValidatorStatistics.Codec),
9977
+ previous: common_codecPerValidator(ValidatorStatistics.Codec),
9978
+ cores: codecPerCore(CoreStatistics.Codec),
9979
+ services: descriptors_codec.dictionary(codecServiceId, ServiceStatistics.Codec, {
9980
+ sortKeys: (a, b) => a - b,
9981
+ }),
9982
+ });
9983
+ static create(v) {
9984
+ return new StatisticsData(v.current, v.previous, v.cores, v.services);
9568
9985
  }
9569
- constructor(current) {
9570
- super();
9986
+ constructor(current, previous, cores, services) {
9571
9987
  this.current = current;
9572
- }
9573
- /** History of recent blocks with maximum size of `MAX_RECENT_HISTORY` */
9574
- get blocks() {
9575
- if (this.current !== null) {
9576
- return this.current.blocks;
9577
- }
9578
- throw new Error("RecentBlocksHistory is in invalid state");
9579
- }
9580
- asCurrent() {
9581
- if (this.current === null) {
9582
- throw new Error("Cannot access current RecentBlocks format");
9583
- }
9584
- return this.current;
9585
- }
9586
- updateBlocks(blocks) {
9587
- if (this.current !== null) {
9588
- return RecentBlocksHistory.create(RecentBlocks.create({
9589
- ...this.current,
9590
- blocks: opaque_asOpaqueType(blocks),
9591
- }));
9592
- }
9593
- throw new Error("RecentBlocksHistory is in invalid state. Cannot be updated!");
9988
+ this.previous = previous;
9989
+ this.cores = cores;
9990
+ this.services = services;
9594
9991
  }
9595
9992
  }
9596
9993
 
9597
- ;// CONCATENATED MODULE: ./packages/jam/state/validator-data.ts
9994
+ ;// CONCATENATED MODULE: ./packages/jam/state/in-memory-state-view.ts
9598
9995
 
9599
9996
 
9600
9997
 
9601
- /**
9602
- * Fixed size of validator metadata.
9603
- *
9604
- * https://graypaper.fluffylabs.dev/#/5f542d7/0d55010d5501
9605
- */
9606
- const VALIDATOR_META_BYTES = 128;
9607
- /**
9608
- * Details about validators' identity.
9609
- *
9610
- * https://graypaper.fluffylabs.dev/#/5f542d7/0d4b010d4c01
9611
- */
9612
- class ValidatorData extends WithDebug {
9613
- bandersnatch;
9614
- ed25519;
9615
- bls;
9616
- metadata;
9617
- static Codec = descriptors_codec.Class(ValidatorData, {
9618
- bandersnatch: descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque(),
9619
- ed25519: descriptors_codec.bytes(ED25519_KEY_BYTES).asOpaque(),
9620
- bls: descriptors_codec.bytes(BLS_KEY_BYTES).asOpaque(),
9621
- metadata: descriptors_codec.bytes(VALIDATOR_META_BYTES),
9622
- });
9623
- static create({ ed25519, bandersnatch, bls, metadata }) {
9624
- return new ValidatorData(bandersnatch, ed25519, bls, metadata);
9625
- }
9626
- constructor(
9627
- /** Bandersnatch public key. */
9628
- bandersnatch,
9629
- /** ED25519 key data. */
9630
- ed25519,
9631
- /** BLS public key. */
9632
- bls,
9633
- /** Validator-defined additional metdata. */
9634
- metadata) {
9635
- super();
9636
- this.bandersnatch = bandersnatch;
9637
- this.ed25519 = ed25519;
9638
- this.bls = bls;
9639
- this.metadata = metadata;
9640
- }
9641
- }
9642
9998
 
9643
- ;// CONCATENATED MODULE: ./packages/jam/state/safrole-data.ts
9644
9999
 
9645
10000
 
9646
10001
 
9647
10002
 
9648
10003
 
9649
10004
 
10005
+ class InMemoryStateView {
10006
+ chainSpec;
10007
+ state;
10008
+ constructor(chainSpec, state) {
10009
+ this.chainSpec = chainSpec;
10010
+ this.state = state;
10011
+ }
10012
+ availabilityAssignmentView() {
10013
+ return reencodeAsView(availabilityAssignmentsCodec, this.state.availabilityAssignment, this.chainSpec);
10014
+ }
10015
+ designatedValidatorDataView() {
10016
+ return reencodeAsView(validatorsDataCodec, this.state.designatedValidatorData, this.chainSpec);
10017
+ }
10018
+ currentValidatorDataView() {
10019
+ return reencodeAsView(validatorsDataCodec, this.state.currentValidatorData, this.chainSpec);
10020
+ }
10021
+ previousValidatorDataView() {
10022
+ return reencodeAsView(validatorsDataCodec, this.state.previousValidatorData, this.chainSpec);
10023
+ }
10024
+ authPoolsView() {
10025
+ return reencodeAsView(authPoolsCodec, this.state.authPools, this.chainSpec);
10026
+ }
10027
+ authQueuesView() {
10028
+ return reencodeAsView(authQueuesCodec, this.state.authQueues, this.chainSpec);
10029
+ }
10030
+ recentBlocksView() {
10031
+ return reencodeAsView(RecentBlocks.Codec, this.state.recentBlocks, this.chainSpec);
10032
+ }
10033
+ statisticsView() {
10034
+ return reencodeAsView(StatisticsData.Codec, this.state.statistics, this.chainSpec);
10035
+ }
10036
+ accumulationQueueView() {
10037
+ return reencodeAsView(accumulationQueueCodec, this.state.accumulationQueue, this.chainSpec);
10038
+ }
10039
+ recentlyAccumulatedView() {
10040
+ return reencodeAsView(recentlyAccumulatedCodec, this.state.recentlyAccumulated, this.chainSpec);
10041
+ }
10042
+ safroleDataView() {
10043
+ // TODO [ToDr] Consider exposting `safrole` from state
10044
+ // instead of individual fields
10045
+ const safrole = SafroleData.create({
10046
+ nextValidatorData: this.state.nextValidatorData,
10047
+ epochRoot: this.state.epochRoot,
10048
+ sealingKeySeries: this.state.sealingKeySeries,
10049
+ ticketsAccumulator: this.state.ticketsAccumulator,
10050
+ });
10051
+ return reencodeAsView(SafroleData.Codec, safrole, this.chainSpec);
10052
+ }
10053
+ getServiceInfoView(id) {
10054
+ const service = this.state.getService(id);
10055
+ if (service === null) {
10056
+ return null;
10057
+ }
10058
+ return reencodeAsView(ServiceAccountInfo.Codec, service.getInfo(), this.chainSpec);
10059
+ }
10060
+ }
9650
10061
 
10062
+ ;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
9651
10063
 
9652
10064
 
9653
10065
 
9654
10066
 
9655
- var SafroleSealingKeysKind;
9656
- (function (SafroleSealingKeysKind) {
9657
- SafroleSealingKeysKind[SafroleSealingKeysKind["Tickets"] = 0] = "Tickets";
9658
- SafroleSealingKeysKind[SafroleSealingKeysKind["Keys"] = 1] = "Keys";
9659
- })(SafroleSealingKeysKind || (SafroleSealingKeysKind = {}));
9660
- const codecBandersnatchKey = descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque();
9661
- class SafroleSealingKeysData extends WithDebug {
9662
- kind;
9663
- keys;
9664
- tickets;
9665
- static Codec = codecWithContext((context) => {
9666
- return descriptors_codec.custom({
9667
- name: "SafroleSealingKeys",
9668
- sizeHint: { bytes: 1 + hash_HASH_SIZE * context.epochLength, isExact: false },
9669
- }, (e, x) => {
9670
- e.varU32(numbers_tryAsU32(x.kind));
9671
- if (x.kind === SafroleSealingKeysKind.Keys) {
9672
- e.sequenceFixLen(codecBandersnatchKey, x.keys);
9673
- }
9674
- else {
9675
- e.sequenceFixLen(Ticket.Codec, x.tickets);
9676
- }
9677
- }, (d) => {
9678
- const epochLength = context.epochLength;
9679
- const kind = d.varU32();
9680
- if (kind === SafroleSealingKeysKind.Keys) {
9681
- const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
9682
- return SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
9683
- }
9684
- if (kind === SafroleSealingKeysKind.Tickets) {
9685
- const tickets = d.sequenceFixLen(Ticket.Codec, epochLength);
9686
- return SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
9687
- }
9688
- throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
9689
- }, (s) => {
9690
- const kind = s.decoder.varU32();
9691
- if (kind === SafroleSealingKeysKind.Keys) {
9692
- s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
9693
- return;
9694
- }
9695
- if (kind === SafroleSealingKeysKind.Tickets) {
9696
- s.sequenceFixLen(Ticket.Codec, context.epochLength);
9697
- return;
9698
- }
9699
- throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
9700
- });
9701
- });
9702
- static keys(keys) {
9703
- return new SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
9704
- }
9705
- static tickets(tickets) {
9706
- return new SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
10067
+
10068
+ /** Dictionary entry of services that auto-accumulate every block. */
10069
+ class AutoAccumulate {
10070
+ service;
10071
+ gasLimit;
10072
+ static Codec = descriptors_codec.Class(AutoAccumulate, {
10073
+ service: descriptors_codec.u32.asOpaque(),
10074
+ gasLimit: descriptors_codec.u64.asOpaque(),
10075
+ });
10076
+ static create({ service, gasLimit }) {
10077
+ return new AutoAccumulate(service, gasLimit);
9707
10078
  }
9708
- constructor(kind, keys, tickets) {
9709
- super();
9710
- this.kind = kind;
9711
- this.keys = keys;
9712
- this.tickets = tickets;
10079
+ constructor(
10080
+ /** Service id that auto-accumulates. */
10081
+ service,
10082
+ /** Gas limit for auto-accumulation. */
10083
+ gasLimit) {
10084
+ this.service = service;
10085
+ this.gasLimit = gasLimit;
9713
10086
  }
9714
10087
  }
9715
- class SafroleData {
9716
- nextValidatorData;
9717
- epochRoot;
9718
- sealingKeySeries;
9719
- ticketsAccumulator;
9720
- static Codec = descriptors_codec.Class(SafroleData, {
9721
- nextValidatorData: codecPerValidator(ValidatorData.Codec),
9722
- epochRoot: descriptors_codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
9723
- sealingKeySeries: SafroleSealingKeysData.Codec,
9724
- ticketsAccumulator: readonlyArray(descriptors_codec.sequenceVarLen(Ticket.Codec)).convert(seeThrough, sized_array_asKnownSize),
10088
+ /**
10089
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
10090
+ */
10091
+ class PrivilegedServices {
10092
+ manager;
10093
+ delegator;
10094
+ registrar;
10095
+ assigners;
10096
+ autoAccumulateServices;
10097
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
10098
+ static Codec = descriptors_codec.Class(PrivilegedServices, {
10099
+ manager: descriptors_codec.u32.asOpaque(),
10100
+ assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
10101
+ delegator: descriptors_codec.u32.asOpaque(),
10102
+ registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
10103
+ ? descriptors_codec.u32.asOpaque()
10104
+ : ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
10105
+ autoAccumulateServices: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
9725
10106
  });
9726
- static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
9727
- return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
10107
+ static create(a) {
10108
+ return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
9728
10109
  }
9729
10110
  constructor(
9730
- /** gamma_k */
9731
- nextValidatorData,
9732
- /** gamma_z */
9733
- epochRoot,
9734
- /** gamma_s */
9735
- sealingKeySeries,
9736
- /** gamma_a */
9737
- ticketsAccumulator) {
9738
- this.nextValidatorData = nextValidatorData;
9739
- this.epochRoot = epochRoot;
9740
- this.sealingKeySeries = sealingKeySeries;
9741
- this.ticketsAccumulator = ticketsAccumulator;
10111
+ /**
10112
+ * `χ_M`: Manages alteration of χ from block to block,
10113
+ * as well as bestow services with storage deposit credits.
10114
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
10115
+ */
10116
+ manager,
10117
+ /** `χ_V`: Managers validator keys. */
10118
+ delegator,
10119
+ /**
10120
+ * `χ_R`: Manages the creation of services in protected range.
10121
+ *
10122
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
10123
+ */
10124
+ registrar,
10125
+ /** `χ_A`: Manages authorization queue one for each core. */
10126
+ assigners,
10127
+ /** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
10128
+ autoAccumulateServices) {
10129
+ this.manager = manager;
10130
+ this.delegator = delegator;
10131
+ this.registrar = registrar;
10132
+ this.assigners = assigners;
10133
+ this.autoAccumulateServices = autoAccumulateServices;
9742
10134
  }
9743
10135
  }
9744
10136
 
@@ -9857,321 +10249,49 @@ class UpdateService {
9857
10249
  }
9858
10250
  static create({ serviceId, serviceInfo, lookupHistory, }) {
9859
10251
  return new UpdateService(serviceId, {
9860
- kind: UpdateServiceKind.Create,
9861
- account: serviceInfo,
9862
- lookupHistory,
9863
- });
9864
- }
9865
- }
9866
- /** Update service storage kind. */
9867
- var UpdateStorageKind;
9868
- (function (UpdateStorageKind) {
9869
- /** Set a storage value. */
9870
- UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
9871
- /** Remove a storage value. */
9872
- UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
9873
- })(UpdateStorageKind || (UpdateStorageKind = {}));
9874
- /**
9875
- * Update service storage item.
9876
- *
9877
- * Can either create/modify an entry or remove it.
9878
- */
9879
- class UpdateStorage {
9880
- serviceId;
9881
- action;
9882
- constructor(serviceId, action) {
9883
- this.serviceId = serviceId;
9884
- this.action = action;
9885
- }
9886
- static set({ serviceId, storage }) {
9887
- return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Set, storage });
9888
- }
9889
- static remove({ serviceId, key }) {
9890
- return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Remove, key });
9891
- }
9892
- get key() {
9893
- if (this.action.kind === UpdateStorageKind.Remove) {
9894
- return this.action.key;
9895
- }
9896
- return this.action.storage.key;
9897
- }
9898
- get value() {
9899
- if (this.action.kind === UpdateStorageKind.Remove) {
9900
- return null;
9901
- }
9902
- return this.action.storage.value;
9903
- }
9904
- }
9905
-
9906
- ;// CONCATENATED MODULE: ./packages/jam/state/statistics.ts
9907
-
9908
-
9909
-
9910
-
9911
-
9912
-
9913
- const codecServiceId = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
9914
- ? descriptors_codec.u32.asOpaque()
9915
- : descriptors_codec.varU32.convert((s) => numbers_tryAsU32(s), (i) => tryAsServiceId(i));
9916
- /**
9917
- * Activity Record of a single validator.
9918
- *
9919
- * https://graypaper.fluffylabs.dev/#/579bd12/183701183701
9920
- */
9921
- class ValidatorStatistics {
9922
- blocks;
9923
- tickets;
9924
- preImages;
9925
- preImagesSize;
9926
- guarantees;
9927
- assurances;
9928
- static Codec = descriptors_codec.Class(ValidatorStatistics, {
9929
- blocks: descriptors_codec.u32,
9930
- tickets: descriptors_codec.u32,
9931
- preImages: descriptors_codec.u32,
9932
- preImagesSize: descriptors_codec.u32,
9933
- guarantees: descriptors_codec.u32,
9934
- assurances: descriptors_codec.u32,
9935
- });
9936
- static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
9937
- return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
9938
- }
9939
- constructor(
9940
- /** The number of blocks produced by the validator. */
9941
- blocks,
9942
- /** The number of tickets introduced by the validator. */
9943
- tickets,
9944
- /** The number of preimages introduced by the validator. */
9945
- preImages,
9946
- /** The total number of octets across all preimages introduced by the validator. */
9947
- preImagesSize,
9948
- /** The number of reports guaranteed by the validator. */
9949
- guarantees,
9950
- /** The number of availability assurances made by the validator. */
9951
- assurances) {
9952
- this.blocks = blocks;
9953
- this.tickets = tickets;
9954
- this.preImages = preImages;
9955
- this.preImagesSize = preImagesSize;
9956
- this.guarantees = guarantees;
9957
- this.assurances = assurances;
9958
- }
9959
- static empty() {
9960
- const zero = numbers_tryAsU32(0);
9961
- return new ValidatorStatistics(zero, zero, zero, zero, zero, zero);
9962
- }
9963
- }
9964
- const codecVarU16 = descriptors_codec.varU32.convert((i) => numbers_tryAsU32(i), (o) => numbers_tryAsU16(o));
9965
- /** Encode/decode unsigned gas. */
9966
- const codecVarGas = descriptors_codec.varU64.convert((g) => tryAsU64(g), (i) => tryAsServiceGas(i));
9967
- /**
9968
- * Single core statistics.
9969
- * Updated per block, based on incoming work reports (`w`).
9970
- *
9971
- * https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
9972
- * https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
9973
- */
9974
- class CoreStatistics {
9975
- dataAvailabilityLoad;
9976
- popularity;
9977
- imports;
9978
- exports;
9979
- extrinsicSize;
9980
- extrinsicCount;
9981
- bundleSize;
9982
- gasUsed;
9983
- static Codec = Compatibility.isGreaterOrEqual(GpVersion.V0_7_0)
9984
- ? descriptors_codec.Class(CoreStatistics, {
9985
- dataAvailabilityLoad: descriptors_codec.varU32,
9986
- popularity: codecVarU16,
9987
- imports: codecVarU16,
9988
- extrinsicCount: codecVarU16,
9989
- extrinsicSize: descriptors_codec.varU32,
9990
- exports: codecVarU16,
9991
- bundleSize: descriptors_codec.varU32,
9992
- gasUsed: codecVarGas,
9993
- })
9994
- : descriptors_codec.Class(CoreStatistics, {
9995
- dataAvailabilityLoad: descriptors_codec.varU32,
9996
- popularity: codecVarU16,
9997
- imports: codecVarU16,
9998
- exports: codecVarU16,
9999
- extrinsicSize: descriptors_codec.varU32,
10000
- extrinsicCount: codecVarU16,
10001
- bundleSize: descriptors_codec.varU32,
10002
- gasUsed: codecVarGas,
10003
- });
10004
- static create(v) {
10005
- return new CoreStatistics(v.dataAvailabilityLoad, v.popularity, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.bundleSize, v.gasUsed);
10006
- }
10007
- constructor(
10008
- /** `d` */
10009
- dataAvailabilityLoad,
10010
- /** `p` */
10011
- popularity,
10012
- /** `i` */
10013
- imports,
10014
- /** `e` */
10015
- exports,
10016
- /** `z` */
10017
- extrinsicSize,
10018
- /** `x` */
10019
- extrinsicCount,
10020
- /** `b` */
10021
- bundleSize,
10022
- /** `u` */
10023
- gasUsed) {
10024
- this.dataAvailabilityLoad = dataAvailabilityLoad;
10025
- this.popularity = popularity;
10026
- this.imports = imports;
10027
- this.exports = exports;
10028
- this.extrinsicSize = extrinsicSize;
10029
- this.extrinsicCount = extrinsicCount;
10030
- this.bundleSize = bundleSize;
10031
- this.gasUsed = gasUsed;
10032
- }
10033
- static empty() {
10034
- const zero = numbers_tryAsU32(0);
10035
- const zero16 = numbers_tryAsU16(0);
10036
- const zeroGas = tryAsServiceGas(0);
10037
- return new CoreStatistics(zero, zero16, zero16, zero16, zero, zero16, zero, zeroGas);
10252
+ kind: UpdateServiceKind.Create,
10253
+ account: serviceInfo,
10254
+ lookupHistory,
10255
+ });
10038
10256
  }
10039
10257
  }
10258
+ /** Update service storage kind. */
10259
+ var UpdateStorageKind;
10260
+ (function (UpdateStorageKind) {
10261
+ /** Set a storage value. */
10262
+ UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
10263
+ /** Remove a storage value. */
10264
+ UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
10265
+ })(UpdateStorageKind || (UpdateStorageKind = {}));
10040
10266
  /**
10041
- * Service statistics.
10042
- * Updated per block, based on available work reports (`W`).
10267
+ * Update service storage item.
10043
10268
  *
10044
- * https://graypaper.fluffylabs.dev/#/1c979cb/199802199802?v=0.7.1
10269
+ * Can either create/modify an entry or remove it.
10045
10270
  */
10046
- class ServiceStatistics {
10047
- providedCount;
10048
- providedSize;
10049
- refinementCount;
10050
- refinementGasUsed;
10051
- imports;
10052
- exports;
10053
- extrinsicSize;
10054
- extrinsicCount;
10055
- accumulateCount;
10056
- accumulateGasUsed;
10057
- onTransfersCount;
10058
- onTransfersGasUsed;
10059
- static Codec = Compatibility.selectIfGreaterOrEqual({
10060
- fallback: descriptors_codec.Class(ServiceStatistics, {
10061
- providedCount: codecVarU16,
10062
- providedSize: descriptors_codec.varU32,
10063
- refinementCount: descriptors_codec.varU32,
10064
- refinementGasUsed: codecVarGas,
10065
- imports: codecVarU16,
10066
- exports: codecVarU16,
10067
- extrinsicSize: descriptors_codec.varU32,
10068
- extrinsicCount: codecVarU16,
10069
- accumulateCount: descriptors_codec.varU32,
10070
- accumulateGasUsed: codecVarGas,
10071
- onTransfersCount: descriptors_codec.varU32,
10072
- onTransfersGasUsed: codecVarGas,
10073
- }),
10074
- versions: {
10075
- [GpVersion.V0_7_0]: descriptors_codec.Class(ServiceStatistics, {
10076
- providedCount: codecVarU16,
10077
- providedSize: descriptors_codec.varU32,
10078
- refinementCount: descriptors_codec.varU32,
10079
- refinementGasUsed: codecVarGas,
10080
- imports: codecVarU16,
10081
- extrinsicCount: codecVarU16,
10082
- extrinsicSize: descriptors_codec.varU32,
10083
- exports: codecVarU16,
10084
- accumulateCount: descriptors_codec.varU32,
10085
- accumulateGasUsed: codecVarGas,
10086
- onTransfersCount: descriptors_codec.varU32,
10087
- onTransfersGasUsed: codecVarGas,
10088
- }),
10089
- [GpVersion.V0_7_1]: descriptors_codec.Class(ServiceStatistics, {
10090
- providedCount: codecVarU16,
10091
- providedSize: descriptors_codec.varU32,
10092
- refinementCount: descriptors_codec.varU32,
10093
- refinementGasUsed: codecVarGas,
10094
- imports: codecVarU16,
10095
- extrinsicCount: codecVarU16,
10096
- extrinsicSize: descriptors_codec.varU32,
10097
- exports: codecVarU16,
10098
- accumulateCount: descriptors_codec.varU32,
10099
- accumulateGasUsed: codecVarGas,
10100
- onTransfersCount: ignoreValueWithDefault(numbers_tryAsU32(0)),
10101
- onTransfersGasUsed: ignoreValueWithDefault(tryAsServiceGas(0)),
10102
- }),
10103
- },
10104
- });
10105
- static create(v) {
10106
- 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);
10271
+ class UpdateStorage {
10272
+ serviceId;
10273
+ action;
10274
+ constructor(serviceId, action) {
10275
+ this.serviceId = serviceId;
10276
+ this.action = action;
10107
10277
  }
10108
- constructor(
10109
- /** `p.0` */
10110
- providedCount,
10111
- /** `p.1` */
10112
- providedSize,
10113
- /** `r.0` */
10114
- refinementCount,
10115
- /** `r.1` */
10116
- refinementGasUsed,
10117
- /** `i` */
10118
- imports,
10119
- /** `e` */
10120
- exports,
10121
- /** `z` */
10122
- extrinsicSize,
10123
- /** `x` */
10124
- extrinsicCount,
10125
- /** `a.0` */
10126
- accumulateCount,
10127
- /** `a.1` */
10128
- accumulateGasUsed,
10129
- /** `t.0` @deprecated since 0.7.1 */
10130
- onTransfersCount,
10131
- /** `t.1` @deprecated since 0.7.1 */
10132
- onTransfersGasUsed) {
10133
- this.providedCount = providedCount;
10134
- this.providedSize = providedSize;
10135
- this.refinementCount = refinementCount;
10136
- this.refinementGasUsed = refinementGasUsed;
10137
- this.imports = imports;
10138
- this.exports = exports;
10139
- this.extrinsicSize = extrinsicSize;
10140
- this.extrinsicCount = extrinsicCount;
10141
- this.accumulateCount = accumulateCount;
10142
- this.accumulateGasUsed = accumulateGasUsed;
10143
- this.onTransfersCount = onTransfersCount;
10144
- this.onTransfersGasUsed = onTransfersGasUsed;
10278
+ static set({ serviceId, storage }) {
10279
+ return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Set, storage });
10145
10280
  }
10146
- static empty() {
10147
- const zero = numbers_tryAsU32(0);
10148
- const zero16 = numbers_tryAsU16(0);
10149
- const zeroGas = tryAsServiceGas(0);
10150
- return new ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
10281
+ static remove({ serviceId, key }) {
10282
+ return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Remove, key });
10151
10283
  }
10152
- }
10153
- /** `pi`: Statistics of each validator, cores statistics and services statistics. */
10154
- class StatisticsData {
10155
- current;
10156
- previous;
10157
- cores;
10158
- services;
10159
- static Codec = descriptors_codec.Class(StatisticsData, {
10160
- current: codecPerValidator(ValidatorStatistics.Codec),
10161
- previous: codecPerValidator(ValidatorStatistics.Codec),
10162
- cores: codecPerCore(CoreStatistics.Codec),
10163
- services: descriptors_codec.dictionary(codecServiceId, ServiceStatistics.Codec, {
10164
- sortKeys: (a, b) => a - b,
10165
- }),
10166
- });
10167
- static create(v) {
10168
- return new StatisticsData(v.current, v.previous, v.cores, v.services);
10284
+ get key() {
10285
+ if (this.action.kind === UpdateStorageKind.Remove) {
10286
+ return this.action.key;
10287
+ }
10288
+ return this.action.storage.key;
10169
10289
  }
10170
- constructor(current, previous, cores, services) {
10171
- this.current = current;
10172
- this.previous = previous;
10173
- this.cores = cores;
10174
- this.services = services;
10290
+ get value() {
10291
+ if (this.action.kind === UpdateStorageKind.Remove) {
10292
+ return null;
10293
+ }
10294
+ return this.action.storage.value;
10175
10295
  }
10176
10296
  }
10177
10297
 
@@ -10196,6 +10316,7 @@ class StatisticsData {
10196
10316
 
10197
10317
 
10198
10318
 
10319
+
10199
10320
 
10200
10321
 
10201
10322
  var in_memory_state_UpdateError;
@@ -10296,10 +10417,11 @@ class InMemoryService extends WithDebug {
10296
10417
  /**
10297
10418
  * A special version of state, stored fully in-memory.
10298
10419
  */
10299
- class InMemoryState extends WithDebug {
10420
+ class in_memory_state_InMemoryState extends WithDebug {
10421
+ chainSpec;
10300
10422
  /** Create a new `InMemoryState` by providing all required fields. */
10301
- static create(state) {
10302
- return new InMemoryState(state);
10423
+ static new(chainSpec, state) {
10424
+ return new in_memory_state_InMemoryState(chainSpec, state);
10303
10425
  }
10304
10426
  /**
10305
10427
  * Create a new `InMemoryState` with a partial state override.
@@ -10308,14 +10430,14 @@ class InMemoryState extends WithDebug {
10308
10430
  * not-necessarily coherent values.
10309
10431
  */
10310
10432
  static partial(spec, partial) {
10311
- const state = InMemoryState.empty(spec);
10433
+ const state = in_memory_state_InMemoryState.empty(spec);
10312
10434
  Object.assign(state, partial);
10313
10435
  return state;
10314
10436
  }
10315
10437
  /**
10316
10438
  * Create a new `InMemoryState` from some other state object.
10317
10439
  */
10318
- static copyFrom(other, servicesData) {
10440
+ static copyFrom(chainSpec, other, servicesData) {
10319
10441
  const services = new Map();
10320
10442
  for (const [id, entries] of servicesData.entries()) {
10321
10443
  const service = other.getService(id);
@@ -10325,7 +10447,7 @@ class InMemoryState extends WithDebug {
10325
10447
  const inMemService = InMemoryService.copyFrom(service, entries);
10326
10448
  services.set(id, inMemService);
10327
10449
  }
10328
- return InMemoryState.create({
10450
+ return in_memory_state_InMemoryState.new(chainSpec, {
10329
10451
  availabilityAssignment: other.availabilityAssignment,
10330
10452
  accumulationQueue: other.accumulationQueue,
10331
10453
  designatedValidatorData: other.designatedValidatorData,
@@ -10522,8 +10644,9 @@ class InMemoryState extends WithDebug {
10522
10644
  getService(id) {
10523
10645
  return this.services.get(id) ?? null;
10524
10646
  }
10525
- constructor(s) {
10647
+ constructor(chainSpec, s) {
10526
10648
  super();
10649
+ this.chainSpec = chainSpec;
10527
10650
  this.availabilityAssignment = s.availabilityAssignment;
10528
10651
  this.designatedValidatorData = s.designatedValidatorData;
10529
10652
  this.nextValidatorData = s.nextValidatorData;
@@ -10545,31 +10668,34 @@ class InMemoryState extends WithDebug {
10545
10668
  this.accumulationOutputLog = s.accumulationOutputLog;
10546
10669
  this.services = s.services;
10547
10670
  }
10671
+ view() {
10672
+ return new InMemoryStateView(this.chainSpec, this);
10673
+ }
10548
10674
  /**
10549
10675
  * Create an empty and possibly incoherent `InMemoryState`.
10550
10676
  */
10551
10677
  static empty(spec) {
10552
- return new InMemoryState({
10678
+ return new in_memory_state_InMemoryState(spec, {
10553
10679
  availabilityAssignment: tryAsPerCore(Array.from({ length: spec.coresCount }, () => null), spec),
10554
- designatedValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
10680
+ designatedValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
10555
10681
  bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
10556
10682
  bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
10557
10683
  ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
10558
10684
  metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
10559
10685
  })), spec),
10560
- nextValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
10686
+ nextValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
10561
10687
  bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
10562
10688
  bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
10563
10689
  ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
10564
10690
  metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
10565
10691
  })), spec),
10566
- currentValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
10692
+ currentValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
10567
10693
  bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
10568
10694
  bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
10569
10695
  ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
10570
10696
  metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
10571
10697
  })), spec),
10572
- previousValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
10698
+ previousValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
10573
10699
  bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
10574
10700
  bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
10575
10701
  ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
@@ -10585,7 +10711,7 @@ class InMemoryState extends WithDebug {
10585
10711
  entropy: FixedSizeArray.fill(() => bytes_Bytes.zero(hash_HASH_SIZE).asOpaque(), ENTROPY_ENTRIES),
10586
10712
  authPools: tryAsPerCore(Array.from({ length: spec.coresCount }, () => sized_array_asKnownSize([])), spec),
10587
10713
  authQueues: tryAsPerCore(Array.from({ length: spec.coresCount }, () => FixedSizeArray.fill(() => bytes_Bytes.zero(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE)), spec),
10588
- recentBlocks: RecentBlocksHistory.empty(),
10714
+ recentBlocks: RecentBlocks.empty(),
10589
10715
  statistics: StatisticsData.create({
10590
10716
  current: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
10591
10717
  previous: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
@@ -10595,8 +10721,8 @@ class InMemoryState extends WithDebug {
10595
10721
  accumulationQueue: tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => []), spec),
10596
10722
  recentlyAccumulated: tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => HashSet.new()), spec),
10597
10723
  ticketsAccumulator: sized_array_asKnownSize([]),
10598
- sealingKeySeries: SafroleSealingKeysData.keys(tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque()), spec)),
10599
- epochRoot: bytes_Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
10724
+ sealingKeySeries: safrole_data_SafroleSealingKeysData.keys(tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque()), spec)),
10725
+ epochRoot: bytes_Bytes.zero(bandersnatch_BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
10600
10726
  privilegedServices: PrivilegedServices.create({
10601
10727
  manager: tryAsServiceId(0),
10602
10728
  assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
@@ -10636,50 +10762,9 @@ const serviceDataCodec = descriptors_codec.dictionary(descriptors_codec.u32.asOp
10636
10762
 
10637
10763
 
10638
10764
 
10639
- ;// CONCATENATED MODULE: ./packages/jam/state/not-yet-accumulated.ts
10640
-
10641
-
10642
-
10643
10765
 
10644
10766
 
10645
10767
 
10646
- /**
10647
- * Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
10648
- *
10649
- * https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
10650
- */
10651
- class NotYetAccumulatedReport extends WithDebug {
10652
- report;
10653
- dependencies;
10654
- static Codec = descriptors_codec.Class(NotYetAccumulatedReport, {
10655
- report: WorkReport.Codec,
10656
- dependencies: codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
10657
- typicalLength: MAX_REPORT_DEPENDENCIES / 2,
10658
- maxLength: MAX_REPORT_DEPENDENCIES,
10659
- minLength: 0,
10660
- }),
10661
- });
10662
- static create({ report, dependencies }) {
10663
- return new NotYetAccumulatedReport(report, dependencies);
10664
- }
10665
- constructor(
10666
- /**
10667
- * Each of these were made available at most one epoch ago
10668
- * but have or had unfulfilled dependencies.
10669
- */
10670
- report,
10671
- /**
10672
- * Alongside the work-report itself, we retain its un-accumulated
10673
- * dependencies, a set of work-package hashes.
10674
- *
10675
- * https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
10676
- */
10677
- dependencies) {
10678
- super();
10679
- this.report = report;
10680
- this.dependencies = dependencies;
10681
- }
10682
- }
10683
10768
 
10684
10769
  ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialize.ts
10685
10770
 
@@ -10693,26 +10778,19 @@ class NotYetAccumulatedReport extends WithDebug {
10693
10778
 
10694
10779
 
10695
10780
 
10696
-
10697
-
10698
-
10699
10781
  /** Serialization for particular state entries. */
10700
- var serialize;
10782
+ var serialize_serialize;
10701
10783
  (function (serialize) {
10702
10784
  /** C(1): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b15013b1501?v=0.6.7 */
10703
10785
  serialize.authPools = {
10704
10786
  key: stateKeys.index(StateKeyIdx.Alpha),
10705
- Codec: codecPerCore(codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
10706
- minLength: 0,
10707
- maxLength: MAX_AUTH_POOL_SIZE,
10708
- typicalLength: MAX_AUTH_POOL_SIZE,
10709
- })),
10787
+ Codec: authPoolsCodec,
10710
10788
  extract: (s) => s.authPools,
10711
10789
  };
10712
10790
  /** C(2): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b31013b3101?v=0.6.7 */
10713
10791
  serialize.authQueues = {
10714
10792
  key: stateKeys.index(StateKeyIdx.Phi),
10715
- Codec: codecPerCore(codecFixedSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE)),
10793
+ Codec: authQueuesCodec,
10716
10794
  extract: (s) => s.authQueues,
10717
10795
  };
10718
10796
  /**
@@ -10721,7 +10799,7 @@ var serialize;
10721
10799
  */
10722
10800
  serialize.recentBlocks = {
10723
10801
  key: stateKeys.index(StateKeyIdx.Beta),
10724
- Codec: RecentBlocksHistory.Codec,
10802
+ Codec: RecentBlocks.Codec,
10725
10803
  extract: (s) => s.recentBlocks,
10726
10804
  };
10727
10805
  /** C(4): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b63013b6301?v=0.6.7 */
@@ -10750,25 +10828,25 @@ var serialize;
10750
10828
  /** C(7): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b00023b0002?v=0.6.7 */
10751
10829
  serialize.designatedValidators = {
10752
10830
  key: stateKeys.index(StateKeyIdx.Iota),
10753
- Codec: codecPerValidator(ValidatorData.Codec),
10831
+ Codec: validatorsDataCodec,
10754
10832
  extract: (s) => s.designatedValidatorData,
10755
10833
  };
10756
10834
  /** C(8): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b0d023b0d02?v=0.6.7 */
10757
10835
  serialize.currentValidators = {
10758
10836
  key: stateKeys.index(StateKeyIdx.Kappa),
10759
- Codec: codecPerValidator(ValidatorData.Codec),
10837
+ Codec: validatorsDataCodec,
10760
10838
  extract: (s) => s.currentValidatorData,
10761
10839
  };
10762
10840
  /** C(9): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b1a023b1a02?v=0.6.7 */
10763
10841
  serialize.previousValidators = {
10764
10842
  key: stateKeys.index(StateKeyIdx.Lambda),
10765
- Codec: codecPerValidator(ValidatorData.Codec),
10843
+ Codec: validatorsDataCodec,
10766
10844
  extract: (s) => s.previousValidatorData,
10767
10845
  };
10768
10846
  /** C(10): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b27023b2702?v=0.6.7 */
10769
10847
  serialize.availabilityAssignment = {
10770
10848
  key: stateKeys.index(StateKeyIdx.Rho),
10771
- Codec: codecPerCore(descriptors_codec.optional(AvailabilityAssignment.Codec)),
10849
+ Codec: availabilityAssignmentsCodec,
10772
10850
  extract: (s) => s.availabilityAssignment,
10773
10851
  };
10774
10852
  /** C(11): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b3e023b3e02?v=0.6.7 */
@@ -10792,13 +10870,13 @@ var serialize;
10792
10870
  /** C(14): https://graypaper.fluffylabs.dev/#/1c979cb/3bf0023bf002?v=0.7.1 */
10793
10871
  serialize.accumulationQueue = {
10794
10872
  key: stateKeys.index(StateKeyIdx.Omega),
10795
- Codec: codecPerEpochBlock(readonlyArray(descriptors_codec.sequenceVarLen(NotYetAccumulatedReport.Codec))),
10873
+ Codec: accumulationQueueCodec,
10796
10874
  extract: (s) => s.accumulationQueue,
10797
10875
  };
10798
10876
  /** C(15): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b96023b9602?v=0.6.7 */
10799
10877
  serialize.recentlyAccumulated = {
10800
10878
  key: stateKeys.index(StateKeyIdx.Xi),
10801
- Codec: codecPerEpochBlock(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque()).convert((x) => Array.from(x), (x) => HashSet.from(x))),
10879
+ Codec: recentlyAccumulatedCodec,
10802
10880
  extract: (s) => s.recentlyAccumulated,
10803
10881
  };
10804
10882
  /** C(16): https://graypaper.fluffylabs.dev/#/38c4e62/3b46033b4603?v=0.7.0 */
@@ -10827,9 +10905,9 @@ var serialize;
10827
10905
  /** https://graypaper.fluffylabs.dev/#/85129da/387603387603?v=0.6.3 */
10828
10906
  serialize.serviceLookupHistory = (blake2b, serviceId, hash, len) => ({
10829
10907
  key: stateKeys.serviceLookupHistory(blake2b, serviceId, hash, len),
10830
- Codec: readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32)),
10908
+ Codec: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32)),
10831
10909
  });
10832
- })(serialize || (serialize = {}));
10910
+ })(serialize_serialize || (serialize_serialize = {}));
10833
10911
  /**
10834
10912
  * Just dump the entire terminal blob as-is.
10835
10913
  *
@@ -10839,6 +10917,87 @@ var serialize;
10839
10917
  */
10840
10918
  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()));
10841
10919
 
10920
+ ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state-view.ts
10921
+
10922
+
10923
+ class SerializedStateView {
10924
+ spec;
10925
+ backend;
10926
+ recentlyUsedServices;
10927
+ viewCache;
10928
+ constructor(spec, backend,
10929
+ /** Best-effort list of recently active services. */
10930
+ recentlyUsedServices, viewCache) {
10931
+ this.spec = spec;
10932
+ this.backend = backend;
10933
+ this.recentlyUsedServices = recentlyUsedServices;
10934
+ this.viewCache = viewCache;
10935
+ }
10936
+ retrieveView({ key, Codec }, description) {
10937
+ const cached = this.viewCache.get(key);
10938
+ if (cached !== undefined) {
10939
+ return cached;
10940
+ }
10941
+ const bytes = this.backend.get(key);
10942
+ if (bytes === null) {
10943
+ throw new Error(`Required state entry for ${description} is missing!. Accessing view of key: ${key}`);
10944
+ }
10945
+ // NOTE [ToDr] we are not using `Decoder.decodeObject` here because
10946
+ // it needs to get to the end of the data (skip), yet that's expensive.
10947
+ // we assume that the state data is correct and coherent anyway, so
10948
+ // for performance reasons we simply create the view here.
10949
+ const d = decoder_Decoder.fromBytesBlob(bytes);
10950
+ d.attachContext(this.spec);
10951
+ const view = Codec.View.decode(d);
10952
+ this.viewCache.set(key, view);
10953
+ return view;
10954
+ }
10955
+ availabilityAssignmentView() {
10956
+ return this.retrieveView(serialize_serialize.availabilityAssignment, "availabilityAssignmentView");
10957
+ }
10958
+ designatedValidatorDataView() {
10959
+ return this.retrieveView(serialize_serialize.designatedValidators, "designatedValidatorsView");
10960
+ }
10961
+ currentValidatorDataView() {
10962
+ return this.retrieveView(serialize_serialize.currentValidators, "currentValidatorsView");
10963
+ }
10964
+ previousValidatorDataView() {
10965
+ return this.retrieveView(serialize_serialize.previousValidators, "previousValidatorsView");
10966
+ }
10967
+ authPoolsView() {
10968
+ return this.retrieveView(serialize_serialize.authPools, "authPoolsView");
10969
+ }
10970
+ authQueuesView() {
10971
+ return this.retrieveView(serialize_serialize.authQueues, "authQueuesView");
10972
+ }
10973
+ recentBlocksView() {
10974
+ return this.retrieveView(serialize_serialize.recentBlocks, "recentBlocksView");
10975
+ }
10976
+ statisticsView() {
10977
+ return this.retrieveView(serialize_serialize.statistics, "statisticsView");
10978
+ }
10979
+ accumulationQueueView() {
10980
+ return this.retrieveView(serialize_serialize.accumulationQueue, "accumulationQueueView");
10981
+ }
10982
+ recentlyAccumulatedView() {
10983
+ return this.retrieveView(serialize_serialize.recentlyAccumulated, "recentlyAccumulatedView");
10984
+ }
10985
+ safroleDataView() {
10986
+ return this.retrieveView(serialize_serialize.safrole, "safroleDataView");
10987
+ }
10988
+ getServiceInfoView(id) {
10989
+ const serviceData = serialize_serialize.serviceData(id);
10990
+ const bytes = this.backend.get(serviceData.key);
10991
+ if (bytes === null) {
10992
+ return null;
10993
+ }
10994
+ if (!this.recentlyUsedServices.includes(id)) {
10995
+ this.recentlyUsedServices.push(id);
10996
+ }
10997
+ return decoder_Decoder.decodeObject(serviceData.Codec.View, bytes, this.spec);
10998
+ }
10999
+ }
11000
+
10842
11001
  ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
10843
11002
 
10844
11003
 
@@ -10847,6 +11006,8 @@ const dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }, (e, v) =
10847
11006
 
10848
11007
 
10849
11008
 
11009
+
11010
+
10850
11011
  /**
10851
11012
  * State object which reads it's entries from some backend.
10852
11013
  *
@@ -10859,7 +11020,7 @@ class serialized_state_SerializedState {
10859
11020
  spec;
10860
11021
  blake2b;
10861
11022
  backend;
10862
- _recentServiceIds;
11023
+ recentlyUsedServices;
10863
11024
  /** Create a state-like object from collection of serialized entries. */
10864
11025
  static fromStateEntries(spec, blake2b, state, recentServices = []) {
10865
11026
  return new serialized_state_SerializedState(spec, blake2b, state, recentServices);
@@ -10868,106 +11029,120 @@ class serialized_state_SerializedState {
10868
11029
  static new(spec, blake2b, db, recentServices = []) {
10869
11030
  return new serialized_state_SerializedState(spec, blake2b, db, recentServices);
10870
11031
  }
11032
+ dataCache = hash_dictionary_HashDictionary.new();
11033
+ viewCache = hash_dictionary_HashDictionary.new();
10871
11034
  constructor(spec, blake2b, backend,
10872
11035
  /** Best-effort list of recently active services. */
10873
- _recentServiceIds) {
11036
+ recentlyUsedServices) {
10874
11037
  this.spec = spec;
10875
11038
  this.blake2b = blake2b;
10876
11039
  this.backend = backend;
10877
- this._recentServiceIds = _recentServiceIds;
11040
+ this.recentlyUsedServices = recentlyUsedServices;
10878
11041
  }
10879
11042
  /** Comparing the serialized states, just means comparing their backends. */
10880
11043
  [TEST_COMPARE_USING]() {
10881
11044
  return this.backend;
10882
11045
  }
11046
+ /** Return a non-decoding version of the state. */
11047
+ view() {
11048
+ return new SerializedStateView(this.spec, this.backend, this.recentlyUsedServices, this.viewCache);
11049
+ }
10883
11050
  // TODO [ToDr] Temporary method to update the state,
10884
11051
  // without changing references.
10885
11052
  updateBackend(newBackend) {
10886
11053
  this.backend = newBackend;
11054
+ this.dataCache = hash_dictionary_HashDictionary.new();
11055
+ this.viewCache = hash_dictionary_HashDictionary.new();
10887
11056
  }
10888
11057
  recentServiceIds() {
10889
- return this._recentServiceIds;
11058
+ return this.recentlyUsedServices;
10890
11059
  }
10891
11060
  getService(id) {
10892
- const serviceData = this.retrieveOptional(serialize.serviceData(id));
11061
+ const serviceData = this.retrieveOptional(serialize_serialize.serviceData(id));
10893
11062
  if (serviceData === undefined) {
10894
11063
  return null;
10895
11064
  }
10896
- if (!this._recentServiceIds.includes(id)) {
10897
- this._recentServiceIds.push(id);
11065
+ if (!this.recentlyUsedServices.includes(id)) {
11066
+ this.recentlyUsedServices.push(id);
10898
11067
  }
10899
11068
  return new SerializedService(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
10900
11069
  }
10901
- retrieve({ key, Codec }, description) {
10902
- const bytes = this.backend.get(key);
10903
- if (bytes === null) {
10904
- throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${key}`);
11070
+ retrieve(k, description) {
11071
+ const data = this.retrieveOptional(k);
11072
+ if (data === undefined) {
11073
+ throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${k.key}`);
10905
11074
  }
10906
- return decoder_Decoder.decodeObject(Codec, bytes, this.spec);
11075
+ return data;
10907
11076
  }
10908
11077
  retrieveOptional({ key, Codec }) {
11078
+ const cached = this.dataCache.get(key);
11079
+ if (cached !== undefined) {
11080
+ return cached;
11081
+ }
10909
11082
  const bytes = this.backend.get(key);
10910
11083
  if (bytes === null) {
10911
11084
  return undefined;
10912
11085
  }
10913
- return decoder_Decoder.decodeObject(Codec, bytes, this.spec);
11086
+ const data = decoder_Decoder.decodeObject(Codec, bytes, this.spec);
11087
+ this.dataCache.set(key, data);
11088
+ return data;
10914
11089
  }
10915
11090
  get availabilityAssignment() {
10916
- return this.retrieve(serialize.availabilityAssignment, "availabilityAssignment");
11091
+ return this.retrieve(serialize_serialize.availabilityAssignment, "availabilityAssignment");
10917
11092
  }
10918
11093
  get designatedValidatorData() {
10919
- return this.retrieve(serialize.designatedValidators, "designatedValidatorData");
11094
+ return this.retrieve(serialize_serialize.designatedValidators, "designatedValidatorData");
10920
11095
  }
10921
11096
  get nextValidatorData() {
10922
- return this.retrieve(serialize.safrole, "safroleData.nextValidatorData").nextValidatorData;
11097
+ return this.retrieve(serialize_serialize.safrole, "safroleData.nextValidatorData").nextValidatorData;
10923
11098
  }
10924
11099
  get currentValidatorData() {
10925
- return this.retrieve(serialize.currentValidators, "currentValidators");
11100
+ return this.retrieve(serialize_serialize.currentValidators, "currentValidators");
10926
11101
  }
10927
11102
  get previousValidatorData() {
10928
- return this.retrieve(serialize.previousValidators, "previousValidators");
11103
+ return this.retrieve(serialize_serialize.previousValidators, "previousValidators");
10929
11104
  }
10930
11105
  get disputesRecords() {
10931
- return this.retrieve(serialize.disputesRecords, "disputesRecords");
11106
+ return this.retrieve(serialize_serialize.disputesRecords, "disputesRecords");
10932
11107
  }
10933
11108
  get timeslot() {
10934
- return this.retrieve(serialize.timeslot, "timeslot");
11109
+ return this.retrieve(serialize_serialize.timeslot, "timeslot");
10935
11110
  }
10936
11111
  get entropy() {
10937
- return this.retrieve(serialize.entropy, "entropy");
11112
+ return this.retrieve(serialize_serialize.entropy, "entropy");
10938
11113
  }
10939
11114
  get authPools() {
10940
- return this.retrieve(serialize.authPools, "authPools");
11115
+ return this.retrieve(serialize_serialize.authPools, "authPools");
10941
11116
  }
10942
11117
  get authQueues() {
10943
- return this.retrieve(serialize.authQueues, "authQueues");
11118
+ return this.retrieve(serialize_serialize.authQueues, "authQueues");
10944
11119
  }
10945
11120
  get recentBlocks() {
10946
- return this.retrieve(serialize.recentBlocks, "recentBlocks");
11121
+ return this.retrieve(serialize_serialize.recentBlocks, "recentBlocks");
10947
11122
  }
10948
11123
  get statistics() {
10949
- return this.retrieve(serialize.statistics, "statistics");
11124
+ return this.retrieve(serialize_serialize.statistics, "statistics");
10950
11125
  }
10951
11126
  get accumulationQueue() {
10952
- return this.retrieve(serialize.accumulationQueue, "accumulationQueue");
11127
+ return this.retrieve(serialize_serialize.accumulationQueue, "accumulationQueue");
10953
11128
  }
10954
11129
  get recentlyAccumulated() {
10955
- return this.retrieve(serialize.recentlyAccumulated, "recentlyAccumulated");
11130
+ return this.retrieve(serialize_serialize.recentlyAccumulated, "recentlyAccumulated");
10956
11131
  }
10957
11132
  get ticketsAccumulator() {
10958
- return this.retrieve(serialize.safrole, "safroleData.ticketsAccumulator").ticketsAccumulator;
11133
+ return this.retrieve(serialize_serialize.safrole, "safroleData.ticketsAccumulator").ticketsAccumulator;
10959
11134
  }
10960
11135
  get sealingKeySeries() {
10961
- return this.retrieve(serialize.safrole, "safrole.sealingKeySeries").sealingKeySeries;
11136
+ return this.retrieve(serialize_serialize.safrole, "safrole.sealingKeySeries").sealingKeySeries;
10962
11137
  }
10963
11138
  get epochRoot() {
10964
- return this.retrieve(serialize.safrole, "safrole.epochRoot").epochRoot;
11139
+ return this.retrieve(serialize_serialize.safrole, "safrole.epochRoot").epochRoot;
10965
11140
  }
10966
11141
  get privilegedServices() {
10967
- return this.retrieve(serialize.privilegedServices, "privilegedServices");
11142
+ return this.retrieve(serialize_serialize.privilegedServices, "privilegedServices");
10968
11143
  }
10969
11144
  get accumulationOutputLog() {
10970
- return this.retrieve(serialize.accumulationOutputLog, "accumulationOutputLog");
11145
+ return this.retrieve(serialize_serialize.accumulationOutputLog, "accumulationOutputLog");
10971
11146
  }
10972
11147
  }
10973
11148
  /** Service data representation on a serialized state. */
@@ -10996,9 +11171,9 @@ class SerializedService {
10996
11171
  serviceIdAndKey.set(numbers_u32AsLeBytes(this.serviceId));
10997
11172
  serviceIdAndKey.set(rawKey.raw, SERVICE_ID_BYTES);
10998
11173
  const key = opaque_asOpaqueType(bytes_BytesBlob.blobFrom(this.blake2b.hashBytes(serviceIdAndKey).raw));
10999
- return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, key)) ?? null;
11174
+ return this.retrieveOptional(serialize_serialize.serviceStorage(this.blake2b, this.serviceId, key)) ?? null;
11000
11175
  }
11001
- return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, rawKey)) ?? null;
11176
+ return this.retrieveOptional(serialize_serialize.serviceStorage(this.blake2b, this.serviceId, rawKey)) ?? null;
11002
11177
  }
11003
11178
  /**
11004
11179
  * Check if preimage is present in the DB.
@@ -11007,15 +11182,15 @@ class SerializedService {
11007
11182
  */
11008
11183
  hasPreimage(hash) {
11009
11184
  // TODO [ToDr] consider optimizing to avoid fetching the whole data.
11010
- return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) !== undefined;
11185
+ return this.retrieveOptional(serialize_serialize.servicePreimages(this.blake2b, this.serviceId, hash)) !== undefined;
11011
11186
  }
11012
11187
  /** Retrieve preimage from the DB. */
11013
11188
  getPreimage(hash) {
11014
- return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) ?? null;
11189
+ return this.retrieveOptional(serialize_serialize.servicePreimages(this.blake2b, this.serviceId, hash)) ?? null;
11015
11190
  }
11016
11191
  /** Retrieve preimage lookup history. */
11017
11192
  getLookupHistory(hash, len) {
11018
- const rawSlots = this.retrieveOptional(serialize.serviceLookupHistory(this.blake2b, this.serviceId, hash, len));
11193
+ const rawSlots = this.retrieveOptional(serialize_serialize.serviceLookupHistory(this.blake2b, this.serviceId, hash, len));
11019
11194
  if (rawSlots === undefined) {
11020
11195
  return null;
11021
11196
  }
@@ -11704,7 +11879,7 @@ function* serializeStateUpdate(spec, blake2b, update) {
11704
11879
  function* serializeRemovedServices(servicesRemoved) {
11705
11880
  for (const serviceId of servicesRemoved ?? []) {
11706
11881
  // TODO [ToDr] what about all data associated with a service?
11707
- const codec = serialize.serviceData(serviceId);
11882
+ const codec = serialize_serialize.serviceData(serviceId);
11708
11883
  yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
11709
11884
  }
11710
11885
  }
@@ -11713,13 +11888,13 @@ function* serializeStorage(storage, blake2b) {
11713
11888
  switch (action.kind) {
11714
11889
  case UpdateStorageKind.Set: {
11715
11890
  const key = action.storage.key;
11716
- const codec = serialize.serviceStorage(blake2b, serviceId, key);
11891
+ const codec = serialize_serialize.serviceStorage(blake2b, serviceId, key);
11717
11892
  yield [StateEntryUpdateAction.Insert, codec.key, action.storage.value];
11718
11893
  break;
11719
11894
  }
11720
11895
  case UpdateStorageKind.Remove: {
11721
11896
  const key = action.key;
11722
- const codec = serialize.serviceStorage(blake2b, serviceId, key);
11897
+ const codec = serialize_serialize.serviceStorage(blake2b, serviceId, key);
11723
11898
  yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
11724
11899
  break;
11725
11900
  }
@@ -11733,10 +11908,10 @@ function* serializePreimages(preimages, encode, blake2b) {
11733
11908
  switch (action.kind) {
11734
11909
  case UpdatePreimageKind.Provide: {
11735
11910
  const { hash, blob } = action.preimage;
11736
- const codec = serialize.servicePreimages(blake2b, serviceId, hash);
11911
+ const codec = serialize_serialize.servicePreimages(blake2b, serviceId, hash);
11737
11912
  yield [StateEntryUpdateAction.Insert, codec.key, blob];
11738
11913
  if (action.slot !== null) {
11739
- const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, numbers_tryAsU32(blob.length));
11914
+ const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, numbers_tryAsU32(blob.length));
11740
11915
  yield [
11741
11916
  StateEntryUpdateAction.Insert,
11742
11917
  codec2.key,
@@ -11747,15 +11922,15 @@ function* serializePreimages(preimages, encode, blake2b) {
11747
11922
  }
11748
11923
  case UpdatePreimageKind.UpdateOrAdd: {
11749
11924
  const { hash, length, slots } = action.item;
11750
- const codec = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
11925
+ const codec = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
11751
11926
  yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, slots)];
11752
11927
  break;
11753
11928
  }
11754
11929
  case UpdatePreimageKind.Remove: {
11755
11930
  const { hash, length } = action;
11756
- const codec = serialize.servicePreimages(blake2b, serviceId, hash);
11931
+ const codec = serialize_serialize.servicePreimages(blake2b, serviceId, hash);
11757
11932
  yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
11758
- const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
11933
+ const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
11759
11934
  yield [StateEntryUpdateAction.Remove, codec2.key, EMPTY_BLOB];
11760
11935
  break;
11761
11936
  }
@@ -11767,12 +11942,12 @@ function* serializePreimages(preimages, encode, blake2b) {
11767
11942
  function* serializeServiceUpdates(servicesUpdates, encode, blake2b) {
11768
11943
  for (const { action, serviceId } of servicesUpdates ?? []) {
11769
11944
  // new service being created or updated
11770
- const codec = serialize.serviceData(serviceId);
11945
+ const codec = serialize_serialize.serviceData(serviceId);
11771
11946
  yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, action.account)];
11772
11947
  // additional lookup history update
11773
11948
  if (action.kind === UpdateServiceKind.Create && action.lookupHistory !== null) {
11774
11949
  const { lookupHistory } = action;
11775
- const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
11950
+ const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
11776
11951
  yield [StateEntryUpdateAction.Insert, codec2.key, encode(codec2.Codec, lookupHistory.slots)];
11777
11952
  }
11778
11953
  }
@@ -11782,53 +11957,53 @@ function* serializeBasicKeys(spec, update) {
11782
11957
  return [StateEntryUpdateAction.Insert, codec.key, encoder_Encoder.encodeObject(codec.Codec, val, spec)];
11783
11958
  }
11784
11959
  if (update.authPools !== undefined) {
11785
- yield doSerialize(update.authPools, serialize.authPools); // C(1)
11960
+ yield doSerialize(update.authPools, serialize_serialize.authPools); // C(1)
11786
11961
  }
11787
11962
  if (update.authQueues !== undefined) {
11788
- yield doSerialize(update.authQueues, serialize.authQueues); // C(2)
11963
+ yield doSerialize(update.authQueues, serialize_serialize.authQueues); // C(2)
11789
11964
  }
11790
11965
  if (update.recentBlocks !== undefined) {
11791
- yield doSerialize(update.recentBlocks, serialize.recentBlocks); // C(3)
11966
+ yield doSerialize(update.recentBlocks, serialize_serialize.recentBlocks); // C(3)
11792
11967
  }
11793
11968
  const safroleData = getSafroleData(update.nextValidatorData, update.epochRoot, update.sealingKeySeries, update.ticketsAccumulator);
11794
11969
  if (safroleData !== undefined) {
11795
- yield doSerialize(safroleData, serialize.safrole); // C(4)
11970
+ yield doSerialize(safroleData, serialize_serialize.safrole); // C(4)
11796
11971
  }
11797
11972
  if (update.disputesRecords !== undefined) {
11798
- yield doSerialize(update.disputesRecords, serialize.disputesRecords); // C(5)
11973
+ yield doSerialize(update.disputesRecords, serialize_serialize.disputesRecords); // C(5)
11799
11974
  }
11800
11975
  if (update.entropy !== undefined) {
11801
- yield doSerialize(update.entropy, serialize.entropy); // C(6)
11976
+ yield doSerialize(update.entropy, serialize_serialize.entropy); // C(6)
11802
11977
  }
11803
11978
  if (update.designatedValidatorData !== undefined) {
11804
- yield doSerialize(update.designatedValidatorData, serialize.designatedValidators); // C(7)
11979
+ yield doSerialize(update.designatedValidatorData, serialize_serialize.designatedValidators); // C(7)
11805
11980
  }
11806
11981
  if (update.currentValidatorData !== undefined) {
11807
- yield doSerialize(update.currentValidatorData, serialize.currentValidators); // C(8)
11982
+ yield doSerialize(update.currentValidatorData, serialize_serialize.currentValidators); // C(8)
11808
11983
  }
11809
11984
  if (update.previousValidatorData !== undefined) {
11810
- yield doSerialize(update.previousValidatorData, serialize.previousValidators); // C(9)
11985
+ yield doSerialize(update.previousValidatorData, serialize_serialize.previousValidators); // C(9)
11811
11986
  }
11812
11987
  if (update.availabilityAssignment !== undefined) {
11813
- yield doSerialize(update.availabilityAssignment, serialize.availabilityAssignment); // C(10)
11988
+ yield doSerialize(update.availabilityAssignment, serialize_serialize.availabilityAssignment); // C(10)
11814
11989
  }
11815
11990
  if (update.timeslot !== undefined) {
11816
- yield doSerialize(update.timeslot, serialize.timeslot); // C(11)
11991
+ yield doSerialize(update.timeslot, serialize_serialize.timeslot); // C(11)
11817
11992
  }
11818
11993
  if (update.privilegedServices !== undefined) {
11819
- yield doSerialize(update.privilegedServices, serialize.privilegedServices); // C(12)
11994
+ yield doSerialize(update.privilegedServices, serialize_serialize.privilegedServices); // C(12)
11820
11995
  }
11821
11996
  if (update.statistics !== undefined) {
11822
- yield doSerialize(update.statistics, serialize.statistics); // C(13)
11997
+ yield doSerialize(update.statistics, serialize_serialize.statistics); // C(13)
11823
11998
  }
11824
11999
  if (update.accumulationQueue !== undefined) {
11825
- yield doSerialize(update.accumulationQueue, serialize.accumulationQueue); // C(14)
12000
+ yield doSerialize(update.accumulationQueue, serialize_serialize.accumulationQueue); // C(14)
11826
12001
  }
11827
12002
  if (update.recentlyAccumulated !== undefined) {
11828
- yield doSerialize(update.recentlyAccumulated, serialize.recentlyAccumulated); // C(15)
12003
+ yield doSerialize(update.recentlyAccumulated, serialize_serialize.recentlyAccumulated); // C(15)
11829
12004
  }
11830
12005
  if (update.accumulationOutputLog !== undefined) {
11831
- yield doSerialize(update.accumulationOutputLog, serialize.accumulationOutputLog); // C(16)
12006
+ yield doSerialize(update.accumulationOutputLog, serialize_serialize.accumulationOutputLog); // C(16)
11832
12007
  }
11833
12008
  }
11834
12009
  function getSafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator) {
@@ -11941,41 +12116,41 @@ function convertInMemoryStateToDictionary(spec, blake2b, state) {
11941
12116
  function doSerialize(codec) {
11942
12117
  serialized.set(codec.key, encoder_Encoder.encodeObject(codec.Codec, codec.extract(state), spec));
11943
12118
  }
11944
- doSerialize(serialize.authPools); // C(1)
11945
- doSerialize(serialize.authQueues); // C(2)
11946
- doSerialize(serialize.recentBlocks); // C(3)
11947
- doSerialize(serialize.safrole); // C(4)
11948
- doSerialize(serialize.disputesRecords); // C(5)
11949
- doSerialize(serialize.entropy); // C(6)
11950
- doSerialize(serialize.designatedValidators); // C(7)
11951
- doSerialize(serialize.currentValidators); // C(8)
11952
- doSerialize(serialize.previousValidators); // C(9)
11953
- doSerialize(serialize.availabilityAssignment); // C(10)
11954
- doSerialize(serialize.timeslot); // C(11)
11955
- doSerialize(serialize.privilegedServices); // C(12)
11956
- doSerialize(serialize.statistics); // C(13)
11957
- doSerialize(serialize.accumulationQueue); // C(14)
11958
- doSerialize(serialize.recentlyAccumulated); // C(15)
11959
- doSerialize(serialize.accumulationOutputLog); // C(16)
12119
+ doSerialize(serialize_serialize.authPools); // C(1)
12120
+ doSerialize(serialize_serialize.authQueues); // C(2)
12121
+ doSerialize(serialize_serialize.recentBlocks); // C(3)
12122
+ doSerialize(serialize_serialize.safrole); // C(4)
12123
+ doSerialize(serialize_serialize.disputesRecords); // C(5)
12124
+ doSerialize(serialize_serialize.entropy); // C(6)
12125
+ doSerialize(serialize_serialize.designatedValidators); // C(7)
12126
+ doSerialize(serialize_serialize.currentValidators); // C(8)
12127
+ doSerialize(serialize_serialize.previousValidators); // C(9)
12128
+ doSerialize(serialize_serialize.availabilityAssignment); // C(10)
12129
+ doSerialize(serialize_serialize.timeslot); // C(11)
12130
+ doSerialize(serialize_serialize.privilegedServices); // C(12)
12131
+ doSerialize(serialize_serialize.statistics); // C(13)
12132
+ doSerialize(serialize_serialize.accumulationQueue); // C(14)
12133
+ doSerialize(serialize_serialize.recentlyAccumulated); // C(15)
12134
+ doSerialize(serialize_serialize.accumulationOutputLog); // C(16)
11960
12135
  // services
11961
12136
  for (const [serviceId, service] of state.services.entries()) {
11962
12137
  // data
11963
- const { key, Codec } = serialize.serviceData(serviceId);
12138
+ const { key, Codec } = serialize_serialize.serviceData(serviceId);
11964
12139
  serialized.set(key, encoder_Encoder.encodeObject(Codec, service.getInfo()));
11965
12140
  // preimages
11966
12141
  for (const preimage of service.data.preimages.values()) {
11967
- const { key, Codec } = serialize.servicePreimages(blake2b, serviceId, preimage.hash);
12142
+ const { key, Codec } = serialize_serialize.servicePreimages(blake2b, serviceId, preimage.hash);
11968
12143
  serialized.set(key, encoder_Encoder.encodeObject(Codec, preimage.blob));
11969
12144
  }
11970
12145
  // storage
11971
12146
  for (const storage of service.data.storage.values()) {
11972
- const { key, Codec } = serialize.serviceStorage(blake2b, serviceId, storage.key);
12147
+ const { key, Codec } = serialize_serialize.serviceStorage(blake2b, serviceId, storage.key);
11973
12148
  serialized.set(key, encoder_Encoder.encodeObject(Codec, storage.value));
11974
12149
  }
11975
12150
  // lookup history
11976
12151
  for (const lookupHistoryList of service.data.lookupHistory.values()) {
11977
12152
  for (const lookupHistory of lookupHistoryList) {
11978
- const { key, Codec } = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
12153
+ const { key, Codec } = serialize_serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
11979
12154
  serialized.set(key, encoder_Encoder.encodeObject(Codec, lookupHistory.slots.slice()));
11980
12155
  }
11981
12156
  }
@@ -12025,6 +12200,7 @@ function loadState(spec, blake2b, entries) {
12025
12200
 
12026
12201
 
12027
12202
 
12203
+
12028
12204
  ;// CONCATENATED MODULE: ./packages/jam/database/leaf-db.ts
12029
12205
 
12030
12206
 
@@ -12183,7 +12359,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
12183
12359
  const lookupHistoryItemCodec = descriptors_codec.object({
12184
12360
  hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
12185
12361
  length: descriptors_codec.u32,
12186
- slots: readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32.asOpaque())).convert(seeThrough, tryAsLookupHistorySlots),
12362
+ slots: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32.asOpaque())).convert(seeThrough, tryAsLookupHistorySlots),
12187
12363
  }, "LookupHistoryItem", ({ hash, length, slots }) => new service_LookupHistoryItem(hash, length, slots));
12188
12364
  const lookupHistoryEntryCodec = descriptors_codec.object({
12189
12365
  key: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
@@ -12226,7 +12402,11 @@ class ServiceWithCodec extends InMemoryService {
12226
12402
  return new ServiceWithCodec(serviceId, data);
12227
12403
  }
12228
12404
  }
12229
- const in_memory_state_codec_inMemoryStateCodec = descriptors_codec.Class(InMemoryState, {
12405
+ const in_memory_state_codec_inMemoryStateCodec = (spec) => codec.Class(class State extends InMemoryState {
12406
+ static create(data) {
12407
+ return InMemoryState.new(spec, data);
12408
+ }
12409
+ }, {
12230
12410
  // alpha
12231
12411
  authPools: serialize.authPools.Codec,
12232
12412
  // phi
@@ -12236,11 +12416,11 @@ const in_memory_state_codec_inMemoryStateCodec = descriptors_codec.Class(InMemor
12236
12416
  // gamma_k
12237
12417
  nextValidatorData: codecPerValidator(ValidatorData.Codec),
12238
12418
  // gamma_z
12239
- epochRoot: descriptors_codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
12419
+ epochRoot: codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
12240
12420
  // gamma_s
12241
12421
  sealingKeySeries: SafroleSealingKeysData.Codec,
12242
12422
  // gamma_a
12243
- ticketsAccumulator: readonlyArray(descriptors_codec.sequenceVarLen(Ticket.Codec)).convert((x) => x, sized_array_asKnownSize),
12423
+ ticketsAccumulator: readonlyArray(codec.sequenceVarLen(Ticket.Codec)).convert((x) => x, asKnownSize),
12244
12424
  // psi
12245
12425
  disputesRecords: serialize.disputesRecords.Codec,
12246
12426
  // eta
@@ -12266,7 +12446,7 @@ const in_memory_state_codec_inMemoryStateCodec = descriptors_codec.Class(InMemor
12266
12446
  // theta
12267
12447
  accumulationOutputLog: serialize.accumulationOutputLog.Codec,
12268
12448
  // delta
12269
- services: descriptors_codec.dictionary(descriptors_codec.u32.asOpaque(), ServiceWithCodec.Codec, {
12449
+ services: codec.dictionary(codec.u32.asOpaque(), ServiceWithCodec.Codec, {
12270
12450
  sortKeys: (a, b) => a - b,
12271
12451
  }),
12272
12452
  });
@@ -12313,7 +12493,7 @@ class InMemoryStates {
12313
12493
  }
12314
12494
  /** Insert a full state into the database. */
12315
12495
  async insertState(headerHash, state) {
12316
- const encoded = Encoder.encodeObject(inMemoryStateCodec, state, this.spec);
12496
+ const encoded = Encoder.encodeObject(inMemoryStateCodec(this.spec), state, this.spec);
12317
12497
  this.db.set(headerHash, encoded);
12318
12498
  return Result.ok(OK);
12319
12499
  }
@@ -12322,7 +12502,7 @@ class InMemoryStates {
12322
12502
  if (encodedState === undefined) {
12323
12503
  return null;
12324
12504
  }
12325
- return Decoder.decodeObject(inMemoryStateCodec, encodedState, this.spec);
12505
+ return Decoder.decodeObject(inMemoryStateCodec(this.spec), encodedState, this.spec);
12326
12506
  }
12327
12507
  }
12328
12508
 
@@ -13509,21 +13689,21 @@ class TransitionHasher {
13509
13689
  */
13510
13690
  extrinsic(extrinsicView) {
13511
13691
  // https://graypaper.fluffylabs.dev/#/cc517d7/0cfb000cfb00?v=0.6.5
13512
- const guarantees = extrinsicView.guarantees
13692
+ const guaranteesCount = numbers_tryAsU32(extrinsicView.guarantees.view().length);
13693
+ const countEncoded = encoder_Encoder.encodeObject(descriptors_codec.varU32, guaranteesCount);
13694
+ const guaranteesBlobs = extrinsicView.guarantees
13513
13695
  .view()
13514
13696
  .map((g) => g.view())
13515
- .map((guarantee) => {
13697
+ .reduce((aggregated, guarantee) => {
13516
13698
  const reportHash = this.blake2b.hashBytes(guarantee.report.encoded()).asOpaque();
13517
- return bytes_BytesBlob.blobFromParts([
13518
- reportHash.raw,
13519
- guarantee.slot.encoded().raw,
13520
- guarantee.credentials.encoded().raw,
13521
- ]);
13522
- });
13523
- const guaranteeBlob = encoder_Encoder.encodeObject(descriptors_codec.sequenceVarLen(dumpCodec), guarantees, this.context);
13699
+ aggregated.push(reportHash.raw);
13700
+ aggregated.push(guarantee.slot.encoded().raw);
13701
+ aggregated.push(guarantee.credentials.encoded().raw);
13702
+ return aggregated;
13703
+ }, [countEncoded.raw]);
13524
13704
  const et = this.blake2b.hashBytes(extrinsicView.tickets.encoded()).asOpaque();
13525
13705
  const ep = this.blake2b.hashBytes(extrinsicView.preimages.encoded()).asOpaque();
13526
- const eg = this.blake2b.hashBytes(guaranteeBlob).asOpaque();
13706
+ const eg = this.blake2b.hashBlobs(guaranteesBlobs).asOpaque();
13527
13707
  const ea = this.blake2b.hashBytes(extrinsicView.assurances.encoded()).asOpaque();
13528
13708
  const ed = this.blake2b.hashBytes(extrinsicView.disputes.encoded()).asOpaque();
13529
13709
  const encoded = bytes_BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);