@typeberry/lib 0.1.1 → 0.1.2-60899f7

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/index.cjs CHANGED
@@ -10,6 +10,7 @@ var GpVersion;
10
10
  GpVersion["V0_6_7"] = "0.6.7";
11
11
  GpVersion["V0_7_0"] = "0.7.0";
12
12
  GpVersion["V0_7_1"] = "0.7.1-preview";
13
+ GpVersion["V0_7_2"] = "0.7.2-preview";
13
14
  })(GpVersion || (GpVersion = {}));
14
15
  var TestSuite;
15
16
  (function (TestSuite) {
@@ -17,29 +18,35 @@ var TestSuite;
17
18
  TestSuite["JAMDUNA"] = "jamduna";
18
19
  })(TestSuite || (TestSuite = {}));
19
20
  const DEFAULT_SUITE = TestSuite.W3F_DAVXY;
20
- const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1];
21
- const env = typeof process === "undefined" ? {} : process.env;
21
+ const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1, GpVersion.V0_7_2];
22
+ const env$1 = typeof process === "undefined" ? {} : process.env;
22
23
  const DEFAULT_VERSION = GpVersion.V0_7_0;
23
- let CURRENT_VERSION = parseCurrentVersion(env.GP_VERSION) ?? DEFAULT_VERSION;
24
- let CURRENT_SUITE = parseCurrentSuite(env.TEST_SUITE) ?? DEFAULT_SUITE;
24
+ let CURRENT_VERSION = parseCurrentVersion(env$1.GP_VERSION) ?? DEFAULT_VERSION;
25
+ let CURRENT_SUITE = parseCurrentSuite(env$1.TEST_SUITE) ?? DEFAULT_SUITE;
25
26
  function parseCurrentVersion(env) {
26
27
  if (env === undefined) {
27
28
  return undefined;
28
29
  }
29
- const version = env;
30
- if (!Object.values(GpVersion).includes(version)) {
31
- throw new Error(`Configured environment variable GP_VERSION is unknown: '${env}'. Use one of: ${ALL_VERSIONS_IN_ORDER}`);
30
+ switch (env) {
31
+ case GpVersion.V0_6_7:
32
+ case GpVersion.V0_7_0:
33
+ case GpVersion.V0_7_1:
34
+ case GpVersion.V0_7_2:
35
+ return env;
36
+ default:
37
+ throw new Error(`Configured environment variable GP_VERSION is unknown: '${env}'. Use one of: ${ALL_VERSIONS_IN_ORDER}`);
32
38
  }
33
- return version;
34
39
  }
35
40
  function parseCurrentSuite(env) {
36
41
  if (env === undefined)
37
42
  return undefined;
38
- const val = env;
39
- if (!Object.values(TestSuite).includes(val)) {
40
- throw new Error(`Configured environment variable TEST_SUITE is unknown: '${env}'. Use one of: ${Object.values(TestSuite)}`);
43
+ switch (env) {
44
+ case TestSuite.W3F_DAVXY:
45
+ case TestSuite.JAMDUNA:
46
+ return env;
47
+ default:
48
+ throw new Error(`Configured environment variable TEST_SUITE is unknown: '${env}'. Use one of: ${Object.values(TestSuite)}`);
41
49
  }
42
- return val;
43
50
  }
44
51
  class Compatibility {
45
52
  static override(version) {
@@ -200,6 +207,33 @@ class WithDebug {
200
207
  }
201
208
  }
202
209
 
210
+ const env = typeof process === "undefined" ? {} : process.env;
211
+ /**
212
+ * The function will produce relative path resolver that is adjusted
213
+ * for package location within the workspace.
214
+ *
215
+ * Example:
216
+ * $ npm start -w @typeberry/jam
217
+ *
218
+ * The above command will run `./bin/jam/index.js`, however we would
219
+ * still want relative paths to be resolved according to top-level workspace
220
+ * directory.
221
+ *
222
+ * So the caller, passes the absolute workspace path as argument and get's
223
+ * a function that can properly resolve relative paths.
224
+ *
225
+ * NOTE: the translation happens only for development build! When
226
+ * we build a single library from our project, we no longer mangle the paths.
227
+ */
228
+ const workspacePathFix = env.NODE_ENV === "development"
229
+ ? (workspacePath) => (p) => {
230
+ if (p.startsWith("/")) {
231
+ return p;
232
+ }
233
+ return `${workspacePath}/${p}`;
234
+ }
235
+ : () => (p) => p;
236
+
203
237
  /**
204
238
  * @fileoverview `Opaque<Type, Token>` constructs a unique type which is a subset of Type with a
205
239
  * specified unique token Token. It means that base type cannot be assigned to unique type by accident.
@@ -552,7 +586,8 @@ var index$s = /*#__PURE__*/Object.freeze({
552
586
  isBrowser: isBrowser,
553
587
  measure: measure,
554
588
  resultToString: resultToString,
555
- seeThrough: seeThrough
589
+ seeThrough: seeThrough,
590
+ workspacePathFix: workspacePathFix
556
591
  });
557
592
 
558
593
  /**
@@ -5922,6 +5957,40 @@ var assurances = /*#__PURE__*/Object.freeze({
5922
5957
  assurancesExtrinsicCodec: assurancesExtrinsicCodec
5923
5958
  });
5924
5959
 
5960
+ /** Attempt to convert a number into `TimeSlot`. */
5961
+ const tryAsTimeSlot = (v) => asOpaqueType(tryAsU32(v));
5962
+ /** Attempt to convert a number into `ValidatorIndex`. */
5963
+ const tryAsValidatorIndex = (v) => asOpaqueType(tryAsU16(v));
5964
+ /** Attempt to convert a number into `ServiceId`. */
5965
+ const tryAsServiceId = (v) => asOpaqueType(tryAsU32(v));
5966
+ const tryAsServiceGas = (v) => asOpaqueType(tryAsU64(v));
5967
+ /** Attempt to convert a number into `CoreIndex`. */
5968
+ const tryAsCoreIndex = (v) => asOpaqueType(tryAsU16(v));
5969
+ /** Attempt to convert a number into `Epoch`. */
5970
+ const tryAsEpoch = (v) => asOpaqueType(tryAsU32(v));
5971
+ function tryAsPerValidator(array, spec) {
5972
+ check `
5973
+ ${array.length === spec.validatorsCount}
5974
+ Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}
5975
+ `;
5976
+ return asKnownSize(array);
5977
+ }
5978
+ const codecPerValidator = (val) => codecWithContext((context) => {
5979
+ return codecKnownSizeArray(val, {
5980
+ fixedLength: context.validatorsCount,
5981
+ });
5982
+ });
5983
+ function tryAsPerEpochBlock(array, spec) {
5984
+ check `
5985
+ ${array.length === spec.epochLength}
5986
+ Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}
5987
+ `;
5988
+ return asKnownSize(array);
5989
+ }
5990
+ const codecPerEpochBlock = (val) => codecWithContext((context) => {
5991
+ return codecKnownSizeArray(val, { fixedLength: context.epochLength });
5992
+ });
5993
+
5925
5994
  /**
5926
5995
  * Proof of signing a contradictory [`Judgement`] of a work report.
5927
5996
  */
@@ -6113,40 +6182,6 @@ var disputes = /*#__PURE__*/Object.freeze({
6113
6182
  Verdict: Verdict
6114
6183
  });
6115
6184
 
6116
- /** Attempt to convert a number into `TimeSlot`. */
6117
- const tryAsTimeSlot = (v) => asOpaqueType(tryAsU32(v));
6118
- /** Attempt to convert a number into `ValidatorIndex`. */
6119
- const tryAsValidatorIndex = (v) => asOpaqueType(tryAsU16(v));
6120
- /** Attempt to convert a number into `ServiceId`. */
6121
- const tryAsServiceId = (v) => asOpaqueType(tryAsU32(v));
6122
- const tryAsServiceGas = (v) => asOpaqueType(tryAsU64(v));
6123
- /** Attempt to convert a number into `CoreIndex`. */
6124
- const tryAsCoreIndex = (v) => asOpaqueType(tryAsU16(v));
6125
- /** Attempt to convert a number into `Epoch`. */
6126
- const tryAsEpoch = (v) => asOpaqueType(tryAsU32(v));
6127
- function tryAsPerValidator(array, spec) {
6128
- check `
6129
- ${array.length === spec.validatorsCount}
6130
- Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}
6131
- `;
6132
- return asKnownSize(array);
6133
- }
6134
- const codecPerValidator = (val) => codecWithContext((context) => {
6135
- return codecKnownSizeArray(val, {
6136
- fixedLength: context.validatorsCount,
6137
- });
6138
- });
6139
- function tryAsPerEpochBlock(array, spec) {
6140
- check `
6141
- ${array.length === spec.epochLength}
6142
- Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}
6143
- `;
6144
- return asKnownSize(array);
6145
- }
6146
- const codecPerEpochBlock = (val) => codecWithContext((context) => {
6147
- return codecKnownSizeArray(val, { fixedLength: context.epochLength });
6148
- });
6149
-
6150
6185
  /**
6151
6186
  * Mapping between work package hash and root hash of it's exports.
6152
6187
  *
@@ -7225,6 +7260,24 @@ class Block extends WithDebug {
7225
7260
  this.extrinsic = extrinsic;
7226
7261
  }
7227
7262
  }
7263
+ function emptyBlock(slot = tryAsTimeSlot(0)) {
7264
+ const header = Header.empty();
7265
+ header.timeSlotIndex = slot;
7266
+ return Block.create({
7267
+ header,
7268
+ extrinsic: Extrinsic.create({
7269
+ tickets: asKnownSize([]),
7270
+ preimages: [],
7271
+ assurances: asKnownSize([]),
7272
+ guarantees: asKnownSize([]),
7273
+ disputes: {
7274
+ verdicts: [],
7275
+ culprits: [],
7276
+ faults: [],
7277
+ },
7278
+ }),
7279
+ });
7280
+ }
7228
7281
 
7229
7282
  var index$j = /*#__PURE__*/Object.freeze({
7230
7283
  __proto__: null,
@@ -7241,6 +7294,7 @@ var index$j = /*#__PURE__*/Object.freeze({
7241
7294
  codecPerValidator: codecPerValidator,
7242
7295
  codecUtils: codec,
7243
7296
  disputes: disputes,
7297
+ emptyBlock: emptyBlock,
7244
7298
  encodeUnsealedHeader: encodeUnsealedHeader,
7245
7299
  guarantees: guarantees,
7246
7300
  headerViewWithHashCodec: headerViewWithHashCodec,
@@ -8012,6 +8066,23 @@ function parseLevel(lvl) {
8012
8066
  }
8013
8067
 
8014
8068
  // biome-ignore-all lint/suspicious/noConsole: logger
8069
+ function print(level, levelAndName, strings, data) {
8070
+ if (level < levelAndName[0]) {
8071
+ return;
8072
+ }
8073
+ const lvlText = Level[level].padEnd(5);
8074
+ const val = strings.map((v, idx) => `${v}${idx < data.length ? data[idx] : ""}`);
8075
+ const msg = `${lvlText} [${levelAndName[1]}] ${val.join("")}`;
8076
+ if (level === Level.WARN) {
8077
+ console.warn(msg);
8078
+ }
8079
+ else if (level === Level.ERROR) {
8080
+ console.error(msg);
8081
+ }
8082
+ else {
8083
+ console.info(msg);
8084
+ }
8085
+ }
8015
8086
  /** An optimized logger that ignores `TRACE`, `DEBUG` and `LOG` messages.
8016
8087
  *
8017
8088
  * Use the `create` method to instantiate the right instance of a more specialized logger.
@@ -8042,109 +8113,91 @@ class ConsoleTransport {
8042
8113
  constructor(options) {
8043
8114
  this.options = options;
8044
8115
  }
8045
- insane(_moduleName, _val) {
8116
+ insane(_levelAndName, _strings, _data) {
8046
8117
  /* no-op */
8047
8118
  }
8048
- trace(_moduleName, _val) {
8119
+ trace(_levelAndName, _strings, _data) {
8049
8120
  /* no-op */
8050
8121
  }
8051
- log(_moduleName, _val) {
8122
+ log(_levelAndName, _strings, _data) {
8052
8123
  /* no-op */
8053
8124
  }
8054
- info(_moduleName, _val) {
8125
+ info(_levelAndName, _strings, _data) {
8055
8126
  /* no-op */
8056
8127
  }
8057
- warn(moduleName, val) {
8058
- this.push(Level.WARN, moduleName, val);
8059
- }
8060
- error(moduleName, val) {
8061
- this.push(Level.ERROR, moduleName, val);
8128
+ warn(levelAndName, strings, data) {
8129
+ print(Level.WARN, levelAndName, strings, data);
8062
8130
  }
8063
- push(level, moduleName, val) {
8064
- const shortModule = moduleName.replace(this.options.workingDir, "");
8065
- const configuredLevel = findLevel(this.options, moduleName);
8066
- const lvlText = Level[level].padEnd(5);
8067
- if (level < configuredLevel) {
8068
- return;
8069
- }
8070
- const msg = `${lvlText} [${shortModule}] ${val}`;
8071
- if (level === Level.WARN) {
8072
- console.warn(msg);
8073
- }
8074
- else if (level === Level.ERROR) {
8075
- console.error(msg);
8076
- }
8077
- else {
8078
- console.info(msg);
8079
- }
8131
+ error(levelAndName, strings, data) {
8132
+ print(Level.ERROR, levelAndName, strings, data);
8080
8133
  }
8081
8134
  }
8082
8135
  /**
8083
8136
  * Insane version of console logger - supports insane level.
8084
8137
  */
8085
8138
  class InsaneConsoleLogger extends ConsoleTransport {
8086
- insane(moduleName, val) {
8087
- this.push(Level.INSANE, moduleName, val);
8139
+ insane(levelAndName, strings, data) {
8140
+ print(Level.INSANE, levelAndName, strings, data);
8088
8141
  }
8089
- trace(moduleName, val) {
8090
- this.push(Level.TRACE, moduleName, val);
8142
+ trace(levelAndName, strings, data) {
8143
+ print(Level.TRACE, levelAndName, strings, data);
8091
8144
  }
8092
- log(moduleName, val) {
8093
- this.push(Level.LOG, moduleName, val);
8145
+ log(levelAndName, strings, data) {
8146
+ print(Level.LOG, levelAndName, strings, data);
8094
8147
  }
8095
- info(moduleName, val) {
8096
- this.push(Level.INFO, moduleName, val);
8148
+ info(levelAndName, strings, data) {
8149
+ print(Level.INFO, levelAndName, strings, data);
8097
8150
  }
8098
8151
  }
8099
8152
  /**
8100
8153
  * A basic version of console logger - printing everything.
8101
8154
  */
8102
8155
  class TraceConsoleTransport extends ConsoleTransport {
8103
- insane(_moduleName, _val) {
8156
+ insane(_levelAndName, _strings, _data) {
8104
8157
  /* no-op */
8105
8158
  }
8106
- trace(moduleName, val) {
8107
- this.push(Level.TRACE, moduleName, val);
8159
+ trace(levelAndName, strings, data) {
8160
+ print(Level.TRACE, levelAndName, strings, data);
8108
8161
  }
8109
- log(moduleName, val) {
8110
- this.push(Level.LOG, moduleName, val);
8162
+ log(levelAndName, strings, data) {
8163
+ print(Level.LOG, levelAndName, strings, data);
8111
8164
  }
8112
- info(moduleName, val) {
8113
- this.push(Level.INFO, moduleName, val);
8165
+ info(levelAndName, strings, data) {
8166
+ print(Level.INFO, levelAndName, strings, data);
8114
8167
  }
8115
8168
  }
8116
8169
  /**
8117
8170
  * An optimized version of the logger - completely ignores `TRACE` level calls.
8118
8171
  */
8119
8172
  class LogConsoleTransport extends ConsoleTransport {
8120
- insane(_moduleName, _val) {
8173
+ insane(_levelAndName, _strings, _data) {
8121
8174
  /* no-op */
8122
8175
  }
8123
- trace(_moduleName, _val) {
8176
+ trace(_levelAndName, _strings, _data) {
8124
8177
  /* no-op */
8125
8178
  }
8126
- log(moduleName, val) {
8127
- this.push(Level.LOG, moduleName, val);
8179
+ log(levelAndName, strings, data) {
8180
+ print(Level.LOG, levelAndName, strings, data);
8128
8181
  }
8129
- info(moduleName, val) {
8130
- this.push(Level.INFO, moduleName, val);
8182
+ info(levelAndName, strings, data) {
8183
+ print(Level.INFO, levelAndName, strings, data);
8131
8184
  }
8132
8185
  }
8133
8186
  /**
8134
8187
  * An optimized version of the logger - completely ignores `TRACE` & `DEBUG` level calls.
8135
8188
  */
8136
8189
  class InfoConsoleTransport extends ConsoleTransport {
8137
- insane(_moduleName, _val) {
8190
+ insane(_levelAndName, _strings, _data) {
8138
8191
  /* no-op */
8139
8192
  }
8140
- trace(_moduleName, _val) {
8193
+ trace(_levelAndName, _strings, _data) {
8141
8194
  /* no-op */
8142
8195
  }
8143
- log(_moduleName, _val) {
8196
+ log(_levelAndName, _strings, _data) {
8144
8197
  /* no-op */
8145
8198
  }
8146
- info(moduleName, val) {
8147
- this.push(Level.INFO, moduleName, val);
8199
+ info(levelAndName, strings, data) {
8200
+ print(Level.INFO, levelAndName, strings, data);
8148
8201
  }
8149
8202
  }
8150
8203
 
@@ -8177,11 +8230,6 @@ class Logger {
8177
8230
  const module = moduleName ?? fName;
8178
8231
  return new Logger(module.padStart(8, " "), GLOBAL_CONFIG);
8179
8232
  }
8180
- /**
8181
- * Return currently configured level for given module. */
8182
- static getLevel(moduleName) {
8183
- return findLevel(GLOBAL_CONFIG.options, moduleName);
8184
- }
8185
8233
  /**
8186
8234
  * Global configuration of all loggers.
8187
8235
  *
@@ -8212,33 +8260,46 @@ class Logger {
8212
8260
  const options = parseLoggerOptions(input, defaultLevel, workingDir);
8213
8261
  Logger.configureAllFromOptions(options);
8214
8262
  }
8263
+ cachedLevelAndName;
8215
8264
  constructor(moduleName, config) {
8216
8265
  this.moduleName = moduleName;
8217
8266
  this.config = config;
8218
8267
  }
8268
+ /** Return currently configured level for given module. */
8269
+ getLevel() {
8270
+ return this.getLevelAndName()[0];
8271
+ }
8272
+ getLevelAndName() {
8273
+ if (this.cachedLevelAndName === undefined) {
8274
+ const level = findLevel(this.config.options, this.moduleName);
8275
+ const shortName = this.moduleName.replace(this.config.options.workingDir, "");
8276
+ this.cachedLevelAndName = [level, shortName];
8277
+ }
8278
+ return this.cachedLevelAndName;
8279
+ }
8219
8280
  /** Log a message with `INSANE` level. */
8220
- insane(val) {
8221
- this.config.transport.insane(this.moduleName, val);
8281
+ insane(strings, ...data) {
8282
+ this.config.transport.insane(this.getLevelAndName(), strings, data);
8222
8283
  }
8223
8284
  /** Log a message with `TRACE` level. */
8224
- trace(val) {
8225
- this.config.transport.trace(this.moduleName, val);
8285
+ trace(strings, ...data) {
8286
+ this.config.transport.trace(this.getLevelAndName(), strings, data);
8226
8287
  }
8227
8288
  /** Log a message with `DEBUG`/`LOG` level. */
8228
- log(val) {
8229
- this.config.transport.log(this.moduleName, val);
8289
+ log(strings, ...data) {
8290
+ this.config.transport.log(this.getLevelAndName(), strings, data);
8230
8291
  }
8231
8292
  /** Log a message with `INFO` level. */
8232
- info(val) {
8233
- this.config.transport.info(this.moduleName, val);
8293
+ info(strings, ...data) {
8294
+ this.config.transport.info(this.getLevelAndName(), strings, data);
8234
8295
  }
8235
8296
  /** Log a message with `WARN` level. */
8236
- warn(val) {
8237
- this.config.transport.warn(this.moduleName, val);
8297
+ warn(strings, ...data) {
8298
+ this.config.transport.warn(this.getLevelAndName(), strings, data);
8238
8299
  }
8239
8300
  /** Log a message with `ERROR` level. */
8240
- error(val) {
8241
- this.config.transport.error(this.moduleName, val);
8301
+ error(strings, ...data) {
8302
+ this.config.transport.error(this.getLevelAndName(), strings, data);
8242
8303
  }
8243
8304
  }
8244
8305
 
@@ -8265,7 +8326,7 @@ class AuthorshipOptions {
8265
8326
  }
8266
8327
  }
8267
8328
 
8268
- const logger$3 = Logger.new(undefined, "config");
8329
+ const logger$4 = Logger.new(undefined, "config");
8269
8330
  /** Development config. Will accept unsealed blocks for now. */
8270
8331
  const DEV_CONFIG = "dev";
8271
8332
  /** Default config file. */
@@ -8324,15 +8385,15 @@ class NodeConfiguration {
8324
8385
  }
8325
8386
  function loadConfig(configPath) {
8326
8387
  if (configPath === DEFAULT_CONFIG) {
8327
- logger$3.log("🔧 Loading DEFAULT config");
8388
+ logger$4.log `🔧 Loading DEFAULT config`;
8328
8389
  return parseFromJson(configs.default, NodeConfiguration.fromJson);
8329
8390
  }
8330
8391
  if (configPath === DEV_CONFIG) {
8331
- logger$3.log("🔧 Loading DEV config");
8392
+ logger$4.log `🔧 Loading DEV config`;
8332
8393
  return parseFromJson(configs.dev, NodeConfiguration.fromJson);
8333
8394
  }
8334
8395
  try {
8335
- logger$3.log(`🔧 Loading config from ${configPath}`);
8396
+ logger$4.log `🔧 Loading config from ${configPath}`;
8336
8397
  const configFile = fs.readFileSync(configPath, "utf8");
8337
8398
  const parsed = JSON.parse(configFile);
8338
8399
  return parseFromJson(parsed, NodeConfiguration.fromJson);
@@ -12362,16 +12423,12 @@ class PartiallyUpdatedState {
12362
12423
  *
12363
12424
  * NOTE the info may be updated compared to what is in the state.
12364
12425
  *
12365
- * Takes into account newly created services as well.
12426
+ * Takes into account ejected and newly created services as well.
12366
12427
  */
12367
12428
  getServiceInfo(destination) {
12368
12429
  if (destination === null) {
12369
12430
  return null;
12370
12431
  }
12371
- const isEjected = this.stateUpdate.services.servicesRemoved.some((x) => x === destination);
12372
- if (isEjected) {
12373
- return null;
12374
- }
12375
12432
  const maybeNewService = this.stateUpdate.services.servicesUpdates.find((update) => update.serviceId === destination);
12376
12433
  if (maybeNewService !== undefined) {
12377
12434
  return maybeNewService.action.account;
@@ -14087,6 +14144,17 @@ class PageRange {
14087
14144
  }
14088
14145
  return new PageRange(start, length);
14089
14146
  }
14147
+ /** Returns true if the page range is wrapped (`start` >= `end`) and is not empty */
14148
+ isWrapped() {
14149
+ return this.start >= this.end && !this.isEmpty();
14150
+ }
14151
+ /** Checks if given page number is within the range */
14152
+ isInRange(page) {
14153
+ if (this.isWrapped()) {
14154
+ return page >= this.start || page < this.end;
14155
+ }
14156
+ return page >= this.start && page < this.end;
14157
+ }
14090
14158
  /** Checks if a range is empty (`length === 0`) */
14091
14159
  isEmpty() {
14092
14160
  return this.length === 0;
@@ -14194,7 +14262,7 @@ var AccessType;
14194
14262
  AccessType[AccessType["READ"] = 0] = "READ";
14195
14263
  AccessType[AccessType["WRITE"] = 1] = "WRITE";
14196
14264
  })(AccessType || (AccessType = {}));
14197
- // const logger = Logger.new(import.meta.filename, "pvm:mem");
14265
+ const logger$3 = Logger.new(undefined, "pvm:mem");
14198
14266
  class Memory {
14199
14267
  sbrkIndex;
14200
14268
  virtualSbrkIndex;
@@ -14225,7 +14293,7 @@ class Memory {
14225
14293
  if (bytes.length === 0) {
14226
14294
  return Result$1.ok(OK);
14227
14295
  }
14228
- // logger.insane(`MEM[${address}] <- ${BytesBlob.blobFrom(bytes)}`);
14296
+ logger$3.insane `MEM[${address}] <- ${BytesBlob.blobFrom(bytes)}`;
14229
14297
  const pagesResult = this.getPages(address, bytes.length, AccessType.WRITE);
14230
14298
  if (pagesResult.isError) {
14231
14299
  return Result$1.error(pagesResult.error);
@@ -14292,7 +14360,7 @@ class Memory {
14292
14360
  currentPosition += bytesToRead;
14293
14361
  bytesLeft -= bytesToRead;
14294
14362
  }
14295
- // logger.insane(`MEM[${startAddress}] => ${BytesBlob.blobFrom(result)}`);
14363
+ logger$3.insane `MEM[${startAddress}] => ${BytesBlob.blobFrom(result)}`;
14296
14364
  return Result$1.ok(OK);
14297
14365
  }
14298
14366
  sbrk(length) {
@@ -14427,10 +14495,11 @@ class MemoryBuilder {
14427
14495
  startHeapIndex (${startHeapIndex}) has to be less than or equal to endHeapIndex (${endHeapIndex})
14428
14496
  `;
14429
14497
  this.ensureNotFinalized();
14430
- const range = MemoryRange.fromStartAndLength(startHeapIndex, endHeapIndex - startHeapIndex);
14431
- const pages = PageRange.fromMemoryRange(range);
14432
- for (const pageNumber of pages) {
14433
- if (this.initialMemory.has(pageNumber)) {
14498
+ const heapRange = MemoryRange.fromStartAndLength(startHeapIndex, endHeapIndex - startHeapIndex);
14499
+ const heapPagesRange = PageRange.fromMemoryRange(heapRange);
14500
+ const initializedPageNumbers = Array.from(this.initialMemory.keys());
14501
+ for (const pageNumber of initializedPageNumbers) {
14502
+ if (heapPagesRange.isInRange(pageNumber)) {
14434
14503
  throw new IncorrectSbrkIndex();
14435
14504
  }
14436
14505
  }
@@ -16086,7 +16155,7 @@ class ProgramDecoder {
16086
16155
  return Result$1.ok(new ProgramDecoder(program));
16087
16156
  }
16088
16157
  catch (e) {
16089
- logger$2.error(`Invalid program: ${e}`);
16158
+ logger$2.error `Invalid program: ${e}`;
16090
16159
  return Result$1.error(ProgramDecoderError.InvalidProgramError);
16091
16160
  }
16092
16161
  }
@@ -16211,7 +16280,7 @@ class Interpreter {
16211
16280
  const argsType = instructionArgumentTypeMap[currentInstruction] ?? ArgumentType.NO_ARGUMENTS;
16212
16281
  const argsResult = this.argsDecodingResults[argsType];
16213
16282
  this.argsDecoder.fillArgs(this.pc, argsResult);
16214
- logger$1.insane(`[PC: ${this.pc}] ${Instruction[currentInstruction]}`);
16283
+ logger$1.insane `[PC: ${this.pc}] ${Instruction[currentInstruction]}`;
16215
16284
  if (!isValidInstruction) {
16216
16285
  this.instructionResult.status = Result.PANIC;
16217
16286
  }
@@ -16283,7 +16352,7 @@ class Interpreter {
16283
16352
  this.status = Status.HOST;
16284
16353
  break;
16285
16354
  }
16286
- logger$1.insane(`[PC: ${this.pc}] Status: ${Result[this.instructionResult.status]}`);
16355
+ logger$1.insane `[PC: ${this.pc}] Status: ${Result[this.instructionResult.status]}`;
16287
16356
  return this.status;
16288
16357
  }
16289
16358
  this.pc = this.instructionResult.nextPc;
@@ -16517,7 +16586,7 @@ class HostCallsManager {
16517
16586
  return `r${idx}=${value} (0x${value.toString(16)})`;
16518
16587
  })
16519
16588
  .join(", ");
16520
- logger.insane(`[${currentServiceId}] ${context} ${name}${requested}. Gas: ${gas}. Regs: ${registerValues}.`);
16589
+ logger.insane `[${currentServiceId}] ${context} ${name}${requested}. Gas: ${gas}. Regs: ${registerValues}.`;
16521
16590
  }
16522
16591
  }
16523
16592