@aztec/validator-client 0.0.1-commit.03f7ef2 → 0.0.1-commit.0b941701
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 +20 -9
- package/dest/block_proposal_handler.d.ts.map +1 -1
- package/dest/block_proposal_handler.js +333 -78
- 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 +41 -12
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +109 -26
- package/dest/factory.d.ts +13 -10
- 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 +8 -4
- 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 +8 -4
- 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 +45 -20
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +313 -71
- package/package.json +19 -13
- package/src/block_proposal_handler.ts +252 -44
- package/src/checkpoint_builder.ts +284 -0
- package/src/config.ts +12 -7
- package/src/duties/validation_service.ts +153 -31
- package/src/factory.ts +17 -11
- 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 +13 -4
- package/src/key_store/node_keystore_adapter.ts +27 -4
- package/src/key_store/web3signer_key_store.ts +17 -4
- 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 +428 -102
package/dest/validator.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { TimeoutError } from '@aztec/foundation/error';
|
|
2
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
3
6
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
4
7
|
import { sleep } from '@aztec/foundation/sleep';
|
|
5
8
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
6
9
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
7
10
|
import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
|
|
11
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
8
12
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
9
13
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
14
|
+
import { createHASigner } from '@aztec/validator-ha-signer/factory';
|
|
15
|
+
import { DutyType } from '@aztec/validator-ha-signer/types';
|
|
10
16
|
import { EventEmitter } from 'events';
|
|
11
17
|
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
12
18
|
import { ValidationService } from './duties/validation_service.js';
|
|
19
|
+
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
13
20
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
14
21
|
import { ValidatorMetrics } from './metrics.js';
|
|
15
22
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
@@ -27,8 +34,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
27
34
|
epochCache;
|
|
28
35
|
p2pClient;
|
|
29
36
|
blockProposalHandler;
|
|
37
|
+
blockSource;
|
|
38
|
+
checkpointsBuilder;
|
|
39
|
+
worldState;
|
|
40
|
+
l1ToL2MessageSource;
|
|
30
41
|
config;
|
|
31
|
-
|
|
42
|
+
blobClient;
|
|
32
43
|
dateProvider;
|
|
33
44
|
tracer;
|
|
34
45
|
validationService;
|
|
@@ -41,8 +52,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
41
52
|
lastEpochForCommitteeUpdateLoop;
|
|
42
53
|
epochCacheUpdateLoop;
|
|
43
54
|
proposersOfInvalidBlocks;
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
// TODO(palla/mbps): Remove this once checkpoint validation is stable and we can validate all blocks properly.
|
|
56
|
+
// Tracks slots for which we have successfully validated a block proposal, so we can attest to checkpoint proposals for those slots.
|
|
57
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
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();
|
|
46
61
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
47
62
|
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
48
63
|
this.tracer = telemetry.getTracer('Validator');
|
|
@@ -96,13 +111,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
96
111
|
this.log.error(`Error updating epoch committee`, err);
|
|
97
112
|
}
|
|
98
113
|
}
|
|
99
|
-
static new(config,
|
|
114
|
+
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
100
115
|
const metrics = new ValidatorMetrics(telemetry);
|
|
101
116
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
102
117
|
txsPermitted: !config.disableTransactions
|
|
103
118
|
});
|
|
104
|
-
const blockProposalHandler = new BlockProposalHandler(
|
|
105
|
-
|
|
119
|
+
const blockProposalHandler = new BlockProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, metrics, dateProvider, telemetry);
|
|
120
|
+
let validatorKeyStore = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
121
|
+
if (config.haSigningEnabled) {
|
|
122
|
+
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
123
|
+
const haConfig = {
|
|
124
|
+
...config,
|
|
125
|
+
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000
|
|
126
|
+
};
|
|
127
|
+
const { signer } = await createHASigner(haConfig);
|
|
128
|
+
validatorKeyStore = new HAKeyStore(validatorKeyStore, signer);
|
|
129
|
+
}
|
|
130
|
+
const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider, telemetry);
|
|
106
131
|
return validator;
|
|
107
132
|
}
|
|
108
133
|
getValidatorAddresses() {
|
|
@@ -111,12 +136,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
111
136
|
getBlockProposalHandler() {
|
|
112
137
|
return this.blockProposalHandler;
|
|
113
138
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return this.blockProposalHandler.reexecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages);
|
|
117
|
-
}
|
|
118
|
-
signWithAddress(addr, msg) {
|
|
119
|
-
return this.keyStore.signTypedDataWithAddress(addr, msg);
|
|
139
|
+
signWithAddress(addr, msg, context) {
|
|
140
|
+
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
120
141
|
}
|
|
121
142
|
getCoinbaseForAttestor(attestor) {
|
|
122
143
|
return this.keyStore.getCoinbaseAddress(attestor);
|
|
@@ -138,6 +159,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
138
159
|
this.log.warn(`Validator client already started`);
|
|
139
160
|
return;
|
|
140
161
|
}
|
|
162
|
+
await this.keyStore.start();
|
|
141
163
|
await this.registerHandlers();
|
|
142
164
|
const myAddresses = this.getValidatorAddresses();
|
|
143
165
|
const inCommittee = await this.epochCache.filterInCommittee('now', myAddresses);
|
|
@@ -150,46 +172,59 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
150
172
|
}
|
|
151
173
|
async stop() {
|
|
152
174
|
await this.epochCacheUpdateLoop.stop();
|
|
175
|
+
await this.keyStore.stop();
|
|
153
176
|
}
|
|
154
177
|
/** Register handlers on the p2p client */ async registerHandlers() {
|
|
155
178
|
if (!this.hasRegisteredHandlers) {
|
|
156
179
|
this.hasRegisteredHandlers = true;
|
|
157
180
|
this.log.debug(`Registering validator handlers for p2p client`);
|
|
158
|
-
|
|
159
|
-
this.
|
|
181
|
+
// Block proposal handler - validates but does NOT attest (validators only attest to checkpoints)
|
|
182
|
+
const blockHandler = (block, proposalSender)=>this.validateBlockProposal(block, proposalSender);
|
|
183
|
+
this.p2pClient.registerBlockProposalHandler(blockHandler);
|
|
184
|
+
// Checkpoint proposal handler - validates and creates attestations
|
|
185
|
+
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
186
|
+
// and processed separately via the block handler above.
|
|
187
|
+
const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
188
|
+
this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
|
|
160
189
|
const myAddresses = this.getValidatorAddresses();
|
|
161
190
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
162
191
|
await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
|
|
163
192
|
}
|
|
164
193
|
}
|
|
165
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Validate a block proposal from a peer.
|
|
196
|
+
* Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
|
|
197
|
+
* @returns true if the proposal is valid, false otherwise
|
|
198
|
+
*/ async validateBlockProposal(proposal, proposalSender) {
|
|
166
199
|
const slotNumber = proposal.slotNumber;
|
|
200
|
+
// Note: During escape hatch, we still want to "validate" proposals for observability,
|
|
201
|
+
// but we intentionally reject them and disable slashing invalid block and attestation flow.
|
|
202
|
+
const escapeHatchOpen = await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber);
|
|
167
203
|
const proposer = proposal.getSender();
|
|
168
204
|
// Reject proposals with invalid signatures
|
|
169
205
|
if (!proposer) {
|
|
170
|
-
this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
|
|
171
|
-
return
|
|
206
|
+
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
207
|
+
return false;
|
|
172
208
|
}
|
|
173
|
-
// Check
|
|
209
|
+
// Check if we're in the committee (for metrics purposes)
|
|
174
210
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
175
211
|
const partOfCommittee = inCommittee.length > 0;
|
|
176
212
|
const proposalInfo = {
|
|
177
213
|
...proposal.toBlockInfo(),
|
|
178
214
|
proposer: proposer.toString()
|
|
179
215
|
};
|
|
180
|
-
this.log.info(`Received proposal for slot ${slotNumber}`, {
|
|
216
|
+
this.log.info(`Received block proposal for slot ${slotNumber}`, {
|
|
181
217
|
...proposalInfo,
|
|
182
218
|
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
183
219
|
fishermanMode: this.config.fishermanMode || false
|
|
184
220
|
});
|
|
185
|
-
// Reexecute txs if we are part of the committee
|
|
186
|
-
// invalid proposals even when not in the committee, or if we are configured to always reexecute for monitoring purposes.
|
|
221
|
+
// Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
|
|
187
222
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
188
223
|
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
189
|
-
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.
|
|
190
|
-
const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute);
|
|
224
|
+
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
|
|
225
|
+
const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
|
|
191
226
|
if (!validationResult.isValid) {
|
|
192
|
-
this.log.warn(`
|
|
227
|
+
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
193
228
|
const reason = validationResult.reason || 'unknown';
|
|
194
229
|
// Classify failure reason: bad proposal vs node issue
|
|
195
230
|
const badProposalReasons = [
|
|
@@ -202,43 +237,97 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
202
237
|
if (badProposalReasons.includes(reason)) {
|
|
203
238
|
this.metrics.incFailedAttestationsBadProposal(1, reason, partOfCommittee);
|
|
204
239
|
} else {
|
|
205
|
-
// Node issues so we can't
|
|
240
|
+
// Node issues so we can't validate
|
|
206
241
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
207
242
|
}
|
|
208
243
|
// Slash invalid block proposals (can happen even when not in committee)
|
|
209
|
-
if (validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
|
|
244
|
+
if (!escapeHatchOpen && validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
|
|
210
245
|
this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
|
|
211
246
|
this.slashInvalidBlock(proposal);
|
|
212
247
|
}
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
this.log.info(`Validated block proposal for slot ${slotNumber}`, {
|
|
251
|
+
...proposalInfo,
|
|
252
|
+
inCommittee: partOfCommittee,
|
|
253
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
254
|
+
escapeHatchOpen
|
|
255
|
+
});
|
|
256
|
+
if (escapeHatchOpen) {
|
|
257
|
+
this.log.warn(`Escape hatch open for slot ${slotNumber}, rejecting block proposal`, proposalInfo);
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
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
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Validate and attest to a checkpoint proposal from a peer.
|
|
267
|
+
* The proposal is received as CheckpointProposalCore (without lastBlock) since
|
|
268
|
+
* the lastBlock is extracted and processed separately via the block handler.
|
|
269
|
+
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
270
|
+
*/ async attestToCheckpointProposal(proposal, _proposalSender) {
|
|
271
|
+
const slotNumber = proposal.slotNumber;
|
|
272
|
+
const proposer = proposal.getSender();
|
|
273
|
+
// If escape hatch is open for this slot's epoch, do not attest.
|
|
274
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
|
|
275
|
+
this.log.warn(`Escape hatch open for slot ${slotNumber}, skipping checkpoint attestation handling`);
|
|
276
|
+
return undefined;
|
|
277
|
+
}
|
|
278
|
+
// Reject proposals with invalid signatures
|
|
279
|
+
if (!proposer) {
|
|
280
|
+
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
213
281
|
return undefined;
|
|
214
282
|
}
|
|
215
283
|
// Check that I have any address in current committee before attesting
|
|
284
|
+
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
285
|
+
const partOfCommittee = inCommittee.length > 0;
|
|
286
|
+
const proposalInfo = {
|
|
287
|
+
slotNumber,
|
|
288
|
+
archive: proposal.archive.toString(),
|
|
289
|
+
proposer: proposer.toString(),
|
|
290
|
+
txCount: proposal.txHashes.length
|
|
291
|
+
};
|
|
292
|
+
this.log.info(`Received checkpoint proposal for slot ${slotNumber}`, {
|
|
293
|
+
...proposalInfo,
|
|
294
|
+
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
295
|
+
fishermanMode: this.config.fishermanMode || false
|
|
296
|
+
});
|
|
297
|
+
// TODO(palla/mbps): Remove this once checkpoint validation is stable.
|
|
298
|
+
// Check that we have successfully validated a block for this slot before attesting to the checkpoint.
|
|
299
|
+
if (!this.validatedBlockSlots.has(slotNumber)) {
|
|
300
|
+
this.log.warn(`No validated block found for slot ${slotNumber}, refusing to attest to checkpoint`, proposalInfo);
|
|
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);
|
|
307
|
+
} else {
|
|
308
|
+
const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
|
|
309
|
+
if (!validationResult.isValid) {
|
|
310
|
+
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
311
|
+
return undefined;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
// Upload blobs to filestore if we can (fire and forget)
|
|
315
|
+
if (this.blobClient.canUpload()) {
|
|
316
|
+
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
317
|
+
}
|
|
318
|
+
// Check that I have any address in current committee before attesting
|
|
216
319
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
217
320
|
if (!partOfCommittee && !this.config.fishermanMode) {
|
|
218
321
|
this.log.verbose(`No validator in the current committee, skipping attestation`, proposalInfo);
|
|
219
322
|
return undefined;
|
|
220
323
|
}
|
|
221
324
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
222
|
-
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} proposal for slot ${slotNumber}`, {
|
|
325
|
+
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${slotNumber}`, {
|
|
223
326
|
...proposalInfo,
|
|
224
327
|
inCommittee: partOfCommittee,
|
|
225
328
|
fishermanMode: this.config.fishermanMode || false
|
|
226
329
|
});
|
|
227
330
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
228
|
-
// Upload blobs to filestore after successful re-execution (fire-and-forget)
|
|
229
|
-
if (validationResult.reexecutionResult?.block && this.fileStoreBlobUploadClient) {
|
|
230
|
-
void Promise.resolve().then(async ()=>{
|
|
231
|
-
try {
|
|
232
|
-
const blobFields = validationResult.reexecutionResult.block.getCheckpointBlobFields();
|
|
233
|
-
const blobs = getBlobsPerL1Block(blobFields);
|
|
234
|
-
await this.fileStoreBlobUploadClient.saveBlobs(blobs, true);
|
|
235
|
-
this.log.debug(`Uploaded ${blobs.length} blobs to filestore from re-execution`, proposalInfo);
|
|
236
|
-
} catch (err) {
|
|
237
|
-
this.log.warn(`Failed to upload blobs from re-execution`, err);
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
// If the above function does not throw an error, then we can attest to the proposal
|
|
242
331
|
// Determine which validators should attest
|
|
243
332
|
let attestors;
|
|
244
333
|
if (partOfCommittee) {
|
|
@@ -255,13 +344,169 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
255
344
|
}
|
|
256
345
|
if (this.config.fishermanMode) {
|
|
257
346
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
258
|
-
this.log.info(`Creating attestations for
|
|
347
|
+
this.log.info(`Creating checkpoint attestations for slot ${slotNumber}`, {
|
|
259
348
|
...proposalInfo,
|
|
260
349
|
attestors: attestors.map((a)=>a.toString())
|
|
261
350
|
});
|
|
262
351
|
return undefined;
|
|
263
352
|
}
|
|
264
|
-
return this.
|
|
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;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
362
|
+
* @returns Validation result with isValid flag and reason if invalid.
|
|
363
|
+
*/ async validateCheckpointProposal(proposal, proposalInfo) {
|
|
364
|
+
const slot = proposal.slotNumber;
|
|
365
|
+
const timeoutSeconds = 10;
|
|
366
|
+
// Wait for last block to sync by archive
|
|
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
|
+
};
|
|
402
|
+
}
|
|
403
|
+
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
404
|
+
...proposalInfo,
|
|
405
|
+
blockNumbers: blocks.map((b)=>b.number)
|
|
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();
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Extract checkpoint global variables from a block.
|
|
475
|
+
*/ extractCheckpointConstants(block) {
|
|
476
|
+
const gv = block.header.globalVariables;
|
|
477
|
+
return {
|
|
478
|
+
chainId: gv.chainId,
|
|
479
|
+
version: gv.version,
|
|
480
|
+
slotNumber: gv.slotNumber,
|
|
481
|
+
coinbase: gv.coinbase,
|
|
482
|
+
feeRecipient: gv.feeRecipient,
|
|
483
|
+
gasFees: gv.gasFees
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
488
|
+
*/ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
|
|
489
|
+
try {
|
|
490
|
+
const lastBlockHeader = await this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
491
|
+
if (!lastBlockHeader) {
|
|
492
|
+
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
const blocks = await this.blockSource.getBlocksForSlot(proposal.slotNumber);
|
|
496
|
+
if (blocks.length === 0) {
|
|
497
|
+
this.log.warn(`No blocks found for blob upload`, proposalInfo);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
const blobFields = blocks.flatMap((b)=>b.toBlobFields());
|
|
501
|
+
const blobs = getBlobsPerL1Block(blobFields);
|
|
502
|
+
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
503
|
+
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
504
|
+
...proposalInfo,
|
|
505
|
+
numBlobs: blobs.length
|
|
506
|
+
});
|
|
507
|
+
} catch (err) {
|
|
508
|
+
this.log.warn(`Failed to upload blobs for checkpoint: ${err}`, proposalInfo);
|
|
509
|
+
}
|
|
265
510
|
}
|
|
266
511
|
slashInvalidBlock(proposal) {
|
|
267
512
|
const proposer = proposal.getSender();
|
|
@@ -285,50 +530,48 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
285
530
|
}
|
|
286
531
|
]);
|
|
287
532
|
}
|
|
288
|
-
|
|
289
|
-
async createBlockProposal(blockNumber, header, archive, txs, proposerAddress, options) {
|
|
533
|
+
async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options) {
|
|
290
534
|
// TODO(palla/mbps): Prevent double proposals properly
|
|
291
|
-
// if (this.previousProposal?.slotNumber ===
|
|
535
|
+
// if (this.previousProposal?.slotNumber === blockHeader.globalVariables.slotNumber) {
|
|
292
536
|
// this.log.verbose(`Already made a proposal for the same slot, skipping proposal`);
|
|
293
537
|
// return Promise.resolve(undefined);
|
|
294
538
|
// }
|
|
295
|
-
this.log.info(`Assembling block proposal for block ${blockNumber} slot ${
|
|
296
|
-
const newProposal = await this.validationService.createBlockProposal(
|
|
539
|
+
this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
|
|
540
|
+
const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
297
541
|
...options,
|
|
298
542
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
299
543
|
});
|
|
300
544
|
this.previousProposal = newProposal;
|
|
301
545
|
return newProposal;
|
|
302
546
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
this.
|
|
306
|
-
return this.createBlockProposal(0, header, archive, txs, proposerAddress, options);
|
|
547
|
+
async createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options) {
|
|
548
|
+
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
549
|
+
return await this.validationService.createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options);
|
|
307
550
|
}
|
|
308
551
|
async broadcastBlockProposal(proposal) {
|
|
309
552
|
await this.p2pClient.broadcastProposal(proposal);
|
|
310
553
|
}
|
|
311
|
-
async signAttestationsAndSigners(attestationsAndSigners, proposer) {
|
|
312
|
-
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
|
|
554
|
+
async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber) {
|
|
555
|
+
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
|
|
313
556
|
}
|
|
314
557
|
async collectOwnAttestations(proposal) {
|
|
315
|
-
const slot = proposal.
|
|
558
|
+
const slot = proposal.slotNumber;
|
|
316
559
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
317
560
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
|
|
318
561
|
inCommittee
|
|
319
562
|
});
|
|
320
|
-
const attestations = await this.
|
|
563
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
321
564
|
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
322
565
|
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
323
566
|
// due to inactivity for missed attestations.
|
|
324
|
-
void this.p2pClient.
|
|
567
|
+
void this.p2pClient.broadcastCheckpointAttestations(attestations).catch((err)=>{
|
|
325
568
|
this.log.error(`Failed to broadcast self-attestations for slot ${slot}`, err);
|
|
326
569
|
});
|
|
327
570
|
return attestations;
|
|
328
571
|
}
|
|
329
572
|
async collectAttestations(proposal, required, deadline) {
|
|
330
|
-
// Wait and poll the p2pClient's attestation pool for this
|
|
331
|
-
const slot = proposal.
|
|
573
|
+
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
574
|
+
const slot = proposal.slotNumber;
|
|
332
575
|
this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
|
|
333
576
|
if (+deadline < this.dateProvider.now()) {
|
|
334
577
|
this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
|
|
@@ -339,13 +582,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
339
582
|
const myAddresses = this.getValidatorAddresses();
|
|
340
583
|
let attestations = [];
|
|
341
584
|
while(true){
|
|
342
|
-
// Filter out attestations with a mismatching
|
|
585
|
+
// Filter out attestations with a mismatching archive. This should NOT happen since we have verified
|
|
343
586
|
// the proposer signature (ie our own) before accepting the attestation into the pool via the p2p client.
|
|
344
|
-
const collectedAttestations = (await this.p2pClient.
|
|
345
|
-
if (!attestation.
|
|
346
|
-
this.log.warn(`Received attestation for slot ${slot} with mismatched
|
|
347
|
-
|
|
348
|
-
|
|
587
|
+
const collectedAttestations = (await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalId)).filter((attestation)=>{
|
|
588
|
+
if (!attestation.archive.equals(proposal.archive)) {
|
|
589
|
+
this.log.warn(`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`, {
|
|
590
|
+
attestationArchive: attestation.archive.toString(),
|
|
591
|
+
proposalArchive: proposal.archive.toString()
|
|
349
592
|
});
|
|
350
593
|
return false;
|
|
351
594
|
}
|
|
@@ -377,11 +620,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
377
620
|
await sleep(this.config.attestationPollingIntervalMs);
|
|
378
621
|
}
|
|
379
622
|
}
|
|
380
|
-
async createBlockAttestationsFromProposal(proposal, attestors = []) {
|
|
381
|
-
const attestations = await this.validationService.attestToProposal(proposal, attestors);
|
|
382
|
-
await this.p2pClient.addAttestations(attestations);
|
|
383
|
-
return attestations;
|
|
384
|
-
}
|
|
385
623
|
async handleAuthRequest(peer, msg) {
|
|
386
624
|
const authRequest = AuthRequest.fromBuffer(msg);
|
|
387
625
|
const statusMessage = await this.p2pClient.handleAuthRequestFromPeer(authRequest, peer).catch((_)=>undefined);
|
|
@@ -396,7 +634,11 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
396
634
|
return Buffer.alloc(0);
|
|
397
635
|
}
|
|
398
636
|
const payloadToSign = authRequest.getPayloadToSign();
|
|
399
|
-
|
|
637
|
+
// AUTH_REQUEST doesn't require HA protection - multiple signatures are safe
|
|
638
|
+
const context = {
|
|
639
|
+
dutyType: DutyType.AUTH_REQUEST
|
|
640
|
+
};
|
|
641
|
+
const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign, context);
|
|
400
642
|
const authResponse = new AuthResponse(statusMessage, signature);
|
|
401
643
|
return authResponse.toBuffer();
|
|
402
644
|
}
|
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.0b941701",
|
|
4
4
|
"main": "dest/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -64,27 +64,33 @@
|
|
|
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/
|
|
75
|
-
"@aztec/
|
|
76
|
-
"@aztec/
|
|
77
|
-
"@aztec/
|
|
67
|
+
"@aztec/blob-client": "0.0.1-commit.0b941701",
|
|
68
|
+
"@aztec/blob-lib": "0.0.1-commit.0b941701",
|
|
69
|
+
"@aztec/constants": "0.0.1-commit.0b941701",
|
|
70
|
+
"@aztec/epoch-cache": "0.0.1-commit.0b941701",
|
|
71
|
+
"@aztec/ethereum": "0.0.1-commit.0b941701",
|
|
72
|
+
"@aztec/foundation": "0.0.1-commit.0b941701",
|
|
73
|
+
"@aztec/node-keystore": "0.0.1-commit.0b941701",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.0b941701",
|
|
75
|
+
"@aztec/p2p": "0.0.1-commit.0b941701",
|
|
76
|
+
"@aztec/protocol-contracts": "0.0.1-commit.0b941701",
|
|
77
|
+
"@aztec/prover-client": "0.0.1-commit.0b941701",
|
|
78
|
+
"@aztec/simulator": "0.0.1-commit.0b941701",
|
|
79
|
+
"@aztec/slasher": "0.0.1-commit.0b941701",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.0b941701",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.0b941701",
|
|
82
|
+
"@aztec/validator-ha-signer": "0.0.1-commit.0b941701",
|
|
78
83
|
"koa": "^2.16.1",
|
|
79
84
|
"koa-router": "^13.1.1",
|
|
80
85
|
"tslib": "^2.4.0",
|
|
81
86
|
"viem": "npm:@aztec/viem@2.38.2"
|
|
82
87
|
},
|
|
83
88
|
"devDependencies": {
|
|
89
|
+
"@electric-sql/pglite": "^0.3.14",
|
|
84
90
|
"@jest/globals": "^30.0.0",
|
|
85
91
|
"@types/jest": "^30.0.0",
|
|
86
92
|
"@types/node": "^22.15.17",
|
|
87
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
93
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
88
94
|
"jest": "^30.0.0",
|
|
89
95
|
"jest-mock-extended": "^4.0.0",
|
|
90
96
|
"ts-node": "^10.9.1",
|