@typeberry/jam 0.2.0-c96e8ef → 0.2.0-ca77d76

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.
@@ -24033,44 +24033,40 @@ var GpVersion;
24033
24033
  GpVersion["V0_6_7"] = "0.6.7";
24034
24034
  GpVersion["V0_7_0"] = "0.7.0";
24035
24035
  GpVersion["V0_7_1"] = "0.7.1";
24036
- GpVersion["V0_7_2"] = "0.7.2-preview";
24036
+ GpVersion["V0_7_2"] = "0.7.2";
24037
24037
  })(GpVersion || (GpVersion = {}));
24038
24038
  var TestSuite;
24039
24039
  (function (TestSuite) {
24040
24040
  TestSuite["W3F_DAVXY"] = "w3f-davxy";
24041
24041
  TestSuite["JAMDUNA"] = "jamduna";
24042
24042
  })(TestSuite || (TestSuite = {}));
24043
+ const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1, GpVersion.V0_7_2];
24043
24044
  const DEFAULT_SUITE = TestSuite.W3F_DAVXY;
24044
- const DEFAULT_VERSION = GpVersion.V0_7_1;
24045
+ const DEFAULT_VERSION = GpVersion.V0_7_2;
24045
24046
  const env = typeof process === "undefined" ? {} : process.env;
24046
24047
  let CURRENT_VERSION = parseCurrentVersion(env.GP_VERSION) ?? DEFAULT_VERSION;
24047
24048
  let CURRENT_SUITE = parseCurrentSuite(env.TEST_SUITE) ?? DEFAULT_SUITE;
