@aztec/validator-client 0.0.1-commit.9b94fc1 → 0.0.1-commit.9badcec54
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 +324 -0
- package/dest/checkpoint_builder.d.ts +79 -0
- package/dest/checkpoint_builder.d.ts.map +1 -0
- package/dest/checkpoint_builder.js +251 -0
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +37 -13
- package/dest/duties/validation_service.d.ts +40 -13
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +93 -28
- package/dest/factory.d.ts +19 -11
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +6 -5
- package/dest/index.d.ts +3 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -1
- package/dest/key_store/ha_key_store.d.ts +99 -0
- package/dest/key_store/ha_key_store.d.ts.map +1 -0
- package/dest/key_store/ha_key_store.js +208 -0
- package/dest/key_store/index.d.ts +2 -1
- package/dest/key_store/index.d.ts.map +1 -1
- package/dest/key_store/index.js +1 -0
- package/dest/key_store/interface.d.ts +36 -6
- package/dest/key_store/interface.d.ts.map +1 -1
- package/dest/key_store/local_key_store.d.ts +10 -5
- package/dest/key_store/local_key_store.d.ts.map +1 -1
- package/dest/key_store/local_key_store.js +9 -5
- package/dest/key_store/node_keystore_adapter.d.ts +18 -5
- package/dest/key_store/node_keystore_adapter.d.ts.map +1 -1
- package/dest/key_store/node_keystore_adapter.js +18 -4
- package/dest/key_store/web3signer_key_store.d.ts +10 -5
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
- package/dest/key_store/web3signer_key_store.js +9 -5
- package/dest/metrics.d.ts +16 -3
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +58 -30
- package/dest/proposal_handler.d.ts +108 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/proposal_handler.js +974 -0
- package/dest/validator.d.ts +73 -23
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +318 -65
- package/package.json +23 -13
- package/src/checkpoint_builder.ts +417 -0
- package/src/config.ts +36 -12
- package/src/duties/validation_service.ts +143 -33
- package/src/factory.ts +27 -11
- package/src/index.ts +2 -1
- package/src/key_store/ha_key_store.ts +269 -0
- package/src/key_store/index.ts +1 -0
- package/src/key_store/interface.ts +44 -5
- package/src/key_store/local_key_store.ts +14 -5
- package/src/key_store/node_keystore_adapter.ts +28 -5
- package/src/key_store/web3signer_key_store.ts +18 -5
- package/src/metrics.ts +81 -33
- package/src/proposal_handler.ts +1042 -0
- package/src/validator.ts +493 -101
- package/dest/block_proposal_handler.d.ts +0 -52
- package/dest/block_proposal_handler.d.ts.map +0 -1
- package/dest/block_proposal_handler.js +0 -290
- package/src/block_proposal_handler.ts +0 -341
package/src/validator.ts
CHANGED
|
@@ -1,33 +1,58 @@
|
|
|
1
|
+
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
2
|
+
import { type Blob, getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
1
3
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
-
import { EpochNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { CheckpointNumber, EpochNumber, IndexWithinCheckpoint, SlotNumber } from '@aztec/foundation/branded-types';
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
6
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
7
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
5
|
-
import {
|
|
6
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
8
|
+
import { type LogData, type Logger, createLogger } from '@aztec/foundation/log';
|
|
7
9
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
8
10
|
import { sleep } from '@aztec/foundation/sleep';
|
|
9
11
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
10
12
|
import type { KeystoreManager } from '@aztec/node-keystore';
|
|
11
|
-
import type { P2P, PeerId
|
|
13
|
+
import type { DuplicateAttestationInfo, DuplicateProposalInfo, P2P, PeerId } from '@aztec/p2p';
|
|
12
14
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
13
15
|
import { OffenseType, WANT_TO_SLASH_EVENT, type Watcher, type WatcherEmitter } from '@aztec/slasher';
|
|
14
16
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
|
-
import type { CommitteeAttestationsAndSigners, L2BlockSource } from '@aztec/stdlib/block';
|
|
16
|
-
import
|
|
17
|
+
import type { CommitteeAttestationsAndSigners, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
18
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
19
|
+
import type {
|
|
20
|
+
ITxProvider,
|
|
21
|
+
Validator,
|
|
22
|
+
ValidatorClientFullConfig,
|
|
23
|
+
WorldStateSynchronizer,
|
|
24
|
+
} from '@aztec/stdlib/interfaces/server';
|
|
17
25
|
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
18
|
-
import
|
|
26
|
+
import {
|
|
27
|
+
type BlockProposal,
|
|
28
|
+
type BlockProposalOptions,
|
|
29
|
+
type CheckpointAttestation,
|
|
30
|
+
CheckpointProposal,
|
|
31
|
+
type CheckpointProposalCore,
|
|
32
|
+
type CheckpointProposalOptions,
|
|
33
|
+
} from '@aztec/stdlib/p2p';
|
|
19
34
|
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
20
|
-
import type { Tx } from '@aztec/stdlib/tx';
|
|
35
|
+
import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
|
|
21
36
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
22
37
|
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
38
|
+
import {
|
|
39
|
+
createHASigner,
|
|
40
|
+
createLocalSignerWithProtection,
|
|
41
|
+
createSignerFromSharedDb,
|
|
42
|
+
} from '@aztec/validator-ha-signer/factory';
|
|
43
|
+
import { DutyType, type SigningContext, type SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
44
|
+
import type { ValidatorHASigner } from '@aztec/validator-ha-signer/validator-ha-signer';
|
|
23
45
|
|
|
24
46
|
import { EventEmitter } from 'events';
|
|
25
47
|
import type { TypedDataDefinition } from 'viem';
|
|
26
48
|
|
|
27
|
-
import {
|
|
49
|
+
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
28
50
|
import { ValidationService } from './duties/validation_service.js';
|
|
51
|
+
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
52
|
+
import type { ExtendedValidatorKeyStore } from './key_store/interface.js';
|
|
29
53
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
30
54
|
import { ValidatorMetrics } from './metrics.js';
|
|
55
|
+
import { type BlockProposalValidationFailureReason, ProposalHandler } from './proposal_handler.js';
|
|
31
56
|
|
|
32
57
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
33
58
|
// Just cap the set to avoid unbounded growth.
|
|
@@ -47,24 +72,37 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
47
72
|
private validationService: ValidationService;
|
|
48
73
|
private metrics: ValidatorMetrics;
|
|
49
74
|
private log: Logger;
|
|
50
|
-
|
|
51
75
|
// Whether it has already registered handlers on the p2p client
|
|
52
76
|
private hasRegisteredHandlers = false;
|
|
53
77
|
|
|
54
|
-
|
|
55
|
-
private
|
|
78
|
+
/** Tracks the last block proposal we created, to detect duplicate proposal attempts. */
|
|
79
|
+
private lastProposedBlock?: BlockProposal;
|
|
80
|
+
|
|
81
|
+
/** Tracks the last checkpoint proposal we created. */
|
|
82
|
+
private lastProposedCheckpoint?: CheckpointProposal;
|
|
56
83
|
|
|
57
84
|
private lastEpochForCommitteeUpdateLoop: EpochNumber | undefined;
|
|
58
85
|
private epochCacheUpdateLoop: RunningPromise;
|
|
86
|
+
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */
|
|
87
|
+
private lastAttestedEpochByAttester: Map<string, EpochNumber> = new Map();
|
|
59
88
|
|
|
60
89
|
private proposersOfInvalidBlocks: Set<string> = new Set();
|
|
61
90
|
|
|
91
|
+
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */
|
|
92
|
+
private lastAttestedProposal?: CheckpointProposalCore;
|
|
93
|
+
|
|
62
94
|
protected constructor(
|
|
63
|
-
private keyStore:
|
|
95
|
+
private keyStore: ExtendedValidatorKeyStore,
|
|
64
96
|
private epochCache: EpochCache,
|
|
65
97
|
private p2pClient: P2P,
|
|
66
|
-
private
|
|
98
|
+
private proposalHandler: ProposalHandler,
|
|
99
|
+
private blockSource: L2BlockSource,
|
|
100
|
+
private checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
101
|
+
private worldState: WorldStateSynchronizer,
|
|
102
|
+
private l1ToL2MessageSource: L1ToL2MessageSource,
|
|
67
103
|
private config: ValidatorClientFullConfig,
|
|
104
|
+
private blobClient: BlobClientInterface,
|
|
105
|
+
private slashingProtectionSigner: ValidatorHASigner,
|
|
68
106
|
private dateProvider: DateProvider = new DateProvider(),
|
|
69
107
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
70
108
|
log = createLogger('validator'),
|
|
@@ -118,6 +156,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
118
156
|
this.log.trace(`No committee found for slot`);
|
|
119
157
|
return;
|
|
120
158
|
}
|
|
159
|
+
this.metrics.setCurrentEpoch(epoch);
|
|
121
160
|
if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
|
|
122
161
|
const me = this.getValidatorAddresses();
|
|
123
162
|
const committeeSet = new Set(committee.map(v => v.toString()));
|
|
@@ -138,40 +177,83 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
138
177
|
}
|
|
139
178
|
}
|
|
140
179
|
|
|
141
|
-
static new(
|
|
180
|
+
static async new(
|
|
142
181
|
config: ValidatorClientFullConfig,
|
|
143
|
-
|
|
182
|
+
checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
183
|
+
worldState: WorldStateSynchronizer,
|
|
144
184
|
epochCache: EpochCache,
|
|
145
185
|
p2pClient: P2P,
|
|
146
|
-
blockSource: L2BlockSource,
|
|
186
|
+
blockSource: L2BlockSource & L2BlockSink,
|
|
147
187
|
l1ToL2MessageSource: L1ToL2MessageSource,
|
|
148
|
-
txProvider:
|
|
188
|
+
txProvider: ITxProvider,
|
|
149
189
|
keyStoreManager: KeystoreManager,
|
|
190
|
+
blobClient: BlobClientInterface,
|
|
150
191
|
dateProvider: DateProvider = new DateProvider(),
|
|
151
192
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
193
|
+
slashingProtectionDb?: SlashingProtectionDatabase,
|
|
152
194
|
) {
|
|
153
195
|
const metrics = new ValidatorMetrics(telemetry);
|
|
154
196
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
155
197
|
txsPermitted: !config.disableTransactions,
|
|
198
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock,
|
|
156
199
|
});
|
|
157
|
-
const
|
|
158
|
-
|
|
200
|
+
const proposalHandler = new ProposalHandler(
|
|
201
|
+
checkpointsBuilder,
|
|
202
|
+
worldState,
|
|
159
203
|
blockSource,
|
|
160
204
|
l1ToL2MessageSource,
|
|
161
205
|
txProvider,
|
|
162
206
|
blockProposalValidator,
|
|
207
|
+
epochCache,
|
|
163
208
|
config,
|
|
209
|
+
blobClient,
|
|
164
210
|
metrics,
|
|
165
211
|
dateProvider,
|
|
166
212
|
telemetry,
|
|
213
|
+
undefined,
|
|
167
214
|
);
|
|
168
215
|
|
|
216
|
+
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
217
|
+
let slashingProtectionSigner: ValidatorHASigner;
|
|
218
|
+
if (slashingProtectionDb) {
|
|
219
|
+
// Shared database mode: use a pre-existing database (e.g. for testing HA setups).
|
|
220
|
+
({ signer: slashingProtectionSigner } = createSignerFromSharedDb(slashingProtectionDb, config, {
|
|
221
|
+
telemetryClient: telemetry,
|
|
222
|
+
dateProvider,
|
|
223
|
+
}));
|
|
224
|
+
} else if (config.haSigningEnabled) {
|
|
225
|
+
// Multi-node HA mode: use PostgreSQL-backed distributed locking.
|
|
226
|
+
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
227
|
+
const haConfig = {
|
|
228
|
+
...config,
|
|
229
|
+
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000,
|
|
230
|
+
};
|
|
231
|
+
({ signer: slashingProtectionSigner } = await createHASigner(haConfig, {
|
|
232
|
+
telemetryClient: telemetry,
|
|
233
|
+
dateProvider,
|
|
234
|
+
}));
|
|
235
|
+
} else {
|
|
236
|
+
// Single-node mode: use LMDB-backed local signing protection.
|
|
237
|
+
// This prevents double-signing if the node crashes and restarts mid-proposal.
|
|
238
|
+
({ signer: slashingProtectionSigner } = await createLocalSignerWithProtection(config, {
|
|
239
|
+
telemetryClient: telemetry,
|
|
240
|
+
dateProvider,
|
|
241
|
+
}));
|
|
242
|
+
}
|
|
243
|
+
const validatorKeyStore: ExtendedValidatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, slashingProtectionSigner);
|
|
244
|
+
|
|
169
245
|
const validator = new ValidatorClient(
|
|
170
|
-
|
|
246
|
+
validatorKeyStore,
|
|
171
247
|
epochCache,
|
|
172
248
|
p2pClient,
|
|
173
|
-
|
|
249
|
+
proposalHandler,
|
|
250
|
+
blockSource,
|
|
251
|
+
checkpointsBuilder,
|
|
252
|
+
worldState,
|
|
253
|
+
l1ToL2MessageSource,
|
|
174
254
|
config,
|
|
255
|
+
blobClient,
|
|
256
|
+
slashingProtectionSigner,
|
|
175
257
|
dateProvider,
|
|
176
258
|
telemetry,
|
|
177
259
|
);
|
|
@@ -185,22 +267,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
185
267
|
.filter(addr => !this.config.disabledValidators.some(disabled => disabled.equals(addr)));
|
|
186
268
|
}
|
|
187
269
|
|
|
188
|
-
public
|
|
189
|
-
return this.
|
|
270
|
+
public getProposalHandler() {
|
|
271
|
+
return this.proposalHandler;
|
|
190
272
|
}
|
|
191
273
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
proposal: BlockProposal,
|
|
195
|
-
blockNumber: number,
|
|
196
|
-
txs: any[],
|
|
197
|
-
l1ToL2Messages: Fr[],
|
|
198
|
-
): Promise<any> {
|
|
199
|
-
return this.blockProposalHandler.reexecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
public signWithAddress(addr: EthAddress, msg: TypedDataDefinition) {
|
|
203
|
-
return this.keyStore.signTypedDataWithAddress(addr, msg);
|
|
274
|
+
public signWithAddress(addr: EthAddress, msg: TypedDataDefinition, context: SigningContext) {
|
|
275
|
+
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
204
276
|
}
|
|
205
277
|
|
|
206
278
|
public getCoinbaseForAttestor(attestor: EthAddress): EthAddress {
|
|
@@ -219,12 +291,20 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
219
291
|
this.config = { ...this.config, ...config };
|
|
220
292
|
}
|
|
221
293
|
|
|
294
|
+
public reloadKeystore(newManager: KeystoreManager): void {
|
|
295
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
296
|
+
this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
|
|
297
|
+
this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
|
|
298
|
+
}
|
|
299
|
+
|
|
222
300
|
public async start() {
|
|
223
301
|
if (this.epochCacheUpdateLoop.isRunning()) {
|
|
224
302
|
this.log.warn(`Validator client already started`);
|
|
225
303
|
return;
|
|
226
304
|
}
|
|
227
305
|
|
|
306
|
+
await this.keyStore.start();
|
|
307
|
+
|
|
228
308
|
await this.registerHandlers();
|
|
229
309
|
|
|
230
310
|
const myAddresses = this.getValidatorAddresses();
|
|
@@ -240,6 +320,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
240
320
|
|
|
241
321
|
public async stop() {
|
|
242
322
|
await this.epochCacheUpdateLoop.stop();
|
|
323
|
+
await this.keyStore.stop();
|
|
243
324
|
}
|
|
244
325
|
|
|
245
326
|
/** Register handlers on the p2p client */
|
|
@@ -248,9 +329,29 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
248
329
|
this.hasRegisteredHandlers = true;
|
|
249
330
|
this.log.debug(`Registering validator handlers for p2p client`);
|
|
250
331
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
332
|
+
// Block proposal handler - validates but does NOT attest (validators only attest to checkpoints)
|
|
333
|
+
const blockHandler = (block: BlockProposal, proposalSender: PeerId): Promise<boolean> =>
|
|
334
|
+
this.validateBlockProposal(block, proposalSender);
|
|
335
|
+
this.p2pClient.registerBlockProposalHandler(blockHandler);
|
|
336
|
+
|
|
337
|
+
// Checkpoint proposal handler - validates and creates attestations
|
|
338
|
+
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
339
|
+
// and processed separately via the block handler above.
|
|
340
|
+
const checkpointHandler = (
|
|
341
|
+
checkpoint: CheckpointProposalCore,
|
|
342
|
+
proposalSender: PeerId,
|
|
343
|
+
): Promise<CheckpointAttestation[] | undefined> => this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
344
|
+
this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
|
|
345
|
+
|
|
346
|
+
// Duplicate proposal handler - triggers slashing for equivocation
|
|
347
|
+
this.p2pClient.registerDuplicateProposalCallback((info: DuplicateProposalInfo) => {
|
|
348
|
+
this.handleDuplicateProposal(info);
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
// Duplicate attestation handler - triggers slashing for attestation equivocation
|
|
352
|
+
this.p2pClient.registerDuplicateAttestationCallback((info: DuplicateAttestationInfo) => {
|
|
353
|
+
this.handleDuplicateAttestation(info);
|
|
354
|
+
});
|
|
254
355
|
|
|
255
356
|
const myAddresses = this.getValidatorAddresses();
|
|
256
357
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
@@ -259,48 +360,66 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
259
360
|
}
|
|
260
361
|
}
|
|
261
362
|
|
|
262
|
-
|
|
363
|
+
/**
|
|
364
|
+
* Validate a block proposal from a peer.
|
|
365
|
+
* Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
|
|
366
|
+
* @returns true if the proposal is valid, false otherwise
|
|
367
|
+
*/
|
|
368
|
+
async validateBlockProposal(proposal: BlockProposal, proposalSender: PeerId): Promise<boolean> {
|
|
263
369
|
const slotNumber = proposal.slotNumber;
|
|
370
|
+
|
|
371
|
+
// Note: During escape hatch, we still want to "validate" proposals for observability,
|
|
372
|
+
// but we intentionally reject them and disable slashing invalid block and attestation flow.
|
|
373
|
+
const escapeHatchOpen = await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber);
|
|
374
|
+
|
|
264
375
|
const proposer = proposal.getSender();
|
|
265
376
|
|
|
266
377
|
// Reject proposals with invalid signatures
|
|
267
378
|
if (!proposer) {
|
|
268
|
-
this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
|
|
269
|
-
return
|
|
379
|
+
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
380
|
+
return false;
|
|
270
381
|
}
|
|
271
382
|
|
|
272
|
-
//
|
|
383
|
+
// Log self-proposals from HA peers (same validator key on different nodes)
|
|
384
|
+
if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
385
|
+
this.log.verbose(`Processing block proposal from HA peer for slot ${slotNumber}`, {
|
|
386
|
+
proposer: proposer.toString(),
|
|
387
|
+
slotNumber,
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// Check if we're in the committee (for metrics purposes)
|
|
273
392
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
274
393
|
const partOfCommittee = inCommittee.length > 0;
|
|
275
394
|
|
|
276
395
|
const proposalInfo = { ...proposal.toBlockInfo(), proposer: proposer.toString() };
|
|
277
|
-
this.log.info(`Received proposal for slot ${slotNumber}`, {
|
|
396
|
+
this.log.info(`Received block proposal for slot ${slotNumber}`, {
|
|
278
397
|
...proposalInfo,
|
|
279
398
|
txHashes: proposal.txHashes.map(t => t.toString()),
|
|
280
399
|
fishermanMode: this.config.fishermanMode || false,
|
|
281
400
|
});
|
|
282
401
|
|
|
283
|
-
// Reexecute txs if we are part of the committee
|
|
284
|
-
// invalid proposals even when not in the committee, or if we are configured to always reexecute for monitoring purposes.
|
|
402
|
+
// Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
|
|
285
403
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
286
|
-
const {
|
|
287
|
-
this.config;
|
|
404
|
+
const { slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
288
405
|
const shouldReexecute =
|
|
289
406
|
fishermanMode ||
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
alwaysReexecuteBlockProposals
|
|
407
|
+
slashBroadcastedInvalidBlockPenalty > 0n ||
|
|
408
|
+
partOfCommittee ||
|
|
409
|
+
alwaysReexecuteBlockProposals ||
|
|
410
|
+
this.blobClient.canUpload();
|
|
293
411
|
|
|
294
|
-
const validationResult = await this.
|
|
412
|
+
const validationResult = await this.proposalHandler.handleBlockProposal(
|
|
295
413
|
proposal,
|
|
296
414
|
proposalSender,
|
|
297
|
-
!!shouldReexecute,
|
|
415
|
+
!!shouldReexecute && !escapeHatchOpen,
|
|
298
416
|
);
|
|
299
417
|
|
|
300
418
|
if (!validationResult.isValid) {
|
|
301
|
-
this.log.warn(`Proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
302
|
-
|
|
303
419
|
const reason = validationResult.reason || 'unknown';
|
|
420
|
+
|
|
421
|
+
this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
|
|
422
|
+
|
|
304
423
|
// Classify failure reason: bad proposal vs node issue
|
|
305
424
|
const badProposalReasons: BlockProposalValidationFailureReason[] = [
|
|
306
425
|
'invalid_proposal',
|
|
@@ -313,12 +432,13 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
313
432
|
if (badProposalReasons.includes(reason as BlockProposalValidationFailureReason)) {
|
|
314
433
|
this.metrics.incFailedAttestationsBadProposal(1, reason, partOfCommittee);
|
|
315
434
|
} else {
|
|
316
|
-
// Node issues so we can't
|
|
435
|
+
// Node issues so we can't validate
|
|
317
436
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
318
437
|
}
|
|
319
438
|
|
|
320
439
|
// Slash invalid block proposals (can happen even when not in committee)
|
|
321
440
|
if (
|
|
441
|
+
!escapeHatchOpen &&
|
|
322
442
|
validationResult.reason &&
|
|
323
443
|
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) &&
|
|
324
444
|
slashBroadcastedInvalidBlockPenalty > 0n
|
|
@@ -326,9 +446,81 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
326
446
|
this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
|
|
327
447
|
this.slashInvalidBlock(proposal);
|
|
328
448
|
}
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
this.log.info(`Validated block proposal for slot ${slotNumber}`, {
|
|
453
|
+
...proposalInfo,
|
|
454
|
+
inCommittee: partOfCommittee,
|
|
455
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
456
|
+
escapeHatchOpen,
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
if (escapeHatchOpen) {
|
|
460
|
+
this.log.warn(`Escape hatch open for slot ${slotNumber}, rejecting block proposal`, proposalInfo);
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
return true;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Validate and attest to a checkpoint proposal from a peer.
|
|
469
|
+
* The proposal is received as CheckpointProposalCore (without lastBlock) since
|
|
470
|
+
* the lastBlock is extracted and processed separately via the block handler.
|
|
471
|
+
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
472
|
+
*/
|
|
473
|
+
async attestToCheckpointProposal(
|
|
474
|
+
proposal: CheckpointProposalCore,
|
|
475
|
+
_proposalSender: PeerId,
|
|
476
|
+
): Promise<CheckpointAttestation[] | undefined> {
|
|
477
|
+
const proposalSlotNumber = proposal.slotNumber;
|
|
478
|
+
const proposer = proposal.getSender();
|
|
479
|
+
|
|
480
|
+
// If escape hatch is open for this slot's epoch, do not attest.
|
|
481
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(proposalSlotNumber)) {
|
|
482
|
+
this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
|
|
329
483
|
return undefined;
|
|
330
484
|
}
|
|
331
485
|
|
|
486
|
+
// Ignore proposals from ourselves (may happen in HA setups)
|
|
487
|
+
if (proposer && this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
488
|
+
this.log.debug(`Ignoring block proposal from self for slot ${proposalSlotNumber}`, {
|
|
489
|
+
proposer: proposer.toString(),
|
|
490
|
+
proposalSlotNumber,
|
|
491
|
+
});
|
|
492
|
+
return undefined;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// Check that I have any address in the committee where this checkpoint will land before attesting
|
|
496
|
+
const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
|
|
497
|
+
const partOfCommittee = inCommittee.length > 0;
|
|
498
|
+
|
|
499
|
+
const proposalInfo = {
|
|
500
|
+
proposalSlotNumber,
|
|
501
|
+
archive: proposal.archive.toString(),
|
|
502
|
+
proposer: proposer?.toString(),
|
|
503
|
+
};
|
|
504
|
+
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
505
|
+
...proposalInfo,
|
|
506
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
|
|
510
|
+
// Uses the cached result from the all-nodes callback if available (avoids double validation).
|
|
511
|
+
let checkpointNumber: CheckpointNumber;
|
|
512
|
+
if (this.config.skipCheckpointProposalValidation) {
|
|
513
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
514
|
+
checkpointNumber = CheckpointNumber(0);
|
|
515
|
+
} else {
|
|
516
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
517
|
+
if (!validationResult.isValid) {
|
|
518
|
+
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
519
|
+
return undefined;
|
|
520
|
+
}
|
|
521
|
+
checkpointNumber = validationResult.checkpointNumber;
|
|
522
|
+
}
|
|
523
|
+
|
|
332
524
|
// Check that I have any address in current committee before attesting
|
|
333
525
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
334
526
|
if (!partOfCommittee && !this.config.fishermanMode) {
|
|
@@ -337,15 +529,28 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
337
529
|
}
|
|
338
530
|
|
|
339
531
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
340
|
-
this.log.info(
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
532
|
+
this.log.info(
|
|
533
|
+
`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${proposalSlotNumber}`,
|
|
534
|
+
{
|
|
535
|
+
...proposalInfo,
|
|
536
|
+
inCommittee: partOfCommittee,
|
|
537
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
538
|
+
},
|
|
539
|
+
);
|
|
345
540
|
|
|
346
541
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
347
542
|
|
|
348
|
-
//
|
|
543
|
+
// Track epoch participation per attester: count each (attester, epoch) pair at most once
|
|
544
|
+
const proposalEpoch = getEpochAtSlot(proposalSlotNumber, this.epochCache.getL1Constants());
|
|
545
|
+
for (const attester of inCommittee) {
|
|
546
|
+
const key = attester.toString();
|
|
547
|
+
const lastEpoch = this.lastAttestedEpochByAttester.get(key);
|
|
548
|
+
if (lastEpoch === undefined || proposalEpoch > lastEpoch) {
|
|
549
|
+
this.lastAttestedEpochByAttester.set(key, proposalEpoch);
|
|
550
|
+
this.metrics.incAttestedEpochCount(attester);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
349
554
|
// Determine which validators should attest
|
|
350
555
|
let attestors: EthAddress[];
|
|
351
556
|
if (partOfCommittee) {
|
|
@@ -364,13 +569,83 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
364
569
|
|
|
365
570
|
if (this.config.fishermanMode) {
|
|
366
571
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
367
|
-
this.log.info(`Creating attestations for
|
|
572
|
+
this.log.info(`Creating checkpoint attestations for slot ${proposalSlotNumber}`, {
|
|
368
573
|
...proposalInfo,
|
|
369
574
|
attestors: attestors.map(a => a.toString()),
|
|
370
575
|
});
|
|
371
576
|
return undefined;
|
|
372
577
|
}
|
|
373
|
-
|
|
578
|
+
|
|
579
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Checks if we should attest to a slot based on equivocation prevention rules.
|
|
584
|
+
* @returns true if we should attest, false if we should skip
|
|
585
|
+
*/
|
|
586
|
+
private shouldAttestToSlot(slotNumber: SlotNumber): boolean {
|
|
587
|
+
// If attestToEquivocatedProposals is true, always allow
|
|
588
|
+
if (this.config.attestToEquivocatedProposals) {
|
|
589
|
+
return true;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// Check if incoming slot is strictly greater than last attested
|
|
593
|
+
if (this.lastAttestedProposal && slotNumber <= this.lastAttestedProposal.slotNumber) {
|
|
594
|
+
this.log.warn(
|
|
595
|
+
`Refusing to process a proposal for slot ${slotNumber} given we already attested to a proposal for slot ${this.lastAttestedProposal.slotNumber}`,
|
|
596
|
+
);
|
|
597
|
+
return false;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
return true;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
private async createCheckpointAttestationsFromProposal(
|
|
604
|
+
proposal: CheckpointProposalCore,
|
|
605
|
+
attestors: EthAddress[] = [],
|
|
606
|
+
checkpointNumber: CheckpointNumber,
|
|
607
|
+
): Promise<CheckpointAttestation[] | undefined> {
|
|
608
|
+
// Equivocation check: must happen right before signing to minimize the race window
|
|
609
|
+
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
610
|
+
return undefined;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
|
|
614
|
+
|
|
615
|
+
// Track the proposal we attested to (to prevent equivocation)
|
|
616
|
+
this.lastAttestedProposal = proposal;
|
|
617
|
+
|
|
618
|
+
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
619
|
+
return attestations;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
624
|
+
*/
|
|
625
|
+
protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
|
|
626
|
+
try {
|
|
627
|
+
const lastBlockHeader = await this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
628
|
+
if (!lastBlockHeader) {
|
|
629
|
+
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
const blocks = await this.blockSource.getBlocksForSlot(proposal.slotNumber);
|
|
634
|
+
if (blocks.length === 0) {
|
|
635
|
+
this.log.warn(`No blocks found for blob upload`, proposalInfo);
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
const blobFields = blocks.flatMap(b => b.toBlobFields());
|
|
640
|
+
const blobs: Blob[] = await getBlobsPerL1Block(blobFields);
|
|
641
|
+
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
642
|
+
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
643
|
+
...proposalInfo,
|
|
644
|
+
numBlobs: blobs.length,
|
|
645
|
+
});
|
|
646
|
+
} catch (err) {
|
|
647
|
+
this.log.warn(`Failed to upload blobs for checkpoint: ${err}`, proposalInfo);
|
|
648
|
+
}
|
|
374
649
|
}
|
|
375
650
|
|
|
376
651
|
private slashInvalidBlock(proposal: BlockProposal) {
|
|
@@ -400,24 +675,129 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
400
675
|
]);
|
|
401
676
|
}
|
|
402
677
|
|
|
678
|
+
/**
|
|
679
|
+
* Handle detection of a duplicate proposal (equivocation).
|
|
680
|
+
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
681
|
+
*/
|
|
682
|
+
private handleDuplicateProposal(info: DuplicateProposalInfo): void {
|
|
683
|
+
const { slot, proposer, type } = info;
|
|
684
|
+
|
|
685
|
+
this.log.warn(`Triggering slash event for duplicate ${type} proposal from ${proposer.toString()} at slot ${slot}`, {
|
|
686
|
+
proposer: proposer.toString(),
|
|
687
|
+
slot,
|
|
688
|
+
type,
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
// Emit slash event
|
|
692
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
693
|
+
{
|
|
694
|
+
validator: proposer,
|
|
695
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
696
|
+
offenseType: OffenseType.DUPLICATE_PROPOSAL,
|
|
697
|
+
epochOrSlot: BigInt(slot),
|
|
698
|
+
},
|
|
699
|
+
]);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Handle detection of a duplicate attestation (equivocation).
|
|
704
|
+
* Emits a slash event when an attester signs attestations for different proposals at the same slot.
|
|
705
|
+
*/
|
|
706
|
+
private handleDuplicateAttestation(info: DuplicateAttestationInfo): void {
|
|
707
|
+
const { slot, attester } = info;
|
|
708
|
+
|
|
709
|
+
this.log.warn(`Triggering slash event for duplicate attestation from ${attester.toString()} at slot ${slot}`, {
|
|
710
|
+
attester: attester.toString(),
|
|
711
|
+
slot,
|
|
712
|
+
});
|
|
713
|
+
|
|
714
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
715
|
+
{
|
|
716
|
+
validator: attester,
|
|
717
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
718
|
+
offenseType: OffenseType.DUPLICATE_ATTESTATION,
|
|
719
|
+
epochOrSlot: BigInt(slot),
|
|
720
|
+
},
|
|
721
|
+
]);
|
|
722
|
+
}
|
|
723
|
+
|
|
403
724
|
async createBlockProposal(
|
|
404
|
-
|
|
405
|
-
|
|
725
|
+
blockHeader: BlockHeader,
|
|
726
|
+
checkpointNumber: CheckpointNumber,
|
|
727
|
+
indexWithinCheckpoint: IndexWithinCheckpoint,
|
|
728
|
+
inHash: Fr,
|
|
406
729
|
archive: Fr,
|
|
407
730
|
txs: Tx[],
|
|
408
731
|
proposerAddress: EthAddress | undefined,
|
|
409
|
-
options: BlockProposalOptions,
|
|
410
|
-
): Promise<BlockProposal
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
732
|
+
options: BlockProposalOptions = {},
|
|
733
|
+
): Promise<BlockProposal> {
|
|
734
|
+
// Validate that we're not creating a proposal for an older or equal position
|
|
735
|
+
if (this.lastProposedBlock) {
|
|
736
|
+
const lastSlot = this.lastProposedBlock.slotNumber;
|
|
737
|
+
const lastIndex = this.lastProposedBlock.indexWithinCheckpoint;
|
|
738
|
+
const newSlot = blockHeader.globalVariables.slotNumber;
|
|
739
|
+
|
|
740
|
+
if (newSlot < lastSlot || (newSlot === lastSlot && indexWithinCheckpoint <= lastIndex)) {
|
|
741
|
+
throw new Error(
|
|
742
|
+
`Cannot create block proposal for slot ${newSlot} index ${indexWithinCheckpoint}: ` +
|
|
743
|
+
`already proposed block for slot ${lastSlot} index ${lastIndex}`,
|
|
744
|
+
);
|
|
745
|
+
}
|
|
414
746
|
}
|
|
415
747
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
748
|
+
this.log.info(
|
|
749
|
+
`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`,
|
|
750
|
+
);
|
|
751
|
+
const newProposal = await this.validationService.createBlockProposal(
|
|
752
|
+
blockHeader,
|
|
753
|
+
checkpointNumber,
|
|
754
|
+
indexWithinCheckpoint,
|
|
755
|
+
inHash,
|
|
756
|
+
archive,
|
|
757
|
+
txs,
|
|
758
|
+
proposerAddress,
|
|
759
|
+
{
|
|
760
|
+
...options,
|
|
761
|
+
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal,
|
|
762
|
+
},
|
|
763
|
+
);
|
|
764
|
+
this.lastProposedBlock = newProposal;
|
|
765
|
+
return newProposal;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
async createCheckpointProposal(
|
|
769
|
+
checkpointHeader: CheckpointHeader,
|
|
770
|
+
archive: Fr,
|
|
771
|
+
checkpointNumber: CheckpointNumber,
|
|
772
|
+
feeAssetPriceModifier: bigint,
|
|
773
|
+
lastBlockProposal: BlockProposal | undefined,
|
|
774
|
+
proposerAddress: EthAddress | undefined,
|
|
775
|
+
options: CheckpointProposalOptions = {},
|
|
776
|
+
): Promise<CheckpointProposal> {
|
|
777
|
+
// Validate that we're not creating a proposal for an older or equal slot
|
|
778
|
+
if (this.lastProposedCheckpoint) {
|
|
779
|
+
const lastSlot = this.lastProposedCheckpoint.slotNumber;
|
|
780
|
+
const newSlot = checkpointHeader.slotNumber;
|
|
781
|
+
|
|
782
|
+
if (newSlot <= lastSlot) {
|
|
783
|
+
throw new Error(
|
|
784
|
+
`Cannot create checkpoint proposal for slot ${newSlot}: ` +
|
|
785
|
+
`already proposed checkpoint for slot ${lastSlot}`,
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
791
|
+
const newProposal = await this.validationService.createCheckpointProposal(
|
|
792
|
+
checkpointHeader,
|
|
793
|
+
archive,
|
|
794
|
+
checkpointNumber,
|
|
795
|
+
feeAssetPriceModifier,
|
|
796
|
+
lastBlockProposal,
|
|
797
|
+
proposerAddress,
|
|
798
|
+
options,
|
|
799
|
+
);
|
|
800
|
+
this.lastProposedCheckpoint = newProposal;
|
|
421
801
|
return newProposal;
|
|
422
802
|
}
|
|
423
803
|
|
|
@@ -428,28 +808,47 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
428
808
|
async signAttestationsAndSigners(
|
|
429
809
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
430
810
|
proposer: EthAddress,
|
|
811
|
+
slot: SlotNumber,
|
|
812
|
+
checkpointNumber: CheckpointNumber,
|
|
431
813
|
): Promise<Signature> {
|
|
432
|
-
return await this.validationService.signAttestationsAndSigners(
|
|
814
|
+
return await this.validationService.signAttestationsAndSigners(
|
|
815
|
+
attestationsAndSigners,
|
|
816
|
+
proposer,
|
|
817
|
+
slot,
|
|
818
|
+
checkpointNumber,
|
|
819
|
+
);
|
|
433
820
|
}
|
|
434
821
|
|
|
435
|
-
async collectOwnAttestations(
|
|
436
|
-
|
|
822
|
+
async collectOwnAttestations(
|
|
823
|
+
proposal: CheckpointProposal,
|
|
824
|
+
checkpointNumber: CheckpointNumber,
|
|
825
|
+
): Promise<CheckpointAttestation[]> {
|
|
826
|
+
const slot = proposal.slotNumber;
|
|
437
827
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
438
828
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, { inCommittee });
|
|
439
|
-
const attestations = await this.
|
|
829
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
|
|
830
|
+
|
|
831
|
+
if (!attestations) {
|
|
832
|
+
return [];
|
|
833
|
+
}
|
|
440
834
|
|
|
441
835
|
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
442
836
|
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
443
837
|
// due to inactivity for missed attestations.
|
|
444
|
-
void this.p2pClient.
|
|
838
|
+
void this.p2pClient.broadcastCheckpointAttestations(attestations).catch(err => {
|
|
445
839
|
this.log.error(`Failed to broadcast self-attestations for slot ${slot}`, err);
|
|
446
840
|
});
|
|
447
841
|
return attestations;
|
|
448
842
|
}
|
|
449
843
|
|
|
450
|
-
async collectAttestations(
|
|
451
|
-
|
|
452
|
-
|
|
844
|
+
async collectAttestations(
|
|
845
|
+
proposal: CheckpointProposal,
|
|
846
|
+
required: number,
|
|
847
|
+
deadline: Date,
|
|
848
|
+
checkpointNumber: CheckpointNumber,
|
|
849
|
+
): Promise<CheckpointAttestation[]> {
|
|
850
|
+
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
851
|
+
const slot = proposal.slotNumber;
|
|
453
852
|
this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
|
|
454
853
|
|
|
455
854
|
if (+deadline < this.dateProvider.now()) {
|
|
@@ -459,21 +858,21 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
459
858
|
throw new AttestationTimeoutError(0, required, slot);
|
|
460
859
|
}
|
|
461
860
|
|
|
462
|
-
await this.collectOwnAttestations(proposal);
|
|
861
|
+
await this.collectOwnAttestations(proposal, checkpointNumber);
|
|
463
862
|
|
|
464
863
|
const proposalId = proposal.archive.toString();
|
|
465
864
|
const myAddresses = this.getValidatorAddresses();
|
|
466
865
|
|
|
467
|
-
let attestations:
|
|
866
|
+
let attestations: CheckpointAttestation[] = [];
|
|
468
867
|
while (true) {
|
|
469
|
-
// Filter out attestations with a mismatching
|
|
868
|
+
// Filter out attestations with a mismatching archive. This should NOT happen since we have verified
|
|
470
869
|
// the proposer signature (ie our own) before accepting the attestation into the pool via the p2p client.
|
|
471
|
-
const collectedAttestations = (await this.p2pClient.
|
|
870
|
+
const collectedAttestations = (await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalId)).filter(
|
|
472
871
|
attestation => {
|
|
473
|
-
if (!attestation.
|
|
872
|
+
if (!attestation.archive.equals(proposal.archive)) {
|
|
474
873
|
this.log.warn(
|
|
475
|
-
`Received attestation for slot ${slot} with mismatched
|
|
476
|
-
{
|
|
874
|
+
`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`,
|
|
875
|
+
{ attestationArchive: attestation.archive.toString(), proposalArchive: proposal.archive.toString() },
|
|
477
876
|
);
|
|
478
877
|
return false;
|
|
479
878
|
}
|
|
@@ -514,15 +913,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
514
913
|
}
|
|
515
914
|
}
|
|
516
915
|
|
|
517
|
-
private async createBlockAttestationsFromProposal(
|
|
518
|
-
proposal: BlockProposal,
|
|
519
|
-
attestors: EthAddress[] = [],
|
|
520
|
-
): Promise<BlockAttestation[]> {
|
|
521
|
-
const attestations = await this.validationService.attestToProposal(proposal, attestors);
|
|
522
|
-
await this.p2pClient.addAttestations(attestations);
|
|
523
|
-
return attestations;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
916
|
private async handleAuthRequest(peer: PeerId, msg: Buffer): Promise<Buffer> {
|
|
527
917
|
const authRequest = AuthRequest.fromBuffer(msg);
|
|
528
918
|
const statusMessage = await this.p2pClient.handleAuthRequestFromPeer(authRequest, peer).catch(_ => undefined);
|
|
@@ -541,7 +931,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
541
931
|
}
|
|
542
932
|
|
|
543
933
|
const payloadToSign = authRequest.getPayloadToSign();
|
|
544
|
-
|
|
934
|
+
// AUTH_REQUEST doesn't require HA protection - multiple signatures are safe
|
|
935
|
+
const context: SigningContext = { dutyType: DutyType.AUTH_REQUEST };
|
|
936
|
+
const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign, context);
|
|
545
937
|
const authResponse = new AuthResponse(statusMessage, signature);
|
|
546
938
|
return authResponse.toBuffer();
|
|
547
939
|
}
|