@typeberry/jam 0.1.1-b537c8b → 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.
package/importer/index.js CHANGED
@@ -4436,6 +4436,34 @@ class WithDebug {
4436
4436
  }
4437
4437
  }
4438
4438
 
4439
+ ;// CONCATENATED MODULE: ./packages/core/utils/dev.ts
4440
+ const dev_env = typeof process === "undefined" ? {} : process.env;
4441
+ /**
4442
+ * The function will produce relative path resolver that is adjusted
4443
+ * for package location within the workspace.
4444
+ *
4445
+ * Example:
4446
+ * $ npm start -w @typeberry/jam
4447
+ *
4448
+ * The above command will run `./bin/jam/index.js`, however we would
4449
+ * still want relative paths to be resolved according to top-level workspace
4450
+ * directory.
4451
+ *
4452
+ * So the caller, passes the absolute workspace path as argument and get's
4453
+ * a function that can properly resolve relative paths.
4454
+ *
4455
+ * NOTE: the translation happens only for development build! When
4456
+ * we build a single library from our project, we no longer mangle the paths.
4457
+ */
4458
+ const workspacePathFix = dev_env.NODE_ENV === "development"
4459
+ ? (workspacePath) => (p) => {
4460
+ if (p.startsWith("/")) {
4461
+ return p;
4462
+ }
4463
+ return `${workspacePath}/${p}`;
4464
+ }
4465
+ : () => (p) => p;
4466
+
4439
4467
  ;// CONCATENATED MODULE: ./packages/core/utils/opaque.ts
4440
4468
  /**
4441
4469
  * @fileoverview `Opaque<Type, Token>` constructs a unique type which is a subset of Type with a
@@ -4779,6 +4807,7 @@ function isResult(x) {
4779
4807
 
4780
4808
 
4781
4809
 
4810
+
4782
4811
  ;// CONCATENATED MODULE: ./packages/core/bytes/bitvec.ts
4783
4812
 
4784
4813
  /**
@@ -13372,6 +13401,23 @@ function parseLevel(lvl) {
13372
13401
  ;// CONCATENATED MODULE: ./packages/core/logger/console.ts
13373
13402
  // biome-ignore-all lint/suspicious/noConsole: logger
13374
13403
 
13404
+ function print(level, levelAndName, strings, data) {
13405
+ if (level < levelAndName[0]) {
13406
+ return;
13407
+ }
13408
+ const lvlText = Level[level].padEnd(5);
13409
+ const val = strings.map((v, idx) => `${v}${data[idx]}`);
13410
+ const msg = `${lvlText} [${levelAndName[1]}] ${val}`;
13411
+ if (level === Level.WARN) {
13412
+ console.warn(msg);
13413
+ }
13414
+ else if (level === Level.ERROR) {
13415
+ console.error(msg);
13416
+ }
13417
+ else {
13418
+ console.info(msg);
13419
+ }
13420
+ }
13375
13421
  /** An optimized logger that ignores `TRACE`, `DEBUG` and `LOG` messages.
13376
13422
  *
13377
13423
  * Use the `create` method to instantiate the right instance of a more specialized logger.
@@ -13402,109 +13448,91 @@ class ConsoleTransport {
13402
13448
  constructor(options) {
13403
13449
  this.options = options;
13404
13450
  }
13405
- insane(_moduleName, _val) {
13451
+ insane(_levelAndName, _strings, _data) {
13406
13452
  /* no-op */
13407
13453
  }
