@typeberry/lib 0.2.0-b6e3410 → 0.2.0-e767e74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +915 -762
- package/index.d.ts +891 -608
- package/index.js +915 -762
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -2091,6 +2091,9 @@ 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
|
+
}
|
|
2094
2097
|
}
|
|
2095
2098
|
/**
|
|
2096
2099
|
* A lazy-evaluated decoder of a sequence.
|
|
@@ -2376,7 +2379,15 @@ var codec$1;
|
|
|
2376
2379
|
/** Custom encoding / decoding logic. */
|
|
2377
2380
|
codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
|
|
2378
2381
|
/** Choose a descriptor depending on the encoding/decoding context. */
|
|
2379
|
-
codec.select = ({ name, sizeHint, }, chooser) =>
|
|
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
|
+
};
|
|
2380
2391
|
/**
|
|
2381
2392
|
* A descriptor for a more complex POJO.
|
|
2382
2393
|
*
|
|
@@ -6675,6 +6686,17 @@ function emptyBlock(slot = tryAsTimeSlot(0)) {
|
|
|
6675
6686
|
});
|
|
6676
6687
|
}
|
|
6677
6688
|
|
|
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
|
+
|
|
6678
6700
|
var index$l = /*#__PURE__*/Object.freeze({
|
|
6679
6701
|
__proto__: null,
|
|
6680
6702
|
Block: Block,
|
|
@@ -6695,6 +6717,7 @@ var index$l = /*#__PURE__*/Object.freeze({
|
|
|
6695
6717
|
guarantees: guarantees,
|
|
6696
6718
|
headerViewWithHashCodec: headerViewWithHashCodec,
|
|
6697
6719
|
preimage: preimage,
|
|
6720
|
+
reencodeAsView: reencodeAsView,
|
|
6698
6721
|
refineContext: refineContext,
|
|
6699
6722
|
tickets: tickets,
|
|
6700
6723
|
tryAsCoreIndex: tryAsCoreIndex,
|
|
@@ -8045,6 +8068,70 @@ function accumulationOutputComparator(a, b) {
|
|
|
8045
8068
|
return Ordering.Equal;
|
|
8046
8069
|
}
|
|
8047
8070
|
|
|
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
|
+
|
|
8048
8135
|
/**
|
|
8049
8136
|
* Assignment of particular work report to a core.
|
|
8050
8137
|
*
|
|
@@ -8073,18 +8160,18 @@ class AvailabilityAssignment extends WithDebug {
|
|
|
8073
8160
|
this.timeout = timeout;
|
|
8074
8161
|
}
|
|
8075
8162
|
}
|
|
8163
|
+
const availabilityAssignmentsCodec = codecPerCore(codec$1.optional(AvailabilityAssignment.Codec));
|
|
8076
8164
|
|
|
8077
|
-
/**
|
|
8078
|
-
|
|
8079
|
-
|
|
8080
|
-
|
|
8081
|
-
|
|
8082
|
-
|
|
8083
|
-
|
|
8084
|
-
|
|
8085
|
-
|
|
8086
|
-
|
|
8087
|
-
});
|
|
8165
|
+
/** `O`: Maximal authorization pool size. */
|
|
8166
|
+
const MAX_AUTH_POOL_SIZE = O;
|
|
8167
|
+
/** `Q`: Size of the authorization queue. */
|
|
8168
|
+
const AUTHORIZATION_QUEUE_SIZE = Q;
|
|
8169
|
+
const authPoolsCodec = codecPerCore(codecKnownSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), {
|
|
8170
|
+
minLength: 0,
|
|
8171
|
+
maxLength: MAX_AUTH_POOL_SIZE,
|
|
8172
|
+
typicalLength: MAX_AUTH_POOL_SIZE,
|
|
8173
|
+
}));
|
|
8174
|
+
const authQueuesCodec = codecPerCore(codecFixedSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE));
|
|
8088
8175
|
|
|
8089
8176
|
const sortedSetCodec = () => readonlyArray(codec$1.sequenceVarLen(codec$1.bytes(HASH_SIZE))).convert((input) => input.array, (output) => {
|
|
8090
8177
|
const typed = output.map((x) => x.asOpaque());
|
|
@@ -8148,103 +8235,301 @@ function hashComparator(a, b) {
|
|
|
8148
8235
|
return a.compare(b);
|
|
8149
8236
|
}
|
|
8150
8237
|
|
|
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
|
-
|
|
8168
8238
|
const MAX_VALUE = 4294967295;
|
|
8169
8239
|
const MIN_VALUE = -2147483648;
|
|
8170
8240
|
const MAX_SHIFT_U32 = 32;
|
|
8171
8241
|
const MAX_SHIFT_U64 = 64n;
|
|
8172
8242
|
|
|
8173
8243
|
/**
|
|
8174
|
-
* `
|
|
8244
|
+
* `H = 8`: The size of recent history, in blocks.
|
|
8175
8245
|
*
|
|
8176
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
8246
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/416300416500
|
|
8177
8247
|
*/
|
|
8178
|
-
const
|
|
8248
|
+
const MAX_RECENT_HISTORY = 8;
|
|
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
|
+
}
|
|
8179
8280
|
/**
|
|
8180
|
-
*
|
|
8281
|
+
* Recent history of blocks.
|
|
8181
8282
|
*
|
|
8182
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/
|
|
8283
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
|
|
8183
8284
|
*/
|
|
8184
|
-
|
|
8285
|
+
class RecentBlocks extends WithDebug {
|
|
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
|
+
|
|
8185
8325
|
/**
|
|
8186
|
-
*
|
|
8326
|
+
* Fixed size of validator metadata.
|
|
8187
8327
|
*
|
|
8188
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
8328
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/0d55010d5501
|
|
8189
8329
|
*/
|
|
8190
|
-
const
|
|
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
|
-
});
|
|
8330
|
+
const VALIDATOR_META_BYTES = 128;
|
|
8214
8331
|
/**
|
|
8215
|
-
*
|
|
8332
|
+
* Details about validators' identity.
|
|
8216
8333
|
*
|
|
8217
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
8334
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/0d4b010d4c01
|
|
8218
8335
|
*/
|
|
8219
|
-
class
|
|
8220
|
-
|
|
8221
|
-
|
|
8222
|
-
|
|
8223
|
-
|
|
8224
|
-
|
|
8225
|
-
|
|
8226
|
-
|
|
8227
|
-
|
|
8228
|
-
|
|
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),
|
|
8336
|
+
class ValidatorData extends WithDebug {
|
|
8337
|
+
bandersnatch;
|
|
8338
|
+
ed25519;
|
|
8339
|
+
bls;
|
|
8340
|
+
metadata;
|
|
8341
|
+
static Codec = codec$1.Class(ValidatorData, {
|
|
8342
|
+
bandersnatch: codec$1.bytes(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
8343
|
+
ed25519: codec$1.bytes(ED25519_KEY_BYTES).asOpaque(),
|
|
8344
|
+
bls: codec$1.bytes(BLS_KEY_BYTES).asOpaque(),
|
|
8345
|
+
metadata: codec$1.bytes(VALIDATOR_META_BYTES),
|
|
8241
8346
|
});
|
|
8242
|
-
static create(
|
|
8243
|
-
return new
|
|
8347
|
+
static create({ ed25519, bandersnatch, bls, metadata }) {
|
|
8348
|
+
return new ValidatorData(bandersnatch, ed25519, bls, metadata);
|
|
8244
8349
|
}
|
|
8245
|
-
|
|
8246
|
-
|
|
8247
|
-
|
|
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);
|
|
8529
|
+
}
|
|
8530
|
+
/**
|
|
8531
|
+
* `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
|
|
8532
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
|
|
8248
8533
|
*/
|
|
8249
8534
|
static calculateThresholdBalance(items, bytes, gratisStorage) {
|
|
8250
8535
|
const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
|
|
@@ -8353,329 +8638,394 @@ class LookupHistoryItem {
|
|
|
8353
8638
|
}
|
|
8354
8639
|
}
|
|
8355
8640
|
|
|
8356
|
-
|
|
8357
|
-
|
|
8358
|
-
|
|
8359
|
-
|
|
8360
|
-
|
|
8361
|
-
|
|
8362
|
-
|
|
8641
|
+
const codecServiceId = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
|
|
8642
|
+
? codec$1.u32.asOpaque()
|
|
8643
|
+
: codec$1.varU32.convert((s) => tryAsU32(s), (i) => tryAsServiceId(i));
|
|
8644
|
+
/**
|
|
8645
|
+
* Activity Record of a single validator.
|
|
8646
|
+
*
|
|
8647
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/183701183701
|
|
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,
|
|
8363
8663
|
});
|
|
8364
|
-
static create({
|
|
8365
|
-
return new
|
|
8664
|
+
static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
|
|
8665
|
+
return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
|
|
8366
8666
|
}
|
|
8367
8667
|
constructor(
|
|
8368
|
-
/**
|
|
8369
|
-
|
|
8370
|
-
/**
|
|
8371
|
-
|
|
8372
|
-
|
|
8373
|
-
|
|
8668
|
+
/** The number of blocks produced by the validator. */
|
|
8669
|
+
blocks,
|
|
8670
|
+
/** The number of tickets introduced by the validator. */
|
|
8671
|
+
tickets,
|
|
8672
|
+
/** The number of preimages introduced by the validator. */
|
|
8673
|
+
preImages,
|
|
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);
|
|
8374
8690
|
}
|
|
8375
8691
|
}
|
|
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));
|
|
8376
8695
|
/**
|
|
8377
|
-
*
|
|
8696
|
+
* Single core statistics.
|
|
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
|
|
8378
8701
|
*/
|
|
8379
|
-
class
|
|
8380
|
-
|
|
8381
|
-
|
|
8382
|
-
|
|
8383
|
-
|
|
8384
|
-
|
|
8385
|
-
|
|
8386
|
-
|
|
8387
|
-
|
|
8388
|
-
|
|
8389
|
-
|
|
8390
|
-
|
|
8391
|
-
|
|
8392
|
-
:
|
|
8393
|
-
|
|
8394
|
-
|
|
8395
|
-
|
|
8396
|
-
|
|
8702
|
+
class CoreStatistics {
|
|
8703
|
+
dataAvailabilityLoad;
|
|
8704
|
+
popularity;
|
|
8705
|
+
imports;
|
|
8706
|
+
exports;
|
|
8707
|
+
extrinsicSize;
|
|
8708
|
+
extrinsicCount;
|
|
8709
|
+
bundleSize;
|
|
8710
|
+
gasUsed;
|
|
8711
|
+
static Codec = Compatibility.isGreaterOrEqual(GpVersion.V0_7_0)
|
|
8712
|
+
? codec$1.Class(CoreStatistics, {
|
|
8713
|
+
dataAvailabilityLoad: codec$1.varU32,
|
|
8714
|
+
popularity: codecVarU16,
|
|
8715
|
+
imports: codecVarU16,
|
|
8716
|
+
extrinsicCount: codecVarU16,
|
|
8717
|
+
extrinsicSize: codec$1.varU32,
|
|
8718
|
+
exports: codecVarU16,
|
|
8719
|
+
bundleSize: codec$1.varU32,
|
|
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);
|
|
8397
8734
|
}
|
|
8398
8735
|
constructor(
|
|
8399
|
-
/**
|
|
8400
|
-
|
|
8401
|
-
|
|
8402
|
-
|
|
8403
|
-
|
|
8404
|
-
|
|
8405
|
-
/**
|
|
8406
|
-
|
|
8407
|
-
/**
|
|
8408
|
-
|
|
8409
|
-
|
|
8410
|
-
|
|
8411
|
-
|
|
8412
|
-
|
|
8413
|
-
/**
|
|
8414
|
-
|
|
8415
|
-
|
|
8416
|
-
|
|
8417
|
-
this.
|
|
8418
|
-
this.
|
|
8419
|
-
this.
|
|
8420
|
-
this.
|
|
8421
|
-
this.
|
|
8736
|
+
/** `d` */
|
|
8737
|
+
dataAvailabilityLoad,
|
|
8738
|
+
/** `p` */
|
|
8739
|
+
popularity,
|
|
8740
|
+
/** `i` */
|
|
8741
|
+
imports,
|
|
8742
|
+
/** `e` */
|
|
8743
|
+
exports,
|
|
8744
|
+
/** `z` */
|
|
8745
|
+
extrinsicSize,
|
|
8746
|
+
/** `x` */
|
|
8747
|
+
extrinsicCount,
|
|
8748
|
+
/** `b` */
|
|
8749
|
+
bundleSize,
|
|
8750
|
+
/** `u` */
|
|
8751
|
+
gasUsed) {
|
|
8752
|
+
this.dataAvailabilityLoad = dataAvailabilityLoad;
|
|
8753
|
+
this.popularity = popularity;
|
|
8754
|
+
this.imports = imports;
|
|
8755
|
+
this.exports = exports;
|
|
8756
|
+
this.extrinsicSize = extrinsicSize;
|
|
8757
|
+
this.extrinsicCount = extrinsicCount;
|
|
8758
|
+
this.bundleSize = bundleSize;
|
|
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);
|
|
8422
8766
|
}
|
|
8423
8767
|
}
|
|
8424
|
-
|
|
8425
8768
|
/**
|
|
8426
|
-
*
|
|
8769
|
+
* Service statistics.
|
|
8770
|
+
* Updated per block, based on available work reports (`W`).
|
|
8427
8771
|
*
|
|
8428
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
8772
|
+
* https://graypaper.fluffylabs.dev/#/1c979cb/199802199802?v=0.7.1
|
|
8429
8773
|
*/
|
|
8430
|
-
|
|
8431
|
-
|
|
8432
|
-
|
|
8433
|
-
|
|
8434
|
-
|
|
8435
|
-
|
|
8436
|
-
|
|
8437
|
-
|
|
8438
|
-
|
|
8439
|
-
|
|
8440
|
-
|
|
8441
|
-
|
|
8774
|
+
class ServiceStatistics {
|
|
8775
|
+
providedCount;
|
|
8776
|
+
providedSize;
|
|
8777
|
+
refinementCount;
|
|
8778
|
+
refinementGasUsed;
|
|
8779
|
+
imports;
|
|
8780
|
+
exports;
|
|
8781
|
+
extrinsicSize;
|
|
8782
|
+
extrinsicCount;
|
|
8783
|
+
accumulateCount;
|
|
8784
|
+
accumulateGasUsed;
|
|
8785
|
+
onTransfersCount;
|
|
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
|
+
},
|
|
8442
8832
|
});
|
|
8443
|
-
static create(
|
|
8444
|
-
return new
|
|
8833
|
+
static create(v) {
|
|
8834
|
+
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);
|
|
8445
8835
|
}
|
|
8446
8836
|
constructor(
|
|
8447
|
-
/**
|
|
8448
|
-
|
|
8449
|
-
/**
|
|
8450
|
-
|
|
8451
|
-
/**
|
|
8452
|
-
|
|
8453
|
-
/**
|
|
8454
|
-
|
|
8455
|
-
|
|
8456
|
-
|
|
8457
|
-
|
|
8458
|
-
|
|
8459
|
-
|
|
8837
|
+
/** `p.0` */
|
|
8838
|
+
providedCount,
|
|
8839
|
+
/** `p.1` */
|
|
8840
|
+
providedSize,
|
|
8841
|
+
/** `r.0` */
|
|
8842
|
+
refinementCount,
|
|
8843
|
+
/** `r.1` */
|
|
8844
|
+
refinementGasUsed,
|
|
8845
|
+
/** `i` */
|
|
8846
|
+
imports,
|
|
8847
|
+
/** `e` */
|
|
8848
|
+
exports,
|
|
8849
|
+
/** `z` */
|
|
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);
|
|
8460
8879
|
}
|
|
8461
8880
|
}
|
|
8462
|
-
|
|
8463
|
-
|
|
8464
|
-
|
|
8465
|
-
|
|
8466
|
-
|
|
8467
|
-
|
|
8468
|
-
|
|
8469
|
-
|
|
8470
|
-
|
|
8471
|
-
|
|
8472
|
-
|
|
8881
|
+
/** `pi`: Statistics of each validator, cores statistics and services statistics. */
|
|
8882
|
+
class StatisticsData {
|
|
8883
|
+
current;
|
|
8884
|
+
previous;
|
|
8885
|
+
cores;
|
|
8886
|
+
services;
|
|
8887
|
+
static Codec = codec$1.Class(StatisticsData, {
|
|
8888
|
+
current: codecPerValidator(ValidatorStatistics.Codec),
|
|
8889
|
+
previous: codecPerValidator(ValidatorStatistics.Codec),
|
|
8890
|
+
cores: codecPerCore(CoreStatistics.Codec),
|
|
8891
|
+
services: codec$1.dictionary(codecServiceId, ServiceStatistics.Codec, {
|
|
8892
|
+
sortKeys: (a, b) => a - b,
|
|
8473
8893
|
}),
|
|
8474
8894
|
});
|
|
8475
|
-
static create(
|
|
8476
|
-
return new
|
|
8895
|
+
static create(v) {
|
|
8896
|
+
return new StatisticsData(v.current, v.previous, v.cores, v.services);
|
|
8477
8897
|
}
|
|
8478
|
-
constructor(
|
|
8479
|
-
|
|
8480
|
-
|
|
8481
|
-
|
|
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;
|
|
8898
|
+
constructor(current, previous, cores, services) {
|
|
8899
|
+
this.current = current;
|
|
8900
|
+
this.previous = previous;
|
|
8901
|
+
this.cores = cores;
|
|
8902
|
+
this.services = services;
|
|
8492
8903
|
}
|
|
8493
8904
|
}
|
|
8494
|
-
|
|
8495
|
-
|
|
8496
|
-
|
|
8497
|
-
|
|
8498
|
-
|
|
8499
|
-
|
|
8500
|
-
|
|
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);
|
|
8905
|
+
|
|
8906
|
+
class InMemoryStateView {
|
|
8907
|
+
chainSpec;
|
|
8908
|
+
state;
|
|
8909
|
+
constructor(chainSpec, state) {
|
|
8910
|
+
this.chainSpec = chainSpec;
|
|
8911
|
+
this.state = state;
|
|
8509
8912
|
}
|
|
8510
|
-
|
|
8511
|
-
return
|
|
8512
|
-
blocks: asKnownSize([]),
|
|
8513
|
-
accumulationLog: { peaks: [] },
|
|
8514
|
-
}));
|
|
8913
|
+
availabilityAssignmentView() {
|
|
8914
|
+
return reencodeAsView(availabilityAssignmentsCodec, this.state.availabilityAssignment, this.chainSpec);
|
|
8515
8915
|
}
|
|
8516
|
-
|
|
8517
|
-
|
|
8518
|
-
*/
|
|
8519
|
-
static accumulationResult(block) {
|
|
8520
|
-
return block.accumulationResult;
|
|
8916
|
+
designatedValidatorDataView() {
|
|
8917
|
+
return reencodeAsView(validatorsDataCodec, this.state.designatedValidatorData, this.chainSpec);
|
|
8521
8918
|
}
|
|
8522
|
-
|
|
8523
|
-
|
|
8524
|
-
this.current = current;
|
|
8919
|
+
currentValidatorDataView() {
|
|
8920
|
+
return reencodeAsView(validatorsDataCodec, this.state.currentValidatorData, this.chainSpec);
|
|
8525
8921
|
}
|
|
8526
|
-
|
|
8527
|
-
|
|
8528
|
-
if (this.current !== null) {
|
|
8529
|
-
return this.current.blocks;
|
|
8530
|
-
}
|
|
8531
|
-
throw new Error("RecentBlocksHistory is in invalid state");
|
|
8922
|
+
previousValidatorDataView() {
|
|
8923
|
+
return reencodeAsView(validatorsDataCodec, this.state.previousValidatorData, this.chainSpec);
|
|
8532
8924
|
}
|
|
8533
|
-
|
|
8534
|
-
|
|
8535
|
-
throw new Error("Cannot access current RecentBlocks format");
|
|
8536
|
-
}
|
|
8537
|
-
return this.current;
|
|
8925
|
+
authPoolsView() {
|
|
8926
|
+
return reencodeAsView(authPoolsCodec, this.state.authPools, this.chainSpec);
|
|
8538
8927
|
}
|
|
8539
|
-
|
|
8540
|
-
|
|
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!");
|
|
8928
|
+
authQueuesView() {
|
|
8929
|
+
return reencodeAsView(authQueuesCodec, this.state.authQueues, this.chainSpec);
|
|
8547
8930
|
}
|
|
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);
|
|
8931
|
+
recentBlocksView() {
|
|
8932
|
+
return reencodeAsView(RecentBlocks.Codec, this.state.recentBlocks, this.chainSpec);
|
|
8574
8933
|
}
|
|
8575
|
-
|
|
8576
|
-
|
|
8577
|
-
|
|
8578
|
-
|
|
8579
|
-
|
|
8580
|
-
|
|
8581
|
-
|
|
8582
|
-
|
|
8583
|
-
|
|
8584
|
-
|
|
8585
|
-
|
|
8586
|
-
|
|
8587
|
-
|
|
8588
|
-
|
|
8934
|
+
statisticsView() {
|
|
8935
|
+
return reencodeAsView(StatisticsData.Codec, this.state.statistics, this.chainSpec);
|
|
8936
|
+
}
|
|
8937
|
+
accumulationQueueView() {
|
|
8938
|
+
return reencodeAsView(accumulationQueueCodec, this.state.accumulationQueue, this.chainSpec);
|
|
8939
|
+
}
|
|
8940
|
+
recentlyAccumulatedView() {
|
|
8941
|
+
return reencodeAsView(recentlyAccumulatedCodec, this.state.recentlyAccumulated, this.chainSpec);
|
|
8942
|
+
}
|
|
8943
|
+
safroleDataView() {
|
|
8944
|
+
// TODO [ToDr] Consider exposting `safrole` from state
|
|
8945
|
+
// instead of individual fields
|
|
8946
|
+
const safrole = SafroleData.create({
|
|
8947
|
+
nextValidatorData: this.state.nextValidatorData,
|
|
8948
|
+
epochRoot: this.state.epochRoot,
|
|
8949
|
+
sealingKeySeries: this.state.sealingKeySeries,
|
|
8950
|
+
ticketsAccumulator: this.state.ticketsAccumulator,
|
|
8951
|
+
});
|
|
8952
|
+
return reencodeAsView(SafroleData.Codec, safrole, this.chainSpec);
|
|
8953
|
+
}
|
|
8954
|
+
getServiceInfoView(id) {
|
|
8955
|
+
const service = this.state.getService(id);
|
|
8956
|
+
if (service === null) {
|
|
8957
|
+
return null;
|
|
8958
|
+
}
|
|
8959
|
+
return reencodeAsView(ServiceAccountInfo.Codec, service.getInfo(), this.chainSpec);
|
|
8589
8960
|
}
|
|
8590
8961
|
}
|
|
8591
8962
|
|
|
8592
|
-
|
|
8593
|
-
|
|
8594
|
-
|
|
8595
|
-
|
|
8596
|
-
|
|
8597
|
-
|
|
8598
|
-
|
|
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
|
-
});
|
|
8963
|
+
/** Dictionary entry of services that auto-accumulate every block. */
|
|
8964
|
+
class AutoAccumulate {
|
|
8965
|
+
service;
|
|
8966
|
+
gasLimit;
|
|
8967
|
+
static Codec = codec$1.Class(AutoAccumulate, {
|
|
8968
|
+
service: codec$1.u32.asOpaque(),
|
|
8969
|
+
gasLimit: codec$1.u64.asOpaque(),
|
|
8638
8970
|
});
|
|
8639
|
-
static
|
|
8640
|
-
return new
|
|
8641
|
-
}
|
|
8642
|
-
static tickets(tickets) {
|
|
8643
|
-
return new SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
|
|
8971
|
+
static create({ service, gasLimit }) {
|
|
8972
|
+
return new AutoAccumulate(service, gasLimit);
|
|
8644
8973
|
}
|
|
8645
|
-
constructor(
|
|
8646
|
-
|
|
8647
|
-
|
|
8648
|
-
|
|
8649
|
-
|
|
8974
|
+
constructor(
|
|
8975
|
+
/** Service id that auto-accumulates. */
|
|
8976
|
+
service,
|
|
8977
|
+
/** Gas limit for auto-accumulation. */
|
|
8978
|
+
gasLimit) {
|
|
8979
|
+
this.service = service;
|
|
8980
|
+
this.gasLimit = gasLimit;
|
|
8650
8981
|
}
|
|
8651
8982
|
}
|
|
8652
|
-
|
|
8653
|
-
|
|
8654
|
-
|
|
8655
|
-
|
|
8656
|
-
|
|
8657
|
-
|
|
8658
|
-
|
|
8659
|
-
|
|
8660
|
-
|
|
8661
|
-
|
|
8983
|
+
/**
|
|
8984
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
|
|
8985
|
+
*/
|
|
8986
|
+
class PrivilegedServices {
|
|
8987
|
+
manager;
|
|
8988
|
+
delegator;
|
|
8989
|
+
registrar;
|
|
8990
|
+
assigners;
|
|
8991
|
+
autoAccumulateServices;
|
|
8992
|
+
/** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
|
|
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)),
|
|
8662
9001
|
});
|
|
8663
|
-
static create(
|
|
8664
|
-
return new
|
|
9002
|
+
static create(a) {
|
|
9003
|
+
return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
8665
9004
|
}
|
|
8666
9005
|
constructor(
|
|
8667
|
-
/**
|
|
8668
|
-
|
|
8669
|
-
|
|
8670
|
-
|
|
8671
|
-
|
|
8672
|
-
|
|
8673
|
-
/**
|
|
8674
|
-
|
|
8675
|
-
|
|
8676
|
-
|
|
8677
|
-
|
|
8678
|
-
|
|
9006
|
+
/**
|
|
9007
|
+
* `χ_M`: Manages alteration of χ from block to block,
|
|
9008
|
+
* as well as bestow services with storage deposit credits.
|
|
9009
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
9010
|
+
*/
|
|
9011
|
+
manager,
|
|
9012
|
+
/** `χ_V`: Managers validator keys. */
|
|
9013
|
+
delegator,
|
|
9014
|
+
/**
|
|
9015
|
+
* `χ_R`: Manages the creation of services in protected range.
|
|
9016
|
+
*
|
|
9017
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
|
|
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;
|
|
8679
9029
|
}
|
|
8680
9030
|
}
|
|
8681
9031
|
|
|
@@ -8786,318 +9136,53 @@ class UpdateService {
|
|
|
8786
9136
|
return new UpdateService(serviceId, {
|
|
8787
9137
|
kind: UpdateServiceKind.Update,
|
|
8788
9138
|
account: serviceInfo,
|
|
8789
|
-
});
|
|
8790
|
-
}
|
|
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;
|
|
9139
|
+
});
|
|
8958
9140
|
}
|
|
8959
|
-
static
|
|
8960
|
-
|
|
8961
|
-
|
|
8962
|
-
|
|
8963
|
-
|
|
9141
|
+
static create({ serviceId, serviceInfo, lookupHistory, }) {
|
|
9142
|
+
return new UpdateService(serviceId, {
|
|
9143
|
+
kind: UpdateServiceKind.Create,
|
|
9144
|
+
account: serviceInfo,
|
|
9145
|
+
lookupHistory,
|
|
9146
|
+
});
|
|
8964
9147
|
}
|
|
8965
9148
|
}
|
|
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 = {}));
|
|
8966
9157
|
/**
|
|
8967
|
-
*
|
|
8968
|
-
* Updated per block, based on available work reports (`W`).
|
|
9158
|
+
* Update service storage item.
|
|
8969
9159
|
*
|
|
8970
|
-
*
|
|
9160
|
+
* Can either create/modify an entry or remove it.
|
|
8971
9161
|
*/
|
|
8972
|
-
class
|
|
8973
|
-
|
|
8974
|
-
|
|
8975
|
-
|
|
8976
|
-
|
|
8977
|
-
|
|
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);
|
|
9162
|
+
class UpdateStorage {
|
|
9163
|
+
serviceId;
|
|
9164
|
+
action;
|
|
9165
|
+
constructor(serviceId, action) {
|
|
9166
|
+
this.serviceId = serviceId;
|
|
9167
|
+
this.action = action;
|
|
9033
9168
|
}
|
|
9034
|
-
|
|
9035
|
-
|
|
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;
|
|
9169
|
+
static set({ serviceId, storage }) {
|
|
9170
|
+
return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Set, storage });
|
|
9071
9171
|
}
|
|
9072
|
-
static
|
|
9073
|
-
|
|
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);
|
|
9172
|
+
static remove({ serviceId, key }) {
|
|
9173
|
+
return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Remove, key });
|
|
9077
9174
|
}
|
|
9078
|
-
|
|
9079
|
-
|
|
9080
|
-
|
|
9081
|
-
|
|
9082
|
-
|
|
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);
|
|
9175
|
+
get key() {
|
|
9176
|
+
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
9177
|
+
return this.action.key;
|
|
9178
|
+
}
|
|
9179
|
+
return this.action.storage.key;
|
|
9095
9180
|
}
|
|
9096
|
-
|
|
9097
|
-
this.
|
|
9098
|
-
|
|
9099
|
-
|
|
9100
|
-
this.
|
|
9181
|
+
get value() {
|
|
9182
|
+
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
9183
|
+
return null;
|
|
9184
|
+
}
|
|
9185
|
+
return this.action.storage.value;
|
|
9101
9186
|
}
|
|
9102
9187
|
}
|
|
9103
9188
|
|
|
@@ -9200,9 +9285,10 @@ class InMemoryService extends WithDebug {
|
|
|
9200
9285
|
* A special version of state, stored fully in-memory.
|
|
9201
9286
|
*/
|
|
9202
9287
|
class InMemoryState extends WithDebug {
|
|
9288
|
+
chainSpec;
|
|
9203
9289
|
/** Create a new `InMemoryState` by providing all required fields. */
|
|
9204
|
-
static
|
|
9205
|
-
return new InMemoryState(state);
|
|
9290
|
+
static new(chainSpec, state) {
|
|
9291
|
+
return new InMemoryState(chainSpec, state);
|
|
9206
9292
|
}
|
|
9207
9293
|
/**
|
|
9208
9294
|
* Create a new `InMemoryState` with a partial state override.
|
|
@@ -9218,7 +9304,7 @@ class InMemoryState extends WithDebug {
|
|
|
9218
9304
|
/**
|
|
9219
9305
|
* Create a new `InMemoryState` from some other state object.
|
|
9220
9306
|
*/
|
|
9221
|
-
static copyFrom(other, servicesData) {
|
|
9307
|
+
static copyFrom(chainSpec, other, servicesData) {
|
|
9222
9308
|
const services = new Map();
|
|
9223
9309
|
for (const [id, entries] of servicesData.entries()) {
|
|
9224
9310
|
const service = other.getService(id);
|
|
@@ -9228,7 +9314,7 @@ class InMemoryState extends WithDebug {
|
|
|
9228
9314
|
const inMemService = InMemoryService.copyFrom(service, entries);
|
|
9229
9315
|
services.set(id, inMemService);
|
|
9230
9316
|
}
|
|
9231
|
-
return InMemoryState.
|
|
9317
|
+
return InMemoryState.new(chainSpec, {
|
|
9232
9318
|
availabilityAssignment: other.availabilityAssignment,
|
|
9233
9319
|
accumulationQueue: other.accumulationQueue,
|
|
9234
9320
|
designatedValidatorData: other.designatedValidatorData,
|
|
@@ -9425,8 +9511,9 @@ class InMemoryState extends WithDebug {
|
|
|
9425
9511
|
getService(id) {
|
|
9426
9512
|
return this.services.get(id) ?? null;
|
|
9427
9513
|
}
|
|
9428
|
-
constructor(s) {
|
|
9514
|
+
constructor(chainSpec, s) {
|
|
9429
9515
|
super();
|
|
9516
|
+
this.chainSpec = chainSpec;
|
|
9430
9517
|
this.availabilityAssignment = s.availabilityAssignment;
|
|
9431
9518
|
this.designatedValidatorData = s.designatedValidatorData;
|
|
9432
9519
|
this.nextValidatorData = s.nextValidatorData;
|
|
@@ -9448,11 +9535,14 @@ class InMemoryState extends WithDebug {
|
|
|
9448
9535
|
this.accumulationOutputLog = s.accumulationOutputLog;
|
|
9449
9536
|
this.services = s.services;
|
|
9450
9537
|
}
|
|
9538
|
+
view() {
|
|
9539
|
+
return new InMemoryStateView(this.chainSpec, this);
|
|
9540
|
+
}
|
|
9451
9541
|
/**
|
|
9452
9542
|
* Create an empty and possibly incoherent `InMemoryState`.
|
|
9453
9543
|
*/
|
|
9454
9544
|
static empty(spec) {
|
|
9455
|
-
return new InMemoryState({
|
|
9545
|
+
return new InMemoryState(spec, {
|
|
9456
9546
|
availabilityAssignment: tryAsPerCore(Array.from({ length: spec.coresCount }, () => null), spec),
|
|
9457
9547
|
designatedValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
|
|
9458
9548
|
bandersnatch: Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
@@ -9488,7 +9578,7 @@ class InMemoryState extends WithDebug {
|
|
|
9488
9578
|
entropy: FixedSizeArray.fill(() => Bytes.zero(HASH_SIZE).asOpaque(), ENTROPY_ENTRIES),
|
|
9489
9579
|
authPools: tryAsPerCore(Array.from({ length: spec.coresCount }, () => asKnownSize([])), spec),
|
|
9490
9580
|
authQueues: tryAsPerCore(Array.from({ length: spec.coresCount }, () => FixedSizeArray.fill(() => Bytes.zero(HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE)), spec),
|
|
9491
|
-
recentBlocks:
|
|
9581
|
+
recentBlocks: RecentBlocks.empty(),
|
|
9492
9582
|
statistics: StatisticsData.create({
|
|
9493
9583
|
current: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
|
|
9494
9584
|
previous: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
|
|
@@ -9526,6 +9616,7 @@ const serviceDataCodec = codec$1.dictionary(codec$1.u32.asOpaque(), serviceEntri
|
|
|
9526
9616
|
|
|
9527
9617
|
var index$g = /*#__PURE__*/Object.freeze({
|
|
9528
9618
|
__proto__: null,
|
|
9619
|
+
AUTHORIZATION_QUEUE_SIZE: AUTHORIZATION_QUEUE_SIZE,
|
|
9529
9620
|
AccumulationOutput: AccumulationOutput,
|
|
9530
9621
|
AutoAccumulate: AutoAccumulate,
|
|
9531
9622
|
AvailabilityAssignment: AvailabilityAssignment,
|
|
@@ -9539,11 +9630,12 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
9539
9630
|
InMemoryService: InMemoryService,
|
|
9540
9631
|
InMemoryState: InMemoryState,
|
|
9541
9632
|
LookupHistoryItem: LookupHistoryItem,
|
|
9633
|
+
MAX_AUTH_POOL_SIZE: MAX_AUTH_POOL_SIZE,
|
|
9542
9634
|
MAX_RECENT_HISTORY: MAX_RECENT_HISTORY,
|
|
9635
|
+
NotYetAccumulatedReport: NotYetAccumulatedReport,
|
|
9543
9636
|
PreimageItem: PreimageItem,
|
|
9544
9637
|
PrivilegedServices: PrivilegedServices,
|
|
9545
9638
|
RecentBlocks: RecentBlocks,
|
|
9546
|
-
RecentBlocksHistory: RecentBlocksHistory,
|
|
9547
9639
|
SafroleData: SafroleData,
|
|
9548
9640
|
SafroleSealingKeysData: SafroleSealingKeysData,
|
|
9549
9641
|
get SafroleSealingKeysKind () { return SafroleSealingKeysKind; },
|
|
@@ -9562,71 +9654,35 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
9562
9654
|
ValidatorData: ValidatorData,
|
|
9563
9655
|
ValidatorStatistics: ValidatorStatistics,
|
|
9564
9656
|
accumulationOutputComparator: accumulationOutputComparator,
|
|
9657
|
+
accumulationQueueCodec: accumulationQueueCodec,
|
|
9658
|
+
authPoolsCodec: authPoolsCodec,
|
|
9659
|
+
authQueuesCodec: authQueuesCodec,
|
|
9660
|
+
availabilityAssignmentsCodec: availabilityAssignmentsCodec,
|
|
9565
9661
|
codecPerCore: codecPerCore,
|
|
9566
9662
|
codecWithVersion: codecWithVersion,
|
|
9567
9663
|
hashComparator: hashComparator,
|
|
9568
9664
|
ignoreValueWithDefault: ignoreValueWithDefault,
|
|
9665
|
+
recentlyAccumulatedCodec: recentlyAccumulatedCodec,
|
|
9569
9666
|
serviceDataCodec: serviceDataCodec,
|
|
9570
9667
|
serviceEntriesCodec: serviceEntriesCodec,
|
|
9571
9668
|
tryAsLookupHistorySlots: tryAsLookupHistorySlots,
|
|
9572
|
-
tryAsPerCore: tryAsPerCore
|
|
9669
|
+
tryAsPerCore: tryAsPerCore,
|
|
9670
|
+
validatorsDataCodec: validatorsDataCodec
|
|
9573
9671
|
});
|
|
9574
9672
|
|
|
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
|
-
|
|
9613
9673
|
/** Serialization for particular state entries. */
|
|
9614
9674
|
var serialize;
|
|
9615
9675
|
(function (serialize) {
|
|
9616
9676
|
/** C(1): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b15013b1501?v=0.6.7 */
|
|
9617
9677
|
serialize.authPools = {
|
|
9618
9678
|
key: stateKeys.index(StateKeyIdx.Alpha),
|
|
9619
|
-
Codec:
|
|
9620
|
-
minLength: 0,
|
|
9621
|
-
maxLength: MAX_AUTH_POOL_SIZE,
|
|
9622
|
-
typicalLength: MAX_AUTH_POOL_SIZE,
|
|
9623
|
-
})),
|
|
9679
|
+
Codec: authPoolsCodec,
|
|
9624
9680
|
extract: (s) => s.authPools,
|
|
9625
9681
|
};
|
|
9626
9682
|
/** C(2): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b31013b3101?v=0.6.7 */
|
|
9627
9683
|
serialize.authQueues = {
|
|
9628
9684
|
key: stateKeys.index(StateKeyIdx.Phi),
|
|
9629
|
-
Codec:
|
|
9685
|
+
Codec: authQueuesCodec,
|
|
9630
9686
|
extract: (s) => s.authQueues,
|
|
9631
9687
|
};
|
|
9632
9688
|
/**
|
|
@@ -9635,7 +9691,7 @@ var serialize;
|
|
|
9635
9691
|
*/
|
|
9636
9692
|
serialize.recentBlocks = {
|
|
9637
9693
|
key: stateKeys.index(StateKeyIdx.Beta),
|
|
9638
|
-
Codec:
|
|
9694
|
+
Codec: RecentBlocks.Codec,
|
|
9639
9695
|
extract: (s) => s.recentBlocks,
|
|
9640
9696
|
};
|
|
9641
9697
|
/** C(4): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b63013b6301?v=0.6.7 */
|
|
@@ -9664,25 +9720,25 @@ var serialize;
|
|
|
9664
9720
|
/** C(7): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b00023b0002?v=0.6.7 */
|
|
9665
9721
|
serialize.designatedValidators = {
|
|
9666
9722
|
key: stateKeys.index(StateKeyIdx.Iota),
|
|
9667
|
-
Codec:
|
|
9723
|
+
Codec: validatorsDataCodec,
|
|
9668
9724
|
extract: (s) => s.designatedValidatorData,
|
|
9669
9725
|
};
|
|
9670
9726
|
/** C(8): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b0d023b0d02?v=0.6.7 */
|
|
9671
9727
|
serialize.currentValidators = {
|
|
9672
9728
|
key: stateKeys.index(StateKeyIdx.Kappa),
|
|
9673
|
-
Codec:
|
|
9729
|
+
Codec: validatorsDataCodec,
|
|
9674
9730
|
extract: (s) => s.currentValidatorData,
|
|
9675
9731
|
};
|
|
9676
9732
|
/** C(9): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b1a023b1a02?v=0.6.7 */
|
|
9677
9733
|
serialize.previousValidators = {
|
|
9678
9734
|
key: stateKeys.index(StateKeyIdx.Lambda),
|
|
9679
|
-
Codec:
|
|
9735
|
+
Codec: validatorsDataCodec,
|
|
9680
9736
|
extract: (s) => s.previousValidatorData,
|
|
9681
9737
|
};
|
|
9682
9738
|
/** C(10): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b27023b2702?v=0.6.7 */
|
|
9683
9739
|
serialize.availabilityAssignment = {
|
|
9684
9740
|
key: stateKeys.index(StateKeyIdx.Rho),
|
|
9685
|
-
Codec:
|
|
9741
|
+
Codec: availabilityAssignmentsCodec,
|
|
9686
9742
|
extract: (s) => s.availabilityAssignment,
|
|
9687
9743
|
};
|
|
9688
9744
|
/** C(11): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b3e023b3e02?v=0.6.7 */
|
|
@@ -9706,13 +9762,13 @@ var serialize;
|
|
|
9706
9762
|
/** C(14): https://graypaper.fluffylabs.dev/#/1c979cb/3bf0023bf002?v=0.7.1 */
|
|
9707
9763
|
serialize.accumulationQueue = {
|
|
9708
9764
|
key: stateKeys.index(StateKeyIdx.Omega),
|
|
9709
|
-
Codec:
|
|
9765
|
+
Codec: accumulationQueueCodec,
|
|
9710
9766
|
extract: (s) => s.accumulationQueue,
|
|
9711
9767
|
};
|
|
9712
9768
|
/** C(15): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b96023b9602?v=0.6.7 */
|
|
9713
9769
|
serialize.recentlyAccumulated = {
|
|
9714
9770
|
key: stateKeys.index(StateKeyIdx.Xi),
|
|
9715
|
-
Codec:
|
|
9771
|
+
Codec: recentlyAccumulatedCodec,
|
|
9716
9772
|
extract: (s) => s.recentlyAccumulated,
|
|
9717
9773
|
};
|
|
9718
9774
|
/** C(16): https://graypaper.fluffylabs.dev/#/38c4e62/3b46033b4603?v=0.7.0 */
|
|
@@ -9753,6 +9809,84 @@ var serialize;
|
|
|
9753
9809
|
*/
|
|
9754
9810
|
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()));
|
|
9755
9811
|
|
|
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
|
+
|
|
9756
9890
|
/**
|
|
9757
9891
|
* State object which reads it's entries from some backend.
|
|
9758
9892
|
*
|
|
@@ -9765,7 +9899,7 @@ class SerializedState {
|
|
|
9765
9899
|
spec;
|
|
9766
9900
|
blake2b;
|
|
9767
9901
|
backend;
|
|
9768
|
-
|
|
9902
|
+
recentlyUsedServices;
|
|
9769
9903
|
/** Create a state-like object from collection of serialized entries. */
|
|
9770
9904
|
static fromStateEntries(spec, blake2b, state, recentServices = []) {
|
|
9771
9905
|
return new SerializedState(spec, blake2b, state, recentServices);
|
|
@@ -9774,49 +9908,63 @@ class SerializedState {
|
|
|
9774
9908
|
static new(spec, blake2b, db, recentServices = []) {
|
|
9775
9909
|
return new SerializedState(spec, blake2b, db, recentServices);
|
|
9776
9910
|
}
|
|
9911
|
+
dataCache = HashDictionary.new();
|
|
9912
|
+
viewCache = HashDictionary.new();
|
|
9777
9913
|
constructor(spec, blake2b, backend,
|
|
9778
9914
|
/** Best-effort list of recently active services. */
|
|
9779
|
-
|
|
9915
|
+
recentlyUsedServices) {
|
|
9780
9916
|
this.spec = spec;
|
|
9781
9917
|
this.blake2b = blake2b;
|
|
9782
9918
|
this.backend = backend;
|
|
9783
|
-
this.
|
|
9919
|
+
this.recentlyUsedServices = recentlyUsedServices;
|
|
9784
9920
|
}
|
|
9785
9921
|
/** Comparing the serialized states, just means comparing their backends. */
|
|
9786
9922
|
[TEST_COMPARE_USING]() {
|
|
9787
9923
|
return this.backend;
|
|
9788
9924
|
}
|
|
9925
|
+
/** Return a non-decoding version of the state. */
|
|
9926
|
+
view() {
|
|
9927
|
+
return new SerializedStateView(this.spec, this.backend, this.recentlyUsedServices, this.viewCache);
|
|
9928
|
+
}
|
|
9789
9929
|
// TODO [ToDr] Temporary method to update the state,
|
|
9790
9930
|
// without changing references.
|
|
9791
9931
|
updateBackend(newBackend) {
|
|
9792
9932
|
this.backend = newBackend;
|
|
9933
|
+
this.dataCache = HashDictionary.new();
|
|
9934
|
+
this.viewCache = HashDictionary.new();
|
|
9793
9935
|
}
|
|
9794
9936
|
recentServiceIds() {
|
|
9795
|
-
return this.
|
|
9937
|
+
return this.recentlyUsedServices;
|
|
9796
9938
|
}
|
|
9797
9939
|
getService(id) {
|
|
9798
9940
|
const serviceData = this.retrieveOptional(serialize.serviceData(id));
|
|
9799
9941
|
if (serviceData === undefined) {
|
|
9800
9942
|
return null;
|
|
9801
9943
|
}
|
|
9802
|
-
if (!this.
|
|
9803
|
-
this.
|
|
9944
|
+
if (!this.recentlyUsedServices.includes(id)) {
|
|
9945
|
+
this.recentlyUsedServices.push(id);
|
|
9804
9946
|
}
|
|
9805
9947
|
return new SerializedService(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
|
|
9806
9948
|
}
|
|
9807
|
-
retrieve(
|
|
9808
|
-
const
|
|
9809
|
-
if (
|
|
9810
|
-
throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${key}`);
|
|
9949
|
+
retrieve(k, description) {
|
|
9950
|
+
const data = this.retrieveOptional(k);
|
|
9951
|
+
if (data === undefined) {
|
|
9952
|
+
throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${k.key}`);
|
|
9811
9953
|
}
|
|
9812
|
-
return
|
|
9954
|
+
return data;
|
|
9813
9955
|
}
|
|
9814
9956
|
retrieveOptional({ key, Codec }) {
|
|
9957
|
+
const cached = this.dataCache.get(key);
|
|
9958
|
+
if (cached !== undefined) {
|
|
9959
|
+
return cached;
|
|
9960
|
+
}
|
|
9815
9961
|
const bytes = this.backend.get(key);
|
|
9816
9962
|
if (bytes === null) {
|
|
9817
9963
|
return undefined;
|
|
9818
9964
|
}
|
|
9819
|
-
|
|
9965
|
+
const data = Decoder.decodeObject(Codec, bytes, this.spec);
|
|
9966
|
+
this.dataCache.set(key, data);
|
|
9967
|
+
return data;
|
|
9820
9968
|
}
|
|
9821
9969
|
get availabilityAssignment() {
|
|
9822
9970
|
return this.retrieve(serialize.availabilityAssignment, "availabilityAssignment");
|
|
@@ -10894,6 +11042,7 @@ var index$e = /*#__PURE__*/Object.freeze({
|
|
|
10894
11042
|
__proto__: null,
|
|
10895
11043
|
SerializedService: SerializedService,
|
|
10896
11044
|
SerializedState: SerializedState,
|
|
11045
|
+
SerializedStateView: SerializedStateView,
|
|
10897
11046
|
StateEntries: StateEntries,
|
|
10898
11047
|
get StateEntryUpdateAction () { return StateEntryUpdateAction; },
|
|
10899
11048
|
get StateKeyIdx () { return StateKeyIdx; },
|
|
@@ -11086,7 +11235,11 @@ class ServiceWithCodec extends InMemoryService {
|
|
|
11086
11235
|
return new ServiceWithCodec(serviceId, data);
|
|
11087
11236
|
}
|
|
11088
11237
|
}
|
|
11089
|
-
const inMemoryStateCodec = codec$1.Class(InMemoryState
|
|
11238
|
+
const inMemoryStateCodec = (spec) => codec$1.Class(class State extends InMemoryState {
|
|
11239
|
+
static create(data) {
|
|
11240
|
+
return InMemoryState.new(spec, data);
|
|
11241
|
+
}
|
|
11242
|
+
}, {
|
|
11090
11243
|
// alpha
|
|
11091
11244
|
authPools: serialize.authPools.Codec,
|
|
11092
11245
|
// phi
|
|
@@ -11165,7 +11318,7 @@ class InMemoryStates {
|
|
|
11165
11318
|
}
|
|
11166
11319
|
/** Insert a full state into the database. */
|
|
11167
11320
|
async insertState(headerHash, state) {
|
|
11168
|
-
const encoded = Encoder.encodeObject(inMemoryStateCodec, state, this.spec);
|
|
11321
|
+
const encoded = Encoder.encodeObject(inMemoryStateCodec(this.spec), state, this.spec);
|
|
11169
11322
|
this.db.set(headerHash, encoded);
|
|
11170
11323
|
return Result$1.ok(OK);
|
|
11171
11324
|
}
|
|
@@ -11174,7 +11327,7 @@ class InMemoryStates {
|
|
|
11174
11327
|
if (encodedState === undefined) {
|
|
11175
11328
|
return null;
|
|
11176
11329
|
}
|
|
11177
|
-
return Decoder.decodeObject(inMemoryStateCodec, encodedState, this.spec);
|
|
11330
|
+
return Decoder.decodeObject(inMemoryStateCodec(this.spec), encodedState, this.spec);
|
|
11178
11331
|
}
|
|
11179
11332
|
}
|
|
11180
11333
|
|
|
@@ -17104,10 +17257,10 @@ const recentBlocksHistoryFromJson = json.object({
|
|
|
17104
17257
|
peaks: json.array(json.nullable(fromJson.bytes32())),
|
|
17105
17258
|
},
|
|
17106
17259
|
}, ({ history, mmr }) => {
|
|
17107
|
-
return
|
|
17260
|
+
return RecentBlocks.create({
|
|
17108
17261
|
blocks: history,
|
|
17109
17262
|
accumulationLog: mmr,
|
|
17110
|
-
})
|
|
17263
|
+
});
|
|
17111
17264
|
});
|
|
17112
17265
|
|
|
17113
17266
|
const ticketFromJson = json.object({
|
|
@@ -17305,7 +17458,7 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17305
17458
|
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && chi.chi_r === undefined) {
|
|
17306
17459
|
throw new Error("Registrar is required in Privileges GP ^0.7.1");
|
|
17307
17460
|
}
|
|
17308
|
-
return InMemoryState.
|
|
17461
|
+
return InMemoryState.new(spec, {
|
|
17309
17462
|
authPools: tryAsPerCore(alpha.map((perCore) => {
|
|
17310
17463
|
if (perCore.length > MAX_AUTH_POOL_SIZE) {
|
|
17311
17464
|
throw new Error(`AuthPools: expected less than ${MAX_AUTH_POOL_SIZE}, got ${perCore.length}`);
|
|
@@ -17318,7 +17471,7 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17318
17471
|
}
|
|
17319
17472
|
return asKnownSize(perCore);
|
|
17320
17473
|
}), spec),
|
|
17321
|
-
recentBlocks: beta ??
|
|
17474
|
+
recentBlocks: beta ?? RecentBlocks.empty(),
|
|
17322
17475
|
nextValidatorData: gamma.gamma_k,
|
|
17323
17476
|
epochRoot: gamma.gamma_z,
|
|
17324
17477
|
sealingKeySeries: TicketsOrKeys.toSafroleSealingKeys(gamma.gamma_s, spec),
|
|
@@ -17391,21 +17544,21 @@ class TransitionHasher {
|
|
|
17391
17544
|
*/
|
|
17392
17545
|
extrinsic(extrinsicView) {
|
|
17393
17546
|
// https://graypaper.fluffylabs.dev/#/cc517d7/0cfb000cfb00?v=0.6.5
|
|
17394
|
-
const
|
|
17547
|
+
const guaranteesCount = tryAsU32(extrinsicView.guarantees.view().length);
|
|
17548
|
+
const countEncoded = Encoder.encodeObject(codec$1.varU32, guaranteesCount);
|
|
17549
|
+
const guaranteesBlobs = extrinsicView.guarantees
|
|
17395
17550
|
.view()
|
|
17396
17551
|
.map((g) => g.view())
|
|
17397
|
-
.
|
|
17552
|
+
.reduce((aggregated, guarantee) => {
|
|
17398
17553
|
const reportHash = this.blake2b.hashBytes(guarantee.report.encoded()).asOpaque();
|
|
17399
|
-
|
|
17400
|
-
|
|
17401
|
-
|
|
17402
|
-
|
|
17403
|
-
|
|
17404
|
-
});
|
|
17405
|
-
const guaranteeBlob = Encoder.encodeObject(codec$1.sequenceVarLen(dumpCodec), guarantees, this.context);
|
|
17554
|
+
aggregated.push(reportHash.raw);
|
|
17555
|
+
aggregated.push(guarantee.slot.encoded().raw);
|
|
17556
|
+
aggregated.push(guarantee.credentials.encoded().raw);
|
|
17557
|
+
return aggregated;
|
|
17558
|
+
}, [countEncoded.raw]);
|
|
17406
17559
|
const et = this.blake2b.hashBytes(extrinsicView.tickets.encoded()).asOpaque();
|
|
17407
17560
|
const ep = this.blake2b.hashBytes(extrinsicView.preimages.encoded()).asOpaque();
|
|
17408
|
-
const eg = this.blake2b.
|
|
17561
|
+
const eg = this.blake2b.hashBlobs(guaranteesBlobs).asOpaque();
|
|
17409
17562
|
const ea = this.blake2b.hashBytes(extrinsicView.assurances.encoded()).asOpaque();
|
|
17410
17563
|
const ed = this.blake2b.hashBytes(extrinsicView.disputes.encoded()).asOpaque();
|
|
17411
17564
|
const encoded = BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);
|