@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-generator.mjs
CHANGED
|
@@ -2870,7 +2870,7 @@ var GpVersion;
|
|
|
2870
2870
|
(function (GpVersion) {
|
|
2871
2871
|
GpVersion["V0_6_7"] = "0.6.7";
|
|
2872
2872
|
GpVersion["V0_7_0"] = "0.7.0";
|
|
2873
|
-
GpVersion["V0_7_1"] = "0.7.1
|
|
2873
|
+
GpVersion["V0_7_1"] = "0.7.1";
|
|
2874
2874
|
GpVersion["V0_7_2"] = "0.7.2-preview";
|
|
2875
2875
|
})(GpVersion || (GpVersion = {}));
|
|
2876
2876
|
var TestSuite;
|
|
@@ -2879,11 +2879,11 @@ var TestSuite;
|
|
|
2879
2879
|
TestSuite["JAMDUNA"] = "jamduna";
|
|
2880
2880
|
})(TestSuite || (TestSuite = {}));
|
|
2881
2881
|
const DEFAULT_SUITE = TestSuite.W3F_DAVXY;
|
|
2882
|
-
const
|
|
2882
|
+
const DEFAULT_VERSION = GpVersion.V0_7_1;
|
|
2883
2883
|
const env = typeof process === "undefined" ? {} : process.env;
|
|
2884
|
-
const DEFAULT_VERSION = GpVersion.V0_7_0;
|
|
2885
2884
|
let CURRENT_VERSION = parseCurrentVersion(env.GP_VERSION) ?? DEFAULT_VERSION;
|
|
2886
2885
|
let CURRENT_SUITE = parseCurrentSuite(env.TEST_SUITE) ?? DEFAULT_SUITE;
|
|
2886
|
+
const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1, GpVersion.V0_7_2];
|
|
2887
2887
|
function parseCurrentVersion(env) {
|
|
2888
2888
|
if (env === undefined) {
|
|
2889
2889
|
return undefined;
|
|
@@ -4940,6 +4940,9 @@ class ObjectView {
|
|
|
4940
4940
|
toString() {
|
|
4941
4941
|
return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
|
|
4942
4942
|
}
|
|
4943
|
+
[TEST_COMPARE_USING]() {
|
|
4944
|
+
return this.materialize();
|
|
4945
|
+
}
|
|
4943
4946
|
}
|
|
4944
4947
|
/**
|
|
4945
4948
|
* A lazy-evaluated decoder of a sequence.
|
|
@@ -5072,7 +5075,7 @@ const TYPICAL_DICTIONARY_LENGTH = 32;
|
|
|
5072
5075
|
* It's not true in a general case, but should be good enough for us.
|
|
5073
5076
|
*
|
|
5074
5077
|
*/
|
|
5075
|
-
function
|
|
5078
|
+
function descriptors_readonlyArray(desc) {
|
|
5076
5079
|
return desc.convert((x) => {
|
|
5077
5080
|
debug_check `
|
|
5078
5081
|
${Array.isArray(x)}
|
|
@@ -5234,7 +5237,15 @@ var descriptors_codec;
|
|
|
5234
5237
|
/** Custom encoding / decoding logic. */
|
|
5235
5238
|
codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
|
|
5236
5239
|
/** Choose a descriptor depending on the encoding/decoding context. */
|
|
5237
|
-
codec.select = ({ name, sizeHint, }, chooser) =>
|
|
5240
|
+
codec.select = ({ name, sizeHint, }, chooser) => {
|
|
5241
|
+
const Self = chooser(null);
|
|
5242
|
+
return Descriptor.withView(name, sizeHint, (e, x) => chooser(e.getContext()).encode(e, x), (d) => chooser(d.getContext()).decode(d), (s) => chooser(s.decoder.getContext()).skip(s), hasUniqueView(Self)
|
|
5243
|
+
? codec.select({
|
|
5244
|
+
name: Self.View.name,
|
|
5245
|
+
sizeHint: Self.View.sizeHint,
|
|
5246
|
+
}, (ctx) => chooser(ctx).View)
|
|
5247
|
+
: Self.View);
|
|
5248
|
+
};
|
|
5238
5249
|
/**
|
|
5239
5250
|
* A descriptor for a more complex POJO.
|
|
5240
5251
|
*
|
|
@@ -6056,7 +6067,7 @@ const BANDERSNATCH_KEY_BYTES = 32;
|
|
|
6056
6067
|
/** Bandersnatch VRF signature size */
|
|
6057
6068
|
const bandersnatch_BANDERSNATCH_VRF_SIGNATURE_BYTES = 96;
|
|
6058
6069
|
/** Bandersnatch ring commitment size */
|
|
6059
|
-
const
|
|
6070
|
+
const bandersnatch_BANDERSNATCH_RING_ROOT_BYTES = 144;
|
|
6060
6071
|
/** Bandersnatch proof size */
|
|
6061
6072
|
const BANDERSNATCH_PROOF_BYTES = 784;
|
|
6062
6073
|
/** BLS public key size. */
|
|
@@ -7184,9 +7195,9 @@ function codecWithContext(chooser) {
|
|
|
7184
7195
|
/** Codec for a known-size array with length validation. */
|
|
7185
7196
|
const codecKnownSizeArray = (val, options, _id) => {
|
|
7186
7197
|
if ("fixedLength" in options) {
|
|
7187
|
-
return
|
|
7198
|
+
return descriptors_readonlyArray(descriptors_codec.sequenceFixLen(val, options.fixedLength)).convert(seeThrough, sized_array_asKnownSize);
|
|
7188
7199
|
}
|
|
7189
|
-
return
|
|
7200
|
+
return descriptors_readonlyArray(descriptors_codec.sequenceVarLen(val, options)).convert(seeThrough, sized_array_asKnownSize);
|
|
7190
7201
|
};
|
|
7191
7202
|
/** Codec for a fixed-size array with length validation. */
|
|
7192
7203
|
const codecFixedSizeArray = (val, len) => {
|
|
@@ -7323,7 +7334,7 @@ function tryAsPerValidator(array, spec) {
|
|
|
7323
7334
|
`;
|
|
7324
7335
|
return sized_array_asKnownSize(array);
|
|
7325
7336
|
}
|
|
7326
|
-
const
|
|
7337
|
+
const common_codecPerValidator = (val) => codecWithContext((context) => {
|
|
7327
7338
|
return codecKnownSizeArray(val, {
|
|
7328
7339
|
fixedLength: context.validatorsCount,
|
|
7329
7340
|
});
|
|
@@ -7450,7 +7461,7 @@ class Verdict extends WithDebug {
|
|
|
7450
7461
|
workReportHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
7451
7462
|
votesEpoch: descriptors_codec.u32.asOpaque(),
|
|
7452
7463
|
votes: codecWithContext((context) => {
|
|
7453
|
-
return
|
|
7464
|
+
return descriptors_readonlyArray(descriptors_codec.sequenceFixLen(Judgement.Codec, context.validatorsSuperMajority)).convert(seeThrough, sized_array_asKnownSize);
|
|
7454
7465
|
}),
|
|
7455
7466
|
});
|
|
7456
7467
|
static create({ workReportHash, votesEpoch, votes }) {
|
|
@@ -8142,7 +8153,7 @@ const WorkReportCodec = descriptors_codec.Class(WorkReportNoCodec, {
|
|
|
8142
8153
|
authorizerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
8143
8154
|
authorizationGasUsed: descriptors_codec.varU64.asOpaque(),
|
|
8144
8155
|
authorizationOutput: descriptors_codec.blob,
|
|
8145
|
-
segmentRootLookup:
|
|
8156
|
+
segmentRootLookup: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
|
|
8146
8157
|
results: descriptors_codec.sequenceVarLen(WorkResult.Codec).convert((x) => x, (items) => FixedSizeArray.new(items, tryAsWorkItemsCount(items.length))),
|
|
8147
8158
|
});
|
|
8148
8159
|
const WorkReportCodecPre070 = descriptors_codec.Class(WorkReportNoCodec, {
|
|
@@ -8156,7 +8167,7 @@ const WorkReportCodecPre070 = descriptors_codec.Class(WorkReportNoCodec, {
|
|
|
8156
8167
|
}),
|
|
8157
8168
|
authorizerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
8158
8169
|
authorizationOutput: descriptors_codec.blob,
|
|
8159
|
-
segmentRootLookup:
|
|
8170
|
+
segmentRootLookup: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(WorkPackageInfo.Codec)),
|
|
8160
8171
|
results: descriptors_codec.sequenceVarLen(WorkResult.Codec).convert((x) => x, (items) => FixedSizeArray.new(items, tryAsWorkItemsCount(items.length))),
|
|
8161
8172
|
authorizationGasUsed: descriptors_codec.varU64.asOpaque(),
|
|
8162
8173
|
});
|
|
@@ -8274,16 +8285,16 @@ class SignedTicket extends WithDebug {
|
|
|
8274
8285
|
}
|
|
8275
8286
|
}
|
|
8276
8287
|
/** Anonymous? entry into the ticket contest. */
|
|
8277
|
-
class
|
|
8288
|
+
class tickets_Ticket extends WithDebug {
|
|
8278
8289
|
id;
|
|
8279
8290
|
attempt;
|
|
8280
|
-
static Codec = descriptors_codec.Class(
|
|
8291
|
+
static Codec = descriptors_codec.Class(tickets_Ticket, {
|
|
8281
8292
|
id: descriptors_codec.bytes(hash_HASH_SIZE),
|
|
8282
8293
|
// TODO [ToDr] we should verify that attempt is either 0|1|2.
|
|
8283
8294
|
attempt: descriptors_codec.u8.asOpaque(),
|
|
8284
8295
|
});
|
|
8285
8296
|
static create({ id, attempt }) {
|
|
8286
|
-
return new
|
|
8297
|
+
return new tickets_Ticket(id, attempt);
|
|
8287
8298
|
}
|
|
8288
8299
|
constructor(
|
|
8289
8300
|
/**
|
|
@@ -8352,7 +8363,7 @@ class ValidatorKeys extends WithDebug {
|
|
|
8352
8363
|
class TicketsMarker extends WithDebug {
|
|
8353
8364
|
tickets;
|
|
8354
8365
|
static Codec = descriptors_codec.Class(TicketsMarker, {
|
|
8355
|
-
tickets: codecPerEpochBlock(
|
|
8366
|
+
tickets: codecPerEpochBlock(tickets_Ticket.Codec),
|
|
8356
8367
|
});
|
|
8357
8368
|
static create({ tickets }) {
|
|
8358
8369
|
return new TicketsMarker(tickets);
|
|
@@ -8376,7 +8387,7 @@ class EpochMarker extends WithDebug {
|
|
|
8376
8387
|
static Codec = descriptors_codec.Class(EpochMarker, {
|
|
8377
8388
|
entropy: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
8378
8389
|
ticketsEntropy: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
8379
|
-
validators:
|
|
8390
|
+
validators: common_codecPerValidator(ValidatorKeys.Codec),
|
|
8380
8391
|
});
|
|
8381
8392
|
static create({ entropy, ticketsEntropy, validators }) {
|
|
8382
8393
|
return new EpochMarker(entropy, ticketsEntropy, validators);
|
|
@@ -8648,6 +8659,19 @@ function emptyBlock(slot = tryAsTimeSlot(0)) {
|
|
|
8648
8659
|
});
|
|
8649
8660
|
}
|
|
8650
8661
|
|
|
8662
|
+
;// CONCATENATED MODULE: ./packages/jam/block/utils.ts
|
|
8663
|
+
|
|
8664
|
+
/**
|
|
8665
|
+
* Take an input data and re-encode that data as view.
|
|
8666
|
+
*
|
|
8667
|
+
* NOTE: this function should NEVER be used in any production code,
|
|
8668
|
+
* it's only a test helper.
|
|
8669
|
+
*/
|
|
8670
|
+
function reencodeAsView(codec, object, chainSpec) {
|
|
8671
|
+
const encoded = encoder_Encoder.encodeObject(codec, object, chainSpec);
|
|
8672
|
+
return decoder_Decoder.decodeObject(codec.View, encoded, chainSpec);
|
|
8673
|
+
}
|
|
8674
|
+
|
|
8651
8675
|
;// CONCATENATED MODULE: ./packages/jam/block/index.ts
|
|
8652
8676
|
|
|
8653
8677
|
|
|
@@ -8666,6 +8690,7 @@ function emptyBlock(slot = tryAsTimeSlot(0)) {
|
|
|
8666
8690
|
|
|
8667
8691
|
|
|
8668
8692
|
|
|
8693
|
+
|
|
8669
8694
|
;// CONCATENATED MODULE: ./packages/jam/database-lmdb/blocks.ts
|
|
8670
8695
|
|
|
8671
8696
|
|
|
@@ -9017,10 +9042,128 @@ function accumulationOutputComparator(a, b) {
|
|
|
9017
9042
|
return Ordering.Equal;
|
|
9018
9043
|
}
|
|
9019
9044
|
|
|
9045
|
+
;// CONCATENATED MODULE: ./packages/jam/block/gp-constants.ts
|
|
9046
|
+
|
|
9047
|
+
/**
|
|
9048
|
+
* This file lists all of the constants defined in the GrayPaper appendix.
|
|
9049
|
+
*
|
|
9050
|
+
* NOTE: Avoid using the constants directly, prefer "named" constants defined
|
|
9051
|
+
* in a semantical proximity to where they are used.
|
|
9052
|
+
*
|
|
9053
|
+
* NOTE: This file will most likely be removed in the future. The constants
|
|
9054
|
+
* here are only temporarily for convenience. When we figure out better names
|
|
9055
|
+
* and places for these this file will be eradicated.
|
|
9056
|
+
*
|
|
9057
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/413000413000
|
|
9058
|
+
*/
|
|
9059
|
+
/** `G_I`: The gas allocated to invoke a work-package’s Is-Authorized logic. */
|
|
9060
|
+
const G_I = 50_000_000;
|
|
9061
|
+
/** `I`: Maximum number of work items in a package. */
|
|
9062
|
+
const I = (/* unused pure expression or super */ null && (MAX_NUMBER_OF_WORK_ITEMS));
|
|
9063
|
+
/** `O`: Maximum number of items in the authorizations pool. */
|
|
9064
|
+
const O = 8;
|
|
9065
|
+
/** `Q`: The number of items in the authorizations queue. */
|
|
9066
|
+
const Q = 80;
|
|
9067
|
+
/** `S`: The maximum number of entries in the accumulation queue. */
|
|
9068
|
+
const S = 1024;
|
|
9069
|
+
/** `T`: The maximum number of extrinsics in a work-package. */
|
|
9070
|
+
const T = 128;
|
|
9071
|
+
/** `W_A`: The maximum size of is-authorized code in octets. */
|
|
9072
|
+
const W_A = 64_000;
|
|
9073
|
+
/** `W_B`: The maximum size of an encoded work-package with extrinsic data and imports. */
|
|
9074
|
+
const W_B = 13_794_305;
|
|
9075
|
+
/** `W_C`: The maximum size of service code in octets. */
|
|
9076
|
+
const W_C = 4_000_000;
|
|
9077
|
+
/** `W_M`: The maximum number of imports in a work-package. */
|
|
9078
|
+
const W_M = 3_072;
|
|
9079
|
+
/** `W_R`: The maximum total size of all output blobs in a work-report, in octets. */
|
|
9080
|
+
const W_R = 49_152;
|
|
9081
|
+
/** `W_T`: The size of a transfer memo in octets. */
|
|
9082
|
+
const W_T = 128;
|
|
9083
|
+
/** `W_M`: The maximum number of exports in a work-package. */
|
|
9084
|
+
const W_X = 3_072;
|
|
9085
|
+
// TODO [ToDr] Not sure where these should live yet :(
|
|
9086
|
+
/**
|
|
9087
|
+
* `S`: The minimum public service index.
|
|
9088
|
+
* Services of indices below these may only be created by the Registrar.
|
|
9089
|
+
*
|
|
9090
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
|
|
9091
|
+
*/
|
|
9092
|
+
const MIN_PUBLIC_SERVICE_INDEX = (/* unused pure expression or super */ null && (2 ** 16));
|
|
9093
|
+
/**
|
|
9094
|
+
* `J`: The maximum sum of dependency items in a work-report.
|
|
9095
|
+
*
|
|
9096
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
|
|
9097
|
+
*/
|
|
9098
|
+
const MAX_REPORT_DEPENDENCIES = 8;
|
|
9099
|
+
|
|
9100
|
+
;// CONCATENATED MODULE: ./packages/jam/state/accumulation-queue.ts
|
|
9101
|
+
|
|
9102
|
+
|
|
9103
|
+
|
|
9104
|
+
|
|
9105
|
+
|
|
9106
|
+
|
|
9107
|
+
|
|
9108
|
+
/**
|
|
9109
|
+
* Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
|
|
9110
|
+
*
|
|
9111
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
|
|
9112
|
+
*/
|
|
9113
|
+
class NotYetAccumulatedReport extends WithDebug {
|
|
9114
|
+
report;
|
|
9115
|
+
dependencies;
|
|
9116
|
+
static Codec = descriptors_codec.Class(NotYetAccumulatedReport, {
|
|
9117
|
+
report: WorkReport.Codec,
|
|
9118
|
+
dependencies: codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
|
|
9119
|
+
typicalLength: MAX_REPORT_DEPENDENCIES / 2,
|
|
9120
|
+
maxLength: MAX_REPORT_DEPENDENCIES,
|
|
9121
|
+
minLength: 0,
|
|
9122
|
+
}),
|
|
9123
|
+
});
|
|
9124
|
+
static create({ report, dependencies }) {
|
|
9125
|
+
return new NotYetAccumulatedReport(report, dependencies);
|
|
9126
|
+
}
|
|
9127
|
+
constructor(
|
|
9128
|
+
/**
|
|
9129
|
+
* Each of these were made available at most one epoch ago
|
|
9130
|
+
* but have or had unfulfilled dependencies.
|
|
9131
|
+
*/
|
|
9132
|
+
report,
|
|
9133
|
+
/**
|
|
9134
|
+
* Alongside the work-report itself, we retain its un-accumulated
|
|
9135
|
+
* dependencies, a set of work-package hashes.
|
|
9136
|
+
*
|
|
9137
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
|
|
9138
|
+
*/
|
|
9139
|
+
dependencies) {
|
|
9140
|
+
super();
|
|
9141
|
+
this.report = report;
|
|
9142
|
+
this.dependencies = dependencies;
|
|
9143
|
+
}
|
|
9144
|
+
}
|
|
9145
|
+
const accumulationQueueCodec = codecPerEpochBlock(descriptors_readonlyArray(descriptors_codec.sequenceVarLen(NotYetAccumulatedReport.Codec)));
|
|
9146
|
+
|
|
9147
|
+
;// CONCATENATED MODULE: ./packages/jam/state/common.ts
|
|
9148
|
+
|
|
9149
|
+
|
|
9150
|
+
/** Check if given array has correct length before casting to the opaque type. */
|
|
9151
|
+
function tryAsPerCore(array, spec) {
|
|
9152
|
+
debug_check `
|
|
9153
|
+
${array.length === spec.coresCount}
|
|
9154
|
+
Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
|
|
9155
|
+
`;
|
|
9156
|
+
return opaque_asOpaqueType(array);
|
|
9157
|
+
}
|
|
9158
|
+
const codecPerCore = (val) => codecWithContext((context) => {
|
|
9159
|
+
return codecKnownSizeArray(val, { fixedLength: context.coresCount });
|
|
9160
|
+
});
|
|
9161
|
+
|
|
9020
9162
|
;// CONCATENATED MODULE: ./packages/jam/state/assurances.ts
|
|
9021
9163
|
|
|
9022
9164
|
|
|
9023
9165
|
|
|
9166
|
+
|
|
9024
9167
|
/**
|
|
9025
9168
|
* Assignment of particular work report to a core.
|
|
9026
9169
|
*
|
|
@@ -9049,27 +9192,30 @@ class AvailabilityAssignment extends WithDebug {
|
|
|
9049
9192
|
this.timeout = timeout;
|
|
9050
9193
|
}
|
|
9051
9194
|
}
|
|
9195
|
+
const availabilityAssignmentsCodec = codecPerCore(descriptors_codec.optional(AvailabilityAssignment.Codec));
|
|
9052
9196
|
|
|
9053
|
-
;// CONCATENATED MODULE: ./packages/jam/state/
|
|
9197
|
+
;// CONCATENATED MODULE: ./packages/jam/state/auth.ts
|
|
9054
9198
|
|
|
9055
9199
|
|
|
9056
|
-
|
|
9057
|
-
|
|
9058
|
-
|
|
9059
|
-
|
|
9060
|
-
|
|
9061
|
-
|
|
9062
|
-
|
|
9063
|
-
|
|
9064
|
-
|
|
9065
|
-
|
|
9066
|
-
|
|
9200
|
+
|
|
9201
|
+
|
|
9202
|
+
|
|
9203
|
+
/** `O`: Maximal authorization pool size. */
|
|
9204
|
+
const MAX_AUTH_POOL_SIZE = O;
|
|
9205
|
+
/** `Q`: Size of the authorization queue. */
|
|
9206
|
+
const AUTHORIZATION_QUEUE_SIZE = Q;
|
|
9207
|
+
const authPoolsCodec = codecPerCore(codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
|
|
9208
|
+
minLength: 0,
|
|
9209
|
+
maxLength: MAX_AUTH_POOL_SIZE,
|
|
9210
|
+
typicalLength: MAX_AUTH_POOL_SIZE,
|
|
9211
|
+
}));
|
|
9212
|
+
const authQueuesCodec = codecPerCore(codecFixedSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE));
|
|
9067
9213
|
|
|
9068
9214
|
;// CONCATENATED MODULE: ./packages/jam/state/disputes.ts
|
|
9069
9215
|
|
|
9070
9216
|
|
|
9071
9217
|
|
|
9072
|
-
const sortedSetCodec = () =>
|
|
9218
|
+
const sortedSetCodec = () => descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE))).convert((input) => input.array, (output) => {
|
|
9073
9219
|
const typed = output.map((x) => x.asOpaque());
|
|
9074
9220
|
return SortedSet.fromSortedArray(hashComparator, typed);
|
|
9075
9221
|
});
|
|
@@ -9131,65 +9277,6 @@ function hashComparator(a, b) {
|
|
|
9131
9277
|
return a.compare(b);
|
|
9132
9278
|
}
|
|
9133
9279
|
|
|
9134
|
-
;// CONCATENATED MODULE: ./packages/jam/block/gp-constants.ts
|
|
9135
|
-
|
|
9136
|
-
/**
|
|
9137
|
-
* This file lists all of the constants defined in the GrayPaper appendix.
|
|
9138
|
-
*
|
|
9139
|
-
* NOTE: Avoid using the constants directly, prefer "named" constants defined
|
|
9140
|
-
* in a semantical proximity to where they are used.
|
|
9141
|
-
*
|
|
9142
|
-
* NOTE: This file will most likely be removed in the future. The constants
|
|
9143
|
-
* here are only temporarily for convenience. When we figure out better names
|
|
9144
|
-
* and places for these this file will be eradicated.
|
|
9145
|
-
*
|
|
9146
|
-
* https://graypaper.fluffylabs.dev/#/579bd12/413000413000
|
|
9147
|
-
*/
|
|
9148
|
-
/** `G_I`: The gas allocated to invoke a work-package’s Is-Authorized logic. */
|
|
9149
|
-
const G_I = 50_000_000;
|
|
9150
|
-
/** `I`: Maximum number of work items in a package. */
|
|
9151
|
-
const I = (/* unused pure expression or super */ null && (MAX_NUMBER_OF_WORK_ITEMS));
|
|
9152
|
-
/** `O`: Maximum number of items in the authorizations pool. */
|
|
9153
|
-
const O = 8;
|
|
9154
|
-
/** `Q`: The number of items in the authorizations queue. */
|
|
9155
|
-
const Q = 80;
|
|
9156
|
-
/** `S`: The maximum number of entries in the accumulation queue. */
|
|
9157
|
-
const S = 1024;
|
|
9158
|
-
/** `T`: The maximum number of extrinsics in a work-package. */
|
|
9159
|
-
const T = 128;
|
|
9160
|
-
/** `W_A`: The maximum size of is-authorized code in octets. */
|
|
9161
|
-
const W_A = 64_000;
|
|
9162
|
-
/** `W_B`: The maximum size of an encoded work-package with extrinsic data and imports. */
|
|
9163
|
-
const W_B = 13_794_305;
|
|
9164
|
-
/** `W_C`: The maximum size of service code in octets. */
|
|
9165
|
-
const W_C = 4_000_000;
|
|
9166
|
-
/** `W_M`: The maximum number of imports in a work-package. */
|
|
9167
|
-
const W_M = 3_072;
|
|
9168
|
-
/** `W_R`: The maximum total size of all output blobs in a work-report, in octets. */
|
|
9169
|
-
const W_R = 49_152;
|
|
9170
|
-
/** `W_T`: The size of a transfer memo in octets. */
|
|
9171
|
-
const W_T = 128;
|
|
9172
|
-
/** `W_M`: The maximum number of exports in a work-package. */
|
|
9173
|
-
const W_X = 3_072;
|
|
9174
|
-
// TODO [ToDr] Not sure where these should live yet :(
|
|
9175
|
-
/**
|
|
9176
|
-
* `S`: The minimum public service index.
|
|
9177
|
-
* Services of indices below these may only be created by the Registrar.
|
|
9178
|
-
*
|
|
9179
|
-
* https://graypaper.fluffylabs.dev/#/ab2cdbd/447a00447a00?v=0.7.2
|
|
9180
|
-
*/
|
|
9181
|
-
const MIN_PUBLIC_SERVICE_INDEX = (/* unused pure expression or super */ null && (2 ** 16));
|
|
9182
|
-
/**
|
|
9183
|
-
* `J`: The maximum sum of dependency items in a work-report.
|
|
9184
|
-
*
|
|
9185
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
|
|
9186
|
-
*/
|
|
9187
|
-
const MAX_REPORT_DEPENDENCIES = 8;
|
|
9188
|
-
/** `Q`: Size of the authorization queue. */
|
|
9189
|
-
const AUTHORIZATION_QUEUE_SIZE = Q;
|
|
9190
|
-
/** `O`: Maximal authorization pool size. */
|
|
9191
|
-
const MAX_AUTH_POOL_SIZE = O;
|
|
9192
|
-
|
|
9193
9280
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
|
|
9194
9281
|
const MAX_VALUE = 4294967295;
|
|
9195
9282
|
const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
|
|
@@ -9197,7 +9284,7 @@ const MIN_VALUE = (/* unused pure expression or super */ null && (-(2 ** 31)));
|
|
|
9197
9284
|
const MAX_SHIFT_U32 = 32;
|
|
9198
9285
|
const MAX_SHIFT_U64 = 64n;
|
|
9199
9286
|
|
|
9200
|
-
;// CONCATENATED MODULE: ./packages/jam/state/
|
|
9287
|
+
;// CONCATENATED MODULE: ./packages/jam/state/recent-blocks.ts
|
|
9201
9288
|
|
|
9202
9289
|
|
|
9203
9290
|
|
|
@@ -9205,21 +9292,265 @@ const MAX_SHIFT_U64 = 64n;
|
|
|
9205
9292
|
|
|
9206
9293
|
|
|
9207
9294
|
/**
|
|
9208
|
-
* `
|
|
9295
|
+
* `H = 8`: The size of recent history, in blocks.
|
|
9209
9296
|
*
|
|
9210
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
9297
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/416300416500
|
|
9211
9298
|
*/
|
|
9212
|
-
const
|
|
9299
|
+
const MAX_RECENT_HISTORY = 8;
|
|
9300
|
+
/** Recent history of a single block. */
|
|
9301
|
+
class BlockState extends WithDebug {
|
|
9302
|
+
headerHash;
|
|
9303
|
+
accumulationResult;
|
|
9304
|
+
postStateRoot;
|
|
9305
|
+
reported;
|
|
9306
|
+
static Codec = descriptors_codec.Class(BlockState, {
|
|
9307
|
+
headerHash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
9308
|
+
accumulationResult: descriptors_codec.bytes(hash_HASH_SIZE),
|
|
9309
|
+
postStateRoot: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
9310
|
+
reported: codecHashDictionary(WorkPackageInfo.Codec, (x) => x.workPackageHash),
|
|
9311
|
+
});
|
|
9312
|
+
static create({ headerHash, accumulationResult, postStateRoot, reported }) {
|
|
9313
|
+
return new BlockState(headerHash, accumulationResult, postStateRoot, reported);
|
|
9314
|
+
}
|
|
9315
|
+
constructor(
|
|
9316
|
+
/** Header hash. */
|
|
9317
|
+
headerHash,
|
|
9318
|
+
/** Merkle mountain belt of accumulation result. */
|
|
9319
|
+
accumulationResult,
|
|
9320
|
+
/** Posterior state root filled in with a 1-block delay. */
|
|
9321
|
+
postStateRoot,
|
|
9322
|
+
/** Reported work packages (no more than number of cores). */
|
|
9323
|
+
reported) {
|
|
9324
|
+
super();
|
|
9325
|
+
this.headerHash = headerHash;
|
|
9326
|
+
this.accumulationResult = accumulationResult;
|
|
9327
|
+
this.postStateRoot = postStateRoot;
|
|
9328
|
+
this.reported = reported;
|
|
9329
|
+
}
|
|
9330
|
+
}
|
|
9213
9331
|
/**
|
|
9214
|
-
*
|
|
9332
|
+
* Recent history of blocks.
|
|
9215
9333
|
*
|
|
9216
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/
|
|
9334
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
|
|
9217
9335
|
*/
|
|
9218
|
-
|
|
9219
|
-
|
|
9220
|
-
|
|
9221
|
-
|
|
9222
|
-
|
|
9336
|
+
class RecentBlocks extends WithDebug {
|
|
9337
|
+
blocks;
|
|
9338
|
+
accumulationLog;
|
|
9339
|
+
static Codec = descriptors_codec.Class(RecentBlocks, {
|
|
9340
|
+
blocks: codecKnownSizeArray(BlockState.Codec, {
|
|
9341
|
+
minLength: 0,
|
|
9342
|
+
maxLength: MAX_RECENT_HISTORY,
|
|
9343
|
+
typicalLength: MAX_RECENT_HISTORY,
|
|
9344
|
+
}),
|
|
9345
|
+
accumulationLog: descriptors_codec.object({
|
|
9346
|
+
peaks: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.optional(descriptors_codec.bytes(hash_HASH_SIZE)))),
|
|
9347
|
+
}),
|
|
9348
|
+
});
|
|
9349
|
+
static empty() {
|
|
9350
|
+
return new RecentBlocks(sized_array_asKnownSize([]), {
|
|
9351
|
+
peaks: [],
|
|
9352
|
+
});
|
|
9353
|
+
}
|
|
9354
|
+
static create(a) {
|
|
9355
|
+
return new RecentBlocks(a.blocks, a.accumulationLog);
|
|
9356
|
+
}
|
|
9357
|
+
constructor(
|
|
9358
|
+
/**
|
|
9359
|
+
* Most recent blocks.
|
|
9360
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0fea010fea01?v=0.6.7
|
|
9361
|
+
*/
|
|
9362
|
+
blocks,
|
|
9363
|
+
/**
|
|
9364
|
+
* Accumulation output log.
|
|
9365
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0f02020f0202?v=0.6.7
|
|
9366
|
+
*/
|
|
9367
|
+
accumulationLog) {
|
|
9368
|
+
super();
|
|
9369
|
+
this.blocks = blocks;
|
|
9370
|
+
this.accumulationLog = accumulationLog;
|
|
9371
|
+
}
|
|
9372
|
+
}
|
|
9373
|
+
|
|
9374
|
+
;// CONCATENATED MODULE: ./packages/jam/state/recently-accumulated.ts
|
|
9375
|
+
|
|
9376
|
+
|
|
9377
|
+
|
|
9378
|
+
|
|
9379
|
+
const recentlyAccumulatedCodec = codecPerEpochBlock(descriptors_codec.sequenceVarLen(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque()).convert((x) => Array.from(x), (x) => HashSet.from(x)));
|
|
9380
|
+
|
|
9381
|
+
;// CONCATENATED MODULE: ./packages/jam/state/validator-data.ts
|
|
9382
|
+
|
|
9383
|
+
|
|
9384
|
+
|
|
9385
|
+
|
|
9386
|
+
/**
|
|
9387
|
+
* Fixed size of validator metadata.
|
|
9388
|
+
*
|
|
9389
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/0d55010d5501
|
|
9390
|
+
*/
|
|
9391
|
+
const VALIDATOR_META_BYTES = 128;
|
|
9392
|
+
/**
|
|
9393
|
+
* Details about validators' identity.
|
|
9394
|
+
*
|
|
9395
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/0d4b010d4c01
|
|
9396
|
+
*/
|
|
9397
|
+
class validator_data_ValidatorData extends WithDebug {
|
|
9398
|
+
bandersnatch;
|
|
9399
|
+
ed25519;
|
|
9400
|
+
bls;
|
|
9401
|
+
metadata;
|
|
9402
|
+
static Codec = descriptors_codec.Class(validator_data_ValidatorData, {
|
|
9403
|
+
bandersnatch: descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
9404
|
+
ed25519: descriptors_codec.bytes(ED25519_KEY_BYTES).asOpaque(),
|
|
9405
|
+
bls: descriptors_codec.bytes(BLS_KEY_BYTES).asOpaque(),
|
|
9406
|
+
metadata: descriptors_codec.bytes(VALIDATOR_META_BYTES),
|
|
9407
|
+
});
|
|
9408
|
+
static create({ ed25519, bandersnatch, bls, metadata }) {
|
|
9409
|
+
return new validator_data_ValidatorData(bandersnatch, ed25519, bls, metadata);
|
|
9410
|
+
}
|
|
9411
|
+
constructor(
|
|
9412
|
+
/** Bandersnatch public key. */
|
|
9413
|
+
bandersnatch,
|
|
9414
|
+
/** ED25519 key data. */
|
|
9415
|
+
ed25519,
|
|
9416
|
+
/** BLS public key. */
|
|
9417
|
+
bls,
|
|
9418
|
+
/** Validator-defined additional metdata. */
|
|
9419
|
+
metadata) {
|
|
9420
|
+
super();
|
|
9421
|
+
this.bandersnatch = bandersnatch;
|
|
9422
|
+
this.ed25519 = ed25519;
|
|
9423
|
+
this.bls = bls;
|
|
9424
|
+
this.metadata = metadata;
|
|
9425
|
+
}
|
|
9426
|
+
}
|
|
9427
|
+
const validatorsDataCodec = common_codecPerValidator(validator_data_ValidatorData.Codec);
|
|
9428
|
+
|
|
9429
|
+
;// CONCATENATED MODULE: ./packages/jam/state/safrole-data.ts
|
|
9430
|
+
|
|
9431
|
+
|
|
9432
|
+
|
|
9433
|
+
|
|
9434
|
+
|
|
9435
|
+
|
|
9436
|
+
|
|
9437
|
+
|
|
9438
|
+
|
|
9439
|
+
|
|
9440
|
+
|
|
9441
|
+
var SafroleSealingKeysKind;
|
|
9442
|
+
(function (SafroleSealingKeysKind) {
|
|
9443
|
+
SafroleSealingKeysKind[SafroleSealingKeysKind["Tickets"] = 0] = "Tickets";
|
|
9444
|
+
SafroleSealingKeysKind[SafroleSealingKeysKind["Keys"] = 1] = "Keys";
|
|
9445
|
+
})(SafroleSealingKeysKind || (SafroleSealingKeysKind = {}));
|
|
9446
|
+
const codecBandersnatchKey = descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque();
|
|
9447
|
+
class safrole_data_SafroleSealingKeysData extends WithDebug {
|
|
9448
|
+
kind;
|
|
9449
|
+
keys;
|
|
9450
|
+
tickets;
|
|
9451
|
+
static Codec = codecWithContext((context) => {
|
|
9452
|
+
return descriptors_codec.custom({
|
|
9453
|
+
name: "SafroleSealingKeys",
|
|
9454
|
+
sizeHint: { bytes: 1 + hash_HASH_SIZE * context.epochLength, isExact: false },
|
|
9455
|
+
}, (e, x) => {
|
|
9456
|
+
e.varU32(numbers_tryAsU32(x.kind));
|
|
9457
|
+
if (x.kind === SafroleSealingKeysKind.Keys) {
|
|
9458
|
+
e.sequenceFixLen(codecBandersnatchKey, x.keys);
|
|
9459
|
+
}
|
|
9460
|
+
else {
|
|
9461
|
+
e.sequenceFixLen(tickets_Ticket.Codec, x.tickets);
|
|
9462
|
+
}
|
|
9463
|
+
}, (d) => {
|
|
9464
|
+
const epochLength = context.epochLength;
|
|
9465
|
+
const kind = d.varU32();
|
|
9466
|
+
if (kind === SafroleSealingKeysKind.Keys) {
|
|
9467
|
+
const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
|
|
9468
|
+
return safrole_data_SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
|
|
9469
|
+
}
|
|
9470
|
+
if (kind === SafroleSealingKeysKind.Tickets) {
|
|
9471
|
+
const tickets = d.sequenceFixLen(tickets_Ticket.Codec, epochLength);
|
|
9472
|
+
return safrole_data_SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
|
|
9473
|
+
}
|
|
9474
|
+
throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
|
|
9475
|
+
}, (s) => {
|
|
9476
|
+
const kind = s.decoder.varU32();
|
|
9477
|
+
if (kind === SafroleSealingKeysKind.Keys) {
|
|
9478
|
+
s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
|
|
9479
|
+
return;
|
|
9480
|
+
}
|
|
9481
|
+
if (kind === SafroleSealingKeysKind.Tickets) {
|
|
9482
|
+
s.sequenceFixLen(tickets_Ticket.Codec, context.epochLength);
|
|
9483
|
+
return;
|
|
9484
|
+
}
|
|
9485
|
+
throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
|
|
9486
|
+
});
|
|
9487
|
+
});
|
|
9488
|
+
static keys(keys) {
|
|
9489
|
+
return new safrole_data_SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
|
|
9490
|
+
}
|
|
9491
|
+
static tickets(tickets) {
|
|
9492
|
+
return new safrole_data_SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
|
|
9493
|
+
}
|
|
9494
|
+
constructor(kind, keys, tickets) {
|
|
9495
|
+
super();
|
|
9496
|
+
this.kind = kind;
|
|
9497
|
+
this.keys = keys;
|
|
9498
|
+
this.tickets = tickets;
|
|
9499
|
+
}
|
|
9500
|
+
}
|
|
9501
|
+
class SafroleData {
|
|
9502
|
+
nextValidatorData;
|
|
9503
|
+
epochRoot;
|
|
9504
|
+
sealingKeySeries;
|
|
9505
|
+
ticketsAccumulator;
|
|
9506
|
+
static Codec = descriptors_codec.Class(SafroleData, {
|
|
9507
|
+
nextValidatorData: common_codecPerValidator(validator_data_ValidatorData.Codec),
|
|
9508
|
+
epochRoot: descriptors_codec.bytes(bandersnatch_BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
9509
|
+
sealingKeySeries: safrole_data_SafroleSealingKeysData.Codec,
|
|
9510
|
+
ticketsAccumulator: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(tickets_Ticket.Codec)).convert(seeThrough, sized_array_asKnownSize),
|
|
9511
|
+
});
|
|
9512
|
+
static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
|
|
9513
|
+
return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
|
|
9514
|
+
}
|
|
9515
|
+
constructor(
|
|
9516
|
+
/** gamma_k */
|
|
9517
|
+
nextValidatorData,
|
|
9518
|
+
/** gamma_z */
|
|
9519
|
+
epochRoot,
|
|
9520
|
+
/** gamma_s */
|
|
9521
|
+
sealingKeySeries,
|
|
9522
|
+
/** gamma_a */
|
|
9523
|
+
ticketsAccumulator) {
|
|
9524
|
+
this.nextValidatorData = nextValidatorData;
|
|
9525
|
+
this.epochRoot = epochRoot;
|
|
9526
|
+
this.sealingKeySeries = sealingKeySeries;
|
|
9527
|
+
this.ticketsAccumulator = ticketsAccumulator;
|
|
9528
|
+
}
|
|
9529
|
+
}
|
|
9530
|
+
|
|
9531
|
+
;// CONCATENATED MODULE: ./packages/jam/state/service.ts
|
|
9532
|
+
|
|
9533
|
+
|
|
9534
|
+
|
|
9535
|
+
|
|
9536
|
+
|
|
9537
|
+
|
|
9538
|
+
/**
|
|
9539
|
+
* `B_S`: The basic minimum balance which all services require.
|
|
9540
|
+
*
|
|
9541
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
9542
|
+
*/
|
|
9543
|
+
const BASE_SERVICE_BALANCE = 100n;
|
|
9544
|
+
/**
|
|
9545
|
+
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
9546
|
+
*
|
|
9547
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
9548
|
+
*/
|
|
9549
|
+
const ELECTIVE_ITEM_BALANCE = 10n;
|
|
9550
|
+
/**
|
|
9551
|
+
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
9552
|
+
*
|
|
9553
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
9223
9554
|
*/
|
|
9224
9555
|
const ELECTIVE_BYTE_BALANCE = 1n;
|
|
9225
9556
|
const zeroSizeHint = {
|
|
@@ -9387,358 +9718,418 @@ class service_LookupHistoryItem {
|
|
|
9387
9718
|
}
|
|
9388
9719
|
}
|
|
9389
9720
|
|
|
9390
|
-
;// CONCATENATED MODULE: ./packages/jam/state/
|
|
9721
|
+
;// CONCATENATED MODULE: ./packages/jam/state/statistics.ts
|
|
9391
9722
|
|
|
9392
9723
|
|
|
9393
9724
|
|
|
9394
9725
|
|
|
9395
9726
|
|
|
9396
|
-
|
|
9397
|
-
|
|
9398
|
-
|
|
9399
|
-
|
|
9400
|
-
static Codec = descriptors_codec.Class(AutoAccumulate, {
|
|
9401
|
-
service: descriptors_codec.u32.asOpaque(),
|
|
9402
|
-
gasLimit: descriptors_codec.u64.asOpaque(),
|
|
9403
|
-
});
|
|
9404
|
-
static create({ service, gasLimit }) {
|
|
9405
|
-
return new AutoAccumulate(service, gasLimit);
|
|
9406
|
-
}
|
|
9407
|
-
constructor(
|
|
9408
|
-
/** Service id that auto-accumulates. */
|
|
9409
|
-
service,
|
|
9410
|
-
/** Gas limit for auto-accumulation. */
|
|
9411
|
-
gasLimit) {
|
|
9412
|
-
this.service = service;
|
|
9413
|
-
this.gasLimit = gasLimit;
|
|
9414
|
-
}
|
|
9415
|
-
}
|
|
9727
|
+
|
|
9728
|
+
const codecServiceId = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
|
|
9729
|
+
? descriptors_codec.u32.asOpaque()
|
|
9730
|
+
: descriptors_codec.varU32.convert((s) => numbers_tryAsU32(s), (i) => tryAsServiceId(i));
|
|
9416
9731
|
/**
|
|
9417
|
-
*
|
|
9732
|
+
* Activity Record of a single validator.
|
|
9733
|
+
*
|
|
9734
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/183701183701
|
|
9418
9735
|
*/
|
|
9419
|
-
class
|
|
9420
|
-
|
|
9421
|
-
|
|
9422
|
-
|
|
9423
|
-
|
|
9424
|
-
|
|
9425
|
-
|
|
9426
|
-
static Codec = descriptors_codec.Class(
|
|
9427
|
-
|
|
9428
|
-
|
|
9429
|
-
|
|
9430
|
-
|
|
9431
|
-
|
|
9432
|
-
|
|
9433
|
-
autoAccumulateServices: readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
|
|
9736
|
+
class ValidatorStatistics {
|
|
9737
|
+
blocks;
|
|
9738
|
+
tickets;
|
|
9739
|
+
preImages;
|
|
9740
|
+
preImagesSize;
|
|
9741
|
+
guarantees;
|
|
9742
|
+
assurances;
|
|
9743
|
+
static Codec = descriptors_codec.Class(ValidatorStatistics, {
|
|
9744
|
+
blocks: descriptors_codec.u32,
|
|
9745
|
+
tickets: descriptors_codec.u32,
|
|
9746
|
+
preImages: descriptors_codec.u32,
|
|
9747
|
+
preImagesSize: descriptors_codec.u32,
|
|
9748
|
+
guarantees: descriptors_codec.u32,
|
|
9749
|
+
assurances: descriptors_codec.u32,
|
|
9434
9750
|
});
|
|
9435
|
-
static create(
|
|
9436
|
-
return new
|
|
9751
|
+
static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
|
|
9752
|
+
return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
|
|
9437
9753
|
}
|
|
9438
9754
|
constructor(
|
|
9439
|
-
/**
|
|
9440
|
-
|
|
9441
|
-
|
|
9442
|
-
|
|
9443
|
-
|
|
9444
|
-
|
|
9445
|
-
/**
|
|
9446
|
-
|
|
9447
|
-
/**
|
|
9448
|
-
|
|
9449
|
-
|
|
9450
|
-
|
|
9451
|
-
|
|
9452
|
-
|
|
9453
|
-
|
|
9454
|
-
|
|
9455
|
-
|
|
9456
|
-
|
|
9457
|
-
|
|
9458
|
-
|
|
9459
|
-
|
|
9460
|
-
|
|
9461
|
-
this.autoAccumulateServices = autoAccumulateServices;
|
|
9755
|
+
/** The number of blocks produced by the validator. */
|
|
9756
|
+
blocks,
|
|
9757
|
+
/** The number of tickets introduced by the validator. */
|
|
9758
|
+
tickets,
|
|
9759
|
+
/** The number of preimages introduced by the validator. */
|
|
9760
|
+
preImages,
|
|
9761
|
+
/** The total number of octets across all preimages introduced by the validator. */
|
|
9762
|
+
preImagesSize,
|
|
9763
|
+
/** The number of reports guaranteed by the validator. */
|
|
9764
|
+
guarantees,
|
|
9765
|
+
/** The number of availability assurances made by the validator. */
|
|
9766
|
+
assurances) {
|
|
9767
|
+
this.blocks = blocks;
|
|
9768
|
+
this.tickets = tickets;
|
|
9769
|
+
this.preImages = preImages;
|
|
9770
|
+
this.preImagesSize = preImagesSize;
|
|
9771
|
+
this.guarantees = guarantees;
|
|
9772
|
+
this.assurances = assurances;
|
|
9773
|
+
}
|
|
9774
|
+
static empty() {
|
|
9775
|
+
const zero = numbers_tryAsU32(0);
|
|
9776
|
+
return new ValidatorStatistics(zero, zero, zero, zero, zero, zero);
|
|
9462
9777
|
}
|
|
9463
9778
|
}
|
|
9464
|
-
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9471
|
-
|
|
9779
|
+
const codecVarU16 = descriptors_codec.varU32.convert((i) => numbers_tryAsU32(i), (o) => numbers_tryAsU16(o));
|
|
9780
|
+
/** Encode/decode unsigned gas. */
|
|
9781
|
+
const codecVarGas = descriptors_codec.varU64.convert((g) => tryAsU64(g), (i) => tryAsServiceGas(i));
|
|
9472
9782
|
/**
|
|
9473
|
-
*
|
|
9783
|
+
* Single core statistics.
|
|
9784
|
+
* Updated per block, based on incoming work reports (`w`).
|
|
9474
9785
|
*
|
|
9475
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
9786
|
+
* https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
|
|
9787
|
+
* https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
|
|
9476
9788
|
*/
|
|
9477
|
-
|
|
9478
|
-
|
|
9479
|
-
|
|
9480
|
-
|
|
9481
|
-
|
|
9482
|
-
|
|
9483
|
-
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
|
|
9789
|
+
class CoreStatistics {
|
|
9790
|
+
dataAvailabilityLoad;
|
|
9791
|
+
popularity;
|
|
9792
|
+
imports;
|
|
9793
|
+
exports;
|
|
9794
|
+
extrinsicSize;
|
|
9795
|
+
extrinsicCount;
|
|
9796
|
+
bundleSize;
|
|
9797
|
+
gasUsed;
|
|
9798
|
+
static Codec = Compatibility.isGreaterOrEqual(GpVersion.V0_7_0)
|
|
9799
|
+
? descriptors_codec.Class(CoreStatistics, {
|
|
9800
|
+
dataAvailabilityLoad: descriptors_codec.varU32,
|
|
9801
|
+
popularity: codecVarU16,
|
|
9802
|
+
imports: codecVarU16,
|
|
9803
|
+
extrinsicCount: codecVarU16,
|
|
9804
|
+
extrinsicSize: descriptors_codec.varU32,
|
|
9805
|
+
exports: codecVarU16,
|
|
9806
|
+
bundleSize: descriptors_codec.varU32,
|
|
9807
|
+
gasUsed: codecVarGas,
|
|
9808
|
+
})
|
|
9809
|
+
: descriptors_codec.Class(CoreStatistics, {
|
|
9810
|
+
dataAvailabilityLoad: descriptors_codec.varU32,
|
|
9811
|
+
popularity: codecVarU16,
|
|
9812
|
+
imports: codecVarU16,
|
|
9813
|
+
exports: codecVarU16,
|
|
9814
|
+
extrinsicSize: descriptors_codec.varU32,
|
|
9815
|
+
extrinsicCount: codecVarU16,
|
|
9816
|
+
bundleSize: descriptors_codec.varU32,
|
|
9817
|
+
gasUsed: codecVarGas,
|
|
9818
|
+
});
|
|
9819
|
+
static create(v) {
|
|
9820
|
+
return new CoreStatistics(v.dataAvailabilityLoad, v.popularity, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.bundleSize, v.gasUsed);
|
|
9492
9821
|
}
|
|
9493
9822
|
constructor(
|
|
9494
|
-
/**
|
|
9495
|
-
|
|
9496
|
-
/**
|
|
9497
|
-
|
|
9498
|
-
/**
|
|
9499
|
-
|
|
9500
|
-
/**
|
|
9501
|
-
|
|
9502
|
-
|
|
9503
|
-
|
|
9504
|
-
|
|
9505
|
-
|
|
9506
|
-
|
|
9507
|
-
|
|
9508
|
-
|
|
9509
|
-
|
|
9510
|
-
|
|
9511
|
-
|
|
9512
|
-
|
|
9513
|
-
|
|
9514
|
-
|
|
9515
|
-
|
|
9516
|
-
|
|
9517
|
-
|
|
9518
|
-
accumulationLog: descriptors_codec.object({
|
|
9519
|
-
peaks: readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.optional(descriptors_codec.bytes(hash_HASH_SIZE)))),
|
|
9520
|
-
}),
|
|
9521
|
-
});
|
|
9522
|
-
static create(a) {
|
|
9523
|
-
return new RecentBlocks(a.blocks, a.accumulationLog);
|
|
9823
|
+
/** `d` */
|
|
9824
|
+
dataAvailabilityLoad,
|
|
9825
|
+
/** `p` */
|
|
9826
|
+
popularity,
|
|
9827
|
+
/** `i` */
|
|
9828
|
+
imports,
|
|
9829
|
+
/** `e` */
|
|
9830
|
+
exports,
|
|
9831
|
+
/** `z` */
|
|
9832
|
+
extrinsicSize,
|
|
9833
|
+
/** `x` */
|
|
9834
|
+
extrinsicCount,
|
|
9835
|
+
/** `b` */
|
|
9836
|
+
bundleSize,
|
|
9837
|
+
/** `u` */
|
|
9838
|
+
gasUsed) {
|
|
9839
|
+
this.dataAvailabilityLoad = dataAvailabilityLoad;
|
|
9840
|
+
this.popularity = popularity;
|
|
9841
|
+
this.imports = imports;
|
|
9842
|
+
this.exports = exports;
|
|
9843
|
+
this.extrinsicSize = extrinsicSize;
|
|
9844
|
+
this.extrinsicCount = extrinsicCount;
|
|
9845
|
+
this.bundleSize = bundleSize;
|
|
9846
|
+
this.gasUsed = gasUsed;
|
|
9524
9847
|
}
|
|
9525
|
-
|
|
9526
|
-
|
|
9527
|
-
|
|
9528
|
-
|
|
9529
|
-
|
|
9530
|
-
blocks,
|
|
9531
|
-
/**
|
|
9532
|
-
* Accumulation output log.
|
|
9533
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0f02020f0202?v=0.6.7
|
|
9534
|
-
*/
|
|
9535
|
-
accumulationLog) {
|
|
9536
|
-
super();
|
|
9537
|
-
this.blocks = blocks;
|
|
9538
|
-
this.accumulationLog = accumulationLog;
|
|
9848
|
+
static empty() {
|
|
9849
|
+
const zero = numbers_tryAsU32(0);
|
|
9850
|
+
const zero16 = numbers_tryAsU16(0);
|
|
9851
|
+
const zeroGas = tryAsServiceGas(0);
|
|
9852
|
+
return new CoreStatistics(zero, zero16, zero16, zero16, zero, zero16, zero, zeroGas);
|
|
9539
9853
|
}
|
|
9540
9854
|
}
|
|
9541
9855
|
/**
|
|
9542
|
-
*
|
|
9856
|
+
* Service statistics.
|
|
9857
|
+
* Updated per block, based on available work reports (`W`).
|
|
9543
9858
|
*
|
|
9544
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
9859
|
+
* https://graypaper.fluffylabs.dev/#/1c979cb/199802199802?v=0.7.1
|
|
9545
9860
|
*/
|
|
9546
|
-
class
|
|
9547
|
-
|
|
9548
|
-
|
|
9549
|
-
|
|
9550
|
-
|
|
9551
|
-
|
|
9552
|
-
|
|
9861
|
+
class ServiceStatistics {
|
|
9862
|
+
providedCount;
|
|
9863
|
+
providedSize;
|
|
9864
|
+
refinementCount;
|
|
9865
|
+
refinementGasUsed;
|
|
9866
|
+
imports;
|
|
9867
|
+
exports;
|
|
9868
|
+
extrinsicSize;
|
|
9869
|
+
extrinsicCount;
|
|
9870
|
+
accumulateCount;
|
|
9871
|
+
accumulateGasUsed;
|
|
9872
|
+
onTransfersCount;
|
|
9873
|
+
onTransfersGasUsed;
|
|
9874
|
+
static Codec = Compatibility.selectIfGreaterOrEqual({
|
|
9875
|
+
fallback: descriptors_codec.Class(ServiceStatistics, {
|
|
9876
|
+
providedCount: codecVarU16,
|
|
9877
|
+
providedSize: descriptors_codec.varU32,
|
|
9878
|
+
refinementCount: descriptors_codec.varU32,
|
|
9879
|
+
refinementGasUsed: codecVarGas,
|
|
9880
|
+
imports: codecVarU16,
|
|
9881
|
+
exports: codecVarU16,
|
|
9882
|
+
extrinsicSize: descriptors_codec.varU32,
|
|
9883
|
+
extrinsicCount: codecVarU16,
|
|
9884
|
+
accumulateCount: descriptors_codec.varU32,
|
|
9885
|
+
accumulateGasUsed: codecVarGas,
|
|
9886
|
+
onTransfersCount: descriptors_codec.varU32,
|
|
9887
|
+
onTransfersGasUsed: codecVarGas,
|
|
9888
|
+
}),
|
|
9889
|
+
versions: {
|
|
9890
|
+
[GpVersion.V0_7_0]: descriptors_codec.Class(ServiceStatistics, {
|
|
9891
|
+
providedCount: codecVarU16,
|
|
9892
|
+
providedSize: descriptors_codec.varU32,
|
|
9893
|
+
refinementCount: descriptors_codec.varU32,
|
|
9894
|
+
refinementGasUsed: codecVarGas,
|
|
9895
|
+
imports: codecVarU16,
|
|
9896
|
+
extrinsicCount: codecVarU16,
|
|
9897
|
+
extrinsicSize: descriptors_codec.varU32,
|
|
9898
|
+
exports: codecVarU16,
|
|
9899
|
+
accumulateCount: descriptors_codec.varU32,
|
|
9900
|
+
accumulateGasUsed: codecVarGas,
|
|
9901
|
+
onTransfersCount: descriptors_codec.varU32,
|
|
9902
|
+
onTransfersGasUsed: codecVarGas,
|
|
9903
|
+
}),
|
|
9904
|
+
[GpVersion.V0_7_1]: descriptors_codec.Class(ServiceStatistics, {
|
|
9905
|
+
providedCount: codecVarU16,
|
|
9906
|
+
providedSize: descriptors_codec.varU32,
|
|
9907
|
+
refinementCount: descriptors_codec.varU32,
|
|
9908
|
+
refinementGasUsed: codecVarGas,
|
|
9909
|
+
imports: codecVarU16,
|
|
9910
|
+
extrinsicCount: codecVarU16,
|
|
9911
|
+
extrinsicSize: descriptors_codec.varU32,
|
|
9912
|
+
exports: codecVarU16,
|
|
9913
|
+
accumulateCount: descriptors_codec.varU32,
|
|
9914
|
+
accumulateGasUsed: codecVarGas,
|
|
9915
|
+
onTransfersCount: ignoreValueWithDefault(numbers_tryAsU32(0)),
|
|
9916
|
+
onTransfersGasUsed: ignoreValueWithDefault(tryAsServiceGas(0)),
|
|
9917
|
+
}),
|
|
9918
|
+
},
|
|
9553
9919
|
});
|
|
9554
|
-
static create(
|
|
9555
|
-
return new
|
|
9920
|
+
static create(v) {
|
|
9921
|
+
return new ServiceStatistics(v.providedCount, v.providedSize, v.refinementCount, v.refinementGasUsed, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.accumulateCount, v.accumulateGasUsed, v.onTransfersCount, v.onTransfersGasUsed);
|
|
9922
|
+
}
|
|
9923
|
+
constructor(
|
|
9924
|
+
/** `p.0` */
|
|
9925
|
+
providedCount,
|
|
9926
|
+
/** `p.1` */
|
|
9927
|
+
providedSize,
|
|
9928
|
+
/** `r.0` */
|
|
9929
|
+
refinementCount,
|
|
9930
|
+
/** `r.1` */
|
|
9931
|
+
refinementGasUsed,
|
|
9932
|
+
/** `i` */
|
|
9933
|
+
imports,
|
|
9934
|
+
/** `e` */
|
|
9935
|
+
exports,
|
|
9936
|
+
/** `z` */
|
|
9937
|
+
extrinsicSize,
|
|
9938
|
+
/** `x` */
|
|
9939
|
+
extrinsicCount,
|
|
9940
|
+
/** `a.0` */
|
|
9941
|
+
accumulateCount,
|
|
9942
|
+
/** `a.1` */
|
|
9943
|
+
accumulateGasUsed,
|
|
9944
|
+
/** `t.0` @deprecated since 0.7.1 */
|
|
9945
|
+
onTransfersCount,
|
|
9946
|
+
/** `t.1` @deprecated since 0.7.1 */
|
|
9947
|
+
onTransfersGasUsed) {
|
|
9948
|
+
this.providedCount = providedCount;
|
|
9949
|
+
this.providedSize = providedSize;
|
|
9950
|
+
this.refinementCount = refinementCount;
|
|
9951
|
+
this.refinementGasUsed = refinementGasUsed;
|
|
9952
|
+
this.imports = imports;
|
|
9953
|
+
this.exports = exports;
|
|
9954
|
+
this.extrinsicSize = extrinsicSize;
|
|
9955
|
+
this.extrinsicCount = extrinsicCount;
|
|
9956
|
+
this.accumulateCount = accumulateCount;
|
|
9957
|
+
this.accumulateGasUsed = accumulateGasUsed;
|
|
9958
|
+
this.onTransfersCount = onTransfersCount;
|
|
9959
|
+
this.onTransfersGasUsed = onTransfersGasUsed;
|
|
9556
9960
|
}
|
|
9557
9961
|
static empty() {
|
|
9558
|
-
|
|
9559
|
-
|
|
9560
|
-
|
|
9561
|
-
|
|
9962
|
+
const zero = numbers_tryAsU32(0);
|
|
9963
|
+
const zero16 = numbers_tryAsU16(0);
|
|
9964
|
+
const zeroGas = tryAsServiceGas(0);
|
|
9965
|
+
return new ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
|
|
9562
9966
|
}
|
|
9563
|
-
|
|
9564
|
-
|
|
9565
|
-
|
|
9566
|
-
|
|
9567
|
-
|
|
9967
|
+
}
|
|
9968
|
+
/** `pi`: Statistics of each validator, cores statistics and services statistics. */
|
|
9969
|
+
class StatisticsData {
|
|
9970
|
+
current;
|
|
9971
|
+
previous;
|
|
9972
|
+
cores;
|
|
9973
|
+
services;
|
|
9974
|
+
static Codec = descriptors_codec.Class(StatisticsData, {
|
|
9975
|
+
current: common_codecPerValidator(ValidatorStatistics.Codec),
|
|
9976
|
+
previous: common_codecPerValidator(ValidatorStatistics.Codec),
|
|
9977
|
+
cores: codecPerCore(CoreStatistics.Codec),
|
|
9978
|
+
services: descriptors_codec.dictionary(codecServiceId, ServiceStatistics.Codec, {
|
|
9979
|
+
sortKeys: (a, b) => a - b,
|
|
9980
|
+
}),
|
|
9981
|
+
});
|
|
9982
|
+
static create(v) {
|
|
9983
|
+
return new StatisticsData(v.current, v.previous, v.cores, v.services);
|
|
9568
9984
|
}
|
|
9569
|
-
constructor(current) {
|
|
9570
|
-
super();
|
|
9985
|
+
constructor(current, previous, cores, services) {
|
|
9571
9986
|
this.current = current;
|
|
9572
|
-
|
|
9573
|
-
|
|
9574
|
-
|
|
9575
|
-
if (this.current !== null) {
|
|
9576
|
-
return this.current.blocks;
|
|
9577
|
-
}
|
|
9578
|
-
throw new Error("RecentBlocksHistory is in invalid state");
|
|
9579
|
-
}
|
|
9580
|
-
asCurrent() {
|
|
9581
|
-
if (this.current === null) {
|
|
9582
|
-
throw new Error("Cannot access current RecentBlocks format");
|
|
9583
|
-
}
|
|
9584
|
-
return this.current;
|
|
9585
|
-
}
|
|
9586
|
-
updateBlocks(blocks) {
|
|
9587
|
-
if (this.current !== null) {
|
|
9588
|
-
return RecentBlocksHistory.create(RecentBlocks.create({
|
|
9589
|
-
...this.current,
|
|
9590
|
-
blocks: opaque_asOpaqueType(blocks),
|
|
9591
|
-
}));
|
|
9592
|
-
}
|
|
9593
|
-
throw new Error("RecentBlocksHistory is in invalid state. Cannot be updated!");
|
|
9987
|
+
this.previous = previous;
|
|
9988
|
+
this.cores = cores;
|
|
9989
|
+
this.services = services;
|
|
9594
9990
|
}
|
|
9595
9991
|
}
|
|
9596
9992
|
|
|
9597
|
-
;// CONCATENATED MODULE: ./packages/jam/state/
|
|
9993
|
+
;// CONCATENATED MODULE: ./packages/jam/state/in-memory-state-view.ts
|
|
9598
9994
|
|
|
9599
9995
|
|
|
9600
9996
|
|
|
9601
|
-
/**
|
|
9602
|
-
* Fixed size of validator metadata.
|
|
9603
|
-
*
|
|
9604
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/0d55010d5501
|
|
9605
|
-
*/
|
|
9606
|
-
const VALIDATOR_META_BYTES = 128;
|
|
9607
|
-
/**
|
|
9608
|
-
* Details about validators' identity.
|
|
9609
|
-
*
|
|
9610
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/0d4b010d4c01
|
|
9611
|
-
*/
|
|
9612
|
-
class ValidatorData extends WithDebug {
|
|
9613
|
-
bandersnatch;
|
|
9614
|
-
ed25519;
|
|
9615
|
-
bls;
|
|
9616
|
-
metadata;
|
|
9617
|
-
static Codec = descriptors_codec.Class(ValidatorData, {
|
|
9618
|
-
bandersnatch: descriptors_codec.bytes(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
9619
|
-
ed25519: descriptors_codec.bytes(ED25519_KEY_BYTES).asOpaque(),
|
|
9620
|
-
bls: descriptors_codec.bytes(BLS_KEY_BYTES).asOpaque(),
|
|
9621
|
-
metadata: descriptors_codec.bytes(VALIDATOR_META_BYTES),
|
|
9622
|
-
});
|
|
9623
|
-
static create({ ed25519, bandersnatch, bls, metadata }) {
|
|
9624
|
-
return new ValidatorData(bandersnatch, ed25519, bls, metadata);
|
|
9625
|
-
}
|
|
9626
|
-
constructor(
|
|
9627
|
-
/** Bandersnatch public key. */
|
|
9628
|
-
bandersnatch,
|
|
9629
|
-
/** ED25519 key data. */
|
|
9630
|
-
ed25519,
|
|
9631
|
-
/** BLS public key. */
|
|
9632
|
-
bls,
|
|
9633
|
-
/** Validator-defined additional metdata. */
|
|
9634
|
-
metadata) {
|
|
9635
|
-
super();
|
|
9636
|
-
this.bandersnatch = bandersnatch;
|
|
9637
|
-
this.ed25519 = ed25519;
|
|
9638
|
-
this.bls = bls;
|
|
9639
|
-
this.metadata = metadata;
|
|
9640
|
-
}
|
|
9641
|
-
}
|
|
9642
9997
|
|
|
9643
|
-
;// CONCATENATED MODULE: ./packages/jam/state/safrole-data.ts
|
|
9644
9998
|
|
|
9645
9999
|
|
|
9646
10000
|
|
|
9647
10001
|
|
|
9648
10002
|
|
|
9649
10003
|
|
|
10004
|
+
class InMemoryStateView {
|
|
10005
|
+
chainSpec;
|
|
10006
|
+
state;
|
|
10007
|
+
constructor(chainSpec, state) {
|
|
10008
|
+
this.chainSpec = chainSpec;
|
|
10009
|
+
this.state = state;
|
|
10010
|
+
}
|
|
10011
|
+
availabilityAssignmentView() {
|
|
10012
|
+
return reencodeAsView(availabilityAssignmentsCodec, this.state.availabilityAssignment, this.chainSpec);
|
|
10013
|
+
}
|
|
10014
|
+
designatedValidatorDataView() {
|
|
10015
|
+
return reencodeAsView(validatorsDataCodec, this.state.designatedValidatorData, this.chainSpec);
|
|
10016
|
+
}
|
|
10017
|
+
currentValidatorDataView() {
|
|
10018
|
+
return reencodeAsView(validatorsDataCodec, this.state.currentValidatorData, this.chainSpec);
|
|
10019
|
+
}
|
|
10020
|
+
previousValidatorDataView() {
|
|
10021
|
+
return reencodeAsView(validatorsDataCodec, this.state.previousValidatorData, this.chainSpec);
|
|
10022
|
+
}
|
|
10023
|
+
authPoolsView() {
|
|
10024
|
+
return reencodeAsView(authPoolsCodec, this.state.authPools, this.chainSpec);
|
|
10025
|
+
}
|
|
10026
|
+
authQueuesView() {
|
|
10027
|
+
return reencodeAsView(authQueuesCodec, this.state.authQueues, this.chainSpec);
|
|
10028
|
+
}
|
|
10029
|
+
recentBlocksView() {
|
|
10030
|
+
return reencodeAsView(RecentBlocks.Codec, this.state.recentBlocks, this.chainSpec);
|
|
10031
|
+
}
|
|
10032
|
+
statisticsView() {
|
|
10033
|
+
return reencodeAsView(StatisticsData.Codec, this.state.statistics, this.chainSpec);
|
|
10034
|
+
}
|
|
10035
|
+
accumulationQueueView() {
|
|
10036
|
+
return reencodeAsView(accumulationQueueCodec, this.state.accumulationQueue, this.chainSpec);
|
|
10037
|
+
}
|
|
10038
|
+
recentlyAccumulatedView() {
|
|
10039
|
+
return reencodeAsView(recentlyAccumulatedCodec, this.state.recentlyAccumulated, this.chainSpec);
|
|
10040
|
+
}
|
|
10041
|
+
safroleDataView() {
|
|
10042
|
+
// TODO [ToDr] Consider exposting `safrole` from state
|
|
10043
|
+
// instead of individual fields
|
|
10044
|
+
const safrole = SafroleData.create({
|
|
10045
|
+
nextValidatorData: this.state.nextValidatorData,
|
|
10046
|
+
epochRoot: this.state.epochRoot,
|
|
10047
|
+
sealingKeySeries: this.state.sealingKeySeries,
|
|
10048
|
+
ticketsAccumulator: this.state.ticketsAccumulator,
|
|
10049
|
+
});
|
|
10050
|
+
return reencodeAsView(SafroleData.Codec, safrole, this.chainSpec);
|
|
10051
|
+
}
|
|
10052
|
+
getServiceInfoView(id) {
|
|
10053
|
+
const service = this.state.getService(id);
|
|
10054
|
+
if (service === null) {
|
|
10055
|
+
return null;
|
|
10056
|
+
}
|
|
10057
|
+
return reencodeAsView(ServiceAccountInfo.Codec, service.getInfo(), this.chainSpec);
|
|
10058
|
+
}
|
|
10059
|
+
}
|
|
9650
10060
|
|
|
10061
|
+
;// CONCATENATED MODULE: ./packages/jam/state/privileged-services.ts
|
|
9651
10062
|
|
|
9652
10063
|
|
|
9653
10064
|
|
|
9654
10065
|
|
|
9655
|
-
|
|
9656
|
-
|
|
9657
|
-
|
|
9658
|
-
|
|
9659
|
-
|
|
9660
|
-
|
|
9661
|
-
|
|
9662
|
-
|
|
9663
|
-
keys;
|
|
9664
|
-
tickets;
|
|
9665
|
-
static Codec = codecWithContext((context) => {
|
|
9666
|
-
return descriptors_codec.custom({
|
|
9667
|
-
name: "SafroleSealingKeys",
|
|
9668
|
-
sizeHint: { bytes: 1 + hash_HASH_SIZE * context.epochLength, isExact: false },
|
|
9669
|
-
}, (e, x) => {
|
|
9670
|
-
e.varU32(numbers_tryAsU32(x.kind));
|
|
9671
|
-
if (x.kind === SafroleSealingKeysKind.Keys) {
|
|
9672
|
-
e.sequenceFixLen(codecBandersnatchKey, x.keys);
|
|
9673
|
-
}
|
|
9674
|
-
else {
|
|
9675
|
-
e.sequenceFixLen(Ticket.Codec, x.tickets);
|
|
9676
|
-
}
|
|
9677
|
-
}, (d) => {
|
|
9678
|
-
const epochLength = context.epochLength;
|
|
9679
|
-
const kind = d.varU32();
|
|
9680
|
-
if (kind === SafroleSealingKeysKind.Keys) {
|
|
9681
|
-
const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
|
|
9682
|
-
return SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
|
|
9683
|
-
}
|
|
9684
|
-
if (kind === SafroleSealingKeysKind.Tickets) {
|
|
9685
|
-
const tickets = d.sequenceFixLen(Ticket.Codec, epochLength);
|
|
9686
|
-
return SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
|
|
9687
|
-
}
|
|
9688
|
-
throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
|
|
9689
|
-
}, (s) => {
|
|
9690
|
-
const kind = s.decoder.varU32();
|
|
9691
|
-
if (kind === SafroleSealingKeysKind.Keys) {
|
|
9692
|
-
s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
|
|
9693
|
-
return;
|
|
9694
|
-
}
|
|
9695
|
-
if (kind === SafroleSealingKeysKind.Tickets) {
|
|
9696
|
-
s.sequenceFixLen(Ticket.Codec, context.epochLength);
|
|
9697
|
-
return;
|
|
9698
|
-
}
|
|
9699
|
-
throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
|
|
9700
|
-
});
|
|
10066
|
+
|
|
10067
|
+
/** Dictionary entry of services that auto-accumulate every block. */
|
|
10068
|
+
class AutoAccumulate {
|
|
10069
|
+
service;
|
|
10070
|
+
gasLimit;
|
|
10071
|
+
static Codec = descriptors_codec.Class(AutoAccumulate, {
|
|
10072
|
+
service: descriptors_codec.u32.asOpaque(),
|
|
10073
|
+
gasLimit: descriptors_codec.u64.asOpaque(),
|
|
9701
10074
|
});
|
|
9702
|
-
static
|
|
9703
|
-
return new
|
|
9704
|
-
}
|
|
9705
|
-
static tickets(tickets) {
|
|
9706
|
-
return new SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
|
|
10075
|
+
static create({ service, gasLimit }) {
|
|
10076
|
+
return new AutoAccumulate(service, gasLimit);
|
|
9707
10077
|
}
|
|
9708
|
-
constructor(
|
|
9709
|
-
|
|
9710
|
-
|
|
9711
|
-
|
|
9712
|
-
|
|
10078
|
+
constructor(
|
|
10079
|
+
/** Service id that auto-accumulates. */
|
|
10080
|
+
service,
|
|
10081
|
+
/** Gas limit for auto-accumulation. */
|
|
10082
|
+
gasLimit) {
|
|
10083
|
+
this.service = service;
|
|
10084
|
+
this.gasLimit = gasLimit;
|
|
9713
10085
|
}
|
|
9714
10086
|
}
|
|
9715
|
-
|
|
9716
|
-
|
|
9717
|
-
|
|
9718
|
-
|
|
9719
|
-
|
|
9720
|
-
|
|
9721
|
-
|
|
9722
|
-
|
|
9723
|
-
|
|
9724
|
-
|
|
10087
|
+
/**
|
|
10088
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
|
|
10089
|
+
*/
|
|
10090
|
+
class PrivilegedServices {
|
|
10091
|
+
manager;
|
|
10092
|
+
delegator;
|
|
10093
|
+
registrar;
|
|
10094
|
+
assigners;
|
|
10095
|
+
autoAccumulateServices;
|
|
10096
|
+
/** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
|
|
10097
|
+
static Codec = descriptors_codec.Class(PrivilegedServices, {
|
|
10098
|
+
manager: descriptors_codec.u32.asOpaque(),
|
|
10099
|
+
assigners: codecPerCore(descriptors_codec.u32.asOpaque()),
|
|
10100
|
+
delegator: descriptors_codec.u32.asOpaque(),
|
|
10101
|
+
registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
10102
|
+
? descriptors_codec.u32.asOpaque()
|
|
10103
|
+
: ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
|
|
10104
|
+
autoAccumulateServices: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(AutoAccumulate.Codec)),
|
|
9725
10105
|
});
|
|
9726
|
-
static create(
|
|
9727
|
-
return new
|
|
10106
|
+
static create(a) {
|
|
10107
|
+
return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
9728
10108
|
}
|
|
9729
10109
|
constructor(
|
|
9730
|
-
/**
|
|
9731
|
-
|
|
9732
|
-
|
|
9733
|
-
|
|
9734
|
-
|
|
9735
|
-
|
|
9736
|
-
/**
|
|
9737
|
-
|
|
9738
|
-
|
|
9739
|
-
|
|
9740
|
-
|
|
9741
|
-
|
|
10110
|
+
/**
|
|
10111
|
+
* `χ_M`: Manages alteration of χ from block to block,
|
|
10112
|
+
* as well as bestow services with storage deposit credits.
|
|
10113
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
10114
|
+
*/
|
|
10115
|
+
manager,
|
|
10116
|
+
/** `χ_V`: Managers validator keys. */
|
|
10117
|
+
delegator,
|
|
10118
|
+
/**
|
|
10119
|
+
* `χ_R`: Manages the creation of services in protected range.
|
|
10120
|
+
*
|
|
10121
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
|
|
10122
|
+
*/
|
|
10123
|
+
registrar,
|
|
10124
|
+
/** `χ_A`: Manages authorization queue one for each core. */
|
|
10125
|
+
assigners,
|
|
10126
|
+
/** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
|
|
10127
|
+
autoAccumulateServices) {
|
|
10128
|
+
this.manager = manager;
|
|
10129
|
+
this.delegator = delegator;
|
|
10130
|
+
this.registrar = registrar;
|
|
10131
|
+
this.assigners = assigners;
|
|
10132
|
+
this.autoAccumulateServices = autoAccumulateServices;
|
|
9742
10133
|
}
|
|
9743
10134
|
}
|
|
9744
10135
|
|
|
@@ -9839,322 +10230,67 @@ var UpdateServiceKind;
|
|
|
9839
10230
|
/** Create a new `Service` instance. */
|
|
9840
10231
|
UpdateServiceKind[UpdateServiceKind["Create"] = 1] = "Create";
|
|
9841
10232
|
})(UpdateServiceKind || (UpdateServiceKind = {}));
|
|
9842
|
-
/**
|
|
9843
|
-
* Update service info of a particular `ServiceId` or create a new one.
|
|
9844
|
-
*/
|
|
9845
|
-
class UpdateService {
|
|
9846
|
-
serviceId;
|
|
9847
|
-
action;
|
|
9848
|
-
constructor(serviceId, action) {
|
|
9849
|
-
this.serviceId = serviceId;
|
|
9850
|
-
this.action = action;
|
|
9851
|
-
}
|
|
9852
|
-
static update({ serviceId, serviceInfo }) {
|
|
9853
|
-
return new UpdateService(serviceId, {
|
|
9854
|
-
kind: UpdateServiceKind.Update,
|
|
9855
|
-
account: serviceInfo,
|
|
9856
|
-
});
|
|
9857
|
-
}
|
|
9858
|
-
static create({ serviceId, serviceInfo, lookupHistory, }) {
|
|
9859
|
-
return new UpdateService(serviceId, {
|
|
9860
|
-
kind: UpdateServiceKind.Create,
|
|
9861
|
-
account: serviceInfo,
|
|
9862
|
-
lookupHistory,
|
|
9863
|
-
});
|
|
9864
|
-
}
|
|
9865
|
-
}
|
|
9866
|
-
/** Update service storage kind. */
|
|
9867
|
-
var UpdateStorageKind;
|
|
9868
|
-
(function (UpdateStorageKind) {
|
|
9869
|
-
/** Set a storage value. */
|
|
9870
|
-
UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
|
|
9871
|
-
/** Remove a storage value. */
|
|
9872
|
-
UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
|
|
9873
|
-
})(UpdateStorageKind || (UpdateStorageKind = {}));
|
|
9874
|
-
/**
|
|
9875
|
-
* Update service storage item.
|
|
9876
|
-
*
|
|
9877
|
-
* Can either create/modify an entry or remove it.
|
|
9878
|
-
*/
|
|
9879
|
-
class UpdateStorage {
|
|
9880
|
-
serviceId;
|
|
9881
|
-
action;
|
|
9882
|
-
constructor(serviceId, action) {
|
|
9883
|
-
this.serviceId = serviceId;
|
|
9884
|
-
this.action = action;
|
|
9885
|
-
}
|
|
9886
|
-
static set({ serviceId, storage }) {
|
|
9887
|
-
return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Set, storage });
|
|
9888
|
-
}
|
|
9889
|
-
static remove({ serviceId, key }) {
|
|
9890
|
-
return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Remove, key });
|
|
9891
|
-
}
|
|
9892
|
-
get key() {
|
|
9893
|
-
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
9894
|
-
return this.action.key;
|
|
9895
|
-
}
|
|
9896
|
-
return this.action.storage.key;
|
|
9897
|
-
}
|
|
9898
|
-
get value() {
|
|
9899
|
-
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
9900
|
-
return null;
|
|
9901
|
-
}
|
|
9902
|
-
return this.action.storage.value;
|
|
9903
|
-
}
|
|
9904
|
-
}
|
|
9905
|
-
|
|
9906
|
-
;// CONCATENATED MODULE: ./packages/jam/state/statistics.ts
|
|
9907
|
-
|
|
9908
|
-
|
|
9909
|
-
|
|
9910
|
-
|
|
9911
|
-
|
|
9912
|
-
const codecServiceId = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
|
|
9913
|
-
? descriptors_codec.u32.asOpaque()
|
|
9914
|
-
: descriptors_codec.varU32.convert((s) => numbers_tryAsU32(s), (i) => tryAsServiceId(i));
|
|
9915
|
-
/**
|
|
9916
|
-
* Activity Record of a single validator.
|
|
9917
|
-
*
|
|
9918
|
-
* https://graypaper.fluffylabs.dev/#/579bd12/183701183701
|
|
9919
|
-
*/
|
|
9920
|
-
class ValidatorStatistics {
|
|
9921
|
-
blocks;
|
|
9922
|
-
tickets;
|
|
9923
|
-
preImages;
|
|
9924
|
-
preImagesSize;
|
|
9925
|
-
guarantees;
|
|
9926
|
-
assurances;
|
|
9927
|
-
static Codec = descriptors_codec.Class(ValidatorStatistics, {
|
|
9928
|
-
blocks: descriptors_codec.u32,
|
|
9929
|
-
tickets: descriptors_codec.u32,
|
|
9930
|
-
preImages: descriptors_codec.u32,
|
|
9931
|
-
preImagesSize: descriptors_codec.u32,
|
|
9932
|
-
guarantees: descriptors_codec.u32,
|
|
9933
|
-
assurances: descriptors_codec.u32,
|
|
9934
|
-
});
|
|
9935
|
-
static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
|
|
9936
|
-
return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
|
|
9937
|
-
}
|
|
9938
|
-
constructor(
|
|
9939
|
-
/** The number of blocks produced by the validator. */
|
|
9940
|
-
blocks,
|
|
9941
|
-
/** The number of tickets introduced by the validator. */
|
|
9942
|
-
tickets,
|
|
9943
|
-
/** The number of preimages introduced by the validator. */
|
|
9944
|
-
preImages,
|
|
9945
|
-
/** The total number of octets across all preimages introduced by the validator. */
|
|
9946
|
-
preImagesSize,
|
|
9947
|
-
/** The number of reports guaranteed by the validator. */
|
|
9948
|
-
guarantees,
|
|
9949
|
-
/** The number of availability assurances made by the validator. */
|
|
9950
|
-
assurances) {
|
|
9951
|
-
this.blocks = blocks;
|
|
9952
|
-
this.tickets = tickets;
|
|
9953
|
-
this.preImages = preImages;
|
|
9954
|
-
this.preImagesSize = preImagesSize;
|
|
9955
|
-
this.guarantees = guarantees;
|
|
9956
|
-
this.assurances = assurances;
|
|
9957
|
-
}
|
|
9958
|
-
static empty() {
|
|
9959
|
-
const zero = numbers_tryAsU32(0);
|
|
9960
|
-
return new ValidatorStatistics(zero, zero, zero, zero, zero, zero);
|
|
9961
|
-
}
|
|
9962
|
-
}
|
|
9963
|
-
const codecVarU16 = descriptors_codec.varU32.convert((i) => numbers_tryAsU32(i), (o) => numbers_tryAsU16(o));
|
|
9964
|
-
/** Encode/decode unsigned gas. */
|
|
9965
|
-
const codecVarGas = descriptors_codec.varU64.convert((g) => tryAsU64(g), (i) => tryAsServiceGas(i));
|
|
9966
|
-
/**
|
|
9967
|
-
* Single core statistics.
|
|
9968
|
-
* Updated per block, based on incoming work reports (`w`).
|
|
9969
|
-
*
|
|
9970
|
-
* https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
|
|
9971
|
-
* https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
|
|
9972
|
-
*/
|
|
9973
|
-
class CoreStatistics {
|
|
9974
|
-
dataAvailabilityLoad;
|
|
9975
|
-
popularity;
|
|
9976
|
-
imports;
|
|
9977
|
-
exports;
|
|
9978
|
-
extrinsicSize;
|
|
9979
|
-
extrinsicCount;
|
|
9980
|
-
bundleSize;
|
|
9981
|
-
gasUsed;
|
|
9982
|
-
static Codec = Compatibility.isGreaterOrEqual(GpVersion.V0_7_0)
|
|
9983
|
-
? descriptors_codec.Class(CoreStatistics, {
|
|
9984
|
-
dataAvailabilityLoad: descriptors_codec.varU32,
|
|
9985
|
-
popularity: codecVarU16,
|
|
9986
|
-
imports: codecVarU16,
|
|
9987
|
-
extrinsicCount: codecVarU16,
|
|
9988
|
-
extrinsicSize: descriptors_codec.varU32,
|
|
9989
|
-
exports: codecVarU16,
|
|
9990
|
-
bundleSize: descriptors_codec.varU32,
|
|
9991
|
-
gasUsed: codecVarGas,
|
|
9992
|
-
})
|
|
9993
|
-
: descriptors_codec.Class(CoreStatistics, {
|
|
9994
|
-
dataAvailabilityLoad: descriptors_codec.varU32,
|
|
9995
|
-
popularity: codecVarU16,
|
|
9996
|
-
imports: codecVarU16,
|
|
9997
|
-
exports: codecVarU16,
|
|
9998
|
-
extrinsicSize: descriptors_codec.varU32,
|
|
9999
|
-
extrinsicCount: codecVarU16,
|
|
10000
|
-
bundleSize: descriptors_codec.varU32,
|
|
10001
|
-
gasUsed: codecVarGas,
|
|
10002
|
-
});
|
|
10003
|
-
static create(v) {
|
|
10004
|
-
return new CoreStatistics(v.dataAvailabilityLoad, v.popularity, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.bundleSize, v.gasUsed);
|
|
10005
|
-
}
|
|
10006
|
-
constructor(
|
|
10007
|
-
/** `d` */
|
|
10008
|
-
dataAvailabilityLoad,
|
|
10009
|
-
/** `p` */
|
|
10010
|
-
popularity,
|
|
10011
|
-
/** `i` */
|
|
10012
|
-
imports,
|
|
10013
|
-
/** `e` */
|
|
10014
|
-
exports,
|
|
10015
|
-
/** `z` */
|
|
10016
|
-
extrinsicSize,
|
|
10017
|
-
/** `x` */
|
|
10018
|
-
extrinsicCount,
|
|
10019
|
-
/** `b` */
|
|
10020
|
-
bundleSize,
|
|
10021
|
-
/** `u` */
|
|
10022
|
-
gasUsed) {
|
|
10023
|
-
this.dataAvailabilityLoad = dataAvailabilityLoad;
|
|
10024
|
-
this.popularity = popularity;
|
|
10025
|
-
this.imports = imports;
|
|
10026
|
-
this.exports = exports;
|
|
10027
|
-
this.extrinsicSize = extrinsicSize;
|
|
10028
|
-
this.extrinsicCount = extrinsicCount;
|
|
10029
|
-
this.bundleSize = bundleSize;
|
|
10030
|
-
this.gasUsed = gasUsed;
|
|
10233
|
+
/**
|
|
10234
|
+
* Update service info of a particular `ServiceId` or create a new one.
|
|
10235
|
+
*/
|
|
10236
|
+
class UpdateService {
|
|
10237
|
+
serviceId;
|
|
10238
|
+
action;
|
|
10239
|
+
constructor(serviceId, action) {
|
|
10240
|
+
this.serviceId = serviceId;
|
|
10241
|
+
this.action = action;
|
|
10031
10242
|
}
|
|
10032
|
-
static
|
|
10033
|
-
|
|
10034
|
-
|
|
10035
|
-
|
|
10036
|
-
|
|
10243
|
+
static update({ serviceId, serviceInfo }) {
|
|
10244
|
+
return new UpdateService(serviceId, {
|
|
10245
|
+
kind: UpdateServiceKind.Update,
|
|
10246
|
+
account: serviceInfo,
|
|
10247
|
+
});
|
|
10248
|
+
}
|
|
10249
|
+
static create({ serviceId, serviceInfo, lookupHistory, }) {
|
|
10250
|
+
return new UpdateService(serviceId, {
|
|
10251
|
+
kind: UpdateServiceKind.Create,
|
|
10252
|
+
account: serviceInfo,
|
|
10253
|
+
lookupHistory,
|
|
10254
|
+
});
|
|
10037
10255
|
}
|
|
10038
10256
|
}
|
|
10257
|
+
/** Update service storage kind. */
|
|
10258
|
+
var UpdateStorageKind;
|
|
10259
|
+
(function (UpdateStorageKind) {
|
|
10260
|
+
/** Set a storage value. */
|
|
10261
|
+
UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
|
|
10262
|
+
/** Remove a storage value. */
|
|
10263
|
+
UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
|
|
10264
|
+
})(UpdateStorageKind || (UpdateStorageKind = {}));
|
|
10039
10265
|
/**
|
|
10040
|
-
*
|
|
10041
|
-
* Updated per block, based on available work reports (`W`).
|
|
10266
|
+
* Update service storage item.
|
|
10042
10267
|
*
|
|
10043
|
-
*
|
|
10044
|
-
* https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L77
|
|
10268
|
+
* Can either create/modify an entry or remove it.
|
|
10045
10269
|
*/
|
|
10046
|
-
class
|
|
10047
|
-
|
|
10048
|
-
|
|
10049
|
-
|
|
10050
|
-
|
|
10051
|
-
|
|
10052
|
-
exports;
|
|
10053
|
-
extrinsicSize;
|
|
10054
|
-
extrinsicCount;
|
|
10055
|
-
accumulateCount;
|
|
10056
|
-
accumulateGasUsed;
|
|
10057
|
-
onTransfersCount;
|
|
10058
|
-
onTransfersGasUsed;
|
|
10059
|
-
static Codec = Compatibility.isGreaterOrEqual(GpVersion.V0_7_0)
|
|
10060
|
-
? descriptors_codec.Class(ServiceStatistics, {
|
|
10061
|
-
providedCount: codecVarU16,
|
|
10062
|
-
providedSize: descriptors_codec.varU32,
|
|
10063
|
-
refinementCount: descriptors_codec.varU32,
|
|
10064
|
-
refinementGasUsed: codecVarGas,
|
|
10065
|
-
imports: codecVarU16,
|
|
10066
|
-
extrinsicCount: codecVarU16,
|
|
10067
|
-
extrinsicSize: descriptors_codec.varU32,
|
|
10068
|
-
exports: codecVarU16,
|
|
10069
|
-
accumulateCount: descriptors_codec.varU32,
|
|
10070
|
-
accumulateGasUsed: codecVarGas,
|
|
10071
|
-
onTransfersCount: descriptors_codec.varU32,
|
|
10072
|
-
onTransfersGasUsed: codecVarGas,
|
|
10073
|
-
})
|
|
10074
|
-
: descriptors_codec.Class(ServiceStatistics, {
|
|
10075
|
-
providedCount: codecVarU16,
|
|
10076
|
-
providedSize: descriptors_codec.varU32,
|
|
10077
|
-
refinementCount: descriptors_codec.varU32,
|
|
10078
|
-
refinementGasUsed: codecVarGas,
|
|
10079
|
-
imports: codecVarU16,
|
|
10080
|
-
exports: codecVarU16,
|
|
10081
|
-
extrinsicSize: descriptors_codec.varU32,
|
|
10082
|
-
extrinsicCount: codecVarU16,
|
|
10083
|
-
accumulateCount: descriptors_codec.varU32,
|
|
10084
|
-
accumulateGasUsed: codecVarGas,
|
|
10085
|
-
onTransfersCount: descriptors_codec.varU32,
|
|
10086
|
-
onTransfersGasUsed: codecVarGas,
|
|
10087
|
-
});
|
|
10088
|
-
static create(v) {
|
|
10089
|
-
return new ServiceStatistics(v.providedCount, v.providedSize, v.refinementCount, v.refinementGasUsed, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.accumulateCount, v.accumulateGasUsed, v.onTransfersCount, v.onTransfersGasUsed);
|
|
10270
|
+
class UpdateStorage {
|
|
10271
|
+
serviceId;
|
|
10272
|
+
action;
|
|
10273
|
+
constructor(serviceId, action) {
|
|
10274
|
+
this.serviceId = serviceId;
|
|
10275
|
+
this.action = action;
|
|
10090
10276
|
}
|
|
10091
|
-
|
|
10092
|
-
|
|
10093
|
-
providedCount,
|
|
10094
|
-
/** `p.1` */
|
|
10095
|
-
providedSize,
|
|
10096
|
-
/** `r.0` */
|
|
10097
|
-
refinementCount,
|
|
10098
|
-
/** `r.1` */
|
|
10099
|
-
refinementGasUsed,
|
|
10100
|
-
/** `i` */
|
|
10101
|
-
imports,
|
|
10102
|
-
/** `e` */
|
|
10103
|
-
exports,
|
|
10104
|
-
/** `z` */
|
|
10105
|
-
extrinsicSize,
|
|
10106
|
-
/** `x` */
|
|
10107
|
-
extrinsicCount,
|
|
10108
|
-
/** `a.0` */
|
|
10109
|
-
accumulateCount,
|
|
10110
|
-
/** `a.1` */
|
|
10111
|
-
accumulateGasUsed,
|
|
10112
|
-
/** `t.0` */
|
|
10113
|
-
onTransfersCount,
|
|
10114
|
-
/** `t.1` */
|
|
10115
|
-
onTransfersGasUsed) {
|
|
10116
|
-
this.providedCount = providedCount;
|
|
10117
|
-
this.providedSize = providedSize;
|
|
10118
|
-
this.refinementCount = refinementCount;
|
|
10119
|
-
this.refinementGasUsed = refinementGasUsed;
|
|
10120
|
-
this.imports = imports;
|
|
10121
|
-
this.exports = exports;
|
|
10122
|
-
this.extrinsicSize = extrinsicSize;
|
|
10123
|
-
this.extrinsicCount = extrinsicCount;
|
|
10124
|
-
this.accumulateCount = accumulateCount;
|
|
10125
|
-
this.accumulateGasUsed = accumulateGasUsed;
|
|
10126
|
-
this.onTransfersCount = onTransfersCount;
|
|
10127
|
-
this.onTransfersGasUsed = onTransfersGasUsed;
|
|
10277
|
+
static set({ serviceId, storage }) {
|
|
10278
|
+
return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Set, storage });
|
|
10128
10279
|
}
|
|
10129
|
-
static
|
|
10130
|
-
|
|
10131
|
-
const zero16 = numbers_tryAsU16(0);
|
|
10132
|
-
const zeroGas = tryAsServiceGas(0);
|
|
10133
|
-
return new ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
|
|
10280
|
+
static remove({ serviceId, key }) {
|
|
10281
|
+
return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Remove, key });
|
|
10134
10282
|
}
|
|
10135
|
-
|
|
10136
|
-
|
|
10137
|
-
|
|
10138
|
-
|
|
10139
|
-
|
|
10140
|
-
cores;
|
|
10141
|
-
services;
|
|
10142
|
-
static Codec = descriptors_codec.Class(StatisticsData, {
|
|
10143
|
-
current: codecPerValidator(ValidatorStatistics.Codec),
|
|
10144
|
-
previous: codecPerValidator(ValidatorStatistics.Codec),
|
|
10145
|
-
cores: codecPerCore(CoreStatistics.Codec),
|
|
10146
|
-
services: descriptors_codec.dictionary(codecServiceId, ServiceStatistics.Codec, {
|
|
10147
|
-
sortKeys: (a, b) => a - b,
|
|
10148
|
-
}),
|
|
10149
|
-
});
|
|
10150
|
-
static create(v) {
|
|
10151
|
-
return new StatisticsData(v.current, v.previous, v.cores, v.services);
|
|
10283
|
+
get key() {
|
|
10284
|
+
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
10285
|
+
return this.action.key;
|
|
10286
|
+
}
|
|
10287
|
+
return this.action.storage.key;
|
|
10152
10288
|
}
|
|
10153
|
-
|
|
10154
|
-
this.
|
|
10155
|
-
|
|
10156
|
-
|
|
10157
|
-
this.
|
|
10289
|
+
get value() {
|
|
10290
|
+
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
10291
|
+
return null;
|
|
10292
|
+
}
|
|
10293
|
+
return this.action.storage.value;
|
|
10158
10294
|
}
|
|
10159
10295
|
}
|
|
10160
10296
|
|
|
@@ -10179,6 +10315,7 @@ class StatisticsData {
|
|
|
10179
10315
|
|
|
10180
10316
|
|
|
10181
10317
|
|
|
10318
|
+
|
|
10182
10319
|
|
|
10183
10320
|
|
|
10184
10321
|
var in_memory_state_UpdateError;
|
|
@@ -10279,10 +10416,11 @@ class InMemoryService extends WithDebug {
|
|
|
10279
10416
|
/**
|
|
10280
10417
|
* A special version of state, stored fully in-memory.
|
|
10281
10418
|
*/
|
|
10282
|
-
class
|
|
10419
|
+
class in_memory_state_InMemoryState extends WithDebug {
|
|
10420
|
+
chainSpec;
|
|
10283
10421
|
/** Create a new `InMemoryState` by providing all required fields. */
|
|
10284
|
-
static
|
|
10285
|
-
return new
|
|
10422
|
+
static new(chainSpec, state) {
|
|
10423
|
+
return new in_memory_state_InMemoryState(chainSpec, state);
|
|
10286
10424
|
}
|
|
10287
10425
|
/**
|
|
10288
10426
|
* Create a new `InMemoryState` with a partial state override.
|
|
@@ -10291,14 +10429,14 @@ class InMemoryState extends WithDebug {
|
|
|
10291
10429
|
* not-necessarily coherent values.
|
|
10292
10430
|
*/
|
|
10293
10431
|
static partial(spec, partial) {
|
|
10294
|
-
const state =
|
|
10432
|
+
const state = in_memory_state_InMemoryState.empty(spec);
|
|
10295
10433
|
Object.assign(state, partial);
|
|
10296
10434
|
return state;
|
|
10297
10435
|
}
|
|
10298
10436
|
/**
|
|
10299
10437
|
* Create a new `InMemoryState` from some other state object.
|
|
10300
10438
|
*/
|
|
10301
|
-
static copyFrom(other, servicesData) {
|
|
10439
|
+
static copyFrom(chainSpec, other, servicesData) {
|
|
10302
10440
|
const services = new Map();
|
|
10303
10441
|
for (const [id, entries] of servicesData.entries()) {
|
|
10304
10442
|
const service = other.getService(id);
|
|
@@ -10308,7 +10446,7 @@ class InMemoryState extends WithDebug {
|
|
|
10308
10446
|
const inMemService = InMemoryService.copyFrom(service, entries);
|
|
10309
10447
|
services.set(id, inMemService);
|
|
10310
10448
|
}
|
|
10311
|
-
return
|
|
10449
|
+
return in_memory_state_InMemoryState.new(chainSpec, {
|
|
10312
10450
|
availabilityAssignment: other.availabilityAssignment,
|
|
10313
10451
|
accumulationQueue: other.accumulationQueue,
|
|
10314
10452
|
designatedValidatorData: other.designatedValidatorData,
|
|
@@ -10505,8 +10643,9 @@ class InMemoryState extends WithDebug {
|
|
|
10505
10643
|
getService(id) {
|
|
10506
10644
|
return this.services.get(id) ?? null;
|
|
10507
10645
|
}
|
|
10508
|
-
constructor(s) {
|
|
10646
|
+
constructor(chainSpec, s) {
|
|
10509
10647
|
super();
|
|
10648
|
+
this.chainSpec = chainSpec;
|
|
10510
10649
|
this.availabilityAssignment = s.availabilityAssignment;
|
|
10511
10650
|
this.designatedValidatorData = s.designatedValidatorData;
|
|
10512
10651
|
this.nextValidatorData = s.nextValidatorData;
|
|
@@ -10528,31 +10667,34 @@ class InMemoryState extends WithDebug {
|
|
|
10528
10667
|
this.accumulationOutputLog = s.accumulationOutputLog;
|
|
10529
10668
|
this.services = s.services;
|
|
10530
10669
|
}
|
|
10670
|
+
view() {
|
|
10671
|
+
return new InMemoryStateView(this.chainSpec, this);
|
|
10672
|
+
}
|
|
10531
10673
|
/**
|
|
10532
10674
|
* Create an empty and possibly incoherent `InMemoryState`.
|
|
10533
10675
|
*/
|
|
10534
10676
|
static empty(spec) {
|
|
10535
|
-
return new
|
|
10677
|
+
return new in_memory_state_InMemoryState(spec, {
|
|
10536
10678
|
availabilityAssignment: tryAsPerCore(Array.from({ length: spec.coresCount }, () => null), spec),
|
|
10537
|
-
designatedValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () =>
|
|
10679
|
+
designatedValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
|
|
10538
10680
|
bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
10539
10681
|
bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
|
|
10540
10682
|
ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
|
|
10541
10683
|
metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
|
|
10542
10684
|
})), spec),
|
|
10543
|
-
nextValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () =>
|
|
10685
|
+
nextValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
|
|
10544
10686
|
bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
10545
10687
|
bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
|
|
10546
10688
|
ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
|
|
10547
10689
|
metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
|
|
10548
10690
|
})), spec),
|
|
10549
|
-
currentValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () =>
|
|
10691
|
+
currentValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
|
|
10550
10692
|
bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
10551
10693
|
bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
|
|
10552
10694
|
ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
|
|
10553
10695
|
metadata: bytes_Bytes.zero(VALIDATOR_META_BYTES).asOpaque(),
|
|
10554
10696
|
})), spec),
|
|
10555
|
-
previousValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () =>
|
|
10697
|
+
previousValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => validator_data_ValidatorData.create({
|
|
10556
10698
|
bandersnatch: bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
10557
10699
|
bls: bytes_Bytes.zero(BLS_KEY_BYTES).asOpaque(),
|
|
10558
10700
|
ed25519: bytes_Bytes.zero(ED25519_KEY_BYTES).asOpaque(),
|
|
@@ -10568,7 +10710,7 @@ class InMemoryState extends WithDebug {
|
|
|
10568
10710
|
entropy: FixedSizeArray.fill(() => bytes_Bytes.zero(hash_HASH_SIZE).asOpaque(), ENTROPY_ENTRIES),
|
|
10569
10711
|
authPools: tryAsPerCore(Array.from({ length: spec.coresCount }, () => sized_array_asKnownSize([])), spec),
|
|
10570
10712
|
authQueues: tryAsPerCore(Array.from({ length: spec.coresCount }, () => FixedSizeArray.fill(() => bytes_Bytes.zero(hash_HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE)), spec),
|
|
10571
|
-
recentBlocks:
|
|
10713
|
+
recentBlocks: RecentBlocks.empty(),
|
|
10572
10714
|
statistics: StatisticsData.create({
|
|
10573
10715
|
current: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
|
|
10574
10716
|
previous: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
|
|
@@ -10578,8 +10720,8 @@ class InMemoryState extends WithDebug {
|
|
|
10578
10720
|
accumulationQueue: tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => []), spec),
|
|
10579
10721
|
recentlyAccumulated: tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => HashSet.new()), spec),
|
|
10580
10722
|
ticketsAccumulator: sized_array_asKnownSize([]),
|
|
10581
|
-
sealingKeySeries:
|
|
10582
|
-
epochRoot: bytes_Bytes.zero(
|
|
10723
|
+
sealingKeySeries: safrole_data_SafroleSealingKeysData.keys(tryAsPerEpochBlock(Array.from({ length: spec.epochLength }, () => bytes_Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque()), spec)),
|
|
10724
|
+
epochRoot: bytes_Bytes.zero(bandersnatch_BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
10583
10725
|
privilegedServices: PrivilegedServices.create({
|
|
10584
10726
|
manager: tryAsServiceId(0),
|
|
10585
10727
|
assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
|
|
@@ -10619,50 +10761,9 @@ const serviceDataCodec = descriptors_codec.dictionary(descriptors_codec.u32.asOp
|
|
|
10619
10761
|
|
|
10620
10762
|
|
|
10621
10763
|
|
|
10622
|
-
;// CONCATENATED MODULE: ./packages/jam/state/not-yet-accumulated.ts
|
|
10623
|
-
|
|
10624
|
-
|
|
10625
|
-
|
|
10626
10764
|
|
|
10627
10765
|
|
|
10628
10766
|
|
|
10629
|
-
/**
|
|
10630
|
-
* Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
|
|
10631
|
-
*
|
|
10632
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
|
|
10633
|
-
*/
|
|
10634
|
-
class NotYetAccumulatedReport extends WithDebug {
|
|
10635
|
-
report;
|
|
10636
|
-
dependencies;
|
|
10637
|
-
static Codec = descriptors_codec.Class(NotYetAccumulatedReport, {
|
|
10638
|
-
report: WorkReport.Codec,
|
|
10639
|
-
dependencies: codecKnownSizeArray(descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(), {
|
|
10640
|
-
typicalLength: MAX_REPORT_DEPENDENCIES / 2,
|
|
10641
|
-
maxLength: MAX_REPORT_DEPENDENCIES,
|
|
10642
|
-
minLength: 0,
|
|
10643
|
-
}),
|
|
10644
|
-
});
|
|
10645
|
-
static create({ report, dependencies }) {
|
|
10646
|
-
return new NotYetAccumulatedReport(report, dependencies);
|
|
10647
|
-
}
|
|
10648
|
-
constructor(
|
|
10649
|
-
/**
|
|
10650
|
-
* Each of these were made available at most one epoch ago
|
|
10651
|
-
* but have or had unfulfilled dependencies.
|
|
10652
|
-
*/
|
|
10653
|
-
report,
|
|
10654
|
-
/**
|
|
10655
|
-
* Alongside the work-report itself, we retain its un-accumulated
|
|
10656
|
-
* dependencies, a set of work-package hashes.
|
|
10657
|
-
*
|
|
10658
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
|
|
10659
|
-
*/
|
|
10660
|
-
dependencies) {
|
|
10661
|
-
super();
|
|
10662
|
-
this.report = report;
|
|
10663
|
-
this.dependencies = dependencies;
|
|
10664
|
-
}
|
|
10665
|
-
}
|
|
10666
10767
|
|
|
10667
10768
|
;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialize.ts
|
|
10668
10769
|
|
|
@@ -10676,26 +10777,19 @@ class NotYetAccumulatedReport extends WithDebug {
|
|
|
10676
10777
|
|
|
10677
10778
|
|
|
10678
10779
|
|
|
10679
|
-
|
|
10680
|
-
|
|
10681
|
-
|
|
10682
10780
|
/** Serialization for particular state entries. */
|
|
10683
|
-
var
|
|
10781
|
+
var serialize_serialize;
|
|
10684
10782
|
(function (serialize) {
|
|
10685
10783
|
/** C(1): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b15013b1501?v=0.6.7 */
|
|
10686
10784
|
serialize.authPools = {
|
|
10687
10785
|
key: stateKeys.index(StateKeyIdx.Alpha),
|
|
10688
|
-
Codec:
|
|
10689
|
-
minLength: 0,
|
|
10690
|
-
maxLength: MAX_AUTH_POOL_SIZE,
|
|
10691
|
-
typicalLength: MAX_AUTH_POOL_SIZE,
|
|
10692
|
-
})),
|
|
10786
|
+
Codec: authPoolsCodec,
|
|
10693
10787
|
extract: (s) => s.authPools,
|
|
10694
10788
|
};
|
|
10695
10789
|
/** C(2): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b31013b3101?v=0.6.7 */
|
|
10696
10790
|
serialize.authQueues = {
|
|
10697
10791
|
key: stateKeys.index(StateKeyIdx.Phi),
|
|
10698
|
-
Codec:
|
|
10792
|
+
Codec: authQueuesCodec,
|
|
10699
10793
|
extract: (s) => s.authQueues,
|
|
10700
10794
|
};
|
|
10701
10795
|
/**
|
|
@@ -10704,7 +10798,7 @@ var serialize;
|
|
|
10704
10798
|
*/
|
|
10705
10799
|
serialize.recentBlocks = {
|
|
10706
10800
|
key: stateKeys.index(StateKeyIdx.Beta),
|
|
10707
|
-
Codec:
|
|
10801
|
+
Codec: RecentBlocks.Codec,
|
|
10708
10802
|
extract: (s) => s.recentBlocks,
|
|
10709
10803
|
};
|
|
10710
10804
|
/** C(4): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b63013b6301?v=0.6.7 */
|
|
@@ -10733,25 +10827,25 @@ var serialize;
|
|
|
10733
10827
|
/** C(7): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b00023b0002?v=0.6.7 */
|
|
10734
10828
|
serialize.designatedValidators = {
|
|
10735
10829
|
key: stateKeys.index(StateKeyIdx.Iota),
|
|
10736
|
-
Codec:
|
|
10830
|
+
Codec: validatorsDataCodec,
|
|
10737
10831
|
extract: (s) => s.designatedValidatorData,
|
|
10738
10832
|
};
|
|
10739
10833
|
/** C(8): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b0d023b0d02?v=0.6.7 */
|
|
10740
10834
|
serialize.currentValidators = {
|
|
10741
10835
|
key: stateKeys.index(StateKeyIdx.Kappa),
|
|
10742
|
-
Codec:
|
|
10836
|
+
Codec: validatorsDataCodec,
|
|
10743
10837
|
extract: (s) => s.currentValidatorData,
|
|
10744
10838
|
};
|
|
10745
10839
|
/** C(9): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b1a023b1a02?v=0.6.7 */
|
|
10746
10840
|
serialize.previousValidators = {
|
|
10747
10841
|
key: stateKeys.index(StateKeyIdx.Lambda),
|
|
10748
|
-
Codec:
|
|
10842
|
+
Codec: validatorsDataCodec,
|
|
10749
10843
|
extract: (s) => s.previousValidatorData,
|
|
10750
10844
|
};
|
|
10751
10845
|
/** C(10): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b27023b2702?v=0.6.7 */
|
|
10752
10846
|
serialize.availabilityAssignment = {
|
|
10753
10847
|
key: stateKeys.index(StateKeyIdx.Rho),
|
|
10754
|
-
Codec:
|
|
10848
|
+
Codec: availabilityAssignmentsCodec,
|
|
10755
10849
|
extract: (s) => s.availabilityAssignment,
|
|
10756
10850
|
};
|
|
10757
10851
|
/** C(11): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b3e023b3e02?v=0.6.7 */
|
|
@@ -10775,13 +10869,13 @@ var serialize;
|
|
|
10775
10869
|
/** C(14): https://graypaper.fluffylabs.dev/#/1c979cb/3bf0023bf002?v=0.7.1 */
|
|
10776
10870
|
serialize.accumulationQueue = {
|
|
10777
10871
|
key: stateKeys.index(StateKeyIdx.Omega),
|
|
10778
|
-
Codec:
|
|
10872
|
+
Codec: accumulationQueueCodec,
|
|
10779
10873
|
extract: (s) => s.accumulationQueue,
|
|
10780
10874
|
};
|
|
10781
10875
|
/** C(15): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b96023b9602?v=0.6.7 */
|
|
10782
10876
|
serialize.recentlyAccumulated = {
|
|
10783
10877
|
key: stateKeys.index(StateKeyIdx.Xi),
|
|
10784
|
-
Codec:
|
|
10878
|
+
Codec: recentlyAccumulatedCodec,
|
|
10785
10879
|
extract: (s) => s.recentlyAccumulated,
|
|
10786
10880
|
};
|
|
10787
10881
|
/** C(16): https://graypaper.fluffylabs.dev/#/38c4e62/3b46033b4603?v=0.7.0 */
|
|
@@ -10810,9 +10904,9 @@ var serialize;
|
|
|
10810
10904
|
/** https://graypaper.fluffylabs.dev/#/85129da/387603387603?v=0.6.3 */
|
|
10811
10905
|
serialize.serviceLookupHistory = (blake2b, serviceId, hash, len) => ({
|
|
10812
10906
|
key: stateKeys.serviceLookupHistory(blake2b, serviceId, hash, len),
|
|
10813
|
-
Codec:
|
|
10907
|
+
Codec: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32)),
|
|
10814
10908
|
});
|
|
10815
|
-
})(
|
|
10909
|
+
})(serialize_serialize || (serialize_serialize = {}));
|
|
10816
10910
|
/**
|
|
10817
10911
|
* Just dump the entire terminal blob as-is.
|
|
10818
10912
|
*
|
|
@@ -10822,6 +10916,87 @@ var serialize;
|
|
|
10822
10916
|
*/
|
|
10823
10917
|
const dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }, (e, v) => e.bytes(bytes_Bytes.fromBlob(v.raw, v.raw.length)), (d) => bytes_BytesBlob.blobFrom(d.bytes(d.source.length - d.bytesRead()).raw), (s) => s.bytes(s.decoder.source.length - s.decoder.bytesRead()));
|
|
10824
10918
|
|
|
10919
|
+
;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state-view.ts
|
|
10920
|
+
|
|
10921
|
+
|
|
10922
|
+
class SerializedStateView {
|
|
10923
|
+
spec;
|
|
10924
|
+
backend;
|
|
10925
|
+
recentlyUsedServices;
|
|
10926
|
+
viewCache;
|
|
10927
|
+
constructor(spec, backend,
|
|
10928
|
+
/** Best-effort list of recently active services. */
|
|
10929
|
+
recentlyUsedServices, viewCache) {
|
|
10930
|
+
this.spec = spec;
|
|
10931
|
+
this.backend = backend;
|
|
10932
|
+
this.recentlyUsedServices = recentlyUsedServices;
|
|
10933
|
+
this.viewCache = viewCache;
|
|
10934
|
+
}
|
|
10935
|
+
retrieveView({ key, Codec }, description) {
|
|
10936
|
+
const cached = this.viewCache.get(key);
|
|
10937
|
+
if (cached !== undefined) {
|
|
10938
|
+
return cached;
|
|
10939
|
+
}
|
|
10940
|
+
const bytes = this.backend.get(key);
|
|
10941
|
+
if (bytes === null) {
|
|
10942
|
+
throw new Error(`Required state entry for ${description} is missing!. Accessing view of key: ${key}`);
|
|
10943
|
+
}
|
|
10944
|
+
// NOTE [ToDr] we are not using `Decoder.decodeObject` here because
|
|
10945
|
+
// it needs to get to the end of the data (skip), yet that's expensive.
|
|
10946
|
+
// we assume that the state data is correct and coherent anyway, so
|
|
10947
|
+
// for performance reasons we simply create the view here.
|
|
10948
|
+
const d = decoder_Decoder.fromBytesBlob(bytes);
|
|
10949
|
+
d.attachContext(this.spec);
|
|
10950
|
+
const view = Codec.View.decode(d);
|
|
10951
|
+
this.viewCache.set(key, view);
|
|
10952
|
+
return view;
|
|
10953
|
+
}
|
|
10954
|
+
availabilityAssignmentView() {
|
|
10955
|
+
return this.retrieveView(serialize_serialize.availabilityAssignment, "availabilityAssignmentView");
|
|
10956
|
+
}
|
|
10957
|
+
designatedValidatorDataView() {
|
|
10958
|
+
return this.retrieveView(serialize_serialize.designatedValidators, "designatedValidatorsView");
|
|
10959
|
+
}
|
|
10960
|
+
currentValidatorDataView() {
|
|
10961
|
+
return this.retrieveView(serialize_serialize.currentValidators, "currentValidatorsView");
|
|
10962
|
+
}
|
|
10963
|
+
previousValidatorDataView() {
|
|
10964
|
+
return this.retrieveView(serialize_serialize.previousValidators, "previousValidatorsView");
|
|
10965
|
+
}
|
|
10966
|
+
authPoolsView() {
|
|
10967
|
+
return this.retrieveView(serialize_serialize.authPools, "authPoolsView");
|
|
10968
|
+
}
|
|
10969
|
+
authQueuesView() {
|
|
10970
|
+
return this.retrieveView(serialize_serialize.authQueues, "authQueuesView");
|
|
10971
|
+
}
|
|
10972
|
+
recentBlocksView() {
|
|
10973
|
+
return this.retrieveView(serialize_serialize.recentBlocks, "recentBlocksView");
|
|
10974
|
+
}
|
|
10975
|
+
statisticsView() {
|
|
10976
|
+
return this.retrieveView(serialize_serialize.statistics, "statisticsView");
|
|
10977
|
+
}
|
|
10978
|
+
accumulationQueueView() {
|
|
10979
|
+
return this.retrieveView(serialize_serialize.accumulationQueue, "accumulationQueueView");
|
|
10980
|
+
}
|
|
10981
|
+
recentlyAccumulatedView() {
|
|
10982
|
+
return this.retrieveView(serialize_serialize.recentlyAccumulated, "recentlyAccumulatedView");
|
|
10983
|
+
}
|
|
10984
|
+
safroleDataView() {
|
|
10985
|
+
return this.retrieveView(serialize_serialize.safrole, "safroleDataView");
|
|
10986
|
+
}
|
|
10987
|
+
getServiceInfoView(id) {
|
|
10988
|
+
const serviceData = serialize_serialize.serviceData(id);
|
|
10989
|
+
const bytes = this.backend.get(serviceData.key);
|
|
10990
|
+
if (bytes === null) {
|
|
10991
|
+
return null;
|
|
10992
|
+
}
|
|
10993
|
+
if (!this.recentlyUsedServices.includes(id)) {
|
|
10994
|
+
this.recentlyUsedServices.push(id);
|
|
10995
|
+
}
|
|
10996
|
+
return decoder_Decoder.decodeObject(serviceData.Codec.View, bytes, this.spec);
|
|
10997
|
+
}
|
|
10998
|
+
}
|
|
10999
|
+
|
|
10825
11000
|
;// CONCATENATED MODULE: ./packages/jam/state-merkleization/serialized-state.ts
|
|
10826
11001
|
|
|
10827
11002
|
|
|
@@ -10830,6 +11005,8 @@ const dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }, (e, v) =
|
|
|
10830
11005
|
|
|
10831
11006
|
|
|
10832
11007
|
|
|
11008
|
+
|
|
11009
|
+
|
|
10833
11010
|
/**
|
|
10834
11011
|
* State object which reads it's entries from some backend.
|
|
10835
11012
|
*
|
|
@@ -10842,7 +11019,7 @@ class serialized_state_SerializedState {
|
|
|
10842
11019
|
spec;
|
|
10843
11020
|
blake2b;
|
|
10844
11021
|
backend;
|
|
10845
|
-
|
|
11022
|
+
recentlyUsedServices;
|
|
10846
11023
|
/** Create a state-like object from collection of serialized entries. */
|
|
10847
11024
|
static fromStateEntries(spec, blake2b, state, recentServices = []) {
|
|
10848
11025
|
return new serialized_state_SerializedState(spec, blake2b, state, recentServices);
|
|
@@ -10851,106 +11028,120 @@ class serialized_state_SerializedState {
|
|
|
10851
11028
|
static new(spec, blake2b, db, recentServices = []) {
|
|
10852
11029
|
return new serialized_state_SerializedState(spec, blake2b, db, recentServices);
|
|
10853
11030
|
}
|
|
11031
|
+
dataCache = hash_dictionary_HashDictionary.new();
|
|
11032
|
+
viewCache = hash_dictionary_HashDictionary.new();
|
|
10854
11033
|
constructor(spec, blake2b, backend,
|
|
10855
11034
|
/** Best-effort list of recently active services. */
|
|
10856
|
-
|
|
11035
|
+
recentlyUsedServices) {
|
|
10857
11036
|
this.spec = spec;
|
|
10858
11037
|
this.blake2b = blake2b;
|
|
10859
11038
|
this.backend = backend;
|
|
10860
|
-
this.
|
|
11039
|
+
this.recentlyUsedServices = recentlyUsedServices;
|
|
10861
11040
|
}
|
|
10862
11041
|
/** Comparing the serialized states, just means comparing their backends. */
|
|
10863
11042
|
[TEST_COMPARE_USING]() {
|
|
10864
11043
|
return this.backend;
|
|
10865
11044
|
}
|
|
11045
|
+
/** Return a non-decoding version of the state. */
|
|
11046
|
+
view() {
|
|
11047
|
+
return new SerializedStateView(this.spec, this.backend, this.recentlyUsedServices, this.viewCache);
|
|
11048
|
+
}
|
|
10866
11049
|
// TODO [ToDr] Temporary method to update the state,
|
|
10867
11050
|
// without changing references.
|
|
10868
11051
|
updateBackend(newBackend) {
|
|
10869
11052
|
this.backend = newBackend;
|
|
11053
|
+
this.dataCache = hash_dictionary_HashDictionary.new();
|
|
11054
|
+
this.viewCache = hash_dictionary_HashDictionary.new();
|
|
10870
11055
|
}
|
|
10871
11056
|
recentServiceIds() {
|
|
10872
|
-
return this.
|
|
11057
|
+
return this.recentlyUsedServices;
|
|
10873
11058
|
}
|
|
10874
11059
|
getService(id) {
|
|
10875
|
-
const serviceData = this.retrieveOptional(
|
|
11060
|
+
const serviceData = this.retrieveOptional(serialize_serialize.serviceData(id));
|
|
10876
11061
|
if (serviceData === undefined) {
|
|
10877
11062
|
return null;
|
|
10878
11063
|
}
|
|
10879
|
-
if (!this.
|
|
10880
|
-
this.
|
|
11064
|
+
if (!this.recentlyUsedServices.includes(id)) {
|
|
11065
|
+
this.recentlyUsedServices.push(id);
|
|
10881
11066
|
}
|
|
10882
11067
|
return new SerializedService(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
|
|
10883
11068
|
}
|
|
10884
|
-
retrieve(
|
|
10885
|
-
const
|
|
10886
|
-
if (
|
|
10887
|
-
throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${key}`);
|
|
11069
|
+
retrieve(k, description) {
|
|
11070
|
+
const data = this.retrieveOptional(k);
|
|
11071
|
+
if (data === undefined) {
|
|
11072
|
+
throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${k.key}`);
|
|
10888
11073
|
}
|
|
10889
|
-
return
|
|
11074
|
+
return data;
|
|
10890
11075
|
}
|
|
10891
11076
|
retrieveOptional({ key, Codec }) {
|
|
11077
|
+
const cached = this.dataCache.get(key);
|
|
11078
|
+
if (cached !== undefined) {
|
|
11079
|
+
return cached;
|
|
11080
|
+
}
|
|
10892
11081
|
const bytes = this.backend.get(key);
|
|
10893
11082
|
if (bytes === null) {
|
|
10894
11083
|
return undefined;
|
|
10895
11084
|
}
|
|
10896
|
-
|
|
11085
|
+
const data = decoder_Decoder.decodeObject(Codec, bytes, this.spec);
|
|
11086
|
+
this.dataCache.set(key, data);
|
|
11087
|
+
return data;
|
|
10897
11088
|
}
|
|
10898
11089
|
get availabilityAssignment() {
|
|
10899
|
-
return this.retrieve(
|
|
11090
|
+
return this.retrieve(serialize_serialize.availabilityAssignment, "availabilityAssignment");
|
|
10900
11091
|
}
|
|
10901
11092
|
get designatedValidatorData() {
|
|
10902
|
-
return this.retrieve(
|
|
11093
|
+
return this.retrieve(serialize_serialize.designatedValidators, "designatedValidatorData");
|
|
10903
11094
|
}
|
|
10904
11095
|
get nextValidatorData() {
|
|
10905
|
-
return this.retrieve(
|
|
11096
|
+
return this.retrieve(serialize_serialize.safrole, "safroleData.nextValidatorData").nextValidatorData;
|
|
10906
11097
|
}
|
|
10907
11098
|
get currentValidatorData() {
|
|
10908
|
-
return this.retrieve(
|
|
11099
|
+
return this.retrieve(serialize_serialize.currentValidators, "currentValidators");
|
|
10909
11100
|
}
|
|
10910
11101
|
get previousValidatorData() {
|
|
10911
|
-
return this.retrieve(
|
|
11102
|
+
return this.retrieve(serialize_serialize.previousValidators, "previousValidators");
|
|
10912
11103
|
}
|
|
10913
11104
|
get disputesRecords() {
|
|
10914
|
-
return this.retrieve(
|
|
11105
|
+
return this.retrieve(serialize_serialize.disputesRecords, "disputesRecords");
|
|
10915
11106
|
}
|
|
10916
11107
|
get timeslot() {
|
|
10917
|
-
return this.retrieve(
|
|
11108
|
+
return this.retrieve(serialize_serialize.timeslot, "timeslot");
|
|
10918
11109
|
}
|
|
10919
11110
|
get entropy() {
|
|
10920
|
-
return this.retrieve(
|
|
11111
|
+
return this.retrieve(serialize_serialize.entropy, "entropy");
|
|
10921
11112
|
}
|
|
10922
11113
|
get authPools() {
|
|
10923
|
-
return this.retrieve(
|
|
11114
|
+
return this.retrieve(serialize_serialize.authPools, "authPools");
|
|
10924
11115
|
}
|
|
10925
11116
|
get authQueues() {
|
|
10926
|
-
return this.retrieve(
|
|
11117
|
+
return this.retrieve(serialize_serialize.authQueues, "authQueues");
|
|
10927
11118
|
}
|
|
10928
11119
|
get recentBlocks() {
|
|
10929
|
-
return this.retrieve(
|
|
11120
|
+
return this.retrieve(serialize_serialize.recentBlocks, "recentBlocks");
|
|
10930
11121
|
}
|
|
10931
11122
|
get statistics() {
|
|
10932
|
-
return this.retrieve(
|
|
11123
|
+
return this.retrieve(serialize_serialize.statistics, "statistics");
|
|
10933
11124
|
}
|
|
10934
11125
|
get accumulationQueue() {
|
|
10935
|
-
return this.retrieve(
|
|
11126
|
+
return this.retrieve(serialize_serialize.accumulationQueue, "accumulationQueue");
|
|
10936
11127
|
}
|
|
10937
11128
|
get recentlyAccumulated() {
|
|
10938
|
-
return this.retrieve(
|
|
11129
|
+
return this.retrieve(serialize_serialize.recentlyAccumulated, "recentlyAccumulated");
|
|
10939
11130
|
}
|
|
10940
11131
|
get ticketsAccumulator() {
|
|
10941
|
-
return this.retrieve(
|
|
11132
|
+
return this.retrieve(serialize_serialize.safrole, "safroleData.ticketsAccumulator").ticketsAccumulator;
|
|
10942
11133
|
}
|
|
10943
11134
|
get sealingKeySeries() {
|
|
10944
|
-
return this.retrieve(
|
|
11135
|
+
return this.retrieve(serialize_serialize.safrole, "safrole.sealingKeySeries").sealingKeySeries;
|
|
10945
11136
|
}
|
|
10946
11137
|
get epochRoot() {
|
|
10947
|
-
return this.retrieve(
|
|
11138
|
+
return this.retrieve(serialize_serialize.safrole, "safrole.epochRoot").epochRoot;
|
|
10948
11139
|
}
|
|
10949
11140
|
get privilegedServices() {
|
|
10950
|
-
return this.retrieve(
|
|
11141
|
+
return this.retrieve(serialize_serialize.privilegedServices, "privilegedServices");
|
|
10951
11142
|
}
|
|
10952
11143
|
get accumulationOutputLog() {
|
|
10953
|
-
return this.retrieve(
|
|
11144
|
+
return this.retrieve(serialize_serialize.accumulationOutputLog, "accumulationOutputLog");
|
|
10954
11145
|
}
|
|
10955
11146
|
}
|
|
10956
11147
|
/** Service data representation on a serialized state. */
|
|
@@ -10979,9 +11170,9 @@ class SerializedService {
|
|
|
10979
11170
|
serviceIdAndKey.set(numbers_u32AsLeBytes(this.serviceId));
|
|
10980
11171
|
serviceIdAndKey.set(rawKey.raw, SERVICE_ID_BYTES);
|
|
10981
11172
|
const key = opaque_asOpaqueType(bytes_BytesBlob.blobFrom(this.blake2b.hashBytes(serviceIdAndKey).raw));
|
|
10982
|
-
return this.retrieveOptional(
|
|
11173
|
+
return this.retrieveOptional(serialize_serialize.serviceStorage(this.blake2b, this.serviceId, key)) ?? null;
|
|
10983
11174
|
}
|
|
10984
|
-
return this.retrieveOptional(
|
|
11175
|
+
return this.retrieveOptional(serialize_serialize.serviceStorage(this.blake2b, this.serviceId, rawKey)) ?? null;
|
|
10985
11176
|
}
|
|
10986
11177
|
/**
|
|
10987
11178
|
* Check if preimage is present in the DB.
|
|
@@ -10990,15 +11181,15 @@ class SerializedService {
|
|
|
10990
11181
|
*/
|
|
10991
11182
|
hasPreimage(hash) {
|
|
10992
11183
|
// TODO [ToDr] consider optimizing to avoid fetching the whole data.
|
|
10993
|
-
return this.retrieveOptional(
|
|
11184
|
+
return this.retrieveOptional(serialize_serialize.servicePreimages(this.blake2b, this.serviceId, hash)) !== undefined;
|
|
10994
11185
|
}
|
|
10995
11186
|
/** Retrieve preimage from the DB. */
|
|
10996
11187
|
getPreimage(hash) {
|
|
10997
|
-
return this.retrieveOptional(
|
|
11188
|
+
return this.retrieveOptional(serialize_serialize.servicePreimages(this.blake2b, this.serviceId, hash)) ?? null;
|
|
10998
11189
|
}
|
|
10999
11190
|
/** Retrieve preimage lookup history. */
|
|
11000
11191
|
getLookupHistory(hash, len) {
|
|
11001
|
-
const rawSlots = this.retrieveOptional(
|
|
11192
|
+
const rawSlots = this.retrieveOptional(serialize_serialize.serviceLookupHistory(this.blake2b, this.serviceId, hash, len));
|
|
11002
11193
|
if (rawSlots === undefined) {
|
|
11003
11194
|
return null;
|
|
11004
11195
|
}
|
|
@@ -11687,7 +11878,7 @@ function* serializeStateUpdate(spec, blake2b, update) {
|
|
|
11687
11878
|
function* serializeRemovedServices(servicesRemoved) {
|
|
11688
11879
|
for (const serviceId of servicesRemoved ?? []) {
|
|
11689
11880
|
// TODO [ToDr] what about all data associated with a service?
|
|
11690
|
-
const codec =
|
|
11881
|
+
const codec = serialize_serialize.serviceData(serviceId);
|
|
11691
11882
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11692
11883
|
}
|
|
11693
11884
|
}
|
|
@@ -11696,13 +11887,13 @@ function* serializeStorage(storage, blake2b) {
|
|
|
11696
11887
|
switch (action.kind) {
|
|
11697
11888
|
case UpdateStorageKind.Set: {
|
|
11698
11889
|
const key = action.storage.key;
|
|
11699
|
-
const codec =
|
|
11890
|
+
const codec = serialize_serialize.serviceStorage(blake2b, serviceId, key);
|
|
11700
11891
|
yield [StateEntryUpdateAction.Insert, codec.key, action.storage.value];
|
|
11701
11892
|
break;
|
|
11702
11893
|
}
|
|
11703
11894
|
case UpdateStorageKind.Remove: {
|
|
11704
11895
|
const key = action.key;
|
|
11705
|
-
const codec =
|
|
11896
|
+
const codec = serialize_serialize.serviceStorage(blake2b, serviceId, key);
|
|
11706
11897
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11707
11898
|
break;
|
|
11708
11899
|
}
|
|
@@ -11716,10 +11907,10 @@ function* serializePreimages(preimages, encode, blake2b) {
|
|
|
11716
11907
|
switch (action.kind) {
|
|
11717
11908
|
case UpdatePreimageKind.Provide: {
|
|
11718
11909
|
const { hash, blob } = action.preimage;
|
|
11719
|
-
const codec =
|
|
11910
|
+
const codec = serialize_serialize.servicePreimages(blake2b, serviceId, hash);
|
|
11720
11911
|
yield [StateEntryUpdateAction.Insert, codec.key, blob];
|
|
11721
11912
|
if (action.slot !== null) {
|
|
11722
|
-
const codec2 =
|
|
11913
|
+
const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, numbers_tryAsU32(blob.length));
|
|
11723
11914
|
yield [
|
|
11724
11915
|
StateEntryUpdateAction.Insert,
|
|
11725
11916
|
codec2.key,
|
|
@@ -11730,15 +11921,15 @@ function* serializePreimages(preimages, encode, blake2b) {
|
|
|
11730
11921
|
}
|
|
11731
11922
|
case UpdatePreimageKind.UpdateOrAdd: {
|
|
11732
11923
|
const { hash, length, slots } = action.item;
|
|
11733
|
-
const codec =
|
|
11924
|
+
const codec = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
11734
11925
|
yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, slots)];
|
|
11735
11926
|
break;
|
|
11736
11927
|
}
|
|
11737
11928
|
case UpdatePreimageKind.Remove: {
|
|
11738
11929
|
const { hash, length } = action;
|
|
11739
|
-
const codec =
|
|
11930
|
+
const codec = serialize_serialize.servicePreimages(blake2b, serviceId, hash);
|
|
11740
11931
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11741
|
-
const codec2 =
|
|
11932
|
+
const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
11742
11933
|
yield [StateEntryUpdateAction.Remove, codec2.key, EMPTY_BLOB];
|
|
11743
11934
|
break;
|
|
11744
11935
|
}
|
|
@@ -11750,12 +11941,12 @@ function* serializePreimages(preimages, encode, blake2b) {
|
|
|
11750
11941
|
function* serializeServiceUpdates(servicesUpdates, encode, blake2b) {
|
|
11751
11942
|
for (const { action, serviceId } of servicesUpdates ?? []) {
|
|
11752
11943
|
// new service being created or updated
|
|
11753
|
-
const codec =
|
|
11944
|
+
const codec = serialize_serialize.serviceData(serviceId);
|
|
11754
11945
|
yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, action.account)];
|
|
11755
11946
|
// additional lookup history update
|
|
11756
11947
|
if (action.kind === UpdateServiceKind.Create && action.lookupHistory !== null) {
|
|
11757
11948
|
const { lookupHistory } = action;
|
|
11758
|
-
const codec2 =
|
|
11949
|
+
const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
11759
11950
|
yield [StateEntryUpdateAction.Insert, codec2.key, encode(codec2.Codec, lookupHistory.slots)];
|
|
11760
11951
|
}
|
|
11761
11952
|
}
|
|
@@ -11765,53 +11956,53 @@ function* serializeBasicKeys(spec, update) {
|
|
|
11765
11956
|
return [StateEntryUpdateAction.Insert, codec.key, encoder_Encoder.encodeObject(codec.Codec, val, spec)];
|
|
11766
11957
|
}
|
|
11767
11958
|
if (update.authPools !== undefined) {
|
|
11768
|
-
yield doSerialize(update.authPools,
|
|
11959
|
+
yield doSerialize(update.authPools, serialize_serialize.authPools); // C(1)
|
|
11769
11960
|
}
|
|
11770
11961
|
if (update.authQueues !== undefined) {
|
|
11771
|
-
yield doSerialize(update.authQueues,
|
|
11962
|
+
yield doSerialize(update.authQueues, serialize_serialize.authQueues); // C(2)
|
|
11772
11963
|
}
|
|
11773
11964
|
if (update.recentBlocks !== undefined) {
|
|
11774
|
-
yield doSerialize(update.recentBlocks,
|
|
11965
|
+
yield doSerialize(update.recentBlocks, serialize_serialize.recentBlocks); // C(3)
|
|
11775
11966
|
}
|
|
11776
11967
|
const safroleData = getSafroleData(update.nextValidatorData, update.epochRoot, update.sealingKeySeries, update.ticketsAccumulator);
|
|
11777
11968
|
if (safroleData !== undefined) {
|
|
11778
|
-
yield doSerialize(safroleData,
|
|
11969
|
+
yield doSerialize(safroleData, serialize_serialize.safrole); // C(4)
|
|
11779
11970
|
}
|
|
11780
11971
|
if (update.disputesRecords !== undefined) {
|
|
11781
|
-
yield doSerialize(update.disputesRecords,
|
|
11972
|
+
yield doSerialize(update.disputesRecords, serialize_serialize.disputesRecords); // C(5)
|
|
11782
11973
|
}
|
|
11783
11974
|
if (update.entropy !== undefined) {
|
|
11784
|
-
yield doSerialize(update.entropy,
|
|
11975
|
+
yield doSerialize(update.entropy, serialize_serialize.entropy); // C(6)
|
|
11785
11976
|
}
|
|
11786
11977
|
if (update.designatedValidatorData !== undefined) {
|
|
11787
|
-
yield doSerialize(update.designatedValidatorData,
|
|
11978
|
+
yield doSerialize(update.designatedValidatorData, serialize_serialize.designatedValidators); // C(7)
|
|
11788
11979
|
}
|
|
11789
11980
|
if (update.currentValidatorData !== undefined) {
|
|
11790
|
-
yield doSerialize(update.currentValidatorData,
|
|
11981
|
+
yield doSerialize(update.currentValidatorData, serialize_serialize.currentValidators); // C(8)
|
|
11791
11982
|
}
|
|
11792
11983
|
if (update.previousValidatorData !== undefined) {
|
|
11793
|
-
yield doSerialize(update.previousValidatorData,
|
|
11984
|
+
yield doSerialize(update.previousValidatorData, serialize_serialize.previousValidators); // C(9)
|
|
11794
11985
|
}
|
|
11795
11986
|
if (update.availabilityAssignment !== undefined) {
|
|
11796
|
-
yield doSerialize(update.availabilityAssignment,
|
|
11987
|
+
yield doSerialize(update.availabilityAssignment, serialize_serialize.availabilityAssignment); // C(10)
|
|
11797
11988
|
}
|
|
11798
11989
|
if (update.timeslot !== undefined) {
|
|
11799
|
-
yield doSerialize(update.timeslot,
|
|
11990
|
+
yield doSerialize(update.timeslot, serialize_serialize.timeslot); // C(11)
|
|
11800
11991
|
}
|
|
11801
11992
|
if (update.privilegedServices !== undefined) {
|
|
11802
|
-
yield doSerialize(update.privilegedServices,
|
|
11993
|
+
yield doSerialize(update.privilegedServices, serialize_serialize.privilegedServices); // C(12)
|
|
11803
11994
|
}
|
|
11804
11995
|
if (update.statistics !== undefined) {
|
|
11805
|
-
yield doSerialize(update.statistics,
|
|
11996
|
+
yield doSerialize(update.statistics, serialize_serialize.statistics); // C(13)
|
|
11806
11997
|
}
|
|
11807
11998
|
if (update.accumulationQueue !== undefined) {
|
|
11808
|
-
yield doSerialize(update.accumulationQueue,
|
|
11999
|
+
yield doSerialize(update.accumulationQueue, serialize_serialize.accumulationQueue); // C(14)
|
|
11809
12000
|
}
|
|
11810
12001
|
if (update.recentlyAccumulated !== undefined) {
|
|
11811
|
-
yield doSerialize(update.recentlyAccumulated,
|
|
12002
|
+
yield doSerialize(update.recentlyAccumulated, serialize_serialize.recentlyAccumulated); // C(15)
|
|
11812
12003
|
}
|
|
11813
12004
|
if (update.accumulationOutputLog !== undefined) {
|
|
11814
|
-
yield doSerialize(update.accumulationOutputLog,
|
|
12005
|
+
yield doSerialize(update.accumulationOutputLog, serialize_serialize.accumulationOutputLog); // C(16)
|
|
11815
12006
|
}
|
|
11816
12007
|
}
|
|
11817
12008
|
function getSafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator) {
|
|
@@ -11924,41 +12115,41 @@ function convertInMemoryStateToDictionary(spec, blake2b, state) {
|
|
|
11924
12115
|
function doSerialize(codec) {
|
|
11925
12116
|
serialized.set(codec.key, encoder_Encoder.encodeObject(codec.Codec, codec.extract(state), spec));
|
|
11926
12117
|
}
|
|
11927
|
-
doSerialize(
|
|
11928
|
-
doSerialize(
|
|
11929
|
-
doSerialize(
|
|
11930
|
-
doSerialize(
|
|
11931
|
-
doSerialize(
|
|
11932
|
-
doSerialize(
|
|
11933
|
-
doSerialize(
|
|
11934
|
-
doSerialize(
|
|
11935
|
-
doSerialize(
|
|
11936
|
-
doSerialize(
|
|
11937
|
-
doSerialize(
|
|
11938
|
-
doSerialize(
|
|
11939
|
-
doSerialize(
|
|
11940
|
-
doSerialize(
|
|
11941
|
-
doSerialize(
|
|
11942
|
-
doSerialize(
|
|
12118
|
+
doSerialize(serialize_serialize.authPools); // C(1)
|
|
12119
|
+
doSerialize(serialize_serialize.authQueues); // C(2)
|
|
12120
|
+
doSerialize(serialize_serialize.recentBlocks); // C(3)
|
|
12121
|
+
doSerialize(serialize_serialize.safrole); // C(4)
|
|
12122
|
+
doSerialize(serialize_serialize.disputesRecords); // C(5)
|
|
12123
|
+
doSerialize(serialize_serialize.entropy); // C(6)
|
|
12124
|
+
doSerialize(serialize_serialize.designatedValidators); // C(7)
|
|
12125
|
+
doSerialize(serialize_serialize.currentValidators); // C(8)
|
|
12126
|
+
doSerialize(serialize_serialize.previousValidators); // C(9)
|
|
12127
|
+
doSerialize(serialize_serialize.availabilityAssignment); // C(10)
|
|
12128
|
+
doSerialize(serialize_serialize.timeslot); // C(11)
|
|
12129
|
+
doSerialize(serialize_serialize.privilegedServices); // C(12)
|
|
12130
|
+
doSerialize(serialize_serialize.statistics); // C(13)
|
|
12131
|
+
doSerialize(serialize_serialize.accumulationQueue); // C(14)
|
|
12132
|
+
doSerialize(serialize_serialize.recentlyAccumulated); // C(15)
|
|
12133
|
+
doSerialize(serialize_serialize.accumulationOutputLog); // C(16)
|
|
11943
12134
|
// services
|
|
11944
12135
|
for (const [serviceId, service] of state.services.entries()) {
|
|
11945
12136
|
// data
|
|
11946
|
-
const { key, Codec } =
|
|
12137
|
+
const { key, Codec } = serialize_serialize.serviceData(serviceId);
|
|
11947
12138
|
serialized.set(key, encoder_Encoder.encodeObject(Codec, service.getInfo()));
|
|
11948
12139
|
// preimages
|
|
11949
12140
|
for (const preimage of service.data.preimages.values()) {
|
|
11950
|
-
const { key, Codec } =
|
|
12141
|
+
const { key, Codec } = serialize_serialize.servicePreimages(blake2b, serviceId, preimage.hash);
|
|
11951
12142
|
serialized.set(key, encoder_Encoder.encodeObject(Codec, preimage.blob));
|
|
11952
12143
|
}
|
|
11953
12144
|
// storage
|
|
11954
12145
|
for (const storage of service.data.storage.values()) {
|
|
11955
|
-
const { key, Codec } =
|
|
12146
|
+
const { key, Codec } = serialize_serialize.serviceStorage(blake2b, serviceId, storage.key);
|
|
11956
12147
|
serialized.set(key, encoder_Encoder.encodeObject(Codec, storage.value));
|
|
11957
12148
|
}
|
|
11958
12149
|
// lookup history
|
|
11959
12150
|
for (const lookupHistoryList of service.data.lookupHistory.values()) {
|
|
11960
12151
|
for (const lookupHistory of lookupHistoryList) {
|
|
11961
|
-
const { key, Codec } =
|
|
12152
|
+
const { key, Codec } = serialize_serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
11962
12153
|
serialized.set(key, encoder_Encoder.encodeObject(Codec, lookupHistory.slots.slice()));
|
|
11963
12154
|
}
|
|
11964
12155
|
}
|
|
@@ -12008,6 +12199,7 @@ function loadState(spec, blake2b, entries) {
|
|
|
12008
12199
|
|
|
12009
12200
|
|
|
12010
12201
|
|
|
12202
|
+
|
|
12011
12203
|
;// CONCATENATED MODULE: ./packages/jam/database/leaf-db.ts
|
|
12012
12204
|
|
|
12013
12205
|
|
|
@@ -12166,7 +12358,7 @@ const codecMap = (value, extractKey, { typicalLength = TYPICAL_DICTIONARY_LENGTH
|
|
|
12166
12358
|
const lookupHistoryItemCodec = descriptors_codec.object({
|
|
12167
12359
|
hash: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
12168
12360
|
length: descriptors_codec.u32,
|
|
12169
|
-
slots:
|
|
12361
|
+
slots: descriptors_readonlyArray(descriptors_codec.sequenceVarLen(descriptors_codec.u32.asOpaque())).convert(seeThrough, tryAsLookupHistorySlots),
|
|
12170
12362
|
}, "LookupHistoryItem", ({ hash, length, slots }) => new service_LookupHistoryItem(hash, length, slots));
|
|
12171
12363
|
const lookupHistoryEntryCodec = descriptors_codec.object({
|
|
12172
12364
|
key: descriptors_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
@@ -12209,7 +12401,11 @@ class ServiceWithCodec extends InMemoryService {
|
|
|
12209
12401
|
return new ServiceWithCodec(serviceId, data);
|
|
12210
12402
|
}
|
|
12211
12403
|
}
|
|
12212
|
-
const in_memory_state_codec_inMemoryStateCodec =
|
|
12404
|
+
const in_memory_state_codec_inMemoryStateCodec = (spec) => codec.Class(class State extends InMemoryState {
|
|
12405
|
+
static create(data) {
|
|
12406
|
+
return InMemoryState.new(spec, data);
|
|
12407
|
+
}
|
|
12408
|
+
}, {
|
|
12213
12409
|
// alpha
|
|
12214
12410
|
authPools: serialize.authPools.Codec,
|
|
12215
12411
|
// phi
|
|
@@ -12219,11 +12415,11 @@ const in_memory_state_codec_inMemoryStateCodec = descriptors_codec.Class(InMemor
|
|
|
12219
12415
|
// gamma_k
|
|
12220
12416
|
nextValidatorData: codecPerValidator(ValidatorData.Codec),
|
|
12221
12417
|
// gamma_z
|
|
12222
|
-
epochRoot:
|
|
12418
|
+
epochRoot: codec.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
12223
12419
|
// gamma_s
|
|
12224
12420
|
sealingKeySeries: SafroleSealingKeysData.Codec,
|
|
12225
12421
|
// gamma_a
|
|
12226
|
-
ticketsAccumulator: readonlyArray(
|
|
12422
|
+
ticketsAccumulator: readonlyArray(codec.sequenceVarLen(Ticket.Codec)).convert((x) => x, asKnownSize),
|
|
12227
12423
|
// psi
|
|
12228
12424
|
disputesRecords: serialize.disputesRecords.Codec,
|
|
12229
12425
|
// eta
|
|
@@ -12249,7 +12445,7 @@ const in_memory_state_codec_inMemoryStateCodec = descriptors_codec.Class(InMemor
|
|
|
12249
12445
|
// theta
|
|
12250
12446
|
accumulationOutputLog: serialize.accumulationOutputLog.Codec,
|
|
12251
12447
|
// delta
|
|
12252
|
-
services:
|
|
12448
|
+
services: codec.dictionary(codec.u32.asOpaque(), ServiceWithCodec.Codec, {
|
|
12253
12449
|
sortKeys: (a, b) => a - b,
|
|
12254
12450
|
}),
|
|
12255
12451
|
});
|
|
@@ -12296,7 +12492,7 @@ class InMemoryStates {
|
|
|
12296
12492
|
}
|
|
12297
12493
|
/** Insert a full state into the database. */
|
|
12298
12494
|
async insertState(headerHash, state) {
|
|
12299
|
-
const encoded = Encoder.encodeObject(inMemoryStateCodec, state, this.spec);
|
|
12495
|
+
const encoded = Encoder.encodeObject(inMemoryStateCodec(this.spec), state, this.spec);
|
|
12300
12496
|
this.db.set(headerHash, encoded);
|
|
12301
12497
|
return Result.ok(OK);
|
|
12302
12498
|
}
|
|
@@ -12305,7 +12501,7 @@ class InMemoryStates {
|
|
|
12305
12501
|
if (encodedState === undefined) {
|
|
12306
12502
|
return null;
|
|
12307
12503
|
}
|
|
12308
|
-
return Decoder.decodeObject(inMemoryStateCodec, encodedState, this.spec);
|
|
12504
|
+
return Decoder.decodeObject(inMemoryStateCodec(this.spec), encodedState, this.spec);
|
|
12309
12505
|
}
|
|
12310
12506
|
}
|
|
12311
12507
|
|
|
@@ -13492,21 +13688,21 @@ class TransitionHasher {
|
|
|
13492
13688
|
*/
|
|
13493
13689
|
extrinsic(extrinsicView) {
|
|
13494
13690
|
// https://graypaper.fluffylabs.dev/#/cc517d7/0cfb000cfb00?v=0.6.5
|
|
13495
|
-
const
|
|
13691
|
+
const guaranteesCount = numbers_tryAsU32(extrinsicView.guarantees.view().length);
|
|
13692
|
+
const countEncoded = encoder_Encoder.encodeObject(descriptors_codec.varU32, guaranteesCount);
|
|
13693
|
+
const guaranteesBlobs = extrinsicView.guarantees
|
|
13496
13694
|
.view()
|
|
13497
13695
|
.map((g) => g.view())
|
|
13498
|
-
.
|
|
13696
|
+
.reduce((aggregated, guarantee) => {
|
|
13499
13697
|
const reportHash = this.blake2b.hashBytes(guarantee.report.encoded()).asOpaque();
|
|
13500
|
-
|
|
13501
|
-
|
|
13502
|
-
|
|
13503
|
-
|
|
13504
|
-
|
|
13505
|
-
});
|
|
13506
|
-
const guaranteeBlob = encoder_Encoder.encodeObject(descriptors_codec.sequenceVarLen(dumpCodec), guarantees, this.context);
|
|
13698
|
+
aggregated.push(reportHash.raw);
|
|
13699
|
+
aggregated.push(guarantee.slot.encoded().raw);
|
|
13700
|
+
aggregated.push(guarantee.credentials.encoded().raw);
|
|
13701
|
+
return aggregated;
|
|
13702
|
+
}, [countEncoded.raw]);
|
|
13507
13703
|
const et = this.blake2b.hashBytes(extrinsicView.tickets.encoded()).asOpaque();
|
|
13508
13704
|
const ep = this.blake2b.hashBytes(extrinsicView.preimages.encoded()).asOpaque();
|
|
13509
|
-
const eg = this.blake2b.
|
|
13705
|
+
const eg = this.blake2b.hashBlobs(guaranteesBlobs).asOpaque();
|
|
13510
13706
|
const ea = this.blake2b.hashBytes(extrinsicView.assurances.encoded()).asOpaque();
|
|
13511
13707
|
const ed = this.blake2b.hashBytes(extrinsicView.disputes.encoded()).asOpaque();
|
|
13512
13708
|
const encoded = bytes_BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);
|