@typeberry/jam 0.2.0-79dc2d4 → 0.2.0-98b01af

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # typeberry 🫐
2
2
 
3
- [![JAM Conformance 0.7.0](https://github.com/FluffyLabs/typeberry/actions/workflows/vectors-jam-conformance-070.yml/badge.svg?branch=main)](https://github.com/FluffyLabs/typeberry/actions/workflows/vectors-jam-conformance-070.yml) [![W3F vectors](https://github.com/FluffyLabs/typeberry/actions/workflows/vectors-w3f.yml/badge.svg?branch=main)](https://github.com/FluffyLabs/typeberry/actions/workflows/vectors-w3f.yml) [![Publish commits](https://github.com/FluffyLabs/typeberry/actions/workflows/blockchain-git-log.yml/badge.svg?branch=main)](https://github.com/FluffyLabs/typeberry/actions/workflows/blockchain-git-log.yml) [![License: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg)](https://opensource.org/licenses/MPL-2.0)
3
+ [![JAM Conformance 0.7.1](https://github.com/FluffyLabs/typeberry/actions/workflows/vectors-jam-conformance-071.yml/badge.svg?branch=main)](https://github.com/FluffyLabs/typeberry/actions/workflows/vectors-jam-conformance-071.yml) [![W3F davxy 0.7.1](https://github.com/FluffyLabs/typeberry/actions/workflows/vectors-w3f-davxy-071.yml/badge.svg?branch=main)](https://github.com/FluffyLabs/typeberry/actions/workflows/vectors-w3f-davxy-071.yml) [![W3F vectors](https://github.com/FluffyLabs/typeberry/actions/workflows/vectors-w3f.yml/badge.svg?branch=main)](https://github.com/FluffyLabs/typeberry/actions/workflows/vectors-w3f.yml) [![Publish commits](https://github.com/FluffyLabs/typeberry/actions/workflows/prize-blockchain.yml/badge.svg?branch=main)](https://github.com/FluffyLabs/typeberry/actions/workflows/prize-blockchain.yml) [![License: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg)](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
- - [ ] Performance optimisations
26
+ - [x] Performance optimisations
27
27
  - [ ] Milestone 2
28
28
  - [x] Networking (partial)
29
- - [ ] Fast PVM
29
+ - [x] Fast PVM (ananas)
30
30
  - [ ] Milestone 3
31
31
  - [ ] PVM Recompiler
32
32
  - [ ] Milestone 4
@@ -3618,12 +3618,13 @@ class bytes_BytesBlob {
3618
3618
  }
3619
3619
  /** Display a hex-encoded version of this byte blob, but truncated if it's large. */
3620
3620
  toStringTruncated() {
3621
+ const bytes = `${this.raw.length} ${this.raw.length === 1 ? "byte" : "bytes"}`;
3621
3622
  if (this.raw.length > 32) {
3622
3623
  const start = bytesToHexString(this.raw.subarray(0, 16));
3623
3624
  const end = bytesToHexString(this.raw.subarray(this.raw.length - 16));
3624
- return `${start}...${end.substring(2)} (${this.raw.length} bytes)`;
3625
+ return `${start}...${end.substring(2)} (${bytes})`;
3625
3626
  }
3626
- return this.toString();
3627
+ return `${this.toString()} (${bytes})`;
3627
3628
  }
3628
3629
  toJSON() {
3629
3630
  return this.toString();
@@ -7358,6 +7359,8 @@ const EC_SEGMENT_SIZE = 4104;
7358
7359
  * Additional data that has to be passed to the codec to correctly parse incoming bytes.
7359
7360
  */
7360
7361
  class ChainSpec extends WithDebug {
7362
+ /** Human-readable name of the chain spec. */
7363
+ name;
7361
7364
  /** Number of validators. */
7362
7365
  validatorsCount;
7363
7366
  /** 1/3 of number of validators */
@@ -7400,6 +7403,7 @@ class ChainSpec extends WithDebug {
7400
7403
  maxLookupAnchorAge;
7401
7404
  constructor(data) {
7402
7405
  super();
7406
+ this.name = data.name;
7403
7407
  this.validatorsCount = data.validatorsCount;
7404
7408
  this.thirdOfValidators = numbers_tryAsU16(Math.floor(data.validatorsCount / 3));
7405
7409
  this.validatorsSuperMajority = numbers_tryAsU16(Math.floor(data.validatorsCount / 3) * 2 + 1);
@@ -7420,6 +7424,7 @@ class ChainSpec extends WithDebug {
7420
7424
  }
7421
7425
  /** Set of values for "tiny" chain as defined in JAM test vectors. */
7422
7426
  const tinyChainSpec = new ChainSpec({
7427
+ name: "tiny",
7423
7428
  validatorsCount: numbers_tryAsU16(6),
7424
7429
  coresCount: numbers_tryAsU16(2),
7425
7430
  epochLength: numbers_tryAsU32(12),
@@ -7441,6 +7446,7 @@ const tinyChainSpec = new ChainSpec({
7441
7446
  * Please note that only validatorsCount and epochLength are "full", the rest is copied from "tiny".
7442
7447
  */
7443
7448
  const fullChainSpec = new ChainSpec({
7449
+ name: "full",
7444
7450
  validatorsCount: numbers_tryAsU16(1023),
7445
7451
  coresCount: numbers_tryAsU16(341),
7446
7452
  epochLength: numbers_tryAsU32(600),
@@ -9016,7 +9022,6 @@ function reencodeAsView(codec, object, chainSpec) {
9016
9022
 
9017
9023
 
9018
9024
 
9019
-
9020
9025
  /** Helper function to create most used hashes in the block */
9021
9026
  class TransitionHasher {
9022
9027
  context;
@@ -9065,15 +9070,6 @@ class TransitionHasher {
9065
9070
  const encoded = bytes_BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);
9066
9071
  return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), extrinsicView, encoded);
9067
9072
  }
9068
- /** Creates hash for given WorkPackage */
9069
- workPackage(workPackage) {
9070
- return this.encode(WorkPackage.Codec, workPackage);
9071
- }
9072
- encode(codec, data) {
9073
- // TODO [ToDr] Use already allocated encoding destination and hash bytes from some arena.
9074
- const encoded = Encoder.encodeObject(codec, data, this.context);
9075
- return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), data, encoded);
9076
- }
9077
9073
  }
9078
9074
 
9079
9075
  ;// CONCATENATED MODULE: ./packages/jam/state/accumulation-output.ts
@@ -9108,7 +9104,7 @@ function accumulationOutputComparator(a, b) {
9108
9104
  if (result > 0) {
9109
9105
  return Ordering.Greater;
9110
9106
  }
9111
- return Ordering.Equal;
9107
+ return a.output.compare(b.output);
9112
9108
  }
9113
9109
 
9114
9110
  ;// CONCATENATED MODULE: ./packages/jam/block/gp-constants.ts
@@ -10227,11 +10223,12 @@ class state_update_UpdatePreimage {
10227
10223
  this.action = action;
10228
10224
  }
10229
10225
  /** A preimage is provided. We should update the lookuphistory and add the preimage to db. */
10230
- static provide({ preimage, slot }) {
10226
+ static provide({ preimage, slot, providedFor, }) {
10231
10227
  return new state_update_UpdatePreimage({
10232
10228
  kind: UpdatePreimageKind.Provide,
10233
10229
  preimage,
10234
10230
  slot,
10231
+ providedFor,
10235
10232
  });
10236
10233
  }
10237
10234
  /** The preimage should be removed completely from the database. */
@@ -10416,6 +10413,15 @@ class InMemoryService extends WithDebug {
10416
10413
  }),
10417
10414
  };
10418
10415
  }
10416
+ /** Return identical `InMemoryService` which does not share any references. */
10417
+ clone() {
10418
+ return new InMemoryService(this.serviceId, {
10419
+ info: ServiceAccountInfo.create(this.data.info),
10420
+ preimages: HashDictionary.fromEntries(Array.from(this.data.preimages.entries())),
10421
+ lookupHistory: HashDictionary.fromEntries(Array.from(this.data.lookupHistory.entries()).map(([k, v]) => [k, v.slice()])),
10422
+ storage: new Map(this.data.storage.entries()),
10423
+ });
10424
+ }
10419
10425
  /**
10420
10426
  * Create a new in-memory service from another state service
10421
10427
  * by copying all given entries.
@@ -10834,7 +10840,6 @@ var PreimagesErrorCode;
10834
10840
  PreimagesErrorCode["PreimagesNotSortedUnique"] = "preimages_not_sorted_unique";
10835
10841
  PreimagesErrorCode["AccountNotFound"] = "account_not_found";
10836
10842
  })(PreimagesErrorCode || (PreimagesErrorCode = {}));
10837
- // TODO [SeKo] consider whether this module is the right place to remove expired preimages
10838
10843
  class Preimages {
10839
10844
  state;
10840
10845
  blake2b;
@@ -10880,6 +10885,7 @@ class Preimages {
10880
10885
  updates.push(UpdatePreimage.provide({
10881
10886
  preimage: PreimageItem.create({ hash, blob }),
10882
10887
  slot,
10888
+ providedFor: requester,
10883
10889
  }));
10884
10890
  pendingChanges.set(requester, updates);
10885
10891
  }