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