@aztec/validator-client 0.0.1-commit.7b97ef96e → 0.0.1-commit.7cbc774
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 +51 -11
- package/dest/checkpoint_builder.d.ts +19 -6
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +115 -39
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +33 -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 +135 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/proposal_handler.js +1111 -0
- package/dest/validator.d.ts +31 -21
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +263 -263
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +135 -39
- package/src/config.ts +33 -6
- package/src/duties/validation_service.ts +52 -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 +1207 -0
- package/src/validator.ts +338 -305
- 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 -532
- 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 -535
- 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/dest/validator.js
CHANGED
|
@@ -1,48 +1,70 @@
|
|
|
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
8
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
11
|
-
import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
|
|
12
|
-
import { getEpochAtSlot
|
|
13
|
-
import { accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
|
|
9
|
+
import { OffenseType, WANT_TO_CLEAR_SLASH_EVENT, WANT_TO_SLASH_EVENT, getOffenseTypeName } from '@aztec/slasher';
|
|
10
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
14
11
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
15
12
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
16
|
-
import { createHASigner } from '@aztec/validator-ha-signer/factory';
|
|
13
|
+
import { createHASigner, createLocalSignerWithProtection, createSignerFromSharedDb } from '@aztec/validator-ha-signer/factory';
|
|
17
14
|
import { DutyType } from '@aztec/validator-ha-signer/types';
|
|
18
15
|
import { EventEmitter } from 'events';
|
|
19
|
-
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
20
16
|
import { ValidationService } from './duties/validation_service.js';
|
|
21
17
|
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
22
18
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
23
19
|
import { ValidatorMetrics } from './metrics.js';
|
|
20
|
+
import { ProposalHandler } from './proposal_handler.js';
|
|
24
21
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
25
22
|
// Just cap the set to avoid unbounded growth.
|
|
26
23
|
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
24
|
+
const MAX_TRACKED_INVALID_PROPOSAL_SLOTS = 1000;
|
|
25
|
+
const MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS = 1000;
|
|
26
|
+
const MAX_TRACKED_BAD_ATTESTATIONS = 10_000;
|
|
27
27
|
// What errors from the block proposal handler result in slashing
|
|
28
28
|
const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
29
29
|
'state_mismatch',
|
|
30
|
-
'failed_txs'
|
|
30
|
+
'failed_txs',
|
|
31
|
+
'global_variables_mismatch',
|
|
32
|
+
'invalid_proposal',
|
|
33
|
+
'parent_block_wrong_slot',
|
|
34
|
+
'in_hash_mismatch'
|
|
31
35
|
];
|
|
36
|
+
const SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT = {
|
|
37
|
+
// enabled
|
|
38
|
+
['invalid_fee_asset_price_modifier']: true,
|
|
39
|
+
['checkpoint_header_mismatch']: true,
|
|
40
|
+
// These late mismatches should normally be caught by earlier checks, but if reached after validating the local
|
|
41
|
+
// checkpoint inputs, the proposer-signed payload disagrees with deterministic recomputation.
|
|
42
|
+
['archive_mismatch']: true,
|
|
43
|
+
['out_hash_mismatch']: true,
|
|
44
|
+
['no_blocks_for_slot']: true,
|
|
45
|
+
['too_many_blocks_in_checkpoint']: true,
|
|
46
|
+
['checkpoint_validation_failed']: true,
|
|
47
|
+
['last_block_archive_mismatch']: true,
|
|
48
|
+
// disabled
|
|
49
|
+
['invalid_signature']: false,
|
|
50
|
+
['last_block_not_found']: false,
|
|
51
|
+
['block_fetch_error']: false,
|
|
52
|
+
['checkpoint_already_published']: false
|
|
53
|
+
};
|
|
32
54
|
/**
|
|
33
55
|
* Validator Client
|
|
34
56
|
*/ export class ValidatorClient extends EventEmitter {
|
|
35
57
|
keyStore;
|
|
36
58
|
epochCache;
|
|
37
59
|
p2pClient;
|
|
38
|
-
|
|
60
|
+
proposalHandler;
|
|
39
61
|
blockSource;
|
|
40
62
|
checkpointsBuilder;
|
|
41
63
|
worldState;
|
|
42
64
|
l1ToL2MessageSource;
|
|
43
65
|
config;
|
|
44
66
|
blobClient;
|
|
45
|
-
|
|
67
|
+
slashingProtectionSigner;
|
|
46
68
|
dateProvider;
|
|
47
69
|
tracer;
|
|
48
70
|
validationService;
|
|
@@ -54,15 +76,21 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
54
76
|
/** Tracks the last checkpoint proposal we created. */ lastProposedCheckpoint;
|
|
55
77
|
lastEpochForCommitteeUpdateLoop;
|
|
56
78
|
epochCacheUpdateLoop;
|
|
79
|
+
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */ lastAttestedEpochByAttester;
|
|
57
80
|
proposersOfInvalidBlocks;
|
|
81
|
+
slotsWithInvalidProposals;
|
|
82
|
+
invalidCheckpointProposalOffenseKeys;
|
|
83
|
+
badAttestationOffenseKeys;
|
|
84
|
+
slotsWithProposalEquivocation;
|
|
58
85
|
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */ lastAttestedProposal;
|
|
59
|
-
constructor(keyStore, epochCache, p2pClient,
|
|
60
|
-
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.
|
|
86
|
+
constructor(keyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
87
|
+
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.slotsWithInvalidProposals = FifoSet.withLimit(MAX_TRACKED_INVALID_PROPOSAL_SLOTS), this.invalidCheckpointProposalOffenseKeys = FifoSet.withLimit(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS), this.badAttestationOffenseKeys = FifoSet.withLimit(MAX_TRACKED_BAD_ATTESTATIONS), this.slotsWithProposalEquivocation = FifoSet.withLimit(MAX_TRACKED_INVALID_PROPOSAL_SLOTS);
|
|
61
88
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
62
89
|
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
63
90
|
this.tracer = telemetry.getTracer('Validator');
|
|
64
91
|
this.metrics = new ValidatorMetrics(telemetry);
|
|
65
|
-
this.validationService = new ValidationService(keyStore, this.log.createChild('validation-service'));
|
|
92
|
+
this.validationService = new ValidationService(keyStore, this.getSignatureContext(), this.log.createChild('validation-service'));
|
|
93
|
+
this.proposalHandler.setCheckpointProposalValidationFailureCallback((proposal, result, proposalInfo)=>this.handleInvalidCheckpointProposal(proposal, result, proposalInfo));
|
|
66
94
|
// Refresh epoch cache every second to trigger alert if participation in committee changes
|
|
67
95
|
this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), this.log, 1000);
|
|
68
96
|
const myAddresses = this.getValidatorAddresses();
|
|
@@ -96,6 +124,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
96
124
|
this.log.trace(`No committee found for slot`);
|
|
97
125
|
return;
|
|
98
126
|
}
|
|
127
|
+
this.metrics.setCurrentEpoch(epoch);
|
|
99
128
|
if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
|
|
100
129
|
const me = this.getValidatorAddresses();
|
|
101
130
|
const committeeSet = new Set(committee.map((v)=>v.toString()));
|
|
@@ -111,37 +140,65 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
111
140
|
this.log.error(`Error updating epoch committee`, err);
|
|
112
141
|
}
|
|
113
142
|
}
|
|
114
|
-
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
143
|
+
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, reexecutionTracker, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), slashingProtectionDb) {
|
|
115
144
|
const metrics = new ValidatorMetrics(telemetry);
|
|
116
145
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
117
|
-
txsPermitted: !config.disableTransactions
|
|
146
|
+
txsPermitted: !config.disableTransactions,
|
|
147
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock,
|
|
148
|
+
maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
|
|
149
|
+
skipSlotValidation: config.skipProposalSlotValidation,
|
|
150
|
+
signatureContext: {
|
|
151
|
+
chainId: config.l1ChainId,
|
|
152
|
+
rollupAddress: config.rollupAddress
|
|
153
|
+
}
|
|
118
154
|
});
|
|
119
|
-
const
|
|
155
|
+
const proposalHandler = new ProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, blobClient, reexecutionTracker, metrics, dateProvider, telemetry, undefined);
|
|
120
156
|
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
121
|
-
let
|
|
122
|
-
|
|
123
|
-
|
|
157
|
+
let slashingProtectionSigner;
|
|
158
|
+
if (slashingProtectionDb) {
|
|
159
|
+
// Shared database mode: use a pre-existing database (e.g. for testing HA setups).
|
|
160
|
+
({ signer: slashingProtectionSigner } = createSignerFromSharedDb(slashingProtectionDb, config, {
|
|
161
|
+
telemetryClient: telemetry,
|
|
162
|
+
dateProvider
|
|
163
|
+
}));
|
|
164
|
+
} else if (config.haSigningEnabled) {
|
|
165
|
+
// Multi-node HA mode: use PostgreSQL-backed distributed locking.
|
|
124
166
|
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
125
167
|
const haConfig = {
|
|
126
168
|
...config,
|
|
127
169
|
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000
|
|
128
170
|
};
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
171
|
+
({ signer: slashingProtectionSigner } = await createHASigner(haConfig, {
|
|
172
|
+
telemetryClient: telemetry,
|
|
173
|
+
dateProvider
|
|
174
|
+
}));
|
|
175
|
+
} else {
|
|
176
|
+
// Single-node mode: use LMDB-backed local signing protection.
|
|
177
|
+
// This prevents double-signing if the node crashes and restarts mid-proposal.
|
|
178
|
+
({ signer: slashingProtectionSigner } = await createLocalSignerWithProtection(config, {
|
|
179
|
+
telemetryClient: telemetry,
|
|
180
|
+
dateProvider
|
|
181
|
+
}));
|
|
182
|
+
}
|
|
183
|
+
const validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, slashingProtectionSigner);
|
|
184
|
+
const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider, telemetry);
|
|
134
185
|
return validator;
|
|
135
186
|
}
|
|
136
187
|
getValidatorAddresses() {
|
|
137
188
|
return this.keyStore.getAddresses().filter((addr)=>!this.config.disabledValidators.some((disabled)=>disabled.equals(addr)));
|
|
138
189
|
}
|
|
139
|
-
|
|
140
|
-
return this.
|
|
190
|
+
getProposalHandler() {
|
|
191
|
+
return this.proposalHandler;
|
|
141
192
|
}
|
|
142
193
|
signWithAddress(addr, msg, context) {
|
|
143
194
|
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
144
195
|
}
|
|
196
|
+
getSignatureContext() {
|
|
197
|
+
return {
|
|
198
|
+
chainId: this.config.l1ChainId,
|
|
199
|
+
rollupAddress: this.config.rollupAddress
|
|
200
|
+
};
|
|
201
|
+
}
|
|
145
202
|
getCoinbaseForAttestor(attestor) {
|
|
146
203
|
return this.keyStore.getCoinbaseAddress(attestor);
|
|
147
204
|
}
|
|
@@ -151,25 +208,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
151
208
|
getConfig() {
|
|
152
209
|
return this.config;
|
|
153
210
|
}
|
|
211
|
+
hasProposalEquivocation(slotNumber) {
|
|
212
|
+
return this.slotsWithProposalEquivocation.has(slotNumber);
|
|
213
|
+
}
|
|
214
|
+
hasInvalidProposals(slotNumber) {
|
|
215
|
+
return this.slotsWithInvalidProposals.has(slotNumber);
|
|
216
|
+
}
|
|
154
217
|
updateConfig(config) {
|
|
155
218
|
this.config = {
|
|
156
219
|
...this.config,
|
|
157
220
|
...config
|
|
158
221
|
};
|
|
222
|
+
this.proposalHandler.updateConfig(config);
|
|
159
223
|
}
|
|
160
224
|
reloadKeystore(newManager) {
|
|
161
|
-
if (this.config.haSigningEnabled && !this.haSigner) {
|
|
162
|
-
this.log.warn('HA signing is enabled in config but was not initialized at startup. ' + 'Restart the node to enable HA signing.');
|
|
163
|
-
} else if (!this.config.haSigningEnabled && this.haSigner) {
|
|
164
|
-
this.log.warn('HA signing was disabled via config update but the HA signer is still active. ' + 'Restart the node to fully disable HA signing.');
|
|
165
|
-
}
|
|
166
225
|
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
} else {
|
|
170
|
-
this.keyStore = newAdapter;
|
|
171
|
-
}
|
|
172
|
-
this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
|
|
226
|
+
this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
|
|
227
|
+
this.validationService = new ValidationService(this.keyStore, this.getSignatureContext(), this.log.createChild('validation-service'));
|
|
173
228
|
}
|
|
174
229
|
async start() {
|
|
175
230
|
if (this.epochCacheUpdateLoop.isRunning()) {
|
|
@@ -202,7 +257,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
202
257
|
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
203
258
|
// and processed separately via the block handler above.
|
|
204
259
|
const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
205
|
-
this.p2pClient.
|
|
260
|
+
this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
|
|
206
261
|
// Duplicate proposal handler - triggers slashing for equivocation
|
|
207
262
|
this.p2pClient.registerDuplicateProposalCallback((info)=>{
|
|
208
263
|
this.handleDuplicateProposal(info);
|
|
@@ -211,6 +266,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
211
266
|
this.p2pClient.registerDuplicateAttestationCallback((info)=>{
|
|
212
267
|
this.handleDuplicateAttestation(info);
|
|
213
268
|
});
|
|
269
|
+
this.p2pClient.registerCheckpointAttestationCallback((attestation)=>{
|
|
270
|
+
this.handleCheckpointAttestation(attestation);
|
|
271
|
+
});
|
|
214
272
|
const myAddresses = this.getValidatorAddresses();
|
|
215
273
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
216
274
|
await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
|
|
@@ -231,13 +289,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
231
289
|
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
232
290
|
return false;
|
|
233
291
|
}
|
|
234
|
-
//
|
|
292
|
+
// Log self-proposals from HA peers (same validator key on different nodes)
|
|
235
293
|
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
236
|
-
this.log.
|
|
294
|
+
this.log.verbose(`Processing block proposal from HA peer for slot ${slotNumber}`, {
|
|
237
295
|
proposer: proposer.toString(),
|
|
238
296
|
slotNumber
|
|
239
297
|
});
|
|
240
|
-
return false;
|
|
241
298
|
}
|
|
242
299
|
// Check if we're in the committee (for metrics purposes)
|
|
243
300
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
@@ -251,14 +308,11 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
251
308
|
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
252
309
|
fishermanMode: this.config.fishermanMode || false
|
|
253
310
|
});
|
|
254
|
-
// Reexecute
|
|
255
|
-
|
|
256
|
-
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
257
|
-
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
|
|
258
|
-
const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
|
|
311
|
+
// Reexecute outside the escape hatch so slashing observers can detect invalid proposals even when penalties are 0.
|
|
312
|
+
const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !escapeHatchOpen);
|
|
259
313
|
if (!validationResult.isValid) {
|
|
260
|
-
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
261
314
|
const reason = validationResult.reason || 'unknown';
|
|
315
|
+
this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
|
|
262
316
|
// Classify failure reason: bad proposal vs node issue
|
|
263
317
|
const badProposalReasons = [
|
|
264
318
|
'invalid_proposal',
|
|
@@ -273,10 +327,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
273
327
|
// Node issues so we can't validate
|
|
274
328
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
275
329
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
330
|
+
if (!escapeHatchOpen && validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)) {
|
|
331
|
+
this.log.info(`Detected invalid block proposal offense`, {
|
|
332
|
+
...proposalInfo,
|
|
333
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
334
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL)
|
|
335
|
+
});
|
|
279
336
|
this.slashInvalidBlock(proposal);
|
|
337
|
+
this.markInvalidProposalSlot(proposal.slotNumber);
|
|
280
338
|
}
|
|
281
339
|
return false;
|
|
282
340
|
}
|
|
@@ -298,58 +356,50 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
298
356
|
* the lastBlock is extracted and processed separately via the block handler.
|
|
299
357
|
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
300
358
|
*/ async attestToCheckpointProposal(proposal, _proposalSender) {
|
|
301
|
-
const
|
|
359
|
+
const proposalSlotNumber = proposal.slotNumber;
|
|
302
360
|
const proposer = proposal.getSender();
|
|
303
361
|
// If escape hatch is open for this slot's epoch, do not attest.
|
|
304
|
-
if (await this.epochCache.isEscapeHatchOpenAtSlot(
|
|
305
|
-
this.log.warn(`Escape hatch open for slot ${
|
|
362
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(proposalSlotNumber)) {
|
|
363
|
+
this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
|
|
306
364
|
return undefined;
|
|
307
365
|
}
|
|
308
|
-
//
|
|
309
|
-
if (!
|
|
310
|
-
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
366
|
+
// Early-out for equivocation: refuses if we've already attested to a higher slot.
|
|
367
|
+
if (!this.shouldAttestToSlot(proposalSlotNumber)) {
|
|
311
368
|
return undefined;
|
|
312
369
|
}
|
|
313
370
|
// Ignore proposals from ourselves (may happen in HA setups)
|
|
314
|
-
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
315
|
-
this.log.
|
|
371
|
+
if (proposer && this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
372
|
+
this.log.debug(`Ignoring block proposal from self for slot ${proposalSlotNumber}`, {
|
|
316
373
|
proposer: proposer.toString(),
|
|
317
|
-
|
|
374
|
+
proposalSlotNumber
|
|
318
375
|
});
|
|
319
376
|
return undefined;
|
|
320
377
|
}
|
|
321
|
-
//
|
|
322
|
-
|
|
323
|
-
this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`);
|
|
324
|
-
return undefined;
|
|
325
|
-
}
|
|
326
|
-
// Check that I have any address in current committee before attesting
|
|
327
|
-
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
378
|
+
// Check that I have any address in the committee where this checkpoint will land before attesting
|
|
379
|
+
const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
|
|
328
380
|
const partOfCommittee = inCommittee.length > 0;
|
|
329
381
|
const proposalInfo = {
|
|
330
|
-
|
|
382
|
+
proposalSlotNumber,
|
|
331
383
|
archive: proposal.archive.toString(),
|
|
332
|
-
proposer: proposer
|
|
333
|
-
txCount: proposal.txHashes.length
|
|
384
|
+
proposer: proposer?.toString()
|
|
334
385
|
};
|
|
335
|
-
this.log.info(`Received checkpoint proposal for slot ${
|
|
386
|
+
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
336
387
|
...proposalInfo,
|
|
337
|
-
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
338
388
|
fishermanMode: this.config.fishermanMode || false
|
|
339
389
|
});
|
|
340
|
-
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
390
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
|
|
391
|
+
// Uses the cached result from the all-nodes callback if available (avoids double validation).
|
|
392
|
+
let checkpointNumber;
|
|
341
393
|
if (this.config.skipCheckpointProposalValidation) {
|
|
342
|
-
this.log.warn(`Skipping checkpoint proposal validation for slot ${
|
|
394
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
395
|
+
checkpointNumber = CheckpointNumber(0);
|
|
343
396
|
} else {
|
|
344
|
-
const validationResult = await this.
|
|
397
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
345
398
|
if (!validationResult.isValid) {
|
|
346
399
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
347
400
|
return undefined;
|
|
348
401
|
}
|
|
349
|
-
|
|
350
|
-
// Upload blobs to filestore if we can (fire and forget)
|
|
351
|
-
if (this.blobClient.canUpload()) {
|
|
352
|
-
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
402
|
+
checkpointNumber = validationResult.checkpointNumber;
|
|
353
403
|
}
|
|
354
404
|
// Check that I have any address in current committee before attesting
|
|
355
405
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
@@ -358,12 +408,22 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
358
408
|
return undefined;
|
|
359
409
|
}
|
|
360
410
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
361
|
-
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${
|
|
411
|
+
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
362
412
|
...proposalInfo,
|
|
363
413
|
inCommittee: partOfCommittee,
|
|
364
414
|
fishermanMode: this.config.fishermanMode || false
|
|
365
415
|
});
|
|
366
416
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
417
|
+
// Track epoch participation per attester: count each (attester, epoch) pair at most once
|
|
418
|
+
const proposalEpoch = getEpochAtSlot(proposalSlotNumber, this.epochCache.getL1Constants());
|
|
419
|
+
for (const attester of inCommittee){
|
|
420
|
+
const key = attester.toString();
|
|
421
|
+
const lastEpoch = this.lastAttestedEpochByAttester.get(key);
|
|
422
|
+
if (lastEpoch === undefined || proposalEpoch > lastEpoch) {
|
|
423
|
+
this.lastAttestedEpochByAttester.set(key, proposalEpoch);
|
|
424
|
+
this.metrics.incAttestedEpochCount(attester);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
367
427
|
// Determine which validators should attest
|
|
368
428
|
let attestors;
|
|
369
429
|
if (partOfCommittee) {
|
|
@@ -380,13 +440,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
380
440
|
}
|
|
381
441
|
if (this.config.fishermanMode) {
|
|
382
442
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
383
|
-
this.log.info(`Creating checkpoint attestations for slot ${
|
|
443
|
+
this.log.info(`Creating checkpoint attestations for slot ${proposalSlotNumber}`, {
|
|
384
444
|
...proposalInfo,
|
|
385
445
|
attestors: attestors.map((a)=>a.toString())
|
|
386
446
|
});
|
|
387
447
|
return undefined;
|
|
388
448
|
}
|
|
389
|
-
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
449
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
|
|
390
450
|
}
|
|
391
451
|
/**
|
|
392
452
|
* Checks if we should attest to a slot based on equivocation prevention rules.
|
|
@@ -403,164 +463,24 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
403
463
|
}
|
|
404
464
|
return true;
|
|
405
465
|
}
|
|
406
|
-
async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
|
|
466
|
+
async createCheckpointAttestationsFromProposal(proposal, attestors = [], checkpointNumber) {
|
|
407
467
|
// Equivocation check: must happen right before signing to minimize the race window
|
|
408
468
|
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
409
469
|
return undefined;
|
|
410
470
|
}
|
|
411
|
-
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
471
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
|
|
412
472
|
// Track the proposal we attested to (to prevent equivocation)
|
|
413
473
|
this.lastAttestedProposal = proposal;
|
|
414
474
|
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
415
475
|
return attestations;
|
|
416
476
|
}
|
|
417
477
|
/**
|
|
418
|
-
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
419
|
-
* @returns Validation result with isValid flag and reason if invalid.
|
|
420
|
-
*/ async validateCheckpointProposal(proposal, proposalInfo) {
|
|
421
|
-
const slot = proposal.slotNumber;
|
|
422
|
-
// Timeout block syncing at the start of the next slot
|
|
423
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
424
|
-
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
|
|
425
|
-
const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
|
|
426
|
-
// Wait for last block to sync by archive
|
|
427
|
-
let lastBlockHeader;
|
|
428
|
-
try {
|
|
429
|
-
lastBlockHeader = await retryUntil(async ()=>{
|
|
430
|
-
await this.blockSource.syncImmediate();
|
|
431
|
-
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
432
|
-
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, timeoutSeconds, 0.5);
|
|
433
|
-
} catch (err) {
|
|
434
|
-
if (err instanceof TimeoutError) {
|
|
435
|
-
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
436
|
-
return {
|
|
437
|
-
isValid: false,
|
|
438
|
-
reason: 'last_block_not_found'
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
|
-
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
442
|
-
return {
|
|
443
|
-
isValid: false,
|
|
444
|
-
reason: 'block_fetch_error'
|
|
445
|
-
};
|
|
446
|
-
}
|
|
447
|
-
if (!lastBlockHeader) {
|
|
448
|
-
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
449
|
-
return {
|
|
450
|
-
isValid: false,
|
|
451
|
-
reason: 'last_block_not_found'
|
|
452
|
-
};
|
|
453
|
-
}
|
|
454
|
-
// Get all full blocks for the slot and checkpoint
|
|
455
|
-
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
456
|
-
if (blocks.length === 0) {
|
|
457
|
-
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
458
|
-
return {
|
|
459
|
-
isValid: false,
|
|
460
|
-
reason: 'no_blocks_for_slot'
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
|
-
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
464
|
-
if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
|
|
465
|
-
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
466
|
-
return {
|
|
467
|
-
isValid: false,
|
|
468
|
-
reason: 'last_block_archive_mismatch'
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
472
|
-
...proposalInfo,
|
|
473
|
-
blockNumbers: blocks.map((b)=>b.number)
|
|
474
|
-
});
|
|
475
|
-
// Get checkpoint constants from first block
|
|
476
|
-
const firstBlock = blocks[0];
|
|
477
|
-
const constants = this.extractCheckpointConstants(firstBlock);
|
|
478
|
-
const checkpointNumber = firstBlock.checkpointNumber;
|
|
479
|
-
// Get L1-to-L2 messages for this checkpoint
|
|
480
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
481
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
482
|
-
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
483
|
-
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch)).filter((c)=>c.checkpointNumber < checkpointNumber).map((c)=>c.checkpointOutHash);
|
|
484
|
-
// Fork world state at the block before the first block
|
|
485
|
-
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
486
|
-
const fork = await this.worldState.fork(parentBlockNumber);
|
|
487
|
-
try {
|
|
488
|
-
// Create checkpoint builder with all existing blocks
|
|
489
|
-
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
|
|
490
|
-
// Complete the checkpoint to get computed values
|
|
491
|
-
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
492
|
-
// Compare checkpoint header with proposal
|
|
493
|
-
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
494
|
-
this.log.warn(`Checkpoint header mismatch`, {
|
|
495
|
-
...proposalInfo,
|
|
496
|
-
computed: computedCheckpoint.header.toInspect(),
|
|
497
|
-
proposal: proposal.checkpointHeader.toInspect()
|
|
498
|
-
});
|
|
499
|
-
return {
|
|
500
|
-
isValid: false,
|
|
501
|
-
reason: 'checkpoint_header_mismatch'
|
|
502
|
-
};
|
|
503
|
-
}
|
|
504
|
-
// Compare archive root with proposal
|
|
505
|
-
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
506
|
-
this.log.warn(`Archive root mismatch`, {
|
|
507
|
-
...proposalInfo,
|
|
508
|
-
computed: computedCheckpoint.archive.root.toString(),
|
|
509
|
-
proposal: proposal.archive.toString()
|
|
510
|
-
});
|
|
511
|
-
return {
|
|
512
|
-
isValid: false,
|
|
513
|
-
reason: 'archive_mismatch'
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
517
|
-
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
518
|
-
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
519
|
-
const computedEpochOutHash = accumulateCheckpointOutHashes([
|
|
520
|
-
...previousCheckpointOutHashes,
|
|
521
|
-
checkpointOutHash
|
|
522
|
-
]);
|
|
523
|
-
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
524
|
-
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
525
|
-
this.log.warn(`Epoch out hash mismatch`, {
|
|
526
|
-
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
527
|
-
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
528
|
-
checkpointOutHash: checkpointOutHash.toString(),
|
|
529
|
-
previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
|
|
530
|
-
...proposalInfo
|
|
531
|
-
});
|
|
532
|
-
return {
|
|
533
|
-
isValid: false,
|
|
534
|
-
reason: 'out_hash_mismatch'
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
538
|
-
return {
|
|
539
|
-
isValid: true
|
|
540
|
-
};
|
|
541
|
-
} finally{
|
|
542
|
-
await fork.close();
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
/**
|
|
546
|
-
* Extract checkpoint global variables from a block.
|
|
547
|
-
*/ extractCheckpointConstants(block) {
|
|
548
|
-
const gv = block.header.globalVariables;
|
|
549
|
-
return {
|
|
550
|
-
chainId: gv.chainId,
|
|
551
|
-
version: gv.version,
|
|
552
|
-
slotNumber: gv.slotNumber,
|
|
553
|
-
timestamp: gv.timestamp,
|
|
554
|
-
coinbase: gv.coinbase,
|
|
555
|
-
feeRecipient: gv.feeRecipient,
|
|
556
|
-
gasFees: gv.gasFees
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
|
-
/**
|
|
560
478
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
561
479
|
*/ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
|
|
562
480
|
try {
|
|
563
|
-
const lastBlockHeader = await this.blockSource.
|
|
481
|
+
const lastBlockHeader = (await this.blockSource.getBlockData({
|
|
482
|
+
archive: proposal.archive
|
|
483
|
+
}))?.header;
|
|
564
484
|
if (!lastBlockHeader) {
|
|
565
485
|
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
566
486
|
return;
|
|
@@ -588,11 +508,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
588
508
|
this.log.warn(`Cannot slash proposal with invalid signature`);
|
|
589
509
|
return;
|
|
590
510
|
}
|
|
591
|
-
// Trim the set if it's too big.
|
|
592
|
-
if (this.proposersOfInvalidBlocks.size > MAX_PROPOSERS_OF_INVALID_BLOCKS) {
|
|
593
|
-
// remove oldest proposer. `values` is guaranteed to be in insertion order.
|
|
594
|
-
this.proposersOfInvalidBlocks.delete(this.proposersOfInvalidBlocks.values().next().value);
|
|
595
|
-
}
|
|
596
511
|
this.proposersOfInvalidBlocks.add(proposer.toString());
|
|
597
512
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
598
513
|
{
|
|
@@ -603,17 +518,95 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
603
518
|
}
|
|
604
519
|
]);
|
|
605
520
|
}
|
|
521
|
+
handleInvalidCheckpointProposal(proposal, result, proposalInfo) {
|
|
522
|
+
if (!SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT[result.reason]) {
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
this.markInvalidProposalSlot(proposal.slotNumber);
|
|
526
|
+
if (this.slashInvalidCheckpointProposal(proposal)) {
|
|
527
|
+
this.log.info(`Detected invalid checkpoint proposal offense`, {
|
|
528
|
+
...proposalInfo,
|
|
529
|
+
reason: result.reason,
|
|
530
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
531
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL)
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
slashInvalidCheckpointProposal(proposal) {
|
|
536
|
+
const proposer = proposal.getSender();
|
|
537
|
+
if (!proposer) {
|
|
538
|
+
this.log.warn(`Cannot slash checkpoint proposal with invalid signature`, {
|
|
539
|
+
slotNumber: proposal.slotNumber,
|
|
540
|
+
archive: proposal.archive.toString()
|
|
541
|
+
});
|
|
542
|
+
return false;
|
|
543
|
+
}
|
|
544
|
+
const offenseType = OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL;
|
|
545
|
+
const offenseKey = `${proposer.toString()}:${offenseType}:${proposal.slotNumber}`;
|
|
546
|
+
if (!this.invalidCheckpointProposalOffenseKeys.addIfAbsent(offenseKey)) {
|
|
547
|
+
return false;
|
|
548
|
+
}
|
|
549
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
550
|
+
{
|
|
551
|
+
validator: proposer,
|
|
552
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
553
|
+
offenseType,
|
|
554
|
+
epochOrSlot: BigInt(proposal.slotNumber)
|
|
555
|
+
}
|
|
556
|
+
]);
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
559
|
+
markInvalidProposalSlot(slotNumber) {
|
|
560
|
+
this.slotsWithInvalidProposals.add(slotNumber);
|
|
561
|
+
}
|
|
562
|
+
handleCheckpointAttestation(attestation) {
|
|
563
|
+
const slotNumber = attestation.slotNumber;
|
|
564
|
+
if (!this.slotsWithInvalidProposals.has(slotNumber) || this.slotsWithProposalEquivocation.has(slotNumber)) {
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
const attester = attestation.getSender();
|
|
568
|
+
if (!attester) {
|
|
569
|
+
this.log.warn(`Cannot slash checkpoint attestation with invalid signature`, {
|
|
570
|
+
slotNumber,
|
|
571
|
+
archive: attestation.archive.toString()
|
|
572
|
+
});
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
this.slashAttestedToInvalidCheckpointProposal(slotNumber, attester);
|
|
576
|
+
}
|
|
577
|
+
slashAttestedToInvalidCheckpointProposal(slotNumber, attester) {
|
|
578
|
+
const offenseKey = `${attester.toString()}:${OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL}:${slotNumber}`;
|
|
579
|
+
if (!this.badAttestationOffenseKeys.addIfAbsent(offenseKey)) {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
this.log.info(`Detected attestation to invalid checkpoint proposal offense`, {
|
|
583
|
+
attester: attester.toString(),
|
|
584
|
+
slotNumber,
|
|
585
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
586
|
+
offenseType: getOffenseTypeName(OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL)
|
|
587
|
+
});
|
|
588
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
589
|
+
{
|
|
590
|
+
validator: attester,
|
|
591
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
592
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
593
|
+
epochOrSlot: BigInt(slotNumber)
|
|
594
|
+
}
|
|
595
|
+
]);
|
|
596
|
+
}
|
|
606
597
|
/**
|
|
607
598
|
* Handle detection of a duplicate proposal (equivocation).
|
|
608
599
|
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
609
600
|
*/ handleDuplicateProposal(info) {
|
|
610
601
|
const { slot, proposer, type } = info;
|
|
611
|
-
this.
|
|
602
|
+
this.slotsWithProposalEquivocation.add(slot);
|
|
603
|
+
this.log.info(`Detected duplicate ${type} proposal offense from ${proposer.toString()} at slot ${slot}`, {
|
|
612
604
|
proposer: proposer.toString(),
|
|
613
605
|
slot,
|
|
614
|
-
type
|
|
606
|
+
type,
|
|
607
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
608
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_PROPOSAL)
|
|
615
609
|
});
|
|
616
|
-
// Emit slash event
|
|
617
610
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
618
611
|
{
|
|
619
612
|
validator: proposer,
|
|
@@ -622,15 +615,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
622
615
|
epochOrSlot: BigInt(slot)
|
|
623
616
|
}
|
|
624
617
|
]);
|
|
618
|
+
this.emit(WANT_TO_CLEAR_SLASH_EVENT, [
|
|
619
|
+
{
|
|
620
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
621
|
+
epochOrSlot: BigInt(slot)
|
|
622
|
+
}
|
|
623
|
+
]);
|
|
625
624
|
}
|
|
626
625
|
/**
|
|
627
626
|
* Handle detection of a duplicate attestation (equivocation).
|
|
628
627
|
* Emits a slash event when an attester signs attestations for different proposals at the same slot.
|
|
629
628
|
*/ handleDuplicateAttestation(info) {
|
|
630
629
|
const { slot, attester } = info;
|
|
631
|
-
this.log.
|
|
630
|
+
this.log.info(`Detected duplicate attestation offense from ${attester.toString()} at slot ${slot}`, {
|
|
632
631
|
attester: attester.toString(),
|
|
633
|
-
slot
|
|
632
|
+
slot,
|
|
633
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
634
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_ATTESTATION)
|
|
634
635
|
});
|
|
635
636
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
636
637
|
{
|
|
@@ -641,7 +642,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
641
642
|
}
|
|
642
643
|
]);
|
|
643
644
|
}
|
|
644
|
-
async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
|
|
645
|
+
async createBlockProposal(blockHeader, checkpointNumber, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
|
|
645
646
|
// Validate that we're not creating a proposal for an older or equal position
|
|
646
647
|
if (this.lastProposedBlock) {
|
|
647
648
|
const lastSlot = this.lastProposedBlock.slotNumber;
|
|
@@ -652,14 +653,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
652
653
|
}
|
|
653
654
|
}
|
|
654
655
|
this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
|
|
655
|
-
const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
656
|
+
const newProposal = await this.validationService.createBlockProposal(blockHeader, checkpointNumber, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
656
657
|
...options,
|
|
657
|
-
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
658
|
+
broadcastInvalidBlockProposal: options.broadcastInvalidBlockProposal || this.config.broadcastInvalidBlockProposal
|
|
658
659
|
});
|
|
659
660
|
this.lastProposedBlock = newProposal;
|
|
660
661
|
return newProposal;
|
|
661
662
|
}
|
|
662
|
-
async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier,
|
|
663
|
+
async createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options = {}) {
|
|
663
664
|
// Validate that we're not creating a proposal for an older or equal slot
|
|
664
665
|
if (this.lastProposedCheckpoint) {
|
|
665
666
|
const lastSlot = this.lastProposedCheckpoint.slotNumber;
|
|
@@ -669,23 +670,30 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
669
670
|
}
|
|
670
671
|
}
|
|
671
672
|
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
672
|
-
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier,
|
|
673
|
+
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options);
|
|
673
674
|
this.lastProposedCheckpoint = newProposal;
|
|
675
|
+
// Self-record this slot's outcome on the re-execution tracker. Proposers don't run their
|
|
676
|
+
// own proposals through `handleCheckpointProposal`, so without this call the proposer's
|
|
677
|
+
// sentinel would see no outcome for slots it proposed and would mis-attribute itself as
|
|
678
|
+
// inactive. We pass the locally-computed `archive` (not `newProposal.archive`, which may
|
|
679
|
+
// be intentionally corrupted under test-only flags); from the proposer's local-view
|
|
680
|
+
// perspective the work it just completed is valid by definition.
|
|
681
|
+
this.proposalHandler.recordOwnCheckpointProposalAsValid(checkpointHeader.slotNumber, archive, checkpointNumber);
|
|
674
682
|
return newProposal;
|
|
675
683
|
}
|
|
676
684
|
async broadcastBlockProposal(proposal) {
|
|
677
685
|
await this.p2pClient.broadcastProposal(proposal);
|
|
678
686
|
}
|
|
679
|
-
async signAttestationsAndSigners(attestationsAndSigners, proposer, slot,
|
|
680
|
-
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot,
|
|
687
|
+
async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, checkpointNumber) {
|
|
688
|
+
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, checkpointNumber);
|
|
681
689
|
}
|
|
682
|
-
async collectOwnAttestations(proposal) {
|
|
690
|
+
async collectOwnAttestations(proposal, checkpointNumber) {
|
|
683
691
|
const slot = proposal.slotNumber;
|
|
684
692
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
685
693
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
|
|
686
694
|
inCommittee
|
|
687
695
|
});
|
|
688
|
-
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
696
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
|
|
689
697
|
if (!attestations) {
|
|
690
698
|
return [];
|
|
691
699
|
}
|
|
@@ -697,7 +705,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
697
705
|
});
|
|
698
706
|
return attestations;
|
|
699
707
|
}
|
|
700
|
-
async collectAttestations(proposal, required, deadline) {
|
|
708
|
+
async collectAttestations(proposal, required, deadline, checkpointNumber) {
|
|
701
709
|
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
702
710
|
const slot = proposal.slotNumber;
|
|
703
711
|
this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
|
|
@@ -705,28 +713,20 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
705
713
|
this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
|
|
706
714
|
throw new AttestationTimeoutError(0, required, slot);
|
|
707
715
|
}
|
|
708
|
-
await this.collectOwnAttestations(proposal);
|
|
709
|
-
const
|
|
716
|
+
await this.collectOwnAttestations(proposal, checkpointNumber);
|
|
717
|
+
const proposalPayloadHash = proposal.getPayloadHash();
|
|
710
718
|
const myAddresses = this.getValidatorAddresses();
|
|
711
719
|
let attestations = [];
|
|
712
720
|
while(true){
|
|
713
|
-
//
|
|
714
|
-
//
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
this.log.warn(`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`, {
|
|
718
|
-
attestationArchive: attestation.archive.toString(),
|
|
719
|
-
proposalArchive: proposal.archive.toString()
|
|
720
|
-
});
|
|
721
|
-
return false;
|
|
722
|
-
}
|
|
723
|
-
return true;
|
|
724
|
-
});
|
|
721
|
+
// The pool already filters by proposal payload hash; if any attestation slips through with a
|
|
722
|
+
// mismatched payload hash, drop it defensively. Equivocations are emitted as separate slash
|
|
723
|
+
// events from libp2p_service.
|
|
724
|
+
const collectedAttestations = await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalPayloadHash);
|
|
725
725
|
// Log new attestations we collected
|
|
726
726
|
const oldSenders = attestations.map((attestation)=>attestation.getSender());
|
|
727
727
|
for (const collected of collectedAttestations){
|
|
728
728
|
const collectedSender = collected.getSender();
|
|
729
|
-
// Skip attestations with invalid signatures
|
|
729
|
+
// Skip attestations with invalid signatures. Should not happen as we don't add invalid attestations to our pool.
|
|
730
730
|
if (!collectedSender) {
|
|
731
731
|
this.log.warn(`Skipping attestation with invalid signature for slot ${slot}`);
|
|
732
732
|
continue;
|