@typeberry/lib 0.5.3-355fdf7 → 0.5.3-5a6cfcc

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 (124) 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/networking/certificate.d.ts.map +1 -1
  5. package/packages/core/networking/certificate.js +1 -0
  6. package/packages/core/networking/setup.d.ts.map +1 -1
  7. package/packages/core/networking/setup.js +16 -12
  8. package/packages/core/numbers/index.d.ts +4 -0
  9. package/packages/core/numbers/index.d.ts.map +1 -1
  10. package/packages/core/numbers/index.js +4 -4
  11. package/packages/core/pvm-host-calls/host-calls-executor.d.ts +23 -17
  12. package/packages/core/pvm-host-calls/host-calls-executor.d.ts.map +1 -1
  13. package/packages/core/pvm-host-calls/host-calls-executor.js +23 -31
  14. package/packages/core/pvm-interpreter/ops/math-consts.d.ts +2 -3
  15. package/packages/core/pvm-interpreter/ops/math-consts.d.ts.map +1 -1
  16. package/packages/core/pvm-interpreter/ops/math-consts.js +2 -3
  17. package/packages/core/pvm-interpreter/ops/math-ops.js +3 -3
  18. package/packages/core/pvm-interpreter/ops/math-utils.js +13 -13
  19. package/packages/core/pvm-interpreter/ops/math-utils.test.js +17 -16
  20. package/packages/extensions/ipc/jamnp/handler.d.ts +5 -4
  21. package/packages/extensions/ipc/jamnp/handler.d.ts.map +1 -1
  22. package/packages/extensions/ipc/jamnp/handler.js +59 -34
  23. package/packages/extensions/ipc/jamnp/stream.d.ts +6 -4
  24. package/packages/extensions/ipc/jamnp/stream.d.ts.map +1 -1
  25. package/packages/jam/block/work-item.d.ts +13 -4
  26. package/packages/jam/block/work-item.d.ts.map +1 -1
  27. package/packages/jam/block/work-result.d.ts +3 -5
  28. package/packages/jam/block/work-result.d.ts.map +1 -1
  29. package/packages/jam/block/work-result.js +6 -0
  30. package/packages/jam/block-json/work-result.d.ts.map +1 -1
  31. package/packages/jam/block-json/work-result.js +6 -6
  32. package/packages/jam/database-lmdb/states.test.js +4 -3
  33. package/packages/jam/executor/index.d.ts +4 -0
  34. package/packages/jam/executor/index.d.ts.map +1 -0
  35. package/packages/jam/executor/index.js +2 -0
  36. package/packages/jam/{transition/accumulate → executor}/pvm-executor.d.ts +19 -16
  37. package/packages/jam/executor/pvm-executor.d.ts.map +1 -0
  38. package/packages/jam/{transition/accumulate → executor}/pvm-executor.js +46 -3
  39. package/packages/jam/in-core/externalities/refine.d.ts +24 -0
  40. package/packages/jam/in-core/externalities/refine.d.ts.map +1 -0
  41. package/packages/jam/in-core/externalities/refine.js +36 -0
  42. package/packages/jam/in-core/in-core.d.ts +60 -0
  43. package/packages/jam/in-core/in-core.d.ts.map +1 -0
  44. package/packages/jam/in-core/in-core.js +294 -0
  45. package/packages/jam/in-core/in-core.test.d.ts +2 -0
  46. package/packages/jam/in-core/in-core.test.d.ts.map +1 -0
  47. package/packages/jam/in-core/in-core.test.js +81 -0
  48. package/packages/jam/in-core/index.d.ts +2 -0
  49. package/packages/jam/in-core/index.d.ts.map +1 -0
  50. package/packages/jam/in-core/index.js +1 -0
  51. package/packages/jam/jam-host-calls/accumulate/bless.test.js +4 -5
  52. package/packages/jam/jamnp-s/peers.d.ts.map +1 -1
  53. package/packages/jam/jamnp-s/peers.js +10 -0
  54. package/packages/jam/jamnp-s/protocol/ce-128-block-request.d.ts +1 -1
  55. package/packages/jam/jamnp-s/protocol/ce-128-block-request.d.ts.map +1 -1
  56. package/packages/jam/jamnp-s/protocol/ce-128-block-request.js +10 -8
  57. package/packages/jam/jamnp-s/protocol/ce-129-state-request.d.ts.map +1 -1
  58. package/packages/jam/jamnp-s/protocol/ce-129-state-request.js +11 -9
  59. package/packages/jam/jamnp-s/protocol/ce-131-ce-132-safrole-ticket-distribution.d.ts +3 -3
  60. package/packages/jam/jamnp-s/protocol/ce-131-ce-132-safrole-ticket-distribution.d.ts.map +1 -1
  61. package/packages/jam/jamnp-s/protocol/ce-131-ce-132-safrole-ticket-distribution.js +2 -2
  62. package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.d.ts +5 -5
  63. package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.d.ts.map +1 -1
  64. package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.js +2 -2
  65. package/packages/jam/jamnp-s/protocol/ce-134-work-package-sharing.d.ts.map +1 -1
  66. package/packages/jam/jamnp-s/protocol/ce-134-work-package-sharing.js +8 -6
  67. package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.d.ts +3 -3
  68. package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.d.ts.map +1 -1
  69. package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.js +2 -2
  70. package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.test.js +2 -2
  71. package/packages/jam/jamnp-s/protocol/stream.d.ts +13 -7
  72. package/packages/jam/jamnp-s/protocol/stream.d.ts.map +1 -1
  73. package/packages/jam/jamnp-s/protocol/stream.js +5 -4
  74. package/packages/jam/jamnp-s/protocol/test-utils.d.ts +1 -1
  75. package/packages/jam/jamnp-s/protocol/test-utils.d.ts.map +1 -1
  76. package/packages/jam/jamnp-s/protocol/test-utils.js +9 -12
  77. package/packages/jam/jamnp-s/protocol/up-0-block-announcement.d.ts +1 -1
  78. package/packages/jam/jamnp-s/protocol/up-0-block-announcement.d.ts.map +1 -1
  79. package/packages/jam/jamnp-s/protocol/up-0-block-announcement.js +1 -1
  80. package/packages/jam/jamnp-s/stream-manager.d.ts.map +1 -1
  81. package/packages/jam/jamnp-s/stream-manager.js +7 -5
  82. package/packages/jam/jamnp-s/stream-manager.test.js +8 -5
  83. package/packages/jam/jamnp-s/tasks/sync.js +1 -1
  84. package/packages/jam/node/jam-config.d.ts +4 -1
  85. package/packages/jam/node/jam-config.d.ts.map +1 -1
  86. package/packages/jam/node/jam-config.js +6 -2
  87. package/packages/jam/node/main.d.ts.map +1 -1
  88. package/packages/jam/node/main.js +5 -4
  89. package/packages/jam/rpc-validation/types.d.ts +7 -3
  90. package/packages/jam/rpc-validation/types.d.ts.map +1 -1
  91. package/packages/jam/rpc-validation/validation.d.ts +254 -36
  92. package/packages/jam/rpc-validation/validation.d.ts.map +1 -1
  93. package/packages/jam/rpc-validation/validation.js +20 -2
  94. package/packages/jam/state/in-memory-state.d.ts.map +1 -1
  95. package/packages/jam/state/in-memory-state.js +2 -3
  96. package/packages/jam/state/test.utils.d.ts.map +1 -1
  97. package/packages/jam/state/test.utils.js +2 -3
  98. package/packages/jam/transition/accumulate/accumulate-data.d.ts.map +1 -1
  99. package/packages/jam/transition/accumulate/accumulate-data.js +1 -2
  100. package/packages/jam/transition/accumulate/accumulate-queue.test.js +2 -2
  101. package/packages/jam/transition/accumulate/accumulate-utils.test.js +2 -2
  102. package/packages/jam/transition/accumulate/accumulate.d.ts.map +1 -1
  103. package/packages/jam/transition/accumulate/accumulate.js +8 -13
  104. package/packages/jam/transition/accumulate/accumulate.test.js +2 -2
  105. package/packages/jam/transition/accumulate/accumulation-result-merge-utils.d.ts.map +1 -1
  106. package/packages/jam/transition/accumulate/accumulation-result-merge-utils.js +1 -2
  107. package/packages/jam/transition/accumulate/accumulation-result-merge-utils.test.js +1 -2
  108. package/packages/jam/transition/accumulate/deferred-transfers.d.ts +1 -1
  109. package/packages/jam/transition/accumulate/deferred-transfers.d.ts.map +1 -1
  110. package/packages/jam/transition/accumulate/deferred-transfers.js +6 -7
  111. package/packages/jam/transition/disputes/disputes.test.data2.js +2 -2
  112. package/packages/jam/transition/externalities/fetch-externalities.d.ts +7 -1
  113. package/packages/jam/transition/externalities/fetch-externalities.d.ts.map +1 -1
  114. package/packages/jam/transition/externalities/fetch-externalities.js +4 -0
  115. package/packages/jam/transition/externalities/fetch-externalities.test.js +2 -2
  116. package/packages/jam/transition/hasher.test.js +2 -2
  117. package/packages/jam/transition/reports/test.utils.d.ts.map +1 -1
  118. package/packages/jam/transition/reports/test.utils.js +2 -2
  119. package/packages/workers/block-authorship/main.d.ts.map +1 -1
  120. package/packages/workers/block-authorship/main.js +23 -4
  121. package/packages/workers/block-authorship/protocol.d.ts +3 -1
  122. package/packages/workers/block-authorship/protocol.d.ts.map +1 -1
  123. package/packages/workers/block-authorship/protocol.js +6 -3
  124. package/packages/jam/transition/accumulate/pvm-executor.d.ts.map +0 -1
