@aztec/validator-client 0.0.1-commit.f146247c → 0.0.1-commit.f1b29a41e
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 +60 -18
- package/dest/checkpoint_builder.d.ts +21 -8
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +124 -46
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +26 -6
- package/dest/duties/validation_service.d.ts +2 -2
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +6 -12
- package/dest/factory.d.ts +7 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +6 -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.d.ts +1 -1
- package/dest/key_store/ha_key_store.d.ts.map +1 -1
- package/dest/key_store/ha_key_store.js +3 -3
- package/dest/metrics.d.ts +10 -2
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +12 -0
- package/dest/proposal_handler.d.ts +107 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/proposal_handler.js +963 -0
- package/dest/validator.d.ts +39 -17
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +181 -191
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +142 -39
- package/src/config.ts +26 -6
- package/src/duties/validation_service.ts +12 -11
- package/src/factory.ts +9 -3
- package/src/index.ts +1 -2
- package/src/key_store/ha_key_store.ts +3 -3
- package/src/metrics.ts +19 -1
- package/src/proposal_handler.ts +1027 -0
- package/src/validator.ts +243 -212
- package/dest/block_proposal_handler.d.ts +0 -63
- package/dest/block_proposal_handler.d.ts.map +0 -1
- package/dest/block_proposal_handler.js +0 -546
- package/dest/tx_validator/index.d.ts +0 -3
- package/dest/tx_validator/index.d.ts.map +0 -1
- package/dest/tx_validator/index.js +0 -2
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -19
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -54
- package/src/block_proposal_handler.ts +0 -555
- package/src/tx_validator/index.ts +0 -2
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -154
package/dest/validator.js
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
import { getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
2
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import { TimeoutError } from '@aztec/foundation/error';
|
|
4
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
6
3
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
7
4
|
import { sleep } from '@aztec/foundation/sleep';
|
|
8
5
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
9
6
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
10
7
|
import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
|
|
11
8
|
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
12
|
-
import { accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
|
|
13
9
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
14
10
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
15
|
-
import { createHASigner } from '@aztec/validator-ha-signer/factory';
|
|
11
|
+
import { createHASigner, createLocalSignerWithProtection, createSignerFromSharedDb } from '@aztec/validator-ha-signer/factory';
|
|
16
12
|
import { DutyType } from '@aztec/validator-ha-signer/types';
|
|
17
13
|
import { EventEmitter } from 'events';
|
|
18
|
-
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
19
14
|
import { ValidationService } from './duties/validation_service.js';
|
|
20
15
|
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
21
16
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
22
17
|
import { ValidatorMetrics } from './metrics.js';
|
|
18
|
+
import { ProposalHandler } from './proposal_handler.js';
|
|
23
19
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
24
20
|
// Just cap the set to avoid unbounded growth.
|
|
25
21
|
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
@@ -34,13 +30,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
34
30
|
keyStore;
|
|
35
31
|
epochCache;
|
|
36
32
|
p2pClient;
|
|
37
|
-
|
|
33
|
+
proposalHandler;
|
|
38
34
|
blockSource;
|
|
39
35
|
checkpointsBuilder;
|
|
40
36
|
worldState;
|
|
41
37
|
l1ToL2MessageSource;
|
|
42
38
|
config;
|
|
43
39
|
blobClient;
|
|
40
|
+
slashingProtectionSigner;
|
|
44
41
|
dateProvider;
|
|
45
42
|
tracer;
|
|
46
43
|
validationService;
|
|
@@ -48,13 +45,15 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
48
45
|
log;
|
|
49
46
|
// Whether it has already registered handlers on the p2p client
|
|
50
47
|
hasRegisteredHandlers;
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
/** Tracks the last block proposal we created, to detect duplicate proposal attempts. */ lastProposedBlock;
|
|
49
|
+
/** Tracks the last checkpoint proposal we created. */ lastProposedCheckpoint;
|
|
53
50
|
lastEpochForCommitteeUpdateLoop;
|
|
54
51
|
epochCacheUpdateLoop;
|
|
52
|
+
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */ lastAttestedEpochByAttester;
|
|
55
53
|
proposersOfInvalidBlocks;
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */ lastAttestedProposal;
|
|
55
|
+
constructor(keyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
56
|
+
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 = new Set();
|
|
58
57
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
59
58
|
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
60
59
|
this.tracer = telemetry.getTracer('Validator');
|
|
@@ -93,6 +92,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
93
92
|
this.log.trace(`No committee found for slot`);
|
|
94
93
|
return;
|
|
95
94
|
}
|
|
95
|
+
this.metrics.setCurrentEpoch(epoch);
|
|
96
96
|
if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
|
|
97
97
|
const me = this.getValidatorAddresses();
|
|
98
98
|
const committeeSet = new Set(committee.map((v)=>v.toString()));
|
|
@@ -108,30 +108,49 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
108
108
|
this.log.error(`Error updating epoch committee`, err);
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
111
|
+
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), slashingProtectionDb) {
|
|
112
112
|
const metrics = new ValidatorMetrics(telemetry);
|
|
113
113
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
114
|
-
txsPermitted: !config.disableTransactions
|
|
114
|
+
txsPermitted: !config.disableTransactions,
|
|
115
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock
|
|
115
116
|
});
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
const proposalHandler = new ProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, blobClient, metrics, dateProvider, telemetry);
|
|
118
|
+
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
119
|
+
let slashingProtectionSigner;
|
|
120
|
+
if (slashingProtectionDb) {
|
|
121
|
+
// Shared database mode: use a pre-existing database (e.g. for testing HA setups).
|
|
122
|
+
({ signer: slashingProtectionSigner } = createSignerFromSharedDb(slashingProtectionDb, config, {
|
|
123
|
+
telemetryClient: telemetry,
|
|
124
|
+
dateProvider
|
|
125
|
+
}));
|
|
126
|
+
} else if (config.haSigningEnabled) {
|
|
127
|
+
// Multi-node HA mode: use PostgreSQL-backed distributed locking.
|
|
119
128
|
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
120
129
|
const haConfig = {
|
|
121
130
|
...config,
|
|
122
131
|
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000
|
|
123
132
|
};
|
|
124
|
-
|
|
125
|
-
|
|
133
|
+
({ signer: slashingProtectionSigner } = await createHASigner(haConfig, {
|
|
134
|
+
telemetryClient: telemetry,
|
|
135
|
+
dateProvider
|
|
136
|
+
}));
|
|
137
|
+
} else {
|
|
138
|
+
// Single-node mode: use LMDB-backed local signing protection.
|
|
139
|
+
// This prevents double-signing if the node crashes and restarts mid-proposal.
|
|
140
|
+
({ signer: slashingProtectionSigner } = await createLocalSignerWithProtection(config, {
|
|
141
|
+
telemetryClient: telemetry,
|
|
142
|
+
dateProvider
|
|
143
|
+
}));
|
|
126
144
|
}
|
|
127
|
-
const
|
|
145
|
+
const validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, slashingProtectionSigner);
|
|
146
|
+
const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider, telemetry);
|
|
128
147
|
return validator;
|
|
129
148
|
}
|
|
130
149
|
getValidatorAddresses() {
|
|
131
150
|
return this.keyStore.getAddresses().filter((addr)=>!this.config.disabledValidators.some((disabled)=>disabled.equals(addr)));
|
|
132
151
|
}
|
|
133
|
-
|
|
134
|
-
return this.
|
|
152
|
+
getProposalHandler() {
|
|
153
|
+
return this.proposalHandler;
|
|
135
154
|
}
|
|
136
155
|
signWithAddress(addr, msg, context) {
|
|
137
156
|
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
@@ -151,6 +170,11 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
151
170
|
...config
|
|
152
171
|
};
|
|
153
172
|
}
|
|
173
|
+
reloadKeystore(newManager) {
|
|
174
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
175
|
+
this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
|
|
176
|
+
this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
|
|
177
|
+
}
|
|
154
178
|
async start() {
|
|
155
179
|
if (this.epochCacheUpdateLoop.isRunning()) {
|
|
156
180
|
this.log.warn(`Validator client already started`);
|
|
@@ -182,7 +206,15 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
182
206
|
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
183
207
|
// and processed separately via the block handler above.
|
|
184
208
|
const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
185
|
-
this.p2pClient.
|
|
209
|
+
this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
|
|
210
|
+
// Duplicate proposal handler - triggers slashing for equivocation
|
|
211
|
+
this.p2pClient.registerDuplicateProposalCallback((info)=>{
|
|
212
|
+
this.handleDuplicateProposal(info);
|
|
213
|
+
});
|
|
214
|
+
// Duplicate attestation handler - triggers slashing for attestation equivocation
|
|
215
|
+
this.p2pClient.registerDuplicateAttestationCallback((info)=>{
|
|
216
|
+
this.handleDuplicateAttestation(info);
|
|
217
|
+
});
|
|
186
218
|
const myAddresses = this.getValidatorAddresses();
|
|
187
219
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
188
220
|
await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
|
|
@@ -203,6 +235,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
203
235
|
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
204
236
|
return false;
|
|
205
237
|
}
|
|
238
|
+
// Log self-proposals from HA peers (same validator key on different nodes)
|
|
239
|
+
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
240
|
+
this.log.verbose(`Processing block proposal from HA peer for slot ${slotNumber}`, {
|
|
241
|
+
proposer: proposer.toString(),
|
|
242
|
+
slotNumber
|
|
243
|
+
});
|
|
244
|
+
}
|
|
206
245
|
// Check if we're in the committee (for metrics purposes)
|
|
207
246
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
208
247
|
const partOfCommittee = inCommittee.length > 0;
|
|
@@ -217,12 +256,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
217
256
|
});
|
|
218
257
|
// Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
|
|
219
258
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
220
|
-
const {
|
|
221
|
-
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n
|
|
222
|
-
const validationResult = await this.
|
|
259
|
+
const { slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
260
|
+
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n || partOfCommittee || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
|
|
261
|
+
const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
|
|
223
262
|
if (!validationResult.isValid) {
|
|
224
|
-
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
225
263
|
const reason = validationResult.reason || 'unknown';
|
|
264
|
+
this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
|
|
226
265
|
// Classify failure reason: bad proposal vs node issue
|
|
227
266
|
const badProposalReasons = [
|
|
228
267
|
'invalid_proposal',
|
|
@@ -262,46 +301,44 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
262
301
|
* the lastBlock is extracted and processed separately via the block handler.
|
|
263
302
|
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
264
303
|
*/ async attestToCheckpointProposal(proposal, _proposalSender) {
|
|
265
|
-
const
|
|
304
|
+
const proposalSlotNumber = proposal.slotNumber;
|
|
266
305
|
const proposer = proposal.getSender();
|
|
267
306
|
// If escape hatch is open for this slot's epoch, do not attest.
|
|
268
|
-
if (await this.epochCache.isEscapeHatchOpenAtSlot(
|
|
269
|
-
this.log.warn(`Escape hatch open for slot ${
|
|
307
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(proposalSlotNumber)) {
|
|
308
|
+
this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
|
|
270
309
|
return undefined;
|
|
271
310
|
}
|
|
272
|
-
//
|
|
273
|
-
if (
|
|
274
|
-
this.log.
|
|
311
|
+
// Ignore proposals from ourselves (may happen in HA setups)
|
|
312
|
+
if (proposer && this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
313
|
+
this.log.debug(`Ignoring block proposal from self for slot ${proposalSlotNumber}`, {
|
|
314
|
+
proposer: proposer.toString(),
|
|
315
|
+
proposalSlotNumber
|
|
316
|
+
});
|
|
275
317
|
return undefined;
|
|
276
318
|
}
|
|
277
|
-
// Check that I have any address in
|
|
278
|
-
const inCommittee = await this.epochCache.filterInCommittee(
|
|
319
|
+
// Check that I have any address in the committee where this checkpoint will land before attesting
|
|
320
|
+
const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
|
|
279
321
|
const partOfCommittee = inCommittee.length > 0;
|
|
280
322
|
const proposalInfo = {
|
|
281
|
-
|
|
323
|
+
proposalSlotNumber,
|
|
282
324
|
archive: proposal.archive.toString(),
|
|
283
|
-
proposer: proposer
|
|
284
|
-
txCount: proposal.txHashes.length
|
|
325
|
+
proposer: proposer?.toString()
|
|
285
326
|
};
|
|
286
|
-
this.log.info(`Received checkpoint proposal for slot ${
|
|
327
|
+
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
287
328
|
...proposalInfo,
|
|
288
|
-
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
289
329
|
fishermanMode: this.config.fishermanMode || false
|
|
290
330
|
});
|
|
291
|
-
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
331
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
|
|
332
|
+
// Uses the cached result from the all-nodes callback if available (avoids double validation).
|
|
292
333
|
if (this.config.skipCheckpointProposalValidation) {
|
|
293
|
-
this.log.warn(`Skipping checkpoint proposal validation for slot ${
|
|
334
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
294
335
|
} else {
|
|
295
|
-
const validationResult = await this.
|
|
336
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
296
337
|
if (!validationResult.isValid) {
|
|
297
338
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
298
339
|
return undefined;
|
|
299
340
|
}
|
|
300
341
|
}
|
|
301
|
-
// Upload blobs to filestore if we can (fire and forget)
|
|
302
|
-
if (this.blobClient.canUpload()) {
|
|
303
|
-
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
304
|
-
}
|
|
305
342
|
// Check that I have any address in current committee before attesting
|
|
306
343
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
307
344
|
if (!partOfCommittee && !this.config.fishermanMode) {
|
|
@@ -309,12 +346,22 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
309
346
|
return undefined;
|
|
310
347
|
}
|
|
311
348
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
312
|
-
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${
|
|
349
|
+
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
313
350
|
...proposalInfo,
|
|
314
351
|
inCommittee: partOfCommittee,
|
|
315
352
|
fishermanMode: this.config.fishermanMode || false
|
|
316
353
|
});
|
|
317
354
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
355
|
+
// Track epoch participation per attester: count each (attester, epoch) pair at most once
|
|
356
|
+
const proposalEpoch = getEpochAtSlot(proposalSlotNumber, this.epochCache.getL1Constants());
|
|
357
|
+
for (const attester of inCommittee){
|
|
358
|
+
const key = attester.toString();
|
|
359
|
+
const lastEpoch = this.lastAttestedEpochByAttester.get(key);
|
|
360
|
+
if (lastEpoch === undefined || proposalEpoch > lastEpoch) {
|
|
361
|
+
this.lastAttestedEpochByAttester.set(key, proposalEpoch);
|
|
362
|
+
this.metrics.incAttestedEpochCount(attester);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
318
365
|
// Determine which validators should attest
|
|
319
366
|
let attestors;
|
|
320
367
|
if (partOfCommittee) {
|
|
@@ -331,151 +378,39 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
331
378
|
}
|
|
332
379
|
if (this.config.fishermanMode) {
|
|
333
380
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
334
|
-
this.log.info(`Creating checkpoint attestations for slot ${
|
|
381
|
+
this.log.info(`Creating checkpoint attestations for slot ${proposalSlotNumber}`, {
|
|
335
382
|
...proposalInfo,
|
|
336
383
|
attestors: attestors.map((a)=>a.toString())
|
|
337
384
|
});
|
|
338
385
|
return undefined;
|
|
339
386
|
}
|
|
340
|
-
return this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
341
|
-
}
|
|
342
|
-
async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
|
|
343
|
-
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
344
|
-
await this.p2pClient.addCheckpointAttestations(attestations);
|
|
345
|
-
return attestations;
|
|
387
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
346
388
|
}
|
|
347
389
|
/**
|
|
348
|
-
*
|
|
349
|
-
* @returns
|
|
350
|
-
*/
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
let lastBlockHeader;
|
|
355
|
-
try {
|
|
356
|
-
lastBlockHeader = await retryUntil(async ()=>{
|
|
357
|
-
await this.blockSource.syncImmediate();
|
|
358
|
-
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
359
|
-
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, timeoutSeconds, 0.5);
|
|
360
|
-
} catch (err) {
|
|
361
|
-
if (err instanceof TimeoutError) {
|
|
362
|
-
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
363
|
-
return {
|
|
364
|
-
isValid: false,
|
|
365
|
-
reason: 'last_block_not_found'
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
369
|
-
return {
|
|
370
|
-
isValid: false,
|
|
371
|
-
reason: 'block_fetch_error'
|
|
372
|
-
};
|
|
390
|
+
* Checks if we should attest to a slot based on equivocation prevention rules.
|
|
391
|
+
* @returns true if we should attest, false if we should skip
|
|
392
|
+
*/ shouldAttestToSlot(slotNumber) {
|
|
393
|
+
// If attestToEquivocatedProposals is true, always allow
|
|
394
|
+
if (this.config.attestToEquivocatedProposals) {
|
|
395
|
+
return true;
|
|
373
396
|
}
|
|
374
|
-
if
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
reason: 'last_block_not_found'
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
// Get all full blocks for the slot and checkpoint
|
|
382
|
-
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
383
|
-
if (blocks.length === 0) {
|
|
384
|
-
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
385
|
-
return {
|
|
386
|
-
isValid: false,
|
|
387
|
-
reason: 'no_blocks_for_slot'
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
391
|
-
...proposalInfo,
|
|
392
|
-
blockNumbers: blocks.map((b)=>b.number)
|
|
393
|
-
});
|
|
394
|
-
// Get checkpoint constants from first block
|
|
395
|
-
const firstBlock = blocks[0];
|
|
396
|
-
const constants = this.extractCheckpointConstants(firstBlock);
|
|
397
|
-
const checkpointNumber = firstBlock.checkpointNumber;
|
|
398
|
-
// Get L1-to-L2 messages for this checkpoint
|
|
399
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
400
|
-
// Compute the previous checkpoint out hashes for the epoch.
|
|
401
|
-
// TODO: There can be a more efficient way to get the previous checkpoint out hashes without having to fetch the
|
|
402
|
-
// actual checkpoints and the blocks/txs in them.
|
|
403
|
-
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
404
|
-
const previousCheckpoints = (await this.blockSource.getCheckpointsForEpoch(epoch)).filter((b)=>b.number < checkpointNumber).sort((a, b)=>a.number - b.number);
|
|
405
|
-
const previousCheckpointOutHashes = previousCheckpoints.map((c)=>c.getCheckpointOutHash());
|
|
406
|
-
// Fork world state at the block before the first block
|
|
407
|
-
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
408
|
-
const fork = await this.worldState.fork(parentBlockNumber);
|
|
409
|
-
try {
|
|
410
|
-
// Create checkpoint builder with all existing blocks
|
|
411
|
-
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
|
|
412
|
-
// Complete the checkpoint to get computed values
|
|
413
|
-
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
414
|
-
// Compare checkpoint header with proposal
|
|
415
|
-
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
416
|
-
this.log.warn(`Checkpoint header mismatch`, {
|
|
417
|
-
...proposalInfo,
|
|
418
|
-
computed: computedCheckpoint.header.toInspect(),
|
|
419
|
-
proposal: proposal.checkpointHeader.toInspect()
|
|
420
|
-
});
|
|
421
|
-
return {
|
|
422
|
-
isValid: false,
|
|
423
|
-
reason: 'checkpoint_header_mismatch'
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
// Compare archive root with proposal
|
|
427
|
-
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
428
|
-
this.log.warn(`Archive root mismatch`, {
|
|
429
|
-
...proposalInfo,
|
|
430
|
-
computed: computedCheckpoint.archive.root.toString(),
|
|
431
|
-
proposal: proposal.archive.toString()
|
|
432
|
-
});
|
|
433
|
-
return {
|
|
434
|
-
isValid: false,
|
|
435
|
-
reason: 'archive_mismatch'
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
|
-
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
439
|
-
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
440
|
-
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
441
|
-
const computedEpochOutHash = accumulateCheckpointOutHashes([
|
|
442
|
-
...previousCheckpointOutHashes,
|
|
443
|
-
checkpointOutHash
|
|
444
|
-
]);
|
|
445
|
-
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
446
|
-
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
447
|
-
this.log.warn(`Epoch out hash mismatch`, {
|
|
448
|
-
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
449
|
-
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
450
|
-
checkpointOutHash: checkpointOutHash.toString(),
|
|
451
|
-
previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
|
|
452
|
-
...proposalInfo
|
|
453
|
-
});
|
|
454
|
-
return {
|
|
455
|
-
isValid: false,
|
|
456
|
-
reason: 'out_hash_mismatch'
|
|
457
|
-
};
|
|
458
|
-
}
|
|
459
|
-
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
460
|
-
return {
|
|
461
|
-
isValid: true
|
|
462
|
-
};
|
|
463
|
-
} finally{
|
|
464
|
-
await fork.close();
|
|
397
|
+
// Check if incoming slot is strictly greater than last attested
|
|
398
|
+
if (this.lastAttestedProposal && slotNumber <= this.lastAttestedProposal.slotNumber) {
|
|
399
|
+
this.log.warn(`Refusing to process a proposal for slot ${slotNumber} given we already attested to a proposal for slot ${this.lastAttestedProposal.slotNumber}`);
|
|
400
|
+
return false;
|
|
465
401
|
}
|
|
402
|
+
return true;
|
|
466
403
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
gasFees: gv.gasFees
|
|
478
|
-
};
|
|
404
|
+
async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
|
|
405
|
+
// Equivocation check: must happen right before signing to minimize the race window
|
|
406
|
+
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
407
|
+
return undefined;
|
|
408
|
+
}
|
|
409
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
410
|
+
// Track the proposal we attested to (to prevent equivocation)
|
|
411
|
+
this.lastAttestedProposal = proposal;
|
|
412
|
+
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
413
|
+
return attestations;
|
|
479
414
|
}
|
|
480
415
|
/**
|
|
481
416
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
@@ -492,7 +427,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
492
427
|
return;
|
|
493
428
|
}
|
|
494
429
|
const blobFields = blocks.flatMap((b)=>b.toBlobFields());
|
|
495
|
-
const blobs = getBlobsPerL1Block(blobFields);
|
|
430
|
+
const blobs = await getBlobsPerL1Block(blobFields);
|
|
496
431
|
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
497
432
|
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
498
433
|
...proposalInfo,
|
|
@@ -524,23 +459,75 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
524
459
|
}
|
|
525
460
|
]);
|
|
526
461
|
}
|
|
462
|
+
/**
|
|
463
|
+
* Handle detection of a duplicate proposal (equivocation).
|
|
464
|
+
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
465
|
+
*/ handleDuplicateProposal(info) {
|
|
466
|
+
const { slot, proposer, type } = info;
|
|
467
|
+
this.log.warn(`Triggering slash event for duplicate ${type} proposal from ${proposer.toString()} at slot ${slot}`, {
|
|
468
|
+
proposer: proposer.toString(),
|
|
469
|
+
slot,
|
|
470
|
+
type
|
|
471
|
+
});
|
|
472
|
+
// Emit slash event
|
|
473
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
474
|
+
{
|
|
475
|
+
validator: proposer,
|
|
476
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
477
|
+
offenseType: OffenseType.DUPLICATE_PROPOSAL,
|
|
478
|
+
epochOrSlot: BigInt(slot)
|
|
479
|
+
}
|
|
480
|
+
]);
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Handle detection of a duplicate attestation (equivocation).
|
|
484
|
+
* Emits a slash event when an attester signs attestations for different proposals at the same slot.
|
|
485
|
+
*/ handleDuplicateAttestation(info) {
|
|
486
|
+
const { slot, attester } = info;
|
|
487
|
+
this.log.warn(`Triggering slash event for duplicate attestation from ${attester.toString()} at slot ${slot}`, {
|
|
488
|
+
attester: attester.toString(),
|
|
489
|
+
slot
|
|
490
|
+
});
|
|
491
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
492
|
+
{
|
|
493
|
+
validator: attester,
|
|
494
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
495
|
+
offenseType: OffenseType.DUPLICATE_ATTESTATION,
|
|
496
|
+
epochOrSlot: BigInt(slot)
|
|
497
|
+
}
|
|
498
|
+
]);
|
|
499
|
+
}
|
|
527
500
|
async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
|
|
528
|
-
//
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
501
|
+
// Validate that we're not creating a proposal for an older or equal position
|
|
502
|
+
if (this.lastProposedBlock) {
|
|
503
|
+
const lastSlot = this.lastProposedBlock.slotNumber;
|
|
504
|
+
const lastIndex = this.lastProposedBlock.indexWithinCheckpoint;
|
|
505
|
+
const newSlot = blockHeader.globalVariables.slotNumber;
|
|
506
|
+
if (newSlot < lastSlot || newSlot === lastSlot && indexWithinCheckpoint <= lastIndex) {
|
|
507
|
+
throw new Error(`Cannot create block proposal for slot ${newSlot} index ${indexWithinCheckpoint}: ` + `already proposed block for slot ${lastSlot} index ${lastIndex}`);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
533
510
|
this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
|
|
534
511
|
const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
535
512
|
...options,
|
|
536
513
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
537
514
|
});
|
|
538
|
-
this.
|
|
515
|
+
this.lastProposedBlock = newProposal;
|
|
539
516
|
return newProposal;
|
|
540
517
|
}
|
|
541
|
-
async createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options = {}) {
|
|
518
|
+
async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options = {}) {
|
|
519
|
+
// Validate that we're not creating a proposal for an older or equal slot
|
|
520
|
+
if (this.lastProposedCheckpoint) {
|
|
521
|
+
const lastSlot = this.lastProposedCheckpoint.slotNumber;
|
|
522
|
+
const newSlot = checkpointHeader.slotNumber;
|
|
523
|
+
if (newSlot <= lastSlot) {
|
|
524
|
+
throw new Error(`Cannot create checkpoint proposal for slot ${newSlot}: ` + `already proposed checkpoint for slot ${lastSlot}`);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
542
527
|
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
543
|
-
|
|
528
|
+
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options);
|
|
529
|
+
this.lastProposedCheckpoint = newProposal;
|
|
530
|
+
return newProposal;
|
|
544
531
|
}
|
|
545
532
|
async broadcastBlockProposal(proposal) {
|
|
546
533
|
await this.p2pClient.broadcastProposal(proposal);
|
|
@@ -555,6 +542,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
555
542
|
inCommittee
|
|
556
543
|
});
|
|
557
544
|
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
545
|
+
if (!attestations) {
|
|
546
|
+
return [];
|
|
547
|
+
}
|
|
558
548
|
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
559
549
|
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
560
550
|
// due to inactivity for missed attestations.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/validator-client",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.f1b29a41e",
|
|
4
4
|
"main": "dest/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -64,30 +64,30 @@
|
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@aztec/blob-client": "0.0.1-commit.
|
|
68
|
-
"@aztec/blob-lib": "0.0.1-commit.
|
|
69
|
-
"@aztec/constants": "0.0.1-commit.
|
|
70
|
-
"@aztec/epoch-cache": "0.0.1-commit.
|
|
71
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
72
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
73
|
-
"@aztec/node-keystore": "0.0.1-commit.
|
|
74
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
75
|
-
"@aztec/p2p": "0.0.1-commit.
|
|
76
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
77
|
-
"@aztec/prover-client": "0.0.1-commit.
|
|
78
|
-
"@aztec/simulator": "0.0.1-commit.
|
|
79
|
-
"@aztec/slasher": "0.0.1-commit.
|
|
80
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
81
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
82
|
-
"@aztec/validator-ha-signer": "0.0.1-commit.
|
|
67
|
+
"@aztec/blob-client": "0.0.1-commit.f1b29a41e",
|
|
68
|
+
"@aztec/blob-lib": "0.0.1-commit.f1b29a41e",
|
|
69
|
+
"@aztec/constants": "0.0.1-commit.f1b29a41e",
|
|
70
|
+
"@aztec/epoch-cache": "0.0.1-commit.f1b29a41e",
|
|
71
|
+
"@aztec/ethereum": "0.0.1-commit.f1b29a41e",
|
|
72
|
+
"@aztec/foundation": "0.0.1-commit.f1b29a41e",
|
|
73
|
+
"@aztec/node-keystore": "0.0.1-commit.f1b29a41e",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.f1b29a41e",
|
|
75
|
+
"@aztec/p2p": "0.0.1-commit.f1b29a41e",
|
|
76
|
+
"@aztec/protocol-contracts": "0.0.1-commit.f1b29a41e",
|
|
77
|
+
"@aztec/prover-client": "0.0.1-commit.f1b29a41e",
|
|
78
|
+
"@aztec/simulator": "0.0.1-commit.f1b29a41e",
|
|
79
|
+
"@aztec/slasher": "0.0.1-commit.f1b29a41e",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.f1b29a41e",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.f1b29a41e",
|
|
82
|
+
"@aztec/validator-ha-signer": "0.0.1-commit.f1b29a41e",
|
|
83
83
|
"koa": "^2.16.1",
|
|
84
84
|
"koa-router": "^13.1.1",
|
|
85
85
|
"tslib": "^2.4.0",
|
|
86
86
|
"viem": "npm:@aztec/viem@2.38.2"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
|
-
"@aztec/archiver": "0.0.1-commit.
|
|
90
|
-
"@aztec/world-state": "0.0.1-commit.
|
|
89
|
+
"@aztec/archiver": "0.0.1-commit.f1b29a41e",
|
|
90
|
+
"@aztec/world-state": "0.0.1-commit.f1b29a41e",
|
|
91
91
|
"@electric-sql/pglite": "^0.3.14",
|
|
92
92
|
"@jest/globals": "^30.0.0",
|
|
93
93
|
"@types/jest": "^30.0.0",
|