@aztec/prover-client 0.0.1-commit.e3c1de76 → 0.0.1-commit.e57c76e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -2
- package/dest/light/lightweight_checkpoint_builder.d.ts +10 -5
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
- package/dest/light/lightweight_checkpoint_builder.js +53 -22
- package/dest/mocks/test_context.d.ts +3 -1
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +18 -9
- package/dest/orchestrator/block-building-helpers.d.ts +4 -4
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +2 -2
- package/dest/orchestrator/block-proving-state.d.ts +4 -1
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +7 -0
- package/dest/orchestrator/checkpoint-proving-state.d.ts +10 -3
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +13 -4
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +107 -0
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.js +151 -0
- package/dest/orchestrator/epoch-proving-context.d.ts +51 -0
- package/dest/orchestrator/epoch-proving-context.d.ts.map +1 -0
- package/dest/orchestrator/epoch-proving-context.js +81 -0
- package/dest/orchestrator/epoch-proving-state.d.ts +3 -3
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +5 -3
- package/dest/orchestrator/index.d.ts +4 -1
- package/dest/orchestrator/index.d.ts.map +1 -1
- package/dest/orchestrator/index.js +3 -0
- package/dest/orchestrator/orchestrator.d.ts +16 -26
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +76 -206
- package/dest/orchestrator/proving-scheduler.d.ts +72 -0
- package/dest/orchestrator/proving-scheduler.d.ts.map +1 -0
- package/dest/orchestrator/proving-scheduler.js +117 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts +83 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-orchestrator.js +182 -0
- package/dest/orchestrator/top-tree-proving-scheduler.d.ts +62 -0
- package/dest/orchestrator/top-tree-proving-scheduler.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-proving-scheduler.js +73 -0
- package/dest/orchestrator/top-tree-proving-state.d.ts +61 -0
- package/dest/orchestrator/top-tree-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-proving-state.js +185 -0
- package/dest/prover-client/prover-client.d.ts +64 -5
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +58 -8
- package/dest/proving_broker/broker_prover_facade.d.ts +1 -1
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +13 -19
- package/dest/proving_broker/config.d.ts +11 -67
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +16 -5
- package/dest/proving_broker/index.d.ts +2 -1
- package/dest/proving_broker/index.d.ts.map +1 -1
- package/dest/proving_broker/index.js +1 -0
- package/dest/proving_broker/proof_store/factory.d.ts +2 -5
- package/dest/proving_broker/proof_store/factory.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/factory.js +7 -30
- package/dest/proving_broker/proof_store/file_store_proof_store.d.ts +18 -0
- package/dest/proving_broker/proof_store/file_store_proof_store.d.ts.map +1 -0
- package/dest/proving_broker/proof_store/file_store_proof_store.js +60 -0
- package/dest/proving_broker/proof_store/index.d.ts +2 -2
- package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/index.js +1 -1
- package/dest/proving_broker/proving_broker.d.ts +8 -5
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +68 -11
- package/dest/proving_broker/proving_broker_database/persisted.js +2 -2
- package/dest/proving_broker/proving_broker_instrumentation.d.ts +3 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.js +7 -0
- package/dest/proving_broker/rpc.d.ts +6 -2
- package/dest/proving_broker/rpc.d.ts.map +1 -1
- package/dest/proving_broker/rpc.js +87 -23
- package/dest/test/mock_prover.d.ts +4 -4
- package/package.json +18 -19
- package/src/config.ts +18 -2
- package/src/light/lightweight_checkpoint_builder.ts +56 -25
- package/src/mocks/test_context.ts +13 -10
- package/src/orchestrator/block-building-helpers.ts +2 -2
- package/src/orchestrator/block-proving-state.ts +9 -0
- package/src/orchestrator/checkpoint-proving-state.ts +18 -5
- package/src/orchestrator/checkpoint-sub-tree-orchestrator.ts +271 -0
- package/src/orchestrator/epoch-proving-context.ts +101 -0
- package/src/orchestrator/epoch-proving-state.ts +6 -4
- package/src/orchestrator/index.ts +8 -0
- package/src/orchestrator/orchestrator.ts +98 -268
- package/src/orchestrator/proving-scheduler.ts +156 -0
- package/src/orchestrator/top-tree-orchestrator.ts +314 -0
- package/src/orchestrator/top-tree-proving-scheduler.ts +154 -0
- package/src/orchestrator/top-tree-proving-state.ts +220 -0
- package/src/prover-client/prover-client.ts +132 -9
- package/src/proving_broker/broker_prover_facade.ts +17 -20
- package/src/proving_broker/config.ts +16 -2
- package/src/proving_broker/index.ts +1 -0
- package/src/proving_broker/proof_store/factory.ts +10 -32
- package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
- package/src/proving_broker/proof_store/index.ts +1 -1
- package/src/proving_broker/proving_broker.ts +64 -8
- package/src/proving_broker/proving_broker_database/persisted.ts +2 -2
- package/src/proving_broker/proving_broker_instrumentation.ts +9 -0
- package/src/proving_broker/rpc.ts +46 -20
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +0 -14
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +0 -1
- package/dest/proving_broker/proof_store/gcs_proof_store.js +0 -52
- package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -76
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type Logger, type LoggerBindings } from '@aztec/foundation/log';
|
|
2
|
+
/**
|
|
3
|
+
* Minimal surface a deferred-proving state must expose. Both `EpochProvingState` /
|
|
4
|
+
* `CheckpointProvingState` / `BlockProvingState` (used by `ProvingOrchestrator`) and
|
|
5
|
+
* `TopTreeProvingState` (used by `TopTreeOrchestrator`) satisfy it.
|
|
6
|
+
*/
|
|
7
|
+
export interface ProvingStateLike {
|
|
8
|
+
/** Returns false once the state has been cancelled or otherwise invalidated. */
|
|
9
|
+
verifyState(): boolean;
|
|
10
|
+
/** Surfaces a proving error to the state's owner. */
|
|
11
|
+
reject(reason: string): void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Common scheduling infrastructure shared by every orchestrator that drives broker
|
|
15
|
+
* proving jobs:
|
|
16
|
+
*
|
|
17
|
+
* - One `SerialQueue` (`deferredJobQueue`) acting as the enqueue-throttle.
|
|
18
|
+
* - A list of `AbortController`s (`pendingProvingJobs`) so a `cancel()` can abort
|
|
19
|
+
* in-flight broker jobs when needed.
|
|
20
|
+
* - A `deferredProving<T>(state, request, callback, isCancelled?)` method that wraps
|
|
21
|
+
* a broker request in the standard "submit, drop result if state invalidated, push
|
|
22
|
+
* errors to state.reject" envelope.
|
|
23
|
+
*
|
|
24
|
+
* Subclasses own their own concrete proving state and define `cancelInternal()` for
|
|
25
|
+
* the rest of the cleanup work (closing world-state forks, marking sub-trees
|
|
26
|
+
* cancelled, etc.). `stop()` lives on the base class and follows the standard pattern
|
|
27
|
+
* of grabbing the old queue, calling `cancelInternal()` (which recreates the queue),
|
|
28
|
+
* and awaiting the old queue's drain.
|
|
29
|
+
*/
|
|
30
|
+
export declare abstract class ProvingScheduler {
|
|
31
|
+
private readonly enqueueConcurrency;
|
|
32
|
+
protected pendingProvingJobs: AbortController[];
|
|
33
|
+
protected logger: Logger;
|
|
34
|
+
private deferredJobQueue;
|
|
35
|
+
constructor(enqueueConcurrency: number, loggerName?: string, bindings?: LoggerBindings);
|
|
36
|
+
/** Number of broker jobs currently in flight. */
|
|
37
|
+
getNumPendingProvingJobs(): number;
|
|
38
|
+
/**
|
|
39
|
+
* Drains the deferred-job queue, recreates it (so the subclass can be reused), and
|
|
40
|
+
* optionally aborts every in-flight broker job. Aborting is the right choice on
|
|
41
|
+
* reorg-driven cancel (where the in-flight inputs are no longer valid) and the
|
|
42
|
+
* wrong choice on shutdown (where leaving jobs in the broker queue lets a restart
|
|
43
|
+
* pick them up).
|
|
44
|
+
*/
|
|
45
|
+
protected resetSchedulerState(abortJobs: boolean): void;
|
|
46
|
+
/**
|
|
47
|
+
* Subclass-defined cancellation. Implementations call `resetSchedulerState(...)`
|
|
48
|
+
* and then do their own cleanup (close world-state forks, propagate cancel into
|
|
49
|
+
* the proving state, etc.).
|
|
50
|
+
*/
|
|
51
|
+
protected abstract cancelInternal(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Standard stop: grab the old queue, cancel (which recreates the queue), then
|
|
54
|
+
* await the old queue's drain so any final job tear-down has unwound before we
|
|
55
|
+
* return.
|
|
56
|
+
*/
|
|
57
|
+
stop(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Submits a broker request. The returned-via-callback result is dropped if the
|
|
60
|
+
* state has become invalid (re-org, cancellation) by the time it lands. Errors
|
|
61
|
+
* are routed to `state.reject` unless they are abort-driven or the state is
|
|
62
|
+
* already invalid (in which case they're a stale echo of the cancel).
|
|
63
|
+
*
|
|
64
|
+
* @param state - Object exposing `verifyState()` and `reject()`.
|
|
65
|
+
* @param request - The broker call. Receives the controller's signal.
|
|
66
|
+
* @param callback - Runs on success, after `verifyState()` is checked.
|
|
67
|
+
* @param isCancelled - Optional extra cancellation predicate (e.g. a `cancelled`
|
|
68
|
+
* flag the subclass maintains independently of the state). Defaults to never.
|
|
69
|
+
*/
|
|
70
|
+
protected deferredProving<S extends ProvingStateLike, T>(state: S, request: (signal: AbortSignal) => Promise<T>, callback: (result: T) => void | Promise<void>, isCancelled?: () => boolean): void;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvdmluZy1zY2hlZHVsZXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9vcmNoZXN0cmF0b3IvcHJvdmluZy1zY2hlZHVsZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEtBQUssTUFBTSxFQUFFLEtBQUssY0FBYyxFQUFnQixNQUFNLHVCQUF1QixDQUFDO0FBSXZGOzs7O0dBSUc7QUFDSCxNQUFNLFdBQVcsZ0JBQWdCO0lBQy9CLGdGQUFnRjtJQUNoRixXQUFXLElBQUksT0FBTyxDQUFDO0lBQ3ZCLHFEQUFxRDtJQUNyRCxNQUFNLENBQUMsTUFBTSxFQUFFLE1BQU0sR0FBRyxJQUFJLENBQUM7Q0FDOUI7QUFFRDs7Ozs7Ozs7Ozs7Ozs7OztHQWdCRztBQUNILDhCQUFzQixnQkFBZ0I7SUFNbEMsT0FBTyxDQUFDLFFBQVEsQ0FBQyxrQkFBa0I7SUFMckMsU0FBUyxDQUFDLGtCQUFrQixFQUFFLGVBQWUsRUFBRSxDQUFNO0lBQ3JELFNBQVMsQ0FBQyxNQUFNLEVBQUUsTUFBTSxDQUFDO0lBQ3pCLE9BQU8sQ0FBQyxnQkFBZ0IsQ0FBYztJQUV0QyxZQUNtQixrQkFBa0IsRUFBRSxNQUFNLEVBQzNDLFVBQVUsU0FBb0MsRUFDOUMsUUFBUSxDQUFDLEVBQUUsY0FBYyxFQUsxQjtJQUVELGlEQUFpRDtJQUMxQyx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AC,kBAAkB,EAAE,eAAe,EAAE,CAAM;IACrD,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,gBAAgB,CAAc;IAEtC,YACmB,kBAAkB,EAAE,MAAM,EAC3C,UAAU,SAAoC,EAC9C,QAAQ,CAAC,EAAE,cAAc,EAK1B;IAED,iDAAiD;IAC1C,wBAAwB,IAAI,MAAM,CAExC;IAED;;;;;;OAMG;IACH,SAAS,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAStD;IAED;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,cAAc,IAAI,IAAI,CAAC;IAE1C;;;;OAIG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAIjC;IAED;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,eAAe,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,EACrD,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EAC5C,QAAQ,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAC7C,WAAW,GAAE,MAAM,OAAqB,GACvC,IAAI,CA+CN;CACF"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { AbortError } from '@aztec/foundation/error';
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { SerialQueue } from '@aztec/foundation/queue';
|
|
4
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
5
|
+
/**
|
|
6
|
+
* Common scheduling infrastructure shared by every orchestrator that drives broker
|
|
7
|
+
* proving jobs:
|
|
8
|
+
*
|
|
9
|
+
* - One `SerialQueue` (`deferredJobQueue`) acting as the enqueue-throttle.
|
|
10
|
+
* - A list of `AbortController`s (`pendingProvingJobs`) so a `cancel()` can abort
|
|
11
|
+
* in-flight broker jobs when needed.
|
|
12
|
+
* - A `deferredProving<T>(state, request, callback, isCancelled?)` method that wraps
|
|
13
|
+
* a broker request in the standard "submit, drop result if state invalidated, push
|
|
14
|
+
* errors to state.reject" envelope.
|
|
15
|
+
*
|
|
16
|
+
* Subclasses own their own concrete proving state and define `cancelInternal()` for
|
|
17
|
+
* the rest of the cleanup work (closing world-state forks, marking sub-trees
|
|
18
|
+
* cancelled, etc.). `stop()` lives on the base class and follows the standard pattern
|
|
19
|
+
* of grabbing the old queue, calling `cancelInternal()` (which recreates the queue),
|
|
20
|
+
* and awaiting the old queue's drain.
|
|
21
|
+
*/ export class ProvingScheduler {
|
|
22
|
+
enqueueConcurrency;
|
|
23
|
+
pendingProvingJobs;
|
|
24
|
+
logger;
|
|
25
|
+
deferredJobQueue;
|
|
26
|
+
constructor(enqueueConcurrency, loggerName = 'prover-client:proving-scheduler', bindings){
|
|
27
|
+
this.enqueueConcurrency = enqueueConcurrency;
|
|
28
|
+
this.pendingProvingJobs = [];
|
|
29
|
+
this.logger = createLogger(loggerName, bindings);
|
|
30
|
+
this.deferredJobQueue = new SerialQueue();
|
|
31
|
+
this.deferredJobQueue.start(this.enqueueConcurrency);
|
|
32
|
+
}
|
|
33
|
+
/** Number of broker jobs currently in flight. */ getNumPendingProvingJobs() {
|
|
34
|
+
return this.pendingProvingJobs.length;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Drains the deferred-job queue, recreates it (so the subclass can be reused), and
|
|
38
|
+
* optionally aborts every in-flight broker job. Aborting is the right choice on
|
|
39
|
+
* reorg-driven cancel (where the in-flight inputs are no longer valid) and the
|
|
40
|
+
* wrong choice on shutdown (where leaving jobs in the broker queue lets a restart
|
|
41
|
+
* pick them up).
|
|
42
|
+
*/ resetSchedulerState(abortJobs) {
|
|
43
|
+
void this.deferredJobQueue.cancel();
|
|
44
|
+
this.deferredJobQueue = new SerialQueue();
|
|
45
|
+
this.deferredJobQueue.start(this.enqueueConcurrency);
|
|
46
|
+
if (abortJobs) {
|
|
47
|
+
for (const controller of this.pendingProvingJobs){
|
|
48
|
+
controller.abort();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Standard stop: grab the old queue, cancel (which recreates the queue), then
|
|
54
|
+
* await the old queue's drain so any final job tear-down has unwound before we
|
|
55
|
+
* return.
|
|
56
|
+
*/ async stop() {
|
|
57
|
+
const oldQueue = this.deferredJobQueue;
|
|
58
|
+
this.cancelInternal();
|
|
59
|
+
await oldQueue.cancel();
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Submits a broker request. The returned-via-callback result is dropped if the
|
|
63
|
+
* state has become invalid (re-org, cancellation) by the time it lands. Errors
|
|
64
|
+
* are routed to `state.reject` unless they are abort-driven or the state is
|
|
65
|
+
* already invalid (in which case they're a stale echo of the cancel).
|
|
66
|
+
*
|
|
67
|
+
* @param state - Object exposing `verifyState()` and `reject()`.
|
|
68
|
+
* @param request - The broker call. Receives the controller's signal.
|
|
69
|
+
* @param callback - Runs on success, after `verifyState()` is checked.
|
|
70
|
+
* @param isCancelled - Optional extra cancellation predicate (e.g. a `cancelled`
|
|
71
|
+
* flag the subclass maintains independently of the state). Defaults to never.
|
|
72
|
+
*/ deferredProving(state, request, callback, isCancelled = ()=>false) {
|
|
73
|
+
if (!state.verifyState()) {
|
|
74
|
+
this.logger.debug(`Not enqueuing job, state no longer valid`);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const controller = new AbortController();
|
|
78
|
+
this.pendingProvingJobs.push(controller);
|
|
79
|
+
// We use a 'safeJob'. We don't want promise rejections in the proving pool — we
|
|
80
|
+
// want to capture the error here and reject the proving state while keeping the
|
|
81
|
+
// event loop free of rejections.
|
|
82
|
+
const safeJob = async ()=>{
|
|
83
|
+
try {
|
|
84
|
+
if (controller.signal.aborted) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const result = await request(controller.signal);
|
|
88
|
+
if (controller.signal.aborted || !state.verifyState() || isCancelled()) {
|
|
89
|
+
this.logger.debug(`State no longer valid, discarding result`);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
await callback(result);
|
|
93
|
+
} catch (err) {
|
|
94
|
+
if (err instanceof AbortError || isCancelled()) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (!state.verifyState()) {
|
|
98
|
+
this.logger.debug(`State no longer valid, discarding error from proving job`, err);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this.logger.error(`Error thrown when proving job`, err);
|
|
102
|
+
state.reject(`${err}`);
|
|
103
|
+
} finally{
|
|
104
|
+
const idx = this.pendingProvingJobs.indexOf(controller);
|
|
105
|
+
if (idx > -1) {
|
|
106
|
+
this.pendingProvingJobs.splice(idx, 1);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
void this.deferredJobQueue.put(async ()=>{
|
|
111
|
+
void safeJob();
|
|
112
|
+
// Yield to the macrotask queue so Node has a chance to interleave other work
|
|
113
|
+
// between enqueues.
|
|
114
|
+
await sleep(0);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { type FinalBlobBatchingChallenges } from '@aztec/blob-lib';
|
|
2
|
+
import type { BatchedBlob } from '@aztec/blob-lib/types';
|
|
3
|
+
import { type ARCHIVE_HEIGHT, type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH } from '@aztec/constants';
|
|
4
|
+
import type { EpochNumber } from '@aztec/foundation/branded-types';
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
|
+
import type { LoggerBindings } from '@aztec/foundation/log';
|
|
7
|
+
import type { Tuple } from '@aztec/foundation/serialize';
|
|
8
|
+
import type { EthAddress } from '@aztec/stdlib/block';
|
|
9
|
+
import type { PublicInputsAndRecursiveProof, ServerCircuitProver } from '@aztec/stdlib/interfaces/server';
|
|
10
|
+
import type { Proof } from '@aztec/stdlib/proofs';
|
|
11
|
+
import { type BlockRollupPublicInputs, type RootRollupPublicInputs } from '@aztec/stdlib/rollup';
|
|
12
|
+
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
13
|
+
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
14
|
+
import { TopTreeProvingScheduler } from './top-tree-proving-scheduler.js';
|
|
15
|
+
import { TopTreeProvingState } from './top-tree-proving-state.js';
|
|
16
|
+
/** Per-checkpoint data fed into the top tree. */
|
|
17
|
+
export type CheckpointTopTreeData = {
|
|
18
|
+
/**
|
|
19
|
+
* Block-rollup proof outputs from the checkpoint's sub-tree. Passed as a Promise so the
|
|
20
|
+
* top tree can start (compute hints, pipeline merges) while sub-trees are still proving.
|
|
21
|
+
* The promise resolves to 1 entry for a single-block checkpoint, 2 for multi-block.
|
|
22
|
+
*/
|
|
23
|
+
blockProofs: Promise<PublicInputsAndRecursiveProof<BlockRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>[]>;
|
|
24
|
+
/** L2-to-L1 messages per block in the checkpoint, used to compute the out hash. */
|
|
25
|
+
l2ToL1MsgsPerBlock: Fr[][][];
|
|
26
|
+
/** Blob fields encoding the checkpoint's tx effects, used to compute the blob accumulator. */
|
|
27
|
+
blobFields: Fr[];
|
|
28
|
+
/** Header of the last block in the previous checkpoint (or the epoch's predecessor for index 0). */
|
|
29
|
+
previousBlockHeader: BlockHeader;
|
|
30
|
+
/** Sibling path of the archive tree before any block in this checkpoint landed. */
|
|
31
|
+
previousArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>;
|
|
32
|
+
};
|
|
33
|
+
/** Result of proving the top tree. */
|
|
34
|
+
export type TopTreeResult = {
|
|
35
|
+
publicInputs: RootRollupPublicInputs;
|
|
36
|
+
proof: Proof;
|
|
37
|
+
batchedBlobInputs: BatchedBlob;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Sentinel thrown by `cancel` so callers can distinguish reorg-driven cancellation from
|
|
41
|
+
* a genuine proving failure (and choose to rebuild + retry instead of failing the epoch).
|
|
42
|
+
*/
|
|
43
|
+
export declare class TopTreeCancelledError extends Error {
|
|
44
|
+
constructor(reason?: string);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Drives proving from checkpoint root rollups through the epoch root rollup. Owns no
|
|
48
|
+
* world-state forks or tx processing — every input is supplied by the caller.
|
|
49
|
+
*
|
|
50
|
+
* Pipelined start: `prove()` does not wait for block-level proving. It pre-computes the
|
|
51
|
+
* out-hash and blob-accumulator hint chains immediately from archiver-derivable data,
|
|
52
|
+
* and each checkpoint's root rollup fires the moment its sub-tree's `blockProofs`
|
|
53
|
+
* promise resolves. Later checkpoints can still be block-level proving in parallel.
|
|
54
|
+
*/
|
|
55
|
+
export declare class TopTreeOrchestrator extends TopTreeProvingScheduler {
|
|
56
|
+
private readonly proverId;
|
|
57
|
+
private state;
|
|
58
|
+
private cancelled;
|
|
59
|
+
constructor(prover: ServerCircuitProver, proverId: EthAddress, enqueueConcurrency: number, _telemetryClient?: TelemetryClient, bindings?: LoggerBindings);
|
|
60
|
+
getProverId(): EthAddress;
|
|
61
|
+
/**
|
|
62
|
+
* Proves the top tree from per-checkpoint data and pending block-proofs promises.
|
|
63
|
+
* Resolves with the final epoch proof, or rejects with `TopTreeCancelledError` if
|
|
64
|
+
* `cancel()` is invoked, or any other error if a circuit fails.
|
|
65
|
+
*/
|
|
66
|
+
prove(epochNumber: EpochNumber, totalNumCheckpoints: number, finalBlobBatchingChallenges: FinalBlobBatchingChallenges, checkpointData: CheckpointTopTreeData[]): Promise<TopTreeResult>;
|
|
67
|
+
/**
|
|
68
|
+
* Cancels in-flight proving. If `abortJobs` is true, each pending broker job is aborted
|
|
69
|
+
* (used on reorg, when the surviving checkpoint set differs and the in-flight jobs'
|
|
70
|
+
* inputs are no longer valid). On shutdown the caller passes `false` so jobs remain in
|
|
71
|
+
* the broker queue for reuse on restart.
|
|
72
|
+
*/
|
|
73
|
+
cancel({ abortJobs }: {
|
|
74
|
+
abortJobs: boolean;
|
|
75
|
+
}): void;
|
|
76
|
+
/** Standard shutdown — preserve the broker queue (`abortJobs: false`). */
|
|
77
|
+
protected cancelInternal(): void;
|
|
78
|
+
protected onRootRollupComplete(state: TopTreeProvingState): void;
|
|
79
|
+
private enqueueCheckpointRoot;
|
|
80
|
+
private buildCheckpointRootInputs;
|
|
81
|
+
private computeOutHashHints;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidG9wLXRyZWUtb3JjaGVzdHJhdG9yLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvb3JjaGVzdHJhdG9yL3RvcC10cmVlLW9yY2hlc3RyYXRvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQTBCLEtBQUssMkJBQTJCLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQztBQUMzRixPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUN6RCxPQUFPLEVBQ0wsS0FBSyxjQUFjLEVBR25CLEtBQUsseUNBQXlDLEVBRS9DLE1BQU0sa0JBQWtCLENBQUM7QUFDMUIsT0FBTyxLQUFLLEVBQUUsV0FBVyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFHbkUsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBQ3BELE9BQU8sS0FBSyxFQUFFLGNBQWMsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBRTVELE9BQU8sS0FBSyxFQUFFLEtBQUssRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBRXpELE9BQU8sS0FBSyxFQUFFLFVBQVUsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBQ3RELE9BQU8sS0FBSyxFQUFFLDZCQUE2QixFQU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f,yBAAyB;YA6BzB,mBAAmB;CAyBlC"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { BatchedBlobAccumulator } from '@aztec/blob-lib';
|
|
2
|
+
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB, OUT_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
3
|
+
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
4
|
+
import { BLS12Point } from '@aztec/foundation/curves/bls12';
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
|
+
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
7
|
+
import { MerkleTreeCalculator, shaMerkleHash } from '@aztec/foundation/trees';
|
|
8
|
+
import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
|
|
9
|
+
import { CheckpointRootRollupHints, CheckpointRootRollupPrivateInputs, CheckpointRootSingleBlockRollupPrivateInputs } from '@aztec/stdlib/rollup';
|
|
10
|
+
import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
|
|
11
|
+
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
12
|
+
import { buildBlobHints, toProofData } from './block-building-helpers.js';
|
|
13
|
+
import { TopTreeProvingScheduler } from './top-tree-proving-scheduler.js';
|
|
14
|
+
import { TopTreeProvingState } from './top-tree-proving-state.js';
|
|
15
|
+
/**
|
|
16
|
+
* Sentinel thrown by `cancel` so callers can distinguish reorg-driven cancellation from
|
|
17
|
+
* a genuine proving failure (and choose to rebuild + retry instead of failing the epoch).
|
|
18
|
+
*/ export class TopTreeCancelledError extends Error {
|
|
19
|
+
constructor(reason = 'Top-tree proving cancelled'){
|
|
20
|
+
super(reason);
|
|
21
|
+
this.name = 'TopTreeCancelledError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Drives proving from checkpoint root rollups through the epoch root rollup. Owns no
|
|
26
|
+
* world-state forks or tx processing — every input is supplied by the caller.
|
|
27
|
+
*
|
|
28
|
+
* Pipelined start: `prove()` does not wait for block-level proving. It pre-computes the
|
|
29
|
+
* out-hash and blob-accumulator hint chains immediately from archiver-derivable data,
|
|
30
|
+
* and each checkpoint's root rollup fires the moment its sub-tree's `blockProofs`
|
|
31
|
+
* promise resolves. Later checkpoints can still be block-level proving in parallel.
|
|
32
|
+
*/ export class TopTreeOrchestrator extends TopTreeProvingScheduler {
|
|
33
|
+
proverId;
|
|
34
|
+
state;
|
|
35
|
+
cancelled;
|
|
36
|
+
constructor(prover, proverId, enqueueConcurrency, _telemetryClient = getTelemetryClient(), bindings){
|
|
37
|
+
super(prover, enqueueConcurrency, 'prover-client:top-tree-orchestrator', bindings), this.proverId = proverId, this.cancelled = false;
|
|
38
|
+
}
|
|
39
|
+
getProverId() {
|
|
40
|
+
return this.proverId;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Proves the top tree from per-checkpoint data and pending block-proofs promises.
|
|
44
|
+
* Resolves with the final epoch proof, or rejects with `TopTreeCancelledError` if
|
|
45
|
+
* `cancel()` is invoked, or any other error if a circuit fails.
|
|
46
|
+
*/ async prove(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges, checkpointData) {
|
|
47
|
+
if (checkpointData.length !== totalNumCheckpoints) {
|
|
48
|
+
throw new Error(`checkpointData length (${checkpointData.length}) does not match totalNumCheckpoints (${totalNumCheckpoints}).`);
|
|
49
|
+
}
|
|
50
|
+
if (this.state) {
|
|
51
|
+
throw new Error('TopTreeOrchestrator.prove called twice; construct a new orchestrator per epoch.');
|
|
52
|
+
}
|
|
53
|
+
// If cancel() was already called before prove() ran (e.g. a removeCheckpoint that
|
|
54
|
+
// landed while the caller was still preparing inputs), short-circuit the whole
|
|
55
|
+
// proving path. Without this, prove() would build its state, the per-checkpoint
|
|
56
|
+
// .then handlers would all bail on `this.cancelled`, and the completion promise
|
|
57
|
+
// would never resolve — prove() would hang forever.
|
|
58
|
+
if (this.cancelled) {
|
|
59
|
+
throw new TopTreeCancelledError();
|
|
60
|
+
}
|
|
61
|
+
const { promise: completionPromise, resolve, reject } = promiseWithResolvers();
|
|
62
|
+
// The completion promise is awaited inside the try/catch below. Attach a no-op catch
|
|
63
|
+
// here as well so any spurious unhandled-rejection detection during cancellation
|
|
64
|
+
// (where reject() can fire synchronously before the await microtask installs a handler)
|
|
65
|
+
// is silenced.
|
|
66
|
+
completionPromise.catch(()=>{});
|
|
67
|
+
const startBlobAccumulator = BatchedBlobAccumulator.newWithChallenges(finalBlobBatchingChallenges);
|
|
68
|
+
this.state = new TopTreeProvingState(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges, startBlobAccumulator, resolve, (reason)=>reject(this.cancelled ? new TopTreeCancelledError(reason) : new Error(reason)));
|
|
69
|
+
// Compute the full out-hash hint chain and per-checkpoint start blob accumulators
|
|
70
|
+
// synchronously from archiver data. No proving required.
|
|
71
|
+
const outHashHints = await this.computeOutHashHints(checkpointData);
|
|
72
|
+
const checkpointStartBlobs = [];
|
|
73
|
+
let runningBlobAccumulator = startBlobAccumulator;
|
|
74
|
+
for (const cd of checkpointData){
|
|
75
|
+
checkpointStartBlobs.push(runningBlobAccumulator);
|
|
76
|
+
runningBlobAccumulator = await runningBlobAccumulator.accumulateFields(cd.blobFields);
|
|
77
|
+
}
|
|
78
|
+
this.state.setEndBlobAccumulator(runningBlobAccumulator);
|
|
79
|
+
// For each checkpoint, await its block proofs promise then enqueue the checkpoint root.
|
|
80
|
+
// Each await runs independently — checkpoints whose sub-trees finish first start their
|
|
81
|
+
// root proofs first, in parallel with later checkpoints' block-level proving.
|
|
82
|
+
for(let i = 0; i < checkpointData.length; i++){
|
|
83
|
+
const cd = checkpointData[i];
|
|
84
|
+
const checkpointIndex = i;
|
|
85
|
+
void cd.blockProofs.then((blockProofs)=>{
|
|
86
|
+
if (this.cancelled || !this.state?.verifyState()) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
this.enqueueCheckpointRoot(this.state, checkpointIndex, blockProofs, cd, outHashHints[i], checkpointStartBlobs[i]);
|
|
90
|
+
}, (err)=>{
|
|
91
|
+
if (this.cancelled) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
this.state?.reject(`Sub-tree for checkpoint ${i} failed: ${err}`);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
await completionPromise;
|
|
99
|
+
await this.state.finalizeBatchedBlob();
|
|
100
|
+
return this.state.getEpochProofResult();
|
|
101
|
+
} catch (err) {
|
|
102
|
+
if (this.cancelled) {
|
|
103
|
+
throw new TopTreeCancelledError();
|
|
104
|
+
}
|
|
105
|
+
throw err;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Cancels in-flight proving. If `abortJobs` is true, each pending broker job is aborted
|
|
110
|
+
* (used on reorg, when the surviving checkpoint set differs and the in-flight jobs'
|
|
111
|
+
* inputs are no longer valid). On shutdown the caller passes `false` so jobs remain in
|
|
112
|
+
* the broker queue for reuse on restart.
|
|
113
|
+
*/ cancel({ abortJobs }) {
|
|
114
|
+
this.cancelled = true;
|
|
115
|
+
this.resetSchedulerState(abortJobs);
|
|
116
|
+
this.state?.cancel();
|
|
117
|
+
}
|
|
118
|
+
/** Standard shutdown — preserve the broker queue (`abortJobs: false`). */ cancelInternal() {
|
|
119
|
+
this.cancel({
|
|
120
|
+
abortJobs: false
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
// --- internal: per-checkpoint enqueue path ---
|
|
124
|
+
onRootRollupComplete(state) {
|
|
125
|
+
state.resolve();
|
|
126
|
+
}
|
|
127
|
+
enqueueCheckpointRoot(state, checkpointIndex, blockProofs, cd, outHashHint, startBlobAccumulator) {
|
|
128
|
+
void this.buildCheckpointRootInputs(blockProofs, cd, outHashHint, startBlobAccumulator).then((inputs)=>{
|
|
129
|
+
this.deferredProving(state, (signal)=>{
|
|
130
|
+
if (inputs instanceof CheckpointRootSingleBlockRollupPrivateInputs) {
|
|
131
|
+
return this.prover.getCheckpointRootSingleBlockRollupProof(inputs, signal, state.epochNumber);
|
|
132
|
+
}
|
|
133
|
+
return this.prover.getCheckpointRootRollupProof(inputs, signal, state.epochNumber);
|
|
134
|
+
}, (result)=>{
|
|
135
|
+
this.logger.debug(`Completed checkpoint root proof for checkpoint ${checkpointIndex}`);
|
|
136
|
+
const leafLocation = state.setCheckpointRootRollupProof(checkpointIndex, result);
|
|
137
|
+
if (state.totalNumCheckpoints === 1) {
|
|
138
|
+
this.enqueueEpochPadding(state);
|
|
139
|
+
} else {
|
|
140
|
+
this.checkAndEnqueueNextCheckpointMergeRollup(state, leafLocation);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
async buildCheckpointRootInputs(blockProofs, cd, outHashHint, startBlobAccumulator) {
|
|
146
|
+
const { blobCommitments, blobsHash } = await buildBlobHints(cd.blobFields);
|
|
147
|
+
const hints = CheckpointRootRollupHints.from({
|
|
148
|
+
previousBlockHeader: cd.previousBlockHeader,
|
|
149
|
+
previousArchiveSiblingPath: cd.previousArchiveSiblingPath,
|
|
150
|
+
previousOutHash: outHashHint.treeSnapshot,
|
|
151
|
+
newOutHashSiblingPath: outHashHint.siblingPath,
|
|
152
|
+
startBlobAccumulator: startBlobAccumulator.toBlobAccumulator(),
|
|
153
|
+
finalBlobChallenges: this.state.finalBlobBatchingChallenges,
|
|
154
|
+
blobFields: padArrayEnd(cd.blobFields, Fr.ZERO, FIELDS_PER_BLOB * BLOBS_PER_CHECKPOINT),
|
|
155
|
+
blobCommitments: padArrayEnd(blobCommitments, BLS12Point.ZERO, BLOBS_PER_CHECKPOINT),
|
|
156
|
+
blobsHash
|
|
157
|
+
});
|
|
158
|
+
const proofDatas = blockProofs.map((p)=>toProofData(p));
|
|
159
|
+
return proofDatas.length === 1 ? new CheckpointRootSingleBlockRollupPrivateInputs(proofDatas[0], hints) : new CheckpointRootRollupPrivateInputs([
|
|
160
|
+
proofDatas[0],
|
|
161
|
+
proofDatas[1]
|
|
162
|
+
], hints);
|
|
163
|
+
}
|
|
164
|
+
async computeOutHashHints(checkpointData) {
|
|
165
|
+
const treeCalculator = await MerkleTreeCalculator.create(OUT_HASH_TREE_HEIGHT, undefined, (left, right)=>Promise.resolve(shaMerkleHash(left, right)));
|
|
166
|
+
const computeHint = async (leaves)=>{
|
|
167
|
+
const tree = await treeCalculator.computeTree(leaves.map((l)=>l.toBuffer()));
|
|
168
|
+
const nextAvailableLeafIndex = leaves.length;
|
|
169
|
+
return {
|
|
170
|
+
treeSnapshot: new AppendOnlyTreeSnapshot(Fr.fromBuffer(tree.root), nextAvailableLeafIndex),
|
|
171
|
+
siblingPath: tree.getSiblingPath(nextAvailableLeafIndex).map(Fr.fromBuffer)
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
const hints = [];
|
|
175
|
+
const outHashes = [];
|
|
176
|
+
for (const cd of checkpointData){
|
|
177
|
+
hints.push(await computeHint(outHashes));
|
|
178
|
+
outHashes.push(computeCheckpointOutHash(cd.l2ToL1MsgsPerBlock));
|
|
179
|
+
}
|
|
180
|
+
return hints;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { NESTED_RECURSIVE_PROOF_LENGTH, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH } from '@aztec/constants';
|
|
2
|
+
import type { EpochNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import type { LoggerBindings } from '@aztec/foundation/log';
|
|
4
|
+
import type { TreeNodeLocation } from '@aztec/foundation/trees';
|
|
5
|
+
import type { PublicInputsAndRecursiveProof, ServerCircuitProver } from '@aztec/stdlib/interfaces/server';
|
|
6
|
+
import type { CheckpointMergeRollupPrivateInputs, CheckpointPaddingRollupPrivateInputs, CheckpointRollupPublicInputs, RootRollupPrivateInputs, RootRollupPublicInputs } from '@aztec/stdlib/rollup';
|
|
7
|
+
import { ProvingScheduler, type ProvingStateLike } from './proving-scheduler.js';
|
|
8
|
+
type CheckpointRollupProof = PublicInputsAndRecursiveProof<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>;
|
|
9
|
+
type RootRollupProof = PublicInputsAndRecursiveProof<RootRollupPublicInputs, typeof NESTED_RECURSIVE_PROOF_LENGTH>;
|
|
10
|
+
/**
|
|
11
|
+
* State interface required by the top-tree proving drivers (checkpoint-merge → padding →
|
|
12
|
+
* root-rollup). Both `EpochProvingState` and `TopTreeProvingState` satisfy it structurally;
|
|
13
|
+
* the per-checkpoint state in `EpochProvingState` (block/tx proving, world-state forks)
|
|
14
|
+
* is owned outside this surface.
|
|
15
|
+
*/
|
|
16
|
+
export interface TopTreeStateLike extends ProvingStateLike {
|
|
17
|
+
readonly epochNumber: EpochNumber;
|
|
18
|
+
readonly totalNumCheckpoints: number;
|
|
19
|
+
tryStartProvingCheckpointMerge(location: TreeNodeLocation): boolean;
|
|
20
|
+
setCheckpointMergeRollupProof(location: TreeNodeLocation, provingOutput: CheckpointRollupProof): void;
|
|
21
|
+
isReadyForCheckpointMerge(location: TreeNodeLocation): boolean;
|
|
22
|
+
getParentLocation(location: TreeNodeLocation): TreeNodeLocation;
|
|
23
|
+
getCheckpointMergeRollupInputs(location: TreeNodeLocation): CheckpointMergeRollupPrivateInputs;
|
|
24
|
+
tryStartProvingPaddingCheckpoint(): boolean;
|
|
25
|
+
setCheckpointPaddingProof(provingOutput: CheckpointRollupProof): void;
|
|
26
|
+
getPaddingCheckpointInputs(): CheckpointPaddingRollupPrivateInputs;
|
|
27
|
+
tryStartProvingRootRollup(): boolean;
|
|
28
|
+
setRootRollupProof(provingOutput: RootRollupProof): void;
|
|
29
|
+
isReadyForRootRollup(): boolean;
|
|
30
|
+
getRootRollupInputs(): RootRollupPrivateInputs;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Shared scheduling for the top-tree section of epoch proving — checkpoint-merge,
|
|
34
|
+
* padding (single-checkpoint case), and root rollup. Both `ProvingOrchestrator` and
|
|
35
|
+
* `TopTreeOrchestrator` extend this; their per-checkpoint-root drivers diverge (one
|
|
36
|
+
* drains state-derived inputs once block-merge is done, the other builds inputs from
|
|
37
|
+
* caller-supplied checkpoint data), but the rest of the tree is identical.
|
|
38
|
+
*
|
|
39
|
+
* Subclasses provide a `wrapCircuitCall` hook for telemetry (the orchestrator wraps
|
|
40
|
+
* each call in a span; the top-tree leaves it as identity), and an
|
|
41
|
+
* `onRootRollupComplete` hook to invoke the right shape of `state.resolve()` —
|
|
42
|
+
* `EpochProvingState.resolve` takes a `ProvingResult`, `TopTreeProvingState.resolve`
|
|
43
|
+
* is no-arg.
|
|
44
|
+
*/
|
|
45
|
+
export declare abstract class TopTreeProvingScheduler extends ProvingScheduler {
|
|
46
|
+
protected readonly prover: ServerCircuitProver;
|
|
47
|
+
constructor(prover: ServerCircuitProver, enqueueConcurrency: number, loggerName?: string, bindings?: LoggerBindings);
|
|
48
|
+
/**
|
|
49
|
+
* Wraps a circuit call for telemetry. Default is identity; the orchestrator overrides
|
|
50
|
+
* to wrap with `wrapCallbackInSpan`.
|
|
51
|
+
*/
|
|
52
|
+
protected wrapCircuitCall<T>(_circuitName: string, fn: (signal: AbortSignal) => Promise<T>): (signal: AbortSignal) => Promise<T>;
|
|
53
|
+
/** Called once the root rollup proof has been set; subclasses call `state.resolve(...)` with the right shape. */
|
|
54
|
+
protected abstract onRootRollupComplete(state: TopTreeStateLike): void;
|
|
55
|
+
protected enqueueCheckpointMergeRollup(state: TopTreeStateLike, location: TreeNodeLocation): void;
|
|
56
|
+
protected enqueueEpochPadding(state: TopTreeStateLike): void;
|
|
57
|
+
protected enqueueRootRollup(state: TopTreeStateLike): void;
|
|
58
|
+
protected checkAndEnqueueNextCheckpointMergeRollup(state: TopTreeStateLike, currentLocation: TreeNodeLocation): void;
|
|
59
|
+
protected checkAndEnqueueRootRollup(state: TopTreeStateLike): void;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
62
|
+
//# sour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,CAAC;IACzD,oBAAoB,IAAI,OAAO,CAAC;IAChC,mBAAmB,IAAI,uBAAuB,CAAC;CAChD;AAED;;;;;;;;;;;;GAYG;AACH,8BAAsB,uBAAwB,SAAQ,gBAAgB;IAElE,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,mBAAmB;IADhD,YACqB,MAAM,EAAE,mBAAmB,EAC9C,kBAAkB,EAAE,MAAM,EAC1B,UAAU,CAAC,EAAE,MAAM,EACnB,QAAQ,CAAC,EAAE,cAAc,EAG1B;IAED;;;OAGG;IACH,SAAS,CAAC,eAAe,CAAC,CAAC,EACzB,YAAY,EAAE,MAAM,EACpB,EAAE,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GACtC,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,CAErC;IAED,iHAAiH;IACjH,SAAS,CAAC,QAAQ,CAAC,oBAAoB,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAEvE,SAAS,CAAC,4BAA4B,CAAC,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,gBAAgB,QAezF;IAED,SAAS,CAAC,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,QAepD;IAED,SAAS,CAAC,iBAAiB,CAAC,KAAK,EAAE,gBAAgB,QAclD;IAED,SAAS,CAAC,wCAAwC,CAAC,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,gBAAgB,QAU5G;IAED,SAAS,CAAC,yBAAyB,CAAC,KAAK,EAAE,gBAAgB,QAK1D;CACF"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ProvingScheduler } from './proving-scheduler.js';
|
|
2
|
+
/**
|
|
3
|
+
* Shared scheduling for the top-tree section of epoch proving — checkpoint-merge,
|
|
4
|
+
* padding (single-checkpoint case), and root rollup. Both `ProvingOrchestrator` and
|
|
5
|
+
* `TopTreeOrchestrator` extend this; their per-checkpoint-root drivers diverge (one
|
|
6
|
+
* drains state-derived inputs once block-merge is done, the other builds inputs from
|
|
7
|
+
* caller-supplied checkpoint data), but the rest of the tree is identical.
|
|
8
|
+
*
|
|
9
|
+
* Subclasses provide a `wrapCircuitCall` hook for telemetry (the orchestrator wraps
|
|
10
|
+
* each call in a span; the top-tree leaves it as identity), and an
|
|
11
|
+
* `onRootRollupComplete` hook to invoke the right shape of `state.resolve()` —
|
|
12
|
+
* `EpochProvingState.resolve` takes a `ProvingResult`, `TopTreeProvingState.resolve`
|
|
13
|
+
* is no-arg.
|
|
14
|
+
*/ export class TopTreeProvingScheduler extends ProvingScheduler {
|
|
15
|
+
prover;
|
|
16
|
+
constructor(prover, enqueueConcurrency, loggerName, bindings){
|
|
17
|
+
super(enqueueConcurrency, loggerName, bindings), this.prover = prover;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Wraps a circuit call for telemetry. Default is identity; the orchestrator overrides
|
|
21
|
+
* to wrap with `wrapCallbackInSpan`.
|
|
22
|
+
*/ wrapCircuitCall(_circuitName, fn) {
|
|
23
|
+
return fn;
|
|
24
|
+
}
|
|
25
|
+
enqueueCheckpointMergeRollup(state, location) {
|
|
26
|
+
if (!state.verifyState() || !state.tryStartProvingCheckpointMerge(location)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const inputs = state.getCheckpointMergeRollupInputs(location);
|
|
30
|
+
this.deferredProving(state, this.wrapCircuitCall('rollup-checkpoint-merge', (signal)=>this.prover.getCheckpointMergeRollupProof(inputs, signal, state.epochNumber)), (result)=>{
|
|
31
|
+
state.setCheckpointMergeRollupProof(location, result);
|
|
32
|
+
this.checkAndEnqueueNextCheckpointMergeRollup(state, location);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
enqueueEpochPadding(state) {
|
|
36
|
+
if (!state.verifyState() || !state.tryStartProvingPaddingCheckpoint()) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const inputs = state.getPaddingCheckpointInputs();
|
|
40
|
+
this.deferredProving(state, this.wrapCircuitCall('rollup-checkpoint-padding', (signal)=>this.prover.getCheckpointPaddingRollupProof(inputs, signal, state.epochNumber)), (result)=>{
|
|
41
|
+
state.setCheckpointPaddingProof(result);
|
|
42
|
+
this.checkAndEnqueueRootRollup(state);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
enqueueRootRollup(state) {
|
|
46
|
+
if (!state.verifyState() || !state.tryStartProvingRootRollup()) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const inputs = state.getRootRollupInputs();
|
|
50
|
+
this.deferredProving(state, this.wrapCircuitCall('rollup-root', (signal)=>this.prover.getRootRollupProof(inputs, signal, state.epochNumber)), (result)=>{
|
|
51
|
+
this.logger.verbose(`Completed root rollup for epoch ${state.epochNumber}`);
|
|
52
|
+
state.setRootRollupProof(result);
|
|
53
|
+
this.onRootRollupComplete(state);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
checkAndEnqueueNextCheckpointMergeRollup(state, currentLocation) {
|
|
57
|
+
if (!state.isReadyForCheckpointMerge(currentLocation)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const parentLocation = state.getParentLocation(currentLocation);
|
|
61
|
+
if (parentLocation.level === 0) {
|
|
62
|
+
this.checkAndEnqueueRootRollup(state);
|
|
63
|
+
} else {
|
|
64
|
+
this.enqueueCheckpointMergeRollup(state, parentLocation);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
checkAndEnqueueRootRollup(state) {
|
|
68
|
+
if (!state.isReadyForRootRollup()) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
this.enqueueRootRollup(state);
|
|
72
|
+
}
|
|
73
|
+
}
|