@typeberry/convert 0.2.0-e767e74 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +837 -1023
  2. package/index.js.map +1 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -6319,9 +6319,6 @@ class ObjectView {
6319
6319
  toString() {
6320
6320
  return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
6321
6321
  }
6322
- [TEST_COMPARE_USING]() {
6323
- return this.materialize();
6324
- }
6325
6322
  }
6326
6323
  /**
6327
6324
  * A lazy-evaluated decoder of a sequence.
@@ -6616,15 +6613,7 @@ var descriptors_codec;
6616
6613
  /** Custom encoding / decoding logic. */
6617
6614
  codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
6618
6615
  /** Choose a descriptor depending on the encoding/decoding context. */
6619
- codec.select = ({ name, sizeHint, }, chooser) => {
6620
- const Self = chooser(null);
6621
- 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)
6622
- ? codec.select({
6623
- name: Self.View.name,
6624
- sizeHint: Self.View.sizeHint,
6625
- }, (ctx) => chooser(ctx).View)
6626
- : Self.View);
6627
- };
6616
+ 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);
6628
6617
  /**
6629
6618
  * A descriptor for a more complex POJO.
6630
6619
  *
@@ -10063,19 +10052,6 @@ function block_emptyBlock(slot = tryAsTimeSlot(0)) {
10063
10052
  });
10064
10053
  }
10065
10054
 
10066
- ;// CONCATENATED MODULE: ./packages/jam/block/utils.ts
10067
-
10068
- /**
10069
- * Take an input data and re-encode that data as view.
10070
- *
10071
- * NOTE: this function should NEVER be used in any production code,
10072
- * it's only a test helper.
10073
- */
10074
- function reencodeAsView(codec, object, chainSpec) {
10075
- const encoded = encoder_Encoder.encodeObject(codec, object, chainSpec);
10076
- return decoder_Decoder.decodeObject(codec.View, encoded, chainSpec);
10077
- }
10078
-
10079
10055
  ;// CONCATENATED MODULE: ./packages/jam/block/index.ts
10080
10056
 
10081
10057
 
@@ -10094,7 +10070,6 @@ function reencodeAsView(codec, object, chainSpec) {
10094
10070
 
10095
10071
 
10096
10072
 
10097
-
10098
10073
  ;// CONCATENATED MODULE: ./packages/core/json-parser/parse.ts
10099
10074
  const NO_KEY = Symbol("no key");
10100
10075
  /** Given already parsed JSON, parse & validate it further to match the expected `jsonDescription` type. */
@@ -11463,128 +11438,10 @@ function accumulation_output_accumulationOutputComparator(a, b) {
11463
11438
  return Ordering.Equal;
11464
11439
  }
11465
11440
 
11466
- ;// CONCATENATED MODULE: ./packages/jam/block/gp-constants.ts
11467
-
11468
- /**
11469
- * This file lists all of the constants defined in the GrayPaper appendix.
11470
- *
11471
- * NOTE: Avoid using the constants directly, prefer "named" constants defined
11472
- * in a semantical proximity to where they are used.
11473
- *
11474
- * NOTE: This file will most likely be removed in the future. The constants
11475
- * here are only temporarily for convenience. When we figure out better names
11476
- * and places for these this file will be eradicated.
11477
- *
11478
- * https://graypaper.fluffylabs.dev/#/579bd12/413000413000
11479
- */
11480
- /** `G_I`: The gas allocated to invoke a work-package’s Is-Authorized logic. */
11481
- const gp_constants_G_I = 50_000_000;
11482
- /** `I`: Maximum number of work items in a package. */
11483
- const I = (/* unused pure expression or super */ null && (MAX_NUMBER_OF_WORK_ITEMS));
11484
- /** `O`: Maximum number of items in the authorizations pool. */
11485
- const gp_constants_O = 8;
11486
- /** `Q`: The number of items in the authorizations queue. */
11487
- const gp_constants_Q = 80;
11488
- /** `S`: The maximum number of entries in the accumulation queue. */
11489
- const S = 1024;
11490
- /** `T`: The maximum number of extrinsics in a work-package. */
11491
- const gp_constants_T = 128;
11492
- /** `W_A`: The maximum size of is-authorized code in octets. */
11493
- const gp_constants_W_A = 64_000;
11494
- /** `W_B`: The maximum size of an encoded work-package with extrinsic data and imports. */
11495
- const gp_constants_W_B = 13_794_305;
11496
- /** `W_C`: The maximum size of service code in octets. */
11497
- const gp_constants_W_C = 4_000_000;
11498
- /** `W_M`: The maximum number of imports in a work-package. */
11499
- const gp_constants_W_M = 3_072;
11500
- /** `W_R`: The maximum total size of all output blobs in a work-report, in octets. */
11501
- const gp_constants_W_R = 49_152;
11502
- /** `W_T`: The size of a transfer memo in octets. */
11503
- const gp_constants_W_T = 128;
11504
- /** `W_M`: The maximum number of exports in a work-package. */
11505
- const gp_constants_W_X = 3_072;
11506
- // TODO [ToDr] Not sure where these should live yet :(
11507
- /**
11508
- * `S`: The minimum public service index.
11509
- * Services of indices below these may only be created by the Registrar.
11510
- *
11511
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
11512
- */
11513
- const gp_constants_MIN_PUBLIC_SERVICE_INDEX = (/* unused pure expression or super */ null && (2 ** 16));
11514
- /**
11515
- * `J`: The maximum sum of dependency items in a work-report.
11516
- *
11517
- * https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
11518
- */
11519
- const gp_constants_MAX_REPORT_DEPENDENCIES = 8;
11520
-
11521
- ;// CONCATENATED MODULE: ./packages/jam/state/accumulation-queue.ts
11522
-
11523
-
11524
-
11525
-
11526
-
11527
-
11528
-
11529
- /**
11530
- * Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
11531
- *
11532
- * https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
11533
- */
11534
- class accumulation_queue_NotYetAccumulatedReport extends WithDebug {
11535
- report;
11536
- dependencies;
11537
- static Codec = descriptors_codec.Class(accumulation_queue_NotYetAccumulatedReport, {
11538
- report: work_report_WorkReport.Codec,
11539
- dependencies: codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
11540
- typicalLength: gp_constants_MAX_REPORT_DEPENDENCIES / 2,
11541
- maxLength: gp_constants_MAX_REPORT_DEPENDENCIES,
11542
- minLength: 0,
11543
- }),
11544
- });
11545
- static create({ report, dependencies }) {
11546
- return new accumulation_queue_NotYetAccumulatedReport(report, dependencies);
11547
- }
11548
- constructor(
11549
- /**
11550
- * Each of these were made available at most one epoch ago
11551
- * but have or had unfulfilled dependencies.
11552
- */
11553
- report,
11554
- /**
11555
- * Alongside the work-report itself, we retain its un-accumulated
11556
- * dependencies, a set of work-package hashes.
11557
- *
11558
- * https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
11559
- */
11560
- dependencies) {
11561
- super();
11562
- this.report = report;
11563
- this.dependencies = dependencies;
11564
- }
11565
- }
11566
- const accumulationQueueCodec = codecPerEpochBlock(readonlyArray(descriptors_codec.sequenceVarLen(accumulation_queue_NotYetAccumulatedReport.Codec)));
11567
-
11568
- ;// CONCATENATED MODULE: ./packages/jam/state/common.ts
11569
-
11570
-
11571
- /** Check if given array has correct length before casting to the opaque type. */
11572
- function common_tryAsPerCore(array, spec) {
11573
- debug_check `
11574
- ${array.length === spec.coresCount}
11575
- Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
11576
- `;
11577
- return opaque_asOpaqueType(array);
11578
- }
11579
- const codecPerCore = (val) => codecWithContext((context) => {
11580
- return codecKnownSizeArray(val, { fixedLength: context.coresCount });
11581
- });
11582
-
11583
11441
  ;// CONCATENATED MODULE: ./packages/jam/state/assurances.ts
11584
11442
 
11585
11443
 
11586
11444
 
11587
-
11588
11445
  /**
11589
11446
  * Assignment of particular work report to a core.
11590
11447
  *
@@ -11613,24 +11470,21 @@ class assurances_AvailabilityAssignment extends WithDebug {
11613
11470
  this.timeout = timeout;
11614
11471
  }
11615
11472
  }
11616
- const availabilityAssignmentsCodec = codecPerCore(descriptors_codec.optional(assurances_AvailabilityAssignment.Codec));
11617
-
11618
- ;// CONCATENATED MODULE: ./packages/jam/state/auth.ts
11619
-
11620
-
11621
11473
 
11474
+ ;// CONCATENATED MODULE: ./packages/jam/state/common.ts
11622
11475
 
11623
11476
 
11624
- /** `O`: Maximal authorization pool size. */
11625
- const auth_MAX_AUTH_POOL_SIZE = gp_constants_O;
11626
- /** `Q`: Size of the authorization queue. */
11627
- const auth_AUTHORIZATION_QUEUE_SIZE = gp_constants_Q;
11628
- const authPoolsCodec = codecPerCore(codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
11629
- minLength: 0,
11630
- maxLength: auth_MAX_AUTH_POOL_SIZE,
11631
- typicalLength: auth_MAX_AUTH_POOL_SIZE,
11632
- }));
11633
- const authQueuesCodec = codecPerCore(codecFixedSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), auth_AUTHORIZATION_QUEUE_SIZE));
11477
+ /** Check if given array has correct length before casting to the opaque type. */
11478
+ function common_tryAsPerCore(array, spec) {
11479
+ debug_check `
11480
+ ${array.length === spec.coresCount}
11481
+ Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
11482
+ `;
11483
+ return opaque_asOpaqueType(array);
11484
+ }
11485
+ const codecPerCore = (val) => codecWithContext((context) => {
11486
+ return codecKnownSizeArray(val, { fixedLength: context.coresCount });
11487
+ });
11634
11488
 
11635
11489
  ;// CONCATENATED MODULE: ./packages/jam/state/disputes.ts
11636
11490
 
@@ -11698,6 +11552,65 @@ function disputes_hashComparator(a, b) {
11698
11552
  return a.compare(b);
11699
11553
  }
11700
11554
 
11555
+ ;// CONCATENATED MODULE: ./packages/jam/block/gp-constants.ts
11556
+
11557
+ /**
11558
+ * This file lists all of the constants defined in the GrayPaper appendix.
11559
+ *
11560
+ * NOTE: Avoid using the constants directly, prefer "named" constants defined
11561
+ * in a semantical proximity to where they are used.
11562
+ *
11563
+ * NOTE: This file will most likely be removed in the future. The constants
11564
+ * here are only temporarily for convenience. When we figure out better names
11565
+ * and places for these this file will be eradicated.
11566
+ *
11567
+ * https://graypaper.fluffylabs.dev/#/579bd12/413000413000
11568
+ */
11569
+ /** `G_I`: The gas allocated to invoke a work-package’s Is-Authorized logic. */
11570
+ const gp_constants_G_I = 50_000_000;
11571
+ /** `I`: Maximum number of work items in a package. */
11572
+ const I = (/* unused pure expression or super */ null && (MAX_NUMBER_OF_WORK_ITEMS));
11573
+ /** `O`: Maximum number of items in the authorizations pool. */
11574
+ const gp_constants_O = 8;
11575
+ /** `Q`: The number of items in the authorizations queue. */
11576
+ const gp_constants_Q = 80;
11577
+ /** `S`: The maximum number of entries in the accumulation queue. */
11578
+ const S = 1024;
11579
+ /** `T`: The maximum number of extrinsics in a work-package. */
11580
+ const gp_constants_T = 128;
11581
+ /** `W_A`: The maximum size of is-authorized code in octets. */
11582
+ const gp_constants_W_A = 64_000;
11583
+ /** `W_B`: The maximum size of an encoded work-package with extrinsic data and imports. */
11584
+ const gp_constants_W_B = 13_794_305;
11585
+ /** `W_C`: The maximum size of service code in octets. */
11586
+ const gp_constants_W_C = 4_000_000;
11587
+ /** `W_M`: The maximum number of imports in a work-package. */
11588
+ const gp_constants_W_M = 3_072;
11589
+ /** `W_R`: The maximum total size of all output blobs in a work-report, in octets. */
11590
+ const gp_constants_W_R = 49_152;
11591
+ /** `W_T`: The size of a transfer memo in octets. */
11592
+ const gp_constants_W_T = 128;
11593
+ /** `W_M`: The maximum number of exports in a work-package. */
11594
+ const gp_constants_W_X = 3_072;
11595
+ // TODO [ToDr] Not sure where these should live yet :(
11596
+ /**
11597
+ * `S`: The minimum public service index.
11598
+ * Services of indices below these may only be created by the Registrar.
11599
+ *
11600
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
11601
+ */
11602
+ const gp_constants_MIN_PUBLIC_SERVICE_INDEX = (/* unused pure expression or super */ null && (2 ** 16));
11603
+ /**
11604
+ * `J`: The maximum sum of dependency items in a work-report.
11605
+ *
11606
+ * https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
11607
+ */
11608
+ const gp_constants_MAX_REPORT_DEPENDENCIES = 8;
11609
+ /** `Q`: Size of the authorization queue. */
11610
+ const gp_constants_AUTHORIZATION_QUEUE_SIZE = gp_constants_Q;
11611
+ /** `O`: Maximal authorization pool size. */
11612
+ const gp_constants_MAX_AUTH_POOL_SIZE = gp_constants_O;
11613
+
11701
11614
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
11702
11615
  const math_consts_MAX_VALUE = 4294967295;
11703
11616
  const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
