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