@typeberry/jam 0.2.0-daa61f5 → 0.2.0-dabd741
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/README.md +3 -3
- package/bootstrap-generator.mjs +29 -36
- package/bootstrap-generator.mjs.map +1 -1
- package/bootstrap-importer.mjs +4191 -4132
- package/bootstrap-importer.mjs.map +1 -1
- package/bootstrap-network.mjs +16 -3
- package/bootstrap-network.mjs.map +1 -1
- package/index.js +5009 -4945
- package/index.js.map +1 -1
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# typeberry 🫐
|
|
2
2
|
|
|
3
|
-
[](https://github.com/FluffyLabs/typeberry/actions/workflows/vectors-jam-conformance-071.yml) [](https://github.com/FluffyLabs/typeberry/actions/workflows/vectors-w3f-davxy-071.yml) [](https://github.com/FluffyLabs/typeberry/actions/workflows/vectors-w3f.yml) [](https://github.com/FluffyLabs/typeberry/actions/workflows/prize-blockchain.yml) [](https://opensource.org/licenses/MPL-2.0)
|
|
4
4
|
|
|
5
5
|
Typeberry is a TypeScript implementation of [JAM protocol](https://graypaper.com/) by Fluffy Labs.
|
|
6
6
|
|
|
@@ -23,10 +23,10 @@ JAM Prize requirements
|
|
|
23
23
|
- [x] Block import
|
|
24
24
|
- [x] W3F test vectors
|
|
25
25
|
- [x] JAM Conformance Fuzzer
|
|
26
|
-
- [
|
|
26
|
+
- [x] Performance optimisations
|
|
27
27
|
- [ ] Milestone 2
|
|
28
28
|
- [x] Networking (partial)
|
|
29
|
-
- [
|
|
29
|
+
- [x] Fast PVM (ananas)
|
|
30
30
|
- [ ] Milestone 3
|
|
31
31
|
- [ ] PVM Recompiler
|
|
32
32
|
- [ ] Milestone 4
|
package/bootstrap-generator.mjs
CHANGED
|
@@ -3063,6 +3063,13 @@ class WithDebug {
|
|
|
3063
3063
|
return debug_inspect(this);
|
|
3064
3064
|
}
|
|
3065
3065
|
}
|
|
3066
|
+
function lazyInspect(obj) {
|
|
3067
|
+
return {
|
|
3068
|
+
toString() {
|
|
3069
|
+
return debug_inspect(obj);
|
|
3070
|
+
},
|
|
3071
|
+
};
|
|
3072
|
+
}
|
|
3066
3073
|
|
|
3067
3074
|
;// CONCATENATED MODULE: ./packages/core/utils/dev.ts
|
|
3068
3075
|
const dev_env = typeof process === "undefined" ? {} : process.env;
|
|
@@ -3611,12 +3618,13 @@ class bytes_BytesBlob {
|
|
|
3611
3618
|
}
|
|
3612
3619
|
/** Display a hex-encoded version of this byte blob, but truncated if it's large. */
|
|
3613
3620
|
toStringTruncated() {
|
|
3621
|
+
const bytes = `${this.raw.length} ${this.raw.length === 1 ? "byte" : "bytes"}`;
|
|
3614
3622
|
if (this.raw.length > 32) {
|
|
3615
3623
|
const start = bytesToHexString(this.raw.subarray(0, 16));
|
|
3616
3624
|
const end = bytesToHexString(this.raw.subarray(this.raw.length - 16));
|
|
3617
|
-
return `${start}...${end.substring(2)} (${
|
|
3625
|
+
return `${start}...${end.substring(2)} (${bytes})`;
|
|
3618
3626
|
}
|
|
3619
|
-
return this.toString()
|
|
3627
|
+
return `${this.toString()} (${bytes})`;
|
|
3620
3628
|
}
|
|
3621
3629
|
toJSON() {
|
|
3622
3630
|
return this.toString();
|
|
@@ -7351,6 +7359,8 @@ const EC_SEGMENT_SIZE = 4104;
|
|
|
7351
7359
|
* Additional data that has to be passed to the codec to correctly parse incoming bytes.
|
|
7352
7360
|
*/
|
|
7353
7361
|
class ChainSpec extends WithDebug {
|
|
7362
|
+
/** Human-readable name of the chain spec. */
|
|
7363
|
+
name;
|
|
7354
7364
|
/** Number of validators. */
|
|
7355
7365
|
validatorsCount;
|
|
7356
7366
|
/** 1/3 of number of validators */
|
|
@@ -7393,6 +7403,7 @@ class ChainSpec extends WithDebug {
|
|
|
7393
7403
|
maxLookupAnchorAge;
|
|
7394
7404
|
constructor(data) {
|
|
7395
7405
|
super();
|
|
7406
|
+
this.name = data.name;
|
|
7396
7407
|
this.validatorsCount = data.validatorsCount;
|
|
7397
7408
|
this.thirdOfValidators = numbers_tryAsU16(Math.floor(data.validatorsCount / 3));
|
|
7398
7409
|
this.validatorsSuperMajority = numbers_tryAsU16(Math.floor(data.validatorsCount / 3) * 2 + 1);
|
|
@@ -7413,6 +7424,7 @@ class ChainSpec extends WithDebug {
|
|
|
7413
7424
|
}
|
|
7414
7425
|
/** Set of values for "tiny" chain as defined in JAM test vectors. */
|
|
7415
7426
|
const tinyChainSpec = new ChainSpec({
|
|
7427
|
+
name: "tiny",
|
|
7416
7428
|
validatorsCount: numbers_tryAsU16(6),
|
|
7417
7429
|
coresCount: numbers_tryAsU16(2),
|
|
7418
7430
|
epochLength: numbers_tryAsU32(12),
|
|
@@ -7434,6 +7446,7 @@ const tinyChainSpec = new ChainSpec({
|
|
|
7434
7446
|
* Please note that only validatorsCount and epochLength are "full", the rest is copied from "tiny".
|
|
7435
7447
|
*/
|
|
7436
7448
|
const fullChainSpec = new ChainSpec({
|
|
7449
|
+
name: "full",
|
|
7437
7450
|
validatorsCount: numbers_tryAsU16(1023),
|
|
7438
7451
|
coresCount: numbers_tryAsU16(341),
|
|
7439
7452
|
epochLength: numbers_tryAsU32(600),
|
|
@@ -9009,7 +9022,6 @@ function reencodeAsView(codec, object, chainSpec) {
|
|
|
9009
9022
|
|
|
9010
9023
|
|
|
9011
9024
|
|
|
9012
|
-
|
|
9013
9025
|
/** Helper function to create most used hashes in the block */
|
|
9014
9026
|
class TransitionHasher {
|
|
9015
9027
|
context;
|
|
@@ -9058,15 +9070,6 @@ class TransitionHasher {
|
|
|
9058
9070
|
const encoded = bytes_BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);
|
|
9059
9071
|
return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), extrinsicView, encoded);
|
|
9060
9072
|
}
|
|
9061
|
-
/** Creates hash for given WorkPackage */
|
|
9062
|
-
workPackage(workPackage) {
|
|
9063
|
-
return this.encode(WorkPackage.Codec, workPackage);
|
|
9064
|
-
}
|
|
9065
|
-
encode(codec, data) {
|
|
9066
|
-
// TODO [ToDr] Use already allocated encoding destination and hash bytes from some arena.
|
|
9067
|
-
const encoded = Encoder.encodeObject(codec, data, this.context);
|
|
9068
|
-
return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), data, encoded);
|
|
9069
|
-
}
|
|
9070
9073
|
}
|
|
9071
9074
|
|
|
9072
9075
|
;// CONCATENATED MODULE: ./packages/jam/state/accumulation-output.ts
|
|
@@ -9101,7 +9104,7 @@ function accumulationOutputComparator(a, b) {
|
|
|
9101
9104
|
if (result > 0) {
|
|
9102
9105
|
return Ordering.Greater;
|
|
9103
9106
|
}
|
|
9104
|
-
return
|
|
9107
|
+
return a.output.compare(b.output);
|
|
9105
9108
|
}
|
|
9106
9109
|
|
|
9107
9110
|
;// CONCATENATED MODULE: ./packages/jam/block/gp-constants.ts
|
|
@@ -10127,26 +10130,6 @@ class InMemoryStateView {
|
|
|
10127
10130
|
|
|
10128
10131
|
|
|
10129
10132
|
|
|
10130
|
-
/** Dictionary entry of services that auto-accumulate every block. */
|
|
10131
|
-
class AutoAccumulate {
|
|
10132
|
-
service;
|
|
10133
|
-
gasLimit;
|
|
10134
|
-
static Codec = descriptors_codec.Class(AutoAccumulate, {
|
|
10135
|
-
service: descriptors_codec.u32.asOpaque(),
|
|
10136
|
-
gasLimit: descriptors_codec.u64.asOpaque(),
|
|
10137
|
-
});
|
|
10138
|
-
static create({ service, gasLimit }) {
|
|
10139
|
-
return new AutoAccumulate(service, gasLimit);
|
|
10140
|
-
}
|
|
10141
|
-
constructor(
|
|
10142
|
-
/** Service id that auto-accumulates. */
|
|
10143
|
-
service,
|
|
10144
|
-
/** Gas limit for auto-accumulation. */
|
|
10145
|
-
gasLimit) {
|
|
10146
|
-
this.service = service;
|
|
10147
|
-
this.gasLimit = gasLimit;
|
|
10148
|
-
}
|
|
10149
|
-
}
|
|
10150
10133
|
/**
|
|
10151
10134
|
* https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
|
|
10152
10135
|
*/
|
|
@@ -10164,7 +10147,9 @@ class PrivilegedServices {
|
|
|
10164
10147
|
registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
10165
10148
|
? descriptors_codec.u32.asOpaque()
|
|
10166
10149
|
: ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
|
|
10167
|
-
autoAccumulateServices:
|
|
10150
|
+
autoAccumulateServices: descriptors_codec.dictionary(descriptors_codec.u32.asOpaque(), descriptors_codec.u64.asOpaque(), {
|
|
10151
|
+
sortKeys: (a, b) => a - b,
|
|
10152
|
+
}),
|
|
10168
10153
|
});
|
|
10169
10154
|
static create(a) {
|
|
10170
10155
|
return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
@@ -10427,6 +10412,15 @@ class InMemoryService extends WithDebug {
|
|
|
10427
10412
|
}),
|
|
10428
10413
|
};
|
|
10429
10414
|
}
|
|
10415
|
+
/** Return identical `InMemoryService` which does not share any references. */
|
|
10416
|
+
clone() {
|
|
10417
|
+
return new InMemoryService(this.serviceId, {
|
|
10418
|
+
info: ServiceAccountInfo.create(this.data.info),
|
|
10419
|
+
preimages: HashDictionary.fromEntries(Array.from(this.data.preimages.entries())),
|
|
10420
|
+
lookupHistory: HashDictionary.fromEntries(Array.from(this.data.lookupHistory.entries()).map(([k, v]) => [k, v.slice()])),
|
|
10421
|
+
storage: new Map(this.data.storage.entries()),
|
|
10422
|
+
});
|
|
10423
|
+
}
|
|
10430
10424
|
/**
|
|
10431
10425
|
* Create a new in-memory service from another state service
|
|
10432
10426
|
* by copying all given entries.
|
|
@@ -10797,7 +10791,7 @@ class InMemoryState extends WithDebug {
|
|
|
10797
10791
|
assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
|
|
10798
10792
|
delegator: tryAsServiceId(0),
|
|
10799
10793
|
registrar: tryAsServiceId(MAX_VALUE),
|
|
10800
|
-
autoAccumulateServices:
|
|
10794
|
+
autoAccumulateServices: new Map(),
|
|
10801
10795
|
}),
|
|
10802
10796
|
accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
|
|
10803
10797
|
services: new Map(),
|
|
@@ -10845,7 +10839,6 @@ var PreimagesErrorCode;
|
|
|
10845
10839
|
PreimagesErrorCode["PreimagesNotSortedUnique"] = "preimages_not_sorted_unique";
|
|
10846
10840
|
PreimagesErrorCode["AccountNotFound"] = "account_not_found";
|
|
10847
10841
|
})(PreimagesErrorCode || (PreimagesErrorCode = {}));
|
|
10848
|
-
// TODO [SeKo] consider whether this module is the right place to remove expired preimages
|
|
10849
10842
|
class Preimages {
|
|
10850
10843
|
state;
|
|
10851
10844
|
blake2b;
|