@typeberry/lib 0.1.3-707962d → 0.1.3-ea24911

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.cjs CHANGED
@@ -8731,6 +8731,10 @@ class DisputesRecords {
8731
8731
  static create({ goodSet, badSet, wonkySet, punishSet }) {
8732
8732
  return new DisputesRecords(goodSet, badSet, wonkySet, punishSet);
8733
8733
  }
8734
+ goodSetDict;
8735
+ badSetDict;
8736
+ wonkySetDict;
8737
+ punishSetDict;
8734
8738
  constructor(
8735
8739
  /** `goodSet`: all work-reports hashes which were judged to be correct */
8736
8740
  goodSet,
@@ -8744,6 +8748,18 @@ class DisputesRecords {
8744
8748
  this.badSet = badSet;
8745
8749
  this.wonkySet = wonkySet;
8746
8750
  this.punishSet = punishSet;
8751
+ this.goodSetDict = HashSet.from(goodSet.array);
8752
+ this.badSetDict = HashSet.from(badSet.array);
8753
+ this.wonkySetDict = HashSet.from(wonkySet.array);
8754
+ this.punishSetDict = HashSet.from(punishSet.array);
8755
+ }
8756
+ asDictionaries() {
8757
+ return {
8758
+ goodSet: this.goodSetDict,
8759
+ badSet: this.badSetDict,
8760
+ wonkySet: this.wonkySetDict,
8761
+ punishSet: this.punishSetDict,
8762
+ };
8747
8763
  }
8748
8764
  static fromSortedArrays({ goodSet, badSet, wonkySet, punishSet, }) {
8749
8765
  return new DisputesRecords(SortedSet.fromSortedArray(hashComparator, goodSet), SortedSet.fromSortedArray(hashComparator, badSet), SortedSet.fromSortedArray(hashComparator, wonkySet), SortedSet.fromSortedArray(hashComparator, punishSet));
@@ -13327,10 +13343,16 @@ function signExtend32To64(value) {
13327
13343
 
13328
13344
  /** Attempt to convert a number into `HostCallIndex`. */
13329
13345
  const tryAsHostCallIndex = (v) => asOpaqueType(tryAsU32(v));
13346
+ /**
13347
+ * Host-call exit reason.
13348
+ *
13349
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/24a30124a501?v=0.7.2
13350
+ */
13330
13351
  var PvmExecution;
13331
13352
  (function (PvmExecution) {
13332
13353
  PvmExecution[PvmExecution["Halt"] = 0] = "Halt";
13333
13354
  PvmExecution[PvmExecution["Panic"] = 1] = "Panic";
13355
+ PvmExecution[PvmExecution["OOG"] = 2] = "OOG";
13334
13356
  })(PvmExecution || (PvmExecution = {}));
13335
13357
  /** A utility function to easily trace a bunch of registers. */
13336
13358
  function traceRegisters(...regs) {
@@ -16965,8 +16987,9 @@ class HostCalls {
16965
16987
  const index = tryAsHostCallIndex(hostCallIndex);
16966
16988
  const hostCall = this.hostCalls.get(index);
16967
16989
  const gasBefore = gas.get();
16968
- const gasCost = typeof hostCall.gasCost === "number" ? hostCall.gasCost : hostCall.gasCost(regs);
16969
- const underflow = gas.sub(gasCost);
16990
+ // NOTE: `basicGasCost(regs)` function is for compatibility reasons: pre GP 0.7.2
16991
+ const basicGasCost = typeof hostCall.basicGasCost === "number" ? hostCall.basicGasCost : hostCall.basicGasCost(regs);
16992
+ const underflow = gas.sub(basicGasCost);
16970
16993
  const pcLog = `[PC: ${pvmInstance.getPC()}]`;
16971
16994
  if (underflow) {
16972
16995
  this.hostCalls.traceHostCall(`${pcLog} OOG`, index, hostCall, regs, gas.get());
@@ -16983,6 +17006,10 @@ class HostCalls {
16983
17006
  status = Status.PANIC;
16984
17007
  return this.getReturnValue(status, pvmInstance);
16985
17008
  }
17009
+ if (result === PvmExecution.OOG) {
17010
+ status = Status.OOG;
17011
+ return this.getReturnValue(status, pvmInstance);
17012
+ }
16986
17013
  if (result === undefined) {
16987
17014
  pvmInstance.runProgram();
16988
17015
  status = pvmInstance.getStatus();
@@ -17972,7 +17999,7 @@ class Preimages {
17972
17999
 
17973
18000
  class Missing {
17974
18001
  index = tryAsHostCallIndex(2 ** 32 - 1);
17975
- gasCost = tryAsSmallGas(10);
18002
+ basicGasCost = tryAsSmallGas(10);
17976
18003
  currentServiceId = CURRENT_SERVICE_ID;
17977
18004
  tracedRegisters = traceRegisters(7);
17978
18005
  execute(_gas, regs, _memory) {
package/index.d.ts CHANGED
@@ -9196,6 +9196,11 @@ declare class DisputesRecords {
9196
9196
  return new DisputesRecords(goodSet, badSet, wonkySet, punishSet);
9197
9197
  }
9198
9198
 
9199
+ private readonly goodSetDict: ImmutableHashSet<WorkReportHash>;
9200
+ private readonly badSetDict: ImmutableHashSet<WorkReportHash>;
9201
+ private readonly wonkySetDict: ImmutableHashSet<WorkReportHash>;
9202
+ private readonly punishSetDict: ImmutableHashSet<Ed25519Key>;
9203
+
9199
9204
  private constructor(
9200
9205
  /** `goodSet`: all work-reports hashes which were judged to be correct */
9201
9206
  public readonly goodSet: ImmutableSortedSet<WorkReportHash>,
@@ -9205,7 +9210,21 @@ declare class DisputesRecords {
9205
9210
  public readonly wonkySet: ImmutableSortedSet<WorkReportHash>,
9206
9211
  /** `punishSet`: set of Ed25519 keys representing validators which were found to have misjudged a work-report */
9207
9212
  public readonly punishSet: ImmutableSortedSet<Ed25519Key>,
9208
- ) {}
9213
+ ) {
9214
+ this.goodSetDict = HashSet.from(goodSet.array);
9215
+ this.badSetDict = HashSet.from(badSet.array);
9216
+ this.wonkySetDict = HashSet.from(wonkySet.array);
9217
+ this.punishSetDict = HashSet.from(punishSet.array);
9218
+ }
9219
+
9220
+ public asDictionaries() {
9221
+ return {
9222
+ goodSet: this.goodSetDict,
9223
+ badSet: this.badSetDict,
9224
+ wonkySet: this.wonkySetDict,
9225
+ punishSet: this.punishSetDict,
9226
+ };
9227
+ }
9209
9228
 
9210
9229
  static fromSortedArrays({
9211
9230
  goodSet,
@@ -13675,13 +13694,12 @@ interface PartialState {
13675
13694
 
13676
13695
  /**
13677
13696
  * Transfer given `amount` of funds to the `destination`,
13678
- * passing `suppliedGas` to invoke `OnTransfer` entry point
13679
- * and given `memo`.
13697
+ * passing `gas` fee for transfer and given `memo`.
13680
13698
  */
13681
13699
  transfer(
13682
13700
  destination: ServiceId | null,
13683
13701
  amount: U64,
13684
- suppliedGas: ServiceGas,
13702
+ gas: ServiceGas,
13685
13703
  memo: Bytes<TRANSFER_MEMO_BYTES>,
13686
13704
  ): Result$2<OK, TransferError>;
13687
13705
 
@@ -18052,9 +18070,15 @@ type HostCallIndex = Opaque<U32, "HostCallIndex[U32]">;
18052
18070
  /** Attempt to convert a number into `HostCallIndex`. */
18053
18071
  declare const tryAsHostCallIndex = (v: number): HostCallIndex => asOpaqueType(tryAsU32(v));
18054
18072
 
18073
+ /**
18074
+ * Host-call exit reason.
18075
+ *
18076
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/24a30124a501?v=0.7.2
18077
+ */
18055
18078
  declare enum PvmExecution {
18056
18079
  Halt = 0,
18057
18080
  Panic = 1,
18081
+ OOG = 2, // out-of-gas
18058
18082
  }
18059
18083
 
18060
18084
  /** A utility function to easily trace a bunch of registers. */
@@ -18067,8 +18091,12 @@ interface HostCallHandler {
18067
18091
  /** Index of that host call (i.e. what PVM invokes via `ecalli`) */
18068
18092
  readonly index: HostCallIndex;
18069
18093
 
18070
- /** The gas cost of invocation of that host call. */
18071
- readonly gasCost: SmallGas | ((reg: IHostCallRegisters) => Gas);
18094
+ /**
18095
+ * The gas cost of invocation of that host call.
18096
+ *
18097
+ * NOTE: `((reg: IHostCallRegisters) => Gas)` function is for compatibility reasons: pre GP 0.7.2
18098
+ */
18099
+ readonly basicGasCost: SmallGas | ((reg: IHostCallRegisters) => Gas);
18072
18100
 
18073
18101
  /** Currently executing service id. */
18074
18102
  readonly currentServiceId: U32;
@@ -18244,8 +18272,10 @@ declare class HostCalls {
18244
18272
 
18245
18273
  const hostCall = this.hostCalls.get(index);
18246
18274
  const gasBefore = gas.get();
18247
- const gasCost = typeof hostCall.gasCost === "number" ? hostCall.gasCost : hostCall.gasCost(regs);
18248
- const underflow = gas.sub(gasCost);
18275
+ // NOTE: `basicGasCost(regs)` function is for compatibility reasons: pre GP 0.7.2
18276
+ const basicGasCost =
18277
+ typeof hostCall.basicGasCost === "number" ? hostCall.basicGasCost : hostCall.basicGasCost(regs);
18278
+ const underflow = gas.sub(basicGasCost);
18249
18279
 
18250
18280
  const pcLog = `[PC: ${pvmInstance.getPC()}]`;
18251
18281
  if (underflow) {
@@ -18272,6 +18302,11 @@ declare class HostCalls {
18272
18302
  return this.getReturnValue(status, pvmInstance);
18273
18303
  }
18274
18304
 
18305
+ if (result === PvmExecution.OOG) {
18306
+ status = Status.OOG;
18307
+ return this.getReturnValue(status, pvmInstance);
18308
+ }
18309
+
18275
18310
  if (result === undefined) {
18276
18311
  pvmInstance.runProgram();
18277
18312
  status = pvmInstance.getStatus();
package/index.js CHANGED
@@ -8728,6 +8728,10 @@ class DisputesRecords {
8728
8728
  static create({ goodSet, badSet, wonkySet, punishSet }) {
8729
8729
  return new DisputesRecords(goodSet, badSet, wonkySet, punishSet);
8730
8730
  }
8731
+ goodSetDict;
8732
+ badSetDict;
8733
+ wonkySetDict;
8734
+ punishSetDict;
8731
8735
  constructor(
8732
8736
  /** `goodSet`: all work-reports hashes which were judged to be correct */
8733
8737
  goodSet,
@@ -8741,6 +8745,18 @@ class DisputesRecords {
8741
8745
  this.badSet = badSet;
8742
8746
  this.wonkySet = wonkySet;
8743
8747
  this.punishSet = punishSet;
8748
+ this.goodSetDict = HashSet.from(goodSet.array);
8749
+ this.badSetDict = HashSet.from(badSet.array);
8750
+ this.wonkySetDict = HashSet.from(wonkySet.array);
8751
+ this.punishSetDict = HashSet.from(punishSet.array);
8752
+ }
8753
+ asDictionaries() {
8754
+ return {
8755
+ goodSet: this.goodSetDict,
8756
+ badSet: this.badSetDict,
8757
+ wonkySet: this.wonkySetDict,
8758
+ punishSet: this.punishSetDict,
8759
+ };
8744
8760
  }
8745
8761
  static fromSortedArrays({ goodSet, badSet, wonkySet, punishSet, }) {
8746
8762
  return new DisputesRecords(SortedSet.fromSortedArray(hashComparator, goodSet), SortedSet.fromSortedArray(hashComparator, badSet), SortedSet.fromSortedArray(hashComparator, wonkySet), SortedSet.fromSortedArray(hashComparator, punishSet));
@@ -13324,10 +13340,16 @@ function signExtend32To64(value) {
13324
13340
 
13325
13341
  /** Attempt to convert a number into `HostCallIndex`. */
13326
13342
  const tryAsHostCallIndex = (v) => asOpaqueType(tryAsU32(v));
13343
+ /**
13344
+ * Host-call exit reason.
13345
+ *
13346
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/24a30124a501?v=0.7.2
13347
+ */
13327
13348
  var PvmExecution;
13328
13349
  (function (PvmExecution) {
13329
13350
  PvmExecution[PvmExecution["Halt"] = 0] = "Halt";
13330
13351
  PvmExecution[PvmExecution["Panic"] = 1] = "Panic";
13352
+ PvmExecution[PvmExecution["OOG"] = 2] = "OOG";
13331
13353
  })(PvmExecution || (PvmExecution = {}));
13332
13354
  /** A utility function to easily trace a bunch of registers. */
13333
13355
  function traceRegisters(...regs) {
@@ -16962,8 +16984,9 @@ class HostCalls {
16962
16984
  const index = tryAsHostCallIndex(hostCallIndex);
16963
16985
  const hostCall = this.hostCalls.get(index);
16964
16986
  const gasBefore = gas.get();
16965
- const gasCost = typeof hostCall.gasCost === "number" ? hostCall.gasCost : hostCall.gasCost(regs);
16966
- const underflow = gas.sub(gasCost);
16987
+ // NOTE: `basicGasCost(regs)` function is for compatibility reasons: pre GP 0.7.2
16988
+ const basicGasCost = typeof hostCall.basicGasCost === "number" ? hostCall.basicGasCost : hostCall.basicGasCost(regs);
16989
+ const underflow = gas.sub(basicGasCost);
16967
16990
  const pcLog = `[PC: ${pvmInstance.getPC()}]`;
16968
16991
  if (underflow) {
16969
16992
  this.hostCalls.traceHostCall(`${pcLog} OOG`, index, hostCall, regs, gas.get());
@@ -16980,6 +17003,10 @@ class HostCalls {
16980
17003
  status = Status.PANIC;
16981
17004
  return this.getReturnValue(status, pvmInstance);
16982
17005
  }
17006
+ if (result === PvmExecution.OOG) {
17007
+ status = Status.OOG;
17008
+ return this.getReturnValue(status, pvmInstance);
17009
+ }
16983
17010
  if (result === undefined) {
16984
17011
  pvmInstance.runProgram();
16985
17012
  status = pvmInstance.getStatus();
@@ -17969,7 +17996,7 @@ class Preimages {
17969
17996
 
17970
17997
  class Missing {
17971
17998
  index = tryAsHostCallIndex(2 ** 32 - 1);
17972
- gasCost = tryAsSmallGas(10);
17999
+ basicGasCost = tryAsSmallGas(10);
17973
18000
  currentServiceId = CURRENT_SERVICE_ID;
17974
18001
  tracedRegisters = traceRegisters(7);
17975
18002
  execute(_gas, regs, _memory) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typeberry/lib",
3
- "version": "0.1.3-707962d",
3
+ "version": "0.1.3-ea24911",
4
4
  "main": "index.js",
5
5
  "author": "Fluffy Labs",
6
6
  "license": "MPL-2.0",