@typeberry/jam 0.4.0 → 0.4.1-69ce381
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 +505 -42
- package/bootstrap-generator.mjs.map +1 -1
- package/bootstrap-importer.mjs +798 -258
- package/bootstrap-importer.mjs.map +1 -1
- package/bootstrap-network.mjs +479 -38
- package/bootstrap-network.mjs.map +1 -1
- package/index.js +802 -262
- 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.
|
|
@@ -28430,9 +28434,438 @@ class ArrayView {
|
|
|
28430
28434
|
}
|
|
28431
28435
|
}
|
|
28432
28436
|
|
|
28437
|
+
;// CONCATENATED MODULE: ./packages/core/collections/blob-dictionary.ts
|
|
28438
|
+
|
|
28439
|
+
|
|
28440
|
+
/** A map which uses byte blobs as keys */
|
|
28441
|
+
class BlobDictionary extends WithDebug {
|
|
28442
|
+
mapNodeThreshold;
|
|
28443
|
+
/**
|
|
28444
|
+
* The root node of the dictionary.
|
|
28445
|
+
*
|
|
28446
|
+
* This is the main internal data structure that organizes entries
|
|
28447
|
+
* in a tree-like fashion (array-based nodes up to `mapNodeThreshold`,
|
|
28448
|
+
* map-based nodes beyond it). All insertions, updates, and deletions
|
|
28449
|
+
* operate through this structure.
|
|
28450
|
+
*/
|
|
28451
|
+
root = Node.withList();
|
|
28452
|
+
/**
|
|
28453
|
+
* Auxiliary map that stores references to the original keys and their values.
|
|
28454
|
+
*
|
|
28455
|
+
* - Overriding a value in the main structure does not replace the original key reference.
|
|
28456
|
+
* - Used for efficient iteration over `keys()`, `values()`, `entries()`, and computing `size`.
|
|
28457
|
+
*/
|
|
28458
|
+
keyvals = new Map();
|
|
28459
|
+
/**
|
|
28460
|
+
* Protected constructor used internally by `BlobDictionary.new`
|
|
28461
|
+
* and `BlobDictionary.fromEntries`.
|
|
28462
|
+
*
|
|
28463
|
+
* This enforces controlled instantiation — users should create instances
|
|
28464
|
+
* through the provided static factory methods instead of calling the
|
|
28465
|
+
* constructor directly.
|
|
28466
|
+
*
|
|
28467
|
+
* @param mapNodeThreshold - The threshold that determines when the dictionary
|
|
28468
|
+
* switches from using an array-based (`ListChildren`) node to a map-based (`MapChildren`) node for storing entries.
|
|
28469
|
+
*/
|
|
28470
|
+
constructor(mapNodeThreshold) {
|
|
28471
|
+
super();
|
|
28472
|
+
this.mapNodeThreshold = mapNodeThreshold;
|
|
28473
|
+
}
|
|
28474
|
+
/**
|
|
28475
|
+
* Returns the number of entries in the dictionary.
|
|
28476
|
+
*
|
|
28477
|
+
* The count is derived from the auxiliary `keyvals` map, which stores
|
|
28478
|
+
* all original key references and their associated values. This ensures
|
|
28479
|
+
* that the `size` reflects the actual number of entries, independent of
|
|
28480
|
+
* internal overrides in the main `root` structure.
|
|
28481
|
+
*
|
|
28482
|
+
* @returns The total number of entries in the dictionary.
|
|
28483
|
+
*/
|
|
28484
|
+
get size() {
|
|
28485
|
+
return this.keyvals.size;
|
|
28486
|
+
}
|
|
28487
|
+
[TEST_COMPARE_USING]() {
|
|
28488
|
+
const vals = Array.from(this);
|
|
28489
|
+
vals.sort((a, b) => a[0].compare(b[0]).value);
|
|
28490
|
+
return vals;
|
|
28491
|
+
}
|
|
28492
|
+
/**
|
|
28493
|
+
* Creates an empty `BlobDictionary`.
|
|
28494
|
+
*
|
|
28495
|
+
* @param mapNodeThreshold - The threshold that determines when the dictionary
|
|
28496
|
+
* switches from using an array-based (`ListChildren`) node to a map-based (`MapChildren`) node for storing entries.
|
|
28497
|
+
* Defaults to `0`.
|
|
28498
|
+
*
|
|
28499
|
+
* @returns A new, empty `BlobDictionary` instance.
|
|
28500
|
+
*/
|
|
28501
|
+
static new(mapNodeThreshold = 0) {
|
|
28502
|
+
return new BlobDictionary(mapNodeThreshold);
|
|
28503
|
+
}
|
|
28504
|
+
/**
|
|
28505
|
+
* Creates a new `BlobDictionary` initialized with the given entries.
|
|
28506
|
+
*
|
|
28507
|
+
* @param entries - An array of `[key, value]` pairs used to populate the dictionary.
|
|
28508
|
+
* @param mapNodeThreshold - The threshold that determines when the dictionary
|
|
28509
|
+
* switches from using an array-based (`ListChildren`) node to a map-based (`MapChildren`) node for storing entries.
|
|
28510
|
+
* Defaults to `0`.
|
|
28511
|
+
*
|
|
28512
|
+
* @returns A new `BlobDictionary` containing the provided entries.
|
|
28513
|
+
*/
|
|
28514
|
+
static fromEntries(entries, mapNodeThreshold) {
|
|
28515
|
+
const dict = BlobDictionary.new(mapNodeThreshold);
|
|
28516
|
+
for (const [key, value] of entries) {
|
|
28517
|
+
dict.set(key, value);
|
|
28518
|
+
}
|
|
28519
|
+
return dict;
|
|
28520
|
+
}
|
|
28521
|
+
/**
|
|
28522
|
+
* Internal helper that inserts, updates or deletes an entry in the dictionary.
|
|
28523
|
+
*
|
|
28524
|
+
* Behaviour details:
|
|
28525
|
+
* - Passing `undefined` as `value` indicates a deletion. (E.g. `delete` uses `internalSet(key, undefined)`.)
|
|
28526
|
+
* - When an add (new entry) or a delete actually changes the structure, the method returns the affected leaf node.
|
|
28527
|
+
* - When the call only overrides an existing value (no structural add/delete), the method returns `null`.
|
|
28528
|
+
*
|
|
28529
|
+
* This method is intended for internal use by the dictionary implementation and allows `undefined` as a
|
|
28530
|
+
* sentinel value to signal removals.
|
|
28531
|
+
*
|
|
28532
|
+
* @param key - The key to insert, update or remove.
|
|
28533
|
+
* @param value - The value to associate with the key, or `undefined` to remove the key.
|
|
28534
|
+
* @returns The leaf node created or removed on add/delete, or `null` if the operation only overwrote an existing value.
|
|
28535
|
+
*/
|
|
28536
|
+
internalSet(key, value) {
|
|
28537
|
+
let node = this.root;
|
|
28538
|
+
const keyChunkGenerator = key.chunks(CHUNK_SIZE);
|
|
28539
|
+
let depth = 0;
|
|
28540
|
+
for (;;) {
|
|
28541
|
+
const maybeKeyChunk = keyChunkGenerator.next().value;
|
|
28542
|
+
if (maybeKeyChunk === undefined) {
|
|
28543
|
+
if (value === undefined) {
|
|
28544
|
+
return node.remove(key);
|
|
28545
|
+
}
|
|
28546
|
+
return node.set(key, value);
|
|
28547
|
+
}
|
|
28548
|
+
const keyChunk = opaque_asOpaqueType(maybeKeyChunk);
|
|
28549
|
+
if (node.children instanceof ListChildren) {
|
|
28550
|
+
const subkey = bytes_BytesBlob.blobFrom(key.raw.subarray(CHUNK_SIZE * depth));
|
|
28551
|
+
const leaf = value !== undefined ? node.children.insert(subkey, { key, value }) : node.children.remove(subkey);
|
|
28552
|
+
if (subkey.length > CHUNK_SIZE && node.children.children.length > this.mapNodeThreshold) {
|
|
28553
|
+
node.convertListChildrenToMap();
|
|
28554
|
+
}
|
|
28555
|
+
return leaf;
|
|
28556
|
+
}
|
|
28557
|
+
depth += 1;
|
|
28558
|
+
const children = node.children;
|
|
28559
|
+
if (children instanceof ListChildren) {
|
|
28560
|
+
throw new Error("We handle list node earlier. If we fall through, we know it's for the `Map` case.");
|
|
28561
|
+
}
|
|
28562
|
+
if (children instanceof MapChildren) {
|
|
28563
|
+
const maybeNode = children.getChild(keyChunk);
|
|
28564
|
+
if (maybeNode !== undefined) {
|
|
28565
|
+
// simply go one level deeper
|
|
28566
|
+
node = maybeNode;
|
|
28567
|
+
}
|
|
28568
|
+
else {
|
|
28569
|
+
// we are trying to remove an item, but it does not exist
|
|
28570
|
+
if (value === undefined) {
|
|
28571
|
+
return null;
|
|
28572
|
+
}
|
|
28573
|
+
// no more child nodes, we insert a new one.
|
|
28574
|
+
const newNode = Node.withList();
|
|
28575
|
+
children.setChild(keyChunk, newNode);
|
|
28576
|
+
node = newNode;
|
|
28577
|
+
}
|
|
28578
|
+
continue;
|
|
28579
|
+
}
|
|
28580
|
+
debug_assertNever(children);
|
|
28581
|
+
}
|
|
28582
|
+
}
|
|
28583
|
+
/**
|
|
28584
|
+
* Adds a new entry to the dictionary or updates the value of an existing key.
|
|
28585
|
+
*
|
|
28586
|
+
* If an entry with the given key already exists, its value is replaced
|
|
28587
|
+
* with the new one.
|
|
28588
|
+
*
|
|
28589
|
+
* @param key - The key to add or update in the dictionary.
|
|
28590
|
+
* @param value - The value to associate with the specified key.
|
|
28591
|
+
* @returns Nothing (`void`).
|
|
28592
|
+
*/
|
|
28593
|
+
set(key, value) {
|
|
28594
|
+
const leaf = this.internalSet(key, value);
|
|
28595
|
+
if (leaf !== null) {
|
|
28596
|
+
this.keyvals.set(leaf.key, leaf);
|
|
28597
|
+
}
|
|
28598
|
+
}
|
|
28599
|
+
/**
|
|
28600
|
+
* Retrieves the value associated with the given key from the dictionary.
|
|
28601
|
+
*
|
|
28602
|
+
* If the key does not exist, this method returns `undefined`.
|
|
28603
|
+
*
|
|
28604
|
+
* @param key - The key whose associated value should be retrieved.
|
|
28605
|
+
* @returns The value associated with the specified key, or `undefined` if the key is not present.
|
|
28606
|
+
*/
|
|
28607
|
+
get(key) {
|
|
28608
|
+
let node = this.root;
|
|
28609
|
+
const pathChunksGenerator = key.chunks(CHUNK_SIZE);
|
|
28610
|
+
let depth = 0;
|
|
28611
|
+
while (node !== undefined) {
|
|
28612
|
+
const maybePathChunk = pathChunksGenerator.next().value;
|
|
28613
|
+
if (node.children instanceof ListChildren) {
|
|
28614
|
+
const subkey = bytes_BytesBlob.blobFrom(key.raw.subarray(depth * CHUNK_SIZE));
|
|
28615
|
+
const child = node.children.find(subkey);
|
|
28616
|
+
if (child !== null) {
|
|
28617
|
+
return child.value;
|
|
28618
|
+
}
|
|
28619
|
+
}
|
|
28620
|
+
if (maybePathChunk === undefined) {
|
|
28621
|
+
return node.getLeaf()?.value;
|
|
28622
|
+
}
|
|
28623
|
+
if (node.children instanceof MapChildren) {
|
|
28624
|
+
const pathChunk = opaque_asOpaqueType(maybePathChunk);
|
|
28625
|
+
node = node.children.getChild(pathChunk);
|
|
28626
|
+
depth += 1;
|
|
28627
|
+
}
|
|
28628
|
+
}
|
|
28629
|
+
return undefined;
|
|
28630
|
+
}
|
|
28631
|
+
/**
|
|
28632
|
+
* Checks whether the dictionary contains an entry for the given key.
|
|
28633
|
+
*
|
|
28634
|
+
* ⚠️ **Note:** Avoid using `has(...)` together with `get(...)` in a pattern like this:
|
|
28635
|
+
*
|
|
28636
|
+
* ```ts
|
|
28637
|
+
* if (dict.has(key)) {
|
|
28638
|
+
* const value = dict.get(key);
|
|
28639
|
+
* ...
|
|
28640
|
+
* }
|
|
28641
|
+
* ```
|
|
28642
|
+
*
|
|
28643
|
+
* This approach performs two lookups for the same key.
|
|
28644
|
+
*
|
|
28645
|
+
* Instead, prefer the following pattern, which retrieves the value once:
|
|
28646
|
+
*
|
|
28647
|
+
* ```ts
|
|
28648
|
+
* const value = dict.get(key);
|
|
28649
|
+
* if (value !== undefined) {
|
|
28650
|
+
* ...
|
|
28651
|
+
* }
|
|
28652
|
+
* ```
|
|
28653
|
+
*
|
|
28654
|
+
* @param key - The key to check for.
|
|
28655
|
+
* @returns `true` if the dictionary contains an entry for the given key, otherwise `false`.
|
|
28656
|
+
*/
|
|
28657
|
+
has(key) {
|
|
28658
|
+
return this.get(key) !== undefined;
|
|
28659
|
+
}
|
|
28660
|
+
/**
|
|
28661
|
+
* Removes an entry with the specified key from the dictionary.
|
|
28662
|
+
*
|
|
28663
|
+
* Internally, this calls {@link internalSet} with `undefined` to mark the entry as deleted.
|
|
28664
|
+
*
|
|
28665
|
+
* @param key - The key of the entry to remove.
|
|
28666
|
+
* @returns `true` if an entry was removed (i.e. the key existed), otherwise `false`.
|
|
28667
|
+
*/
|
|
28668
|
+
delete(key) {
|
|
28669
|
+
const leaf = this.internalSet(key, undefined);
|
|
28670
|
+
if (leaf !== null) {
|
|
28671
|
+
this.keyvals.delete(leaf.key);
|
|
28672
|
+
return true;
|
|
28673
|
+
}
|
|
28674
|
+
return false;
|
|
28675
|
+
}
|
|
28676
|
+
/**
|
|
28677
|
+
* Returns an iterator over the keys in the dictionary.
|
|
28678
|
+
*
|
|
28679
|
+
* The iterator yields each key in insertion order.
|
|
28680
|
+
*
|
|
28681
|
+
* @returns An iterator over all keys in the dictionary.
|
|
28682
|
+
*/
|
|
28683
|
+
keys() {
|
|
28684
|
+
return this.keyvals.keys();
|
|
28685
|
+
}
|
|
28686
|
+
/**
|
|
28687
|
+
* Returns an iterator over the values in the dictionary.
|
|
28688
|
+
*
|
|
28689
|
+
* The iterator yields each value in insertion order.
|
|
28690
|
+
*
|
|
28691
|
+
* @returns An iterator over all values in the dictionary.
|
|
28692
|
+
*/
|
|
28693
|
+
*values() {
|
|
28694
|
+
for (const leaf of this.keyvals.values()) {
|
|
28695
|
+
yield leaf.value;
|
|
28696
|
+
}
|
|
28697
|
+
}
|
|
28698
|
+
/**
|
|
28699
|
+
* Returns an iterator over the `[key, value]` pairs in the dictionary.
|
|
28700
|
+
*
|
|
28701
|
+
* The iterator yields entries in insertion order.
|
|
28702
|
+
*
|
|
28703
|
+
* @returns An iterator over `[key, value]` tuples for each entry in the dictionary.
|
|
28704
|
+
*/
|
|
28705
|
+
*entries() {
|
|
28706
|
+
for (const leaf of this.keyvals.values()) {
|
|
28707
|
+
yield [leaf.key, leaf.value];
|
|
28708
|
+
}
|
|
28709
|
+
}
|
|
28710
|
+
/**
|
|
28711
|
+
* Default iterator for the dictionary.
|
|
28712
|
+
*
|
|
28713
|
+
* Equivalent to calling {@link entries}.
|
|
28714
|
+
* Enables iteration with `for...of`:
|
|
28715
|
+
*
|
|
28716
|
+
* ```ts
|
|
28717
|
+
* for (const [key, value] of dict) {
|
|
28718
|
+
* ...
|
|
28719
|
+
* }
|
|
28720
|
+
* ```
|
|
28721
|
+
*
|
|
28722
|
+
* @returns An iterator over `[key, value]` pairs.
|
|
28723
|
+
*/
|
|
28724
|
+
[Symbol.iterator]() {
|
|
28725
|
+
return this.entries();
|
|
28726
|
+
}
|
|
28727
|
+
/**
|
|
28728
|
+
* Creates a new sorted array of values, ordered by their corresponding keys.
|
|
28729
|
+
*
|
|
28730
|
+
* Iterates over all entries in the dictionary and sorts them according
|
|
28731
|
+
* to the provided comparator function applied to the keys.
|
|
28732
|
+
*
|
|
28733
|
+
* @param comparator - A comparator function that can compare two keys.
|
|
28734
|
+
*
|
|
28735
|
+
* @returns A new array containing all values from the dictionary,
|
|
28736
|
+
* sorted according to their keys.
|
|
28737
|
+
*/
|
|
28738
|
+
toSortedArray(comparator) {
|
|
28739
|
+
const vals = Array.from(this);
|
|
28740
|
+
vals.sort((a, b) => comparator(a[0], b[0]).value);
|
|
28741
|
+
return vals.map((x) => x[1]);
|
|
28742
|
+
}
|
|
28743
|
+
}
|
|
28744
|
+
const CHUNK_SIZE = 6;
|
|
28745
|
+
/**
|
|
28746
|
+
* A function to transform a bytes chunk (up to 6 bytes into U48 number)
|
|
28747
|
+
*
|
|
28748
|
+
* Note that it uses 3 additional bits to store length(`value * 8 + len;`),
|
|
28749
|
+
* It is needed to distinguish shorter chunks that have 0s at the end, for example: [1, 2] and [1, 2, 0]
|
|
28750
|
+
* */
|
|
28751
|
+
function bytesAsU48(bytes) {
|
|
28752
|
+
const len = bytes.length;
|
|
28753
|
+
debug_check `${len <= CHUNK_SIZE} Length has to be <= ${CHUNK_SIZE}, got: ${len}`;
|
|
28754
|
+
let value = bytes[3] | (bytes[2] << 8) | (bytes[1] << 16) | (bytes[0] << 24);
|
|
28755
|
+
for (let i = 4; i < bytes.length; i++) {
|
|
28756
|
+
value = value * 256 + bytes[i];
|
|
28757
|
+
}
|
|
28758
|
+
return value * 8 + len;
|
|
28759
|
+
}
|
|
28760
|
+
class Node {
|
|
28761
|
+
leaf;
|
|
28762
|
+
children;
|
|
28763
|
+
convertListChildrenToMap() {
|
|
28764
|
+
if (!(this.children instanceof ListChildren)) {
|
|
28765
|
+
return;
|
|
28766
|
+
}
|
|
28767
|
+
this.children = MapChildren.fromListNode(this.children);
|
|
28768
|
+
}
|
|
28769
|
+
static withList() {
|
|
28770
|
+
return new Node(undefined, ListChildren.new());
|
|
28771
|
+
}
|
|
28772
|
+
static withMap() {
|
|
28773
|
+
return new Node(undefined, MapChildren.new());
|
|
28774
|
+
}
|
|
28775
|
+
constructor(leaf, children) {
|
|
28776
|
+
this.leaf = leaf;
|
|
28777
|
+
this.children = children;
|
|
28778
|
+
}
|
|
28779
|
+
getLeaf() {
|
|
28780
|
+
return this.leaf;
|
|
28781
|
+
}
|
|
28782
|
+
remove(_key) {
|
|
28783
|
+
if (this.leaf === undefined) {
|
|
28784
|
+
return null;
|
|
28785
|
+
}
|
|
28786
|
+
const removedLeaf = this.leaf;
|
|
28787
|
+
this.leaf = undefined;
|
|
28788
|
+
return removedLeaf;
|
|
28789
|
+
}
|
|
28790
|
+
set(key, value) {
|
|
28791
|
+
if (this.leaf === undefined) {
|
|
28792
|
+
this.leaf = { key, value };
|
|
28793
|
+
return this.leaf;
|
|
28794
|
+
}
|
|
28795
|
+
this.leaf.value = value;
|
|
28796
|
+
return null;
|
|
28797
|
+
}
|
|
28798
|
+
}
|
|
28799
|
+
class ListChildren {
|
|
28800
|
+
children = [];
|
|
28801
|
+
constructor() { }
|
|
28802
|
+
find(key) {
|
|
28803
|
+
const result = this.children.find((item) => item[0].isEqualTo(key));
|
|
28804
|
+
if (result !== undefined) {
|
|
28805
|
+
return result[1];
|
|
28806
|
+
}
|
|
28807
|
+
return null;
|
|
28808
|
+
}
|
|
28809
|
+
remove(key) {
|
|
28810
|
+
const existingIndex = this.children.findIndex((item) => item[0].isEqualTo(key));
|
|
28811
|
+
if (existingIndex >= 0) {
|
|
28812
|
+
const ret = this.children.splice(existingIndex, 1);
|
|
28813
|
+
return ret[0][1];
|
|
28814
|
+
}
|
|
28815
|
+
return null;
|
|
28816
|
+
}
|
|
28817
|
+
insert(key, leaf) {
|
|
28818
|
+
const existingIndex = this.children.findIndex((item) => item[0].isEqualTo(key));
|
|
28819
|
+
if (existingIndex >= 0) {
|
|
28820
|
+
const existing = this.children[existingIndex];
|
|
28821
|
+
existing[1].value = leaf.value;
|
|
28822
|
+
return null;
|
|
28823
|
+
}
|
|
28824
|
+
this.children.push([key, leaf]);
|
|
28825
|
+
return leaf;
|
|
28826
|
+
}
|
|
28827
|
+
static new() {
|
|
28828
|
+
return new ListChildren();
|
|
28829
|
+
}
|
|
28830
|
+
}
|
|
28831
|
+
class MapChildren {
|
|
28832
|
+
children = new Map();
|
|
28833
|
+
constructor() { }
|
|
28834
|
+
static new() {
|
|
28835
|
+
return new MapChildren();
|
|
28836
|
+
}
|
|
28837
|
+
static fromListNode(node) {
|
|
28838
|
+
const mapNode = new MapChildren();
|
|
28839
|
+
for (const [key, leaf] of node.children) {
|
|
28840
|
+
const currentKeyChunk = opaque_asOpaqueType(bytes_BytesBlob.blobFrom(key.raw.subarray(0, CHUNK_SIZE)));
|
|
28841
|
+
const subKey = bytes_BytesBlob.blobFrom(key.raw.subarray(CHUNK_SIZE));
|
|
28842
|
+
let child = mapNode.getChild(currentKeyChunk);
|
|
28843
|
+
if (child === undefined) {
|
|
28844
|
+
child = Node.withList();
|
|
28845
|
+
mapNode.setChild(currentKeyChunk, child);
|
|
28846
|
+
}
|
|
28847
|
+
const children = child.children;
|
|
28848
|
+
children.insert(subKey, leaf);
|
|
28849
|
+
}
|
|
28850
|
+
return mapNode;
|
|
28851
|
+
}
|
|
28852
|
+
getChild(keyChunk) {
|
|
28853
|
+
const chunkAsNumber = bytesAsU48(keyChunk.raw);
|
|
28854
|
+
return this.children.get(chunkAsNumber);
|
|
28855
|
+
}
|
|
28856
|
+
setChild(keyChunk, node) {
|
|
28857
|
+
const chunkAsNumber = bytesAsU48(keyChunk.raw);
|
|
28858
|
+
this.children.set(chunkAsNumber, node);
|
|
28859
|
+
}
|
|
28860
|
+
}
|
|
28861
|
+
|
|
28433
28862
|
;// CONCATENATED MODULE: ./packages/core/collections/hash-dictionary.ts
|
|
28434
|
-
/**
|
|
28435
|
-
|
|
28863
|
+
/**
|
|
28864
|
+
* A map which uses hashes as keys.
|
|
28865
|
+
*
|
|
28866
|
+
* @deprecated
|
|
28867
|
+
* */
|
|
28868
|
+
class StringHashDictionary {
|
|
28436
28869
|
// TODO [ToDr] [crit] We can't use `TrieHash` directly in the map,
|
|
28437
28870
|
// because of the way it's being compared. Hence having `string` here.
|
|
28438
28871
|
// This has to be benchmarked and re-written to a custom map most likely.
|
|
@@ -28498,6 +28931,17 @@ class hash_dictionary_HashDictionary {
|
|
|
28498
28931
|
}
|
|
28499
28932
|
}
|
|
28500
28933
|
|
|
28934
|
+
/**
|
|
28935
|
+
* A value that indicates when `BlobDictionary` transforms Array nodes into Map nodes.
|
|
28936
|
+
* In practice, it doesn't matter much because, in real life, arrays in this structure usually have a length close to 1.
|
|
28937
|
+
*/
|
|
28938
|
+
const BLOB_DICTIONARY_THRESHOLD = 5;
|
|
28939
|
+
class hash_dictionary_HashDictionary extends BlobDictionary {
|
|
28940
|
+
constructor() {
|
|
28941
|
+
super(BLOB_DICTIONARY_THRESHOLD);
|
|
28942
|
+
}
|
|
28943
|
+
}
|
|
28944
|
+
|
|
28501
28945
|
;// CONCATENATED MODULE: ./packages/core/collections/hash-set.ts
|
|
28502
28946
|
|
|
28503
28947
|
/** A set specialized for storing hashes. */
|
|
@@ -28962,6 +29406,18 @@ class SortedSet extends SortedArray {
|
|
|
28962
29406
|
|
|
28963
29407
|
|
|
28964
29408
|
|
|
29409
|
+
function getTruncatedKey(key) {
|
|
29410
|
+
// Always return exactly TRUNCATED_HASH_SIZE bytes.
|
|
29411
|
+
if (key.length === TRUNCATED_HASH_SIZE) {
|
|
29412
|
+
return key;
|
|
29413
|
+
}
|
|
29414
|
+
return bytes_Bytes.fromBlob(key.raw.subarray(0, TRUNCATED_HASH_SIZE), TRUNCATED_HASH_SIZE);
|
|
29415
|
+
}
|
|
29416
|
+
/**
|
|
29417
|
+
* A value that indicates when `BlobDictionary` transforms Array nodes into Map nodes.
|
|
29418
|
+
* In practice, it doesn't matter much because, in real life, arrays in this structure usually have a length close to 1.
|
|
29419
|
+
*/
|
|
29420
|
+
const truncated_hash_dictionary_BLOB_DICTIONARY_THRESHOLD = 5;
|
|
28965
29421
|
/**
|
|
28966
29422
|
* A collection of hash-based keys (likely `StateKey`s) which ignores
|
|
28967
29423
|
* differences on the last byte.
|
|
@@ -28974,48 +29430,37 @@ class TruncatedHashDictionary {
|
|
|
28974
29430
|
* Each key will be copied and have the last byte replace with a 0.
|
|
28975
29431
|
*/
|
|
28976
29432
|
static fromEntries(entries) {
|
|
28977
|
-
|
|
28978
|
-
const mapped = Array.from(entries).map(([key, value]) => {
|
|
28979
|
-
const newKey = bytes_Bytes.zero(hash_HASH_SIZE).asOpaque();
|
|
28980
|
-
newKey.raw.set(key.raw.subarray(0, TRUNCATED_HASH_SIZE));
|
|
28981
|
-
return [newKey, value];
|
|
28982
|
-
});
|
|
28983
|
-
return new TruncatedHashDictionary(hash_dictionary_HashDictionary.fromEntries(mapped));
|
|
29433
|
+
return new TruncatedHashDictionary(BlobDictionary.fromEntries(Array.from(entries).map(([key, value]) => [getTruncatedKey(key), value]), truncated_hash_dictionary_BLOB_DICTIONARY_THRESHOLD));
|
|
28984
29434
|
}
|
|
28985
|
-
/** A truncated key which we re-use to query the dictionary. */
|
|
28986
|
-
truncatedKey = bytes_Bytes.zero(hash_HASH_SIZE).asOpaque();
|
|
28987
29435
|
constructor(dict) {
|
|
28988
29436
|
this.dict = dict;
|
|
28989
29437
|
}
|
|
28990
29438
|
[TEST_COMPARE_USING]() {
|
|
28991
|
-
return this.dict;
|
|
29439
|
+
return Array.from(this.dict);
|
|
28992
29440
|
}
|
|
28993
29441
|
/** Return number of items in the dictionary. */
|
|
28994
29442
|
get size() {
|
|
28995
29443
|
return this.dict.size;
|
|
28996
29444
|
}
|
|
28997
29445
|
/** Retrieve a value that matches the key on `TRUNCATED_HASH_SIZE`. */
|
|
28998
|
-
get(
|
|
28999
|
-
|
|
29000
|
-
return this.dict.get(
|
|
29446
|
+
get(key) {
|
|
29447
|
+
const truncatedKey = getTruncatedKey(key);
|
|
29448
|
+
return this.dict.get(truncatedKey);
|
|
29001
29449
|
}
|
|
29002
29450
|
/** Return true if the key is present in the dictionary */
|
|
29003
|
-
has(
|
|
29004
|
-
|
|
29005
|
-
return this.dict.has(
|
|
29451
|
+
has(key) {
|
|
29452
|
+
const truncatedKey = getTruncatedKey(key);
|
|
29453
|
+
return this.dict.has(truncatedKey);
|
|
29006
29454
|
}
|
|
29007
29455
|
/** Set or update a value that matches the key on `TRUNCATED_HASH_SIZE`. */
|
|
29008
|
-
set(
|
|
29009
|
-
|
|
29010
|
-
|
|
29011
|
-
const key = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
29012
|
-
key.raw.set(fullKey.raw.subarray(0, TRUNCATED_HASH_SIZE));
|
|
29013
|
-
this.dict.set(key.asOpaque(), value);
|
|
29456
|
+
set(key, value) {
|
|
29457
|
+
const truncatedKey = getTruncatedKey(key);
|
|
29458
|
+
this.dict.set(truncatedKey, value);
|
|
29014
29459
|
}
|
|
29015
29460
|
/** Remove a value that matches the key on `TRUNCATED_HASH_SIZE`. */
|
|
29016
|
-
delete(
|
|
29017
|
-
|
|
29018
|
-
this.dict.delete(
|
|
29461
|
+
delete(key) {
|
|
29462
|
+
const truncatedKey = getTruncatedKey(key);
|
|
29463
|
+
this.dict.delete(truncatedKey);
|
|
29019
29464
|
}
|
|
29020
29465
|
/** Iterator over values of the dictionary. */
|
|
29021
29466
|
values() {
|
|
@@ -29023,9 +29468,7 @@ class TruncatedHashDictionary {
|
|
|
29023
29468
|
}
|
|
29024
29469
|
/** Iterator over entries of the dictionary (with truncated keys) */
|
|
29025
29470
|
*entries() {
|
|
29026
|
-
|
|
29027
|
-
yield [bytes_Bytes.fromBlob(key.raw.subarray(0, TRUNCATED_HASH_SIZE), TRUNCATED_HASH_SIZE).asOpaque(), value];
|
|
29028
|
-
}
|
|
29471
|
+
yield* this.dict.entries();
|
|
29029
29472
|
}
|
|
29030
29473
|
[Symbol.iterator]() {
|
|
29031
29474
|
return this.entries();
|
|
@@ -29042,6 +29485,7 @@ class TruncatedHashDictionary {
|
|
|
29042
29485
|
|
|
29043
29486
|
|
|
29044
29487
|
|
|
29488
|
+
|
|
29045
29489
|
;// CONCATENATED MODULE: ./packages/jam/block/codec.ts
|
|
29046
29490
|
|
|
29047
29491
|
|
|
@@ -31185,7 +31629,7 @@ function jip_chain_spec_parseBootnode(v) {
|
|
|
31185
31629
|
if (name === "" || ip === "" || port === "") {
|
|
31186
31630
|
throw new Error(`Invalid bootnode format, expected: <name>@<ip>:<port>, got: "${v}"`);
|
|
31187
31631
|
}
|
|
31188
|
-
const portNumber = Number.parseInt(port);
|
|
31632
|
+
const portNumber = Number.parseInt(port, 10);
|
|
31189
31633
|
if (!isU16(portNumber)) {
|
|
31190
31634
|
throw new Error(`Invalid port number: "${port}"`);
|
|
31191
31635
|
}
|
|
@@ -34210,11 +34654,32 @@ const ENTROPY_ENTRIES = 4;
|
|
|
34210
34654
|
|
|
34211
34655
|
var UpdatePreimageKind;
|
|
34212
34656
|
(function (UpdatePreimageKind) {
|
|
34213
|
-
/**
|
|
34657
|
+
/**
|
|
34658
|
+
* Insert new preimage and optionally update it's lookup history.
|
|
34659
|
+
*
|
|
34660
|
+
* Used in: `provide`
|
|
34661
|
+
*
|
|
34662
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/383904383904?v=0.7.2
|
|
34663
|
+
*/
|
|
34214
34664
|
UpdatePreimageKind[UpdatePreimageKind["Provide"] = 0] = "Provide";
|
|
34215
|
-
/**
|
|
34665
|
+
/**
|
|
34666
|
+
* Remove a preimage and it's lookup history.
|
|
34667
|
+
*
|
|
34668
|
+
* Used in: `forget` and `eject`
|
|
34669
|
+
*
|
|
34670
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/38c701380202?v=0.7.2
|
|
34671
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/379102379302?v=0.7.2
|
|
34672
|
+
*/
|
|
34216
34673
|
UpdatePreimageKind[UpdatePreimageKind["Remove"] = 1] = "Remove";
|
|
34217
|
-
/**
|
|
34674
|
+
/**
|
|
34675
|
+
* Update or add lookup history for preimage hash/len to given value.
|
|
34676
|
+
*
|
|
34677
|
+
* Used in: `solicit` and `forget`
|
|
34678
|
+
*
|
|
34679
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/382802382802?v=0.7.2
|
|
34680
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/384002384b02?v=0.7.2
|
|
34681
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/38c60038ea00?v=0.7.2
|
|
34682
|
+
*/
|
|
34218
34683
|
UpdatePreimageKind[UpdatePreimageKind["UpdateOrAdd"] = 2] = "UpdateOrAdd";
|
|
34219
34684
|
})(UpdatePreimageKind || (UpdatePreimageKind = {}));
|
|
34220
34685
|
/**
|
|
@@ -34222,7 +34687,7 @@ var UpdatePreimageKind;
|
|
|
34222
34687
|
*
|
|
34223
34688
|
* Can be one of the following cases:
|
|
34224
34689
|
* 1. Provide a new preimage blob and set the lookup history to available at `slot`.
|
|
34225
|
-
* 2. Remove (
|
|
34690
|
+
* 2. Remove (forget) a preimage and it's lookup history.
|
|
34226
34691
|
* 3. Update `LookupHistory` with given value.
|
|
34227
34692
|
*/
|
|
34228
34693
|
class UpdatePreimage {
|
|
@@ -35445,7 +35910,6 @@ class LeafNode {
|
|
|
35445
35910
|
/**
|
|
35446
35911
|
* Get the byte length of embedded value.
|
|
35447
35912
|
*
|
|
35448
|
-
* @remark
|
|
35449
35913
|
* Note in case this node only contains hash this is going to be 0.
|
|
35450
35914
|
*/
|
|
35451
35915
|
getValueLength() {
|
|
@@ -35456,7 +35920,6 @@ class LeafNode {
|
|
|
35456
35920
|
/**
|
|
35457
35921
|
* Returns the embedded value.
|
|
35458
35922
|
*
|
|
35459
|
-
* @remark
|
|
35460
35923
|
* Note that this is going to be empty for a regular leaf node (i.e. containing a hash).
|
|
35461
35924
|
*/
|
|
35462
35925
|
getValue() {
|
|
@@ -35466,7 +35929,6 @@ class LeafNode {
|
|
|
35466
35929
|
/**
|
|
35467
35930
|
* Returns contained value hash.
|
|
35468
35931
|
*
|
|
35469
|
-
* @remark
|
|
35470
35932
|
* Note that for embedded value this is going to be full 0-padded 32 bytes.
|
|
35471
35933
|
*/
|
|
35472
35934
|
getValueHash() {
|
|
@@ -37588,11 +38050,9 @@ class JamConfig {
|
|
|
37588
38050
|
|
|
37589
38051
|
/** Helper function to create most used hashes in the block */
|
|
37590
38052
|
class hasher_TransitionHasher {
|
|
37591
|
-
context;
|
|
37592
38053
|
keccakHasher;
|
|
37593
38054
|
blake2b;
|
|
37594
|
-
constructor(
|
|
37595
|
-
this.context = context;
|
|
38055
|
+
constructor(keccakHasher, blake2b) {
|
|
37596
38056
|
this.keccakHasher = keccakHasher;
|
|
37597
38057
|
this.blake2b = blake2b;
|
|
37598
38058
|
}
|
|
@@ -37726,7 +38186,7 @@ class BlockVerifier {
|
|
|
37726
38186
|
this.hasher = hasher;
|
|
37727
38187
|
this.blocks = blocks;
|
|
37728
38188
|
}
|
|
37729
|
-
async verifyBlock(block) {
|
|
38189
|
+
async verifyBlock(block, options = { skipParentAndStateRoot: false }) {
|
|
37730
38190
|
const headerView = block.header.view();
|
|
37731
38191
|
const headerHash = this.hasher.header(headerView);
|
|
37732
38192
|
// check if current block is already imported
|
|
@@ -37738,7 +38198,7 @@ class BlockVerifier {
|
|
|
37738
38198
|
// https://graypaper.fluffylabs.dev/#/cc517d7/0c9d000c9d00?v=0.6.5
|
|
37739
38199
|
const parentHash = headerView.parentHeaderHash.materialize();
|
|
37740
38200
|
// importing genesis block
|
|
37741
|
-
if (!parentHash.isEqualTo(block_verifier_ZERO_HASH)) {
|
|
38201
|
+
if (!parentHash.isEqualTo(block_verifier_ZERO_HASH) && !options.skipParentAndStateRoot) {
|
|
37742
38202
|
const parentBlock = this.blocks.getHeader(parentHash);
|
|
37743
38203
|
if (parentBlock === null) {
|
|
37744
38204
|
return result_Result.error(BlockVerifierError.ParentNotFound, () => `Parent ${parentHash.toString()} not found`);
|
|
@@ -37758,21 +38218,20 @@ class BlockVerifier {
|
|
|
37758
38218
|
if (!extrinsicHash.isEqualTo(extrinsicMerkleCommitment.hash)) {
|
|
37759
38219
|
return result_Result.error(BlockVerifierError.InvalidExtrinsic, () => `Invalid extrinsic hash: ${extrinsicHash.toString()}, expected ${extrinsicMerkleCommitment.hash.toString()}`);
|
|
37760
38220
|
}
|
|
37761
|
-
|
|
37762
|
-
|
|
37763
|
-
|
|
37764
|
-
|
|
37765
|
-
|
|
37766
|
-
|
|
37767
|
-
|
|
37768
|
-
|
|
37769
|
-
|
|
38221
|
+
if (!options.skipParentAndStateRoot) {
|
|
38222
|
+
// Check if the state root is valid.
|
|
38223
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/0c73010c7301?v=0.7.2
|
|
38224
|
+
const stateRoot = headerView.priorStateRoot.materialize();
|
|
38225
|
+
const posteriorStateRoot = this.blocks.getPostStateRoot(parentHash);
|
|
38226
|
+
if (posteriorStateRoot === null) {
|
|
38227
|
+
return result_Result.error(BlockVerifierError.StateRootNotFound, () => `Posterior state root ${parentHash.toString()} not found`);
|
|
38228
|
+
}
|
|
38229
|
+
if (!stateRoot.isEqualTo(posteriorStateRoot)) {
|
|
38230
|
+
return result_Result.error(BlockVerifierError.InvalidStateRoot, () => `Invalid prior state root: ${stateRoot.toString()}, expected ${posteriorStateRoot.toString()} (ours)`);
|
|
38231
|
+
}
|
|
37770
38232
|
}
|
|
37771
38233
|
return result_Result.ok(headerHash.hash);
|
|
37772
38234
|
}
|
|
37773
|
-
hashHeader(block) {
|
|
37774
|
-
return this.hasher.header(block.header.view());
|
|
37775
|
-
}
|
|
37776
38235
|
}
|
|
37777
38236
|
|
|
37778
38237
|
;// CONCATENATED MODULE: ./packages/jam/transition/disputes/disputes-error-code.ts
|
|
@@ -39016,7 +39475,11 @@ class PartiallyUpdatedState {
|
|
|
39016
39475
|
const service = this.state.getService(serviceId);
|
|
39017
39476
|
return service?.getPreimage(hash) ?? null;
|
|
39018
39477
|
}
|
|
39019
|
-
/**
|
|
39478
|
+
/**
|
|
39479
|
+
* Get status of a preimage of current service taking into account any updates.
|
|
39480
|
+
*
|
|
39481
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/110201110201?v=0.7.2
|
|
39482
|
+
*/
|
|
39020
39483
|
getLookupHistory(currentTimeslot, serviceId, hash, length) {
|
|
39021
39484
|
const updatedService = this.stateUpdate.services.updated.get(serviceId);
|
|
39022
39485
|
/** Return lookup history item for newly created service */
|
|
@@ -39053,12 +39516,7 @@ class PartiallyUpdatedState {
|
|
|
39053
39516
|
return new LookupHistoryItem(hash, updatedPreimage.length, tryAsLookupHistorySlots([currentTimeslot]));
|
|
39054
39517
|
}
|
|
39055
39518
|
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]));
|
|
39519
|
+
return null;
|
|
39062
39520
|
}
|
|
39063
39521
|
case UpdatePreimageKind.UpdateOrAdd: {
|
|
39064
39522
|
return action.item;
|
|
@@ -39151,7 +39609,7 @@ const gas_tryAsSmallGas = (v) => opaque_asOpaqueType(numbers_tryAsU32(v));
|
|
|
39151
39609
|
/** Attempt to convert given number into U64 gas representation. */
|
|
39152
39610
|
const tryAsBigGas = (v) => opaque_asOpaqueType(numbers_tryAsU64(v));
|
|
39153
39611
|
/** Attempt to convert given number into gas. */
|
|
39154
|
-
const
|
|
39612
|
+
const gas_tryAsGas = (v) => typeof v === "number" && v < 2 ** 32 ? gas_tryAsSmallGas(v) : tryAsBigGas(v);
|
|
39155
39613
|
|
|
39156
39614
|
;// CONCATENATED MODULE: ./packages/core/pvm-interface/memory.ts
|
|
39157
39615
|
|
|
@@ -39434,7 +39892,7 @@ const tryAsRegisterIndex = (index) => {
|
|
|
39434
39892
|
debug_check `${index >= 0 && index < registers_NO_OF_REGISTERS} Incorrect register index: ${index}!`;
|
|
39435
39893
|
return opaque_asOpaqueType(index);
|
|
39436
39894
|
};
|
|
39437
|
-
class
|
|
39895
|
+
class registers_Registers {
|
|
39438
39896
|
bytes;
|
|
39439
39897
|
asSigned;
|
|
39440
39898
|
asUnsigned;
|
|
@@ -39453,7 +39911,7 @@ class Registers {
|
|
|
39453
39911
|
}
|
|
39454
39912
|
static fromBytes(bytes) {
|
|
39455
39913
|
debug_check `${bytes.length === registers_NO_OF_REGISTERS << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
|
|
39456
|
-
return new
|
|
39914
|
+
return new registers_Registers(bytes);
|
|
39457
39915
|
}
|
|
39458
39916
|
getBytesAsLittleEndian(index, len) {
|
|
39459
39917
|
const offset = index << REGISTER_SIZE_SHIFT;
|
|
@@ -39767,49 +40225,10 @@ class NoopMissing {
|
|
|
39767
40225
|
}
|
|
39768
40226
|
}
|
|
39769
40227
|
|
|
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
40228
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/memory-index.ts
|
|
39810
40229
|
|
|
39811
40230
|
|
|
39812
|
-
const
|
|
40231
|
+
const memory_index_tryAsMemoryIndex = (index) => {
|
|
39813
40232
|
debug_check `${index >= 0 && index <= MAX_MEMORY_INDEX} Incorrect memory index: ${index}!`;
|
|
39814
40233
|
return opaque_asOpaqueType(index);
|
|
39815
40234
|
};
|
|
@@ -39823,25 +40242,25 @@ const tryAsSbrkIndex = (index) => {
|
|
|
39823
40242
|
|
|
39824
40243
|
const memory_consts_PAGE_SIZE_SHIFT = 12;
|
|
39825
40244
|
// PAGE_SIZE has to be a power of 2
|
|
39826
|
-
const
|
|
40245
|
+
const memory_consts_PAGE_SIZE = 1 << memory_consts_PAGE_SIZE_SHIFT;
|
|
39827
40246
|
const MIN_ALLOCATION_SHIFT = (() => {
|
|
39828
40247
|
const MIN_ALLOCATION_SHIFT = 7;
|
|
39829
40248
|
debug_check `${MIN_ALLOCATION_SHIFT >= 0 && MIN_ALLOCATION_SHIFT < memory_consts_PAGE_SIZE_SHIFT} incorrect minimal allocation shift`;
|
|
39830
40249
|
return MIN_ALLOCATION_SHIFT;
|
|
39831
40250
|
})();
|
|
39832
|
-
const MIN_ALLOCATION_LENGTH =
|
|
39833
|
-
const LAST_PAGE_NUMBER = (MEMORY_SIZE -
|
|
40251
|
+
const MIN_ALLOCATION_LENGTH = memory_consts_PAGE_SIZE >> MIN_ALLOCATION_SHIFT;
|
|
40252
|
+
const LAST_PAGE_NUMBER = (MEMORY_SIZE - memory_consts_PAGE_SIZE) / memory_consts_PAGE_SIZE;
|
|
39834
40253
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/35a60235a602?v=0.6.4 */
|
|
39835
40254
|
const RESERVED_NUMBER_OF_PAGES = 16;
|
|
39836
40255
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/35a60235a602?v=0.6.4 */
|
|
39837
|
-
const MAX_NUMBER_OF_PAGES = MEMORY_SIZE /
|
|
40256
|
+
const MAX_NUMBER_OF_PAGES = MEMORY_SIZE / memory_consts_PAGE_SIZE;
|
|
39838
40257
|
|
|
39839
40258
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/pages/page-utils.ts
|
|
39840
40259
|
|
|
39841
40260
|
|
|
39842
40261
|
/** Ensure that given memory `index` is within `[0...PAGE_SIZE)` and can be used to index a page */
|
|
39843
40262
|
const tryAsPageIndex = (index) => {
|
|
39844
|
-
debug_check `${index >= 0 && index <
|
|
40263
|
+
debug_check `${index >= 0 && index < memory_consts_PAGE_SIZE}, Incorect page index: ${index}!`;
|
|
39845
40264
|
return opaque_asOpaqueType(index);
|
|
39846
40265
|
};
|
|
39847
40266
|
/** Ensure that given `index` represents an index of one of the pages. */
|
|
@@ -39869,17 +40288,17 @@ function getNextPageNumber(pageNumber) {
|
|
|
39869
40288
|
|
|
39870
40289
|
|
|
39871
40290
|
function alignToPageSize(length) {
|
|
39872
|
-
return
|
|
40291
|
+
return memory_consts_PAGE_SIZE * Math.ceil(length / memory_consts_PAGE_SIZE);
|
|
39873
40292
|
}
|
|
39874
40293
|
function getPageNumber(address) {
|
|
39875
40294
|
return tryAsPageNumber(address >>> memory_consts_PAGE_SIZE_SHIFT);
|
|
39876
40295
|
}
|
|
39877
40296
|
function getStartPageIndex(address) {
|
|
39878
|
-
return
|
|
40297
|
+
return memory_index_tryAsMemoryIndex((address >>> memory_consts_PAGE_SIZE_SHIFT) << memory_consts_PAGE_SIZE_SHIFT);
|
|
39879
40298
|
}
|
|
39880
40299
|
function getStartPageIndexFromPageNumber(pageNumber) {
|
|
39881
40300
|
// >>> 0 is needed to avoid changing sign of the number
|
|
39882
|
-
return
|
|
40301
|
+
return memory_index_tryAsMemoryIndex((pageNumber << memory_consts_PAGE_SIZE_SHIFT) >>> 0);
|
|
39883
40302
|
}
|
|
39884
40303
|
|
|
39885
40304
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/errors.ts
|
|
@@ -39901,7 +40320,7 @@ class PageFault {
|
|
|
39901
40320
|
return new PageFault(numbers_tryAsU32(startPageIndex), isAccessFault);
|
|
39902
40321
|
}
|
|
39903
40322
|
static fromMemoryIndex(maybeMemoryIndex, isAccessFault = false) {
|
|
39904
|
-
const memoryIndex =
|
|
40323
|
+
const memoryIndex = memory_index_tryAsMemoryIndex(maybeMemoryIndex % MEMORY_SIZE);
|
|
39905
40324
|
const startPageIndex = getStartPageIndex(memoryIndex);
|
|
39906
40325
|
return new PageFault(numbers_tryAsU32(startPageIndex), isAccessFault);
|
|
39907
40326
|
}
|
|
@@ -39980,9 +40399,9 @@ class MemoryRange {
|
|
|
39980
40399
|
constructor(start, length) {
|
|
39981
40400
|
this.start = start;
|
|
39982
40401
|
this.length = length;
|
|
39983
|
-
this.end =
|
|
40402
|
+
this.end = memory_index_tryAsMemoryIndex((this.start + this.length) % MEMORY_SIZE);
|
|
39984
40403
|
if (length > 0) {
|
|
39985
|
-
this.lastIndex =
|
|
40404
|
+
this.lastIndex = memory_index_tryAsMemoryIndex((this.end - 1 + MEMORY_SIZE) % MEMORY_SIZE);
|
|
39986
40405
|
}
|
|
39987
40406
|
}
|
|
39988
40407
|
/** Creates a memory range from given starting point and length */
|
|
@@ -40025,7 +40444,7 @@ class MemoryRange {
|
|
|
40025
40444
|
*
|
|
40026
40445
|
* it should be in `memory-consts` but it cannot be there because of circular dependency
|
|
40027
40446
|
*/
|
|
40028
|
-
const RESERVED_MEMORY_RANGE = MemoryRange.fromStartAndLength(
|
|
40447
|
+
const RESERVED_MEMORY_RANGE = MemoryRange.fromStartAndLength(memory_index_tryAsMemoryIndex(0), RESERVED_NUMBER_OF_PAGES * memory_consts_PAGE_SIZE);
|
|
40029
40448
|
|
|
40030
40449
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/page-range.ts
|
|
40031
40450
|
|
|
@@ -40063,7 +40482,7 @@ class PageRange {
|
|
|
40063
40482
|
// lastIndex is not null because we just ensured that the range is not empty
|
|
40064
40483
|
const pageWithLastIndex = getPageNumber(range.lastIndex ?? range.end);
|
|
40065
40484
|
const endPage = getNextPageNumber(pageWithLastIndex);
|
|
40066
|
-
if ((startPage === endPage || startPage === pageWithLastIndex) && range.length >
|
|
40485
|
+
if ((startPage === endPage || startPage === pageWithLastIndex) && range.length > memory_consts_PAGE_SIZE) {
|
|
40067
40486
|
// full range
|
|
40068
40487
|
return new PageRange(startPage, MAX_NUMBER_OF_PAGES);
|
|
40069
40488
|
}
|
|
@@ -40127,8 +40546,8 @@ class ReadablePage extends MemoryPage {
|
|
|
40127
40546
|
}
|
|
40128
40547
|
loadInto(result, startIndex, length) {
|
|
40129
40548
|
const endIndex = startIndex + length;
|
|
40130
|
-
if (endIndex >
|
|
40131
|
-
return result_Result.error(PageFault.fromMemoryIndex(this.start +
|
|
40549
|
+
if (endIndex > memory_consts_PAGE_SIZE) {
|
|
40550
|
+
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
40551
|
}
|
|
40133
40552
|
const bytes = this.data.subarray(startIndex, endIndex);
|
|
40134
40553
|
// we zero the bytes, since data might not yet be initialized at `endIndex`.
|
|
@@ -40161,8 +40580,8 @@ class WriteablePage extends MemoryPage {
|
|
|
40161
40580
|
constructor(pageNumber, initialData) {
|
|
40162
40581
|
super(pageNumber);
|
|
40163
40582
|
const dataLength = initialData?.length ?? 0;
|
|
40164
|
-
const initialPageLength = Math.min(
|
|
40165
|
-
this.buffer = new ArrayBuffer(initialPageLength, { maxByteLength:
|
|
40583
|
+
const initialPageLength = Math.min(memory_consts_PAGE_SIZE, Math.max(dataLength, MIN_ALLOCATION_LENGTH));
|
|
40584
|
+
this.buffer = new ArrayBuffer(initialPageLength, { maxByteLength: memory_consts_PAGE_SIZE });
|
|
40166
40585
|
this.view = new Uint8Array(this.buffer);
|
|
40167
40586
|
if (initialData !== undefined) {
|
|
40168
40587
|
this.view.set(initialData);
|
|
@@ -40170,8 +40589,8 @@ class WriteablePage extends MemoryPage {
|
|
|
40170
40589
|
}
|
|
40171
40590
|
loadInto(result, startIndex, length) {
|
|
40172
40591
|
const endIndex = startIndex + length;
|
|
40173
|
-
if (endIndex >
|
|
40174
|
-
return result_Result.error(PageFault.fromMemoryIndex(this.start +
|
|
40592
|
+
if (endIndex > memory_consts_PAGE_SIZE) {
|
|
40593
|
+
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
40594
|
}
|
|
40176
40595
|
const bytes = this.view.subarray(startIndex, endIndex);
|
|
40177
40596
|
// we zero the bytes, since the view might not yet be initialized at `endIndex`.
|
|
@@ -40180,16 +40599,16 @@ class WriteablePage extends MemoryPage {
|
|
|
40180
40599
|
return result_Result.ok(result_OK);
|
|
40181
40600
|
}
|
|
40182
40601
|
storeFrom(startIndex, bytes) {
|
|
40183
|
-
if (this.buffer.byteLength < startIndex + bytes.length && this.buffer.byteLength <
|
|
40184
|
-
const newLength = Math.min(
|
|
40602
|
+
if (this.buffer.byteLength < startIndex + bytes.length && this.buffer.byteLength < memory_consts_PAGE_SIZE) {
|
|
40603
|
+
const newLength = Math.min(memory_consts_PAGE_SIZE, Math.max(MIN_ALLOCATION_LENGTH, startIndex + bytes.length));
|
|
40185
40604
|
this.buffer.resize(newLength);
|
|
40186
40605
|
}
|
|
40187
40606
|
this.view.set(bytes, startIndex);
|
|
40188
40607
|
return result_Result.ok(result_OK);
|
|
40189
40608
|
}
|
|
40190
40609
|
setData(pageIndex, data) {
|
|
40191
|
-
if (this.buffer.byteLength < pageIndex + data.length && this.buffer.byteLength <
|
|
40192
|
-
const newLength = Math.min(
|
|
40610
|
+
if (this.buffer.byteLength < pageIndex + data.length && this.buffer.byteLength < memory_consts_PAGE_SIZE) {
|
|
40611
|
+
const newLength = Math.min(memory_consts_PAGE_SIZE, Math.max(MIN_ALLOCATION_LENGTH, pageIndex + data.length));
|
|
40193
40612
|
this.buffer.resize(newLength);
|
|
40194
40613
|
}
|
|
40195
40614
|
this.view.set(data, pageIndex);
|
|
@@ -40240,10 +40659,10 @@ class Memory {
|
|
|
40240
40659
|
this.memory = memory;
|
|
40241
40660
|
}
|
|
40242
40661
|
store(address, bytes) {
|
|
40243
|
-
return this.storeFrom(
|
|
40662
|
+
return this.storeFrom(memory_index_tryAsMemoryIndex(address), bytes);
|
|
40244
40663
|
}
|
|
40245
40664
|
read(address, output) {
|
|
40246
|
-
return this.loadInto(output,
|
|
40665
|
+
return this.loadInto(output, memory_index_tryAsMemoryIndex(address));
|
|
40247
40666
|
}
|
|
40248
40667
|
reset() {
|
|
40249
40668
|
this.sbrkIndex = tryAsSbrkIndex(RESERVED_MEMORY_RANGE.end);
|
|
@@ -40270,8 +40689,8 @@ class Memory {
|
|
|
40270
40689
|
let currentPosition = address;
|
|
40271
40690
|
let bytesLeft = bytes.length;
|
|
40272
40691
|
for (const page of pages) {
|
|
40273
|
-
const pageStartIndex = tryAsPageIndex(currentPosition %
|
|
40274
|
-
const bytesToWrite = Math.min(
|
|
40692
|
+
const pageStartIndex = tryAsPageIndex(currentPosition % memory_consts_PAGE_SIZE);
|
|
40693
|
+
const bytesToWrite = Math.min(memory_consts_PAGE_SIZE - pageStartIndex, bytesLeft);
|
|
40275
40694
|
const sourceStartIndex = currentPosition - address;
|
|
40276
40695
|
const source = bytes.subarray(sourceStartIndex, sourceStartIndex + bytesToWrite);
|
|
40277
40696
|
page.storeFrom(pageStartIndex, source);
|
|
@@ -40320,8 +40739,8 @@ class Memory {
|
|
|
40320
40739
|
let currentPosition = startAddress;
|
|
40321
40740
|
let bytesLeft = result.length;
|
|
40322
40741
|
for (const page of pages) {
|
|
40323
|
-
const pageStartIndex = tryAsPageIndex(currentPosition %
|
|
40324
|
-
const bytesToRead = Math.min(
|
|
40742
|
+
const pageStartIndex = tryAsPageIndex(currentPosition % memory_consts_PAGE_SIZE);
|
|
40743
|
+
const bytesToRead = Math.min(memory_consts_PAGE_SIZE - pageStartIndex, bytesLeft);
|
|
40325
40744
|
const destinationStartIndex = currentPosition - startAddress;
|
|
40326
40745
|
const destination = result.subarray(destinationStartIndex);
|
|
40327
40746
|
page.loadInto(destination, pageStartIndex, bytesToRead);
|
|
@@ -40348,7 +40767,7 @@ class Memory {
|
|
|
40348
40767
|
const newSbrkIndex = tryAsSbrkIndex(alignToPageSize(newVirtualSbrkIndex));
|
|
40349
40768
|
// TODO [MaSi]: `getPageNumber` works incorrectly for SbrkIndex. Sbrk index should be changed to MemoryIndex
|
|
40350
40769
|
const firstPageNumber = getPageNumber(currentSbrkIndex);
|
|
40351
|
-
const pagesToAllocate = (newSbrkIndex - currentSbrkIndex) /
|
|
40770
|
+
const pagesToAllocate = (newSbrkIndex - currentSbrkIndex) / memory_consts_PAGE_SIZE;
|
|
40352
40771
|
const rangeToAllocate = PageRange.fromStartAndLength(firstPageNumber, pagesToAllocate);
|
|
40353
40772
|
for (const pageNumber of rangeToAllocate) {
|
|
40354
40773
|
const page = new WriteablePage(pageNumber);
|
|
@@ -40403,8 +40822,8 @@ class MemoryBuilder {
|
|
|
40403
40822
|
setReadablePages(start, end, data = new Uint8Array()) {
|
|
40404
40823
|
this.ensureNotFinalized();
|
|
40405
40824
|
debug_check `${start < end} end has to be bigger than start`;
|
|
40406
|
-
debug_check `${start %
|
|
40407
|
-
debug_check `${end %
|
|
40825
|
+
debug_check `${start % memory_consts_PAGE_SIZE === 0} start needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
|
|
40826
|
+
debug_check `${end % memory_consts_PAGE_SIZE === 0} end needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
|
|
40408
40827
|
debug_check `${data.length <= end - start} the initial data is longer than address range`;
|
|
40409
40828
|
const length = end - start;
|
|
40410
40829
|
const range = MemoryRange.fromStartAndLength(start, length);
|
|
@@ -40413,7 +40832,7 @@ class MemoryBuilder {
|
|
|
40413
40832
|
const noOfPages = pages.length;
|
|
40414
40833
|
for (let i = 0; i < noOfPages; i++) {
|
|
40415
40834
|
const pageNumber = pages[i];
|
|
40416
|
-
const dataChunk = data.subarray(i *
|
|
40835
|
+
const dataChunk = data.subarray(i * memory_consts_PAGE_SIZE, (i + 1) * memory_consts_PAGE_SIZE);
|
|
40417
40836
|
const page = new ReadablePage(pageNumber, dataChunk);
|
|
40418
40837
|
this.initialMemory.set(pageNumber, page);
|
|
40419
40838
|
}
|
|
@@ -40431,8 +40850,8 @@ class MemoryBuilder {
|
|
|
40431
40850
|
setWriteablePages(start, end, data = new Uint8Array()) {
|
|
40432
40851
|
this.ensureNotFinalized();
|
|
40433
40852
|
debug_check `${start < end} end has to be bigger than start`;
|
|
40434
|
-
debug_check `${start %
|
|
40435
|
-
debug_check `${end %
|
|
40853
|
+
debug_check `${start % memory_consts_PAGE_SIZE === 0} start needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
|
|
40854
|
+
debug_check `${end % memory_consts_PAGE_SIZE === 0} end needs to be a multiple of page size (${memory_consts_PAGE_SIZE})`;
|
|
40436
40855
|
debug_check `${data.length <= end - start} the initial data is longer than address range`;
|
|
40437
40856
|
const length = end - start;
|
|
40438
40857
|
const range = MemoryRange.fromStartAndLength(start, length);
|
|
@@ -40441,7 +40860,7 @@ class MemoryBuilder {
|
|
|
40441
40860
|
const noOfPages = pages.length;
|
|
40442
40861
|
for (let i = 0; i < noOfPages; i++) {
|
|
40443
40862
|
const pageNumber = pages[i];
|
|
40444
|
-
const dataChunk = data.subarray(i *
|
|
40863
|
+
const dataChunk = data.subarray(i * memory_consts_PAGE_SIZE, (i + 1) * memory_consts_PAGE_SIZE);
|
|
40445
40864
|
const page = new WriteablePage(pageNumber, dataChunk);
|
|
40446
40865
|
this.initialMemory.set(pageNumber, page);
|
|
40447
40866
|
}
|
|
@@ -40453,8 +40872,8 @@ class MemoryBuilder {
|
|
|
40453
40872
|
*/
|
|
40454
40873
|
setData(start, data) {
|
|
40455
40874
|
this.ensureNotFinalized();
|
|
40456
|
-
const pageOffset = start %
|
|
40457
|
-
const remainingSpaceOnPage =
|
|
40875
|
+
const pageOffset = start % memory_consts_PAGE_SIZE;
|
|
40876
|
+
const remainingSpaceOnPage = memory_consts_PAGE_SIZE - pageOffset;
|
|
40458
40877
|
debug_check `${data.length <= remainingSpaceOnPage} The data has to fit into a single page.`;
|
|
40459
40878
|
const length = data.length;
|
|
40460
40879
|
const range = MemoryRange.fromStartAndLength(start, length);
|
|
@@ -40645,27 +41064,27 @@ class Program {
|
|
|
40645
41064
|
static fromSpi(blob, args, hasMetadata) {
|
|
40646
41065
|
const { code: spiCode, metadata } = hasMetadata ? extractCodeAndMetadata(blob) : { code: blob };
|
|
40647
41066
|
const { code, memory: rawMemory, registers } = decodeStandardProgram(spiCode, args);
|
|
40648
|
-
const regs = new
|
|
41067
|
+
const regs = new registers_Registers();
|
|
40649
41068
|
regs.copyFrom(registers);
|
|
40650
41069
|
const memoryBuilder = new MemoryBuilder();
|
|
40651
41070
|
for (const { start, end, data } of rawMemory.readable) {
|
|
40652
|
-
const startIndex =
|
|
40653
|
-
const endIndex =
|
|
41071
|
+
const startIndex = memory_index_tryAsMemoryIndex(start);
|
|
41072
|
+
const endIndex = memory_index_tryAsMemoryIndex(end);
|
|
40654
41073
|
memoryBuilder.setReadablePages(startIndex, endIndex, data ?? new Uint8Array());
|
|
40655
41074
|
}
|
|
40656
41075
|
for (const { start, end, data } of rawMemory.writeable) {
|
|
40657
|
-
const startIndex =
|
|
40658
|
-
const endIndex =
|
|
41076
|
+
const startIndex = memory_index_tryAsMemoryIndex(start);
|
|
41077
|
+
const endIndex = memory_index_tryAsMemoryIndex(end);
|
|
40659
41078
|
memoryBuilder.setWriteablePages(startIndex, endIndex, data ?? new Uint8Array());
|
|
40660
41079
|
}
|
|
40661
|
-
const heapStart =
|
|
41080
|
+
const heapStart = memory_index_tryAsMemoryIndex(rawMemory.sbrkIndex);
|
|
40662
41081
|
const heapEnd = tryAsSbrkIndex(rawMemory.heapEnd);
|
|
40663
41082
|
const memory = memoryBuilder.finalize(heapStart, heapEnd);
|
|
40664
41083
|
return new Program(code, regs, memory, metadata);
|
|
40665
41084
|
}
|
|
40666
41085
|
static fromGeneric(blob, hasMetadata) {
|
|
40667
41086
|
const { code, metadata } = hasMetadata ? extractCodeAndMetadata(blob) : { code: blob };
|
|
40668
|
-
const regs = new
|
|
41087
|
+
const regs = new registers_Registers();
|
|
40669
41088
|
const memory = new Memory();
|
|
40670
41089
|
return new Program(code, regs, memory, metadata);
|
|
40671
41090
|
}
|
|
@@ -41680,6 +42099,45 @@ class BasicBlocks {
|
|
|
41680
42099
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/basic-blocks/index.ts
|
|
41681
42100
|
|
|
41682
42101
|
|
|
42102
|
+
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/gas.ts
|
|
42103
|
+
|
|
42104
|
+
|
|
42105
|
+
/** Create a new gas counter instance depending on the gas value. */
|
|
42106
|
+
function gasCounter(gas) {
|
|
42107
|
+
return new GasCounterU64(numbers_tryAsU64(gas));
|
|
42108
|
+
}
|
|
42109
|
+
class GasCounterU64 {
|
|
42110
|
+
gas;
|
|
42111
|
+
initialGas;
|
|
42112
|
+
constructor(gas) {
|
|
42113
|
+
this.gas = gas;
|
|
42114
|
+
this.initialGas = gas_tryAsGas(gas);
|
|
42115
|
+
}
|
|
42116
|
+
set(g) {
|
|
42117
|
+
this.gas = numbers_tryAsU64(g);
|
|
42118
|
+
}
|
|
42119
|
+
get() {
|
|
42120
|
+
return gas_tryAsGas(this.gas);
|
|
42121
|
+
}
|
|
42122
|
+
sub(g) {
|
|
42123
|
+
const result = this.gas - numbers_tryAsU64(g);
|
|
42124
|
+
if (result >= 0n) {
|
|
42125
|
+
this.gas = numbers_tryAsU64(result);
|
|
42126
|
+
return false;
|
|
42127
|
+
}
|
|
42128
|
+
this.gas = numbers_tryAsU64(0n);
|
|
42129
|
+
return true;
|
|
42130
|
+
}
|
|
42131
|
+
used() {
|
|
42132
|
+
const gasConsumed = numbers_tryAsU64(this.initialGas) - this.gas;
|
|
42133
|
+
// In we have less than zero left we assume that all gas has been consumed.
|
|
42134
|
+
if (gasConsumed < 0) {
|
|
42135
|
+
return this.initialGas;
|
|
42136
|
+
}
|
|
42137
|
+
return gas_tryAsGas(gasConsumed);
|
|
42138
|
+
}
|
|
42139
|
+
}
|
|
42140
|
+
|
|
41683
42141
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/instruction-gas-map.ts
|
|
41684
42142
|
|
|
41685
42143
|
|
|
@@ -42256,7 +42714,7 @@ class LoadOps {
|
|
|
42256
42714
|
}
|
|
42257
42715
|
loadNumber(address, registerIndex, numberLength) {
|
|
42258
42716
|
const registerBytes = this.regs.getBytesAsLittleEndian(registerIndex, REG_SIZE_BYTES);
|
|
42259
|
-
const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength),
|
|
42717
|
+
const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength), memory_index_tryAsMemoryIndex(address));
|
|
42260
42718
|
if (loadResult.isError) {
|
|
42261
42719
|
if (loadResult.error.isAccessFault) {
|
|
42262
42720
|
this.instructionResult.status = pvm_interpreter_result_Result.FAULT_ACCESS;
|
|
@@ -42272,7 +42730,7 @@ class LoadOps {
|
|
|
42272
42730
|
loadSignedNumber(address, registerIndex, numberLength) {
|
|
42273
42731
|
// load all bytes from register to correctly handle the sign.
|
|
42274
42732
|
const registerBytes = this.regs.getBytesAsLittleEndian(registerIndex, REG_SIZE_BYTES);
|
|
42275
|
-
const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength),
|
|
42733
|
+
const loadResult = this.memory.loadInto(registerBytes.subarray(0, numberLength), memory_index_tryAsMemoryIndex(address));
|
|
42276
42734
|
if (loadResult.isError) {
|
|
42277
42735
|
if (loadResult.error.isAccessFault) {
|
|
42278
42736
|
this.instructionResult.status = pvm_interpreter_result_Result.FAULT_ACCESS;
|
|
@@ -42694,7 +43152,7 @@ class StoreOps {
|
|
|
42694
43152
|
this.store(address, secondImmediateDecoder.getExtendedBytesAsLittleEndian());
|
|
42695
43153
|
}
|
|
42696
43154
|
store(address, bytes) {
|
|
42697
|
-
const storeResult = this.memory.storeFrom(
|
|
43155
|
+
const storeResult = this.memory.storeFrom(memory_index_tryAsMemoryIndex(address), bytes);
|
|
42698
43156
|
if (storeResult.isOk) {
|
|
42699
43157
|
return;
|
|
42700
43158
|
}
|
|
@@ -42703,7 +43161,7 @@ class StoreOps {
|
|
|
42703
43161
|
}
|
|
42704
43162
|
else {
|
|
42705
43163
|
this.instructionResult.status = pvm_interpreter_result_Result.FAULT;
|
|
42706
|
-
this.instructionResult.exitParam = getStartPageIndex(
|
|
43164
|
+
this.instructionResult.exitParam = getStartPageIndex(memory_index_tryAsMemoryIndex(storeResult.error.address));
|
|
42707
43165
|
}
|
|
42708
43166
|
}
|
|
42709
43167
|
}
|
|
@@ -43502,11 +43960,11 @@ class ProgramDecoder {
|
|
|
43502
43960
|
|
|
43503
43961
|
|
|
43504
43962
|
const interpreter_logger = logger_Logger.new(import.meta.filename, "pvm");
|
|
43505
|
-
class
|
|
43963
|
+
class interpreter_Interpreter {
|
|
43506
43964
|
useSbrkGas;
|
|
43507
|
-
registers = new
|
|
43965
|
+
registers = new registers_Registers();
|
|
43508
43966
|
memory = new Memory();
|
|
43509
|
-
gas = gasCounter(
|
|
43967
|
+
gas = gasCounter(gas_tryAsGas(0));
|
|
43510
43968
|
code = new Uint8Array();
|
|
43511
43969
|
mask = Mask.empty();
|
|
43512
43970
|
pc = 0;
|
|
@@ -43640,8 +44098,8 @@ class Interpreter {
|
|
|
43640
44098
|
break;
|
|
43641
44099
|
case ArgumentType.TWO_REGISTERS:
|
|
43642
44100
|
if (this.useSbrkGas && currentInstruction === Instruction.SBRK) {
|
|
43643
|
-
const calculateSbrkCost = (length) => (alignToPageSize(length) /
|
|
43644
|
-
const underflow = this.gas.sub(
|
|
44101
|
+
const calculateSbrkCost = (length) => (alignToPageSize(length) / memory_consts_PAGE_SIZE) * 16;
|
|
44102
|
+
const underflow = this.gas.sub(gas_tryAsGas(calculateSbrkCost(this.registers.getLowerU32(argsResult.firstRegisterIndex))));
|
|
43645
44103
|
if (underflow) {
|
|
43646
44104
|
this.status = status_Status.OOG;
|
|
43647
44105
|
return this.status;
|
|
@@ -43736,12 +44194,88 @@ class Interpreter {
|
|
|
43736
44194
|
}
|
|
43737
44195
|
}
|
|
43738
44196
|
|
|
44197
|
+
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/debugger-adapter.ts
|
|
44198
|
+
|
|
44199
|
+
|
|
44200
|
+
|
|
44201
|
+
|
|
44202
|
+
|
|
44203
|
+
|
|
44204
|
+
class DebuggerAdapter {
|
|
44205
|
+
pvm;
|
|
44206
|
+
constructor(useSbrkGas = false) {
|
|
44207
|
+
this.pvm = new Interpreter({ useSbrkGas });
|
|
44208
|
+
}
|
|
44209
|
+
resetGeneric(rawProgram, flatRegisters, initialGas) {
|
|
44210
|
+
this.pvm.resetGeneric(rawProgram, 0, tryAsGas(initialGas), new Registers(flatRegisters));
|
|
44211
|
+
}
|
|
44212
|
+
reset(rawProgram, pc, gas, maybeRegisters, maybeMemory) {
|
|
44213
|
+
this.pvm.resetGeneric(rawProgram, pc, tryAsGas(gas), maybeRegisters, maybeMemory);
|
|
44214
|
+
}
|
|
44215
|
+
getPageDump(pageNumber) {
|
|
44216
|
+
const page = this.pvm.getMemoryPage(pageNumber);
|
|
44217
|
+
if (page === null) {
|
|
44218
|
+
// page wasn't allocated so we return an empty page
|
|
44219
|
+
return safeAllocUint8Array(PAGE_SIZE);
|
|
44220
|
+
}
|
|
44221
|
+
if (page.length === PAGE_SIZE) {
|
|
44222
|
+
// page was allocated and has a proper size so we can simply return it
|
|
44223
|
+
return page;
|
|
44224
|
+
}
|
|
44225
|
+
// page was allocated but it is shorter than PAGE_SIZE so we have to extend it
|
|
44226
|
+
const fullPage = safeAllocUint8Array(PAGE_SIZE);
|
|
44227
|
+
fullPage.set(page);
|
|
44228
|
+
return fullPage;
|
|
44229
|
+
}
|
|
44230
|
+
setMemory(address, value) {
|
|
44231
|
+
this.pvm.memory.storeFrom(tryAsMemoryIndex(address), value);
|
|
44232
|
+
}
|
|
44233
|
+
getExitArg() {
|
|
44234
|
+
return this.pvm.getExitParam() ?? 0;
|
|
44235
|
+
}
|
|
44236
|
+
getStatus() {
|
|
44237
|
+
return this.pvm.getStatus();
|
|
44238
|
+
}
|
|
44239
|
+
nextStep() {
|
|
44240
|
+
return this.pvm.nextStep() === Status.OK;
|
|
44241
|
+
}
|
|
44242
|
+
nSteps(steps) {
|
|
44243
|
+
check `${steps >>> 0 > 0} Expected a positive integer got ${steps}`;
|
|
44244
|
+
for (let i = 0; i < steps; i++) {
|
|
44245
|
+
const isOk = this.nextStep();
|
|
44246
|
+
if (!isOk) {
|
|
44247
|
+
return false;
|
|
44248
|
+
}
|
|
44249
|
+
}
|
|
44250
|
+
return true;
|
|
44251
|
+
}
|
|
44252
|
+
getRegisters() {
|
|
44253
|
+
return this.pvm.registers.getAllU64();
|
|
44254
|
+
}
|
|
44255
|
+
setRegisters(registers) {
|
|
44256
|
+
this.pvm.registers.copyFrom(new Registers(registers));
|
|
44257
|
+
}
|
|
44258
|
+
getProgramCounter() {
|
|
44259
|
+
return this.pvm.getPC();
|
|
44260
|
+
}
|
|
44261
|
+
setNextProgramCounter(nextPc) {
|
|
44262
|
+
this.pvm.setNextPC(nextPc);
|
|
44263
|
+
}
|
|
44264
|
+
getGasLeft() {
|
|
44265
|
+
return BigInt(this.pvm.gas.get());
|
|
44266
|
+
}
|
|
44267
|
+
setGasLeft(gas) {
|
|
44268
|
+
this.pvm.gas.set(tryAsGas(gas));
|
|
44269
|
+
}
|
|
44270
|
+
}
|
|
44271
|
+
|
|
43739
44272
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/index.ts
|
|
43740
44273
|
|
|
43741
44274
|
|
|
43742
44275
|
|
|
43743
44276
|
|
|
43744
44277
|
|
|
44278
|
+
|
|
43745
44279
|
;// CONCATENATED MODULE: ./node_modules/@fluffylabs/anan-as/build/debug-raw.js
|
|
43746
44280
|
async function instantiate(module, imports = {}) {
|
|
43747
44281
|
const adaptedImports = {
|
|
@@ -44195,12 +44729,12 @@ class AnanasMemory {
|
|
|
44195
44729
|
}
|
|
44196
44730
|
class AnanasGasCounter {
|
|
44197
44731
|
instance;
|
|
44198
|
-
initialGas =
|
|
44732
|
+
initialGas = gas_tryAsGas(0n);
|
|
44199
44733
|
constructor(instance) {
|
|
44200
44734
|
this.instance = instance;
|
|
44201
44735
|
}
|
|
44202
44736
|
get() {
|
|
44203
|
-
return
|
|
44737
|
+
return gas_tryAsGas(this.instance.getGasLeft());
|
|
44204
44738
|
}
|
|
44205
44739
|
set(g) {
|
|
44206
44740
|
this.instance.setGasLeft(BigInt(g));
|
|
@@ -44305,7 +44839,7 @@ class InterpreterInstanceManager {
|
|
|
44305
44839
|
const instances = [];
|
|
44306
44840
|
switch (interpreter) {
|
|
44307
44841
|
case PvmBackend.BuiltIn:
|
|
44308
|
-
instances.push(new
|
|
44842
|
+
instances.push(new interpreter_Interpreter({
|
|
44309
44843
|
useSbrkGas: false,
|
|
44310
44844
|
}));
|
|
44311
44845
|
break;
|
|
@@ -44479,10 +45013,10 @@ class Info {
|
|
|
44479
45013
|
const chunk = encodedInfo.raw.subarray(Number(offset), Number(offset + length));
|
|
44480
45014
|
const writeResult = memory.storeFrom(outputStart, chunk);
|
|
44481
45015
|
if (writeResult.isError) {
|
|
44482
|
-
logger_logger.trace `INFO(${serviceId}, off: ${offset}, len: ${length}) <- PANIC`;
|
|
45016
|
+
logger_logger.trace `[${this.currentServiceId}] INFO(${serviceId}, off: ${offset}, len: ${length}) <- PANIC`;
|
|
44483
45017
|
return PvmExecution.Panic;
|
|
44484
45018
|
}
|
|
44485
|
-
logger_logger.trace `INFO(${serviceId}, off: ${offset}, len: ${length}) <- ${bytes_BytesBlob.blobFrom(chunk)}`;
|
|
45019
|
+
logger_logger.trace `[${this.currentServiceId}] INFO(${serviceId}, off: ${offset}, len: ${length}) <- ${bytes_BytesBlob.blobFrom(chunk)}`;
|
|
44486
45020
|
if (accountInfo === null) {
|
|
44487
45021
|
regs.set(IN_OUT_REG, HostCallResult.NONE);
|
|
44488
45022
|
return;
|
|
@@ -44706,7 +45240,7 @@ class AccumulateExternalities {
|
|
|
44706
45240
|
const bytes = serviceInfo.storageUtilisationBytes - length - LOOKUP_HISTORY_ENTRY_BYTES;
|
|
44707
45241
|
return this.updatedState.updateServiceStorageUtilisation(this.currentServiceId, items, bytes, serviceInfo);
|
|
44708
45242
|
};
|
|
44709
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
45243
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/380802380802?v=0.7.2
|
|
44710
45244
|
if (s.status === PreimageStatusKind.Requested) {
|
|
44711
45245
|
const res = updateStorageUtilisation();
|
|
44712
45246
|
if (res.isError) {
|
|
@@ -44719,7 +45253,7 @@ class AccumulateExternalities {
|
|
|
44719
45253
|
return result_Result.ok(result_OK);
|
|
44720
45254
|
}
|
|
44721
45255
|
const t = this.currentTimeslot;
|
|
44722
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
45256
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/380802380802?v=0.7.2
|
|
44723
45257
|
if (s.status === PreimageStatusKind.Unavailable) {
|
|
44724
45258
|
const y = s.data[1];
|
|
44725
45259
|
if (y < t - this.chainSpec.preimageExpungePeriod) {
|
|
@@ -44735,14 +45269,14 @@ class AccumulateExternalities {
|
|
|
44735
45269
|
}
|
|
44736
45270
|
return result_Result.error(ForgetPreimageError.NotExpired, () => `Preimage not expired: y=${y}, timeslot=${t}, period=${this.chainSpec.preimageExpungePeriod}`);
|
|
44737
45271
|
}
|
|
44738
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
45272
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/382802383302?v=0.7.2
|
|
44739
45273
|
if (s.status === PreimageStatusKind.Available) {
|
|
44740
45274
|
this.updatedState.updatePreimage(serviceId, UpdatePreimage.updateOrAdd({
|
|
44741
45275
|
lookupHistory: new LookupHistoryItem(status.hash, status.length, tryAsLookupHistorySlots([s.data[0], t])),
|
|
44742
45276
|
}));
|
|
44743
45277
|
return result_Result.ok(result_OK);
|
|
44744
45278
|
}
|
|
44745
|
-
// https://graypaper.fluffylabs.dev/#/
|
|
45279
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/384002384c02?v=0.7.2
|
|
44746
45280
|
if (s.status === PreimageStatusKind.Reavailable) {
|
|
44747
45281
|
const y = s.data[1];
|
|
44748
45282
|
if (y < t - this.chainSpec.preimageExpungePeriod) {
|
|
@@ -45578,13 +46112,11 @@ class AccumulateDataItem {
|
|
|
45578
46112
|
* - gas cost and reports length for each service (statistics)
|
|
45579
46113
|
*/
|
|
45580
46114
|
class AccumulateData {
|
|
45581
|
-
autoAccumulateServicesByServiceId;
|
|
45582
46115
|
reportsDataByServiceId;
|
|
45583
46116
|
transfersByServiceId;
|
|
45584
46117
|
serviceIds;
|
|
45585
46118
|
gasLimitByServiceId;
|
|
45586
46119
|
constructor(reports, transfers, autoAccumulateServicesByServiceId) {
|
|
45587
|
-
this.autoAccumulateServicesByServiceId = autoAccumulateServicesByServiceId;
|
|
45588
46120
|
const serviceIdsFromAutoAccumulate = new Set(autoAccumulateServicesByServiceId.keys());
|
|
45589
46121
|
const { reportsDataByServiceId, serviceIds: serviceIdsFromReports, gasLimitByServiceId: reportsGasLimitByServiceId, } = this.transformReports(reports);
|
|
45590
46122
|
this.reportsDataByServiceId = reportsDataByServiceId;
|
|
@@ -45904,12 +46436,12 @@ function createMergeContext(chainSpec, state, inputState, results) {
|
|
|
45904
46436
|
}
|
|
45905
46437
|
function updatePrivilegedService(currentServiceId, serviceIdUpdatedByManager, selfUpdatedServiceId) {
|
|
45906
46438
|
if (currentServiceId === serviceIdUpdatedByManager) {
|
|
45907
|
-
return
|
|
46439
|
+
return selfUpdatedServiceId;
|
|
45908
46440
|
}
|
|
45909
|
-
return
|
|
46441
|
+
return serviceIdUpdatedByManager;
|
|
45910
46442
|
}
|
|
45911
46443
|
function mergePrivilegedServices(mergeContext, [serviceId, { stateUpdate }]) {
|
|
45912
|
-
const { outputState, currentPrivilegedServices, chainSpec } = mergeContext;
|
|
46444
|
+
const { outputState, currentPrivilegedServices, chainSpec, privilegedServicesUpdatedByManager } = mergeContext;
|
|
45913
46445
|
const currentManager = currentPrivilegedServices.manager;
|
|
45914
46446
|
const currentRegistrar = currentPrivilegedServices.registrar;
|
|
45915
46447
|
const currentDelegator = currentPrivilegedServices.delegator;
|
|
@@ -45927,28 +46459,35 @@ function mergePrivilegedServices(mergeContext, [serviceId, { stateUpdate }]) {
|
|
|
45927
46459
|
});
|
|
45928
46460
|
}
|
|
45929
46461
|
if (serviceId === currentRegistrar) {
|
|
45930
|
-
const newRegistrar = updatePrivilegedService(currentPrivilegedServices.registrar,
|
|
46462
|
+
const newRegistrar = updatePrivilegedService(currentPrivilegedServices.registrar, privilegedServicesUpdatedByManager.registrar, privilegedServices.registrar);
|
|
45931
46463
|
outputState.privilegedServices = PrivilegedServices.create({
|
|
45932
46464
|
...outputState.privilegedServices,
|
|
45933
46465
|
registrar: newRegistrar,
|
|
45934
46466
|
});
|
|
45935
46467
|
}
|
|
45936
46468
|
if (serviceId === currentDelegator) {
|
|
45937
|
-
const newDelegator = updatePrivilegedService(currentPrivilegedServices.delegator,
|
|
46469
|
+
const newDelegator = updatePrivilegedService(currentPrivilegedServices.delegator, privilegedServicesUpdatedByManager.delegator, privilegedServices.delegator);
|
|
45938
46470
|
outputState.privilegedServices = PrivilegedServices.create({
|
|
45939
46471
|
...outputState.privilegedServices,
|
|
45940
46472
|
delegator: newDelegator,
|
|
45941
46473
|
});
|
|
45942
46474
|
}
|
|
45943
|
-
|
|
45944
|
-
const newAssigners = currentAssigners.map((currentAssigner, coreIndex) =>
|
|
45945
|
-
|
|
45946
|
-
|
|
45947
|
-
|
|
45948
|
-
|
|
45949
|
-
|
|
45950
|
-
|
|
46475
|
+
let shouldUpdateAssigners = false;
|
|
46476
|
+
const newAssigners = currentAssigners.map((currentAssigner, coreIndex) => {
|
|
46477
|
+
if (serviceId === currentAssigner) {
|
|
46478
|
+
const newAssigner = updatePrivilegedService(currentPrivilegedServices.assigners[coreIndex], privilegedServicesUpdatedByManager.assigners[coreIndex], privilegedServices.assigners[coreIndex]);
|
|
46479
|
+
shouldUpdateAssigners = shouldUpdateAssigners || newAssigner !== currentAssigner;
|
|
46480
|
+
return newAssigner;
|
|
46481
|
+
}
|
|
46482
|
+
return currentAssigner;
|
|
45951
46483
|
});
|
|
46484
|
+
if (shouldUpdateAssigners) {
|
|
46485
|
+
const newAssignersPerCore = tryAsPerCore(newAssigners, chainSpec);
|
|
46486
|
+
outputState.privilegedServices = PrivilegedServices.create({
|
|
46487
|
+
...outputState.privilegedServices,
|
|
46488
|
+
assigners: newAssignersPerCore,
|
|
46489
|
+
});
|
|
46490
|
+
}
|
|
45952
46491
|
}
|
|
45953
46492
|
}
|
|
45954
46493
|
function mergeValidatorsData(mergeContext, [serviceId, { stateUpdate }]) {
|
|
@@ -46093,7 +46632,7 @@ class Assign {
|
|
|
46093
46632
|
const memoryReadResult = memory.loadInto(res, authorizationQueueStart);
|
|
46094
46633
|
// error while reading the memory.
|
|
46095
46634
|
if (memoryReadResult.isError) {
|
|
46096
|
-
logger_logger.trace `ASSIGN() <- PANIC`;
|
|
46635
|
+
logger_logger.trace `[${this.currentServiceId}] ASSIGN() <- PANIC`;
|
|
46097
46636
|
return PvmExecution.Panic;
|
|
46098
46637
|
}
|
|
46099
46638
|
if (maybeCoreIndex >= this.chainSpec.coresCount) {
|
|
@@ -46108,18 +46647,18 @@ class Assign {
|
|
|
46108
46647
|
const result = this.partialState.updateAuthorizationQueue(coreIndex, fixedSizeAuthQueue, assigners);
|
|
46109
46648
|
if (result.isOk) {
|
|
46110
46649
|
regs.set(assign_IN_OUT_REG, HostCallResult.OK);
|
|
46111
|
-
logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
|
|
46650
|
+
logger_logger.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- OK`;
|
|
46112
46651
|
return;
|
|
46113
46652
|
}
|
|
46114
46653
|
const e = result.error;
|
|
46115
46654
|
if (e === UpdatePrivilegesError.UnprivilegedService) {
|
|
46116
46655
|
regs.set(assign_IN_OUT_REG, HostCallResult.HUH);
|
|
46117
|
-
logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
|
|
46656
|
+
logger_logger.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
|
|
46118
46657
|
return;
|
|
46119
46658
|
}
|
|
46120
46659
|
if (e === UpdatePrivilegesError.InvalidServiceId) {
|
|
46121
46660
|
regs.set(assign_IN_OUT_REG, HostCallResult.WHO);
|
|
46122
|
-
logger_logger.trace `ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
|
|
46661
|
+
logger_logger.trace `[${this.currentServiceId}] ASSIGN(${coreIndex}, ${fixedSizeAuthQueue}) <- HUH`;
|
|
46123
46662
|
return;
|
|
46124
46663
|
}
|
|
46125
46664
|
debug_assertNever(e);
|
|
@@ -46190,7 +46729,7 @@ class Bless {
|
|
|
46190
46729
|
decoder.resetTo(0);
|
|
46191
46730
|
const memoryReadResult = memory.loadInto(result, memIndex);
|
|
46192
46731
|
if (memoryReadResult.isError) {
|
|
46193
|
-
logger_logger.trace `BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}) <- PANIC`;
|
|
46732
|
+
logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}) <- PANIC`;
|
|
46194
46733
|
return PvmExecution.Panic;
|
|
46195
46734
|
}
|
|
46196
46735
|
const { serviceId, gas } = decoder.object(serviceIdAndGasCodec);
|
|
@@ -46203,26 +46742,26 @@ class Bless {
|
|
|
46203
46742
|
const authorizersDecoder = decoder_Decoder.fromBlob(res);
|
|
46204
46743
|
const memoryReadResult = memory.loadInto(res, authorization);
|
|
46205
46744
|
if (memoryReadResult.isError) {
|
|
46206
|
-
logger_logger.trace `BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- PANIC`;
|
|
46745
|
+
logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- PANIC`;
|
|
46207
46746
|
return PvmExecution.Panic;
|
|
46208
46747
|
}
|
|
46209
46748
|
// `a`
|
|
46210
46749
|
const authorizers = tryAsPerCore(authorizersDecoder.sequenceFixLen(descriptors_codec.u32.asOpaque(), this.chainSpec.coresCount), this.chainSpec);
|
|
46211
46750
|
const updateResult = this.partialState.updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate);
|
|
46212
46751
|
if (updateResult.isOk) {
|
|
46213
|
-
logger_logger.trace `BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- OK`;
|
|
46752
|
+
logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- OK`;
|
|
46214
46753
|
regs.set(bless_IN_OUT_REG, HostCallResult.OK);
|
|
46215
46754
|
return;
|
|
46216
46755
|
}
|
|
46217
46756
|
const e = updateResult.error;
|
|
46218
46757
|
// NOTE: `UpdatePrivilegesError.UnprivilegedService` won't happen in 0.7.1+
|
|
46219
46758
|
if (e === UpdatePrivilegesError.UnprivilegedService) {
|
|
46220
|
-
logger_logger.trace `BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- HUH`;
|
|
46759
|
+
logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- HUH`;
|
|
46221
46760
|
regs.set(bless_IN_OUT_REG, HostCallResult.HUH);
|
|
46222
46761
|
return;
|
|
46223
46762
|
}
|
|
46224
46763
|
if (e === UpdatePrivilegesError.InvalidServiceId) {
|
|
46225
|
-
logger_logger.trace `BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- WHO`;
|
|
46764
|
+
logger_logger.trace `[${this.currentServiceId}] BLESS(m: ${manager}, a: [${authorizers}], v: ${delegator}, r: ${registrar}, ${lazyInspect(autoAccumulate)}) <- WHO`;
|
|
46226
46765
|
regs.set(bless_IN_OUT_REG, HostCallResult.WHO);
|
|
46227
46766
|
return;
|
|
46228
46767
|
}
|
|
@@ -46252,7 +46791,7 @@ class GasHostCall {
|
|
|
46252
46791
|
}
|
|
46253
46792
|
execute(gas, regs) {
|
|
46254
46793
|
const gasValue = gas.get();
|
|
46255
|
-
logger_logger.trace `GAS <- ${gasValue}`;
|
|
46794
|
+
logger_logger.trace `[${this.currentServiceId}] GAS <- ${gasValue}`;
|
|
46256
46795
|
regs.set(7, numbers_tryAsU64(gasValue));
|
|
46257
46796
|
return Promise.resolve(undefined);
|
|
46258
46797
|
}
|
|
@@ -46284,7 +46823,7 @@ class Checkpoint {
|
|
|
46284
46823
|
async execute(gas, regs) {
|
|
46285
46824
|
await this.gasHostCall.execute(gas, regs);
|
|
46286
46825
|
this.partialState.checkpoint();
|
|
46287
|
-
logger_logger.trace `CHECKPOINT()`;
|
|
46826
|
+
logger_logger.trace `[${this.currentServiceId}] CHECKPOINT()`;
|
|
46288
46827
|
return;
|
|
46289
46828
|
}
|
|
46290
46829
|
}
|
|
@@ -46324,18 +46863,18 @@ class Designate {
|
|
|
46324
46863
|
const memoryReadResult = memory.loadInto(res, validatorsStart);
|
|
46325
46864
|
// error while reading the memory.
|
|
46326
46865
|
if (memoryReadResult.isError) {
|
|
46327
|
-
logger_logger.trace `DESIGNATE() <- PANIC`;
|
|
46866
|
+
logger_logger.trace `[${this.currentServiceId}] DESIGNATE() <- PANIC`;
|
|
46328
46867
|
return PvmExecution.Panic;
|
|
46329
46868
|
}
|
|
46330
46869
|
const decoder = decoder_Decoder.fromBlob(res);
|
|
46331
46870
|
const validatorsData = decoder.sequenceFixLen(ValidatorData.Codec, this.chainSpec.validatorsCount);
|
|
46332
46871
|
const result = this.partialState.updateValidatorsData(tryAsPerValidator(validatorsData, this.chainSpec));
|
|
46333
46872
|
if (result.isError) {
|
|
46334
|
-
logger_logger.trace `DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- HUH`;
|
|
46873
|
+
logger_logger.trace `[${this.currentServiceId}] DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- HUH`;
|
|
46335
46874
|
regs.set(designate_IN_OUT_REG, HostCallResult.HUH);
|
|
46336
46875
|
}
|
|
46337
46876
|
else {
|
|
46338
|
-
logger_logger.trace `DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- OK`;
|
|
46877
|
+
logger_logger.trace `[${this.currentServiceId}] DESIGNATE([${validatorsData[0]}, ${validatorsData[1]}, ...]) <- OK`;
|
|
46339
46878
|
regs.set(designate_IN_OUT_REG, HostCallResult.OK);
|
|
46340
46879
|
}
|
|
46341
46880
|
}
|
|
@@ -46376,29 +46915,29 @@ class Eject {
|
|
|
46376
46915
|
const previousCodeHash = bytes_Bytes.zero(hash_HASH_SIZE).asOpaque();
|
|
46377
46916
|
const memoryReadResult = memory.loadInto(previousCodeHash.raw, preimageHashStart);
|
|
46378
46917
|
if (memoryReadResult.isError) {
|
|
46379
|
-
logger_logger.trace `EJECT(${serviceId}) <- PANIC`;
|
|
46918
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}) <- PANIC`;
|
|
46380
46919
|
return PvmExecution.Panic;
|
|
46381
46920
|
}
|
|
46382
46921
|
// cannot eject self
|
|
46383
46922
|
if (serviceId === this.currentServiceId) {
|
|
46384
46923
|
regs.set(eject_IN_OUT_REG, HostCallResult.WHO);
|
|
46385
|
-
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- WHO`;
|
|
46924
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- WHO`;
|
|
46386
46925
|
return;
|
|
46387
46926
|
}
|
|
46388
46927
|
const result = this.partialState.eject(serviceId, previousCodeHash);
|
|
46389
46928
|
// All good!
|
|
46390
46929
|
if (result.isOk) {
|
|
46391
|
-
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- OK`;
|
|
46930
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- OK`;
|
|
46392
46931
|
regs.set(eject_IN_OUT_REG, HostCallResult.OK);
|
|
46393
46932
|
return;
|
|
46394
46933
|
}
|
|
46395
46934
|
const e = result.error;
|
|
46396
46935
|
if (e === EjectError.InvalidService) {
|
|
46397
|
-
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- WHO ${result_resultToString(result)}`;
|
|
46936
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- WHO ${result_resultToString(result)}`;
|
|
46398
46937
|
regs.set(eject_IN_OUT_REG, HostCallResult.WHO);
|
|
46399
46938
|
}
|
|
46400
46939
|
else if (e === EjectError.InvalidPreimage) {
|
|
46401
|
-
logger_logger.trace `EJECT(${serviceId}, ${previousCodeHash}) <- HUH ${result_resultToString(result)}`;
|
|
46940
|
+
logger_logger.trace `[${this.currentServiceId}] EJECT(${serviceId}, ${previousCodeHash}) <- HUH ${result_resultToString(result)}`;
|
|
46402
46941
|
regs.set(eject_IN_OUT_REG, HostCallResult.HUH);
|
|
46403
46942
|
}
|
|
46404
46943
|
else {
|
|
@@ -46417,9 +46956,9 @@ class Eject {
|
|
|
46417
46956
|
|
|
46418
46957
|
const forget_IN_OUT_REG = 7;
|
|
46419
46958
|
/**
|
|
46420
|
-
*
|
|
46959
|
+
* Delete preimage hash or mark as unavailable if it was available.
|
|
46421
46960
|
*
|
|
46422
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
46961
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/385d01385d01?v=0.7.2
|
|
46423
46962
|
*/
|
|
46424
46963
|
class Forget {
|
|
46425
46964
|
currentServiceId;
|
|
@@ -46440,11 +46979,11 @@ class Forget {
|
|
|
46440
46979
|
const memoryReadResult = memory.loadInto(hash.raw, hashStart);
|
|
46441
46980
|
// error while reading the memory.
|
|
46442
46981
|
if (memoryReadResult.isError) {
|
|
46443
|
-
logger_logger.trace `FORGET(${hash}, ${length}) <- PANIC`;
|
|
46982
|
+
logger_logger.trace `[${this.currentServiceId}] FORGET(${hash}, ${length}) <- PANIC`;
|
|
46444
46983
|
return PvmExecution.Panic;
|
|
46445
46984
|
}
|
|
46446
46985
|
const result = this.partialState.forgetPreimage(hash.asOpaque(), length);
|
|
46447
|
-
logger_logger.trace `FORGET(${hash}, ${length}) <- ${result_resultToString(result)}`;
|
|
46986
|
+
logger_logger.trace `[${this.currentServiceId}] FORGET(${hash}, ${length}) <- ${result_resultToString(result)}`;
|
|
46448
46987
|
if (result.isOk) {
|
|
46449
46988
|
regs.set(forget_IN_OUT_REG, HostCallResult.OK);
|
|
46450
46989
|
}
|
|
@@ -46501,11 +47040,11 @@ class New {
|
|
|
46501
47040
|
const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
|
|
46502
47041
|
// error while reading the memory.
|
|
46503
47042
|
if (memoryReadResult.isError) {
|
|
46504
|
-
logger_logger.trace `NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
|
|
47043
|
+
logger_logger.trace `[${this.currentServiceId}] NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- PANIC`;
|
|
46505
47044
|
return PvmExecution.Panic;
|
|
46506
47045
|
}
|
|
46507
47046
|
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)}`;
|
|
47047
|
+
logger_logger.trace `[${this.currentServiceId}] NEW(${codeHash}, ${codeLength}, ${gas}, ${allowance}, ${gratisStorage}, ${requestedServiceId}) <- ${result_resultToString(assignedId)}`;
|
|
46509
47048
|
if (assignedId.isOk) {
|
|
46510
47049
|
regs.set(new_IN_OUT_REG, numbers_tryAsU64(assignedId.ok));
|
|
46511
47050
|
return;
|
|
@@ -46565,11 +47104,11 @@ class Provide {
|
|
|
46565
47104
|
const preimage = bytes_BytesBlob.blobFrom(safe_alloc_uint8array_safeAllocUint8Array(length));
|
|
46566
47105
|
const memoryReadResult = memory.loadInto(preimage.raw, preimageStart);
|
|
46567
47106
|
if (memoryReadResult.isError) {
|
|
46568
|
-
logger_logger.trace `PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- PANIC`;
|
|
47107
|
+
logger_logger.trace `[${this.currentServiceId}] PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- PANIC`;
|
|
46569
47108
|
return PvmExecution.Panic;
|
|
46570
47109
|
}
|
|
46571
47110
|
const result = this.partialState.providePreimage(serviceId, preimage);
|
|
46572
|
-
logger_logger.trace `PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- ${result_resultToString(result)}`;
|
|
47111
|
+
logger_logger.trace `[${this.currentServiceId}] PROVIDE(${serviceId}, ${preimage.toStringTruncated()}) <- ${result_resultToString(result)}`;
|
|
46573
47112
|
if (result.isOk) {
|
|
46574
47113
|
regs.set(provide_IN_OUT_REG, HostCallResult.OK);
|
|
46575
47114
|
return;
|
|
@@ -46625,35 +47164,35 @@ class Query {
|
|
|
46625
47164
|
const memoryReadResult = memory.loadInto(hash.raw, hashStart);
|
|
46626
47165
|
// error while reading the memory.
|
|
46627
47166
|
if (memoryReadResult.isError) {
|
|
46628
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- PANIC`;
|
|
47167
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- PANIC`;
|
|
46629
47168
|
return PvmExecution.Panic;
|
|
46630
47169
|
}
|
|
46631
47170
|
const result = this.partialState.checkPreimageStatus(hash.asOpaque(), length);
|
|
46632
47171
|
const zero = numbers_tryAsU64(0n);
|
|
46633
47172
|
if (result === null) {
|
|
46634
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- NONE`;
|
|
47173
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- NONE`;
|
|
46635
47174
|
regs.set(IN_OUT_REG_1, HostCallResult.NONE);
|
|
46636
47175
|
regs.set(IN_OUT_REG_2, zero);
|
|
46637
47176
|
return;
|
|
46638
47177
|
}
|
|
46639
47178
|
switch (result.status) {
|
|
46640
47179
|
case PreimageStatusKind.Requested:
|
|
46641
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- REQUESTED`;
|
|
47180
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- REQUESTED`;
|
|
46642
47181
|
regs.set(IN_OUT_REG_1, zero);
|
|
46643
47182
|
regs.set(IN_OUT_REG_2, zero);
|
|
46644
47183
|
return;
|
|
46645
47184
|
case PreimageStatusKind.Available:
|
|
46646
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- AVAILABLE [${result.data}]`;
|
|
47185
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- AVAILABLE [${result.data}]`;
|
|
46647
47186
|
regs.set(IN_OUT_REG_1, numbers_tryAsU64((BigInt(result.data[0]) << UPPER_BITS_SHIFT) + 1n));
|
|
46648
47187
|
regs.set(IN_OUT_REG_2, zero);
|
|
46649
47188
|
return;
|
|
46650
47189
|
case PreimageStatusKind.Unavailable:
|
|
46651
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- UNAVAILABLE [${result.data.join(", ")}]`;
|
|
47190
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- UNAVAILABLE [${result.data.join(", ")}]`;
|
|
46652
47191
|
regs.set(IN_OUT_REG_1, numbers_tryAsU64((BigInt(result.data[0]) << UPPER_BITS_SHIFT) + 2n));
|
|
46653
47192
|
regs.set(IN_OUT_REG_2, numbers_tryAsU64(result.data[1]));
|
|
46654
47193
|
return;
|
|
46655
47194
|
case PreimageStatusKind.Reavailable:
|
|
46656
|
-
logger_logger.trace `QUERY(${hash}, ${length}) <- REAVAILABLE [${result.data.join(", ")}]`;
|
|
47195
|
+
logger_logger.trace `[${this.currentServiceId}] QUERY(${hash}, ${length}) <- REAVAILABLE [${result.data.join(", ")}]`;
|
|
46657
47196
|
regs.set(IN_OUT_REG_1, numbers_tryAsU64((BigInt(result.data[0]) << UPPER_BITS_SHIFT) + 3n));
|
|
46658
47197
|
regs.set(IN_OUT_REG_2, numbers_tryAsU64((BigInt(result.data[2]) << UPPER_BITS_SHIFT) + BigInt(result.data[1])));
|
|
46659
47198
|
return;
|
|
@@ -46694,11 +47233,11 @@ class Solicit {
|
|
|
46694
47233
|
const hash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
46695
47234
|
const memoryReadResult = memory.loadInto(hash.raw, hashStart);
|
|
46696
47235
|
if (memoryReadResult.isError) {
|
|
46697
|
-
logger_logger.trace `SOLICIT(${hash}, ${length}) <- PANIC`;
|
|
47236
|
+
logger_logger.trace `[${this.currentServiceId}] SOLICIT(${hash}, ${length}) <- PANIC`;
|
|
46698
47237
|
return PvmExecution.Panic;
|
|
46699
47238
|
}
|
|
46700
47239
|
const result = this.partialState.requestPreimage(hash.asOpaque(), length);
|
|
46701
|
-
logger_logger.trace `SOLICIT(${hash}, ${length}) <- ${result_resultToString(result)}`;
|
|
47240
|
+
logger_logger.trace `[${this.currentServiceId}] SOLICIT(${hash}, ${length}) <- ${result_resultToString(result)}`;
|
|
46702
47241
|
if (result.isOk) {
|
|
46703
47242
|
regs.set(solicit_IN_OUT_REG, HostCallResult.OK);
|
|
46704
47243
|
return;
|
|
@@ -46756,7 +47295,7 @@ class Transfer {
|
|
|
46756
47295
|
*/
|
|
46757
47296
|
basicGasCost = Compatibility.isGreaterOrEqual(GpVersion.V0_7_2)
|
|
46758
47297
|
? gas_tryAsSmallGas(10)
|
|
46759
|
-
: (regs) =>
|
|
47298
|
+
: (regs) => gas_tryAsGas(10n + regs.get(TRANSFER_GAS_FEE_REG));
|
|
46760
47299
|
tracedRegisters = traceRegisters(transfer_IN_OUT_REG, AMOUNT_REG, TRANSFER_GAS_FEE_REG, MEMO_START_REG);
|
|
46761
47300
|
constructor(currentServiceId, partialState) {
|
|
46762
47301
|
this.currentServiceId = currentServiceId;
|
|
@@ -46775,16 +47314,16 @@ class Transfer {
|
|
|
46775
47314
|
const memoryReadResult = memory.loadInto(memo.raw, memoStart);
|
|
46776
47315
|
// page fault while reading the memory.
|
|
46777
47316
|
if (memoryReadResult.isError) {
|
|
46778
|
-
logger_logger.trace `TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- PANIC`;
|
|
47317
|
+
logger_logger.trace `[${this.currentServiceId}] TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- PANIC`;
|
|
46779
47318
|
return PvmExecution.Panic;
|
|
46780
47319
|
}
|
|
46781
47320
|
const transferResult = this.partialState.transfer(destination, amount, transferGasFee, memo);
|
|
46782
|
-
logger_logger.trace `TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- ${result_resultToString(transferResult)}`;
|
|
47321
|
+
logger_logger.trace `[${this.currentServiceId}] TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- ${result_resultToString(transferResult)}`;
|
|
46783
47322
|
// All good!
|
|
46784
47323
|
if (transferResult.isOk) {
|
|
46785
47324
|
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_2)) {
|
|
46786
47325
|
// substracting value `t`
|
|
46787
|
-
const underflow = gas.sub(
|
|
47326
|
+
const underflow = gas.sub(gas_tryAsGas(transferGasFee));
|
|
46788
47327
|
if (underflow) {
|
|
46789
47328
|
return PvmExecution.OOG;
|
|
46790
47329
|
}
|
|
@@ -46845,11 +47384,11 @@ class Upgrade {
|
|
|
46845
47384
|
const codeHash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
46846
47385
|
const memoryReadResult = memory.loadInto(codeHash.raw, codeHashStart);
|
|
46847
47386
|
if (memoryReadResult.isError) {
|
|
46848
|
-
logger_logger.trace `UPGRADE(${codeHash}, ${gas}, ${allowance}) <- PANIC`;
|
|
47387
|
+
logger_logger.trace `[${this.currentServiceId}] UPGRADE(${codeHash}, ${gas}, ${allowance}) <- PANIC`;
|
|
46849
47388
|
return PvmExecution.Panic;
|
|
46850
47389
|
}
|
|
46851
47390
|
this.partialState.upgradeService(codeHash.asOpaque(), gas, allowance);
|
|
46852
|
-
logger_logger.trace `UPGRADE(${codeHash}, ${gas}, ${allowance})`;
|
|
47391
|
+
logger_logger.trace `[${this.currentServiceId}] UPGRADE(${codeHash}, ${gas}, ${allowance})`;
|
|
46853
47392
|
regs.set(upgrade_IN_OUT_REG, HostCallResult.OK);
|
|
46854
47393
|
}
|
|
46855
47394
|
}
|
|
@@ -46883,11 +47422,11 @@ class Yield {
|
|
|
46883
47422
|
const hash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
46884
47423
|
const memoryReadResult = memory.loadInto(hash.raw, hashStart);
|
|
46885
47424
|
if (memoryReadResult.isError) {
|
|
46886
|
-
logger_logger.trace `YIELD() <- PANIC`;
|
|
47425
|
+
logger_logger.trace `[${this.currentServiceId}] YIELD() <- PANIC`;
|
|
46887
47426
|
return PvmExecution.Panic;
|
|
46888
47427
|
}
|
|
46889
47428
|
this.partialState.yield(hash);
|
|
46890
|
-
logger_logger.trace `YIELD(${hash})`;
|
|
47429
|
+
logger_logger.trace `[${this.currentServiceId}] YIELD(${hash})`;
|
|
46891
47430
|
regs.set(yield_IN_OUT_REG, HostCallResult.OK);
|
|
46892
47431
|
}
|
|
46893
47432
|
}
|
|
@@ -46930,10 +47469,10 @@ class Fetch {
|
|
|
46930
47469
|
const chunk = value === null ? new Uint8Array() : value.raw.subarray(Number(offset), Number(offset + length));
|
|
46931
47470
|
const storeResult = memory.storeFrom(output, chunk);
|
|
46932
47471
|
if (storeResult.isError) {
|
|
46933
|
-
logger_logger.trace `FETCH(${kind}) <- PANIC`;
|
|
47472
|
+
logger_logger.trace `[${this.currentServiceId}] FETCH(${kind}) <- PANIC`;
|
|
46934
47473
|
return PvmExecution.Panic;
|
|
46935
47474
|
}
|
|
46936
|
-
logger_logger.trace `FETCH(${kind}) <- ${value?.toStringTruncated()}`;
|
|
47475
|
+
logger_logger.trace `[${this.currentServiceId}] FETCH(${kind}) <- ${value?.toStringTruncated()}`;
|
|
46937
47476
|
// write result
|
|
46938
47477
|
regs.set(fetch_IN_OUT_REG, value === null ? HostCallResult.NONE : valueLength);
|
|
46939
47478
|
}
|
|
@@ -47083,7 +47622,7 @@ class LogHostCall {
|
|
|
47083
47622
|
}
|
|
47084
47623
|
memory.loadInto(message, msgStart);
|
|
47085
47624
|
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)})`;
|
|
47625
|
+
logger_logger.trace `[${this.currentServiceId}] LOG(${this.currentServiceId}, ${level < Levels.UNKNOWN ? Levels[level] : Levels[Levels.UNKNOWN]}(${lvl}), ${decoder.decode(target)}, ${decoder.decode(message)})`;
|
|
47087
47626
|
return Promise.resolve(undefined);
|
|
47088
47627
|
}
|
|
47089
47628
|
}
|
|
@@ -47124,12 +47663,12 @@ class Lookup {
|
|
|
47124
47663
|
const preImageHash = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
47125
47664
|
const memoryReadResult = memory.loadInto(preImageHash.raw, hashAddress);
|
|
47126
47665
|
if (memoryReadResult.isError) {
|
|
47127
|
-
logger_logger.trace `LOOKUP(${serviceId}, ${preImageHash}) <- PANIC`;
|
|
47666
|
+
logger_logger.trace `[${this.currentServiceId}] LOOKUP(${serviceId}, ${preImageHash}) <- PANIC`;
|
|
47128
47667
|
return PvmExecution.Panic;
|
|
47129
47668
|
}
|
|
47130
47669
|
// v
|
|
47131
47670
|
const preImage = this.account.lookup(serviceId, preImageHash);
|
|
47132
|
-
logger_logger.trace `LOOKUP(${serviceId}, ${preImageHash}) <- ${preImage?.toStringTruncated() ?? "<missing>"}...`;
|
|
47671
|
+
logger_logger.trace `[${this.currentServiceId}] LOOKUP(${serviceId}, ${preImageHash}) <- ${preImage?.toStringTruncated() ?? "<missing>"}...`;
|
|
47133
47672
|
const preImageLength = preImage === null ? numbers_tryAsU64(0) : numbers_tryAsU64(preImage.raw.length);
|
|
47134
47673
|
const preimageBlobOffset = regs.get(10);
|
|
47135
47674
|
const lengthToWrite = regs.get(11);
|
|
@@ -47226,20 +47765,20 @@ class Read {
|
|
|
47226
47765
|
const chunk = value === null ? safe_alloc_uint8array_safeAllocUint8Array(0) : value.raw.subarray(Number(offset), Number(offset + blobLength));
|
|
47227
47766
|
const memoryWriteResult = memory.storeFrom(destinationAddress, chunk);
|
|
47228
47767
|
if (memoryWriteResult.isError) {
|
|
47229
|
-
logger_logger.trace `READ(${serviceId}, ${rawKey}) <- PANIC`;
|
|
47768
|
+
logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- PANIC`;
|
|
47230
47769
|
return PvmExecution.Panic;
|
|
47231
47770
|
}
|
|
47232
47771
|
if (value === null) {
|
|
47233
|
-
logger_logger.trace `READ(${serviceId}, ${rawKey}) <- NONE`;
|
|
47772
|
+
logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- NONE`;
|
|
47234
47773
|
regs.set(read_IN_OUT_REG, HostCallResult.NONE);
|
|
47235
47774
|
return;
|
|
47236
47775
|
}
|
|
47237
47776
|
if (chunk.length > 0) {
|
|
47238
|
-
logger_logger.trace `READ(${serviceId}, ${rawKey}) <- ${bytes_BytesBlob.blobFrom(chunk).toStringTruncated()}`;
|
|
47777
|
+
logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- ${bytes_BytesBlob.blobFrom(chunk).toStringTruncated()}`;
|
|
47239
47778
|
}
|
|
47240
47779
|
else {
|
|
47241
47780
|
// just a query for length of stored data
|
|
47242
|
-
logger_logger.trace `READ(${serviceId}, ${rawKey}) <- (${valueLength} ${valueLength === 1n ? "byte" : "bytes"})`;
|
|
47781
|
+
logger_logger.trace `[${this.currentServiceId}] READ(${serviceId}, ${rawKey}) <- (${valueLength} ${valueLength === 1n ? "byte" : "bytes"})`;
|
|
47243
47782
|
}
|
|
47244
47783
|
regs.set(read_IN_OUT_REG, valueLength);
|
|
47245
47784
|
}
|
|
@@ -47283,7 +47822,7 @@ class Write {
|
|
|
47283
47822
|
const rawStorageKey = safe_alloc_uint8array_safeAllocUint8Array(storageKeyLengthClamped);
|
|
47284
47823
|
const keyLoadingResult = memory.loadInto(rawStorageKey, storageKeyStartAddress);
|
|
47285
47824
|
if (keyLoadingResult.isError) {
|
|
47286
|
-
logger_logger.trace `WRITE() <- PANIC`;
|
|
47825
|
+
logger_logger.trace `[${this.currentServiceId}] WRITE() <- PANIC`;
|
|
47287
47826
|
return PvmExecution.Panic;
|
|
47288
47827
|
}
|
|
47289
47828
|
// k
|
|
@@ -47293,14 +47832,14 @@ class Write {
|
|
|
47293
47832
|
const valueLoadingResult = memory.loadInto(value, valueStart);
|
|
47294
47833
|
// Note [MaSo] this is ok to return bcs if valueLength is 0, then this panic won't happen
|
|
47295
47834
|
if (valueLoadingResult.isError) {
|
|
47296
|
-
logger_logger.trace `WRITE(${storageKey}) <- PANIC`;
|
|
47835
|
+
logger_logger.trace `[${this.currentServiceId}] WRITE(${storageKey}) <- PANIC`;
|
|
47297
47836
|
return PvmExecution.Panic;
|
|
47298
47837
|
}
|
|
47299
47838
|
/** https://graypaper.fluffylabs.dev/#/9a08063/33af0133b201?v=0.6.6 */
|
|
47300
47839
|
const maybeValue = valueLength === 0n ? null : bytes_BytesBlob.blobFrom(value);
|
|
47301
47840
|
// a
|
|
47302
47841
|
const result = this.account.write(storageKey, maybeValue);
|
|
47303
|
-
logger_logger.trace `WRITE(${storageKey}, ${maybeValue?.toStringTruncated() ?? "remove"}) <- ${result_resultToString(result)}`;
|
|
47842
|
+
logger_logger.trace `[${this.currentServiceId}] WRITE(${storageKey}, ${maybeValue?.toStringTruncated() ?? "remove"}) <- ${result_resultToString(result)}`;
|
|
47304
47843
|
if (result.isError) {
|
|
47305
47844
|
regs.set(write_IN_OUT_REG, HostCallResult.FULL);
|
|
47306
47845
|
return;
|
|
@@ -47529,7 +48068,7 @@ class Accumulate {
|
|
|
47529
48068
|
serviceId,
|
|
47530
48069
|
argsLength: numbers_tryAsU32(transfers.length + operands.length),
|
|
47531
48070
|
});
|
|
47532
|
-
const result = await executor.run(invocationArgs,
|
|
48071
|
+
const result = await executor.run(invocationArgs, gas_tryAsGas(gas));
|
|
47533
48072
|
const [newState, checkpoint] = partialState.getStateUpdates();
|
|
47534
48073
|
/**
|
|
47535
48074
|
* PVM invocation returned and error so we return the checkpoint
|
|
@@ -47730,19 +48269,19 @@ class Accumulate {
|
|
|
47730
48269
|
for (let serviceIndex = 0; serviceIndex < serviceIdsLength; serviceIndex += 1) {
|
|
47731
48270
|
const serviceId = serviceIds[serviceIndex];
|
|
47732
48271
|
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
|
-
|
|
48272
|
+
const promise = this.accumulateSingleService(serviceId, accumulateData.getTransfers(serviceId), accumulateData.getOperands(serviceId), accumulateData.getGasLimit(serviceId), slot, entropy, AccumulationStateUpdate.copyFrom(inputStateUpdate)).then(({ consumedGas, stateUpdate }) => {
|
|
48273
|
+
const resultEntry = [
|
|
48274
|
+
serviceId,
|
|
48275
|
+
{
|
|
48276
|
+
consumedGas,
|
|
48277
|
+
stateUpdate: stateUpdate === null ? checkpoint : stateUpdate,
|
|
48278
|
+
},
|
|
48279
|
+
];
|
|
48280
|
+
return resultEntry;
|
|
48281
|
+
});
|
|
47737
48282
|
resultPromises[serviceIndex] = promise;
|
|
47738
48283
|
}
|
|
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
|
-
});
|
|
48284
|
+
return Promise.all(resultPromises).then((results) => new Map(results));
|
|
47746
48285
|
}
|
|
47747
48286
|
/**
|
|
47748
48287
|
* A method that updates `recentlyAccumulated`, `accumulationQueue` and `timeslot` in state
|
|
@@ -47831,9 +48370,10 @@ class Accumulate {
|
|
|
47831
48370
|
const _gasCost = gasCost;
|
|
47832
48371
|
assertEmpty(rest);
|
|
47833
48372
|
const accumulated = accumulatableReports.subview(0, accumulatedReports);
|
|
47834
|
-
const { yieldedRoot, services, transfers
|
|
48373
|
+
const { yieldedRoot, services, transfers, validatorsData, privilegedServices, authorizationQueues, ...stateUpdateRest } = state;
|
|
47835
48374
|
assertEmpty(stateUpdateRest);
|
|
47836
|
-
// yielded root
|
|
48375
|
+
// transfers and yielded root are retrieved after each pvm invocation so we can ignore it here
|
|
48376
|
+
const _transfers = transfers;
|
|
47837
48377
|
const _yieldedRoot = yieldedRoot;
|
|
47838
48378
|
if (this.hasDuplicatedServiceIdCreated(services.created)) {
|
|
47839
48379
|
accumulate_logger.trace `Duplicated Service creation detected. Block is invalid.`;
|
|
@@ -47932,7 +48472,7 @@ class DeferredTransfers {
|
|
|
47932
48472
|
partiallyUpdatedState.updateServiceInfo(serviceId, newInfo);
|
|
47933
48473
|
const partialState = new AccumulateExternalities(this.chainSpec, this.blake2b, partiallyUpdatedState, serviceId, serviceId, timeslot);
|
|
47934
48474
|
const fetchExternalities = FetchExternalities.createForOnTransfer({ entropy, transfers }, this.chainSpec);
|
|
47935
|
-
let consumedGas =
|
|
48475
|
+
let consumedGas = gas_tryAsGas(0);
|
|
47936
48476
|
const hasTransfers = transfers.length > 0;
|
|
47937
48477
|
const isCodeCorrect = code !== null && code.length <= W_C;
|
|
47938
48478
|
if (!hasTransfers || !isCodeCorrect) {
|
|
@@ -47950,7 +48490,7 @@ class DeferredTransfers {
|
|
|
47950
48490
|
const executor = await PvmExecutor.createOnTransferExecutor(serviceId, code, { partialState, fetchExternalities }, this.pvm);
|
|
47951
48491
|
const args = encoder_Encoder.encodeObject(deferred_transfers_ARGS_CODEC, { timeslot, serviceId, transfersLength: numbers_tryAsU32(transfers.length) }, this.chainSpec);
|
|
47952
48492
|
const gas = transfers.reduce((acc, item) => acc + item.gas, 0n);
|
|
47953
|
-
consumedGas = (await executor.run(args,
|
|
48493
|
+
consumedGas = (await executor.run(args, gas_tryAsGas(gas))).consumedGas;
|
|
47954
48494
|
}
|
|
47955
48495
|
transferStatistics.set(serviceId, { count: numbers_tryAsU32(transfers.length), gasUsed: tryAsServiceGas(consumedGas) });
|
|
47956
48496
|
const [updatedState] = partialState.getStateUpdates();
|
|
@@ -49764,7 +50304,7 @@ async function createImporter(config) {
|
|
|
49764
50304
|
const interpreter = config.workerParams.pvm;
|
|
49765
50305
|
const blocks = db.getBlocksDb();
|
|
49766
50306
|
const states = db.getStatesDb();
|
|
49767
|
-
const hasher = new hasher_TransitionHasher(
|
|
50307
|
+
const hasher = new hasher_TransitionHasher(await keccakHasher, await blake2b);
|
|
49768
50308
|
const importer = new Importer(chainSpec, interpreter, hasher, main_logger, blocks, states);
|
|
49769
50309
|
return {
|
|
49770
50310
|
importer,
|
|
@@ -52421,7 +52961,7 @@ function initializeExtensions(api) {
|
|
|
52421
52961
|
}
|
|
52422
52962
|
|
|
52423
52963
|
;// CONCATENATED MODULE: ./packages/jam/node/package.json
|
|
52424
|
-
const package_namespaceObject = {"rE":"0.4.
|
|
52964
|
+
const package_namespaceObject = {"rE":"0.4.1"};
|
|
52425
52965
|
;// CONCATENATED MODULE: ./packages/workers/block-generator/generator.ts
|
|
52426
52966
|
|
|
52427
52967
|
|
|
@@ -52488,7 +53028,7 @@ class generator_Generator {
|
|
|
52488
53028
|
// select validator for block
|
|
52489
53029
|
const validatorId = tryAsValidatorIndex(newTimeSlot % 6);
|
|
52490
53030
|
// retriev data from previous block
|
|
52491
|
-
const hasher = new TransitionHasher(this.
|
|
53031
|
+
const hasher = new TransitionHasher(this.keccakHasher, this.blake2b);
|
|
52492
53032
|
const parentHeaderHash = this.lastHeaderHash;
|
|
52493
53033
|
const stateRoot = this.states.getStateRoot(this.lastState);
|
|
52494
53034
|
// create extrinsic
|
|
@@ -53055,7 +53595,7 @@ function readJsonBlock(file, chainSpec) {
|
|
|
53055
53595
|
var minimist = __nccwpck_require__(8595);
|
|
53056
53596
|
var minimist_default = /*#__PURE__*/__nccwpck_require__.n(minimist);
|
|
53057
53597
|
;// CONCATENATED MODULE: ./bin/jam/package.json
|
|
53058
|
-
const jam_package_namespaceObject = {"rE":"0.4.
|
|
53598
|
+
const jam_package_namespaceObject = {"rE":"0.4.1"};
|
|
53059
53599
|
;// CONCATENATED MODULE: ./bin/jam/args.ts
|
|
53060
53600
|
|
|
53061
53601
|
|