@typeberry/jam 0.2.0-b6e3410 → 0.2.0-e767e74

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