@aztec/validator-client 0.0.1-commit.6d63667d → 0.0.1-commit.7b97ef96e
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 +21 -18
- package/dest/block_proposal_handler.d.ts +2 -2
- package/dest/block_proposal_handler.d.ts.map +1 -1
- package/dest/block_proposal_handler.js +20 -34
- package/dest/checkpoint_builder.d.ts +3 -3
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +9 -7
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +4 -0
- 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 +3 -3
- package/dest/validator.d.ts +33 -8
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +161 -27
- package/package.json +19 -19
- package/src/block_proposal_handler.ts +28 -48
- package/src/checkpoint_builder.ts +7 -0
- package/src/config.ts +4 -0
- package/src/duties/validation_service.ts +9 -2
- package/src/validator.ts +218 -34
package/dest/validator.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
2
|
-
import {
|
|
2
|
+
import { validateFeeAssetPriceModifier } from '@aztec/ethereum/contracts';
|
|
3
|
+
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
4
|
import { TimeoutError } from '@aztec/foundation/error';
|
|
4
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
6
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
@@ -8,7 +9,7 @@ import { sleep } from '@aztec/foundation/sleep';
|
|
|
8
9
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
9
10
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
10
11
|
import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
|
|
11
|
-
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
12
|
+
import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
12
13
|
import { accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
|
|
13
14
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
14
15
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
@@ -41,6 +42,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
41
42
|
l1ToL2MessageSource;
|
|
42
43
|
config;
|
|
43
44
|
blobClient;
|
|
45
|
+
haSigner;
|
|
44
46
|
dateProvider;
|
|
45
47
|
tracer;
|
|
46
48
|
validationService;
|
|
@@ -48,13 +50,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
48
50
|
log;
|
|
49
51
|
// Whether it has already registered handlers on the p2p client
|
|
50
52
|
hasRegisteredHandlers;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
/** Tracks the last block proposal we created, to detect duplicate proposal attempts. */ lastProposedBlock;
|
|
54
|
+
/** Tracks the last checkpoint proposal we created. */ lastProposedCheckpoint;
|
|
53
55
|
lastEpochForCommitteeUpdateLoop;
|
|
54
56
|
epochCacheUpdateLoop;
|
|
55
57
|
proposersOfInvalidBlocks;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */ lastAttestedProposal;
|
|
59
|
+
constructor(keyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, haSigner, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
60
|
+
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.blockProposalHandler = blockProposalHandler, this.blockSource = blockSource, this.checkpointsBuilder = checkpointsBuilder, this.worldState = worldState, this.l1ToL2MessageSource = l1ToL2MessageSource, this.config = config, this.blobClient = blobClient, this.haSigner = haSigner, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.proposersOfInvalidBlocks = new Set();
|
|
58
61
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
59
62
|
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
60
63
|
this.tracer = telemetry.getTracer('Validator');
|
|
@@ -114,7 +117,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
114
117
|
txsPermitted: !config.disableTransactions
|
|
115
118
|
});
|
|
116
119
|
const blockProposalHandler = new BlockProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, metrics, dateProvider, telemetry);
|
|
117
|
-
|
|
120
|
+
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
121
|
+
let validatorKeyStore = nodeKeystoreAdapter;
|
|
122
|
+
let haSigner;
|
|
118
123
|
if (config.haSigningEnabled) {
|
|
119
124
|
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
120
125
|
const haConfig = {
|
|
@@ -122,9 +127,10 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
122
127
|
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000
|
|
123
128
|
};
|
|
124
129
|
const { signer } = await createHASigner(haConfig);
|
|
125
|
-
|
|
130
|
+
haSigner = signer;
|
|
131
|
+
validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, signer);
|
|
126
132
|
}
|
|
127
|
-
const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider, telemetry);
|
|
133
|
+
const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, haSigner, dateProvider, telemetry);
|
|
128
134
|
return validator;
|
|
129
135
|
}
|
|
130
136
|
getValidatorAddresses() {
|
|
@@ -151,6 +157,20 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
151
157
|
...config
|
|
152
158
|
};
|
|
153
159
|
}
|
|
160
|
+
reloadKeystore(newManager) {
|
|
161
|
+
if (this.config.haSigningEnabled && !this.haSigner) {
|
|
162
|
+
this.log.warn('HA signing is enabled in config but was not initialized at startup. ' + 'Restart the node to enable HA signing.');
|
|
163
|
+
} else if (!this.config.haSigningEnabled && this.haSigner) {
|
|
164
|
+
this.log.warn('HA signing was disabled via config update but the HA signer is still active. ' + 'Restart the node to fully disable HA signing.');
|
|
165
|
+
}
|
|
166
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
167
|
+
if (this.haSigner) {
|
|
168
|
+
this.keyStore = new HAKeyStore(newAdapter, this.haSigner);
|
|
169
|
+
} else {
|
|
170
|
+
this.keyStore = newAdapter;
|
|
171
|
+
}
|
|
172
|
+
this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
|
|
173
|
+
}
|
|
154
174
|
async start() {
|
|
155
175
|
if (this.epochCacheUpdateLoop.isRunning()) {
|
|
156
176
|
this.log.warn(`Validator client already started`);
|
|
@@ -183,6 +203,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
183
203
|
// and processed separately via the block handler above.
|
|
184
204
|
const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
185
205
|
this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
|
|
206
|
+
// Duplicate proposal handler - triggers slashing for equivocation
|
|
207
|
+
this.p2pClient.registerDuplicateProposalCallback((info)=>{
|
|
208
|
+
this.handleDuplicateProposal(info);
|
|
209
|
+
});
|
|
210
|
+
// Duplicate attestation handler - triggers slashing for attestation equivocation
|
|
211
|
+
this.p2pClient.registerDuplicateAttestationCallback((info)=>{
|
|
212
|
+
this.handleDuplicateAttestation(info);
|
|
213
|
+
});
|
|
186
214
|
const myAddresses = this.getValidatorAddresses();
|
|
187
215
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
188
216
|
await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
|
|
@@ -203,6 +231,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
203
231
|
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
204
232
|
return false;
|
|
205
233
|
}
|
|
234
|
+
// Ignore proposals from ourselves (may happen in HA setups)
|
|
235
|
+
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
236
|
+
this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
|
|
237
|
+
proposer: proposer.toString(),
|
|
238
|
+
slotNumber
|
|
239
|
+
});
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
206
242
|
// Check if we're in the committee (for metrics purposes)
|
|
207
243
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
208
244
|
const partOfCommittee = inCommittee.length > 0;
|
|
@@ -274,6 +310,19 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
274
310
|
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
275
311
|
return undefined;
|
|
276
312
|
}
|
|
313
|
+
// Ignore proposals from ourselves (may happen in HA setups)
|
|
314
|
+
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
315
|
+
this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
|
|
316
|
+
proposer: proposer.toString(),
|
|
317
|
+
slotNumber
|
|
318
|
+
});
|
|
319
|
+
return undefined;
|
|
320
|
+
}
|
|
321
|
+
// Validate fee asset price modifier is within allowed range
|
|
322
|
+
if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
|
|
323
|
+
this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`);
|
|
324
|
+
return undefined;
|
|
325
|
+
}
|
|
277
326
|
// Check that I have any address in current committee before attesting
|
|
278
327
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
279
328
|
const partOfCommittee = inCommittee.length > 0;
|
|
@@ -337,11 +386,32 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
337
386
|
});
|
|
338
387
|
return undefined;
|
|
339
388
|
}
|
|
340
|
-
return this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
389
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Checks if we should attest to a slot based on equivocation prevention rules.
|
|
393
|
+
* @returns true if we should attest, false if we should skip
|
|
394
|
+
*/ shouldAttestToSlot(slotNumber) {
|
|
395
|
+
// If attestToEquivocatedProposals is true, always allow
|
|
396
|
+
if (this.config.attestToEquivocatedProposals) {
|
|
397
|
+
return true;
|
|
398
|
+
}
|
|
399
|
+
// Check if incoming slot is strictly greater than last attested
|
|
400
|
+
if (this.lastAttestedProposal && slotNumber <= this.lastAttestedProposal.slotNumber) {
|
|
401
|
+
this.log.warn(`Refusing to process a proposal for slot ${slotNumber} given we already attested to a proposal for slot ${this.lastAttestedProposal.slotNumber}`);
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
return true;
|
|
341
405
|
}
|
|
342
406
|
async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
|
|
407
|
+
// Equivocation check: must happen right before signing to minimize the race window
|
|
408
|
+
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
409
|
+
return undefined;
|
|
410
|
+
}
|
|
343
411
|
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
344
|
-
|
|
412
|
+
// Track the proposal we attested to (to prevent equivocation)
|
|
413
|
+
this.lastAttestedProposal = proposal;
|
|
414
|
+
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
345
415
|
return attestations;
|
|
346
416
|
}
|
|
347
417
|
/**
|
|
@@ -349,7 +419,10 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
349
419
|
* @returns Validation result with isValid flag and reason if invalid.
|
|
350
420
|
*/ async validateCheckpointProposal(proposal, proposalInfo) {
|
|
351
421
|
const slot = proposal.slotNumber;
|
|
352
|
-
|
|
422
|
+
// Timeout block syncing at the start of the next slot
|
|
423
|
+
const config = this.checkpointsBuilder.getConfig();
|
|
424
|
+
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
|
|
425
|
+
const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
|
|
353
426
|
// Wait for last block to sync by archive
|
|
354
427
|
let lastBlockHeader;
|
|
355
428
|
try {
|
|
@@ -387,6 +460,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
387
460
|
reason: 'no_blocks_for_slot'
|
|
388
461
|
};
|
|
389
462
|
}
|
|
463
|
+
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
464
|
+
if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
|
|
465
|
+
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
466
|
+
return {
|
|
467
|
+
isValid: false,
|
|
468
|
+
reason: 'last_block_archive_mismatch'
|
|
469
|
+
};
|
|
470
|
+
}
|
|
390
471
|
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
391
472
|
...proposalInfo,
|
|
392
473
|
blockNumbers: blocks.map((b)=>b.number)
|
|
@@ -397,18 +478,15 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
397
478
|
const checkpointNumber = firstBlock.checkpointNumber;
|
|
398
479
|
// Get L1-to-L2 messages for this checkpoint
|
|
399
480
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
400
|
-
//
|
|
401
|
-
// TODO: There can be a more efficient way to get the previous checkpoint out hashes without having to fetch the
|
|
402
|
-
// actual checkpoints and the blocks/txs in them.
|
|
481
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
403
482
|
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
404
|
-
const
|
|
405
|
-
const previousCheckpointOutHashes = previousCheckpoints.map((c)=>c.getCheckpointOutHash());
|
|
483
|
+
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch)).filter((c)=>c.checkpointNumber < checkpointNumber).map((c)=>c.checkpointOutHash);
|
|
406
484
|
// Fork world state at the block before the first block
|
|
407
485
|
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
408
486
|
const fork = await this.worldState.fork(parentBlockNumber);
|
|
409
487
|
try {
|
|
410
488
|
// Create checkpoint builder with all existing blocks
|
|
411
|
-
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
|
|
489
|
+
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
|
|
412
490
|
// Complete the checkpoint to get computed values
|
|
413
491
|
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
414
492
|
// Compare checkpoint header with proposal
|
|
@@ -472,6 +550,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
472
550
|
chainId: gv.chainId,
|
|
473
551
|
version: gv.version,
|
|
474
552
|
slotNumber: gv.slotNumber,
|
|
553
|
+
timestamp: gv.timestamp,
|
|
475
554
|
coinbase: gv.coinbase,
|
|
476
555
|
feeRecipient: gv.feeRecipient,
|
|
477
556
|
gasFees: gv.gasFees
|
|
@@ -492,7 +571,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
492
571
|
return;
|
|
493
572
|
}
|
|
494
573
|
const blobFields = blocks.flatMap((b)=>b.toBlobFields());
|
|
495
|
-
const blobs = getBlobsPerL1Block(blobFields);
|
|
574
|
+
const blobs = await getBlobsPerL1Block(blobFields);
|
|
496
575
|
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
497
576
|
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
498
577
|
...proposalInfo,
|
|
@@ -524,23 +603,75 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
524
603
|
}
|
|
525
604
|
]);
|
|
526
605
|
}
|
|
606
|
+
/**
|
|
607
|
+
* Handle detection of a duplicate proposal (equivocation).
|
|
608
|
+
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
609
|
+
*/ handleDuplicateProposal(info) {
|
|
610
|
+
const { slot, proposer, type } = info;
|
|
611
|
+
this.log.warn(`Triggering slash event for duplicate ${type} proposal from ${proposer.toString()} at slot ${slot}`, {
|
|
612
|
+
proposer: proposer.toString(),
|
|
613
|
+
slot,
|
|
614
|
+
type
|
|
615
|
+
});
|
|
616
|
+
// Emit slash event
|
|
617
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
618
|
+
{
|
|
619
|
+
validator: proposer,
|
|
620
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
621
|
+
offenseType: OffenseType.DUPLICATE_PROPOSAL,
|
|
622
|
+
epochOrSlot: BigInt(slot)
|
|
623
|
+
}
|
|
624
|
+
]);
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Handle detection of a duplicate attestation (equivocation).
|
|
628
|
+
* Emits a slash event when an attester signs attestations for different proposals at the same slot.
|
|
629
|
+
*/ handleDuplicateAttestation(info) {
|
|
630
|
+
const { slot, attester } = info;
|
|
631
|
+
this.log.warn(`Triggering slash event for duplicate attestation from ${attester.toString()} at slot ${slot}`, {
|
|
632
|
+
attester: attester.toString(),
|
|
633
|
+
slot
|
|
634
|
+
});
|
|
635
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
636
|
+
{
|
|
637
|
+
validator: attester,
|
|
638
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
639
|
+
offenseType: OffenseType.DUPLICATE_ATTESTATION,
|
|
640
|
+
epochOrSlot: BigInt(slot)
|
|
641
|
+
}
|
|
642
|
+
]);
|
|
643
|
+
}
|
|
527
644
|
async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
|
|
528
|
-
//
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
645
|
+
// Validate that we're not creating a proposal for an older or equal position
|
|
646
|
+
if (this.lastProposedBlock) {
|
|
647
|
+
const lastSlot = this.lastProposedBlock.slotNumber;
|
|
648
|
+
const lastIndex = this.lastProposedBlock.indexWithinCheckpoint;
|
|
649
|
+
const newSlot = blockHeader.globalVariables.slotNumber;
|
|
650
|
+
if (newSlot < lastSlot || newSlot === lastSlot && indexWithinCheckpoint <= lastIndex) {
|
|
651
|
+
throw new Error(`Cannot create block proposal for slot ${newSlot} index ${indexWithinCheckpoint}: ` + `already proposed block for slot ${lastSlot} index ${lastIndex}`);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
533
654
|
this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
|
|
534
655
|
const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
535
656
|
...options,
|
|
536
657
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
537
658
|
});
|
|
538
|
-
this.
|
|
659
|
+
this.lastProposedBlock = newProposal;
|
|
539
660
|
return newProposal;
|
|
540
661
|
}
|
|
541
|
-
async createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options = {}) {
|
|
662
|
+
async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options = {}) {
|
|
663
|
+
// Validate that we're not creating a proposal for an older or equal slot
|
|
664
|
+
if (this.lastProposedCheckpoint) {
|
|
665
|
+
const lastSlot = this.lastProposedCheckpoint.slotNumber;
|
|
666
|
+
const newSlot = checkpointHeader.slotNumber;
|
|
667
|
+
if (newSlot <= lastSlot) {
|
|
668
|
+
throw new Error(`Cannot create checkpoint proposal for slot ${newSlot}: ` + `already proposed checkpoint for slot ${lastSlot}`);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
542
671
|
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
543
|
-
|
|
672
|
+
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options);
|
|
673
|
+
this.lastProposedCheckpoint = newProposal;
|
|
674
|
+
return newProposal;
|
|
544
675
|
}
|
|
545
676
|
async broadcastBlockProposal(proposal) {
|
|
546
677
|
await this.p2pClient.broadcastProposal(proposal);
|
|
@@ -555,6 +686,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
555
686
|
inCommittee
|
|
556
687
|
});
|
|
557
688
|
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
689
|
+
if (!attestations) {
|
|
690
|
+
return [];
|
|
691
|
+
}
|
|
558
692
|
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
559
693
|
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
560
694
|
// due to inactivity for missed attestations.
|
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.7b97ef96e",
|
|
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.7b97ef96e",
|
|
68
|
+
"@aztec/blob-lib": "0.0.1-commit.7b97ef96e",
|
|
69
|
+
"@aztec/constants": "0.0.1-commit.7b97ef96e",
|
|
70
|
+
"@aztec/epoch-cache": "0.0.1-commit.7b97ef96e",
|
|
71
|
+
"@aztec/ethereum": "0.0.1-commit.7b97ef96e",
|
|
72
|
+
"@aztec/foundation": "0.0.1-commit.7b97ef96e",
|
|
73
|
+
"@aztec/node-keystore": "0.0.1-commit.7b97ef96e",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.7b97ef96e",
|
|
75
|
+
"@aztec/p2p": "0.0.1-commit.7b97ef96e",
|
|
76
|
+
"@aztec/protocol-contracts": "0.0.1-commit.7b97ef96e",
|
|
77
|
+
"@aztec/prover-client": "0.0.1-commit.7b97ef96e",
|
|
78
|
+
"@aztec/simulator": "0.0.1-commit.7b97ef96e",
|
|
79
|
+
"@aztec/slasher": "0.0.1-commit.7b97ef96e",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.7b97ef96e",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.7b97ef96e",
|
|
82
|
+
"@aztec/validator-ha-signer": "0.0.1-commit.7b97ef96e",
|
|
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.7b97ef96e",
|
|
90
|
+
"@aztec/world-state": "0.0.1-commit.7b97ef96e",
|
|
91
91
|
"@electric-sql/pglite": "^0.3.14",
|
|
92
92
|
"@jest/globals": "^30.0.0",
|
|
93
93
|
"@types/jest": "^30.0.0",
|
|
@@ -1,7 +1,6 @@
|
|
|
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 { chunkBy } from '@aztec/foundation/collection';
|
|
5
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
5
|
import { TimeoutError } from '@aztec/foundation/error';
|
|
7
6
|
import { createLogger } from '@aztec/foundation/log';
|
|
@@ -9,16 +8,12 @@ import { retryUntil } from '@aztec/foundation/retry';
|
|
|
9
8
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
10
9
|
import type { P2P, PeerId } from '@aztec/p2p';
|
|
11
10
|
import { BlockProposalValidator } from '@aztec/p2p/msg_validators';
|
|
12
|
-
import type { L2Block, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
11
|
+
import type { BlockData, L2Block, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
13
12
|
import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
14
13
|
import type { ITxProvider, ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
15
|
-
import {
|
|
16
|
-
type L1ToL2MessageSource,
|
|
17
|
-
computeCheckpointOutHash,
|
|
18
|
-
computeInHashFromL1ToL2Messages,
|
|
19
|
-
} from '@aztec/stdlib/messaging';
|
|
14
|
+
import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
20
15
|
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
21
|
-
import {
|
|
16
|
+
import type { CheckpointGlobalVariables, FailedTx, Tx } from '@aztec/stdlib/tx';
|
|
22
17
|
import {
|
|
23
18
|
ReExFailedTxsError,
|
|
24
19
|
ReExStateMismatchError,
|
|
@@ -153,16 +148,16 @@ export class BlockProposalHandler {
|
|
|
153
148
|
}
|
|
154
149
|
|
|
155
150
|
// Check that the parent proposal is a block we know, otherwise reexecution would fail
|
|
156
|
-
const
|
|
157
|
-
if (
|
|
151
|
+
const parentBlock = await this.getParentBlock(proposal);
|
|
152
|
+
if (parentBlock === undefined) {
|
|
158
153
|
this.log.warn(`Parent block for proposal not found, skipping processing`, proposalInfo);
|
|
159
154
|
return { isValid: false, reason: 'parent_block_not_found' };
|
|
160
155
|
}
|
|
161
156
|
|
|
162
157
|
// Check that the parent block's slot is not greater than the proposal's slot.
|
|
163
|
-
if (
|
|
158
|
+
if (parentBlock !== 'genesis' && parentBlock.header.getSlot() > slotNumber) {
|
|
164
159
|
this.log.warn(`Parent block slot is greater than proposal slot, skipping processing`, {
|
|
165
|
-
parentBlockSlot:
|
|
160
|
+
parentBlockSlot: parentBlock.header.getSlot().toString(),
|
|
166
161
|
proposalSlot: slotNumber.toString(),
|
|
167
162
|
...proposalInfo,
|
|
168
163
|
});
|
|
@@ -171,9 +166,9 @@ export class BlockProposalHandler {
|
|
|
171
166
|
|
|
172
167
|
// Compute the block number based on the parent block
|
|
173
168
|
const blockNumber =
|
|
174
|
-
|
|
169
|
+
parentBlock === 'genesis'
|
|
175
170
|
? BlockNumber(INITIAL_L2_BLOCK_NUM)
|
|
176
|
-
: BlockNumber(
|
|
171
|
+
: BlockNumber(parentBlock.header.getBlockNumber() + 1);
|
|
177
172
|
|
|
178
173
|
// Check that this block number does not exist already
|
|
179
174
|
const existingBlock = await this.blockSource.getBlockHeader(blockNumber);
|
|
@@ -190,7 +185,7 @@ export class BlockProposalHandler {
|
|
|
190
185
|
});
|
|
191
186
|
|
|
192
187
|
// Compute the checkpoint number for this block and validate checkpoint consistency
|
|
193
|
-
const checkpointResult =
|
|
188
|
+
const checkpointResult = this.computeCheckpointNumber(proposal, parentBlock, proposalInfo);
|
|
194
189
|
if (checkpointResult.reason) {
|
|
195
190
|
return { isValid: false, blockNumber, reason: checkpointResult.reason };
|
|
196
191
|
}
|
|
@@ -218,17 +213,11 @@ export class BlockProposalHandler {
|
|
|
218
213
|
// Try re-executing the transactions in the proposal if needed
|
|
219
214
|
let reexecutionResult;
|
|
220
215
|
if (shouldReexecute) {
|
|
221
|
-
//
|
|
222
|
-
// TODO(leila/mbps): There can be a more efficient way to get the previous checkpoint out
|
|
223
|
-
// hashes without having to fetch all the blocks.
|
|
216
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
224
217
|
const epoch = getEpochAtSlot(slotNumber, this.epochCache.getL1Constants());
|
|
225
|
-
const
|
|
226
|
-
.filter(
|
|
227
|
-
.
|
|
228
|
-
const blocksByCheckpoint = chunkBy(checkpointedBlocks, b => b.checkpointNumber);
|
|
229
|
-
const previousCheckpointOutHashes = blocksByCheckpoint.map(checkpointBlocks =>
|
|
230
|
-
computeCheckpointOutHash(checkpointBlocks.map(b => b.block.body.txEffects.map(tx => tx.l2ToL1Msgs))),
|
|
231
|
-
);
|
|
218
|
+
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch))
|
|
219
|
+
.filter(c => c.checkpointNumber < checkpointNumber)
|
|
220
|
+
.map(c => c.checkpointOutHash);
|
|
232
221
|
|
|
233
222
|
try {
|
|
234
223
|
this.log.verbose(`Re-executing transactions in the proposal`, proposalInfo);
|
|
@@ -260,7 +249,7 @@ export class BlockProposalHandler {
|
|
|
260
249
|
return { isValid: true, blockNumber, reexecutionResult };
|
|
261
250
|
}
|
|
262
251
|
|
|
263
|
-
private async getParentBlock(proposal: BlockProposal): Promise<'genesis' |
|
|
252
|
+
private async getParentBlock(proposal: BlockProposal): Promise<'genesis' | BlockData | undefined> {
|
|
264
253
|
const parentArchive = proposal.blockHeader.lastArchive.root;
|
|
265
254
|
const slot = proposal.slotNumber;
|
|
266
255
|
const config = this.checkpointsBuilder.getConfig();
|
|
@@ -276,12 +265,11 @@ export class BlockProposalHandler {
|
|
|
276
265
|
|
|
277
266
|
try {
|
|
278
267
|
return (
|
|
279
|
-
(await this.blockSource.
|
|
268
|
+
(await this.blockSource.getBlockDataByArchive(parentArchive)) ??
|
|
280
269
|
(timeoutDurationMs <= 0
|
|
281
270
|
? undefined
|
|
282
271
|
: await retryUntil(
|
|
283
|
-
() =>
|
|
284
|
-
this.blockSource.syncImmediate().then(() => this.blockSource.getBlockHeaderByArchive(parentArchive)),
|
|
272
|
+
() => this.blockSource.syncImmediate().then(() => this.blockSource.getBlockDataByArchive(parentArchive)),
|
|
285
273
|
'force archiver sync',
|
|
286
274
|
timeoutDurationMs / 1000,
|
|
287
275
|
0.5,
|
|
@@ -297,12 +285,12 @@ export class BlockProposalHandler {
|
|
|
297
285
|
}
|
|
298
286
|
}
|
|
299
287
|
|
|
300
|
-
private
|
|
288
|
+
private computeCheckpointNumber(
|
|
301
289
|
proposal: BlockProposal,
|
|
302
|
-
|
|
290
|
+
parentBlock: 'genesis' | BlockData,
|
|
303
291
|
proposalInfo: object,
|
|
304
|
-
):
|
|
305
|
-
if (
|
|
292
|
+
): CheckpointComputationResult {
|
|
293
|
+
if (parentBlock === 'genesis') {
|
|
306
294
|
// First block is in checkpoint 1
|
|
307
295
|
if (proposal.indexWithinCheckpoint !== 0) {
|
|
308
296
|
this.log.warn(`First block proposal has non-zero indexWithinCheckpoint`, proposalInfo);
|
|
@@ -311,19 +299,9 @@ export class BlockProposalHandler {
|
|
|
311
299
|
return { checkpointNumber: CheckpointNumber.INITIAL };
|
|
312
300
|
}
|
|
313
301
|
|
|
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
302
|
if (proposal.indexWithinCheckpoint === 0) {
|
|
325
303
|
// If this is the first block in a new checkpoint, increment the checkpoint number
|
|
326
|
-
if (!(proposal.blockHeader.getSlot() >
|
|
304
|
+
if (!(proposal.blockHeader.getSlot() > parentBlock.header.getSlot())) {
|
|
327
305
|
this.log.warn(`Slot should be greater than parent block slot for first block in checkpoint`, proposalInfo);
|
|
328
306
|
return { reason: 'invalid_proposal' };
|
|
329
307
|
}
|
|
@@ -335,7 +313,7 @@ export class BlockProposalHandler {
|
|
|
335
313
|
this.log.warn(`Non-sequential indexWithinCheckpoint`, proposalInfo);
|
|
336
314
|
return { reason: 'invalid_proposal' };
|
|
337
315
|
}
|
|
338
|
-
if (proposal.blockHeader.getSlot() !==
|
|
316
|
+
if (proposal.blockHeader.getSlot() !== parentBlock.header.getSlot()) {
|
|
339
317
|
this.log.warn(`Slot should be equal to parent block slot for non-first block in checkpoint`, proposalInfo);
|
|
340
318
|
return { reason: 'invalid_proposal' };
|
|
341
319
|
}
|
|
@@ -356,7 +334,7 @@ export class BlockProposalHandler {
|
|
|
356
334
|
*/
|
|
357
335
|
private validateNonFirstBlockInCheckpoint(
|
|
358
336
|
proposal: BlockProposal,
|
|
359
|
-
parentBlock:
|
|
337
|
+
parentBlock: BlockData,
|
|
360
338
|
proposalInfo: object,
|
|
361
339
|
): CheckpointComputationResult | undefined {
|
|
362
340
|
const proposalGlobals = proposal.blockHeader.globalVariables;
|
|
@@ -475,13 +453,14 @@ export class BlockProposalHandler {
|
|
|
475
453
|
// Fork before the block to be built
|
|
476
454
|
const parentBlockNumber = BlockNumber(blockNumber - 1);
|
|
477
455
|
await this.worldState.syncImmediate(parentBlockNumber);
|
|
478
|
-
using fork = await this.worldState.fork(parentBlockNumber);
|
|
456
|
+
await using fork = await this.worldState.fork(parentBlockNumber);
|
|
479
457
|
|
|
480
|
-
// Build checkpoint constants from proposal (excludes blockNumber
|
|
458
|
+
// Build checkpoint constants from proposal (excludes blockNumber which is per-block)
|
|
481
459
|
const constants: CheckpointGlobalVariables = {
|
|
482
460
|
chainId: new Fr(config.l1ChainId),
|
|
483
461
|
version: new Fr(config.rollupVersion),
|
|
484
462
|
slotNumber: slot,
|
|
463
|
+
timestamp: blockHeader.globalVariables.timestamp,
|
|
485
464
|
coinbase: blockHeader.globalVariables.coinbase,
|
|
486
465
|
feeRecipient: blockHeader.globalVariables.feeRecipient,
|
|
487
466
|
gasFees: blockHeader.globalVariables.gasFees,
|
|
@@ -491,6 +470,7 @@ export class BlockProposalHandler {
|
|
|
491
470
|
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
|
|
492
471
|
checkpointNumber,
|
|
493
472
|
constants,
|
|
473
|
+
0n, // only takes effect in the following checkpoint.
|
|
494
474
|
l1ToL2Messages,
|
|
495
475
|
previousCheckpointOutHashes,
|
|
496
476
|
fork,
|
|
@@ -215,6 +215,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
215
215
|
async startCheckpoint(
|
|
216
216
|
checkpointNumber: CheckpointNumber,
|
|
217
217
|
constants: CheckpointGlobalVariables,
|
|
218
|
+
feeAssetPriceModifier: bigint,
|
|
218
219
|
l1ToL2Messages: Fr[],
|
|
219
220
|
previousCheckpointOutHashes: Fr[],
|
|
220
221
|
fork: MerkleTreeWriteOperations,
|
|
@@ -229,6 +230,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
229
230
|
initialStateReference: stateReference.toInspect(),
|
|
230
231
|
initialArchiveRoot: bufferToHex(archiveTree.root),
|
|
231
232
|
constants,
|
|
233
|
+
feeAssetPriceModifier,
|
|
232
234
|
});
|
|
233
235
|
|
|
234
236
|
const lightweightBuilder = await LightweightCheckpointBuilder.startNewCheckpoint(
|
|
@@ -238,6 +240,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
238
240
|
previousCheckpointOutHashes,
|
|
239
241
|
fork,
|
|
240
242
|
bindings,
|
|
243
|
+
feeAssetPriceModifier,
|
|
241
244
|
);
|
|
242
245
|
|
|
243
246
|
return new CheckpointBuilder(
|
|
@@ -257,6 +260,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
257
260
|
async openCheckpoint(
|
|
258
261
|
checkpointNumber: CheckpointNumber,
|
|
259
262
|
constants: CheckpointGlobalVariables,
|
|
263
|
+
feeAssetPriceModifier: bigint,
|
|
260
264
|
l1ToL2Messages: Fr[],
|
|
261
265
|
previousCheckpointOutHashes: Fr[],
|
|
262
266
|
fork: MerkleTreeWriteOperations,
|
|
@@ -270,6 +274,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
270
274
|
return this.startCheckpoint(
|
|
271
275
|
checkpointNumber,
|
|
272
276
|
constants,
|
|
277
|
+
feeAssetPriceModifier,
|
|
273
278
|
l1ToL2Messages,
|
|
274
279
|
previousCheckpointOutHashes,
|
|
275
280
|
fork,
|
|
@@ -284,11 +289,13 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
284
289
|
initialStateReference: stateReference.toInspect(),
|
|
285
290
|
initialArchiveRoot: bufferToHex(archiveTree.root),
|
|
286
291
|
constants,
|
|
292
|
+
feeAssetPriceModifier,
|
|
287
293
|
});
|
|
288
294
|
|
|
289
295
|
const lightweightBuilder = await LightweightCheckpointBuilder.resumeCheckpoint(
|
|
290
296
|
checkpointNumber,
|
|
291
297
|
constants,
|
|
298
|
+
feeAssetPriceModifier,
|
|
292
299
|
l1ToL2Messages,
|
|
293
300
|
previousCheckpointOutHashes,
|
|
294
301
|
fork,
|
package/src/config.ts
CHANGED
|
@@ -73,6 +73,10 @@ 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
|
+
},
|
|
76
80
|
...validatorHASignerConfigMappings,
|
|
77
81
|
};
|
|
78
82
|
|