@aztec/prover-client 0.0.0-test.1 → 0.0.1-commit.21caa21
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/block-factory/index.d.ts +2 -0
- package/dest/block-factory/index.d.ts.map +1 -0
- package/dest/block-factory/light.d.ts +38 -0
- package/dest/block-factory/light.d.ts.map +1 -0
- package/dest/block-factory/light.js +108 -0
- package/dest/config.d.ts +7 -7
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +11 -1
- package/dest/index.d.ts +1 -1
- package/dest/light/lightweight_checkpoint_builder.d.ts +28 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
- package/dest/light/lightweight_checkpoint_builder.js +107 -0
- package/dest/mocks/fixtures.d.ts +8 -8
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +32 -14
- package/dest/mocks/test_context.d.ts +40 -31
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +134 -86
- package/dest/orchestrator/block-building-helpers.d.ts +36 -29
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +168 -188
- package/dest/orchestrator/block-proving-state.d.ts +68 -47
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +281 -176
- package/dest/orchestrator/checkpoint-proving-state.d.ts +62 -0
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/checkpoint-proving-state.js +208 -0
- package/dest/orchestrator/epoch-proving-state.d.ts +40 -26
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +143 -73
- package/dest/orchestrator/index.d.ts +1 -1
- package/dest/orchestrator/orchestrator.d.ts +35 -32
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +389 -239
- package/dest/orchestrator/orchestrator_metrics.d.ts +3 -1
- package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator_metrics.js +9 -0
- package/dest/orchestrator/tx-proving-state.d.ts +13 -11
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +23 -40
- package/dest/prover-client/factory.d.ts +1 -1
- package/dest/prover-client/index.d.ts +1 -1
- package/dest/prover-client/prover-client.d.ts +4 -4
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +5 -4
- package/dest/prover-client/server-epoch-prover.d.ts +15 -11
- package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
- package/dest/prover-client/server-epoch-prover.js +11 -11
- package/dest/proving_broker/broker_prover_facade.d.ts +23 -16
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +67 -41
- package/dest/proving_broker/config.d.ts +18 -9
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +22 -5
- package/dest/proving_broker/factory.d.ts +2 -2
- package/dest/proving_broker/factory.d.ts.map +1 -1
- package/dest/proving_broker/factory.js +5 -1
- package/dest/proving_broker/fixtures.d.ts +3 -2
- package/dest/proving_broker/fixtures.d.ts.map +1 -1
- package/dest/proving_broker/fixtures.js +2 -1
- package/dest/proving_broker/index.d.ts +1 -1
- package/dest/proving_broker/proof_store/factory.d.ts +2 -2
- package/dest/proving_broker/proof_store/factory.js +1 -1
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +1 -1
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/gcs_proof_store.js +1 -0
- package/dest/proving_broker/proof_store/index.d.ts +2 -1
- package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/index.js +1 -0
- package/dest/proving_broker/proof_store/inline_proof_store.d.ts +1 -1
- package/dest/proving_broker/proof_store/inline_proof_store.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/proof_store.d.ts +1 -1
- package/dest/proving_broker/proving_agent.d.ts +4 -4
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent.js +83 -47
- package/dest/proving_broker/proving_agent_instrumentation.d.ts +1 -1
- package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.d.ts +13 -4
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +36 -23
- package/dest/proving_broker/proving_broker_database/memory.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/memory.js +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.js +12 -10
- package/dest/proving_broker/proving_broker_database.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
- package/dest/proving_broker/proving_job_controller.d.ts +9 -9
- package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
- package/dest/proving_broker/proving_job_controller.js +89 -61
- package/dest/proving_broker/rpc.d.ts +4 -6
- package/dest/proving_broker/rpc.d.ts.map +1 -1
- package/dest/proving_broker/rpc.js +1 -4
- package/dest/test/mock_proof_store.d.ts +9 -0
- package/dest/test/mock_proof_store.d.ts.map +1 -0
- package/dest/test/mock_proof_store.js +10 -0
- package/dest/test/mock_prover.d.ts +23 -17
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +38 -20
- package/package.json +32 -31
- package/src/block-factory/index.ts +1 -0
- package/src/block-factory/light.ts +137 -0
- package/src/config.ts +24 -8
- package/src/light/lightweight_checkpoint_builder.ts +142 -0
- package/src/mocks/fixtures.ts +42 -37
- package/src/mocks/test_context.ts +207 -115
- package/src/orchestrator/block-building-helpers.ts +256 -333
- package/src/orchestrator/block-proving-state.ts +323 -230
- package/src/orchestrator/checkpoint-proving-state.ts +301 -0
- package/src/orchestrator/epoch-proving-state.ts +187 -112
- package/src/orchestrator/orchestrator.ts +592 -299
- package/src/orchestrator/orchestrator_metrics.ts +20 -1
- package/src/orchestrator/tx-proving-state.ts +50 -64
- package/src/prover-client/prover-client.ts +16 -14
- package/src/prover-client/server-epoch-prover.ts +39 -21
- package/src/proving_broker/broker_prover_facade.ts +214 -126
- package/src/proving_broker/config.ts +24 -6
- package/src/proving_broker/factory.ts +2 -1
- package/src/proving_broker/fixtures.ts +7 -2
- package/src/proving_broker/proof_store/factory.ts +1 -1
- package/src/proving_broker/proof_store/gcs_proof_store.ts +5 -1
- package/src/proving_broker/proof_store/index.ts +1 -0
- package/src/proving_broker/proof_store/inline_proof_store.ts +1 -1
- package/src/proving_broker/proving_agent.ts +89 -47
- package/src/proving_broker/proving_broker.ts +53 -33
- package/src/proving_broker/proving_broker_database/memory.ts +3 -2
- package/src/proving_broker/proving_broker_database/persisted.ts +14 -12
- package/src/proving_broker/proving_broker_database.ts +2 -1
- package/src/proving_broker/proving_job_controller.ts +94 -82
- package/src/proving_broker/rpc.ts +1 -6
- package/src/test/mock_proof_store.ts +14 -0
- package/src/test/mock_prover.ts +164 -60
- package/dest/bin/get-proof-inputs.d.ts +0 -2
- package/dest/bin/get-proof-inputs.d.ts.map +0 -1
- package/dest/bin/get-proof-inputs.js +0 -51
- package/dest/block_builder/index.d.ts +0 -6
- package/dest/block_builder/index.d.ts.map +0 -1
- package/dest/block_builder/light.d.ts +0 -33
- package/dest/block_builder/light.d.ts.map +0 -1
- package/dest/block_builder/light.js +0 -82
- package/src/bin/get-proof-inputs.ts +0 -59
- package/src/block_builder/index.ts +0 -6
- package/src/block_builder/light.ts +0 -101
- /package/dest/{block_builder → block-factory}/index.js +0 -0
|
@@ -1,56 +1,63 @@
|
|
|
1
1
|
import type { BBProverConfig } from '@aztec/bb-prover';
|
|
2
|
-
import {
|
|
2
|
+
import { TestCircuitProver } from '@aztec/bb-prover';
|
|
3
|
+
import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
4
|
+
import { padArrayEnd, times, timesAsync } from '@aztec/foundation/collection';
|
|
3
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
4
6
|
import type { Logger } from '@aztec/foundation/log';
|
|
5
|
-
import {
|
|
7
|
+
import type { FieldsOf } from '@aztec/foundation/types';
|
|
6
8
|
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
7
|
-
import {
|
|
9
|
+
import { ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
8
10
|
import { computeFeePayerBalanceLeafSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
9
|
-
import {
|
|
10
|
-
PublicProcessor,
|
|
11
|
-
PublicTxSimulationTester,
|
|
12
|
-
PublicTxSimulator,
|
|
13
|
-
SimpleContractDataSource,
|
|
14
|
-
WorldStateDB,
|
|
15
|
-
} from '@aztec/simulator/server';
|
|
16
11
|
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
17
12
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
18
|
-
import
|
|
19
|
-
import type {
|
|
20
|
-
import {
|
|
21
|
-
import
|
|
22
|
-
import {
|
|
13
|
+
import { EthAddress } from '@aztec/stdlib/block';
|
|
14
|
+
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
15
|
+
import type { MerkleTreeWriteOperations, ServerCircuitProver } from '@aztec/stdlib/interfaces/server';
|
|
16
|
+
import type { CheckpointConstantData } from '@aztec/stdlib/rollup';
|
|
17
|
+
import { mockProcessedTx } from '@aztec/stdlib/testing';
|
|
18
|
+
import { MerkleTreeId, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
19
|
+
import {
|
|
20
|
+
type BlockHeader,
|
|
21
|
+
type GlobalVariables,
|
|
22
|
+
type ProcessedTx,
|
|
23
|
+
StateReference,
|
|
24
|
+
TreeSnapshots,
|
|
25
|
+
} from '@aztec/stdlib/tx';
|
|
23
26
|
import type { MerkleTreeAdminDatabase } from '@aztec/world-state';
|
|
24
27
|
import { NativeWorldStateService } from '@aztec/world-state/native';
|
|
25
28
|
|
|
26
29
|
import { promises as fs } from 'fs';
|
|
27
30
|
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
31
|
+
import { LightweightCheckpointBuilder } from '../light/lightweight_checkpoint_builder.js';
|
|
32
|
+
import {
|
|
33
|
+
buildFinalBlobChallenges,
|
|
34
|
+
getTreeSnapshot,
|
|
35
|
+
insertSideEffects,
|
|
36
|
+
} from '../orchestrator/block-building-helpers.js';
|
|
37
|
+
import type { BlockProvingState } from '../orchestrator/block-proving-state.js';
|
|
30
38
|
import { ProvingOrchestrator } from '../orchestrator/index.js';
|
|
31
39
|
import { BrokerCircuitProverFacade } from '../proving_broker/broker_prover_facade.js';
|
|
32
40
|
import { TestBroker } from '../test/mock_prover.js';
|
|
33
|
-
import { getEnvironmentConfig,
|
|
41
|
+
import { getEnvironmentConfig, getSimulator, makeCheckpointConstants, makeGlobals } from './fixtures.js';
|
|
34
42
|
|
|
35
43
|
export class TestContext {
|
|
36
44
|
private headers: Map<number, BlockHeader> = new Map();
|
|
45
|
+
private checkpoints: Checkpoint[] = [];
|
|
46
|
+
private nextCheckpointIndex = 0;
|
|
47
|
+
private nextBlockNumber = 1;
|
|
48
|
+
private epochNumber = 1;
|
|
37
49
|
private feePayerBalance: Fr;
|
|
38
50
|
|
|
39
51
|
constructor(
|
|
40
|
-
public publicTxSimulator: PublicTxSimulator,
|
|
41
52
|
public worldState: MerkleTreeAdminDatabase,
|
|
42
|
-
public publicProcessor: PublicProcessor,
|
|
43
|
-
public globalVariables: GlobalVariables,
|
|
44
53
|
public prover: ServerCircuitProver,
|
|
45
54
|
public broker: TestBroker,
|
|
46
55
|
public brokerProverFacade: BrokerCircuitProverFacade,
|
|
47
56
|
public orchestrator: TestProvingOrchestrator,
|
|
48
|
-
|
|
49
|
-
public feePayer: AztecAddress,
|
|
57
|
+
private feePayer: AztecAddress,
|
|
50
58
|
initialFeePayerBalance: Fr,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
public logger: Logger,
|
|
59
|
+
private directoriesToCleanup: string[],
|
|
60
|
+
private logger: Logger,
|
|
54
61
|
) {
|
|
55
62
|
this.feePayerBalance = initialFeePayerBalance;
|
|
56
63
|
}
|
|
@@ -61,13 +68,15 @@ export class TestContext {
|
|
|
61
68
|
|
|
62
69
|
static async new(
|
|
63
70
|
logger: Logger,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
new TestCircuitProver(await
|
|
67
|
-
|
|
71
|
+
{
|
|
72
|
+
proverCount = 4,
|
|
73
|
+
createProver = async (bbConfig: BBProverConfig) => new TestCircuitProver(await getSimulator(bbConfig, logger)),
|
|
74
|
+
}: {
|
|
75
|
+
proverCount?: number;
|
|
76
|
+
createProver?: (bbConfig: BBProverConfig) => Promise<ServerCircuitProver>;
|
|
77
|
+
} = {},
|
|
68
78
|
) {
|
|
69
79
|
const directoriesToCleanup: string[] = [];
|
|
70
|
-
const globalVariables = makeGlobals(blockNumber);
|
|
71
80
|
|
|
72
81
|
const feePayer = AztecAddress.fromNumber(42222);
|
|
73
82
|
const initialFeePayerBalance = new Fr(10n ** 20n);
|
|
@@ -76,25 +85,10 @@ export class TestContext {
|
|
|
76
85
|
|
|
77
86
|
// Separated dbs for public processor and prover - see public_processor for context
|
|
78
87
|
const ws = await NativeWorldStateService.tmp(
|
|
79
|
-
|
|
80
|
-
|
|
88
|
+
/*rollupAddress=*/ undefined,
|
|
89
|
+
/*cleanupTmpDir=*/ true,
|
|
81
90
|
prefilledPublicData,
|
|
82
91
|
);
|
|
83
|
-
const publicDb = await ws.fork();
|
|
84
|
-
|
|
85
|
-
const contractDataSource = new SimpleContractDataSource();
|
|
86
|
-
const worldStateDB = new WorldStateDB(publicDb, contractDataSource);
|
|
87
|
-
|
|
88
|
-
const tester = new PublicTxSimulationTester(worldStateDB, contractDataSource, publicDb);
|
|
89
|
-
|
|
90
|
-
const publicTxSimulator = new PublicTxSimulator(publicDb, worldStateDB, globalVariables, true);
|
|
91
|
-
const processor = new PublicProcessor(
|
|
92
|
-
publicDb,
|
|
93
|
-
globalVariables,
|
|
94
|
-
worldStateDB,
|
|
95
|
-
publicTxSimulator,
|
|
96
|
-
new TestDateProvider(),
|
|
97
|
-
);
|
|
98
92
|
|
|
99
93
|
let localProver: ServerCircuitProver;
|
|
100
94
|
const config = await getEnvironmentConfig(logger);
|
|
@@ -107,6 +101,8 @@ export class TestContext {
|
|
|
107
101
|
bbBinaryPath: config.expectedBBPath,
|
|
108
102
|
bbWorkingDirectory: config.bbWorkingDirectory,
|
|
109
103
|
bbSkipCleanup: config.bbSkipCleanup,
|
|
104
|
+
numConcurrentIVCVerifiers: 2,
|
|
105
|
+
bbIVCConcurrency: 1,
|
|
110
106
|
};
|
|
111
107
|
localProver = await createProver(bbConfig);
|
|
112
108
|
}
|
|
@@ -117,25 +113,20 @@ export class TestContext {
|
|
|
117
113
|
|
|
118
114
|
const broker = new TestBroker(proverCount, localProver);
|
|
119
115
|
const facade = new BrokerCircuitProverFacade(broker);
|
|
120
|
-
const orchestrator = new TestProvingOrchestrator(ws, facade,
|
|
116
|
+
const orchestrator = new TestProvingOrchestrator(ws, facade, EthAddress.ZERO);
|
|
121
117
|
|
|
122
118
|
await broker.start();
|
|
123
119
|
facade.start();
|
|
124
120
|
|
|
125
121
|
return new this(
|
|
126
|
-
publicTxSimulator,
|
|
127
122
|
ws,
|
|
128
|
-
processor,
|
|
129
|
-
globalVariables,
|
|
130
123
|
localProver,
|
|
131
124
|
broker,
|
|
132
125
|
facade,
|
|
133
126
|
orchestrator,
|
|
134
|
-
blockNumber,
|
|
135
127
|
feePayer,
|
|
136
128
|
initialFeePayerBalance,
|
|
137
129
|
directoriesToCleanup,
|
|
138
|
-
tester,
|
|
139
130
|
logger,
|
|
140
131
|
);
|
|
141
132
|
}
|
|
@@ -144,16 +135,6 @@ export class TestContext {
|
|
|
144
135
|
return this.worldState.fork();
|
|
145
136
|
}
|
|
146
137
|
|
|
147
|
-
public getBlockHeader(blockNumber: 0): BlockHeader;
|
|
148
|
-
public getBlockHeader(blockNumber: number): BlockHeader | undefined;
|
|
149
|
-
public getBlockHeader(blockNumber = 0) {
|
|
150
|
-
return blockNumber === 0 ? this.worldState.getCommitted().getInitialHeader() : this.headers.get(blockNumber);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
public getPreviousBlockHeader(currentBlockNumber = this.blockNumber): BlockHeader {
|
|
154
|
-
return this.getBlockHeader(currentBlockNumber - 1)!;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
138
|
async cleanup() {
|
|
158
139
|
await this.brokerProverFacade.stop();
|
|
159
140
|
await this.broker.stop();
|
|
@@ -166,77 +147,191 @@ export class TestContext {
|
|
|
166
147
|
}
|
|
167
148
|
}
|
|
168
149
|
|
|
169
|
-
public
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
150
|
+
public startNewEpoch() {
|
|
151
|
+
this.checkpoints = [];
|
|
152
|
+
this.nextCheckpointIndex = 0;
|
|
153
|
+
this.epochNumber++;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Return blob fields of all checkpoints in the epoch.
|
|
157
|
+
public getBlobFields() {
|
|
158
|
+
return this.checkpoints.map(checkpoint => checkpoint.toBlobFields());
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
public async getFinalBlobChallenges() {
|
|
162
|
+
const blobFields = this.getBlobFields();
|
|
163
|
+
return await buildFinalBlobChallenges(blobFields);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
public async makeCheckpoint(
|
|
167
|
+
numBlocks: number,
|
|
168
|
+
{
|
|
169
|
+
numTxsPerBlock = 0,
|
|
170
|
+
numL1ToL2Messages = 0,
|
|
171
|
+
makeProcessedTxOpts = () => ({}),
|
|
172
|
+
...constantOpts
|
|
173
|
+
}: {
|
|
174
|
+
numTxsPerBlock?: number | number[];
|
|
175
|
+
numL1ToL2Messages?: number;
|
|
176
|
+
makeProcessedTxOpts?: (
|
|
177
|
+
blockGlobalVariables: GlobalVariables,
|
|
178
|
+
txIndex: number,
|
|
179
|
+
) => Partial<Parameters<typeof mockProcessedTx>[0]>;
|
|
180
|
+
} & Partial<FieldsOf<CheckpointConstantData>> = {},
|
|
181
|
+
) {
|
|
182
|
+
if (numBlocks === 0) {
|
|
183
|
+
throw new Error(
|
|
184
|
+
'Cannot make a checkpoint with 0 blocks. Crate an empty block (numTxsPerBlock = 0) if there are no txs.',
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const checkpointIndex = this.nextCheckpointIndex++;
|
|
189
|
+
const checkpointNumber = checkpointIndex + 1;
|
|
190
|
+
const slotNumber = checkpointNumber * 15; // times an arbitrary number to make it different to the checkpoint number
|
|
191
|
+
|
|
192
|
+
const constants = makeCheckpointConstants(slotNumber, constantOpts);
|
|
193
|
+
|
|
194
|
+
const fork = await this.worldState.fork();
|
|
195
|
+
|
|
196
|
+
// Build l1 to l2 messages.
|
|
197
|
+
const l1ToL2Messages = times(numL1ToL2Messages, i => new Fr(slotNumber * 100 + i));
|
|
198
|
+
await fork.appendLeaves(
|
|
199
|
+
MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
|
|
200
|
+
padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
|
|
201
|
+
);
|
|
202
|
+
const newL1ToL2Snapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, fork);
|
|
203
|
+
|
|
204
|
+
const startBlockNumber = this.nextBlockNumber;
|
|
205
|
+
const previousBlockHeader = this.getBlockHeader(startBlockNumber - 1);
|
|
206
|
+
|
|
207
|
+
// Build global variables.
|
|
208
|
+
const blockGlobalVariables = times(numBlocks, i =>
|
|
209
|
+
makeGlobals(startBlockNumber + i, slotNumber, {
|
|
210
|
+
coinbase: constants.coinbase,
|
|
211
|
+
feeRecipient: constants.feeRecipient,
|
|
212
|
+
gasFees: constants.gasFees,
|
|
213
|
+
}),
|
|
214
|
+
);
|
|
215
|
+
this.nextBlockNumber += numBlocks;
|
|
216
|
+
|
|
217
|
+
// Build txs.
|
|
218
|
+
let totalTxs = 0;
|
|
219
|
+
const blockEndStates: StateReference[] = [];
|
|
220
|
+
const blockTxs = await timesAsync(numBlocks, async blockIndex => {
|
|
221
|
+
const txIndexOffset = totalTxs;
|
|
222
|
+
const numTxs = typeof numTxsPerBlock === 'number' ? numTxsPerBlock : numTxsPerBlock[blockIndex];
|
|
223
|
+
totalTxs += numTxs;
|
|
224
|
+
const txs = await timesAsync(numTxs, txIndex =>
|
|
225
|
+
this.makeProcessedTx({
|
|
226
|
+
seed: (txIndexOffset + txIndex + 1) * 321 + (checkpointIndex + 1) * 123456 + this.epochNumber * 0x99999,
|
|
227
|
+
globalVariables: blockGlobalVariables[blockIndex],
|
|
228
|
+
anchorBlockHeader: previousBlockHeader,
|
|
229
|
+
newL1ToL2Snapshot,
|
|
230
|
+
...makeProcessedTxOpts(blockGlobalVariables[blockIndex], txIndexOffset + txIndex),
|
|
231
|
+
}),
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
// Insert side effects into the trees.
|
|
235
|
+
const endState = await this.updateTrees(txs, fork);
|
|
236
|
+
blockEndStates.push(endState);
|
|
237
|
+
|
|
238
|
+
return txs;
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
const cleanFork = await this.worldState.fork();
|
|
242
|
+
const builder = await LightweightCheckpointBuilder.startNewCheckpoint(
|
|
243
|
+
checkpointNumber,
|
|
244
|
+
constants,
|
|
245
|
+
l1ToL2Messages,
|
|
246
|
+
cleanFork,
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
// Add tx effects to db and build block headers.
|
|
250
|
+
const blocks = [];
|
|
251
|
+
for (let i = 0; i < numBlocks; i++) {
|
|
252
|
+
const isFirstBlock = i === 0;
|
|
253
|
+
const txs = blockTxs[i];
|
|
254
|
+
const state = blockEndStates[i];
|
|
255
|
+
|
|
256
|
+
const block = await builder.addBlock(blockGlobalVariables[i], state, txs);
|
|
257
|
+
|
|
258
|
+
const header = block.header;
|
|
259
|
+
this.headers.set(block.number, header);
|
|
260
|
+
|
|
261
|
+
const blockMsgs = isFirstBlock ? l1ToL2Messages : [];
|
|
262
|
+
await this.worldState.handleL2BlockAndMessages(block, blockMsgs, isFirstBlock);
|
|
263
|
+
|
|
264
|
+
blocks.push({ header, txs });
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const checkpoint = await builder.completeCheckpoint();
|
|
268
|
+
this.checkpoints.push(checkpoint);
|
|
269
|
+
|
|
270
|
+
return {
|
|
271
|
+
constants,
|
|
272
|
+
header: checkpoint.header,
|
|
273
|
+
blocks,
|
|
274
|
+
l1ToL2Messages,
|
|
275
|
+
previousBlockHeader,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
private async makeProcessedTx(opts: Parameters<typeof mockProcessedTx>[0] = {}): Promise<ProcessedTx> {
|
|
280
|
+
const tx = await mockProcessedTx({
|
|
179
281
|
vkTreeRoot: getVKTreeRoot(),
|
|
180
|
-
|
|
181
|
-
globalVariables: this.globalVariables,
|
|
282
|
+
protocolContracts: ProtocolContractsList,
|
|
182
283
|
feePayer: this.feePayer,
|
|
183
284
|
...opts,
|
|
184
285
|
});
|
|
286
|
+
|
|
185
287
|
this.feePayerBalance = new Fr(this.feePayerBalance.toBigInt() - tx.txEffect.transactionFee.toBigInt());
|
|
186
|
-
if (opts?.privateOnly) {
|
|
187
|
-
const feePayerSlot = await computeFeePayerBalanceLeafSlot(this.feePayer);
|
|
188
|
-
tx.txEffect.publicDataWrites[0] = new PublicDataWrite(feePayerSlot, this.feePayerBalance);
|
|
189
|
-
}
|
|
190
|
-
return tx;
|
|
191
|
-
}
|
|
192
288
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
) {
|
|
200
|
-
const globalVariables = typeof blockNumOrGlobals === 'number' ? makeGlobals(blockNumOrGlobals) : blockNumOrGlobals;
|
|
201
|
-
const blockNum = globalVariables.blockNumber.toNumber();
|
|
202
|
-
const db = await this.worldState.fork();
|
|
203
|
-
const msgs = times(numMsgs, i => new Fr(blockNum * 100 + i));
|
|
204
|
-
const txs = await timesParallel(numTxs, i =>
|
|
205
|
-
this.makeProcessedTx({ seed: i + blockNum * 1000, globalVariables, ...makeProcessedTxOpts(i) }),
|
|
206
|
-
);
|
|
207
|
-
await this.setTreeRoots(txs);
|
|
289
|
+
const feePayerSlot = await computeFeePayerBalanceLeafSlot(this.feePayer);
|
|
290
|
+
const feePaymentPublicDataWrite = new PublicDataWrite(feePayerSlot, this.feePayerBalance);
|
|
291
|
+
tx.txEffect.publicDataWrites[0] = feePaymentPublicDataWrite;
|
|
292
|
+
if (tx.avmProvingRequest) {
|
|
293
|
+
tx.avmProvingRequest.inputs.publicInputs.accumulatedData.publicDataWrites[0] = feePaymentPublicDataWrite;
|
|
294
|
+
}
|
|
208
295
|
|
|
209
|
-
|
|
210
|
-
this.headers.set(blockNum, block.header);
|
|
211
|
-
await this.worldState.handleL2BlockAndMessages(block, msgs);
|
|
212
|
-
return { block, txs, msgs };
|
|
296
|
+
return tx;
|
|
213
297
|
}
|
|
214
298
|
|
|
215
|
-
|
|
216
|
-
|
|
299
|
+
private getBlockHeader(blockNumber: number): BlockHeader {
|
|
300
|
+
if (blockNumber > 0 && blockNumber >= this.nextBlockNumber) {
|
|
301
|
+
throw new Error(`Block header not built for block number ${blockNumber}.`);
|
|
302
|
+
}
|
|
303
|
+
return blockNumber === 0 ? this.worldState.getCommitted().getInitialHeader() : this.headers.get(blockNumber)!;
|
|
217
304
|
}
|
|
218
305
|
|
|
219
|
-
|
|
220
|
-
|
|
306
|
+
private async updateTrees(txs: ProcessedTx[], fork: MerkleTreeWriteOperations) {
|
|
307
|
+
let startStateReference = await fork.getStateReference();
|
|
308
|
+
let endStateReference = startStateReference;
|
|
221
309
|
for (const tx of txs) {
|
|
222
|
-
|
|
223
|
-
await
|
|
224
|
-
|
|
310
|
+
await insertSideEffects(tx, fork);
|
|
311
|
+
endStateReference = await fork.getStateReference();
|
|
312
|
+
|
|
225
313
|
if (tx.avmProvingRequest) {
|
|
314
|
+
// Update the trees in the avm public inputs so that the proof won't fail.
|
|
315
|
+
const l1ToL2MessageTree = tx.avmProvingRequest.inputs.publicInputs.startTreeSnapshots.l1ToL2MessageTree;
|
|
226
316
|
tx.avmProvingRequest.inputs.publicInputs.startTreeSnapshots = new TreeSnapshots(
|
|
227
|
-
|
|
317
|
+
l1ToL2MessageTree,
|
|
228
318
|
startStateReference.partial.noteHashTree,
|
|
229
319
|
startStateReference.partial.nullifierTree,
|
|
230
320
|
startStateReference.partial.publicDataTree,
|
|
231
321
|
);
|
|
322
|
+
|
|
232
323
|
tx.avmProvingRequest.inputs.publicInputs.endTreeSnapshots = new TreeSnapshots(
|
|
233
|
-
|
|
324
|
+
l1ToL2MessageTree,
|
|
234
325
|
endStateReference.partial.noteHashTree,
|
|
235
326
|
endStateReference.partial.nullifierTree,
|
|
236
327
|
endStateReference.partial.publicDataTree,
|
|
237
328
|
);
|
|
238
329
|
}
|
|
330
|
+
|
|
331
|
+
startStateReference = endStateReference;
|
|
239
332
|
}
|
|
333
|
+
|
|
334
|
+
return endStateReference;
|
|
240
335
|
}
|
|
241
336
|
}
|
|
242
337
|
|
|
@@ -245,12 +340,9 @@ class TestProvingOrchestrator extends ProvingOrchestrator {
|
|
|
245
340
|
|
|
246
341
|
// Disable this check by default, since it requires seeding world state with the block being built
|
|
247
342
|
// This is only enabled in some tests with multiple blocks that populate the pending chain via makePendingBlock
|
|
248
|
-
protected override verifyBuiltBlockAgainstSyncedState(
|
|
249
|
-
l2Block: L2Block,
|
|
250
|
-
newArchive: AppendOnlyTreeSnapshot,
|
|
251
|
-
): Promise<void> {
|
|
343
|
+
protected override verifyBuiltBlockAgainstSyncedState(provingState: BlockProvingState): Promise<void> {
|
|
252
344
|
if (this.isVerifyBuiltBlockAgainstSyncedStateEnabled) {
|
|
253
|
-
return super.verifyBuiltBlockAgainstSyncedState(
|
|
345
|
+
return super.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
254
346
|
}
|
|
255
347
|
return Promise.resolve();
|
|
256
348
|
}
|