@typeberry/jam 0.4.0-fcdfbb1 → 0.4.1-9e565b9
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/README.md +5 -0
- package/bootstrap-generator.mjs +33 -8
- package/bootstrap-generator.mjs.map +1 -1
- package/bootstrap-importer.mjs +313 -208
- package/bootstrap-importer.mjs.map +1 -1
- package/bootstrap-network.mjs +8 -7
- package/bootstrap-network.mjs.map +1 -1
- package/index.js +315 -210
- package/index.js.map +1 -1
- package/package.json +1 -1
package/bootstrap-importer.mjs
CHANGED
|
@@ -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
|
-
|
|
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
|
-
*
|
|
3613
|
-
*
|
|
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
|
-
*
|
|
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.
|
|
@@ -10628,11 +10632,32 @@ const ENTROPY_ENTRIES = 4;
|
|
|
10628
10632
|
|
|
10629
10633
|
var state_update_UpdatePreimageKind;
|
|
10630
10634
|
(function (UpdatePreimageKind) {
|
|
10631
|
-
/**
|
|
10635
|
+
/**
|
|
10636
|
+
* Insert new preimage and optionally update it's lookup history.
|
|
10637
|
+
*
|
|
10638
|
+
* Used in: `provide`
|
|
10639
|
+
*
|
|
10640
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/383904383904?v=0.7.2
|
|
10641
|
+
*/
|
|
10632
10642
|
UpdatePreimageKind[UpdatePreimageKind["Provide"] = 0] = "Provide";
|
|
10633
|
-
/**
|
|
10643
|
+
/**
|
|
10644
|
+
* Remove a preimage and it's lookup history.
|
|
10645
|
+
*
|
|
10646
|
+
* Used in: `forget` and `eject`
|
|
10647
|
+
*
|
|
10648
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/38c701380202?v=0.7.2
|
|
10649
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/379102379302?v=0.7.2
|
|
10650
|
+
*/
|
|
10634
10651
|
UpdatePreimageKind[UpdatePreimageKind["Remove"] = 1] = "Remove";
|
|
10635
|
-
/**
|
|
10652
|
+
/**
|
|
10653
|
+
* Update or add lookup history for preimage hash/len to given value.
|
|
10654
|
+
*
|
|
10655
|
+
* Used in: `solicit` and `forget`
|
|
10656
|
+
*
|
|
10657
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/382802382802?v=0.7.2
|
|
10658
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/384002384b02?v=0.7.2
|
|
10659
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/38c60038ea00?v=0.7.2
|
|
10660
|
+
*/
|
|
10636
10661
|
UpdatePreimageKind[UpdatePreimageKind["UpdateOrAdd"] = 2] = "UpdateOrAdd";
|
|
10637
10662
|
})(state_update_UpdatePreimageKind || (state_update_UpdatePreimageKind = {}));
|
|
10638
10663
|
/**
|
|
@@ -10640,7 +10665,7 @@ var state_update_UpdatePreimageKind;
|
|
|
10640
10665
|
*
|
|
10641
10666
|
* Can be one of the following cases:
|
|
10642
10667
|
* 1. Provide a new preimage blob and set the lookup history to available at `slot`.
|
|
10643
|
-
* 2. Remove (
|
|
10668
|
+
* 2. Remove (forget) a preimage and it's lookup history.
|
|
10644
10669
|
* 3. Update `LookupHistory` with given value.
|
|
10645
10670
|
*/
|
|
10646
10671
|
class UpdatePreimage {
|
|
@@ -13210,7 +13235,6 @@ class LeafNode {
|
|
|
13210
13235
|
/**
|
|
13211
13236
|
* Get the byte length of embedded value.
|
|
13212
13237
|
*
|
|
13213
|
-
* @remark
|
|
13214
13238
|
* Note in case this node only contains hash this is going to be 0.
|
|
13215
13239
|
*/
|
|
13216
13240
|
getValueLength() {
|
|
@@ -13221,7 +13245,6 @@ class LeafNode {
|
|
|
13221
13245
|
/**
|
|
13222
13246
|
* Returns the embedded value.
|
|
13223
13247
|
*
|
|
13224
|
-
* @remark
|
|
13225
13248
|
* Note that this is going to be empty for a regular leaf node (i.e. containing a hash).
|
|
13226
13249
|
*/
|
|
13227
13250
|
getValue() {
|
|
@@ -13231,7 +13254,6 @@ class LeafNode {
|
|
|
13231
13254
|
/**
|
|
13232
13255
|
* Returns contained value hash.
|
|
13233
13256
|
*
|
|
13234
|
-
* @remark
|
|
13235
13257
|
* Note that for embedded value this is going to be full 0-padded 32 bytes.
|
|
13236
13258
|
*/
|
|
13237
13259
|
getValueHash() {
|
|
@@ -14252,7 +14274,11 @@ class PartiallyUpdatedState {
|
|
|
14252
14274
|
const service = this.state.getService(serviceId);
|
|
14253
14275
|
return service?.getPreimage(hash) ?? null;
|
|
14254
14276
|
}
|
|
14255
|
-
/**
|
|
14277
|
+
/**
|
|
14278
|
+
* Get status of a preimage of current service taking into account any updates.
|
|
14279
|
+
*
|
|
14280
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/110201110201?v=0.7.2
|
|
14281
|
+
*/
|
|
14256
14282
|
getLookupHistory(currentTimeslot, serviceId, hash, length) {
|
|
14257
14283
|
const updatedService = this.stateUpdate.services.updated.get(serviceId);
|
|
14258
14284
|
/** Return lookup history item for newly created service */
|
|
@@ -14289,12 +14315,7 @@ class PartiallyUpdatedState {
|
|
|
14289
14315
|
return new LookupHistoryItem(hash, updatedPreimage.length, service_tryAsLookupHistorySlots([currentTimeslot]));
|
|
14290
14316
|
}
|
|
14291
14317
|
case state_update_UpdatePreimageKind.Remove: {
|
|
14292
|
-
|
|
14293
|
-
// kinda impossible, since we know it's there because it's removed.
|
|
14294
|
-
if (state === null) {
|
|
14295
|
-
return null;
|
|
14296
|
-
}
|
|
14297
|
-
return new LookupHistoryItem(hash, state.length, service_tryAsLookupHistorySlots([...state.slots, currentTimeslot]));
|
|
14318
|
+
return null;
|
|
14298
14319
|
}
|
|
14299
14320
|
case state_update_UpdatePreimageKind.UpdateOrAdd: {
|
|
14300
14321
|
return action.item;
|
|
@@ -14387,7 +14408,7 @@ const gas_tryAsSmallGas = (v) => opaque_asOpaqueType(numbers_tryAsU32(v));
|
|
|
14387
14408
|
/** Attempt to convert given number into U64 gas representation. */
|
|
14388
14409
|
const tryAsBigGas = (v) => opaque_asOpaqueType(numbers_tryAsU64(v));
|
|
14389
14410
|
/** Attempt to convert given number into gas. */
|
|
14390
|
-
const
|
|
14411
|
+
const gas_tryAsGas = (v) => typeof v === "number" && v < 2 ** 32 ? gas_tryAsSmallGas(v) : tryAsBigGas(v);
|
|
14391
14412
|
|
|
14392
14413
|
;// CONCATENATED MODULE: ./packages/core/pvm-interface/memory.ts
|
|
14393
14414
|
|
|
@@ -14670,7 +14691,7 @@ const tryAsRegisterIndex = (index) => {
|
|
|
14670
14691
|
debug_check `${index >= 0 && index < registers_NO_OF_REGISTERS} Incorrect register index: ${index}!`;
|
|
14671
14692
|
return opaque_asOpaqueType(index);
|
|
14672
14693
|
};
|
|
14673
|
-
class
|
|
14694
|
+
class registers_Registers {
|
|
14674
14695
|
bytes;
|
|
14675
14696
|
asSigned;
|
|
14676
14697
|
asUnsigned;
|
|
@@ -14689,7 +14710,7 @@ class Registers {
|
|
|
14689
14710
|
}
|
|
14690
14711
|
static fromBytes(bytes) {
|
|
14691
14712
|
debug_check `${bytes.length === registers_NO_OF_REGISTERS << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
|
|
14692
|
-
return new
|
|
14713
|
+
return new registers_Registers(bytes);
|
|
14693
14714
|
}
|
|
14694
14715
|
getBytesAsLittleEndian(index, len) {
|
|
14695
14716
|
const offset = index << REGISTER_SIZE_SHIFT;
|
|
@@ -15003,49 +15024,10 @@ class NoopMissing {
|
|
|
15003
15024
|
}
|
|
15004
15025
|
}
|
|
15005
15026
|
|
|
15006
|
-
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/gas.ts
|
|
15007
|
-
|
|
15008
|
-
|
|
15009
|
-
/** Create a new gas counter instance depending on the gas value. */
|
|
15010
|
-
function gasCounter(gas) {
|
|
15011
|
-
return new GasCounterU64(numbers_tryAsU64(gas));
|
|
15012
|
-
}
|
|
15013
|
-
class GasCounterU64 {
|
|
15014
|
-
gas;
|
|
15015
|
-
initialGas;
|
|
15016
|
-
constructor(gas) {
|
|
15017
|
-
this.gas = gas;
|
|
15018
|
-
this.initialGas = tryAsGas(gas);
|
|
15019
|
-
}
|
|
15020
|
-
set(g) {
|
|
15021
|
-
this.gas = numbers_tryAsU64(g);
|
|
15022
|
-
}
|
|
15023
|
-
get() {
|
|
15024
|
-
return tryAsGas(this.gas);
|
|
15025
|
-
}
|
|
15026
|
-
sub(g) {
|
|
15027
|
-
const result = this.gas - numbers_tryAsU64(g);
|
|
15028
|
-
if (result >= 0n) {
|
|
15029
|
-
this.gas = numbers_tryAsU64(result);
|
|
15030
|
-
return false;
|
|
15031
|
-
}
|
|
15032
|
-
this.gas = numbers_tryAsU64(0n);
|
|
15033
|
-
return true;
|
|
15034
|
-
}
|
|
15035
|
-
used() {
|
|
15036
|
-
const gasConsumed = numbers_tryAsU64(this.initialGas) - this.gas;
|
|
15037
|
-
// In we have less than zero left we assume that all gas has been consumed.
|
|
15038
|
-
if (gasConsumed < 0) {
|
|
15039
|
-
return this.initialGas;
|
|
15040
|
-
}
|
|
15041
|
-
return tryAsGas(gasConsumed);
|
|
15042
|
-
}
|
|
15043
|
-
}
|
|
15044
|
-
|
|
15045
15027
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/memory-index.ts
|
|
15046
15028
|
|
|
15047
15029
|
|
|
15048
|
-
const
|
|
15030
|
+
const memory_index_tryAsMemoryIndex = (index) => {
|
|
15049
15031
|
debug_check `${index >= 0 && index <= MAX_MEMORY_INDEX} Incorrect memory index: ${index}!`;
|
|
15050
15032
|
return opaque_asOpaqueType(index);
|
|
15051
15033
|
};
|
|
@@ -15059,25 +15041,25 @@ const tryAsSbrkIndex = (index) => {
|
|
|
15059
15041
|
|
|
15060
15042
|
const memory_consts_PAGE_SIZE_SHIFT = 12;
|
|
15061
15043
|
// PAGE_SIZE has to be a power of 2
|
|
15062
|
-
const
|
|
15044
|
+
const memory_consts_PAGE_SIZE = 1 << memory_consts_PAGE_SIZE_SHIFT;
|
|
15063
15045
|
const MIN_ALLOCATION_SHIFT = (() => {
|
|
15064
15046
|
const MIN_ALLOCATION_SHIFT = 7;
|
|
15065
15047
|
debug_check `${MIN_ALLOCATION_SHIFT >= 0 && MIN_ALLOCATION_SHIFT < memory_consts_PAGE_SIZE_SHIFT} incorrect minimal allocation shift`;
|
|
15066
15048
|
return MIN_ALLOCATION_SHIFT;
|
|
15067
15049
|
})();
|
|
15068
|
-
const MIN_ALLOCATION_LENGTH =
|
|
15069
|
-
const LAST_PAGE_NUMBER = (MEMORY_SIZE -
|
|
15050
|
+
const MIN_ALLOCATION_LENGTH = memory_consts_PAGE_SIZE >> MIN_ALLOCATION_SHIFT;
|
|
15051
|
+
const LAST_PAGE_NUMBER = (MEMORY_SIZE - memory_consts_PAGE_SIZE) / memory_consts_PAGE_SIZE;
|
|
15070
15052
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/35a60235a602?v=0.6.4 */
|
|
15071
15053
|
const RESERVED_NUMBER_OF_PAGES = 16;
|
|
15072
15054
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/35a60235a602?v=0.6.4 */
|
|
15073
|
-
const MAX_NUMBER_OF_PAGES = MEMORY_SIZE /
|
|
15055
|
+
const MAX_NUMBER_OF_PAGES = MEMORY_SIZE / memory_consts_PAGE_SIZE;
|
|
15074
15056
|
|
|
15075
15057
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/pages/page-utils.ts
|
|
15076
15058
|
|
|
15077
15059
|
|
|
15078
15060
|
/** Ensure that given memory `index` is within `[0...PAGE_SIZE)` and can be used to index a page */
|
|
15079
15061
|
const tryAsPageIndex = (index) => {
|
|
15080
|
-
debug_check `${index >= 0 && index <
|
|
15062
|
+
debug_check `${index >= 0 && index < memory_consts_PAGE_SIZE}, Incorect page index: ${index}!`;
|
|
15081
15063
|
return opaque_asOpaqueType(index);
|
|
15082
15064
|
};
|
|
15083
15065
|
/** Ensure that given `index` represents an index of one of the pages. */
|
|
@@ -15105,17 +15087,17 @@ function getNextPageNumber(pageNumber) {
|
|
|
15105
15087
|
|
|
15106
15088
|
|
|
15107
15089
|
function alignToPageSize(length) {
|
|
15108
|
-
return
|
|
15090
|
+
return memory_consts_PAGE_SIZE * Math.ceil(length / memory_consts_PAGE_SIZE);
|
|
15109
15091
|
}
|
|
15110
15092
|
function getPageNumber(address) {
|
|
15111
15093
|
return tryAsPageNumber(address >>> memory_consts_PAGE_SIZE_SHIFT);
|
|
15112
15094
|
}
|
|
15113
15095
|
function getStartPageIndex(address) {
|
|
15114
|
-
return
|
|
15096
|
+
return memory_index_tryAsMemoryIndex((address >>> memory_consts_PAGE_SIZE_SHIFT) << memory_consts_PAGE_SIZE_SHIFT);
|
|
15115
15097
|
}
|
|
15116
15098
|
function getStartPageIndexFromPageNumber(pageNumber) {
|
|
15117
15099
|
// >>> 0 is needed to avoid changing sign of the number
|
|
15118
|
-
return
|
|
15100
|
+
return memory_index_tryAsMemoryIndex((pageNumber << memory_consts_PAGE_SIZE_SHIFT) >>> 0);
|
|
15119
15101
|
}
|
|
15120
15102
|
|
|
15121
15103
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/errors.ts
|
|
@@ -15137,7 +15119,7 @@ class PageFault {
|
|
|
15137
15119
|
return new PageFault(numbers_tryAsU32(startPageIndex), isAccessFault);
|
|
15138
15120
|
}
|
|
15139
15121
|
static fromMemoryIndex(maybeMemoryIndex, isAccessFault = false) {
|
|
15140
|
-
const memoryIndex =
|
|
15122
|
+
const memoryIndex = memory_index_tryAsMemoryIndex(maybeMemoryIndex % MEMORY_SIZE);
|
|
15141
15123
|
const startPageIndex = getStartPageIndex(memoryIndex);
|
|
15142
15124
|
return new PageFault(numbers_tryAsU32(startPageIndex), isAccessFault);
|
|
15143
15125
|
}
|
|
@@ -15216,9 +15198,9 @@ class MemoryRange {
|
|
|
15216
15198
|
constructor(start, length) {
|
|
15217
15199
|
this.start = start;
|
|
15218
15200
|
this.length = length;
|
|
15219
|
-
this.end =
|
|
15201
|
+
this.end = memory_index_tryAsMemoryIndex((this.start + this.length) % MEMORY_SIZE);
|
|
15220
15202
|
if (length > 0) {
|
|
15221
|
-
this.lastIndex =
|
|
15203
|
+
this.lastIndex = memory_index_tryAsMemoryIndex((this.end - 1 + MEMORY_SIZE) % MEMORY_SIZE);
|
|
15222
15204
|
}
|
|
15223
15205
|
}
|
|
15224
15206
|
/** Creates a memory range from given starting point and length */
|
|
@@ -15261,7 +15243,7 @@ class MemoryRange {
|
|
|
15261
15243
|
*
|
|
15262
15244
|
* it should be in `memory-consts` but it cannot be there because of circular dependency
|
|
15263
15245
|
*/
|
|
15264
|
-
const RESERVED_MEMORY_RANGE = MemoryRange.fromStartAndLength(
|
|
15246
|
+
const RESERVED_MEMORY_RANGE = MemoryRange.fromStartAndLength(memory_index_tryAsMemoryIndex(0), RESERVED_NUMBER_OF_PAGES * memory_consts_PAGE_SIZE);
|
|
15265
15247
|
|
|
15266
15248
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/page-range.ts
|
|
15267
15249
|
|
|
@@ -15299,7 +15281,7 @@ class PageRange {
|
|
|
15299
15281
|
// lastIndex is not null because we just ensured that the range is not empty
|
|
15300
15282
|
const pageWithLastIndex = getPageNumber(range.lastIndex ?? range.end);
|
|
15301
15283
|
const endPage = getNextPageNumber(pageWithLastIndex);
|
|
15302
|
-
if ((startPage === endPage || startPage === pageWithLastIndex) && range.length >
|
|
15284
|
+
if ((startPage === endPage || startPage === pageWithLastIndex) && range.length > memory_consts_PAGE_SIZE) {
|
|
15303
15285
|
// full range
|
|
15304
15286
|
return new PageRange(startPage, MAX_NUMBER_OF_PAGES);
|
|
15305
15287
|
}
|
|
@@ -15363,8 +15345,8 @@ class ReadablePage extends MemoryPage {
|
|
|
15363
15345
|
}
|
|
15364
15346
|
loadInto(result, startIndex, length) {
|
|
15365
15347
|
const endIndex = startIndex + length;
|
|
15366
|
-
if (endIndex >
|
|
15367
|
-
return Result.error(PageFault.fromMemoryIndex(this.start +
|
|
15348
|
+
if (endIndex > memory_consts_PAGE_SIZE) {
|
|
15349
|
+
return Result.error(PageFault.fromMemoryIndex(this.start + memory_consts_PAGE_SIZE), () => `Page fault: read beyond page boundary at ${this.start + memory_consts_PAGE_SIZE}`);
|
|
15368
15350
|
}
|
|
15369
15351
|
const bytes = this.data.subarray(startIndex, endIndex);
|
|
15370
15352
|
// we zero the bytes, since data might not yet be initialized at `endIndex`.
|
|
@@ -15397,8 +15379,8 @@ class WriteablePage extends MemoryPage {
|
|
|
15397
15379
|
constructor(pageNumber, initialData) {
|
|
15398
15380
|
super(pageNumber);
|
|
15399
15381
|
const dataLength = initialData?.length ?? 0;
|
|
15400
|
-
const initialPageLength = Math.min(
|
|
15401
|
-
this.buffer = new ArrayBuffer(initialPageLength, { maxByteLength:
|
|
15382
|
+
const initialPageLength = Math.min(memory_consts_PAGE_SIZE, Math.max(dataLength, MIN_ALLOCATION_LENGTH));
|
|
15383
|
+
this.buffer = new ArrayBuffer(initialPageLength, { maxByteLength: memory_consts_PAGE_SIZE });
|
|
15402
15384
|
this.view = new Uint8Array(this.buffer);
|
|
15403
15385
|
if (initialData !== undefined) {
|
|
15404
15386
|
this.view.set(initialData);
|
|
@@ -15406,8 +15388,8 @@ class WriteablePage extends MemoryPage {
|
|
|
15406
15388
|
}
|
|
15407
15389
|
loadInto(result, startIndex, length) {
|
|
15408
15390
|
const endIndex = startIndex + length;
|
|
15409
|
-
if (endIndex >
|
|
15410
|
-
return Result.error(PageFault.fromMemoryIndex(this.start +
|
|
15391
|
+
if (endIndex > memory_consts_PAGE_SIZE) {
|
|
15392
|
+
return Result.error(PageFault.fromMemoryIndex(this.start + memory_consts_PAGE_SIZE), () => `Page fault: read beyond page boundary at ${this.start + memory_consts_PAGE_SIZE}`);
|
|
15411
15393
|
}
|
|
15412
15394
|
const bytes = this.view.subarray(startIndex, endIndex);
|
|
15413
15395
|
// we zero the bytes, since the view might not yet be initialized at `endIndex`.
|
|
@@ -15416,16 +15398,16 @@ class WriteablePage extends MemoryPage {
|
|
|
15416
15398
|
return Result.ok(OK);
|
|
15417
15399
|
}
|
|
15418
15400
|
storeFrom(startIndex, bytes) {
|
|
15419
|
-
if (this.buffer.byteLength < startIndex + bytes.length && this.buffer.byteLength <
|
|
15420
|
-
const newLength = Math.min(
|
|
15401
|
+
if (this.buffer.byteLength < startIndex + bytes.length && this.buffer.byteLength < memory_consts_PAGE_SIZE) {
|
|
15402
|
+
const newLength = Math.min(memory_consts_PAGE_SIZE, Math.max(MIN_ALLOCATION_LENGTH, startIndex + bytes.length));
|
|
15421
15403
|
this.buffer.resize(newLength);
|
|
15422
15404
|
}
|
|
15423
15405
|
this.view.set(bytes, startIndex);
|
|
15424
15406
|
return Result.ok(OK);
|
|
15425
15407
|
}
|
|
15426
15408
|
setData(pageIndex, data) {
|
|
15427
|
-
if (this.buffer.byteLength < pageIndex + data.length && this.buffer.byteLength <
|
|
15428
|
-
const newLength = Math.min(
|
|
15409
|
+
if (this.buffer.byteLength < pageIndex + data.length && this.buffer.byteLength < memory_consts_PAGE_SIZE) {
|
|
15410
|
+
const newLength = Math.min(memory_consts_PAGE_SIZE, Math.max(MIN_ALLOCATION_LENGTH, pageIndex + data.length));
|
|
15429
15411
|
this.buffer.resize(newLength);
|
|
15430
15412
|
}
|
|
15431
15413
|
this.view.set(data, pageIndex);
|
|
@@ -15476,10 +15458,10 @@ class Memory {
|
|
|
15476
15458
|
this.memory = memory;
|
|
15477
15459
|
}
|
|
15478
15460
|
store(address, bytes) {
|
|
15479
|
-
return this.storeFrom(
|
|
15461
|
+
return this.storeFrom(memory_index_tryAsMemoryIndex(address), bytes);
|
|
15480
15462
|
}
|
|
15481
15463
|
read(address, output) {
|
|
15482
|
-
return this.loadInto(output,
|
|
15464
|
+
return this.loadInto(output, memory_index_tryAsMemoryIndex(address));
|
|
15483
15465
|
}
|
|
15484
15466
|
reset() {
|
|
15485
15467
|
this.sbrkIndex = tryAsSbrkIndex(RESERVED_MEMORY_RANGE.end);
|
|
@@ -15506,8 +15488,8 @@ class Memory {
|
|
|
15506
15488
|
let currentPosition = address;
|
|
15507
15489
|
let bytesLeft = bytes.length;
|
|
15508
15490
|
for (const page of pages) {
|
|
15509
|
-
const pageStartIndex = tryAsPageIndex(currentPosition %
|
|
15510
|
-
const bytesToWrite = Math.min(
|
|
15491
|
+
const pageStartIndex = tryAsPageIndex(currentPosition % memory_consts_PAGE_SIZE);
|
|
15492
|
+
const bytesToWrite = Math.min(memory_consts_PAGE_SIZE - pageStartIndex, bytesLeft);
|
|
15511
15493
|
const sourceStartIndex = currentPosition - address;
|
|
15512
15494
|
const source = bytes.subarray(sourceStartIndex, sourceStartIndex + bytesToWrite);
|
|
15513
15495
|
page.storeFrom(pageStartIndex, source);
|
|
@@ -15556,8 +15538,8 @@ class Memory {
|
|
|
15556
15538
|
let currentPosition = startAddress;
|
|
15557
15539
|
let bytesLeft = result.length;
|
|
15558
15540
|
for (const page of pages) {
|
|
15559
|
-
const pageStartIndex = tryAsPageIndex(currentPosition %
|
|
15560
|
-
const bytesToRead = Math.min(
|
|
15541
|
+
const pageStartIndex = tryAsPageIndex(currentPosition % memory_consts_PAGE_SIZE);
|
|
15542
|
+
const bytesToRead = Math.min(memory_consts_PAGE_SIZE - pageStartIndex, bytesLeft);
|
|
15561
15543
|
const destinationStartIndex = currentPosition - startAddress;
|
|
15562
15544
|
const destination = result.subarray(destinationStartIndex);
|
|
15563
15545
|
page.loadInto(destination, pageStartIndex, bytesToRead);
|
|
@@ -15584,7 +15566,7 @@ class Memory {
|
|
|
15584
15566
|
const newSbrkIndex = tryAsSbrkIndex(alignToPageSize(newVirtualSbrkIndex));
|
|
15585
15567
|
// TODO [MaSi]: `getPageNumber` works incorrectly for SbrkIndex. Sbrk index should be changed to MemoryIndex
|
|
15586
15568
|
const firstPageNumber = getPageNumber(currentSbrkIndex);
|
|
15587
|
-
const pagesToAllocate = (newSbrkIndex - currentSbrkIndex) /
|
|
15569
|
+
const pagesToAllocate = (newSbrkIndex - currentSbrkIndex) / memory_consts_PAGE_SIZE;
|
|
15588
15570
|
const rangeToAllocate = PageRange.fromStartAndLength(firstPageNumber, pagesToAllocate);
|
|
15589
15571
|
for (const pageNumber of rangeToAllocate) {
|
|
15590
15572
|
const page = new WriteablePage(pageNumber);
|
|
@@ -15639,8 +15621,8 @@ class MemoryBuilder {
|
|
|
15639
15621
|
setReadablePages(start, end, data = new Uint8Array()) {
|
|
15640
15622
|
this.ensureNotFinalized();
|
|
15641
15623
|
debug_check `${start < end} end has to be bigger than start`;
|
|
15642
|
-
debug_check `${start %
|
|
15643
|
-
debug_check `${end %
|
|
15624
|
+
debug_check `${start % memory_consts_PAGE_SIZE === 0} start needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
|
|
15625
|
+
debug_check `${end % memory_consts_PAGE_SIZE === 0} end needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
|
|
15644
15626
|
debug_check `${data.length <= end - start} the initial data is longer than address range`;
|
|
15645
15627
|
const length = end - start;
|
|
15646
15628
|
const range = MemoryRange.fromStartAndLength(start, length);
|
|
@@ -15649,7 +15631,7 @@ class MemoryBuilder {
|
|
|
15649
15631
|
const noOfPages = pages.length;
|
|
15650
15632
|
for (let i = 0; i < noOfPages; i++) {
|
|
15651
15633
|
const pageNumber = pages[i];
|
|
15652
|
-
const dataChunk = data.subarray(i *
|
|
15634
|
+
const dataChunk = data.subarray(i * memory_consts_PAGE_SIZE, (i + 1) * memory_consts_PAGE_SIZE);
|
|
15653
15635
|
const page = new ReadablePage(pageNumber, dataChunk);
|
|
15654
15636
|
this.initialMemory.set(pageNumber, page);
|
|
15655
15637
|
}
|
|
@@ -15667,8 +15649,8 @@ class MemoryBuilder {
|
|
|
15667
15649
|
setWriteablePages(start, end, data = new Uint8Array()) {
|
|
15668
15650
|
this.ensureNotFinalized();
|
|
15669
15651
|
debug_check `${start < end} end has to be bigger than start`;
|
|
15670
|
-
debug_check `${start %
|
|
15671
|
-
debug_check `${end %
|
|
15652
|
+
debug_check `${start % memory_consts_PAGE_SIZE === 0} start needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
|
|
15653
|
+
debug_check `${end % memory_consts_PAGE_SIZE === 0} end needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
|
|
15672
15654
|
debug_check `${data.length <= end - start} the initial data is longer than address range`;
|
|
15673
15655
|
const length = end - start;
|
|
15674
15656
|
const range = MemoryRange.fromStartAndLength(start, length);
|
|
@@ -15677,7 +15659,7 @@ class MemoryBuilder {
|
|
|
15677
15659
|
const noOfPages = pages.length;
|
|
15678
15660
|
for (let i = 0; i < noOfPages; i++) {
|
|
15679
15661
|
const pageNumber = pages[i];
|
|
15680
|
-
const dataChunk = data.subarray(i *
|
|
15662
|
+
const dataChunk = data.subarray(i * memory_consts_PAGE_SIZE, (i + 1) * memory_consts_PAGE_SIZE);
|
|
15681
15663
|
const page = new WriteablePage(pageNumber, dataChunk);
|
|
15682
15664
|
this.initialMemory.set(pageNumber, page);
|
|
15683
15665
|
}
|
|
@@ -15689,8 +15671,8 @@ class MemoryBuilder {
|
|
|
15689
15671
|
*/
|
|
15690
15672
|
setData(start, data) {
|
|
15691
15673
|
this.ensureNotFinalized();
|
|
15692
|
-
const pageOffset = start %
|
|
15693
|
-
const remainingSpaceOnPage =
|
|
15674
|
+
const pageOffset = start % memory_consts_PAGE_SIZE;
|
|
15675
|
+
const remainingSpaceOnPage = memory_consts_PAGE_SIZE - pageOffset;
|
|
15694
15676
|
debug_check `${data.length <= remainingSpaceOnPage} The data has to fit into a single page.`;
|
|
15695
15677
|
const length = data.length;
|
|
15696
15678
|
const range = MemoryRange.fromStartAndLength(start, length);
|
|
@@ -15881,27 +15863,27 @@ class Program {
|
|
|
15881
15863
|
static fromSpi(blob, args, hasMetadata) {
|
|
15882
15864
|
const { code: spiCode, metadata } = hasMetadata ? extractCodeAndMetadata(blob) : { code: blob };
|
|
15883
15865
|
const { code, memory: rawMemory, registers } = decodeStandardProgram(spiCode, args);
|
|
15884
|
-
const regs = new
|
|
15866
|
+
const regs = new registers_Registers();
|
|
15885
15867
|
regs.copyFrom(registers);
|
|
15886
15868
|
const memoryBuilder = new MemoryBuilder();
|
|
15887
15869
|
for (const { start, end, data } of rawMemory.readable) {
|
|
15888
|
-
const startIndex =
|
|
15889
|
-
const endIndex =
|
|
15870
|
+
const startIndex = memory_index_tryAsMemoryIndex(start);
|
|
15871
|
+
const endIndex = memory_index_tryAsMemoryIndex(end);
|
|
15890
15872
|
memoryBuilder.setReadablePages(startIndex, endIndex, data ?? new Uint8Array());
|
|
15891
15873
|
}
|
|
15892
15874
|
for (const { start, end, data } of rawMemory.writeable) {
|
|
15893
|
-
const startIndex =
|
|
15894
|
-
const endIndex =
|
|
15875
|
+
const startIndex = memory_index_tryAsMemoryIndex(start);
|
|
15876
|
+
const endIndex = memory_index_tryAsMemoryIndex(end);
|
|
15895
15877
|
memoryBuilder.setWriteablePages(startIndex, endIndex, data ?? new Uint8Array());
|
|
15896
15878
|
}
|
|
15897
|
-
const heapStart =
|
|
15879
|
+
const heapStart = memory_index_tryAsMemoryIndex(rawMemory.sbrkIndex);
|
|
15898
15880
|
const heapEnd = tryAsSbrkIndex(rawMemory.heapEnd);
|
|
15899
15881
|
const memory = memoryBuilder.finalize(heapStart, heapEnd);
|
|
15900
15882
|
return new Program(code, regs, memory, metadata);
|
|
15901
15883
|
}
|
|
15902
15884
|
static fromGeneric(blob, hasMetadata) {
|
|
15903
15885
|
const { code, metadata } = hasMetadata ? extractCodeAndMetadata(blob) : { code: blob };
|
|
15904
|
-
const regs = new
|
|
15886
|
+
const regs = new registers_Registers();
|
|
15905
15887
|
const memory = new Memory();
|
|
15906
15888
|
return new Program(code, regs, memory, metadata);
|
|
15907
15889
|
}
|
|
@@ -16916,6 +16898,45 @@ class BasicBlocks {
|
|
|
16916
16898
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/basic-blocks/index.ts
|
|
16917
16899
|
|
|
16918
16900
|
|
|
16901
|
+
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/gas.ts
|
|
16902
|
+
|
|
16903
|
+
|
|
16904
|
+
/** Create a new gas counter instance depending on the gas value. */
|
|
16905
|
+
function gasCounter(gas) {
|
|
16906
|
+
return new GasCounterU64(numbers_tryAsU64(gas));
|
|
16907
|
+
}
|
|
16908
|
+
class GasCounterU64 {
|
|
16909
|
+
gas;
|
|
16910
|
+
initialGas;
|
|
16911
|
+
constructor(gas) {
|
|
16912
|
+
this.gas = gas;
|
|
16913
|
+
this.initialGas = gas_tryAsGas(gas);
|
|
16914
|
+
}
|
|
16915
|
+
set(g) {
|
|
16916
|
+
this.gas = numbers_tryAsU64(g);
|
|
16917
|
+
}
|
|
16918
|
+
get() {
|
|
16919
|
+
return gas_tryAsGas(this.gas);
|
|
16920
|
+
}
|
|
16921
|
+
sub(g) {
|
|
16922
|
+
const result = this.gas - numbers_tryAsU64(g);
|
|
16923
|
+
if (result >= 0n) {
|
|
16924
|
+
this.gas = numbers_tryAsU64(result);
|
|
16925
|
+
return false;
|
|
16926
|
+
}
|
|
16927
|
+
this.gas = numbers_tryAsU64(0n);
|
|
16928
|
+
return true;
|
|
16929
|
+
}
|
|
16930
|
+
used() {
|
|
16931
|
+
const gasConsumed = numbers_tryAsU64(this.initialGas) - this.gas;
|
|
16932
|
+
// In we have less than zero left we assume that all gas has been consumed.
|
|
16933
|
+
if (gasConsumed < 0) {
|
|
16934
|
+
return this.initialGas;
|
|
16935
|
+
}
|
|
16936
|
+
return gas_tryAsGas(gasConsumed);
|
|
16937
|
+
}
|
|
16938
|
+
}
|
|
16939
|
+
|
|
16919
16940
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/instruction-gas-map.ts
|
|
16920
16941
|
|
|
16921
16942
|
|
|
@@ -17492,7 +17513,7 @@ class LoadOps {
|
|
|
17492
17513
|
}
|
|
17493
17514
|
loadNumber(address, registerIndex, numberLength) {
|
|
17494
17515
|
const registerBytes = this.regs.getBytesAsLittleEndian(registerIndex, REG_SIZE_BYTES);
|
|
17495
|
-
const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength),
|
|
17516
|
+
const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength), memory_index_tryAsMemoryIndex(address));
|
|
17496
17517
|
if (loadResult.isError) {
|
|
17497
17518
|
if (loadResult.error.isAccessFault) {
|
|
17498
17519
|
this.instructionResult.status = result_Result.FAULT_ACCESS;
|
|
@@ -17508,7 +17529,7 @@ class LoadOps {
|
|
|
17508
17529
|
loadSignedNumber(address, registerIndex, numberLength) {
|
|
17509
17530
|
// load all bytes from register to correctly handle the sign.
|
|
17510
17531
|
const registerBytes = this.regs.getBytesAsLittleEndian(registerIndex, REG_SIZE_BYTES);
|
|
17511
|
-
const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength),
|
|
17532
|
+
const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength), memory_index_tryAsMemoryIndex(address));
|
|
17512
17533
|
if (loadResult.isError) {
|
|
17513
17534
|
if (loadResult.error.isAccessFault) {
|
|
17514
17535
|
this.instructionResult.status = result_Result.FAULT_ACCESS;
|
|
@@ -17930,7 +17951,7 @@ class StoreOps {
|
|
|
17930
17951
|
this.store(address, secondImmediateDecoder.getExtendedBytesAsLittleEndian());
|
|
17931
17952
|
}
|
|
17932
17953
|
store(address, bytes) {
|
|
17933
|
-
const storeResult = this.memory.storeFrom(
|
|
17954
|
+
const storeResult = this.memory.storeFrom(memory_index_tryAsMemoryIndex(address), bytes);
|
|
17934
17955
|
if (storeResult.isOk) {
|
|
17935
17956
|
return;
|
|
17936
17957
|
}
|
|
@@ -17939,7 +17960,7 @@ class StoreOps {
|
|
|
17939
17960
|
}
|
|
17940
17961
|
else {
|
|
17941
17962
|
this.instructionResult.status = result_Result.FAULT;
|
|
17942
|
-
this.instructionResult.exitParam = getStartPageIndex(
|
|
17963
|
+
this.instructionResult.exitParam = getStartPageIndex(memory_index_tryAsMemoryIndex(storeResult.error.address));
|
|
17943
17964
|
}
|
|
17944
17965
|
}
|
|
17945
17966
|
}
|
|
@@ -18738,11 +18759,11 @@ class ProgramDecoder {
|
|
|
18738
18759
|
|
|
18739
18760
|
|
|
18740
18761
|
const interpreter_logger = Logger.new(import.meta.filename, "pvm");
|
|
18741
|
-
class
|
|
18762
|
+
class interpreter_Interpreter {
|
|
18742
18763
|
useSbrkGas;
|
|
18743
|
-
registers = new
|
|
18764
|
+
registers = new registers_Registers();
|
|
18744
18765
|
memory = new Memory();
|
|
18745
|
-
gas = gasCounter(
|
|
18766
|
+
gas = gasCounter(gas_tryAsGas(0));
|
|
18746
18767
|
code = new Uint8Array();
|
|
18747
18768
|
mask = Mask.empty();
|
|
18748
18769
|
pc = 0;
|
|
@@ -18876,8 +18897,8 @@ class Interpreter {
|
|
|
18876
18897
|
break;
|
|
18877
18898
|
case ArgumentType.TWO_REGISTERS:
|
|
18878
18899
|
if (this.useSbrkGas && currentInstruction === Instruction.SBRK) {
|
|
18879
|
-
const calculateSbrkCost = (length) => (alignToPageSize(length) /
|
|
18880
|
-
const underflow = this.gas.sub(
|
|
18900
|
+
const calculateSbrkCost = (length) => (alignToPageSize(length) / memory_consts_PAGE_SIZE) * 16;
|
|
18901
|
+
const underflow = this.gas.sub(gas_tryAsGas(calculateSbrkCost(this.registers.getLowerU32(argsResult.firstRegisterIndex))));
|
|
18881
18902
|
if (underflow) {
|
|
18882
18903
|
this.status = status_Status.OOG;
|
|
18883
18904
|
return this.status;
|
|
@@ -18972,12 +18993,88 @@ class Interpreter {
|
|
|
18972
18993
|
}
|
|
18973
18994
|
}
|
|
18974
18995
|
|
|
18996
|
+
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/debugger-adapter.ts
|
|
18997
|
+
|
|
18998
|
+
|
|
18999
|
+
|
|
19000
|
+
|
|
19001
|
+
|
|
19002
|
+
|
|
19003
|
+
class DebuggerAdapter {
|
|
19004
|
+
pvm;
|
|
19005
|
+
constructor(useSbrkGas = false) {
|
|
19006
|
+
this.pvm = new Interpreter({ useSbrkGas });
|
|
19007
|
+
}
|
|
19008
|
+
resetGeneric(rawProgram, flatRegisters, initialGas) {
|
|
19009
|
+
this.pvm.resetGeneric(rawProgram, 0, tryAsGas(initialGas), new Registers(flatRegisters));
|
|
19010
|
+
}
|
|
19011
|
+
reset(rawProgram, pc, gas, maybeRegisters, maybeMemory) {
|
|
19012
|
+
this.pvm.resetGeneric(rawProgram, pc, tryAsGas(gas), maybeRegisters, maybeMemory);
|
|
19013
|
+
}
|
|
19014
|
+
getPageDump(pageNumber) {
|
|
19015
|
+
const page = this.pvm.getMemoryPage(pageNumber);
|
|
19016
|
+
if (page === null) {
|
|
19017
|
+
// page wasn't allocated so we return an empty page
|
|
19018
|
+
return safeAllocUint8Array(PAGE_SIZE);
|
|
19019
|
+
}
|
|
19020
|
+
if (page.length === PAGE_SIZE) {
|
|
19021
|
+
// page was allocated and has a proper size so we can simply return it
|
|
19022
|
+
return page;
|
|
19023
|
+
}
|
|
19024
|
+
// page was allocated but it is shorter than PAGE_SIZE so we have to extend it
|
|
19025
|
+
const fullPage = safeAllocUint8Array(PAGE_SIZE);
|
|
19026
|
+
fullPage.set(page);
|
|
19027
|
+
return fullPage;
|
|
19028
|
+
}
|
|
19029
|
+
setMemory(address, value) {
|
|
19030
|
+
this.pvm.memory.storeFrom(tryAsMemoryIndex(address), value);
|
|
19031
|
+
}
|
|
19032
|
+
getExitArg() {
|
|
19033
|
+
return this.pvm.getExitParam() ?? 0;
|
|
19034
|
+
}
|
|
19035
|
+
getStatus() {
|
|
19036
|
+
return this.pvm.getStatus();
|
|
19037
|
+
}
|
|
19038
|
+
nextStep() {
|
|
19039
|
+
return this.pvm.nextStep() === Status.OK;
|
|
19040
|
+
}
|
|
19041
|
+
nSteps(steps) {
|
|
19042
|
+
check `${steps >>> 0 > 0} Expected a positive integer got ${steps}`;
|
|
19043
|
+
for (let i = 0; i < steps; i++) {
|
|
19044
|
+
const isOk = this.nextStep();
|
|
19045
|
+
if (!isOk) {
|
|
19046
|
+
return false;
|
|
19047
|
+
}
|
|
19048
|
+
}
|
|
19049
|
+
return true;
|
|
19050
|
+
}
|
|
19051
|
+
getRegisters() {
|
|
19052
|
+
return this.pvm.registers.getAllU64();
|
|
19053
|
+
}
|
|
19054
|
+
setRegisters(registers) {
|
|
19055
|
+
this.pvm.registers.copyFrom(new Registers(registers));
|
|
19056
|
+
}
|
|
19057
|
+
getProgramCounter() {
|
|
19058
|
+
return this.pvm.getPC();
|
|
19059
|
+
}
|
|
19060
|
+
setNextProgramCounter(nextPc) {
|
|
19061
|
+
this.pvm.setNextPC(nextPc);
|
|
19062
|
+
}
|
|
19063
|
+
getGasLeft() {
|
|
19064
|
+
return BigInt(this.pvm.gas.get());
|
|
19065
|
+
}
|
|
19066
|
+
setGasLeft(gas) {
|
|
19067
|
+
this.pvm.gas.set(tryAsGas(gas));
|
|
19068
|
+
}
|
|
19069
|
+
}
|
|
19070
|
+
|
|
18975
19071
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/index.ts
|
|
18976
19072
|
|
|
18977
19073
|
|
|
18978
19074
|
|
|
18979
19075
|
|
|
18980
19076
|
|
|
19077
|
+
|
|
18981
19078
|
;// CONCATENATED MODULE: ./node_modules/@fluffylabs/anan-as/build/debug-raw.js
|
|
18982
19079
|
async function instantiate(module, imports = {}) {
|
|
18983
19080
|
const adaptedImports = {
|
|
@@ -19431,12 +19528,12 @@ class AnanasMemory {
|
|
|
19431
19528
|
}
|
|
19432
19529
|
class AnanasGasCounter {
|
|
19433
19530
|
instance;
|
|
19434
|
-
initialGas =
|
|
19531
|
+
initialGas = gas_tryAsGas(0n);
|
|
19435
19532
|
constructor(instance) {
|
|
19436
19533
|
this.instance = instance;
|
|
19437
19534
|
}
|
|
19438
19535
|
get() {
|
|
19439
|
-
return
|
|
19536
|
+
return gas_tryAsGas(this.instance.getGasLeft());
|
|
19440
19537
|
}
|
|
19441
19538
|
set(g) {
|
|
19442
19539
|
this.instance.setGasLeft(BigInt(g));
|
|
@@ -19541,7 +19638,7 @@ class InterpreterInstanceManager {
|
|
|
19541
19638
|
const instances = [];
|
|
19542
19639
|
switch (interpreter) {
|
|
19543
19640
|
case PvmBackend.BuiltIn:
|
|
19544
|
-
instances.push(new
|
|
19641
|
+
instances.push(new interpreter_Interpreter({
|
|
19545
19642
|
useSbrkGas: false,
|
|
19546
19643
|
}));
|
|
19547
19644
|
break;
|
|
@@ -19715,10 +19812,10 @@ class Info {
|
|
|
19715
19812
|
const chunk = encodedInfo.raw.subarray(Number(offset), Number(offset + length));
|
|
19716
19813
|
const writeResult = memory.storeFrom(outputStart, chunk);
|
|
19717
19814
|
if (writeResult.isError) {
|
|
19718
|
-
logger_logger.trace `INFO(${serviceId}, off: ${offset}, len: ${length}) <- PANIC`;
|
|
19815
|
+
logger_logger.trace `[${this.currentServiceId}] INFO(${serviceId}, off: ${offset}, len: ${length}) <- PANIC`;
|
|
19719
19816
|
return PvmExecution.Panic;
|
|
19720
19817
|
}
|
|
19721
|
-
logger_logger.trace `INFO(${serviceId}, off: ${offset}, len: ${length}) <- ${bytes_BytesBlob.blobFrom(chunk)}`;
|
|
19818
|
+
logger_logger.trace `[${this.currentServiceId}] INFO(${serviceId}, off: ${offset}, len: ${length}) <- ${bytes_BytesBlob.blobFrom(chunk)}`;
|
|
19722
19819
|
if (accountInfo === null) {
|
|
19723
19820
|
regs.set(IN_OUT_REG, HostCallResult.NONE);
|
|
19724
19821
|
return;
|
|
@@ -19942,7 +20039,7 @@ class AccumulateExternalities {
|
|
|
19942
20039
|
const bytes = serviceInfo.storageUtilisationBytes - length - LOOKUP_HISTORY_ENTRY_BYTES;
|
|
19943
20040
|
return this.updatedState.updateServiceStorageUtilisation(this.currentServiceId, items, bytes, serviceInfo);
|
|
19944
20041
|
};
|
|
19945
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
20042
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/380802380802?v=0.7.2
|
|
19946
20043
|
if (s.status === PreimageStatusKind.Requested) {
|
|
19947
20044
|
const res = updateStorageUtilisation();
|
|
19948
20045
|
if (res.isError) {
|
|
@@ -19955,7 +20052,7 @@ class AccumulateExternalities {
|
|
|
19955
20052
|
return Result.ok(OK);
|
|
19956
20053
|
}
|
|
19957
20054
|
const t = this.currentTimeslot;
|
|
19958
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
20055
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/380802380802?v=0.7.2
|
|
19959
20056
|
if (s.status === PreimageStatusKind.Unavailable) {
|
|
19960
20057
|
const y = s.data[1];
|
|
19961
20058
|
if (y < t - this.chainSpec.preimageExpungePeriod) {
|
|
@@ -19971,14 +20068,14 @@ class AccumulateExternalities {
|
|
|
19971
20068
|
}
|
|
19972
20069
|
return Result.error(ForgetPreimageError.NotExpired, () => `Preimage not expired: y=${y}, timeslot=${t}, period=${this.chainSpec.preimageExpungePeriod}`);
|
|
19973
20070
|
}
|
|
19974
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
20071
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/382802383302?v=0.7.2
|
|
19975
20072
|
if (s.status === PreimageStatusKind.Available) {
|
|
19976
20073
|
this.updatedState.updatePreimage(serviceId, UpdatePreimage.updateOrAdd({
|
|
19977
20074
|
lookupHistory: new LookupHistoryItem(status.hash, status.length, service_tryAsLookupHistorySlots([s.data[0], t])),
|
|
19978
20075
|
}));
|
|
19979
20076
|
return Result.ok(OK);
|
|
19980
20077
|
}
|
|
19981
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
20078
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/384002384c02?v=0.7.2
|
|
19982
20079
|
if (s.status === PreimageStatusKind.Reavailable) {
|
|
19983
20080
|
const y = s.data[1];
|
|
19984
20081
|
if (y < t - this.chainSpec.preimageExpungePeriod) {
|
|
@@ -21138,12 +21235,12 @@ function createMergeContext(chainSpec, state, inputState, results) {
|
|
|
21138
21235
|
}
|
|
21139
21236
|
function updatePrivilegedService(currentServiceId, serviceIdUpdatedByManager, selfUpdatedServiceId) {
|
|
21140
21237
|
if (currentServiceId === serviceIdUpdatedByManager) {
|
|
21141
|
-
return
|
|
21238
|
+
return selfUpdatedServiceId;
|
|
21142
21239
|
}
|
|
21143
|
-
return
|
|
21240
|
+
return serviceIdUpdatedByManager;
|
|
21144
21241
|
}
|
|
21145
21242
|
function mergePrivilegedServices(mergeContext, [serviceId, { stateUpdate }]) {
|
|
21146
|
-
const { outputState, currentPrivilegedServices, chainSpec } = mergeContext;
|
|
21243
|
+
const { outputState, currentPrivilegedServices, chainSpec, privilegedServicesUpdatedByManager } = mergeContext;
|
|
21147
21244
|
const currentManager = currentPrivilegedServices.manager;
|
|
21148
21245
|
const currentRegistrar = currentPrivilegedServices.registrar;
|
|
21149
21246
|
const currentDelegator = currentPrivilegedServices.delegator;
|
|
@@ -21161,28 +21258,35 @@ function mergePrivilegedServices(mergeContext, [serviceId, { stateUpdate }]) {
|
|
|
21161
21258
|
});
|
|
21162
21259
|
}
|
|
21163
21260
|
if (serviceId === currentRegistrar) {
|
|
21164
|
-
const newRegistrar = updatePrivilegedService(currentPrivilegedServices.registrar,
|
|
21261
|
+
const newRegistrar = updatePrivilegedService(currentPrivilegedServices.registrar, privilegedServicesUpdatedByManager.registrar, privilegedServices.registrar);
|
|
21165
21262
|
outputState.privilegedServices = PrivilegedServices.create({
|
|
21166
21263
|
...outputState.privilegedServices,
|
|
21167
21264
|
registrar: newRegistrar,
|
|
21168
21265
|
});
|
|
21169
21266
|
}
|
|
21170
21267
|
if (serviceId === currentDelegator) {
|
|
21171
|
-
const newDelegator = updatePrivilegedService(currentPrivilegedServices.delegator,
|
|
21268
|
+
const newDelegator = updatePrivilegedService(currentPrivilegedServices.delegator, privilegedServicesUpdatedByManager.delegator, privilegedServices.delegator);
|
|
21172
21269
|
outputState.privilegedServices = PrivilegedServices.create({
|
|
21173
21270
|
...outputState.privilegedServices,
|
|
21174
21271
|
delegator: newDelegator,
|
|
21175
21272
|
});
|
|
21176
21273
|
}
|
|
21177
|
-
|
|
21178
|
-
const newAssigners = currentAssigners.map((currentAssigner, coreIndex) =>
|
|
21179
|
-
|
|
21180
|
-
|
|
21181
|
-
|
|
21182
|
-
|
|
21183
|
-
|
|
21184
|
-
|
|
21274
|
+
let shouldUpdateAssigners = false;
|
|
21275
|
+
const newAssigners = currentAssigners.map((currentAssigner, coreIndex) => {
|
|
21276
|
+
if (serviceId === currentAssigner) {
|
|
21277
|
+
const newAssigner = updatePrivilegedService(currentPrivilegedServices.assigners[coreIndex], privilegedServicesUpdatedByManager.assigners[coreIndex], privilegedServices.assigners[coreIndex]);
|
|
21278
|
+
shouldUpdateAssigners = shouldUpdateAssigners || newAssigner !== currentAssigner;
|
|
21279
|
+
return newAssigner;
|
|
21280
|
+
}
|
|
21281
|
+
return currentAssigner;
|
|
21185
21282
|
});
|
|
21283
|
+
if (shouldUpdateAssigners) {
|
|
21284
|
+
const newAssignersPerCore = tryAsPerCore(newAssigners, chainSpec);
|
|
21285
|
+
outputState.privilegedServices = PrivilegedServices.create({
|
|
21286
|
+
...outputState.privilegedServices,
|
|
21287
|
+
assigners: newAssignersPerCore,
|
|
21288
|
+
});
|
|
21289
|
+
}
|
|
21186
21290
|
}
|
|
21187
21291
|
}
|
|
21188
21292
|
function mergeValidatorsData(mergeContext, [serviceId, { stateUpdate }]) {
|
|
@@ -21327,7 +21431,7 @@ class Assign {
|
|
|
21327
21431
|
const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
|
|
21328
21432
|
// error while reading the memory.
|
|
21329
21433
|
if (memoryReadResult.isError) {
|
|
21330
|
-
logger_logger.trace `ASSIGN() <- PANIC`;
|
|
21434
|
+
logger_logger.trace `[${this.currentServiceId}] ASSIGN() <- PANIC`;
|
|
21331
21435
|
return PvmExecution.Panic;
|
|
21332
21436
|
}
|
|
21333
21437
|
if (maybeCoreIndex >= this.chainSpec.coresCount) {
|
|
@@ -21342,18 +21446,18 @@ class Assign {
|
|
|
21342
21446
|
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
|
|
21343
21447
|
if (result.isOk) {
|
|
21344
21448
|
regs.set(assign_IN_OUT_REG, HostCallResult.OK);
|
|
21345
|
-
logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
|
|
21449
|
+
logger_logger.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
|
|
21346
21450
|
return;
|
|
21347
21451
|
}
|
|
21348
21452
|
const e = result.error;
|
|
21349
21453
|
if (e === UpdatePrivilegesError.UnprivilegedService) {
|
|
21350
21454
|
regs.set(assign_IN_OUT_REG, HostCallResult.HUH);
|
|
21351
|
-
logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
|
|
21455
|
+
logger_logger.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
|
|
21352
21456
|
return;
|
|
21353
21457
|
}
|
|
21354
21458
|
if (e === UpdatePrivilegesError.InvalidServiceId) {
|
|
21355
21459
|
regs.set(assign_IN_OUT_REG, HostCallResult.WHO);
|
|
21356
|
-
logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
|
|
21460
|
+
logger_logger.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
|
|
21357
21461
|
return;
|
|
21358
21462
|
}
|
|
21359
21463
|
assertNever(e);
|
|
@@ -21424,7 +21528,7 @@ class Bless {
|
|
|
21424
21528
|
decoder.resetTo(0);
|
|
21425
21529
|
const memoryReadResult = memory.loadInto(result, memIndex);
|
|
21426
21530
|
if (memoryReadResult.isError) {
|
|
21427
|
-
logger_logger.trace `BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}) <- PANIC`;
|
|
21531
|
+
logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}) <- PANIC`;
|
|
21428
21532
|
return PvmExecution.Panic;
|
|
21429
21533
|
}
|
|
21430
21534
|
const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
|
|
@@ -21437,26 +21541,26 @@ class Bless {
|
|
|
21437
21541
|
const authorizersDecoder = decoder_Decoder.fromBlob(res);
|
|
21438
21542
|
const memoryReadResult = memory.loadInto(res, authorization);
|
|
21439
21543
|
if (memoryReadResult.isError) {
|
|
21440
|
-
logger_logger.trace `BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- PANIC`;
|
|
21544
|
+
logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- PANIC`;
|
|
21441
21545
|
return PvmExecution.Panic;
|
|
21442
21546
|
}
|
|
21443
21547
|
// `a`
|
|
21444
21548
|
const authorizers = tryAsPerCore(authorizersDecoder.sequenceFixLen(descriptors_codec.u32.asOpaque(), this.chainSpec.coresCount), this.chainSpec);
|
|
21445
21549
|
const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate);
|
|
21446
21550
|
if (updateResult.isOk) {
|
|
21447
|
-
logger_logger.trace `BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- OK`;
|
|
21551
|
+
logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- OK`;
|
|
21448
21552
|
regs.set(bless_IN_OUT_REG, HostCallResult.OK);
|
|
21449
21553
|
return;
|
|
21450
21554
|
}
|
|
21451
21555
|
const e = updateResult.error;
|
|
21452
21556
|
// NOTE: `UpdatePrivilegesError.UnprivilegedService` won't happen in 0.7.1+
|
|
21453
21557
|
if (e === UpdatePrivilegesError.UnprivilegedService) {
|
|
21454
|
-
logger_logger.trace `BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- HUH`;
|
|
21558
|
+
logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- HUH`;
|
|
21455
21559
|
regs.set(bless_IN_OUT_REG, HostCallResult.HUH);
|
|
21456
21560
|
return;
|
|
21457
21561
|
}
|
|
21458
21562
|
if (e === UpdatePrivilegesError.InvalidServiceId) {
|
|
21459
|
-
logger_logger.trace `BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- WHO`;
|
|
21563
|
+
logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- WHO`;
|
|
21460
21564
|
regs.set(bless_IN_OUT_REG, HostCallResult.WHO);
|
|
21461
21565
|
return;
|
|
21462
21566
|
}
|
|
@@ -21486,7 +21590,7 @@ class GasHostCall {
|
|
|
21486
21590
|
}
|
|
21487
21591
|
execute(gas, regs) {
|
|
21488
21592
|
const gasValue = gas.get();
|
|
21489
|
-
logger_logger.trace `GAS <- ${gasValue}`;
|
|
21593
|
+
logger_logger.trace `[${this.currentServiceId}] GAS <- ${gasValue}`;
|
|
21490
21594
|
regs.set(7, numbers_tryAsU64(gasValue));
|
|
21491
21595
|
return Promise.resolve(undefined);
|
|
21492
21596
|
}
|
|
@@ -21518,7 +21622,7 @@ class Checkpoint {
|
|
|
21518
21622
|
async execute(gas, regs) {
|
|
21519
21623
|
await this.gasHostCall.execute(gas, regs);
|
|
21520
21624
|
this.partialState.checkpoint();
|
|
21521
|
-
logger_logger.trace `CHECKPOINT()`;
|
|
21625
|
+
logger_logger.trace `[${this.currentServiceId}] CHECKPOINT()`;
|
|
21522
21626
|
return;
|
|
21523
21627
|
}
|
|
21524
21628
|
}
|
|
@@ -21558,18 +21662,18 @@ class Designate {
|
|
|
21558
21662
|
const memoryReadResult = memory.loadInto(res, validatorsStart);
|
|
21559
21663
|
// error while reading the memory.
|
|
21560
21664
|
if (memoryReadResult.isError) {
|
|
21561
|
-
logger_logger.trace `DESIGNATE() <- PANIC`;
|
|
21665
|
+
logger_logger.trace `[${this.currentServiceId}] DESIGNATE() <- PANIC`;
|
|
21562
21666
|
return PvmExecution.Panic;
|
|
21563
21667
|
}
|
|
21564
21668
|
const decoder = decoder_Decoder.fromBlob(res);
|
|
21565
21669
|
const validatorsData = decoder.sequenceFixLen(ValidatorData.Codec, this.chainSpec.validatorsCount);
|
|
21566
21670
|
const result = this.partialState.updateValidatorsData(tryAsPerValidator(validatorsData, this.chainSpec));
|
|
21567
21671
|
if (result.isError) {
|
|
21568
|
-
logger_logger.trace `DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- HUH`;
|
|
21672
|
+
logger_logger.trace `[${this.currentServiceId}] DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- HUH`;
|
|
21569
21673
|
regs.set(designate_IN_OUT_REG, HostCallResult.HUH);
|
|
21570
21674
|
}
|
|
21571
21675
|
else {
|
|
21572
|
-
logger_logger.trace `DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- OK`;
|
|
21676
|
+
logger_logger.trace `[${this.currentServiceId}] DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- OK`;
|
|
21573
21677
|
regs.set(designate_IN_OUT_REG, HostCallResult.OK);
|
|
21574
21678
|
}
|
|
21575
21679
|
}
|
|
@@ -21610,29 +21714,29 @@ class Eject {
|
|
|
21610
21714
|
const previousCodeHash = bytes_Bytes.zero(hash_HASH_SIZE).asOpaque();
|
|
21611
21715
|
const memoryReadResult = memory.loadInto(previousCodeHash.raw, preimageHashStart);
|
|
21612
21716
|
if (memoryReadResult.isError) {
|
|
21613
|
-
logger_logger.trace `EJECT(${serviceId}) <- PANIC`;
|
|
21717
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}) <- PANIC`;
|
|
21614
21718
|
return PvmExecution.Panic;
|
|
21615
21719
|
}
|
|
21616
21720
|
// cannot eject self
|
|
21617
21721
|
if (serviceId === this.currentServiceId) {
|
|
21618
21722
|
regs.set(eject_IN_OUT_REG, HostCallResult.WHO);
|
|
21619
|
-
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- WHO`;
|
|
21723
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- WHO`;
|
|
21620
21724
|
return;
|
|
21621
21725
|
}
|
|
21622
21726
|
const result = this.partialState.eject(serviceId, previousCodeHash);
|
|
21623
21727
|
// All good!
|
|
21624
21728
|
if (result.isOk) {
|
|
21625
|
-
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- OK`;
|
|
21729
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- OK`;
|
|
21626
21730
|
regs.set(eject_IN_OUT_REG, HostCallResult.OK);
|
|
21627
21731
|
return;
|
|
21628
21732
|
}
|
|
21629
21733
|
const e = result.error;
|
|
21630
21734
|
if (e === EjectError.InvalidService) {
|
|
21631
|
-
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- WHO ${resultToString(result)}`;
|
|
21735
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- WHO ${resultToString(result)}`;
|
|
21632
21736
|
regs.set(eject_IN_OUT_REG, HostCallResult.WHO);
|
|
21633
21737
|
}
|
|
21634
21738
|
else if (e === EjectError.InvalidPreimage) {
|
|
21635
|
-
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- HUH ${resultToString(result)}`;
|
|
21739
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- HUH ${resultToString(result)}`;
|
|
21636
21740
|
regs.set(eject_IN_OUT_REG, HostCallResult.HUH);
|
|
21637
21741
|
}
|
|
21638
21742
|
else {
|
|
@@ -21651,9 +21755,9 @@ class Eject {
|
|
|
21651
21755
|
|
|
21652
21756
|
const forget_IN_OUT_REG = 7;
|
|
21653
21757
|
/**
|
|
21654
|
-
*
|
|
21758
|
+
* Delete preimage hash or mark as unavailable if it was available.
|
|
21655
21759
|
*
|
|
21656
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
21760
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/385d01385d01?v=0.7.2
|
|
21657
21761
|
*/
|
|
21658
21762
|
class Forget {
|
|
21659
21763
|
currentServiceId;
|
|
@@ -21674,11 +21778,11 @@ class Forget {
|
|
|
21674
21778
|
const memoryReadResult = memory.loadInto(hash.raw, hashStart);
|
|
21675
21779
|
// error while reading the memory.
|
|
21676
21780
|
if (memoryReadResult.isError) {
|
|
21677
|
-
logger_logger.trace `FORGET(${hash}, ${length}) <- PANIC`;
|
|
21781
|
+
logger_logger.trace `[${this.currentServiceId}] FORGET(${hash}, ${length}) <- PANIC`;
|
|
21678
21782
|
return PvmExecution.Panic;
|
|
21679
21783
|
}
|
|
21680
21784
|
const result = this.partialState.forgetPreimage(hash.asOpaque(), length);
|
|
21681
|
-
logger_logger.trace `FORGET(${hash}, ${length}) <- ${resultToString(result)}`;
|
|
21785
|
+
logger_logger.trace `[${this.currentServiceId}] FORGET(${hash}, ${length}) <- ${resultToString(result)}`;
|
|
21682
21786
|
if (result.isOk) {
|
|
21683
21787
|
regs.set(forget_IN_OUT_REG, HostCallResult.OK);
|
|
21684
21788
|
}
|
|
@@ -21735,11 +21839,11 @@ class New {
|
|
|
21735
21839
|
const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
|
|
21736
21840
|
// error while reading the memory.
|
|
21737
21841
|
if (memoryReadResult.isError) {
|
|
21738
|
-
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
|
|
21842
|
+
logger_logger.trace `[${this.currentServiceId}] NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
|
|
21739
21843
|
return PvmExecution.Panic;
|
|
21740
21844
|
}
|
|
21741
21845
|
const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage, requestedServiceId);
|
|
21742
|
-
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${resultToString(assignedId)}`;
|
|
21846
|
+
logger_logger.trace `[${this.currentServiceId}] NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${resultToString(assignedId)}`;
|
|
21743
21847
|
if (assignedId.isOk) {
|
|
21744
21848
|
regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
|
|
21745
21849
|
return;
|
|
@@ -21799,11 +21903,11 @@ class Provide {
|
|
|
21799
21903
|
const preimage = bytes_BytesBlob.blobFrom(safe_alloc_uint8array_safeAllocUint8Array(length));
|
|
21800
21904
|
const memoryReadResult = memory.loadInto(preimage.raw, preimageStart);
|
|
21801
21905
|
if (memoryReadResult.isError) {
|
|
21802
|
-
logger_logger.trace `PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- PANIC`;
|
|
21906
|
+
logger_logger.trace `[${this.currentServiceId}] PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- PANIC`;
|
|
21803
21907
|
return PvmExecution.Panic;
|
|
21804
21908
|
}
|
|
21805
21909
|
const result = this.partialState.providePreimage(serviceId, preimage);
|
|
21806
|
-
logger_logger.trace `PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- ${resultToString(result)}`;
|
|
21910
|
+
logger_logger.trace `[${this.currentServiceId}] PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- ${resultToString(result)}`;
|
|
21807
21911
|
if (result.isOk) {
|
|
21808
21912
|
regs.set(provide_IN_OUT_REG, HostCallResult.OK);
|
|
21809
21913
|
return;
|
|
@@ -21859,35 +21963,35 @@ class Query {
|
|
|
21859
21963
|
const memoryReadResult = memory.loadInto(hash.raw, hashStart);
|
|
21860
21964
|
// error while reading the memory.
|
|
21861
21965
|
if (memoryReadResult.isError) {
|
|
21862
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- PANIC`;
|
|
21966
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- PANIC`;
|
|
21863
21967
|
return PvmExecution.Panic;
|
|
21864
21968
|
}
|
|
21865
21969
|
const result = this.partialState.checkPreimageStatus(hash.asOpaque(), length);
|
|
21866
21970
|
const zero = numbers_tryAsU64(0n);
|
|
21867
21971
|
if (result === null) {
|
|
21868
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- NONE`;
|
|
21972
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- NONE`;
|
|
21869
21973
|
regs.set(IN_OUT_REG_1, HostCallResult.NONE);
|
|
21870
21974
|
regs.set(IN_OUT_REG_2, zero);
|
|
21871
21975
|
return;
|
|
21872
21976
|
}
|
|
21873
21977
|
switch (result.status) {
|
|
21874
21978
|
case PreimageStatusKind.Requested:
|
|
21875
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- REQUESTED`;
|
|
21979
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- REQUESTED`;
|
|
21876
21980
|
regs.set(IN_OUT_REG_1, zero);
|
|
21877
21981
|
regs.set(IN_OUT_REG_2, zero);
|
|
21878
21982
|
return;
|
|
21879
21983
|
case PreimageStatusKind.Available:
|
|
21880
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- AVAILABLE [${result.data}]`;
|
|
21984
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- AVAILABLE [${result.data}]`;
|
|
21881
21985
|
regs.set(IN_OUT_REG_1, numbers_tryAsU64((BigInt(result.data[0]) << UPPER_BITS_SHIFT) + 1n));
|
|
21882
21986
|
regs.set(IN_OUT_REG_2, zero);
|
|
21883
21987
|
return;
|
|
21884
21988
|
case PreimageStatusKind.Unavailable:
|
|
21885
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- UNAVAILABLE [${result.data.join(", ")}]`;
|
|
21989
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- UNAVAILABLE [${result.data.join(", ")}]`;
|
|
21886
21990
|
regs.set(IN_OUT_REG_1, numbers_tryAsU64((BigInt(result.data[0]) << UPPER_BITS_SHIFT) + 2n));
|
|
21887
21991
|
regs.set(IN_OUT_REG_2, numbers_tryAsU64(result.data[1]));
|
|
21888
21992
|
return;
|
|
21889
21993
|
case PreimageStatusKind.Reavailable:
|
|
21890
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- REAVAILABLE [${result.data.join(", ")}]`;
|
|
21994
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- REAVAILABLE [${result.data.join(", ")}]`;
|
|
21891
21995
|
regs.set(IN_OUT_REG_1, numbers_tryAsU64((BigInt(result.data[0]) << UPPER_BITS_SHIFT) + 3n));
|
|
21892
21996
|
regs.set(IN_OUT_REG_2, numbers_tryAsU64((BigInt(result.data[2]) << UPPER_BITS_SHIFT) + BigInt(result.data[1])));
|
|
21893
21997
|
return;
|
|
@@ -21928,11 +22032,11 @@ class Solicit {
|
|
|
21928
22032
|
const hash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
21929
22033
|
const memoryReadResult = memory.loadInto(hash.raw, hashStart);
|
|
21930
22034
|
if (memoryReadResult.isError) {
|
|
21931
|
-
logger_logger.trace `SOLICIT(${hash}, ${length}) <- PANIC`;
|
|
22035
|
+
logger_logger.trace `[${this.currentServiceId}] SOLICIT(${hash}, ${length}) <- PANIC`;
|
|
21932
22036
|
return PvmExecution.Panic;
|
|
21933
22037
|
}
|
|
21934
22038
|
const result = this.partialState.requestPreimage(hash.asOpaque(), length);
|
|
21935
|
-
logger_logger.trace `SOLICIT(${hash}, ${length}) <- ${resultToString(result)}`;
|
|
22039
|
+
logger_logger.trace `[${this.currentServiceId}] SOLICIT(${hash}, ${length}) <- ${resultToString(result)}`;
|
|
21936
22040
|
if (result.isOk) {
|
|
21937
22041
|
regs.set(solicit_IN_OUT_REG, HostCallResult.OK);
|
|
21938
22042
|
return;
|
|
@@ -21990,7 +22094,7 @@ class Transfer {
|
|
|
21990
22094
|
*/
|
|
21991
22095
|
basicGasCost = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_2)
|
|
21992
22096
|
? gas_tryAsSmallGas(10)
|
|
21993
|
-
: (regs) =>
|
|
22097
|
+
: (regs) => gas_tryAsGas(10n + regs.get(TRANSFER_GAS_FEE_REG));
|
|
21994
22098
|
tracedRegisters = traceRegisters(transfer_IN_OUT_REG, AMOUNT_REG, TRANSFER_GAS_FEE_REG, MEMO_START_REG);
|
|
21995
22099
|
constructor(currentServiceId, partialState) {
|
|
21996
22100
|
this.currentServiceId = currentServiceId;
|
|
@@ -22009,16 +22113,16 @@ class Transfer {
|
|
|
22009
22113
|
const memoryReadResult = memory.loadInto(memo.raw, memoStart);
|
|
22010
22114
|
// page fault while reading the memory.
|
|
22011
22115
|
if (memoryReadResult.isError) {
|
|
22012
|
-
logger_logger.trace `TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- PANIC`;
|
|
22116
|
+
logger_logger.trace `[${this.currentServiceId}] TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- PANIC`;
|
|
22013
22117
|
return PvmExecution.Panic;
|
|
22014
22118
|
}
|
|
22015
22119
|
const transferResult = this.partialState.transfer(destination, amount, transferGasFee, memo);
|
|
22016
|
-
logger_logger.trace `TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- ${resultToString(transferResult)}`;
|
|
22120
|
+
logger_logger.trace `[${this.currentServiceId}] TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- ${resultToString(transferResult)}`;
|
|
22017
22121
|
// All good!
|
|
22018
22122
|
if (transferResult.isOk) {
|
|
22019
22123
|
if (compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_2)) {
|
|
22020
22124
|
// substracting value `t`
|
|
22021
|
-
const underflow = gas.sub(
|
|
22125
|
+
const underflow = gas.sub(gas_tryAsGas(transferGasFee));
|
|
22022
22126
|
if (underflow) {
|
|
22023
22127
|
return PvmExecution.OOG;
|
|
22024
22128
|
}
|
|
@@ -22079,11 +22183,11 @@ class Upgrade {
|
|
|
22079
22183
|
const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
22080
22184
|
const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
|
|
22081
22185
|
if (memoryReadResult.isError) {
|
|
22082
|
-
logger_logger.trace `UPGRADE(${codeHash}, ${gas}, ${allowance}) <- PANIC`;
|
|
22186
|
+
logger_logger.trace `[${this.currentServiceId}] UPGRADE(${codeHash}, ${gas}, ${allowance}) <- PANIC`;
|
|
22083
22187
|
return PvmExecution.Panic;
|
|
22084
22188
|
}
|
|
22085
22189
|
this.partialState.upgradeService(codeHash.asOpaque(), gas, allowance);
|
|
22086
|
-
logger_logger.trace `UPGRADE(${codeHash}, ${gas}, ${allowance})`;
|
|
22190
|
+
logger_logger.trace `[${this.currentServiceId}] UPGRADE(${codeHash}, ${gas}, ${allowance})`;
|
|
22087
22191
|
regs.set(upgrade_IN_OUT_REG, HostCallResult.OK);
|
|
22088
22192
|
}
|
|
22089
22193
|
}
|
|
@@ -22117,11 +22221,11 @@ class Yield {
|
|
|
22117
22221
|
const hash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
22118
22222
|
const memoryReadResult = memory.loadInto(hash.raw, hashStart);
|
|
22119
22223
|
if (memoryReadResult.isError) {
|
|
22120
|
-
logger_logger.trace `YIELD() <- PANIC`;
|
|
22224
|
+
logger_logger.trace `[${this.currentServiceId}] YIELD() <- PANIC`;
|
|
22121
22225
|
return PvmExecution.Panic;
|
|
22122
22226
|
}
|
|
22123
22227
|
this.partialState.yield(hash);
|
|
22124
|
-
logger_logger.trace `YIELD(${hash})`;
|
|
22228
|
+
logger_logger.trace `[${this.currentServiceId}] YIELD(${hash})`;
|
|
22125
22229
|
regs.set(yield_IN_OUT_REG, HostCallResult.OK);
|
|
22126
22230
|
}
|
|
22127
22231
|
}
|
|
@@ -22164,10 +22268,10 @@ class Fetch {
|
|
|
22164
22268
|
const chunk = value === null ? new Uint8Array() : value.raw.subarray(Number(offset), Number(offset + length));
|
|
22165
22269
|
const storeResult = memory.storeFrom(output, chunk);
|
|
22166
22270
|
if (storeResult.isError) {
|
|
22167
|
-
logger_logger.trace `FETCH(${kind}) <- PANIC`;
|
|
22271
|
+
logger_logger.trace `[${this.currentServiceId}] FETCH(${kind}) <- PANIC`;
|
|
22168
22272
|
return PvmExecution.Panic;
|
|
22169
22273
|
}
|
|
22170
|
-
logger_logger.trace `FETCH(${kind}) <- ${value?.toStringTruncated()}`;
|
|
22274
|
+
logger_logger.trace `[${this.currentServiceId}] FETCH(${kind}) <- ${value?.toStringTruncated()}`;
|
|
22171
22275
|
// write result
|
|
22172
22276
|
regs.set(fetch_IN_OUT_REG, value === null ? HostCallResult.NONE : valueLength);
|
|
22173
22277
|
}
|
|
@@ -22317,7 +22421,7 @@ class LogHostCall {
|
|
|
22317
22421
|
}
|
|
22318
22422
|
memory.loadInto(message, msgStart);
|
|
22319
22423
|
const level = clampU64ToU32(lvl);
|
|
22320
|
-
logger_logger.trace `LOG(${this.currentServiceId}, ${level < Levels.UNKNOWN ? Levels[level] : Levels[Levels.UNKNOWN]}(${lvl}), ${decoder.decode(target)}, ${decoder.decode(message)})`;
|
|
22424
|
+
logger_logger.trace `[${this.currentServiceId}] LOG(${this.currentServiceId}, ${level < Levels.UNKNOWN ? Levels[level] : Levels[Levels.UNKNOWN]}(${lvl}), ${decoder.decode(target)}, ${decoder.decode(message)})`;
|
|
22321
22425
|
return Promise.resolve(undefined);
|
|
22322
22426
|
}
|
|
22323
22427
|
}
|
|
@@ -22358,12 +22462,12 @@ class Lookup {
|
|
|
22358
22462
|
const preImageHash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
22359
22463
|
const memoryReadResult = memory.loadInto(preImageHash.raw, hashAddress);
|
|
22360
22464
|
if (memoryReadResult.isError) {
|
|
22361
|
-
logger_logger.trace `LOOKUP(${serviceId}, ${preImageHash}) <- PANIC`;
|
|
22465
|
+
logger_logger.trace `[${this.currentServiceId}] LOOKUP(${serviceId}, ${preImageHash}) <- PANIC`;
|
|
22362
22466
|
return PvmExecution.Panic;
|
|
22363
22467
|
}
|
|
22364
22468
|
// v
|
|
22365
22469
|
const preImage = this.account.lookup(serviceId, preImageHash);
|
|
22366
|
-
logger_logger.trace `LOOKUP(${serviceId}, ${preImageHash}) <- ${preImage?.toStringTruncated() ?? "<missing>"}...`;
|
|
22470
|
+
logger_logger.trace `[${this.currentServiceId}] LOOKUP(${serviceId}, ${preImageHash}) <- ${preImage?.toStringTruncated() ?? "<missing>"}...`;
|
|
22367
22471
|
const preImageLength = preImage === null ? numbers_tryAsU64(0) : numbers_tryAsU64(preImage.raw.length);
|
|
22368
22472
|
const preimageBlobOffset = regs.get(10);
|
|
22369
22473
|
const lengthToWrite = regs.get(11);
|
|
@@ -22460,20 +22564,20 @@ class Read {
|
|
|
22460
22564
|
const chunk = value === null ? safe_alloc_uint8array_safeAllocUint8Array(0) : value.raw.subarray(Number(offset), Number(offset + blobLength));
|
|
22461
22565
|
const memoryWriteResult = memory.storeFrom(destinationAddress, chunk);
|
|
22462
22566
|
if (memoryWriteResult.isError) {
|
|
22463
|
-
logger_logger.trace `READ(${serviceId}, ${rawKey}) <- PANIC`;
|
|
22567
|
+
logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- PANIC`;
|
|
22464
22568
|
return PvmExecution.Panic;
|
|
22465
22569
|
}
|
|
22466
22570
|
if (value === null) {
|
|
22467
|
-
logger_logger.trace `READ(${serviceId}, ${rawKey}) <- NONE`;
|
|
22571
|
+
logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- NONE`;
|
|
22468
22572
|
regs.set(read_IN_OUT_REG, HostCallResult.NONE);
|
|
22469
22573
|
return;
|
|
22470
22574
|
}
|
|
22471
22575
|
if (chunk.length > 0) {
|
|
22472
|
-
logger_logger.trace `READ(${serviceId}, ${rawKey}) <- ${bytes_BytesBlob.blobFrom(chunk).toStringTruncated()}`;
|
|
22576
|
+
logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- ${bytes_BytesBlob.blobFrom(chunk).toStringTruncated()}`;
|
|
22473
22577
|
}
|
|
22474
22578
|
else {
|
|
22475
22579
|
// just a query for length of stored data
|
|
22476
|
-
logger_logger.trace `READ(${serviceId}, ${rawKey}) <- (${valueLength} ${valueLength === 1n ? "byte" : "bytes"})`;
|
|
22580
|
+
logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- (${valueLength} ${valueLength === 1n ? "byte" : "bytes"})`;
|
|
22477
22581
|
}
|
|
22478
22582
|
regs.set(read_IN_OUT_REG, valueLength);
|
|
22479
22583
|
}
|
|
@@ -22517,7 +22621,7 @@ class Write {
|
|
|
22517
22621
|
const rawStorageKey = safe_alloc_uint8array_safeAllocUint8Array(storageKeyLengthClamped);
|
|
22518
22622
|
const keyLoadingResult = memory.loadInto(rawStorageKey, storageKeyStartAddress);
|
|
22519
22623
|
if (keyLoadingResult.isError) {
|
|
22520
|
-
logger_logger.trace `WRITE() <- PANIC`;
|
|
22624
|
+
logger_logger.trace `[${this.currentServiceId}] WRITE() <- PANIC`;
|
|
22521
22625
|
return PvmExecution.Panic;
|
|
22522
22626
|
}
|
|
22523
22627
|
// k
|
|
@@ -22527,14 +22631,14 @@ class Write {
|
|
|
22527
22631
|
const valueLoadingResult = memory.loadInto(value, valueStart);
|
|
22528
22632
|
// Note [MaSo] this is ok to return bcs if valueLength is 0, then this panic won't happen
|
|
22529
22633
|
if (valueLoadingResult.isError) {
|
|
22530
|
-
logger_logger.trace `WRITE(${storageKey}) <- PANIC`;
|
|
22634
|
+
logger_logger.trace `[${this.currentServiceId}] WRITE(${storageKey}) <- PANIC`;
|
|
22531
22635
|
return PvmExecution.Panic;
|
|
22532
22636
|
}
|
|
22533
22637
|
/** https://graypaper.fluffylabs.dev/#/9a08063/33af0133b201?v=0.6.6 */
|
|
22534
22638
|
const maybeValue = valueLength === 0n ? null : bytes_BytesBlob.blobFrom(value);
|
|
22535
22639
|
// a
|
|
22536
22640
|
const result = this.account.write(storageKey, maybeValue);
|
|
22537
|
-
logger_logger.trace `WRITE(${storageKey}, ${maybeValue?.toStringTruncated() ?? "remove"}) <- ${resultToString(result)}`;
|
|
22641
|
+
logger_logger.trace `[${this.currentServiceId}] WRITE(${storageKey}, ${maybeValue?.toStringTruncated() ?? "remove"}) <- ${resultToString(result)}`;
|
|
22538
22642
|
if (result.isError) {
|
|
22539
22643
|
regs.set(write_IN_OUT_REG, HostCallResult.FULL);
|
|
22540
22644
|
return;
|
|
@@ -22763,7 +22867,7 @@ class Accumulate {
|
|
|
22763
22867
|
serviceId,
|
|
22764
22868
|
argsLength: numbers_tryAsU32(transfers.length + operands.length),
|
|
22765
22869
|
});
|
|
22766
|
-
const result = await executor.run(invocationArgs,
|
|
22870
|
+
const result = await executor.run(invocationArgs, gas_tryAsGas(gas));
|
|
22767
22871
|
const [newState, checkpoint] = partialState.getStateUpdates();
|
|
22768
22872
|
/**
|
|
22769
22873
|
* PVM invocation returned and error so we return the checkpoint
|
|
@@ -22964,19 +23068,19 @@ class Accumulate {
|
|
|
22964
23068
|
for (let serviceIndex = 0; serviceIndex < serviceIdsLength; serviceIndex += 1) {
|
|
22965
23069
|
const serviceId = serviceIds[serviceIndex];
|
|
22966
23070
|
const checkpoint = AccumulationStateUpdate.copyFrom(inputStateUpdate);
|
|
22967
|
-
const promise = this.accumulateSingleService(serviceId, accumulateData.getTransfers(serviceId), accumulateData.getOperands(serviceId), accumulateData.getGasLimit(serviceId), slot, entropy, AccumulationStateUpdate.copyFrom(inputStateUpdate)).then(({ consumedGas, stateUpdate }) =>
|
|
22968
|
-
|
|
22969
|
-
|
|
22970
|
-
|
|
23071
|
+
const promise = this.accumulateSingleService(serviceId, accumulateData.getTransfers(serviceId), accumulateData.getOperands(serviceId), accumulateData.getGasLimit(serviceId), slot, entropy, AccumulationStateUpdate.copyFrom(inputStateUpdate)).then(({ consumedGas, stateUpdate }) => {
|
|
23072
|
+
const resultEntry = [
|
|
23073
|
+
serviceId,
|
|
23074
|
+
{
|
|
23075
|
+
consumedGas,
|
|
23076
|
+
stateUpdate: stateUpdate === null ? checkpoint : stateUpdate,
|
|
23077
|
+
},
|
|
23078
|
+
];
|
|
23079
|
+
return resultEntry;
|
|
23080
|
+
});
|
|
22971
23081
|
resultPromises[serviceIndex] = promise;
|
|
22972
23082
|
}
|
|
22973
|
-
return Promise.all(resultPromises).then((results) =>
|
|
22974
|
-
const map = new Map();
|
|
22975
|
-
for (let serviceIndex = 0; serviceIndex < serviceIdsLength; serviceIndex += 1) {
|
|
22976
|
-
map.set(serviceIds[serviceIndex], results[serviceIndex]);
|
|
22977
|
-
}
|
|
22978
|
-
return map;
|
|
22979
|
-
});
|
|
23083
|
+
return Promise.all(resultPromises).then((results) => new Map(results));
|
|
22980
23084
|
}
|
|
22981
23085
|
/**
|
|
22982
23086
|
* A method that updates `recentlyAccumulated`, `accumulationQueue` and `timeslot` in state
|
|
@@ -23065,9 +23169,10 @@ class Accumulate {
|
|
|
23065
23169
|
const _gasCost = gasCost;
|
|
23066
23170
|
assertEmpty(rest);
|
|
23067
23171
|
const accumulated = accumulatableReports.subview(0, accumulatedReports);
|
|
23068
|
-
const { yieldedRoot, services, transfers
|
|
23172
|
+
const { yieldedRoot, services, transfers, validatorsData, privilegedServices, authorizationQueues, ...stateUpdateRest } = state;
|
|
23069
23173
|
assertEmpty(stateUpdateRest);
|
|
23070
|
-
// yielded root
|
|
23174
|
+
// transfers and yielded root are retrieved after each pvm invocation so we can ignore it here
|
|
23175
|
+
const _transfers = transfers;
|
|
23071
23176
|
const _yieldedRoot = yieldedRoot;
|
|
23072
23177
|
if (this.hasDuplicatedServiceIdCreated(services.created)) {
|
|
23073
23178
|
accumulate_logger.trace `Duplicated Service creation detected. Block is invalid.`;
|
|
@@ -23166,7 +23271,7 @@ class DeferredTransfers {
|
|
|
23166
23271
|
partiallyUpdatedState.updateServiceInfo(serviceId, newInfo);
|
|
23167
23272
|
const partialState = new AccumulateExternalities(this.chainSpec, this.blake2b, partiallyUpdatedState, serviceId, serviceId, timeslot);
|
|
23168
23273
|
const fetchExternalities = FetchExternalities.createForOnTransfer({ entropy, transfers }, this.chainSpec);
|
|
23169
|
-
let consumedGas =
|
|
23274
|
+
let consumedGas = gas_tryAsGas(0);
|
|
23170
23275
|
const hasTransfers = transfers.length > 0;
|
|
23171
23276
|
const isCodeCorrect = code !== null && code.length <= W_C;
|
|
23172
23277
|
if (!hasTransfers || !isCodeCorrect) {
|
|
@@ -23184,7 +23289,7 @@ class DeferredTransfers {
|
|
|
23184
23289
|
const executor = await PvmExecutor.createOnTransferExecutor(serviceId, code, { partialState, fetchExternalities }, this.pvm);
|
|
23185
23290
|
const args = encoder_Encoder.encodeObject(deferred_transfers_ARGS_CODEC, { timeslot, serviceId, transfersLength: numbers_tryAsU32(transfers.length) }, this.chainSpec);
|
|
23186
23291
|
const gas = transfers.reduce((acc, item) => acc + item.gas, 0n);
|
|
23187
|
-
consumedGas = (await executor.run(args,
|
|
23292
|
+
consumedGas = (await executor.run(args, gas_tryAsGas(gas))).consumedGas;
|
|
23188
23293
|
}
|
|
23189
23294
|
transferStatistics.set(serviceId, { count: numbers_tryAsU32(transfers.length), gasUsed: tryAsServiceGas(consumedGas) });
|
|
23190
23295
|
const [updatedState] = partialState.getStateUpdates();
|