@aztec/prover-client 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0

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 (164) hide show
  1. package/dest/config.d.ts +2 -2
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +17 -3
  4. package/dest/light/index.d.ts +2 -0
  5. package/dest/light/index.d.ts.map +1 -0
  6. package/dest/light/index.js +1 -0
  7. package/dest/light/lightweight_checkpoint_builder.d.ts +38 -15
  8. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
  9. package/dest/light/lightweight_checkpoint_builder.js +162 -36
  10. package/dest/mocks/fixtures.d.ts +1 -1
  11. package/dest/mocks/fixtures.d.ts.map +1 -1
  12. package/dest/mocks/fixtures.js +4 -3
  13. package/dest/mocks/test_context.d.ts +15 -13
  14. package/dest/mocks/test_context.d.ts.map +1 -1
  15. package/dest/mocks/test_context.js +50 -36
  16. package/dest/orchestrator/block-building-helpers.d.ts +6 -6
  17. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  18. package/dest/orchestrator/block-building-helpers.js +5 -5
  19. package/dest/orchestrator/block-proving-state.d.ts +5 -2
  20. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  21. package/dest/orchestrator/block-proving-state.js +8 -1
  22. package/dest/orchestrator/checkpoint-proving-state.d.ts +20 -23
  23. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
  24. package/dest/orchestrator/checkpoint-proving-state.js +23 -87
  25. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +161 -0
  26. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -0
  27. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.js +1066 -0
  28. package/dest/orchestrator/chonk-cache.d.ts +39 -0
  29. package/dest/orchestrator/chonk-cache.d.ts.map +1 -0
  30. package/dest/orchestrator/chonk-cache.js +80 -0
  31. package/dest/orchestrator/index.d.ts +4 -2
  32. package/dest/orchestrator/index.d.ts.map +1 -1
  33. package/dest/orchestrator/index.js +3 -1
  34. package/dest/orchestrator/orchestrator_metrics.d.ts +1 -3
  35. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
  36. package/dest/orchestrator/orchestrator_metrics.js +2 -15
  37. package/dest/orchestrator/proving-scheduler.d.ts +81 -0
  38. package/dest/orchestrator/proving-scheduler.d.ts.map +1 -0
  39. package/dest/orchestrator/proving-scheduler.js +120 -0
  40. package/dest/orchestrator/top-tree-orchestrator.d.ts +88 -0
  41. package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -0
  42. package/dest/orchestrator/top-tree-orchestrator.js +232 -0
  43. package/dest/orchestrator/top-tree-proving-state.d.ts +61 -0
  44. package/dest/orchestrator/top-tree-proving-state.d.ts.map +1 -0
  45. package/dest/orchestrator/top-tree-proving-state.js +185 -0
  46. package/dest/orchestrator/tx-proving-state.d.ts +7 -6
  47. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  48. package/dest/orchestrator/tx-proving-state.js +8 -8
  49. package/dest/prover-client/factory.d.ts +3 -3
  50. package/dest/prover-client/factory.d.ts.map +1 -1
  51. package/dest/prover-client/prover-client.d.ts +65 -8
  52. package/dest/prover-client/prover-client.d.ts.map +1 -1
  53. package/dest/prover-client/prover-client.js +66 -14
  54. package/dest/proving_broker/broker_prover_facade.d.ts +8 -6
  55. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  56. package/dest/proving_broker/broker_prover_facade.js +18 -31
  57. package/dest/proving_broker/config.d.ts +13 -65
  58. package/dest/proving_broker/config.d.ts.map +1 -1
  59. package/dest/proving_broker/config.js +23 -6
  60. package/dest/proving_broker/fixtures.js +1 -1
  61. package/dest/proving_broker/index.d.ts +2 -1
  62. package/dest/proving_broker/index.d.ts.map +1 -1
  63. package/dest/proving_broker/index.js +1 -0
  64. package/dest/proving_broker/proof_store/factory.d.ts +2 -5
  65. package/dest/proving_broker/proof_store/factory.d.ts.map +1 -1
  66. package/dest/proving_broker/proof_store/factory.js +7 -30
  67. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts +18 -0
  68. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts.map +1 -0
  69. package/dest/proving_broker/proof_store/file_store_proof_store.js +60 -0
  70. package/dest/proving_broker/proof_store/index.d.ts +2 -2
  71. package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
  72. package/dest/proving_broker/proof_store/index.js +1 -1
  73. package/dest/proving_broker/proving_agent.d.ts +5 -9
  74. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  75. package/dest/proving_broker/proving_agent.js +4 -19
  76. package/dest/proving_broker/proving_broker.d.ts +8 -5
  77. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  78. package/dest/proving_broker/proving_broker.js +72 -21
  79. package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
  80. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  81. package/dest/proving_broker/proving_broker_database/persisted.js +391 -3
  82. package/dest/proving_broker/proving_broker_instrumentation.d.ts +3 -1
  83. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  84. package/dest/proving_broker/proving_broker_instrumentation.js +22 -35
  85. package/dest/proving_broker/proving_job_controller.d.ts +4 -3
  86. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  87. package/dest/proving_broker/proving_job_controller.js +8 -6
  88. package/dest/proving_broker/rpc.d.ts +6 -2
  89. package/dest/proving_broker/rpc.d.ts.map +1 -1
  90. package/dest/proving_broker/rpc.js +87 -23
  91. package/dest/test/epoch_settlement.d.ts +36 -0
  92. package/dest/test/epoch_settlement.d.ts.map +1 -0
  93. package/dest/test/epoch_settlement.js +52 -0
  94. package/dest/test/index.d.ts +2 -0
  95. package/dest/test/index.d.ts.map +1 -0
  96. package/dest/test/index.js +1 -0
  97. package/dest/test/mock_proof_store.d.ts +3 -3
  98. package/dest/test/mock_proof_store.d.ts.map +1 -1
  99. package/dest/test/mock_prover.d.ts +5 -5
  100. package/dest/test/mock_prover.d.ts.map +1 -1
  101. package/dest/test/mock_prover.js +4 -4
  102. package/package.json +23 -22
  103. package/src/config.ts +19 -3
  104. package/src/light/index.ts +1 -0
  105. package/src/light/lightweight_checkpoint_builder.ts +229 -50
  106. package/src/mocks/fixtures.ts +4 -3
  107. package/src/mocks/test_context.ts +44 -48
  108. package/src/orchestrator/block-building-helpers.ts +5 -5
  109. package/src/orchestrator/block-proving-state.ts +10 -1
  110. package/src/orchestrator/checkpoint-proving-state.ts +22 -116
  111. package/src/orchestrator/checkpoint-sub-tree-orchestrator.ts +1044 -0
  112. package/src/orchestrator/chonk-cache.ts +99 -0
  113. package/src/orchestrator/index.ts +8 -1
  114. package/src/orchestrator/orchestrator_metrics.ts +2 -25
  115. package/src/orchestrator/proving-scheduler.ts +160 -0
  116. package/src/orchestrator/top-tree-orchestrator.ts +384 -0
  117. package/src/orchestrator/top-tree-proving-state.ts +219 -0
  118. package/src/orchestrator/tx-proving-state.ts +11 -15
  119. package/src/prover-client/factory.ts +6 -2
  120. package/src/prover-client/prover-client.ts +148 -29
  121. package/src/proving_broker/broker_prover_facade.ts +27 -37
  122. package/src/proving_broker/config.ts +26 -3
  123. package/src/proving_broker/fixtures.ts +1 -1
  124. package/src/proving_broker/index.ts +1 -0
  125. package/src/proving_broker/proof_store/factory.ts +10 -32
  126. package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
  127. package/src/proving_broker/proof_store/index.ts +1 -1
  128. package/src/proving_broker/proving_agent.ts +6 -19
  129. package/src/proving_broker/proving_broker.ts +68 -16
  130. package/src/proving_broker/proving_broker_database/persisted.ts +17 -3
  131. package/src/proving_broker/proving_broker_instrumentation.ts +23 -35
  132. package/src/proving_broker/proving_job_controller.ts +11 -6
  133. package/src/proving_broker/rpc.ts +46 -20
  134. package/src/test/epoch_settlement.ts +82 -0
  135. package/src/test/index.ts +1 -0
  136. package/src/test/mock_prover.ts +3 -15
  137. package/dest/block-factory/index.d.ts +0 -2
  138. package/dest/block-factory/index.d.ts.map +0 -1
  139. package/dest/block-factory/index.js +0 -1
  140. package/dest/block-factory/light.d.ts +0 -38
  141. package/dest/block-factory/light.d.ts.map +0 -1
  142. package/dest/block-factory/light.js +0 -108
  143. package/dest/orchestrator/epoch-proving-state.d.ts +0 -74
  144. package/dest/orchestrator/epoch-proving-state.d.ts.map +0 -1
  145. package/dest/orchestrator/epoch-proving-state.js +0 -233
  146. package/dest/orchestrator/orchestrator.d.ts +0 -113
  147. package/dest/orchestrator/orchestrator.d.ts.map +0 -1
  148. package/dest/orchestrator/orchestrator.js +0 -842
  149. package/dest/prover-client/server-epoch-prover.d.ts +0 -32
  150. package/dest/prover-client/server-epoch-prover.d.ts.map +0 -1
  151. package/dest/prover-client/server-epoch-prover.js +0 -40
  152. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +0 -14
  153. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +0 -1
  154. package/dest/proving_broker/proof_store/gcs_proof_store.js +0 -52
  155. package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
  156. package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
  157. package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
  158. package/src/block-factory/index.ts +0 -1
  159. package/src/block-factory/light.ts +0 -137
  160. package/src/orchestrator/epoch-proving-state.ts +0 -330
  161. package/src/orchestrator/orchestrator.ts +0 -1265
  162. package/src/prover-client/server-epoch-prover.ts +0 -69
  163. package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -76
  164. package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
