@aztec/validator-client 5.0.0-private.20260319 → 5.0.0-rc.2
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 -11
- package/dest/checkpoint_builder.d.ts +1 -1
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +4 -2
- package/dest/config.d.ts +9 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +23 -10
- 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 +8 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +18 -6
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.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 +165 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/proposal_handler.js +1207 -0
- package/dest/validator.d.ts +33 -19
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +225 -249
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +4 -2
- package/src/config.ts +31 -12
- package/src/duties/validation_service.ts +51 -47
- package/src/factory.ts +25 -4
- package/src/index.ts +1 -1
- package/src/metrics.ts +19 -1
- package/src/proposal_handler.ts +1314 -0
- package/src/validator.ts +292 -279
- package/dest/block_proposal_handler.d.ts +0 -64
- package/dest/block_proposal_handler.d.ts.map +0 -1
- package/dest/block_proposal_handler.js +0 -614
- package/src/block_proposal_handler.ts +0 -632
package/src/validator.ts
CHANGED
|
@@ -1,39 +1,37 @@
|
|
|
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';
|
|
8
|
+
import { FifoSet } from '@aztec/foundation/fifo-set';
|
|
16
9
|
import { type LogData, type Logger, createLogger } from '@aztec/foundation/log';
|
|
17
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
18
10
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
19
11
|
import { sleep } from '@aztec/foundation/sleep';
|
|
20
12
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
21
13
|
import type { KeystoreManager } from '@aztec/node-keystore';
|
|
22
|
-
import type { DuplicateAttestationInfo, DuplicateProposalInfo, P2P, PeerId } from '@aztec/p2p';
|
|
14
|
+
import type { DuplicateAttestationInfo, DuplicateProposalInfo, OversizedProposalInfo, P2P, PeerId } from '@aztec/p2p';
|
|
23
15
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
24
|
-
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';
|
|
25
24
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
26
|
-
import type { CommitteeAttestationsAndSigners,
|
|
27
|
-
import {
|
|
28
|
-
import { getEpochAtSlot
|
|
25
|
+
import type { CommitteeAttestationsAndSigners, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
26
|
+
import type { CheckpointReexecutionTracker } from '@aztec/stdlib/checkpoint';
|
|
27
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
29
28
|
import type {
|
|
30
|
-
CreateCheckpointProposalLastBlockData,
|
|
31
29
|
ITxProvider,
|
|
32
30
|
Validator,
|
|
33
31
|
ValidatorClientFullConfig,
|
|
34
32
|
WorldStateSynchronizer,
|
|
35
33
|
} from '@aztec/stdlib/interfaces/server';
|
|
36
|
-
import {
|
|
34
|
+
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
37
35
|
import {
|
|
38
36
|
type BlockProposal,
|
|
39
37
|
type BlockProposalOptions,
|
|
@@ -41,9 +39,11 @@ import {
|
|
|
41
39
|
CheckpointProposal,
|
|
42
40
|
type CheckpointProposalCore,
|
|
43
41
|
type CheckpointProposalOptions,
|
|
42
|
+
type CoordinationSignatureContext,
|
|
44
43
|
} from '@aztec/stdlib/p2p';
|
|
45
44
|
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
46
|
-
import
|
|
45
|
+
import { ConsensusTimetable } from '@aztec/stdlib/timetable';
|
|
46
|
+
import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
|
|
47
47
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
48
48
|
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
49
49
|
import {
|
|
@@ -57,23 +57,26 @@ import type { ValidatorHASigner } from '@aztec/validator-ha-signer/validator-ha-
|
|
|
57
57
|
import { EventEmitter } from 'events';
|
|
58
58
|
import type { TypedDataDefinition } from 'viem';
|
|
59
59
|
|
|
60
|
-
import { BlockProposalHandler, type BlockProposalValidationFailureReason } from './block_proposal_handler.js';
|
|
61
60
|
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
61
|
+
import { DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS } from './config.js';
|
|
62
62
|
import { ValidationService } from './duties/validation_service.js';
|
|
63
63
|
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
64
64
|
import type { ExtendedValidatorKeyStore } from './key_store/interface.js';
|
|
65
65
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
66
66
|
import { ValidatorMetrics } from './metrics.js';
|
|
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';
|
|
67
74
|
|
|
68
75
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
69
76
|
// Just cap the set to avoid unbounded growth.
|
|
70
77
|
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT: BlockProposalValidationFailureReason[] = [
|
|
74
|
-
'state_mismatch',
|
|
75
|
-
'failed_txs',
|
|
76
|
-
];
|
|
78
|
+
const MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS = 1000;
|
|
79
|
+
const MAX_TRACKED_BAD_ATTESTATIONS = 10_000;
|
|
77
80
|
|
|
78
81
|
/**
|
|
79
82
|
* Validator Client
|
|
@@ -97,7 +100,10 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
97
100
|
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */
|
|
98
101
|
private lastAttestedEpochByAttester: Map<string, EpochNumber> = new Map();
|
|
99
102
|
|
|
100
|
-
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);
|
|
101
107
|
|
|
102
108
|
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */
|
|
103
109
|
private lastAttestedProposal?: CheckpointProposalCore;
|
|
@@ -106,7 +112,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
106
112
|
private keyStore: ExtendedValidatorKeyStore,
|
|
107
113
|
private epochCache: EpochCache,
|
|
108
114
|
private p2pClient: P2P,
|
|
109
|
-
private
|
|
115
|
+
private proposalHandler: ProposalHandler,
|
|
110
116
|
private blockSource: L2BlockSource,
|
|
111
117
|
private checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
112
118
|
private worldState: WorldStateSynchronizer,
|
|
@@ -126,11 +132,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
126
132
|
this.tracer = telemetry.getTracer('Validator');
|
|
127
133
|
this.metrics = new ValidatorMetrics(telemetry);
|
|
128
134
|
|
|
129
|
-
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
|
+
);
|
|
130
143
|
|
|
131
144
|
// Refresh epoch cache every second to trigger alert if participation in committee changes
|
|
132
145
|
this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), this.log, 1000);
|
|
133
|
-
|
|
134
146
|
const myAddresses = this.getValidatorAddresses();
|
|
135
147
|
this.log.verbose(`Initialized validator with addresses: ${myAddresses.map(a => a.toString()).join(', ')}`);
|
|
136
148
|
}
|
|
@@ -199,16 +211,28 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
199
211
|
txProvider: ITxProvider,
|
|
200
212
|
keyStoreManager: KeystoreManager,
|
|
201
213
|
blobClient: BlobClientInterface,
|
|
214
|
+
reexecutionTracker: CheckpointReexecutionTracker,
|
|
202
215
|
dateProvider: DateProvider = new DateProvider(),
|
|
203
216
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
204
217
|
slashingProtectionDb?: SlashingProtectionDatabase,
|
|
205
218
|
) {
|
|
206
219
|
const metrics = new ValidatorMetrics(telemetry);
|
|
207
|
-
const
|
|
220
|
+
const consensusTimetable = new ConsensusTimetable({
|
|
221
|
+
l1Constants: epochCache.getL1Constants(),
|
|
222
|
+
blockDuration: config.blockDurationMs / 1000,
|
|
223
|
+
});
|
|
224
|
+
const blockProposalValidator = new BlockProposalValidator(epochCache, consensusTimetable, {
|
|
208
225
|
txsPermitted: !config.disableTransactions,
|
|
209
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,
|
|
210
234
|
});
|
|
211
|
-
const
|
|
235
|
+
const proposalHandler = new ProposalHandler(
|
|
212
236
|
checkpointsBuilder,
|
|
213
237
|
worldState,
|
|
214
238
|
blockSource,
|
|
@@ -216,10 +240,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
216
240
|
txProvider,
|
|
217
241
|
blockProposalValidator,
|
|
218
242
|
epochCache,
|
|
243
|
+
consensusTimetable,
|
|
219
244
|
config,
|
|
245
|
+
blobClient,
|
|
246
|
+
reexecutionTracker,
|
|
220
247
|
metrics,
|
|
221
248
|
dateProvider,
|
|
222
249
|
telemetry,
|
|
250
|
+
undefined,
|
|
223
251
|
);
|
|
224
252
|
|
|
225
253
|
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
@@ -255,7 +283,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
255
283
|
validatorKeyStore,
|
|
256
284
|
epochCache,
|
|
257
285
|
p2pClient,
|
|
258
|
-
|
|
286
|
+
proposalHandler,
|
|
259
287
|
blockSource,
|
|
260
288
|
checkpointsBuilder,
|
|
261
289
|
worldState,
|
|
@@ -276,14 +304,21 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
276
304
|
.filter(addr => !this.config.disabledValidators.some(disabled => disabled.equals(addr)));
|
|
277
305
|
}
|
|
278
306
|
|
|
279
|
-
public
|
|
280
|
-
return this.
|
|
307
|
+
public getProposalHandler() {
|
|
308
|
+
return this.proposalHandler;
|
|
281
309
|
}
|
|
282
310
|
|
|
283
311
|
public signWithAddress(addr: EthAddress, msg: TypedDataDefinition, context: SigningContext) {
|
|
284
312
|
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
285
313
|
}
|
|
286
314
|
|
|
315
|
+
private getSignatureContext(): CoordinationSignatureContext {
|
|
316
|
+
return {
|
|
317
|
+
chainId: this.config.l1ChainId,
|
|
318
|
+
rollupAddress: this.config.rollupAddress,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
|
|
287
322
|
public getCoinbaseForAttestor(attestor: EthAddress): EthAddress {
|
|
288
323
|
return this.keyStore.getCoinbaseAddress(attestor);
|
|
289
324
|
}
|
|
@@ -296,14 +331,27 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
296
331
|
return this.config;
|
|
297
332
|
}
|
|
298
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
|
+
|
|
299
342
|
public updateConfig(config: Partial<ValidatorClientFullConfig>) {
|
|
300
343
|
this.config = { ...this.config, ...config };
|
|
344
|
+
this.proposalHandler.updateConfig(config);
|
|
301
345
|
}
|
|
302
346
|
|
|
303
347
|
public reloadKeystore(newManager: KeystoreManager): void {
|
|
304
348
|
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
305
349
|
this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
|
|
306
|
-
this.validationService = new ValidationService(
|
|
350
|
+
this.validationService = new ValidationService(
|
|
351
|
+
this.keyStore,
|
|
352
|
+
this.getSignatureContext(),
|
|
353
|
+
this.log.createChild('validation-service'),
|
|
354
|
+
);
|
|
307
355
|
}
|
|
308
356
|
|
|
309
357
|
public async start() {
|
|
@@ -350,18 +398,27 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
350
398
|
checkpoint: CheckpointProposalCore,
|
|
351
399
|
proposalSender: PeerId,
|
|
352
400
|
): Promise<CheckpointAttestation[] | undefined> => this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
353
|
-
this.p2pClient.
|
|
401
|
+
this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
|
|
354
402
|
|
|
355
403
|
// Duplicate proposal handler - triggers slashing for equivocation
|
|
356
404
|
this.p2pClient.registerDuplicateProposalCallback((info: DuplicateProposalInfo) => {
|
|
357
405
|
this.handleDuplicateProposal(info);
|
|
358
406
|
});
|
|
359
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
|
+
|
|
360
413
|
// Duplicate attestation handler - triggers slashing for attestation equivocation
|
|
361
414
|
this.p2pClient.registerDuplicateAttestationCallback((info: DuplicateAttestationInfo) => {
|
|
362
415
|
this.handleDuplicateAttestation(info);
|
|
363
416
|
});
|
|
364
417
|
|
|
418
|
+
this.p2pClient.registerCheckpointAttestationCallback((attestation: CheckpointAttestation) => {
|
|
419
|
+
this.handleCheckpointAttestation(attestation);
|
|
420
|
+
});
|
|
421
|
+
|
|
365
422
|
const myAddresses = this.getValidatorAddresses();
|
|
366
423
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
367
424
|
|
|
@@ -408,22 +465,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
408
465
|
fishermanMode: this.config.fishermanMode || false,
|
|
409
466
|
});
|
|
410
467
|
|
|
411
|
-
// Reexecute
|
|
412
|
-
|
|
413
|
-
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } =
|
|
414
|
-
this.config;
|
|
415
|
-
const shouldReexecute =
|
|
416
|
-
fishermanMode ||
|
|
417
|
-
(slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute) ||
|
|
418
|
-
(partOfCommittee && validatorReexecute) ||
|
|
419
|
-
alwaysReexecuteBlockProposals ||
|
|
420
|
-
this.blobClient.canUpload();
|
|
421
|
-
|
|
422
|
-
const validationResult = await this.blockProposalHandler.handleBlockProposal(
|
|
423
|
-
proposal,
|
|
424
|
-
proposalSender,
|
|
425
|
-
!!shouldReexecute && !escapeHatchOpen,
|
|
426
|
-
);
|
|
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);
|
|
427
470
|
|
|
428
471
|
if (!validationResult.isValid) {
|
|
429
472
|
const reason = validationResult.reason || 'unknown';
|
|
@@ -446,15 +489,18 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
446
489
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
447
490
|
}
|
|
448
491
|
|
|
449
|
-
// Slash invalid block proposals (can happen even when not in committee)
|
|
450
492
|
if (
|
|
451
493
|
!escapeHatchOpen &&
|
|
452
494
|
validationResult.reason &&
|
|
453
|
-
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
|
|
454
|
-
slashBroadcastedInvalidBlockPenalty > 0n
|
|
495
|
+
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
|
|
455
496
|
) {
|
|
456
|
-
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
|
+
});
|
|
457
502
|
this.slashInvalidBlock(proposal);
|
|
503
|
+
this.markInvalidProposalSlot(proposal.slotNumber);
|
|
458
504
|
}
|
|
459
505
|
return false;
|
|
460
506
|
}
|
|
@@ -493,29 +539,20 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
493
539
|
return undefined;
|
|
494
540
|
}
|
|
495
541
|
|
|
496
|
-
//
|
|
497
|
-
if (!
|
|
498
|
-
this.log.warn(`Received checkpoint proposal with invalid signature for proposal slot ${proposalSlotNumber}`);
|
|
542
|
+
// Early-out for equivocation: refuses if we've already attested to a higher slot.
|
|
543
|
+
if (!this.shouldAttestToSlot(proposalSlotNumber)) {
|
|
499
544
|
return undefined;
|
|
500
545
|
}
|
|
501
546
|
|
|
502
547
|
// Ignore proposals from ourselves (may happen in HA setups)
|
|
503
|
-
if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
504
|
-
this.log.debug(`
|
|
548
|
+
if (proposer && this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
549
|
+
this.log.debug(`Not attesting to block proposal from self for slot ${proposalSlotNumber}`, {
|
|
505
550
|
proposer: proposer.toString(),
|
|
506
551
|
proposalSlotNumber,
|
|
507
552
|
});
|
|
508
553
|
return undefined;
|
|
509
554
|
}
|
|
510
555
|
|
|
511
|
-
// Validate fee asset price modifier is within allowed range
|
|
512
|
-
if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
|
|
513
|
-
this.log.warn(
|
|
514
|
-
`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${proposalSlotNumber}`,
|
|
515
|
-
);
|
|
516
|
-
return undefined;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
556
|
// Check that I have any address in the committee where this checkpoint will land before attesting
|
|
520
557
|
const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
|
|
521
558
|
const partOfCommittee = inCommittee.length > 0;
|
|
@@ -523,27 +560,26 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
523
560
|
const proposalInfo = {
|
|
524
561
|
proposalSlotNumber,
|
|
525
562
|
archive: proposal.archive.toString(),
|
|
526
|
-
proposer: proposer
|
|
563
|
+
proposer: proposer?.toString(),
|
|
527
564
|
};
|
|
528
565
|
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
529
566
|
...proposalInfo,
|
|
530
567
|
fishermanMode: this.config.fishermanMode || false,
|
|
531
568
|
});
|
|
532
569
|
|
|
533
|
-
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
570
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
|
|
571
|
+
// Uses the cached result from the all-nodes callback if available (avoids double validation).
|
|
572
|
+
let checkpointNumber: CheckpointNumber;
|
|
534
573
|
if (this.config.skipCheckpointProposalValidation) {
|
|
535
574
|
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
575
|
+
checkpointNumber = CheckpointNumber(0);
|
|
536
576
|
} else {
|
|
537
|
-
const validationResult = await this.
|
|
577
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
538
578
|
if (!validationResult.isValid) {
|
|
539
579
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
540
580
|
return undefined;
|
|
541
581
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
// Upload blobs to filestore if we can (fire and forget)
|
|
545
|
-
if (this.blobClient.canUpload()) {
|
|
546
|
-
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
582
|
+
checkpointNumber = validationResult.checkpointNumber;
|
|
547
583
|
}
|
|
548
584
|
|
|
549
585
|
// Check that I have any address in current committee before attesting
|
|
@@ -601,7 +637,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
601
637
|
return undefined;
|
|
602
638
|
}
|
|
603
639
|
|
|
604
|
-
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
640
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
|
|
605
641
|
}
|
|
606
642
|
|
|
607
643
|
/**
|
|
@@ -628,13 +664,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
628
664
|
private async createCheckpointAttestationsFromProposal(
|
|
629
665
|
proposal: CheckpointProposalCore,
|
|
630
666
|
attestors: EthAddress[] = [],
|
|
667
|
+
checkpointNumber: CheckpointNumber,
|
|
631
668
|
): Promise<CheckpointAttestation[] | undefined> {
|
|
632
669
|
// Equivocation check: must happen right before signing to minimize the race window
|
|
633
670
|
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
634
671
|
return undefined;
|
|
635
672
|
}
|
|
636
673
|
|
|
637
|
-
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
674
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
|
|
638
675
|
|
|
639
676
|
// Track the proposal we attested to (to prevent equivocation)
|
|
640
677
|
this.lastAttestedProposal = proposal;
|
|
@@ -643,178 +680,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
643
680
|
return attestations;
|
|
644
681
|
}
|
|
645
682
|
|
|
646
|
-
/**
|
|
647
|
-
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
648
|
-
* @returns Validation result with isValid flag and reason if invalid.
|
|
649
|
-
*/
|
|
650
|
-
private async validateCheckpointProposal(
|
|
651
|
-
proposal: CheckpointProposalCore,
|
|
652
|
-
proposalInfo: LogData,
|
|
653
|
-
): Promise<{ isValid: true } | { isValid: false; reason: string }> {
|
|
654
|
-
const slot = proposal.slotNumber;
|
|
655
|
-
|
|
656
|
-
// Timeout block syncing at the start of the next slot
|
|
657
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
658
|
-
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
|
|
659
|
-
const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
|
|
660
|
-
|
|
661
|
-
// Wait for last block to sync by archive
|
|
662
|
-
let lastBlockHeader: BlockHeader | undefined;
|
|
663
|
-
try {
|
|
664
|
-
lastBlockHeader = await retryUntil(
|
|
665
|
-
async () => {
|
|
666
|
-
await this.blockSource.syncImmediate();
|
|
667
|
-
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
668
|
-
},
|
|
669
|
-
`waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`,
|
|
670
|
-
timeoutSeconds,
|
|
671
|
-
0.5,
|
|
672
|
-
);
|
|
673
|
-
} catch (err) {
|
|
674
|
-
if (err instanceof TimeoutError) {
|
|
675
|
-
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
676
|
-
return { isValid: false, reason: 'last_block_not_found' };
|
|
677
|
-
}
|
|
678
|
-
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
679
|
-
return { isValid: false, reason: 'block_fetch_error' };
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
if (!lastBlockHeader) {
|
|
683
|
-
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
684
|
-
return { isValid: false, reason: 'last_block_not_found' };
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
// Get all full blocks for the slot and checkpoint
|
|
688
|
-
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
689
|
-
if (blocks.length === 0) {
|
|
690
|
-
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
691
|
-
return { isValid: false, reason: 'no_blocks_for_slot' };
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
695
|
-
if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
|
|
696
|
-
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
697
|
-
return { isValid: false, reason: 'last_block_archive_mismatch' };
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
701
|
-
...proposalInfo,
|
|
702
|
-
blockNumbers: blocks.map(b => b.number),
|
|
703
|
-
});
|
|
704
|
-
|
|
705
|
-
// Get checkpoint constants from first block
|
|
706
|
-
const firstBlock = blocks[0];
|
|
707
|
-
const constants = this.extractCheckpointConstants(firstBlock);
|
|
708
|
-
const checkpointNumber = firstBlock.checkpointNumber;
|
|
709
|
-
|
|
710
|
-
// Get L1-to-L2 messages for this checkpoint
|
|
711
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
712
|
-
|
|
713
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
714
|
-
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
715
|
-
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch))
|
|
716
|
-
.filter(c => c.checkpointNumber < checkpointNumber)
|
|
717
|
-
.map(c => c.checkpointOutHash);
|
|
718
|
-
|
|
719
|
-
// Fork world state at the block before the first block
|
|
720
|
-
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
721
|
-
const fork = await this.worldState.fork(parentBlockNumber);
|
|
722
|
-
|
|
723
|
-
try {
|
|
724
|
-
// Create checkpoint builder with all existing blocks
|
|
725
|
-
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
|
|
726
|
-
checkpointNumber,
|
|
727
|
-
constants,
|
|
728
|
-
proposal.feeAssetPriceModifier,
|
|
729
|
-
l1ToL2Messages,
|
|
730
|
-
previousCheckpointOutHashes,
|
|
731
|
-
fork,
|
|
732
|
-
blocks,
|
|
733
|
-
this.log.getBindings(),
|
|
734
|
-
);
|
|
735
|
-
|
|
736
|
-
// Complete the checkpoint to get computed values
|
|
737
|
-
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
738
|
-
|
|
739
|
-
// Compare checkpoint header with proposal
|
|
740
|
-
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
741
|
-
this.log.warn(`Checkpoint header mismatch`, {
|
|
742
|
-
...proposalInfo,
|
|
743
|
-
computed: computedCheckpoint.header.toInspect(),
|
|
744
|
-
proposal: proposal.checkpointHeader.toInspect(),
|
|
745
|
-
});
|
|
746
|
-
return { isValid: false, reason: 'checkpoint_header_mismatch' };
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
// Compare archive root with proposal
|
|
750
|
-
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
751
|
-
this.log.warn(`Archive root mismatch`, {
|
|
752
|
-
...proposalInfo,
|
|
753
|
-
computed: computedCheckpoint.archive.root.toString(),
|
|
754
|
-
proposal: proposal.archive.toString(),
|
|
755
|
-
});
|
|
756
|
-
return { isValid: false, reason: 'archive_mismatch' };
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
760
|
-
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
761
|
-
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
762
|
-
const computedEpochOutHash = accumulateCheckpointOutHashes([...previousCheckpointOutHashes, checkpointOutHash]);
|
|
763
|
-
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
764
|
-
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
765
|
-
this.log.warn(`Epoch out hash mismatch`, {
|
|
766
|
-
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
767
|
-
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
768
|
-
checkpointOutHash: checkpointOutHash.toString(),
|
|
769
|
-
previousCheckpointOutHashes: previousCheckpointOutHashes.map(h => h.toString()),
|
|
770
|
-
...proposalInfo,
|
|
771
|
-
});
|
|
772
|
-
return { isValid: false, reason: 'out_hash_mismatch' };
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
// Final round of validations on the checkpoint, just in case.
|
|
776
|
-
try {
|
|
777
|
-
validateCheckpoint(computedCheckpoint, {
|
|
778
|
-
rollupManaLimit: this.checkpointsBuilder.getConfig().rollupManaLimit,
|
|
779
|
-
maxDABlockGas: this.config.validateMaxDABlockGas,
|
|
780
|
-
maxL2BlockGas: this.config.validateMaxL2BlockGas,
|
|
781
|
-
maxTxsPerBlock: this.config.validateMaxTxsPerBlock,
|
|
782
|
-
maxTxsPerCheckpoint: this.config.validateMaxTxsPerCheckpoint,
|
|
783
|
-
});
|
|
784
|
-
} catch (err) {
|
|
785
|
-
this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
|
|
786
|
-
return { isValid: false, reason: 'checkpoint_validation_failed' };
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
790
|
-
return { isValid: true };
|
|
791
|
-
} finally {
|
|
792
|
-
await fork.close();
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
/**
|
|
797
|
-
* Extract checkpoint global variables from a block.
|
|
798
|
-
*/
|
|
799
|
-
private extractCheckpointConstants(block: L2Block): CheckpointGlobalVariables {
|
|
800
|
-
const gv = block.header.globalVariables;
|
|
801
|
-
return {
|
|
802
|
-
chainId: gv.chainId,
|
|
803
|
-
version: gv.version,
|
|
804
|
-
slotNumber: gv.slotNumber,
|
|
805
|
-
timestamp: gv.timestamp,
|
|
806
|
-
coinbase: gv.coinbase,
|
|
807
|
-
feeRecipient: gv.feeRecipient,
|
|
808
|
-
gasFees: gv.gasFees,
|
|
809
|
-
};
|
|
810
|
-
}
|
|
811
|
-
|
|
812
683
|
/**
|
|
813
684
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
814
685
|
*/
|
|
815
686
|
protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
|
|
816
687
|
try {
|
|
817
|
-
const lastBlockHeader = await this.blockSource.
|
|
688
|
+
const lastBlockHeader = (await this.blockSource.getBlockData({ archive: proposal.archive }))?.header;
|
|
818
689
|
if (!lastBlockHeader) {
|
|
819
690
|
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
820
691
|
return;
|
|
@@ -847,12 +718,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
847
718
|
return;
|
|
848
719
|
}
|
|
849
720
|
|
|
850
|
-
// Trim the set if it's too big.
|
|
851
|
-
if (this.proposersOfInvalidBlocks.size > MAX_PROPOSERS_OF_INVALID_BLOCKS) {
|
|
852
|
-
// remove oldest proposer. `values` is guaranteed to be in insertion order.
|
|
853
|
-
this.proposersOfInvalidBlocks.delete(this.proposersOfInvalidBlocks.values().next().value!);
|
|
854
|
-
}
|
|
855
|
-
|
|
856
721
|
this.proposersOfInvalidBlocks.add(proposer.toString());
|
|
857
722
|
|
|
858
723
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
@@ -865,20 +730,148 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
865
730
|
]);
|
|
866
731
|
}
|
|
867
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
|
+
|
|
868
859
|
/**
|
|
869
860
|
* Handle detection of a duplicate proposal (equivocation).
|
|
870
861
|
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
871
862
|
*/
|
|
872
863
|
private handleDuplicateProposal(info: DuplicateProposalInfo): void {
|
|
873
864
|
const { slot, proposer, type } = info;
|
|
865
|
+
this.proposalHandler.markProposalEquivocation(slot);
|
|
874
866
|
|
|
875
|
-
this.log.
|
|
867
|
+
this.log.info(`Detected duplicate ${type} proposal offense from ${proposer.toString()} at slot ${slot}`, {
|
|
876
868
|
proposer: proposer.toString(),
|
|
877
869
|
slot,
|
|
878
870
|
type,
|
|
871
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
872
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_PROPOSAL),
|
|
879
873
|
});
|
|
880
874
|
|
|
881
|
-
// Emit slash event
|
|
882
875
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
883
876
|
{
|
|
884
877
|
validator: proposer,
|
|
@@ -887,6 +880,13 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
887
880
|
epochOrSlot: BigInt(slot),
|
|
888
881
|
},
|
|
889
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
|
+
]);
|
|
890
890
|
}
|
|
891
891
|
|
|
892
892
|
/**
|
|
@@ -896,9 +896,11 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
896
896
|
private handleDuplicateAttestation(info: DuplicateAttestationInfo): void {
|
|
897
897
|
const { slot, attester } = info;
|
|
898
898
|
|
|
899
|
-
this.log.
|
|
899
|
+
this.log.info(`Detected duplicate attestation offense from ${attester.toString()} at slot ${slot}`, {
|
|
900
900
|
attester: attester.toString(),
|
|
901
901
|
slot,
|
|
902
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
903
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_ATTESTATION),
|
|
902
904
|
});
|
|
903
905
|
|
|
904
906
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
@@ -913,6 +915,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
913
915
|
|
|
914
916
|
async createBlockProposal(
|
|
915
917
|
blockHeader: BlockHeader,
|
|
918
|
+
checkpointNumber: CheckpointNumber,
|
|
916
919
|
indexWithinCheckpoint: IndexWithinCheckpoint,
|
|
917
920
|
inHash: Fr,
|
|
918
921
|
archive: Fr,
|
|
@@ -939,6 +942,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
939
942
|
);
|
|
940
943
|
const newProposal = await this.validationService.createBlockProposal(
|
|
941
944
|
blockHeader,
|
|
945
|
+
checkpointNumber,
|
|
942
946
|
indexWithinCheckpoint,
|
|
943
947
|
inHash,
|
|
944
948
|
archive,
|
|
@@ -946,7 +950,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
946
950
|
proposerAddress,
|
|
947
951
|
{
|
|
948
952
|
...options,
|
|
949
|
-
broadcastInvalidBlockProposal:
|
|
953
|
+
broadcastInvalidBlockProposal:
|
|
954
|
+
options.broadcastInvalidBlockProposal || this.config.broadcastInvalidBlockProposal,
|
|
950
955
|
},
|
|
951
956
|
);
|
|
952
957
|
this.lastProposedBlock = newProposal;
|
|
@@ -956,8 +961,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
956
961
|
async createCheckpointProposal(
|
|
957
962
|
checkpointHeader: CheckpointHeader,
|
|
958
963
|
archive: Fr,
|
|
964
|
+
checkpointNumber: CheckpointNumber,
|
|
959
965
|
feeAssetPriceModifier: bigint,
|
|
960
|
-
|
|
966
|
+
lastBlockProposal: BlockProposal | undefined,
|
|
961
967
|
proposerAddress: EthAddress | undefined,
|
|
962
968
|
options: CheckpointProposalOptions = {},
|
|
963
969
|
): Promise<CheckpointProposal> {
|
|
@@ -978,12 +984,20 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
978
984
|
const newProposal = await this.validationService.createCheckpointProposal(
|
|
979
985
|
checkpointHeader,
|
|
980
986
|
archive,
|
|
987
|
+
checkpointNumber,
|
|
981
988
|
feeAssetPriceModifier,
|
|
982
|
-
|
|
989
|
+
lastBlockProposal,
|
|
983
990
|
proposerAddress,
|
|
984
991
|
options,
|
|
985
992
|
);
|
|
986
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);
|
|
987
1001
|
return newProposal;
|
|
988
1002
|
}
|
|
989
1003
|
|
|
@@ -995,16 +1009,24 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
995
1009
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
996
1010
|
proposer: EthAddress,
|
|
997
1011
|
slot: SlotNumber,
|
|
998
|
-
|
|
1012
|
+
checkpointNumber: CheckpointNumber,
|
|
999
1013
|
): Promise<Signature> {
|
|
1000
|
-
return await this.validationService.signAttestationsAndSigners(
|
|
1014
|
+
return await this.validationService.signAttestationsAndSigners(
|
|
1015
|
+
attestationsAndSigners,
|
|
1016
|
+
proposer,
|
|
1017
|
+
slot,
|
|
1018
|
+
checkpointNumber,
|
|
1019
|
+
);
|
|
1001
1020
|
}
|
|
1002
1021
|
|
|
1003
|
-
async collectOwnAttestations(
|
|
1022
|
+
async collectOwnAttestations(
|
|
1023
|
+
proposal: CheckpointProposal,
|
|
1024
|
+
checkpointNumber: CheckpointNumber,
|
|
1025
|
+
): Promise<CheckpointAttestation[]> {
|
|
1004
1026
|
const slot = proposal.slotNumber;
|
|
1005
1027
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
1006
1028
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, { inCommittee });
|
|
1007
|
-
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
1029
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
|
|
1008
1030
|
|
|
1009
1031
|
if (!attestations) {
|
|
1010
1032
|
return [];
|
|
@@ -1023,6 +1045,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
1023
1045
|
proposal: CheckpointProposal,
|
|
1024
1046
|
required: number,
|
|
1025
1047
|
deadline: Date,
|
|
1048
|
+
checkpointNumber: CheckpointNumber,
|
|
1026
1049
|
): Promise<CheckpointAttestation[]> {
|
|
1027
1050
|
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
1028
1051
|
const slot = proposal.slotNumber;
|
|
@@ -1035,33 +1058,23 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
1035
1058
|
throw new AttestationTimeoutError(0, required, slot);
|
|
1036
1059
|
}
|
|
1037
1060
|
|
|
1038
|
-
await this.collectOwnAttestations(proposal);
|
|
1061
|
+
await this.collectOwnAttestations(proposal, checkpointNumber);
|
|
1039
1062
|
|
|
1040
|
-
const
|
|
1063
|
+
const proposalPayloadHash = proposal.getPayloadHash();
|
|
1041
1064
|
const myAddresses = this.getValidatorAddresses();
|
|
1042
1065
|
|
|
1043
1066
|
let attestations: CheckpointAttestation[] = [];
|
|
1044
1067
|
while (true) {
|
|
1045
|
-
//
|
|
1046
|
-
//
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
if (!attestation.archive.equals(proposal.archive)) {
|
|
1050
|
-
this.log.warn(
|
|
1051
|
-
`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`,
|
|
1052
|
-
{ attestationArchive: attestation.archive.toString(), proposalArchive: proposal.archive.toString() },
|
|
1053
|
-
);
|
|
1054
|
-
return false;
|
|
1055
|
-
}
|
|
1056
|
-
return true;
|
|
1057
|
-
},
|
|
1058
|
-
);
|
|
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);
|
|
1059
1072
|
|
|
1060
1073
|
// Log new attestations we collected
|
|
1061
1074
|
const oldSenders = attestations.map(attestation => attestation.getSender());
|
|
1062
1075
|
for (const collected of collectedAttestations) {
|
|
1063
1076
|
const collectedSender = collected.getSender();
|
|
1064
|
-
// Skip attestations with invalid signatures
|
|
1077
|
+
// Skip attestations with invalid signatures. Should not happen as we don't add invalid attestations to our pool.
|
|
1065
1078
|
if (!collectedSender) {
|
|
1066
1079
|
this.log.warn(`Skipping attestation with invalid signature for slot ${slot}`);
|
|
1067
1080
|
continue;
|