@typeberry/lib 0.2.0-e767e74 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +758 -911
- package/index.d.ts +697 -980
- package/index.js +758 -911
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -2088,9 +2088,6 @@ class ObjectView {
|
|
|
2088
2088
|
toString() {
|
|
2089
2089
|
return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
|
|
2090
2090
|
}
|
|
2091
|
-
[TEST_COMPARE_USING]() {
|
|
2092
|
-
return this.materialize();
|
|
2093
|
-
}
|
|
2094
2091
|
}
|
|
2095
2092
|
/**
|
|
2096
2093
|
* A lazy-evaluated decoder of a sequence.
|
|
@@ -2376,15 +2373,7 @@ var codec$1;
|
|
|
2376
2373
|
/** Custom encoding / decoding logic. */
|
|
2377
2374
|
codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
|
|
2378
2375
|
/** Choose a descriptor depending on the encoding/decoding context. */
|
|
2379
|
-
codec.select = ({ name, sizeHint, }, chooser) =>
|
|
2380
|
-
const Self = chooser(null);
|
|
2381
|
-
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)
|
|
2382
|
-
? codec.select({
|
|
2383
|
-
name: Self.View.name,
|
|
2384
|
-
sizeHint: Self.View.sizeHint,
|
|
2385
|
-
}, (ctx) => chooser(ctx).View)
|
|
2386
|
-
: Self.View);
|
|
2387
|
-
};
|
|
2376
|
+
codec.select = ({ name, sizeHint, }, chooser) => Descriptor.withView(name, sizeHint, (e, x) => chooser(e.getContext()).encode(e, x), (d) => chooser(d.getContext()).decode(d), (s) => chooser(s.decoder.getContext()).skip(s), chooser(null).View);
|
|
2388
2377
|
/**
|
|
2389
2378
|
* A descriptor for a more complex POJO.
|
|
2390
2379
|
*
|
|
@@ -6683,17 +6672,6 @@ function emptyBlock(slot = tryAsTimeSlot(0)) {
|
|
|
6683
6672
|
});
|
|
6684
6673
|
}
|
|
6685
6674
|
|
|
6686
|
-
/**
|
|
6687
|
-
* Take an input data and re-encode that data as view.
|
|
6688
|
-
*
|
|
6689
|
-
* NOTE: this function should NEVER be used in any production code,
|
|
6690
|
-
* it's only a test helper.
|
|
6691
|
-
*/
|
|
6692
|
-
function reencodeAsView(codec, object, chainSpec) {
|
|
6693
|
-
const encoded = Encoder.encodeObject(codec, object, chainSpec);
|
|
6694
|
-
return Decoder.decodeObject(codec.View, encoded, chainSpec);
|
|
6695
|
-
}
|
|
6696
|
-
|
|
6697
6675
|
var index$l = /*#__PURE__*/Object.freeze({
|
|
6698
6676
|
__proto__: null,
|
|
6699
6677
|
Block: Block,
|
|
@@ -6714,7 +6692,6 @@ var index$l = /*#__PURE__*/Object.freeze({
|
|
|
6714
6692
|
guarantees: guarantees,
|
|
6715
6693
|
headerViewWithHashCodec: headerViewWithHashCodec,
|
|
6716
6694
|
preimage: preimage,
|
|
6717
|
-
reencodeAsView: reencodeAsView,
|
|
6718
6695
|
refineContext: refineContext,
|
|
6719
6696
|
tickets: tickets,
|
|
6720
6697
|
tryAsCoreIndex: tryAsCoreIndex,
|
|
@@ -8065,70 +8042,6 @@ function accumulationOutputComparator(a, b) {
|
|
|
8065
8042
|
return Ordering.Equal;
|
|
8066
8043
|
}
|
|
8067
8044
|
|
|
8068
|
-
/** `O`: Maximum number of items in the authorizations pool. */
|
|
8069
|
-
const O = 8;
|
|
8070
|
-
/** `Q`: The number of items in the authorizations queue. */
|
|
8071
|
-
const Q = 80;
|
|
8072
|
-
/** `W_T`: The size of a transfer memo in octets. */
|
|
8073
|
-
const W_T = 128;
|
|
8074
|
-
/**
|
|
8075
|
-
* `J`: The maximum sum of dependency items in a work-report.
|
|
8076
|
-
*
|
|
8077
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
|
|
8078
|
-
*/
|
|
8079
|
-
const MAX_REPORT_DEPENDENCIES = 8;
|
|
8080
|
-
|
|
8081
|
-
/**
|
|
8082
|
-
* Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
|
|
8083
|
-
*
|
|
8084
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
|
|
8085
|
-
*/
|
|
8086
|
-
class NotYetAccumulatedReport extends WithDebug {
|
|
8087
|
-
report;
|
|
8088
|
-
dependencies;
|
|
8089
|
-
static Codec = codec$1.Class(NotYetAccumulatedReport, {
|
|
8090
|
-
report: WorkReport.Codec,
|
|
8091
|
-
dependencies: codecKnownSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), {
|
|
8092
|
-
typicalLength: MAX_REPORT_DEPENDENCIES / 2,
|
|
8093
|
-
maxLength: MAX_REPORT_DEPENDENCIES,
|
|
8094
|
-
minLength: 0,
|
|
8095
|
-
}),
|
|
8096
|
-
});
|
|
8097
|
-
static create({ report, dependencies }) {
|
|
8098
|
-
return new NotYetAccumulatedReport(report, dependencies);
|
|
8099
|
-
}
|
|
8100
|
-
constructor(
|
|
8101
|
-
/**
|
|
8102
|
-
* Each of these were made available at most one epoch ago
|
|
8103
|
-
* but have or had unfulfilled dependencies.
|
|
8104
|
-
*/
|
|
8105
|
-
report,
|
|
8106
|
-
/**
|
|
8107
|
-
* Alongside the work-report itself, we retain its un-accumulated
|
|
8108
|
-
* dependencies, a set of work-package hashes.
|
|
8109
|
-
*
|
|
8110
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
|
|
8111
|
-
*/
|
|
8112
|
-
dependencies) {
|
|
8113
|
-
super();
|
|
8114
|
-
this.report = report;
|
|
8115
|
-
this.dependencies = dependencies;
|
|
8116
|
-
}
|
|
8117
|
-
}
|
|
8118
|
-
const accumulationQueueCodec = codecPerEpochBlock(readonlyArray(codec$1.sequenceVarLen(NotYetAccumulatedReport.Codec)));
|
|
8119
|
-
|
|
8120
|
-
/** Check if given array has correct length before casting to the opaque type. */
|
|
8121
|
-
function tryAsPerCore(array, spec) {
|
|
8122
|
-
check `
|
|
8123
|
-
${array.length === spec.coresCount}
|
|
8124
|
-
Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
|
|
8125
|
-
`;
|
|
8126
|
-
return asOpaqueType(array);
|
|
8127
|
-
}
|
|
8128
|
-
const codecPerCore = (val) => codecWithContext((context) => {
|
|
8129
|
-
return codecKnownSizeArray(val, { fixedLength: context.coresCount });
|
|
8130
|
-
});
|
|
8131
|
-
|
|
8132
8045
|
/**
|
|
8133
8046
|
* Assignment of particular work report to a core.
|
|
8134
8047
|
*
|
|
@@ -8157,18 +8070,18 @@ class AvailabilityAssignment extends WithDebug {
|
|
|
8157
8070
|
this.timeout = timeout;
|
|
8158
8071
|
}
|
|
8159
8072
|
}
|
|
8160
|
-
const availabilityAssignmentsCodec = codecPerCore(codec$1.optional(AvailabilityAssignment.Codec));
|
|
8161
8073
|
|
|
8162
|
-
/**
|
|
8163
|
-
|
|
8164
|
-
|
|
8165
|
-
|
|
8166
|
-
|
|
8167
|
-
|
|
8168
|
-
|
|
8169
|
-
|
|
8170
|
-
|
|
8171
|
-
|
|
8074
|
+
/** Check if given array has correct length before casting to the opaque type. */
|
|
8075
|
+
function tryAsPerCore(array, spec) {
|
|
8076
|
+
check `
|
|
8077
|
+
${array.length === spec.coresCount}
|
|
8078
|
+
Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
|
|
8079
|
+
`;
|
|
8080
|
+
return asOpaqueType(array);
|
|
8081
|
+
}
|
|
8082
|
+
const codecPerCore = (val) => codecWithContext((context) => {
|
|
8083
|
+
return codecKnownSizeArray(val, { fixedLength: context.coresCount });
|
|
8084
|
+
});
|
|
8172
8085
|
|
|
8173
8086
|
const sortedSetCodec = () => readonlyArray(codec$1.sequenceVarLen(codec$1.bytes(HASH_SIZE))).convert((input) => input.array, (output) => {
|
|
8174
8087
|
const typed = output.map((x) => x.asOpaque());
|
|
@@ -8232,297 +8145,99 @@ function hashComparator(a, b) {
|
|
|
8232
8145
|
return a.compare(b);
|
|
8233
8146
|
}
|
|
8234
8147
|
|
|
8148
|
+
/** `O`: Maximum number of items in the authorizations pool. */
|
|
8149
|
+
const O = 8;
|
|
8150
|
+
/** `Q`: The number of items in the authorizations queue. */
|
|
8151
|
+
const Q = 80;
|
|
8152
|
+
/** `W_T`: The size of a transfer memo in octets. */
|
|
8153
|
+
const W_T = 128;
|
|
8154
|
+
/**
|
|
8155
|
+
* `J`: The maximum sum of dependency items in a work-report.
|
|
8156
|
+
*
|
|
8157
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
|
|
8158
|
+
*/
|
|
8159
|
+
const MAX_REPORT_DEPENDENCIES = 8;
|
|
8160
|
+
/** `Q`: Size of the authorization queue. */
|
|
8161
|
+
const AUTHORIZATION_QUEUE_SIZE = Q;
|
|
8162
|
+
/** `O`: Maximal authorization pool size. */
|
|
8163
|
+
const MAX_AUTH_POOL_SIZE = O;
|
|
8164
|
+
|
|
8235
8165
|
const MAX_VALUE = 4294967295;
|
|
8236
8166
|
const MIN_VALUE = -2147483648;
|
|
8237
8167
|
const MAX_SHIFT_U32 = 32;
|
|
8238
8168
|
const MAX_SHIFT_U64 = 64n;
|
|
8239
8169
|
|
|
8240
8170
|
/**
|
|
8241
|
-
* `
|
|
8171
|
+
* `B_S`: The basic minimum balance which all services require.
|
|
8242
8172
|
*
|
|
8243
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
8173
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
8244
8174
|
*/
|
|
8245
|
-
const
|
|
8246
|
-
/** Recent history of a single block. */
|
|
8247
|
-
class BlockState extends WithDebug {
|
|
8248
|
-
headerHash;
|
|
8249
|
-
accumulationResult;
|
|
8250
|
-
postStateRoot;
|
|
8251
|
-
reported;
|
|
8252
|
-
static Codec = codec$1.Class(BlockState, {
|
|
8253
|
-
headerHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
8254
|
-
accumulationResult: codec$1.bytes(HASH_SIZE),
|
|
8255
|
-
postStateRoot: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
8256
|
-
reported: codecHashDictionary(WorkPackageInfo.Codec, (x) => x.workPackageHash),
|
|
8257
|
-
});
|
|
8258
|
-
static create({ headerHash, accumulationResult, postStateRoot, reported }) {
|
|
8259
|
-
return new BlockState(headerHash, accumulationResult, postStateRoot, reported);
|
|
8260
|
-
}
|
|
8261
|
-
constructor(
|
|
8262
|
-
/** Header hash. */
|
|
8263
|
-
headerHash,
|
|
8264
|
-
/** Merkle mountain belt of accumulation result. */
|
|
8265
|
-
accumulationResult,
|
|
8266
|
-
/** Posterior state root filled in with a 1-block delay. */
|
|
8267
|
-
postStateRoot,
|
|
8268
|
-
/** Reported work packages (no more than number of cores). */
|
|
8269
|
-
reported) {
|
|
8270
|
-
super();
|
|
8271
|
-
this.headerHash = headerHash;
|
|
8272
|
-
this.accumulationResult = accumulationResult;
|
|
8273
|
-
this.postStateRoot = postStateRoot;
|
|
8274
|
-
this.reported = reported;
|
|
8275
|
-
}
|
|
8276
|
-
}
|
|
8175
|
+
const BASE_SERVICE_BALANCE = 100n;
|
|
8277
8176
|
/**
|
|
8278
|
-
*
|
|
8177
|
+
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
8279
8178
|
*
|
|
8280
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/
|
|
8179
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
8281
8180
|
*/
|
|
8282
|
-
|
|
8283
|
-
blocks;
|
|
8284
|
-
accumulationLog;
|
|
8285
|
-
static Codec = codec$1.Class(RecentBlocks, {
|
|
8286
|
-
blocks: codecKnownSizeArray(BlockState.Codec, {
|
|
8287
|
-
minLength: 0,
|
|
8288
|
-
maxLength: MAX_RECENT_HISTORY,
|
|
8289
|
-
typicalLength: MAX_RECENT_HISTORY,
|
|
8290
|
-
}),
|
|
8291
|
-
accumulationLog: codec$1.object({
|
|
8292
|
-
peaks: readonlyArray(codec$1.sequenceVarLen(codec$1.optional(codec$1.bytes(HASH_SIZE)))),
|
|
8293
|
-
}),
|
|
8294
|
-
});
|
|
8295
|
-
static empty() {
|
|
8296
|
-
return new RecentBlocks(asKnownSize([]), {
|
|
8297
|
-
peaks: [],
|
|
8298
|
-
});
|
|
8299
|
-
}
|
|
8300
|
-
static create(a) {
|
|
8301
|
-
return new RecentBlocks(a.blocks, a.accumulationLog);
|
|
8302
|
-
}
|
|
8303
|
-
constructor(
|
|
8304
|
-
/**
|
|
8305
|
-
* Most recent blocks.
|
|
8306
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0fea010fea01?v=0.6.7
|
|
8307
|
-
*/
|
|
8308
|
-
blocks,
|
|
8309
|
-
/**
|
|
8310
|
-
* Accumulation output log.
|
|
8311
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0f02020f0202?v=0.6.7
|
|
8312
|
-
*/
|
|
8313
|
-
accumulationLog) {
|
|
8314
|
-
super();
|
|
8315
|
-
this.blocks = blocks;
|
|
8316
|
-
this.accumulationLog = accumulationLog;
|
|
8317
|
-
}
|
|
8318
|
-
}
|
|
8319
|
-
|
|
8320
|
-
const recentlyAccumulatedCodec = codecPerEpochBlock(codec$1.sequenceVarLen(codec$1.bytes(HASH_SIZE).asOpaque()).convert((x) => Array.from(x), (x) => HashSet.from(x)));
|
|
8321
|
-
|
|
8181
|
+
const ELECTIVE_ITEM_BALANCE = 10n;
|
|
8322
8182
|
/**
|
|
8323
|
-
*
|
|
8183
|
+
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
8324
8184
|
*
|
|
8325
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
8185
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
8326
8186
|
*/
|
|
8327
|
-
const
|
|
8187
|
+
const ELECTIVE_BYTE_BALANCE = 1n;
|
|
8188
|
+
const zeroSizeHint = {
|
|
8189
|
+
bytes: 0,
|
|
8190
|
+
isExact: true,
|
|
8191
|
+
};
|
|
8192
|
+
/** 0-byte read, return given default value */
|
|
8193
|
+
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
8194
|
+
/** Encode and decode object with leading version number. */
|
|
8195
|
+
const codecWithVersion = (val) => Descriptor.new("withVersion", {
|
|
8196
|
+
bytes: val.sizeHint.bytes + 8,
|
|
8197
|
+
isExact: false,
|
|
8198
|
+
}, (e, v) => {
|
|
8199
|
+
e.varU64(0n);
|
|
8200
|
+
val.encode(e, v);
|
|
8201
|
+
}, (d) => {
|
|
8202
|
+
const version = d.varU64();
|
|
8203
|
+
if (version !== 0n) {
|
|
8204
|
+
throw new Error("Non-zero version is not supported!");
|
|
8205
|
+
}
|
|
8206
|
+
return val.decode(d);
|
|
8207
|
+
}, (s) => {
|
|
8208
|
+
s.varU64();
|
|
8209
|
+
val.skip(s);
|
|
8210
|
+
});
|
|
8328
8211
|
/**
|
|
8329
|
-
*
|
|
8212
|
+
* Service account details.
|
|
8330
8213
|
*
|
|
8331
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
8214
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
|
|
8332
8215
|
*/
|
|
8333
|
-
class
|
|
8334
|
-
|
|
8335
|
-
|
|
8336
|
-
|
|
8337
|
-
|
|
8338
|
-
|
|
8339
|
-
|
|
8340
|
-
|
|
8341
|
-
|
|
8342
|
-
|
|
8216
|
+
class ServiceAccountInfo extends WithDebug {
|
|
8217
|
+
codeHash;
|
|
8218
|
+
balance;
|
|
8219
|
+
accumulateMinGas;
|
|
8220
|
+
onTransferMinGas;
|
|
8221
|
+
storageUtilisationBytes;
|
|
8222
|
+
gratisStorage;
|
|
8223
|
+
storageUtilisationCount;
|
|
8224
|
+
created;
|
|
8225
|
+
lastAccumulation;
|
|
8226
|
+
parentService;
|
|
8227
|
+
static Codec = codec$1.Class(ServiceAccountInfo, {
|
|
8228
|
+
codeHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
8229
|
+
balance: codec$1.u64,
|
|
8230
|
+
accumulateMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
|
|
8231
|
+
onTransferMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
|
|
8232
|
+
storageUtilisationBytes: codec$1.u64,
|
|
8233
|
+
gratisStorage: codec$1.u64,
|
|
8234
|
+
storageUtilisationCount: codec$1.u32,
|
|
8235
|
+
created: codec$1.u32.convert((x) => x, tryAsTimeSlot),
|
|
8236
|
+
lastAccumulation: codec$1.u32.convert((x) => x, tryAsTimeSlot),
|
|
8237
|
+
parentService: codec$1.u32.convert((x) => x, tryAsServiceId),
|
|
8343
8238
|
});
|
|
8344
|
-
static create(
|
|
8345
|
-
return new
|
|
8346
|
-
}
|
|
8347
|
-
constructor(
|
|
8348
|
-
/** Bandersnatch public key. */
|
|
8349
|
-
bandersnatch,
|
|
8350
|
-
/** ED25519 key data. */
|
|
8351
|
-
ed25519,
|
|
8352
|
-
/** BLS public key. */
|
|
8353
|
-
bls,
|
|
8354
|
-
/** Validator-defined additional metdata. */
|
|
8355
|
-
metadata) {
|
|
8356
|
-
super();
|
|
8357
|
-
this.bandersnatch = bandersnatch;
|
|
8358
|
-
this.ed25519 = ed25519;
|
|
8359
|
-
this.bls = bls;
|
|
8360
|
-
this.metadata = metadata;
|
|
8361
|
-
}
|
|
8362
|
-
}
|
|
8363
|
-
const validatorsDataCodec = codecPerValidator(ValidatorData.Codec);
|
|
8364
|
-
|
|
8365
|
-
var SafroleSealingKeysKind;
|
|
8366
|
-
(function (SafroleSealingKeysKind) {
|
|
8367
|
-
SafroleSealingKeysKind[SafroleSealingKeysKind["Tickets"] = 0] = "Tickets";
|
|
8368
|
-
SafroleSealingKeysKind[SafroleSealingKeysKind["Keys"] = 1] = "Keys";
|
|
8369
|
-
})(SafroleSealingKeysKind || (SafroleSealingKeysKind = {}));
|
|
8370
|
-
const codecBandersnatchKey = codec$1.bytes(BANDERSNATCH_KEY_BYTES).asOpaque();
|
|
8371
|
-
class SafroleSealingKeysData extends WithDebug {
|
|
8372
|
-
kind;
|
|
8373
|
-
keys;
|
|
8374
|
-
tickets;
|
|
8375
|
-
static Codec = codecWithContext((context) => {
|
|
8376
|
-
return codec$1.custom({
|
|
8377
|
-
name: "SafroleSealingKeys",
|
|
8378
|
-
sizeHint: { bytes: 1 + HASH_SIZE * context.epochLength, isExact: false },
|
|
8379
|
-
}, (e, x) => {
|
|
8380
|
-
e.varU32(tryAsU32(x.kind));
|
|
8381
|
-
if (x.kind === SafroleSealingKeysKind.Keys) {
|
|
8382
|
-
e.sequenceFixLen(codecBandersnatchKey, x.keys);
|
|
8383
|
-
}
|
|
8384
|
-
else {
|
|
8385
|
-
e.sequenceFixLen(Ticket.Codec, x.tickets);
|
|
8386
|
-
}
|
|
8387
|
-
}, (d) => {
|
|
8388
|
-
const epochLength = context.epochLength;
|
|
8389
|
-
const kind = d.varU32();
|
|
8390
|
-
if (kind === SafroleSealingKeysKind.Keys) {
|
|
8391
|
-
const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
|
|
8392
|
-
return SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
|
|
8393
|
-
}
|
|
8394
|
-
if (kind === SafroleSealingKeysKind.Tickets) {
|
|
8395
|
-
const tickets = d.sequenceFixLen(Ticket.Codec, epochLength);
|
|
8396
|
-
return SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
|
|
8397
|
-
}
|
|
8398
|
-
throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
|
|
8399
|
-
}, (s) => {
|
|
8400
|
-
const kind = s.decoder.varU32();
|
|
8401
|
-
if (kind === SafroleSealingKeysKind.Keys) {
|
|
8402
|
-
s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
|
|
8403
|
-
return;
|
|
8404
|
-
}
|
|
8405
|
-
if (kind === SafroleSealingKeysKind.Tickets) {
|
|
8406
|
-
s.sequenceFixLen(Ticket.Codec, context.epochLength);
|
|
8407
|
-
return;
|
|
8408
|
-
}
|
|
8409
|
-
throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
|
|
8410
|
-
});
|
|
8411
|
-
});
|
|
8412
|
-
static keys(keys) {
|
|
8413
|
-
return new SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
|
|
8414
|
-
}
|
|
8415
|
-
static tickets(tickets) {
|
|
8416
|
-
return new SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
|
|
8417
|
-
}
|
|
8418
|
-
constructor(kind, keys, tickets) {
|
|
8419
|
-
super();
|
|
8420
|
-
this.kind = kind;
|
|
8421
|
-
this.keys = keys;
|
|
8422
|
-
this.tickets = tickets;
|
|
8423
|
-
}
|
|
8424
|
-
}
|
|
8425
|
-
class SafroleData {
|
|
8426
|
-
nextValidatorData;
|
|
8427
|
-
epochRoot;
|
|
8428
|
-
sealingKeySeries;
|
|
8429
|
-
ticketsAccumulator;
|
|
8430
|
-
static Codec = codec$1.Class(SafroleData, {
|
|
8431
|
-
nextValidatorData: codecPerValidator(ValidatorData.Codec),
|
|
8432
|
-
epochRoot: codec$1.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
8433
|
-
sealingKeySeries: SafroleSealingKeysData.Codec,
|
|
8434
|
-
ticketsAccumulator: readonlyArray(codec$1.sequenceVarLen(Ticket.Codec)).convert(seeThrough, asKnownSize),
|
|
8435
|
-
});
|
|
8436
|
-
static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
|
|
8437
|
-
return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
|
|
8438
|
-
}
|
|
8439
|
-
constructor(
|
|
8440
|
-
/** gamma_k */
|
|
8441
|
-
nextValidatorData,
|
|
8442
|
-
/** gamma_z */
|
|
8443
|
-
epochRoot,
|
|
8444
|
-
/** gamma_s */
|
|
8445
|
-
sealingKeySeries,
|
|
8446
|
-
/** gamma_a */
|
|
8447
|
-
ticketsAccumulator) {
|
|
8448
|
-
this.nextValidatorData = nextValidatorData;
|
|
8449
|
-
this.epochRoot = epochRoot;
|
|
8450
|
-
this.sealingKeySeries = sealingKeySeries;
|
|
8451
|
-
this.ticketsAccumulator = ticketsAccumulator;
|
|
8452
|
-
}
|
|
8453
|
-
}
|
|
8454
|
-
|
|
8455
|
-
/**
|
|
8456
|
-
* `B_S`: The basic minimum balance which all services require.
|
|
8457
|
-
*
|
|
8458
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
8459
|
-
*/
|
|
8460
|
-
const BASE_SERVICE_BALANCE = 100n;
|
|
8461
|
-
/**
|
|
8462
|
-
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
8463
|
-
*
|
|
8464
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
8465
|
-
*/
|
|
8466
|
-
const ELECTIVE_ITEM_BALANCE = 10n;
|
|
8467
|
-
/**
|
|
8468
|
-
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
8469
|
-
*
|
|
8470
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
8471
|
-
*/
|
|
8472
|
-
const ELECTIVE_BYTE_BALANCE = 1n;
|
|
8473
|
-
const zeroSizeHint = {
|
|
8474
|
-
bytes: 0,
|
|
8475
|
-
isExact: true,
|
|
8476
|
-
};
|
|
8477
|
-
/** 0-byte read, return given default value */
|
|
8478
|
-
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
8479
|
-
/** Encode and decode object with leading version number. */
|
|
8480
|
-
const codecWithVersion = (val) => Descriptor.new("withVersion", {
|
|
8481
|
-
bytes: val.sizeHint.bytes + 8,
|
|
8482
|
-
isExact: false,
|
|
8483
|
-
}, (e, v) => {
|
|
8484
|
-
e.varU64(0n);
|
|
8485
|
-
val.encode(e, v);
|
|
8486
|
-
}, (d) => {
|
|
8487
|
-
const version = d.varU64();
|
|
8488
|
-
if (version !== 0n) {
|
|
8489
|
-
throw new Error("Non-zero version is not supported!");
|
|
8490
|
-
}
|
|
8491
|
-
return val.decode(d);
|
|
8492
|
-
}, (s) => {
|
|
8493
|
-
s.varU64();
|
|
8494
|
-
val.skip(s);
|
|
8495
|
-
});
|
|
8496
|
-
/**
|
|
8497
|
-
* Service account details.
|
|
8498
|
-
*
|
|
8499
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
|
|
8500
|
-
*/
|
|
8501
|
-
class ServiceAccountInfo extends WithDebug {
|
|
8502
|
-
codeHash;
|
|
8503
|
-
balance;
|
|
8504
|
-
accumulateMinGas;
|
|
8505
|
-
onTransferMinGas;
|
|
8506
|
-
storageUtilisationBytes;
|
|
8507
|
-
gratisStorage;
|
|
8508
|
-
storageUtilisationCount;
|
|
8509
|
-
created;
|
|
8510
|
-
lastAccumulation;
|
|
8511
|
-
parentService;
|
|
8512
|
-
static Codec = codec$1.Class(ServiceAccountInfo, {
|
|
8513
|
-
codeHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
8514
|
-
balance: codec$1.u64,
|
|
8515
|
-
accumulateMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
|
|
8516
|
-
onTransferMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
|
|
8517
|
-
storageUtilisationBytes: codec$1.u64,
|
|
8518
|
-
gratisStorage: codec$1.u64,
|
|
8519
|
-
storageUtilisationCount: codec$1.u32,
|
|
8520
|
-
created: codec$1.u32.convert((x) => x, tryAsTimeSlot),
|
|
8521
|
-
lastAccumulation: codec$1.u32.convert((x) => x, tryAsTimeSlot),
|
|
8522
|
-
parentService: codec$1.u32.convert((x) => x, tryAsServiceId),
|
|
8523
|
-
});
|
|
8524
|
-
static create(a) {
|
|
8525
|
-
return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
|
|
8239
|
+
static create(a) {
|
|
8240
|
+
return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
|
|
8526
8241
|
}
|
|
8527
8242
|
/**
|
|
8528
8243
|
* `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
|
|
@@ -8635,394 +8350,329 @@ class LookupHistoryItem {
|
|
|
8635
8350
|
}
|
|
8636
8351
|
}
|
|
8637
8352
|
|
|
8638
|
-
|
|
8639
|
-
|
|
8640
|
-
|
|
8641
|
-
|
|
8642
|
-
|
|
8643
|
-
|
|
8644
|
-
|
|
8645
|
-
*/
|
|
8646
|
-
class ValidatorStatistics {
|
|
8647
|
-
blocks;
|
|
8648
|
-
tickets;
|
|
8649
|
-
preImages;
|
|
8650
|
-
preImagesSize;
|
|
8651
|
-
guarantees;
|
|
8652
|
-
assurances;
|
|
8653
|
-
static Codec = codec$1.Class(ValidatorStatistics, {
|
|
8654
|
-
blocks: codec$1.u32,
|
|
8655
|
-
tickets: codec$1.u32,
|
|
8656
|
-
preImages: codec$1.u32,
|
|
8657
|
-
preImagesSize: codec$1.u32,
|
|
8658
|
-
guarantees: codec$1.u32,
|
|
8659
|
-
assurances: codec$1.u32,
|
|
8353
|
+
/** Dictionary entry of services that auto-accumulate every block. */
|
|
8354
|
+
class AutoAccumulate {
|
|
8355
|
+
service;
|
|
8356
|
+
gasLimit;
|
|
8357
|
+
static Codec = codec$1.Class(AutoAccumulate, {
|
|
8358
|
+
service: codec$1.u32.asOpaque(),
|
|
8359
|
+
gasLimit: codec$1.u64.asOpaque(),
|
|
8660
8360
|
});
|
|
8661
|
-
static create({
|
|
8662
|
-
return new
|
|
8361
|
+
static create({ service, gasLimit }) {
|
|
8362
|
+
return new AutoAccumulate(service, gasLimit);
|
|
8663
8363
|
}
|
|
8664
8364
|
constructor(
|
|
8665
|
-
/**
|
|
8666
|
-
|
|
8667
|
-
/**
|
|
8668
|
-
|
|
8669
|
-
|
|
8670
|
-
|
|
8671
|
-
/** The total number of octets across all preimages introduced by the validator. */
|
|
8672
|
-
preImagesSize,
|
|
8673
|
-
/** The number of reports guaranteed by the validator. */
|
|
8674
|
-
guarantees,
|
|
8675
|
-
/** The number of availability assurances made by the validator. */
|
|
8676
|
-
assurances) {
|
|
8677
|
-
this.blocks = blocks;
|
|
8678
|
-
this.tickets = tickets;
|
|
8679
|
-
this.preImages = preImages;
|
|
8680
|
-
this.preImagesSize = preImagesSize;
|
|
8681
|
-
this.guarantees = guarantees;
|
|
8682
|
-
this.assurances = assurances;
|
|
8683
|
-
}
|
|
8684
|
-
static empty() {
|
|
8685
|
-
const zero = tryAsU32(0);
|
|
8686
|
-
return new ValidatorStatistics(zero, zero, zero, zero, zero, zero);
|
|
8365
|
+
/** Service id that auto-accumulates. */
|
|
8366
|
+
service,
|
|
8367
|
+
/** Gas limit for auto-accumulation. */
|
|
8368
|
+
gasLimit) {
|
|
8369
|
+
this.service = service;
|
|
8370
|
+
this.gasLimit = gasLimit;
|
|
8687
8371
|
}
|
|
8688
8372
|
}
|
|
8689
|
-
const codecVarU16 = codec$1.varU32.convert((i) => tryAsU32(i), (o) => tryAsU16(o));
|
|
8690
|
-
/** Encode/decode unsigned gas. */
|
|
8691
|
-
const codecVarGas = codec$1.varU64.convert((g) => tryAsU64(g), (i) => tryAsServiceGas(i));
|
|
8692
8373
|
/**
|
|
8693
|
-
*
|
|
8694
|
-
* Updated per block, based on incoming work reports (`w`).
|
|
8695
|
-
*
|
|
8696
|
-
* https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
|
|
8697
|
-
* https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
|
|
8374
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
|
|
8698
8375
|
*/
|
|
8699
|
-
class
|
|
8700
|
-
|
|
8701
|
-
|
|
8702
|
-
|
|
8703
|
-
|
|
8704
|
-
|
|
8705
|
-
|
|
8706
|
-
|
|
8707
|
-
|
|
8708
|
-
|
|
8709
|
-
|
|
8710
|
-
|
|
8711
|
-
|
|
8712
|
-
|
|
8713
|
-
|
|
8714
|
-
|
|
8715
|
-
|
|
8716
|
-
|
|
8717
|
-
gasUsed: codecVarGas,
|
|
8718
|
-
})
|
|
8719
|
-
: codec$1.Class(CoreStatistics, {
|
|
8720
|
-
dataAvailabilityLoad: codec$1.varU32,
|
|
8721
|
-
popularity: codecVarU16,
|
|
8722
|
-
imports: codecVarU16,
|
|
8723
|
-
exports: codecVarU16,
|
|
8724
|
-
extrinsicSize: codec$1.varU32,
|
|
8725
|
-
extrinsicCount: codecVarU16,
|
|
8726
|
-
bundleSize: codec$1.varU32,
|
|
8727
|
-
gasUsed: codecVarGas,
|
|
8728
|
-
});
|
|
8729
|
-
static create(v) {
|
|
8730
|
-
return new CoreStatistics(v.dataAvailabilityLoad, v.popularity, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.bundleSize, v.gasUsed);
|
|
8376
|
+
class PrivilegedServices {
|
|
8377
|
+
manager;
|
|
8378
|
+
delegator;
|
|
8379
|
+
registrar;
|
|
8380
|
+
assigners;
|
|
8381
|
+
autoAccumulateServices;
|
|
8382
|
+
/** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
|
|
8383
|
+
static Codec = codec$1.Class(PrivilegedServices, {
|
|
8384
|
+
manager: codec$1.u32.asOpaque(),
|
|
8385
|
+
assigners: codecPerCore(codec$1.u32.asOpaque()),
|
|
8386
|
+
delegator: codec$1.u32.asOpaque(),
|
|
8387
|
+
registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
8388
|
+
? codec$1.u32.asOpaque()
|
|
8389
|
+
: ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
|
|
8390
|
+
autoAccumulateServices: readonlyArray(codec$1.sequenceVarLen(AutoAccumulate.Codec)),
|
|
8391
|
+
});
|
|
8392
|
+
static create(a) {
|
|
8393
|
+
return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
8731
8394
|
}
|
|
8732
8395
|
constructor(
|
|
8733
|
-
/**
|
|
8734
|
-
|
|
8735
|
-
|
|
8736
|
-
|
|
8737
|
-
|
|
8738
|
-
|
|
8739
|
-
/**
|
|
8740
|
-
|
|
8741
|
-
/**
|
|
8742
|
-
|
|
8743
|
-
|
|
8744
|
-
|
|
8745
|
-
|
|
8746
|
-
|
|
8747
|
-
/**
|
|
8748
|
-
|
|
8749
|
-
|
|
8750
|
-
|
|
8751
|
-
this.
|
|
8752
|
-
this.
|
|
8753
|
-
this.
|
|
8754
|
-
this.
|
|
8755
|
-
this.
|
|
8756
|
-
this.gasUsed = gasUsed;
|
|
8757
|
-
}
|
|
8758
|
-
static empty() {
|
|
8759
|
-
const zero = tryAsU32(0);
|
|
8760
|
-
const zero16 = tryAsU16(0);
|
|
8761
|
-
const zeroGas = tryAsServiceGas(0);
|
|
8762
|
-
return new CoreStatistics(zero, zero16, zero16, zero16, zero, zero16, zero, zeroGas);
|
|
8396
|
+
/**
|
|
8397
|
+
* `χ_M`: Manages alteration of χ from block to block,
|
|
8398
|
+
* as well as bestow services with storage deposit credits.
|
|
8399
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
8400
|
+
*/
|
|
8401
|
+
manager,
|
|
8402
|
+
/** `χ_V`: Managers validator keys. */
|
|
8403
|
+
delegator,
|
|
8404
|
+
/**
|
|
8405
|
+
* `χ_R`: Manages the creation of services in protected range.
|
|
8406
|
+
*
|
|
8407
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
|
|
8408
|
+
*/
|
|
8409
|
+
registrar,
|
|
8410
|
+
/** `χ_A`: Manages authorization queue one for each core. */
|
|
8411
|
+
assigners,
|
|
8412
|
+
/** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
|
|
8413
|
+
autoAccumulateServices) {
|
|
8414
|
+
this.manager = manager;
|
|
8415
|
+
this.delegator = delegator;
|
|
8416
|
+
this.registrar = registrar;
|
|
8417
|
+
this.assigners = assigners;
|
|
8418
|
+
this.autoAccumulateServices = autoAccumulateServices;
|
|
8763
8419
|
}
|
|
8764
8420
|
}
|
|
8421
|
+
|
|
8765
8422
|
/**
|
|
8766
|
-
*
|
|
8767
|
-
* Updated per block, based on available work reports (`W`).
|
|
8423
|
+
* `H = 8`: The size of recent history, in blocks.
|
|
8768
8424
|
*
|
|
8769
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
8425
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/416300416500
|
|
8770
8426
|
*/
|
|
8771
|
-
|
|
8772
|
-
|
|
8773
|
-
|
|
8774
|
-
|
|
8775
|
-
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
|
|
8779
|
-
|
|
8780
|
-
|
|
8781
|
-
|
|
8782
|
-
|
|
8783
|
-
onTransfersGasUsed;
|
|
8784
|
-
static Codec = Compatibility.selectIfGreaterOrEqual({
|
|
8785
|
-
fallback: codec$1.Class(ServiceStatistics, {
|
|
8786
|
-
providedCount: codecVarU16,
|
|
8787
|
-
providedSize: codec$1.varU32,
|
|
8788
|
-
refinementCount: codec$1.varU32,
|
|
8789
|
-
refinementGasUsed: codecVarGas,
|
|
8790
|
-
imports: codecVarU16,
|
|
8791
|
-
exports: codecVarU16,
|
|
8792
|
-
extrinsicSize: codec$1.varU32,
|
|
8793
|
-
extrinsicCount: codecVarU16,
|
|
8794
|
-
accumulateCount: codec$1.varU32,
|
|
8795
|
-
accumulateGasUsed: codecVarGas,
|
|
8796
|
-
onTransfersCount: codec$1.varU32,
|
|
8797
|
-
onTransfersGasUsed: codecVarGas,
|
|
8798
|
-
}),
|
|
8799
|
-
versions: {
|
|
8800
|
-
[GpVersion.V0_7_0]: codec$1.Class(ServiceStatistics, {
|
|
8801
|
-
providedCount: codecVarU16,
|
|
8802
|
-
providedSize: codec$1.varU32,
|
|
8803
|
-
refinementCount: codec$1.varU32,
|
|
8804
|
-
refinementGasUsed: codecVarGas,
|
|
8805
|
-
imports: codecVarU16,
|
|
8806
|
-
extrinsicCount: codecVarU16,
|
|
8807
|
-
extrinsicSize: codec$1.varU32,
|
|
8808
|
-
exports: codecVarU16,
|
|
8809
|
-
accumulateCount: codec$1.varU32,
|
|
8810
|
-
accumulateGasUsed: codecVarGas,
|
|
8811
|
-
onTransfersCount: codec$1.varU32,
|
|
8812
|
-
onTransfersGasUsed: codecVarGas,
|
|
8813
|
-
}),
|
|
8814
|
-
[GpVersion.V0_7_1]: codec$1.Class(ServiceStatistics, {
|
|
8815
|
-
providedCount: codecVarU16,
|
|
8816
|
-
providedSize: codec$1.varU32,
|
|
8817
|
-
refinementCount: codec$1.varU32,
|
|
8818
|
-
refinementGasUsed: codecVarGas,
|
|
8819
|
-
imports: codecVarU16,
|
|
8820
|
-
extrinsicCount: codecVarU16,
|
|
8821
|
-
extrinsicSize: codec$1.varU32,
|
|
8822
|
-
exports: codecVarU16,
|
|
8823
|
-
accumulateCount: codec$1.varU32,
|
|
8824
|
-
accumulateGasUsed: codecVarGas,
|
|
8825
|
-
onTransfersCount: ignoreValueWithDefault(tryAsU32(0)),
|
|
8826
|
-
onTransfersGasUsed: ignoreValueWithDefault(tryAsServiceGas(0)),
|
|
8827
|
-
}),
|
|
8828
|
-
},
|
|
8427
|
+
const MAX_RECENT_HISTORY = 8;
|
|
8428
|
+
/** Recent history of a single block. */
|
|
8429
|
+
class BlockState extends WithDebug {
|
|
8430
|
+
headerHash;
|
|
8431
|
+
accumulationResult;
|
|
8432
|
+
postStateRoot;
|
|
8433
|
+
reported;
|
|
8434
|
+
static Codec = codec$1.Class(BlockState, {
|
|
8435
|
+
headerHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
8436
|
+
accumulationResult: codec$1.bytes(HASH_SIZE),
|
|
8437
|
+
postStateRoot: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
8438
|
+
reported: codecHashDictionary(WorkPackageInfo.Codec, (x) => x.workPackageHash),
|
|
8829
8439
|
});
|
|
8830
|
-
static create(
|
|
8831
|
-
return new
|
|
8440
|
+
static create({ headerHash, accumulationResult, postStateRoot, reported }) {
|
|
8441
|
+
return new BlockState(headerHash, accumulationResult, postStateRoot, reported);
|
|
8832
8442
|
}
|
|
8833
8443
|
constructor(
|
|
8834
|
-
/**
|
|
8835
|
-
|
|
8836
|
-
/**
|
|
8837
|
-
|
|
8838
|
-
/**
|
|
8839
|
-
|
|
8840
|
-
/**
|
|
8841
|
-
|
|
8842
|
-
|
|
8843
|
-
|
|
8844
|
-
|
|
8845
|
-
|
|
8846
|
-
|
|
8847
|
-
extrinsicSize,
|
|
8848
|
-
/** `x` */
|
|
8849
|
-
extrinsicCount,
|
|
8850
|
-
/** `a.0` */
|
|
8851
|
-
accumulateCount,
|
|
8852
|
-
/** `a.1` */
|
|
8853
|
-
accumulateGasUsed,
|
|
8854
|
-
/** `t.0` @deprecated since 0.7.1 */
|
|
8855
|
-
onTransfersCount,
|
|
8856
|
-
/** `t.1` @deprecated since 0.7.1 */
|
|
8857
|
-
onTransfersGasUsed) {
|
|
8858
|
-
this.providedCount = providedCount;
|
|
8859
|
-
this.providedSize = providedSize;
|
|
8860
|
-
this.refinementCount = refinementCount;
|
|
8861
|
-
this.refinementGasUsed = refinementGasUsed;
|
|
8862
|
-
this.imports = imports;
|
|
8863
|
-
this.exports = exports;
|
|
8864
|
-
this.extrinsicSize = extrinsicSize;
|
|
8865
|
-
this.extrinsicCount = extrinsicCount;
|
|
8866
|
-
this.accumulateCount = accumulateCount;
|
|
8867
|
-
this.accumulateGasUsed = accumulateGasUsed;
|
|
8868
|
-
this.onTransfersCount = onTransfersCount;
|
|
8869
|
-
this.onTransfersGasUsed = onTransfersGasUsed;
|
|
8870
|
-
}
|
|
8871
|
-
static empty() {
|
|
8872
|
-
const zero = tryAsU32(0);
|
|
8873
|
-
const zero16 = tryAsU16(0);
|
|
8874
|
-
const zeroGas = tryAsServiceGas(0);
|
|
8875
|
-
return new ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
|
|
8444
|
+
/** Header hash. */
|
|
8445
|
+
headerHash,
|
|
8446
|
+
/** Merkle mountain belt of accumulation result. */
|
|
8447
|
+
accumulationResult,
|
|
8448
|
+
/** Posterior state root filled in with a 1-block delay. */
|
|
8449
|
+
postStateRoot,
|
|
8450
|
+
/** Reported work packages (no more than number of cores). */
|
|
8451
|
+
reported) {
|
|
8452
|
+
super();
|
|
8453
|
+
this.headerHash = headerHash;
|
|
8454
|
+
this.accumulationResult = accumulationResult;
|
|
8455
|
+
this.postStateRoot = postStateRoot;
|
|
8456
|
+
this.reported = reported;
|
|
8876
8457
|
}
|
|
8877
8458
|
}
|
|
8878
|
-
|
|
8879
|
-
|
|
8880
|
-
|
|
8881
|
-
|
|
8882
|
-
|
|
8883
|
-
|
|
8884
|
-
|
|
8885
|
-
|
|
8886
|
-
|
|
8887
|
-
|
|
8888
|
-
|
|
8889
|
-
sortKeys: (a, b) => a - b,
|
|
8459
|
+
class RecentBlocks extends WithDebug {
|
|
8460
|
+
blocks;
|
|
8461
|
+
accumulationLog;
|
|
8462
|
+
static Codec = codec$1.Class(RecentBlocks, {
|
|
8463
|
+
blocks: codecKnownSizeArray(BlockState.Codec, {
|
|
8464
|
+
minLength: 0,
|
|
8465
|
+
maxLength: MAX_RECENT_HISTORY,
|
|
8466
|
+
typicalLength: MAX_RECENT_HISTORY,
|
|
8467
|
+
}),
|
|
8468
|
+
accumulationLog: codec$1.object({
|
|
8469
|
+
peaks: readonlyArray(codec$1.sequenceVarLen(codec$1.optional(codec$1.bytes(HASH_SIZE)))),
|
|
8890
8470
|
}),
|
|
8891
8471
|
});
|
|
8892
|
-
static create(
|
|
8893
|
-
return new
|
|
8472
|
+
static create(a) {
|
|
8473
|
+
return new RecentBlocks(a.blocks, a.accumulationLog);
|
|
8894
8474
|
}
|
|
8895
|
-
constructor(
|
|
8896
|
-
|
|
8897
|
-
|
|
8898
|
-
|
|
8899
|
-
|
|
8475
|
+
constructor(
|
|
8476
|
+
/**
|
|
8477
|
+
* Most recent blocks.
|
|
8478
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0fea010fea01?v=0.6.7
|
|
8479
|
+
*/
|
|
8480
|
+
blocks,
|
|
8481
|
+
/**
|
|
8482
|
+
* Accumulation output log.
|
|
8483
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0f02020f0202?v=0.6.7
|
|
8484
|
+
*/
|
|
8485
|
+
accumulationLog) {
|
|
8486
|
+
super();
|
|
8487
|
+
this.blocks = blocks;
|
|
8488
|
+
this.accumulationLog = accumulationLog;
|
|
8900
8489
|
}
|
|
8901
8490
|
}
|
|
8902
|
-
|
|
8903
|
-
|
|
8904
|
-
|
|
8905
|
-
|
|
8906
|
-
|
|
8907
|
-
|
|
8908
|
-
|
|
8909
|
-
|
|
8910
|
-
|
|
8911
|
-
return
|
|
8912
|
-
}
|
|
8913
|
-
|
|
8914
|
-
|
|
8915
|
-
|
|
8916
|
-
|
|
8917
|
-
return reencodeAsView(validatorsDataCodec, this.state.currentValidatorData, this.chainSpec);
|
|
8918
|
-
}
|
|
8919
|
-
previousValidatorDataView() {
|
|
8920
|
-
return reencodeAsView(validatorsDataCodec, this.state.previousValidatorData, this.chainSpec);
|
|
8491
|
+
/**
|
|
8492
|
+
* Recent history of blocks.
|
|
8493
|
+
*
|
|
8494
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
|
|
8495
|
+
*/
|
|
8496
|
+
class RecentBlocksHistory extends WithDebug {
|
|
8497
|
+
current;
|
|
8498
|
+
static Codec = Descriptor.new("RecentBlocksHistory", RecentBlocks.Codec.sizeHint, (encoder, value) => RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
|
|
8499
|
+
const recentBlocks = RecentBlocks.Codec.decode(decoder);
|
|
8500
|
+
return RecentBlocksHistory.create(recentBlocks);
|
|
8501
|
+
}, (skip) => {
|
|
8502
|
+
return RecentBlocks.Codec.skip(skip);
|
|
8503
|
+
});
|
|
8504
|
+
static create(recentBlocks) {
|
|
8505
|
+
return new RecentBlocksHistory(recentBlocks);
|
|
8921
8506
|
}
|
|
8922
|
-
|
|
8923
|
-
return
|
|
8507
|
+
static empty() {
|
|
8508
|
+
return RecentBlocksHistory.create(RecentBlocks.create({
|
|
8509
|
+
blocks: asKnownSize([]),
|
|
8510
|
+
accumulationLog: { peaks: [] },
|
|
8511
|
+
}));
|
|
8924
8512
|
}
|
|
8925
|
-
|
|
8926
|
-
|
|
8513
|
+
/**
|
|
8514
|
+
* Returns the block's BEEFY super peak.
|
|
8515
|
+
*/
|
|
8516
|
+
static accumulationResult(block) {
|
|
8517
|
+
return block.accumulationResult;
|
|
8927
8518
|
}
|
|
8928
|
-
|
|
8929
|
-
|
|
8519
|
+
constructor(current) {
|
|
8520
|
+
super();
|
|
8521
|
+
this.current = current;
|
|
8930
8522
|
}
|
|
8931
|
-
|
|
8932
|
-
|
|
8523
|
+
/** History of recent blocks with maximum size of `MAX_RECENT_HISTORY` */
|
|
8524
|
+
get blocks() {
|
|
8525
|
+
if (this.current !== null) {
|
|
8526
|
+
return this.current.blocks;
|
|
8527
|
+
}
|
|
8528
|
+
throw new Error("RecentBlocksHistory is in invalid state");
|
|
8933
8529
|
}
|
|
8934
|
-
|
|
8935
|
-
|
|
8530
|
+
asCurrent() {
|
|
8531
|
+
if (this.current === null) {
|
|
8532
|
+
throw new Error("Cannot access current RecentBlocks format");
|
|
8533
|
+
}
|
|
8534
|
+
return this.current;
|
|
8936
8535
|
}
|
|
8937
|
-
|
|
8938
|
-
|
|
8536
|
+
updateBlocks(blocks) {
|
|
8537
|
+
if (this.current !== null) {
|
|
8538
|
+
return RecentBlocksHistory.create(RecentBlocks.create({
|
|
8539
|
+
...this.current,
|
|
8540
|
+
blocks: asOpaqueType(blocks),
|
|
8541
|
+
}));
|
|
8542
|
+
}
|
|
8543
|
+
throw new Error("RecentBlocksHistory is in invalid state. Cannot be updated!");
|
|
8939
8544
|
}
|
|
8940
|
-
|
|
8941
|
-
|
|
8942
|
-
|
|
8943
|
-
|
|
8944
|
-
|
|
8945
|
-
|
|
8946
|
-
|
|
8947
|
-
|
|
8948
|
-
|
|
8949
|
-
|
|
8545
|
+
}
|
|
8546
|
+
|
|
8547
|
+
/**
|
|
8548
|
+
* Fixed size of validator metadata.
|
|
8549
|
+
*
|
|
8550
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/0d55010d5501
|
|
8551
|
+
*/
|
|
8552
|
+
const VALIDATOR_META_BYTES = 128;
|
|
8553
|
+
/**
|
|
8554
|
+
* Details about validators' identity.
|
|
8555
|
+
*
|
|
8556
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/0d4b010d4c01
|
|
8557
|
+
*/
|
|
8558
|
+
class ValidatorData extends WithDebug {
|
|
8559
|
+
bandersnatch;
|
|
8560
|
+
ed25519;
|
|
8561
|
+
bls;
|
|
8562
|
+
metadata;
|
|
8563
|
+
static Codec = codec$1.Class(ValidatorData, {
|
|
8564
|
+
bandersnatch: codec$1.bytes(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
8565
|
+
ed25519: codec$1.bytes(ED25519_KEY_BYTES).asOpaque(),
|
|
8566
|
+
bls: codec$1.bytes(BLS_KEY_BYTES).asOpaque(),
|
|
8567
|
+
metadata: codec$1.bytes(VALIDATOR_META_BYTES),
|
|
8568
|
+
});
|
|
8569
|
+
static create({ ed25519, bandersnatch, bls, metadata }) {
|
|
8570
|
+
return new ValidatorData(bandersnatch, ed25519, bls, metadata);
|
|
8950
8571
|
}
|
|
8951
|
-
|
|
8952
|
-
|
|
8953
|
-
|
|
8954
|
-
|
|
8955
|
-
|
|
8956
|
-
|
|
8572
|
+
constructor(
|
|
8573
|
+
/** Bandersnatch public key. */
|
|
8574
|
+
bandersnatch,
|
|
8575
|
+
/** ED25519 key data. */
|
|
8576
|
+
ed25519,
|
|
8577
|
+
/** BLS public key. */
|
|
8578
|
+
bls,
|
|
8579
|
+
/** Validator-defined additional metdata. */
|
|
8580
|
+
metadata) {
|
|
8581
|
+
super();
|
|
8582
|
+
this.bandersnatch = bandersnatch;
|
|
8583
|
+
this.ed25519 = ed25519;
|
|
8584
|
+
this.bls = bls;
|
|
8585
|
+
this.metadata = metadata;
|
|
8957
8586
|
}
|
|
8958
8587
|
}
|
|
8959
8588
|
|
|
8960
|
-
|
|
8961
|
-
|
|
8962
|
-
|
|
8963
|
-
|
|
8964
|
-
|
|
8965
|
-
|
|
8966
|
-
|
|
8589
|
+
var SafroleSealingKeysKind;
|
|
8590
|
+
(function (SafroleSealingKeysKind) {
|
|
8591
|
+
SafroleSealingKeysKind[SafroleSealingKeysKind["Tickets"] = 0] = "Tickets";
|
|
8592
|
+
SafroleSealingKeysKind[SafroleSealingKeysKind["Keys"] = 1] = "Keys";
|
|
8593
|
+
})(SafroleSealingKeysKind || (SafroleSealingKeysKind = {}));
|
|
8594
|
+
const codecBandersnatchKey = codec$1.bytes(BANDERSNATCH_KEY_BYTES).asOpaque();
|
|
8595
|
+
class SafroleSealingKeysData extends WithDebug {
|
|
8596
|
+
kind;
|
|
8597
|
+
keys;
|
|
8598
|
+
tickets;
|
|
8599
|
+
static Codec = codecWithContext((context) => {
|
|
8600
|
+
return codec$1.custom({
|
|
8601
|
+
name: "SafroleSealingKeys",
|
|
8602
|
+
sizeHint: { bytes: 1 + HASH_SIZE * context.epochLength, isExact: false },
|
|
8603
|
+
}, (e, x) => {
|
|
8604
|
+
e.varU32(tryAsU32(x.kind));
|
|
8605
|
+
if (x.kind === SafroleSealingKeysKind.Keys) {
|
|
8606
|
+
e.sequenceFixLen(codecBandersnatchKey, x.keys);
|
|
8607
|
+
}
|
|
8608
|
+
else {
|
|
8609
|
+
e.sequenceFixLen(Ticket.Codec, x.tickets);
|
|
8610
|
+
}
|
|
8611
|
+
}, (d) => {
|
|
8612
|
+
const epochLength = context.epochLength;
|
|
8613
|
+
const kind = d.varU32();
|
|
8614
|
+
if (kind === SafroleSealingKeysKind.Keys) {
|
|
8615
|
+
const keys = d.sequenceFixLen(codecBandersnatchKey, epochLength);
|
|
8616
|
+
return SafroleSealingKeysData.keys(tryAsPerEpochBlock(keys, context));
|
|
8617
|
+
}
|
|
8618
|
+
if (kind === SafroleSealingKeysKind.Tickets) {
|
|
8619
|
+
const tickets = d.sequenceFixLen(Ticket.Codec, epochLength);
|
|
8620
|
+
return SafroleSealingKeysData.tickets(tryAsPerEpochBlock(tickets, context));
|
|
8621
|
+
}
|
|
8622
|
+
throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
|
|
8623
|
+
}, (s) => {
|
|
8624
|
+
const kind = s.decoder.varU32();
|
|
8625
|
+
if (kind === SafroleSealingKeysKind.Keys) {
|
|
8626
|
+
s.sequenceFixLen(codecBandersnatchKey, context.epochLength);
|
|
8627
|
+
return;
|
|
8628
|
+
}
|
|
8629
|
+
if (kind === SafroleSealingKeysKind.Tickets) {
|
|
8630
|
+
s.sequenceFixLen(Ticket.Codec, context.epochLength);
|
|
8631
|
+
return;
|
|
8632
|
+
}
|
|
8633
|
+
throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
|
|
8634
|
+
});
|
|
8967
8635
|
});
|
|
8968
|
-
static
|
|
8969
|
-
return new
|
|
8636
|
+
static keys(keys) {
|
|
8637
|
+
return new SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
|
|
8970
8638
|
}
|
|
8971
|
-
|
|
8972
|
-
|
|
8973
|
-
|
|
8974
|
-
|
|
8975
|
-
|
|
8976
|
-
this.
|
|
8977
|
-
this.
|
|
8639
|
+
static tickets(tickets) {
|
|
8640
|
+
return new SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
|
|
8641
|
+
}
|
|
8642
|
+
constructor(kind, keys, tickets) {
|
|
8643
|
+
super();
|
|
8644
|
+
this.kind = kind;
|
|
8645
|
+
this.keys = keys;
|
|
8646
|
+
this.tickets = tickets;
|
|
8978
8647
|
}
|
|
8979
8648
|
}
|
|
8980
|
-
|
|
8981
|
-
|
|
8982
|
-
|
|
8983
|
-
|
|
8984
|
-
|
|
8985
|
-
|
|
8986
|
-
|
|
8987
|
-
|
|
8988
|
-
|
|
8989
|
-
|
|
8990
|
-
static Codec = codec$1.Class(PrivilegedServices, {
|
|
8991
|
-
manager: codec$1.u32.asOpaque(),
|
|
8992
|
-
assigners: codecPerCore(codec$1.u32.asOpaque()),
|
|
8993
|
-
delegator: codec$1.u32.asOpaque(),
|
|
8994
|
-
registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
8995
|
-
? codec$1.u32.asOpaque()
|
|
8996
|
-
: ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
|
|
8997
|
-
autoAccumulateServices: readonlyArray(codec$1.sequenceVarLen(AutoAccumulate.Codec)),
|
|
8649
|
+
class SafroleData {
|
|
8650
|
+
nextValidatorData;
|
|
8651
|
+
epochRoot;
|
|
8652
|
+
sealingKeySeries;
|
|
8653
|
+
ticketsAccumulator;
|
|
8654
|
+
static Codec = codec$1.Class(SafroleData, {
|
|
8655
|
+
nextValidatorData: codecPerValidator(ValidatorData.Codec),
|
|
8656
|
+
epochRoot: codec$1.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
8657
|
+
sealingKeySeries: SafroleSealingKeysData.Codec,
|
|
8658
|
+
ticketsAccumulator: readonlyArray(codec$1.sequenceVarLen(Ticket.Codec)).convert(seeThrough, asKnownSize),
|
|
8998
8659
|
});
|
|
8999
|
-
static create(
|
|
9000
|
-
return new
|
|
8660
|
+
static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
|
|
8661
|
+
return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
|
|
9001
8662
|
}
|
|
9002
8663
|
constructor(
|
|
9003
|
-
/**
|
|
9004
|
-
|
|
9005
|
-
|
|
9006
|
-
|
|
9007
|
-
|
|
9008
|
-
|
|
9009
|
-
/**
|
|
9010
|
-
|
|
9011
|
-
|
|
9012
|
-
|
|
9013
|
-
|
|
9014
|
-
|
|
9015
|
-
*/
|
|
9016
|
-
registrar,
|
|
9017
|
-
/** `χ_A`: Manages authorization queue one for each core. */
|
|
9018
|
-
assigners,
|
|
9019
|
-
/** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
|
|
9020
|
-
autoAccumulateServices) {
|
|
9021
|
-
this.manager = manager;
|
|
9022
|
-
this.delegator = delegator;
|
|
9023
|
-
this.registrar = registrar;
|
|
9024
|
-
this.assigners = assigners;
|
|
9025
|
-
this.autoAccumulateServices = autoAccumulateServices;
|
|
8664
|
+
/** gamma_k */
|
|
8665
|
+
nextValidatorData,
|
|
8666
|
+
/** gamma_z */
|
|
8667
|
+
epochRoot,
|
|
8668
|
+
/** gamma_s */
|
|
8669
|
+
sealingKeySeries,
|
|
8670
|
+
/** gamma_a */
|
|
8671
|
+
ticketsAccumulator) {
|
|
8672
|
+
this.nextValidatorData = nextValidatorData;
|
|
8673
|
+
this.epochRoot = epochRoot;
|
|
8674
|
+
this.sealingKeySeries = sealingKeySeries;
|
|
8675
|
+
this.ticketsAccumulator = ticketsAccumulator;
|
|
9026
8676
|
}
|
|
9027
8677
|
}
|
|
9028
8678
|
|
|
@@ -9135,51 +8785,316 @@ class UpdateService {
|
|
|
9135
8785
|
account: serviceInfo,
|
|
9136
8786
|
});
|
|
9137
8787
|
}
|
|
9138
|
-
static create({ serviceId, serviceInfo, lookupHistory, }) {
|
|
9139
|
-
return new UpdateService(serviceId, {
|
|
9140
|
-
kind: UpdateServiceKind.Create,
|
|
9141
|
-
account: serviceInfo,
|
|
9142
|
-
lookupHistory,
|
|
9143
|
-
});
|
|
8788
|
+
static create({ serviceId, serviceInfo, lookupHistory, }) {
|
|
8789
|
+
return new UpdateService(serviceId, {
|
|
8790
|
+
kind: UpdateServiceKind.Create,
|
|
8791
|
+
account: serviceInfo,
|
|
8792
|
+
lookupHistory,
|
|
8793
|
+
});
|
|
8794
|
+
}
|
|
8795
|
+
}
|
|
8796
|
+
/** Update service storage kind. */
|
|
8797
|
+
var UpdateStorageKind;
|
|
8798
|
+
(function (UpdateStorageKind) {
|
|
8799
|
+
/** Set a storage value. */
|
|
8800
|
+
UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
|
|
8801
|
+
/** Remove a storage value. */
|
|
8802
|
+
UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
|
|
8803
|
+
})(UpdateStorageKind || (UpdateStorageKind = {}));
|
|
8804
|
+
/**
|
|
8805
|
+
* Update service storage item.
|
|
8806
|
+
*
|
|
8807
|
+
* Can either create/modify an entry or remove it.
|
|
8808
|
+
*/
|
|
8809
|
+
class UpdateStorage {
|
|
8810
|
+
serviceId;
|
|
8811
|
+
action;
|
|
8812
|
+
constructor(serviceId, action) {
|
|
8813
|
+
this.serviceId = serviceId;
|
|
8814
|
+
this.action = action;
|
|
8815
|
+
}
|
|
8816
|
+
static set({ serviceId, storage }) {
|
|
8817
|
+
return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Set, storage });
|
|
8818
|
+
}
|
|
8819
|
+
static remove({ serviceId, key }) {
|
|
8820
|
+
return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Remove, key });
|
|
8821
|
+
}
|
|
8822
|
+
get key() {
|
|
8823
|
+
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
8824
|
+
return this.action.key;
|
|
8825
|
+
}
|
|
8826
|
+
return this.action.storage.key;
|
|
8827
|
+
}
|
|
8828
|
+
get value() {
|
|
8829
|
+
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
8830
|
+
return null;
|
|
8831
|
+
}
|
|
8832
|
+
return this.action.storage.value;
|
|
8833
|
+
}
|
|
8834
|
+
}
|
|
8835
|
+
|
|
8836
|
+
const codecServiceId = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
|
|
8837
|
+
? codec$1.u32.asOpaque()
|
|
8838
|
+
: codec$1.varU32.convert((s) => tryAsU32(s), (i) => tryAsServiceId(i));
|
|
8839
|
+
/**
|
|
8840
|
+
* Activity Record of a single validator.
|
|
8841
|
+
*
|
|
8842
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/183701183701
|
|
8843
|
+
*/
|
|
8844
|
+
class ValidatorStatistics {
|
|
8845
|
+
blocks;
|
|
8846
|
+
tickets;
|
|
8847
|
+
preImages;
|
|
8848
|
+
preImagesSize;
|
|
8849
|
+
guarantees;
|
|
8850
|
+
assurances;
|
|
8851
|
+
static Codec = codec$1.Class(ValidatorStatistics, {
|
|
8852
|
+
blocks: codec$1.u32,
|
|
8853
|
+
tickets: codec$1.u32,
|
|
8854
|
+
preImages: codec$1.u32,
|
|
8855
|
+
preImagesSize: codec$1.u32,
|
|
8856
|
+
guarantees: codec$1.u32,
|
|
8857
|
+
assurances: codec$1.u32,
|
|
8858
|
+
});
|
|
8859
|
+
static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
|
|
8860
|
+
return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
|
|
8861
|
+
}
|
|
8862
|
+
constructor(
|
|
8863
|
+
/** The number of blocks produced by the validator. */
|
|
8864
|
+
blocks,
|
|
8865
|
+
/** The number of tickets introduced by the validator. */
|
|
8866
|
+
tickets,
|
|
8867
|
+
/** The number of preimages introduced by the validator. */
|
|
8868
|
+
preImages,
|
|
8869
|
+
/** The total number of octets across all preimages introduced by the validator. */
|
|
8870
|
+
preImagesSize,
|
|
8871
|
+
/** The number of reports guaranteed by the validator. */
|
|
8872
|
+
guarantees,
|
|
8873
|
+
/** The number of availability assurances made by the validator. */
|
|
8874
|
+
assurances) {
|
|
8875
|
+
this.blocks = blocks;
|
|
8876
|
+
this.tickets = tickets;
|
|
8877
|
+
this.preImages = preImages;
|
|
8878
|
+
this.preImagesSize = preImagesSize;
|
|
8879
|
+
this.guarantees = guarantees;
|
|
8880
|
+
this.assurances = assurances;
|
|
8881
|
+
}
|
|
8882
|
+
static empty() {
|
|
8883
|
+
const zero = tryAsU32(0);
|
|
8884
|
+
return new ValidatorStatistics(zero, zero, zero, zero, zero, zero);
|
|
8885
|
+
}
|
|
8886
|
+
}
|
|
8887
|
+
const codecVarU16 = codec$1.varU32.convert((i) => tryAsU32(i), (o) => tryAsU16(o));
|
|
8888
|
+
/** Encode/decode unsigned gas. */
|
|
8889
|
+
const codecVarGas = codec$1.varU64.convert((g) => tryAsU64(g), (i) => tryAsServiceGas(i));
|
|
8890
|
+
/**
|
|
8891
|
+
* Single core statistics.
|
|
8892
|
+
* Updated per block, based on incoming work reports (`w`).
|
|
8893
|
+
*
|
|
8894
|
+
* https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
|
|
8895
|
+
* https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
|
|
8896
|
+
*/
|
|
8897
|
+
class CoreStatistics {
|
|
8898
|
+
dataAvailabilityLoad;
|
|
8899
|
+
popularity;
|
|
8900
|
+
imports;
|
|
8901
|
+
exports;
|
|
8902
|
+
extrinsicSize;
|
|
8903
|
+
extrinsicCount;
|
|
8904
|
+
bundleSize;
|
|
8905
|
+
gasUsed;
|
|
8906
|
+
static Codec = Compatibility.isGreaterOrEqual(GpVersion.V0_7_0)
|
|
8907
|
+
? codec$1.Class(CoreStatistics, {
|
|
8908
|
+
dataAvailabilityLoad: codec$1.varU32,
|
|
8909
|
+
popularity: codecVarU16,
|
|
8910
|
+
imports: codecVarU16,
|
|
8911
|
+
extrinsicCount: codecVarU16,
|
|
8912
|
+
extrinsicSize: codec$1.varU32,
|
|
8913
|
+
exports: codecVarU16,
|
|
8914
|
+
bundleSize: codec$1.varU32,
|
|
8915
|
+
gasUsed: codecVarGas,
|
|
8916
|
+
})
|
|
8917
|
+
: codec$1.Class(CoreStatistics, {
|
|
8918
|
+
dataAvailabilityLoad: codec$1.varU32,
|
|
8919
|
+
popularity: codecVarU16,
|
|
8920
|
+
imports: codecVarU16,
|
|
8921
|
+
exports: codecVarU16,
|
|
8922
|
+
extrinsicSize: codec$1.varU32,
|
|
8923
|
+
extrinsicCount: codecVarU16,
|
|
8924
|
+
bundleSize: codec$1.varU32,
|
|
8925
|
+
gasUsed: codecVarGas,
|
|
8926
|
+
});
|
|
8927
|
+
static create(v) {
|
|
8928
|
+
return new CoreStatistics(v.dataAvailabilityLoad, v.popularity, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.bundleSize, v.gasUsed);
|
|
8929
|
+
}
|
|
8930
|
+
constructor(
|
|
8931
|
+
/** `d` */
|
|
8932
|
+
dataAvailabilityLoad,
|
|
8933
|
+
/** `p` */
|
|
8934
|
+
popularity,
|
|
8935
|
+
/** `i` */
|
|
8936
|
+
imports,
|
|
8937
|
+
/** `e` */
|
|
8938
|
+
exports,
|
|
8939
|
+
/** `z` */
|
|
8940
|
+
extrinsicSize,
|
|
8941
|
+
/** `x` */
|
|
8942
|
+
extrinsicCount,
|
|
8943
|
+
/** `b` */
|
|
8944
|
+
bundleSize,
|
|
8945
|
+
/** `u` */
|
|
8946
|
+
gasUsed) {
|
|
8947
|
+
this.dataAvailabilityLoad = dataAvailabilityLoad;
|
|
8948
|
+
this.popularity = popularity;
|
|
8949
|
+
this.imports = imports;
|
|
8950
|
+
this.exports = exports;
|
|
8951
|
+
this.extrinsicSize = extrinsicSize;
|
|
8952
|
+
this.extrinsicCount = extrinsicCount;
|
|
8953
|
+
this.bundleSize = bundleSize;
|
|
8954
|
+
this.gasUsed = gasUsed;
|
|
8955
|
+
}
|
|
8956
|
+
static empty() {
|
|
8957
|
+
const zero = tryAsU32(0);
|
|
8958
|
+
const zero16 = tryAsU16(0);
|
|
8959
|
+
const zeroGas = tryAsServiceGas(0);
|
|
8960
|
+
return new CoreStatistics(zero, zero16, zero16, zero16, zero, zero16, zero, zeroGas);
|
|
9144
8961
|
}
|
|
9145
8962
|
}
|
|
9146
|
-
/** Update service storage kind. */
|
|
9147
|
-
var UpdateStorageKind;
|
|
9148
|
-
(function (UpdateStorageKind) {
|
|
9149
|
-
/** Set a storage value. */
|
|
9150
|
-
UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
|
|
9151
|
-
/** Remove a storage value. */
|
|
9152
|
-
UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
|
|
9153
|
-
})(UpdateStorageKind || (UpdateStorageKind = {}));
|
|
9154
8963
|
/**
|
|
9155
|
-
*
|
|
8964
|
+
* Service statistics.
|
|
8965
|
+
* Updated per block, based on available work reports (`W`).
|
|
9156
8966
|
*
|
|
9157
|
-
*
|
|
8967
|
+
* https://graypaper.fluffylabs.dev/#/1c979cb/199802199802?v=0.7.1
|
|
9158
8968
|
*/
|
|
9159
|
-
class
|
|
9160
|
-
|
|
9161
|
-
|
|
9162
|
-
|
|
9163
|
-
|
|
9164
|
-
|
|
8969
|
+
class ServiceStatistics {
|
|
8970
|
+
providedCount;
|
|
8971
|
+
providedSize;
|
|
8972
|
+
refinementCount;
|
|
8973
|
+
refinementGasUsed;
|
|
8974
|
+
imports;
|
|
8975
|
+
exports;
|
|
8976
|
+
extrinsicSize;
|
|
8977
|
+
extrinsicCount;
|
|
8978
|
+
accumulateCount;
|
|
8979
|
+
accumulateGasUsed;
|
|
8980
|
+
onTransfersCount;
|
|
8981
|
+
onTransfersGasUsed;
|
|
8982
|
+
static Codec = Compatibility.selectIfGreaterOrEqual({
|
|
8983
|
+
fallback: codec$1.Class(ServiceStatistics, {
|
|
8984
|
+
providedCount: codecVarU16,
|
|
8985
|
+
providedSize: codec$1.varU32,
|
|
8986
|
+
refinementCount: codec$1.varU32,
|
|
8987
|
+
refinementGasUsed: codecVarGas,
|
|
8988
|
+
imports: codecVarU16,
|
|
8989
|
+
exports: codecVarU16,
|
|
8990
|
+
extrinsicSize: codec$1.varU32,
|
|
8991
|
+
extrinsicCount: codecVarU16,
|
|
8992
|
+
accumulateCount: codec$1.varU32,
|
|
8993
|
+
accumulateGasUsed: codecVarGas,
|
|
8994
|
+
onTransfersCount: codec$1.varU32,
|
|
8995
|
+
onTransfersGasUsed: codecVarGas,
|
|
8996
|
+
}),
|
|
8997
|
+
versions: {
|
|
8998
|
+
[GpVersion.V0_7_0]: codec$1.Class(ServiceStatistics, {
|
|
8999
|
+
providedCount: codecVarU16,
|
|
9000
|
+
providedSize: codec$1.varU32,
|
|
9001
|
+
refinementCount: codec$1.varU32,
|
|
9002
|
+
refinementGasUsed: codecVarGas,
|
|
9003
|
+
imports: codecVarU16,
|
|
9004
|
+
extrinsicCount: codecVarU16,
|
|
9005
|
+
extrinsicSize: codec$1.varU32,
|
|
9006
|
+
exports: codecVarU16,
|
|
9007
|
+
accumulateCount: codec$1.varU32,
|
|
9008
|
+
accumulateGasUsed: codecVarGas,
|
|
9009
|
+
onTransfersCount: codec$1.varU32,
|
|
9010
|
+
onTransfersGasUsed: codecVarGas,
|
|
9011
|
+
}),
|
|
9012
|
+
[GpVersion.V0_7_1]: codec$1.Class(ServiceStatistics, {
|
|
9013
|
+
providedCount: codecVarU16,
|
|
9014
|
+
providedSize: codec$1.varU32,
|
|
9015
|
+
refinementCount: codec$1.varU32,
|
|
9016
|
+
refinementGasUsed: codecVarGas,
|
|
9017
|
+
imports: codecVarU16,
|
|
9018
|
+
extrinsicCount: codecVarU16,
|
|
9019
|
+
extrinsicSize: codec$1.varU32,
|
|
9020
|
+
exports: codecVarU16,
|
|
9021
|
+
accumulateCount: codec$1.varU32,
|
|
9022
|
+
accumulateGasUsed: codecVarGas,
|
|
9023
|
+
onTransfersCount: ignoreValueWithDefault(tryAsU32(0)),
|
|
9024
|
+
onTransfersGasUsed: ignoreValueWithDefault(tryAsServiceGas(0)),
|
|
9025
|
+
}),
|
|
9026
|
+
},
|
|
9027
|
+
});
|
|
9028
|
+
static create(v) {
|
|
9029
|
+
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);
|
|
9165
9030
|
}
|
|
9166
|
-
|
|
9167
|
-
|
|
9031
|
+
constructor(
|
|
9032
|
+
/** `p.0` */
|
|
9033
|
+
providedCount,
|
|
9034
|
+
/** `p.1` */
|
|
9035
|
+
providedSize,
|
|
9036
|
+
/** `r.0` */
|
|
9037
|
+
refinementCount,
|
|
9038
|
+
/** `r.1` */
|
|
9039
|
+
refinementGasUsed,
|
|
9040
|
+
/** `i` */
|
|
9041
|
+
imports,
|
|
9042
|
+
/** `e` */
|
|
9043
|
+
exports,
|
|
9044
|
+
/** `z` */
|
|
9045
|
+
extrinsicSize,
|
|
9046
|
+
/** `x` */
|
|
9047
|
+
extrinsicCount,
|
|
9048
|
+
/** `a.0` */
|
|
9049
|
+
accumulateCount,
|
|
9050
|
+
/** `a.1` */
|
|
9051
|
+
accumulateGasUsed,
|
|
9052
|
+
/** `t.0` @deprecated since 0.7.1 */
|
|
9053
|
+
onTransfersCount,
|
|
9054
|
+
/** `t.1` @deprecated since 0.7.1 */
|
|
9055
|
+
onTransfersGasUsed) {
|
|
9056
|
+
this.providedCount = providedCount;
|
|
9057
|
+
this.providedSize = providedSize;
|
|
9058
|
+
this.refinementCount = refinementCount;
|
|
9059
|
+
this.refinementGasUsed = refinementGasUsed;
|
|
9060
|
+
this.imports = imports;
|
|
9061
|
+
this.exports = exports;
|
|
9062
|
+
this.extrinsicSize = extrinsicSize;
|
|
9063
|
+
this.extrinsicCount = extrinsicCount;
|
|
9064
|
+
this.accumulateCount = accumulateCount;
|
|
9065
|
+
this.accumulateGasUsed = accumulateGasUsed;
|
|
9066
|
+
this.onTransfersCount = onTransfersCount;
|
|
9067
|
+
this.onTransfersGasUsed = onTransfersGasUsed;
|
|
9168
9068
|
}
|
|
9169
|
-
static
|
|
9170
|
-
|
|
9069
|
+
static empty() {
|
|
9070
|
+
const zero = tryAsU32(0);
|
|
9071
|
+
const zero16 = tryAsU16(0);
|
|
9072
|
+
const zeroGas = tryAsServiceGas(0);
|
|
9073
|
+
return new ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
|
|
9171
9074
|
}
|
|
9172
|
-
|
|
9173
|
-
|
|
9174
|
-
|
|
9175
|
-
|
|
9176
|
-
|
|
9075
|
+
}
|
|
9076
|
+
/** `pi`: Statistics of each validator, cores statistics and services statistics. */
|
|
9077
|
+
class StatisticsData {
|
|
9078
|
+
current;
|
|
9079
|
+
previous;
|
|
9080
|
+
cores;
|
|
9081
|
+
services;
|
|
9082
|
+
static Codec = codec$1.Class(StatisticsData, {
|
|
9083
|
+
current: codecPerValidator(ValidatorStatistics.Codec),
|
|
9084
|
+
previous: codecPerValidator(ValidatorStatistics.Codec),
|
|
9085
|
+
cores: codecPerCore(CoreStatistics.Codec),
|
|
9086
|
+
services: codec$1.dictionary(codecServiceId, ServiceStatistics.Codec, {
|
|
9087
|
+
sortKeys: (a, b) => a - b,
|
|
9088
|
+
}),
|
|
9089
|
+
});
|
|
9090
|
+
static create(v) {
|
|
9091
|
+
return new StatisticsData(v.current, v.previous, v.cores, v.services);
|
|
9177
9092
|
}
|
|
9178
|
-
|
|
9179
|
-
|
|
9180
|
-
|
|
9181
|
-
|
|
9182
|
-
|
|
9093
|
+
constructor(current, previous, cores, services) {
|
|
9094
|
+
this.current = current;
|
|
9095
|
+
this.previous = previous;
|
|
9096
|
+
this.cores = cores;
|
|
9097
|
+
this.services = services;
|
|
9183
9098
|
}
|
|
9184
9099
|
}
|
|
9185
9100
|
|
|
@@ -9282,10 +9197,9 @@ class InMemoryService extends WithDebug {
|
|
|
9282
9197
|
* A special version of state, stored fully in-memory.
|
|
9283
9198
|
*/
|
|
9284
9199
|
class InMemoryState extends WithDebug {
|
|
9285
|
-
chainSpec;
|
|
9286
9200
|
/** Create a new `InMemoryState` by providing all required fields. */
|
|
9287
|
-
static
|
|
9288
|
-
return new InMemoryState(
|
|
9201
|
+
static create(state) {
|
|
9202
|
+
return new InMemoryState(state);
|
|
9289
9203
|
}
|
|
9290
9204
|
/**
|
|
9291
9205
|
* Create a new `InMemoryState` with a partial state override.
|
|
@@ -9301,7 +9215,7 @@ class InMemoryState extends WithDebug {
|
|
|
9301
9215
|
/**
|
|
9302
9216
|
* Create a new `InMemoryState` from some other state object.
|
|
9303
9217
|
*/
|
|
9304
|
-
static copyFrom(
|
|
9218
|
+
static copyFrom(other, servicesData) {
|
|
9305
9219
|
const services = new Map();
|
|
9306
9220
|
for (const [id, entries] of servicesData.entries()) {
|
|
9307
9221
|
const service = other.getService(id);
|
|
@@ -9311,7 +9225,7 @@ class InMemoryState extends WithDebug {
|
|
|
9311
9225
|
const inMemService = InMemoryService.copyFrom(service, entries);
|
|
9312
9226
|
services.set(id, inMemService);
|
|
9313
9227
|
}
|
|
9314
|
-
return InMemoryState.
|
|
9228
|
+
return InMemoryState.create({
|
|
9315
9229
|
availabilityAssignment: other.availabilityAssignment,
|
|
9316
9230
|
accumulationQueue: other.accumulationQueue,
|
|
9317
9231
|
designatedValidatorData: other.designatedValidatorData,
|
|
@@ -9508,9 +9422,8 @@ class InMemoryState extends WithDebug {
|
|
|
9508
9422
|
getService(id) {
|
|
9509
9423
|
return this.services.get(id) ?? null;
|
|
9510
9424
|
}
|
|
9511
|
-
constructor(
|
|
9425
|
+
constructor(s) {
|
|
9512
9426
|
super();
|
|
9513
|
-
this.chainSpec = chainSpec;
|
|
9514
9427
|
this.availabilityAssignment = s.availabilityAssignment;
|
|
9515
9428
|
this.designatedValidatorData = s.designatedValidatorData;
|
|
9516
9429
|
this.nextValidatorData = s.nextValidatorData;
|
|
@@ -9532,14 +9445,11 @@ class InMemoryState extends WithDebug {
|
|
|
9532
9445
|
this.accumulationOutputLog = s.accumulationOutputLog;
|
|
9533
9446
|
this.services = s.services;
|
|
9534
9447
|
}
|
|
9535
|
-
view() {
|
|
9536
|
-
return new InMemoryStateView(this.chainSpec, this);
|
|
9537
|
-
}
|
|
9538
9448
|
/**
|
|
9539
9449
|
* Create an empty and possibly incoherent `InMemoryState`.
|
|
9540
9450
|
*/
|
|
9541
9451
|
static empty(spec) {
|
|
9542
|
-
return new InMemoryState(
|
|
9452
|
+
return new InMemoryState({
|
|
9543
9453
|
availabilityAssignment: tryAsPerCore(Array.from({ length: spec.coresCount }, () => null), spec),
|
|
9544
9454
|
designatedValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
|
|
9545
9455
|
bandersnatch: Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
@@ -9575,7 +9485,7 @@ class InMemoryState extends WithDebug {
|
|
|
9575
9485
|
entropy: FixedSizeArray.fill(() => Bytes.zero(HASH_SIZE).asOpaque(), ENTROPY_ENTRIES),
|
|
9576
9486
|
authPools: tryAsPerCore(Array.from({ length: spec.coresCount }, () => asKnownSize([])), spec),
|
|
9577
9487
|
authQueues: tryAsPerCore(Array.from({ length: spec.coresCount }, () => FixedSizeArray.fill(() => Bytes.zero(HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE)), spec),
|
|
9578
|
-
recentBlocks:
|
|
9488
|
+
recentBlocks: RecentBlocksHistory.empty(),
|
|
9579
9489
|
statistics: StatisticsData.create({
|
|
9580
9490
|
current: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
|
|
9581
9491
|
previous: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
|
|
@@ -9613,7 +9523,6 @@ const serviceDataCodec = codec$1.dictionary(codec$1.u32.asOpaque(), serviceEntri
|
|
|
9613
9523
|
|
|
9614
9524
|
var index$g = /*#__PURE__*/Object.freeze({
|
|
9615
9525
|
__proto__: null,
|
|
9616
|
-
AUTHORIZATION_QUEUE_SIZE: AUTHORIZATION_QUEUE_SIZE,
|
|
9617
9526
|
AccumulationOutput: AccumulationOutput,
|
|
9618
9527
|
AutoAccumulate: AutoAccumulate,
|
|
9619
9528
|
AvailabilityAssignment: AvailabilityAssignment,
|
|
@@ -9627,12 +9536,11 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
9627
9536
|
InMemoryService: InMemoryService,
|
|
9628
9537
|
InMemoryState: InMemoryState,
|
|
9629
9538
|
LookupHistoryItem: LookupHistoryItem,
|
|
9630
|
-
MAX_AUTH_POOL_SIZE: MAX_AUTH_POOL_SIZE,
|
|
9631
9539
|
MAX_RECENT_HISTORY: MAX_RECENT_HISTORY,
|
|
9632
|
-
NotYetAccumulatedReport: NotYetAccumulatedReport,
|
|
9633
9540
|
PreimageItem: PreimageItem,
|
|
9634
9541
|
PrivilegedServices: PrivilegedServices,
|
|
9635
9542
|
RecentBlocks: RecentBlocks,
|
|
9543
|
+
RecentBlocksHistory: RecentBlocksHistory,
|
|
9636
9544
|
SafroleData: SafroleData,
|
|
9637
9545
|
SafroleSealingKeysData: SafroleSealingKeysData,
|
|
9638
9546
|
get SafroleSealingKeysKind () { return SafroleSealingKeysKind; },
|
|
@@ -9651,35 +9559,71 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
9651
9559
|
ValidatorData: ValidatorData,
|
|
9652
9560
|
ValidatorStatistics: ValidatorStatistics,
|
|
9653
9561
|
accumulationOutputComparator: accumulationOutputComparator,
|
|
9654
|
-
accumulationQueueCodec: accumulationQueueCodec,
|
|
9655
|
-
authPoolsCodec: authPoolsCodec,
|
|
9656
|
-
authQueuesCodec: authQueuesCodec,
|
|
9657
|
-
availabilityAssignmentsCodec: availabilityAssignmentsCodec,
|
|
9658
9562
|
codecPerCore: codecPerCore,
|
|
9659
9563
|
codecWithVersion: codecWithVersion,
|
|
9660
9564
|
hashComparator: hashComparator,
|
|
9661
9565
|
ignoreValueWithDefault: ignoreValueWithDefault,
|
|
9662
|
-
recentlyAccumulatedCodec: recentlyAccumulatedCodec,
|
|
9663
9566
|
serviceDataCodec: serviceDataCodec,
|
|
9664
9567
|
serviceEntriesCodec: serviceEntriesCodec,
|
|
9665
9568
|
tryAsLookupHistorySlots: tryAsLookupHistorySlots,
|
|
9666
|
-
tryAsPerCore: tryAsPerCore
|
|
9667
|
-
validatorsDataCodec: validatorsDataCodec
|
|
9569
|
+
tryAsPerCore: tryAsPerCore
|
|
9668
9570
|
});
|
|
9669
9571
|
|
|
9572
|
+
/**
|
|
9573
|
+
* Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
|
|
9574
|
+
*
|
|
9575
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
|
|
9576
|
+
*/
|
|
9577
|
+
class NotYetAccumulatedReport extends WithDebug {
|
|
9578
|
+
report;
|
|
9579
|
+
dependencies;
|
|
9580
|
+
static Codec = codec$1.Class(NotYetAccumulatedReport, {
|
|
9581
|
+
report: WorkReport.Codec,
|
|
9582
|
+
dependencies: codecKnownSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), {
|
|
9583
|
+
typicalLength: MAX_REPORT_DEPENDENCIES / 2,
|
|
9584
|
+
maxLength: MAX_REPORT_DEPENDENCIES,
|
|
9585
|
+
minLength: 0,
|
|
9586
|
+
}),
|
|
9587
|
+
});
|
|
9588
|
+
static create({ report, dependencies }) {
|
|
9589
|
+
return new NotYetAccumulatedReport(report, dependencies);
|
|
9590
|
+
}
|
|
9591
|
+
constructor(
|
|
9592
|
+
/**
|
|
9593
|
+
* Each of these were made available at most one epoch ago
|
|
9594
|
+
* but have or had unfulfilled dependencies.
|
|
9595
|
+
*/
|
|
9596
|
+
report,
|
|
9597
|
+
/**
|
|
9598
|
+
* Alongside the work-report itself, we retain its un-accumulated
|
|
9599
|
+
* dependencies, a set of work-package hashes.
|
|
9600
|
+
*
|
|
9601
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
|
|
9602
|
+
*/
|
|
9603
|
+
dependencies) {
|
|
9604
|
+
super();
|
|
9605
|
+
this.report = report;
|
|
9606
|
+
this.dependencies = dependencies;
|
|
9607
|
+
}
|
|
9608
|
+
}
|
|
9609
|
+
|
|
9670
9610
|
/** Serialization for particular state entries. */
|
|
9671
9611
|
var serialize;
|
|
9672
9612
|
(function (serialize) {
|
|
9673
9613
|
/** C(1): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b15013b1501?v=0.6.7 */
|
|
9674
9614
|
serialize.authPools = {
|
|
9675
9615
|
key: stateKeys.index(StateKeyIdx.Alpha),
|
|
9676
|
-
Codec:
|
|
9616
|
+
Codec: codecPerCore(codecKnownSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), {
|
|
9617
|
+
minLength: 0,
|
|
9618
|
+
maxLength: MAX_AUTH_POOL_SIZE,
|
|
9619
|
+
typicalLength: MAX_AUTH_POOL_SIZE,
|
|
9620
|
+
})),
|
|
9677
9621
|
extract: (s) => s.authPools,
|
|
9678
9622
|
};
|
|
9679
9623
|
/** C(2): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b31013b3101?v=0.6.7 */
|
|
9680
9624
|
serialize.authQueues = {
|
|
9681
9625
|
key: stateKeys.index(StateKeyIdx.Phi),
|
|
9682
|
-
Codec:
|
|
9626
|
+
Codec: codecPerCore(codecFixedSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE)),
|
|
9683
9627
|
extract: (s) => s.authQueues,
|
|
9684
9628
|
};
|
|
9685
9629
|
/**
|
|
@@ -9688,7 +9632,7 @@ var serialize;
|
|
|
9688
9632
|
*/
|
|
9689
9633
|
serialize.recentBlocks = {
|
|
9690
9634
|
key: stateKeys.index(StateKeyIdx.Beta),
|
|
9691
|
-
Codec:
|
|
9635
|
+
Codec: RecentBlocksHistory.Codec,
|
|
9692
9636
|
extract: (s) => s.recentBlocks,
|
|
9693
9637
|
};
|
|
9694
9638
|
/** C(4): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b63013b6301?v=0.6.7 */
|
|
@@ -9717,25 +9661,25 @@ var serialize;
|
|
|
9717
9661
|
/** C(7): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b00023b0002?v=0.6.7 */
|
|
9718
9662
|
serialize.designatedValidators = {
|
|
9719
9663
|
key: stateKeys.index(StateKeyIdx.Iota),
|
|
9720
|
-
Codec:
|
|
9664
|
+
Codec: codecPerValidator(ValidatorData.Codec),
|
|
9721
9665
|
extract: (s) => s.designatedValidatorData,
|
|
9722
9666
|
};
|
|
9723
9667
|
/** C(8): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b0d023b0d02?v=0.6.7 */
|
|
9724
9668
|
serialize.currentValidators = {
|
|
9725
9669
|
key: stateKeys.index(StateKeyIdx.Kappa),
|
|
9726
|
-
Codec:
|
|
9670
|
+
Codec: codecPerValidator(ValidatorData.Codec),
|
|
9727
9671
|
extract: (s) => s.currentValidatorData,
|
|
9728
9672
|
};
|
|
9729
9673
|
/** C(9): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b1a023b1a02?v=0.6.7 */
|
|
9730
9674
|
serialize.previousValidators = {
|
|
9731
9675
|
key: stateKeys.index(StateKeyIdx.Lambda),
|
|
9732
|
-
Codec:
|
|
9676
|
+
Codec: codecPerValidator(ValidatorData.Codec),
|
|
9733
9677
|
extract: (s) => s.previousValidatorData,
|
|
9734
9678
|
};
|
|
9735
9679
|
/** C(10): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b27023b2702?v=0.6.7 */
|
|
9736
9680
|
serialize.availabilityAssignment = {
|
|
9737
9681
|
key: stateKeys.index(StateKeyIdx.Rho),
|
|
9738
|
-
Codec:
|
|
9682
|
+
Codec: codecPerCore(codec$1.optional(AvailabilityAssignment.Codec)),
|
|
9739
9683
|
extract: (s) => s.availabilityAssignment,
|
|
9740
9684
|
};
|
|
9741
9685
|
/** C(11): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b3e023b3e02?v=0.6.7 */
|
|
@@ -9759,13 +9703,13 @@ var serialize;
|
|
|
9759
9703
|
/** C(14): https://graypaper.fluffylabs.dev/#/1c979cb/3bf0023bf002?v=0.7.1 */
|
|
9760
9704
|
serialize.accumulationQueue = {
|
|
9761
9705
|
key: stateKeys.index(StateKeyIdx.Omega),
|
|
9762
|
-
Codec:
|
|
9706
|
+
Codec: codecPerEpochBlock(readonlyArray(codec$1.sequenceVarLen(NotYetAccumulatedReport.Codec))),
|
|
9763
9707
|
extract: (s) => s.accumulationQueue,
|
|
9764
9708
|
};
|
|
9765
9709
|
/** C(15): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b96023b9602?v=0.6.7 */
|
|
9766
9710
|
serialize.recentlyAccumulated = {
|
|
9767
9711
|
key: stateKeys.index(StateKeyIdx.Xi),
|
|
9768
|
-
Codec:
|
|
9712
|
+
Codec: codecPerEpochBlock(codec$1.sequenceVarLen(codec$1.bytes(HASH_SIZE).asOpaque()).convert((x) => Array.from(x), (x) => HashSet.from(x))),
|
|
9769
9713
|
extract: (s) => s.recentlyAccumulated,
|
|
9770
9714
|
};
|
|
9771
9715
|
/** C(16): https://graypaper.fluffylabs.dev/#/38c4e62/3b46033b4603?v=0.7.0 */
|
|
@@ -9806,84 +9750,6 @@ var serialize;
|
|
|
9806
9750
|
*/
|
|
9807
9751
|
const dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }, (e, v) => e.bytes(Bytes.fromBlob(v.raw, v.raw.length)), (d) => BytesBlob.blobFrom(d.bytes(d.source.length - d.bytesRead()).raw), (s) => s.bytes(s.decoder.source.length - s.decoder.bytesRead()));
|
|
9808
9752
|
|
|
9809
|
-
class SerializedStateView {
|
|
9810
|
-
spec;
|
|
9811
|
-
backend;
|
|
9812
|
-
recentlyUsedServices;
|
|
9813
|
-
viewCache;
|
|
9814
|
-
constructor(spec, backend,
|
|
9815
|
-
/** Best-effort list of recently active services. */
|
|
9816
|
-
recentlyUsedServices, viewCache) {
|
|
9817
|
-
this.spec = spec;
|
|
9818
|
-
this.backend = backend;
|
|
9819
|
-
this.recentlyUsedServices = recentlyUsedServices;
|
|
9820
|
-
this.viewCache = viewCache;
|
|
9821
|
-
}
|
|
9822
|
-
retrieveView({ key, Codec }, description) {
|
|
9823
|
-
const cached = this.viewCache.get(key);
|
|
9824
|
-
if (cached !== undefined) {
|
|
9825
|
-
return cached;
|
|
9826
|
-
}
|
|
9827
|
-
const bytes = this.backend.get(key);
|
|
9828
|
-
if (bytes === null) {
|
|
9829
|
-
throw new Error(`Required state entry for ${description} is missing!. Accessing view of key: ${key}`);
|
|
9830
|
-
}
|
|
9831
|
-
// NOTE [ToDr] we are not using `Decoder.decodeObject` here because
|
|
9832
|
-
// it needs to get to the end of the data (skip), yet that's expensive.
|
|
9833
|
-
// we assume that the state data is correct and coherent anyway, so
|
|
9834
|
-
// for performance reasons we simply create the view here.
|
|
9835
|
-
const d = Decoder.fromBytesBlob(bytes);
|
|
9836
|
-
d.attachContext(this.spec);
|
|
9837
|
-
const view = Codec.View.decode(d);
|
|
9838
|
-
this.viewCache.set(key, view);
|
|
9839
|
-
return view;
|
|
9840
|
-
}
|
|
9841
|
-
availabilityAssignmentView() {
|
|
9842
|
-
return this.retrieveView(serialize.availabilityAssignment, "availabilityAssignmentView");
|
|
9843
|
-
}
|
|
9844
|
-
designatedValidatorDataView() {
|
|
9845
|
-
return this.retrieveView(serialize.designatedValidators, "designatedValidatorsView");
|
|
9846
|
-
}
|
|
9847
|
-
currentValidatorDataView() {
|
|
9848
|
-
return this.retrieveView(serialize.currentValidators, "currentValidatorsView");
|
|
9849
|
-
}
|
|
9850
|
-
previousValidatorDataView() {
|
|
9851
|
-
return this.retrieveView(serialize.previousValidators, "previousValidatorsView");
|
|
9852
|
-
}
|
|
9853
|
-
authPoolsView() {
|
|
9854
|
-
return this.retrieveView(serialize.authPools, "authPoolsView");
|
|
9855
|
-
}
|
|
9856
|
-
authQueuesView() {
|
|
9857
|
-
return this.retrieveView(serialize.authQueues, "authQueuesView");
|
|
9858
|
-
}
|
|
9859
|
-
recentBlocksView() {
|
|
9860
|
-
return this.retrieveView(serialize.recentBlocks, "recentBlocksView");
|
|
9861
|
-
}
|
|
9862
|
-
statisticsView() {
|
|
9863
|
-
return this.retrieveView(serialize.statistics, "statisticsView");
|
|
9864
|
-
}
|
|
9865
|
-
accumulationQueueView() {
|
|
9866
|
-
return this.retrieveView(serialize.accumulationQueue, "accumulationQueueView");
|
|
9867
|
-
}
|
|
9868
|
-
recentlyAccumulatedView() {
|
|
9869
|
-
return this.retrieveView(serialize.recentlyAccumulated, "recentlyAccumulatedView");
|
|
9870
|
-
}
|
|
9871
|
-
safroleDataView() {
|
|
9872
|
-
return this.retrieveView(serialize.safrole, "safroleDataView");
|
|
9873
|
-
}
|
|
9874
|
-
getServiceInfoView(id) {
|
|
9875
|
-
const serviceData = serialize.serviceData(id);
|
|
9876
|
-
const bytes = this.backend.get(serviceData.key);
|
|
9877
|
-
if (bytes === null) {
|
|
9878
|
-
return null;
|
|
9879
|
-
}
|
|
9880
|
-
if (!this.recentlyUsedServices.includes(id)) {
|
|
9881
|
-
this.recentlyUsedServices.push(id);
|
|
9882
|
-
}
|
|
9883
|
-
return Decoder.decodeObject(serviceData.Codec.View, bytes, this.spec);
|
|
9884
|
-
}
|
|
9885
|
-
}
|
|
9886
|
-
|
|
9887
9753
|
/**
|
|
9888
9754
|
* State object which reads it's entries from some backend.
|
|
9889
9755
|
*
|
|
@@ -9896,7 +9762,7 @@ class SerializedState {
|
|
|
9896
9762
|
spec;
|
|
9897
9763
|
blake2b;
|
|
9898
9764
|
backend;
|
|
9899
|
-
|
|
9765
|
+
_recentServiceIds;
|
|
9900
9766
|
/** Create a state-like object from collection of serialized entries. */
|
|
9901
9767
|
static fromStateEntries(spec, blake2b, state, recentServices = []) {
|
|
9902
9768
|
return new SerializedState(spec, blake2b, state, recentServices);
|
|
@@ -9905,63 +9771,49 @@ class SerializedState {
|
|
|
9905
9771
|
static new(spec, blake2b, db, recentServices = []) {
|
|
9906
9772
|
return new SerializedState(spec, blake2b, db, recentServices);
|
|
9907
9773
|
}
|
|
9908
|
-
dataCache = HashDictionary.new();
|
|
9909
|
-
viewCache = HashDictionary.new();
|
|
9910
9774
|
constructor(spec, blake2b, backend,
|
|
9911
9775
|
/** Best-effort list of recently active services. */
|
|
9912
|
-
|
|
9776
|
+
_recentServiceIds) {
|
|
9913
9777
|
this.spec = spec;
|
|
9914
9778
|
this.blake2b = blake2b;
|
|
9915
9779
|
this.backend = backend;
|
|
9916
|
-
this.
|
|
9780
|
+
this._recentServiceIds = _recentServiceIds;
|
|
9917
9781
|
}
|
|
9918
9782
|
/** Comparing the serialized states, just means comparing their backends. */
|
|
9919
9783
|
[TEST_COMPARE_USING]() {
|
|
9920
9784
|
return this.backend;
|
|
9921
9785
|
}
|
|
9922
|
-
/** Return a non-decoding version of the state. */
|
|
9923
|
-
view() {
|
|
9924
|
-
return new SerializedStateView(this.spec, this.backend, this.recentlyUsedServices, this.viewCache);
|
|
9925
|
-
}
|
|
9926
9786
|
// TODO [ToDr] Temporary method to update the state,
|
|
9927
9787
|
// without changing references.
|
|
9928
9788
|
updateBackend(newBackend) {
|
|
9929
9789
|
this.backend = newBackend;
|
|
9930
|
-
this.dataCache = HashDictionary.new();
|
|
9931
|
-
this.viewCache = HashDictionary.new();
|
|
9932
9790
|
}
|
|
9933
9791
|
recentServiceIds() {
|
|
9934
|
-
return this.
|
|
9792
|
+
return this._recentServiceIds;
|
|
9935
9793
|
}
|
|
9936
9794
|
getService(id) {
|
|
9937
9795
|
const serviceData = this.retrieveOptional(serialize.serviceData(id));
|
|
9938
9796
|
if (serviceData === undefined) {
|
|
9939
9797
|
return null;
|
|
9940
9798
|
}
|
|
9941
|
-
if (!this.
|
|
9942
|
-
this.
|
|
9799
|
+
if (!this._recentServiceIds.includes(id)) {
|
|
9800
|
+
this._recentServiceIds.push(id);
|
|
9943
9801
|
}
|
|
9944
9802
|
return new SerializedService(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
|
|
9945
9803
|
}
|
|
9946
|
-
retrieve(
|
|
9947
|
-
const
|
|
9948
|
-
if (
|
|
9949
|
-
throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${
|
|
9804
|
+
retrieve({ key, Codec }, description) {
|
|
9805
|
+
const bytes = this.backend.get(key);
|
|
9806
|
+
if (bytes === null) {
|
|
9807
|
+
throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${key}`);
|
|
9950
9808
|
}
|
|
9951
|
-
return
|
|
9809
|
+
return Decoder.decodeObject(Codec, bytes, this.spec);
|
|
9952
9810
|
}
|
|
9953
9811
|
retrieveOptional({ key, Codec }) {
|
|
9954
|
-
const cached = this.dataCache.get(key);
|
|
9955
|
-
if (cached !== undefined) {
|
|
9956
|
-
return cached;
|
|
9957
|
-
}
|
|
9958
9812
|
const bytes = this.backend.get(key);
|
|
9959
9813
|
if (bytes === null) {
|
|
9960
9814
|
return undefined;
|
|
9961
9815
|
}
|
|
9962
|
-
|
|
9963
|
-
this.dataCache.set(key, data);
|
|
9964
|
-
return data;
|
|
9816
|
+
return Decoder.decodeObject(Codec, bytes, this.spec);
|
|
9965
9817
|
}
|
|
9966
9818
|
get availabilityAssignment() {
|
|
9967
9819
|
return this.retrieve(serialize.availabilityAssignment, "availabilityAssignment");
|
|
@@ -11039,7 +10891,6 @@ var index$e = /*#__PURE__*/Object.freeze({
|
|
|
11039
10891
|
__proto__: null,
|
|
11040
10892
|
SerializedService: SerializedService,
|
|
11041
10893
|
SerializedState: SerializedState,
|
|
11042
|
-
SerializedStateView: SerializedStateView,
|
|
11043
10894
|
StateEntries: StateEntries,
|
|
11044
10895
|
get StateEntryUpdateAction () { return StateEntryUpdateAction; },
|
|
11045
10896
|
get StateKeyIdx () { return StateKeyIdx; },
|
|
@@ -11232,11 +11083,7 @@ class ServiceWithCodec extends InMemoryService {
|
|
|
11232
11083
|
return new ServiceWithCodec(serviceId, data);
|
|
11233
11084
|
}
|
|
11234
11085
|
}
|
|
11235
|
-
const inMemoryStateCodec =
|
|
11236
|
-
static create(data) {
|
|
11237
|
-
return InMemoryState.new(spec, data);
|
|
11238
|
-
}
|
|
11239
|
-
}, {
|
|
11086
|
+
const inMemoryStateCodec = codec$1.Class(InMemoryState, {
|
|
11240
11087
|
// alpha
|
|
11241
11088
|
authPools: serialize.authPools.Codec,
|
|
11242
11089
|
// phi
|
|
@@ -11315,7 +11162,7 @@ class InMemoryStates {
|
|
|
11315
11162
|
}
|
|
11316
11163
|
/** Insert a full state into the database. */
|
|
11317
11164
|
async insertState(headerHash, state) {
|
|
11318
|
-
const encoded = Encoder.encodeObject(inMemoryStateCodec
|
|
11165
|
+
const encoded = Encoder.encodeObject(inMemoryStateCodec, state, this.spec);
|
|
11319
11166
|
this.db.set(headerHash, encoded);
|
|
11320
11167
|
return Result$1.ok(OK);
|
|
11321
11168
|
}
|
|
@@ -11324,7 +11171,7 @@ class InMemoryStates {
|
|
|
11324
11171
|
if (encodedState === undefined) {
|
|
11325
11172
|
return null;
|
|
11326
11173
|
}
|
|
11327
|
-
return Decoder.decodeObject(inMemoryStateCodec
|
|
11174
|
+
return Decoder.decodeObject(inMemoryStateCodec, encodedState, this.spec);
|
|
11328
11175
|
}
|
|
11329
11176
|
}
|
|
11330
11177
|
|
|
@@ -17254,10 +17101,10 @@ const recentBlocksHistoryFromJson = json.object({
|
|
|
17254
17101
|
peaks: json.array(json.nullable(fromJson.bytes32())),
|
|
17255
17102
|
},
|
|
17256
17103
|
}, ({ history, mmr }) => {
|
|
17257
|
-
return RecentBlocks.create({
|
|
17104
|
+
return RecentBlocksHistory.create(RecentBlocks.create({
|
|
17258
17105
|
blocks: history,
|
|
17259
17106
|
accumulationLog: mmr,
|
|
17260
|
-
});
|
|
17107
|
+
}));
|
|
17261
17108
|
});
|
|
17262
17109
|
|
|
17263
17110
|
const ticketFromJson = json.object({
|
|
@@ -17455,7 +17302,7 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17455
17302
|
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && chi.chi_r === undefined) {
|
|
17456
17303
|
throw new Error("Registrar is required in Privileges GP ^0.7.1");
|
|
17457
17304
|
}
|
|
17458
|
-
return InMemoryState.
|
|
17305
|
+
return InMemoryState.create({
|
|
17459
17306
|
authPools: tryAsPerCore(alpha.map((perCore) => {
|
|
17460
17307
|
if (perCore.length > MAX_AUTH_POOL_SIZE) {
|
|
17461
17308
|
throw new Error(`AuthPools: expected less than ${MAX_AUTH_POOL_SIZE}, got ${perCore.length}`);
|
|
@@ -17468,7 +17315,7 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17468
17315
|
}
|
|
17469
17316
|
return asKnownSize(perCore);
|
|
17470
17317
|
}), spec),
|
|
17471
|
-
recentBlocks: beta ??
|
|
17318
|
+
recentBlocks: beta ?? RecentBlocksHistory.empty(),
|
|
17472
17319
|
nextValidatorData: gamma.gamma_k,
|
|
17473
17320
|
epochRoot: gamma.gamma_z,
|
|
17474
17321
|
sealingKeySeries: TicketsOrKeys.toSafroleSealingKeys(gamma.gamma_s, spec),
|
|
@@ -17541,21 +17388,21 @@ class TransitionHasher {
|
|
|
17541
17388
|
*/
|
|
17542
17389
|
extrinsic(extrinsicView) {
|
|
17543
17390
|
// https://graypaper.fluffylabs.dev/#/cc517d7/0cfb000cfb00?v=0.6.5
|
|
17544
|
-
const
|
|
17545
|
-
const countEncoded = Encoder.encodeObject(codec$1.varU32, guaranteesCount);
|
|
17546
|
-
const guaranteesBlobs = extrinsicView.guarantees
|
|
17391
|
+
const guarantees = extrinsicView.guarantees
|
|
17547
17392
|
.view()
|
|
17548
17393
|
.map((g) => g.view())
|
|
17549
|
-
.
|
|
17394
|
+
.map((guarantee) => {
|
|
17550
17395
|
const reportHash = this.blake2b.hashBytes(guarantee.report.encoded()).asOpaque();
|
|
17551
|
-
|
|
17552
|
-
|
|
17553
|
-
|
|
17554
|
-
|
|
17555
|
-
|
|
17396
|
+
return BytesBlob.blobFromParts([
|
|
17397
|
+
reportHash.raw,
|
|
17398
|
+
guarantee.slot.encoded().raw,
|
|
17399
|
+
guarantee.credentials.encoded().raw,
|
|
17400
|
+
]);
|
|
17401
|
+
});
|
|
17402
|
+
const guaranteeBlob = Encoder.encodeObject(codec$1.sequenceVarLen(dumpCodec), guarantees, this.context);
|
|
17556
17403
|
const et = this.blake2b.hashBytes(extrinsicView.tickets.encoded()).asOpaque();
|
|
17557
17404
|
const ep = this.blake2b.hashBytes(extrinsicView.preimages.encoded()).asOpaque();
|
|
17558
|
-
const eg = this.blake2b.
|
|
17405
|
+
const eg = this.blake2b.hashBytes(guaranteeBlob).asOpaque();
|
|
17559
17406
|
const ea = this.blake2b.hashBytes(extrinsicView.assurances.encoded()).asOpaque();
|
|
17560
17407
|
const ed = this.blake2b.hashBytes(extrinsicView.disputes.encoded()).asOpaque();
|
|
17561
17408
|
const encoded = BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);
|