@typeberry/lib 0.0.1-886997c → 0.0.1-8a792cb

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.
Files changed (4) hide show
  1. package/configs/index.d.ts +74 -0
  2. package/index.d.ts +351 -295
  3. package/index.js +1448 -665
  4. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -160,6 +160,10 @@ declare class Compatibility {
160
160
  }
161
161
  }
162
162
 
163
+ declare function isBrowser() {
164
+ return typeof process === "undefined" || typeof process.abort === "undefined";
165
+ }
166
+
163
167
  /**
164
168
  * A function to perform runtime assertions.
165
169
  *
@@ -278,20 +282,19 @@ declare function inspect<T>(val: T): string {
278
282
  }
279
283
 
280
284
  /** Utility function to measure time taken for some operation [ms]. */
281
- declare const measure =
282
- typeof process === "undefined"
283
- ? (id: string) => {
284
- const start = performance.now();
285
- return () => `${id} took ${performance.now() - start}ms`;
286
- }
287
- : (id: string) => {
288
- const start = process.hrtime.bigint();
289
- return () => {
290
- const tookNano = process.hrtime.bigint() - start;
291
- const tookMilli = Number(tookNano / 1_000_000n).toFixed(2);
292
- return `${id} took ${tookMilli}ms`;
293
- };
285
+ declare const measure = isBrowser()
286
+ ? (id: string) => {
287
+ const start = performance.now();
288
+ return () => `${id} took ${performance.now() - start}ms`;
289
+ }
290
+ : (id: string) => {
291
+ const start = process.hrtime.bigint();
292
+ return () => {
293
+ const tookNano = process.hrtime.bigint() - start;
294
+ const tookMilli = Number(tookNano / 1_000_000n).toFixed(2);
295
+ return `${id} took ${tookMilli}ms`;
294
296
  };
297
+ };
295
298
 
296
299
  /** A class that adds `toString` method that prints all properties of an object. */
297
300
  declare abstract class WithDebug {
@@ -490,6 +493,8 @@ type DeepEqualOptions = {
490
493
  errorsCollector?: ErrorsCollector;
491
494
  };
492
495
 
496
+ declare let oomWarningPrinted = false;
497
+
493
498
  /** Deeply compare `actual` and `expected` values. */
494
499
  declare function deepEqual<T>(
495
500
  actual: T | undefined,
@@ -522,7 +527,7 @@ declare function deepEqual<T>(
522
527
  try {
523
528
  assert.strictEqual(actualDisp, expectedDisp, message);
524
529
  } catch (e) {
525
- if (isOoMWorkaroundNeeded) {
530
+ if (isOoMWorkaroundNeeded && !oomWarningPrinted) {
526
531
  console.warn(
527
532
  [
528
533
  "Stacktrace may be crappy because of a problem in nodejs.",
@@ -530,6 +535,7 @@ declare function deepEqual<T>(
530
535
  "Maybe we do not need it anymore",
531
536
  ].join("\n"),
532
537
  );
538
+ oomWarningPrinted = true;
533
539
  }
534
540
  throw e;
535
541
  }
@@ -778,17 +784,19 @@ declare const index$r_ensure: typeof ensure;
778
784
  declare const index$r_env: typeof env;
779
785
  declare const index$r_getAllKeysSorted: typeof getAllKeysSorted;
780
786
  declare const index$r_inspect: typeof inspect;
787
+ declare const index$r_isBrowser: typeof isBrowser;
781
788
  declare const index$r_isResult: typeof isResult;
782
789
  declare const index$r_isTaggedError: typeof isTaggedError;
783
790
  declare const index$r_maybeTaggedErrorToString: typeof maybeTaggedErrorToString;
784
791
  declare const index$r_measure: typeof measure;
792
+ declare const index$r_oomWarningPrinted: typeof oomWarningPrinted;
785
793
  declare const index$r_parseCurrentSuite: typeof parseCurrentSuite;
786
794
  declare const index$r_parseCurrentVersion: typeof parseCurrentVersion;
787
795
  declare const index$r_resultToString: typeof resultToString;
788
796
  declare const index$r_seeThrough: typeof seeThrough;
789
797
  declare const index$r_trimStack: typeof trimStack;
790
798
  declare namespace index$r {
791
- export { index$r_ALL_VERSIONS_IN_ORDER as ALL_VERSIONS_IN_ORDER, index$r_CURRENT_SUITE as CURRENT_SUITE, index$r_CURRENT_VERSION as CURRENT_VERSION, index$r_Compatibility as Compatibility, index$r_DEFAULT_SUITE as DEFAULT_SUITE, index$r_DEFAULT_VERSION as DEFAULT_VERSION, index$r_ErrorsCollector as ErrorsCollector, index$r_GpVersion as GpVersion, Result$2 as Result, index$r_RichTaggedError as RichTaggedError, index$r_TEST_COMPARE_USING as TEST_COMPARE_USING, index$r_TestSuite as TestSuite, index$r_WithDebug as WithDebug, index$r___OPAQUE_TYPE__ as __OPAQUE_TYPE__, index$r_asOpaqueType as asOpaqueType, index$r_assertEmpty as assertEmpty, index$r_assertNever as assertNever, index$r_callCompareFunction as callCompareFunction, index$r_cast as cast, index$r_check as check, index$r_deepEqual as deepEqual, index$r_ensure as ensure, index$r_env as env, index$r_getAllKeysSorted as getAllKeysSorted, index$r_inspect as inspect, index$r_isResult as isResult, index$r_isTaggedError as isTaggedError, index$r_maybeTaggedErrorToString as maybeTaggedErrorToString, index$r_measure as measure, index$r_parseCurrentSuite as parseCurrentSuite, index$r_parseCurrentVersion as parseCurrentVersion, index$r_resultToString as resultToString, index$r_seeThrough as seeThrough, index$r_trimStack as trimStack };
799
+ export { index$r_ALL_VERSIONS_IN_ORDER as ALL_VERSIONS_IN_ORDER, index$r_CURRENT_SUITE as CURRENT_SUITE, index$r_CURRENT_VERSION as CURRENT_VERSION, index$r_Compatibility as Compatibility, index$r_DEFAULT_SUITE as DEFAULT_SUITE, index$r_DEFAULT_VERSION as DEFAULT_VERSION, index$r_ErrorsCollector as ErrorsCollector, index$r_GpVersion as GpVersion, Result$2 as Result, index$r_RichTaggedError as RichTaggedError, index$r_TEST_COMPARE_USING as TEST_COMPARE_USING, index$r_TestSuite as TestSuite, index$r_WithDebug as WithDebug, index$r___OPAQUE_TYPE__ as __OPAQUE_TYPE__, index$r_asOpaqueType as asOpaqueType, index$r_assertEmpty as assertEmpty, index$r_assertNever as assertNever, index$r_callCompareFunction as callCompareFunction, index$r_cast as cast, index$r_check as check, index$r_deepEqual as deepEqual, index$r_ensure as ensure, index$r_env as env, index$r_getAllKeysSorted as getAllKeysSorted, index$r_inspect as inspect, index$r_isBrowser as isBrowser, index$r_isResult as isResult, index$r_isTaggedError as isTaggedError, index$r_maybeTaggedErrorToString as maybeTaggedErrorToString, index$r_measure as measure, index$r_oomWarningPrinted as oomWarningPrinted, index$r_parseCurrentSuite as parseCurrentSuite, index$r_parseCurrentVersion as parseCurrentVersion, index$r_resultToString as resultToString, index$r_seeThrough as seeThrough, index$r_trimStack as trimStack };
792
800
  export type { index$r_DeepEqualOptions as DeepEqualOptions, index$r_EnumMapping as EnumMapping, index$r_ErrorResult as ErrorResult, index$r_OK as OK, index$r_OkResult as OkResult, index$r_Opaque as Opaque, index$r_StringLiteral as StringLiteral, index$r_TaggedError as TaggedError, index$r_TokenOf as TokenOf, index$r_Uninstantiable as Uninstantiable, index$r_WithOpaque as WithOpaque };
793
801
  }
794
802
 
@@ -4456,6 +4464,84 @@ declare namespace index$m {
4456
4464
  export type { index$m_HashWithZeroedBit as HashWithZeroedBit, index$m_ImmutableHashDictionary as ImmutableHashDictionary, index$m_ImmutableHashSet as ImmutableHashSet, index$m_ImmutableSortedArray as ImmutableSortedArray, index$m_ImmutableSortedSet as ImmutableSortedSet, index$m_KeyMapper as KeyMapper, index$m_KeyMappers as KeyMappers, index$m_KnownSize as KnownSize, index$m_KnownSizeArray as KnownSizeArray, index$m_KnownSizeId as KnownSizeId, index$m_NestedMaps as NestedMaps };
4457
4465
  }
4458
4466
 
4467
+ declare namespace bandersnatch_d_exports {
4468
+ export { batch_verify_tickets, __wbg_init$2 as default, derive_public_key, initSync$2 as initSync, ring_commitment, verify_seal };
4469
+ export type { InitInput$2 as InitInput, InitOutput$2 as InitOutput, SyncInitInput$2 as SyncInitInput };
4470
+ }
4471
+ /* tslint:disable */
4472
+ /* eslint-disable */
4473
+ /**
4474
+ * @param {Uint8Array} keys
4475
+ * @returns {Uint8Array}
4476
+ */
4477
+ declare function ring_commitment(keys: Uint8Array): Uint8Array;
4478
+ /**
4479
+ * Derive Private and Public Key from Seed
4480
+ *
4481
+ * returns: `Vec<u8>` containing the exit (1 byte) status followed by the (32 bytes) public key
4482
+ * @param {Uint8Array} seed
4483
+ * @returns {Uint8Array}
4484
+ */
4485
+ declare function derive_public_key(seed: Uint8Array): Uint8Array;
4486
+ /**
4487
+ * Seal verification as defined in:
4488
+ * https://graypaper.fluffylabs.dev/#/68eaa1f/0eff000eff00?v=0.6.4
4489
+ * or
4490
+ * https://graypaper.fluffylabs.dev/#/68eaa1f/0e54010e5401?v=0.6.4
4491
+ * @param {Uint8Array} keys
4492
+ * @param {number} signer_key_index
4493
+ * @param {Uint8Array} seal_data
4494
+ * @param {Uint8Array} payload
4495
+ * @param {Uint8Array} aux_data
4496
+ * @returns {Uint8Array}
4497
+ */
4498
+ declare function verify_seal(keys: Uint8Array, signer_key_index: number, seal_data: Uint8Array, payload: Uint8Array, aux_data: Uint8Array): Uint8Array;
4499
+ /**
4500
+ * Verify multiple tickets at once as defined in:
4501
+ * https://graypaper.fluffylabs.dev/#/68eaa1f/0f3e000f3e00?v=0.6.4
4502
+ *
4503
+ * NOTE: the aux_data of VRF function is empty!
4504
+ * @param {Uint8Array} keys
4505
+ * @param {Uint8Array} tickets_data
4506
+ * @param {number} vrf_input_data_len
4507
+ * @returns {Uint8Array}
4508
+ */
4509
+ declare function batch_verify_tickets(keys: Uint8Array, tickets_data: Uint8Array, vrf_input_data_len: number): Uint8Array;
4510
+ type InitInput$2 = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
4511
+ interface InitOutput$2 {
4512
+ readonly memory: WebAssembly.Memory;
4513
+ readonly ring_commitment: (a: number, b: number, c: number) => void;
4514
+ readonly derive_public_key: (a: number, b: number, c: number) => void;
4515
+ readonly verify_seal: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
4516
+ readonly batch_verify_tickets: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
4517
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
4518
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
4519
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
4520
+ }
4521
+ type SyncInitInput$2 = BufferSource | WebAssembly.Module;
4522
+ /**
4523
+ * Instantiates the given `module`, which can either be bytes or
4524
+ * a precompiled `WebAssembly.Module`.
4525
+ *
4526
+ * @param {SyncInitInput} module
4527
+ *
4528
+ * @returns {InitOutput}
4529
+ */
4530
+ declare function initSync$2(module: SyncInitInput$2): InitOutput$2;
4531
+
4532
+ /**
4533
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
4534
+ * for everything else, calls `WebAssembly.instantiate` directly.
4535
+ *
4536
+ * @param {InitInput | Promise<InitInput>} module_or_path
4537
+ *
4538
+ * @returns {Promise<InitOutput>}
4539
+ */
4540
+ declare function __wbg_init$2(module_or_path?: InitInput$2 | Promise<InitInput$2>): Promise<InitOutput$2>;
4541
+ //#endregion
4542
+ //#region native/index.d.ts
4543
+ declare function initAll(): Promise<void>;
4544
+
4459
4545
  /** ED25519 private key size. */
4460
4546
  declare const ED25519_PRIV_KEY_BYTES = 32;
4461
4547
  type ED25519_PRIV_KEY_BYTES = typeof ED25519_PRIV_KEY_BYTES;
@@ -4548,7 +4634,7 @@ declare async function verify<T extends BytesBlob>(input: Input<T>[]): Promise<b
4548
4634
  offset += messageLength;
4549
4635
  }
4550
4636
 
4551
- const result = Array.from(verify_ed25519(data)).map((x) => x === 1);
4637
+ const result = Array.from(ed25519.verify_ed25519(data)).map((x) => x === 1);
4552
4638
  return Promise.resolve(result);
4553
4639
  }
4554
4640
 
@@ -4570,7 +4656,7 @@ declare async function verifyBatch<T extends BytesBlob>(input: Input<T>[]): Prom
4570
4656
 
4571
4657
  const data = BytesBlob.blobFromParts(first, ...rest).raw;
4572
4658
 
4573
- return Promise.resolve(verify_ed25519_batch(data));
4659
+ return Promise.resolve(ed25519.verify_ed25519_batch(data));
4574
4660
  }
4575
4661
 
4576
4662
  type ed25519_ED25519_KEY_BYTES = ED25519_KEY_BYTES;
@@ -4590,59 +4676,6 @@ declare namespace ed25519 {
4590
4676
  export type { ed25519_ED25519_KEY_BYTES as ED25519_KEY_BYTES, ed25519_ED25519_PRIV_KEY_BYTES as ED25519_PRIV_KEY_BYTES, ed25519_ED25519_SIGNATURE_BYTES as ED25519_SIGNATURE_BYTES, ed25519_Ed25519Key as Ed25519Key, ed25519_Ed25519Signature as Ed25519Signature, ed25519_Input as Input };
4591
4677
  }
4592
4678
 
4593
- /* tslint:disable */
4594
- /* eslint-disable */
4595
- /**
4596
- * @param {Uint8Array} keys
4597
- * @returns {Uint8Array}
4598
- */
4599
- declare function ring_commitment(keys: Uint8Array): Uint8Array;
4600
- /**
4601
- * Derive Private and Public Key from Seed
4602
- *
4603
- * returns: `Vec<u8>` containing the exit (1 byte) status followed by the (32 bytes) public key
4604
- * @param {Uint8Array} seed
4605
- * @returns {Uint8Array}
4606
- */
4607
- declare function derive_public_key(seed: Uint8Array): Uint8Array;
4608
- /**
4609
- * Seal verification as defined in:
4610
- * https://graypaper.fluffylabs.dev/#/68eaa1f/0eff000eff00?v=0.6.4
4611
- * or
4612
- * https://graypaper.fluffylabs.dev/#/68eaa1f/0e54010e5401?v=0.6.4
4613
- * @param {Uint8Array} keys
4614
- * @param {number} signer_key_index
4615
- * @param {Uint8Array} seal_data
4616
- * @param {Uint8Array} payload
4617
- * @param {Uint8Array} aux_data
4618
- * @returns {Uint8Array}
4619
- */
4620
- declare function verify_seal(keys: Uint8Array, signer_key_index: number, seal_data: Uint8Array, payload: Uint8Array, aux_data: Uint8Array): Uint8Array;
4621
- /**
4622
- * Verify multiple tickets at once as defined in:
4623
- * https://graypaper.fluffylabs.dev/#/68eaa1f/0f3e000f3e00?v=0.6.4
4624
- *
4625
- * NOTE: the aux_data of VRF function is empty!
4626
- * @param {Uint8Array} keys
4627
- * @param {Uint8Array} tickets_data
4628
- * @param {number} vrf_input_data_len
4629
- * @returns {Uint8Array}
4630
- */
4631
- declare function batch_verify_tickets(keys: Uint8Array, tickets_data: Uint8Array, vrf_input_data_len: number): Uint8Array;
4632
-
4633
- declare const bandersnatch_d_batch_verify_tickets: typeof batch_verify_tickets;
4634
- declare const bandersnatch_d_derive_public_key: typeof derive_public_key;
4635
- declare const bandersnatch_d_ring_commitment: typeof ring_commitment;
4636
- declare const bandersnatch_d_verify_seal: typeof verify_seal;
4637
- declare namespace bandersnatch_d {
4638
- export {
4639
- bandersnatch_d_batch_verify_tickets as batch_verify_tickets,
4640
- bandersnatch_d_derive_public_key as derive_public_key,
4641
- bandersnatch_d_ring_commitment as ring_commitment,
4642
- bandersnatch_d_verify_seal as verify_seal,
4643
- };
4644
- }
4645
-
4646
4679
  /** Bandersnatch public key size. */
4647
4680
  declare const BANDERSNATCH_KEY_BYTES = 32;
4648
4681
  type BANDERSNATCH_KEY_BYTES = typeof BANDERSNATCH_KEY_BYTES;
@@ -4700,7 +4733,7 @@ type BlsKey = Opaque<Bytes<BLS_KEY_BYTES>, "BlsKey">;
4700
4733
 
4701
4734
  /** Derive a Bandersnatch public key from a seed. */
4702
4735
  declare function publicKey(seed: Uint8Array): BandersnatchKey {
4703
- const key = derive_public_key(seed);
4736
+ const key = bandersnatch.derive_public_key(seed);
4704
4737
 
4705
4738
  check(key[0] === 0, "Invalid Bandersnatch public key derived from seed");
4706
4739
 
@@ -4826,7 +4859,7 @@ declare const index$l_bandersnatch: typeof bandersnatch;
4826
4859
  declare const index$l_ed25519: typeof ed25519;
4827
4860
  declare const index$l_keyDerivation: typeof keyDerivation;
4828
4861
  declare namespace index$l {
4829
- export { index$l_Ed25519Pair as Ed25519Pair, index$l_bandersnatch as bandersnatch, bandersnatch_d as bandersnatchWasm, index$l_ed25519 as ed25519, index$l_keyDerivation as keyDerivation };
4862
+ export { index$l_Ed25519Pair as Ed25519Pair, index$l_bandersnatch as bandersnatch, bandersnatch_d_exports as bandersnatchWasm, index$l_ed25519 as ed25519, initAll as initWasm, index$l_keyDerivation as keyDerivation };
4830
4863
  export type { index$l_BANDERSNATCH_KEY_BYTES as BANDERSNATCH_KEY_BYTES, index$l_BANDERSNATCH_PROOF_BYTES as BANDERSNATCH_PROOF_BYTES, index$l_BANDERSNATCH_RING_ROOT_BYTES as BANDERSNATCH_RING_ROOT_BYTES, index$l_BANDERSNATCH_VRF_SIGNATURE_BYTES as BANDERSNATCH_VRF_SIGNATURE_BYTES, index$l_BLS_KEY_BYTES as BLS_KEY_BYTES, index$l_BandersnatchKey as BandersnatchKey, index$l_BandersnatchProof as BandersnatchProof, index$l_BandersnatchRingRoot as BandersnatchRingRoot, index$l_BandersnatchSecretSeed as BandersnatchSecretSeed, index$l_BandersnatchVrfSignature as BandersnatchVrfSignature, index$l_BlsKey as BlsKey, index$l_ED25519_KEY_BYTES as ED25519_KEY_BYTES, index$l_ED25519_PRIV_KEY_BYTES as ED25519_PRIV_KEY_BYTES, index$l_ED25519_SIGNATURE_BYTES as ED25519_SIGNATURE_BYTES, index$l_Ed25519Key as Ed25519Key, index$l_Ed25519SecretSeed as Ed25519SecretSeed, index$l_Ed25519Signature as Ed25519Signature, KeySeed as PublicKeySeed, index$l_SEED_SIZE as SEED_SIZE };
4831
4864
  }
4832
4865
 
@@ -7820,7 +7853,7 @@ declare const DEV_CONFIG = "dev";
7820
7853
  declare const DEFAULT_CONFIG = "default";
7821
7854
 
7822
7855
  declare const NODE_DEFAULTS = {
7823
- name: os.hostname(),
7856
+ name: isBrowser() ? "browser" : os.hostname(),
7824
7857
  config: DEFAULT_CONFIG,
7825
7858
  };
7826
7859
 
@@ -7875,11 +7908,11 @@ declare class NodeConfiguration {
7875
7908
 
7876
7909
  declare function loadConfig(configPath: string): NodeConfiguration {
7877
7910
  if (configPath === DEFAULT_CONFIG) {
7878
- return parseFromJson(defaultConfigJson, NodeConfiguration.fromJson);
7911
+ return parseFromJson(configs.default, NodeConfiguration.fromJson);
7879
7912
  }
7880
7913
 
7881
7914
  if (configPath === DEV_CONFIG) {
7882
- return parseFromJson(devConfigJson, NodeConfiguration.fromJson);
7915
+ return parseFromJson(configs.dev, NodeConfiguration.fromJson);
7883
7916
  }
7884
7917
 
7885
7918
  try {
@@ -8743,31 +8776,18 @@ declare const ignoreValueWithDefault = <T>(defaultValue: T) =>
8743
8776
  * https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
8744
8777
  */
8745
8778
  declare class ServiceAccountInfo extends WithDebug {
8746
- static Codec = Compatibility.isGreaterOrEqual(GpVersion.V0_6_7)
8747
- ? codec.Class(ServiceAccountInfo, {
8748
- codeHash: codec.bytes(HASH_SIZE).asOpaque<CodeHash>(),
8749
- balance: codec.u64,
8750
- accumulateMinGas: codec.u64.convert((x) => x, tryAsServiceGas),
8751
- onTransferMinGas: codec.u64.convert((x) => x, tryAsServiceGas),
8752
- storageUtilisationBytes: codec.u64,
8753
- gratisStorage: codec.u64,
8754
- storageUtilisationCount: codec.u32,
8755
- created: codec.u32.convert((x) => x, tryAsTimeSlot),
8756
- lastAccumulation: codec.u32.convert((x) => x, tryAsTimeSlot),
8757
- parentService: codec.u32.convert((x) => x, tryAsServiceId),
8758
- })
8759
- : codec.Class(ServiceAccountInfo, {
8760
- codeHash: codec.bytes(HASH_SIZE).asOpaque<CodeHash>(),
8761
- balance: codec.u64,
8762
- accumulateMinGas: codec.u64.convert((x) => x, tryAsServiceGas),
8763
- onTransferMinGas: codec.u64.convert((x) => x, tryAsServiceGas),
8764
- storageUtilisationBytes: codec.u64,
8765
- storageUtilisationCount: codec.u32,
8766
- gratisStorage: ignoreValueWithDefault(tryAsU64(0)),
8767
- created: ignoreValueWithDefault(tryAsTimeSlot(0)),
8768
- lastAccumulation: ignoreValueWithDefault(tryAsTimeSlot(0)),
8769
- parentService: ignoreValueWithDefault(tryAsServiceId(0)),
8770
- });
8779
+ static Codec = codec.Class(ServiceAccountInfo, {
8780
+ codeHash: codec.bytes(HASH_SIZE).asOpaque<CodeHash>(),
8781
+ balance: codec.u64,
8782
+ accumulateMinGas: codec.u64.convert((x) => x, tryAsServiceGas),
8783
+ onTransferMinGas: codec.u64.convert((x) => x, tryAsServiceGas),
8784
+ storageUtilisationBytes: codec.u64,
8785
+ gratisStorage: codec.u64,
8786
+ storageUtilisationCount: codec.u32,
8787
+ created: codec.u32.convert((x) => x, tryAsTimeSlot),
8788
+ lastAccumulation: codec.u32.convert((x) => x, tryAsTimeSlot),
8789
+ parentService: codec.u32.convert((x) => x, tryAsServiceId),
8790
+ });
8771
8791
 
8772
8792
  static create(a: CodecRecord<ServiceAccountInfo>) {
8773
8793
  return new ServiceAccountInfo(
@@ -10361,7 +10381,7 @@ type StateCodec<T> = {
10361
10381
 
10362
10382
  /** Serialization for particular state entries. */
10363
10383
  declare namespace serialize {
10364
- /** C(1): https://graypaper.fluffylabs.dev/#/85129da/38a20138a201?v=0.6.3 */
10384
+ /** C(1): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b15013b1501?v=0.6.7 */
10365
10385
  export const authPools: StateCodec<State["authPools"]> = {
10366
10386
  key: stateKeys.index(StateKeyIdx.Alpha),
10367
10387
  Codec: codecPerCore(
@@ -10374,7 +10394,7 @@ declare namespace serialize {
10374
10394
  extract: (s) => s.authPools,
10375
10395
  };
10376
10396
 
10377
- /** C(2): https://graypaper.fluffylabs.dev/#/85129da/38be0138be01?v=0.6.3 */
10397
+ /** C(2): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b31013b3101?v=0.6.7 */
10378
10398
  export const authQueues: StateCodec<State["authQueues"]> = {
10379
10399
  key: stateKeys.index(StateKeyIdx.Phi),
10380
10400
  Codec: codecPerCore(
@@ -10385,7 +10405,6 @@ declare namespace serialize {
10385
10405
 
10386
10406
  /**
10387
10407
  * C(3): Recent blocks with compatibility
10388
- * https://graypaper.fluffylabs.dev/#/85129da/38cb0138cb01?v=0.6.3
10389
10408
  * https://graypaper.fluffylabs.dev/#/7e6ff6a/3b3e013b3e01?v=0.6.7
10390
10409
  */
10391
10410
  export const recentBlocks: StateCodec<State["recentBlocks"]> = {
@@ -10394,7 +10413,7 @@ declare namespace serialize {
10394
10413
  extract: (s) => s.recentBlocks,
10395
10414
  };
10396
10415
 
10397
- /** C(4): https://graypaper.fluffylabs.dev/#/85129da/38e60138e601?v=0.6.3 */
10416
+ /** C(4): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b63013b6301?v=0.6.7 */
10398
10417
  export const safrole: StateCodec<SafroleData> = {
10399
10418
  key: stateKeys.index(StateKeyIdx.Gamma),
10400
10419
  Codec: SafroleData.Codec,
@@ -10407,63 +10426,63 @@ declare namespace serialize {
10407
10426
  }),
10408
10427
  };
10409
10428
 
10410
- /** C(5): https://graypaper.fluffylabs.dev/#/85129da/383d02383d02?v=0.6.3 */
10429
+ /** C(5): https://graypaper.fluffylabs.dev/#/7e6ff6a/3bba013bba01?v=0.6.7 */
10411
10430
  export const disputesRecords: StateCodec<State["disputesRecords"]> = {
10412
10431
  key: stateKeys.index(StateKeyIdx.Psi),
10413
10432
  Codec: DisputesRecords.Codec,
10414
10433
  extract: (s) => s.disputesRecords,
10415
10434
  };
10416
10435
 
10417
- /** C(6): https://graypaper.fluffylabs.dev/#/85129da/387602387602?v=0.6.3 */
10436
+ /** C(6): https://graypaper.fluffylabs.dev/#/7e6ff6a/3bf3013bf301?v=0.6.7 */
10418
10437
  export const entropy: StateCodec<State["entropy"]> = {
10419
10438
  key: stateKeys.index(StateKeyIdx.Eta),
10420
10439
  Codec: codecFixedSizeArray(codec.bytes(HASH_SIZE).asOpaque<EntropyHash>(), ENTROPY_ENTRIES),
10421
10440
  extract: (s) => s.entropy,
10422
10441
  };
10423
10442
 
10424
- /** C(7): https://graypaper.fluffylabs.dev/#/85129da/388302388302?v=0.6.3 */
10443
+ /** C(7): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b00023b0002?v=0.6.7 */
10425
10444
  export const designatedValidators: StateCodec<State["designatedValidatorData"]> = {
10426
10445
  key: stateKeys.index(StateKeyIdx.Iota),
10427
10446
  Codec: codecPerValidator(ValidatorData.Codec),
10428
10447
  extract: (s) => s.designatedValidatorData,
10429
10448
  };
10430
10449
 
10431
- /** C(8): https://graypaper.fluffylabs.dev/#/85129da/389002389002?v=0.6.3 */
10450
+ /** C(8): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b0d023b0d02?v=0.6.7 */
10432
10451
  export const currentValidators: StateCodec<State["currentValidatorData"]> = {
10433
10452
  key: stateKeys.index(StateKeyIdx.Kappa),
10434
10453
  Codec: codecPerValidator(ValidatorData.Codec),
10435
10454
  extract: (s) => s.currentValidatorData,
10436
10455
  };
10437
10456
 
10438
- /** C(9): https://graypaper.fluffylabs.dev/#/85129da/389d02389d02?v=0.6.3 */
10457
+ /** C(9): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b1a023b1a02?v=0.6.7 */
10439
10458
  export const previousValidators: StateCodec<State["previousValidatorData"]> = {
10440
10459
  key: stateKeys.index(StateKeyIdx.Lambda),
10441
10460
  Codec: codecPerValidator(ValidatorData.Codec),
10442
10461
  extract: (s) => s.previousValidatorData,
10443
10462
  };
10444
10463
 
10445
- /** C(10): https://graypaper.fluffylabs.dev/#/85129da/38aa0238aa02?v=0.6.3 */
10464
+ /** C(10): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b27023b2702?v=0.6.7 */
10446
10465
  export const availabilityAssignment: StateCodec<State["availabilityAssignment"]> = {
10447
10466
  key: stateKeys.index(StateKeyIdx.Rho),
10448
10467
  Codec: codecPerCore(codec.optional(AvailabilityAssignment.Codec)),
10449
10468
  extract: (s) => s.availabilityAssignment,
10450
10469
  };
10451
10470
 
10452
- /** C(11): https://graypaper.fluffylabs.dev/#/85129da/38c10238c102?v=0.6.3 */
10471
+ /** C(11): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b3e023b3e02?v=0.6.7 */
10453
10472
  export const timeslot: StateCodec<State["timeslot"]> = {
10454
10473
  key: stateKeys.index(StateKeyIdx.Tau),
10455
10474
  Codec: codec.u32.asOpaque<TimeSlot>(),
10456
10475
  extract: (s) => s.timeslot,
10457
10476
  };
10458
10477
 
10459
- /** C(12): https://graypaper.fluffylabs.dev/#/85129da/38cf0238cf02?v=0.6.3 */
10478
+ /** C(12): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b4c023b4c02?v=0.6.7 */
10460
10479
  export const privilegedServices: StateCodec<State["privilegedServices"]> = {
10461
10480
  key: stateKeys.index(StateKeyIdx.Chi),
10462
10481
  Codec: PrivilegedServices.Codec,
10463
10482
  extract: (s) => s.privilegedServices,
10464
10483
  };
10465
10484
 
10466
- /** C(13): https://graypaper.fluffylabs.dev/#/85129da/38e10238e102?v=0.6.3 */
10485
+ /** C(13): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b5e023b5e02?v=0.6.7 */
10467
10486
  export const statistics: StateCodec<State["statistics"]> = {
10468
10487
  key: stateKeys.index(StateKeyIdx.Pi),
10469
10488
  Codec: StatisticsData.Codec,
@@ -10477,7 +10496,7 @@ declare namespace serialize {
10477
10496
  extract: (s) => s.accumulationQueue,
10478
10497
  };
10479
10498
 
10480
- /** C(15): https://graypaper.fluffylabs.dev/#/85129da/381903381903?v=0.6.3 */
10499
+ /** C(15): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b96023b9602?v=0.6.7 */
10481
10500
  export const recentlyAccumulated: StateCodec<State["recentlyAccumulated"]> = {
10482
10501
  key: stateKeys.index(StateKeyIdx.Xi),
10483
10502
  Codec: codecPerEpochBlock(
@@ -12245,8 +12264,8 @@ declare function encodePoints(input: Bytes<PIECE_SIZE>): FixedSizeArray<Bytes<PO
12245
12264
  }
12246
12265
 
12247
12266
  // encode and add redundancy shards
12248
- const points = new ShardsCollection(POINT_ALIGNMENT, data);
12249
- const encodedResult = encode(N_CHUNKS_REDUNDANCY, POINT_ALIGNMENT, points);
12267
+ const points = new reedSolomon.ShardsCollection(POINT_ALIGNMENT, data);
12268
+ const encodedResult = reedSolomon.encode(N_CHUNKS_REDUNDANCY, points);
12250
12269
  const encodedData = encodedResult.take_data();
12251
12270
 
12252
12271
  for (let i = 0; i < N_CHUNKS_REDUNDANCY; i++) {
@@ -12288,9 +12307,9 @@ declare function decodePiece(
12288
12307
  result.raw.set(points.raw, pointStartInResult);
12289
12308
  }
12290
12309
  }
12291
- const points = new ShardsCollection(POINT_ALIGNMENT, data, indices);
12310
+ const points = new reedSolomon.ShardsCollection(POINT_ALIGNMENT, data, indices);
12292
12311
 
12293
- const decodingResult = decode(N_CHUNKS_REQUIRED, N_CHUNKS_REDUNDANCY, POINT_ALIGNMENT, points);
12312
+ const decodingResult = reedSolomon.decode(N_CHUNKS_REQUIRED, N_CHUNKS_REDUNDANCY, points);
12294
12313
  const resultIndices = decodingResult.take_indices(); // it has to be called before take_data
12295
12314
  const resultData = decodingResult.take_data(); // it destroys the result object in rust
12296
12315
 
@@ -12527,6 +12546,10 @@ declare function chunksToShards(
12527
12546
  return tryAsPerValidator(result, spec);
12528
12547
  }
12529
12548
 
12549
+ declare const initEc = async () => {
12550
+ await init.reedSolomon();
12551
+ };
12552
+
12530
12553
  declare const index$a_HALF_POINT_SIZE: typeof HALF_POINT_SIZE;
12531
12554
  declare const index$a_N_CHUNKS_REDUNDANCY: typeof N_CHUNKS_REDUNDANCY;
12532
12555
  type index$a_N_CHUNKS_REQUIRED = N_CHUNKS_REQUIRED;
@@ -12540,6 +12563,7 @@ declare const index$a_decodeData: typeof decodeData;
12540
12563
  declare const index$a_decodeDataAndTrim: typeof decodeDataAndTrim;
12541
12564
  declare const index$a_decodePiece: typeof decodePiece;
12542
12565
  declare const index$a_encodePoints: typeof encodePoints;
12566
+ declare const index$a_initEc: typeof initEc;
12543
12567
  declare const index$a_join: typeof join;
12544
12568
  declare const index$a_lace: typeof lace;
12545
12569
  declare const index$a_padAndEncodeData: typeof padAndEncodeData;
@@ -12548,7 +12572,7 @@ declare const index$a_split: typeof split;
12548
12572
  declare const index$a_transpose: typeof transpose;
12549
12573
  declare const index$a_unzip: typeof unzip;
12550
12574
  declare namespace index$a {
12551
- export { index$a_HALF_POINT_SIZE as HALF_POINT_SIZE, index$a_N_CHUNKS_REDUNDANCY as N_CHUNKS_REDUNDANCY, index$a_POINT_ALIGNMENT as POINT_ALIGNMENT, index$a_chunkingFunction as chunkingFunction, index$a_chunksToShards as chunksToShards, index$a_decodeData as decodeData, index$a_decodeDataAndTrim as decodeDataAndTrim, index$a_decodePiece as decodePiece, index$a_encodePoints as encodePoints, index$a_join as join, index$a_lace as lace, index$a_padAndEncodeData as padAndEncodeData, index$a_shardsToChunks as shardsToChunks, index$a_split as split, index$a_transpose as transpose, index$a_unzip as unzip };
12575
+ export { index$a_HALF_POINT_SIZE as HALF_POINT_SIZE, index$a_N_CHUNKS_REDUNDANCY as N_CHUNKS_REDUNDANCY, index$a_POINT_ALIGNMENT as POINT_ALIGNMENT, index$a_chunkingFunction as chunkingFunction, index$a_chunksToShards as chunksToShards, index$a_decodeData as decodeData, index$a_decodeDataAndTrim as decodeDataAndTrim, index$a_decodePiece as decodePiece, index$a_encodePoints as encodePoints, index$a_initEc as initEc, index$a_join as join, index$a_lace as lace, index$a_padAndEncodeData as padAndEncodeData, index$a_shardsToChunks as shardsToChunks, index$a_split as split, index$a_transpose as transpose, index$a_unzip as unzip };
12552
12576
  export type { index$a_N_CHUNKS_REQUIRED as N_CHUNKS_REQUIRED, index$a_N_CHUNKS_TOTAL as N_CHUNKS_TOTAL, index$a_PIECE_SIZE as PIECE_SIZE, index$a_POINT_LENGTH as POINT_LENGTH };
12553
12577
  }
12554
12578
 
@@ -12580,6 +12604,173 @@ declare const HostCallResult = {
12580
12604
  OK: tryAsU64(0n),
12581
12605
  } as const;
12582
12606
 
12607
+ declare enum Level {
12608
+ INSANE = 1,
12609
+ TRACE = 2,
12610
+ LOG = 3,
12611
+ INFO = 4,
12612
+ WARN = 5,
12613
+ ERROR = 6,
12614
+ }
12615
+
12616
+ type Options = {
12617
+ defaultLevel: Level;
12618
+ workingDir: string;
12619
+ modules: Map<string, Level>;
12620
+ };
12621
+
12622
+ /**
12623
+ * A function to parse logger definition (including modules) given as a string.
12624
+ *
12625
+ * Examples
12626
+ * - `info` - setup default logging level to `info`.
12627
+ * - `trace` - default logging level set to `trace`.
12628
+ * - `debug;consensus=trace` - default level is set to `debug/log`, but consensus is in trace mode.
12629
+ */
12630
+ declare function parseLoggerOptions(input: string, defaultLevel: Level, workingDir?: string): Options {
12631
+ const modules = new Map<string, Level>();
12632
+ const parts = input.toLowerCase().split(",");
12633
+ let defLevel = defaultLevel;
12634
+
12635
+ for (const p of parts) {
12636
+ const clean = p.trim();
12637
+ // skip empty objects (forgotten `,` removed)
12638
+ if (clean.length === 0) {
12639
+ continue;
12640
+ }
12641
+ // we just have the default level
12642
+ if (clean.includes("=")) {
12643
+ const [mod, lvl] = clean.split("=");
12644
+ modules.set(mod.trim(), parseLevel(lvl.trim()));
12645
+ } else {
12646
+ defLevel = parseLevel(clean);
12647
+ }
12648
+ }
12649
+
12650
+ // TODO [ToDr] Fix dirname for workers.
12651
+ const myDir = (import.meta.dirname ?? "").split("/");
12652
+ myDir.pop();
12653
+ myDir.pop();
12654
+ return {
12655
+ defaultLevel: defLevel,
12656
+ modules,
12657
+ workingDir: workingDir ?? myDir.join("/"),
12658
+ };
12659
+ }
12660
+
12661
+ declare const GLOBAL_CONFIG = {
12662
+ options: DEFAULT_OPTIONS,
12663
+ transport: ConsoleTransport.create(DEFAULT_OPTIONS.defaultLevel, DEFAULT_OPTIONS),
12664
+ };
12665
+
12666
+ /**
12667
+ * A logger instance.
12668
+ */
12669
+ declare class Logger {
12670
+ /**
12671
+ * Create a new logger instance given filename and an optional module name.
12672
+ *
12673
+ * If the module name is not given, `fileName` becomes the module name.
12674
+ * The module name can be composed from multiple parts separated with `/`.
12675
+ *
12676
+ * The logger will use a global configuration which can be changed using
12677
+ * [`configureLogger`] function.
12678
+ */
12679
+ static new(fileName?: string, moduleName?: string) {
12680
+ const fName = fileName ?? "unknown";
12681
+ return new Logger(moduleName ?? fName, fName, GLOBAL_CONFIG);
12682
+ }
12683
+
12684
+ /**
12685
+ * Return currently configured level for given module. */
12686
+ static getLevel(moduleName: string): Level {
12687
+ return findLevel(GLOBAL_CONFIG.options, moduleName);
12688
+ }
12689
+
12690
+ /**
12691
+ * Global configuration of all loggers.
12692
+ *
12693
+ * One can specify a default logging level (only logs with level >= default will be printed).
12694
+ * It's also possible to configure per-module logging level that takes precedence
12695
+ * over the default one.
12696
+ *
12697
+ * Changing the options affects all previously created loggers.
12698
+ */
12699
+ static configureAllFromOptions(options: Options) {
12700
+ // find minimal level to optimise logging in case
12701
+ // we don't care about low-level logs.
12702
+ const minimalLevel = Array.from(options.modules.values()).reduce((level, modLevel) => {
12703
+ return level < modLevel ? level : modLevel;
12704
+ }, options.defaultLevel);
12705
+
12706
+ const transport = ConsoleTransport.create(minimalLevel, options);
12707
+
12708
+ // set the global config
12709
+ GLOBAL_CONFIG.options = options;
12710
+ GLOBAL_CONFIG.transport = transport;
12711
+ }
12712
+
12713
+ /**
12714
+ * Global configuration of all loggers.
12715
+ *
12716
+ * Parse configuration options from an input string typically obtained
12717
+ * from environment variable `JAM_LOG`.
12718
+ */
12719
+ static configureAll(input: string, defaultLevel: Level, workingDir?: string) {
12720
+ const options = parseLoggerOptions(input, defaultLevel, workingDir);
12721
+ Logger.configureAllFromOptions(options);
12722
+ }
12723
+
12724
+ constructor(
12725
+ private readonly moduleName: string,
12726
+ private readonly fileName: string,
12727
+ private readonly config: typeof GLOBAL_CONFIG,
12728
+ ) {}
12729
+
12730
+ /** Log a message with `INSANE` level. */
12731
+ insane(val: string) {
12732
+ this.config.transport.insane(this.moduleName, val);
12733
+ }
12734
+
12735
+ /** Log a message with `TRACE` level. */
12736
+ trace(val: string) {
12737
+ this.config.transport.trace(this.moduleName, val);
12738
+ }
12739
+
12740
+ /** Log a message with `DEBUG`/`LOG` level. */
12741
+ log(val: string) {
12742
+ this.config.transport.log(this.moduleName, val);
12743
+ }
12744
+
12745
+ /** Log a message with `INFO` level. */
12746
+ info(val: string) {
12747
+ this.config.transport.info(this.moduleName, val);
12748
+ }
12749
+
12750
+ /** Log a message with `WARN` level. */
12751
+ warn(val: string) {
12752
+ this.config.transport.warn(this.moduleName, val);
12753
+ }
12754
+
12755
+ /** Log a message with `ERROR` level. */
12756
+ error(val: string) {
12757
+ this.config.transport.error(this.moduleName, val);
12758
+ }
12759
+ }
12760
+
12761
+ type index$9_Level = Level;
12762
+ declare const index$9_Level: typeof Level;
12763
+ type index$9_Logger = Logger;
12764
+ declare const index$9_Logger: typeof Logger;
12765
+ declare const index$9_parseLoggerOptions: typeof parseLoggerOptions;
12766
+ declare namespace index$9 {
12767
+ export {
12768
+ index$9_Level as Level,
12769
+ index$9_Logger as Logger,
12770
+ index$9_parseLoggerOptions as parseLoggerOptions,
12771
+ };
12772
+ }
12773
+
12583
12774
  /**
12584
12775
  * Mask class is an implementation of skip function defined in GP.
12585
12776
  *
@@ -13839,13 +14030,14 @@ declare abstract class MemoryPage {
13839
14030
  * And then a new version of TypeScript is released.
13840
14031
  */
13841
14032
  declare global {
13842
- interface ArrayBufferConstructor {
13843
- new (length: number, options?: { maxByteLength: number }): ArrayBuffer;
13844
- }
13845
-
13846
- interface ArrayBuffer {
13847
- resize(length: number): void;
13848
- }
14033
+ interface ArrayBufferConstructor {
14034
+ new (length: number, options?: {
14035
+ maxByteLength: number;
14036
+ }): ArrayBuffer;
14037
+ }
14038
+ interface ArrayBuffer {
14039
+ resize(length: number): void;
14040
+ }
13849
14041
  }
13850
14042
 
13851
14043
  type InitialMemoryState = {
@@ -13858,6 +14050,7 @@ declare enum AccessType {
13858
14050
  READ = 0,
13859
14051
  WRITE = 1,
13860
14052
  }
14053
+
13861
14054
  declare class Memory {
13862
14055
  static fromInitialMemory(initialMemoryState: InitialMemoryState) {
13863
14056
  return new Memory(
@@ -13894,6 +14087,7 @@ declare class Memory {
13894
14087
  return Result.ok(OK);
13895
14088
  }
13896
14089
 
14090
+ logger.insane(`MEM[${address}] <- ${BytesBlob.blobFrom(bytes)}`);
13897
14091
  const pagesResult = this.getPages(address, bytes.length, AccessType.WRITE);
13898
14092
 
13899
14093
  if (pagesResult.isError) {
@@ -13982,6 +14176,7 @@ declare class Memory {
13982
14176
  bytesLeft -= bytesToRead;
13983
14177
  }
13984
14178
 
14179
+ logger.insane(`MEM[${startAddress}] => ${BytesBlob.blobFrom(result)}`);
13985
14180
  return Result.ok(OK);
13986
14181
  }
13987
14182
 
@@ -14981,6 +15176,10 @@ declare class JumpTable {
14981
15176
  return new JumpTable(0, new Uint8Array());
14982
15177
  }
14983
15178
 
15179
+ getSize() {
15180
+ return this.indices.length;
15181
+ }
15182
+
14984
15183
  copyFrom(jt: JumpTable) {
14985
15184
  this.indices = jt.indices;
14986
15185
  }
@@ -15882,167 +16081,6 @@ declare class OneRegOneExtImmDispatcher {
15882
16081
  }
15883
16082
  }
15884
16083
 
15885
- declare enum Level {
15886
- TRACE = 1,
15887
- LOG = 2,
15888
- INFO = 3,
15889
- WARN = 4,
15890
- ERROR = 5,
15891
- }
15892
-
15893
- type Options = {
15894
- defaultLevel: Level;
15895
- workingDir: string;
15896
- modules: Map<string, Level>;
15897
- };
15898
-
15899
- /**
15900
- * A function to parse logger definition (including modules) given as a string.
15901
- *
15902
- * Examples
15903
- * - `info` - setup default logging level to `info`.
15904
- * - `trace` - default logging level set to `trace`.
15905
- * - `debug;consensus=trace` - default level is set to `debug/log`, but consensus is in trace mode.
15906
- */
15907
- declare function parseLoggerOptions(input: string, defaultLevel: Level, workingDir?: string): Options {
15908
- const modules = new Map<string, Level>();
15909
- const parts = input.toLowerCase().split(",");
15910
- let defLevel = defaultLevel;
15911
-
15912
- for (const p of parts) {
15913
- const clean = p.trim();
15914
- // skip empty objects (forgotten `,` removed)
15915
- if (clean.length === 0) {
15916
- continue;
15917
- }
15918
- // we just have the default level
15919
- if (clean.includes("=")) {
15920
- const [mod, lvl] = clean.split("=");
15921
- modules.set(mod.trim(), parseLevel(lvl.trim()));
15922
- } else {
15923
- defLevel = parseLevel(clean);
15924
- }
15925
- }
15926
-
15927
- // TODO [ToDr] Fix dirname for workers.
15928
- const myDir = (import.meta.dirname ?? "").split("/");
15929
- myDir.pop();
15930
- myDir.pop();
15931
- return {
15932
- defaultLevel: defLevel,
15933
- modules,
15934
- workingDir: workingDir ?? myDir.join("/"),
15935
- };
15936
- }
15937
-
15938
- declare const GLOBAL_CONFIG = {
15939
- options: DEFAULT_OPTIONS,
15940
- transport: ConsoleTransport.create(DEFAULT_OPTIONS.defaultLevel, DEFAULT_OPTIONS),
15941
- };
15942
-
15943
- /**
15944
- * A logger instance.
15945
- */
15946
- declare class Logger {
15947
- /**
15948
- * Create a new logger instance given filename and an optional module name.
15949
- *
15950
- * If the module name is not given, `fileName` becomes the module name.
15951
- * The module name can be composed from multiple parts separated with `/`.
15952
- *
15953
- * The logger will use a global configuration which can be changed using
15954
- * [`configureLogger`] function.
15955
- */
15956
- static new(fileName?: string, moduleName?: string) {
15957
- const fName = fileName ?? "unknown";
15958
- return new Logger(moduleName ?? fName, fName, GLOBAL_CONFIG);
15959
- }
15960
-
15961
- /**
15962
- * Return currently configured level for given module. */
15963
- static getLevel(moduleName: string): Level {
15964
- return findLevel(GLOBAL_CONFIG.options, moduleName);
15965
- }
15966
-
15967
- /**
15968
- * Global configuration of all loggers.
15969
- *
15970
- * One can specify a default logging level (only logs with level >= default will be printed).
15971
- * It's also possible to configure per-module logging level that takes precedence
15972
- * over the default one.
15973
- *
15974
- * Changing the options affects all previously created loggers.
15975
- */
15976
- static configureAllFromOptions(options: Options) {
15977
- // find minimal level to optimise logging in case
15978
- // we don't care about low-level logs.
15979
- const minimalLevel = Array.from(options.modules.values()).reduce((level, modLevel) => {
15980
- return level < modLevel ? level : modLevel;
15981
- }, options.defaultLevel);
15982
-
15983
- const transport = ConsoleTransport.create(minimalLevel, options);
15984
-
15985
- // set the global config
15986
- GLOBAL_CONFIG.options = options;
15987
- GLOBAL_CONFIG.transport = transport;
15988
- }
15989
-
15990
- /**
15991
- * Global configuration of all loggers.
15992
- *
15993
- * Parse configuration options from an input string typically obtained
15994
- * from environment variable `JAM_LOG`.
15995
- */
15996
- static configureAll(input: string, defaultLevel: Level, workingDir?: string) {
15997
- const options = parseLoggerOptions(input, defaultLevel, workingDir);
15998
- Logger.configureAllFromOptions(options);
15999
- }
16000
-
16001
- constructor(
16002
- private readonly moduleName: string,
16003
- private readonly fileName: string,
16004
- private readonly config: typeof GLOBAL_CONFIG,
16005
- ) {}
16006
-
16007
- /** Log a message with `TRACE` level. */
16008
- trace(val: string) {
16009
- this.config.transport.trace(this.moduleName, this.fileName, val);
16010
- }
16011
-
16012
- /** Log a message with `DEBUG`/`LOG` level. */
16013
- log(val: string) {
16014
- this.config.transport.log(this.moduleName, this.fileName, val);
16015
- }
16016
-
16017
- /** Log a message with `INFO` level. */
16018
- info(val: string) {
16019
- this.config.transport.info(this.moduleName, this.fileName, val);
16020
- }
16021
-
16022
- /** Log a message with `WARN` level. */
16023
- warn(val: string) {
16024
- this.config.transport.warn(this.moduleName, this.fileName, val);
16025
- }
16026
-
16027
- /** Log a message with `ERROR` level. */
16028
- error(val: string) {
16029
- this.config.transport.error(this.moduleName, this.fileName, val);
16030
- }
16031
- }
16032
-
16033
- type index$9_Level = Level;
16034
- declare const index$9_Level: typeof Level;
16035
- type index$9_Logger = Logger;
16036
- declare const index$9_Logger: typeof Logger;
16037
- declare const index$9_parseLoggerOptions: typeof parseLoggerOptions;
16038
- declare namespace index$9 {
16039
- export {
16040
- index$9_Level as Level,
16041
- index$9_Logger as Logger,
16042
- index$9_parseLoggerOptions as parseLoggerOptions,
16043
- };
16044
- }
16045
-
16046
16084
  declare enum ProgramDecoderError {
16047
16085
  InvalidProgramError = 0,
16048
16086
  }
@@ -16125,6 +16163,8 @@ type InterpreterOptions = {
16125
16163
  useSbrkGas?: boolean;
16126
16164
  };
16127
16165
 
16166
+ declare const logger = Logger.new(import.meta.filename, "pvm");
16167
+
16128
16168
  declare class Interpreter {
16129
16169
  private readonly useSbrkGas: boolean;
16130
16170
  private registers = new Registers();
@@ -16260,6 +16300,8 @@ declare class Interpreter {
16260
16300
  const argsResult = this.argsDecodingResults[argsType];
16261
16301
  this.argsDecoder.fillArgs(this.pc, argsResult);
16262
16302
 
16303
+ logger.insane(`[PC: ${this.pc}] ${Instruction[currentInstruction]}`);
16304
+
16263
16305
  if (!isValidInstruction) {
16264
16306
  this.instructionResult.status = Result.PANIC;
16265
16307
  } else {
@@ -16335,6 +16377,7 @@ declare class Interpreter {
16335
16377
  this.status = Status.HOST;
16336
16378
  break;
16337
16379
  }
16380
+ logger.insane(`[PC: ${this.pc}] Status: ${Result[this.instructionResult.status]}`);
16338
16381
  return this.status;
16339
16382
  }
16340
16383
 
@@ -16406,13 +16449,14 @@ declare const index$8_Registers: typeof Registers;
16406
16449
  type index$8_SbrkIndex = SbrkIndex;
16407
16450
  type index$8_SmallGas = SmallGas;
16408
16451
  declare const index$8_gasCounter: typeof gasCounter;
16452
+ declare const index$8_logger: typeof logger;
16409
16453
  declare const index$8_tryAsBigGas: typeof tryAsBigGas;
16410
16454
  declare const index$8_tryAsGas: typeof tryAsGas;
16411
16455
  declare const index$8_tryAsMemoryIndex: typeof tryAsMemoryIndex;
16412
16456
  declare const index$8_tryAsSbrkIndex: typeof tryAsSbrkIndex;
16413
16457
  declare const index$8_tryAsSmallGas: typeof tryAsSmallGas;
16414
16458
  declare namespace index$8 {
16415
- export { index$8_Interpreter as Interpreter, index$8_Memory as Memory, index$8_MemoryBuilder as MemoryBuilder, index$8_Registers as Registers, index$8_gasCounter as gasCounter, index$8_tryAsBigGas as tryAsBigGas, index$8_tryAsGas as tryAsGas, index$8_tryAsMemoryIndex as tryAsMemoryIndex, index$8_tryAsSbrkIndex as tryAsSbrkIndex, index$8_tryAsSmallGas as tryAsSmallGas };
16459
+ export { index$8_Interpreter as Interpreter, index$8_Memory as Memory, index$8_MemoryBuilder as MemoryBuilder, index$8_Registers as Registers, index$8_gasCounter as gasCounter, index$8_logger as logger, index$8_tryAsBigGas as tryAsBigGas, index$8_tryAsGas as tryAsGas, index$8_tryAsMemoryIndex as tryAsMemoryIndex, index$8_tryAsSbrkIndex as tryAsSbrkIndex, index$8_tryAsSmallGas as tryAsSmallGas };
16416
16460
  export type { index$8_BigGas as BigGas, index$8_Gas as Gas, index$8_GasCounter as GasCounter, index$8_InterpreterOptions as InterpreterOptions, index$8_MemoryIndex as MemoryIndex, index$8_SbrkIndex as SbrkIndex, index$8_SmallGas as SmallGas };
16417
16461
  }
16418
16462
 
@@ -16550,7 +16594,7 @@ declare class HostCallsManager {
16550
16594
  return `r${idx}=${value} (0x${value.toString(16)})`;
16551
16595
  })
16552
16596
  .join(", ");
16553
- logger.trace(`[${currentServiceId}] ${context} ${name}${requested}. Gas: ${gas}. Regs: ${registerValues}.`);
16597
+ logger.insane(`[${currentServiceId}] ${context} ${name}${requested}. Gas: ${gas}. Regs: ${registerValues}.`);
16554
16598
  }
16555
16599
  }
16556
16600
 
@@ -16671,14 +16715,15 @@ declare class HostCalls {
16671
16715
  const gasCost = typeof hostCall.gasCost === "number" ? hostCall.gasCost : hostCall.gasCost(regs);
16672
16716
  const underflow = gas.sub(gasCost);
16673
16717
 
16718
+ const pcLog = `[PC: ${pvmInstance.getPC()}]`;
16674
16719
  if (underflow) {
16675
- this.hostCalls.traceHostCall("OOG", index, hostCall, regs, gas.get());
16720
+ this.hostCalls.traceHostCall(`${pcLog} OOG`, index, hostCall, regs, gas.get());
16676
16721
  return ReturnValue.fromStatus(pvmInstance.getGasConsumed(), Status.OOG);
16677
16722
  }
16678
- this.hostCalls.traceHostCall("Invoking", index, hostCall, regs, gasBefore);
16723
+ this.hostCalls.traceHostCall(`${pcLog} Invoking`, index, hostCall, regs, gasBefore);
16679
16724
  const result = await hostCall.execute(gas, regs, memory);
16680
16725
  this.hostCalls.traceHostCall(
16681
- result === undefined ? "Result" : `Status(${PvmExecution[result]})`,
16726
+ result === undefined ? `${pcLog} Result` : `${pcLog} Status(${PvmExecution[result]})`,
16682
16727
  index,
16683
16728
  hostCall,
16684
16729
  regs,
@@ -16690,8 +16735,18 @@ declare class HostCalls {
16690
16735
  return this.getReturnValue(status, pvmInstance);
16691
16736
  }
16692
16737
 
16693
- pvmInstance.runProgram();
16694
- status = pvmInstance.getStatus();
16738
+ if (result === PvmExecution.Panic) {
16739
+ status = Status.PANIC;
16740
+ return this.getReturnValue(status, pvmInstance);
16741
+ }
16742
+
16743
+ if (result === undefined) {
16744
+ pvmInstance.runProgram();
16745
+ status = pvmInstance.getStatus();
16746
+ continue;
16747
+ }
16748
+
16749
+ assertNever(result);
16695
16750
  }
16696
16751
  }
16697
16752
 
@@ -18030,6 +18085,7 @@ declare const index$3_getServiceId: typeof getServiceId;
18030
18085
  declare const index$3_getServiceIdOrCurrent: typeof getServiceIdOrCurrent;
18031
18086
  declare const index$3_inspect: typeof inspect;
18032
18087
  declare const index$3_instructionArgumentTypeMap: typeof instructionArgumentTypeMap;
18088
+ declare const index$3_isBrowser: typeof isBrowser;
18033
18089
  declare const index$3_isTaggedError: typeof isTaggedError;
18034
18090
  declare const index$3_maybeTaggedErrorToString: typeof maybeTaggedErrorToString;
18035
18091
  declare const index$3_measure: typeof measure;
@@ -18042,7 +18098,7 @@ declare const index$3_tryAsMachineId: typeof tryAsMachineId;
18042
18098
  declare const index$3_tryAsProgramCounter: typeof tryAsProgramCounter;
18043
18099
  declare const index$3_writeServiceIdAsLeBytes: typeof writeServiceIdAsLeBytes;
18044
18100
  declare namespace index$3 {
18045
- export { index$3_AccumulationStateUpdate as AccumulationStateUpdate, index$3_ArgsDecoder as ArgsDecoder, index$3_ArgumentType as ArgumentType, index$3_BasicBlocks as BasicBlocks, index$3_CURRENT_SERVICE_ID as CURRENT_SERVICE_ID, index$3_EjectError as EjectError, index$3_ExtendedWitdthImmediateDecoder as ExtendedWitdthImmediateDecoder, index$3_ForgetPreimageError as ForgetPreimageError, index$3_HostCallMemory as HostCallMemory, index$3_HostCallRegisters as HostCallRegisters, index$3_HostCallResult as HostCallResult, index$3_ImmediateDecoder as ImmediateDecoder, index$3_MAX_U32 as MAX_U32, index$3_MAX_U32_BIG_INT as MAX_U32_BIG_INT, index$3_MachineInstance as MachineInstance, index$3_Mask as Mask, index$3_MemoryOperation as MemoryOperation, index$3_MemorySegment as MemorySegment, NO_OF_REGISTERS$1 as NO_OF_REGISTERS, index$3_NewServiceError as NewServiceError, index$3_NibblesDecoder as NibblesDecoder, index$3_PagesError as PagesError, index$3_PartiallyUpdatedState as PartiallyUpdatedState, index$3_PeekPokeError as PeekPokeError, index$3_PendingTransfer as PendingTransfer, index$3_PreimageStatusKind as PreimageStatusKind, index$3_Program as Program, index$3_ProgramDecoder as ProgramDecoder, index$3_ProvidePreimageError as ProvidePreimageError, DebuggerAdapter as Pvm, index$3_Registers as Registers, index$3_RequestPreimageError as RequestPreimageError, Result$2 as Result, index$3_RichTaggedError as RichTaggedError, index$3_SERVICE_ID_BYTES as SERVICE_ID_BYTES, index$3_SpiMemory as SpiMemory, index$3_SpiProgram as SpiProgram, index$3_TransferError as TransferError, index$3_UpdatePrivilegesError as UpdatePrivilegesError, index$3_WithDebug as WithDebug, index$3_ZeroVoidError as ZeroVoidError, index$3___OPAQUE_TYPE__ as __OPAQUE_TYPE__, index$3_asOpaqueType as asOpaqueType, index$3_assertEmpty as assertEmpty, index$3_assertNever as assertNever, index$j as block, index$q as bytes, index$3_cast as cast, index$3_check as check, index$3_clampU64ToU32 as clampU64ToU32, index$3_createResults as createResults, index$3_decodeStandardProgram as decodeStandardProgram, index$3_ensure as ensure, index$3_extractCodeAndMetadata as extractCodeAndMetadata, index$3_getServiceId as getServiceId, index$3_getServiceIdOrCurrent as getServiceIdOrCurrent, index$n as hash, index$3_inspect as inspect, index$3_instructionArgumentTypeMap as instructionArgumentTypeMap, index$8 as interpreter, index$3_isTaggedError as isTaggedError, index$3_maybeTaggedErrorToString as maybeTaggedErrorToString, index$3_measure as measure, index$p as numbers, index$3_preimageLenAsU32 as preimageLenAsU32, index$3_resultToString as resultToString, index$3_seeThrough as seeThrough, index$3_slotsToPreimageStatus as slotsToPreimageStatus, index$3_toMemoryOperation as toMemoryOperation, index$3_tryAsMachineId as tryAsMachineId, index$3_tryAsProgramCounter as tryAsProgramCounter, index$3_writeServiceIdAsLeBytes as writeServiceIdAsLeBytes };
18101
+ export { index$3_AccumulationStateUpdate as AccumulationStateUpdate, index$3_ArgsDecoder as ArgsDecoder, index$3_ArgumentType as ArgumentType, index$3_BasicBlocks as BasicBlocks, index$3_CURRENT_SERVICE_ID as CURRENT_SERVICE_ID, index$3_EjectError as EjectError, index$3_ExtendedWitdthImmediateDecoder as ExtendedWitdthImmediateDecoder, index$3_ForgetPreimageError as ForgetPreimageError, index$3_HostCallMemory as HostCallMemory, index$3_HostCallRegisters as HostCallRegisters, index$3_HostCallResult as HostCallResult, index$3_ImmediateDecoder as ImmediateDecoder, index$3_MAX_U32 as MAX_U32, index$3_MAX_U32_BIG_INT as MAX_U32_BIG_INT, index$3_MachineInstance as MachineInstance, index$3_Mask as Mask, index$3_MemoryOperation as MemoryOperation, index$3_MemorySegment as MemorySegment, NO_OF_REGISTERS$1 as NO_OF_REGISTERS, index$3_NewServiceError as NewServiceError, index$3_NibblesDecoder as NibblesDecoder, index$3_PagesError as PagesError, index$3_PartiallyUpdatedState as PartiallyUpdatedState, index$3_PeekPokeError as PeekPokeError, index$3_PendingTransfer as PendingTransfer, index$3_PreimageStatusKind as PreimageStatusKind, index$3_Program as Program, index$3_ProgramDecoder as ProgramDecoder, index$3_ProvidePreimageError as ProvidePreimageError, DebuggerAdapter as Pvm, index$3_Registers as Registers, index$3_RequestPreimageError as RequestPreimageError, Result$2 as Result, index$3_RichTaggedError as RichTaggedError, index$3_SERVICE_ID_BYTES as SERVICE_ID_BYTES, index$3_SpiMemory as SpiMemory, index$3_SpiProgram as SpiProgram, index$3_TransferError as TransferError, index$3_UpdatePrivilegesError as UpdatePrivilegesError, index$3_WithDebug as WithDebug, index$3_ZeroVoidError as ZeroVoidError, index$3___OPAQUE_TYPE__ as __OPAQUE_TYPE__, index$3_asOpaqueType as asOpaqueType, index$3_assertEmpty as assertEmpty, index$3_assertNever as assertNever, index$j as block, index$q as bytes, index$3_cast as cast, index$3_check as check, index$3_clampU64ToU32 as clampU64ToU32, index$3_createResults as createResults, index$3_decodeStandardProgram as decodeStandardProgram, index$3_ensure as ensure, index$3_extractCodeAndMetadata as extractCodeAndMetadata, index$3_getServiceId as getServiceId, index$3_getServiceIdOrCurrent as getServiceIdOrCurrent, index$n as hash, index$3_inspect as inspect, index$3_instructionArgumentTypeMap as instructionArgumentTypeMap, index$8 as interpreter, index$3_isBrowser as isBrowser, index$3_isTaggedError as isTaggedError, index$3_maybeTaggedErrorToString as maybeTaggedErrorToString, index$3_measure as measure, index$p as numbers, index$3_preimageLenAsU32 as preimageLenAsU32, index$3_resultToString as resultToString, index$3_seeThrough as seeThrough, index$3_slotsToPreimageStatus as slotsToPreimageStatus, index$3_toMemoryOperation as toMemoryOperation, index$3_tryAsMachineId as tryAsMachineId, index$3_tryAsProgramCounter as tryAsProgramCounter, index$3_writeServiceIdAsLeBytes as writeServiceIdAsLeBytes };
18046
18102
  export type { index$3_Args as Args, index$3_EnumMapping as EnumMapping, index$3_ErrorResult as ErrorResult, index$3_IHostCallMemory as IHostCallMemory, index$3_IHostCallRegisters as IHostCallRegisters, index$3_InsufficientFundsError as InsufficientFundsError, index$3_MachineId as MachineId, index$3_MachineResult as MachineResult, index$3_MachineStatus as MachineStatus, index$3_NoMachineError as NoMachineError, index$3_OK as OK, index$3_OkResult as OkResult, index$3_Opaque as Opaque, index$3_PartialState as PartialState, index$3_PreimageStatus as PreimageStatus, index$3_ProgramCounter as ProgramCounter, index$3_RefineExternalities as RefineExternalities, index$3_SegmentExportError as SegmentExportError, index$3_ServiceStateUpdate as ServiceStateUpdate, index$3_StateSlice as StateSlice, index$3_StringLiteral as StringLiteral, index$3_TRANSFER_MEMO_BYTES as TRANSFER_MEMO_BYTES, index$3_TaggedError as TaggedError, index$3_TokenOf as TokenOf, index$3_Uninstantiable as Uninstantiable, index$3_UnprivilegedError as UnprivilegedError, index$3_WithOpaque as WithOpaque };
18047
18103
  }
18048
18104