@typeberry/jam 0.1.1-4a6ffa9 → 0.1.1-e48de40

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.
@@ -12975,6 +12975,23 @@ function parseLevel(lvl) {
12975
12975
  ;// CONCATENATED MODULE: ./packages/core/logger/console.ts
12976
12976
  // biome-ignore-all lint/suspicious/noConsole: logger
12977
12977
 
12978
+ function print(level, levelAndName, strings, data) {
12979
+ if (level < levelAndName[0]) {
12980
+ return;
12981
+ }
12982
+ const lvlText = Level[level].padEnd(5);
12983
+ const val = strings.map((v, idx) => `${v}${data[idx]}`);
12984
+ const msg = `${lvlText} [${levelAndName[1]}] ${val}`;
12985
+ if (level === Level.WARN) {
12986
+ console.warn(msg);
12987
+ }
12988
+ else if (level === Level.ERROR) {
12989
+ console.error(msg);
12990
+ }
12991
+ else {
12992
+ console.info(msg);
12993
+ }
12994
+ }
12978
12995
  /** An optimized logger that ignores `TRACE`, `DEBUG` and `LOG` messages.
12979
12996
  *
12980
12997
  * Use the `create` method to instantiate the right instance of a more specialized logger.
@@ -13005,109 +13022,91 @@ class ConsoleTransport {
13005
13022
  constructor(options) {
13006
13023
  this.options = options;
13007
13024
  }
13008
- insane(_moduleName, _val) {
13025
+ insane(_levelAndName, _strings, _data) {
13009
13026
  /* no-op */
13010
13027
  }
