@typeberry/lib 0.5.3-355fdf7 → 0.5.3-fb6e98a

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.
Files changed (76) hide show
  1. package/package.json +8 -4
  2. package/packages/core/hash/hash.d.ts.map +1 -1
  3. package/packages/core/hash/hash.js +1 -0
  4. package/packages/core/numbers/index.d.ts +4 -0
  5. package/packages/core/numbers/index.d.ts.map +1 -1
  6. package/packages/core/numbers/index.js +4 -4
  7. package/packages/core/pvm-host-calls/host-calls-executor.d.ts +23 -17
  8. package/packages/core/pvm-host-calls/host-calls-executor.d.ts.map +1 -1
  9. package/packages/core/pvm-host-calls/host-calls-executor.js +23 -31
  10. package/packages/core/pvm-interpreter/ops/math-consts.d.ts +2 -3
  11. package/packages/core/pvm-interpreter/ops/math-consts.d.ts.map +1 -1
  12. package/packages/core/pvm-interpreter/ops/math-consts.js +2 -3
  13. package/packages/core/pvm-interpreter/ops/math-ops.js +3 -3
  14. package/packages/core/pvm-interpreter/ops/math-utils.js +13 -13
  15. package/packages/core/pvm-interpreter/ops/math-utils.test.js +17 -16
  16. package/packages/jam/block/work-item.d.ts +13 -4
  17. package/packages/jam/block/work-item.d.ts.map +1 -1
  18. package/packages/jam/block/work-result.d.ts +3 -5
  19. package/packages/jam/block/work-result.d.ts.map +1 -1
  20. package/packages/jam/block/work-result.js +6 -0
  21. package/packages/jam/block-json/work-result.d.ts.map +1 -1
  22. package/packages/jam/block-json/work-result.js +6 -6
  23. package/packages/jam/database-lmdb/states.test.js +4 -3
  24. package/packages/jam/executor/index.d.ts +4 -0
  25. package/packages/jam/executor/index.d.ts.map +1 -0
  26. package/packages/jam/executor/index.js +2 -0
  27. package/packages/jam/{transition/accumulate → executor}/pvm-executor.d.ts +19 -16
  28. package/packages/jam/executor/pvm-executor.d.ts.map +1 -0
  29. package/packages/jam/{transition/accumulate → executor}/pvm-executor.js +46 -3
  30. package/packages/jam/in-core/externalities/refine.d.ts +24 -0
  31. package/packages/jam/in-core/externalities/refine.d.ts.map +1 -0
  32. package/packages/jam/in-core/externalities/refine.js +36 -0
  33. package/packages/jam/in-core/in-core.d.ts +60 -0
  34. package/packages/jam/in-core/in-core.d.ts.map +1 -0
  35. package/packages/jam/in-core/in-core.js +294 -0
  36. package/packages/jam/in-core/in-core.test.d.ts +2 -0
  37. package/packages/jam/in-core/in-core.test.d.ts.map +1 -0
  38. package/packages/jam/in-core/in-core.test.js +81 -0
  39. package/packages/jam/in-core/index.d.ts +2 -0
  40. package/packages/jam/in-core/index.d.ts.map +1 -0
  41. package/packages/jam/in-core/index.js +1 -0
  42. package/packages/jam/jam-host-calls/accumulate/bless.test.js +4 -5
  43. package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.d.ts +3 -3
  44. package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.d.ts.map +1 -1
  45. package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.test.js +2 -2
  46. package/packages/jam/rpc-validation/types.d.ts +7 -3
  47. package/packages/jam/rpc-validation/types.d.ts.map +1 -1
  48. package/packages/jam/rpc-validation/validation.d.ts +254 -36
  49. package/packages/jam/rpc-validation/validation.d.ts.map +1 -1
  50. package/packages/jam/rpc-validation/validation.js +20 -2
  51. package/packages/jam/state/in-memory-state.d.ts.map +1 -1
  52. package/packages/jam/state/in-memory-state.js +2 -3
  53. package/packages/jam/state/test.utils.d.ts.map +1 -1
  54. package/packages/jam/state/test.utils.js +2 -3
  55. package/packages/jam/transition/accumulate/accumulate-data.d.ts.map +1 -1
  56. package/packages/jam/transition/accumulate/accumulate-data.js +1 -2
  57. package/packages/jam/transition/accumulate/accumulate-queue.test.js +2 -2
  58. package/packages/jam/transition/accumulate/accumulate-utils.test.js +2 -2
  59. package/packages/jam/transition/accumulate/accumulate.d.ts.map +1 -1
  60. package/packages/jam/transition/accumulate/accumulate.js +8 -13
  61. package/packages/jam/transition/accumulate/accumulate.test.js +2 -2
  62. package/packages/jam/transition/accumulate/accumulation-result-merge-utils.d.ts.map +1 -1
  63. package/packages/jam/transition/accumulate/accumulation-result-merge-utils.js +1 -2
  64. package/packages/jam/transition/accumulate/accumulation-result-merge-utils.test.js +1 -2
  65. package/packages/jam/transition/accumulate/deferred-transfers.d.ts +1 -1
  66. package/packages/jam/transition/accumulate/deferred-transfers.d.ts.map +1 -1
  67. package/packages/jam/transition/accumulate/deferred-transfers.js +6 -7
  68. package/packages/jam/transition/disputes/disputes.test.data2.js +2 -2
  69. package/packages/jam/transition/externalities/fetch-externalities.d.ts +7 -1
  70. package/packages/jam/transition/externalities/fetch-externalities.d.ts.map +1 -1
  71. package/packages/jam/transition/externalities/fetch-externalities.js +4 -0
  72. package/packages/jam/transition/externalities/fetch-externalities.test.js +2 -2
  73. package/packages/jam/transition/hasher.test.js +2 -2
  74. package/packages/jam/transition/reports/test.utils.d.ts.map +1 -1
  75. package/packages/jam/transition/reports/test.utils.js +2 -2
  76. package/packages/jam/transition/accumulate/pvm-executor.d.ts.map +0 -1
