@aztec/validator-client 0.0.1-commit.9b94fc1 → 0.0.1-commit.bf2612ae
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 +282 -0
- package/dest/block_proposal_handler.d.ts +23 -12
- package/dest/block_proposal_handler.d.ts.map +1 -1
- package/dest/block_proposal_handler.js +340 -84
- package/dest/checkpoint_builder.d.ts +67 -0
- package/dest/checkpoint_builder.d.ts.map +1 -0
- package/dest/checkpoint_builder.js +160 -0
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +13 -8
- package/dest/duties/validation_service.d.ts +42 -13
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +111 -28
- package/dest/factory.d.ts +13 -8
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +2 -2
- package/dest/index.d.ts +3 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -0
- 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 +1 -1
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +8 -33
- package/dest/tx_validator/index.d.ts +3 -0
- package/dest/tx_validator/index.d.ts.map +1 -0
- package/dest/tx_validator/index.js +2 -0
- package/dest/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/tx_validator/nullifier_cache.js +24 -0
- package/dest/tx_validator/tx_validator_factory.d.ts +18 -0
- package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -0
- package/dest/tx_validator/tx_validator_factory.js +54 -0
- package/dest/validator.d.ts +48 -19
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +327 -54
- package/package.json +23 -13
- package/src/block_proposal_handler.ts +266 -53
- package/src/checkpoint_builder.ts +284 -0
- package/src/config.ts +12 -7
- package/src/duties/validation_service.ts +155 -33
- package/src/factory.ts +17 -8
- package/src/index.ts +2 -0
- 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 +7 -34
- package/src/tx_validator/index.ts +2 -0
- package/src/tx_validator/nullifier_cache.ts +30 -0
- package/src/tx_validator/tx_validator_factory.ts +135 -0
- package/src/validator.ts +449 -83
package/src/validator.ts
CHANGED
|
@@ -1,31 +1,60 @@
|
|
|
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 {
|
|
4
|
+
import {
|
|
5
|
+
BlockNumber,
|
|
6
|
+
CheckpointNumber,
|
|
7
|
+
EpochNumber,
|
|
8
|
+
IndexWithinCheckpoint,
|
|
9
|
+
SlotNumber,
|
|
10
|
+
} from '@aztec/foundation/branded-types';
|
|
11
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
12
|
+
import { TimeoutError } from '@aztec/foundation/error';
|
|
3
13
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
14
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
15
|
+
import { type LogData, type Logger, createLogger } from '@aztec/foundation/log';
|
|
16
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
7
17
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
8
18
|
import { sleep } from '@aztec/foundation/sleep';
|
|
9
19
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
10
20
|
import type { KeystoreManager } from '@aztec/node-keystore';
|
|
11
|
-
import type { P2P, PeerId
|
|
21
|
+
import type { P2P, PeerId } from '@aztec/p2p';
|
|
12
22
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
13
23
|
import { OffenseType, WANT_TO_SLASH_EVENT, type Watcher, type WatcherEmitter } from '@aztec/slasher';
|
|
14
24
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
|
-
import type { CommitteeAttestationsAndSigners, L2BlockSource } from '@aztec/stdlib/block';
|
|
16
|
-
import
|
|
17
|
-
import type {
|
|
18
|
-
|
|
25
|
+
import type { CommitteeAttestationsAndSigners, L2Block, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
26
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
27
|
+
import type {
|
|
28
|
+
CreateCheckpointProposalLastBlockData,
|
|
29
|
+
ITxProvider,
|
|
30
|
+
Validator,
|
|
31
|
+
ValidatorClientFullConfig,
|
|
32
|
+
WorldStateSynchronizer,
|
|
33
|
+
} from '@aztec/stdlib/interfaces/server';
|
|
34
|
+
import { type L1ToL2MessageSource, accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
|
|
35
|
+
import type {
|
|
36
|
+
BlockProposal,
|
|
37
|
+
BlockProposalOptions,
|
|
38
|
+
CheckpointAttestation,
|
|
39
|
+
CheckpointProposalCore,
|
|
40
|
+
CheckpointProposalOptions,
|
|
41
|
+
} from '@aztec/stdlib/p2p';
|
|
42
|
+
import { CheckpointProposal } from '@aztec/stdlib/p2p';
|
|
19
43
|
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
20
|
-
import type { Tx } from '@aztec/stdlib/tx';
|
|
44
|
+
import type { BlockHeader, CheckpointGlobalVariables, Tx } from '@aztec/stdlib/tx';
|
|
21
45
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
22
46
|
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
47
|
+
import { createHASigner } from '@aztec/validator-ha-signer/factory';
|
|
48
|
+
import { DutyType, type SigningContext } from '@aztec/validator-ha-signer/types';
|
|
23
49
|
|
|
24
50
|
import { EventEmitter } from 'events';
|
|
25
51
|
import type { TypedDataDefinition } from 'viem';
|
|
26
52
|
|
|
27
53
|
import { BlockProposalHandler, type BlockProposalValidationFailureReason } from './block_proposal_handler.js';
|
|
54
|
+
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
28
55
|
import { ValidationService } from './duties/validation_service.js';
|
|
56
|
+
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
57
|
+
import type { ExtendedValidatorKeyStore } from './key_store/interface.js';
|
|
29
58
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
30
59
|
import { ValidatorMetrics } from './metrics.js';
|
|
31
60
|
|
|
@@ -59,12 +88,22 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
59
88
|
|
|
60
89
|
private proposersOfInvalidBlocks: Set<string> = new Set();
|
|
61
90
|
|
|
91
|
+
// TODO(palla/mbps): Remove this once checkpoint validation is stable and we can validate all blocks properly.
|
|
92
|
+
// Tracks slots for which we have successfully validated a block proposal, so we can attest to checkpoint proposals for those slots.
|
|
93
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
94
|
+
private validatedBlockSlots: Set<SlotNumber> = new Set();
|
|
95
|
+
|
|
62
96
|
protected constructor(
|
|
63
|
-
private keyStore:
|
|
97
|
+
private keyStore: ExtendedValidatorKeyStore,
|
|
64
98
|
private epochCache: EpochCache,
|
|
65
99
|
private p2pClient: P2P,
|
|
66
100
|
private blockProposalHandler: BlockProposalHandler,
|
|
101
|
+
private blockSource: L2BlockSource,
|
|
102
|
+
private checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
103
|
+
private worldState: WorldStateSynchronizer,
|
|
104
|
+
private l1ToL2MessageSource: L1ToL2MessageSource,
|
|
67
105
|
private config: ValidatorClientFullConfig,
|
|
106
|
+
private blobClient: BlobClientInterface,
|
|
68
107
|
private dateProvider: DateProvider = new DateProvider(),
|
|
69
108
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
70
109
|
log = createLogger('validator'),
|
|
@@ -138,15 +177,17 @@ 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(),
|
|
152
193
|
) {
|
|
@@ -155,23 +196,41 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
155
196
|
txsPermitted: !config.disableTransactions,
|
|
156
197
|
});
|
|
157
198
|
const blockProposalHandler = new BlockProposalHandler(
|
|
158
|
-
|
|
199
|
+
checkpointsBuilder,
|
|
200
|
+
worldState,
|
|
159
201
|
blockSource,
|
|
160
202
|
l1ToL2MessageSource,
|
|
161
203
|
txProvider,
|
|
162
204
|
blockProposalValidator,
|
|
205
|
+
epochCache,
|
|
163
206
|
config,
|
|
164
207
|
metrics,
|
|
165
208
|
dateProvider,
|
|
166
209
|
telemetry,
|
|
167
210
|
);
|
|
168
211
|
|
|
212
|
+
let validatorKeyStore: ExtendedValidatorKeyStore = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
213
|
+
if (config.haSigningEnabled) {
|
|
214
|
+
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
215
|
+
const haConfig = {
|
|
216
|
+
...config,
|
|
217
|
+
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000,
|
|
218
|
+
};
|
|
219
|
+
const { signer } = await createHASigner(haConfig);
|
|
220
|
+
validatorKeyStore = new HAKeyStore(validatorKeyStore, signer);
|
|
221
|
+
}
|
|
222
|
+
|
|
169
223
|
const validator = new ValidatorClient(
|
|
170
|
-
|
|
224
|
+
validatorKeyStore,
|
|
171
225
|
epochCache,
|
|
172
226
|
p2pClient,
|
|
173
227
|
blockProposalHandler,
|
|
228
|
+
blockSource,
|
|
229
|
+
checkpointsBuilder,
|
|
230
|
+
worldState,
|
|
231
|
+
l1ToL2MessageSource,
|
|
174
232
|
config,
|
|
233
|
+
blobClient,
|
|
175
234
|
dateProvider,
|
|
176
235
|
telemetry,
|
|
177
236
|
);
|
|
@@ -189,18 +248,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
189
248
|
return this.blockProposalHandler;
|
|
190
249
|
}
|
|
191
250
|
|
|
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);
|
|
251
|
+
public signWithAddress(addr: EthAddress, msg: TypedDataDefinition, context: SigningContext) {
|
|
252
|
+
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
204
253
|
}
|
|
205
254
|
|
|
206
255
|
public getCoinbaseForAttestor(attestor: EthAddress): EthAddress {
|
|
@@ -225,6 +274,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
225
274
|
return;
|
|
226
275
|
}
|
|
227
276
|
|
|
277
|
+
await this.keyStore.start();
|
|
278
|
+
|
|
228
279
|
await this.registerHandlers();
|
|
229
280
|
|
|
230
281
|
const myAddresses = this.getValidatorAddresses();
|
|
@@ -240,6 +291,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
240
291
|
|
|
241
292
|
public async stop() {
|
|
242
293
|
await this.epochCacheUpdateLoop.stop();
|
|
294
|
+
await this.keyStore.stop();
|
|
243
295
|
}
|
|
244
296
|
|
|
245
297
|
/** Register handlers on the p2p client */
|
|
@@ -248,9 +300,19 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
248
300
|
this.hasRegisteredHandlers = true;
|
|
249
301
|
this.log.debug(`Registering validator handlers for p2p client`);
|
|
250
302
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
303
|
+
// Block proposal handler - validates but does NOT attest (validators only attest to checkpoints)
|
|
304
|
+
const blockHandler = (block: BlockProposal, proposalSender: PeerId): Promise<boolean> =>
|
|
305
|
+
this.validateBlockProposal(block, proposalSender);
|
|
306
|
+
this.p2pClient.registerBlockProposalHandler(blockHandler);
|
|
307
|
+
|
|
308
|
+
// Checkpoint proposal handler - validates and creates attestations
|
|
309
|
+
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
310
|
+
// and processed separately via the block handler above.
|
|
311
|
+
const checkpointHandler = (
|
|
312
|
+
checkpoint: CheckpointProposalCore,
|
|
313
|
+
proposalSender: PeerId,
|
|
314
|
+
): Promise<CheckpointAttestation[] | undefined> => this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
315
|
+
this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
|
|
254
316
|
|
|
255
317
|
const myAddresses = this.getValidatorAddresses();
|
|
256
318
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
@@ -259,29 +321,38 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
259
321
|
}
|
|
260
322
|
}
|
|
261
323
|
|
|
262
|
-
|
|
324
|
+
/**
|
|
325
|
+
* Validate a block proposal from a peer.
|
|
326
|
+
* Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
|
|
327
|
+
* @returns true if the proposal is valid, false otherwise
|
|
328
|
+
*/
|
|
329
|
+
async validateBlockProposal(proposal: BlockProposal, proposalSender: PeerId): Promise<boolean> {
|
|
263
330
|
const slotNumber = proposal.slotNumber;
|
|
331
|
+
|
|
332
|
+
// Note: During escape hatch, we still want to "validate" proposals for observability,
|
|
333
|
+
// but we intentionally reject them and disable slashing invalid block and attestation flow.
|
|
334
|
+
const escapeHatchOpen = await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber);
|
|
335
|
+
|
|
264
336
|
const proposer = proposal.getSender();
|
|
265
337
|
|
|
266
338
|
// Reject proposals with invalid signatures
|
|
267
339
|
if (!proposer) {
|
|
268
|
-
this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
|
|
269
|
-
return
|
|
340
|
+
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
341
|
+
return false;
|
|
270
342
|
}
|
|
271
343
|
|
|
272
|
-
// Check
|
|
344
|
+
// Check if we're in the committee (for metrics purposes)
|
|
273
345
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
274
346
|
const partOfCommittee = inCommittee.length > 0;
|
|
275
347
|
|
|
276
348
|
const proposalInfo = { ...proposal.toBlockInfo(), proposer: proposer.toString() };
|
|
277
|
-
this.log.info(`Received proposal for slot ${slotNumber}`, {
|
|
349
|
+
this.log.info(`Received block proposal for slot ${slotNumber}`, {
|
|
278
350
|
...proposalInfo,
|
|
279
351
|
txHashes: proposal.txHashes.map(t => t.toString()),
|
|
280
352
|
fishermanMode: this.config.fishermanMode || false,
|
|
281
353
|
});
|
|
282
354
|
|
|
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.
|
|
355
|
+
// Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
|
|
285
356
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
286
357
|
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } =
|
|
287
358
|
this.config;
|
|
@@ -289,16 +360,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
289
360
|
fishermanMode ||
|
|
290
361
|
(slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute) ||
|
|
291
362
|
(partOfCommittee && validatorReexecute) ||
|
|
292
|
-
alwaysReexecuteBlockProposals
|
|
363
|
+
alwaysReexecuteBlockProposals ||
|
|
364
|
+
this.blobClient.canUpload();
|
|
293
365
|
|
|
294
366
|
const validationResult = await this.blockProposalHandler.handleBlockProposal(
|
|
295
367
|
proposal,
|
|
296
368
|
proposalSender,
|
|
297
|
-
!!shouldReexecute,
|
|
369
|
+
!!shouldReexecute && !escapeHatchOpen,
|
|
298
370
|
);
|
|
299
371
|
|
|
300
372
|
if (!validationResult.isValid) {
|
|
301
|
-
this.log.warn(`
|
|
373
|
+
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
302
374
|
|
|
303
375
|
const reason = validationResult.reason || 'unknown';
|
|
304
376
|
// Classify failure reason: bad proposal vs node issue
|
|
@@ -313,12 +385,13 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
313
385
|
if (badProposalReasons.includes(reason as BlockProposalValidationFailureReason)) {
|
|
314
386
|
this.metrics.incFailedAttestationsBadProposal(1, reason, partOfCommittee);
|
|
315
387
|
} else {
|
|
316
|
-
// Node issues so we can't
|
|
388
|
+
// Node issues so we can't validate
|
|
317
389
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
318
390
|
}
|
|
319
391
|
|
|
320
392
|
// Slash invalid block proposals (can happen even when not in committee)
|
|
321
393
|
if (
|
|
394
|
+
!escapeHatchOpen &&
|
|
322
395
|
validationResult.reason &&
|
|
323
396
|
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) &&
|
|
324
397
|
slashBroadcastedInvalidBlockPenalty > 0n
|
|
@@ -326,9 +399,93 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
326
399
|
this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
|
|
327
400
|
this.slashInvalidBlock(proposal);
|
|
328
401
|
}
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
this.log.info(`Validated block proposal for slot ${slotNumber}`, {
|
|
406
|
+
...proposalInfo,
|
|
407
|
+
inCommittee: partOfCommittee,
|
|
408
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
409
|
+
escapeHatchOpen,
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
if (escapeHatchOpen) {
|
|
413
|
+
this.log.warn(`Escape hatch open for slot ${slotNumber}, rejecting block proposal`, proposalInfo);
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// TODO(palla/mbps): Remove this once checkpoint validation is stable.
|
|
418
|
+
// Track that we successfully validated a block for this slot, so we can attest to checkpoint proposals for it.
|
|
419
|
+
this.validatedBlockSlots.add(slotNumber);
|
|
420
|
+
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Validate and attest to a checkpoint proposal from a peer.
|
|
426
|
+
* The proposal is received as CheckpointProposalCore (without lastBlock) since
|
|
427
|
+
* the lastBlock is extracted and processed separately via the block handler.
|
|
428
|
+
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
429
|
+
*/
|
|
430
|
+
async attestToCheckpointProposal(
|
|
431
|
+
proposal: CheckpointProposalCore,
|
|
432
|
+
_proposalSender: PeerId,
|
|
433
|
+
): Promise<CheckpointAttestation[] | undefined> {
|
|
434
|
+
const slotNumber = proposal.slotNumber;
|
|
435
|
+
const proposer = proposal.getSender();
|
|
436
|
+
|
|
437
|
+
// If escape hatch is open for this slot's epoch, do not attest.
|
|
438
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
|
|
439
|
+
this.log.warn(`Escape hatch open for slot ${slotNumber}, skipping checkpoint attestation handling`);
|
|
440
|
+
return undefined;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// Reject proposals with invalid signatures
|
|
444
|
+
if (!proposer) {
|
|
445
|
+
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
329
446
|
return undefined;
|
|
330
447
|
}
|
|
331
448
|
|
|
449
|
+
// Check that I have any address in current committee before attesting
|
|
450
|
+
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
451
|
+
const partOfCommittee = inCommittee.length > 0;
|
|
452
|
+
|
|
453
|
+
const proposalInfo = {
|
|
454
|
+
slotNumber,
|
|
455
|
+
archive: proposal.archive.toString(),
|
|
456
|
+
proposer: proposer.toString(),
|
|
457
|
+
txCount: proposal.txHashes.length,
|
|
458
|
+
};
|
|
459
|
+
this.log.info(`Received checkpoint proposal for slot ${slotNumber}`, {
|
|
460
|
+
...proposalInfo,
|
|
461
|
+
txHashes: proposal.txHashes.map(t => t.toString()),
|
|
462
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
// TODO(palla/mbps): Remove this once checkpoint validation is stable.
|
|
466
|
+
// Check that we have successfully validated a block for this slot before attesting to the checkpoint.
|
|
467
|
+
if (!this.validatedBlockSlots.has(slotNumber)) {
|
|
468
|
+
this.log.warn(`No validated block found for slot ${slotNumber}, refusing to attest to checkpoint`, proposalInfo);
|
|
469
|
+
return undefined;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
473
|
+
// TODO(palla/mbps): Change default to false once checkpoint validation is stable.
|
|
474
|
+
if (this.config.skipCheckpointProposalValidation !== false) {
|
|
475
|
+
this.log.verbose(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
|
|
476
|
+
} else {
|
|
477
|
+
const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
|
|
478
|
+
if (!validationResult.isValid) {
|
|
479
|
+
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
480
|
+
return undefined;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// Upload blobs to filestore if we can (fire and forget)
|
|
485
|
+
if (this.blobClient.canUpload()) {
|
|
486
|
+
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
487
|
+
}
|
|
488
|
+
|
|
332
489
|
// Check that I have any address in current committee before attesting
|
|
333
490
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
334
491
|
if (!partOfCommittee && !this.config.fishermanMode) {
|
|
@@ -337,7 +494,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
337
494
|
}
|
|
338
495
|
|
|
339
496
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
340
|
-
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} proposal for slot ${slotNumber}`, {
|
|
497
|
+
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${slotNumber}`, {
|
|
341
498
|
...proposalInfo,
|
|
342
499
|
inCommittee: partOfCommittee,
|
|
343
500
|
fishermanMode: this.config.fishermanMode || false,
|
|
@@ -345,7 +502,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
345
502
|
|
|
346
503
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
347
504
|
|
|
348
|
-
// If the above function does not throw an error, then we can attest to the proposal
|
|
349
505
|
// Determine which validators should attest
|
|
350
506
|
let attestors: EthAddress[];
|
|
351
507
|
if (partOfCommittee) {
|
|
@@ -364,13 +520,194 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
364
520
|
|
|
365
521
|
if (this.config.fishermanMode) {
|
|
366
522
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
367
|
-
this.log.info(`Creating attestations for
|
|
523
|
+
this.log.info(`Creating checkpoint attestations for slot ${slotNumber}`, {
|
|
368
524
|
...proposalInfo,
|
|
369
525
|
attestors: attestors.map(a => a.toString()),
|
|
370
526
|
});
|
|
371
527
|
return undefined;
|
|
372
528
|
}
|
|
373
|
-
|
|
529
|
+
|
|
530
|
+
return this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
private async createCheckpointAttestationsFromProposal(
|
|
534
|
+
proposal: CheckpointProposalCore,
|
|
535
|
+
attestors: EthAddress[] = [],
|
|
536
|
+
): Promise<CheckpointAttestation[]> {
|
|
537
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
538
|
+
await this.p2pClient.addCheckpointAttestations(attestations);
|
|
539
|
+
return attestations;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
544
|
+
* @returns Validation result with isValid flag and reason if invalid.
|
|
545
|
+
*/
|
|
546
|
+
private async validateCheckpointProposal(
|
|
547
|
+
proposal: CheckpointProposalCore,
|
|
548
|
+
proposalInfo: LogData,
|
|
549
|
+
): Promise<{ isValid: true } | { isValid: false; reason: string }> {
|
|
550
|
+
const slot = proposal.slotNumber;
|
|
551
|
+
const timeoutSeconds = 10;
|
|
552
|
+
|
|
553
|
+
// Wait for last block to sync by archive
|
|
554
|
+
let lastBlockHeader: BlockHeader | undefined;
|
|
555
|
+
try {
|
|
556
|
+
lastBlockHeader = await retryUntil(
|
|
557
|
+
async () => {
|
|
558
|
+
await this.blockSource.syncImmediate();
|
|
559
|
+
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
560
|
+
},
|
|
561
|
+
`waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`,
|
|
562
|
+
timeoutSeconds,
|
|
563
|
+
0.5,
|
|
564
|
+
);
|
|
565
|
+
} catch (err) {
|
|
566
|
+
if (err instanceof TimeoutError) {
|
|
567
|
+
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
568
|
+
return { isValid: false, reason: 'last_block_not_found' };
|
|
569
|
+
}
|
|
570
|
+
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
571
|
+
return { isValid: false, reason: 'block_fetch_error' };
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
if (!lastBlockHeader) {
|
|
575
|
+
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
576
|
+
return { isValid: false, reason: 'last_block_not_found' };
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// Get all full blocks for the slot and checkpoint
|
|
580
|
+
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
581
|
+
if (blocks.length === 0) {
|
|
582
|
+
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
583
|
+
return { isValid: false, reason: 'no_blocks_for_slot' };
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
587
|
+
...proposalInfo,
|
|
588
|
+
blockNumbers: blocks.map(b => b.number),
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
// Get checkpoint constants from first block
|
|
592
|
+
const firstBlock = blocks[0];
|
|
593
|
+
const constants = this.extractCheckpointConstants(firstBlock);
|
|
594
|
+
const checkpointNumber = firstBlock.checkpointNumber;
|
|
595
|
+
|
|
596
|
+
// Get L1-to-L2 messages for this checkpoint
|
|
597
|
+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
598
|
+
|
|
599
|
+
// Compute the previous checkpoint out hashes for the epoch.
|
|
600
|
+
// TODO: There can be a more efficient way to get the previous checkpoint out hashes without having to fetch the
|
|
601
|
+
// actual checkpoints and the blocks/txs in them.
|
|
602
|
+
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
603
|
+
const previousCheckpoints = (await this.blockSource.getCheckpointsForEpoch(epoch))
|
|
604
|
+
.filter(b => b.number < checkpointNumber)
|
|
605
|
+
.sort((a, b) => a.number - b.number);
|
|
606
|
+
const previousCheckpointOutHashes = previousCheckpoints.map(c => c.getCheckpointOutHash());
|
|
607
|
+
|
|
608
|
+
// Fork world state at the block before the first block
|
|
609
|
+
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
610
|
+
const fork = await this.worldState.fork(parentBlockNumber);
|
|
611
|
+
|
|
612
|
+
try {
|
|
613
|
+
// Create checkpoint builder with all existing blocks
|
|
614
|
+
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
|
|
615
|
+
checkpointNumber,
|
|
616
|
+
constants,
|
|
617
|
+
l1ToL2Messages,
|
|
618
|
+
previousCheckpointOutHashes,
|
|
619
|
+
fork,
|
|
620
|
+
blocks,
|
|
621
|
+
);
|
|
622
|
+
|
|
623
|
+
// Complete the checkpoint to get computed values
|
|
624
|
+
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
625
|
+
|
|
626
|
+
// Compare checkpoint header with proposal
|
|
627
|
+
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
628
|
+
this.log.warn(`Checkpoint header mismatch`, {
|
|
629
|
+
...proposalInfo,
|
|
630
|
+
computed: computedCheckpoint.header.toInspect(),
|
|
631
|
+
proposal: proposal.checkpointHeader.toInspect(),
|
|
632
|
+
});
|
|
633
|
+
return { isValid: false, reason: 'checkpoint_header_mismatch' };
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// Compare archive root with proposal
|
|
637
|
+
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
638
|
+
this.log.warn(`Archive root mismatch`, {
|
|
639
|
+
...proposalInfo,
|
|
640
|
+
computed: computedCheckpoint.archive.root.toString(),
|
|
641
|
+
proposal: proposal.archive.toString(),
|
|
642
|
+
});
|
|
643
|
+
return { isValid: false, reason: 'archive_mismatch' };
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
647
|
+
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
648
|
+
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
649
|
+
const computedEpochOutHash = accumulateCheckpointOutHashes([...previousCheckpointOutHashes, checkpointOutHash]);
|
|
650
|
+
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
651
|
+
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
652
|
+
this.log.warn(`Epoch out hash mismatch`, {
|
|
653
|
+
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
654
|
+
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
655
|
+
checkpointOutHash: checkpointOutHash.toString(),
|
|
656
|
+
previousCheckpointOutHashes: previousCheckpointOutHashes.map(h => h.toString()),
|
|
657
|
+
...proposalInfo,
|
|
658
|
+
});
|
|
659
|
+
return { isValid: false, reason: 'out_hash_mismatch' };
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
663
|
+
return { isValid: true };
|
|
664
|
+
} finally {
|
|
665
|
+
await fork.close();
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* Extract checkpoint global variables from a block.
|
|
671
|
+
*/
|
|
672
|
+
private extractCheckpointConstants(block: L2Block): CheckpointGlobalVariables {
|
|
673
|
+
const gv = block.header.globalVariables;
|
|
674
|
+
return {
|
|
675
|
+
chainId: gv.chainId,
|
|
676
|
+
version: gv.version,
|
|
677
|
+
slotNumber: gv.slotNumber,
|
|
678
|
+
coinbase: gv.coinbase,
|
|
679
|
+
feeRecipient: gv.feeRecipient,
|
|
680
|
+
gasFees: gv.gasFees,
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
686
|
+
*/
|
|
687
|
+
private async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
|
|
688
|
+
try {
|
|
689
|
+
const lastBlockHeader = await this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
690
|
+
if (!lastBlockHeader) {
|
|
691
|
+
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
const blocks = await this.blockSource.getBlocksForSlot(proposal.slotNumber);
|
|
696
|
+
if (blocks.length === 0) {
|
|
697
|
+
this.log.warn(`No blocks found for blob upload`, proposalInfo);
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
const blobFields = blocks.flatMap(b => b.toBlobFields());
|
|
702
|
+
const blobs: Blob[] = getBlobsPerL1Block(blobFields);
|
|
703
|
+
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
704
|
+
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
705
|
+
...proposalInfo,
|
|
706
|
+
numBlobs: blobs.length,
|
|
707
|
+
});
|
|
708
|
+
} catch (err) {
|
|
709
|
+
this.log.warn(`Failed to upload blobs for checkpoint: ${err}`, proposalInfo);
|
|
710
|
+
}
|
|
374
711
|
}
|
|
375
712
|
|
|
376
713
|
private slashInvalidBlock(proposal: BlockProposal) {
|
|
@@ -401,26 +738,56 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
401
738
|
}
|
|
402
739
|
|
|
403
740
|
async createBlockProposal(
|
|
404
|
-
|
|
405
|
-
|
|
741
|
+
blockHeader: BlockHeader,
|
|
742
|
+
indexWithinCheckpoint: IndexWithinCheckpoint,
|
|
743
|
+
inHash: Fr,
|
|
406
744
|
archive: Fr,
|
|
407
745
|
txs: Tx[],
|
|
408
746
|
proposerAddress: EthAddress | undefined,
|
|
409
|
-
options: BlockProposalOptions,
|
|
410
|
-
): Promise<BlockProposal
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
747
|
+
options: BlockProposalOptions = {},
|
|
748
|
+
): Promise<BlockProposal> {
|
|
749
|
+
// TODO(palla/mbps): Prevent double proposals properly
|
|
750
|
+
// if (this.previousProposal?.slotNumber === blockHeader.globalVariables.slotNumber) {
|
|
751
|
+
// this.log.verbose(`Already made a proposal for the same slot, skipping proposal`);
|
|
752
|
+
// return Promise.resolve(undefined);
|
|
753
|
+
// }
|
|
754
|
+
|
|
755
|
+
this.log.info(
|
|
756
|
+
`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`,
|
|
757
|
+
);
|
|
758
|
+
const newProposal = await this.validationService.createBlockProposal(
|
|
759
|
+
blockHeader,
|
|
760
|
+
indexWithinCheckpoint,
|
|
761
|
+
inHash,
|
|
762
|
+
archive,
|
|
763
|
+
txs,
|
|
764
|
+
proposerAddress,
|
|
765
|
+
{
|
|
766
|
+
...options,
|
|
767
|
+
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal,
|
|
768
|
+
},
|
|
769
|
+
);
|
|
420
770
|
this.previousProposal = newProposal;
|
|
421
771
|
return newProposal;
|
|
422
772
|
}
|
|
423
773
|
|
|
774
|
+
async createCheckpointProposal(
|
|
775
|
+
checkpointHeader: CheckpointHeader,
|
|
776
|
+
archive: Fr,
|
|
777
|
+
lastBlockInfo: CreateCheckpointProposalLastBlockData | undefined,
|
|
778
|
+
proposerAddress: EthAddress | undefined,
|
|
779
|
+
options: CheckpointProposalOptions = {},
|
|
780
|
+
): Promise<CheckpointProposal> {
|
|
781
|
+
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
782
|
+
return await this.validationService.createCheckpointProposal(
|
|
783
|
+
checkpointHeader,
|
|
784
|
+
archive,
|
|
785
|
+
lastBlockInfo,
|
|
786
|
+
proposerAddress,
|
|
787
|
+
options,
|
|
788
|
+
);
|
|
789
|
+
}
|
|
790
|
+
|
|
424
791
|
async broadcastBlockProposal(proposal: BlockProposal): Promise<void> {
|
|
425
792
|
await this.p2pClient.broadcastProposal(proposal);
|
|
426
793
|
}
|
|
@@ -428,28 +795,34 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
428
795
|
async signAttestationsAndSigners(
|
|
429
796
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
430
797
|
proposer: EthAddress,
|
|
798
|
+
slot: SlotNumber,
|
|
799
|
+
blockNumber: BlockNumber | CheckpointNumber,
|
|
431
800
|
): Promise<Signature> {
|
|
432
|
-
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
|
|
801
|
+
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
|
|
433
802
|
}
|
|
434
803
|
|
|
435
|
-
async collectOwnAttestations(proposal:
|
|
436
|
-
const slot = proposal.
|
|
804
|
+
async collectOwnAttestations(proposal: CheckpointProposal): Promise<CheckpointAttestation[]> {
|
|
805
|
+
const slot = proposal.slotNumber;
|
|
437
806
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
438
807
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, { inCommittee });
|
|
439
|
-
const attestations = await this.
|
|
808
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
440
809
|
|
|
441
810
|
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
442
811
|
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
443
812
|
// due to inactivity for missed attestations.
|
|
444
|
-
void this.p2pClient.
|
|
813
|
+
void this.p2pClient.broadcastCheckpointAttestations(attestations).catch(err => {
|
|
445
814
|
this.log.error(`Failed to broadcast self-attestations for slot ${slot}`, err);
|
|
446
815
|
});
|
|
447
816
|
return attestations;
|
|
448
817
|
}
|
|
449
818
|
|
|
450
|
-
async collectAttestations(
|
|
451
|
-
|
|
452
|
-
|
|
819
|
+
async collectAttestations(
|
|
820
|
+
proposal: CheckpointProposal,
|
|
821
|
+
required: number,
|
|
822
|
+
deadline: Date,
|
|
823
|
+
): Promise<CheckpointAttestation[]> {
|
|
824
|
+
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
825
|
+
const slot = proposal.slotNumber;
|
|
453
826
|
this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
|
|
454
827
|
|
|
455
828
|
if (+deadline < this.dateProvider.now()) {
|
|
@@ -464,16 +837,16 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
464
837
|
const proposalId = proposal.archive.toString();
|
|
465
838
|
const myAddresses = this.getValidatorAddresses();
|
|
466
839
|
|
|
467
|
-
let attestations:
|
|
840
|
+
let attestations: CheckpointAttestation[] = [];
|
|
468
841
|
while (true) {
|
|
469
|
-
// Filter out attestations with a mismatching
|
|
842
|
+
// Filter out attestations with a mismatching archive. This should NOT happen since we have verified
|
|
470
843
|
// the proposer signature (ie our own) before accepting the attestation into the pool via the p2p client.
|
|
471
|
-
const collectedAttestations = (await this.p2pClient.
|
|
844
|
+
const collectedAttestations = (await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalId)).filter(
|
|
472
845
|
attestation => {
|
|
473
|
-
if (!attestation.
|
|
846
|
+
if (!attestation.archive.equals(proposal.archive)) {
|
|
474
847
|
this.log.warn(
|
|
475
|
-
`Received attestation for slot ${slot} with mismatched
|
|
476
|
-
{
|
|
848
|
+
`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`,
|
|
849
|
+
{ attestationArchive: attestation.archive.toString(), proposalArchive: proposal.archive.toString() },
|
|
477
850
|
);
|
|
478
851
|
return false;
|
|
479
852
|
}
|
|
@@ -514,15 +887,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
514
887
|
}
|
|
515
888
|
}
|
|
516
889
|
|
|
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
890
|
private async handleAuthRequest(peer: PeerId, msg: Buffer): Promise<Buffer> {
|
|
527
891
|
const authRequest = AuthRequest.fromBuffer(msg);
|
|
528
892
|
const statusMessage = await this.p2pClient.handleAuthRequestFromPeer(authRequest, peer).catch(_ => undefined);
|
|
@@ -541,7 +905,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
541
905
|
}
|
|
542
906
|
|
|
543
907
|
const payloadToSign = authRequest.getPayloadToSign();
|
|
544
|
-
|
|
908
|
+
// AUTH_REQUEST doesn't require HA protection - multiple signatures are safe
|
|
909
|
+
const context: SigningContext = { dutyType: DutyType.AUTH_REQUEST };
|
|
910
|
+
const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign, context);
|
|
545
911
|
const authResponse = new AuthResponse(statusMessage, signature);
|
|
546
912
|
return authResponse.toBuffer();
|
|
547
913
|
}
|