@@ -1,7 +1,14 @@
1
1
  import { BytesBlob } from "#@typeberry/bytes";
2
2
  import { Decoder, Encoder } from "#@typeberry/codec";
3
+ import { tryAsStreamId, } from "#@typeberry/jamnp-s";
3
4
  import { Logger } from "#@typeberry/logger";
5
+ import { assertNever } from "#@typeberry/utils";
4
6
  import { NewStream, StreamEnvelope, StreamEnvelopeType } from "./stream.js";
7
+ const IPC_PEER_ID = "ipc-peer";
8
+ /** Construct a protocol-level StreamId from an IPC-level numeric stream ID. */
9
+ function toStreamId(ipcStreamId) {
10
+ return tryAsStreamId(`${IPC_PEER_ID}:${ipcStreamId}`);
11
+ }
5
12
  const logger = Logger.new(import.meta.filename, "ext-ipc-jamnp");
6
13
  export class JamnpIpcHandler {
7
14
  sender;
@@ -37,9 +44,9 @@ export class JamnpIpcHandler {
37
44
  /** Re-use an existing stream of given kind if present. */
38
45
  withStreamOfKind(streamKind, work) {
39
46
  // find first stream id with given kind
40
- for (const [streamId, handler] of this.streams.entries()) {
47
+ for (const [ipcStreamId, handler] of this.streams.entries()) {
41
48
  if (handler.kind === streamKind) {
42
- work(handler, new EnvelopeSender(streamId, this.sender));
49
+ work(handler, new EnvelopeSender(ipcStreamId, this.sender));
43
50
  return;
44
51
  }
45
52
  }
@@ -52,19 +59,19 @@ export class JamnpIpcHandler {
52
59
  throw new Error(`Stream with unregistered handler of kind: ${kind} was requested to be opened.`);
53
60
  }
54
61
  // pick a stream id
55
- const getRandomStreamId = () => Math.floor(Math.random() * 2 ** 16);
62
+ const getRandomIpcStreamId = () => Math.floor(Math.random() * 2 ** 32);
56
63
  const streams = this.streams;
57
- const streamId = (function findStreamId() {
58
- const s = getRandomStreamId();
64
+ const ipcStreamId = (function findStreamId() {
65
+ const s = getRandomIpcStreamId();
59
66
  if (!streams.has(s)) {
60
67
  return s;
61
68
  }
62
69
  return findStreamId();
63
70
  })();
64
71
  // register the stream
65
- this.streams.set(streamId, handler);
66
- this.pendingStreams.set(streamId, true);
67
- const sender = new EnvelopeSender(streamId, this.sender);
72
+ this.streams.set(ipcStreamId, handler);
73
+ this.pendingStreams.set(ipcStreamId, true);
74
+ const sender = new EnvelopeSender(ipcStreamId, this.sender);
68
75
  sender.open(NewStream.create({ streamByte: kind }));
69
76
  work(handler, sender);
70
77
  }
@@ -72,24 +79,24 @@ export class JamnpIpcHandler {
72
79
  async onSocketMessage(msg) {
73
80
  // decode the message as `StreamEnvelope`
74
81
  const envelope = Decoder.decodeObject(StreamEnvelope.Codec, msg);
75
- const streamId = envelope.streamId;
76
- logger.log `[${streamId}] incoming message: ${envelope.type} ${envelope.data}`;
82
+ const ipcStreamId = envelope.streamId;
83
+ logger.log `[${ipcStreamId}] incoming message: ${envelope.type} ${envelope.data}`;
77
84
  // check if this is a already known stream id
78
- const streamHandler = this.streams.get(streamId);
79
- const streamSender = new EnvelopeSender(streamId, this.sender);
85
+ const streamHandler = this.streams.get(ipcStreamId);
86
+ const streamSender = new EnvelopeSender(ipcStreamId, this.sender);
80
87
  // we don't know that stream yet, so it has to be a new one
81
88
  if (streamHandler === undefined) {
82
89
  // closing or message of unknown stream - ignore.
83
90
  if (envelope.type !== StreamEnvelopeType.Open) {
84
- logger.warn `[${streamId}] (unknown) got invalid type ${envelope.type}.`;
91
+ logger.warn `[${ipcStreamId}] (unknown) got invalid type ${envelope.type}.`;
85
92
  return;
86
93
  }
87
94
  const newStream = Decoder.decodeObject(NewStream.Codec, envelope.data);
88
95
  const handler = this.streamHandlers.get(newStream.streamByte);
89
96
  if (handler !== undefined) {
90
- logger.log `[${streamId}] new stream for ${handler.kind}`;
97
+ logger.log `[${ipcStreamId}] new stream for ${handler.kind}`;
91
98
  // insert the stream
92
- this.streams.set(streamId, handler);
99
+ this.streams.set(ipcStreamId, handler);
93
100
  // Just send back the same stream byte.
94
101
  streamSender.open(newStream);
95
102
  return;
@@ -98,31 +105,47 @@ export class JamnpIpcHandler {
98
105
  streamSender.close();
99
106
  return;
100
107
  }
101
- // close the stream
102
- if (envelope.type === StreamEnvelopeType.Close) {
103
- const handler = this.streams.get(streamId);
104
- handler?.onClose(streamId, false);
105
- this.streams.delete(streamId);
106
- return;
107
- }
108
- if (envelope.type !== StreamEnvelopeType.Msg) {
108
+ if (envelope.type === StreamEnvelopeType.Open) {
109
109
  // display a warning but only if the stream was not pending for confirmation.
110
- if (!this.pendingStreams.delete(streamId)) {
111
- logger.warn `[${streamId}] got invalid type ${envelope.type}.`;
110
+ if (!this.pendingStreams.delete(ipcStreamId)) {
111
+ logger.warn `[${ipcStreamId}] got invalid type ${envelope.type}.`;
112
112
  }
113
113
  return;
114
114
  }
115
+ // reject stream messages without open ack first.
116
+ if (this.pendingStreams.has(ipcStreamId)) {
117
+ logger.warn `[${ipcStreamId}] got invalid type ${envelope.type}. Expected Open.`;
118
+ // closing the connection and removing the stream from pending.
119
+ this.pendingStreams.delete(ipcStreamId);
120
+ // the stream should not be in the collection yet, but we remove it just for safety.
121
+ this.streams.delete(ipcStreamId);
122
+ streamSender.close();
123
+ return;
124
+ }
115
125
  // this is a known stream, so just dispatch the message.
116
- streamHandler.onStreamMessage(streamSender, envelope.data);
126
+ if (envelope.type === StreamEnvelopeType.Msg) {
127
+ streamHandler.onStreamMessage(streamSender, envelope.data);
128
+ return;
129
+ }
130
+ // close the stream
131
+ if (envelope.type === StreamEnvelopeType.Close) {
132
+ streamHandler.onClose(toStreamId(ipcStreamId), false);
133
+ this.streams.delete(ipcStreamId);
134
+ // not really needed, but just for sure.
135
+ this.pendingStreams.delete(ipcStreamId);
136
+ return;
137
+ }
138
+ assertNever(envelope.type);
117
139
  }
118
140
  /** Notify about termination of the underlying socket. */
119
141
  onClose({ error }) {
120
142
  logger.log `Closing the handler. Reason: ${error !== undefined ? error.message : "close"}.`;
121
143
  // Socket closed - we should probably clear everything.
122
- for (const [streamId, handler] of this.streams.entries()) {
123
- handler.onClose(streamId, error === undefined);
144
+ for (const [ipcStreamId, handler] of this.streams.entries()) {
145
+ handler.onClose(toStreamId(ipcStreamId), error !== undefined);
124
146
  }
125
147
  this.streams.clear();
148
+ this.pendingStreams.clear();
126
149
  // finish the handler.
127
150
  this.onEnd.finished = true;
128
151
  if (error !== undefined) {
@@ -139,24 +162,26 @@ export class JamnpIpcHandler {
139
162
  }
140
163
  }
141
164
  class EnvelopeSender {
142
- streamId;
165
+ ipcStreamId;
143
166
  sender;
144
- constructor(streamId, sender) {
145
- this.streamId = streamId;
167
+ streamId;
168
+ constructor(ipcStreamId, sender) {
169
+ this.ipcStreamId = ipcStreamId;
146
170
  this.sender = sender;
171
+ this.streamId = toStreamId(ipcStreamId);
147
172
  }
148
173
  open(newStream) {
149
174
  const msg = Encoder.encodeObject(NewStream.Codec, newStream);
150
- this.sender.send(Encoder.encodeObject(StreamEnvelope.Codec, StreamEnvelope.create({ streamId: this.streamId, type: StreamEnvelopeType.Open, data: msg })));
175
+ this.sender.send(Encoder.encodeObject(StreamEnvelope.Codec, StreamEnvelope.create({ streamId: this.ipcStreamId, type: StreamEnvelopeType.Open, data: msg })));
151
176
  }
152
177
  bufferAndSend(msg) {
153
- this.sender.send(Encoder.encodeObject(StreamEnvelope.Codec, StreamEnvelope.create({ streamId: this.streamId, type: StreamEnvelopeType.Msg, data: msg })));
178
+ this.sender.send(Encoder.encodeObject(StreamEnvelope.Codec, StreamEnvelope.create({ streamId: this.ipcStreamId, type: StreamEnvelopeType.Msg, data: msg })));
154
179
  // we are buffering until we run OOM
155
180
  return true;
156
181
  }
157
182
  close() {
158
183
  this.sender.send(Encoder.encodeObject(StreamEnvelope.Codec, StreamEnvelope.create({
159
- streamId: this.streamId,
184
+ streamId: this.ipcStreamId,
160
185
  type: StreamEnvelopeType.Close,
161
186
  data: BytesBlob.blobFromNumbers([]),
162
187
  })));
@@ -1,18 +1,20 @@
1
1
  import type { BytesBlob } from "#@typeberry/bytes";
2
2
  import { type CodecRecord } from "#@typeberry/codec";
3
- import type { StreamId, StreamKind } from "#@typeberry/jamnp-s";
4
- import { type U8 } from "#@typeberry/numbers";
3
+ import type { StreamKind } from "#@typeberry/jamnp-s";
4
+ import { type U8, type U32 } from "#@typeberry/numbers";
5
+ /** IPC-level stream identifier (u32), used for multiplexing streams over a single socket. */
6
+ export type IpcStreamId = U32;
5
7
  export declare enum StreamEnvelopeType {
6
8
  Msg = 0,
7
9
  Open = 1,
8
10
  Close = 2
9
11
  }
10
12
  export declare class StreamEnvelope {
11
- readonly streamId: StreamId;
13
+ readonly streamId: IpcStreamId;
12
14
  readonly type: StreamEnvelopeType;
13
15
  readonly data: BytesBlob;
14
16
  static Codec: import("@typeberry/codec").Descriptor<StreamEnvelope, import("@typeberry/codec").ViewOf<StreamEnvelope, {
15
- streamId: import("@typeberry/codec").Descriptor<import("@typeberry/numbers").U32, import("@typeberry/bytes").Bytes<4>>;
17
+ streamId: import("@typeberry/codec").Descriptor<U32, import("@typeberry/bytes").Bytes<4>>;
16
18
  type: import("@typeberry/codec").Descriptor<StreamEnvelopeType, U8>;
17
19
  data: import("@typeberry/codec").Descriptor<BytesBlob, BytesBlob>;
18
20
  }>>;
@@ -1 +1 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../../../../packages/extensions/ipc/jamnp/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,KAAK,WAAW,EAAS,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAW,KAAK,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAEtD,oBAAY,kBAAkB;IAC5B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UAAU,EAAE,UAAU;IAR1D,MAAM,CAAC,KAAK;;QAET;IAEH,MAAM,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,EAAE,WAAW,CAAC,SAAS,CAAC;IAIpD,OAAO;CACR"}
@@ -8,6 +8,19 @@ import type { ServiceGas, ServiceId } from "./common.js";
8
8
  import type { CodeHash } from "./hash.js";
9
9
  import { MAX_NUMBER_OF_SEGMENTS, type SegmentIndex } from "./work-item-segment.js";
10
10
  type WorkItemExtrinsicHash = Opaque<OpaqueHash, "ExtrinsicHash">;
11
+ /**
12
+ * An opaque piece of data that the work item brings in.
13
+ *
14
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/1a1b001a1d00?v=0.7.2
15
+ */
16
+ export type WorkItemExtrinsic = Opaque<BytesBlob, "Extrinsic">;
17
+ /**
18
+ * Extrinsics that are needed by all [`WorkItem`]s and are specified via [`WorkItemExtrinsicSpec`].
19
+ *
20
+ * This is a flat-package of all extrinsics in a work package across all work items.
21
+ * For encoding it also requires the length of items to be known in advance.
22
+ */
23
+ export type WorkPackageExtrinsics = KnownSizeArray<Bytes<U32>, "Count of all extrinsics within work items in a work package">;
11
24
  /**
12
25
  * Definition of data segment that was exported by some work package earlier
13
26
  * and now is being imported by another work-item.
@@ -40,10 +53,6 @@ export declare class WorkItemExtrinsicSpec extends WithDebug {
40
53
  static create({ hash, len }: CodecRecord<WorkItemExtrinsicSpec>): WorkItemExtrinsicSpec;
41
54
  private constructor();
42
55
  }
43
- /**
44
- * Extrinsics that are needed by [`WorkItem`]s and are specified via [`WorkItemExtrinsicSpec`].
45
- */
46
- export type WorkItemExtrinsics = KnownSizeArray<Bytes<U32>, "Count of all extrinsics within work items in a work package">;
47
56
  /**
48
57
  * To encode/decode extrinsics that are specified via [`WorkItemExtrinsicSpec`]
49
58
  * we need to know their lenghts. Hence this is created dynamically.
@@ -1 +1 @@
1
- {"version":3,"file":"work-item.d.ts","sourceRoot":"","sources":["../../../../../packages/jam/block/work-item.ts"],"names":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ClC;;;;;OAKG;aACa,QAAQ,EAAE,QAAQ;IAClC,wBAAwB;aACR,OAAO,EAAE,SAAS;IAClC,sCAAsC;aACtB,cAAc,EAAE,UAAU;IAC1C,0CAA0C;aAC1B,kBAAkB,EAAE,UAAU;IAC9C,wFAAwF;aACxE,cAAc,EAAE,cAAc,CAAC,UAAU,EAAE,aAAa,OAAO,sBAAsB,EAAE,CAAC;IACxG,8EAA8E;aAC9D,SAAS,EAAE,qBAAqB,EAAE;IAClD,+DAA+D;aAC/C,WAAW,EAAE,GAAG;IA1DlC,MAAM,CAAC,KAAK;;;;;;;;;;;;;;;QAaT;IAEH,MAAM,CAAC,MAAM,CAAC,EACZ,OAAO,EACP,QAAQ,EACR,OAAO,EACP,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,SAAS,EACT,WAAW,GACZ,EAAE,WAAW,CAAC,QAAQ,CAAC;IAaxB,OAAO;CAyBR"}
@@ -45,11 +45,9 @@ export declare class WorkExecResult extends WithDebug {
45
45
  /** Optional octet sequence - available only if `kind === ok` */
46
46
  readonly okBlob: BytesBlob | null;
47
47
  static Codec: import("@typeberry/codec").Descriptor<WorkExecResult, WorkExecResultUnion>;
48
- constructor(
49
- /** The execution result tag. */
50
- kind: WorkExecResultKind,
51
- /** Optional octet sequence - available only if `kind === ok` */
52
- okBlob?: BytesBlob | null);
48
+ static ok(blob: BytesBlob): WorkExecResult;
49
+ static error(kind: Exclude<WorkExecResultKind, WorkExecResultKind.ok>): WorkExecResult;
50
+ private constructor();
53
51
  }
54
52
  /**
55
53
  * Five fields describing the level of activity which this workload
@@ -1 +1 @@
1
- {"version":3,"file":"work-result.d.ts","sourceRoot":"","sources":["../../../../../packages/jam/block/work-result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,KAAK,WAAW,EAAS,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAa,KAAK,UAAU,EAAE,MAAM,iBAAi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EAAE,CAAC;IAIrE,OAAO;CAQR;AAED;;;;;;GAMG;AACH,qBAAa,cAAe,SAAQ,SAAS;IAoBzC,wDAAwD;aACxC,OAAO,EAAE,UAAU;IACnC,4CAA4C;aAC5B,gBAAgB,EAAE,GAAG;IACrC,+DAA+D;aAC/C,cAAc,EAAE,GAAG;IACnC,6DAA6D;aAC7C,aAAa,EAAE,GAAG;IAClC,4CAA4C;aAC5B,gBAAgB,EAAE,GAAG;IA5BvC,MAAM,CAAC,KAAK;;;;;;QAMT;IAEH,MAAM,CAAC,MAAM,CAAC,EACZ,OAAO,EACP,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,gBAAgB,GACjB,EAAE,WAAW,CAAC,cAAc,CAAC;IAI9B,OAAO;CAcR;AAED;;;;GAIG;AACH,qBAAa,UAAU;IAenB,wFAAwF;aACxE,SAAS,EAAE,SAAS;IACpC,0EAA0E;aAC1D,QAAQ,EAAE,QAAQ;IAClC;;;;;;OAMG;aACa,WAAW,EAAE,UAAU;IACvC;;;;;OAKG;aACa,GAAG,EAAE,UAAU;IAC/B,6DAA6D;aAC7C,MAAM,EAAE,cAAc;IACtC;;;;;;OAMG;aACa,IAAI,EAAE,cAAc;IA1CtC,MAAM,CAAC,KAAK;;;;;;;;;;;;;QAOT;IAEH,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,WAAW,CAAC,UAAU,CAAC;IAI9F,OAAO;CA+BR"}
@@ -40,6 +40,12 @@ export class WorkExecResult extends WithDebug {
40
40
  }
41
41
  return { kind: x.kind };
42
42
  }, (x) => new WorkExecResult(x.kind, x.kind === WorkExecResultKind.ok ? x.okBlob : null));
43
+ static ok(blob) {
44
+ return new WorkExecResult(WorkExecResultKind.ok, blob);
45
+ }
46
+ static error(kind) {
47
+ return new WorkExecResult(kind, null);
48
+ }
43
49
  constructor(
44
50
  /** The execution result tag. */
45
51
  kind,
@@ -1 +1 @@
1
- {"version":3,"file":"work-result.d.ts","sourceRoot":"","sources":["../../../../../packages/jam/block-json/work-result.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsD,UAAU,EAAE,MAAM,iCAAiC,CAAC;AA6EjH,eAAO,MAAM,kBAAkB,0EAkB9B,CAAC"}
1
+ {"version":3,"file":"work-result.d.ts","sourceRoot":"","sources":["../../../../../packages/jam/block-json/work-result.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsD,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAkFjH,eAAO,MAAM,kBAAkB,0EAkB9B,CAAC"}
@@ -15,22 +15,22 @@ const workExecResultFromJson = json.object({
15
15
  }, (val) => {
16
16
  const { ok, out_of_gas, panic, bad_code, code_oversize, output_oversize } = val;
17
17
  if (ok !== undefined) {
18
- return new WorkExecResult(tryAsU32(WorkExecResultKind.ok), ok);
18
+ return WorkExecResult.ok(ok);
19
19
  }
20
20
  if (out_of_gas === null) {
21
- return new WorkExecResult(tryAsU32(WorkExecResultKind.outOfGas));
21
+ return WorkExecResult.error(WorkExecResultKind.outOfGas);
22
22
  }
23
23
  if (panic === null) {
24
- return new WorkExecResult(tryAsU32(WorkExecResultKind.panic));
24
+ return WorkExecResult.error(WorkExecResultKind.panic);
25
25
  }
26
26
  if (bad_code === null) {
27
- return new WorkExecResult(tryAsU32(WorkExecResultKind.badCode));
27
+ return WorkExecResult.error(WorkExecResultKind.badCode);
28
28
  }
29
29
  if (code_oversize === null) {
30
- return new WorkExecResult(tryAsU32(WorkExecResultKind.codeOversize));
30
+ return WorkExecResult.error(WorkExecResultKind.codeOversize);
31
31
  }
32
32
  if (output_oversize === null) {
33
- return new WorkExecResult(tryAsU32(WorkExecResultKind.digestTooBig));
33
+ return WorkExecResult.error(WorkExecResultKind.digestTooBig);
34
34
  }
35
35
  throw new Error("Invalid WorkExecResult");
36
36
  });
@@ -6,8 +6,7 @@ import { Bytes, BytesBlob } from "#@typeberry/bytes";
6
6
  import { SortedSet } from "#@typeberry/collections";
7
7
  import { tinyChainSpec } from "#@typeberry/config";
8
8
  import { Blake2b, HASH_SIZE } from "#@typeberry/hash";
9
- import { tryAsU32, tryAsU64 } from "#@typeberry/numbers";
10
- import { MAX_VALUE } from "#@typeberry/pvm-interpreter/ops/math-consts.js";
9
+ import { MAX_VALUE_U32, tryAsU32, tryAsU64 } from "#@typeberry/numbers";
11
10
  import { InMemoryState, LookupHistoryItem, PrivilegedServices, ServiceAccountInfo, tryAsLookupHistorySlots, tryAsPerCore, UpdateService, } from "#@typeberry/state";
12
11
  import { testState } from "#@typeberry/state/test.utils.js";
13
12
  import { StateEntries } from "#@typeberry/state-merkleization";
@@ -74,7 +73,9 @@ describe("LMDB States database", () => {
74
73
  manager: tryAsServiceId(1),
75
74
  assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(2)), spec),
76
75
  delegator: tryAsServiceId(3),
77
- registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? tryAsServiceId(4) : tryAsServiceId(MAX_VALUE),
76
+ registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
77
+ ? tryAsServiceId(4)
78
+ : tryAsServiceId(MAX_VALUE_U32),
78
79
  autoAccumulateServices: new Map(),
79
80
  }),
80
81
  updated: new Map([
@@ -0,0 +1,4 @@
1
+ export type { ReturnValue } from "#@typeberry/pvm-host-calls";
2
+ export { ReturnStatus } from "#@typeberry/pvm-host-calls";
3
+ export * from "./pvm-executor.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/jam/executor/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { ReturnStatus } from "#@typeberry/pvm-host-calls";
2
+ export * from "./pvm-executor.js";
@@ -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;IAC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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,EA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{
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
+ }