@typeberry/convert 0.2.0-0e2cdac → 0.2.0-2ecdea0
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.js +37 -44
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -8413,6 +8413,8 @@ const chain_spec_EC_SEGMENT_SIZE = 4104;
|
|
|
8413
8413
|
* Additional data that has to be passed to the codec to correctly parse incoming bytes.
|
|
8414
8414
|
*/
|
|
8415
8415
|
class ChainSpec extends WithDebug {
|
|
8416
|
+
/** Human-readable name of the chain spec. */
|
|
8417
|
+
name;
|
|
8416
8418
|
/** Number of validators. */
|
|
8417
8419
|
validatorsCount;
|
|
8418
8420
|
/** 1/3 of number of validators */
|
|
@@ -8455,6 +8457,7 @@ class ChainSpec extends WithDebug {
|
|
|
8455
8457
|
maxLookupAnchorAge;
|
|
8456
8458
|
constructor(data) {
|
|
8457
8459
|
super();
|
|
8460
|
+
this.name = data.name;
|
|
8458
8461
|
this.validatorsCount = data.validatorsCount;
|
|
8459
8462
|
this.thirdOfValidators = numbers_tryAsU16(Math.floor(data.validatorsCount / 3));
|
|
8460
8463
|
this.validatorsSuperMajority = numbers_tryAsU16(Math.floor(data.validatorsCount / 3) * 2 + 1);
|
|
@@ -8475,6 +8478,7 @@ class ChainSpec extends WithDebug {
|
|
|
8475
8478
|
}
|
|
8476
8479
|
/** Set of values for "tiny" chain as defined in JAM test vectors. */
|
|
8477
8480
|
const chain_spec_tinyChainSpec = new ChainSpec({
|
|
8481
|
+
name: "tiny",
|
|
8478
8482
|
validatorsCount: numbers_tryAsU16(6),
|
|
8479
8483
|
coresCount: numbers_tryAsU16(2),
|
|
8480
8484
|
epochLength: numbers_tryAsU32(12),
|
|
@@ -8496,6 +8500,7 @@ const chain_spec_tinyChainSpec = new ChainSpec({
|
|
|
8496
8500
|
* Please note that only validatorsCount and epochLength are "full", the rest is copied from "tiny".
|
|
8497
8501
|
*/
|
|
8498
8502
|
const chain_spec_fullChainSpec = new ChainSpec({
|
|
8503
|
+
name: "full",
|
|
8499
8504
|
validatorsCount: numbers_tryAsU16(1023),
|
|
8500
8505
|
coresCount: numbers_tryAsU16(341),
|
|
8501
8506
|
epochLength: numbers_tryAsU32(600),
|
|
@@ -10789,7 +10794,7 @@ const DEFAULT_CONFIG = "default";
|
|
|
10789
10794
|
const NODE_DEFAULTS = {
|
|
10790
10795
|
name: isBrowser() ? "browser" : external_node_os_default().hostname(),
|
|
10791
10796
|
config: [DEFAULT_CONFIG],
|
|
10792
|
-
pvm: pvm_backend_PvmBackend.
|
|
10797
|
+
pvm: pvm_backend_PvmBackend.Ananas,
|
|
10793
10798
|
};
|
|
10794
10799
|
/** Chain spec chooser. */
|
|
10795
10800
|
var KnownChainSpec;
|
|
@@ -12880,6 +12885,15 @@ class InMemoryService extends WithDebug {
|
|
|
12880
12885
|
}),
|
|
12881
12886
|
};
|
|
12882
12887
|
}
|
|
12888
|
+
/** Return identical `InMemoryService` which does not share any references. */
|
|
12889
|
+
clone() {
|
|
12890
|
+
return new InMemoryService(this.serviceId, {
|
|
12891
|
+
info: service_ServiceAccountInfo.create(this.data.info),
|
|
12892
|
+
preimages: hash_dictionary_HashDictionary.fromEntries(Array.from(this.data.preimages.entries())),
|
|
12893
|
+
lookupHistory: hash_dictionary_HashDictionary.fromEntries(Array.from(this.data.lookupHistory.entries()).map(([k, v]) => [k, v.slice()])),
|
|
12894
|
+
storage: new Map(this.data.storage.entries()),
|
|
12895
|
+
});
|
|
12896
|
+
}
|
|
12883
12897
|
/**
|
|
12884
12898
|
* Create a new in-memory service from another state service
|
|
12885
12899
|
* by copying all given entries.
|
|
@@ -15062,7 +15076,6 @@ function* serializeRemovedServices(servicesRemoved) {
|
|
|
15062
15076
|
return;
|
|
15063
15077
|
}
|
|
15064
15078
|
for (const serviceId of servicesRemoved) {
|
|
15065
|
-
// TODO [ToDr] what about all data associated with a service?
|
|
15066
15079
|
const codec = serialize.serviceData(serviceId);
|
|
15067
15080
|
yield [serialize_state_update_StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
15068
15081
|
}
|
|
@@ -15874,7 +15887,6 @@ class InMemoryStates {
|
|
|
15874
15887
|
|
|
15875
15888
|
|
|
15876
15889
|
|
|
15877
|
-
|
|
15878
15890
|
/** Helper function to create most used hashes in the block */
|
|
15879
15891
|
class hasher_TransitionHasher {
|
|
15880
15892
|
context;
|
|
@@ -15923,15 +15935,6 @@ class hasher_TransitionHasher {
|
|
|
15923
15935
|
const encoded = BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);
|
|
15924
15936
|
return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), extrinsicView, encoded);
|
|
15925
15937
|
}
|
|
15926
|
-
/** Creates hash for given WorkPackage */
|
|
15927
|
-
workPackage(workPackage) {
|
|
15928
|
-
return this.encode(WorkPackage.Codec, workPackage);
|
|
15929
|
-
}
|
|
15930
|
-
encode(codec, data) {
|
|
15931
|
-
// TODO [ToDr] Use already allocated encoding destination and hash bytes from some arena.
|
|
15932
|
-
const encoded = Encoder.encodeObject(codec, data, this.context);
|
|
15933
|
-
return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), data, encoded);
|
|
15934
|
-
}
|
|
15935
15938
|
}
|
|
15936
15939
|
|
|
15937
15940
|
;// CONCATENATED MODULE: ./packages/jam/transition/preimages.ts
|
|
@@ -15944,7 +15947,6 @@ var PreimagesErrorCode;
|
|
|
15944
15947
|
PreimagesErrorCode["PreimagesNotSortedUnique"] = "preimages_not_sorted_unique";
|
|
15945
15948
|
PreimagesErrorCode["AccountNotFound"] = "account_not_found";
|
|
15946
15949
|
})(PreimagesErrorCode || (PreimagesErrorCode = {}));
|
|
15947
|
-
// TODO [SeKo] consider whether this module is the right place to remove expired preimages
|
|
15948
15950
|
class preimages_Preimages {
|
|
15949
15951
|
state;
|
|
15950
15952
|
blake2b;
|
|
@@ -16514,7 +16516,7 @@ var ResultValues;
|
|
|
16514
16516
|
* reach the epoch change block.
|
|
16515
16517
|
*/
|
|
16516
16518
|
const ringCommitmentCache = [];
|
|
16517
|
-
//
|
|
16519
|
+
// NOTE [ToDr] We export the entire object to allow mocking in tests.
|
|
16518
16520
|
// Ideally we would just export functions and figure out how to mock
|
|
16519
16521
|
// properly in ESM.
|
|
16520
16522
|
/* harmony default export */ const bandersnatch_vrf = ({
|
|
@@ -17539,13 +17541,6 @@ var partial_state_ForgetPreimageError;
|
|
|
17539
17541
|
})(partial_state_ForgetPreimageError || (partial_state_ForgetPreimageError = {}));
|
|
17540
17542
|
/**
|
|
17541
17543
|
* Errors that may occur when the transfer is invoked.
|
|
17542
|
-
*
|
|
17543
|
-
* TODO [ToDr] Since I don't fully understand yet which of these
|
|
17544
|
-
* could be checked directly in the host call (i.e. if we will
|
|
17545
|
-
* have access to the service account state there) for now I keep
|
|
17546
|
-
* them safely in the `AccumulationPartialState` implementation.
|
|
17547
|
-
* However, if possible, these should be moved directly to the
|
|
17548
|
-
* host call implementation.
|
|
17549
17544
|
*/
|
|
17550
17545
|
var partial_state_TransferError;
|
|
17551
17546
|
(function (TransferError) {
|
|
@@ -17876,7 +17871,7 @@ class accumulate_externalities_AccumulateExternalities {
|
|
|
17876
17871
|
const status = slots === null ? null : slotsToPreimageStatus(slots.slots);
|
|
17877
17872
|
// The previous code needs to be forgotten and expired.
|
|
17878
17873
|
if (status?.status !== PreimageStatusKind.Unavailable) {
|
|
17879
|
-
return [false,
|
|
17874
|
+
return [false, `wrong status: ${status !== null ? PreimageStatusKind[status.status] : null}`];
|
|
17880
17875
|
}
|
|
17881
17876
|
const t = this.currentTimeslot;
|
|
17882
17877
|
const isExpired = status.data[1] < t - this.chainSpec.preimageExpungePeriod;
|
|
@@ -18266,7 +18261,8 @@ class accumulate_externalities_AccumulateExternalities {
|
|
|
18266
18261
|
}
|
|
18267
18262
|
eject(destination, previousCodeHash) {
|
|
18268
18263
|
const service = this.getServiceInfo(destination);
|
|
18269
|
-
|
|
18264
|
+
const isRemoved = this.updatedState.stateUpdate.services.removed.find((serviceId) => serviceId === destination) !== undefined;
|
|
18265
|
+
if (service === null || destination === null || isRemoved) {
|
|
18270
18266
|
return Result.error(EjectError.InvalidService, () => "Service missing");
|
|
18271
18267
|
}
|
|
18272
18268
|
const currentService = this.getCurrentServiceInfo();
|
|
@@ -23038,18 +23034,11 @@ class interpreter_Interpreter {
|
|
|
23038
23034
|
|
|
23039
23035
|
|
|
23040
23036
|
|
|
23041
|
-
;// CONCATENATED MODULE: external "node:url"
|
|
23042
|
-
const external_node_url_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:url");
|
|
23043
23037
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter-ananas/index.ts
|
|
23044
23038
|
|
|
23045
23039
|
|
|
23046
23040
|
|
|
23047
23041
|
|
|
23048
|
-
|
|
23049
|
-
|
|
23050
|
-
// TODO [ToDr] Temporary solution. We need to inline WASM files for the final build.
|
|
23051
|
-
const wasmPath = (0,external_node_url_namespaceObject.fileURLToPath)(new URL(import.meta.resolve("@fluffylabs/anan-as/release-mini.wasm"), import.meta.url));
|
|
23052
|
-
const wasmBuffer = (0,external_node_fs_namespaceObject.readFileSync)(wasmPath);
|
|
23053
23042
|
// Max u32 value
|
|
23054
23043
|
const INF_STEPS = (/* unused pure expression or super */ null && (2 ** 32 - 1));
|
|
23055
23044
|
class AnanasRegisters {
|
|
@@ -23135,8 +23124,7 @@ class pvm_interpreter_ananas_AnanasInterpreter {
|
|
|
23135
23124
|
this.gas = new AnanasGasCounter(instance);
|
|
23136
23125
|
}
|
|
23137
23126
|
static async new() {
|
|
23138
|
-
const
|
|
23139
|
-
const instance = await instantiate(wasmModule, {
|
|
23127
|
+
const instance = await instantiate({
|
|
23140
23128
|
env: {
|
|
23141
23129
|
abort: () => {
|
|
23142
23130
|
throw new Error("Abort called from WASM");
|
|
@@ -23584,17 +23572,19 @@ class Eject {
|
|
|
23584
23572
|
return;
|
|
23585
23573
|
}
|
|
23586
23574
|
const result = this.partialState.eject(serviceId, previousCodeHash);
|
|
23587
|
-
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- ${result_resultToString(result)}`;
|
|
23588
23575
|
// All good!
|
|
23589
23576
|
if (result.isOk) {
|
|
23577
|
+
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- OK`;
|
|
23590
23578
|
regs.set(eject_IN_OUT_REG, results_HostCallResult.OK);
|
|
23591
23579
|
return;
|
|
23592
23580
|
}
|
|
23593
23581
|
const e = result.error;
|
|
23594
23582
|
if (e === partial_state_EjectError.InvalidService) {
|
|
23583
|
+
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- WHO ${result_resultToString(result)}`;
|
|
23595
23584
|
regs.set(eject_IN_OUT_REG, results_HostCallResult.WHO);
|
|
23596
23585
|
}
|
|
23597
23586
|
else if (e === partial_state_EjectError.InvalidPreimage) {
|
|
23587
|
+
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- HUH ${result_resultToString(result)}`;
|
|
23598
23588
|
regs.set(eject_IN_OUT_REG, results_HostCallResult.HUH);
|
|
23599
23589
|
}
|
|
23600
23590
|
else {
|
|
@@ -24839,7 +24829,7 @@ class accumulate_Accumulate {
|
|
|
24839
24829
|
* https://graypaper.fluffylabs.dev/#/7e6ff6a/18d70118d701?v=0.6.7
|
|
24840
24830
|
*/
|
|
24841
24831
|
async accumulateSingleService(serviceId, transfers, operands, gasCost, slot, entropy, inputStateUpdate) {
|
|
24842
|
-
accumulate_logger.log `Accumulating service ${serviceId}, transfers: ${transfers.length} operands: ${operands.length} at slot: ${slot}
|
|
24832
|
+
accumulate_logger.log `Accumulating service ${serviceId}, transfers: ${transfers.length} operands: ${operands.length} at slot: ${slot}`;
|
|
24843
24833
|
const updatedState = new PartiallyUpdatedState(this.state, inputStateUpdate);
|
|
24844
24834
|
// update service balance from incoming transfers
|
|
24845
24835
|
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
|
|
@@ -26542,6 +26532,7 @@ class statistics_Statistics {
|
|
|
26542
26532
|
|
|
26543
26533
|
|
|
26544
26534
|
|
|
26535
|
+
|
|
26545
26536
|
class DbHeaderChain {
|
|
26546
26537
|
blocks;
|
|
26547
26538
|
constructor(blocks) {
|
|
@@ -26735,7 +26726,7 @@ class chain_stf_OnChain {
|
|
|
26735
26726
|
}
|
|
26736
26727
|
const { preimages, ...preimagesRest } = preimagesResult.ok;
|
|
26737
26728
|
assertEmpty(preimagesRest);
|
|
26738
|
-
const timerAccumulate = measure(
|
|
26729
|
+
const timerAccumulate = measure(`import:accumulate (${PvmBackend[this.accumulate.pvm]})`);
|
|
26739
26730
|
// accumulate
|
|
26740
26731
|
const accumulateResult = await this.accumulate.transition({
|
|
26741
26732
|
slot: timeSlot,
|
|
@@ -26975,22 +26966,24 @@ function blockAsView(spec, block) {
|
|
|
26975
26966
|
// that were run pre-V1 fuzzer version.
|
|
26976
26967
|
const jamConformance070V0Spec = new ChainSpec({
|
|
26977
26968
|
...chain_spec_tinyChainSpec,
|
|
26969
|
+
name: "jam-conformance-v070v0",
|
|
26978
26970
|
maxLookupAnchorAge: numbers_tryAsU32(14_400),
|
|
26979
26971
|
});
|
|
26980
|
-
async function runStateTransition(testContent,
|
|
26972
|
+
async function runStateTransition(testContent, options, variant) {
|
|
26973
|
+
const pvm = variant === "ananas" ? PvmBackend.Ananas : PvmBackend.BuiltIn;
|
|
26981
26974
|
const blake2b = await Blake2b.createHasher();
|
|
26982
26975
|
// a bit of a hack, but the new value for `maxLookupAnchorAge` was proposed with V1
|
|
26983
26976
|
// version of the fuzzer, yet these tests were still depending on the older value.
|
|
26984
26977
|
// To simplify the chain spec, we just special case this one vector here.
|
|
26985
|
-
const spec =
|
|
26978
|
+
const spec = options.path.includes("fuzz-reports/0.7.0/traces/1756548916/00000082.json")
|
|
26986
26979
|
? jamConformance070V0Spec
|
|
26987
|
-
: chainSpec;
|
|
26980
|
+
: options.chainSpec;
|
|
26988
26981
|
const preState = loadState(spec, blake2b, testContent.pre_state.keyvals);
|
|
26989
26982
|
const postState = loadState(spec, blake2b, testContent.post_state.keyvals);
|
|
26990
26983
|
const preStateRoot = preState.backend.getRootHash(blake2b);
|
|
26991
26984
|
const postStateRoot = postState.backend.getRootHash(blake2b);
|
|
26992
26985
|
const blockView = blockAsView(spec, testContent.block);
|
|
26993
|
-
const allBlocks = loadBlocks(
|
|
26986
|
+
const allBlocks = loadBlocks(options.path, spec);
|
|
26994
26987
|
const myBlockIndex = allBlocks.findIndex(({ header }) => header.timeSlotIndex === testContent.block.header.timeSlotIndex);
|
|
26995
26988
|
const previousBlocks = allBlocks.slice(0, myBlockIndex);
|
|
26996
26989
|
const hasher = new TransitionHasher(spec, await keccakHasher, blake2b);
|
|
@@ -26999,7 +26992,7 @@ async function runStateTransition(testContent, testPath, t, chainSpec) {
|
|
|
26999
26992
|
const headerHash = hasher.header(blockView.header.view());
|
|
27000
26993
|
return new WithHash(headerHash.hash, blockView);
|
|
27001
26994
|
}));
|
|
27002
|
-
const stf = new OnChain(spec, preState, blocksDb, hasher,
|
|
26995
|
+
const stf = new OnChain(spec, preState, blocksDb, hasher, pvm);
|
|
27003
26996
|
// verify that we compute the state root exactly the same.
|
|
27004
26997
|
assert.deepStrictEqual(testContent.pre_state.state_root.toString(), preStateRoot.toString());
|
|
27005
26998
|
assert.deepStrictEqual(testContent.post_state.state_root.toString(), postStateRoot.toString());
|
|
@@ -27024,7 +27017,7 @@ async function runStateTransition(testContent, testPath, t, chainSpec) {
|
|
|
27024
27017
|
preState.backend.applyUpdate(serializeStateUpdate(spec, blake2b, stfResult.ok));
|
|
27025
27018
|
// some conformance test vectors have an empty state, we run them, yet do not perform any assertions.
|
|
27026
27019
|
if (testContent.post_state.keyvals.length === 0) {
|
|
27027
|
-
|
|
27020
|
+
options.test.skip(`Successfuly run a test vector with empty post state!. Please verify: ${options.path}`);
|
|
27028
27021
|
return;
|
|
27029
27022
|
}
|
|
27030
27023
|
// if the stf was successful compare the resulting state and the root (redundant, but double checking).
|
|
@@ -27091,8 +27084,8 @@ const workItemFromJson = json.object({
|
|
|
27091
27084
|
extrinsic,
|
|
27092
27085
|
exportCount: export_count,
|
|
27093
27086
|
}));
|
|
27094
|
-
async function runWorkItemTest(test,
|
|
27095
|
-
runCodecTest(WorkItem.Codec, test,
|
|
27087
|
+
async function runWorkItemTest(test, { path }) {
|
|
27088
|
+
runCodecTest(WorkItem.Codec, test, path);
|
|
27096
27089
|
}
|
|
27097
27090
|
|
|
27098
27091
|
;// CONCATENATED MODULE: ./bin/test-runner/w3f/codec/work-package.ts
|
|
@@ -27138,7 +27131,7 @@ const workPackageFromJson = compatibility_Compatibility.isGreaterOrEqual(compati
|
|
|
27138
27131
|
context,
|
|
27139
27132
|
items: sized_array_FixedSizeArray.new(items, tryAsWorkItemsCount(items.length)),
|
|
27140
27133
|
}));
|
|
27141
|
-
async function runWorkPackageTest(test, file) {
|
|
27134
|
+
async function runWorkPackageTest(test, { path: file }) {
|
|
27142
27135
|
runCodecTest(WorkPackage.Codec, test, file);
|
|
27143
27136
|
}
|
|
27144
27137
|
|