@typeberry/convert 0.2.0-b6e3410 → 0.2.0-e767e74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1003 -817
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -6319,6 +6319,9 @@ 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
|
+
}
|
|
6322
6325
|
}
|
|
6323
6326
|
/**
|
|
6324
6327
|
* A lazy-evaluated decoder of a sequence.
|
|
@@ -6613,7 +6616,15 @@ var descriptors_codec;
|
|
|
6613
6616
|
/** Custom encoding / decoding logic. */
|
|
6614
6617
|
codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
|
|
6615
6618
|
/** Choose a descriptor depending on the encoding/decoding context. */
|
|
6616
|
-
codec.select = ({ name, sizeHint, }, chooser) =>
|
|
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
|
+
};
|
|
6617
6628
|
/**
|
|
6618
6629
|
* A descriptor for a more complex POJO.
|
|
6619
6630
|
*
|
|
@@ -10052,6 +10063,19 @@ function block_emptyBlock(slot = tryAsTimeSlot(0)) {
|
|
|
10052
10063
|
});
|
|
10053
10064
|
}
|
|
10054
10065
|
|
|
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
|
+
|
|
10055
10079
|
;// CONCATENATED MODULE: ./packages/jam/block/index.ts
|
|
10056
10080
|
|
|
10057
10081
|
|
|
@@ -10070,6 +10094,7 @@ function block_emptyBlock(slot = tryAsTimeSlot(0)) {
|
|
|
10070
10094
|
|
|
10071
10095
|
|
|
10072
10096
|
|
|
10097
|
+
|
|
10073
10098
|
;// CONCATENATED MODULE: ./packages/core/json-parser/parse.ts
|
|
10074
10099
|
const NO_KEY = Symbol("no key");
|
|
10075
10100
|
/** Given already parsed JSON, parse & validate it further to match the expected `jsonDescription` type. */
|
|
@@ -11438,10 +11463,128 @@ function accumulation_output_accumulationOutputComparator(a, b) {
|
|
|
11438
11463
|
return Ordering.Equal;
|
|
11439
11464
|
}
|
|
11440
11465
|
|
|
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
|
+
|
|
11441
11583
|
;// CONCATENATED MODULE: ./packages/jam/state/assurances.ts
|
|
11442
11584
|
|
|
11443
11585
|
|
|
11444
11586
|
|
|
11587
|
+
|
|
11445
11588
|
/**
|
|
11446
11589
|
* Assignment of particular work report to a core.
|
|
11447
11590
|
*
|
|
@@ -11470,21 +11613,24 @@ class assurances_AvailabilityAssignment extends WithDebug {
|
|
|
11470
11613
|
this.timeout = timeout;
|
|
11471
11614
|
}
|
|
11472
11615
|
}
|
|
11616
|
+
const availabilityAssignmentsCodec = codecPerCore(descriptors_codec.optional(assurances_AvailabilityAssignment.Codec));
|
|
11617
|
+
|
|
11618
|
+
;// CONCATENATED MODULE: ./packages/jam/state/auth.ts
|
|
11473
11619
|
|
|
11474
|
-
;// CONCATENATED MODULE: ./packages/jam/state/common.ts
|
|
11475
11620
|
|
|
11476
11621
|
|
|
11477
|
-
|
|
11478
|
-
|
|
11479
|
-
|
|
11480
|
-
|
|
11481
|
-
|
|
11482
|
-
|
|
11483
|
-
|
|
11484
|
-
|
|
11485
|
-
|
|
11486
|
-
|
|
11487
|
-
});
|
|
11622
|
+
|
|
11623
|
+
|
|
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));
|
|
11488
11634
|
|
|
11489
11635
|
;// CONCATENATED MODULE: ./packages/jam/state/disputes.ts
|
|
11490
11636
|
|
|
@@ -11552,65 +11698,6 @@ function disputes_hashComparator(a, b) {
|
|
|
11552
11698
|
return a.compare(b);
|
|
11553
11699
|
}
|
|
11554
11700
|
|
|
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
|
-
|
|
11614
11701
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
|
|
11615
11702
|
const math_consts_MAX_VALUE = 4294967295;
|
|
11616
11703
|
const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
|
|
@@ -11618,7 +11705,7 @@ const math_consts_MIN_VALUE = (/* unused pure expression or super */ null && (-(
|
|
|
11618
11705
|
const math_consts_MAX_SHIFT_U32 = 32;
|
|
11619
11706
|
const math_consts_MAX_SHIFT_U64 = 64n;
|
|
11620
11707
|
|
|
11621
|
-
;// CONCATENATED MODULE: ./packages/jam/state/
|
|
11708
|
+
;// CONCATENATED MODULE: ./packages/jam/state/recent-blocks.ts
|
|
11622
11709
|
|
|
11623
11710
|
|
|
11624
11711
|
|
|
@@ -11626,30 +11713,274 @@ const math_consts_MAX_SHIFT_U64 = 64n;
|
|
|
11626
11713
|
|
|
11627
11714
|
|
|
11628
11715
|
/**
|
|
11629
|
-
* `
|
|
11630
|
-
*
|
|
11631
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
11632
|
-
*/
|
|
11633
|
-
const service_BASE_SERVICE_BALANCE = 100n;
|
|
11634
|
-
/**
|
|
11635
|
-
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
11716
|
+
* `H = 8`: The size of recent history, in blocks.
|
|
11636
11717
|
*
|
|
11637
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
11718
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/416300416500
|
|
11638
11719
|
*/
|
|
11639
|
-
const
|
|
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
|
+
}
|
|
11640
11752
|
/**
|
|
11641
|
-
*
|
|
11753
|
+
* Recent history of blocks.
|
|
11642
11754
|
*
|
|
11643
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/
|
|
11755
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
|
|
11644
11756
|
*/
|
|
11645
|
-
|
|
11646
|
-
|
|
11647
|
-
|
|
11648
|
-
|
|
11649
|
-
|
|
11650
|
-
|
|
11651
|
-
|
|
11652
|
-
|
|
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
|
|
11969
|
+
*/
|
|
11970
|
+
const service_ELECTIVE_ITEM_BALANCE = 10n;
|
|
11971
|
+
/**
|
|
11972
|
+
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
11973
|
+
*
|
|
11974
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
11975
|
+
*/
|
|
11976
|
+
const service_ELECTIVE_BYTE_BALANCE = 1n;
|
|
11977
|
+
const zeroSizeHint = {
|
|
11978
|
+
bytes: 0,
|
|
11979
|
+
isExact: true,
|
|
11980
|
+
};
|
|
11981
|
+
/** 0-byte read, return given default value */
|
|
11982
|
+
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
11983
|
+
/** Encode and decode object with leading version number. */
|
|
11653
11984
|
const codecWithVersion = (val) => Descriptor.new("withVersion", {
|
|
11654
11985
|
bytes: val.sizeHint.bytes + 8,
|
|
11655
11986
|
isExact: false,
|
|
@@ -11802,525 +12133,9 @@ class service_LookupHistoryItem {
|
|
|
11802
12133
|
}
|
|
11803
12134
|
static isRequested(item) {
|
|
11804
12135
|
if ("slots" in item) {
|
|
11805
|
-
return item.slots.length === 0;
|
|
11806
|
-
}
|
|
11807
|
-
return item.length === 0;
|
|
11808
|
-
}
|
|
11809
|
-
}
|
|
11810
|
-
|
|
11811
|
-
;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
|
|
11812
|
-
|
|
11813
|
-
|
|
11814
|
-
|
|
11815
|
-
|
|
11816
|
-
|
|
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(),
|
|
11824
|
-
});
|
|
11825
|
-
static create({ service, gasLimit }) {
|
|
11826
|
-
return new privileged_services_AutoAccumulate(service, gasLimit);
|
|
11827
|
-
}
|
|
11828
|
-
constructor(
|
|
11829
|
-
/** Service id that auto-accumulates. */
|
|
11830
|
-
service,
|
|
11831
|
-
/** Gas limit for auto-accumulation. */
|
|
11832
|
-
gasLimit) {
|
|
11833
|
-
this.service = service;
|
|
11834
|
-
this.gasLimit = gasLimit;
|
|
11835
|
-
}
|
|
11836
|
-
}
|
|
11837
|
-
/**
|
|
11838
|
-
* https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
|
|
11839
|
-
*/
|
|
11840
|
-
class privileged_services_PrivilegedServices {
|
|
11841
|
-
manager;
|
|
11842
|
-
delegator;
|
|
11843
|
-
registrar;
|
|
11844
|
-
assigners;
|
|
11845
|
-
autoAccumulateServices;
|
|
11846
|
-
/** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
|
|
11847
|
-
static Codec = descriptors_codec.Class(privileged_services_PrivilegedServices, {
|
|
11848
|
-
manager: descriptors_codec.u32.asOpaque(),
|
|
11849
|
-
assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
|
|
11850
|
-
delegator: descriptors_codec.u32.asOpaque(),
|
|
11851
|
-
registrar: compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1)
|
|
11852
|
-
? descriptors_codec.u32.asOpaque()
|
|
11853
|
-
: ignoreValueWithDefault(common_tryAsServiceId(2 ** 32 - 1)),
|
|
11854
|
-
autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(privileged_services_AutoAccumulate.Codec)),
|
|
11855
|
-
});
|
|
11856
|
-
static create(a) {
|
|
11857
|
-
return new privileged_services_PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
11858
|
-
}
|
|
11859
|
-
constructor(
|
|
11860
|
-
/**
|
|
11861
|
-
* `χ_M`: Manages alteration of χ from block to block,
|
|
11862
|
-
* as well as bestow services with storage deposit credits.
|
|
11863
|
-
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
11864
|
-
*/
|
|
11865
|
-
manager,
|
|
11866
|
-
/** `χ_V`: Managers validator keys. */
|
|
11867
|
-
delegator,
|
|
11868
|
-
/**
|
|
11869
|
-
* `χ_R`: Manages the creation of services in protected range.
|
|
11870
|
-
*
|
|
11871
|
-
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
|
|
11872
|
-
*/
|
|
11873
|
-
registrar,
|
|
11874
|
-
/** `χ_A`: Manages authorization queue one for each core. */
|
|
11875
|
-
assigners,
|
|
11876
|
-
/** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
|
|
11877
|
-
autoAccumulateServices) {
|
|
11878
|
-
this.manager = manager;
|
|
11879
|
-
this.delegator = delegator;
|
|
11880
|
-
this.registrar = registrar;
|
|
11881
|
-
this.assigners = assigners;
|
|
11882
|
-
this.autoAccumulateServices = autoAccumulateServices;
|
|
11883
|
-
}
|
|
11884
|
-
}
|
|
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
|
-
|
|
12166
|
-
;// CONCATENATED MODULE: ./packages/jam/state/state.ts
|
|
12167
|
-
/**
|
|
12168
|
-
* In addition to the entropy accumulator η_0, we retain
|
|
12169
|
-
* three additional historical values of the accumulator at
|
|
12170
|
-
* the point of each of the three most recently ended epochs,
|
|
12171
|
-
* η_1, η_2 and η_3. The second-oldest of these η2 is utilized to
|
|
12172
|
-
* help ensure future entropy is unbiased (see equation 6.29)
|
|
12173
|
-
* and seed the fallback seal-key generation function with
|
|
12174
|
-
* randomness (see equation 6.24). The oldest is used to re-
|
|
12175
|
-
* generate this randomness when verifying the seal above
|
|
12176
|
-
* (see equations 6.16 and 6.15).
|
|
12177
|
-
*
|
|
12178
|
-
* https://graypaper.fluffylabs.dev/#/579bd12/0ef5010ef501
|
|
12179
|
-
*/
|
|
12180
|
-
const ENTROPY_ENTRIES = 4;
|
|
12181
|
-
|
|
12182
|
-
;// CONCATENATED MODULE: ./packages/jam/state/state-update.ts
|
|
12183
|
-
|
|
12184
|
-
|
|
12185
|
-
var state_update_UpdatePreimageKind;
|
|
12186
|
-
(function (UpdatePreimageKind) {
|
|
12187
|
-
/** Insert new preimage and optionally update it's lookup history. */
|
|
12188
|
-
UpdatePreimageKind[UpdatePreimageKind["Provide"] = 0] = "Provide";
|
|
12189
|
-
/** Remove a preimage and it's lookup history. */
|
|
12190
|
-
UpdatePreimageKind[UpdatePreimageKind["Remove"] = 1] = "Remove";
|
|
12191
|
-
/** update or add lookup history for preimage hash/len to given value. */
|
|
12192
|
-
UpdatePreimageKind[UpdatePreimageKind["UpdateOrAdd"] = 2] = "UpdateOrAdd";
|
|
12193
|
-
})(state_update_UpdatePreimageKind || (state_update_UpdatePreimageKind = {}));
|
|
12194
|
-
/**
|
|
12195
|
-
* A preimage update.
|
|
12196
|
-
*
|
|
12197
|
-
* Can be one of the following cases:
|
|
12198
|
-
* 1. Provide a new preimage blob and set the lookup history to available at `slot`.
|
|
12199
|
-
* 2. Remove (expunge) a preimage and it's lookup history.
|
|
12200
|
-
* 3. Update `LookupHistory` with given value.
|
|
12201
|
-
*/
|
|
12202
|
-
class state_update_UpdatePreimage {
|
|
12203
|
-
serviceId;
|
|
12204
|
-
action;
|
|
12205
|
-
constructor(serviceId, action) {
|
|
12206
|
-
this.serviceId = serviceId;
|
|
12207
|
-
this.action = action;
|
|
12208
|
-
}
|
|
12209
|
-
/** A preimage is provided. We should update the lookuphistory and add the preimage to db. */
|
|
12210
|
-
static provide({ serviceId, preimage, slot, }) {
|
|
12211
|
-
return new state_update_UpdatePreimage(serviceId, {
|
|
12212
|
-
kind: state_update_UpdatePreimageKind.Provide,
|
|
12213
|
-
preimage,
|
|
12214
|
-
slot,
|
|
12215
|
-
});
|
|
12216
|
-
}
|
|
12217
|
-
/** The preimage should be removed completely from the database. */
|
|
12218
|
-
static remove({ serviceId, hash, length }) {
|
|
12219
|
-
return new state_update_UpdatePreimage(serviceId, {
|
|
12220
|
-
kind: state_update_UpdatePreimageKind.Remove,
|
|
12221
|
-
hash,
|
|
12222
|
-
length,
|
|
12223
|
-
});
|
|
12224
|
-
}
|
|
12225
|
-
/** Update the lookup history of some preimage or add a new one (request). */
|
|
12226
|
-
static updateOrAdd({ serviceId, lookupHistory }) {
|
|
12227
|
-
return new state_update_UpdatePreimage(serviceId, {
|
|
12228
|
-
kind: state_update_UpdatePreimageKind.UpdateOrAdd,
|
|
12229
|
-
item: lookupHistory,
|
|
12230
|
-
});
|
|
12231
|
-
}
|
|
12232
|
-
get hash() {
|
|
12233
|
-
switch (this.action.kind) {
|
|
12234
|
-
case state_update_UpdatePreimageKind.Provide:
|
|
12235
|
-
return this.action.preimage.hash;
|
|
12236
|
-
case state_update_UpdatePreimageKind.Remove:
|
|
12237
|
-
return this.action.hash;
|
|
12238
|
-
case state_update_UpdatePreimageKind.UpdateOrAdd:
|
|
12239
|
-
return this.action.item.hash;
|
|
12240
|
-
}
|
|
12241
|
-
throw assertNever(this.action);
|
|
12242
|
-
}
|
|
12243
|
-
get length() {
|
|
12244
|
-
switch (this.action.kind) {
|
|
12245
|
-
case state_update_UpdatePreimageKind.Provide:
|
|
12246
|
-
return tryAsU32(this.action.preimage.blob.length);
|
|
12247
|
-
case state_update_UpdatePreimageKind.Remove:
|
|
12248
|
-
return this.action.length;
|
|
12249
|
-
case state_update_UpdatePreimageKind.UpdateOrAdd:
|
|
12250
|
-
return this.action.item.length;
|
|
12251
|
-
}
|
|
12252
|
-
throw assertNever(this.action);
|
|
12253
|
-
}
|
|
12254
|
-
}
|
|
12255
|
-
/** The type of service update. */
|
|
12256
|
-
var state_update_UpdateServiceKind;
|
|
12257
|
-
(function (UpdateServiceKind) {
|
|
12258
|
-
/** Just update the `ServiceAccountInfo`. */
|
|
12259
|
-
UpdateServiceKind[UpdateServiceKind["Update"] = 0] = "Update";
|
|
12260
|
-
/** Create a new `Service` instance. */
|
|
12261
|
-
UpdateServiceKind[UpdateServiceKind["Create"] = 1] = "Create";
|
|
12262
|
-
})(state_update_UpdateServiceKind || (state_update_UpdateServiceKind = {}));
|
|
12263
|
-
/**
|
|
12264
|
-
* Update service info of a particular `ServiceId` or create a new one.
|
|
12265
|
-
*/
|
|
12266
|
-
class state_update_UpdateService {
|
|
12267
|
-
serviceId;
|
|
12268
|
-
action;
|
|
12269
|
-
constructor(serviceId, action) {
|
|
12270
|
-
this.serviceId = serviceId;
|
|
12271
|
-
this.action = action;
|
|
12272
|
-
}
|
|
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;
|
|
12136
|
+
return item.slots.length === 0;
|
|
12322
12137
|
}
|
|
12323
|
-
return
|
|
12138
|
+
return item.length === 0;
|
|
12324
12139
|
}
|
|
12325
12140
|
}
|
|
12326
12141
|
|
|
@@ -12526,73 +12341,377 @@ class statistics_ServiceStatistics {
|
|
|
12526
12341
|
static create(v) {
|
|
12527
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);
|
|
12528
12343
|
}
|
|
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;
|
|
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;
|
|
12506
|
+
}
|
|
12507
|
+
}
|
|
12508
|
+
/**
|
|
12509
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
|
|
12510
|
+
*/
|
|
12511
|
+
class privileged_services_PrivilegedServices {
|
|
12512
|
+
manager;
|
|
12513
|
+
delegator;
|
|
12514
|
+
registrar;
|
|
12515
|
+
assigners;
|
|
12516
|
+
autoAccumulateServices;
|
|
12517
|
+
/** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
|
|
12518
|
+
static Codec = descriptors_codec.Class(privileged_services_PrivilegedServices, {
|
|
12519
|
+
manager: descriptors_codec.u32.asOpaque(),
|
|
12520
|
+
assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
|
|
12521
|
+
delegator: descriptors_codec.u32.asOpaque(),
|
|
12522
|
+
registrar: compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1)
|
|
12523
|
+
? descriptors_codec.u32.asOpaque()
|
|
12524
|
+
: ignoreValueWithDefault(common_tryAsServiceId(2 ** 32 - 1)),
|
|
12525
|
+
autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(privileged_services_AutoAccumulate.Codec)),
|
|
12526
|
+
});
|
|
12527
|
+
static create(a) {
|
|
12528
|
+
return new privileged_services_PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
12529
|
+
}
|
|
12530
|
+
constructor(
|
|
12531
|
+
/**
|
|
12532
|
+
* `χ_M`: Manages alteration of χ from block to block,
|
|
12533
|
+
* as well as bestow services with storage deposit credits.
|
|
12534
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
12535
|
+
*/
|
|
12536
|
+
manager,
|
|
12537
|
+
/** `χ_V`: Managers validator keys. */
|
|
12538
|
+
delegator,
|
|
12539
|
+
/**
|
|
12540
|
+
* `χ_R`: Manages the creation of services in protected range.
|
|
12541
|
+
*
|
|
12542
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
|
|
12543
|
+
*/
|
|
12544
|
+
registrar,
|
|
12545
|
+
/** `χ_A`: Manages authorization queue one for each core. */
|
|
12546
|
+
assigners,
|
|
12547
|
+
/** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
|
|
12548
|
+
autoAccumulateServices) {
|
|
12549
|
+
this.manager = manager;
|
|
12550
|
+
this.delegator = delegator;
|
|
12551
|
+
this.registrar = registrar;
|
|
12552
|
+
this.assigners = assigners;
|
|
12553
|
+
this.autoAccumulateServices = autoAccumulateServices;
|
|
12554
|
+
}
|
|
12555
|
+
}
|
|
12556
|
+
|
|
12557
|
+
;// CONCATENATED MODULE: ./packages/jam/state/state.ts
|
|
12558
|
+
/**
|
|
12559
|
+
* In addition to the entropy accumulator η_0, we retain
|
|
12560
|
+
* three additional historical values of the accumulator at
|
|
12561
|
+
* the point of each of the three most recently ended epochs,
|
|
12562
|
+
* η_1, η_2 and η_3. The second-oldest of these η2 is utilized to
|
|
12563
|
+
* help ensure future entropy is unbiased (see equation 6.29)
|
|
12564
|
+
* and seed the fallback seal-key generation function with
|
|
12565
|
+
* randomness (see equation 6.24). The oldest is used to re-
|
|
12566
|
+
* generate this randomness when verifying the seal above
|
|
12567
|
+
* (see equations 6.16 and 6.15).
|
|
12568
|
+
*
|
|
12569
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/0ef5010ef501
|
|
12570
|
+
*/
|
|
12571
|
+
const ENTROPY_ENTRIES = 4;
|
|
12572
|
+
|
|
12573
|
+
;// CONCATENATED MODULE: ./packages/jam/state/state-update.ts
|
|
12574
|
+
|
|
12575
|
+
|
|
12576
|
+
var state_update_UpdatePreimageKind;
|
|
12577
|
+
(function (UpdatePreimageKind) {
|
|
12578
|
+
/** Insert new preimage and optionally update it's lookup history. */
|
|
12579
|
+
UpdatePreimageKind[UpdatePreimageKind["Provide"] = 0] = "Provide";
|
|
12580
|
+
/** Remove a preimage and it's lookup history. */
|
|
12581
|
+
UpdatePreimageKind[UpdatePreimageKind["Remove"] = 1] = "Remove";
|
|
12582
|
+
/** update or add lookup history for preimage hash/len to given value. */
|
|
12583
|
+
UpdatePreimageKind[UpdatePreimageKind["UpdateOrAdd"] = 2] = "UpdateOrAdd";
|
|
12584
|
+
})(state_update_UpdatePreimageKind || (state_update_UpdatePreimageKind = {}));
|
|
12585
|
+
/**
|
|
12586
|
+
* A preimage update.
|
|
12587
|
+
*
|
|
12588
|
+
* Can be one of the following cases:
|
|
12589
|
+
* 1. Provide a new preimage blob and set the lookup history to available at `slot`.
|
|
12590
|
+
* 2. Remove (expunge) a preimage and it's lookup history.
|
|
12591
|
+
* 3. Update `LookupHistory` with given value.
|
|
12592
|
+
*/
|
|
12593
|
+
class state_update_UpdatePreimage {
|
|
12594
|
+
serviceId;
|
|
12595
|
+
action;
|
|
12596
|
+
constructor(serviceId, action) {
|
|
12597
|
+
this.serviceId = serviceId;
|
|
12598
|
+
this.action = action;
|
|
12599
|
+
}
|
|
12600
|
+
/** A preimage is provided. We should update the lookuphistory and add the preimage to db. */
|
|
12601
|
+
static provide({ serviceId, preimage, slot, }) {
|
|
12602
|
+
return new state_update_UpdatePreimage(serviceId, {
|
|
12603
|
+
kind: state_update_UpdatePreimageKind.Provide,
|
|
12604
|
+
preimage,
|
|
12605
|
+
slot,
|
|
12606
|
+
});
|
|
12607
|
+
}
|
|
12608
|
+
/** The preimage should be removed completely from the database. */
|
|
12609
|
+
static remove({ serviceId, hash, length }) {
|
|
12610
|
+
return new state_update_UpdatePreimage(serviceId, {
|
|
12611
|
+
kind: state_update_UpdatePreimageKind.Remove,
|
|
12612
|
+
hash,
|
|
12613
|
+
length,
|
|
12614
|
+
});
|
|
12615
|
+
}
|
|
12616
|
+
/** Update the lookup history of some preimage or add a new one (request). */
|
|
12617
|
+
static updateOrAdd({ serviceId, lookupHistory }) {
|
|
12618
|
+
return new state_update_UpdatePreimage(serviceId, {
|
|
12619
|
+
kind: state_update_UpdatePreimageKind.UpdateOrAdd,
|
|
12620
|
+
item: lookupHistory,
|
|
12621
|
+
});
|
|
12622
|
+
}
|
|
12623
|
+
get hash() {
|
|
12624
|
+
switch (this.action.kind) {
|
|
12625
|
+
case state_update_UpdatePreimageKind.Provide:
|
|
12626
|
+
return this.action.preimage.hash;
|
|
12627
|
+
case state_update_UpdatePreimageKind.Remove:
|
|
12628
|
+
return this.action.hash;
|
|
12629
|
+
case state_update_UpdatePreimageKind.UpdateOrAdd:
|
|
12630
|
+
return this.action.item.hash;
|
|
12631
|
+
}
|
|
12632
|
+
throw assertNever(this.action);
|
|
12633
|
+
}
|
|
12634
|
+
get length() {
|
|
12635
|
+
switch (this.action.kind) {
|
|
12636
|
+
case state_update_UpdatePreimageKind.Provide:
|
|
12637
|
+
return tryAsU32(this.action.preimage.blob.length);
|
|
12638
|
+
case state_update_UpdatePreimageKind.Remove:
|
|
12639
|
+
return this.action.length;
|
|
12640
|
+
case state_update_UpdatePreimageKind.UpdateOrAdd:
|
|
12641
|
+
return this.action.item.length;
|
|
12642
|
+
}
|
|
12643
|
+
throw assertNever(this.action);
|
|
12566
12644
|
}
|
|
12567
|
-
|
|
12568
|
-
|
|
12569
|
-
|
|
12570
|
-
|
|
12571
|
-
|
|
12645
|
+
}
|
|
12646
|
+
/** The type of service update. */
|
|
12647
|
+
var state_update_UpdateServiceKind;
|
|
12648
|
+
(function (UpdateServiceKind) {
|
|
12649
|
+
/** Just update the `ServiceAccountInfo`. */
|
|
12650
|
+
UpdateServiceKind[UpdateServiceKind["Update"] = 0] = "Update";
|
|
12651
|
+
/** Create a new `Service` instance. */
|
|
12652
|
+
UpdateServiceKind[UpdateServiceKind["Create"] = 1] = "Create";
|
|
12653
|
+
})(state_update_UpdateServiceKind || (state_update_UpdateServiceKind = {}));
|
|
12654
|
+
/**
|
|
12655
|
+
* Update service info of a particular `ServiceId` or create a new one.
|
|
12656
|
+
*/
|
|
12657
|
+
class state_update_UpdateService {
|
|
12658
|
+
serviceId;
|
|
12659
|
+
action;
|
|
12660
|
+
constructor(serviceId, action) {
|
|
12661
|
+
this.serviceId = serviceId;
|
|
12662
|
+
this.action = action;
|
|
12663
|
+
}
|
|
12664
|
+
static update({ serviceId, serviceInfo }) {
|
|
12665
|
+
return new state_update_UpdateService(serviceId, {
|
|
12666
|
+
kind: state_update_UpdateServiceKind.Update,
|
|
12667
|
+
account: serviceInfo,
|
|
12668
|
+
});
|
|
12669
|
+
}
|
|
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
|
+
});
|
|
12572
12676
|
}
|
|
12573
12677
|
}
|
|
12574
|
-
/**
|
|
12575
|
-
|
|
12576
|
-
|
|
12577
|
-
|
|
12578
|
-
|
|
12579
|
-
|
|
12580
|
-
|
|
12581
|
-
|
|
12582
|
-
|
|
12583
|
-
|
|
12584
|
-
|
|
12585
|
-
|
|
12586
|
-
|
|
12587
|
-
|
|
12588
|
-
|
|
12589
|
-
|
|
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;
|
|
12590
12697
|
}
|
|
12591
|
-
|
|
12592
|
-
|
|
12593
|
-
|
|
12594
|
-
|
|
12595
|
-
|
|
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;
|
|
12709
|
+
}
|
|
12710
|
+
get value() {
|
|
12711
|
+
if (this.action.kind === state_update_UpdateStorageKind.Remove) {
|
|
12712
|
+
return null;
|
|
12713
|
+
}
|
|
12714
|
+
return this.action.storage.value;
|
|
12596
12715
|
}
|
|
12597
12716
|
}
|
|
12598
12717
|
|
|
@@ -12617,6 +12736,7 @@ class statistics_StatisticsData {
|
|
|
12617
12736
|
|
|
12618
12737
|
|
|
12619
12738
|
|
|
12739
|
+
|
|
12620
12740
|
|
|
12621
12741
|
|
|
12622
12742
|
var in_memory_state_UpdateError;
|
|
@@ -12718,9 +12838,10 @@ class InMemoryService extends WithDebug {
|
|
|
12718
12838
|
* A special version of state, stored fully in-memory.
|
|
12719
12839
|
*/
|
|
12720
12840
|
class InMemoryState extends WithDebug {
|
|
12841
|
+
chainSpec;
|
|
12721
12842
|
/** Create a new `InMemoryState` by providing all required fields. */
|
|
12722
|
-
static
|
|
12723
|
-
return new InMemoryState(state);
|
|
12843
|
+
static new(chainSpec, state) {
|
|
12844
|
+
return new InMemoryState(chainSpec, state);
|
|
12724
12845
|
}
|
|
12725
12846
|
/**
|
|
12726
12847
|
* Create a new `InMemoryState` with a partial state override.
|
|
@@ -12736,7 +12857,7 @@ class InMemoryState extends WithDebug {
|
|
|
12736
12857
|
/**
|
|
12737
12858
|
* Create a new `InMemoryState` from some other state object.
|
|
12738
12859
|
*/
|
|
12739
|
-
static copyFrom(other, servicesData) {
|
|
12860
|
+
static copyFrom(chainSpec, other, servicesData) {
|
|
12740
12861
|
const services = new Map();
|
|
12741
12862
|
for (const [id, entries] of servicesData.entries()) {
|
|
12742
12863
|
const service = other.getService(id);
|
|
@@ -12746,7 +12867,7 @@ class InMemoryState extends WithDebug {
|
|
|
12746
12867
|
const inMemService = InMemoryService.copyFrom(service, entries);
|
|
12747
12868
|
services.set(id, inMemService);
|
|
12748
12869
|
}
|
|
12749
|
-
return InMemoryState.
|
|
12870
|
+
return InMemoryState.new(chainSpec, {
|
|
12750
12871
|
availabilityAssignment: other.availabilityAssignment,
|
|
12751
12872
|
accumulationQueue: other.accumulationQueue,
|
|
12752
12873
|
designatedValidatorData: other.designatedValidatorData,
|
|
@@ -12943,8 +13064,9 @@ class InMemoryState extends WithDebug {
|
|
|
12943
13064
|
getService(id) {
|
|
12944
13065
|
return this.services.get(id) ?? null;
|
|
12945
13066
|
}
|
|
12946
|
-
constructor(s) {
|
|
13067
|
+
constructor(chainSpec, s) {
|
|
12947
13068
|
super();
|
|
13069
|
+
this.chainSpec = chainSpec;
|
|
12948
13070
|
this.availabilityAssignment = s.availabilityAssignment;
|
|
12949
13071
|
this.designatedValidatorData = s.designatedValidatorData;
|
|
12950
13072
|
this.nextValidatorData = s.nextValidatorData;
|
|
@@ -12966,11 +13088,14 @@ class InMemoryState extends WithDebug {
|
|
|
12966
13088
|
this.accumulationOutputLog = s.accumulationOutputLog;
|
|
12967
13089
|
this.services = s.services;
|
|
12968
13090
|
}
|
|
13091
|
+
view() {
|
|
13092
|
+
return new InMemoryStateView(this.chainSpec, this);
|
|
13093
|
+
}
|
|
12969
13094
|
/**
|
|
12970
13095
|
* Create an empty and possibly incoherent `InMemoryState`.
|
|
12971
13096
|
*/
|
|
12972
13097
|
static empty(spec) {
|
|
12973
|
-
return new InMemoryState({
|
|
13098
|
+
return new InMemoryState(spec, {
|
|
12974
13099
|
availabilityAssignment: common_tryAsPerCore(Array.from({ length: spec.coresCount }, () => null), spec),
|
|
12975
13100
|
designatedValidatorData: common_tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
|
|
12976
13101
|
bandersnatch: bytes_Bytes.zero(bandersnatch_BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
@@ -13005,8 +13130,8 @@ class InMemoryState extends WithDebug {
|
|
|
13005
13130
|
timeslot: common_tryAsTimeSlot(0),
|
|
13006
13131
|
entropy: sized_array_FixedSizeArray.fill(() => bytes_Bytes.zero(hash_HASH_SIZE).asOpaque(), ENTROPY_ENTRIES),
|
|
13007
13132
|
authPools: common_tryAsPerCore(Array.from({ length: spec.coresCount }, () => sized_array_asKnownSize([])), spec),
|
|
13008
|
-
authQueues: common_tryAsPerCore(Array.from({ length: spec.coresCount }, () => sized_array_FixedSizeArray.fill(() => bytes_Bytes.zero(hash_HASH_SIZE).asOpaque(),
|
|
13009
|
-
recentBlocks:
|
|
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(),
|
|
13010
13135
|
statistics: statistics_StatisticsData.create({
|
|
13011
13136
|
current: common_tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => statistics_ValidatorStatistics.empty()), spec),
|
|
13012
13137
|
previous: common_tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => statistics_ValidatorStatistics.empty()), spec),
|
|
@@ -13057,6 +13182,10 @@ const serviceDataCodec = descriptors_codec.dictionary(descriptors_codec.u32.asOp
|
|
|
13057
13182
|
|
|
13058
13183
|
|
|
13059
13184
|
|
|
13185
|
+
|
|
13186
|
+
|
|
13187
|
+
|
|
13188
|
+
|
|
13060
13189
|
;// CONCATENATED MODULE: ./packages/jam/state-json/accounts.ts
|
|
13061
13190
|
|
|
13062
13191
|
|
|
@@ -13228,51 +13357,6 @@ const accumulationOutput = json.object({
|
|
|
13228
13357
|
output: fromJson.bytes32(),
|
|
13229
13358
|
}, ({ serviceId, output }) => AccumulationOutput.create({ serviceId, output }));
|
|
13230
13359
|
|
|
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
|
-
|
|
13276
13360
|
;// CONCATENATED MODULE: ./packages/jam/state-json/not-yet-accumulated.ts
|
|
13277
13361
|
|
|
13278
13362
|
|
|
@@ -13280,7 +13364,7 @@ class not_yet_accumulated_NotYetAccumulatedReport extends WithDebug {
|
|
|
13280
13364
|
const notYetAccumulatedFromJson = json.object({
|
|
13281
13365
|
report: workReportFromJson,
|
|
13282
13366
|
dependencies: json.array(fromJson.bytes32()),
|
|
13283
|
-
}, ({ report, dependencies }) =>
|
|
13367
|
+
}, ({ report, dependencies }) => accumulation_queue_NotYetAccumulatedReport.create({ report, dependencies }));
|
|
13284
13368
|
|
|
13285
13369
|
;// CONCATENATED MODULE: ./packages/jam/state-json/recent-history.ts
|
|
13286
13370
|
|
|
@@ -13313,10 +13397,10 @@ const recentBlocksHistoryFromJson = json.object({
|
|
|
13313
13397
|
peaks: json.array(json.nullable(fromJson.bytes32())),
|
|
13314
13398
|
},
|
|
13315
13399
|
}, ({ history, mmr }) => {
|
|
13316
|
-
return
|
|
13400
|
+
return recent_blocks_RecentBlocks.create({
|
|
13317
13401
|
blocks: history,
|
|
13318
13402
|
accumulationLog: mmr,
|
|
13319
|
-
})
|
|
13403
|
+
});
|
|
13320
13404
|
});
|
|
13321
13405
|
|
|
13322
13406
|
;// CONCATENATED MODULE: ./packages/jam/state-json/safrole.ts
|
|
@@ -13514,7 +13598,6 @@ const validatorDataFromJson = json.object({
|
|
|
13514
13598
|
|
|
13515
13599
|
|
|
13516
13600
|
|
|
13517
|
-
|
|
13518
13601
|
const fullStateDumpFromJson = (spec) => json.object({
|
|
13519
13602
|
alpha: json.array(json.array(fromJson.bytes32())),
|
|
13520
13603
|
varphi: json.array(json.array(fromJson.bytes32())),
|
|
@@ -13551,20 +13634,20 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
13551
13634
|
if (compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_1) && chi.chi_r === undefined) {
|
|
13552
13635
|
throw new Error("Registrar is required in Privileges GP ^0.7.1");
|
|
13553
13636
|
}
|
|
13554
|
-
return InMemoryState.
|
|
13637
|
+
return InMemoryState.new(spec, {
|
|
13555
13638
|
authPools: common_tryAsPerCore(alpha.map((perCore) => {
|
|
13556
|
-
if (perCore.length >
|
|
13557
|
-
throw new Error(`AuthPools: expected less than ${
|
|
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}`);
|
|
13558
13641
|
}
|
|
13559
13642
|
return sized_array_asKnownSize(perCore);
|
|
13560
13643
|
}), spec),
|
|
13561
13644
|
authQueues: common_tryAsPerCore(varphi.map((perCore) => {
|
|
13562
|
-
if (perCore.length !==
|
|
13563
|
-
throw new Error(`AuthQueues: expected ${
|
|
13645
|
+
if (perCore.length !== auth_AUTHORIZATION_QUEUE_SIZE) {
|
|
13646
|
+
throw new Error(`AuthQueues: expected ${auth_AUTHORIZATION_QUEUE_SIZE}, got: ${perCore.length}`);
|
|
13564
13647
|
}
|
|
13565
13648
|
return sized_array_asKnownSize(perCore);
|
|
13566
13649
|
}), spec),
|
|
13567
|
-
recentBlocks: beta ??
|
|
13650
|
+
recentBlocks: beta ?? recent_blocks_RecentBlocks.empty(),
|
|
13568
13651
|
nextValidatorData: gamma.gamma_k,
|
|
13569
13652
|
epochRoot: gamma.gamma_z,
|
|
13570
13653
|
sealingKeySeries: TicketsOrKeys.toSafroleSealingKeys(gamma.gamma_s, spec),
|
|
@@ -13778,26 +13861,19 @@ function legacyServiceNested(serviceId, hash) {
|
|
|
13778
13861
|
|
|
13779
13862
|
|
|
13780
13863
|
|
|
13781
|
-
|
|
13782
|
-
|
|
13783
|
-
|
|
13784
13864
|
/** Serialization for particular state entries. */
|
|
13785
13865
|
var serialize_serialize;
|
|
13786
13866
|
(function (serialize) {
|
|
13787
13867
|
/** C(1): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b15013b1501?v=0.6.7 */
|
|
13788
13868
|
serialize.authPools = {
|
|
13789
13869
|
key: stateKeys.index(StateKeyIdx.Alpha),
|
|
13790
|
-
Codec:
|
|
13791
|
-
minLength: 0,
|
|
13792
|
-
maxLength: gp_constants_MAX_AUTH_POOL_SIZE,
|
|
13793
|
-
typicalLength: gp_constants_MAX_AUTH_POOL_SIZE,
|
|
13794
|
-
})),
|
|
13870
|
+
Codec: authPoolsCodec,
|
|
13795
13871
|
extract: (s) => s.authPools,
|
|
13796
13872
|
};
|
|
13797
13873
|
/** C(2): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b31013b3101?v=0.6.7 */
|
|
13798
13874
|
serialize.authQueues = {
|
|
13799
13875
|
key: stateKeys.index(StateKeyIdx.Phi),
|
|
13800
|
-
Codec:
|
|
13876
|
+
Codec: authQueuesCodec,
|
|
13801
13877
|
extract: (s) => s.authQueues,
|
|
13802
13878
|
};
|
|
13803
13879
|
/**
|
|
@@ -13806,7 +13882,7 @@ var serialize_serialize;
|
|
|
13806
13882
|
*/
|
|
13807
13883
|
serialize.recentBlocks = {
|
|
13808
13884
|
key: stateKeys.index(StateKeyIdx.Beta),
|
|
13809
|
-
Codec:
|
|
13885
|
+
Codec: recent_blocks_RecentBlocks.Codec,
|
|
13810
13886
|
extract: (s) => s.recentBlocks,
|
|
13811
13887
|
};
|
|
13812
13888
|
/** C(4): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b63013b6301?v=0.6.7 */
|
|
@@ -13835,25 +13911,25 @@ var serialize_serialize;
|
|
|
13835
13911
|
/** C(7): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b00023b0002?v=0.6.7 */
|
|
13836
13912
|
serialize.designatedValidators = {
|
|
13837
13913
|
key: stateKeys.index(StateKeyIdx.Iota),
|
|
13838
|
-
Codec:
|
|
13914
|
+
Codec: validatorsDataCodec,
|
|
13839
13915
|
extract: (s) => s.designatedValidatorData,
|
|
13840
13916
|
};
|
|
13841
13917
|
/** C(8): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b0d023b0d02?v=0.6.7 */
|
|
13842
13918
|
serialize.currentValidators = {
|
|
13843
13919
|
key: stateKeys.index(StateKeyIdx.Kappa),
|
|
13844
|
-
Codec:
|
|
13920
|
+
Codec: validatorsDataCodec,
|
|
13845
13921
|
extract: (s) => s.currentValidatorData,
|
|
13846
13922
|
};
|
|
13847
13923
|
/** C(9): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b1a023b1a02?v=0.6.7 */
|
|
13848
13924
|
serialize.previousValidators = {
|
|
13849
13925
|
key: stateKeys.index(StateKeyIdx.Lambda),
|
|
13850
|
-
Codec:
|
|
13926
|
+
Codec: validatorsDataCodec,
|
|
13851
13927
|
extract: (s) => s.previousValidatorData,
|
|
13852
13928
|
};
|
|
13853
13929
|
/** C(10): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b27023b2702?v=0.6.7 */
|
|
13854
13930
|
serialize.availabilityAssignment = {
|
|
13855
13931
|
key: stateKeys.index(StateKeyIdx.Rho),
|
|
13856
|
-
Codec:
|
|
13932
|
+
Codec: availabilityAssignmentsCodec,
|
|
13857
13933
|
extract: (s) => s.availabilityAssignment,
|
|
13858
13934
|
};
|
|
13859
13935
|
/** C(11): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b3e023b3e02?v=0.6.7 */
|
|
@@ -13877,13 +13953,13 @@ var serialize_serialize;
|
|
|
13877
13953
|
/** C(14): https://graypaper.fluffylabs.dev/#/1c979cb/3bf0023bf002?v=0.7.1 */
|
|
13878
13954
|
serialize.accumulationQueue = {
|
|
13879
13955
|
key: stateKeys.index(StateKeyIdx.Omega),
|
|
13880
|
-
Codec:
|
|
13956
|
+
Codec: accumulationQueueCodec,
|
|
13881
13957
|
extract: (s) => s.accumulationQueue,
|
|
13882
13958
|
};
|
|
13883
13959
|
/** C(15): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b96023b9602?v=0.6.7 */
|
|
13884
13960
|
serialize.recentlyAccumulated = {
|
|
13885
13961
|
key: stateKeys.index(StateKeyIdx.Xi),
|
|
13886
|
-
Codec:
|
|
13962
|
+
Codec: recentlyAccumulatedCodec,
|
|
13887
13963
|
extract: (s) => s.recentlyAccumulated,
|
|
13888
13964
|
};
|
|
13889
13965
|
/** C(16): https://graypaper.fluffylabs.dev/#/38c4e62/3b46033b4603?v=0.7.0 */
|
|
@@ -13902,12 +13978,12 @@ var serialize_serialize;
|
|
|
13902
13978
|
/** https://graypaper.fluffylabs.dev/#/85129da/384803384803?v=0.6.3 */
|
|
13903
13979
|
serialize.serviceStorage = (blake2b, serviceId, key) => ({
|
|
13904
13980
|
key: stateKeys.serviceStorage(blake2b, serviceId, key),
|
|
13905
|
-
Codec:
|
|
13981
|
+
Codec: dumpCodec,
|
|
13906
13982
|
});
|
|
13907
13983
|
/** https://graypaper.fluffylabs.dev/#/85129da/385b03385b03?v=0.6.3 */
|
|
13908
13984
|
serialize.servicePreimages = (blake2b, serviceId, hash) => ({
|
|
13909
13985
|
key: stateKeys.servicePreimage(blake2b, serviceId, hash),
|
|
13910
|
-
Codec:
|
|
13986
|
+
Codec: dumpCodec,
|
|
13911
13987
|
});
|
|
13912
13988
|
/** https://graypaper.fluffylabs.dev/#/85129da/387603387603?v=0.6.3 */
|
|
13913
13989
|
serialize.serviceLookupHistory = (blake2b, serviceId, hash, len) => ({
|
|
@@ -13922,7 +13998,88 @@ var serialize_serialize;
|
|
|
13922
13998
|
* determine the boundary of the bytes, so it can only be used
|
|
13923
13999
|
* as the last element of the codec and can't be used in sequences!
|
|
13924
14000
|
*/
|
|
13925
|
-
const
|
|
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
|
+
}
|
|
13926
14083
|
|
|
13927
14084
|
;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
|
|
13928
14085
|
|
|
@@ -13932,6 +14089,8 @@ const serialize_dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }
|
|
|
13932
14089
|
|
|
13933
14090
|
|
|
13934
14091
|
|
|
14092
|
+
|
|
14093
|
+
|
|
13935
14094
|
/**
|
|
13936
14095
|
* State object which reads it's entries from some backend.
|
|
13937
14096
|
*
|
|
@@ -13944,7 +14103,7 @@ class serialized_state_SerializedState {
|
|
|
13944
14103
|
spec;
|
|
13945
14104
|
blake2b;
|
|
13946
14105
|
backend;
|
|
13947
|
-
|
|
14106
|
+
recentlyUsedServices;
|
|
13948
14107
|
/** Create a state-like object from collection of serialized entries. */
|
|
13949
14108
|
static fromStateEntries(spec, blake2b, state, recentServices = []) {
|
|
13950
14109
|
return new serialized_state_SerializedState(spec, blake2b, state, recentServices);
|
|
@@ -13953,49 +14112,63 @@ class serialized_state_SerializedState {
|
|
|
13953
14112
|
static new(spec, blake2b, db, recentServices = []) {
|
|
13954
14113
|
return new serialized_state_SerializedState(spec, blake2b, db, recentServices);
|
|
13955
14114
|
}
|
|
14115
|
+
dataCache = hash_dictionary_HashDictionary.new();
|
|
14116
|
+
viewCache = hash_dictionary_HashDictionary.new();
|
|
13956
14117
|
constructor(spec, blake2b, backend,
|
|
13957
14118
|
/** Best-effort list of recently active services. */
|
|
13958
|
-
|
|
14119
|
+
recentlyUsedServices) {
|
|
13959
14120
|
this.spec = spec;
|
|
13960
14121
|
this.blake2b = blake2b;
|
|
13961
14122
|
this.backend = backend;
|
|
13962
|
-
this.
|
|
14123
|
+
this.recentlyUsedServices = recentlyUsedServices;
|
|
13963
14124
|
}
|
|
13964
14125
|
/** Comparing the serialized states, just means comparing their backends. */
|
|
13965
14126
|
[TEST_COMPARE_USING]() {
|
|
13966
14127
|
return this.backend;
|
|
13967
14128
|
}
|
|
14129
|
+
/** Return a non-decoding version of the state. */
|
|
14130
|
+
view() {
|
|
14131
|
+
return new SerializedStateView(this.spec, this.backend, this.recentlyUsedServices, this.viewCache);
|
|
14132
|
+
}
|
|
13968
14133
|
// TODO [ToDr] Temporary method to update the state,
|
|
13969
14134
|
// without changing references.
|
|
13970
14135
|
updateBackend(newBackend) {
|
|
13971
14136
|
this.backend = newBackend;
|
|
14137
|
+
this.dataCache = hash_dictionary_HashDictionary.new();
|
|
14138
|
+
this.viewCache = hash_dictionary_HashDictionary.new();
|
|
13972
14139
|
}
|
|
13973
14140
|
recentServiceIds() {
|
|
13974
|
-
return this.
|
|
14141
|
+
return this.recentlyUsedServices;
|
|
13975
14142
|
}
|
|
13976
14143
|
getService(id) {
|
|
13977
14144
|
const serviceData = this.retrieveOptional(serialize_serialize.serviceData(id));
|
|
13978
14145
|
if (serviceData === undefined) {
|
|
13979
14146
|
return null;
|
|
13980
14147
|
}
|
|
13981
|
-
if (!this.
|
|
13982
|
-
this.
|
|
14148
|
+
if (!this.recentlyUsedServices.includes(id)) {
|
|
14149
|
+
this.recentlyUsedServices.push(id);
|
|
13983
14150
|
}
|
|
13984
14151
|
return new SerializedService(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
|
|
13985
14152
|
}
|
|
13986
|
-
retrieve(
|
|
13987
|
-
const
|
|
13988
|
-
if (
|
|
13989
|
-
throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${key}`);
|
|
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}`);
|
|
13990
14157
|
}
|
|
13991
|
-
return
|
|
14158
|
+
return data;
|
|
13992
14159
|
}
|
|
13993
14160
|
retrieveOptional({ key, Codec }) {
|
|
14161
|
+
const cached = this.dataCache.get(key);
|
|
14162
|
+
if (cached !== undefined) {
|
|
14163
|
+
return cached;
|
|
14164
|
+
}
|
|
13994
14165
|
const bytes = this.backend.get(key);
|
|
13995
14166
|
if (bytes === null) {
|
|
13996
14167
|
return undefined;
|
|
13997
14168
|
}
|
|
13998
|
-
|
|
14169
|
+
const data = decoder_Decoder.decodeObject(Codec, bytes, this.spec);
|
|
14170
|
+
this.dataCache.set(key, data);
|
|
14171
|
+
return data;
|
|
13999
14172
|
}
|
|
14000
14173
|
get availabilityAssignment() {
|
|
14001
14174
|
return this.retrieve(serialize_serialize.availabilityAssignment, "availabilityAssignment");
|
|
@@ -15110,6 +15283,7 @@ function loader_loadState(spec, blake2b, entries) {
|
|
|
15110
15283
|
|
|
15111
15284
|
|
|
15112
15285
|
|
|
15286
|
+
|
|
15113
15287
|
;// CONCATENATED MODULE: ./packages/jam/state-merkleization/in-memory-state-codec.ts
|
|
15114
15288
|
|
|
15115
15289
|
|
|
@@ -15214,7 +15388,11 @@ class ServiceWithCodec extends InMemoryService {
|
|
|
15214
15388
|
return new ServiceWithCodec(serviceId, data);
|
|
15215
15389
|
}
|
|
15216
15390
|
}
|
|
15217
|
-
const in_memory_state_codec_inMemoryStateCodec = descriptors_codec.Class(InMemoryState
|
|
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
|
+
}, {
|
|
15218
15396
|
// alpha
|
|
15219
15397
|
authPools: serialize_serialize.authPools.Codec,
|
|
15220
15398
|
// phi
|
|
@@ -15450,7 +15628,7 @@ class InMemoryStates {
|
|
|
15450
15628
|
}
|
|
15451
15629
|
/** Insert a full state into the database. */
|
|
15452
15630
|
async insertState(headerHash, state) {
|
|
15453
|
-
const encoded = Encoder.encodeObject(inMemoryStateCodec, state, this.spec);
|
|
15631
|
+
const encoded = Encoder.encodeObject(inMemoryStateCodec(this.spec), state, this.spec);
|
|
15454
15632
|
this.db.set(headerHash, encoded);
|
|
15455
15633
|
return Result.ok(OK);
|
|
15456
15634
|
}
|
|
@@ -15459,7 +15637,7 @@ class InMemoryStates {
|
|
|
15459
15637
|
if (encodedState === undefined) {
|
|
15460
15638
|
return null;
|
|
15461
15639
|
}
|
|
15462
|
-
return Decoder.decodeObject(inMemoryStateCodec, encodedState, this.spec);
|
|
15640
|
+
return Decoder.decodeObject(inMemoryStateCodec(this.spec), encodedState, this.spec);
|
|
15463
15641
|
}
|
|
15464
15642
|
}
|
|
15465
15643
|
|
|
@@ -15502,21 +15680,21 @@ class hasher_TransitionHasher {
|
|
|
15502
15680
|
*/
|
|
15503
15681
|
extrinsic(extrinsicView) {
|
|
15504
15682
|
// https://graypaper.fluffylabs.dev/#/cc517d7/0cfb000cfb00?v=0.6.5
|
|
15505
|
-
const
|
|
15683
|
+
const guaranteesCount = tryAsU32(extrinsicView.guarantees.view().length);
|
|
15684
|
+
const countEncoded = Encoder.encodeObject(codec.varU32, guaranteesCount);
|
|
15685
|
+
const guaranteesBlobs = extrinsicView.guarantees
|
|
15506
15686
|
.view()
|
|
15507
15687
|
.map((g) => g.view())
|
|
15508
|
-
.
|
|
15688
|
+
.reduce((aggregated, guarantee) => {
|
|
15509
15689
|
const reportHash = this.blake2b.hashBytes(guarantee.report.encoded()).asOpaque();
|
|
15510
|
-
|
|
15511
|
-
|
|
15512
|
-
|
|
15513
|
-
|
|
15514
|
-
|
|
15515
|
-
});
|
|
15516
|
-
const guaranteeBlob = Encoder.encodeObject(codec.sequenceVarLen(dumpCodec), guarantees, this.context);
|
|
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]);
|
|
15517
15695
|
const et = this.blake2b.hashBytes(extrinsicView.tickets.encoded()).asOpaque();
|
|
15518
15696
|
const ep = this.blake2b.hashBytes(extrinsicView.preimages.encoded()).asOpaque();
|
|
15519
|
-
const eg = this.blake2b.
|
|
15697
|
+
const eg = this.blake2b.hashBlobs(guaranteesBlobs).asOpaque();
|
|
15520
15698
|
const ea = this.blake2b.hashBytes(extrinsicView.assurances.encoded()).asOpaque();
|
|
15521
15699
|
const ed = this.blake2b.hashBytes(extrinsicView.disputes.encoded()).asOpaque();
|
|
15522
15700
|
const encoded = BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);
|
|
@@ -16639,47 +16817,46 @@ class safrole_seal_SafroleSeal {
|
|
|
16639
16817
|
}
|
|
16640
16818
|
async verifySeal(headerView, state) {
|
|
16641
16819
|
// we use transitioned keys already
|
|
16642
|
-
const validators = state.currentValidatorData;
|
|
16643
16820
|
const validatorIndex = headerView.bandersnatchBlockAuthorIndex.materialize();
|
|
16644
|
-
const
|
|
16645
|
-
if (
|
|
16821
|
+
const authorKeys = state.currentValidatorData.at(validatorIndex);
|
|
16822
|
+
if (authorKeys === undefined) {
|
|
16646
16823
|
return Result.error(SafroleSealError.InvalidValidatorIndex);
|
|
16647
16824
|
}
|
|
16648
16825
|
const timeSlot = headerView.timeSlotIndex.materialize();
|
|
16649
16826
|
const sealingKeys = state.sealingKeySeries;
|
|
16650
16827
|
const entropy = state.currentEntropy;
|
|
16651
16828
|
if (sealingKeys.kind === SafroleSealingKeysKind.Tickets) {
|
|
16652
|
-
return await this.verifySealWithTicket(sealingKeys.tickets, timeSlot, entropy,
|
|
16829
|
+
return await this.verifySealWithTicket(sealingKeys.tickets, timeSlot, entropy, authorKeys, headerView);
|
|
16653
16830
|
}
|
|
16654
|
-
return await this.verifySealWithKeys(sealingKeys.keys,
|
|
16831
|
+
return await this.verifySealWithKeys(sealingKeys.keys, timeSlot, entropy, authorKeys, headerView);
|
|
16655
16832
|
}
|
|
16656
16833
|
/** Regular (non-fallback) mode of Safrole. */
|
|
16657
|
-
async verifySealWithTicket(tickets, timeSlot, entropy,
|
|
16834
|
+
async verifySealWithTicket(tickets, timeSlot, entropy, validatorData, headerView) {
|
|
16658
16835
|
const index = timeSlot % tickets.length;
|
|
16659
|
-
const
|
|
16660
|
-
const payload = BytesBlob.blobFromParts(JAM_TICKET_SEAL, entropy.raw, new Uint8Array([attempt]));
|
|
16836
|
+
const ticket = tickets.at(index);
|
|
16837
|
+
const payload = BytesBlob.blobFromParts(JAM_TICKET_SEAL, entropy.raw, new Uint8Array([ticket?.attempt ?? 0]));
|
|
16661
16838
|
// verify seal correctness
|
|
16662
|
-
const authorKey =
|
|
16839
|
+
const authorKey = validatorData.bandersnatch;
|
|
16663
16840
|
const result = await bandersnatchVrf.verifySeal(await this.bandersnatch, authorKey ?? BANDERSNATCH_ZERO_KEY, headerView.seal.materialize(), payload, encodeUnsealedHeader(headerView));
|
|
16664
16841
|
if (result.isError) {
|
|
16665
16842
|
return Result.error(SafroleSealError.IncorrectSeal);
|
|
16666
16843
|
}
|
|
16667
|
-
if (!id.isEqualTo(result.ok)) {
|
|
16844
|
+
if (ticket === undefined || !ticket.id.isEqualTo(result.ok)) {
|
|
16668
16845
|
return Result.error(SafroleSealError.InvalidTicket);
|
|
16669
16846
|
}
|
|
16670
16847
|
return Result.ok(result.ok);
|
|
16671
16848
|
}
|
|
16672
16849
|
/** Fallback mode of Safrole. */
|
|
16673
|
-
async verifySealWithKeys(keys,
|
|
16850
|
+
async verifySealWithKeys(keys, timeSlot, entropy, authorKey, headerView) {
|
|
16674
16851
|
const index = timeSlot % keys.length;
|
|
16675
|
-
const sealingKey = keys
|
|
16676
|
-
|
|
16852
|
+
const sealingKey = keys.at(index);
|
|
16853
|
+
const authorBandersnatchKey = authorKey.bandersnatch;
|
|
16854
|
+
if (sealingKey === undefined || !sealingKey.isEqualTo(authorBandersnatchKey)) {
|
|
16677
16855
|
return Result.error(SafroleSealError.InvalidValidator, `Invalid Validator. Expected: ${sealingKey}, got: ${authorKey.bandersnatch}`);
|
|
16678
16856
|
}
|
|
16679
16857
|
// verify seal correctness
|
|
16680
16858
|
const payload = BytesBlob.blobFromParts(JAM_FALLBACK_SEAL, entropy.raw);
|
|
16681
|
-
const
|
|
16682
|
-
const result = await bandersnatchVrf.verifySeal(await this.bandersnatch, blockAuthorKey ?? BANDERSNATCH_ZERO_KEY, headerView.seal.materialize(), payload, encodeUnsealedHeader(headerView));
|
|
16859
|
+
const result = await bandersnatchVrf.verifySeal(await this.bandersnatch, authorBandersnatchKey, headerView.seal.materialize(), payload, encodeUnsealedHeader(headerView));
|
|
16683
16860
|
if (result.isError) {
|
|
16684
16861
|
return Result.error(SafroleSealError.IncorrectSeal);
|
|
16685
16862
|
}
|
|
@@ -22558,7 +22735,7 @@ class Assign {
|
|
|
22558
22735
|
const authorizationQueueStart = regs.get(8);
|
|
22559
22736
|
// a
|
|
22560
22737
|
const assigners = getServiceId(regs.get(9));
|
|
22561
|
-
const res = safe_alloc_uint8array_safeAllocUint8Array(hash_HASH_SIZE *
|
|
22738
|
+
const res = safe_alloc_uint8array_safeAllocUint8Array(hash_HASH_SIZE * auth_AUTHORIZATION_QUEUE_SIZE);
|
|
22562
22739
|
const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
|
|
22563
22740
|
// error while reading the memory.
|
|
22564
22741
|
if (memoryReadResult.isError) {
|
|
@@ -22572,8 +22749,8 @@ class Assign {
|
|
|
22572
22749
|
// NOTE: Here we know the core index is valid
|
|
22573
22750
|
const coreIndex = common_tryAsCoreIndex(Number(maybeCoreIndex));
|
|
22574
22751
|
const decoder = decoder_Decoder.fromBlob(res);
|
|
22575
|
-
const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE),
|
|
22576
|
-
const fixedSizeAuthQueue = sized_array_FixedSizeArray.new(authQueue,
|
|
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);
|
|
22577
22754
|
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
|
|
22578
22755
|
if (result.isOk) {
|
|
22579
22756
|
regs.set(IN_OUT_REG, results_HostCallResult.OK);
|
|
@@ -24319,9 +24496,10 @@ class accumulate_Accumulate {
|
|
|
24319
24496
|
const recentlyAccumulated = tryAsPerEpochBlock(newRecentlyAccumulated, this.chainSpec);
|
|
24320
24497
|
const accumulationQueue = this.state.accumulationQueue.slice();
|
|
24321
24498
|
accumulationQueue[phaseIndex] = pruneQueue(toAccumulateLater, accumulatedSet);
|
|
24499
|
+
const timeslot = this.state.timeslot;
|
|
24322
24500
|
for (let i = 1; i < epochLength; i++) {
|
|
24323
24501
|
const queueIndex = (phaseIndex + epochLength - i) % epochLength;
|
|
24324
|
-
if (i < slot -
|
|
24502
|
+
if (i < slot - timeslot) {
|
|
24325
24503
|
accumulationQueue[queueIndex] = [];
|
|
24326
24504
|
}
|
|
24327
24505
|
else {
|
|
@@ -24533,7 +24711,6 @@ class deferred_transfers_DeferredTransfers {
|
|
|
24533
24711
|
|
|
24534
24712
|
|
|
24535
24713
|
|
|
24536
|
-
|
|
24537
24714
|
/**
|
|
24538
24715
|
* Maintain a list of available authorizations per core.
|
|
24539
24716
|
*
|
|
@@ -24562,11 +24739,12 @@ class authorization_Authorization {
|
|
|
24562
24739
|
*/
|
|
24563
24740
|
transition(input) {
|
|
24564
24741
|
const authPoolsUpdate = this.state.authPools.slice();
|
|
24742
|
+
const authQueues = this.state.authQueues;
|
|
24565
24743
|
// we transition authorizations for each core.
|
|
24566
24744
|
for (let coreIndex = tryAsCoreIndex(0); coreIndex < this.chainSpec.coresCount; coreIndex++) {
|
|
24567
24745
|
let pool = authPoolsUpdate[coreIndex].slice();
|
|
24568
24746
|
// the queue is only read (we should most likely use `ArrayView` here).
|
|
24569
|
-
const queue =
|
|
24747
|
+
const queue = authQueues[coreIndex];
|
|
24570
24748
|
// if there were any used hashes - remove them
|
|
24571
24749
|
const usedHashes = input.used.get(coreIndex);
|
|
24572
24750
|
if (usedHashes !== undefined) {
|
|
@@ -24740,14 +24918,18 @@ class recent_history_RecentHistory {
|
|
|
24740
24918
|
* https://graypaper.fluffylabs.dev/#/1c979cb/0f55020f5502?v=0.7.1
|
|
24741
24919
|
*/
|
|
24742
24920
|
partialTransition(input) {
|
|
24743
|
-
const
|
|
24921
|
+
const stateBlocks = this.state.recentBlocks;
|
|
24922
|
+
const recentBlocks = stateBlocks.blocks.slice();
|
|
24744
24923
|
const lastState = recentBlocks.length > 0 ? recentBlocks[recentBlocks.length - 1] : null;
|
|
24745
24924
|
// update the posterior root of previous state.
|
|
24746
24925
|
if (lastState !== null) {
|
|
24747
24926
|
lastState.postStateRoot = input.priorStateRoot;
|
|
24748
24927
|
}
|
|
24749
24928
|
return {
|
|
24750
|
-
recentBlocks:
|
|
24929
|
+
recentBlocks: RecentBlocks.create({
|
|
24930
|
+
blocks: asKnownSize(recentBlocks),
|
|
24931
|
+
accumulationLog: stateBlocks.accumulationLog,
|
|
24932
|
+
}), // β_H†
|
|
24751
24933
|
};
|
|
24752
24934
|
}
|
|
24753
24935
|
/**
|
|
@@ -24759,8 +24941,8 @@ class recent_history_RecentHistory {
|
|
|
24759
24941
|
transition(input) {
|
|
24760
24942
|
const recentBlocks = input.partial.recentBlocks.blocks.slice();
|
|
24761
24943
|
// `β′_B`
|
|
24762
|
-
const mmr = this.state.recentBlocks.
|
|
24763
|
-
? MerkleMountainRange.fromPeaks(this.hasher, this.state.recentBlocks.
|
|
24944
|
+
const mmr = this.state.recentBlocks.accumulationLog !== null
|
|
24945
|
+
? MerkleMountainRange.fromPeaks(this.hasher, this.state.recentBlocks.accumulationLog)
|
|
24764
24946
|
: MerkleMountainRange.empty(this.hasher);
|
|
24765
24947
|
// append the accumulation root
|
|
24766
24948
|
mmr.append(input.accumulateRoot);
|
|
@@ -24778,7 +24960,7 @@ class recent_history_RecentHistory {
|
|
|
24778
24960
|
}
|
|
24779
24961
|
// write back to the state.
|
|
24780
24962
|
return {
|
|
24781
|
-
recentBlocks:
|
|
24963
|
+
recentBlocks: RecentBlocks.create(RecentBlocks.create({
|
|
24782
24964
|
blocks: asKnownSize(recentBlocks),
|
|
24783
24965
|
accumulationLog: peaks,
|
|
24784
24966
|
})),
|
|
@@ -24990,7 +25172,6 @@ function verify_basic_verifyReportsBasic(input) {
|
|
|
24990
25172
|
|
|
24991
25173
|
|
|
24992
25174
|
|
|
24993
|
-
|
|
24994
25175
|
const verify_contextual_logger = Logger.new(import.meta.filename, "stf:reports");
|
|
24995
25176
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/15eb0115eb01?v=0.6.7 */
|
|
24996
25177
|
function verify_contextual_verifyContextualValidity(input, state, headerChain, maxLookupAnchorAge) {
|
|
@@ -25103,7 +25284,7 @@ function verifyRefineContexts(minLookupSlot, contexts, recentBlocksPartialUpdate
|
|
|
25103
25284
|
return Result.error(ReportsError.BadStateRoot, `Anchor state root mismatch. Got: ${context.stateRoot}, expected: ${recentBlock.postStateRoot}.`);
|
|
25104
25285
|
}
|
|
25105
25286
|
// check beefy root
|
|
25106
|
-
const beefyRoot =
|
|
25287
|
+
const beefyRoot = recentBlock.accumulationResult;
|
|
25107
25288
|
if (!beefyRoot.isEqualTo(context.beefyRoot)) {
|
|
25108
25289
|
return Result.error(ReportsError.BadBeefyMmrRoot, `Invalid BEEFY super peak hash. Got: ${context.beefyRoot}, expected: ${beefyRoot}. Anchor: ${recentBlock.headerHash}`);
|
|
25109
25290
|
}
|
|
@@ -25345,8 +25526,9 @@ function verify_post_signature_verifyPostSignatureChecks(input, availabilityAssi
|
|
|
25345
25526
|
* https://graypaper.fluffylabs.dev/#/5f542d7/15eb0015ed00
|
|
25346
25527
|
*/
|
|
25347
25528
|
const authorizerHash = report.authorizerHash;
|
|
25348
|
-
const authorizerPool = authPools
|
|
25349
|
-
|
|
25529
|
+
const authorizerPool = authPools.get(coreIndex);
|
|
25530
|
+
const pool = authorizerPool?.materialize() ?? [];
|
|
25531
|
+
if (pool.find((hash) => hash.isEqualTo(authorizerHash)) === undefined) {
|
|
25350
25532
|
return Result.error(ReportsError.CoreUnauthorized, `Authorizer hash not found in the pool of core ${coreIndex}: ${authorizerHash}`);
|
|
25351
25533
|
}
|
|
25352
25534
|
/**
|
|
@@ -25476,7 +25658,8 @@ class reports_Reports {
|
|
|
25476
25658
|
return verifyCredentials(input.guarantees, workReportHashes, input.slot, (headerTimeSlot, guaranteeTimeSlot) => this.getGuarantorAssignment(headerTimeSlot, guaranteeTimeSlot, input.newEntropy));
|
|
25477
25659
|
}
|
|
25478
25660
|
verifyPostSignatureChecks(input, assurancesAvailAssignment) {
|
|
25479
|
-
|
|
25661
|
+
const authPoolsView = this.state.view().authPoolsView();
|
|
25662
|
+
return verifyPostSignatureChecks(input, assurancesAvailAssignment, authPoolsView, (id) => this.state.getService(id));
|
|
25480
25663
|
}
|
|
25481
25664
|
verifyContextualValidity(input) {
|
|
25482
25665
|
return verifyContextualValidity(input, this.state, this.headerChain, this.chainSpec.maxLookupAnchorAge);
|
|
@@ -27038,18 +27221,20 @@ function dumpOutput(spec, data, type, outputFormat, args, withRelPath) {
|
|
|
27038
27221
|
if (type.encode === undefined) {
|
|
27039
27222
|
throw new Error(`${type.name} does not support encoding to JAM codec.`);
|
|
27040
27223
|
}
|
|
27041
|
-
const
|
|
27224
|
+
const encoder = typeof type.encode === "function" ? type.encode(spec) : type.encode;
|
|
27225
|
+
const encoded = encoder_Encoder.encodeObject(encoder, data, spec);
|
|
27042
27226
|
dump(`${encoded}`);
|
|
27043
27227
|
return;
|
|
27044
27228
|
}
|
|
27045
27229
|
case OutputFormat.Bin: {
|
|
27046
|
-
if (type.encode === undefined) {
|
|
27047
|
-
throw new Error(`${type.name} does not support encoding to JAM codec.`);
|
|
27048
|
-
}
|
|
27049
27230
|
if (destination === null) {
|
|
27050
27231
|
throw new Error(`${OutputFormat.Bin} requires destination file.`);
|
|
27051
27232
|
}
|
|
27052
|
-
|
|
27233
|
+
if (type.encode === undefined) {
|
|
27234
|
+
throw new Error(`${type.name} does not support encoding to JAM codec.`);
|
|
27235
|
+
}
|
|
27236
|
+
const encoder = typeof type.encode === "function" ? type.encode(spec) : type.encode;
|
|
27237
|
+
const encoded = encoder_Encoder.encodeObject(encoder, data, spec);
|
|
27053
27238
|
dump(encoded.raw);
|
|
27054
27239
|
return;
|
|
27055
27240
|
}
|
|
@@ -27156,7 +27341,8 @@ async function loadAndProcessDataFile(file, withRelPath, flavor, decodeType, pro
|
|
|
27156
27341
|
if (decodeType.decode === undefined) {
|
|
27157
27342
|
throw new Error(`${decodeType.name} does not support decoding from binary data.`);
|
|
27158
27343
|
}
|
|
27159
|
-
|
|
27344
|
+
const decoder = typeof decodeType.decode === "function" ? decodeType.decode(spec) : decodeType.decode;
|
|
27345
|
+
data = decoder_Decoder.decodeObject(decoder, input.data, spec);
|
|
27160
27346
|
}
|
|
27161
27347
|
else if (input.type === "json") {
|
|
27162
27348
|
if (decodeType.json === undefined) {
|