@aztec/validator-client 0.0.1-commit.ee80a48 → 0.0.1-commit.ef17749e1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -18
- package/dest/block_proposal_handler.d.ts +3 -3
- package/dest/block_proposal_handler.d.ts.map +1 -1
- package/dest/block_proposal_handler.js +63 -58
- package/dest/checkpoint_builder.d.ts +15 -5
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +80 -25
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +26 -1
- package/dest/duties/validation_service.d.ts +2 -2
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +5 -11
- package/dest/factory.d.ts +1 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +2 -1
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/key_store/ha_key_store.d.ts +1 -1
- package/dest/key_store/ha_key_store.d.ts.map +1 -1
- package/dest/key_store/ha_key_store.js +2 -2
- package/dest/metrics.d.ts +9 -1
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +12 -0
- package/dest/validator.d.ts +35 -8
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +195 -33
- package/package.json +19 -19
- package/src/block_proposal_handler.ts +75 -76
- package/src/checkpoint_builder.ts +90 -14
- package/src/config.ts +26 -1
- package/src/duties/validation_service.ts +11 -10
- package/src/factory.ts +1 -0
- package/src/index.ts +0 -1
- package/src/key_store/ha_key_store.ts +2 -2
- package/src/metrics.ts +18 -0
- package/src/validator.ts +243 -38
- package/dest/tx_validator/index.d.ts +0 -3
- package/dest/tx_validator/index.d.ts.map +0 -1
- package/dest/tx_validator/index.js +0 -2
- 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 -19
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -54
- package/src/tx_validator/index.ts +0 -2
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -154
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
2
2
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
3
3
|
import { BlockNumber, CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
|
-
import {
|
|
4
|
+
import { pick } from '@aztec/foundation/collection';
|
|
5
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
6
|
import { TimeoutError } from '@aztec/foundation/error';
|
|
7
7
|
import { createLogger } from '@aztec/foundation/log';
|
|
@@ -9,16 +9,13 @@ import { retryUntil } from '@aztec/foundation/retry';
|
|
|
9
9
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
10
10
|
import type { P2P, PeerId } from '@aztec/p2p';
|
|
11
11
|
import { BlockProposalValidator } from '@aztec/p2p/msg_validators';
|
|
12
|
-
import type { L2Block, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
12
|
+
import type { BlockData, L2Block, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
13
13
|
import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
14
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
14
15
|
import type { ITxProvider, ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
15
|
-
import {
|
|
16
|
-
type L1ToL2MessageSource,
|
|
17
|
-
computeCheckpointOutHash,
|
|
18
|
-
computeInHashFromL1ToL2Messages,
|
|
19
|
-
} from '@aztec/stdlib/messaging';
|
|
16
|
+
import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
20
17
|
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
21
|
-
import {
|
|
18
|
+
import type { CheckpointGlobalVariables, FailedTx, Tx } from '@aztec/stdlib/tx';
|
|
22
19
|
import {
|
|
23
20
|
ReExFailedTxsError,
|
|
24
21
|
ReExStateMismatchError,
|
|
@@ -92,25 +89,28 @@ export class BlockProposalHandler {
|
|
|
92
89
|
this.tracer = telemetry.getTracer('BlockProposalHandler');
|
|
93
90
|
}
|
|
94
91
|
|
|
95
|
-
|
|
96
|
-
// Non-validator handler that re-executes for monitoring but does not attest.
|
|
92
|
+
register(p2pClient: P2P, shouldReexecute: boolean): BlockProposalHandler {
|
|
93
|
+
// Non-validator handler that processes or re-executes for monitoring but does not attest.
|
|
97
94
|
// Returns boolean indicating whether the proposal was valid.
|
|
98
95
|
const handler = async (proposal: BlockProposal, proposalSender: PeerId): Promise<boolean> => {
|
|
99
96
|
try {
|
|
100
|
-
const
|
|
97
|
+
const { slotNumber, blockNumber } = proposal;
|
|
98
|
+
const result = await this.handleBlockProposal(proposal, proposalSender, shouldReexecute);
|
|
101
99
|
if (result.isValid) {
|
|
102
|
-
this.log.info(`Non-validator
|
|
100
|
+
this.log.info(`Non-validator block proposal ${blockNumber} at slot ${slotNumber} handled`, {
|
|
103
101
|
blockNumber: result.blockNumber,
|
|
102
|
+
slotNumber,
|
|
104
103
|
reexecutionTimeMs: result.reexecutionResult?.reexecutionTimeMs,
|
|
105
104
|
totalManaUsed: result.reexecutionResult?.totalManaUsed,
|
|
106
105
|
numTxs: result.reexecutionResult?.block?.body?.txEffects?.length ?? 0,
|
|
106
|
+
reexecuted: shouldReexecute,
|
|
107
107
|
});
|
|
108
108
|
return true;
|
|
109
109
|
} else {
|
|
110
|
-
this.log.warn(
|
|
111
|
-
blockNumber
|
|
112
|
-
reason: result.reason,
|
|
113
|
-
|
|
110
|
+
this.log.warn(
|
|
111
|
+
`Non-validator block proposal ${blockNumber} at slot ${slotNumber} failed processing with ${result.reason}`,
|
|
112
|
+
{ blockNumber: result.blockNumber, slotNumber, reason: result.reason },
|
|
113
|
+
);
|
|
114
114
|
return false;
|
|
115
115
|
}
|
|
116
116
|
} catch (error) {
|
|
@@ -153,16 +153,16 @@ export class BlockProposalHandler {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
// Check that the parent proposal is a block we know, otherwise reexecution would fail
|
|
156
|
-
const
|
|
157
|
-
if (
|
|
156
|
+
const parentBlock = await this.getParentBlock(proposal);
|
|
157
|
+
if (parentBlock === undefined) {
|
|
158
158
|
this.log.warn(`Parent block for proposal not found, skipping processing`, proposalInfo);
|
|
159
159
|
return { isValid: false, reason: 'parent_block_not_found' };
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
// Check that the parent block's slot is not greater than the proposal's slot.
|
|
163
|
-
if (
|
|
163
|
+
if (parentBlock !== 'genesis' && parentBlock.header.getSlot() > slotNumber) {
|
|
164
164
|
this.log.warn(`Parent block slot is greater than proposal slot, skipping processing`, {
|
|
165
|
-
parentBlockSlot:
|
|
165
|
+
parentBlockSlot: parentBlock.header.getSlot().toString(),
|
|
166
166
|
proposalSlot: slotNumber.toString(),
|
|
167
167
|
...proposalInfo,
|
|
168
168
|
});
|
|
@@ -171,9 +171,9 @@ export class BlockProposalHandler {
|
|
|
171
171
|
|
|
172
172
|
// Compute the block number based on the parent block
|
|
173
173
|
const blockNumber =
|
|
174
|
-
|
|
174
|
+
parentBlock === 'genesis'
|
|
175
175
|
? BlockNumber(INITIAL_L2_BLOCK_NUM)
|
|
176
|
-
: BlockNumber(
|
|
176
|
+
: BlockNumber(parentBlock.header.getBlockNumber() + 1);
|
|
177
177
|
|
|
178
178
|
// Check that this block number does not exist already
|
|
179
179
|
const existingBlock = await this.blockSource.getBlockHeader(blockNumber);
|
|
@@ -189,8 +189,17 @@ export class BlockProposalHandler {
|
|
|
189
189
|
deadline: this.getReexecutionDeadline(slotNumber, config),
|
|
190
190
|
});
|
|
191
191
|
|
|
192
|
+
// If reexecution is disabled, bail. We are just interested in triggering tx collection.
|
|
193
|
+
if (!shouldReexecute) {
|
|
194
|
+
this.log.info(
|
|
195
|
+
`Received valid block ${blockNumber} proposal at index ${proposal.indexWithinCheckpoint} on slot ${slotNumber}`,
|
|
196
|
+
proposalInfo,
|
|
197
|
+
);
|
|
198
|
+
return { isValid: true, blockNumber };
|
|
199
|
+
}
|
|
200
|
+
|
|
192
201
|
// Compute the checkpoint number for this block and validate checkpoint consistency
|
|
193
|
-
const checkpointResult =
|
|
202
|
+
const checkpointResult = this.computeCheckpointNumber(proposal, parentBlock, proposalInfo);
|
|
194
203
|
if (checkpointResult.reason) {
|
|
195
204
|
return { isValid: false, blockNumber, reason: checkpointResult.reason };
|
|
196
205
|
}
|
|
@@ -215,36 +224,28 @@ export class BlockProposalHandler {
|
|
|
215
224
|
return { isValid: false, blockNumber, reason: 'txs_not_available' };
|
|
216
225
|
}
|
|
217
226
|
|
|
227
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
228
|
+
const epoch = getEpochAtSlot(slotNumber, this.epochCache.getL1Constants());
|
|
229
|
+
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch))
|
|
230
|
+
.filter(c => c.checkpointNumber < checkpointNumber)
|
|
231
|
+
.map(c => c.checkpointOutHash);
|
|
232
|
+
|
|
218
233
|
// Try re-executing the transactions in the proposal if needed
|
|
219
234
|
let reexecutionResult;
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const previousCheckpointOutHashes = blocksByCheckpoint.map(checkpointBlocks =>
|
|
230
|
-
computeCheckpointOutHash(checkpointBlocks.map(b => b.block.body.txEffects.map(tx => tx.l2ToL1Msgs))),
|
|
235
|
+
try {
|
|
236
|
+
this.log.verbose(`Re-executing transactions in the proposal`, proposalInfo);
|
|
237
|
+
reexecutionResult = await this.reexecuteTransactions(
|
|
238
|
+
proposal,
|
|
239
|
+
blockNumber,
|
|
240
|
+
checkpointNumber,
|
|
241
|
+
txs,
|
|
242
|
+
l1ToL2Messages,
|
|
243
|
+
previousCheckpointOutHashes,
|
|
231
244
|
);
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
proposal,
|
|
237
|
-
blockNumber,
|
|
238
|
-
checkpointNumber,
|
|
239
|
-
txs,
|
|
240
|
-
l1ToL2Messages,
|
|
241
|
-
previousCheckpointOutHashes,
|
|
242
|
-
);
|
|
243
|
-
} catch (error) {
|
|
244
|
-
this.log.error(`Error reexecuting txs while processing block proposal`, error, proposalInfo);
|
|
245
|
-
const reason = this.getReexecuteFailureReason(error);
|
|
246
|
-
return { isValid: false, blockNumber, reason, reexecutionResult };
|
|
247
|
-
}
|
|
245
|
+
} catch (error) {
|
|
246
|
+
this.log.error(`Error reexecuting txs while processing block proposal`, error, proposalInfo);
|
|
247
|
+
const reason = this.getReexecuteFailureReason(error);
|
|
248
|
+
return { isValid: false, blockNumber, reason, reexecutionResult };
|
|
248
249
|
}
|
|
249
250
|
|
|
250
251
|
// If we succeeded, push this block into the archiver (unless disabled)
|
|
@@ -253,14 +254,14 @@ export class BlockProposalHandler {
|
|
|
253
254
|
}
|
|
254
255
|
|
|
255
256
|
this.log.info(
|
|
256
|
-
`Successfully
|
|
257
|
-
proposalInfo,
|
|
257
|
+
`Successfully re-executed block ${blockNumber} proposal at index ${proposal.indexWithinCheckpoint} on slot ${slotNumber}`,
|
|
258
|
+
{ ...proposalInfo, ...pick(reexecutionResult, 'reexecutionTimeMs', 'totalManaUsed') },
|
|
258
259
|
);
|
|
259
260
|
|
|
260
261
|
return { isValid: true, blockNumber, reexecutionResult };
|
|
261
262
|
}
|
|
262
263
|
|
|
263
|
-
private async getParentBlock(proposal: BlockProposal): Promise<'genesis' |
|
|
264
|
+
private async getParentBlock(proposal: BlockProposal): Promise<'genesis' | BlockData | undefined> {
|
|
264
265
|
const parentArchive = proposal.blockHeader.lastArchive.root;
|
|
265
266
|
const slot = proposal.slotNumber;
|
|
266
267
|
const config = this.checkpointsBuilder.getConfig();
|
|
@@ -276,12 +277,11 @@ export class BlockProposalHandler {
|
|
|
276
277
|
|
|
277
278
|
try {
|
|
278
279
|
return (
|
|
279
|
-
(await this.blockSource.
|
|
280
|
+
(await this.blockSource.getBlockDataByArchive(parentArchive)) ??
|
|
280
281
|
(timeoutDurationMs <= 0
|
|
281
282
|
? undefined
|
|
282
283
|
: await retryUntil(
|
|
283
|
-
() =>
|
|
284
|
-
this.blockSource.syncImmediate().then(() => this.blockSource.getBlockHeaderByArchive(parentArchive)),
|
|
284
|
+
() => this.blockSource.syncImmediate().then(() => this.blockSource.getBlockDataByArchive(parentArchive)),
|
|
285
285
|
'force archiver sync',
|
|
286
286
|
timeoutDurationMs / 1000,
|
|
287
287
|
0.5,
|
|
@@ -297,12 +297,12 @@ export class BlockProposalHandler {
|
|
|
297
297
|
}
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
-
private
|
|
300
|
+
private computeCheckpointNumber(
|
|
301
301
|
proposal: BlockProposal,
|
|
302
|
-
|
|
302
|
+
parentBlock: 'genesis' | BlockData,
|
|
303
303
|
proposalInfo: object,
|
|
304
|
-
):
|
|
305
|
-
if (
|
|
304
|
+
): CheckpointComputationResult {
|
|
305
|
+
if (parentBlock === 'genesis') {
|
|
306
306
|
// First block is in checkpoint 1
|
|
307
307
|
if (proposal.indexWithinCheckpoint !== 0) {
|
|
308
308
|
this.log.warn(`First block proposal has non-zero indexWithinCheckpoint`, proposalInfo);
|
|
@@ -311,19 +311,9 @@ export class BlockProposalHandler {
|
|
|
311
311
|
return { checkpointNumber: CheckpointNumber.INITIAL };
|
|
312
312
|
}
|
|
313
313
|
|
|
314
|
-
// Get the parent block to find its checkpoint number
|
|
315
|
-
// TODO(palla/mbps): The block header should include the checkpoint number to avoid this lookup,
|
|
316
|
-
// or at least the L2BlockSource should return a different struct that includes it.
|
|
317
|
-
const parentBlockNumber = parentBlockHeader.getBlockNumber();
|
|
318
|
-
const parentBlock = await this.blockSource.getL2Block(parentBlockNumber);
|
|
319
|
-
if (!parentBlock) {
|
|
320
|
-
this.log.warn(`Parent block ${parentBlockNumber} not found in archiver`, proposalInfo);
|
|
321
|
-
return { reason: 'invalid_proposal' };
|
|
322
|
-
}
|
|
323
|
-
|
|
324
314
|
if (proposal.indexWithinCheckpoint === 0) {
|
|
325
315
|
// If this is the first block in a new checkpoint, increment the checkpoint number
|
|
326
|
-
if (!(proposal.blockHeader.getSlot() >
|
|
316
|
+
if (!(proposal.blockHeader.getSlot() > parentBlock.header.getSlot())) {
|
|
327
317
|
this.log.warn(`Slot should be greater than parent block slot for first block in checkpoint`, proposalInfo);
|
|
328
318
|
return { reason: 'invalid_proposal' };
|
|
329
319
|
}
|
|
@@ -335,7 +325,7 @@ export class BlockProposalHandler {
|
|
|
335
325
|
this.log.warn(`Non-sequential indexWithinCheckpoint`, proposalInfo);
|
|
336
326
|
return { reason: 'invalid_proposal' };
|
|
337
327
|
}
|
|
338
|
-
if (proposal.blockHeader.getSlot() !==
|
|
328
|
+
if (proposal.blockHeader.getSlot() !== parentBlock.header.getSlot()) {
|
|
339
329
|
this.log.warn(`Slot should be equal to parent block slot for non-first block in checkpoint`, proposalInfo);
|
|
340
330
|
return { reason: 'invalid_proposal' };
|
|
341
331
|
}
|
|
@@ -356,7 +346,7 @@ export class BlockProposalHandler {
|
|
|
356
346
|
*/
|
|
357
347
|
private validateNonFirstBlockInCheckpoint(
|
|
358
348
|
proposal: BlockProposal,
|
|
359
|
-
parentBlock:
|
|
349
|
+
parentBlock: BlockData,
|
|
360
350
|
proposalInfo: object,
|
|
361
351
|
): CheckpointComputationResult | undefined {
|
|
362
352
|
const proposalGlobals = proposal.blockHeader.globalVariables;
|
|
@@ -475,13 +465,14 @@ export class BlockProposalHandler {
|
|
|
475
465
|
// Fork before the block to be built
|
|
476
466
|
const parentBlockNumber = BlockNumber(blockNumber - 1);
|
|
477
467
|
await this.worldState.syncImmediate(parentBlockNumber);
|
|
478
|
-
using fork = await this.worldState.fork(parentBlockNumber);
|
|
468
|
+
await using fork = await this.worldState.fork(parentBlockNumber);
|
|
479
469
|
|
|
480
|
-
// Build checkpoint constants from proposal (excludes blockNumber
|
|
470
|
+
// Build checkpoint constants from proposal (excludes blockNumber which is per-block)
|
|
481
471
|
const constants: CheckpointGlobalVariables = {
|
|
482
472
|
chainId: new Fr(config.l1ChainId),
|
|
483
473
|
version: new Fr(config.rollupVersion),
|
|
484
474
|
slotNumber: slot,
|
|
475
|
+
timestamp: blockHeader.globalVariables.timestamp,
|
|
485
476
|
coinbase: blockHeader.globalVariables.coinbase,
|
|
486
477
|
feeRecipient: blockHeader.globalVariables.feeRecipient,
|
|
487
478
|
gasFees: blockHeader.globalVariables.gasFees,
|
|
@@ -491,6 +482,7 @@ export class BlockProposalHandler {
|
|
|
491
482
|
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
|
|
492
483
|
checkpointNumber,
|
|
493
484
|
constants,
|
|
485
|
+
0n, // only takes effect in the following checkpoint.
|
|
494
486
|
l1ToL2Messages,
|
|
495
487
|
previousCheckpointOutHashes,
|
|
496
488
|
fork,
|
|
@@ -500,18 +492,25 @@ export class BlockProposalHandler {
|
|
|
500
492
|
|
|
501
493
|
// Build the new block
|
|
502
494
|
const deadline = this.getReexecutionDeadline(slot, config);
|
|
495
|
+
const maxBlockGas =
|
|
496
|
+
this.config.validateMaxL2BlockGas !== undefined || this.config.validateMaxDABlockGas !== undefined
|
|
497
|
+
? new Gas(this.config.validateMaxDABlockGas ?? Infinity, this.config.validateMaxL2BlockGas ?? Infinity)
|
|
498
|
+
: undefined;
|
|
503
499
|
const result = await checkpointBuilder.buildBlock(txs, blockNumber, blockHeader.globalVariables.timestamp, {
|
|
504
500
|
deadline,
|
|
505
501
|
expectedEndState: blockHeader.state,
|
|
502
|
+
maxTransactions: this.config.validateMaxTxsPerBlock,
|
|
503
|
+
maxBlockGas,
|
|
506
504
|
});
|
|
507
505
|
|
|
508
506
|
const { block, failedTxs } = result;
|
|
509
507
|
const numFailedTxs = failedTxs.length;
|
|
510
508
|
|
|
511
|
-
this.log.verbose(`
|
|
509
|
+
this.log.verbose(`Block proposal ${blockNumber} at slot ${slot} transaction re-execution complete`, {
|
|
512
510
|
numFailedTxs,
|
|
513
511
|
numProposalTxs: txHashes.length,
|
|
514
512
|
numProcessedTxs: block.body.txEffects.length,
|
|
513
|
+
blockNumber,
|
|
515
514
|
slot,
|
|
516
515
|
});
|
|
517
516
|
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { NUM_CHECKPOINT_END_MARKER_FIELDS, getNumBlockEndBlobFields } from '@aztec/blob-lib/encoding';
|
|
2
|
+
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB, MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT } from '@aztec/constants';
|
|
1
3
|
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { merge, pick } from '@aztec/foundation/collection';
|
|
4
|
+
import { merge, pick, sum } from '@aztec/foundation/collection';
|
|
3
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
6
|
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
5
7
|
import { bufferToHex } from '@aztec/foundation/string';
|
|
6
8
|
import { DateProvider, elapsed } from '@aztec/foundation/timer';
|
|
7
|
-
import { getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
|
|
9
|
+
import { createTxValidatorForBlockBuilding, getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
|
|
8
10
|
import { LightweightCheckpointBuilder } from '@aztec/prover-client/light';
|
|
9
11
|
import {
|
|
10
12
|
GuardedMerkleTreeOperations,
|
|
@@ -28,12 +30,11 @@ import {
|
|
|
28
30
|
type PublicProcessorLimits,
|
|
29
31
|
type WorldStateSynchronizer,
|
|
30
32
|
} from '@aztec/stdlib/interfaces/server';
|
|
33
|
+
import { type DebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
31
34
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
32
35
|
import { type CheckpointGlobalVariables, GlobalVariables, StateReference, Tx } from '@aztec/stdlib/tx';
|
|
33
36
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
34
37
|
|
|
35
|
-
import { createValidatorForBlockBuilding } from './tx_validator/tx_validator_factory.js';
|
|
36
|
-
|
|
37
38
|
// Re-export for backward compatibility
|
|
38
39
|
export type { BuildBlockInCheckpointResult } from '@aztec/stdlib/interfaces/server';
|
|
39
40
|
|
|
@@ -52,6 +53,7 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
52
53
|
private dateProvider: DateProvider,
|
|
53
54
|
private telemetryClient: TelemetryClient,
|
|
54
55
|
bindings?: LoggerBindings,
|
|
56
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
55
57
|
) {
|
|
56
58
|
this.log = createLogger('checkpoint-builder', {
|
|
57
59
|
...bindings,
|
|
@@ -65,6 +67,7 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
65
67
|
|
|
66
68
|
/**
|
|
67
69
|
* Builds a single block within this checkpoint.
|
|
70
|
+
* Automatically caps gas and blob field limits based on checkpoint-level budgets and prior blocks.
|
|
68
71
|
*/
|
|
69
72
|
async buildBlock(
|
|
70
73
|
pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
@@ -94,8 +97,14 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
94
97
|
});
|
|
95
98
|
const { processor, validator } = await this.makeBlockBuilderDeps(globalVariables, this.fork);
|
|
96
99
|
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
// Cap gas limits amd available blob fields by remaining checkpoint-level budgets
|
|
101
|
+
const cappedOpts: PublicProcessorLimits & { expectedEndState?: StateReference } = {
|
|
102
|
+
...opts,
|
|
103
|
+
...this.capLimitsByCheckpointBudgets(opts),
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(() =>
|
|
107
|
+
processor.process(pendingTxs, cappedOpts, validator),
|
|
99
108
|
);
|
|
100
109
|
|
|
101
110
|
// Throw if we didn't collect a single valid tx and we're not allowed to build empty blocks
|
|
@@ -105,13 +114,10 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
105
114
|
}
|
|
106
115
|
|
|
107
116
|
// Add block to checkpoint
|
|
108
|
-
const block = await this.checkpointBuilder.addBlock(globalVariables, processedTxs, {
|
|
117
|
+
const { block } = await this.checkpointBuilder.addBlock(globalVariables, processedTxs, {
|
|
109
118
|
expectedEndState: opts.expectedEndState,
|
|
110
119
|
});
|
|
111
120
|
|
|
112
|
-
// How much public gas was processed
|
|
113
|
-
const publicGas = processedTxs.reduce((acc, tx) => acc.add(tx.gasUsed.publicGas), Gas.empty());
|
|
114
|
-
|
|
115
121
|
this.log.debug('Built block within checkpoint', {
|
|
116
122
|
header: block.header.toInspect(),
|
|
117
123
|
processedTxs: processedTxs.map(tx => tx.hash.toString()),
|
|
@@ -120,12 +126,10 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
120
126
|
|
|
121
127
|
return {
|
|
122
128
|
block,
|
|
123
|
-
publicGas,
|
|
124
129
|
publicProcessorDuration,
|
|
125
130
|
numTxs: processedTxs.length,
|
|
126
131
|
failedTxs,
|
|
127
132
|
usedTxs,
|
|
128
|
-
usedTxBlobFields,
|
|
129
133
|
};
|
|
130
134
|
}
|
|
131
135
|
|
|
@@ -147,11 +151,71 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
147
151
|
return this.checkpointBuilder.clone().completeCheckpoint();
|
|
148
152
|
}
|
|
149
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Caps per-block gas and blob field limits by remaining checkpoint-level budgets.
|
|
156
|
+
* Computes remaining L2 gas (mana), DA gas, and blob fields from blocks already added to the checkpoint,
|
|
157
|
+
* then returns opts with maxBlockGas and maxBlobFields capped accordingly.
|
|
158
|
+
*/
|
|
159
|
+
protected capLimitsByCheckpointBudgets(
|
|
160
|
+
opts: PublicProcessorLimits,
|
|
161
|
+
): Pick<PublicProcessorLimits, 'maxBlockGas' | 'maxBlobFields' | 'maxTransactions'> {
|
|
162
|
+
const existingBlocks = this.checkpointBuilder.getBlocks();
|
|
163
|
+
|
|
164
|
+
// Remaining L2 gas (mana)
|
|
165
|
+
// IMPORTANT: This assumes mana is computed solely based on L2 gas used in transactions.
|
|
166
|
+
// This may change in the future.
|
|
167
|
+
const usedMana = sum(existingBlocks.map(b => b.header.totalManaUsed.toNumber()));
|
|
168
|
+
const remainingMana = this.config.rollupManaLimit - usedMana;
|
|
169
|
+
|
|
170
|
+
// Remaining DA gas
|
|
171
|
+
const usedDAGas = sum(existingBlocks.map(b => b.computeDAGasUsed())) ?? 0;
|
|
172
|
+
const remainingDAGas = MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT - usedDAGas;
|
|
173
|
+
|
|
174
|
+
// Remaining blob fields (block blob fields include both tx data and block-end overhead)
|
|
175
|
+
const usedBlobFields = sum(existingBlocks.map(b => b.toBlobFields().length));
|
|
176
|
+
const totalBlobCapacity = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
|
|
177
|
+
const isFirstBlock = existingBlocks.length === 0;
|
|
178
|
+
const blockEndOverhead = getNumBlockEndBlobFields(isFirstBlock);
|
|
179
|
+
const maxBlobFieldsForTxs = totalBlobCapacity - usedBlobFields - blockEndOverhead;
|
|
180
|
+
|
|
181
|
+
// Cap L2 gas by remaining checkpoint mana
|
|
182
|
+
const cappedL2Gas = Math.min(opts.maxBlockGas?.l2Gas ?? remainingMana, remainingMana);
|
|
183
|
+
|
|
184
|
+
// Cap DA gas by remaining checkpoint DA gas budget
|
|
185
|
+
const cappedDAGas = Math.min(opts.maxBlockGas?.daGas ?? remainingDAGas, remainingDAGas);
|
|
186
|
+
|
|
187
|
+
// Cap blob fields by remaining checkpoint blob capacity
|
|
188
|
+
const cappedBlobFields =
|
|
189
|
+
opts.maxBlobFields !== undefined ? Math.min(opts.maxBlobFields, maxBlobFieldsForTxs) : maxBlobFieldsForTxs;
|
|
190
|
+
|
|
191
|
+
// Cap transaction count by remaining checkpoint tx budget
|
|
192
|
+
let cappedMaxTransactions: number | undefined;
|
|
193
|
+
if (this.config.maxTxsPerCheckpoint !== undefined) {
|
|
194
|
+
const usedTxs = sum(existingBlocks.map(b => b.body.txEffects.length));
|
|
195
|
+
const remainingTxs = Math.max(0, this.config.maxTxsPerCheckpoint - usedTxs);
|
|
196
|
+
cappedMaxTransactions =
|
|
197
|
+
opts.maxTransactions !== undefined ? Math.min(opts.maxTransactions, remainingTxs) : remainingTxs;
|
|
198
|
+
} else {
|
|
199
|
+
cappedMaxTransactions = opts.maxTransactions;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
maxBlockGas: new Gas(cappedDAGas, cappedL2Gas),
|
|
204
|
+
maxBlobFields: cappedBlobFields,
|
|
205
|
+
maxTransactions: cappedMaxTransactions,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
150
209
|
protected async makeBlockBuilderDeps(globalVariables: GlobalVariables, fork: MerkleTreeWriteOperations) {
|
|
151
|
-
const txPublicSetupAllowList =
|
|
210
|
+
const txPublicSetupAllowList = [
|
|
211
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
212
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
213
|
+
];
|
|
152
214
|
const contractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings());
|
|
153
215
|
const guardedFork = new GuardedMerkleTreeOperations(fork);
|
|
154
216
|
|
|
217
|
+
const collectDebugLogs = this.debugLogStore.isEnabled;
|
|
218
|
+
|
|
155
219
|
const bindings = this.log.getBindings();
|
|
156
220
|
const publicTxSimulator = createPublicTxSimulatorForBlockBuilding(
|
|
157
221
|
guardedFork,
|
|
@@ -159,6 +223,7 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
159
223
|
globalVariables,
|
|
160
224
|
this.telemetryClient,
|
|
161
225
|
bindings,
|
|
226
|
+
collectDebugLogs,
|
|
162
227
|
);
|
|
163
228
|
|
|
164
229
|
const processor = new PublicProcessor(
|
|
@@ -170,9 +235,10 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
170
235
|
this.telemetryClient,
|
|
171
236
|
createLogger('simulator:public-processor', bindings),
|
|
172
237
|
this.config,
|
|
238
|
+
this.debugLogStore,
|
|
173
239
|
);
|
|
174
240
|
|
|
175
|
-
const validator =
|
|
241
|
+
const validator = createTxValidatorForBlockBuilding(
|
|
176
242
|
fork,
|
|
177
243
|
this.contractDataSource,
|
|
178
244
|
globalVariables,
|
|
@@ -197,6 +263,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
197
263
|
private contractDataSource: ContractDataSource,
|
|
198
264
|
private dateProvider: DateProvider,
|
|
199
265
|
private telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
266
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
200
267
|
) {
|
|
201
268
|
this.log = createLogger('checkpoint-builder');
|
|
202
269
|
}
|
|
@@ -215,6 +282,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
215
282
|
async startCheckpoint(
|
|
216
283
|
checkpointNumber: CheckpointNumber,
|
|
217
284
|
constants: CheckpointGlobalVariables,
|
|
285
|
+
feeAssetPriceModifier: bigint,
|
|
218
286
|
l1ToL2Messages: Fr[],
|
|
219
287
|
previousCheckpointOutHashes: Fr[],
|
|
220
288
|
fork: MerkleTreeWriteOperations,
|
|
@@ -229,6 +297,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
229
297
|
initialStateReference: stateReference.toInspect(),
|
|
230
298
|
initialArchiveRoot: bufferToHex(archiveTree.root),
|
|
231
299
|
constants,
|
|
300
|
+
feeAssetPriceModifier,
|
|
232
301
|
});
|
|
233
302
|
|
|
234
303
|
const lightweightBuilder = await LightweightCheckpointBuilder.startNewCheckpoint(
|
|
@@ -238,6 +307,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
238
307
|
previousCheckpointOutHashes,
|
|
239
308
|
fork,
|
|
240
309
|
bindings,
|
|
310
|
+
feeAssetPriceModifier,
|
|
241
311
|
);
|
|
242
312
|
|
|
243
313
|
return new CheckpointBuilder(
|
|
@@ -248,6 +318,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
248
318
|
this.dateProvider,
|
|
249
319
|
this.telemetryClient,
|
|
250
320
|
bindings,
|
|
321
|
+
this.debugLogStore,
|
|
251
322
|
);
|
|
252
323
|
}
|
|
253
324
|
|
|
@@ -257,6 +328,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
257
328
|
async openCheckpoint(
|
|
258
329
|
checkpointNumber: CheckpointNumber,
|
|
259
330
|
constants: CheckpointGlobalVariables,
|
|
331
|
+
feeAssetPriceModifier: bigint,
|
|
260
332
|
l1ToL2Messages: Fr[],
|
|
261
333
|
previousCheckpointOutHashes: Fr[],
|
|
262
334
|
fork: MerkleTreeWriteOperations,
|
|
@@ -270,6 +342,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
270
342
|
return this.startCheckpoint(
|
|
271
343
|
checkpointNumber,
|
|
272
344
|
constants,
|
|
345
|
+
feeAssetPriceModifier,
|
|
273
346
|
l1ToL2Messages,
|
|
274
347
|
previousCheckpointOutHashes,
|
|
275
348
|
fork,
|
|
@@ -284,11 +357,13 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
284
357
|
initialStateReference: stateReference.toInspect(),
|
|
285
358
|
initialArchiveRoot: bufferToHex(archiveTree.root),
|
|
286
359
|
constants,
|
|
360
|
+
feeAssetPriceModifier,
|
|
287
361
|
});
|
|
288
362
|
|
|
289
363
|
const lightweightBuilder = await LightweightCheckpointBuilder.resumeCheckpoint(
|
|
290
364
|
checkpointNumber,
|
|
291
365
|
constants,
|
|
366
|
+
feeAssetPriceModifier,
|
|
292
367
|
l1ToL2Messages,
|
|
293
368
|
previousCheckpointOutHashes,
|
|
294
369
|
fork,
|
|
@@ -304,6 +379,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
304
379
|
this.dateProvider,
|
|
305
380
|
this.telemetryClient,
|
|
306
381
|
bindings,
|
|
382
|
+
this.debugLogStore,
|
|
307
383
|
);
|
|
308
384
|
}
|
|
309
385
|
|
package/src/config.ts
CHANGED
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
secretValueConfigHelper,
|
|
7
7
|
} from '@aztec/foundation/config';
|
|
8
8
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
9
|
+
import { localSignerConfigMappings, validatorHASignerConfigMappings } from '@aztec/stdlib/ha-signing';
|
|
9
10
|
import type { ValidatorClientConfig } from '@aztec/stdlib/interfaces/server';
|
|
10
|
-
import { validatorHASignerConfigMappings } from '@aztec/validator-ha-signer/config';
|
|
11
11
|
|
|
12
12
|
export type { ValidatorClientConfig };
|
|
13
13
|
|
|
@@ -73,6 +73,31 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
|
|
|
73
73
|
description: 'Skip pushing re-executed blocks to archiver (default: false)',
|
|
74
74
|
defaultValue: false,
|
|
75
75
|
},
|
|
76
|
+
attestToEquivocatedProposals: {
|
|
77
|
+
description: 'Agree to attest to equivocated checkpoint proposals (for testing purposes only)',
|
|
78
|
+
...booleanConfigHelper(false),
|
|
79
|
+
},
|
|
80
|
+
validateMaxL2BlockGas: {
|
|
81
|
+
env: 'VALIDATOR_MAX_L2_BLOCK_GAS',
|
|
82
|
+
description: 'Maximum L2 block gas for validation. Proposals exceeding this limit are rejected.',
|
|
83
|
+
parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
|
|
84
|
+
},
|
|
85
|
+
validateMaxDABlockGas: {
|
|
86
|
+
env: 'VALIDATOR_MAX_DA_BLOCK_GAS',
|
|
87
|
+
description: 'Maximum DA block gas for validation. Proposals exceeding this limit are rejected.',
|
|
88
|
+
parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
|
|
89
|
+
},
|
|
90
|
+
validateMaxTxsPerBlock: {
|
|
91
|
+
env: 'VALIDATOR_MAX_TX_PER_BLOCK',
|
|
92
|
+
description: 'Maximum transactions per block for validation. Proposals exceeding this limit are rejected.',
|
|
93
|
+
parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
|
|
94
|
+
},
|
|
95
|
+
validateMaxTxsPerCheckpoint: {
|
|
96
|
+
env: 'VALIDATOR_MAX_TX_PER_CHECKPOINT',
|
|
97
|
+
description: 'Maximum transactions per checkpoint for validation. Proposals exceeding this limit are rejected.',
|
|
98
|
+
parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
|
|
99
|
+
},
|
|
100
|
+
...localSignerConfigMappings,
|
|
76
101
|
...validatorHASignerConfigMappings,
|
|
77
102
|
};
|
|
78
103
|
|
|
@@ -95,6 +95,7 @@ export class ValidationService {
|
|
|
95
95
|
public createCheckpointProposal(
|
|
96
96
|
checkpointHeader: CheckpointHeader,
|
|
97
97
|
archive: Fr,
|
|
98
|
+
feeAssetPriceModifier: bigint,
|
|
98
99
|
lastBlockInfo: CreateCheckpointProposalLastBlockData | undefined,
|
|
99
100
|
proposerAttesterAddress: EthAddress | undefined,
|
|
100
101
|
options: CheckpointProposalOptions,
|
|
@@ -119,7 +120,13 @@ export class ValidationService {
|
|
|
119
120
|
txs: options.publishFullTxs ? lastBlockInfo.txs : undefined,
|
|
120
121
|
};
|
|
121
122
|
|
|
122
|
-
return CheckpointProposal.createProposalFromSigner(
|
|
123
|
+
return CheckpointProposal.createProposalFromSigner(
|
|
124
|
+
checkpointHeader,
|
|
125
|
+
archive,
|
|
126
|
+
feeAssetPriceModifier,
|
|
127
|
+
lastBlock,
|
|
128
|
+
payloadSigner,
|
|
129
|
+
);
|
|
123
130
|
}
|
|
124
131
|
|
|
125
132
|
/**
|
|
@@ -137,22 +144,16 @@ export class ValidationService {
|
|
|
137
144
|
attestors: EthAddress[],
|
|
138
145
|
): Promise<CheckpointAttestation[]> {
|
|
139
146
|
// Create the attestation payload from the checkpoint proposal
|
|
140
|
-
const payload = new ConsensusPayload(proposal.checkpointHeader, proposal.archive);
|
|
147
|
+
const payload = new ConsensusPayload(proposal.checkpointHeader, proposal.archive, proposal.feeAssetPriceModifier);
|
|
141
148
|
const buf = Buffer32.fromBuffer(
|
|
142
149
|
keccak256(payload.getPayloadToSign(SignatureDomainSeparator.checkpointAttestation)),
|
|
143
150
|
);
|
|
144
151
|
|
|
145
152
|
// TODO(spy/ha): Use checkpointNumber instead of blockNumber once CheckpointHeader includes it.
|
|
146
|
-
//
|
|
153
|
+
// CheckpointProposalCore doesn't have lastBlock info, so use 0 as a proxy.
|
|
147
154
|
// blockNumber is NOT used for the primary key so it's safe to use here.
|
|
148
155
|
// See CheckpointHeader TODO and SigningContext types documentation.
|
|
149
|
-
|
|
150
|
-
try {
|
|
151
|
-
blockNumber = proposal.blockNumber;
|
|
152
|
-
} catch {
|
|
153
|
-
// Checkpoint proposal may not have lastBlock, use 0 as fallback
|
|
154
|
-
blockNumber = BlockNumber(0);
|
|
155
|
-
}
|
|
156
|
+
const blockNumber = BlockNumber(0);
|
|
156
157
|
const context: SigningContext = {
|
|
157
158
|
slot: proposal.slotNumber,
|
|
158
159
|
blockNumber,
|
package/src/factory.ts
CHANGED
|
@@ -29,6 +29,7 @@ export function createBlockProposalHandler(
|
|
|
29
29
|
const metrics = new ValidatorMetrics(deps.telemetry);
|
|
30
30
|
const blockProposalValidator = new BlockProposalValidator(deps.epochCache, {
|
|
31
31
|
txsPermitted: !config.disableTransactions,
|
|
32
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock,
|
|
32
33
|
});
|
|
33
34
|
return new BlockProposalHandler(
|
|
34
35
|
deps.checkpointsBuilder,
|
package/src/index.ts
CHANGED