@@ -11705,7 +11618,7 @@ const math_consts_MIN_VALUE = (/* unused pure expression or super */ null && (-(
11705
11618
  const math_consts_MAX_SHIFT_U32 = 32;
11706
11619
  const math_consts_MAX_SHIFT_U64 = 64n;
11707
11620
 
11708
- ;// CONCATENATED MODULE: ./packages/jam/state/recent-blocks.ts
11621
+ ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
11709
11622
 
11710
11623
 
11711
11624
 
@@ -11713,259 +11626,15 @@ const math_consts_MAX_SHIFT_U64 = 64n;
11713
11626
 
11714
11627
 
11715
11628
  /**
11716
- * `H = 8`: The size of recent history, in blocks.
11629
+ * `B_S`: The basic minimum balance which all services require.
11717
11630
  *
11718
- * https://graypaper.fluffylabs.dev/#/579bd12/416300416500
11631
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
11719
11632
  */
11720
- const recent_blocks_MAX_RECENT_HISTORY = 8;
11721
- /** Recent history of a single block. */
11722
- class recent_blocks_BlockState extends WithDebug {
11723
- headerHash;
11724
- accumulationResult;
11725
- postStateRoot;
11726
- reported;
11727
- static Codec = descriptors_codec.Class(recent_blocks_BlockState, {
11728
- headerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
11729
- accumulationResult: descriptors_codec.bytes(hash_HASH_SIZE),
11730
- postStateRoot: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
11731
- reported: codecHashDictionary(refine_context_WorkPackageInfo.Codec, (x) => x.workPackageHash),
11732
- });
11733
- static create({ headerHash, accumulationResult, postStateRoot, reported }) {
11734
- return new recent_blocks_BlockState(headerHash, accumulationResult, postStateRoot, reported);
11735
- }
11736
- constructor(
11737
- /** Header hash. */
11738
- headerHash,
11739
- /** Merkle mountain belt of accumulation result. */
11740
- accumulationResult,
11741
- /** Posterior state root filled in with a 1-block delay. */
11742
- postStateRoot,
11743
- /** Reported work packages (no more than number of cores). */
11744
- reported) {
11745
- super();
11746
- this.headerHash = headerHash;
11747
- this.accumulationResult = accumulationResult;
11748
- this.postStateRoot = postStateRoot;
11749
- this.reported = reported;
11750
- }
11751
- }
11633
+ const service_BASE_SERVICE_BALANCE = 100n;
11752
11634
  /**
11753
- * Recent history of blocks.
11635
+ * `B_I`: The additional minimum balance required per item of elective service state.
11754
11636
  *
11755
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
11756
- */
11757
- class recent_blocks_RecentBlocks extends WithDebug {
11758
- blocks;
11759
- accumulationLog;
11760
- static Codec = descriptors_codec.Class(recent_blocks_RecentBlocks, {
11761
- blocks: codecKnownSizeArray(recent_blocks_BlockState.Codec, {
11762
- minLength: 0,
11763
- maxLength: recent_blocks_MAX_RECENT_HISTORY,
11764
- typicalLength: recent_blocks_MAX_RECENT_HISTORY,
11765
- }),
11766
- accumulationLog: descriptors_codec.object({
11767
- peaks: readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.optional(descriptors_codec.bytes(hash_HASH_SIZE)))),
11768
- }),
11769
- });
11770
- static empty() {
11771
- return new recent_blocks_RecentBlocks(sized_array_asKnownSize([]), {
11772
- peaks: [],
11773
- });
11774
- }
11775
- static create(a) {
11776
- return new recent_blocks_RecentBlocks(a.blocks, a.accumulationLog);
11777
- }
11778
- constructor(
11779
- /**
11780
- * Most recent blocks.
11781
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fea010fea01?v=0.6.7
11782
- */
11783
- blocks,
11784
- /**
11785
- * Accumulation output log.
11786
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/0f02020f0202?v=0.6.7
11787
- */
11788
- accumulationLog) {
11789
- super();
11790
- this.blocks = blocks;
11791
- this.accumulationLog = accumulationLog;
11792
- }
11793
- }
11794
-
11795
- ;// CONCATENATED MODULE: ./packages/jam/state/recently-accumulated.ts
11796
-
11797
-
11798
-
11799
-
11800
- const recentlyAccumulatedCodec = codecPerEpochBlock(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque()).convert((x) => Array.from(x), (x) => hash_set_HashSet.from(x)));
11801
-
11802
- ;// CONCATENATED MODULE: ./packages/jam/state/validator-data.ts
11803
-
11804
-
11805
-
11806
-
11807
- /**
11808
- * Fixed size of validator metadata.
11809
- *
11810
- * https://graypaper.fluffylabs.dev/#/5f542d7/0d55010d5501
11811
- */
11812
- const VALIDATOR_META_BYTES = 128;
11813
- /**
11814
- * Details about validators' identity.
11815
- *
11816
- * https://graypaper.fluffylabs.dev/#/5f542d7/0d4b010d4c01
11817
- */
11818
- class validator_data_ValidatorData extends WithDebug {
11819
- bandersnatch;
11820
- ed25519;
11821
- bls;
11822
- metadata;
11823
- static Codec = descriptors_codec.Class(validator_data_ValidatorData, {
11824
- bandersnatch: descriptors_codec.bytes(bandersnatch_BANDERSNATCH_KEY_BYTES).asOpaque(),
11825
- ed25519: descriptors_codec.bytes(ed25519_ED25519_KEY_BYTES).asOpaque(),
11826
- bls: descriptors_codec.bytes(bandersnatch_BLS_KEY_BYTES).asOpaque(),
11827
- metadata: descriptors_codec.bytes(VALIDATOR_META_BYTES),
11828
- });
11829
- static create({ ed25519, bandersnatch, bls, metadata }) {
11830
- return new validator_data_ValidatorData(bandersnatch, ed25519, bls, metadata);
11831
- }
11832
- constructor(
11833
- /** Bandersnatch public key. */
11834
- bandersnatch,
11835
- /** ED25519 key data. */
11836
- ed25519,
11837
- /** BLS public key. */
11838
- bls,
11839
- /** Validator-defined additional metdata. */
11840
- metadata) {
11841
- super();
11842
- this.bandersnatch = bandersnatch;
11843
- this.ed25519 = ed25519;
11844
- this.bls = bls;
11845
- this.metadata = metadata;
11846
- }
11847
- }
11848
- const validatorsDataCodec = codecPerValidator(validator_data_ValidatorData.Codec);
11849
-
11850
- ;// CONCATENATED MODULE: ./packages/jam/state/safrole-data.ts
11851
-
11852
-
11853
-
11854
-
11855
-
11856
-
11857
-
11858
-
11859
-
11860
-
11861
-
11862
- var safrole_data_SafroleSealingKeysKind;
11863
- (function (SafroleSealingKeysKind) {
11864
- SafroleSealingKeysKind[SafroleSealingKeysKind["Tickets"] = 0] = "Tickets";
11865
- SafroleSealingKeysKind[SafroleSealingKeysKind["Keys"] = 1] = "Keys";
11866
- })(safrole_data_SafroleSealingKeysKind || (safrole_data_SafroleSealingKeysKind = {}));
11867
- const codecBandersnatchKey = descriptors_codec.bytes(bandersnatch_BANDERSNATCH_KEY_BYTES).asOpaque();
11868
- class safrole_data_SafroleSealingKeysData extends WithDebug {
11869
- kind;
11870
- keys;
11871
- tickets;
11872
- static Codec = codecWithContext((context) => {
11873
- return descriptors_codec.custom({
11874
- name: "SafroleSealingKeys",
11875
- sizeHint: { bytes: 1 + hash_HASH_SIZE * context.epochLength, isExact: false },
11876
- }, (e, x) => {
11877
- e.varU32(numbers_tryAsU32(x.kind));
11878
- if (x.kind === safrole_data_SafroleSealingKeysKind.Keys) {
11879
- e.sequenceFixLen(codecBandersnatchKey, x.keys);
11880
- }
11881
- else {
11882
- e.sequenceFixLen(Ticket.Codec, x.tickets);
11883
- }
11884
- }, (d) => {
11885
- const epochLength = context.epochLength;
11886
- const kind = d.varU32();
11887
- if (kind === safrole_data_SafroleSealingKeysKind.Keys) {
11888
- const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
11889
- return safrole_data_SafroleSealingKeysData.keys(common_tryAsPerEpochBlock(keys, context));
11890
- }
11891
- if (kind === safrole_data_SafroleSealingKeysKind.Tickets) {
11892
- const tickets = d.sequenceFixLen(Ticket.Codec, epochLength);
11893
- return safrole_data_SafroleSealingKeysData.tickets(common_tryAsPerEpochBlock(tickets, context));
11894
- }
11895
- throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
11896
- }, (s) => {
11897
- const kind = s.decoder.varU32();
11898
- if (kind === safrole_data_SafroleSealingKeysKind.Keys) {
11899
- s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
11900
- return;
11901
- }
11902
- if (kind === safrole_data_SafroleSealingKeysKind.Tickets) {
11903
- s.sequenceFixLen(Ticket.Codec, context.epochLength);
11904
- return;
11905
- }
11906
- throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
11907
- });
11908
- });
11909
- static keys(keys) {
11910
- return new safrole_data_SafroleSealingKeysData(safrole_data_SafroleSealingKeysKind.Keys, keys, undefined);
11911
- }
11912
- static tickets(tickets) {
11913
- return new safrole_data_SafroleSealingKeysData(safrole_data_SafroleSealingKeysKind.Tickets, undefined, tickets);
11914
- }
11915
- constructor(kind, keys, tickets) {
11916
- super();
11917
- this.kind = kind;
11918
- this.keys = keys;
11919
- this.tickets = tickets;
11920
- }
11921
- }
11922
- class safrole_data_SafroleData {
11923
- nextValidatorData;
11924
- epochRoot;
11925
- sealingKeySeries;
11926
- ticketsAccumulator;
11927
- static Codec = descriptors_codec.Class(safrole_data_SafroleData, {
11928
- nextValidatorData: codecPerValidator(validator_data_ValidatorData.Codec),
11929
- epochRoot: descriptors_codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
11930
- sealingKeySeries: safrole_data_SafroleSealingKeysData.Codec,
11931
- ticketsAccumulator: readonlyArray(descriptors_codec.sequenceVarLen(Ticket.Codec)).convert(seeThrough, sized_array_asKnownSize),
11932
- });
11933
- static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
11934
- return new safrole_data_SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
11935
- }
11936
- constructor(
11937
- /** gamma_k */
11938
- nextValidatorData,
11939
- /** gamma_z */
11940
- epochRoot,
11941
- /** gamma_s */
11942
- sealingKeySeries,
11943
- /** gamma_a */
11944
- ticketsAccumulator) {
11945
- this.nextValidatorData = nextValidatorData;
11946
- this.epochRoot = epochRoot;
11947
- this.sealingKeySeries = sealingKeySeries;
11948
- this.ticketsAccumulator = ticketsAccumulator;
11949
- }
11950
- }
11951
-
11952
- ;// CONCATENATED MODULE: ./packages/jam/state/service.ts
11953
-
11954
-
11955
-
11956
-
11957
-
11958
-
11959
- /**
11960
- * `B_S`: The basic minimum balance which all services require.
11961
- *
11962
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
11963
- */
11964
- const service_BASE_SERVICE_BALANCE = 100n;
11965
- /**
11966
- * `B_I`: The additional minimum balance required per item of elective service state.
11967
- *
11968
- * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
11637
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
11969
11638
  */
11970
11639
  const service_ELECTIVE_ITEM_BALANCE = 10n;
