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