@aztec/validator-client 0.0.1-commit.9b94fc1 → 0.0.1-commit.bf2612ae
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 +282 -0
- package/dest/block_proposal_handler.d.ts +23 -12
- package/dest/block_proposal_handler.d.ts.map +1 -1
- package/dest/block_proposal_handler.js +340 -84
- package/dest/checkpoint_builder.d.ts +67 -0
- package/dest/checkpoint_builder.d.ts.map +1 -0
- package/dest/checkpoint_builder.js +160 -0
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +13 -8
- package/dest/duties/validation_service.d.ts +42 -13
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +111 -28
- package/dest/factory.d.ts +13 -8
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +2 -2
- package/dest/index.d.ts +3 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -0
- package/dest/key_store/ha_key_store.d.ts +99 -0
- package/dest/key_store/ha_key_store.d.ts.map +1 -0
- package/dest/key_store/ha_key_store.js +208 -0
- package/dest/key_store/index.d.ts +2 -1
- package/dest/key_store/index.d.ts.map +1 -1
- package/dest/key_store/index.js +1 -0
- package/dest/key_store/interface.d.ts +36 -6
- package/dest/key_store/interface.d.ts.map +1 -1
- package/dest/key_store/local_key_store.d.ts +10 -5
- package/dest/key_store/local_key_store.d.ts.map +1 -1
- package/dest/key_store/local_key_store.js +9 -5
- package/dest/key_store/node_keystore_adapter.d.ts +18 -5
- package/dest/key_store/node_keystore_adapter.d.ts.map +1 -1
- package/dest/key_store/node_keystore_adapter.js +18 -4
- package/dest/key_store/web3signer_key_store.d.ts +10 -5
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
- package/dest/key_store/web3signer_key_store.js +9 -5
- package/dest/metrics.d.ts +1 -1
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +8 -33
- package/dest/tx_validator/index.d.ts +3 -0
- package/dest/tx_validator/index.d.ts.map +1 -0
- package/dest/tx_validator/index.js +2 -0
- package/dest/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/tx_validator/nullifier_cache.js +24 -0
- package/dest/tx_validator/tx_validator_factory.d.ts +18 -0
- package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -0
- package/dest/tx_validator/tx_validator_factory.js +54 -0
- package/dest/validator.d.ts +48 -19
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +327 -54
- package/package.json +23 -13
- package/src/block_proposal_handler.ts +266 -53
- package/src/checkpoint_builder.ts +284 -0
- package/src/config.ts +12 -7
- package/src/duties/validation_service.ts +155 -33
- package/src/factory.ts +17 -8
- package/src/index.ts +2 -0
- package/src/key_store/ha_key_store.ts +269 -0
- package/src/key_store/index.ts +1 -0
- package/src/key_store/interface.ts +44 -5
- package/src/key_store/local_key_store.ts +14 -5
- package/src/key_store/node_keystore_adapter.ts +28 -5
- package/src/key_store/web3signer_key_store.ts +18 -5
- package/src/metrics.ts +7 -34
- package/src/tx_validator/index.ts +2 -0
- package/src/tx_validator/nullifier_cache.ts +30 -0
- package/src/tx_validator/tx_validator_factory.ts +135 -0
- package/src/validator.ts +449 -83
package/dest/validator.js
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
+
import { getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { TimeoutError } from '@aztec/foundation/error';
|
|
1
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
2
6
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
3
7
|
import { sleep } from '@aztec/foundation/sleep';
|
|
4
8
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
5
9
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
6
10
|
import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
|
|
11
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
12
|
+
import { accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
|
|
7
13
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
8
14
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
15
|
+
import { createHASigner } from '@aztec/validator-ha-signer/factory';
|
|
16
|
+
import { DutyType } from '@aztec/validator-ha-signer/types';
|
|
9
17
|
import { EventEmitter } from 'events';
|
|
10
18
|
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
11
19
|
import { ValidationService } from './duties/validation_service.js';
|
|
20
|
+
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
12
21
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
13
22
|
import { ValidatorMetrics } from './metrics.js';
|
|
14
23
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
@@ -26,7 +35,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
26
35
|
epochCache;
|
|
27
36
|
p2pClient;
|
|
28
37
|
blockProposalHandler;
|
|
38
|
+
blockSource;
|
|
39
|
+
checkpointsBuilder;
|
|
40
|
+
worldState;
|
|
41
|
+
l1ToL2MessageSource;
|
|
29
42
|
config;
|
|
43
|
+
blobClient;
|
|
30
44
|
dateProvider;
|
|
31
45
|
tracer;
|
|
32
46
|
validationService;
|
|
@@ -39,8 +53,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
39
53
|
lastEpochForCommitteeUpdateLoop;
|
|
40
54
|
epochCacheUpdateLoop;
|
|
41
55
|
proposersOfInvalidBlocks;
|
|
42
|
-
|
|
43
|
-
|
|
56
|
+
// TODO(palla/mbps): Remove this once checkpoint validation is stable and we can validate all blocks properly.
|
|
57
|
+
// Tracks slots for which we have successfully validated a block proposal, so we can attest to checkpoint proposals for those slots.
|
|
58
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
59
|
+
validatedBlockSlots;
|
|
60
|
+
constructor(keyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
61
|
+
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();
|
|
44
62
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
45
63
|
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
46
64
|
this.tracer = telemetry.getTracer('Validator');
|
|
@@ -94,13 +112,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
94
112
|
this.log.error(`Error updating epoch committee`, err);
|
|
95
113
|
}
|
|
96
114
|
}
|
|
97
|
-
static new(config,
|
|
115
|
+
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
98
116
|
const metrics = new ValidatorMetrics(telemetry);
|
|
99
117
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
100
118
|
txsPermitted: !config.disableTransactions
|
|
101
119
|
});
|
|
102
|
-
const blockProposalHandler = new BlockProposalHandler(
|
|
103
|
-
|
|
120
|
+
const blockProposalHandler = new BlockProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, metrics, dateProvider, telemetry);
|
|
121
|
+
let validatorKeyStore = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
122
|
+
if (config.haSigningEnabled) {
|
|
123
|
+
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
124
|
+
const haConfig = {
|
|
125
|
+
...config,
|
|
126
|
+
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000
|
|
127
|
+
};
|
|
128
|
+
const { signer } = await createHASigner(haConfig);
|
|
129
|
+
validatorKeyStore = new HAKeyStore(validatorKeyStore, signer);
|
|
130
|
+
}
|
|
131
|
+
const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider, telemetry);
|
|
104
132
|
return validator;
|
|
105
133
|
}
|
|
106
134
|
getValidatorAddresses() {
|
|
@@ -109,12 +137,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
109
137
|
getBlockProposalHandler() {
|
|
110
138
|
return this.blockProposalHandler;
|
|
111
139
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return this.blockProposalHandler.reexecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages);
|
|
115
|
-
}
|
|
116
|
-
signWithAddress(addr, msg) {
|
|
117
|
-
return this.keyStore.signTypedDataWithAddress(addr, msg);
|
|
140
|
+
signWithAddress(addr, msg, context) {
|
|
141
|
+
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
118
142
|
}
|
|
119
143
|
getCoinbaseForAttestor(attestor) {
|
|
120
144
|
return this.keyStore.getCoinbaseAddress(attestor);
|
|
@@ -136,6 +160,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
136
160
|
this.log.warn(`Validator client already started`);
|
|
137
161
|
return;
|
|
138
162
|
}
|
|
163
|
+
await this.keyStore.start();
|
|
139
164
|
await this.registerHandlers();
|
|
140
165
|
const myAddresses = this.getValidatorAddresses();
|
|
141
166
|
const inCommittee = await this.epochCache.filterInCommittee('now', myAddresses);
|
|
@@ -148,46 +173,59 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
148
173
|
}
|
|
149
174
|
async stop() {
|
|
150
175
|
await this.epochCacheUpdateLoop.stop();
|
|
176
|
+
await this.keyStore.stop();
|
|
151
177
|
}
|
|
152
178
|
/** Register handlers on the p2p client */ async registerHandlers() {
|
|
153
179
|
if (!this.hasRegisteredHandlers) {
|
|
154
180
|
this.hasRegisteredHandlers = true;
|
|
155
181
|
this.log.debug(`Registering validator handlers for p2p client`);
|
|
156
|
-
|
|
157
|
-
this.
|
|
182
|
+
// Block proposal handler - validates but does NOT attest (validators only attest to checkpoints)
|
|
183
|
+
const blockHandler = (block, proposalSender)=>this.validateBlockProposal(block, proposalSender);
|
|
184
|
+
this.p2pClient.registerBlockProposalHandler(blockHandler);
|
|
185
|
+
// Checkpoint proposal handler - validates and creates attestations
|
|
186
|
+
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
187
|
+
// and processed separately via the block handler above.
|
|
188
|
+
const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
189
|
+
this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
|
|
158
190
|
const myAddresses = this.getValidatorAddresses();
|
|
159
191
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
160
192
|
await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
|
|
161
193
|
}
|
|
162
194
|
}
|
|
163
|
-
|
|
195
|
+
/**
|
|
196
|
+
* Validate a block proposal from a peer.
|
|
197
|
+
* Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
|
|
198
|
+
* @returns true if the proposal is valid, false otherwise
|
|
199
|
+
*/ async validateBlockProposal(proposal, proposalSender) {
|
|
164
200
|
const slotNumber = proposal.slotNumber;
|
|
201
|
+
// Note: During escape hatch, we still want to "validate" proposals for observability,
|
|
202
|
+
// but we intentionally reject them and disable slashing invalid block and attestation flow.
|
|
203
|
+
const escapeHatchOpen = await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber);
|
|
165
204
|
const proposer = proposal.getSender();
|
|
166
205
|
// Reject proposals with invalid signatures
|
|
167
206
|
if (!proposer) {
|
|
168
|
-
this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
|
|
169
|
-
return
|
|
207
|
+
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
208
|
+
return false;
|
|
170
209
|
}
|
|
171
|
-
// Check
|
|
210
|
+
// Check if we're in the committee (for metrics purposes)
|
|
172
211
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
173
212
|
const partOfCommittee = inCommittee.length > 0;
|
|
174
213
|
const proposalInfo = {
|
|
175
214
|
...proposal.toBlockInfo(),
|
|
176
215
|
proposer: proposer.toString()
|
|
177
216
|
};
|
|
178
|
-
this.log.info(`Received proposal for slot ${slotNumber}`, {
|
|
217
|
+
this.log.info(`Received block proposal for slot ${slotNumber}`, {
|
|
179
218
|
...proposalInfo,
|
|
180
219
|
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
181
220
|
fishermanMode: this.config.fishermanMode || false
|
|
182
221
|
});
|
|
183
|
-
// Reexecute txs if we are part of the committee
|
|
184
|
-
// invalid proposals even when not in the committee, or if we are configured to always reexecute for monitoring purposes.
|
|
222
|
+
// Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
|
|
185
223
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
186
224
|
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
187
|
-
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals;
|
|
188
|
-
const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute);
|
|
225
|
+
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
|
|
226
|
+
const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
|
|
189
227
|
if (!validationResult.isValid) {
|
|
190
|
-
this.log.warn(`
|
|
228
|
+
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
191
229
|
const reason = validationResult.reason || 'unknown';
|
|
192
230
|
// Classify failure reason: bad proposal vs node issue
|
|
193
231
|
const badProposalReasons = [
|
|
@@ -200,30 +238,97 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
200
238
|
if (badProposalReasons.includes(reason)) {
|
|
201
239
|
this.metrics.incFailedAttestationsBadProposal(1, reason, partOfCommittee);
|
|
202
240
|
} else {
|
|
203
|
-
// Node issues so we can't
|
|
241
|
+
// Node issues so we can't validate
|
|
204
242
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
205
243
|
}
|
|
206
244
|
// Slash invalid block proposals (can happen even when not in committee)
|
|
207
|
-
if (validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
|
|
245
|
+
if (!escapeHatchOpen && validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
|
|
208
246
|
this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
|
|
209
247
|
this.slashInvalidBlock(proposal);
|
|
210
248
|
}
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
this.log.info(`Validated block proposal for slot ${slotNumber}`, {
|
|
252
|
+
...proposalInfo,
|
|
253
|
+
inCommittee: partOfCommittee,
|
|
254
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
255
|
+
escapeHatchOpen
|
|
256
|
+
});
|
|
257
|
+
if (escapeHatchOpen) {
|
|
258
|
+
this.log.warn(`Escape hatch open for slot ${slotNumber}, rejecting block proposal`, proposalInfo);
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
// TODO(palla/mbps): Remove this once checkpoint validation is stable.
|
|
262
|
+
// Track that we successfully validated a block for this slot, so we can attest to checkpoint proposals for it.
|
|
263
|
+
this.validatedBlockSlots.add(slotNumber);
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Validate and attest to a checkpoint proposal from a peer.
|
|
268
|
+
* The proposal is received as CheckpointProposalCore (without lastBlock) since
|
|
269
|
+
* the lastBlock is extracted and processed separately via the block handler.
|
|
270
|
+
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
271
|
+
*/ async attestToCheckpointProposal(proposal, _proposalSender) {
|
|
272
|
+
const slotNumber = proposal.slotNumber;
|
|
273
|
+
const proposer = proposal.getSender();
|
|
274
|
+
// If escape hatch is open for this slot's epoch, do not attest.
|
|
275
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
|
|
276
|
+
this.log.warn(`Escape hatch open for slot ${slotNumber}, skipping checkpoint attestation handling`);
|
|
277
|
+
return undefined;
|
|
278
|
+
}
|
|
279
|
+
// Reject proposals with invalid signatures
|
|
280
|
+
if (!proposer) {
|
|
281
|
+
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
211
282
|
return undefined;
|
|
212
283
|
}
|
|
213
284
|
// Check that I have any address in current committee before attesting
|
|
285
|
+
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
286
|
+
const partOfCommittee = inCommittee.length > 0;
|
|
287
|
+
const proposalInfo = {
|
|
288
|
+
slotNumber,
|
|
289
|
+
archive: proposal.archive.toString(),
|
|
290
|
+
proposer: proposer.toString(),
|
|
291
|
+
txCount: proposal.txHashes.length
|
|
292
|
+
};
|
|
293
|
+
this.log.info(`Received checkpoint proposal for slot ${slotNumber}`, {
|
|
294
|
+
...proposalInfo,
|
|
295
|
+
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
296
|
+
fishermanMode: this.config.fishermanMode || false
|
|
297
|
+
});
|
|
298
|
+
// TODO(palla/mbps): Remove this once checkpoint validation is stable.
|
|
299
|
+
// Check that we have successfully validated a block for this slot before attesting to the checkpoint.
|
|
300
|
+
if (!this.validatedBlockSlots.has(slotNumber)) {
|
|
301
|
+
this.log.warn(`No validated block found for slot ${slotNumber}, refusing to attest to checkpoint`, proposalInfo);
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
304
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
305
|
+
// TODO(palla/mbps): Change default to false once checkpoint validation is stable.
|
|
306
|
+
if (this.config.skipCheckpointProposalValidation !== false) {
|
|
307
|
+
this.log.verbose(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
|
|
308
|
+
} else {
|
|
309
|
+
const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
|
|
310
|
+
if (!validationResult.isValid) {
|
|
311
|
+
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
312
|
+
return undefined;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
// Upload blobs to filestore if we can (fire and forget)
|
|
316
|
+
if (this.blobClient.canUpload()) {
|
|
317
|
+
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
318
|
+
}
|
|
319
|
+
// Check that I have any address in current committee before attesting
|
|
214
320
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
215
321
|
if (!partOfCommittee && !this.config.fishermanMode) {
|
|
216
322
|
this.log.verbose(`No validator in the current committee, skipping attestation`, proposalInfo);
|
|
217
323
|
return undefined;
|
|
218
324
|
}
|
|
219
325
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
220
|
-
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} proposal for slot ${slotNumber}`, {
|
|
326
|
+
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${slotNumber}`, {
|
|
221
327
|
...proposalInfo,
|
|
222
328
|
inCommittee: partOfCommittee,
|
|
223
329
|
fishermanMode: this.config.fishermanMode || false
|
|
224
330
|
});
|
|
225
331
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
226
|
-
// If the above function does not throw an error, then we can attest to the proposal
|
|
227
332
|
// Determine which validators should attest
|
|
228
333
|
let attestors;
|
|
229
334
|
if (partOfCommittee) {
|
|
@@ -240,13 +345,176 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
240
345
|
}
|
|
241
346
|
if (this.config.fishermanMode) {
|
|
242
347
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
243
|
-
this.log.info(`Creating attestations for
|
|
348
|
+
this.log.info(`Creating checkpoint attestations for slot ${slotNumber}`, {
|
|
244
349
|
...proposalInfo,
|
|
245
350
|
attestors: attestors.map((a)=>a.toString())
|
|
246
351
|
});
|
|
247
352
|
return undefined;
|
|
248
353
|
}
|
|
249
|
-
return this.
|
|
354
|
+
return this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
355
|
+
}
|
|
356
|
+
async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
|
|
357
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
358
|
+
await this.p2pClient.addCheckpointAttestations(attestations);
|
|
359
|
+
return attestations;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
363
|
+
* @returns Validation result with isValid flag and reason if invalid.
|
|
364
|
+
*/ async validateCheckpointProposal(proposal, proposalInfo) {
|
|
365
|
+
const slot = proposal.slotNumber;
|
|
366
|
+
const timeoutSeconds = 10;
|
|
367
|
+
// Wait for last block to sync by archive
|
|
368
|
+
let lastBlockHeader;
|
|
369
|
+
try {
|
|
370
|
+
lastBlockHeader = await retryUntil(async ()=>{
|
|
371
|
+
await this.blockSource.syncImmediate();
|
|
372
|
+
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
373
|
+
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, timeoutSeconds, 0.5);
|
|
374
|
+
} catch (err) {
|
|
375
|
+
if (err instanceof TimeoutError) {
|
|
376
|
+
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
377
|
+
return {
|
|
378
|
+
isValid: false,
|
|
379
|
+
reason: 'last_block_not_found'
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
383
|
+
return {
|
|
384
|
+
isValid: false,
|
|
385
|
+
reason: 'block_fetch_error'
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
if (!lastBlockHeader) {
|
|
389
|
+
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
390
|
+
return {
|
|
391
|
+
isValid: false,
|
|
392
|
+
reason: 'last_block_not_found'
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
// Get all full blocks for the slot and checkpoint
|
|
396
|
+
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
397
|
+
if (blocks.length === 0) {
|
|
398
|
+
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
399
|
+
return {
|
|
400
|
+
isValid: false,
|
|
401
|
+
reason: 'no_blocks_for_slot'
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
405
|
+
...proposalInfo,
|
|
406
|
+
blockNumbers: blocks.map((b)=>b.number)
|
|
407
|
+
});
|
|
408
|
+
// Get checkpoint constants from first block
|
|
409
|
+
const firstBlock = blocks[0];
|
|
410
|
+
const constants = this.extractCheckpointConstants(firstBlock);
|
|
411
|
+
const checkpointNumber = firstBlock.checkpointNumber;
|
|
412
|
+
// Get L1-to-L2 messages for this checkpoint
|
|
413
|
+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
414
|
+
// Compute the previous checkpoint out hashes for the epoch.
|
|
415
|
+
// TODO: There can be a more efficient way to get the previous checkpoint out hashes without having to fetch the
|
|
416
|
+
// actual checkpoints and the blocks/txs in them.
|
|
417
|
+
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
418
|
+
const previousCheckpoints = (await this.blockSource.getCheckpointsForEpoch(epoch)).filter((b)=>b.number < checkpointNumber).sort((a, b)=>a.number - b.number);
|
|
419
|
+
const previousCheckpointOutHashes = previousCheckpoints.map((c)=>c.getCheckpointOutHash());
|
|
420
|
+
// Fork world state at the block before the first block
|
|
421
|
+
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
422
|
+
const fork = await this.worldState.fork(parentBlockNumber);
|
|
423
|
+
try {
|
|
424
|
+
// Create checkpoint builder with all existing blocks
|
|
425
|
+
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks);
|
|
426
|
+
// Complete the checkpoint to get computed values
|
|
427
|
+
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
428
|
+
// Compare checkpoint header with proposal
|
|
429
|
+
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
430
|
+
this.log.warn(`Checkpoint header mismatch`, {
|
|
431
|
+
...proposalInfo,
|
|
432
|
+
computed: computedCheckpoint.header.toInspect(),
|
|
433
|
+
proposal: proposal.checkpointHeader.toInspect()
|
|
434
|
+
});
|
|
435
|
+
return {
|
|
436
|
+
isValid: false,
|
|
437
|
+
reason: 'checkpoint_header_mismatch'
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
// Compare archive root with proposal
|
|
441
|
+
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
442
|
+
this.log.warn(`Archive root mismatch`, {
|
|
443
|
+
...proposalInfo,
|
|
444
|
+
computed: computedCheckpoint.archive.root.toString(),
|
|
445
|
+
proposal: proposal.archive.toString()
|
|
446
|
+
});
|
|
447
|
+
return {
|
|
448
|
+
isValid: false,
|
|
449
|
+
reason: 'archive_mismatch'
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
453
|
+
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
454
|
+
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
455
|
+
const computedEpochOutHash = accumulateCheckpointOutHashes([
|
|
456
|
+
...previousCheckpointOutHashes,
|
|
457
|
+
checkpointOutHash
|
|
458
|
+
]);
|
|
459
|
+
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
460
|
+
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
461
|
+
this.log.warn(`Epoch out hash mismatch`, {
|
|
462
|
+
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
463
|
+
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
464
|
+
checkpointOutHash: checkpointOutHash.toString(),
|
|
465
|
+
previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
|
|
466
|
+
...proposalInfo
|
|
467
|
+
});
|
|
468
|
+
return {
|
|
469
|
+
isValid: false,
|
|
470
|
+
reason: 'out_hash_mismatch'
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
474
|
+
return {
|
|
475
|
+
isValid: true
|
|
476
|
+
};
|
|
477
|
+
} finally{
|
|
478
|
+
await fork.close();
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Extract checkpoint global variables from a block.
|
|
483
|
+
*/ extractCheckpointConstants(block) {
|
|
484
|
+
const gv = block.header.globalVariables;
|
|
485
|
+
return {
|
|
486
|
+
chainId: gv.chainId,
|
|
487
|
+
version: gv.version,
|
|
488
|
+
slotNumber: gv.slotNumber,
|
|
489
|
+
coinbase: gv.coinbase,
|
|
490
|
+
feeRecipient: gv.feeRecipient,
|
|
491
|
+
gasFees: gv.gasFees
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
496
|
+
*/ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
|
|
497
|
+
try {
|
|
498
|
+
const lastBlockHeader = await this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
499
|
+
if (!lastBlockHeader) {
|
|
500
|
+
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
const blocks = await this.blockSource.getBlocksForSlot(proposal.slotNumber);
|
|
504
|
+
if (blocks.length === 0) {
|
|
505
|
+
this.log.warn(`No blocks found for blob upload`, proposalInfo);
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
const blobFields = blocks.flatMap((b)=>b.toBlobFields());
|
|
509
|
+
const blobs = getBlobsPerL1Block(blobFields);
|
|
510
|
+
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
511
|
+
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
512
|
+
...proposalInfo,
|
|
513
|
+
numBlobs: blobs.length
|
|
514
|
+
});
|
|
515
|
+
} catch (err) {
|
|
516
|
+
this.log.warn(`Failed to upload blobs for checkpoint: ${err}`, proposalInfo);
|
|
517
|
+
}
|
|
250
518
|
}
|
|
251
519
|
slashInvalidBlock(proposal) {
|
|
252
520
|
const proposer = proposal.getSender();
|
|
@@ -270,42 +538,48 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
270
538
|
}
|
|
271
539
|
]);
|
|
272
540
|
}
|
|
273
|
-
async createBlockProposal(
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
541
|
+
async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
|
|
542
|
+
// TODO(palla/mbps): Prevent double proposals properly
|
|
543
|
+
// if (this.previousProposal?.slotNumber === blockHeader.globalVariables.slotNumber) {
|
|
544
|
+
// this.log.verbose(`Already made a proposal for the same slot, skipping proposal`);
|
|
545
|
+
// return Promise.resolve(undefined);
|
|
546
|
+
// }
|
|
547
|
+
this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
|
|
548
|
+
const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
279
549
|
...options,
|
|
280
550
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
281
551
|
});
|
|
282
552
|
this.previousProposal = newProposal;
|
|
283
553
|
return newProposal;
|
|
284
554
|
}
|
|
555
|
+
async createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options = {}) {
|
|
556
|
+
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
557
|
+
return await this.validationService.createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options);
|
|
558
|
+
}
|
|
285
559
|
async broadcastBlockProposal(proposal) {
|
|
286
560
|
await this.p2pClient.broadcastProposal(proposal);
|
|
287
561
|
}
|
|
288
|
-
async signAttestationsAndSigners(attestationsAndSigners, proposer) {
|
|
289
|
-
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
|
|
562
|
+
async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber) {
|
|
563
|
+
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
|
|
290
564
|
}
|
|
291
565
|
async collectOwnAttestations(proposal) {
|
|
292
|
-
const slot = proposal.
|
|
566
|
+
const slot = proposal.slotNumber;
|
|
293
567
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
294
568
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
|
|
295
569
|
inCommittee
|
|
296
570
|
});
|
|
297
|
-
const attestations = await this.
|
|
571
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
298
572
|
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
299
573
|
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
300
574
|
// due to inactivity for missed attestations.
|
|
301
|
-
void this.p2pClient.
|
|
575
|
+
void this.p2pClient.broadcastCheckpointAttestations(attestations).catch((err)=>{
|
|
302
576
|
this.log.error(`Failed to broadcast self-attestations for slot ${slot}`, err);
|
|
303
577
|
});
|
|
304
578
|
return attestations;
|
|
305
579
|
}
|
|
306
580
|
async collectAttestations(proposal, required, deadline) {
|
|
307
|
-
// Wait and poll the p2pClient's attestation pool for this
|
|
308
|
-
const slot = proposal.
|
|
581
|
+
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
582
|
+
const slot = proposal.slotNumber;
|
|
309
583
|
this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
|
|
310
584
|
if (+deadline < this.dateProvider.now()) {
|
|
311
585
|
this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
|
|
@@ -316,13 +590,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
316
590
|
const myAddresses = this.getValidatorAddresses();
|
|
317
591
|
let attestations = [];
|
|
318
592
|
while(true){
|
|
319
|
-
// Filter out attestations with a mismatching
|
|
593
|
+
// Filter out attestations with a mismatching archive. This should NOT happen since we have verified
|
|
320
594
|
// the proposer signature (ie our own) before accepting the attestation into the pool via the p2p client.
|
|
321
|
-
const collectedAttestations = (await this.p2pClient.
|
|
322
|
-
if (!attestation.
|
|
323
|
-
this.log.warn(`Received attestation for slot ${slot} with mismatched
|
|
324
|
-
|
|
325
|
-
|
|
595
|
+
const collectedAttestations = (await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalId)).filter((attestation)=>{
|
|
596
|
+
if (!attestation.archive.equals(proposal.archive)) {
|
|
597
|
+
this.log.warn(`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`, {
|
|
598
|
+
attestationArchive: attestation.archive.toString(),
|
|
599
|
+
proposalArchive: proposal.archive.toString()
|
|
326
600
|
});
|
|
327
601
|
return false;
|
|
328
602
|
}
|
|
@@ -354,11 +628,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
354
628
|
await sleep(this.config.attestationPollingIntervalMs);
|
|
355
629
|
}
|
|
356
630
|
}
|
|
357
|
-
async createBlockAttestationsFromProposal(proposal, attestors = []) {
|
|
358
|
-
const attestations = await this.validationService.attestToProposal(proposal, attestors);
|
|
359
|
-
await this.p2pClient.addAttestations(attestations);
|
|
360
|
-
return attestations;
|
|
361
|
-
}
|
|
362
631
|
async handleAuthRequest(peer, msg) {
|
|
363
632
|
const authRequest = AuthRequest.fromBuffer(msg);
|
|
364
633
|
const statusMessage = await this.p2pClient.handleAuthRequestFromPeer(authRequest, peer).catch((_)=>undefined);
|
|
@@ -373,7 +642,11 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
373
642
|
return Buffer.alloc(0);
|
|
374
643
|
}
|
|
375
644
|
const payloadToSign = authRequest.getPayloadToSign();
|
|
376
|
-
|
|
645
|
+
// AUTH_REQUEST doesn't require HA protection - multiple signatures are safe
|
|
646
|
+
const context = {
|
|
647
|
+
dutyType: DutyType.AUTH_REQUEST
|
|
648
|
+
};
|
|
649
|
+
const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign, context);
|
|
377
650
|
const authResponse = new AuthResponse(statusMessage, signature);
|
|
378
651
|
return authResponse.toBuffer();
|
|
379
652
|
}
|
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.bf2612ae",
|
|
4
4
|
"main": "dest/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
20
|
"start": "node --no-warnings ./dest/bin",
|
|
21
|
-
"build": "yarn clean &&
|
|
22
|
-
"build:dev": "
|
|
21
|
+
"build": "yarn clean && ../scripts/tsc.sh",
|
|
22
|
+
"build:dev": "../scripts/tsc.sh --watch",
|
|
23
23
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
24
24
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
25
25
|
},
|
|
@@ -64,25 +64,35 @@
|
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@aztec/
|
|
68
|
-
"@aztec/
|
|
69
|
-
"@aztec/
|
|
70
|
-
"@aztec/
|
|
71
|
-
"@aztec/
|
|
72
|
-
"@aztec/
|
|
73
|
-
"@aztec/
|
|
74
|
-
"@aztec/
|
|
75
|
-
"@aztec/
|
|
67
|
+
"@aztec/blob-client": "0.0.1-commit.bf2612ae",
|
|
68
|
+
"@aztec/blob-lib": "0.0.1-commit.bf2612ae",
|
|
69
|
+
"@aztec/constants": "0.0.1-commit.bf2612ae",
|
|
70
|
+
"@aztec/epoch-cache": "0.0.1-commit.bf2612ae",
|
|
71
|
+
"@aztec/ethereum": "0.0.1-commit.bf2612ae",
|
|
72
|
+
"@aztec/foundation": "0.0.1-commit.bf2612ae",
|
|
73
|
+
"@aztec/node-keystore": "0.0.1-commit.bf2612ae",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.bf2612ae",
|
|
75
|
+
"@aztec/p2p": "0.0.1-commit.bf2612ae",
|
|
76
|
+
"@aztec/protocol-contracts": "0.0.1-commit.bf2612ae",
|
|
77
|
+
"@aztec/prover-client": "0.0.1-commit.bf2612ae",
|
|
78
|
+
"@aztec/simulator": "0.0.1-commit.bf2612ae",
|
|
79
|
+
"@aztec/slasher": "0.0.1-commit.bf2612ae",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.bf2612ae",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.bf2612ae",
|
|
82
|
+
"@aztec/validator-ha-signer": "0.0.1-commit.bf2612ae",
|
|
76
83
|
"koa": "^2.16.1",
|
|
77
84
|
"koa-router": "^13.1.1",
|
|
78
85
|
"tslib": "^2.4.0",
|
|
79
86
|
"viem": "npm:@aztec/viem@2.38.2"
|
|
80
87
|
},
|
|
81
88
|
"devDependencies": {
|
|
89
|
+
"@aztec/archiver": "0.0.1-commit.bf2612ae",
|
|
90
|
+
"@aztec/world-state": "0.0.1-commit.bf2612ae",
|
|
91
|
+
"@electric-sql/pglite": "^0.3.14",
|
|
82
92
|
"@jest/globals": "^30.0.0",
|
|
83
93
|
"@types/jest": "^30.0.0",
|
|
84
94
|
"@types/node": "^22.15.17",
|
|
85
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
95
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
86
96
|
"jest": "^30.0.0",
|
|
87
97
|
"jest-mock-extended": "^4.0.0",
|
|
88
98
|
"ts-node": "^10.9.1",
|