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