@aztec/sequencer-client 0.0.1-commit.c7c42ec → 0.0.1-commit.f295ac2
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/client/sequencer-client.d.ts +4 -5
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +8 -1
- package/dest/global_variable_builder/global_builder.d.ts +4 -4
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +12 -12
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +15 -86
- package/dest/publisher/sequencer-publisher.d.ts +17 -16
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +442 -49
- package/dest/sequencer/checkpoint_proposal_job.d.ts +14 -9
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +551 -38
- package/dest/sequencer/checkpoint_voter.d.ts +3 -2
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_voter.js +34 -10
- package/dest/sequencer/index.d.ts +1 -3
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +0 -2
- package/dest/sequencer/metrics.d.ts +3 -3
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +30 -121
- package/dest/sequencer/sequencer.d.ts +24 -14
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +485 -41
- package/dest/test/index.d.ts +2 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +16 -7
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +32 -3
- package/dest/test/utils.d.ts +8 -4
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +23 -14
- package/package.json +30 -28
- package/src/client/sequencer-client.ts +3 -4
- package/src/config.ts +7 -0
- package/src/global_variable_builder/global_builder.ts +12 -12
- package/src/index.ts +1 -9
- package/src/publisher/sequencer-publisher-metrics.ts +14 -70
- package/src/publisher/sequencer-publisher.ts +84 -73
- package/src/sequencer/checkpoint_proposal_job.ts +183 -53
- package/src/sequencer/checkpoint_voter.ts +32 -7
- package/src/sequencer/index.ts +0 -2
- package/src/sequencer/metrics.ts +23 -131
- package/src/sequencer/sequencer.ts +122 -39
- package/src/test/index.ts +1 -2
- package/src/test/mock_checkpoint_builder.ts +62 -14
- package/src/test/utils.ts +42 -21
- package/dest/sequencer/block_builder.d.ts +0 -26
- package/dest/sequencer/block_builder.d.ts.map +0 -1
- package/dest/sequencer/block_builder.js +0 -129
- package/dest/sequencer/checkpoint_builder.d.ts +0 -63
- package/dest/sequencer/checkpoint_builder.d.ts.map +0 -1
- package/dest/sequencer/checkpoint_builder.js +0 -131
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -53
- package/src/sequencer/block_builder.ts +0 -217
- package/src/sequencer/checkpoint_builder.ts +0 -217
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -133
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { type BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { Timer } from '@aztec/foundation/timer';
|
|
4
|
-
import type { FunctionsOf } from '@aztec/foundation/types';
|
|
5
4
|
import { L2BlockNew } from '@aztec/stdlib/block';
|
|
6
5
|
import { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
7
6
|
import { Gas } from '@aztec/stdlib/gas';
|
|
8
|
-
import type {
|
|
7
|
+
import type {
|
|
8
|
+
BuildBlockInCheckpointResult,
|
|
9
|
+
FullNodeBlockBuilderConfig,
|
|
10
|
+
ICheckpointBlockBuilder,
|
|
11
|
+
ICheckpointsBuilder,
|
|
12
|
+
MerkleTreeWriteOperations,
|
|
13
|
+
PublicProcessorLimits,
|
|
14
|
+
} from '@aztec/stdlib/interfaces/server';
|
|
9
15
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
10
16
|
import { makeAppendOnlyTreeSnapshot } from '@aztec/stdlib/testing';
|
|
11
17
|
import type { CheckpointGlobalVariables, Tx } from '@aztec/stdlib/tx';
|
|
12
18
|
|
|
13
|
-
import type {
|
|
14
|
-
BuildBlockInCheckpointResult,
|
|
15
|
-
CheckpointBuilder,
|
|
16
|
-
FullNodeCheckpointsBuilder,
|
|
17
|
-
} from '../sequencer/checkpoint_builder.js';
|
|
18
|
-
|
|
19
19
|
/**
|
|
20
20
|
* A fake CheckpointBuilder for testing that implements the same interface as the real one.
|
|
21
21
|
* Can be seeded with blocks to return sequentially on each `buildBlock` call.
|
|
22
22
|
*/
|
|
23
|
-
export class MockCheckpointBuilder implements
|
|
23
|
+
export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
|
|
24
24
|
private blocks: L2BlockNew[] = [];
|
|
25
25
|
private builtBlocks: L2BlockNew[] = [];
|
|
26
26
|
private usedTxsPerBlock: Tx[][] = [];
|
|
@@ -105,6 +105,7 @@ export class MockCheckpointBuilder implements FunctionsOf<CheckpointBuilder> {
|
|
|
105
105
|
blockBuildingTimer: new Timer(),
|
|
106
106
|
usedTxs,
|
|
107
107
|
failedTxs: [],
|
|
108
|
+
usedTxBlobFields: block?.body?.txEffects?.reduce((sum, tx) => sum + tx.getNumBlobFields(), 0) ?? 0,
|
|
108
109
|
});
|
|
109
110
|
}
|
|
110
111
|
|
|
@@ -181,7 +182,7 @@ export class MockCheckpointBuilder implements FunctionsOf<CheckpointBuilder> {
|
|
|
181
182
|
* as FullNodeCheckpointsBuilder. Returns MockCheckpointBuilder instances.
|
|
182
183
|
* Does NOT use jest mocks - this is a proper test double.
|
|
183
184
|
*/
|
|
184
|
-
export class MockCheckpointsBuilder implements
|
|
185
|
+
export class MockCheckpointsBuilder implements ICheckpointsBuilder {
|
|
185
186
|
private checkpointBuilder: MockCheckpointBuilder | undefined;
|
|
186
187
|
|
|
187
188
|
/** Track calls for assertions */
|
|
@@ -189,6 +190,14 @@ export class MockCheckpointsBuilder implements FunctionsOf<FullNodeCheckpointsBu
|
|
|
189
190
|
checkpointNumber: CheckpointNumber;
|
|
190
191
|
constants: CheckpointGlobalVariables;
|
|
191
192
|
l1ToL2Messages: Fr[];
|
|
193
|
+
previousCheckpointOutHashes: Fr[];
|
|
194
|
+
}> = [];
|
|
195
|
+
public openCheckpointCalls: Array<{
|
|
196
|
+
checkpointNumber: CheckpointNumber;
|
|
197
|
+
constants: CheckpointGlobalVariables;
|
|
198
|
+
l1ToL2Messages: Fr[];
|
|
199
|
+
previousCheckpointOutHashes: Fr[];
|
|
200
|
+
existingBlocks: L2BlockNew[];
|
|
192
201
|
}> = [];
|
|
193
202
|
public updateConfigCalls: Array<Partial<FullNodeBlockBuilderConfig>> = [];
|
|
194
203
|
|
|
@@ -218,6 +227,15 @@ export class MockCheckpointsBuilder implements FunctionsOf<FullNodeCheckpointsBu
|
|
|
218
227
|
return this.checkpointBuilder;
|
|
219
228
|
}
|
|
220
229
|
|
|
230
|
+
getConfig(): FullNodeBlockBuilderConfig {
|
|
231
|
+
return {
|
|
232
|
+
l1GenesisTime: 0n,
|
|
233
|
+
slotDuration: 24,
|
|
234
|
+
l1ChainId: 1,
|
|
235
|
+
rollupVersion: 1,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
221
239
|
updateConfig(config: Partial<FullNodeBlockBuilderConfig>): void {
|
|
222
240
|
this.updateConfigCalls.push(config);
|
|
223
241
|
}
|
|
@@ -226,22 +244,52 @@ export class MockCheckpointsBuilder implements FunctionsOf<FullNodeCheckpointsBu
|
|
|
226
244
|
checkpointNumber: CheckpointNumber,
|
|
227
245
|
constants: CheckpointGlobalVariables,
|
|
228
246
|
l1ToL2Messages: Fr[],
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
247
|
+
previousCheckpointOutHashes: Fr[],
|
|
248
|
+
_fork: MerkleTreeWriteOperations,
|
|
249
|
+
): Promise<ICheckpointBlockBuilder> {
|
|
250
|
+
this.startCheckpointCalls.push({ checkpointNumber, constants, l1ToL2Messages, previousCheckpointOutHashes });
|
|
232
251
|
|
|
233
252
|
if (!this.checkpointBuilder) {
|
|
234
253
|
// Auto-create a builder if none was set
|
|
235
254
|
this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
|
|
236
255
|
}
|
|
237
256
|
|
|
238
|
-
return Promise.resolve(this.checkpointBuilder
|
|
257
|
+
return Promise.resolve(this.checkpointBuilder);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
openCheckpoint(
|
|
261
|
+
checkpointNumber: CheckpointNumber,
|
|
262
|
+
constants: CheckpointGlobalVariables,
|
|
263
|
+
l1ToL2Messages: Fr[],
|
|
264
|
+
previousCheckpointOutHashes: Fr[],
|
|
265
|
+
_fork: MerkleTreeWriteOperations,
|
|
266
|
+
existingBlocks: L2BlockNew[] = [],
|
|
267
|
+
): Promise<ICheckpointBlockBuilder> {
|
|
268
|
+
this.openCheckpointCalls.push({
|
|
269
|
+
checkpointNumber,
|
|
270
|
+
constants,
|
|
271
|
+
l1ToL2Messages,
|
|
272
|
+
previousCheckpointOutHashes,
|
|
273
|
+
existingBlocks,
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
if (!this.checkpointBuilder) {
|
|
277
|
+
// Auto-create a builder if none was set
|
|
278
|
+
this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return Promise.resolve(this.checkpointBuilder);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
getFork(_blockNumber: BlockNumber): Promise<MerkleTreeWriteOperations> {
|
|
285
|
+
throw new Error('MockCheckpointsBuilder.getFork not implemented');
|
|
239
286
|
}
|
|
240
287
|
|
|
241
288
|
/** Reset for reuse in another test */
|
|
242
289
|
reset(): void {
|
|
243
290
|
this.checkpointBuilder = undefined;
|
|
244
291
|
this.startCheckpointCalls = [];
|
|
292
|
+
this.openCheckpointCalls = [];
|
|
245
293
|
this.updateConfigCalls = [];
|
|
246
294
|
}
|
|
247
295
|
}
|
package/src/test/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Body } from '@aztec/aztec.js/block';
|
|
2
|
-
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { times } from '@aztec/foundation/collection';
|
|
4
4
|
import { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
5
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
@@ -8,16 +8,10 @@ import { Signature } from '@aztec/foundation/eth-signature';
|
|
|
8
8
|
import type { P2P } from '@aztec/p2p';
|
|
9
9
|
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
10
10
|
import { CommitteeAttestation, L2BlockNew } from '@aztec/stdlib/block';
|
|
11
|
-
import {
|
|
11
|
+
import { BlockProposal, CheckpointAttestation, CheckpointProposal, ConsensusPayload } from '@aztec/stdlib/p2p';
|
|
12
12
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
13
13
|
import { makeAppendOnlyTreeSnapshot, mockTxForRollup } from '@aztec/stdlib/testing';
|
|
14
|
-
import {
|
|
15
|
-
BlockHeader,
|
|
16
|
-
ContentCommitment,
|
|
17
|
-
GlobalVariables,
|
|
18
|
-
type Tx,
|
|
19
|
-
makeProcessedTxFromPrivateOnlyTx,
|
|
20
|
-
} from '@aztec/stdlib/tx';
|
|
14
|
+
import { BlockHeader, GlobalVariables, type Tx, makeProcessedTxFromPrivateOnlyTx } from '@aztec/stdlib/tx';
|
|
21
15
|
|
|
22
16
|
import type { MockProxy } from 'jest-mock-extended';
|
|
23
17
|
|
|
@@ -47,7 +41,7 @@ export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Pr
|
|
|
47
41
|
const body = new Body(processedTxs.map(tx => tx.txEffect));
|
|
48
42
|
const header = BlockHeader.empty({ globalVariables });
|
|
49
43
|
const archive = makeAppendOnlyTreeSnapshot(globalVariables.blockNumber + 1);
|
|
50
|
-
return new L2BlockNew(archive, header, body, CheckpointNumber(globalVariables.blockNumber), 0);
|
|
44
|
+
return new L2BlockNew(archive, header, body, CheckpointNumber(globalVariables.blockNumber), IndexWithinCheckpoint(0));
|
|
51
45
|
}
|
|
52
46
|
|
|
53
47
|
/**
|
|
@@ -77,15 +71,16 @@ export function createMockSignatures(signer: Secp256k1Signer): CommitteeAttestat
|
|
|
77
71
|
|
|
78
72
|
/**
|
|
79
73
|
* Creates a CheckpointHeader from an L2BlockNew for testing purposes.
|
|
80
|
-
* Uses mock values for
|
|
81
|
-
* L2BlockNew doesn't have these fields.
|
|
74
|
+
* Uses mock values for blockHeadersHash, blobsHash and inHash since L2BlockNew doesn't have these fields.
|
|
82
75
|
*/
|
|
83
76
|
function createCheckpointHeaderFromBlock(block: L2BlockNew): CheckpointHeader {
|
|
84
77
|
const gv = block.header.globalVariables;
|
|
85
78
|
return new CheckpointHeader(
|
|
86
79
|
block.header.lastArchive.root,
|
|
87
80
|
Fr.random(), // blockHeadersHash - mock value for testing
|
|
88
|
-
|
|
81
|
+
Fr.random(), // blobsHash - mock value for testing
|
|
82
|
+
Fr.random(), // inHash - mock value for testing
|
|
83
|
+
Fr.random(), // outHash - mock value for testing
|
|
89
84
|
gv.slotNumber,
|
|
90
85
|
gv.timestamp,
|
|
91
86
|
gv.coinbase,
|
|
@@ -99,23 +94,49 @@ function createCheckpointHeaderFromBlock(block: L2BlockNew): CheckpointHeader {
|
|
|
99
94
|
* Creates a block proposal from a block and signature
|
|
100
95
|
*/
|
|
101
96
|
export function createBlockProposal(block: L2BlockNew, signature: Signature): BlockProposal {
|
|
102
|
-
const checkpointHeader = createCheckpointHeaderFromBlock(block);
|
|
103
|
-
const consensusPayload = new ConsensusPayload(checkpointHeader, block.archive.root);
|
|
104
97
|
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
105
|
-
return new BlockProposal(
|
|
98
|
+
return new BlockProposal(
|
|
99
|
+
block.header,
|
|
100
|
+
block.indexWithinCheckpoint,
|
|
101
|
+
Fr.ZERO, // inHash - using zero for testing
|
|
102
|
+
block.archive.root,
|
|
103
|
+
txHashes,
|
|
104
|
+
signature,
|
|
105
|
+
);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
|
-
* Creates a
|
|
109
|
+
* Creates a checkpoint proposal from a block and signature
|
|
110
|
+
*/
|
|
111
|
+
export function createCheckpointProposal(
|
|
112
|
+
block: L2BlockNew,
|
|
113
|
+
checkpointSignature: Signature,
|
|
114
|
+
blockSignature?: Signature,
|
|
115
|
+
): CheckpointProposal {
|
|
116
|
+
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
117
|
+
const checkpointHeader = createCheckpointHeaderFromBlock(block);
|
|
118
|
+
return new CheckpointProposal(checkpointHeader, block.archive.root, checkpointSignature, {
|
|
119
|
+
blockHeader: block.header,
|
|
120
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
121
|
+
txHashes,
|
|
122
|
+
signature: blockSignature ?? checkpointSignature, // Use checkpoint signature as block signature if not provided
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Creates a checkpoint attestation from a block and signature.
|
|
110
128
|
* Note: We manually set the sender since we use random signatures in tests.
|
|
111
129
|
* In production, the sender is recovered from the signature.
|
|
112
130
|
*/
|
|
113
|
-
export function
|
|
131
|
+
export function createCheckpointAttestation(
|
|
132
|
+
block: L2BlockNew,
|
|
133
|
+
signature: Signature,
|
|
134
|
+
sender: EthAddress,
|
|
135
|
+
): CheckpointAttestation {
|
|
114
136
|
const checkpointHeader = createCheckpointHeaderFromBlock(block);
|
|
115
|
-
const
|
|
116
|
-
const attestation = new
|
|
137
|
+
const payload = new ConsensusPayload(checkpointHeader, block.archive.root);
|
|
138
|
+
const attestation = new CheckpointAttestation(payload, signature, signature);
|
|
117
139
|
// Set sender directly for testing (bypasses signature recovery)
|
|
118
|
-
|
|
119
140
|
(attestation as any).sender = sender;
|
|
120
141
|
return attestation;
|
|
121
142
|
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import { DateProvider } from '@aztec/foundation/timer';
|
|
4
|
-
import { PublicProcessor } from '@aztec/simulator/server';
|
|
5
|
-
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
6
|
-
import type { BuildBlockResult, FullNodeBlockBuilderConfig, IFullNodeBlockBuilder, MerkleTreeWriteOperations, PublicProcessorLimits, PublicProcessorValidator, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
7
|
-
import { GlobalVariables, Tx } from '@aztec/stdlib/tx';
|
|
8
|
-
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
9
|
-
export declare class FullNodeBlockBuilder implements IFullNodeBlockBuilder {
|
|
10
|
-
private config;
|
|
11
|
-
private worldState;
|
|
12
|
-
private contractDataSource;
|
|
13
|
-
private dateProvider;
|
|
14
|
-
private telemetryClient;
|
|
15
|
-
constructor(config: FullNodeBlockBuilderConfig, worldState: WorldStateSynchronizer, contractDataSource: ContractDataSource, dateProvider: DateProvider, telemetryClient?: TelemetryClient);
|
|
16
|
-
getConfig(): FullNodeBlockBuilderConfig;
|
|
17
|
-
updateConfig(config: Partial<FullNodeBlockBuilderConfig>): void;
|
|
18
|
-
makeBlockBuilderDeps(globalVariables: GlobalVariables, fork: MerkleTreeWriteOperations): Promise<{
|
|
19
|
-
processor: PublicProcessor;
|
|
20
|
-
validator: PublicProcessorValidator;
|
|
21
|
-
}>;
|
|
22
|
-
private syncToPreviousBlock;
|
|
23
|
-
buildBlock(pendingTxs: Iterable<Tx> | AsyncIterable<Tx>, l1ToL2Messages: Fr[], globalVariables: GlobalVariables, opts: PublicProcessorLimits, suppliedFork?: MerkleTreeWriteOperations): Promise<BuildBlockResult>;
|
|
24
|
-
getFork(blockNumber: BlockNumber): Promise<MerkleTreeWriteOperations>;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmxvY2tfYnVpbGRlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3NlcXVlbmNlci9ibG9ja19idWlsZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUU5RCxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUl6RCxPQUFPLEVBQUUsWUFBWSxFQUFrQixNQUFNLHlCQUF5QixDQUFDO0FBR3ZFLE9BQU8sRUFHTCxlQUFlLEVBRWhCLE1BQU0seUJBQXlCLENBQUM7QUFDakMsT0FBTyxLQUFLLEVBQUUsa0JBQWtCLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUdqRSxPQUFPLEtBQUssRUFDVixnQkFBZ0IsRUFDaEIsMEJBQTBCLEVBQzF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AAe,EAAE,eAAe,EAAE,IAAI,EAAE,yBAAyB;;;OAkClG;YAEa,mBAAmB;IAU3B,UAAU,CACd,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,EAAE,CAAC,EAC5C,cAAc,EAAE,EAAE,EAAE,EACpB,eAAe,EAAE,eAAe,EAChC,IAAI,EAAE,qBAAqB,EAC3B,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,gBAAgB,CAAC,CAsC3B;IAED,OAAO,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAEpE;CACF"}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { MerkleTreeId } from '@aztec/aztec.js/trees';
|
|
2
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import { merge, pick } from '@aztec/foundation/collection';
|
|
4
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
6
|
-
import { bufferToHex } from '@aztec/foundation/string';
|
|
7
|
-
import { Timer, elapsed } from '@aztec/foundation/timer';
|
|
8
|
-
import { getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
|
|
9
|
-
import { LightweightBlockFactory } from '@aztec/prover-client/block-factory';
|
|
10
|
-
import { GuardedMerkleTreeOperations, PublicContractsDB, PublicProcessor, createPublicTxSimulatorForBlockBuilding } from '@aztec/simulator/server';
|
|
11
|
-
import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
12
|
-
import { Gas } from '@aztec/stdlib/gas';
|
|
13
|
-
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
14
|
-
import { createValidatorForBlockBuilding } from '../tx_validator/tx_validator_factory.js';
|
|
15
|
-
const log = createLogger('block-builder');
|
|
16
|
-
/** Builds a block out of pending txs */ async function buildBlock(pendingTxs, l1ToL2Messages, newGlobalVariables, opts = {}, worldStateFork, processor, validator, l1Constants, dateProvider, telemetryClient = getTelemetryClient()) {
|
|
17
|
-
const blockBuildingTimer = new Timer();
|
|
18
|
-
const blockNumber = newGlobalVariables.blockNumber;
|
|
19
|
-
const slot = newGlobalVariables.slotNumber;
|
|
20
|
-
const msgCount = l1ToL2Messages.length;
|
|
21
|
-
const stateReference = await worldStateFork.getStateReference();
|
|
22
|
-
const archiveTree = await worldStateFork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
23
|
-
log.verbose(`Building block ${blockNumber} for slot ${slot}`, {
|
|
24
|
-
slot,
|
|
25
|
-
slotStart: new Date(Number(getTimestampForSlot(slot, l1Constants)) * 1000),
|
|
26
|
-
now: new Date(dateProvider.now()),
|
|
27
|
-
blockNumber,
|
|
28
|
-
msgCount,
|
|
29
|
-
initialStateReference: stateReference.toInspect(),
|
|
30
|
-
initialArchiveRoot: bufferToHex(archiveTree.root),
|
|
31
|
-
opts
|
|
32
|
-
});
|
|
33
|
-
const blockFactory = new LightweightBlockFactory(worldStateFork, telemetryClient);
|
|
34
|
-
await blockFactory.startNewBlock(newGlobalVariables, l1ToL2Messages);
|
|
35
|
-
const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(()=>processor.process(pendingTxs, opts, validator));
|
|
36
|
-
// All real transactions have been added, set the block as full and pad if needed
|
|
37
|
-
await blockFactory.addTxs(processedTxs);
|
|
38
|
-
const block = await blockFactory.setBlockCompleted();
|
|
39
|
-
// How much public gas was processed
|
|
40
|
-
const publicGas = processedTxs.reduce((acc, tx)=>acc.add(tx.gasUsed.publicGas), Gas.empty());
|
|
41
|
-
const res = {
|
|
42
|
-
block,
|
|
43
|
-
publicGas,
|
|
44
|
-
publicProcessorDuration,
|
|
45
|
-
numMsgs: l1ToL2Messages.length,
|
|
46
|
-
numTxs: processedTxs.length,
|
|
47
|
-
failedTxs: failedTxs,
|
|
48
|
-
blockBuildingTimer,
|
|
49
|
-
usedTxs
|
|
50
|
-
};
|
|
51
|
-
log.trace('Built block', res.block.header);
|
|
52
|
-
return res;
|
|
53
|
-
}
|
|
54
|
-
const FullNodeBlockBuilderConfigKeys = [
|
|
55
|
-
'l1GenesisTime',
|
|
56
|
-
'slotDuration',
|
|
57
|
-
'l1ChainId',
|
|
58
|
-
'rollupVersion',
|
|
59
|
-
'txPublicSetupAllowList',
|
|
60
|
-
'fakeProcessingDelayPerTxMs',
|
|
61
|
-
'fakeThrowAfterProcessingTxCount'
|
|
62
|
-
];
|
|
63
|
-
// TODO(palla/mbps): Try killing this in favor of the CheckpointsBuilder
|
|
64
|
-
export class FullNodeBlockBuilder {
|
|
65
|
-
config;
|
|
66
|
-
worldState;
|
|
67
|
-
contractDataSource;
|
|
68
|
-
dateProvider;
|
|
69
|
-
telemetryClient;
|
|
70
|
-
constructor(config, worldState, contractDataSource, dateProvider, telemetryClient = getTelemetryClient()){
|
|
71
|
-
this.config = config;
|
|
72
|
-
this.worldState = worldState;
|
|
73
|
-
this.contractDataSource = contractDataSource;
|
|
74
|
-
this.dateProvider = dateProvider;
|
|
75
|
-
this.telemetryClient = telemetryClient;
|
|
76
|
-
}
|
|
77
|
-
getConfig() {
|
|
78
|
-
return pick(this.config, ...FullNodeBlockBuilderConfigKeys);
|
|
79
|
-
}
|
|
80
|
-
updateConfig(config) {
|
|
81
|
-
this.config = merge(this.config, pick(config, ...FullNodeBlockBuilderConfigKeys));
|
|
82
|
-
}
|
|
83
|
-
async makeBlockBuilderDeps(globalVariables, fork) {
|
|
84
|
-
const txPublicSetupAllowList = this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
|
|
85
|
-
const contractsDB = new PublicContractsDB(this.contractDataSource);
|
|
86
|
-
const guardedFork = new GuardedMerkleTreeOperations(fork);
|
|
87
|
-
const publicTxSimulator = createPublicTxSimulatorForBlockBuilding(guardedFork, contractsDB, globalVariables, this.telemetryClient);
|
|
88
|
-
const processor = new PublicProcessor(globalVariables, guardedFork, contractsDB, publicTxSimulator, this.dateProvider, this.telemetryClient, undefined, this.config);
|
|
89
|
-
const validator = createValidatorForBlockBuilding(fork, this.contractDataSource, globalVariables, txPublicSetupAllowList);
|
|
90
|
-
return {
|
|
91
|
-
processor,
|
|
92
|
-
validator
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
async syncToPreviousBlock(parentBlockNumber, timeout) {
|
|
96
|
-
await retryUntil(()=>this.worldState.syncImmediate(parentBlockNumber, true).then((syncedTo)=>syncedTo >= parentBlockNumber), 'sync to previous block', timeout, 0.1);
|
|
97
|
-
log.debug(`Synced to previous block ${parentBlockNumber}`);
|
|
98
|
-
}
|
|
99
|
-
async buildBlock(pendingTxs, l1ToL2Messages, globalVariables, opts, suppliedFork) {
|
|
100
|
-
const parentBlockNumber = BlockNumber(globalVariables.blockNumber - 1);
|
|
101
|
-
const syncTimeout = opts.deadline ? (opts.deadline.getTime() - this.dateProvider.now()) / 1000 : undefined;
|
|
102
|
-
await this.syncToPreviousBlock(parentBlockNumber, syncTimeout);
|
|
103
|
-
const fork = suppliedFork ?? await this.worldState.fork(parentBlockNumber);
|
|
104
|
-
try {
|
|
105
|
-
const { processor, validator } = await this.makeBlockBuilderDeps(globalVariables, fork);
|
|
106
|
-
const res = await buildBlock(pendingTxs, l1ToL2Messages, globalVariables, opts, fork, processor, validator, this.config, this.dateProvider, this.telemetryClient);
|
|
107
|
-
return res;
|
|
108
|
-
} finally{
|
|
109
|
-
// If the fork was supplied, we don't close it.
|
|
110
|
-
// Otherwise, we wait a bit to close the fork we just created,
|
|
111
|
-
// since the processor may still be working on a dangling tx
|
|
112
|
-
// which was interrupted due to the processingDeadline being hit.
|
|
113
|
-
if (!suppliedFork) {
|
|
114
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
115
|
-
setTimeout(async ()=>{
|
|
116
|
-
try {
|
|
117
|
-
await fork.close();
|
|
118
|
-
} catch (err) {
|
|
119
|
-
// This can happen if the sequencer is stopped before we hit this timeout.
|
|
120
|
-
log.warn(`Error closing forks for block processing`, err);
|
|
121
|
-
}
|
|
122
|
-
}, 5000);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
getFork(blockNumber) {
|
|
127
|
-
return this.worldState.fork(blockNumber);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
4
|
-
import { LightweightCheckpointBuilder } from '@aztec/prover-client/light';
|
|
5
|
-
import { PublicProcessor } from '@aztec/simulator/server';
|
|
6
|
-
import { L2BlockNew } from '@aztec/stdlib/block';
|
|
7
|
-
import { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
8
|
-
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
9
|
-
import { Gas } from '@aztec/stdlib/gas';
|
|
10
|
-
import { type FullNodeBlockBuilderConfig, type MerkleTreeWriteOperations, type PublicProcessorLimits } from '@aztec/stdlib/interfaces/server';
|
|
11
|
-
import { type CheckpointGlobalVariables, type FailedTx, GlobalVariables, Tx } from '@aztec/stdlib/tx';
|
|
12
|
-
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
13
|
-
export interface BuildBlockInCheckpointResult {
|
|
14
|
-
block: L2BlockNew;
|
|
15
|
-
publicGas: Gas;
|
|
16
|
-
publicProcessorDuration: number;
|
|
17
|
-
numTxs: number;
|
|
18
|
-
failedTxs: FailedTx[];
|
|
19
|
-
blockBuildingTimer: Timer;
|
|
20
|
-
usedTxs: Tx[];
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Builder for a single checkpoint. Handles building blocks within the checkpoint
|
|
24
|
-
* and completing it.
|
|
25
|
-
*/
|
|
26
|
-
export declare class CheckpointBuilder {
|
|
27
|
-
private checkpointBuilder;
|
|
28
|
-
private fork;
|
|
29
|
-
private config;
|
|
30
|
-
private contractDataSource;
|
|
31
|
-
private dateProvider;
|
|
32
|
-
private telemetryClient;
|
|
33
|
-
constructor(checkpointBuilder: LightweightCheckpointBuilder, fork: MerkleTreeWriteOperations, config: FullNodeBlockBuilderConfig, contractDataSource: ContractDataSource, dateProvider: DateProvider, telemetryClient: TelemetryClient);
|
|
34
|
-
getConstantData(): CheckpointGlobalVariables;
|
|
35
|
-
/**
|
|
36
|
-
* Builds a single block within this checkpoint.
|
|
37
|
-
*/
|
|
38
|
-
buildBlock(pendingTxs: Iterable<Tx> | AsyncIterable<Tx>, blockNumber: BlockNumber, timestamp: bigint, opts: PublicProcessorLimits): Promise<BuildBlockInCheckpointResult>;
|
|
39
|
-
/** Completes the checkpoint and returns it. */
|
|
40
|
-
completeCheckpoint(): Promise<Checkpoint>;
|
|
41
|
-
/** Gets the checkpoint currently in progress. */
|
|
42
|
-
getCheckpoint(): Promise<Checkpoint>;
|
|
43
|
-
protected makeBlockBuilderDeps(globalVariables: GlobalVariables, fork: MerkleTreeWriteOperations): Promise<{
|
|
44
|
-
processor: PublicProcessor;
|
|
45
|
-
validator: import("@aztec/stdlib/interfaces/server").PublicProcessorValidator;
|
|
46
|
-
}>;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Factory for creating checkpoint builders.
|
|
50
|
-
*/
|
|
51
|
-
export declare class FullNodeCheckpointsBuilder {
|
|
52
|
-
private config;
|
|
53
|
-
private contractDataSource;
|
|
54
|
-
private dateProvider;
|
|
55
|
-
private telemetryClient;
|
|
56
|
-
constructor(config: FullNodeBlockBuilderConfig, contractDataSource: ContractDataSource, dateProvider: DateProvider, telemetryClient?: TelemetryClient);
|
|
57
|
-
updateConfig(config: Partial<FullNodeBlockBuilderConfig>): void;
|
|
58
|
-
/**
|
|
59
|
-
* Starts a new checkpoint and returns a CheckpointBuilder to build blocks within it.
|
|
60
|
-
*/
|
|
61
|
-
startCheckpoint(checkpointNumber: CheckpointNumber, constants: CheckpointGlobalVariables, l1ToL2Messages: Fr[], fork: Merk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e,EACtC;IAEJ,eAAe,IAAI,yBAAyB,CAE3C;IAED;;OAEG;IACG,UAAU,CACd,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,EAAE,CAAC,EAC5C,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,qBAAqB,GAC1B,OAAO,CAAC,4BAA4B,CAAC,CAwCvC;IAED,+CAA+C;IACzC,kBAAkB,IAAI,OAAO,CAAC,UAAU,CAAC,CAU9C;IAED,iDAAiD;IACjD,aAAa,IAAI,OAAO,CAAC,UAAU,CAAC,CAEnC;IAED,UAAgB,oBAAoB,CAAC,eAAe,EAAE,eAAe,EAAE,IAAI,EAAE,yBAAyB;;;OAkCrG;CACF;AAED;;GAEG;AACH,qBAAa,0BAA0B;IAEnC,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,kBAAkB;IAC1B,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,eAAe;IAJzB,YACU,MAAM,EAAE,0BAA0B,EAClC,kBAAkB,EAAE,kBAAkB,EACtC,YAAY,EAAE,YAAY,EAC1B,eAAe,GAAE,eAAsC,EAC7D;IAEG,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,0BAA0B,CAAC,QAE9D;IAED;;OAEG;IACG,eAAe,CACnB,gBAAgB,EAAE,gBAAgB,EAClC,SAAS,EAAE,yBAAyB,EACpC,cAAc,EAAE,EAAE,EAAE,EACpB,IAAI,EAAE,yBAAyB,GAC9B,OAAO,CAAC,iBAAiB,CAAC,CA2B5B;CACF"}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { MerkleTreeId } from '@aztec/aztec.js/trees';
|
|
2
|
-
import { merge, pick } from '@aztec/foundation/collection';
|
|
3
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import { bufferToHex } from '@aztec/foundation/string';
|
|
5
|
-
import { Timer, elapsed } from '@aztec/foundation/timer';
|
|
6
|
-
import { getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
|
|
7
|
-
import { LightweightCheckpointBuilder } from '@aztec/prover-client/light';
|
|
8
|
-
import { GuardedMerkleTreeOperations, PublicContractsDB, PublicProcessor, createPublicTxSimulatorForBlockBuilding } from '@aztec/simulator/server';
|
|
9
|
-
import { Gas } from '@aztec/stdlib/gas';
|
|
10
|
-
import { FullNodeBlockBuilderConfigKeys } from '@aztec/stdlib/interfaces/server';
|
|
11
|
-
import { GlobalVariables } from '@aztec/stdlib/tx';
|
|
12
|
-
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
13
|
-
import { createValidatorForBlockBuilding } from '../tx_validator/tx_validator_factory.js';
|
|
14
|
-
const log = createLogger('checkpoint-builder');
|
|
15
|
-
/**
|
|
16
|
-
* Builder for a single checkpoint. Handles building blocks within the checkpoint
|
|
17
|
-
* and completing it.
|
|
18
|
-
*/ export class CheckpointBuilder {
|
|
19
|
-
checkpointBuilder;
|
|
20
|
-
fork;
|
|
21
|
-
config;
|
|
22
|
-
contractDataSource;
|
|
23
|
-
dateProvider;
|
|
24
|
-
telemetryClient;
|
|
25
|
-
constructor(checkpointBuilder, fork, config, contractDataSource, dateProvider, telemetryClient){
|
|
26
|
-
this.checkpointBuilder = checkpointBuilder;
|
|
27
|
-
this.fork = fork;
|
|
28
|
-
this.config = config;
|
|
29
|
-
this.contractDataSource = contractDataSource;
|
|
30
|
-
this.dateProvider = dateProvider;
|
|
31
|
-
this.telemetryClient = telemetryClient;
|
|
32
|
-
}
|
|
33
|
-
getConstantData() {
|
|
34
|
-
return this.checkpointBuilder.constants;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Builds a single block within this checkpoint.
|
|
38
|
-
*/ async buildBlock(pendingTxs, blockNumber, timestamp, opts) {
|
|
39
|
-
const blockBuildingTimer = new Timer();
|
|
40
|
-
const slot = this.checkpointBuilder.constants.slotNumber;
|
|
41
|
-
log.verbose(`Building block ${blockNumber} for slot ${slot} within checkpoint`, {
|
|
42
|
-
slot,
|
|
43
|
-
blockNumber,
|
|
44
|
-
...opts
|
|
45
|
-
});
|
|
46
|
-
const constants = this.checkpointBuilder.constants;
|
|
47
|
-
const globalVariables = GlobalVariables.from({
|
|
48
|
-
chainId: constants.chainId,
|
|
49
|
-
version: constants.version,
|
|
50
|
-
blockNumber,
|
|
51
|
-
slotNumber: constants.slotNumber,
|
|
52
|
-
timestamp,
|
|
53
|
-
coinbase: constants.coinbase,
|
|
54
|
-
feeRecipient: constants.feeRecipient,
|
|
55
|
-
gasFees: constants.gasFees
|
|
56
|
-
});
|
|
57
|
-
const { processor, validator } = await this.makeBlockBuilderDeps(globalVariables, this.fork);
|
|
58
|
-
const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(()=>processor.process(pendingTxs, opts, validator));
|
|
59
|
-
// Add block to checkpoint
|
|
60
|
-
const block = await this.checkpointBuilder.addBlock(globalVariables, processedTxs);
|
|
61
|
-
// How much public gas was processed
|
|
62
|
-
const publicGas = processedTxs.reduce((acc, tx)=>acc.add(tx.gasUsed.publicGas), Gas.empty());
|
|
63
|
-
const res = {
|
|
64
|
-
block,
|
|
65
|
-
publicGas,
|
|
66
|
-
publicProcessorDuration,
|
|
67
|
-
numTxs: processedTxs.length,
|
|
68
|
-
failedTxs,
|
|
69
|
-
blockBuildingTimer,
|
|
70
|
-
usedTxs
|
|
71
|
-
};
|
|
72
|
-
log.debug('Built block within checkpoint', res.block.header);
|
|
73
|
-
return res;
|
|
74
|
-
}
|
|
75
|
-
/** Completes the checkpoint and returns it. */ async completeCheckpoint() {
|
|
76
|
-
const checkpoint = await this.checkpointBuilder.completeCheckpoint();
|
|
77
|
-
log.verbose(`Completed checkpoint ${checkpoint.number}`, {
|
|
78
|
-
checkpointNumber: checkpoint.number,
|
|
79
|
-
numBlocks: checkpoint.blocks.length,
|
|
80
|
-
archiveRoot: checkpoint.archive.root.toString()
|
|
81
|
-
});
|
|
82
|
-
return checkpoint;
|
|
83
|
-
}
|
|
84
|
-
/** Gets the checkpoint currently in progress. */ getCheckpoint() {
|
|
85
|
-
return this.checkpointBuilder.clone().completeCheckpoint();
|
|
86
|
-
}
|
|
87
|
-
async makeBlockBuilderDeps(globalVariables, fork) {
|
|
88
|
-
const txPublicSetupAllowList = this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
|
|
89
|
-
const contractsDB = new PublicContractsDB(this.contractDataSource);
|
|
90
|
-
const guardedFork = new GuardedMerkleTreeOperations(fork);
|
|
91
|
-
const publicTxSimulator = createPublicTxSimulatorForBlockBuilding(guardedFork, contractsDB, globalVariables, this.telemetryClient);
|
|
92
|
-
const processor = new PublicProcessor(globalVariables, guardedFork, contractsDB, publicTxSimulator, this.dateProvider, this.telemetryClient, undefined, this.config);
|
|
93
|
-
const validator = createValidatorForBlockBuilding(fork, this.contractDataSource, globalVariables, txPublicSetupAllowList);
|
|
94
|
-
return {
|
|
95
|
-
processor,
|
|
96
|
-
validator
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Factory for creating checkpoint builders.
|
|
102
|
-
*/ export class FullNodeCheckpointsBuilder {
|
|
103
|
-
config;
|
|
104
|
-
contractDataSource;
|
|
105
|
-
dateProvider;
|
|
106
|
-
telemetryClient;
|
|
107
|
-
constructor(config, contractDataSource, dateProvider, telemetryClient = getTelemetryClient()){
|
|
108
|
-
this.config = config;
|
|
109
|
-
this.contractDataSource = contractDataSource;
|
|
110
|
-
this.dateProvider = dateProvider;
|
|
111
|
-
this.telemetryClient = telemetryClient;
|
|
112
|
-
}
|
|
113
|
-
updateConfig(config) {
|
|
114
|
-
this.config = merge(this.config, pick(config, ...FullNodeBlockBuilderConfigKeys));
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Starts a new checkpoint and returns a CheckpointBuilder to build blocks within it.
|
|
118
|
-
*/ async startCheckpoint(checkpointNumber, constants, l1ToL2Messages, fork) {
|
|
119
|
-
const stateReference = await fork.getStateReference();
|
|
120
|
-
const archiveTree = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
121
|
-
log.verbose(`Building checkpoint ${checkpointNumber}`, {
|
|
122
|
-
checkpointNumber,
|
|
123
|
-
msgCount: l1ToL2Messages.length,
|
|
124
|
-
initialStateReference: stateReference.toInspect(),
|
|
125
|
-
initialArchiveRoot: bufferToHex(archiveTree.root),
|
|
126
|
-
constants
|
|
127
|
-
});
|
|
128
|
-
const lightweightBuilder = await LightweightCheckpointBuilder.startNewCheckpoint(checkpointNumber, constants, l1ToL2Messages, fork);
|
|
129
|
-
return new CheckpointBuilder(lightweightBuilder, fork, this.config, this.contractDataSource, this.dateProvider, this.telemetryClient);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { NullifierSource } from '@aztec/p2p';
|
|
2
|
-
import type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
/**
|
|
4
|
-
* Implements a nullifier source by checking a DB and an in-memory collection.
|
|
5
|
-
* Intended for validating transactions as they are added to a block.
|
|
6
|
-
*/
|
|
7
|
-
export declare class NullifierCache implements NullifierSource {
|
|
8
|
-
private db;
|
|
9
|
-
nullifiers: Set<string>;
|
|
10
|
-
constructor(db: MerkleTreeReadOperations);
|
|
11
|
-
nullifiersExist(nullifiers: Buffer[]): Promise<boolean[]>;
|
|
12
|
-
addNullifiers(nullifiers: Buffer[]): void;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnVsbGlmaWVyX2NhY2hlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdHhfdmFsaWRhdG9yL251bGxpZmllcl9jYWNoZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxlQUFlLEVBQUUsTUFBTSxZQUFZLENBQUM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