24048
- const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1, GpVersion.V0_7_2];
24049
24049
  function parseCurrentVersion(env) {
24050
24050
  if (env === undefined) {
24051
24051
  return undefined;
24052
24052
  }
24053
- switch (env) {
24054
- case GpVersion.V0_6_7:
24055
- case GpVersion.V0_7_0:
24056
- case GpVersion.V0_7_1:
24057
- case GpVersion.V0_7_2:
24058
- return env;
24059
- default:
24060
- throw new Error(`Configured environment variable GP_VERSION is unknown: '${env}'. Use one of: ${ALL_VERSIONS_IN_ORDER}`);
24053
+ for (const v of Object.values(GpVersion)) {
24054
+ if (env === v) {
24055
+ return v;
24056
+ }
24061
24057
  }
24058
+ throw new Error(`Configured environment variable GP_VERSION is unknown: '${env}'. Use one of: ${ALL_VERSIONS_IN_ORDER}`);
24062
24059
  }
24063
24060
  function parseCurrentSuite(env) {
24064
24061
  if (env === undefined) {
24065
24062
  return undefined;
24066
24063
  }
24067
- switch (env) {
24068
- case TestSuite.W3F_DAVXY:
24069
- case TestSuite.JAMDUNA:
24070
- return env;
24071
- default:
24072
- throw new Error(`Configured environment variable TEST_SUITE is unknown: '${env}'. Use one of: ${Object.values(TestSuite)}`);
24064
+ for (const s of Object.values(TestSuite)) {
24065
+ if (env === s) {
24066
+ return s;
24067
+ }
24073
24068
  }
24069
+ throw new Error(`Configured environment variable TEST_SUITE is unknown: '${env}'. Use one of: ${Object.values(TestSuite)}`);
24074
24070
  }
24075
24071
  class Compatibility {
24076
24072
  static override(version) {
@@ -24231,6 +24227,13 @@ class WithDebug {
24231
24227
  return debug_inspect(this);
24232
24228
  }
24233
24229
  }
24230
+ function lazyInspect(obj) {
24231
+ return {
24232
+ toString() {
24233
+ return debug_inspect(obj);
24234
+ },
24235
+ };
24236
+ }
24234
24237
 
24235
24238
  ;// CONCATENATED MODULE: ./packages/core/utils/dev.ts
24236
24239
  const dev_env = typeof process === "undefined" ? {} : process.env;
@@ -24779,12 +24782,13 @@ class bytes_BytesBlob {
24779
24782
  }
24780
24783
  /** Display a hex-encoded version of this byte blob, but truncated if it's large. */
24781
24784
  toStringTruncated() {
24785
+ const bytes = `${this.raw.length} ${this.raw.length === 1 ? "byte" : "bytes"}`;
24782
24786
  if (this.raw.length > 32) {
24783
24787
  const start = bytesToHexString(this.raw.subarray(0, 16));
24784
24788
  const end = bytesToHexString(this.raw.subarray(this.raw.length - 16));
24785
- return `${start}...${end.substring(2)} (${this.raw.length} bytes)`;
24789
+ return `${start}...${end.substring(2)} (${bytes})`;
24786
24790
  }
24787
- return this.toString();
24791
+ return `${this.toString()} (${bytes})`;
24788
24792
  }
24789
24793
  toJSON() {
24790
24794
  return this.toString();
@@ -28621,6 +28625,8 @@ const EC_SEGMENT_SIZE = 4104;
28621
28625
  * Additional data that has to be passed to the codec to correctly parse incoming bytes.
28622
28626
  */
28623
28627
  class ChainSpec extends WithDebug {
28628
+ /** Human-readable name of the chain spec. */
28629
+ name;
28624
28630
  /** Number of validators. */
28625
28631
  validatorsCount;
28626
28632
  /** 1/3 of number of validators */
@@ -28663,6 +28669,7 @@ class ChainSpec extends WithDebug {
28663
28669
  maxLookupAnchorAge;
28664
28670
  constructor(data) {
28665
28671
  super();
28672
+ this.name = data.name;
28666
28673
  this.validatorsCount = data.validatorsCount;
28667
28674
  this.thirdOfValidators = numbers_tryAsU16(Math.floor(data.validatorsCount / 3));
28668
28675
  this.validatorsSuperMajority = numbers_tryAsU16(Math.floor(data.validatorsCount / 3) * 2 + 1);
@@ -28683,6 +28690,7 @@ class ChainSpec extends WithDebug {
28683
28690
  }
28684
28691
  /** Set of values for "tiny" chain as defined in JAM test vectors. */
28685
28692
  const tinyChainSpec = new ChainSpec({
28693
+ name: "tiny",
28686
28694
  validatorsCount: numbers_tryAsU16(6),
28687
28695
  coresCount: numbers_tryAsU16(2),
28688
28696
  epochLength: numbers_tryAsU32(12),
@@ -28704,6 +28712,7 @@ const tinyChainSpec = new ChainSpec({
28704
28712
  * Please note that only validatorsCount and epochLength are "full", the rest is copied from "tiny".
28705
28713
  */
28706
28714
  const fullChainSpec = new ChainSpec({
28715
+ name: "full",
28707
28716
  validatorsCount: numbers_tryAsU16(1023),
28708
28717
  coresCount: numbers_tryAsU16(341),
28709
28718
  epochLength: numbers_tryAsU32(600),
@@ -28744,10 +28753,23 @@ class Bootnode {
28744
28753
  }
28745
28754
  }
28746
28755
 
28756
+ ;// CONCATENATED MODULE: ./packages/jam/config/pvm-backend.ts
28757
+ /** Implemented PVM Backends names in THE SAME ORDER as enum. */
28758
+ const PvmBackendNames = (/* unused pure expression or super */ null && (["built-in", "ananas"]));
28759
+ /** Implemented PVM Backends to choose from. */
28760
+ var PvmBackend;
28761
+ (function (PvmBackend) {
28762
+ /** Built-in aka. Typeberry 🫐 interpreter. */
28763
+ PvmBackend[PvmBackend["BuiltIn"] = 0] = "BuiltIn";
28764
+ /** Ananas 🍍 interpreter. */
28765
+ PvmBackend[PvmBackend["Ananas"] = 1] = "Ananas";
28766
+ })(PvmBackend || (PvmBackend = {}));
28767
+
28747
28768
  ;// CONCATENATED MODULE: ./packages/jam/config/index.ts
28748
28769
 
28749
28770
 
28750
28771
 
28772
+
28751
28773
  ;// CONCATENATED MODULE: ./packages/jam/block/codec.ts
28752
28774
 
28753
28775
 
@@ -31300,6 +31322,7 @@ class AuthorshipOptions {
31300
31322
 
31301
31323
 
31302
31324
 
31325
+
31303
31326
  const logger = Logger.new(import.meta.filename, "config");
31304
31327
  /** Development config. Will accept unsealed blocks for now. */
31305
31328
  const DEV_CONFIG = "dev";
@@ -31307,7 +31330,8 @@ const DEV_CONFIG = "dev";
31307
31330
  const DEFAULT_CONFIG = "default";
31308
31331
  const NODE_DEFAULTS = {
31309
31332
  name: isBrowser() ? "browser" : external_node_os_default().hostname(),
31310
- config: DEFAULT_CONFIG,
31333
+ config: [DEFAULT_CONFIG],
31334
+ pvm: PvmBackend.Ananas,
31311
31335
  };
31312
31336
  /** Chain spec chooser. */
31313
31337
  var KnownChainSpec;
@@ -31359,25 +31383,137 @@ class NodeConfiguration {
31359
31383
  this.authorship = authorship;
31360
31384
  }
31361
31385
  }
31362
- function loadConfig(configPath) {
31363
- if (configPath === DEFAULT_CONFIG) {
31364
- logger.log `🔧 Loading DEFAULT config`;
31365
- return parseFromJson(configs.default, NodeConfiguration.fromJson);
31366
- }
31367
- if (configPath === DEV_CONFIG) {
31368
- logger.log `🔧 Loading DEV config`;
31369
- return parseFromJson(configs.dev, NodeConfiguration.fromJson);
31386
+ function loadConfig(config, withRelPath) {
31387
+ logger.log `🔧 Loading config`;
31388
+ let mergedJson = {};
31389
+ for (const entry of config) {
31390
+ logger.log `🔧 Applying '${entry}'`;
31391
+ if (entry === DEV_CONFIG) {
31392
+ mergedJson = structuredClone(configs.dev); // clone to avoid mutating the original config. not doing a merge since dev and default should theoretically replace all properties.
31393
+ continue;
31394
+ }
31395
+ if (entry === DEFAULT_CONFIG) {
31396
+ mergedJson = structuredClone(configs.default);
31397
+ continue;
31398
+ }
31399
+ // try to parse as JSON
31400
+ try {
31401
+ const parsed = JSON.parse(entry);
31402
+ deepMerge(mergedJson, parsed);
31403
+ continue;
31404
+ }
31405
+ catch { }
31406
+ // if not, try to load as file
31407
+ if (entry.indexOf("=") === -1 && entry.endsWith(".json")) {
31408
+ try {
31409
+ const configFile = fs.readFileSync(withRelPath(entry), "utf8");
31410
+ const parsed = JSON.parse(configFile);
31411
+ deepMerge(mergedJson, parsed);
31412
+ }
31413
+ catch (e) {
31414
+ throw new Error(`Unable to load config from ${entry}: ${e}`);
31415
+ }
31416
+ }
31417
+ else {
31418
+ // finally try to process as a pseudo-jq query
31419
+ try {
31420
+ processQuery(mergedJson, entry, withRelPath);
31421
+ }
31422
+ catch (e) {
31423
+ throw new Error(`Error while processing '${entry}': ${e}`);
31424
+ }
31425
+ }
31370
31426
  }
31371
31427
  try {
31372
- logger.log `🔧 Loading config from ${configPath}`;
31373
- const configFile = fs.readFileSync(configPath, "utf8");
31374
- const parsed = JSON.parse(configFile);
31375
- return parseFromJson(parsed, NodeConfiguration.fromJson);
31428
+ const parsed = parseFromJson(mergedJson, NodeConfiguration.fromJson);
31429
+ logger.log `🔧 Config ready`;
31430
+ return parsed;
31376
31431
  }
31377
31432
  catch (e) {
31378
- throw new Error(`Unable to load config file from ${configPath}: ${e}`);
31433
+ throw new Error(`Unable to parse config: ${e}`);
31434
+ }
31435
+ }
31436
+ function deepMerge(target, source) {
31437
+ if (!isJsonObject(source)) {
31438
+ throw new Error(`Expected object, got ${source}`);
31439
+ }
31440
+ for (const key in source) {
31441
+ if (isJsonObject(source[key])) {
31442
+ if (!isJsonObject(target[key])) {
31443
+ target[key] = {};
31444
+ }
31445
+ deepMerge(target[key], source[key]);
31446
+ }
31447
+ else {
31448
+ target[key] = source[key];
31449
+ }
31379
31450
  }
31380
31451
  }
31452
+ /**
31453
+ * Caution: updates input directly.
31454
+ * Processes a pseudo-jq query. Syntax:
31455
+ * .path.to.value = { ... } - updates value with the specified object by replacement
31456
+ * .path.to.value += { ... } - updates value with the specified object by merging
31457
+ * .path.to.value = file.json - updates value with the contents of file.json
31458
+ * .path.to.value += file.json - merges the contents of file.json onto value
31459
+ */
31460
+ function processQuery(input, query, withRelPath) {
31461
+ const queryParts = query.split("=");
31462
+ if (queryParts.length === 2) {
31463
+ let [path, value] = queryParts.map((part) => part.trim());
31464
+ let merge = false;
31465
+ // detect += syntax
31466
+ if (path.endsWith("+")) {
31467
+ merge = true;
31468
+ path = path.slice(0, -1);
31469
+ }
31470
+ let parsedValue;
31471
+ if (value.endsWith(".json")) {
31472
+ try {
31473
+ const configFile = fs.readFileSync(withRelPath(value), "utf8");
31474
+ const parsed = JSON.parse(configFile);
31475
+ parsedValue = parsed;
31476
+ }
31477
+ catch (e) {
31478
+ throw new Error(`Unable to load config from ${value}: ${e}`);
31479
+ }
31480
+ }
31481
+ else {
31482
+ try {
31483
+ parsedValue = JSON.parse(value);
31484
+ }
31485
+ catch (e) {
31486
+ throw new Error(`Unrecognized syntax '${value}': ${e}`);
31487
+ }
31488
+ }
31489
+ let pathParts = path.split(".");
31490
+ // allow leading dot in path
31491
+ if (pathParts[0] === "") {
31492
+ pathParts = pathParts.slice(1);
31493
+ }
31494
+ let target = input;
31495
+ for (let i = 0; i < pathParts.length; i++) {
31496
+ const part = pathParts[i];
31497
+ if (!isJsonObject(target[part])) {
31498
+ target[part] = {};
31499
+ }
31500
+ if (i === pathParts.length - 1) {
31501
+ if (merge) {
31502
+ deepMerge(target[part], parsedValue);
31503
+ }
31504
+ else {
31505
+ target[part] = parsedValue;
31506
+ }
31507
+ return;
31508
+ }
31509
+ target = target[part];
31510
+ }
31511
+ }
31512
+ throw new Error("Unrecognized syntax.");
31513
+ }
31514
+ function isJsonObject(value) {
31515
+ return typeof value === "object" && value !== null && !Array.isArray(value);
31516
+ }
31381
31517
 
31382
31518
  ;// CONCATENATED MODULE: ./packages/jam/config-node/index.ts
31383
31519