@aztec/validator-client 0.0.1-commit.ef17749e1 → 0.0.1-commit.f1b29a41e
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 +9 -12
- package/dest/checkpoint_builder.d.ts +10 -7
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +64 -41
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +0 -5
- package/dest/duties/validation_service.js +1 -1
- package/dest/factory.d.ts +7 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +5 -5
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/key_store/ha_key_store.js +1 -1
- package/dest/metrics.d.ts +2 -2
- package/dest/metrics.d.ts.map +1 -1
- package/dest/proposal_handler.d.ts +107 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/{block_proposal_handler.js → proposal_handler.js} +425 -13
- package/dest/validator.d.ts +8 -13
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +43 -215
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +79 -52
- package/src/config.ts +0 -5
- package/src/duties/validation_service.ts +1 -1
- package/src/factory.ts +9 -4
- package/src/index.ts +1 -1
- package/src/key_store/ha_key_store.ts +1 -1
- package/src/metrics.ts +1 -1
- package/src/{block_proposal_handler.ts → proposal_handler.ts} +487 -14
- package/src/validator.ts +60 -234
- package/dest/block_proposal_handler.d.ts +0 -63
- package/dest/block_proposal_handler.d.ts.map +0 -1
package/dest/validator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAErE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC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aAAa,EAAE,qCAAqC,GAAG,SAAS,EAChE,eAAe,EAAE,UAAU,GAAG,SAAS,EACvC,OAAO,GAAE,yBAA8B,GACtC,OAAO,CAAC,kBAAkB,CAAC,CAyB7B;IAEK,sBAAsB,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAEnE;IAEK,0BAA0B,CAC9B,sBAAsB,EAAE,+BAA+B,EACvD,QAAQ,EAAE,UAAU,EACpB,IAAI,EAAE,UAAU,EAChB,WAAW,EAAE,WAAW,GAAG,gBAAgB,GAC1C,OAAO,CAAC,SAAS,CAAC,CAEpB;IAEK,sBAAsB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAiB3F;IAEK,mBAAmB,CACvB,QAAQ,EAAE,kBAAkB,EAC5B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,IAAI,GACb,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAiElC;YAEa,iBAAiB;CAwBhC"}
|
package/dest/validator.js
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
1
|
import { getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
2
|
-
import { validateFeeAssetPriceModifier } from '@aztec/ethereum/contracts';
|
|
3
|
-
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
|
-
import { TimeoutError } from '@aztec/foundation/error';
|
|
5
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
7
3
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
8
4
|
import { sleep } from '@aztec/foundation/sleep';
|
|
9
5
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
10
6
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
11
7
|
import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
|
|
12
|
-
import {
|
|
13
|
-
import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
14
|
-
import { accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
|
|
8
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
15
9
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
16
10
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
17
|
-
import { createHASigner, createLocalSignerWithProtection } from '@aztec/validator-ha-signer/factory';
|
|
11
|
+
import { createHASigner, createLocalSignerWithProtection, createSignerFromSharedDb } from '@aztec/validator-ha-signer/factory';
|
|
18
12
|
import { DutyType } from '@aztec/validator-ha-signer/types';
|
|
19
13
|
import { EventEmitter } from 'events';
|
|
20
|
-
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
21
14
|
import { ValidationService } from './duties/validation_service.js';
|
|
22
15
|
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
23
16
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
24
17
|
import { ValidatorMetrics } from './metrics.js';
|
|
18
|
+
import { ProposalHandler } from './proposal_handler.js';
|
|
25
19
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
26
20
|
// Just cap the set to avoid unbounded growth.
|
|
27
21
|
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
@@ -36,7 +30,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
36
30
|
keyStore;
|
|
37
31
|
epochCache;
|
|
38
32
|
p2pClient;
|
|
39
|
-
|
|
33
|
+
proposalHandler;
|
|
40
34
|
blockSource;
|
|
41
35
|
checkpointsBuilder;
|
|
42
36
|
worldState;
|
|
@@ -58,8 +52,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
58
52
|
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */ lastAttestedEpochByAttester;
|
|
59
53
|
proposersOfInvalidBlocks;
|
|
60
54
|
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */ lastAttestedProposal;
|
|
61
|
-
constructor(keyStore, epochCache, p2pClient,
|
|
62
|
-
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.
|
|
55
|
+
constructor(keyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
56
|
+
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.proposalHandler = proposalHandler, this.blockSource = blockSource, this.checkpointsBuilder = checkpointsBuilder, this.worldState = worldState, this.l1ToL2MessageSource = l1ToL2MessageSource, this.config = config, this.blobClient = blobClient, this.slashingProtectionSigner = slashingProtectionSigner, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.lastAttestedEpochByAttester = new Map(), this.proposersOfInvalidBlocks = new Set();
|
|
63
57
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
64
58
|
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
65
59
|
this.tracer = telemetry.getTracer('Validator');
|
|
@@ -114,16 +108,22 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
114
108
|
this.log.error(`Error updating epoch committee`, err);
|
|
115
109
|
}
|
|
116
110
|
}
|
|
117
|
-
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
111
|
+
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), slashingProtectionDb) {
|
|
118
112
|
const metrics = new ValidatorMetrics(telemetry);
|
|
119
113
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
120
114
|
txsPermitted: !config.disableTransactions,
|
|
121
115
|
maxTxsPerBlock: config.validateMaxTxsPerBlock
|
|
122
116
|
});
|
|
123
|
-
const
|
|
117
|
+
const proposalHandler = new ProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, blobClient, metrics, dateProvider, telemetry);
|
|
124
118
|
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
125
119
|
let slashingProtectionSigner;
|
|
126
|
-
if (
|
|
120
|
+
if (slashingProtectionDb) {
|
|
121
|
+
// Shared database mode: use a pre-existing database (e.g. for testing HA setups).
|
|
122
|
+
({ signer: slashingProtectionSigner } = createSignerFromSharedDb(slashingProtectionDb, config, {
|
|
123
|
+
telemetryClient: telemetry,
|
|
124
|
+
dateProvider
|
|
125
|
+
}));
|
|
126
|
+
} else if (config.haSigningEnabled) {
|
|
127
127
|
// Multi-node HA mode: use PostgreSQL-backed distributed locking.
|
|
128
128
|
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
129
129
|
const haConfig = {
|
|
@@ -143,14 +143,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
143
143
|
}));
|
|
144
144
|
}
|
|
145
145
|
const validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, slashingProtectionSigner);
|
|
146
|
-
const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient,
|
|
146
|
+
const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider, telemetry);
|
|
147
147
|
return validator;
|
|
148
148
|
}
|
|
149
149
|
getValidatorAddresses() {
|
|
150
150
|
return this.keyStore.getAddresses().filter((addr)=>!this.config.disabledValidators.some((disabled)=>disabled.equals(addr)));
|
|
151
151
|
}
|
|
152
|
-
|
|
153
|
-
return this.
|
|
152
|
+
getProposalHandler() {
|
|
153
|
+
return this.proposalHandler;
|
|
154
154
|
}
|
|
155
155
|
signWithAddress(addr, msg, context) {
|
|
156
156
|
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
@@ -206,7 +206,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
206
206
|
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
207
207
|
// and processed separately via the block handler above.
|
|
208
208
|
const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
209
|
-
this.p2pClient.
|
|
209
|
+
this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
|
|
210
210
|
// Duplicate proposal handler - triggers slashing for equivocation
|
|
211
211
|
this.p2pClient.registerDuplicateProposalCallback((info)=>{
|
|
212
212
|
this.handleDuplicateProposal(info);
|
|
@@ -235,13 +235,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
235
235
|
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
236
236
|
return false;
|
|
237
237
|
}
|
|
238
|
-
//
|
|
238
|
+
// Log self-proposals from HA peers (same validator key on different nodes)
|
|
239
239
|
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
240
|
-
this.log.
|
|
240
|
+
this.log.verbose(`Processing block proposal from HA peer for slot ${slotNumber}`, {
|
|
241
241
|
proposer: proposer.toString(),
|
|
242
242
|
slotNumber
|
|
243
243
|
});
|
|
244
|
-
return false;
|
|
245
244
|
}
|
|
246
245
|
// Check if we're in the committee (for metrics purposes)
|
|
247
246
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
@@ -257,12 +256,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
257
256
|
});
|
|
258
257
|
// Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
|
|
259
258
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
260
|
-
const {
|
|
261
|
-
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n
|
|
262
|
-
const validationResult = await this.
|
|
259
|
+
const { slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
260
|
+
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n || partOfCommittee || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
|
|
261
|
+
const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
|
|
263
262
|
if (!validationResult.isValid) {
|
|
264
|
-
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
265
263
|
const reason = validationResult.reason || 'unknown';
|
|
264
|
+
this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
|
|
266
265
|
// Classify failure reason: bad proposal vs node issue
|
|
267
266
|
const badProposalReasons = [
|
|
268
267
|
'invalid_proposal',
|
|
@@ -302,57 +301,44 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
302
301
|
* the lastBlock is extracted and processed separately via the block handler.
|
|
303
302
|
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
304
303
|
*/ async attestToCheckpointProposal(proposal, _proposalSender) {
|
|
305
|
-
const
|
|
304
|
+
const proposalSlotNumber = proposal.slotNumber;
|
|
306
305
|
const proposer = proposal.getSender();
|
|
307
306
|
// If escape hatch is open for this slot's epoch, do not attest.
|
|
308
|
-
if (await this.epochCache.isEscapeHatchOpenAtSlot(
|
|
309
|
-
this.log.warn(`Escape hatch open for slot ${
|
|
310
|
-
return undefined;
|
|
311
|
-
}
|
|
312
|
-
// Reject proposals with invalid signatures
|
|
313
|
-
if (!proposer) {
|
|
314
|
-
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
307
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(proposalSlotNumber)) {
|
|
308
|
+
this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
|
|
315
309
|
return undefined;
|
|
316
310
|
}
|
|
317
311
|
// Ignore proposals from ourselves (may happen in HA setups)
|
|
318
|
-
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
319
|
-
this.log.
|
|
312
|
+
if (proposer && this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
313
|
+
this.log.debug(`Ignoring block proposal from self for slot ${proposalSlotNumber}`, {
|
|
320
314
|
proposer: proposer.toString(),
|
|
321
|
-
|
|
315
|
+
proposalSlotNumber
|
|
322
316
|
});
|
|
323
317
|
return undefined;
|
|
324
318
|
}
|
|
325
|
-
//
|
|
326
|
-
|
|
327
|
-
this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`);
|
|
328
|
-
return undefined;
|
|
329
|
-
}
|
|
330
|
-
// Check that I have any address in current committee before attesting
|
|
331
|
-
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
319
|
+
// Check that I have any address in the committee where this checkpoint will land before attesting
|
|
320
|
+
const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
|
|
332
321
|
const partOfCommittee = inCommittee.length > 0;
|
|
333
322
|
const proposalInfo = {
|
|
334
|
-
|
|
323
|
+
proposalSlotNumber,
|
|
335
324
|
archive: proposal.archive.toString(),
|
|
336
|
-
proposer: proposer
|
|
325
|
+
proposer: proposer?.toString()
|
|
337
326
|
};
|
|
338
|
-
this.log.info(`Received checkpoint proposal for slot ${
|
|
327
|
+
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
339
328
|
...proposalInfo,
|
|
340
329
|
fishermanMode: this.config.fishermanMode || false
|
|
341
330
|
});
|
|
342
|
-
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
331
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
|
|
332
|
+
// Uses the cached result from the all-nodes callback if available (avoids double validation).
|
|
343
333
|
if (this.config.skipCheckpointProposalValidation) {
|
|
344
|
-
this.log.warn(`Skipping checkpoint proposal validation for slot ${
|
|
334
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
345
335
|
} else {
|
|
346
|
-
const validationResult = await this.
|
|
336
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
347
337
|
if (!validationResult.isValid) {
|
|
348
338
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
349
339
|
return undefined;
|
|
350
340
|
}
|
|
351
341
|
}
|
|
352
|
-
// Upload blobs to filestore if we can (fire and forget)
|
|
353
|
-
if (this.blobClient.canUpload()) {
|
|
354
|
-
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
355
|
-
}
|
|
356
342
|
// Check that I have any address in current committee before attesting
|
|
357
343
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
358
344
|
if (!partOfCommittee && !this.config.fishermanMode) {
|
|
@@ -360,14 +346,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
360
346
|
return undefined;
|
|
361
347
|
}
|
|
362
348
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
363
|
-
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${
|
|
349
|
+
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
364
350
|
...proposalInfo,
|
|
365
351
|
inCommittee: partOfCommittee,
|
|
366
352
|
fishermanMode: this.config.fishermanMode || false
|
|
367
353
|
});
|
|
368
354
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
369
355
|
// Track epoch participation per attester: count each (attester, epoch) pair at most once
|
|
370
|
-
const proposalEpoch = getEpochAtSlot(
|
|
356
|
+
const proposalEpoch = getEpochAtSlot(proposalSlotNumber, this.epochCache.getL1Constants());
|
|
371
357
|
for (const attester of inCommittee){
|
|
372
358
|
const key = attester.toString();
|
|
373
359
|
const lastEpoch = this.lastAttestedEpochByAttester.get(key);
|
|
@@ -392,7 +378,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
392
378
|
}
|
|
393
379
|
if (this.config.fishermanMode) {
|
|
394
380
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
395
|
-
this.log.info(`Creating checkpoint attestations for slot ${
|
|
381
|
+
this.log.info(`Creating checkpoint attestations for slot ${proposalSlotNumber}`, {
|
|
396
382
|
...proposalInfo,
|
|
397
383
|
attestors: attestors.map((a)=>a.toString())
|
|
398
384
|
});
|
|
@@ -427,164 +413,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
427
413
|
return attestations;
|
|
428
414
|
}
|
|
429
415
|
/**
|
|
430
|
-
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
431
|
-
* @returns Validation result with isValid flag and reason if invalid.
|
|
432
|
-
*/ async validateCheckpointProposal(proposal, proposalInfo) {
|
|
433
|
-
const slot = proposal.slotNumber;
|
|
434
|
-
// Timeout block syncing at the start of the next slot
|
|
435
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
436
|
-
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
|
|
437
|
-
const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
|
|
438
|
-
// Wait for last block to sync by archive
|
|
439
|
-
let lastBlockHeader;
|
|
440
|
-
try {
|
|
441
|
-
lastBlockHeader = await retryUntil(async ()=>{
|
|
442
|
-
await this.blockSource.syncImmediate();
|
|
443
|
-
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
444
|
-
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, timeoutSeconds, 0.5);
|
|
445
|
-
} catch (err) {
|
|
446
|
-
if (err instanceof TimeoutError) {
|
|
447
|
-
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
448
|
-
return {
|
|
449
|
-
isValid: false,
|
|
450
|
-
reason: 'last_block_not_found'
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
454
|
-
return {
|
|
455
|
-
isValid: false,
|
|
456
|
-
reason: 'block_fetch_error'
|
|
457
|
-
};
|
|
458
|
-
}
|
|
459
|
-
if (!lastBlockHeader) {
|
|
460
|
-
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
461
|
-
return {
|
|
462
|
-
isValid: false,
|
|
463
|
-
reason: 'last_block_not_found'
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
// Get all full blocks for the slot and checkpoint
|
|
467
|
-
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
468
|
-
if (blocks.length === 0) {
|
|
469
|
-
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
470
|
-
return {
|
|
471
|
-
isValid: false,
|
|
472
|
-
reason: 'no_blocks_for_slot'
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
476
|
-
if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
|
|
477
|
-
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
478
|
-
return {
|
|
479
|
-
isValid: false,
|
|
480
|
-
reason: 'last_block_archive_mismatch'
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
484
|
-
...proposalInfo,
|
|
485
|
-
blockNumbers: blocks.map((b)=>b.number)
|
|
486
|
-
});
|
|
487
|
-
// Get checkpoint constants from first block
|
|
488
|
-
const firstBlock = blocks[0];
|
|
489
|
-
const constants = this.extractCheckpointConstants(firstBlock);
|
|
490
|
-
const checkpointNumber = firstBlock.checkpointNumber;
|
|
491
|
-
// Get L1-to-L2 messages for this checkpoint
|
|
492
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
493
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
494
|
-
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
495
|
-
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch)).filter((c)=>c.checkpointNumber < checkpointNumber).map((c)=>c.checkpointOutHash);
|
|
496
|
-
// Fork world state at the block before the first block
|
|
497
|
-
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
498
|
-
const fork = await this.worldState.fork(parentBlockNumber);
|
|
499
|
-
try {
|
|
500
|
-
// Create checkpoint builder with all existing blocks
|
|
501
|
-
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
|
|
502
|
-
// Complete the checkpoint to get computed values
|
|
503
|
-
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
504
|
-
// Compare checkpoint header with proposal
|
|
505
|
-
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
506
|
-
this.log.warn(`Checkpoint header mismatch`, {
|
|
507
|
-
...proposalInfo,
|
|
508
|
-
computed: computedCheckpoint.header.toInspect(),
|
|
509
|
-
proposal: proposal.checkpointHeader.toInspect()
|
|
510
|
-
});
|
|
511
|
-
return {
|
|
512
|
-
isValid: false,
|
|
513
|
-
reason: 'checkpoint_header_mismatch'
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
// Compare archive root with proposal
|
|
517
|
-
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
518
|
-
this.log.warn(`Archive root mismatch`, {
|
|
519
|
-
...proposalInfo,
|
|
520
|
-
computed: computedCheckpoint.archive.root.toString(),
|
|
521
|
-
proposal: proposal.archive.toString()
|
|
522
|
-
});
|
|
523
|
-
return {
|
|
524
|
-
isValid: false,
|
|
525
|
-
reason: 'archive_mismatch'
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
529
|
-
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
530
|
-
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
531
|
-
const computedEpochOutHash = accumulateCheckpointOutHashes([
|
|
532
|
-
...previousCheckpointOutHashes,
|
|
533
|
-
checkpointOutHash
|
|
534
|
-
]);
|
|
535
|
-
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
536
|
-
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
537
|
-
this.log.warn(`Epoch out hash mismatch`, {
|
|
538
|
-
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
539
|
-
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
540
|
-
checkpointOutHash: checkpointOutHash.toString(),
|
|
541
|
-
previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
|
|
542
|
-
...proposalInfo
|
|
543
|
-
});
|
|
544
|
-
return {
|
|
545
|
-
isValid: false,
|
|
546
|
-
reason: 'out_hash_mismatch'
|
|
547
|
-
};
|
|
548
|
-
}
|
|
549
|
-
// Final round of validations on the checkpoint, just in case.
|
|
550
|
-
try {
|
|
551
|
-
validateCheckpoint(computedCheckpoint, {
|
|
552
|
-
rollupManaLimit: this.checkpointsBuilder.getConfig().rollupManaLimit,
|
|
553
|
-
maxDABlockGas: this.config.validateMaxDABlockGas,
|
|
554
|
-
maxL2BlockGas: this.config.validateMaxL2BlockGas,
|
|
555
|
-
maxTxsPerBlock: this.config.validateMaxTxsPerBlock,
|
|
556
|
-
maxTxsPerCheckpoint: this.config.validateMaxTxsPerCheckpoint
|
|
557
|
-
});
|
|
558
|
-
} catch (err) {
|
|
559
|
-
this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
|
|
560
|
-
return {
|
|
561
|
-
isValid: false,
|
|
562
|
-
reason: 'checkpoint_validation_failed'
|
|
563
|
-
};
|
|
564
|
-
}
|
|
565
|
-
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
566
|
-
return {
|
|
567
|
-
isValid: true
|
|
568
|
-
};
|
|
569
|
-
} finally{
|
|
570
|
-
await fork.close();
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
/**
|
|
574
|
-
* Extract checkpoint global variables from a block.
|
|
575
|
-
*/ extractCheckpointConstants(block) {
|
|
576
|
-
const gv = block.header.globalVariables;
|
|
577
|
-
return {
|
|
578
|
-
chainId: gv.chainId,
|
|
579
|
-
version: gv.version,
|
|
580
|
-
slotNumber: gv.slotNumber,
|
|
581
|
-
timestamp: gv.timestamp,
|
|
582
|
-
coinbase: gv.coinbase,
|
|
583
|
-
feeRecipient: gv.feeRecipient,
|
|
584
|
-
gasFees: gv.gasFees
|
|
585
|
-
};
|
|
586
|
-
}
|
|
587
|
-
/**
|
|
588
416
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
589
417
|
*/ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
|
|
590
418
|
try {
|
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.f1b29a41e",
|
|
4
4
|
"main": "dest/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -64,30 +64,30 @@
|
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@aztec/blob-client": "0.0.1-commit.
|
|
68
|
-
"@aztec/blob-lib": "0.0.1-commit.
|
|
69
|
-
"@aztec/constants": "0.0.1-commit.
|
|
70
|
-
"@aztec/epoch-cache": "0.0.1-commit.
|
|
71
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
72
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
73
|
-
"@aztec/node-keystore": "0.0.1-commit.
|
|
74
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
75
|
-
"@aztec/p2p": "0.0.1-commit.
|
|
76
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
77
|
-
"@aztec/prover-client": "0.0.1-commit.
|
|
78
|
-
"@aztec/simulator": "0.0.1-commit.
|
|
79
|
-
"@aztec/slasher": "0.0.1-commit.
|
|
80
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
81
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
82
|
-
"@aztec/validator-ha-signer": "0.0.1-commit.
|
|
67
|
+
"@aztec/blob-client": "0.0.1-commit.f1b29a41e",
|
|
68
|
+
"@aztec/blob-lib": "0.0.1-commit.f1b29a41e",
|
|
69
|
+
"@aztec/constants": "0.0.1-commit.f1b29a41e",
|
|
70
|
+
"@aztec/epoch-cache": "0.0.1-commit.f1b29a41e",
|
|
71
|
+
"@aztec/ethereum": "0.0.1-commit.f1b29a41e",
|
|
72
|
+
"@aztec/foundation": "0.0.1-commit.f1b29a41e",
|
|
73
|
+
"@aztec/node-keystore": "0.0.1-commit.f1b29a41e",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.f1b29a41e",
|
|
75
|
+
"@aztec/p2p": "0.0.1-commit.f1b29a41e",
|
|
76
|
+
"@aztec/protocol-contracts": "0.0.1-commit.f1b29a41e",
|
|
77
|
+
"@aztec/prover-client": "0.0.1-commit.f1b29a41e",
|
|
78
|
+
"@aztec/simulator": "0.0.1-commit.f1b29a41e",
|
|
79
|
+
"@aztec/slasher": "0.0.1-commit.f1b29a41e",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.f1b29a41e",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.f1b29a41e",
|
|
82
|
+
"@aztec/validator-ha-signer": "0.0.1-commit.f1b29a41e",
|
|
83
83
|
"koa": "^2.16.1",
|
|
84
84
|
"koa-router": "^13.1.1",
|
|
85
85
|
"tslib": "^2.4.0",
|
|
86
86
|
"viem": "npm:@aztec/viem@2.38.2"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
|
-
"@aztec/archiver": "0.0.1-commit.
|
|
90
|
-
"@aztec/world-state": "0.0.1-commit.
|
|
89
|
+
"@aztec/archiver": "0.0.1-commit.f1b29a41e",
|
|
90
|
+
"@aztec/world-state": "0.0.1-commit.f1b29a41e",
|
|
91
91
|
"@electric-sql/pglite": "^0.3.14",
|
|
92
92
|
"@jest/globals": "^30.0.0",
|
|
93
93
|
"@types/jest": "^30.0.0",
|