@aztec/validator-client 5.0.0-private.20260319 → 5.0.0-rc.1
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 +142 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/proposal_handler.js +1081 -0
- package/dest/validator.d.ts +27 -19
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +219 -245
- 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 +1160 -0
- package/src/validator.ts +278 -272
- 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
14
|
import type { DuplicateAttestationInfo, DuplicateProposalInfo, 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,24 +57,57 @@ 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 CheckpointProposalValidationFailureReason,
|
|
70
|
+
type CheckpointProposalValidationFailureResult,
|
|
71
|
+
ProposalHandler,
|
|
72
|
+
} from './proposal_handler.js';
|
|
67
73
|
|
|
68
74
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
69
75
|
// Just cap the set to avoid unbounded growth.
|
|
70
76
|
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
77
|
+
const MAX_TRACKED_INVALID_PROPOSAL_SLOTS = 1000;
|
|
78
|
+
const MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS = 1000;
|
|
79
|
+
const MAX_TRACKED_BAD_ATTESTATIONS = 10_000;
|
|
71
80
|
|
|
72
81
|
// What errors from the block proposal handler result in slashing
|
|
73
82
|
const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT: BlockProposalValidationFailureReason[] = [
|
|
74
83
|
'state_mismatch',
|
|
75
84
|
'failed_txs',
|
|
85
|
+
'global_variables_mismatch',
|
|
86
|
+
'invalid_proposal',
|
|
87
|
+
'parent_block_wrong_slot',
|
|
88
|
+
'in_hash_mismatch',
|
|
76
89
|
];
|
|
77
90
|
|
|
91
|
+
const SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT: Record<CheckpointProposalValidationFailureReason, boolean> = {
|
|
92
|
+
// enabled
|
|
93
|
+
['invalid_fee_asset_price_modifier']: true,
|
|
94
|
+
['checkpoint_header_mismatch']: true,
|
|
95
|
+
// These late mismatches should normally be caught by earlier checks, but if reached after validating the local
|
|
96
|
+
// checkpoint inputs, the proposer-signed payload disagrees with deterministic recomputation.
|
|
97
|
+
['archive_mismatch']: true,
|
|
98
|
+
['out_hash_mismatch']: true,
|
|
99
|
+
['no_blocks_for_slot']: true,
|
|
100
|
+
['too_many_blocks_in_checkpoint']: true,
|
|
101
|
+
['checkpoint_validation_failed']: true,
|
|
102
|
+
['last_block_archive_mismatch']: true,
|
|
103
|
+
|
|
104
|
+
// disabled
|
|
105
|
+
['invalid_signature']: false,
|
|
106
|
+
['last_block_not_found']: false,
|
|
107
|
+
['block_fetch_error']: false,
|
|
108
|
+
['checkpoint_already_published']: false,
|
|
109
|
+
};
|
|
110
|
+
|
|
78
111
|
/**
|
|
79
112
|
* Validator Client
|
|
80
113
|
*/
|
|
@@ -97,7 +130,11 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
97
130
|
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */
|
|
98
131
|
private lastAttestedEpochByAttester: Map<string, EpochNumber> = new Map();
|
|
99
132
|
|
|
100
|
-
private proposersOfInvalidBlocks
|
|
133
|
+
private proposersOfInvalidBlocks = FifoSet.withLimit<string>(MAX_PROPOSERS_OF_INVALID_BLOCKS);
|
|
134
|
+
private slotsWithInvalidProposals = FifoSet.withLimit<SlotNumber>(MAX_TRACKED_INVALID_PROPOSAL_SLOTS);
|
|
135
|
+
private invalidCheckpointProposalOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS);
|
|
136
|
+
private badAttestationOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_BAD_ATTESTATIONS);
|
|
137
|
+
private slotsWithProposalEquivocation = FifoSet.withLimit<SlotNumber>(MAX_TRACKED_INVALID_PROPOSAL_SLOTS);
|
|
101
138
|
|
|
102
139
|
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */
|
|
103
140
|
private lastAttestedProposal?: CheckpointProposalCore;
|
|
@@ -106,7 +143,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
106
143
|
private keyStore: ExtendedValidatorKeyStore,
|
|
107
144
|
private epochCache: EpochCache,
|
|
108
145
|
private p2pClient: P2P,
|
|
109
|
-
private
|
|
146
|
+
private proposalHandler: ProposalHandler,
|
|
110
147
|
private blockSource: L2BlockSource,
|
|
111
148
|
private checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
112
149
|
private worldState: WorldStateSynchronizer,
|
|
@@ -126,11 +163,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
126
163
|
this.tracer = telemetry.getTracer('Validator');
|
|
127
164
|
this.metrics = new ValidatorMetrics(telemetry);
|
|
128
165
|
|
|
129
|
-
this.validationService = new ValidationService(
|
|
166
|
+
this.validationService = new ValidationService(
|
|
167
|
+
keyStore,
|
|
168
|
+
this.getSignatureContext(),
|
|
169
|
+
this.log.createChild('validation-service'),
|
|
170
|
+
);
|
|
171
|
+
this.proposalHandler.setCheckpointProposalValidationFailureCallback((proposal, result, proposalInfo) =>
|
|
172
|
+
this.handleInvalidCheckpointProposal(proposal, result, proposalInfo),
|
|
173
|
+
);
|
|
130
174
|
|
|
131
175
|
// Refresh epoch cache every second to trigger alert if participation in committee changes
|
|
132
176
|
this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), this.log, 1000);
|
|
133
|
-
|
|
134
177
|
const myAddresses = this.getValidatorAddresses();
|
|
135
178
|
this.log.verbose(`Initialized validator with addresses: ${myAddresses.map(a => a.toString()).join(', ')}`);
|
|
136
179
|
}
|
|
@@ -199,16 +242,28 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
199
242
|
txProvider: ITxProvider,
|
|
200
243
|
keyStoreManager: KeystoreManager,
|
|
201
244
|
blobClient: BlobClientInterface,
|
|
245
|
+
reexecutionTracker: CheckpointReexecutionTracker,
|
|
202
246
|
dateProvider: DateProvider = new DateProvider(),
|
|
203
247
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
204
248
|
slashingProtectionDb?: SlashingProtectionDatabase,
|
|
205
249
|
) {
|
|
206
250
|
const metrics = new ValidatorMetrics(telemetry);
|
|
207
|
-
const
|
|
251
|
+
const consensusTimetable = new ConsensusTimetable({
|
|
252
|
+
l1Constants: epochCache.getL1Constants(),
|
|
253
|
+
blockDuration: config.blockDurationMs / 1000,
|
|
254
|
+
});
|
|
255
|
+
const blockProposalValidator = new BlockProposalValidator(epochCache, consensusTimetable, {
|
|
208
256
|
txsPermitted: !config.disableTransactions,
|
|
209
257
|
maxTxsPerBlock: config.validateMaxTxsPerBlock,
|
|
258
|
+
maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
|
|
259
|
+
skipSlotValidation: config.skipProposalSlotValidation,
|
|
260
|
+
signatureContext: {
|
|
261
|
+
chainId: config.l1ChainId,
|
|
262
|
+
rollupAddress: config.rollupAddress,
|
|
263
|
+
},
|
|
264
|
+
clockDisparityMs: config.maxGossipClockDisparityMs ?? DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS,
|
|
210
265
|
});
|
|
211
|
-
const
|
|
266
|
+
const proposalHandler = new ProposalHandler(
|
|
212
267
|
checkpointsBuilder,
|
|
213
268
|
worldState,
|
|
214
269
|
blockSource,
|
|
@@ -216,10 +271,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
216
271
|
txProvider,
|
|
217
272
|
blockProposalValidator,
|
|
218
273
|
epochCache,
|
|
274
|
+
consensusTimetable,
|
|
219
275
|
config,
|
|
276
|
+
blobClient,
|
|
277
|
+
reexecutionTracker,
|
|
220
278
|
metrics,
|
|
221
279
|
dateProvider,
|
|
222
280
|
telemetry,
|
|
281
|
+
undefined,
|
|
223
282
|
);
|
|
224
283
|
|
|
225
284
|
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
@@ -255,7 +314,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
255
314
|
validatorKeyStore,
|
|
256
315
|
epochCache,
|
|
257
316
|
p2pClient,
|
|
258
|
-
|
|
317
|
+
proposalHandler,
|
|
259
318
|
blockSource,
|
|
260
319
|
checkpointsBuilder,
|
|
261
320
|
worldState,
|
|
@@ -276,14 +335,21 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
276
335
|
.filter(addr => !this.config.disabledValidators.some(disabled => disabled.equals(addr)));
|
|
277
336
|
}
|
|
278
337
|
|
|
279
|
-
public
|
|
280
|
-
return this.
|
|
338
|
+
public getProposalHandler() {
|
|
339
|
+
return this.proposalHandler;
|
|
281
340
|
}
|
|
282
341
|
|
|
283
342
|
public signWithAddress(addr: EthAddress, msg: TypedDataDefinition, context: SigningContext) {
|
|
284
343
|
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
285
344
|
}
|
|
286
345
|
|
|
346
|
+
private getSignatureContext(): CoordinationSignatureContext {
|
|
347
|
+
return {
|
|
348
|
+
chainId: this.config.l1ChainId,
|
|
349
|
+
rollupAddress: this.config.rollupAddress,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
287
353
|
public getCoinbaseForAttestor(attestor: EthAddress): EthAddress {
|
|
288
354
|
return this.keyStore.getCoinbaseAddress(attestor);
|
|
289
355
|
}
|
|
@@ -296,14 +362,27 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
296
362
|
return this.config;
|
|
297
363
|
}
|
|
298
364
|
|
|
365
|
+
public hasProposalEquivocation(slotNumber: SlotNumber): boolean {
|
|
366
|
+
return this.slotsWithProposalEquivocation.has(slotNumber);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
public hasInvalidProposals(slotNumber: SlotNumber): boolean {
|
|
370
|
+
return this.slotsWithInvalidProposals.has(slotNumber);
|
|
371
|
+
}
|
|
372
|
+
|
|
299
373
|
public updateConfig(config: Partial<ValidatorClientFullConfig>) {
|
|
300
374
|
this.config = { ...this.config, ...config };
|
|
375
|
+
this.proposalHandler.updateConfig(config);
|
|
301
376
|
}
|
|
302
377
|
|
|
303
378
|
public reloadKeystore(newManager: KeystoreManager): void {
|
|
304
379
|
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
305
380
|
this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
|
|
306
|
-
this.validationService = new ValidationService(
|
|
381
|
+
this.validationService = new ValidationService(
|
|
382
|
+
this.keyStore,
|
|
383
|
+
this.getSignatureContext(),
|
|
384
|
+
this.log.createChild('validation-service'),
|
|
385
|
+
);
|
|
307
386
|
}
|
|
308
387
|
|
|
309
388
|
public async start() {
|
|
@@ -350,7 +429,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
350
429
|
checkpoint: CheckpointProposalCore,
|
|
351
430
|
proposalSender: PeerId,
|
|
352
431
|
): Promise<CheckpointAttestation[] | undefined> => this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
353
|
-
this.p2pClient.
|
|
432
|
+
this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
|
|
354
433
|
|
|
355
434
|
// Duplicate proposal handler - triggers slashing for equivocation
|
|
356
435
|
this.p2pClient.registerDuplicateProposalCallback((info: DuplicateProposalInfo) => {
|
|
@@ -362,6 +441,10 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
362
441
|
this.handleDuplicateAttestation(info);
|
|
363
442
|
});
|
|
364
443
|
|
|
444
|
+
this.p2pClient.registerCheckpointAttestationCallback((attestation: CheckpointAttestation) => {
|
|
445
|
+
this.handleCheckpointAttestation(attestation);
|
|
446
|
+
});
|
|
447
|
+
|
|
365
448
|
const myAddresses = this.getValidatorAddresses();
|
|
366
449
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
367
450
|
|
|
@@ -408,22 +491,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
408
491
|
fishermanMode: this.config.fishermanMode || false,
|
|
409
492
|
});
|
|
410
493
|
|
|
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
|
-
);
|
|
494
|
+
// Reexecute outside the escape hatch so slashing observers can detect invalid proposals even when penalties are 0.
|
|
495
|
+
const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !escapeHatchOpen);
|
|
427
496
|
|
|
428
497
|
if (!validationResult.isValid) {
|
|
429
498
|
const reason = validationResult.reason || 'unknown';
|
|
@@ -446,15 +515,18 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
446
515
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
447
516
|
}
|
|
448
517
|
|
|
449
|
-
// Slash invalid block proposals (can happen even when not in committee)
|
|
450
518
|
if (
|
|
451
519
|
!escapeHatchOpen &&
|
|
452
520
|
validationResult.reason &&
|
|
453
|
-
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
|
|
454
|
-
slashBroadcastedInvalidBlockPenalty > 0n
|
|
521
|
+
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
|
|
455
522
|
) {
|
|
456
|
-
this.log.
|
|
523
|
+
this.log.info(`Detected invalid block proposal offense`, {
|
|
524
|
+
...proposalInfo,
|
|
525
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
526
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL),
|
|
527
|
+
});
|
|
457
528
|
this.slashInvalidBlock(proposal);
|
|
529
|
+
this.markInvalidProposalSlot(proposal.slotNumber);
|
|
458
530
|
}
|
|
459
531
|
return false;
|
|
460
532
|
}
|
|
@@ -493,29 +565,20 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
493
565
|
return undefined;
|
|
494
566
|
}
|
|
495
567
|
|
|
496
|
-
//
|
|
497
|
-
if (!
|
|
498
|
-
this.log.warn(`Received checkpoint proposal with invalid signature for proposal slot ${proposalSlotNumber}`);
|
|
568
|
+
// Early-out for equivocation: refuses if we've already attested to a higher slot.
|
|
569
|
+
if (!this.shouldAttestToSlot(proposalSlotNumber)) {
|
|
499
570
|
return undefined;
|
|
500
571
|
}
|
|
501
572
|
|
|
502
573
|
// Ignore proposals from ourselves (may happen in HA setups)
|
|
503
|
-
if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
504
|
-
this.log.debug(`
|
|
574
|
+
if (proposer && this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
575
|
+
this.log.debug(`Not attesting to block proposal from self for slot ${proposalSlotNumber}`, {
|
|
505
576
|
proposer: proposer.toString(),
|
|
506
577
|
proposalSlotNumber,
|
|
507
578
|
});
|
|
508
579
|
return undefined;
|
|
509
580
|
}
|
|
510
581
|
|
|
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
582
|
// Check that I have any address in the committee where this checkpoint will land before attesting
|
|
520
583
|
const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
|
|
521
584
|
const partOfCommittee = inCommittee.length > 0;
|
|
@@ -523,27 +586,26 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
523
586
|
const proposalInfo = {
|
|
524
587
|
proposalSlotNumber,
|
|
525
588
|
archive: proposal.archive.toString(),
|
|
526
|
-
proposer: proposer
|
|
589
|
+
proposer: proposer?.toString(),
|
|
527
590
|
};
|
|
528
591
|
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
529
592
|
...proposalInfo,
|
|
530
593
|
fishermanMode: this.config.fishermanMode || false,
|
|
531
594
|
});
|
|
532
595
|
|
|
533
|
-
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
596
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
|
|
597
|
+
// Uses the cached result from the all-nodes callback if available (avoids double validation).
|
|
598
|
+
let checkpointNumber: CheckpointNumber;
|
|
534
599
|
if (this.config.skipCheckpointProposalValidation) {
|
|
535
600
|
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
601
|
+
checkpointNumber = CheckpointNumber(0);
|
|
536
602
|
} else {
|
|
537
|
-
const validationResult = await this.
|
|
603
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
538
604
|
if (!validationResult.isValid) {
|
|
539
605
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
540
606
|
return undefined;
|
|
541
607
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
// Upload blobs to filestore if we can (fire and forget)
|
|
545
|
-
if (this.blobClient.canUpload()) {
|
|
546
|
-
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
608
|
+
checkpointNumber = validationResult.checkpointNumber;
|
|
547
609
|
}
|
|
548
610
|
|
|
549
611
|
// Check that I have any address in current committee before attesting
|
|
@@ -601,7 +663,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
601
663
|
return undefined;
|
|
602
664
|
}
|
|
603
665
|
|
|
604
|
-
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
666
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
|
|
605
667
|
}
|
|
606
668
|
|
|
607
669
|
/**
|
|
@@ -628,13 +690,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
628
690
|
private async createCheckpointAttestationsFromProposal(
|
|
629
691
|
proposal: CheckpointProposalCore,
|
|
630
692
|
attestors: EthAddress[] = [],
|
|
693
|
+
checkpointNumber: CheckpointNumber,
|
|
631
694
|
): Promise<CheckpointAttestation[] | undefined> {
|
|
632
695
|
// Equivocation check: must happen right before signing to minimize the race window
|
|
633
696
|
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
634
697
|
return undefined;
|
|
635
698
|
}
|
|
636
699
|
|
|
637
|
-
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
700
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
|
|
638
701
|
|
|
639
702
|
// Track the proposal we attested to (to prevent equivocation)
|
|
640
703
|
this.lastAttestedProposal = proposal;
|
|
@@ -643,178 +706,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
643
706
|
return attestations;
|
|
644
707
|
}
|
|
645
708
|
|
|
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
709
|
/**
|
|
813
710
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
814
711
|
*/
|
|
815
712
|
protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
|
|
816
713
|
try {
|
|
817
|
-
const lastBlockHeader = await this.blockSource.
|
|
714
|
+
const lastBlockHeader = (await this.blockSource.getBlockData({ archive: proposal.archive }))?.header;
|
|
818
715
|
if (!lastBlockHeader) {
|
|
819
716
|
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
820
717
|
return;
|
|
@@ -847,12 +744,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
847
744
|
return;
|
|
848
745
|
}
|
|
849
746
|
|
|
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
747
|
this.proposersOfInvalidBlocks.add(proposer.toString());
|
|
857
748
|
|
|
858
749
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
@@ -865,20 +756,115 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
865
756
|
]);
|
|
866
757
|
}
|
|
867
758
|
|
|
759
|
+
private handleInvalidCheckpointProposal(
|
|
760
|
+
proposal: CheckpointProposalCore,
|
|
761
|
+
result: CheckpointProposalValidationFailureResult,
|
|
762
|
+
proposalInfo: LogData,
|
|
763
|
+
): void {
|
|
764
|
+
if (!SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT[result.reason]) {
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
this.markInvalidProposalSlot(proposal.slotNumber);
|
|
769
|
+
|
|
770
|
+
if (this.slashInvalidCheckpointProposal(proposal)) {
|
|
771
|
+
this.log.info(`Detected invalid checkpoint proposal offense`, {
|
|
772
|
+
...proposalInfo,
|
|
773
|
+
reason: result.reason,
|
|
774
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
775
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL),
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
private slashInvalidCheckpointProposal(proposal: CheckpointProposalCore): boolean {
|
|
781
|
+
const proposer = proposal.getSender();
|
|
782
|
+
if (!proposer) {
|
|
783
|
+
this.log.warn(`Cannot slash checkpoint proposal with invalid signature`, {
|
|
784
|
+
slotNumber: proposal.slotNumber,
|
|
785
|
+
archive: proposal.archive.toString(),
|
|
786
|
+
});
|
|
787
|
+
return false;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
const offenseType = OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL;
|
|
791
|
+
const offenseKey = `${proposer.toString()}:${offenseType}:${proposal.slotNumber}`;
|
|
792
|
+
if (!this.invalidCheckpointProposalOffenseKeys.addIfAbsent(offenseKey)) {
|
|
793
|
+
return false;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
797
|
+
{
|
|
798
|
+
validator: proposer,
|
|
799
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
800
|
+
offenseType,
|
|
801
|
+
epochOrSlot: BigInt(proposal.slotNumber),
|
|
802
|
+
},
|
|
803
|
+
]);
|
|
804
|
+
return true;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
private markInvalidProposalSlot(slotNumber: SlotNumber): void {
|
|
808
|
+
this.slotsWithInvalidProposals.add(slotNumber);
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
private handleCheckpointAttestation(attestation: CheckpointAttestation): void {
|
|
812
|
+
const slotNumber = attestation.slotNumber;
|
|
813
|
+
if (!this.slotsWithInvalidProposals.has(slotNumber) || this.slotsWithProposalEquivocation.has(slotNumber)) {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
const attester = attestation.getSender();
|
|
818
|
+
if (!attester) {
|
|
819
|
+
this.log.warn(`Cannot slash checkpoint attestation with invalid signature`, {
|
|
820
|
+
slotNumber,
|
|
821
|
+
archive: attestation.archive.toString(),
|
|
822
|
+
});
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
this.slashAttestedToInvalidCheckpointProposal(slotNumber, attester);
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
private slashAttestedToInvalidCheckpointProposal(slotNumber: SlotNumber, attester: EthAddress): void {
|
|
830
|
+
const offenseKey = `${attester.toString()}:${OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL}:${slotNumber}`;
|
|
831
|
+
if (!this.badAttestationOffenseKeys.addIfAbsent(offenseKey)) {
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
this.log.info(`Detected attestation to invalid checkpoint proposal offense`, {
|
|
836
|
+
attester: attester.toString(),
|
|
837
|
+
slotNumber,
|
|
838
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
839
|
+
offenseType: getOffenseTypeName(OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL),
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
843
|
+
{
|
|
844
|
+
validator: attester,
|
|
845
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
846
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
847
|
+
epochOrSlot: BigInt(slotNumber),
|
|
848
|
+
},
|
|
849
|
+
]);
|
|
850
|
+
}
|
|
851
|
+
|
|
868
852
|
/**
|
|
869
853
|
* Handle detection of a duplicate proposal (equivocation).
|
|
870
854
|
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
871
855
|
*/
|
|
872
856
|
private handleDuplicateProposal(info: DuplicateProposalInfo): void {
|
|
873
857
|
const { slot, proposer, type } = info;
|
|
858
|
+
this.slotsWithProposalEquivocation.add(slot);
|
|
874
859
|
|
|
875
|
-
this.log.
|
|
860
|
+
this.log.info(`Detected duplicate ${type} proposal offense from ${proposer.toString()} at slot ${slot}`, {
|
|
876
861
|
proposer: proposer.toString(),
|
|
877
862
|
slot,
|
|
878
863
|
type,
|
|
864
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
865
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_PROPOSAL),
|
|
879
866
|
});
|
|
880
867
|
|
|
881
|
-
// Emit slash event
|
|
882
868
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
883
869
|
{
|
|
884
870
|
validator: proposer,
|
|
@@ -887,6 +873,13 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
887
873
|
epochOrSlot: BigInt(slot),
|
|
888
874
|
},
|
|
889
875
|
]);
|
|
876
|
+
|
|
877
|
+
this.emit(WANT_TO_CLEAR_SLASH_EVENT, [
|
|
878
|
+
{
|
|
879
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
880
|
+
epochOrSlot: BigInt(slot),
|
|
881
|
+
},
|
|
882
|
+
]);
|
|
890
883
|
}
|
|
891
884
|
|
|
892
885
|
/**
|
|
@@ -896,9 +889,11 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
896
889
|
private handleDuplicateAttestation(info: DuplicateAttestationInfo): void {
|
|
897
890
|
const { slot, attester } = info;
|
|
898
891
|
|
|
899
|
-
this.log.
|
|
892
|
+
this.log.info(`Detected duplicate attestation offense from ${attester.toString()} at slot ${slot}`, {
|
|
900
893
|
attester: attester.toString(),
|
|
901
894
|
slot,
|
|
895
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
896
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_ATTESTATION),
|
|
902
897
|
});
|
|
903
898
|
|
|
904
899
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
@@ -913,6 +908,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
913
908
|
|
|
914
909
|
async createBlockProposal(
|
|
915
910
|
blockHeader: BlockHeader,
|
|
911
|
+
checkpointNumber: CheckpointNumber,
|
|
916
912
|
indexWithinCheckpoint: IndexWithinCheckpoint,
|
|
917
913
|
inHash: Fr,
|
|
918
914
|
archive: Fr,
|
|
@@ -939,6 +935,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
939
935
|
);
|
|
940
936
|
const newProposal = await this.validationService.createBlockProposal(
|
|
941
937
|
blockHeader,
|
|
938
|
+
checkpointNumber,
|
|
942
939
|
indexWithinCheckpoint,
|
|
943
940
|
inHash,
|
|
944
941
|
archive,
|
|
@@ -946,7 +943,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
946
943
|
proposerAddress,
|
|
947
944
|
{
|
|
948
945
|
...options,
|
|
949
|
-
broadcastInvalidBlockProposal:
|
|
946
|
+
broadcastInvalidBlockProposal:
|
|
947
|
+
options.broadcastInvalidBlockProposal || this.config.broadcastInvalidBlockProposal,
|
|
950
948
|
},
|
|
951
949
|
);
|
|
952
950
|
this.lastProposedBlock = newProposal;
|
|
@@ -956,8 +954,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
956
954
|
async createCheckpointProposal(
|
|
957
955
|
checkpointHeader: CheckpointHeader,
|
|
958
956
|
archive: Fr,
|
|
957
|
+
checkpointNumber: CheckpointNumber,
|
|
959
958
|
feeAssetPriceModifier: bigint,
|
|
960
|
-
|
|
959
|
+
lastBlockProposal: BlockProposal | undefined,
|
|
961
960
|
proposerAddress: EthAddress | undefined,
|
|
962
961
|
options: CheckpointProposalOptions = {},
|
|
963
962
|
): Promise<CheckpointProposal> {
|
|
@@ -978,12 +977,20 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
978
977
|
const newProposal = await this.validationService.createCheckpointProposal(
|
|
979
978
|
checkpointHeader,
|
|
980
979
|
archive,
|
|
980
|
+
checkpointNumber,
|
|
981
981
|
feeAssetPriceModifier,
|
|
982
|
-
|
|
982
|
+
lastBlockProposal,
|
|
983
983
|
proposerAddress,
|
|
984
984
|
options,
|
|
985
985
|
);
|
|
986
986
|
this.lastProposedCheckpoint = newProposal;
|
|
987
|
+
// Self-record this slot's outcome on the re-execution tracker. Proposers don't run their
|
|
988
|
+
// own proposals through `handleCheckpointProposal`, so without this call the proposer's
|
|
989
|
+
// sentinel would see no outcome for slots it proposed and would mis-attribute itself as
|
|
990
|
+
// inactive. We pass the locally-computed `archive` (not `newProposal.archive`, which may
|
|
991
|
+
// be intentionally corrupted under test-only flags); from the proposer's local-view
|
|
992
|
+
// perspective the work it just completed is valid by definition.
|
|
993
|
+
this.proposalHandler.recordOwnCheckpointProposalAsValid(checkpointHeader.slotNumber, archive, checkpointNumber);
|
|
987
994
|
return newProposal;
|
|
988
995
|
}
|
|
989
996
|
|
|
@@ -995,16 +1002,24 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
995
1002
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
996
1003
|
proposer: EthAddress,
|
|
997
1004
|
slot: SlotNumber,
|
|
998
|
-
|
|
1005
|
+
checkpointNumber: CheckpointNumber,
|
|
999
1006
|
): Promise<Signature> {
|
|
1000
|
-
return await this.validationService.signAttestationsAndSigners(
|
|
1007
|
+
return await this.validationService.signAttestationsAndSigners(
|
|
1008
|
+
attestationsAndSigners,
|
|
1009
|
+
proposer,
|
|
1010
|
+
slot,
|
|
1011
|
+
checkpointNumber,
|
|
1012
|
+
);
|
|
1001
1013
|
}
|
|
1002
1014
|
|
|
1003
|
-
async collectOwnAttestations(
|
|
1015
|
+
async collectOwnAttestations(
|
|
1016
|
+
proposal: CheckpointProposal,
|
|
1017
|
+
checkpointNumber: CheckpointNumber,
|
|
1018
|
+
): Promise<CheckpointAttestation[]> {
|
|
1004
1019
|
const slot = proposal.slotNumber;
|
|
1005
1020
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
1006
1021
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, { inCommittee });
|
|
1007
|
-
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
1022
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
|
|
1008
1023
|
|
|
1009
1024
|
if (!attestations) {
|
|
1010
1025
|
return [];
|
|
@@ -1023,6 +1038,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
1023
1038
|
proposal: CheckpointProposal,
|
|
1024
1039
|
required: number,
|
|
1025
1040
|
deadline: Date,
|
|
1041
|
+
checkpointNumber: CheckpointNumber,
|
|
1026
1042
|
): Promise<CheckpointAttestation[]> {
|
|
1027
1043
|
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
1028
1044
|
const slot = proposal.slotNumber;
|
|
@@ -1035,33 +1051,23 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
1035
1051
|
throw new AttestationTimeoutError(0, required, slot);
|
|
1036
1052
|
}
|
|
1037
1053
|
|
|
1038
|
-
await this.collectOwnAttestations(proposal);
|
|
1054
|
+
await this.collectOwnAttestations(proposal, checkpointNumber);
|
|
1039
1055
|
|
|
1040
|
-
const
|
|
1056
|
+
const proposalPayloadHash = proposal.getPayloadHash();
|
|
1041
1057
|
const myAddresses = this.getValidatorAddresses();
|
|
1042
1058
|
|
|
1043
1059
|
let attestations: CheckpointAttestation[] = [];
|
|
1044
1060
|
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
|
-
);
|
|
1061
|
+
// The pool already filters by proposal payload hash; if any attestation slips through with a
|
|
1062
|
+
// mismatched payload hash, drop it defensively. Equivocations are emitted as separate slash
|
|
1063
|
+
// events from libp2p_service.
|
|
1064
|
+
const collectedAttestations = await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalPayloadHash);
|
|
1059
1065
|
|
|
1060
1066
|
// Log new attestations we collected
|
|
1061
1067
|
const oldSenders = attestations.map(attestation => attestation.getSender());
|
|
1062
1068
|
for (const collected of collectedAttestations) {
|
|
1063
1069
|
const collectedSender = collected.getSender();
|
|
1064
|
-
// Skip attestations with invalid signatures
|
|
1070
|
+
// Skip attestations with invalid signatures. Should not happen as we don't add invalid attestations to our pool.
|
|
1065
1071
|
if (!collectedSender) {
|
|
1066
1072
|
this.log.warn(`Skipping attestation with invalid signature for slot ${slot}`);
|
|
1067
1073
|
continue;
|