@@ -0,0 +1,99 @@
1
+ import type { NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH } from '@aztec/constants';
2
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
3
+ import type { L2Block } from '@aztec/stdlib/block';
4
+ import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
5
+ import type { PublicChonkVerifierPublicInputs } from '@aztec/stdlib/rollup';
6
+
7
+ /** Result of a chonk-verifier proof, cached by tx hash. */
8
+ export type ChonkVerifierProofResult = PublicInputsAndRecursiveProof<
9
+ PublicChonkVerifierPublicInputs,
10
+ typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
11
+ >;
12
+
13
+ /**
14
+ * Shared cache of `getPublicChonkVerifierProof` results, keyed by tx hash.
15
+ *
16
+ * Owned by the prover-node and shared across every epoch / session: a tx remined into
17
+ * a different block (e.g. after a brief L1 reorg) reuses the already-computed chonk
18
+ * proof rather than redoing it. Entries are released via `releaseForBlocks` once the
19
+ * containing block is no longer interesting to the caller (e.g. its epoch's proof
20
+ * submission window has expired).
21
+ */
22
+ export class ChonkCache {
23
+ private readonly cache = new Map<string, Promise<ChonkVerifierProofResult>>();
24
+ private readonly pending = new Map<string, AbortController>();
25
+ private readonly log: Logger;
26
+ private stopped = false;
27
+
28
+ constructor(bindings?: LoggerBindings) {
29
+ this.log = createLogger('prover-client:chonk-cache', bindings);
30
+ }
31
+
32
+ /** Returns the cached promise for `txHash`, or `undefined` if none is registered. */
33
+ public get(txHash: string): Promise<ChonkVerifierProofResult> | undefined {
34
+ return this.cache.get(txHash);
35
+ }
36
+
37
+ /**
38
+ * Atomic get-or-compute: returns the cached promise for `txHash`, or runs `factory`
39
+ * (passing an AbortSignal the cache controls) and caches its result. Concurrent
40
+ * callers for the same `txHash` share the same promise.
41
+ *
42
+ * Rejected promises are evicted so a future caller can retry. The factory's
43
+ * AbortSignal fires when the cache is stopped.
44
+ */
45
+ public getOrCompute(
46
+ txHash: string,
47
+ factory: (signal: AbortSignal) => Promise<ChonkVerifierProofResult>,
48
+ ): Promise<ChonkVerifierProofResult> {
49
+ if (this.stopped) {
50
+ return Promise.reject(new Error('ChonkCache is stopped'));
51
+ }
52
+ const existing = this.cache.get(txHash);
53
+ if (existing) {
54
+ return existing;
55
+ }
56
+ const controller = new AbortController();
57
+ this.pending.set(txHash, controller);
58
+ this.log.debug(`Enqueueing chonk-verifier circuit`, { txHash });
59
+ const promise = factory(controller.signal).finally(() => this.pending.delete(txHash));
60
+ // Silently observe the rejection branch and evict so a retry is possible.
61
+ promise.catch(err => {
62
+ this.cache.delete(txHash);
63
+ this.log.debug(`Chonk-verifier proof failed; evicted from cache`, { txHash, error: `${err}` });
64
+ });
65
+ this.cache.set(txHash, promise);
66
+ return promise;
67
+ }
68
+
69
+ /** Drops cache entries for every tx in the supplied blocks. */
70
+ public releaseForBlocks(blocks: L2Block[]): void {
71
+ let released = 0;
72
+ for (const block of blocks) {
73
+ for (const txEffect of block.body.txEffects) {
74
+ if (this.cache.delete(txEffect.txHash.toString())) {
75
+ released++;
76
+ }
77
+ }
78
+ }
79
+ if (released > 0) {
80
+ this.log.debug(`Released ${released} chonk-verifier cache entries`, {
81
+ blockCount: blocks.length,
82
+ releasedCount: released,
83
+ });
84
+ }
85
+ }
86
+
87
+ /** Aborts every in-flight chonk-verifier job and clears the cache. */
88
+ public stop(): void {
89
+ if (this.stopped) {
90
+ return;
91
+ }
92
+ this.stopped = true;
93
+ for (const controller of this.pending.values()) {
94
+ controller.abort();
95
+ }
96
+ this.pending.clear();
97
+ this.cache.clear();
98
+ }
99
+ }
@@ -1 +1,8 @@
1
- export { ProvingOrchestrator } from './orchestrator.js';
1
+ export { CheckpointSubTreeOrchestrator, type SubTreeResult } from './checkpoint-sub-tree-orchestrator.js';
2
+ export { ChonkCache, type ChonkVerifierProofResult } from './chonk-cache.js';
3
+ export {
4
+ TopTreeOrchestrator,
5
+ TopTreeCancelledError,
6
+ type CheckpointTopTreeData,
7
+ type TopTreeResult,
8
+ } from './top-tree-orchestrator.js';
@@ -1,41 +1,18 @@
1
- import {
2
- type Histogram,
3
- Metrics,
4
- type TelemetryClient,
5
- type Tracer,
6
- type UpDownCounter,
7
- ValueType,
8
- } from '@aztec/telemetry-client';
1
+ import { type Histogram, Metrics, type TelemetryClient, type Tracer } from '@aztec/telemetry-client';
9
2
 
