@typeberry/jam 0.2.0-b6e3410 → 0.2.0-e767e74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bootstrap-generator.mjs +1059 -880
- package/bootstrap-generator.mjs.map +1 -1
- package/bootstrap-importer.mjs +1097 -913
- package/bootstrap-importer.mjs.map +1 -1
- package/bootstrap-network.mjs +993 -814
- package/bootstrap-network.mjs.map +1 -1
- package/index.js +1096 -915
- package/index.js.map +1 -1
- package/package.json +1 -1
package/bootstrap-importer.mjs
CHANGED
|
@@ -2753,7 +2753,7 @@ module.exports = __nccwpck_require__.p + "e2fdc1b646378dd96eda.js?ed25519_wasm_b
|
|
|
2753
2753
|
|
|
2754
2754
|
/***/ }),
|
|
2755
2755
|
|
|
2756
|
-
/***/
|
|
2756
|
+
/***/ 566:
|
|
2757
2757
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
2758
2758
|
|
|
2759
2759
|
module.exports = __nccwpck_require__.p + "ccf8ada94096a8f232f5.js?reed_solomon_wasm_bg.wasm";
|
|
@@ -3452,7 +3452,7 @@ async function __wbg_init(module_or_path) {
|
|
|
3452
3452
|
if (wasm !== void 0) return wasm;
|
|
3453
3453
|
if (typeof module_or_path !== "undefined") if (Object.getPrototypeOf(module_or_path) === Object.prototype) ({module_or_path} = module_or_path);
|
|
3454
3454
|
else console.warn("using deprecated parameters for the initialization function; pass a single object instead");
|
|
3455
|
-
if (typeof module_or_path === "undefined") module_or_path = new URL(/* asset import */ __nccwpck_require__(
|
|
3455
|
+
if (typeof module_or_path === "undefined") module_or_path = new URL(/* asset import */ __nccwpck_require__(566), __nccwpck_require__.b);
|
|
3456
3456
|
const imports = __wbg_get_imports();
|
|
3457
3457
|
if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) module_or_path = fetch(module_or_path);
|
|
3458
3458
|
__wbg_init_memory(imports);
|
|
@@ -4521,7 +4521,7 @@ const BANDERSNATCH_KEY_BYTES = 32;
|
|
|
4521
4521
|
/** Bandersnatch VRF signature size */
|
|
4522
4522
|
const BANDERSNATCH_VRF_SIGNATURE_BYTES = 96;
|
|
4523
4523
|
/** Bandersnatch ring commitment size */
|
|
4524
|
-
const
|
|
4524
|
+
const bandersnatch_BANDERSNATCH_RING_ROOT_BYTES = 144;
|
|
4525
4525
|
/** Bandersnatch proof size */
|
|
4526
4526
|
const BANDERSNATCH_PROOF_BYTES = 784;
|
|
4527
4527
|
/** BLS public key size. */
|
|
@@ -6198,6 +6198,9 @@ class ObjectView {
|
|
|
6198
6198
|
toString() {
|
|
6199
6199
|
return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
|
|
6200
6200
|
}
|
|
6201
|
+
[TEST_COMPARE_USING]() {
|
|
6202
|
+
return this.materialize();
|
|
6203
|
+
}
|
|
6201
6204
|
}
|
|
6202
6205
|
/**
|
|
6203
6206
|
* A lazy-evaluated decoder of a sequence.
|
|
@@ -6330,7 +6333,7 @@ const TYPICAL_DICTIONARY_LENGTH = 32;
|
|
|
6330
6333
|
* It's not true in a general case, but should be good enough for us.
|
|
6331
6334
|
*
|
|
6332
6335
|
*/
|
|
6333
|
-
function
|
|
6336
|
+
function descriptors_readonlyArray(desc) {
|
|
6334
6337
|
return desc.convert((x) => {
|
|
6335
6338
|
debug_check `
|
|
6336
6339
|
${Array.isArray(x)}
|
|
@@ -6492,7 +6495,15 @@ var descriptors_codec;
|
|
|
6492
6495
|
/** Custom encoding / decoding logic. */
|
|
6493
6496
|
codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
|
|
6494
6497
|
/** Choose a descriptor depending on the encoding/decoding context. */
|
|
6495
|
-
codec.select = ({ name, sizeHint, }, chooser) =>
|
|
6498
|
+
codec.select = ({ name, sizeHint, }, chooser) => {
|
|
6499
|
+
const Self = chooser(null);
|
|
6500
|
+
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)
|
|
6501
|
+
? codec.select({
|
|
6502
|
+
name: Self.View.name,
|
|
6503
|
+
sizeHint: Self.View.sizeHint,
|
|
6504
|
+
}, (ctx) => chooser(ctx).View)
|
|
6505
|
+
: Self.View);
|
|
6506
|
+
};
|
|
6496
6507
|
/**
|
|
6497
6508
|
* A descriptor for a more complex POJO.
|
|
6498
6509
|
*
|
|
@@ -7610,9 +7621,9 @@ function codecWithContext(chooser) {
|
|
|
7610
7621
|
/** Codec for a known-size array with length validation. */
|
|
7611
7622
|
const codecKnownSizeArray = (val, options, _id) => {
|
|
7612
7623
|
if ("fixedLength" in options) {
|
|
7613
|
-
return
|
|
7624
|
+
return descriptors_readonlyArray(descriptors_codec.sequenceFixLen(val, options.fixedLength)).convert(seeThrough, sized_array_asKnownSize);
|
|
7614
7625
|
}
|
|
7615
|
-
return
|
|
7626
|
+
return descriptors_readonlyArray(descriptors_codec.sequenceVarLen(val, options)).convert(seeThrough, sized_array_asKnownSize);
|
|
7616
7627
|
};
|
|
7617
7628
|
/** Codec for a fixed-size array with length validation. */
|
|
7618
7629
|
const codecFixedSizeArray = (val, len) => {
|
|
@@ -7749,7 +7760,7 @@ function tryAsPerValidator(array, spec) {
|
|
|
7749
7760
|
`;
|
|
7750
7761
|
return sized_array_asKnownSize(array);
|
|
7751
7762
|
}
|
|
7752
|
-
const
|
|
7763
|
+
const common_codecPerValidator = (val) => codecWithContext((context) => {
|
|
7753
7764
|
return codecKnownSizeArray(val, {
|
|
7754
7765
|
fixedLength: context.validatorsCount,
|
|
7755
7766
|
});
|
|
@@ -7876,7 +7887,7 @@ class Verdict extends WithDebug {
|
|
|
7876
7887
|
workReportHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
7877
7888
|
votesEpoch: descriptors_codec.u32.asOpaque(),
|
|
7878
7889
|
votes: codecWithContext((context) => {
|
|
7879
|
-
return
|
|
7890
|
+
return descriptors_readonlyArray(descriptors_codec.sequenceFixLen(Judgement.Codec, context.validatorsSuperMajority)).convert(seeThrough, sized_array_asKnownSize);
|
|
7880
7891
|
}),
|
|
7881
7892
|
});
|
|
7882
7893
|
static create({ workReportHash, votesEpoch, votes }) {
|
|
@@ -8568,7 +8579,7 @@ const WorkReportCodec = descriptors_codec.Class(WorkReportNoCodec, {
|
|
|
8568
8579
|
authorizerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
8569
8580
|
authorizationGasUsed: descriptors_codec.varU64.asOpaque(),
|
|
8570
8581
|
authorizationOutput: descriptors_codec.blob,
|
|
8571
|
-
segmentRootLookup:
|
|
8582
|
+
segmentRootLookup: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
|
|
8572
8583
|
results: descriptors_codec.sequenceVarLen(WorkResult.Codec).convert((x) => x, (items) => FixedSizeArray.new(items, tryAsWorkItemsCount(items.length))),
|
|
8573
8584
|
});
|
|
8574
8585
|
const WorkReportCodecPre070 = descriptors_codec.Class(WorkReportNoCodec, {
|
|
@@ -8582,7 +8593,7 @@ const WorkReportCodecPre070 = descriptors_codec.Class(WorkReportNoCodec, {
|
|
|
8582
8593
|
}),
|
|
8583
8594
|
authorizerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
8584
8595
|
authorizationOutput: descriptors_codec.blob,
|
|
8585
|
-
segmentRootLookup:
|
|
8596
|
+
segmentRootLookup: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
|
|
8586
8597
|
results: descriptors_codec.sequenceVarLen(WorkResult.Codec).convert((x) => x, (items) => FixedSizeArray.new(items, tryAsWorkItemsCount(items.length))),
|
|
8587
8598
|
authorizationGasUsed: descriptors_codec.varU64.asOpaque(),
|
|
8588
8599
|
});
|
|
@@ -8700,16 +8711,16 @@ class SignedTicket extends WithDebug {
|
|
|
8700
8711
|
}
|
|
8701
8712
|
}
|
|
8702
8713
|
/** Anonymous? entry into the ticket contest. */
|
|
8703
|
-
class
|
|
8714
|
+
class tickets_Ticket extends WithDebug {
|
|
8704
8715
|
id;
|
|
8705
8716
|
attempt;
|
|
8706
|
-
static Codec = descriptors_codec.Class(
|
|
8717
|
+
static Codec = descriptors_codec.Class(tickets_Ticket, {
|
|
8707
8718
|
id: descriptors_codec.bytes(hash_HASH_SIZE),
|
|
8708
8719
|
// TODO [ToDr] we should verify that attempt is either 0|1|2.
|
|
8709
8720
|
attempt: descriptors_codec.u8.asOpaque(),
|
|
8710
8721
|
});
|
|
8711
8722
|
static create({ id, attempt }) {
|
|
8712
|
-
return new
|
|
8723
|
+
return new tickets_Ticket(id, attempt);
|
|
8713
8724
|
}
|
|
8714
8725
|
constructor(
|
|
8715
8726
|
/**
|
|
@@ -8778,7 +8789,7 @@ class ValidatorKeys extends WithDebug {
|
|
|
8778
8789
|
class TicketsMarker extends WithDebug {
|
|
8779
8790
|
tickets;
|
|
8780
8791
|
static Codec = descriptors_codec.Class(TicketsMarker, {
|
|
8781
|
-
tickets: codecPerEpochBlock(
|
|
8792
|
+
tickets: codecPerEpochBlock(tickets_Ticket.Codec),
|
|
8782
8793
|
});
|
|
8783
8794
|
static create({ tickets }) {
|
|
8784
8795
|
return new TicketsMarker(tickets);
|
|
@@ -8802,7 +8813,7 @@ class EpochMarker extends WithDebug {
|
|
|
8802
8813
|
static Codec = descriptors_codec.Class(EpochMarker, {
|
|
8803
8814
|
entropy: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
8804
8815
|
ticketsEntropy: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
8805
|
-
validators:
|
|
8816
|
+
validators: common_codecPerValidator(ValidatorKeys.Codec),
|
|
8806
8817
|
});
|
|
8807
8818
|
static create({ entropy, ticketsEntropy, validators }) {
|
|
8808
8819
|
return new EpochMarker(entropy, ticketsEntropy, validators);
|
|
@@ -9074,6 +9085,19 @@ function emptyBlock(slot = tryAsTimeSlot(0)) {
|
|
|
9074
9085
|
});
|
|
9075
9086
|
}
|
|
9076
9087
|
|
|
9088
|
+
;// CONCATENATED MODULE: ./packages/jam/block/utils.ts
|
|
9089
|
+
|
|
9090
|
+
/**
|
|
9091
|
+
* Take an input data and re-encode that data as view.
|
|
9092
|
+
*
|
|
9093
|
+
* NOTE: this function should NEVER be used in any production code,
|
|
9094
|
+
* it's only a test helper.
|
|
9095
|
+
*/
|
|
9096
|
+
function reencodeAsView(codec, object, chainSpec) {
|
|
9097
|
+
const encoded = encoder_Encoder.encodeObject(codec, object, chainSpec);
|
|
9098
|
+
return decoder_Decoder.decodeObject(codec.View, encoded, chainSpec);
|
|
9099
|
+
}
|
|
9100
|
+
|
|
9077
9101
|
;// CONCATENATED MODULE: ./packages/jam/block/index.ts
|
|
9078
9102
|
|
|
9079
9103
|
|
|
@@ -9092,6 +9116,7 @@ function emptyBlock(slot = tryAsTimeSlot(0)) {
|
|
|
9092
9116
|
|
|
9093
9117
|
|
|
9094
9118
|
|
|
9119
|
+
|
|
9095
9120
|
;// CONCATENATED MODULE: ./packages/jam/database-lmdb/blocks.ts
|
|
9096
9121
|
|
|
9097
9122
|
|
|
@@ -9443,10 +9468,128 @@ function accumulationOutputComparator(a, b) {
|
|
|
9443
9468
|
return Ordering.Equal;
|
|
9444
9469
|
}
|
|
9445
9470
|
|
|
9471
|
+
;// CONCATENATED MODULE: ./packages/jam/block/gp-constants.ts
|
|
9472
|
+
|
|
9473
|
+
/**
|
|
9474
|
+
* This file lists all of the constants defined in the GrayPaper appendix.
|
|
9475
|
+
*
|
|
9476
|
+
* NOTE: Avoid using the constants directly, prefer "named" constants defined
|
|
9477
|
+
* in a semantical proximity to where they are used.
|
|
9478
|
+
*
|
|
9479
|
+
* NOTE: This file will most likely be removed in the future. The constants
|
|
9480
|
+
* here are only temporarily for convenience. When we figure out better names
|
|
9481
|
+
* and places for these this file will be eradicated.
|
|
9482
|
+
*
|
|
9483
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/413000413000
|
|
9484
|
+
*/
|
|
9485
|
+
/** `G_I`: The gas allocated to invoke a work-package’s Is-Authorized logic. */
|
|
9486
|
+
const G_I = 50_000_000;
|
|
9487
|
+
/** `I`: Maximum number of work items in a package. */
|
|
9488
|
+
const gp_constants_I = (/* unused pure expression or super */ null && (MAX_NUMBER_OF_WORK_ITEMS));
|
|
9489
|
+
/** `O`: Maximum number of items in the authorizations pool. */
|
|
9490
|
+
const O = 8;
|
|
9491
|
+
/** `Q`: The number of items in the authorizations queue. */
|
|
9492
|
+
const Q = 80;
|
|
9493
|
+
/** `S`: The maximum number of entries in the accumulation queue. */
|
|
9494
|
+
const S = 1024;
|
|
9495
|
+
/** `T`: The maximum number of extrinsics in a work-package. */
|
|
9496
|
+
const T = 128;
|
|
9497
|
+
/** `W_A`: The maximum size of is-authorized code in octets. */
|
|
9498
|
+
const W_A = 64_000;
|
|
9499
|
+
/** `W_B`: The maximum size of an encoded work-package with extrinsic data and imports. */
|
|
9500
|
+
const W_B = 13_794_305;
|
|
9501
|
+
/** `W_C`: The maximum size of service code in octets. */
|
|
9502
|
+
const W_C = 4_000_000;
|
|
9503
|
+
/** `W_M`: The maximum number of imports in a work-package. */
|
|
9504
|
+
const W_M = 3_072;
|
|
9505
|
+
/** `W_R`: The maximum total size of all output blobs in a work-report, in octets. */
|
|
9506
|
+
const W_R = 49_152;
|
|
9507
|
+
/** `W_T`: The size of a transfer memo in octets. */
|
|
9508
|
+
const W_T = 128;
|
|
9509
|
+
/** `W_M`: The maximum number of exports in a work-package. */
|
|
9510
|
+
const W_X = 3_072;
|
|
9511
|
+
// TODO [ToDr] Not sure where these should live yet :(
|
|
9512
|
+
/**
|
|
9513
|
+
* `S`: The minimum public service index.
|
|
9514
|
+
* Services of indices below these may only be created by the Registrar.
|
|
9515
|
+
*
|
|
9516
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
|
|
9517
|
+
*/
|
|
9518
|
+
const MIN_PUBLIC_SERVICE_INDEX = 2 ** 16;
|
|
9519
|
+
/**
|
|
9520
|
+
* `J`: The maximum sum of dependency items in a work-report.
|
|
9521
|
+
*
|
|
9522
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
|
|
9523
|
+
*/
|
|
9524
|
+
const MAX_REPORT_DEPENDENCIES = 8;
|
|
9525
|
+
|
|
9526
|
+
;// CONCATENATED MODULE: ./packages/jam/state/accumulation-queue.ts
|
|
9527
|
+
|
|
9528
|
+
|
|
9529
|
+
|
|
9530
|
+
|
|
9531
|
+
|
|
9532
|
+
|
|
9533
|
+
|
|
9534
|
+
/**
|
|
9535
|
+
* Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
|
|
9536
|
+
*
|
|
9537
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
|
|
9538
|
+
*/
|
|
9539
|
+
class NotYetAccumulatedReport extends WithDebug {
|
|
9540
|
+
report;
|
|
9541
|
+
dependencies;
|
|
9542
|
+
static Codec = descriptors_codec.Class(NotYetAccumulatedReport, {
|
|
9543
|
+
report: WorkReport.Codec,
|
|
9544
|
+
dependencies: codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
|
|
9545
|
+
typicalLength: MAX_REPORT_DEPENDENCIES / 2,
|
|
9546
|
+
maxLength: MAX_REPORT_DEPENDENCIES,
|
|
9547
|
+
minLength: 0,
|
|
9548
|
+
}),
|
|
9549
|
+
});
|
|
9550
|
+
static create({ report, dependencies }) {
|
|
9551
|
+
return new NotYetAccumulatedReport(report, dependencies);
|
|
9552
|
+
}
|
|
9553
|
+
constructor(
|
|
9554
|
+
/**
|
|
9555
|
+
* Each of these were made available at most one epoch ago
|
|
9556
|
+
* but have or had unfulfilled dependencies.
|
|
9557
|
+
*/
|
|
9558
|
+
report,
|
|
9559
|
+
/**
|
|
9560
|
+
* Alongside the work-report itself, we retain its un-accumulated
|
|
9561
|
+
* dependencies, a set of work-package hashes.
|
|
9562
|
+
*
|
|
9563
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
|
|
9564
|
+
*/
|
|
9565
|
+
dependencies) {
|
|
9566
|
+
super();
|
|
9567
|
+
this.report = report;
|
|
9568
|
+
this.dependencies = dependencies;
|
|
9569
|
+
}
|
|
9570
|
+
}
|
|
9571
|
+
const accumulationQueueCodec = codecPerEpochBlock(descriptors_readonlyArray(descriptors_codec.sequenceVarLen(NotYetAccumulatedReport.Codec)));
|
|
9572
|
+
|
|
9573
|
+
;// CONCATENATED MODULE: ./packages/jam/state/common.ts
|
|
9574
|
+
|
|
9575
|
+
|
|
9576
|
+
/** Check if given array has correct length before casting to the opaque type. */
|
|
9577
|
+
function tryAsPerCore(array, spec) {
|
|
9578
|
+
debug_check `
|
|
9579
|
+
${array.length === spec.coresCount}
|
|
9580
|
+
Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
|
|
9581
|
+
`;
|
|
9582
|
+
return opaque_asOpaqueType(array);
|
|
9583
|
+
}
|
|
9584
|
+
const codecPerCore = (val) => codecWithContext((context) => {
|
|
9585
|
+
return codecKnownSizeArray(val, { fixedLength: context.coresCount });
|
|
9586
|
+
});
|
|
9587
|
+
|
|
9446
9588
|
;// CONCATENATED MODULE: ./packages/jam/state/assurances.ts
|
|
9447
9589
|
|
|
9448
9590
|
|
|
9449
9591
|
|
|
9592
|
+
|
|
9450
9593
|
/**
|
|
9451
9594
|
* Assignment of particular work report to a core.
|
|
9452
9595
|
*
|
|
@@ -9475,27 +9618,30 @@ class AvailabilityAssignment extends WithDebug {
|
|
|
9475
9618
|
this.timeout = timeout;
|
|
9476
9619
|
}
|
|
9477
9620
|
}
|
|
9621
|
+
const availabilityAssignmentsCodec = codecPerCore(descriptors_codec.optional(AvailabilityAssignment.Codec));
|
|
9478
9622
|
|
|
9479
|
-
;// CONCATENATED MODULE: ./packages/jam/state/
|
|
9623
|
+
;// CONCATENATED MODULE: ./packages/jam/state/auth.ts
|
|
9480
9624
|
|
|
9481
9625
|
|
|
9482
|
-
|
|
9483
|
-
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
|
|
9492
|
-
|
|
9626
|
+
|
|
9627
|
+
|
|
9628
|
+
|
|
9629
|
+
/** `O`: Maximal authorization pool size. */
|
|
9630
|
+
const MAX_AUTH_POOL_SIZE = O;
|
|
9631
|
+
/** `Q`: Size of the authorization queue. */
|
|
9632
|
+
const AUTHORIZATION_QUEUE_SIZE = Q;
|
|
9633
|
+
const authPoolsCodec = codecPerCore(codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
|
|
9634
|
+
minLength: 0,
|
|
9635
|
+
maxLength: MAX_AUTH_POOL_SIZE,
|
|
9636
|
+
typicalLength: MAX_AUTH_POOL_SIZE,
|
|
9637
|
+
}));
|
|
9638
|
+
const authQueuesCodec = codecPerCore(codecFixedSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE));
|
|
9493
9639
|
|
|
9494
9640
|
;// CONCATENATED MODULE: ./packages/jam/state/disputes.ts
|
|
9495
9641
|
|
|
9496
9642
|
|
|
9497
9643
|
|
|
9498
|
-
const sortedSetCodec = () =>
|
|
9644
|
+
const sortedSetCodec = () => descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE))).convert((input) => input.array, (output) => {
|
|
9499
9645
|
const typed = output.map((x) => x.asOpaque());
|
|
9500
9646
|
return SortedSet.fromSortedArray(hashComparator, typed);
|
|
9501
9647
|
});
|
|
@@ -9557,65 +9703,6 @@ function hashComparator(a, b) {
|
|
|
9557
9703
|
return a.compare(b);
|
|
9558
9704
|
}
|
|
9559
9705
|
|
|
9560
|
-
;// CONCATENATED MODULE: ./packages/jam/block/gp-constants.ts
|
|
9561
|
-
|
|
9562
|
-
/**
|
|
9563
|
-
* This file lists all of the constants defined in the GrayPaper appendix.
|
|
9564
|
-
*
|
|
9565
|
-
* NOTE: Avoid using the constants directly, prefer "named" constants defined
|
|
9566
|
-
* in a semantical proximity to where they are used.
|
|
9567
|
-
*
|
|
9568
|
-
* NOTE: This file will most likely be removed in the future. The constants
|
|
9569
|
-
* here are only temporarily for convenience. When we figure out better names
|
|
9570
|
-
* and places for these this file will be eradicated.
|
|
9571
|
-
*
|
|
9572
|
-
* https://graypaper.fluffylabs.dev/#/579bd12/413000413000
|
|
9573
|
-
*/
|
|
9574
|
-
/** `G_I`: The gas allocated to invoke a work-package’s Is-Authorized logic. */
|
|
9575
|
-
const G_I = 50_000_000;
|
|
9576
|
-
/** `I`: Maximum number of work items in a package. */
|
|
9577
|
-
const gp_constants_I = (/* unused pure expression or super */ null && (MAX_NUMBER_OF_WORK_ITEMS));
|
|
9578
|
-
/** `O`: Maximum number of items in the authorizations pool. */
|
|
9579
|
-
const O = 8;
|
|
9580
|
-
/** `Q`: The number of items in the authorizations queue. */
|
|
9581
|
-
const Q = 80;
|
|
9582
|
-
/** `S`: The maximum number of entries in the accumulation queue. */
|
|
9583
|
-
const S = 1024;
|
|
9584
|
-
/** `T`: The maximum number of extrinsics in a work-package. */
|
|
9585
|
-
const T = 128;
|
|
9586
|
-
/** `W_A`: The maximum size of is-authorized code in octets. */
|
|
9587
|
-
const W_A = 64_000;
|
|
9588
|
-
/** `W_B`: The maximum size of an encoded work-package with extrinsic data and imports. */
|
|
9589
|
-
const W_B = 13_794_305;
|
|
9590
|
-
/** `W_C`: The maximum size of service code in octets. */
|
|
9591
|
-
const W_C = 4_000_000;
|
|
9592
|
-
/** `W_M`: The maximum number of imports in a work-package. */
|
|
9593
|
-
const W_M = 3_072;
|
|
9594
|
-
/** `W_R`: The maximum total size of all output blobs in a work-report, in octets. */
|
|
9595
|
-
const W_R = 49_152;
|
|
9596
|
-
/** `W_T`: The size of a transfer memo in octets. */
|
|
9597
|
-
const W_T = 128;
|
|
9598
|
-
/** `W_M`: The maximum number of exports in a work-package. */
|
|
9599
|
-
const W_X = 3_072;
|
|
9600
|
-
// TODO [ToDr] Not sure where these should live yet :(
|
|
9601
|
-
/**
|
|
9602
|
-
* `S`: The minimum public service index.
|
|
9603
|
-
* Services of indices below these may only be created by the Registrar.
|
|
9604
|
-
*
|
|
9605
|
-
* https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
|
|
9606
|
-
*/
|
|
9607
|
-
const MIN_PUBLIC_SERVICE_INDEX = 2 ** 16;
|
|
9608
|
-
/**
|
|
9609
|
-
* `J`: The maximum sum of dependency items in a work-report.
|
|
9610
|
-
*
|
|
9611
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
|
|
9612
|
-
*/
|
|
9613
|
-
const MAX_REPORT_DEPENDENCIES = 8;
|
|
9614
|
-
/** `Q`: Size of the authorization queue. */
|
|
9615
|
-
const AUTHORIZATION_QUEUE_SIZE = Q;
|
|
9616
|
-
/** `O`: Maximal authorization pool size. */
|
|
9617
|
-
const MAX_AUTH_POOL_SIZE = O;
|
|
9618
|
-
|
|
9619
9706
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
|
|
9620
9707
|
const MAX_VALUE = 4294967295;
|
|
9621
9708
|
const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
|
|
@@ -9623,7 +9710,7 @@ const MIN_VALUE = -(2 ** 31);
|
|
|
9623
9710
|
const MAX_SHIFT_U32 = 32;
|
|
9624
9711
|
const MAX_SHIFT_U64 = 64n;
|
|
9625
9712
|
|
|
9626
|
-
;// CONCATENATED MODULE: ./packages/jam/state/
|
|
9713
|
+
;// CONCATENATED MODULE: ./packages/jam/state/recent-blocks.ts
|
|
9627
9714
|
|
|
9628
9715
|
|
|
9629
9716
|
|
|
@@ -9631,23 +9718,267 @@ const MAX_SHIFT_U64 = 64n;
|
|
|
9631
9718
|
|
|
9632
9719
|
|
|
9633
9720
|
/**
|
|
9634
|
-
* `
|
|
9635
|
-
*
|
|
9636
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
9637
|
-
*/
|
|
9638
|
-
const BASE_SERVICE_BALANCE = 100n;
|
|
9639
|
-
/**
|
|
9640
|
-
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
9721
|
+
* `H = 8`: The size of recent history, in blocks.
|
|
9641
9722
|
*
|
|
9642
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
9723
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/416300416500
|
|
9643
9724
|
*/
|
|
9644
|
-
const
|
|
9725
|
+
const MAX_RECENT_HISTORY = 8;
|
|
9726
|
+
/** Recent history of a single block. */
|
|
9727
|
+
class BlockState extends WithDebug {
|
|
9728
|
+
headerHash;
|
|
9729
|
+
accumulationResult;
|
|
9730
|
+
postStateRoot;
|
|
9731
|
+
reported;
|
|
9732
|
+
static Codec = descriptors_codec.Class(BlockState, {
|
|
9733
|
+
headerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
9734
|
+
accumulationResult: descriptors_codec.bytes(hash_HASH_SIZE),
|
|
9735
|
+
postStateRoot: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
9736
|
+
reported: codecHashDictionary(WorkPackageInfo.Codec, (x) => x.workPackageHash),
|
|
9737
|
+
});
|
|
9738
|
+
static create({ headerHash, accumulationResult, postStateRoot, reported }) {
|
|
9739
|
+
return new BlockState(headerHash, accumulationResult, postStateRoot, reported);
|
|
9740
|
+
}
|
|
9741
|
+
constructor(
|
|
9742
|
+
/** Header hash. */
|
|
9743
|
+
headerHash,
|
|
9744
|
+
/** Merkle mountain belt of accumulation result. */
|
|
9745
|
+
accumulationResult,
|
|
9746
|
+
/** Posterior state root filled in with a 1-block delay. */
|
|
9747
|
+
postStateRoot,
|
|
9748
|
+
/** Reported work packages (no more than number of cores). */
|
|
9749
|
+
reported) {
|
|
9750
|
+
super();
|
|
9751
|
+
this.headerHash = headerHash;
|
|
9752
|
+
this.accumulationResult = accumulationResult;
|
|
9753
|
+
this.postStateRoot = postStateRoot;
|
|
9754
|
+
this.reported = reported;
|
|
9755
|
+
}
|
|
9756
|
+
}
|
|
9645
9757
|
/**
|
|
9646
|
-
*
|
|
9758
|
+
* Recent history of blocks.
|
|
9647
9759
|
*
|
|
9648
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/
|
|
9760
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
|
|
9649
9761
|
*/
|
|
9650
|
-
|
|
9762
|
+
class RecentBlocks extends WithDebug {
|
|
9763
|
+
blocks;
|
|
9764
|
+
accumulationLog;
|
|
9765
|
+
static Codec = descriptors_codec.Class(RecentBlocks, {
|
|
9766
|
+
blocks: codecKnownSizeArray(BlockState.Codec, {
|
|
9767
|
+
minLength: 0,
|
|
9768
|
+
maxLength: MAX_RECENT_HISTORY,
|
|
9769
|
+
typicalLength: MAX_RECENT_HISTORY,
|
|
9770
|
+
}),
|
|
9771
|
+
accumulationLog: descriptors_codec.object({
|
|
9772
|
+
peaks: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.optional(descriptors_codec.bytes(hash_HASH_SIZE)))),
|
|
9773
|
+
}),
|
|
9774
|
+
});
|
|
9775
|
+
static empty() {
|
|
9776
|
+
return new RecentBlocks(sized_array_asKnownSize([]), {
|
|
9777
|
+
peaks: [],
|
|
9778
|
+
});
|
|
9779
|
+
}
|
|
9780
|
+
static create(a) {
|
|
9781
|
+
return new RecentBlocks(a.blocks, a.accumulationLog);
|
|
9782
|
+
}
|
|
9783
|
+
constructor(
|
|
9784
|
+
/**
|
|
9785
|
+
* Most recent blocks.
|
|
9786
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0fea010fea01?v=0.6.7
|
|
9787
|
+
*/
|
|
9788
|
+
blocks,
|
|
9789
|
+
/**
|
|
9790
|
+
* Accumulation output log.
|
|
9791
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0f02020f0202?v=0.6.7
|
|
9792
|
+
*/
|
|
9793
|
+
accumulationLog) {
|
|
9794
|
+
super();
|
|
9795
|
+
this.blocks = blocks;
|
|
9796
|
+
this.accumulationLog = accumulationLog;
|
|
9797
|
+
}
|
|
9798
|
+
}
|
|
9799
|
+
|
|
9800
|
+
;// CONCATENATED MODULE: ./packages/jam/state/recently-accumulated.ts
|
|
9801
|
+
|
|
9802
|
+
|
|
9803
|
+
|
|
9804
|
+
|
|
9805
|
+
const recentlyAccumulatedCodec = codecPerEpochBlock(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque()).convert((x) => Array.from(x), (x) => HashSet.from(x)));
|
|
9806
|
+
|
|
9807
|
+
;// CONCATENATED MODULE: ./packages/jam/state/validator-data.ts
|
|
9808
|
+
|
|
9809
|
+
|
|
9810
|
+
|
|
9811
|
+
|
|
9812
|
+
/**
|
|
9813
|
+
* Fixed size of validator metadata.
|
|
9814
|
+
*
|
|
9815
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/0d55010d5501
|
|
9816
|
+
*/
|
|
9817
|
+
const VALIDATOR_META_BYTES = 128;
|
|
9818
|
+
/**
|
|
9819
|
+
* Details about validators' identity.
|
|
9820
|
+
*
|
|
9821
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/0d4b010d4c01
|
|
9822
|
+
*/
|
|
9823
|
+
class validator_data_ValidatorData extends WithDebug {
|
|
9824
|
+
bandersnatch;
|
|
9825
|
+
ed25519;
|
|
9826
|
+
bls;
|
|
9827
|
+
metadata;
|
|
9828
|
+
static Codec = descriptors_codec.Class(validator_data_ValidatorData, {
|
|
9829
|
+
bandersnatch: descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
9830
|
+
ed25519: descriptors_codec.bytes(ED25519_KEY_BYTES).asOpaque(),
|
|
9831
|
+
bls: descriptors_codec.bytes(BLS_KEY_BYTES).asOpaque(),
|
|
9832
|
+
metadata: descriptors_codec.bytes(VALIDATOR_META_BYTES),
|
|
9833
|
+
});
|
|
9834
|
+
static create({ ed25519, bandersnatch, bls, metadata }) {
|
|
9835
|
+
return new validator_data_ValidatorData(bandersnatch, ed25519, bls, metadata);
|
|
9836
|
+
}
|
|
9837
|
+
constructor(
|
|
9838
|
+
/** Bandersnatch public key. */
|
|
9839
|
+
bandersnatch,
|
|
9840
|
+
/** ED25519 key data. */
|
|
9841
|
+
ed25519,
|
|
9842
|
+
/** BLS public key. */
|
|
9843
|
+
bls,
|
|
9844
|
+
/** Validator-defined additional metdata. */
|
|
9845
|
+
metadata) {
|
|
9846
|
+
super();
|
|
9847
|
+
this.bandersnatch = bandersnatch;
|
|
9848
|
+
this.ed25519 = ed25519;
|
|
9849
|
+
this.bls = bls;
|
|
9850
|
+
this.metadata = metadata;
|
|
9851
|
+
}
|
|
9852
|
+
}
|
|
9853
|
+
const validatorsDataCodec = common_codecPerValidator(validator_data_ValidatorData.Codec);
|
|
9854
|
+
|
|
9855
|
+
;// CONCATENATED MODULE: ./packages/jam/state/safrole-data.ts
|
|
9856
|
+
|
|
9857
|
+
|
|
9858
|
+
|
|
9859
|
+
|
|
9860
|
+
|
|
9861
|
+
|
|
9862
|
+
|
|
9863
|
+
|
|
9864
|
+
|
|
9865
|
+
|
|
9866
|
+
|
|
9867
|
+
var SafroleSealingKeysKind;
|
|
9868
|
+
(function (SafroleSealingKeysKind) {
|
|
9869
|
+
SafroleSealingKeysKind[SafroleSealingKeysKind["Tickets"] = 0] = "Tickets";
|
|
9870
|
+
SafroleSealingKeysKind[SafroleSealingKeysKind["Keys"] = 1] = "Keys";
|
|
9871
|
+
})(SafroleSealingKeysKind || (SafroleSealingKeysKind = {}));
|
|
9872
|
+
const codecBandersnatchKey = descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque();
|
|
9873
|
+
class safrole_data_SafroleSealingKeysData extends WithDebug {
|
|
9874
|
+
kind;
|
|
9875
|
+
keys;
|
|
9876
|
+
tickets;
|
|
9877
|
+
static Codec = codecWithContext((context) => {
|
|
9878
|
+
return descriptors_codec.custom({
|
|
9879
|
+
name: "SafroleSealingKeys",
|
|
9880
|
+
sizeHint: { bytes: 1 + hash_HASH_SIZE * context.epochLength, isExact: false },
|
|
9881
|
+
}, (e, x) => {
|
|
9882
|
+
e.varU32(numbers_tryAsU32(x.kind));
|
|
9883
|
+
if (x.kind === SafroleSealingKeysKind.Keys) {
|
|
9884
|
+
e.sequenceFixLen(codecBandersnatchKey, x.keys);
|
|
9885
|
+
}
|
|
9886
|
+
else {
|
|
9887
|
+
e.sequenceFixLen(tickets_Ticket.Codec, x.tickets);
|
|
9888
|
+
}
|
|
9889
|
+
}, (d) => {
|
|
9890
|
+
const epochLength = context.epochLength;
|
|
9891
|
+
const kind = d.varU32();
|
|
9892
|
+
if (kind === SafroleSealingKeysKind.Keys) {
|
|
9893
|
+
const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
|
|
9894
|
+
return safrole_data_SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
|
|
9895
|
+
}
|
|
9896
|
+
if (kind === SafroleSealingKeysKind.Tickets) {
|
|
9897
|
+
const tickets = d.sequenceFixLen(tickets_Ticket.Codec, epochLength);
|
|
9898
|
+
return safrole_data_SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
|
|
9899
|
+
}
|
|
9900
|
+
throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
|
|
9901
|
+
}, (s) => {
|
|
9902
|
+
const kind = s.decoder.varU32();
|
|
9903
|
+
if (kind === SafroleSealingKeysKind.Keys) {
|
|
9904
|
+
s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
|
|
9905
|
+
return;
|
|
9906
|
+
}
|
|
9907
|
+
if (kind === SafroleSealingKeysKind.Tickets) {
|
|
9908
|
+
s.sequenceFixLen(tickets_Ticket.Codec, context.epochLength);
|
|
9909
|
+
return;
|
|
9910
|
+
}
|
|
9911
|
+
throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
|
|
9912
|
+
});
|
|
9913
|
+
});
|
|
9914
|
+
static keys(keys) {
|
|
9915
|
+
return new safrole_data_SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
|
|
9916
|
+
}
|
|
9917
|
+
static tickets(tickets) {
|
|
9918
|
+
return new safrole_data_SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
|
|
9919
|
+
}
|
|
9920
|
+
constructor(kind, keys, tickets) {
|
|
9921
|
+
super();
|
|
9922
|
+
this.kind = kind;
|
|
9923
|
+
this.keys = keys;
|
|
9924
|
+
this.tickets = tickets;
|
|
9925
|
+
}
|
|
9926
|
+
}
|
|
9927
|
+
class SafroleData {
|
|
9928
|
+
nextValidatorData;
|
|
9929
|
+
epochRoot;
|
|
9930
|
+
sealingKeySeries;
|
|
9931
|
+
ticketsAccumulator;
|
|
9932
|
+
static Codec = descriptors_codec.Class(SafroleData, {
|
|
9933
|
+
nextValidatorData: common_codecPerValidator(validator_data_ValidatorData.Codec),
|
|
9934
|
+
epochRoot: descriptors_codec.bytes(bandersnatch_BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
9935
|
+
sealingKeySeries: safrole_data_SafroleSealingKeysData.Codec,
|
|
9936
|
+
ticketsAccumulator: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(tickets_Ticket.Codec)).convert(seeThrough, sized_array_asKnownSize),
|
|
9937
|
+
});
|
|
9938
|
+
static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
|
|
9939
|
+
return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
|
|
9940
|
+
}
|
|
9941
|
+
constructor(
|
|
9942
|
+
/** gamma_k */
|
|
9943
|
+
nextValidatorData,
|
|
9944
|
+
/** gamma_z */
|
|
9945
|
+
epochRoot,
|
|
9946
|
+
/** gamma_s */
|
|
9947
|
+
sealingKeySeries,
|
|
9948
|
+
/** gamma_a */
|
|
9949
|
+
ticketsAccumulator) {
|
|
9950
|
+
this.nextValidatorData = nextValidatorData;
|
|
9951
|
+
this.epochRoot = epochRoot;
|
|
9952
|
+
this.sealingKeySeries = sealingKeySeries;
|
|
9953
|
+
this.ticketsAccumulator = ticketsAccumulator;
|
|
9954
|
+
}
|
|
9955
|
+
}
|
|
9956
|
+
|
|
9957
|
+
;// CONCATENATED MODULE: ./packages/jam/state/service.ts
|
|
9958
|
+
|
|
9959
|
+
|
|
9960
|
+
|
|
9961
|
+
|
|
9962
|
+
|
|
9963
|
+
|
|
9964
|
+
/**
|
|
9965
|
+
* `B_S`: The basic minimum balance which all services require.
|
|
9966
|
+
*
|
|
9967
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
9968
|
+
*/
|
|
9969
|
+
const BASE_SERVICE_BALANCE = 100n;
|
|
9970
|
+
/**
|
|
9971
|
+
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
9972
|
+
*
|
|
9973
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
9974
|
+
*/
|
|
9975
|
+
const ELECTIVE_ITEM_BALANCE = 10n;
|
|
9976
|
+
/**
|
|
9977
|
+
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
9978
|
+
*
|
|
9979
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
9980
|
+
*/
|
|
9981
|
+
const ELECTIVE_BYTE_BALANCE = 1n;
|
|
9651
9982
|
const zeroSizeHint = {
|
|
9652
9983
|
bytes: 0,
|
|
9653
9984
|
isExact: true,
|
|
@@ -9813,358 +10144,418 @@ class LookupHistoryItem {
|
|
|
9813
10144
|
}
|
|
9814
10145
|
}
|
|
9815
10146
|
|
|
9816
|
-
;// CONCATENATED MODULE: ./packages/jam/state/
|
|
10147
|
+
;// CONCATENATED MODULE: ./packages/jam/state/statistics.ts
|
|
9817
10148
|
|
|
9818
10149
|
|
|
9819
10150
|
|
|
9820
10151
|
|
|
9821
10152
|
|
|
9822
|
-
|
|
9823
|
-
|
|
9824
|
-
|
|
9825
|
-
|
|
9826
|
-
|
|
9827
|
-
|
|
9828
|
-
|
|
10153
|
+
|
|
10154
|
+
const codecServiceId = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
|
|
10155
|
+
? descriptors_codec.u32.asOpaque()
|
|
10156
|
+
: descriptors_codec.varU32.convert((s) => numbers_tryAsU32(s), (i) => tryAsServiceId(i));
|
|
10157
|
+
/**
|
|
10158
|
+
* Activity Record of a single validator.
|
|
10159
|
+
*
|
|
10160
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/183701183701
|
|
10161
|
+
*/
|
|
10162
|
+
class ValidatorStatistics {
|
|
10163
|
+
blocks;
|
|
10164
|
+
tickets;
|
|
10165
|
+
preImages;
|
|
10166
|
+
preImagesSize;
|
|
10167
|
+
guarantees;
|
|
10168
|
+
assurances;
|
|
10169
|
+
static Codec = descriptors_codec.Class(ValidatorStatistics, {
|
|
10170
|
+
blocks: descriptors_codec.u32,
|
|
10171
|
+
tickets: descriptors_codec.u32,
|
|
10172
|
+
preImages: descriptors_codec.u32,
|
|
10173
|
+
preImagesSize: descriptors_codec.u32,
|
|
10174
|
+
guarantees: descriptors_codec.u32,
|
|
10175
|
+
assurances: descriptors_codec.u32,
|
|
9829
10176
|
});
|
|
9830
|
-
static create({
|
|
9831
|
-
return new
|
|
10177
|
+
static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
|
|
10178
|
+
return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
|
|
9832
10179
|
}
|
|
9833
10180
|
constructor(
|
|
9834
|
-
/**
|
|
9835
|
-
|
|
9836
|
-
/**
|
|
9837
|
-
|
|
9838
|
-
|
|
9839
|
-
|
|
9840
|
-
|
|
9841
|
-
|
|
9842
|
-
/**
|
|
9843
|
-
|
|
9844
|
-
*/
|
|
9845
|
-
|
|
9846
|
-
|
|
9847
|
-
|
|
9848
|
-
|
|
9849
|
-
|
|
9850
|
-
|
|
9851
|
-
|
|
9852
|
-
static Codec = descriptors_codec.Class(PrivilegedServices, {
|
|
9853
|
-
manager: descriptors_codec.u32.asOpaque(),
|
|
9854
|
-
assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
|
|
9855
|
-
delegator: descriptors_codec.u32.asOpaque(),
|
|
9856
|
-
registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
9857
|
-
? descriptors_codec.u32.asOpaque()
|
|
9858
|
-
: ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
|
|
9859
|
-
autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
|
|
9860
|
-
});
|
|
9861
|
-
static create(a) {
|
|
9862
|
-
return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
10181
|
+
/** The number of blocks produced by the validator. */
|
|
10182
|
+
blocks,
|
|
10183
|
+
/** The number of tickets introduced by the validator. */
|
|
10184
|
+
tickets,
|
|
10185
|
+
/** The number of preimages introduced by the validator. */
|
|
10186
|
+
preImages,
|
|
10187
|
+
/** The total number of octets across all preimages introduced by the validator. */
|
|
10188
|
+
preImagesSize,
|
|
10189
|
+
/** The number of reports guaranteed by the validator. */
|
|
10190
|
+
guarantees,
|
|
10191
|
+
/** The number of availability assurances made by the validator. */
|
|
10192
|
+
assurances) {
|
|
10193
|
+
this.blocks = blocks;
|
|
10194
|
+
this.tickets = tickets;
|
|
10195
|
+
this.preImages = preImages;
|
|
10196
|
+
this.preImagesSize = preImagesSize;
|
|
10197
|
+
this.guarantees = guarantees;
|
|
10198
|
+
this.assurances = assurances;
|
|
9863
10199
|
}
|
|
9864
|
-
|
|
9865
|
-
|
|
9866
|
-
|
|
9867
|
-
* as well as bestow services with storage deposit credits.
|
|
9868
|
-
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
9869
|
-
*/
|
|
9870
|
-
manager,
|
|
9871
|
-
/** `χ_V`: Managers validator keys. */
|
|
9872
|
-
delegator,
|
|
9873
|
-
/**
|
|
9874
|
-
* `χ_R`: Manages the creation of services in protected range.
|
|
9875
|
-
*
|
|
9876
|
-
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
|
|
9877
|
-
*/
|
|
9878
|
-
registrar,
|
|
9879
|
-
/** `χ_A`: Manages authorization queue one for each core. */
|
|
9880
|
-
assigners,
|
|
9881
|
-
/** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
|
|
9882
|
-
autoAccumulateServices) {
|
|
9883
|
-
this.manager = manager;
|
|
9884
|
-
this.delegator = delegator;
|
|
9885
|
-
this.registrar = registrar;
|
|
9886
|
-
this.assigners = assigners;
|
|
9887
|
-
this.autoAccumulateServices = autoAccumulateServices;
|
|
10200
|
+
static empty() {
|
|
10201
|
+
const zero = numbers_tryAsU32(0);
|
|
10202
|
+
return new ValidatorStatistics(zero, zero, zero, zero, zero, zero);
|
|
9888
10203
|
}
|
|
9889
10204
|
}
|
|
9890
|
-
|
|
9891
|
-
|
|
9892
|
-
|
|
9893
|
-
|
|
9894
|
-
|
|
9895
|
-
|
|
9896
|
-
|
|
9897
|
-
|
|
10205
|
+
const codecVarU16 = descriptors_codec.varU32.convert((i) => numbers_tryAsU32(i), (o) => numbers_tryAsU16(o));
|
|
10206
|
+
/** Encode/decode unsigned gas. */
|
|
10207
|
+
const codecVarGas = descriptors_codec.varU64.convert((g) => numbers_tryAsU64(g), (i) => tryAsServiceGas(i));
|
|
9898
10208
|
/**
|
|
9899
|
-
*
|
|
10209
|
+
* Single core statistics.
|
|
10210
|
+
* Updated per block, based on incoming work reports (`w`).
|
|
9900
10211
|
*
|
|
9901
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
10212
|
+
* https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
|
|
10213
|
+
* https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
|
|
9902
10214
|
*/
|
|
9903
|
-
|
|
9904
|
-
|
|
9905
|
-
|
|
9906
|
-
|
|
9907
|
-
|
|
9908
|
-
|
|
9909
|
-
|
|
9910
|
-
|
|
9911
|
-
|
|
9912
|
-
|
|
9913
|
-
|
|
9914
|
-
|
|
9915
|
-
|
|
9916
|
-
|
|
9917
|
-
|
|
10215
|
+
class CoreStatistics {
|
|
10216
|
+
dataAvailabilityLoad;
|
|
10217
|
+
popularity;
|
|
10218
|
+
imports;
|
|
10219
|
+
exports;
|
|
10220
|
+
extrinsicSize;
|
|
10221
|
+
extrinsicCount;
|
|
10222
|
+
bundleSize;
|
|
10223
|
+
gasUsed;
|
|
10224
|
+
static Codec = Compatibility.isGreaterOrEqual(GpVersion.V0_7_0)
|
|
10225
|
+
? descriptors_codec.Class(CoreStatistics, {
|
|
10226
|
+
dataAvailabilityLoad: descriptors_codec.varU32,
|
|
10227
|
+
popularity: codecVarU16,
|
|
10228
|
+
imports: codecVarU16,
|
|
10229
|
+
extrinsicCount: codecVarU16,
|
|
10230
|
+
extrinsicSize: descriptors_codec.varU32,
|
|
10231
|
+
exports: codecVarU16,
|
|
10232
|
+
bundleSize: descriptors_codec.varU32,
|
|
10233
|
+
gasUsed: codecVarGas,
|
|
10234
|
+
})
|
|
10235
|
+
: descriptors_codec.Class(CoreStatistics, {
|
|
10236
|
+
dataAvailabilityLoad: descriptors_codec.varU32,
|
|
10237
|
+
popularity: codecVarU16,
|
|
10238
|
+
imports: codecVarU16,
|
|
10239
|
+
exports: codecVarU16,
|
|
10240
|
+
extrinsicSize: descriptors_codec.varU32,
|
|
10241
|
+
extrinsicCount: codecVarU16,
|
|
10242
|
+
bundleSize: descriptors_codec.varU32,
|
|
10243
|
+
gasUsed: codecVarGas,
|
|
10244
|
+
});
|
|
10245
|
+
static create(v) {
|
|
10246
|
+
return new CoreStatistics(v.dataAvailabilityLoad, v.popularity, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.bundleSize, v.gasUsed);
|
|
9918
10247
|
}
|
|
9919
10248
|
constructor(
|
|
9920
|
-
/**
|
|
9921
|
-
|
|
9922
|
-
/**
|
|
9923
|
-
|
|
9924
|
-
/**
|
|
9925
|
-
|
|
9926
|
-
/**
|
|
9927
|
-
|
|
9928
|
-
|
|
9929
|
-
|
|
9930
|
-
|
|
9931
|
-
|
|
9932
|
-
|
|
9933
|
-
|
|
9934
|
-
|
|
9935
|
-
|
|
9936
|
-
|
|
9937
|
-
|
|
9938
|
-
|
|
9939
|
-
|
|
9940
|
-
|
|
9941
|
-
|
|
9942
|
-
|
|
9943
|
-
|
|
9944
|
-
accumulationLog: descriptors_codec.object({
|
|
9945
|
-
peaks: readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.optional(descriptors_codec.bytes(hash_HASH_SIZE)))),
|
|
9946
|
-
}),
|
|
9947
|
-
});
|
|
9948
|
-
static create(a) {
|
|
9949
|
-
return new RecentBlocks(a.blocks, a.accumulationLog);
|
|
10249
|
+
/** `d` */
|
|
10250
|
+
dataAvailabilityLoad,
|
|
10251
|
+
/** `p` */
|
|
10252
|
+
popularity,
|
|
10253
|
+
/** `i` */
|
|
10254
|
+
imports,
|
|
10255
|
+
/** `e` */
|
|
10256
|
+
exports,
|
|
10257
|
+
/** `z` */
|
|
10258
|
+
extrinsicSize,
|
|
10259
|
+
/** `x` */
|
|
10260
|
+
extrinsicCount,
|
|
10261
|
+
/** `b` */
|
|
10262
|
+
bundleSize,
|
|
10263
|
+
/** `u` */
|
|
10264
|
+
gasUsed) {
|
|
10265
|
+
this.dataAvailabilityLoad = dataAvailabilityLoad;
|
|
10266
|
+
this.popularity = popularity;
|
|
10267
|
+
this.imports = imports;
|
|
10268
|
+
this.exports = exports;
|
|
10269
|
+
this.extrinsicSize = extrinsicSize;
|
|
10270
|
+
this.extrinsicCount = extrinsicCount;
|
|
10271
|
+
this.bundleSize = bundleSize;
|
|
10272
|
+
this.gasUsed = gasUsed;
|
|
9950
10273
|
}
|
|
9951
|
-
|
|
9952
|
-
|
|
9953
|
-
|
|
9954
|
-
|
|
9955
|
-
|
|
9956
|
-
blocks,
|
|
9957
|
-
/**
|
|
9958
|
-
* Accumulation output log.
|
|
9959
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0f02020f0202?v=0.6.7
|
|
9960
|
-
*/
|
|
9961
|
-
accumulationLog) {
|
|
9962
|
-
super();
|
|
9963
|
-
this.blocks = blocks;
|
|
9964
|
-
this.accumulationLog = accumulationLog;
|
|
10274
|
+
static empty() {
|
|
10275
|
+
const zero = numbers_tryAsU32(0);
|
|
10276
|
+
const zero16 = numbers_tryAsU16(0);
|
|
10277
|
+
const zeroGas = tryAsServiceGas(0);
|
|
10278
|
+
return new CoreStatistics(zero, zero16, zero16, zero16, zero, zero16, zero, zeroGas);
|
|
9965
10279
|
}
|
|
9966
10280
|
}
|
|
9967
10281
|
/**
|
|
9968
|
-
*
|
|
10282
|
+
* Service statistics.
|
|
10283
|
+
* Updated per block, based on available work reports (`W`).
|
|
9969
10284
|
*
|
|
9970
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
10285
|
+
* https://graypaper.fluffylabs.dev/#/1c979cb/199802199802?v=0.7.1
|
|
9971
10286
|
*/
|
|
9972
|
-
class
|
|
9973
|
-
|
|
9974
|
-
|
|
9975
|
-
|
|
9976
|
-
|
|
9977
|
-
|
|
9978
|
-
|
|
10287
|
+
class ServiceStatistics {
|
|
10288
|
+
providedCount;
|
|
10289
|
+
providedSize;
|
|
10290
|
+
refinementCount;
|
|
10291
|
+
refinementGasUsed;
|
|
10292
|
+
imports;
|
|
10293
|
+
exports;
|
|
10294
|
+
extrinsicSize;
|
|
10295
|
+
extrinsicCount;
|
|
10296
|
+
accumulateCount;
|
|
10297
|
+
accumulateGasUsed;
|
|
10298
|
+
onTransfersCount;
|
|
10299
|
+
onTransfersGasUsed;
|
|
10300
|
+
static Codec = Compatibility.selectIfGreaterOrEqual({
|
|
10301
|
+
fallback: descriptors_codec.Class(ServiceStatistics, {
|
|
10302
|
+
providedCount: codecVarU16,
|
|
10303
|
+
providedSize: descriptors_codec.varU32,
|
|
10304
|
+
refinementCount: descriptors_codec.varU32,
|
|
10305
|
+
refinementGasUsed: codecVarGas,
|
|
10306
|
+
imports: codecVarU16,
|
|
10307
|
+
exports: codecVarU16,
|
|
10308
|
+
extrinsicSize: descriptors_codec.varU32,
|
|
10309
|
+
extrinsicCount: codecVarU16,
|
|
10310
|
+
accumulateCount: descriptors_codec.varU32,
|
|
10311
|
+
accumulateGasUsed: codecVarGas,
|
|
10312
|
+
onTransfersCount: descriptors_codec.varU32,
|
|
10313
|
+
onTransfersGasUsed: codecVarGas,
|
|
10314
|
+
}),
|
|
10315
|
+
versions: {
|
|
10316
|
+
[GpVersion.V0_7_0]: descriptors_codec.Class(ServiceStatistics, {
|
|
10317
|
+
providedCount: codecVarU16,
|
|
10318
|
+
providedSize: descriptors_codec.varU32,
|
|
10319
|
+
refinementCount: descriptors_codec.varU32,
|
|
10320
|
+
refinementGasUsed: codecVarGas,
|
|
10321
|
+
imports: codecVarU16,
|
|
10322
|
+
extrinsicCount: codecVarU16,
|
|
10323
|
+
extrinsicSize: descriptors_codec.varU32,
|
|
10324
|
+
exports: codecVarU16,
|
|
10325
|
+
accumulateCount: descriptors_codec.varU32,
|
|
10326
|
+
accumulateGasUsed: codecVarGas,
|
|
10327
|
+
onTransfersCount: descriptors_codec.varU32,
|
|
10328
|
+
onTransfersGasUsed: codecVarGas,
|
|
10329
|
+
}),
|
|
10330
|
+
[GpVersion.V0_7_1]: descriptors_codec.Class(ServiceStatistics, {
|
|
10331
|
+
providedCount: codecVarU16,
|
|
10332
|
+
providedSize: descriptors_codec.varU32,
|
|
10333
|
+
refinementCount: descriptors_codec.varU32,
|
|
10334
|
+
refinementGasUsed: codecVarGas,
|
|
10335
|
+
imports: codecVarU16,
|
|
10336
|
+
extrinsicCount: codecVarU16,
|
|
10337
|
+
extrinsicSize: descriptors_codec.varU32,
|
|
10338
|
+
exports: codecVarU16,
|
|
10339
|
+
accumulateCount: descriptors_codec.varU32,
|
|
10340
|
+
accumulateGasUsed: codecVarGas,
|
|
10341
|
+
onTransfersCount: ignoreValueWithDefault(numbers_tryAsU32(0)),
|
|
10342
|
+
onTransfersGasUsed: ignoreValueWithDefault(tryAsServiceGas(0)),
|
|
10343
|
+
}),
|
|
10344
|
+
},
|
|
9979
10345
|
});
|
|
9980
|
-
static create(
|
|
9981
|
-
return new
|
|
10346
|
+
static create(v) {
|
|
10347
|
+
return new ServiceStatistics(v.providedCount, v.providedSize, v.refinementCount, v.refinementGasUsed, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.accumulateCount, v.accumulateGasUsed, v.onTransfersCount, v.onTransfersGasUsed);
|
|
10348
|
+
}
|
|
10349
|
+
constructor(
|
|
10350
|
+
/** `p.0` */
|
|
10351
|
+
providedCount,
|
|
10352
|
+
/** `p.1` */
|
|
10353
|
+
providedSize,
|
|
10354
|
+
/** `r.0` */
|
|
10355
|
+
refinementCount,
|
|
10356
|
+
/** `r.1` */
|
|
10357
|
+
refinementGasUsed,
|
|
10358
|
+
/** `i` */
|
|
10359
|
+
imports,
|
|
10360
|
+
/** `e` */
|
|
10361
|
+
exports,
|
|
10362
|
+
/** `z` */
|
|
10363
|
+
extrinsicSize,
|
|
10364
|
+
/** `x` */
|
|
10365
|
+
extrinsicCount,
|
|
10366
|
+
/** `a.0` */
|
|
10367
|
+
accumulateCount,
|
|
10368
|
+
/** `a.1` */
|
|
10369
|
+
accumulateGasUsed,
|
|
10370
|
+
/** `t.0` @deprecated since 0.7.1 */
|
|
10371
|
+
onTransfersCount,
|
|
10372
|
+
/** `t.1` @deprecated since 0.7.1 */
|
|
10373
|
+
onTransfersGasUsed) {
|
|
10374
|
+
this.providedCount = providedCount;
|
|
10375
|
+
this.providedSize = providedSize;
|
|
10376
|
+
this.refinementCount = refinementCount;
|
|
10377
|
+
this.refinementGasUsed = refinementGasUsed;
|
|
10378
|
+
this.imports = imports;
|
|
10379
|
+
this.exports = exports;
|
|
10380
|
+
this.extrinsicSize = extrinsicSize;
|
|
10381
|
+
this.extrinsicCount = extrinsicCount;
|
|
10382
|
+
this.accumulateCount = accumulateCount;
|
|
10383
|
+
this.accumulateGasUsed = accumulateGasUsed;
|
|
10384
|
+
this.onTransfersCount = onTransfersCount;
|
|
10385
|
+
this.onTransfersGasUsed = onTransfersGasUsed;
|
|
9982
10386
|
}
|
|
9983
10387
|
static empty() {
|
|
9984
|
-
|
|
9985
|
-
|
|
9986
|
-
|
|
9987
|
-
|
|
10388
|
+
const zero = numbers_tryAsU32(0);
|
|
10389
|
+
const zero16 = numbers_tryAsU16(0);
|
|
10390
|
+
const zeroGas = tryAsServiceGas(0);
|
|
10391
|
+
return new ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
|
|
9988
10392
|
}
|
|
9989
|
-
|
|
9990
|
-
|
|
9991
|
-
|
|
9992
|
-
|
|
9993
|
-
|
|
10393
|
+
}
|
|
10394
|
+
/** `pi`: Statistics of each validator, cores statistics and services statistics. */
|
|
10395
|
+
class StatisticsData {
|
|
10396
|
+
current;
|
|
10397
|
+
previous;
|
|
10398
|
+
cores;
|
|
10399
|
+
services;
|
|
10400
|
+
static Codec = descriptors_codec.Class(StatisticsData, {
|
|
10401
|
+
current: common_codecPerValidator(ValidatorStatistics.Codec),
|
|
10402
|
+
previous: common_codecPerValidator(ValidatorStatistics.Codec),
|
|
10403
|
+
cores: codecPerCore(CoreStatistics.Codec),
|
|
10404
|
+
services: descriptors_codec.dictionary(codecServiceId, ServiceStatistics.Codec, {
|
|
10405
|
+
sortKeys: (a, b) => a - b,
|
|
10406
|
+
}),
|
|
10407
|
+
});
|
|
10408
|
+
static create(v) {
|
|
10409
|
+
return new StatisticsData(v.current, v.previous, v.cores, v.services);
|
|
9994
10410
|
}
|
|
9995
|
-
constructor(current) {
|
|
9996
|
-
super();
|
|
10411
|
+
constructor(current, previous, cores, services) {
|
|
9997
10412
|
this.current = current;
|
|
9998
|
-
|
|
9999
|
-
|
|
10000
|
-
|
|
10001
|
-
if (this.current !== null) {
|
|
10002
|
-
return this.current.blocks;
|
|
10003
|
-
}
|
|
10004
|
-
throw new Error("RecentBlocksHistory is in invalid state");
|
|
10005
|
-
}
|
|
10006
|
-
asCurrent() {
|
|
10007
|
-
if (this.current === null) {
|
|
10008
|
-
throw new Error("Cannot access current RecentBlocks format");
|
|
10009
|
-
}
|
|
10010
|
-
return this.current;
|
|
10011
|
-
}
|
|
10012
|
-
updateBlocks(blocks) {
|
|
10013
|
-
if (this.current !== null) {
|
|
10014
|
-
return RecentBlocksHistory.create(RecentBlocks.create({
|
|
10015
|
-
...this.current,
|
|
10016
|
-
blocks: opaque_asOpaqueType(blocks),
|
|
10017
|
-
}));
|
|
10018
|
-
}
|
|
10019
|
-
throw new Error("RecentBlocksHistory is in invalid state. Cannot be updated!");
|
|
10413
|
+
this.previous = previous;
|
|
10414
|
+
this.cores = cores;
|
|
10415
|
+
this.services = services;
|
|
10020
10416
|
}
|
|
10021
10417
|
}
|
|
10022
10418
|
|
|
10023
|
-
;// CONCATENATED MODULE: ./packages/jam/state/
|
|
10419
|
+
;// CONCATENATED MODULE: ./packages/jam/state/in-memory-state-view.ts
|
|
10024
10420
|
|
|
10025
10421
|
|
|
10026
10422
|
|
|
10027
|
-
/**
|
|
10028
|
-
* Fixed size of validator metadata.
|
|
10029
|
-
*
|
|
10030
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/0d55010d5501
|
|
10031
|
-
*/
|
|
10032
|
-
const VALIDATOR_META_BYTES = 128;
|
|
10033
|
-
/**
|
|
10034
|
-
* Details about validators' identity.
|
|
10035
|
-
*
|
|
10036
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/0d4b010d4c01
|
|
10037
|
-
*/
|
|
10038
|
-
class ValidatorData extends WithDebug {
|
|
10039
|
-
bandersnatch;
|
|
10040
|
-
ed25519;
|
|
10041
|
-
bls;
|
|
10042
|
-
metadata;
|
|
10043
|
-
static Codec = descriptors_codec.Class(ValidatorData, {
|
|
10044
|
-
bandersnatch: descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
10045
|
-
ed25519: descriptors_codec.bytes(ED25519_KEY_BYTES).asOpaque(),
|
|
10046
|
-
bls: descriptors_codec.bytes(BLS_KEY_BYTES).asOpaque(),
|
|
10047
|
-
metadata: descriptors_codec.bytes(VALIDATOR_META_BYTES),
|
|
10048
|
-
});
|
|
10049
|
-
static create({ ed25519, bandersnatch, bls, metadata }) {
|
|
10050
|
-
return new ValidatorData(bandersnatch, ed25519, bls, metadata);
|
|
10051
|
-
}
|
|
10052
|
-
constructor(
|
|
10053
|
-
/** Bandersnatch public key. */
|
|
10054
|
-
bandersnatch,
|
|
10055
|
-
/** ED25519 key data. */
|
|
10056
|
-
ed25519,
|
|
10057
|
-
/** BLS public key. */
|
|
10058
|
-
bls,
|
|
10059
|
-
/** Validator-defined additional metdata. */
|
|
10060
|
-
metadata) {
|
|
10061
|
-
super();
|
|
10062
|
-
this.bandersnatch = bandersnatch;
|
|
10063
|
-
this.ed25519 = ed25519;
|
|
10064
|
-
this.bls = bls;
|
|
10065
|
-
this.metadata = metadata;
|
|
10066
|
-
}
|
|
10067
|
-
}
|
|
10068
10423
|
|
|
10069
|
-
;// CONCATENATED MODULE: ./packages/jam/state/safrole-data.ts
|
|
10070
10424
|
|
|
10071
10425
|
|
|
10072
10426
|
|
|
10073
10427
|
|
|
10074
10428
|
|
|
10075
10429
|
|
|
10430
|
+
class InMemoryStateView {
|
|
10431
|
+
chainSpec;
|
|
10432
|
+
state;
|
|
10433
|
+
constructor(chainSpec, state) {
|
|
10434
|
+
this.chainSpec = chainSpec;
|
|
10435
|
+
this.state = state;
|
|
10436
|
+
}
|
|
10437
|
+
availabilityAssignmentView() {
|
|
10438
|
+
return reencodeAsView(availabilityAssignmentsCodec, this.state.availabilityAssignment, this.chainSpec);
|
|
10439
|
+
}
|
|
10440
|
+
designatedValidatorDataView() {
|
|
10441
|
+
return reencodeAsView(validatorsDataCodec, this.state.designatedValidatorData, this.chainSpec);
|
|
10442
|
+
}
|
|
10443
|
+
currentValidatorDataView() {
|
|
10444
|
+
return reencodeAsView(validatorsDataCodec, this.state.currentValidatorData, this.chainSpec);
|
|
10445
|
+
}
|
|
10446
|
+
previousValidatorDataView() {
|
|
10447
|
+
return reencodeAsView(validatorsDataCodec, this.state.previousValidatorData, this.chainSpec);
|
|
10448
|
+
}
|
|
10449
|
+
authPoolsView() {
|
|
10450
|
+
return reencodeAsView(authPoolsCodec, this.state.authPools, this.chainSpec);
|
|
10451
|
+
}
|
|
10452
|
+
authQueuesView() {
|
|
10453
|
+
return reencodeAsView(authQueuesCodec, this.state.authQueues, this.chainSpec);
|
|
10454
|
+
}
|
|
10455
|
+
recentBlocksView() {
|
|
10456
|
+
return reencodeAsView(RecentBlocks.Codec, this.state.recentBlocks, this.chainSpec);
|
|
10457
|
+
}
|
|
10458
|
+
statisticsView() {
|
|
10459
|
+
return reencodeAsView(StatisticsData.Codec, this.state.statistics, this.chainSpec);
|
|
10460
|
+
}
|
|
10461
|
+
accumulationQueueView() {
|
|
10462
|
+
return reencodeAsView(accumulationQueueCodec, this.state.accumulationQueue, this.chainSpec);
|
|
10463
|
+
}
|
|
10464
|
+
recentlyAccumulatedView() {
|
|
10465
|
+
return reencodeAsView(recentlyAccumulatedCodec, this.state.recentlyAccumulated, this.chainSpec);
|
|
10466
|
+
}
|
|
10467
|
+
safroleDataView() {
|
|
10468
|
+
// TODO [ToDr] Consider exposting `safrole` from state
|
|
10469
|
+
// instead of individual fields
|
|
10470
|
+
const safrole = SafroleData.create({
|
|
10471
|
+
nextValidatorData: this.state.nextValidatorData,
|
|
10472
|
+
epochRoot: this.state.epochRoot,
|
|
10473
|
+
sealingKeySeries: this.state.sealingKeySeries,
|
|
10474
|
+
ticketsAccumulator: this.state.ticketsAccumulator,
|
|
10475
|
+
});
|
|
10476
|
+
return reencodeAsView(SafroleData.Codec, safrole, this.chainSpec);
|
|
10477
|
+
}
|
|
10478
|
+
getServiceInfoView(id) {
|
|
10479
|
+
const service = this.state.getService(id);
|
|
10480
|
+
if (service === null) {
|
|
10481
|
+
return null;
|
|
10482
|
+
}
|
|
10483
|
+
return reencodeAsView(ServiceAccountInfo.Codec, service.getInfo(), this.chainSpec);
|
|
10484
|
+
}
|
|
10485
|
+
}
|
|
10076
10486
|
|
|
10487
|
+
;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
|
|
10077
10488
|
|
|
10078
10489
|
|
|
10079
10490
|
|
|
10080
10491
|
|
|
10081
|
-
|
|
10082
|
-
|
|
10083
|
-
|
|
10084
|
-
|
|
10085
|
-
|
|
10086
|
-
|
|
10087
|
-
|
|
10088
|
-
|
|
10089
|
-
keys;
|
|
10090
|
-
tickets;
|
|
10091
|
-
static Codec = codecWithContext((context) => {
|
|
10092
|
-
return descriptors_codec.custom({
|
|
10093
|
-
name: "SafroleSealingKeys",
|
|
10094
|
-
sizeHint: { bytes: 1 + hash_HASH_SIZE * context.epochLength, isExact: false },
|
|
10095
|
-
}, (e, x) => {
|
|
10096
|
-
e.varU32(numbers_tryAsU32(x.kind));
|
|
10097
|
-
if (x.kind === SafroleSealingKeysKind.Keys) {
|
|
10098
|
-
e.sequenceFixLen(codecBandersnatchKey, x.keys);
|
|
10099
|
-
}
|
|
10100
|
-
else {
|
|
10101
|
-
e.sequenceFixLen(Ticket.Codec, x.tickets);
|
|
10102
|
-
}
|
|
10103
|
-
}, (d) => {
|
|
10104
|
-
const epochLength = context.epochLength;
|
|
10105
|
-
const kind = d.varU32();
|
|
10106
|
-
if (kind === SafroleSealingKeysKind.Keys) {
|
|
10107
|
-
const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
|
|
10108
|
-
return SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
|
|
10109
|
-
}
|
|
10110
|
-
if (kind === SafroleSealingKeysKind.Tickets) {
|
|
10111
|
-
const tickets = d.sequenceFixLen(Ticket.Codec, epochLength);
|
|
10112
|
-
return SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
|
|
10113
|
-
}
|
|
10114
|
-
throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
|
|
10115
|
-
}, (s) => {
|
|
10116
|
-
const kind = s.decoder.varU32();
|
|
10117
|
-
if (kind === SafroleSealingKeysKind.Keys) {
|
|
10118
|
-
s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
|
|
10119
|
-
return;
|
|
10120
|
-
}
|
|
10121
|
-
if (kind === SafroleSealingKeysKind.Tickets) {
|
|
10122
|
-
s.sequenceFixLen(Ticket.Codec, context.epochLength);
|
|
10123
|
-
return;
|
|
10124
|
-
}
|
|
10125
|
-
throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
|
|
10126
|
-
});
|
|
10492
|
+
|
|
10493
|
+
/** Dictionary entry of services that auto-accumulate every block. */
|
|
10494
|
+
class AutoAccumulate {
|
|
10495
|
+
service;
|
|
10496
|
+
gasLimit;
|
|
10497
|
+
static Codec = descriptors_codec.Class(AutoAccumulate, {
|
|
10498
|
+
service: descriptors_codec.u32.asOpaque(),
|
|
10499
|
+
gasLimit: descriptors_codec.u64.asOpaque(),
|
|
10127
10500
|
});
|
|
10128
|
-
static
|
|
10129
|
-
return new
|
|
10130
|
-
}
|
|
10131
|
-
static tickets(tickets) {
|
|
10132
|
-
return new SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
|
|
10501
|
+
static create({ service, gasLimit }) {
|
|
10502
|
+
return new AutoAccumulate(service, gasLimit);
|
|
10133
10503
|
}
|
|
10134
|
-
constructor(
|
|
10135
|
-
|
|
10136
|
-
|
|
10137
|
-
|
|
10138
|
-
|
|
10504
|
+
constructor(
|
|
10505
|
+
/** Service id that auto-accumulates. */
|
|
10506
|
+
service,
|
|
10507
|
+
/** Gas limit for auto-accumulation. */
|
|
10508
|
+
gasLimit) {
|
|
10509
|
+
this.service = service;
|
|
10510
|
+
this.gasLimit = gasLimit;
|
|
10139
10511
|
}
|
|
10140
10512
|
}
|
|
10141
|
-
|
|
10142
|
-
|
|
10143
|
-
|
|
10144
|
-
|
|
10145
|
-
|
|
10146
|
-
|
|
10147
|
-
|
|
10148
|
-
|
|
10149
|
-
|
|
10150
|
-
|
|
10513
|
+
/**
|
|
10514
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
|
|
10515
|
+
*/
|
|
10516
|
+
class PrivilegedServices {
|
|
10517
|
+
manager;
|
|
10518
|
+
delegator;
|
|
10519
|
+
registrar;
|
|
10520
|
+
assigners;
|
|
10521
|
+
autoAccumulateServices;
|
|
10522
|
+
/** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
|
|
10523
|
+
static Codec = descriptors_codec.Class(PrivilegedServices, {
|
|
10524
|
+
manager: descriptors_codec.u32.asOpaque(),
|
|
10525
|
+
assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
|
|
10526
|
+
delegator: descriptors_codec.u32.asOpaque(),
|
|
10527
|
+
registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
10528
|
+
? descriptors_codec.u32.asOpaque()
|
|
10529
|
+
: ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
|
|
10530
|
+
autoAccumulateServices: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
|
|
10151
10531
|
});
|
|
10152
|
-
static create(
|
|
10153
|
-
return new
|
|
10532
|
+
static create(a) {
|
|
10533
|
+
return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
10154
10534
|
}
|
|
10155
10535
|
constructor(
|
|
10156
|
-
/**
|
|
10157
|
-
|
|
10158
|
-
|
|
10159
|
-
|
|
10160
|
-
|
|
10161
|
-
|
|
10162
|
-
/**
|
|
10163
|
-
|
|
10164
|
-
|
|
10165
|
-
|
|
10166
|
-
|
|
10167
|
-
|
|
10536
|
+
/**
|
|
10537
|
+
* `χ_M`: Manages alteration of χ from block to block,
|
|
10538
|
+
* as well as bestow services with storage deposit credits.
|
|
10539
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
10540
|
+
*/
|
|
10541
|
+
manager,
|
|
10542
|
+
/** `χ_V`: Managers validator keys. */
|
|
10543
|
+
delegator,
|
|
10544
|
+
/**
|
|
10545
|
+
* `χ_R`: Manages the creation of services in protected range.
|
|
10546
|
+
*
|
|
10547
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
|
|
10548
|
+
*/
|
|
10549
|
+
registrar,
|
|
10550
|
+
/** `χ_A`: Manages authorization queue one for each core. */
|
|
10551
|
+
assigners,
|
|
10552
|
+
/** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
|
|
10553
|
+
autoAccumulateServices) {
|
|
10554
|
+
this.manager = manager;
|
|
10555
|
+
this.delegator = delegator;
|
|
10556
|
+
this.registrar = registrar;
|
|
10557
|
+
this.assigners = assigners;
|
|
10558
|
+
this.autoAccumulateServices = autoAccumulateServices;
|
|
10168
10559
|
}
|
|
10169
10560
|
}
|
|
10170
10561
|
|
|
@@ -10286,318 +10677,46 @@ class UpdateService {
|
|
|
10286
10677
|
kind: UpdateServiceKind.Create,
|
|
10287
10678
|
account: serviceInfo,
|
|
10288
10679
|
lookupHistory,
|
|
10289
|
-
});
|
|
10290
|
-
}
|
|
10291
|
-
}
|
|
10292
|
-
/** Update service storage kind. */
|
|
10293
|
-
var UpdateStorageKind;
|
|
10294
|
-
(function (UpdateStorageKind) {
|
|
10295
|
-
/** Set a storage value. */
|
|
10296
|
-
UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
|
|
10297
|
-
/** Remove a storage value. */
|
|
10298
|
-
UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
|
|
10299
|
-
})(UpdateStorageKind || (UpdateStorageKind = {}));
|
|
10300
|
-
/**
|
|
10301
|
-
* Update service storage item.
|
|
10302
|
-
*
|
|
10303
|
-
* Can either create/modify an entry or remove it.
|
|
10304
|
-
*/
|
|
10305
|
-
class UpdateStorage {
|
|
10306
|
-
serviceId;
|
|
10307
|
-
action;
|
|
10308
|
-
constructor(serviceId, action) {
|
|
10309
|
-
this.serviceId = serviceId;
|
|
10310
|
-
this.action = action;
|
|
10311
|
-
}
|
|
10312
|
-
static set({ serviceId, storage }) {
|
|
10313
|
-
return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Set, storage });
|
|
10314
|
-
}
|
|
10315
|
-
static remove({ serviceId, key }) {
|
|
10316
|
-
return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Remove, key });
|
|
10317
|
-
}
|
|
10318
|
-
get key() {
|
|
10319
|
-
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
10320
|
-
return this.action.key;
|
|
10321
|
-
}
|
|
10322
|
-
return this.action.storage.key;
|
|
10323
|
-
}
|
|
10324
|
-
get value() {
|
|
10325
|
-
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
10326
|
-
return null;
|
|
10327
|
-
}
|
|
10328
|
-
return this.action.storage.value;
|
|
10329
|
-
}
|
|
10330
|
-
}
|
|
10331
|
-
|
|
10332
|
-
;// CONCATENATED MODULE: ./packages/jam/state/statistics.ts
|
|
10333
|
-
|
|
10334
|
-
|
|
10335
|
-
|
|
10336
|
-
|
|
10337
|
-
|
|
10338
|
-
|
|
10339
|
-
const codecServiceId = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
|
|
10340
|
-
? descriptors_codec.u32.asOpaque()
|
|
10341
|
-
: descriptors_codec.varU32.convert((s) => numbers_tryAsU32(s), (i) => tryAsServiceId(i));
|
|
10342
|
-
/**
|
|
10343
|
-
* Activity Record of a single validator.
|
|
10344
|
-
*
|
|
10345
|
-
* https://graypaper.fluffylabs.dev/#/579bd12/183701183701
|
|
10346
|
-
*/
|
|
10347
|
-
class ValidatorStatistics {
|
|
10348
|
-
blocks;
|
|
10349
|
-
tickets;
|
|
10350
|
-
preImages;
|
|
10351
|
-
preImagesSize;
|
|
10352
|
-
guarantees;
|
|
10353
|
-
assurances;
|
|
10354
|
-
static Codec = descriptors_codec.Class(ValidatorStatistics, {
|
|
10355
|
-
blocks: descriptors_codec.u32,
|
|
10356
|
-
tickets: descriptors_codec.u32,
|
|
10357
|
-
preImages: descriptors_codec.u32,
|
|
10358
|
-
preImagesSize: descriptors_codec.u32,
|
|
10359
|
-
guarantees: descriptors_codec.u32,
|
|
10360
|
-
assurances: descriptors_codec.u32,
|
|
10361
|
-
});
|
|
10362
|
-
static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
|
|
10363
|
-
return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
|
|
10364
|
-
}
|
|
10365
|
-
constructor(
|
|
10366
|
-
/** The number of blocks produced by the validator. */
|
|
10367
|
-
blocks,
|
|
10368
|
-
/** The number of tickets introduced by the validator. */
|
|
10369
|
-
tickets,
|
|
10370
|
-
/** The number of preimages introduced by the validator. */
|
|
10371
|
-
preImages,
|
|
10372
|
-
/** The total number of octets across all preimages introduced by the validator. */
|
|
10373
|
-
preImagesSize,
|
|
10374
|
-
/** The number of reports guaranteed by the validator. */
|
|
10375
|
-
guarantees,
|
|
10376
|
-
/** The number of availability assurances made by the validator. */
|
|
10377
|
-
assurances) {
|
|
10378
|
-
this.blocks = blocks;
|
|
10379
|
-
this.tickets = tickets;
|
|
10380
|
-
this.preImages = preImages;
|
|
10381
|
-
this.preImagesSize = preImagesSize;
|
|
10382
|
-
this.guarantees = guarantees;
|
|
10383
|
-
this.assurances = assurances;
|
|
10384
|
-
}
|
|
10385
|
-
static empty() {
|
|
10386
|
-
const zero = numbers_tryAsU32(0);
|
|
10387
|
-
return new ValidatorStatistics(zero, zero, zero, zero, zero, zero);
|
|
10388
|
-
}
|
|
10389
|
-
}
|
|
10390
|
-
const codecVarU16 = descriptors_codec.varU32.convert((i) => numbers_tryAsU32(i), (o) => numbers_tryAsU16(o));
|
|
10391
|
-
/** Encode/decode unsigned gas. */
|
|
10392
|
-
const codecVarGas = descriptors_codec.varU64.convert((g) => numbers_tryAsU64(g), (i) => tryAsServiceGas(i));
|
|
10393
|
-
/**
|
|
10394
|
-
* Single core statistics.
|
|
10395
|
-
* Updated per block, based on incoming work reports (`w`).
|
|
10396
|
-
*
|
|
10397
|
-
* https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
|
|
10398
|
-
* https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
|
|
10399
|
-
*/
|
|
10400
|
-
class CoreStatistics {
|
|
10401
|
-
dataAvailabilityLoad;
|
|
10402
|
-
popularity;
|
|
10403
|
-
imports;
|
|
10404
|
-
exports;
|
|
10405
|
-
extrinsicSize;
|
|
10406
|
-
extrinsicCount;
|
|
10407
|
-
bundleSize;
|
|
10408
|
-
gasUsed;
|
|
10409
|
-
static Codec = Compatibility.isGreaterOrEqual(GpVersion.V0_7_0)
|
|
10410
|
-
? descriptors_codec.Class(CoreStatistics, {
|
|
10411
|
-
dataAvailabilityLoad: descriptors_codec.varU32,
|
|
10412
|
-
popularity: codecVarU16,
|
|
10413
|
-
imports: codecVarU16,
|
|
10414
|
-
extrinsicCount: codecVarU16,
|
|
10415
|
-
extrinsicSize: descriptors_codec.varU32,
|
|
10416
|
-
exports: codecVarU16,
|
|
10417
|
-
bundleSize: descriptors_codec.varU32,
|
|
10418
|
-
gasUsed: codecVarGas,
|
|
10419
|
-
})
|
|
10420
|
-
: descriptors_codec.Class(CoreStatistics, {
|
|
10421
|
-
dataAvailabilityLoad: descriptors_codec.varU32,
|
|
10422
|
-
popularity: codecVarU16,
|
|
10423
|
-
imports: codecVarU16,
|
|
10424
|
-
exports: codecVarU16,
|
|
10425
|
-
extrinsicSize: descriptors_codec.varU32,
|
|
10426
|
-
extrinsicCount: codecVarU16,
|
|
10427
|
-
bundleSize: descriptors_codec.varU32,
|
|
10428
|
-
gasUsed: codecVarGas,
|
|
10429
|
-
});
|
|
10430
|
-
static create(v) {
|
|
10431
|
-
return new CoreStatistics(v.dataAvailabilityLoad, v.popularity, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.bundleSize, v.gasUsed);
|
|
10432
|
-
}
|
|
10433
|
-
constructor(
|
|
10434
|
-
/** `d` */
|
|
10435
|
-
dataAvailabilityLoad,
|
|
10436
|
-
/** `p` */
|
|
10437
|
-
popularity,
|
|
10438
|
-
/** `i` */
|
|
10439
|
-
imports,
|
|
10440
|
-
/** `e` */
|
|
10441
|
-
exports,
|
|
10442
|
-
/** `z` */
|
|
10443
|
-
extrinsicSize,
|
|
10444
|
-
/** `x` */
|
|
10445
|
-
extrinsicCount,
|
|
10446
|
-
/** `b` */
|
|
10447
|
-
bundleSize,
|
|
10448
|
-
/** `u` */
|
|
10449
|
-
gasUsed) {
|
|
10450
|
-
this.dataAvailabilityLoad = dataAvailabilityLoad;
|
|
10451
|
-
this.popularity = popularity;
|
|
10452
|
-
this.imports = imports;
|
|
10453
|
-
this.exports = exports;
|
|
10454
|
-
this.extrinsicSize = extrinsicSize;
|
|
10455
|
-
this.extrinsicCount = extrinsicCount;
|
|
10456
|
-
this.bundleSize = bundleSize;
|
|
10457
|
-
this.gasUsed = gasUsed;
|
|
10458
|
-
}
|
|
10459
|
-
static empty() {
|
|
10460
|
-
const zero = numbers_tryAsU32(0);
|
|
10461
|
-
const zero16 = numbers_tryAsU16(0);
|
|
10462
|
-
const zeroGas = tryAsServiceGas(0);
|
|
10463
|
-
return new CoreStatistics(zero, zero16, zero16, zero16, zero, zero16, zero, zeroGas);
|
|
10680
|
+
});
|
|
10464
10681
|
}
|
|
10465
10682
|
}
|
|
10683
|
+
/** Update service storage kind. */
|
|
10684
|
+
var UpdateStorageKind;
|
|
10685
|
+
(function (UpdateStorageKind) {
|
|
10686
|
+
/** Set a storage value. */
|
|
10687
|
+
UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
|
|
10688
|
+
/** Remove a storage value. */
|
|
10689
|
+
UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
|
|
10690
|
+
})(UpdateStorageKind || (UpdateStorageKind = {}));
|
|
10466
10691
|
/**
|
|
10467
|
-
*
|
|
10468
|
-
* Updated per block, based on available work reports (`W`).
|
|
10692
|
+
* Update service storage item.
|
|
10469
10693
|
*
|
|
10470
|
-
*
|
|
10694
|
+
* Can either create/modify an entry or remove it.
|
|
10471
10695
|
*/
|
|
10472
|
-
class
|
|
10473
|
-
|
|
10474
|
-
|
|
10475
|
-
|
|
10476
|
-
|
|
10477
|
-
|
|
10478
|
-
exports;
|
|
10479
|
-
extrinsicSize;
|
|
10480
|
-
extrinsicCount;
|
|
10481
|
-
accumulateCount;
|
|
10482
|
-
accumulateGasUsed;
|
|
10483
|
-
onTransfersCount;
|
|
10484
|
-
onTransfersGasUsed;
|
|
10485
|
-
static Codec = Compatibility.selectIfGreaterOrEqual({
|
|
10486
|
-
fallback: descriptors_codec.Class(ServiceStatistics, {
|
|
10487
|
-
providedCount: codecVarU16,
|
|
10488
|
-
providedSize: descriptors_codec.varU32,
|
|
10489
|
-
refinementCount: descriptors_codec.varU32,
|
|
10490
|
-
refinementGasUsed: codecVarGas,
|
|
10491
|
-
imports: codecVarU16,
|
|
10492
|
-
exports: codecVarU16,
|
|
10493
|
-
extrinsicSize: descriptors_codec.varU32,
|
|
10494
|
-
extrinsicCount: codecVarU16,
|
|
10495
|
-
accumulateCount: descriptors_codec.varU32,
|
|
10496
|
-
accumulateGasUsed: codecVarGas,
|
|
10497
|
-
onTransfersCount: descriptors_codec.varU32,
|
|
10498
|
-
onTransfersGasUsed: codecVarGas,
|
|
10499
|
-
}),
|
|
10500
|
-
versions: {
|
|
10501
|
-
[GpVersion.V0_7_0]: descriptors_codec.Class(ServiceStatistics, {
|
|
10502
|
-
providedCount: codecVarU16,
|
|
10503
|
-
providedSize: descriptors_codec.varU32,
|
|
10504
|
-
refinementCount: descriptors_codec.varU32,
|
|
10505
|
-
refinementGasUsed: codecVarGas,
|
|
10506
|
-
imports: codecVarU16,
|
|
10507
|
-
extrinsicCount: codecVarU16,
|
|
10508
|
-
extrinsicSize: descriptors_codec.varU32,
|
|
10509
|
-
exports: codecVarU16,
|
|
10510
|
-
accumulateCount: descriptors_codec.varU32,
|
|
10511
|
-
accumulateGasUsed: codecVarGas,
|
|
10512
|
-
onTransfersCount: descriptors_codec.varU32,
|
|
10513
|
-
onTransfersGasUsed: codecVarGas,
|
|
10514
|
-
}),
|
|
10515
|
-
[GpVersion.V0_7_1]: descriptors_codec.Class(ServiceStatistics, {
|
|
10516
|
-
providedCount: codecVarU16,
|
|
10517
|
-
providedSize: descriptors_codec.varU32,
|
|
10518
|
-
refinementCount: descriptors_codec.varU32,
|
|
10519
|
-
refinementGasUsed: codecVarGas,
|
|
10520
|
-
imports: codecVarU16,
|
|
10521
|
-
extrinsicCount: codecVarU16,
|
|
10522
|
-
extrinsicSize: descriptors_codec.varU32,
|
|
10523
|
-
exports: codecVarU16,
|
|
10524
|
-
accumulateCount: descriptors_codec.varU32,
|
|
10525
|
-
accumulateGasUsed: codecVarGas,
|
|
10526
|
-
onTransfersCount: ignoreValueWithDefault(numbers_tryAsU32(0)),
|
|
10527
|
-
onTransfersGasUsed: ignoreValueWithDefault(tryAsServiceGas(0)),
|
|
10528
|
-
}),
|
|
10529
|
-
},
|
|
10530
|
-
});
|
|
10531
|
-
static create(v) {
|
|
10532
|
-
return new ServiceStatistics(v.providedCount, v.providedSize, v.refinementCount, v.refinementGasUsed, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.accumulateCount, v.accumulateGasUsed, v.onTransfersCount, v.onTransfersGasUsed);
|
|
10696
|
+
class UpdateStorage {
|
|
10697
|
+
serviceId;
|
|
10698
|
+
action;
|
|
10699
|
+
constructor(serviceId, action) {
|
|
10700
|
+
this.serviceId = serviceId;
|
|
10701
|
+
this.action = action;
|
|
10533
10702
|
}
|
|
10534
|
-
|
|
10535
|
-
|
|
10536
|
-
providedCount,
|
|
10537
|
-
/** `p.1` */
|
|
10538
|
-
providedSize,
|
|
10539
|
-
/** `r.0` */
|
|
10540
|
-
refinementCount,
|
|
10541
|
-
/** `r.1` */
|
|
10542
|
-
refinementGasUsed,
|
|
10543
|
-
/** `i` */
|
|
10544
|
-
imports,
|
|
10545
|
-
/** `e` */
|
|
10546
|
-
exports,
|
|
10547
|
-
/** `z` */
|
|
10548
|
-
extrinsicSize,
|
|
10549
|
-
/** `x` */
|
|
10550
|
-
extrinsicCount,
|
|
10551
|
-
/** `a.0` */
|
|
10552
|
-
accumulateCount,
|
|
10553
|
-
/** `a.1` */
|
|
10554
|
-
accumulateGasUsed,
|
|
10555
|
-
/** `t.0` @deprecated since 0.7.1 */
|
|
10556
|
-
onTransfersCount,
|
|
10557
|
-
/** `t.1` @deprecated since 0.7.1 */
|
|
10558
|
-
onTransfersGasUsed) {
|
|
10559
|
-
this.providedCount = providedCount;
|
|
10560
|
-
this.providedSize = providedSize;
|
|
10561
|
-
this.refinementCount = refinementCount;
|
|
10562
|
-
this.refinementGasUsed = refinementGasUsed;
|
|
10563
|
-
this.imports = imports;
|
|
10564
|
-
this.exports = exports;
|
|
10565
|
-
this.extrinsicSize = extrinsicSize;
|
|
10566
|
-
this.extrinsicCount = extrinsicCount;
|
|
10567
|
-
this.accumulateCount = accumulateCount;
|
|
10568
|
-
this.accumulateGasUsed = accumulateGasUsed;
|
|
10569
|
-
this.onTransfersCount = onTransfersCount;
|
|
10570
|
-
this.onTransfersGasUsed = onTransfersGasUsed;
|
|
10703
|
+
static set({ serviceId, storage }) {
|
|
10704
|
+
return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Set, storage });
|
|
10571
10705
|
}
|
|
10572
|
-
static
|
|
10573
|
-
|
|
10574
|
-
const zero16 = numbers_tryAsU16(0);
|
|
10575
|
-
const zeroGas = tryAsServiceGas(0);
|
|
10576
|
-
return new ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
|
|
10706
|
+
static remove({ serviceId, key }) {
|
|
10707
|
+
return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Remove, key });
|
|
10577
10708
|
}
|
|
10578
|
-
|
|
10579
|
-
|
|
10580
|
-
|
|
10581
|
-
|
|
10582
|
-
|
|
10583
|
-
cores;
|
|
10584
|
-
services;
|
|
10585
|
-
static Codec = descriptors_codec.Class(StatisticsData, {
|
|
10586
|
-
current: codecPerValidator(ValidatorStatistics.Codec),
|
|
10587
|
-
previous: codecPerValidator(ValidatorStatistics.Codec),
|
|
10588
|
-
cores: codecPerCore(CoreStatistics.Codec),
|
|
10589
|
-
services: descriptors_codec.dictionary(codecServiceId, ServiceStatistics.Codec, {
|
|
10590
|
-
sortKeys: (a, b) => a - b,
|
|
10591
|
-
}),
|
|
10592
|
-
});
|
|
10593
|
-
static create(v) {
|
|
10594
|
-
return new StatisticsData(v.current, v.previous, v.cores, v.services);
|
|
10709
|
+
get key() {
|
|
10710
|
+
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
10711
|
+
return this.action.key;
|
|
10712
|
+
}
|
|
10713
|
+
return this.action.storage.key;
|
|
10595
10714
|
}
|
|
10596
|
-
|
|
10597
|
-
this.
|
|
10598
|
-
|
|
10599
|
-
|
|
10600
|
-
this.
|
|
10715
|
+
get value() {
|
|
10716
|
+
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
10717
|
+
return null;
|
|
10718
|
+
}
|
|
10719
|
+
return this.action.storage.value;
|
|
10601
10720
|
}
|
|
10602
10721
|
}
|
|
10603
10722
|
|
|
@@ -10622,6 +10741,7 @@ class StatisticsData {
|
|
|
10622
10741
|
|
|
10623
10742
|
|
|
10624
10743
|
|
|
10744
|
+
|
|
10625
10745
|
|
|
10626
10746
|
|
|
10627
10747
|
var in_memory_state_UpdateError;
|
|
@@ -10722,10 +10842,11 @@ class InMemoryService extends WithDebug {
|
|
|
10722
10842
|
/**
|
|
10723
10843
|
* A special version of state, stored fully in-memory.
|
|
10724
10844
|
*/
|
|
10725
|
-
class
|
|
10845
|
+
class in_memory_state_InMemoryState extends WithDebug {
|
|
10846
|
+
chainSpec;
|
|
10726
10847
|
/** Create a new `InMemoryState` by providing all required fields. */
|
|
10727
|
-
static
|
|
10728
|
-
return new
|
|
10848
|
+
static new(chainSpec, state) {
|
|
10849
|
+
return new in_memory_state_InMemoryState(chainSpec, state);
|
|
10729
10850
|
}
|
|
10730
10851
|
/**
|
|
10731
10852
|
* Create a new `InMemoryState` with a partial state override.
|
|
@@ -10734,14 +10855,14 @@ class InMemoryState extends WithDebug {
|
|
|
10734
10855
|
* not-necessarily coherent values.
|
|
10735
10856
|
*/
|
|
10736
10857
|
static partial(spec, partial) {
|
|
10737
|
-
const state =
|
|
10858
|
+
const state = in_memory_state_InMemoryState.empty(spec);
|
|
10738
10859
|
Object.assign(state, partial);
|
|
10739
10860
|
return state;
|
|
10740
10861
|
}
|
|
10741
10862
|
/**
|
|
10742
10863
|
* Create a new `InMemoryState` from some other state object.
|
|
10743
10864
|
*/
|
|
10744
|
-
static copyFrom(other, servicesData) {
|
|
10865
|
+
static copyFrom(chainSpec, other, servicesData) {
|
|
10745
10866
|
const services = new Map();
|
|
10746
10867
|
for (const [id, entries] of servicesData.entries()) {
|
|
10747
10868
|
const service = other.getService(id);
|
|
@@ -10751,7 +10872,7 @@ class InMemoryState extends WithDebug {
|
|
|
10751
10872
|
const inMemService = InMemoryService.copyFrom(service, entries);
|
|
10752
10873
|
services.set(id, inMemService);
|
|
10753
10874
|
}
|
|
10754
|
-
return
|
|
10875
|
+
return in_memory_state_InMemoryState.new(chainSpec, {
|
|
10755
10876
|
availabilityAssignment: other.availabilityAssignment,
|
|
10756
10877
|
accumulationQueue: other.accumulationQueue,
|
|
10757
10878
|
designatedValidatorData: other.designatedValidatorData,
|
|
@@ -10948,8 +11069,9 @@ class InMemoryState extends WithDebug {
|
|
|
10948
11069
|
getService(id) {
|
|
10949
11070
|
return this.services.get(id) ?? null;
|
|
10950
11071
|
}
|
|
10951
|
-
constructor(s) {
|
|
11072
|
+
constructor(chainSpec, s) {
|
|
10952
11073
|
super();
|
|
11074
|
+
this.chainSpec = chainSpec;
|
|
10953
11075
|
this.availabilityAssignment = s.availabilityAssignment;
|
|
10954
11076
|
this.designatedValidatorData = s.designatedValidatorData;
|
|
10955
11077
|
this.nextValidatorData = s.nextValidatorData;
|
|
@@ -10971,31 +11093,34 @@ class InMemoryState extends WithDebug {
|
|
|
10971
11093
|
this.accumulationOutputLog = s.accumulationOutputLog;
|
|
10972
11094
|
this.services = s.services;
|
|
10973
11095
|
}
|
|
11096
|
+
view() {
|
|
11097
|
+
return new InMemoryStateView(this.chainSpec, this);
|
|
11098
|
+
}
|
|
10974
11099
|
/**
|
|
10975
11100
|
* Create an empty and possibly incoherent `InMemoryState`.
|
|
10976
11101
|
*/
|
|
10977
11102
|
static empty(spec) {
|
|
10978
|
-
return new
|
|
11103
|
+
return new in_memory_state_InMemoryState(spec, {
|
|
10979
11104
|
availabilityAssignment: tryAsPerCore(Array.from({ length: spec.coresCount }, () => null), spec),
|
|
10980
|
-
designatedValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () =>
|
|
11105
|
+
designatedValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
|
|
10981
11106
|
bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
10982
11107
|
bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
|
|
10983
11108
|
ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
|
|
10984
11109
|
metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
|
|
10985
11110
|
})), spec),
|
|
10986
|
-
nextValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () =>
|
|
11111
|
+
nextValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
|
|
10987
11112
|
bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
10988
11113
|
bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
|
|
10989
11114
|
ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
|
|
10990
11115
|
metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
|
|
10991
11116
|
})), spec),
|
|
10992
|
-
currentValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () =>
|
|
11117
|
+
currentValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
|
|
10993
11118
|
bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
10994
11119
|
bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
|
|
10995
11120
|
ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
|
|
10996
11121
|
metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
|
|
10997
11122
|
})), spec),
|
|
10998
|
-
previousValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () =>
|
|
11123
|
+
previousValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
|
|
10999
11124
|
bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
11000
11125
|
bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
|
|
11001
11126
|
ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
|
|
@@ -11011,7 +11136,7 @@ class InMemoryState extends WithDebug {
|
|
|
11011
11136
|
entropy: FixedSizeArray.fill(() => bytes_Bytes.zero(hash_HASH_SIZE).asOpaque(), ENTROPY_ENTRIES),
|
|
11012
11137
|
authPools: tryAsPerCore(Array.from({ length: spec.coresCount }, () => sized_array_asKnownSize([])), spec),
|
|
11013
11138
|
authQueues: tryAsPerCore(Array.from({ length: spec.coresCount }, () => FixedSizeArray.fill(() => bytes_Bytes.zero(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE)), spec),
|
|
11014
|
-
recentBlocks:
|
|
11139
|
+
recentBlocks: RecentBlocks.empty(),
|
|
11015
11140
|
statistics: StatisticsData.create({
|
|
11016
11141
|
current: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
|
|
11017
11142
|
previous: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
|
|
@@ -11021,8 +11146,8 @@ class InMemoryState extends WithDebug {
|
|
|
11021
11146
|
accumulationQueue: tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => []), spec),
|
|
11022
11147
|
recentlyAccumulated: tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => HashSet.new()), spec),
|
|
11023
11148
|
ticketsAccumulator: sized_array_asKnownSize([]),
|
|
11024
|
-
sealingKeySeries:
|
|
11025
|
-
epochRoot: bytes_Bytes.zero(
|
|
11149
|
+
sealingKeySeries: safrole_data_SafroleSealingKeysData.keys(tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque()), spec)),
|
|
11150
|
+
epochRoot: bytes_Bytes.zero(bandersnatch_BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
11026
11151
|
privilegedServices: PrivilegedServices.create({
|
|
11027
11152
|
manager: tryAsServiceId(0),
|
|
11028
11153
|
assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
|
|
@@ -11062,51 +11187,10 @@ const serviceDataCodec = descriptors_codec.dictionary(descriptors_codec.u32.asOp
|
|
|
11062
11187
|
|
|
11063
11188
|
|
|
11064
11189
|
|
|
11065
|
-
;// CONCATENATED MODULE: ./packages/jam/state/not-yet-accumulated.ts
|
|
11066
|
-
|
|
11067
|
-
|
|
11068
11190
|
|
|
11069
11191
|
|
|
11070
11192
|
|
|
11071
11193
|
|
|
11072
|
-
/**
|
|
11073
|
-
* Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
|
|
11074
|
-
*
|
|
11075
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
|
|
11076
|
-
*/
|
|
11077
|
-
class NotYetAccumulatedReport extends WithDebug {
|
|
11078
|
-
report;
|
|
11079
|
-
dependencies;
|
|
11080
|
-
static Codec = descriptors_codec.Class(NotYetAccumulatedReport, {
|
|
11081
|
-
report: WorkReport.Codec,
|
|
11082
|
-
dependencies: codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
|
|
11083
|
-
typicalLength: MAX_REPORT_DEPENDENCIES / 2,
|
|
11084
|
-
maxLength: MAX_REPORT_DEPENDENCIES,
|
|
11085
|
-
minLength: 0,
|
|
11086
|
-
}),
|
|
11087
|
-
});
|
|
11088
|
-
static create({ report, dependencies }) {
|
|
11089
|
-
return new NotYetAccumulatedReport(report, dependencies);
|
|
11090
|
-
}
|
|
11091
|
-
constructor(
|
|
11092
|
-
/**
|
|
11093
|
-
* Each of these were made available at most one epoch ago
|
|
11094
|
-
* but have or had unfulfilled dependencies.
|
|
11095
|
-
*/
|
|
11096
|
-
report,
|
|
11097
|
-
/**
|
|
11098
|
-
* Alongside the work-report itself, we retain its un-accumulated
|
|
11099
|
-
* dependencies, a set of work-package hashes.
|
|
11100
|
-
*
|
|
11101
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
|
|
11102
|
-
*/
|
|
11103
|
-
dependencies) {
|
|
11104
|
-
super();
|
|
11105
|
-
this.report = report;
|
|
11106
|
-
this.dependencies = dependencies;
|
|
11107
|
-
}
|
|
11108
|
-
}
|
|
11109
|
-
|
|
11110
11194
|
;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialize.ts
|
|
11111
11195
|
|
|
11112
11196
|
|
|
@@ -11119,26 +11203,19 @@ class NotYetAccumulatedReport extends WithDebug {
|
|
|
11119
11203
|
|
|
11120
11204
|
|
|
11121
11205
|
|
|
11122
|
-
|
|
11123
|
-
|
|
11124
|
-
|
|
11125
11206
|
/** Serialization for particular state entries. */
|
|
11126
|
-
var
|
|
11207
|
+
var serialize_serialize;
|
|
11127
11208
|
(function (serialize) {
|
|
11128
11209
|
/** C(1): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b15013b1501?v=0.6.7 */
|
|
11129
11210
|
serialize.authPools = {
|
|
11130
11211
|
key: stateKeys.index(StateKeyIdx.Alpha),
|
|
11131
|
-
Codec:
|
|
11132
|
-
minLength: 0,
|
|
11133
|
-
maxLength: MAX_AUTH_POOL_SIZE,
|
|
11134
|
-
typicalLength: MAX_AUTH_POOL_SIZE,
|
|
11135
|
-
})),
|
|
11212
|
+
Codec: authPoolsCodec,
|
|
11136
11213
|
extract: (s) => s.authPools,
|
|
11137
11214
|
};
|
|
11138
11215
|
/** C(2): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b31013b3101?v=0.6.7 */
|
|
11139
11216
|
serialize.authQueues = {
|
|
11140
11217
|
key: stateKeys.index(StateKeyIdx.Phi),
|
|
11141
|
-
Codec:
|
|
11218
|
+
Codec: authQueuesCodec,
|
|
11142
11219
|
extract: (s) => s.authQueues,
|
|
11143
11220
|
};
|
|
11144
11221
|
/**
|
|
@@ -11147,7 +11224,7 @@ var serialize;
|
|
|
11147
11224
|
*/
|
|
11148
11225
|
serialize.recentBlocks = {
|
|
11149
11226
|
key: stateKeys.index(StateKeyIdx.Beta),
|
|
11150
|
-
Codec:
|
|
11227
|
+
Codec: RecentBlocks.Codec,
|
|
11151
11228
|
extract: (s) => s.recentBlocks,
|
|
11152
11229
|
};
|
|
11153
11230
|
/** C(4): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b63013b6301?v=0.6.7 */
|
|
@@ -11176,25 +11253,25 @@ var serialize;
|
|
|
11176
11253
|
/** C(7): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b00023b0002?v=0.6.7 */
|
|
11177
11254
|
serialize.designatedValidators = {
|
|
11178
11255
|
key: stateKeys.index(StateKeyIdx.Iota),
|
|
11179
|
-
Codec:
|
|
11256
|
+
Codec: validatorsDataCodec,
|
|
11180
11257
|
extract: (s) => s.designatedValidatorData,
|
|
11181
11258
|
};
|
|
11182
11259
|
/** C(8): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b0d023b0d02?v=0.6.7 */
|
|
11183
11260
|
serialize.currentValidators = {
|
|
11184
11261
|
key: stateKeys.index(StateKeyIdx.Kappa),
|
|
11185
|
-
Codec:
|
|
11262
|
+
Codec: validatorsDataCodec,
|
|
11186
11263
|
extract: (s) => s.currentValidatorData,
|
|
11187
11264
|
};
|
|
11188
11265
|
/** C(9): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b1a023b1a02?v=0.6.7 */
|
|
11189
11266
|
serialize.previousValidators = {
|
|
11190
11267
|
key: stateKeys.index(StateKeyIdx.Lambda),
|
|
11191
|
-
Codec:
|
|
11268
|
+
Codec: validatorsDataCodec,
|
|
11192
11269
|
extract: (s) => s.previousValidatorData,
|
|
11193
11270
|
};
|
|
11194
11271
|
/** C(10): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b27023b2702?v=0.6.7 */
|
|
11195
11272
|
serialize.availabilityAssignment = {
|
|
11196
11273
|
key: stateKeys.index(StateKeyIdx.Rho),
|
|
11197
|
-
Codec:
|
|
11274
|
+
Codec: availabilityAssignmentsCodec,
|
|
11198
11275
|
extract: (s) => s.availabilityAssignment,
|
|
11199
11276
|
};
|
|
11200
11277
|
/** C(11): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b3e023b3e02?v=0.6.7 */
|
|
@@ -11218,13 +11295,13 @@ var serialize;
|
|
|
11218
11295
|
/** C(14): https://graypaper.fluffylabs.dev/#/1c979cb/3bf0023bf002?v=0.7.1 */
|
|
11219
11296
|
serialize.accumulationQueue = {
|
|
11220
11297
|
key: stateKeys.index(StateKeyIdx.Omega),
|
|
11221
|
-
Codec:
|
|
11298
|
+
Codec: accumulationQueueCodec,
|
|
11222
11299
|
extract: (s) => s.accumulationQueue,
|
|
11223
11300
|
};
|
|
11224
11301
|
/** C(15): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b96023b9602?v=0.6.7 */
|
|
11225
11302
|
serialize.recentlyAccumulated = {
|
|
11226
11303
|
key: stateKeys.index(StateKeyIdx.Xi),
|
|
11227
|
-
Codec:
|
|
11304
|
+
Codec: recentlyAccumulatedCodec,
|
|
11228
11305
|
extract: (s) => s.recentlyAccumulated,
|
|
11229
11306
|
};
|
|
11230
11307
|
/** C(16): https://graypaper.fluffylabs.dev/#/38c4e62/3b46033b4603?v=0.7.0 */
|
|
@@ -11253,9 +11330,9 @@ var serialize;
|
|
|
11253
11330
|
/** https://graypaper.fluffylabs.dev/#/85129da/387603387603?v=0.6.3 */
|
|
11254
11331
|
serialize.serviceLookupHistory = (blake2b, serviceId, hash, len) => ({
|
|
11255
11332
|
key: stateKeys.serviceLookupHistory(blake2b, serviceId, hash, len),
|
|
11256
|
-
Codec:
|
|
11333
|
+
Codec: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32)),
|
|
11257
11334
|
});
|
|
11258
|
-
})(
|
|
11335
|
+
})(serialize_serialize || (serialize_serialize = {}));
|
|
11259
11336
|
/**
|
|
11260
11337
|
* Just dump the entire terminal blob as-is.
|
|
11261
11338
|
*
|
|
@@ -11265,6 +11342,87 @@ var serialize;
|
|
|
11265
11342
|
*/
|
|
11266
11343
|
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()));
|
|
11267
11344
|
|
|
11345
|
+
;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state-view.ts
|
|
11346
|
+
|
|
11347
|
+
|
|
11348
|
+
class SerializedStateView {
|
|
11349
|
+
spec;
|
|
11350
|
+
backend;
|
|
11351
|
+
recentlyUsedServices;
|
|
11352
|
+
viewCache;
|
|
11353
|
+
constructor(spec, backend,
|
|
11354
|
+
/** Best-effort list of recently active services. */
|
|
11355
|
+
recentlyUsedServices, viewCache) {
|
|
11356
|
+
this.spec = spec;
|
|
11357
|
+
this.backend = backend;
|
|
11358
|
+
this.recentlyUsedServices = recentlyUsedServices;
|
|
11359
|
+
this.viewCache = viewCache;
|
|
11360
|
+
}
|
|
11361
|
+
retrieveView({ key, Codec }, description) {
|
|
11362
|
+
const cached = this.viewCache.get(key);
|
|
11363
|
+
if (cached !== undefined) {
|
|
11364
|
+
return cached;
|
|
11365
|
+
}
|
|
11366
|
+
const bytes = this.backend.get(key);
|
|
11367
|
+
if (bytes === null) {
|
|
11368
|
+
throw new Error(`Required state entry for ${description} is missing!. Accessing view of key: ${key}`);
|
|
11369
|
+
}
|
|
11370
|
+
// NOTE [ToDr] we are not using `Decoder.decodeObject` here because
|
|
11371
|
+
// it needs to get to the end of the data (skip), yet that's expensive.
|
|
11372
|
+
// we assume that the state data is correct and coherent anyway, so
|
|
11373
|
+
// for performance reasons we simply create the view here.
|
|
11374
|
+
const d = decoder_Decoder.fromBytesBlob(bytes);
|
|
11375
|
+
d.attachContext(this.spec);
|
|
11376
|
+
const view = Codec.View.decode(d);
|
|
11377
|
+
this.viewCache.set(key, view);
|
|
11378
|
+
return view;
|
|
11379
|
+
}
|
|
11380
|
+
availabilityAssignmentView() {
|
|
11381
|
+
return this.retrieveView(serialize_serialize.availabilityAssignment, "availabilityAssignmentView");
|
|
11382
|
+
}
|
|
11383
|
+
designatedValidatorDataView() {
|
|
11384
|
+
return this.retrieveView(serialize_serialize.designatedValidators, "designatedValidatorsView");
|
|
11385
|
+
}
|
|
11386
|
+
currentValidatorDataView() {
|
|
11387
|
+
return this.retrieveView(serialize_serialize.currentValidators, "currentValidatorsView");
|
|
11388
|
+
}
|
|
11389
|
+
previousValidatorDataView() {
|
|
11390
|
+
return this.retrieveView(serialize_serialize.previousValidators, "previousValidatorsView");
|
|
11391
|
+
}
|
|
11392
|
+
authPoolsView() {
|
|
11393
|
+
return this.retrieveView(serialize_serialize.authPools, "authPoolsView");
|
|
11394
|
+
}
|
|
11395
|
+
authQueuesView() {
|
|
11396
|
+
return this.retrieveView(serialize_serialize.authQueues, "authQueuesView");
|
|
11397
|
+
}
|
|
11398
|
+
recentBlocksView() {
|
|
11399
|
+
return this.retrieveView(serialize_serialize.recentBlocks, "recentBlocksView");
|
|
11400
|
+
}
|
|
11401
|
+
statisticsView() {
|
|
11402
|
+
return this.retrieveView(serialize_serialize.statistics, "statisticsView");
|
|
11403
|
+
}
|
|
11404
|
+
accumulationQueueView() {
|
|
11405
|
+
return this.retrieveView(serialize_serialize.accumulationQueue, "accumulationQueueView");
|
|
11406
|
+
}
|
|
11407
|
+
recentlyAccumulatedView() {
|
|
11408
|
+
return this.retrieveView(serialize_serialize.recentlyAccumulated, "recentlyAccumulatedView");
|
|
11409
|
+
}
|
|
11410
|
+
safroleDataView() {
|
|
11411
|
+
return this.retrieveView(serialize_serialize.safrole, "safroleDataView");
|
|
11412
|
+
}
|
|
11413
|
+
getServiceInfoView(id) {
|
|
11414
|
+
const serviceData = serialize_serialize.serviceData(id);
|
|
11415
|
+
const bytes = this.backend.get(serviceData.key);
|
|
11416
|
+
if (bytes === null) {
|
|
11417
|
+
return null;
|
|
11418
|
+
}
|
|
11419
|
+
if (!this.recentlyUsedServices.includes(id)) {
|
|
11420
|
+
this.recentlyUsedServices.push(id);
|
|
11421
|
+
}
|
|
11422
|
+
return decoder_Decoder.decodeObject(serviceData.Codec.View, bytes, this.spec);
|
|
11423
|
+
}
|
|
11424
|
+
}
|
|
11425
|
+
|
|
11268
11426
|
;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
|
|
11269
11427
|
|
|
11270
11428
|
|
|
@@ -11273,6 +11431,8 @@ const dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }, (e, v) =
|
|
|
11273
11431
|
|
|
11274
11432
|
|
|
11275
11433
|
|
|
11434
|
+
|
|
11435
|
+
|
|
11276
11436
|
/**
|
|
11277
11437
|
* State object which reads it's entries from some backend.
|
|
11278
11438
|
*
|
|
@@ -11285,7 +11445,7 @@ class serialized_state_SerializedState {
|
|
|
11285
11445
|
spec;
|
|
11286
11446
|
blake2b;
|
|
11287
11447
|
backend;
|
|
11288
|
-
|
|
11448
|
+
recentlyUsedServices;
|
|
11289
11449
|
/** Create a state-like object from collection of serialized entries. */
|
|
11290
11450
|
static fromStateEntries(spec, blake2b, state, recentServices = []) {
|
|
11291
11451
|
return new serialized_state_SerializedState(spec, blake2b, state, recentServices);
|
|
@@ -11294,106 +11454,120 @@ class serialized_state_SerializedState {
|
|
|
11294
11454
|
static new(spec, blake2b, db, recentServices = []) {
|
|
11295
11455
|
return new serialized_state_SerializedState(spec, blake2b, db, recentServices);
|
|
11296
11456
|
}
|
|
11457
|
+
dataCache = hash_dictionary_HashDictionary.new();
|
|
11458
|
+
viewCache = hash_dictionary_HashDictionary.new();
|
|
11297
11459
|
constructor(spec, blake2b, backend,
|
|
11298
11460
|
/** Best-effort list of recently active services. */
|
|
11299
|
-
|
|
11461
|
+
recentlyUsedServices) {
|
|
11300
11462
|
this.spec = spec;
|
|
11301
11463
|
this.blake2b = blake2b;
|
|
11302
11464
|
this.backend = backend;
|
|
11303
|
-
this.
|
|
11465
|
+
this.recentlyUsedServices = recentlyUsedServices;
|
|
11304
11466
|
}
|
|
11305
11467
|
/** Comparing the serialized states, just means comparing their backends. */
|
|
11306
11468
|
[TEST_COMPARE_USING]() {
|
|
11307
11469
|
return this.backend;
|
|
11308
11470
|
}
|
|
11471
|
+
/** Return a non-decoding version of the state. */
|
|
11472
|
+
view() {
|
|
11473
|
+
return new SerializedStateView(this.spec, this.backend, this.recentlyUsedServices, this.viewCache);
|
|
11474
|
+
}
|
|
11309
11475
|
// TODO [ToDr] Temporary method to update the state,
|
|
11310
11476
|
// without changing references.
|
|
11311
11477
|
updateBackend(newBackend) {
|
|
11312
11478
|
this.backend = newBackend;
|
|
11479
|
+
this.dataCache = hash_dictionary_HashDictionary.new();
|
|
11480
|
+
this.viewCache = hash_dictionary_HashDictionary.new();
|
|
11313
11481
|
}
|
|
11314
11482
|
recentServiceIds() {
|
|
11315
|
-
return this.
|
|
11483
|
+
return this.recentlyUsedServices;
|
|
11316
11484
|
}
|
|
11317
11485
|
getService(id) {
|
|
11318
|
-
const serviceData = this.retrieveOptional(
|
|
11486
|
+
const serviceData = this.retrieveOptional(serialize_serialize.serviceData(id));
|
|
11319
11487
|
if (serviceData === undefined) {
|
|
11320
11488
|
return null;
|
|
11321
11489
|
}
|
|
11322
|
-
if (!this.
|
|
11323
|
-
this.
|
|
11490
|
+
if (!this.recentlyUsedServices.includes(id)) {
|
|
11491
|
+
this.recentlyUsedServices.push(id);
|
|
11324
11492
|
}
|
|
11325
11493
|
return new SerializedService(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
|
|
11326
11494
|
}
|
|
11327
|
-
retrieve(
|
|
11328
|
-
const
|
|
11329
|
-
if (
|
|
11330
|
-
throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${key}`);
|
|
11495
|
+
retrieve(k, description) {
|
|
11496
|
+
const data = this.retrieveOptional(k);
|
|
11497
|
+
if (data === undefined) {
|
|
11498
|
+
throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${k.key}`);
|
|
11331
11499
|
}
|
|
11332
|
-
return
|
|
11500
|
+
return data;
|
|
11333
11501
|
}
|
|
11334
11502
|
retrieveOptional({ key, Codec }) {
|
|
11503
|
+
const cached = this.dataCache.get(key);
|
|
11504
|
+
if (cached !== undefined) {
|
|
11505
|
+
return cached;
|
|
11506
|
+
}
|
|
11335
11507
|
const bytes = this.backend.get(key);
|
|
11336
11508
|
if (bytes === null) {
|
|
11337
11509
|
return undefined;
|
|
11338
11510
|
}
|
|
11339
|
-
|
|
11511
|
+
const data = decoder_Decoder.decodeObject(Codec, bytes, this.spec);
|
|
11512
|
+
this.dataCache.set(key, data);
|
|
11513
|
+
return data;
|
|
11340
11514
|
}
|
|
11341
11515
|
get availabilityAssignment() {
|
|
11342
|
-
return this.retrieve(
|
|
11516
|
+
return this.retrieve(serialize_serialize.availabilityAssignment, "availabilityAssignment");
|
|
11343
11517
|
}
|
|
11344
11518
|
get designatedValidatorData() {
|
|
11345
|
-
return this.retrieve(
|
|
11519
|
+
return this.retrieve(serialize_serialize.designatedValidators, "designatedValidatorData");
|
|
11346
11520
|
}
|
|
11347
11521
|
get nextValidatorData() {
|
|
11348
|
-
return this.retrieve(
|
|
11522
|
+
return this.retrieve(serialize_serialize.safrole, "safroleData.nextValidatorData").nextValidatorData;
|
|
11349
11523
|
}
|
|
11350
11524
|
get currentValidatorData() {
|
|
11351
|
-
return this.retrieve(
|
|
11525
|
+
return this.retrieve(serialize_serialize.currentValidators, "currentValidators");
|
|
11352
11526
|
}
|
|
11353
11527
|
get previousValidatorData() {
|
|
11354
|
-
return this.retrieve(
|
|
11528
|
+
return this.retrieve(serialize_serialize.previousValidators, "previousValidators");
|
|
11355
11529
|
}
|
|
11356
11530
|
get disputesRecords() {
|
|
11357
|
-
return this.retrieve(
|
|
11531
|
+
return this.retrieve(serialize_serialize.disputesRecords, "disputesRecords");
|
|
11358
11532
|
}
|
|
11359
11533
|
get timeslot() {
|
|
11360
|
-
return this.retrieve(
|
|
11534
|
+
return this.retrieve(serialize_serialize.timeslot, "timeslot");
|
|
11361
11535
|
}
|
|
11362
11536
|
get entropy() {
|
|
11363
|
-
return this.retrieve(
|
|
11537
|
+
return this.retrieve(serialize_serialize.entropy, "entropy");
|
|
11364
11538
|
}
|
|
11365
11539
|
get authPools() {
|
|
11366
|
-
return this.retrieve(
|
|
11540
|
+
return this.retrieve(serialize_serialize.authPools, "authPools");
|
|
11367
11541
|
}
|
|
11368
11542
|
get authQueues() {
|
|
11369
|
-
return this.retrieve(
|
|
11543
|
+
return this.retrieve(serialize_serialize.authQueues, "authQueues");
|
|
11370
11544
|
}
|
|
11371
11545
|
get recentBlocks() {
|
|
11372
|
-
return this.retrieve(
|
|
11546
|
+
return this.retrieve(serialize_serialize.recentBlocks, "recentBlocks");
|
|
11373
11547
|
}
|
|
11374
11548
|
get statistics() {
|
|
11375
|
-
return this.retrieve(
|
|
11549
|
+
return this.retrieve(serialize_serialize.statistics, "statistics");
|
|
11376
11550
|
}
|
|
11377
11551
|
get accumulationQueue() {
|
|
11378
|
-
return this.retrieve(
|
|
11552
|
+
return this.retrieve(serialize_serialize.accumulationQueue, "accumulationQueue");
|
|
11379
11553
|
}
|
|
11380
11554
|
get recentlyAccumulated() {
|
|
11381
|
-
return this.retrieve(
|
|
11555
|
+
return this.retrieve(serialize_serialize.recentlyAccumulated, "recentlyAccumulated");
|
|
11382
11556
|
}
|
|
11383
11557
|
get ticketsAccumulator() {
|
|
11384
|
-
return this.retrieve(
|
|
11558
|
+
return this.retrieve(serialize_serialize.safrole, "safroleData.ticketsAccumulator").ticketsAccumulator;
|
|
11385
11559
|
}
|
|
11386
11560
|
get sealingKeySeries() {
|
|
11387
|
-
return this.retrieve(
|
|
11561
|
+
return this.retrieve(serialize_serialize.safrole, "safrole.sealingKeySeries").sealingKeySeries;
|
|
11388
11562
|
}
|
|
11389
11563
|
get epochRoot() {
|
|
11390
|
-
return this.retrieve(
|
|
11564
|
+
return this.retrieve(serialize_serialize.safrole, "safrole.epochRoot").epochRoot;
|
|
11391
11565
|
}
|
|
11392
11566
|
get privilegedServices() {
|
|
11393
|
-
return this.retrieve(
|
|
11567
|
+
return this.retrieve(serialize_serialize.privilegedServices, "privilegedServices");
|
|
11394
11568
|
}
|
|
11395
11569
|
get accumulationOutputLog() {
|
|
11396
|
-
return this.retrieve(
|
|
11570
|
+
return this.retrieve(serialize_serialize.accumulationOutputLog, "accumulationOutputLog");
|
|
11397
11571
|
}
|
|
11398
11572
|
}
|
|
11399
11573
|
/** Service data representation on a serialized state. */
|
|
@@ -11422,9 +11596,9 @@ class SerializedService {
|
|
|
11422
11596
|
serviceIdAndKey.set(numbers_u32AsLeBytes(this.serviceId));
|
|
11423
11597
|
serviceIdAndKey.set(rawKey.raw, SERVICE_ID_BYTES);
|
|
11424
11598
|
const key = opaque_asOpaqueType(bytes_BytesBlob.blobFrom(this.blake2b.hashBytes(serviceIdAndKey).raw));
|
|
11425
|
-
return this.retrieveOptional(
|
|
11599
|
+
return this.retrieveOptional(serialize_serialize.serviceStorage(this.blake2b, this.serviceId, key)) ?? null;
|
|
11426
11600
|
}
|
|
11427
|
-
return this.retrieveOptional(
|
|
11601
|
+
return this.retrieveOptional(serialize_serialize.serviceStorage(this.blake2b, this.serviceId, rawKey)) ?? null;
|
|
11428
11602
|
}
|
|
11429
11603
|
/**
|
|
11430
11604
|
* Check if preimage is present in the DB.
|
|
@@ -11433,15 +11607,15 @@ class SerializedService {
|
|
|
11433
11607
|
*/
|
|
11434
11608
|
hasPreimage(hash) {
|
|
11435
11609
|
// TODO [ToDr] consider optimizing to avoid fetching the whole data.
|
|
11436
|
-
return this.retrieveOptional(
|
|
11610
|
+
return this.retrieveOptional(serialize_serialize.servicePreimages(this.blake2b, this.serviceId, hash)) !== undefined;
|
|
11437
11611
|
}
|
|
11438
11612
|
/** Retrieve preimage from the DB. */
|
|
11439
11613
|
getPreimage(hash) {
|
|
11440
|
-
return this.retrieveOptional(
|
|
11614
|
+
return this.retrieveOptional(serialize_serialize.servicePreimages(this.blake2b, this.serviceId, hash)) ?? null;
|
|
11441
11615
|
}
|
|
11442
11616
|
/** Retrieve preimage lookup history. */
|
|
11443
11617
|
getLookupHistory(hash, len) {
|
|
11444
|
-
const rawSlots = this.retrieveOptional(
|
|
11618
|
+
const rawSlots = this.retrieveOptional(serialize_serialize.serviceLookupHistory(this.blake2b, this.serviceId, hash, len));
|
|
11445
11619
|
if (rawSlots === undefined) {
|
|
11446
11620
|
return null;
|
|
11447
11621
|
}
|
|
@@ -12130,7 +12304,7 @@ function* serializeStateUpdate(spec, blake2b, update) {
|
|
|
12130
12304
|
function* serializeRemovedServices(servicesRemoved) {
|
|
12131
12305
|
for (const serviceId of servicesRemoved ?? []) {
|
|
12132
12306
|
// TODO [ToDr] what about all data associated with a service?
|
|
12133
|
-
const codec =
|
|
12307
|
+
const codec = serialize_serialize.serviceData(serviceId);
|
|
12134
12308
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
12135
12309
|
}
|
|
12136
12310
|
}
|
|
@@ -12139,13 +12313,13 @@ function* serializeStorage(storage, blake2b) {
|
|
|
12139
12313
|
switch (action.kind) {
|
|
12140
12314
|
case UpdateStorageKind.Set: {
|
|
12141
12315
|
const key = action.storage.key;
|
|
12142
|
-
const codec =
|
|
12316
|
+
const codec = serialize_serialize.serviceStorage(blake2b, serviceId, key);
|
|
12143
12317
|
yield [StateEntryUpdateAction.Insert, codec.key, action.storage.value];
|
|
12144
12318
|
break;
|
|
12145
12319
|
}
|
|
12146
12320
|
case UpdateStorageKind.Remove: {
|
|
12147
12321
|
const key = action.key;
|
|
12148
|
-
const codec =
|
|
12322
|
+
const codec = serialize_serialize.serviceStorage(blake2b, serviceId, key);
|
|
12149
12323
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
12150
12324
|
break;
|
|
12151
12325
|
}
|
|
@@ -12159,10 +12333,10 @@ function* serializePreimages(preimages, encode, blake2b) {
|
|
|
12159
12333
|
switch (action.kind) {
|
|
12160
12334
|
case UpdatePreimageKind.Provide: {
|
|
12161
12335
|
const { hash, blob } = action.preimage;
|
|
12162
|
-
const codec =
|
|
12336
|
+
const codec = serialize_serialize.servicePreimages(blake2b, serviceId, hash);
|
|
12163
12337
|
yield [StateEntryUpdateAction.Insert, codec.key, blob];
|
|
12164
12338
|
if (action.slot !== null) {
|
|
12165
|
-
const codec2 =
|
|
12339
|
+
const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, numbers_tryAsU32(blob.length));
|
|
12166
12340
|
yield [
|
|
12167
12341
|
StateEntryUpdateAction.Insert,
|
|
12168
12342
|
codec2.key,
|
|
@@ -12173,15 +12347,15 @@ function* serializePreimages(preimages, encode, blake2b) {
|
|
|
12173
12347
|
}
|
|
12174
12348
|
case UpdatePreimageKind.UpdateOrAdd: {
|
|
12175
12349
|
const { hash, length, slots } = action.item;
|
|
12176
|
-
const codec =
|
|
12350
|
+
const codec = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
12177
12351
|
yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, slots)];
|
|
12178
12352
|
break;
|
|
12179
12353
|
}
|
|
12180
12354
|
case UpdatePreimageKind.Remove: {
|
|
12181
12355
|
const { hash, length } = action;
|
|
12182
|
-
const codec =
|
|
12356
|
+
const codec = serialize_serialize.servicePreimages(blake2b, serviceId, hash);
|
|
12183
12357
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
12184
|
-
const codec2 =
|
|
12358
|
+
const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
12185
12359
|
yield [StateEntryUpdateAction.Remove, codec2.key, EMPTY_BLOB];
|
|
12186
12360
|
break;
|
|
12187
12361
|
}
|
|
@@ -12193,12 +12367,12 @@ function* serializePreimages(preimages, encode, blake2b) {
|
|
|
12193
12367
|
function* serializeServiceUpdates(servicesUpdates, encode, blake2b) {
|
|
12194
12368
|
for (const { action, serviceId } of servicesUpdates ?? []) {
|
|
12195
12369
|
// new service being created or updated
|
|
12196
|
-
const codec =
|
|
12370
|
+
const codec = serialize_serialize.serviceData(serviceId);
|
|
12197
12371
|
yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, action.account)];
|
|
12198
12372
|
// additional lookup history update
|
|
12199
12373
|
if (action.kind === UpdateServiceKind.Create && action.lookupHistory !== null) {
|
|
12200
12374
|
const { lookupHistory } = action;
|
|
12201
|
-
const codec2 =
|
|
12375
|
+
const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
12202
12376
|
yield [StateEntryUpdateAction.Insert, codec2.key, encode(codec2.Codec, lookupHistory.slots)];
|
|
12203
12377
|
}
|
|
12204
12378
|
}
|
|
@@ -12208,53 +12382,53 @@ function* serializeBasicKeys(spec, update) {
|
|
|
12208
12382
|
return [StateEntryUpdateAction.Insert, codec.key, encoder_Encoder.encodeObject(codec.Codec, val, spec)];
|
|
12209
12383
|
}
|
|
12210
12384
|
if (update.authPools !== undefined) {
|
|
12211
|
-
yield doSerialize(update.authPools,
|
|
12385
|
+
yield doSerialize(update.authPools, serialize_serialize.authPools); // C(1)
|
|
12212
12386
|
}
|
|
12213
12387
|
if (update.authQueues !== undefined) {
|
|
12214
|
-
yield doSerialize(update.authQueues,
|
|
12388
|
+
yield doSerialize(update.authQueues, serialize_serialize.authQueues); // C(2)
|
|
12215
12389
|
}
|
|
12216
12390
|
if (update.recentBlocks !== undefined) {
|
|
12217
|
-
yield doSerialize(update.recentBlocks,
|
|
12391
|
+
yield doSerialize(update.recentBlocks, serialize_serialize.recentBlocks); // C(3)
|
|
12218
12392
|
}
|
|
12219
12393
|
const safroleData = getSafroleData(update.nextValidatorData, update.epochRoot, update.sealingKeySeries, update.ticketsAccumulator);
|
|
12220
12394
|
if (safroleData !== undefined) {
|
|
12221
|
-
yield doSerialize(safroleData,
|
|
12395
|
+
yield doSerialize(safroleData, serialize_serialize.safrole); // C(4)
|
|
12222
12396
|
}
|
|
12223
12397
|
if (update.disputesRecords !== undefined) {
|
|
12224
|
-
yield doSerialize(update.disputesRecords,
|
|
12398
|
+
yield doSerialize(update.disputesRecords, serialize_serialize.disputesRecords); // C(5)
|
|
12225
12399
|
}
|
|
12226
12400
|
if (update.entropy !== undefined) {
|
|
12227
|
-
yield doSerialize(update.entropy,
|
|
12401
|
+
yield doSerialize(update.entropy, serialize_serialize.entropy); // C(6)
|
|
12228
12402
|
}
|
|
12229
12403
|
if (update.designatedValidatorData !== undefined) {
|
|
12230
|
-
yield doSerialize(update.designatedValidatorData,
|
|
12404
|
+
yield doSerialize(update.designatedValidatorData, serialize_serialize.designatedValidators); // C(7)
|
|
12231
12405
|
}
|
|
12232
12406
|
if (update.currentValidatorData !== undefined) {
|
|
12233
|
-
yield doSerialize(update.currentValidatorData,
|
|
12407
|
+
yield doSerialize(update.currentValidatorData, serialize_serialize.currentValidators); // C(8)
|
|
12234
12408
|
}
|
|
12235
12409
|
if (update.previousValidatorData !== undefined) {
|
|
12236
|
-
yield doSerialize(update.previousValidatorData,
|
|
12410
|
+
yield doSerialize(update.previousValidatorData, serialize_serialize.previousValidators); // C(9)
|
|
12237
12411
|
}
|
|
12238
12412
|
if (update.availabilityAssignment !== undefined) {
|
|
12239
|
-
yield doSerialize(update.availabilityAssignment,
|
|
12413
|
+
yield doSerialize(update.availabilityAssignment, serialize_serialize.availabilityAssignment); // C(10)
|
|
12240
12414
|
}
|
|
12241
12415
|
if (update.timeslot !== undefined) {
|
|
12242
|
-
yield doSerialize(update.timeslot,
|
|
12416
|
+
yield doSerialize(update.timeslot, serialize_serialize.timeslot); // C(11)
|
|
12243
12417
|
}
|
|
12244
12418
|
if (update.privilegedServices !== undefined) {
|
|
12245
|
-
yield doSerialize(update.privilegedServices,
|
|
12419
|
+
yield doSerialize(update.privilegedServices, serialize_serialize.privilegedServices); // C(12)
|
|
12246
12420
|
}
|
|
12247
12421
|
if (update.statistics !== undefined) {
|
|
12248
|
-
yield doSerialize(update.statistics,
|
|
12422
|
+
yield doSerialize(update.statistics, serialize_serialize.statistics); // C(13)
|
|
12249
12423
|
}
|
|
12250
12424
|
if (update.accumulationQueue !== undefined) {
|
|
12251
|
-
yield doSerialize(update.accumulationQueue,
|
|
12425
|
+
yield doSerialize(update.accumulationQueue, serialize_serialize.accumulationQueue); // C(14)
|
|
12252
12426
|
}
|
|
12253
12427
|
if (update.recentlyAccumulated !== undefined) {
|
|
12254
|
-
yield doSerialize(update.recentlyAccumulated,
|
|
12428
|
+
yield doSerialize(update.recentlyAccumulated, serialize_serialize.recentlyAccumulated); // C(15)
|
|
12255
12429
|
}
|
|
12256
12430
|
if (update.accumulationOutputLog !== undefined) {
|
|
12257
|
-
yield doSerialize(update.accumulationOutputLog,
|
|
12431
|
+
yield doSerialize(update.accumulationOutputLog, serialize_serialize.accumulationOutputLog); // C(16)
|
|
12258
12432
|
}
|
|
12259
12433
|
}
|
|
12260
12434
|
function getSafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator) {
|
|
@@ -12367,41 +12541,41 @@ function convertInMemoryStateToDictionary(spec, blake2b, state) {
|
|
|
12367
12541
|
function doSerialize(codec) {
|
|
12368
12542
|
serialized.set(codec.key, encoder_Encoder.encodeObject(codec.Codec, codec.extract(state), spec));
|
|
12369
12543
|
}
|
|
12370
|
-
doSerialize(
|
|
12371
|
-
doSerialize(
|
|
12372
|
-
doSerialize(
|
|
12373
|
-
doSerialize(
|
|
12374
|
-
doSerialize(
|
|
12375
|
-
doSerialize(
|
|
12376
|
-
doSerialize(
|
|
12377
|
-
doSerialize(
|
|
12378
|
-
doSerialize(
|
|
12379
|
-
doSerialize(
|
|
12380
|
-
doSerialize(
|
|
12381
|
-
doSerialize(
|
|
12382
|
-
doSerialize(
|
|
12383
|
-
doSerialize(
|
|
12384
|
-
doSerialize(
|
|
12385
|
-
doSerialize(
|
|
12544
|
+
doSerialize(serialize_serialize.authPools); // C(1)
|
|
12545
|
+
doSerialize(serialize_serialize.authQueues); // C(2)
|
|
12546
|
+
doSerialize(serialize_serialize.recentBlocks); // C(3)
|
|
12547
|
+
doSerialize(serialize_serialize.safrole); // C(4)
|
|
12548
|
+
doSerialize(serialize_serialize.disputesRecords); // C(5)
|
|
12549
|
+
doSerialize(serialize_serialize.entropy); // C(6)
|
|
12550
|
+
doSerialize(serialize_serialize.designatedValidators); // C(7)
|
|
12551
|
+
doSerialize(serialize_serialize.currentValidators); // C(8)
|
|
12552
|
+
doSerialize(serialize_serialize.previousValidators); // C(9)
|
|
12553
|
+
doSerialize(serialize_serialize.availabilityAssignment); // C(10)
|
|
12554
|
+
doSerialize(serialize_serialize.timeslot); // C(11)
|
|
12555
|
+
doSerialize(serialize_serialize.privilegedServices); // C(12)
|
|
12556
|
+
doSerialize(serialize_serialize.statistics); // C(13)
|
|
12557
|
+
doSerialize(serialize_serialize.accumulationQueue); // C(14)
|
|
12558
|
+
doSerialize(serialize_serialize.recentlyAccumulated); // C(15)
|
|
12559
|
+
doSerialize(serialize_serialize.accumulationOutputLog); // C(16)
|
|
12386
12560
|
// services
|
|
12387
12561
|
for (const [serviceId, service] of state.services.entries()) {
|
|
12388
12562
|
// data
|
|
12389
|
-
const { key, Codec } =
|
|
12563
|
+
const { key, Codec } = serialize_serialize.serviceData(serviceId);
|
|
12390
12564
|
serialized.set(key, encoder_Encoder.encodeObject(Codec, service.getInfo()));
|
|
12391
12565
|
// preimages
|
|
12392
12566
|
for (const preimage of service.data.preimages.values()) {
|
|
12393
|
-
const { key, Codec } =
|
|
12567
|
+
const { key, Codec } = serialize_serialize.servicePreimages(blake2b, serviceId, preimage.hash);
|
|
12394
12568
|
serialized.set(key, encoder_Encoder.encodeObject(Codec, preimage.blob));
|
|
12395
12569
|
}
|
|
12396
12570
|
// storage
|
|
12397
12571
|
for (const storage of service.data.storage.values()) {
|
|
12398
|
-
const { key, Codec } =
|
|
12572
|
+
const { key, Codec } = serialize_serialize.serviceStorage(blake2b, serviceId, storage.key);
|
|
12399
12573
|
serialized.set(key, encoder_Encoder.encodeObject(Codec, storage.value));
|
|
12400
12574
|
}
|
|
12401
12575
|
// lookup history
|
|
12402
12576
|
for (const lookupHistoryList of service.data.lookupHistory.values()) {
|
|
12403
12577
|
for (const lookupHistory of lookupHistoryList) {
|
|
12404
|
-
const { key, Codec } =
|
|
12578
|
+
const { key, Codec } = serialize_serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
12405
12579
|
serialized.set(key, encoder_Encoder.encodeObject(Codec, lookupHistory.slots.slice()));
|
|
12406
12580
|
}
|
|
12407
12581
|
}
|
|
@@ -12451,6 +12625,7 @@ function loadState(spec, blake2b, entries) {
|
|
|
12451
12625
|
|
|
12452
12626
|
|
|
12453
12627
|
|
|
12628
|
+
|
|
12454
12629
|
;// CONCATENATED MODULE: ./packages/jam/database/leaf-db.ts
|
|
12455
12630
|
|
|
12456
12631
|
|
|
@@ -12609,7 +12784,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
|
|
|
12609
12784
|
const lookupHistoryItemCodec = descriptors_codec.object({
|
|
12610
12785
|
hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
12611
12786
|
length: descriptors_codec.u32,
|
|
12612
|
-
slots:
|
|
12787
|
+
slots: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32.asOpaque())).convert(seeThrough, tryAsLookupHistorySlots),
|
|
12613
12788
|
}, "LookupHistoryItem", ({ hash, length, slots }) => new LookupHistoryItem(hash, length, slots));
|
|
12614
12789
|
const lookupHistoryEntryCodec = descriptors_codec.object({
|
|
12615
12790
|
key: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
@@ -12652,7 +12827,11 @@ class ServiceWithCodec extends InMemoryService {
|
|
|
12652
12827
|
return new ServiceWithCodec(serviceId, data);
|
|
12653
12828
|
}
|
|
12654
12829
|
}
|
|
12655
|
-
const in_memory_state_codec_inMemoryStateCodec =
|
|
12830
|
+
const in_memory_state_codec_inMemoryStateCodec = (spec) => codec.Class(class State extends InMemoryState {
|
|
12831
|
+
static create(data) {
|
|
12832
|
+
return InMemoryState.new(spec, data);
|
|
12833
|
+
}
|
|
12834
|
+
}, {
|
|
12656
12835
|
// alpha
|
|
12657
12836
|
authPools: serialize.authPools.Codec,
|
|
12658
12837
|
// phi
|
|
@@ -12662,11 +12841,11 @@ const in_memory_state_codec_inMemoryStateCodec = descriptors_codec.Class(InMemor
|
|
|
12662
12841
|
// gamma_k
|
|
12663
12842
|
nextValidatorData: codecPerValidator(ValidatorData.Codec),
|
|
12664
12843
|
// gamma_z
|
|
12665
|
-
epochRoot:
|
|
12844
|
+
epochRoot: codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
12666
12845
|
// gamma_s
|
|
12667
12846
|
sealingKeySeries: SafroleSealingKeysData.Codec,
|
|
12668
12847
|
// gamma_a
|
|
12669
|
-
ticketsAccumulator: readonlyArray(
|
|
12848
|
+
ticketsAccumulator: readonlyArray(codec.sequenceVarLen(Ticket.Codec)).convert((x) => x, asKnownSize),
|
|
12670
12849
|
// psi
|
|
12671
12850
|
disputesRecords: serialize.disputesRecords.Codec,
|
|
12672
12851
|
// eta
|
|
@@ -12692,7 +12871,7 @@ const in_memory_state_codec_inMemoryStateCodec = descriptors_codec.Class(InMemor
|
|
|
12692
12871
|
// theta
|
|
12693
12872
|
accumulationOutputLog: serialize.accumulationOutputLog.Codec,
|
|
12694
12873
|
// delta
|
|
12695
|
-
services:
|
|
12874
|
+
services: codec.dictionary(codec.u32.asOpaque(), ServiceWithCodec.Codec, {
|
|
12696
12875
|
sortKeys: (a, b) => a - b,
|
|
12697
12876
|
}),
|
|
12698
12877
|
});
|
|
@@ -12739,7 +12918,7 @@ class InMemoryStates {
|
|
|
12739
12918
|
}
|
|
12740
12919
|
/** Insert a full state into the database. */
|
|
12741
12920
|
async insertState(headerHash, state) {
|
|
12742
|
-
const encoded = Encoder.encodeObject(inMemoryStateCodec, state, this.spec);
|
|
12921
|
+
const encoded = Encoder.encodeObject(inMemoryStateCodec(this.spec), state, this.spec);
|
|
12743
12922
|
this.db.set(headerHash, encoded);
|
|
12744
12923
|
return Result.ok(OK);
|
|
12745
12924
|
}
|
|
@@ -12748,7 +12927,7 @@ class InMemoryStates {
|
|
|
12748
12927
|
if (encodedState === undefined) {
|
|
12749
12928
|
return null;
|
|
12750
12929
|
}
|
|
12751
|
-
return Decoder.decodeObject(inMemoryStateCodec, encodedState, this.spec);
|
|
12930
|
+
return Decoder.decodeObject(inMemoryStateCodec(this.spec), encodedState, this.spec);
|
|
12752
12931
|
}
|
|
12753
12932
|
}
|
|
12754
12933
|
|
|
@@ -13856,21 +14035,21 @@ class TransitionHasher {
|
|
|
13856
14035
|
*/
|
|
13857
14036
|
extrinsic(extrinsicView) {
|
|
13858
14037
|
// https://graypaper.fluffylabs.dev/#/cc517d7/0cfb000cfb00?v=0.6.5
|
|
13859
|
-
const
|
|
14038
|
+
const guaranteesCount = numbers_tryAsU32(extrinsicView.guarantees.view().length);
|
|
14039
|
+
const countEncoded = encoder_Encoder.encodeObject(descriptors_codec.varU32, guaranteesCount);
|
|
14040
|
+
const guaranteesBlobs = extrinsicView.guarantees
|
|
13860
14041
|
.view()
|
|
13861
14042
|
.map((g) => g.view())
|
|
13862
|
-
.
|
|
14043
|
+
.reduce((aggregated, guarantee) => {
|
|
13863
14044
|
const reportHash = this.blake2b.hashBytes(guarantee.report.encoded()).asOpaque();
|
|
13864
|
-
|
|
13865
|
-
|
|
13866
|
-
|
|
13867
|
-
|
|
13868
|
-
|
|
13869
|
-
});
|
|
13870
|
-
const guaranteeBlob = encoder_Encoder.encodeObject(descriptors_codec.sequenceVarLen(dumpCodec), guarantees, this.context);
|
|
14045
|
+
aggregated.push(reportHash.raw);
|
|
14046
|
+
aggregated.push(guarantee.slot.encoded().raw);
|
|
14047
|
+
aggregated.push(guarantee.credentials.encoded().raw);
|
|
14048
|
+
return aggregated;
|
|
14049
|
+
}, [countEncoded.raw]);
|
|
13871
14050
|
const et = this.blake2b.hashBytes(extrinsicView.tickets.encoded()).asOpaque();
|
|
13872
14051
|
const ep = this.blake2b.hashBytes(extrinsicView.preimages.encoded()).asOpaque();
|
|
13873
|
-
const eg = this.blake2b.
|
|
14052
|
+
const eg = this.blake2b.hashBlobs(guaranteesBlobs).asOpaque();
|
|
13874
14053
|
const ea = this.blake2b.hashBytes(extrinsicView.assurances.encoded()).asOpaque();
|
|
13875
14054
|
const ed = this.blake2b.hashBytes(extrinsicView.disputes.encoded()).asOpaque();
|
|
13876
14055
|
const encoded = bytes_BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);
|
|
@@ -14529,7 +14708,7 @@ async function getRingCommitmentNoCache(bandersnatch, keys) {
|
|
|
14529
14708
|
if (commitmentResult[RESULT_INDEX] === ResultValues.Error) {
|
|
14530
14709
|
return result_Result.error(null);
|
|
14531
14710
|
}
|
|
14532
|
-
return result_Result.ok(bytes_Bytes.fromBlob(commitmentResult.subarray(1),
|
|
14711
|
+
return result_Result.ok(bytes_Bytes.fromBlob(commitmentResult.subarray(1), bandersnatch_BANDERSNATCH_RING_ROOT_BYTES).asOpaque());
|
|
14533
14712
|
}
|
|
14534
14713
|
// One byte for result discriminator (`ResultValues`) and the rest is entropy hash.
|
|
14535
14714
|
const TICKET_RESULT_LENGTH = 1 + hash_HASH_SIZE;
|
|
@@ -14683,7 +14862,7 @@ class Safrole {
|
|
|
14683
14862
|
* https://graypaper.fluffylabs.dev/#/5f542d7/0ea2000ea200
|
|
14684
14863
|
*/
|
|
14685
14864
|
if (isOffender) {
|
|
14686
|
-
return
|
|
14865
|
+
return validator_data_ValidatorData.create({
|
|
14687
14866
|
bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
14688
14867
|
ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
|
|
14689
14868
|
bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
|
|
@@ -14761,13 +14940,13 @@ class Safrole {
|
|
|
14761
14940
|
if (this.isNextEpoch(timeslot) &&
|
|
14762
14941
|
m >= this.chainSpec.contestLength &&
|
|
14763
14942
|
this.state.ticketsAccumulator.length === this.chainSpec.epochLength) {
|
|
14764
|
-
return
|
|
14943
|
+
return safrole_data_SafroleSealingKeysData.tickets(this.outsideInSequencer(this.state.ticketsAccumulator).tickets);
|
|
14765
14944
|
}
|
|
14766
14945
|
if (this.isSameEpoch(timeslot)) {
|
|
14767
14946
|
return this.state.sealingKeySeries;
|
|
14768
14947
|
}
|
|
14769
14948
|
// TODO [MaSi]: the result of fallback sequencer should be cached
|
|
14770
|
-
return
|
|
14949
|
+
return safrole_data_SafroleSealingKeysData.keys(this.fallbackKeySequencer(newEntropy, newValidators));
|
|
14771
14950
|
}
|
|
14772
14951
|
/**
|
|
14773
14952
|
* Returns epoch markers if the epoch is changed and null otherwise
|
|
@@ -15017,47 +15196,46 @@ class SafroleSeal {
|
|
|
15017
15196
|
}
|
|
15018
15197
|
async verifySeal(headerView, state) {
|
|
15019
15198
|
// we use transitioned keys already
|
|
15020
|
-
const validators = state.currentValidatorData;
|
|
15021
15199
|
const validatorIndex = headerView.bandersnatchBlockAuthorIndex.materialize();
|
|
15022
|
-
const
|
|
15023
|
-
if (
|
|
15200
|
+
const authorKeys = state.currentValidatorData.at(validatorIndex);
|
|
15201
|
+
if (authorKeys === undefined) {
|
|
15024
15202
|
return result_Result.error(SafroleSealError.InvalidValidatorIndex);
|
|
15025
15203
|
}
|
|
15026
15204
|
const timeSlot = headerView.timeSlotIndex.materialize();
|
|
15027
15205
|
const sealingKeys = state.sealingKeySeries;
|
|
15028
15206
|
const entropy = state.currentEntropy;
|
|
15029
15207
|
if (sealingKeys.kind === SafroleSealingKeysKind.Tickets) {
|
|
15030
|
-
return await this.verifySealWithTicket(sealingKeys.tickets, timeSlot, entropy,
|
|
15208
|
+
return await this.verifySealWithTicket(sealingKeys.tickets, timeSlot, entropy, authorKeys, headerView);
|
|
15031
15209
|
}
|
|
15032
|
-
return await this.verifySealWithKeys(sealingKeys.keys,
|
|
15210
|
+
return await this.verifySealWithKeys(sealingKeys.keys, timeSlot, entropy, authorKeys, headerView);
|
|
15033
15211
|
}
|
|
15034
15212
|
/** Regular (non-fallback) mode of Safrole. */
|
|
15035
|
-
async verifySealWithTicket(tickets, timeSlot, entropy,
|
|
15213
|
+
async verifySealWithTicket(tickets, timeSlot, entropy, validatorData, headerView) {
|
|
15036
15214
|
const index = timeSlot % tickets.length;
|
|
15037
|
-
const
|
|
15038
|
-
const payload = bytes_BytesBlob.blobFromParts(JAM_TICKET_SEAL, entropy.raw, new Uint8Array([attempt]));
|
|
15215
|
+
const ticket = tickets.at(index);
|
|
15216
|
+
const payload = bytes_BytesBlob.blobFromParts(JAM_TICKET_SEAL, entropy.raw, new Uint8Array([ticket?.attempt ?? 0]));
|
|
15039
15217
|
// verify seal correctness
|
|
15040
|
-
const authorKey =
|
|
15218
|
+
const authorKey = validatorData.bandersnatch;
|
|
15041
15219
|
const result = await bandersnatch_vrf.verifySeal(await this.bandersnatch, authorKey ?? BANDERSNATCH_ZERO_KEY, headerView.seal.materialize(), payload, encodeUnsealedHeader(headerView));
|
|
15042
15220
|
if (result.isError) {
|
|
15043
15221
|
return result_Result.error(SafroleSealError.IncorrectSeal);
|
|
15044
15222
|
}
|
|
15045
|
-
if (!id.isEqualTo(result.ok)) {
|
|
15223
|
+
if (ticket === undefined || !ticket.id.isEqualTo(result.ok)) {
|
|
15046
15224
|
return result_Result.error(SafroleSealError.InvalidTicket);
|
|
15047
15225
|
}
|
|
15048
15226
|
return result_Result.ok(result.ok);
|
|
15049
15227
|
}
|
|
15050
15228
|
/** Fallback mode of Safrole. */
|
|
15051
|
-
async verifySealWithKeys(keys,
|
|
15229
|
+
async verifySealWithKeys(keys, timeSlot, entropy, authorKey, headerView) {
|
|
15052
15230
|
const index = timeSlot % keys.length;
|
|
15053
|
-
const sealingKey = keys
|
|
15054
|
-
|
|
15231
|
+
const sealingKey = keys.at(index);
|
|
15232
|
+
const authorBandersnatchKey = authorKey.bandersnatch;
|
|
15233
|
+
if (sealingKey === undefined || !sealingKey.isEqualTo(authorBandersnatchKey)) {
|
|
15055
15234
|
return result_Result.error(SafroleSealError.InvalidValidator, `Invalid Validator. Expected: ${sealingKey}, got: ${authorKey.bandersnatch}`);
|
|
15056
15235
|
}
|
|
15057
15236
|
// verify seal correctness
|
|
15058
15237
|
const payload = bytes_BytesBlob.blobFromParts(JAM_FALLBACK_SEAL, entropy.raw);
|
|
15059
|
-
const
|
|
15060
|
-
const result = await bandersnatch_vrf.verifySeal(await this.bandersnatch, blockAuthorKey ?? BANDERSNATCH_ZERO_KEY, headerView.seal.materialize(), payload, encodeUnsealedHeader(headerView));
|
|
15238
|
+
const result = await bandersnatch_vrf.verifySeal(await this.bandersnatch, authorBandersnatchKey, headerView.seal.materialize(), payload, encodeUnsealedHeader(headerView));
|
|
15061
15239
|
if (result.isError) {
|
|
15062
15240
|
return result_Result.error(SafroleSealError.IncorrectSeal);
|
|
15063
15241
|
}
|
|
@@ -21254,7 +21432,7 @@ class Assign {
|
|
|
21254
21432
|
// NOTE: Here we know the core index is valid
|
|
21255
21433
|
const coreIndex = tryAsCoreIndex(Number(maybeCoreIndex));
|
|
21256
21434
|
const decoder = decoder_Decoder.fromBlob(res);
|
|
21257
|
-
const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE), AUTHORIZATION_QUEUE_SIZE);
|
|
21435
|
+
const authQueue = decoder.sequenceFixLen(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE);
|
|
21258
21436
|
const fixedSizeAuthQueue = FixedSizeArray.new(authQueue, AUTHORIZATION_QUEUE_SIZE);
|
|
21259
21437
|
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
|
|
21260
21438
|
if (result.isOk) {
|
|
@@ -21450,7 +21628,7 @@ class Checkpoint {
|
|
|
21450
21628
|
|
|
21451
21629
|
|
|
21452
21630
|
const designate_IN_OUT_REG = 7;
|
|
21453
|
-
const VALIDATOR_DATA_BYTES = tryAsExactBytes(
|
|
21631
|
+
const VALIDATOR_DATA_BYTES = tryAsExactBytes(validator_data_ValidatorData.Codec.sizeHint);
|
|
21454
21632
|
/**
|
|
21455
21633
|
* Designate a new set of validator keys.
|
|
21456
21634
|
*
|
|
@@ -21479,7 +21657,7 @@ class Designate {
|
|
|
21479
21657
|
return PvmExecution.Panic;
|
|
21480
21658
|
}
|
|
21481
21659
|
const decoder = decoder_Decoder.fromBlob(res);
|
|
21482
|
-
const validatorsData = decoder.sequenceFixLen(
|
|
21660
|
+
const validatorsData = decoder.sequenceFixLen(validator_data_ValidatorData.Codec, this.chainSpec.validatorsCount);
|
|
21483
21661
|
const result = this.partialState.updateValidatorsData(tryAsPerValidator(validatorsData, this.chainSpec));
|
|
21484
21662
|
if (result.isError) {
|
|
21485
21663
|
logger_logger.trace `DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- HUH`;
|
|
@@ -23135,9 +23313,10 @@ class Accumulate {
|
|
|
23135
23313
|
const recentlyAccumulated = tryAsPerEpochBlock(newRecentlyAccumulated, this.chainSpec);
|
|
23136
23314
|
const accumulationQueue = this.state.accumulationQueue.slice();
|
|
23137
23315
|
accumulationQueue[phaseIndex] = pruneQueue(toAccumulateLater, accumulatedSet);
|
|
23316
|
+
const timeslot = this.state.timeslot;
|
|
23138
23317
|
for (let i = 1; i < epochLength; i++) {
|
|
23139
23318
|
const queueIndex = (phaseIndex + epochLength - i) % epochLength;
|
|
23140
|
-
if (i < slot -
|
|
23319
|
+
if (i < slot - timeslot) {
|
|
23141
23320
|
accumulationQueue[queueIndex] = [];
|
|
23142
23321
|
}
|
|
23143
23322
|
else {
|
|
@@ -23349,7 +23528,6 @@ class DeferredTransfers {
|
|
|
23349
23528
|
|
|
23350
23529
|
|
|
23351
23530
|
|
|
23352
|
-
|
|
23353
23531
|
/**
|
|
23354
23532
|
* Maintain a list of available authorizations per core.
|
|
23355
23533
|
*
|
|
@@ -23378,11 +23556,12 @@ class Authorization {
|
|
|
23378
23556
|
*/
|
|
23379
23557
|
transition(input) {
|
|
23380
23558
|
const authPoolsUpdate = this.state.authPools.slice();
|
|
23559
|
+
const authQueues = this.state.authQueues;
|
|
23381
23560
|
// we transition authorizations for each core.
|
|
23382
23561
|
for (let coreIndex = tryAsCoreIndex(0); coreIndex < this.chainSpec.coresCount; coreIndex++) {
|
|
23383
23562
|
let pool = authPoolsUpdate[coreIndex].slice();
|
|
23384
23563
|
// the queue is only read (we should most likely use `ArrayView` here).
|
|
23385
|
-
const queue =
|
|
23564
|
+
const queue = authQueues[coreIndex];
|
|
23386
23565
|
// if there were any used hashes - remove them
|
|
23387
23566
|
const usedHashes = input.used.get(coreIndex);
|
|
23388
23567
|
if (usedHashes !== undefined) {
|
|
@@ -23556,14 +23735,18 @@ class RecentHistory {
|
|
|
23556
23735
|
* https://graypaper.fluffylabs.dev/#/1c979cb/0f55020f5502?v=0.7.1
|
|
23557
23736
|
*/
|
|
23558
23737
|
partialTransition(input) {
|
|
23559
|
-
const
|
|
23738
|
+
const stateBlocks = this.state.recentBlocks;
|
|
23739
|
+
const recentBlocks = stateBlocks.blocks.slice();
|
|
23560
23740
|
const lastState = recentBlocks.length > 0 ? recentBlocks[recentBlocks.length - 1] : null;
|
|
23561
23741
|
// update the posterior root of previous state.
|
|
23562
23742
|
if (lastState !== null) {
|
|
23563
23743
|
lastState.postStateRoot = input.priorStateRoot;
|
|
23564
23744
|
}
|
|
23565
23745
|
return {
|
|
23566
|
-
recentBlocks:
|
|
23746
|
+
recentBlocks: RecentBlocks.create({
|
|
23747
|
+
blocks: sized_array_asKnownSize(recentBlocks),
|
|
23748
|
+
accumulationLog: stateBlocks.accumulationLog,
|
|
23749
|
+
}), // β_H†
|
|
23567
23750
|
};
|
|
23568
23751
|
}
|
|
23569
23752
|
/**
|
|
@@ -23575,8 +23758,8 @@ class RecentHistory {
|
|
|
23575
23758
|
transition(input) {
|
|
23576
23759
|
const recentBlocks = input.partial.recentBlocks.blocks.slice();
|
|
23577
23760
|
// `β′_B`
|
|
23578
|
-
const mmr = this.state.recentBlocks.
|
|
23579
|
-
? MerkleMountainRange.fromPeaks(this.hasher, this.state.recentBlocks.
|
|
23761
|
+
const mmr = this.state.recentBlocks.accumulationLog !== null
|
|
23762
|
+
? MerkleMountainRange.fromPeaks(this.hasher, this.state.recentBlocks.accumulationLog)
|
|
23580
23763
|
: MerkleMountainRange.empty(this.hasher);
|
|
23581
23764
|
// append the accumulation root
|
|
23582
23765
|
mmr.append(input.accumulateRoot);
|
|
@@ -23594,7 +23777,7 @@ class RecentHistory {
|
|
|
23594
23777
|
}
|
|
23595
23778
|
// write back to the state.
|
|
23596
23779
|
return {
|
|
23597
|
-
recentBlocks:
|
|
23780
|
+
recentBlocks: RecentBlocks.create(RecentBlocks.create({
|
|
23598
23781
|
blocks: sized_array_asKnownSize(recentBlocks),
|
|
23599
23782
|
accumulationLog: peaks,
|
|
23600
23783
|
})),
|
|
@@ -23806,7 +23989,6 @@ function verifyReportsBasic(input) {
|
|
|
23806
23989
|
|
|
23807
23990
|
|
|
23808
23991
|
|
|
23809
|
-
|
|
23810
23992
|
const verify_contextual_logger = Logger.new(import.meta.filename, "stf:reports");
|
|
23811
23993
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/15eb0115eb01?v=0.6.7 */
|
|
23812
23994
|
function verifyContextualValidity(input, state, headerChain, maxLookupAnchorAge) {
|
|
@@ -23919,7 +24101,7 @@ function verifyRefineContexts(minLookupSlot, contexts, recentBlocksPartialUpdate
|
|
|
23919
24101
|
return result_Result.error(ReportsError.BadStateRoot, `Anchor state root mismatch. Got: ${context.stateRoot}, expected: ${recentBlock.postStateRoot}.`);
|
|
23920
24102
|
}
|
|
23921
24103
|
// check beefy root
|
|
23922
|
-
const beefyRoot =
|
|
24104
|
+
const beefyRoot = recentBlock.accumulationResult;
|
|
23923
24105
|
if (!beefyRoot.isEqualTo(context.beefyRoot)) {
|
|
23924
24106
|
return result_Result.error(ReportsError.BadBeefyMmrRoot, `Invalid BEEFY super peak hash. Got: ${context.beefyRoot}, expected: ${beefyRoot}. Anchor: ${recentBlock.headerHash}`);
|
|
23925
24107
|
}
|
|
@@ -24161,8 +24343,9 @@ function verifyPostSignatureChecks(input, availabilityAssignment, authPools, ser
|
|
|
24161
24343
|
* https://graypaper.fluffylabs.dev/#/5f542d7/15eb0015ed00
|
|
24162
24344
|
*/
|
|
24163
24345
|
const authorizerHash = report.authorizerHash;
|
|
24164
|
-
const authorizerPool = authPools
|
|
24165
|
-
|
|
24346
|
+
const authorizerPool = authPools.get(coreIndex);
|
|
24347
|
+
const pool = authorizerPool?.materialize() ?? [];
|
|
24348
|
+
if (pool.find((hash) => hash.isEqualTo(authorizerHash)) === undefined) {
|
|
24166
24349
|
return result_Result.error(ReportsError.CoreUnauthorized, `Authorizer hash not found in the pool of core ${coreIndex}: ${authorizerHash}`);
|
|
24167
24350
|
}
|
|
24168
24351
|
/**
|
|
@@ -24292,7 +24475,8 @@ class Reports {
|
|
|
24292
24475
|
return verifyCredentials(input.guarantees, workReportHashes, input.slot, (headerTimeSlot, guaranteeTimeSlot) => this.getGuarantorAssignment(headerTimeSlot, guaranteeTimeSlot, input.newEntropy));
|
|
24293
24476
|
}
|
|
24294
24477
|
verifyPostSignatureChecks(input, assurancesAvailAssignment) {
|
|
24295
|
-
|
|
24478
|
+
const authPoolsView = this.state.view().authPoolsView();
|
|
24479
|
+
return verifyPostSignatureChecks(input, assurancesAvailAssignment, authPoolsView, (id) => this.state.getService(id));
|
|
24296
24480
|
}
|
|
24297
24481
|
verifyContextualValidity(input) {
|
|
24298
24482
|
return verifyContextualValidity(input, this.state, this.headerChain, this.chainSpec.maxLookupAnchorAge);
|