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