10
3
  export class ProvingOrchestratorMetrics {
11
4
  public readonly tracer: Tracer;
12
5
 
13
6
  private baseRollupInputsDuration: Histogram;
14
- private avmFallbackCount: UpDownCounter;
15
7
 
16
8
  constructor(client: TelemetryClient, name = 'ProvingOrchestrator') {
17
9
  this.tracer = client.getTracer(name);
18
10
  const meter = client.getMeter(name);
19
11
 
20
- this.baseRollupInputsDuration = meter.createHistogram(Metrics.PROVING_ORCHESTRATOR_BASE_ROLLUP_INPUTS_DURATION, {
21
- unit: 'ms',
22
- description: 'Duration to build base rollup inputs',
23
- valueType: ValueType.INT,
24
- });
25
-
26
- this.avmFallbackCount = meter.createUpDownCounter(Metrics.PROVING_ORCHESTRATOR_AVM_FALLBACK_COUNT, {
27
- description: 'How many times the AVM fallback was used',
28
- valueType: ValueType.INT,
29
- });
30
-
31
- this.avmFallbackCount.add(0);
12
+ this.baseRollupInputsDuration = meter.createHistogram(Metrics.PROVING_ORCHESTRATOR_BASE_ROLLUP_INPUTS_DURATION);
32
13
  }
33
14
 
34
15
  recordBaseRollupInputs(durationMs: number) {
35
16
  this.baseRollupInputsDuration.record(Math.ceil(durationMs));
36
17
  }
37
-
38
- incAvmFallback() {
39
- this.avmFallbackCount.add(1);
40
- }
41
18
  }