13408
- trace(_moduleName, _val) {
13454
+ trace(_levelAndName, _strings, _data) {
13409
13455
  /* no-op */
13410
13456
  }
13411
- log(_moduleName, _val) {
13457
+ log(_levelAndName, _strings, _data) {
13412
13458
  /* no-op */
13413
13459
  }
13414
- info(_moduleName, _val) {
13460
+ info(_levelAndName, _strings, _data) {
13415
13461
  /* no-op */
13416
13462
  }
13417
- warn(moduleName, val) {
13418
- this.push(Level.WARN, moduleName, val);
13419
- }
13420
- error(moduleName, val) {
13421
- this.push(Level.ERROR, moduleName, val);
13463
+ warn(levelAndName, strings, data) {
13464
+ print(Level.WARN, levelAndName, strings, data);
13422
13465
  }
13423
- push(level, moduleName, val) {
13424
- const shortModule = moduleName.replace(this.options.workingDir, "");
13425
- const configuredLevel = findLevel(this.options, moduleName);
13426
- const lvlText = Level[level].padEnd(5);
13427
- if (level < configuredLevel) {
13428
- return;
13429
- }
13430
- const msg = `${lvlText} [${shortModule}] ${val}`;
13431
- if (level === Level.WARN) {
13432
- console.warn(msg);
13433
- }
13434
- else if (level === Level.ERROR) {
13435
- console.error(msg);
13436
- }
13437
- else {
13438
- console.info(msg);
13439
- }
13466
+ error(levelAndName, strings, data) {
13467
+ print(Level.ERROR, levelAndName, strings, data);
13440
13468
  }
13441
13469
  }
13442
13470
  /**
13443
13471
  * Insane version of console logger - supports insane level.
13444
13472
  */
13445
13473
  class InsaneConsoleLogger extends ConsoleTransport {
13446
- insane(moduleName, val) {
13447
- this.push(Level.INSANE, moduleName, val);
13474
+ insane(levelAndName, strings, data) {
13475
+ print(Level.INSANE, levelAndName, strings, data);
13448
13476
  }
13449
- trace(moduleName, val) {
13450
- this.push(Level.TRACE, moduleName, val);
13477
+ trace(levelAndName, strings, data) {
13478
+ print(Level.TRACE, levelAndName, strings, data);
13451
13479
  }
13452
- log(moduleName, val) {
13453
- this.push(Level.LOG, moduleName, val);
13480
+ log(levelAndName, strings, data) {
13481
+ print(Level.LOG, levelAndName, strings, data);
13454
13482
  }
13455
- info(moduleName, val) {
13456
- this.push(Level.INFO, moduleName, val);
13483
+ info(levelAndName, strings, data) {
13484
+ print(Level.INFO, levelAndName, strings, data);
13457
13485
  }
13458
13486
  }
13459
13487
  /**
13460
13488
  * A basic version of console logger - printing everything.
13461
13489
  */
13462
13490
  class TraceConsoleTransport extends ConsoleTransport {
13463
- insane(_moduleName, _val) {
13491
+ insane(_levelAndName, _strings, _data) {
13464
13492
  /* no-op */
13465
13493
  }
13466
- trace(moduleName, val) {
13467
- this.push(Level.TRACE, moduleName, val);
13494
+ trace(levelAndName, strings, data) {
13495
+ print(Level.TRACE, levelAndName, strings, data);
13468
13496
  }
13469
- log(moduleName, val) {
13470
- this.push(Level.LOG, moduleName, val);
13497
+ log(levelAndName, strings, data) {
13498
+ print(Level.LOG, levelAndName, strings, data);
13471
13499
  }
13472
- info(moduleName, val) {
13473
- this.push(Level.INFO, moduleName, val);
13500
+ info(levelAndName, strings, data) {
13501
+ print(Level.INFO, levelAndName, strings, data);
13474
13502
  }
13475
13503
  }
13476
13504
  /**
13477
13505
  * An optimized version of the logger - completely ignores `TRACE` level calls.
13478
13506
  */
13479
13507
  class LogConsoleTransport extends ConsoleTransport {
13480
- insane(_moduleName, _val) {
13508
+ insane(_levelAndName, _strings, _data) {
13481
13509
  /* no-op */
13482
13510
  }
13483
- trace(_moduleName, _val) {
13511
+ trace(_levelAndName, _strings, _data) {
13484
13512
  /* no-op */
13485
13513
  }
13486
- log(moduleName, val) {
13487
- this.push(Level.LOG, moduleName, val);
13514
+ log(levelAndName, strings, data) {
13515
+ print(Level.LOG, levelAndName, strings, data);
13488
13516
  }
13489
- info(moduleName, val) {
13490
- this.push(Level.INFO, moduleName, val);
13517
+ info(levelAndName, strings, data) {
13518
+ print(Level.INFO, levelAndName, strings, data);
13491
13519
  }
13492
13520
  }
13493
13521
  /**
13494
13522
  * An optimized version of the logger - completely ignores `TRACE` & `DEBUG` level calls.
13495
13523
  */
13496
13524
  class InfoConsoleTransport extends ConsoleTransport {
13497
- insane(_moduleName, _val) {
13525
+ insane(_levelAndName, _strings, _data) {
13498
13526
  /* no-op */
13499
13527
  }
13500
- trace(_moduleName, _val) {
13528
+ trace(_levelAndName, _strings, _data) {
13501
13529
  /* no-op */
13502
13530
  }
13503
- log(_moduleName, _val) {
13531
+ log(_levelAndName, _strings, _data) {
13504
13532
  /* no-op */
13505
13533
  }
13506
- info(moduleName, val) {
13507
- this.push(Level.INFO, moduleName, val);
13534
+ info(levelAndName, strings, data) {
13535
+ print(Level.INFO, levelAndName, strings, data);
13508
13536
  }
13509
13537
  }
13510
13538
 
@@ -13541,11 +13569,6 @@ class Logger {
13541
13569
  const module = moduleName ?? fName;
13542
13570
  return new Logger(module.padStart(8, " "), GLOBAL_CONFIG);
13543
13571
  }
13544
- /**
13545
- * Return currently configured level for given module. */
13546
- static getLevel(moduleName) {
13547
- return findLevel(GLOBAL_CONFIG.options, moduleName);
13548
- }
13549
13572
  /**
13550
13573
  * Global configuration of all loggers.
13551
13574
  *
@@ -13576,33 +13599,46 @@ class Logger {
13576
13599
  const options = parseLoggerOptions(input, defaultLevel, workingDir);
13577
13600
  Logger.configureAllFromOptions(options);
13578
13601
  }
13602
+ cachedLevelAndName;
13579
13603
  constructor(moduleName, config) {
13580
13604
  this.moduleName = moduleName;
13581
13605
  this.config = config;
13582
13606
  }
13607
+ /** Return currently configured level for given module. */
13608
+ getLevel() {
13609
+ return this.getLevelAndName()[0];
13610
+ }
13611
+ getLevelAndName() {
13612
+ if (this.cachedLevelAndName === undefined) {
13613
+ const level = findLevel(this.config.options, this.moduleName);
13614
+ const shortName = this.moduleName.replace(this.config.options.workingDir, "");
13615
+ this.cachedLevelAndName = [level, shortName];
13616
+ }
13617
+ return this.cachedLevelAndName;
13618
+ }
13583
13619
  /** Log a message with `INSANE` level. */
13584
- insane(val) {
13585
- this.config.transport.insane(this.moduleName, val);
13620
+ insane(strings, ...data) {
13621
+ this.config.transport.insane(this.getLevelAndName(), strings, data);
13586
13622
  }
13587
13623
  /** Log a message with `TRACE` level. */
13588
- trace(val) {
13589
- this.config.transport.trace(this.moduleName, val);
13624
+ trace(strings, ...data) {
13625
+ this.config.transport.trace(this.getLevelAndName(), strings, data);
13590
13626
  }
13591
13627
  /** Log a message with `DEBUG`/`LOG` level. */
13592
- log(val) {
13593
- this.config.transport.log(this.moduleName, val);
13628
+ log(strings, ...data) {
13629
+ this.config.transport.log(this.getLevelAndName(), strings, data);
13594
13630
  }
13595
13631
  /** Log a message with `INFO` level. */
13596
- info(val) {
13597
- this.config.transport.info(this.moduleName, val);
13632
+ info(strings, ...data) {
13633
+ this.config.transport.info(this.getLevelAndName(), strings, data);
13598
13634
  }
13599
13635
  /** Log a message with `WARN` level. */
13600
- warn(val) {
13601
- this.config.transport.warn(this.moduleName, val);
13636
+ warn(strings, ...data) {
13637
+ this.config.transport.warn(this.getLevelAndName(), strings, data);
13602
13638
  }
13603
13639
  /** Log a message with `ERROR` level. */
13604
- error(val) {
13605
- this.config.transport.error(this.moduleName, val);
13640
+ error(strings, ...data) {
13641
+ this.config.transport.error(this.getLevelAndName(), strings, data);
13606
13642
  }
13607
13643
  }
13608
13644
 
@@ -13717,7 +13753,7 @@ class LmdbStates {
13717
13753
  await Promise.all([valuesWrite, statesWrite]);
13718
13754
  }
13719
13755
  catch (e) {
13720
- logger.error(`${e}`);
13756
+ logger.error `${e}`;
13721
13757
  return result_Result.error(StateUpdateError.Commit);
13722
13758
  }
13723
13759
  return result_Result.ok(result_OK);
@@ -13825,7 +13861,7 @@ class TypedPort {
13825
13861
  this.dispatchPortMessage(msg);
13826
13862
  }
13827
13863
  catch (e) {
13828
- port_logger.error(`[${this.constructor.name}] Failed to dispatch a message: ${e}: ${JSON.stringify(msg)}`);
13864
+ port_logger.error `[${this.constructor.name}] Failed to dispatch a message: ${e}: ${msg}`;
13829
13865
  throw e;
13830
13866
  }
13831
13867
  });
@@ -13899,7 +13935,7 @@ class TypedPort {
13899
13935
  this.port.postMessage(msg, transferList);
13900
13936
  }
13901
13937
  catch (e) {
13902
- port_logger.error(`[${this.constructor.name}] Failed to post a message: ${e}: ${JSON.stringify(msg)}`);
13938
+ port_logger.error `[${this.constructor.name}] Failed to post a message: ${e}: ${msg}`;
13903
13939
  throw e;
13904
13940
  }
13905
13941
  }
@@ -13930,7 +13966,7 @@ class TypedPort {
13930
13966
  cleanup(reason) {
13931
13967
  // resolve all pending requests with an error.
13932
13968
  const responseListeners = this.responseListeners.eventNames();
13933
- for (const ev in responseListeners) {
13969
+ for (const ev of responseListeners) {
13934
13970
  this.responseListeners.emit(ev, new Error(`port is ${reason}`));
13935
13971
  }
13936
13972
  }
@@ -13979,7 +14015,7 @@ class channel_MessageChannelStateMachine {
13979
14015
  this.dispatchSignal(name, data);
13980
14016
  }
13981
14017
  catch (e) {
13982
- channel_logger.error(`[${this.constructor.name}] Unable to dispatch signal (${name}): ${e}. ${this.stateInfo(remoteState)}`);
14018
+ channel_logger.error `[${this.constructor.name}] Unable to dispatch signal (${name}): ${e}. ${this.stateInfo(remoteState)}`;
13983
14019
  throw e;
13984
14020
  }
13985
14021
  });
@@ -13988,7 +14024,7 @@ class channel_MessageChannelStateMachine {
13988
14024
  await this.dispatchRequest(name, data, msg);
13989
14025
  }
13990
14026
  catch (e) {
13991
- channel_logger.error(`[${this.constructor.name}] Unable to dispatch request (${name}): ${e}. ${this.stateInfo(remoteState)}`);
14027
+ channel_logger.error `[${this.constructor.name}] Unable to dispatch request (${name}): ${e}. ${this.stateInfo(remoteState)}`;
13992
14028
  throw e;
13993
14029
  }
13994
14030
  });
@@ -14074,7 +14110,7 @@ class channel_MessageChannelStateMachine {
14074
14110
  this.machine.transition(res.transitionTo.state, res.transitionTo.data);
14075
14111
  }
14076
14112
  if (didStateChangeInMeantime) {
14077
- channel_logger.warn(`Ignoring obsolete response for an old request: "${name}"`);
14113
+ channel_logger.warn `Ignoring obsolete response for an old request: "${name}"`;
14078
14114
  return;
14079
14115
  }
14080
14116
  return this.port.respond(prevState.stateName, msg, res.response);
@@ -14090,7 +14126,7 @@ class channel_MessageChannelStateMachine {
14090
14126
  }
14091
14127
  }
14092
14128
  transitionTo() {
14093
- channel_logger.trace(`[${this.machine.name}] transitioned to ${this.currentState()}`);
14129
+ channel_logger.trace `[${this.machine.name}] transitioned to ${this.currentState()}`;
14094
14130
  return this;
14095
14131
  }
14096
14132
  /**
@@ -14110,7 +14146,7 @@ class channel_MessageChannelStateMachine {
14110
14146
  await promise;
14111
14147
  }
14112
14148
  catch (e) {
14113
- channel_logger.error(JSON.stringify(e));
14149
+ channel_logger.error `${e}`;
14114
14150
  }
14115
14151
  return new channel_MessageChannelStateMachine(machine, port);
14116
14152
  }
@@ -14313,7 +14349,7 @@ class State {
14313
14349
  * actions.
14314
14350
  */
14315
14351
  onActivation(data) {
14316
- state_logger.trace(`[${this.constructor.name}] Changing state to: ${this}`);
14352
+ state_logger.trace `[${this.constructor.name}] Changing state to: ${this}`;
14317
14353
  this.data = data;
14318
14354
  }
14319
14355
  /**
@@ -16024,12 +16060,14 @@ class WriteablePage extends MemoryPage {
16024
16060
 
16025
16061
 
16026
16062
 
16063
+
16064
+
16027
16065
  var AccessType;
16028
16066
  (function (AccessType) {
16029
16067
  AccessType[AccessType["READ"] = 0] = "READ";
16030
16068
  AccessType[AccessType["WRITE"] = 1] = "WRITE";
16031
16069
  })(AccessType || (AccessType = {}));
16032
- // const logger = Logger.new(import.meta.filename, "pvm:mem");
16070
+ const memory_logger = Logger.new(import.meta.filename, "pvm:mem");
16033
16071
  class Memory {
16034
16072
  sbrkIndex;
16035
16073
  virtualSbrkIndex;
@@ -16060,7 +16098,7 @@ class Memory {
16060
16098
  if (bytes.length === 0) {
16061
16099
  return result_Result.ok(result_OK);
16062
16100
  }
16063
- // logger.insane(`MEM[${address}] <- ${BytesBlob.blobFrom(bytes)}`);
16101
+ memory_logger.insane `MEM[${address}] <- ${bytes_BytesBlob.blobFrom(bytes)}`;
16064
16102
  const pagesResult = this.getPages(address, bytes.length, AccessType.WRITE);
16065
16103
  if (pagesResult.isError) {
16066
16104
  return result_Result.error(pagesResult.error);
@@ -16127,7 +16165,7 @@ class Memory {
16127
16165
  currentPosition += bytesToRead;
16128
16166
  bytesLeft -= bytesToRead;
16129
16167
  }
16130
- // logger.insane(`MEM[${startAddress}] => ${BytesBlob.blobFrom(result)}`);
16168
+ memory_logger.insane `MEM[${startAddress}] => ${bytes_BytesBlob.blobFrom(result)}`;
16131
16169
  return result_Result.ok(result_OK);
16132
16170
  }
16133
16171
  sbrk(length) {
@@ -18057,7 +18095,7 @@ class ProgramDecoder {
18057
18095
  return result_Result.ok(new ProgramDecoder(program));
18058
18096
  }
18059
18097
  catch (e) {
18060
- program_decoder_logger.error(`Invalid program: ${e}`);
18098
+ program_decoder_logger.error `Invalid program: ${e}`;
18061
18099
  return result_Result.error(ProgramDecoderError.InvalidProgramError);
18062
18100
  }
18063
18101
  }
@@ -18223,7 +18261,7 @@ class Interpreter {
18223
18261
  const argsType = instructionArgumentTypeMap[currentInstruction] ?? ArgumentType.NO_ARGUMENTS;
18224
18262
  const argsResult = this.argsDecodingResults[argsType];
18225
18263
  this.argsDecoder.fillArgs(this.pc, argsResult);
18226
- interpreter_logger.insane(`[PC: ${this.pc}] ${Instruction[currentInstruction]}`);
18264
+ interpreter_logger.insane `[PC: ${this.pc}] ${Instruction[currentInstruction]}`;
18227
18265
  if (!isValidInstruction) {
18228
18266
  this.instructionResult.status = pvm_interpreter_result_Result.PANIC;
18229
18267
  }
@@ -18295,7 +18333,7 @@ class Interpreter {
18295
18333
  this.status = status_Status.HOST;
18296
18334
  break;
18297
18335
  }
18298
- interpreter_logger.insane(`[PC: ${this.pc}] Status: ${pvm_interpreter_result_Result[this.instructionResult.status]}`);
18336
+ interpreter_logger.insane `[PC: ${this.pc}] Status: ${pvm_interpreter_result_Result[this.instructionResult.status]}`;
18299
18337
  return this.status;
18300
18338
  }
18301
18339
  this.pc = this.instructionResult.nextPc;
@@ -18542,7 +18580,7 @@ class host_calls_manager_HostCallsManager {
18542
18580
  return `r${idx}=${value} (0x${value.toString(16)})`;
18543
18581
  })
18544
18582
  .join(", ");
18545
- host_calls_manager_logger.insane(`[${currentServiceId}] ${context} ${name}${requested}. Gas: ${gas}. Regs: ${registerValues}.`);
18583
+ host_calls_manager_logger.insane `[${currentServiceId}] ${context} ${name}${requested}. Gas: ${gas}. Regs: ${registerValues}.`;
18546
18584
  }
18547
18585
  }
18548
18586
  class NoopMissing {
@@ -20925,7 +20963,7 @@ class AccumulateExternalities {
20925
20963
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/362802362d02?v=0.6.7 */
20926
20964
  const validatorsManager = this.updatedState.getPrivilegedServices().validatorsManager;
20927
20965
  if (validatorsManager !== this.currentServiceId) {
20928
- accumulate_externalities_logger.trace(`Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${validatorsManager}) and cannot update validators data. Ignoring`);
20966
+ accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not a validators manager. (expected: ${validatorsManager}) and cannot update validators data. Ignoring`;
20929
20967
  return result_Result.error(UnprivilegedError);
20930
20968
  }
20931
20969
  this.updatedState.stateUpdate.validatorsData = validatorsData;
@@ -20940,11 +20978,11 @@ class AccumulateExternalities {
20940
20978
  // NOTE `coreIndex` is already verified in the HC, so this is infallible.
20941
20979
  const currentAuthManager = this.updatedState.getPrivilegedServices().authManager[coreIndex];
20942
20980
  if (currentAuthManager !== this.currentServiceId) {
20943
- accumulate_externalities_logger.trace(`Current service id (${this.currentServiceId}) is not an auth manager of core ${coreIndex} (expected: ${currentAuthManager}) and cannot update authorization queue. Ignoring`);
20981
+ accumulate_externalities_logger.trace `Current service id (${this.currentServiceId}) is not an auth manager of core ${coreIndex} (expected: ${currentAuthManager}) and cannot update authorization queue. Ignoring`;
20944
20982
  return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
20945
20983
  }
20946
20984
  if (authManager === null && Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
20947
- accumulate_externalities_logger.trace("The new auth manager is not a valid service id. Ignoring");
20985
+ accumulate_externalities_logger.trace `The new auth manager is not a valid service id. Ignoring`;
20948
20986
  return result_Result.error(UpdatePrivilegesError.InvalidServiceId);
20949
20987
  }
20950
20988
  this.updatedState.stateUpdate.authorizationQueues.set(coreIndex, authQueue);
@@ -21825,7 +21863,7 @@ class Assign {
21825
21863
  const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
21826
21864
  // error while reading the memory.
21827
21865
  if (memoryReadResult.isError) {
21828
- logger_logger.trace("ASSIGN() <- PANIC");
21866
+ logger_logger.trace `ASSIGN() <- PANIC`;
21829
21867
  return PvmExecution.Panic;
21830
21868
  }
21831
21869
  if (maybeCoreIndex >= this.chainSpec.coresCount) {
@@ -21840,18 +21878,18 @@ class Assign {
21840
21878
  const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, authManager);
21841
21879
  if (result.isOk) {
21842
21880
  regs.set(IN_OUT_REG, HostCallResult.OK);
21843
- logger_logger.trace(`ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`);
21881
+ logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
21844
21882
  return;
21845
21883
  }
21846
21884
  const e = result.error;
21847
21885
  if (e === UpdatePrivilegesError.UnprivilegedService) {
21848
21886
  regs.set(IN_OUT_REG, HostCallResult.HUH);
21849
- logger_logger.trace(`ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`);
21887
+ logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
21850
21888
  return;
21851
21889
  }
21852
21890
  if (e === UpdatePrivilegesError.InvalidServiceId) {
21853
21891
  regs.set(IN_OUT_REG, HostCallResult.WHO);
21854
- logger_logger.trace(`ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`);
21892
+ logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
21855
21893
  return;
21856
21894
  }
21857
21895
  debug_assertNever(e);
@@ -21917,7 +21955,7 @@ class Bless {
21917
21955
  decoder.resetTo(0);
21918
21956
  const memoryReadResult = memory.loadInto(result, memIndex);
21919
21957
  if (memoryReadResult.isError) {
21920
- logger_logger.trace(`BLESS(${manager}, ${validator}) <- PANIC`);
21958
+ logger_logger.trace `BLESS(${manager}, ${validator}) <- PANIC`;
21921
21959
  return PvmExecution.Panic;
21922
21960
  }
21923
21961
  const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
@@ -21930,24 +21968,24 @@ class Bless {
21930
21968
  const authorizersDecoder = decoder_Decoder.fromBlob(res);
21931
21969
  const memoryReadResult = memory.loadInto(res, authorization);
21932
21970
  if (memoryReadResult.isError) {
21933
- logger_logger.trace(`BLESS(${manager}, ${validator}, ${autoAccumulateEntries}) <- PANIC`);
21971
+ logger_logger.trace `BLESS(${manager}, ${validator}, ${autoAccumulateEntries}) <- PANIC`;
21934
21972
  return PvmExecution.Panic;
21935
21973
  }
21936
21974
  const authorizers = tryAsPerCore(authorizersDecoder.sequenceFixLen(descriptors_codec.u32.asOpaque(), this.chainSpec.coresCount), this.chainSpec);
21937
21975
  const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, validator, autoAccumulateEntries);
21938
21976
  if (updateResult.isOk) {
21939
- logger_logger.trace(`BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- OK`);
21977
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- OK`;
21940
21978
  regs.set(bless_IN_OUT_REG, HostCallResult.OK);
21941
21979
  return;
21942
21980
  }
21943
21981
  const e = updateResult.error;
21944
21982
  if (e === UpdatePrivilegesError.UnprivilegedService) {
21945
- logger_logger.trace(`BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- HUH`);
21983
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- HUH`;
21946
21984
  regs.set(bless_IN_OUT_REG, HostCallResult.HUH);
21947
21985
  return;
21948
21986
  }
21949
21987
  if (e === UpdatePrivilegesError.InvalidServiceId) {
21950
- logger_logger.trace(`BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- WHO`);
21988
+ logger_logger.trace `BLESS(${manager}, ${authorizers}, ${validator}, ${autoAccumulateEntries}) <- WHO`;
21951
21989
  regs.set(bless_IN_OUT_REG, HostCallResult.WHO);
21952
21990
  return;
21953
21991
  }
@@ -21977,7 +22015,7 @@ class GasHostCall {
21977
22015
  }
21978
22016
  execute(gas, regs) {
21979
22017
  const gasValue = gas.get();
21980
- logger_logger.trace(`GAS <- ${gasValue}`);
22018
+ logger_logger.trace `GAS <- ${gasValue}`;
21981
22019
  regs.set(7, numbers_tryAsU64(gasValue));
21982
22020
  return Promise.resolve(undefined);
21983
22021
  }
@@ -22009,7 +22047,7 @@ class Checkpoint {
22009
22047
  async execute(gas, regs) {
22010
22048
  await this.gasHostCall.execute(gas, regs);
22011
22049
  this.partialState.checkpoint();
22012
- logger_logger.trace("CHECKPOINT()");
22050
+ logger_logger.trace `CHECKPOINT()`;
22013
22051
  return;
22014
22052
  }
22015
22053
  }
@@ -22048,18 +22086,18 @@ class Designate {
22048
22086
  const memoryReadResult = memory.loadInto(res, validatorsStart);
22049
22087
  // error while reading the memory.
22050
22088
  if (memoryReadResult.isError) {
22051
- logger_logger.trace("DESIGNATE() <- PANIC");
22089
+ logger_logger.trace `DESIGNATE() <- PANIC`;
22052
22090
  return PvmExecution.Panic;
22053
22091
  }
22054
22092
  const decoder = decoder_Decoder.fromBlob(res);
22055
22093
  const validatorsData = decoder.sequenceFixLen(ValidatorData.Codec, this.chainSpec.validatorsCount);
22056
22094
  const result = this.partialState.updateValidatorsData(tryAsPerValidator(validatorsData, this.chainSpec));
22057
22095
  if (result.isError) {
22058
- logger_logger.trace(`DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- HUH`);
22096
+ logger_logger.trace `DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- HUH`;
22059
22097
  regs.set(designate_IN_OUT_REG, HostCallResult.HUH);
22060
22098
  }
22061
22099
  else {
22062
- logger_logger.trace(`DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- OK`);
22100
+ logger_logger.trace `DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- OK`;
22063
22101
  regs.set(designate_IN_OUT_REG, HostCallResult.OK);
22064
22102
  }
22065
22103
  }
@@ -22100,17 +22138,17 @@ class Eject {
22100
22138
  const previousCodeHash = bytes_Bytes.zero(hash_HASH_SIZE).asOpaque();
22101
22139
  const memoryReadResult = memory.loadInto(previousCodeHash.raw, preimageHashStart);
22102
22140
  if (memoryReadResult.isError) {
22103
- logger_logger.trace(`EJECT(${serviceId}) <- PANIC`);
22141
+ logger_logger.trace `EJECT(${serviceId}) <- PANIC`;
22104
22142
  return PvmExecution.Panic;
22105
22143
  }
22106
22144
  // cannot eject self
22107
22145
  if (serviceId === this.currentServiceId) {
22108
22146
  regs.set(eject_IN_OUT_REG, HostCallResult.WHO);
22109
- logger_logger.trace(`EJECT(${serviceId}, ${previousCodeHash}) <- WHO`);
22147
+ logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- WHO`;
22110
22148
  return;
22111
22149
  }
22112
22150
  const result = this.partialState.eject(serviceId, previousCodeHash);
22113
- logger_logger.trace(`EJECT(${serviceId}, ${previousCodeHash}) <- ${resultToString(result)}`);
22151
+ logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- ${resultToString(result)}`;
22114
22152
  // All good!
22115
22153
  if (result.isOk) {
22116
22154
  regs.set(eject_IN_OUT_REG, HostCallResult.OK);
@@ -22162,11 +22200,11 @@ class Forget {
22162
22200
  const memoryReadResult = memory.loadInto(hash.raw, hashStart);
22163
22201
  // error while reading the memory.
22164
22202
  if (memoryReadResult.isError) {
22165
- logger_logger.trace(`FORGET(${hash}, ${length}) <- PANIC`);
22203
+ logger_logger.trace `FORGET(${hash}, ${length}) <- PANIC`;
22166
22204
  return PvmExecution.Panic;
22167
22205
  }
22168
22206
  const result = this.partialState.forgetPreimage(hash.asOpaque(), length);
22169
- logger_logger.trace(`FORGET(${hash}, ${length}) <- ${resultToString(result)}`);
22207
+ logger_logger.trace `FORGET(${hash}, ${length}) <- ${resultToString(result)}`;
22170
22208
  if (result.isOk) {
22171
22209
  regs.set(forget_IN_OUT_REG, HostCallResult.OK);
22172
22210
  }
@@ -22219,11 +22257,11 @@ class New {
22219
22257
  const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
22220
22258
  // error while reading the memory.
22221
22259
  if (memoryReadResult.isError) {
22222
- logger_logger.trace(`NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- PANIC`);
22260
+ logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- PANIC`;
22223
22261
  return PvmExecution.Panic;
22224
22262
  }
22225
22263
  const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage);
22226
- logger_logger.trace(`NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- ${resultToString(assignedId)}`);
22264
+ logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}) <- ${resultToString(assignedId)}`;
22227
22265
  if (assignedId.isOk) {
22228
22266
  regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
22229
22267
  return;
@@ -22278,11 +22316,11 @@ class Provide {
22278
22316
  const preimage = bytes_BytesBlob.blobFrom(new Uint8Array(length));
22279
22317
  const memoryReadResult = memory.loadInto(preimage.raw, preimageStart);
22280
22318
  if (memoryReadResult.isError) {
22281
- logger_logger.trace(`PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- PANIC`);
22319
+ logger_logger.trace `PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- PANIC`;
22282
22320
  return PvmExecution.Panic;
22283
22321
  }
22284
22322
  const result = this.partialState.providePreimage(serviceId, preimage);
22285
- logger_logger.trace(`PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- ${resultToString(result)}`);
22323
+ logger_logger.trace `PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- ${resultToString(result)}`;
22286
22324
  if (result.isOk) {
22287
22325
  regs.set(provide_IN_OUT_REG, HostCallResult.OK);
22288
22326
  return;
@@ -22336,11 +22374,11 @@ class Query {
22336
22374
  const memoryReadResult = memory.loadInto(hash.raw, hashStart);
22337
22375
  // error while reading the memory.
22338
22376
  if (memoryReadResult.isError) {
22339
- logger_logger.trace(`QUERY(${hash}, ${length}) <- PANIC`);
22377
+ logger_logger.trace `QUERY(${hash}, ${length}) <- PANIC`;
22340
22378
  return PvmExecution.Panic;
22341
22379
  }
22342
22380
  const result = this.partialState.checkPreimageStatus(hash.asOpaque(), length);
22343
- logger_logger.trace(`QUERY(${hash}, ${length}) <- ${result}`);
22381
+ logger_logger.trace `QUERY(${hash}, ${length}) <- ${result}`;
22344
22382
  const zero = numbers_tryAsU64(0n);
22345
22383
  if (result === null) {
22346
22384
  regs.set(IN_OUT_REG_1, HostCallResult.NONE);
@@ -22401,11 +22439,11 @@ class Solicit {
22401
22439
  const hash = bytes_Bytes.zero(hash_HASH_SIZE);
22402
22440
  const memoryReadResult = memory.loadInto(hash.raw, hashStart);
22403
22441
  if (memoryReadResult.isError) {
22404
- logger_logger.trace(`SOLICIT(${hash}, ${length}) <- PANIC`);
22442
+ logger_logger.trace `SOLICIT(${hash}, ${length}) <- PANIC`;
22405
22443
  return PvmExecution.Panic;
22406
22444
  }
22407
22445
  const result = this.partialState.requestPreimage(hash.asOpaque(), length);
22408
- logger_logger.trace(`SOLICIT(${hash}, ${length}) <- ${resultToString(result)}`);
22446
+ logger_logger.trace `SOLICIT(${hash}, ${length}) <- ${resultToString(result)}`;
22409
22447
  if (result.isOk) {
22410
22448
  regs.set(solicit_IN_OUT_REG, HostCallResult.OK);
22411
22449
  return;
@@ -22477,11 +22515,11 @@ class Transfer {
22477
22515
  const memoryReadResult = memory.loadInto(memo.raw, memoStart);
22478
22516
  // page fault while reading the memory.
22479
22517
  if (memoryReadResult.isError) {
22480
- logger_logger.trace(`TRANSFER(${destination}, ${amount}, ${onTransferGas}, ${memo}) <- PANIC`);
22518
+ logger_logger.trace `TRANSFER(${destination}, ${amount}, ${onTransferGas}, ${memo}) <- PANIC`;
22481
22519
  return PvmExecution.Panic;
22482
22520
  }
22483
22521
  const transferResult = this.partialState.transfer(destination, amount, onTransferGas, memo);
22484
- logger_logger.trace(`TRANSFER(${destination}, ${amount}, ${onTransferGas}, ${memo}) <- ${resultToString(transferResult)}`);
22522
+ logger_logger.trace `TRANSFER(${destination}, ${amount}, ${onTransferGas}, ${memo}) <- ${resultToString(transferResult)}`;
22485
22523
  // All good!
22486
22524
  if (transferResult.isOk) {
22487
22525
  regs.set(transfer_IN_OUT_REG, HostCallResult.OK);
@@ -22540,11 +22578,11 @@ class Upgrade {
22540
22578
  const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
22541
22579
  const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
22542
22580
  if (memoryReadResult.isError) {
22543
- logger_logger.trace(`UPGRADE(${codeHash}, ${gas}, ${allowance}) <- PANIC`);
22581
+ logger_logger.trace `UPGRADE(${codeHash}, ${gas}, ${allowance}) <- PANIC`;
22544
22582
  return PvmExecution.Panic;
22545
22583
  }
22546
22584
  this.partialState.upgradeService(codeHash.asOpaque(), gas, allowance);
22547
- logger_logger.trace(`UPGRADE(${codeHash}, ${gas}, ${allowance})`);
22585
+ logger_logger.trace `UPGRADE(${codeHash}, ${gas}, ${allowance})`;
22548
22586
  regs.set(upgrade_IN_OUT_REG, HostCallResult.OK);
22549
22587
  }
22550
22588
  }
@@ -22578,11 +22616,11 @@ class Yield {
22578
22616
  const hash = bytes_Bytes.zero(hash_HASH_SIZE);
22579
22617
  const memoryReadResult = memory.loadInto(hash.raw, hashStart);
22580
22618
  if (memoryReadResult.isError) {
22581
- logger_logger.trace("YIELD() <- PANIC");
22619
+ logger_logger.trace `YIELD() <- PANIC`;
22582
22620
  return PvmExecution.Panic;
22583
22621
  }
22584
22622
  this.partialState.yield(hash);
22585
- logger_logger.trace(`YIELD(${hash})`);
22623
+ logger_logger.trace `YIELD(${hash})`;
22586
22624
  regs.set(yield_IN_OUT_REG, HostCallResult.OK);
22587
22625
  }
22588
22626
  }
@@ -22624,10 +22662,10 @@ class Fetch {
22624
22662
  const chunk = value === null ? new Uint8Array() : value.raw.subarray(Number(offset), Number(offset + length));
22625
22663
  const storeResult = memory.storeFrom(output, chunk);
22626
22664
  if (storeResult.isError) {
22627
- logger_logger.trace(`FETCH(${kind}) <- PANIC`);
22665
+ logger_logger.trace `FETCH(${kind}) <- PANIC`;
22628
22666
  return PvmExecution.Panic;
22629
22667
  }
22630
- logger_logger.trace(`FETCH(${kind}) <- ${value?.toStringTruncated()}`);
22668
+ logger_logger.trace `FETCH(${kind}) <- ${value?.toStringTruncated()}`;
22631
22669
  // write result
22632
22670
  regs.set(fetch_IN_OUT_REG, value === null ? HostCallResult.NONE : valueLength);
22633
22671
  }
@@ -22786,10 +22824,10 @@ class Info {
22786
22824
  const chunk = encodedInfo.raw.subarray(Number(offset), Number(offset + length));
22787
22825
  const writeResult = memory.storeFrom(outputStart, chunk);
22788
22826
  if (writeResult.isError) {
22789
- logger_logger.trace(`INFO(${serviceId}) <- PANIC`);
22827
+ logger_logger.trace `INFO(${serviceId}) <- PANIC`;
22790
22828
  return PvmExecution.Panic;
22791
22829
  }
22792
- logger_logger.trace(`INFO(${serviceId}) <- ${bytes_BytesBlob.blobFrom(chunk)}`);
22830
+ logger_logger.trace `INFO(${serviceId}) <- ${bytes_BytesBlob.blobFrom(chunk)}`;
22793
22831
  if (accountInfo === null) {
22794
22832
  regs.set(info_IN_OUT_REG, HostCallResult.NONE);
22795
22833
  return;
@@ -22850,7 +22888,7 @@ class LogHostCall {
22850
22888
  memory.loadInto(target, targetStart);
22851
22889
  }
22852
22890
  memory.loadInto(message, msgStart);
22853
- logger_logger.trace(`SERVICE [${this.currentServiceId}] [${lvl}] ${decoder.decode(target)} ${decoder.decode(message)}`);
22891
+ logger_logger.trace `SERVICE [${this.currentServiceId}] [${lvl}] ${decoder.decode(target)} ${decoder.decode(message)}`;
22854
22892
  return Promise.resolve(undefined);
22855
22893
  }
22856
22894
  }
@@ -22890,12 +22928,12 @@ class Lookup {
22890
22928
  const preImageHash = bytes_Bytes.zero(hash_HASH_SIZE);
22891
22929
  const memoryReadResult = memory.loadInto(preImageHash.raw, hashAddress);
22892
22930
  if (memoryReadResult.isError) {
22893
- logger_logger.trace(`LOOKUP(${serviceId}, ${preImageHash}) <- PANIC`);
22931
+ logger_logger.trace `LOOKUP(${serviceId}, ${preImageHash}) <- PANIC`;
22894
22932
  return PvmExecution.Panic;
22895
22933
  }
22896
22934
  // v
22897
22935
  const preImage = this.account.lookup(serviceId, preImageHash);
22898
- logger_logger.trace(`LOOKUP(${serviceId}, ${preImageHash}) <- ${preImage?.toStringTruncated()}...`);
22936
+ logger_logger.trace `LOOKUP(${serviceId}, ${preImageHash}) <- ${preImage?.toStringTruncated()}...`;
22899
22937
  const preImageLength = preImage === null ? numbers_tryAsU64(0) : numbers_tryAsU64(preImage.raw.length);
22900
22938
  const preimageBlobOffset = regs.get(10);
22901
22939
  const lengthToWrite = regs.get(11);
@@ -22957,7 +22995,7 @@ class Read {
22957
22995
  const rawKey = bytes_BytesBlob.blobFrom(new Uint8Array(storageKeyLengthClamped));
22958
22996
  const memoryReadResult = memory.loadInto(rawKey.raw, storageKeyStartAddress);
22959
22997
  if (memoryReadResult.isError) {
22960
- logger_logger.trace(`READ(${serviceId}, ${rawKey}) <- PANIC`);
22998
+ logger_logger.trace `READ(${serviceId}, ${rawKey}) <- PANIC`;
22961
22999
  return PvmExecution.Panic;
22962
23000
  }
22963
23001
  // v
@@ -22975,15 +23013,15 @@ class Read {
22975
23013
  const chunk = value === null ? new Uint8Array(0) : value.raw.subarray(Number(offset), Number(offset + blobLength));
22976
23014
  const memoryWriteResult = memory.storeFrom(destinationAddress, chunk);
22977
23015
  if (memoryWriteResult.isError) {
22978
- logger_logger.trace(`READ(${serviceId}, ${rawKey}) <- PANIC`);
23016
+ logger_logger.trace `READ(${serviceId}, ${rawKey}) <- PANIC`;
22979
23017
  return PvmExecution.Panic;
22980
23018
  }
22981
23019
  if (value === null) {
22982
- logger_logger.trace(`READ(${serviceId}, ${rawKey}) <- NONE`);
23020
+ logger_logger.trace `READ(${serviceId}, ${rawKey}) <- NONE`;
22983
23021
  regs.set(read_IN_OUT_REG, HostCallResult.NONE);
22984
23022
  return;
22985
23023
  }
22986
- logger_logger.trace(`READ(${serviceId}, ${rawKey}) <- ${bytes_BytesBlob.blobFrom(chunk).toStringTruncated()}`);
23024
+ logger_logger.trace `READ(${serviceId}, ${rawKey}) <- ${bytes_BytesBlob.blobFrom(chunk).toStringTruncated()}`;
22987
23025
  regs.set(read_IN_OUT_REG, valueLength);
22988
23026
  }
22989
23027
  }
@@ -23026,7 +23064,7 @@ class Write {
23026
23064
  const rawStorageKey = new Uint8Array(storageKeyLengthClamped);
23027
23065
  const keyLoadingResult = memory.loadInto(rawStorageKey, storageKeyStartAddress);
23028
23066
  if (keyLoadingResult.isError) {
23029
- logger_logger.trace("WRITE() <- PANIC");
23067
+ logger_logger.trace `WRITE() <- PANIC`;
23030
23068
  return PvmExecution.Panic;
23031
23069
  }
23032
23070
  // k
@@ -23036,14 +23074,14 @@ class Write {
23036
23074
  const valueLoadingResult = memory.loadInto(value, valueStart);
23037
23075
  // Note [MaSo] this is ok to return bcs if valueLength is 0, then this panic won't happen
23038
23076
  if (valueLoadingResult.isError) {
23039
- logger_logger.trace(`WRITE(${storageKey})}) <- PANIC`);
23077
+ logger_logger.trace `WRITE(${storageKey}) <- PANIC`;
23040
23078
  return PvmExecution.Panic;
23041
23079
  }
23042
23080
  /** https://graypaper.fluffylabs.dev/#/9a08063/33af0133b201?v=0.6.6 */
23043
23081
  const maybeValue = valueLength === 0n ? null : bytes_BytesBlob.blobFrom(value);
23044
23082
  // a
23045
23083
  const result = this.account.write(storageKey, maybeValue);
23046
- logger_logger.trace(`WRITE(${storageKey}, ${maybeValue?.toStringTruncated()}) <- ${resultToString(result)}`);
23084
+ logger_logger.trace `WRITE(${storageKey}, ${maybeValue?.toStringTruncated()}) <- ${resultToString(result)}`;
23047
23085
  if (result.isError) {
23048
23086
  regs.set(write_IN_OUT_REG, HostCallResult.FULL);
23049
23087
  return;
@@ -23235,18 +23273,18 @@ class Accumulate {
23235
23273
  async pvmAccumulateInvocation(slot, serviceId, operands, gas, entropy, inputStateUpdate) {
23236
23274
  const service = this.state.getService(serviceId);
23237
23275
  if (service === null) {
23238
- accumulate_logger.log(`Service with id ${serviceId} not found.`);
23276
+ accumulate_logger.log `Service with id ${serviceId} not found.`;
23239
23277
  return result_Result.error(PvmInvocationError.NoService);
23240
23278
  }
23241
23279
  const codeHash = service.getInfo().codeHash;
23242
23280
  // TODO [ToDr] Should we check that the preimage is still available?
23243
23281
  const code = service.getPreimage(codeHash.asOpaque());
23244
23282
  if (code === null) {
23245
- accumulate_logger.log(`Code with hash ${codeHash} not found for service ${serviceId}.`);
23283
+ accumulate_logger.log `Code with hash ${codeHash} not found for service ${serviceId}.`;
23246
23284
  return result_Result.error(PvmInvocationError.NoPreimage);
23247
23285
  }
23248
23286
  if (code.length > W_C) {
23249
- accumulate_logger.log(`Code with hash ${codeHash} is too long for service ${serviceId}.`);
23287
+ accumulate_logger.log `Code with hash ${codeHash} is too long for service ${serviceId}.`;
23250
23288
  return result_Result.error(PvmInvocationError.PreimageTooLong);
23251
23289
  }
23252
23290
  const nextServiceId = generateNextServiceId({ serviceId, entropy, timeslot: slot }, this.chainSpec);
@@ -23268,10 +23306,10 @@ class Accumulate {
23268
23306
  if (result.hasStatus()) {
23269
23307
  const status = result.status;
23270
23308
  if (status === status_Status.OOG || status === status_Status.PANIC) {
23271
- accumulate_logger.trace(`[${serviceId}] accumulate finished with ${status_Status[status]} reverting to checkpoint.`);
23309
+ accumulate_logger.trace `[${serviceId}] accumulate finished with ${status_Status[status]} reverting to checkpoint.`;
23272
23310
  return result_Result.ok({ stateUpdate: checkpoint, consumedGas: common_tryAsServiceGas(result.consumedGas) });
23273
23311
  }
23274
- accumulate_logger.trace(`[${serviceId}] accumulate finished with ${status_Status[status]}`);
23312
+ accumulate_logger.trace `[${serviceId}] accumulate finished with ${status_Status[status]}`;
23275
23313
  }
23276
23314
  /**
23277
23315
  * PVM invocation returned a hash so we override whatever `yield` host call
@@ -23296,14 +23334,14 @@ class Accumulate {
23296
23334
  * https://graypaper.fluffylabs.dev/#/7e6ff6a/18d70118d701?v=0.6.7
23297
23335
  */
23298
23336
  async accumulateSingleService(serviceId, operands, gasCost, slot, entropy, inputStateUpdate) {
23299
- accumulate_logger.log(`Accumulating service ${serviceId}, items: ${operands.length} at slot: ${slot}.`);
23337
+ accumulate_logger.log `Accumulating service ${serviceId}, items: ${operands.length} at slot: ${slot}.`;
23300
23338
  const result = await this.pvmAccumulateInvocation(slot, serviceId, operands, gasCost, entropy, inputStateUpdate);
23301
23339
  if (result.isError) {
23302
23340
  // https://graypaper.fluffylabs.dev/#/7e6ff6a/2fb6012fb601?v=0.6.7
23303
- accumulate_logger.log(`Accumulation failed for ${serviceId}.`);
23341
+ accumulate_logger.log `Accumulation failed for ${serviceId}.`;
23304
23342
  return { stateUpdate: null, consumedGas: 0n };
23305
23343
  }
23306
- accumulate_logger.log(`Accumulation successful for ${serviceId}. Consumed: ${result.ok.consumedGas}`);
23344
+ accumulate_logger.log `Accumulation successful for ${serviceId}. Consumed: ${result.ok.consumedGas}`;
23307
23345
  return result.ok;
23308
23346
  }
23309
23347
  /**
@@ -23365,7 +23403,7 @@ class Accumulate {
23365
23403
  if (Compatibility.is(GpVersion.V0_7_0) && serviceId === currentManager) {
23366
23404
  const newV = currentState.privilegedServices?.validatorsManager;
23367
23405
  if (currentState.privilegedServices !== null && newV !== undefined && serviceIds.includes(newV)) {
23368
- accumulate_logger.info("Entering completely incorrect code that probably reverts validatorsManager change. This is valid in 0.7.0 only and incorrect in 0.7.1+");
23406
+ accumulate_logger.info `Entering completely incorrect code that probably reverts validatorsManager change. This is valid in 0.7.0 only and incorrect in 0.7.1+`;
23369
23407
  // Since serviceIds already contains newV, this service gets accumulated twice.
23370
23408
  // To avoid double-counting, we skip stats and gas cost tracking here.
23371
23409
  // We need this accumulation to get the correct `validatorsManager`
@@ -23548,13 +23586,13 @@ class DeferredTransfers {
23548
23586
  const isCodeCorrect = code !== null && code.length <= W_C;
23549
23587
  if (!hasTransfers || !isCodeCorrect) {
23550
23588
  if (code === null) {
23551
- deferred_transfers_logger.trace(`Skipping ON_TRANSFER execution for service ${serviceId} because code is null`);
23589
+ deferred_transfers_logger.trace `Skipping ON_TRANSFER execution for service ${serviceId} because code is null`;
23552
23590
  }
23553
23591
  else if (!hasTransfers) {
23554
- deferred_transfers_logger.trace(`Skipping ON_TRANSFER execution for service ${serviceId} because there are no transfers`);
23592
+ deferred_transfers_logger.trace `Skipping ON_TRANSFER execution for service ${serviceId} because there are no transfers`;
23555
23593
  }
23556
23594
  else {
23557
- deferred_transfers_logger.trace(`Skipping ON_TRANSFER execution for service ${serviceId} because code is too long`);
23595
+ deferred_transfers_logger.trace `Skipping ON_TRANSFER execution for service ${serviceId} because code is too long`;
23558
23596
  }
23559
23597
  }
23560
23598
  else {
@@ -24182,7 +24220,7 @@ function verifyRefineContexts(minLookupSlot, contexts, recentBlocksPartialUpdate
24182
24220
  headerChain.isAncestor(context.lookupAnchorSlot, context.lookupAnchor, context.anchor);
24183
24221
  if (!isInChain) {
24184
24222
  if (process.env.SKIP_LOOKUP_ANCHOR_CHECK !== undefined) {
24185
- verify_contextual_logger.warn(`Lookup anchor check for ${context.lookupAnchor} would fail, but override is active.`);
24223
+ verify_contextual_logger.warn `Lookup anchor check for ${context.lookupAnchor} would fail, but override is active.`;
24186
24224
  }
24187
24225
  else {
24188
24226
  return result_Result.error(ReportsError.SegmentRootLookupInvalid, `Lookup anchor is not found in chain. Hash: ${context.lookupAnchor} (slot: ${context.lookupAnchorSlot})`);
@@ -25069,7 +25107,7 @@ class OnChain {
25069
25107
  reports: availableReports,
25070
25108
  entropy: entropy[0],
25071
25109
  });
25072
- chain_stf_logger.log(timerAccumulate());
25110
+ chain_stf_logger.log `${timerAccumulate()}`;
25073
25111
  if (accumulateResult.isError) {
25074
25112
  return stfError(StfErrorKind.Accumulate, accumulateResult);
25075
25113
  }
@@ -25200,7 +25238,7 @@ class Importer {
25200
25238
  this.stf = new OnChain(spec, state, blocks, hasher);
25201
25239
  this.state = state;
25202
25240
  this.currentHash = currentBestHeaderHash;
25203
- logger.info(`😎 Best time slot: ${state.timeslot} (header hash: ${currentBestHeaderHash})`);
25241
+ logger.info `😎 Best time slot: ${state.timeslot} (header hash: ${currentBestHeaderHash})`;
25204
25242
  }
25205
25243
  async importBlock(block, omitSealVerification) {
25206
25244
  const timer = measure("importBlock");
@@ -25208,20 +25246,20 @@ class Importer {
25208
25246
  const maybeBestHeader = await this.importBlockInternal(block, omitSealVerification);
25209
25247
  if (maybeBestHeader.isOk) {
25210
25248
  const bestHeader = maybeBestHeader.ok;
25211
- this.logger.info(`🧊 Best block: #${timeSlot} (${bestHeader.hash})`);
25212
- this.logger.log(timer());
25249
+ this.logger.info `🧊 Best block: #${timeSlot} (${bestHeader.hash})`;
25250
+ this.logger.log `${timer()}`;
25213
25251
  return maybeBestHeader;
25214
25252
  }
25215
- this.logger.log(`❌ Rejected block #${timeSlot}: ${resultToString(maybeBestHeader)}`);
25216
- this.logger.log(timer());
25253
+ this.logger.log `❌ Rejected block #${timeSlot}: ${resultToString(maybeBestHeader)}`;
25254
+ this.logger.log `${timer()}`;
25217
25255
  return maybeBestHeader;
25218
25256
  }
25219
25257
  async importBlockInternal(block, omitSealVerification = false) {
25220
25258
  const logger = this.logger;
25221
- logger.log("🧱 Attempting to import a new block");
25259
+ logger.log `🧱 Attempting to import a new block`;
25222
25260
  const timerVerify = measure("import:verify");
25223
25261
  const hash = await this.verifier.verifyBlock(block);
25224
- logger.log(timerVerify());
25262
+ logger.log `${timerVerify()}`;
25225
25263
  if (hash.isError) {
25226
25264
  return importerError(ImporterErrorKind.Verifier, hash);
25227
25265
  }
@@ -25241,10 +25279,10 @@ class Importer {
25241
25279
  }
25242
25280
  const timeSlot = block.header.view().timeSlotIndex.materialize();
25243
25281
  const headerHash = hash.ok;
25244
- logger.log(`🧱 Verified block: Got hash ${headerHash} for block at slot ${timeSlot}.`);
25282
+ logger.log `🧱 Verified block: Got hash ${headerHash} for block at slot ${timeSlot}.`;
25245
25283
  const timerStf = measure("import:stf");
25246
25284
  const res = await this.stf.transition(block, headerHash, omitSealVerification);
25247
- logger.log(timerStf());
25285
+ logger.log `${timerStf()}`;
25248
25286
  if (res.isError) {
25249
25287
  return importerError(ImporterErrorKind.Stf, res);
25250
25288
  }
@@ -25253,7 +25291,7 @@ class Importer {
25253
25291
  const timerState = measure("import:state");
25254
25292
  const updateResult = await this.states.updateAndSetState(headerHash, this.state, update);
25255
25293
  if (updateResult.isError) {
25256
- logger.error(`🧱 Unable to update state: ${resultToString(updateResult)}`);
25294
+ logger.error `🧱 Unable to update state: ${resultToString(updateResult)}`;
25257
25295
  return importerError(ImporterErrorKind.Update, updateResult);
25258
25296
  }
25259
25297
  const newState = this.states.getState(headerHash);
@@ -25264,17 +25302,17 @@ class Importer {
25264
25302
  // the state of a parent block to support forks and create a fresh STF.
25265
25303
  this.state.updateBackend(newState.backend);
25266
25304
  this.currentHash = headerHash;
25267
- logger.log(timerState());
25305
+ logger.log `${timerState()}`;
25268
25306
  // insert new state and the block to DB.
25269
25307
  const timerDb = measure("import:db");
25270
25308
  const writeBlocks = this.blocks.insertBlock(new WithHash(headerHash, block));
25271
25309
  // Computation of the state root may happen asynchronously,
25272
25310
  // but we still need to wait for it before next block can be imported
25273
25311
  const stateRoot = await this.states.getStateRoot(newState);
25274
- logger.log(`🧱 Storing post-state-root for ${headerHash}: ${stateRoot}.`);
25312
+ logger.log `🧱 Storing post-state-root for ${headerHash}: ${stateRoot}.`;
25275
25313
  const writeStateRoot = this.blocks.setPostStateRoot(headerHash, stateRoot);
25276
25314
  await Promise.all([writeBlocks, writeStateRoot]);
25277
- logger.log(timerDb());
25315
+ logger.log `${timerDb()}`;
25278
25316
  // finally update the best block
25279
25317
  await this.blocks.setBestHeaderHash(headerHash);
25280
25318
  return result_Result.ok(new WithHash(headerHash, block.header.view()));
@@ -25376,7 +25414,7 @@ async function spawnWorkerGeneric(bootstrapPath, logger, mainReadyName, mainRead
25376
25414
  const worker = new Worker(bootstrapPath);
25377
25415
  const machine = stateMachineMain(`main->${mainReadyName}`, mainReadyName, mainReadyState);
25378
25416
  const channel = await MessageChannelStateMachine.createAndTransferChannel(machine, worker);
25379
- logger.trace(`[${machine.name}] Worker spawned ${channel.currentState()}`);
25417
+ logger.trace `[${machine.name}] Worker spawned ${channel.currentState()}`;
25380
25418
  return channel;
25381
25419
  }
25382
25420
 
@@ -25489,7 +25527,7 @@ class MainReady extends State {
25489
25527
  if (res instanceof Uint8Array) {
25490
25528
  return bytes_Bytes.fromBlob(res, hash_HASH_SIZE).asOpaque();
25491
25529
  }
25492
- state_machine_logger.error(`Invalid response for getBestStateRootHash. Expected Uint8Array, got: ${res}`);
25530
+ state_machine_logger.error `Invalid response for getBestStateRootHash. Expected Uint8Array, got: ${res}`;
25493
25531
  return bytes_Bytes.zero(hash_HASH_SIZE).asOpaque();
25494
25532
  }
25495
25533
  finish(channel) {
@@ -25537,7 +25575,7 @@ class ImporterReady extends State {
25537
25575
  }
25538
25576
  async getStateEntries(hash) {
25539
25577
  if (this.importer === null) {
25540
- state_machine_logger.error(`${this.constructor.name} importer not initialized yet!`);
25578
+ state_machine_logger.error `${this.constructor.name} importer not initialized yet!`;
25541
25579
  await new Promise((resolve) => {
25542
25580
  this.onImporter.once(resolve);
25543
25581
  });
@@ -25551,7 +25589,7 @@ class ImporterReady extends State {
25551
25589
  response: encoded.raw,
25552
25590
  };
25553
25591
  }
25554
- state_machine_logger.error(`${this.constructor.name} got invalid request type: ${JSON.stringify(hash)}.`);
25592
+ state_machine_logger.error `${this.constructor.name} got invalid request type: ${JSON.stringify(hash)}.`;
25555
25593
  return {
25556
25594
  response: null,
25557
25595
  };
@@ -25571,7 +25609,7 @@ class ImporterReady extends State {
25571
25609
  }
25572
25610
  async importBlock(block) {
25573
25611
  if (this.importer === null) {
25574
- state_machine_logger.error(`${this.constructor.name} importer not initialized yet!`);
25612
+ state_machine_logger.error `${this.constructor.name} importer not initialized yet!`;
25575
25613
  await new Promise((resolve) => {
25576
25614
  this.onImporter.once(resolve);
25577
25615
  });
@@ -25591,8 +25629,8 @@ class ImporterReady extends State {
25591
25629
  }
25592
25630
  }
25593
25631
  catch (e) {
25594
- state_machine_logger.error(`Failed to import block: ${e}`);
25595
- state_machine_logger.error(`${e instanceof Error ? e.stack : ""}`);
25632
+ state_machine_logger.error `Failed to import block: ${e}`;
25633
+ state_machine_logger.error `${e instanceof Error ? e.stack : ""}`;
25596
25634
  response = result_Result.error(`${e}`);
25597
25635
  }
25598
25636
  const encoded = encoder_Encoder.encodeObject(importBlockResultCodec, response);
@@ -25600,7 +25638,7 @@ class ImporterReady extends State {
25600
25638
  response: encoded.raw,
25601
25639
  };
25602
25640
  }
25603
- state_machine_logger.error(`${this.constructor.name} got invalid request type: ${JSON.stringify(block)}.`);
25641
+ state_machine_logger.error `${this.constructor.name} got invalid request type: ${JSON.stringify(block)}.`;
25604
25642
  return {
25605
25643
  response: null,
25606
25644
  };
@@ -25612,7 +25650,7 @@ class ImporterReady extends State {
25612
25650
  this.onBlock.emit(blockView);
25613
25651
  }
25614
25652
  else {
25615
- state_machine_logger.error(`${this.constructor.name} got invalid signal type: ${JSON.stringify(block)}.`);
25653
+ state_machine_logger.error `${this.constructor.name} got invalid signal type: ${JSON.stringify(block)}.`;
25616
25654
  }
25617
25655
  }
25618
25656
  async endWork() {
@@ -25639,7 +25677,7 @@ if (!external_node_worker_threads_namespaceObject.isMainThread) {
25639
25677
  Logger.configureAll(process.env.JAM_LOG ?? "", Level.LOG);
25640
25678
  const machine = importerStateMachine();
25641
25679
  const channel = channel_MessageChannelStateMachine.receiveChannel(machine, external_node_worker_threads_namespaceObject.parentPort);
25642
- channel.then((channel) => main(channel)).catch((e) => importer_logger.error(e));
25680
+ channel.then((channel) => main(channel)).catch((e) => importer_logger.error `${e}`);
25643
25681
  }
25644
25682
  const keccakHasher = KeccakHasher.create();
25645
25683
  async function createImporter(config) {
@@ -25661,7 +25699,7 @@ async function createImporter(config) {
25661
25699
  */
25662
25700
  async function main(channel) {
25663
25701
  const wasmPromise = initAll();
25664
- importer_logger.info(`📥 Importer starting ${channel.currentState()}`);
25702
+ importer_logger.info `📥 Importer starting ${channel.currentState()}`;
25665
25703
  // Await the configuration object
25666
25704
  const ready = await channel.waitForState("ready(importer)");
25667
25705
  let closeDb = async () => { };
@@ -25673,7 +25711,7 @@ async function main(channel) {
25673
25711
  };
25674
25712
  // TODO [ToDr] this is shit, since we have circular dependency.
25675
25713
  worker.setImporter(importer);
25676
- importer_logger.info("📥 Importer waiting for blocks.");
25714
+ importer_logger.info `📥 Importer waiting for blocks.`;
25677
25715
  worker.onBlock.on(async (block) => {
25678
25716
  const res = await importer.importBlock(block, config.omitSealVerification);
25679
25717
  if (res.isOk) {
@@ -25682,7 +25720,7 @@ async function main(channel) {
25682
25720
  });
25683
25721
  await wasmPromise;
25684
25722
  });
25685
- importer_logger.info("📥 Importer finished. Closing channel.");
25723
+ importer_logger.info `📥 Importer finished. Closing channel.`;
25686
25724
  // close the database
25687
25725
  await closeDb();
25688
25726
  // Close the comms to gracefuly close the app.