@aztec/validator-client 0.0.1-commit.3fd054f6 → 0.0.1-commit.431c48d
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 +12 -11
- package/dest/checkpoint_builder.d.ts +12 -4
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +14 -3
- package/dest/config.d.ts +9 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +23 -10
- 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 +32 -38
- package/dest/factory.d.ts +9 -5
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +8 -8
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/key_store/web3signer_key_store.d.ts +10 -2
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
- package/dest/key_store/web3signer_key_store.js +32 -41
- package/dest/metrics.d.ts +6 -2
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +15 -1
- package/dest/proposal_handler.d.ts +173 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/proposal_handler.js +1302 -0
- package/dest/validator.d.ts +37 -23
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +218 -252
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +16 -5
- package/src/config.ts +31 -12
- package/src/duties/validation_service.ts +51 -47
- package/src/factory.ts +17 -8
- package/src/index.ts +1 -1
- package/src/key_store/web3signer_key_store.ts +43 -59
- package/src/metrics.ts +21 -1
- package/src/proposal_handler.ts +1418 -0
- package/src/validator.ts +293 -289
- package/dest/block_proposal_handler.d.ts +0 -64
- package/dest/block_proposal_handler.d.ts.map +0 -1
- package/dest/block_proposal_handler.js +0 -614
- package/src/block_proposal_handler.ts +0 -632
package/dest/validator.js
CHANGED
|
@@ -1,42 +1,36 @@
|
|
|
1
1
|
import { getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { TimeoutError } from '@aztec/foundation/error';
|
|
2
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { FifoSet } from '@aztec/foundation/fifo-set';
|
|
5
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
7
5
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
8
6
|
import { sleep } from '@aztec/foundation/sleep';
|
|
9
7
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
10
|
-
import { AuthRequest, AuthResponse,
|
|
11
|
-
import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
|
|
8
|
+
import { AuthRequest, AuthResponse, ReqRespSubProtocol } from '@aztec/p2p';
|
|
9
|
+
import { OffenseType, WANT_TO_CLEAR_SLASH_EVENT, WANT_TO_SLASH_EVENT, getOffenseTypeName } from '@aztec/slasher';
|
|
10
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
11
|
+
import { ConsensusTimetable } from '@aztec/stdlib/timetable';
|
|
15
12
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
16
13
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
17
14
|
import { createHASigner, createLocalSignerWithProtection, createSignerFromSharedDb } from '@aztec/validator-ha-signer/factory';
|
|
18
15
|
import { DutyType } from '@aztec/validator-ha-signer/types';
|
|
19
16
|
import { EventEmitter } from 'events';
|
|
20
|
-
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
21
17
|
import { ValidationService } from './duties/validation_service.js';
|
|
22
18
|
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
23
19
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
24
20
|
import { ValidatorMetrics } from './metrics.js';
|
|
21
|
+
import { ProposalHandler, SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT, SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT } from './proposal_handler.js';
|
|
25
22
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
26
23
|
// Just cap the set to avoid unbounded growth.
|
|
27
24
|
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
'state_mismatch',
|
|
31
|
-
'failed_txs'
|
|
32
|
-
];
|
|
25
|
+
const MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS = 1000;
|
|
26
|
+
const MAX_TRACKED_BAD_ATTESTATIONS = 10_000;
|
|
33
27
|
/**
|
|
34
28
|
* Validator Client
|
|
35
29
|
*/ export class ValidatorClient extends EventEmitter {
|
|
36
30
|
keyStore;
|
|
37
31
|
epochCache;
|
|
38
32
|
p2pClient;
|
|
39
|
-
|
|
33
|
+
proposalHandler;
|
|
40
34
|
blockSource;
|
|
41
35
|
checkpointsBuilder;
|
|
42
36
|
worldState;
|
|
@@ -57,14 +51,18 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
57
51
|
epochCacheUpdateLoop;
|
|
58
52
|
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */ lastAttestedEpochByAttester;
|
|
59
53
|
proposersOfInvalidBlocks;
|
|
54
|
+
invalidCheckpointProposalOffenseKeys;
|
|
55
|
+
oversizedProposalOffenseKeys;
|
|
56
|
+
badAttestationOffenseKeys;
|
|
60
57
|
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */ lastAttestedProposal;
|
|
61
|
-
constructor(keyStore, epochCache, p2pClient,
|
|
62
|
-
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.
|
|
58
|
+
constructor(keyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
59
|
+
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.proposalHandler = proposalHandler, this.blockSource = blockSource, this.checkpointsBuilder = checkpointsBuilder, this.worldState = worldState, this.l1ToL2MessageSource = l1ToL2MessageSource, this.config = config, this.blobClient = blobClient, this.slashingProtectionSigner = slashingProtectionSigner, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.lastAttestedEpochByAttester = new Map(), this.proposersOfInvalidBlocks = FifoSet.withLimit(MAX_PROPOSERS_OF_INVALID_BLOCKS), this.invalidCheckpointProposalOffenseKeys = FifoSet.withLimit(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS), this.oversizedProposalOffenseKeys = FifoSet.withLimit(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS), this.badAttestationOffenseKeys = FifoSet.withLimit(MAX_TRACKED_BAD_ATTESTATIONS);
|
|
63
60
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
64
61
|
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
65
62
|
this.tracer = telemetry.getTracer('Validator');
|
|
66
63
|
this.metrics = new ValidatorMetrics(telemetry);
|
|
67
|
-
this.validationService = new ValidationService(keyStore, this.log.createChild('validation-service'));
|
|
64
|
+
this.validationService = new ValidationService(keyStore, this.getSignatureContext(), this.log.createChild('validation-service'));
|
|
65
|
+
this.proposalHandler.setCheckpointProposalValidationFailureCallback((proposal, result, proposalInfo)=>this.handleInvalidCheckpointProposal(proposal, result, proposalInfo));
|
|
68
66
|
// Refresh epoch cache every second to trigger alert if participation in committee changes
|
|
69
67
|
this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), this.log, 1000);
|
|
70
68
|
const myAddresses = this.getValidatorAddresses();
|
|
@@ -114,13 +112,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
114
112
|
this.log.error(`Error updating epoch committee`, err);
|
|
115
113
|
}
|
|
116
114
|
}
|
|
117
|
-
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), slashingProtectionDb) {
|
|
115
|
+
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, reexecutionTracker, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), slashingProtectionDb) {
|
|
118
116
|
const metrics = new ValidatorMetrics(telemetry);
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
const consensusTimetable = new ConsensusTimetable({
|
|
118
|
+
l1Constants: epochCache.getL1Constants(),
|
|
119
|
+
blockDuration: config.blockDurationMs / 1000
|
|
122
120
|
});
|
|
123
|
-
const
|
|
121
|
+
const proposalHandler = new ProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, epochCache, consensusTimetable, config, blobClient, reexecutionTracker, metrics, dateProvider, telemetry, undefined);
|
|
124
122
|
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
125
123
|
let slashingProtectionSigner;
|
|
126
124
|
if (slashingProtectionDb) {
|
|
@@ -149,18 +147,24 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
149
147
|
}));
|
|
150
148
|
}
|
|
151
149
|
const validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, slashingProtectionSigner);
|
|
152
|
-
const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient,
|
|
150
|
+
const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider, telemetry);
|
|
153
151
|
return validator;
|
|
154
152
|
}
|
|
155
153
|
getValidatorAddresses() {
|
|
156
154
|
return this.keyStore.getAddresses().filter((addr)=>!this.config.disabledValidators.some((disabled)=>disabled.equals(addr)));
|
|
157
155
|
}
|
|
158
|
-
|
|
159
|
-
return this.
|
|
156
|
+
getProposalHandler() {
|
|
157
|
+
return this.proposalHandler;
|
|
160
158
|
}
|
|
161
159
|
signWithAddress(addr, msg, context) {
|
|
162
160
|
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
163
161
|
}
|
|
162
|
+
getSignatureContext() {
|
|
163
|
+
return {
|
|
164
|
+
chainId: this.config.l1ChainId,
|
|
165
|
+
rollupAddress: this.config.rollupAddress
|
|
166
|
+
};
|
|
167
|
+
}
|
|
164
168
|
getCoinbaseForAttestor(attestor) {
|
|
165
169
|
return this.keyStore.getCoinbaseAddress(attestor);
|
|
166
170
|
}
|
|
@@ -170,16 +174,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
170
174
|
getConfig() {
|
|
171
175
|
return this.config;
|
|
172
176
|
}
|
|
177
|
+
hasProposalEquivocation(slotNumber) {
|
|
178
|
+
return this.proposalHandler.hasProposalEquivocation(slotNumber);
|
|
179
|
+
}
|
|
180
|
+
hasInvalidProposals(slotNumber) {
|
|
181
|
+
return this.proposalHandler.hasInvalidProposals(slotNumber);
|
|
182
|
+
}
|
|
173
183
|
updateConfig(config) {
|
|
174
184
|
this.config = {
|
|
175
185
|
...this.config,
|
|
176
186
|
...config
|
|
177
187
|
};
|
|
188
|
+
this.proposalHandler.updateConfig(config);
|
|
178
189
|
}
|
|
179
190
|
reloadKeystore(newManager) {
|
|
180
191
|
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
181
192
|
this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
|
|
182
|
-
this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
|
|
193
|
+
this.validationService = new ValidationService(this.keyStore, this.getSignatureContext(), this.log.createChild('validation-service'));
|
|
183
194
|
}
|
|
184
195
|
async start() {
|
|
185
196
|
if (this.epochCacheUpdateLoop.isRunning()) {
|
|
@@ -212,15 +223,22 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
212
223
|
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
213
224
|
// and processed separately via the block handler above.
|
|
214
225
|
const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
215
|
-
this.p2pClient.
|
|
226
|
+
this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
|
|
216
227
|
// Duplicate proposal handler - triggers slashing for equivocation
|
|
217
228
|
this.p2pClient.registerDuplicateProposalCallback((info)=>{
|
|
218
229
|
this.handleDuplicateProposal(info);
|
|
219
230
|
});
|
|
231
|
+
// Oversized proposal handler - triggers slashing for proposals beyond the per-checkpoint block limit
|
|
232
|
+
this.p2pClient.registerOversizedProposalCallback((info)=>{
|
|
233
|
+
this.handleOversizedProposal(info);
|
|
234
|
+
});
|
|
220
235
|
// Duplicate attestation handler - triggers slashing for attestation equivocation
|
|
221
236
|
this.p2pClient.registerDuplicateAttestationCallback((info)=>{
|
|
222
237
|
this.handleDuplicateAttestation(info);
|
|
223
238
|
});
|
|
239
|
+
this.p2pClient.registerCheckpointAttestationCallback((attestation)=>{
|
|
240
|
+
this.handleCheckpointAttestation(attestation);
|
|
241
|
+
});
|
|
224
242
|
const myAddresses = this.getValidatorAddresses();
|
|
225
243
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
226
244
|
await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
|
|
@@ -260,11 +278,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
260
278
|
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
261
279
|
fishermanMode: this.config.fishermanMode || false
|
|
262
280
|
});
|
|
263
|
-
// Reexecute
|
|
264
|
-
|
|
265
|
-
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
266
|
-
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
|
|
267
|
-
const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
|
|
281
|
+
// Reexecute outside the escape hatch so slashing observers can detect invalid proposals even when penalties are 0.
|
|
282
|
+
const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !escapeHatchOpen);
|
|
268
283
|
if (!validationResult.isValid) {
|
|
269
284
|
const reason = validationResult.reason || 'unknown';
|
|
270
285
|
this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
|
|
@@ -274,7 +289,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
274
289
|
'state_mismatch',
|
|
275
290
|
'failed_txs',
|
|
276
291
|
'in_hash_mismatch',
|
|
277
|
-
'parent_block_wrong_slot'
|
|
292
|
+
'parent_block_wrong_slot',
|
|
293
|
+
'duplicate_txs',
|
|
294
|
+
'invalid_embedded_txs'
|
|
278
295
|
];
|
|
279
296
|
if (badProposalReasons.includes(reason)) {
|
|
280
297
|
this.metrics.incFailedAttestationsBadProposal(1, reason, partOfCommittee);
|
|
@@ -282,10 +299,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
282
299
|
// Node issues so we can't validate
|
|
283
300
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
284
301
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
302
|
+
if (!escapeHatchOpen && validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)) {
|
|
303
|
+
this.log.info(`Detected invalid block proposal offense`, {
|
|
304
|
+
...proposalInfo,
|
|
305
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
306
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL)
|
|
307
|
+
});
|
|
288
308
|
this.slashInvalidBlock(proposal);
|
|
309
|
+
this.markInvalidProposalSlot(proposal.slotNumber);
|
|
289
310
|
}
|
|
290
311
|
return false;
|
|
291
312
|
}
|
|
@@ -314,49 +335,43 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
314
335
|
this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
|
|
315
336
|
return undefined;
|
|
316
337
|
}
|
|
317
|
-
//
|
|
318
|
-
if (!
|
|
319
|
-
this.log.warn(`Received checkpoint proposal with invalid signature for proposal slot ${proposalSlotNumber}`);
|
|
338
|
+
// Early-out for equivocation: refuses if we've already attested to a higher slot.
|
|
339
|
+
if (!this.shouldAttestToSlot(proposalSlotNumber)) {
|
|
320
340
|
return undefined;
|
|
321
341
|
}
|
|
322
342
|
// Ignore proposals from ourselves (may happen in HA setups)
|
|
323
|
-
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
324
|
-
this.log.debug(`
|
|
343
|
+
if (proposer && this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
344
|
+
this.log.debug(`Not attesting to block proposal from self for slot ${proposalSlotNumber}`, {
|
|
325
345
|
proposer: proposer.toString(),
|
|
326
346
|
proposalSlotNumber
|
|
327
347
|
});
|
|
328
348
|
return undefined;
|
|
329
349
|
}
|
|
330
|
-
// Validate fee asset price modifier is within allowed range
|
|
331
|
-
if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
|
|
332
|
-
this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${proposalSlotNumber}`);
|
|
333
|
-
return undefined;
|
|
334
|
-
}
|
|
335
350
|
// Check that I have any address in the committee where this checkpoint will land before attesting
|
|
336
351
|
const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
|
|
337
352
|
const partOfCommittee = inCommittee.length > 0;
|
|
338
353
|
const proposalInfo = {
|
|
339
354
|
proposalSlotNumber,
|
|
340
355
|
archive: proposal.archive.toString(),
|
|
341
|
-
proposer: proposer
|
|
356
|
+
proposer: proposer?.toString()
|
|
342
357
|
};
|
|
343
358
|
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
344
359
|
...proposalInfo,
|
|
345
360
|
fishermanMode: this.config.fishermanMode || false
|
|
346
361
|
});
|
|
347
|
-
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
362
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
|
|
363
|
+
// Uses the cached result from the all-nodes callback if available (avoids double validation).
|
|
364
|
+
let checkpointNumber;
|
|
348
365
|
if (this.config.skipCheckpointProposalValidation) {
|
|
349
366
|
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
367
|
+
checkpointNumber = CheckpointNumber(0);
|
|
350
368
|
} else {
|
|
351
|
-
const validationResult = await this.
|
|
369
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
352
370
|
if (!validationResult.isValid) {
|
|
353
371
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
354
372
|
return undefined;
|
|
355
373
|
}
|
|
356
|
-
|
|
357
|
-
// Upload blobs to filestore if we can (fire and forget)
|
|
358
|
-
if (this.blobClient.canUpload()) {
|
|
359
|
-
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
374
|
+
checkpointNumber = validationResult.checkpointNumber;
|
|
360
375
|
}
|
|
361
376
|
// Check that I have any address in current committee before attesting
|
|
362
377
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
@@ -403,7 +418,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
403
418
|
});
|
|
404
419
|
return undefined;
|
|
405
420
|
}
|
|
406
|
-
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
421
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
|
|
407
422
|
}
|
|
408
423
|
/**
|
|
409
424
|
* Checks if we should attest to a slot based on equivocation prevention rules.
|
|
@@ -420,180 +435,24 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
420
435
|
}
|
|
421
436
|
return true;
|
|
422
437
|
}
|
|
423
|
-
async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
|
|
438
|
+
async createCheckpointAttestationsFromProposal(proposal, attestors = [], checkpointNumber) {
|
|
424
439
|
// Equivocation check: must happen right before signing to minimize the race window
|
|
425
440
|
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
426
441
|
return undefined;
|
|
427
442
|
}
|
|
428
|
-
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
443
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
|
|
429
444
|
// Track the proposal we attested to (to prevent equivocation)
|
|
430
445
|
this.lastAttestedProposal = proposal;
|
|
431
446
|
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
432
447
|
return attestations;
|
|
433
448
|
}
|
|
434
449
|
/**
|
|
435
|
-
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
436
|
-
* @returns Validation result with isValid flag and reason if invalid.
|
|
437
|
-
*/ async validateCheckpointProposal(proposal, proposalInfo) {
|
|
438
|
-
const slot = proposal.slotNumber;
|
|
439
|
-
// Timeout block syncing at the start of the next slot
|
|
440
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
441
|
-
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
|
|
442
|
-
const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
|
|
443
|
-
// Wait for last block to sync by archive
|
|
444
|
-
let lastBlockHeader;
|
|
445
|
-
try {
|
|
446
|
-
lastBlockHeader = await retryUntil(async ()=>{
|
|
447
|
-
await this.blockSource.syncImmediate();
|
|
448
|
-
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
449
|
-
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, timeoutSeconds, 0.5);
|
|
450
|
-
} catch (err) {
|
|
451
|
-
if (err instanceof TimeoutError) {
|
|
452
|
-
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
453
|
-
return {
|
|
454
|
-
isValid: false,
|
|
455
|
-
reason: 'last_block_not_found'
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
459
|
-
return {
|
|
460
|
-
isValid: false,
|
|
461
|
-
reason: 'block_fetch_error'
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
if (!lastBlockHeader) {
|
|
465
|
-
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
466
|
-
return {
|
|
467
|
-
isValid: false,
|
|
468
|
-
reason: 'last_block_not_found'
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
// Get all full blocks for the slot and checkpoint
|
|
472
|
-
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
473
|
-
if (blocks.length === 0) {
|
|
474
|
-
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
475
|
-
return {
|
|
476
|
-
isValid: false,
|
|
477
|
-
reason: 'no_blocks_for_slot'
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
481
|
-
if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
|
|
482
|
-
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
483
|
-
return {
|
|
484
|
-
isValid: false,
|
|
485
|
-
reason: 'last_block_archive_mismatch'
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
489
|
-
...proposalInfo,
|
|
490
|
-
blockNumbers: blocks.map((b)=>b.number)
|
|
491
|
-
});
|
|
492
|
-
// Get checkpoint constants from first block
|
|
493
|
-
const firstBlock = blocks[0];
|
|
494
|
-
const constants = this.extractCheckpointConstants(firstBlock);
|
|
495
|
-
const checkpointNumber = firstBlock.checkpointNumber;
|
|
496
|
-
// Get L1-to-L2 messages for this checkpoint
|
|
497
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
498
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
499
|
-
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
500
|
-
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch)).filter((c)=>c.checkpointNumber < checkpointNumber).map((c)=>c.checkpointOutHash);
|
|
501
|
-
// Fork world state at the block before the first block
|
|
502
|
-
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
503
|
-
const fork = await this.worldState.fork(parentBlockNumber);
|
|
504
|
-
try {
|
|
505
|
-
// Create checkpoint builder with all existing blocks
|
|
506
|
-
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
|
|
507
|
-
// Complete the checkpoint to get computed values
|
|
508
|
-
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
509
|
-
// Compare checkpoint header with proposal
|
|
510
|
-
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
511
|
-
this.log.warn(`Checkpoint header mismatch`, {
|
|
512
|
-
...proposalInfo,
|
|
513
|
-
computed: computedCheckpoint.header.toInspect(),
|
|
514
|
-
proposal: proposal.checkpointHeader.toInspect()
|
|
515
|
-
});
|
|
516
|
-
return {
|
|
517
|
-
isValid: false,
|
|
518
|
-
reason: 'checkpoint_header_mismatch'
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
// Compare archive root with proposal
|
|
522
|
-
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
523
|
-
this.log.warn(`Archive root mismatch`, {
|
|
524
|
-
...proposalInfo,
|
|
525
|
-
computed: computedCheckpoint.archive.root.toString(),
|
|
526
|
-
proposal: proposal.archive.toString()
|
|
527
|
-
});
|
|
528
|
-
return {
|
|
529
|
-
isValid: false,
|
|
530
|
-
reason: 'archive_mismatch'
|
|
531
|
-
};
|
|
532
|
-
}
|
|
533
|
-
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
534
|
-
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
535
|
-
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
536
|
-
const computedEpochOutHash = accumulateCheckpointOutHashes([
|
|
537
|
-
...previousCheckpointOutHashes,
|
|
538
|
-
checkpointOutHash
|
|
539
|
-
]);
|
|
540
|
-
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
541
|
-
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
542
|
-
this.log.warn(`Epoch out hash mismatch`, {
|
|
543
|
-
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
544
|
-
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
545
|
-
checkpointOutHash: checkpointOutHash.toString(),
|
|
546
|
-
previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
|
|
547
|
-
...proposalInfo
|
|
548
|
-
});
|
|
549
|
-
return {
|
|
550
|
-
isValid: false,
|
|
551
|
-
reason: 'out_hash_mismatch'
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
// Final round of validations on the checkpoint, just in case.
|
|
555
|
-
try {
|
|
556
|
-
validateCheckpoint(computedCheckpoint, {
|
|
557
|
-
rollupManaLimit: this.checkpointsBuilder.getConfig().rollupManaLimit,
|
|
558
|
-
maxDABlockGas: this.config.validateMaxDABlockGas,
|
|
559
|
-
maxL2BlockGas: this.config.validateMaxL2BlockGas,
|
|
560
|
-
maxTxsPerBlock: this.config.validateMaxTxsPerBlock,
|
|
561
|
-
maxTxsPerCheckpoint: this.config.validateMaxTxsPerCheckpoint
|
|
562
|
-
});
|
|
563
|
-
} catch (err) {
|
|
564
|
-
this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
|
|
565
|
-
return {
|
|
566
|
-
isValid: false,
|
|
567
|
-
reason: 'checkpoint_validation_failed'
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
571
|
-
return {
|
|
572
|
-
isValid: true
|
|
573
|
-
};
|
|
574
|
-
} finally{
|
|
575
|
-
await fork.close();
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
/**
|
|
579
|
-
* Extract checkpoint global variables from a block.
|
|
580
|
-
*/ extractCheckpointConstants(block) {
|
|
581
|
-
const gv = block.header.globalVariables;
|
|
582
|
-
return {
|
|
583
|
-
chainId: gv.chainId,
|
|
584
|
-
version: gv.version,
|
|
585
|
-
slotNumber: gv.slotNumber,
|
|
586
|
-
timestamp: gv.timestamp,
|
|
587
|
-
coinbase: gv.coinbase,
|
|
588
|
-
feeRecipient: gv.feeRecipient,
|
|
589
|
-
gasFees: gv.gasFees
|
|
590
|
-
};
|
|
591
|
-
}
|
|
592
|
-
/**
|
|
593
450
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
594
451
|
*/ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
|
|
595
452
|
try {
|
|
596
|
-
const lastBlockHeader = await this.blockSource.
|
|
453
|
+
const lastBlockHeader = (await this.blockSource.getBlockData({
|
|
454
|
+
archive: proposal.archive
|
|
455
|
+
}))?.header;
|
|
597
456
|
if (!lastBlockHeader) {
|
|
598
457
|
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
599
458
|
return;
|
|
@@ -621,11 +480,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
621
480
|
this.log.warn(`Cannot slash proposal with invalid signature`);
|
|
622
481
|
return;
|
|
623
482
|
}
|
|
624
|
-
// Trim the set if it's too big.
|
|
625
|
-
if (this.proposersOfInvalidBlocks.size > MAX_PROPOSERS_OF_INVALID_BLOCKS) {
|
|
626
|
-
// remove oldest proposer. `values` is guaranteed to be in insertion order.
|
|
627
|
-
this.proposersOfInvalidBlocks.delete(this.proposersOfInvalidBlocks.values().next().value);
|
|
628
|
-
}
|
|
629
483
|
this.proposersOfInvalidBlocks.add(proposer.toString());
|
|
630
484
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
631
485
|
{
|
|
@@ -636,17 +490,122 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
636
490
|
}
|
|
637
491
|
]);
|
|
638
492
|
}
|
|
493
|
+
handleInvalidCheckpointProposal(proposal, result, proposalInfo) {
|
|
494
|
+
if (!SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT[result.reason]) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
// The slot is already marked invalid by the all-nodes checkpoint handler that invokes this callback,
|
|
498
|
+
// so we only emit the proposer slash event here.
|
|
499
|
+
if (this.slashInvalidCheckpointProposal(proposal)) {
|
|
500
|
+
this.log.info(`Detected invalid checkpoint proposal offense`, {
|
|
501
|
+
...proposalInfo,
|
|
502
|
+
reason: result.reason,
|
|
503
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
504
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL)
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
slashInvalidCheckpointProposal(proposal) {
|
|
509
|
+
const proposer = proposal.getSender();
|
|
510
|
+
if (!proposer) {
|
|
511
|
+
this.log.warn(`Cannot slash checkpoint proposal with invalid signature`, {
|
|
512
|
+
slotNumber: proposal.slotNumber,
|
|
513
|
+
archive: proposal.archive.toString()
|
|
514
|
+
});
|
|
515
|
+
return false;
|
|
516
|
+
}
|
|
517
|
+
const offenseType = OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL;
|
|
518
|
+
const offenseKey = `${proposer.toString()}:${offenseType}:${proposal.slotNumber}`;
|
|
519
|
+
if (!this.invalidCheckpointProposalOffenseKeys.addIfAbsent(offenseKey)) {
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
522
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
523
|
+
{
|
|
524
|
+
validator: proposer,
|
|
525
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
526
|
+
offenseType,
|
|
527
|
+
epochOrSlot: BigInt(proposal.slotNumber)
|
|
528
|
+
}
|
|
529
|
+
]);
|
|
530
|
+
return true;
|
|
531
|
+
}
|
|
532
|
+
markInvalidProposalSlot(slotNumber) {
|
|
533
|
+
this.proposalHandler.markInvalidProposalSlot(slotNumber);
|
|
534
|
+
}
|
|
535
|
+
handleCheckpointAttestation(attestation) {
|
|
536
|
+
const slotNumber = attestation.slotNumber;
|
|
537
|
+
if (!this.proposalHandler.hasInvalidProposals(slotNumber) || this.proposalHandler.hasProposalEquivocation(slotNumber)) {
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
const attester = attestation.getSender();
|
|
541
|
+
if (!attester) {
|
|
542
|
+
this.log.warn(`Cannot slash checkpoint attestation with invalid signature`, {
|
|
543
|
+
slotNumber,
|
|
544
|
+
archive: attestation.archive.toString()
|
|
545
|
+
});
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
this.slashAttestedToInvalidCheckpointProposal(slotNumber, attester);
|
|
549
|
+
}
|
|
550
|
+
slashAttestedToInvalidCheckpointProposal(slotNumber, attester) {
|
|
551
|
+
const offenseKey = `${attester.toString()}:${OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL}:${slotNumber}`;
|
|
552
|
+
if (!this.badAttestationOffenseKeys.addIfAbsent(offenseKey)) {
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
this.log.info(`Detected attestation to invalid checkpoint proposal offense`, {
|
|
556
|
+
attester: attester.toString(),
|
|
557
|
+
slotNumber,
|
|
558
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
559
|
+
offenseType: getOffenseTypeName(OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL)
|
|
560
|
+
});
|
|
561
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
562
|
+
{
|
|
563
|
+
validator: attester,
|
|
564
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
565
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
566
|
+
epochOrSlot: BigInt(slotNumber)
|
|
567
|
+
}
|
|
568
|
+
]);
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Handle detection of an oversized block proposal: one whose index within its checkpoint lands at or
|
|
572
|
+
* beyond the consensus per-checkpoint block limit. A single signed proposal at an illegal index is
|
|
573
|
+
* self-contained evidence, so emit an invalid-block-proposal slash event for the proposer, deduped per
|
|
574
|
+
* (proposer, slot) since the p2p layer reports every oversized proposal it stores.
|
|
575
|
+
*/ handleOversizedProposal(info) {
|
|
576
|
+
const { slot, proposer } = info;
|
|
577
|
+
const offenseType = OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL;
|
|
578
|
+
if (!this.oversizedProposalOffenseKeys.addIfAbsent(`${proposer.toString()}:${offenseType}:${slot}`)) {
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
this.log.info(`Detected oversized block proposal offense from ${proposer.toString()} at slot ${slot}`, {
|
|
582
|
+
proposer: proposer.toString(),
|
|
583
|
+
slot,
|
|
584
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
585
|
+
offenseType: getOffenseTypeName(offenseType)
|
|
586
|
+
});
|
|
587
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
588
|
+
{
|
|
589
|
+
validator: proposer,
|
|
590
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
591
|
+
offenseType,
|
|
592
|
+
epochOrSlot: BigInt(slot)
|
|
593
|
+
}
|
|
594
|
+
]);
|
|
595
|
+
}
|
|
639
596
|
/**
|
|
640
597
|
* Handle detection of a duplicate proposal (equivocation).
|
|
641
598
|
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
642
599
|
*/ handleDuplicateProposal(info) {
|
|
643
600
|
const { slot, proposer, type } = info;
|
|
644
|
-
this.
|
|
601
|
+
this.proposalHandler.markProposalEquivocation(slot);
|
|
602
|
+
this.log.info(`Detected duplicate ${type} proposal offense from ${proposer.toString()} at slot ${slot}`, {
|
|
645
603
|
proposer: proposer.toString(),
|
|
646
604
|
slot,
|
|
647
|
-
type
|
|
605
|
+
type,
|
|
606
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
607
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_PROPOSAL)
|
|
648
608
|
});
|
|
649
|
-
// Emit slash event
|
|
650
609
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
651
610
|
{
|
|
652
611
|
validator: proposer,
|
|
@@ -655,15 +614,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
655
614
|
epochOrSlot: BigInt(slot)
|
|
656
615
|
}
|
|
657
616
|
]);
|
|
617
|
+
this.emit(WANT_TO_CLEAR_SLASH_EVENT, [
|
|
618
|
+
{
|
|
619
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
620
|
+
epochOrSlot: BigInt(slot)
|
|
621
|
+
}
|
|
622
|
+
]);
|
|
658
623
|
}
|
|
659
624
|
/**
|
|
660
625
|
* Handle detection of a duplicate attestation (equivocation).
|
|
661
626
|
* Emits a slash event when an attester signs attestations for different proposals at the same slot.
|
|
662
627
|
*/ handleDuplicateAttestation(info) {
|
|
663
628
|
const { slot, attester } = info;
|
|
664
|
-
this.log.
|
|
629
|
+
this.log.info(`Detected duplicate attestation offense from ${attester.toString()} at slot ${slot}`, {
|
|
665
630
|
attester: attester.toString(),
|
|
666
|
-
slot
|
|
631
|
+
slot,
|
|
632
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
633
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_ATTESTATION)
|
|
667
634
|
});
|
|
668
635
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
669
636
|
{
|
|
@@ -674,7 +641,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
674
641
|
}
|
|
675
642
|
]);
|
|
676
643
|
}
|
|
677
|
-
async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
|
|
644
|
+
async createBlockProposal(blockHeader, checkpointNumber, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
|
|
678
645
|
// Validate that we're not creating a proposal for an older or equal position
|
|
679
646
|
if (this.lastProposedBlock) {
|
|
680
647
|
const lastSlot = this.lastProposedBlock.slotNumber;
|
|
@@ -685,14 +652,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
685
652
|
}
|
|
686
653
|
}
|
|
687
654
|
this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
|
|
688
|
-
const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
655
|
+
const newProposal = await this.validationService.createBlockProposal(blockHeader, checkpointNumber, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
689
656
|
...options,
|
|
690
|
-
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
657
|
+
broadcastInvalidBlockProposal: options.broadcastInvalidBlockProposal || this.config.broadcastInvalidBlockProposal
|
|
691
658
|
});
|
|
692
659
|
this.lastProposedBlock = newProposal;
|
|
693
660
|
return newProposal;
|
|
694
661
|
}
|
|
695
|
-
async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier,
|
|
662
|
+
async createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options = {}) {
|
|
696
663
|
// Validate that we're not creating a proposal for an older or equal slot
|
|
697
664
|
if (this.lastProposedCheckpoint) {
|
|
698
665
|
const lastSlot = this.lastProposedCheckpoint.slotNumber;
|
|
@@ -702,23 +669,30 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
702
669
|
}
|
|
703
670
|
}
|
|
704
671
|
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
705
|
-
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier,
|
|
672
|
+
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options);
|
|
706
673
|
this.lastProposedCheckpoint = newProposal;
|
|
674
|
+
// Self-record this slot's outcome on the re-execution tracker. Proposers don't run their
|
|
675
|
+
// own proposals through `handleCheckpointProposal`, so without this call the proposer's
|
|
676
|
+
// sentinel would see no outcome for slots it proposed and would mis-attribute itself as
|
|
677
|
+
// inactive. We pass the locally-computed `archive` (not `newProposal.archive`, which may
|
|
678
|
+
// be intentionally corrupted under test-only flags); from the proposer's local-view
|
|
679
|
+
// perspective the work it just completed is valid by definition.
|
|
680
|
+
this.proposalHandler.recordOwnCheckpointProposalAsValid(checkpointHeader.slotNumber, archive, checkpointNumber);
|
|
707
681
|
return newProposal;
|
|
708
682
|
}
|
|
709
683
|
async broadcastBlockProposal(proposal) {
|
|
710
684
|
await this.p2pClient.broadcastProposal(proposal);
|
|
711
685
|
}
|
|
712
|
-
async signAttestationsAndSigners(attestationsAndSigners, proposer, slot,
|
|
713
|
-
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot,
|
|
686
|
+
async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, checkpointNumber) {
|
|
687
|
+
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, checkpointNumber);
|
|
714
688
|
}
|
|
715
|
-
async collectOwnAttestations(proposal) {
|
|
689
|
+
async collectOwnAttestations(proposal, checkpointNumber) {
|
|
716
690
|
const slot = proposal.slotNumber;
|
|
717
691
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
718
692
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
|
|
719
693
|
inCommittee
|
|
720
694
|
});
|
|
721
|
-
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
695
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
|
|
722
696
|
if (!attestations) {
|
|
723
697
|
return [];
|
|
724
698
|
}
|
|
@@ -730,7 +704,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
730
704
|
});
|
|
731
705
|
return attestations;
|
|
732
706
|
}
|
|
733
|
-
async collectAttestations(proposal, required, deadline) {
|
|
707
|
+
async collectAttestations(proposal, required, deadline, checkpointNumber) {
|
|
734
708
|
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
735
709
|
const slot = proposal.slotNumber;
|
|
736
710
|
this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
|
|
@@ -738,28 +712,20 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
738
712
|
this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
|
|
739
713
|
throw new AttestationTimeoutError(0, required, slot);
|
|
740
714
|
}
|
|
741
|
-
await this.collectOwnAttestations(proposal);
|
|
742
|
-
const
|
|
715
|
+
await this.collectOwnAttestations(proposal, checkpointNumber);
|
|
716
|
+
const proposalPayloadHash = proposal.getPayloadHash();
|
|
743
717
|
const myAddresses = this.getValidatorAddresses();
|
|
744
718
|
let attestations = [];
|
|
745
719
|
while(true){
|
|
746
|
-
//
|
|
747
|
-
//
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
this.log.warn(`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`, {
|
|
751
|
-
attestationArchive: attestation.archive.toString(),
|
|
752
|
-
proposalArchive: proposal.archive.toString()
|
|
753
|
-
});
|
|
754
|
-
return false;
|
|
755
|
-
}
|
|
756
|
-
return true;
|
|
757
|
-
});
|
|
720
|
+
// The pool already filters by proposal payload hash; if any attestation slips through with a
|
|
721
|
+
// mismatched payload hash, drop it defensively. Equivocations are emitted as separate slash
|
|
722
|
+
// events from libp2p_service.
|
|
723
|
+
const collectedAttestations = await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalPayloadHash);
|
|
758
724
|
// Log new attestations we collected
|
|
759
725
|
const oldSenders = attestations.map((attestation)=>attestation.getSender());
|
|
760
726
|
for (const collected of collectedAttestations){
|
|
761
727
|
const collectedSender = collected.getSender();
|
|
762
|
-
// Skip attestations with invalid signatures
|
|
728
|
+
// Skip attestations with invalid signatures. Should not happen as we don't add invalid attestations to our pool.
|
|
763
729
|
if (!collectedSender) {
|
|
764
730
|
this.log.warn(`Skipping attestation with invalid signature for slot ${slot}`);
|
|
765
731
|
continue;
|