@aztec/validator-client 0.0.1-commit.2eb6648a → 0.0.1-commit.2f68f620
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 +52 -10
- package/dest/checkpoint_builder.d.ts +21 -8
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +124 -46
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +37 -7
- package/dest/duties/validation_service.d.ts +12 -13
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +33 -45
- package/dest/factory.d.ts +10 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +11 -5
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/key_store/ha_key_store.js +1 -1
- package/dest/metrics.d.ts +14 -2
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +24 -0
- package/dest/proposal_handler.d.ts +134 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/proposal_handler.js +1072 -0
- package/dest/validator.d.ts +53 -23
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +341 -231
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +142 -39
- package/src/config.ts +37 -6
- package/src/duties/validation_service.ts +59 -54
- package/src/factory.ts +20 -3
- package/src/index.ts +1 -2
- package/src/key_store/ha_key_store.ts +1 -1
- package/src/metrics.ts +37 -1
- package/src/proposal_handler.ts +1161 -0
- package/src/validator.ts +460 -272
- package/dest/block_proposal_handler.d.ts +0 -63
- package/dest/block_proposal_handler.d.ts.map +0 -1
- package/dest/block_proposal_handler.js +0 -546
- 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 -19
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -54
- package/src/block_proposal_handler.ts +0 -555
- 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 -154
package/src/validator.ts
CHANGED
|
@@ -1,73 +1,111 @@
|
|
|
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 {
|
|
5
|
-
BlockNumber,
|
|
6
|
-
CheckpointNumber,
|
|
7
|
-
EpochNumber,
|
|
8
|
-
IndexWithinCheckpoint,
|
|
9
|
-
SlotNumber,
|
|
10
|
-
} from '@aztec/foundation/branded-types';
|
|
4
|
+
import { CheckpointNumber, EpochNumber, IndexWithinCheckpoint, SlotNumber } from '@aztec/foundation/branded-types';
|
|
11
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
12
|
-
import { TimeoutError } from '@aztec/foundation/error';
|
|
13
6
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
14
7
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
8
|
+
import { FifoSet } from '@aztec/foundation/fifo-set';
|
|
15
9
|
import { type LogData, type Logger, createLogger } from '@aztec/foundation/log';
|
|
16
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
17
10
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
18
11
|
import { sleep } from '@aztec/foundation/sleep';
|
|
19
12
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
20
13
|
import type { KeystoreManager } from '@aztec/node-keystore';
|
|
21
|
-
import type { DuplicateProposalInfo, P2P, PeerId } from '@aztec/p2p';
|
|
14
|
+
import type { DuplicateAttestationInfo, DuplicateProposalInfo, P2P, PeerId } from '@aztec/p2p';
|
|
22
15
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
23
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
OffenseType,
|
|
18
|
+
WANT_TO_CLEAR_SLASH_EVENT,
|
|
19
|
+
WANT_TO_SLASH_EVENT,
|
|
20
|
+
type Watcher,
|
|
21
|
+
type WatcherEmitter,
|
|
22
|
+
getOffenseTypeName,
|
|
23
|
+
} from '@aztec/slasher';
|
|
24
24
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
25
|
-
import type { CommitteeAttestationsAndSigners,
|
|
25
|
+
import type { CommitteeAttestationsAndSigners, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
26
|
+
import type { CheckpointReexecutionTracker } from '@aztec/stdlib/checkpoint';
|
|
26
27
|
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
27
28
|
import type {
|
|
28
|
-
CreateCheckpointProposalLastBlockData,
|
|
29
29
|
ITxProvider,
|
|
30
30
|
Validator,
|
|
31
31
|
ValidatorClientFullConfig,
|
|
32
32
|
WorldStateSynchronizer,
|
|
33
33
|
} from '@aztec/stdlib/interfaces/server';
|
|
34
|
-
import {
|
|
35
|
-
import
|
|
36
|
-
BlockProposal,
|
|
37
|
-
BlockProposalOptions,
|
|
38
|
-
CheckpointAttestation,
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
35
|
+
import {
|
|
36
|
+
type BlockProposal,
|
|
37
|
+
type BlockProposalOptions,
|
|
38
|
+
type CheckpointAttestation,
|
|
39
|
+
CheckpointProposal,
|
|
40
|
+
type CheckpointProposalCore,
|
|
41
|
+
type CheckpointProposalOptions,
|
|
42
|
+
type CoordinationSignatureContext,
|
|
41
43
|
} from '@aztec/stdlib/p2p';
|
|
42
|
-
import { CheckpointProposal } from '@aztec/stdlib/p2p';
|
|
43
44
|
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
44
|
-
import type { BlockHeader,
|
|
45
|
+
import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
|
|
45
46
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
46
47
|
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
47
|
-
import {
|
|
48
|
-
|
|
48
|
+
import {
|
|
49
|
+
createHASigner,
|
|
50
|
+
createLocalSignerWithProtection,
|
|
51
|
+
createSignerFromSharedDb,
|
|
52
|
+
} from '@aztec/validator-ha-signer/factory';
|
|
53
|
+
import { DutyType, type SigningContext, type SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
54
|
+
import type { ValidatorHASigner } from '@aztec/validator-ha-signer/validator-ha-signer';
|
|
49
55
|
|
|
50
56
|
import { EventEmitter } from 'events';
|
|
51
57
|
import type { TypedDataDefinition } from 'viem';
|
|
52
58
|
|
|
53
|
-
import { BlockProposalHandler, type BlockProposalValidationFailureReason } from './block_proposal_handler.js';
|
|
54
59
|
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
55
60
|
import { ValidationService } from './duties/validation_service.js';
|
|
56
61
|
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
57
62
|
import type { ExtendedValidatorKeyStore } from './key_store/interface.js';
|
|
58
63
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
59
64
|
import { ValidatorMetrics } from './metrics.js';
|
|
65
|
+
import {
|
|
66
|
+
type BlockProposalValidationFailureReason,
|
|
67
|
+
type CheckpointProposalValidationFailureReason,
|
|
68
|
+
type CheckpointProposalValidationFailureResult,
|
|
69
|
+
ProposalHandler,
|
|
70
|
+
} from './proposal_handler.js';
|
|
60
71
|
|
|
61
72
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
62
73
|
// Just cap the set to avoid unbounded growth.
|
|
63
74
|
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
75
|
+
const MAX_TRACKED_INVALID_PROPOSAL_SLOTS = 1000;
|
|
76
|
+
const MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS = 1000;
|
|
77
|
+
const MAX_TRACKED_BAD_ATTESTATIONS = 10_000;
|
|
64
78
|
|
|
65
79
|
// What errors from the block proposal handler result in slashing
|
|
66
80
|
const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT: BlockProposalValidationFailureReason[] = [
|
|
67
81
|
'state_mismatch',
|
|
68
82
|
'failed_txs',
|
|
83
|
+
'global_variables_mismatch',
|
|
84
|
+
'invalid_proposal',
|
|
85
|
+
'parent_block_wrong_slot',
|
|
86
|
+
'in_hash_mismatch',
|
|
69
87
|
];
|
|
70
88
|
|
|
89
|
+
const SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT: Record<CheckpointProposalValidationFailureReason, boolean> = {
|
|
90
|
+
// enabled
|
|
91
|
+
['invalid_fee_asset_price_modifier']: true,
|
|
92
|
+
['checkpoint_header_mismatch']: true,
|
|
93
|
+
// These late mismatches should normally be caught by earlier checks, but if reached after validating the local
|
|
94
|
+
// checkpoint inputs, the proposer-signed payload disagrees with deterministic recomputation.
|
|
95
|
+
['archive_mismatch']: true,
|
|
96
|
+
['out_hash_mismatch']: true,
|
|
97
|
+
['no_blocks_for_slot']: true,
|
|
98
|
+
['too_many_blocks_in_checkpoint']: true,
|
|
99
|
+
['checkpoint_validation_failed']: true,
|
|
100
|
+
['last_block_archive_mismatch']: true,
|
|
101
|
+
|
|
102
|
+
// disabled
|
|
103
|
+
['invalid_signature']: false,
|
|
104
|
+
['last_block_not_found']: false,
|
|
105
|
+
['block_fetch_error']: false,
|
|
106
|
+
['checkpoint_already_published']: false,
|
|
107
|
+
};
|
|
108
|
+
|
|
71
109
|
/**
|
|
72
110
|
* Validator Client
|
|
73
111
|
*/
|
|
@@ -76,29 +114,41 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
76
114
|
private validationService: ValidationService;
|
|
77
115
|
private metrics: ValidatorMetrics;
|
|
78
116
|
private log: Logger;
|
|
79
|
-
|
|
80
117
|
// Whether it has already registered handlers on the p2p client
|
|
81
118
|
private hasRegisteredHandlers = false;
|
|
82
119
|
|
|
83
|
-
|
|
84
|
-
private
|
|
120
|
+
/** Tracks the last block proposal we created, to detect duplicate proposal attempts. */
|
|
121
|
+
private lastProposedBlock?: BlockProposal;
|
|
122
|
+
|
|
123
|
+
/** Tracks the last checkpoint proposal we created. */
|
|
124
|
+
private lastProposedCheckpoint?: CheckpointProposal;
|
|
85
125
|
|
|
86
126
|
private lastEpochForCommitteeUpdateLoop: EpochNumber | undefined;
|
|
87
127
|
private epochCacheUpdateLoop: RunningPromise;
|
|
128
|
+
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */
|
|
129
|
+
private lastAttestedEpochByAttester: Map<string, EpochNumber> = new Map();
|
|
130
|
+
|
|
131
|
+
private proposersOfInvalidBlocks = FifoSet.withLimit<string>(MAX_PROPOSERS_OF_INVALID_BLOCKS);
|
|
132
|
+
private slotsWithInvalidProposals = FifoSet.withLimit<SlotNumber>(MAX_TRACKED_INVALID_PROPOSAL_SLOTS);
|
|
133
|
+
private invalidCheckpointProposalOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS);
|
|
134
|
+
private badAttestationOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_BAD_ATTESTATIONS);
|
|
135
|
+
private slotsWithProposalEquivocation = FifoSet.withLimit<SlotNumber>(MAX_TRACKED_INVALID_PROPOSAL_SLOTS);
|
|
88
136
|
|
|
89
|
-
|
|
137
|
+
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */
|
|
138
|
+
private lastAttestedProposal?: CheckpointProposalCore;
|
|
90
139
|
|
|
91
140
|
protected constructor(
|
|
92
141
|
private keyStore: ExtendedValidatorKeyStore,
|
|
93
142
|
private epochCache: EpochCache,
|
|
94
143
|
private p2pClient: P2P,
|
|
95
|
-
private
|
|
144
|
+
private proposalHandler: ProposalHandler,
|
|
96
145
|
private blockSource: L2BlockSource,
|
|
97
146
|
private checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
98
147
|
private worldState: WorldStateSynchronizer,
|
|
99
148
|
private l1ToL2MessageSource: L1ToL2MessageSource,
|
|
100
149
|
private config: ValidatorClientFullConfig,
|
|
101
150
|
private blobClient: BlobClientInterface,
|
|
151
|
+
private slashingProtectionSigner: ValidatorHASigner,
|
|
102
152
|
private dateProvider: DateProvider = new DateProvider(),
|
|
103
153
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
104
154
|
log = createLogger('validator'),
|
|
@@ -111,11 +161,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
111
161
|
this.tracer = telemetry.getTracer('Validator');
|
|
112
162
|
this.metrics = new ValidatorMetrics(telemetry);
|
|
113
163
|
|
|
114
|
-
this.validationService = new ValidationService(
|
|
164
|
+
this.validationService = new ValidationService(
|
|
165
|
+
keyStore,
|
|
166
|
+
this.getSignatureContext(),
|
|
167
|
+
this.log.createChild('validation-service'),
|
|
168
|
+
);
|
|
169
|
+
this.proposalHandler.setCheckpointProposalValidationFailureCallback((proposal, result, proposalInfo) =>
|
|
170
|
+
this.handleInvalidCheckpointProposal(proposal, result, proposalInfo),
|
|
171
|
+
);
|
|
115
172
|
|
|
116
173
|
// Refresh epoch cache every second to trigger alert if participation in committee changes
|
|
117
174
|
this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), this.log, 1000);
|
|
118
|
-
|
|
119
175
|
const myAddresses = this.getValidatorAddresses();
|
|
120
176
|
this.log.verbose(`Initialized validator with addresses: ${myAddresses.map(a => a.toString()).join(', ')}`);
|
|
121
177
|
}
|
|
@@ -152,6 +208,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
152
208
|
this.log.trace(`No committee found for slot`);
|
|
153
209
|
return;
|
|
154
210
|
}
|
|
211
|
+
this.metrics.setCurrentEpoch(epoch);
|
|
155
212
|
if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
|
|
156
213
|
const me = this.getValidatorAddresses();
|
|
157
214
|
const committeeSet = new Set(committee.map(v => v.toString()));
|
|
@@ -183,14 +240,23 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
183
240
|
txProvider: ITxProvider,
|
|
184
241
|
keyStoreManager: KeystoreManager,
|
|
185
242
|
blobClient: BlobClientInterface,
|
|
243
|
+
reexecutionTracker: CheckpointReexecutionTracker,
|
|
186
244
|
dateProvider: DateProvider = new DateProvider(),
|
|
187
245
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
246
|
+
slashingProtectionDb?: SlashingProtectionDatabase,
|
|
188
247
|
) {
|
|
189
248
|
const metrics = new ValidatorMetrics(telemetry);
|
|
190
249
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
191
250
|
txsPermitted: !config.disableTransactions,
|
|
251
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock,
|
|
252
|
+
maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
|
|
253
|
+
skipSlotValidation: config.skipProposalSlotValidation,
|
|
254
|
+
signatureContext: {
|
|
255
|
+
chainId: config.l1ChainId,
|
|
256
|
+
rollupAddress: config.rollupAddress,
|
|
257
|
+
},
|
|
192
258
|
});
|
|
193
|
-
const
|
|
259
|
+
const proposalHandler = new ProposalHandler(
|
|
194
260
|
checkpointsBuilder,
|
|
195
261
|
worldState,
|
|
196
262
|
blockSource,
|
|
@@ -199,33 +265,55 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
199
265
|
blockProposalValidator,
|
|
200
266
|
epochCache,
|
|
201
267
|
config,
|
|
268
|
+
blobClient,
|
|
269
|
+
reexecutionTracker,
|
|
202
270
|
metrics,
|
|
203
271
|
dateProvider,
|
|
204
272
|
telemetry,
|
|
273
|
+
undefined,
|
|
205
274
|
);
|
|
206
275
|
|
|
207
|
-
|
|
208
|
-
|
|
276
|
+
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
277
|
+
let slashingProtectionSigner: ValidatorHASigner;
|
|
278
|
+
if (slashingProtectionDb) {
|
|
279
|
+
// Shared database mode: use a pre-existing database (e.g. for testing HA setups).
|
|
280
|
+
({ signer: slashingProtectionSigner } = createSignerFromSharedDb(slashingProtectionDb, config, {
|
|
281
|
+
telemetryClient: telemetry,
|
|
282
|
+
dateProvider,
|
|
283
|
+
}));
|
|
284
|
+
} else if (config.haSigningEnabled) {
|
|
285
|
+
// Multi-node HA mode: use PostgreSQL-backed distributed locking.
|
|
209
286
|
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
210
287
|
const haConfig = {
|
|
211
288
|
...config,
|
|
212
289
|
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000,
|
|
213
290
|
};
|
|
214
|
-
|
|
215
|
-
|
|
291
|
+
({ signer: slashingProtectionSigner } = await createHASigner(haConfig, {
|
|
292
|
+
telemetryClient: telemetry,
|
|
293
|
+
dateProvider,
|
|
294
|
+
}));
|
|
295
|
+
} else {
|
|
296
|
+
// Single-node mode: use LMDB-backed local signing protection.
|
|
297
|
+
// This prevents double-signing if the node crashes and restarts mid-proposal.
|
|
298
|
+
({ signer: slashingProtectionSigner } = await createLocalSignerWithProtection(config, {
|
|
299
|
+
telemetryClient: telemetry,
|
|
300
|
+
dateProvider,
|
|
301
|
+
}));
|
|
216
302
|
}
|
|
303
|
+
const validatorKeyStore: ExtendedValidatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, slashingProtectionSigner);
|
|
217
304
|
|
|
218
305
|
const validator = new ValidatorClient(
|
|
219
306
|
validatorKeyStore,
|
|
220
307
|
epochCache,
|
|
221
308
|
p2pClient,
|
|
222
|
-
|
|
309
|
+
proposalHandler,
|
|
223
310
|
blockSource,
|
|
224
311
|
checkpointsBuilder,
|
|
225
312
|
worldState,
|
|
226
313
|
l1ToL2MessageSource,
|
|
227
314
|
config,
|
|
228
315
|
blobClient,
|
|
316
|
+
slashingProtectionSigner,
|
|
229
317
|
dateProvider,
|
|
230
318
|
telemetry,
|
|
231
319
|
);
|
|
@@ -239,14 +327,21 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
239
327
|
.filter(addr => !this.config.disabledValidators.some(disabled => disabled.equals(addr)));
|
|
240
328
|
}
|
|
241
329
|
|
|
242
|
-
public
|
|
243
|
-
return this.
|
|
330
|
+
public getProposalHandler() {
|
|
331
|
+
return this.proposalHandler;
|
|
244
332
|
}
|
|
245
333
|
|
|
246
334
|
public signWithAddress(addr: EthAddress, msg: TypedDataDefinition, context: SigningContext) {
|
|
247
335
|
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
248
336
|
}
|
|
249
337
|
|
|
338
|
+
private getSignatureContext(): CoordinationSignatureContext {
|
|
339
|
+
return {
|
|
340
|
+
chainId: this.config.l1ChainId,
|
|
341
|
+
rollupAddress: this.config.rollupAddress,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
250
345
|
public getCoinbaseForAttestor(attestor: EthAddress): EthAddress {
|
|
251
346
|
return this.keyStore.getCoinbaseAddress(attestor);
|
|
252
347
|
}
|
|
@@ -259,8 +354,27 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
259
354
|
return this.config;
|
|
260
355
|
}
|
|
261
356
|
|
|
357
|
+
public hasProposalEquivocation(slotNumber: SlotNumber): boolean {
|
|
358
|
+
return this.slotsWithProposalEquivocation.has(slotNumber);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
public hasInvalidProposals(slotNumber: SlotNumber): boolean {
|
|
362
|
+
return this.slotsWithInvalidProposals.has(slotNumber);
|
|
363
|
+
}
|
|
364
|
+
|
|
262
365
|
public updateConfig(config: Partial<ValidatorClientFullConfig>) {
|
|
263
366
|
this.config = { ...this.config, ...config };
|
|
367
|
+
this.proposalHandler.updateConfig(config);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
public reloadKeystore(newManager: KeystoreManager): void {
|
|
371
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
372
|
+
this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
|
|
373
|
+
this.validationService = new ValidationService(
|
|
374
|
+
this.keyStore,
|
|
375
|
+
this.getSignatureContext(),
|
|
376
|
+
this.log.createChild('validation-service'),
|
|
377
|
+
);
|
|
264
378
|
}
|
|
265
379
|
|
|
266
380
|
public async start() {
|
|
@@ -307,13 +421,22 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
307
421
|
checkpoint: CheckpointProposalCore,
|
|
308
422
|
proposalSender: PeerId,
|
|
309
423
|
): Promise<CheckpointAttestation[] | undefined> => this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
310
|
-
this.p2pClient.
|
|
424
|
+
this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
|
|
311
425
|
|
|
312
426
|
// Duplicate proposal handler - triggers slashing for equivocation
|
|
313
427
|
this.p2pClient.registerDuplicateProposalCallback((info: DuplicateProposalInfo) => {
|
|
314
428
|
this.handleDuplicateProposal(info);
|
|
315
429
|
});
|
|
316
430
|
|
|
431
|
+
// Duplicate attestation handler - triggers slashing for attestation equivocation
|
|
432
|
+
this.p2pClient.registerDuplicateAttestationCallback((info: DuplicateAttestationInfo) => {
|
|
433
|
+
this.handleDuplicateAttestation(info);
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
this.p2pClient.registerCheckpointAttestationCallback((attestation: CheckpointAttestation) => {
|
|
437
|
+
this.handleCheckpointAttestation(attestation);
|
|
438
|
+
});
|
|
439
|
+
|
|
317
440
|
const myAddresses = this.getValidatorAddresses();
|
|
318
441
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
319
442
|
|
|
@@ -341,6 +464,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
341
464
|
return false;
|
|
342
465
|
}
|
|
343
466
|
|
|
467
|
+
// Log self-proposals from HA peers (same validator key on different nodes)
|
|
468
|
+
if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
469
|
+
this.log.verbose(`Processing block proposal from HA peer for slot ${slotNumber}`, {
|
|
470
|
+
proposer: proposer.toString(),
|
|
471
|
+
slotNumber,
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
|
|
344
475
|
// Check if we're in the committee (for metrics purposes)
|
|
345
476
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
346
477
|
const partOfCommittee = inCommittee.length > 0;
|
|
@@ -352,27 +483,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
352
483
|
fishermanMode: this.config.fishermanMode || false,
|
|
353
484
|
});
|
|
354
485
|
|
|
355
|
-
// Reexecute
|
|
356
|
-
|
|
357
|
-
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } =
|
|
358
|
-
this.config;
|
|
359
|
-
const shouldReexecute =
|
|
360
|
-
fishermanMode ||
|
|
361
|
-
(slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute) ||
|
|
362
|
-
(partOfCommittee && validatorReexecute) ||
|
|
363
|
-
alwaysReexecuteBlockProposals ||
|
|
364
|
-
this.blobClient.canUpload();
|
|
365
|
-
|
|
366
|
-
const validationResult = await this.blockProposalHandler.handleBlockProposal(
|
|
367
|
-
proposal,
|
|
368
|
-
proposalSender,
|
|
369
|
-
!!shouldReexecute && !escapeHatchOpen,
|
|
370
|
-
);
|
|
486
|
+
// Reexecute outside the escape hatch so slashing observers can detect invalid proposals even when penalties are 0.
|
|
487
|
+
const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !escapeHatchOpen);
|
|
371
488
|
|
|
372
489
|
if (!validationResult.isValid) {
|
|
373
|
-
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
374
|
-
|
|
375
490
|
const reason = validationResult.reason || 'unknown';
|
|
491
|
+
|
|
492
|
+
this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
|
|
493
|
+
|
|
376
494
|
// Classify failure reason: bad proposal vs node issue
|
|
377
495
|
const badProposalReasons: BlockProposalValidationFailureReason[] = [
|
|
378
496
|
'invalid_proposal',
|
|
@@ -389,15 +507,18 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
389
507
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
390
508
|
}
|
|
391
509
|
|
|
392
|
-
// Slash invalid block proposals (can happen even when not in committee)
|
|
393
510
|
if (
|
|
394
511
|
!escapeHatchOpen &&
|
|
395
512
|
validationResult.reason &&
|
|
396
|
-
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
|
|
397
|
-
slashBroadcastedInvalidBlockPenalty > 0n
|
|
513
|
+
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
|
|
398
514
|
) {
|
|
399
|
-
this.log.
|
|
515
|
+
this.log.info(`Detected invalid block proposal offense`, {
|
|
516
|
+
...proposalInfo,
|
|
517
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
518
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL),
|
|
519
|
+
});
|
|
400
520
|
this.slashInvalidBlock(proposal);
|
|
521
|
+
this.markInvalidProposalSlot(proposal.slotNumber);
|
|
401
522
|
}
|
|
402
523
|
return false;
|
|
403
524
|
}
|
|
@@ -427,51 +548,56 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
427
548
|
proposal: CheckpointProposalCore,
|
|
428
549
|
_proposalSender: PeerId,
|
|
429
550
|
): Promise<CheckpointAttestation[] | undefined> {
|
|
430
|
-
const
|
|
551
|
+
const proposalSlotNumber = proposal.slotNumber;
|
|
431
552
|
const proposer = proposal.getSender();
|
|
432
553
|
|
|
433
554
|
// If escape hatch is open for this slot's epoch, do not attest.
|
|
434
|
-
if (await this.epochCache.isEscapeHatchOpenAtSlot(
|
|
435
|
-
this.log.warn(`Escape hatch open for slot ${
|
|
555
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(proposalSlotNumber)) {
|
|
556
|
+
this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
|
|
436
557
|
return undefined;
|
|
437
558
|
}
|
|
438
559
|
|
|
439
|
-
//
|
|
440
|
-
if (!
|
|
441
|
-
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
560
|
+
// Early-out for equivocation: refuses if we've already attested to a higher slot.
|
|
561
|
+
if (!this.shouldAttestToSlot(proposalSlotNumber)) {
|
|
442
562
|
return undefined;
|
|
443
563
|
}
|
|
444
564
|
|
|
445
|
-
//
|
|
446
|
-
|
|
565
|
+
// Ignore proposals from ourselves (may happen in HA setups)
|
|
566
|
+
if (proposer && this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
567
|
+
this.log.debug(`Ignoring block proposal from self for slot ${proposalSlotNumber}`, {
|
|
568
|
+
proposer: proposer.toString(),
|
|
569
|
+
proposalSlotNumber,
|
|
570
|
+
});
|
|
571
|
+
return undefined;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// Check that I have any address in the committee where this checkpoint will land before attesting
|
|
575
|
+
const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
|
|
447
576
|
const partOfCommittee = inCommittee.length > 0;
|
|
448
577
|
|
|
449
578
|
const proposalInfo = {
|
|
450
|
-
|
|
579
|
+
proposalSlotNumber,
|
|
451
580
|
archive: proposal.archive.toString(),
|
|
452
|
-
proposer: proposer
|
|
453
|
-
txCount: proposal.txHashes.length,
|
|
581
|
+
proposer: proposer?.toString(),
|
|
454
582
|
};
|
|
455
|
-
this.log.info(`Received checkpoint proposal for slot ${
|
|
583
|
+
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
456
584
|
...proposalInfo,
|
|
457
|
-
txHashes: proposal.txHashes.map(t => t.toString()),
|
|
458
585
|
fishermanMode: this.config.fishermanMode || false,
|
|
459
586
|
});
|
|
460
587
|
|
|
461
|
-
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
588
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
|
|
589
|
+
// Uses the cached result from the all-nodes callback if available (avoids double validation).
|
|
590
|
+
let checkpointNumber: CheckpointNumber;
|
|
462
591
|
if (this.config.skipCheckpointProposalValidation) {
|
|
463
|
-
this.log.warn(`Skipping checkpoint proposal validation for slot ${
|
|
592
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
593
|
+
checkpointNumber = CheckpointNumber(0);
|
|
464
594
|
} else {
|
|
465
|
-
const validationResult = await this.
|
|
595
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
466
596
|
if (!validationResult.isValid) {
|
|
467
597
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
468
598
|
return undefined;
|
|
469
599
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
// Upload blobs to filestore if we can (fire and forget)
|
|
473
|
-
if (this.blobClient.canUpload()) {
|
|
474
|
-
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
600
|
+
checkpointNumber = validationResult.checkpointNumber;
|
|
475
601
|
}
|
|
476
602
|
|
|
477
603
|
// Check that I have any address in current committee before attesting
|
|
@@ -482,14 +608,28 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
482
608
|
}
|
|
483
609
|
|
|
484
610
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
485
|
-
this.log.info(
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
611
|
+
this.log.info(
|
|
612
|
+
`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${proposalSlotNumber}`,
|
|
613
|
+
{
|
|
614
|
+
...proposalInfo,
|
|
615
|
+
inCommittee: partOfCommittee,
|
|
616
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
617
|
+
},
|
|
618
|
+
);
|
|
490
619
|
|
|
491
620
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
492
621
|
|
|
622
|
+
// Track epoch participation per attester: count each (attester, epoch) pair at most once
|
|
623
|
+
const proposalEpoch = getEpochAtSlot(proposalSlotNumber, this.epochCache.getL1Constants());
|
|
624
|
+
for (const attester of inCommittee) {
|
|
625
|
+
const key = attester.toString();
|
|
626
|
+
const lastEpoch = this.lastAttestedEpochByAttester.get(key);
|
|
627
|
+
if (lastEpoch === undefined || proposalEpoch > lastEpoch) {
|
|
628
|
+
this.lastAttestedEpochByAttester.set(key, proposalEpoch);
|
|
629
|
+
this.metrics.incAttestedEpochCount(attester);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
493
633
|
// Determine which validators should attest
|
|
494
634
|
let attestors: EthAddress[];
|
|
495
635
|
if (partOfCommittee) {
|
|
@@ -508,174 +648,62 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
508
648
|
|
|
509
649
|
if (this.config.fishermanMode) {
|
|
510
650
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
511
|
-
this.log.info(`Creating checkpoint attestations for slot ${
|
|
651
|
+
this.log.info(`Creating checkpoint attestations for slot ${proposalSlotNumber}`, {
|
|
512
652
|
...proposalInfo,
|
|
513
653
|
attestors: attestors.map(a => a.toString()),
|
|
514
654
|
});
|
|
515
655
|
return undefined;
|
|
516
656
|
}
|
|
517
657
|
|
|
518
|
-
return this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
private async createCheckpointAttestationsFromProposal(
|
|
522
|
-
proposal: CheckpointProposalCore,
|
|
523
|
-
attestors: EthAddress[] = [],
|
|
524
|
-
): Promise<CheckpointAttestation[]> {
|
|
525
|
-
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
526
|
-
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
527
|
-
return attestations;
|
|
658
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
|
|
528
659
|
}
|
|
529
660
|
|
|
530
661
|
/**
|
|
531
|
-
*
|
|
532
|
-
* @returns
|
|
662
|
+
* Checks if we should attest to a slot based on equivocation prevention rules.
|
|
663
|
+
* @returns true if we should attest, false if we should skip
|
|
533
664
|
*/
|
|
534
|
-
private
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
const timeoutSeconds = 10; // TODO(palla/mbps): This should map to the timetable settings
|
|
665
|
+
private shouldAttestToSlot(slotNumber: SlotNumber): boolean {
|
|
666
|
+
// If attestToEquivocatedProposals is true, always allow
|
|
667
|
+
if (this.config.attestToEquivocatedProposals) {
|
|
668
|
+
return true;
|
|
669
|
+
}
|
|
540
670
|
|
|
541
|
-
//
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
async () => {
|
|
546
|
-
await this.blockSource.syncImmediate();
|
|
547
|
-
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
548
|
-
},
|
|
549
|
-
`waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`,
|
|
550
|
-
timeoutSeconds,
|
|
551
|
-
0.5,
|
|
671
|
+
// Check if incoming slot is strictly greater than last attested
|
|
672
|
+
if (this.lastAttestedProposal && slotNumber <= this.lastAttestedProposal.slotNumber) {
|
|
673
|
+
this.log.warn(
|
|
674
|
+
`Refusing to process a proposal for slot ${slotNumber} given we already attested to a proposal for slot ${this.lastAttestedProposal.slotNumber}`,
|
|
552
675
|
);
|
|
553
|
-
|
|
554
|
-
if (err instanceof TimeoutError) {
|
|
555
|
-
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
556
|
-
return { isValid: false, reason: 'last_block_not_found' };
|
|
557
|
-
}
|
|
558
|
-
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
559
|
-
return { isValid: false, reason: 'block_fetch_error' };
|
|
676
|
+
return false;
|
|
560
677
|
}
|
|
561
678
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
return { isValid: false, reason: 'last_block_not_found' };
|
|
565
|
-
}
|
|
679
|
+
return true;
|
|
680
|
+
}
|
|
566
681
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
682
|
+
private async createCheckpointAttestationsFromProposal(
|
|
683
|
+
proposal: CheckpointProposalCore,
|
|
684
|
+
attestors: EthAddress[] = [],
|
|
685
|
+
checkpointNumber: CheckpointNumber,
|
|
686
|
+
): Promise<CheckpointAttestation[] | undefined> {
|
|
687
|
+
// Equivocation check: must happen right before signing to minimize the race window
|
|
688
|
+
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
689
|
+
return undefined;
|
|
572
690
|
}
|
|
573
691
|
|
|
574
|
-
this.
|
|
575
|
-
...proposalInfo,
|
|
576
|
-
blockNumbers: blocks.map(b => b.number),
|
|
577
|
-
});
|
|
578
|
-
|
|
579
|
-
// Get checkpoint constants from first block
|
|
580
|
-
const firstBlock = blocks[0];
|
|
581
|
-
const constants = this.extractCheckpointConstants(firstBlock);
|
|
582
|
-
const checkpointNumber = firstBlock.checkpointNumber;
|
|
583
|
-
|
|
584
|
-
// Get L1-to-L2 messages for this checkpoint
|
|
585
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
586
|
-
|
|
587
|
-
// Compute the previous checkpoint out hashes for the epoch.
|
|
588
|
-
// TODO: There can be a more efficient way to get the previous checkpoint out hashes without having to fetch the
|
|
589
|
-
// actual checkpoints and the blocks/txs in them.
|
|
590
|
-
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
591
|
-
const previousCheckpoints = (await this.blockSource.getCheckpointsForEpoch(epoch))
|
|
592
|
-
.filter(b => b.number < checkpointNumber)
|
|
593
|
-
.sort((a, b) => a.number - b.number);
|
|
594
|
-
const previousCheckpointOutHashes = previousCheckpoints.map(c => c.getCheckpointOutHash());
|
|
595
|
-
|
|
596
|
-
// Fork world state at the block before the first block
|
|
597
|
-
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
598
|
-
const fork = await this.worldState.fork(parentBlockNumber);
|
|
599
|
-
|
|
600
|
-
try {
|
|
601
|
-
// Create checkpoint builder with all existing blocks
|
|
602
|
-
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
|
|
603
|
-
checkpointNumber,
|
|
604
|
-
constants,
|
|
605
|
-
l1ToL2Messages,
|
|
606
|
-
previousCheckpointOutHashes,
|
|
607
|
-
fork,
|
|
608
|
-
blocks,
|
|
609
|
-
this.log.getBindings(),
|
|
610
|
-
);
|
|
611
|
-
|
|
612
|
-
// Complete the checkpoint to get computed values
|
|
613
|
-
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
692
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
|
|
614
693
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
this.log.warn(`Checkpoint header mismatch`, {
|
|
618
|
-
...proposalInfo,
|
|
619
|
-
computed: computedCheckpoint.header.toInspect(),
|
|
620
|
-
proposal: proposal.checkpointHeader.toInspect(),
|
|
621
|
-
});
|
|
622
|
-
return { isValid: false, reason: 'checkpoint_header_mismatch' };
|
|
623
|
-
}
|
|
694
|
+
// Track the proposal we attested to (to prevent equivocation)
|
|
695
|
+
this.lastAttestedProposal = proposal;
|
|
624
696
|
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
this.log.warn(`Archive root mismatch`, {
|
|
628
|
-
...proposalInfo,
|
|
629
|
-
computed: computedCheckpoint.archive.root.toString(),
|
|
630
|
-
proposal: proposal.archive.toString(),
|
|
631
|
-
});
|
|
632
|
-
return { isValid: false, reason: 'archive_mismatch' };
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
636
|
-
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
637
|
-
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
638
|
-
const computedEpochOutHash = accumulateCheckpointOutHashes([...previousCheckpointOutHashes, checkpointOutHash]);
|
|
639
|
-
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
640
|
-
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
641
|
-
this.log.warn(`Epoch out hash mismatch`, {
|
|
642
|
-
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
643
|
-
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
644
|
-
checkpointOutHash: checkpointOutHash.toString(),
|
|
645
|
-
previousCheckpointOutHashes: previousCheckpointOutHashes.map(h => h.toString()),
|
|
646
|
-
...proposalInfo,
|
|
647
|
-
});
|
|
648
|
-
return { isValid: false, reason: 'out_hash_mismatch' };
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
652
|
-
return { isValid: true };
|
|
653
|
-
} finally {
|
|
654
|
-
await fork.close();
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
/**
|
|
659
|
-
* Extract checkpoint global variables from a block.
|
|
660
|
-
*/
|
|
661
|
-
private extractCheckpointConstants(block: L2Block): CheckpointGlobalVariables {
|
|
662
|
-
const gv = block.header.globalVariables;
|
|
663
|
-
return {
|
|
664
|
-
chainId: gv.chainId,
|
|
665
|
-
version: gv.version,
|
|
666
|
-
slotNumber: gv.slotNumber,
|
|
667
|
-
coinbase: gv.coinbase,
|
|
668
|
-
feeRecipient: gv.feeRecipient,
|
|
669
|
-
gasFees: gv.gasFees,
|
|
670
|
-
};
|
|
697
|
+
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
698
|
+
return attestations;
|
|
671
699
|
}
|
|
672
700
|
|
|
673
701
|
/**
|
|
674
702
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
675
703
|
*/
|
|
676
|
-
|
|
704
|
+
protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
|
|
677
705
|
try {
|
|
678
|
-
const lastBlockHeader = await this.blockSource.
|
|
706
|
+
const lastBlockHeader = (await this.blockSource.getBlockData({ archive: proposal.archive }))?.header;
|
|
679
707
|
if (!lastBlockHeader) {
|
|
680
708
|
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
681
709
|
return;
|
|
@@ -688,7 +716,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
688
716
|
}
|
|
689
717
|
|
|
690
718
|
const blobFields = blocks.flatMap(b => b.toBlobFields());
|
|
691
|
-
const blobs: Blob[] = getBlobsPerL1Block(blobFields);
|
|
719
|
+
const blobs: Blob[] = await getBlobsPerL1Block(blobFields);
|
|
692
720
|
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
693
721
|
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
694
722
|
...proposalInfo,
|
|
@@ -708,12 +736,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
708
736
|
return;
|
|
709
737
|
}
|
|
710
738
|
|
|
711
|
-
// Trim the set if it's too big.
|
|
712
|
-
if (this.proposersOfInvalidBlocks.size > MAX_PROPOSERS_OF_INVALID_BLOCKS) {
|
|
713
|
-
// remove oldest proposer. `values` is guaranteed to be in insertion order.
|
|
714
|
-
this.proposersOfInvalidBlocks.delete(this.proposersOfInvalidBlocks.values().next().value!);
|
|
715
|
-
}
|
|
716
|
-
|
|
717
739
|
this.proposersOfInvalidBlocks.add(proposer.toString());
|
|
718
740
|
|
|
719
741
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
@@ -726,20 +748,115 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
726
748
|
]);
|
|
727
749
|
}
|
|
728
750
|
|
|
751
|
+
private handleInvalidCheckpointProposal(
|
|
752
|
+
proposal: CheckpointProposalCore,
|
|
753
|
+
result: CheckpointProposalValidationFailureResult,
|
|
754
|
+
proposalInfo: LogData,
|
|
755
|
+
): void {
|
|
756
|
+
if (!SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT[result.reason]) {
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
this.markInvalidProposalSlot(proposal.slotNumber);
|
|
761
|
+
|
|
762
|
+
if (this.slashInvalidCheckpointProposal(proposal)) {
|
|
763
|
+
this.log.info(`Detected invalid checkpoint proposal offense`, {
|
|
764
|
+
...proposalInfo,
|
|
765
|
+
reason: result.reason,
|
|
766
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
767
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL),
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
private slashInvalidCheckpointProposal(proposal: CheckpointProposalCore): boolean {
|
|
773
|
+
const proposer = proposal.getSender();
|
|
774
|
+
if (!proposer) {
|
|
775
|
+
this.log.warn(`Cannot slash checkpoint proposal with invalid signature`, {
|
|
776
|
+
slotNumber: proposal.slotNumber,
|
|
777
|
+
archive: proposal.archive.toString(),
|
|
778
|
+
});
|
|
779
|
+
return false;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
const offenseType = OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL;
|
|
783
|
+
const offenseKey = `${proposer.toString()}:${offenseType}:${proposal.slotNumber}`;
|
|
784
|
+
if (!this.invalidCheckpointProposalOffenseKeys.addIfAbsent(offenseKey)) {
|
|
785
|
+
return false;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
789
|
+
{
|
|
790
|
+
validator: proposer,
|
|
791
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
792
|
+
offenseType,
|
|
793
|
+
epochOrSlot: BigInt(proposal.slotNumber),
|
|
794
|
+
},
|
|
795
|
+
]);
|
|
796
|
+
return true;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
private markInvalidProposalSlot(slotNumber: SlotNumber): void {
|
|
800
|
+
this.slotsWithInvalidProposals.add(slotNumber);
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
private handleCheckpointAttestation(attestation: CheckpointAttestation): void {
|
|
804
|
+
const slotNumber = attestation.slotNumber;
|
|
805
|
+
if (!this.slotsWithInvalidProposals.has(slotNumber) || this.slotsWithProposalEquivocation.has(slotNumber)) {
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
const attester = attestation.getSender();
|
|
810
|
+
if (!attester) {
|
|
811
|
+
this.log.warn(`Cannot slash checkpoint attestation with invalid signature`, {
|
|
812
|
+
slotNumber,
|
|
813
|
+
archive: attestation.archive.toString(),
|
|
814
|
+
});
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
this.slashAttestedToInvalidCheckpointProposal(slotNumber, attester);
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
private slashAttestedToInvalidCheckpointProposal(slotNumber: SlotNumber, attester: EthAddress): void {
|
|
822
|
+
const offenseKey = `${attester.toString()}:${OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL}:${slotNumber}`;
|
|
823
|
+
if (!this.badAttestationOffenseKeys.addIfAbsent(offenseKey)) {
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
this.log.info(`Detected attestation to invalid checkpoint proposal offense`, {
|
|
828
|
+
attester: attester.toString(),
|
|
829
|
+
slotNumber,
|
|
830
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
831
|
+
offenseType: getOffenseTypeName(OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL),
|
|
832
|
+
});
|
|
833
|
+
|
|
834
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
835
|
+
{
|
|
836
|
+
validator: attester,
|
|
837
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
838
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
839
|
+
epochOrSlot: BigInt(slotNumber),
|
|
840
|
+
},
|
|
841
|
+
]);
|
|
842
|
+
}
|
|
843
|
+
|
|
729
844
|
/**
|
|
730
845
|
* Handle detection of a duplicate proposal (equivocation).
|
|
731
846
|
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
732
847
|
*/
|
|
733
848
|
private handleDuplicateProposal(info: DuplicateProposalInfo): void {
|
|
734
849
|
const { slot, proposer, type } = info;
|
|
850
|
+
this.slotsWithProposalEquivocation.add(slot);
|
|
735
851
|
|
|
736
|
-
this.log.
|
|
852
|
+
this.log.info(`Detected duplicate ${type} proposal offense from ${proposer.toString()} at slot ${slot}`, {
|
|
737
853
|
proposer: proposer.toString(),
|
|
738
854
|
slot,
|
|
739
855
|
type,
|
|
856
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
857
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_PROPOSAL),
|
|
740
858
|
});
|
|
741
859
|
|
|
742
|
-
// Emit slash event
|
|
743
860
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
744
861
|
{
|
|
745
862
|
validator: proposer,
|
|
@@ -748,10 +865,42 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
748
865
|
epochOrSlot: BigInt(slot),
|
|
749
866
|
},
|
|
750
867
|
]);
|
|
868
|
+
|
|
869
|
+
this.emit(WANT_TO_CLEAR_SLASH_EVENT, [
|
|
870
|
+
{
|
|
871
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
872
|
+
epochOrSlot: BigInt(slot),
|
|
873
|
+
},
|
|
874
|
+
]);
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* Handle detection of a duplicate attestation (equivocation).
|
|
879
|
+
* Emits a slash event when an attester signs attestations for different proposals at the same slot.
|
|
880
|
+
*/
|
|
881
|
+
private handleDuplicateAttestation(info: DuplicateAttestationInfo): void {
|
|
882
|
+
const { slot, attester } = info;
|
|
883
|
+
|
|
884
|
+
this.log.info(`Detected duplicate attestation offense from ${attester.toString()} at slot ${slot}`, {
|
|
885
|
+
attester: attester.toString(),
|
|
886
|
+
slot,
|
|
887
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
888
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_ATTESTATION),
|
|
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
|
+
]);
|
|
751
899
|
}
|
|
752
900
|
|
|
753
901
|
async createBlockProposal(
|
|
754
902
|
blockHeader: BlockHeader,
|
|
903
|
+
checkpointNumber: CheckpointNumber,
|
|
755
904
|
indexWithinCheckpoint: IndexWithinCheckpoint,
|
|
756
905
|
inHash: Fr,
|
|
757
906
|
archive: Fr,
|
|
@@ -759,17 +908,26 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
759
908
|
proposerAddress: EthAddress | undefined,
|
|
760
909
|
options: BlockProposalOptions = {},
|
|
761
910
|
): Promise<BlockProposal> {
|
|
762
|
-
//
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
911
|
+
// Validate that we're not creating a proposal for an older or equal position
|
|
912
|
+
if (this.lastProposedBlock) {
|
|
913
|
+
const lastSlot = this.lastProposedBlock.slotNumber;
|
|
914
|
+
const lastIndex = this.lastProposedBlock.indexWithinCheckpoint;
|
|
915
|
+
const newSlot = blockHeader.globalVariables.slotNumber;
|
|
916
|
+
|
|
917
|
+
if (newSlot < lastSlot || (newSlot === lastSlot && indexWithinCheckpoint <= lastIndex)) {
|
|
918
|
+
throw new Error(
|
|
919
|
+
`Cannot create block proposal for slot ${newSlot} index ${indexWithinCheckpoint}: ` +
|
|
920
|
+
`already proposed block for slot ${lastSlot} index ${lastIndex}`,
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
767
924
|
|
|
768
925
|
this.log.info(
|
|
769
926
|
`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`,
|
|
770
927
|
);
|
|
771
928
|
const newProposal = await this.validationService.createBlockProposal(
|
|
772
929
|
blockHeader,
|
|
930
|
+
checkpointNumber,
|
|
773
931
|
indexWithinCheckpoint,
|
|
774
932
|
inHash,
|
|
775
933
|
archive,
|
|
@@ -777,28 +935,55 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
777
935
|
proposerAddress,
|
|
778
936
|
{
|
|
779
937
|
...options,
|
|
780
|
-
broadcastInvalidBlockProposal:
|
|
938
|
+
broadcastInvalidBlockProposal:
|
|
939
|
+
options.broadcastInvalidBlockProposal || this.config.broadcastInvalidBlockProposal,
|
|
781
940
|
},
|
|
782
941
|
);
|
|
783
|
-
this.
|
|
942
|
+
this.lastProposedBlock = newProposal;
|
|
784
943
|
return newProposal;
|
|
785
944
|
}
|
|
786
945
|
|
|
787
946
|
async createCheckpointProposal(
|
|
788
947
|
checkpointHeader: CheckpointHeader,
|
|
789
948
|
archive: Fr,
|
|
790
|
-
|
|
949
|
+
checkpointNumber: CheckpointNumber,
|
|
950
|
+
feeAssetPriceModifier: bigint,
|
|
951
|
+
lastBlockProposal: BlockProposal | undefined,
|
|
791
952
|
proposerAddress: EthAddress | undefined,
|
|
792
953
|
options: CheckpointProposalOptions = {},
|
|
793
954
|
): Promise<CheckpointProposal> {
|
|
955
|
+
// Validate that we're not creating a proposal for an older or equal slot
|
|
956
|
+
if (this.lastProposedCheckpoint) {
|
|
957
|
+
const lastSlot = this.lastProposedCheckpoint.slotNumber;
|
|
958
|
+
const newSlot = checkpointHeader.slotNumber;
|
|
959
|
+
|
|
960
|
+
if (newSlot <= lastSlot) {
|
|
961
|
+
throw new Error(
|
|
962
|
+
`Cannot create checkpoint proposal for slot ${newSlot}: ` +
|
|
963
|
+
`already proposed checkpoint for slot ${lastSlot}`,
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
|
|
794
968
|
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
795
|
-
|
|
969
|
+
const newProposal = await this.validationService.createCheckpointProposal(
|
|
796
970
|
checkpointHeader,
|
|
797
971
|
archive,
|
|
798
|
-
|
|
972
|
+
checkpointNumber,
|
|
973
|
+
feeAssetPriceModifier,
|
|
974
|
+
lastBlockProposal,
|
|
799
975
|
proposerAddress,
|
|
800
976
|
options,
|
|
801
977
|
);
|
|
978
|
+
this.lastProposedCheckpoint = newProposal;
|
|
979
|
+
// Self-record this slot's outcome on the re-execution tracker. Proposers don't run their
|
|
980
|
+
// own proposals through `handleCheckpointProposal`, so without this call the proposer's
|
|
981
|
+
// sentinel would see no outcome for slots it proposed and would mis-attribute itself as
|
|
982
|
+
// inactive. We pass the locally-computed `archive` (not `newProposal.archive`, which may
|
|
983
|
+
// be intentionally corrupted under test-only flags); from the proposer's local-view
|
|
984
|
+
// perspective the work it just completed is valid by definition.
|
|
985
|
+
this.proposalHandler.recordOwnCheckpointProposalAsValid(checkpointHeader.slotNumber, archive, checkpointNumber);
|
|
986
|
+
return newProposal;
|
|
802
987
|
}
|
|
803
988
|
|
|
804
989
|
async broadcastBlockProposal(proposal: BlockProposal): Promise<void> {
|
|
@@ -809,16 +994,28 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
809
994
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
810
995
|
proposer: EthAddress,
|
|
811
996
|
slot: SlotNumber,
|
|
812
|
-
|
|
997
|
+
checkpointNumber: CheckpointNumber,
|
|
813
998
|
): Promise<Signature> {
|
|
814
|
-
return await this.validationService.signAttestationsAndSigners(
|
|
999
|
+
return await this.validationService.signAttestationsAndSigners(
|
|
1000
|
+
attestationsAndSigners,
|
|
1001
|
+
proposer,
|
|
1002
|
+
slot,
|
|
1003
|
+
checkpointNumber,
|
|
1004
|
+
);
|
|
815
1005
|
}
|
|
816
1006
|
|
|
817
|
-
async collectOwnAttestations(
|
|
1007
|
+
async collectOwnAttestations(
|
|
1008
|
+
proposal: CheckpointProposal,
|
|
1009
|
+
checkpointNumber: CheckpointNumber,
|
|
1010
|
+
): Promise<CheckpointAttestation[]> {
|
|
818
1011
|
const slot = proposal.slotNumber;
|
|
819
1012
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
820
1013
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, { inCommittee });
|
|
821
|
-
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
1014
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
|
|
1015
|
+
|
|
1016
|
+
if (!attestations) {
|
|
1017
|
+
return [];
|
|
1018
|
+
}
|
|
822
1019
|
|
|
823
1020
|
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
824
1021
|
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
@@ -833,6 +1030,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
833
1030
|
proposal: CheckpointProposal,
|
|
834
1031
|
required: number,
|
|
835
1032
|
deadline: Date,
|
|
1033
|
+
checkpointNumber: CheckpointNumber,
|
|
836
1034
|
): Promise<CheckpointAttestation[]> {
|
|
837
1035
|
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
838
1036
|
const slot = proposal.slotNumber;
|
|
@@ -845,33 +1043,23 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
845
1043
|
throw new AttestationTimeoutError(0, required, slot);
|
|
846
1044
|
}
|
|
847
1045
|
|
|
848
|
-
await this.collectOwnAttestations(proposal);
|
|
1046
|
+
await this.collectOwnAttestations(proposal, checkpointNumber);
|
|
849
1047
|
|
|
850
|
-
const
|
|
1048
|
+
const proposalPayloadHash = proposal.getPayloadHash();
|
|
851
1049
|
const myAddresses = this.getValidatorAddresses();
|
|
852
1050
|
|
|
853
1051
|
let attestations: CheckpointAttestation[] = [];
|
|
854
1052
|
while (true) {
|
|
855
|
-
//
|
|
856
|
-
//
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
if (!attestation.archive.equals(proposal.archive)) {
|
|
860
|
-
this.log.warn(
|
|
861
|
-
`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`,
|
|
862
|
-
{ attestationArchive: attestation.archive.toString(), proposalArchive: proposal.archive.toString() },
|
|
863
|
-
);
|
|
864
|
-
return false;
|
|
865
|
-
}
|
|
866
|
-
return true;
|
|
867
|
-
},
|
|
868
|
-
);
|
|
1053
|
+
// The pool already filters by proposal payload hash; if any attestation slips through with a
|
|
1054
|
+
// mismatched payload hash, drop it defensively. Equivocations are emitted as separate slash
|
|
1055
|
+
// events from libp2p_service.
|
|
1056
|
+
const collectedAttestations = await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalPayloadHash);
|
|
869
1057
|
|
|
870
1058
|
// Log new attestations we collected
|
|
871
1059
|
const oldSenders = attestations.map(attestation => attestation.getSender());
|
|
872
1060
|
for (const collected of collectedAttestations) {
|
|
873
1061
|
const collectedSender = collected.getSender();
|
|
874
|
-
// Skip attestations with invalid signatures
|
|
1062
|
+
// Skip attestations with invalid signatures. Should not happen as we don't add invalid attestations to our pool.
|
|
875
1063
|
if (!collectedSender) {
|
|
876
1064
|
this.log.warn(`Skipping attestation with invalid signature for slot ${slot}`);
|
|
877
1065
|
continue;
|