@aztec/validator-client 0.0.1-commit.934299a21 → 0.0.1-commit.949a33fd8
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 +41 -2
- package/dest/checkpoint_builder.d.ts +14 -4
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +101 -30
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +29 -7
- package/dest/duties/validation_service.d.ts +11 -12
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +27 -45
- package/dest/factory.d.ts +7 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +10 -5
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/key_store/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 +108 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/proposal_handler.js +974 -0
- package/dest/validator.d.ts +19 -21
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +99 -232
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +124 -35
- package/src/config.ts +29 -6
- package/src/duties/validation_service.ts +46 -53
- package/src/factory.ts +14 -3
- package/src/index.ts +1 -1
- package/src/key_store/ha_key_store.ts +1 -1
- package/src/metrics.ts +37 -1
- package/src/proposal_handler.ts +1042 -0
- package/src/validator.ts +144 -264
- 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/src/block_proposal_handler.ts +0 -535
package/dest/validator.js
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
import { getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
2
|
-
import {
|
|
3
|
-
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
|
-
import { TimeoutError } from '@aztec/foundation/error';
|
|
2
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
5
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
7
4
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
8
5
|
import { sleep } from '@aztec/foundation/sleep';
|
|
9
6
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
10
7
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
11
8
|
import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
|
|
12
|
-
import { getEpochAtSlot
|
|
13
|
-
import { accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
|
|
9
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
14
10
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
15
11
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
16
|
-
import { createHASigner } from '@aztec/validator-ha-signer/factory';
|
|
12
|
+
import { createHASigner, createLocalSignerWithProtection, createSignerFromSharedDb } from '@aztec/validator-ha-signer/factory';
|
|
17
13
|
import { DutyType } from '@aztec/validator-ha-signer/types';
|
|
18
14
|
import { EventEmitter } from 'events';
|
|
19
|
-
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
20
15
|
import { ValidationService } from './duties/validation_service.js';
|
|
21
16
|
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
22
17
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
23
18
|
import { ValidatorMetrics } from './metrics.js';
|
|
19
|
+
import { ProposalHandler } from './proposal_handler.js';
|
|
24
20
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
25
21
|
// Just cap the set to avoid unbounded growth.
|
|
26
22
|
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
@@ -35,14 +31,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
35
31
|
keyStore;
|
|
36
32
|
epochCache;
|
|
37
33
|
p2pClient;
|
|
38
|
-
|
|
34
|
+
proposalHandler;
|
|
39
35
|
blockSource;
|
|
40
36
|
checkpointsBuilder;
|
|
41
37
|
worldState;
|
|
42
38
|
l1ToL2MessageSource;
|
|
43
39
|
config;
|
|
44
40
|
blobClient;
|
|
45
|
-
|
|
41
|
+
slashingProtectionSigner;
|
|
46
42
|
dateProvider;
|
|
47
43
|
tracer;
|
|
48
44
|
validationService;
|
|
@@ -54,15 +50,16 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
54
50
|
/** Tracks the last checkpoint proposal we created. */ lastProposedCheckpoint;
|
|
55
51
|
lastEpochForCommitteeUpdateLoop;
|
|
56
52
|
epochCacheUpdateLoop;
|
|
53
|
+
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */ lastAttestedEpochByAttester;
|
|
57
54
|
proposersOfInvalidBlocks;
|
|
58
55
|
/** 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.
|
|
56
|
+
constructor(keyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
57
|
+
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
58
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
62
59
|
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
63
60
|
this.tracer = telemetry.getTracer('Validator');
|
|
64
61
|
this.metrics = new ValidatorMetrics(telemetry);
|
|
65
|
-
this.validationService = new ValidationService(keyStore, this.log.createChild('validation-service'));
|
|
62
|
+
this.validationService = new ValidationService(keyStore, this.getSignatureContext(), this.log.createChild('validation-service'));
|
|
66
63
|
// Refresh epoch cache every second to trigger alert if participation in committee changes
|
|
67
64
|
this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), this.log, 1000);
|
|
68
65
|
const myAddresses = this.getValidatorAddresses();
|
|
@@ -96,6 +93,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
96
93
|
this.log.trace(`No committee found for slot`);
|
|
97
94
|
return;
|
|
98
95
|
}
|
|
96
|
+
this.metrics.setCurrentEpoch(epoch);
|
|
99
97
|
if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
|
|
100
98
|
const me = this.getValidatorAddresses();
|
|
101
99
|
const committeeSet = new Set(committee.map((v)=>v.toString()));
|
|
@@ -111,40 +109,63 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
111
109
|
this.log.error(`Error updating epoch committee`, err);
|
|
112
110
|
}
|
|
113
111
|
}
|
|
114
|
-
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
112
|
+
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), slashingProtectionDb) {
|
|
115
113
|
const metrics = new ValidatorMetrics(telemetry);
|
|
116
114
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
117
|
-
txsPermitted: !config.disableTransactions
|
|
115
|
+
txsPermitted: !config.disableTransactions,
|
|
116
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock,
|
|
117
|
+
signatureContext: {
|
|
118
|
+
chainId: config.l1ChainId,
|
|
119
|
+
rollupAddress: config.l1Contracts.rollupAddress
|
|
120
|
+
}
|
|
118
121
|
});
|
|
119
|
-
const
|
|
122
|
+
const proposalHandler = new ProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, blobClient, metrics, dateProvider, telemetry, undefined);
|
|
120
123
|
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
121
|
-
let
|
|
122
|
-
|
|
123
|
-
|
|
124
|
+
let slashingProtectionSigner;
|
|
125
|
+
if (slashingProtectionDb) {
|
|
126
|
+
// Shared database mode: use a pre-existing database (e.g. for testing HA setups).
|
|
127
|
+
({ signer: slashingProtectionSigner } = createSignerFromSharedDb(slashingProtectionDb, config, {
|
|
128
|
+
telemetryClient: telemetry,
|
|
129
|
+
dateProvider
|
|
130
|
+
}));
|
|
131
|
+
} else if (config.haSigningEnabled) {
|
|
132
|
+
// Multi-node HA mode: use PostgreSQL-backed distributed locking.
|
|
124
133
|
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
125
134
|
const haConfig = {
|
|
126
135
|
...config,
|
|
127
136
|
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000
|
|
128
137
|
};
|
|
129
|
-
|
|
138
|
+
({ signer: slashingProtectionSigner } = await createHASigner(haConfig, {
|
|
130
139
|
telemetryClient: telemetry,
|
|
131
140
|
dateProvider
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
|
|
141
|
+
}));
|
|
142
|
+
} else {
|
|
143
|
+
// Single-node mode: use LMDB-backed local signing protection.
|
|
144
|
+
// This prevents double-signing if the node crashes and restarts mid-proposal.
|
|
145
|
+
({ signer: slashingProtectionSigner } = await createLocalSignerWithProtection(config, {
|
|
146
|
+
telemetryClient: telemetry,
|
|
147
|
+
dateProvider
|
|
148
|
+
}));
|
|
135
149
|
}
|
|
136
|
-
const
|
|
150
|
+
const validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, slashingProtectionSigner);
|
|
151
|
+
const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider, telemetry);
|
|
137
152
|
return validator;
|
|
138
153
|
}
|
|
139
154
|
getValidatorAddresses() {
|
|
140
155
|
return this.keyStore.getAddresses().filter((addr)=>!this.config.disabledValidators.some((disabled)=>disabled.equals(addr)));
|
|
141
156
|
}
|
|
142
|
-
|
|
143
|
-
return this.
|
|
157
|
+
getProposalHandler() {
|
|
158
|
+
return this.proposalHandler;
|
|
144
159
|
}
|
|
145
160
|
signWithAddress(addr, msg, context) {
|
|
146
161
|
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
147
162
|
}
|
|
163
|
+
getSignatureContext() {
|
|
164
|
+
return {
|
|
165
|
+
chainId: this.config.l1ChainId,
|
|
166
|
+
rollupAddress: this.config.l1Contracts.rollupAddress
|
|
167
|
+
};
|
|
168
|
+
}
|
|
148
169
|
getCoinbaseForAttestor(attestor) {
|
|
149
170
|
return this.keyStore.getCoinbaseAddress(attestor);
|
|
150
171
|
}
|
|
@@ -161,18 +182,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
161
182
|
};
|
|
162
183
|
}
|
|
163
184
|
reloadKeystore(newManager) {
|
|
164
|
-
if (this.config.haSigningEnabled && !this.haSigner) {
|
|
165
|
-
this.log.warn('HA signing is enabled in config but was not initialized at startup. ' + 'Restart the node to enable HA signing.');
|
|
166
|
-
} else if (!this.config.haSigningEnabled && this.haSigner) {
|
|
167
|
-
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.');
|
|
168
|
-
}
|
|
169
185
|
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
} else {
|
|
173
|
-
this.keyStore = newAdapter;
|
|
174
|
-
}
|
|
175
|
-
this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
|
|
186
|
+
this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
|
|
187
|
+
this.validationService = new ValidationService(this.keyStore, this.getSignatureContext(), this.log.createChild('validation-service'));
|
|
176
188
|
}
|
|
177
189
|
async start() {
|
|
178
190
|
if (this.epochCacheUpdateLoop.isRunning()) {
|
|
@@ -205,7 +217,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
205
217
|
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
206
218
|
// and processed separately via the block handler above.
|
|
207
219
|
const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
208
|
-
this.p2pClient.
|
|
220
|
+
this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
|
|
209
221
|
// Duplicate proposal handler - triggers slashing for equivocation
|
|
210
222
|
this.p2pClient.registerDuplicateProposalCallback((info)=>{
|
|
211
223
|
this.handleDuplicateProposal(info);
|
|
@@ -234,13 +246,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
234
246
|
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
235
247
|
return false;
|
|
236
248
|
}
|
|
237
|
-
//
|
|
249
|
+
// Log self-proposals from HA peers (same validator key on different nodes)
|
|
238
250
|
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
239
|
-
this.log.
|
|
251
|
+
this.log.verbose(`Processing block proposal from HA peer for slot ${slotNumber}`, {
|
|
240
252
|
proposer: proposer.toString(),
|
|
241
253
|
slotNumber
|
|
242
254
|
});
|
|
243
|
-
return false;
|
|
244
255
|
}
|
|
245
256
|
// Check if we're in the committee (for metrics purposes)
|
|
246
257
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
@@ -256,12 +267,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
256
267
|
});
|
|
257
268
|
// Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
|
|
258
269
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
259
|
-
const {
|
|
260
|
-
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n
|
|
261
|
-
const validationResult = await this.
|
|
270
|
+
const { slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
271
|
+
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n || partOfCommittee || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
|
|
272
|
+
const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
|
|
262
273
|
if (!validationResult.isValid) {
|
|
263
|
-
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
264
274
|
const reason = validationResult.reason || 'unknown';
|
|
275
|
+
this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
|
|
265
276
|
// Classify failure reason: bad proposal vs node issue
|
|
266
277
|
const badProposalReasons = [
|
|
267
278
|
'invalid_proposal',
|
|
@@ -301,58 +312,46 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
301
312
|
* the lastBlock is extracted and processed separately via the block handler.
|
|
302
313
|
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
303
314
|
*/ async attestToCheckpointProposal(proposal, _proposalSender) {
|
|
304
|
-
const
|
|
315
|
+
const proposalSlotNumber = proposal.slotNumber;
|
|
305
316
|
const proposer = proposal.getSender();
|
|
306
317
|
// If escape hatch is open for this slot's epoch, do not attest.
|
|
307
|
-
if (await this.epochCache.isEscapeHatchOpenAtSlot(
|
|
308
|
-
this.log.warn(`Escape hatch open for slot ${
|
|
309
|
-
return undefined;
|
|
310
|
-
}
|
|
311
|
-
// Reject proposals with invalid signatures
|
|
312
|
-
if (!proposer) {
|
|
313
|
-
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
318
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(proposalSlotNumber)) {
|
|
319
|
+
this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
|
|
314
320
|
return undefined;
|
|
315
321
|
}
|
|
316
322
|
// Ignore proposals from ourselves (may happen in HA setups)
|
|
317
|
-
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
318
|
-
this.log.
|
|
323
|
+
if (proposer && this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
324
|
+
this.log.debug(`Ignoring block proposal from self for slot ${proposalSlotNumber}`, {
|
|
319
325
|
proposer: proposer.toString(),
|
|
320
|
-
|
|
326
|
+
proposalSlotNumber
|
|
321
327
|
});
|
|
322
328
|
return undefined;
|
|
323
329
|
}
|
|
324
|
-
//
|
|
325
|
-
|
|
326
|
-
this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`);
|
|
327
|
-
return undefined;
|
|
328
|
-
}
|
|
329
|
-
// Check that I have any address in current committee before attesting
|
|
330
|
-
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
330
|
+
// Check that I have any address in the committee where this checkpoint will land before attesting
|
|
331
|
+
const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
|
|
331
332
|
const partOfCommittee = inCommittee.length > 0;
|
|
332
333
|
const proposalInfo = {
|
|
333
|
-
|
|
334
|
+
proposalSlotNumber,
|
|
334
335
|
archive: proposal.archive.toString(),
|
|
335
|
-
proposer: proposer
|
|
336
|
-
txCount: proposal.txHashes.length
|
|
336
|
+
proposer: proposer?.toString()
|
|
337
337
|
};
|
|
338
|
-
this.log.info(`Received checkpoint proposal for slot ${
|
|
338
|
+
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
339
339
|
...proposalInfo,
|
|
340
|
-
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
341
340
|
fishermanMode: this.config.fishermanMode || false
|
|
342
341
|
});
|
|
343
|
-
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
342
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
|
|
343
|
+
// Uses the cached result from the all-nodes callback if available (avoids double validation).
|
|
344
|
+
let checkpointNumber;
|
|
344
345
|
if (this.config.skipCheckpointProposalValidation) {
|
|
345
|
-
this.log.warn(`Skipping checkpoint proposal validation for slot ${
|
|
346
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
347
|
+
checkpointNumber = CheckpointNumber(0);
|
|
346
348
|
} else {
|
|
347
|
-
const validationResult = await this.
|
|
349
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
348
350
|
if (!validationResult.isValid) {
|
|
349
351
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
350
352
|
return undefined;
|
|
351
353
|
}
|
|
352
|
-
|
|
353
|
-
// Upload blobs to filestore if we can (fire and forget)
|
|
354
|
-
if (this.blobClient.canUpload()) {
|
|
355
|
-
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
354
|
+
checkpointNumber = validationResult.checkpointNumber;
|
|
356
355
|
}
|
|
357
356
|
// Check that I have any address in current committee before attesting
|
|
358
357
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
@@ -361,12 +360,22 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
361
360
|
return undefined;
|
|
362
361
|
}
|
|
363
362
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
364
|
-
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${
|
|
363
|
+
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
365
364
|
...proposalInfo,
|
|
366
365
|
inCommittee: partOfCommittee,
|
|
367
366
|
fishermanMode: this.config.fishermanMode || false
|
|
368
367
|
});
|
|
369
368
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
369
|
+
// Track epoch participation per attester: count each (attester, epoch) pair at most once
|
|
370
|
+
const proposalEpoch = getEpochAtSlot(proposalSlotNumber, this.epochCache.getL1Constants());
|
|
371
|
+
for (const attester of inCommittee){
|
|
372
|
+
const key = attester.toString();
|
|
373
|
+
const lastEpoch = this.lastAttestedEpochByAttester.get(key);
|
|
374
|
+
if (lastEpoch === undefined || proposalEpoch > lastEpoch) {
|
|
375
|
+
this.lastAttestedEpochByAttester.set(key, proposalEpoch);
|
|
376
|
+
this.metrics.incAttestedEpochCount(attester);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
370
379
|
// Determine which validators should attest
|
|
371
380
|
let attestors;
|
|
372
381
|
if (partOfCommittee) {
|
|
@@ -383,13 +392,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
383
392
|
}
|
|
384
393
|
if (this.config.fishermanMode) {
|
|
385
394
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
386
|
-
this.log.info(`Creating checkpoint attestations for slot ${
|
|
395
|
+
this.log.info(`Creating checkpoint attestations for slot ${proposalSlotNumber}`, {
|
|
387
396
|
...proposalInfo,
|
|
388
397
|
attestors: attestors.map((a)=>a.toString())
|
|
389
398
|
});
|
|
390
399
|
return undefined;
|
|
391
400
|
}
|
|
392
|
-
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
401
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
|
|
393
402
|
}
|
|
394
403
|
/**
|
|
395
404
|
* Checks if we should attest to a slot based on equivocation prevention rules.
|
|
@@ -406,160 +415,18 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
406
415
|
}
|
|
407
416
|
return true;
|
|
408
417
|
}
|
|
409
|
-
async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
|
|
418
|
+
async createCheckpointAttestationsFromProposal(proposal, attestors = [], checkpointNumber) {
|
|
410
419
|
// Equivocation check: must happen right before signing to minimize the race window
|
|
411
420
|
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
412
421
|
return undefined;
|
|
413
422
|
}
|
|
414
|
-
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
423
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
|
|
415
424
|
// Track the proposal we attested to (to prevent equivocation)
|
|
416
425
|
this.lastAttestedProposal = proposal;
|
|
417
426
|
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
418
427
|
return attestations;
|
|
419
428
|
}
|
|
420
429
|
/**
|
|
421
|
-
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
422
|
-
* @returns Validation result with isValid flag and reason if invalid.
|
|
423
|
-
*/ async validateCheckpointProposal(proposal, proposalInfo) {
|
|
424
|
-
const slot = proposal.slotNumber;
|
|
425
|
-
// Timeout block syncing at the start of the next slot
|
|
426
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
427
|
-
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
|
|
428
|
-
const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
|
|
429
|
-
// Wait for last block to sync by archive
|
|
430
|
-
let lastBlockHeader;
|
|
431
|
-
try {
|
|
432
|
-
lastBlockHeader = await retryUntil(async ()=>{
|
|
433
|
-
await this.blockSource.syncImmediate();
|
|
434
|
-
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
435
|
-
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, timeoutSeconds, 0.5);
|
|
436
|
-
} catch (err) {
|
|
437
|
-
if (err instanceof TimeoutError) {
|
|
438
|
-
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
439
|
-
return {
|
|
440
|
-
isValid: false,
|
|
441
|
-
reason: 'last_block_not_found'
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
445
|
-
return {
|
|
446
|
-
isValid: false,
|
|
447
|
-
reason: 'block_fetch_error'
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
if (!lastBlockHeader) {
|
|
451
|
-
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
452
|
-
return {
|
|
453
|
-
isValid: false,
|
|
454
|
-
reason: 'last_block_not_found'
|
|
455
|
-
};
|
|
456
|
-
}
|
|
457
|
-
// Get all full blocks for the slot and checkpoint
|
|
458
|
-
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
459
|
-
if (blocks.length === 0) {
|
|
460
|
-
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
461
|
-
return {
|
|
462
|
-
isValid: false,
|
|
463
|
-
reason: 'no_blocks_for_slot'
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
467
|
-
if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
|
|
468
|
-
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
469
|
-
return {
|
|
470
|
-
isValid: false,
|
|
471
|
-
reason: 'last_block_archive_mismatch'
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
475
|
-
...proposalInfo,
|
|
476
|
-
blockNumbers: blocks.map((b)=>b.number)
|
|
477
|
-
});
|
|
478
|
-
// Get checkpoint constants from first block
|
|
479
|
-
const firstBlock = blocks[0];
|
|
480
|
-
const constants = this.extractCheckpointConstants(firstBlock);
|
|
481
|
-
const checkpointNumber = firstBlock.checkpointNumber;
|
|
482
|
-
// Get L1-to-L2 messages for this checkpoint
|
|
483
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
484
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
485
|
-
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
486
|
-
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch)).filter((c)=>c.checkpointNumber < checkpointNumber).map((c)=>c.checkpointOutHash);
|
|
487
|
-
// Fork world state at the block before the first block
|
|
488
|
-
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
489
|
-
const fork = await this.worldState.fork(parentBlockNumber);
|
|
490
|
-
try {
|
|
491
|
-
// Create checkpoint builder with all existing blocks
|
|
492
|
-
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
|
|
493
|
-
// Complete the checkpoint to get computed values
|
|
494
|
-
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
495
|
-
// Compare checkpoint header with proposal
|
|
496
|
-
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
497
|
-
this.log.warn(`Checkpoint header mismatch`, {
|
|
498
|
-
...proposalInfo,
|
|
499
|
-
computed: computedCheckpoint.header.toInspect(),
|
|
500
|
-
proposal: proposal.checkpointHeader.toInspect()
|
|
501
|
-
});
|
|
502
|
-
return {
|
|
503
|
-
isValid: false,
|
|
504
|
-
reason: 'checkpoint_header_mismatch'
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
// Compare archive root with proposal
|
|
508
|
-
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
509
|
-
this.log.warn(`Archive root mismatch`, {
|
|
510
|
-
...proposalInfo,
|
|
511
|
-
computed: computedCheckpoint.archive.root.toString(),
|
|
512
|
-
proposal: proposal.archive.toString()
|
|
513
|
-
});
|
|
514
|
-
return {
|
|
515
|
-
isValid: false,
|
|
516
|
-
reason: 'archive_mismatch'
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
520
|
-
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
521
|
-
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
522
|
-
const computedEpochOutHash = accumulateCheckpointOutHashes([
|
|
523
|
-
...previousCheckpointOutHashes,
|
|
524
|
-
checkpointOutHash
|
|
525
|
-
]);
|
|
526
|
-
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
527
|
-
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
528
|
-
this.log.warn(`Epoch out hash mismatch`, {
|
|
529
|
-
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
530
|
-
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
531
|
-
checkpointOutHash: checkpointOutHash.toString(),
|
|
532
|
-
previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
|
|
533
|
-
...proposalInfo
|
|
534
|
-
});
|
|
535
|
-
return {
|
|
536
|
-
isValid: false,
|
|
537
|
-
reason: 'out_hash_mismatch'
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
541
|
-
return {
|
|
542
|
-
isValid: true
|
|
543
|
-
};
|
|
544
|
-
} finally{
|
|
545
|
-
await fork.close();
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
/**
|
|
549
|
-
* Extract checkpoint global variables from a block.
|
|
550
|
-
*/ extractCheckpointConstants(block) {
|
|
551
|
-
const gv = block.header.globalVariables;
|
|
552
|
-
return {
|
|
553
|
-
chainId: gv.chainId,
|
|
554
|
-
version: gv.version,
|
|
555
|
-
slotNumber: gv.slotNumber,
|
|
556
|
-
timestamp: gv.timestamp,
|
|
557
|
-
coinbase: gv.coinbase,
|
|
558
|
-
feeRecipient: gv.feeRecipient,
|
|
559
|
-
gasFees: gv.gasFees
|
|
560
|
-
};
|
|
561
|
-
}
|
|
562
|
-
/**
|
|
563
430
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
564
431
|
*/ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
|
|
565
432
|
try {
|
|
@@ -644,7 +511,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
644
511
|
}
|
|
645
512
|
]);
|
|
646
513
|
}
|
|
647
|
-
async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
|
|
514
|
+
async createBlockProposal(blockHeader, checkpointNumber, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
|
|
648
515
|
// Validate that we're not creating a proposal for an older or equal position
|
|
649
516
|
if (this.lastProposedBlock) {
|
|
650
517
|
const lastSlot = this.lastProposedBlock.slotNumber;
|
|
@@ -655,14 +522,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
655
522
|
}
|
|
656
523
|
}
|
|
657
524
|
this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
|
|
658
|
-
const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
525
|
+
const newProposal = await this.validationService.createBlockProposal(blockHeader, checkpointNumber, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
659
526
|
...options,
|
|
660
527
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
661
528
|
});
|
|
662
529
|
this.lastProposedBlock = newProposal;
|
|
663
530
|
return newProposal;
|
|
664
531
|
}
|
|
665
|
-
async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier,
|
|
532
|
+
async createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options = {}) {
|
|
666
533
|
// Validate that we're not creating a proposal for an older or equal slot
|
|
667
534
|
if (this.lastProposedCheckpoint) {
|
|
668
535
|
const lastSlot = this.lastProposedCheckpoint.slotNumber;
|
|
@@ -672,23 +539,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
672
539
|
}
|
|
673
540
|
}
|
|
674
541
|
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
675
|
-
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier,
|
|
542
|
+
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options);
|
|
676
543
|
this.lastProposedCheckpoint = newProposal;
|
|
677
544
|
return newProposal;
|
|
678
545
|
}
|
|
679
546
|
async broadcastBlockProposal(proposal) {
|
|
680
547
|
await this.p2pClient.broadcastProposal(proposal);
|
|
681
548
|
}
|
|
682
|
-
async signAttestationsAndSigners(attestationsAndSigners, proposer, slot,
|
|
683
|
-
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot,
|
|
549
|
+
async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, checkpointNumber) {
|
|
550
|
+
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, checkpointNumber);
|
|
684
551
|
}
|
|
685
|
-
async collectOwnAttestations(proposal) {
|
|
552
|
+
async collectOwnAttestations(proposal, checkpointNumber) {
|
|
686
553
|
const slot = proposal.slotNumber;
|
|
687
554
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
688
555
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
|
|
689
556
|
inCommittee
|
|
690
557
|
});
|
|
691
|
-
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
558
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
|
|
692
559
|
if (!attestations) {
|
|
693
560
|
return [];
|
|
694
561
|
}
|
|
@@ -700,7 +567,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
700
567
|
});
|
|
701
568
|
return attestations;
|
|
702
569
|
}
|
|
703
|
-
async collectAttestations(proposal, required, deadline) {
|
|
570
|
+
async collectAttestations(proposal, required, deadline, checkpointNumber) {
|
|
704
571
|
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
705
572
|
const slot = proposal.slotNumber;
|
|
706
573
|
this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
|
|
@@ -708,7 +575,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
708
575
|
this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
|
|
709
576
|
throw new AttestationTimeoutError(0, required, slot);
|
|
710
577
|
}
|
|
711
|
-
await this.collectOwnAttestations(proposal);
|
|
578
|
+
await this.collectOwnAttestations(proposal, checkpointNumber);
|
|
712
579
|
const proposalId = proposal.archive.toString();
|
|
713
580
|
const myAddresses = this.getValidatorAddresses();
|
|
714
581
|
let 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.949a33fd8",
|
|
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.949a33fd8",
|
|
68
|
+
"@aztec/blob-lib": "0.0.1-commit.949a33fd8",
|
|
69
|
+
"@aztec/constants": "0.0.1-commit.949a33fd8",
|
|
70
|
+
"@aztec/epoch-cache": "0.0.1-commit.949a33fd8",
|
|
71
|
+
"@aztec/ethereum": "0.0.1-commit.949a33fd8",
|
|
72
|
+
"@aztec/foundation": "0.0.1-commit.949a33fd8",
|
|
73
|
+
"@aztec/node-keystore": "0.0.1-commit.949a33fd8",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.949a33fd8",
|
|
75
|
+
"@aztec/p2p": "0.0.1-commit.949a33fd8",
|
|
76
|
+
"@aztec/protocol-contracts": "0.0.1-commit.949a33fd8",
|
|
77
|
+
"@aztec/prover-client": "0.0.1-commit.949a33fd8",
|
|
78
|
+
"@aztec/simulator": "0.0.1-commit.949a33fd8",
|
|
79
|
+
"@aztec/slasher": "0.0.1-commit.949a33fd8",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.949a33fd8",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.949a33fd8",
|
|
82
|
+
"@aztec/validator-ha-signer": "0.0.1-commit.949a33fd8",
|
|
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.949a33fd8",
|
|
90
|
+
"@aztec/world-state": "0.0.1-commit.949a33fd8",
|
|
91
91
|
"@electric-sql/pglite": "^0.3.14",
|
|
92
92
|
"@jest/globals": "^30.0.0",
|
|
93
93
|
"@types/jest": "^30.0.0",
|