@aztec/validator-client 0.0.1-commit.9593d84 → 0.0.1-commit.96bb3f7
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 +256 -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 +336 -75
- package/dest/checkpoint_builder.d.ts +70 -0
- package/dest/checkpoint_builder.d.ts.map +1 -0
- package/dest/checkpoint_builder.js +155 -0
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +10 -0
- package/dest/duties/validation_service.d.ts +27 -11
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +53 -23
- package/dest/factory.d.ts +12 -7
- 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/local_key_store.js +1 -1
- package/dest/key_store/web3signer_key_store.js +1 -1
- 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 +53 -0
- package/dest/validator.d.ts +42 -14
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +304 -47
- package/package.json +18 -12
- package/src/block_proposal_handler.ts +258 -43
- package/src/checkpoint_builder.ts +267 -0
- package/src/config.ts +10 -0
- package/src/duties/validation_service.ts +81 -27
- package/src/factory.ts +16 -8
- package/src/index.ts +2 -0
- package/src/key_store/local_key_store.ts +1 -1
- package/src/key_store/node_keystore_adapter.ts +1 -1
- package/src/key_store/web3signer_key_store.ts +1 -1
- 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 +133 -0
- package/src/validator.ts +416 -71
package/dest/validator.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
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';
|
|
@@ -26,7 +30,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
26
30
|
epochCache;
|
|
27
31
|
p2pClient;
|
|
28
32
|
blockProposalHandler;
|
|
33
|
+
blockSource;
|
|
34
|
+
checkpointsBuilder;
|
|
35
|
+
worldState;
|
|
36
|
+
l1ToL2MessageSource;
|
|
29
37
|
config;
|
|
38
|
+
blobClient;
|
|
30
39
|
dateProvider;
|
|
31
40
|
tracer;
|
|
32
41
|
validationService;
|
|
@@ -39,8 +48,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
39
48
|
lastEpochForCommitteeUpdateLoop;
|
|
40
49
|
epochCacheUpdateLoop;
|
|
41
50
|
proposersOfInvalidBlocks;
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
// TODO(palla/mbps): Remove this once checkpoint validation is stable and we can validate all blocks properly.
|
|
52
|
+
// Tracks slots for which we have successfully validated a block proposal, so we can attest to checkpoint proposals for those slots.
|
|
53
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
54
|
+
validatedBlockSlots;
|
|
55
|
+
constructor(keyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
56
|
+
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
57
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
45
58
|
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
46
59
|
this.tracer = telemetry.getTracer('Validator');
|
|
@@ -94,13 +107,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
94
107
|
this.log.error(`Error updating epoch committee`, err);
|
|
95
108
|
}
|
|
96
109
|
}
|
|
97
|
-
static new(config,
|
|
110
|
+
static new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
98
111
|
const metrics = new ValidatorMetrics(telemetry);
|
|
99
112
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
100
113
|
txsPermitted: !config.disableTransactions
|
|
101
114
|
});
|
|
102
|
-
const blockProposalHandler = new BlockProposalHandler(
|
|
103
|
-
const validator = new ValidatorClient(NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager), epochCache, p2pClient, blockProposalHandler, config, dateProvider, telemetry);
|
|
115
|
+
const blockProposalHandler = new BlockProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, config, metrics, dateProvider, telemetry);
|
|
116
|
+
const validator = new ValidatorClient(NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager), epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider, telemetry);
|
|
104
117
|
return validator;
|
|
105
118
|
}
|
|
106
119
|
getValidatorAddresses() {
|
|
@@ -109,10 +122,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
109
122
|
getBlockProposalHandler() {
|
|
110
123
|
return this.blockProposalHandler;
|
|
111
124
|
}
|
|
112
|
-
// Proxy method for backwards compatibility with tests
|
|
113
|
-
reExecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages) {
|
|
114
|
-
return this.blockProposalHandler.reexecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages);
|
|
115
|
-
}
|
|
116
125
|
signWithAddress(addr, msg) {
|
|
117
126
|
return this.keyStore.signTypedDataWithAddress(addr, msg);
|
|
118
127
|
}
|
|
@@ -153,41 +162,50 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
153
162
|
if (!this.hasRegisteredHandlers) {
|
|
154
163
|
this.hasRegisteredHandlers = true;
|
|
155
164
|
this.log.debug(`Registering validator handlers for p2p client`);
|
|
156
|
-
|
|
157
|
-
this.
|
|
165
|
+
// Block proposal handler - validates but does NOT attest (validators only attest to checkpoints)
|
|
166
|
+
const blockHandler = (block, proposalSender)=>this.validateBlockProposal(block, proposalSender);
|
|
167
|
+
this.p2pClient.registerBlockProposalHandler(blockHandler);
|
|
168
|
+
// Checkpoint proposal handler - validates and creates attestations
|
|
169
|
+
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
170
|
+
// and processed separately via the block handler above.
|
|
171
|
+
const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
172
|
+
this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
|
|
158
173
|
const myAddresses = this.getValidatorAddresses();
|
|
159
174
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
160
175
|
await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
|
|
161
176
|
}
|
|
162
177
|
}
|
|
163
|
-
|
|
178
|
+
/**
|
|
179
|
+
* Validate a block proposal from a peer.
|
|
180
|
+
* Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
|
|
181
|
+
* @returns true if the proposal is valid, false otherwise
|
|
182
|
+
*/ async validateBlockProposal(proposal, proposalSender) {
|
|
164
183
|
const slotNumber = proposal.slotNumber;
|
|
165
184
|
const proposer = proposal.getSender();
|
|
166
185
|
// Reject proposals with invalid signatures
|
|
167
186
|
if (!proposer) {
|
|
168
|
-
this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
|
|
169
|
-
return
|
|
187
|
+
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
188
|
+
return false;
|
|
170
189
|
}
|
|
171
|
-
// Check
|
|
190
|
+
// Check if we're in the committee (for metrics purposes)
|
|
172
191
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
173
192
|
const partOfCommittee = inCommittee.length > 0;
|
|
174
193
|
const proposalInfo = {
|
|
175
194
|
...proposal.toBlockInfo(),
|
|
176
195
|
proposer: proposer.toString()
|
|
177
196
|
};
|
|
178
|
-
this.log.info(`Received proposal for slot ${slotNumber}`, {
|
|
197
|
+
this.log.info(`Received block proposal for slot ${slotNumber}`, {
|
|
179
198
|
...proposalInfo,
|
|
180
199
|
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
181
200
|
fishermanMode: this.config.fishermanMode || false
|
|
182
201
|
});
|
|
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.
|
|
202
|
+
// Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
|
|
185
203
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
186
204
|
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
187
|
-
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals;
|
|
205
|
+
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
|
|
188
206
|
const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute);
|
|
189
207
|
if (!validationResult.isValid) {
|
|
190
|
-
this.log.warn(`
|
|
208
|
+
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
191
209
|
const reason = validationResult.reason || 'unknown';
|
|
192
210
|
// Classify failure reason: bad proposal vs node issue
|
|
193
211
|
const badProposalReasons = [
|
|
@@ -200,7 +218,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
200
218
|
if (badProposalReasons.includes(reason)) {
|
|
201
219
|
this.metrics.incFailedAttestationsBadProposal(1, reason, partOfCommittee);
|
|
202
220
|
} else {
|
|
203
|
-
// Node issues so we can't
|
|
221
|
+
// Node issues so we can't validate
|
|
204
222
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
205
223
|
}
|
|
206
224
|
// Slash invalid block proposals (can happen even when not in committee)
|
|
@@ -208,8 +226,66 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
208
226
|
this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
|
|
209
227
|
this.slashInvalidBlock(proposal);
|
|
210
228
|
}
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
this.log.info(`Validated block proposal for slot ${slotNumber}`, {
|
|
232
|
+
...proposalInfo,
|
|
233
|
+
inCommittee: partOfCommittee,
|
|
234
|
+
fishermanMode: this.config.fishermanMode || false
|
|
235
|
+
});
|
|
236
|
+
// TODO(palla/mbps): Remove this once checkpoint validation is stable.
|
|
237
|
+
// Track that we successfully validated a block for this slot, so we can attest to checkpoint proposals for it.
|
|
238
|
+
this.validatedBlockSlots.add(slotNumber);
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Validate and attest to a checkpoint proposal from a peer.
|
|
243
|
+
* The proposal is received as CheckpointProposalCore (without lastBlock) since
|
|
244
|
+
* the lastBlock is extracted and processed separately via the block handler.
|
|
245
|
+
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
246
|
+
*/ async attestToCheckpointProposal(proposal, _proposalSender) {
|
|
247
|
+
const slotNumber = proposal.slotNumber;
|
|
248
|
+
const proposer = proposal.getSender();
|
|
249
|
+
// Reject proposals with invalid signatures
|
|
250
|
+
if (!proposer) {
|
|
251
|
+
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
252
|
+
return undefined;
|
|
253
|
+
}
|
|
254
|
+
// Check that I have any address in current committee before attesting
|
|
255
|
+
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
256
|
+
const partOfCommittee = inCommittee.length > 0;
|
|
257
|
+
const proposalInfo = {
|
|
258
|
+
slotNumber,
|
|
259
|
+
archive: proposal.archive.toString(),
|
|
260
|
+
proposer: proposer.toString(),
|
|
261
|
+
txCount: proposal.txHashes.length
|
|
262
|
+
};
|
|
263
|
+
this.log.info(`Received checkpoint proposal for slot ${slotNumber}`, {
|
|
264
|
+
...proposalInfo,
|
|
265
|
+
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
266
|
+
fishermanMode: this.config.fishermanMode || false
|
|
267
|
+
});
|
|
268
|
+
// TODO(palla/mbps): Remove this once checkpoint validation is stable.
|
|
269
|
+
// Check that we have successfully validated a block for this slot before attesting to the checkpoint.
|
|
270
|
+
if (!this.validatedBlockSlots.has(slotNumber)) {
|
|
271
|
+
this.log.warn(`No validated block found for slot ${slotNumber}, refusing to attest to checkpoint`, proposalInfo);
|
|
211
272
|
return undefined;
|
|
212
273
|
}
|
|
274
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
275
|
+
// TODO(palla/mbps): Change default to false once checkpoint validation is stable.
|
|
276
|
+
if (this.config.skipCheckpointProposalValidation !== false) {
|
|
277
|
+
this.log.verbose(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
|
|
278
|
+
} else {
|
|
279
|
+
const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
|
|
280
|
+
if (!validationResult.isValid) {
|
|
281
|
+
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
282
|
+
return undefined;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
// Upload blobs to filestore if we can (fire and forget)
|
|
286
|
+
if (this.blobClient.canUpload()) {
|
|
287
|
+
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
288
|
+
}
|
|
213
289
|
// Check that I have any address in current committee before attesting
|
|
214
290
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
215
291
|
if (!partOfCommittee && !this.config.fishermanMode) {
|
|
@@ -217,13 +293,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
217
293
|
return undefined;
|
|
218
294
|
}
|
|
219
295
|
// 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}`, {
|
|
296
|
+
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${slotNumber}`, {
|
|
221
297
|
...proposalInfo,
|
|
222
298
|
inCommittee: partOfCommittee,
|
|
223
299
|
fishermanMode: this.config.fishermanMode || false
|
|
224
300
|
});
|
|
225
301
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
226
|
-
// If the above function does not throw an error, then we can attest to the proposal
|
|
227
302
|
// Determine which validators should attest
|
|
228
303
|
let attestors;
|
|
229
304
|
if (partOfCommittee) {
|
|
@@ -240,13 +315,194 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
240
315
|
}
|
|
241
316
|
if (this.config.fishermanMode) {
|
|
242
317
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
243
|
-
this.log.info(`Creating attestations for
|
|
318
|
+
this.log.info(`Creating checkpoint attestations for slot ${slotNumber}`, {
|
|
244
319
|
...proposalInfo,
|
|
245
320
|
attestors: attestors.map((a)=>a.toString())
|
|
246
321
|
});
|
|
247
322
|
return undefined;
|
|
248
323
|
}
|
|
249
|
-
return this.
|
|
324
|
+
return this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
325
|
+
}
|
|
326
|
+
async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
|
|
327
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
328
|
+
await this.p2pClient.addCheckpointAttestations(attestations);
|
|
329
|
+
return attestations;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
333
|
+
* @returns Validation result with isValid flag and reason if invalid.
|
|
334
|
+
*/ async validateCheckpointProposal(proposal, proposalInfo) {
|
|
335
|
+
const slot = proposal.slotNumber;
|
|
336
|
+
const timeoutSeconds = 10;
|
|
337
|
+
// Wait for last block to sync by archive
|
|
338
|
+
let lastBlockHeader;
|
|
339
|
+
try {
|
|
340
|
+
lastBlockHeader = await retryUntil(async ()=>{
|
|
341
|
+
await this.blockSource.syncImmediate();
|
|
342
|
+
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
343
|
+
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, timeoutSeconds, 0.5);
|
|
344
|
+
} catch (err) {
|
|
345
|
+
if (err instanceof TimeoutError) {
|
|
346
|
+
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
347
|
+
return {
|
|
348
|
+
isValid: false,
|
|
349
|
+
reason: 'last_block_not_found'
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
353
|
+
return {
|
|
354
|
+
isValid: false,
|
|
355
|
+
reason: 'block_fetch_error'
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
if (!lastBlockHeader) {
|
|
359
|
+
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
360
|
+
return {
|
|
361
|
+
isValid: false,
|
|
362
|
+
reason: 'last_block_not_found'
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
// Get the last full block to determine checkpoint number
|
|
366
|
+
const lastBlock = await this.blockSource.getL2BlockNew(lastBlockHeader.getBlockNumber());
|
|
367
|
+
if (!lastBlock) {
|
|
368
|
+
this.log.warn(`Last block ${lastBlockHeader.getBlockNumber()} not found`, proposalInfo);
|
|
369
|
+
return {
|
|
370
|
+
isValid: false,
|
|
371
|
+
reason: 'last_block_not_found'
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
const checkpointNumber = lastBlock.checkpointNumber;
|
|
375
|
+
// Get all full blocks for the slot and checkpoint
|
|
376
|
+
const blocks = await this.getBlocksForSlot(slot, lastBlockHeader, checkpointNumber);
|
|
377
|
+
if (blocks.length === 0) {
|
|
378
|
+
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
379
|
+
return {
|
|
380
|
+
isValid: false,
|
|
381
|
+
reason: 'no_blocks_for_slot'
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
385
|
+
...proposalInfo,
|
|
386
|
+
blockNumbers: blocks.map((b)=>b.number)
|
|
387
|
+
});
|
|
388
|
+
// Get checkpoint constants from first block
|
|
389
|
+
const firstBlock = blocks[0];
|
|
390
|
+
const constants = this.extractCheckpointConstants(firstBlock);
|
|
391
|
+
// Get L1-to-L2 messages for this checkpoint
|
|
392
|
+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
393
|
+
// Fork world state at the block before the first block
|
|
394
|
+
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
395
|
+
const fork = await this.worldState.fork(parentBlockNumber);
|
|
396
|
+
try {
|
|
397
|
+
// Create checkpoint builder with all existing blocks
|
|
398
|
+
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, l1ToL2Messages, fork, blocks);
|
|
399
|
+
// Complete the checkpoint to get computed values
|
|
400
|
+
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
401
|
+
// Compare checkpoint header with proposal
|
|
402
|
+
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
403
|
+
this.log.warn(`Checkpoint header mismatch`, {
|
|
404
|
+
...proposalInfo,
|
|
405
|
+
computed: computedCheckpoint.header.toInspect(),
|
|
406
|
+
proposal: proposal.checkpointHeader.toInspect()
|
|
407
|
+
});
|
|
408
|
+
return {
|
|
409
|
+
isValid: false,
|
|
410
|
+
reason: 'checkpoint_header_mismatch'
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
// Compare archive root with proposal
|
|
414
|
+
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
415
|
+
this.log.warn(`Archive root mismatch`, {
|
|
416
|
+
...proposalInfo,
|
|
417
|
+
computed: computedCheckpoint.archive.root.toString(),
|
|
418
|
+
proposal: proposal.archive.toString()
|
|
419
|
+
});
|
|
420
|
+
return {
|
|
421
|
+
isValid: false,
|
|
422
|
+
reason: 'archive_mismatch'
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
426
|
+
return {
|
|
427
|
+
isValid: true
|
|
428
|
+
};
|
|
429
|
+
} finally{
|
|
430
|
+
await fork.close();
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Get all full blocks for a given slot and checkpoint by walking backwards from the last block.
|
|
435
|
+
* Returns blocks in ascending order (earliest to latest).
|
|
436
|
+
* TODO(palla/mbps): Add getL2BlocksForSlot() to L2BlockSource interface for efficiency.
|
|
437
|
+
*/ async getBlocksForSlot(slot, lastBlockHeader, checkpointNumber) {
|
|
438
|
+
const blocks = [];
|
|
439
|
+
let currentHeader = lastBlockHeader;
|
|
440
|
+
const { genesisArchiveRoot } = await this.blockSource.getGenesisValues();
|
|
441
|
+
while(currentHeader.getSlot() === slot){
|
|
442
|
+
const block = await this.blockSource.getL2BlockNew(currentHeader.getBlockNumber());
|
|
443
|
+
if (!block) {
|
|
444
|
+
this.log.warn(`Block ${currentHeader.getBlockNumber()} not found while getting blocks for slot ${slot}`);
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
if (block.checkpointNumber !== checkpointNumber) {
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
blocks.unshift(block);
|
|
451
|
+
const prevArchive = currentHeader.lastArchive.root;
|
|
452
|
+
if (prevArchive.equals(genesisArchiveRoot)) {
|
|
453
|
+
break;
|
|
454
|
+
}
|
|
455
|
+
const prevHeader = await this.blockSource.getBlockHeaderByArchive(prevArchive);
|
|
456
|
+
if (!prevHeader || prevHeader.getSlot() !== slot) {
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
currentHeader = prevHeader;
|
|
460
|
+
}
|
|
461
|
+
return blocks;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Extract checkpoint global variables from a block.
|
|
465
|
+
*/ extractCheckpointConstants(block) {
|
|
466
|
+
const gv = block.header.globalVariables;
|
|
467
|
+
return {
|
|
468
|
+
chainId: gv.chainId,
|
|
469
|
+
version: gv.version,
|
|
470
|
+
slotNumber: gv.slotNumber,
|
|
471
|
+
coinbase: gv.coinbase,
|
|
472
|
+
feeRecipient: gv.feeRecipient,
|
|
473
|
+
gasFees: gv.gasFees
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
478
|
+
*/ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
|
|
479
|
+
try {
|
|
480
|
+
const lastBlockHeader = await this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
481
|
+
if (!lastBlockHeader) {
|
|
482
|
+
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
// Get the last full block to determine checkpoint number
|
|
486
|
+
const lastBlock = await this.blockSource.getL2BlockNew(lastBlockHeader.getBlockNumber());
|
|
487
|
+
if (!lastBlock) {
|
|
488
|
+
this.log.warn(`Failed to get last block for blob upload`, proposalInfo);
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
const blocks = await this.getBlocksForSlot(proposal.slotNumber, lastBlockHeader, lastBlock.checkpointNumber);
|
|
492
|
+
if (blocks.length === 0) {
|
|
493
|
+
this.log.warn(`No blocks found for blob upload`, proposalInfo);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
const blobFields = blocks.flatMap((b)=>b.toBlobFields());
|
|
497
|
+
const blobs = getBlobsPerL1Block(blobFields);
|
|
498
|
+
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
499
|
+
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
500
|
+
...proposalInfo,
|
|
501
|
+
numBlobs: blobs.length
|
|
502
|
+
});
|
|
503
|
+
} catch (err) {
|
|
504
|
+
this.log.warn(`Failed to upload blobs for checkpoint: ${err}`, proposalInfo);
|
|
505
|
+
}
|
|
250
506
|
}
|
|
251
507
|
slashInvalidBlock(proposal) {
|
|
252
508
|
const proposer = proposal.getSender();
|
|
@@ -270,18 +526,24 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
270
526
|
}
|
|
271
527
|
]);
|
|
272
528
|
}
|
|
273
|
-
async createBlockProposal(
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
529
|
+
async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options) {
|
|
530
|
+
// TODO(palla/mbps): Prevent double proposals properly
|
|
531
|
+
// if (this.previousProposal?.slotNumber === blockHeader.globalVariables.slotNumber) {
|
|
532
|
+
// this.log.verbose(`Already made a proposal for the same slot, skipping proposal`);
|
|
533
|
+
// return Promise.resolve(undefined);
|
|
534
|
+
// }
|
|
535
|
+
this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
|
|
536
|
+
const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
279
537
|
...options,
|
|
280
538
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
281
539
|
});
|
|
282
540
|
this.previousProposal = newProposal;
|
|
283
541
|
return newProposal;
|
|
284
542
|
}
|
|
543
|
+
async createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options) {
|
|
544
|
+
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
545
|
+
return await this.validationService.createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options);
|
|
546
|
+
}
|
|
285
547
|
async broadcastBlockProposal(proposal) {
|
|
286
548
|
await this.p2pClient.broadcastProposal(proposal);
|
|
287
549
|
}
|
|
@@ -289,23 +551,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
289
551
|
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
|
|
290
552
|
}
|
|
291
553
|
async collectOwnAttestations(proposal) {
|
|
292
|
-
const slot = proposal.
|
|
554
|
+
const slot = proposal.slotNumber;
|
|
293
555
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
294
556
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
|
|
295
557
|
inCommittee
|
|
296
558
|
});
|
|
297
|
-
const attestations = await this.
|
|
559
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
298
560
|
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
299
561
|
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
300
562
|
// due to inactivity for missed attestations.
|
|
301
|
-
void this.p2pClient.
|
|
563
|
+
void this.p2pClient.broadcastCheckpointAttestations(attestations).catch((err)=>{
|
|
302
564
|
this.log.error(`Failed to broadcast self-attestations for slot ${slot}`, err);
|
|
303
565
|
});
|
|
304
566
|
return attestations;
|
|
305
567
|
}
|
|
306
568
|
async collectAttestations(proposal, required, deadline) {
|
|
307
|
-
// Wait and poll the p2pClient's attestation pool for this
|
|
308
|
-
const slot = proposal.
|
|
569
|
+
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
570
|
+
const slot = proposal.slotNumber;
|
|
309
571
|
this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
|
|
310
572
|
if (+deadline < this.dateProvider.now()) {
|
|
311
573
|
this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
|
|
@@ -316,13 +578,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
316
578
|
const myAddresses = this.getValidatorAddresses();
|
|
317
579
|
let attestations = [];
|
|
318
580
|
while(true){
|
|
319
|
-
// Filter out attestations with a mismatching
|
|
581
|
+
// Filter out attestations with a mismatching archive. This should NOT happen since we have verified
|
|
320
582
|
// 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
|
-
|
|
583
|
+
const collectedAttestations = (await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalId)).filter((attestation)=>{
|
|
584
|
+
if (!attestation.archive.equals(proposal.archive)) {
|
|
585
|
+
this.log.warn(`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`, {
|
|
586
|
+
attestationArchive: attestation.archive.toString(),
|
|
587
|
+
proposalArchive: proposal.archive.toString()
|
|
326
588
|
});
|
|
327
589
|
return false;
|
|
328
590
|
}
|
|
@@ -354,11 +616,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
354
616
|
await sleep(this.config.attestationPollingIntervalMs);
|
|
355
617
|
}
|
|
356
618
|
}
|
|
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
619
|
async handleAuthRequest(peer, msg) {
|
|
363
620
|
const authRequest = AuthRequest.fromBuffer(msg);
|
|
364
621
|
const statusMessage = await this.p2pClient.handleAuthRequestFromPeer(authRequest, peer).catch((_)=>undefined);
|
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.96bb3f7",
|
|
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,15 +64,21 @@
|
|
|
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.96bb3f7",
|
|
68
|
+
"@aztec/blob-lib": "0.0.1-commit.96bb3f7",
|
|
69
|
+
"@aztec/constants": "0.0.1-commit.96bb3f7",
|
|
70
|
+
"@aztec/epoch-cache": "0.0.1-commit.96bb3f7",
|
|
71
|
+
"@aztec/ethereum": "0.0.1-commit.96bb3f7",
|
|
72
|
+
"@aztec/foundation": "0.0.1-commit.96bb3f7",
|
|
73
|
+
"@aztec/node-keystore": "0.0.1-commit.96bb3f7",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.96bb3f7",
|
|
75
|
+
"@aztec/p2p": "0.0.1-commit.96bb3f7",
|
|
76
|
+
"@aztec/protocol-contracts": "0.0.1-commit.96bb3f7",
|
|
77
|
+
"@aztec/prover-client": "0.0.1-commit.96bb3f7",
|
|
78
|
+
"@aztec/simulator": "0.0.1-commit.96bb3f7",
|
|
79
|
+
"@aztec/slasher": "0.0.1-commit.96bb3f7",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.96bb3f7",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.96bb3f7",
|
|
76
82
|
"koa": "^2.16.1",
|
|
77
83
|
"koa-router": "^13.1.1",
|
|
78
84
|
"tslib": "^2.4.0",
|