@aztec/validator-client 0.0.1-commit.e6bd8901 → 0.0.1-commit.ec7ac5448
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 +26 -14
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +136 -45
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +28 -9
- package/dest/duties/validation_service.d.ts +3 -4
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +11 -22
- 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 +12 -3
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +46 -5
- package/dest/proposal_handler.d.ts +107 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/proposal_handler.js +966 -0
- package/dest/validator.d.ts +41 -20
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +183 -199
- package/package.json +19 -17
- package/src/checkpoint_builder.ts +183 -50
- package/src/config.ts +28 -9
- package/src/duties/validation_service.ts +18 -24
- 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 +63 -6
- package/src/proposal_handler.ts +1033 -0
- package/src/validator.ts +248 -229
- 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 -545
- package/dest/tx_validator/index.d.ts +0 -3
- package/dest/tx_validator/index.d.ts.map +0 -1
- package/dest/tx_validator/index.js +0 -2
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -54
- package/src/block_proposal_handler.ts +0 -554
- 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 -135
package/dest/validator.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
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';
|
|
@@ -11,14 +8,14 @@ import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
|
|
|
11
8
|
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
12
9
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
13
10
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
14
|
-
import { createHASigner } from '@aztec/validator-ha-signer/factory';
|
|
11
|
+
import { createHASigner, createLocalSignerWithProtection, createSignerFromSharedDb } from '@aztec/validator-ha-signer/factory';
|
|
15
12
|
import { DutyType } from '@aztec/validator-ha-signer/types';
|
|
16
13
|
import { EventEmitter } from 'events';
|
|
17
|
-
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
18
14
|
import { ValidationService } from './duties/validation_service.js';
|
|
19
15
|
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
20
16
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
21
17
|
import { ValidatorMetrics } from './metrics.js';
|
|
18
|
+
import { ProposalHandler } from './proposal_handler.js';
|
|
22
19
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
23
20
|
// Just cap the set to avoid unbounded growth.
|
|
24
21
|
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
@@ -33,13 +30,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
33
30
|
keyStore;
|
|
34
31
|
epochCache;
|
|
35
32
|
p2pClient;
|
|
36
|
-
|
|
33
|
+
proposalHandler;
|
|
37
34
|
blockSource;
|
|
38
35
|
checkpointsBuilder;
|
|
39
36
|
worldState;
|
|
40
37
|
l1ToL2MessageSource;
|
|
41
38
|
config;
|
|
42
39
|
blobClient;
|
|
40
|
+
slashingProtectionSigner;
|
|
43
41
|
dateProvider;
|
|
44
42
|
tracer;
|
|
45
43
|
validationService;
|
|
@@ -47,17 +45,15 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
47
45
|
log;
|
|
48
46
|
// Whether it has already registered handlers on the p2p client
|
|
49
47
|
hasRegisteredHandlers;
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
/** Tracks the last block proposal we created, to detect duplicate proposal attempts. */ lastProposedBlock;
|
|
49
|
+
/** Tracks the last checkpoint proposal we created. */ lastProposedCheckpoint;
|
|
52
50
|
lastEpochForCommitteeUpdateLoop;
|
|
53
51
|
epochCacheUpdateLoop;
|
|
52
|
+
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */ lastAttestedEpochByAttester;
|
|
54
53
|
proposersOfInvalidBlocks;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
validatedBlockSlots;
|
|
59
|
-
constructor(keyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
60
|
-
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.blockProposalHandler = blockProposalHandler, this.blockSource = blockSource, this.checkpointsBuilder = checkpointsBuilder, this.worldState = worldState, this.l1ToL2MessageSource = l1ToL2MessageSource, this.config = config, this.blobClient = blobClient, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.proposersOfInvalidBlocks = new Set(), this.validatedBlockSlots = new Set();
|
|
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();
|
|
61
57
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
62
58
|
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
63
59
|
this.tracer = telemetry.getTracer('Validator');
|
|
@@ -96,6 +92,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
96
92
|
this.log.trace(`No committee found for slot`);
|
|
97
93
|
return;
|
|
98
94
|
}
|
|
95
|
+
this.metrics.setCurrentEpoch(epoch);
|
|
99
96
|
if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
|
|
100
97
|
const me = this.getValidatorAddresses();
|
|
101
98
|
const committeeSet = new Set(committee.map((v)=>v.toString()));
|
|
@@ -111,30 +108,49 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
111
108
|
this.log.error(`Error updating epoch committee`, err);
|
|
112
109
|
}
|
|
113
110
|
}
|
|
114
|
-
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) {
|
|
115
112
|
const metrics = new ValidatorMetrics(telemetry);
|
|
116
113
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
117
|
-
txsPermitted: !config.disableTransactions
|
|
114
|
+
txsPermitted: !config.disableTransactions,
|
|
115
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock
|
|
118
116
|
});
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
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.
|
|
122
128
|
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
123
129
|
const haConfig = {
|
|
124
130
|
...config,
|
|
125
131
|
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000
|
|
126
132
|
};
|
|
127
|
-
|
|
128
|
-
|
|
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
|
+
}));
|
|
129
144
|
}
|
|
130
|
-
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);
|
|
131
147
|
return validator;
|
|
132
148
|
}
|
|
133
149
|
getValidatorAddresses() {
|
|
134
150
|
return this.keyStore.getAddresses().filter((addr)=>!this.config.disabledValidators.some((disabled)=>disabled.equals(addr)));
|
|
135
151
|
}
|
|
136
|
-
|
|
137
|
-
return this.
|
|
152
|
+
getProposalHandler() {
|
|
153
|
+
return this.proposalHandler;
|
|
138
154
|
}
|
|
139
155
|
signWithAddress(addr, msg, context) {
|
|
140
156
|
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
@@ -154,6 +170,11 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
154
170
|
...config
|
|
155
171
|
};
|
|
156
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
|
+
}
|
|
157
178
|
async start() {
|
|
158
179
|
if (this.epochCacheUpdateLoop.isRunning()) {
|
|
159
180
|
this.log.warn(`Validator client already started`);
|
|
@@ -185,7 +206,15 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
185
206
|
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
186
207
|
// and processed separately via the block handler above.
|
|
187
208
|
const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
188
|
-
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
|
+
});
|
|
189
218
|
const myAddresses = this.getValidatorAddresses();
|
|
190
219
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
191
220
|
await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
|
|
@@ -206,6 +235,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
206
235
|
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
207
236
|
return false;
|
|
208
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
|
+
}
|
|
209
245
|
// Check if we're in the committee (for metrics purposes)
|
|
210
246
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
211
247
|
const partOfCommittee = inCommittee.length > 0;
|
|
@@ -220,12 +256,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
220
256
|
});
|
|
221
257
|
// Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
|
|
222
258
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
223
|
-
const {
|
|
224
|
-
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n
|
|
225
|
-
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);
|
|
226
262
|
if (!validationResult.isValid) {
|
|
227
|
-
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
228
263
|
const reason = validationResult.reason || 'unknown';
|
|
264
|
+
this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
|
|
229
265
|
// Classify failure reason: bad proposal vs node issue
|
|
230
266
|
const badProposalReasons = [
|
|
231
267
|
'invalid_proposal',
|
|
@@ -257,9 +293,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
257
293
|
this.log.warn(`Escape hatch open for slot ${slotNumber}, rejecting block proposal`, proposalInfo);
|
|
258
294
|
return false;
|
|
259
295
|
}
|
|
260
|
-
// TODO(palla/mbps): Remove this once checkpoint validation is stable.
|
|
261
|
-
// Track that we successfully validated a block for this slot, so we can attest to checkpoint proposals for it.
|
|
262
|
-
this.validatedBlockSlots.add(slotNumber);
|
|
263
296
|
return true;
|
|
264
297
|
}
|
|
265
298
|
/**
|
|
@@ -268,53 +301,44 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
268
301
|
* the lastBlock is extracted and processed separately via the block handler.
|
|
269
302
|
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
270
303
|
*/ async attestToCheckpointProposal(proposal, _proposalSender) {
|
|
271
|
-
const
|
|
304
|
+
const proposalSlotNumber = proposal.slotNumber;
|
|
272
305
|
const proposer = proposal.getSender();
|
|
273
306
|
// If escape hatch is open for this slot's epoch, do not attest.
|
|
274
|
-
if (await this.epochCache.isEscapeHatchOpenAtSlot(
|
|
275
|
-
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`);
|
|
276
309
|
return undefined;
|
|
277
310
|
}
|
|
278
|
-
//
|
|
279
|
-
if (
|
|
280
|
-
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
|
+
});
|
|
281
317
|
return undefined;
|
|
282
318
|
}
|
|
283
|
-
// Check that I have any address in
|
|
284
|
-
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());
|
|
285
321
|
const partOfCommittee = inCommittee.length > 0;
|
|
286
322
|
const proposalInfo = {
|
|
287
|
-
|
|
323
|
+
proposalSlotNumber,
|
|
288
324
|
archive: proposal.archive.toString(),
|
|
289
|
-
proposer: proposer
|
|
290
|
-
txCount: proposal.txHashes.length
|
|
325
|
+
proposer: proposer?.toString()
|
|
291
326
|
};
|
|
292
|
-
this.log.info(`Received checkpoint proposal for slot ${
|
|
327
|
+
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
293
328
|
...proposalInfo,
|
|
294
|
-
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
295
329
|
fishermanMode: this.config.fishermanMode || false
|
|
296
330
|
});
|
|
297
|
-
//
|
|
298
|
-
//
|
|
299
|
-
if (
|
|
300
|
-
this.log.warn(`
|
|
301
|
-
return undefined;
|
|
302
|
-
}
|
|
303
|
-
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
304
|
-
// TODO(palla/mbps): Change default to false once checkpoint validation is stable.
|
|
305
|
-
if (this.config.skipCheckpointProposalValidation !== false) {
|
|
306
|
-
this.log.verbose(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
|
|
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).
|
|
333
|
+
if (this.config.skipCheckpointProposalValidation) {
|
|
334
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
307
335
|
} else {
|
|
308
|
-
const validationResult = await this.
|
|
336
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
309
337
|
if (!validationResult.isValid) {
|
|
310
338
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
311
339
|
return undefined;
|
|
312
340
|
}
|
|
313
341
|
}
|
|
314
|
-
// Upload blobs to filestore if we can (fire and forget)
|
|
315
|
-
if (this.blobClient.canUpload()) {
|
|
316
|
-
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
317
|
-
}
|
|
318
342
|
// Check that I have any address in current committee before attesting
|
|
319
343
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
320
344
|
if (!partOfCommittee && !this.config.fishermanMode) {
|
|
@@ -322,12 +346,22 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
322
346
|
return undefined;
|
|
323
347
|
}
|
|
324
348
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
325
|
-
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${
|
|
349
|
+
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
326
350
|
...proposalInfo,
|
|
327
351
|
inCommittee: partOfCommittee,
|
|
328
352
|
fishermanMode: this.config.fishermanMode || false
|
|
329
353
|
});
|
|
330
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
|
+
}
|
|
331
365
|
// Determine which validators should attest
|
|
332
366
|
let attestors;
|
|
333
367
|
if (partOfCommittee) {
|
|
@@ -344,144 +378,39 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
344
378
|
}
|
|
345
379
|
if (this.config.fishermanMode) {
|
|
346
380
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
347
|
-
this.log.info(`Creating checkpoint attestations for slot ${
|
|
381
|
+
this.log.info(`Creating checkpoint attestations for slot ${proposalSlotNumber}`, {
|
|
348
382
|
...proposalInfo,
|
|
349
383
|
attestors: attestors.map((a)=>a.toString())
|
|
350
384
|
});
|
|
351
385
|
return undefined;
|
|
352
386
|
}
|
|
353
|
-
return this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
354
|
-
}
|
|
355
|
-
async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
|
|
356
|
-
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
357
|
-
await this.p2pClient.addCheckpointAttestations(attestations);
|
|
358
|
-
return attestations;
|
|
387
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
359
388
|
}
|
|
360
389
|
/**
|
|
361
|
-
*
|
|
362
|
-
* @returns
|
|
363
|
-
*/
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
let lastBlockHeader;
|
|
368
|
-
try {
|
|
369
|
-
lastBlockHeader = await retryUntil(async ()=>{
|
|
370
|
-
await this.blockSource.syncImmediate();
|
|
371
|
-
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
372
|
-
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, timeoutSeconds, 0.5);
|
|
373
|
-
} catch (err) {
|
|
374
|
-
if (err instanceof TimeoutError) {
|
|
375
|
-
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
376
|
-
return {
|
|
377
|
-
isValid: false,
|
|
378
|
-
reason: 'last_block_not_found'
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
382
|
-
return {
|
|
383
|
-
isValid: false,
|
|
384
|
-
reason: 'block_fetch_error'
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
if (!lastBlockHeader) {
|
|
388
|
-
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
389
|
-
return {
|
|
390
|
-
isValid: false,
|
|
391
|
-
reason: 'last_block_not_found'
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
// Get all full blocks for the slot and checkpoint
|
|
395
|
-
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
396
|
-
if (blocks.length === 0) {
|
|
397
|
-
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
398
|
-
return {
|
|
399
|
-
isValid: false,
|
|
400
|
-
reason: 'no_blocks_for_slot'
|
|
401
|
-
};
|
|
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;
|
|
402
396
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
// Get checkpoint constants from first block
|
|
408
|
-
const firstBlock = blocks[0];
|
|
409
|
-
const constants = this.extractCheckpointConstants(firstBlock);
|
|
410
|
-
const checkpointNumber = firstBlock.checkpointNumber;
|
|
411
|
-
// Get L1-to-L2 messages for this checkpoint
|
|
412
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
413
|
-
// Compute the previous checkpoint out hashes for the epoch.
|
|
414
|
-
// TODO: There can be a more efficient way to get the previous checkpoint out hashes without having to fetch the
|
|
415
|
-
// actual checkpoints and the blocks/txs in them.
|
|
416
|
-
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
417
|
-
const previousCheckpoints = (await this.blockSource.getCheckpointsForEpoch(epoch)).filter((b)=>b.number < checkpointNumber).sort((a, b)=>a.number - b.number);
|
|
418
|
-
const previousCheckpointOutHashes = previousCheckpoints.map((c)=>c.getCheckpointOutHash());
|
|
419
|
-
// Fork world state at the block before the first block
|
|
420
|
-
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
421
|
-
const fork = await this.worldState.fork(parentBlockNumber);
|
|
422
|
-
try {
|
|
423
|
-
// Create checkpoint builder with all existing blocks
|
|
424
|
-
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks);
|
|
425
|
-
// Complete the checkpoint to get computed values
|
|
426
|
-
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
427
|
-
// Compare checkpoint header with proposal
|
|
428
|
-
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
429
|
-
this.log.warn(`Checkpoint header mismatch`, {
|
|
430
|
-
...proposalInfo,
|
|
431
|
-
computed: computedCheckpoint.header.toInspect(),
|
|
432
|
-
proposal: proposal.checkpointHeader.toInspect()
|
|
433
|
-
});
|
|
434
|
-
return {
|
|
435
|
-
isValid: false,
|
|
436
|
-
reason: 'checkpoint_header_mismatch'
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
// Compare archive root with proposal
|
|
440
|
-
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
441
|
-
this.log.warn(`Archive root mismatch`, {
|
|
442
|
-
...proposalInfo,
|
|
443
|
-
computed: computedCheckpoint.archive.root.toString(),
|
|
444
|
-
proposal: proposal.archive.toString()
|
|
445
|
-
});
|
|
446
|
-
return {
|
|
447
|
-
isValid: false,
|
|
448
|
-
reason: 'archive_mismatch'
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
// Check that the accumulated out hash matches the value in the proposal.
|
|
452
|
-
const computedOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
453
|
-
const proposalOutHash = proposal.checkpointHeader.epochOutHash;
|
|
454
|
-
if (!computedOutHash.equals(proposalOutHash)) {
|
|
455
|
-
this.log.warn(`Epoch out hash mismatch`, {
|
|
456
|
-
proposalOutHash: proposalOutHash.toString(),
|
|
457
|
-
computedOutHash: computedOutHash.toString(),
|
|
458
|
-
...proposalInfo
|
|
459
|
-
});
|
|
460
|
-
return {
|
|
461
|
-
isValid: false,
|
|
462
|
-
reason: 'out_hash_mismatch'
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
466
|
-
return {
|
|
467
|
-
isValid: true
|
|
468
|
-
};
|
|
469
|
-
} finally{
|
|
470
|
-
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;
|
|
471
401
|
}
|
|
402
|
+
return true;
|
|
472
403
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
gasFees: gv.gasFees
|
|
484
|
-
};
|
|
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;
|
|
485
414
|
}
|
|
486
415
|
/**
|
|
487
416
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
@@ -498,7 +427,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
498
427
|
return;
|
|
499
428
|
}
|
|
500
429
|
const blobFields = blocks.flatMap((b)=>b.toBlobFields());
|
|
501
|
-
const blobs = getBlobsPerL1Block(blobFields);
|
|
430
|
+
const blobs = await getBlobsPerL1Block(blobFields);
|
|
502
431
|
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
503
432
|
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
504
433
|
...proposalInfo,
|
|
@@ -530,23 +459,75 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
530
459
|
}
|
|
531
460
|
]);
|
|
532
461
|
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
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
|
+
}
|
|
500
|
+
async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
|
|
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
|
+
}
|
|
539
510
|
this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
|
|
540
511
|
const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
541
512
|
...options,
|
|
542
513
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
543
514
|
});
|
|
544
|
-
this.
|
|
515
|
+
this.lastProposedBlock = newProposal;
|
|
545
516
|
return newProposal;
|
|
546
517
|
}
|
|
547
|
-
async createCheckpointProposal(checkpointHeader, archive,
|
|
518
|
+
async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockProposal, 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
|
+
}
|
|
548
527
|
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
549
|
-
|
|
528
|
+
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options);
|
|
529
|
+
this.lastProposedCheckpoint = newProposal;
|
|
530
|
+
return newProposal;
|
|
550
531
|
}
|
|
551
532
|
async broadcastBlockProposal(proposal) {
|
|
552
533
|
await this.p2pClient.broadcastProposal(proposal);
|
|
@@ -561,6 +542,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
561
542
|
inCommittee
|
|
562
543
|
});
|
|
563
544
|
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
545
|
+
if (!attestations) {
|
|
546
|
+
return [];
|
|
547
|
+
}
|
|
564
548
|
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
565
549
|
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
566
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.ec7ac5448",
|
|
4
4
|
"main": "dest/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -64,28 +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.ec7ac5448",
|
|
68
|
+
"@aztec/blob-lib": "0.0.1-commit.ec7ac5448",
|
|
69
|
+
"@aztec/constants": "0.0.1-commit.ec7ac5448",
|
|
70
|
+
"@aztec/epoch-cache": "0.0.1-commit.ec7ac5448",
|
|
71
|
+
"@aztec/ethereum": "0.0.1-commit.ec7ac5448",
|
|
72
|
+
"@aztec/foundation": "0.0.1-commit.ec7ac5448",
|
|
73
|
+
"@aztec/node-keystore": "0.0.1-commit.ec7ac5448",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.ec7ac5448",
|
|
75
|
+
"@aztec/p2p": "0.0.1-commit.ec7ac5448",
|
|
76
|
+
"@aztec/protocol-contracts": "0.0.1-commit.ec7ac5448",
|
|
77
|
+
"@aztec/prover-client": "0.0.1-commit.ec7ac5448",
|
|
78
|
+
"@aztec/simulator": "0.0.1-commit.ec7ac5448",
|
|
79
|
+
"@aztec/slasher": "0.0.1-commit.ec7ac5448",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.ec7ac5448",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.ec7ac5448",
|
|
82
|
+
"@aztec/validator-ha-signer": "0.0.1-commit.ec7ac5448",
|
|
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.ec7ac5448",
|
|
90
|
+
"@aztec/world-state": "0.0.1-commit.ec7ac5448",
|
|
89
91
|
"@electric-sql/pglite": "^0.3.14",
|
|
90
92
|
"@jest/globals": "^30.0.0",
|
|
91
93
|
"@types/jest": "^30.0.0",
|