@@ -1,10 +1,14 @@
1
- import type { ServiceId } from "#@typeberry/block";
1
+ import { type ServiceGas, type ServiceId } from "#@typeberry/block";
2
2
  import type { BytesBlob } from "#@typeberry/bytes";
3
3
  import type { ChainSpec, PvmBackend } from "#@typeberry/config";
4
4
  import { general } from "#@typeberry/jam-host-calls";
5
5
  import type { PartialState } from "#@typeberry/jam-host-calls/externalities/partial-state.js";
6
- import type { Gas } from "#@typeberry/pvm-interface";
7
- type AccumulateHostCallExternalities = {
6
+ import { type RefineExternalities } from "#@typeberry/jam-host-calls/externalities/refine-externalities.js";
7
+ export type RefineHostCallExternalities = {
8
+ refine: RefineExternalities;
9
+ fetchExternalities: general.IFetchExternalities;
10
+ };
11
+ export type AccumulateHostCallExternalities = {
8
12
  partialState: PartialState;
9
13
  fetchExternalities: general.IFetchExternalities;
10
14
  serviceExternalities: general.AccountsInfo & general.AccountsLookup & general.AccountsWrite & general.AccountsRead;
@@ -23,6 +27,8 @@ export declare class PvmExecutor {
23
27
  private hostCalls;
24
28
  private constructor();
25
29
  private static prepareBackend;
30
+ /** Prepare refine host call handlers */
31
+ private static prepareRefineHostCalls;
26
32
  /** Prepare accumulation host call handlers */
27
33
  private static prepareAccumulateHostCalls;
28
34
  /** Prepare on transfer host call handlers */
@@ -32,21 +38,18 @@ export declare class PvmExecutor {
32
38
  *
33
39
  * @param args additional arguments that will be placed in PVM memory before execution
34
40
  * @param gas gas limit
35
- * @returns `ReturnValue` object that can be a status or memory slice
41
+ * @returns `ReturnValue` object containing consumed gas, status and an optional memory slice
36
42
  */
37
- run(args: BytesBlob, gas: Gas): Promise<{
38
- consumedGas: Gas;
39
- status: import("@typeberry/pvm-interface").Status | null;
40
- memorySlice: Uint8Array | null;
41
- hasMemorySlice(): this is /*elided*/ any & {
42
- status: null;
43
- memorySlice: Uint8Array;
44
- };
45
- hasStatus(): this is /*elided*/ any & {
46
- status: import("@typeberry/pvm-interface").Status;
47
- memorySlice: null;
48
- };
43
+ run(args: BytesBlob, gas: ServiceGas): Promise<{
44
+ consumedGas: bigint & import("@typeberry/numbers").WithBytesRepresentation<8> & import("@typeberry/utils").WithOpaque<"ServiceGas[u64]">;
45
+ status: import("@typeberry/pvm-host-calls").ReturnStatus.OK;
46
+ memorySlice: Uint8Array;
47
+ } | {
48
+ consumedGas: bigint & import("@typeberry/numbers").WithBytesRepresentation<8> & import("@typeberry/utils").WithOpaque<"ServiceGas[u64]">;
49
+ status: import("@typeberry/pvm-host-calls").ReturnStatus.OOG | import("@typeberry/pvm-host-calls").ReturnStatus.PANIC;
49
50
  }>;
51
+ /** A utility function that can be used to prepare refine executor */
52
+ static createRefineExecutor(serviceId: ServiceId, serviceCode: BytesBlob, externalities: RefineHostCallExternalities, pvm: PvmBackend): Promise<PvmExecutor>;
50
53
  /** A utility function that can be used to prepare accumulate executor */
51
54
  static createAccumulateExecutor(serviceId: ServiceId, serviceCode: BytesBlob, externalities: AccumulateHostCallExternalities, chainSpec: ChainSpec, pvm: PvmBackend): Promise<PvmExecutor>;
52
55
  /** A utility function that can be used to prepare on transfer executor */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pvm-executor.d.ts","sourceRoot":"","sources":["../../../../../packages/jam/executor/pvm-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAmB,MAAM,kBAAkB,CAAC;AACpF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAc,OAAO,EAAU,MAAM,2BAA2B,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0DAA0D,CAAC;AAC7F,OAAO,EAEL,KAAK,mBAAmB,EAEzB,MAAM,iEAAiE,CAAC;AAuCzE,MAAM,MAAM,2BAA2B,GAAG;IACxC,MAAM,EAAE,mBAAmB,CAAC;IAC5B,kBAAkB,EAAE,OAAO,CAAC,mBAAmB,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,YAAY,EAAE,YAAY,CAAC;IAC3B,kBAAkB,EAAE,OAAO,CAAC,mBAAmB,CAAC;IAChD,oBAAoB,EAAE,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;CACpH,CAAC;AAEF,KAAK,+BAA+B,GAAG;IACrC,YAAY,EAAE,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IAC3G,kBAAkB,EAAE,OAAO,CAAC,mBAAmB,CAAC;CACjD,CAAC;AAUF;;GAEG;AACH,qBAAa,WAAW;IAKpB,OAAO,CAAC,WAAW;IAEnB,OAAO,CAAC,UAAU;IANpB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAoB;IACxC,OAAO,CAAC,SAAS,CAAY;IAE7B,OAAO;mBAac,cAAc;IAInC,wCAAwC;IACxC,OAAO,CAAC,MAAM,CAAC,sBAAsB;IAerC,8CAA8C;IAC9C,OAAO,CAAC,MAAM,CAAC,0BAA0B;IAuBzC,6CAA6C;IAC7C,OAAO,CAAC,MAAM,CAAC,0BAA0B;IAazC;;;;;;OAMG;IACG,GAAG,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,UAAU;;;;;;;;IAQ1C,qEAAqE;WACxD,oBAAoB,CAC/B,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,SAAS,EACtB,aAAa,EAAE,2BAA2B,EAC1C,GAAG,EAAE,UAAU;IAOjB,yEAAyE;WAC5D,wBAAwB,CACnC,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,SAAS,EACtB,aAAa,EAAE,+BAA+B,EAC9C,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,UAAU;IAQjB,0EAA0E;WAC7D,wBAAwB,CACnC,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,SAAS,EACtB,aAAa,EAAE,+BAA+B,EAC9C,GAAG,EAAE,UAAU;CAMlB"}
@@ -1,6 +1,26 @@
1
- import { accumulate, general } from "#@typeberry/jam-host-calls";
1
+ import { tryAsServiceGas } from "#@typeberry/block";
2
+ import { accumulate, general, refine } from "#@typeberry/jam-host-calls";
2
3
  import { tryAsProgramCounter, } from "#@typeberry/jam-host-calls/externalities/refine-externalities.js";
3
4
  import { HostCalls, HostCallsExecutor, PvmInstanceManager } from "#@typeberry/pvm-host-calls";
5
+ import { tryAsGas } from "#@typeberry/pvm-interface";
6
+ /**
7
+ * Refine-specific host calls with common constructor.
8
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/2fa7022fa702?v=0.7.2
9
+ */
10
+ const REFINE_HOST_CALL_CLASSES = [
11
+ refine.HistoricalLookup,
12
+ refine.Export,
13
+ refine.Machine,
14
+ refine.Peek,
15
+ refine.Poke,
16
+ refine.Pages,
17
+ refine.Invoke,
18
+ refine.Expunge,
19
+ ];
20
+ /**
21
+ * Accumulate-specific host calls with common constructor.
22
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/30d00130d001?v=0.7.2
23
+ */
4
24
  const ACCUMULATE_HOST_CALL_CLASSES = [
5
25
  accumulate.Bless,
6
26
  accumulate.Assign,
@@ -21,6 +41,7 @@ var entrypoint;
21
41
  entrypoint.IS_AUTHORIZED = tryAsProgramCounter(0);
22
42
  entrypoint.REFINE = tryAsProgramCounter(0);
23
43
  entrypoint.ACCUMULATE = tryAsProgramCounter(5);
44
+ /** @deprecated since 0.7.1 */
24
45
  entrypoint.ON_TRANSFER = tryAsProgramCounter(10);
25
46
  })(entrypoint || (entrypoint = {}));
26
47
  /**
@@ -43,9 +64,21 @@ export class PvmExecutor {
43
64
  static async prepareBackend(pvm) {
44
65
  return PvmInstanceManager.new(pvm);
45
66
  }
67
+ /** Prepare refine host call handlers */
68
+ static prepareRefineHostCalls(serviceId, externalities) {
69
+ const refineHandlers = REFINE_HOST_CALL_CLASSES.map((HandlerClass) => new HandlerClass(externalities.refine));
70
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/2fa7022fa702?v=0.7.2 */
71
+ const generalHandlers = [
72
+ new general.LogHostCall(serviceId),
73
+ new general.GasHostCall(serviceId),
74
+ new general.Fetch(serviceId, externalities.fetchExternalities),
75
+ ];
76
+ return refineHandlers.concat(generalHandlers);
77
+ }
46
78
  /** Prepare accumulation host call handlers */
47
79
  static prepareAccumulateHostCalls(serviceId, externalities, chainSpec) {
48
80
  const accumulateHandlers = ACCUMULATE_HOST_CALL_CLASSES.map((HandlerClass) => new HandlerClass(serviceId, externalities.partialState, chainSpec));
81
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/30d00130d001?v=0.7.2 */
49
82
  const generalHandlers = [
50
83
  new general.LogHostCall(serviceId),
51
84
  new general.GasHostCall(serviceId),
@@ -75,10 +108,20 @@ export class PvmExecutor {
75
108
  *
76
109
  * @param args additional arguments that will be placed in PVM memory before execution
77
110
  * @param gas gas limit
78
- * @returns `ReturnValue` object that can be a status or memory slice
111
+ * @returns `ReturnValue` object containing consumed gas, status and an optional memory slice
79
112
  */
80
113
  async run(args, gas) {
81
- return this.pvm.runProgram(this.serviceCode.raw, args.raw, Number(this.entrypoint), gas);
114
+ const ret = await this.pvm.runProgram(this.serviceCode.raw, args.raw, Number(this.entrypoint), tryAsGas(gas));
115
+ return {
116
+ ...ret,
117
+ consumedGas: tryAsServiceGas(ret.consumedGas),
118
+ };
119
+ }
120
+ /** A utility function that can be used to prepare refine executor */
121
+ static async createRefineExecutor(serviceId, serviceCode, externalities, pvm) {
122
+ const hostCallHandlers = PvmExecutor.prepareRefineHostCalls(serviceId, externalities);
123
+ const instances = await PvmExecutor.prepareBackend(pvm);
124
+ return new PvmExecutor(serviceCode, hostCallHandlers, entrypoint.REFINE, instances);
82
125
  }
83
126
  /** A utility function that can be used to prepare accumulate executor */
84
127
  static async createAccumulateExecutor(serviceId, serviceCode, externalities, chainSpec, pvm) {
@@ -0,0 +1,24 @@
1
+ import type { Segment, SegmentIndex, ServiceId } from "#@typeberry/block";
2
+ import type { BytesBlob } from "#@typeberry/bytes";
3
+ import type { Blake2bHash } from "#@typeberry/hash";
4
+ import type { MachineId, MachineResult, MemoryOperation, NoMachineError, PagesError, PeekPokeError, ProgramCounter, RefineExternalities, SegmentExportError, ZeroVoidError } from "#@typeberry/jam-host-calls";
5
+ import type { U64 } from "#@typeberry/numbers";
6
+ import type { HostCallMemory, HostCallRegisters } from "#@typeberry/pvm-host-calls";
7
+ import type { BigGas } from "#@typeberry/pvm-interface";
8
+ import type { ProgramDecoderError } from "#@typeberry/pvm-interpreter";
9
+ import type { OK, Result } from "#@typeberry/utils";
10
+ export declare class RefineExternalitiesImpl implements RefineExternalities {
11
+ static create(): RefineExternalitiesImpl;
12
+ private constructor();
13
+ machineExpunge(_machineIndex: MachineId): Promise<Result<ProgramCounter, NoMachineError>>;
14
+ machinePages(_machineIndex: MachineId, _pageStart: U64, _pageCount: U64, _requestType: MemoryOperation | null): Promise<Result<OK, PagesError>>;
15
+ machineVoidPages(_machineIndex: MachineId, _pageStart: U64, _pageCount: U64): Promise<Result<OK, ZeroVoidError>>;
16
+ machineZeroPages(_machineIndex: MachineId, _pageStart: U64, _pageCount: U64): Promise<Result<OK, ZeroVoidError>>;
17
+ machinePeekFrom(_machineIndex: MachineId, _destinationStart: U64, _sourceStart: U64, _length: U64, _destination: HostCallMemory): Promise<Result<OK, PeekPokeError>>;
18
+ machinePokeInto(_machineIndex: MachineId, _sourceStart: U64, _destinationStart: U64, _length: U64, _source: HostCallMemory): Promise<Result<OK, PeekPokeError>>;
19
+ machineInit(_code: BytesBlob, _programCounter: ProgramCounter): Promise<Result<MachineId, ProgramDecoderError>>;
20
+ machineInvoke(_machineIndex: MachineId, _gas: BigGas, _registers: HostCallRegisters): Promise<Result<MachineResult, NoMachineError>>;
21
+ exportSegment(_segment: Segment): Result<SegmentIndex, SegmentExportError>;
22
+ historicalLookup(_serviceId: ServiceId | null, _hash: Blake2bHash): Promise<BytesBlob | null>;
23
+ }
24
+ //# sourceMappingURL=refine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refine.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/in-core/externalities/refine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EACb,eAAe,EACf,cAAc,EACd,UAAU,EACV,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACd,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAEnD,qBAAa,uBAAwB,YAAW,mBAAmB;IACjE,MAAM,CAAC,MAAM;IAIb,OAAO;IAEP,cAAc,CAAC,aAAa,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IAIzF,YAAY,CACV,aAAa,EAAE,SAAS,EACxB,UAAU,EAAE,GAAG,EACf,UAAU,EAAE,GAAG,EACf,YAAY,EAAE,eAAe,GAAG,IAAI,GACnC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;IAIlC,gBAAgB,CAAC,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC;IAIhH,gBAAgB,CAAC,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC;IAIhH,eAAe,CACb,aAAa,EAAE,SAAS,EACxB,iBAAiB,EAAE,GAAG,EACtB,YAAY,EAAE,GAAG,EACjB,OAAO,EAAE,GAAG,EACZ,YAAY,EAAE,cAAc,GAC3B,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC;IAIrC,eAAe,CACb,aAAa,EAAE,SAAS,EACxB,YAAY,EAAE,GAAG,EACjB,iBAAiB,EAAE,GAAG,EACtB,OAAO,EAAE,GAAG,EACZ,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC;IAIrC,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;IAI/G,aAAa,CACX,aAAa,EAAE,SAAS,EACxB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,iBAAiB,GAC5B,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;IAIjD,aAAa,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC,YAAY,EAAE,kBAAkB,CAAC;IAI1E,gBAAgB,CAAC,UAAU,EAAE,SAAS,GAAG,IAAI,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;CAG9F"}
@@ -0,0 +1,36 @@
1
+ export class RefineExternalitiesImpl {
2
+ static create() {
3
+ return new RefineExternalitiesImpl();
4
+ }
5
+ constructor() { }
6
+ machineExpunge(_machineIndex) {
7
+ throw new Error("Method not implemented.");
8
+ }
9
+ machinePages(_machineIndex, _pageStart, _pageCount, _requestType) {
10
+ throw new Error("Method not implemented.");
11
+ }
12
+ machineVoidPages(_machineIndex, _pageStart, _pageCount) {
13
+ throw new Error("Method not implemented.");
14
+ }
15
+ machineZeroPages(_machineIndex, _pageStart, _pageCount) {
16
+ throw new Error("Method not implemented.");
17
+ }
18
+ machinePeekFrom(_machineIndex, _destinationStart, _sourceStart, _length, _destination) {
19
+ throw new Error("Method not implemented.");
20
+ }
21
+ machinePokeInto(_machineIndex, _sourceStart, _destinationStart, _length, _source) {
22
+ throw new Error("Method not implemented.");
23
+ }
24
+ machineInit(_code, _programCounter) {
25
+ throw new Error("Method not implemented.");
26
+ }
27
+ machineInvoke(_machineIndex, _gas, _registers) {
28
+ throw new Error("Method not implemented.");
29
+ }
30
+ exportSegment(_segment) {
31
+ throw new Error("Method not implemented.");
32
+ }
33
+ historicalLookup(_serviceId, _hash) {
34
+ throw new Error("Method not implemented.");
35
+ }
36
+ }
@@ -0,0 +1,60 @@
1
+ import { type CoreIndex, type Segment, type SegmentIndex, type ServiceGas } from "#@typeberry/block";
2
+ import { type WorkPackageHash } from "#@typeberry/block/refine-context.js";
3
+ import type { WorkItemExtrinsic } from "#@typeberry/block/work-item.js";
4
+ import type { WorkPackage } from "#@typeberry/block/work-package.js";
5
+ import { WorkReport } from "#@typeberry/block/work-report.js";
6
+ import { WorkExecResult, WorkResult } from "#@typeberry/block/work-result.js";
7
+ import { type KnownSizeArray } from "#@typeberry/collections";
8
+ import type { ChainSpec, PvmBackend } from "#@typeberry/config";
9
+ import type { StatesDb } from "#@typeberry/database";
10
+ import { type ReturnValue } from "#@typeberry/executor";
11
+ import { type Blake2b, type WithHash } from "#@typeberry/hash";
12
+ import { Result } from "#@typeberry/utils";
13
+ export type RefineResult = {
14
+ report: WorkReport;
15
+ exports: PerWorkItem<Segment[]>;
16
+ };
17
+ export type RefineItemResult = {
18
+ result: WorkResult;
19
+ exports: Segment[];
20
+ };
21
+ export declare enum RefineError {
22
+ /** State for context anchor block or lookup anchor is not found in the DB. */
23
+ StateMissing = 0,
24
+ /** Posterior state root of context anchor block does not match the one in the DB. */
25
+ StateRootMismatch = 1,
26
+ /** Lookup anchor state-slot does not match the one given in context. */
27
+ InvalidLookupAnchorSlot = 2,
28
+ /** Authorization error. */
29
+ AuthorizationError = 3
30
+ }
31
+ export type PerWorkItem<T> = KnownSizeArray<T, "for each work item">;
32
+ export type ImportedSegment = {
33
+ index: SegmentIndex;
34
+ data: Segment;
35
+ };
36
+ export declare class InCore {
37
+ readonly chainSpec: ChainSpec;
38
+ private readonly states;
39
+ private readonly pvmBackend;
40
+ private readonly blake2b;
41
+ constructor(chainSpec: ChainSpec, states: StatesDb, pvmBackend: PvmBackend, blake2b: Blake2b);
42
+ /**
43
+ * Work-report computation function.
44
+ *
45
+ * Note this requires all of the imports and extrinsics to be already fetched
46
+ * and only performs the refinement.
47
+ *
48
+ * Any validation must be done externally!
49
+ *
50
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/1b7f021b7f02?v=0.7.2
51
+ */
52
+ refine(workPackageAndHash: WithHash<WorkPackageHash, WorkPackage>, core: CoreIndex, imports: PerWorkItem<ImportedSegment[]>, extrinsics: PerWorkItem<WorkItemExtrinsic[]>): Promise<Result<RefineResult, RefineError>>;
53
+ private amalgamateWorkReport;
54
+ private authorizePackage;
55
+ private refineItem;
56
+ extractWorkResult(execResult: ReturnValue<ServiceGas>): WorkExecResult;
57
+ private getServiceCode;
58
+ private createRefineExternalities;
59
+ }
60
+ //# sourceMappingURL=in-core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-core.d.ts","sourceRoot":"","sources":["../../../../../packages/jam/in-core/in-core.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,UAAU,EAIhB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAGL,KAAK,eAAe,EAErB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAY,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAmB,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAsC,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAGjH,OAAO,EAA+B,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC1F,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAA+D,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACpH,OAAO,EAAE,KAAK,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAKzE,OAAO,EAA4B,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAGpE,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,OAAO,EAAE,CAAC;CACpB,CAAC;AAEF,oBAAY,WAAW;IACrB,8EAA8E;IAC9E,YAAY,IAAI;IAChB,qFAAqF;IACrF,iBAAiB,IAAI;IACrB,wEAAwE;IACxE,uBAAuB,IAAI;IAC3B,2BAA2B;IAC3B,kBAAkB,IAAI;CACvB;AAqBD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC;AAErE,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,YAAY,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAgBF,qBAAa,MAAM;aAEC,SAAS,EAAE,SAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAHR,SAAS,EAAE,SAAS,EACnB,MAAM,EAAE,QAAQ,EAChB,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,OAAO;IAGnC;;;;;;;;;OASG;IACG,MAAM,CACV,kBAAkB,EAAE,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,EAC1D,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,WAAW,CAAC,eAAe,EAAE,CAAC,EACvC,UAAU,EAAE,WAAW,CAAC,iBAAiB,EAAE,CAAC,GAC3C,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IAmE7C,OAAO,CAAC,oBAAoB;YAuDd,gBAAgB;YAkBhB,UAAU;IAgGxB,iBAAiB,CAAC,UAAU,EAAE,WAAW,CAAC,UAAU,CAAC;IAiBrD,OAAO,CAAC,cAAc;IAyCtB,OAAO,CAAC,yBAAyB;CAoBlC"}
@@ -0,0 +1,294 @@
1
+ import { tryAsCoreIndex, tryAsServiceGas, } from "#@typeberry/block";
2
+ import { W_C } from "#@typeberry/block/gp-constants.js";
3
+ import { WorkPackageInfo, } from "#@typeberry/block/refine-context.js";
4
+ import { WorkPackageSpec, WorkReport } from "#@typeberry/block/work-report.js";
5
+ import { WorkExecResult, WorkExecResultKind, WorkRefineLoad, WorkResult } from "#@typeberry/block/work-result.js";
6
+ import { Bytes, BytesBlob } from "#@typeberry/bytes";
7
+ import { codec, Encoder } from "#@typeberry/codec";
8
+ import { asKnownSize, FixedSizeArray } from "#@typeberry/collections";
9
+ import { PvmExecutor, ReturnStatus } from "#@typeberry/executor";
10
+ import { HASH_SIZE } from "#@typeberry/hash";
11
+ import { Logger } from "#@typeberry/logger";
12
+ import { tryAsU8, tryAsU16, tryAsU32 } from "#@typeberry/numbers";
13
+ import { FetchExternalities } from "#@typeberry/transition/externalities/fetch-externalities.js";
14
+ import { assertEmpty, assertNever, Result } from "#@typeberry/utils";
15
+ import { RefineExternalitiesImpl } from "./externalities/refine.js";
16
+ export var RefineError;
17
+ (function (RefineError) {
18
+ /** State for context anchor block or lookup anchor is not found in the DB. */
19
+ RefineError[RefineError["StateMissing"] = 0] = "StateMissing";
20
+ /** Posterior state root of context anchor block does not match the one in the DB. */
21
+ RefineError[RefineError["StateRootMismatch"] = 1] = "StateRootMismatch";
22
+ /** Lookup anchor state-slot does not match the one given in context. */
23
+ RefineError[RefineError["InvalidLookupAnchorSlot"] = 2] = "InvalidLookupAnchorSlot";
24
+ /** Authorization error. */
25
+ RefineError[RefineError["AuthorizationError"] = 3] = "AuthorizationError";
26
+ })(RefineError || (RefineError = {}));
27
+ var ServiceCodeError;
28
+ (function (ServiceCodeError) {
29
+ /** Service id is not found in the state. */
30
+ ServiceCodeError[ServiceCodeError["ServiceNotFound"] = 0] = "ServiceNotFound";
31
+ /** Expected service code does not match the state one. */
32
+ ServiceCodeError[ServiceCodeError["ServiceCodeMismatch"] = 1] = "ServiceCodeMismatch";
33
+ /** Code preimage missing. */
34
+ ServiceCodeError[ServiceCodeError["ServiceCodeMissing"] = 2] = "ServiceCodeMissing";
35
+ /** Code blob is too big. */
36
+ ServiceCodeError[ServiceCodeError["ServiceCodeTooBig"] = 3] = "ServiceCodeTooBig";
37
+ })(ServiceCodeError || (ServiceCodeError = {}));
38
+ var AuthorizationError;
39
+ (function (AuthorizationError) {
40
+ })(AuthorizationError || (AuthorizationError = {}));
41
+ const logger = Logger.new(import.meta.filename, "refine");
42
+ /** https://graypaper.fluffylabs.dev/#/ab2cdbd/2ffe002ffe00?v=0.7.2 */
43
+ const ARGS_CODEC = codec.object({
44
+ core: codec.varU32.convert((x) => tryAsU32(x), (x) => tryAsCoreIndex(x)),
45
+ workItemIndex: codec.varU32,
46
+ serviceId: codec.varU32.asOpaque(),
47
+ payloadLength: codec.varU32,
48
+ packageHash: codec.bytes(HASH_SIZE).asOpaque(),
49
+ });
50
+ export class InCore {
51
+ chainSpec;
52
+ states;
53
+ pvmBackend;
54
+ blake2b;
55
+ constructor(chainSpec, states, pvmBackend, blake2b) {
56
+ this.chainSpec = chainSpec;
57
+ this.states = states;
58
+ this.pvmBackend = pvmBackend;
59
+ this.blake2b = blake2b;
60
+ }
61
+ /**
62
+ * Work-report computation function.
63
+ *
64
+ * Note this requires all of the imports and extrinsics to be already fetched
65
+ * and only performs the refinement.
66
+ *
67
+ * Any validation must be done externally!
68
+ *
69
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/1b7f021b7f02?v=0.7.2
70
+ */
71
+ async refine(workPackageAndHash, core, imports, extrinsics) {
72
+ const workPackageHash = workPackageAndHash.hash;
73
+ const { context, authorization, authCodeHash, authCodeHost, parametrization, items, ...rest } = workPackageAndHash.data;
74
+ assertEmpty(rest);
75
+ // TODO [ToDr] Verify BEEFY root
76
+ // TODO [ToDr] Verify prerequisites
77
+ logger.log `[core:${core}] Attempting to refine work package with ${items.length} items.`;
78
+ // TODO [ToDr] GP link
79
+ // Verify anchor block
80
+ const state = this.states.getState(context.anchor);
81
+ if (state === null) {
82
+ return Result.error(RefineError.StateMissing, () => `State at anchor block ${context.anchor} is missing.`);
83
+ }
84
+ const stateRoot = await this.states.getStateRoot(state);
85
+ if (!stateRoot.isEqualTo(context.stateRoot)) {
86
+ return Result.error(RefineError.StateRootMismatch, () => `State at ${context.anchor} does not match expected root hash. Ours: ${stateRoot}, expected: ${context.stateRoot}`);
87
+ }
88
+ // TODO [ToDr] GP link
89
+ // Verify lookup anchor state
90
+ const lookupState = this.states.getState(context.lookupAnchor);
91
+ if (lookupState === null) {
92
+ return Result.error(RefineError.StateMissing, () => `Lookup state at block ${context.lookupAnchor} is missing.`);
93
+ }
94
+ // TODO [ToDr] GP link
95
+ if (lookupState.timeslot !== context.lookupAnchorSlot) {
96
+ return Result.error(RefineError.InvalidLookupAnchorSlot, () => `Lookup anchor slot does not match the one is state. Ours: ${lookupState.timeslot}, expected: ${context.lookupAnchorSlot}`);
97
+ }
98
+ // Check authorization
99
+ const authResult = await this.authorizePackage(authorization, authCodeHost, authCodeHash, parametrization);
100
+ if (authResult.isError) {
101
+ return Result.error(RefineError.AuthorizationError, () => `Authorization error: ${AuthorizationError[authResult.error]}: ${authResult.details()}.`);
102
+ }
103
+ logger.log `[core:${core}] Authorized. Proceeding with work items verification. Anchor=${context.anchor}`;
104
+ // Verify the work items
105
+ const refineResults = [];
106
+ for (const [idx, item] of items.entries()) {
107
+ logger.info `[core:${core}][i:${idx}] Refining item for service ${item.service}.`;
108
+ refineResults.push(await this.refineItem(state, idx, item, imports, extrinsics, core, workPackageHash));
109
+ }
110
+ // amalgamate the work report now
111
+ return Result.ok(this.amalgamateWorkReport(asKnownSize(refineResults), authResult.ok, workPackageHash, context, core));
112
+ }
113
+ amalgamateWorkReport(refineResults, authResult, workPackageHash, context, coreIndex) {
114
+ // unzip exports and work results for each work item
115
+ const exports = refineResults.map((x) => x.exports);
116
+ const results = refineResults.map((x) => x.result);
117
+ const { authorizerHash, authorizationGasUsed, authorizationOutput, ...authRest } = authResult;
118
+ assertEmpty(authRest);
119
+ // TODO [ToDr] Compute erasure root
120
+ const erasureRoot = Bytes.zero(HASH_SIZE);
121
+ // TODO [ToDr] Compute exports root
122
+ const exportsRoot = Bytes.zero(HASH_SIZE).asOpaque();
123
+ const exportsCount = exports.reduce((acc, x) => acc + x.length, 0);
124
+ // TODO [ToDr] Segment root lookup computation?
125
+ const segmentRootLookup = [
126
+ WorkPackageInfo.create({
127
+ workPackageHash,
128
+ segmentTreeRoot: exportsRoot,
129
+ }),
130
+ ];
131
+ // TODO [ToDr] Auditable work bundle length?
132
+ const workBundleLength = tryAsU32(0);
133
+ return {
134
+ report: WorkReport.create({
135
+ workPackageSpec: WorkPackageSpec.create({
136
+ length: workBundleLength,
137
+ hash: workPackageHash,
138
+ erasureRoot,
139
+ exportsRoot,
140
+ // safe to convert, since we have limit on number of
141
+ // exports per item and a limit for number of items
142
+ exportsCount: tryAsU16(exportsCount),
143
+ }),
144
+ context,
145
+ coreIndex,
146
+ authorizerHash,
147
+ authorizationGasUsed,
148
+ authorizationOutput,
149
+ segmentRootLookup,
150
+ // safe to convert, since we know that number of work items is limited
151
+ results: FixedSizeArray.new(results, tryAsU8(refineResults.length)),
152
+ }),
153
+ exports: asKnownSize(exports),
154
+ };
155
+ }
156
+ async authorizePackage(_authorization, _authCodeHost, _authCodeHash, _parametrization) {
157
+ // TODO [ToDr] Check authorization?
158
+ const authorizerHash = Bytes.zero(HASH_SIZE).asOpaque();
159
+ const authorizationGasUsed = tryAsServiceGas(0);
160
+ const authorizationOutput = BytesBlob.empty();
161
+ return Result.ok({
162
+ authorizerHash,
163
+ authorizationGasUsed,
164
+ authorizationOutput,
165
+ });
166
+ }
167
+ async refineItem(state, idx, item, allImports, allExtrinsics, coreIndex, workPackageHash) {
168
+ const payloadHash = this.blake2b.hashBytes(item.payload);
169
+ const baseResult = {
170
+ serviceId: item.service,
171
+ codeHash: item.codeHash,
172
+ payloadHash,
173
+ gas: item.refineGasLimit,
174
+ };
175
+ const imports = allImports[idx];
176
+ const extrinsics = allExtrinsics[idx];
177
+ const baseLoad = {
178
+ importedSegments: tryAsU32(imports.length),
179
+ extrinsicCount: tryAsU32(extrinsics.length),
180
+ extrinsicSize: tryAsU32(extrinsics.reduce((acc, x) => acc + x.length, 0)),
181
+ };
182
+ const maybeCode = this.getServiceCode(state, idx, item);
183
+ if (maybeCode.isError) {
184
+ const error = maybeCode.error === ServiceCodeError.ServiceCodeTooBig
185
+ ? WorkExecResultKind.codeOversize
186
+ : WorkExecResultKind.badCode;
187
+ return {
188
+ exports: [],
189
+ result: WorkResult.create({
190
+ ...baseResult,
191
+ result: WorkExecResult.error(error),
192
+ load: WorkRefineLoad.create({
193
+ ...baseLoad,
194
+ gasUsed: tryAsServiceGas(item.refineGasLimit),
195
+ exportedSegments: tryAsU32(0),
196
+ }),
197
+ }),
198
+ };
199
+ }
200
+ const code = maybeCode.ok;
201
+ const externalities = this.createRefineExternalities({
202
+ payload: item.payload,
203
+ imports: allImports,
204
+ extrinsics: allExtrinsics,
205
+ });
206
+ const executor = await PvmExecutor.createRefineExecutor(item.service, code, externalities, this.pvmBackend);
207
+ const args = Encoder.encodeObject(ARGS_CODEC, {
208
+ serviceId: item.service,
209
+ core: coreIndex,
210
+ workItemIndex: tryAsU32(idx),
211
+ payloadLength: tryAsU32(item.payload.length),
212
+ packageHash: workPackageHash,
213
+ });
214
+ const execResult = await executor.run(args, item.refineGasLimit);
215
+ // TODO [ToDr] get exports from externalities
216
+ const exports = [];
217
+ if (exports.length !== item.exportCount) {
218
+ return {
219
+ exports,
220
+ result: WorkResult.create({
221
+ ...baseResult,
222
+ result: WorkExecResult.error(WorkExecResultKind.incorrectNumberOfExports),
223
+ load: WorkRefineLoad.create({
224
+ ...baseLoad,
225
+ gasUsed: tryAsServiceGas(item.refineGasLimit),
226
+ exportedSegments: tryAsU32(0),
227
+ }),
228
+ }),
229
+ };
230
+ }
231
+ const result = this.extractWorkResult(execResult);
232
+ return {
233
+ exports,
234
+ result: WorkResult.create({
235
+ ...baseResult,
236
+ result,
237
+ load: WorkRefineLoad.create({
238
+ ...baseLoad,
239
+ gasUsed: tryAsServiceGas(execResult.consumedGas),
240
+ exportedSegments: tryAsU32(exports.length),
241
+ }),
242
+ }),
243
+ };
244
+ }
245
+ extractWorkResult(execResult) {
246
+ if (execResult.status === ReturnStatus.OK) {
247
+ const slice = execResult.memorySlice;
248
+ // TODO [ToDr] Verify the output size and change digestTooBig?
249
+ return WorkExecResult.ok(BytesBlob.blobFrom(slice));
250
+ }
251
+ switch (execResult.status) {
252
+ case ReturnStatus.OOG:
253
+ return WorkExecResult.error(WorkExecResultKind.outOfGas);
254
+ case ReturnStatus.PANIC:
255
+ return WorkExecResult.error(WorkExecResultKind.panic);
256
+ default:
257
+ assertNever(execResult);
258
+ }
259
+ }
260
+ getServiceCode(state, idx, item) {
261
+ const serviceId = item.service;
262
+ const service = state.getService(serviceId);
263
+ // TODO [ToDr] GP link
264
+ // missing service
265
+ if (service === null) {
266
+ return Result.error(ServiceCodeError.ServiceNotFound, () => `[i:${idx}] Service ${serviceId} is missing in state.`);
267
+ }
268
+ // TODO [ToDr] GP link
269
+ // TODO [ToDr] shall we rather use the old codehash instead
270
+ if (!service.getInfo().codeHash.isEqualTo(item.codeHash)) {
271
+ return Result.error(ServiceCodeError.ServiceCodeMismatch, () => `[i:${idx}] Service ${serviceId} has invalid code hash. Ours: ${service.getInfo().codeHash}, expected: ${item.codeHash}`);
272
+ }
273
+ const code = service.getPreimage(item.codeHash.asOpaque());
274
+ if (code === null) {
275
+ return Result.error(ServiceCodeError.ServiceCodeMissing, () => `[i:${idx}] Code ${item.codeHash} for service ${serviceId} was not found.`);
276
+ }
277
+ if (code.length > W_C) {
278
+ return Result.error(ServiceCodeError.ServiceCodeTooBig, () => `[i:${idx}] Code ${item.codeHash} for service ${serviceId} is too big! ${code.length} bytes vs ${W_C} bytes max.`);
279
+ }
280
+ return Result.ok(code);
281
+ }
282
+ createRefineExternalities(args) {
283
+ // TODO [ToDr] Pass all required fetch data
284
+ const fetchExternalities = FetchExternalities.createForRefine({
285
+ entropy: undefined,
286
+ ...args,
287
+ }, this.chainSpec);
288
+ const refine = RefineExternalitiesImpl.create();
289
+ return {
290
+ fetchExternalities,
291
+ refine,
292
+ };
293
+ }
294
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=in-core.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-core.test.d.ts","sourceRoot":"","sources":["../../../../../packages/jam/in-core/in-core.test.ts"],"names":[],"mappings":""}