@typeberry/convert 0.5.10 → 0.5.11-10b197e
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/index.js +250 -115
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -4626,7 +4626,7 @@ function seeThrough(v) {
|
|
|
4626
4626
|
}
|
|
4627
4627
|
|
|
4628
4628
|
;// CONCATENATED MODULE: ./packages/core/utils/package.json
|
|
4629
|
-
const package_namespaceObject = {"rE":"0.5.
|
|
4629
|
+
const package_namespaceObject = {"rE":"0.5.11"};
|
|
4630
4630
|
;// CONCATENATED MODULE: ./packages/core/utils/result.ts
|
|
4631
4631
|
|
|
4632
4632
|
/**
|
|
@@ -5784,6 +5784,9 @@ class EndOfDataError extends Error {
|
|
|
5784
5784
|
/** Wrapper for `Decoder` that can skip bytes of fields in the data buffer instead of decoding them. */
|
|
5785
5785
|
class Skipper {
|
|
5786
5786
|
decoder;
|
|
5787
|
+
static new(decoder) {
|
|
5788
|
+
return new Skipper(decoder);
|
|
5789
|
+
}
|
|
5787
5790
|
constructor(decoder) {
|
|
5788
5791
|
this.decoder = decoder;
|
|
5789
5792
|
}
|
|
@@ -5906,7 +5909,7 @@ class descriptor_Descriptor {
|
|
|
5906
5909
|
*/
|
|
5907
5910
|
skipEncoded(decoder) {
|
|
5908
5911
|
const initBytes = decoder.bytesRead();
|
|
5909
|
-
this.skip(new
|
|
5912
|
+
this.skip(Skipper.new(decoder));
|
|
5910
5913
|
const endBytes = decoder.bytesRead();
|
|
5911
5914
|
return bytes_BytesBlob.blobFrom(decoder.source.subarray(initBytes, endBytes));
|
|
5912
5915
|
}
|
|
@@ -5924,6 +5927,7 @@ class descriptor_Descriptor {
|
|
|
5924
5927
|
|
|
5925
5928
|
|
|
5926
5929
|
|
|
5930
|
+
|
|
5927
5931
|
function tryAsExactBytes(a) {
|
|
5928
5932
|
check `${a.isExact} The value is not exact size estimation!`;
|
|
5929
5933
|
return a.bytes;
|
|
@@ -6073,12 +6077,12 @@ class encoder_Encoder {
|
|
|
6073
6077
|
this.offset += 1;
|
|
6074
6078
|
}
|
|
6075
6079
|
/**
|
|
6076
|
-
* Encode a single boolean discriminator using
|
|
6080
|
+
* Encode a single boolean discriminator using 1-byte encoding.
|
|
6077
6081
|
*
|
|
6078
6082
|
* https://graypaper.fluffylabs.dev/#/579bd12/375300375300
|
|
6079
6083
|
*/
|
|
6080
6084
|
bool(bool) {
|
|
6081
|
-
this.
|
|
6085
|
+
this.i8(tryAsU8(bool ? 1 : 0));
|
|
6082
6086
|
}
|
|
6083
6087
|
/**
|
|
6084
6088
|
* Prepare for encoding of a fixed-bytes number.
|
|
@@ -6430,7 +6434,7 @@ class ObjectView {
|
|
|
6430
6434
|
is already decoded (${this.lastDecodedFieldIdx}, ${String(lastField)}).
|
|
6431
6435
|
`;
|
|
6432
6436
|
let lastItem = this.cache.get(lastField);
|
|
6433
|
-
const skipper = new
|
|
6437
|
+
const skipper = Skipper.new(this.decoder);
|
|
6434
6438
|
// now skip all of the fields and further populate the cache.
|
|
6435
6439
|
for (let i = this.lastDecodedFieldIdx + 1; i <= index; i++) {
|
|
6436
6440
|
// create new cached prop
|
|
@@ -6537,7 +6541,7 @@ class SequenceView {
|
|
|
6537
6541
|
Unjustified call to 'decodeUpTo' - the index (${index}) is already decoded (${this.lastDecodedIdx}).
|
|
6538
6542
|
`;
|
|
6539
6543
|
let lastItem = this.cache.get(this.lastDecodedIdx);
|
|
6540
|
-
const skipper = new
|
|
6544
|
+
const skipper = Skipper.new(this.decoder);
|
|
6541
6545
|
// now skip all of the fields and further populate the cache.
|
|
6542
6546
|
for (let i = this.lastDecodedIdx + 1; i <= index; i++) {
|
|
6543
6547
|
// create new cached prop
|
|
@@ -6874,6 +6878,9 @@ function hasUniqueView(a) {
|
|
|
6874
6878
|
function objectView(Class, descriptors, sizeHint, skipper) {
|
|
6875
6879
|
// Create a View, based on the `AbstractView`.
|
|
6876
6880
|
class ClassView extends ObjectView {
|
|
6881
|
+
static new(d) {
|
|
6882
|
+
return new ClassView(d);
|
|
6883
|
+
}
|
|
6877
6884
|
constructor(d) {
|
|
6878
6885
|
super(d, Class, descriptors);
|
|
6879
6886
|
}
|
|
@@ -6893,8 +6900,8 @@ function objectView(Class, descriptors, sizeHint, skipper) {
|
|
|
6893
6900
|
const encoded = t.encoded();
|
|
6894
6901
|
e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
|
|
6895
6902
|
}, (d) => {
|
|
6896
|
-
const view = new
|
|
6897
|
-
skipper(new
|
|
6903
|
+
const view = ClassView.new(d.clone());
|
|
6904
|
+
skipper(Skipper.new(d));
|
|
6898
6905
|
return view;
|
|
6899
6906
|
}, skipper);
|
|
6900
6907
|
}
|
|
@@ -6914,7 +6921,7 @@ function sequenceViewVarLen(type, options) {
|
|
|
6914
6921
|
e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
|
|
6915
6922
|
}, (d) => {
|
|
6916
6923
|
const view = new SequenceView(d.clone(), type);
|
|
6917
|
-
skipper(new
|
|
6924
|
+
skipper(Skipper.new(d));
|
|
6918
6925
|
return view;
|
|
6919
6926
|
}, skipper);
|
|
6920
6927
|
}
|
|
@@ -6929,7 +6936,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
|
|
|
6929
6936
|
e.bytes(bytes_Bytes.fromBlob(encoded.raw, encoded.length));
|
|
6930
6937
|
}, (d) => {
|
|
6931
6938
|
const view = new SequenceView(d.clone(), type, fixedLength);
|
|
6932
|
-
skipper(new
|
|
6939
|
+
skipper(Skipper.new(d));
|
|
6933
6940
|
return view;
|
|
6934
6941
|
}, skipper);
|
|
6935
6942
|
}
|
|
@@ -7617,6 +7624,9 @@ const ED25519_SIGNATURE_BYTES = 64;
|
|
|
7617
7624
|
class Ed25519Pair {
|
|
7618
7625
|
pubKey;
|
|
7619
7626
|
_privKey;
|
|
7627
|
+
static new(pubKey, _privKey) {
|
|
7628
|
+
return new Ed25519Pair(pubKey, _privKey);
|
|
7629
|
+
}
|
|
7620
7630
|
constructor(
|
|
7621
7631
|
/** Public key */
|
|
7622
7632
|
pubKey,
|
|
@@ -7629,7 +7639,7 @@ class Ed25519Pair {
|
|
|
7629
7639
|
/** Create a private key from given raw bytes. */
|
|
7630
7640
|
async function ed25519_privateKey(privKey) {
|
|
7631
7641
|
const pubKey = await ed.getPublicKeyAsync(privKey.raw);
|
|
7632
|
-
return new
|
|
7642
|
+
return Ed25519Pair.new(Bytes.fromBlob(pubKey, ED25519_KEY_BYTES).asOpaque(), privKey.asOpaque());
|
|
7633
7643
|
}
|
|
7634
7644
|
/** Sign given piece of data using provided key pair. */
|
|
7635
7645
|
async function sign(key, message) {
|
|
@@ -7761,7 +7771,9 @@ const ZERO_HASH = bytes_Bytes.zero(hash_HASH_SIZE);
|
|
|
7761
7771
|
class WithHash extends WithDebug {
|
|
7762
7772
|
hash;
|
|
7763
7773
|
data;
|
|
7764
|
-
|
|
7774
|
+
static new(hash, data) {
|
|
7775
|
+
return new WithHash(hash, data);
|
|
7776
|
+
}
|
|
7765
7777
|
constructor(hash, data) {
|
|
7766
7778
|
super();
|
|
7767
7779
|
this.hash = hash;
|
|
@@ -7773,6 +7785,9 @@ class WithHash extends WithDebug {
|
|
|
7773
7785
|
*/
|
|
7774
7786
|
class WithHashAndBytes extends WithHash {
|
|
7775
7787
|
encoded;
|
|
7788
|
+
static create(hash, data, encoded) {
|
|
7789
|
+
return new WithHashAndBytes(hash, data, encoded);
|
|
7790
|
+
}
|
|
7776
7791
|
constructor(hash, data, encoded) {
|
|
7777
7792
|
super(hash, data);
|
|
7778
7793
|
this.encoded = encoded;
|
|
@@ -8481,6 +8496,9 @@ class MultiMap {
|
|
|
8481
8496
|
* Pass the number of keys and optionally mappers from keys to primitive types
|
|
8482
8497
|
* if needed.
|
|
8483
8498
|
*/
|
|
8499
|
+
static new(keysLength, keyMappers) {
|
|
8500
|
+
return new MultiMap(keysLength, keyMappers);
|
|
8501
|
+
}
|
|
8484
8502
|
constructor(keysLength, keyMappers) {
|
|
8485
8503
|
check `${keysLength > 0} Keys cannot be empty.`;
|
|
8486
8504
|
check `${keyMappers === undefined || keyMappers.length === keysLength} Incorrect number of key mappers given!`;
|
|
@@ -9029,6 +9047,9 @@ class ChainSpec extends WithDebug {
|
|
|
9029
9047
|
maxRefineGas;
|
|
9030
9048
|
/** `L`: The maximum age in timeslots of the lookup anchor. */
|
|
9031
9049
|
maxLookupAnchorAge;
|
|
9050
|
+
static new(data) {
|
|
9051
|
+
return new ChainSpec(data);
|
|
9052
|
+
}
|
|
9032
9053
|
constructor(data) {
|
|
9033
9054
|
super();
|
|
9034
9055
|
this.name = data.name;
|
|
@@ -9051,7 +9072,7 @@ class ChainSpec extends WithDebug {
|
|
|
9051
9072
|
}
|
|
9052
9073
|
}
|
|
9053
9074
|
/** Set of values for "tiny" chain as defined in JAM test vectors. */
|
|
9054
|
-
const chain_spec_tinyChainSpec = new
|
|
9075
|
+
const chain_spec_tinyChainSpec = ChainSpec.new({
|
|
9055
9076
|
name: "tiny",
|
|
9056
9077
|
validatorsCount: numbers_tryAsU16(6),
|
|
9057
9078
|
coresCount: numbers_tryAsU16(2),
|
|
@@ -9073,7 +9094,7 @@ const chain_spec_tinyChainSpec = new ChainSpec({
|
|
|
9073
9094
|
* Set of values for "full" chain as defined in JAM test vectors.
|
|
9074
9095
|
* Please note that only validatorsCount and epochLength are "full", the rest is copied from "tiny".
|
|
9075
9096
|
*/
|
|
9076
|
-
const chain_spec_fullChainSpec = new
|
|
9097
|
+
const chain_spec_fullChainSpec = ChainSpec.new({
|
|
9077
9098
|
name: "full",
|
|
9078
9099
|
validatorsCount: numbers_tryAsU16(1023),
|
|
9079
9100
|
coresCount: numbers_tryAsU16(341),
|
|
@@ -9096,6 +9117,9 @@ class Bootnode {
|
|
|
9096
9117
|
id;
|
|
9097
9118
|
ip;
|
|
9098
9119
|
port;
|
|
9120
|
+
static new(id, ip, port) {
|
|
9121
|
+
return new Bootnode(id, ip, port);
|
|
9122
|
+
}
|
|
9099
9123
|
constructor(
|
|
9100
9124
|
/** Network address derived from the node's cryptographic public key (always 53-character?) */
|
|
9101
9125
|
id,
|
|
@@ -9806,37 +9830,37 @@ const work_package_MAX_NUMBER_OF_WORK_ITEMS = 16;
|
|
|
9806
9830
|
/**
|
|
9807
9831
|
* A piece of work done within a core.
|
|
9808
9832
|
*
|
|
9809
|
-
* `P = (j ∈ Y, h ∈ NS, u ∈ H,
|
|
9833
|
+
* `P = (j ∈ Y, h ∈ NS, u ∈ H, f ∈ Y, x ∈ X, w ∈ ⟦I⟧1∶I)
|
|
9810
9834
|
*
|
|
9811
9835
|
* https://graypaper.fluffylabs.dev/#/579bd12/197000197200
|
|
9812
9836
|
*/
|
|
9813
9837
|
class work_package_WorkPackage extends WithDebug {
|
|
9814
|
-
|
|
9838
|
+
authToken;
|
|
9815
9839
|
authCodeHost;
|
|
9816
9840
|
authCodeHash;
|
|
9817
|
-
|
|
9841
|
+
authConfiguration;
|
|
9818
9842
|
context;
|
|
9819
9843
|
items;
|
|
9820
9844
|
static Codec = codec_codec.Class(work_package_WorkPackage, {
|
|
9821
9845
|
authCodeHost: codec_codec.u32.asOpaque(),
|
|
9822
9846
|
authCodeHash: codec_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
9823
9847
|
context: RefineContext.Codec,
|
|
9824
|
-
|
|
9825
|
-
|
|
9848
|
+
authToken: codec_codec.blob,
|
|
9849
|
+
authConfiguration: codec_codec.blob,
|
|
9826
9850
|
items: codec_codec.sequenceVarLen(work_item_WorkItem.Codec).convert((x) => x, (items) => FixedSizeArray.new(items, tryAsWorkItemsCount(items.length))),
|
|
9827
9851
|
});
|
|
9828
|
-
static create({
|
|
9829
|
-
return new work_package_WorkPackage(
|
|
9852
|
+
static create({ authToken, authCodeHost, authCodeHash, authConfiguration, context, items, }) {
|
|
9853
|
+
return new work_package_WorkPackage(authToken, authCodeHost, authCodeHash, authConfiguration, context, items);
|
|
9830
9854
|
}
|
|
9831
9855
|
constructor(
|
|
9832
9856
|
/** `j`: simple blob acting as an authorization token */
|
|
9833
|
-
|
|
9857
|
+
authToken,
|
|
9834
9858
|
/** `h`: index of the service that hosts the authorization code */
|
|
9835
9859
|
authCodeHost,
|
|
9836
9860
|
/** `u`: authorization code hash */
|
|
9837
9861
|
authCodeHash,
|
|
9838
|
-
/** `
|
|
9839
|
-
|
|
9862
|
+
/** `f`: authorization configuration blob */
|
|
9863
|
+
authConfiguration,
|
|
9840
9864
|
/** `x`: context in which the refine function should run */
|
|
9841
9865
|
context,
|
|
9842
9866
|
/**
|
|
@@ -9847,10 +9871,10 @@ class work_package_WorkPackage extends WithDebug {
|
|
|
9847
9871
|
*/
|
|
9848
9872
|
items) {
|
|
9849
9873
|
super();
|
|
9850
|
-
this.
|
|
9874
|
+
this.authToken = authToken;
|
|
9851
9875
|
this.authCodeHost = authCodeHost;
|
|
9852
9876
|
this.authCodeHash = authCodeHash;
|
|
9853
|
-
this.
|
|
9877
|
+
this.authConfiguration = authConfiguration;
|
|
9854
9878
|
this.context = context;
|
|
9855
9879
|
this.items = items;
|
|
9856
9880
|
}
|
|
@@ -10448,7 +10472,7 @@ class HeaderViewWithHash extends WithHash {
|
|
|
10448
10472
|
data: header_Header.Codec.View,
|
|
10449
10473
|
});
|
|
10450
10474
|
static create({ hash, data }) {
|
|
10451
|
-
return new
|
|
10475
|
+
return WithHash.new(hash, data);
|
|
10452
10476
|
}
|
|
10453
10477
|
}
|
|
10454
10478
|
/** Encoding of header + hash. */
|
|
@@ -11250,7 +11274,7 @@ function parseBootnode(v) {
|
|
|
11250
11274
|
throw new Error(`Invalid port number: "${port}"`);
|
|
11251
11275
|
}
|
|
11252
11276
|
// TODO [ToDr] we should probably validate the name!
|
|
11253
|
-
return new
|
|
11277
|
+
return Bootnode.new(opaque_asOpaqueType(name), ip, portNumber);
|
|
11254
11278
|
}
|
|
11255
11279
|
/**
|
|
11256
11280
|
* Configuration file for any blockchain network built on the JAM protocol
|
|
@@ -11833,6 +11857,9 @@ class FuzzTarget {
|
|
|
11833
11857
|
sender;
|
|
11834
11858
|
spec;
|
|
11835
11859
|
sessionFeatures = 0;
|
|
11860
|
+
static new(msgHandler, sender, spec) {
|
|
11861
|
+
return new FuzzTarget(msgHandler, sender, spec);
|
|
11862
|
+
}
|
|
11836
11863
|
constructor(msgHandler, sender, spec) {
|
|
11837
11864
|
this.msgHandler = msgHandler;
|
|
11838
11865
|
this.sender = sender;
|
|
@@ -12017,6 +12044,9 @@ class MemorySegment extends WithDebug {
|
|
|
12017
12044
|
end;
|
|
12018
12045
|
data;
|
|
12019
12046
|
static from({ start, end, data }) {
|
|
12047
|
+
return MemorySegment.new(start, end, data);
|
|
12048
|
+
}
|
|
12049
|
+
static new(start, end, data) {
|
|
12020
12050
|
return new MemorySegment(start, end, data);
|
|
12021
12051
|
}
|
|
12022
12052
|
constructor(start, end, data) {
|
|
@@ -12031,6 +12061,9 @@ class SpiMemory extends WithDebug {
|
|
|
12031
12061
|
writeable;
|
|
12032
12062
|
sbrkIndex;
|
|
12033
12063
|
heapEnd;
|
|
12064
|
+
static new(readable, writeable, sbrkIndex, heapEnd) {
|
|
12065
|
+
return new SpiMemory(readable, writeable, sbrkIndex, heapEnd);
|
|
12066
|
+
}
|
|
12034
12067
|
constructor(readable, writeable, sbrkIndex, heapEnd) {
|
|
12035
12068
|
super();
|
|
12036
12069
|
this.readable = readable;
|
|
@@ -12043,6 +12076,9 @@ class SpiProgram extends WithDebug {
|
|
|
12043
12076
|
code;
|
|
12044
12077
|
memory;
|
|
12045
12078
|
registers;
|
|
12079
|
+
static new(code, memory, registers) {
|
|
12080
|
+
return new SpiProgram(code, memory, registers);
|
|
12081
|
+
}
|
|
12046
12082
|
constructor(code, memory, registers) {
|
|
12047
12083
|
super();
|
|
12048
12084
|
this.code = code;
|
|
@@ -12101,10 +12137,10 @@ function decode_standard_program_decodeStandardProgram(program, args) {
|
|
|
12101
12137
|
heapDataEnd < heapZerosEnd && getMemorySegment(heapDataEnd, heapZerosEnd),
|
|
12102
12138
|
stackStart < stackEnd && getMemorySegment(stackStart, stackEnd),
|
|
12103
12139
|
].filter(nonEmpty);
|
|
12104
|
-
return new
|
|
12140
|
+
return SpiProgram.new(code, SpiMemory.new(readableMemory, writeableMemory, heapZerosEnd, stackStart), getRegisters(args.length));
|
|
12105
12141
|
}
|
|
12106
12142
|
function getMemorySegment(start, end, data = null) {
|
|
12107
|
-
return new
|
|
12143
|
+
return MemorySegment.new(start, end, data);
|
|
12108
12144
|
}
|
|
12109
12145
|
function getRegisters(argsLength) {
|
|
12110
12146
|
const regs = new BigUint64Array(decode_standard_program_NO_OF_REGISTERS);
|
|
@@ -12784,6 +12820,9 @@ class LookupHistoryItem {
|
|
|
12784
12820
|
hash;
|
|
12785
12821
|
length;
|
|
12786
12822
|
slots;
|
|
12823
|
+
static new(hash, length, slots) {
|
|
12824
|
+
return new LookupHistoryItem(hash, length, slots);
|
|
12825
|
+
}
|
|
12787
12826
|
constructor(hash, length,
|
|
12788
12827
|
/**
|
|
12789
12828
|
* Preimage availability history as a sequence of time slots.
|
|
@@ -13030,6 +13069,9 @@ class StatisticsData {
|
|
|
13030
13069
|
class InMemoryStateView {
|
|
13031
13070
|
chainSpec;
|
|
13032
13071
|
state;
|
|
13072
|
+
static new(chainSpec, state) {
|
|
13073
|
+
return new InMemoryStateView(chainSpec, state);
|
|
13074
|
+
}
|
|
13033
13075
|
constructor(chainSpec, state) {
|
|
13034
13076
|
this.chainSpec = chainSpec;
|
|
13035
13077
|
this.state = state;
|
|
@@ -13351,6 +13393,10 @@ var UpdateError;
|
|
|
13351
13393
|
class InMemoryService extends WithDebug {
|
|
13352
13394
|
serviceId;
|
|
13353
13395
|
data;
|
|
13396
|
+
/** Create a new in-memory service wrapping the given id and data. */
|
|
13397
|
+
static new(serviceId, data) {
|
|
13398
|
+
return new InMemoryService(serviceId, data);
|
|
13399
|
+
}
|
|
13354
13400
|
constructor(
|
|
13355
13401
|
/** Service id. */
|
|
13356
13402
|
serviceId,
|
|
@@ -13390,7 +13436,7 @@ class InMemoryService extends WithDebug {
|
|
|
13390
13436
|
}
|
|
13391
13437
|
/** Return identical `InMemoryService` which does not share any references. */
|
|
13392
13438
|
clone() {
|
|
13393
|
-
return new
|
|
13439
|
+
return InMemoryService.new(this.serviceId, {
|
|
13394
13440
|
info: ServiceAccountInfo.create(this.data.info),
|
|
13395
13441
|
preimages: HashDictionary.fromEntries(Array.from(this.data.preimages.entries())),
|
|
13396
13442
|
lookupHistory: HashDictionary.fromEntries(Array.from(this.data.lookupHistory.entries()).map(([k, v]) => [k, v.slice()])),
|
|
@@ -13421,7 +13467,7 @@ class InMemoryService extends WithDebug {
|
|
|
13421
13467
|
throw new Error(`Service ${service.serviceId} is missing expected lookupHistory: ${hash}, ${length}`);
|
|
13422
13468
|
}
|
|
13423
13469
|
const items = lookupHistory.get(hash) ?? [];
|
|
13424
|
-
items.push(new
|
|
13470
|
+
items.push(LookupHistoryItem.new(hash, length, slots));
|
|
13425
13471
|
lookupHistory.set(hash, items);
|
|
13426
13472
|
}
|
|
13427
13473
|
// copy storage
|
|
@@ -13432,7 +13478,7 @@ class InMemoryService extends WithDebug {
|
|
|
13432
13478
|
}
|
|
13433
13479
|
storage.set(key.toString(), StorageItem.create({ key, value }));
|
|
13434
13480
|
}
|
|
13435
|
-
return new
|
|
13481
|
+
return InMemoryService.new(service.serviceId, {
|
|
13436
13482
|
info,
|
|
13437
13483
|
preimages,
|
|
13438
13484
|
storage,
|
|
@@ -13590,7 +13636,7 @@ class InMemoryState extends WithDebug {
|
|
|
13590
13636
|
if (slot !== null) {
|
|
13591
13637
|
const lookupHistory = service.data.lookupHistory.get(preimage.hash);
|
|
13592
13638
|
const length = numbers_tryAsU32(preimage.blob.length);
|
|
13593
|
-
const lookup = new
|
|
13639
|
+
const lookup = LookupHistoryItem.new(preimage.hash, length, service_tryAsLookupHistorySlots([slot]));
|
|
13594
13640
|
if (lookupHistory === undefined) {
|
|
13595
13641
|
// no lookup history for that preimage at all (edge case, should be requested)
|
|
13596
13642
|
service.data.lookupHistory.set(preimage.hash, [lookup]);
|
|
@@ -13637,7 +13683,7 @@ class InMemoryState extends WithDebug {
|
|
|
13637
13683
|
if (this.services.has(serviceId)) {
|
|
13638
13684
|
return result_Result.error(UpdateError.DuplicateService, () => `${serviceId} already exists!`);
|
|
13639
13685
|
}
|
|
13640
|
-
this.services.set(serviceId, new
|
|
13686
|
+
this.services.set(serviceId, InMemoryService.new(serviceId, {
|
|
13641
13687
|
info: account,
|
|
13642
13688
|
preimages: HashDictionary.new(),
|
|
13643
13689
|
storage: new Map(),
|
|
@@ -13708,7 +13754,7 @@ class InMemoryState extends WithDebug {
|
|
|
13708
13754
|
this.services = s.services;
|
|
13709
13755
|
}
|
|
13710
13756
|
view() {
|
|
13711
|
-
return new
|
|
13757
|
+
return InMemoryStateView.new(this.chainSpec, this);
|
|
13712
13758
|
}
|
|
13713
13759
|
/**
|
|
13714
13760
|
* Create an empty and possibly incoherent `InMemoryState`.
|
|
@@ -13875,7 +13921,7 @@ const preimageStatusFromJson = json.object({
|
|
|
13875
13921
|
length: "number",
|
|
13876
13922
|
},
|
|
13877
13923
|
value: json.array("number"),
|
|
13878
|
-
}, ({ key, value }) => new
|
|
13924
|
+
}, ({ key, value }) => LookupHistoryItem.new(key.hash, numbers_tryAsU32(key.length), value));
|
|
13879
13925
|
class JsonService {
|
|
13880
13926
|
static fromJson = json.object({
|
|
13881
13927
|
id: "number",
|
|
@@ -13901,7 +13947,7 @@ class JsonService {
|
|
|
13901
13947
|
for (const [key, item] of entries) {
|
|
13902
13948
|
storage.set(key.toString(), item);
|
|
13903
13949
|
}
|
|
13904
|
-
return new
|
|
13950
|
+
return InMemoryService.new(id, {
|
|
13905
13951
|
info: data.service,
|
|
13906
13952
|
preimages,
|
|
13907
13953
|
storage,
|
|
@@ -13914,7 +13960,7 @@ class JsonService {
|
|
|
13914
13960
|
const preimageStatusFromJson072 = json.object({
|
|
13915
13961
|
hash: fromJson.bytes32(),
|
|
13916
13962
|
status: json.array("number"),
|
|
13917
|
-
}, ({ hash, status }) => new
|
|
13963
|
+
}, ({ hash, status }) => LookupHistoryItem.new(hash, numbers_tryAsU32(0), status));
|
|
13918
13964
|
class JsonServicePre072 {
|
|
13919
13965
|
static fromJson = json.object({
|
|
13920
13966
|
id: "number",
|
|
@@ -13930,7 +13976,7 @@ class JsonServicePre072 {
|
|
|
13930
13976
|
for (const item of data.lookup_meta ?? data.preimages_status ?? []) {
|
|
13931
13977
|
const data = lookupHistory.get(item.hash) ?? [];
|
|
13932
13978
|
const length = numbers_tryAsU32(preimages.get(item.hash)?.blob.length ?? item.length);
|
|
13933
|
-
data.push(new
|
|
13979
|
+
data.push(LookupHistoryItem.new(item.hash, length, item.slots));
|
|
13934
13980
|
lookupHistory.set(item.hash, data);
|
|
13935
13981
|
}
|
|
13936
13982
|
const storage = new Map();
|
|
@@ -13941,7 +13987,7 @@ class JsonServicePre072 {
|
|
|
13941
13987
|
for (const [key, item] of entries) {
|
|
13942
13988
|
storage.set(key.toString(), item);
|
|
13943
13989
|
}
|
|
13944
|
-
return new
|
|
13990
|
+
return InMemoryService.new(id, {
|
|
13945
13991
|
info: data.service,
|
|
13946
13992
|
preimages,
|
|
13947
13993
|
storage,
|
|
@@ -14612,11 +14658,14 @@ const dumpCodec = descriptor_Descriptor.new("Dump", { bytes: 64, isExact: false
|
|
|
14612
14658
|
class SerializedStateView {
|
|
14613
14659
|
spec;
|
|
14614
14660
|
backend;
|
|
14661
|
+
/** Best-effort list of recently active services. */
|
|
14615
14662
|
recentlyUsedServices;
|
|
14616
14663
|
viewCache;
|
|
14617
|
-
|
|
14618
|
-
|
|
14619
|
-
|
|
14664
|
+
/** Build a new view over an existing serialized-state backend. */
|
|
14665
|
+
static new(args) {
|
|
14666
|
+
return new SerializedStateView(args.spec, args.backend, args.recentlyUsedServices, args.viewCache);
|
|
14667
|
+
}
|
|
14668
|
+
constructor(spec, backend, recentlyUsedServices, viewCache) {
|
|
14620
14669
|
this.spec = spec;
|
|
14621
14670
|
this.backend = backend;
|
|
14622
14671
|
this.recentlyUsedServices = recentlyUsedServices;
|
|
@@ -14732,7 +14781,12 @@ class serialized_state_SerializedState {
|
|
|
14732
14781
|
}
|
|
14733
14782
|
/** Return a non-decoding version of the state. */
|
|
14734
14783
|
view() {
|
|
14735
|
-
return new
|
|
14784
|
+
return SerializedStateView.new({
|
|
14785
|
+
spec: this.spec,
|
|
14786
|
+
backend: this.backend,
|
|
14787
|
+
recentlyUsedServices: this.recentlyUsedServices,
|
|
14788
|
+
viewCache: this.viewCache,
|
|
14789
|
+
});
|
|
14736
14790
|
}
|
|
14737
14791
|
// TODO [ToDr] Temporary method to update the state,
|
|
14738
14792
|
// without changing references.
|
|
@@ -14752,7 +14806,7 @@ class serialized_state_SerializedState {
|
|
|
14752
14806
|
if (!this.recentlyUsedServices.includes(id)) {
|
|
14753
14807
|
this.recentlyUsedServices.push(id);
|
|
14754
14808
|
}
|
|
14755
|
-
return new
|
|
14809
|
+
return SerializedService.new(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
|
|
14756
14810
|
}
|
|
14757
14811
|
retrieve(k, description) {
|
|
14758
14812
|
const data = this.retrieveOptional(k);
|
|
@@ -14838,6 +14892,9 @@ class SerializedService {
|
|
|
14838
14892
|
serviceId;
|
|
14839
14893
|
accountInfo;
|
|
14840
14894
|
retrieveOptional;
|
|
14895
|
+
static new(blake2b, serviceId, accountInfo, retrieveOptional) {
|
|
14896
|
+
return new SerializedService(blake2b, serviceId, accountInfo, retrieveOptional);
|
|
14897
|
+
}
|
|
14841
14898
|
constructor(blake2b,
|
|
14842
14899
|
/** Service id */
|
|
14843
14900
|
serviceId, accountInfo, retrieveOptional) {
|
|
@@ -14952,13 +15009,11 @@ class TrieNode {
|
|
|
14952
15009
|
}
|
|
14953
15010
|
/** View this node as a branch node */
|
|
14954
15011
|
asBranchNode() {
|
|
14955
|
-
|
|
14956
|
-
return new BranchNode(this);
|
|
15012
|
+
return BranchNode.viewOf(this);
|
|
14957
15013
|
}
|
|
14958
15014
|
/** View this node as a leaf node */
|
|
14959
15015
|
asLeafNode() {
|
|
14960
|
-
|
|
14961
|
-
return new LeafNode(this);
|
|
15016
|
+
return LeafNode.viewOf(this);
|
|
14962
15017
|
}
|
|
14963
15018
|
toString() {
|
|
14964
15019
|
return bytes_BytesBlob.blobFrom(this.raw).toString();
|
|
@@ -14978,10 +15033,7 @@ class TrieNode {
|
|
|
14978
15033
|
*/
|
|
14979
15034
|
class BranchNode {
|
|
14980
15035
|
node;
|
|
14981
|
-
|
|
14982
|
-
constructor(node) {
|
|
14983
|
-
this.node = node;
|
|
14984
|
-
}
|
|
15036
|
+
/** Build a branch node from its left and right sub-node hashes. */
|
|
14985
15037
|
static fromSubNodes(left, right) {
|
|
14986
15038
|
const node = new TrieNode();
|
|
14987
15039
|
node.raw.set(left.raw, 0);
|
|
@@ -14990,6 +15042,15 @@ class BranchNode {
|
|
|
14990
15042
|
node.raw[0] &= FIRST_BIT_SET_NEG;
|
|
14991
15043
|
return new BranchNode(node);
|
|
14992
15044
|
}
|
|
15045
|
+
/** View an existing raw trie node as a branch node (validates node type). */
|
|
15046
|
+
static viewOf(node) {
|
|
15047
|
+
debug_check `${node.getNodeType() === NodeType.Branch} not a branch!`;
|
|
15048
|
+
return new BranchNode(node);
|
|
15049
|
+
}
|
|
15050
|
+
// Underlying raw node.
|
|
15051
|
+
constructor(node) {
|
|
15052
|
+
this.node = node;
|
|
15053
|
+
}
|
|
14993
15054
|
/** Get the hash of the left sub-trie. */
|
|
14994
15055
|
getLeft() {
|
|
14995
15056
|
return bytes_Bytes.fromBlob(this.node.raw.subarray(0, hash_HASH_SIZE), hash_HASH_SIZE).asOpaque();
|
|
@@ -15020,9 +15081,6 @@ class BranchNode {
|
|
|
15020
15081
|
class LeafNode {
|
|
15021
15082
|
// Underlying raw node.
|
|
15022
15083
|
node;
|
|
15023
|
-
constructor(node) {
|
|
15024
|
-
this.node = node;
|
|
15025
|
-
}
|
|
15026
15084
|
static fromValue(key, value, valueHash) {
|
|
15027
15085
|
const node = new TrieNode();
|
|
15028
15086
|
// The value will fit in the leaf itself.
|
|
@@ -15042,6 +15100,14 @@ class LeafNode {
|
|
|
15042
15100
|
}
|
|
15043
15101
|
return new LeafNode(node);
|
|
15044
15102
|
}
|
|
15103
|
+
/** View an existing raw trie node as a leaf node (validates node type). */
|
|
15104
|
+
static viewOf(node) {
|
|
15105
|
+
debug_check `${node.getNodeType() !== NodeType.Branch} not a leaf!`;
|
|
15106
|
+
return new LeafNode(node);
|
|
15107
|
+
}
|
|
15108
|
+
constructor(node) {
|
|
15109
|
+
this.node = node;
|
|
15110
|
+
}
|
|
15045
15111
|
/** Get the key (truncated to 31 bytes). */
|
|
15046
15112
|
getKey() {
|
|
15047
15113
|
return bytes_Bytes.fromBlob(this.node.raw.subarray(1, TRUNCATED_KEY_BYTES + 1), TRUNCATED_KEY_BYTES).asOpaque();
|
|
@@ -15089,6 +15155,9 @@ class LeafNode {
|
|
|
15089
15155
|
class NodesDb {
|
|
15090
15156
|
hasher;
|
|
15091
15157
|
nodes = HashDictionary.new();
|
|
15158
|
+
static new(hasher) {
|
|
15159
|
+
return new NodesDb(hasher);
|
|
15160
|
+
}
|
|
15092
15161
|
constructor(hasher) {
|
|
15093
15162
|
this.hasher = hasher;
|
|
15094
15163
|
}
|
|
@@ -15130,6 +15199,9 @@ class NodesDb {
|
|
|
15130
15199
|
* A version of `NodesDb` augmented with mutating methods.
|
|
15131
15200
|
*/
|
|
15132
15201
|
class WriteableNodesDb extends NodesDb {
|
|
15202
|
+
static new(hasher) {
|
|
15203
|
+
return new WriteableNodesDb(hasher);
|
|
15204
|
+
}
|
|
15133
15205
|
remove(hash) {
|
|
15134
15206
|
return NodesDb.withHashCompat(hash, (key) => {
|
|
15135
15207
|
this.nodes.delete(key);
|
|
@@ -15158,7 +15230,7 @@ class InMemoryTrie {
|
|
|
15158
15230
|
root;
|
|
15159
15231
|
/** Create an empty in-memory trie. */
|
|
15160
15232
|
static empty(hasher) {
|
|
15161
|
-
return new InMemoryTrie(new
|
|
15233
|
+
return new InMemoryTrie(WriteableNodesDb.new(hasher));
|
|
15162
15234
|
}
|
|
15163
15235
|
/** Given a collection of leaves, compute the state root. */
|
|
15164
15236
|
static computeStateRoot(hasher, leaves) {
|
|
@@ -15246,7 +15318,7 @@ class InMemoryTrie {
|
|
|
15246
15318
|
static fromLeaves(hasher, leaves) {
|
|
15247
15319
|
// TODO [ToDr] [opti] Pair up the leaves and build upper levels.
|
|
15248
15320
|
let root = null;
|
|
15249
|
-
const nodes = new
|
|
15321
|
+
const nodes = WriteableNodesDb.new(hasher);
|
|
15250
15322
|
for (const leaf of leaves) {
|
|
15251
15323
|
root = trieInsert(root, nodes, leaf);
|
|
15252
15324
|
}
|
|
@@ -15970,7 +16042,7 @@ const lookupHistoryItemCodec = codec_codec.object({
|
|
|
15970
16042
|
slots: codec_codec
|
|
15971
16043
|
.readonlyArray(codec_codec.sequenceVarLen(codec_codec.u32.asOpaque()))
|
|
15972
16044
|
.convert(seeThrough, service_tryAsLookupHistorySlots),
|
|
15973
|
-
}, "LookupHistoryItem", ({ hash, length, slots }) => new
|
|
16045
|
+
}, "LookupHistoryItem", ({ hash, length, slots }) => LookupHistoryItem.new(hash, length, slots));
|
|
15974
16046
|
const lookupHistoryEntryCodec = codec_codec.object({
|
|
15975
16047
|
key: codec_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
15976
16048
|
data: codec_codec.sequenceVarLen(lookupHistoryItemCodec),
|
|
@@ -16199,10 +16271,10 @@ const workPackageFromJson = json.object({
|
|
|
16199
16271
|
context: refineContextFromJson,
|
|
16200
16272
|
items: json.array(workItemFromJson),
|
|
16201
16273
|
}, ({ authorization, auth_code_host, auth_code_hash, authorizer_config, context, items }) => work_package_WorkPackage.create({
|
|
16202
|
-
authorization,
|
|
16274
|
+
authToken: authorization,
|
|
16203
16275
|
authCodeHost: auth_code_host,
|
|
16204
16276
|
authCodeHash: auth_code_hash,
|
|
16205
|
-
|
|
16277
|
+
authConfiguration: authorizer_config,
|
|
16206
16278
|
context,
|
|
16207
16279
|
items: FixedSizeArray.new(items, tryAsWorkItemsCount(items.length)),
|
|
16208
16280
|
}));
|
|
@@ -16287,6 +16359,9 @@ class mask_Mask {
|
|
|
16287
16359
|
* There are instructions at indices `0, 3, 5, 9`.
|
|
16288
16360
|
*/
|
|
16289
16361
|
lookupTableForward;
|
|
16362
|
+
static new(mask) {
|
|
16363
|
+
return new mask_Mask(mask);
|
|
16364
|
+
}
|
|
16290
16365
|
constructor(mask) {
|
|
16291
16366
|
this.lookupTableForward = this.buildLookupTableForward(mask);
|
|
16292
16367
|
}
|
|
@@ -16371,7 +16446,7 @@ class nibbles_decoder_NibblesDecoder {
|
|
|
16371
16446
|
const IMMEDIATE_AND_OFFSET_MAX_LENGTH = 4;
|
|
16372
16447
|
class args_decoder_ArgsDecoder {
|
|
16373
16448
|
nibblesDecoder = new NibblesDecoder();
|
|
16374
|
-
offsetDecoder = new
|
|
16449
|
+
offsetDecoder = ImmediateDecoder.new();
|
|
16375
16450
|
code = new Uint8Array();
|
|
16376
16451
|
mask = Mask.empty();
|
|
16377
16452
|
reset(code, mask) {
|
|
@@ -16544,7 +16619,7 @@ const args_decoding_results_createResults = () => {
|
|
|
16544
16619
|
results[ArgumentType.ONE_IMMEDIATE] = {
|
|
16545
16620
|
type: ArgumentType.ONE_IMMEDIATE,
|
|
16546
16621
|
noOfBytesToSkip: 1,
|
|
16547
|
-
immediateDecoder: new
|
|
16622
|
+
immediateDecoder: ImmediateDecoder.new(),
|
|
16548
16623
|
};
|
|
16549
16624
|
results[ArgumentType.TWO_REGISTERS] = {
|
|
16550
16625
|
type: ArgumentType.TWO_REGISTERS,
|
|
@@ -16563,7 +16638,7 @@ const args_decoding_results_createResults = () => {
|
|
|
16563
16638
|
type: ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET,
|
|
16564
16639
|
noOfBytesToSkip: 1,
|
|
16565
16640
|
registerIndex: 0,
|
|
16566
|
-
immediateDecoder: new
|
|
16641
|
+
immediateDecoder: ImmediateDecoder.new(),
|
|
16567
16642
|
nextPc: 0,
|
|
16568
16643
|
};
|
|
16569
16644
|
results[ArgumentType.TWO_REGISTERS_ONE_OFFSET] = {
|
|
@@ -16578,20 +16653,20 @@ const args_decoding_results_createResults = () => {
|
|
|
16578
16653
|
noOfBytesToSkip: 1,
|
|
16579
16654
|
firstRegisterIndex: 0,
|
|
16580
16655
|
secondRegisterIndex: 0,
|
|
16581
|
-
immediateDecoder: new
|
|
16656
|
+
immediateDecoder: ImmediateDecoder.new(),
|
|
16582
16657
|
};
|
|
16583
16658
|
results[ArgumentType.ONE_REGISTER_ONE_IMMEDIATE] = {
|
|
16584
16659
|
type: ArgumentType.ONE_REGISTER_ONE_IMMEDIATE,
|
|
16585
16660
|
noOfBytesToSkip: 1,
|
|
16586
16661
|
registerIndex: 0,
|
|
16587
|
-
immediateDecoder: new
|
|
16662
|
+
immediateDecoder: ImmediateDecoder.new(),
|
|
16588
16663
|
};
|
|
16589
16664
|
results[ArgumentType.ONE_REGISTER_TWO_IMMEDIATES] = {
|
|
16590
16665
|
type: ArgumentType.ONE_REGISTER_TWO_IMMEDIATES,
|
|
16591
16666
|
noOfBytesToSkip: 1,
|
|
16592
16667
|
registerIndex: 0,
|
|
16593
|
-
firstImmediateDecoder: new
|
|
16594
|
-
secondImmediateDecoder: new
|
|
16668
|
+
firstImmediateDecoder: ImmediateDecoder.new(),
|
|
16669
|
+
secondImmediateDecoder: ImmediateDecoder.new(),
|
|
16595
16670
|
};
|
|
16596
16671
|
results[ArgumentType.ONE_OFFSET] = {
|
|
16597
16672
|
type: ArgumentType.ONE_OFFSET,
|
|
@@ -16601,14 +16676,14 @@ const args_decoding_results_createResults = () => {
|
|
|
16601
16676
|
results[ArgumentType.TWO_IMMEDIATES] = {
|
|
16602
16677
|
type: ArgumentType.TWO_IMMEDIATES,
|
|
16603
16678
|
noOfBytesToSkip: 1,
|
|
16604
|
-
firstImmediateDecoder: new
|
|
16605
|
-
secondImmediateDecoder: new
|
|
16679
|
+
firstImmediateDecoder: ImmediateDecoder.new(),
|
|
16680
|
+
secondImmediateDecoder: ImmediateDecoder.new(),
|
|
16606
16681
|
};
|
|
16607
16682
|
results[ArgumentType.TWO_REGISTERS_TWO_IMMEDIATES] = {
|
|
16608
16683
|
type: ArgumentType.TWO_REGISTERS_TWO_IMMEDIATES,
|
|
16609
16684
|
noOfBytesToSkip: 1,
|
|
16610
|
-
firstImmediateDecoder: new
|
|
16611
|
-
secondImmediateDecoder: new
|
|
16685
|
+
firstImmediateDecoder: ImmediateDecoder.new(),
|
|
16686
|
+
secondImmediateDecoder: ImmediateDecoder.new(),
|
|
16612
16687
|
firstRegisterIndex: 0,
|
|
16613
16688
|
secondRegisterIndex: 0,
|
|
16614
16689
|
};
|
|
@@ -16616,7 +16691,7 @@ const args_decoding_results_createResults = () => {
|
|
|
16616
16691
|
type: ArgumentType.ONE_REGISTER_ONE_EXTENDED_WIDTH_IMMEDIATE,
|
|
16617
16692
|
noOfBytesToSkip: 9,
|
|
16618
16693
|
registerIndex: 0,
|
|
16619
|
-
immediateDecoder: new
|
|
16694
|
+
immediateDecoder: ExtendedWitdthImmediateDecoder.new(),
|
|
16620
16695
|
};
|
|
16621
16696
|
return results;
|
|
16622
16697
|
};
|
|
@@ -17173,11 +17248,14 @@ function assemblify_assemblify(program, mask) {
|
|
|
17173
17248
|
|
|
17174
17249
|
/** Create a new gas counter instance depending on the gas value. */
|
|
17175
17250
|
function gas_gasCounter(gas) {
|
|
17176
|
-
return new
|
|
17251
|
+
return GasCounterU64.new(tryAsU64(gas));
|
|
17177
17252
|
}
|
|
17178
17253
|
class GasCounterU64 {
|
|
17179
17254
|
gas;
|
|
17180
17255
|
initialGas;
|
|
17256
|
+
static new(gas) {
|
|
17257
|
+
return new GasCounterU64(gas);
|
|
17258
|
+
}
|
|
17181
17259
|
constructor(gas) {
|
|
17182
17260
|
this.gas = gas;
|
|
17183
17261
|
this.initialGas = tryAsGas(gas);
|
|
@@ -17534,6 +17612,9 @@ class MemoryPage {
|
|
|
17534
17612
|
|
|
17535
17613
|
class readable_page_ReadablePage extends MemoryPage {
|
|
17536
17614
|
data;
|
|
17615
|
+
static new(pageNumber, data) {
|
|
17616
|
+
return new readable_page_ReadablePage(pageNumber, data);
|
|
17617
|
+
}
|
|
17537
17618
|
constructor(pageNumber, data) {
|
|
17538
17619
|
super(pageNumber);
|
|
17539
17620
|
this.data = data;
|
|
@@ -17571,6 +17652,9 @@ class readable_page_ReadablePage extends MemoryPage {
|
|
|
17571
17652
|
class writeable_page_WriteablePage extends MemoryPage {
|
|
17572
17653
|
buffer;
|
|
17573
17654
|
view;
|
|
17655
|
+
static new(pageNumber, initialData) {
|
|
17656
|
+
return new writeable_page_WriteablePage(pageNumber, initialData);
|
|
17657
|
+
}
|
|
17574
17658
|
constructor(pageNumber, initialData) {
|
|
17575
17659
|
super(pageNumber);
|
|
17576
17660
|
const dataLength = initialData?.length ?? 0;
|
|
@@ -17646,6 +17730,9 @@ class memory_Memory {
|
|
|
17646
17730
|
static fromInitialMemory(initialMemoryState) {
|
|
17647
17731
|
return new memory_Memory(initialMemoryState?.sbrkIndex, initialMemoryState?.sbrkIndex, initialMemoryState?.endHeapIndex, initialMemoryState?.memory);
|
|
17648
17732
|
}
|
|
17733
|
+
static new(sbrkIndex = tryAsSbrkIndex(RESERVED_MEMORY_RANGE.end), virtualSbrkIndex = tryAsSbrkIndex(RESERVED_MEMORY_RANGE.end), endHeapIndex = tryAsSbrkIndex(MAX_MEMORY_INDEX), memory = new Map()) {
|
|
17734
|
+
return new memory_Memory(sbrkIndex, virtualSbrkIndex, endHeapIndex, memory);
|
|
17735
|
+
}
|
|
17649
17736
|
constructor(sbrkIndex = tryAsSbrkIndex(RESERVED_MEMORY_RANGE.end), virtualSbrkIndex = tryAsSbrkIndex(RESERVED_MEMORY_RANGE.end), endHeapIndex = tryAsSbrkIndex(MAX_MEMORY_INDEX), memory = new Map()) {
|
|
17650
17737
|
this.sbrkIndex = sbrkIndex;
|
|
17651
17738
|
this.virtualSbrkIndex = virtualSbrkIndex;
|
|
@@ -17764,7 +17851,7 @@ class memory_Memory {
|
|
|
17764
17851
|
const pagesToAllocate = (newSbrkIndex - currentSbrkIndex) / PAGE_SIZE;
|
|
17765
17852
|
const rangeToAllocate = PageRange.fromStartAndLength(firstPageNumber, pagesToAllocate);
|
|
17766
17853
|
for (const pageNumber of rangeToAllocate) {
|
|
17767
|
-
const page = new
|
|
17854
|
+
const page = WriteablePage.new(pageNumber);
|
|
17768
17855
|
this.memory.set(pageNumber, page);
|
|
17769
17856
|
}
|
|
17770
17857
|
this.virtualSbrkIndex = newVirtualSbrkIndex;
|
|
@@ -17827,7 +17914,7 @@ class memory_builder_MemoryBuilder {
|
|
|
17827
17914
|
for (let i = 0; i < noOfPages; i++) {
|
|
17828
17915
|
const pageNumber = pages[i];
|
|
17829
17916
|
const dataChunk = data.subarray(i * PAGE_SIZE, (i + 1) * PAGE_SIZE);
|
|
17830
|
-
const page = new
|
|
17917
|
+
const page = ReadablePage.new(pageNumber, dataChunk);
|
|
17831
17918
|
this.initialMemory.set(pageNumber, page);
|
|
17832
17919
|
}
|
|
17833
17920
|
return this;
|
|
@@ -17855,7 +17942,7 @@ class memory_builder_MemoryBuilder {
|
|
|
17855
17942
|
for (let i = 0; i < noOfPages; i++) {
|
|
17856
17943
|
const pageNumber = pages[i];
|
|
17857
17944
|
const dataChunk = data.subarray(i * PAGE_SIZE, (i + 1) * PAGE_SIZE);
|
|
17858
|
-
const page = new
|
|
17945
|
+
const page = WriteablePage.new(pageNumber, dataChunk);
|
|
17859
17946
|
this.initialMemory.set(pageNumber, page);
|
|
17860
17947
|
}
|
|
17861
17948
|
return this;
|
|
@@ -18050,6 +18137,9 @@ function math_utils_minBigInt(...args) {
|
|
|
18050
18137
|
|
|
18051
18138
|
class bit_rotation_ops_BitRotationOps {
|
|
18052
18139
|
regs;
|
|
18140
|
+
static new(regs) {
|
|
18141
|
+
return new bit_rotation_ops_BitRotationOps(regs);
|
|
18142
|
+
}
|
|
18053
18143
|
constructor(regs) {
|
|
18054
18144
|
this.regs = regs;
|
|
18055
18145
|
}
|
|
@@ -18144,6 +18234,9 @@ class branch_ops_BranchOps {
|
|
|
18144
18234
|
regs;
|
|
18145
18235
|
instructionResult;
|
|
18146
18236
|
basicBlocks;
|
|
18237
|
+
static new(regs, instructionResult, basicBlocks) {
|
|
18238
|
+
return new branch_ops_BranchOps(regs, instructionResult, basicBlocks);
|
|
18239
|
+
}
|
|
18147
18240
|
constructor(regs, instructionResult, basicBlocks) {
|
|
18148
18241
|
this.regs = regs;
|
|
18149
18242
|
this.instructionResult = instructionResult;
|
|
@@ -18226,6 +18319,9 @@ class dynamic_jump_ops_DynamicJumpOps {
|
|
|
18226
18319
|
jumpTable;
|
|
18227
18320
|
instructionResult;
|
|
18228
18321
|
basicBlocks;
|
|
18322
|
+
static new(regs, jumpTable, instructionResult, basicBlocks) {
|
|
18323
|
+
return new dynamic_jump_ops_DynamicJumpOps(regs, jumpTable, instructionResult, basicBlocks);
|
|
18324
|
+
}
|
|
18229
18325
|
constructor(regs, jumpTable, instructionResult, basicBlocks) {
|
|
18230
18326
|
this.regs = regs;
|
|
18231
18327
|
this.jumpTable = jumpTable;
|
|
@@ -18266,6 +18362,9 @@ class dynamic_jump_ops_DynamicJumpOps {
|
|
|
18266
18362
|
|
|
18267
18363
|
class host_call_ops_HostCallOps {
|
|
18268
18364
|
instructionResult;
|
|
18365
|
+
static new(instructionResult) {
|
|
18366
|
+
return new host_call_ops_HostCallOps(instructionResult);
|
|
18367
|
+
}
|
|
18269
18368
|
constructor(instructionResult) {
|
|
18270
18369
|
this.instructionResult = instructionResult;
|
|
18271
18370
|
}
|
|
@@ -18284,6 +18383,9 @@ class load_ops_LoadOps {
|
|
|
18284
18383
|
regs;
|
|
18285
18384
|
memory;
|
|
18286
18385
|
instructionResult;
|
|
18386
|
+
static new(regs, memory, instructionResult) {
|
|
18387
|
+
return new load_ops_LoadOps(regs, memory, instructionResult);
|
|
18388
|
+
}
|
|
18287
18389
|
constructor(regs, memory, instructionResult) {
|
|
18288
18390
|
this.regs = regs;
|
|
18289
18391
|
this.memory = memory;
|
|
@@ -18395,9 +18497,17 @@ class registers_Registers {
|
|
|
18395
18497
|
bytes;
|
|
18396
18498
|
asSigned;
|
|
18397
18499
|
asUnsigned;
|
|
18398
|
-
|
|
18399
|
-
|
|
18500
|
+
/** Creates an empty registers object backed by a freshly allocated buffer. */
|
|
18501
|
+
static empty() {
|
|
18502
|
+
return new registers_Registers(safeAllocUint8Array(NO_OF_REGISTERS << REGISTER_SIZE_SHIFT));
|
|
18503
|
+
}
|
|
18504
|
+
/** Wraps an existing byte buffer, validating its size. */
|
|
18505
|
+
static fromBytes(bytes) {
|
|
18400
18506
|
check `${bytes.length === NO_OF_REGISTERS << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
|
|
18507
|
+
return new registers_Registers(bytes);
|
|
18508
|
+
}
|
|
18509
|
+
constructor(bytes) {
|
|
18510
|
+
this.bytes = bytes;
|
|
18401
18511
|
this.asSigned = new BigInt64Array(bytes.buffer, bytes.byteOffset);
|
|
18402
18512
|
this.asUnsigned = new BigUint64Array(bytes.buffer, bytes.byteOffset);
|
|
18403
18513
|
}
|
|
@@ -18408,10 +18518,6 @@ class registers_Registers {
|
|
|
18408
18518
|
check `${bytes.length === this.bytes.length} Incorrect size of input registers. Got: ${bytes.length}, need: ${this.bytes.length}`;
|
|
18409
18519
|
this.bytes.set(bytes, 0);
|
|
18410
18520
|
}
|
|
18411
|
-
static fromBytes(bytes) {
|
|
18412
|
-
check `${bytes.length === NO_OF_REGISTERS << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
|
|
18413
|
-
return new registers_Registers(bytes);
|
|
18414
|
-
}
|
|
18415
18521
|
getBytesAsLittleEndian(index, len) {
|
|
18416
18522
|
const offset = index << REGISTER_SIZE_SHIFT;
|
|
18417
18523
|
return this.bytes.subarray(offset, offset + len);
|
|
@@ -18475,6 +18581,9 @@ function registers_signExtend32To64(value) {
|
|
|
18475
18581
|
|
|
18476
18582
|
class math_ops_MathOps {
|
|
18477
18583
|
regs;
|
|
18584
|
+
static new(regs) {
|
|
18585
|
+
return new math_ops_MathOps(regs);
|
|
18586
|
+
}
|
|
18478
18587
|
constructor(regs) {
|
|
18479
18588
|
this.regs = regs;
|
|
18480
18589
|
}
|
|
@@ -18625,6 +18734,9 @@ class memory_ops_MemoryOps {
|
|
|
18625
18734
|
regs;
|
|
18626
18735
|
memory;
|
|
18627
18736
|
instructionResult;
|
|
18737
|
+
static new(regs, memory, instructionResult) {
|
|
18738
|
+
return new memory_ops_MemoryOps(regs, memory, instructionResult);
|
|
18739
|
+
}
|
|
18628
18740
|
constructor(regs, memory, instructionResult) {
|
|
18629
18741
|
this.regs = regs;
|
|
18630
18742
|
this.memory = memory;
|
|
@@ -18644,6 +18756,9 @@ class memory_ops_MemoryOps {
|
|
|
18644
18756
|
|
|
18645
18757
|
class no_args_ops_NoArgsOps {
|
|
18646
18758
|
instructionResult;
|
|
18759
|
+
static new(instructionResult) {
|
|
18760
|
+
return new no_args_ops_NoArgsOps(instructionResult);
|
|
18761
|
+
}
|
|
18647
18762
|
constructor(instructionResult) {
|
|
18648
18763
|
this.instructionResult = instructionResult;
|
|
18649
18764
|
}
|
|
@@ -18660,6 +18775,9 @@ class no_args_ops_NoArgsOps {
|
|
|
18660
18775
|
|
|
18661
18776
|
class shift_ops_ShiftOps {
|
|
18662
18777
|
regs;
|
|
18778
|
+
static new(regs) {
|
|
18779
|
+
return new shift_ops_ShiftOps(regs);
|
|
18780
|
+
}
|
|
18663
18781
|
constructor(regs) {
|
|
18664
18782
|
this.regs = regs;
|
|
18665
18783
|
}
|
|
@@ -18728,6 +18846,9 @@ class store_ops_StoreOps {
|
|
|
18728
18846
|
regs;
|
|
18729
18847
|
memory;
|
|
18730
18848
|
instructionResult;
|
|
18849
|
+
static new(regs, memory, instructionResult) {
|
|
18850
|
+
return new store_ops_StoreOps(regs, memory, instructionResult);
|
|
18851
|
+
}
|
|
18731
18852
|
constructor(regs, memory, instructionResult) {
|
|
18732
18853
|
this.regs = regs;
|
|
18733
18854
|
this.memory = memory;
|
|
@@ -19478,7 +19599,7 @@ class program_Program {
|
|
|
19478
19599
|
static fromSpi(blob, args, hasMetadata) {
|
|
19479
19600
|
const { code: spiCode, metadata } = hasMetadata ? extractCodeAndMetadata(blob) : { code: blob };
|
|
19480
19601
|
const { code, memory: rawMemory, registers } = decodeStandardProgram(spiCode, args);
|
|
19481
|
-
const regs =
|
|
19602
|
+
const regs = Registers.empty();
|
|
19482
19603
|
regs.copyFrom(registers);
|
|
19483
19604
|
const memoryBuilder = new MemoryBuilder();
|
|
19484
19605
|
for (const { start, end, data } of rawMemory.readable) {
|
|
@@ -19498,8 +19619,8 @@ class program_Program {
|
|
|
19498
19619
|
}
|
|
19499
19620
|
static fromGeneric(blob, hasMetadata) {
|
|
19500
19621
|
const { code, metadata } = hasMetadata ? extractCodeAndMetadata(blob) : { code: blob };
|
|
19501
|
-
const regs =
|
|
19502
|
-
const memory = new
|
|
19622
|
+
const regs = Registers.empty();
|
|
19623
|
+
const memory = Memory.new();
|
|
19503
19624
|
return new program_Program(code, regs, memory, metadata);
|
|
19504
19625
|
}
|
|
19505
19626
|
constructor(code, registers, memory, metadata = new Uint8Array()) {
|
|
@@ -19525,11 +19646,19 @@ function extractCodeAndMetadata(blobWithMetadata) {
|
|
|
19525
19646
|
|
|
19526
19647
|
class jump_table_JumpTable {
|
|
19527
19648
|
indices;
|
|
19528
|
-
|
|
19649
|
+
/** Create an empty jump table. */
|
|
19650
|
+
static empty() {
|
|
19651
|
+
return new jump_table_JumpTable(0, new Uint8Array());
|
|
19652
|
+
}
|
|
19653
|
+
/** Decode a jump table from a raw bytes buffer. */
|
|
19654
|
+
static fromRaw(itemByteLength, bytes) {
|
|
19529
19655
|
check `
|
|
19530
19656
|
${itemByteLength === 0 || bytes.length % itemByteLength === 0}
|
|
19531
19657
|
Length of jump table (${bytes.length}) should be a multiple of item lenght (${itemByteLength})!
|
|
19532
19658
|
`;
|
|
19659
|
+
return new jump_table_JumpTable(itemByteLength, bytes);
|
|
19660
|
+
}
|
|
19661
|
+
constructor(itemByteLength, bytes) {
|
|
19533
19662
|
const length = itemByteLength === 0 ? 0 : bytes.length / itemByteLength;
|
|
19534
19663
|
this.indices = new Uint32Array(length);
|
|
19535
19664
|
for (let i = 0; i < length; i++) {
|
|
@@ -19555,9 +19684,6 @@ class jump_table_JumpTable {
|
|
|
19555
19684
|
getDestination(index) {
|
|
19556
19685
|
return this.indices[index];
|
|
19557
19686
|
}
|
|
19558
|
-
static empty() {
|
|
19559
|
-
return new jump_table_JumpTable(0, new Uint8Array());
|
|
19560
|
-
}
|
|
19561
19687
|
getSize() {
|
|
19562
19688
|
return this.indices.length;
|
|
19563
19689
|
}
|
|
@@ -19581,11 +19707,14 @@ class program_decoder_ProgramDecoder {
|
|
|
19581
19707
|
code;
|
|
19582
19708
|
mask;
|
|
19583
19709
|
jumpTable;
|
|
19710
|
+
static new(rawProgram) {
|
|
19711
|
+
return new program_decoder_ProgramDecoder(rawProgram);
|
|
19712
|
+
}
|
|
19584
19713
|
constructor(rawProgram) {
|
|
19585
19714
|
const { code, mask, jumpTable, jumpTableItemLength } = this.decodeProgram(rawProgram);
|
|
19586
19715
|
this.code = new Uint8Array(code);
|
|
19587
|
-
this.mask = new
|
|
19588
|
-
this.jumpTable =
|
|
19716
|
+
this.mask = Mask.new(mask);
|
|
19717
|
+
this.jumpTable = JumpTable.fromRaw(jumpTableItemLength, jumpTable);
|
|
19589
19718
|
}
|
|
19590
19719
|
decodeProgram(program) {
|
|
19591
19720
|
const decoder = Decoder.fromBlob(program);
|
|
@@ -19619,7 +19748,7 @@ class program_decoder_ProgramDecoder {
|
|
|
19619
19748
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/23f400234701?v=0.6.4 */
|
|
19620
19749
|
static deblob(program) {
|
|
19621
19750
|
try {
|
|
19622
|
-
return Result.ok(new
|
|
19751
|
+
return Result.ok(program_decoder_ProgramDecoder.new(program));
|
|
19623
19752
|
}
|
|
19624
19753
|
catch (e) {
|
|
19625
19754
|
program_decoder_logger.error `Invalid program: ${e}`;
|
|
@@ -19657,8 +19786,8 @@ class program_decoder_ProgramDecoder {
|
|
|
19657
19786
|
const interpreter_logger = Logger.new(import.meta.filename, "pvm");
|
|
19658
19787
|
class interpreter_Interpreter {
|
|
19659
19788
|
useSbrkGas;
|
|
19660
|
-
registers =
|
|
19661
|
-
memory = new
|
|
19789
|
+
registers = Registers.empty();
|
|
19790
|
+
memory = Memory.new();
|
|
19662
19791
|
gas = gasCounter(tryAsGas(0));
|
|
19663
19792
|
code = new Uint8Array();
|
|
19664
19793
|
mask = Mask.empty();
|
|
@@ -19682,23 +19811,26 @@ class interpreter_Interpreter {
|
|
|
19682
19811
|
argsDecodingResults = createResults();
|
|
19683
19812
|
basicBlocks;
|
|
19684
19813
|
jumpTable = JumpTable.empty();
|
|
19814
|
+
static new(options = {}) {
|
|
19815
|
+
return new interpreter_Interpreter(options);
|
|
19816
|
+
}
|
|
19685
19817
|
constructor({ useSbrkGas = false } = {}) {
|
|
19686
19818
|
this.useSbrkGas = useSbrkGas;
|
|
19687
19819
|
this.argsDecoder = new ArgsDecoder();
|
|
19688
19820
|
this.basicBlocks = new BasicBlocks();
|
|
19689
|
-
const mathOps = new
|
|
19690
|
-
const shiftOps = new
|
|
19691
|
-
const bitOps = new
|
|
19692
|
-
const booleanOps = new
|
|
19693
|
-
const moveOps = new
|
|
19694
|
-
const branchOps = new
|
|
19695
|
-
const loadOps = new
|
|
19696
|
-
const storeOps = new
|
|
19697
|
-
const noArgsOps = new
|
|
19698
|
-
const dynamicJumpOps = new
|
|
19699
|
-
const hostCallOps = new
|
|
19700
|
-
const memoryOps = new
|
|
19701
|
-
const bitRotationOps = new
|
|
19821
|
+
const mathOps = MathOps.new(this.registers);
|
|
19822
|
+
const shiftOps = ShiftOps.new(this.registers);
|
|
19823
|
+
const bitOps = BitOps.new(this.registers);
|
|
19824
|
+
const booleanOps = BooleanOps.new(this.registers);
|
|
19825
|
+
const moveOps = MoveOps.new(this.registers);
|
|
19826
|
+
const branchOps = BranchOps.new(this.registers, this.instructionResult, this.basicBlocks);
|
|
19827
|
+
const loadOps = LoadOps.new(this.registers, this.memory, this.instructionResult);
|
|
19828
|
+
const storeOps = StoreOps.new(this.registers, this.memory, this.instructionResult);
|
|
19829
|
+
const noArgsOps = NoArgsOps.new(this.instructionResult);
|
|
19830
|
+
const dynamicJumpOps = DynamicJumpOps.new(this.registers, this.jumpTable, this.instructionResult, this.basicBlocks);
|
|
19831
|
+
const hostCallOps = HostCallOps.new(this.instructionResult);
|
|
19832
|
+
const memoryOps = MemoryOps.new(this.registers, this.memory, this.instructionResult);
|
|
19833
|
+
const bitRotationOps = BitRotationOps.new(this.registers);
|
|
19702
19834
|
this.threeRegsDispatcher = new ThreeRegsDispatcher(mathOps, shiftOps, bitOps, booleanOps, moveOps, bitRotationOps);
|
|
19703
19835
|
this.twoRegsOneImmDispatcher = new TwoRegsOneImmDispatcher(mathOps, shiftOps, bitOps, booleanOps, moveOps, storeOps, loadOps, bitRotationOps);
|
|
19704
19836
|
this.twoRegsDispatcher = new TwoRegsDispatcher(moveOps, memoryOps, bitOps, bitRotationOps);
|
|
@@ -19718,7 +19850,7 @@ class interpreter_Interpreter {
|
|
|
19718
19850
|
this.resetGeneric(p.code, pc, gas, p.registers, p.memory);
|
|
19719
19851
|
}
|
|
19720
19852
|
resetGeneric(rawProgram, pc, gas, maybeRegisters, maybeMemory) {
|
|
19721
|
-
const programDecoder = new
|
|
19853
|
+
const programDecoder = ProgramDecoder.new(rawProgram);
|
|
19722
19854
|
this.code = programDecoder.getCode();
|
|
19723
19855
|
this.mask = programDecoder.getMask();
|
|
19724
19856
|
this.jumpTable.copyFrom(programDecoder.getJumpTable());
|
|
@@ -19895,14 +20027,17 @@ class interpreter_Interpreter {
|
|
|
19895
20027
|
|
|
19896
20028
|
class DebuggerAdapter {
|
|
19897
20029
|
pvm;
|
|
20030
|
+
static new(useSbrkGas = false) {
|
|
20031
|
+
return new DebuggerAdapter(useSbrkGas);
|
|
20032
|
+
}
|
|
19898
20033
|
constructor(useSbrkGas = false) {
|
|
19899
|
-
this.pvm = new
|
|
20034
|
+
this.pvm = Interpreter.new({ useSbrkGas });
|
|
19900
20035
|
}
|
|
19901
20036
|
resetJAM(jamProgram, pc, gas, args, hasMetadata = false) {
|
|
19902
20037
|
this.pvm.resetJam(jamProgram, args, pc, tryAsGas(gas), hasMetadata);
|
|
19903
20038
|
}
|
|
19904
20039
|
resetGeneric(rawProgram, flatRegisters, initialGas) {
|
|
19905
|
-
this.pvm.resetGeneric(rawProgram, 0, tryAsGas(initialGas),
|
|
20040
|
+
this.pvm.resetGeneric(rawProgram, 0, tryAsGas(initialGas), Registers.fromBytes(flatRegisters));
|
|
19906
20041
|
}
|
|
19907
20042
|
reset(rawProgram, pc, gas, maybeRegisters, maybeMemory) {
|
|
19908
20043
|
this.pvm.resetGeneric(rawProgram, pc, tryAsGas(gas), maybeRegisters, maybeMemory);
|
|
@@ -19948,7 +20083,7 @@ class DebuggerAdapter {
|
|
|
19948
20083
|
return this.pvm.registers.getAllEncoded();
|
|
19949
20084
|
}
|
|
19950
20085
|
setRegisters(registers) {
|
|
19951
|
-
this.pvm.registers.copyFrom(
|
|
20086
|
+
this.pvm.registers.copyFrom(Registers.fromBytes(registers));
|
|
19952
20087
|
}
|
|
19953
20088
|
getProgramCounter() {
|
|
19954
20089
|
return this.pvm.getPC();
|
|
@@ -20066,9 +20201,9 @@ async function runPvmTest(testContent) {
|
|
|
20066
20201
|
const HEAP_START_PAGE = hasMemoryLayout ? maxAddressFromPageMap + PAGE_SIZE : 0;
|
|
20067
20202
|
const HEAP_END_PAGE = MAX_MEMORY_INDEX;
|
|
20068
20203
|
const memory = memoryBuilder.finalize(tryAsMemoryIndex(HEAP_START_PAGE), tryAsSbrkIndex(HEAP_END_PAGE));
|
|
20069
|
-
const regs =
|
|
20204
|
+
const regs = Registers.empty();
|
|
20070
20205
|
regs.copyFrom(testContent["initial-regs"]);
|
|
20071
|
-
const pvm = new
|
|
20206
|
+
const pvm = Interpreter.new();
|
|
20072
20207
|
const mapPvmStatus = (status) => {
|
|
20073
20208
|
if (status === Status.FAULT) {
|
|
20074
20209
|
return "page-fault";
|