@aztec/validator-client 0.0.1-commit.4d3c002 → 0.0.1-commit.4d9804df
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 +12 -9
- package/dest/checkpoint_builder.d.ts +6 -4
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +16 -8
- package/dest/config.d.ts +9 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +23 -5
- package/dest/duties/validation_service.d.ts +12 -13
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +32 -38
- package/dest/factory.d.ts +4 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +16 -4
- package/dest/key_store/web3signer_key_store.d.ts +10 -2
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
- package/dest/key_store/web3signer_key_store.js +32 -41
- package/dest/metrics.d.ts +5 -1
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +12 -0
- package/dest/proposal_handler.d.ts +71 -13
- package/dest/proposal_handler.d.ts.map +1 -1
- package/dest/proposal_handler.js +400 -156
- package/dest/validator.d.ts +30 -11
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +215 -62
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +16 -7
- package/src/config.ts +31 -7
- package/src/duties/validation_service.ts +51 -47
- package/src/factory.ts +20 -1
- package/src/key_store/web3signer_key_store.ts +43 -59
- package/src/metrics.ts +18 -0
- package/src/proposal_handler.ts +466 -179
- package/src/validator.ts +281 -80
package/src/validator.ts
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
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
|
-
BlockNumber,
|
|
6
|
-
CheckpointNumber,
|
|
7
|
-
EpochNumber,
|
|
8
|
-
IndexWithinCheckpoint,
|
|
9
|
-
SlotNumber,
|
|
10
|
-
} from '@aztec/foundation/branded-types';
|
|
4
|
+
import { CheckpointNumber, EpochNumber, IndexWithinCheckpoint, SlotNumber } from '@aztec/foundation/branded-types';
|
|
11
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
12
6
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
13
|
-
import
|
|
7
|
+
import { Signature } from '@aztec/foundation/eth-signature';
|
|
8
|
+
import { FifoSet } from '@aztec/foundation/fifo-set';
|
|
14
9
|
import { type LogData, type Logger, createLogger } from '@aztec/foundation/log';
|
|
15
10
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
16
11
|
import { sleep } from '@aztec/foundation/sleep';
|
|
17
12
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
18
13
|
import type { KeystoreManager } from '@aztec/node-keystore';
|
|
19
|
-
import type { DuplicateAttestationInfo, DuplicateProposalInfo, P2P, PeerId } from '@aztec/p2p';
|
|
14
|
+
import type { DuplicateAttestationInfo, DuplicateProposalInfo, OversizedProposalInfo, P2P, PeerId } from '@aztec/p2p';
|
|
20
15
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
21
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
OffenseType,
|
|
18
|
+
WANT_TO_CLEAR_SLASH_EVENT,
|
|
19
|
+
WANT_TO_SLASH_EVENT,
|
|
20
|
+
type Watcher,
|
|
21
|
+
type WatcherEmitter,
|
|
22
|
+
getOffenseTypeName,
|
|
23
|
+
} from '@aztec/slasher';
|
|
22
24
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
23
25
|
import type { CommitteeAttestationsAndSigners, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
26
|
+
import type { CheckpointReexecutionTracker } from '@aztec/stdlib/checkpoint';
|
|
24
27
|
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
25
28
|
import type {
|
|
26
|
-
CreateCheckpointProposalLastBlockData,
|
|
27
29
|
ITxProvider,
|
|
28
30
|
Validator,
|
|
29
31
|
ValidatorClientFullConfig,
|
|
@@ -33,12 +35,14 @@ import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
|
33
35
|
import {
|
|
34
36
|
type BlockProposal,
|
|
35
37
|
type BlockProposalOptions,
|
|
36
|
-
|
|
38
|
+
CheckpointAttestation,
|
|
37
39
|
CheckpointProposal,
|
|
38
40
|
type CheckpointProposalCore,
|
|
39
41
|
type CheckpointProposalOptions,
|
|
42
|
+
type CoordinationSignatureContext,
|
|
40
43
|
} from '@aztec/stdlib/p2p';
|
|
41
44
|
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
45
|
+
import { ConsensusTimetable } from '@aztec/stdlib/timetable';
|
|
42
46
|
import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
|
|
43
47
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
44
48
|
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
@@ -54,22 +58,25 @@ import { EventEmitter } from 'events';
|
|
|
54
58
|
import type { TypedDataDefinition } from 'viem';
|
|
55
59
|
|
|
56
60
|
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
61
|
+
import { DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS } from './config.js';
|
|
57
62
|
import { ValidationService } from './duties/validation_service.js';
|
|
58
63
|
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
59
64
|
import type { ExtendedValidatorKeyStore } from './key_store/interface.js';
|
|
60
65
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
61
66
|
import { ValidatorMetrics } from './metrics.js';
|
|
62
|
-
import {
|
|
67
|
+
import {
|
|
68
|
+
type BlockProposalValidationFailureReason,
|
|
69
|
+
type CheckpointProposalValidationFailureResult,
|
|
70
|
+
ProposalHandler,
|
|
71
|
+
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT,
|
|
72
|
+
SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT,
|
|
73
|
+
} from './proposal_handler.js';
|
|
63
74
|
|
|
64
75
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
65
76
|
// Just cap the set to avoid unbounded growth.
|
|
66
77
|
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT: BlockProposalValidationFailureReason[] = [
|
|
70
|
-
'state_mismatch',
|
|
71
|
-
'failed_txs',
|
|
72
|
-
];
|
|
78
|
+
const MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS = 1000;
|
|
79
|
+
const MAX_TRACKED_BAD_ATTESTATIONS = 10_000;
|
|
73
80
|
|
|
74
81
|
/**
|
|
75
82
|
* Validator Client
|
|
@@ -93,7 +100,10 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
93
100
|
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */
|
|
94
101
|
private lastAttestedEpochByAttester: Map<string, EpochNumber> = new Map();
|
|
95
102
|
|
|
96
|
-
private proposersOfInvalidBlocks
|
|
103
|
+
private proposersOfInvalidBlocks = FifoSet.withLimit<string>(MAX_PROPOSERS_OF_INVALID_BLOCKS);
|
|
104
|
+
private invalidCheckpointProposalOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS);
|
|
105
|
+
private oversizedProposalOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS);
|
|
106
|
+
private badAttestationOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_BAD_ATTESTATIONS);
|
|
97
107
|
|
|
98
108
|
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */
|
|
99
109
|
private lastAttestedProposal?: CheckpointProposalCore;
|
|
@@ -122,11 +132,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
122
132
|
this.tracer = telemetry.getTracer('Validator');
|
|
123
133
|
this.metrics = new ValidatorMetrics(telemetry);
|
|
124
134
|
|
|
125
|
-
this.validationService = new ValidationService(
|
|
135
|
+
this.validationService = new ValidationService(
|
|
136
|
+
keyStore,
|
|
137
|
+
this.getSignatureContext(),
|
|
138
|
+
this.log.createChild('validation-service'),
|
|
139
|
+
);
|
|
140
|
+
this.proposalHandler.setCheckpointProposalValidationFailureCallback((proposal, result, proposalInfo) =>
|
|
141
|
+
this.handleInvalidCheckpointProposal(proposal, result, proposalInfo),
|
|
142
|
+
);
|
|
126
143
|
|
|
127
144
|
// Refresh epoch cache every second to trigger alert if participation in committee changes
|
|
128
145
|
this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), this.log, 1000);
|
|
129
|
-
|
|
130
146
|
const myAddresses = this.getValidatorAddresses();
|
|
131
147
|
this.log.verbose(`Initialized validator with addresses: ${myAddresses.map(a => a.toString()).join(', ')}`);
|
|
132
148
|
}
|
|
@@ -195,14 +211,26 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
195
211
|
txProvider: ITxProvider,
|
|
196
212
|
keyStoreManager: KeystoreManager,
|
|
197
213
|
blobClient: BlobClientInterface,
|
|
214
|
+
reexecutionTracker: CheckpointReexecutionTracker,
|
|
198
215
|
dateProvider: DateProvider = new DateProvider(),
|
|
199
216
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
200
217
|
slashingProtectionDb?: SlashingProtectionDatabase,
|
|
201
218
|
) {
|
|
202
219
|
const metrics = new ValidatorMetrics(telemetry);
|
|
203
|
-
const
|
|
220
|
+
const consensusTimetable = new ConsensusTimetable({
|
|
221
|
+
l1Constants: epochCache.getL1Constants(),
|
|
222
|
+
blockDuration: config.blockDurationMs / 1000,
|
|
223
|
+
});
|
|
224
|
+
const blockProposalValidator = new BlockProposalValidator(epochCache, consensusTimetable, {
|
|
204
225
|
txsPermitted: !config.disableTransactions,
|
|
205
226
|
maxTxsPerBlock: config.validateMaxTxsPerBlock,
|
|
227
|
+
maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
|
|
228
|
+
skipSlotValidation: config.skipProposalSlotValidation,
|
|
229
|
+
signatureContext: {
|
|
230
|
+
chainId: config.l1ChainId,
|
|
231
|
+
rollupAddress: config.rollupAddress,
|
|
232
|
+
},
|
|
233
|
+
clockDisparityMs: config.maxGossipClockDisparityMs ?? DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS,
|
|
206
234
|
});
|
|
207
235
|
const proposalHandler = new ProposalHandler(
|
|
208
236
|
checkpointsBuilder,
|
|
@@ -212,11 +240,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
212
240
|
txProvider,
|
|
213
241
|
blockProposalValidator,
|
|
214
242
|
epochCache,
|
|
243
|
+
consensusTimetable,
|
|
215
244
|
config,
|
|
216
245
|
blobClient,
|
|
246
|
+
reexecutionTracker,
|
|
217
247
|
metrics,
|
|
218
248
|
dateProvider,
|
|
219
249
|
telemetry,
|
|
250
|
+
undefined,
|
|
220
251
|
);
|
|
221
252
|
|
|
222
253
|
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
@@ -281,6 +312,13 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
281
312
|
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
282
313
|
}
|
|
283
314
|
|
|
315
|
+
private getSignatureContext(): CoordinationSignatureContext {
|
|
316
|
+
return {
|
|
317
|
+
chainId: this.config.l1ChainId,
|
|
318
|
+
rollupAddress: this.config.rollupAddress,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
|
|
284
322
|
public getCoinbaseForAttestor(attestor: EthAddress): EthAddress {
|
|
285
323
|
return this.keyStore.getCoinbaseAddress(attestor);
|
|
286
324
|
}
|
|
@@ -293,14 +331,27 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
293
331
|
return this.config;
|
|
294
332
|
}
|
|
295
333
|
|
|
334
|
+
public hasProposalEquivocation(slotNumber: SlotNumber): boolean {
|
|
335
|
+
return this.proposalHandler.hasProposalEquivocation(slotNumber);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
public hasInvalidProposals(slotNumber: SlotNumber): boolean {
|
|
339
|
+
return this.proposalHandler.hasInvalidProposals(slotNumber);
|
|
340
|
+
}
|
|
341
|
+
|
|
296
342
|
public updateConfig(config: Partial<ValidatorClientFullConfig>) {
|
|
297
343
|
this.config = { ...this.config, ...config };
|
|
344
|
+
this.proposalHandler.updateConfig(config);
|
|
298
345
|
}
|
|
299
346
|
|
|
300
347
|
public reloadKeystore(newManager: KeystoreManager): void {
|
|
301
348
|
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
302
349
|
this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
|
|
303
|
-
this.validationService = new ValidationService(
|
|
350
|
+
this.validationService = new ValidationService(
|
|
351
|
+
this.keyStore,
|
|
352
|
+
this.getSignatureContext(),
|
|
353
|
+
this.log.createChild('validation-service'),
|
|
354
|
+
);
|
|
304
355
|
}
|
|
305
356
|
|
|
306
357
|
public async start() {
|
|
@@ -354,11 +405,20 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
354
405
|
this.handleDuplicateProposal(info);
|
|
355
406
|
});
|
|
356
407
|
|
|
408
|
+
// Oversized proposal handler - triggers slashing for proposals beyond the per-checkpoint block limit
|
|
409
|
+
this.p2pClient.registerOversizedProposalCallback((info: OversizedProposalInfo) => {
|
|
410
|
+
this.handleOversizedProposal(info);
|
|
411
|
+
});
|
|
412
|
+
|
|
357
413
|
// Duplicate attestation handler - triggers slashing for attestation equivocation
|
|
358
414
|
this.p2pClient.registerDuplicateAttestationCallback((info: DuplicateAttestationInfo) => {
|
|
359
415
|
this.handleDuplicateAttestation(info);
|
|
360
416
|
});
|
|
361
417
|
|
|
418
|
+
this.p2pClient.registerCheckpointAttestationCallback((attestation: CheckpointAttestation) => {
|
|
419
|
+
this.handleCheckpointAttestation(attestation);
|
|
420
|
+
});
|
|
421
|
+
|
|
362
422
|
const myAddresses = this.getValidatorAddresses();
|
|
363
423
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
364
424
|
|
|
@@ -405,21 +465,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
405
465
|
fishermanMode: this.config.fishermanMode || false,
|
|
406
466
|
});
|
|
407
467
|
|
|
408
|
-
// Reexecute
|
|
409
|
-
|
|
410
|
-
const { slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
411
|
-
const shouldReexecute =
|
|
412
|
-
fishermanMode ||
|
|
413
|
-
slashBroadcastedInvalidBlockPenalty > 0n ||
|
|
414
|
-
partOfCommittee ||
|
|
415
|
-
alwaysReexecuteBlockProposals ||
|
|
416
|
-
this.blobClient.canUpload();
|
|
417
|
-
|
|
418
|
-
const validationResult = await this.proposalHandler.handleBlockProposal(
|
|
419
|
-
proposal,
|
|
420
|
-
proposalSender,
|
|
421
|
-
!!shouldReexecute && !escapeHatchOpen,
|
|
422
|
-
);
|
|
468
|
+
// Reexecute outside the escape hatch so slashing observers can detect invalid proposals even when penalties are 0.
|
|
469
|
+
const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !escapeHatchOpen);
|
|
423
470
|
|
|
424
471
|
if (!validationResult.isValid) {
|
|
425
472
|
const reason = validationResult.reason || 'unknown';
|
|
@@ -442,15 +489,18 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
442
489
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
443
490
|
}
|
|
444
491
|
|
|
445
|
-
// Slash invalid block proposals (can happen even when not in committee)
|
|
446
492
|
if (
|
|
447
493
|
!escapeHatchOpen &&
|
|
448
494
|
validationResult.reason &&
|
|
449
|
-
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
|
|
450
|
-
slashBroadcastedInvalidBlockPenalty > 0n
|
|
495
|
+
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
|
|
451
496
|
) {
|
|
452
|
-
this.log.
|
|
497
|
+
this.log.info(`Detected invalid block proposal offense`, {
|
|
498
|
+
...proposalInfo,
|
|
499
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
500
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL),
|
|
501
|
+
});
|
|
453
502
|
this.slashInvalidBlock(proposal);
|
|
503
|
+
this.markInvalidProposalSlot(proposal.slotNumber);
|
|
454
504
|
}
|
|
455
505
|
return false;
|
|
456
506
|
}
|
|
@@ -489,9 +539,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
489
539
|
return undefined;
|
|
490
540
|
}
|
|
491
541
|
|
|
542
|
+
// Early-out for equivocation: refuses if we've already attested to a higher slot.
|
|
543
|
+
if (!this.shouldAttestToSlot(proposalSlotNumber)) {
|
|
544
|
+
return undefined;
|
|
545
|
+
}
|
|
546
|
+
|
|
492
547
|
// Ignore proposals from ourselves (may happen in HA setups)
|
|
493
548
|
if (proposer && this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
494
|
-
this.log.debug(`
|
|
549
|
+
this.log.debug(`Not attesting to block proposal from self for slot ${proposalSlotNumber}`, {
|
|
495
550
|
proposer: proposer.toString(),
|
|
496
551
|
proposalSlotNumber,
|
|
497
552
|
});
|
|
@@ -514,14 +569,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
514
569
|
|
|
515
570
|
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
|
|
516
571
|
// Uses the cached result from the all-nodes callback if available (avoids double validation).
|
|
572
|
+
let checkpointNumber: CheckpointNumber;
|
|
517
573
|
if (this.config.skipCheckpointProposalValidation) {
|
|
518
574
|
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
575
|
+
checkpointNumber = CheckpointNumber(0);
|
|
519
576
|
} else {
|
|
520
577
|
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
521
578
|
if (!validationResult.isValid) {
|
|
522
579
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
523
580
|
return undefined;
|
|
524
581
|
}
|
|
582
|
+
checkpointNumber = validationResult.checkpointNumber;
|
|
525
583
|
}
|
|
526
584
|
|
|
527
585
|
// Check that I have any address in current committee before attesting
|
|
@@ -579,7 +637,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
579
637
|
return undefined;
|
|
580
638
|
}
|
|
581
639
|
|
|
582
|
-
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
640
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
|
|
583
641
|
}
|
|
584
642
|
|
|
585
643
|
/**
|
|
@@ -606,13 +664,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
606
664
|
private async createCheckpointAttestationsFromProposal(
|
|
607
665
|
proposal: CheckpointProposalCore,
|
|
608
666
|
attestors: EthAddress[] = [],
|
|
667
|
+
checkpointNumber: CheckpointNumber,
|
|
609
668
|
): Promise<CheckpointAttestation[] | undefined> {
|
|
610
669
|
// Equivocation check: must happen right before signing to minimize the race window
|
|
611
670
|
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
612
671
|
return undefined;
|
|
613
672
|
}
|
|
614
673
|
|
|
615
|
-
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
674
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
|
|
616
675
|
|
|
617
676
|
// Track the proposal we attested to (to prevent equivocation)
|
|
618
677
|
this.lastAttestedProposal = proposal;
|
|
@@ -626,7 +685,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
626
685
|
*/
|
|
627
686
|
protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
|
|
628
687
|
try {
|
|
629
|
-
const lastBlockHeader = await this.blockSource.
|
|
688
|
+
const lastBlockHeader = (await this.blockSource.getBlockData({ archive: proposal.archive }))?.header;
|
|
630
689
|
if (!lastBlockHeader) {
|
|
631
690
|
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
632
691
|
return;
|
|
@@ -659,12 +718,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
659
718
|
return;
|
|
660
719
|
}
|
|
661
720
|
|
|
662
|
-
// Trim the set if it's too big.
|
|
663
|
-
if (this.proposersOfInvalidBlocks.size > MAX_PROPOSERS_OF_INVALID_BLOCKS) {
|
|
664
|
-
// remove oldest proposer. `values` is guaranteed to be in insertion order.
|
|
665
|
-
this.proposersOfInvalidBlocks.delete(this.proposersOfInvalidBlocks.values().next().value!);
|
|
666
|
-
}
|
|
667
|
-
|
|
668
721
|
this.proposersOfInvalidBlocks.add(proposer.toString());
|
|
669
722
|
|
|
670
723
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
@@ -677,20 +730,148 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
677
730
|
]);
|
|
678
731
|
}
|
|
679
732
|
|
|
733
|
+
private handleInvalidCheckpointProposal(
|
|
734
|
+
proposal: CheckpointProposalCore,
|
|
735
|
+
result: CheckpointProposalValidationFailureResult,
|
|
736
|
+
proposalInfo: LogData,
|
|
737
|
+
): void {
|
|
738
|
+
if (!SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT[result.reason]) {
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// The slot is already marked invalid by the all-nodes checkpoint handler that invokes this callback,
|
|
743
|
+
// so we only emit the proposer slash event here.
|
|
744
|
+
if (this.slashInvalidCheckpointProposal(proposal)) {
|
|
745
|
+
this.log.info(`Detected invalid checkpoint proposal offense`, {
|
|
746
|
+
...proposalInfo,
|
|
747
|
+
reason: result.reason,
|
|
748
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
749
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL),
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
private slashInvalidCheckpointProposal(proposal: CheckpointProposalCore): boolean {
|
|
755
|
+
const proposer = proposal.getSender();
|
|
756
|
+
if (!proposer) {
|
|
757
|
+
this.log.warn(`Cannot slash checkpoint proposal with invalid signature`, {
|
|
758
|
+
slotNumber: proposal.slotNumber,
|
|
759
|
+
archive: proposal.archive.toString(),
|
|
760
|
+
});
|
|
761
|
+
return false;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
const offenseType = OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL;
|
|
765
|
+
const offenseKey = `${proposer.toString()}:${offenseType}:${proposal.slotNumber}`;
|
|
766
|
+
if (!this.invalidCheckpointProposalOffenseKeys.addIfAbsent(offenseKey)) {
|
|
767
|
+
return false;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
771
|
+
{
|
|
772
|
+
validator: proposer,
|
|
773
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
774
|
+
offenseType,
|
|
775
|
+
epochOrSlot: BigInt(proposal.slotNumber),
|
|
776
|
+
},
|
|
777
|
+
]);
|
|
778
|
+
return true;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
private markInvalidProposalSlot(slotNumber: SlotNumber): void {
|
|
782
|
+
this.proposalHandler.markInvalidProposalSlot(slotNumber);
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
private handleCheckpointAttestation(attestation: CheckpointAttestation): void {
|
|
786
|
+
const slotNumber = attestation.slotNumber;
|
|
787
|
+
if (
|
|
788
|
+
!this.proposalHandler.hasInvalidProposals(slotNumber) ||
|
|
789
|
+
this.proposalHandler.hasProposalEquivocation(slotNumber)
|
|
790
|
+
) {
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
const attester = attestation.getSender();
|
|
795
|
+
if (!attester) {
|
|
796
|
+
this.log.warn(`Cannot slash checkpoint attestation with invalid signature`, {
|
|
797
|
+
slotNumber,
|
|
798
|
+
archive: attestation.archive.toString(),
|
|
799
|
+
});
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
this.slashAttestedToInvalidCheckpointProposal(slotNumber, attester);
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
private slashAttestedToInvalidCheckpointProposal(slotNumber: SlotNumber, attester: EthAddress): void {
|
|
807
|
+
const offenseKey = `${attester.toString()}:${OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL}:${slotNumber}`;
|
|
808
|
+
if (!this.badAttestationOffenseKeys.addIfAbsent(offenseKey)) {
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
this.log.info(`Detected attestation to invalid checkpoint proposal offense`, {
|
|
813
|
+
attester: attester.toString(),
|
|
814
|
+
slotNumber,
|
|
815
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
816
|
+
offenseType: getOffenseTypeName(OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL),
|
|
817
|
+
});
|
|
818
|
+
|
|
819
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
820
|
+
{
|
|
821
|
+
validator: attester,
|
|
822
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
823
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
824
|
+
epochOrSlot: BigInt(slotNumber),
|
|
825
|
+
},
|
|
826
|
+
]);
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Handle detection of an oversized block proposal: one whose index within its checkpoint lands at or
|
|
831
|
+
* beyond the consensus per-checkpoint block limit. A single signed proposal at an illegal index is
|
|
832
|
+
* self-contained evidence, so emit an invalid-block-proposal slash event for the proposer, deduped per
|
|
833
|
+
* (proposer, slot) since the p2p layer reports every oversized proposal it stores.
|
|
834
|
+
*/
|
|
835
|
+
private handleOversizedProposal(info: OversizedProposalInfo): void {
|
|
836
|
+
const { slot, proposer } = info;
|
|
837
|
+
const offenseType = OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL;
|
|
838
|
+
if (!this.oversizedProposalOffenseKeys.addIfAbsent(`${proposer.toString()}:${offenseType}:${slot}`)) {
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
this.log.info(`Detected oversized block proposal offense from ${proposer.toString()} at slot ${slot}`, {
|
|
843
|
+
proposer: proposer.toString(),
|
|
844
|
+
slot,
|
|
845
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
846
|
+
offenseType: getOffenseTypeName(offenseType),
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
850
|
+
{
|
|
851
|
+
validator: proposer,
|
|
852
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
853
|
+
offenseType,
|
|
854
|
+
epochOrSlot: BigInt(slot),
|
|
855
|
+
},
|
|
856
|
+
]);
|
|
857
|
+
}
|
|
858
|
+
|
|
680
859
|
/**
|
|
681
860
|
* Handle detection of a duplicate proposal (equivocation).
|
|
682
861
|
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
683
862
|
*/
|
|
684
863
|
private handleDuplicateProposal(info: DuplicateProposalInfo): void {
|
|
685
864
|
const { slot, proposer, type } = info;
|
|
865
|
+
this.proposalHandler.markProposalEquivocation(slot);
|
|
686
866
|
|
|
687
|
-
this.log.
|
|
867
|
+
this.log.info(`Detected duplicate ${type} proposal offense from ${proposer.toString()} at slot ${slot}`, {
|
|
688
868
|
proposer: proposer.toString(),
|
|
689
869
|
slot,
|
|
690
870
|
type,
|
|
871
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
872
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_PROPOSAL),
|
|
691
873
|
});
|
|
692
874
|
|
|
693
|
-
// Emit slash event
|
|
694
875
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
695
876
|
{
|
|
696
877
|
validator: proposer,
|
|
@@ -699,6 +880,13 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
699
880
|
epochOrSlot: BigInt(slot),
|
|
700
881
|
},
|
|
701
882
|
]);
|
|
883
|
+
|
|
884
|
+
this.emit(WANT_TO_CLEAR_SLASH_EVENT, [
|
|
885
|
+
{
|
|
886
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
887
|
+
epochOrSlot: BigInt(slot),
|
|
888
|
+
},
|
|
889
|
+
]);
|
|
702
890
|
}
|
|
703
891
|
|
|
704
892
|
/**
|
|
@@ -708,9 +896,11 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
708
896
|
private handleDuplicateAttestation(info: DuplicateAttestationInfo): void {
|
|
709
897
|
const { slot, attester } = info;
|
|
710
898
|
|
|
711
|
-
this.log.
|
|
899
|
+
this.log.info(`Detected duplicate attestation offense from ${attester.toString()} at slot ${slot}`, {
|
|
712
900
|
attester: attester.toString(),
|
|
713
901
|
slot,
|
|
902
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
903
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_ATTESTATION),
|
|
714
904
|
});
|
|
715
905
|
|
|
716
906
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
@@ -725,6 +915,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
725
915
|
|
|
726
916
|
async createBlockProposal(
|
|
727
917
|
blockHeader: BlockHeader,
|
|
918
|
+
checkpointNumber: CheckpointNumber,
|
|
728
919
|
indexWithinCheckpoint: IndexWithinCheckpoint,
|
|
729
920
|
inHash: Fr,
|
|
730
921
|
archive: Fr,
|
|
@@ -751,6 +942,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
751
942
|
);
|
|
752
943
|
const newProposal = await this.validationService.createBlockProposal(
|
|
753
944
|
blockHeader,
|
|
945
|
+
checkpointNumber,
|
|
754
946
|
indexWithinCheckpoint,
|
|
755
947
|
inHash,
|
|
756
948
|
archive,
|
|
@@ -758,7 +950,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
758
950
|
proposerAddress,
|
|
759
951
|
{
|
|
760
952
|
...options,
|
|
761
|
-
broadcastInvalidBlockProposal:
|
|
953
|
+
broadcastInvalidBlockProposal:
|
|
954
|
+
options.broadcastInvalidBlockProposal || this.config.broadcastInvalidBlockProposal,
|
|
762
955
|
},
|
|
763
956
|
);
|
|
764
957
|
this.lastProposedBlock = newProposal;
|
|
@@ -768,8 +961,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
768
961
|
async createCheckpointProposal(
|
|
769
962
|
checkpointHeader: CheckpointHeader,
|
|
770
963
|
archive: Fr,
|
|
964
|
+
checkpointNumber: CheckpointNumber,
|
|
771
965
|
feeAssetPriceModifier: bigint,
|
|
772
|
-
|
|
966
|
+
lastBlockProposal: BlockProposal | undefined,
|
|
773
967
|
proposerAddress: EthAddress | undefined,
|
|
774
968
|
options: CheckpointProposalOptions = {},
|
|
775
969
|
): Promise<CheckpointProposal> {
|
|
@@ -790,12 +984,20 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
790
984
|
const newProposal = await this.validationService.createCheckpointProposal(
|
|
791
985
|
checkpointHeader,
|
|
792
986
|
archive,
|
|
987
|
+
checkpointNumber,
|
|
793
988
|
feeAssetPriceModifier,
|
|
794
|
-
|
|
989
|
+
lastBlockProposal,
|
|
795
990
|
proposerAddress,
|
|
796
991
|
options,
|
|
797
992
|
);
|
|
798
993
|
this.lastProposedCheckpoint = newProposal;
|
|
994
|
+
// Self-record this slot's outcome on the re-execution tracker. Proposers don't run their
|
|
995
|
+
// own proposals through `handleCheckpointProposal`, so without this call the proposer's
|
|
996
|
+
// sentinel would see no outcome for slots it proposed and would mis-attribute itself as
|
|
997
|
+
// inactive. We pass the locally-computed `archive` (not `newProposal.archive`, which may
|
|
998
|
+
// be intentionally corrupted under test-only flags); from the proposer's local-view
|
|
999
|
+
// perspective the work it just completed is valid by definition.
|
|
1000
|
+
this.proposalHandler.recordOwnCheckpointProposalAsValid(checkpointHeader.slotNumber, archive, checkpointNumber);
|
|
799
1001
|
return newProposal;
|
|
800
1002
|
}
|
|
801
1003
|
|
|
@@ -807,16 +1009,24 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
807
1009
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
808
1010
|
proposer: EthAddress,
|
|
809
1011
|
slot: SlotNumber,
|
|
810
|
-
|
|
1012
|
+
checkpointNumber: CheckpointNumber,
|
|
811
1013
|
): Promise<Signature> {
|
|
812
|
-
return await this.validationService.signAttestationsAndSigners(
|
|
1014
|
+
return await this.validationService.signAttestationsAndSigners(
|
|
1015
|
+
attestationsAndSigners,
|
|
1016
|
+
proposer,
|
|
1017
|
+
slot,
|
|
1018
|
+
checkpointNumber,
|
|
1019
|
+
);
|
|
813
1020
|
}
|
|
814
1021
|
|
|
815
|
-
async collectOwnAttestations(
|
|
1022
|
+
async collectOwnAttestations(
|
|
1023
|
+
proposal: CheckpointProposal,
|
|
1024
|
+
checkpointNumber: CheckpointNumber,
|
|
1025
|
+
): Promise<CheckpointAttestation[]> {
|
|
816
1026
|
const slot = proposal.slotNumber;
|
|
817
1027
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
818
1028
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, { inCommittee });
|
|
819
|
-
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
1029
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
|
|
820
1030
|
|
|
821
1031
|
if (!attestations) {
|
|
822
1032
|
return [];
|
|
@@ -835,6 +1045,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
835
1045
|
proposal: CheckpointProposal,
|
|
836
1046
|
required: number,
|
|
837
1047
|
deadline: Date,
|
|
1048
|
+
checkpointNumber: CheckpointNumber,
|
|
838
1049
|
): Promise<CheckpointAttestation[]> {
|
|
839
1050
|
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
840
1051
|
const slot = proposal.slotNumber;
|
|
@@ -847,33 +1058,23 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
847
1058
|
throw new AttestationTimeoutError(0, required, slot);
|
|
848
1059
|
}
|
|
849
1060
|
|
|
850
|
-
await this.collectOwnAttestations(proposal);
|
|
1061
|
+
await this.collectOwnAttestations(proposal, checkpointNumber);
|
|
851
1062
|
|
|
852
|
-
const
|
|
1063
|
+
const proposalPayloadHash = proposal.getPayloadHash();
|
|
853
1064
|
const myAddresses = this.getValidatorAddresses();
|
|
854
1065
|
|
|
855
1066
|
let attestations: CheckpointAttestation[] = [];
|
|
856
1067
|
while (true) {
|
|
857
|
-
//
|
|
858
|
-
//
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
if (!attestation.archive.equals(proposal.archive)) {
|
|
862
|
-
this.log.warn(
|
|
863
|
-
`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`,
|
|
864
|
-
{ attestationArchive: attestation.archive.toString(), proposalArchive: proposal.archive.toString() },
|
|
865
|
-
);
|
|
866
|
-
return false;
|
|
867
|
-
}
|
|
868
|
-
return true;
|
|
869
|
-
},
|
|
870
|
-
);
|
|
1068
|
+
// The pool already filters by proposal payload hash; if any attestation slips through with a
|
|
1069
|
+
// mismatched payload hash, drop it defensively. Equivocations are emitted as separate slash
|
|
1070
|
+
// events from libp2p_service.
|
|
1071
|
+
const collectedAttestations = await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalPayloadHash);
|
|
871
1072
|
|
|
872
1073
|
// Log new attestations we collected
|
|
873
1074
|
const oldSenders = attestations.map(attestation => attestation.getSender());
|
|
874
1075
|
for (const collected of collectedAttestations) {
|
|
875
1076
|
const collectedSender = collected.getSender();
|
|
876
|
-
// Skip attestations with invalid signatures
|
|
1077
|
+
// Skip attestations with invalid signatures. Should not happen as we don't add invalid attestations to our pool.
|
|
877
1078
|
if (!collectedSender) {
|
|
878
1079
|
this.log.warn(`Skipping attestation with invalid signature for slot ${slot}`);
|
|
879
1080
|
continue;
|