@typeberry/jam 0.4.0 → 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 +35 -12
- package/bootstrap-generator.mjs.map +1 -1
- package/bootstrap-importer.mjs +315 -214
- package/bootstrap-importer.mjs.map +1 -1
- package/bootstrap-network.mjs +9 -8
- package/bootstrap-network.mjs.map +1 -1
- package/index.js +319 -218
- 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.
|
|
@@ -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(
|
|
7107
|
-
this.context = context;
|
|
7109
|
+
constructor(keccakHasher, blake2b) {
|
|
7108
7110
|
this.keccakHasher = keccakHasher;
|
|
7109
7111
|
this.blake2b = blake2b;
|
|
7110
7112
|
}
|
|
@@ -10630,11 +10632,32 @@ const ENTROPY_ENTRIES = 4;
|
|
|
10630
10632
|
|
|
10631
10633
|
var state_update_UpdatePreimageKind;
|
|
10632
10634
|
(function (UpdatePreimageKind) {
|
|
10633
|
-
/**
|
|
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
|
+
*/
|
|
10634
10642
|
UpdatePreimageKind[UpdatePreimageKind["Provide"] = 0] = "Provide";
|
|
10635
|
-
/**
|
|
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
|
+
*/
|
|
10636
10651
|
UpdatePreimageKind[UpdatePreimageKind["Remove"] = 1] = "Remove";
|
|
10637
|
-
/**
|
|
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
|
+
*/
|
|
10638
10661
|
UpdatePreimageKind[UpdatePreimageKind["UpdateOrAdd"] = 2] = "UpdateOrAdd";
|
|
10639
10662
|
})(state_update_UpdatePreimageKind || (state_update_UpdatePreimageKind = {}));
|
|
10640
10663
|
/**
|
|
@@ -10642,7 +10665,7 @@ var state_update_UpdatePreimageKind;
|
|
|
10642
10665
|
*
|
|
10643
10666
|
* Can be one of the following cases:
|
|
10644
10667
|
* 1. Provide a new preimage blob and set the lookup history to available at `slot`.
|
|
10645
|
-
* 2. Remove (
|
|
10668
|
+
* 2. Remove (forget) a preimage and it's lookup history.
|
|
10646
10669
|
* 3. Update `LookupHistory` with given value.
|
|
10647
10670
|
*/
|
|
10648
10671
|
class UpdatePreimage {
|
|
@@ -13212,7 +13235,6 @@ class LeafNode {
|
|
|
13212
13235
|
/**
|
|
13213
13236
|
* Get the byte length of embedded value.
|
|
13214
13237
|
*
|
|
13215
|
-
* @remark
|
|
13216
13238
|
* Note in case this node only contains hash this is going to be 0.
|
|
13217
13239
|
*/
|
|
13218
13240
|
getValueLength() {
|
|
@@ -13223,7 +13245,6 @@ class LeafNode {
|
|
|
13223
13245
|
/**
|
|
13224
13246
|
* Returns the embedded value.
|
|
13225
13247
|
*
|
|
13226
|
-
* @remark
|
|
13227
13248
|
* Note that this is going to be empty for a regular leaf node (i.e. containing a hash).
|
|
13228
13249
|
*/
|
|
13229
13250
|
getValue() {
|
|
@@ -13233,7 +13254,6 @@ class LeafNode {
|
|
|
13233
13254
|
/**
|
|
13234
13255
|
* Returns contained value hash.
|
|
13235
13256
|
*
|
|
13236
|
-
* @remark
|
|
13237
13257
|
* Note that for embedded value this is going to be full 0-padded 32 bytes.
|
|
13238
13258
|
*/
|
|
13239
13259
|
getValueHash() {
|
|
@@ -14254,7 +14274,11 @@ class PartiallyUpdatedState {
|
|
|
14254
14274
|
const service = this.state.getService(serviceId);
|
|
14255
14275
|
return service?.getPreimage(hash) ?? null;
|
|
14256
14276
|
}
|
|
14257
|
-
/**
|
|
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
|
+
*/
|
|
14258
14282
|
getLookupHistory(currentTimeslot, serviceId, hash, length) {
|
|
14259
14283
|
const updatedService = this.stateUpdate.services.updated.get(serviceId);
|
|
14260
14284
|
/** Return lookup history item for newly created service */
|
|
@@ -14291,12 +14315,7 @@ class PartiallyUpdatedState {
|
|
|
14291
14315
|
return new LookupHistoryItem(hash, updatedPreimage.length, service_tryAsLookupHistorySlots([currentTimeslot]));
|
|
14292
14316
|
}
|
|
14293
14317
|
case state_update_UpdatePreimageKind.Remove: {
|
|
14294
|
-
|
|
14295
|
-
// kinda impossible, since we know it's there because it's removed.
|
|
14296
|
-
if (state === null) {
|
|
14297
|
-
return null;
|
|
14298
|
-
}
|
|
14299
|
-
return new LookupHistoryItem(hash, state.length, service_tryAsLookupHistorySlots([...state.slots, currentTimeslot]));
|
|
14318
|
+
return null;
|
|
14300
14319
|
}
|
|
14301
14320
|
case state_update_UpdatePreimageKind.UpdateOrAdd: {
|
|
14302
14321
|
return action.item;
|
|
@@ -14389,7 +14408,7 @@ const gas_tryAsSmallGas = (v) => opaque_asOpaqueType(numbers_tryAsU32(v));
|
|
|
14389
14408
|
/** Attempt to convert given number into U64 gas representation. */
|
|
14390
14409
|
const tryAsBigGas = (v) => opaque_asOpaqueType(numbers_tryAsU64(v));
|
|
14391
14410
|
/** Attempt to convert given number into gas. */
|
|
14392
|
-
const
|
|
14411
|
+
const gas_tryAsGas = (v) => typeof v === "number" && v < 2 ** 32 ? gas_tryAsSmallGas(v) : tryAsBigGas(v);
|
|
14393
14412
|
|
|
14394
14413
|
;// CONCATENATED MODULE: ./packages/core/pvm-interface/memory.ts
|
|
14395
14414
|
|
|
@@ -14672,7 +14691,7 @@ const tryAsRegisterIndex = (index) => {
|
|
|
14672
14691
|
debug_check `${index >= 0 && index < registers_NO_OF_REGISTERS} Incorrect register index: ${index}!`;
|
|
14673
14692
|
return opaque_asOpaqueType(index);
|
|
14674
14693
|
};
|
|
14675
|
-
class
|
|
14694
|
+
class registers_Registers {
|
|
14676
14695
|
bytes;
|
|
14677
14696
|
asSigned;
|
|
14678
14697
|
asUnsigned;
|
|
@@ -14691,7 +14710,7 @@ class Registers {
|
|
|
14691
14710
|
}
|
|
14692
14711
|
static fromBytes(bytes) {
|
|
14693
14712
|
debug_check `${bytes.length === registers_NO_OF_REGISTERS << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
|
|
14694
|
-
return new
|
|
14713
|
+
return new registers_Registers(bytes);
|
|
14695
14714
|
}
|
|
14696
14715
|
getBytesAsLittleEndian(index, len) {
|
|
14697
14716
|
const offset = index << REGISTER_SIZE_SHIFT;
|
|
@@ -15005,49 +15024,10 @@ class NoopMissing {
|
|
|
15005
15024
|
}
|
|
15006
15025
|
}
|
|
15007
15026
|
|
|
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
15027
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/memory-index.ts
|
|
15048
15028
|
|
|
15049
15029
|
|
|
15050
|
-
const
|
|
15030
|
+
const memory_index_tryAsMemoryIndex = (index) => {
|
|
15051
15031
|
debug_check `${index >= 0 && index <= MAX_MEMORY_INDEX} Incorrect memory index: ${index}!`;
|
|
15052
15032
|
return opaque_asOpaqueType(index);
|
|
15053
15033
|
};
|
|
@@ -15061,25 +15041,25 @@ const tryAsSbrkIndex = (index) => {
|
|
|
15061
15041
|
|
|
15062
15042
|
const memory_consts_PAGE_SIZE_SHIFT = 12;
|
|
15063
15043
|
// PAGE_SIZE has to be a power of 2
|
|
15064
|
-
const
|
|
15044
|
+
const memory_consts_PAGE_SIZE = 1 << memory_consts_PAGE_SIZE_SHIFT;
|
|
15065
15045
|
const MIN_ALLOCATION_SHIFT = (() => {
|
|
15066
15046
|
const MIN_ALLOCATION_SHIFT = 7;
|
|
15067
15047
|
debug_check `${MIN_ALLOCATION_SHIFT >= 0 && MIN_ALLOCATION_SHIFT < memory_consts_PAGE_SIZE_SHIFT} incorrect minimal allocation shift`;
|
|
15068
15048
|
return MIN_ALLOCATION_SHIFT;
|
|
15069
15049
|
})();
|
|
15070
|
-
const MIN_ALLOCATION_LENGTH =
|
|
15071
|
-
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;
|
|
15072
15052
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/35a60235a602?v=0.6.4 */
|
|
15073
15053
|
const RESERVED_NUMBER_OF_PAGES = 16;
|
|
15074
15054
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/35a60235a602?v=0.6.4 */
|
|
15075
|
-
const MAX_NUMBER_OF_PAGES = MEMORY_SIZE /
|
|
15055
|
+
const MAX_NUMBER_OF_PAGES = MEMORY_SIZE / memory_consts_PAGE_SIZE;
|
|
15076
15056
|
|
|
15077
15057
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/pages/page-utils.ts
|
|
15078
15058
|
|
|
15079
15059
|
|
|
15080
15060
|
/** Ensure that given memory `index` is within `[0...PAGE_SIZE)` and can be used to index a page */
|
|
15081
15061
|
const tryAsPageIndex = (index) => {
|
|
15082
|
-
debug_check `${index >= 0 && index <
|
|
15062
|
+
debug_check `${index >= 0 && index < memory_consts_PAGE_SIZE}, Incorect page index: ${index}!`;
|
|
15083
15063
|
return opaque_asOpaqueType(index);
|
|
15084
15064
|
};
|
|
15085
15065
|
/** Ensure that given `index` represents an index of one of the pages. */
|
|
@@ -15107,17 +15087,17 @@ function getNextPageNumber(pageNumber) {
|
|
|
15107
15087
|
|
|
15108
15088
|
|
|
15109
15089
|
function alignToPageSize(length) {
|
|
15110
|
-
return
|
|
15090
|
+
return memory_consts_PAGE_SIZE * Math.ceil(length / memory_consts_PAGE_SIZE);
|
|
15111
15091
|
}
|
|
15112
15092
|
function getPageNumber(address) {
|
|
15113
15093
|
return tryAsPageNumber(address >>> memory_consts_PAGE_SIZE_SHIFT);
|
|
15114
15094
|
}
|
|
15115
15095
|
function getStartPageIndex(address) {
|
|
15116
|
-
return
|
|
15096
|
+
return memory_index_tryAsMemoryIndex((address >>> memory_consts_PAGE_SIZE_SHIFT) << memory_consts_PAGE_SIZE_SHIFT);
|
|
15117
15097
|
}
|
|
15118
15098
|
function getStartPageIndexFromPageNumber(pageNumber) {
|
|
15119
15099
|
// >>> 0 is needed to avoid changing sign of the number
|
|
15120
|
-
return
|
|
15100
|
+
return memory_index_tryAsMemoryIndex((pageNumber << memory_consts_PAGE_SIZE_SHIFT) >>> 0);
|
|
15121
15101
|
}
|
|
15122
15102
|
|
|
15123
15103
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/errors.ts
|
|
@@ -15139,7 +15119,7 @@ class PageFault {
|
|
|
15139
15119
|
return new PageFault(numbers_tryAsU32(startPageIndex), isAccessFault);
|
|
15140
15120
|
}
|
|
15141
15121
|
static fromMemoryIndex(maybeMemoryIndex, isAccessFault = false) {
|
|
15142
|
-
const memoryIndex =
|
|
15122
|
+
const memoryIndex = memory_index_tryAsMemoryIndex(maybeMemoryIndex % MEMORY_SIZE);
|
|
15143
15123
|
const startPageIndex = getStartPageIndex(memoryIndex);
|
|
15144
15124
|
return new PageFault(numbers_tryAsU32(startPageIndex), isAccessFault);
|
|
15145
15125
|
}
|
|
@@ -15218,9 +15198,9 @@ class MemoryRange {
|
|
|
15218
15198
|
constructor(start, length) {
|
|
15219
15199
|
this.start = start;
|
|
15220
15200
|
this.length = length;
|
|
15221
|
-
this.end =
|
|
15201
|
+
this.end = memory_index_tryAsMemoryIndex((this.start + this.length) % MEMORY_SIZE);
|
|
15222
15202
|
if (length > 0) {
|
|
15223
|
-
this.lastIndex =
|
|
15203
|
+
this.lastIndex = memory_index_tryAsMemoryIndex((this.end - 1 + MEMORY_SIZE) % MEMORY_SIZE);
|
|
15224
15204
|
}
|
|
15225
15205
|
}
|
|
15226
15206
|
/** Creates a memory range from given starting point and length */
|
|
@@ -15263,7 +15243,7 @@ class MemoryRange {
|
|
|
15263
15243
|
*
|
|
15264
15244
|
* it should be in `memory-consts` but it cannot be there because of circular dependency
|
|
15265
15245
|
*/
|
|
15266
|
-
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);
|
|
15267
15247
|
|
|
15268
15248
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/page-range.ts
|
|
15269
15249
|
|
|
@@ -15301,7 +15281,7 @@ class PageRange {
|
|
|
15301
15281
|
// lastIndex is not null because we just ensured that the range is not empty
|
|
15302
15282
|
const pageWithLastIndex = getPageNumber(range.lastIndex ?? range.end);
|
|
15303
15283
|
const endPage = getNextPageNumber(pageWithLastIndex);
|
|
15304
|
-
if ((startPage === endPage || startPage === pageWithLastIndex) && range.length >
|
|
15284
|
+
if ((startPage === endPage || startPage === pageWithLastIndex) && range.length > memory_consts_PAGE_SIZE) {
|
|
15305
15285
|
// full range
|
|
15306
15286
|
return new PageRange(startPage, MAX_NUMBER_OF_PAGES);
|
|
15307
15287
|
}
|
|
@@ -15365,8 +15345,8 @@ class ReadablePage extends MemoryPage {
|
|
|
15365
15345
|
}
|
|
15366
15346
|
loadInto(result, startIndex, length) {
|
|
15367
15347
|
const endIndex = startIndex + length;
|
|
15368
|
-
if (endIndex >
|
|
15369
|
-
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}`);
|
|
15370
15350
|
}
|
|
15371
15351
|
const bytes = this.data.subarray(startIndex, endIndex);
|
|
15372
15352
|
// we zero the bytes, since data might not yet be initialized at `endIndex`.
|
|
@@ -15399,8 +15379,8 @@ class WriteablePage extends MemoryPage {
|
|
|
15399
15379
|
constructor(pageNumber, initialData) {
|
|
15400
15380
|
super(pageNumber);
|
|
15401
15381
|
const dataLength = initialData?.length ?? 0;
|
|
15402
|
-
const initialPageLength = Math.min(
|
|
15403
|
-
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 });
|
|
15404
15384
|
this.view = new Uint8Array(this.buffer);
|
|
15405
15385
|
if (initialData !== undefined) {
|
|
15406
15386
|
this.view.set(initialData);
|
|
@@ -15408,8 +15388,8 @@ class WriteablePage extends MemoryPage {
|
|
|
15408
15388
|
}
|
|
15409
15389
|
loadInto(result, startIndex, length) {
|
|
15410
15390
|
const endIndex = startIndex + length;
|
|
15411
|
-
if (endIndex >
|
|
15412
|
-
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}`);
|
|
15413
15393
|
}
|
|
15414
15394
|
const bytes = this.view.subarray(startIndex, endIndex);
|
|
15415
15395
|
// we zero the bytes, since the view might not yet be initialized at `endIndex`.
|
|
@@ -15418,16 +15398,16 @@ class WriteablePage extends MemoryPage {
|
|
|
15418
15398
|
return Result.ok(OK);
|
|
15419
15399
|
}
|
|
15420
15400
|
storeFrom(startIndex, bytes) {
|
|
15421
|
-
if (this.buffer.byteLength < startIndex + bytes.length && this.buffer.byteLength <
|
|
15422
|
-
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));
|
|
15423
15403
|
this.buffer.resize(newLength);
|
|
15424
15404
|
}
|
|
15425
15405
|
this.view.set(bytes, startIndex);
|
|
15426
15406
|
return Result.ok(OK);
|
|
15427
15407
|
}
|
|
15428
15408
|
setData(pageIndex, data) {
|
|
15429
|
-
if (this.buffer.byteLength < pageIndex + data.length && this.buffer.byteLength <
|
|
15430
|
-
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));
|
|
15431
15411
|
this.buffer.resize(newLength);
|
|
15432
15412
|
}
|
|
15433
15413
|
this.view.set(data, pageIndex);
|
|
@@ -15478,10 +15458,10 @@ class Memory {
|
|
|
15478
15458
|
this.memory = memory;
|
|
15479
15459
|
}
|
|
15480
15460
|
store(address, bytes) {
|
|
15481
|
-
return this.storeFrom(
|
|
15461
|
+
return this.storeFrom(memory_index_tryAsMemoryIndex(address), bytes);
|
|
15482
15462
|
}
|
|
15483
15463
|
read(address, output) {
|
|
15484
|
-
return this.loadInto(output,
|
|
15464
|
+
return this.loadInto(output, memory_index_tryAsMemoryIndex(address));
|
|
15485
15465
|
}
|
|
15486
15466
|
reset() {
|
|
15487
15467
|
this.sbrkIndex = tryAsSbrkIndex(RESERVED_MEMORY_RANGE.end);
|
|
@@ -15508,8 +15488,8 @@ class Memory {
|
|
|
15508
15488
|
let currentPosition = address;
|
|
15509
15489
|
let bytesLeft = bytes.length;
|
|
15510
15490
|
for (const page of pages) {
|
|
15511
|
-
const pageStartIndex = tryAsPageIndex(currentPosition %
|
|
15512
|
-
const bytesToWrite = Math.min(
|
|
15491
|
+
const pageStartIndex = tryAsPageIndex(currentPosition % memory_consts_PAGE_SIZE);
|
|
15492
|
+
const bytesToWrite = Math.min(memory_consts_PAGE_SIZE - pageStartIndex, bytesLeft);
|
|
15513
15493
|
const sourceStartIndex = currentPosition - address;
|
|
15514
15494
|
const source = bytes.subarray(sourceStartIndex, sourceStartIndex + bytesToWrite);
|
|
15515
15495
|
page.storeFrom(pageStartIndex, source);
|
|
@@ -15558,8 +15538,8 @@ class Memory {
|
|
|
15558
15538
|
let currentPosition = startAddress;
|
|
15559
15539
|
let bytesLeft = result.length;
|
|
15560
15540
|
for (const page of pages) {
|
|
15561
|
-
const pageStartIndex = tryAsPageIndex(currentPosition %
|
|
15562
|
-
const bytesToRead = Math.min(
|
|
15541
|
+
const pageStartIndex = tryAsPageIndex(currentPosition % memory_consts_PAGE_SIZE);
|
|
15542
|
+
const bytesToRead = Math.min(memory_consts_PAGE_SIZE - pageStartIndex, bytesLeft);
|
|
15563
15543
|
const destinationStartIndex = currentPosition - startAddress;
|
|
15564
15544
|
const destination = result.subarray(destinationStartIndex);
|
|
15565
15545
|
page.loadInto(destination, pageStartIndex, bytesToRead);
|
|
@@ -15586,7 +15566,7 @@ class Memory {
|
|
|
15586
15566
|
const newSbrkIndex = tryAsSbrkIndex(alignToPageSize(newVirtualSbrkIndex));
|
|
15587
15567
|
// TODO [MaSi]: `getPageNumber` works incorrectly for SbrkIndex. Sbrk index should be changed to MemoryIndex
|
|
15588
15568
|
const firstPageNumber = getPageNumber(currentSbrkIndex);
|
|
15589
|
-
const pagesToAllocate = (newSbrkIndex - currentSbrkIndex) /
|
|
15569
|
+
const pagesToAllocate = (newSbrkIndex - currentSbrkIndex) / memory_consts_PAGE_SIZE;
|
|
15590
15570
|
const rangeToAllocate = PageRange.fromStartAndLength(firstPageNumber, pagesToAllocate);
|
|
15591
15571
|
for (const pageNumber of rangeToAllocate) {
|
|
15592
15572
|
const page = new WriteablePage(pageNumber);
|
|
@@ -15641,8 +15621,8 @@ class MemoryBuilder {
|
|
|
15641
15621
|
setReadablePages(start, end, data = new Uint8Array()) {
|
|
15642
15622
|
this.ensureNotFinalized();
|
|
15643
15623
|
debug_check `${start < end} end has to be bigger than start`;
|
|
15644
|
-
debug_check `${start %
|
|
15645
|
-
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})`;
|
|
15646
15626
|
debug_check `${data.length <= end - start} the initial data is longer than address range`;
|
|
15647
15627
|
const length = end - start;
|
|
15648
15628
|
const range = MemoryRange.fromStartAndLength(start, length);
|
|
@@ -15651,7 +15631,7 @@ class MemoryBuilder {
|
|
|
15651
15631
|
const noOfPages = pages.length;
|
|
15652
15632
|
for (let i = 0; i < noOfPages; i++) {
|
|
15653
15633
|
const pageNumber = pages[i];
|
|
15654
|
-
const dataChunk = data.subarray(i *
|
|
15634
|
+
const dataChunk = data.subarray(i * memory_consts_PAGE_SIZE, (i + 1) * memory_consts_PAGE_SIZE);
|
|
15655
15635
|
const page = new ReadablePage(pageNumber, dataChunk);
|
|
15656
15636
|
this.initialMemory.set(pageNumber, page);
|
|
15657
15637
|
}
|
|
@@ -15669,8 +15649,8 @@ class MemoryBuilder {
|
|
|
15669
15649
|
setWriteablePages(start, end, data = new Uint8Array()) {
|
|
15670
15650
|
this.ensureNotFinalized();
|
|
15671
15651
|
debug_check `${start < end} end has to be bigger than start`;
|
|
15672
|
-
debug_check `${start %
|
|
15673
|
-
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})`;
|
|
15674
15654
|
debug_check `${data.length <= end - start} the initial data is longer than address range`;
|
|
15675
15655
|
const length = end - start;
|
|
15676
15656
|
const range = MemoryRange.fromStartAndLength(start, length);
|
|
@@ -15679,7 +15659,7 @@ class MemoryBuilder {
|
|
|
15679
15659
|
const noOfPages = pages.length;
|
|
15680
15660
|
for (let i = 0; i < noOfPages; i++) {
|
|
15681
15661
|
const pageNumber = pages[i];
|
|
15682
|
-
const dataChunk = data.subarray(i *
|
|
15662
|
+
const dataChunk = data.subarray(i * memory_consts_PAGE_SIZE, (i + 1) * memory_consts_PAGE_SIZE);
|
|
15683
15663
|
const page = new WriteablePage(pageNumber, dataChunk);
|
|
15684
15664
|
this.initialMemory.set(pageNumber, page);
|
|
15685
15665
|
}
|
|
@@ -15691,8 +15671,8 @@ class MemoryBuilder {
|
|
|
15691
15671
|
*/
|
|
15692
15672
|
setData(start, data) {
|
|
15693
15673
|
this.ensureNotFinalized();
|
|
15694
|
-
const pageOffset = start %
|
|
15695
|
-
const remainingSpaceOnPage =
|
|
15674
|
+
const pageOffset = start % memory_consts_PAGE_SIZE;
|
|
15675
|
+
const remainingSpaceOnPage = memory_consts_PAGE_SIZE - pageOffset;
|
|
15696
15676
|
debug_check `${data.length <= remainingSpaceOnPage} The data has to fit into a single page.`;
|
|
15697
15677
|
const length = data.length;
|
|
15698
15678
|
const range = MemoryRange.fromStartAndLength(start, length);
|
|
@@ -15883,27 +15863,27 @@ class Program {
|
|
|
15883
15863
|
static fromSpi(blob, args, hasMetadata) {
|
|
15884
15864
|
const { code: spiCode, metadata } = hasMetadata ? extractCodeAndMetadata(blob) : { code: blob };
|
|
15885
15865
|
const { code, memory: rawMemory, registers } = decodeStandardProgram(spiCode, args);
|
|
15886
|
-
const regs = new
|
|
15866
|
+
const regs = new registers_Registers();
|
|
15887
15867
|
regs.copyFrom(registers);
|
|
15888
15868
|
const memoryBuilder = new MemoryBuilder();
|
|
15889
15869
|
for (const { start, end, data } of rawMemory.readable) {
|
|
15890
|
-
const startIndex =
|
|
15891
|
-
const endIndex =
|
|
15870
|
+
const startIndex = memory_index_tryAsMemoryIndex(start);
|
|
15871
|
+
const endIndex = memory_index_tryAsMemoryIndex(end);
|
|
15892
15872
|
memoryBuilder.setReadablePages(startIndex, endIndex, data ?? new Uint8Array());
|
|
15893
15873
|
}
|
|
15894
15874
|
for (const { start, end, data } of rawMemory.writeable) {
|
|
15895
|
-
const startIndex =
|
|
15896
|
-
const endIndex =
|
|
15875
|
+
const startIndex = memory_index_tryAsMemoryIndex(start);
|
|
15876
|
+
const endIndex = memory_index_tryAsMemoryIndex(end);
|
|
15897
15877
|
memoryBuilder.setWriteablePages(startIndex, endIndex, data ?? new Uint8Array());
|
|
15898
15878
|
}
|
|
15899
|
-
const heapStart =
|
|
15879
|
+
const heapStart = memory_index_tryAsMemoryIndex(rawMemory.sbrkIndex);
|
|
15900
15880
|
const heapEnd = tryAsSbrkIndex(rawMemory.heapEnd);
|
|
15901
15881
|
const memory = memoryBuilder.finalize(heapStart, heapEnd);
|
|
15902
15882
|
return new Program(code, regs, memory, metadata);
|
|
15903
15883
|
}
|
|
15904
15884
|
static fromGeneric(blob, hasMetadata) {
|
|
15905
15885
|
const { code, metadata } = hasMetadata ? extractCodeAndMetadata(blob) : { code: blob };
|
|
15906
|
-
const regs = new
|
|
15886
|
+
const regs = new registers_Registers();
|
|
15907
15887
|
const memory = new Memory();
|
|
15908
15888
|
return new Program(code, regs, memory, metadata);
|
|
15909
15889
|
}
|
|
@@ -16918,6 +16898,45 @@ class BasicBlocks {
|
|
|
16918
16898
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/basic-blocks/index.ts
|
|
16919
16899
|
|
|
16920
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
|
+
|
|
16921
16940
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/instruction-gas-map.ts
|
|
16922
16941
|
|
|
16923
16942
|
|
|
@@ -17494,7 +17513,7 @@ class LoadOps {
|
|
|
17494
17513
|
}
|
|
17495
17514
|
loadNumber(address, registerIndex, numberLength) {
|
|
17496
17515
|
const registerBytes = this.regs.getBytesAsLittleEndian(registerIndex, REG_SIZE_BYTES);
|
|
17497
|
-
const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength),
|
|
17516
|
+
const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength), memory_index_tryAsMemoryIndex(address));
|
|
17498
17517
|
if (loadResult.isError) {
|
|
17499
17518
|
if (loadResult.error.isAccessFault) {
|
|
17500
17519
|
this.instructionResult.status = result_Result.FAULT_ACCESS;
|
|
@@ -17510,7 +17529,7 @@ class LoadOps {
|
|
|
17510
17529
|
loadSignedNumber(address, registerIndex, numberLength) {
|
|
17511
17530
|
// load all bytes from register to correctly handle the sign.
|
|
17512
17531
|
const registerBytes = this.regs.getBytesAsLittleEndian(registerIndex, REG_SIZE_BYTES);
|
|
17513
|
-
const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength),
|
|
17532
|
+
const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength), memory_index_tryAsMemoryIndex(address));
|
|
17514
17533
|
if (loadResult.isError) {
|
|
17515
17534
|
if (loadResult.error.isAccessFault) {
|
|
17516
17535
|
this.instructionResult.status = result_Result.FAULT_ACCESS;
|
|
@@ -17932,7 +17951,7 @@ class StoreOps {
|
|
|
17932
17951
|
this.store(address, secondImmediateDecoder.getExtendedBytesAsLittleEndian());
|
|
17933
17952
|
}
|
|
17934
17953
|
store(address, bytes) {
|
|
17935
|
-
const storeResult = this.memory.storeFrom(
|
|
17954
|
+
const storeResult = this.memory.storeFrom(memory_index_tryAsMemoryIndex(address), bytes);
|
|
17936
17955
|
if (storeResult.isOk) {
|
|
17937
17956
|
return;
|
|
17938
17957
|
}
|
|
@@ -17941,7 +17960,7 @@ class StoreOps {
|
|
|
17941
17960
|
}
|
|
17942
17961
|
else {
|
|
17943
17962
|
this.instructionResult.status = result_Result.FAULT;
|
|
17944
|
-
this.instructionResult.exitParam = getStartPageIndex(
|
|
17963
|
+
this.instructionResult.exitParam = getStartPageIndex(memory_index_tryAsMemoryIndex(storeResult.error.address));
|
|
17945
17964
|
}
|
|
17946
17965
|
}
|
|
17947
17966
|
}
|
|
@@ -18740,11 +18759,11 @@ class ProgramDecoder {
|
|
|
18740
18759
|
|
|
18741
18760
|
|
|
18742
18761
|
const interpreter_logger = Logger.new(import.meta.filename, "pvm");
|
|
18743
|
-
class
|
|
18762
|
+
class interpreter_Interpreter {
|
|
18744
18763
|
useSbrkGas;
|
|
18745
|
-
registers = new
|
|
18764
|
+
registers = new registers_Registers();
|
|
18746
18765
|
memory = new Memory();
|
|
18747
|
-
gas = gasCounter(
|
|
18766
|
+
gas = gasCounter(gas_tryAsGas(0));
|
|
18748
18767
|
code = new Uint8Array();
|
|
18749
18768
|
mask = Mask.empty();
|
|
18750
18769
|
pc = 0;
|
|
@@ -18878,8 +18897,8 @@ class Interpreter {
|
|
|
18878
18897
|
break;
|
|
18879
18898
|
case ArgumentType.TWO_REGISTERS:
|
|
18880
18899
|
if (this.useSbrkGas && currentInstruction === Instruction.SBRK) {
|
|
18881
|
-
const calculateSbrkCost = (length) => (alignToPageSize(length) /
|
|
18882
|
-
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))));
|
|
18883
18902
|
if (underflow) {
|
|
18884
18903
|
this.status = status_Status.OOG;
|
|
18885
18904
|
return this.status;
|
|
@@ -18974,12 +18993,88 @@ class Interpreter {
|
|
|
18974
18993
|
}
|
|
18975
18994
|
}
|
|
18976
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
|
+
|
|
18977
19071
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/index.ts
|
|
18978
19072
|
|
|
18979
19073
|
|
|
18980
19074
|
|
|
18981
19075
|
|
|
18982
19076
|
|
|
19077
|
+
|
|
18983
19078
|
;// CONCATENATED MODULE: ./node_modules/@fluffylabs/anan-as/build/debug-raw.js
|
|
18984
19079
|
async function instantiate(module, imports = {}) {
|
|
18985
19080
|
const adaptedImports = {
|
|
@@ -19433,12 +19528,12 @@ class AnanasMemory {
|
|
|
19433
19528
|
}
|
|
19434
19529
|
class AnanasGasCounter {
|
|
19435
19530
|
instance;
|
|
19436
|
-
initialGas =
|
|
19531
|
+
initialGas = gas_tryAsGas(0n);
|
|
19437
19532
|
constructor(instance) {
|
|
19438
19533
|
this.instance = instance;
|
|
19439
19534
|
}
|
|
19440
19535
|
get() {
|
|
19441
|
-
return
|
|
19536
|
+
return gas_tryAsGas(this.instance.getGasLeft());
|
|
19442
19537
|
}
|
|
19443
19538
|
set(g) {
|
|
19444
19539
|
this.instance.setGasLeft(BigInt(g));
|
|
@@ -19543,7 +19638,7 @@ class InterpreterInstanceManager {
|
|
|
19543
19638
|
const instances = [];
|
|
19544
19639
|
switch (interpreter) {
|
|
19545
19640
|
case PvmBackend.BuiltIn:
|
|
19546
|
-
instances.push(new
|
|
19641
|
+
instances.push(new interpreter_Interpreter({
|
|
19547
19642
|
useSbrkGas: false,
|
|
19548
19643
|
}));
|
|
19549
19644
|
break;
|
|
@@ -19717,10 +19812,10 @@ class Info {
|
|
|
19717
19812
|
const chunk = encodedInfo.raw.subarray(Number(offset), Number(offset + length));
|
|
19718
19813
|
const writeResult = memory.storeFrom(outputStart, chunk);
|
|
19719
19814
|
if (writeResult.isError) {
|
|
19720
|
-
logger_logger.trace `INFO(${serviceId}, off: ${offset}, len: ${length}) <- PANIC`;
|
|
19815
|
+
logger_logger.trace `[${this.currentServiceId}] INFO(${serviceId}, off: ${offset}, len: ${length}) <- PANIC`;
|
|
19721
19816
|
return PvmExecution.Panic;
|
|
19722
19817
|
}
|
|
19723
|
-
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)}`;
|
|
19724
19819
|
if (accountInfo === null) {
|
|
19725
19820
|
regs.set(IN_OUT_REG, HostCallResult.NONE);
|
|
19726
19821
|
return;
|
|
@@ -19944,7 +20039,7 @@ class AccumulateExternalities {
|
|
|
19944
20039
|
const bytes = serviceInfo.storageUtilisationBytes - length - LOOKUP_HISTORY_ENTRY_BYTES;
|
|
19945
20040
|
return this.updatedState.updateServiceStorageUtilisation(this.currentServiceId, items, bytes, serviceInfo);
|
|
19946
20041
|
};
|
|
19947
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
20042
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/380802380802?v=0.7.2
|
|
19948
20043
|
if (s.status === PreimageStatusKind.Requested) {
|
|
19949
20044
|
const res = updateStorageUtilisation();
|
|
19950
20045
|
if (res.isError) {
|
|
@@ -19957,7 +20052,7 @@ class AccumulateExternalities {
|
|
|
19957
20052
|
return Result.ok(OK);
|
|
19958
20053
|
}
|
|
19959
20054
|
const t = this.currentTimeslot;
|
|
19960
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
20055
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/380802380802?v=0.7.2
|
|
19961
20056
|
if (s.status === PreimageStatusKind.Unavailable) {
|
|
19962
20057
|
const y = s.data[1];
|
|
19963
20058
|
if (y < t - this.chainSpec.preimageExpungePeriod) {
|
|
@@ -19973,14 +20068,14 @@ class AccumulateExternalities {
|
|
|
19973
20068
|
}
|
|
19974
20069
|
return Result.error(ForgetPreimageError.NotExpired, () => `Preimage not expired: y=${y}, timeslot=${t}, period=${this.chainSpec.preimageExpungePeriod}`);
|
|
19975
20070
|
}
|
|
19976
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
20071
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/382802383302?v=0.7.2
|
|
19977
20072
|
if (s.status === PreimageStatusKind.Available) {
|
|
19978
20073
|
this.updatedState.updatePreimage(serviceId, UpdatePreimage.updateOrAdd({
|
|
19979
20074
|
lookupHistory: new LookupHistoryItem(status.hash, status.length, service_tryAsLookupHistorySlots([s.data[0], t])),
|
|
19980
20075
|
}));
|
|
19981
20076
|
return Result.ok(OK);
|
|
19982
20077
|
}
|
|
19983
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
20078
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/384002384c02?v=0.7.2
|
|
19984
20079
|
if (s.status === PreimageStatusKind.Reavailable) {
|
|
19985
20080
|
const y = s.data[1];
|
|
19986
20081
|
if (y < t - this.chainSpec.preimageExpungePeriod) {
|
|
@@ -20816,13 +20911,11 @@ class AccumulateDataItem {
|
|
|
20816
20911
|
* - gas cost and reports length for each service (statistics)
|
|
20817
20912
|
*/
|
|
20818
20913
|
class AccumulateData {
|
|
20819
|
-
autoAccumulateServicesByServiceId;
|
|
20820
20914
|
reportsDataByServiceId;
|
|
20821
20915
|
transfersByServiceId;
|
|
20822
20916
|
serviceIds;
|
|
20823
20917
|
gasLimitByServiceId;
|
|
20824
20918
|
constructor(reports, transfers, autoAccumulateServicesByServiceId) {
|
|
20825
|
-
this.autoAccumulateServicesByServiceId = autoAccumulateServicesByServiceId;
|
|
20826
20919
|
const serviceIdsFromAutoAccumulate = new Set(autoAccumulateServicesByServiceId.keys());
|
|
20827
20920
|
const { reportsDataByServiceId, serviceIds: serviceIdsFromReports, gasLimitByServiceId: reportsGasLimitByServiceId, } = this.transformReports(reports);
|
|
20828
20921
|
this.reportsDataByServiceId = reportsDataByServiceId;
|
|
@@ -21142,12 +21235,12 @@ function createMergeContext(chainSpec, state, inputState, results) {
|
|
|
21142
21235
|
}
|
|
21143
21236
|
function updatePrivilegedService(currentServiceId, serviceIdUpdatedByManager, selfUpdatedServiceId) {
|
|
21144
21237
|
if (currentServiceId === serviceIdUpdatedByManager) {
|
|
21145
|
-
return
|
|
21238
|
+
return selfUpdatedServiceId;
|
|
21146
21239
|
}
|
|
21147
|
-
return
|
|
21240
|
+
return serviceIdUpdatedByManager;
|
|
21148
21241
|
}
|
|
21149
21242
|
function mergePrivilegedServices(mergeContext, [serviceId, { stateUpdate }]) {
|
|
21150
|
-
const { outputState, currentPrivilegedServices, chainSpec } = mergeContext;
|
|
21243
|
+
const { outputState, currentPrivilegedServices, chainSpec, privilegedServicesUpdatedByManager } = mergeContext;
|
|
21151
21244
|
const currentManager = currentPrivilegedServices.manager;
|
|
21152
21245
|
const currentRegistrar = currentPrivilegedServices.registrar;
|
|
21153
21246
|
const currentDelegator = currentPrivilegedServices.delegator;
|
|
@@ -21165,28 +21258,35 @@ function mergePrivilegedServices(mergeContext, [serviceId, { stateUpdate }]) {
|
|
|
21165
21258
|
});
|
|
21166
21259
|
}
|
|
21167
21260
|
if (serviceId === currentRegistrar) {
|
|
21168
|
-
const newRegistrar = updatePrivilegedService(currentPrivilegedServices.registrar,
|
|
21261
|
+
const newRegistrar = updatePrivilegedService(currentPrivilegedServices.registrar, privilegedServicesUpdatedByManager.registrar, privilegedServices.registrar);
|
|
21169
21262
|
outputState.privilegedServices = PrivilegedServices.create({
|
|
21170
21263
|
...outputState.privilegedServices,
|
|
21171
21264
|
registrar: newRegistrar,
|
|
21172
21265
|
});
|
|
21173
21266
|
}
|
|
21174
21267
|
if (serviceId === currentDelegator) {
|
|
21175
|
-
const newDelegator = updatePrivilegedService(currentPrivilegedServices.delegator,
|
|
21268
|
+
const newDelegator = updatePrivilegedService(currentPrivilegedServices.delegator, privilegedServicesUpdatedByManager.delegator, privilegedServices.delegator);
|
|
21176
21269
|
outputState.privilegedServices = PrivilegedServices.create({
|
|
21177
21270
|
...outputState.privilegedServices,
|
|
21178
21271
|
delegator: newDelegator,
|
|
21179
21272
|
});
|
|
21180
21273
|
}
|
|
21181
|
-
|
|
21182
|
-
const newAssigners = currentAssigners.map((currentAssigner, coreIndex) =>
|
|
21183
|
-
|
|
21184
|
-
|
|
21185
|
-
|
|
21186
|
-
|
|
21187
|
-
|
|
21188
|
-
|
|
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;
|
|
21189
21282
|
});
|
|
21283
|
+
if (shouldUpdateAssigners) {
|
|
21284
|
+
const newAssignersPerCore = tryAsPerCore(newAssigners, chainSpec);
|
|
21285
|
+
outputState.privilegedServices = PrivilegedServices.create({
|
|
21286
|
+
...outputState.privilegedServices,
|
|
21287
|
+
assigners: newAssignersPerCore,
|
|
21288
|
+
});
|
|
21289
|
+
}
|
|
21190
21290
|
}
|
|
21191
21291
|
}
|
|
21192
21292
|
function mergeValidatorsData(mergeContext, [serviceId, { stateUpdate }]) {
|
|
@@ -21331,7 +21431,7 @@ class Assign {
|
|
|
21331
21431
|
const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
|
|
21332
21432
|
// error while reading the memory.
|
|
21333
21433
|
if (memoryReadResult.isError) {
|
|
21334
|
-
logger_logger.trace `ASSIGN() <- PANIC`;
|
|
21434
|
+
logger_logger.trace `[${this.currentServiceId}] ASSIGN() <- PANIC`;
|
|
21335
21435
|
return PvmExecution.Panic;
|
|
21336
21436
|
}
|
|
21337
21437
|
if (maybeCoreIndex >= this.chainSpec.coresCount) {
|
|
@@ -21346,18 +21446,18 @@ class Assign {
|
|
|
21346
21446
|
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
|
|
21347
21447
|
if (result.isOk) {
|
|
21348
21448
|
regs.set(assign_IN_OUT_REG, HostCallResult.OK);
|
|
21349
|
-
logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
|
|
21449
|
+
logger_logger.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
|
|
21350
21450
|
return;
|
|
21351
21451
|
}
|
|
21352
21452
|
const e = result.error;
|
|
21353
21453
|
if (e === UpdatePrivilegesError.UnprivilegedService) {
|
|
21354
21454
|
regs.set(assign_IN_OUT_REG, HostCallResult.HUH);
|
|
21355
|
-
logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
|
|
21455
|
+
logger_logger.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
|
|
21356
21456
|
return;
|
|
21357
21457
|
}
|
|
21358
21458
|
if (e === UpdatePrivilegesError.InvalidServiceId) {
|
|
21359
21459
|
regs.set(assign_IN_OUT_REG, HostCallResult.WHO);
|
|
21360
|
-
logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
|
|
21460
|
+
logger_logger.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
|
|
21361
21461
|
return;
|
|
21362
21462
|
}
|
|
21363
21463
|
assertNever(e);
|
|
@@ -21428,7 +21528,7 @@ class Bless {
|
|
|
21428
21528
|
decoder.resetTo(0);
|
|
21429
21529
|
const memoryReadResult = memory.loadInto(result, memIndex);
|
|
21430
21530
|
if (memoryReadResult.isError) {
|
|
21431
|
-
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`;
|
|
21432
21532
|
return PvmExecution.Panic;
|
|
21433
21533
|
}
|
|
21434
21534
|
const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
|
|
@@ -21441,26 +21541,26 @@ class Bless {
|
|
|
21441
21541
|
const authorizersDecoder = decoder_Decoder.fromBlob(res);
|
|
21442
21542
|
const memoryReadResult = memory.loadInto(res, authorization);
|
|
21443
21543
|
if (memoryReadResult.isError) {
|
|
21444
|
-
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`;
|
|
21445
21545
|
return PvmExecution.Panic;
|
|
21446
21546
|
}
|
|
21447
21547
|
// `a`
|
|
21448
21548
|
const authorizers = tryAsPerCore(authorizersDecoder.sequenceFixLen(descriptors_codec.u32.asOpaque(), this.chainSpec.coresCount), this.chainSpec);
|
|
21449
21549
|
const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate);
|
|
21450
21550
|
if (updateResult.isOk) {
|
|
21451
|
-
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`;
|
|
21452
21552
|
regs.set(bless_IN_OUT_REG, HostCallResult.OK);
|
|
21453
21553
|
return;
|
|
21454
21554
|
}
|
|
21455
21555
|
const e = updateResult.error;
|
|
21456
21556
|
// NOTE: `UpdatePrivilegesError.UnprivilegedService` won't happen in 0.7.1+
|
|
21457
21557
|
if (e === UpdatePrivilegesError.UnprivilegedService) {
|
|
21458
|
-
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`;
|
|
21459
21559
|
regs.set(bless_IN_OUT_REG, HostCallResult.HUH);
|
|
21460
21560
|
return;
|
|
21461
21561
|
}
|
|
21462
21562
|
if (e === UpdatePrivilegesError.InvalidServiceId) {
|
|
21463
|
-
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`;
|
|
21464
21564
|
regs.set(bless_IN_OUT_REG, HostCallResult.WHO);
|
|
21465
21565
|
return;
|
|
21466
21566
|
}
|
|
@@ -21490,7 +21590,7 @@ class GasHostCall {
|
|
|
21490
21590
|
}
|
|
21491
21591
|
execute(gas, regs) {
|
|
21492
21592
|
const gasValue = gas.get();
|
|
21493
|
-
logger_logger.trace `GAS <- ${gasValue}`;
|
|
21593
|
+
logger_logger.trace `[${this.currentServiceId}] GAS <- ${gasValue}`;
|
|
21494
21594
|
regs.set(7, numbers_tryAsU64(gasValue));
|
|
21495
21595
|
return Promise.resolve(undefined);
|
|
21496
21596
|
}
|
|
@@ -21522,7 +21622,7 @@ class Checkpoint {
|
|
|
21522
21622
|
async execute(gas, regs) {
|
|
21523
21623
|
await this.gasHostCall.execute(gas, regs);
|
|
21524
21624
|
this.partialState.checkpoint();
|
|
21525
|
-
logger_logger.trace `CHECKPOINT()`;
|
|
21625
|
+
logger_logger.trace `[${this.currentServiceId}] CHECKPOINT()`;
|
|
21526
21626
|
return;
|
|
21527
21627
|
}
|
|
21528
21628
|
}
|
|
@@ -21562,18 +21662,18 @@ class Designate {
|
|
|
21562
21662
|
const memoryReadResult = memory.loadInto(res, validatorsStart);
|
|
21563
21663
|
// error while reading the memory.
|
|
21564
21664
|
if (memoryReadResult.isError) {
|
|
21565
|
-
logger_logger.trace `DESIGNATE() <- PANIC`;
|
|
21665
|
+
logger_logger.trace `[${this.currentServiceId}] DESIGNATE() <- PANIC`;
|
|
21566
21666
|
return PvmExecution.Panic;
|
|
21567
21667
|
}
|
|
21568
21668
|
const decoder = decoder_Decoder.fromBlob(res);
|
|
21569
21669
|
const validatorsData = decoder.sequenceFixLen(ValidatorData.Codec, this.chainSpec.validatorsCount);
|
|
21570
21670
|
const result = this.partialState.updateValidatorsData(tryAsPerValidator(validatorsData, this.chainSpec));
|
|
21571
21671
|
if (result.isError) {
|
|
21572
|
-
logger_logger.trace `DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- HUH`;
|
|
21672
|
+
logger_logger.trace `[${this.currentServiceId}] DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- HUH`;
|
|
21573
21673
|
regs.set(designate_IN_OUT_REG, HostCallResult.HUH);
|
|
21574
21674
|
}
|
|
21575
21675
|
else {
|
|
21576
|
-
logger_logger.trace `DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- OK`;
|
|
21676
|
+
logger_logger.trace `[${this.currentServiceId}] DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- OK`;
|
|
21577
21677
|
regs.set(designate_IN_OUT_REG, HostCallResult.OK);
|
|
21578
21678
|
}
|
|
21579
21679
|
}
|
|
@@ -21614,29 +21714,29 @@ class Eject {
|
|
|
21614
21714
|
const previousCodeHash = bytes_Bytes.zero(hash_HASH_SIZE).asOpaque();
|
|
21615
21715
|
const memoryReadResult = memory.loadInto(previousCodeHash.raw, preimageHashStart);
|
|
21616
21716
|
if (memoryReadResult.isError) {
|
|
21617
|
-
logger_logger.trace `EJECT(${serviceId}) <- PANIC`;
|
|
21717
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}) <- PANIC`;
|
|
21618
21718
|
return PvmExecution.Panic;
|
|
21619
21719
|
}
|
|
21620
21720
|
// cannot eject self
|
|
21621
21721
|
if (serviceId === this.currentServiceId) {
|
|
21622
21722
|
regs.set(eject_IN_OUT_REG, HostCallResult.WHO);
|
|
21623
|
-
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- WHO`;
|
|
21723
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- WHO`;
|
|
21624
21724
|
return;
|
|
21625
21725
|
}
|
|
21626
21726
|
const result = this.partialState.eject(serviceId, previousCodeHash);
|
|
21627
21727
|
// All good!
|
|
21628
21728
|
if (result.isOk) {
|
|
21629
|
-
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- OK`;
|
|
21729
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- OK`;
|
|
21630
21730
|
regs.set(eject_IN_OUT_REG, HostCallResult.OK);
|
|
21631
21731
|
return;
|
|
21632
21732
|
}
|
|
21633
21733
|
const e = result.error;
|
|
21634
21734
|
if (e === EjectError.InvalidService) {
|
|
21635
|
-
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- WHO ${resultToString(result)}`;
|
|
21735
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- WHO ${resultToString(result)}`;
|
|
21636
21736
|
regs.set(eject_IN_OUT_REG, HostCallResult.WHO);
|
|
21637
21737
|
}
|
|
21638
21738
|
else if (e === EjectError.InvalidPreimage) {
|
|
21639
|
-
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- HUH ${resultToString(result)}`;
|
|
21739
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- HUH ${resultToString(result)}`;
|
|
21640
21740
|
regs.set(eject_IN_OUT_REG, HostCallResult.HUH);
|
|
21641
21741
|
}
|
|
21642
21742
|
else {
|
|
@@ -21655,9 +21755,9 @@ class Eject {
|
|
|
21655
21755
|
|
|
21656
21756
|
const forget_IN_OUT_REG = 7;
|
|
21657
21757
|
/**
|
|
21658
|
-
*
|
|
21758
|
+
* Delete preimage hash or mark as unavailable if it was available.
|
|
21659
21759
|
*
|
|
21660
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
21760
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/385d01385d01?v=0.7.2
|
|
21661
21761
|
*/
|
|
21662
21762
|
class Forget {
|
|
21663
21763
|
currentServiceId;
|
|
@@ -21678,11 +21778,11 @@ class Forget {
|
|
|
21678
21778
|
const memoryReadResult = memory.loadInto(hash.raw, hashStart);
|
|
21679
21779
|
// error while reading the memory.
|
|
21680
21780
|
if (memoryReadResult.isError) {
|
|
21681
|
-
logger_logger.trace `FORGET(${hash}, ${length}) <- PANIC`;
|
|
21781
|
+
logger_logger.trace `[${this.currentServiceId}] FORGET(${hash}, ${length}) <- PANIC`;
|
|
21682
21782
|
return PvmExecution.Panic;
|
|
21683
21783
|
}
|
|
21684
21784
|
const result = this.partialState.forgetPreimage(hash.asOpaque(), length);
|
|
21685
|
-
logger_logger.trace `FORGET(${hash}, ${length}) <- ${resultToString(result)}`;
|
|
21785
|
+
logger_logger.trace `[${this.currentServiceId}] FORGET(${hash}, ${length}) <- ${resultToString(result)}`;
|
|
21686
21786
|
if (result.isOk) {
|
|
21687
21787
|
regs.set(forget_IN_OUT_REG, HostCallResult.OK);
|
|
21688
21788
|
}
|
|
@@ -21739,11 +21839,11 @@ class New {
|
|
|
21739
21839
|
const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
|
|
21740
21840
|
// error while reading the memory.
|
|
21741
21841
|
if (memoryReadResult.isError) {
|
|
21742
|
-
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`;
|
|
21743
21843
|
return PvmExecution.Panic;
|
|
21744
21844
|
}
|
|
21745
21845
|
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)}`;
|
|
21846
|
+
logger_logger.trace `[${this.currentServiceId}] NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${resultToString(assignedId)}`;
|
|
21747
21847
|
if (assignedId.isOk) {
|
|
21748
21848
|
regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
|
|
21749
21849
|
return;
|
|
@@ -21803,11 +21903,11 @@ class Provide {
|
|
|
21803
21903
|
const preimage = bytes_BytesBlob.blobFrom(safe_alloc_uint8array_safeAllocUint8Array(length));
|
|
21804
21904
|
const memoryReadResult = memory.loadInto(preimage.raw, preimageStart);
|
|
21805
21905
|
if (memoryReadResult.isError) {
|
|
21806
|
-
logger_logger.trace `PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- PANIC`;
|
|
21906
|
+
logger_logger.trace `[${this.currentServiceId}] PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- PANIC`;
|
|
21807
21907
|
return PvmExecution.Panic;
|
|
21808
21908
|
}
|
|
21809
21909
|
const result = this.partialState.providePreimage(serviceId, preimage);
|
|
21810
|
-
logger_logger.trace `PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- ${resultToString(result)}`;
|
|
21910
|
+
logger_logger.trace `[${this.currentServiceId}] PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- ${resultToString(result)}`;
|
|
21811
21911
|
if (result.isOk) {
|
|
21812
21912
|
regs.set(provide_IN_OUT_REG, HostCallResult.OK);
|
|
21813
21913
|
return;
|
|
@@ -21863,35 +21963,35 @@ class Query {
|
|
|
21863
21963
|
const memoryReadResult = memory.loadInto(hash.raw, hashStart);
|
|
21864
21964
|
// error while reading the memory.
|
|
21865
21965
|
if (memoryReadResult.isError) {
|
|
21866
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- PANIC`;
|
|
21966
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- PANIC`;
|
|
21867
21967
|
return PvmExecution.Panic;
|
|
21868
21968
|
}
|
|
21869
21969
|
const result = this.partialState.checkPreimageStatus(hash.asOpaque(), length);
|
|
21870
21970
|
const zero = numbers_tryAsU64(0n);
|
|
21871
21971
|
if (result === null) {
|
|
21872
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- NONE`;
|
|
21972
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- NONE`;
|
|
21873
21973
|
regs.set(IN_OUT_REG_1, HostCallResult.NONE);
|
|
21874
21974
|
regs.set(IN_OUT_REG_2, zero);
|
|
21875
21975
|
return;
|
|
21876
21976
|
}
|
|
21877
21977
|
switch (result.status) {
|
|
21878
21978
|
case PreimageStatusKind.Requested:
|
|
21879
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- REQUESTED`;
|
|
21979
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- REQUESTED`;
|
|
21880
21980
|
regs.set(IN_OUT_REG_1, zero);
|
|
21881
21981
|
regs.set(IN_OUT_REG_2, zero);
|
|
21882
21982
|
return;
|
|
21883
21983
|
case PreimageStatusKind.Available:
|
|
21884
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- AVAILABLE [${result.data}]`;
|
|
21984
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- AVAILABLE [${result.data}]`;
|
|
21885
21985
|
regs.set(IN_OUT_REG_1, numbers_tryAsU64((BigInt(result.data[0]) << UPPER_BITS_SHIFT) + 1n));
|
|
21886
21986
|
regs.set(IN_OUT_REG_2, zero);
|
|
21887
21987
|
return;
|
|
21888
21988
|
case PreimageStatusKind.Unavailable:
|
|
21889
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- UNAVAILABLE [${result.data.join(", ")}]`;
|
|
21989
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- UNAVAILABLE [${result.data.join(", ")}]`;
|
|
21890
21990
|
regs.set(IN_OUT_REG_1, numbers_tryAsU64((BigInt(result.data[0]) << UPPER_BITS_SHIFT) + 2n));
|
|
21891
21991
|
regs.set(IN_OUT_REG_2, numbers_tryAsU64(result.data[1]));
|
|
21892
21992
|
return;
|
|
21893
21993
|
case PreimageStatusKind.Reavailable:
|
|
21894
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- REAVAILABLE [${result.data.join(", ")}]`;
|
|
21994
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- REAVAILABLE [${result.data.join(", ")}]`;
|
|
21895
21995
|
regs.set(IN_OUT_REG_1, numbers_tryAsU64((BigInt(result.data[0]) << UPPER_BITS_SHIFT) + 3n));
|
|
21896
21996
|
regs.set(IN_OUT_REG_2, numbers_tryAsU64((BigInt(result.data[2]) << UPPER_BITS_SHIFT) + BigInt(result.data[1])));
|
|
21897
21997
|
return;
|
|
@@ -21932,11 +22032,11 @@ class Solicit {
|
|
|
21932
22032
|
const hash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
21933
22033
|
const memoryReadResult = memory.loadInto(hash.raw, hashStart);
|
|
21934
22034
|
if (memoryReadResult.isError) {
|
|
21935
|
-
logger_logger.trace `SOLICIT(${hash}, ${length}) <- PANIC`;
|
|
22035
|
+
logger_logger.trace `[${this.currentServiceId}] SOLICIT(${hash}, ${length}) <- PANIC`;
|
|
21936
22036
|
return PvmExecution.Panic;
|
|
21937
22037
|
}
|
|
21938
22038
|
const result = this.partialState.requestPreimage(hash.asOpaque(), length);
|
|
21939
|
-
logger_logger.trace `SOLICIT(${hash}, ${length}) <- ${resultToString(result)}`;
|
|
22039
|
+
logger_logger.trace `[${this.currentServiceId}] SOLICIT(${hash}, ${length}) <- ${resultToString(result)}`;
|
|
21940
22040
|
if (result.isOk) {
|
|
21941
22041
|
regs.set(solicit_IN_OUT_REG, HostCallResult.OK);
|
|
21942
22042
|
return;
|
|
@@ -21994,7 +22094,7 @@ class Transfer {
|
|
|
21994
22094
|
*/
|
|
21995
22095
|
basicGasCost = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_2)
|
|
21996
22096
|
? gas_tryAsSmallGas(10)
|
|
21997
|
-
: (regs) =>
|
|
22097
|
+
: (regs) => gas_tryAsGas(10n + regs.get(TRANSFER_GAS_FEE_REG));
|
|
21998
22098
|
tracedRegisters = traceRegisters(transfer_IN_OUT_REG, AMOUNT_REG, TRANSFER_GAS_FEE_REG, MEMO_START_REG);
|
|
21999
22099
|
constructor(currentServiceId, partialState) {
|
|
22000
22100
|
this.currentServiceId = currentServiceId;
|
|
@@ -22013,16 +22113,16 @@ class Transfer {
|
|
|
22013
22113
|
const memoryReadResult = memory.loadInto(memo.raw, memoStart);
|
|
22014
22114
|
// page fault while reading the memory.
|
|
22015
22115
|
if (memoryReadResult.isError) {
|
|
22016
|
-
logger_logger.trace `TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- PANIC`;
|
|
22116
|
+
logger_logger.trace `[${this.currentServiceId}] TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- PANIC`;
|
|
22017
22117
|
return PvmExecution.Panic;
|
|
22018
22118
|
}
|
|
22019
22119
|
const transferResult = this.partialState.transfer(destination, amount, transferGasFee, memo);
|
|
22020
|
-
logger_logger.trace `TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- ${resultToString(transferResult)}`;
|
|
22120
|
+
logger_logger.trace `[${this.currentServiceId}] TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- ${resultToString(transferResult)}`;
|
|
22021
22121
|
// All good!
|
|
22022
22122
|
if (transferResult.isOk) {
|
|
22023
22123
|
if (compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_2)) {
|
|
22024
22124
|
// substracting value `t`
|
|
22025
|
-
const underflow = gas.sub(
|
|
22125
|
+
const underflow = gas.sub(gas_tryAsGas(transferGasFee));
|
|
22026
22126
|
if (underflow) {
|
|
22027
22127
|
return PvmExecution.OOG;
|
|
22028
22128
|
}
|
|
@@ -22083,11 +22183,11 @@ class Upgrade {
|
|
|
22083
22183
|
const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
22084
22184
|
const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
|
|
22085
22185
|
if (memoryReadResult.isError) {
|
|
22086
|
-
logger_logger.trace `UPGRADE(${codeHash}, ${gas}, ${allowance}) <- PANIC`;
|
|
22186
|
+
logger_logger.trace `[${this.currentServiceId}] UPGRADE(${codeHash}, ${gas}, ${allowance}) <- PANIC`;
|
|
22087
22187
|
return PvmExecution.Panic;
|
|
22088
22188
|
}
|
|
22089
22189
|
this.partialState.upgradeService(codeHash.asOpaque(), gas, allowance);
|
|
22090
|
-
logger_logger.trace `UPGRADE(${codeHash}, ${gas}, ${allowance})`;
|
|
22190
|
+
logger_logger.trace `[${this.currentServiceId}] UPGRADE(${codeHash}, ${gas}, ${allowance})`;
|
|
22091
22191
|
regs.set(upgrade_IN_OUT_REG, HostCallResult.OK);
|
|
22092
22192
|
}
|
|
22093
22193
|
}
|
|
@@ -22121,11 +22221,11 @@ class Yield {
|
|
|
22121
22221
|
const hash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
22122
22222
|
const memoryReadResult = memory.loadInto(hash.raw, hashStart);
|
|
22123
22223
|
if (memoryReadResult.isError) {
|
|
22124
|
-
logger_logger.trace `YIELD() <- PANIC`;
|
|
22224
|
+
logger_logger.trace `[${this.currentServiceId}] YIELD() <- PANIC`;
|
|
22125
22225
|
return PvmExecution.Panic;
|
|
22126
22226
|
}
|
|
22127
22227
|
this.partialState.yield(hash);
|
|
22128
|
-
logger_logger.trace `YIELD(${hash})`;
|
|
22228
|
+
logger_logger.trace `[${this.currentServiceId}] YIELD(${hash})`;
|
|
22129
22229
|
regs.set(yield_IN_OUT_REG, HostCallResult.OK);
|
|
22130
22230
|
}
|
|
22131
22231
|
}
|
|
@@ -22168,10 +22268,10 @@ class Fetch {
|
|
|
22168
22268
|
const chunk = value === null ? new Uint8Array() : value.raw.subarray(Number(offset), Number(offset + length));
|
|
22169
22269
|
const storeResult = memory.storeFrom(output, chunk);
|
|
22170
22270
|
if (storeResult.isError) {
|
|
22171
|
-
logger_logger.trace `FETCH(${kind}) <- PANIC`;
|
|
22271
|
+
logger_logger.trace `[${this.currentServiceId}] FETCH(${kind}) <- PANIC`;
|
|
22172
22272
|
return PvmExecution.Panic;
|
|
22173
22273
|
}
|
|
22174
|
-
logger_logger.trace `FETCH(${kind}) <- ${value?.toStringTruncated()}`;
|
|
22274
|
+
logger_logger.trace `[${this.currentServiceId}] FETCH(${kind}) <- ${value?.toStringTruncated()}`;
|
|
22175
22275
|
// write result
|
|
22176
22276
|
regs.set(fetch_IN_OUT_REG, value === null ? HostCallResult.NONE : valueLength);
|
|
22177
22277
|
}
|
|
@@ -22321,7 +22421,7 @@ class LogHostCall {
|
|
|
22321
22421
|
}
|
|
22322
22422
|
memory.loadInto(message, msgStart);
|
|
22323
22423
|
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)})`;
|
|
22424
|
+
logger_logger.trace `[${this.currentServiceId}] LOG(${this.currentServiceId}, ${level < Levels.UNKNOWN ? Levels[level] : Levels[Levels.UNKNOWN]}(${lvl}), ${decoder.decode(target)}, ${decoder.decode(message)})`;
|
|
22325
22425
|
return Promise.resolve(undefined);
|
|
22326
22426
|
}
|
|
22327
22427
|
}
|
|
@@ -22362,12 +22462,12 @@ class Lookup {
|
|
|
22362
22462
|
const preImageHash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
22363
22463
|
const memoryReadResult = memory.loadInto(preImageHash.raw, hashAddress);
|
|
22364
22464
|
if (memoryReadResult.isError) {
|
|
22365
|
-
logger_logger.trace `LOOKUP(${serviceId}, ${preImageHash}) <- PANIC`;
|
|
22465
|
+
logger_logger.trace `[${this.currentServiceId}] LOOKUP(${serviceId}, ${preImageHash}) <- PANIC`;
|
|
22366
22466
|
return PvmExecution.Panic;
|
|
22367
22467
|
}
|
|
22368
22468
|
// v
|
|
22369
22469
|
const preImage = this.account.lookup(serviceId, preImageHash);
|
|
22370
|
-
logger_logger.trace `LOOKUP(${serviceId}, ${preImageHash}) <- ${preImage?.toStringTruncated() ?? "<missing>"}...`;
|
|
22470
|
+
logger_logger.trace `[${this.currentServiceId}] LOOKUP(${serviceId}, ${preImageHash}) <- ${preImage?.toStringTruncated() ?? "<missing>"}...`;
|
|
22371
22471
|
const preImageLength = preImage === null ? numbers_tryAsU64(0) : numbers_tryAsU64(preImage.raw.length);
|
|
22372
22472
|
const preimageBlobOffset = regs.get(10);
|
|
22373
22473
|
const lengthToWrite = regs.get(11);
|
|
@@ -22464,20 +22564,20 @@ class Read {
|
|
|
22464
22564
|
const chunk = value === null ? safe_alloc_uint8array_safeAllocUint8Array(0) : value.raw.subarray(Number(offset), Number(offset + blobLength));
|
|
22465
22565
|
const memoryWriteResult = memory.storeFrom(destinationAddress, chunk);
|
|
22466
22566
|
if (memoryWriteResult.isError) {
|
|
22467
|
-
logger_logger.trace `READ(${serviceId}, ${rawKey}) <- PANIC`;
|
|
22567
|
+
logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- PANIC`;
|
|
22468
22568
|
return PvmExecution.Panic;
|
|
22469
22569
|
}
|
|
22470
22570
|
if (value === null) {
|
|
22471
|
-
logger_logger.trace `READ(${serviceId}, ${rawKey}) <- NONE`;
|
|
22571
|
+
logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- NONE`;
|
|
22472
22572
|
regs.set(read_IN_OUT_REG, HostCallResult.NONE);
|
|
22473
22573
|
return;
|
|
22474
22574
|
}
|
|
22475
22575
|
if (chunk.length > 0) {
|
|
22476
|
-
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()}`;
|
|
22477
22577
|
}
|
|
22478
22578
|
else {
|
|
22479
22579
|
// just a query for length of stored data
|
|
22480
|
-
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"})`;
|
|
22481
22581
|
}
|
|
22482
22582
|
regs.set(read_IN_OUT_REG, valueLength);
|
|
22483
22583
|
}
|
|
@@ -22521,7 +22621,7 @@ class Write {
|
|
|
22521
22621
|
const rawStorageKey = safe_alloc_uint8array_safeAllocUint8Array(storageKeyLengthClamped);
|
|
22522
22622
|
const keyLoadingResult = memory.loadInto(rawStorageKey, storageKeyStartAddress);
|
|
22523
22623
|
if (keyLoadingResult.isError) {
|
|
22524
|
-
logger_logger.trace `WRITE() <- PANIC`;
|
|
22624
|
+
logger_logger.trace `[${this.currentServiceId}] WRITE() <- PANIC`;
|
|
22525
22625
|
return PvmExecution.Panic;
|
|
22526
22626
|
}
|
|
22527
22627
|
// k
|
|
@@ -22531,14 +22631,14 @@ class Write {
|
|
|
22531
22631
|
const valueLoadingResult = memory.loadInto(value, valueStart);
|
|
22532
22632
|
// Note [MaSo] this is ok to return bcs if valueLength is 0, then this panic won't happen
|
|
22533
22633
|
if (valueLoadingResult.isError) {
|
|
22534
|
-
logger_logger.trace `WRITE(${storageKey}) <- PANIC`;
|
|
22634
|
+
logger_logger.trace `[${this.currentServiceId}] WRITE(${storageKey}) <- PANIC`;
|
|
22535
22635
|
return PvmExecution.Panic;
|
|
22536
22636
|
}
|
|
22537
22637
|
/** https://graypaper.fluffylabs.dev/#/9a08063/33af0133b201?v=0.6.6 */
|
|
22538
22638
|
const maybeValue = valueLength === 0n ? null : bytes_BytesBlob.blobFrom(value);
|
|
22539
22639
|
// a
|
|
22540
22640
|
const result = this.account.write(storageKey, maybeValue);
|
|
22541
|
-
logger_logger.trace `WRITE(${storageKey}, ${maybeValue?.toStringTruncated() ?? "remove"}) <- ${resultToString(result)}`;
|
|
22641
|
+
logger_logger.trace `[${this.currentServiceId}] WRITE(${storageKey}, ${maybeValue?.toStringTruncated() ?? "remove"}) <- ${resultToString(result)}`;
|
|
22542
22642
|
if (result.isError) {
|
|
22543
22643
|
regs.set(write_IN_OUT_REG, HostCallResult.FULL);
|
|
22544
22644
|
return;
|
|
@@ -22767,7 +22867,7 @@ class Accumulate {
|
|
|
22767
22867
|
serviceId,
|
|
22768
22868
|
argsLength: numbers_tryAsU32(transfers.length + operands.length),
|
|
22769
22869
|
});
|
|
22770
|
-
const result = await executor.run(invocationArgs,
|
|
22870
|
+
const result = await executor.run(invocationArgs, gas_tryAsGas(gas));
|
|
22771
22871
|
const [newState, checkpoint] = partialState.getStateUpdates();
|
|
22772
22872
|
/**
|
|
22773
22873
|
* PVM invocation returned and error so we return the checkpoint
|
|
@@ -22968,19 +23068,19 @@ class Accumulate {
|
|
|
22968
23068
|
for (let serviceIndex = 0; serviceIndex < serviceIdsLength; serviceIndex += 1) {
|
|
22969
23069
|
const serviceId = serviceIds[serviceIndex];
|
|
22970
23070
|
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
|
-
|
|
22973
|
-
|
|
22974
|
-
|
|
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
|
+
});
|
|
22975
23081
|
resultPromises[serviceIndex] = promise;
|
|
22976
23082
|
}
|
|
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
|
-
});
|
|
23083
|
+
return Promise.all(resultPromises).then((results) => new Map(results));
|
|
22984
23084
|
}
|
|
22985
23085
|
/**
|
|
22986
23086
|
* A method that updates `recentlyAccumulated`, `accumulationQueue` and `timeslot` in state
|
|
@@ -23069,9 +23169,10 @@ class Accumulate {
|
|
|
23069
23169
|
const _gasCost = gasCost;
|
|
23070
23170
|
assertEmpty(rest);
|
|
23071
23171
|
const accumulated = accumulatableReports.subview(0, accumulatedReports);
|
|
23072
|
-
const { yieldedRoot, services, transfers
|
|
23172
|
+
const { yieldedRoot, services, transfers, validatorsData, privilegedServices, authorizationQueues, ...stateUpdateRest } = state;
|
|
23073
23173
|
assertEmpty(stateUpdateRest);
|
|
23074
|
-
// yielded root
|
|
23174
|
+
// transfers and yielded root are retrieved after each pvm invocation so we can ignore it here
|
|
23175
|
+
const _transfers = transfers;
|
|
23075
23176
|
const _yieldedRoot = yieldedRoot;
|
|
23076
23177
|
if (this.hasDuplicatedServiceIdCreated(services.created)) {
|
|
23077
23178
|
accumulate_logger.trace `Duplicated Service creation detected. Block is invalid.`;
|
|
@@ -23170,7 +23271,7 @@ class DeferredTransfers {
|
|
|
23170
23271
|
partiallyUpdatedState.updateServiceInfo(serviceId, newInfo);
|
|
23171
23272
|
const partialState = new AccumulateExternalities(this.chainSpec, this.blake2b, partiallyUpdatedState, serviceId, serviceId, timeslot);
|
|
23172
23273
|
const fetchExternalities = FetchExternalities.createForOnTransfer({ entropy, transfers }, this.chainSpec);
|
|
23173
|
-
let consumedGas =
|
|
23274
|
+
let consumedGas = gas_tryAsGas(0);
|
|
23174
23275
|
const hasTransfers = transfers.length > 0;
|
|
23175
23276
|
const isCodeCorrect = code !== null && code.length <= W_C;
|
|
23176
23277
|
if (!hasTransfers || !isCodeCorrect) {
|
|
@@ -23188,7 +23289,7 @@ class DeferredTransfers {
|
|
|
23188
23289
|
const executor = await PvmExecutor.createOnTransferExecutor(serviceId, code, { partialState, fetchExternalities }, this.pvm);
|
|
23189
23290
|
const args = encoder_Encoder.encodeObject(deferred_transfers_ARGS_CODEC, { timeslot, serviceId, transfersLength: numbers_tryAsU32(transfers.length) }, this.chainSpec);
|
|
23190
23291
|
const gas = transfers.reduce((acc, item) => acc + item.gas, 0n);
|
|
23191
|
-
consumedGas = (await executor.run(args,
|
|
23292
|
+
consumedGas = (await executor.run(args, gas_tryAsGas(gas))).consumedGas;
|
|
23192
23293
|
}
|
|
23193
23294
|
transferStatistics.set(serviceId, { count: numbers_tryAsU32(transfers.length), gasUsed: tryAsServiceGas(consumedGas) });
|
|
23194
23295
|
const [updatedState] = partialState.getStateUpdates();
|
|
@@ -25002,7 +25103,7 @@ async function createImporter(config) {
|
|
|
25002
25103
|
const interpreter = config.workerParams.pvm;
|
|
25003
25104
|
const blocks = db.getBlocksDb();
|
|
25004
25105
|
const states = db.getStatesDb();
|
|
25005
|
-
const hasher = new TransitionHasher(
|
|
25106
|
+
const hasher = new TransitionHasher(await keccakHasher, await blake2b);
|
|
25006
25107
|
const importer = new Importer(chainSpec, interpreter, hasher, main_logger, blocks, states);
|
|
25007
25108
|
return {
|
|
25008
25109
|
importer,
|