11971
11640
  /**
@@ -12139,370 +11808,30 @@ class service_LookupHistoryItem {
12139
11808
  }
12140
11809
  }
12141
11810
 
12142
- ;// CONCATENATED MODULE: ./packages/jam/state/statistics.ts
12143
-
11811
+ ;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
12144
11812
 
12145
11813
 
12146
11814
 
12147
11815
 
12148
11816
 
12149
- const codecServiceId = compatibility_Compatibility.isSuite(TestSuite.W3F_DAVXY) || compatibility_Compatibility.isSuite(TestSuite.JAMDUNA, compatibility_GpVersion.V0_6_7)
12150
- ? descriptors_codec.u32.asOpaque()
12151
- : descriptors_codec.varU32.convert((s) => numbers_tryAsU32(s), (i) => common_tryAsServiceId(i));
12152
- /**
12153
- * Activity Record of a single validator.
12154
- *
12155
- * https://graypaper.fluffylabs.dev/#/579bd12/183701183701
12156
- */
12157
- class statistics_ValidatorStatistics {
12158
- blocks;
12159
- tickets;
12160
- preImages;
12161
- preImagesSize;
12162
- guarantees;
12163
- assurances;
12164
- static Codec = descriptors_codec.Class(statistics_ValidatorStatistics, {
12165
- blocks: descriptors_codec.u32,
12166
- tickets: descriptors_codec.u32,
12167
- preImages: descriptors_codec.u32,
12168
- preImagesSize: descriptors_codec.u32,
12169
- guarantees: descriptors_codec.u32,
12170
- assurances: descriptors_codec.u32,
11817
+ /** Dictionary entry of services that auto-accumulate every block. */
11818
+ class privileged_services_AutoAccumulate {
11819
+ service;
11820
+ gasLimit;
11821
+ static Codec = descriptors_codec.Class(privileged_services_AutoAccumulate, {
11822
+ service: descriptors_codec.u32.asOpaque(),
11823
+ gasLimit: descriptors_codec.u64.asOpaque(),
12171
11824
  });
12172
- static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
12173
- return new statistics_ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
11825
+ static create({ service, gasLimit }) {
11826
+ return new privileged_services_AutoAccumulate(service, gasLimit);
12174
11827
  }
12175
11828
  constructor(
12176
- /** The number of blocks produced by the validator. */
12177
- blocks,
12178
- /** The number of tickets introduced by the validator. */
12179
- tickets,
12180
- /** The number of preimages introduced by the validator. */
12181
- preImages,
12182
- /** The total number of octets across all preimages introduced by the validator. */
12183
- preImagesSize,
12184
- /** The number of reports guaranteed by the validator. */
12185
- guarantees,
12186
- /** The number of availability assurances made by the validator. */
12187
- assurances) {
12188
- this.blocks = blocks;
12189
- this.tickets = tickets;
12190
- this.preImages = preImages;
12191
- this.preImagesSize = preImagesSize;
12192
- this.guarantees = guarantees;
12193
- this.assurances = assurances;
12194
- }
12195
- static empty() {
12196
- const zero = numbers_tryAsU32(0);
12197
- return new statistics_ValidatorStatistics(zero, zero, zero, zero, zero, zero);
12198
- }
12199
- }
12200
- const codecVarU16 = descriptors_codec.varU32.convert((i) => numbers_tryAsU32(i), (o) => numbers_tryAsU16(o));
12201
- /** Encode/decode unsigned gas. */
12202
- const codecVarGas = descriptors_codec.varU64.convert((g) => numbers_tryAsU64(g), (i) => common_tryAsServiceGas(i));
12203
- /**
12204
- * Single core statistics.
12205
- * Updated per block, based on incoming work reports (`w`).
12206
- *
12207
- * https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
12208
- * https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
12209
- */
12210
- class CoreStatistics {
12211
- dataAvailabilityLoad;
12212
- popularity;
12213
- imports;
12214
- exports;
12215
- extrinsicSize;
12216
- extrinsicCount;
12217
- bundleSize;
12218
- gasUsed;
12219
- static Codec = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_0)
12220
- ? descriptors_codec.Class(CoreStatistics, {
12221
- dataAvailabilityLoad: descriptors_codec.varU32,
12222
- popularity: codecVarU16,
12223
- imports: codecVarU16,
12224
- extrinsicCount: codecVarU16,
12225
- extrinsicSize: descriptors_codec.varU32,
12226
- exports: codecVarU16,
12227
- bundleSize: descriptors_codec.varU32,
12228
- gasUsed: codecVarGas,
12229
- })
12230
- : descriptors_codec.Class(CoreStatistics, {
12231
- dataAvailabilityLoad: descriptors_codec.varU32,
12232
- popularity: codecVarU16,
12233
- imports: codecVarU16,
12234
- exports: codecVarU16,
12235
- extrinsicSize: descriptors_codec.varU32,
12236
- extrinsicCount: codecVarU16,
12237
- bundleSize: descriptors_codec.varU32,
12238
- gasUsed: codecVarGas,
12239
- });
12240
- static create(v) {
12241
- return new CoreStatistics(v.dataAvailabilityLoad, v.popularity, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.bundleSize, v.gasUsed);
12242
- }
12243
- constructor(
12244
- /** `d` */
12245
- dataAvailabilityLoad,
12246
- /** `p` */
12247
- popularity,
12248
- /** `i` */
12249
- imports,
12250
- /** `e` */
12251
- exports,
12252
- /** `z` */
12253
- extrinsicSize,
12254
- /** `x` */
12255
- extrinsicCount,
12256
- /** `b` */
12257
- bundleSize,
12258
- /** `u` */
12259
- gasUsed) {
12260
- this.dataAvailabilityLoad = dataAvailabilityLoad;
12261
- this.popularity = popularity;
12262
- this.imports = imports;
12263
- this.exports = exports;
12264
- this.extrinsicSize = extrinsicSize;
12265
- this.extrinsicCount = extrinsicCount;
12266
- this.bundleSize = bundleSize;
12267
- this.gasUsed = gasUsed;
12268
- }
12269
- static empty() {
12270
- const zero = numbers_tryAsU32(0);
12271
- const zero16 = numbers_tryAsU16(0);
12272
- const zeroGas = common_tryAsServiceGas(0);
12273
- return new CoreStatistics(zero, zero16, zero16, zero16, zero, zero16, zero, zeroGas);
12274
- }
12275
- }
12276
- /**
12277
- * Service statistics.
12278
- * Updated per block, based on available work reports (`W`).
12279
- *
12280
- * https://graypaper.fluffylabs.dev/#/1c979cb/199802199802?v=0.7.1
12281
- */
12282
- class statistics_ServiceStatistics {
12283
- providedCount;
12284
- providedSize;
12285
- refinementCount;
12286
- refinementGasUsed;
12287
- imports;
12288
- exports;
12289
- extrinsicSize;
12290
- extrinsicCount;
12291
- accumulateCount;
12292
- accumulateGasUsed;
12293
- onTransfersCount;
12294
- onTransfersGasUsed;
12295
- static Codec = compatibility_Compatibility.selectIfGreaterOrEqual({
12296
- fallback: descriptors_codec.Class(statistics_ServiceStatistics, {
12297
- providedCount: codecVarU16,
12298
- providedSize: descriptors_codec.varU32,
12299
- refinementCount: descriptors_codec.varU32,
12300
- refinementGasUsed: codecVarGas,
12301
- imports: codecVarU16,
12302
- exports: codecVarU16,
12303
- extrinsicSize: descriptors_codec.varU32,
12304
- extrinsicCount: codecVarU16,
12305
- accumulateCount: descriptors_codec.varU32,
12306
- accumulateGasUsed: codecVarGas,
12307
- onTransfersCount: descriptors_codec.varU32,
12308
- onTransfersGasUsed: codecVarGas,
12309
- }),
12310
- versions: {
12311
- [compatibility_GpVersion.V0_7_0]: descriptors_codec.Class(statistics_ServiceStatistics, {
12312
- providedCount: codecVarU16,
12313
- providedSize: descriptors_codec.varU32,
12314
- refinementCount: descriptors_codec.varU32,
12315
- refinementGasUsed: codecVarGas,
12316
- imports: codecVarU16,
12317
- extrinsicCount: codecVarU16,
12318
- extrinsicSize: descriptors_codec.varU32,
12319
- exports: codecVarU16,
12320
- accumulateCount: descriptors_codec.varU32,
12321
- accumulateGasUsed: codecVarGas,
12322
- onTransfersCount: descriptors_codec.varU32,
12323
- onTransfersGasUsed: codecVarGas,
12324
- }),
12325
- [compatibility_GpVersion.V0_7_1]: descriptors_codec.Class(statistics_ServiceStatistics, {
12326
- providedCount: codecVarU16,
12327
- providedSize: descriptors_codec.varU32,
12328
- refinementCount: descriptors_codec.varU32,
12329
- refinementGasUsed: codecVarGas,
12330
- imports: codecVarU16,
12331
- extrinsicCount: codecVarU16,
12332
- extrinsicSize: descriptors_codec.varU32,
12333
- exports: codecVarU16,
12334
- accumulateCount: descriptors_codec.varU32,
12335
- accumulateGasUsed: codecVarGas,
12336
- onTransfersCount: ignoreValueWithDefault(numbers_tryAsU32(0)),
12337
- onTransfersGasUsed: ignoreValueWithDefault(common_tryAsServiceGas(0)),
12338
- }),
12339
- },
12340
- });
12341
- static create(v) {
12342
- return new statistics_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);
12343
- }
12344
- constructor(
12345
- /** `p.0` */
12346
- providedCount,
12347
- /** `p.1` */
12348
- providedSize,
12349
- /** `r.0` */
12350
- refinementCount,
12351
- /** `r.1` */
12352
- refinementGasUsed,
12353
- /** `i` */
12354
- imports,
12355
- /** `e` */
12356
- exports,
12357
- /** `z` */
12358
- extrinsicSize,
12359
- /** `x` */
12360
- extrinsicCount,
12361
- /** `a.0` */
12362
- accumulateCount,
12363
- /** `a.1` */
12364
- accumulateGasUsed,
12365
- /** `t.0` @deprecated since 0.7.1 */
12366
- onTransfersCount,
12367
- /** `t.1` @deprecated since 0.7.1 */
12368
- onTransfersGasUsed) {
12369
- this.providedCount = providedCount;
12370
- this.providedSize = providedSize;
12371
- this.refinementCount = refinementCount;
12372
- this.refinementGasUsed = refinementGasUsed;
12373
- this.imports = imports;
12374
- this.exports = exports;
12375
- this.extrinsicSize = extrinsicSize;
12376
- this.extrinsicCount = extrinsicCount;
12377
- this.accumulateCount = accumulateCount;
12378
- this.accumulateGasUsed = accumulateGasUsed;
12379
- this.onTransfersCount = onTransfersCount;
12380
- this.onTransfersGasUsed = onTransfersGasUsed;
12381
- }
12382
- static empty() {
12383
- const zero = numbers_tryAsU32(0);
12384
- const zero16 = numbers_tryAsU16(0);
12385
- const zeroGas = common_tryAsServiceGas(0);
12386
- return new statistics_ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
12387
- }
12388
- }
12389
- /** `pi`: Statistics of each validator, cores statistics and services statistics. */
12390
- class statistics_StatisticsData {
12391
- current;
12392
- previous;
12393
- cores;
12394
- services;
12395
- static Codec = descriptors_codec.Class(statistics_StatisticsData, {
12396
- current: codecPerValidator(statistics_ValidatorStatistics.Codec),
12397
- previous: codecPerValidator(statistics_ValidatorStatistics.Codec),
12398
- cores: codecPerCore(CoreStatistics.Codec),
12399
- services: descriptors_codec.dictionary(codecServiceId, statistics_ServiceStatistics.Codec, {
12400
- sortKeys: (a, b) => a - b,
12401
- }),
12402
- });
12403
- static create(v) {
12404
- return new statistics_StatisticsData(v.current, v.previous, v.cores, v.services);
12405
- }
12406
- constructor(current, previous, cores, services) {
12407
- this.current = current;
12408
- this.previous = previous;
12409
- this.cores = cores;
12410
- this.services = services;
12411
- }
12412
- }
12413
-
12414
- ;// CONCATENATED MODULE: ./packages/jam/state/in-memory-state-view.ts
12415
-
12416
-
12417
-
12418
-
12419
-
12420
-
12421
-
12422
-
12423
-
12424
-
12425
- class InMemoryStateView {
12426
- chainSpec;
12427
- state;
12428
- constructor(chainSpec, state) {
12429
- this.chainSpec = chainSpec;
12430
- this.state = state;
12431
- }
12432
- availabilityAssignmentView() {
12433
- return reencodeAsView(availabilityAssignmentsCodec, this.state.availabilityAssignment, this.chainSpec);
12434
- }
12435
- designatedValidatorDataView() {
12436
- return reencodeAsView(validatorsDataCodec, this.state.designatedValidatorData, this.chainSpec);
12437
- }
12438
- currentValidatorDataView() {
12439
- return reencodeAsView(validatorsDataCodec, this.state.currentValidatorData, this.chainSpec);
12440
- }
12441
- previousValidatorDataView() {
12442
- return reencodeAsView(validatorsDataCodec, this.state.previousValidatorData, this.chainSpec);
12443
- }
12444
- authPoolsView() {
12445
- return reencodeAsView(authPoolsCodec, this.state.authPools, this.chainSpec);
12446
- }
12447
- authQueuesView() {
12448
- return reencodeAsView(authQueuesCodec, this.state.authQueues, this.chainSpec);
12449
- }
12450
- recentBlocksView() {
12451
- return reencodeAsView(recent_blocks_RecentBlocks.Codec, this.state.recentBlocks, this.chainSpec);
12452
- }
12453
- statisticsView() {
12454
- return reencodeAsView(statistics_StatisticsData.Codec, this.state.statistics, this.chainSpec);
12455
- }
12456
- accumulationQueueView() {
12457
- return reencodeAsView(accumulationQueueCodec, this.state.accumulationQueue, this.chainSpec);
12458
- }
12459
- recentlyAccumulatedView() {
12460
- return reencodeAsView(recentlyAccumulatedCodec, this.state.recentlyAccumulated, this.chainSpec);
12461
- }
12462
- safroleDataView() {
12463
- // TODO [ToDr] Consider exposting `safrole` from state
12464
- // instead of individual fields
12465
- const safrole = safrole_data_SafroleData.create({
12466
- nextValidatorData: this.state.nextValidatorData,
12467
- epochRoot: this.state.epochRoot,
12468
- sealingKeySeries: this.state.sealingKeySeries,
12469
- ticketsAccumulator: this.state.ticketsAccumulator,
12470
- });
12471
- return reencodeAsView(safrole_data_SafroleData.Codec, safrole, this.chainSpec);
12472
- }
12473
- getServiceInfoView(id) {
12474
- const service = this.state.getService(id);
12475
- if (service === null) {
12476
- return null;
12477
- }
12478
- return reencodeAsView(service_ServiceAccountInfo.Codec, service.getInfo(), this.chainSpec);
12479
- }
12480
- }
12481
-
12482
- ;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
12483
-
12484
-
12485
-
12486
-
12487
-
12488
- /** Dictionary entry of services that auto-accumulate every block. */
12489
- class privileged_services_AutoAccumulate {
12490
- service;
12491
- gasLimit;
12492
- static Codec = descriptors_codec.Class(privileged_services_AutoAccumulate, {
12493
- service: descriptors_codec.u32.asOpaque(),
12494
- gasLimit: descriptors_codec.u64.asOpaque(),
12495
- });
12496
- static create({ service, gasLimit }) {
12497
- return new privileged_services_AutoAccumulate(service, gasLimit);
12498
- }
12499
- constructor(
12500
- /** Service id that auto-accumulates. */
12501
- service,
12502
- /** Gas limit for auto-accumulation. */
12503
- gasLimit) {
12504
- this.service = service;
12505
- this.gasLimit = gasLimit;
11829
+ /** Service id that auto-accumulates. */
11830
+ service,
11831
+ /** Gas limit for auto-accumulation. */
11832
+ gasLimit) {
11833
+ this.service = service;
11834
+ this.gasLimit = gasLimit;
12506
11835
  }
12507
11836
  }
12508
11837
  /**
@@ -12554,6 +11883,286 @@ class privileged_services_PrivilegedServices {
12554
11883
  }
12555
11884
  }
12556
11885
 
11886
+ ;// CONCATENATED MODULE: ./packages/jam/state/recent-blocks.ts
11887
+
11888
+
11889
+
11890
+
11891
+
11892
+
11893
+ /**
11894
+ * `H = 8`: The size of recent history, in blocks.
11895
+ *
11896
+ * https://graypaper.fluffylabs.dev/#/579bd12/416300416500
11897
+ */
11898
+ const recent_blocks_MAX_RECENT_HISTORY = 8;
11899
+ /** Recent history of a single block. */
11900
+ class recent_blocks_BlockState extends WithDebug {
11901
+ headerHash;
11902
+ accumulationResult;
11903
+ postStateRoot;
11904
+ reported;
11905
+ static Codec = descriptors_codec.Class(recent_blocks_BlockState, {
11906
+ headerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
11907
+ accumulationResult: descriptors_codec.bytes(hash_HASH_SIZE),
11908
+ postStateRoot: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
11909
+ reported: codecHashDictionary(refine_context_WorkPackageInfo.Codec, (x) => x.workPackageHash),
11910
+ });
11911
+ static create({ headerHash, accumulationResult, postStateRoot, reported }) {
11912
+ return new recent_blocks_BlockState(headerHash, accumulationResult, postStateRoot, reported);
11913
+ }
11914
+ constructor(
11915
+ /** Header hash. */
11916
+ headerHash,
11917
+ /** Merkle mountain belt of accumulation result. */
11918
+ accumulationResult,
11919
+ /** Posterior state root filled in with a 1-block delay. */
11920
+ postStateRoot,
11921
+ /** Reported work packages (no more than number of cores). */
11922
+ reported) {
11923
+ super();
11924
+ this.headerHash = headerHash;
11925
+ this.accumulationResult = accumulationResult;
11926
+ this.postStateRoot = postStateRoot;
11927
+ this.reported = reported;
11928
+ }
11929
+ }
11930
+ class recent_blocks_RecentBlocks extends WithDebug {
11931
+ blocks;
11932
+ accumulationLog;
11933
+ static Codec = descriptors_codec.Class(recent_blocks_RecentBlocks, {
11934
+ blocks: codecKnownSizeArray(recent_blocks_BlockState.Codec, {
11935
+ minLength: 0,
11936
+ maxLength: recent_blocks_MAX_RECENT_HISTORY,
11937
+ typicalLength: recent_blocks_MAX_RECENT_HISTORY,
11938
+ }),
11939
+ accumulationLog: descriptors_codec.object({
11940
+ peaks: readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.optional(descriptors_codec.bytes(hash_HASH_SIZE)))),
11941
+ }),
11942
+ });
11943
+ static create(a) {
11944
+ return new recent_blocks_RecentBlocks(a.blocks, a.accumulationLog);
11945
+ }
11946
+ constructor(
11947
+ /**
11948
+ * Most recent blocks.
11949
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fea010fea01?v=0.6.7
11950
+ */
11951
+ blocks,
11952
+ /**
11953
+ * Accumulation output log.
11954
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/0f02020f0202?v=0.6.7
11955
+ */
11956
+ accumulationLog) {
11957
+ super();
11958
+ this.blocks = blocks;
11959
+ this.accumulationLog = accumulationLog;
11960
+ }
11961
+ }
11962
+ /**
11963
+ * Recent history of blocks.
11964
+ *
11965
+ * https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
11966
+ */
11967
+ class recent_blocks_RecentBlocksHistory extends WithDebug {
11968
+ current;
11969
+ static Codec = Descriptor.new("RecentBlocksHistory", recent_blocks_RecentBlocks.Codec.sizeHint, (encoder, value) => recent_blocks_RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
11970
+ const recentBlocks = recent_blocks_RecentBlocks.Codec.decode(decoder);
11971
+ return recent_blocks_RecentBlocksHistory.create(recentBlocks);
11972
+ }, (skip) => {
11973
+ return recent_blocks_RecentBlocks.Codec.skip(skip);
11974
+ });
11975
+ static create(recentBlocks) {
11976
+ return new recent_blocks_RecentBlocksHistory(recentBlocks);
11977
+ }
11978
+ static empty() {
11979
+ return recent_blocks_RecentBlocksHistory.create(recent_blocks_RecentBlocks.create({
11980
+ blocks: sized_array_asKnownSize([]),
11981
+ accumulationLog: { peaks: [] },
11982
+ }));
11983
+ }
11984
+ /**
11985
+ * Returns the block's BEEFY super peak.
11986
+ */
11987
+ static accumulationResult(block) {
11988
+ return block.accumulationResult;
11989
+ }
11990
+ constructor(current) {
11991
+ super();
11992
+ this.current = current;
11993
+ }
11994
+ /** History of recent blocks with maximum size of `MAX_RECENT_HISTORY` */
11995
+ get blocks() {
11996
+ if (this.current !== null) {
11997
+ return this.current.blocks;
11998
+ }
11999
+ throw new Error("RecentBlocksHistory is in invalid state");
12000
+ }
12001
+ asCurrent() {
12002
+ if (this.current === null) {
12003
+ throw new Error("Cannot access current RecentBlocks format");
12004
+ }
12005
+ return this.current;
12006
+ }
12007
+ updateBlocks(blocks) {
12008
+ if (this.current !== null) {
12009
+ return recent_blocks_RecentBlocksHistory.create(recent_blocks_RecentBlocks.create({
12010
+ ...this.current,
12011
+ blocks: opaque_asOpaqueType(blocks),
12012
+ }));
12013
+ }
12014
+ throw new Error("RecentBlocksHistory is in invalid state. Cannot be updated!");
12015
+ }
12016
+ }
12017
+
12018
+ ;// CONCATENATED MODULE: ./packages/jam/state/validator-data.ts
12019
+
12020
+
12021
+
12022
+ /**
12023
+ * Fixed size of validator metadata.
12024
+ *
12025
+ * https://graypaper.fluffylabs.dev/#/5f542d7/0d55010d5501
12026
+ */
12027
+ const VALIDATOR_META_BYTES = 128;
12028
+ /**
12029
+ * Details about validators' identity.
12030
+ *
12031
+ * https://graypaper.fluffylabs.dev/#/5f542d7/0d4b010d4c01
12032
+ */
12033
+ class validator_data_ValidatorData extends WithDebug {
12034
+ bandersnatch;
12035
+ ed25519;
12036
+ bls;
12037
+ metadata;
12038
+ static Codec = descriptors_codec.Class(validator_data_ValidatorData, {
12039
+ bandersnatch: descriptors_codec.bytes(bandersnatch_BANDERSNATCH_KEY_BYTES).asOpaque(),
12040
+ ed25519: descriptors_codec.bytes(ed25519_ED25519_KEY_BYTES).asOpaque(),
12041
+ bls: descriptors_codec.bytes(bandersnatch_BLS_KEY_BYTES).asOpaque(),
12042
+ metadata: descriptors_codec.bytes(VALIDATOR_META_BYTES),
12043
+ });
12044
+ static create({ ed25519, bandersnatch, bls, metadata }) {
12045
+ return new validator_data_ValidatorData(bandersnatch, ed25519, bls, metadata);
12046
+ }
12047
+ constructor(
12048
+ /** Bandersnatch public key. */
12049
+ bandersnatch,
12050
+ /** ED25519 key data. */
12051
+ ed25519,
12052
+ /** BLS public key. */
12053
+ bls,
12054
+ /** Validator-defined additional metdata. */
12055
+ metadata) {
12056
+ super();
12057
+ this.bandersnatch = bandersnatch;
12058
+ this.ed25519 = ed25519;
12059
+ this.bls = bls;
12060
+ this.metadata = metadata;
12061
+ }
12062
+ }
12063
+
12064
+ ;// CONCATENATED MODULE: ./packages/jam/state/safrole-data.ts
12065
+
12066
+
12067
+
12068
+
12069
+
12070
+
12071
+
12072
+
12073
+
12074
+
12075
+
12076
+ var safrole_data_SafroleSealingKeysKind;
12077
+ (function (SafroleSealingKeysKind) {
12078
+ SafroleSealingKeysKind[SafroleSealingKeysKind["Tickets"] = 0] = "Tickets";
12079
+ SafroleSealingKeysKind[SafroleSealingKeysKind["Keys"] = 1] = "Keys";
12080
+ })(safrole_data_SafroleSealingKeysKind || (safrole_data_SafroleSealingKeysKind = {}));
12081
+ const codecBandersnatchKey = descriptors_codec.bytes(bandersnatch_BANDERSNATCH_KEY_BYTES).asOpaque();
12082
+ class safrole_data_SafroleSealingKeysData extends WithDebug {
12083
+ kind;
12084
+ keys;
12085
+ tickets;
12086
+ static Codec = codecWithContext((context) => {
12087
+ return descriptors_codec.custom({
12088
+ name: "SafroleSealingKeys",
12089
+ sizeHint: { bytes: 1 + hash_HASH_SIZE * context.epochLength, isExact: false },
12090
+ }, (e, x) => {
12091
+ e.varU32(numbers_tryAsU32(x.kind));
12092
+ if (x.kind === safrole_data_SafroleSealingKeysKind.Keys) {
12093
+ e.sequenceFixLen(codecBandersnatchKey, x.keys);
12094
+ }
12095
+ else {
12096
+ e.sequenceFixLen(Ticket.Codec, x.tickets);
12097
+ }
12098
+ }, (d) => {
12099
+ const epochLength = context.epochLength;
12100
+ const kind = d.varU32();
12101
+ if (kind === safrole_data_SafroleSealingKeysKind.Keys) {
12102
+ const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
12103
+ return safrole_data_SafroleSealingKeysData.keys(common_tryAsPerEpochBlock(keys, context));
12104
+ }
12105
+ if (kind === safrole_data_SafroleSealingKeysKind.Tickets) {
12106
+ const tickets = d.sequenceFixLen(Ticket.Codec, epochLength);
12107
+ return safrole_data_SafroleSealingKeysData.tickets(common_tryAsPerEpochBlock(tickets, context));
12108
+ }
12109
+ throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
12110
+ }, (s) => {
12111
+ const kind = s.decoder.varU32();
12112
+ if (kind === safrole_data_SafroleSealingKeysKind.Keys) {
12113
+ s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
12114
+ return;
12115
+ }
12116
+ if (kind === safrole_data_SafroleSealingKeysKind.Tickets) {
12117
+ s.sequenceFixLen(Ticket.Codec, context.epochLength);
12118
+ return;
12119
+ }
12120
+ throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
12121
+ });
12122
+ });
12123
+ static keys(keys) {
12124
+ return new safrole_data_SafroleSealingKeysData(safrole_data_SafroleSealingKeysKind.Keys, keys, undefined);
12125
+ }
12126
+ static tickets(tickets) {
12127
+ return new safrole_data_SafroleSealingKeysData(safrole_data_SafroleSealingKeysKind.Tickets, undefined, tickets);
12128
+ }
12129
+ constructor(kind, keys, tickets) {
12130
+ super();
12131
+ this.kind = kind;
12132
+ this.keys = keys;
12133
+ this.tickets = tickets;
12134
+ }
12135
+ }
12136
+ class safrole_data_SafroleData {
12137
+ nextValidatorData;
12138
+ epochRoot;
12139
+ sealingKeySeries;
12140
+ ticketsAccumulator;
12141
+ static Codec = descriptors_codec.Class(safrole_data_SafroleData, {
12142
+ nextValidatorData: codecPerValidator(validator_data_ValidatorData.Codec),
12143
+ epochRoot: descriptors_codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
12144
+ sealingKeySeries: safrole_data_SafroleSealingKeysData.Codec,
12145
+ ticketsAccumulator: readonlyArray(descriptors_codec.sequenceVarLen(Ticket.Codec)).convert(seeThrough, sized_array_asKnownSize),
12146
+ });
12147
+ static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
12148
+ return new safrole_data_SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
12149
+ }
12150
+ constructor(
12151
+ /** gamma_k */
12152
+ nextValidatorData,
12153
+ /** gamma_z */
12154
+ epochRoot,
12155
+ /** gamma_s */
12156
+ sealingKeySeries,
12157
+ /** gamma_a */
12158
+ ticketsAccumulator) {
12159
+ this.nextValidatorData = nextValidatorData;
12160
+ this.epochRoot = epochRoot;
12161
+ this.sealingKeySeries = sealingKeySeries;
12162
+ this.ticketsAccumulator = ticketsAccumulator;
12163
+ }
12164
+ }
12165
+
12557
12166
  ;// CONCATENATED MODULE: ./packages/jam/state/state.ts
