@aztec/validator-client 3.0.3-rc.3 → 3.9.9-nightly.20260312
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 +328 -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 +423 -107
- package/dest/checkpoint_builder.d.ts +76 -0
- package/dest/checkpoint_builder.d.ts.map +1 -0
- package/dest/checkpoint_builder.js +237 -0
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +36 -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 +103 -26
- package/dest/factory.d.ts +13 -8
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +4 -3
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -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 +12 -3
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +46 -30
- package/dest/validator.d.ts +75 -21
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +478 -57
- package/package.json +21 -11
- package/src/block_proposal_handler.ts +355 -77
- package/src/checkpoint_builder.ts +398 -0
- package/src/config.ts +35 -7
- package/src/duties/validation_service.ts +154 -31
- package/src/factory.ts +18 -8
- package/src/index.ts +1 -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 +63 -33
- package/src/validator.ts +648 -85
package/src/validator.ts
CHANGED
|
@@ -1,31 +1,63 @@
|
|
|
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 { validateFeeAssetPriceModifier } from '@aztec/ethereum/contracts';
|
|
5
|
+
import {
|
|
6
|
+
BlockNumber,
|
|
7
|
+
CheckpointNumber,
|
|
8
|
+
EpochNumber,
|
|
9
|
+
IndexWithinCheckpoint,
|
|
10
|
+
SlotNumber,
|
|
11
|
+
} from '@aztec/foundation/branded-types';
|
|
3
12
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
13
|
+
import { TimeoutError } from '@aztec/foundation/error';
|
|
4
14
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
15
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
6
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
16
|
+
import { type LogData, type Logger, createLogger } from '@aztec/foundation/log';
|
|
17
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
7
18
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
8
19
|
import { sleep } from '@aztec/foundation/sleep';
|
|
9
20
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
10
21
|
import type { KeystoreManager } from '@aztec/node-keystore';
|
|
11
|
-
import type { P2P, PeerId
|
|
22
|
+
import type { DuplicateAttestationInfo, DuplicateProposalInfo, P2P, PeerId } from '@aztec/p2p';
|
|
12
23
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
13
24
|
import { OffenseType, WANT_TO_SLASH_EVENT, type Watcher, type WatcherEmitter } from '@aztec/slasher';
|
|
14
25
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
|
-
import type { CommitteeAttestationsAndSigners, L2BlockSource } from '@aztec/stdlib/block';
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import type {
|
|
26
|
+
import type { CommitteeAttestationsAndSigners, L2Block, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
27
|
+
import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
28
|
+
import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
29
|
+
import type {
|
|
30
|
+
CreateCheckpointProposalLastBlockData,
|
|
31
|
+
ITxProvider,
|
|
32
|
+
Validator,
|
|
33
|
+
ValidatorClientFullConfig,
|
|
34
|
+
WorldStateSynchronizer,
|
|
35
|
+
} from '@aztec/stdlib/interfaces/server';
|
|
36
|
+
import { type L1ToL2MessageSource, accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
|
|
37
|
+
import {
|
|
38
|
+
type BlockProposal,
|
|
39
|
+
type BlockProposalOptions,
|
|
40
|
+
type CheckpointAttestation,
|
|
41
|
+
CheckpointProposal,
|
|
42
|
+
type CheckpointProposalCore,
|
|
43
|
+
type CheckpointProposalOptions,
|
|
44
|
+
} from '@aztec/stdlib/p2p';
|
|
19
45
|
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
20
|
-
import type { Tx } from '@aztec/stdlib/tx';
|
|
46
|
+
import type { BlockHeader, CheckpointGlobalVariables, Tx } from '@aztec/stdlib/tx';
|
|
21
47
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
22
48
|
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
49
|
+
import { createHASigner } from '@aztec/validator-ha-signer/factory';
|
|
50
|
+
import { DutyType, type SigningContext } from '@aztec/validator-ha-signer/types';
|
|
51
|
+
import type { ValidatorHASigner } from '@aztec/validator-ha-signer/validator-ha-signer';
|
|
23
52
|
|
|
24
53
|
import { EventEmitter } from 'events';
|
|
25
54
|
import type { TypedDataDefinition } from 'viem';
|
|
26
55
|
|
|
27
56
|
import { BlockProposalHandler, type BlockProposalValidationFailureReason } from './block_proposal_handler.js';
|
|
57
|
+
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
28
58
|
import { ValidationService } from './duties/validation_service.js';
|
|
59
|
+
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
60
|
+
import type { ExtendedValidatorKeyStore } from './key_store/interface.js';
|
|
29
61
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
30
62
|
import { ValidatorMetrics } from './metrics.js';
|
|
31
63
|
|
|
@@ -47,24 +79,37 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
47
79
|
private validationService: ValidationService;
|
|
48
80
|
private metrics: ValidatorMetrics;
|
|
49
81
|
private log: Logger;
|
|
50
|
-
|
|
51
82
|
// Whether it has already registered handlers on the p2p client
|
|
52
83
|
private hasRegisteredHandlers = false;
|
|
53
84
|
|
|
54
|
-
|
|
55
|
-
private
|
|
85
|
+
/** Tracks the last block proposal we created, to detect duplicate proposal attempts. */
|
|
86
|
+
private lastProposedBlock?: BlockProposal;
|
|
87
|
+
|
|
88
|
+
/** Tracks the last checkpoint proposal we created. */
|
|
89
|
+
private lastProposedCheckpoint?: CheckpointProposal;
|
|
56
90
|
|
|
57
91
|
private lastEpochForCommitteeUpdateLoop: EpochNumber | undefined;
|
|
58
92
|
private epochCacheUpdateLoop: RunningPromise;
|
|
93
|
+
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */
|
|
94
|
+
private lastAttestedEpochByAttester: Map<string, EpochNumber> = new Map();
|
|
59
95
|
|
|
60
96
|
private proposersOfInvalidBlocks: Set<string> = new Set();
|
|
61
97
|
|
|
98
|
+
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */
|
|
99
|
+
private lastAttestedProposal?: CheckpointProposalCore;
|
|
100
|
+
|
|
62
101
|
protected constructor(
|
|
63
|
-
private keyStore:
|
|
102
|
+
private keyStore: ExtendedValidatorKeyStore,
|
|
64
103
|
private epochCache: EpochCache,
|
|
65
104
|
private p2pClient: P2P,
|
|
66
105
|
private blockProposalHandler: BlockProposalHandler,
|
|
106
|
+
private blockSource: L2BlockSource,
|
|
107
|
+
private checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
108
|
+
private worldState: WorldStateSynchronizer,
|
|
109
|
+
private l1ToL2MessageSource: L1ToL2MessageSource,
|
|
67
110
|
private config: ValidatorClientFullConfig,
|
|
111
|
+
private blobClient: BlobClientInterface,
|
|
112
|
+
private haSigner: ValidatorHASigner | undefined,
|
|
68
113
|
private dateProvider: DateProvider = new DateProvider(),
|
|
69
114
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
70
115
|
log = createLogger('validator'),
|
|
@@ -118,6 +163,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
118
163
|
this.log.trace(`No committee found for slot`);
|
|
119
164
|
return;
|
|
120
165
|
}
|
|
166
|
+
this.metrics.setCurrentEpoch(epoch);
|
|
121
167
|
if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
|
|
122
168
|
const me = this.getValidatorAddresses();
|
|
123
169
|
const committeeSet = new Set(committee.map(v => v.toString()));
|
|
@@ -138,40 +184,65 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
138
184
|
}
|
|
139
185
|
}
|
|
140
186
|
|
|
141
|
-
static new(
|
|
187
|
+
static async new(
|
|
142
188
|
config: ValidatorClientFullConfig,
|
|
143
|
-
|
|
189
|
+
checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
190
|
+
worldState: WorldStateSynchronizer,
|
|
144
191
|
epochCache: EpochCache,
|
|
145
192
|
p2pClient: P2P,
|
|
146
|
-
blockSource: L2BlockSource,
|
|
193
|
+
blockSource: L2BlockSource & L2BlockSink,
|
|
147
194
|
l1ToL2MessageSource: L1ToL2MessageSource,
|
|
148
|
-
txProvider:
|
|
195
|
+
txProvider: ITxProvider,
|
|
149
196
|
keyStoreManager: KeystoreManager,
|
|
197
|
+
blobClient: BlobClientInterface,
|
|
150
198
|
dateProvider: DateProvider = new DateProvider(),
|
|
151
199
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
152
200
|
) {
|
|
153
201
|
const metrics = new ValidatorMetrics(telemetry);
|
|
154
202
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
155
203
|
txsPermitted: !config.disableTransactions,
|
|
204
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock,
|
|
156
205
|
});
|
|
157
206
|
const blockProposalHandler = new BlockProposalHandler(
|
|
158
|
-
|
|
207
|
+
checkpointsBuilder,
|
|
208
|
+
worldState,
|
|
159
209
|
blockSource,
|
|
160
210
|
l1ToL2MessageSource,
|
|
161
211
|
txProvider,
|
|
162
212
|
blockProposalValidator,
|
|
213
|
+
epochCache,
|
|
163
214
|
config,
|
|
164
215
|
metrics,
|
|
165
216
|
dateProvider,
|
|
166
217
|
telemetry,
|
|
167
218
|
);
|
|
168
219
|
|
|
220
|
+
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
221
|
+
let validatorKeyStore: ExtendedValidatorKeyStore = nodeKeystoreAdapter;
|
|
222
|
+
let haSigner: ValidatorHASigner | undefined;
|
|
223
|
+
if (config.haSigningEnabled) {
|
|
224
|
+
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
225
|
+
const haConfig = {
|
|
226
|
+
...config,
|
|
227
|
+
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000,
|
|
228
|
+
};
|
|
229
|
+
const { signer } = await createHASigner(haConfig);
|
|
230
|
+
haSigner = signer;
|
|
231
|
+
validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, signer);
|
|
232
|
+
}
|
|
233
|
+
|
|
169
234
|
const validator = new ValidatorClient(
|
|
170
|
-
|
|
235
|
+
validatorKeyStore,
|
|
171
236
|
epochCache,
|
|
172
237
|
p2pClient,
|
|
173
238
|
blockProposalHandler,
|
|
239
|
+
blockSource,
|
|
240
|
+
checkpointsBuilder,
|
|
241
|
+
worldState,
|
|
242
|
+
l1ToL2MessageSource,
|
|
174
243
|
config,
|
|
244
|
+
blobClient,
|
|
245
|
+
haSigner,
|
|
175
246
|
dateProvider,
|
|
176
247
|
telemetry,
|
|
177
248
|
);
|
|
@@ -189,18 +260,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
189
260
|
return this.blockProposalHandler;
|
|
190
261
|
}
|
|
191
262
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
proposal: BlockProposal,
|
|
195
|
-
blockNumber: BlockNumber,
|
|
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);
|
|
263
|
+
public signWithAddress(addr: EthAddress, msg: TypedDataDefinition, context: SigningContext) {
|
|
264
|
+
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
204
265
|
}
|
|
205
266
|
|
|
206
267
|
public getCoinbaseForAttestor(attestor: EthAddress): EthAddress {
|
|
@@ -219,12 +280,36 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
219
280
|
this.config = { ...this.config, ...config };
|
|
220
281
|
}
|
|
221
282
|
|
|
283
|
+
public reloadKeystore(newManager: KeystoreManager): void {
|
|
284
|
+
if (this.config.haSigningEnabled && !this.haSigner) {
|
|
285
|
+
this.log.warn(
|
|
286
|
+
'HA signing is enabled in config but was not initialized at startup. ' +
|
|
287
|
+
'Restart the node to enable HA signing.',
|
|
288
|
+
);
|
|
289
|
+
} else if (!this.config.haSigningEnabled && this.haSigner) {
|
|
290
|
+
this.log.warn(
|
|
291
|
+
'HA signing was disabled via config update but the HA signer is still active. ' +
|
|
292
|
+
'Restart the node to fully disable HA signing.',
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
297
|
+
if (this.haSigner) {
|
|
298
|
+
this.keyStore = new HAKeyStore(newAdapter, this.haSigner);
|
|
299
|
+
} else {
|
|
300
|
+
this.keyStore = newAdapter;
|
|
301
|
+
}
|
|
302
|
+
this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
|
|
303
|
+
}
|
|
304
|
+
|
|
222
305
|
public async start() {
|
|
223
306
|
if (this.epochCacheUpdateLoop.isRunning()) {
|
|
224
307
|
this.log.warn(`Validator client already started`);
|
|
225
308
|
return;
|
|
226
309
|
}
|
|
227
310
|
|
|
311
|
+
await this.keyStore.start();
|
|
312
|
+
|
|
228
313
|
await this.registerHandlers();
|
|
229
314
|
|
|
230
315
|
const myAddresses = this.getValidatorAddresses();
|
|
@@ -240,6 +325,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
240
325
|
|
|
241
326
|
public async stop() {
|
|
242
327
|
await this.epochCacheUpdateLoop.stop();
|
|
328
|
+
await this.keyStore.stop();
|
|
243
329
|
}
|
|
244
330
|
|
|
245
331
|
/** Register handlers on the p2p client */
|
|
@@ -248,9 +334,29 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
248
334
|
this.hasRegisteredHandlers = true;
|
|
249
335
|
this.log.debug(`Registering validator handlers for p2p client`);
|
|
250
336
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
337
|
+
// Block proposal handler - validates but does NOT attest (validators only attest to checkpoints)
|
|
338
|
+
const blockHandler = (block: BlockProposal, proposalSender: PeerId): Promise<boolean> =>
|
|
339
|
+
this.validateBlockProposal(block, proposalSender);
|
|
340
|
+
this.p2pClient.registerBlockProposalHandler(blockHandler);
|
|
341
|
+
|
|
342
|
+
// Checkpoint proposal handler - validates and creates attestations
|
|
343
|
+
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
344
|
+
// and processed separately via the block handler above.
|
|
345
|
+
const checkpointHandler = (
|
|
346
|
+
checkpoint: CheckpointProposalCore,
|
|
347
|
+
proposalSender: PeerId,
|
|
348
|
+
): Promise<CheckpointAttestation[] | undefined> => this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
349
|
+
this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
|
|
350
|
+
|
|
351
|
+
// Duplicate proposal handler - triggers slashing for equivocation
|
|
352
|
+
this.p2pClient.registerDuplicateProposalCallback((info: DuplicateProposalInfo) => {
|
|
353
|
+
this.handleDuplicateProposal(info);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
// Duplicate attestation handler - triggers slashing for attestation equivocation
|
|
357
|
+
this.p2pClient.registerDuplicateAttestationCallback((info: DuplicateAttestationInfo) => {
|
|
358
|
+
this.handleDuplicateAttestation(info);
|
|
359
|
+
});
|
|
254
360
|
|
|
255
361
|
const myAddresses = this.getValidatorAddresses();
|
|
256
362
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
@@ -259,29 +365,47 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
259
365
|
}
|
|
260
366
|
}
|
|
261
367
|
|
|
262
|
-
|
|
368
|
+
/**
|
|
369
|
+
* Validate a block proposal from a peer.
|
|
370
|
+
* Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
|
|
371
|
+
* @returns true if the proposal is valid, false otherwise
|
|
372
|
+
*/
|
|
373
|
+
async validateBlockProposal(proposal: BlockProposal, proposalSender: PeerId): Promise<boolean> {
|
|
263
374
|
const slotNumber = proposal.slotNumber;
|
|
375
|
+
|
|
376
|
+
// Note: During escape hatch, we still want to "validate" proposals for observability,
|
|
377
|
+
// but we intentionally reject them and disable slashing invalid block and attestation flow.
|
|
378
|
+
const escapeHatchOpen = await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber);
|
|
379
|
+
|
|
264
380
|
const proposer = proposal.getSender();
|
|
265
381
|
|
|
266
382
|
// Reject proposals with invalid signatures
|
|
267
383
|
if (!proposer) {
|
|
268
|
-
this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
|
|
269
|
-
return
|
|
384
|
+
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
385
|
+
return false;
|
|
270
386
|
}
|
|
271
387
|
|
|
272
|
-
//
|
|
388
|
+
// Ignore proposals from ourselves (may happen in HA setups)
|
|
389
|
+
if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
390
|
+
this.log.debug(`Ignoring block proposal from self for slot ${slotNumber}`, {
|
|
391
|
+
proposer: proposer.toString(),
|
|
392
|
+
slotNumber,
|
|
393
|
+
});
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Check if we're in the committee (for metrics purposes)
|
|
273
398
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
274
399
|
const partOfCommittee = inCommittee.length > 0;
|
|
275
400
|
|
|
276
401
|
const proposalInfo = { ...proposal.toBlockInfo(), proposer: proposer.toString() };
|
|
277
|
-
this.log.info(`Received proposal for slot ${slotNumber}`, {
|
|
402
|
+
this.log.info(`Received block proposal for slot ${slotNumber}`, {
|
|
278
403
|
...proposalInfo,
|
|
279
404
|
txHashes: proposal.txHashes.map(t => t.toString()),
|
|
280
405
|
fishermanMode: this.config.fishermanMode || false,
|
|
281
406
|
});
|
|
282
407
|
|
|
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.
|
|
408
|
+
// Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
|
|
285
409
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
286
410
|
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } =
|
|
287
411
|
this.config;
|
|
@@ -289,18 +413,20 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
289
413
|
fishermanMode ||
|
|
290
414
|
(slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute) ||
|
|
291
415
|
(partOfCommittee && validatorReexecute) ||
|
|
292
|
-
alwaysReexecuteBlockProposals
|
|
416
|
+
alwaysReexecuteBlockProposals ||
|
|
417
|
+
this.blobClient.canUpload();
|
|
293
418
|
|
|
294
419
|
const validationResult = await this.blockProposalHandler.handleBlockProposal(
|
|
295
420
|
proposal,
|
|
296
421
|
proposalSender,
|
|
297
|
-
!!shouldReexecute,
|
|
422
|
+
!!shouldReexecute && !escapeHatchOpen,
|
|
298
423
|
);
|
|
299
424
|
|
|
300
425
|
if (!validationResult.isValid) {
|
|
301
|
-
this.log.warn(`Proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
302
|
-
|
|
303
426
|
const reason = validationResult.reason || 'unknown';
|
|
427
|
+
|
|
428
|
+
this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
|
|
429
|
+
|
|
304
430
|
// Classify failure reason: bad proposal vs node issue
|
|
305
431
|
const badProposalReasons: BlockProposalValidationFailureReason[] = [
|
|
306
432
|
'invalid_proposal',
|
|
@@ -313,12 +439,13 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
313
439
|
if (badProposalReasons.includes(reason as BlockProposalValidationFailureReason)) {
|
|
314
440
|
this.metrics.incFailedAttestationsBadProposal(1, reason, partOfCommittee);
|
|
315
441
|
} else {
|
|
316
|
-
// Node issues so we can't
|
|
442
|
+
// Node issues so we can't validate
|
|
317
443
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
318
444
|
}
|
|
319
445
|
|
|
320
446
|
// Slash invalid block proposals (can happen even when not in committee)
|
|
321
447
|
if (
|
|
448
|
+
!escapeHatchOpen &&
|
|
322
449
|
validationResult.reason &&
|
|
323
450
|
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) &&
|
|
324
451
|
slashBroadcastedInvalidBlockPenalty > 0n
|
|
@@ -326,9 +453,96 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
326
453
|
this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
|
|
327
454
|
this.slashInvalidBlock(proposal);
|
|
328
455
|
}
|
|
456
|
+
return false;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
this.log.info(`Validated block proposal for slot ${slotNumber}`, {
|
|
460
|
+
...proposalInfo,
|
|
461
|
+
inCommittee: partOfCommittee,
|
|
462
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
463
|
+
escapeHatchOpen,
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
if (escapeHatchOpen) {
|
|
467
|
+
this.log.warn(`Escape hatch open for slot ${slotNumber}, rejecting block proposal`, proposalInfo);
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
return true;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Validate and attest to a checkpoint proposal from a peer.
|
|
476
|
+
* The proposal is received as CheckpointProposalCore (without lastBlock) since
|
|
477
|
+
* the lastBlock is extracted and processed separately via the block handler.
|
|
478
|
+
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
479
|
+
*/
|
|
480
|
+
async attestToCheckpointProposal(
|
|
481
|
+
proposal: CheckpointProposalCore,
|
|
482
|
+
_proposalSender: PeerId,
|
|
483
|
+
): Promise<CheckpointAttestation[] | undefined> {
|
|
484
|
+
const slotNumber = proposal.slotNumber;
|
|
485
|
+
const proposer = proposal.getSender();
|
|
486
|
+
|
|
487
|
+
// If escape hatch is open for this slot's epoch, do not attest.
|
|
488
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
|
|
489
|
+
this.log.warn(`Escape hatch open for slot ${slotNumber}, skipping checkpoint attestation handling`);
|
|
490
|
+
return undefined;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// Reject proposals with invalid signatures
|
|
494
|
+
if (!proposer) {
|
|
495
|
+
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
496
|
+
return undefined;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// Ignore proposals from ourselves (may happen in HA setups)
|
|
500
|
+
if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
501
|
+
this.log.debug(`Ignoring block proposal from self for slot ${slotNumber}`, {
|
|
502
|
+
proposer: proposer.toString(),
|
|
503
|
+
slotNumber,
|
|
504
|
+
});
|
|
505
|
+
return undefined;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// Validate fee asset price modifier is within allowed range
|
|
509
|
+
if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
|
|
510
|
+
this.log.warn(
|
|
511
|
+
`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`,
|
|
512
|
+
);
|
|
329
513
|
return undefined;
|
|
330
514
|
}
|
|
331
515
|
|
|
516
|
+
// Check that I have any address in current committee before attesting
|
|
517
|
+
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
518
|
+
const partOfCommittee = inCommittee.length > 0;
|
|
519
|
+
|
|
520
|
+
const proposalInfo = {
|
|
521
|
+
slotNumber,
|
|
522
|
+
archive: proposal.archive.toString(),
|
|
523
|
+
proposer: proposer.toString(),
|
|
524
|
+
};
|
|
525
|
+
this.log.info(`Received checkpoint proposal for slot ${slotNumber}`, {
|
|
526
|
+
...proposalInfo,
|
|
527
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
531
|
+
if (this.config.skipCheckpointProposalValidation) {
|
|
532
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
|
|
533
|
+
} else {
|
|
534
|
+
const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
|
|
535
|
+
if (!validationResult.isValid) {
|
|
536
|
+
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
537
|
+
return undefined;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// Upload blobs to filestore if we can (fire and forget)
|
|
542
|
+
if (this.blobClient.canUpload()) {
|
|
543
|
+
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
544
|
+
}
|
|
545
|
+
|
|
332
546
|
// Check that I have any address in current committee before attesting
|
|
333
547
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
334
548
|
if (!partOfCommittee && !this.config.fishermanMode) {
|
|
@@ -337,7 +551,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
337
551
|
}
|
|
338
552
|
|
|
339
553
|
// 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}`, {
|
|
554
|
+
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${slotNumber}`, {
|
|
341
555
|
...proposalInfo,
|
|
342
556
|
inCommittee: partOfCommittee,
|
|
343
557
|
fishermanMode: this.config.fishermanMode || false,
|
|
@@ -345,7 +559,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
345
559
|
|
|
346
560
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
347
561
|
|
|
348
|
-
//
|
|
562
|
+
// Track epoch participation per attester: count each (attester, epoch) pair at most once
|
|
563
|
+
const proposalEpoch = getEpochAtSlot(slotNumber, this.epochCache.getL1Constants());
|
|
564
|
+
for (const attester of inCommittee) {
|
|
565
|
+
const key = attester.toString();
|
|
566
|
+
const lastEpoch = this.lastAttestedEpochByAttester.get(key);
|
|
567
|
+
if (lastEpoch === undefined || proposalEpoch > lastEpoch) {
|
|
568
|
+
this.lastAttestedEpochByAttester.set(key, proposalEpoch);
|
|
569
|
+
this.metrics.incAttestedEpochCount(attester);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
349
573
|
// Determine which validators should attest
|
|
350
574
|
let attestors: EthAddress[];
|
|
351
575
|
if (partOfCommittee) {
|
|
@@ -364,13 +588,248 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
364
588
|
|
|
365
589
|
if (this.config.fishermanMode) {
|
|
366
590
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
367
|
-
this.log.info(`Creating attestations for
|
|
591
|
+
this.log.info(`Creating checkpoint attestations for slot ${slotNumber}`, {
|
|
368
592
|
...proposalInfo,
|
|
369
593
|
attestors: attestors.map(a => a.toString()),
|
|
370
594
|
});
|
|
371
595
|
return undefined;
|
|
372
596
|
}
|
|
373
|
-
|
|
597
|
+
|
|
598
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Checks if we should attest to a slot based on equivocation prevention rules.
|
|
603
|
+
* @returns true if we should attest, false if we should skip
|
|
604
|
+
*/
|
|
605
|
+
private shouldAttestToSlot(slotNumber: SlotNumber): boolean {
|
|
606
|
+
// If attestToEquivocatedProposals is true, always allow
|
|
607
|
+
if (this.config.attestToEquivocatedProposals) {
|
|
608
|
+
return true;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// Check if incoming slot is strictly greater than last attested
|
|
612
|
+
if (this.lastAttestedProposal && slotNumber <= this.lastAttestedProposal.slotNumber) {
|
|
613
|
+
this.log.warn(
|
|
614
|
+
`Refusing to process a proposal for slot ${slotNumber} given we already attested to a proposal for slot ${this.lastAttestedProposal.slotNumber}`,
|
|
615
|
+
);
|
|
616
|
+
return false;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
return true;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
private async createCheckpointAttestationsFromProposal(
|
|
623
|
+
proposal: CheckpointProposalCore,
|
|
624
|
+
attestors: EthAddress[] = [],
|
|
625
|
+
): Promise<CheckpointAttestation[] | undefined> {
|
|
626
|
+
// Equivocation check: must happen right before signing to minimize the race window
|
|
627
|
+
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
628
|
+
return undefined;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
632
|
+
|
|
633
|
+
// Track the proposal we attested to (to prevent equivocation)
|
|
634
|
+
this.lastAttestedProposal = proposal;
|
|
635
|
+
|
|
636
|
+
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
637
|
+
return attestations;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
642
|
+
* @returns Validation result with isValid flag and reason if invalid.
|
|
643
|
+
*/
|
|
644
|
+
private async validateCheckpointProposal(
|
|
645
|
+
proposal: CheckpointProposalCore,
|
|
646
|
+
proposalInfo: LogData,
|
|
647
|
+
): Promise<{ isValid: true } | { isValid: false; reason: string }> {
|
|
648
|
+
const slot = proposal.slotNumber;
|
|
649
|
+
|
|
650
|
+
// Timeout block syncing at the start of the next slot
|
|
651
|
+
const config = this.checkpointsBuilder.getConfig();
|
|
652
|
+
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
|
|
653
|
+
const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
|
|
654
|
+
|
|
655
|
+
// Wait for last block to sync by archive
|
|
656
|
+
let lastBlockHeader: BlockHeader | undefined;
|
|
657
|
+
try {
|
|
658
|
+
lastBlockHeader = await retryUntil(
|
|
659
|
+
async () => {
|
|
660
|
+
await this.blockSource.syncImmediate();
|
|
661
|
+
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
662
|
+
},
|
|
663
|
+
`waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`,
|
|
664
|
+
timeoutSeconds,
|
|
665
|
+
0.5,
|
|
666
|
+
);
|
|
667
|
+
} catch (err) {
|
|
668
|
+
if (err instanceof TimeoutError) {
|
|
669
|
+
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
670
|
+
return { isValid: false, reason: 'last_block_not_found' };
|
|
671
|
+
}
|
|
672
|
+
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
673
|
+
return { isValid: false, reason: 'block_fetch_error' };
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
if (!lastBlockHeader) {
|
|
677
|
+
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
678
|
+
return { isValid: false, reason: 'last_block_not_found' };
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// Get all full blocks for the slot and checkpoint
|
|
682
|
+
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
683
|
+
if (blocks.length === 0) {
|
|
684
|
+
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
685
|
+
return { isValid: false, reason: 'no_blocks_for_slot' };
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
689
|
+
if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
|
|
690
|
+
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
691
|
+
return { isValid: false, reason: 'last_block_archive_mismatch' };
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
695
|
+
...proposalInfo,
|
|
696
|
+
blockNumbers: blocks.map(b => b.number),
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
// Get checkpoint constants from first block
|
|
700
|
+
const firstBlock = blocks[0];
|
|
701
|
+
const constants = this.extractCheckpointConstants(firstBlock);
|
|
702
|
+
const checkpointNumber = firstBlock.checkpointNumber;
|
|
703
|
+
|
|
704
|
+
// Get L1-to-L2 messages for this checkpoint
|
|
705
|
+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
706
|
+
|
|
707
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
708
|
+
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
709
|
+
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch))
|
|
710
|
+
.filter(c => c.checkpointNumber < checkpointNumber)
|
|
711
|
+
.map(c => c.checkpointOutHash);
|
|
712
|
+
|
|
713
|
+
// Fork world state at the block before the first block
|
|
714
|
+
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
715
|
+
const fork = await this.worldState.fork(parentBlockNumber);
|
|
716
|
+
|
|
717
|
+
try {
|
|
718
|
+
// Create checkpoint builder with all existing blocks
|
|
719
|
+
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
|
|
720
|
+
checkpointNumber,
|
|
721
|
+
constants,
|
|
722
|
+
proposal.feeAssetPriceModifier,
|
|
723
|
+
l1ToL2Messages,
|
|
724
|
+
previousCheckpointOutHashes,
|
|
725
|
+
fork,
|
|
726
|
+
blocks,
|
|
727
|
+
this.log.getBindings(),
|
|
728
|
+
);
|
|
729
|
+
|
|
730
|
+
// Complete the checkpoint to get computed values
|
|
731
|
+
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
732
|
+
|
|
733
|
+
// Compare checkpoint header with proposal
|
|
734
|
+
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
735
|
+
this.log.warn(`Checkpoint header mismatch`, {
|
|
736
|
+
...proposalInfo,
|
|
737
|
+
computed: computedCheckpoint.header.toInspect(),
|
|
738
|
+
proposal: proposal.checkpointHeader.toInspect(),
|
|
739
|
+
});
|
|
740
|
+
return { isValid: false, reason: 'checkpoint_header_mismatch' };
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// Compare archive root with proposal
|
|
744
|
+
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
745
|
+
this.log.warn(`Archive root mismatch`, {
|
|
746
|
+
...proposalInfo,
|
|
747
|
+
computed: computedCheckpoint.archive.root.toString(),
|
|
748
|
+
proposal: proposal.archive.toString(),
|
|
749
|
+
});
|
|
750
|
+
return { isValid: false, reason: 'archive_mismatch' };
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
754
|
+
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
755
|
+
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
756
|
+
const computedEpochOutHash = accumulateCheckpointOutHashes([...previousCheckpointOutHashes, checkpointOutHash]);
|
|
757
|
+
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
758
|
+
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
759
|
+
this.log.warn(`Epoch out hash mismatch`, {
|
|
760
|
+
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
761
|
+
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
762
|
+
checkpointOutHash: checkpointOutHash.toString(),
|
|
763
|
+
previousCheckpointOutHashes: previousCheckpointOutHashes.map(h => h.toString()),
|
|
764
|
+
...proposalInfo,
|
|
765
|
+
});
|
|
766
|
+
return { isValid: false, reason: 'out_hash_mismatch' };
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
// Final round of validations on the checkpoint, just in case.
|
|
770
|
+
try {
|
|
771
|
+
validateCheckpoint(computedCheckpoint, {
|
|
772
|
+
rollupManaLimit: this.checkpointsBuilder.getConfig().rollupManaLimit,
|
|
773
|
+
maxDABlockGas: this.config.validateMaxDABlockGas,
|
|
774
|
+
maxL2BlockGas: this.config.validateMaxL2BlockGas,
|
|
775
|
+
maxTxsPerBlock: this.config.validateMaxTxsPerBlock,
|
|
776
|
+
maxTxsPerCheckpoint: this.config.validateMaxTxsPerCheckpoint,
|
|
777
|
+
});
|
|
778
|
+
} catch (err) {
|
|
779
|
+
this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
|
|
780
|
+
return { isValid: false, reason: 'checkpoint_validation_failed' };
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
784
|
+
return { isValid: true };
|
|
785
|
+
} finally {
|
|
786
|
+
await fork.close();
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* Extract checkpoint global variables from a block.
|
|
792
|
+
*/
|
|
793
|
+
private extractCheckpointConstants(block: L2Block): CheckpointGlobalVariables {
|
|
794
|
+
const gv = block.header.globalVariables;
|
|
795
|
+
return {
|
|
796
|
+
chainId: gv.chainId,
|
|
797
|
+
version: gv.version,
|
|
798
|
+
slotNumber: gv.slotNumber,
|
|
799
|
+
timestamp: gv.timestamp,
|
|
800
|
+
coinbase: gv.coinbase,
|
|
801
|
+
feeRecipient: gv.feeRecipient,
|
|
802
|
+
gasFees: gv.gasFees,
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
808
|
+
*/
|
|
809
|
+
protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
|
|
810
|
+
try {
|
|
811
|
+
const lastBlockHeader = await this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
812
|
+
if (!lastBlockHeader) {
|
|
813
|
+
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
const blocks = await this.blockSource.getBlocksForSlot(proposal.slotNumber);
|
|
818
|
+
if (blocks.length === 0) {
|
|
819
|
+
this.log.warn(`No blocks found for blob upload`, proposalInfo);
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
const blobFields = blocks.flatMap(b => b.toBlobFields());
|
|
824
|
+
const blobs: Blob[] = await getBlobsPerL1Block(blobFields);
|
|
825
|
+
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
826
|
+
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
827
|
+
...proposalInfo,
|
|
828
|
+
numBlobs: blobs.length,
|
|
829
|
+
});
|
|
830
|
+
} catch (err) {
|
|
831
|
+
this.log.warn(`Failed to upload blobs for checkpoint: ${err}`, proposalInfo);
|
|
832
|
+
}
|
|
374
833
|
}
|
|
375
834
|
|
|
376
835
|
private slashInvalidBlock(proposal: BlockProposal) {
|
|
@@ -400,24 +859,125 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
400
859
|
]);
|
|
401
860
|
}
|
|
402
861
|
|
|
862
|
+
/**
|
|
863
|
+
* Handle detection of a duplicate proposal (equivocation).
|
|
864
|
+
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
865
|
+
*/
|
|
866
|
+
private handleDuplicateProposal(info: DuplicateProposalInfo): void {
|
|
867
|
+
const { slot, proposer, type } = info;
|
|
868
|
+
|
|
869
|
+
this.log.warn(`Triggering slash event for duplicate ${type} proposal from ${proposer.toString()} at slot ${slot}`, {
|
|
870
|
+
proposer: proposer.toString(),
|
|
871
|
+
slot,
|
|
872
|
+
type,
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
// Emit slash event
|
|
876
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
877
|
+
{
|
|
878
|
+
validator: proposer,
|
|
879
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
880
|
+
offenseType: OffenseType.DUPLICATE_PROPOSAL,
|
|
881
|
+
epochOrSlot: BigInt(slot),
|
|
882
|
+
},
|
|
883
|
+
]);
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
/**
|
|
887
|
+
* Handle detection of a duplicate attestation (equivocation).
|
|
888
|
+
* Emits a slash event when an attester signs attestations for different proposals at the same slot.
|
|
889
|
+
*/
|
|
890
|
+
private handleDuplicateAttestation(info: DuplicateAttestationInfo): void {
|
|
891
|
+
const { slot, attester } = info;
|
|
892
|
+
|
|
893
|
+
this.log.warn(`Triggering slash event for duplicate attestation from ${attester.toString()} at slot ${slot}`, {
|
|
894
|
+
attester: attester.toString(),
|
|
895
|
+
slot,
|
|
896
|
+
});
|
|
897
|
+
|
|
898
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
899
|
+
{
|
|
900
|
+
validator: attester,
|
|
901
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
902
|
+
offenseType: OffenseType.DUPLICATE_ATTESTATION,
|
|
903
|
+
epochOrSlot: BigInt(slot),
|
|
904
|
+
},
|
|
905
|
+
]);
|
|
906
|
+
}
|
|
907
|
+
|
|
403
908
|
async createBlockProposal(
|
|
404
|
-
|
|
405
|
-
|
|
909
|
+
blockHeader: BlockHeader,
|
|
910
|
+
indexWithinCheckpoint: IndexWithinCheckpoint,
|
|
911
|
+
inHash: Fr,
|
|
406
912
|
archive: Fr,
|
|
407
913
|
txs: Tx[],
|
|
408
914
|
proposerAddress: EthAddress | undefined,
|
|
409
|
-
options: BlockProposalOptions,
|
|
410
|
-
): Promise<BlockProposal
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
915
|
+
options: BlockProposalOptions = {},
|
|
916
|
+
): Promise<BlockProposal> {
|
|
917
|
+
// Validate that we're not creating a proposal for an older or equal position
|
|
918
|
+
if (this.lastProposedBlock) {
|
|
919
|
+
const lastSlot = this.lastProposedBlock.slotNumber;
|
|
920
|
+
const lastIndex = this.lastProposedBlock.indexWithinCheckpoint;
|
|
921
|
+
const newSlot = blockHeader.globalVariables.slotNumber;
|
|
922
|
+
|
|
923
|
+
if (newSlot < lastSlot || (newSlot === lastSlot && indexWithinCheckpoint <= lastIndex)) {
|
|
924
|
+
throw new Error(
|
|
925
|
+
`Cannot create block proposal for slot ${newSlot} index ${indexWithinCheckpoint}: ` +
|
|
926
|
+
`already proposed block for slot ${lastSlot} index ${lastIndex}`,
|
|
927
|
+
);
|
|
928
|
+
}
|
|
414
929
|
}
|
|
415
930
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
931
|
+
this.log.info(
|
|
932
|
+
`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`,
|
|
933
|
+
);
|
|
934
|
+
const newProposal = await this.validationService.createBlockProposal(
|
|
935
|
+
blockHeader,
|
|
936
|
+
indexWithinCheckpoint,
|
|
937
|
+
inHash,
|
|
938
|
+
archive,
|
|
939
|
+
txs,
|
|
940
|
+
proposerAddress,
|
|
941
|
+
{
|
|
942
|
+
...options,
|
|
943
|
+
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal,
|
|
944
|
+
},
|
|
945
|
+
);
|
|
946
|
+
this.lastProposedBlock = newProposal;
|
|
947
|
+
return newProposal;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
async createCheckpointProposal(
|
|
951
|
+
checkpointHeader: CheckpointHeader,
|
|
952
|
+
archive: Fr,
|
|
953
|
+
feeAssetPriceModifier: bigint,
|
|
954
|
+
lastBlockInfo: CreateCheckpointProposalLastBlockData | undefined,
|
|
955
|
+
proposerAddress: EthAddress | undefined,
|
|
956
|
+
options: CheckpointProposalOptions = {},
|
|
957
|
+
): Promise<CheckpointProposal> {
|
|
958
|
+
// Validate that we're not creating a proposal for an older or equal slot
|
|
959
|
+
if (this.lastProposedCheckpoint) {
|
|
960
|
+
const lastSlot = this.lastProposedCheckpoint.slotNumber;
|
|
961
|
+
const newSlot = checkpointHeader.slotNumber;
|
|
962
|
+
|
|
963
|
+
if (newSlot <= lastSlot) {
|
|
964
|
+
throw new Error(
|
|
965
|
+
`Cannot create checkpoint proposal for slot ${newSlot}: ` +
|
|
966
|
+
`already proposed checkpoint for slot ${lastSlot}`,
|
|
967
|
+
);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
972
|
+
const newProposal = await this.validationService.createCheckpointProposal(
|
|
973
|
+
checkpointHeader,
|
|
974
|
+
archive,
|
|
975
|
+
feeAssetPriceModifier,
|
|
976
|
+
lastBlockInfo,
|
|
977
|
+
proposerAddress,
|
|
978
|
+
options,
|
|
979
|
+
);
|
|
980
|
+
this.lastProposedCheckpoint = newProposal;
|
|
421
981
|
return newProposal;
|
|
422
982
|
}
|
|
423
983
|
|
|
@@ -428,28 +988,38 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
428
988
|
async signAttestationsAndSigners(
|
|
429
989
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
430
990
|
proposer: EthAddress,
|
|
991
|
+
slot: SlotNumber,
|
|
992
|
+
blockNumber: BlockNumber | CheckpointNumber,
|
|
431
993
|
): Promise<Signature> {
|
|
432
|
-
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
|
|
994
|
+
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
|
|
433
995
|
}
|
|
434
996
|
|
|
435
|
-
async collectOwnAttestations(proposal:
|
|
436
|
-
const slot = proposal.
|
|
997
|
+
async collectOwnAttestations(proposal: CheckpointProposal): Promise<CheckpointAttestation[]> {
|
|
998
|
+
const slot = proposal.slotNumber;
|
|
437
999
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
438
1000
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, { inCommittee });
|
|
439
|
-
const attestations = await this.
|
|
1001
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
1002
|
+
|
|
1003
|
+
if (!attestations) {
|
|
1004
|
+
return [];
|
|
1005
|
+
}
|
|
440
1006
|
|
|
441
1007
|
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
442
1008
|
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
443
1009
|
// due to inactivity for missed attestations.
|
|
444
|
-
void this.p2pClient.
|
|
1010
|
+
void this.p2pClient.broadcastCheckpointAttestations(attestations).catch(err => {
|
|
445
1011
|
this.log.error(`Failed to broadcast self-attestations for slot ${slot}`, err);
|
|
446
1012
|
});
|
|
447
1013
|
return attestations;
|
|
448
1014
|
}
|
|
449
1015
|
|
|
450
|
-
async collectAttestations(
|
|
451
|
-
|
|
452
|
-
|
|
1016
|
+
async collectAttestations(
|
|
1017
|
+
proposal: CheckpointProposal,
|
|
1018
|
+
required: number,
|
|
1019
|
+
deadline: Date,
|
|
1020
|
+
): Promise<CheckpointAttestation[]> {
|
|
1021
|
+
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
1022
|
+
const slot = proposal.slotNumber;
|
|
453
1023
|
this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
|
|
454
1024
|
|
|
455
1025
|
if (+deadline < this.dateProvider.now()) {
|
|
@@ -464,16 +1034,16 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
464
1034
|
const proposalId = proposal.archive.toString();
|
|
465
1035
|
const myAddresses = this.getValidatorAddresses();
|
|
466
1036
|
|
|
467
|
-
let attestations:
|
|
1037
|
+
let attestations: CheckpointAttestation[] = [];
|
|
468
1038
|
while (true) {
|
|
469
|
-
// Filter out attestations with a mismatching
|
|
1039
|
+
// Filter out attestations with a mismatching archive. This should NOT happen since we have verified
|
|
470
1040
|
// the proposer signature (ie our own) before accepting the attestation into the pool via the p2p client.
|
|
471
|
-
const collectedAttestations = (await this.p2pClient.
|
|
1041
|
+
const collectedAttestations = (await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalId)).filter(
|
|
472
1042
|
attestation => {
|
|
473
|
-
if (!attestation.
|
|
1043
|
+
if (!attestation.archive.equals(proposal.archive)) {
|
|
474
1044
|
this.log.warn(
|
|
475
|
-
`Received attestation for slot ${slot} with mismatched
|
|
476
|
-
{
|
|
1045
|
+
`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`,
|
|
1046
|
+
{ attestationArchive: attestation.archive.toString(), proposalArchive: proposal.archive.toString() },
|
|
477
1047
|
);
|
|
478
1048
|
return false;
|
|
479
1049
|
}
|
|
@@ -514,15 +1084,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
514
1084
|
}
|
|
515
1085
|
}
|
|
516
1086
|
|
|
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
1087
|
private async handleAuthRequest(peer: PeerId, msg: Buffer): Promise<Buffer> {
|
|
527
1088
|
const authRequest = AuthRequest.fromBuffer(msg);
|
|
528
1089
|
const statusMessage = await this.p2pClient.handleAuthRequestFromPeer(authRequest, peer).catch(_ => undefined);
|
|
@@ -541,7 +1102,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
541
1102
|
}
|
|
542
1103
|
|
|
543
1104
|
const payloadToSign = authRequest.getPayloadToSign();
|
|
544
|
-
|
|
1105
|
+
// AUTH_REQUEST doesn't require HA protection - multiple signatures are safe
|
|
1106
|
+
const context: SigningContext = { dutyType: DutyType.AUTH_REQUEST };
|
|
1107
|
+
const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign, context);
|
|
545
1108
|
const authResponse = new AuthResponse(statusMessage, signature);
|
|
546
1109
|
return authResponse.toBuffer();
|
|
547
1110
|
}
|