@aztec/validator-client 0.0.1-commit.db765a8 → 0.0.1-commit.ddcf04837
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 +41 -2
- package/dest/checkpoint_builder.d.ts +14 -4
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +97 -29
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +22 -6
- package/dest/duties/validation_service.d.ts +7 -9
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +14 -32
- package/dest/factory.d.ts +7 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +5 -5
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/key_store/ha_key_store.js +1 -1
- package/dest/metrics.d.ts +6 -2
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +12 -0
- package/dest/proposal_handler.d.ts +108 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/proposal_handler.js +974 -0
- package/dest/validator.d.ts +16 -21
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +75 -231
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +120 -34
- package/src/config.ts +22 -6
- package/src/duties/validation_service.ts +17 -36
- package/src/factory.ts +10 -4
- package/src/index.ts +1 -1
- package/src/key_store/ha_key_store.ts +1 -1
- package/src/metrics.ts +19 -1
- package/src/proposal_handler.ts +1042 -0
- package/src/validator.ts +106 -263
- package/dest/block_proposal_handler.d.ts +0 -63
- package/dest/block_proposal_handler.d.ts.map +0 -1
- package/dest/block_proposal_handler.js +0 -532
- package/src/block_proposal_handler.ts +0 -535
package/dest/validator.js
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
import { getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
2
|
-
import {
|
|
3
|
-
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
|
-
import { TimeoutError } from '@aztec/foundation/error';
|
|
2
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
5
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
7
4
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
8
5
|
import { sleep } from '@aztec/foundation/sleep';
|
|
9
6
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
10
7
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
11
8
|
import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
|
|
12
|
-
import { getEpochAtSlot
|
|
13
|
-
import { accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
|
|
9
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
14
10
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
15
11
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
16
|
-
import { createHASigner } from '@aztec/validator-ha-signer/factory';
|
|
12
|
+
import { createHASigner, createLocalSignerWithProtection, createSignerFromSharedDb } from '@aztec/validator-ha-signer/factory';
|
|
17
13
|
import { DutyType } from '@aztec/validator-ha-signer/types';
|
|
18
14
|
import { EventEmitter } from 'events';
|
|
19
|
-
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
20
15
|
import { ValidationService } from './duties/validation_service.js';
|
|
21
16
|
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
22
17
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
23
18
|
import { ValidatorMetrics } from './metrics.js';
|
|
19
|
+
import { ProposalHandler } from './proposal_handler.js';
|
|
24
20
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
25
21
|
// Just cap the set to avoid unbounded growth.
|
|
26
22
|
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
@@ -35,14 +31,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
35
31
|
keyStore;
|
|
36
32
|
epochCache;
|
|
37
33
|
p2pClient;
|
|
38
|
-
|
|
34
|
+
proposalHandler;
|
|
39
35
|
blockSource;
|
|
40
36
|
checkpointsBuilder;
|
|
41
37
|
worldState;
|
|
42
38
|
l1ToL2MessageSource;
|
|
43
39
|
config;
|
|
44
40
|
blobClient;
|
|
45
|
-
|
|
41
|
+
slashingProtectionSigner;
|
|
46
42
|
dateProvider;
|
|
47
43
|
tracer;
|
|
48
44
|
validationService;
|
|
@@ -57,8 +53,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
57
53
|
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */ lastAttestedEpochByAttester;
|
|
58
54
|
proposersOfInvalidBlocks;
|
|
59
55
|
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */ lastAttestedProposal;
|
|
60
|
-
constructor(keyStore, epochCache, p2pClient,
|
|
61
|
-
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.
|
|
56
|
+
constructor(keyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
57
|
+
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();
|
|
62
58
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
63
59
|
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
64
60
|
this.tracer = telemetry.getTracer('Validator');
|
|
@@ -113,37 +109,49 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
113
109
|
this.log.error(`Error updating epoch committee`, err);
|
|
114
110
|
}
|
|
115
111
|
}
|
|
116
|
-
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
112
|
+
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), slashingProtectionDb) {
|
|
117
113
|
const metrics = new ValidatorMetrics(telemetry);
|
|
118
114
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
119
115
|
txsPermitted: !config.disableTransactions,
|
|
120
|
-
maxTxsPerBlock: config.
|
|
116
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock
|
|
121
117
|
});
|
|
122
|
-
const
|
|
118
|
+
const proposalHandler = new ProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, blobClient, metrics, dateProvider, telemetry, undefined);
|
|
123
119
|
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
124
|
-
let
|
|
125
|
-
|
|
126
|
-
|
|
120
|
+
let slashingProtectionSigner;
|
|
121
|
+
if (slashingProtectionDb) {
|
|
122
|
+
// Shared database mode: use a pre-existing database (e.g. for testing HA setups).
|
|
123
|
+
({ signer: slashingProtectionSigner } = createSignerFromSharedDb(slashingProtectionDb, config, {
|
|
124
|
+
telemetryClient: telemetry,
|
|
125
|
+
dateProvider
|
|
126
|
+
}));
|
|
127
|
+
} else if (config.haSigningEnabled) {
|
|
128
|
+
// Multi-node HA mode: use PostgreSQL-backed distributed locking.
|
|
127
129
|
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
128
130
|
const haConfig = {
|
|
129
131
|
...config,
|
|
130
132
|
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000
|
|
131
133
|
};
|
|
132
|
-
|
|
134
|
+
({ signer: slashingProtectionSigner } = await createHASigner(haConfig, {
|
|
133
135
|
telemetryClient: telemetry,
|
|
134
136
|
dateProvider
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
|
|
137
|
+
}));
|
|
138
|
+
} else {
|
|
139
|
+
// Single-node mode: use LMDB-backed local signing protection.
|
|
140
|
+
// This prevents double-signing if the node crashes and restarts mid-proposal.
|
|
141
|
+
({ signer: slashingProtectionSigner } = await createLocalSignerWithProtection(config, {
|
|
142
|
+
telemetryClient: telemetry,
|
|
143
|
+
dateProvider
|
|
144
|
+
}));
|
|
138
145
|
}
|
|
139
|
-
const
|
|
146
|
+
const validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, slashingProtectionSigner);
|
|
147
|
+
const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider, telemetry);
|
|
140
148
|
return validator;
|
|
141
149
|
}
|
|
142
150
|
getValidatorAddresses() {
|
|
143
151
|
return this.keyStore.getAddresses().filter((addr)=>!this.config.disabledValidators.some((disabled)=>disabled.equals(addr)));
|
|
144
152
|
}
|
|
145
|
-
|
|
146
|
-
return this.
|
|
153
|
+
getProposalHandler() {
|
|
154
|
+
return this.proposalHandler;
|
|
147
155
|
}
|
|
148
156
|
signWithAddress(addr, msg, context) {
|
|
149
157
|
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
@@ -164,17 +172,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
164
172
|
};
|
|
165
173
|
}
|
|
166
174
|
reloadKeystore(newManager) {
|
|
167
|
-
if (this.config.haSigningEnabled && !this.haSigner) {
|
|
168
|
-
this.log.warn('HA signing is enabled in config but was not initialized at startup. ' + 'Restart the node to enable HA signing.');
|
|
169
|
-
} else if (!this.config.haSigningEnabled && this.haSigner) {
|
|
170
|
-
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.');
|
|
171
|
-
}
|
|
172
175
|
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
173
|
-
|
|
174
|
-
this.keyStore = new HAKeyStore(newAdapter, this.haSigner);
|
|
175
|
-
} else {
|
|
176
|
-
this.keyStore = newAdapter;
|
|
177
|
-
}
|
|
176
|
+
this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
|
|
178
177
|
this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
|
|
179
178
|
}
|
|
180
179
|
async start() {
|
|
@@ -208,7 +207,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
208
207
|
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
209
208
|
// and processed separately via the block handler above.
|
|
210
209
|
const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
211
|
-
this.p2pClient.
|
|
210
|
+
this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
|
|
212
211
|
// Duplicate proposal handler - triggers slashing for equivocation
|
|
213
212
|
this.p2pClient.registerDuplicateProposalCallback((info)=>{
|
|
214
213
|
this.handleDuplicateProposal(info);
|
|
@@ -237,13 +236,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
237
236
|
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
238
237
|
return false;
|
|
239
238
|
}
|
|
240
|
-
//
|
|
239
|
+
// Log self-proposals from HA peers (same validator key on different nodes)
|
|
241
240
|
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
242
|
-
this.log.
|
|
241
|
+
this.log.verbose(`Processing block proposal from HA peer for slot ${slotNumber}`, {
|
|
243
242
|
proposer: proposer.toString(),
|
|
244
243
|
slotNumber
|
|
245
244
|
});
|
|
246
|
-
return false;
|
|
247
245
|
}
|
|
248
246
|
// Check if we're in the committee (for metrics purposes)
|
|
249
247
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
@@ -259,12 +257,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
259
257
|
});
|
|
260
258
|
// Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
|
|
261
259
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
262
|
-
const {
|
|
263
|
-
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n
|
|
264
|
-
const validationResult = await this.
|
|
260
|
+
const { slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
261
|
+
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n || partOfCommittee || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
|
|
262
|
+
const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
|
|
265
263
|
if (!validationResult.isValid) {
|
|
266
|
-
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
267
264
|
const reason = validationResult.reason || 'unknown';
|
|
265
|
+
this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
|
|
268
266
|
// Classify failure reason: bad proposal vs node issue
|
|
269
267
|
const badProposalReasons = [
|
|
270
268
|
'invalid_proposal',
|
|
@@ -304,58 +302,46 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
304
302
|
* the lastBlock is extracted and processed separately via the block handler.
|
|
305
303
|
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
306
304
|
*/ async attestToCheckpointProposal(proposal, _proposalSender) {
|
|
307
|
-
const
|
|
305
|
+
const proposalSlotNumber = proposal.slotNumber;
|
|
308
306
|
const proposer = proposal.getSender();
|
|
309
307
|
// If escape hatch is open for this slot's epoch, do not attest.
|
|
310
|
-
if (await this.epochCache.isEscapeHatchOpenAtSlot(
|
|
311
|
-
this.log.warn(`Escape hatch open for slot ${
|
|
312
|
-
return undefined;
|
|
313
|
-
}
|
|
314
|
-
// Reject proposals with invalid signatures
|
|
315
|
-
if (!proposer) {
|
|
316
|
-
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
308
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(proposalSlotNumber)) {
|
|
309
|
+
this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
|
|
317
310
|
return undefined;
|
|
318
311
|
}
|
|
319
312
|
// Ignore proposals from ourselves (may happen in HA setups)
|
|
320
|
-
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
321
|
-
this.log.
|
|
313
|
+
if (proposer && this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
314
|
+
this.log.debug(`Ignoring block proposal from self for slot ${proposalSlotNumber}`, {
|
|
322
315
|
proposer: proposer.toString(),
|
|
323
|
-
|
|
316
|
+
proposalSlotNumber
|
|
324
317
|
});
|
|
325
318
|
return undefined;
|
|
326
319
|
}
|
|
327
|
-
//
|
|
328
|
-
|
|
329
|
-
this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`);
|
|
330
|
-
return undefined;
|
|
331
|
-
}
|
|
332
|
-
// Check that I have any address in current committee before attesting
|
|
333
|
-
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
320
|
+
// Check that I have any address in the committee where this checkpoint will land before attesting
|
|
321
|
+
const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
|
|
334
322
|
const partOfCommittee = inCommittee.length > 0;
|
|
335
323
|
const proposalInfo = {
|
|
336
|
-
|
|
324
|
+
proposalSlotNumber,
|
|
337
325
|
archive: proposal.archive.toString(),
|
|
338
|
-
proposer: proposer
|
|
339
|
-
txCount: proposal.txHashes.length
|
|
326
|
+
proposer: proposer?.toString()
|
|
340
327
|
};
|
|
341
|
-
this.log.info(`Received checkpoint proposal for slot ${
|
|
328
|
+
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
342
329
|
...proposalInfo,
|
|
343
|
-
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
344
330
|
fishermanMode: this.config.fishermanMode || false
|
|
345
331
|
});
|
|
346
|
-
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
332
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
|
|
333
|
+
// Uses the cached result from the all-nodes callback if available (avoids double validation).
|
|
334
|
+
let checkpointNumber;
|
|
347
335
|
if (this.config.skipCheckpointProposalValidation) {
|
|
348
|
-
this.log.warn(`Skipping checkpoint proposal validation for slot ${
|
|
336
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
337
|
+
checkpointNumber = CheckpointNumber(0);
|
|
349
338
|
} else {
|
|
350
|
-
const validationResult = await this.
|
|
339
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
351
340
|
if (!validationResult.isValid) {
|
|
352
341
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
353
342
|
return undefined;
|
|
354
343
|
}
|
|
355
|
-
|
|
356
|
-
// Upload blobs to filestore if we can (fire and forget)
|
|
357
|
-
if (this.blobClient.canUpload()) {
|
|
358
|
-
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
344
|
+
checkpointNumber = validationResult.checkpointNumber;
|
|
359
345
|
}
|
|
360
346
|
// Check that I have any address in current committee before attesting
|
|
361
347
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
@@ -364,14 +350,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
364
350
|
return undefined;
|
|
365
351
|
}
|
|
366
352
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
367
|
-
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${
|
|
353
|
+
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
368
354
|
...proposalInfo,
|
|
369
355
|
inCommittee: partOfCommittee,
|
|
370
356
|
fishermanMode: this.config.fishermanMode || false
|
|
371
357
|
});
|
|
372
358
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
373
359
|
// Track epoch participation per attester: count each (attester, epoch) pair at most once
|
|
374
|
-
const proposalEpoch = getEpochAtSlot(
|
|
360
|
+
const proposalEpoch = getEpochAtSlot(proposalSlotNumber, this.epochCache.getL1Constants());
|
|
375
361
|
for (const attester of inCommittee){
|
|
376
362
|
const key = attester.toString();
|
|
377
363
|
const lastEpoch = this.lastAttestedEpochByAttester.get(key);
|
|
@@ -396,13 +382,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
396
382
|
}
|
|
397
383
|
if (this.config.fishermanMode) {
|
|
398
384
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
399
|
-
this.log.info(`Creating checkpoint attestations for slot ${
|
|
385
|
+
this.log.info(`Creating checkpoint attestations for slot ${proposalSlotNumber}`, {
|
|
400
386
|
...proposalInfo,
|
|
401
387
|
attestors: attestors.map((a)=>a.toString())
|
|
402
388
|
});
|
|
403
389
|
return undefined;
|
|
404
390
|
}
|
|
405
|
-
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
391
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
|
|
406
392
|
}
|
|
407
393
|
/**
|
|
408
394
|
* Checks if we should attest to a slot based on equivocation prevention rules.
|
|
@@ -419,160 +405,18 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
419
405
|
}
|
|
420
406
|
return true;
|
|
421
407
|
}
|
|
422
|
-
async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
|
|
408
|
+
async createCheckpointAttestationsFromProposal(proposal, attestors = [], checkpointNumber) {
|
|
423
409
|
// Equivocation check: must happen right before signing to minimize the race window
|
|
424
410
|
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
425
411
|
return undefined;
|
|
426
412
|
}
|
|
427
|
-
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
413
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
|
|
428
414
|
// Track the proposal we attested to (to prevent equivocation)
|
|
429
415
|
this.lastAttestedProposal = proposal;
|
|
430
416
|
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
431
417
|
return attestations;
|
|
432
418
|
}
|
|
433
419
|
/**
|
|
434
|
-
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
435
|
-
* @returns Validation result with isValid flag and reason if invalid.
|
|
436
|
-
*/ async validateCheckpointProposal(proposal, proposalInfo) {
|
|
437
|
-
const slot = proposal.slotNumber;
|
|
438
|
-
// Timeout block syncing at the start of the next slot
|
|
439
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
440
|
-
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
|
|
441
|
-
const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
|
|
442
|
-
// Wait for last block to sync by archive
|
|
443
|
-
let lastBlockHeader;
|
|
444
|
-
try {
|
|
445
|
-
lastBlockHeader = await retryUntil(async ()=>{
|
|
446
|
-
await this.blockSource.syncImmediate();
|
|
447
|
-
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
448
|
-
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, timeoutSeconds, 0.5);
|
|
449
|
-
} catch (err) {
|
|
450
|
-
if (err instanceof TimeoutError) {
|
|
451
|
-
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
452
|
-
return {
|
|
453
|
-
isValid: false,
|
|
454
|
-
reason: 'last_block_not_found'
|
|
455
|
-
};
|
|
456
|
-
}
|
|
457
|
-
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
458
|
-
return {
|
|
459
|
-
isValid: false,
|
|
460
|
-
reason: 'block_fetch_error'
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
|
-
if (!lastBlockHeader) {
|
|
464
|
-
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
465
|
-
return {
|
|
466
|
-
isValid: false,
|
|
467
|
-
reason: 'last_block_not_found'
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
// Get all full blocks for the slot and checkpoint
|
|
471
|
-
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
472
|
-
if (blocks.length === 0) {
|
|
473
|
-
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
474
|
-
return {
|
|
475
|
-
isValid: false,
|
|
476
|
-
reason: 'no_blocks_for_slot'
|
|
477
|
-
};
|
|
478
|
-
}
|
|
479
|
-
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
480
|
-
if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
|
|
481
|
-
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
482
|
-
return {
|
|
483
|
-
isValid: false,
|
|
484
|
-
reason: 'last_block_archive_mismatch'
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
|
-
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
488
|
-
...proposalInfo,
|
|
489
|
-
blockNumbers: blocks.map((b)=>b.number)
|
|
490
|
-
});
|
|
491
|
-
// Get checkpoint constants from first block
|
|
492
|
-
const firstBlock = blocks[0];
|
|
493
|
-
const constants = this.extractCheckpointConstants(firstBlock);
|
|
494
|
-
const checkpointNumber = firstBlock.checkpointNumber;
|
|
495
|
-
// Get L1-to-L2 messages for this checkpoint
|
|
496
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
497
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
498
|
-
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
499
|
-
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch)).filter((c)=>c.checkpointNumber < checkpointNumber).map((c)=>c.checkpointOutHash);
|
|
500
|
-
// Fork world state at the block before the first block
|
|
501
|
-
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
502
|
-
const fork = await this.worldState.fork(parentBlockNumber);
|
|
503
|
-
try {
|
|
504
|
-
// Create checkpoint builder with all existing blocks
|
|
505
|
-
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
|
|
506
|
-
// Complete the checkpoint to get computed values
|
|
507
|
-
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
508
|
-
// Compare checkpoint header with proposal
|
|
509
|
-
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
510
|
-
this.log.warn(`Checkpoint header mismatch`, {
|
|
511
|
-
...proposalInfo,
|
|
512
|
-
computed: computedCheckpoint.header.toInspect(),
|
|
513
|
-
proposal: proposal.checkpointHeader.toInspect()
|
|
514
|
-
});
|
|
515
|
-
return {
|
|
516
|
-
isValid: false,
|
|
517
|
-
reason: 'checkpoint_header_mismatch'
|
|
518
|
-
};
|
|
519
|
-
}
|
|
520
|
-
// Compare archive root with proposal
|
|
521
|
-
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
522
|
-
this.log.warn(`Archive root mismatch`, {
|
|
523
|
-
...proposalInfo,
|
|
524
|
-
computed: computedCheckpoint.archive.root.toString(),
|
|
525
|
-
proposal: proposal.archive.toString()
|
|
526
|
-
});
|
|
527
|
-
return {
|
|
528
|
-
isValid: false,
|
|
529
|
-
reason: 'archive_mismatch'
|
|
530
|
-
};
|
|
531
|
-
}
|
|
532
|
-
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
533
|
-
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
534
|
-
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
535
|
-
const computedEpochOutHash = accumulateCheckpointOutHashes([
|
|
536
|
-
...previousCheckpointOutHashes,
|
|
537
|
-
checkpointOutHash
|
|
538
|
-
]);
|
|
539
|
-
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
540
|
-
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
541
|
-
this.log.warn(`Epoch out hash mismatch`, {
|
|
542
|
-
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
543
|
-
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
544
|
-
checkpointOutHash: checkpointOutHash.toString(),
|
|
545
|
-
previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
|
|
546
|
-
...proposalInfo
|
|
547
|
-
});
|
|
548
|
-
return {
|
|
549
|
-
isValid: false,
|
|
550
|
-
reason: 'out_hash_mismatch'
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
554
|
-
return {
|
|
555
|
-
isValid: true
|
|
556
|
-
};
|
|
557
|
-
} finally{
|
|
558
|
-
await fork.close();
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
/**
|
|
562
|
-
* Extract checkpoint global variables from a block.
|
|
563
|
-
*/ extractCheckpointConstants(block) {
|
|
564
|
-
const gv = block.header.globalVariables;
|
|
565
|
-
return {
|
|
566
|
-
chainId: gv.chainId,
|
|
567
|
-
version: gv.version,
|
|
568
|
-
slotNumber: gv.slotNumber,
|
|
569
|
-
timestamp: gv.timestamp,
|
|
570
|
-
coinbase: gv.coinbase,
|
|
571
|
-
feeRecipient: gv.feeRecipient,
|
|
572
|
-
gasFees: gv.gasFees
|
|
573
|
-
};
|
|
574
|
-
}
|
|
575
|
-
/**
|
|
576
420
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
577
421
|
*/ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
|
|
578
422
|
try {
|
|
@@ -657,7 +501,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
657
501
|
}
|
|
658
502
|
]);
|
|
659
503
|
}
|
|
660
|
-
async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
|
|
504
|
+
async createBlockProposal(blockHeader, checkpointNumber, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
|
|
661
505
|
// Validate that we're not creating a proposal for an older or equal position
|
|
662
506
|
if (this.lastProposedBlock) {
|
|
663
507
|
const lastSlot = this.lastProposedBlock.slotNumber;
|
|
@@ -668,14 +512,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
668
512
|
}
|
|
669
513
|
}
|
|
670
514
|
this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
|
|
671
|
-
const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
515
|
+
const newProposal = await this.validationService.createBlockProposal(blockHeader, checkpointNumber, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
672
516
|
...options,
|
|
673
517
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
674
518
|
});
|
|
675
519
|
this.lastProposedBlock = newProposal;
|
|
676
520
|
return newProposal;
|
|
677
521
|
}
|
|
678
|
-
async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier,
|
|
522
|
+
async createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options = {}) {
|
|
679
523
|
// Validate that we're not creating a proposal for an older or equal slot
|
|
680
524
|
if (this.lastProposedCheckpoint) {
|
|
681
525
|
const lastSlot = this.lastProposedCheckpoint.slotNumber;
|
|
@@ -685,23 +529,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
685
529
|
}
|
|
686
530
|
}
|
|
687
531
|
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
688
|
-
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier,
|
|
532
|
+
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options);
|
|
689
533
|
this.lastProposedCheckpoint = newProposal;
|
|
690
534
|
return newProposal;
|
|
691
535
|
}
|
|
692
536
|
async broadcastBlockProposal(proposal) {
|
|
693
537
|
await this.p2pClient.broadcastProposal(proposal);
|
|
694
538
|
}
|
|
695
|
-
async signAttestationsAndSigners(attestationsAndSigners, proposer, slot,
|
|
696
|
-
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot,
|
|
539
|
+
async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, checkpointNumber) {
|
|
540
|
+
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, checkpointNumber);
|
|
697
541
|
}
|
|
698
|
-
async collectOwnAttestations(proposal) {
|
|
542
|
+
async collectOwnAttestations(proposal, checkpointNumber) {
|
|
699
543
|
const slot = proposal.slotNumber;
|
|
700
544
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
701
545
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
|
|
702
546
|
inCommittee
|
|
703
547
|
});
|
|
704
|
-
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
548
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
|
|
705
549
|
if (!attestations) {
|
|
706
550
|
return [];
|
|
707
551
|
}
|
|
@@ -713,7 +557,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
713
557
|
});
|
|
714
558
|
return attestations;
|
|
715
559
|
}
|
|
716
|
-
async collectAttestations(proposal, required, deadline) {
|
|
560
|
+
async collectAttestations(proposal, required, deadline, checkpointNumber) {
|
|
717
561
|
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
718
562
|
const slot = proposal.slotNumber;
|
|
719
563
|
this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
|
|
@@ -721,7 +565,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
721
565
|
this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
|
|
722
566
|
throw new AttestationTimeoutError(0, required, slot);
|
|
723
567
|
}
|
|
724
|
-
await this.collectOwnAttestations(proposal);
|
|
568
|
+
await this.collectOwnAttestations(proposal, checkpointNumber);
|
|
725
569
|
const proposalId = proposal.archive.toString();
|
|
726
570
|
const myAddresses = this.getValidatorAddresses();
|
|
727
571
|
let 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.ddcf04837",
|
|
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.ddcf04837",
|
|
68
|
+
"@aztec/blob-lib": "0.0.1-commit.ddcf04837",
|
|
69
|
+
"@aztec/constants": "0.0.1-commit.ddcf04837",
|
|
70
|
+
"@aztec/epoch-cache": "0.0.1-commit.ddcf04837",
|
|
71
|
+
"@aztec/ethereum": "0.0.1-commit.ddcf04837",
|
|
72
|
+
"@aztec/foundation": "0.0.1-commit.ddcf04837",
|
|
73
|
+
"@aztec/node-keystore": "0.0.1-commit.ddcf04837",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.ddcf04837",
|
|
75
|
+
"@aztec/p2p": "0.0.1-commit.ddcf04837",
|
|
76
|
+
"@aztec/protocol-contracts": "0.0.1-commit.ddcf04837",
|
|
77
|
+
"@aztec/prover-client": "0.0.1-commit.ddcf04837",
|
|
78
|
+
"@aztec/simulator": "0.0.1-commit.ddcf04837",
|
|
79
|
+
"@aztec/slasher": "0.0.1-commit.ddcf04837",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.ddcf04837",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.ddcf04837",
|
|
82
|
+
"@aztec/validator-ha-signer": "0.0.1-commit.ddcf04837",
|
|
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.ddcf04837",
|
|
90
|
+
"@aztec/world-state": "0.0.1-commit.ddcf04837",
|
|
91
91
|
"@electric-sql/pglite": "^0.3.14",
|
|
92
92
|
"@jest/globals": "^30.0.0",
|
|
93
93
|
"@types/jest": "^30.0.0",
|