12558
12167
  /**
12559
12168
  * In addition to the entropy accumulator η_0, we retain
@@ -12661,57 +12270,329 @@ class state_update_UpdateService {
12661
12270
  this.serviceId = serviceId;
12662
12271
  this.action = action;
12663
12272
  }
12664
- static update({ serviceId, serviceInfo }) {
12665
- return new state_update_UpdateService(serviceId, {
12666
- kind: state_update_UpdateServiceKind.Update,
12667
- account: serviceInfo,
12668
- });
12273
+ static update({ serviceId, serviceInfo }) {
12274
+ return new state_update_UpdateService(serviceId, {
12275
+ kind: state_update_UpdateServiceKind.Update,
12276
+ account: serviceInfo,
12277
+ });
12278
+ }
12279
+ static create({ serviceId, serviceInfo, lookupHistory, }) {
12280
+ return new state_update_UpdateService(serviceId, {
12281
+ kind: state_update_UpdateServiceKind.Create,
12282
+ account: serviceInfo,
12283
+ lookupHistory,
12284
+ });
12285
+ }
12286
+ }
12287
+ /** Update service storage kind. */
12288
+ var state_update_UpdateStorageKind;
12289
+ (function (UpdateStorageKind) {
12290
+ /** Set a storage value. */
12291
+ UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
12292
+ /** Remove a storage value. */
12293
+ UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
12294
+ })(state_update_UpdateStorageKind || (state_update_UpdateStorageKind = {}));
12295
+ /**
12296
+ * Update service storage item.
12297
+ *
12298
+ * Can either create/modify an entry or remove it.
12299
+ */
12300
+ class state_update_UpdateStorage {
12301
+ serviceId;
12302
+ action;
12303
+ constructor(serviceId, action) {
12304
+ this.serviceId = serviceId;
12305
+ this.action = action;
12306
+ }
12307
+ static set({ serviceId, storage }) {
12308
+ return new state_update_UpdateStorage(serviceId, { kind: state_update_UpdateStorageKind.Set, storage });
12309
+ }
12310
+ static remove({ serviceId, key }) {
12311
+ return new state_update_UpdateStorage(serviceId, { kind: state_update_UpdateStorageKind.Remove, key });
12312
+ }
12313
+ get key() {
12314
+ if (this.action.kind === state_update_UpdateStorageKind.Remove) {
12315
+ return this.action.key;
12316
+ }
12317
+ return this.action.storage.key;
12318
+ }
12319
+ get value() {
12320
+ if (this.action.kind === state_update_UpdateStorageKind.Remove) {
12321
+ return null;
12322
+ }
12323
+ return this.action.storage.value;
12324
+ }
12325
+ }
12326
+
12327
+ ;// CONCATENATED MODULE: ./packages/jam/state/statistics.ts
12328
+
12329
+
12330
+
12331
+
12332
+
12333
+
12334
+ const codecServiceId = compatibility_Compatibility.isSuite(TestSuite.W3F_DAVXY) || compatibility_Compatibility.isSuite(TestSuite.JAMDUNA, compatibility_GpVersion.V0_6_7)
12335
+ ? descriptors_codec.u32.asOpaque()
12336
+ : descriptors_codec.varU32.convert((s) => numbers_tryAsU32(s), (i) => common_tryAsServiceId(i));
12337
+ /**
12338
+ * Activity Record of a single validator.
12339
+ *
12340
+ * https://graypaper.fluffylabs.dev/#/579bd12/183701183701
12341
+ */
12342
+ class statistics_ValidatorStatistics {
12343
+ blocks;
12344
+ tickets;
12345
+ preImages;
12346
+ preImagesSize;
12347
+ guarantees;
12348
+ assurances;
12349
+ static Codec = descriptors_codec.Class(statistics_ValidatorStatistics, {
12350
+ blocks: descriptors_codec.u32,
12351
+ tickets: descriptors_codec.u32,
12352
+ preImages: descriptors_codec.u32,
12353
+ preImagesSize: descriptors_codec.u32,
12354
+ guarantees: descriptors_codec.u32,
12355
+ assurances: descriptors_codec.u32,
12356
+ });
12357
+ static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
12358
+ return new statistics_ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
12359
+ }
12360
+ constructor(
12361
+ /** The number of blocks produced by the validator. */
12362
+ blocks,
12363
+ /** The number of tickets introduced by the validator. */
12364
+ tickets,
12365
+ /** The number of preimages introduced by the validator. */
12366
+ preImages,
12367
+ /** The total number of octets across all preimages introduced by the validator. */
12368
+ preImagesSize,
12369
+ /** The number of reports guaranteed by the validator. */
12370
+ guarantees,
12371
+ /** The number of availability assurances made by the validator. */
12372
+ assurances) {
12373
+ this.blocks = blocks;
12374
+ this.tickets = tickets;
12375
+ this.preImages = preImages;
12376
+ this.preImagesSize = preImagesSize;
12377
+ this.guarantees = guarantees;
12378
+ this.assurances = assurances;
12379
+ }
12380
+ static empty() {
12381
+ const zero = numbers_tryAsU32(0);
12382
+ return new statistics_ValidatorStatistics(zero, zero, zero, zero, zero, zero);
12383
+ }
12384
+ }
12385
+ const codecVarU16 = descriptors_codec.varU32.convert((i) => numbers_tryAsU32(i), (o) => numbers_tryAsU16(o));
12386
+ /** Encode/decode unsigned gas. */
12387
+ const codecVarGas = descriptors_codec.varU64.convert((g) => numbers_tryAsU64(g), (i) => common_tryAsServiceGas(i));
12388
+ /**
12389
+ * Single core statistics.
12390
+ * Updated per block, based on incoming work reports (`w`).
12391
+ *
12392
+ * https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
12393
+ * https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
12394
+ */
12395
+ class CoreStatistics {
12396
+ dataAvailabilityLoad;
12397
+ popularity;
12398
+ imports;
12399
+ exports;
12400
+ extrinsicSize;
12401
+ extrinsicCount;
12402
+ bundleSize;
12403
+ gasUsed;
12404
+ static Codec = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_0)
12405
+ ? descriptors_codec.Class(CoreStatistics, {
12406
+ dataAvailabilityLoad: descriptors_codec.varU32,
12407
+ popularity: codecVarU16,
12408
+ imports: codecVarU16,
12409
+ extrinsicCount: codecVarU16,
12410
+ extrinsicSize: descriptors_codec.varU32,
12411
+ exports: codecVarU16,
12412
+ bundleSize: descriptors_codec.varU32,
12413
+ gasUsed: codecVarGas,
12414
+ })
12415
+ : descriptors_codec.Class(CoreStatistics, {
12416
+ dataAvailabilityLoad: descriptors_codec.varU32,
12417
+ popularity: codecVarU16,
12418
+ imports: codecVarU16,
12419
+ exports: codecVarU16,
12420
+ extrinsicSize: descriptors_codec.varU32,
12421
+ extrinsicCount: codecVarU16,
12422
+ bundleSize: descriptors_codec.varU32,
12423
+ gasUsed: codecVarGas,
12424
+ });
12425
+ static create(v) {
12426
+ return new CoreStatistics(v.dataAvailabilityLoad, v.popularity, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.bundleSize, v.gasUsed);
12427
+ }
12428
+ constructor(
12429
+ /** `d` */
12430
+ dataAvailabilityLoad,
12431
+ /** `p` */
12432
+ popularity,
12433
+ /** `i` */
12434
+ imports,
12435
+ /** `e` */
12436
+ exports,
12437
+ /** `z` */
12438
+ extrinsicSize,
12439
+ /** `x` */
12440
+ extrinsicCount,
12441
+ /** `b` */
12442
+ bundleSize,
12443
+ /** `u` */
12444
+ gasUsed) {
12445
+ this.dataAvailabilityLoad = dataAvailabilityLoad;
12446
+ this.popularity = popularity;
12447
+ this.imports = imports;
12448
+ this.exports = exports;
12449
+ this.extrinsicSize = extrinsicSize;
12450
+ this.extrinsicCount = extrinsicCount;
12451
+ this.bundleSize = bundleSize;
12452
+ this.gasUsed = gasUsed;
12453
+ }
12454
+ static empty() {
12455
+ const zero = numbers_tryAsU32(0);
12456
+ const zero16 = numbers_tryAsU16(0);
12457
+ const zeroGas = common_tryAsServiceGas(0);
12458
+ return new CoreStatistics(zero, zero16, zero16, zero16, zero, zero16, zero, zeroGas);
12459
+ }
12460
+ }
12461
+ /**
12462
+ * Service statistics.
12463
+ * Updated per block, based on available work reports (`W`).
12464
+ *
12465
+ * https://graypaper.fluffylabs.dev/#/1c979cb/199802199802?v=0.7.1
12466
+ */
12467
+ class statistics_ServiceStatistics {
12468
+ providedCount;
12469
+ providedSize;
12470
+ refinementCount;
12471
+ refinementGasUsed;
12472
+ imports;
12473
+ exports;
12474
+ extrinsicSize;
12475
+ extrinsicCount;
12476
+ accumulateCount;
12477
+ accumulateGasUsed;
12478
+ onTransfersCount;
12479
+ onTransfersGasUsed;
12480
+ static Codec = compatibility_Compatibility.selectIfGreaterOrEqual({
12481
+ fallback: descriptors_codec.Class(statistics_ServiceStatistics, {
12482
+ providedCount: codecVarU16,
12483
+ providedSize: descriptors_codec.varU32,
12484
+ refinementCount: descriptors_codec.varU32,
12485
+ refinementGasUsed: codecVarGas,
12486
+ imports: codecVarU16,
12487
+ exports: codecVarU16,
12488
+ extrinsicSize: descriptors_codec.varU32,
12489
+ extrinsicCount: codecVarU16,
12490
+ accumulateCount: descriptors_codec.varU32,
12491
+ accumulateGasUsed: codecVarGas,
12492
+ onTransfersCount: descriptors_codec.varU32,
12493
+ onTransfersGasUsed: codecVarGas,
12494
+ }),
12495
+ versions: {
12496
+ [compatibility_GpVersion.V0_7_0]: descriptors_codec.Class(statistics_ServiceStatistics, {
12497
+ providedCount: codecVarU16,
12498
+ providedSize: descriptors_codec.varU32,
12499
+ refinementCount: descriptors_codec.varU32,
12500
+ refinementGasUsed: codecVarGas,
12501
+ imports: codecVarU16,
12502
+ extrinsicCount: codecVarU16,
12503
+ extrinsicSize: descriptors_codec.varU32,
12504
+ exports: codecVarU16,
12505
+ accumulateCount: descriptors_codec.varU32,
12506
+ accumulateGasUsed: codecVarGas,
12507
+ onTransfersCount: descriptors_codec.varU32,
12508
+ onTransfersGasUsed: codecVarGas,
12509
+ }),
12510
+ [compatibility_GpVersion.V0_7_1]: descriptors_codec.Class(statistics_ServiceStatistics, {
12511
+ providedCount: codecVarU16,
12512
+ providedSize: descriptors_codec.varU32,
12513
+ refinementCount: descriptors_codec.varU32,
12514
+ refinementGasUsed: codecVarGas,
12515
+ imports: codecVarU16,
12516
+ extrinsicCount: codecVarU16,
12517
+ extrinsicSize: descriptors_codec.varU32,
12518
+ exports: codecVarU16,
12519
+ accumulateCount: descriptors_codec.varU32,
12520
+ accumulateGasUsed: codecVarGas,
12521
+ onTransfersCount: ignoreValueWithDefault(numbers_tryAsU32(0)),
12522
+ onTransfersGasUsed: ignoreValueWithDefault(common_tryAsServiceGas(0)),
12523
+ }),
12524
+ },
12525
+ });
12526
+ static create(v) {
12527
+ return new statistics_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);
12528
+ }
12529
+ constructor(
12530
+ /** `p.0` */
12531
+ providedCount,
12532
+ /** `p.1` */
12533
+ providedSize,
12534
+ /** `r.0` */
12535
+ refinementCount,
12536
+ /** `r.1` */
12537
+ refinementGasUsed,
12538
+ /** `i` */
12539
+ imports,
12540
+ /** `e` */
12541
+ exports,
12542
+ /** `z` */
12543
+ extrinsicSize,
12544
+ /** `x` */
12545
+ extrinsicCount,
12546
+ /** `a.0` */
12547
+ accumulateCount,
12548
+ /** `a.1` */
12549
+ accumulateGasUsed,
12550
+ /** `t.0` @deprecated since 0.7.1 */
12551
+ onTransfersCount,
12552
+ /** `t.1` @deprecated since 0.7.1 */
12553
+ onTransfersGasUsed) {
12554
+ this.providedCount = providedCount;
12555
+ this.providedSize = providedSize;
12556
+ this.refinementCount = refinementCount;
12557
+ this.refinementGasUsed = refinementGasUsed;
12558
+ this.imports = imports;
12559
+ this.exports = exports;
12560
+ this.extrinsicSize = extrinsicSize;
12561
+ this.extrinsicCount = extrinsicCount;
12562
+ this.accumulateCount = accumulateCount;
12563
+ this.accumulateGasUsed = accumulateGasUsed;
12564
+ this.onTransfersCount = onTransfersCount;
12565
+ this.onTransfersGasUsed = onTransfersGasUsed;
12669
12566
  }