13011
- trace(_moduleName, _val) {
13028
+ trace(_levelAndName, _strings, _data) {
13012
13029
  /* no-op */
13013
13030
  }
13014
- log(_moduleName, _val) {
13031
+ log(_levelAndName, _strings, _data) {
13015
13032
  /* no-op */
13016
13033
  }
13017
- info(_moduleName, _val) {
13034
+ info(_levelAndName, _strings, _data) {
13018
13035
  /* no-op */
13019
13036
  }
13020
- warn(moduleName, val) {
13021
- this.push(Level.WARN, moduleName, val);
13022
- }
13023
- error(moduleName, val) {
13024
- this.push(Level.ERROR, moduleName, val);
13037
+ warn(levelAndName, strings, data) {
13038
+ print(Level.WARN, levelAndName, strings, data);
13025
13039
  }
13026
- push(level, moduleName, val) {
13027
- const shortModule = moduleName.replace(this.options.workingDir, "");
13028
- const configuredLevel = findLevel(this.options, moduleName);
13029
- const lvlText = Level[level].padEnd(5);
13030
- if (level < configuredLevel) {
13031
- return;
13032
- }
13033
- const msg = `${lvlText} [${shortModule}] ${val}`;
13034
- if (level === Level.WARN) {
13035
- console.warn(msg);
13036
- }
13037
- else if (level === Level.ERROR) {
13038
- console.error(msg);
13039
- }
13040
- else {
13041
- console.info(msg);
13042
- }
13040
+ error(levelAndName, strings, data) {
13041
+ print(Level.ERROR, levelAndName, strings, data);
13043
13042
  }
13044
13043
  }
13045
13044
  /**
13046
13045
  * Insane version of console logger - supports insane level.
13047
13046
  */
13048
13047
  class InsaneConsoleLogger extends ConsoleTransport {
13049
- insane(moduleName, val) {
13050
- this.push(Level.INSANE, moduleName, val);
13048
+ insane(levelAndName, strings, data) {
13049
+ print(Level.INSANE, levelAndName, strings, data);
13051
13050
  }
13052
- trace(moduleName, val) {
13053
- this.push(Level.TRACE, moduleName, val);
13051
+ trace(levelAndName, strings, data) {
13052
+ print(Level.TRACE, levelAndName, strings, data);
13054
13053
  }
13055
- log(moduleName, val) {
13056
- this.push(Level.LOG, moduleName, val);
13054
+ log(levelAndName, strings, data) {
13055
+ print(Level.LOG, levelAndName, strings, data);
13057
13056
  }
13058
- info(moduleName, val) {
13059
- this.push(Level.INFO, moduleName, val);
13057
+ info(levelAndName, strings, data) {
13058
+ print(Level.INFO, levelAndName, strings, data);
13060
13059
  }
13061
13060
  }
13062
13061
  /**
13063
13062
  * A basic version of console logger - printing everything.
13064
13063
  */
13065
13064
  class TraceConsoleTransport extends ConsoleTransport {
13066
- insane(_moduleName, _val) {
13065
+ insane(_levelAndName, _strings, _data) {
13067
13066
  /* no-op */
13068
13067
  }
13069
- trace(moduleName, val) {
13070
- this.push(Level.TRACE, moduleName, val);
13068
+ trace(levelAndName, strings, data) {
13069
+ print(Level.TRACE, levelAndName, strings, data);
13071
13070
  }
13072
- log(moduleName, val) {
13073
- this.push(Level.LOG, moduleName, val);
13071
+ log(levelAndName, strings, data) {
13072
+ print(Level.LOG, levelAndName, strings, data);
13074
13073
  }
13075
- info(moduleName, val) {
13076
- this.push(Level.INFO, moduleName, val);
13074
+ info(levelAndName, strings, data) {
13075
+ print(Level.INFO, levelAndName, strings, data);
13077
13076
  }
13078
13077
  }
13079
13078
  /**
13080
13079
  * An optimized version of the logger - completely ignores `TRACE` level calls.
13081
13080
  */
13082
13081
  class LogConsoleTransport extends ConsoleTransport {
13083
- insane(_moduleName, _val) {
13082
+ insane(_levelAndName, _strings, _data) {
13084
13083
  /* no-op */
13085
13084
  }
13086
- trace(_moduleName, _val) {
13085
+ trace(_levelAndName, _strings, _data) {
13087
13086
  /* no-op */
13088
13087
  }
13089
- log(moduleName, val) {
13090
- this.push(Level.LOG, moduleName, val);
13088
+ log(levelAndName, strings, data) {
13089
+ print(Level.LOG, levelAndName, strings, data);
13091
13090
  }
13092
- info(moduleName, val) {
13093
- this.push(Level.INFO, moduleName, val);
13091
+ info(levelAndName, strings, data) {
13092
+ print(Level.INFO, levelAndName, strings, data);
13094
13093
  }
13095
13094
  }
13096
13095
  /**
13097
13096
  * An optimized version of the logger - completely ignores `TRACE` & `DEBUG` level calls.
13098
13097
  */
13099
13098
  class InfoConsoleTransport extends ConsoleTransport {
13100
- insane(_moduleName, _val) {
13099
+ insane(_levelAndName, _strings, _data) {
13101
13100
  /* no-op */
13102
13101
  }
13103
- trace(_moduleName, _val) {
13102
+ trace(_levelAndName, _strings, _data) {
13104
13103
  /* no-op */
13105
13104
  }
13106
- log(_moduleName, _val) {
13105
+ log(_levelAndName, _strings, _data) {
13107
13106
  /* no-op */
13108
13107
  }
13109
- info(moduleName, val) {
13110
- this.push(Level.INFO, moduleName, val);
13108
+ info(levelAndName, strings, data) {
13109
+ print(Level.INFO, levelAndName, strings, data);
13111
13110
  }
13112
13111
  }
13113
13112
 
@@ -13144,11 +13143,6 @@ class Logger {
13144
13143
  const module = moduleName ?? fName;
13145
13144
  return new Logger(module.padStart(8, " "), GLOBAL_CONFIG);
13146
13145
  }
13147
- /**
13148
- * Return currently configured level for given module. */
13149
- static getLevel(moduleName) {
13150
- return findLevel(GLOBAL_CONFIG.options, moduleName);
13151
- }
13152
13146
  /**
13153
13147
  * Global configuration of all loggers.
13154
13148
  *
@@ -13179,33 +13173,46 @@ class Logger {
13179
13173
  const options = parseLoggerOptions(input, defaultLevel, workingDir);
13180
13174
  Logger.configureAllFromOptions(options);
13181
13175
  }
13176
+ cachedLevelAndName;
13182
13177
  constructor(moduleName, config) {
13183
13178
  this.moduleName = moduleName;
13184
13179
  this.config = config;
13185
13180
  }
13181
+ /** Return currently configured level for given module. */
13182
+ getLevel() {
13183
+ return this.getLevelAndName()[0];
13184
+ }
13185
+ getLevelAndName() {
13186
+ if (this.cachedLevelAndName === undefined) {
13187
+ const level = findLevel(this.config.options, this.moduleName);
13188
+ const shortName = this.moduleName.replace(this.config.options.workingDir, "");
13189
+ this.cachedLevelAndName = [level, shortName];
13190
+ }
13191
+ return this.cachedLevelAndName;
13192
+ }
13186
13193
  /** Log a message with `INSANE` level. */
13187
- insane(val) {
13188
- this.config.transport.insane(this.moduleName, val);
13194
+ insane(strings, ...data) {
13195
+ this.config.transport.insane(this.getLevelAndName(), strings, data);
13189
13196
  }
13190
13197
  /** Log a message with `TRACE` level. */
13191
- trace(val) {
13192
- this.config.transport.trace(this.moduleName, val);
13198
+ trace(strings, ...data) {
13199
+ this.config.transport.trace(this.getLevelAndName(), strings, data);
13193
13200
  }
13194
13201
  /** Log a message with `DEBUG`/`LOG` level. */
13195
- log(val) {
13196
- this.config.transport.log(this.moduleName, val);
13202
+ log(strings, ...data) {
13203
+ this.config.transport.log(this.getLevelAndName(), strings, data);
13197
13204
  }
13198
13205
  /** Log a message with `INFO` level. */
13199
- info(val) {
13200
- this.config.transport.info(this.moduleName, val);
13206
+ info(strings, ...data) {
13207
+ this.config.transport.info(this.getLevelAndName(), strings, data);
13201
13208
  }
13202
13209
  /** Log a message with `WARN` level. */
13203
- warn(val) {
13204
- this.config.transport.warn(this.moduleName, val);
13210
+ warn(strings, ...data) {
13211
+ this.config.transport.warn(this.getLevelAndName(), strings, data);
13205
13212
  }
13206
13213
  /** Log a message with `ERROR` level. */
13207
- error(val) {
13208
- this.config.transport.error(this.moduleName, val);
13214
+ error(strings, ...data) {
13215
+ this.config.transport.error(this.getLevelAndName(), strings, data);
13209
13216
  }
13210
13217
  }
13211
13218
 
@@ -13320,7 +13327,7 @@ class LmdbStates {
13320
13327
  await Promise.all([valuesWrite, statesWrite]);
13321
13328
  }
13322
13329
  catch (e) {
13323
- logger.error(`${e}`);
13330
+ logger.error `${e}`;
13324
13331
  return result_Result.error(StateUpdateError.Commit);
13325
13332
  }
13326
13333
  return result_Result.ok(result_OK);
@@ -13428,7 +13435,7 @@ class TypedPort {
13428
13435
  this.dispatchPortMessage(msg);
13429
13436
  }
13430
13437
  catch (e) {
13431
- port_logger.error(`[${this.constructor.name}] Failed to dispatch a message: ${e}: ${JSON.stringify(msg)}`);
13438
+ port_logger.error `[${this.constructor.name}] Failed to dispatch a message: ${e}: ${msg}`;
13432
13439
  throw e;
13433
13440
  }
13434
13441
  });
@@ -13502,7 +13509,7 @@ class TypedPort {
13502
13509
  this.port.postMessage(msg, transferList);
13503
13510
  }
13504
13511
  catch (e) {
13505
- port_logger.error(`[${this.constructor.name}] Failed to post a message: ${e}: ${JSON.stringify(msg)}`);
13512
+ port_logger.error `[${this.constructor.name}] Failed to post a message: ${e}: ${msg}`;
13506
13513
  throw e;
13507
13514
  }
13508
13515
  }
@@ -13533,7 +13540,7 @@ class TypedPort {
13533
13540
  cleanup(reason) {
13534
13541
  // resolve all pending requests with an error.
13535
13542
  const responseListeners = this.responseListeners.eventNames();
13536
- for (const ev in responseListeners) {
13543
+ for (const ev of responseListeners) {
13537
13544
  this.responseListeners.emit(ev, new Error(`port is ${reason}`));
13538
13545
  }
13539
13546
  }
@@ -13582,7 +13589,7 @@ class MessageChannelStateMachine {
13582
13589
  this.dispatchSignal(name, data);
13583
13590
  }
13584
13591
  catch (e) {
13585
- channel_logger.error(`[${this.constructor.name}] Unable to dispatch signal (${name}): ${e}. ${this.stateInfo(remoteState)}`);
13592
+ channel_logger.error `[${this.constructor.name}] Unable to dispatch signal (${name}): ${e}. ${this.stateInfo(remoteState)}`;
13586
13593
  throw e;
13587
13594
  }
13588
13595
  });
@@ -13591,7 +13598,7 @@ class MessageChannelStateMachine {
13591
13598
  await this.dispatchRequest(name, data, msg);
13592
13599
  }
13593
13600
  catch (e) {
13594
- channel_logger.error(`[${this.constructor.name}] Unable to dispatch request (${name}): ${e}. ${this.stateInfo(remoteState)}`);
13601
+ channel_logger.error `[${this.constructor.name}] Unable to dispatch request (${name}): ${e}. ${this.stateInfo(remoteState)}`;
13595
13602
  throw e;
13596
13603
  }
13597
13604
  });
@@ -13677,7 +13684,7 @@ class MessageChannelStateMachine {
13677
13684
  this.machine.transition(res.transitionTo.state, res.transitionTo.data);
13678
13685
  }
13679
13686
  if (didStateChangeInMeantime) {
13680
- channel_logger.warn(`Ignoring obsolete response for an old request: "${name}"`);
13687
+ channel_logger.warn `Ignoring obsolete response for an old request: "${name}"`;
13681
13688
  return;
13682
13689
  }
13683
13690
  return this.port.respond(prevState.stateName, msg, res.response);
@@ -13693,7 +13700,7 @@ class MessageChannelStateMachine {
13693
13700
  }
13694
13701
  }
13695
13702
  transitionTo() {
13696
- channel_logger.trace(`[${this.machine.name}] transitioned to ${this.currentState()}`);
13703
+ channel_logger.trace `[${this.machine.name}] transitioned to ${this.currentState()}`;
13697
13704
  return this;
13698
13705
  }
13699
13706
  /**
@@ -13713,7 +13720,7 @@ class MessageChannelStateMachine {
13713
13720
  await promise;
13714
13721
  }
13715
13722
  catch (e) {
13716
- channel_logger.error(JSON.stringify(e));
13723
+ channel_logger.error `${e}`;
13717
13724
  }
13718
13725
  return new MessageChannelStateMachine(machine, port);
13719
13726
  }
@@ -13916,7 +13923,7 @@ class State {
13916
13923
  * actions.
13917
13924
  */
13918
13925
  onActivation(data) {
13919
- state_logger.trace(`[${this.constructor.name}] Changing state to: ${this}`);
13926
+ state_logger.trace `[${this.constructor.name}] Changing state to: ${this}`;
13920
13927
  this.data = data;
13921
13928
  }
13922
13929
  /**
@@ -14014,7 +14021,7 @@ async function spawnWorkerGeneric(bootstrapPath, logger, mainReadyName, mainRead
14014
14021
  const worker = new external_node_worker_threads_namespaceObject.Worker(bootstrapPath);
14015
14022
  const machine = stateMachineMain(`main->${mainReadyName}`, mainReadyName, mainReadyState);
14016
14023
  const channel = await MessageChannelStateMachine.createAndTransferChannel(machine, worker);
14017
- logger.trace(`[${machine.name}] Worker spawned ${channel.currentState()}`);
14024
+ logger.trace `[${machine.name}] Worker spawned ${channel.currentState()}`;
14018
14025
  return channel;
14019
14026
  }
14020
14027
 
@@ -15592,12 +15599,14 @@ class writeable_page_WriteablePage extends MemoryPage {
15592
15599
 
15593
15600
 
15594
15601
 
15602
+
15603
+
15595
15604
  var AccessType;
15596
15605
  (function (AccessType) {
15597
15606
  AccessType[AccessType["READ"] = 0] = "READ";
15598
15607
  AccessType[AccessType["WRITE"] = 1] = "WRITE";
15599
15608
  })(AccessType || (AccessType = {}));
15600
- // const logger = Logger.new(import.meta.filename, "pvm:mem");
15609
+ const memory_logger = Logger.new(import.meta.filename, "pvm:mem");
15601
15610
  class memory_Memory {
15602
15611
  sbrkIndex;
15603
15612
  virtualSbrkIndex;
@@ -15628,7 +15637,7 @@ class memory_Memory {
15628
15637
  if (bytes.length === 0) {
15629
15638
  return Result.ok(OK);
15630
15639
  }
15631
- // logger.insane(`MEM[${address}] <- ${BytesBlob.blobFrom(bytes)}`);
15640
+ memory_logger.insane `MEM[${address}] <- ${BytesBlob.blobFrom(bytes)}`;
15632
15641
  const pagesResult = this.getPages(address, bytes.length, AccessType.WRITE);
15633
15642
  if (pagesResult.isError) {
15634
15643
  return Result.error(pagesResult.error);
@@ -15695,7 +15704,7 @@ class memory_Memory {
15695
15704
  currentPosition += bytesToRead;
15696
15705
  bytesLeft -= bytesToRead;
15697
15706
  }
15698
- // logger.insane(`MEM[${startAddress}] => ${BytesBlob.blobFrom(result)}`);
15707
+ memory_logger.insane `MEM[${startAddress}] => ${BytesBlob.blobFrom(result)}`;
15699
15708
  return Result.ok(OK);
15700
15709
  }
15701
15710
  sbrk(length) {
@@ -17432,7 +17441,7 @@ class program_decoder_ProgramDecoder {
17432
17441
  return Result.ok(new program_decoder_ProgramDecoder(program));
17433
17442
  }
17434
17443
  catch (e) {
17435
- program_decoder_logger.error(`Invalid program: ${e}`);
17444
+ program_decoder_logger.error `Invalid program: ${e}`;
17436
17445
  return Result.error(ProgramDecoderError.InvalidProgramError);
17437
17446
  }
17438
17447
  }
@@ -17598,7 +17607,7 @@ class interpreter_Interpreter {
17598
17607
  const argsType = instructionArgumentTypeMap[currentInstruction] ?? ArgumentType.NO_ARGUMENTS;
17599
17608
  const argsResult = this.argsDecodingResults[argsType];
17600
17609
  this.argsDecoder.fillArgs(this.pc, argsResult);
17601
- interpreter_logger.insane(`[PC: ${this.pc}] ${Instruction[currentInstruction]}`);
17610
+ interpreter_logger.insane `[PC: ${this.pc}] ${Instruction[currentInstruction]}`;
17602
17611
  if (!isValidInstruction) {
17603
17612
  this.instructionResult.status = Result.PANIC;
17604
17613
  }
@@ -17670,7 +17679,7 @@ class interpreter_Interpreter {
17670
17679
  this.status = Status.HOST;
17671
17680
  break;
17672
17681
  }
17673
- interpreter_logger.insane(`[PC: ${this.pc}] Status: ${Result[this.instructionResult.status]}`);
17682
+ interpreter_logger.insane `[PC: ${this.pc}] Status: ${Result[this.instructionResult.status]}`;
17674
17683
  return this.status;
17675
17684
  }
17676
17685
  this.pc = this.instructionResult.nextPc;
@@ -17917,7 +17926,7 @@ class host_calls_manager_HostCallsManager {
17917
17926
  return `r${idx}=${value} (0x${value.toString(16)})`;
17918
17927
  })
17919
17928
  .join(", ");
17920
- host_calls_manager_logger.insane(`[${currentServiceId}] ${context} ${name}${requested}. Gas: ${gas}. Regs: ${registerValues}.`);
17929
+ host_calls_manager_logger.insane `[${currentServiceId}] ${context} ${name}${requested}. Gas: ${gas}. Regs: ${registerValues}.`;
17921
17930
  }
17922
17931
  }
17923
17932
  class NoopMissing {
@@ -18504,7 +18513,7 @@ class MainReady extends State {
18504
18513
  this.onBlock.emit(block);
18505
18514
  }
18506
18515
  else {
18507
- state_machine_logger.error(`${this.constructor.name} got invalid signal type: ${JSON.stringify(block)}.`);
18516
+ state_machine_logger.error `${this.constructor.name} got invalid signal type: ${JSON.stringify(block)}.`;
18508
18517
  }
18509
18518
  }
18510
18519
  finish(channel) {
@@ -18559,12 +18568,12 @@ if (!external_node_worker_threads_namespaceObject.isMainThread) {
18559
18568
  channel
18560
18569
  .then((channel) => main(channel))
18561
18570
  .catch((e) => {
18562
- block_generator_logger.error(e);
18571
+ block_generator_logger.error `${e}`;
18563
18572
  if (e.stack !== undefined) {
18564
- block_generator_logger.error(e.stack);
18573
+ block_generator_logger.error `${e.stack}`;
18565
18574
  }
18566
18575
  if (e.cause !== undefined) {
18567
- block_generator_logger.error(e.cause);
18576
+ block_generator_logger.error `${e.cause}`;
18568
18577
  }
18569
18578
  });
18570
18579
  }
@@ -18572,7 +18581,7 @@ if (!external_node_worker_threads_namespaceObject.isMainThread) {
18572
18581
  * The `BlockGenerator` should periodically create new blocks and send them as signals to the main thread.
18573
18582
  */
18574
18583
  async function main(channel) {
18575
- block_generator_logger.info(`🎁 Block Generator running ${channel.currentState()}`);
18584
+ block_generator_logger.info `🎁 Block Generator running ${channel.currentState()}`;
18576
18585
  // Await the configuration object
18577
18586
  const ready = await channel.waitForState("ready(generator)");
18578
18587
  const config = ready.currentState().getConfig();
@@ -18587,11 +18596,11 @@ async function main(channel) {
18587
18596
  await (0,promises_namespaceObject.setTimeout)(config.chainSpec.slotDuration * 1000);
18588
18597
  counter += 1;
18589
18598
  const newBlock = await generator.nextEncodedBlock();
18590
- block_generator_logger.trace(`Sending block ${counter}`);
18599
+ block_generator_logger.trace `Sending block ${counter}`;
18591
18600
  worker.sendBlock(port, newBlock);
18592
18601
  }
18593
18602
  });
18594
- block_generator_logger.info("Block Generator finished. Closing channel.");
18603
+ block_generator_logger.info `Block Generator finished. Closing channel.`;
18595
18604
  // Close the comms to gracefully close the app.
18596
18605
  finished.currentState().close(channel);
18597
18606
  }