@aztec/validator-client 0.0.1-commit.1142ef1 → 0.0.1-commit.125b3452
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 +96 -24
- package/dest/block_proposal_handler.d.ts +12 -11
- package/dest/block_proposal_handler.d.ts.map +1 -1
- package/dest/block_proposal_handler.js +132 -77
- package/dest/checkpoint_builder.d.ts +32 -25
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +144 -49
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +33 -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 +69 -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 +263 -99
- package/package.json +21 -17
- package/src/block_proposal_handler.ts +163 -95
- package/src/checkpoint_builder.ts +206 -61
- package/src/config.ts +32 -13
- package/src/duties/validation_service.ts +94 -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 +329 -118
- 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,36 @@ 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 { validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
28
|
+
import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
20
29
|
import type {
|
|
21
30
|
CreateCheckpointProposalLastBlockData,
|
|
31
|
+
ITxProvider,
|
|
22
32
|
Validator,
|
|
23
33
|
ValidatorClientFullConfig,
|
|
24
34
|
WorldStateSynchronizer,
|
|
25
35
|
} from '@aztec/stdlib/interfaces/server';
|
|
26
|
-
import type
|
|
27
|
-
import
|
|
28
|
-
BlockProposal,
|
|
29
|
-
BlockProposalOptions,
|
|
30
|
-
CheckpointAttestation,
|
|
31
|
-
|
|
32
|
-
|
|
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,
|
|
33
44
|
} from '@aztec/stdlib/p2p';
|
|
34
|
-
import { CheckpointProposal } from '@aztec/stdlib/p2p';
|
|
35
45
|
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
36
46
|
import type { BlockHeader, CheckpointGlobalVariables, Tx } from '@aztec/stdlib/tx';
|
|
37
47
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
38
48
|
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
49
|
+
import { createHASigner, createLocalSignerWithProtection } 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';
|
|
39
52
|
|
|
40
53
|
import { EventEmitter } from 'events';
|
|
41
54
|
import type { TypedDataDefinition } from 'viem';
|
|
@@ -43,6 +56,8 @@ import type { TypedDataDefinition } from 'viem';
|
|
|
43
56
|
import { BlockProposalHandler, type BlockProposalValidationFailureReason } from './block_proposal_handler.js';
|
|
44
57
|
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
45
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';
|
|
46
61
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
47
62
|
import { ValidatorMetrics } from './metrics.js';
|
|
48
63
|
|
|
@@ -64,25 +79,27 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
64
79
|
private validationService: ValidationService;
|
|
65
80
|
private metrics: ValidatorMetrics;
|
|
66
81
|
private log: Logger;
|
|
67
|
-
|
|
68
82
|
// Whether it has already registered handlers on the p2p client
|
|
69
83
|
private hasRegisteredHandlers = false;
|
|
70
84
|
|
|
71
|
-
|
|
72
|
-
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;
|
|
73
90
|
|
|
74
91
|
private lastEpochForCommitteeUpdateLoop: EpochNumber | undefined;
|
|
75
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();
|
|
76
95
|
|
|
77
96
|
private proposersOfInvalidBlocks: Set<string> = new Set();
|
|
78
97
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
82
|
-
private validatedBlockSlots: Set<SlotNumber> = new Set();
|
|
98
|
+
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */
|
|
99
|
+
private lastAttestedProposal?: CheckpointProposalCore;
|
|
83
100
|
|
|
84
101
|
protected constructor(
|
|
85
|
-
private keyStore:
|
|
102
|
+
private keyStore: ExtendedValidatorKeyStore,
|
|
86
103
|
private epochCache: EpochCache,
|
|
87
104
|
private p2pClient: P2P,
|
|
88
105
|
private blockProposalHandler: BlockProposalHandler,
|
|
@@ -92,6 +109,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
92
109
|
private l1ToL2MessageSource: L1ToL2MessageSource,
|
|
93
110
|
private config: ValidatorClientFullConfig,
|
|
94
111
|
private blobClient: BlobClientInterface,
|
|
112
|
+
private slashingProtectionSigner: ValidatorHASigner,
|
|
95
113
|
private dateProvider: DateProvider = new DateProvider(),
|
|
96
114
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
97
115
|
log = createLogger('validator'),
|
|
@@ -145,6 +163,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
145
163
|
this.log.trace(`No committee found for slot`);
|
|
146
164
|
return;
|
|
147
165
|
}
|
|
166
|
+
this.metrics.setCurrentEpoch(epoch);
|
|
148
167
|
if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
|
|
149
168
|
const me = this.getValidatorAddresses();
|
|
150
169
|
const committeeSet = new Set(committee.map(v => v.toString()));
|
|
@@ -165,7 +184,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
165
184
|
}
|
|
166
185
|
}
|
|
167
186
|
|
|
168
|
-
static new(
|
|
187
|
+
static async new(
|
|
169
188
|
config: ValidatorClientFullConfig,
|
|
170
189
|
checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
171
190
|
worldState: WorldStateSynchronizer,
|
|
@@ -173,7 +192,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
173
192
|
p2pClient: P2P,
|
|
174
193
|
blockSource: L2BlockSource & L2BlockSink,
|
|
175
194
|
l1ToL2MessageSource: L1ToL2MessageSource,
|
|
176
|
-
txProvider:
|
|
195
|
+
txProvider: ITxProvider,
|
|
177
196
|
keyStoreManager: KeystoreManager,
|
|
178
197
|
blobClient: BlobClientInterface,
|
|
179
198
|
dateProvider: DateProvider = new DateProvider(),
|
|
@@ -182,6 +201,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
182
201
|
const metrics = new ValidatorMetrics(telemetry);
|
|
183
202
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
184
203
|
txsPermitted: !config.disableTransactions,
|
|
204
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock,
|
|
185
205
|
});
|
|
186
206
|
const blockProposalHandler = new BlockProposalHandler(
|
|
187
207
|
checkpointsBuilder,
|
|
@@ -190,14 +210,38 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
190
210
|
l1ToL2MessageSource,
|
|
191
211
|
txProvider,
|
|
192
212
|
blockProposalValidator,
|
|
213
|
+
epochCache,
|
|
193
214
|
config,
|
|
194
215
|
metrics,
|
|
195
216
|
dateProvider,
|
|
196
217
|
telemetry,
|
|
197
218
|
);
|
|
198
219
|
|
|
220
|
+
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
221
|
+
let slashingProtectionSigner: ValidatorHASigner;
|
|
222
|
+
if (config.haSigningEnabled) {
|
|
223
|
+
// Multi-node HA mode: use PostgreSQL-backed distributed locking.
|
|
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
|
+
({ signer: slashingProtectionSigner } = await createHASigner(haConfig, {
|
|
230
|
+
telemetryClient: telemetry,
|
|
231
|
+
dateProvider,
|
|
232
|
+
}));
|
|
233
|
+
} else {
|
|
234
|
+
// Single-node mode: use LMDB-backed local signing protection.
|
|
235
|
+
// This prevents double-signing if the node crashes and restarts mid-proposal.
|
|
236
|
+
({ signer: slashingProtectionSigner } = await createLocalSignerWithProtection(config, {
|
|
237
|
+
telemetryClient: telemetry,
|
|
238
|
+
dateProvider,
|
|
239
|
+
}));
|
|
240
|
+
}
|
|
241
|
+
const validatorKeyStore: ExtendedValidatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, slashingProtectionSigner);
|
|
242
|
+
|
|
199
243
|
const validator = new ValidatorClient(
|
|
200
|
-
|
|
244
|
+
validatorKeyStore,
|
|
201
245
|
epochCache,
|
|
202
246
|
p2pClient,
|
|
203
247
|
blockProposalHandler,
|
|
@@ -207,6 +251,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
207
251
|
l1ToL2MessageSource,
|
|
208
252
|
config,
|
|
209
253
|
blobClient,
|
|
254
|
+
slashingProtectionSigner,
|
|
210
255
|
dateProvider,
|
|
211
256
|
telemetry,
|
|
212
257
|
);
|
|
@@ -224,8 +269,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
224
269
|
return this.blockProposalHandler;
|
|
225
270
|
}
|
|
226
271
|
|
|
227
|
-
public signWithAddress(addr: EthAddress, msg: TypedDataDefinition) {
|
|
228
|
-
return this.keyStore.signTypedDataWithAddress(addr, msg);
|
|
272
|
+
public signWithAddress(addr: EthAddress, msg: TypedDataDefinition, context: SigningContext) {
|
|
273
|
+
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
229
274
|
}
|
|
230
275
|
|
|
231
276
|
public getCoinbaseForAttestor(attestor: EthAddress): EthAddress {
|
|
@@ -244,12 +289,20 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
244
289
|
this.config = { ...this.config, ...config };
|
|
245
290
|
}
|
|
246
291
|
|
|
292
|
+
public reloadKeystore(newManager: KeystoreManager): void {
|
|
293
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
294
|
+
this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
|
|
295
|
+
this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
|
|
296
|
+
}
|
|
297
|
+
|
|
247
298
|
public async start() {
|
|
248
299
|
if (this.epochCacheUpdateLoop.isRunning()) {
|
|
249
300
|
this.log.warn(`Validator client already started`);
|
|
250
301
|
return;
|
|
251
302
|
}
|
|
252
303
|
|
|
304
|
+
await this.keyStore.start();
|
|
305
|
+
|
|
253
306
|
await this.registerHandlers();
|
|
254
307
|
|
|
255
308
|
const myAddresses = this.getValidatorAddresses();
|
|
@@ -265,6 +318,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
265
318
|
|
|
266
319
|
public async stop() {
|
|
267
320
|
await this.epochCacheUpdateLoop.stop();
|
|
321
|
+
await this.keyStore.stop();
|
|
268
322
|
}
|
|
269
323
|
|
|
270
324
|
/** Register handlers on the p2p client */
|
|
@@ -287,6 +341,16 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
287
341
|
): Promise<CheckpointAttestation[] | undefined> => this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
288
342
|
this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
|
|
289
343
|
|
|
344
|
+
// Duplicate proposal handler - triggers slashing for equivocation
|
|
345
|
+
this.p2pClient.registerDuplicateProposalCallback((info: DuplicateProposalInfo) => {
|
|
346
|
+
this.handleDuplicateProposal(info);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
// Duplicate attestation handler - triggers slashing for attestation equivocation
|
|
350
|
+
this.p2pClient.registerDuplicateAttestationCallback((info: DuplicateAttestationInfo) => {
|
|
351
|
+
this.handleDuplicateAttestation(info);
|
|
352
|
+
});
|
|
353
|
+
|
|
290
354
|
const myAddresses = this.getValidatorAddresses();
|
|
291
355
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
292
356
|
|
|
@@ -301,6 +365,11 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
301
365
|
*/
|
|
302
366
|
async validateBlockProposal(proposal: BlockProposal, proposalSender: PeerId): Promise<boolean> {
|
|
303
367
|
const slotNumber = proposal.slotNumber;
|
|
368
|
+
|
|
369
|
+
// Note: During escape hatch, we still want to "validate" proposals for observability,
|
|
370
|
+
// but we intentionally reject them and disable slashing invalid block and attestation flow.
|
|
371
|
+
const escapeHatchOpen = await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber);
|
|
372
|
+
|
|
304
373
|
const proposer = proposal.getSender();
|
|
305
374
|
|
|
306
375
|
// Reject proposals with invalid signatures
|
|
@@ -309,6 +378,15 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
309
378
|
return false;
|
|
310
379
|
}
|
|
311
380
|
|
|
381
|
+
// Ignore proposals from ourselves (may happen in HA setups)
|
|
382
|
+
if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
383
|
+
this.log.debug(`Ignoring block proposal from self for slot ${slotNumber}`, {
|
|
384
|
+
proposer: proposer.toString(),
|
|
385
|
+
slotNumber,
|
|
386
|
+
});
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
|
|
312
390
|
// Check if we're in the committee (for metrics purposes)
|
|
313
391
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
314
392
|
const partOfCommittee = inCommittee.length > 0;
|
|
@@ -334,13 +412,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
334
412
|
const validationResult = await this.blockProposalHandler.handleBlockProposal(
|
|
335
413
|
proposal,
|
|
336
414
|
proposalSender,
|
|
337
|
-
!!shouldReexecute,
|
|
415
|
+
!!shouldReexecute && !escapeHatchOpen,
|
|
338
416
|
);
|
|
339
417
|
|
|
340
418
|
if (!validationResult.isValid) {
|
|
341
|
-
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
342
|
-
|
|
343
419
|
const reason = validationResult.reason || 'unknown';
|
|
420
|
+
|
|
421
|
+
this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
|
|
422
|
+
|
|
344
423
|
// Classify failure reason: bad proposal vs node issue
|
|
345
424
|
const badProposalReasons: BlockProposalValidationFailureReason[] = [
|
|
346
425
|
'invalid_proposal',
|
|
@@ -359,6 +438,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
359
438
|
|
|
360
439
|
// Slash invalid block proposals (can happen even when not in committee)
|
|
361
440
|
if (
|
|
441
|
+
!escapeHatchOpen &&
|
|
362
442
|
validationResult.reason &&
|
|
363
443
|
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) &&
|
|
364
444
|
slashBroadcastedInvalidBlockPenalty > 0n
|
|
@@ -373,11 +453,13 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
373
453
|
...proposalInfo,
|
|
374
454
|
inCommittee: partOfCommittee,
|
|
375
455
|
fishermanMode: this.config.fishermanMode || false,
|
|
456
|
+
escapeHatchOpen,
|
|
376
457
|
});
|
|
377
458
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
459
|
+
if (escapeHatchOpen) {
|
|
460
|
+
this.log.warn(`Escape hatch open for slot ${slotNumber}, rejecting block proposal`, proposalInfo);
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
381
463
|
|
|
382
464
|
return true;
|
|
383
465
|
}
|
|
@@ -395,12 +477,35 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
395
477
|
const slotNumber = proposal.slotNumber;
|
|
396
478
|
const proposer = proposal.getSender();
|
|
397
479
|
|
|
480
|
+
// If escape hatch is open for this slot's epoch, do not attest.
|
|
481
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
|
|
482
|
+
this.log.warn(`Escape hatch open for slot ${slotNumber}, skipping checkpoint attestation handling`);
|
|
483
|
+
return undefined;
|
|
484
|
+
}
|
|
485
|
+
|
|
398
486
|
// Reject proposals with invalid signatures
|
|
399
487
|
if (!proposer) {
|
|
400
488
|
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
401
489
|
return undefined;
|
|
402
490
|
}
|
|
403
491
|
|
|
492
|
+
// Ignore proposals from ourselves (may happen in HA setups)
|
|
493
|
+
if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
494
|
+
this.log.debug(`Ignoring block proposal from self for slot ${slotNumber}`, {
|
|
495
|
+
proposer: proposer.toString(),
|
|
496
|
+
slotNumber,
|
|
497
|
+
});
|
|
498
|
+
return undefined;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// Validate fee asset price modifier is within allowed range
|
|
502
|
+
if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
|
|
503
|
+
this.log.warn(
|
|
504
|
+
`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`,
|
|
505
|
+
);
|
|
506
|
+
return undefined;
|
|
507
|
+
}
|
|
508
|
+
|
|
404
509
|
// Check that I have any address in current committee before attesting
|
|
405
510
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
406
511
|
const partOfCommittee = inCommittee.length > 0;
|
|
@@ -409,25 +514,15 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
409
514
|
slotNumber,
|
|
410
515
|
archive: proposal.archive.toString(),
|
|
411
516
|
proposer: proposer.toString(),
|
|
412
|
-
txCount: proposal.txHashes.length,
|
|
413
517
|
};
|
|
414
518
|
this.log.info(`Received checkpoint proposal for slot ${slotNumber}`, {
|
|
415
519
|
...proposalInfo,
|
|
416
|
-
txHashes: proposal.txHashes.map(t => t.toString()),
|
|
417
520
|
fishermanMode: this.config.fishermanMode || false,
|
|
418
521
|
});
|
|
419
522
|
|
|
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
523
|
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
this.log.verbose(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
|
|
524
|
+
if (this.config.skipCheckpointProposalValidation) {
|
|
525
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
|
|
431
526
|
} else {
|
|
432
527
|
const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
|
|
433
528
|
if (!validationResult.isValid) {
|
|
@@ -457,6 +552,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
457
552
|
|
|
458
553
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
459
554
|
|
|
555
|
+
// Track epoch participation per attester: count each (attester, epoch) pair at most once
|
|
556
|
+
const proposalEpoch = getEpochAtSlot(slotNumber, this.epochCache.getL1Constants());
|
|
557
|
+
for (const attester of inCommittee) {
|
|
558
|
+
const key = attester.toString();
|
|
559
|
+
const lastEpoch = this.lastAttestedEpochByAttester.get(key);
|
|
560
|
+
if (lastEpoch === undefined || proposalEpoch > lastEpoch) {
|
|
561
|
+
this.lastAttestedEpochByAttester.set(key, proposalEpoch);
|
|
562
|
+
this.metrics.incAttestedEpochCount(attester);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
460
566
|
// Determine which validators should attest
|
|
461
567
|
let attestors: EthAddress[];
|
|
462
568
|
if (partOfCommittee) {
|
|
@@ -482,15 +588,45 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
482
588
|
return undefined;
|
|
483
589
|
}
|
|
484
590
|
|
|
485
|
-
return this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
591
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Checks if we should attest to a slot based on equivocation prevention rules.
|
|
596
|
+
* @returns true if we should attest, false if we should skip
|
|
597
|
+
*/
|
|
598
|
+
private shouldAttestToSlot(slotNumber: SlotNumber): boolean {
|
|
599
|
+
// If attestToEquivocatedProposals is true, always allow
|
|
600
|
+
if (this.config.attestToEquivocatedProposals) {
|
|
601
|
+
return true;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// Check if incoming slot is strictly greater than last attested
|
|
605
|
+
if (this.lastAttestedProposal && slotNumber <= this.lastAttestedProposal.slotNumber) {
|
|
606
|
+
this.log.warn(
|
|
607
|
+
`Refusing to process a proposal for slot ${slotNumber} given we already attested to a proposal for slot ${this.lastAttestedProposal.slotNumber}`,
|
|
608
|
+
);
|
|
609
|
+
return false;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
return true;
|
|
486
613
|
}
|
|
487
614
|
|
|
488
615
|
private async createCheckpointAttestationsFromProposal(
|
|
489
616
|
proposal: CheckpointProposalCore,
|
|
490
617
|
attestors: EthAddress[] = [],
|
|
491
|
-
): Promise<CheckpointAttestation[]> {
|
|
618
|
+
): Promise<CheckpointAttestation[] | undefined> {
|
|
619
|
+
// Equivocation check: must happen right before signing to minimize the race window
|
|
620
|
+
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
621
|
+
return undefined;
|
|
622
|
+
}
|
|
623
|
+
|
|
492
624
|
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
493
|
-
|
|
625
|
+
|
|
626
|
+
// Track the proposal we attested to (to prevent equivocation)
|
|
627
|
+
this.lastAttestedProposal = proposal;
|
|
628
|
+
|
|
629
|
+
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
494
630
|
return attestations;
|
|
495
631
|
}
|
|
496
632
|
|
|
@@ -503,7 +639,11 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
503
639
|
proposalInfo: LogData,
|
|
504
640
|
): Promise<{ isValid: true } | { isValid: false; reason: string }> {
|
|
505
641
|
const slot = proposal.slotNumber;
|
|
506
|
-
|
|
642
|
+
|
|
643
|
+
// Timeout block syncing at the start of the next slot
|
|
644
|
+
const config = this.checkpointsBuilder.getConfig();
|
|
645
|
+
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
|
|
646
|
+
const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
|
|
507
647
|
|
|
508
648
|
// Wait for last block to sync by archive
|
|
509
649
|
let lastBlockHeader: BlockHeader | undefined;
|
|
@@ -531,21 +671,19 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
531
671
|
return { isValid: false, reason: 'last_block_not_found' };
|
|
532
672
|
}
|
|
533
673
|
|
|
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
674
|
// Get all full blocks for the slot and checkpoint
|
|
543
|
-
const blocks = await this.getBlocksForSlot(slot
|
|
675
|
+
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
544
676
|
if (blocks.length === 0) {
|
|
545
677
|
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
546
678
|
return { isValid: false, reason: 'no_blocks_for_slot' };
|
|
547
679
|
}
|
|
548
680
|
|
|
681
|
+
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
682
|
+
if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
|
|
683
|
+
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
684
|
+
return { isValid: false, reason: 'last_block_archive_mismatch' };
|
|
685
|
+
}
|
|
686
|
+
|
|
549
687
|
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
550
688
|
...proposalInfo,
|
|
551
689
|
blockNumbers: blocks.map(b => b.number),
|
|
@@ -554,10 +692,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
554
692
|
// Get checkpoint constants from first block
|
|
555
693
|
const firstBlock = blocks[0];
|
|
556
694
|
const constants = this.extractCheckpointConstants(firstBlock);
|
|
695
|
+
const checkpointNumber = firstBlock.checkpointNumber;
|
|
557
696
|
|
|
558
697
|
// Get L1-to-L2 messages for this checkpoint
|
|
559
698
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
560
699
|
|
|
700
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
701
|
+
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
702
|
+
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch))
|
|
703
|
+
.filter(c => c.checkpointNumber < checkpointNumber)
|
|
704
|
+
.map(c => c.checkpointOutHash);
|
|
705
|
+
|
|
561
706
|
// Fork world state at the block before the first block
|
|
562
707
|
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
563
708
|
const fork = await this.worldState.fork(parentBlockNumber);
|
|
@@ -567,9 +712,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
567
712
|
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
|
|
568
713
|
checkpointNumber,
|
|
569
714
|
constants,
|
|
715
|
+
proposal.feeAssetPriceModifier,
|
|
570
716
|
l1ToL2Messages,
|
|
717
|
+
previousCheckpointOutHashes,
|
|
571
718
|
fork,
|
|
572
719
|
blocks,
|
|
720
|
+
this.log.getBindings(),
|
|
573
721
|
);
|
|
574
722
|
|
|
575
723
|
// Complete the checkpoint to get computed values
|
|
@@ -595,62 +743,53 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
595
743
|
return { isValid: false, reason: 'archive_mismatch' };
|
|
596
744
|
}
|
|
597
745
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
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;
|
|
746
|
+
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
747
|
+
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
748
|
+
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
749
|
+
const computedEpochOutHash = accumulateCheckpointOutHashes([...previousCheckpointOutHashes, checkpointOutHash]);
|
|
750
|
+
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
751
|
+
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
752
|
+
this.log.warn(`Epoch out hash mismatch`, {
|
|
753
|
+
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
754
|
+
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
755
|
+
checkpointOutHash: checkpointOutHash.toString(),
|
|
756
|
+
previousCheckpointOutHashes: previousCheckpointOutHashes.map(h => h.toString()),
|
|
757
|
+
...proposalInfo,
|
|
758
|
+
});
|
|
759
|
+
return { isValid: false, reason: 'out_hash_mismatch' };
|
|
627
760
|
}
|
|
628
|
-
blocks.unshift(block);
|
|
629
761
|
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
762
|
+
// Final round of validations on the checkpoint, just in case.
|
|
763
|
+
try {
|
|
764
|
+
validateCheckpoint(computedCheckpoint, {
|
|
765
|
+
rollupManaLimit: this.checkpointsBuilder.getConfig().rollupManaLimit,
|
|
766
|
+
maxDABlockGas: this.config.validateMaxDABlockGas,
|
|
767
|
+
maxL2BlockGas: this.config.validateMaxL2BlockGas,
|
|
768
|
+
maxTxsPerBlock: this.config.validateMaxTxsPerBlock,
|
|
769
|
+
maxTxsPerCheckpoint: this.config.validateMaxTxsPerCheckpoint,
|
|
770
|
+
});
|
|
771
|
+
} catch (err) {
|
|
772
|
+
this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
|
|
773
|
+
return { isValid: false, reason: 'checkpoint_validation_failed' };
|
|
633
774
|
}
|
|
634
775
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
currentHeader = prevHeader;
|
|
776
|
+
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
777
|
+
return { isValid: true };
|
|
778
|
+
} finally {
|
|
779
|
+
await fork.close();
|
|
640
780
|
}
|
|
641
|
-
|
|
642
|
-
return blocks;
|
|
643
781
|
}
|
|
644
782
|
|
|
645
783
|
/**
|
|
646
784
|
* Extract checkpoint global variables from a block.
|
|
647
785
|
*/
|
|
648
|
-
private extractCheckpointConstants(block:
|
|
786
|
+
private extractCheckpointConstants(block: L2Block): CheckpointGlobalVariables {
|
|
649
787
|
const gv = block.header.globalVariables;
|
|
650
788
|
return {
|
|
651
789
|
chainId: gv.chainId,
|
|
652
790
|
version: gv.version,
|
|
653
791
|
slotNumber: gv.slotNumber,
|
|
792
|
+
timestamp: gv.timestamp,
|
|
654
793
|
coinbase: gv.coinbase,
|
|
655
794
|
feeRecipient: gv.feeRecipient,
|
|
656
795
|
gasFees: gv.gasFees,
|
|
@@ -660,7 +799,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
660
799
|
/**
|
|
661
800
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
662
801
|
*/
|
|
663
|
-
|
|
802
|
+
protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
|
|
664
803
|
try {
|
|
665
804
|
const lastBlockHeader = await this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
666
805
|
if (!lastBlockHeader) {
|
|
@@ -668,21 +807,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
668
807
|
return;
|
|
669
808
|
}
|
|
670
809
|
|
|
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);
|
|
810
|
+
const blocks = await this.blockSource.getBlocksForSlot(proposal.slotNumber);
|
|
679
811
|
if (blocks.length === 0) {
|
|
680
812
|
this.log.warn(`No blocks found for blob upload`, proposalInfo);
|
|
681
813
|
return;
|
|
682
814
|
}
|
|
683
815
|
|
|
684
816
|
const blobFields = blocks.flatMap(b => b.toBlobFields());
|
|
685
|
-
const blobs: Blob[] = getBlobsPerL1Block(blobFields);
|
|
817
|
+
const blobs: Blob[] = await getBlobsPerL1Block(blobFields);
|
|
686
818
|
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
687
819
|
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
688
820
|
...proposalInfo,
|
|
@@ -720,20 +852,74 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
720
852
|
]);
|
|
721
853
|
}
|
|
722
854
|
|
|
855
|
+
/**
|
|
856
|
+
* Handle detection of a duplicate proposal (equivocation).
|
|
857
|
+
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
858
|
+
*/
|
|
859
|
+
private handleDuplicateProposal(info: DuplicateProposalInfo): void {
|
|
860
|
+
const { slot, proposer, type } = info;
|
|
861
|
+
|
|
862
|
+
this.log.warn(`Triggering slash event for duplicate ${type} proposal from ${proposer.toString()} at slot ${slot}`, {
|
|
863
|
+
proposer: proposer.toString(),
|
|
864
|
+
slot,
|
|
865
|
+
type,
|
|
866
|
+
});
|
|
867
|
+
|
|
868
|
+
// Emit slash event
|
|
869
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
870
|
+
{
|
|
871
|
+
validator: proposer,
|
|
872
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
873
|
+
offenseType: OffenseType.DUPLICATE_PROPOSAL,
|
|
874
|
+
epochOrSlot: BigInt(slot),
|
|
875
|
+
},
|
|
876
|
+
]);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* Handle detection of a duplicate attestation (equivocation).
|
|
881
|
+
* Emits a slash event when an attester signs attestations for different proposals at the same slot.
|
|
882
|
+
*/
|
|
883
|
+
private handleDuplicateAttestation(info: DuplicateAttestationInfo): void {
|
|
884
|
+
const { slot, attester } = info;
|
|
885
|
+
|
|
886
|
+
this.log.warn(`Triggering slash event for duplicate attestation from ${attester.toString()} at slot ${slot}`, {
|
|
887
|
+
attester: attester.toString(),
|
|
888
|
+
slot,
|
|
889
|
+
});
|
|
890
|
+
|
|
891
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
892
|
+
{
|
|
893
|
+
validator: attester,
|
|
894
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
895
|
+
offenseType: OffenseType.DUPLICATE_ATTESTATION,
|
|
896
|
+
epochOrSlot: BigInt(slot),
|
|
897
|
+
},
|
|
898
|
+
]);
|
|
899
|
+
}
|
|
900
|
+
|
|
723
901
|
async createBlockProposal(
|
|
724
902
|
blockHeader: BlockHeader,
|
|
725
|
-
indexWithinCheckpoint:
|
|
903
|
+
indexWithinCheckpoint: IndexWithinCheckpoint,
|
|
726
904
|
inHash: Fr,
|
|
727
905
|
archive: Fr,
|
|
728
906
|
txs: Tx[],
|
|
729
907
|
proposerAddress: EthAddress | undefined,
|
|
730
|
-
options: BlockProposalOptions,
|
|
908
|
+
options: BlockProposalOptions = {},
|
|
731
909
|
): Promise<BlockProposal> {
|
|
732
|
-
//
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
910
|
+
// Validate that we're not creating a proposal for an older or equal position
|
|
911
|
+
if (this.lastProposedBlock) {
|
|
912
|
+
const lastSlot = this.lastProposedBlock.slotNumber;
|
|
913
|
+
const lastIndex = this.lastProposedBlock.indexWithinCheckpoint;
|
|
914
|
+
const newSlot = blockHeader.globalVariables.slotNumber;
|
|
915
|
+
|
|
916
|
+
if (newSlot < lastSlot || (newSlot === lastSlot && indexWithinCheckpoint <= lastIndex)) {
|
|
917
|
+
throw new Error(
|
|
918
|
+
`Cannot create block proposal for slot ${newSlot} index ${indexWithinCheckpoint}: ` +
|
|
919
|
+
`already proposed block for slot ${lastSlot} index ${lastIndex}`,
|
|
920
|
+
);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
737
923
|
|
|
738
924
|
this.log.info(
|
|
739
925
|
`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`,
|
|
@@ -750,25 +936,42 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
750
936
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal,
|
|
751
937
|
},
|
|
752
938
|
);
|
|
753
|
-
this.
|
|
939
|
+
this.lastProposedBlock = newProposal;
|
|
754
940
|
return newProposal;
|
|
755
941
|
}
|
|
756
942
|
|
|
757
943
|
async createCheckpointProposal(
|
|
758
944
|
checkpointHeader: CheckpointHeader,
|
|
759
945
|
archive: Fr,
|
|
946
|
+
feeAssetPriceModifier: bigint,
|
|
760
947
|
lastBlockInfo: CreateCheckpointProposalLastBlockData | undefined,
|
|
761
948
|
proposerAddress: EthAddress | undefined,
|
|
762
|
-
options: CheckpointProposalOptions,
|
|
949
|
+
options: CheckpointProposalOptions = {},
|
|
763
950
|
): Promise<CheckpointProposal> {
|
|
951
|
+
// Validate that we're not creating a proposal for an older or equal slot
|
|
952
|
+
if (this.lastProposedCheckpoint) {
|
|
953
|
+
const lastSlot = this.lastProposedCheckpoint.slotNumber;
|
|
954
|
+
const newSlot = checkpointHeader.slotNumber;
|
|
955
|
+
|
|
956
|
+
if (newSlot <= lastSlot) {
|
|
957
|
+
throw new Error(
|
|
958
|
+
`Cannot create checkpoint proposal for slot ${newSlot}: ` +
|
|
959
|
+
`already proposed checkpoint for slot ${lastSlot}`,
|
|
960
|
+
);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
|
|
764
964
|
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
765
|
-
|
|
965
|
+
const newProposal = await this.validationService.createCheckpointProposal(
|
|
766
966
|
checkpointHeader,
|
|
767
967
|
archive,
|
|
968
|
+
feeAssetPriceModifier,
|
|
768
969
|
lastBlockInfo,
|
|
769
970
|
proposerAddress,
|
|
770
971
|
options,
|
|
771
972
|
);
|
|
973
|
+
this.lastProposedCheckpoint = newProposal;
|
|
974
|
+
return newProposal;
|
|
772
975
|
}
|
|
773
976
|
|
|
774
977
|
async broadcastBlockProposal(proposal: BlockProposal): Promise<void> {
|
|
@@ -778,8 +981,10 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
778
981
|
async signAttestationsAndSigners(
|
|
779
982
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
780
983
|
proposer: EthAddress,
|
|
984
|
+
slot: SlotNumber,
|
|
985
|
+
blockNumber: BlockNumber | CheckpointNumber,
|
|
781
986
|
): Promise<Signature> {
|
|
782
|
-
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
|
|
987
|
+
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
|
|
783
988
|
}
|
|
784
989
|
|
|
785
990
|
async collectOwnAttestations(proposal: CheckpointProposal): Promise<CheckpointAttestation[]> {
|
|
@@ -788,6 +993,10 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
788
993
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, { inCommittee });
|
|
789
994
|
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
790
995
|
|
|
996
|
+
if (!attestations) {
|
|
997
|
+
return [];
|
|
998
|
+
}
|
|
999
|
+
|
|
791
1000
|
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
792
1001
|
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
793
1002
|
// due to inactivity for missed attestations.
|
|
@@ -886,7 +1095,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
886
1095
|
}
|
|
887
1096
|
|
|
888
1097
|
const payloadToSign = authRequest.getPayloadToSign();
|
|
889
|
-
|
|
1098
|
+
// AUTH_REQUEST doesn't require HA protection - multiple signatures are safe
|
|
1099
|
+
const context: SigningContext = { dutyType: DutyType.AUTH_REQUEST };
|
|
1100
|
+
const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign, context);
|
|
890
1101
|
const authResponse = new AuthResponse(statusMessage, signature);
|
|
891
1102
|
return authResponse.toBuffer();
|
|
892
1103
|
}
|