12670
- static create({ serviceId, serviceInfo, lookupHistory, }) {
12671
- return new state_update_UpdateService(serviceId, {
12672
- kind: state_update_UpdateServiceKind.Create,
12673
- account: serviceInfo,
12674
- lookupHistory,
12675
- });
12567
+ static empty() {
12568
+ const zero = numbers_tryAsU32(0);
12569
+ const zero16 = numbers_tryAsU16(0);
12570
+ const zeroGas = common_tryAsServiceGas(0);
12571
+ return new statistics_ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
12676
12572
  }
12677
12573
  }
12678
- /** Update service storage kind. */
12679
- var state_update_UpdateStorageKind;
12680
- (function (UpdateStorageKind) {
12681
- /** Set a storage value. */
12682
- UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
12683
- /** Remove a storage value. */
12684
- UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
12685
- })(state_update_UpdateStorageKind || (state_update_UpdateStorageKind = {}));
12686
- /**
12687
- * Update service storage item.
12688
- *
12689
- * Can either create/modify an entry or remove it.
12690
- */
12691
- class state_update_UpdateStorage {
12692
- serviceId;
12693
- action;
12694
- constructor(serviceId, action) {
12695
- this.serviceId = serviceId;
12696
- this.action = action;
12697
- }
12698
- static set({ serviceId, storage }) {
12699
- return new state_update_UpdateStorage(serviceId, { kind: state_update_UpdateStorageKind.Set, storage });
12700
- }
12701
- static remove({ serviceId, key }) {
12702
- return new state_update_UpdateStorage(serviceId, { kind: state_update_UpdateStorageKind.Remove, key });
12703
- }
12704
- get key() {
12705
- if (this.action.kind === state_update_UpdateStorageKind.Remove) {
12706
- return this.action.key;
12707
- }
12708
- return this.action.storage.key;
12574
+ /** `pi`: Statistics of each validator, cores statistics and services statistics. */
12575
+ class statistics_StatisticsData {
12576
+ current;
12577
+ previous;
12578
+ cores;
12579
+ services;
12580
+ static Codec = descriptors_codec.Class(statistics_StatisticsData, {
12581
+ current: codecPerValidator(statistics_ValidatorStatistics.Codec),
12582
+ previous: codecPerValidator(statistics_ValidatorStatistics.Codec),
12583
+ cores: codecPerCore(CoreStatistics.Codec),
12584
+ services: descriptors_codec.dictionary(codecServiceId, statistics_ServiceStatistics.Codec, {
12585
+ sortKeys: (a, b) => a - b,
12586
+ }),
12587
+ });
12588
+ static create(v) {
12589
+ return new statistics_StatisticsData(v.current, v.previous, v.cores, v.services);
12709
12590
  }
12710
- get value() {
12711
- if (this.action.kind === state_update_UpdateStorageKind.Remove) {
12712
- return null;
12713
- }
12714
- return this.action.storage.value;
12591
+ constructor(current, previous, cores, services) {
12592
+ this.current = current;
12593
+ this.previous = previous;
12594
+ this.cores = cores;
12595
+ this.services = services;
12715
12596
  }
12716
12597
  }
12717
12598
 
@@ -12736,7 +12617,6 @@ class state_update_UpdateStorage {
12736
12617
 
12737
12618
 
12738
12619
 
12739
-
12740
12620
 
12741
12621
 
12742
12622
  var in_memory_state_UpdateError;
@@ -12838,10 +12718,9 @@ class InMemoryService extends WithDebug {
12838
12718
  * A special version of state, stored fully in-memory.
12839
12719
  */
12840
12720
  class InMemoryState extends WithDebug {
12841
- chainSpec;
12842
12721
  /** Create a new `InMemoryState` by providing all required fields. */
12843
- static new(chainSpec, state) {
12844
- return new InMemoryState(chainSpec, state);
12722
+ static create(state) {
12723
+ return new InMemoryState(state);
12845
12724
  }
12846
12725
  /**
12847
12726
  * Create a new `InMemoryState` with a partial state override.
@@ -12857,7 +12736,7 @@ class InMemoryState extends WithDebug {
12857
12736
  /**
12858
12737
  * Create a new `InMemoryState` from some other state object.
12859
12738
  */
12860
- static copyFrom(chainSpec, other, servicesData) {
12739
+ static copyFrom(other, servicesData) {
12861
12740
  const services = new Map();
12862
12741
  for (const [id, entries] of servicesData.entries()) {
12863
12742
  const service = other.getService(id);
@@ -12867,7 +12746,7 @@ class InMemoryState extends WithDebug {
12867
12746
  const inMemService = InMemoryService.copyFrom(service, entries);
12868
12747
  services.set(id, inMemService);
12869
12748
  }
12870
- return InMemoryState.new(chainSpec, {
12749
+ return InMemoryState.create({
12871
12750
  availabilityAssignment: other.availabilityAssignment,
12872
12751
  accumulationQueue: other.accumulationQueue,
12873
12752
  designatedValidatorData: other.designatedValidatorData,
@@ -13064,9 +12943,8 @@ class InMemoryState extends WithDebug {
13064
12943
  getService(id) {
13065
12944
  return this.services.get(id) ?? null;
13066
12945
  }
13067
- constructor(chainSpec, s) {
12946
+ constructor(s) {
13068
12947
  super();
13069
- this.chainSpec = chainSpec;
13070
12948
  this.availabilityAssignment = s.availabilityAssignment;
13071
12949
  this.designatedValidatorData = s.designatedValidatorData;
13072
12950
  this.nextValidatorData = s.nextValidatorData;
@@ -13088,14 +12966,11 @@ class InMemoryState extends WithDebug {
13088
12966
  this.accumulationOutputLog = s.accumulationOutputLog;
13089
12967
  this.services = s.services;
13090
12968
  }
13091
- view() {
13092
- return new InMemoryStateView(this.chainSpec, this);
13093
- }
13094
12969
  /**
13095
12970
  * Create an empty and possibly incoherent `InMemoryState`.
13096
12971
  */
13097
12972
  static empty(spec) {
13098
- return new InMemoryState(spec, {
12973
+ return new InMemoryState({
13099
12974
  availabilityAssignment: common_tryAsPerCore(Array.from({ length: spec.coresCount }, () => null), spec),
13100
12975
  designatedValidatorData: common_tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
13101
12976
  bandersnatch: bytes_Bytes.zero(bandersnatch_BANDERSNATCH_KEY_BYTES).asOpaque(),
@@ -13130,8 +13005,8 @@ class InMemoryState extends WithDebug {
13130
13005
  timeslot: common_tryAsTimeSlot(0),
13131
13006
  entropy: sized_array_FixedSizeArray.fill(() => bytes_Bytes.zero(hash_HASH_SIZE).asOpaque(), ENTROPY_ENTRIES),
13132
13007
  authPools: common_tryAsPerCore(Array.from({ length: spec.coresCount }, () => sized_array_asKnownSize([])), spec),
13133
- authQueues: common_tryAsPerCore(Array.from({ length: spec.coresCount }, () => sized_array_FixedSizeArray.fill(() => bytes_Bytes.zero(hash_HASH_SIZE).asOpaque(), auth_AUTHORIZATION_QUEUE_SIZE)), spec),
13134
- recentBlocks: recent_blocks_RecentBlocks.empty(),
13008
+ authQueues: common_tryAsPerCore(Array.from({ length: spec.coresCount }, () => sized_array_FixedSizeArray.fill(() => bytes_Bytes.zero(hash_HASH_SIZE).asOpaque(), gp_constants_AUTHORIZATION_QUEUE_SIZE)), spec),
13009
+ recentBlocks: recent_blocks_RecentBlocksHistory.empty(),
13135
13010
  statistics: statistics_StatisticsData.create({
13136
13011
  current: common_tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => statistics_ValidatorStatistics.empty()), spec),
13137
13012
  previous: common_tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => statistics_ValidatorStatistics.empty()), spec),
@@ -13182,10 +13057,6 @@ const serviceDataCodec = descriptors_codec.dictionary(descriptors_codec.u32.asOp
13182
13057
 
13183
13058
 
13184
13059
 
13185
-
13186
-
13187
-
13188
-
13189
13060
  ;// CONCATENATED MODULE: ./packages/jam/state-json/accounts.ts
13190
13061
 
13191
13062
 
@@ -13357,6 +13228,51 @@ const accumulationOutput = json.object({
13357
13228
  output: fromJson.bytes32(),
13358
13229
  }, ({ serviceId, output }) => AccumulationOutput.create({ serviceId, output }));
13359
13230
 
13231
+ ;// CONCATENATED MODULE: ./packages/jam/state/not-yet-accumulated.ts
13232
+
13233
+
13234
+
13235
+
13236
+
13237
+
13238
+ /**
13239
+ * Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
13240
+ *
13241
+ * https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
13242
+ */
13243
+ class not_yet_accumulated_NotYetAccumulatedReport extends WithDebug {
13244
+ report;
13245
+ dependencies;
13246
+ static Codec = descriptors_codec.Class(not_yet_accumulated_NotYetAccumulatedReport, {
13247
+ report: work_report_WorkReport.Codec,
13248
+ dependencies: codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
13249
+ typicalLength: gp_constants_MAX_REPORT_DEPENDENCIES / 2,
13250
+ maxLength: gp_constants_MAX_REPORT_DEPENDENCIES,
13251
+ minLength: 0,
13252
+ }),
13253
+ });
13254
+ static create({ report, dependencies }) {
13255
+ return new not_yet_accumulated_NotYetAccumulatedReport(report, dependencies);
13256
+ }
13257
+ constructor(
13258
+ /**
13259
+ * Each of these were made available at most one epoch ago
13260
+ * but have or had unfulfilled dependencies.
13261
+ */
13262
+ report,
13263
+ /**
13264
+ * Alongside the work-report itself, we retain its un-accumulated
13265
+ * dependencies, a set of work-package hashes.
13266
+ *
13267
+ * https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
13268
+ */
13269
+ dependencies) {
13270
+ super();
13271
+ this.report = report;
13272
+ this.dependencies = dependencies;
13273
+ }
13274
+ }
13275
+
13360
13276
  ;// CONCATENATED MODULE: ./packages/jam/state-json/not-yet-accumulated.ts
13361
13277
 
13362
13278
 
@@ -13364,7 +13280,7 @@ const accumulationOutput = json.object({
13364
13280
  const notYetAccumulatedFromJson = json.object({
13365
13281
  report: workReportFromJson,
13366
13282
  dependencies: json.array(fromJson.bytes32()),
13367
- }, ({ report, dependencies }) => accumulation_queue_NotYetAccumulatedReport.create({ report, dependencies }));
13283
+ }, ({ report, dependencies }) => not_yet_accumulated_NotYetAccumulatedReport.create({ report, dependencies }));
13368
13284
 
13369
13285
  ;// CONCATENATED MODULE: ./packages/jam/state-json/recent-history.ts
13370
13286
 
@@ -13397,10 +13313,10 @@ const recentBlocksHistoryFromJson = json.object({
13397
13313
  peaks: json.array(json.nullable(fromJson.bytes32())),
13398
13314
  },
13399
13315
  }, ({ history, mmr }) => {
13400
- return recent_blocks_RecentBlocks.create({
13316
+ return recent_blocks_RecentBlocksHistory.create(recent_blocks_RecentBlocks.create({
13401
13317
  blocks: history,
13402
13318
  accumulationLog: mmr,
13403
- });
13319
+ }));
13404
13320
  });
13405
13321
 
13406
13322
  ;// CONCATENATED MODULE: ./packages/jam/state-json/safrole.ts
@@ -13598,6 +13514,7 @@ const validatorDataFromJson = json.object({
13598
13514
 
13599
13515
 
13600
13516
 
13517
+
13601
13518
  const fullStateDumpFromJson = (spec) => json.object({
13602
13519
  alpha: json.array(json.array(fromJson.bytes32())),
13603
13520
  varphi: json.array(json.array(fromJson.bytes32())),
@@ -13634,20 +13551,20 @@ const fullStateDumpFromJson = (spec) => json.object({
13634
13551
  if (compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1) && chi.chi_r === undefined) {
13635
13552
  throw new Error("Registrar is required in Privileges GP ^0.7.1");
13636
13553
  }
13637
- return InMemoryState.new(spec, {
13554
+ return InMemoryState.create({
13638
13555
  authPools: common_tryAsPerCore(alpha.map((perCore) => {
13639
- if (perCore.length > auth_MAX_AUTH_POOL_SIZE) {
13640
- throw new Error(`AuthPools: expected less than ${auth_MAX_AUTH_POOL_SIZE}, got ${perCore.length}`);
13556
+ if (perCore.length > gp_constants_MAX_AUTH_POOL_SIZE) {
13557
+ throw new Error(`AuthPools: expected less than ${gp_constants_MAX_AUTH_POOL_SIZE}, got ${perCore.length}`);
13641
13558
  }
13642
13559
  return sized_array_asKnownSize(perCore);
13643
13560
  }), spec),
13644
13561
  authQueues: common_tryAsPerCore(varphi.map((perCore) => {
13645
- if (perCore.length !== auth_AUTHORIZATION_QUEUE_SIZE) {
13646
- throw new Error(`AuthQueues: expected ${auth_AUTHORIZATION_QUEUE_SIZE}, got: ${perCore.length}`);
13562
+ if (perCore.length !== gp_constants_AUTHORIZATION_QUEUE_SIZE) {
13563
+ throw new Error(`AuthQueues: expected ${gp_constants_AUTHORIZATION_QUEUE_SIZE}, got: ${perCore.length}`);
13647
13564
  }
13648
13565
  return sized_array_asKnownSize(perCore);
13649
13566
  }), spec),
13650
- recentBlocks: beta ?? recent_blocks_RecentBlocks.empty(),
13567
+ recentBlocks: beta ?? recent_blocks_RecentBlocksHistory.empty(),
13651
13568
  nextValidatorData: gamma.gamma_k,
13652
13569
  epochRoot: gamma.gamma_z,
13653
13570
  sealingKeySeries: TicketsOrKeys.toSafroleSealingKeys(gamma.gamma_s, spec),
@@ -13861,19 +13778,26 @@ function legacyServiceNested(serviceId, hash) {
13861
13778
 
13862
13779
 
13863
13780
 
13781
+
13782
+
13783
+
13864
13784
  /** Serialization for particular state entries. */
13865
13785
  var serialize_serialize;
13866
13786
  (function (serialize) {
13867
13787
  /** C(1): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b15013b1501?v=0.6.7 */
13868
13788
  serialize.authPools = {
13869
13789
  key: stateKeys.index(StateKeyIdx.Alpha),
13870
- Codec: authPoolsCodec,
13790
+ Codec: codecPerCore(codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
13791
+ minLength: 0,
13792
+ maxLength: gp_constants_MAX_AUTH_POOL_SIZE,
13793
+ typicalLength: gp_constants_MAX_AUTH_POOL_SIZE,
13794
+ })),
13871
13795
  extract: (s) => s.authPools,
13872
13796
  };
13873
13797
  /** C(2): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b31013b3101?v=0.6.7 */
13874
13798
  serialize.authQueues = {
13875
13799
  key: stateKeys.index(StateKeyIdx.Phi),
13876
- Codec: authQueuesCodec,
13800
+ Codec: codecPerCore(codecFixedSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), gp_constants_AUTHORIZATION_QUEUE_SIZE)),
13877
13801
  extract: (s) => s.authQueues,
13878
13802
  };
13879
13803
  /**
@@ -13882,7 +13806,7 @@ var serialize_serialize;
13882
13806
  */
13883
13807
  serialize.recentBlocks = {
13884
13808
  key: stateKeys.index(StateKeyIdx.Beta),
13885
- Codec: recent_blocks_RecentBlocks.Codec,
13809
+ Codec: recent_blocks_RecentBlocksHistory.Codec,
13886
13810
  extract: (s) => s.recentBlocks,
13887
13811
  };
13888
13812
  /** C(4): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b63013b6301?v=0.6.7 */
@@ -13911,25 +13835,25 @@ var serialize_serialize;
13911
13835
  /** C(7): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b00023b0002?v=0.6.7 */
13912
13836
  serialize.designatedValidators = {
13913
13837
  key: stateKeys.index(StateKeyIdx.Iota),
13914
- Codec: validatorsDataCodec,
13838
+ Codec: codecPerValidator(validator_data_ValidatorData.Codec),
13915
13839
  extract: (s) => s.designatedValidatorData,
13916
13840
  };
13917
13841
  /** C(8): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b0d023b0d02?v=0.6.7 */
13918
13842
  serialize.currentValidators = {
13919
13843
  key: stateKeys.index(StateKeyIdx.Kappa),
13920
- Codec: validatorsDataCodec,
13844
+ Codec: codecPerValidator(validator_data_ValidatorData.Codec),
13921
13845
  extract: (s) => s.currentValidatorData,
13922
13846
  };
13923
13847
  /** C(9): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b1a023b1a02?v=0.6.7 */
13924
13848
  serialize.previousValidators = {
13925
13849
  key: stateKeys.index(StateKeyIdx.Lambda),
13926
- Codec: validatorsDataCodec,
13850
+ Codec: codecPerValidator(validator_data_ValidatorData.Codec),
13927
13851
  extract: (s) => s.previousValidatorData,
13928
13852
  };
13929
13853
  /** C(10): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b27023b2702?v=0.6.7 */
13930
13854
  serialize.availabilityAssignment = {
13931
13855
  key: stateKeys.index(StateKeyIdx.Rho),
13932
- Codec: availabilityAssignmentsCodec,
13856
+ Codec: codecPerCore(descriptors_codec.optional(assurances_AvailabilityAssignment.Codec)),
13933
13857
  extract: (s) => s.availabilityAssignment,
13934
13858
  };
13935
13859
  /** C(11): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b3e023b3e02?v=0.6.7 */
@@ -13953,13 +13877,13 @@ var serialize_serialize;
13953
13877
  /** C(14): https://graypaper.fluffylabs.dev/#/1c979cb/3bf0023bf002?v=0.7.1 */
13954
13878
  serialize.accumulationQueue = {
13955
13879
  key: stateKeys.index(StateKeyIdx.Omega),
13956
- Codec: accumulationQueueCodec,
13880
+ Codec: codecPerEpochBlock(readonlyArray(descriptors_codec.sequenceVarLen(not_yet_accumulated_NotYetAccumulatedReport.Codec))),
13957
13881
  extract: (s) => s.accumulationQueue,
13958
13882
  };
13959
13883
  /** C(15): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b96023b9602?v=0.6.7 */
13960
13884
  serialize.recentlyAccumulated = {
13961
13885
  key: stateKeys.index(StateKeyIdx.Xi),
13962
- Codec: recentlyAccumulatedCodec,
13886
+ Codec: codecPerEpochBlock(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque()).convert((x) => Array.from(x), (x) => hash_set_HashSet.from(x))),
13963
13887
  extract: (s) => s.recentlyAccumulated,
13964
13888
  };
13965
13889
  /** C(16): https://graypaper.fluffylabs.dev/#/38c4e62/3b46033b4603?v=0.7.0 */
@@ -13978,12 +13902,12 @@ var serialize_serialize;
13978
13902
  /** https://graypaper.fluffylabs.dev/#/85129da/384803384803?v=0.6.3 */
13979
13903
  serialize.serviceStorage = (blake2b, serviceId, key) => ({
13980
13904
  key: stateKeys.serviceStorage(blake2b, serviceId, key),
13981
- Codec: dumpCodec,
13905
+ Codec: serialize_dumpCodec,
13982
13906
  });
13983
13907
  /** https://graypaper.fluffylabs.dev/#/85129da/385b03385b03?v=0.6.3 */
13984
13908
  serialize.servicePreimages = (blake2b, serviceId, hash) => ({
13985
13909
  key: stateKeys.servicePreimage(blake2b, serviceId, hash),
13986
- Codec: dumpCodec,
13910
+ Codec: serialize_dumpCodec,
13987
13911
  });
13988
13912
  /** https://graypaper.fluffylabs.dev/#/85129da/387603387603?v=0.6.3 */
13989
13913
  serialize.serviceLookupHistory = (blake2b, serviceId, hash, len) => ({
@@ -13998,88 +13922,7 @@ var serialize_serialize;
13998
13922
  * determine the boundary of the bytes, so it can only be used
13999
13923
  * as the last element of the codec and can't be used in sequences!
14000
13924
  */
14001
- 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()));
14002
-
14003
- ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state-view.ts
14004
-
14005
-
14006
- class SerializedStateView {
14007
- spec;
14008
- backend;
14009
- recentlyUsedServices;
14010
- viewCache;
14011
- constructor(spec, backend,
14012
- /** Best-effort list of recently active services. */
14013
- recentlyUsedServices, viewCache) {
14014
- this.spec = spec;
14015
- this.backend = backend;
14016
- this.recentlyUsedServices = recentlyUsedServices;
14017
- this.viewCache = viewCache;
14018
- }
14019
- retrieveView({ key, Codec }, description) {
14020
- const cached = this.viewCache.get(key);
14021
- if (cached !== undefined) {
14022
- return cached;
14023
- }
14024
- const bytes = this.backend.get(key);
14025
- if (bytes === null) {
14026
- throw new Error(`Required state entry for ${description} is missing!. Accessing view of key: ${key}`);
14027
- }
14028
- // NOTE [ToDr] we are not using `Decoder.decodeObject` here because
14029
- // it needs to get to the end of the data (skip), yet that's expensive.
14030
- // we assume that the state data is correct and coherent anyway, so
14031
- // for performance reasons we simply create the view here.
14032
- const d = decoder_Decoder.fromBytesBlob(bytes);
14033
- d.attachContext(this.spec);
14034
- const view = Codec.View.decode(d);
14035
- this.viewCache.set(key, view);
14036
- return view;
14037
- }
14038
- availabilityAssignmentView() {
14039
- return this.retrieveView(serialize_serialize.availabilityAssignment, "availabilityAssignmentView");
14040
- }
14041
- designatedValidatorDataView() {
14042
- return this.retrieveView(serialize_serialize.designatedValidators, "designatedValidatorsView");
14043
- }
14044
- currentValidatorDataView() {
14045
- return this.retrieveView(serialize_serialize.currentValidators, "currentValidatorsView");
14046
- }
14047
- previousValidatorDataView() {
14048
- return this.retrieveView(serialize_serialize.previousValidators, "previousValidatorsView");
14049
- }
14050
- authPoolsView() {
14051
- return this.retrieveView(serialize_serialize.authPools, "authPoolsView");
14052
- }
14053
- authQueuesView() {
14054
- return this.retrieveView(serialize_serialize.authQueues, "authQueuesView");
14055
- }
14056
- recentBlocksView() {
14057
- return this.retrieveView(serialize_serialize.recentBlocks, "recentBlocksView");
14058
- }
14059
- statisticsView() {
14060
- return this.retrieveView(serialize_serialize.statistics, "statisticsView");
14061
- }
14062
- accumulationQueueView() {
14063
- return this.retrieveView(serialize_serialize.accumulationQueue, "accumulationQueueView");
14064
- }
14065
- recentlyAccumulatedView() {
14066
- return this.retrieveView(serialize_serialize.recentlyAccumulated, "recentlyAccumulatedView");
14067
- }
14068
- safroleDataView() {
14069
- return this.retrieveView(serialize_serialize.safrole, "safroleDataView");
14070
- }
14071
- getServiceInfoView(id) {
14072
- const serviceData = serialize_serialize.serviceData(id);
14073
- const bytes = this.backend.get(serviceData.key);
14074
- if (bytes === null) {
14075
- return null;
14076
- }
14077
- if (!this.recentlyUsedServices.includes(id)) {
14078
- this.recentlyUsedServices.push(id);
14079
- }
14080
- return decoder_Decoder.decodeObject(serviceData.Codec.View, bytes, this.spec);
14081
- }
14082
- }
13925
+ const serialize_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()));
14083
13926
 
14084
13927
  ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
14085
13928
 
@@ -14089,8 +13932,6 @@ class SerializedStateView {
14089
13932
 
14090
13933
 
14091
13934
 
14092
-
14093
-
14094
13935
  /**
14095
13936
  * State object which reads it's entries from some backend.
14096
13937
  *
@@ -14103,7 +13944,7 @@ class serialized_state_SerializedState {
14103
13944
  spec;
14104
13945
  blake2b;
14105
13946
  backend;
14106
- recentlyUsedServices;
13947
+ _recentServiceIds;
14107
13948
  /** Create a state-like object from collection of serialized entries. */
14108
13949
  static fromStateEntries(spec, blake2b, state, recentServices = []) {
14109
13950
  return new serialized_state_SerializedState(spec, blake2b, state, recentServices);
@@ -14112,63 +13953,49 @@ class serialized_state_SerializedState {
14112
13953
  static new(spec, blake2b, db, recentServices = []) {
14113
13954
  return new serialized_state_SerializedState(spec, blake2b, db, recentServices);
14114
13955
  }
14115
- dataCache = hash_dictionary_HashDictionary.new();
14116
- viewCache = hash_dictionary_HashDictionary.new();
14117
13956
  constructor(spec, blake2b, backend,
14118
13957
  /** Best-effort list of recently active services. */
14119
- recentlyUsedServices) {
13958
+ _recentServiceIds) {
14120
13959
  this.spec = spec;
14121
13960
  this.blake2b = blake2b;
14122
13961
  this.backend = backend;
14123
- this.recentlyUsedServices = recentlyUsedServices;
13962
+ this._recentServiceIds = _recentServiceIds;
14124
13963
  }
14125
13964
  /** Comparing the serialized states, just means comparing their backends. */
14126
13965
  [TEST_COMPARE_USING]() {
14127
13966
  return this.backend;
14128
13967
  }
14129
- /** Return a non-decoding version of the state. */
14130
- view() {
14131
- return new SerializedStateView(this.spec, this.backend, this.recentlyUsedServices, this.viewCache);
14132
- }
14133
13968
  // TODO [ToDr] Temporary method to update the state,
14134
13969
  // without changing references.
14135
13970
  updateBackend(newBackend) {
14136
13971
  this.backend = newBackend;
14137
- this.dataCache = hash_dictionary_HashDictionary.new();
14138
- this.viewCache = hash_dictionary_HashDictionary.new();
14139
13972
  }
14140
13973
  recentServiceIds() {
14141
- return this.recentlyUsedServices;
13974
+ return this._recentServiceIds;
14142
13975
  }
14143
13976
  getService(id) {
14144
13977
  const serviceData = this.retrieveOptional(serialize_serialize.serviceData(id));
14145
13978
  if (serviceData === undefined) {
14146
13979
  return null;
14147
13980
  }
14148
- if (!this.recentlyUsedServices.includes(id)) {
14149
- this.recentlyUsedServices.push(id);
13981
+ if (!this._recentServiceIds.includes(id)) {
13982
+ this._recentServiceIds.push(id);
14150
13983
  }
14151
13984
  return new SerializedService(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
14152
13985
  }
14153
- retrieve(k, description) {
14154
- const data = this.retrieveOptional(k);
14155
- if (data === undefined) {
14156
- throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${k.key}`);
13986
+ retrieve({ key, Codec }, description) {
13987
+ const bytes = this.backend.get(key);
13988
+ if (bytes === null) {
13989
+ throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${key}`);
14157
13990
  }
14158
- return data;
13991
+ return decoder_Decoder.decodeObject(Codec, bytes, this.spec);
14159
13992
  }
14160
13993
  retrieveOptional({ key, Codec }) {
14161
- const cached = this.dataCache.get(key);
14162
- if (cached !== undefined) {
14163
- return cached;
14164
- }
14165
13994
  const bytes = this.backend.get(key);
14166
13995
  if (bytes === null) {
14167
13996
  return undefined;
14168
13997
  }
14169
- const data = decoder_Decoder.decodeObject(Codec, bytes, this.spec);
14170
- this.dataCache.set(key, data);
14171
- return data;
13998
+ return decoder_Decoder.decodeObject(Codec, bytes, this.spec);
14172
13999
  }
14173
14000
  get availabilityAssignment() {
14174
14001
  return this.retrieve(serialize_serialize.availabilityAssignment, "availabilityAssignment");
@@ -15283,7 +15110,6 @@ function loader_loadState(spec, blake2b, entries) {
15283
15110
 
15284
15111
 
15285
15112
 
15286
-
15287
15113
  ;// CONCATENATED MODULE: ./packages/jam/state-merkleization/in-memory-state-codec.ts
15288
15114
 
15289
15115
 
@@ -15388,11 +15214,7 @@ class ServiceWithCodec extends InMemoryService {
15388
15214
  return new ServiceWithCodec(serviceId, data);
15389
15215
  }
15390
15216
  }
15391
- const in_memory_state_codec_inMemoryStateCodec = (spec) => descriptors_codec.Class(class State extends InMemoryState {
15392
- static create(data) {
15393
- return InMemoryState.new(spec, data);
15394
- }
15395
- }, {
15217
+ const in_memory_state_codec_inMemoryStateCodec = descriptors_codec.Class(InMemoryState, {
15396
15218
  // alpha
15397
15219
  authPools: serialize_serialize.authPools.Codec,
15398
15220
  // phi
@@ -15628,7 +15450,7 @@ class InMemoryStates {
15628
15450
  }
15629
15451
  /** Insert a full state into the database. */
15630
15452
  async insertState(headerHash, state) {
15631
- const encoded = Encoder.encodeObject(inMemoryStateCodec(this.spec), state, this.spec);
15453
+ const encoded = Encoder.encodeObject(inMemoryStateCodec, state, this.spec);
15632
15454
  this.db.set(headerHash, encoded);
15633
15455
  return Result.ok(OK);
15634
15456
  }
@@ -15637,7 +15459,7 @@ class InMemoryStates {
15637
15459
  if (encodedState === undefined) {
15638
15460
  return null;
15639
15461
  }
15640
- return Decoder.decodeObject(inMemoryStateCodec(this.spec), encodedState, this.spec);
15462
+ return Decoder.decodeObject(inMemoryStateCodec, encodedState, this.spec);
15641
15463
  }
15642
15464
  }
15643
15465
 
@@ -15680,21 +15502,21 @@ class hasher_TransitionHasher {
15680
15502
  */
15681
15503
  extrinsic(extrinsicView) {
15682
15504
  // https://graypaper.fluffylabs.dev/#/cc517d7/0cfb000cfb00?v=0.6.5
15683
- const guaranteesCount = tryAsU32(extrinsicView.guarantees.view().length);
15684
- const countEncoded = Encoder.encodeObject(codec.varU32, guaranteesCount);
15685
- const guaranteesBlobs = extrinsicView.guarantees
15505
+ const guarantees = extrinsicView.guarantees
15686
15506
  .view()
15687
15507
  .map((g) => g.view())
15688
- .reduce((aggregated, guarantee) => {
15508
+ .map((guarantee) => {
15689
15509
  const reportHash = this.blake2b.hashBytes(guarantee.report.encoded()).asOpaque();
15690
- aggregated.push(reportHash.raw);
15691
- aggregated.push(guarantee.slot.encoded().raw);
15692
- aggregated.push(guarantee.credentials.encoded().raw);
15693
- return aggregated;
15694
- }, [countEncoded.raw]);
15510
+ return BytesBlob.blobFromParts([
15511
+ reportHash.raw,
15512
+ guarantee.slot.encoded().raw,
15513
+ guarantee.credentials.encoded().raw,
15514
+ ]);
15515
+ });
15516
+ const guaranteeBlob = Encoder.encodeObject(codec.sequenceVarLen(dumpCodec), guarantees, this.context);
15695
15517
  const et = this.blake2b.hashBytes(extrinsicView.tickets.encoded()).asOpaque();
15696
15518
  const ep = this.blake2b.hashBytes(extrinsicView.preimages.encoded()).asOpaque();
15697
- const eg = this.blake2b.hashBlobs(guaranteesBlobs).asOpaque();
15519
+ const eg = this.blake2b.hashBytes(guaranteeBlob).asOpaque();
15698
15520
  const ea = this.blake2b.hashBytes(extrinsicView.assurances.encoded()).asOpaque();
15699
15521
  const ed = this.blake2b.hashBytes(extrinsicView.disputes.encoded()).asOpaque();
15700
15522
  const encoded = BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);
@@ -16817,46 +16639,47 @@ class safrole_seal_SafroleSeal {
16817
16639
  }
16818
16640
  async verifySeal(headerView, state) {
16819
16641
  // we use transitioned keys already
16642
+ const validators = state.currentValidatorData;
16820
16643
  const validatorIndex = headerView.bandersnatchBlockAuthorIndex.materialize();
16821
- const authorKeys = state.currentValidatorData.at(validatorIndex);
16822
- if (authorKeys === undefined) {
16644
+ const authorKey = validators[validatorIndex];
16645
+ if (authorKey === undefined) {
16823
16646
  return Result.error(SafroleSealError.InvalidValidatorIndex);
16824
16647
  }
16825
16648
  const timeSlot = headerView.timeSlotIndex.materialize();
16826
16649
  const sealingKeys = state.sealingKeySeries;
16827
16650
  const entropy = state.currentEntropy;
16828
16651
  if (sealingKeys.kind === SafroleSealingKeysKind.Tickets) {
16829
- return await this.verifySealWithTicket(sealingKeys.tickets, timeSlot, entropy, authorKeys, headerView);
16652
+ return await this.verifySealWithTicket(sealingKeys.tickets, timeSlot, entropy, validators, validatorIndex, headerView);
16830
16653
  }
16831
- return await this.verifySealWithKeys(sealingKeys.keys, timeSlot, entropy, authorKeys, headerView);
16654
+ return await this.verifySealWithKeys(sealingKeys.keys, authorKey, timeSlot, entropy, validators, validatorIndex, headerView);
16832
16655
  }
16833
16656
  /** Regular (non-fallback) mode of Safrole. */
16834
- async verifySealWithTicket(tickets, timeSlot, entropy, validatorData, headerView) {
16657
+ async verifySealWithTicket(tickets, timeSlot, entropy, validators, validatorIndex, headerView) {
16835
16658
  const index = timeSlot % tickets.length;
16836
- const ticket = tickets.at(index);
16837
- const payload = BytesBlob.blobFromParts(JAM_TICKET_SEAL, entropy.raw, new Uint8Array([ticket?.attempt ?? 0]));
16659
+ const { id, attempt } = tickets[index];
16660
+ const payload = BytesBlob.blobFromParts(JAM_TICKET_SEAL, entropy.raw, new Uint8Array([attempt]));
16838
16661
  // verify seal correctness
16839
- const authorKey = validatorData.bandersnatch;
16662
+ const authorKey = validators.at(validatorIndex)?.bandersnatch;
16840
16663
  const result = await bandersnatchVrf.verifySeal(await this.bandersnatch, authorKey ?? BANDERSNATCH_ZERO_KEY, headerView.seal.materialize(), payload, encodeUnsealedHeader(headerView));
16841
16664
  if (result.isError) {
16842
16665
  return Result.error(SafroleSealError.IncorrectSeal);
16843
16666
  }
16844
- if (ticket === undefined || !ticket.id.isEqualTo(result.ok)) {
16667
+ if (!id.isEqualTo(result.ok)) {
16845
16668
  return Result.error(SafroleSealError.InvalidTicket);
16846
16669
  }
16847
16670
  return Result.ok(result.ok);
16848
16671
  }
16849
16672
  /** Fallback mode of Safrole. */
16850
- async verifySealWithKeys(keys, timeSlot, entropy, authorKey, headerView) {
16673
+ async verifySealWithKeys(keys, authorKey, timeSlot, entropy, validators, validatorIndex, headerView) {
16851
16674
  const index = timeSlot % keys.length;
16852
- const sealingKey = keys.at(index);
16853
- const authorBandersnatchKey = authorKey.bandersnatch;
16854
- if (sealingKey === undefined || !sealingKey.isEqualTo(authorBandersnatchKey)) {
16675
+ const sealingKey = keys[index];
16676
+ if (!sealingKey.isEqualTo(authorKey.bandersnatch)) {
16855
16677
  return Result.error(SafroleSealError.InvalidValidator, `Invalid Validator. Expected: ${sealingKey}, got: ${authorKey.bandersnatch}`);
16856
16678
  }
16857
16679
  // verify seal correctness
16858
16680
  const payload = BytesBlob.blobFromParts(JAM_FALLBACK_SEAL, entropy.raw);
16859
- const result = await bandersnatchVrf.verifySeal(await this.bandersnatch, authorBandersnatchKey, headerView.seal.materialize(), payload, encodeUnsealedHeader(headerView));
16681
+ const blockAuthorKey = validators.at(validatorIndex)?.bandersnatch;
16682
+ const result = await bandersnatchVrf.verifySeal(await this.bandersnatch, blockAuthorKey ?? BANDERSNATCH_ZERO_KEY, headerView.seal.materialize(), payload, encodeUnsealedHeader(headerView));
16860
16683
  if (result.isError) {
16861
16684
  return Result.error(SafroleSealError.IncorrectSeal);
16862
16685
  }
@@ -22735,7 +22558,7 @@ class Assign {
22735
22558
  const authorizationQueueStart = regs.get(8);
22736
22559
  // a
22737
22560
  const assigners = getServiceId(regs.get(9));
22738
- const res = safe_alloc_uint8array_safeAllocUint8Array(hash_HASH_SIZE * auth_AUTHORIZATION_QUEUE_SIZE);
22561
+ const res = safe_alloc_uint8array_safeAllocUint8Array(hash_HASH_SIZE * gp_constants_AUTHORIZATION_QUEUE_SIZE);
22739
22562
  const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
22740
22563
  // error while reading the memory.
22741
22564
  if (memoryReadResult.isError) {
@@ -22749,8 +22572,8 @@ class Assign {
22749
22572
  // NOTE: Here we know the core index is valid
22750
22573
  const coreIndex = common_tryAsCoreIndex(Number(maybeCoreIndex));
22751
22574
  const decoder = decoder_Decoder.fromBlob(res);
22752
- const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), auth_AUTHORIZATION_QUEUE_SIZE);
22753
- const fixedSizeAuthQueue = sized_array_FixedSizeArray.new(authQueue, auth_AUTHORIZATION_QUEUE_SIZE);
22575
+ const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE), gp_constants_AUTHORIZATION_QUEUE_SIZE);
22576
+ const fixedSizeAuthQueue = sized_array_FixedSizeArray.new(authQueue, gp_constants_AUTHORIZATION_QUEUE_SIZE);
22754
22577
  const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
22755
22578
  if (result.isOk) {
22756
22579
  regs.set(IN_OUT_REG, results_HostCallResult.OK);
@@ -24496,10 +24319,9 @@ class accumulate_Accumulate {
24496
24319
  const recentlyAccumulated = tryAsPerEpochBlock(newRecentlyAccumulated, this.chainSpec);
24497
24320
  const accumulationQueue = this.state.accumulationQueue.slice();
24498
24321
  accumulationQueue[phaseIndex] = pruneQueue(toAccumulateLater, accumulatedSet);
24499
- const timeslot = this.state.timeslot;
24500
24322
  for (let i = 1; i < epochLength; i++) {
24501
24323
  const queueIndex = (phaseIndex + epochLength - i) % epochLength;
24502
- if (i < slot - timeslot) {
24324
+ if (i < slot - this.state.timeslot) {
24503
24325
  accumulationQueue[queueIndex] = [];
24504
24326
  }
24505
24327
  else {
@@ -24711,6 +24533,7 @@ class deferred_transfers_DeferredTransfers {
24711
24533
 
24712
24534
 
24713
24535
 
24536
+
24714
24537
  /**
24715
24538
  * Maintain a list of available authorizations per core.
24716
24539
  *
@@ -24739,12 +24562,11 @@ class authorization_Authorization {
24739
24562
  */
24740
24563
  transition(input) {
24741
24564
  const authPoolsUpdate = this.state.authPools.slice();
24742
- const authQueues = this.state.authQueues;
24743
24565
  // we transition authorizations for each core.
24744
24566
  for (let coreIndex = tryAsCoreIndex(0); coreIndex < this.chainSpec.coresCount; coreIndex++) {
24745
24567
  let pool = authPoolsUpdate[coreIndex].slice();
24746
24568
  // the queue is only read (we should most likely use `ArrayView` here).
24747
- const queue = authQueues[coreIndex];
24569
+ const queue = this.state.authQueues[coreIndex];
24748
24570
  // if there were any used hashes - remove them
24749
24571
  const usedHashes = input.used.get(coreIndex);
24750
24572
  if (usedHashes !== undefined) {
@@ -24918,18 +24740,14 @@ class recent_history_RecentHistory {
24918
24740
  * https://graypaper.fluffylabs.dev/#/1c979cb/0f55020f5502?v=0.7.1
24919
24741
  */
24920
24742
  partialTransition(input) {
24921
- const stateBlocks = this.state.recentBlocks;
24922
- const recentBlocks = stateBlocks.blocks.slice();
24743
+ const recentBlocks = this.state.recentBlocks.blocks.slice();
24923
24744
  const lastState = recentBlocks.length > 0 ? recentBlocks[recentBlocks.length - 1] : null;
24924
24745
  // update the posterior root of previous state.
24925
24746
  if (lastState !== null) {
24926
24747
  lastState.postStateRoot = input.priorStateRoot;
24927
24748
  }
24928
24749
  return {
24929
- recentBlocks: RecentBlocks.create({
24930
- blocks: asKnownSize(recentBlocks),
24931
- accumulationLog: stateBlocks.accumulationLog,
24932
- }), // β_H†
24750
+ recentBlocks: this.state.recentBlocks.updateBlocks(recentBlocks), // β_H†
24933
24751
  };
24934
24752
  }
24935
24753
  /**
@@ -24941,8 +24759,8 @@ class recent_history_RecentHistory {
24941
24759
  transition(input) {
24942
24760
  const recentBlocks = input.partial.recentBlocks.blocks.slice();
24943
24761
  // `β′_B`
24944
- const mmr = this.state.recentBlocks.accumulationLog !== null
24945
- ? MerkleMountainRange.fromPeaks(this.hasher, this.state.recentBlocks.accumulationLog)
24762
+ const mmr = this.state.recentBlocks.asCurrent().accumulationLog !== null
24763
+ ? MerkleMountainRange.fromPeaks(this.hasher, this.state.recentBlocks.asCurrent().accumulationLog)
24946
24764
  : MerkleMountainRange.empty(this.hasher);
24947
24765
  // append the accumulation root
24948
24766
  mmr.append(input.accumulateRoot);
@@ -24960,7 +24778,7 @@ class recent_history_RecentHistory {
24960
24778
  }
24961
24779
  // write back to the state.
24962
24780
  return {
24963
- recentBlocks: RecentBlocks.create(RecentBlocks.create({
24781
+ recentBlocks: RecentBlocksHistory.create(RecentBlocks.create({
24964
24782
  blocks: asKnownSize(recentBlocks),
24965
24783
  accumulationLog: peaks,
24966
24784
  })),
@@ -25172,6 +24990,7 @@ function verify_basic_verifyReportsBasic(input) {
25172
24990
 
25173
24991
 
25174
24992
 
24993
+
25175
24994
  const verify_contextual_logger = Logger.new(import.meta.filename, "stf:reports");
25176
24995
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/15eb0115eb01?v=0.6.7 */
25177
24996
  function verify_contextual_verifyContextualValidity(input, state, headerChain, maxLookupAnchorAge) {
@@ -25284,7 +25103,7 @@ function verifyRefineContexts(minLookupSlot, contexts, recentBlocksPartialUpdate
25284
25103
  return Result.error(ReportsError.BadStateRoot, `Anchor state root mismatch. Got: ${context.stateRoot}, expected: ${recentBlock.postStateRoot}.`);
25285
25104
  }
25286
25105
  // check beefy root
25287
- const beefyRoot = recentBlock.accumulationResult;
25106
+ const beefyRoot = RecentBlocksHistory.accumulationResult(recentBlock);
25288
25107
  if (!beefyRoot.isEqualTo(context.beefyRoot)) {
25289
25108
  return Result.error(ReportsError.BadBeefyMmrRoot, `Invalid BEEFY super peak hash. Got: ${context.beefyRoot}, expected: ${beefyRoot}. Anchor: ${recentBlock.headerHash}`);
25290
25109
  }
@@ -25526,9 +25345,8 @@ function verify_post_signature_verifyPostSignatureChecks(input, availabilityAssi
25526
25345
  * https://graypaper.fluffylabs.dev/#/5f542d7/15eb0015ed00
25527
25346
  */
25528
25347
  const authorizerHash = report.authorizerHash;
25529
- const authorizerPool = authPools.get(coreIndex);
25530
- const pool = authorizerPool?.materialize() ?? [];
25531
- if (pool.find((hash) => hash.isEqualTo(authorizerHash)) === undefined) {
25348
+ const authorizerPool = authPools[coreIndex];
25349
+ if (authorizerPool.find((hash) => hash.isEqualTo(authorizerHash)) === undefined) {
25532
25350
  return Result.error(ReportsError.CoreUnauthorized, `Authorizer hash not found in the pool of core ${coreIndex}: ${authorizerHash}`);
25533
25351
  }
25534
25352
  /**
@@ -25658,8 +25476,7 @@ class reports_Reports {
25658
25476
  return verifyCredentials(input.guarantees, workReportHashes, input.slot, (headerTimeSlot, guaranteeTimeSlot) => this.getGuarantorAssignment(headerTimeSlot, guaranteeTimeSlot, input.newEntropy));
25659
25477
  }
25660
25478
  verifyPostSignatureChecks(input, assurancesAvailAssignment) {
25661
- const authPoolsView = this.state.view().authPoolsView();
25662
- return verifyPostSignatureChecks(input, assurancesAvailAssignment, authPoolsView, (id) => this.state.getService(id));
25479
+ return verifyPostSignatureChecks(input, assurancesAvailAssignment, this.state.authPools, (id) => this.state.getService(id));
25663
25480
  }
25664
25481
  verifyContextualValidity(input) {
25665
25482
  return verifyContextualValidity(input, this.state, this.headerChain, this.chainSpec.maxLookupAnchorAge);
@@ -27221,20 +27038,18 @@ function dumpOutput(spec, data, type, outputFormat, args, withRelPath) {
27221
27038
  if (type.encode === undefined) {
27222
27039
  throw new Error(`${type.name} does not support encoding to JAM codec.`);
27223
27040
  }
27224
- const encoder = typeof type.encode === "function" ? type.encode(spec) : type.encode;
27225
- const encoded = encoder_Encoder.encodeObject(encoder, data, spec);
27041
+ const encoded = encoder_Encoder.encodeObject(type.encode, data, spec);
27226
27042
  dump(`${encoded}`);
27227
27043
  return;
27228
27044
  }
27229
27045
  case OutputFormat.Bin: {
27230
- if (destination === null) {
27231
- throw new Error(`${OutputFormat.Bin} requires destination file.`);
27232
- }
27233
27046
  if (type.encode === undefined) {
27234
27047
  throw new Error(`${type.name} does not support encoding to JAM codec.`);
27235
27048
  }
27236
- const encoder = typeof type.encode === "function" ? type.encode(spec) : type.encode;
27237
- const encoded = encoder_Encoder.encodeObject(encoder, data, spec);
27049
+ if (destination === null) {
27050
+ throw new Error(`${OutputFormat.Bin} requires destination file.`);
27051
+ }
27052
+ const encoded = encoder_Encoder.encodeObject(type.encode, data, spec);
27238
27053
  dump(encoded.raw);
27239
27054
  return;
27240
27055
  }
@@ -27341,8 +27156,7 @@ async function loadAndProcessDataFile(file, withRelPath, flavor, decodeType, pro
27341
27156
  if (decodeType.decode === undefined) {
27342
27157
  throw new Error(`${decodeType.name} does not support decoding from binary data.`);
27343
27158
  }
27344
- const decoder = typeof decodeType.decode === "function" ? decodeType.decode(spec) : decodeType.decode;
27345
- data = decoder_Decoder.decodeObject(decoder, input.data, spec);
27159
+ data = decoder_Decoder.decodeObject(decodeType.decode, input.data, spec);
27346
27160
  }
27347
27161
  else if (input.type === "json") {
27348
27162
  if (decodeType.json === undefined) {