@typeberry/jam 0.1.3-ca63b35 → 0.2.0-74f246e
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 +1075 -879
- package/bootstrap-generator.mjs.map +1 -1
- package/bootstrap-importer.mjs +1231 -923
- package/bootstrap-importer.mjs.map +1 -1
- package/bootstrap-network.mjs +1011 -815
- package/bootstrap-network.mjs.map +1 -1
- package/index.js +1305 -921
- 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);
|
|
@@ -3540,7 +3540,7 @@ var GpVersion;
|
|
|
3540
3540
|
(function (GpVersion) {
|
|
3541
3541
|
GpVersion["V0_6_7"] = "0.6.7";
|
|
3542
3542
|
GpVersion["V0_7_0"] = "0.7.0";
|
|
3543
|
-
GpVersion["V0_7_1"] = "0.7.1
|
|
3543
|
+
GpVersion["V0_7_1"] = "0.7.1";
|
|
3544
3544
|
GpVersion["V0_7_2"] = "0.7.2-preview";
|
|
3545
3545
|
})(GpVersion || (GpVersion = {}));
|
|
3546
3546
|
var TestSuite;
|
|
@@ -3549,11 +3549,11 @@ var TestSuite;
|
|
|
3549
3549
|
TestSuite["JAMDUNA"] = "jamduna";
|
|
3550
3550
|
})(TestSuite || (TestSuite = {}));
|
|
3551
3551
|
const DEFAULT_SUITE = TestSuite.W3F_DAVXY;
|
|
3552
|
-
const
|
|
3552
|
+
const DEFAULT_VERSION = GpVersion.V0_7_1;
|
|
3553
3553
|
const env = typeof process === "undefined" ? {} : process.env;
|
|
3554
|
-
const DEFAULT_VERSION = GpVersion.V0_7_0;
|
|
3555
3554
|
let CURRENT_VERSION = parseCurrentVersion(env.GP_VERSION) ?? DEFAULT_VERSION;
|
|
3556
3555
|
let CURRENT_SUITE = parseCurrentSuite(env.TEST_SUITE) ?? DEFAULT_SUITE;
|
|
3556
|
+
const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1, GpVersion.V0_7_2];
|
|
3557
3557
|
function parseCurrentVersion(env) {
|
|
3558
3558
|
if (env === undefined) {
|
|
3559
3559
|
return undefined;
|
|
@@ -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,21 +9718,265 @@ const MAX_SHIFT_U64 = 64n;
|
|
|
9631
9718
|
|
|
9632
9719
|
|
|
9633
9720
|
/**
|
|
9634
|
-
* `
|
|
9721
|
+
* `H = 8`: The size of recent history, in blocks.
|
|
9635
9722
|
*
|
|
9636
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
9723
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/416300416500
|
|
9637
9724
|
*/
|
|
9638
|
-
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
|
+
}
|
|
9639
9757
|
/**
|
|
9640
|
-
*
|
|
9758
|
+
* Recent history of blocks.
|
|
9641
9759
|
*
|
|
9642
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/
|
|
9760
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
|
|
9643
9761
|
*/
|
|
9644
|
-
|
|
9645
|
-
|
|
9646
|
-
|
|
9647
|
-
|
|
9648
|
-
|
|
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
|
|
9649
9980
|
*/
|
|
9650
9981
|
const ELECTIVE_BYTE_BALANCE = 1n;
|
|
9651
9982
|
const zeroSizeHint = {
|
|
@@ -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
|
-
static Codec = descriptors_codec.Class(AutoAccumulate, {
|
|
9827
|
-
service: descriptors_codec.u32.asOpaque(),
|
|
9828
|
-
gasLimit: descriptors_codec.u64.asOpaque(),
|
|
9829
|
-
});
|
|
9830
|
-
static create({ service, gasLimit }) {
|
|
9831
|
-
return new AutoAccumulate(service, gasLimit);
|
|
9832
|
-
}
|
|
9833
|
-
constructor(
|
|
9834
|
-
/** Service id that auto-accumulates. */
|
|
9835
|
-
service,
|
|
9836
|
-
/** Gas limit for auto-accumulation. */
|
|
9837
|
-
gasLimit) {
|
|
9838
|
-
this.service = service;
|
|
9839
|
-
this.gasLimit = gasLimit;
|
|
9840
|
-
}
|
|
9841
|
-
}
|
|
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));
|
|
9842
10157
|
/**
|
|
9843
|
-
*
|
|
10158
|
+
* Activity Record of a single validator.
|
|
10159
|
+
*
|
|
10160
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/183701183701
|
|
9844
10161
|
*/
|
|
9845
|
-
class
|
|
9846
|
-
|
|
9847
|
-
|
|
9848
|
-
|
|
9849
|
-
|
|
9850
|
-
|
|
9851
|
-
|
|
9852
|
-
static Codec = descriptors_codec.Class(
|
|
9853
|
-
|
|
9854
|
-
|
|
9855
|
-
|
|
9856
|
-
|
|
9857
|
-
|
|
9858
|
-
|
|
9859
|
-
autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
|
|
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,
|
|
9860
10176
|
});
|
|
9861
|
-
static create(
|
|
9862
|
-
return new
|
|
10177
|
+
static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
|
|
10178
|
+
return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
|
|
9863
10179
|
}
|
|
9864
10180
|
constructor(
|
|
9865
|
-
/**
|
|
9866
|
-
|
|
9867
|
-
|
|
9868
|
-
|
|
9869
|
-
|
|
9870
|
-
|
|
9871
|
-
/**
|
|
9872
|
-
|
|
9873
|
-
/**
|
|
9874
|
-
|
|
9875
|
-
|
|
9876
|
-
|
|
9877
|
-
|
|
9878
|
-
|
|
9879
|
-
|
|
9880
|
-
|
|
9881
|
-
|
|
9882
|
-
|
|
9883
|
-
|
|
9884
|
-
|
|
9885
|
-
|
|
9886
|
-
|
|
9887
|
-
this.autoAccumulateServices = 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;
|
|
10199
|
+
}
|
|
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
|
|
|
@@ -10289,298 +10680,43 @@ class UpdateService {
|
|
|
10289
10680
|
});
|
|
10290
10681
|
}
|
|
10291
10682
|
}
|
|
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
|
-
const codecServiceId = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
|
|
10339
|
-
? descriptors_codec.u32.asOpaque()
|
|
10340
|
-
: descriptors_codec.varU32.convert((s) => numbers_tryAsU32(s), (i) => tryAsServiceId(i));
|
|
10341
|
-
/**
|
|
10342
|
-
* Activity Record of a single validator.
|
|
10343
|
-
*
|
|
10344
|
-
* https://graypaper.fluffylabs.dev/#/579bd12/183701183701
|
|
10345
|
-
*/
|
|
10346
|
-
class ValidatorStatistics {
|
|
10347
|
-
blocks;
|
|
10348
|
-
tickets;
|
|
10349
|
-
preImages;
|
|
10350
|
-
preImagesSize;
|
|
10351
|
-
guarantees;
|
|
10352
|
-
assurances;
|
|
10353
|
-
static Codec = descriptors_codec.Class(ValidatorStatistics, {
|
|
10354
|
-
blocks: descriptors_codec.u32,
|
|
10355
|
-
tickets: descriptors_codec.u32,
|
|
10356
|
-
preImages: descriptors_codec.u32,
|
|
10357
|
-
preImagesSize: descriptors_codec.u32,
|
|
10358
|
-
guarantees: descriptors_codec.u32,
|
|
10359
|
-
assurances: descriptors_codec.u32,
|
|
10360
|
-
});
|
|
10361
|
-
static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
|
|
10362
|
-
return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
|
|
10363
|
-
}
|
|
10364
|
-
constructor(
|
|
10365
|
-
/** The number of blocks produced by the validator. */
|
|
10366
|
-
blocks,
|
|
10367
|
-
/** The number of tickets introduced by the validator. */
|
|
10368
|
-
tickets,
|
|
10369
|
-
/** The number of preimages introduced by the validator. */
|
|
10370
|
-
preImages,
|
|
10371
|
-
/** The total number of octets across all preimages introduced by the validator. */
|
|
10372
|
-
preImagesSize,
|
|
10373
|
-
/** The number of reports guaranteed by the validator. */
|
|
10374
|
-
guarantees,
|
|
10375
|
-
/** The number of availability assurances made by the validator. */
|
|
10376
|
-
assurances) {
|
|
10377
|
-
this.blocks = blocks;
|
|
10378
|
-
this.tickets = tickets;
|
|
10379
|
-
this.preImages = preImages;
|
|
10380
|
-
this.preImagesSize = preImagesSize;
|
|
10381
|
-
this.guarantees = guarantees;
|
|
10382
|
-
this.assurances = assurances;
|
|
10383
|
-
}
|
|
10384
|
-
static empty() {
|
|
10385
|
-
const zero = numbers_tryAsU32(0);
|
|
10386
|
-
return new ValidatorStatistics(zero, zero, zero, zero, zero, zero);
|
|
10387
|
-
}
|
|
10388
|
-
}
|
|
10389
|
-
const codecVarU16 = descriptors_codec.varU32.convert((i) => numbers_tryAsU32(i), (o) => numbers_tryAsU16(o));
|
|
10390
|
-
/** Encode/decode unsigned gas. */
|
|
10391
|
-
const codecVarGas = descriptors_codec.varU64.convert((g) => numbers_tryAsU64(g), (i) => tryAsServiceGas(i));
|
|
10392
|
-
/**
|
|
10393
|
-
* Single core statistics.
|
|
10394
|
-
* Updated per block, based on incoming work reports (`w`).
|
|
10395
|
-
*
|
|
10396
|
-
* https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
|
|
10397
|
-
* https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
|
|
10398
|
-
*/
|
|
10399
|
-
class CoreStatistics {
|
|
10400
|
-
dataAvailabilityLoad;
|
|
10401
|
-
popularity;
|
|
10402
|
-
imports;
|
|
10403
|
-
exports;
|
|
10404
|
-
extrinsicSize;
|
|
10405
|
-
extrinsicCount;
|
|
10406
|
-
bundleSize;
|
|
10407
|
-
gasUsed;
|
|
10408
|
-
static Codec = Compatibility.isGreaterOrEqual(GpVersion.V0_7_0)
|
|
10409
|
-
? descriptors_codec.Class(CoreStatistics, {
|
|
10410
|
-
dataAvailabilityLoad: descriptors_codec.varU32,
|
|
10411
|
-
popularity: codecVarU16,
|
|
10412
|
-
imports: codecVarU16,
|
|
10413
|
-
extrinsicCount: codecVarU16,
|
|
10414
|
-
extrinsicSize: descriptors_codec.varU32,
|
|
10415
|
-
exports: codecVarU16,
|
|
10416
|
-
bundleSize: descriptors_codec.varU32,
|
|
10417
|
-
gasUsed: codecVarGas,
|
|
10418
|
-
})
|
|
10419
|
-
: descriptors_codec.Class(CoreStatistics, {
|
|
10420
|
-
dataAvailabilityLoad: descriptors_codec.varU32,
|
|
10421
|
-
popularity: codecVarU16,
|
|
10422
|
-
imports: codecVarU16,
|
|
10423
|
-
exports: codecVarU16,
|
|
10424
|
-
extrinsicSize: descriptors_codec.varU32,
|
|
10425
|
-
extrinsicCount: codecVarU16,
|
|
10426
|
-
bundleSize: descriptors_codec.varU32,
|
|
10427
|
-
gasUsed: codecVarGas,
|
|
10428
|
-
});
|
|
10429
|
-
static create(v) {
|
|
10430
|
-
return new CoreStatistics(v.dataAvailabilityLoad, v.popularity, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.bundleSize, v.gasUsed);
|
|
10431
|
-
}
|
|
10432
|
-
constructor(
|
|
10433
|
-
/** `d` */
|
|
10434
|
-
dataAvailabilityLoad,
|
|
10435
|
-
/** `p` */
|
|
10436
|
-
popularity,
|
|
10437
|
-
/** `i` */
|
|
10438
|
-
imports,
|
|
10439
|
-
/** `e` */
|
|
10440
|
-
exports,
|
|
10441
|
-
/** `z` */
|
|
10442
|
-
extrinsicSize,
|
|
10443
|
-
/** `x` */
|
|
10444
|
-
extrinsicCount,
|
|
10445
|
-
/** `b` */
|
|
10446
|
-
bundleSize,
|
|
10447
|
-
/** `u` */
|
|
10448
|
-
gasUsed) {
|
|
10449
|
-
this.dataAvailabilityLoad = dataAvailabilityLoad;
|
|
10450
|
-
this.popularity = popularity;
|
|
10451
|
-
this.imports = imports;
|
|
10452
|
-
this.exports = exports;
|
|
10453
|
-
this.extrinsicSize = extrinsicSize;
|
|
10454
|
-
this.extrinsicCount = extrinsicCount;
|
|
10455
|
-
this.bundleSize = bundleSize;
|
|
10456
|
-
this.gasUsed = gasUsed;
|
|
10457
|
-
}
|
|
10458
|
-
static empty() {
|
|
10459
|
-
const zero = numbers_tryAsU32(0);
|
|
10460
|
-
const zero16 = numbers_tryAsU16(0);
|
|
10461
|
-
const zeroGas = tryAsServiceGas(0);
|
|
10462
|
-
return new CoreStatistics(zero, zero16, zero16, zero16, zero, zero16, zero, zeroGas);
|
|
10463
|
-
}
|
|
10464
|
-
}
|
|
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 = {}));
|
|
10465
10691
|
/**
|
|
10466
|
-
*
|
|
10467
|
-
* Updated per block, based on available work reports (`W`).
|
|
10692
|
+
* Update service storage item.
|
|
10468
10693
|
*
|
|
10469
|
-
*
|
|
10470
|
-
* https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L77
|
|
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.isGreaterOrEqual(GpVersion.V0_7_0)
|
|
10486
|
-
? descriptors_codec.Class(ServiceStatistics, {
|
|
10487
|
-
providedCount: codecVarU16,
|
|
10488
|
-
providedSize: descriptors_codec.varU32,
|
|
10489
|
-
refinementCount: descriptors_codec.varU32,
|
|
10490
|
-
refinementGasUsed: codecVarGas,
|
|
10491
|
-
imports: codecVarU16,
|
|
10492
|
-
extrinsicCount: codecVarU16,
|
|
10493
|
-
extrinsicSize: descriptors_codec.varU32,
|
|
10494
|
-
exports: codecVarU16,
|
|
10495
|
-
accumulateCount: descriptors_codec.varU32,
|
|
10496
|
-
accumulateGasUsed: codecVarGas,
|
|
10497
|
-
onTransfersCount: descriptors_codec.varU32,
|
|
10498
|
-
onTransfersGasUsed: codecVarGas,
|
|
10499
|
-
})
|
|
10500
|
-
: descriptors_codec.Class(ServiceStatistics, {
|
|
10501
|
-
providedCount: codecVarU16,
|
|
10502
|
-
providedSize: descriptors_codec.varU32,
|
|
10503
|
-
refinementCount: descriptors_codec.varU32,
|
|
10504
|
-
refinementGasUsed: codecVarGas,
|
|
10505
|
-
imports: codecVarU16,
|
|
10506
|
-
exports: codecVarU16,
|
|
10507
|
-
extrinsicSize: descriptors_codec.varU32,
|
|
10508
|
-
extrinsicCount: codecVarU16,
|
|
10509
|
-
accumulateCount: descriptors_codec.varU32,
|
|
10510
|
-
accumulateGasUsed: codecVarGas,
|
|
10511
|
-
onTransfersCount: descriptors_codec.varU32,
|
|
10512
|
-
onTransfersGasUsed: codecVarGas,
|
|
10513
|
-
});
|
|
10514
|
-
static create(v) {
|
|
10515
|
-
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;
|
|
10516
10702
|
}
|
|
10517
|
-
|
|
10518
|
-
|
|
10519
|
-
providedCount,
|
|
10520
|
-
/** `p.1` */
|
|
10521
|
-
providedSize,
|
|
10522
|
-
/** `r.0` */
|
|
10523
|
-
refinementCount,
|
|
10524
|
-
/** `r.1` */
|
|
10525
|
-
refinementGasUsed,
|
|
10526
|
-
/** `i` */
|
|
10527
|
-
imports,
|
|
10528
|
-
/** `e` */
|
|
10529
|
-
exports,
|
|
10530
|
-
/** `z` */
|
|
10531
|
-
extrinsicSize,
|
|
10532
|
-
/** `x` */
|
|
10533
|
-
extrinsicCount,
|
|
10534
|
-
/** `a.0` */
|
|
10535
|
-
accumulateCount,
|
|
10536
|
-
/** `a.1` */
|
|
10537
|
-
accumulateGasUsed,
|
|
10538
|
-
/** `t.0` */
|
|
10539
|
-
onTransfersCount,
|
|
10540
|
-
/** `t.1` */
|
|
10541
|
-
onTransfersGasUsed) {
|
|
10542
|
-
this.providedCount = providedCount;
|
|
10543
|
-
this.providedSize = providedSize;
|
|
10544
|
-
this.refinementCount = refinementCount;
|
|
10545
|
-
this.refinementGasUsed = refinementGasUsed;
|
|
10546
|
-
this.imports = imports;
|
|
10547
|
-
this.exports = exports;
|
|
10548
|
-
this.extrinsicSize = extrinsicSize;
|
|
10549
|
-
this.extrinsicCount = extrinsicCount;
|
|
10550
|
-
this.accumulateCount = accumulateCount;
|
|
10551
|
-
this.accumulateGasUsed = accumulateGasUsed;
|
|
10552
|
-
this.onTransfersCount = onTransfersCount;
|
|
10553
|
-
this.onTransfersGasUsed = onTransfersGasUsed;
|
|
10703
|
+
static set({ serviceId, storage }) {
|
|
10704
|
+
return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Set, storage });
|
|
10554
10705
|
}
|
|
10555
|
-
static
|
|
10556
|
-
|
|
10557
|
-
const zero16 = numbers_tryAsU16(0);
|
|
10558
|
-
const zeroGas = tryAsServiceGas(0);
|
|
10559
|
-
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 });
|
|
10560
10708
|
}
|
|
10561
|
-
|
|
10562
|
-
|
|
10563
|
-
|
|
10564
|
-
|
|
10565
|
-
|
|
10566
|
-
cores;
|
|
10567
|
-
services;
|
|
10568
|
-
static Codec = descriptors_codec.Class(StatisticsData, {
|
|
10569
|
-
current: codecPerValidator(ValidatorStatistics.Codec),
|
|
10570
|
-
previous: codecPerValidator(ValidatorStatistics.Codec),
|
|
10571
|
-
cores: codecPerCore(CoreStatistics.Codec),
|
|
10572
|
-
services: descriptors_codec.dictionary(codecServiceId, ServiceStatistics.Codec, {
|
|
10573
|
-
sortKeys: (a, b) => a - b,
|
|
10574
|
-
}),
|
|
10575
|
-
});
|
|
10576
|
-
static create(v) {
|
|
10577
|
-
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;
|
|
10578
10714
|
}
|
|
10579
|
-
|
|
10580
|
-
this.
|
|
10581
|
-
|
|
10582
|
-
|
|
10583
|
-
this.
|
|
10715
|
+
get value() {
|
|
10716
|
+
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
10717
|
+
return null;
|
|
10718
|
+
}
|
|
10719
|
+
return this.action.storage.value;
|
|
10584
10720
|
}
|
|
10585
10721
|
}
|
|
10586
10722
|
|
|
@@ -10605,6 +10741,7 @@ class StatisticsData {
|
|
|
10605
10741
|
|
|
10606
10742
|
|
|
10607
10743
|
|
|
10744
|
+
|
|
10608
10745
|
|
|
10609
10746
|
|
|
10610
10747
|
var in_memory_state_UpdateError;
|
|
@@ -10705,10 +10842,11 @@ class InMemoryService extends WithDebug {
|
|
|
10705
10842
|
/**
|
|
10706
10843
|
* A special version of state, stored fully in-memory.
|
|
10707
10844
|
*/
|
|
10708
|
-
class
|
|
10845
|
+
class in_memory_state_InMemoryState extends WithDebug {
|
|
10846
|
+
chainSpec;
|
|
10709
10847
|
/** Create a new `InMemoryState` by providing all required fields. */
|
|
10710
|
-
static
|
|
10711
|
-
return new
|
|
10848
|
+
static new(chainSpec, state) {
|
|
10849
|
+
return new in_memory_state_InMemoryState(chainSpec, state);
|
|
10712
10850
|
}
|
|
10713
10851
|
/**
|
|
10714
10852
|
* Create a new `InMemoryState` with a partial state override.
|
|
@@ -10717,14 +10855,14 @@ class InMemoryState extends WithDebug {
|
|
|
10717
10855
|
* not-necessarily coherent values.
|
|
10718
10856
|
*/
|
|
10719
10857
|
static partial(spec, partial) {
|
|
10720
|
-
const state =
|
|
10858
|
+
const state = in_memory_state_InMemoryState.empty(spec);
|
|
10721
10859
|
Object.assign(state, partial);
|
|
10722
10860
|
return state;
|
|
10723
10861
|
}
|
|
10724
10862
|
/**
|
|
10725
10863
|
* Create a new `InMemoryState` from some other state object.
|
|
10726
10864
|
*/
|
|
10727
|
-
static copyFrom(other, servicesData) {
|
|
10865
|
+
static copyFrom(chainSpec, other, servicesData) {
|
|
10728
10866
|
const services = new Map();
|
|
10729
10867
|
for (const [id, entries] of servicesData.entries()) {
|
|
10730
10868
|
const service = other.getService(id);
|
|
@@ -10734,7 +10872,7 @@ class InMemoryState extends WithDebug {
|
|
|
10734
10872
|
const inMemService = InMemoryService.copyFrom(service, entries);
|
|
10735
10873
|
services.set(id, inMemService);
|
|
10736
10874
|
}
|
|
10737
|
-
return
|
|
10875
|
+
return in_memory_state_InMemoryState.new(chainSpec, {
|
|
10738
10876
|
availabilityAssignment: other.availabilityAssignment,
|
|
10739
10877
|
accumulationQueue: other.accumulationQueue,
|
|
10740
10878
|
designatedValidatorData: other.designatedValidatorData,
|
|
@@ -10931,8 +11069,9 @@ class InMemoryState extends WithDebug {
|
|
|
10931
11069
|
getService(id) {
|
|
10932
11070
|
return this.services.get(id) ?? null;
|
|
10933
11071
|
}
|
|
10934
|
-
constructor(s) {
|
|
11072
|
+
constructor(chainSpec, s) {
|
|
10935
11073
|
super();
|
|
11074
|
+
this.chainSpec = chainSpec;
|
|
10936
11075
|
this.availabilityAssignment = s.availabilityAssignment;
|
|
10937
11076
|
this.designatedValidatorData = s.designatedValidatorData;
|
|
10938
11077
|
this.nextValidatorData = s.nextValidatorData;
|
|
@@ -10954,31 +11093,34 @@ class InMemoryState extends WithDebug {
|
|
|
10954
11093
|
this.accumulationOutputLog = s.accumulationOutputLog;
|
|
10955
11094
|
this.services = s.services;
|
|
10956
11095
|
}
|
|
11096
|
+
view() {
|
|
11097
|
+
return new InMemoryStateView(this.chainSpec, this);
|
|
11098
|
+
}
|
|
10957
11099
|
/**
|
|
10958
11100
|
* Create an empty and possibly incoherent `InMemoryState`.
|
|
10959
11101
|
*/
|
|
10960
11102
|
static empty(spec) {
|
|
10961
|
-
return new
|
|
11103
|
+
return new in_memory_state_InMemoryState(spec, {
|
|
10962
11104
|
availabilityAssignment: tryAsPerCore(Array.from({ length: spec.coresCount }, () => null), spec),
|
|
10963
|
-
designatedValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () =>
|
|
11105
|
+
designatedValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
|
|
10964
11106
|
bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
10965
11107
|
bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
|
|
10966
11108
|
ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
|
|
10967
11109
|
metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
|
|
10968
11110
|
})), spec),
|
|
10969
|
-
nextValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () =>
|
|
11111
|
+
nextValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
|
|
10970
11112
|
bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
10971
11113
|
bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
|
|
10972
11114
|
ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
|
|
10973
11115
|
metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
|
|
10974
11116
|
})), spec),
|
|
10975
|
-
currentValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () =>
|
|
11117
|
+
currentValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
|
|
10976
11118
|
bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
10977
11119
|
bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
|
|
10978
11120
|
ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
|
|
10979
11121
|
metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
|
|
10980
11122
|
})), spec),
|
|
10981
|
-
previousValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () =>
|
|
11123
|
+
previousValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
|
|
10982
11124
|
bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
10983
11125
|
bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
|
|
10984
11126
|
ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
|
|
@@ -10994,7 +11136,7 @@ class InMemoryState extends WithDebug {
|
|
|
10994
11136
|
entropy: FixedSizeArray.fill(() => bytes_Bytes.zero(hash_HASH_SIZE).asOpaque(), ENTROPY_ENTRIES),
|
|
10995
11137
|
authPools: tryAsPerCore(Array.from({ length: spec.coresCount }, () => sized_array_asKnownSize([])), spec),
|
|
10996
11138
|
authQueues: tryAsPerCore(Array.from({ length: spec.coresCount }, () => FixedSizeArray.fill(() => bytes_Bytes.zero(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE)), spec),
|
|
10997
|
-
recentBlocks:
|
|
11139
|
+
recentBlocks: RecentBlocks.empty(),
|
|
10998
11140
|
statistics: StatisticsData.create({
|
|
10999
11141
|
current: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
|
|
11000
11142
|
previous: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
|
|
@@ -11004,8 +11146,8 @@ class InMemoryState extends WithDebug {
|
|
|
11004
11146
|
accumulationQueue: tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => []), spec),
|
|
11005
11147
|
recentlyAccumulated: tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => HashSet.new()), spec),
|
|
11006
11148
|
ticketsAccumulator: sized_array_asKnownSize([]),
|
|
11007
|
-
sealingKeySeries:
|
|
11008
|
-
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(),
|
|
11009
11151
|
privilegedServices: PrivilegedServices.create({
|
|
11010
11152
|
manager: tryAsServiceId(0),
|
|
11011
11153
|
assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
|
|
@@ -11045,51 +11187,10 @@ const serviceDataCodec = descriptors_codec.dictionary(descriptors_codec.u32.asOp
|
|
|
11045
11187
|
|
|
11046
11188
|
|
|
11047
11189
|
|
|
11048
|
-
;// CONCATENATED MODULE: ./packages/jam/state/not-yet-accumulated.ts
|
|
11049
|
-
|
|
11050
11190
|
|
|
11051
11191
|
|
|
11052
11192
|
|
|
11053
11193
|
|
|
11054
|
-
|
|
11055
|
-
/**
|
|
11056
|
-
* Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
|
|
11057
|
-
*
|
|
11058
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
|
|
11059
|
-
*/
|
|
11060
|
-
class NotYetAccumulatedReport extends WithDebug {
|
|
11061
|
-
report;
|
|
11062
|
-
dependencies;
|
|
11063
|
-
static Codec = descriptors_codec.Class(NotYetAccumulatedReport, {
|
|
11064
|
-
report: WorkReport.Codec,
|
|
11065
|
-
dependencies: codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
|
|
11066
|
-
typicalLength: MAX_REPORT_DEPENDENCIES / 2,
|
|
11067
|
-
maxLength: MAX_REPORT_DEPENDENCIES,
|
|
11068
|
-
minLength: 0,
|
|
11069
|
-
}),
|
|
11070
|
-
});
|
|
11071
|
-
static create({ report, dependencies }) {
|
|
11072
|
-
return new NotYetAccumulatedReport(report, dependencies);
|
|
11073
|
-
}
|
|
11074
|
-
constructor(
|
|
11075
|
-
/**
|
|
11076
|
-
* Each of these were made available at most one epoch ago
|
|
11077
|
-
* but have or had unfulfilled dependencies.
|
|
11078
|
-
*/
|
|
11079
|
-
report,
|
|
11080
|
-
/**
|
|
11081
|
-
* Alongside the work-report itself, we retain its un-accumulated
|
|
11082
|
-
* dependencies, a set of work-package hashes.
|
|
11083
|
-
*
|
|
11084
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
|
|
11085
|
-
*/
|
|
11086
|
-
dependencies) {
|
|
11087
|
-
super();
|
|
11088
|
-
this.report = report;
|
|
11089
|
-
this.dependencies = dependencies;
|
|
11090
|
-
}
|
|
11091
|
-
}
|
|
11092
|
-
|
|
11093
11194
|
;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialize.ts
|
|
11094
11195
|
|
|
11095
11196
|
|
|
@@ -11102,26 +11203,19 @@ class NotYetAccumulatedReport extends WithDebug {
|
|
|
11102
11203
|
|
|
11103
11204
|
|
|
11104
11205
|
|
|
11105
|
-
|
|
11106
|
-
|
|
11107
|
-
|
|
11108
11206
|
/** Serialization for particular state entries. */
|
|
11109
|
-
var
|
|
11207
|
+
var serialize_serialize;
|
|
11110
11208
|
(function (serialize) {
|
|
11111
11209
|
/** C(1): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b15013b1501?v=0.6.7 */
|
|
11112
11210
|
serialize.authPools = {
|
|
11113
11211
|
key: stateKeys.index(StateKeyIdx.Alpha),
|
|
11114
|
-
Codec:
|
|
11115
|
-
minLength: 0,
|
|
11116
|
-
maxLength: MAX_AUTH_POOL_SIZE,
|
|
11117
|
-
typicalLength: MAX_AUTH_POOL_SIZE,
|
|
11118
|
-
})),
|
|
11212
|
+
Codec: authPoolsCodec,
|
|
11119
11213
|
extract: (s) => s.authPools,
|
|
11120
11214
|
};
|
|
11121
11215
|
/** C(2): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b31013b3101?v=0.6.7 */
|
|
11122
11216
|
serialize.authQueues = {
|
|
11123
11217
|
key: stateKeys.index(StateKeyIdx.Phi),
|
|
11124
|
-
Codec:
|
|
11218
|
+
Codec: authQueuesCodec,
|
|
11125
11219
|
extract: (s) => s.authQueues,
|
|
11126
11220
|
};
|
|
11127
11221
|
/**
|
|
@@ -11130,7 +11224,7 @@ var serialize;
|
|
|
11130
11224
|
*/
|
|
11131
11225
|
serialize.recentBlocks = {
|
|
11132
11226
|
key: stateKeys.index(StateKeyIdx.Beta),
|
|
11133
|
-
Codec:
|
|
11227
|
+
Codec: RecentBlocks.Codec,
|
|
11134
11228
|
extract: (s) => s.recentBlocks,
|
|
11135
11229
|
};
|
|
11136
11230
|
/** C(4): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b63013b6301?v=0.6.7 */
|
|
@@ -11159,25 +11253,25 @@ var serialize;
|
|
|
11159
11253
|
/** C(7): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b00023b0002?v=0.6.7 */
|
|
11160
11254
|
serialize.designatedValidators = {
|
|
11161
11255
|
key: stateKeys.index(StateKeyIdx.Iota),
|
|
11162
|
-
Codec:
|
|
11256
|
+
Codec: validatorsDataCodec,
|
|
11163
11257
|
extract: (s) => s.designatedValidatorData,
|
|
11164
11258
|
};
|
|
11165
11259
|
/** C(8): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b0d023b0d02?v=0.6.7 */
|
|
11166
11260
|
serialize.currentValidators = {
|
|
11167
11261
|
key: stateKeys.index(StateKeyIdx.Kappa),
|
|
11168
|
-
Codec:
|
|
11262
|
+
Codec: validatorsDataCodec,
|
|
11169
11263
|
extract: (s) => s.currentValidatorData,
|
|
11170
11264
|
};
|
|
11171
11265
|
/** C(9): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b1a023b1a02?v=0.6.7 */
|
|
11172
11266
|
serialize.previousValidators = {
|
|
11173
11267
|
key: stateKeys.index(StateKeyIdx.Lambda),
|
|
11174
|
-
Codec:
|
|
11268
|
+
Codec: validatorsDataCodec,
|
|
11175
11269
|
extract: (s) => s.previousValidatorData,
|
|
11176
11270
|
};
|
|
11177
11271
|
/** C(10): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b27023b2702?v=0.6.7 */
|
|
11178
11272
|
serialize.availabilityAssignment = {
|
|
11179
11273
|
key: stateKeys.index(StateKeyIdx.Rho),
|
|
11180
|
-
Codec:
|
|
11274
|
+
Codec: availabilityAssignmentsCodec,
|
|
11181
11275
|
extract: (s) => s.availabilityAssignment,
|
|
11182
11276
|
};
|
|
11183
11277
|
/** C(11): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b3e023b3e02?v=0.6.7 */
|
|
@@ -11201,13 +11295,13 @@ var serialize;
|
|
|
11201
11295
|
/** C(14): https://graypaper.fluffylabs.dev/#/1c979cb/3bf0023bf002?v=0.7.1 */
|
|
11202
11296
|
serialize.accumulationQueue = {
|
|
11203
11297
|
key: stateKeys.index(StateKeyIdx.Omega),
|
|
11204
|
-
Codec:
|
|
11298
|
+
Codec: accumulationQueueCodec,
|
|
11205
11299
|
extract: (s) => s.accumulationQueue,
|
|
11206
11300
|
};
|
|
11207
11301
|
/** C(15): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b96023b9602?v=0.6.7 */
|
|
11208
11302
|
serialize.recentlyAccumulated = {
|
|
11209
11303
|
key: stateKeys.index(StateKeyIdx.Xi),
|
|
11210
|
-
Codec:
|
|
11304
|
+
Codec: recentlyAccumulatedCodec,
|
|
11211
11305
|
extract: (s) => s.recentlyAccumulated,
|
|
11212
11306
|
};
|
|
11213
11307
|
/** C(16): https://graypaper.fluffylabs.dev/#/38c4e62/3b46033b4603?v=0.7.0 */
|
|
@@ -11236,9 +11330,9 @@ var serialize;
|
|
|
11236
11330
|
/** https://graypaper.fluffylabs.dev/#/85129da/387603387603?v=0.6.3 */
|
|
11237
11331
|
serialize.serviceLookupHistory = (blake2b, serviceId, hash, len) => ({
|
|
11238
11332
|
key: stateKeys.serviceLookupHistory(blake2b, serviceId, hash, len),
|
|
11239
|
-
Codec:
|
|
11333
|
+
Codec: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32)),
|
|
11240
11334
|
});
|
|
11241
|
-
})(
|
|
11335
|
+
})(serialize_serialize || (serialize_serialize = {}));
|
|
11242
11336
|
/**
|
|
11243
11337
|
* Just dump the entire terminal blob as-is.
|
|
11244
11338
|
*
|
|
@@ -11248,6 +11342,87 @@ var serialize;
|
|
|
11248
11342
|
*/
|
|
11249
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()));
|
|
11250
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
|
+
|
|
11251
11426
|
;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
|
|
11252
11427
|
|
|
11253
11428
|
|
|
@@ -11256,6 +11431,8 @@ const dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }, (e, v) =
|
|
|
11256
11431
|
|
|
11257
11432
|
|
|
11258
11433
|
|
|
11434
|
+
|
|
11435
|
+
|
|
11259
11436
|
/**
|
|
11260
11437
|
* State object which reads it's entries from some backend.
|
|
11261
11438
|
*
|
|
@@ -11268,7 +11445,7 @@ class serialized_state_SerializedState {
|
|
|
11268
11445
|
spec;
|
|
11269
11446
|
blake2b;
|
|
11270
11447
|
backend;
|
|
11271
|
-
|
|
11448
|
+
recentlyUsedServices;
|
|
11272
11449
|
/** Create a state-like object from collection of serialized entries. */
|
|
11273
11450
|
static fromStateEntries(spec, blake2b, state, recentServices = []) {
|
|
11274
11451
|
return new serialized_state_SerializedState(spec, blake2b, state, recentServices);
|
|
@@ -11277,106 +11454,120 @@ class serialized_state_SerializedState {
|
|
|
11277
11454
|
static new(spec, blake2b, db, recentServices = []) {
|
|
11278
11455
|
return new serialized_state_SerializedState(spec, blake2b, db, recentServices);
|
|
11279
11456
|
}
|
|
11457
|
+
dataCache = hash_dictionary_HashDictionary.new();
|
|
11458
|
+
viewCache = hash_dictionary_HashDictionary.new();
|
|
11280
11459
|
constructor(spec, blake2b, backend,
|
|
11281
11460
|
/** Best-effort list of recently active services. */
|
|
11282
|
-
|
|
11461
|
+
recentlyUsedServices) {
|
|
11283
11462
|
this.spec = spec;
|
|
11284
11463
|
this.blake2b = blake2b;
|
|
11285
11464
|
this.backend = backend;
|
|
11286
|
-
this.
|
|
11465
|
+
this.recentlyUsedServices = recentlyUsedServices;
|
|
11287
11466
|
}
|
|
11288
11467
|
/** Comparing the serialized states, just means comparing their backends. */
|
|
11289
11468
|
[TEST_COMPARE_USING]() {
|
|
11290
11469
|
return this.backend;
|
|
11291
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
|
+
}
|
|
11292
11475
|
// TODO [ToDr] Temporary method to update the state,
|
|
11293
11476
|
// without changing references.
|
|
11294
11477
|
updateBackend(newBackend) {
|
|
11295
11478
|
this.backend = newBackend;
|
|
11479
|
+
this.dataCache = hash_dictionary_HashDictionary.new();
|
|
11480
|
+
this.viewCache = hash_dictionary_HashDictionary.new();
|
|
11296
11481
|
}
|
|
11297
11482
|
recentServiceIds() {
|
|
11298
|
-
return this.
|
|
11483
|
+
return this.recentlyUsedServices;
|
|
11299
11484
|
}
|
|
11300
11485
|
getService(id) {
|
|
11301
|
-
const serviceData = this.retrieveOptional(
|
|
11486
|
+
const serviceData = this.retrieveOptional(serialize_serialize.serviceData(id));
|
|
11302
11487
|
if (serviceData === undefined) {
|
|
11303
11488
|
return null;
|
|
11304
11489
|
}
|
|
11305
|
-
if (!this.
|
|
11306
|
-
this.
|
|
11490
|
+
if (!this.recentlyUsedServices.includes(id)) {
|
|
11491
|
+
this.recentlyUsedServices.push(id);
|
|
11307
11492
|
}
|
|
11308
11493
|
return new SerializedService(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
|
|
11309
11494
|
}
|
|
11310
|
-
retrieve(
|
|
11311
|
-
const
|
|
11312
|
-
if (
|
|
11313
|
-
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}`);
|
|
11314
11499
|
}
|
|
11315
|
-
return
|
|
11500
|
+
return data;
|
|
11316
11501
|
}
|
|
11317
11502
|
retrieveOptional({ key, Codec }) {
|
|
11503
|
+
const cached = this.dataCache.get(key);
|
|
11504
|
+
if (cached !== undefined) {
|
|
11505
|
+
return cached;
|
|
11506
|
+
}
|
|
11318
11507
|
const bytes = this.backend.get(key);
|
|
11319
11508
|
if (bytes === null) {
|
|
11320
11509
|
return undefined;
|
|
11321
11510
|
}
|
|
11322
|
-
|
|
11511
|
+
const data = decoder_Decoder.decodeObject(Codec, bytes, this.spec);
|
|
11512
|
+
this.dataCache.set(key, data);
|
|
11513
|
+
return data;
|
|
11323
11514
|
}
|
|
11324
11515
|
get availabilityAssignment() {
|
|
11325
|
-
return this.retrieve(
|
|
11516
|
+
return this.retrieve(serialize_serialize.availabilityAssignment, "availabilityAssignment");
|
|
11326
11517
|
}
|
|
11327
11518
|
get designatedValidatorData() {
|
|
11328
|
-
return this.retrieve(
|
|
11519
|
+
return this.retrieve(serialize_serialize.designatedValidators, "designatedValidatorData");
|
|
11329
11520
|
}
|
|
11330
11521
|
get nextValidatorData() {
|
|
11331
|
-
return this.retrieve(
|
|
11522
|
+
return this.retrieve(serialize_serialize.safrole, "safroleData.nextValidatorData").nextValidatorData;
|
|
11332
11523
|
}
|
|
11333
11524
|
get currentValidatorData() {
|
|
11334
|
-
return this.retrieve(
|
|
11525
|
+
return this.retrieve(serialize_serialize.currentValidators, "currentValidators");
|
|
11335
11526
|
}
|
|
11336
11527
|
get previousValidatorData() {
|
|
11337
|
-
return this.retrieve(
|
|
11528
|
+
return this.retrieve(serialize_serialize.previousValidators, "previousValidators");
|
|
11338
11529
|
}
|
|
11339
11530
|
get disputesRecords() {
|
|
11340
|
-
return this.retrieve(
|
|
11531
|
+
return this.retrieve(serialize_serialize.disputesRecords, "disputesRecords");
|
|
11341
11532
|
}
|
|
11342
11533
|
get timeslot() {
|
|
11343
|
-
return this.retrieve(
|
|
11534
|
+
return this.retrieve(serialize_serialize.timeslot, "timeslot");
|
|
11344
11535
|
}
|
|
11345
11536
|
get entropy() {
|
|
11346
|
-
return this.retrieve(
|
|
11537
|
+
return this.retrieve(serialize_serialize.entropy, "entropy");
|
|
11347
11538
|
}
|
|
11348
11539
|
get authPools() {
|
|
11349
|
-
return this.retrieve(
|
|
11540
|
+
return this.retrieve(serialize_serialize.authPools, "authPools");
|
|
11350
11541
|
}
|
|
11351
11542
|
get authQueues() {
|
|
11352
|
-
return this.retrieve(
|
|
11543
|
+
return this.retrieve(serialize_serialize.authQueues, "authQueues");
|
|
11353
11544
|
}
|
|
11354
11545
|
get recentBlocks() {
|
|
11355
|
-
return this.retrieve(
|
|
11546
|
+
return this.retrieve(serialize_serialize.recentBlocks, "recentBlocks");
|
|
11356
11547
|
}
|
|
11357
11548
|
get statistics() {
|
|
11358
|
-
return this.retrieve(
|
|
11549
|
+
return this.retrieve(serialize_serialize.statistics, "statistics");
|
|
11359
11550
|
}
|
|
11360
11551
|
get accumulationQueue() {
|
|
11361
|
-
return this.retrieve(
|
|
11552
|
+
return this.retrieve(serialize_serialize.accumulationQueue, "accumulationQueue");
|
|
11362
11553
|
}
|
|
11363
11554
|
get recentlyAccumulated() {
|
|
11364
|
-
return this.retrieve(
|
|
11555
|
+
return this.retrieve(serialize_serialize.recentlyAccumulated, "recentlyAccumulated");
|
|
11365
11556
|
}
|
|
11366
11557
|
get ticketsAccumulator() {
|
|
11367
|
-
return this.retrieve(
|
|
11558
|
+
return this.retrieve(serialize_serialize.safrole, "safroleData.ticketsAccumulator").ticketsAccumulator;
|
|
11368
11559
|
}
|
|
11369
11560
|
get sealingKeySeries() {
|
|
11370
|
-
return this.retrieve(
|
|
11561
|
+
return this.retrieve(serialize_serialize.safrole, "safrole.sealingKeySeries").sealingKeySeries;
|
|
11371
11562
|
}
|
|
11372
11563
|
get epochRoot() {
|
|
11373
|
-
return this.retrieve(
|
|
11564
|
+
return this.retrieve(serialize_serialize.safrole, "safrole.epochRoot").epochRoot;
|
|
11374
11565
|
}
|
|
11375
11566
|
get privilegedServices() {
|
|
11376
|
-
return this.retrieve(
|
|
11567
|
+
return this.retrieve(serialize_serialize.privilegedServices, "privilegedServices");
|
|
11377
11568
|
}
|
|
11378
11569
|
get accumulationOutputLog() {
|
|
11379
|
-
return this.retrieve(
|
|
11570
|
+
return this.retrieve(serialize_serialize.accumulationOutputLog, "accumulationOutputLog");
|
|
11380
11571
|
}
|
|
11381
11572
|
}
|
|
11382
11573
|
/** Service data representation on a serialized state. */
|
|
@@ -11405,9 +11596,9 @@ class SerializedService {
|
|
|
11405
11596
|
serviceIdAndKey.set(numbers_u32AsLeBytes(this.serviceId));
|
|
11406
11597
|
serviceIdAndKey.set(rawKey.raw, SERVICE_ID_BYTES);
|
|
11407
11598
|
const key = opaque_asOpaqueType(bytes_BytesBlob.blobFrom(this.blake2b.hashBytes(serviceIdAndKey).raw));
|
|
11408
|
-
return this.retrieveOptional(
|
|
11599
|
+
return this.retrieveOptional(serialize_serialize.serviceStorage(this.blake2b, this.serviceId, key)) ?? null;
|
|
11409
11600
|
}
|
|
11410
|
-
return this.retrieveOptional(
|
|
11601
|
+
return this.retrieveOptional(serialize_serialize.serviceStorage(this.blake2b, this.serviceId, rawKey)) ?? null;
|
|
11411
11602
|
}
|
|
11412
11603
|
/**
|
|
11413
11604
|
* Check if preimage is present in the DB.
|
|
@@ -11416,15 +11607,15 @@ class SerializedService {
|
|
|
11416
11607
|
*/
|
|
11417
11608
|
hasPreimage(hash) {
|
|
11418
11609
|
// TODO [ToDr] consider optimizing to avoid fetching the whole data.
|
|
11419
|
-
return this.retrieveOptional(
|
|
11610
|
+
return this.retrieveOptional(serialize_serialize.servicePreimages(this.blake2b, this.serviceId, hash)) !== undefined;
|
|
11420
11611
|
}
|
|
11421
11612
|
/** Retrieve preimage from the DB. */
|
|
11422
11613
|
getPreimage(hash) {
|
|
11423
|
-
return this.retrieveOptional(
|
|
11614
|
+
return this.retrieveOptional(serialize_serialize.servicePreimages(this.blake2b, this.serviceId, hash)) ?? null;
|
|
11424
11615
|
}
|
|
11425
11616
|
/** Retrieve preimage lookup history. */
|
|
11426
11617
|
getLookupHistory(hash, len) {
|
|
11427
|
-
const rawSlots = this.retrieveOptional(
|
|
11618
|
+
const rawSlots = this.retrieveOptional(serialize_serialize.serviceLookupHistory(this.blake2b, this.serviceId, hash, len));
|
|
11428
11619
|
if (rawSlots === undefined) {
|
|
11429
11620
|
return null;
|
|
11430
11621
|
}
|
|
@@ -12113,7 +12304,7 @@ function* serializeStateUpdate(spec, blake2b, update) {
|
|
|
12113
12304
|
function* serializeRemovedServices(servicesRemoved) {
|
|
12114
12305
|
for (const serviceId of servicesRemoved ?? []) {
|
|
12115
12306
|
// TODO [ToDr] what about all data associated with a service?
|
|
12116
|
-
const codec =
|
|
12307
|
+
const codec = serialize_serialize.serviceData(serviceId);
|
|
12117
12308
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
12118
12309
|
}
|
|
12119
12310
|
}
|
|
@@ -12122,13 +12313,13 @@ function* serializeStorage(storage, blake2b) {
|
|
|
12122
12313
|
switch (action.kind) {
|
|
12123
12314
|
case UpdateStorageKind.Set: {
|
|
12124
12315
|
const key = action.storage.key;
|
|
12125
|
-
const codec =
|
|
12316
|
+
const codec = serialize_serialize.serviceStorage(blake2b, serviceId, key);
|
|
12126
12317
|
yield [StateEntryUpdateAction.Insert, codec.key, action.storage.value];
|
|
12127
12318
|
break;
|
|
12128
12319
|
}
|
|
12129
12320
|
case UpdateStorageKind.Remove: {
|
|
12130
12321
|
const key = action.key;
|
|
12131
|
-
const codec =
|
|
12322
|
+
const codec = serialize_serialize.serviceStorage(blake2b, serviceId, key);
|
|
12132
12323
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
12133
12324
|
break;
|
|
12134
12325
|
}
|
|
@@ -12142,10 +12333,10 @@ function* serializePreimages(preimages, encode, blake2b) {
|
|
|
12142
12333
|
switch (action.kind) {
|
|
12143
12334
|
case UpdatePreimageKind.Provide: {
|
|
12144
12335
|
const { hash, blob } = action.preimage;
|
|
12145
|
-
const codec =
|
|
12336
|
+
const codec = serialize_serialize.servicePreimages(blake2b, serviceId, hash);
|
|
12146
12337
|
yield [StateEntryUpdateAction.Insert, codec.key, blob];
|
|
12147
12338
|
if (action.slot !== null) {
|
|
12148
|
-
const codec2 =
|
|
12339
|
+
const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, numbers_tryAsU32(blob.length));
|
|
12149
12340
|
yield [
|
|
12150
12341
|
StateEntryUpdateAction.Insert,
|
|
12151
12342
|
codec2.key,
|
|
@@ -12156,15 +12347,15 @@ function* serializePreimages(preimages, encode, blake2b) {
|
|
|
12156
12347
|
}
|
|
12157
12348
|
case UpdatePreimageKind.UpdateOrAdd: {
|
|
12158
12349
|
const { hash, length, slots } = action.item;
|
|
12159
|
-
const codec =
|
|
12350
|
+
const codec = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
12160
12351
|
yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, slots)];
|
|
12161
12352
|
break;
|
|
12162
12353
|
}
|
|
12163
12354
|
case UpdatePreimageKind.Remove: {
|
|
12164
12355
|
const { hash, length } = action;
|
|
12165
|
-
const codec =
|
|
12356
|
+
const codec = serialize_serialize.servicePreimages(blake2b, serviceId, hash);
|
|
12166
12357
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
12167
|
-
const codec2 =
|
|
12358
|
+
const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
12168
12359
|
yield [StateEntryUpdateAction.Remove, codec2.key, EMPTY_BLOB];
|
|
12169
12360
|
break;
|
|
12170
12361
|
}
|
|
@@ -12176,12 +12367,12 @@ function* serializePreimages(preimages, encode, blake2b) {
|
|
|
12176
12367
|
function* serializeServiceUpdates(servicesUpdates, encode, blake2b) {
|
|
12177
12368
|
for (const { action, serviceId } of servicesUpdates ?? []) {
|
|
12178
12369
|
// new service being created or updated
|
|
12179
|
-
const codec =
|
|
12370
|
+
const codec = serialize_serialize.serviceData(serviceId);
|
|
12180
12371
|
yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, action.account)];
|
|
12181
12372
|
// additional lookup history update
|
|
12182
12373
|
if (action.kind === UpdateServiceKind.Create && action.lookupHistory !== null) {
|
|
12183
12374
|
const { lookupHistory } = action;
|
|
12184
|
-
const codec2 =
|
|
12375
|
+
const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
12185
12376
|
yield [StateEntryUpdateAction.Insert, codec2.key, encode(codec2.Codec, lookupHistory.slots)];
|
|
12186
12377
|
}
|
|
12187
12378
|
}
|
|
@@ -12191,53 +12382,53 @@ function* serializeBasicKeys(spec, update) {
|
|
|
12191
12382
|
return [StateEntryUpdateAction.Insert, codec.key, encoder_Encoder.encodeObject(codec.Codec, val, spec)];
|
|
12192
12383
|
}
|
|
12193
12384
|
if (update.authPools !== undefined) {
|
|
12194
|
-
yield doSerialize(update.authPools,
|
|
12385
|
+
yield doSerialize(update.authPools, serialize_serialize.authPools); // C(1)
|
|
12195
12386
|
}
|
|
12196
12387
|
if (update.authQueues !== undefined) {
|
|
12197
|
-
yield doSerialize(update.authQueues,
|
|
12388
|
+
yield doSerialize(update.authQueues, serialize_serialize.authQueues); // C(2)
|
|
12198
12389
|
}
|
|
12199
12390
|
if (update.recentBlocks !== undefined) {
|
|
12200
|
-
yield doSerialize(update.recentBlocks,
|
|
12391
|
+
yield doSerialize(update.recentBlocks, serialize_serialize.recentBlocks); // C(3)
|
|
12201
12392
|
}
|
|
12202
12393
|
const safroleData = getSafroleData(update.nextValidatorData, update.epochRoot, update.sealingKeySeries, update.ticketsAccumulator);
|
|
12203
12394
|
if (safroleData !== undefined) {
|
|
12204
|
-
yield doSerialize(safroleData,
|
|
12395
|
+
yield doSerialize(safroleData, serialize_serialize.safrole); // C(4)
|
|
12205
12396
|
}
|
|
12206
12397
|
if (update.disputesRecords !== undefined) {
|
|
12207
|
-
yield doSerialize(update.disputesRecords,
|
|
12398
|
+
yield doSerialize(update.disputesRecords, serialize_serialize.disputesRecords); // C(5)
|
|
12208
12399
|
}
|
|
12209
12400
|
if (update.entropy !== undefined) {
|
|
12210
|
-
yield doSerialize(update.entropy,
|
|
12401
|
+
yield doSerialize(update.entropy, serialize_serialize.entropy); // C(6)
|
|
12211
12402
|
}
|
|
12212
12403
|
if (update.designatedValidatorData !== undefined) {
|
|
12213
|
-
yield doSerialize(update.designatedValidatorData,
|
|
12404
|
+
yield doSerialize(update.designatedValidatorData, serialize_serialize.designatedValidators); // C(7)
|
|
12214
12405
|
}
|
|
12215
12406
|
if (update.currentValidatorData !== undefined) {
|
|
12216
|
-
yield doSerialize(update.currentValidatorData,
|
|
12407
|
+
yield doSerialize(update.currentValidatorData, serialize_serialize.currentValidators); // C(8)
|
|
12217
12408
|
}
|
|
12218
12409
|
if (update.previousValidatorData !== undefined) {
|
|
12219
|
-
yield doSerialize(update.previousValidatorData,
|
|
12410
|
+
yield doSerialize(update.previousValidatorData, serialize_serialize.previousValidators); // C(9)
|
|
12220
12411
|
}
|
|
12221
12412
|
if (update.availabilityAssignment !== undefined) {
|
|
12222
|
-
yield doSerialize(update.availabilityAssignment,
|
|
12413
|
+
yield doSerialize(update.availabilityAssignment, serialize_serialize.availabilityAssignment); // C(10)
|
|
12223
12414
|
}
|
|
12224
12415
|
if (update.timeslot !== undefined) {
|
|
12225
|
-
yield doSerialize(update.timeslot,
|
|
12416
|
+
yield doSerialize(update.timeslot, serialize_serialize.timeslot); // C(11)
|
|
12226
12417
|
}
|
|
12227
12418
|
if (update.privilegedServices !== undefined) {
|
|
12228
|
-
yield doSerialize(update.privilegedServices,
|
|
12419
|
+
yield doSerialize(update.privilegedServices, serialize_serialize.privilegedServices); // C(12)
|
|
12229
12420
|
}
|
|
12230
12421
|
if (update.statistics !== undefined) {
|
|
12231
|
-
yield doSerialize(update.statistics,
|
|
12422
|
+
yield doSerialize(update.statistics, serialize_serialize.statistics); // C(13)
|
|
12232
12423
|
}
|
|
12233
12424
|
if (update.accumulationQueue !== undefined) {
|
|
12234
|
-
yield doSerialize(update.accumulationQueue,
|
|
12425
|
+
yield doSerialize(update.accumulationQueue, serialize_serialize.accumulationQueue); // C(14)
|
|
12235
12426
|
}
|
|
12236
12427
|
if (update.recentlyAccumulated !== undefined) {
|
|
12237
|
-
yield doSerialize(update.recentlyAccumulated,
|
|
12428
|
+
yield doSerialize(update.recentlyAccumulated, serialize_serialize.recentlyAccumulated); // C(15)
|
|
12238
12429
|
}
|
|
12239
12430
|
if (update.accumulationOutputLog !== undefined) {
|
|
12240
|
-
yield doSerialize(update.accumulationOutputLog,
|
|
12431
|
+
yield doSerialize(update.accumulationOutputLog, serialize_serialize.accumulationOutputLog); // C(16)
|
|
12241
12432
|
}
|
|
12242
12433
|
}
|
|
12243
12434
|
function getSafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator) {
|
|
@@ -12350,41 +12541,41 @@ function convertInMemoryStateToDictionary(spec, blake2b, state) {
|
|
|
12350
12541
|
function doSerialize(codec) {
|
|
12351
12542
|
serialized.set(codec.key, encoder_Encoder.encodeObject(codec.Codec, codec.extract(state), spec));
|
|
12352
12543
|
}
|
|
12353
|
-
doSerialize(
|
|
12354
|
-
doSerialize(
|
|
12355
|
-
doSerialize(
|
|
12356
|
-
doSerialize(
|
|
12357
|
-
doSerialize(
|
|
12358
|
-
doSerialize(
|
|
12359
|
-
doSerialize(
|
|
12360
|
-
doSerialize(
|
|
12361
|
-
doSerialize(
|
|
12362
|
-
doSerialize(
|
|
12363
|
-
doSerialize(
|
|
12364
|
-
doSerialize(
|
|
12365
|
-
doSerialize(
|
|
12366
|
-
doSerialize(
|
|
12367
|
-
doSerialize(
|
|
12368
|
-
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)
|
|
12369
12560
|
// services
|
|
12370
12561
|
for (const [serviceId, service] of state.services.entries()) {
|
|
12371
12562
|
// data
|
|
12372
|
-
const { key, Codec } =
|
|
12563
|
+
const { key, Codec } = serialize_serialize.serviceData(serviceId);
|
|
12373
12564
|
serialized.set(key, encoder_Encoder.encodeObject(Codec, service.getInfo()));
|
|
12374
12565
|
// preimages
|
|
12375
12566
|
for (const preimage of service.data.preimages.values()) {
|
|
12376
|
-
const { key, Codec } =
|
|
12567
|
+
const { key, Codec } = serialize_serialize.servicePreimages(blake2b, serviceId, preimage.hash);
|
|
12377
12568
|
serialized.set(key, encoder_Encoder.encodeObject(Codec, preimage.blob));
|
|
12378
12569
|
}
|
|
12379
12570
|
// storage
|
|
12380
12571
|
for (const storage of service.data.storage.values()) {
|
|
12381
|
-
const { key, Codec } =
|
|
12572
|
+
const { key, Codec } = serialize_serialize.serviceStorage(blake2b, serviceId, storage.key);
|
|
12382
12573
|
serialized.set(key, encoder_Encoder.encodeObject(Codec, storage.value));
|
|
12383
12574
|
}
|
|
12384
12575
|
// lookup history
|
|
12385
12576
|
for (const lookupHistoryList of service.data.lookupHistory.values()) {
|
|
12386
12577
|
for (const lookupHistory of lookupHistoryList) {
|
|
12387
|
-
const { key, Codec } =
|
|
12578
|
+
const { key, Codec } = serialize_serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
12388
12579
|
serialized.set(key, encoder_Encoder.encodeObject(Codec, lookupHistory.slots.slice()));
|
|
12389
12580
|
}
|
|
12390
12581
|
}
|
|
@@ -12434,6 +12625,7 @@ function loadState(spec, blake2b, entries) {
|
|
|
12434
12625
|
|
|
12435
12626
|
|
|
12436
12627
|
|
|
12628
|
+
|
|
12437
12629
|
;// CONCATENATED MODULE: ./packages/jam/database/leaf-db.ts
|
|
12438
12630
|
|
|
12439
12631
|
|
|
@@ -12592,7 +12784,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
|
|
|
12592
12784
|
const lookupHistoryItemCodec = descriptors_codec.object({
|
|
12593
12785
|
hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
12594
12786
|
length: descriptors_codec.u32,
|
|
12595
|
-
slots:
|
|
12787
|
+
slots: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32.asOpaque())).convert(seeThrough, tryAsLookupHistorySlots),
|
|
12596
12788
|
}, "LookupHistoryItem", ({ hash, length, slots }) => new LookupHistoryItem(hash, length, slots));
|
|
12597
12789
|
const lookupHistoryEntryCodec = descriptors_codec.object({
|
|
12598
12790
|
key: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
@@ -12635,7 +12827,11 @@ class ServiceWithCodec extends InMemoryService {
|
|
|
12635
12827
|
return new ServiceWithCodec(serviceId, data);
|
|
12636
12828
|
}
|
|
12637
12829
|
}
|
|
12638
|
-
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
|
+
}, {
|
|
12639
12835
|
// alpha
|
|
12640
12836
|
authPools: serialize.authPools.Codec,
|
|
12641
12837
|
// phi
|
|
@@ -12645,11 +12841,11 @@ const in_memory_state_codec_inMemoryStateCodec = descriptors_codec.Class(InMemor
|
|
|
12645
12841
|
// gamma_k
|
|
12646
12842
|
nextValidatorData: codecPerValidator(ValidatorData.Codec),
|
|
12647
12843
|
// gamma_z
|
|
12648
|
-
epochRoot:
|
|
12844
|
+
epochRoot: codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
12649
12845
|
// gamma_s
|
|
12650
12846
|
sealingKeySeries: SafroleSealingKeysData.Codec,
|
|
12651
12847
|
// gamma_a
|
|
12652
|
-
ticketsAccumulator: readonlyArray(
|
|
12848
|
+
ticketsAccumulator: readonlyArray(codec.sequenceVarLen(Ticket.Codec)).convert((x) => x, asKnownSize),
|
|
12653
12849
|
// psi
|
|
12654
12850
|
disputesRecords: serialize.disputesRecords.Codec,
|
|
12655
12851
|
// eta
|
|
@@ -12675,7 +12871,7 @@ const in_memory_state_codec_inMemoryStateCodec = descriptors_codec.Class(InMemor
|
|
|
12675
12871
|
// theta
|
|
12676
12872
|
accumulationOutputLog: serialize.accumulationOutputLog.Codec,
|
|
12677
12873
|
// delta
|
|
12678
|
-
services:
|
|
12874
|
+
services: codec.dictionary(codec.u32.asOpaque(), ServiceWithCodec.Codec, {
|
|
12679
12875
|
sortKeys: (a, b) => a - b,
|
|
12680
12876
|
}),
|
|
12681
12877
|
});
|
|
@@ -12722,7 +12918,7 @@ class InMemoryStates {
|
|
|
12722
12918
|
}
|
|
12723
12919
|
/** Insert a full state into the database. */
|
|
12724
12920
|
async insertState(headerHash, state) {
|
|
12725
|
-
const encoded = Encoder.encodeObject(inMemoryStateCodec, state, this.spec);
|
|
12921
|
+
const encoded = Encoder.encodeObject(inMemoryStateCodec(this.spec), state, this.spec);
|
|
12726
12922
|
this.db.set(headerHash, encoded);
|
|
12727
12923
|
return Result.ok(OK);
|
|
12728
12924
|
}
|
|
@@ -12731,7 +12927,7 @@ class InMemoryStates {
|
|
|
12731
12927
|
if (encodedState === undefined) {
|
|
12732
12928
|
return null;
|
|
12733
12929
|
}
|
|
12734
|
-
return Decoder.decodeObject(inMemoryStateCodec, encodedState, this.spec);
|
|
12930
|
+
return Decoder.decodeObject(inMemoryStateCodec(this.spec), encodedState, this.spec);
|
|
12735
12931
|
}
|
|
12736
12932
|
}
|
|
12737
12933
|
|
|
@@ -13839,21 +14035,21 @@ class TransitionHasher {
|
|
|
13839
14035
|
*/
|
|
13840
14036
|
extrinsic(extrinsicView) {
|
|
13841
14037
|
// https://graypaper.fluffylabs.dev/#/cc517d7/0cfb000cfb00?v=0.6.5
|
|
13842
|
-
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
|
|
13843
14041
|
.view()
|
|
13844
14042
|
.map((g) => g.view())
|
|
13845
|
-
.
|
|
14043
|
+
.reduce((aggregated, guarantee) => {
|
|
13846
14044
|
const reportHash = this.blake2b.hashBytes(guarantee.report.encoded()).asOpaque();
|
|
13847
|
-
|
|
13848
|
-
|
|
13849
|
-
|
|
13850
|
-
|
|
13851
|
-
|
|
13852
|
-
});
|
|
13853
|
-
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]);
|
|
13854
14050
|
const et = this.blake2b.hashBytes(extrinsicView.tickets.encoded()).asOpaque();
|
|
13855
14051
|
const ep = this.blake2b.hashBytes(extrinsicView.preimages.encoded()).asOpaque();
|
|
13856
|
-
const eg = this.blake2b.
|
|
14052
|
+
const eg = this.blake2b.hashBlobs(guaranteesBlobs).asOpaque();
|
|
13857
14053
|
const ea = this.blake2b.hashBytes(extrinsicView.assurances.encoded()).asOpaque();
|
|
13858
14054
|
const ed = this.blake2b.hashBytes(extrinsicView.disputes.encoded()).asOpaque();
|
|
13859
14055
|
const encoded = bytes_BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);
|
|
@@ -14512,7 +14708,7 @@ async function getRingCommitmentNoCache(bandersnatch, keys) {
|
|
|
14512
14708
|
if (commitmentResult[RESULT_INDEX] === ResultValues.Error) {
|
|
14513
14709
|
return result_Result.error(null);
|
|
14514
14710
|
}
|
|
14515
|
-
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());
|
|
14516
14712
|
}
|
|
14517
14713
|
// One byte for result discriminator (`ResultValues`) and the rest is entropy hash.
|
|
14518
14714
|
const TICKET_RESULT_LENGTH = 1 + hash_HASH_SIZE;
|
|
@@ -14666,7 +14862,7 @@ class Safrole {
|
|
|
14666
14862
|
* https://graypaper.fluffylabs.dev/#/5f542d7/0ea2000ea200
|
|
14667
14863
|
*/
|
|
14668
14864
|
if (isOffender) {
|
|
14669
|
-
return
|
|
14865
|
+
return validator_data_ValidatorData.create({
|
|
14670
14866
|
bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
14671
14867
|
ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
|
|
14672
14868
|
bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
|
|
@@ -14744,13 +14940,13 @@ class Safrole {
|
|
|
14744
14940
|
if (this.isNextEpoch(timeslot) &&
|
|
14745
14941
|
m >= this.chainSpec.contestLength &&
|
|
14746
14942
|
this.state.ticketsAccumulator.length === this.chainSpec.epochLength) {
|
|
14747
|
-
return
|
|
14943
|
+
return safrole_data_SafroleSealingKeysData.tickets(this.outsideInSequencer(this.state.ticketsAccumulator).tickets);
|
|
14748
14944
|
}
|
|
14749
14945
|
if (this.isSameEpoch(timeslot)) {
|
|
14750
14946
|
return this.state.sealingKeySeries;
|
|
14751
14947
|
}
|
|
14752
14948
|
// TODO [MaSi]: the result of fallback sequencer should be cached
|
|
14753
|
-
return
|
|
14949
|
+
return safrole_data_SafroleSealingKeysData.keys(this.fallbackKeySequencer(newEntropy, newValidators));
|
|
14754
14950
|
}
|
|
14755
14951
|
/**
|
|
14756
14952
|
* Returns epoch markers if the epoch is changed and null otherwise
|
|
@@ -15000,47 +15196,46 @@ class SafroleSeal {
|
|
|
15000
15196
|
}
|
|
15001
15197
|
async verifySeal(headerView, state) {
|
|
15002
15198
|
// we use transitioned keys already
|
|
15003
|
-
const validators = state.currentValidatorData;
|
|
15004
15199
|
const validatorIndex = headerView.bandersnatchBlockAuthorIndex.materialize();
|
|
15005
|
-
const
|
|
15006
|
-
if (
|
|
15200
|
+
const authorKeys = state.currentValidatorData.at(validatorIndex);
|
|
15201
|
+
if (authorKeys === undefined) {
|
|
15007
15202
|
return result_Result.error(SafroleSealError.InvalidValidatorIndex);
|
|
15008
15203
|
}
|
|
15009
15204
|
const timeSlot = headerView.timeSlotIndex.materialize();
|
|
15010
15205
|
const sealingKeys = state.sealingKeySeries;
|
|
15011
15206
|
const entropy = state.currentEntropy;
|
|
15012
15207
|
if (sealingKeys.kind === SafroleSealingKeysKind.Tickets) {
|
|
15013
|
-
return await this.verifySealWithTicket(sealingKeys.tickets, timeSlot, entropy,
|
|
15208
|
+
return await this.verifySealWithTicket(sealingKeys.tickets, timeSlot, entropy, authorKeys, headerView);
|
|
15014
15209
|
}
|
|
15015
|
-
return await this.verifySealWithKeys(sealingKeys.keys,
|
|
15210
|
+
return await this.verifySealWithKeys(sealingKeys.keys, timeSlot, entropy, authorKeys, headerView);
|
|
15016
15211
|
}
|
|
15017
15212
|
/** Regular (non-fallback) mode of Safrole. */
|
|
15018
|
-
async verifySealWithTicket(tickets, timeSlot, entropy,
|
|
15213
|
+
async verifySealWithTicket(tickets, timeSlot, entropy, validatorData, headerView) {
|
|
15019
15214
|
const index = timeSlot % tickets.length;
|
|
15020
|
-
const
|
|
15021
|
-
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]));
|
|
15022
15217
|
// verify seal correctness
|
|
15023
|
-
const authorKey =
|
|
15218
|
+
const authorKey = validatorData.bandersnatch;
|
|
15024
15219
|
const result = await bandersnatch_vrf.verifySeal(await this.bandersnatch, authorKey ?? BANDERSNATCH_ZERO_KEY, headerView.seal.materialize(), payload, encodeUnsealedHeader(headerView));
|
|
15025
15220
|
if (result.isError) {
|
|
15026
15221
|
return result_Result.error(SafroleSealError.IncorrectSeal);
|
|
15027
15222
|
}
|
|
15028
|
-
if (!id.isEqualTo(result.ok)) {
|
|
15223
|
+
if (ticket === undefined || !ticket.id.isEqualTo(result.ok)) {
|
|
15029
15224
|
return result_Result.error(SafroleSealError.InvalidTicket);
|
|
15030
15225
|
}
|
|
15031
15226
|
return result_Result.ok(result.ok);
|
|
15032
15227
|
}
|
|
15033
15228
|
/** Fallback mode of Safrole. */
|
|
15034
|
-
async verifySealWithKeys(keys,
|
|
15229
|
+
async verifySealWithKeys(keys, timeSlot, entropy, authorKey, headerView) {
|
|
15035
15230
|
const index = timeSlot % keys.length;
|
|
15036
|
-
const sealingKey = keys
|
|
15037
|
-
|
|
15231
|
+
const sealingKey = keys.at(index);
|
|
15232
|
+
const authorBandersnatchKey = authorKey.bandersnatch;
|
|
15233
|
+
if (sealingKey === undefined || !sealingKey.isEqualTo(authorBandersnatchKey)) {
|
|
15038
15234
|
return result_Result.error(SafroleSealError.InvalidValidator, `Invalid Validator. Expected: ${sealingKey}, got: ${authorKey.bandersnatch}`);
|
|
15039
15235
|
}
|
|
15040
15236
|
// verify seal correctness
|
|
15041
15237
|
const payload = bytes_BytesBlob.blobFromParts(JAM_FALLBACK_SEAL, entropy.raw);
|
|
15042
|
-
const
|
|
15043
|
-
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));
|
|
15044
15239
|
if (result.isError) {
|
|
15045
15240
|
return result_Result.error(SafroleSealError.IncorrectSeal);
|
|
15046
15241
|
}
|
|
@@ -15151,6 +15346,12 @@ class AccumulationStateUpdate {
|
|
|
15151
15346
|
}
|
|
15152
15347
|
return update;
|
|
15153
15348
|
}
|
|
15349
|
+
/** Retrieve and clear pending transfers. */
|
|
15350
|
+
takeTransfers() {
|
|
15351
|
+
const transfers = this.transfers;
|
|
15352
|
+
this.transfers = [];
|
|
15353
|
+
return transfers;
|
|
15354
|
+
}
|
|
15154
15355
|
}
|
|
15155
15356
|
class PartiallyUpdatedState {
|
|
15156
15357
|
state;
|
|
@@ -19190,6 +19391,24 @@ class Interpreter {
|
|
|
19190
19391
|
getMemoryPage(pageNumber) {
|
|
19191
19392
|
return this.memory.getPageDump(tryAsPageNumber(pageNumber));
|
|
19192
19393
|
}
|
|
19394
|
+
calculateBlockGasCost() {
|
|
19395
|
+
const codeLength = this.code.length;
|
|
19396
|
+
const blocks = new Map();
|
|
19397
|
+
let currentBlock = "0";
|
|
19398
|
+
let gasCost = 0;
|
|
19399
|
+
const getNextIstructionIndex = (index) => index + 1 + this.mask.getNoOfBytesToNextInstruction(index + 1);
|
|
19400
|
+
for (let index = 0; index < codeLength; index = getNextIstructionIndex(index)) {
|
|
19401
|
+
const instruction = this.code[index];
|
|
19402
|
+
if (this.basicBlocks.isBeginningOfBasicBlock(index)) {
|
|
19403
|
+
blocks.set(currentBlock, gasCost);
|
|
19404
|
+
currentBlock = index.toString();
|
|
19405
|
+
gasCost = 0;
|
|
19406
|
+
}
|
|
19407
|
+
gasCost += instructionGasMap[instruction];
|
|
19408
|
+
}
|
|
19409
|
+
blocks.set(currentBlock, gasCost);
|
|
19410
|
+
return blocks;
|
|
19411
|
+
}
|
|
19193
19412
|
}
|
|
19194
19413
|
|
|
19195
19414
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/index.ts
|
|
@@ -19895,24 +20114,78 @@ class AccumulateExternalities {
|
|
|
19895
20114
|
this.updatedState.stateUpdate.authorizationQueues.set(coreIndex, authQueue);
|
|
19896
20115
|
return result_Result.ok(result_OK);
|
|
19897
20116
|
}
|
|
20117
|
+
updatePrivilegedServiceId(
|
|
20118
|
+
// The id that privileged service wants to be updated to
|
|
20119
|
+
newId,
|
|
20120
|
+
// Current id of privileged service (updated state)
|
|
20121
|
+
currentId, {
|
|
20122
|
+
// is current service id a manager (can update anything)
|
|
20123
|
+
isManager,
|
|
20124
|
+
// is current service attempting to update itself (privileged are owned)
|
|
20125
|
+
isSelf,
|
|
20126
|
+
// is the service id already changed in this block
|
|
20127
|
+
isAlreadyChanged, }) {
|
|
20128
|
+
if (isManager) {
|
|
20129
|
+
return newId;
|
|
20130
|
+
}
|
|
20131
|
+
// current service can update itself, only if it was a privileged
|
|
20132
|
+
// service at the start of the block. I.e. owned privileges cannot
|
|
20133
|
+
// be transfered multiple times in a block.
|
|
20134
|
+
if (isSelf && !isAlreadyChanged) {
|
|
20135
|
+
return newId;
|
|
20136
|
+
}
|
|
20137
|
+
return currentId;
|
|
20138
|
+
}
|
|
19898
20139
|
updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate) {
|
|
19899
20140
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/36d90036de00?v=0.6.7 */
|
|
19900
|
-
const
|
|
19901
|
-
|
|
19902
|
-
|
|
19903
|
-
|
|
19904
|
-
|
|
19905
|
-
|
|
20141
|
+
const current = this.updatedState.getPrivilegedServices();
|
|
20142
|
+
const isManager = current.manager === this.currentServiceId;
|
|
20143
|
+
if (Compatibility.isLessThan(GpVersion.V0_7_1)) {
|
|
20144
|
+
if (!isManager) {
|
|
20145
|
+
return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
|
|
20146
|
+
}
|
|
20147
|
+
if (manager === null || delegator === null) {
|
|
20148
|
+
return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Either manager or delegator is not a valid service id.");
|
|
20149
|
+
}
|
|
20150
|
+
this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
|
|
20151
|
+
manager,
|
|
20152
|
+
assigners: authorizers,
|
|
20153
|
+
delegator: delegator,
|
|
20154
|
+
registrar: registrar ?? tryAsServiceId(0),
|
|
20155
|
+
autoAccumulateServices: autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit })),
|
|
20156
|
+
});
|
|
20157
|
+
return result_Result.ok(result_OK);
|
|
19906
20158
|
}
|
|
19907
|
-
|
|
19908
|
-
|
|
20159
|
+
const original = this.updatedState.state.privilegedServices;
|
|
20160
|
+
if (manager === null || delegator === null || registrar === null) {
|
|
20161
|
+
return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Either manager or delegator or registrar is not a valid service id.");
|
|
19909
20162
|
}
|
|
20163
|
+
const newDelegator = this.updatePrivilegedServiceId(delegator, current.delegator, {
|
|
20164
|
+
isManager,
|
|
20165
|
+
isSelf: this.currentServiceId === current.delegator,
|
|
20166
|
+
isAlreadyChanged: current.delegator !== original.delegator,
|
|
20167
|
+
});
|
|
20168
|
+
const newRegistrar = this.updatePrivilegedServiceId(registrar, current.registrar, {
|
|
20169
|
+
isManager,
|
|
20170
|
+
isSelf: this.currentServiceId === current.registrar,
|
|
20171
|
+
isAlreadyChanged: current.registrar !== original.registrar,
|
|
20172
|
+
});
|
|
20173
|
+
const newAssigners = current.assigners.map((currentAssigner, index) => this.updatePrivilegedServiceId(authorizers[index], currentAssigner, {
|
|
20174
|
+
isManager,
|
|
20175
|
+
isSelf: this.currentServiceId === currentAssigner,
|
|
20176
|
+
isAlreadyChanged: currentAssigner !== original.assigners[index],
|
|
20177
|
+
}));
|
|
20178
|
+
const newManager = isManager ? manager : current.manager;
|
|
20179
|
+
const newAutoAccumulateServices = isManager
|
|
20180
|
+
? autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit }))
|
|
20181
|
+
: current.autoAccumulateServices;
|
|
20182
|
+
// finally update the privileges
|
|
19910
20183
|
this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
|
|
19911
|
-
manager,
|
|
19912
|
-
assigners:
|
|
19913
|
-
delegator,
|
|
19914
|
-
registrar:
|
|
19915
|
-
autoAccumulateServices:
|
|
20184
|
+
manager: newManager,
|
|
20185
|
+
assigners: tryAsPerCore(newAssigners, this.chainSpec),
|
|
20186
|
+
delegator: newDelegator,
|
|
20187
|
+
registrar: newRegistrar,
|
|
20188
|
+
autoAccumulateServices: newAutoAccumulateServices,
|
|
19916
20189
|
});
|
|
19917
20190
|
return result_Result.ok(result_OK);
|
|
19918
20191
|
}
|
|
@@ -21159,7 +21432,7 @@ class Assign {
|
|
|
21159
21432
|
// NOTE: Here we know the core index is valid
|
|
21160
21433
|
const coreIndex = tryAsCoreIndex(Number(maybeCoreIndex));
|
|
21161
21434
|
const decoder = decoder_Decoder.fromBlob(res);
|
|
21162
|
-
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);
|
|
21163
21436
|
const fixedSizeAuthQueue = FixedSizeArray.new(authQueue, AUTHORIZATION_QUEUE_SIZE);
|
|
21164
21437
|
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
|
|
21165
21438
|
if (result.isOk) {
|
|
@@ -21271,6 +21544,7 @@ class Bless {
|
|
|
21271
21544
|
return;
|
|
21272
21545
|
}
|
|
21273
21546
|
const e = updateResult.error;
|
|
21547
|
+
// NOTE: `UpdatePrivilegesError.UnprivilegedService` won't happen in 0.7.1+
|
|
21274
21548
|
if (e === UpdatePrivilegesError.UnprivilegedService) {
|
|
21275
21549
|
logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- HUH`;
|
|
21276
21550
|
regs.set(bless_IN_OUT_REG, HostCallResult.HUH);
|
|
@@ -21354,7 +21628,7 @@ class Checkpoint {
|
|
|
21354
21628
|
|
|
21355
21629
|
|
|
21356
21630
|
const designate_IN_OUT_REG = 7;
|
|
21357
|
-
const VALIDATOR_DATA_BYTES = tryAsExactBytes(
|
|
21631
|
+
const VALIDATOR_DATA_BYTES = tryAsExactBytes(validator_data_ValidatorData.Codec.sizeHint);
|
|
21358
21632
|
/**
|
|
21359
21633
|
* Designate a new set of validator keys.
|
|
21360
21634
|
*
|
|
@@ -21383,7 +21657,7 @@ class Designate {
|
|
|
21383
21657
|
return PvmExecution.Panic;
|
|
21384
21658
|
}
|
|
21385
21659
|
const decoder = decoder_Decoder.fromBlob(res);
|
|
21386
|
-
const validatorsData = decoder.sequenceFixLen(
|
|
21660
|
+
const validatorsData = decoder.sequenceFixLen(validator_data_ValidatorData.Codec, this.chainSpec.validatorsCount);
|
|
21387
21661
|
const result = this.partialState.updateValidatorsData(tryAsPerValidator(validatorsData, this.chainSpec));
|
|
21388
21662
|
if (result.isError) {
|
|
21389
21663
|
logger_logger.trace `DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- HUH`;
|
|
@@ -22265,7 +22539,7 @@ class Lookup {
|
|
|
22265
22539
|
}
|
|
22266
22540
|
// v
|
|
22267
22541
|
const preImage = this.account.lookup(serviceId, preImageHash);
|
|
22268
|
-
logger_logger.trace `LOOKUP(${serviceId}, ${preImageHash}) <- ${preImage?.toStringTruncated()}...`;
|
|
22542
|
+
logger_logger.trace `LOOKUP(${serviceId}, ${preImageHash}) <- ${preImage?.toStringTruncated() ?? "<missing>"}...`;
|
|
22269
22543
|
const preImageLength = preImage === null ? numbers_tryAsU64(0) : numbers_tryAsU64(preImage.raw.length);
|
|
22270
22544
|
const preimageBlobOffset = regs.get(10);
|
|
22271
22545
|
const lengthToWrite = regs.get(11);
|
|
@@ -22815,15 +23089,15 @@ class Accumulate {
|
|
|
22815
23089
|
*
|
|
22816
23090
|
* https://graypaper.fluffylabs.dev/#/7e6ff6a/2fdb012fdb01?v=0.6.7
|
|
22817
23091
|
*/
|
|
22818
|
-
async pvmAccumulateInvocation(slot, serviceId, transfers, operands, gas, entropy,
|
|
22819
|
-
const
|
|
22820
|
-
if (
|
|
23092
|
+
async pvmAccumulateInvocation(slot, serviceId, transfers, operands, gas, entropy, updatedState) {
|
|
23093
|
+
const serviceInfo = updatedState.getServiceInfo(serviceId);
|
|
23094
|
+
if (serviceInfo === null) {
|
|
22821
23095
|
accumulate_logger.log `Service with id ${serviceId} not found.`;
|
|
22822
23096
|
return result_Result.error(PvmInvocationError.NoService);
|
|
22823
23097
|
}
|
|
22824
|
-
const codeHash =
|
|
23098
|
+
const codeHash = serviceInfo.codeHash;
|
|
22825
23099
|
// TODO [ToDr] Should we check that the preimage is still available?
|
|
22826
|
-
const code =
|
|
23100
|
+
const code = updatedState.getPreimage(serviceId, codeHash.asOpaque());
|
|
22827
23101
|
if (code === null) {
|
|
22828
23102
|
accumulate_logger.log `Code with hash ${codeHash} not found for service ${serviceId}.`;
|
|
22829
23103
|
return result_Result.error(PvmInvocationError.NoPreimage);
|
|
@@ -22833,7 +23107,7 @@ class Accumulate {
|
|
|
22833
23107
|
return result_Result.error(PvmInvocationError.PreimageTooLong);
|
|
22834
23108
|
}
|
|
22835
23109
|
const nextServiceId = generateNextServiceId({ serviceId, entropy, timeslot: slot }, this.chainSpec, this.blake2b);
|
|
22836
|
-
const partialState = new AccumulateExternalities(this.chainSpec, this.blake2b,
|
|
23110
|
+
const partialState = new AccumulateExternalities(this.chainSpec, this.blake2b, updatedState, serviceId, nextServiceId, slot);
|
|
22837
23111
|
const fetchExternalities = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
22838
23112
|
? FetchExternalities.createForAccumulate({ entropy, transfers, operands }, this.chainSpec)
|
|
22839
23113
|
: FetchExternalities.createForPre071Accumulate({ entropy, operands }, this.chainSpec);
|
|
@@ -22887,11 +23161,28 @@ class Accumulate {
|
|
|
22887
23161
|
*/
|
|
22888
23162
|
async accumulateSingleService(serviceId, transfers, operands, gasCost, slot, entropy, inputStateUpdate) {
|
|
22889
23163
|
accumulate_logger.log `Accumulating service ${serviceId}, transfers: ${transfers.length} operands: ${operands.length} at slot: ${slot}.`;
|
|
22890
|
-
const
|
|
23164
|
+
const updatedState = new PartiallyUpdatedState(this.state, inputStateUpdate);
|
|
23165
|
+
// update service balance from incoming transfers
|
|
23166
|
+
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
|
|
23167
|
+
const serviceInfo = updatedState.getServiceInfo(serviceId);
|
|
23168
|
+
if (serviceInfo !== null) {
|
|
23169
|
+
// update the balance from incoming tranfsers
|
|
23170
|
+
const newBalance = sumU64(serviceInfo.balance, ...transfers.map((item) => item.amount));
|
|
23171
|
+
if (newBalance.overflow) {
|
|
23172
|
+
accumulate_logger.log `Accumulation failed because of overflowing balance ${serviceId}.`;
|
|
23173
|
+
return { stateUpdate: null, consumedGas: 0n };
|
|
23174
|
+
}
|
|
23175
|
+
const newInfo = ServiceAccountInfo.create({ ...serviceInfo, balance: newBalance.value });
|
|
23176
|
+
updatedState.updateServiceInfo(serviceId, newInfo);
|
|
23177
|
+
}
|
|
23178
|
+
}
|
|
23179
|
+
const result = await this.pvmAccumulateInvocation(slot, serviceId, transfers, operands, gasCost, entropy, updatedState);
|
|
22891
23180
|
if (result.isError) {
|
|
22892
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
23181
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/2fc9032fc903?v=0.7.2
|
|
22893
23182
|
accumulate_logger.log `Accumulation failed for ${serviceId}.`;
|
|
22894
|
-
|
|
23183
|
+
// even though accumulation failed, we still need to make sure that
|
|
23184
|
+
// incoming transfers updated the balance, hence we pass state update here
|
|
23185
|
+
return { stateUpdate: updatedState.stateUpdate, consumedGas: 0n };
|
|
22895
23186
|
}
|
|
22896
23187
|
accumulate_logger.log `Accumulation successful for ${serviceId}. Consumed: ${result.ok.consumedGas}`;
|
|
22897
23188
|
return result.ok;
|
|
@@ -22949,7 +23240,7 @@ class Accumulate {
|
|
|
22949
23240
|
const accumulateData = new AccumulateData(reportsToAccumulateInParallel, transfers, autoAccumulateServices);
|
|
22950
23241
|
const reportsToAccumulateSequentially = reports.subview(i);
|
|
22951
23242
|
const { gasCost, state: stateAfterParallelAcc, ...rest } = await this.accumulateInParallel(accumulateData, slot, entropy, statistics, stateUpdate);
|
|
22952
|
-
const newTransfers = stateAfterParallelAcc.
|
|
23243
|
+
const newTransfers = stateAfterParallelAcc.takeTransfers();
|
|
22953
23244
|
assertEmpty(rest);
|
|
22954
23245
|
// NOTE [ToDr] recursive invocation
|
|
22955
23246
|
const { accumulatedReports, gasCost: seqGasCost, state, ...seqRest } = await this.accumulateSequentially(tryAsServiceGas(gasLimit - gasCost), reportsToAccumulateSequentially, newTransfers, slot, entropy, statistics, stateAfterParallelAcc, []);
|
|
@@ -22977,12 +23268,19 @@ class Accumulate {
|
|
|
22977
23268
|
const currentManager = (inputStateUpdate.privilegedServices ?? this.state.privilegedServices).manager;
|
|
22978
23269
|
for (const serviceId of serviceIds) {
|
|
22979
23270
|
const checkpoint = AccumulationStateUpdate.copyFrom(currentState);
|
|
22980
|
-
const
|
|
23271
|
+
const operands = accumulateData.getOperands(serviceId);
|
|
23272
|
+
const { consumedGas, stateUpdate } = await this.accumulateSingleService(serviceId, accumulateData.getTransfers(serviceId), operands, accumulateData.getGasCost(serviceId), slot, entropy, currentState);
|
|
22981
23273
|
gasCost = tryAsServiceGas(gasCost + consumedGas);
|
|
23274
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/193b05193b05?v=0.7.2
|
|
22982
23275
|
const serviceStatistics = statistics.get(serviceId) ?? { count: numbers_tryAsU32(0), gasUsed: tryAsServiceGas(0) };
|
|
22983
|
-
|
|
22984
|
-
|
|
22985
|
-
|
|
23276
|
+
const count = accumulateData.getReportsLength(serviceId);
|
|
23277
|
+
// [0.7.1]: do not update statistics, if the service only had incoming transfers
|
|
23278
|
+
if ((Compatibility.isLessThan(GpVersion.V0_7_2) && count > 0) ||
|
|
23279
|
+
(Compatibility.isGreaterOrEqual(GpVersion.V0_7_2) && (count > 0 || consumedGas > 0n))) {
|
|
23280
|
+
serviceStatistics.count = numbers_tryAsU32(serviceStatistics.count + count);
|
|
23281
|
+
serviceStatistics.gasUsed = tryAsServiceGas(serviceStatistics.gasUsed + consumedGas);
|
|
23282
|
+
statistics.set(serviceId, serviceStatistics);
|
|
23283
|
+
}
|
|
22986
23284
|
currentState = stateUpdate === null ? checkpoint : stateUpdate;
|
|
22987
23285
|
if (Compatibility.is(GpVersion.V0_7_0) && serviceId === currentManager) {
|
|
22988
23286
|
const newV = currentState.privilegedServices?.delegator;
|
|
@@ -23017,9 +23315,10 @@ class Accumulate {
|
|
|
23017
23315
|
const recentlyAccumulated = tryAsPerEpochBlock(newRecentlyAccumulated, this.chainSpec);
|
|
23018
23316
|
const accumulationQueue = this.state.accumulationQueue.slice();
|
|
23019
23317
|
accumulationQueue[phaseIndex] = pruneQueue(toAccumulateLater, accumulatedSet);
|
|
23318
|
+
const timeslot = this.state.timeslot;
|
|
23020
23319
|
for (let i = 1; i < epochLength; i++) {
|
|
23021
23320
|
const queueIndex = (phaseIndex + epochLength - i) % epochLength;
|
|
23022
|
-
if (i < slot -
|
|
23321
|
+
if (i < slot - timeslot) {
|
|
23023
23322
|
accumulationQueue[queueIndex] = [];
|
|
23024
23323
|
}
|
|
23025
23324
|
else {
|
|
@@ -23034,6 +23333,7 @@ class Accumulate {
|
|
|
23034
23333
|
const info = partialStateUpdate.getServiceInfo(serviceId);
|
|
23035
23334
|
if (info === null) {
|
|
23036
23335
|
// NOTE If there is no service, we dont update it.
|
|
23336
|
+
accumulate_logger.log `Skipping update of ${serviceId}, because we have no service info.`;
|
|
23037
23337
|
continue;
|
|
23038
23338
|
}
|
|
23039
23339
|
// δ‡
|
|
@@ -23230,7 +23530,6 @@ class DeferredTransfers {
|
|
|
23230
23530
|
|
|
23231
23531
|
|
|
23232
23532
|
|
|
23233
|
-
|
|
23234
23533
|
/**
|
|
23235
23534
|
* Maintain a list of available authorizations per core.
|
|
23236
23535
|
*
|
|
@@ -23259,11 +23558,12 @@ class Authorization {
|
|
|
23259
23558
|
*/
|
|
23260
23559
|
transition(input) {
|
|
23261
23560
|
const authPoolsUpdate = this.state.authPools.slice();
|
|
23561
|
+
const authQueues = this.state.authQueues;
|
|
23262
23562
|
// we transition authorizations for each core.
|
|
23263
23563
|
for (let coreIndex = tryAsCoreIndex(0); coreIndex < this.chainSpec.coresCount; coreIndex++) {
|
|
23264
23564
|
let pool = authPoolsUpdate[coreIndex].slice();
|
|
23265
23565
|
// the queue is only read (we should most likely use `ArrayView` here).
|
|
23266
|
-
const queue =
|
|
23566
|
+
const queue = authQueues[coreIndex];
|
|
23267
23567
|
// if there were any used hashes - remove them
|
|
23268
23568
|
const usedHashes = input.used.get(coreIndex);
|
|
23269
23569
|
if (usedHashes !== undefined) {
|
|
@@ -23437,14 +23737,18 @@ class RecentHistory {
|
|
|
23437
23737
|
* https://graypaper.fluffylabs.dev/#/1c979cb/0f55020f5502?v=0.7.1
|
|
23438
23738
|
*/
|
|
23439
23739
|
partialTransition(input) {
|
|
23440
|
-
const
|
|
23740
|
+
const stateBlocks = this.state.recentBlocks;
|
|
23741
|
+
const recentBlocks = stateBlocks.blocks.slice();
|
|
23441
23742
|
const lastState = recentBlocks.length > 0 ? recentBlocks[recentBlocks.length - 1] : null;
|
|
23442
23743
|
// update the posterior root of previous state.
|
|
23443
23744
|
if (lastState !== null) {
|
|
23444
23745
|
lastState.postStateRoot = input.priorStateRoot;
|
|
23445
23746
|
}
|
|
23446
23747
|
return {
|
|
23447
|
-
recentBlocks:
|
|
23748
|
+
recentBlocks: RecentBlocks.create({
|
|
23749
|
+
blocks: sized_array_asKnownSize(recentBlocks),
|
|
23750
|
+
accumulationLog: stateBlocks.accumulationLog,
|
|
23751
|
+
}), // β_H†
|
|
23448
23752
|
};
|
|
23449
23753
|
}
|
|
23450
23754
|
/**
|
|
@@ -23456,8 +23760,8 @@ class RecentHistory {
|
|
|
23456
23760
|
transition(input) {
|
|
23457
23761
|
const recentBlocks = input.partial.recentBlocks.blocks.slice();
|
|
23458
23762
|
// `β′_B`
|
|
23459
|
-
const mmr = this.state.recentBlocks.
|
|
23460
|
-
? MerkleMountainRange.fromPeaks(this.hasher, this.state.recentBlocks.
|
|
23763
|
+
const mmr = this.state.recentBlocks.accumulationLog !== null
|
|
23764
|
+
? MerkleMountainRange.fromPeaks(this.hasher, this.state.recentBlocks.accumulationLog)
|
|
23461
23765
|
: MerkleMountainRange.empty(this.hasher);
|
|
23462
23766
|
// append the accumulation root
|
|
23463
23767
|
mmr.append(input.accumulateRoot);
|
|
@@ -23475,7 +23779,7 @@ class RecentHistory {
|
|
|
23475
23779
|
}
|
|
23476
23780
|
// write back to the state.
|
|
23477
23781
|
return {
|
|
23478
|
-
recentBlocks:
|
|
23782
|
+
recentBlocks: RecentBlocks.create(RecentBlocks.create({
|
|
23479
23783
|
blocks: sized_array_asKnownSize(recentBlocks),
|
|
23480
23784
|
accumulationLog: peaks,
|
|
23481
23785
|
})),
|
|
@@ -23687,7 +23991,6 @@ function verifyReportsBasic(input) {
|
|
|
23687
23991
|
|
|
23688
23992
|
|
|
23689
23993
|
|
|
23690
|
-
|
|
23691
23994
|
const verify_contextual_logger = Logger.new(import.meta.filename, "stf:reports");
|
|
23692
23995
|
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/15eb0115eb01?v=0.6.7 */
|
|
23693
23996
|
function verifyContextualValidity(input, state, headerChain, maxLookupAnchorAge) {
|
|
@@ -23800,7 +24103,7 @@ function verifyRefineContexts(minLookupSlot, contexts, recentBlocksPartialUpdate
|
|
|
23800
24103
|
return result_Result.error(ReportsError.BadStateRoot, `Anchor state root mismatch. Got: ${context.stateRoot}, expected: ${recentBlock.postStateRoot}.`);
|
|
23801
24104
|
}
|
|
23802
24105
|
// check beefy root
|
|
23803
|
-
const beefyRoot =
|
|
24106
|
+
const beefyRoot = recentBlock.accumulationResult;
|
|
23804
24107
|
if (!beefyRoot.isEqualTo(context.beefyRoot)) {
|
|
23805
24108
|
return result_Result.error(ReportsError.BadBeefyMmrRoot, `Invalid BEEFY super peak hash. Got: ${context.beefyRoot}, expected: ${beefyRoot}. Anchor: ${recentBlock.headerHash}`);
|
|
23806
24109
|
}
|
|
@@ -24042,8 +24345,9 @@ function verifyPostSignatureChecks(input, availabilityAssignment, authPools, ser
|
|
|
24042
24345
|
* https://graypaper.fluffylabs.dev/#/5f542d7/15eb0015ed00
|
|
24043
24346
|
*/
|
|
24044
24347
|
const authorizerHash = report.authorizerHash;
|
|
24045
|
-
const authorizerPool = authPools
|
|
24046
|
-
|
|
24348
|
+
const authorizerPool = authPools.get(coreIndex);
|
|
24349
|
+
const pool = authorizerPool?.materialize() ?? [];
|
|
24350
|
+
if (pool.find((hash) => hash.isEqualTo(authorizerHash)) === undefined) {
|
|
24047
24351
|
return result_Result.error(ReportsError.CoreUnauthorized, `Authorizer hash not found in the pool of core ${coreIndex}: ${authorizerHash}`);
|
|
24048
24352
|
}
|
|
24049
24353
|
/**
|
|
@@ -24173,7 +24477,8 @@ class Reports {
|
|
|
24173
24477
|
return verifyCredentials(input.guarantees, workReportHashes, input.slot, (headerTimeSlot, guaranteeTimeSlot) => this.getGuarantorAssignment(headerTimeSlot, guaranteeTimeSlot, input.newEntropy));
|
|
24174
24478
|
}
|
|
24175
24479
|
verifyPostSignatureChecks(input, assurancesAvailAssignment) {
|
|
24176
|
-
|
|
24480
|
+
const authPoolsView = this.state.view().authPoolsView();
|
|
24481
|
+
return verifyPostSignatureChecks(input, assurancesAvailAssignment, authPoolsView, (id) => this.state.getService(id));
|
|
24177
24482
|
}
|
|
24178
24483
|
verifyContextualValidity(input) {
|
|
24179
24484
|
return verifyContextualValidity(input, this.state, this.headerChain, this.chainSpec.maxLookupAnchorAge);
|
|
@@ -24746,6 +25051,9 @@ class OnChain {
|
|
|
24746
25051
|
servicesUpdate = servicesUpdateFromDeferredTransfers;
|
|
24747
25052
|
assertEmpty(deferredTransfersRest);
|
|
24748
25053
|
}
|
|
25054
|
+
else {
|
|
25055
|
+
debug_check `${pendingTransfers.length === 0} All transfers should be already accumulated.`;
|
|
25056
|
+
}
|
|
24749
25057
|
const accumulateRoot = await this.accumulateOutput.transition({ accumulationOutputLog });
|
|
24750
25058
|
// recent history
|
|
24751
25059
|
const recentHistoryUpdate = this.recentHistory.transition({
|