@aztec/validator-client 5.0.0-private.20260318 → 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 +21 -22
- package/dest/checkpoint_builder.d.ts +10 -8
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +31 -28
- 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 +10 -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 +28 -20
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +241 -262
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +40 -33
- package/src/config.ts +31 -12
- package/src/duties/validation_service.ts +51 -47
- package/src/factory.ts +29 -5
- package/src/index.ts +1 -1
- package/src/metrics.ts +19 -1
- package/src/proposal_handler.ts +1160 -0
- package/src/validator.ts +313 -294
- 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 -606
- package/src/block_proposal_handler.ts +0 -624
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,36 +39,75 @@ 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
|
-
import {
|
|
50
|
-
|
|
49
|
+
import {
|
|
50
|
+
createHASigner,
|
|
51
|
+
createLocalSignerWithProtection,
|
|
52
|
+
createSignerFromSharedDb,
|
|
53
|
+
} from '@aztec/validator-ha-signer/factory';
|
|
54
|
+
import { DutyType, type SigningContext, type SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
51
55
|
import type { ValidatorHASigner } from '@aztec/validator-ha-signer/validator-ha-signer';
|
|
52
56
|
|
|
53
57
|
import { EventEmitter } from 'events';
|
|
54
58
|
import type { TypedDataDefinition } from 'viem';
|
|
55
59
|
|
|
56
|
-
import { BlockProposalHandler, type BlockProposalValidationFailureReason } from './block_proposal_handler.js';
|
|
57
60
|
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
61
|
+
import { DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS } from './config.js';
|
|
58
62
|
import { ValidationService } from './duties/validation_service.js';
|
|
59
63
|
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
60
64
|
import type { ExtendedValidatorKeyStore } from './key_store/interface.js';
|
|
61
65
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
62
66
|
import { ValidatorMetrics } from './metrics.js';
|
|
67
|
+
import {
|
|
68
|
+
type BlockProposalValidationFailureReason,
|
|
69
|
+
type CheckpointProposalValidationFailureReason,
|
|
70
|
+
type CheckpointProposalValidationFailureResult,
|
|
71
|
+
ProposalHandler,
|
|
72
|
+
} from './proposal_handler.js';
|
|
63
73
|
|
|
64
74
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
65
75
|
// Just cap the set to avoid unbounded growth.
|
|
66
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;
|
|
67
80
|
|
|
68
81
|
// What errors from the block proposal handler result in slashing
|
|
69
82
|
const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT: BlockProposalValidationFailureReason[] = [
|
|
70
83
|
'state_mismatch',
|
|
71
84
|
'failed_txs',
|
|
85
|
+
'global_variables_mismatch',
|
|
86
|
+
'invalid_proposal',
|
|
87
|
+
'parent_block_wrong_slot',
|
|
88
|
+
'in_hash_mismatch',
|
|
72
89
|
];
|
|
73
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
|
+
|
|
74
111
|
/**
|
|
75
112
|
* Validator Client
|
|
76
113
|
*/
|
|
@@ -93,7 +130,11 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
93
130
|
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */
|
|
94
131
|
private lastAttestedEpochByAttester: Map<string, EpochNumber> = new Map();
|
|
95
132
|
|
|
96
|
-
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);
|
|
97
138
|
|
|
98
139
|
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */
|
|
99
140
|
private lastAttestedProposal?: CheckpointProposalCore;
|
|
@@ -102,7 +143,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
102
143
|
private keyStore: ExtendedValidatorKeyStore,
|
|
103
144
|
private epochCache: EpochCache,
|
|
104
145
|
private p2pClient: P2P,
|
|
105
|
-
private
|
|
146
|
+
private proposalHandler: ProposalHandler,
|
|
106
147
|
private blockSource: L2BlockSource,
|
|
107
148
|
private checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
108
149
|
private worldState: WorldStateSynchronizer,
|
|
@@ -122,11 +163,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
122
163
|
this.tracer = telemetry.getTracer('Validator');
|
|
123
164
|
this.metrics = new ValidatorMetrics(telemetry);
|
|
124
165
|
|
|
125
|
-
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
|
+
);
|
|
126
174
|
|
|
127
175
|
// Refresh epoch cache every second to trigger alert if participation in committee changes
|
|
128
176
|
this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), this.log, 1000);
|
|
129
|
-
|
|
130
177
|
const myAddresses = this.getValidatorAddresses();
|
|
131
178
|
this.log.verbose(`Initialized validator with addresses: ${myAddresses.map(a => a.toString()).join(', ')}`);
|
|
132
179
|
}
|
|
@@ -195,15 +242,28 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
195
242
|
txProvider: ITxProvider,
|
|
196
243
|
keyStoreManager: KeystoreManager,
|
|
197
244
|
blobClient: BlobClientInterface,
|
|
245
|
+
reexecutionTracker: CheckpointReexecutionTracker,
|
|
198
246
|
dateProvider: DateProvider = new DateProvider(),
|
|
199
247
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
248
|
+
slashingProtectionDb?: SlashingProtectionDatabase,
|
|
200
249
|
) {
|
|
201
250
|
const metrics = new ValidatorMetrics(telemetry);
|
|
202
|
-
const
|
|
251
|
+
const consensusTimetable = new ConsensusTimetable({
|
|
252
|
+
l1Constants: epochCache.getL1Constants(),
|
|
253
|
+
blockDuration: config.blockDurationMs / 1000,
|
|
254
|
+
});
|
|
255
|
+
const blockProposalValidator = new BlockProposalValidator(epochCache, consensusTimetable, {
|
|
203
256
|
txsPermitted: !config.disableTransactions,
|
|
204
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,
|
|
205
265
|
});
|
|
206
|
-
const
|
|
266
|
+
const proposalHandler = new ProposalHandler(
|
|
207
267
|
checkpointsBuilder,
|
|
208
268
|
worldState,
|
|
209
269
|
blockSource,
|
|
@@ -211,15 +271,25 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
211
271
|
txProvider,
|
|
212
272
|
blockProposalValidator,
|
|
213
273
|
epochCache,
|
|
274
|
+
consensusTimetable,
|
|
214
275
|
config,
|
|
276
|
+
blobClient,
|
|
277
|
+
reexecutionTracker,
|
|
215
278
|
metrics,
|
|
216
279
|
dateProvider,
|
|
217
280
|
telemetry,
|
|
281
|
+
undefined,
|
|
218
282
|
);
|
|
219
283
|
|
|
220
284
|
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
221
285
|
let slashingProtectionSigner: ValidatorHASigner;
|
|
222
|
-
if (
|
|
286
|
+
if (slashingProtectionDb) {
|
|
287
|
+
// Shared database mode: use a pre-existing database (e.g. for testing HA setups).
|
|
288
|
+
({ signer: slashingProtectionSigner } = createSignerFromSharedDb(slashingProtectionDb, config, {
|
|
289
|
+
telemetryClient: telemetry,
|
|
290
|
+
dateProvider,
|
|
291
|
+
}));
|
|
292
|
+
} else if (config.haSigningEnabled) {
|
|
223
293
|
// Multi-node HA mode: use PostgreSQL-backed distributed locking.
|
|
224
294
|
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
225
295
|
const haConfig = {
|
|
@@ -244,7 +314,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
244
314
|
validatorKeyStore,
|
|
245
315
|
epochCache,
|
|
246
316
|
p2pClient,
|
|
247
|
-
|
|
317
|
+
proposalHandler,
|
|
248
318
|
blockSource,
|
|
249
319
|
checkpointsBuilder,
|
|
250
320
|
worldState,
|
|
@@ -265,14 +335,21 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
265
335
|
.filter(addr => !this.config.disabledValidators.some(disabled => disabled.equals(addr)));
|
|
266
336
|
}
|
|
267
337
|
|
|
268
|
-
public
|
|
269
|
-
return this.
|
|
338
|
+
public getProposalHandler() {
|
|
339
|
+
return this.proposalHandler;
|
|
270
340
|
}
|
|
271
341
|
|
|
272
342
|
public signWithAddress(addr: EthAddress, msg: TypedDataDefinition, context: SigningContext) {
|
|
273
343
|
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
274
344
|
}
|
|
275
345
|
|
|
346
|
+
private getSignatureContext(): CoordinationSignatureContext {
|
|
347
|
+
return {
|
|
348
|
+
chainId: this.config.l1ChainId,
|
|
349
|
+
rollupAddress: this.config.rollupAddress,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
276
353
|
public getCoinbaseForAttestor(attestor: EthAddress): EthAddress {
|
|
277
354
|
return this.keyStore.getCoinbaseAddress(attestor);
|
|
278
355
|
}
|
|
@@ -285,14 +362,27 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
285
362
|
return this.config;
|
|
286
363
|
}
|
|
287
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
|
+
|
|
288
373
|
public updateConfig(config: Partial<ValidatorClientFullConfig>) {
|
|
289
374
|
this.config = { ...this.config, ...config };
|
|
375
|
+
this.proposalHandler.updateConfig(config);
|
|
290
376
|
}
|
|
291
377
|
|
|
292
378
|
public reloadKeystore(newManager: KeystoreManager): void {
|
|
293
379
|
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
294
380
|
this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
|
|
295
|
-
this.validationService = new ValidationService(
|
|
381
|
+
this.validationService = new ValidationService(
|
|
382
|
+
this.keyStore,
|
|
383
|
+
this.getSignatureContext(),
|
|
384
|
+
this.log.createChild('validation-service'),
|
|
385
|
+
);
|
|
296
386
|
}
|
|
297
387
|
|
|
298
388
|
public async start() {
|
|
@@ -339,7 +429,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
339
429
|
checkpoint: CheckpointProposalCore,
|
|
340
430
|
proposalSender: PeerId,
|
|
341
431
|
): Promise<CheckpointAttestation[] | undefined> => this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
342
|
-
this.p2pClient.
|
|
432
|
+
this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
|
|
343
433
|
|
|
344
434
|
// Duplicate proposal handler - triggers slashing for equivocation
|
|
345
435
|
this.p2pClient.registerDuplicateProposalCallback((info: DuplicateProposalInfo) => {
|
|
@@ -351,6 +441,10 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
351
441
|
this.handleDuplicateAttestation(info);
|
|
352
442
|
});
|
|
353
443
|
|
|
444
|
+
this.p2pClient.registerCheckpointAttestationCallback((attestation: CheckpointAttestation) => {
|
|
445
|
+
this.handleCheckpointAttestation(attestation);
|
|
446
|
+
});
|
|
447
|
+
|
|
354
448
|
const myAddresses = this.getValidatorAddresses();
|
|
355
449
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
356
450
|
|
|
@@ -378,13 +472,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
378
472
|
return false;
|
|
379
473
|
}
|
|
380
474
|
|
|
381
|
-
//
|
|
475
|
+
// Log self-proposals from HA peers (same validator key on different nodes)
|
|
382
476
|
if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
383
|
-
this.log.
|
|
477
|
+
this.log.verbose(`Processing block proposal from HA peer for slot ${slotNumber}`, {
|
|
384
478
|
proposer: proposer.toString(),
|
|
385
479
|
slotNumber,
|
|
386
480
|
});
|
|
387
|
-
return false;
|
|
388
481
|
}
|
|
389
482
|
|
|
390
483
|
// Check if we're in the committee (for metrics purposes)
|
|
@@ -398,22 +491,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
398
491
|
fishermanMode: this.config.fishermanMode || false,
|
|
399
492
|
});
|
|
400
493
|
|
|
401
|
-
// Reexecute
|
|
402
|
-
|
|
403
|
-
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } =
|
|
404
|
-
this.config;
|
|
405
|
-
const shouldReexecute =
|
|
406
|
-
fishermanMode ||
|
|
407
|
-
(slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute) ||
|
|
408
|
-
(partOfCommittee && validatorReexecute) ||
|
|
409
|
-
alwaysReexecuteBlockProposals ||
|
|
410
|
-
this.blobClient.canUpload();
|
|
411
|
-
|
|
412
|
-
const validationResult = await this.blockProposalHandler.handleBlockProposal(
|
|
413
|
-
proposal,
|
|
414
|
-
proposalSender,
|
|
415
|
-
!!shouldReexecute && !escapeHatchOpen,
|
|
416
|
-
);
|
|
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);
|
|
417
496
|
|
|
418
497
|
if (!validationResult.isValid) {
|
|
419
498
|
const reason = validationResult.reason || 'unknown';
|
|
@@ -436,15 +515,18 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
436
515
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
437
516
|
}
|
|
438
517
|
|
|
439
|
-
// Slash invalid block proposals (can happen even when not in committee)
|
|
440
518
|
if (
|
|
441
519
|
!escapeHatchOpen &&
|
|
442
520
|
validationResult.reason &&
|
|
443
|
-
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
|
|
444
|
-
slashBroadcastedInvalidBlockPenalty > 0n
|
|
521
|
+
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
|
|
445
522
|
) {
|
|
446
|
-
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
|
+
});
|
|
447
528
|
this.slashInvalidBlock(proposal);
|
|
529
|
+
this.markInvalidProposalSlot(proposal.slotNumber);
|
|
448
530
|
}
|
|
449
531
|
return false;
|
|
450
532
|
}
|
|
@@ -474,66 +556,56 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
474
556
|
proposal: CheckpointProposalCore,
|
|
475
557
|
_proposalSender: PeerId,
|
|
476
558
|
): Promise<CheckpointAttestation[] | undefined> {
|
|
477
|
-
const
|
|
559
|
+
const proposalSlotNumber = proposal.slotNumber;
|
|
478
560
|
const proposer = proposal.getSender();
|
|
479
561
|
|
|
480
562
|
// If escape hatch is open for this slot's epoch, do not attest.
|
|
481
|
-
if (await this.epochCache.isEscapeHatchOpenAtSlot(
|
|
482
|
-
this.log.warn(`Escape hatch open for slot ${
|
|
563
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(proposalSlotNumber)) {
|
|
564
|
+
this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
|
|
483
565
|
return undefined;
|
|
484
566
|
}
|
|
485
567
|
|
|
486
|
-
//
|
|
487
|
-
if (!
|
|
488
|
-
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
568
|
+
// Early-out for equivocation: refuses if we've already attested to a higher slot.
|
|
569
|
+
if (!this.shouldAttestToSlot(proposalSlotNumber)) {
|
|
489
570
|
return undefined;
|
|
490
571
|
}
|
|
491
572
|
|
|
492
573
|
// Ignore proposals from ourselves (may happen in HA setups)
|
|
493
|
-
if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
494
|
-
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}`, {
|
|
495
576
|
proposer: proposer.toString(),
|
|
496
|
-
|
|
577
|
+
proposalSlotNumber,
|
|
497
578
|
});
|
|
498
579
|
return undefined;
|
|
499
580
|
}
|
|
500
581
|
|
|
501
|
-
//
|
|
502
|
-
|
|
503
|
-
this.log.warn(
|
|
504
|
-
`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`,
|
|
505
|
-
);
|
|
506
|
-
return undefined;
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
// Check that I have any address in current committee before attesting
|
|
510
|
-
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
582
|
+
// Check that I have any address in the committee where this checkpoint will land before attesting
|
|
583
|
+
const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
|
|
511
584
|
const partOfCommittee = inCommittee.length > 0;
|
|
512
585
|
|
|
513
586
|
const proposalInfo = {
|
|
514
|
-
|
|
587
|
+
proposalSlotNumber,
|
|
515
588
|
archive: proposal.archive.toString(),
|
|
516
|
-
proposer: proposer
|
|
589
|
+
proposer: proposer?.toString(),
|
|
517
590
|
};
|
|
518
|
-
this.log.info(`Received checkpoint proposal for slot ${
|
|
591
|
+
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
519
592
|
...proposalInfo,
|
|
520
593
|
fishermanMode: this.config.fishermanMode || false,
|
|
521
594
|
});
|
|
522
595
|
|
|
523
|
-
// 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;
|
|
524
599
|
if (this.config.skipCheckpointProposalValidation) {
|
|
525
|
-
this.log.warn(`Skipping checkpoint proposal validation for slot ${
|
|
600
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
601
|
+
checkpointNumber = CheckpointNumber(0);
|
|
526
602
|
} else {
|
|
527
|
-
const validationResult = await this.
|
|
603
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
528
604
|
if (!validationResult.isValid) {
|
|
529
605
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
530
606
|
return undefined;
|
|
531
607
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
// Upload blobs to filestore if we can (fire and forget)
|
|
535
|
-
if (this.blobClient.canUpload()) {
|
|
536
|
-
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
608
|
+
checkpointNumber = validationResult.checkpointNumber;
|
|
537
609
|
}
|
|
538
610
|
|
|
539
611
|
// Check that I have any address in current committee before attesting
|
|
@@ -544,16 +616,19 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
544
616
|
}
|
|
545
617
|
|
|
546
618
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
547
|
-
this.log.info(
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
619
|
+
this.log.info(
|
|
620
|
+
`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${proposalSlotNumber}`,
|
|
621
|
+
{
|
|
622
|
+
...proposalInfo,
|
|
623
|
+
inCommittee: partOfCommittee,
|
|
624
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
625
|
+
},
|
|
626
|
+
);
|
|
552
627
|
|
|
553
628
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
554
629
|
|
|
555
630
|
// Track epoch participation per attester: count each (attester, epoch) pair at most once
|
|
556
|
-
const proposalEpoch = getEpochAtSlot(
|
|
631
|
+
const proposalEpoch = getEpochAtSlot(proposalSlotNumber, this.epochCache.getL1Constants());
|
|
557
632
|
for (const attester of inCommittee) {
|
|
558
633
|
const key = attester.toString();
|
|
559
634
|
const lastEpoch = this.lastAttestedEpochByAttester.get(key);
|
|
@@ -581,14 +656,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
581
656
|
|
|
582
657
|
if (this.config.fishermanMode) {
|
|
583
658
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
584
|
-
this.log.info(`Creating checkpoint attestations for slot ${
|
|
659
|
+
this.log.info(`Creating checkpoint attestations for slot ${proposalSlotNumber}`, {
|
|
585
660
|
...proposalInfo,
|
|
586
661
|
attestors: attestors.map(a => a.toString()),
|
|
587
662
|
});
|
|
588
663
|
return undefined;
|
|
589
664
|
}
|
|
590
665
|
|
|
591
|
-
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
666
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
|
|
592
667
|
}
|
|
593
668
|
|
|
594
669
|
/**
|
|
@@ -615,13 +690,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
615
690
|
private async createCheckpointAttestationsFromProposal(
|
|
616
691
|
proposal: CheckpointProposalCore,
|
|
617
692
|
attestors: EthAddress[] = [],
|
|
693
|
+
checkpointNumber: CheckpointNumber,
|
|
618
694
|
): Promise<CheckpointAttestation[] | undefined> {
|
|
619
695
|
// Equivocation check: must happen right before signing to minimize the race window
|
|
620
696
|
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
621
697
|
return undefined;
|
|
622
698
|
}
|
|
623
699
|
|
|
624
|
-
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
700
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
|
|
625
701
|
|
|
626
702
|
// Track the proposal we attested to (to prevent equivocation)
|
|
627
703
|
this.lastAttestedProposal = proposal;
|
|
@@ -630,178 +706,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
630
706
|
return attestations;
|
|
631
707
|
}
|
|
632
708
|
|
|
633
|
-
/**
|
|
634
|
-
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
635
|
-
* @returns Validation result with isValid flag and reason if invalid.
|
|
636
|
-
*/
|
|
637
|
-
private async validateCheckpointProposal(
|
|
638
|
-
proposal: CheckpointProposalCore,
|
|
639
|
-
proposalInfo: LogData,
|
|
640
|
-
): Promise<{ isValid: true } | { isValid: false; reason: string }> {
|
|
641
|
-
const slot = proposal.slotNumber;
|
|
642
|
-
|
|
643
|
-
// Timeout block syncing at the start of the next slot
|
|
644
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
645
|
-
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
|
|
646
|
-
const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
|
|
647
|
-
|
|
648
|
-
// Wait for last block to sync by archive
|
|
649
|
-
let lastBlockHeader: BlockHeader | undefined;
|
|
650
|
-
try {
|
|
651
|
-
lastBlockHeader = await retryUntil(
|
|
652
|
-
async () => {
|
|
653
|
-
await this.blockSource.syncImmediate();
|
|
654
|
-
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
655
|
-
},
|
|
656
|
-
`waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`,
|
|
657
|
-
timeoutSeconds,
|
|
658
|
-
0.5,
|
|
659
|
-
);
|
|
660
|
-
} catch (err) {
|
|
661
|
-
if (err instanceof TimeoutError) {
|
|
662
|
-
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
663
|
-
return { isValid: false, reason: 'last_block_not_found' };
|
|
664
|
-
}
|
|
665
|
-
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
666
|
-
return { isValid: false, reason: 'block_fetch_error' };
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
if (!lastBlockHeader) {
|
|
670
|
-
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
671
|
-
return { isValid: false, reason: 'last_block_not_found' };
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
// Get all full blocks for the slot and checkpoint
|
|
675
|
-
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
676
|
-
if (blocks.length === 0) {
|
|
677
|
-
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
678
|
-
return { isValid: false, reason: 'no_blocks_for_slot' };
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
682
|
-
if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
|
|
683
|
-
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
684
|
-
return { isValid: false, reason: 'last_block_archive_mismatch' };
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
688
|
-
...proposalInfo,
|
|
689
|
-
blockNumbers: blocks.map(b => b.number),
|
|
690
|
-
});
|
|
691
|
-
|
|
692
|
-
// Get checkpoint constants from first block
|
|
693
|
-
const firstBlock = blocks[0];
|
|
694
|
-
const constants = this.extractCheckpointConstants(firstBlock);
|
|
695
|
-
const checkpointNumber = firstBlock.checkpointNumber;
|
|
696
|
-
|
|
697
|
-
// Get L1-to-L2 messages for this checkpoint
|
|
698
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
699
|
-
|
|
700
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
701
|
-
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
702
|
-
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch))
|
|
703
|
-
.filter(c => c.checkpointNumber < checkpointNumber)
|
|
704
|
-
.map(c => c.checkpointOutHash);
|
|
705
|
-
|
|
706
|
-
// Fork world state at the block before the first block
|
|
707
|
-
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
708
|
-
const fork = await this.worldState.fork(parentBlockNumber);
|
|
709
|
-
|
|
710
|
-
try {
|
|
711
|
-
// Create checkpoint builder with all existing blocks
|
|
712
|
-
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
|
|
713
|
-
checkpointNumber,
|
|
714
|
-
constants,
|
|
715
|
-
proposal.feeAssetPriceModifier,
|
|
716
|
-
l1ToL2Messages,
|
|
717
|
-
previousCheckpointOutHashes,
|
|
718
|
-
fork,
|
|
719
|
-
blocks,
|
|
720
|
-
this.log.getBindings(),
|
|
721
|
-
);
|
|
722
|
-
|
|
723
|
-
// Complete the checkpoint to get computed values
|
|
724
|
-
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
725
|
-
|
|
726
|
-
// Compare checkpoint header with proposal
|
|
727
|
-
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
728
|
-
this.log.warn(`Checkpoint header mismatch`, {
|
|
729
|
-
...proposalInfo,
|
|
730
|
-
computed: computedCheckpoint.header.toInspect(),
|
|
731
|
-
proposal: proposal.checkpointHeader.toInspect(),
|
|
732
|
-
});
|
|
733
|
-
return { isValid: false, reason: 'checkpoint_header_mismatch' };
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
// Compare archive root with proposal
|
|
737
|
-
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
738
|
-
this.log.warn(`Archive root mismatch`, {
|
|
739
|
-
...proposalInfo,
|
|
740
|
-
computed: computedCheckpoint.archive.root.toString(),
|
|
741
|
-
proposal: proposal.archive.toString(),
|
|
742
|
-
});
|
|
743
|
-
return { isValid: false, reason: 'archive_mismatch' };
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
747
|
-
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
748
|
-
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
749
|
-
const computedEpochOutHash = accumulateCheckpointOutHashes([...previousCheckpointOutHashes, checkpointOutHash]);
|
|
750
|
-
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
751
|
-
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
752
|
-
this.log.warn(`Epoch out hash mismatch`, {
|
|
753
|
-
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
754
|
-
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
755
|
-
checkpointOutHash: checkpointOutHash.toString(),
|
|
756
|
-
previousCheckpointOutHashes: previousCheckpointOutHashes.map(h => h.toString()),
|
|
757
|
-
...proposalInfo,
|
|
758
|
-
});
|
|
759
|
-
return { isValid: false, reason: 'out_hash_mismatch' };
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
// Final round of validations on the checkpoint, just in case.
|
|
763
|
-
try {
|
|
764
|
-
validateCheckpoint(computedCheckpoint, {
|
|
765
|
-
rollupManaLimit: this.checkpointsBuilder.getConfig().rollupManaLimit,
|
|
766
|
-
maxDABlockGas: this.config.validateMaxDABlockGas,
|
|
767
|
-
maxL2BlockGas: this.config.validateMaxL2BlockGas,
|
|
768
|
-
maxTxsPerBlock: this.config.validateMaxTxsPerBlock,
|
|
769
|
-
maxTxsPerCheckpoint: this.config.validateMaxTxsPerCheckpoint,
|
|
770
|
-
});
|
|
771
|
-
} catch (err) {
|
|
772
|
-
this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
|
|
773
|
-
return { isValid: false, reason: 'checkpoint_validation_failed' };
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
777
|
-
return { isValid: true };
|
|
778
|
-
} finally {
|
|
779
|
-
await fork.close();
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
/**
|
|
784
|
-
* Extract checkpoint global variables from a block.
|
|
785
|
-
*/
|
|
786
|
-
private extractCheckpointConstants(block: L2Block): CheckpointGlobalVariables {
|
|
787
|
-
const gv = block.header.globalVariables;
|
|
788
|
-
return {
|
|
789
|
-
chainId: gv.chainId,
|
|
790
|
-
version: gv.version,
|
|
791
|
-
slotNumber: gv.slotNumber,
|
|
792
|
-
timestamp: gv.timestamp,
|
|
793
|
-
coinbase: gv.coinbase,
|
|
794
|
-
feeRecipient: gv.feeRecipient,
|
|
795
|
-
gasFees: gv.gasFees,
|
|
796
|
-
};
|
|
797
|
-
}
|
|
798
|
-
|
|
799
709
|
/**
|
|
800
710
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
801
711
|
*/
|
|
802
712
|
protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
|
|
803
713
|
try {
|
|
804
|
-
const lastBlockHeader = await this.blockSource.
|
|
714
|
+
const lastBlockHeader = (await this.blockSource.getBlockData({ archive: proposal.archive }))?.header;
|
|
805
715
|
if (!lastBlockHeader) {
|
|
806
716
|
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
807
717
|
return;
|
|
@@ -834,12 +744,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
834
744
|
return;
|
|
835
745
|
}
|
|
836
746
|
|
|
837
|
-
// Trim the set if it's too big.
|
|
838
|
-
if (this.proposersOfInvalidBlocks.size > MAX_PROPOSERS_OF_INVALID_BLOCKS) {
|
|
839
|
-
// remove oldest proposer. `values` is guaranteed to be in insertion order.
|
|
840
|
-
this.proposersOfInvalidBlocks.delete(this.proposersOfInvalidBlocks.values().next().value!);
|
|
841
|
-
}
|
|
842
|
-
|
|
843
747
|
this.proposersOfInvalidBlocks.add(proposer.toString());
|
|
844
748
|
|
|
845
749
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
@@ -852,20 +756,115 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
852
756
|
]);
|
|
853
757
|
}
|
|
854
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
|
+
|
|
855
852
|
/**
|
|
856
853
|
* Handle detection of a duplicate proposal (equivocation).
|
|
857
854
|
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
858
855
|
*/
|
|
859
856
|
private handleDuplicateProposal(info: DuplicateProposalInfo): void {
|
|
860
857
|
const { slot, proposer, type } = info;
|
|
858
|
+
this.slotsWithProposalEquivocation.add(slot);
|
|
861
859
|
|
|
862
|
-
this.log.
|
|
860
|
+
this.log.info(`Detected duplicate ${type} proposal offense from ${proposer.toString()} at slot ${slot}`, {
|
|
863
861
|
proposer: proposer.toString(),
|
|
864
862
|
slot,
|
|
865
863
|
type,
|
|
864
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
865
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_PROPOSAL),
|
|
866
866
|
});
|
|
867
867
|
|
|
868
|
-
// Emit slash event
|
|
869
868
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
870
869
|
{
|
|
871
870
|
validator: proposer,
|
|
@@ -874,6 +873,13 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
874
873
|
epochOrSlot: BigInt(slot),
|
|
875
874
|
},
|
|
876
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
|
+
]);
|
|
877
883
|
}
|
|
878
884
|
|
|
879
885
|
/**
|
|
@@ -883,9 +889,11 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
883
889
|
private handleDuplicateAttestation(info: DuplicateAttestationInfo): void {
|
|
884
890
|
const { slot, attester } = info;
|
|
885
891
|
|
|
886
|
-
this.log.
|
|
892
|
+
this.log.info(`Detected duplicate attestation offense from ${attester.toString()} at slot ${slot}`, {
|
|
887
893
|
attester: attester.toString(),
|
|
888
894
|
slot,
|
|
895
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
896
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_ATTESTATION),
|
|
889
897
|
});
|
|
890
898
|
|
|
891
899
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
@@ -900,6 +908,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
900
908
|
|
|
901
909
|
async createBlockProposal(
|
|
902
910
|
blockHeader: BlockHeader,
|
|
911
|
+
checkpointNumber: CheckpointNumber,
|
|
903
912
|
indexWithinCheckpoint: IndexWithinCheckpoint,
|
|
904
913
|
inHash: Fr,
|
|
905
914
|
archive: Fr,
|
|
@@ -926,6 +935,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
926
935
|
);
|
|
927
936
|
const newProposal = await this.validationService.createBlockProposal(
|
|
928
937
|
blockHeader,
|
|
938
|
+
checkpointNumber,
|
|
929
939
|
indexWithinCheckpoint,
|
|
930
940
|
inHash,
|
|
931
941
|
archive,
|
|
@@ -933,7 +943,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
933
943
|
proposerAddress,
|
|
934
944
|
{
|
|
935
945
|
...options,
|
|
936
|
-
broadcastInvalidBlockProposal:
|
|
946
|
+
broadcastInvalidBlockProposal:
|
|
947
|
+
options.broadcastInvalidBlockProposal || this.config.broadcastInvalidBlockProposal,
|
|
937
948
|
},
|
|
938
949
|
);
|
|
939
950
|
this.lastProposedBlock = newProposal;
|
|
@@ -943,8 +954,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
943
954
|
async createCheckpointProposal(
|
|
944
955
|
checkpointHeader: CheckpointHeader,
|
|
945
956
|
archive: Fr,
|
|
957
|
+
checkpointNumber: CheckpointNumber,
|
|
946
958
|
feeAssetPriceModifier: bigint,
|
|
947
|
-
|
|
959
|
+
lastBlockProposal: BlockProposal | undefined,
|
|
948
960
|
proposerAddress: EthAddress | undefined,
|
|
949
961
|
options: CheckpointProposalOptions = {},
|
|
950
962
|
): Promise<CheckpointProposal> {
|
|
@@ -965,12 +977,20 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
965
977
|
const newProposal = await this.validationService.createCheckpointProposal(
|
|
966
978
|
checkpointHeader,
|
|
967
979
|
archive,
|
|
980
|
+
checkpointNumber,
|
|
968
981
|
feeAssetPriceModifier,
|
|
969
|
-
|
|
982
|
+
lastBlockProposal,
|
|
970
983
|
proposerAddress,
|
|
971
984
|
options,
|
|
972
985
|
);
|
|
973
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);
|
|
974
994
|
return newProposal;
|
|
975
995
|
}
|
|
976
996
|
|
|
@@ -982,16 +1002,24 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
982
1002
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
983
1003
|
proposer: EthAddress,
|
|
984
1004
|
slot: SlotNumber,
|
|
985
|
-
|
|
1005
|
+
checkpointNumber: CheckpointNumber,
|
|
986
1006
|
): Promise<Signature> {
|
|
987
|
-
return await this.validationService.signAttestationsAndSigners(
|
|
1007
|
+
return await this.validationService.signAttestationsAndSigners(
|
|
1008
|
+
attestationsAndSigners,
|
|
1009
|
+
proposer,
|
|
1010
|
+
slot,
|
|
1011
|
+
checkpointNumber,
|
|
1012
|
+
);
|
|
988
1013
|
}
|
|
989
1014
|
|
|
990
|
-
async collectOwnAttestations(
|
|
1015
|
+
async collectOwnAttestations(
|
|
1016
|
+
proposal: CheckpointProposal,
|
|
1017
|
+
checkpointNumber: CheckpointNumber,
|
|
1018
|
+
): Promise<CheckpointAttestation[]> {
|
|
991
1019
|
const slot = proposal.slotNumber;
|
|
992
1020
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
993
1021
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, { inCommittee });
|
|
994
|
-
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
1022
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
|
|
995
1023
|
|
|
996
1024
|
if (!attestations) {
|
|
997
1025
|
return [];
|
|
@@ -1010,6 +1038,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
1010
1038
|
proposal: CheckpointProposal,
|
|
1011
1039
|
required: number,
|
|
1012
1040
|
deadline: Date,
|
|
1041
|
+
checkpointNumber: CheckpointNumber,
|
|
1013
1042
|
): Promise<CheckpointAttestation[]> {
|
|
1014
1043
|
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
1015
1044
|
const slot = proposal.slotNumber;
|
|
@@ -1022,33 +1051,23 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
1022
1051
|
throw new AttestationTimeoutError(0, required, slot);
|
|
1023
1052
|
}
|
|
1024
1053
|
|
|
1025
|
-
await this.collectOwnAttestations(proposal);
|
|
1054
|
+
await this.collectOwnAttestations(proposal, checkpointNumber);
|
|
1026
1055
|
|
|
1027
|
-
const
|
|
1056
|
+
const proposalPayloadHash = proposal.getPayloadHash();
|
|
1028
1057
|
const myAddresses = this.getValidatorAddresses();
|
|
1029
1058
|
|
|
1030
1059
|
let attestations: CheckpointAttestation[] = [];
|
|
1031
1060
|
while (true) {
|
|
1032
|
-
//
|
|
1033
|
-
//
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
if (!attestation.archive.equals(proposal.archive)) {
|
|
1037
|
-
this.log.warn(
|
|
1038
|
-
`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`,
|
|
1039
|
-
{ attestationArchive: attestation.archive.toString(), proposalArchive: proposal.archive.toString() },
|
|
1040
|
-
);
|
|
1041
|
-
return false;
|
|
1042
|
-
}
|
|
1043
|
-
return true;
|
|
1044
|
-
},
|
|
1045
|
-
);
|
|
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);
|
|
1046
1065
|
|
|
1047
1066
|
// Log new attestations we collected
|
|
1048
1067
|
const oldSenders = attestations.map(attestation => attestation.getSender());
|
|
1049
1068
|
for (const collected of collectedAttestations) {
|
|
1050
1069
|
const collectedSender = collected.getSender();
|
|
1051
|
-
// Skip attestations with invalid signatures
|
|
1070
|
+
// Skip attestations with invalid signatures. Should not happen as we don't add invalid attestations to our pool.
|
|
1052
1071
|
if (!collectedSender) {
|
|
1053
1072
|
this.log.warn(`Skipping attestation with invalid signature for slot ${slot}`);
|
|
1054
1073
|
continue;
|