@aztec/validator-client 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5a9928
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 +54 -10
- package/dest/checkpoint_builder.d.ts +32 -11
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +136 -47
- package/dest/config.d.ts +9 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +45 -7
- 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 +33 -45
- package/dest/factory.d.ts +11 -5
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +8 -7
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/key_store/ha_key_store.js +1 -1
- package/dest/key_store/web3signer_key_store.d.ts +10 -2
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
- package/dest/key_store/web3signer_key_store.js +32 -41
- package/dest/metrics.d.ts +14 -2
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +27 -1
- package/dest/proposal_handler.d.ts +173 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/proposal_handler.js +1302 -0
- package/dest/validator.d.ts +62 -26
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +347 -238
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +156 -42
- package/src/config.ts +53 -9
- package/src/duties/validation_service.ts +59 -54
- package/src/factory.ts +20 -7
- package/src/index.ts +1 -2
- package/src/key_store/ha_key_store.ts +1 -1
- package/src/key_store/web3signer_key_store.ts +43 -59
- package/src/metrics.ts +39 -1
- package/src/proposal_handler.ts +1418 -0
- package/src/validator.ts +480 -286
- package/dest/block_proposal_handler.d.ts +0 -63
- package/dest/block_proposal_handler.d.ts.map +0 -1
- package/dest/block_proposal_handler.js +0 -546
- package/dest/tx_validator/index.d.ts +0 -3
- package/dest/tx_validator/index.d.ts.map +0 -1
- package/dest/tx_validator/index.js +0 -2
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -19
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -54
- package/src/block_proposal_handler.ts +0 -555
- package/src/tx_validator/index.ts +0 -2
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -154
package/src/validator.ts
CHANGED
|
@@ -1,72 +1,83 @@
|
|
|
1
1
|
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
2
2
|
import { type Blob, getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
3
3
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
4
|
-
import {
|
|
5
|
-
BlockNumber,
|
|
6
|
-
CheckpointNumber,
|
|
7
|
-
EpochNumber,
|
|
8
|
-
IndexWithinCheckpoint,
|
|
9
|
-
SlotNumber,
|
|
10
|
-
} from '@aztec/foundation/branded-types';
|
|
4
|
+
import { CheckpointNumber, EpochNumber, IndexWithinCheckpoint, SlotNumber } from '@aztec/foundation/branded-types';
|
|
11
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
12
|
-
import { TimeoutError } from '@aztec/foundation/error';
|
|
13
6
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
14
|
-
import
|
|
7
|
+
import { Signature } from '@aztec/foundation/eth-signature';
|
|
8
|
+
import { FifoSet } from '@aztec/foundation/fifo-set';
|
|
15
9
|
import { type LogData, type Logger, createLogger } from '@aztec/foundation/log';
|
|
16
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
17
10
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
18
11
|
import { sleep } from '@aztec/foundation/sleep';
|
|
19
12
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
20
13
|
import type { KeystoreManager } from '@aztec/node-keystore';
|
|
21
|
-
import type { DuplicateProposalInfo, P2P, PeerId } from '@aztec/p2p';
|
|
22
|
-
import { AuthRequest, AuthResponse,
|
|
23
|
-
import {
|
|
14
|
+
import type { DuplicateAttestationInfo, DuplicateProposalInfo, OversizedProposalInfo, P2P, PeerId } from '@aztec/p2p';
|
|
15
|
+
import { AuthRequest, AuthResponse, ReqRespSubProtocol } from '@aztec/p2p';
|
|
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';
|
|
24
24
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
25
|
-
import type { CommitteeAttestationsAndSigners,
|
|
25
|
+
import type { CommitteeAttestationsAndSigners, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
26
|
+
import type { CheckpointReexecutionTracker } from '@aztec/stdlib/checkpoint';
|
|
26
27
|
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
27
28
|
import type {
|
|
28
|
-
CreateCheckpointProposalLastBlockData,
|
|
29
29
|
ITxProvider,
|
|
30
30
|
Validator,
|
|
31
31
|
ValidatorClientFullConfig,
|
|
32
32
|
WorldStateSynchronizer,
|
|
33
33
|
} from '@aztec/stdlib/interfaces/server';
|
|
34
|
-
import {
|
|
35
|
-
import
|
|
36
|
-
BlockProposal,
|
|
37
|
-
BlockProposalOptions,
|
|
34
|
+
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
35
|
+
import {
|
|
36
|
+
type BlockProposal,
|
|
37
|
+
type BlockProposalOptions,
|
|
38
38
|
CheckpointAttestation,
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
CheckpointProposal,
|
|
40
|
+
type CheckpointProposalCore,
|
|
41
|
+
type CheckpointProposalOptions,
|
|
42
|
+
type CoordinationSignatureContext,
|
|
43
|
+
type ValidatedBlockProposal,
|
|
44
|
+
type ValidatedCheckpointProposalCore,
|
|
41
45
|
} from '@aztec/stdlib/p2p';
|
|
42
|
-
import { CheckpointProposal } from '@aztec/stdlib/p2p';
|
|
43
46
|
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
44
|
-
import
|
|
47
|
+
import { ConsensusTimetable } from '@aztec/stdlib/timetable';
|
|
48
|
+
import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
|
|
45
49
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
46
50
|
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
47
|
-
import {
|
|
48
|
-
|
|
51
|
+
import {
|
|
52
|
+
createHASigner,
|
|
53
|
+
createLocalSignerWithProtection,
|
|
54
|
+
createSignerFromSharedDb,
|
|
55
|
+
} from '@aztec/validator-ha-signer/factory';
|
|
56
|
+
import { DutyType, type SigningContext, type SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
57
|
+
import type { ValidatorHASigner } from '@aztec/validator-ha-signer/validator-ha-signer';
|
|
49
58
|
|
|
50
59
|
import { EventEmitter } from 'events';
|
|
51
60
|
import type { TypedDataDefinition } from 'viem';
|
|
52
61
|
|
|
53
|
-
import { BlockProposalHandler, type BlockProposalValidationFailureReason } from './block_proposal_handler.js';
|
|
54
62
|
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
55
63
|
import { ValidationService } from './duties/validation_service.js';
|
|
56
64
|
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
57
65
|
import type { ExtendedValidatorKeyStore } from './key_store/interface.js';
|
|
58
66
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
59
67
|
import { ValidatorMetrics } from './metrics.js';
|
|
68
|
+
import {
|
|
69
|
+
type BlockProposalValidationFailureReason,
|
|
70
|
+
type CheckpointProposalValidationFailureResult,
|
|
71
|
+
ProposalHandler,
|
|
72
|
+
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT,
|
|
73
|
+
SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT,
|
|
74
|
+
} from './proposal_handler.js';
|
|
60
75
|
|
|
61
76
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
62
77
|
// Just cap the set to avoid unbounded growth.
|
|
63
78
|
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT: BlockProposalValidationFailureReason[] = [
|
|
67
|
-
'state_mismatch',
|
|
68
|
-
'failed_txs',
|
|
69
|
-
];
|
|
79
|
+
const MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS = 1000;
|
|
80
|
+
const MAX_TRACKED_BAD_ATTESTATIONS = 10_000;
|
|
70
81
|
|
|
71
82
|
/**
|
|
72
83
|
* Validator Client
|
|
@@ -76,29 +87,40 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
76
87
|
private validationService: ValidationService;
|
|
77
88
|
private metrics: ValidatorMetrics;
|
|
78
89
|
private log: Logger;
|
|
79
|
-
|
|
80
90
|
// Whether it has already registered handlers on the p2p client
|
|
81
91
|
private hasRegisteredHandlers = false;
|
|
82
92
|
|
|
83
|
-
|
|
84
|
-
private
|
|
93
|
+
/** Tracks the last block proposal we created, to detect duplicate proposal attempts. */
|
|
94
|
+
private lastProposedBlock?: BlockProposal;
|
|
95
|
+
|
|
96
|
+
/** Tracks the last checkpoint proposal we created. */
|
|
97
|
+
private lastProposedCheckpoint?: CheckpointProposal;
|
|
85
98
|
|
|
86
99
|
private lastEpochForCommitteeUpdateLoop: EpochNumber | undefined;
|
|
87
100
|
private epochCacheUpdateLoop: RunningPromise;
|
|
101
|
+
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */
|
|
102
|
+
private lastAttestedEpochByAttester: Map<string, EpochNumber> = new Map();
|
|
88
103
|
|
|
89
|
-
private proposersOfInvalidBlocks
|
|
104
|
+
private proposersOfInvalidBlocks = FifoSet.withLimit<string>(MAX_PROPOSERS_OF_INVALID_BLOCKS);
|
|
105
|
+
private invalidCheckpointProposalOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS);
|
|
106
|
+
private oversizedProposalOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS);
|
|
107
|
+
private badAttestationOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_BAD_ATTESTATIONS);
|
|
108
|
+
|
|
109
|
+
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */
|
|
110
|
+
private lastAttestedProposal?: CheckpointProposalCore;
|
|
90
111
|
|
|
91
112
|
protected constructor(
|
|
92
113
|
private keyStore: ExtendedValidatorKeyStore,
|
|
93
114
|
private epochCache: EpochCache,
|
|
94
115
|
private p2pClient: P2P,
|
|
95
|
-
private
|
|
116
|
+
private proposalHandler: ProposalHandler,
|
|
96
117
|
private blockSource: L2BlockSource,
|
|
97
118
|
private checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
98
119
|
private worldState: WorldStateSynchronizer,
|
|
99
120
|
private l1ToL2MessageSource: L1ToL2MessageSource,
|
|
100
121
|
private config: ValidatorClientFullConfig,
|
|
101
122
|
private blobClient: BlobClientInterface,
|
|
123
|
+
private slashingProtectionSigner: ValidatorHASigner,
|
|
102
124
|
private dateProvider: DateProvider = new DateProvider(),
|
|
103
125
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
104
126
|
log = createLogger('validator'),
|
|
@@ -111,11 +133,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
111
133
|
this.tracer = telemetry.getTracer('Validator');
|
|
112
134
|
this.metrics = new ValidatorMetrics(telemetry);
|
|
113
135
|
|
|
114
|
-
this.validationService = new ValidationService(
|
|
136
|
+
this.validationService = new ValidationService(
|
|
137
|
+
keyStore,
|
|
138
|
+
this.getSignatureContext(),
|
|
139
|
+
this.log.createChild('validation-service'),
|
|
140
|
+
);
|
|
141
|
+
this.proposalHandler.setCheckpointProposalValidationFailureCallback((proposal, result, proposalInfo) =>
|
|
142
|
+
this.handleInvalidCheckpointProposal(proposal, result, proposalInfo),
|
|
143
|
+
);
|
|
115
144
|
|
|
116
145
|
// Refresh epoch cache every second to trigger alert if participation in committee changes
|
|
117
146
|
this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), this.log, 1000);
|
|
118
|
-
|
|
119
147
|
const myAddresses = this.getValidatorAddresses();
|
|
120
148
|
this.log.verbose(`Initialized validator with addresses: ${myAddresses.map(a => a.toString()).join(', ')}`);
|
|
121
149
|
}
|
|
@@ -152,6 +180,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
152
180
|
this.log.trace(`No committee found for slot`);
|
|
153
181
|
return;
|
|
154
182
|
}
|
|
183
|
+
this.metrics.setCurrentEpoch(epoch);
|
|
155
184
|
if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
|
|
156
185
|
const me = this.getValidatorAddresses();
|
|
157
186
|
const committeeSet = new Set(committee.map(v => v.toString()));
|
|
@@ -183,49 +212,74 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
183
212
|
txProvider: ITxProvider,
|
|
184
213
|
keyStoreManager: KeystoreManager,
|
|
185
214
|
blobClient: BlobClientInterface,
|
|
215
|
+
reexecutionTracker: CheckpointReexecutionTracker,
|
|
186
216
|
dateProvider: DateProvider = new DateProvider(),
|
|
187
217
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
218
|
+
slashingProtectionDb?: SlashingProtectionDatabase,
|
|
188
219
|
) {
|
|
189
220
|
const metrics = new ValidatorMetrics(telemetry);
|
|
190
|
-
const
|
|
191
|
-
|
|
221
|
+
const consensusTimetable = new ConsensusTimetable({
|
|
222
|
+
l1Constants: epochCache.getL1Constants(),
|
|
223
|
+
blockDuration: config.blockDurationMs / 1000,
|
|
192
224
|
});
|
|
193
|
-
const
|
|
225
|
+
const proposalHandler = new ProposalHandler(
|
|
194
226
|
checkpointsBuilder,
|
|
195
227
|
worldState,
|
|
196
228
|
blockSource,
|
|
197
229
|
l1ToL2MessageSource,
|
|
198
230
|
txProvider,
|
|
199
|
-
blockProposalValidator,
|
|
200
231
|
epochCache,
|
|
232
|
+
consensusTimetable,
|
|
201
233
|
config,
|
|
234
|
+
blobClient,
|
|
235
|
+
reexecutionTracker,
|
|
202
236
|
metrics,
|
|
203
237
|
dateProvider,
|
|
204
238
|
telemetry,
|
|
239
|
+
undefined,
|
|
205
240
|
);
|
|
206
241
|
|
|
207
|
-
|
|
208
|
-
|
|
242
|
+
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
243
|
+
let slashingProtectionSigner: ValidatorHASigner;
|
|
244
|
+
if (slashingProtectionDb) {
|
|
245
|
+
// Shared database mode: use a pre-existing database (e.g. for testing HA setups).
|
|
246
|
+
({ signer: slashingProtectionSigner } = createSignerFromSharedDb(slashingProtectionDb, config, {
|
|
247
|
+
telemetryClient: telemetry,
|
|
248
|
+
dateProvider,
|
|
249
|
+
}));
|
|
250
|
+
} else if (config.haSigningEnabled) {
|
|
251
|
+
// Multi-node HA mode: use PostgreSQL-backed distributed locking.
|
|
209
252
|
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
210
253
|
const haConfig = {
|
|
211
254
|
...config,
|
|
212
255
|
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000,
|
|
213
256
|
};
|
|
214
|
-
|
|
215
|
-
|
|
257
|
+
({ signer: slashingProtectionSigner } = await createHASigner(haConfig, {
|
|
258
|
+
telemetryClient: telemetry,
|
|
259
|
+
dateProvider,
|
|
260
|
+
}));
|
|
261
|
+
} else {
|
|
262
|
+
// Single-node mode: use LMDB-backed local signing protection.
|
|
263
|
+
// This prevents double-signing if the node crashes and restarts mid-proposal.
|
|
264
|
+
({ signer: slashingProtectionSigner } = await createLocalSignerWithProtection(config, {
|
|
265
|
+
telemetryClient: telemetry,
|
|
266
|
+
dateProvider,
|
|
267
|
+
}));
|
|
216
268
|
}
|
|
269
|
+
const validatorKeyStore: ExtendedValidatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, slashingProtectionSigner);
|
|
217
270
|
|
|
218
271
|
const validator = new ValidatorClient(
|
|
219
272
|
validatorKeyStore,
|
|
220
273
|
epochCache,
|
|
221
274
|
p2pClient,
|
|
222
|
-
|
|
275
|
+
proposalHandler,
|
|
223
276
|
blockSource,
|
|
224
277
|
checkpointsBuilder,
|
|
225
278
|
worldState,
|
|
226
279
|
l1ToL2MessageSource,
|
|
227
280
|
config,
|
|
228
281
|
blobClient,
|
|
282
|
+
slashingProtectionSigner,
|
|
229
283
|
dateProvider,
|
|
230
284
|
telemetry,
|
|
231
285
|
);
|
|
@@ -239,14 +293,21 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
239
293
|
.filter(addr => !this.config.disabledValidators.some(disabled => disabled.equals(addr)));
|
|
240
294
|
}
|
|
241
295
|
|
|
242
|
-
public
|
|
243
|
-
return this.
|
|
296
|
+
public getProposalHandler() {
|
|
297
|
+
return this.proposalHandler;
|
|
244
298
|
}
|
|
245
299
|
|
|
246
300
|
public signWithAddress(addr: EthAddress, msg: TypedDataDefinition, context: SigningContext) {
|
|
247
301
|
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
248
302
|
}
|
|
249
303
|
|
|
304
|
+
private getSignatureContext(): CoordinationSignatureContext {
|
|
305
|
+
return {
|
|
306
|
+
chainId: this.config.l1ChainId,
|
|
307
|
+
rollupAddress: this.config.rollupAddress,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
250
311
|
public getCoinbaseForAttestor(attestor: EthAddress): EthAddress {
|
|
251
312
|
return this.keyStore.getCoinbaseAddress(attestor);
|
|
252
313
|
}
|
|
@@ -259,8 +320,27 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
259
320
|
return this.config;
|
|
260
321
|
}
|
|
261
322
|
|
|
323
|
+
public hasProposalEquivocation(slotNumber: SlotNumber): boolean {
|
|
324
|
+
return this.proposalHandler.hasProposalEquivocation(slotNumber);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
public hasInvalidProposals(slotNumber: SlotNumber): boolean {
|
|
328
|
+
return this.proposalHandler.hasInvalidProposals(slotNumber);
|
|
329
|
+
}
|
|
330
|
+
|
|
262
331
|
public updateConfig(config: Partial<ValidatorClientFullConfig>) {
|
|
263
332
|
this.config = { ...this.config, ...config };
|
|
333
|
+
this.proposalHandler.updateConfig(config);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
public reloadKeystore(newManager: KeystoreManager): void {
|
|
337
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
338
|
+
this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
|
|
339
|
+
this.validationService = new ValidationService(
|
|
340
|
+
this.keyStore,
|
|
341
|
+
this.getSignatureContext(),
|
|
342
|
+
this.log.createChild('validation-service'),
|
|
343
|
+
);
|
|
264
344
|
}
|
|
265
345
|
|
|
266
346
|
public async start() {
|
|
@@ -296,7 +376,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
296
376
|
this.log.debug(`Registering validator handlers for p2p client`);
|
|
297
377
|
|
|
298
378
|
// Block proposal handler - validates but does NOT attest (validators only attest to checkpoints)
|
|
299
|
-
const blockHandler = (block:
|
|
379
|
+
const blockHandler = (block: ValidatedBlockProposal, proposalSender: PeerId): Promise<boolean> =>
|
|
300
380
|
this.validateBlockProposal(block, proposalSender);
|
|
301
381
|
this.p2pClient.registerBlockProposalHandler(blockHandler);
|
|
302
382
|
|
|
@@ -304,16 +384,30 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
304
384
|
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
305
385
|
// and processed separately via the block handler above.
|
|
306
386
|
const checkpointHandler = (
|
|
307
|
-
checkpoint:
|
|
387
|
+
checkpoint: ValidatedCheckpointProposalCore,
|
|
308
388
|
proposalSender: PeerId,
|
|
309
389
|
): Promise<CheckpointAttestation[] | undefined> => this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
310
|
-
this.p2pClient.
|
|
390
|
+
this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
|
|
311
391
|
|
|
312
392
|
// Duplicate proposal handler - triggers slashing for equivocation
|
|
313
393
|
this.p2pClient.registerDuplicateProposalCallback((info: DuplicateProposalInfo) => {
|
|
314
394
|
this.handleDuplicateProposal(info);
|
|
315
395
|
});
|
|
316
396
|
|
|
397
|
+
// Oversized proposal handler - triggers slashing for proposals beyond the per-checkpoint block limit
|
|
398
|
+
this.p2pClient.registerOversizedProposalCallback((info: OversizedProposalInfo) => {
|
|
399
|
+
this.handleOversizedProposal(info);
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
// Duplicate attestation handler - triggers slashing for attestation equivocation
|
|
403
|
+
this.p2pClient.registerDuplicateAttestationCallback((info: DuplicateAttestationInfo) => {
|
|
404
|
+
this.handleDuplicateAttestation(info);
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
this.p2pClient.registerCheckpointAttestationCallback((attestation: CheckpointAttestation) => {
|
|
408
|
+
this.handleCheckpointAttestation(attestation);
|
|
409
|
+
});
|
|
410
|
+
|
|
317
411
|
const myAddresses = this.getValidatorAddresses();
|
|
318
412
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
319
413
|
|
|
@@ -326,7 +420,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
326
420
|
* Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
|
|
327
421
|
* @returns true if the proposal is valid, false otherwise
|
|
328
422
|
*/
|
|
329
|
-
async validateBlockProposal(proposal:
|
|
423
|
+
async validateBlockProposal(proposal: ValidatedBlockProposal, proposalSender: PeerId): Promise<boolean> {
|
|
330
424
|
const slotNumber = proposal.slotNumber;
|
|
331
425
|
|
|
332
426
|
// Note: During escape hatch, we still want to "validate" proposals for observability,
|
|
@@ -341,6 +435,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
341
435
|
return false;
|
|
342
436
|
}
|
|
343
437
|
|
|
438
|
+
// Log self-proposals from HA peers (same validator key on different nodes)
|
|
439
|
+
if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
440
|
+
this.log.verbose(`Processing block proposal from HA peer for slot ${slotNumber}`, {
|
|
441
|
+
proposer: proposer.toString(),
|
|
442
|
+
slotNumber,
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
|
|
344
446
|
// Check if we're in the committee (for metrics purposes)
|
|
345
447
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
346
448
|
const partOfCommittee = inCommittee.length > 0;
|
|
@@ -352,27 +454,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
352
454
|
fishermanMode: this.config.fishermanMode || false,
|
|
353
455
|
});
|
|
354
456
|
|
|
355
|
-
// Reexecute
|
|
356
|
-
|
|
357
|
-
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } =
|
|
358
|
-
this.config;
|
|
359
|
-
const shouldReexecute =
|
|
360
|
-
fishermanMode ||
|
|
361
|
-
(slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute) ||
|
|
362
|
-
(partOfCommittee && validatorReexecute) ||
|
|
363
|
-
alwaysReexecuteBlockProposals ||
|
|
364
|
-
this.blobClient.canUpload();
|
|
365
|
-
|
|
366
|
-
const validationResult = await this.blockProposalHandler.handleBlockProposal(
|
|
367
|
-
proposal,
|
|
368
|
-
proposalSender,
|
|
369
|
-
!!shouldReexecute && !escapeHatchOpen,
|
|
370
|
-
);
|
|
457
|
+
// Reexecute outside the escape hatch so slashing observers can detect invalid proposals even when penalties are 0.
|
|
458
|
+
const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !escapeHatchOpen);
|
|
371
459
|
|
|
372
460
|
if (!validationResult.isValid) {
|
|
373
|
-
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
374
|
-
|
|
375
461
|
const reason = validationResult.reason || 'unknown';
|
|
462
|
+
|
|
463
|
+
this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
|
|
464
|
+
|
|
376
465
|
// Classify failure reason: bad proposal vs node issue
|
|
377
466
|
const badProposalReasons: BlockProposalValidationFailureReason[] = [
|
|
378
467
|
'invalid_proposal',
|
|
@@ -380,6 +469,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
380
469
|
'failed_txs',
|
|
381
470
|
'in_hash_mismatch',
|
|
382
471
|
'parent_block_wrong_slot',
|
|
472
|
+
'duplicate_txs',
|
|
473
|
+
'invalid_embedded_txs',
|
|
383
474
|
];
|
|
384
475
|
|
|
385
476
|
if (badProposalReasons.includes(reason as BlockProposalValidationFailureReason)) {
|
|
@@ -389,15 +480,18 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
389
480
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
390
481
|
}
|
|
391
482
|
|
|
392
|
-
// Slash invalid block proposals (can happen even when not in committee)
|
|
393
483
|
if (
|
|
394
484
|
!escapeHatchOpen &&
|
|
395
485
|
validationResult.reason &&
|
|
396
|
-
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
|
|
397
|
-
slashBroadcastedInvalidBlockPenalty > 0n
|
|
486
|
+
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
|
|
398
487
|
) {
|
|
399
|
-
this.log.
|
|
488
|
+
this.log.info(`Detected invalid block proposal offense`, {
|
|
489
|
+
...proposalInfo,
|
|
490
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
491
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL),
|
|
492
|
+
});
|
|
400
493
|
this.slashInvalidBlock(proposal);
|
|
494
|
+
this.markInvalidProposalSlot(proposal.slotNumber);
|
|
401
495
|
}
|
|
402
496
|
return false;
|
|
403
497
|
}
|
|
@@ -424,54 +518,59 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
424
518
|
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
425
519
|
*/
|
|
426
520
|
async attestToCheckpointProposal(
|
|
427
|
-
proposal:
|
|
521
|
+
proposal: ValidatedCheckpointProposalCore,
|
|
428
522
|
_proposalSender: PeerId,
|
|
429
523
|
): Promise<CheckpointAttestation[] | undefined> {
|
|
430
|
-
const
|
|
524
|
+
const proposalSlotNumber = proposal.slotNumber;
|
|
431
525
|
const proposer = proposal.getSender();
|
|
432
526
|
|
|
433
527
|
// If escape hatch is open for this slot's epoch, do not attest.
|
|
434
|
-
if (await this.epochCache.isEscapeHatchOpenAtSlot(
|
|
435
|
-
this.log.warn(`Escape hatch open for slot ${
|
|
528
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(proposalSlotNumber)) {
|
|
529
|
+
this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
|
|
436
530
|
return undefined;
|
|
437
531
|
}
|
|
438
532
|
|
|
439
|
-
//
|
|
440
|
-
if (!
|
|
441
|
-
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
533
|
+
// Early-out for equivocation: refuses if we've already attested to a higher slot.
|
|
534
|
+
if (!this.shouldAttestToSlot(proposalSlotNumber)) {
|
|
442
535
|
return undefined;
|
|
443
536
|
}
|
|
444
537
|
|
|
445
|
-
//
|
|
446
|
-
|
|
538
|
+
// Ignore proposals from ourselves (may happen in HA setups)
|
|
539
|
+
if (proposer && this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
540
|
+
this.log.debug(`Not attesting to block proposal from self for slot ${proposalSlotNumber}`, {
|
|
541
|
+
proposer: proposer.toString(),
|
|
542
|
+
proposalSlotNumber,
|
|
543
|
+
});
|
|
544
|
+
return undefined;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// Check that I have any address in the committee where this checkpoint will land before attesting
|
|
548
|
+
const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
|
|
447
549
|
const partOfCommittee = inCommittee.length > 0;
|
|
448
550
|
|
|
449
551
|
const proposalInfo = {
|
|
450
|
-
|
|
552
|
+
proposalSlotNumber,
|
|
451
553
|
archive: proposal.archive.toString(),
|
|
452
|
-
proposer: proposer
|
|
453
|
-
txCount: proposal.txHashes.length,
|
|
554
|
+
proposer: proposer?.toString(),
|
|
454
555
|
};
|
|
455
|
-
this.log.info(`Received checkpoint proposal for slot ${
|
|
556
|
+
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
456
557
|
...proposalInfo,
|
|
457
|
-
txHashes: proposal.txHashes.map(t => t.toString()),
|
|
458
558
|
fishermanMode: this.config.fishermanMode || false,
|
|
459
559
|
});
|
|
460
560
|
|
|
461
|
-
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
561
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
|
|
562
|
+
// Uses the cached result from the all-nodes callback if available (avoids double validation).
|
|
563
|
+
let checkpointNumber: CheckpointNumber;
|
|
462
564
|
if (this.config.skipCheckpointProposalValidation) {
|
|
463
|
-
this.log.warn(`Skipping checkpoint proposal validation for slot ${
|
|
565
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
566
|
+
checkpointNumber = CheckpointNumber(0);
|
|
464
567
|
} else {
|
|
465
|
-
const validationResult = await this.
|
|
568
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
466
569
|
if (!validationResult.isValid) {
|
|
467
570
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
468
571
|
return undefined;
|
|
469
572
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
// Upload blobs to filestore if we can (fire and forget)
|
|
473
|
-
if (this.blobClient.canUpload()) {
|
|
474
|
-
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
573
|
+
checkpointNumber = validationResult.checkpointNumber;
|
|
475
574
|
}
|
|
476
575
|
|
|
477
576
|
// Check that I have any address in current committee before attesting
|
|
@@ -482,14 +581,28 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
482
581
|
}
|
|
483
582
|
|
|
484
583
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
485
|
-
this.log.info(
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
584
|
+
this.log.info(
|
|
585
|
+
`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${proposalSlotNumber}`,
|
|
586
|
+
{
|
|
587
|
+
...proposalInfo,
|
|
588
|
+
inCommittee: partOfCommittee,
|
|
589
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
590
|
+
},
|
|
591
|
+
);
|
|
490
592
|
|
|
491
593
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
492
594
|
|
|
595
|
+
// Track epoch participation per attester: count each (attester, epoch) pair at most once
|
|
596
|
+
const proposalEpoch = getEpochAtSlot(proposalSlotNumber, this.epochCache.getL1Constants());
|
|
597
|
+
for (const attester of inCommittee) {
|
|
598
|
+
const key = attester.toString();
|
|
599
|
+
const lastEpoch = this.lastAttestedEpochByAttester.get(key);
|
|
600
|
+
if (lastEpoch === undefined || proposalEpoch > lastEpoch) {
|
|
601
|
+
this.lastAttestedEpochByAttester.set(key, proposalEpoch);
|
|
602
|
+
this.metrics.incAttestedEpochCount(attester);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
493
606
|
// Determine which validators should attest
|
|
494
607
|
let attestors: EthAddress[];
|
|
495
608
|
if (partOfCommittee) {
|
|
@@ -508,174 +621,62 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
508
621
|
|
|
509
622
|
if (this.config.fishermanMode) {
|
|
510
623
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
511
|
-
this.log.info(`Creating checkpoint attestations for slot ${
|
|
624
|
+
this.log.info(`Creating checkpoint attestations for slot ${proposalSlotNumber}`, {
|
|
512
625
|
...proposalInfo,
|
|
513
626
|
attestors: attestors.map(a => a.toString()),
|
|
514
627
|
});
|
|
515
628
|
return undefined;
|
|
516
629
|
}
|
|
517
630
|
|
|
518
|
-
return this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
private async createCheckpointAttestationsFromProposal(
|
|
522
|
-
proposal: CheckpointProposalCore,
|
|
523
|
-
attestors: EthAddress[] = [],
|
|
524
|
-
): Promise<CheckpointAttestation[]> {
|
|
525
|
-
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
526
|
-
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
527
|
-
return attestations;
|
|
631
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
|
|
528
632
|
}
|
|
529
633
|
|
|
530
634
|
/**
|
|
531
|
-
*
|
|
532
|
-
* @returns
|
|
635
|
+
* Checks if we should attest to a slot based on equivocation prevention rules.
|
|
636
|
+
* @returns true if we should attest, false if we should skip
|
|
533
637
|
*/
|
|
534
|
-
private
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
const timeoutSeconds = 10; // TODO(palla/mbps): This should map to the timetable settings
|
|
638
|
+
private shouldAttestToSlot(slotNumber: SlotNumber): boolean {
|
|
639
|
+
// If attestToEquivocatedProposals is true, always allow
|
|
640
|
+
if (this.config.attestToEquivocatedProposals) {
|
|
641
|
+
return true;
|
|
642
|
+
}
|
|
540
643
|
|
|
541
|
-
//
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
async () => {
|
|
546
|
-
await this.blockSource.syncImmediate();
|
|
547
|
-
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
548
|
-
},
|
|
549
|
-
`waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`,
|
|
550
|
-
timeoutSeconds,
|
|
551
|
-
0.5,
|
|
644
|
+
// Check if incoming slot is strictly greater than last attested
|
|
645
|
+
if (this.lastAttestedProposal && slotNumber <= this.lastAttestedProposal.slotNumber) {
|
|
646
|
+
this.log.warn(
|
|
647
|
+
`Refusing to process a proposal for slot ${slotNumber} given we already attested to a proposal for slot ${this.lastAttestedProposal.slotNumber}`,
|
|
552
648
|
);
|
|
553
|
-
|
|
554
|
-
if (err instanceof TimeoutError) {
|
|
555
|
-
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
556
|
-
return { isValid: false, reason: 'last_block_not_found' };
|
|
557
|
-
}
|
|
558
|
-
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
559
|
-
return { isValid: false, reason: 'block_fetch_error' };
|
|
649
|
+
return false;
|
|
560
650
|
}
|
|
561
651
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
return { isValid: false, reason: 'last_block_not_found' };
|
|
565
|
-
}
|
|
652
|
+
return true;
|
|
653
|
+
}
|
|
566
654
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
655
|
+
private async createCheckpointAttestationsFromProposal(
|
|
656
|
+
proposal: CheckpointProposalCore,
|
|
657
|
+
attestors: EthAddress[] = [],
|
|
658
|
+
checkpointNumber: CheckpointNumber,
|
|
659
|
+
): Promise<CheckpointAttestation[] | undefined> {
|
|
660
|
+
// Equivocation check: must happen right before signing to minimize the race window
|
|
661
|
+
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
662
|
+
return undefined;
|
|
572
663
|
}
|
|
573
664
|
|
|
574
|
-
this.
|
|
575
|
-
...proposalInfo,
|
|
576
|
-
blockNumbers: blocks.map(b => b.number),
|
|
577
|
-
});
|
|
578
|
-
|
|
579
|
-
// Get checkpoint constants from first block
|
|
580
|
-
const firstBlock = blocks[0];
|
|
581
|
-
const constants = this.extractCheckpointConstants(firstBlock);
|
|
582
|
-
const checkpointNumber = firstBlock.checkpointNumber;
|
|
583
|
-
|
|
584
|
-
// Get L1-to-L2 messages for this checkpoint
|
|
585
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
586
|
-
|
|
587
|
-
// Compute the previous checkpoint out hashes for the epoch.
|
|
588
|
-
// TODO: There can be a more efficient way to get the previous checkpoint out hashes without having to fetch the
|
|
589
|
-
// actual checkpoints and the blocks/txs in them.
|
|
590
|
-
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
591
|
-
const previousCheckpoints = (await this.blockSource.getCheckpointsForEpoch(epoch))
|
|
592
|
-
.filter(b => b.number < checkpointNumber)
|
|
593
|
-
.sort((a, b) => a.number - b.number);
|
|
594
|
-
const previousCheckpointOutHashes = previousCheckpoints.map(c => c.getCheckpointOutHash());
|
|
595
|
-
|
|
596
|
-
// Fork world state at the block before the first block
|
|
597
|
-
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
598
|
-
const fork = await this.worldState.fork(parentBlockNumber);
|
|
599
|
-
|
|
600
|
-
try {
|
|
601
|
-
// Create checkpoint builder with all existing blocks
|
|
602
|
-
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
|
|
603
|
-
checkpointNumber,
|
|
604
|
-
constants,
|
|
605
|
-
l1ToL2Messages,
|
|
606
|
-
previousCheckpointOutHashes,
|
|
607
|
-
fork,
|
|
608
|
-
blocks,
|
|
609
|
-
this.log.getBindings(),
|
|
610
|
-
);
|
|
611
|
-
|
|
612
|
-
// Complete the checkpoint to get computed values
|
|
613
|
-
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
614
|
-
|
|
615
|
-
// Compare checkpoint header with proposal
|
|
616
|
-
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
617
|
-
this.log.warn(`Checkpoint header mismatch`, {
|
|
618
|
-
...proposalInfo,
|
|
619
|
-
computed: computedCheckpoint.header.toInspect(),
|
|
620
|
-
proposal: proposal.checkpointHeader.toInspect(),
|
|
621
|
-
});
|
|
622
|
-
return { isValid: false, reason: 'checkpoint_header_mismatch' };
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
// Compare archive root with proposal
|
|
626
|
-
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
627
|
-
this.log.warn(`Archive root mismatch`, {
|
|
628
|
-
...proposalInfo,
|
|
629
|
-
computed: computedCheckpoint.archive.root.toString(),
|
|
630
|
-
proposal: proposal.archive.toString(),
|
|
631
|
-
});
|
|
632
|
-
return { isValid: false, reason: 'archive_mismatch' };
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
636
|
-
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
637
|
-
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
638
|
-
const computedEpochOutHash = accumulateCheckpointOutHashes([...previousCheckpointOutHashes, checkpointOutHash]);
|
|
639
|
-
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
640
|
-
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
641
|
-
this.log.warn(`Epoch out hash mismatch`, {
|
|
642
|
-
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
643
|
-
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
644
|
-
checkpointOutHash: checkpointOutHash.toString(),
|
|
645
|
-
previousCheckpointOutHashes: previousCheckpointOutHashes.map(h => h.toString()),
|
|
646
|
-
...proposalInfo,
|
|
647
|
-
});
|
|
648
|
-
return { isValid: false, reason: 'out_hash_mismatch' };
|
|
649
|
-
}
|
|
665
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
|
|
650
666
|
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
} finally {
|
|
654
|
-
await fork.close();
|
|
655
|
-
}
|
|
656
|
-
}
|
|
667
|
+
// Track the proposal we attested to (to prevent equivocation)
|
|
668
|
+
this.lastAttestedProposal = proposal;
|
|
657
669
|
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
*/
|
|
661
|
-
private extractCheckpointConstants(block: L2Block): CheckpointGlobalVariables {
|
|
662
|
-
const gv = block.header.globalVariables;
|
|
663
|
-
return {
|
|
664
|
-
chainId: gv.chainId,
|
|
665
|
-
version: gv.version,
|
|
666
|
-
slotNumber: gv.slotNumber,
|
|
667
|
-
coinbase: gv.coinbase,
|
|
668
|
-
feeRecipient: gv.feeRecipient,
|
|
669
|
-
gasFees: gv.gasFees,
|
|
670
|
-
};
|
|
670
|
+
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
671
|
+
return attestations;
|
|
671
672
|
}
|
|
672
673
|
|
|
673
674
|
/**
|
|
674
675
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
675
676
|
*/
|
|
676
|
-
|
|
677
|
+
protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
|
|
677
678
|
try {
|
|
678
|
-
const lastBlockHeader = await this.blockSource.
|
|
679
|
+
const lastBlockHeader = (await this.blockSource.getBlockData({ archive: proposal.archive }))?.header;
|
|
679
680
|
if (!lastBlockHeader) {
|
|
680
681
|
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
681
682
|
return;
|
|
@@ -688,7 +689,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
688
689
|
}
|
|
689
690
|
|
|
690
691
|
const blobFields = blocks.flatMap(b => b.toBlobFields());
|
|
691
|
-
const blobs: Blob[] = getBlobsPerL1Block(blobFields);
|
|
692
|
+
const blobs: Blob[] = await getBlobsPerL1Block(blobFields);
|
|
692
693
|
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
693
694
|
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
694
695
|
...proposalInfo,
|
|
@@ -708,12 +709,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
708
709
|
return;
|
|
709
710
|
}
|
|
710
711
|
|
|
711
|
-
// Trim the set if it's too big.
|
|
712
|
-
if (this.proposersOfInvalidBlocks.size > MAX_PROPOSERS_OF_INVALID_BLOCKS) {
|
|
713
|
-
// remove oldest proposer. `values` is guaranteed to be in insertion order.
|
|
714
|
-
this.proposersOfInvalidBlocks.delete(this.proposersOfInvalidBlocks.values().next().value!);
|
|
715
|
-
}
|
|
716
|
-
|
|
717
712
|
this.proposersOfInvalidBlocks.add(proposer.toString());
|
|
718
713
|
|
|
719
714
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
@@ -726,20 +721,148 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
726
721
|
]);
|
|
727
722
|
}
|
|
728
723
|
|
|
724
|
+
private handleInvalidCheckpointProposal(
|
|
725
|
+
proposal: CheckpointProposalCore,
|
|
726
|
+
result: CheckpointProposalValidationFailureResult,
|
|
727
|
+
proposalInfo: LogData,
|
|
728
|
+
): void {
|
|
729
|
+
if (!SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT[result.reason]) {
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
// The slot is already marked invalid by the all-nodes checkpoint handler that invokes this callback,
|
|
734
|
+
// so we only emit the proposer slash event here.
|
|
735
|
+
if (this.slashInvalidCheckpointProposal(proposal)) {
|
|
736
|
+
this.log.info(`Detected invalid checkpoint proposal offense`, {
|
|
737
|
+
...proposalInfo,
|
|
738
|
+
reason: result.reason,
|
|
739
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
740
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL),
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
private slashInvalidCheckpointProposal(proposal: CheckpointProposalCore): boolean {
|
|
746
|
+
const proposer = proposal.getSender();
|
|
747
|
+
if (!proposer) {
|
|
748
|
+
this.log.warn(`Cannot slash checkpoint proposal with invalid signature`, {
|
|
749
|
+
slotNumber: proposal.slotNumber,
|
|
750
|
+
archive: proposal.archive.toString(),
|
|
751
|
+
});
|
|
752
|
+
return false;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
const offenseType = OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL;
|
|
756
|
+
const offenseKey = `${proposer.toString()}:${offenseType}:${proposal.slotNumber}`;
|
|
757
|
+
if (!this.invalidCheckpointProposalOffenseKeys.addIfAbsent(offenseKey)) {
|
|
758
|
+
return false;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
762
|
+
{
|
|
763
|
+
validator: proposer,
|
|
764
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
765
|
+
offenseType,
|
|
766
|
+
epochOrSlot: BigInt(proposal.slotNumber),
|
|
767
|
+
},
|
|
768
|
+
]);
|
|
769
|
+
return true;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
private markInvalidProposalSlot(slotNumber: SlotNumber): void {
|
|
773
|
+
this.proposalHandler.markInvalidProposalSlot(slotNumber);
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
private handleCheckpointAttestation(attestation: CheckpointAttestation): void {
|
|
777
|
+
const slotNumber = attestation.slotNumber;
|
|
778
|
+
if (
|
|
779
|
+
!this.proposalHandler.hasInvalidProposals(slotNumber) ||
|
|
780
|
+
this.proposalHandler.hasProposalEquivocation(slotNumber)
|
|
781
|
+
) {
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
const attester = attestation.getSender();
|
|
786
|
+
if (!attester) {
|
|
787
|
+
this.log.warn(`Cannot slash checkpoint attestation with invalid signature`, {
|
|
788
|
+
slotNumber,
|
|
789
|
+
archive: attestation.archive.toString(),
|
|
790
|
+
});
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
this.slashAttestedToInvalidCheckpointProposal(slotNumber, attester);
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
private slashAttestedToInvalidCheckpointProposal(slotNumber: SlotNumber, attester: EthAddress): void {
|
|
798
|
+
const offenseKey = `${attester.toString()}:${OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL}:${slotNumber}`;
|
|
799
|
+
if (!this.badAttestationOffenseKeys.addIfAbsent(offenseKey)) {
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
this.log.info(`Detected attestation to invalid checkpoint proposal offense`, {
|
|
804
|
+
attester: attester.toString(),
|
|
805
|
+
slotNumber,
|
|
806
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
807
|
+
offenseType: getOffenseTypeName(OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL),
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
811
|
+
{
|
|
812
|
+
validator: attester,
|
|
813
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
814
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
815
|
+
epochOrSlot: BigInt(slotNumber),
|
|
816
|
+
},
|
|
817
|
+
]);
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Handle detection of an oversized block proposal: one whose index within its checkpoint lands at or
|
|
822
|
+
* beyond the consensus per-checkpoint block limit. A single signed proposal at an illegal index is
|
|
823
|
+
* self-contained evidence, so emit an invalid-block-proposal slash event for the proposer, deduped per
|
|
824
|
+
* (proposer, slot) since the p2p layer reports every oversized proposal it stores.
|
|
825
|
+
*/
|
|
826
|
+
private handleOversizedProposal(info: OversizedProposalInfo): void {
|
|
827
|
+
const { slot, proposer } = info;
|
|
828
|
+
const offenseType = OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL;
|
|
829
|
+
if (!this.oversizedProposalOffenseKeys.addIfAbsent(`${proposer.toString()}:${offenseType}:${slot}`)) {
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
this.log.info(`Detected oversized block proposal offense from ${proposer.toString()} at slot ${slot}`, {
|
|
834
|
+
proposer: proposer.toString(),
|
|
835
|
+
slot,
|
|
836
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
837
|
+
offenseType: getOffenseTypeName(offenseType),
|
|
838
|
+
});
|
|
839
|
+
|
|
840
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
841
|
+
{
|
|
842
|
+
validator: proposer,
|
|
843
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
844
|
+
offenseType,
|
|
845
|
+
epochOrSlot: BigInt(slot),
|
|
846
|
+
},
|
|
847
|
+
]);
|
|
848
|
+
}
|
|
849
|
+
|
|
729
850
|
/**
|
|
730
851
|
* Handle detection of a duplicate proposal (equivocation).
|
|
731
852
|
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
732
853
|
*/
|
|
733
854
|
private handleDuplicateProposal(info: DuplicateProposalInfo): void {
|
|
734
855
|
const { slot, proposer, type } = info;
|
|
856
|
+
this.proposalHandler.markProposalEquivocation(slot);
|
|
735
857
|
|
|
736
|
-
this.log.
|
|
858
|
+
this.log.info(`Detected duplicate ${type} proposal offense from ${proposer.toString()} at slot ${slot}`, {
|
|
737
859
|
proposer: proposer.toString(),
|
|
738
860
|
slot,
|
|
739
861
|
type,
|
|
862
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
863
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_PROPOSAL),
|
|
740
864
|
});
|
|
741
865
|
|
|
742
|
-
// Emit slash event
|
|
743
866
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
744
867
|
{
|
|
745
868
|
validator: proposer,
|
|
@@ -748,10 +871,42 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
748
871
|
epochOrSlot: BigInt(slot),
|
|
749
872
|
},
|
|
750
873
|
]);
|
|
874
|
+
|
|
875
|
+
this.emit(WANT_TO_CLEAR_SLASH_EVENT, [
|
|
876
|
+
{
|
|
877
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
878
|
+
epochOrSlot: BigInt(slot),
|
|
879
|
+
},
|
|
880
|
+
]);
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
* Handle detection of a duplicate attestation (equivocation).
|
|
885
|
+
* Emits a slash event when an attester signs attestations for different proposals at the same slot.
|
|
886
|
+
*/
|
|
887
|
+
private handleDuplicateAttestation(info: DuplicateAttestationInfo): void {
|
|
888
|
+
const { slot, attester } = info;
|
|
889
|
+
|
|
890
|
+
this.log.info(`Detected duplicate attestation offense from ${attester.toString()} at slot ${slot}`, {
|
|
891
|
+
attester: attester.toString(),
|
|
892
|
+
slot,
|
|
893
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
894
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_ATTESTATION),
|
|
895
|
+
});
|
|
896
|
+
|
|
897
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
898
|
+
{
|
|
899
|
+
validator: attester,
|
|
900
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
901
|
+
offenseType: OffenseType.DUPLICATE_ATTESTATION,
|
|
902
|
+
epochOrSlot: BigInt(slot),
|
|
903
|
+
},
|
|
904
|
+
]);
|
|
751
905
|
}
|
|
752
906
|
|
|
753
907
|
async createBlockProposal(
|
|
754
908
|
blockHeader: BlockHeader,
|
|
909
|
+
checkpointNumber: CheckpointNumber,
|
|
755
910
|
indexWithinCheckpoint: IndexWithinCheckpoint,
|
|
756
911
|
inHash: Fr,
|
|
757
912
|
archive: Fr,
|
|
@@ -759,17 +914,26 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
759
914
|
proposerAddress: EthAddress | undefined,
|
|
760
915
|
options: BlockProposalOptions = {},
|
|
761
916
|
): Promise<BlockProposal> {
|
|
762
|
-
//
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
917
|
+
// Validate that we're not creating a proposal for an older or equal position
|
|
918
|
+
if (this.lastProposedBlock) {
|
|
919
|
+
const lastSlot = this.lastProposedBlock.slotNumber;
|
|
920
|
+
const lastIndex = this.lastProposedBlock.indexWithinCheckpoint;
|
|
921
|
+
const newSlot = blockHeader.globalVariables.slotNumber;
|
|
922
|
+
|
|
923
|
+
if (newSlot < lastSlot || (newSlot === lastSlot && indexWithinCheckpoint <= lastIndex)) {
|
|
924
|
+
throw new Error(
|
|
925
|
+
`Cannot create block proposal for slot ${newSlot} index ${indexWithinCheckpoint}: ` +
|
|
926
|
+
`already proposed block for slot ${lastSlot} index ${lastIndex}`,
|
|
927
|
+
);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
767
930
|
|
|
768
931
|
this.log.info(
|
|
769
932
|
`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`,
|
|
770
933
|
);
|
|
771
934
|
const newProposal = await this.validationService.createBlockProposal(
|
|
772
935
|
blockHeader,
|
|
936
|
+
checkpointNumber,
|
|
773
937
|
indexWithinCheckpoint,
|
|
774
938
|
inHash,
|
|
775
939
|
archive,
|
|
@@ -777,28 +941,55 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
777
941
|
proposerAddress,
|
|
778
942
|
{
|
|
779
943
|
...options,
|
|
780
|
-
broadcastInvalidBlockProposal:
|
|
944
|
+
broadcastInvalidBlockProposal:
|
|
945
|
+
options.broadcastInvalidBlockProposal || this.config.broadcastInvalidBlockProposal,
|
|
781
946
|
},
|
|
782
947
|
);
|
|
783
|
-
this.
|
|
948
|
+
this.lastProposedBlock = newProposal;
|
|
784
949
|
return newProposal;
|
|
785
950
|
}
|
|
786
951
|
|
|
787
952
|
async createCheckpointProposal(
|
|
788
953
|
checkpointHeader: CheckpointHeader,
|
|
789
954
|
archive: Fr,
|
|
790
|
-
|
|
955
|
+
checkpointNumber: CheckpointNumber,
|
|
956
|
+
feeAssetPriceModifier: bigint,
|
|
957
|
+
lastBlockProposal: BlockProposal | undefined,
|
|
791
958
|
proposerAddress: EthAddress | undefined,
|
|
792
959
|
options: CheckpointProposalOptions = {},
|
|
793
960
|
): Promise<CheckpointProposal> {
|
|
961
|
+
// Validate that we're not creating a proposal for an older or equal slot
|
|
962
|
+
if (this.lastProposedCheckpoint) {
|
|
963
|
+
const lastSlot = this.lastProposedCheckpoint.slotNumber;
|
|
964
|
+
const newSlot = checkpointHeader.slotNumber;
|
|
965
|
+
|
|
966
|
+
if (newSlot <= lastSlot) {
|
|
967
|
+
throw new Error(
|
|
968
|
+
`Cannot create checkpoint proposal for slot ${newSlot}: ` +
|
|
969
|
+
`already proposed checkpoint for slot ${lastSlot}`,
|
|
970
|
+
);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
|
|
794
974
|
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
795
|
-
|
|
975
|
+
const newProposal = await this.validationService.createCheckpointProposal(
|
|
796
976
|
checkpointHeader,
|
|
797
977
|
archive,
|
|
798
|
-
|
|
978
|
+
checkpointNumber,
|
|
979
|
+
feeAssetPriceModifier,
|
|
980
|
+
lastBlockProposal,
|
|
799
981
|
proposerAddress,
|
|
800
982
|
options,
|
|
801
983
|
);
|
|
984
|
+
this.lastProposedCheckpoint = newProposal;
|
|
985
|
+
// Self-record this slot's outcome on the re-execution tracker. Proposers don't run their
|
|
986
|
+
// own proposals through `handleCheckpointProposal`, so without this call the proposer's
|
|
987
|
+
// sentinel would see no outcome for slots it proposed and would mis-attribute itself as
|
|
988
|
+
// inactive. We pass the locally-computed `archive` (not `newProposal.archive`, which may
|
|
989
|
+
// be intentionally corrupted under test-only flags); from the proposer's local-view
|
|
990
|
+
// perspective the work it just completed is valid by definition.
|
|
991
|
+
this.proposalHandler.recordOwnCheckpointProposalAsValid(checkpointHeader.slotNumber, archive, checkpointNumber);
|
|
992
|
+
return newProposal;
|
|
802
993
|
}
|
|
803
994
|
|
|
804
995
|
async broadcastBlockProposal(proposal: BlockProposal): Promise<void> {
|
|
@@ -809,16 +1000,28 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
809
1000
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
810
1001
|
proposer: EthAddress,
|
|
811
1002
|
slot: SlotNumber,
|
|
812
|
-
|
|
1003
|
+
checkpointNumber: CheckpointNumber,
|
|
813
1004
|
): Promise<Signature> {
|
|
814
|
-
return await this.validationService.signAttestationsAndSigners(
|
|
1005
|
+
return await this.validationService.signAttestationsAndSigners(
|
|
1006
|
+
attestationsAndSigners,
|
|
1007
|
+
proposer,
|
|
1008
|
+
slot,
|
|
1009
|
+
checkpointNumber,
|
|
1010
|
+
);
|
|
815
1011
|
}
|
|
816
1012
|
|
|
817
|
-
async collectOwnAttestations(
|
|
1013
|
+
async collectOwnAttestations(
|
|
1014
|
+
proposal: CheckpointProposal,
|
|
1015
|
+
checkpointNumber: CheckpointNumber,
|
|
1016
|
+
): Promise<CheckpointAttestation[]> {
|
|
818
1017
|
const slot = proposal.slotNumber;
|
|
819
1018
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
820
1019
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, { inCommittee });
|
|
821
|
-
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
1020
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
|
|
1021
|
+
|
|
1022
|
+
if (!attestations) {
|
|
1023
|
+
return [];
|
|
1024
|
+
}
|
|
822
1025
|
|
|
823
1026
|
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
824
1027
|
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
@@ -833,6 +1036,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
833
1036
|
proposal: CheckpointProposal,
|
|
834
1037
|
required: number,
|
|
835
1038
|
deadline: Date,
|
|
1039
|
+
checkpointNumber: CheckpointNumber,
|
|
836
1040
|
): Promise<CheckpointAttestation[]> {
|
|
837
1041
|
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
838
1042
|
const slot = proposal.slotNumber;
|
|
@@ -845,33 +1049,23 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
845
1049
|
throw new AttestationTimeoutError(0, required, slot);
|
|
846
1050
|
}
|
|
847
1051
|
|
|
848
|
-
await this.collectOwnAttestations(proposal);
|
|
1052
|
+
await this.collectOwnAttestations(proposal, checkpointNumber);
|
|
849
1053
|
|
|
850
|
-
const
|
|
1054
|
+
const proposalPayloadHash = proposal.getPayloadHash();
|
|
851
1055
|
const myAddresses = this.getValidatorAddresses();
|
|
852
1056
|
|
|
853
1057
|
let attestations: CheckpointAttestation[] = [];
|
|
854
1058
|
while (true) {
|
|
855
|
-
//
|
|
856
|
-
//
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
if (!attestation.archive.equals(proposal.archive)) {
|
|
860
|
-
this.log.warn(
|
|
861
|
-
`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`,
|
|
862
|
-
{ attestationArchive: attestation.archive.toString(), proposalArchive: proposal.archive.toString() },
|
|
863
|
-
);
|
|
864
|
-
return false;
|
|
865
|
-
}
|
|
866
|
-
return true;
|
|
867
|
-
},
|
|
868
|
-
);
|
|
1059
|
+
// The pool already filters by proposal payload hash; if any attestation slips through with a
|
|
1060
|
+
// mismatched payload hash, drop it defensively. Equivocations are emitted as separate slash
|
|
1061
|
+
// events from libp2p_service.
|
|
1062
|
+
const collectedAttestations = await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalPayloadHash);
|
|
869
1063
|
|
|
870
1064
|
// Log new attestations we collected
|
|
871
1065
|
const oldSenders = attestations.map(attestation => attestation.getSender());
|
|
872
1066
|
for (const collected of collectedAttestations) {
|
|
873
1067
|
const collectedSender = collected.getSender();
|
|
874
|
-
// Skip attestations with invalid signatures
|
|
1068
|
+
// Skip attestations with invalid signatures. Should not happen as we don't add invalid attestations to our pool.
|
|
875
1069
|
if (!collectedSender) {
|
|
876
1070
|
this.log.warn(`Skipping attestation with invalid signature for slot ${slot}`);
|
|
877
1071
|
continue;
|