@aztec/validator-client 0.0.1-commit.ff7989d6c → 0.0.1-commit.fff30aa
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 +41 -0
- package/dest/checkpoint_builder.d.ts +19 -6
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +115 -39
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +21 -1
- package/dest/duties/validation_service.d.ts +1 -1
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +3 -9
- package/dest/factory.d.ts +7 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +6 -5
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/key_store/ha_key_store.js +1 -1
- package/dest/metrics.d.ts +10 -2
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +12 -0
- package/dest/proposal_handler.d.ts +94 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/{block_proposal_handler.js → proposal_handler.js} +356 -36
- package/dest/validator.d.ts +11 -22
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +42 -221
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +135 -39
- package/src/config.ts +21 -1
- package/src/duties/validation_service.ts +3 -9
- package/src/factory.ts +9 -3
- package/src/index.ts +1 -2
- package/src/key_store/ha_key_store.ts +1 -1
- package/src/metrics.ts +19 -1
- package/src/{block_proposal_handler.ts → proposal_handler.ts} +412 -44
- package/src/validator.ts +49 -241
- package/dest/block_proposal_handler.d.ts +0 -63
- package/dest/block_proposal_handler.d.ts.map +0 -1
- package/dest/tx_validator/index.d.ts +0 -3
- package/dest/tx_validator/index.d.ts.map +0 -1
- package/dest/tx_validator/index.js +0 -2
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -19
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -54
- package/src/tx_validator/index.ts +0 -2
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -154
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;
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EACL,WAAW,EACX,gBAAgB,EAEhB,qBAAqB,EACrB,UAAU,EACX,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAGlE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAmD,GAAG,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAE/F,OAAO,EAAoC,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AA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,EAAE,gBAAgB,EAClC,OAAO,EAAE,EAAE,EACX,qBAAqB,EAAE,MAAM,EAC7B,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,26 +1,20 @@
|
|
|
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
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
7
2
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
8
3
|
import { sleep } from '@aztec/foundation/sleep';
|
|
9
4
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
10
5
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
11
6
|
import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
|
|
12
|
-
import { getEpochAtSlot
|
|
13
|
-
import { accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
|
|
7
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
14
8
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
15
9
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
16
|
-
import { createHASigner } from '@aztec/validator-ha-signer/factory';
|
|
10
|
+
import { createHASigner, createSignerFromSharedDb } from '@aztec/validator-ha-signer/factory';
|
|
17
11
|
import { DutyType } from '@aztec/validator-ha-signer/types';
|
|
18
12
|
import { EventEmitter } from 'events';
|
|
19
|
-
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
20
13
|
import { ValidationService } from './duties/validation_service.js';
|
|
21
14
|
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
22
15
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
23
16
|
import { ValidatorMetrics } from './metrics.js';
|
|
17
|
+
import { ProposalHandler } from './proposal_handler.js';
|
|
24
18
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
25
19
|
// Just cap the set to avoid unbounded growth.
|
|
26
20
|
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
@@ -35,11 +29,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
35
29
|
keyStore;
|
|
36
30
|
epochCache;
|
|
37
31
|
p2pClient;
|
|
38
|
-
|
|
39
|
-
blockSource;
|
|
40
|
-
checkpointsBuilder;
|
|
41
|
-
worldState;
|
|
42
|
-
l1ToL2MessageSource;
|
|
32
|
+
proposalHandler;
|
|
43
33
|
config;
|
|
44
34
|
blobClient;
|
|
45
35
|
haSigner;
|
|
@@ -54,10 +44,11 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
54
44
|
/** Tracks the last checkpoint proposal we created. */ lastProposedCheckpoint;
|
|
55
45
|
lastEpochForCommitteeUpdateLoop;
|
|
56
46
|
epochCacheUpdateLoop;
|
|
47
|
+
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */ lastAttestedEpochByAttester;
|
|
57
48
|
proposersOfInvalidBlocks;
|
|
58
49
|
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */ lastAttestedProposal;
|
|
59
|
-
constructor(keyStore, epochCache, p2pClient,
|
|
60
|
-
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.
|
|
50
|
+
constructor(keyStore, epochCache, p2pClient, proposalHandler, config, blobClient, haSigner, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
51
|
+
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.proposalHandler = proposalHandler, this.config = config, this.blobClient = blobClient, this.haSigner = haSigner, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.lastAttestedEpochByAttester = new Map(), this.proposersOfInvalidBlocks = new Set();
|
|
61
52
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
62
53
|
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
63
54
|
this.tracer = telemetry.getTracer('Validator');
|
|
@@ -96,6 +87,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
96
87
|
this.log.trace(`No committee found for slot`);
|
|
97
88
|
return;
|
|
98
89
|
}
|
|
90
|
+
this.metrics.setCurrentEpoch(epoch);
|
|
99
91
|
if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
|
|
100
92
|
const me = this.getValidatorAddresses();
|
|
101
93
|
const committeeSet = new Set(committee.map((v)=>v.toString()));
|
|
@@ -111,36 +103,39 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
111
103
|
this.log.error(`Error updating epoch committee`, err);
|
|
112
104
|
}
|
|
113
105
|
}
|
|
114
|
-
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
106
|
+
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), slashingProtectionDb) {
|
|
115
107
|
const metrics = new ValidatorMetrics(telemetry);
|
|
116
108
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
117
|
-
txsPermitted: !config.disableTransactions
|
|
109
|
+
txsPermitted: !config.disableTransactions,
|
|
110
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock
|
|
118
111
|
});
|
|
119
|
-
const
|
|
112
|
+
const proposalHandler = new ProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, blobClient, metrics, dateProvider, telemetry);
|
|
120
113
|
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
121
114
|
let validatorKeyStore = nodeKeystoreAdapter;
|
|
122
115
|
let haSigner;
|
|
123
|
-
if (
|
|
116
|
+
if (slashingProtectionDb) {
|
|
117
|
+
// Shared database mode: use a pre-existing database (e.g. for testing HA setups).
|
|
118
|
+
const { signer } = createSignerFromSharedDb(slashingProtectionDb, config);
|
|
119
|
+
haSigner = signer;
|
|
120
|
+
validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, signer);
|
|
121
|
+
} else if (config.haSigningEnabled) {
|
|
124
122
|
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
125
123
|
const haConfig = {
|
|
126
124
|
...config,
|
|
127
125
|
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000
|
|
128
126
|
};
|
|
129
|
-
const { signer } = await createHASigner(haConfig
|
|
130
|
-
telemetryClient: telemetry,
|
|
131
|
-
dateProvider
|
|
132
|
-
});
|
|
127
|
+
const { signer } = await createHASigner(haConfig);
|
|
133
128
|
haSigner = signer;
|
|
134
129
|
validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, signer);
|
|
135
130
|
}
|
|
136
|
-
const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient,
|
|
131
|
+
const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, proposalHandler, config, blobClient, haSigner, dateProvider, telemetry);
|
|
137
132
|
return validator;
|
|
138
133
|
}
|
|
139
134
|
getValidatorAddresses() {
|
|
140
135
|
return this.keyStore.getAddresses().filter((addr)=>!this.config.disabledValidators.some((disabled)=>disabled.equals(addr)));
|
|
141
136
|
}
|
|
142
|
-
|
|
143
|
-
return this.
|
|
137
|
+
getProposalHandler() {
|
|
138
|
+
return this.proposalHandler;
|
|
144
139
|
}
|
|
145
140
|
signWithAddress(addr, msg, context) {
|
|
146
141
|
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
@@ -234,13 +229,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
234
229
|
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
235
230
|
return false;
|
|
236
231
|
}
|
|
237
|
-
//
|
|
232
|
+
// Log self-proposals from HA peers (same validator key on different nodes)
|
|
238
233
|
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
239
|
-
this.log.
|
|
234
|
+
this.log.verbose(`Processing block proposal from HA peer for slot ${slotNumber}`, {
|
|
240
235
|
proposer: proposer.toString(),
|
|
241
236
|
slotNumber
|
|
242
237
|
});
|
|
243
|
-
return false;
|
|
244
238
|
}
|
|
245
239
|
// Check if we're in the committee (for metrics purposes)
|
|
246
240
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
@@ -258,10 +252,10 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
258
252
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
259
253
|
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
260
254
|
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
|
|
261
|
-
const validationResult = await this.
|
|
255
|
+
const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
|
|
262
256
|
if (!validationResult.isValid) {
|
|
263
|
-
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
264
257
|
const reason = validationResult.reason || 'unknown';
|
|
258
|
+
this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
|
|
265
259
|
// Classify failure reason: bad proposal vs node issue
|
|
266
260
|
const badProposalReasons = [
|
|
267
261
|
'invalid_proposal',
|
|
@@ -308,52 +302,36 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
308
302
|
this.log.warn(`Escape hatch open for slot ${slotNumber}, skipping checkpoint attestation handling`);
|
|
309
303
|
return undefined;
|
|
310
304
|
}
|
|
311
|
-
// Reject proposals with invalid signatures
|
|
312
|
-
if (!proposer) {
|
|
313
|
-
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
314
|
-
return undefined;
|
|
315
|
-
}
|
|
316
305
|
// Ignore proposals from ourselves (may happen in HA setups)
|
|
317
|
-
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
318
|
-
this.log.
|
|
306
|
+
if (proposer && this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
307
|
+
this.log.debug(`Ignoring block proposal from self for slot ${slotNumber}`, {
|
|
319
308
|
proposer: proposer.toString(),
|
|
320
309
|
slotNumber
|
|
321
310
|
});
|
|
322
311
|
return undefined;
|
|
323
312
|
}
|
|
324
|
-
//
|
|
325
|
-
if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
|
|
326
|
-
this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`);
|
|
327
|
-
return undefined;
|
|
328
|
-
}
|
|
329
|
-
// Check that I have any address in current committee before attesting
|
|
313
|
+
// Check that I have any address in the committee where this checkpoint will land before attesting
|
|
330
314
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
331
315
|
const partOfCommittee = inCommittee.length > 0;
|
|
332
316
|
const proposalInfo = {
|
|
333
317
|
slotNumber,
|
|
334
318
|
archive: proposal.archive.toString(),
|
|
335
|
-
proposer: proposer
|
|
336
|
-
txCount: proposal.txHashes.length
|
|
319
|
+
proposer: proposer?.toString()
|
|
337
320
|
};
|
|
338
321
|
this.log.info(`Received checkpoint proposal for slot ${slotNumber}`, {
|
|
339
322
|
...proposalInfo,
|
|
340
|
-
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
341
323
|
fishermanMode: this.config.fishermanMode || false
|
|
342
324
|
});
|
|
343
|
-
// Validate the checkpoint proposal
|
|
325
|
+
// Validate the checkpoint proposal and upload blobs (unless skipCheckpointProposalValidation is set)
|
|
344
326
|
if (this.config.skipCheckpointProposalValidation) {
|
|
345
327
|
this.log.warn(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
|
|
346
328
|
} else {
|
|
347
|
-
const validationResult = await this.
|
|
329
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
348
330
|
if (!validationResult.isValid) {
|
|
349
331
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
350
332
|
return undefined;
|
|
351
333
|
}
|
|
352
334
|
}
|
|
353
|
-
// Upload blobs to filestore if we can (fire and forget)
|
|
354
|
-
if (this.blobClient.canUpload()) {
|
|
355
|
-
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
356
|
-
}
|
|
357
335
|
// Check that I have any address in current committee before attesting
|
|
358
336
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
359
337
|
if (!partOfCommittee && !this.config.fishermanMode) {
|
|
@@ -367,6 +345,16 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
367
345
|
fishermanMode: this.config.fishermanMode || false
|
|
368
346
|
});
|
|
369
347
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
348
|
+
// Track epoch participation per attester: count each (attester, epoch) pair at most once
|
|
349
|
+
const proposalEpoch = getEpochAtSlot(slotNumber, this.epochCache.getL1Constants());
|
|
350
|
+
for (const attester of inCommittee){
|
|
351
|
+
const key = attester.toString();
|
|
352
|
+
const lastEpoch = this.lastAttestedEpochByAttester.get(key);
|
|
353
|
+
if (lastEpoch === undefined || proposalEpoch > lastEpoch) {
|
|
354
|
+
this.lastAttestedEpochByAttester.set(key, proposalEpoch);
|
|
355
|
+
this.metrics.incAttestedEpochCount(attester);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
370
358
|
// Determine which validators should attest
|
|
371
359
|
let attestors;
|
|
372
360
|
if (partOfCommittee) {
|
|
@@ -417,173 +405,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
417
405
|
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
418
406
|
return attestations;
|
|
419
407
|
}
|
|
420
|
-
/**
|
|
421
|
-
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
422
|
-
* @returns Validation result with isValid flag and reason if invalid.
|
|
423
|
-
*/ async validateCheckpointProposal(proposal, proposalInfo) {
|
|
424
|
-
const slot = proposal.slotNumber;
|
|
425
|
-
// Timeout block syncing at the start of the next slot
|
|
426
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
427
|
-
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
|
|
428
|
-
const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
|
|
429
|
-
// Wait for last block to sync by archive
|
|
430
|
-
let lastBlockHeader;
|
|
431
|
-
try {
|
|
432
|
-
lastBlockHeader = await retryUntil(async ()=>{
|
|
433
|
-
await this.blockSource.syncImmediate();
|
|
434
|
-
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
435
|
-
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, timeoutSeconds, 0.5);
|
|
436
|
-
} catch (err) {
|
|
437
|
-
if (err instanceof TimeoutError) {
|
|
438
|
-
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
439
|
-
return {
|
|
440
|
-
isValid: false,
|
|
441
|
-
reason: 'last_block_not_found'
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
445
|
-
return {
|
|
446
|
-
isValid: false,
|
|
447
|
-
reason: 'block_fetch_error'
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
if (!lastBlockHeader) {
|
|
451
|
-
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
452
|
-
return {
|
|
453
|
-
isValid: false,
|
|
454
|
-
reason: 'last_block_not_found'
|
|
455
|
-
};
|
|
456
|
-
}
|
|
457
|
-
// Get all full blocks for the slot and checkpoint
|
|
458
|
-
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
459
|
-
if (blocks.length === 0) {
|
|
460
|
-
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
461
|
-
return {
|
|
462
|
-
isValid: false,
|
|
463
|
-
reason: 'no_blocks_for_slot'
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
467
|
-
if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
|
|
468
|
-
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
469
|
-
return {
|
|
470
|
-
isValid: false,
|
|
471
|
-
reason: 'last_block_archive_mismatch'
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
475
|
-
...proposalInfo,
|
|
476
|
-
blockNumbers: blocks.map((b)=>b.number)
|
|
477
|
-
});
|
|
478
|
-
// Get checkpoint constants from first block
|
|
479
|
-
const firstBlock = blocks[0];
|
|
480
|
-
const constants = this.extractCheckpointConstants(firstBlock);
|
|
481
|
-
const checkpointNumber = firstBlock.checkpointNumber;
|
|
482
|
-
// Get L1-to-L2 messages for this checkpoint
|
|
483
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
484
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
485
|
-
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
486
|
-
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch)).filter((c)=>c.checkpointNumber < checkpointNumber).map((c)=>c.checkpointOutHash);
|
|
487
|
-
// Fork world state at the block before the first block
|
|
488
|
-
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
489
|
-
const fork = await this.worldState.fork(parentBlockNumber);
|
|
490
|
-
try {
|
|
491
|
-
// Create checkpoint builder with all existing blocks
|
|
492
|
-
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
|
|
493
|
-
// Complete the checkpoint to get computed values
|
|
494
|
-
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
495
|
-
// Compare checkpoint header with proposal
|
|
496
|
-
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
497
|
-
this.log.warn(`Checkpoint header mismatch`, {
|
|
498
|
-
...proposalInfo,
|
|
499
|
-
computed: computedCheckpoint.header.toInspect(),
|
|
500
|
-
proposal: proposal.checkpointHeader.toInspect()
|
|
501
|
-
});
|
|
502
|
-
return {
|
|
503
|
-
isValid: false,
|
|
504
|
-
reason: 'checkpoint_header_mismatch'
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
// Compare archive root with proposal
|
|
508
|
-
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
509
|
-
this.log.warn(`Archive root mismatch`, {
|
|
510
|
-
...proposalInfo,
|
|
511
|
-
computed: computedCheckpoint.archive.root.toString(),
|
|
512
|
-
proposal: proposal.archive.toString()
|
|
513
|
-
});
|
|
514
|
-
return {
|
|
515
|
-
isValid: false,
|
|
516
|
-
reason: 'archive_mismatch'
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
520
|
-
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
521
|
-
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
522
|
-
const computedEpochOutHash = accumulateCheckpointOutHashes([
|
|
523
|
-
...previousCheckpointOutHashes,
|
|
524
|
-
checkpointOutHash
|
|
525
|
-
]);
|
|
526
|
-
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
527
|
-
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
528
|
-
this.log.warn(`Epoch out hash mismatch`, {
|
|
529
|
-
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
530
|
-
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
531
|
-
checkpointOutHash: checkpointOutHash.toString(),
|
|
532
|
-
previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
|
|
533
|
-
...proposalInfo
|
|
534
|
-
});
|
|
535
|
-
return {
|
|
536
|
-
isValid: false,
|
|
537
|
-
reason: 'out_hash_mismatch'
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
541
|
-
return {
|
|
542
|
-
isValid: true
|
|
543
|
-
};
|
|
544
|
-
} finally{
|
|
545
|
-
await fork.close();
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
/**
|
|
549
|
-
* Extract checkpoint global variables from a block.
|
|
550
|
-
*/ extractCheckpointConstants(block) {
|
|
551
|
-
const gv = block.header.globalVariables;
|
|
552
|
-
return {
|
|
553
|
-
chainId: gv.chainId,
|
|
554
|
-
version: gv.version,
|
|
555
|
-
slotNumber: gv.slotNumber,
|
|
556
|
-
timestamp: gv.timestamp,
|
|
557
|
-
coinbase: gv.coinbase,
|
|
558
|
-
feeRecipient: gv.feeRecipient,
|
|
559
|
-
gasFees: gv.gasFees
|
|
560
|
-
};
|
|
561
|
-
}
|
|
562
|
-
/**
|
|
563
|
-
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
564
|
-
*/ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
|
|
565
|
-
try {
|
|
566
|
-
const lastBlockHeader = await this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
567
|
-
if (!lastBlockHeader) {
|
|
568
|
-
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
569
|
-
return;
|
|
570
|
-
}
|
|
571
|
-
const blocks = await this.blockSource.getBlocksForSlot(proposal.slotNumber);
|
|
572
|
-
if (blocks.length === 0) {
|
|
573
|
-
this.log.warn(`No blocks found for blob upload`, proposalInfo);
|
|
574
|
-
return;
|
|
575
|
-
}
|
|
576
|
-
const blobFields = blocks.flatMap((b)=>b.toBlobFields());
|
|
577
|
-
const blobs = await getBlobsPerL1Block(blobFields);
|
|
578
|
-
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
579
|
-
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
580
|
-
...proposalInfo,
|
|
581
|
-
numBlobs: blobs.length
|
|
582
|
-
});
|
|
583
|
-
} catch (err) {
|
|
584
|
-
this.log.warn(`Failed to upload blobs for checkpoint: ${err}`, proposalInfo);
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
408
|
slashInvalidBlock(proposal) {
|
|
588
409
|
const proposer = proposal.getSender();
|
|
589
410
|
// Skip if signature is invalid (shouldn't happen since we validate earlier)
|
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.fff30aa",
|
|
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.fff30aa",
|
|
68
|
+
"@aztec/blob-lib": "0.0.1-commit.fff30aa",
|
|
69
|
+
"@aztec/constants": "0.0.1-commit.fff30aa",
|
|
70
|
+
"@aztec/epoch-cache": "0.0.1-commit.fff30aa",
|
|
71
|
+
"@aztec/ethereum": "0.0.1-commit.fff30aa",
|
|
72
|
+
"@aztec/foundation": "0.0.1-commit.fff30aa",
|
|
73
|
+
"@aztec/node-keystore": "0.0.1-commit.fff30aa",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.fff30aa",
|
|
75
|
+
"@aztec/p2p": "0.0.1-commit.fff30aa",
|
|
76
|
+
"@aztec/protocol-contracts": "0.0.1-commit.fff30aa",
|
|
77
|
+
"@aztec/prover-client": "0.0.1-commit.fff30aa",
|
|
78
|
+
"@aztec/simulator": "0.0.1-commit.fff30aa",
|
|
79
|
+
"@aztec/slasher": "0.0.1-commit.fff30aa",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.fff30aa",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.fff30aa",
|
|
82
|
+
"@aztec/validator-ha-signer": "0.0.1-commit.fff30aa",
|
|
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.fff30aa",
|
|
90
|
+
"@aztec/world-state": "0.0.1-commit.fff30aa",
|
|
91
91
|
"@electric-sql/pglite": "^0.3.14",
|
|
92
92
|
"@jest/globals": "^30.0.0",
|
|
93
93
|
"@types/jest": "^30.0.0",
|