@typeberry/lib 0.0.1-9d0368d → 0.0.1-a2f0b71
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.d.ts +253 -398
- package/index.js +136 -184
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -52,7 +52,7 @@ var index$s = /*#__PURE__*/Object.freeze({
|
|
|
52
52
|
var GpVersion;
|
|
53
53
|
(function (GpVersion) {
|
|
54
54
|
GpVersion["V0_6_7"] = "0.6.7";
|
|
55
|
-
GpVersion["V0_7_0"] = "0.7.0
|
|
55
|
+
GpVersion["V0_7_0"] = "0.7.0";
|
|
56
56
|
GpVersion["V0_7_1"] = "0.7.1-preview";
|
|
57
57
|
})(GpVersion || (GpVersion = {}));
|
|
58
58
|
var TestSuite;
|
|
@@ -63,7 +63,7 @@ var TestSuite;
|
|
|
63
63
|
const DEFAULT_SUITE = TestSuite.W3F_DAVXY;
|
|
64
64
|
const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1];
|
|
65
65
|
const env = typeof process === "undefined" ? {} : process.env;
|
|
66
|
-
const DEFAULT_VERSION = GpVersion.
|
|
66
|
+
const DEFAULT_VERSION = GpVersion.V0_7_0;
|
|
67
67
|
let CURRENT_VERSION = parseCurrentVersion(env.GP_VERSION) ?? DEFAULT_VERSION;
|
|
68
68
|
let CURRENT_SUITE = parseCurrentSuite(env.TEST_SUITE) ?? DEFAULT_SUITE;
|
|
69
69
|
function parseCurrentVersion(env) {
|
|
@@ -373,6 +373,7 @@ function callCompareFunction(object) {
|
|
|
373
373
|
}
|
|
374
374
|
return object;
|
|
375
375
|
}
|
|
376
|
+
let oomWarningPrinted = false;
|
|
376
377
|
/** Deeply compare `actual` and `expected` values. */
|
|
377
378
|
function deepEqual(actual, expected, { context = [], errorsCollector, ignore = [] } = {}) {
|
|
378
379
|
const ctx = Array.isArray(context) ? context : [context];
|
|
@@ -398,12 +399,13 @@ function deepEqual(actual, expected, { context = [], errorsCollector, ignore = [
|
|
|
398
399
|
assert.strictEqual(actualDisp, expectedDisp, message);
|
|
399
400
|
}
|
|
400
401
|
catch (e) {
|
|
401
|
-
if (isOoMWorkaroundNeeded) {
|
|
402
|
+
if (isOoMWorkaroundNeeded && !oomWarningPrinted) {
|
|
402
403
|
console.warn([
|
|
403
404
|
"Stacktrace may be crappy because of a problem in nodejs.",
|
|
404
405
|
"Use older version than 22.12.0 or check this issue: https://github.com/nodejs/node/issues/57242",
|
|
405
406
|
"Maybe we do not need it anymore",
|
|
406
407
|
].join("\n"));
|
|
408
|
+
oomWarningPrinted = true;
|
|
407
409
|
}
|
|
408
410
|
throw e;
|
|
409
411
|
}
|
|
@@ -5639,6 +5641,8 @@ class ChainSpec extends WithDebug {
|
|
|
5639
5641
|
maxBlockGas;
|
|
5640
5642
|
/** `G_R`: The gas allocated to invoke a work-package’s Refine logic. */
|
|
5641
5643
|
maxRefineGas;
|
|
5644
|
+
/** `L`: The maximum age in timeslots of the lookup anchor. */
|
|
5645
|
+
maxLookupAnchorAge;
|
|
5642
5646
|
constructor(data) {
|
|
5643
5647
|
super();
|
|
5644
5648
|
this.validatorsCount = data.validatorsCount;
|
|
@@ -5656,6 +5660,7 @@ class ChainSpec extends WithDebug {
|
|
|
5656
5660
|
this.erasureCodedPieceSize = tryAsU32(EC_SEGMENT_SIZE / data.numberECPiecesPerSegment);
|
|
5657
5661
|
this.maxBlockGas = data.maxBlockGas;
|
|
5658
5662
|
this.maxRefineGas = data.maxRefineGas;
|
|
5663
|
+
this.maxLookupAnchorAge = data.maxLookupAnchorAge;
|
|
5659
5664
|
}
|
|
5660
5665
|
}
|
|
5661
5666
|
/** Set of values for "tiny" chain as defined in JAM test vectors. */
|
|
@@ -5673,6 +5678,8 @@ const tinyChainSpec = new ChainSpec({
|
|
|
5673
5678
|
preimageExpungePeriod: tryAsU32(32),
|
|
5674
5679
|
maxBlockGas: tryAsU64(20_000_000),
|
|
5675
5680
|
maxRefineGas: tryAsU64(1_000_000_000),
|
|
5681
|
+
// https://github.com/davxy/jam-conformance/pull/47/files#diff-27e26142b3a96e407dab40d388b63d553f5d9cdb66dec58cd93e63dd434f9e45R260
|
|
5682
|
+
maxLookupAnchorAge: tryAsU32(24),
|
|
5676
5683
|
});
|
|
5677
5684
|
/**
|
|
5678
5685
|
* Set of values for "full" chain as defined in JAM test vectors.
|
|
@@ -5691,6 +5698,7 @@ const fullChainSpec = new ChainSpec({
|
|
|
5691
5698
|
preimageExpungePeriod: tryAsU32(19_200),
|
|
5692
5699
|
maxBlockGas: tryAsU64(3_500_000_000),
|
|
5693
5700
|
maxRefineGas: tryAsU64(5_000_000_000),
|
|
5701
|
+
maxLookupAnchorAge: tryAsU32(14_400),
|
|
5694
5702
|
});
|
|
5695
5703
|
|
|
5696
5704
|
/**
|
|
@@ -6936,6 +6944,19 @@ class ValidatorKeys extends WithDebug {
|
|
|
6936
6944
|
this.ed25519 = ed25519;
|
|
6937
6945
|
}
|
|
6938
6946
|
}
|
|
6947
|
+
class TicketsMarker extends WithDebug {
|
|
6948
|
+
tickets;
|
|
6949
|
+
static Codec = codec$1.Class(TicketsMarker, {
|
|
6950
|
+
tickets: codecPerEpochBlock(Ticket.Codec),
|
|
6951
|
+
});
|
|
6952
|
+
static create({ tickets }) {
|
|
6953
|
+
return new TicketsMarker(tickets);
|
|
6954
|
+
}
|
|
6955
|
+
constructor(tickets) {
|
|
6956
|
+
super();
|
|
6957
|
+
this.tickets = tickets;
|
|
6958
|
+
}
|
|
6959
|
+
}
|
|
6939
6960
|
/**
|
|
6940
6961
|
* For the first block in a new epoch, the epoch marker is set
|
|
6941
6962
|
* and contains the epoch randomness and validator keys
|
|
@@ -6989,7 +7010,7 @@ const legacyDescriptor = {
|
|
|
6989
7010
|
extrinsicHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
6990
7011
|
timeSlotIndex: codec$1.u32.asOpaque(),
|
|
6991
7012
|
epochMarker: codec$1.optional(EpochMarker.Codec),
|
|
6992
|
-
ticketsMarker: codec$1.optional(
|
|
7013
|
+
ticketsMarker: codec$1.optional(TicketsMarker.Codec),
|
|
6993
7014
|
offendersMarker: codec$1.sequenceVarLen(codec$1.bytes(ED25519_KEY_BYTES).asOpaque()),
|
|
6994
7015
|
bandersnatchBlockAuthorIndex: codec$1.u16.asOpaque(),
|
|
6995
7016
|
entropySource: codec$1.bytes(BANDERSNATCH_VRF_SIGNATURE_BYTES).asOpaque(),
|
|
@@ -7009,7 +7030,7 @@ class Header extends WithDebug {
|
|
|
7009
7030
|
extrinsicHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
7010
7031
|
timeSlotIndex: codec$1.u32.asOpaque(),
|
|
7011
7032
|
epochMarker: codec$1.optional(EpochMarker.Codec),
|
|
7012
|
-
ticketsMarker: codec$1.optional(
|
|
7033
|
+
ticketsMarker: codec$1.optional(TicketsMarker.Codec),
|
|
7013
7034
|
bandersnatchBlockAuthorIndex: codec$1.u16.asOpaque(),
|
|
7014
7035
|
entropySource: codec$1.bytes(BANDERSNATCH_VRF_SIGNATURE_BYTES).asOpaque(),
|
|
7015
7036
|
offendersMarker: codec$1.sequenceVarLen(codec$1.bytes(ED25519_KEY_BYTES).asOpaque()),
|
|
@@ -7204,6 +7225,7 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
7204
7225
|
Header: Header,
|
|
7205
7226
|
MAX_NUMBER_OF_SEGMENTS: MAX_NUMBER_OF_SEGMENTS,
|
|
7206
7227
|
SEGMENT_BYTES: SEGMENT_BYTES,
|
|
7228
|
+
TicketsMarker: TicketsMarker,
|
|
7207
7229
|
ValidatorKeys: ValidatorKeys,
|
|
7208
7230
|
assurances: assurances,
|
|
7209
7231
|
codecPerEpochBlock: codecPerEpochBlock,
|
|
@@ -7682,7 +7704,7 @@ const epochMark = json.object({
|
|
|
7682
7704
|
tickets_entropy: fromJson.bytes32(),
|
|
7683
7705
|
validators: json.array(validatorKeysFromJson),
|
|
7684
7706
|
}, (x) => EpochMarker.create({ entropy: x.entropy, ticketsEntropy: x.tickets_entropy, validators: x.validators }));
|
|
7685
|
-
const
|
|
7707
|
+
const ticket = json.object({
|
|
7686
7708
|
id: fromJson.bytes32(),
|
|
7687
7709
|
attempt: fromJson.ticketAttempt,
|
|
7688
7710
|
}, (x) => Ticket.create({ id: x.id, attempt: x.attempt }));
|
|
@@ -7692,7 +7714,7 @@ const headerFromJson = json.object({
|
|
|
7692
7714
|
extrinsic_hash: fromJson.bytes32(),
|
|
7693
7715
|
slot: "number",
|
|
7694
7716
|
epoch_mark: json.optional(epochMark),
|
|
7695
|
-
tickets_mark: json.optional(json.array(
|
|
7717
|
+
tickets_mark: json.optional(json.array(ticket)),
|
|
7696
7718
|
offenders_mark: json.array(fromJson.bytes32()),
|
|
7697
7719
|
author_index: "number",
|
|
7698
7720
|
entropy_source: bandersnatchVrfSignature,
|
|
@@ -7704,7 +7726,10 @@ const headerFromJson = json.object({
|
|
|
7704
7726
|
header.extrinsicHash = extrinsic_hash;
|
|
7705
7727
|
header.timeSlotIndex = slot;
|
|
7706
7728
|
header.epochMarker = epoch_mark ?? null;
|
|
7707
|
-
header.ticketsMarker =
|
|
7729
|
+
header.ticketsMarker =
|
|
7730
|
+
tickets_mark === undefined || tickets_mark === null
|
|
7731
|
+
? null
|
|
7732
|
+
: TicketsMarker.create({ tickets: asOpaqueType(tickets_mark) });
|
|
7708
7733
|
header.offendersMarker = offenders_mark;
|
|
7709
7734
|
header.bandersnatchBlockAuthorIndex = author_index;
|
|
7710
7735
|
header.entropySource = entropy_source;
|
|
@@ -8201,16 +8226,7 @@ class PrivilegedServices {
|
|
|
8201
8226
|
autoAccumulateServices;
|
|
8202
8227
|
static Codec = codec$1.Class(PrivilegedServices, {
|
|
8203
8228
|
manager: codec$1.u32.asOpaque(),
|
|
8204
|
-
authManager:
|
|
8205
|
-
? codecPerCore(codec$1.u32.asOpaque())
|
|
8206
|
-
: codecWithContext((ctx) => codec$1.u32.asOpaque().convert(
|
|
8207
|
-
// NOTE: [MaSo] In a compatibility mode we are always updating all entries
|
|
8208
|
-
// (all the entries are the same)
|
|
8209
|
-
// so it doesn't matter which one we take here.
|
|
8210
|
-
(perCore) => perCore[0], (serviceId) => {
|
|
8211
|
-
const array = new Array(ctx.coresCount).fill(serviceId);
|
|
8212
|
-
return tryAsPerCore(array, ctx);
|
|
8213
|
-
})),
|
|
8229
|
+
authManager: codecPerCore(codec$1.u32.asOpaque()),
|
|
8214
8230
|
validatorsManager: codec$1.u32.asOpaque(),
|
|
8215
8231
|
autoAccumulateServices: readonlyArray(codec$1.sequenceVarLen(AutoAccumulate.Codec)),
|
|
8216
8232
|
});
|
|
@@ -8555,7 +8571,6 @@ class ServiceAccountInfo extends WithDebug {
|
|
|
8555
8571
|
* https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
|
|
8556
8572
|
*/
|
|
8557
8573
|
static calculateThresholdBalance(items, bytes, gratisStorage) {
|
|
8558
|
-
check(gratisStorage === tryAsU64(0) || Compatibility.isGreaterOrEqual(GpVersion.V0_6_7), "Gratis storage cannot be non-zero before 0.6.7");
|
|
8559
8574
|
const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
|
|
8560
8575
|
if (storageCost < 0n) {
|
|
8561
8576
|
return tryAsU64(0);
|
|
@@ -9867,26 +9882,17 @@ function* serializeRemovedServices(servicesRemoved) {
|
|
|
9867
9882
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
9868
9883
|
}
|
|
9869
9884
|
}
|
|
9870
|
-
function getLegacyKey(serviceId, rawKey) {
|
|
9871
|
-
const SERVICE_ID_BYTES = 4;
|
|
9872
|
-
const serviceIdAndKey = new Uint8Array(SERVICE_ID_BYTES + rawKey.length);
|
|
9873
|
-
serviceIdAndKey.set(u32AsLeBytes(serviceId));
|
|
9874
|
-
serviceIdAndKey.set(rawKey.raw, SERVICE_ID_BYTES);
|
|
9875
|
-
return asOpaqueType(BytesBlob.blobFrom(hashBytes(serviceIdAndKey).raw));
|
|
9876
|
-
}
|
|
9877
9885
|
function* serializeStorage(storage) {
|
|
9878
9886
|
for (const { action, serviceId } of storage ?? []) {
|
|
9879
9887
|
switch (action.kind) {
|
|
9880
9888
|
case UpdateStorageKind.Set: {
|
|
9881
|
-
const key =
|
|
9882
|
-
? action.storage.key
|
|
9883
|
-
: getLegacyKey(serviceId, action.storage.key);
|
|
9889
|
+
const key = action.storage.key;
|
|
9884
9890
|
const codec = serialize.serviceStorage(serviceId, key);
|
|
9885
9891
|
yield [StateEntryUpdateAction.Insert, codec.key, action.storage.value];
|
|
9886
9892
|
break;
|
|
9887
9893
|
}
|
|
9888
9894
|
case UpdateStorageKind.Remove: {
|
|
9889
|
-
const key =
|
|
9895
|
+
const key = action.key;
|
|
9890
9896
|
const codec = serialize.serviceStorage(serviceId, key);
|
|
9891
9897
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
9892
9898
|
break;
|
|
@@ -9995,7 +10001,7 @@ function* serializeBasicKeys(spec, update) {
|
|
|
9995
10001
|
if (update.recentlyAccumulated !== undefined) {
|
|
9996
10002
|
yield doSerialize(update.recentlyAccumulated, serialize.recentlyAccumulated); // C(15)
|
|
9997
10003
|
}
|
|
9998
|
-
if (update.accumulationOutputLog !== undefined
|
|
10004
|
+
if (update.accumulationOutputLog !== undefined) {
|
|
9999
10005
|
yield doSerialize(update.accumulationOutputLog, serialize.accumulationOutputLog); // C(16)
|
|
10000
10006
|
}
|
|
10001
10007
|
}
|
|
@@ -10135,10 +10141,7 @@ class SerializedState {
|
|
|
10135
10141
|
return this.retrieve(serialize.privilegedServices, "privilegedServices");
|
|
10136
10142
|
}
|
|
10137
10143
|
get accumulationOutputLog() {
|
|
10138
|
-
|
|
10139
|
-
return this.retrieve(serialize.accumulationOutputLog, "accumulationOutputLog");
|
|
10140
|
-
}
|
|
10141
|
-
return [];
|
|
10144
|
+
return this.retrieve(serialize.accumulationOutputLog, "accumulationOutputLog");
|
|
10142
10145
|
}
|
|
10143
10146
|
}
|
|
10144
10147
|
/** Service data representation on a serialized state. */
|
|
@@ -10839,9 +10842,7 @@ function convertInMemoryStateToDictionary(spec, state) {
|
|
|
10839
10842
|
doSerialize(serialize.statistics); // C(13)
|
|
10840
10843
|
doSerialize(serialize.accumulationQueue); // C(14)
|
|
10841
10844
|
doSerialize(serialize.recentlyAccumulated); // C(15)
|
|
10842
|
-
|
|
10843
|
-
doSerialize(serialize.accumulationOutputLog); // C(16)
|
|
10844
|
-
}
|
|
10845
|
+
doSerialize(serialize.accumulationOutputLog); // C(16)
|
|
10845
10846
|
// services
|
|
10846
10847
|
for (const [serviceId, service] of state.services.entries()) {
|
|
10847
10848
|
// data
|
|
@@ -12828,11 +12829,12 @@ var index$a = /*#__PURE__*/Object.freeze({
|
|
|
12828
12829
|
|
|
12829
12830
|
var Level;
|
|
12830
12831
|
(function (Level) {
|
|
12831
|
-
Level[Level["
|
|
12832
|
-
Level[Level["
|
|
12833
|
-
Level[Level["
|
|
12834
|
-
Level[Level["
|
|
12835
|
-
Level[Level["
|
|
12832
|
+
Level[Level["INSANE"] = 1] = "INSANE";
|
|
12833
|
+
Level[Level["TRACE"] = 2] = "TRACE";
|
|
12834
|
+
Level[Level["LOG"] = 3] = "LOG";
|
|
12835
|
+
Level[Level["INFO"] = 4] = "INFO";
|
|
12836
|
+
Level[Level["WARN"] = 5] = "WARN";
|
|
12837
|
+
Level[Level["ERROR"] = 6] = "ERROR";
|
|
12836
12838
|
})(Level || (Level = {}));
|
|
12837
12839
|
/**
|
|
12838
12840
|
* Find a configured log level for given module.
|
|
@@ -12901,7 +12903,7 @@ function parseLoggerOptions(input, defaultLevel, workingDir) {
|
|
|
12901
12903
|
function parseLevel(lvl) {
|
|
12902
12904
|
const typedLvl = lvl === "debug" ? "LOG" : lvl.toUpperCase();
|
|
12903
12905
|
if (Level[typedLvl] === undefined) {
|
|
12904
|
-
throw new Error(`Unknown logging level: "${lvl}". Use one of "trace", "debug", "log","info", "warn", "error"`);
|
|
12906
|
+
throw new Error(`Unknown logging level: "${lvl}". Use one of "trace", "debug", "log","info", "warn", "error" or "insane"`);
|
|
12905
12907
|
}
|
|
12906
12908
|
return Level[typedLvl];
|
|
12907
12909
|
}
|
|
@@ -12917,6 +12919,10 @@ class ConsoleTransport {
|
|
|
12917
12919
|
* `minimalLevel`.
|
|
12918
12920
|
*/
|
|
12919
12921
|
static create(minimalLevel, options) {
|
|
12922
|
+
// optimised transports if we don't care about trace/log levels
|
|
12923
|
+
if (minimalLevel === Level.INSANE) {
|
|
12924
|
+
return new InsaneConsoleLogger(options);
|
|
12925
|
+
}
|
|
12920
12926
|
// optimised transports if we don't care about trace/log levels
|
|
12921
12927
|
if (minimalLevel === Level.TRACE) {
|
|
12922
12928
|
return new TraceConsoleTransport(options);
|
|
@@ -12932,30 +12938,32 @@ class ConsoleTransport {
|
|
|
12932
12938
|
constructor(options) {
|
|
12933
12939
|
this.options = options;
|
|
12934
12940
|
}
|
|
12935
|
-
|
|
12941
|
+
insane(_moduleName, _val) {
|
|
12936
12942
|
/* no-op */
|
|
12937
12943
|
}
|
|
12938
|
-
|
|
12944
|
+
trace(_moduleName, _val) {
|
|
12939
12945
|
/* no-op */
|
|
12940
12946
|
}
|
|
12941
|
-
|
|
12947
|
+
log(_moduleName, _val) {
|
|
12942
12948
|
/* no-op */
|
|
12943
12949
|
}
|
|
12944
|
-
|
|
12945
|
-
|
|
12950
|
+
info(_moduleName, _val) {
|
|
12951
|
+
/* no-op */
|
|
12952
|
+
}
|
|
12953
|
+
warn(moduleName, val) {
|
|
12954
|
+
this.push(Level.WARN, moduleName, val);
|
|
12946
12955
|
}
|
|
12947
|
-
error(moduleName,
|
|
12948
|
-
this.push(Level.ERROR, moduleName,
|
|
12956
|
+
error(moduleName, val) {
|
|
12957
|
+
this.push(Level.ERROR, moduleName, val);
|
|
12949
12958
|
}
|
|
12950
|
-
push(level, moduleName,
|
|
12951
|
-
const shortName = fileName.replace(this.options.workingDir, "");
|
|
12959
|
+
push(level, moduleName, val) {
|
|
12952
12960
|
const shortModule = moduleName.replace(this.options.workingDir, "");
|
|
12953
12961
|
const configuredLevel = findLevel(this.options, moduleName);
|
|
12954
12962
|
const lvlText = Level[level].padEnd(5);
|
|
12955
12963
|
if (level < configuredLevel) {
|
|
12956
12964
|
return;
|
|
12957
12965
|
}
|
|
12958
|
-
const msg = `${lvlText} [${shortModule}] ${val}
|
|
12966
|
+
const msg = `${lvlText} [${shortModule}] ${val}`;
|
|
12959
12967
|
if (level === Level.WARN) {
|
|
12960
12968
|
console.warn(msg);
|
|
12961
12969
|
}
|
|
@@ -12967,46 +12975,72 @@ class ConsoleTransport {
|
|
|
12967
12975
|
}
|
|
12968
12976
|
}
|
|
12969
12977
|
}
|
|
12978
|
+
/**
|
|
12979
|
+
* Insane version of console logger - supports insane level.
|
|
12980
|
+
*/
|
|
12981
|
+
class InsaneConsoleLogger extends ConsoleTransport {
|
|
12982
|
+
insane(moduleName, val) {
|
|
12983
|
+
this.push(Level.INSANE, moduleName, val);
|
|
12984
|
+
}
|
|
12985
|
+
trace(moduleName, val) {
|
|
12986
|
+
this.push(Level.TRACE, moduleName, val);
|
|
12987
|
+
}
|
|
12988
|
+
log(moduleName, val) {
|
|
12989
|
+
this.push(Level.LOG, moduleName, val);
|
|
12990
|
+
}
|
|
12991
|
+
info(moduleName, val) {
|
|
12992
|
+
this.push(Level.INFO, moduleName, val);
|
|
12993
|
+
}
|
|
12994
|
+
}
|
|
12970
12995
|
/**
|
|
12971
12996
|
* A basic version of console logger - printing everything.
|
|
12972
12997
|
*/
|
|
12973
12998
|
class TraceConsoleTransport extends ConsoleTransport {
|
|
12974
|
-
|
|
12975
|
-
|
|
12999
|
+
insane(_moduleName, _val) {
|
|
13000
|
+
/* no-op */
|
|
13001
|
+
}
|
|
13002
|
+
trace(moduleName, val) {
|
|
13003
|
+
this.push(Level.TRACE, moduleName, val);
|
|
12976
13004
|
}
|
|
12977
|
-
log(moduleName,
|
|
12978
|
-
this.push(Level.LOG, moduleName,
|
|
13005
|
+
log(moduleName, val) {
|
|
13006
|
+
this.push(Level.LOG, moduleName, val);
|
|
12979
13007
|
}
|
|
12980
|
-
info(moduleName,
|
|
12981
|
-
this.push(Level.INFO, moduleName,
|
|
13008
|
+
info(moduleName, val) {
|
|
13009
|
+
this.push(Level.INFO, moduleName, val);
|
|
12982
13010
|
}
|
|
12983
13011
|
}
|
|
12984
13012
|
/**
|
|
12985
13013
|
* An optimized version of the logger - completely ignores `TRACE` level calls.
|
|
12986
13014
|
*/
|
|
12987
13015
|
class LogConsoleTransport extends ConsoleTransport {
|
|
12988
|
-
|
|
13016
|
+
insane(_moduleName, _val) {
|
|
12989
13017
|
/* no-op */
|
|
12990
13018
|
}
|
|
12991
|
-
|
|
12992
|
-
|
|
13019
|
+
trace(_moduleName, _val) {
|
|
13020
|
+
/* no-op */
|
|
13021
|
+
}
|
|
13022
|
+
log(moduleName, val) {
|
|
13023
|
+
this.push(Level.LOG, moduleName, val);
|
|
12993
13024
|
}
|
|
12994
|
-
info(moduleName,
|
|
12995
|
-
this.push(Level.INFO, moduleName,
|
|
13025
|
+
info(moduleName, val) {
|
|
13026
|
+
this.push(Level.INFO, moduleName, val);
|
|
12996
13027
|
}
|
|
12997
13028
|
}
|
|
12998
13029
|
/**
|
|
12999
13030
|
* An optimized version of the logger - completely ignores `TRACE` & `DEBUG` level calls.
|
|
13000
13031
|
*/
|
|
13001
13032
|
class InfoConsoleTransport extends ConsoleTransport {
|
|
13002
|
-
|
|
13033
|
+
insane(_moduleName, _val) {
|
|
13034
|
+
/* no-op */
|
|
13035
|
+
}
|
|
13036
|
+
trace(_moduleName, _val) {
|
|
13003
13037
|
/* no-op */
|
|
13004
13038
|
}
|
|
13005
|
-
log(_moduleName,
|
|
13039
|
+
log(_moduleName, _val) {
|
|
13006
13040
|
/* no-op */
|
|
13007
13041
|
}
|
|
13008
|
-
info(moduleName,
|
|
13009
|
-
this.push(Level.INFO, moduleName,
|
|
13042
|
+
info(moduleName, val) {
|
|
13043
|
+
this.push(Level.INFO, moduleName, val);
|
|
13010
13044
|
}
|
|
13011
13045
|
}
|
|
13012
13046
|
|
|
@@ -13079,25 +13113,29 @@ class Logger {
|
|
|
13079
13113
|
this.fileName = fileName;
|
|
13080
13114
|
this.config = config;
|
|
13081
13115
|
}
|
|
13116
|
+
/** Log a message with `INSANE` level. */
|
|
13117
|
+
insane(val) {
|
|
13118
|
+
this.config.transport.insane(this.moduleName, val);
|
|
13119
|
+
}
|
|
13082
13120
|
/** Log a message with `TRACE` level. */
|
|
13083
13121
|
trace(val) {
|
|
13084
|
-
this.config.transport.trace(this.moduleName,
|
|
13122
|
+
this.config.transport.trace(this.moduleName, val);
|
|
13085
13123
|
}
|
|
13086
13124
|
/** Log a message with `DEBUG`/`LOG` level. */
|
|
13087
13125
|
log(val) {
|
|
13088
|
-
this.config.transport.log(this.moduleName,
|
|
13126
|
+
this.config.transport.log(this.moduleName, val);
|
|
13089
13127
|
}
|
|
13090
13128
|
/** Log a message with `INFO` level. */
|
|
13091
13129
|
info(val) {
|
|
13092
|
-
this.config.transport.info(this.moduleName,
|
|
13130
|
+
this.config.transport.info(this.moduleName, val);
|
|
13093
13131
|
}
|
|
13094
13132
|
/** Log a message with `WARN` level. */
|
|
13095
13133
|
warn(val) {
|
|
13096
|
-
this.config.transport.warn(this.moduleName,
|
|
13134
|
+
this.config.transport.warn(this.moduleName, val);
|
|
13097
13135
|
}
|
|
13098
13136
|
/** Log a message with `ERROR` level. */
|
|
13099
13137
|
error(val) {
|
|
13100
|
-
this.config.transport.error(this.moduleName,
|
|
13138
|
+
this.config.transport.error(this.moduleName, val);
|
|
13101
13139
|
}
|
|
13102
13140
|
}
|
|
13103
13141
|
|
|
@@ -14653,6 +14691,7 @@ var AccessType;
|
|
|
14653
14691
|
AccessType[AccessType["READ"] = 0] = "READ";
|
|
14654
14692
|
AccessType[AccessType["WRITE"] = 1] = "WRITE";
|
|
14655
14693
|
})(AccessType || (AccessType = {}));
|
|
14694
|
+
const logger$3 = Logger.new(undefined, "pvm:mem");
|
|
14656
14695
|
class Memory {
|
|
14657
14696
|
sbrkIndex;
|
|
14658
14697
|
virtualSbrkIndex;
|
|
@@ -14683,6 +14722,7 @@ class Memory {
|
|
|
14683
14722
|
if (bytes.length === 0) {
|
|
14684
14723
|
return Result$1.ok(OK);
|
|
14685
14724
|
}
|
|
14725
|
+
logger$3.insane(`MEM[${address}] <- ${BytesBlob.blobFrom(bytes)}`);
|
|
14686
14726
|
const pagesResult = this.getPages(address, bytes.length, AccessType.WRITE);
|
|
14687
14727
|
if (pagesResult.isError) {
|
|
14688
14728
|
return Result$1.error(pagesResult.error);
|
|
@@ -14749,6 +14789,7 @@ class Memory {
|
|
|
14749
14789
|
currentPosition += bytesToRead;
|
|
14750
14790
|
bytesLeft -= bytesToRead;
|
|
14751
14791
|
}
|
|
14792
|
+
logger$3.insane(`MEM[${startAddress}] => ${BytesBlob.blobFrom(result)}`);
|
|
14752
14793
|
return Result$1.ok(OK);
|
|
14753
14794
|
}
|
|
14754
14795
|
sbrk(length) {
|
|
@@ -16478,12 +16519,15 @@ class JumpTable {
|
|
|
16478
16519
|
static empty() {
|
|
16479
16520
|
return new JumpTable(0, new Uint8Array());
|
|
16480
16521
|
}
|
|
16522
|
+
getSize() {
|
|
16523
|
+
return this.indices.length;
|
|
16524
|
+
}
|
|
16481
16525
|
copyFrom(jt) {
|
|
16482
16526
|
this.indices = jt.indices;
|
|
16483
16527
|
}
|
|
16484
16528
|
}
|
|
16485
16529
|
|
|
16486
|
-
const logger$
|
|
16530
|
+
const logger$2 = Logger.new(undefined, "pvm-interpreter");
|
|
16487
16531
|
var ProgramDecoderError;
|
|
16488
16532
|
(function (ProgramDecoderError) {
|
|
16489
16533
|
ProgramDecoderError[ProgramDecoderError["InvalidProgramError"] = 0] = "InvalidProgramError";
|
|
@@ -16533,12 +16577,13 @@ class ProgramDecoder {
|
|
|
16533
16577
|
return Result$1.ok(new ProgramDecoder(program));
|
|
16534
16578
|
}
|
|
16535
16579
|
catch (e) {
|
|
16536
|
-
logger$
|
|
16580
|
+
logger$2.error(`Invalid program: ${e}`);
|
|
16537
16581
|
return Result$1.error(ProgramDecoderError.InvalidProgramError);
|
|
16538
16582
|
}
|
|
16539
16583
|
}
|
|
16540
16584
|
}
|
|
16541
16585
|
|
|
16586
|
+
const logger$1 = Logger.new(undefined, "pvm");
|
|
16542
16587
|
class Interpreter {
|
|
16543
16588
|
useSbrkGas;
|
|
16544
16589
|
registers = new Registers();
|
|
@@ -16656,6 +16701,7 @@ class Interpreter {
|
|
|
16656
16701
|
const argsType = instructionArgumentTypeMap[currentInstruction] ?? ArgumentType.NO_ARGUMENTS;
|
|
16657
16702
|
const argsResult = this.argsDecodingResults[argsType];
|
|
16658
16703
|
this.argsDecoder.fillArgs(this.pc, argsResult);
|
|
16704
|
+
logger$1.insane(`[PC: ${this.pc}] ${Instruction[currentInstruction]}`);
|
|
16659
16705
|
if (!isValidInstruction) {
|
|
16660
16706
|
this.instructionResult.status = Result.PANIC;
|
|
16661
16707
|
}
|
|
@@ -16727,6 +16773,7 @@ class Interpreter {
|
|
|
16727
16773
|
this.status = Status.HOST;
|
|
16728
16774
|
break;
|
|
16729
16775
|
}
|
|
16776
|
+
logger$1.insane(`[PC: ${this.pc}] Status: ${Result[this.instructionResult.status]}`);
|
|
16730
16777
|
return this.status;
|
|
16731
16778
|
}
|
|
16732
16779
|
this.pc = this.instructionResult.nextPc;
|
|
@@ -17149,13 +17196,14 @@ class HostCalls {
|
|
|
17149
17196
|
const gasBefore = gas.get();
|
|
17150
17197
|
const gasCost = typeof hostCall.gasCost === "number" ? hostCall.gasCost : hostCall.gasCost(regs);
|
|
17151
17198
|
const underflow = gas.sub(gasCost);
|
|
17199
|
+
const pcLog = `[PC: ${pvmInstance.getPC()}]`;
|
|
17152
17200
|
if (underflow) {
|
|
17153
|
-
this.hostCalls.traceHostCall(
|
|
17201
|
+
this.hostCalls.traceHostCall(`${pcLog} OOG`, index, hostCall, regs, gas.get());
|
|
17154
17202
|
return ReturnValue.fromStatus(pvmInstance.getGasConsumed(), Status.OOG);
|
|
17155
17203
|
}
|
|
17156
|
-
this.hostCalls.traceHostCall(
|
|
17204
|
+
this.hostCalls.traceHostCall(`${pcLog} Invoking`, index, hostCall, regs, gasBefore);
|
|
17157
17205
|
const result = await hostCall.execute(gas, regs, memory);
|
|
17158
|
-
this.hostCalls.traceHostCall(result === undefined ?
|
|
17206
|
+
this.hostCalls.traceHostCall(result === undefined ? `${pcLog} Result` : `${pcLog} Status(${PvmExecution[result]})`, index, hostCall, regs, gas.get());
|
|
17159
17207
|
if (result === PvmExecution.Halt) {
|
|
17160
17208
|
status = Status.HALT;
|
|
17161
17209
|
return this.getReturnValue(status, pvmInstance);
|
|
@@ -17239,7 +17287,7 @@ class HostCallsManager {
|
|
|
17239
17287
|
return `r${idx}=${value} (0x${value.toString(16)})`;
|
|
17240
17288
|
})
|
|
17241
17289
|
.join(", ");
|
|
17242
|
-
logger.
|
|
17290
|
+
logger.insane(`[${currentServiceId}] ${context} ${name}${requested}. Gas: ${gas}. Regs: ${registerValues}.`);
|
|
17243
17291
|
}
|
|
17244
17292
|
}
|
|
17245
17293
|
|
|
@@ -17372,36 +17420,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
|
|
|
17372
17420
|
fisherYatesShuffle: fisherYatesShuffle
|
|
17373
17421
|
});
|
|
17374
17422
|
|
|
17375
|
-
class
|
|
17376
|
-
static fromJson = json.object({
|
|
17377
|
-
code_hash: fromJson.bytes32(),
|
|
17378
|
-
balance: json.fromNumber((x) => tryAsU64(x)),
|
|
17379
|
-
min_item_gas: json.fromNumber((x) => tryAsServiceGas(x)),
|
|
17380
|
-
min_memo_gas: json.fromNumber((x) => tryAsServiceGas(x)),
|
|
17381
|
-
bytes: json.fromNumber((x) => tryAsU64(x)),
|
|
17382
|
-
items: "number",
|
|
17383
|
-
}, ({ code_hash, balance, min_item_gas, min_memo_gas, bytes, items }) => {
|
|
17384
|
-
return ServiceAccountInfo.create({
|
|
17385
|
-
codeHash: code_hash,
|
|
17386
|
-
balance,
|
|
17387
|
-
accumulateMinGas: min_item_gas,
|
|
17388
|
-
onTransferMinGas: min_memo_gas,
|
|
17389
|
-
storageUtilisationBytes: bytes,
|
|
17390
|
-
storageUtilisationCount: items,
|
|
17391
|
-
gratisStorage: tryAsU64(0),
|
|
17392
|
-
created: tryAsTimeSlot(0),
|
|
17393
|
-
lastAccumulation: tryAsTimeSlot(0),
|
|
17394
|
-
parentService: tryAsServiceId(0),
|
|
17395
|
-
});
|
|
17396
|
-
});
|
|
17397
|
-
code_hash;
|
|
17398
|
-
balance;
|
|
17399
|
-
min_item_gas;
|
|
17400
|
-
min_memo_gas;
|
|
17401
|
-
bytes;
|
|
17402
|
-
items;
|
|
17403
|
-
}
|
|
17404
|
-
class JsonServiceInfo extends JsonServiceInfoPre067 {
|
|
17423
|
+
class JsonServiceInfo {
|
|
17405
17424
|
static fromJson = json.object({
|
|
17406
17425
|
code_hash: fromJson.bytes32(),
|
|
17407
17426
|
balance: json.fromNumber((x) => tryAsU64(x)),
|
|
@@ -17427,6 +17446,12 @@ class JsonServiceInfo extends JsonServiceInfoPre067 {
|
|
|
17427
17446
|
parentService: parent_service,
|
|
17428
17447
|
});
|
|
17429
17448
|
});
|
|
17449
|
+
code_hash;
|
|
17450
|
+
balance;
|
|
17451
|
+
min_item_gas;
|
|
17452
|
+
min_memo_gas;
|
|
17453
|
+
bytes;
|
|
17454
|
+
items;
|
|
17430
17455
|
creation_slot;
|
|
17431
17456
|
deposit_offset;
|
|
17432
17457
|
last_accumulation_slot;
|
|
@@ -17459,9 +17484,7 @@ class JsonService {
|
|
|
17459
17484
|
static fromJson = json.object({
|
|
17460
17485
|
id: "number",
|
|
17461
17486
|
data: {
|
|
17462
|
-
service:
|
|
17463
|
-
? JsonServiceInfo.fromJson
|
|
17464
|
-
: JsonServiceInfoPre067.fromJson,
|
|
17487
|
+
service: JsonServiceInfo.fromJson,
|
|
17465
17488
|
preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
|
|
17466
17489
|
storage: json.optional(json.array(JsonStorageItem.fromJson)),
|
|
17467
17490
|
lookup_meta: json.optional(json.array(lookupMetaFromJson)),
|
|
@@ -17781,76 +17804,6 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17781
17804
|
services: new Map(accounts.map((x) => [x.serviceId, x])),
|
|
17782
17805
|
});
|
|
17783
17806
|
});
|
|
17784
|
-
const fullStateDumpFromJsonPre067 = (spec) => json.object({
|
|
17785
|
-
alpha: json.array(json.array(fromJson.bytes32())),
|
|
17786
|
-
varphi: json.array(json.array(fromJson.bytes32())),
|
|
17787
|
-
beta: json.nullable(recentBlocksHistoryFromJson),
|
|
17788
|
-
gamma: {
|
|
17789
|
-
gamma_k: json.array(validatorDataFromJson),
|
|
17790
|
-
gamma_a: json.array(ticketFromJson),
|
|
17791
|
-
gamma_s: TicketsOrKeys.fromJson,
|
|
17792
|
-
gamma_z: json.fromString((v) => Bytes.parseBytes(v, BANDERSNATCH_RING_ROOT_BYTES).asOpaque()),
|
|
17793
|
-
},
|
|
17794
|
-
psi: disputesRecordsFromJson,
|
|
17795
|
-
eta: json.array(fromJson.bytes32()),
|
|
17796
|
-
iota: json.array(validatorDataFromJson),
|
|
17797
|
-
kappa: json.array(validatorDataFromJson),
|
|
17798
|
-
lambda: json.array(validatorDataFromJson),
|
|
17799
|
-
rho: json.array(json.nullable(availabilityAssignmentFromJson)),
|
|
17800
|
-
tau: "number",
|
|
17801
|
-
chi: {
|
|
17802
|
-
chi_m: "number",
|
|
17803
|
-
chi_a: "number",
|
|
17804
|
-
chi_v: "number",
|
|
17805
|
-
chi_g: json.nullable(json.array({
|
|
17806
|
-
service: "number",
|
|
17807
|
-
gasLimit: json.fromNumber((v) => tryAsServiceGas(v)),
|
|
17808
|
-
})),
|
|
17809
|
-
},
|
|
17810
|
-
pi: JsonStatisticsData.fromJson,
|
|
17811
|
-
theta: json.array(json.array(notYetAccumulatedFromJson)),
|
|
17812
|
-
xi: json.array(json.array(fromJson.bytes32())),
|
|
17813
|
-
accounts: json.array(JsonService.fromJson),
|
|
17814
|
-
}, ({ alpha, varphi, beta, gamma, psi, eta, iota, kappa, lambda, rho, tau, chi, pi, theta, xi, accounts, }) => {
|
|
17815
|
-
return InMemoryState.create({
|
|
17816
|
-
authPools: tryAsPerCore(alpha.map((perCore) => {
|
|
17817
|
-
if (perCore.length > MAX_AUTH_POOL_SIZE) {
|
|
17818
|
-
throw new Error(`AuthPools: expected less than ${MAX_AUTH_POOL_SIZE}, got ${perCore.length}`);
|
|
17819
|
-
}
|
|
17820
|
-
return asKnownSize(perCore);
|
|
17821
|
-
}), spec),
|
|
17822
|
-
authQueues: tryAsPerCore(varphi.map((perCore) => {
|
|
17823
|
-
if (perCore.length !== AUTHORIZATION_QUEUE_SIZE) {
|
|
17824
|
-
throw new Error(`AuthQueues: expected ${AUTHORIZATION_QUEUE_SIZE}, got: ${perCore.length}`);
|
|
17825
|
-
}
|
|
17826
|
-
return asKnownSize(perCore);
|
|
17827
|
-
}), spec),
|
|
17828
|
-
recentBlocks: beta ?? RecentBlocksHistory.empty(),
|
|
17829
|
-
nextValidatorData: gamma.gamma_k,
|
|
17830
|
-
epochRoot: gamma.gamma_z,
|
|
17831
|
-
sealingKeySeries: TicketsOrKeys.toSafroleSealingKeys(gamma.gamma_s, spec),
|
|
17832
|
-
ticketsAccumulator: gamma.gamma_a,
|
|
17833
|
-
disputesRecords: psi,
|
|
17834
|
-
entropy: eta,
|
|
17835
|
-
designatedValidatorData: iota,
|
|
17836
|
-
currentValidatorData: kappa,
|
|
17837
|
-
previousValidatorData: lambda,
|
|
17838
|
-
availabilityAssignment: rho,
|
|
17839
|
-
timeslot: tau,
|
|
17840
|
-
privilegedServices: PrivilegedServices.create({
|
|
17841
|
-
manager: chi.chi_m,
|
|
17842
|
-
authManager: tryAsPerCore(new Array(spec.coresCount).fill(chi.chi_a), spec),
|
|
17843
|
-
validatorsManager: chi.chi_v,
|
|
17844
|
-
autoAccumulateServices: chi.chi_g ?? [],
|
|
17845
|
-
}),
|
|
17846
|
-
statistics: JsonStatisticsData.toStatisticsData(spec, pi),
|
|
17847
|
-
accumulationQueue: theta,
|
|
17848
|
-
recentlyAccumulated: tryAsPerEpochBlock(xi.map((x) => HashSet.from(x)), spec),
|
|
17849
|
-
services: new Map(accounts.map((x) => [x.serviceId, x])),
|
|
17850
|
-
// NOTE Field not present in pre067, added here for compatibility reasons
|
|
17851
|
-
accumulationOutputLog: [],
|
|
17852
|
-
});
|
|
17853
|
-
});
|
|
17854
17807
|
|
|
17855
17808
|
var index$1 = /*#__PURE__*/Object.freeze({
|
|
17856
17809
|
__proto__: null,
|
|
@@ -17862,7 +17815,6 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
17862
17815
|
availabilityAssignmentFromJson: availabilityAssignmentFromJson,
|
|
17863
17816
|
disputesRecordsFromJson: disputesRecordsFromJson,
|
|
17864
17817
|
fullStateDumpFromJson: fullStateDumpFromJson,
|
|
17865
|
-
fullStateDumpFromJsonPre067: fullStateDumpFromJsonPre067,
|
|
17866
17818
|
notYetAccumulatedFromJson: notYetAccumulatedFromJson,
|
|
17867
17819
|
recentBlocksHistoryFromJson: recentBlocksHistoryFromJson,
|
|
17868
17820
|
reportedWorkPackageFromJson: reportedWorkPackageFromJson,
|