@@ -0,0 +1,160 @@
1
+ import { AbortError } from '@aztec/foundation/error';
2
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
3
+ import { SerialQueue } from '@aztec/foundation/queue';
4
+ import { sleep } from '@aztec/foundation/sleep';
5
+
6
+ /**
7
+ * Minimal surface a deferred-proving state must expose. Both `CheckpointProvingState` /
8
+ * `BlockProvingState` (used by `CheckpointSubTreeOrchestrator`) and `TopTreeProvingState`
9
+ * (used by `TopTreeOrchestrator`) satisfy it.
10
+ */
11
+ export interface ProvingStateLike {
12
+ /** Returns false once the state has been cancelled or otherwise invalidated. */
13
+ verifyState(): boolean;
14
+ /** Surfaces a proving error to the state's owner. */
15
+ reject(reason: string): void;
16
+ }
17
+
18
+ /**
19
+ * Common scheduling infrastructure shared by every orchestrator that drives broker
20
+ * proving jobs:
21
+ *
22
+ * - A shared `SerialQueue` (`deferredJobQueue`) that serialises the *act of handing a
23
+ * job to the broker*, one initiation per event-loop tick. Each queue task kicks off
24
+ * `safeJob` (which submits to the broker) without awaiting it, then yields with
25
+ * `sleep(0)`; the next task therefore runs on the following macrotask. This does NOT
26
+ * cap how many broker jobs are concurrently in flight — the broker's own queue absorbs
27
+ * that. What it bounds is the burst rate: a sub-tree that synchronously discovers
28
+ * thousands of ready jobs can't flood the broker (and monopolise the event loop) in a
29
+ * single tick. The queue is owned by the `ProverClient` and shared across every
30
+ * orchestrator (every sub-tree and top-tree across every concurrent epoch session), so
31
+ * this pacing is applied once globally rather than once-per-orchestrator.
32
+ * - A list of `AbortController`s (`pendingProvingJobs`) so a `cancel()` can abort
33
+ * in-flight broker jobs when needed.
34
+ * - A `deferredProving<T>(state, request, callback, isCancelled?)` method that wraps
35
+ * a broker request in the standard "submit, drop result if state invalidated, push
36
+ * errors to state.reject" envelope.
37
+ *
38
+ * Subclasses own their own concrete proving state and define `cancelInternal()` for
39
+ * the rest of the cleanup work (closing world-state forks, marking sub-trees
40
+ * cancelled, etc.). Because the queue is shared, neither `cancel()` nor `stop()` touch
41
+ * it — they only abort this orchestrator's in-flight broker jobs. Queued-but-unrun jobs
42
+ * for a cancelled orchestrator no-op via the guards in `deferredProving`.
43
+ */
44
+ export abstract class ProvingScheduler {
45
+ protected pendingProvingJobs: AbortController[] = [];
46
+ protected logger: Logger;
47
+
48
+ constructor(
49
+ private readonly deferredJobQueue: SerialQueue,
50
+ loggerName = 'prover-client:proving-scheduler',
51
+ bindings?: LoggerBindings,
52
+ ) {
53
+ this.logger = createLogger(loggerName, bindings);
54
+ }
55
+
56
+ /** Number of broker jobs currently in flight. */
57
+ public getNumPendingProvingJobs(): number {
58
+ return this.pendingProvingJobs.length;
59
+ }
60
+
61
+ /**
62
+ * Optionally aborts every in-flight broker job. Aborting is the right choice on
63
+ * reorg-driven cancel (where the in-flight inputs are no longer valid) and the
64
+ * wrong choice on shutdown (where leaving jobs in the broker queue lets a restart
65
+ * pick them up). The shared queue is not touched — queued-but-unrun jobs belonging
66
+ * to this orchestrator no-op once their controller is aborted (or once their state
67
+ * is marked invalid by the subclass).
68
+ */
69
+ protected resetSchedulerState(abortJobs: boolean): void {
70
+ if (abortJobs) {
71
+ for (const controller of this.pendingProvingJobs) {
72
+ controller.abort();
73
+ }
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Subclass-defined cancellation. Implementations call `resetSchedulerState(...)`
79
+ * and then do their own cleanup (close world-state forks, propagate cancel into
80
+ * the proving state, etc.).
81
+ */
82
+ protected abstract cancelInternal(): void;
83
+
84
+ /**
85
+ * Standard stop: cancel this orchestrator's work. The shared queue is owned by the
86
+ * `ProverClient` and outlives every orchestrator, so it is not drained here.
87
+ */
88
+ public stop(): Promise<void> {
89
+ this.cancelInternal();
90
+ return Promise.resolve();
91
+ }
92
+
93
+ /**
94
+ * Submits a broker request. The returned-via-callback result is dropped if the
95
+ * state has become invalid (re-org, cancellation) by the time it lands. Errors
96
+ * are routed to `state.reject` unless they are abort-driven or the state is
97
+ * already invalid (in which case they're a stale echo of the cancel).
98
+ *
99
+ * @param state - Object exposing `verifyState()` and `reject()`.
100
+ * @param request - The broker call. Receives the controller's signal.
101
+ * @param callback - Runs on success, after `verifyState()` is checked.
102
+ * @param isCancelled - Optional extra cancellation predicate (e.g. a `cancelled`
103
+ * flag the subclass maintains independently of the state). Defaults to never.
104
+ */
105
+ protected deferredProving<S extends ProvingStateLike, T>(
106
+ state: S,
107
+ request: (signal: AbortSignal) => Promise<T>,
108
+ callback: (result: T) => void | Promise<void>,
109
+ isCancelled: () => boolean = () => false,
110
+ ): void {
111
+ if (!state.verifyState()) {
112
+ this.logger.debug(`Not enqueuing job, state no longer valid`);
113
+ return;
114
+ }
115
+
116
+ const controller = new AbortController();
117
+ this.pendingProvingJobs.push(controller);
118
+
119
+ // We use a 'safeJob'. We don't want promise rejections in the proving pool — we
120
+ // want to capture the error here and reject the proving state while keeping the
121
+ // event loop free of rejections.
122
+ const safeJob = async () => {
123
+ try {
124
+ if (controller.signal.aborted) {
125
+ return;
126
+ }
127
+ const result = await request(controller.signal);
128
+ if (controller.signal.aborted || !state.verifyState() || isCancelled()) {
129
+ this.logger.debug(`State no longer valid, discarding result`);
130
+ return;
131
+ }
132
+ await callback(result);
133
+ } catch (err) {
134
+ if (err instanceof AbortError || isCancelled()) {
135
+ return;
136
+ }
137
+ if (!state.verifyState()) {
138
+ this.logger.debug(`State no longer valid, discarding error from proving job`, err);
139
+ return;
140
+ }
141
+ this.logger.error(`Error thrown when proving job`, err);
142
+ state.reject(`${err}`);
143
+ } finally {
144
+ const idx = this.pendingProvingJobs.indexOf(controller);
145
+ if (idx > -1) {
146
+ this.pendingProvingJobs.splice(idx, 1);
147
+ }
148
+ }
149
+ };
150
+
151
+ void this.deferredJobQueue.put(async () => {
152
+ // Kick off the broker submission without awaiting it — awaiting here would serialise all
153
+ // proving (one job at a time) and kill parallelism. The `sleep(0)` yields the event loop
154
+ // so the next queued job initiates on the following macrotask, pacing bursts rather than
155
+ // bounding in-flight broker concurrency (the broker's own queue handles that).
156
+ void safeJob();
157
+ await sleep(0);
158
+ });
159
+ }
160
+ }