@aztec/validator-client 0.0.1-commit.993d52e → 0.0.1-commit.9badcec54
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 +101 -30
- 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 +78 -231
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +124 -35
- 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,34 +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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
({ signer: slashingProtectionSigner } = await createHASigner(haConfig, {
|
|
135
|
+
telemetryClient: telemetry,
|
|
136
|
+
dateProvider
|
|
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
|
+
}));
|
|
145
|
+
}
|
|
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);
|
|
137
148
|
return validator;
|
|
138
149
|
}
|
|
139
150
|
getValidatorAddresses() {
|
|
140
151
|
return this.keyStore.getAddresses().filter((addr)=>!this.config.disabledValidators.some((disabled)=>disabled.equals(addr)));
|
|
141
152
|
}
|
|
142
|
-
|
|
143
|
-
return this.
|
|
153
|
+
getProposalHandler() {
|
|
154
|
+
return this.proposalHandler;
|
|
144
155
|
}
|
|
145
156
|
signWithAddress(addr, msg, context) {
|
|
146
157
|
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
@@ -161,17 +172,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
161
172
|
};
|
|
162
173
|
}
|
|
163
174
|
reloadKeystore(newManager) {
|
|
164
|
-
if (this.config.haSigningEnabled && !this.haSigner) {
|
|
165
|
-
this.log.warn('HA signing is enabled in config but was not initialized at startup. ' + 'Restart the node to enable HA signing.');
|
|
166
|
-
} else if (!this.config.haSigningEnabled && this.haSigner) {
|
|
167
|
-
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.');
|
|
168
|
-
}
|
|
169
175
|
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
170
|
-
|
|
171
|
-
this.keyStore = new HAKeyStore(newAdapter, this.haSigner);
|
|
172
|
-
} else {
|
|
173
|
-
this.keyStore = newAdapter;
|
|
174
|
-
}
|
|
176
|
+
this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
|
|
175
177
|
this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
|
|
176
178
|
}
|
|
177
179
|
async start() {
|
|
@@ -205,7 +207,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
205
207
|
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
206
208
|
// and processed separately via the block handler above.
|
|
207
209
|
const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
208
|
-
this.p2pClient.
|
|
210
|
+
this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
|
|
209
211
|
// Duplicate proposal handler - triggers slashing for equivocation
|
|
210
212
|
this.p2pClient.registerDuplicateProposalCallback((info)=>{
|
|
211
213
|
this.handleDuplicateProposal(info);
|
|
@@ -234,13 +236,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
234
236
|
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
235
237
|
return false;
|
|
236
238
|
}
|
|
237
|
-
//
|
|
239
|
+
// Log self-proposals from HA peers (same validator key on different nodes)
|
|
238
240
|
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
239
|
-
this.log.
|
|
241
|
+
this.log.verbose(`Processing block proposal from HA peer for slot ${slotNumber}`, {
|
|
240
242
|
proposer: proposer.toString(),
|
|
241
243
|
slotNumber
|
|
242
244
|
});
|
|
243
|
-
return false;
|
|
244
245
|
}
|
|
245
246
|
// Check if we're in the committee (for metrics purposes)
|
|
246
247
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
@@ -256,12 +257,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
256
257
|
});
|
|
257
258
|
// Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
|
|
258
259
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
259
|
-
const {
|
|
260
|
-
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n
|
|
261
|
-
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);
|
|
262
263
|
if (!validationResult.isValid) {
|
|
263
|
-
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
264
264
|
const reason = validationResult.reason || 'unknown';
|
|
265
|
+
this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
|
|
265
266
|
// Classify failure reason: bad proposal vs node issue
|
|
266
267
|
const badProposalReasons = [
|
|
267
268
|
'invalid_proposal',
|
|
@@ -301,58 +302,46 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
301
302
|
* the lastBlock is extracted and processed separately via the block handler.
|
|
302
303
|
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
303
304
|
*/ async attestToCheckpointProposal(proposal, _proposalSender) {
|
|
304
|
-
const
|
|
305
|
+
const proposalSlotNumber = proposal.slotNumber;
|
|
305
306
|
const proposer = proposal.getSender();
|
|
306
307
|
// If escape hatch is open for this slot's epoch, do not attest.
|
|
307
|
-
if (await this.epochCache.isEscapeHatchOpenAtSlot(
|
|
308
|
-
this.log.warn(`Escape hatch open for slot ${
|
|
309
|
-
return undefined;
|
|
310
|
-
}
|
|
311
|
-
// Reject proposals with invalid signatures
|
|
312
|
-
if (!proposer) {
|
|
313
|
-
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`);
|
|
314
310
|
return undefined;
|
|
315
311
|
}
|
|
316
312
|
// Ignore proposals from ourselves (may happen in HA setups)
|
|
317
|
-
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
318
|
-
this.log.
|
|
313
|
+
if (proposer && this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
314
|
+
this.log.debug(`Ignoring block proposal from self for slot ${proposalSlotNumber}`, {
|
|
319
315
|
proposer: proposer.toString(),
|
|
320
|
-
|
|
316
|
+
proposalSlotNumber
|
|
321
317
|
});
|
|
322
318
|
return undefined;
|
|
323
319
|
}
|
|
324
|
-
//
|
|
325
|
-
|
|
326
|
-
this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`);
|
|
327
|
-
return undefined;
|
|
328
|
-
}
|
|
329
|
-
// Check that I have any address in current committee before attesting
|
|
330
|
-
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());
|
|
331
322
|
const partOfCommittee = inCommittee.length > 0;
|
|
332
323
|
const proposalInfo = {
|
|
333
|
-
|
|
324
|
+
proposalSlotNumber,
|
|
334
325
|
archive: proposal.archive.toString(),
|
|
335
|
-
proposer: proposer
|
|
336
|
-
txCount: proposal.txHashes.length
|
|
326
|
+
proposer: proposer?.toString()
|
|
337
327
|
};
|
|
338
|
-
this.log.info(`Received checkpoint proposal for slot ${
|
|
328
|
+
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
339
329
|
...proposalInfo,
|
|
340
|
-
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
341
330
|
fishermanMode: this.config.fishermanMode || false
|
|
342
331
|
});
|
|
343
|
-
// 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;
|
|
344
335
|
if (this.config.skipCheckpointProposalValidation) {
|
|
345
|
-
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);
|
|
346
338
|
} else {
|
|
347
|
-
const validationResult = await this.
|
|
339
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
348
340
|
if (!validationResult.isValid) {
|
|
349
341
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
350
342
|
return undefined;
|
|
351
343
|
}
|
|
352
|
-
|
|
353
|
-
// Upload blobs to filestore if we can (fire and forget)
|
|
354
|
-
if (this.blobClient.canUpload()) {
|
|
355
|
-
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
344
|
+
checkpointNumber = validationResult.checkpointNumber;
|
|
356
345
|
}
|
|
357
346
|
// Check that I have any address in current committee before attesting
|
|
358
347
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
@@ -361,14 +350,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
361
350
|
return undefined;
|
|
362
351
|
}
|
|
363
352
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
364
|
-
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${
|
|
353
|
+
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
365
354
|
...proposalInfo,
|
|
366
355
|
inCommittee: partOfCommittee,
|
|
367
356
|
fishermanMode: this.config.fishermanMode || false
|
|
368
357
|
});
|
|
369
358
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
370
359
|
// Track epoch participation per attester: count each (attester, epoch) pair at most once
|
|
371
|
-
const proposalEpoch = getEpochAtSlot(
|
|
360
|
+
const proposalEpoch = getEpochAtSlot(proposalSlotNumber, this.epochCache.getL1Constants());
|
|
372
361
|
for (const attester of inCommittee){
|
|
373
362
|
const key = attester.toString();
|
|
374
363
|
const lastEpoch = this.lastAttestedEpochByAttester.get(key);
|
|
@@ -393,13 +382,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
393
382
|
}
|
|
394
383
|
if (this.config.fishermanMode) {
|
|
395
384
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
396
|
-
this.log.info(`Creating checkpoint attestations for slot ${
|
|
385
|
+
this.log.info(`Creating checkpoint attestations for slot ${proposalSlotNumber}`, {
|
|
397
386
|
...proposalInfo,
|
|
398
387
|
attestors: attestors.map((a)=>a.toString())
|
|
399
388
|
});
|
|
400
389
|
return undefined;
|
|
401
390
|
}
|
|
402
|
-
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
391
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
|
|
403
392
|
}
|
|
404
393
|
/**
|
|
405
394
|
* Checks if we should attest to a slot based on equivocation prevention rules.
|
|
@@ -416,160 +405,18 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
416
405
|
}
|
|
417
406
|
return true;
|
|
418
407
|
}
|
|
419
|
-
async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
|
|
408
|
+
async createCheckpointAttestationsFromProposal(proposal, attestors = [], checkpointNumber) {
|
|
420
409
|
// Equivocation check: must happen right before signing to minimize the race window
|
|
421
410
|
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
422
411
|
return undefined;
|
|
423
412
|
}
|
|
424
|
-
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
413
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
|
|
425
414
|
// Track the proposal we attested to (to prevent equivocation)
|
|
426
415
|
this.lastAttestedProposal = proposal;
|
|
427
416
|
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
428
417
|
return attestations;
|
|
429
418
|
}
|
|
430
419
|
/**
|
|
431
|
-
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
432
|
-
* @returns Validation result with isValid flag and reason if invalid.
|
|
433
|
-
*/ async validateCheckpointProposal(proposal, proposalInfo) {
|
|
434
|
-
const slot = proposal.slotNumber;
|
|
435
|
-
// Timeout block syncing at the start of the next slot
|
|
436
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
437
|
-
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
|
|
438
|
-
const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
|
|
439
|
-
// Wait for last block to sync by archive
|
|
440
|
-
let lastBlockHeader;
|
|
441
|
-
try {
|
|
442
|
-
lastBlockHeader = await retryUntil(async ()=>{
|
|
443
|
-
await this.blockSource.syncImmediate();
|
|
444
|
-
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
445
|
-
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, timeoutSeconds, 0.5);
|
|
446
|
-
} catch (err) {
|
|
447
|
-
if (err instanceof TimeoutError) {
|
|
448
|
-
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
449
|
-
return {
|
|
450
|
-
isValid: false,
|
|
451
|
-
reason: 'last_block_not_found'
|
|
452
|
-
};
|
|
453
|
-
}
|
|
454
|
-
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
455
|
-
return {
|
|
456
|
-
isValid: false,
|
|
457
|
-
reason: 'block_fetch_error'
|
|
458
|
-
};
|
|
459
|
-
}
|
|
460
|
-
if (!lastBlockHeader) {
|
|
461
|
-
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
462
|
-
return {
|
|
463
|
-
isValid: false,
|
|
464
|
-
reason: 'last_block_not_found'
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
// Get all full blocks for the slot and checkpoint
|
|
468
|
-
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
469
|
-
if (blocks.length === 0) {
|
|
470
|
-
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
471
|
-
return {
|
|
472
|
-
isValid: false,
|
|
473
|
-
reason: 'no_blocks_for_slot'
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
477
|
-
if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
|
|
478
|
-
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
479
|
-
return {
|
|
480
|
-
isValid: false,
|
|
481
|
-
reason: 'last_block_archive_mismatch'
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
485
|
-
...proposalInfo,
|
|
486
|
-
blockNumbers: blocks.map((b)=>b.number)
|
|
487
|
-
});
|
|
488
|
-
// Get checkpoint constants from first block
|
|
489
|
-
const firstBlock = blocks[0];
|
|
490
|
-
const constants = this.extractCheckpointConstants(firstBlock);
|
|
491
|
-
const checkpointNumber = firstBlock.checkpointNumber;
|
|
492
|
-
// Get L1-to-L2 messages for this checkpoint
|
|
493
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
494
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
495
|
-
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
496
|
-
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch)).filter((c)=>c.checkpointNumber < checkpointNumber).map((c)=>c.checkpointOutHash);
|
|
497
|
-
// Fork world state at the block before the first block
|
|
498
|
-
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
499
|
-
const fork = await this.worldState.fork(parentBlockNumber);
|
|
500
|
-
try {
|
|
501
|
-
// Create checkpoint builder with all existing blocks
|
|
502
|
-
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
|
|
503
|
-
// Complete the checkpoint to get computed values
|
|
504
|
-
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
505
|
-
// Compare checkpoint header with proposal
|
|
506
|
-
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
507
|
-
this.log.warn(`Checkpoint header mismatch`, {
|
|
508
|
-
...proposalInfo,
|
|
509
|
-
computed: computedCheckpoint.header.toInspect(),
|
|
510
|
-
proposal: proposal.checkpointHeader.toInspect()
|
|
511
|
-
});
|
|
512
|
-
return {
|
|
513
|
-
isValid: false,
|
|
514
|
-
reason: 'checkpoint_header_mismatch'
|
|
515
|
-
};
|
|
516
|
-
}
|
|
517
|
-
// Compare archive root with proposal
|
|
518
|
-
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
519
|
-
this.log.warn(`Archive root mismatch`, {
|
|
520
|
-
...proposalInfo,
|
|
521
|
-
computed: computedCheckpoint.archive.root.toString(),
|
|
522
|
-
proposal: proposal.archive.toString()
|
|
523
|
-
});
|
|
524
|
-
return {
|
|
525
|
-
isValid: false,
|
|
526
|
-
reason: 'archive_mismatch'
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
530
|
-
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
531
|
-
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
532
|
-
const computedEpochOutHash = accumulateCheckpointOutHashes([
|
|
533
|
-
...previousCheckpointOutHashes,
|
|
534
|
-
checkpointOutHash
|
|
535
|
-
]);
|
|
536
|
-
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
537
|
-
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
538
|
-
this.log.warn(`Epoch out hash mismatch`, {
|
|
539
|
-
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
540
|
-
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
541
|
-
checkpointOutHash: checkpointOutHash.toString(),
|
|
542
|
-
previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
|
|
543
|
-
...proposalInfo
|
|
544
|
-
});
|
|
545
|
-
return {
|
|
546
|
-
isValid: false,
|
|
547
|
-
reason: 'out_hash_mismatch'
|
|
548
|
-
};
|
|
549
|
-
}
|
|
550
|
-
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
551
|
-
return {
|
|
552
|
-
isValid: true
|
|
553
|
-
};
|
|
554
|
-
} finally{
|
|
555
|
-
await fork.close();
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
/**
|
|
559
|
-
* Extract checkpoint global variables from a block.
|
|
560
|
-
*/ extractCheckpointConstants(block) {
|
|
561
|
-
const gv = block.header.globalVariables;
|
|
562
|
-
return {
|
|
563
|
-
chainId: gv.chainId,
|
|
564
|
-
version: gv.version,
|
|
565
|
-
slotNumber: gv.slotNumber,
|
|
566
|
-
timestamp: gv.timestamp,
|
|
567
|
-
coinbase: gv.coinbase,
|
|
568
|
-
feeRecipient: gv.feeRecipient,
|
|
569
|
-
gasFees: gv.gasFees
|
|
570
|
-
};
|
|
571
|
-
}
|
|
572
|
-
/**
|
|
573
420
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
574
421
|
*/ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
|
|
575
422
|
try {
|
|
@@ -654,7 +501,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
654
501
|
}
|
|
655
502
|
]);
|
|
656
503
|
}
|
|
657
|
-
async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
|
|
504
|
+
async createBlockProposal(blockHeader, checkpointNumber, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
|
|
658
505
|
// Validate that we're not creating a proposal for an older or equal position
|
|
659
506
|
if (this.lastProposedBlock) {
|
|
660
507
|
const lastSlot = this.lastProposedBlock.slotNumber;
|
|
@@ -665,14 +512,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
665
512
|
}
|
|
666
513
|
}
|
|
667
514
|
this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
|
|
668
|
-
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, {
|
|
669
516
|
...options,
|
|
670
517
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
671
518
|
});
|
|
672
519
|
this.lastProposedBlock = newProposal;
|
|
673
520
|
return newProposal;
|
|
674
521
|
}
|
|
675
|
-
async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier,
|
|
522
|
+
async createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options = {}) {
|
|
676
523
|
// Validate that we're not creating a proposal for an older or equal slot
|
|
677
524
|
if (this.lastProposedCheckpoint) {
|
|
678
525
|
const lastSlot = this.lastProposedCheckpoint.slotNumber;
|
|
@@ -682,23 +529,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
682
529
|
}
|
|
683
530
|
}
|
|
684
531
|
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
685
|
-
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier,
|
|
532
|
+
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options);
|
|
686
533
|
this.lastProposedCheckpoint = newProposal;
|
|
687
534
|
return newProposal;
|
|
688
535
|
}
|
|
689
536
|
async broadcastBlockProposal(proposal) {
|
|
690
537
|
await this.p2pClient.broadcastProposal(proposal);
|
|
691
538
|
}
|
|
692
|
-
async signAttestationsAndSigners(attestationsAndSigners, proposer, slot,
|
|
693
|
-
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);
|
|
694
541
|
}
|
|
695
|
-
async collectOwnAttestations(proposal) {
|
|
542
|
+
async collectOwnAttestations(proposal, checkpointNumber) {
|
|
696
543
|
const slot = proposal.slotNumber;
|
|
697
544
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
698
545
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
|
|
699
546
|
inCommittee
|
|
700
547
|
});
|
|
701
|
-
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
548
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
|
|
702
549
|
if (!attestations) {
|
|
703
550
|
return [];
|
|
704
551
|
}
|
|
@@ -710,7 +557,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
710
557
|
});
|
|
711
558
|
return attestations;
|
|
712
559
|
}
|
|
713
|
-
async collectAttestations(proposal, required, deadline) {
|
|
560
|
+
async collectAttestations(proposal, required, deadline, checkpointNumber) {
|
|
714
561
|
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
715
562
|
const slot = proposal.slotNumber;
|
|
716
563
|
this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
|
|
@@ -718,7 +565,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
718
565
|
this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
|
|
719
566
|
throw new AttestationTimeoutError(0, required, slot);
|
|
720
567
|
}
|
|
721
|
-
await this.collectOwnAttestations(proposal);
|
|
568
|
+
await this.collectOwnAttestations(proposal, checkpointNumber);
|
|
722
569
|
const proposalId = proposal.archive.toString();
|
|
723
570
|
const myAddresses = this.getValidatorAddresses();
|
|
724
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.9badcec54",
|
|
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.9badcec54",
|
|
68
|
+
"@aztec/blob-lib": "0.0.1-commit.9badcec54",
|
|
69
|
+
"@aztec/constants": "0.0.1-commit.9badcec54",
|
|
70
|
+
"@aztec/epoch-cache": "0.0.1-commit.9badcec54",
|
|
71
|
+
"@aztec/ethereum": "0.0.1-commit.9badcec54",
|
|
72
|
+
"@aztec/foundation": "0.0.1-commit.9badcec54",
|
|
73
|
+
"@aztec/node-keystore": "0.0.1-commit.9badcec54",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.9badcec54",
|
|
75
|
+
"@aztec/p2p": "0.0.1-commit.9badcec54",
|
|
76
|
+
"@aztec/protocol-contracts": "0.0.1-commit.9badcec54",
|
|
77
|
+
"@aztec/prover-client": "0.0.1-commit.9badcec54",
|
|
78
|
+
"@aztec/simulator": "0.0.1-commit.9badcec54",
|
|
79
|
+
"@aztec/slasher": "0.0.1-commit.9badcec54",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.9badcec54",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.9badcec54",
|
|
82
|
+
"@aztec/validator-ha-signer": "0.0.1-commit.9badcec54",
|
|
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.9badcec54",
|
|
90
|
+
"@aztec/world-state": "0.0.1-commit.9badcec54",
|
|
91
91
|
"@electric-sql/pglite": "^0.3.14",
|
|
92
92
|
"@jest/globals": "^30.0.0",
|
|
93
93
|
"@types/jest": "^30.0.0",
|