@typeberry/jam 0.4.0-4809f38 → 0.4.0-a5d5d88

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.js CHANGED
@@ -24314,7 +24314,11 @@ var TestSuite;
24314
24314
  })(TestSuite || (TestSuite = {}));
24315
24315
  const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1, GpVersion.V0_7_2];
24316
24316
  const DEFAULT_SUITE = TestSuite.W3F_DAVXY;
24317
- const DEFAULT_VERSION = GpVersion.V0_7_2;
24317
+ /**
24318
+ * Current version is set to track the jam-conformance testing.
24319
+ * Since we are currently at 0.7.1 not 0.7.2, we set our default version accordingly.
24320
+ */
24321
+ const DEFAULT_VERSION = GpVersion.V0_7_1;
24318
24322
  const env = typeof process === "undefined" ? {} : process.env;
24319
24323
  let CURRENT_VERSION = parseCurrentVersion(env.GP_VERSION) ?? DEFAULT_VERSION;
24320
24324
  let CURRENT_SUITE = parseCurrentSuite(env.TEST_SUITE) ?? DEFAULT_SUITE;
@@ -24373,8 +24377,8 @@ class Compatibility {
24373
24377
  /**
24374
24378
  * Allows selecting different values for different Gray Paper versions from one record.
24375
24379
  *
24376
- * @param fallback The default value to return if no value is found for the current.
24377
- * @param record A record mapping versions to values, checking if the version is greater or equal to the current version.
24380
+ * fallback The default value to return if no value is found for the current.
24381
+ * versions A record mapping versions to values, checking if the version is greater or equal to the current version.
24378
24382
  * @returns The value for the current version, or the default value.
24379
24383
  */
24380
24384
  static selectIfGreaterOrEqual({ fallback, versions, }) {
@@ -24537,7 +24541,7 @@ const workspacePathFix = dev_env.NODE_ENV === "development"
24537
24541
 
24538
24542
  ;// CONCATENATED MODULE: ./packages/core/utils/opaque.ts
24539
24543
  /**
24540
- * @fileoverview `Opaque<Type, Token>` constructs a unique type which is a subset of Type with a
24544
+ * `Opaque<Type, Token>` constructs a unique type which is a subset of Type with a
24541
24545
  * specified unique token Token. It means that base type cannot be assigned to unique type by accident.
24542
24546
  * Good examples of opaque types include:
24543
24547
  * - JWTs or other tokens - these are special kinds of string used for authorization purposes.
@@ -31185,7 +31189,7 @@ function jip_chain_spec_parseBootnode(v) {
31185
31189
  if (name === "" || ip === "" || port === "") {
31186
31190
  throw new Error(`Invalid bootnode format, expected: <name>@<ip>:<port>, got: "${v}"`);
31187
31191
  }
31188
- const portNumber = Number.parseInt(port);
31192
+ const portNumber = Number.parseInt(port, 10);
31189
31193
  if (!isU16(portNumber)) {
31190
31194
  throw new Error(`Invalid port number: "${port}"`);
31191
31195
  }
@@ -35445,7 +35449,6 @@ class LeafNode {
35445
35449
  /**
35446
35450
  * Get the byte length of embedded value.
35447
35451
  *
35448
- * @remark
35449
35452
  * Note in case this node only contains hash this is going to be 0.
35450
35453
  */
35451
35454
  getValueLength() {
@@ -35456,7 +35459,6 @@ class LeafNode {
35456
35459
  /**
35457
35460
  * Returns the embedded value.
35458
35461
  *
35459
- * @remark
35460
35462
  * Note that this is going to be empty for a regular leaf node (i.e. containing a hash).
35461
35463
  */
35462
35464
  getValue() {
@@ -35466,7 +35468,6 @@ class LeafNode {
35466
35468
  /**
35467
35469
  * Returns contained value hash.
35468
35470
  *
35469
- * @remark
35470
35471
  * Note that for embedded value this is going to be full 0-padded 32 bytes.
35471
35472
  */
35472
35473
  getValueHash() {
@@ -37588,11 +37589,9 @@ class JamConfig {
37588
37589
 
37589
37590
  /** Helper function to create most used hashes in the block */
37590
37591
  class hasher_TransitionHasher {
37591
- context;
37592
37592
  keccakHasher;
37593
37593
  blake2b;
37594
- constructor(context, keccakHasher, blake2b) {
37595
- this.context = context;
37594
+ constructor(keccakHasher, blake2b) {
37596
37595
  this.keccakHasher = keccakHasher;
37597
37596
  this.blake2b = blake2b;
37598
37597
  }
@@ -39151,7 +39150,7 @@ const gas_tryAsSmallGas = (v) => opaque_asOpaqueType(numbers_tryAsU32(v));
39151
39150
  /** Attempt to convert given number into U64 gas representation. */
39152
39151
  const tryAsBigGas = (v) => opaque_asOpaqueType(numbers_tryAsU64(v));
39153
39152
  /** Attempt to convert given number into gas. */
39154
- const tryAsGas = (v) => typeof v === "number" && v < 2 ** 32 ? gas_tryAsSmallGas(v) : tryAsBigGas(v);
39153
+ const gas_tryAsGas = (v) => typeof v === "number" && v < 2 ** 32 ? gas_tryAsSmallGas(v) : tryAsBigGas(v);
39155
39154
 
39156
39155
  ;// CONCATENATED MODULE: ./packages/core/pvm-interface/memory.ts
39157
39156
 
@@ -39434,7 +39433,7 @@ const tryAsRegisterIndex = (index) => {
39434
39433
  debug_check `${index >= 0 && index < registers_NO_OF_REGISTERS} Incorrect register index: ${index}!`;
39435
39434
  return opaque_asOpaqueType(index);
39436
39435
  };
39437
- class Registers {
39436
+ class registers_Registers {
39438
39437
  bytes;
39439
39438
  asSigned;
39440
39439
  asUnsigned;
@@ -39453,7 +39452,7 @@ class Registers {
39453
39452
  }
39454
39453
  static fromBytes(bytes) {
39455
39454
  debug_check `${bytes.length === registers_NO_OF_REGISTERS << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
39456
- return new Registers(bytes);
39455
+ return new registers_Registers(bytes);
39457
39456
  }
39458
39457
  getBytesAsLittleEndian(index, len) {
39459
39458
  const offset = index << REGISTER_SIZE_SHIFT;
@@ -39767,49 +39766,10 @@ class NoopMissing {
39767
39766
  }
39768
39767
  }
39769
39768
 
39770
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/gas.ts
39771
-
39772
-
39773
- /** Create a new gas counter instance depending on the gas value. */
39774
- function gasCounter(gas) {
39775
- return new GasCounterU64(numbers_tryAsU64(gas));
39776
- }
39777
- class GasCounterU64 {
39778
- gas;
39779
- initialGas;
39780
- constructor(gas) {
39781
- this.gas = gas;
39782
- this.initialGas = tryAsGas(gas);
39783
- }
39784
- set(g) {
39785
- this.gas = numbers_tryAsU64(g);
39786
- }
39787
- get() {
39788
- return tryAsGas(this.gas);
39789
- }
39790
- sub(g) {
39791
- const result = this.gas - numbers_tryAsU64(g);
39792
- if (result >= 0n) {
39793
- this.gas = numbers_tryAsU64(result);
39794
- return false;
39795
- }
39796
- this.gas = numbers_tryAsU64(0n);
39797
- return true;
39798
- }
39799
- used() {
39800
- const gasConsumed = numbers_tryAsU64(this.initialGas) - this.gas;
39801
- // In we have less than zero left we assume that all gas has been consumed.
39802
- if (gasConsumed < 0) {
39803
- return this.initialGas;
39804
- }
39805
- return tryAsGas(gasConsumed);
39806
- }
39807
- }
39808
-
39809
39769
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/memory-index.ts
39810
39770
 
39811
39771
 
39812
- const tryAsMemoryIndex = (index) => {
39772
+ const memory_index_tryAsMemoryIndex = (index) => {
39813
39773
  debug_check `${index >= 0 && index <= MAX_MEMORY_INDEX} Incorrect memory index: ${index}!`;
39814
39774
  return opaque_asOpaqueType(index);
39815
39775
  };
@@ -39823,25 +39783,25 @@ const tryAsSbrkIndex = (index) => {
39823
39783
 
39824
39784
  const memory_consts_PAGE_SIZE_SHIFT = 12;
39825
39785
  // PAGE_SIZE has to be a power of 2
39826
- const PAGE_SIZE = 1 << memory_consts_PAGE_SIZE_SHIFT;
39786
+ const memory_consts_PAGE_SIZE = 1 << memory_consts_PAGE_SIZE_SHIFT;
39827
39787
  const MIN_ALLOCATION_SHIFT = (() => {
39828
39788
  const MIN_ALLOCATION_SHIFT = 7;
39829
39789
  debug_check `${MIN_ALLOCATION_SHIFT >= 0 && MIN_ALLOCATION_SHIFT < memory_consts_PAGE_SIZE_SHIFT} incorrect minimal allocation shift`;
39830
39790
  return MIN_ALLOCATION_SHIFT;
39831
39791
  })();
39832
- const MIN_ALLOCATION_LENGTH = PAGE_SIZE >> MIN_ALLOCATION_SHIFT;
39833
- const LAST_PAGE_NUMBER = (MEMORY_SIZE - PAGE_SIZE) / PAGE_SIZE;
39792
+ const MIN_ALLOCATION_LENGTH = memory_consts_PAGE_SIZE >> MIN_ALLOCATION_SHIFT;
39793
+ const LAST_PAGE_NUMBER = (MEMORY_SIZE - memory_consts_PAGE_SIZE) / memory_consts_PAGE_SIZE;
39834
39794
  /** https://graypaper.fluffylabs.dev/#/68eaa1f/35a60235a602?v=0.6.4 */
39835
39795
  const RESERVED_NUMBER_OF_PAGES = 16;
39836
39796
  /** https://graypaper.fluffylabs.dev/#/68eaa1f/35a60235a602?v=0.6.4 */
39837
- const MAX_NUMBER_OF_PAGES = MEMORY_SIZE / PAGE_SIZE;
39797
+ const MAX_NUMBER_OF_PAGES = MEMORY_SIZE / memory_consts_PAGE_SIZE;
39838
39798
 
39839
39799
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/pages/page-utils.ts
39840
39800
 
39841
39801
 
39842
39802
  /** Ensure that given memory `index` is within `[0...PAGE_SIZE)` and can be used to index a page */
39843
39803
  const tryAsPageIndex = (index) => {
39844
- debug_check `${index >= 0 && index < PAGE_SIZE}, Incorect page index: ${index}!`;
39804
+ debug_check `${index >= 0 && index < memory_consts_PAGE_SIZE}, Incorect page index: ${index}!`;
39845
39805
  return opaque_asOpaqueType(index);
39846
39806
  };
39847
39807
  /** Ensure that given `index` represents an index of one of the pages. */
@@ -39869,17 +39829,17 @@ function getNextPageNumber(pageNumber) {
39869
39829
 
39870
39830
 
39871
39831
  function alignToPageSize(length) {
39872
- return PAGE_SIZE * Math.ceil(length / PAGE_SIZE);
39832
+ return memory_consts_PAGE_SIZE * Math.ceil(length / memory_consts_PAGE_SIZE);
39873
39833
  }
39874
39834
  function getPageNumber(address) {
39875
39835
  return tryAsPageNumber(address >>> memory_consts_PAGE_SIZE_SHIFT);
39876
39836
  }
39877
39837
  function getStartPageIndex(address) {
39878
- return tryAsMemoryIndex((address >>> memory_consts_PAGE_SIZE_SHIFT) << memory_consts_PAGE_SIZE_SHIFT);
39838
+ return memory_index_tryAsMemoryIndex((address >>> memory_consts_PAGE_SIZE_SHIFT) << memory_consts_PAGE_SIZE_SHIFT);
39879
39839
  }
39880
39840
  function getStartPageIndexFromPageNumber(pageNumber) {
39881
39841
  // >>> 0 is needed to avoid changing sign of the number
39882
- return tryAsMemoryIndex((pageNumber << memory_consts_PAGE_SIZE_SHIFT) >>> 0);
39842
+ return memory_index_tryAsMemoryIndex((pageNumber << memory_consts_PAGE_SIZE_SHIFT) >>> 0);
39883
39843
  }
39884
39844
 
39885
39845
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/errors.ts
@@ -39901,7 +39861,7 @@ class PageFault {
39901
39861
  return new PageFault(numbers_tryAsU32(startPageIndex), isAccessFault);
39902
39862
  }
39903
39863
  static fromMemoryIndex(maybeMemoryIndex, isAccessFault = false) {
39904
- const memoryIndex = tryAsMemoryIndex(maybeMemoryIndex % MEMORY_SIZE);
39864
+ const memoryIndex = memory_index_tryAsMemoryIndex(maybeMemoryIndex % MEMORY_SIZE);
39905
39865
  const startPageIndex = getStartPageIndex(memoryIndex);
39906
39866
  return new PageFault(numbers_tryAsU32(startPageIndex), isAccessFault);
39907
39867
  }
@@ -39980,9 +39940,9 @@ class MemoryRange {
39980
39940
  constructor(start, length) {
39981
39941
  this.start = start;
39982
39942
  this.length = length;
39983
- this.end = tryAsMemoryIndex((this.start + this.length) % MEMORY_SIZE);
39943
+ this.end = memory_index_tryAsMemoryIndex((this.start + this.length) % MEMORY_SIZE);
39984
39944
  if (length > 0) {
39985
- this.lastIndex = tryAsMemoryIndex((this.end - 1 + MEMORY_SIZE) % MEMORY_SIZE);
39945
+ this.lastIndex = memory_index_tryAsMemoryIndex((this.end - 1 + MEMORY_SIZE) % MEMORY_SIZE);
39986
39946
  }
39987
39947
  }
39988
39948
  /** Creates a memory range from given starting point and length */
@@ -40025,7 +39985,7 @@ class MemoryRange {
40025
39985
  *
40026
39986
  * it should be in `memory-consts` but it cannot be there because of circular dependency
40027
39987
  */
40028
- const RESERVED_MEMORY_RANGE = MemoryRange.fromStartAndLength(tryAsMemoryIndex(0), RESERVED_NUMBER_OF_PAGES * PAGE_SIZE);
39988
+ const RESERVED_MEMORY_RANGE = MemoryRange.fromStartAndLength(memory_index_tryAsMemoryIndex(0), RESERVED_NUMBER_OF_PAGES * memory_consts_PAGE_SIZE);
40029
39989
 
40030
39990
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/page-range.ts
40031
39991
 
@@ -40063,7 +40023,7 @@ class PageRange {
40063
40023
  // lastIndex is not null because we just ensured that the range is not empty
40064
40024
  const pageWithLastIndex = getPageNumber(range.lastIndex ?? range.end);
40065
40025
  const endPage = getNextPageNumber(pageWithLastIndex);
40066
- if ((startPage === endPage || startPage === pageWithLastIndex) && range.length > PAGE_SIZE) {
40026
+ if ((startPage === endPage || startPage === pageWithLastIndex) && range.length > memory_consts_PAGE_SIZE) {
40067
40027
  // full range
40068
40028
  return new PageRange(startPage, MAX_NUMBER_OF_PAGES);
40069
40029
  }
@@ -40127,8 +40087,8 @@ class ReadablePage extends MemoryPage {
40127
40087
  }
40128
40088
  loadInto(result, startIndex, length) {
40129
40089
  const endIndex = startIndex + length;
40130
- if (endIndex > PAGE_SIZE) {
40131
- return result_Result.error(PageFault.fromMemoryIndex(this.start + PAGE_SIZE), () => `Page fault: read beyond page boundary at ${this.start + PAGE_SIZE}`);
40090
+ if (endIndex > memory_consts_PAGE_SIZE) {
40091
+ return result_Result.error(PageFault.fromMemoryIndex(this.start + memory_consts_PAGE_SIZE), () => `Page fault: read beyond page boundary at ${this.start + memory_consts_PAGE_SIZE}`);
40132
40092
  }
40133
40093
  const bytes = this.data.subarray(startIndex, endIndex);
40134
40094
  // we zero the bytes, since data might not yet be initialized at `endIndex`.
@@ -40161,8 +40121,8 @@ class WriteablePage extends MemoryPage {
40161
40121
  constructor(pageNumber, initialData) {
40162
40122
  super(pageNumber);
40163
40123
  const dataLength = initialData?.length ?? 0;
40164
- const initialPageLength = Math.min(PAGE_SIZE, Math.max(dataLength, MIN_ALLOCATION_LENGTH));
40165
- this.buffer = new ArrayBuffer(initialPageLength, { maxByteLength: PAGE_SIZE });
40124
+ const initialPageLength = Math.min(memory_consts_PAGE_SIZE, Math.max(dataLength, MIN_ALLOCATION_LENGTH));
40125
+ this.buffer = new ArrayBuffer(initialPageLength, { maxByteLength: memory_consts_PAGE_SIZE });
40166
40126
  this.view = new Uint8Array(this.buffer);
40167
40127
  if (initialData !== undefined) {
40168
40128
  this.view.set(initialData);
@@ -40170,8 +40130,8 @@ class WriteablePage extends MemoryPage {
40170
40130
  }
40171
40131
  loadInto(result, startIndex, length) {
40172
40132
  const endIndex = startIndex + length;
40173
- if (endIndex > PAGE_SIZE) {
40174
- return result_Result.error(PageFault.fromMemoryIndex(this.start + PAGE_SIZE), () => `Page fault: read beyond page boundary at ${this.start + PAGE_SIZE}`);
40133
+ if (endIndex > memory_consts_PAGE_SIZE) {
40134
+ return result_Result.error(PageFault.fromMemoryIndex(this.start + memory_consts_PAGE_SIZE), () => `Page fault: read beyond page boundary at ${this.start + memory_consts_PAGE_SIZE}`);
40175
40135
  }
40176
40136
  const bytes = this.view.subarray(startIndex, endIndex);
40177
40137
  // we zero the bytes, since the view might not yet be initialized at `endIndex`.
@@ -40180,16 +40140,16 @@ class WriteablePage extends MemoryPage {
40180
40140
  return result_Result.ok(result_OK);
40181
40141
  }
40182
40142
  storeFrom(startIndex, bytes) {
40183
- if (this.buffer.byteLength < startIndex + bytes.length && this.buffer.byteLength < PAGE_SIZE) {
40184
- const newLength = Math.min(PAGE_SIZE, Math.max(MIN_ALLOCATION_LENGTH, startIndex + bytes.length));
40143
+ if (this.buffer.byteLength < startIndex + bytes.length && this.buffer.byteLength < memory_consts_PAGE_SIZE) {
40144
+ const newLength = Math.min(memory_consts_PAGE_SIZE, Math.max(MIN_ALLOCATION_LENGTH, startIndex + bytes.length));
40185
40145
  this.buffer.resize(newLength);
40186
40146
  }
40187
40147
  this.view.set(bytes, startIndex);
40188
40148
  return result_Result.ok(result_OK);
40189
40149
  }
40190
40150
  setData(pageIndex, data) {
40191
- if (this.buffer.byteLength < pageIndex + data.length && this.buffer.byteLength < PAGE_SIZE) {
40192
- const newLength = Math.min(PAGE_SIZE, Math.max(MIN_ALLOCATION_LENGTH, pageIndex + data.length));
40151
+ if (this.buffer.byteLength < pageIndex + data.length && this.buffer.byteLength < memory_consts_PAGE_SIZE) {
40152
+ const newLength = Math.min(memory_consts_PAGE_SIZE, Math.max(MIN_ALLOCATION_LENGTH, pageIndex + data.length));
40193
40153
  this.buffer.resize(newLength);
40194
40154
  }
40195
40155
  this.view.set(data, pageIndex);
@@ -40240,10 +40200,10 @@ class Memory {
40240
40200
  this.memory = memory;
40241
40201
  }
40242
40202
  store(address, bytes) {
40243
- return this.storeFrom(tryAsMemoryIndex(address), bytes);
40203
+ return this.storeFrom(memory_index_tryAsMemoryIndex(address), bytes);
40244
40204
  }
40245
40205
  read(address, output) {
40246
- return this.loadInto(output, tryAsMemoryIndex(address));
40206
+ return this.loadInto(output, memory_index_tryAsMemoryIndex(address));
40247
40207
  }
40248
40208
  reset() {
40249
40209
  this.sbrkIndex = tryAsSbrkIndex(RESERVED_MEMORY_RANGE.end);
@@ -40270,8 +40230,8 @@ class Memory {
40270
40230
  let currentPosition = address;
40271
40231
  let bytesLeft = bytes.length;
40272
40232
  for (const page of pages) {
40273
- const pageStartIndex = tryAsPageIndex(currentPosition % PAGE_SIZE);
40274
- const bytesToWrite = Math.min(PAGE_SIZE - pageStartIndex, bytesLeft);
40233
+ const pageStartIndex = tryAsPageIndex(currentPosition % memory_consts_PAGE_SIZE);
40234
+ const bytesToWrite = Math.min(memory_consts_PAGE_SIZE - pageStartIndex, bytesLeft);
40275
40235
  const sourceStartIndex = currentPosition - address;
40276
40236
  const source = bytes.subarray(sourceStartIndex, sourceStartIndex + bytesToWrite);
40277
40237
  page.storeFrom(pageStartIndex, source);
@@ -40320,8 +40280,8 @@ class Memory {
40320
40280
  let currentPosition = startAddress;
40321
40281
  let bytesLeft = result.length;
40322
40282
  for (const page of pages) {
40323
- const pageStartIndex = tryAsPageIndex(currentPosition % PAGE_SIZE);
40324
- const bytesToRead = Math.min(PAGE_SIZE - pageStartIndex, bytesLeft);
40283
+ const pageStartIndex = tryAsPageIndex(currentPosition % memory_consts_PAGE_SIZE);
40284
+ const bytesToRead = Math.min(memory_consts_PAGE_SIZE - pageStartIndex, bytesLeft);
40325
40285
  const destinationStartIndex = currentPosition - startAddress;
40326
40286
  const destination = result.subarray(destinationStartIndex);
40327
40287
  page.loadInto(destination, pageStartIndex, bytesToRead);
@@ -40348,7 +40308,7 @@ class Memory {
40348
40308
  const newSbrkIndex = tryAsSbrkIndex(alignToPageSize(newVirtualSbrkIndex));
40349
40309
  // TODO [MaSi]: `getPageNumber` works incorrectly for SbrkIndex. Sbrk index should be changed to MemoryIndex
40350
40310
  const firstPageNumber = getPageNumber(currentSbrkIndex);
40351
- const pagesToAllocate = (newSbrkIndex - currentSbrkIndex) / PAGE_SIZE;
40311
+ const pagesToAllocate = (newSbrkIndex - currentSbrkIndex) / memory_consts_PAGE_SIZE;
40352
40312
  const rangeToAllocate = PageRange.fromStartAndLength(firstPageNumber, pagesToAllocate);
40353
40313
  for (const pageNumber of rangeToAllocate) {
40354
40314
  const page = new WriteablePage(pageNumber);
@@ -40403,8 +40363,8 @@ class MemoryBuilder {
40403
40363
  setReadablePages(start, end, data = new Uint8Array()) {
40404
40364
  this.ensureNotFinalized();
40405
40365
  debug_check `${start < end} end has to be bigger than start`;
40406
- debug_check `${start % PAGE_SIZE === 0} start needs to be a multiple of page size (${PAGE_SIZE})`;
40407
- debug_check `${end % PAGE_SIZE === 0} end needs to be a multiple of page size (${PAGE_SIZE})`;
40366
+ debug_check `${start % memory_consts_PAGE_SIZE === 0} start needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
40367
+ debug_check `${end % memory_consts_PAGE_SIZE === 0} end needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
40408
40368
  debug_check `${data.length <= end - start} the initial data is longer than address range`;
40409
40369
  const length = end - start;
40410
40370
  const range = MemoryRange.fromStartAndLength(start, length);
@@ -40413,7 +40373,7 @@ class MemoryBuilder {
40413
40373
  const noOfPages = pages.length;
40414
40374
  for (let i = 0; i < noOfPages; i++) {
40415
40375
  const pageNumber = pages[i];
40416
- const dataChunk = data.subarray(i * PAGE_SIZE, (i + 1) * PAGE_SIZE);
40376
+ const dataChunk = data.subarray(i * memory_consts_PAGE_SIZE, (i + 1) * memory_consts_PAGE_SIZE);
40417
40377
  const page = new ReadablePage(pageNumber, dataChunk);
40418
40378
  this.initialMemory.set(pageNumber, page);
40419
40379
  }
@@ -40431,8 +40391,8 @@ class MemoryBuilder {
40431
40391
  setWriteablePages(start, end, data = new Uint8Array()) {
40432
40392
  this.ensureNotFinalized();
40433
40393
  debug_check `${start < end} end has to be bigger than start`;
40434
- debug_check `${start % PAGE_SIZE === 0} start needs to be a multiple of page size (${PAGE_SIZE})`;
40435
- debug_check `${end % PAGE_SIZE === 0} end needs to be a multiple of page size (${PAGE_SIZE})`;
40394
+ debug_check `${start % memory_consts_PAGE_SIZE === 0} start needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
40395
+ debug_check `${end % memory_consts_PAGE_SIZE === 0} end needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
40436
40396
  debug_check `${data.length <= end - start} the initial data is longer than address range`;
40437
40397
  const length = end - start;
40438
40398
  const range = MemoryRange.fromStartAndLength(start, length);
@@ -40441,7 +40401,7 @@ class MemoryBuilder {
40441
40401
  const noOfPages = pages.length;
40442
40402
  for (let i = 0; i < noOfPages; i++) {
40443
40403
  const pageNumber = pages[i];
40444
- const dataChunk = data.subarray(i * PAGE_SIZE, (i + 1) * PAGE_SIZE);
40404
+ const dataChunk = data.subarray(i * memory_consts_PAGE_SIZE, (i + 1) * memory_consts_PAGE_SIZE);
40445
40405
  const page = new WriteablePage(pageNumber, dataChunk);
40446
40406
  this.initialMemory.set(pageNumber, page);
40447
40407
  }
@@ -40453,8 +40413,8 @@ class MemoryBuilder {
40453
40413
  */
40454
40414
  setData(start, data) {
40455
40415
  this.ensureNotFinalized();
40456
- const pageOffset = start % PAGE_SIZE;
40457
- const remainingSpaceOnPage = PAGE_SIZE - pageOffset;
40416
+ const pageOffset = start % memory_consts_PAGE_SIZE;
40417
+ const remainingSpaceOnPage = memory_consts_PAGE_SIZE - pageOffset;
40458
40418
  debug_check `${data.length <= remainingSpaceOnPage} The data has to fit into a single page.`;
40459
40419
  const length = data.length;
40460
40420
  const range = MemoryRange.fromStartAndLength(start, length);
@@ -40645,27 +40605,27 @@ class Program {
40645
40605
  static fromSpi(blob, args, hasMetadata) {
40646
40606
  const { code: spiCode, metadata } = hasMetadata ? extractCodeAndMetadata(blob) : { code: blob };
40647
40607
  const { code, memory: rawMemory, registers } = decodeStandardProgram(spiCode, args);
40648
- const regs = new Registers();
40608
+ const regs = new registers_Registers();
40649
40609
  regs.copyFrom(registers);
40650
40610
  const memoryBuilder = new MemoryBuilder();
40651
40611
  for (const { start, end, data } of rawMemory.readable) {
40652
- const startIndex = tryAsMemoryIndex(start);
40653
- const endIndex = tryAsMemoryIndex(end);
40612
+ const startIndex = memory_index_tryAsMemoryIndex(start);
40613
+ const endIndex = memory_index_tryAsMemoryIndex(end);
40654
40614
  memoryBuilder.setReadablePages(startIndex, endIndex, data ?? new Uint8Array());
40655
40615
  }
40656
40616
  for (const { start, end, data } of rawMemory.writeable) {
40657
- const startIndex = tryAsMemoryIndex(start);
40658
- const endIndex = tryAsMemoryIndex(end);
40617
+ const startIndex = memory_index_tryAsMemoryIndex(start);
40618
+ const endIndex = memory_index_tryAsMemoryIndex(end);
40659
40619
  memoryBuilder.setWriteablePages(startIndex, endIndex, data ?? new Uint8Array());
40660
40620
  }
40661
- const heapStart = tryAsMemoryIndex(rawMemory.sbrkIndex);
40621
+ const heapStart = memory_index_tryAsMemoryIndex(rawMemory.sbrkIndex);
40662
40622
  const heapEnd = tryAsSbrkIndex(rawMemory.heapEnd);
40663
40623
  const memory = memoryBuilder.finalize(heapStart, heapEnd);
40664
40624
  return new Program(code, regs, memory, metadata);
40665
40625
  }
40666
40626
  static fromGeneric(blob, hasMetadata) {
40667
40627
  const { code, metadata } = hasMetadata ? extractCodeAndMetadata(blob) : { code: blob };
40668
- const regs = new Registers();
40628
+ const regs = new registers_Registers();
40669
40629
  const memory = new Memory();
40670
40630
  return new Program(code, regs, memory, metadata);
40671
40631
  }
@@ -41680,6 +41640,45 @@ class BasicBlocks {
41680
41640
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/basic-blocks/index.ts
41681
41641
 
41682
41642
 
41643
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/gas.ts
41644
+
41645
+
41646
+ /** Create a new gas counter instance depending on the gas value. */
41647
+ function gasCounter(gas) {
41648
+ return new GasCounterU64(numbers_tryAsU64(gas));
41649
+ }
41650
+ class GasCounterU64 {
41651
+ gas;
41652
+ initialGas;
41653
+ constructor(gas) {
41654
+ this.gas = gas;
41655
+ this.initialGas = gas_tryAsGas(gas);
41656
+ }
41657
+ set(g) {
41658
+ this.gas = numbers_tryAsU64(g);
41659
+ }
41660
+ get() {
41661
+ return gas_tryAsGas(this.gas);
41662
+ }
41663
+ sub(g) {
41664
+ const result = this.gas - numbers_tryAsU64(g);
41665
+ if (result >= 0n) {
41666
+ this.gas = numbers_tryAsU64(result);
41667
+ return false;
41668
+ }
41669
+ this.gas = numbers_tryAsU64(0n);
41670
+ return true;
41671
+ }
41672
+ used() {
41673
+ const gasConsumed = numbers_tryAsU64(this.initialGas) - this.gas;
41674
+ // In we have less than zero left we assume that all gas has been consumed.
41675
+ if (gasConsumed < 0) {
41676
+ return this.initialGas;
41677
+ }
41678
+ return gas_tryAsGas(gasConsumed);
41679
+ }
41680
+ }
41681
+
41683
41682
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/instruction-gas-map.ts
41684
41683
 
41685
41684
 
@@ -42256,7 +42255,7 @@ class LoadOps {
42256
42255
  }
42257
42256
  loadNumber(address, registerIndex, numberLength) {
42258
42257
  const registerBytes = this.regs.getBytesAsLittleEndian(registerIndex, REG_SIZE_BYTES);
42259
- const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength), tryAsMemoryIndex(address));
42258
+ const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength), memory_index_tryAsMemoryIndex(address));
42260
42259
  if (loadResult.isError) {
42261
42260
  if (loadResult.error.isAccessFault) {
42262
42261
  this.instructionResult.status = pvm_interpreter_result_Result.FAULT_ACCESS;
@@ -42272,7 +42271,7 @@ class LoadOps {
42272
42271
  loadSignedNumber(address, registerIndex, numberLength) {
42273
42272
  // load all bytes from register to correctly handle the sign.
42274
42273
  const registerBytes = this.regs.getBytesAsLittleEndian(registerIndex, REG_SIZE_BYTES);
42275
- const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength), tryAsMemoryIndex(address));
42274
+ const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength), memory_index_tryAsMemoryIndex(address));
42276
42275
  if (loadResult.isError) {
42277
42276
  if (loadResult.error.isAccessFault) {
42278
42277
  this.instructionResult.status = pvm_interpreter_result_Result.FAULT_ACCESS;
@@ -42694,7 +42693,7 @@ class StoreOps {
42694
42693
  this.store(address, secondImmediateDecoder.getExtendedBytesAsLittleEndian());
42695
42694
  }
42696
42695
  store(address, bytes) {
42697
- const storeResult = this.memory.storeFrom(tryAsMemoryIndex(address), bytes);
42696
+ const storeResult = this.memory.storeFrom(memory_index_tryAsMemoryIndex(address), bytes);
42698
42697
  if (storeResult.isOk) {
42699
42698
  return;
42700
42699
  }
@@ -42703,7 +42702,7 @@ class StoreOps {
42703
42702
  }
42704
42703
  else {
42705
42704
  this.instructionResult.status = pvm_interpreter_result_Result.FAULT;
42706
- this.instructionResult.exitParam = getStartPageIndex(tryAsMemoryIndex(storeResult.error.address));
42705
+ this.instructionResult.exitParam = getStartPageIndex(memory_index_tryAsMemoryIndex(storeResult.error.address));
42707
42706
  }
42708
42707
  }
42709
42708
  }
@@ -43502,11 +43501,11 @@ class ProgramDecoder {
43502
43501
 
43503
43502
 
43504
43503
  const interpreter_logger = logger_Logger.new(import.meta.filename, "pvm");
43505
- class Interpreter {
43504
+ class interpreter_Interpreter {
43506
43505
  useSbrkGas;
43507
- registers = new Registers();
43506
+ registers = new registers_Registers();
43508
43507
  memory = new Memory();
43509
- gas = gasCounter(tryAsGas(0));
43508
+ gas = gasCounter(gas_tryAsGas(0));
43510
43509
  code = new Uint8Array();
43511
43510
  mask = Mask.empty();
43512
43511
  pc = 0;
@@ -43640,8 +43639,8 @@ class Interpreter {
43640
43639
  break;
43641
43640
  case ArgumentType.TWO_REGISTERS:
43642
43641
  if (this.useSbrkGas && currentInstruction === Instruction.SBRK) {
43643
- const calculateSbrkCost = (length) => (alignToPageSize(length) / PAGE_SIZE) * 16;
43644
- const underflow = this.gas.sub(tryAsGas(calculateSbrkCost(this.registers.getLowerU32(argsResult.firstRegisterIndex))));
43642
+ const calculateSbrkCost = (length) => (alignToPageSize(length) / memory_consts_PAGE_SIZE) * 16;
43643
+ const underflow = this.gas.sub(gas_tryAsGas(calculateSbrkCost(this.registers.getLowerU32(argsResult.firstRegisterIndex))));
43645
43644
  if (underflow) {
43646
43645
  this.status = status_Status.OOG;
43647
43646
  return this.status;
@@ -43736,12 +43735,88 @@ class Interpreter {
43736
43735
  }
43737
43736
  }
43738
43737
 
43738
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/debugger-adapter.ts
43739
+
43740
+
43741
+
43742
+
43743
+
43744
+
43745
+ class DebuggerAdapter {
43746
+ pvm;
43747
+ constructor(useSbrkGas = false) {
43748
+ this.pvm = new Interpreter({ useSbrkGas });
43749
+ }
43750
+ resetGeneric(rawProgram, flatRegisters, initialGas) {
43751
+ this.pvm.resetGeneric(rawProgram, 0, tryAsGas(initialGas), new Registers(flatRegisters));
43752
+ }
43753
+ reset(rawProgram, pc, gas, maybeRegisters, maybeMemory) {
43754
+ this.pvm.resetGeneric(rawProgram, pc, tryAsGas(gas), maybeRegisters, maybeMemory);
43755
+ }
43756
+ getPageDump(pageNumber) {
43757
+ const page = this.pvm.getMemoryPage(pageNumber);
43758
+ if (page === null) {
43759
+ // page wasn't allocated so we return an empty page
43760
+ return safeAllocUint8Array(PAGE_SIZE);
43761
+ }
43762
+ if (page.length === PAGE_SIZE) {
43763
+ // page was allocated and has a proper size so we can simply return it
43764
+ return page;
43765
+ }
43766
+ // page was allocated but it is shorter than PAGE_SIZE so we have to extend it
43767
+ const fullPage = safeAllocUint8Array(PAGE_SIZE);
43768
+ fullPage.set(page);
43769
+ return fullPage;
43770
+ }
43771
+ setMemory(address, value) {
43772
+ this.pvm.memory.storeFrom(tryAsMemoryIndex(address), value);
43773
+ }
43774
+ getExitArg() {
43775
+ return this.pvm.getExitParam() ?? 0;
43776
+ }
43777
+ getStatus() {
43778
+ return this.pvm.getStatus();
43779
+ }
43780
+ nextStep() {
43781
+ return this.pvm.nextStep() === Status.OK;
43782
+ }
43783
+ nSteps(steps) {
43784
+ check `${steps >>> 0 > 0} Expected a positive integer got ${steps}`;
43785
+ for (let i = 0; i < steps; i++) {
43786
+ const isOk = this.nextStep();
43787
+ if (!isOk) {
43788
+ return false;
43789
+ }
43790
+ }
43791
+ return true;
43792
+ }
43793
+ getRegisters() {
43794
+ return this.pvm.registers.getAllU64();
43795
+ }
43796
+ setRegisters(registers) {
43797
+ this.pvm.registers.copyFrom(new Registers(registers));
43798
+ }
43799
+ getProgramCounter() {
43800
+ return this.pvm.getPC();
43801
+ }
43802
+ setNextProgramCounter(nextPc) {
43803
+ this.pvm.setNextPC(nextPc);
43804
+ }
43805
+ getGasLeft() {
43806
+ return BigInt(this.pvm.gas.get());
43807
+ }
43808
+ setGasLeft(gas) {
43809
+ this.pvm.gas.set(tryAsGas(gas));
43810
+ }
43811
+ }
43812
+
43739
43813
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/index.ts
43740
43814
 
43741
43815
 
43742
43816
 
43743
43817
 
43744
43818
 
43819
+
43745
43820
  ;// CONCATENATED MODULE: ./node_modules/@fluffylabs/anan-as/build/debug-raw.js
43746
43821
  async function instantiate(module, imports = {}) {
43747
43822
  const adaptedImports = {
@@ -44195,12 +44270,12 @@ class AnanasMemory {
44195
44270
  }
44196
44271
  class AnanasGasCounter {
44197
44272
  instance;
44198
- initialGas = tryAsGas(0n);
44273
+ initialGas = gas_tryAsGas(0n);
44199
44274
  constructor(instance) {
44200
44275
  this.instance = instance;
44201
44276
  }
44202
44277
  get() {
44203
- return tryAsGas(this.instance.getGasLeft());
44278
+ return gas_tryAsGas(this.instance.getGasLeft());
44204
44279
  }
44205
44280
  set(g) {
44206
44281
  this.instance.setGasLeft(BigInt(g));
@@ -44305,7 +44380,7 @@ class InterpreterInstanceManager {
44305
44380
  const instances = [];
44306
44381
  switch (interpreter) {
44307
44382
  case PvmBackend.BuiltIn:
44308
- instances.push(new Interpreter({
44383
+ instances.push(new interpreter_Interpreter({
44309
44384
  useSbrkGas: false,
44310
44385
  }));
44311
44386
  break;
@@ -44479,10 +44554,10 @@ class Info {
44479
44554
  const chunk = encodedInfo.raw.subarray(Number(offset), Number(offset + length));
44480
44555
  const writeResult = memory.storeFrom(outputStart, chunk);
44481
44556
  if (writeResult.isError) {
44482
- logger_logger.trace `INFO(${serviceId}, off: ${offset}, len: ${length}) <- PANIC`;
44557
+ logger_logger.trace `[${this.currentServiceId}] INFO(${serviceId}, off: ${offset}, len: ${length}) <- PANIC`;
44483
44558
  return PvmExecution.Panic;
44484
44559
  }
44485
- logger_logger.trace `INFO(${serviceId}, off: ${offset}, len: ${length}) <- ${bytes_BytesBlob.blobFrom(chunk)}`;
44560
+ logger_logger.trace `[${this.currentServiceId}] INFO(${serviceId}, off: ${offset}, len: ${length}) <- ${bytes_BytesBlob.blobFrom(chunk)}`;
44486
44561
  if (accountInfo === null) {
44487
44562
  regs.set(IN_OUT_REG, HostCallResult.NONE);
44488
44563
  return;
@@ -45578,13 +45653,11 @@ class AccumulateDataItem {
45578
45653
  * - gas cost and reports length for each service (statistics)
45579
45654
  */
45580
45655
  class AccumulateData {
45581
- autoAccumulateServicesByServiceId;
45582
45656
  reportsDataByServiceId;
45583
45657
  transfersByServiceId;
45584
45658
  serviceIds;
45585
45659
  gasLimitByServiceId;
45586
45660
  constructor(reports, transfers, autoAccumulateServicesByServiceId) {
45587
- this.autoAccumulateServicesByServiceId = autoAccumulateServicesByServiceId;
45588
45661
  const serviceIdsFromAutoAccumulate = new Set(autoAccumulateServicesByServiceId.keys());
45589
45662
  const { reportsDataByServiceId, serviceIds: serviceIdsFromReports, gasLimitByServiceId: reportsGasLimitByServiceId, } = this.transformReports(reports);
45590
45663
  this.reportsDataByServiceId = reportsDataByServiceId;
@@ -45904,12 +45977,12 @@ function createMergeContext(chainSpec, state, inputState, results) {
45904
45977
  }
45905
45978
  function updatePrivilegedService(currentServiceId, serviceIdUpdatedByManager, selfUpdatedServiceId) {
45906
45979
  if (currentServiceId === serviceIdUpdatedByManager) {
45907
- return serviceIdUpdatedByManager;
45980
+ return selfUpdatedServiceId;
45908
45981
  }
45909
- return selfUpdatedServiceId;
45982
+ return serviceIdUpdatedByManager;
45910
45983
  }
45911
45984
  function mergePrivilegedServices(mergeContext, [serviceId, { stateUpdate }]) {
45912
- const { outputState, currentPrivilegedServices, chainSpec } = mergeContext;
45985
+ const { outputState, currentPrivilegedServices, chainSpec, privilegedServicesUpdatedByManager } = mergeContext;
45913
45986
  const currentManager = currentPrivilegedServices.manager;
45914
45987
  const currentRegistrar = currentPrivilegedServices.registrar;
45915
45988
  const currentDelegator = currentPrivilegedServices.delegator;
@@ -45927,28 +46000,35 @@ function mergePrivilegedServices(mergeContext, [serviceId, { stateUpdate }]) {
45927
46000
  });
45928
46001
  }
45929
46002
  if (serviceId === currentRegistrar) {
45930
- const newRegistrar = updatePrivilegedService(currentPrivilegedServices.registrar, outputState.privilegedServices.registrar, privilegedServices.registrar);
46003
+ const newRegistrar = updatePrivilegedService(currentPrivilegedServices.registrar, privilegedServicesUpdatedByManager.registrar, privilegedServices.registrar);
45931
46004
  outputState.privilegedServices = PrivilegedServices.create({
45932
46005
  ...outputState.privilegedServices,
45933
46006
  registrar: newRegistrar,
45934
46007
  });
45935
46008
  }
45936
46009
  if (serviceId === currentDelegator) {
45937
- const newDelegator = updatePrivilegedService(currentPrivilegedServices.delegator, outputState.privilegedServices.delegator, privilegedServices.delegator);
46010
+ const newDelegator = updatePrivilegedService(currentPrivilegedServices.delegator, privilegedServicesUpdatedByManager.delegator, privilegedServices.delegator);
45938
46011
  outputState.privilegedServices = PrivilegedServices.create({
45939
46012
  ...outputState.privilegedServices,
45940
46013
  delegator: newDelegator,
45941
46014
  });
45942
46015
  }
45943
- const assignersFromOutputState = outputState.privilegedServices;
45944
- const newAssigners = currentAssigners.map((currentAssigner, coreIndex) => serviceId === currentAssigner
45945
- ? updatePrivilegedService(currentPrivilegedServices.assigners[coreIndex], assignersFromOutputState.assigners[coreIndex], privilegedServices.assigners[coreIndex])
45946
- : currentAssigner);
45947
- const newAssignersPerCore = tryAsPerCore(newAssigners, chainSpec);
45948
- outputState.privilegedServices = PrivilegedServices.create({
45949
- ...outputState.privilegedServices,
45950
- assigners: newAssignersPerCore,
46016
+ let shouldUpdateAssigners = false;
46017
+ const newAssigners = currentAssigners.map((currentAssigner, coreIndex) => {
46018
+ if (serviceId === currentAssigner) {
46019
+ const newAssigner = updatePrivilegedService(currentPrivilegedServices.assigners[coreIndex], privilegedServicesUpdatedByManager.assigners[coreIndex], privilegedServices.assigners[coreIndex]);
46020
+ shouldUpdateAssigners = shouldUpdateAssigners || newAssigner !== currentAssigner;
46021
+ return newAssigner;
46022
+ }
46023
+ return currentAssigner;
45951
46024
  });
46025
+ if (shouldUpdateAssigners) {
46026
+ const newAssignersPerCore = tryAsPerCore(newAssigners, chainSpec);
46027
+ outputState.privilegedServices = PrivilegedServices.create({
46028
+ ...outputState.privilegedServices,
46029
+ assigners: newAssignersPerCore,
46030
+ });
46031
+ }
45952
46032
  }
45953
46033
  }
45954
46034
  function mergeValidatorsData(mergeContext, [serviceId, { stateUpdate }]) {
@@ -46093,7 +46173,7 @@ class Assign {
46093
46173
  const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
46094
46174
  // error while reading the memory.
46095
46175
  if (memoryReadResult.isError) {
46096
- logger_logger.trace `ASSIGN() <- PANIC`;
46176
+ logger_logger.trace `[${this.currentServiceId}] ASSIGN() <- PANIC`;
46097
46177
  return PvmExecution.Panic;
46098
46178
  }
46099
46179
  if (maybeCoreIndex >= this.chainSpec.coresCount) {
@@ -46108,18 +46188,18 @@ class Assign {
46108
46188
  const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
46109
46189
  if (result.isOk) {
46110
46190
  regs.set(assign_IN_OUT_REG, HostCallResult.OK);
46111
- logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
46191
+ logger_logger.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
46112
46192
  return;
46113
46193
  }
46114
46194
  const e = result.error;
46115
46195
  if (e === UpdatePrivilegesError.UnprivilegedService) {
46116
46196
  regs.set(assign_IN_OUT_REG, HostCallResult.HUH);
46117
- logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
46197
+ logger_logger.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
46118
46198
  return;
46119
46199
  }
46120
46200
  if (e === UpdatePrivilegesError.InvalidServiceId) {
46121
46201
  regs.set(assign_IN_OUT_REG, HostCallResult.WHO);
46122
- logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
46202
+ logger_logger.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
46123
46203
  return;
46124
46204
  }
46125
46205
  debug_assertNever(e);
@@ -46190,7 +46270,7 @@ class Bless {
46190
46270
  decoder.resetTo(0);
46191
46271
  const memoryReadResult = memory.loadInto(result, memIndex);
46192
46272
  if (memoryReadResult.isError) {
46193
- logger_logger.trace `BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}) <- PANIC`;
46273
+ logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}) <- PANIC`;
46194
46274
  return PvmExecution.Panic;
46195
46275
  }
46196
46276
  const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
@@ -46203,26 +46283,26 @@ class Bless {
46203
46283
  const authorizersDecoder = decoder_Decoder.fromBlob(res);
46204
46284
  const memoryReadResult = memory.loadInto(res, authorization);
46205
46285
  if (memoryReadResult.isError) {
46206
- logger_logger.trace `BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- PANIC`;
46286
+ logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- PANIC`;
46207
46287
  return PvmExecution.Panic;
46208
46288
  }
46209
46289
  // `a`
46210
46290
  const authorizers = tryAsPerCore(authorizersDecoder.sequenceFixLen(descriptors_codec.u32.asOpaque(), this.chainSpec.coresCount), this.chainSpec);
46211
46291
  const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate);
46212
46292
  if (updateResult.isOk) {
46213
- logger_logger.trace `BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- OK`;
46293
+ logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- OK`;
46214
46294
  regs.set(bless_IN_OUT_REG, HostCallResult.OK);
46215
46295
  return;
46216
46296
  }
46217
46297
  const e = updateResult.error;
46218
46298
  // NOTE: `UpdatePrivilegesError.UnprivilegedService` won't happen in 0.7.1+
46219
46299
  if (e === UpdatePrivilegesError.UnprivilegedService) {
46220
- logger_logger.trace `BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- HUH`;
46300
+ logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- HUH`;
46221
46301
  regs.set(bless_IN_OUT_REG, HostCallResult.HUH);
46222
46302
  return;
46223
46303
  }
46224
46304
  if (e === UpdatePrivilegesError.InvalidServiceId) {
46225
- logger_logger.trace `BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- WHO`;
46305
+ logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- WHO`;
46226
46306
  regs.set(bless_IN_OUT_REG, HostCallResult.WHO);
46227
46307
  return;
46228
46308
  }
@@ -46252,7 +46332,7 @@ class GasHostCall {
46252
46332
  }
46253
46333
  execute(gas, regs) {
46254
46334
  const gasValue = gas.get();
46255
- logger_logger.trace `GAS <- ${gasValue}`;
46335
+ logger_logger.trace `[${this.currentServiceId}] GAS <- ${gasValue}`;
46256
46336
  regs.set(7, numbers_tryAsU64(gasValue));
46257
46337
  return Promise.resolve(undefined);
46258
46338
  }
@@ -46284,7 +46364,7 @@ class Checkpoint {
46284
46364
  async execute(gas, regs) {
46285
46365
  await this.gasHostCall.execute(gas, regs);
46286
46366
  this.partialState.checkpoint();
46287
- logger_logger.trace `CHECKPOINT()`;
46367
+ logger_logger.trace `[${this.currentServiceId}] CHECKPOINT()`;
46288
46368
  return;
46289
46369
  }
46290
46370
  }
@@ -46324,18 +46404,18 @@ class Designate {
46324
46404
  const memoryReadResult = memory.loadInto(res, validatorsStart);
46325
46405
  // error while reading the memory.
46326
46406
  if (memoryReadResult.isError) {
46327
- logger_logger.trace `DESIGNATE() <- PANIC`;
46407
+ logger_logger.trace `[${this.currentServiceId}] DESIGNATE() <- PANIC`;
46328
46408
  return PvmExecution.Panic;
46329
46409
  }
46330
46410
  const decoder = decoder_Decoder.fromBlob(res);
46331
46411
  const validatorsData = decoder.sequenceFixLen(ValidatorData.Codec, this.chainSpec.validatorsCount);
46332
46412
  const result = this.partialState.updateValidatorsData(tryAsPerValidator(validatorsData, this.chainSpec));
46333
46413
  if (result.isError) {
46334
- logger_logger.trace `DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- HUH`;
46414
+ logger_logger.trace `[${this.currentServiceId}] DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- HUH`;
46335
46415
  regs.set(designate_IN_OUT_REG, HostCallResult.HUH);
46336
46416
  }
46337
46417
  else {
46338
- logger_logger.trace `DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- OK`;
46418
+ logger_logger.trace `[${this.currentServiceId}] DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- OK`;
46339
46419
  regs.set(designate_IN_OUT_REG, HostCallResult.OK);
46340
46420
  }
46341
46421
  }
@@ -46376,29 +46456,29 @@ class Eject {
46376
46456
  const previousCodeHash = bytes_Bytes.zero(hash_HASH_SIZE).asOpaque();
46377
46457
  const memoryReadResult = memory.loadInto(previousCodeHash.raw, preimageHashStart);
46378
46458
  if (memoryReadResult.isError) {
46379
- logger_logger.trace `EJECT(${serviceId}) <- PANIC`;
46459
+ logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}) <- PANIC`;
46380
46460
  return PvmExecution.Panic;
46381
46461
  }
46382
46462
  // cannot eject self
46383
46463
  if (serviceId === this.currentServiceId) {
46384
46464
  regs.set(eject_IN_OUT_REG, HostCallResult.WHO);
46385
- logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- WHO`;
46465
+ logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- WHO`;
46386
46466
  return;
46387
46467
  }
46388
46468
  const result = this.partialState.eject(serviceId, previousCodeHash);
46389
46469
  // All good!
46390
46470
  if (result.isOk) {
46391
- logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- OK`;
46471
+ logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- OK`;
46392
46472
  regs.set(eject_IN_OUT_REG, HostCallResult.OK);
46393
46473
  return;
46394
46474
  }
46395
46475
  const e = result.error;
46396
46476
  if (e === EjectError.InvalidService) {
46397
- logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- WHO ${result_resultToString(result)}`;
46477
+ logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- WHO ${result_resultToString(result)}`;
46398
46478
  regs.set(eject_IN_OUT_REG, HostCallResult.WHO);
46399
46479
  }
46400
46480
  else if (e === EjectError.InvalidPreimage) {
46401
- logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- HUH ${result_resultToString(result)}`;
46481
+ logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- HUH ${result_resultToString(result)}`;
46402
46482
  regs.set(eject_IN_OUT_REG, HostCallResult.HUH);
46403
46483
  }
46404
46484
  else {
@@ -46440,11 +46520,11 @@ class Forget {
46440
46520
  const memoryReadResult = memory.loadInto(hash.raw, hashStart);
46441
46521
  // error while reading the memory.
46442
46522
  if (memoryReadResult.isError) {
46443
- logger_logger.trace `FORGET(${hash}, ${length}) <- PANIC`;
46523
+ logger_logger.trace `[${this.currentServiceId}] FORGET(${hash}, ${length}) <- PANIC`;
46444
46524
  return PvmExecution.Panic;
46445
46525
  }
46446
46526
  const result = this.partialState.forgetPreimage(hash.asOpaque(), length);
46447
- logger_logger.trace `FORGET(${hash}, ${length}) <- ${result_resultToString(result)}`;
46527
+ logger_logger.trace `[${this.currentServiceId}] FORGET(${hash}, ${length}) <- ${result_resultToString(result)}`;
46448
46528
  if (result.isOk) {
46449
46529
  regs.set(forget_IN_OUT_REG, HostCallResult.OK);
46450
46530
  }
@@ -46501,11 +46581,11 @@ class New {
46501
46581
  const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
46502
46582
  // error while reading the memory.
46503
46583
  if (memoryReadResult.isError) {
46504
- logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
46584
+ logger_logger.trace `[${this.currentServiceId}] NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
46505
46585
  return PvmExecution.Panic;
46506
46586
  }
46507
46587
  const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage, requestedServiceId);
46508
- logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${result_resultToString(assignedId)}`;
46588
+ logger_logger.trace `[${this.currentServiceId}] NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${result_resultToString(assignedId)}`;
46509
46589
  if (assignedId.isOk) {
46510
46590
  regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
46511
46591
  return;
@@ -46565,11 +46645,11 @@ class Provide {
46565
46645
  const preimage = bytes_BytesBlob.blobFrom(safe_alloc_uint8array_safeAllocUint8Array(length));
46566
46646
  const memoryReadResult = memory.loadInto(preimage.raw, preimageStart);
46567
46647
  if (memoryReadResult.isError) {
46568
- logger_logger.trace `PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- PANIC`;
46648
+ logger_logger.trace `[${this.currentServiceId}] PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- PANIC`;
46569
46649
  return PvmExecution.Panic;
46570
46650
  }
46571
46651
  const result = this.partialState.providePreimage(serviceId, preimage);
46572
- logger_logger.trace `PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- ${result_resultToString(result)}`;
46652
+ logger_logger.trace `[${this.currentServiceId}] PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- ${result_resultToString(result)}`;
46573
46653
  if (result.isOk) {
46574
46654
  regs.set(provide_IN_OUT_REG, HostCallResult.OK);
46575
46655
  return;
@@ -46625,35 +46705,35 @@ class Query {
46625
46705
  const memoryReadResult = memory.loadInto(hash.raw, hashStart);
46626
46706
  // error while reading the memory.
46627
46707
  if (memoryReadResult.isError) {
46628
- logger_logger.trace `QUERY(${hash}, ${length}) <- PANIC`;
46708
+ logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- PANIC`;
46629
46709
  return PvmExecution.Panic;
46630
46710
  }
46631
46711
  const result = this.partialState.checkPreimageStatus(hash.asOpaque(), length);
46632
46712
  const zero = numbers_tryAsU64(0n);
46633
46713
  if (result === null) {
46634
- logger_logger.trace `QUERY(${hash}, ${length}) <- NONE`;
46714
+ logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- NONE`;
46635
46715
  regs.set(IN_OUT_REG_1, HostCallResult.NONE);
46636
46716
  regs.set(IN_OUT_REG_2, zero);
46637
46717
  return;
46638
46718
  }
46639
46719
  switch (result.status) {
46640
46720
  case PreimageStatusKind.Requested:
46641
- logger_logger.trace `QUERY(${hash}, ${length}) <- REQUESTED`;
46721
+ logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- REQUESTED`;
46642
46722
  regs.set(IN_OUT_REG_1, zero);
46643
46723
  regs.set(IN_OUT_REG_2, zero);
46644
46724
  return;
46645
46725
  case PreimageStatusKind.Available:
46646
- logger_logger.trace `QUERY(${hash}, ${length}) <- AVAILABLE [${result.data}]`;
46726
+ logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- AVAILABLE [${result.data}]`;
46647
46727
  regs.set(IN_OUT_REG_1, numbers_tryAsU64((BigInt(result.data[0]) << UPPER_BITS_SHIFT) + 1n));
46648
46728
  regs.set(IN_OUT_REG_2, zero);
46649
46729
  return;
46650
46730
  case PreimageStatusKind.Unavailable:
46651
- logger_logger.trace `QUERY(${hash}, ${length}) <- UNAVAILABLE [${result.data.join(", ")}]`;
46731
+ logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- UNAVAILABLE [${result.data.join(", ")}]`;
46652
46732
  regs.set(IN_OUT_REG_1, numbers_tryAsU64((BigInt(result.data[0]) << UPPER_BITS_SHIFT) + 2n));
46653
46733
  regs.set(IN_OUT_REG_2, numbers_tryAsU64(result.data[1]));
46654
46734
  return;
46655
46735
  case PreimageStatusKind.Reavailable:
46656
- logger_logger.trace `QUERY(${hash}, ${length}) <- REAVAILABLE [${result.data.join(", ")}]`;
46736
+ logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- REAVAILABLE [${result.data.join(", ")}]`;
46657
46737
  regs.set(IN_OUT_REG_1, numbers_tryAsU64((BigInt(result.data[0]) << UPPER_BITS_SHIFT) + 3n));
46658
46738
  regs.set(IN_OUT_REG_2, numbers_tryAsU64((BigInt(result.data[2]) << UPPER_BITS_SHIFT) + BigInt(result.data[1])));
46659
46739
  return;
@@ -46694,11 +46774,11 @@ class Solicit {
46694
46774
  const hash = bytes_Bytes.zero(hash_HASH_SIZE);
46695
46775
  const memoryReadResult = memory.loadInto(hash.raw, hashStart);
46696
46776
  if (memoryReadResult.isError) {
46697
- logger_logger.trace `SOLICIT(${hash}, ${length}) <- PANIC`;
46777
+ logger_logger.trace `[${this.currentServiceId}] SOLICIT(${hash}, ${length}) <- PANIC`;
46698
46778
  return PvmExecution.Panic;
46699
46779
  }
46700
46780
  const result = this.partialState.requestPreimage(hash.asOpaque(), length);
46701
- logger_logger.trace `SOLICIT(${hash}, ${length}) <- ${result_resultToString(result)}`;
46781
+ logger_logger.trace `[${this.currentServiceId}] SOLICIT(${hash}, ${length}) <- ${result_resultToString(result)}`;
46702
46782
  if (result.isOk) {
46703
46783
  regs.set(solicit_IN_OUT_REG, HostCallResult.OK);
46704
46784
  return;
@@ -46756,7 +46836,7 @@ class Transfer {
46756
46836
  */
46757
46837
  basicGasCost = Compatibility.isGreaterOrEqual(GpVersion.V0_7_2)
46758
46838
  ? gas_tryAsSmallGas(10)
46759
- : (regs) => tryAsGas(10n + regs.get(TRANSFER_GAS_FEE_REG));
46839
+ : (regs) => gas_tryAsGas(10n + regs.get(TRANSFER_GAS_FEE_REG));
46760
46840
  tracedRegisters = traceRegisters(transfer_IN_OUT_REG, AMOUNT_REG, TRANSFER_GAS_FEE_REG, MEMO_START_REG);
46761
46841
  constructor(currentServiceId, partialState) {
46762
46842
  this.currentServiceId = currentServiceId;
@@ -46775,16 +46855,16 @@ class Transfer {
46775
46855
  const memoryReadResult = memory.loadInto(memo.raw, memoStart);
46776
46856
  // page fault while reading the memory.
46777
46857
  if (memoryReadResult.isError) {
46778
- logger_logger.trace `TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- PANIC`;
46858
+ logger_logger.trace `[${this.currentServiceId}] TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- PANIC`;
46779
46859
  return PvmExecution.Panic;
46780
46860
  }
46781
46861
  const transferResult = this.partialState.transfer(destination, amount, transferGasFee, memo);
46782
- logger_logger.trace `TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- ${result_resultToString(transferResult)}`;
46862
+ logger_logger.trace `[${this.currentServiceId}] TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- ${result_resultToString(transferResult)}`;
46783
46863
  // All good!
46784
46864
  if (transferResult.isOk) {
46785
46865
  if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_2)) {
46786
46866
  // substracting value `t`
46787
- const underflow = gas.sub(tryAsGas(transferGasFee));
46867
+ const underflow = gas.sub(gas_tryAsGas(transferGasFee));
46788
46868
  if (underflow) {
46789
46869
  return PvmExecution.OOG;
46790
46870
  }
@@ -46845,11 +46925,11 @@ class Upgrade {
46845
46925
  const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
46846
46926
  const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
46847
46927
  if (memoryReadResult.isError) {
46848
- logger_logger.trace `UPGRADE(${codeHash}, ${gas}, ${allowance}) <- PANIC`;
46928
+ logger_logger.trace `[${this.currentServiceId}] UPGRADE(${codeHash}, ${gas}, ${allowance}) <- PANIC`;
46849
46929
  return PvmExecution.Panic;
46850
46930
  }
46851
46931
  this.partialState.upgradeService(codeHash.asOpaque(), gas, allowance);
46852
- logger_logger.trace `UPGRADE(${codeHash}, ${gas}, ${allowance})`;
46932
+ logger_logger.trace `[${this.currentServiceId}] UPGRADE(${codeHash}, ${gas}, ${allowance})`;
46853
46933
  regs.set(upgrade_IN_OUT_REG, HostCallResult.OK);
46854
46934
  }
46855
46935
  }
@@ -46883,11 +46963,11 @@ class Yield {
46883
46963
  const hash = bytes_Bytes.zero(hash_HASH_SIZE);
46884
46964
  const memoryReadResult = memory.loadInto(hash.raw, hashStart);
46885
46965
  if (memoryReadResult.isError) {
46886
- logger_logger.trace `YIELD() <- PANIC`;
46966
+ logger_logger.trace `[${this.currentServiceId}] YIELD() <- PANIC`;
46887
46967
  return PvmExecution.Panic;
46888
46968
  }
46889
46969
  this.partialState.yield(hash);
46890
- logger_logger.trace `YIELD(${hash})`;
46970
+ logger_logger.trace `[${this.currentServiceId}] YIELD(${hash})`;
46891
46971
  regs.set(yield_IN_OUT_REG, HostCallResult.OK);
46892
46972
  }
46893
46973
  }
@@ -46930,10 +47010,10 @@ class Fetch {
46930
47010
  const chunk = value === null ? new Uint8Array() : value.raw.subarray(Number(offset), Number(offset + length));
46931
47011
  const storeResult = memory.storeFrom(output, chunk);
46932
47012
  if (storeResult.isError) {
46933
- logger_logger.trace `FETCH(${kind}) <- PANIC`;
47013
+ logger_logger.trace `[${this.currentServiceId}] FETCH(${kind}) <- PANIC`;
46934
47014
  return PvmExecution.Panic;
46935
47015
  }
46936
- logger_logger.trace `FETCH(${kind}) <- ${value?.toStringTruncated()}`;
47016
+ logger_logger.trace `[${this.currentServiceId}] FETCH(${kind}) <- ${value?.toStringTruncated()}`;
46937
47017
  // write result
46938
47018
  regs.set(fetch_IN_OUT_REG, value === null ? HostCallResult.NONE : valueLength);
46939
47019
  }
@@ -47083,7 +47163,7 @@ class LogHostCall {
47083
47163
  }
47084
47164
  memory.loadInto(message, msgStart);
47085
47165
  const level = clampU64ToU32(lvl);
47086
- logger_logger.trace `LOG(${this.currentServiceId}, ${level < Levels.UNKNOWN ? Levels[level] : Levels[Levels.UNKNOWN]}(${lvl}), ${decoder.decode(target)}, ${decoder.decode(message)})`;
47166
+ logger_logger.trace `[${this.currentServiceId}] LOG(${this.currentServiceId}, ${level < Levels.UNKNOWN ? Levels[level] : Levels[Levels.UNKNOWN]}(${lvl}), ${decoder.decode(target)}, ${decoder.decode(message)})`;
47087
47167
  return Promise.resolve(undefined);
47088
47168
  }
47089
47169
  }
@@ -47124,12 +47204,12 @@ class Lookup {
47124
47204
  const preImageHash = bytes_Bytes.zero(hash_HASH_SIZE);
47125
47205
  const memoryReadResult = memory.loadInto(preImageHash.raw, hashAddress);
47126
47206
  if (memoryReadResult.isError) {
47127
- logger_logger.trace `LOOKUP(${serviceId}, ${preImageHash}) <- PANIC`;
47207
+ logger_logger.trace `[${this.currentServiceId}] LOOKUP(${serviceId}, ${preImageHash}) <- PANIC`;
47128
47208
  return PvmExecution.Panic;
47129
47209
  }
47130
47210
  // v
47131
47211
  const preImage = this.account.lookup(serviceId, preImageHash);
47132
- logger_logger.trace `LOOKUP(${serviceId}, ${preImageHash}) <- ${preImage?.toStringTruncated() ?? "<missing>"}...`;
47212
+ logger_logger.trace `[${this.currentServiceId}] LOOKUP(${serviceId}, ${preImageHash}) <- ${preImage?.toStringTruncated() ?? "<missing>"}...`;
47133
47213
  const preImageLength = preImage === null ? numbers_tryAsU64(0) : numbers_tryAsU64(preImage.raw.length);
47134
47214
  const preimageBlobOffset = regs.get(10);
47135
47215
  const lengthToWrite = regs.get(11);
@@ -47226,20 +47306,20 @@ class Read {
47226
47306
  const chunk = value === null ? safe_alloc_uint8array_safeAllocUint8Array(0) : value.raw.subarray(Number(offset), Number(offset + blobLength));
47227
47307
  const memoryWriteResult = memory.storeFrom(destinationAddress, chunk);
47228
47308
  if (memoryWriteResult.isError) {
47229
- logger_logger.trace `READ(${serviceId}, ${rawKey}) <- PANIC`;
47309
+ logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- PANIC`;
47230
47310
  return PvmExecution.Panic;
47231
47311
  }
47232
47312
  if (value === null) {
47233
- logger_logger.trace `READ(${serviceId}, ${rawKey}) <- NONE`;
47313
+ logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- NONE`;
47234
47314
  regs.set(read_IN_OUT_REG, HostCallResult.NONE);
47235
47315
  return;
47236
47316
  }
47237
47317
  if (chunk.length > 0) {
47238
- logger_logger.trace `READ(${serviceId}, ${rawKey}) <- ${bytes_BytesBlob.blobFrom(chunk).toStringTruncated()}`;
47318
+ logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- ${bytes_BytesBlob.blobFrom(chunk).toStringTruncated()}`;
47239
47319
  }
47240
47320
  else {
47241
47321
  // just a query for length of stored data
47242
- logger_logger.trace `READ(${serviceId}, ${rawKey}) <- (${valueLength} ${valueLength === 1n ? "byte" : "bytes"})`;
47322
+ logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- (${valueLength} ${valueLength === 1n ? "byte" : "bytes"})`;
47243
47323
  }
47244
47324
  regs.set(read_IN_OUT_REG, valueLength);
47245
47325
  }
@@ -47283,7 +47363,7 @@ class Write {
47283
47363
  const rawStorageKey = safe_alloc_uint8array_safeAllocUint8Array(storageKeyLengthClamped);
47284
47364
  const keyLoadingResult = memory.loadInto(rawStorageKey, storageKeyStartAddress);
47285
47365
  if (keyLoadingResult.isError) {
47286
- logger_logger.trace `WRITE() <- PANIC`;
47366
+ logger_logger.trace `[${this.currentServiceId}] WRITE() <- PANIC`;
47287
47367
  return PvmExecution.Panic;
47288
47368
  }
47289
47369
  // k
@@ -47293,14 +47373,14 @@ class Write {
47293
47373
  const valueLoadingResult = memory.loadInto(value, valueStart);
47294
47374
  // Note [MaSo] this is ok to return bcs if valueLength is 0, then this panic won't happen
47295
47375
  if (valueLoadingResult.isError) {
47296
- logger_logger.trace `WRITE(${storageKey}) <- PANIC`;
47376
+ logger_logger.trace `[${this.currentServiceId}] WRITE(${storageKey}) <- PANIC`;
47297
47377
  return PvmExecution.Panic;
47298
47378
  }
47299
47379
  /** https://graypaper.fluffylabs.dev/#/9a08063/33af0133b201?v=0.6.6 */
47300
47380
  const maybeValue = valueLength === 0n ? null : bytes_BytesBlob.blobFrom(value);
47301
47381
  // a
47302
47382
  const result = this.account.write(storageKey, maybeValue);
47303
- logger_logger.trace `WRITE(${storageKey}, ${maybeValue?.toStringTruncated() ?? "remove"}) <- ${result_resultToString(result)}`;
47383
+ logger_logger.trace `[${this.currentServiceId}] WRITE(${storageKey}, ${maybeValue?.toStringTruncated() ?? "remove"}) <- ${result_resultToString(result)}`;
47304
47384
  if (result.isError) {
47305
47385
  regs.set(write_IN_OUT_REG, HostCallResult.FULL);
47306
47386
  return;
@@ -47529,7 +47609,7 @@ class Accumulate {
47529
47609
  serviceId,
47530
47610
  argsLength: numbers_tryAsU32(transfers.length + operands.length),
47531
47611
  });
47532
- const result = await executor.run(invocationArgs, tryAsGas(gas));
47612
+ const result = await executor.run(invocationArgs, gas_tryAsGas(gas));
47533
47613
  const [newState, checkpoint] = partialState.getStateUpdates();
47534
47614
  /**
47535
47615
  * PVM invocation returned and error so we return the checkpoint
@@ -47730,19 +47810,19 @@ class Accumulate {
47730
47810
  for (let serviceIndex = 0; serviceIndex < serviceIdsLength; serviceIndex += 1) {
47731
47811
  const serviceId = serviceIds[serviceIndex];
47732
47812
  const checkpoint = AccumulationStateUpdate.copyFrom(inputStateUpdate);
47733
- const promise = this.accumulateSingleService(serviceId, accumulateData.getTransfers(serviceId), accumulateData.getOperands(serviceId), accumulateData.getGasLimit(serviceId), slot, entropy, AccumulationStateUpdate.copyFrom(inputStateUpdate)).then(({ consumedGas, stateUpdate }) => ({
47734
- consumedGas,
47735
- stateUpdate: stateUpdate === null ? checkpoint : stateUpdate,
47736
- }));
47813
+ const promise = this.accumulateSingleService(serviceId, accumulateData.getTransfers(serviceId), accumulateData.getOperands(serviceId), accumulateData.getGasLimit(serviceId), slot, entropy, AccumulationStateUpdate.copyFrom(inputStateUpdate)).then(({ consumedGas, stateUpdate }) => {
47814
+ const resultEntry = [
47815
+ serviceId,
47816
+ {
47817
+ consumedGas,
47818
+ stateUpdate: stateUpdate === null ? checkpoint : stateUpdate,
47819
+ },
47820
+ ];
47821
+ return resultEntry;
47822
+ });
47737
47823
  resultPromises[serviceIndex] = promise;
47738
47824
  }
47739
- return Promise.all(resultPromises).then((results) => {
47740
- const map = new Map();
47741
- for (let serviceIndex = 0; serviceIndex < serviceIdsLength; serviceIndex += 1) {
47742
- map.set(serviceIds[serviceIndex], results[serviceIndex]);
47743
- }
47744
- return map;
47745
- });
47825
+ return Promise.all(resultPromises).then((results) => new Map(results));
47746
47826
  }
47747
47827
  /**
47748
47828
  * A method that updates `recentlyAccumulated`, `accumulationQueue` and `timeslot` in state
@@ -47831,9 +47911,10 @@ class Accumulate {
47831
47911
  const _gasCost = gasCost;
47832
47912
  assertEmpty(rest);
47833
47913
  const accumulated = accumulatableReports.subview(0, accumulatedReports);
47834
- const { yieldedRoot, services, transfers: _transfers, validatorsData, privilegedServices, authorizationQueues, ...stateUpdateRest } = state;
47914
+ const { yieldedRoot, services, transfers, validatorsData, privilegedServices, authorizationQueues, ...stateUpdateRest } = state;
47835
47915
  assertEmpty(stateUpdateRest);
47836
- // yielded root is retrieved after each pvm invocation so we can ignore it here
47916
+ // transfers and yielded root are retrieved after each pvm invocation so we can ignore it here
47917
+ const _transfers = transfers;
47837
47918
  const _yieldedRoot = yieldedRoot;
47838
47919
  if (this.hasDuplicatedServiceIdCreated(services.created)) {
47839
47920
  accumulate_logger.trace `Duplicated Service creation detected. Block is invalid.`;
@@ -47932,7 +48013,7 @@ class DeferredTransfers {
47932
48013
  partiallyUpdatedState.updateServiceInfo(serviceId, newInfo);
47933
48014
  const partialState = new AccumulateExternalities(this.chainSpec, this.blake2b, partiallyUpdatedState, serviceId, serviceId, timeslot);
47934
48015
  const fetchExternalities = FetchExternalities.createForOnTransfer({ entropy, transfers }, this.chainSpec);
47935
- let consumedGas = tryAsGas(0);
48016
+ let consumedGas = gas_tryAsGas(0);
47936
48017
  const hasTransfers = transfers.length > 0;
47937
48018
  const isCodeCorrect = code !== null && code.length <= W_C;
47938
48019
  if (!hasTransfers || !isCodeCorrect) {
@@ -47950,7 +48031,7 @@ class DeferredTransfers {
47950
48031
  const executor = await PvmExecutor.createOnTransferExecutor(serviceId, code, { partialState, fetchExternalities }, this.pvm);
47951
48032
  const args = encoder_Encoder.encodeObject(deferred_transfers_ARGS_CODEC, { timeslot, serviceId, transfersLength: numbers_tryAsU32(transfers.length) }, this.chainSpec);
47952
48033
  const gas = transfers.reduce((acc, item) => acc + item.gas, 0n);
47953
- consumedGas = (await executor.run(args, tryAsGas(gas))).consumedGas;
48034
+ consumedGas = (await executor.run(args, gas_tryAsGas(gas))).consumedGas;
47954
48035
  }
47955
48036
  transferStatistics.set(serviceId, { count: numbers_tryAsU32(transfers.length), gasUsed: tryAsServiceGas(consumedGas) });
47956
48037
  const [updatedState] = partialState.getStateUpdates();
@@ -49764,7 +49845,7 @@ async function createImporter(config) {
49764
49845
  const interpreter = config.workerParams.pvm;
49765
49846
  const blocks = db.getBlocksDb();
49766
49847
  const states = db.getStatesDb();
49767
- const hasher = new hasher_TransitionHasher(chainSpec, await keccakHasher, await blake2b);
49848
+ const hasher = new hasher_TransitionHasher(await keccakHasher, await blake2b);
49768
49849
  const importer = new Importer(chainSpec, interpreter, hasher, main_logger, blocks, states);
49769
49850
  return {
49770
49851
  importer,
@@ -52488,7 +52569,7 @@ class generator_Generator {
52488
52569
  // select validator for block
52489
52570
  const validatorId = tryAsValidatorIndex(newTimeSlot % 6);
52490
52571
  // retriev data from previous block
52491
- const hasher = new TransitionHasher(this.chainSpec, this.keccakHasher, this.blake2b);
52572
+ const hasher = new TransitionHasher(this.keccakHasher, this.blake2b);
52492
52573
  const parentHeaderHash = this.lastHeaderHash;
52493
52574
  const stateRoot = this.states.getStateRoot(this.lastState);
52494
52575
  // create extrinsic