@typeberry/jam 0.4.0 → 0.4.1-dae2283
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/index.js
CHANGED
|
@@ -24314,7 +24314,11 @@ var TestSuite;
|
|
|
24314
24314
|
})(TestSuite || (TestSuite = {}));
|
|
24315
24315
|
const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1, GpVersion.V0_7_2];
|
|
24316
24316
|
const DEFAULT_SUITE = TestSuite.W3F_DAVXY;
|
|
24317
|
-
|
|
24317
|
+
/**
|
|
24318
|
+
* Current version is set to track the jam-conformance testing.
|
|
24319
|
+
* Since we are currently at 0.7.1 not 0.7.2, we set our default version accordingly.
|
|
24320
|
+
*/
|
|
24321
|
+
const DEFAULT_VERSION = GpVersion.V0_7_1;
|
|
24318
24322
|
const env = typeof process === "undefined" ? {} : process.env;
|
|
24319
24323
|
let CURRENT_VERSION = parseCurrentVersion(env.GP_VERSION) ?? DEFAULT_VERSION;
|
|
24320
24324
|
let CURRENT_SUITE = parseCurrentSuite(env.TEST_SUITE) ?? DEFAULT_SUITE;
|
|
@@ -24373,8 +24377,8 @@ class Compatibility {
|
|
|
24373
24377
|
/**
|
|
24374
24378
|
* Allows selecting different values for different Gray Paper versions from one record.
|
|
24375
24379
|
*
|
|
24376
|
-
*
|
|
24377
|
-
*
|
|
24380
|
+
* fallback The default value to return if no value is found for the current.
|
|
24381
|
+
* versions A record mapping versions to values, checking if the version is greater or equal to the current version.
|
|
24378
24382
|
* @returns The value for the current version, or the default value.
|
|
24379
24383
|
*/
|
|
24380
24384
|
static selectIfGreaterOrEqual({ fallback, versions, }) {
|
|
@@ -24537,7 +24541,7 @@ const workspacePathFix = dev_env.NODE_ENV === "development"
|
|
|
24537
24541
|
|
|
24538
24542
|
;// CONCATENATED MODULE: ./packages/core/utils/opaque.ts
|
|
24539
24543
|
/**
|
|
24540
|
-
*
|
|
24544
|
+
* `Opaque<Type, Token>` constructs a unique type which is a subset of Type with a
|
|
24541
24545
|
* specified unique token Token. It means that base type cannot be assigned to unique type by accident.
|
|
24542
24546
|
* Good examples of opaque types include:
|
|
24543
24547
|
* - JWTs or other tokens - these are special kinds of string used for authorization purposes.
|
|
@@ -31185,7 +31189,7 @@ function jip_chain_spec_parseBootnode(v) {
|
|
|
31185
31189
|
if (name === "" || ip === "" || port === "") {
|
|
31186
31190
|
throw new Error(`Invalid bootnode format, expected: <name>@<ip>:<port>, got: "${v}"`);
|
|
31187
31191
|
}
|
|
31188
|
-
const portNumber = Number.parseInt(port);
|
|
31192
|
+
const portNumber = Number.parseInt(port, 10);
|
|
31189
31193
|
if (!isU16(portNumber)) {
|
|
31190
31194
|
throw new Error(`Invalid port number: "${port}"`);
|
|
31191
31195
|
}
|
|
@@ -34210,11 +34214,32 @@ const ENTROPY_ENTRIES = 4;
|
|
|
34210
34214
|
|
|
34211
34215
|
var UpdatePreimageKind;
|
|
34212
34216
|
(function (UpdatePreimageKind) {
|
|
34213
|
-
/**
|
|
34217
|
+
/**
|
|
34218
|
+
* Insert new preimage and optionally update it's lookup history.
|
|
34219
|
+
*
|
|
34220
|
+
* Used in: `provide`
|
|
34221
|
+
*
|
|
34222
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/383904383904?v=0.7.2
|
|
34223
|
+
*/
|
|
34214
34224
|
UpdatePreimageKind[UpdatePreimageKind["Provide"] = 0] = "Provide";
|
|
34215
|
-
/**
|
|
34225
|
+
/**
|
|
34226
|
+
* Remove a preimage and it's lookup history.
|
|
34227
|
+
*
|
|
34228
|
+
* Used in: `forget` and `eject`
|
|
34229
|
+
*
|
|
34230
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/38c701380202?v=0.7.2
|
|
34231
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/379102379302?v=0.7.2
|
|
34232
|
+
*/
|
|
34216
34233
|
UpdatePreimageKind[UpdatePreimageKind["Remove"] = 1] = "Remove";
|
|
34217
|
-
/**
|
|
34234
|
+
/**
|
|
34235
|
+
* Update or add lookup history for preimage hash/len to given value.
|
|
34236
|
+
*
|
|
34237
|
+
* Used in: `solicit` and `forget`
|
|
34238
|
+
*
|
|
34239
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/382802382802?v=0.7.2
|
|
34240
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/384002384b02?v=0.7.2
|
|
34241
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/38c60038ea00?v=0.7.2
|
|
34242
|
+
*/
|
|
34218
34243
|
UpdatePreimageKind[UpdatePreimageKind["UpdateOrAdd"] = 2] = "UpdateOrAdd";
|
|
34219
34244
|
})(UpdatePreimageKind || (UpdatePreimageKind = {}));
|
|
34220
34245
|
/**
|
|
@@ -34222,7 +34247,7 @@ var UpdatePreimageKind;
|
|
|
34222
34247
|
*
|
|
34223
34248
|
* Can be one of the following cases:
|
|
34224
34249
|
* 1. Provide a new preimage blob and set the lookup history to available at `slot`.
|
|
34225
|
-
* 2. Remove (
|
|
34250
|
+
* 2. Remove (forget) a preimage and it's lookup history.
|
|
34226
34251
|
* 3. Update `LookupHistory` with given value.
|
|
34227
34252
|
*/
|
|
34228
34253
|
class UpdatePreimage {
|
|
@@ -35445,7 +35470,6 @@ class LeafNode {
|
|
|
35445
35470
|
/**
|
|
35446
35471
|
* Get the byte length of embedded value.
|
|
35447
35472
|
*
|
|
35448
|
-
* @remark
|
|
35449
35473
|
* Note in case this node only contains hash this is going to be 0.
|
|
35450
35474
|
*/
|
|
35451
35475
|
getValueLength() {
|
|
@@ -35456,7 +35480,6 @@ class LeafNode {
|
|
|
35456
35480
|
/**
|
|
35457
35481
|
* Returns the embedded value.
|
|
35458
35482
|
*
|
|
35459
|
-
* @remark
|
|
35460
35483
|
* Note that this is going to be empty for a regular leaf node (i.e. containing a hash).
|
|
35461
35484
|
*/
|
|
35462
35485
|
getValue() {
|
|
@@ -35466,7 +35489,6 @@ class LeafNode {
|
|
|
35466
35489
|
/**
|
|
35467
35490
|
* Returns contained value hash.
|
|
35468
35491
|
*
|
|
35469
|
-
* @remark
|
|
35470
35492
|
* Note that for embedded value this is going to be full 0-padded 32 bytes.
|
|
35471
35493
|
*/
|
|
35472
35494
|
getValueHash() {
|
|
@@ -37588,11 +37610,9 @@ class JamConfig {
|
|
|
37588
37610
|
|
|
37589
37611
|
/** Helper function to create most used hashes in the block */
|
|
37590
37612
|
class hasher_TransitionHasher {
|
|
37591
|
-
context;
|
|
37592
37613
|
keccakHasher;
|
|
37593
37614
|
blake2b;
|
|
37594
|
-
constructor(
|
|
37595
|
-
this.context = context;
|
|
37615
|
+
constructor(keccakHasher, blake2b) {
|
|
37596
37616
|
this.keccakHasher = keccakHasher;
|
|
37597
37617
|
this.blake2b = blake2b;
|
|
37598
37618
|
}
|
|
@@ -39016,7 +39036,11 @@ class PartiallyUpdatedState {
|
|
|
39016
39036
|
const service = this.state.getService(serviceId);
|
|
39017
39037
|
return service?.getPreimage(hash) ?? null;
|
|
39018
39038
|
}
|
|
39019
|
-
/**
|
|
39039
|
+
/**
|
|
39040
|
+
* Get status of a preimage of current service taking into account any updates.
|
|
39041
|
+
*
|
|
39042
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/110201110201?v=0.7.2
|
|
39043
|
+
*/
|
|
39020
39044
|
getLookupHistory(currentTimeslot, serviceId, hash, length) {
|
|
39021
39045
|
const updatedService = this.stateUpdate.services.updated.get(serviceId);
|
|
39022
39046
|
/** Return lookup history item for newly created service */
|
|
@@ -39053,12 +39077,7 @@ class PartiallyUpdatedState {
|
|
|
39053
39077
|
return new LookupHistoryItem(hash, updatedPreimage.length, tryAsLookupHistorySlots([currentTimeslot]));
|
|
39054
39078
|
}
|
|
39055
39079
|
case UpdatePreimageKind.Remove: {
|
|
39056
|
-
|
|
39057
|
-
// kinda impossible, since we know it's there because it's removed.
|
|
39058
|
-
if (state === null) {
|
|
39059
|
-
return null;
|
|
39060
|
-
}
|
|
39061
|
-
return new LookupHistoryItem(hash, state.length, tryAsLookupHistorySlots([...state.slots, currentTimeslot]));
|
|
39080
|
+
return null;
|
|
39062
39081
|
}
|
|
39063
39082
|
case UpdatePreimageKind.UpdateOrAdd: {
|
|
39064
39083
|
return action.item;
|
|
@@ -39151,7 +39170,7 @@ const gas_tryAsSmallGas = (v) => opaque_asOpaqueType(numbers_tryAsU32(v));
|
|
|
39151
39170
|
/** Attempt to convert given number into U64 gas representation. */
|
|
39152
39171
|
const tryAsBigGas = (v) => opaque_asOpaqueType(numbers_tryAsU64(v));
|
|
39153
39172
|
/** Attempt to convert given number into gas. */
|
|
39154
|
-
const
|
|
39173
|
+
const gas_tryAsGas = (v) => typeof v === "number" && v < 2 ** 32 ? gas_tryAsSmallGas(v) : tryAsBigGas(v);
|
|
39155
39174
|
|
|
39156
39175
|
;// CONCATENATED MODULE: ./packages/core/pvm-interface/memory.ts
|
|
39157
39176
|
|
|
@@ -39434,7 +39453,7 @@ const tryAsRegisterIndex = (index) => {
|
|
|
39434
39453
|
debug_check `${index >= 0 && index < registers_NO_OF_REGISTERS} Incorrect register index: ${index}!`;
|
|
39435
39454
|
return opaque_asOpaqueType(index);
|
|
39436
39455
|
};
|
|
39437
|
-
class
|
|
39456
|
+
class registers_Registers {
|
|
39438
39457
|
bytes;
|
|
39439
39458
|
asSigned;
|
|
39440
39459
|
asUnsigned;
|
|
@@ -39453,7 +39472,7 @@ class Registers {
|
|
|
39453
39472
|
}
|
|
39454
39473
|
static fromBytes(bytes) {
|
|
39455
39474
|
debug_check `${bytes.length === registers_NO_OF_REGISTERS << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
|
|
39456
|
-
return new
|
|
39475
|
+
return new registers_Registers(bytes);
|
|
39457
39476
|
}
|
|
39458
39477
|
getBytesAsLittleEndian(index, len) {
|
|
39459
39478
|
const offset = index << REGISTER_SIZE_SHIFT;
|
|
@@ -39767,49 +39786,10 @@ class NoopMissing {
|
|
|
39767
39786
|
}
|
|
39768
39787
|
}
|
|
39769
39788
|
|
|
39770
|
-
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/gas.ts
|
|
39771
|
-
|
|
39772
|
-
|
|
39773
|
-
/** Create a new gas counter instance depending on the gas value. */
|
|
39774
|
-
function gasCounter(gas) {
|
|
39775
|
-
return new GasCounterU64(numbers_tryAsU64(gas));
|
|
39776
|
-
}
|
|
39777
|
-
class GasCounterU64 {
|
|
39778
|
-
gas;
|
|
39779
|
-
initialGas;
|
|
39780
|
-
constructor(gas) {
|
|
39781
|
-
this.gas = gas;
|
|
39782
|
-
this.initialGas = tryAsGas(gas);
|
|
39783
|
-
}
|
|
39784
|
-
set(g) {
|
|
39785
|
-
this.gas = numbers_tryAsU64(g);
|
|
39786
|
-
}
|
|
39787
|
-
get() {
|
|
39788
|
-
return tryAsGas(this.gas);
|
|
39789
|
-
}
|
|
39790
|
-
sub(g) {
|
|
39791
|
-
const result = this.gas - numbers_tryAsU64(g);
|
|
39792
|
-
if (result >= 0n) {
|
|
39793
|
-
this.gas = numbers_tryAsU64(result);
|
|
39794
|
-
return false;
|
|
39795
|
-
}
|
|
39796
|
-
this.gas = numbers_tryAsU64(0n);
|
|
39797
|
-
return true;
|
|
39798
|
-
}
|
|
39799
|
-
used() {
|
|
39800
|
-
const gasConsumed = numbers_tryAsU64(this.initialGas) - this.gas;
|
|
39801
|
-
// In we have less than zero left we assume that all gas has been consumed.
|
|
39802
|
-
if (gasConsumed < 0) {
|
|
39803
|
-
return this.initialGas;
|
|
39804
|
-
}
|
|
39805
|
-
return tryAsGas(gasConsumed);
|
|
39806
|
-
}
|
|
39807
|
-
}
|
|
39808
|
-
|
|
39809
39789
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/memory-index.ts
|
|
39810
39790
|
|
|
39811
39791
|
|
|
39812
|
-
const
|
|
39792
|
+
const memory_index_tryAsMemoryIndex = (index) => {
|
|
39813
39793
|
debug_check `${index >= 0 && index <= MAX_MEMORY_INDEX} Incorrect memory index: ${index}!`;
|
|
39814
39794
|
return opaque_asOpaqueType(index);
|
|
39815
39795
|
};
|
|
@@ -39823,25 +39803,25 @@ const tryAsSbrkIndex = (index) => {
|
|
|
39823
39803
|
|
|
39824
39804
|
const memory_consts_PAGE_SIZE_SHIFT = 12;
|
|
39825
39805
|
// PAGE_SIZE has to be a power of 2
|
|
39826
|
-
const
|
|
39806
|
+
const memory_consts_PAGE_SIZE = 1 << memory_consts_PAGE_SIZE_SHIFT;
|
|
39827
39807
|
const MIN_ALLOCATION_SHIFT = (() => {
|
|
39828
39808
|
const MIN_ALLOCATION_SHIFT = 7;
|
|
39829
39809
|
debug_check `${MIN_ALLOCATION_SHIFT >= 0 && MIN_ALLOCATION_SHIFT < memory_consts_PAGE_SIZE_SHIFT} incorrect minimal allocation shift`;
|
|
39830
39810
|
return MIN_ALLOCATION_SHIFT;
|
|
39831
39811
|
})();
|
|
39832
|
-
const MIN_ALLOCATION_LENGTH =
|
|
39833
|
-
const LAST_PAGE_NUMBER = (MEMORY_SIZE -
|
|
39812
|
+
const MIN_ALLOCATION_LENGTH = memory_consts_PAGE_SIZE >> MIN_ALLOCATION_SHIFT;
|
|
39813
|
+
const LAST_PAGE_NUMBER = (MEMORY_SIZE - memory_consts_PAGE_SIZE) / memory_consts_PAGE_SIZE;
|
|
39834
39814
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/35a60235a602?v=0.6.4 */
|
|
39835
39815
|
const RESERVED_NUMBER_OF_PAGES = 16;
|
|
39836
39816
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/35a60235a602?v=0.6.4 */
|
|
39837
|
-
const MAX_NUMBER_OF_PAGES = MEMORY_SIZE /
|
|
39817
|
+
const MAX_NUMBER_OF_PAGES = MEMORY_SIZE / memory_consts_PAGE_SIZE;
|
|
39838
39818
|
|
|
39839
39819
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/pages/page-utils.ts
|
|
39840
39820
|
|
|
39841
39821
|
|
|
39842
39822
|
/** Ensure that given memory `index` is within `[0...PAGE_SIZE)` and can be used to index a page */
|
|
39843
39823
|
const tryAsPageIndex = (index) => {
|
|
39844
|
-
debug_check `${index >= 0 && index <
|
|
39824
|
+
debug_check `${index >= 0 && index < memory_consts_PAGE_SIZE}, Incorect page index: ${index}!`;
|
|
39845
39825
|
return opaque_asOpaqueType(index);
|
|
39846
39826
|
};
|
|
39847
39827
|
/** Ensure that given `index` represents an index of one of the pages. */
|
|
@@ -39869,17 +39849,17 @@ function getNextPageNumber(pageNumber) {
|
|
|
39869
39849
|
|
|
39870
39850
|
|
|
39871
39851
|
function alignToPageSize(length) {
|
|
39872
|
-
return
|
|
39852
|
+
return memory_consts_PAGE_SIZE * Math.ceil(length / memory_consts_PAGE_SIZE);
|
|
39873
39853
|
}
|
|
39874
39854
|
function getPageNumber(address) {
|
|
39875
39855
|
return tryAsPageNumber(address >>> memory_consts_PAGE_SIZE_SHIFT);
|
|
39876
39856
|
}
|
|
39877
39857
|
function getStartPageIndex(address) {
|
|
39878
|
-
return
|
|
39858
|
+
return memory_index_tryAsMemoryIndex((address >>> memory_consts_PAGE_SIZE_SHIFT) << memory_consts_PAGE_SIZE_SHIFT);
|
|
39879
39859
|
}
|
|
39880
39860
|
function getStartPageIndexFromPageNumber(pageNumber) {
|
|
39881
39861
|
// >>> 0 is needed to avoid changing sign of the number
|
|
39882
|
-
return
|
|
39862
|
+
return memory_index_tryAsMemoryIndex((pageNumber << memory_consts_PAGE_SIZE_SHIFT) >>> 0);
|
|
39883
39863
|
}
|
|
39884
39864
|
|
|
39885
39865
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/errors.ts
|
|
@@ -39901,7 +39881,7 @@ class PageFault {
|
|
|
39901
39881
|
return new PageFault(numbers_tryAsU32(startPageIndex), isAccessFault);
|
|
39902
39882
|
}
|
|
39903
39883
|
static fromMemoryIndex(maybeMemoryIndex, isAccessFault = false) {
|
|
39904
|
-
const memoryIndex =
|
|
39884
|
+
const memoryIndex = memory_index_tryAsMemoryIndex(maybeMemoryIndex % MEMORY_SIZE);
|
|
39905
39885
|
const startPageIndex = getStartPageIndex(memoryIndex);
|
|
39906
39886
|
return new PageFault(numbers_tryAsU32(startPageIndex), isAccessFault);
|
|
39907
39887
|
}
|
|
@@ -39980,9 +39960,9 @@ class MemoryRange {
|
|
|
39980
39960
|
constructor(start, length) {
|
|
39981
39961
|
this.start = start;
|
|
39982
39962
|
this.length = length;
|
|
39983
|
-
this.end =
|
|
39963
|
+
this.end = memory_index_tryAsMemoryIndex((this.start + this.length) % MEMORY_SIZE);
|
|
39984
39964
|
if (length > 0) {
|
|
39985
|
-
this.lastIndex =
|
|
39965
|
+
this.lastIndex = memory_index_tryAsMemoryIndex((this.end - 1 + MEMORY_SIZE) % MEMORY_SIZE);
|
|
39986
39966
|
}
|
|
39987
39967
|
}
|
|
39988
39968
|
/** Creates a memory range from given starting point and length */
|
|
@@ -40025,7 +40005,7 @@ class MemoryRange {
|
|
|
40025
40005
|
*
|
|
40026
40006
|
* it should be in `memory-consts` but it cannot be there because of circular dependency
|
|
40027
40007
|
*/
|
|
40028
|
-
const RESERVED_MEMORY_RANGE = MemoryRange.fromStartAndLength(
|
|
40008
|
+
const RESERVED_MEMORY_RANGE = MemoryRange.fromStartAndLength(memory_index_tryAsMemoryIndex(0), RESERVED_NUMBER_OF_PAGES * memory_consts_PAGE_SIZE);
|
|
40029
40009
|
|
|
40030
40010
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/page-range.ts
|
|
40031
40011
|
|
|
@@ -40063,7 +40043,7 @@ class PageRange {
|
|
|
40063
40043
|
// lastIndex is not null because we just ensured that the range is not empty
|
|
40064
40044
|
const pageWithLastIndex = getPageNumber(range.lastIndex ?? range.end);
|
|
40065
40045
|
const endPage = getNextPageNumber(pageWithLastIndex);
|
|
40066
|
-
if ((startPage === endPage || startPage === pageWithLastIndex) && range.length >
|
|
40046
|
+
if ((startPage === endPage || startPage === pageWithLastIndex) && range.length > memory_consts_PAGE_SIZE) {
|
|
40067
40047
|
// full range
|
|
40068
40048
|
return new PageRange(startPage, MAX_NUMBER_OF_PAGES);
|
|
40069
40049
|
}
|
|
@@ -40127,8 +40107,8 @@ class ReadablePage extends MemoryPage {
|
|
|
40127
40107
|
}
|
|
40128
40108
|
loadInto(result, startIndex, length) {
|
|
40129
40109
|
const endIndex = startIndex + length;
|
|
40130
|
-
if (endIndex >
|
|
40131
|
-
return result_Result.error(PageFault.fromMemoryIndex(this.start +
|
|
40110
|
+
if (endIndex > memory_consts_PAGE_SIZE) {
|
|
40111
|
+
return result_Result.error(PageFault.fromMemoryIndex(this.start + memory_consts_PAGE_SIZE), () => `Page fault: read beyond page boundary at ${this.start + memory_consts_PAGE_SIZE}`);
|
|
40132
40112
|
}
|
|
40133
40113
|
const bytes = this.data.subarray(startIndex, endIndex);
|
|
40134
40114
|
// we zero the bytes, since data might not yet be initialized at `endIndex`.
|
|
@@ -40161,8 +40141,8 @@ class WriteablePage extends MemoryPage {
|
|
|
40161
40141
|
constructor(pageNumber, initialData) {
|
|
40162
40142
|
super(pageNumber);
|
|
40163
40143
|
const dataLength = initialData?.length ?? 0;
|
|
40164
|
-
const initialPageLength = Math.min(
|
|
40165
|
-
this.buffer = new ArrayBuffer(initialPageLength, { maxByteLength:
|
|
40144
|
+
const initialPageLength = Math.min(memory_consts_PAGE_SIZE, Math.max(dataLength, MIN_ALLOCATION_LENGTH));
|
|
40145
|
+
this.buffer = new ArrayBuffer(initialPageLength, { maxByteLength: memory_consts_PAGE_SIZE });
|
|
40166
40146
|
this.view = new Uint8Array(this.buffer);
|
|
40167
40147
|
if (initialData !== undefined) {
|
|
40168
40148
|
this.view.set(initialData);
|
|
@@ -40170,8 +40150,8 @@ class WriteablePage extends MemoryPage {
|
|
|
40170
40150
|
}
|
|
40171
40151
|
loadInto(result, startIndex, length) {
|
|
40172
40152
|
const endIndex = startIndex + length;
|
|
40173
|
-
if (endIndex >
|
|
40174
|
-
return result_Result.error(PageFault.fromMemoryIndex(this.start +
|
|
40153
|
+
if (endIndex > memory_consts_PAGE_SIZE) {
|
|
40154
|
+
return result_Result.error(PageFault.fromMemoryIndex(this.start + memory_consts_PAGE_SIZE), () => `Page fault: read beyond page boundary at ${this.start + memory_consts_PAGE_SIZE}`);
|
|
40175
40155
|
}
|
|
40176
40156
|
const bytes = this.view.subarray(startIndex, endIndex);
|
|
40177
40157
|
// we zero the bytes, since the view might not yet be initialized at `endIndex`.
|
|
@@ -40180,16 +40160,16 @@ class WriteablePage extends MemoryPage {
|
|
|
40180
40160
|
return result_Result.ok(result_OK);
|
|
40181
40161
|
}
|
|
40182
40162
|
storeFrom(startIndex, bytes) {
|
|
40183
|
-
if (this.buffer.byteLength < startIndex + bytes.length && this.buffer.byteLength <
|
|
40184
|
-
const newLength = Math.min(
|
|
40163
|
+
if (this.buffer.byteLength < startIndex + bytes.length && this.buffer.byteLength < memory_consts_PAGE_SIZE) {
|
|
40164
|
+
const newLength = Math.min(memory_consts_PAGE_SIZE, Math.max(MIN_ALLOCATION_LENGTH, startIndex + bytes.length));
|
|
40185
40165
|
this.buffer.resize(newLength);
|
|
40186
40166
|
}
|
|
40187
40167
|
this.view.set(bytes, startIndex);
|
|
40188
40168
|
return result_Result.ok(result_OK);
|
|
40189
40169
|
}
|
|
40190
40170
|
setData(pageIndex, data) {
|
|
40191
|
-
if (this.buffer.byteLength < pageIndex + data.length && this.buffer.byteLength <
|
|
40192
|
-
const newLength = Math.min(
|
|
40171
|
+
if (this.buffer.byteLength < pageIndex + data.length && this.buffer.byteLength < memory_consts_PAGE_SIZE) {
|
|
40172
|
+
const newLength = Math.min(memory_consts_PAGE_SIZE, Math.max(MIN_ALLOCATION_LENGTH, pageIndex + data.length));
|
|
40193
40173
|
this.buffer.resize(newLength);
|
|
40194
40174
|
}
|
|
40195
40175
|
this.view.set(data, pageIndex);
|
|
@@ -40240,10 +40220,10 @@ class Memory {
|
|
|
40240
40220
|
this.memory = memory;
|
|
40241
40221
|
}
|
|
40242
40222
|
store(address, bytes) {
|
|
40243
|
-
return this.storeFrom(
|
|
40223
|
+
return this.storeFrom(memory_index_tryAsMemoryIndex(address), bytes);
|
|
40244
40224
|
}
|
|
40245
40225
|
read(address, output) {
|
|
40246
|
-
return this.loadInto(output,
|
|
40226
|
+
return this.loadInto(output, memory_index_tryAsMemoryIndex(address));
|
|
40247
40227
|
}
|
|
40248
40228
|
reset() {
|
|
40249
40229
|
this.sbrkIndex = tryAsSbrkIndex(RESERVED_MEMORY_RANGE.end);
|
|
@@ -40270,8 +40250,8 @@ class Memory {
|
|
|
40270
40250
|
let currentPosition = address;
|
|
40271
40251
|
let bytesLeft = bytes.length;
|
|
40272
40252
|
for (const page of pages) {
|
|
40273
|
-
const pageStartIndex = tryAsPageIndex(currentPosition %
|
|
40274
|
-
const bytesToWrite = Math.min(
|
|
40253
|
+
const pageStartIndex = tryAsPageIndex(currentPosition % memory_consts_PAGE_SIZE);
|
|
40254
|
+
const bytesToWrite = Math.min(memory_consts_PAGE_SIZE - pageStartIndex, bytesLeft);
|
|
40275
40255
|
const sourceStartIndex = currentPosition - address;
|
|
40276
40256
|
const source = bytes.subarray(sourceStartIndex, sourceStartIndex + bytesToWrite);
|
|
40277
40257
|
page.storeFrom(pageStartIndex, source);
|
|
@@ -40320,8 +40300,8 @@ class Memory {
|
|
|
40320
40300
|
let currentPosition = startAddress;
|
|
40321
40301
|
let bytesLeft = result.length;
|
|
40322
40302
|
for (const page of pages) {
|
|
40323
|
-
const pageStartIndex = tryAsPageIndex(currentPosition %
|
|
40324
|
-
const bytesToRead = Math.min(
|
|
40303
|
+
const pageStartIndex = tryAsPageIndex(currentPosition % memory_consts_PAGE_SIZE);
|
|
40304
|
+
const bytesToRead = Math.min(memory_consts_PAGE_SIZE - pageStartIndex, bytesLeft);
|
|
40325
40305
|
const destinationStartIndex = currentPosition - startAddress;
|
|
40326
40306
|
const destination = result.subarray(destinationStartIndex);
|
|
40327
40307
|
page.loadInto(destination, pageStartIndex, bytesToRead);
|
|
@@ -40348,7 +40328,7 @@ class Memory {
|
|
|
40348
40328
|
const newSbrkIndex = tryAsSbrkIndex(alignToPageSize(newVirtualSbrkIndex));
|
|
40349
40329
|
// TODO [MaSi]: `getPageNumber` works incorrectly for SbrkIndex. Sbrk index should be changed to MemoryIndex
|
|
40350
40330
|
const firstPageNumber = getPageNumber(currentSbrkIndex);
|
|
40351
|
-
const pagesToAllocate = (newSbrkIndex - currentSbrkIndex) /
|
|
40331
|
+
const pagesToAllocate = (newSbrkIndex - currentSbrkIndex) / memory_consts_PAGE_SIZE;
|
|
40352
40332
|
const rangeToAllocate = PageRange.fromStartAndLength(firstPageNumber, pagesToAllocate);
|
|
40353
40333
|
for (const pageNumber of rangeToAllocate) {
|
|
40354
40334
|
const page = new WriteablePage(pageNumber);
|
|
@@ -40403,8 +40383,8 @@ class MemoryBuilder {
|
|
|
40403
40383
|
setReadablePages(start, end, data = new Uint8Array()) {
|
|
40404
40384
|
this.ensureNotFinalized();
|
|
40405
40385
|
debug_check `${start < end} end has to be bigger than start`;
|
|
40406
|
-
debug_check `${start %
|
|
40407
|
-
debug_check `${end %
|
|
40386
|
+
debug_check `${start % memory_consts_PAGE_SIZE === 0} start needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
|
|
40387
|
+
debug_check `${end % memory_consts_PAGE_SIZE === 0} end needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
|
|
40408
40388
|
debug_check `${data.length <= end - start} the initial data is longer than address range`;
|
|
40409
40389
|
const length = end - start;
|
|
40410
40390
|
const range = MemoryRange.fromStartAndLength(start, length);
|
|
@@ -40413,7 +40393,7 @@ class MemoryBuilder {
|
|
|
40413
40393
|
const noOfPages = pages.length;
|
|
40414
40394
|
for (let i = 0; i < noOfPages; i++) {
|
|
40415
40395
|
const pageNumber = pages[i];
|
|
40416
|
-
const dataChunk = data.subarray(i *
|
|
40396
|
+
const dataChunk = data.subarray(i * memory_consts_PAGE_SIZE, (i + 1) * memory_consts_PAGE_SIZE);
|
|
40417
40397
|
const page = new ReadablePage(pageNumber, dataChunk);
|
|
40418
40398
|
this.initialMemory.set(pageNumber, page);
|
|
40419
40399
|
}
|
|
@@ -40431,8 +40411,8 @@ class MemoryBuilder {
|
|
|
40431
40411
|
setWriteablePages(start, end, data = new Uint8Array()) {
|
|
40432
40412
|
this.ensureNotFinalized();
|
|
40433
40413
|
debug_check `${start < end} end has to be bigger than start`;
|
|
40434
|
-
debug_check `${start %
|
|
40435
|
-
debug_check `${end %
|
|
40414
|
+
debug_check `${start % memory_consts_PAGE_SIZE === 0} start needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
|
|
40415
|
+
debug_check `${end % memory_consts_PAGE_SIZE === 0} end needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
|
|
40436
40416
|
debug_check `${data.length <= end - start} the initial data is longer than address range`;
|
|
40437
40417
|
const length = end - start;
|
|
40438
40418
|
const range = MemoryRange.fromStartAndLength(start, length);
|
|
@@ -40441,7 +40421,7 @@ class MemoryBuilder {
|
|
|
40441
40421
|
const noOfPages = pages.length;
|
|
40442
40422
|
for (let i = 0; i < noOfPages; i++) {
|
|
40443
40423
|
const pageNumber = pages[i];
|
|
40444
|
-
const dataChunk = data.subarray(i *
|
|
40424
|
+
const dataChunk = data.subarray(i * memory_consts_PAGE_SIZE, (i + 1) * memory_consts_PAGE_SIZE);
|
|
40445
40425
|
const page = new WriteablePage(pageNumber, dataChunk);
|
|
40446
40426
|
this.initialMemory.set(pageNumber, page);
|
|
40447
40427
|
}
|
|
@@ -40453,8 +40433,8 @@ class MemoryBuilder {
|
|
|
40453
40433
|
*/
|
|
40454
40434
|
setData(start, data) {
|
|
40455
40435
|
this.ensureNotFinalized();
|
|
40456
|
-
const pageOffset = start %
|
|
40457
|
-
const remainingSpaceOnPage =
|
|
40436
|
+
const pageOffset = start % memory_consts_PAGE_SIZE;
|
|
40437
|
+
const remainingSpaceOnPage = memory_consts_PAGE_SIZE - pageOffset;
|
|
40458
40438
|
debug_check `${data.length <= remainingSpaceOnPage} The data has to fit into a single page.`;
|
|
40459
40439
|
const length = data.length;
|
|
40460
40440
|
const range = MemoryRange.fromStartAndLength(start, length);
|
|
@@ -40645,27 +40625,27 @@ class Program {
|
|
|
40645
40625
|
static fromSpi(blob, args, hasMetadata) {
|
|
40646
40626
|
const { code: spiCode, metadata } = hasMetadata ? extractCodeAndMetadata(blob) : { code: blob };
|
|
40647
40627
|
const { code, memory: rawMemory, registers } = decodeStandardProgram(spiCode, args);
|
|
40648
|
-
const regs = new
|
|
40628
|
+
const regs = new registers_Registers();
|
|
40649
40629
|
regs.copyFrom(registers);
|
|
40650
40630
|
const memoryBuilder = new MemoryBuilder();
|
|
40651
40631
|
for (const { start, end, data } of rawMemory.readable) {
|
|
40652
|
-
const startIndex =
|
|
40653
|
-
const endIndex =
|
|
40632
|
+
const startIndex = memory_index_tryAsMemoryIndex(start);
|
|
40633
|
+
const endIndex = memory_index_tryAsMemoryIndex(end);
|
|
40654
40634
|
memoryBuilder.setReadablePages(startIndex, endIndex, data ?? new Uint8Array());
|
|
40655
40635
|
}
|
|
40656
40636
|
for (const { start, end, data } of rawMemory.writeable) {
|
|
40657
|
-
const startIndex =
|
|
40658
|
-
const endIndex =
|
|
40637
|
+
const startIndex = memory_index_tryAsMemoryIndex(start);
|
|
40638
|
+
const endIndex = memory_index_tryAsMemoryIndex(end);
|
|
40659
40639
|
memoryBuilder.setWriteablePages(startIndex, endIndex, data ?? new Uint8Array());
|
|
40660
40640
|
}
|
|
40661
|
-
const heapStart =
|
|
40641
|
+
const heapStart = memory_index_tryAsMemoryIndex(rawMemory.sbrkIndex);
|
|
40662
40642
|
const heapEnd = tryAsSbrkIndex(rawMemory.heapEnd);
|
|
40663
40643
|
const memory = memoryBuilder.finalize(heapStart, heapEnd);
|
|
40664
40644
|
return new Program(code, regs, memory, metadata);
|
|
40665
40645
|
}
|
|
40666
40646
|
static fromGeneric(blob, hasMetadata) {
|
|
40667
40647
|
const { code, metadata } = hasMetadata ? extractCodeAndMetadata(blob) : { code: blob };
|
|
40668
|
-
const regs = new
|
|
40648
|
+
const regs = new registers_Registers();
|
|
40669
40649
|
const memory = new Memory();
|
|
40670
40650
|
return new Program(code, regs, memory, metadata);
|
|
40671
40651
|
}
|
|
@@ -41680,6 +41660,45 @@ class BasicBlocks {
|
|
|
41680
41660
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/basic-blocks/index.ts
|
|
41681
41661
|
|
|
41682
41662
|
|
|
41663
|
+
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/gas.ts
|
|
41664
|
+
|
|
41665
|
+
|
|
41666
|
+
/** Create a new gas counter instance depending on the gas value. */
|
|
41667
|
+
function gasCounter(gas) {
|
|
41668
|
+
return new GasCounterU64(numbers_tryAsU64(gas));
|
|
41669
|
+
}
|
|
41670
|
+
class GasCounterU64 {
|
|
41671
|
+
gas;
|
|
41672
|
+
initialGas;
|
|
41673
|
+
constructor(gas) {
|
|
41674
|
+
this.gas = gas;
|
|
41675
|
+
this.initialGas = gas_tryAsGas(gas);
|
|
41676
|
+
}
|
|
41677
|
+
set(g) {
|
|
41678
|
+
this.gas = numbers_tryAsU64(g);
|
|
41679
|
+
}
|
|
41680
|
+
get() {
|
|
41681
|
+
return gas_tryAsGas(this.gas);
|
|
41682
|
+
}
|
|
41683
|
+
sub(g) {
|
|
41684
|
+
const result = this.gas - numbers_tryAsU64(g);
|
|
41685
|
+
if (result >= 0n) {
|
|
41686
|
+
this.gas = numbers_tryAsU64(result);
|
|
41687
|
+
return false;
|
|
41688
|
+
}
|
|
41689
|
+
this.gas = numbers_tryAsU64(0n);
|
|
41690
|
+
return true;
|
|
41691
|
+
}
|
|
41692
|
+
used() {
|
|
41693
|
+
const gasConsumed = numbers_tryAsU64(this.initialGas) - this.gas;
|
|
41694
|
+
// In we have less than zero left we assume that all gas has been consumed.
|
|
41695
|
+
if (gasConsumed < 0) {
|
|
41696
|
+
return this.initialGas;
|
|
41697
|
+
}
|
|
41698
|
+
return gas_tryAsGas(gasConsumed);
|
|
41699
|
+
}
|
|
41700
|
+
}
|
|
41701
|
+
|
|
41683
41702
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/instruction-gas-map.ts
|
|
41684
41703
|
|
|
41685
41704
|
|
|
@@ -42256,7 +42275,7 @@ class LoadOps {
|
|
|
42256
42275
|
}
|
|
42257
42276
|
loadNumber(address, registerIndex, numberLength) {
|
|
42258
42277
|
const registerBytes = this.regs.getBytesAsLittleEndian(registerIndex, REG_SIZE_BYTES);
|
|
42259
|
-
const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength),
|
|
42278
|
+
const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength), memory_index_tryAsMemoryIndex(address));
|
|
42260
42279
|
if (loadResult.isError) {
|
|
42261
42280
|
if (loadResult.error.isAccessFault) {
|
|
42262
42281
|
this.instructionResult.status = pvm_interpreter_result_Result.FAULT_ACCESS;
|
|
@@ -42272,7 +42291,7 @@ class LoadOps {
|
|
|
42272
42291
|
loadSignedNumber(address, registerIndex, numberLength) {
|
|
42273
42292
|
// load all bytes from register to correctly handle the sign.
|
|
42274
42293
|
const registerBytes = this.regs.getBytesAsLittleEndian(registerIndex, REG_SIZE_BYTES);
|
|
42275
|
-
const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength),
|
|
42294
|
+
const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength), memory_index_tryAsMemoryIndex(address));
|
|
42276
42295
|
if (loadResult.isError) {
|
|
42277
42296
|
if (loadResult.error.isAccessFault) {
|
|
42278
42297
|
this.instructionResult.status = pvm_interpreter_result_Result.FAULT_ACCESS;
|
|
@@ -42694,7 +42713,7 @@ class StoreOps {
|
|
|
42694
42713
|
this.store(address, secondImmediateDecoder.getExtendedBytesAsLittleEndian());
|
|
42695
42714
|
}
|
|
42696
42715
|
store(address, bytes) {
|
|
42697
|
-
const storeResult = this.memory.storeFrom(
|
|
42716
|
+
const storeResult = this.memory.storeFrom(memory_index_tryAsMemoryIndex(address), bytes);
|
|
42698
42717
|
if (storeResult.isOk) {
|
|
42699
42718
|
return;
|
|
42700
42719
|
}
|
|
@@ -42703,7 +42722,7 @@ class StoreOps {
|
|
|
42703
42722
|
}
|
|
42704
42723
|
else {
|
|
42705
42724
|
this.instructionResult.status = pvm_interpreter_result_Result.FAULT;
|
|
42706
|
-
this.instructionResult.exitParam = getStartPageIndex(
|
|
42725
|
+
this.instructionResult.exitParam = getStartPageIndex(memory_index_tryAsMemoryIndex(storeResult.error.address));
|
|
42707
42726
|
}
|
|
42708
42727
|
}
|
|
42709
42728
|
}
|
|
@@ -43502,11 +43521,11 @@ class ProgramDecoder {
|
|
|
43502
43521
|
|
|
43503
43522
|
|
|
43504
43523
|
const interpreter_logger = logger_Logger.new(import.meta.filename, "pvm");
|
|
43505
|
-
class
|
|
43524
|
+
class interpreter_Interpreter {
|
|
43506
43525
|
useSbrkGas;
|
|
43507
|
-
registers = new
|
|
43526
|
+
registers = new registers_Registers();
|
|
43508
43527
|
memory = new Memory();
|
|
43509
|
-
gas = gasCounter(
|
|
43528
|
+
gas = gasCounter(gas_tryAsGas(0));
|
|
43510
43529
|
code = new Uint8Array();
|
|
43511
43530
|
mask = Mask.empty();
|
|
43512
43531
|
pc = 0;
|
|
@@ -43640,8 +43659,8 @@ class Interpreter {
|
|
|
43640
43659
|
break;
|
|
43641
43660
|
case ArgumentType.TWO_REGISTERS:
|
|
43642
43661
|
if (this.useSbrkGas && currentInstruction === Instruction.SBRK) {
|
|
43643
|
-
const calculateSbrkCost = (length) => (alignToPageSize(length) /
|
|
43644
|
-
const underflow = this.gas.sub(
|
|
43662
|
+
const calculateSbrkCost = (length) => (alignToPageSize(length) / memory_consts_PAGE_SIZE) * 16;
|
|
43663
|
+
const underflow = this.gas.sub(gas_tryAsGas(calculateSbrkCost(this.registers.getLowerU32(argsResult.firstRegisterIndex))));
|
|
43645
43664
|
if (underflow) {
|
|
43646
43665
|
this.status = status_Status.OOG;
|
|
43647
43666
|
return this.status;
|
|
@@ -43736,12 +43755,88 @@ class Interpreter {
|
|
|
43736
43755
|
}
|
|
43737
43756
|
}
|
|
43738
43757
|
|
|
43758
|
+
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/debugger-adapter.ts
|
|
43759
|
+
|
|
43760
|
+
|
|
43761
|
+
|
|
43762
|
+
|
|
43763
|
+
|
|
43764
|
+
|
|
43765
|
+
class DebuggerAdapter {
|
|
43766
|
+
pvm;
|
|
43767
|
+
constructor(useSbrkGas = false) {
|
|
43768
|
+
this.pvm = new Interpreter({ useSbrkGas });
|
|
43769
|
+
}
|
|
43770
|
+
resetGeneric(rawProgram, flatRegisters, initialGas) {
|
|
43771
|
+
this.pvm.resetGeneric(rawProgram, 0, tryAsGas(initialGas), new Registers(flatRegisters));
|
|
43772
|
+
}
|
|
43773
|
+
reset(rawProgram, pc, gas, maybeRegisters, maybeMemory) {
|
|
43774
|
+
this.pvm.resetGeneric(rawProgram, pc, tryAsGas(gas), maybeRegisters, maybeMemory);
|
|
43775
|
+
}
|
|
43776
|
+
getPageDump(pageNumber) {
|
|
43777
|
+
const page = this.pvm.getMemoryPage(pageNumber);
|
|
43778
|
+
if (page === null) {
|
|
43779
|
+
// page wasn't allocated so we return an empty page
|
|
43780
|
+
return safeAllocUint8Array(PAGE_SIZE);
|
|
43781
|
+
}
|
|
43782
|
+
if (page.length === PAGE_SIZE) {
|
|
43783
|
+
// page was allocated and has a proper size so we can simply return it
|
|
43784
|
+
return page;
|
|
43785
|
+
}
|
|
43786
|
+
// page was allocated but it is shorter than PAGE_SIZE so we have to extend it
|
|
43787
|
+
const fullPage = safeAllocUint8Array(PAGE_SIZE);
|
|
43788
|
+
fullPage.set(page);
|
|
43789
|
+
return fullPage;
|
|
43790
|
+
}
|
|
43791
|
+
setMemory(address, value) {
|
|
43792
|
+
this.pvm.memory.storeFrom(tryAsMemoryIndex(address), value);
|
|
43793
|
+
}
|
|
43794
|
+
getExitArg() {
|
|
43795
|
+
return this.pvm.getExitParam() ?? 0;
|
|
43796
|
+
}
|
|
43797
|
+
getStatus() {
|
|
43798
|
+
return this.pvm.getStatus();
|
|
43799
|
+
}
|
|
43800
|
+
nextStep() {
|
|
43801
|
+
return this.pvm.nextStep() === Status.OK;
|
|
43802
|
+
}
|
|
43803
|
+
nSteps(steps) {
|
|
43804
|
+
check `${steps >>> 0 > 0} Expected a positive integer got ${steps}`;
|
|
43805
|
+
for (let i = 0; i < steps; i++) {
|
|
43806
|
+
const isOk = this.nextStep();
|
|
43807
|
+
if (!isOk) {
|
|
43808
|
+
return false;
|
|
43809
|
+
}
|
|
43810
|
+
}
|
|
43811
|
+
return true;
|
|
43812
|
+
}
|
|
43813
|
+
getRegisters() {
|
|
43814
|
+
return this.pvm.registers.getAllU64();
|
|
43815
|
+
}
|
|
43816
|
+
setRegisters(registers) {
|
|
43817
|
+
this.pvm.registers.copyFrom(new Registers(registers));
|
|
43818
|
+
}
|
|
43819
|
+
getProgramCounter() {
|
|
43820
|
+
return this.pvm.getPC();
|
|
43821
|
+
}
|
|
43822
|
+
setNextProgramCounter(nextPc) {
|
|
43823
|
+
this.pvm.setNextPC(nextPc);
|
|
43824
|
+
}
|
|
43825
|
+
getGasLeft() {
|
|
43826
|
+
return BigInt(this.pvm.gas.get());
|
|
43827
|
+
}
|
|
43828
|
+
setGasLeft(gas) {
|
|
43829
|
+
this.pvm.gas.set(tryAsGas(gas));
|
|
43830
|
+
}
|
|
43831
|
+
}
|
|
43832
|
+
|
|
43739
43833
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/index.ts
|
|
43740
43834
|
|
|
43741
43835
|
|
|
43742
43836
|
|
|
43743
43837
|
|
|
43744
43838
|
|
|
43839
|
+
|
|
43745
43840
|
;// CONCATENATED MODULE: ./node_modules/@fluffylabs/anan-as/build/debug-raw.js
|
|
43746
43841
|
async function instantiate(module, imports = {}) {
|
|
43747
43842
|
const adaptedImports = {
|
|
@@ -44195,12 +44290,12 @@ class AnanasMemory {
|
|
|
44195
44290
|
}
|
|
44196
44291
|
class AnanasGasCounter {
|
|
44197
44292
|
instance;
|
|
44198
|
-
initialGas =
|
|
44293
|
+
initialGas = gas_tryAsGas(0n);
|
|
44199
44294
|
constructor(instance) {
|
|
44200
44295
|
this.instance = instance;
|
|
44201
44296
|
}
|
|
44202
44297
|
get() {
|
|
44203
|
-
return
|
|
44298
|
+
return gas_tryAsGas(this.instance.getGasLeft());
|
|
44204
44299
|
}
|
|
44205
44300
|
set(g) {
|
|
44206
44301
|
this.instance.setGasLeft(BigInt(g));
|
|
@@ -44305,7 +44400,7 @@ class InterpreterInstanceManager {
|
|
|
44305
44400
|
const instances = [];
|
|
44306
44401
|
switch (interpreter) {
|
|
44307
44402
|
case PvmBackend.BuiltIn:
|
|
44308
|
-
instances.push(new
|
|
44403
|
+
instances.push(new interpreter_Interpreter({
|
|
44309
44404
|
useSbrkGas: false,
|
|
44310
44405
|
}));
|
|
44311
44406
|
break;
|
|
@@ -44479,10 +44574,10 @@ class Info {
|
|
|
44479
44574
|
const chunk = encodedInfo.raw.subarray(Number(offset), Number(offset + length));
|
|
44480
44575
|
const writeResult = memory.storeFrom(outputStart, chunk);
|
|
44481
44576
|
if (writeResult.isError) {
|
|
44482
|
-
logger_logger.trace `INFO(${serviceId}, off: ${offset}, len: ${length}) <- PANIC`;
|
|
44577
|
+
logger_logger.trace `[${this.currentServiceId}] INFO(${serviceId}, off: ${offset}, len: ${length}) <- PANIC`;
|
|
44483
44578
|
return PvmExecution.Panic;
|
|
44484
44579
|
}
|
|
44485
|
-
logger_logger.trace `INFO(${serviceId}, off: ${offset}, len: ${length}) <- ${bytes_BytesBlob.blobFrom(chunk)}`;
|
|
44580
|
+
logger_logger.trace `[${this.currentServiceId}] INFO(${serviceId}, off: ${offset}, len: ${length}) <- ${bytes_BytesBlob.blobFrom(chunk)}`;
|
|
44486
44581
|
if (accountInfo === null) {
|
|
44487
44582
|
regs.set(IN_OUT_REG, HostCallResult.NONE);
|
|
44488
44583
|
return;
|
|
@@ -44706,7 +44801,7 @@ class AccumulateExternalities {
|
|
|
44706
44801
|
const bytes = serviceInfo.storageUtilisationBytes - length - LOOKUP_HISTORY_ENTRY_BYTES;
|
|
44707
44802
|
return this.updatedState.updateServiceStorageUtilisation(this.currentServiceId, items, bytes, serviceInfo);
|
|
44708
44803
|
};
|
|
44709
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
44804
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/380802380802?v=0.7.2
|
|
44710
44805
|
if (s.status === PreimageStatusKind.Requested) {
|
|
44711
44806
|
const res = updateStorageUtilisation();
|
|
44712
44807
|
if (res.isError) {
|
|
@@ -44719,7 +44814,7 @@ class AccumulateExternalities {
|
|
|
44719
44814
|
return result_Result.ok(result_OK);
|
|
44720
44815
|
}
|
|
44721
44816
|
const t = this.currentTimeslot;
|
|
44722
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
44817
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/380802380802?v=0.7.2
|
|
44723
44818
|
if (s.status === PreimageStatusKind.Unavailable) {
|
|
44724
44819
|
const y = s.data[1];
|
|
44725
44820
|
if (y < t - this.chainSpec.preimageExpungePeriod) {
|
|
@@ -44735,14 +44830,14 @@ class AccumulateExternalities {
|
|
|
44735
44830
|
}
|
|
44736
44831
|
return result_Result.error(ForgetPreimageError.NotExpired, () => `Preimage not expired: y=${y}, timeslot=${t}, period=${this.chainSpec.preimageExpungePeriod}`);
|
|
44737
44832
|
}
|
|
44738
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
44833
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/382802383302?v=0.7.2
|
|
44739
44834
|
if (s.status === PreimageStatusKind.Available) {
|
|
44740
44835
|
this.updatedState.updatePreimage(serviceId, UpdatePreimage.updateOrAdd({
|
|
44741
44836
|
lookupHistory: new LookupHistoryItem(status.hash, status.length, tryAsLookupHistorySlots([s.data[0], t])),
|
|
44742
44837
|
}));
|
|
44743
44838
|
return result_Result.ok(result_OK);
|
|
44744
44839
|
}
|
|
44745
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
44840
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/384002384c02?v=0.7.2
|
|
44746
44841
|
if (s.status === PreimageStatusKind.Reavailable) {
|
|
44747
44842
|
const y = s.data[1];
|
|
44748
44843
|
if (y < t - this.chainSpec.preimageExpungePeriod) {
|
|
@@ -45578,13 +45673,11 @@ class AccumulateDataItem {
|
|
|
45578
45673
|
* - gas cost and reports length for each service (statistics)
|
|
45579
45674
|
*/
|
|
45580
45675
|
class AccumulateData {
|
|
45581
|
-
autoAccumulateServicesByServiceId;
|
|
45582
45676
|
reportsDataByServiceId;
|
|
45583
45677
|
transfersByServiceId;
|
|
45584
45678
|
serviceIds;
|
|
45585
45679
|
gasLimitByServiceId;
|
|
45586
45680
|
constructor(reports, transfers, autoAccumulateServicesByServiceId) {
|
|
45587
|
-
this.autoAccumulateServicesByServiceId = autoAccumulateServicesByServiceId;
|
|
45588
45681
|
const serviceIdsFromAutoAccumulate = new Set(autoAccumulateServicesByServiceId.keys());
|
|
45589
45682
|
const { reportsDataByServiceId, serviceIds: serviceIdsFromReports, gasLimitByServiceId: reportsGasLimitByServiceId, } = this.transformReports(reports);
|
|
45590
45683
|
this.reportsDataByServiceId = reportsDataByServiceId;
|
|
@@ -45904,12 +45997,12 @@ function createMergeContext(chainSpec, state, inputState, results) {
|
|
|
45904
45997
|
}
|
|
45905
45998
|
function updatePrivilegedService(currentServiceId, serviceIdUpdatedByManager, selfUpdatedServiceId) {
|
|
45906
45999
|
if (currentServiceId === serviceIdUpdatedByManager) {
|
|
45907
|
-
return
|
|
46000
|
+
return selfUpdatedServiceId;
|
|
45908
46001
|
}
|
|
45909
|
-
return
|
|
46002
|
+
return serviceIdUpdatedByManager;
|
|
45910
46003
|
}
|
|
45911
46004
|
function mergePrivilegedServices(mergeContext, [serviceId, { stateUpdate }]) {
|
|
45912
|
-
const { outputState, currentPrivilegedServices, chainSpec } = mergeContext;
|
|
46005
|
+
const { outputState, currentPrivilegedServices, chainSpec, privilegedServicesUpdatedByManager } = mergeContext;
|
|
45913
46006
|
const currentManager = currentPrivilegedServices.manager;
|
|
45914
46007
|
const currentRegistrar = currentPrivilegedServices.registrar;
|
|
45915
46008
|
const currentDelegator = currentPrivilegedServices.delegator;
|
|
@@ -45927,28 +46020,35 @@ function mergePrivilegedServices(mergeContext, [serviceId, { stateUpdate }]) {
|
|
|
45927
46020
|
});
|
|
45928
46021
|
}
|
|
45929
46022
|
if (serviceId === currentRegistrar) {
|
|
45930
|
-
const newRegistrar = updatePrivilegedService(currentPrivilegedServices.registrar,
|
|
46023
|
+
const newRegistrar = updatePrivilegedService(currentPrivilegedServices.registrar, privilegedServicesUpdatedByManager.registrar, privilegedServices.registrar);
|
|
45931
46024
|
outputState.privilegedServices = PrivilegedServices.create({
|
|
45932
46025
|
...outputState.privilegedServices,
|
|
45933
46026
|
registrar: newRegistrar,
|
|
45934
46027
|
});
|
|
45935
46028
|
}
|
|
45936
46029
|
if (serviceId === currentDelegator) {
|
|
45937
|
-
const newDelegator = updatePrivilegedService(currentPrivilegedServices.delegator,
|
|
46030
|
+
const newDelegator = updatePrivilegedService(currentPrivilegedServices.delegator, privilegedServicesUpdatedByManager.delegator, privilegedServices.delegator);
|
|
45938
46031
|
outputState.privilegedServices = PrivilegedServices.create({
|
|
45939
46032
|
...outputState.privilegedServices,
|
|
45940
46033
|
delegator: newDelegator,
|
|
45941
46034
|
});
|
|
45942
46035
|
}
|
|
45943
|
-
|
|
45944
|
-
const newAssigners = currentAssigners.map((currentAssigner, coreIndex) =>
|
|
45945
|
-
|
|
45946
|
-
|
|
45947
|
-
|
|
45948
|
-
|
|
45949
|
-
|
|
45950
|
-
|
|
46036
|
+
let shouldUpdateAssigners = false;
|
|
46037
|
+
const newAssigners = currentAssigners.map((currentAssigner, coreIndex) => {
|
|
46038
|
+
if (serviceId === currentAssigner) {
|
|
46039
|
+
const newAssigner = updatePrivilegedService(currentPrivilegedServices.assigners[coreIndex], privilegedServicesUpdatedByManager.assigners[coreIndex], privilegedServices.assigners[coreIndex]);
|
|
46040
|
+
shouldUpdateAssigners = shouldUpdateAssigners || newAssigner !== currentAssigner;
|
|
46041
|
+
return newAssigner;
|
|
46042
|
+
}
|
|
46043
|
+
return currentAssigner;
|
|
45951
46044
|
});
|
|
46045
|
+
if (shouldUpdateAssigners) {
|
|
46046
|
+
const newAssignersPerCore = tryAsPerCore(newAssigners, chainSpec);
|
|
46047
|
+
outputState.privilegedServices = PrivilegedServices.create({
|
|
46048
|
+
...outputState.privilegedServices,
|
|
46049
|
+
assigners: newAssignersPerCore,
|
|
46050
|
+
});
|
|
46051
|
+
}
|
|
45952
46052
|
}
|
|
45953
46053
|
}
|
|
45954
46054
|
function mergeValidatorsData(mergeContext, [serviceId, { stateUpdate }]) {
|
|
@@ -46093,7 +46193,7 @@ class Assign {
|
|
|
46093
46193
|
const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
|
|
46094
46194
|
// error while reading the memory.
|
|
46095
46195
|
if (memoryReadResult.isError) {
|
|
46096
|
-
logger_logger.trace `ASSIGN() <- PANIC`;
|
|
46196
|
+
logger_logger.trace `[${this.currentServiceId}] ASSIGN() <- PANIC`;
|
|
46097
46197
|
return PvmExecution.Panic;
|
|
46098
46198
|
}
|
|
46099
46199
|
if (maybeCoreIndex >= this.chainSpec.coresCount) {
|
|
@@ -46108,18 +46208,18 @@ class Assign {
|
|
|
46108
46208
|
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
|
|
46109
46209
|
if (result.isOk) {
|
|
46110
46210
|
regs.set(assign_IN_OUT_REG, HostCallResult.OK);
|
|
46111
|
-
logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
|
|
46211
|
+
logger_logger.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
|
|
46112
46212
|
return;
|
|
46113
46213
|
}
|
|
46114
46214
|
const e = result.error;
|
|
46115
46215
|
if (e === UpdatePrivilegesError.UnprivilegedService) {
|
|
46116
46216
|
regs.set(assign_IN_OUT_REG, HostCallResult.HUH);
|
|
46117
|
-
logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
|
|
46217
|
+
logger_logger.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
|
|
46118
46218
|
return;
|
|
46119
46219
|
}
|
|
46120
46220
|
if (e === UpdatePrivilegesError.InvalidServiceId) {
|
|
46121
46221
|
regs.set(assign_IN_OUT_REG, HostCallResult.WHO);
|
|
46122
|
-
logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
|
|
46222
|
+
logger_logger.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
|
|
46123
46223
|
return;
|
|
46124
46224
|
}
|
|
46125
46225
|
debug_assertNever(e);
|
|
@@ -46190,7 +46290,7 @@ class Bless {
|
|
|
46190
46290
|
decoder.resetTo(0);
|
|
46191
46291
|
const memoryReadResult = memory.loadInto(result, memIndex);
|
|
46192
46292
|
if (memoryReadResult.isError) {
|
|
46193
|
-
logger_logger.trace `BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}) <- PANIC`;
|
|
46293
|
+
logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}) <- PANIC`;
|
|
46194
46294
|
return PvmExecution.Panic;
|
|
46195
46295
|
}
|
|
46196
46296
|
const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
|
|
@@ -46203,26 +46303,26 @@ class Bless {
|
|
|
46203
46303
|
const authorizersDecoder = decoder_Decoder.fromBlob(res);
|
|
46204
46304
|
const memoryReadResult = memory.loadInto(res, authorization);
|
|
46205
46305
|
if (memoryReadResult.isError) {
|
|
46206
|
-
logger_logger.trace `BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- PANIC`;
|
|
46306
|
+
logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- PANIC`;
|
|
46207
46307
|
return PvmExecution.Panic;
|
|
46208
46308
|
}
|
|
46209
46309
|
// `a`
|
|
46210
46310
|
const authorizers = tryAsPerCore(authorizersDecoder.sequenceFixLen(descriptors_codec.u32.asOpaque(), this.chainSpec.coresCount), this.chainSpec);
|
|
46211
46311
|
const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate);
|
|
46212
46312
|
if (updateResult.isOk) {
|
|
46213
|
-
logger_logger.trace `BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- OK`;
|
|
46313
|
+
logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- OK`;
|
|
46214
46314
|
regs.set(bless_IN_OUT_REG, HostCallResult.OK);
|
|
46215
46315
|
return;
|
|
46216
46316
|
}
|
|
46217
46317
|
const e = updateResult.error;
|
|
46218
46318
|
// NOTE: `UpdatePrivilegesError.UnprivilegedService` won't happen in 0.7.1+
|
|
46219
46319
|
if (e === UpdatePrivilegesError.UnprivilegedService) {
|
|
46220
|
-
logger_logger.trace `BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- HUH`;
|
|
46320
|
+
logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- HUH`;
|
|
46221
46321
|
regs.set(bless_IN_OUT_REG, HostCallResult.HUH);
|
|
46222
46322
|
return;
|
|
46223
46323
|
}
|
|
46224
46324
|
if (e === UpdatePrivilegesError.InvalidServiceId) {
|
|
46225
|
-
logger_logger.trace `BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- WHO`;
|
|
46325
|
+
logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- WHO`;
|
|
46226
46326
|
regs.set(bless_IN_OUT_REG, HostCallResult.WHO);
|
|
46227
46327
|
return;
|
|
46228
46328
|
}
|
|
@@ -46252,7 +46352,7 @@ class GasHostCall {
|
|
|
46252
46352
|
}
|
|
46253
46353
|
execute(gas, regs) {
|
|
46254
46354
|
const gasValue = gas.get();
|
|
46255
|
-
logger_logger.trace `GAS <- ${gasValue}`;
|
|
46355
|
+
logger_logger.trace `[${this.currentServiceId}] GAS <- ${gasValue}`;
|
|
46256
46356
|
regs.set(7, numbers_tryAsU64(gasValue));
|
|
46257
46357
|
return Promise.resolve(undefined);
|
|
46258
46358
|
}
|
|
@@ -46284,7 +46384,7 @@ class Checkpoint {
|
|
|
46284
46384
|
async execute(gas, regs) {
|
|
46285
46385
|
await this.gasHostCall.execute(gas, regs);
|
|
46286
46386
|
this.partialState.checkpoint();
|
|
46287
|
-
logger_logger.trace `CHECKPOINT()`;
|
|
46387
|
+
logger_logger.trace `[${this.currentServiceId}] CHECKPOINT()`;
|
|
46288
46388
|
return;
|
|
46289
46389
|
}
|
|
46290
46390
|
}
|
|
@@ -46324,18 +46424,18 @@ class Designate {
|
|
|
46324
46424
|
const memoryReadResult = memory.loadInto(res, validatorsStart);
|
|
46325
46425
|
// error while reading the memory.
|
|
46326
46426
|
if (memoryReadResult.isError) {
|
|
46327
|
-
logger_logger.trace `DESIGNATE() <- PANIC`;
|
|
46427
|
+
logger_logger.trace `[${this.currentServiceId}] DESIGNATE() <- PANIC`;
|
|
46328
46428
|
return PvmExecution.Panic;
|
|
46329
46429
|
}
|
|
46330
46430
|
const decoder = decoder_Decoder.fromBlob(res);
|
|
46331
46431
|
const validatorsData = decoder.sequenceFixLen(ValidatorData.Codec, this.chainSpec.validatorsCount);
|
|
46332
46432
|
const result = this.partialState.updateValidatorsData(tryAsPerValidator(validatorsData, this.chainSpec));
|
|
46333
46433
|
if (result.isError) {
|
|
46334
|
-
logger_logger.trace `DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- HUH`;
|
|
46434
|
+
logger_logger.trace `[${this.currentServiceId}] DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- HUH`;
|
|
46335
46435
|
regs.set(designate_IN_OUT_REG, HostCallResult.HUH);
|
|
46336
46436
|
}
|
|
46337
46437
|
else {
|
|
46338
|
-
logger_logger.trace `DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- OK`;
|
|
46438
|
+
logger_logger.trace `[${this.currentServiceId}] DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- OK`;
|
|
46339
46439
|
regs.set(designate_IN_OUT_REG, HostCallResult.OK);
|
|
46340
46440
|
}
|
|
46341
46441
|
}
|
|
@@ -46376,29 +46476,29 @@ class Eject {
|
|
|
46376
46476
|
const previousCodeHash = bytes_Bytes.zero(hash_HASH_SIZE).asOpaque();
|
|
46377
46477
|
const memoryReadResult = memory.loadInto(previousCodeHash.raw, preimageHashStart);
|
|
46378
46478
|
if (memoryReadResult.isError) {
|
|
46379
|
-
logger_logger.trace `EJECT(${serviceId}) <- PANIC`;
|
|
46479
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}) <- PANIC`;
|
|
46380
46480
|
return PvmExecution.Panic;
|
|
46381
46481
|
}
|
|
46382
46482
|
// cannot eject self
|
|
46383
46483
|
if (serviceId === this.currentServiceId) {
|
|
46384
46484
|
regs.set(eject_IN_OUT_REG, HostCallResult.WHO);
|
|
46385
|
-
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- WHO`;
|
|
46485
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- WHO`;
|
|
46386
46486
|
return;
|
|
46387
46487
|
}
|
|
46388
46488
|
const result = this.partialState.eject(serviceId, previousCodeHash);
|
|
46389
46489
|
// All good!
|
|
46390
46490
|
if (result.isOk) {
|
|
46391
|
-
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- OK`;
|
|
46491
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- OK`;
|
|
46392
46492
|
regs.set(eject_IN_OUT_REG, HostCallResult.OK);
|
|
46393
46493
|
return;
|
|
46394
46494
|
}
|
|
46395
46495
|
const e = result.error;
|
|
46396
46496
|
if (e === EjectError.InvalidService) {
|
|
46397
|
-
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- WHO ${result_resultToString(result)}`;
|
|
46497
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- WHO ${result_resultToString(result)}`;
|
|
46398
46498
|
regs.set(eject_IN_OUT_REG, HostCallResult.WHO);
|
|
46399
46499
|
}
|
|
46400
46500
|
else if (e === EjectError.InvalidPreimage) {
|
|
46401
|
-
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- HUH ${result_resultToString(result)}`;
|
|
46501
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- HUH ${result_resultToString(result)}`;
|
|
46402
46502
|
regs.set(eject_IN_OUT_REG, HostCallResult.HUH);
|
|
46403
46503
|
}
|
|
46404
46504
|
else {
|
|
@@ -46417,9 +46517,9 @@ class Eject {
|
|
|
46417
46517
|
|
|
46418
46518
|
const forget_IN_OUT_REG = 7;
|
|
46419
46519
|
/**
|
|
46420
|
-
*
|
|
46520
|
+
* Delete preimage hash or mark as unavailable if it was available.
|
|
46421
46521
|
*
|
|
46422
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
46522
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/385d01385d01?v=0.7.2
|
|
46423
46523
|
*/
|
|
46424
46524
|
class Forget {
|
|
46425
46525
|
currentServiceId;
|
|
@@ -46440,11 +46540,11 @@ class Forget {
|
|
|
46440
46540
|
const memoryReadResult = memory.loadInto(hash.raw, hashStart);
|
|
46441
46541
|
// error while reading the memory.
|
|
46442
46542
|
if (memoryReadResult.isError) {
|
|
46443
|
-
logger_logger.trace `FORGET(${hash}, ${length}) <- PANIC`;
|
|
46543
|
+
logger_logger.trace `[${this.currentServiceId}] FORGET(${hash}, ${length}) <- PANIC`;
|
|
46444
46544
|
return PvmExecution.Panic;
|
|
46445
46545
|
}
|
|
46446
46546
|
const result = this.partialState.forgetPreimage(hash.asOpaque(), length);
|
|
46447
|
-
logger_logger.trace `FORGET(${hash}, ${length}) <- ${result_resultToString(result)}`;
|
|
46547
|
+
logger_logger.trace `[${this.currentServiceId}] FORGET(${hash}, ${length}) <- ${result_resultToString(result)}`;
|
|
46448
46548
|
if (result.isOk) {
|
|
46449
46549
|
regs.set(forget_IN_OUT_REG, HostCallResult.OK);
|
|
46450
46550
|
}
|
|
@@ -46501,11 +46601,11 @@ class New {
|
|
|
46501
46601
|
const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
|
|
46502
46602
|
// error while reading the memory.
|
|
46503
46603
|
if (memoryReadResult.isError) {
|
|
46504
|
-
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
|
|
46604
|
+
logger_logger.trace `[${this.currentServiceId}] NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
|
|
46505
46605
|
return PvmExecution.Panic;
|
|
46506
46606
|
}
|
|
46507
46607
|
const assignedId = this.partialState.newService(codeHash.asOpaque(), codeLength, gas, allowance, gratisStorage, requestedServiceId);
|
|
46508
|
-
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${result_resultToString(assignedId)}`;
|
|
46608
|
+
logger_logger.trace `[${this.currentServiceId}] NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${result_resultToString(assignedId)}`;
|
|
46509
46609
|
if (assignedId.isOk) {
|
|
46510
46610
|
regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
|
|
46511
46611
|
return;
|
|
@@ -46565,11 +46665,11 @@ class Provide {
|
|
|
46565
46665
|
const preimage = bytes_BytesBlob.blobFrom(safe_alloc_uint8array_safeAllocUint8Array(length));
|
|
46566
46666
|
const memoryReadResult = memory.loadInto(preimage.raw, preimageStart);
|
|
46567
46667
|
if (memoryReadResult.isError) {
|
|
46568
|
-
logger_logger.trace `PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- PANIC`;
|
|
46668
|
+
logger_logger.trace `[${this.currentServiceId}] PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- PANIC`;
|
|
46569
46669
|
return PvmExecution.Panic;
|
|
46570
46670
|
}
|
|
46571
46671
|
const result = this.partialState.providePreimage(serviceId, preimage);
|
|
46572
|
-
logger_logger.trace `PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- ${result_resultToString(result)}`;
|
|
46672
|
+
logger_logger.trace `[${this.currentServiceId}] PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- ${result_resultToString(result)}`;
|
|
46573
46673
|
if (result.isOk) {
|
|
46574
46674
|
regs.set(provide_IN_OUT_REG, HostCallResult.OK);
|
|
46575
46675
|
return;
|
|
@@ -46625,35 +46725,35 @@ class Query {
|
|
|
46625
46725
|
const memoryReadResult = memory.loadInto(hash.raw, hashStart);
|
|
46626
46726
|
// error while reading the memory.
|
|
46627
46727
|
if (memoryReadResult.isError) {
|
|
46628
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- PANIC`;
|
|
46728
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- PANIC`;
|
|
46629
46729
|
return PvmExecution.Panic;
|
|
46630
46730
|
}
|
|
46631
46731
|
const result = this.partialState.checkPreimageStatus(hash.asOpaque(), length);
|
|
46632
46732
|
const zero = numbers_tryAsU64(0n);
|
|
46633
46733
|
if (result === null) {
|
|
46634
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- NONE`;
|
|
46734
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- NONE`;
|
|
46635
46735
|
regs.set(IN_OUT_REG_1, HostCallResult.NONE);
|
|
46636
46736
|
regs.set(IN_OUT_REG_2, zero);
|
|
46637
46737
|
return;
|
|
46638
46738
|
}
|
|
46639
46739
|
switch (result.status) {
|
|
46640
46740
|
case PreimageStatusKind.Requested:
|
|
46641
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- REQUESTED`;
|
|
46741
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- REQUESTED`;
|
|
46642
46742
|
regs.set(IN_OUT_REG_1, zero);
|
|
46643
46743
|
regs.set(IN_OUT_REG_2, zero);
|
|
46644
46744
|
return;
|
|
46645
46745
|
case PreimageStatusKind.Available:
|
|
46646
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- AVAILABLE [${result.data}]`;
|
|
46746
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- AVAILABLE [${result.data}]`;
|
|
46647
46747
|
regs.set(IN_OUT_REG_1, numbers_tryAsU64((BigInt(result.data[0]) << UPPER_BITS_SHIFT) + 1n));
|
|
46648
46748
|
regs.set(IN_OUT_REG_2, zero);
|
|
46649
46749
|
return;
|
|
46650
46750
|
case PreimageStatusKind.Unavailable:
|
|
46651
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- UNAVAILABLE [${result.data.join(", ")}]`;
|
|
46751
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- UNAVAILABLE [${result.data.join(", ")}]`;
|
|
46652
46752
|
regs.set(IN_OUT_REG_1, numbers_tryAsU64((BigInt(result.data[0]) << UPPER_BITS_SHIFT) + 2n));
|
|
46653
46753
|
regs.set(IN_OUT_REG_2, numbers_tryAsU64(result.data[1]));
|
|
46654
46754
|
return;
|
|
46655
46755
|
case PreimageStatusKind.Reavailable:
|
|
46656
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- REAVAILABLE [${result.data.join(", ")}]`;
|
|
46756
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- REAVAILABLE [${result.data.join(", ")}]`;
|
|
46657
46757
|
regs.set(IN_OUT_REG_1, numbers_tryAsU64((BigInt(result.data[0]) << UPPER_BITS_SHIFT) + 3n));
|
|
46658
46758
|
regs.set(IN_OUT_REG_2, numbers_tryAsU64((BigInt(result.data[2]) << UPPER_BITS_SHIFT) + BigInt(result.data[1])));
|
|
46659
46759
|
return;
|
|
@@ -46694,11 +46794,11 @@ class Solicit {
|
|
|
46694
46794
|
const hash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
46695
46795
|
const memoryReadResult = memory.loadInto(hash.raw, hashStart);
|
|
46696
46796
|
if (memoryReadResult.isError) {
|
|
46697
|
-
logger_logger.trace `SOLICIT(${hash}, ${length}) <- PANIC`;
|
|
46797
|
+
logger_logger.trace `[${this.currentServiceId}] SOLICIT(${hash}, ${length}) <- PANIC`;
|
|
46698
46798
|
return PvmExecution.Panic;
|
|
46699
46799
|
}
|
|
46700
46800
|
const result = this.partialState.requestPreimage(hash.asOpaque(), length);
|
|
46701
|
-
logger_logger.trace `SOLICIT(${hash}, ${length}) <- ${result_resultToString(result)}`;
|
|
46801
|
+
logger_logger.trace `[${this.currentServiceId}] SOLICIT(${hash}, ${length}) <- ${result_resultToString(result)}`;
|
|
46702
46802
|
if (result.isOk) {
|
|
46703
46803
|
regs.set(solicit_IN_OUT_REG, HostCallResult.OK);
|
|
46704
46804
|
return;
|
|
@@ -46756,7 +46856,7 @@ class Transfer {
|
|
|
46756
46856
|
*/
|
|
46757
46857
|
basicGasCost = Compatibility.isGreaterOrEqual(GpVersion.V0_7_2)
|
|
46758
46858
|
? gas_tryAsSmallGas(10)
|
|
46759
|
-
: (regs) =>
|
|
46859
|
+
: (regs) => gas_tryAsGas(10n + regs.get(TRANSFER_GAS_FEE_REG));
|
|
46760
46860
|
tracedRegisters = traceRegisters(transfer_IN_OUT_REG, AMOUNT_REG, TRANSFER_GAS_FEE_REG, MEMO_START_REG);
|
|
46761
46861
|
constructor(currentServiceId, partialState) {
|
|
46762
46862
|
this.currentServiceId = currentServiceId;
|
|
@@ -46775,16 +46875,16 @@ class Transfer {
|
|
|
46775
46875
|
const memoryReadResult = memory.loadInto(memo.raw, memoStart);
|
|
46776
46876
|
// page fault while reading the memory.
|
|
46777
46877
|
if (memoryReadResult.isError) {
|
|
46778
|
-
logger_logger.trace `TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- PANIC`;
|
|
46878
|
+
logger_logger.trace `[${this.currentServiceId}] TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- PANIC`;
|
|
46779
46879
|
return PvmExecution.Panic;
|
|
46780
46880
|
}
|
|
46781
46881
|
const transferResult = this.partialState.transfer(destination, amount, transferGasFee, memo);
|
|
46782
|
-
logger_logger.trace `TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- ${result_resultToString(transferResult)}`;
|
|
46882
|
+
logger_logger.trace `[${this.currentServiceId}] TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- ${result_resultToString(transferResult)}`;
|
|
46783
46883
|
// All good!
|
|
46784
46884
|
if (transferResult.isOk) {
|
|
46785
46885
|
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_2)) {
|
|
46786
46886
|
// substracting value `t`
|
|
46787
|
-
const underflow = gas.sub(
|
|
46887
|
+
const underflow = gas.sub(gas_tryAsGas(transferGasFee));
|
|
46788
46888
|
if (underflow) {
|
|
46789
46889
|
return PvmExecution.OOG;
|
|
46790
46890
|
}
|
|
@@ -46845,11 +46945,11 @@ class Upgrade {
|
|
|
46845
46945
|
const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
46846
46946
|
const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
|
|
46847
46947
|
if (memoryReadResult.isError) {
|
|
46848
|
-
logger_logger.trace `UPGRADE(${codeHash}, ${gas}, ${allowance}) <- PANIC`;
|
|
46948
|
+
logger_logger.trace `[${this.currentServiceId}] UPGRADE(${codeHash}, ${gas}, ${allowance}) <- PANIC`;
|
|
46849
46949
|
return PvmExecution.Panic;
|
|
46850
46950
|
}
|
|
46851
46951
|
this.partialState.upgradeService(codeHash.asOpaque(), gas, allowance);
|
|
46852
|
-
logger_logger.trace `UPGRADE(${codeHash}, ${gas}, ${allowance})`;
|
|
46952
|
+
logger_logger.trace `[${this.currentServiceId}] UPGRADE(${codeHash}, ${gas}, ${allowance})`;
|
|
46853
46953
|
regs.set(upgrade_IN_OUT_REG, HostCallResult.OK);
|
|
46854
46954
|
}
|
|
46855
46955
|
}
|
|
@@ -46883,11 +46983,11 @@ class Yield {
|
|
|
46883
46983
|
const hash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
46884
46984
|
const memoryReadResult = memory.loadInto(hash.raw, hashStart);
|
|
46885
46985
|
if (memoryReadResult.isError) {
|
|
46886
|
-
logger_logger.trace `YIELD() <- PANIC`;
|
|
46986
|
+
logger_logger.trace `[${this.currentServiceId}] YIELD() <- PANIC`;
|
|
46887
46987
|
return PvmExecution.Panic;
|
|
46888
46988
|
}
|
|
46889
46989
|
this.partialState.yield(hash);
|
|
46890
|
-
logger_logger.trace `YIELD(${hash})`;
|
|
46990
|
+
logger_logger.trace `[${this.currentServiceId}] YIELD(${hash})`;
|
|
46891
46991
|
regs.set(yield_IN_OUT_REG, HostCallResult.OK);
|
|
46892
46992
|
}
|
|
46893
46993
|
}
|
|
@@ -46930,10 +47030,10 @@ class Fetch {
|
|
|
46930
47030
|
const chunk = value === null ? new Uint8Array() : value.raw.subarray(Number(offset), Number(offset + length));
|
|
46931
47031
|
const storeResult = memory.storeFrom(output, chunk);
|
|
46932
47032
|
if (storeResult.isError) {
|
|
46933
|
-
logger_logger.trace `FETCH(${kind}) <- PANIC`;
|
|
47033
|
+
logger_logger.trace `[${this.currentServiceId}] FETCH(${kind}) <- PANIC`;
|
|
46934
47034
|
return PvmExecution.Panic;
|
|
46935
47035
|
}
|
|
46936
|
-
logger_logger.trace `FETCH(${kind}) <- ${value?.toStringTruncated()}`;
|
|
47036
|
+
logger_logger.trace `[${this.currentServiceId}] FETCH(${kind}) <- ${value?.toStringTruncated()}`;
|
|
46937
47037
|
// write result
|
|
46938
47038
|
regs.set(fetch_IN_OUT_REG, value === null ? HostCallResult.NONE : valueLength);
|
|
46939
47039
|
}
|
|
@@ -47083,7 +47183,7 @@ class LogHostCall {
|
|
|
47083
47183
|
}
|
|
47084
47184
|
memory.loadInto(message, msgStart);
|
|
47085
47185
|
const level = clampU64ToU32(lvl);
|
|
47086
|
-
logger_logger.trace `LOG(${this.currentServiceId}, ${level < Levels.UNKNOWN ? Levels[level] : Levels[Levels.UNKNOWN]}(${lvl}), ${decoder.decode(target)}, ${decoder.decode(message)})`;
|
|
47186
|
+
logger_logger.trace `[${this.currentServiceId}] LOG(${this.currentServiceId}, ${level < Levels.UNKNOWN ? Levels[level] : Levels[Levels.UNKNOWN]}(${lvl}), ${decoder.decode(target)}, ${decoder.decode(message)})`;
|
|
47087
47187
|
return Promise.resolve(undefined);
|
|
47088
47188
|
}
|
|
47089
47189
|
}
|
|
@@ -47124,12 +47224,12 @@ class Lookup {
|
|
|
47124
47224
|
const preImageHash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
47125
47225
|
const memoryReadResult = memory.loadInto(preImageHash.raw, hashAddress);
|
|
47126
47226
|
if (memoryReadResult.isError) {
|
|
47127
|
-
logger_logger.trace `LOOKUP(${serviceId}, ${preImageHash}) <- PANIC`;
|
|
47227
|
+
logger_logger.trace `[${this.currentServiceId}] LOOKUP(${serviceId}, ${preImageHash}) <- PANIC`;
|
|
47128
47228
|
return PvmExecution.Panic;
|
|
47129
47229
|
}
|
|
47130
47230
|
// v
|
|
47131
47231
|
const preImage = this.account.lookup(serviceId, preImageHash);
|
|
47132
|
-
logger_logger.trace `LOOKUP(${serviceId}, ${preImageHash}) <- ${preImage?.toStringTruncated() ?? "<missing>"}...`;
|
|
47232
|
+
logger_logger.trace `[${this.currentServiceId}] LOOKUP(${serviceId}, ${preImageHash}) <- ${preImage?.toStringTruncated() ?? "<missing>"}...`;
|
|
47133
47233
|
const preImageLength = preImage === null ? numbers_tryAsU64(0) : numbers_tryAsU64(preImage.raw.length);
|
|
47134
47234
|
const preimageBlobOffset = regs.get(10);
|
|
47135
47235
|
const lengthToWrite = regs.get(11);
|
|
@@ -47226,20 +47326,20 @@ class Read {
|
|
|
47226
47326
|
const chunk = value === null ? safe_alloc_uint8array_safeAllocUint8Array(0) : value.raw.subarray(Number(offset), Number(offset + blobLength));
|
|
47227
47327
|
const memoryWriteResult = memory.storeFrom(destinationAddress, chunk);
|
|
47228
47328
|
if (memoryWriteResult.isError) {
|
|
47229
|
-
logger_logger.trace `READ(${serviceId}, ${rawKey}) <- PANIC`;
|
|
47329
|
+
logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- PANIC`;
|
|
47230
47330
|
return PvmExecution.Panic;
|
|
47231
47331
|
}
|
|
47232
47332
|
if (value === null) {
|
|
47233
|
-
logger_logger.trace `READ(${serviceId}, ${rawKey}) <- NONE`;
|
|
47333
|
+
logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- NONE`;
|
|
47234
47334
|
regs.set(read_IN_OUT_REG, HostCallResult.NONE);
|
|
47235
47335
|
return;
|
|
47236
47336
|
}
|
|
47237
47337
|
if (chunk.length > 0) {
|
|
47238
|
-
logger_logger.trace `READ(${serviceId}, ${rawKey}) <- ${bytes_BytesBlob.blobFrom(chunk).toStringTruncated()}`;
|
|
47338
|
+
logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- ${bytes_BytesBlob.blobFrom(chunk).toStringTruncated()}`;
|
|
47239
47339
|
}
|
|
47240
47340
|
else {
|
|
47241
47341
|
// just a query for length of stored data
|
|
47242
|
-
logger_logger.trace `READ(${serviceId}, ${rawKey}) <- (${valueLength} ${valueLength === 1n ? "byte" : "bytes"})`;
|
|
47342
|
+
logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- (${valueLength} ${valueLength === 1n ? "byte" : "bytes"})`;
|
|
47243
47343
|
}
|
|
47244
47344
|
regs.set(read_IN_OUT_REG, valueLength);
|
|
47245
47345
|
}
|
|
@@ -47283,7 +47383,7 @@ class Write {
|
|
|
47283
47383
|
const rawStorageKey = safe_alloc_uint8array_safeAllocUint8Array(storageKeyLengthClamped);
|
|
47284
47384
|
const keyLoadingResult = memory.loadInto(rawStorageKey, storageKeyStartAddress);
|
|
47285
47385
|
if (keyLoadingResult.isError) {
|
|
47286
|
-
logger_logger.trace `WRITE() <- PANIC`;
|
|
47386
|
+
logger_logger.trace `[${this.currentServiceId}] WRITE() <- PANIC`;
|
|
47287
47387
|
return PvmExecution.Panic;
|
|
47288
47388
|
}
|
|
47289
47389
|
// k
|
|
@@ -47293,14 +47393,14 @@ class Write {
|
|
|
47293
47393
|
const valueLoadingResult = memory.loadInto(value, valueStart);
|
|
47294
47394
|
// Note [MaSo] this is ok to return bcs if valueLength is 0, then this panic won't happen
|
|
47295
47395
|
if (valueLoadingResult.isError) {
|
|
47296
|
-
logger_logger.trace `WRITE(${storageKey}) <- PANIC`;
|
|
47396
|
+
logger_logger.trace `[${this.currentServiceId}] WRITE(${storageKey}) <- PANIC`;
|
|
47297
47397
|
return PvmExecution.Panic;
|
|
47298
47398
|
}
|
|
47299
47399
|
/** https://graypaper.fluffylabs.dev/#/9a08063/33af0133b201?v=0.6.6 */
|
|
47300
47400
|
const maybeValue = valueLength === 0n ? null : bytes_BytesBlob.blobFrom(value);
|
|
47301
47401
|
// a
|
|
47302
47402
|
const result = this.account.write(storageKey, maybeValue);
|
|
47303
|
-
logger_logger.trace `WRITE(${storageKey}, ${maybeValue?.toStringTruncated() ?? "remove"}) <- ${result_resultToString(result)}`;
|
|
47403
|
+
logger_logger.trace `[${this.currentServiceId}] WRITE(${storageKey}, ${maybeValue?.toStringTruncated() ?? "remove"}) <- ${result_resultToString(result)}`;
|
|
47304
47404
|
if (result.isError) {
|
|
47305
47405
|
regs.set(write_IN_OUT_REG, HostCallResult.FULL);
|
|
47306
47406
|
return;
|
|
@@ -47529,7 +47629,7 @@ class Accumulate {
|
|
|
47529
47629
|
serviceId,
|
|
47530
47630
|
argsLength: numbers_tryAsU32(transfers.length + operands.length),
|
|
47531
47631
|
});
|
|
47532
|
-
const result = await executor.run(invocationArgs,
|
|
47632
|
+
const result = await executor.run(invocationArgs, gas_tryAsGas(gas));
|
|
47533
47633
|
const [newState, checkpoint] = partialState.getStateUpdates();
|
|
47534
47634
|
/**
|
|
47535
47635
|
* PVM invocation returned and error so we return the checkpoint
|
|
@@ -47730,19 +47830,19 @@ class Accumulate {
|
|
|
47730
47830
|
for (let serviceIndex = 0; serviceIndex < serviceIdsLength; serviceIndex += 1) {
|
|
47731
47831
|
const serviceId = serviceIds[serviceIndex];
|
|
47732
47832
|
const checkpoint = AccumulationStateUpdate.copyFrom(inputStateUpdate);
|
|
47733
|
-
const promise = this.accumulateSingleService(serviceId, accumulateData.getTransfers(serviceId), accumulateData.getOperands(serviceId), accumulateData.getGasLimit(serviceId), slot, entropy, AccumulationStateUpdate.copyFrom(inputStateUpdate)).then(({ consumedGas, stateUpdate }) =>
|
|
47734
|
-
|
|
47735
|
-
|
|
47736
|
-
|
|
47833
|
+
const promise = this.accumulateSingleService(serviceId, accumulateData.getTransfers(serviceId), accumulateData.getOperands(serviceId), accumulateData.getGasLimit(serviceId), slot, entropy, AccumulationStateUpdate.copyFrom(inputStateUpdate)).then(({ consumedGas, stateUpdate }) => {
|
|
47834
|
+
const resultEntry = [
|
|
47835
|
+
serviceId,
|
|
47836
|
+
{
|
|
47837
|
+
consumedGas,
|
|
47838
|
+
stateUpdate: stateUpdate === null ? checkpoint : stateUpdate,
|
|
47839
|
+
},
|
|
47840
|
+
];
|
|
47841
|
+
return resultEntry;
|
|
47842
|
+
});
|
|
47737
47843
|
resultPromises[serviceIndex] = promise;
|
|
47738
47844
|
}
|
|
47739
|
-
return Promise.all(resultPromises).then((results) =>
|
|
47740
|
-
const map = new Map();
|
|
47741
|
-
for (let serviceIndex = 0; serviceIndex < serviceIdsLength; serviceIndex += 1) {
|
|
47742
|
-
map.set(serviceIds[serviceIndex], results[serviceIndex]);
|
|
47743
|
-
}
|
|
47744
|
-
return map;
|
|
47745
|
-
});
|
|
47845
|
+
return Promise.all(resultPromises).then((results) => new Map(results));
|
|
47746
47846
|
}
|
|
47747
47847
|
/**
|
|
47748
47848
|
* A method that updates `recentlyAccumulated`, `accumulationQueue` and `timeslot` in state
|
|
@@ -47831,9 +47931,10 @@ class Accumulate {
|
|
|
47831
47931
|
const _gasCost = gasCost;
|
|
47832
47932
|
assertEmpty(rest);
|
|
47833
47933
|
const accumulated = accumulatableReports.subview(0, accumulatedReports);
|
|
47834
|
-
const { yieldedRoot, services, transfers
|
|
47934
|
+
const { yieldedRoot, services, transfers, validatorsData, privilegedServices, authorizationQueues, ...stateUpdateRest } = state;
|
|
47835
47935
|
assertEmpty(stateUpdateRest);
|
|
47836
|
-
// yielded root
|
|
47936
|
+
// transfers and yielded root are retrieved after each pvm invocation so we can ignore it here
|
|
47937
|
+
const _transfers = transfers;
|
|
47837
47938
|
const _yieldedRoot = yieldedRoot;
|
|
47838
47939
|
if (this.hasDuplicatedServiceIdCreated(services.created)) {
|
|
47839
47940
|
accumulate_logger.trace `Duplicated Service creation detected. Block is invalid.`;
|
|
@@ -47932,7 +48033,7 @@ class DeferredTransfers {
|
|
|
47932
48033
|
partiallyUpdatedState.updateServiceInfo(serviceId, newInfo);
|
|
47933
48034
|
const partialState = new AccumulateExternalities(this.chainSpec, this.blake2b, partiallyUpdatedState, serviceId, serviceId, timeslot);
|
|
47934
48035
|
const fetchExternalities = FetchExternalities.createForOnTransfer({ entropy, transfers }, this.chainSpec);
|
|
47935
|
-
let consumedGas =
|
|
48036
|
+
let consumedGas = gas_tryAsGas(0);
|
|
47936
48037
|
const hasTransfers = transfers.length > 0;
|
|
47937
48038
|
const isCodeCorrect = code !== null && code.length <= W_C;
|
|
47938
48039
|
if (!hasTransfers || !isCodeCorrect) {
|
|
@@ -47950,7 +48051,7 @@ class DeferredTransfers {
|
|
|
47950
48051
|
const executor = await PvmExecutor.createOnTransferExecutor(serviceId, code, { partialState, fetchExternalities }, this.pvm);
|
|
47951
48052
|
const args = encoder_Encoder.encodeObject(deferred_transfers_ARGS_CODEC, { timeslot, serviceId, transfersLength: numbers_tryAsU32(transfers.length) }, this.chainSpec);
|
|
47952
48053
|
const gas = transfers.reduce((acc, item) => acc + item.gas, 0n);
|
|
47953
|
-
consumedGas = (await executor.run(args,
|
|
48054
|
+
consumedGas = (await executor.run(args, gas_tryAsGas(gas))).consumedGas;
|
|
47954
48055
|
}
|
|
47955
48056
|
transferStatistics.set(serviceId, { count: numbers_tryAsU32(transfers.length), gasUsed: tryAsServiceGas(consumedGas) });
|
|
47956
48057
|
const [updatedState] = partialState.getStateUpdates();
|
|
@@ -49764,7 +49865,7 @@ async function createImporter(config) {
|
|
|
49764
49865
|
const interpreter = config.workerParams.pvm;
|
|
49765
49866
|
const blocks = db.getBlocksDb();
|
|
49766
49867
|
const states = db.getStatesDb();
|
|
49767
|
-
const hasher = new hasher_TransitionHasher(
|
|
49868
|
+
const hasher = new hasher_TransitionHasher(await keccakHasher, await blake2b);
|
|
49768
49869
|
const importer = new Importer(chainSpec, interpreter, hasher, main_logger, blocks, states);
|
|
49769
49870
|
return {
|
|
49770
49871
|
importer,
|
|
@@ -52421,7 +52522,7 @@ function initializeExtensions(api) {
|
|
|
52421
52522
|
}
|
|
52422
52523
|
|
|
52423
52524
|
;// CONCATENATED MODULE: ./packages/jam/node/package.json
|
|
52424
|
-
const package_namespaceObject = {"rE":"0.4.
|
|
52525
|
+
const package_namespaceObject = {"rE":"0.4.1"};
|
|
52425
52526
|
;// CONCATENATED MODULE: ./packages/workers/block-generator/generator.ts
|
|
52426
52527
|
|
|
52427
52528
|
|
|
@@ -52488,7 +52589,7 @@ class generator_Generator {
|
|
|
52488
52589
|
// select validator for block
|
|
52489
52590
|
const validatorId = tryAsValidatorIndex(newTimeSlot % 6);
|
|
52490
52591
|
// retriev data from previous block
|
|
52491
|
-
const hasher = new TransitionHasher(this.
|
|
52592
|
+
const hasher = new TransitionHasher(this.keccakHasher, this.blake2b);
|
|
52492
52593
|
const parentHeaderHash = this.lastHeaderHash;
|
|
52493
52594
|
const stateRoot = this.states.getStateRoot(this.lastState);
|
|
52494
52595
|
// create extrinsic
|
|
@@ -53055,7 +53156,7 @@ function readJsonBlock(file, chainSpec) {
|
|
|
53055
53156
|
var minimist = __nccwpck_require__(8595);
|
|
53056
53157
|
var minimist_default = /*#__PURE__*/__nccwpck_require__.n(minimist);
|
|
53057
53158
|
;// CONCATENATED MODULE: ./bin/jam/package.json
|
|
53058
|
-
const jam_package_namespaceObject = {"rE":"0.4.
|
|
53159
|
+
const jam_package_namespaceObject = {"rE":"0.4.1"};
|
|
53059
53160
|
;// CONCATENATED MODULE: ./bin/jam/args.ts
|
|
53060
53161
|
|
|
53061
53162
|
|