@aztec/validator-client 0.0.1-commit.96bb3f7 → 0.0.1-commit.993d52e
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 +53 -24
- package/dest/block_proposal_handler.d.ts +9 -9
- package/dest/block_proposal_handler.d.ts.map +1 -1
- package/dest/block_proposal_handler.js +35 -54
- package/dest/checkpoint_builder.d.ts +24 -25
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +61 -36
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +12 -14
- package/dest/duties/validation_service.d.ts +20 -7
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +75 -22
- package/dest/factory.d.ts +2 -2
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +3 -2
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/key_store/ha_key_store.d.ts +99 -0
- package/dest/key_store/ha_key_store.d.ts.map +1 -0
- package/dest/key_store/ha_key_store.js +208 -0
- package/dest/key_store/index.d.ts +2 -1
- package/dest/key_store/index.d.ts.map +1 -1
- package/dest/key_store/index.js +1 -0
- package/dest/key_store/interface.d.ts +36 -6
- package/dest/key_store/interface.d.ts.map +1 -1
- package/dest/key_store/local_key_store.d.ts +10 -5
- package/dest/key_store/local_key_store.d.ts.map +1 -1
- package/dest/key_store/local_key_store.js +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 -5
- package/dest/validator.d.ts +45 -18
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +244 -95
- package/package.json +21 -17
- package/src/block_proposal_handler.ts +48 -69
- package/src/checkpoint_builder.ts +103 -42
- package/src/config.ts +11 -13
- package/src/duties/validation_service.ts +100 -25
- package/src/factory.ts +2 -0
- package/src/index.ts +0 -1
- package/src/key_store/ha_key_store.ts +269 -0
- package/src/key_store/index.ts +1 -0
- package/src/key_store/interface.ts +44 -5
- package/src/key_store/local_key_store.ts +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 -6
- package/src/validator.ts +318 -114
- package/dest/tx_validator/index.d.ts +0 -3
- package/dest/tx_validator/index.d.ts.map +0 -1
- package/dest/tx_validator/index.js +0 -2
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -53
- package/src/tx_validator/index.ts +0 -2
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -133
package/src/validator.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
2
2
|
import { type Blob, getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
3
3
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
4
|
-
import {
|
|
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';
|
|
5
12
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
13
|
import { TimeoutError } from '@aztec/foundation/error';
|
|
7
14
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
@@ -12,30 +19,35 @@ import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
|
12
19
|
import { sleep } from '@aztec/foundation/sleep';
|
|
13
20
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
14
21
|
import type { KeystoreManager } from '@aztec/node-keystore';
|
|
15
|
-
import type { P2P, PeerId
|
|
22
|
+
import type { DuplicateAttestationInfo, DuplicateProposalInfo, P2P, PeerId } from '@aztec/p2p';
|
|
16
23
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
17
24
|
import { OffenseType, WANT_TO_SLASH_EVENT, type Watcher, type WatcherEmitter } from '@aztec/slasher';
|
|
18
25
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
19
|
-
import type { CommitteeAttestationsAndSigners,
|
|
26
|
+
import type { CommitteeAttestationsAndSigners, L2Block, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
27
|
+
import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
20
28
|
import type {
|
|
21
29
|
CreateCheckpointProposalLastBlockData,
|
|
30
|
+
ITxProvider,
|
|
22
31
|
Validator,
|
|
23
32
|
ValidatorClientFullConfig,
|
|
24
33
|
WorldStateSynchronizer,
|
|
25
34
|
} from '@aztec/stdlib/interfaces/server';
|
|
26
|
-
import type
|
|
27
|
-
import
|
|
28
|
-
BlockProposal,
|
|
29
|
-
BlockProposalOptions,
|
|
30
|
-
CheckpointAttestation,
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
import { type L1ToL2MessageSource, accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
|
|
36
|
+
import {
|
|
37
|
+
type BlockProposal,
|
|
38
|
+
type BlockProposalOptions,
|
|
39
|
+
type CheckpointAttestation,
|
|
40
|
+
CheckpointProposal,
|
|
41
|
+
type CheckpointProposalCore,
|
|
42
|
+
type CheckpointProposalOptions,
|
|
33
43
|
} from '@aztec/stdlib/p2p';
|
|
34
|
-
import { CheckpointProposal } from '@aztec/stdlib/p2p';
|
|
35
44
|
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
36
45
|
import type { BlockHeader, CheckpointGlobalVariables, Tx } from '@aztec/stdlib/tx';
|
|
37
46
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
38
47
|
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
48
|
+
import { createHASigner } from '@aztec/validator-ha-signer/factory';
|
|
49
|
+
import { DutyType, type SigningContext } from '@aztec/validator-ha-signer/types';
|
|
50
|
+
import type { ValidatorHASigner } from '@aztec/validator-ha-signer/validator-ha-signer';
|
|
39
51
|
|
|
40
52
|
import { EventEmitter } from 'events';
|
|
41
53
|
import type { TypedDataDefinition } from 'viem';
|
|
@@ -43,6 +55,8 @@ import type { TypedDataDefinition } from 'viem';
|
|
|
43
55
|
import { BlockProposalHandler, type BlockProposalValidationFailureReason } from './block_proposal_handler.js';
|
|
44
56
|
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
45
57
|
import { ValidationService } from './duties/validation_service.js';
|
|
58
|
+
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
59
|
+
import type { ExtendedValidatorKeyStore } from './key_store/interface.js';
|
|
46
60
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
47
61
|
import { ValidatorMetrics } from './metrics.js';
|
|
48
62
|
|
|
@@ -64,25 +78,27 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
64
78
|
private validationService: ValidationService;
|
|
65
79
|
private metrics: ValidatorMetrics;
|
|
66
80
|
private log: Logger;
|
|
67
|
-
|
|
68
81
|
// Whether it has already registered handlers on the p2p client
|
|
69
82
|
private hasRegisteredHandlers = false;
|
|
70
83
|
|
|
71
|
-
|
|
72
|
-
private
|
|
84
|
+
/** Tracks the last block proposal we created, to detect duplicate proposal attempts. */
|
|
85
|
+
private lastProposedBlock?: BlockProposal;
|
|
86
|
+
|
|
87
|
+
/** Tracks the last checkpoint proposal we created. */
|
|
88
|
+
private lastProposedCheckpoint?: CheckpointProposal;
|
|
73
89
|
|
|
74
90
|
private lastEpochForCommitteeUpdateLoop: EpochNumber | undefined;
|
|
75
91
|
private epochCacheUpdateLoop: RunningPromise;
|
|
92
|
+
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */
|
|
93
|
+
private lastAttestedEpochByAttester: Map<string, EpochNumber> = new Map();
|
|
76
94
|
|
|
77
95
|
private proposersOfInvalidBlocks: Set<string> = new Set();
|
|
78
96
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
82
|
-
private validatedBlockSlots: Set<SlotNumber> = new Set();
|
|
97
|
+
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */
|
|
98
|
+
private lastAttestedProposal?: CheckpointProposalCore;
|
|
83
99
|
|
|
84
100
|
protected constructor(
|
|
85
|
-
private keyStore:
|
|
101
|
+
private keyStore: ExtendedValidatorKeyStore,
|
|
86
102
|
private epochCache: EpochCache,
|
|
87
103
|
private p2pClient: P2P,
|
|
88
104
|
private blockProposalHandler: BlockProposalHandler,
|
|
@@ -92,6 +108,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
92
108
|
private l1ToL2MessageSource: L1ToL2MessageSource,
|
|
93
109
|
private config: ValidatorClientFullConfig,
|
|
94
110
|
private blobClient: BlobClientInterface,
|
|
111
|
+
private haSigner: ValidatorHASigner | undefined,
|
|
95
112
|
private dateProvider: DateProvider = new DateProvider(),
|
|
96
113
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
97
114
|
log = createLogger('validator'),
|
|
@@ -145,6 +162,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
145
162
|
this.log.trace(`No committee found for slot`);
|
|
146
163
|
return;
|
|
147
164
|
}
|
|
165
|
+
this.metrics.setCurrentEpoch(epoch);
|
|
148
166
|
if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
|
|
149
167
|
const me = this.getValidatorAddresses();
|
|
150
168
|
const committeeSet = new Set(committee.map(v => v.toString()));
|
|
@@ -165,7 +183,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
165
183
|
}
|
|
166
184
|
}
|
|
167
185
|
|
|
168
|
-
static new(
|
|
186
|
+
static async new(
|
|
169
187
|
config: ValidatorClientFullConfig,
|
|
170
188
|
checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
171
189
|
worldState: WorldStateSynchronizer,
|
|
@@ -173,7 +191,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
173
191
|
p2pClient: P2P,
|
|
174
192
|
blockSource: L2BlockSource & L2BlockSink,
|
|
175
193
|
l1ToL2MessageSource: L1ToL2MessageSource,
|
|
176
|
-
txProvider:
|
|
194
|
+
txProvider: ITxProvider,
|
|
177
195
|
keyStoreManager: KeystoreManager,
|
|
178
196
|
blobClient: BlobClientInterface,
|
|
179
197
|
dateProvider: DateProvider = new DateProvider(),
|
|
@@ -182,6 +200,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
182
200
|
const metrics = new ValidatorMetrics(telemetry);
|
|
183
201
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
184
202
|
txsPermitted: !config.disableTransactions,
|
|
203
|
+
maxTxsPerBlock: config.maxTxsPerBlock,
|
|
185
204
|
});
|
|
186
205
|
const blockProposalHandler = new BlockProposalHandler(
|
|
187
206
|
checkpointsBuilder,
|
|
@@ -190,14 +209,29 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
190
209
|
l1ToL2MessageSource,
|
|
191
210
|
txProvider,
|
|
192
211
|
blockProposalValidator,
|
|
212
|
+
epochCache,
|
|
193
213
|
config,
|
|
194
214
|
metrics,
|
|
195
215
|
dateProvider,
|
|
196
216
|
telemetry,
|
|
197
217
|
);
|
|
198
218
|
|
|
219
|
+
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
220
|
+
let validatorKeyStore: ExtendedValidatorKeyStore = nodeKeystoreAdapter;
|
|
221
|
+
let haSigner: ValidatorHASigner | undefined;
|
|
222
|
+
if (config.haSigningEnabled) {
|
|
223
|
+
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
224
|
+
const haConfig = {
|
|
225
|
+
...config,
|
|
226
|
+
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000,
|
|
227
|
+
};
|
|
228
|
+
const { signer } = await createHASigner(haConfig);
|
|
229
|
+
haSigner = signer;
|
|
230
|
+
validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, signer);
|
|
231
|
+
}
|
|
232
|
+
|
|
199
233
|
const validator = new ValidatorClient(
|
|
200
|
-
|
|
234
|
+
validatorKeyStore,
|
|
201
235
|
epochCache,
|
|
202
236
|
p2pClient,
|
|
203
237
|
blockProposalHandler,
|
|
@@ -207,6 +241,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
207
241
|
l1ToL2MessageSource,
|
|
208
242
|
config,
|
|
209
243
|
blobClient,
|
|
244
|
+
haSigner,
|
|
210
245
|
dateProvider,
|
|
211
246
|
telemetry,
|
|
212
247
|
);
|
|
@@ -224,8 +259,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
224
259
|
return this.blockProposalHandler;
|
|
225
260
|
}
|
|
226
261
|
|
|
227
|
-
public signWithAddress(addr: EthAddress, msg: TypedDataDefinition) {
|
|
228
|
-
return this.keyStore.signTypedDataWithAddress(addr, msg);
|
|
262
|
+
public signWithAddress(addr: EthAddress, msg: TypedDataDefinition, context: SigningContext) {
|
|
263
|
+
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
229
264
|
}
|
|
230
265
|
|
|
231
266
|
public getCoinbaseForAttestor(attestor: EthAddress): EthAddress {
|
|
@@ -244,12 +279,36 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
244
279
|
this.config = { ...this.config, ...config };
|
|
245
280
|
}
|
|
246
281
|
|
|
282
|
+
public reloadKeystore(newManager: KeystoreManager): void {
|
|
283
|
+
if (this.config.haSigningEnabled && !this.haSigner) {
|
|
284
|
+
this.log.warn(
|
|
285
|
+
'HA signing is enabled in config but was not initialized at startup. ' +
|
|
286
|
+
'Restart the node to enable HA signing.',
|
|
287
|
+
);
|
|
288
|
+
} else if (!this.config.haSigningEnabled && this.haSigner) {
|
|
289
|
+
this.log.warn(
|
|
290
|
+
'HA signing was disabled via config update but the HA signer is still active. ' +
|
|
291
|
+
'Restart the node to fully disable HA signing.',
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
296
|
+
if (this.haSigner) {
|
|
297
|
+
this.keyStore = new HAKeyStore(newAdapter, this.haSigner);
|
|
298
|
+
} else {
|
|
299
|
+
this.keyStore = newAdapter;
|
|
300
|
+
}
|
|
301
|
+
this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
|
|
302
|
+
}
|
|
303
|
+
|
|
247
304
|
public async start() {
|
|
248
305
|
if (this.epochCacheUpdateLoop.isRunning()) {
|
|
249
306
|
this.log.warn(`Validator client already started`);
|
|
250
307
|
return;
|
|
251
308
|
}
|
|
252
309
|
|
|
310
|
+
await this.keyStore.start();
|
|
311
|
+
|
|
253
312
|
await this.registerHandlers();
|
|
254
313
|
|
|
255
314
|
const myAddresses = this.getValidatorAddresses();
|
|
@@ -265,6 +324,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
265
324
|
|
|
266
325
|
public async stop() {
|
|
267
326
|
await this.epochCacheUpdateLoop.stop();
|
|
327
|
+
await this.keyStore.stop();
|
|
268
328
|
}
|
|
269
329
|
|
|
270
330
|
/** Register handlers on the p2p client */
|
|
@@ -287,6 +347,16 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
287
347
|
): Promise<CheckpointAttestation[] | undefined> => this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
288
348
|
this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
|
|
289
349
|
|
|
350
|
+
// Duplicate proposal handler - triggers slashing for equivocation
|
|
351
|
+
this.p2pClient.registerDuplicateProposalCallback((info: DuplicateProposalInfo) => {
|
|
352
|
+
this.handleDuplicateProposal(info);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
// Duplicate attestation handler - triggers slashing for attestation equivocation
|
|
356
|
+
this.p2pClient.registerDuplicateAttestationCallback((info: DuplicateAttestationInfo) => {
|
|
357
|
+
this.handleDuplicateAttestation(info);
|
|
358
|
+
});
|
|
359
|
+
|
|
290
360
|
const myAddresses = this.getValidatorAddresses();
|
|
291
361
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
292
362
|
|
|
@@ -301,6 +371,11 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
301
371
|
*/
|
|
302
372
|
async validateBlockProposal(proposal: BlockProposal, proposalSender: PeerId): Promise<boolean> {
|
|
303
373
|
const slotNumber = proposal.slotNumber;
|
|
374
|
+
|
|
375
|
+
// Note: During escape hatch, we still want to "validate" proposals for observability,
|
|
376
|
+
// but we intentionally reject them and disable slashing invalid block and attestation flow.
|
|
377
|
+
const escapeHatchOpen = await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber);
|
|
378
|
+
|
|
304
379
|
const proposer = proposal.getSender();
|
|
305
380
|
|
|
306
381
|
// Reject proposals with invalid signatures
|
|
@@ -309,6 +384,15 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
309
384
|
return false;
|
|
310
385
|
}
|
|
311
386
|
|
|
387
|
+
// Ignore proposals from ourselves (may happen in HA setups)
|
|
388
|
+
if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
389
|
+
this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
|
|
390
|
+
proposer: proposer.toString(),
|
|
391
|
+
slotNumber,
|
|
392
|
+
});
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
|
|
312
396
|
// Check if we're in the committee (for metrics purposes)
|
|
313
397
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
314
398
|
const partOfCommittee = inCommittee.length > 0;
|
|
@@ -334,7 +418,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
334
418
|
const validationResult = await this.blockProposalHandler.handleBlockProposal(
|
|
335
419
|
proposal,
|
|
336
420
|
proposalSender,
|
|
337
|
-
!!shouldReexecute,
|
|
421
|
+
!!shouldReexecute && !escapeHatchOpen,
|
|
338
422
|
);
|
|
339
423
|
|
|
340
424
|
if (!validationResult.isValid) {
|
|
@@ -359,6 +443,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
359
443
|
|
|
360
444
|
// Slash invalid block proposals (can happen even when not in committee)
|
|
361
445
|
if (
|
|
446
|
+
!escapeHatchOpen &&
|
|
362
447
|
validationResult.reason &&
|
|
363
448
|
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) &&
|
|
364
449
|
slashBroadcastedInvalidBlockPenalty > 0n
|
|
@@ -373,11 +458,13 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
373
458
|
...proposalInfo,
|
|
374
459
|
inCommittee: partOfCommittee,
|
|
375
460
|
fishermanMode: this.config.fishermanMode || false,
|
|
461
|
+
escapeHatchOpen,
|
|
376
462
|
});
|
|
377
463
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
464
|
+
if (escapeHatchOpen) {
|
|
465
|
+
this.log.warn(`Escape hatch open for slot ${slotNumber}, rejecting block proposal`, proposalInfo);
|
|
466
|
+
return false;
|
|
467
|
+
}
|
|
381
468
|
|
|
382
469
|
return true;
|
|
383
470
|
}
|
|
@@ -395,12 +482,35 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
395
482
|
const slotNumber = proposal.slotNumber;
|
|
396
483
|
const proposer = proposal.getSender();
|
|
397
484
|
|
|
485
|
+
// If escape hatch is open for this slot's epoch, do not attest.
|
|
486
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
|
|
487
|
+
this.log.warn(`Escape hatch open for slot ${slotNumber}, skipping checkpoint attestation handling`);
|
|
488
|
+
return undefined;
|
|
489
|
+
}
|
|
490
|
+
|
|
398
491
|
// Reject proposals with invalid signatures
|
|
399
492
|
if (!proposer) {
|
|
400
493
|
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
401
494
|
return undefined;
|
|
402
495
|
}
|
|
403
496
|
|
|
497
|
+
// Ignore proposals from ourselves (may happen in HA setups)
|
|
498
|
+
if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
499
|
+
this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
|
|
500
|
+
proposer: proposer.toString(),
|
|
501
|
+
slotNumber,
|
|
502
|
+
});
|
|
503
|
+
return undefined;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// Validate fee asset price modifier is within allowed range
|
|
507
|
+
if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
|
|
508
|
+
this.log.warn(
|
|
509
|
+
`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`,
|
|
510
|
+
);
|
|
511
|
+
return undefined;
|
|
512
|
+
}
|
|
513
|
+
|
|
404
514
|
// Check that I have any address in current committee before attesting
|
|
405
515
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
406
516
|
const partOfCommittee = inCommittee.length > 0;
|
|
@@ -417,17 +527,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
417
527
|
fishermanMode: this.config.fishermanMode || false,
|
|
418
528
|
});
|
|
419
529
|
|
|
420
|
-
// TODO(palla/mbps): Remove this once checkpoint validation is stable.
|
|
421
|
-
// Check that we have successfully validated a block for this slot before attesting to the checkpoint.
|
|
422
|
-
if (!this.validatedBlockSlots.has(slotNumber)) {
|
|
423
|
-
this.log.warn(`No validated block found for slot ${slotNumber}, refusing to attest to checkpoint`, proposalInfo);
|
|
424
|
-
return undefined;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
530
|
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
this.log.verbose(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
|
|
531
|
+
if (this.config.skipCheckpointProposalValidation) {
|
|
532
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
|
|
431
533
|
} else {
|
|
432
534
|
const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
|
|
433
535
|
if (!validationResult.isValid) {
|
|
@@ -457,6 +559,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
457
559
|
|
|
458
560
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
459
561
|
|
|
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
|
+
|
|
460
573
|
// Determine which validators should attest
|
|
461
574
|
let attestors: EthAddress[];
|
|
462
575
|
if (partOfCommittee) {
|
|
@@ -482,15 +595,45 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
482
595
|
return undefined;
|
|
483
596
|
}
|
|
484
597
|
|
|
485
|
-
return this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
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;
|
|
486
620
|
}
|
|
487
621
|
|
|
488
622
|
private async createCheckpointAttestationsFromProposal(
|
|
489
623
|
proposal: CheckpointProposalCore,
|
|
490
624
|
attestors: EthAddress[] = [],
|
|
491
|
-
): Promise<CheckpointAttestation[]> {
|
|
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
|
+
|
|
492
631
|
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
493
|
-
|
|
632
|
+
|
|
633
|
+
// Track the proposal we attested to (to prevent equivocation)
|
|
634
|
+
this.lastAttestedProposal = proposal;
|
|
635
|
+
|
|
636
|
+
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
494
637
|
return attestations;
|
|
495
638
|
}
|
|
496
639
|
|
|
@@ -503,7 +646,11 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
503
646
|
proposalInfo: LogData,
|
|
504
647
|
): Promise<{ isValid: true } | { isValid: false; reason: string }> {
|
|
505
648
|
const slot = proposal.slotNumber;
|
|
506
|
-
|
|
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));
|
|
507
654
|
|
|
508
655
|
// Wait for last block to sync by archive
|
|
509
656
|
let lastBlockHeader: BlockHeader | undefined;
|
|
@@ -531,21 +678,19 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
531
678
|
return { isValid: false, reason: 'last_block_not_found' };
|
|
532
679
|
}
|
|
533
680
|
|
|
534
|
-
// Get the last full block to determine checkpoint number
|
|
535
|
-
const lastBlock = await this.blockSource.getL2BlockNew(lastBlockHeader.getBlockNumber());
|
|
536
|
-
if (!lastBlock) {
|
|
537
|
-
this.log.warn(`Last block ${lastBlockHeader.getBlockNumber()} not found`, proposalInfo);
|
|
538
|
-
return { isValid: false, reason: 'last_block_not_found' };
|
|
539
|
-
}
|
|
540
|
-
const checkpointNumber = lastBlock.checkpointNumber;
|
|
541
|
-
|
|
542
681
|
// Get all full blocks for the slot and checkpoint
|
|
543
|
-
const blocks = await this.getBlocksForSlot(slot
|
|
682
|
+
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
544
683
|
if (blocks.length === 0) {
|
|
545
684
|
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
546
685
|
return { isValid: false, reason: 'no_blocks_for_slot' };
|
|
547
686
|
}
|
|
548
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
|
+
|
|
549
694
|
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
550
695
|
...proposalInfo,
|
|
551
696
|
blockNumbers: blocks.map(b => b.number),
|
|
@@ -554,10 +699,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
554
699
|
// Get checkpoint constants from first block
|
|
555
700
|
const firstBlock = blocks[0];
|
|
556
701
|
const constants = this.extractCheckpointConstants(firstBlock);
|
|
702
|
+
const checkpointNumber = firstBlock.checkpointNumber;
|
|
557
703
|
|
|
558
704
|
// Get L1-to-L2 messages for this checkpoint
|
|
559
705
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
560
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
|
+
|
|
561
713
|
// Fork world state at the block before the first block
|
|
562
714
|
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
563
715
|
const fork = await this.worldState.fork(parentBlockNumber);
|
|
@@ -567,9 +719,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
567
719
|
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
|
|
568
720
|
checkpointNumber,
|
|
569
721
|
constants,
|
|
722
|
+
proposal.feeAssetPriceModifier,
|
|
570
723
|
l1ToL2Messages,
|
|
724
|
+
previousCheckpointOutHashes,
|
|
571
725
|
fork,
|
|
572
726
|
blocks,
|
|
727
|
+
this.log.getBindings(),
|
|
573
728
|
);
|
|
574
729
|
|
|
575
730
|
// Complete the checkpoint to get computed values
|
|
@@ -595,6 +750,22 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
595
750
|
return { isValid: false, reason: 'archive_mismatch' };
|
|
596
751
|
}
|
|
597
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
|
+
|
|
598
769
|
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
599
770
|
return { isValid: true };
|
|
600
771
|
} finally {
|
|
@@ -602,55 +773,16 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
602
773
|
}
|
|
603
774
|
}
|
|
604
775
|
|
|
605
|
-
/**
|
|
606
|
-
* Get all full blocks for a given slot and checkpoint by walking backwards from the last block.
|
|
607
|
-
* Returns blocks in ascending order (earliest to latest).
|
|
608
|
-
* TODO(palla/mbps): Add getL2BlocksForSlot() to L2BlockSource interface for efficiency.
|
|
609
|
-
*/
|
|
610
|
-
private async getBlocksForSlot(
|
|
611
|
-
slot: SlotNumber,
|
|
612
|
-
lastBlockHeader: BlockHeader,
|
|
613
|
-
checkpointNumber: CheckpointNumber,
|
|
614
|
-
): Promise<L2BlockNew[]> {
|
|
615
|
-
const blocks: L2BlockNew[] = [];
|
|
616
|
-
let currentHeader = lastBlockHeader;
|
|
617
|
-
const { genesisArchiveRoot } = await this.blockSource.getGenesisValues();
|
|
618
|
-
|
|
619
|
-
while (currentHeader.getSlot() === slot) {
|
|
620
|
-
const block = await this.blockSource.getL2BlockNew(currentHeader.getBlockNumber());
|
|
621
|
-
if (!block) {
|
|
622
|
-
this.log.warn(`Block ${currentHeader.getBlockNumber()} not found while getting blocks for slot ${slot}`);
|
|
623
|
-
break;
|
|
624
|
-
}
|
|
625
|
-
if (block.checkpointNumber !== checkpointNumber) {
|
|
626
|
-
break;
|
|
627
|
-
}
|
|
628
|
-
blocks.unshift(block);
|
|
629
|
-
|
|
630
|
-
const prevArchive = currentHeader.lastArchive.root;
|
|
631
|
-
if (prevArchive.equals(genesisArchiveRoot)) {
|
|
632
|
-
break;
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
const prevHeader = await this.blockSource.getBlockHeaderByArchive(prevArchive);
|
|
636
|
-
if (!prevHeader || prevHeader.getSlot() !== slot) {
|
|
637
|
-
break;
|
|
638
|
-
}
|
|
639
|
-
currentHeader = prevHeader;
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
return blocks;
|
|
643
|
-
}
|
|
644
|
-
|
|
645
776
|
/**
|
|
646
777
|
* Extract checkpoint global variables from a block.
|
|
647
778
|
*/
|
|
648
|
-
private extractCheckpointConstants(block:
|
|
779
|
+
private extractCheckpointConstants(block: L2Block): CheckpointGlobalVariables {
|
|
649
780
|
const gv = block.header.globalVariables;
|
|
650
781
|
return {
|
|
651
782
|
chainId: gv.chainId,
|
|
652
783
|
version: gv.version,
|
|
653
784
|
slotNumber: gv.slotNumber,
|
|
785
|
+
timestamp: gv.timestamp,
|
|
654
786
|
coinbase: gv.coinbase,
|
|
655
787
|
feeRecipient: gv.feeRecipient,
|
|
656
788
|
gasFees: gv.gasFees,
|
|
@@ -660,7 +792,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
660
792
|
/**
|
|
661
793
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
662
794
|
*/
|
|
663
|
-
|
|
795
|
+
protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
|
|
664
796
|
try {
|
|
665
797
|
const lastBlockHeader = await this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
666
798
|
if (!lastBlockHeader) {
|
|
@@ -668,21 +800,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
668
800
|
return;
|
|
669
801
|
}
|
|
670
802
|
|
|
671
|
-
|
|
672
|
-
const lastBlock = await this.blockSource.getL2BlockNew(lastBlockHeader.getBlockNumber());
|
|
673
|
-
if (!lastBlock) {
|
|
674
|
-
this.log.warn(`Failed to get last block for blob upload`, proposalInfo);
|
|
675
|
-
return;
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
const blocks = await this.getBlocksForSlot(proposal.slotNumber, lastBlockHeader, lastBlock.checkpointNumber);
|
|
803
|
+
const blocks = await this.blockSource.getBlocksForSlot(proposal.slotNumber);
|
|
679
804
|
if (blocks.length === 0) {
|
|
680
805
|
this.log.warn(`No blocks found for blob upload`, proposalInfo);
|
|
681
806
|
return;
|
|
682
807
|
}
|
|
683
808
|
|
|
684
809
|
const blobFields = blocks.flatMap(b => b.toBlobFields());
|
|
685
|
-
const blobs: Blob[] = getBlobsPerL1Block(blobFields);
|
|
810
|
+
const blobs: Blob[] = await getBlobsPerL1Block(blobFields);
|
|
686
811
|
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
687
812
|
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
688
813
|
...proposalInfo,
|
|
@@ -720,20 +845,74 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
720
845
|
]);
|
|
721
846
|
}
|
|
722
847
|
|
|
848
|
+
/**
|
|
849
|
+
* Handle detection of a duplicate proposal (equivocation).
|
|
850
|
+
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
851
|
+
*/
|
|
852
|
+
private handleDuplicateProposal(info: DuplicateProposalInfo): void {
|
|
853
|
+
const { slot, proposer, type } = info;
|
|
854
|
+
|
|
855
|
+
this.log.warn(`Triggering slash event for duplicate ${type} proposal from ${proposer.toString()} at slot ${slot}`, {
|
|
856
|
+
proposer: proposer.toString(),
|
|
857
|
+
slot,
|
|
858
|
+
type,
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
// Emit slash event
|
|
862
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
863
|
+
{
|
|
864
|
+
validator: proposer,
|
|
865
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
866
|
+
offenseType: OffenseType.DUPLICATE_PROPOSAL,
|
|
867
|
+
epochOrSlot: BigInt(slot),
|
|
868
|
+
},
|
|
869
|
+
]);
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* Handle detection of a duplicate attestation (equivocation).
|
|
874
|
+
* Emits a slash event when an attester signs attestations for different proposals at the same slot.
|
|
875
|
+
*/
|
|
876
|
+
private handleDuplicateAttestation(info: DuplicateAttestationInfo): void {
|
|
877
|
+
const { slot, attester } = info;
|
|
878
|
+
|
|
879
|
+
this.log.warn(`Triggering slash event for duplicate attestation from ${attester.toString()} at slot ${slot}`, {
|
|
880
|
+
attester: attester.toString(),
|
|
881
|
+
slot,
|
|
882
|
+
});
|
|
883
|
+
|
|
884
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
885
|
+
{
|
|
886
|
+
validator: attester,
|
|
887
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
888
|
+
offenseType: OffenseType.DUPLICATE_ATTESTATION,
|
|
889
|
+
epochOrSlot: BigInt(slot),
|
|
890
|
+
},
|
|
891
|
+
]);
|
|
892
|
+
}
|
|
893
|
+
|
|
723
894
|
async createBlockProposal(
|
|
724
895
|
blockHeader: BlockHeader,
|
|
725
|
-
indexWithinCheckpoint:
|
|
896
|
+
indexWithinCheckpoint: IndexWithinCheckpoint,
|
|
726
897
|
inHash: Fr,
|
|
727
898
|
archive: Fr,
|
|
728
899
|
txs: Tx[],
|
|
729
900
|
proposerAddress: EthAddress | undefined,
|
|
730
|
-
options: BlockProposalOptions,
|
|
901
|
+
options: BlockProposalOptions = {},
|
|
731
902
|
): Promise<BlockProposal> {
|
|
732
|
-
//
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
903
|
+
// Validate that we're not creating a proposal for an older or equal position
|
|
904
|
+
if (this.lastProposedBlock) {
|
|
905
|
+
const lastSlot = this.lastProposedBlock.slotNumber;
|
|
906
|
+
const lastIndex = this.lastProposedBlock.indexWithinCheckpoint;
|
|
907
|
+
const newSlot = blockHeader.globalVariables.slotNumber;
|
|
908
|
+
|
|
909
|
+
if (newSlot < lastSlot || (newSlot === lastSlot && indexWithinCheckpoint <= lastIndex)) {
|
|
910
|
+
throw new Error(
|
|
911
|
+
`Cannot create block proposal for slot ${newSlot} index ${indexWithinCheckpoint}: ` +
|
|
912
|
+
`already proposed block for slot ${lastSlot} index ${lastIndex}`,
|
|
913
|
+
);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
737
916
|
|
|
738
917
|
this.log.info(
|
|
739
918
|
`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`,
|
|
@@ -750,25 +929,42 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
750
929
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal,
|
|
751
930
|
},
|
|
752
931
|
);
|
|
753
|
-
this.
|
|
932
|
+
this.lastProposedBlock = newProposal;
|
|
754
933
|
return newProposal;
|
|
755
934
|
}
|
|
756
935
|
|
|
757
936
|
async createCheckpointProposal(
|
|
758
937
|
checkpointHeader: CheckpointHeader,
|
|
759
938
|
archive: Fr,
|
|
939
|
+
feeAssetPriceModifier: bigint,
|
|
760
940
|
lastBlockInfo: CreateCheckpointProposalLastBlockData | undefined,
|
|
761
941
|
proposerAddress: EthAddress | undefined,
|
|
762
|
-
options: CheckpointProposalOptions,
|
|
942
|
+
options: CheckpointProposalOptions = {},
|
|
763
943
|
): Promise<CheckpointProposal> {
|
|
944
|
+
// Validate that we're not creating a proposal for an older or equal slot
|
|
945
|
+
if (this.lastProposedCheckpoint) {
|
|
946
|
+
const lastSlot = this.lastProposedCheckpoint.slotNumber;
|
|
947
|
+
const newSlot = checkpointHeader.slotNumber;
|
|
948
|
+
|
|
949
|
+
if (newSlot <= lastSlot) {
|
|
950
|
+
throw new Error(
|
|
951
|
+
`Cannot create checkpoint proposal for slot ${newSlot}: ` +
|
|
952
|
+
`already proposed checkpoint for slot ${lastSlot}`,
|
|
953
|
+
);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
|
|
764
957
|
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
765
|
-
|
|
958
|
+
const newProposal = await this.validationService.createCheckpointProposal(
|
|
766
959
|
checkpointHeader,
|
|
767
960
|
archive,
|
|
961
|
+
feeAssetPriceModifier,
|
|
768
962
|
lastBlockInfo,
|
|
769
963
|
proposerAddress,
|
|
770
964
|
options,
|
|
771
965
|
);
|
|
966
|
+
this.lastProposedCheckpoint = newProposal;
|
|
967
|
+
return newProposal;
|
|
772
968
|
}
|
|
773
969
|
|
|
774
970
|
async broadcastBlockProposal(proposal: BlockProposal): Promise<void> {
|
|
@@ -778,8 +974,10 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
778
974
|
async signAttestationsAndSigners(
|
|
779
975
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
780
976
|
proposer: EthAddress,
|
|
977
|
+
slot: SlotNumber,
|
|
978
|
+
blockNumber: BlockNumber | CheckpointNumber,
|
|
781
979
|
): Promise<Signature> {
|
|
782
|
-
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
|
|
980
|
+
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
|
|
783
981
|
}
|
|
784
982
|
|
|
785
983
|
async collectOwnAttestations(proposal: CheckpointProposal): Promise<CheckpointAttestation[]> {
|
|
@@ -788,6 +986,10 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
788
986
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, { inCommittee });
|
|
789
987
|
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
790
988
|
|
|
989
|
+
if (!attestations) {
|
|
990
|
+
return [];
|
|
991
|
+
}
|
|
992
|
+
|
|
791
993
|
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
792
994
|
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
793
995
|
// due to inactivity for missed attestations.
|
|
@@ -886,7 +1088,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
886
1088
|
}
|
|
887
1089
|
|
|
888
1090
|
const payloadToSign = authRequest.getPayloadToSign();
|
|
889
|
-
|
|
1091
|
+
// AUTH_REQUEST doesn't require HA protection - multiple signatures are safe
|
|
1092
|
+
const context: SigningContext = { dutyType: DutyType.AUTH_REQUEST };
|
|
1093
|
+
const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign, context);
|
|
890
1094
|
const authResponse = new AuthResponse(statusMessage, signature);
|
|
891
1095
|
return authResponse.toBuffer();
|
|
892
1096
|
}
|