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