@aztec/validator-client 0.0.1-commit.e0f15ab9b → 0.0.1-commit.e304674f1
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 +0 -2
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +0 -5
- package/dest/duties/validation_service.d.ts +3 -4
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +7 -12
- package/dest/factory.d.ts +5 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +3 -3
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/metrics.d.ts +2 -2
- package/dest/metrics.d.ts.map +1 -1
- package/dest/proposal_handler.d.ts +107 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/{block_proposal_handler.js → proposal_handler.js} +368 -16
- package/dest/validator.d.ts +8 -13
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +20 -197
- package/package.json +19 -19
- package/src/config.ts +0 -5
- package/src/duties/validation_service.ts +7 -14
- package/src/factory.ts +5 -3
- package/src/index.ts +1 -1
- package/src/metrics.ts +1 -1
- package/src/{block_proposal_handler.ts → proposal_handler.ts} +418 -17
- package/src/validator.ts +23 -212
- package/dest/block_proposal_handler.d.ts +0 -64
- package/dest/block_proposal_handler.d.ts.map +0 -1
package/dest/validator.js
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
1
|
import { getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
2
|
-
import { validateFeeAssetPriceModifier } from '@aztec/ethereum/contracts';
|
|
3
|
-
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
|
-
import { TimeoutError } from '@aztec/foundation/error';
|
|
5
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
7
3
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
8
4
|
import { sleep } from '@aztec/foundation/sleep';
|
|
9
5
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
10
6
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
11
7
|
import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
|
|
12
|
-
import {
|
|
13
|
-
import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
14
|
-
import { accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
|
|
8
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
15
9
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
16
10
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
17
11
|
import { createHASigner, createLocalSignerWithProtection, createSignerFromSharedDb } from '@aztec/validator-ha-signer/factory';
|
|
18
12
|
import { DutyType } from '@aztec/validator-ha-signer/types';
|
|
19
13
|
import { EventEmitter } from 'events';
|
|
20
|
-
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
21
14
|
import { ValidationService } from './duties/validation_service.js';
|
|
22
15
|
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
23
16
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
24
17
|
import { ValidatorMetrics } from './metrics.js';
|
|
18
|
+
import { ProposalHandler } from './proposal_handler.js';
|
|
25
19
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
26
20
|
// Just cap the set to avoid unbounded growth.
|
|
27
21
|
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
@@ -36,7 +30,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
36
30
|
keyStore;
|
|
37
31
|
epochCache;
|
|
38
32
|
p2pClient;
|
|
39
|
-
|
|
33
|
+
proposalHandler;
|
|
40
34
|
blockSource;
|
|
41
35
|
checkpointsBuilder;
|
|
42
36
|
worldState;
|
|
@@ -58,8 +52,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
58
52
|
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */ lastAttestedEpochByAttester;
|
|
59
53
|
proposersOfInvalidBlocks;
|
|
60
54
|
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */ lastAttestedProposal;
|
|
61
|
-
constructor(keyStore, epochCache, p2pClient,
|
|
62
|
-
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.
|
|
55
|
+
constructor(keyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
56
|
+
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.proposalHandler = proposalHandler, this.blockSource = blockSource, this.checkpointsBuilder = checkpointsBuilder, this.worldState = worldState, this.l1ToL2MessageSource = l1ToL2MessageSource, this.config = config, this.blobClient = blobClient, this.slashingProtectionSigner = slashingProtectionSigner, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.lastAttestedEpochByAttester = new Map(), this.proposersOfInvalidBlocks = new Set();
|
|
63
57
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
64
58
|
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
65
59
|
this.tracer = telemetry.getTracer('Validator');
|
|
@@ -120,7 +114,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
120
114
|
txsPermitted: !config.disableTransactions,
|
|
121
115
|
maxTxsPerBlock: config.validateMaxTxsPerBlock
|
|
122
116
|
});
|
|
123
|
-
const
|
|
117
|
+
const proposalHandler = new ProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, blobClient, metrics, dateProvider, telemetry);
|
|
124
118
|
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
125
119
|
let slashingProtectionSigner;
|
|
126
120
|
if (slashingProtectionDb) {
|
|
@@ -149,14 +143,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
149
143
|
}));
|
|
150
144
|
}
|
|
151
145
|
const validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, slashingProtectionSigner);
|
|
152
|
-
const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient,
|
|
146
|
+
const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider, telemetry);
|
|
153
147
|
return validator;
|
|
154
148
|
}
|
|
155
149
|
getValidatorAddresses() {
|
|
156
150
|
return this.keyStore.getAddresses().filter((addr)=>!this.config.disabledValidators.some((disabled)=>disabled.equals(addr)));
|
|
157
151
|
}
|
|
158
|
-
|
|
159
|
-
return this.
|
|
152
|
+
getProposalHandler() {
|
|
153
|
+
return this.proposalHandler;
|
|
160
154
|
}
|
|
161
155
|
signWithAddress(addr, msg, context) {
|
|
162
156
|
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
@@ -212,7 +206,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
212
206
|
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
213
207
|
// and processed separately via the block handler above.
|
|
214
208
|
const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
215
|
-
this.p2pClient.
|
|
209
|
+
this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
|
|
216
210
|
// Duplicate proposal handler - triggers slashing for equivocation
|
|
217
211
|
this.p2pClient.registerDuplicateProposalCallback((info)=>{
|
|
218
212
|
this.handleDuplicateProposal(info);
|
|
@@ -262,9 +256,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
262
256
|
});
|
|
263
257
|
// Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
|
|
264
258
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
265
|
-
const {
|
|
266
|
-
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n
|
|
267
|
-
const validationResult = await this.
|
|
259
|
+
const { slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
260
|
+
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n || partOfCommittee || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
|
|
261
|
+
const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
|
|
268
262
|
if (!validationResult.isValid) {
|
|
269
263
|
const reason = validationResult.reason || 'unknown';
|
|
270
264
|
this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
|
|
@@ -314,50 +308,37 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
314
308
|
this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
|
|
315
309
|
return undefined;
|
|
316
310
|
}
|
|
317
|
-
// Reject proposals with invalid signatures
|
|
318
|
-
if (!proposer) {
|
|
319
|
-
this.log.warn(`Received checkpoint proposal with invalid signature for proposal slot ${proposalSlotNumber}`);
|
|
320
|
-
return undefined;
|
|
321
|
-
}
|
|
322
311
|
// Ignore proposals from ourselves (may happen in HA setups)
|
|
323
|
-
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
312
|
+
if (proposer && this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
324
313
|
this.log.debug(`Ignoring block proposal from self for slot ${proposalSlotNumber}`, {
|
|
325
314
|
proposer: proposer.toString(),
|
|
326
315
|
proposalSlotNumber
|
|
327
316
|
});
|
|
328
317
|
return undefined;
|
|
329
318
|
}
|
|
330
|
-
// Validate fee asset price modifier is within allowed range
|
|
331
|
-
if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
|
|
332
|
-
this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${proposalSlotNumber}`);
|
|
333
|
-
return undefined;
|
|
334
|
-
}
|
|
335
319
|
// Check that I have any address in the committee where this checkpoint will land before attesting
|
|
336
320
|
const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
|
|
337
321
|
const partOfCommittee = inCommittee.length > 0;
|
|
338
322
|
const proposalInfo = {
|
|
339
323
|
proposalSlotNumber,
|
|
340
324
|
archive: proposal.archive.toString(),
|
|
341
|
-
proposer: proposer
|
|
325
|
+
proposer: proposer?.toString()
|
|
342
326
|
};
|
|
343
327
|
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
344
328
|
...proposalInfo,
|
|
345
329
|
fishermanMode: this.config.fishermanMode || false
|
|
346
330
|
});
|
|
347
|
-
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
331
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
|
|
332
|
+
// Uses the cached result from the all-nodes callback if available (avoids double validation).
|
|
348
333
|
if (this.config.skipCheckpointProposalValidation) {
|
|
349
334
|
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
350
335
|
} else {
|
|
351
|
-
const validationResult = await this.
|
|
336
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
352
337
|
if (!validationResult.isValid) {
|
|
353
338
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
354
339
|
return undefined;
|
|
355
340
|
}
|
|
356
341
|
}
|
|
357
|
-
// Upload blobs to filestore if we can (fire and forget)
|
|
358
|
-
if (this.blobClient.canUpload()) {
|
|
359
|
-
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
360
|
-
}
|
|
361
342
|
// Check that I have any address in current committee before attesting
|
|
362
343
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
363
344
|
if (!partOfCommittee && !this.config.fishermanMode) {
|
|
@@ -432,164 +413,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
432
413
|
return attestations;
|
|
433
414
|
}
|
|
434
415
|
/**
|
|
435
|
-
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
436
|
-
* @returns Validation result with isValid flag and reason if invalid.
|
|
437
|
-
*/ async validateCheckpointProposal(proposal, proposalInfo) {
|
|
438
|
-
const slot = proposal.slotNumber;
|
|
439
|
-
// Timeout block syncing at the start of the next slot
|
|
440
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
441
|
-
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
|
|
442
|
-
const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
|
|
443
|
-
// Wait for last block to sync by archive
|
|
444
|
-
let lastBlockHeader;
|
|
445
|
-
try {
|
|
446
|
-
lastBlockHeader = await retryUntil(async ()=>{
|
|
447
|
-
await this.blockSource.syncImmediate();
|
|
448
|
-
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
449
|
-
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, timeoutSeconds, 0.5);
|
|
450
|
-
} catch (err) {
|
|
451
|
-
if (err instanceof TimeoutError) {
|
|
452
|
-
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
453
|
-
return {
|
|
454
|
-
isValid: false,
|
|
455
|
-
reason: 'last_block_not_found'
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
459
|
-
return {
|
|
460
|
-
isValid: false,
|
|
461
|
-
reason: 'block_fetch_error'
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
if (!lastBlockHeader) {
|
|
465
|
-
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
466
|
-
return {
|
|
467
|
-
isValid: false,
|
|
468
|
-
reason: 'last_block_not_found'
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
// Get all full blocks for the slot and checkpoint
|
|
472
|
-
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
473
|
-
if (blocks.length === 0) {
|
|
474
|
-
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
475
|
-
return {
|
|
476
|
-
isValid: false,
|
|
477
|
-
reason: 'no_blocks_for_slot'
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
481
|
-
if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
|
|
482
|
-
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
483
|
-
return {
|
|
484
|
-
isValid: false,
|
|
485
|
-
reason: 'last_block_archive_mismatch'
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
489
|
-
...proposalInfo,
|
|
490
|
-
blockNumbers: blocks.map((b)=>b.number)
|
|
491
|
-
});
|
|
492
|
-
// Get checkpoint constants from first block
|
|
493
|
-
const firstBlock = blocks[0];
|
|
494
|
-
const constants = this.extractCheckpointConstants(firstBlock);
|
|
495
|
-
const checkpointNumber = firstBlock.checkpointNumber;
|
|
496
|
-
// Get L1-to-L2 messages for this checkpoint
|
|
497
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
498
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
499
|
-
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
500
|
-
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch)).filter((c)=>c.checkpointNumber < checkpointNumber).map((c)=>c.checkpointOutHash);
|
|
501
|
-
// Fork world state at the block before the first block
|
|
502
|
-
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
503
|
-
const fork = await this.worldState.fork(parentBlockNumber);
|
|
504
|
-
try {
|
|
505
|
-
// Create checkpoint builder with all existing blocks
|
|
506
|
-
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
|
|
507
|
-
// Complete the checkpoint to get computed values
|
|
508
|
-
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
509
|
-
// Compare checkpoint header with proposal
|
|
510
|
-
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
511
|
-
this.log.warn(`Checkpoint header mismatch`, {
|
|
512
|
-
...proposalInfo,
|
|
513
|
-
computed: computedCheckpoint.header.toInspect(),
|
|
514
|
-
proposal: proposal.checkpointHeader.toInspect()
|
|
515
|
-
});
|
|
516
|
-
return {
|
|
517
|
-
isValid: false,
|
|
518
|
-
reason: 'checkpoint_header_mismatch'
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
// Compare archive root with proposal
|
|
522
|
-
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
523
|
-
this.log.warn(`Archive root mismatch`, {
|
|
524
|
-
...proposalInfo,
|
|
525
|
-
computed: computedCheckpoint.archive.root.toString(),
|
|
526
|
-
proposal: proposal.archive.toString()
|
|
527
|
-
});
|
|
528
|
-
return {
|
|
529
|
-
isValid: false,
|
|
530
|
-
reason: 'archive_mismatch'
|
|
531
|
-
};
|
|
532
|
-
}
|
|
533
|
-
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
534
|
-
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
535
|
-
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
536
|
-
const computedEpochOutHash = accumulateCheckpointOutHashes([
|
|
537
|
-
...previousCheckpointOutHashes,
|
|
538
|
-
checkpointOutHash
|
|
539
|
-
]);
|
|
540
|
-
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
541
|
-
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
542
|
-
this.log.warn(`Epoch out hash mismatch`, {
|
|
543
|
-
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
544
|
-
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
545
|
-
checkpointOutHash: checkpointOutHash.toString(),
|
|
546
|
-
previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
|
|
547
|
-
...proposalInfo
|
|
548
|
-
});
|
|
549
|
-
return {
|
|
550
|
-
isValid: false,
|
|
551
|
-
reason: 'out_hash_mismatch'
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
// Final round of validations on the checkpoint, just in case.
|
|
555
|
-
try {
|
|
556
|
-
validateCheckpoint(computedCheckpoint, {
|
|
557
|
-
rollupManaLimit: this.checkpointsBuilder.getConfig().rollupManaLimit,
|
|
558
|
-
maxDABlockGas: this.config.validateMaxDABlockGas,
|
|
559
|
-
maxL2BlockGas: this.config.validateMaxL2BlockGas,
|
|
560
|
-
maxTxsPerBlock: this.config.validateMaxTxsPerBlock,
|
|
561
|
-
maxTxsPerCheckpoint: this.config.validateMaxTxsPerCheckpoint
|
|
562
|
-
});
|
|
563
|
-
} catch (err) {
|
|
564
|
-
this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
|
|
565
|
-
return {
|
|
566
|
-
isValid: false,
|
|
567
|
-
reason: 'checkpoint_validation_failed'
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
571
|
-
return {
|
|
572
|
-
isValid: true
|
|
573
|
-
};
|
|
574
|
-
} finally{
|
|
575
|
-
await fork.close();
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
/**
|
|
579
|
-
* Extract checkpoint global variables from a block.
|
|
580
|
-
*/ extractCheckpointConstants(block) {
|
|
581
|
-
const gv = block.header.globalVariables;
|
|
582
|
-
return {
|
|
583
|
-
chainId: gv.chainId,
|
|
584
|
-
version: gv.version,
|
|
585
|
-
slotNumber: gv.slotNumber,
|
|
586
|
-
timestamp: gv.timestamp,
|
|
587
|
-
coinbase: gv.coinbase,
|
|
588
|
-
feeRecipient: gv.feeRecipient,
|
|
589
|
-
gasFees: gv.gasFees
|
|
590
|
-
};
|
|
591
|
-
}
|
|
592
|
-
/**
|
|
593
416
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
594
417
|
*/ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
|
|
595
418
|
try {
|
|
@@ -692,7 +515,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
692
515
|
this.lastProposedBlock = newProposal;
|
|
693
516
|
return newProposal;
|
|
694
517
|
}
|
|
695
|
-
async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier,
|
|
518
|
+
async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options = {}) {
|
|
696
519
|
// Validate that we're not creating a proposal for an older or equal slot
|
|
697
520
|
if (this.lastProposedCheckpoint) {
|
|
698
521
|
const lastSlot = this.lastProposedCheckpoint.slotNumber;
|
|
@@ -702,7 +525,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
702
525
|
}
|
|
703
526
|
}
|
|
704
527
|
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
705
|
-
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier,
|
|
528
|
+
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options);
|
|
706
529
|
this.lastProposedCheckpoint = newProposal;
|
|
707
530
|
return newProposal;
|
|
708
531
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/validator-client",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.e304674f1",
|
|
4
4
|
"main": "dest/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -64,30 +64,30 @@
|
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@aztec/blob-client": "0.0.1-commit.
|
|
68
|
-
"@aztec/blob-lib": "0.0.1-commit.
|
|
69
|
-
"@aztec/constants": "0.0.1-commit.
|
|
70
|
-
"@aztec/epoch-cache": "0.0.1-commit.
|
|
71
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
72
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
73
|
-
"@aztec/node-keystore": "0.0.1-commit.
|
|
74
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
75
|
-
"@aztec/p2p": "0.0.1-commit.
|
|
76
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
77
|
-
"@aztec/prover-client": "0.0.1-commit.
|
|
78
|
-
"@aztec/simulator": "0.0.1-commit.
|
|
79
|
-
"@aztec/slasher": "0.0.1-commit.
|
|
80
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
81
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
82
|
-
"@aztec/validator-ha-signer": "0.0.1-commit.
|
|
67
|
+
"@aztec/blob-client": "0.0.1-commit.e304674f1",
|
|
68
|
+
"@aztec/blob-lib": "0.0.1-commit.e304674f1",
|
|
69
|
+
"@aztec/constants": "0.0.1-commit.e304674f1",
|
|
70
|
+
"@aztec/epoch-cache": "0.0.1-commit.e304674f1",
|
|
71
|
+
"@aztec/ethereum": "0.0.1-commit.e304674f1",
|
|
72
|
+
"@aztec/foundation": "0.0.1-commit.e304674f1",
|
|
73
|
+
"@aztec/node-keystore": "0.0.1-commit.e304674f1",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.e304674f1",
|
|
75
|
+
"@aztec/p2p": "0.0.1-commit.e304674f1",
|
|
76
|
+
"@aztec/protocol-contracts": "0.0.1-commit.e304674f1",
|
|
77
|
+
"@aztec/prover-client": "0.0.1-commit.e304674f1",
|
|
78
|
+
"@aztec/simulator": "0.0.1-commit.e304674f1",
|
|
79
|
+
"@aztec/slasher": "0.0.1-commit.e304674f1",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.e304674f1",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.e304674f1",
|
|
82
|
+
"@aztec/validator-ha-signer": "0.0.1-commit.e304674f1",
|
|
83
83
|
"koa": "^2.16.1",
|
|
84
84
|
"koa-router": "^13.1.1",
|
|
85
85
|
"tslib": "^2.4.0",
|
|
86
86
|
"viem": "npm:@aztec/viem@2.38.2"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
|
-
"@aztec/archiver": "0.0.1-commit.
|
|
90
|
-
"@aztec/world-state": "0.0.1-commit.
|
|
89
|
+
"@aztec/archiver": "0.0.1-commit.e304674f1",
|
|
90
|
+
"@aztec/world-state": "0.0.1-commit.e304674f1",
|
|
91
91
|
"@electric-sql/pglite": "^0.3.14",
|
|
92
92
|
"@jest/globals": "^30.0.0",
|
|
93
93
|
"@types/jest": "^30.0.0",
|
package/src/config.ts
CHANGED
|
@@ -49,11 +49,6 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
|
|
|
49
49
|
description: 'Interval between polling for new attestations',
|
|
50
50
|
...numberConfigHelper(200),
|
|
51
51
|
},
|
|
52
|
-
validatorReexecute: {
|
|
53
|
-
env: 'VALIDATOR_REEXECUTE',
|
|
54
|
-
description: 'Re-execute transactions before attesting',
|
|
55
|
-
...booleanConfigHelper(true),
|
|
56
|
-
},
|
|
57
52
|
alwaysReexecuteBlockProposals: {
|
|
58
53
|
description:
|
|
59
54
|
'Whether to always reexecute block proposals, even for non-validator nodes (useful for monitoring network status).',
|
|
@@ -11,7 +11,6 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
11
11
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
12
12
|
import { createLogger } from '@aztec/foundation/log';
|
|
13
13
|
import type { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
14
|
-
import type { CreateCheckpointProposalLastBlockData } from '@aztec/stdlib/interfaces/server';
|
|
15
14
|
import {
|
|
16
15
|
BlockProposal,
|
|
17
16
|
type BlockProposalOptions,
|
|
@@ -86,7 +85,7 @@ export class ValidationService {
|
|
|
86
85
|
*
|
|
87
86
|
* @param checkpointHeader - The checkpoint header containing aggregated data
|
|
88
87
|
* @param archive - The archive of the checkpoint
|
|
89
|
-
* @param
|
|
88
|
+
* @param lastBlockProposal - Signed block proposal for the last block in the checkpoint, or undefined
|
|
90
89
|
* @param proposerAttesterAddress - The address of the proposer
|
|
91
90
|
* @param options - Checkpoint proposal options
|
|
92
91
|
*
|
|
@@ -96,13 +95,15 @@ export class ValidationService {
|
|
|
96
95
|
checkpointHeader: CheckpointHeader,
|
|
97
96
|
archive: Fr,
|
|
98
97
|
feeAssetPriceModifier: bigint,
|
|
99
|
-
|
|
98
|
+
lastBlockProposal: BlockProposal | undefined,
|
|
100
99
|
proposerAttesterAddress: EthAddress | undefined,
|
|
101
100
|
options: CheckpointProposalOptions,
|
|
102
101
|
): Promise<CheckpointProposal> {
|
|
103
|
-
// For testing: change the archive to trigger state_mismatch validation failure
|
|
102
|
+
// For testing: change the archive to trigger state_mismatch validation failure.
|
|
103
|
+
// If there's a last block proposal, use its (already invalid) archive to keep signatures consistent
|
|
104
|
+
// so P2P validation passes and the slasher can detect the offense.
|
|
104
105
|
if (options.broadcastInvalidCheckpointProposal) {
|
|
105
|
-
archive = Fr.random();
|
|
106
|
+
archive = lastBlockProposal?.archiveRoot ?? Fr.random();
|
|
106
107
|
this.log.warn(`Creating INVALID checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
107
108
|
}
|
|
108
109
|
|
|
@@ -112,19 +113,11 @@ export class ValidationService {
|
|
|
112
113
|
return this.keyStore.signMessageWithAddress(address, payload, context);
|
|
113
114
|
};
|
|
114
115
|
|
|
115
|
-
// Last block to include in the proposal
|
|
116
|
-
const lastBlock = lastBlockInfo && {
|
|
117
|
-
blockHeader: lastBlockInfo.blockHeader,
|
|
118
|
-
indexWithinCheckpoint: lastBlockInfo.indexWithinCheckpoint,
|
|
119
|
-
txHashes: lastBlockInfo.txs.map(tx => tx.getTxHash()),
|
|
120
|
-
txs: options.publishFullTxs ? lastBlockInfo.txs : undefined,
|
|
121
|
-
};
|
|
122
|
-
|
|
123
116
|
return CheckpointProposal.createProposalFromSigner(
|
|
124
117
|
checkpointHeader,
|
|
125
118
|
archive,
|
|
126
119
|
feeAssetPriceModifier,
|
|
127
|
-
|
|
120
|
+
lastBlockProposal,
|
|
128
121
|
payloadSigner,
|
|
129
122
|
);
|
|
130
123
|
}
|
package/src/factory.ts
CHANGED
|
@@ -9,12 +9,12 @@ import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
|
9
9
|
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
10
10
|
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
11
11
|
|
|
12
|
-
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
13
12
|
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
14
13
|
import { ValidatorMetrics } from './metrics.js';
|
|
14
|
+
import { ProposalHandler } from './proposal_handler.js';
|
|
15
15
|
import { ValidatorClient } from './validator.js';
|
|
16
16
|
|
|
17
|
-
export function
|
|
17
|
+
export function createProposalHandler(
|
|
18
18
|
config: ValidatorClientFullConfig,
|
|
19
19
|
deps: {
|
|
20
20
|
checkpointsBuilder: FullNodeCheckpointsBuilder;
|
|
@@ -23,6 +23,7 @@ export function createBlockProposalHandler(
|
|
|
23
23
|
l1ToL2MessageSource: L1ToL2MessageSource;
|
|
24
24
|
p2pClient: P2PClient;
|
|
25
25
|
epochCache: EpochCache;
|
|
26
|
+
blobClient: BlobClientInterface;
|
|
26
27
|
dateProvider: DateProvider;
|
|
27
28
|
telemetry: TelemetryClient;
|
|
28
29
|
},
|
|
@@ -32,7 +33,7 @@ export function createBlockProposalHandler(
|
|
|
32
33
|
txsPermitted: !config.disableTransactions,
|
|
33
34
|
maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
|
|
34
35
|
});
|
|
35
|
-
return new
|
|
36
|
+
return new ProposalHandler(
|
|
36
37
|
deps.checkpointsBuilder,
|
|
37
38
|
deps.worldState,
|
|
38
39
|
deps.blockSource,
|
|
@@ -41,6 +42,7 @@ export function createBlockProposalHandler(
|
|
|
41
42
|
blockProposalValidator,
|
|
42
43
|
deps.epochCache,
|
|
43
44
|
config,
|
|
45
|
+
deps.blobClient,
|
|
44
46
|
metrics,
|
|
45
47
|
deps.dateProvider,
|
|
46
48
|
deps.telemetry,
|
package/src/index.ts
CHANGED
package/src/metrics.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
createUpDownCounterWithDefault,
|
|
12
12
|
} from '@aztec/telemetry-client';
|
|
13
13
|
|
|
14
|
-
import type { BlockProposalValidationFailureReason } from './
|
|
14
|
+
import type { BlockProposalValidationFailureReason } from './proposal_handler.js';
|
|
15
15
|
|
|
16
16
|
export class ValidatorMetrics {
|
|
17
17
|
private failedReexecutionCounter: UpDownCounter;
|