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