@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.
@@ -3550,7 +3550,11 @@ var TestSuite;
3550
3550
  })(TestSuite || (TestSuite = {}));
3551
3551
  const ALL_VERSIONS_IN_ORDER = [compatibility_GpVersion.V0_6_7, compatibility_GpVersion.V0_7_0, compatibility_GpVersion.V0_7_1, compatibility_GpVersion.V0_7_2];
3552
3552
  const DEFAULT_SUITE = TestSuite.W3F_DAVXY;
3553
- const DEFAULT_VERSION = compatibility_GpVersion.V0_7_2;
3553
+ /**
3554
+ * Current version is set to track the jam-conformance testing.
3555
+ * Since we are currently at 0.7.1 not 0.7.2, we set our default version accordingly.
3556
+ */
3557
+ const DEFAULT_VERSION = compatibility_GpVersion.V0_7_1;
3554
3558
  const env = typeof process === "undefined" ? {} : process.env;
3555
3559
  let CURRENT_VERSION = parseCurrentVersion(env.GP_VERSION) ?? DEFAULT_VERSION;
3556
3560
  let CURRENT_SUITE = parseCurrentSuite(env.TEST_SUITE) ?? DEFAULT_SUITE;
@@ -3609,8 +3613,8 @@ class compatibility_Compatibility {
3609
3613
  /**
3610
3614
  * Allows selecting different values for different Gray Paper versions from one record.
3611
3615
  *
3612
- * @param fallback The default value to return if no value is found for the current.
3613
- * @param record A record mapping versions to values, checking if the version is greater or equal to the current version.
3616
+ * fallback The default value to return if no value is found for the current.
3617
+ * versions A record mapping versions to values, checking if the version is greater or equal to the current version.
3614
3618
  * @returns The value for the current version, or the default value.
3615
3619
  */
3616
3620
  static selectIfGreaterOrEqual({ fallback, versions, }) {
@@ -3773,7 +3777,7 @@ const workspacePathFix = dev_env.NODE_ENV === "development"
3773
3777
 
3774
3778
  ;// CONCATENATED MODULE: ./packages/core/utils/opaque.ts
3775
3779
  /**
3776
- * @fileoverview `Opaque<Type, Token>` constructs a unique type which is a subset of Type with a
3780
+ * `Opaque<Type, Token>` constructs a unique type which is a subset of Type with a
3777
3781
  * specified unique token Token. It means that base type cannot be assigned to unique type by accident.
3778
3782
  * Good examples of opaque types include:
3779
3783
  * - JWTs or other tokens - these are special kinds of string used for authorization purposes.
@@ -7100,11 +7104,9 @@ function sequenceViewFixLen(type, { fixedLength }) {
7100
7104
 
7101
7105
  /** Helper function to create most used hashes in the block */
7102
7106
  class TransitionHasher {
7103
- context;
7104
7107
  keccakHasher;
7105
7108
  blake2b;
7106
- constructor(context, keccakHasher, blake2b) {
7107
- this.context = context;
7109
+ constructor(keccakHasher, blake2b) {
7108
7110
  this.keccakHasher = keccakHasher;
7109
7111
  this.blake2b = blake2b;
7110
7112
  }
@@ -13212,7 +13214,6 @@ class LeafNode {
13212
13214
  /**
13213
13215
  * Get the byte length of embedded value.
13214
13216
  *
13215
- * @remark
13216
13217
  * Note in case this node only contains hash this is going to be 0.
13217
13218
  */
13218
13219
  getValueLength() {
@@ -13223,7 +13224,6 @@ class LeafNode {
13223
13224
  /**
13224
13225
  * Returns the embedded value.
13225
13226
  *
13226
- * @remark
13227
13227
  * Note that this is going to be empty for a regular leaf node (i.e. containing a hash).
13228
13228
  */
13229
13229
  getValue() {
@@ -13233,7 +13233,6 @@ class LeafNode {
13233
13233
  /**
13234
13234
  * Returns contained value hash.
13235
13235
  *
13236
- * @remark
13237
13236
  * Note that for embedded value this is going to be full 0-padded 32 bytes.
13238
13237
  */
13239
13238
  getValueHash() {
@@ -14389,7 +14388,7 @@ const gas_tryAsSmallGas = (v) => opaque_asOpaqueType(numbers_tryAsU32(v));
14389
14388
  /** Attempt to convert given number into U64 gas representation. */
14390
14389
  const tryAsBigGas = (v) => opaque_asOpaqueType(numbers_tryAsU64(v));
14391
14390
  /** Attempt to convert given number into gas. */
14392
- const tryAsGas = (v) => typeof v === "number" && v < 2 ** 32 ? gas_tryAsSmallGas(v) : tryAsBigGas(v);
14391
+ const gas_tryAsGas = (v) => typeof v === "number" && v < 2 ** 32 ? gas_tryAsSmallGas(v) : tryAsBigGas(v);
14393
14392
 
14394
14393
  ;// CONCATENATED MODULE: ./packages/core/pvm-interface/memory.ts
14395
14394
 
@@ -14672,7 +14671,7 @@ const tryAsRegisterIndex = (index) => {
14672
14671
  debug_check `${index >= 0 && index < registers_NO_OF_REGISTERS} Incorrect register index: ${index}!`;
14673
14672
  return opaque_asOpaqueType(index);
14674
14673
  };
14675
- class Registers {
14674
+ class registers_Registers {
14676
14675
  bytes;
14677
14676
  asSigned;
14678
14677
  asUnsigned;
@@ -14691,7 +14690,7 @@ class Registers {
14691
14690
  }
14692
14691
  static fromBytes(bytes) {
14693
14692
  debug_check `${bytes.length === registers_NO_OF_REGISTERS << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
14694
- return new Registers(bytes);
14693
+ return new registers_Registers(bytes);
14695
14694
  }
14696
14695
  getBytesAsLittleEndian(index, len) {
14697
14696
  const offset = index << REGISTER_SIZE_SHIFT;
@@ -15005,49 +15004,10 @@ class NoopMissing {
15005
15004
  }
15006
15005
  }
15007
15006
 
15008
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/gas.ts
15009
-
15010
-
15011
- /** Create a new gas counter instance depending on the gas value. */
15012
- function gasCounter(gas) {
15013
- return new GasCounterU64(numbers_tryAsU64(gas));
15014
- }
15015
- class GasCounterU64 {
15016
- gas;
15017
- initialGas;
15018
- constructor(gas) {
15019
- this.gas = gas;
15020
- this.initialGas = tryAsGas(gas);
15021
- }
15022
- set(g) {
15023
- this.gas = numbers_tryAsU64(g);
15024
- }
15025
- get() {
15026
- return tryAsGas(this.gas);
15027
- }
15028
- sub(g) {
15029
- const result = this.gas - numbers_tryAsU64(g);
15030
- if (result >= 0n) {
15031
- this.gas = numbers_tryAsU64(result);
15032
- return false;
15033
- }
15034
- this.gas = numbers_tryAsU64(0n);
15035
- return true;
15036
- }
15037
- used() {
15038
- const gasConsumed = numbers_tryAsU64(this.initialGas) - this.gas;
15039
- // In we have less than zero left we assume that all gas has been consumed.
15040
- if (gasConsumed < 0) {
15041
- return this.initialGas;
15042
- }
15043
- return tryAsGas(gasConsumed);
15044
- }
15045
- }
15046
-
15047
15007
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/memory-index.ts
15048
15008
 
15049
15009
 
15050
- const tryAsMemoryIndex = (index) => {
15010
+ const memory_index_tryAsMemoryIndex = (index) => {
15051
15011
  debug_check `${index >= 0 && index <= MAX_MEMORY_INDEX} Incorrect memory index: ${index}!`;
15052
15012
  return opaque_asOpaqueType(index);
15053
15013
  };
@@ -15061,25 +15021,25 @@ const tryAsSbrkIndex = (index) => {
15061
15021
 
15062
15022
  const memory_consts_PAGE_SIZE_SHIFT = 12;
15063
15023
  // PAGE_SIZE has to be a power of 2
15064
- const PAGE_SIZE = 1 << memory_consts_PAGE_SIZE_SHIFT;
15024
+ const memory_consts_PAGE_SIZE = 1 << memory_consts_PAGE_SIZE_SHIFT;
15065
15025
  const MIN_ALLOCATION_SHIFT = (() => {
15066
15026
  const MIN_ALLOCATION_SHIFT = 7;
15067
15027
  debug_check `${MIN_ALLOCATION_SHIFT >= 0 && MIN_ALLOCATION_SHIFT < memory_consts_PAGE_SIZE_SHIFT} incorrect minimal allocation shift`;
15068
15028
  return MIN_ALLOCATION_SHIFT;
15069
15029
  })();
15070
- const MIN_ALLOCATION_LENGTH = PAGE_SIZE >> MIN_ALLOCATION_SHIFT;
15071
- const LAST_PAGE_NUMBER = (MEMORY_SIZE - PAGE_SIZE) / PAGE_SIZE;
15030
+ const MIN_ALLOCATION_LENGTH = memory_consts_PAGE_SIZE >> MIN_ALLOCATION_SHIFT;
15031
+ const LAST_PAGE_NUMBER = (MEMORY_SIZE - memory_consts_PAGE_SIZE) / memory_consts_PAGE_SIZE;
15072
15032
  /** https://graypaper.fluffylabs.dev/#/68eaa1f/35a60235a602?v=0.6.4 */
15073
15033
  const RESERVED_NUMBER_OF_PAGES = 16;
15074
15034
  /** https://graypaper.fluffylabs.dev/#/68eaa1f/35a60235a602?v=0.6.4 */
15075
- const MAX_NUMBER_OF_PAGES = MEMORY_SIZE / PAGE_SIZE;
15035
+ const MAX_NUMBER_OF_PAGES = MEMORY_SIZE / memory_consts_PAGE_SIZE;
15076
15036
 
15077
15037
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/pages/page-utils.ts
15078
15038
 
15079
15039
 
15080
15040
  /** Ensure that given memory `index` is within `[0...PAGE_SIZE)` and can be used to index a page */
15081
15041
  const tryAsPageIndex = (index) => {
15082
- debug_check `${index >= 0 && index < PAGE_SIZE}, Incorect page index: ${index}!`;
15042
+ debug_check `${index >= 0 && index < memory_consts_PAGE_SIZE}, Incorect page index: ${index}!`;
15083
15043
  return opaque_asOpaqueType(index);
15084
15044
  };
15085
15045
  /** Ensure that given `index` represents an index of one of the pages. */
@@ -15107,17 +15067,17 @@ function getNextPageNumber(pageNumber) {
15107
15067
 
15108
15068
 
15109
15069
  function alignToPageSize(length) {
15110
- return PAGE_SIZE * Math.ceil(length / PAGE_SIZE);
15070
+ return memory_consts_PAGE_SIZE * Math.ceil(length / memory_consts_PAGE_SIZE);
15111
15071
  }
15112
15072
  function getPageNumber(address) {
15113
15073
  return tryAsPageNumber(address >>> memory_consts_PAGE_SIZE_SHIFT);
15114
15074
  }
15115
15075
  function getStartPageIndex(address) {
15116
- return tryAsMemoryIndex((address >>> memory_consts_PAGE_SIZE_SHIFT) << memory_consts_PAGE_SIZE_SHIFT);
15076
+ return memory_index_tryAsMemoryIndex((address >>> memory_consts_PAGE_SIZE_SHIFT) << memory_consts_PAGE_SIZE_SHIFT);
15117
15077
  }
15118
15078
  function getStartPageIndexFromPageNumber(pageNumber) {
15119
15079
  // >>> 0 is needed to avoid changing sign of the number
15120
- return tryAsMemoryIndex((pageNumber << memory_consts_PAGE_SIZE_SHIFT) >>> 0);
15080
+ return memory_index_tryAsMemoryIndex((pageNumber << memory_consts_PAGE_SIZE_SHIFT) >>> 0);
15121
15081
  }
15122
15082
 
15123
15083
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/errors.ts
@@ -15139,7 +15099,7 @@ class PageFault {
15139
15099
  return new PageFault(numbers_tryAsU32(startPageIndex), isAccessFault);
15140
15100
  }
15141
15101
  static fromMemoryIndex(maybeMemoryIndex, isAccessFault = false) {
15142
- const memoryIndex = tryAsMemoryIndex(maybeMemoryIndex % MEMORY_SIZE);
15102
+ const memoryIndex = memory_index_tryAsMemoryIndex(maybeMemoryIndex % MEMORY_SIZE);
15143
15103
  const startPageIndex = getStartPageIndex(memoryIndex);
15144
15104
  return new PageFault(numbers_tryAsU32(startPageIndex), isAccessFault);
15145
15105
  }
@@ -15218,9 +15178,9 @@ class MemoryRange {
15218
15178
  constructor(start, length) {
15219
15179
  this.start = start;
15220
15180
  this.length = length;
15221
- this.end = tryAsMemoryIndex((this.start + this.length) % MEMORY_SIZE);
15181
+ this.end = memory_index_tryAsMemoryIndex((this.start + this.length) % MEMORY_SIZE);
15222
15182
  if (length > 0) {
15223
- this.lastIndex = tryAsMemoryIndex((this.end - 1 + MEMORY_SIZE) % MEMORY_SIZE);
15183
+ this.lastIndex = memory_index_tryAsMemoryIndex((this.end - 1 + MEMORY_SIZE) % MEMORY_SIZE);
15224
15184
  }
15225
15185
  }
15226
15186
  /** Creates a memory range from given starting point and length */
@@ -15263,7 +15223,7 @@ class MemoryRange {
15263
15223
  *
15264
15224
  * it should be in `memory-consts` but it cannot be there because of circular dependency
15265
15225
  */
15266
- const RESERVED_MEMORY_RANGE = MemoryRange.fromStartAndLength(tryAsMemoryIndex(0), RESERVED_NUMBER_OF_PAGES * PAGE_SIZE);
15226
+ const RESERVED_MEMORY_RANGE = MemoryRange.fromStartAndLength(memory_index_tryAsMemoryIndex(0), RESERVED_NUMBER_OF_PAGES * memory_consts_PAGE_SIZE);
15267
15227
 
15268
15228
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/page-range.ts
15269
15229
 
@@ -15301,7 +15261,7 @@ class PageRange {
15301
15261
  // lastIndex is not null because we just ensured that the range is not empty
15302
15262
  const pageWithLastIndex = getPageNumber(range.lastIndex ?? range.end);
15303
15263
  const endPage = getNextPageNumber(pageWithLastIndex);
15304
- if ((startPage === endPage || startPage === pageWithLastIndex) && range.length > PAGE_SIZE) {
15264
+ if ((startPage === endPage || startPage === pageWithLastIndex) && range.length > memory_consts_PAGE_SIZE) {
15305
15265
  // full range
15306
15266
  return new PageRange(startPage, MAX_NUMBER_OF_PAGES);
15307
15267
  }
@@ -15365,8 +15325,8 @@ class ReadablePage extends MemoryPage {
15365
15325
  }
15366
15326
  loadInto(result, startIndex, length) {
15367
15327
  const endIndex = startIndex + length;
15368
- if (endIndex > PAGE_SIZE) {
15369
- return Result.error(PageFault.fromMemoryIndex(this.start + PAGE_SIZE), () => `Page fault: read beyond page boundary at ${this.start + PAGE_SIZE}`);
15328
+ if (endIndex > memory_consts_PAGE_SIZE) {
15329
+ return Result.error(PageFault.fromMemoryIndex(this.start + memory_consts_PAGE_SIZE), () => `Page fault: read beyond page boundary at ${this.start + memory_consts_PAGE_SIZE}`);
15370
15330
  }
15371
15331
  const bytes = this.data.subarray(startIndex, endIndex);
15372
15332
  // we zero the bytes, since data might not yet be initialized at `endIndex`.
@@ -15399,8 +15359,8 @@ class WriteablePage extends MemoryPage {
15399
15359
  constructor(pageNumber, initialData) {
15400
15360
  super(pageNumber);
15401
15361
  const dataLength = initialData?.length ?? 0;
15402
- const initialPageLength = Math.min(PAGE_SIZE, Math.max(dataLength, MIN_ALLOCATION_LENGTH));
15403
- this.buffer = new ArrayBuffer(initialPageLength, { maxByteLength: PAGE_SIZE });
15362
+ const initialPageLength = Math.min(memory_consts_PAGE_SIZE, Math.max(dataLength, MIN_ALLOCATION_LENGTH));
15363
+ this.buffer = new ArrayBuffer(initialPageLength, { maxByteLength: memory_consts_PAGE_SIZE });
15404
15364
  this.view = new Uint8Array(this.buffer);
15405
15365
  if (initialData !== undefined) {
15406
15366
  this.view.set(initialData);
@@ -15408,8 +15368,8 @@ class WriteablePage extends MemoryPage {
15408
15368
  }
15409
15369
  loadInto(result, startIndex, length) {
15410
15370
  const endIndex = startIndex + length;
15411
- if (endIndex > PAGE_SIZE) {
15412
- return Result.error(PageFault.fromMemoryIndex(this.start + PAGE_SIZE), () => `Page fault: read beyond page boundary at ${this.start + PAGE_SIZE}`);
15371
+ if (endIndex > memory_consts_PAGE_SIZE) {
15372
+ return Result.error(PageFault.fromMemoryIndex(this.start + memory_consts_PAGE_SIZE), () => `Page fault: read beyond page boundary at ${this.start + memory_consts_PAGE_SIZE}`);
15413
15373
  }
15414
15374
  const bytes = this.view.subarray(startIndex, endIndex);
15415
15375
  // we zero the bytes, since the view might not yet be initialized at `endIndex`.
@@ -15418,16 +15378,16 @@ class WriteablePage extends MemoryPage {
15418
15378
  return Result.ok(OK);
15419
15379
  }
15420
15380
  storeFrom(startIndex, bytes) {
15421
- if (this.buffer.byteLength < startIndex + bytes.length && this.buffer.byteLength < PAGE_SIZE) {
15422
- const newLength = Math.min(PAGE_SIZE, Math.max(MIN_ALLOCATION_LENGTH, startIndex + bytes.length));
15381
+ if (this.buffer.byteLength < startIndex + bytes.length && this.buffer.byteLength < memory_consts_PAGE_SIZE) {
15382
+ const newLength = Math.min(memory_consts_PAGE_SIZE, Math.max(MIN_ALLOCATION_LENGTH, startIndex + bytes.length));
15423
15383
  this.buffer.resize(newLength);
15424
15384
  }
15425
15385
  this.view.set(bytes, startIndex);
15426
15386
  return Result.ok(OK);
15427
15387
  }
15428
15388
  setData(pageIndex, data) {
15429
- if (this.buffer.byteLength < pageIndex + data.length && this.buffer.byteLength < PAGE_SIZE) {
15430
- const newLength = Math.min(PAGE_SIZE, Math.max(MIN_ALLOCATION_LENGTH, pageIndex + data.length));
15389
+ if (this.buffer.byteLength < pageIndex + data.length && this.buffer.byteLength < memory_consts_PAGE_SIZE) {
15390
+ const newLength = Math.min(memory_consts_PAGE_SIZE, Math.max(MIN_ALLOCATION_LENGTH, pageIndex + data.length));
15431
15391
  this.buffer.resize(newLength);
15432
15392
  }
15433
15393
  this.view.set(data, pageIndex);
@@ -15478,10 +15438,10 @@ class Memory {
15478
15438
  this.memory = memory;
15479
15439
  }
15480
15440
  store(address, bytes) {
15481
- return this.storeFrom(tryAsMemoryIndex(address), bytes);
15441
+ return this.storeFrom(memory_index_tryAsMemoryIndex(address), bytes);
15482
15442
  }
15483
15443
  read(address, output) {
15484
- return this.loadInto(output, tryAsMemoryIndex(address));
15444
+ return this.loadInto(output, memory_index_tryAsMemoryIndex(address));
15485
15445
  }
15486
15446
  reset() {
15487
15447
  this.sbrkIndex = tryAsSbrkIndex(RESERVED_MEMORY_RANGE.end);
@@ -15508,8 +15468,8 @@ class Memory {
15508
15468
  let currentPosition = address;
15509
15469
  let bytesLeft = bytes.length;
15510
15470
  for (const page of pages) {
15511
- const pageStartIndex = tryAsPageIndex(currentPosition % PAGE_SIZE);
15512
- const bytesToWrite = Math.min(PAGE_SIZE - pageStartIndex, bytesLeft);
15471
+ const pageStartIndex = tryAsPageIndex(currentPosition % memory_consts_PAGE_SIZE);
15472
+ const bytesToWrite = Math.min(memory_consts_PAGE_SIZE - pageStartIndex, bytesLeft);
15513
15473
  const sourceStartIndex = currentPosition - address;
15514
15474
  const source = bytes.subarray(sourceStartIndex, sourceStartIndex + bytesToWrite);
15515
15475
  page.storeFrom(pageStartIndex, source);
@@ -15558,8 +15518,8 @@ class Memory {
15558
15518
  let currentPosition = startAddress;
15559
15519
  let bytesLeft = result.length;
15560
15520
  for (const page of pages) {
15561
- const pageStartIndex = tryAsPageIndex(currentPosition % PAGE_SIZE);
15562
- const bytesToRead = Math.min(PAGE_SIZE - pageStartIndex, bytesLeft);
15521
+ const pageStartIndex = tryAsPageIndex(currentPosition % memory_consts_PAGE_SIZE);
15522
+ const bytesToRead = Math.min(memory_consts_PAGE_SIZE - pageStartIndex, bytesLeft);
15563
15523
  const destinationStartIndex = currentPosition - startAddress;
15564
15524
  const destination = result.subarray(destinationStartIndex);
15565
15525
  page.loadInto(destination, pageStartIndex, bytesToRead);
@@ -15586,7 +15546,7 @@ class Memory {
15586
15546
  const newSbrkIndex = tryAsSbrkIndex(alignToPageSize(newVirtualSbrkIndex));
15587
15547
  // TODO [MaSi]: `getPageNumber` works incorrectly for SbrkIndex. Sbrk index should be changed to MemoryIndex
15588
15548
  const firstPageNumber = getPageNumber(currentSbrkIndex);
15589
- const pagesToAllocate = (newSbrkIndex - currentSbrkIndex) / PAGE_SIZE;
15549
+ const pagesToAllocate = (newSbrkIndex - currentSbrkIndex) / memory_consts_PAGE_SIZE;
15590
15550
  const rangeToAllocate = PageRange.fromStartAndLength(firstPageNumber, pagesToAllocate);
15591
15551
  for (const pageNumber of rangeToAllocate) {
15592
15552
  const page = new WriteablePage(pageNumber);
@@ -15641,8 +15601,8 @@ class MemoryBuilder {
15641
15601
  setReadablePages(start, end, data = new Uint8Array()) {
15642
15602
  this.ensureNotFinalized();
15643
15603
  debug_check `${start < end} end has to be bigger than start`;
15644
- debug_check `${start % PAGE_SIZE === 0} start needs to be a multiple of page size (${PAGE_SIZE})`;
15645
- debug_check `${end % PAGE_SIZE === 0} end needs to be a multiple of page size (${PAGE_SIZE})`;
15604
+ debug_check `${start % memory_consts_PAGE_SIZE === 0} start needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
15605
+ debug_check `${end % memory_consts_PAGE_SIZE === 0} end needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
15646
15606
  debug_check `${data.length <= end - start} the initial data is longer than address range`;
15647
15607
  const length = end - start;
15648
15608
  const range = MemoryRange.fromStartAndLength(start, length);
@@ -15651,7 +15611,7 @@ class MemoryBuilder {
15651
15611
  const noOfPages = pages.length;
15652
15612
  for (let i = 0; i < noOfPages; i++) {
15653
15613
  const pageNumber = pages[i];
15654
- const dataChunk = data.subarray(i * PAGE_SIZE, (i + 1) * PAGE_SIZE);
15614
+ const dataChunk = data.subarray(i * memory_consts_PAGE_SIZE, (i + 1) * memory_consts_PAGE_SIZE);
15655
15615
  const page = new ReadablePage(pageNumber, dataChunk);
15656
15616
  this.initialMemory.set(pageNumber, page);
15657
15617
  }
@@ -15669,8 +15629,8 @@ class MemoryBuilder {
15669
15629
  setWriteablePages(start, end, data = new Uint8Array()) {
15670
15630
  this.ensureNotFinalized();
15671
15631
  debug_check `${start < end} end has to be bigger than start`;
15672
- debug_check `${start % PAGE_SIZE === 0} start needs to be a multiple of page size (${PAGE_SIZE})`;
15673
- debug_check `${end % PAGE_SIZE === 0} end needs to be a multiple of page size (${PAGE_SIZE})`;
15632
+ debug_check `${start % memory_consts_PAGE_SIZE === 0} start needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
15633
+ debug_check `${end % memory_consts_PAGE_SIZE === 0} end needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
15674
15634
  debug_check `${data.length <= end - start} the initial data is longer than address range`;
15675
15635
  const length = end - start;
15676
15636
  const range = MemoryRange.fromStartAndLength(start, length);
@@ -15679,7 +15639,7 @@ class MemoryBuilder {
15679
15639
  const noOfPages = pages.length;
15680
15640
  for (let i = 0; i < noOfPages; i++) {
15681
15641
  const pageNumber = pages[i];
15682
- const dataChunk = data.subarray(i * PAGE_SIZE, (i + 1) * PAGE_SIZE);
15642
+ const dataChunk = data.subarray(i * memory_consts_PAGE_SIZE, (i + 1) * memory_consts_PAGE_SIZE);
15683
15643
  const page = new WriteablePage(pageNumber, dataChunk);
15684
15644
  this.initialMemory.set(pageNumber, page);
15685
15645
  }
@@ -15691,8 +15651,8 @@ class MemoryBuilder {
15691
15651
  */
15692
15652
  setData(start, data) {
15693
15653
  this.ensureNotFinalized();
15694
- const pageOffset = start % PAGE_SIZE;
15695
- const remainingSpaceOnPage = PAGE_SIZE - pageOffset;
15654
+ const pageOffset = start % memory_consts_PAGE_SIZE;
15655
+ const remainingSpaceOnPage = memory_consts_PAGE_SIZE - pageOffset;
15696
15656
  debug_check `${data.length <= remainingSpaceOnPage} The data has to fit into a single page.`;
15697
15657
  const length = data.length;
15698
15658
  const range = MemoryRange.fromStartAndLength(start, length);
@@ -15883,27 +15843,27 @@ class Program {
15883
15843
  static fromSpi(blob, args, hasMetadata) {
15884
15844
  const { code: spiCode, metadata } = hasMetadata ? extractCodeAndMetadata(blob) : { code: blob };
15885
15845
  const { code, memory: rawMemory, registers } = decodeStandardProgram(spiCode, args);
15886
- const regs = new Registers();
15846
+ const regs = new registers_Registers();
15887
15847
  regs.copyFrom(registers);
15888
15848
  const memoryBuilder = new MemoryBuilder();
15889
15849
  for (const { start, end, data } of rawMemory.readable) {
15890
- const startIndex = tryAsMemoryIndex(start);
15891
- const endIndex = tryAsMemoryIndex(end);
15850
+ const startIndex = memory_index_tryAsMemoryIndex(start);
15851
+ const endIndex = memory_index_tryAsMemoryIndex(end);
15892
15852
  memoryBuilder.setReadablePages(startIndex, endIndex, data ?? new Uint8Array());
15893
15853
  }
15894
15854
  for (const { start, end, data } of rawMemory.writeable) {
15895
- const startIndex = tryAsMemoryIndex(start);
15896
- const endIndex = tryAsMemoryIndex(end);
15855
+ const startIndex = memory_index_tryAsMemoryIndex(start);
15856
+ const endIndex = memory_index_tryAsMemoryIndex(end);
15897
15857
  memoryBuilder.setWriteablePages(startIndex, endIndex, data ?? new Uint8Array());
15898
15858
  }
15899
- const heapStart = tryAsMemoryIndex(rawMemory.sbrkIndex);
15859
+ const heapStart = memory_index_tryAsMemoryIndex(rawMemory.sbrkIndex);
15900
15860
  const heapEnd = tryAsSbrkIndex(rawMemory.heapEnd);
15901
15861
  const memory = memoryBuilder.finalize(heapStart, heapEnd);
15902
15862
  return new Program(code, regs, memory, metadata);
15903
15863
  }
15904
15864
  static fromGeneric(blob, hasMetadata) {
15905
15865
  const { code, metadata } = hasMetadata ? extractCodeAndMetadata(blob) : { code: blob };
15906
- const regs = new Registers();
15866
+ const regs = new registers_Registers();
15907
15867
  const memory = new Memory();
15908
15868
  return new Program(code, regs, memory, metadata);
15909
15869
  }
@@ -16918,6 +16878,45 @@ class BasicBlocks {
16918
16878
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/basic-blocks/index.ts
16919
16879
 
16920
16880
 
16881
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/gas.ts
16882
+
16883
+
16884
+ /** Create a new gas counter instance depending on the gas value. */
16885
+ function gasCounter(gas) {
16886
+ return new GasCounterU64(numbers_tryAsU64(gas));
16887
+ }
16888
+ class GasCounterU64 {
16889
+ gas;
16890
+ initialGas;
16891
+ constructor(gas) {
16892
+ this.gas = gas;
16893
+ this.initialGas = gas_tryAsGas(gas);
16894
+ }
16895
+ set(g) {
16896
+ this.gas = numbers_tryAsU64(g);
16897
+ }
16898
+ get() {
16899
+ return gas_tryAsGas(this.gas);
16900
+ }
16901
+ sub(g) {
16902
+ const result = this.gas - numbers_tryAsU64(g);
16903
+ if (result >= 0n) {
16904
+ this.gas = numbers_tryAsU64(result);
16905
+ return false;
16906
+ }
16907
+ this.gas = numbers_tryAsU64(0n);
16908
+ return true;
16909
+ }
16910
+ used() {
16911
+ const gasConsumed = numbers_tryAsU64(this.initialGas) - this.gas;
16912
+ // In we have less than zero left we assume that all gas has been consumed.
16913
+ if (gasConsumed < 0) {
16914
+ return this.initialGas;
16915
+ }
16916
+ return gas_tryAsGas(gasConsumed);
16917
+ }
16918
+ }
16919
+
16921
16920
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/instruction-gas-map.ts
16922
16921
 
16923
16922
 
@@ -17494,7 +17493,7 @@ class LoadOps {
17494
17493
  }
17495
17494
  loadNumber(address, registerIndex, numberLength) {
17496
17495
  const registerBytes = this.regs.getBytesAsLittleEndian(registerIndex, REG_SIZE_BYTES);
17497
- const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength), tryAsMemoryIndex(address));
17496
+ const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength), memory_index_tryAsMemoryIndex(address));
17498
17497
  if (loadResult.isError) {
17499
17498
  if (loadResult.error.isAccessFault) {
17500
17499
  this.instructionResult.status = result_Result.FAULT_ACCESS;
@@ -17510,7 +17509,7 @@ class LoadOps {
17510
17509
  loadSignedNumber(address, registerIndex, numberLength) {
17511
17510
  // load all bytes from register to correctly handle the sign.
17512
17511
  const registerBytes = this.regs.getBytesAsLittleEndian(registerIndex, REG_SIZE_BYTES);
17513
- const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength), tryAsMemoryIndex(address));
17512
+ const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength), memory_index_tryAsMemoryIndex(address));
17514
17513
  if (loadResult.isError) {
17515
17514
  if (loadResult.error.isAccessFault) {
17516
17515
  this.instructionResult.status = result_Result.FAULT_ACCESS;
@@ -17932,7 +17931,7 @@ class StoreOps {
17932
17931
  this.store(address, secondImmediateDecoder.getExtendedBytesAsLittleEndian());
17933
17932
  }
17934
17933
  store(address, bytes) {
17935
- const storeResult = this.memory.storeFrom(tryAsMemoryIndex(address), bytes);
17934
+ const storeResult = this.memory.storeFrom(memory_index_tryAsMemoryIndex(address), bytes);
17936
17935
  if (storeResult.isOk) {
17937
17936
  return;
17938
17937
  }
@@ -17941,7 +17940,7 @@ class StoreOps {
17941
17940
  }
17942
17941
  else {
17943
17942
  this.instructionResult.status = result_Result.FAULT;
17944
- this.instructionResult.exitParam = getStartPageIndex(tryAsMemoryIndex(storeResult.error.address));
17943
+ this.instructionResult.exitParam = getStartPageIndex(memory_index_tryAsMemoryIndex(storeResult.error.address));
17945
17944
  }
17946
17945
  }
17947
17946
  }
@@ -18740,11 +18739,11 @@ class ProgramDecoder {
18740
18739
 
18741
18740
 
18742
18741
  const interpreter_logger = Logger.new(import.meta.filename, "pvm");
18743
- class Interpreter {
18742
+ class interpreter_Interpreter {
18744
18743
  useSbrkGas;
18745
- registers = new Registers();
18744
+ registers = new registers_Registers();
18746
18745
  memory = new Memory();
18747
- gas = gasCounter(tryAsGas(0));
18746
+ gas = gasCounter(gas_tryAsGas(0));
18748
18747
  code = new Uint8Array();
18749
18748
  mask = Mask.empty();
18750
18749
  pc = 0;
@@ -18878,8 +18877,8 @@ class Interpreter {
18878
18877
  break;
18879
18878
  case ArgumentType.TWO_REGISTERS:
18880
18879
  if (this.useSbrkGas && currentInstruction === Instruction.SBRK) {
18881
- const calculateSbrkCost = (length) => (alignToPageSize(length) / PAGE_SIZE) * 16;
18882
- const underflow = this.gas.sub(tryAsGas(calculateSbrkCost(this.registers.getLowerU32(argsResult.firstRegisterIndex))));
18880
+ const calculateSbrkCost = (length) => (alignToPageSize(length) / memory_consts_PAGE_SIZE) * 16;
18881
+ const underflow = this.gas.sub(gas_tryAsGas(calculateSbrkCost(this.registers.getLowerU32(argsResult.firstRegisterIndex))));
18883
18882
  if (underflow) {
18884
18883
  this.status = status_Status.OOG;
18885
18884
  return this.status;
@@ -18974,12 +18973,88 @@ class Interpreter {
18974
18973
  }
18975
18974
  }
18976
18975
 
18976
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/debugger-adapter.ts
18977
+
18978
+
18979
+
18980
+
18981
+
18982
+
18983
+ class DebuggerAdapter {
18984
+ pvm;
18985
+ constructor(useSbrkGas = false) {
18986
+ this.pvm = new Interpreter({ useSbrkGas });
18987
+ }
18988
+ resetGeneric(rawProgram, flatRegisters, initialGas) {
18989
+ this.pvm.resetGeneric(rawProgram, 0, tryAsGas(initialGas), new Registers(flatRegisters));
18990
+ }
18991
+ reset(rawProgram, pc, gas, maybeRegisters, maybeMemory) {
18992
+ this.pvm.resetGeneric(rawProgram, pc, tryAsGas(gas), maybeRegisters, maybeMemory);
18993
+ }
18994
+ getPageDump(pageNumber) {
18995
+ const page = this.pvm.getMemoryPage(pageNumber);
18996
+ if (page === null) {
18997
+ // page wasn't allocated so we return an empty page
18998
+ return safeAllocUint8Array(PAGE_SIZE);
18999
+ }
19000
+ if (page.length === PAGE_SIZE) {
19001
+ // page was allocated and has a proper size so we can simply return it
19002
+ return page;
19003
+ }
19004
+ // page was allocated but it is shorter than PAGE_SIZE so we have to extend it
19005
+ const fullPage = safeAllocUint8Array(PAGE_SIZE);
19006
+ fullPage.set(page);
19007
+ return fullPage;
19008
+ }
19009
+ setMemory(address, value) {
19010
+ this.pvm.memory.storeFrom(tryAsMemoryIndex(address), value);
19011
+ }
19012
+ getExitArg() {
19013
+ return this.pvm.getExitParam() ?? 0;
19014
+ }
19015
+ getStatus() {
19016
+ return this.pvm.getStatus();
19017
+ }
19018
+ nextStep() {
19019
+ return this.pvm.nextStep() === Status.OK;
19020
+ }
19021
+ nSteps(steps) {
19022
+ check `${steps >>> 0 > 0} Expected a positive integer got ${steps}`;
19023
+ for (let i = 0; i < steps; i++) {
19024
+ const isOk = this.nextStep();
19025
+ if (!isOk) {
19026
+ return false;
19027
+ }
19028
+ }
19029
+ return true;
19030
+ }
19031
+ getRegisters() {
19032
+ return this.pvm.registers.getAllU64();
19033
+ }
19034
+ setRegisters(registers) {
19035
+ this.pvm.registers.copyFrom(new Registers(registers));
19036
+ }
19037
+ getProgramCounter() {
19038
+ return this.pvm.getPC();
19039
+ }
19040
+ setNextProgramCounter(nextPc) {
19041
+ this.pvm.setNextPC(nextPc);
19042
+ }
19043
+ getGasLeft() {
19044
+ return BigInt(this.pvm.gas.get());
19045
+ }
19046
+ setGasLeft(gas) {
19047
+ this.pvm.gas.set(tryAsGas(gas));
19048
+ }
19049
+ }
19050
+
18977
19051
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/index.ts
18978
19052
 
18979
19053
 
18980
19054
 
18981
19055
 
18982
19056
 
19057
+
18983
19058
  ;// CONCATENATED MODULE: ./node_modules/@fluffylabs/anan-as/build/debug-raw.js
18984
19059
  async function instantiate(module, imports = {}) {
18985
19060
  const adaptedImports = {
@@ -19433,12 +19508,12 @@ class AnanasMemory {
19433
19508
  }
19434
19509
  class AnanasGasCounter {
19435
19510
  instance;
19436
- initialGas = tryAsGas(0n);
19511
+ initialGas = gas_tryAsGas(0n);
19437
19512
  constructor(instance) {
19438
19513
  this.instance = instance;
19439
19514
  }
19440
19515
  get() {
19441
- return tryAsGas(this.instance.getGasLeft());
19516
+ return gas_tryAsGas(this.instance.getGasLeft());
19442
19517
  }
19443
19518
  set(g) {
19444
19519
  this.instance.setGasLeft(BigInt(g));
@@ -19543,7 +19618,7 @@ class InterpreterInstanceManager {
19543
19618
  const instances = [];
19544
19619
  switch (interpreter) {
19545
19620
  case PvmBackend.BuiltIn:
19546
- instances.push(new Interpreter({
19621
+ instances.push(new interpreter_Interpreter({
19547
19622
  useSbrkGas: false,
19548
19623
  }));
19549
19624
  break;
@@ -19717,10 +19792,10 @@ class Info {
19717
19792
  const chunk = encodedInfo.raw.subarray(Number(offset), Number(offset + length));
19718
19793
  const writeResult = memory.storeFrom(outputStart, chunk);
19719
19794
  if (writeResult.isError) {
19720
- logger_logger.trace `INFO(${serviceId}, off: ${offset}, len: ${length}) <- PANIC`;
19795
+ logger_logger.trace `[${this.currentServiceId}] INFO(${serviceId}, off: ${offset}, len: ${length}) <- PANIC`;
19721
19796
  return PvmExecution.Panic;
19722
19797
  }
19723
- logger_logger.trace `INFO(${serviceId}, off: ${offset}, len: ${length}) <- ${bytes_BytesBlob.blobFrom(chunk)}`;
19798
+ logger_logger.trace `[${this.currentServiceId}] INFO(${serviceId}, off: ${offset}, len: ${length}) <- ${bytes_BytesBlob.blobFrom(chunk)}`;
19724
19799
  if (accountInfo === null) {
19725
19800
  regs.set(IN_OUT_REG, HostCallResult.NONE);
19726
19801
  return;
@@ -20816,13 +20891,11 @@ class AccumulateDataItem {
20816
20891
  * - gas cost and reports length for each service (statistics)
20817
20892
  */
20818
20893
  class AccumulateData {
20819
- autoAccumulateServicesByServiceId;
20820
20894
  reportsDataByServiceId;
20821
20895
  transfersByServiceId;
20822
20896
  serviceIds;
20823
20897
  gasLimitByServiceId;
20824
20898
  constructor(reports, transfers, autoAccumulateServicesByServiceId) {
20825
- this.autoAccumulateServicesByServiceId = autoAccumulateServicesByServiceId;
20826
20899
  const serviceIdsFromAutoAccumulate = new Set(autoAccumulateServicesByServiceId.keys());
20827
20900
  const { reportsDataByServiceId, serviceIds: serviceIdsFromReports, gasLimitByServiceId: reportsGasLimitByServiceId, } = this.transformReports(reports);
20828
20901
  this.reportsDataByServiceId = reportsDataByServiceId;
@@ -21142,12 +21215,12 @@ function createMergeContext(chainSpec, state, inputState, results) {
21142
21215
  }
21143
21216
  function updatePrivilegedService(currentServiceId, serviceIdUpdatedByManager, selfUpdatedServiceId) {
21144
21217
  if (currentServiceId === serviceIdUpdatedByManager) {
21145
- return serviceIdUpdatedByManager;
21218
+ return selfUpdatedServiceId;
21146
21219
  }
21147
- return selfUpdatedServiceId;
21220
+ return serviceIdUpdatedByManager;
21148
21221
  }
21149
21222
  function mergePrivilegedServices(mergeContext, [serviceId, { stateUpdate }]) {
21150
- const { outputState, currentPrivilegedServices, chainSpec } = mergeContext;
21223
+ const { outputState, currentPrivilegedServices, chainSpec, privilegedServicesUpdatedByManager } = mergeContext;
21151
21224
  const currentManager = currentPrivilegedServices.manager;
21152
21225
  const currentRegistrar = currentPrivilegedServices.registrar;
21153
21226
  const currentDelegator = currentPrivilegedServices.delegator;
@@ -21165,28 +21238,35 @@ function mergePrivilegedServices(mergeContext, [serviceId, { stateUpdate }]) {
21165
21238
  });
21166
21239
  }
21167
21240
  if (serviceId === currentRegistrar) {
21168
- const newRegistrar = updatePrivilegedService(currentPrivilegedServices.registrar, outputState.privilegedServices.registrar, privilegedServices.registrar);
21241
+ const newRegistrar = updatePrivilegedService(currentPrivilegedServices.registrar, privilegedServicesUpdatedByManager.registrar, privilegedServices.registrar);
21169
21242
  outputState.privilegedServices = PrivilegedServices.create({
21170
21243
  ...outputState.privilegedServices,
21171
21244
  registrar: newRegistrar,
21172
21245
  });
21173
21246
  }
21174
21247
  if (serviceId === currentDelegator) {
21175
- const newDelegator = updatePrivilegedService(currentPrivilegedServices.delegator, outputState.privilegedServices.delegator, privilegedServices.delegator);
21248
+ const newDelegator = updatePrivilegedService(currentPrivilegedServices.delegator, privilegedServicesUpdatedByManager.delegator, privilegedServices.delegator);
21176
21249
  outputState.privilegedServices = PrivilegedServices.create({
21177
21250
  ...outputState.privilegedServices,
21178
21251
  delegator: newDelegator,
21179
21252
  });
21180
21253
  }
21181
- const assignersFromOutputState = outputState.privilegedServices;
21182
- const newAssigners = currentAssigners.map((currentAssigner, coreIndex) => serviceId === currentAssigner
21183
- ? updatePrivilegedService(currentPrivilegedServices.assigners[coreIndex], assignersFromOutputState.assigners[coreIndex], privilegedServices.assigners[coreIndex])
21184
- : currentAssigner);
21185
- const newAssignersPerCore = tryAsPerCore(newAssigners, chainSpec);
21186
- outputState.privilegedServices = PrivilegedServices.create({
21187
- ...outputState.privilegedServices,
21188
- assigners: newAssignersPerCore,
21254
+ let shouldUpdateAssigners = false;
21255
+ const newAssigners = currentAssigners.map((currentAssigner, coreIndex) => {
21256
+ if (serviceId === currentAssigner) {
21257
+ const newAssigner = updatePrivilegedService(currentPrivilegedServices.assigners[coreIndex], privilegedServicesUpdatedByManager.assigners[coreIndex], privilegedServices.assigners[coreIndex]);
21258
+ shouldUpdateAssigners = shouldUpdateAssigners || newAssigner !== currentAssigner;
21259
+ return newAssigner;
21260
+ }
21261
+ return currentAssigner;
21189
21262
  });
21263
+ if (shouldUpdateAssigners) {
21264
+ const newAssignersPerCore = tryAsPerCore(newAssigners, chainSpec);
21265
+ outputState.privilegedServices = PrivilegedServices.create({
21266
+ ...outputState.privilegedServices,
21267
+ assigners: newAssignersPerCore,
21268
+ });
21269
+ }
21190
21270
  }
21191
21271
  }
21192
21272
  function mergeValidatorsData(mergeContext, [serviceId, { stateUpdate }]) {
@@ -21331,7 +21411,7 @@ class Assign {
21331
21411
  const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
21332
21412
  // error while reading the memory.
21333
21413
  if (memoryReadResult.isError) {
21334
- logger_logger.trace `ASSIGN() <- PANIC`;
21414
+ logger_logger.trace `[${this.currentServiceId}] ASSIGN() <- PANIC`;
21335
21415
  return PvmExecution.Panic;
21336
21416
  }
21337
21417
  if (maybeCoreIndex >= this.chainSpec.coresCount) {
@@ -21346,18 +21426,18 @@ class Assign {
21346
21426
  const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
21347
21427
  if (result.isOk) {
21348
21428
  regs.set(assign_IN_OUT_REG, HostCallResult.OK);
21349
- logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
21429
+ logger_logger.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
21350
21430
  return;
21351
21431
  }
21352
21432
  const e = result.error;
21353
21433
  if (e === UpdatePrivilegesError.UnprivilegedService) {
21354
21434
  regs.set(assign_IN_OUT_REG, HostCallResult.HUH);
21355
- logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
21435
+ logger_logger.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
21356
21436
  return;
21357
21437
  }
21358
21438
  if (e === UpdatePrivilegesError.InvalidServiceId) {
21359
21439
  regs.set(assign_IN_OUT_REG, HostCallResult.WHO);
21360
- logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
21440
+ logger_logger.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
21361
21441
  return;
21362
21442
  }
21363
21443
  assertNever(e);
@@ -21428,7 +21508,7 @@ class Bless {
21428
21508
  decoder.resetTo(0);
21429
21509
  const memoryReadResult = memory.loadInto(result, memIndex);
21430
21510
  if (memoryReadResult.isError) {
21431
- logger_logger.trace `BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}) <- PANIC`;
21511
+ logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}) <- PANIC`;
21432
21512
  return PvmExecution.Panic;
21433
21513
  }
21434
21514
  const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
@@ -21441,26 +21521,26 @@ class Bless {
21441
21521
  const authorizersDecoder = decoder_Decoder.fromBlob(res);
21442
21522
  const memoryReadResult = memory.loadInto(res, authorization);
21443
21523
  if (memoryReadResult.isError) {
21444
- logger_logger.trace `BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- PANIC`;
21524
+ logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- PANIC`;
21445
21525
  return PvmExecution.Panic;
21446
21526
  }
21447
21527
  // `a`
21448
21528
  const authorizers = tryAsPerCore(authorizersDecoder.sequenceFixLen(descriptors_codec.u32.asOpaque(), this.chainSpec.coresCount), this.chainSpec);
21449
21529
  const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate);
21450
21530
  if (updateResult.isOk) {
21451
- logger_logger.trace `BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- OK`;
21531
+ logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- OK`;
21452
21532
  regs.set(bless_IN_OUT_REG, HostCallResult.OK);
21453
21533
  return;
21454
21534
  }
21455
21535
  const e = updateResult.error;
21456
21536
  // NOTE: `UpdatePrivilegesError.UnprivilegedService` won't happen in 0.7.1+
21457
21537
  if (e === UpdatePrivilegesError.UnprivilegedService) {
21458
- logger_logger.trace `BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- HUH`;
21538
+ logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- HUH`;
21459
21539
  regs.set(bless_IN_OUT_REG, HostCallResult.HUH);
21460
21540
  return;
21461
21541
  }
21462
21542
  if (e === UpdatePrivilegesError.InvalidServiceId) {
21463
- logger_logger.trace `BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- WHO`;
21543
+ logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- WHO`;
21464
21544
  regs.set(bless_IN_OUT_REG, HostCallResult.WHO);
21465
21545
  return;
21466
21546
  }
@@ -21490,7 +21570,7 @@ class GasHostCall {
21490
21570
  }
21491
21571
  execute(gas, regs) {
21492
21572
  const gasValue = gas.get();
21493
- logger_logger.trace `GAS <- ${gasValue}`;
21573
+ logger_logger.trace `[${this.currentServiceId}] GAS <- ${gasValue}`;
21494
21574
  regs.set(7, numbers_tryAsU64(gasValue));
21495
21575
  return Promise.resolve(undefined);
21496
21576
  }
@@ -21522,7 +21602,7 @@ class Checkpoint {
21522
21602
  async execute(gas, regs) {
21523
21603
  await this.gasHostCall.execute(gas, regs);
21524
21604
  this.partialState.checkpoint();
21525
- logger_logger.trace `CHECKPOINT()`;
21605
+ logger_logger.trace `[${this.currentServiceId}] CHECKPOINT()`;
21526
21606
  return;
21527
21607
  }
21528
21608
  }
@@ -21562,18 +21642,18 @@ class Designate {
21562
21642
  const memoryReadResult = memory.loadInto(res, validatorsStart);
21563
21643
  // error while reading the memory.
21564
21644
  if (memoryReadResult.isError) {
21565
- logger_logger.trace `DESIGNATE() <- PANIC`;
21645
+ logger_logger.trace `[${this.currentServiceId}] DESIGNATE() <- PANIC`;
21566
21646
  return PvmExecution.Panic;
21567
21647
  }
21568
21648
  const decoder = decoder_Decoder.fromBlob(res);
21569
21649
  const validatorsData = decoder.sequenceFixLen(ValidatorData.Codec, this.chainSpec.validatorsCount);
21570
21650
  const result = this.partialState.updateValidatorsData(tryAsPerValidator(validatorsData, this.chainSpec));
21571
21651
  if (result.isError) {
21572
- logger_logger.trace `DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- HUH`;
21652
+ logger_logger.trace `[${this.currentServiceId}] DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- HUH`;
21573
21653
  regs.set(designate_IN_OUT_REG, HostCallResult.HUH);
21574
21654
  }
21575
21655
  else {
21576
- logger_logger.trace `DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- OK`;
21656
+ logger_logger.trace `[${this.currentServiceId}] DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- OK`;
21577
21657
  regs.set(designate_IN_OUT_REG, HostCallResult.OK);
21578
21658
  }
21579
21659
  }
@@ -21614,29 +21694,29 @@ class Eject {
21614
21694
  const previousCodeHash = bytes_Bytes.zero(hash_HASH_SIZE).asOpaque();
21615
21695
  const memoryReadResult = memory.loadInto(previousCodeHash.raw, preimageHashStart);
21616
21696
  if (memoryReadResult.isError) {
21617
- logger_logger.trace `EJECT(${serviceId}) <- PANIC`;
21697
+ logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}) <- PANIC`;
21618
21698
  return PvmExecution.Panic;
21619
21699
  }
21620
21700
  // cannot eject self
21621
21701
  if (serviceId === this.currentServiceId) {
21622
21702
  regs.set(eject_IN_OUT_REG, HostCallResult.WHO);
21623
- logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- WHO`;
21703
+ logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- WHO`;
21624
21704
  return;
21625
21705
  }
21626
21706
  const result = this.partialState.eject(serviceId, previousCodeHash);
21627
21707
  // All good!
21628
21708
  if (result.isOk) {
21629
- logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- OK`;
21709
+ logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- OK`;
21630
21710
  regs.set(eject_IN_OUT_REG, HostCallResult.OK);
21631
21711
  return;
21632
21712
  }
21633
21713
  const e = result.error;
21634
21714
  if (e === EjectError.InvalidService) {
21635
- logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- WHO ${resultToString(result)}`;
21715
+ logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- WHO ${resultToString(result)}`;
21636
21716
  regs.set(eject_IN_OUT_REG, HostCallResult.WHO);
21637
21717
  }
21638
21718
  else if (e === EjectError.InvalidPreimage) {
21639
- logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- HUH ${resultToString(result)}`;
21719
+ logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- HUH ${resultToString(result)}`;
21640
21720
  regs.set(eject_IN_OUT_REG, HostCallResult.HUH);
21641
21721
  }
21642
21722
  else {
@@ -21678,11 +21758,11 @@ class Forget {
21678
21758
  const memoryReadResult = memory.loadInto(hash.raw, hashStart);
21679
21759
  // error while reading the memory.
21680
21760
  if (memoryReadResult.isError) {
21681
- logger_logger.trace `FORGET(${hash}, ${length}) <- PANIC`;
21761
+ logger_logger.trace `[${this.currentServiceId}] FORGET(${hash}, ${length}) <- PANIC`;
21682
21762
  return PvmExecution.Panic;
21683
21763
  }
21684
21764
  const result = this.partialState.forgetPreimage(hash.asOpaque(), length);
21685
- logger_logger.trace `FORGET(${hash}, ${length}) <- ${resultToString(result)}`;
21765
+ logger_logger.trace `[${this.currentServiceId}] FORGET(${hash}, ${length}) <- ${resultToString(result)}`;
21686
21766
  if (result.isOk) {
21687
21767
  regs.set(forget_IN_OUT_REG, HostCallResult.OK);
21688
21768
  }
@@ -21739,11 +21819,11 @@ class New {
21739
21819
  const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
21740
21820
  // error while reading the memory.
21741
21821
  if (memoryReadResult.isError) {
21742
- logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
21822
+ logger_logger.trace `[${this.currentServiceId}] NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
21743
21823
  return PvmExecution.Panic;
21744
21824
  }
21745
21825
  const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage, requestedServiceId);
21746
- logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${resultToString(assignedId)}`;
21826
+ logger_logger.trace `[${this.currentServiceId}] NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${resultToString(assignedId)}`;
21747
21827
  if (assignedId.isOk) {
21748
21828
  regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
21749
21829
  return;
@@ -21803,11 +21883,11 @@ class Provide {
21803
21883
  const preimage = bytes_BytesBlob.blobFrom(safe_alloc_uint8array_safeAllocUint8Array(length));
21804
21884
  const memoryReadResult = memory.loadInto(preimage.raw, preimageStart);
21805
21885
  if (memoryReadResult.isError) {
21806
- logger_logger.trace `PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- PANIC`;
21886
+ logger_logger.trace `[${this.currentServiceId}] PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- PANIC`;
21807
21887
  return PvmExecution.Panic;
21808
21888
  }
21809
21889
  const result = this.partialState.providePreimage(serviceId, preimage);
21810
- logger_logger.trace `PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- ${resultToString(result)}`;
21890
+ logger_logger.trace `[${this.currentServiceId}] PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- ${resultToString(result)}`;
21811
21891
  if (result.isOk) {
21812
21892
  regs.set(provide_IN_OUT_REG, HostCallResult.OK);
21813
21893
  return;
@@ -21863,35 +21943,35 @@ class Query {
21863
21943
  const memoryReadResult = memory.loadInto(hash.raw, hashStart);
21864
21944
  // error while reading the memory.
21865
21945
  if (memoryReadResult.isError) {
21866
- logger_logger.trace `QUERY(${hash}, ${length}) <- PANIC`;
21946
+ logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- PANIC`;
21867
21947
  return PvmExecution.Panic;
21868
21948
  }
21869
21949
  const result = this.partialState.checkPreimageStatus(hash.asOpaque(), length);
21870
21950
  const zero = numbers_tryAsU64(0n);
21871
21951
  if (result === null) {
21872
- logger_logger.trace `QUERY(${hash}, ${length}) <- NONE`;
21952
+ logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- NONE`;
21873
21953
  regs.set(IN_OUT_REG_1, HostCallResult.NONE);
21874
21954
  regs.set(IN_OUT_REG_2, zero);
21875
21955
  return;
21876
21956
  }
21877
21957
  switch (result.status) {
21878
21958
  case PreimageStatusKind.Requested:
21879
- logger_logger.trace `QUERY(${hash}, ${length}) <- REQUESTED`;
21959
+ logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- REQUESTED`;
21880
21960
  regs.set(IN_OUT_REG_1, zero);
21881
21961
  regs.set(IN_OUT_REG_2, zero);
21882
21962
  return;
21883
21963
  case PreimageStatusKind.Available:
21884
- logger_logger.trace `QUERY(${hash}, ${length}) <- AVAILABLE [${result.data}]`;
21964
+ logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- AVAILABLE [${result.data}]`;
21885
21965
  regs.set(IN_OUT_REG_1, numbers_tryAsU64((BigInt(result.data[0]) << UPPER_BITS_SHIFT) + 1n));
21886
21966
  regs.set(IN_OUT_REG_2, zero);
21887
21967
  return;
21888
21968
  case PreimageStatusKind.Unavailable:
21889
- logger_logger.trace `QUERY(${hash}, ${length}) <- UNAVAILABLE [${result.data.join(", ")}]`;
21969
+ logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- UNAVAILABLE [${result.data.join(", ")}]`;
21890
21970
  regs.set(IN_OUT_REG_1, numbers_tryAsU64((BigInt(result.data[0]) << UPPER_BITS_SHIFT) + 2n));
21891
21971
  regs.set(IN_OUT_REG_2, numbers_tryAsU64(result.data[1]));
21892
21972
  return;
21893
21973
  case PreimageStatusKind.Reavailable:
21894
- logger_logger.trace `QUERY(${hash}, ${length}) <- REAVAILABLE [${result.data.join(", ")}]`;
21974
+ logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- REAVAILABLE [${result.data.join(", ")}]`;
21895
21975
  regs.set(IN_OUT_REG_1, numbers_tryAsU64((BigInt(result.data[0]) << UPPER_BITS_SHIFT) + 3n));
21896
21976
  regs.set(IN_OUT_REG_2, numbers_tryAsU64((BigInt(result.data[2]) << UPPER_BITS_SHIFT) + BigInt(result.data[1])));
21897
21977
  return;
@@ -21932,11 +22012,11 @@ class Solicit {
21932
22012
  const hash = bytes_Bytes.zero(hash_HASH_SIZE);
21933
22013
  const memoryReadResult = memory.loadInto(hash.raw, hashStart);
21934
22014
  if (memoryReadResult.isError) {
21935
- logger_logger.trace `SOLICIT(${hash}, ${length}) <- PANIC`;
22015
+ logger_logger.trace `[${this.currentServiceId}] SOLICIT(${hash}, ${length}) <- PANIC`;
21936
22016
  return PvmExecution.Panic;
21937
22017
  }
21938
22018
  const result = this.partialState.requestPreimage(hash.asOpaque(), length);
21939
- logger_logger.trace `SOLICIT(${hash}, ${length}) <- ${resultToString(result)}`;
22019
+ logger_logger.trace `[${this.currentServiceId}] SOLICIT(${hash}, ${length}) <- ${resultToString(result)}`;
21940
22020
  if (result.isOk) {
21941
22021
  regs.set(solicit_IN_OUT_REG, HostCallResult.OK);
21942
22022
  return;
@@ -21994,7 +22074,7 @@ class Transfer {
21994
22074
  */
21995
22075
  basicGasCost = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_2)
21996
22076
  ? gas_tryAsSmallGas(10)
21997
- : (regs) => tryAsGas(10n + regs.get(TRANSFER_GAS_FEE_REG));
22077
+ : (regs) => gas_tryAsGas(10n + regs.get(TRANSFER_GAS_FEE_REG));
21998
22078
  tracedRegisters = traceRegisters(transfer_IN_OUT_REG, AMOUNT_REG, TRANSFER_GAS_FEE_REG, MEMO_START_REG);
21999
22079
  constructor(currentServiceId, partialState) {
22000
22080
  this.currentServiceId = currentServiceId;
@@ -22013,16 +22093,16 @@ class Transfer {
22013
22093
  const memoryReadResult = memory.loadInto(memo.raw, memoStart);
22014
22094
  // page fault while reading the memory.
22015
22095
  if (memoryReadResult.isError) {
22016
- logger_logger.trace `TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- PANIC`;
22096
+ logger_logger.trace `[${this.currentServiceId}] TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- PANIC`;
22017
22097
  return PvmExecution.Panic;
22018
22098
  }
22019
22099
  const transferResult = this.partialState.transfer(destination, amount, transferGasFee, memo);
22020
- logger_logger.trace `TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- ${resultToString(transferResult)}`;
22100
+ logger_logger.trace `[${this.currentServiceId}] TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- ${resultToString(transferResult)}`;
22021
22101
  // All good!
22022
22102
  if (transferResult.isOk) {
22023
22103
  if (compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_2)) {
22024
22104
  // substracting value `t`
22025
- const underflow = gas.sub(tryAsGas(transferGasFee));
22105
+ const underflow = gas.sub(gas_tryAsGas(transferGasFee));
22026
22106
  if (underflow) {
22027
22107
  return PvmExecution.OOG;
22028
22108
  }
@@ -22083,11 +22163,11 @@ class Upgrade {
22083
22163
  const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
22084
22164
  const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
22085
22165
  if (memoryReadResult.isError) {
22086
- logger_logger.trace `UPGRADE(${codeHash}, ${gas}, ${allowance}) <- PANIC`;
22166
+ logger_logger.trace `[${this.currentServiceId}] UPGRADE(${codeHash}, ${gas}, ${allowance}) <- PANIC`;
22087
22167
  return PvmExecution.Panic;
22088
22168
  }
22089
22169
  this.partialState.upgradeService(codeHash.asOpaque(), gas, allowance);
22090
- logger_logger.trace `UPGRADE(${codeHash}, ${gas}, ${allowance})`;
22170
+ logger_logger.trace `[${this.currentServiceId}] UPGRADE(${codeHash}, ${gas}, ${allowance})`;
22091
22171
  regs.set(upgrade_IN_OUT_REG, HostCallResult.OK);
22092
22172
  }
22093
22173
  }
@@ -22121,11 +22201,11 @@ class Yield {
22121
22201
  const hash = bytes_Bytes.zero(hash_HASH_SIZE);
22122
22202
  const memoryReadResult = memory.loadInto(hash.raw, hashStart);
22123
22203
  if (memoryReadResult.isError) {
22124
- logger_logger.trace `YIELD() <- PANIC`;
22204
+ logger_logger.trace `[${this.currentServiceId}] YIELD() <- PANIC`;
22125
22205
  return PvmExecution.Panic;
22126
22206
  }
22127
22207
  this.partialState.yield(hash);
22128
- logger_logger.trace `YIELD(${hash})`;
22208
+ logger_logger.trace `[${this.currentServiceId}] YIELD(${hash})`;
22129
22209
  regs.set(yield_IN_OUT_REG, HostCallResult.OK);
22130
22210
  }
22131
22211
  }
@@ -22168,10 +22248,10 @@ class Fetch {
22168
22248
  const chunk = value === null ? new Uint8Array() : value.raw.subarray(Number(offset), Number(offset + length));
22169
22249
  const storeResult = memory.storeFrom(output, chunk);
22170
22250
  if (storeResult.isError) {
22171
- logger_logger.trace `FETCH(${kind}) <- PANIC`;
22251
+ logger_logger.trace `[${this.currentServiceId}] FETCH(${kind}) <- PANIC`;
22172
22252
  return PvmExecution.Panic;
22173
22253
  }
22174
- logger_logger.trace `FETCH(${kind}) <- ${value?.toStringTruncated()}`;
22254
+ logger_logger.trace `[${this.currentServiceId}] FETCH(${kind}) <- ${value?.toStringTruncated()}`;
22175
22255
  // write result
22176
22256
  regs.set(fetch_IN_OUT_REG, value === null ? HostCallResult.NONE : valueLength);
22177
22257
  }
@@ -22321,7 +22401,7 @@ class LogHostCall {
22321
22401
  }
22322
22402
  memory.loadInto(message, msgStart);
22323
22403
  const level = clampU64ToU32(lvl);
22324
- logger_logger.trace `LOG(${this.currentServiceId}, ${level < Levels.UNKNOWN ? Levels[level] : Levels[Levels.UNKNOWN]}(${lvl}), ${decoder.decode(target)}, ${decoder.decode(message)})`;
22404
+ logger_logger.trace `[${this.currentServiceId}] LOG(${this.currentServiceId}, ${level < Levels.UNKNOWN ? Levels[level] : Levels[Levels.UNKNOWN]}(${lvl}), ${decoder.decode(target)}, ${decoder.decode(message)})`;
22325
22405
  return Promise.resolve(undefined);
22326
22406
  }
22327
22407
  }
@@ -22362,12 +22442,12 @@ class Lookup {
22362
22442
  const preImageHash = bytes_Bytes.zero(hash_HASH_SIZE);
22363
22443
  const memoryReadResult = memory.loadInto(preImageHash.raw, hashAddress);
22364
22444
  if (memoryReadResult.isError) {
22365
- logger_logger.trace `LOOKUP(${serviceId}, ${preImageHash}) <- PANIC`;
22445
+ logger_logger.trace `[${this.currentServiceId}] LOOKUP(${serviceId}, ${preImageHash}) <- PANIC`;
22366
22446
  return PvmExecution.Panic;
22367
22447
  }
22368
22448
  // v
22369
22449
  const preImage = this.account.lookup(serviceId, preImageHash);
22370
- logger_logger.trace `LOOKUP(${serviceId}, ${preImageHash}) <- ${preImage?.toStringTruncated() ?? "<missing>"}...`;
22450
+ logger_logger.trace `[${this.currentServiceId}] LOOKUP(${serviceId}, ${preImageHash}) <- ${preImage?.toStringTruncated() ?? "<missing>"}...`;
22371
22451
  const preImageLength = preImage === null ? numbers_tryAsU64(0) : numbers_tryAsU64(preImage.raw.length);
22372
22452
  const preimageBlobOffset = regs.get(10);
22373
22453
  const lengthToWrite = regs.get(11);
@@ -22464,20 +22544,20 @@ class Read {
22464
22544
  const chunk = value === null ? safe_alloc_uint8array_safeAllocUint8Array(0) : value.raw.subarray(Number(offset), Number(offset + blobLength));
22465
22545
  const memoryWriteResult = memory.storeFrom(destinationAddress, chunk);
22466
22546
  if (memoryWriteResult.isError) {
22467
- logger_logger.trace `READ(${serviceId}, ${rawKey}) <- PANIC`;
22547
+ logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- PANIC`;
22468
22548
  return PvmExecution.Panic;
22469
22549
  }
22470
22550
  if (value === null) {
22471
- logger_logger.trace `READ(${serviceId}, ${rawKey}) <- NONE`;
22551
+ logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- NONE`;
22472
22552
  regs.set(read_IN_OUT_REG, HostCallResult.NONE);
22473
22553
  return;
22474
22554
  }
22475
22555
  if (chunk.length > 0) {
22476
- logger_logger.trace `READ(${serviceId}, ${rawKey}) <- ${bytes_BytesBlob.blobFrom(chunk).toStringTruncated()}`;
22556
+ logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- ${bytes_BytesBlob.blobFrom(chunk).toStringTruncated()}`;
22477
22557
  }
22478
22558
  else {
22479
22559
  // just a query for length of stored data
22480
- logger_logger.trace `READ(${serviceId}, ${rawKey}) <- (${valueLength} ${valueLength === 1n ? "byte" : "bytes"})`;
22560
+ logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- (${valueLength} ${valueLength === 1n ? "byte" : "bytes"})`;
22481
22561
  }
22482
22562
  regs.set(read_IN_OUT_REG, valueLength);
22483
22563
  }
@@ -22521,7 +22601,7 @@ class Write {
22521
22601
  const rawStorageKey = safe_alloc_uint8array_safeAllocUint8Array(storageKeyLengthClamped);
22522
22602
  const keyLoadingResult = memory.loadInto(rawStorageKey, storageKeyStartAddress);
22523
22603
  if (keyLoadingResult.isError) {
22524
- logger_logger.trace `WRITE() <- PANIC`;
22604
+ logger_logger.trace `[${this.currentServiceId}] WRITE() <- PANIC`;
22525
22605
  return PvmExecution.Panic;
22526
22606
  }
22527
22607
  // k
@@ -22531,14 +22611,14 @@ class Write {
22531
22611
  const valueLoadingResult = memory.loadInto(value, valueStart);
22532
22612
  // Note [MaSo] this is ok to return bcs if valueLength is 0, then this panic won't happen
22533
22613
  if (valueLoadingResult.isError) {
22534
- logger_logger.trace `WRITE(${storageKey}) <- PANIC`;
22614
+ logger_logger.trace `[${this.currentServiceId}] WRITE(${storageKey}) <- PANIC`;
22535
22615
  return PvmExecution.Panic;
22536
22616
  }
22537
22617
  /** https://graypaper.fluffylabs.dev/#/9a08063/33af0133b201?v=0.6.6 */
22538
22618
  const maybeValue = valueLength === 0n ? null : bytes_BytesBlob.blobFrom(value);
22539
22619
  // a
22540
22620
  const result = this.account.write(storageKey, maybeValue);
22541
- logger_logger.trace `WRITE(${storageKey}, ${maybeValue?.toStringTruncated() ?? "remove"}) <- ${resultToString(result)}`;
22621
+ logger_logger.trace `[${this.currentServiceId}] WRITE(${storageKey}, ${maybeValue?.toStringTruncated() ?? "remove"}) <- ${resultToString(result)}`;
22542
22622
  if (result.isError) {
22543
22623
  regs.set(write_IN_OUT_REG, HostCallResult.FULL);
22544
22624
  return;
@@ -22767,7 +22847,7 @@ class Accumulate {
22767
22847
  serviceId,
22768
22848
  argsLength: numbers_tryAsU32(transfers.length + operands.length),
22769
22849
  });
22770
- const result = await executor.run(invocationArgs, tryAsGas(gas));
22850
+ const result = await executor.run(invocationArgs, gas_tryAsGas(gas));
22771
22851
  const [newState, checkpoint] = partialState.getStateUpdates();
22772
22852
  /**
22773
22853
  * PVM invocation returned and error so we return the checkpoint
@@ -22968,19 +23048,19 @@ class Accumulate {
22968
23048
  for (let serviceIndex = 0; serviceIndex < serviceIdsLength; serviceIndex += 1) {
22969
23049
  const serviceId = serviceIds[serviceIndex];
22970
23050
  const checkpoint = AccumulationStateUpdate.copyFrom(inputStateUpdate);
22971
- const promise = this.accumulateSingleService(serviceId, accumulateData.getTransfers(serviceId), accumulateData.getOperands(serviceId), accumulateData.getGasLimit(serviceId), slot, entropy, AccumulationStateUpdate.copyFrom(inputStateUpdate)).then(({ consumedGas, stateUpdate }) => ({
22972
- consumedGas,
22973
- stateUpdate: stateUpdate === null ? checkpoint : stateUpdate,
22974
- }));
23051
+ const promise = this.accumulateSingleService(serviceId, accumulateData.getTransfers(serviceId), accumulateData.getOperands(serviceId), accumulateData.getGasLimit(serviceId), slot, entropy, AccumulationStateUpdate.copyFrom(inputStateUpdate)).then(({ consumedGas, stateUpdate }) => {
23052
+ const resultEntry = [
23053
+ serviceId,
23054
+ {
23055
+ consumedGas,
23056
+ stateUpdate: stateUpdate === null ? checkpoint : stateUpdate,
23057
+ },
23058
+ ];
23059
+ return resultEntry;
23060
+ });
22975
23061
  resultPromises[serviceIndex] = promise;
22976
23062
  }
22977
- return Promise.all(resultPromises).then((results) => {
22978
- const map = new Map();
22979
- for (let serviceIndex = 0; serviceIndex < serviceIdsLength; serviceIndex += 1) {
22980
- map.set(serviceIds[serviceIndex], results[serviceIndex]);
22981
- }
22982
- return map;
22983
- });
23063
+ return Promise.all(resultPromises).then((results) => new Map(results));
22984
23064
  }
22985
23065
  /**
22986
23066
  * A method that updates `recentlyAccumulated`, `accumulationQueue` and `timeslot` in state
@@ -23069,9 +23149,10 @@ class Accumulate {
23069
23149
  const _gasCost = gasCost;
23070
23150
  assertEmpty(rest);
23071
23151
  const accumulated = accumulatableReports.subview(0, accumulatedReports);
23072
- const { yieldedRoot, services, transfers: _transfers, validatorsData, privilegedServices, authorizationQueues, ...stateUpdateRest } = state;
23152
+ const { yieldedRoot, services, transfers, validatorsData, privilegedServices, authorizationQueues, ...stateUpdateRest } = state;
23073
23153
  assertEmpty(stateUpdateRest);
23074
- // yielded root is retrieved after each pvm invocation so we can ignore it here
23154
+ // transfers and yielded root are retrieved after each pvm invocation so we can ignore it here
23155
+ const _transfers = transfers;
23075
23156
  const _yieldedRoot = yieldedRoot;
23076
23157
  if (this.hasDuplicatedServiceIdCreated(services.created)) {
23077
23158
  accumulate_logger.trace `Duplicated Service creation detected. Block is invalid.`;
@@ -23170,7 +23251,7 @@ class DeferredTransfers {
23170
23251
  partiallyUpdatedState.updateServiceInfo(serviceId, newInfo);
23171
23252
  const partialState = new AccumulateExternalities(this.chainSpec, this.blake2b, partiallyUpdatedState, serviceId, serviceId, timeslot);
23172
23253
  const fetchExternalities = FetchExternalities.createForOnTransfer({ entropy, transfers }, this.chainSpec);
23173
- let consumedGas = tryAsGas(0);
23254
+ let consumedGas = gas_tryAsGas(0);
23174
23255
  const hasTransfers = transfers.length > 0;
23175
23256
  const isCodeCorrect = code !== null && code.length <= W_C;
23176
23257
  if (!hasTransfers || !isCodeCorrect) {
@@ -23188,7 +23269,7 @@ class DeferredTransfers {
23188
23269
  const executor = await PvmExecutor.createOnTransferExecutor(serviceId, code, { partialState, fetchExternalities }, this.pvm);
23189
23270
  const args = encoder_Encoder.encodeObject(deferred_transfers_ARGS_CODEC, { timeslot, serviceId, transfersLength: numbers_tryAsU32(transfers.length) }, this.chainSpec);
23190
23271
  const gas = transfers.reduce((acc, item) => acc + item.gas, 0n);
23191
- consumedGas = (await executor.run(args, tryAsGas(gas))).consumedGas;
23272
+ consumedGas = (await executor.run(args, gas_tryAsGas(gas))).consumedGas;
23192
23273
  }
23193
23274
  transferStatistics.set(serviceId, { count: numbers_tryAsU32(transfers.length), gasUsed: tryAsServiceGas(consumedGas) });
23194
23275
  const [updatedState] = partialState.getStateUpdates();
@@ -25002,7 +25083,7 @@ async function createImporter(config) {
25002
25083
  const interpreter = config.workerParams.pvm;
25003
25084
  const blocks = db.getBlocksDb();
25004
25085
  const states = db.getStatesDb();
25005
- const hasher = new TransitionHasher(chainSpec, await keccakHasher, await blake2b);
25086
+ const hasher = new TransitionHasher(await keccakHasher, await blake2b);
25006
25087
  const importer = new Importer(chainSpec, interpreter, hasher, main_logger, blocks, states);
25007
25088
  return {
25008
25089
  importer,