@aztec/prover-client 0.0.0-test.0
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/README.md +1 -0
- package/dest/bin/get-proof-inputs.d.ts +2 -0
- package/dest/bin/get-proof-inputs.d.ts.map +1 -0
- package/dest/bin/get-proof-inputs.js +51 -0
- package/dest/block_builder/index.d.ts +6 -0
- package/dest/block_builder/index.d.ts.map +1 -0
- package/dest/block_builder/index.js +1 -0
- package/dest/block_builder/light.d.ts +33 -0
- package/dest/block_builder/light.d.ts.map +1 -0
- package/dest/block_builder/light.js +82 -0
- package/dest/config.d.ts +17 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/config.js +39 -0
- package/dest/index.d.ts +4 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +2 -0
- package/dest/mocks/fixtures.d.ts +20 -0
- package/dest/mocks/fixtures.d.ts.map +1 -0
- package/dest/mocks/fixtures.js +77 -0
- package/dest/mocks/test_context.d.ts +55 -0
- package/dest/mocks/test_context.d.ts.map +1 -0
- package/dest/mocks/test_context.js +193 -0
- package/dest/orchestrator/block-building-helpers.d.ts +55 -0
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -0
- package/dest/orchestrator/block-building-helpers.js +285 -0
- package/dest/orchestrator/block-proving-state.d.ts +76 -0
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/block-proving-state.js +269 -0
- package/dest/orchestrator/epoch-proving-state.d.ts +60 -0
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/epoch-proving-state.js +163 -0
- package/dest/orchestrator/index.d.ts +2 -0
- package/dest/orchestrator/index.d.ts.map +1 -0
- package/dest/orchestrator/index.js +1 -0
- package/dest/orchestrator/orchestrator.d.ts +110 -0
- package/dest/orchestrator/orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/orchestrator.js +690 -0
- package/dest/orchestrator/orchestrator_metrics.d.ts +8 -0
- package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -0
- package/dest/orchestrator/orchestrator_metrics.js +17 -0
- package/dest/orchestrator/tx-proving-state.d.ts +34 -0
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/tx-proving-state.js +94 -0
- package/dest/prover-client/factory.d.ts +6 -0
- package/dest/prover-client/factory.d.ts.map +1 -0
- package/dest/prover-client/factory.js +5 -0
- package/dest/prover-client/index.d.ts +3 -0
- package/dest/prover-client/index.d.ts.map +1 -0
- package/dest/prover-client/index.js +2 -0
- package/dest/prover-client/prover-client.d.ts +42 -0
- package/dest/prover-client/prover-client.d.ts.map +1 -0
- package/dest/prover-client/prover-client.js +110 -0
- package/dest/prover-client/server-epoch-prover.d.ts +28 -0
- package/dest/prover-client/server-epoch-prover.d.ts.map +1 -0
- package/dest/prover-client/server-epoch-prover.js +40 -0
- package/dest/proving_broker/broker_prover_facade.d.ts +46 -0
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -0
- package/dest/proving_broker/broker_prover_facade.js +344 -0
- package/dest/proving_broker/config.d.ts +83 -0
- package/dest/proving_broker/config.d.ts.map +1 -0
- package/dest/proving_broker/config.js +104 -0
- package/dest/proving_broker/factory.d.ts +5 -0
- package/dest/proving_broker/factory.d.ts.map +1 -0
- package/dest/proving_broker/factory.js +9 -0
- package/dest/proving_broker/fixtures.d.ts +5 -0
- package/dest/proving_broker/fixtures.d.ts.map +1 -0
- package/dest/proving_broker/fixtures.js +12 -0
- package/dest/proving_broker/index.d.ts +10 -0
- package/dest/proving_broker/index.d.ts.map +1 -0
- package/dest/proving_broker/index.js +9 -0
- package/dest/proving_broker/proof_store/factory.d.ts +6 -0
- package/dest/proving_broker/proof_store/factory.d.ts.map +1 -0
- package/dest/proving_broker/proof_store/factory.js +36 -0
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +14 -0
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +1 -0
- package/dest/proving_broker/proof_store/gcs_proof_store.js +51 -0
- package/dest/proving_broker/proof_store/index.d.ts +4 -0
- package/dest/proving_broker/proof_store/index.d.ts.map +1 -0
- package/dest/proving_broker/proof_store/index.js +3 -0
- package/dest/proving_broker/proof_store/inline_proof_store.d.ts +15 -0
- package/dest/proving_broker/proof_store/inline_proof_store.d.ts.map +1 -0
- package/dest/proving_broker/proof_store/inline_proof_store.js +41 -0
- package/dest/proving_broker/proof_store/proof_store.d.ts +36 -0
- package/dest/proving_broker/proof_store/proof_store.d.ts.map +1 -0
- package/dest/proving_broker/proof_store/proof_store.js +3 -0
- package/dest/proving_broker/proving_agent.d.ts +46 -0
- package/dest/proving_broker/proving_agent.d.ts.map +1 -0
- package/dest/proving_broker/proving_agent.js +134 -0
- package/dest/proving_broker/proving_agent_instrumentation.d.ts +8 -0
- package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +1 -0
- package/dest/proving_broker/proving_agent_instrumentation.js +16 -0
- package/dest/proving_broker/proving_broker.d.ts +64 -0
- package/dest/proving_broker/proving_broker.d.ts.map +1 -0
- package/dest/proving_broker/proving_broker.js +570 -0
- package/dest/proving_broker/proving_broker_database/memory.d.ts +16 -0
- package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -0
- package/dest/proving_broker/proving_broker_database/memory.js +54 -0
- package/dest/proving_broker/proving_broker_database/persisted.d.ts +25 -0
- package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -0
- package/dest/proving_broker/proving_broker_database/persisted.js +182 -0
- package/dest/proving_broker/proving_broker_database.d.ts +39 -0
- package/dest/proving_broker/proving_broker_database.d.ts.map +1 -0
- package/dest/proving_broker/proving_broker_database.js +3 -0
- package/dest/proving_broker/proving_broker_instrumentation.d.ts +29 -0
- package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -0
- package/dest/proving_broker/proving_broker_instrumentation.js +110 -0
- package/dest/proving_broker/proving_job_controller.d.ts +33 -0
- package/dest/proving_broker/proving_job_controller.d.ts.map +1 -0
- package/dest/proving_broker/proving_job_controller.js +166 -0
- package/dest/proving_broker/rpc.d.ts +27 -0
- package/dest/proving_broker/rpc.d.ts.map +1 -0
- package/dest/proving_broker/rpc.js +66 -0
- package/dest/test/mock_prover.d.ts +35 -0
- package/dest/test/mock_prover.d.ts.map +1 -0
- package/dest/test/mock_prover.js +82 -0
- package/package.json +112 -0
- package/src/bin/get-proof-inputs.ts +59 -0
- package/src/block_builder/index.ts +6 -0
- package/src/block_builder/light.ts +101 -0
- package/src/config.ts +55 -0
- package/src/index.ts +4 -0
- package/src/mocks/fixtures.ts +117 -0
- package/src/mocks/test_context.ts +257 -0
- package/src/orchestrator/block-building-helpers.ts +553 -0
- package/src/orchestrator/block-proving-state.ts +379 -0
- package/src/orchestrator/epoch-proving-state.ts +252 -0
- package/src/orchestrator/index.ts +1 -0
- package/src/orchestrator/orchestrator.ts +971 -0
- package/src/orchestrator/orchestrator_metrics.ts +22 -0
- package/src/orchestrator/tx-proving-state.ts +139 -0
- package/src/prover-client/factory.ts +14 -0
- package/src/prover-client/index.ts +2 -0
- package/src/prover-client/prover-client.ts +162 -0
- package/src/prover-client/server-epoch-prover.ts +51 -0
- package/src/proving_broker/broker_prover_facade.ts +585 -0
- package/src/proving_broker/config.ts +138 -0
- package/src/proving_broker/factory.ts +18 -0
- package/src/proving_broker/fixtures.ts +15 -0
- package/src/proving_broker/index.ts +9 -0
- package/src/proving_broker/proof_store/factory.ts +42 -0
- package/src/proving_broker/proof_store/gcs_proof_store.ts +72 -0
- package/src/proving_broker/proof_store/index.ts +3 -0
- package/src/proving_broker/proof_store/inline_proof_store.ts +63 -0
- package/src/proving_broker/proof_store/proof_store.ts +54 -0
- package/src/proving_broker/proving_agent.ts +181 -0
- package/src/proving_broker/proving_agent_instrumentation.ts +21 -0
- package/src/proving_broker/proving_broker.ts +687 -0
- package/src/proving_broker/proving_broker_database/memory.ts +63 -0
- package/src/proving_broker/proving_broker_database/persisted.ts +218 -0
- package/src/proving_broker/proving_broker_database.ts +44 -0
- package/src/proving_broker/proving_broker_instrumentation.ts +145 -0
- package/src/proving_broker/proving_job_controller.ts +194 -0
- package/src/proving_broker/rpc.ts +95 -0
- package/src/test/mock_prover.ts +253 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { SpongeBlob } from '@aztec/blob-lib';
|
|
2
|
+
import { BLOBS_PER_BLOCK, FIELDS_PER_BLOB, NUM_BASE_PARITY_PER_ROOT_PARITY, VK_TREE_HEIGHT } from '@aztec/constants';
|
|
3
|
+
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
4
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
5
|
+
import { MembershipWitness, UnbalancedTreeStore } from '@aztec/foundation/trees';
|
|
6
|
+
import { getVKIndex, getVKSiblingPath, getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
7
|
+
import { protocolContractTreeRoot } from '@aztec/protocol-contracts';
|
|
8
|
+
import { RootParityInput, RootParityInputs } from '@aztec/stdlib/parity';
|
|
9
|
+
import { BlockRootRollupBlobData, BlockRootRollupData, BlockRootRollupInputs, ConstantRollupData, EmptyBlockRootRollupInputs, MergeRollupInputs, PreviousRollupData, SingleTxBlockRootRollupInputs } from '@aztec/stdlib/rollup';
|
|
10
|
+
import { StateReference } from '@aztec/stdlib/tx';
|
|
11
|
+
import { buildBlobHints, buildHeaderFromCircuitOutputs } from './block-building-helpers.js';
|
|
12
|
+
/**
|
|
13
|
+
* The current state of the proving schedule for a given block. Managed by ProvingState.
|
|
14
|
+
* Contains the raw inputs and intermediate state to generate every constituent proof in the tree.
|
|
15
|
+
*/ export class BlockProvingState {
|
|
16
|
+
index;
|
|
17
|
+
globalVariables;
|
|
18
|
+
newL1ToL2Messages;
|
|
19
|
+
l1ToL2MessageSubtreeSiblingPath;
|
|
20
|
+
l1ToL2MessageTreeSnapshotAfterInsertion;
|
|
21
|
+
lastArchiveSnapshot;
|
|
22
|
+
newArchiveSiblingPath;
|
|
23
|
+
previousBlockHeader;
|
|
24
|
+
parentEpoch;
|
|
25
|
+
baseOrMergeProvingOutputs;
|
|
26
|
+
baseParityProvingOutputs;
|
|
27
|
+
rootParityProvingOutput;
|
|
28
|
+
blockRootProvingOutput;
|
|
29
|
+
blockRootRollupStarted;
|
|
30
|
+
block;
|
|
31
|
+
spongeBlobState;
|
|
32
|
+
totalNumTxs;
|
|
33
|
+
txs;
|
|
34
|
+
error;
|
|
35
|
+
constructor(index, globalVariables, newL1ToL2Messages, l1ToL2MessageSubtreeSiblingPath, l1ToL2MessageTreeSnapshotAfterInsertion, lastArchiveSnapshot, newArchiveSiblingPath, previousBlockHeader, parentEpoch){
|
|
36
|
+
this.index = index;
|
|
37
|
+
this.globalVariables = globalVariables;
|
|
38
|
+
this.newL1ToL2Messages = newL1ToL2Messages;
|
|
39
|
+
this.l1ToL2MessageSubtreeSiblingPath = l1ToL2MessageSubtreeSiblingPath;
|
|
40
|
+
this.l1ToL2MessageTreeSnapshotAfterInsertion = l1ToL2MessageTreeSnapshotAfterInsertion;
|
|
41
|
+
this.lastArchiveSnapshot = lastArchiveSnapshot;
|
|
42
|
+
this.newArchiveSiblingPath = newArchiveSiblingPath;
|
|
43
|
+
this.previousBlockHeader = previousBlockHeader;
|
|
44
|
+
this.parentEpoch = parentEpoch;
|
|
45
|
+
this.baseOrMergeProvingOutputs = new UnbalancedTreeStore(0);
|
|
46
|
+
this.blockRootRollupStarted = false;
|
|
47
|
+
this.txs = [];
|
|
48
|
+
this.baseParityProvingOutputs = Array.from({
|
|
49
|
+
length: NUM_BASE_PARITY_PER_ROOT_PARITY
|
|
50
|
+
}).map((_)=>undefined);
|
|
51
|
+
this.totalNumTxs = 0;
|
|
52
|
+
}
|
|
53
|
+
get blockNumber() {
|
|
54
|
+
return this.globalVariables.blockNumber.toNumber();
|
|
55
|
+
}
|
|
56
|
+
startNewBlock(numTxs, numBlobFields) {
|
|
57
|
+
if (this.spongeBlobState) {
|
|
58
|
+
throw new Error(`Block ${this.blockNumber} already initalised.`);
|
|
59
|
+
}
|
|
60
|
+
this.baseOrMergeProvingOutputs = new UnbalancedTreeStore(numTxs);
|
|
61
|
+
// Initialise the sponge which will eventually absorb all tx effects to be added to the blob.
|
|
62
|
+
// Like l1 to l2 messages, we need to know beforehand how many effects will be absorbed.
|
|
63
|
+
this.spongeBlobState = SpongeBlob.init(numBlobFields);
|
|
64
|
+
this.totalNumTxs = numTxs;
|
|
65
|
+
}
|
|
66
|
+
// Adds a transaction to the proving state, returns it's index
|
|
67
|
+
addNewTx(tx) {
|
|
68
|
+
if (!this.spongeBlobState) {
|
|
69
|
+
throw new Error(`Invalid block proving state, call startNewBlock before adding transactions.`);
|
|
70
|
+
}
|
|
71
|
+
const txIndex = this.txs.length;
|
|
72
|
+
this.txs[txIndex] = tx;
|
|
73
|
+
return txIndex;
|
|
74
|
+
}
|
|
75
|
+
setBaseRollupProof(txIndex, provingOutput) {
|
|
76
|
+
return this.baseOrMergeProvingOutputs.setLeaf(txIndex, provingOutput);
|
|
77
|
+
}
|
|
78
|
+
setMergeRollupProof(location, provingOutput) {
|
|
79
|
+
this.baseOrMergeProvingOutputs.setNode(location, provingOutput);
|
|
80
|
+
}
|
|
81
|
+
// Stores a set of root parity inputs at the given index
|
|
82
|
+
setBaseParityProof(index, provingOutput) {
|
|
83
|
+
if (index >= NUM_BASE_PARITY_PER_ROOT_PARITY) {
|
|
84
|
+
throw new Error(`Unable to set a base parity proofs at index ${index}. Expected at most ${NUM_BASE_PARITY_PER_ROOT_PARITY} proofs.`);
|
|
85
|
+
}
|
|
86
|
+
this.baseParityProvingOutputs[index] = provingOutput;
|
|
87
|
+
}
|
|
88
|
+
setRootParityProof(provingOutput) {
|
|
89
|
+
this.rootParityProvingOutput = provingOutput;
|
|
90
|
+
}
|
|
91
|
+
setBlockRootRollupProof(provingOutput) {
|
|
92
|
+
this.blockRootProvingOutput = provingOutput;
|
|
93
|
+
}
|
|
94
|
+
// Returns the complete set of transaction proving state objects
|
|
95
|
+
get allTxs() {
|
|
96
|
+
return this.txs;
|
|
97
|
+
}
|
|
98
|
+
/** Returns the block number as an epoch number. Used for prioritizing proof requests. */ get epochNumber() {
|
|
99
|
+
return this.parentEpoch.epochNumber;
|
|
100
|
+
}
|
|
101
|
+
getParentLocation(location) {
|
|
102
|
+
return this.baseOrMergeProvingOutputs.getParentLocation(location);
|
|
103
|
+
}
|
|
104
|
+
getMergeRollupInputs(mergeLocation) {
|
|
105
|
+
const [left, right] = this.baseOrMergeProvingOutputs.getChildren(mergeLocation);
|
|
106
|
+
if (!left || !right) {
|
|
107
|
+
throw new Error('At lease one child is not ready.');
|
|
108
|
+
}
|
|
109
|
+
return new MergeRollupInputs([
|
|
110
|
+
this.#getPreviousRollupData(left),
|
|
111
|
+
this.#getPreviousRollupData(right)
|
|
112
|
+
]);
|
|
113
|
+
}
|
|
114
|
+
async getBlockRootRollupTypeAndInputs(proverId) {
|
|
115
|
+
if (!this.rootParityProvingOutput) {
|
|
116
|
+
throw new Error('Root parity is not ready.');
|
|
117
|
+
}
|
|
118
|
+
const proofs = this.#getChildProofsForBlockRoot();
|
|
119
|
+
const nonEmptyProofs = proofs.filter((p)=>!!p);
|
|
120
|
+
if (proofs.length !== nonEmptyProofs.length) {
|
|
121
|
+
throw new Error('At lease one child is not ready for the block root.');
|
|
122
|
+
}
|
|
123
|
+
const data = this.#getBlockRootRollupData(proverId);
|
|
124
|
+
if (this.totalNumTxs === 0) {
|
|
125
|
+
const constants = ConstantRollupData.from({
|
|
126
|
+
lastArchive: this.lastArchiveSnapshot,
|
|
127
|
+
globalVariables: this.globalVariables,
|
|
128
|
+
vkTreeRoot: getVKTreeRoot(),
|
|
129
|
+
protocolContractTreeRoot
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
rollupType: 'empty-block-root-rollup',
|
|
133
|
+
inputs: EmptyBlockRootRollupInputs.from({
|
|
134
|
+
data,
|
|
135
|
+
constants,
|
|
136
|
+
isPadding: false
|
|
137
|
+
})
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const previousRollupData = await Promise.all(nonEmptyProofs.map((p)=>this.#getPreviousRollupData(p)));
|
|
141
|
+
const blobData = await this.#getBlockRootRollupBlobData();
|
|
142
|
+
if (previousRollupData.length === 1) {
|
|
143
|
+
return {
|
|
144
|
+
rollupType: 'single-tx-block-root-rollup',
|
|
145
|
+
inputs: new SingleTxBlockRootRollupInputs(previousRollupData, data, blobData)
|
|
146
|
+
};
|
|
147
|
+
} else {
|
|
148
|
+
return {
|
|
149
|
+
rollupType: 'block-root-rollup',
|
|
150
|
+
inputs: new BlockRootRollupInputs(previousRollupData, data, blobData)
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async getPaddingBlockRootInputs(proverId) {
|
|
155
|
+
if (!this.rootParityProvingOutput) {
|
|
156
|
+
throw new Error('Root parity is not ready.');
|
|
157
|
+
}
|
|
158
|
+
// Use the new block header and archive of the current block as the previous header and archiver of the next padding block.
|
|
159
|
+
const newBlockHeader = await this.buildHeaderFromProvingOutputs();
|
|
160
|
+
const newArchive = this.blockRootProvingOutput.inputs.newArchive;
|
|
161
|
+
const data = BlockRootRollupData.from({
|
|
162
|
+
l1ToL2Roots: this.#getRootParityData(this.rootParityProvingOutput),
|
|
163
|
+
l1ToL2MessageSubtreeSiblingPath: this.l1ToL2MessageSubtreeSiblingPath,
|
|
164
|
+
newArchiveSiblingPath: this.newArchiveSiblingPath,
|
|
165
|
+
previousBlockHeader: newBlockHeader,
|
|
166
|
+
proverId
|
|
167
|
+
});
|
|
168
|
+
const constants = ConstantRollupData.from({
|
|
169
|
+
lastArchive: newArchive,
|
|
170
|
+
globalVariables: this.globalVariables,
|
|
171
|
+
vkTreeRoot: getVKTreeRoot(),
|
|
172
|
+
protocolContractTreeRoot
|
|
173
|
+
});
|
|
174
|
+
return EmptyBlockRootRollupInputs.from({
|
|
175
|
+
data,
|
|
176
|
+
constants,
|
|
177
|
+
isPadding: true
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
getRootParityInputs() {
|
|
181
|
+
if (!this.baseParityProvingOutputs.every((p)=>!!p)) {
|
|
182
|
+
throw new Error('At lease one base parity is not ready.');
|
|
183
|
+
}
|
|
184
|
+
const children = this.baseParityProvingOutputs.map((p)=>this.#getRootParityData(p));
|
|
185
|
+
return new RootParityInputs(children);
|
|
186
|
+
}
|
|
187
|
+
// Returns a specific transaction proving state
|
|
188
|
+
getTxProvingState(txIndex) {
|
|
189
|
+
return this.txs[txIndex];
|
|
190
|
+
}
|
|
191
|
+
async buildHeaderFromProvingOutputs(logger) {
|
|
192
|
+
const previousRollupData = this.totalNumTxs === 0 ? [] : await Promise.all(this.#getChildProofsForBlockRoot().map((p)=>this.#getPreviousRollupData(p)));
|
|
193
|
+
let endPartialState = this.previousBlockHeader.state.partial;
|
|
194
|
+
if (this.totalNumTxs !== 0) {
|
|
195
|
+
const previousRollupData = this.#getChildProofsForBlockRoot();
|
|
196
|
+
const lastRollup = previousRollupData[previousRollupData.length - 1];
|
|
197
|
+
if (!lastRollup) {
|
|
198
|
+
throw new Error('End state of the block is not available. Last rollup is not ready yet.');
|
|
199
|
+
}
|
|
200
|
+
endPartialState = lastRollup.inputs.end;
|
|
201
|
+
}
|
|
202
|
+
const endState = new StateReference(this.l1ToL2MessageTreeSnapshotAfterInsertion, endPartialState);
|
|
203
|
+
return buildHeaderFromCircuitOutputs(previousRollupData.map((d)=>d.baseOrMergeRollupPublicInputs), this.rootParityProvingOutput.inputs, this.blockRootProvingOutput.inputs, endState, logger);
|
|
204
|
+
}
|
|
205
|
+
isReadyForMergeRollup(location) {
|
|
206
|
+
return this.baseOrMergeProvingOutputs.getSibling(location) !== undefined;
|
|
207
|
+
}
|
|
208
|
+
// Returns true if we have sufficient inputs to execute the block root rollup
|
|
209
|
+
isReadyForBlockRootRollup() {
|
|
210
|
+
const childProofs = this.#getChildProofsForBlockRoot();
|
|
211
|
+
return this.block !== undefined && this.rootParityProvingOutput !== undefined && childProofs.every((p)=>!!p);
|
|
212
|
+
}
|
|
213
|
+
// Returns true if we have sufficient root parity inputs to execute the root parity circuit
|
|
214
|
+
isReadyForRootParity() {
|
|
215
|
+
return this.baseParityProvingOutputs.every((p)=>!!p);
|
|
216
|
+
}
|
|
217
|
+
isComplete() {
|
|
218
|
+
return !!this.blockRootProvingOutput;
|
|
219
|
+
}
|
|
220
|
+
// Returns whether the proving state is still valid
|
|
221
|
+
verifyState() {
|
|
222
|
+
return this.parentEpoch.verifyState();
|
|
223
|
+
}
|
|
224
|
+
reject(reason) {
|
|
225
|
+
this.error = reason;
|
|
226
|
+
this.parentEpoch.reject(reason);
|
|
227
|
+
}
|
|
228
|
+
#getBlockRootRollupData(proverId) {
|
|
229
|
+
return BlockRootRollupData.from({
|
|
230
|
+
l1ToL2Roots: this.#getRootParityData(this.rootParityProvingOutput),
|
|
231
|
+
l1ToL2MessageSubtreeSiblingPath: this.l1ToL2MessageSubtreeSiblingPath,
|
|
232
|
+
newArchiveSiblingPath: this.newArchiveSiblingPath,
|
|
233
|
+
previousBlockHeader: this.previousBlockHeader,
|
|
234
|
+
proverId
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
async #getBlockRootRollupBlobData() {
|
|
238
|
+
const txEffects = this.txs.map((txProvingState)=>txProvingState.processedTx.txEffect);
|
|
239
|
+
const { blobFields, blobCommitments, blobsHash } = await buildBlobHints(txEffects);
|
|
240
|
+
return BlockRootRollupBlobData.from({
|
|
241
|
+
blobFields: padArrayEnd(blobFields, Fr.ZERO, FIELDS_PER_BLOB * BLOBS_PER_BLOCK),
|
|
242
|
+
blobCommitments: padArrayEnd(blobCommitments, [
|
|
243
|
+
Fr.ZERO,
|
|
244
|
+
Fr.ZERO
|
|
245
|
+
], BLOBS_PER_BLOCK),
|
|
246
|
+
blobsHash
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
#getChildProofsForBlockRoot() {
|
|
250
|
+
if (this.totalNumTxs === 0) {
|
|
251
|
+
return [];
|
|
252
|
+
}
|
|
253
|
+
const rootLocation = {
|
|
254
|
+
level: 0,
|
|
255
|
+
index: 0
|
|
256
|
+
};
|
|
257
|
+
// If there's only 1 tx, its base rollup proof will be stored at the root.
|
|
258
|
+
return this.totalNumTxs === 1 ? [
|
|
259
|
+
this.baseOrMergeProvingOutputs.getNode(rootLocation)
|
|
260
|
+
] : this.baseOrMergeProvingOutputs.getChildren(rootLocation);
|
|
261
|
+
}
|
|
262
|
+
#getPreviousRollupData({ inputs, proof, verificationKey }) {
|
|
263
|
+
const leafIndex = getVKIndex(verificationKey.keyAsFields);
|
|
264
|
+
return new PreviousRollupData(inputs, proof, verificationKey.keyAsFields, new MembershipWitness(VK_TREE_HEIGHT, BigInt(leafIndex), getVKSiblingPath(leafIndex)));
|
|
265
|
+
}
|
|
266
|
+
#getRootParityData({ inputs, proof, verificationKey }) {
|
|
267
|
+
return new RootParityInput(proof, verificationKey.keyAsFields, getVKSiblingPath(getVKIndex(verificationKey)), inputs);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type ARCHIVE_HEIGHT, type L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH } from '@aztec/constants';
|
|
2
|
+
import type { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
import type { Tuple } from '@aztec/foundation/serialize';
|
|
4
|
+
import { type TreeNodeLocation } from '@aztec/foundation/trees';
|
|
5
|
+
import type { ProofAndVerificationKey, PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
|
|
6
|
+
import type { Proof } from '@aztec/stdlib/proofs';
|
|
7
|
+
import { BlockMergeRollupInputs, type BlockRootOrBlockMergePublicInputs, RootRollupInputs, type RootRollupPublicInputs } from '@aztec/stdlib/rollup';
|
|
8
|
+
import type { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
9
|
+
import type { BlockHeader, GlobalVariables } from '@aztec/stdlib/tx';
|
|
10
|
+
import { BlockProvingState } from './block-proving-state.js';
|
|
11
|
+
export type TreeSnapshots = Map<MerkleTreeId, AppendOnlyTreeSnapshot>;
|
|
12
|
+
export type ProvingResult = {
|
|
13
|
+
status: 'success';
|
|
14
|
+
} | {
|
|
15
|
+
status: 'failure';
|
|
16
|
+
reason: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The current state of the proving schedule for an epoch.
|
|
20
|
+
* Contains the raw inputs and intermediate state to generate every constituent proof in the tree.
|
|
21
|
+
* Carries an identifier so we can identify if the proving state is discarded and a new one started.
|
|
22
|
+
* Captures resolve and reject callbacks to provide a promise base interface to the consumer of our proving.
|
|
23
|
+
*/
|
|
24
|
+
export declare class EpochProvingState {
|
|
25
|
+
#private;
|
|
26
|
+
readonly epochNumber: number;
|
|
27
|
+
readonly firstBlockNumber: number;
|
|
28
|
+
readonly totalNumBlocks: number;
|
|
29
|
+
private completionCallback;
|
|
30
|
+
private rejectionCallback;
|
|
31
|
+
private blockRootOrMergeProvingOutputs;
|
|
32
|
+
private paddingBlockRootProvingOutput;
|
|
33
|
+
private rootRollupProvingOutput;
|
|
34
|
+
private provingStateLifecycle;
|
|
35
|
+
readonly cachedTubeProofs: Map<string, Promise<ProofAndVerificationKey<538>>>;
|
|
36
|
+
blocks: (BlockProvingState | undefined)[];
|
|
37
|
+
constructor(epochNumber: number, firstBlockNumber: number, totalNumBlocks: number, completionCallback: (result: ProvingResult) => void, rejectionCallback: (reason: string) => void);
|
|
38
|
+
startNewBlock(globalVariables: GlobalVariables, l1ToL2Messages: Fr[], l1ToL2MessageSubtreeSiblingPath: Tuple<Fr, typeof L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH>, l1ToL2MessageTreeSnapshotAfterInsertion: AppendOnlyTreeSnapshot, lastArchiveSnapshot: AppendOnlyTreeSnapshot, newArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>, previousBlockHeader: BlockHeader): BlockProvingState;
|
|
39
|
+
verifyState(): boolean;
|
|
40
|
+
isAcceptingBlocks(): boolean;
|
|
41
|
+
setBlockRootRollupProof(blockIndex: number, proof: PublicInputsAndRecursiveProof<BlockRootOrBlockMergePublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>): TreeNodeLocation;
|
|
42
|
+
setBlockMergeRollupProof(location: TreeNodeLocation, proof: PublicInputsAndRecursiveProof<BlockRootOrBlockMergePublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>): void;
|
|
43
|
+
setRootRollupProof(proof: PublicInputsAndRecursiveProof<RootRollupPublicInputs>): void;
|
|
44
|
+
setPaddingBlockRootProof(proof: PublicInputsAndRecursiveProof<BlockRootOrBlockMergePublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>): void;
|
|
45
|
+
getParentLocation(location: TreeNodeLocation): TreeNodeLocation;
|
|
46
|
+
getBlockMergeRollupInputs(mergeLocation: TreeNodeLocation): BlockMergeRollupInputs;
|
|
47
|
+
getRootRollupInputs(proverId: Fr): RootRollupInputs;
|
|
48
|
+
getPaddingBlockRootInputs(proverId: Fr): Promise<import("@aztec/stdlib/rollup").EmptyBlockRootRollupInputs>;
|
|
49
|
+
getBlockProvingStateByBlockNumber(blockNumber: number): BlockProvingState | undefined;
|
|
50
|
+
getEpochProofResult(): {
|
|
51
|
+
proof: Proof;
|
|
52
|
+
publicInputs: RootRollupPublicInputs;
|
|
53
|
+
};
|
|
54
|
+
isReadyForBlockMerge(location: TreeNodeLocation): boolean;
|
|
55
|
+
isReadyForRootRollup(): boolean;
|
|
56
|
+
cancel(): void;
|
|
57
|
+
reject(reason: string): void;
|
|
58
|
+
resolve(result: ProvingResult): void;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=epoch-proving-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"epoch-proving-state.d.ts","sourceRoot":"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EAAE,MAAM;IAIrD,mBAAmB,IAAI;QAAE,KAAK,EAAE,KAAK,CAAC;QAAC,YAAY,EAAE,sBAAsB,CAAA;KAAE;IAW7E,oBAAoB,CAAC,QAAQ,EAAE,gBAAgB;IAK/C,oBAAoB;IAMpB,MAAM;IAMN,MAAM,CAAC,MAAM,EAAE,MAAM;IAUrB,OAAO,CAAC,MAAM,EAAE,aAAa;CAgCrC"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { VK_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
+
import { MembershipWitness, UnbalancedTreeStore } from '@aztec/foundation/trees';
|
|
3
|
+
import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
4
|
+
import { BlockMergeRollupInputs, PreviousRollupBlockData, RootRollupInputs } from '@aztec/stdlib/rollup';
|
|
5
|
+
import { BlockProvingState } from './block-proving-state.js';
|
|
6
|
+
var PROVING_STATE_LIFECYCLE = /*#__PURE__*/ function(PROVING_STATE_LIFECYCLE) {
|
|
7
|
+
PROVING_STATE_LIFECYCLE[PROVING_STATE_LIFECYCLE["PROVING_STATE_CREATED"] = 0] = "PROVING_STATE_CREATED";
|
|
8
|
+
PROVING_STATE_LIFECYCLE[PROVING_STATE_LIFECYCLE["PROVING_STATE_FULL"] = 1] = "PROVING_STATE_FULL";
|
|
9
|
+
PROVING_STATE_LIFECYCLE[PROVING_STATE_LIFECYCLE["PROVING_STATE_RESOLVED"] = 2] = "PROVING_STATE_RESOLVED";
|
|
10
|
+
PROVING_STATE_LIFECYCLE[PROVING_STATE_LIFECYCLE["PROVING_STATE_REJECTED"] = 3] = "PROVING_STATE_REJECTED";
|
|
11
|
+
return PROVING_STATE_LIFECYCLE;
|
|
12
|
+
}(PROVING_STATE_LIFECYCLE || {});
|
|
13
|
+
/**
|
|
14
|
+
* The current state of the proving schedule for an epoch.
|
|
15
|
+
* Contains the raw inputs and intermediate state to generate every constituent proof in the tree.
|
|
16
|
+
* Carries an identifier so we can identify if the proving state is discarded and a new one started.
|
|
17
|
+
* Captures resolve and reject callbacks to provide a promise base interface to the consumer of our proving.
|
|
18
|
+
*/ export class EpochProvingState {
|
|
19
|
+
epochNumber;
|
|
20
|
+
firstBlockNumber;
|
|
21
|
+
totalNumBlocks;
|
|
22
|
+
completionCallback;
|
|
23
|
+
rejectionCallback;
|
|
24
|
+
blockRootOrMergeProvingOutputs;
|
|
25
|
+
paddingBlockRootProvingOutput;
|
|
26
|
+
rootRollupProvingOutput;
|
|
27
|
+
provingStateLifecycle;
|
|
28
|
+
// Map from tx hash to tube proof promise. Used when kickstarting tube proofs before tx processing.
|
|
29
|
+
cachedTubeProofs;
|
|
30
|
+
blocks;
|
|
31
|
+
constructor(epochNumber, firstBlockNumber, totalNumBlocks, completionCallback, rejectionCallback){
|
|
32
|
+
this.epochNumber = epochNumber;
|
|
33
|
+
this.firstBlockNumber = firstBlockNumber;
|
|
34
|
+
this.totalNumBlocks = totalNumBlocks;
|
|
35
|
+
this.completionCallback = completionCallback;
|
|
36
|
+
this.rejectionCallback = rejectionCallback;
|
|
37
|
+
this.provingStateLifecycle = 0;
|
|
38
|
+
this.cachedTubeProofs = new Map();
|
|
39
|
+
this.blocks = [];
|
|
40
|
+
this.blockRootOrMergeProvingOutputs = new UnbalancedTreeStore(totalNumBlocks);
|
|
41
|
+
}
|
|
42
|
+
// Adds a block to the proving state, returns its index
|
|
43
|
+
// Will update the proving life cycle if this is the last block
|
|
44
|
+
startNewBlock(globalVariables, l1ToL2Messages, l1ToL2MessageSubtreeSiblingPath, l1ToL2MessageTreeSnapshotAfterInsertion, lastArchiveSnapshot, newArchiveSiblingPath, previousBlockHeader) {
|
|
45
|
+
const index = globalVariables.blockNumber.toNumber() - this.firstBlockNumber;
|
|
46
|
+
const block = new BlockProvingState(index, globalVariables, l1ToL2Messages, l1ToL2MessageSubtreeSiblingPath, l1ToL2MessageTreeSnapshotAfterInsertion, lastArchiveSnapshot, newArchiveSiblingPath, previousBlockHeader, this);
|
|
47
|
+
this.blocks[index] = block;
|
|
48
|
+
if (this.blocks.filter((b)=>!!b).length === this.totalNumBlocks) {
|
|
49
|
+
this.provingStateLifecycle = 1;
|
|
50
|
+
}
|
|
51
|
+
return block;
|
|
52
|
+
}
|
|
53
|
+
// Returns true if this proving state is still valid, false otherwise
|
|
54
|
+
verifyState() {
|
|
55
|
+
return this.provingStateLifecycle === 0 || this.provingStateLifecycle === 1;
|
|
56
|
+
}
|
|
57
|
+
// Returns true if we are still able to accept blocks, false otherwise
|
|
58
|
+
isAcceptingBlocks() {
|
|
59
|
+
return this.provingStateLifecycle === 0;
|
|
60
|
+
}
|
|
61
|
+
setBlockRootRollupProof(blockIndex, proof) {
|
|
62
|
+
return this.blockRootOrMergeProvingOutputs.setLeaf(blockIndex, proof);
|
|
63
|
+
}
|
|
64
|
+
setBlockMergeRollupProof(location, proof) {
|
|
65
|
+
this.blockRootOrMergeProvingOutputs.setNode(location, proof);
|
|
66
|
+
}
|
|
67
|
+
setRootRollupProof(proof) {
|
|
68
|
+
this.rootRollupProvingOutput = proof;
|
|
69
|
+
}
|
|
70
|
+
setPaddingBlockRootProof(proof) {
|
|
71
|
+
this.paddingBlockRootProvingOutput = proof;
|
|
72
|
+
}
|
|
73
|
+
getParentLocation(location) {
|
|
74
|
+
return this.blockRootOrMergeProvingOutputs.getParentLocation(location);
|
|
75
|
+
}
|
|
76
|
+
getBlockMergeRollupInputs(mergeLocation) {
|
|
77
|
+
const [left, right] = this.blockRootOrMergeProvingOutputs.getChildren(mergeLocation);
|
|
78
|
+
if (!left || !right) {
|
|
79
|
+
throw new Error('At lease one child is not ready.');
|
|
80
|
+
}
|
|
81
|
+
return new BlockMergeRollupInputs([
|
|
82
|
+
this.#getPreviousRollupData(left),
|
|
83
|
+
this.#getPreviousRollupData(right)
|
|
84
|
+
]);
|
|
85
|
+
}
|
|
86
|
+
getRootRollupInputs(proverId) {
|
|
87
|
+
const [left, right] = this.#getChildProofsForRoot();
|
|
88
|
+
if (!left || !right) {
|
|
89
|
+
throw new Error('At lease one child is not ready.');
|
|
90
|
+
}
|
|
91
|
+
return RootRollupInputs.from({
|
|
92
|
+
previousRollupData: [
|
|
93
|
+
this.#getPreviousRollupData(left),
|
|
94
|
+
this.#getPreviousRollupData(right)
|
|
95
|
+
],
|
|
96
|
+
proverId
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
getPaddingBlockRootInputs(proverId) {
|
|
100
|
+
if (!this.blocks[0]?.isComplete()) {
|
|
101
|
+
throw new Error('Epoch needs one completed block in order to be padded.');
|
|
102
|
+
}
|
|
103
|
+
return this.blocks[0].getPaddingBlockRootInputs(proverId);
|
|
104
|
+
}
|
|
105
|
+
// Returns a specific transaction proving state
|
|
106
|
+
getBlockProvingStateByBlockNumber(blockNumber) {
|
|
107
|
+
return this.blocks.find((block)=>block?.blockNumber === blockNumber);
|
|
108
|
+
}
|
|
109
|
+
getEpochProofResult() {
|
|
110
|
+
if (!this.rootRollupProvingOutput) {
|
|
111
|
+
throw new Error('Unable to get epoch proof result. Root rollup is not ready.');
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
proof: this.rootRollupProvingOutput.proof.binaryProof,
|
|
115
|
+
publicInputs: this.rootRollupProvingOutput.inputs
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
isReadyForBlockMerge(location) {
|
|
119
|
+
return this.blockRootOrMergeProvingOutputs.getSibling(location) !== undefined;
|
|
120
|
+
}
|
|
121
|
+
// Returns true if we have sufficient inputs to execute the block root rollup
|
|
122
|
+
isReadyForRootRollup() {
|
|
123
|
+
const childProofs = this.#getChildProofsForRoot();
|
|
124
|
+
return childProofs.every((p)=>!!p);
|
|
125
|
+
}
|
|
126
|
+
// Attempts to reject the proving state promise with a reason of 'cancelled'
|
|
127
|
+
cancel() {
|
|
128
|
+
this.reject('Proving cancelled');
|
|
129
|
+
}
|
|
130
|
+
// Attempts to reject the proving state promise with the given reason
|
|
131
|
+
// Does nothing if not in a valid state
|
|
132
|
+
reject(reason) {
|
|
133
|
+
if (!this.verifyState()) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
this.provingStateLifecycle = 3;
|
|
137
|
+
this.rejectionCallback(reason);
|
|
138
|
+
}
|
|
139
|
+
// Attempts to resolve the proving state promise with the given result
|
|
140
|
+
// Does nothing if not in a valid state
|
|
141
|
+
resolve(result) {
|
|
142
|
+
if (!this.verifyState()) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
this.provingStateLifecycle = 2;
|
|
146
|
+
this.completionCallback(result);
|
|
147
|
+
}
|
|
148
|
+
#getChildProofsForRoot() {
|
|
149
|
+
const rootLocation = {
|
|
150
|
+
level: 0,
|
|
151
|
+
index: 0
|
|
152
|
+
};
|
|
153
|
+
// If there's only 1 block, its block root proof will be stored at the root.
|
|
154
|
+
return this.totalNumBlocks === 1 ? [
|
|
155
|
+
this.blockRootOrMergeProvingOutputs.getNode(rootLocation),
|
|
156
|
+
this.paddingBlockRootProvingOutput
|
|
157
|
+
] : this.blockRootOrMergeProvingOutputs.getChildren(rootLocation);
|
|
158
|
+
}
|
|
159
|
+
#getPreviousRollupData({ inputs, proof, verificationKey }) {
|
|
160
|
+
const leafIndex = getVKIndex(verificationKey.keyAsFields);
|
|
161
|
+
return new PreviousRollupBlockData(inputs, proof, verificationKey.keyAsFields, new MembershipWitness(VK_TREE_HEIGHT, BigInt(leafIndex), getVKSiblingPath(leafIndex)));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/orchestrator/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ProvingOrchestrator } from './orchestrator.js';
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { L2Block } from '@aztec/stdlib/block';
|
|
3
|
+
import type { EpochProver, ForkMerkleTreeOperations, ServerCircuitProver } from '@aztec/stdlib/interfaces/server';
|
|
4
|
+
import { type AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
|
|
5
|
+
import { type BlockHeader, type GlobalVariables, type ProcessedTx, type Tx } from '@aztec/stdlib/tx';
|
|
6
|
+
import { type TelemetryClient, type Tracer } from '@aztec/telemetry-client';
|
|
7
|
+
/**
|
|
8
|
+
* Implements an event driven proving scheduler to build the recursive proof tree. The idea being:
|
|
9
|
+
* 1. Transactions are provided to the scheduler post simulation.
|
|
10
|
+
* 2. Tree insertions are performed as required to generate transaction specific proofs
|
|
11
|
+
* 3. Those transaction specific proofs are generated in the necessary order accounting for dependencies
|
|
12
|
+
* 4. Once a transaction is proven, it will be incorporated into a merge proof
|
|
13
|
+
* 5. Merge proofs are produced at each level of the tree until the root proof is produced
|
|
14
|
+
*
|
|
15
|
+
* The proving implementation is determined by the provided prover. This could be for example a local prover or a remote prover pool.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* The orchestrator, managing the flow of recursive proving operations required to build the rollup proof tree.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ProvingOrchestrator implements EpochProver {
|
|
21
|
+
private dbProvider;
|
|
22
|
+
private prover;
|
|
23
|
+
private readonly proverId;
|
|
24
|
+
private provingState;
|
|
25
|
+
private pendingProvingJobs;
|
|
26
|
+
private provingPromise;
|
|
27
|
+
private metrics;
|
|
28
|
+
private dbs;
|
|
29
|
+
constructor(dbProvider: ForkMerkleTreeOperations, prover: ServerCircuitProver, proverId?: Fr, telemetryClient?: TelemetryClient);
|
|
30
|
+
get tracer(): Tracer;
|
|
31
|
+
getProverId(): Fr;
|
|
32
|
+
stop(): Promise<void>;
|
|
33
|
+
startNewEpoch(epochNumber: number, firstBlockNumber: number, totalNumBlocks: number): void;
|
|
34
|
+
/**
|
|
35
|
+
* Starts off a new block
|
|
36
|
+
* @param globalVariables - The global variables for the block
|
|
37
|
+
* @param l1ToL2Messages - The l1 to l2 messages for the block
|
|
38
|
+
* @returns A proving ticket, containing a promise notifying of proving completion
|
|
39
|
+
*/
|
|
40
|
+
startNewBlock(globalVariables: GlobalVariables, l1ToL2Messages: Fr[], previousBlockHeader: BlockHeader): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* The interface to add simulated transactions to the scheduler. This can only be called once per block.
|
|
43
|
+
* @param txs - The transactions to be proven
|
|
44
|
+
*/
|
|
45
|
+
addTxs(txs: ProcessedTx[]): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Kickstarts tube circuits for the specified txs. These will be used during epoch proving.
|
|
48
|
+
* Note that if the tube circuits are not started this way, they will be started nontheless after processing.
|
|
49
|
+
*/
|
|
50
|
+
startTubeCircuits(txs: Tx[]): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Marks the block as completed.
|
|
53
|
+
* Computes the block header and updates the archive tree.
|
|
54
|
+
*/
|
|
55
|
+
setBlockCompleted(blockNumber: number, expectedHeader?: BlockHeader): Promise<L2Block>;
|
|
56
|
+
/** Returns the block as built for a given index. */
|
|
57
|
+
getBlock(index: number): L2Block;
|
|
58
|
+
private buildBlock;
|
|
59
|
+
protected verifyBuiltBlockAgainstSyncedState(l2Block: L2Block, newArchive: AppendOnlyTreeSnapshot): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Cancel any further proving
|
|
62
|
+
*/
|
|
63
|
+
cancel(): void;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the proof for the current epoch.
|
|
66
|
+
*/
|
|
67
|
+
finaliseEpoch(): Promise<{
|
|
68
|
+
proof: import("@aztec/stdlib/proofs").Proof;
|
|
69
|
+
publicInputs: import("@aztec/stdlib/rollup").RootRollupPublicInputs;
|
|
70
|
+
}>;
|
|
71
|
+
/**
|
|
72
|
+
* Starts the proving process for the given transaction and adds it to our state
|
|
73
|
+
* @param tx - The transaction whose proving we wish to commence
|
|
74
|
+
* @param provingState - The proving state being worked on
|
|
75
|
+
*/
|
|
76
|
+
private prepareTransaction;
|
|
77
|
+
/**
|
|
78
|
+
* Enqueue a job to be scheduled
|
|
79
|
+
* @param provingState - The proving state object being operated on
|
|
80
|
+
* @param jobType - The type of job to be queued
|
|
81
|
+
* @param job - The actual job, returns a promise notifying of the job's completion
|
|
82
|
+
*/
|
|
83
|
+
private deferredProving;
|
|
84
|
+
private prepareBaseParityInputs;
|
|
85
|
+
private prepareBaseRollupInputs;
|
|
86
|
+
private enqueueBaseRollup;
|
|
87
|
+
private getOrEnqueueTube;
|
|
88
|
+
private doEnqueueTube;
|
|
89
|
+
private enqueueMergeRollup;
|
|
90
|
+
private enqueueBlockRootRollup;
|
|
91
|
+
private enqueueBaseParityCircuit;
|
|
92
|
+
private checkAndEnqueueRootParityCircuit;
|
|
93
|
+
private enqueueRootParityCircuit;
|
|
94
|
+
private enqueueBlockMergeRollup;
|
|
95
|
+
private enqueueEpochPadding;
|
|
96
|
+
private enqueueRootRollup;
|
|
97
|
+
private checkAndEnqueueNextMergeRollup;
|
|
98
|
+
private checkAndEnqueueBlockRootRollup;
|
|
99
|
+
private checkAndEnqueueNextBlockMergeRollup;
|
|
100
|
+
private checkAndEnqueueRootRollup;
|
|
101
|
+
/**
|
|
102
|
+
* Executes the VM circuit for a public function, will enqueue the corresponding kernel if the
|
|
103
|
+
* previous kernel is ready
|
|
104
|
+
* @param provingState - The proving state being operated on
|
|
105
|
+
* @param txIndex - The index of the transaction being proven
|
|
106
|
+
*/
|
|
107
|
+
private enqueueVM;
|
|
108
|
+
private checkAndEnqueueNextTxCircuit;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=orchestrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../src/orchestrator/orchestrator.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAQ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