@aztec/validator-client 0.0.1-commit.27d773e65 → 0.0.1-commit.2b2662070
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 +6 -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 +14 -2
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +24 -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 +18 -21
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +87 -230
- 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 -3
- package/src/index.ts +1 -1
- package/src/key_store/ha_key_store.ts +1 -1
- package/src/metrics.ts +37 -1
- package/src/proposal_handler.ts +1042 -0
- package/src/validator.ts +119 -261
- 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/src/validator.ts
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
2
2
|
import { type Blob, getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
3
3
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
BlockNumber,
|
|
7
|
-
CheckpointNumber,
|
|
8
|
-
EpochNumber,
|
|
9
|
-
IndexWithinCheckpoint,
|
|
10
|
-
SlotNumber,
|
|
11
|
-
} from '@aztec/foundation/branded-types';
|
|
4
|
+
import { CheckpointNumber, EpochNumber, IndexWithinCheckpoint, SlotNumber } from '@aztec/foundation/branded-types';
|
|
12
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
13
|
-
import { TimeoutError } from '@aztec/foundation/error';
|
|
14
6
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
15
7
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
16
8
|
import { type LogData, type Logger, createLogger } from '@aztec/foundation/log';
|
|
17
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
18
9
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
19
10
|
import { sleep } from '@aztec/foundation/sleep';
|
|
20
11
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
@@ -23,16 +14,15 @@ import type { DuplicateAttestationInfo, DuplicateProposalInfo, P2P, PeerId } fro
|
|
|
23
14
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
24
15
|
import { OffenseType, WANT_TO_SLASH_EVENT, type Watcher, type WatcherEmitter } from '@aztec/slasher';
|
|
25
16
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
26
|
-
import type { CommitteeAttestationsAndSigners,
|
|
27
|
-
import { getEpochAtSlot
|
|
17
|
+
import type { CommitteeAttestationsAndSigners, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
18
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
28
19
|
import type {
|
|
29
|
-
CreateCheckpointProposalLastBlockData,
|
|
30
20
|
ITxProvider,
|
|
31
21
|
Validator,
|
|
32
22
|
ValidatorClientFullConfig,
|
|
33
23
|
WorldStateSynchronizer,
|
|
34
24
|
} from '@aztec/stdlib/interfaces/server';
|
|
35
|
-
import {
|
|
25
|
+
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
36
26
|
import {
|
|
37
27
|
type BlockProposal,
|
|
38
28
|
type BlockProposalOptions,
|
|
@@ -42,23 +32,27 @@ import {
|
|
|
42
32
|
type CheckpointProposalOptions,
|
|
43
33
|
} from '@aztec/stdlib/p2p';
|
|
44
34
|
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
45
|
-
import type { BlockHeader,
|
|
35
|
+
import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
|
|
46
36
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
47
37
|
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
48
|
-
import {
|
|
49
|
-
|
|
38
|
+
import {
|
|
39
|
+
createHASigner,
|
|
40
|
+
createLocalSignerWithProtection,
|
|
41
|
+
createSignerFromSharedDb,
|
|
42
|
+
} from '@aztec/validator-ha-signer/factory';
|
|
43
|
+
import { DutyType, type SigningContext, type SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
50
44
|
import type { ValidatorHASigner } from '@aztec/validator-ha-signer/validator-ha-signer';
|
|
51
45
|
|
|
52
46
|
import { EventEmitter } from 'events';
|
|
53
47
|
import type { TypedDataDefinition } from 'viem';
|
|
54
48
|
|
|
55
|
-
import { BlockProposalHandler, type BlockProposalValidationFailureReason } from './block_proposal_handler.js';
|
|
56
49
|
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
57
50
|
import { ValidationService } from './duties/validation_service.js';
|
|
58
51
|
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
59
52
|
import type { ExtendedValidatorKeyStore } from './key_store/interface.js';
|
|
60
53
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
61
54
|
import { ValidatorMetrics } from './metrics.js';
|
|
55
|
+
import { type BlockProposalValidationFailureReason, ProposalHandler } from './proposal_handler.js';
|
|
62
56
|
|
|
63
57
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
64
58
|
// Just cap the set to avoid unbounded growth.
|
|
@@ -89,6 +83,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
89
83
|
|
|
90
84
|
private lastEpochForCommitteeUpdateLoop: EpochNumber | undefined;
|
|
91
85
|
private epochCacheUpdateLoop: RunningPromise;
|
|
86
|
+
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */
|
|
87
|
+
private lastAttestedEpochByAttester: Map<string, EpochNumber> = new Map();
|
|
92
88
|
|
|
93
89
|
private proposersOfInvalidBlocks: Set<string> = new Set();
|
|
94
90
|
|
|
@@ -99,14 +95,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
99
95
|
private keyStore: ExtendedValidatorKeyStore,
|
|
100
96
|
private epochCache: EpochCache,
|
|
101
97
|
private p2pClient: P2P,
|
|
102
|
-
private
|
|
98
|
+
private proposalHandler: ProposalHandler,
|
|
103
99
|
private blockSource: L2BlockSource,
|
|
104
100
|
private checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
105
101
|
private worldState: WorldStateSynchronizer,
|
|
106
102
|
private l1ToL2MessageSource: L1ToL2MessageSource,
|
|
107
103
|
private config: ValidatorClientFullConfig,
|
|
108
104
|
private blobClient: BlobClientInterface,
|
|
109
|
-
private
|
|
105
|
+
private slashingProtectionSigner: ValidatorHASigner,
|
|
110
106
|
private dateProvider: DateProvider = new DateProvider(),
|
|
111
107
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
112
108
|
log = createLogger('validator'),
|
|
@@ -160,6 +156,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
160
156
|
this.log.trace(`No committee found for slot`);
|
|
161
157
|
return;
|
|
162
158
|
}
|
|
159
|
+
this.metrics.setCurrentEpoch(epoch);
|
|
163
160
|
if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
|
|
164
161
|
const me = this.getValidatorAddresses();
|
|
165
162
|
const committeeSet = new Set(committee.map(v => v.toString()));
|
|
@@ -193,12 +190,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
193
190
|
blobClient: BlobClientInterface,
|
|
194
191
|
dateProvider: DateProvider = new DateProvider(),
|
|
195
192
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
193
|
+
slashingProtectionDb?: SlashingProtectionDatabase,
|
|
196
194
|
) {
|
|
197
195
|
const metrics = new ValidatorMetrics(telemetry);
|
|
198
196
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
199
197
|
txsPermitted: !config.disableTransactions,
|
|
198
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock,
|
|
200
199
|
});
|
|
201
|
-
const
|
|
200
|
+
const proposalHandler = new ProposalHandler(
|
|
202
201
|
checkpointsBuilder,
|
|
203
202
|
worldState,
|
|
204
203
|
blockSource,
|
|
@@ -207,37 +206,54 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
207
206
|
blockProposalValidator,
|
|
208
207
|
epochCache,
|
|
209
208
|
config,
|
|
209
|
+
blobClient,
|
|
210
210
|
metrics,
|
|
211
211
|
dateProvider,
|
|
212
212
|
telemetry,
|
|
213
|
+
undefined,
|
|
213
214
|
);
|
|
214
215
|
|
|
215
216
|
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
216
|
-
let
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
let slashingProtectionSigner: ValidatorHASigner;
|
|
218
|
+
if (slashingProtectionDb) {
|
|
219
|
+
// Shared database mode: use a pre-existing database (e.g. for testing HA setups).
|
|
220
|
+
({ signer: slashingProtectionSigner } = createSignerFromSharedDb(slashingProtectionDb, config, {
|
|
221
|
+
telemetryClient: telemetry,
|
|
222
|
+
dateProvider,
|
|
223
|
+
}));
|
|
224
|
+
} else if (config.haSigningEnabled) {
|
|
225
|
+
// Multi-node HA mode: use PostgreSQL-backed distributed locking.
|
|
219
226
|
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
220
227
|
const haConfig = {
|
|
221
228
|
...config,
|
|
222
229
|
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000,
|
|
223
230
|
};
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
231
|
+
({ signer: slashingProtectionSigner } = await createHASigner(haConfig, {
|
|
232
|
+
telemetryClient: telemetry,
|
|
233
|
+
dateProvider,
|
|
234
|
+
}));
|
|
235
|
+
} else {
|
|
236
|
+
// Single-node mode: use LMDB-backed local signing protection.
|
|
237
|
+
// This prevents double-signing if the node crashes and restarts mid-proposal.
|
|
238
|
+
({ signer: slashingProtectionSigner } = await createLocalSignerWithProtection(config, {
|
|
239
|
+
telemetryClient: telemetry,
|
|
240
|
+
dateProvider,
|
|
241
|
+
}));
|
|
227
242
|
}
|
|
243
|
+
const validatorKeyStore: ExtendedValidatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, slashingProtectionSigner);
|
|
228
244
|
|
|
229
245
|
const validator = new ValidatorClient(
|
|
230
246
|
validatorKeyStore,
|
|
231
247
|
epochCache,
|
|
232
248
|
p2pClient,
|
|
233
|
-
|
|
249
|
+
proposalHandler,
|
|
234
250
|
blockSource,
|
|
235
251
|
checkpointsBuilder,
|
|
236
252
|
worldState,
|
|
237
253
|
l1ToL2MessageSource,
|
|
238
254
|
config,
|
|
239
255
|
blobClient,
|
|
240
|
-
|
|
256
|
+
slashingProtectionSigner,
|
|
241
257
|
dateProvider,
|
|
242
258
|
telemetry,
|
|
243
259
|
);
|
|
@@ -251,8 +267,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
251
267
|
.filter(addr => !this.config.disabledValidators.some(disabled => disabled.equals(addr)));
|
|
252
268
|
}
|
|
253
269
|
|
|
254
|
-
public
|
|
255
|
-
return this.
|
|
270
|
+
public getProposalHandler() {
|
|
271
|
+
return this.proposalHandler;
|
|
256
272
|
}
|
|
257
273
|
|
|
258
274
|
public signWithAddress(addr: EthAddress, msg: TypedDataDefinition, context: SigningContext) {
|
|
@@ -276,24 +292,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
276
292
|
}
|
|
277
293
|
|
|
278
294
|
public reloadKeystore(newManager: KeystoreManager): void {
|
|
279
|
-
if (this.config.haSigningEnabled && !this.haSigner) {
|
|
280
|
-
this.log.warn(
|
|
281
|
-
'HA signing is enabled in config but was not initialized at startup. ' +
|
|
282
|
-
'Restart the node to enable HA signing.',
|
|
283
|
-
);
|
|
284
|
-
} else if (!this.config.haSigningEnabled && this.haSigner) {
|
|
285
|
-
this.log.warn(
|
|
286
|
-
'HA signing was disabled via config update but the HA signer is still active. ' +
|
|
287
|
-
'Restart the node to fully disable HA signing.',
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
295
|
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
292
|
-
|
|
293
|
-
this.keyStore = new HAKeyStore(newAdapter, this.haSigner);
|
|
294
|
-
} else {
|
|
295
|
-
this.keyStore = newAdapter;
|
|
296
|
-
}
|
|
296
|
+
this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
|
|
297
297
|
this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
|
|
298
298
|
}
|
|
299
299
|
|
|
@@ -341,7 +341,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
341
341
|
checkpoint: CheckpointProposalCore,
|
|
342
342
|
proposalSender: PeerId,
|
|
343
343
|
): Promise<CheckpointAttestation[] | undefined> => this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
344
|
-
this.p2pClient.
|
|
344
|
+
this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
|
|
345
345
|
|
|
346
346
|
// Duplicate proposal handler - triggers slashing for equivocation
|
|
347
347
|
this.p2pClient.registerDuplicateProposalCallback((info: DuplicateProposalInfo) => {
|
|
@@ -380,13 +380,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
380
380
|
return false;
|
|
381
381
|
}
|
|
382
382
|
|
|
383
|
-
//
|
|
383
|
+
// Log self-proposals from HA peers (same validator key on different nodes)
|
|
384
384
|
if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
385
|
-
this.log.
|
|
385
|
+
this.log.verbose(`Processing block proposal from HA peer for slot ${slotNumber}`, {
|
|
386
386
|
proposer: proposer.toString(),
|
|
387
387
|
slotNumber,
|
|
388
388
|
});
|
|
389
|
-
return false;
|
|
390
389
|
}
|
|
391
390
|
|
|
392
391
|
// Check if we're in the committee (for metrics purposes)
|
|
@@ -402,25 +401,25 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
402
401
|
|
|
403
402
|
// Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
|
|
404
403
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
405
|
-
const {
|
|
406
|
-
this.config;
|
|
404
|
+
const { slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
407
405
|
const shouldReexecute =
|
|
408
406
|
fishermanMode ||
|
|
409
|
-
|
|
410
|
-
|
|
407
|
+
slashBroadcastedInvalidBlockPenalty > 0n ||
|
|
408
|
+
partOfCommittee ||
|
|
411
409
|
alwaysReexecuteBlockProposals ||
|
|
412
410
|
this.blobClient.canUpload();
|
|
413
411
|
|
|
414
|
-
const validationResult = await this.
|
|
412
|
+
const validationResult = await this.proposalHandler.handleBlockProposal(
|
|
415
413
|
proposal,
|
|
416
414
|
proposalSender,
|
|
417
415
|
!!shouldReexecute && !escapeHatchOpen,
|
|
418
416
|
);
|
|
419
417
|
|
|
420
418
|
if (!validationResult.isValid) {
|
|
421
|
-
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
422
|
-
|
|
423
419
|
const reason = validationResult.reason || 'unknown';
|
|
420
|
+
|
|
421
|
+
this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
|
|
422
|
+
|
|
424
423
|
// Classify failure reason: bad proposal vs node issue
|
|
425
424
|
const badProposalReasons: BlockProposalValidationFailureReason[] = [
|
|
426
425
|
'invalid_proposal',
|
|
@@ -475,68 +474,51 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
475
474
|
proposal: CheckpointProposalCore,
|
|
476
475
|
_proposalSender: PeerId,
|
|
477
476
|
): Promise<CheckpointAttestation[] | undefined> {
|
|
478
|
-
const
|
|
477
|
+
const proposalSlotNumber = proposal.slotNumber;
|
|
479
478
|
const proposer = proposal.getSender();
|
|
480
479
|
|
|
481
480
|
// If escape hatch is open for this slot's epoch, do not attest.
|
|
482
|
-
if (await this.epochCache.isEscapeHatchOpenAtSlot(
|
|
483
|
-
this.log.warn(`Escape hatch open for slot ${
|
|
484
|
-
return undefined;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
// Reject proposals with invalid signatures
|
|
488
|
-
if (!proposer) {
|
|
489
|
-
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
481
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(proposalSlotNumber)) {
|
|
482
|
+
this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
|
|
490
483
|
return undefined;
|
|
491
484
|
}
|
|
492
485
|
|
|
493
486
|
// Ignore proposals from ourselves (may happen in HA setups)
|
|
494
|
-
if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
495
|
-
this.log.
|
|
487
|
+
if (proposer && this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
488
|
+
this.log.debug(`Ignoring block proposal from self for slot ${proposalSlotNumber}`, {
|
|
496
489
|
proposer: proposer.toString(),
|
|
497
|
-
|
|
490
|
+
proposalSlotNumber,
|
|
498
491
|
});
|
|
499
492
|
return undefined;
|
|
500
493
|
}
|
|
501
494
|
|
|
502
|
-
//
|
|
503
|
-
|
|
504
|
-
this.log.warn(
|
|
505
|
-
`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`,
|
|
506
|
-
);
|
|
507
|
-
return undefined;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
// Check that I have any address in current committee before attesting
|
|
511
|
-
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
495
|
+
// Check that I have any address in the committee where this checkpoint will land before attesting
|
|
496
|
+
const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
|
|
512
497
|
const partOfCommittee = inCommittee.length > 0;
|
|
513
498
|
|
|
514
499
|
const proposalInfo = {
|
|
515
|
-
|
|
500
|
+
proposalSlotNumber,
|
|
516
501
|
archive: proposal.archive.toString(),
|
|
517
|
-
proposer: proposer
|
|
518
|
-
txCount: proposal.txHashes.length,
|
|
502
|
+
proposer: proposer?.toString(),
|
|
519
503
|
};
|
|
520
|
-
this.log.info(`Received checkpoint proposal for slot ${
|
|
504
|
+
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
521
505
|
...proposalInfo,
|
|
522
|
-
txHashes: proposal.txHashes.map(t => t.toString()),
|
|
523
506
|
fishermanMode: this.config.fishermanMode || false,
|
|
524
507
|
});
|
|
525
508
|
|
|
526
|
-
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
509
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
|
|
510
|
+
// Uses the cached result from the all-nodes callback if available (avoids double validation).
|
|
511
|
+
let checkpointNumber: CheckpointNumber;
|
|
527
512
|
if (this.config.skipCheckpointProposalValidation) {
|
|
528
|
-
this.log.warn(`Skipping checkpoint proposal validation for slot ${
|
|
513
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
514
|
+
checkpointNumber = CheckpointNumber(0);
|
|
529
515
|
} else {
|
|
530
|
-
const validationResult = await this.
|
|
516
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
531
517
|
if (!validationResult.isValid) {
|
|
532
518
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
533
519
|
return undefined;
|
|
534
520
|
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
// Upload blobs to filestore if we can (fire and forget)
|
|
538
|
-
if (this.blobClient.canUpload()) {
|
|
539
|
-
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
521
|
+
checkpointNumber = validationResult.checkpointNumber;
|
|
540
522
|
}
|
|
541
523
|
|
|
542
524
|
// Check that I have any address in current committee before attesting
|
|
@@ -547,14 +529,28 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
547
529
|
}
|
|
548
530
|
|
|
549
531
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
550
|
-
this.log.info(
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
532
|
+
this.log.info(
|
|
533
|
+
`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${proposalSlotNumber}`,
|
|
534
|
+
{
|
|
535
|
+
...proposalInfo,
|
|
536
|
+
inCommittee: partOfCommittee,
|
|
537
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
538
|
+
},
|
|
539
|
+
);
|
|
555
540
|
|
|
556
541
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
557
542
|
|
|
543
|
+
// Track epoch participation per attester: count each (attester, epoch) pair at most once
|
|
544
|
+
const proposalEpoch = getEpochAtSlot(proposalSlotNumber, this.epochCache.getL1Constants());
|
|
545
|
+
for (const attester of inCommittee) {
|
|
546
|
+
const key = attester.toString();
|
|
547
|
+
const lastEpoch = this.lastAttestedEpochByAttester.get(key);
|
|
548
|
+
if (lastEpoch === undefined || proposalEpoch > lastEpoch) {
|
|
549
|
+
this.lastAttestedEpochByAttester.set(key, proposalEpoch);
|
|
550
|
+
this.metrics.incAttestedEpochCount(attester);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
558
554
|
// Determine which validators should attest
|
|
559
555
|
let attestors: EthAddress[];
|
|
560
556
|
if (partOfCommittee) {
|
|
@@ -573,14 +569,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
573
569
|
|
|
574
570
|
if (this.config.fishermanMode) {
|
|
575
571
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
576
|
-
this.log.info(`Creating checkpoint attestations for slot ${
|
|
572
|
+
this.log.info(`Creating checkpoint attestations for slot ${proposalSlotNumber}`, {
|
|
577
573
|
...proposalInfo,
|
|
578
574
|
attestors: attestors.map(a => a.toString()),
|
|
579
575
|
});
|
|
580
576
|
return undefined;
|
|
581
577
|
}
|
|
582
578
|
|
|
583
|
-
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
579
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
|
|
584
580
|
}
|
|
585
581
|
|
|
586
582
|
/**
|
|
@@ -607,13 +603,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
607
603
|
private async createCheckpointAttestationsFromProposal(
|
|
608
604
|
proposal: CheckpointProposalCore,
|
|
609
605
|
attestors: EthAddress[] = [],
|
|
606
|
+
checkpointNumber: CheckpointNumber,
|
|
610
607
|
): Promise<CheckpointAttestation[] | undefined> {
|
|
611
608
|
// Equivocation check: must happen right before signing to minimize the race window
|
|
612
609
|
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
613
610
|
return undefined;
|
|
614
611
|
}
|
|
615
612
|
|
|
616
|
-
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
613
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
|
|
617
614
|
|
|
618
615
|
// Track the proposal we attested to (to prevent equivocation)
|
|
619
616
|
this.lastAttestedProposal = proposal;
|
|
@@ -622,158 +619,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
622
619
|
return attestations;
|
|
623
620
|
}
|
|
624
621
|
|
|
625
|
-
/**
|
|
626
|
-
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
627
|
-
* @returns Validation result with isValid flag and reason if invalid.
|
|
628
|
-
*/
|
|
629
|
-
private async validateCheckpointProposal(
|
|
630
|
-
proposal: CheckpointProposalCore,
|
|
631
|
-
proposalInfo: LogData,
|
|
632
|
-
): Promise<{ isValid: true } | { isValid: false; reason: string }> {
|
|
633
|
-
const slot = proposal.slotNumber;
|
|
634
|
-
|
|
635
|
-
// Timeout block syncing at the start of the next slot
|
|
636
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
637
|
-
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
|
|
638
|
-
const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
|
|
639
|
-
|
|
640
|
-
// Wait for last block to sync by archive
|
|
641
|
-
let lastBlockHeader: BlockHeader | undefined;
|
|
642
|
-
try {
|
|
643
|
-
lastBlockHeader = await retryUntil(
|
|
644
|
-
async () => {
|
|
645
|
-
await this.blockSource.syncImmediate();
|
|
646
|
-
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
647
|
-
},
|
|
648
|
-
`waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`,
|
|
649
|
-
timeoutSeconds,
|
|
650
|
-
0.5,
|
|
651
|
-
);
|
|
652
|
-
} catch (err) {
|
|
653
|
-
if (err instanceof TimeoutError) {
|
|
654
|
-
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
655
|
-
return { isValid: false, reason: 'last_block_not_found' };
|
|
656
|
-
}
|
|
657
|
-
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
658
|
-
return { isValid: false, reason: 'block_fetch_error' };
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
if (!lastBlockHeader) {
|
|
662
|
-
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
663
|
-
return { isValid: false, reason: 'last_block_not_found' };
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
// Get all full blocks for the slot and checkpoint
|
|
667
|
-
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
668
|
-
if (blocks.length === 0) {
|
|
669
|
-
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
670
|
-
return { isValid: false, reason: 'no_blocks_for_slot' };
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
674
|
-
if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
|
|
675
|
-
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
676
|
-
return { isValid: false, reason: 'last_block_archive_mismatch' };
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
680
|
-
...proposalInfo,
|
|
681
|
-
blockNumbers: blocks.map(b => b.number),
|
|
682
|
-
});
|
|
683
|
-
|
|
684
|
-
// Get checkpoint constants from first block
|
|
685
|
-
const firstBlock = blocks[0];
|
|
686
|
-
const constants = this.extractCheckpointConstants(firstBlock);
|
|
687
|
-
const checkpointNumber = firstBlock.checkpointNumber;
|
|
688
|
-
|
|
689
|
-
// Get L1-to-L2 messages for this checkpoint
|
|
690
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
691
|
-
|
|
692
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
693
|
-
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
694
|
-
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch))
|
|
695
|
-
.filter(c => c.checkpointNumber < checkpointNumber)
|
|
696
|
-
.map(c => c.checkpointOutHash);
|
|
697
|
-
|
|
698
|
-
// Fork world state at the block before the first block
|
|
699
|
-
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
700
|
-
const fork = await this.worldState.fork(parentBlockNumber);
|
|
701
|
-
|
|
702
|
-
try {
|
|
703
|
-
// Create checkpoint builder with all existing blocks
|
|
704
|
-
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
|
|
705
|
-
checkpointNumber,
|
|
706
|
-
constants,
|
|
707
|
-
proposal.feeAssetPriceModifier,
|
|
708
|
-
l1ToL2Messages,
|
|
709
|
-
previousCheckpointOutHashes,
|
|
710
|
-
fork,
|
|
711
|
-
blocks,
|
|
712
|
-
this.log.getBindings(),
|
|
713
|
-
);
|
|
714
|
-
|
|
715
|
-
// Complete the checkpoint to get computed values
|
|
716
|
-
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
717
|
-
|
|
718
|
-
// Compare checkpoint header with proposal
|
|
719
|
-
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
720
|
-
this.log.warn(`Checkpoint header mismatch`, {
|
|
721
|
-
...proposalInfo,
|
|
722
|
-
computed: computedCheckpoint.header.toInspect(),
|
|
723
|
-
proposal: proposal.checkpointHeader.toInspect(),
|
|
724
|
-
});
|
|
725
|
-
return { isValid: false, reason: 'checkpoint_header_mismatch' };
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
// Compare archive root with proposal
|
|
729
|
-
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
730
|
-
this.log.warn(`Archive root mismatch`, {
|
|
731
|
-
...proposalInfo,
|
|
732
|
-
computed: computedCheckpoint.archive.root.toString(),
|
|
733
|
-
proposal: proposal.archive.toString(),
|
|
734
|
-
});
|
|
735
|
-
return { isValid: false, reason: 'archive_mismatch' };
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
739
|
-
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
740
|
-
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
741
|
-
const computedEpochOutHash = accumulateCheckpointOutHashes([...previousCheckpointOutHashes, checkpointOutHash]);
|
|
742
|
-
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
743
|
-
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
744
|
-
this.log.warn(`Epoch out hash mismatch`, {
|
|
745
|
-
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
746
|
-
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
747
|
-
checkpointOutHash: checkpointOutHash.toString(),
|
|
748
|
-
previousCheckpointOutHashes: previousCheckpointOutHashes.map(h => h.toString()),
|
|
749
|
-
...proposalInfo,
|
|
750
|
-
});
|
|
751
|
-
return { isValid: false, reason: 'out_hash_mismatch' };
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
755
|
-
return { isValid: true };
|
|
756
|
-
} finally {
|
|
757
|
-
await fork.close();
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
/**
|
|
762
|
-
* Extract checkpoint global variables from a block.
|
|
763
|
-
*/
|
|
764
|
-
private extractCheckpointConstants(block: L2Block): CheckpointGlobalVariables {
|
|
765
|
-
const gv = block.header.globalVariables;
|
|
766
|
-
return {
|
|
767
|
-
chainId: gv.chainId,
|
|
768
|
-
version: gv.version,
|
|
769
|
-
slotNumber: gv.slotNumber,
|
|
770
|
-
timestamp: gv.timestamp,
|
|
771
|
-
coinbase: gv.coinbase,
|
|
772
|
-
feeRecipient: gv.feeRecipient,
|
|
773
|
-
gasFees: gv.gasFees,
|
|
774
|
-
};
|
|
775
|
-
}
|
|
776
|
-
|
|
777
622
|
/**
|
|
778
623
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
779
624
|
*/
|
|
@@ -878,6 +723,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
878
723
|
|
|
879
724
|
async createBlockProposal(
|
|
880
725
|
blockHeader: BlockHeader,
|
|
726
|
+
checkpointNumber: CheckpointNumber,
|
|
881
727
|
indexWithinCheckpoint: IndexWithinCheckpoint,
|
|
882
728
|
inHash: Fr,
|
|
883
729
|
archive: Fr,
|
|
@@ -904,6 +750,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
904
750
|
);
|
|
905
751
|
const newProposal = await this.validationService.createBlockProposal(
|
|
906
752
|
blockHeader,
|
|
753
|
+
checkpointNumber,
|
|
907
754
|
indexWithinCheckpoint,
|
|
908
755
|
inHash,
|
|
909
756
|
archive,
|
|
@@ -921,8 +768,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
921
768
|
async createCheckpointProposal(
|
|
922
769
|
checkpointHeader: CheckpointHeader,
|
|
923
770
|
archive: Fr,
|
|
771
|
+
checkpointNumber: CheckpointNumber,
|
|
924
772
|
feeAssetPriceModifier: bigint,
|
|
925
|
-
|
|
773
|
+
lastBlockProposal: BlockProposal | undefined,
|
|
926
774
|
proposerAddress: EthAddress | undefined,
|
|
927
775
|
options: CheckpointProposalOptions = {},
|
|
928
776
|
): Promise<CheckpointProposal> {
|
|
@@ -943,8 +791,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
943
791
|
const newProposal = await this.validationService.createCheckpointProposal(
|
|
944
792
|
checkpointHeader,
|
|
945
793
|
archive,
|
|
794
|
+
checkpointNumber,
|
|
946
795
|
feeAssetPriceModifier,
|
|
947
|
-
|
|
796
|
+
lastBlockProposal,
|
|
948
797
|
proposerAddress,
|
|
949
798
|
options,
|
|
950
799
|
);
|
|
@@ -960,16 +809,24 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
960
809
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
961
810
|
proposer: EthAddress,
|
|
962
811
|
slot: SlotNumber,
|
|
963
|
-
|
|
812
|
+
checkpointNumber: CheckpointNumber,
|
|
964
813
|
): Promise<Signature> {
|
|
965
|
-
return await this.validationService.signAttestationsAndSigners(
|
|
814
|
+
return await this.validationService.signAttestationsAndSigners(
|
|
815
|
+
attestationsAndSigners,
|
|
816
|
+
proposer,
|
|
817
|
+
slot,
|
|
818
|
+
checkpointNumber,
|
|
819
|
+
);
|
|
966
820
|
}
|
|
967
821
|
|
|
968
|
-
async collectOwnAttestations(
|
|
822
|
+
async collectOwnAttestations(
|
|
823
|
+
proposal: CheckpointProposal,
|
|
824
|
+
checkpointNumber: CheckpointNumber,
|
|
825
|
+
): Promise<CheckpointAttestation[]> {
|
|
969
826
|
const slot = proposal.slotNumber;
|
|
970
827
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
971
828
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, { inCommittee });
|
|
972
|
-
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
829
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
|
|
973
830
|
|
|
974
831
|
if (!attestations) {
|
|
975
832
|
return [];
|
|
@@ -988,6 +845,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
988
845
|
proposal: CheckpointProposal,
|
|
989
846
|
required: number,
|
|
990
847
|
deadline: Date,
|
|
848
|
+
checkpointNumber: CheckpointNumber,
|
|
991
849
|
): Promise<CheckpointAttestation[]> {
|
|
992
850
|
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
993
851
|
const slot = proposal.slotNumber;
|
|
@@ -1000,7 +858,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
1000
858
|
throw new AttestationTimeoutError(0, required, slot);
|
|
1001
859
|
}
|
|
1002
860
|
|
|
1003
|
-
await this.collectOwnAttestations(proposal);
|
|
861
|
+
await this.collectOwnAttestations(proposal, checkpointNumber);
|
|
1004
862
|
|
|
1005
863
|
const proposalId = proposal.archive.toString();
|
|
1006
864
|
const myAddresses = this.getValidatorAddresses();
|