@typeberry/lib 0.1.3-af70ed0 → 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
@@ -13343,10 +13343,16 @@ function signExtend32To64(value) {
13343
13343
 
13344
13344
  /** Attempt to convert a number into `HostCallIndex`. */
13345
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
+ */
13346
13351
  var PvmExecution;
13347
13352
  (function (PvmExecution) {
13348
13353
  PvmExecution[PvmExecution["Halt"] = 0] = "Halt";
13349
13354
  PvmExecution[PvmExecution["Panic"] = 1] = "Panic";
13355
+ PvmExecution[PvmExecution["OOG"] = 2] = "OOG";
13350
13356
  })(PvmExecution || (PvmExecution = {}));
13351
13357
  /** A utility function to easily trace a bunch of registers. */
13352
13358
  function traceRegisters(...regs) {
@@ -16981,8 +16987,9 @@ class HostCalls {
16981
16987
  const index = tryAsHostCallIndex(hostCallIndex);
16982
16988
  const hostCall = this.hostCalls.get(index);
16983
16989
  const gasBefore = gas.get();
16984
- const gasCost = typeof hostCall.gasCost === "number" ? hostCall.gasCost : hostCall.gasCost(regs);
16985
- 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);
16986
16993
  const pcLog = `[PC: ${pvmInstance.getPC()}]`;
16987
16994
  if (underflow) {
16988
16995
  this.hostCalls.traceHostCall(`${pcLog} OOG`, index, hostCall, regs, gas.get());
@@ -16999,6 +17006,10 @@ class HostCalls {
16999
17006
  status = Status.PANIC;
17000
17007
  return this.getReturnValue(status, pvmInstance);
17001
17008
  }
17009
+ if (result === PvmExecution.OOG) {
17010
+ status = Status.OOG;
17011
+ return this.getReturnValue(status, pvmInstance);
17012
+ }
17002
17013
  if (result === undefined) {
17003
17014
  pvmInstance.runProgram();
17004
17015
  status = pvmInstance.getStatus();
@@ -17988,7 +17999,7 @@ class Preimages {
17988
17999
 
17989
18000
  class Missing {
17990
18001
  index = tryAsHostCallIndex(2 ** 32 - 1);
17991
- gasCost = tryAsSmallGas(10);
18002
+ basicGasCost = tryAsSmallGas(10);
17992
18003
  currentServiceId = CURRENT_SERVICE_ID;
17993
18004
  tracedRegisters = traceRegisters(7);
17994
18005
  execute(_gas, regs, _memory) {
package/index.d.ts CHANGED
@@ -13694,13 +13694,12 @@ interface PartialState {
13694
13694
 
13695
13695
  /**
13696
13696
  * Transfer given `amount` of funds to the `destination`,
13697
- * passing `suppliedGas` to invoke `OnTransfer` entry point
13698
- * and given `memo`.
13697
+ * passing `gas` fee for transfer and given `memo`.
13699
13698
  */
13700
13699
  transfer(
13701
13700
  destination: ServiceId | null,
13702
13701
  amount: U64,
13703
- suppliedGas: ServiceGas,
13702
+ gas: ServiceGas,
13704
13703
  memo: Bytes<TRANSFER_MEMO_BYTES>,
13705
13704
  ): Result$2<OK, TransferError>;
13706
13705
 
@@ -18071,9 +18070,15 @@ type HostCallIndex = Opaque<U32, "HostCallIndex[U32]">;
18071
18070
  /** Attempt to convert a number into `HostCallIndex`. */
18072
18071
  declare const tryAsHostCallIndex = (v: number): HostCallIndex => asOpaqueType(tryAsU32(v));
18073
18072
 
18073
+ /**
18074
+ * Host-call exit reason.
18075
+ *
18076
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/24a30124a501?v=0.7.2
18077
+ */
18074
18078
  declare enum PvmExecution {
18075
18079
  Halt = 0,
18076
18080
  Panic = 1,
18081
+ OOG = 2, // out-of-gas
18077
18082
  }
18078
18083
 
18079
18084
  /** A utility function to easily trace a bunch of registers. */
@@ -18086,8 +18091,12 @@ interface HostCallHandler {
18086
18091
  /** Index of that host call (i.e. what PVM invokes via `ecalli`) */
18087
18092
  readonly index: HostCallIndex;
18088
18093
 
18089
- /** The gas cost of invocation of that host call. */
18090
- 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);
18091
18100
 
18092
18101
  /** Currently executing service id. */
18093
18102
  readonly currentServiceId: U32;
@@ -18263,8 +18272,10 @@ declare class HostCalls {
18263
18272
 
18264
18273
  const hostCall = this.hostCalls.get(index);
18265
18274
  const gasBefore = gas.get();
18266
- const gasCost = typeof hostCall.gasCost === "number" ? hostCall.gasCost : hostCall.gasCost(regs);
18267
- 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);
18268
18279
 
18269
18280
  const pcLog = `[PC: ${pvmInstance.getPC()}]`;
18270
18281
  if (underflow) {
@@ -18291,6 +18302,11 @@ declare class HostCalls {
18291
18302
  return this.getReturnValue(status, pvmInstance);
18292
18303
  }
18293
18304
 
18305
+ if (result === PvmExecution.OOG) {
18306
+ status = Status.OOG;
18307
+ return this.getReturnValue(status, pvmInstance);
18308
+ }
18309
+
18294
18310
  if (result === undefined) {
18295
18311
  pvmInstance.runProgram();
18296
18312
  status = pvmInstance.getStatus();
package/index.js CHANGED
@@ -13340,10 +13340,16 @@ function signExtend32To64(value) {
13340
13340
 
13341
13341
  /** Attempt to convert a number into `HostCallIndex`. */
13342
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
+ */
13343
13348
  var PvmExecution;
13344
13349
  (function (PvmExecution) {
13345
13350
  PvmExecution[PvmExecution["Halt"] = 0] = "Halt";
13346
13351
  PvmExecution[PvmExecution["Panic"] = 1] = "Panic";
13352
+ PvmExecution[PvmExecution["OOG"] = 2] = "OOG";
13347
13353
  })(PvmExecution || (PvmExecution = {}));
13348
13354
  /** A utility function to easily trace a bunch of registers. */
13349
13355
  function traceRegisters(...regs) {
@@ -16978,8 +16984,9 @@ class HostCalls {
16978
16984
  const index = tryAsHostCallIndex(hostCallIndex);
16979
16985
  const hostCall = this.hostCalls.get(index);
16980
16986
  const gasBefore = gas.get();
16981
- const gasCost = typeof hostCall.gasCost === "number" ? hostCall.gasCost : hostCall.gasCost(regs);
16982
- 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);
16983
16990
  const pcLog = `[PC: ${pvmInstance.getPC()}]`;
16984
16991
  if (underflow) {
16985
16992
  this.hostCalls.traceHostCall(`${pcLog} OOG`, index, hostCall, regs, gas.get());
@@ -16996,6 +17003,10 @@ class HostCalls {
16996
17003
  status = Status.PANIC;
16997
17004
  return this.getReturnValue(status, pvmInstance);
16998
17005
  }
17006
+ if (result === PvmExecution.OOG) {
17007
+ status = Status.OOG;
17008
+ return this.getReturnValue(status, pvmInstance);
17009
+ }
16999
17010
  if (result === undefined) {
17000
17011
  pvmInstance.runProgram();
17001
17012
  status = pvmInstance.getStatus();
@@ -17985,7 +17996,7 @@ class Preimages {
17985
17996
 
17986
17997
  class Missing {
17987
17998
  index = tryAsHostCallIndex(2 ** 32 - 1);
17988
- gasCost = tryAsSmallGas(10);
17999
+ basicGasCost = tryAsSmallGas(10);
17989
18000
  currentServiceId = CURRENT_SERVICE_ID;
17990
18001
  tracedRegisters = traceRegisters(7);
17991
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-af70ed0",
3
+ "version": "0.1.3-ea24911",
4
4
  "main": "index.js",
5
5
  "author": "Fluffy Labs",
6
6
  "license": "MPL-2.0",