@aztec/validator-client 0.0.1-commit.7cf39cb55 → 0.0.1-commit.808bf7f90
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/dest/block_proposal_handler.d.ts +2 -2
- package/dest/block_proposal_handler.d.ts.map +1 -1
- package/dest/block_proposal_handler.js +20 -34
- package/dest/checkpoint_builder.d.ts +8 -5
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +21 -13
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +1 -1
- package/dest/duties/validation_service.d.ts +2 -2
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +3 -3
- package/dest/validator.d.ts +11 -5
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +48 -15
- package/package.json +19 -19
- package/src/block_proposal_handler.ts +28 -48
- package/src/checkpoint_builder.ts +16 -0
- package/src/config.ts +1 -1
- package/src/duties/validation_service.ts +9 -2
- package/src/validator.ts +56 -13
package/src/validator.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
2
2
|
import { type Blob, getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
3
3
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
4
|
+
import { validateFeeAssetPriceModifier } from '@aztec/ethereum/contracts';
|
|
4
5
|
import {
|
|
5
6
|
BlockNumber,
|
|
6
7
|
CheckpointNumber,
|
|
@@ -46,6 +47,7 @@ import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
|
46
47
|
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
47
48
|
import { createHASigner } from '@aztec/validator-ha-signer/factory';
|
|
48
49
|
import { DutyType, type SigningContext } from '@aztec/validator-ha-signer/types';
|
|
50
|
+
import type { ValidatorHASigner } from '@aztec/validator-ha-signer/validator-ha-signer';
|
|
49
51
|
|
|
50
52
|
import { EventEmitter } from 'events';
|
|
51
53
|
import type { TypedDataDefinition } from 'viem';
|
|
@@ -76,7 +78,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
76
78
|
private validationService: ValidationService;
|
|
77
79
|
private metrics: ValidatorMetrics;
|
|
78
80
|
private log: Logger;
|
|
79
|
-
|
|
80
81
|
// Whether it has already registered handlers on the p2p client
|
|
81
82
|
private hasRegisteredHandlers = false;
|
|
82
83
|
|
|
@@ -105,6 +106,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
105
106
|
private l1ToL2MessageSource: L1ToL2MessageSource,
|
|
106
107
|
private config: ValidatorClientFullConfig,
|
|
107
108
|
private blobClient: BlobClientInterface,
|
|
109
|
+
private haSigner: ValidatorHASigner | undefined,
|
|
108
110
|
private dateProvider: DateProvider = new DateProvider(),
|
|
109
111
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
110
112
|
log = createLogger('validator'),
|
|
@@ -210,15 +212,18 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
210
212
|
telemetry,
|
|
211
213
|
);
|
|
212
214
|
|
|
213
|
-
|
|
215
|
+
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
216
|
+
let validatorKeyStore: ExtendedValidatorKeyStore = nodeKeystoreAdapter;
|
|
217
|
+
let haSigner: ValidatorHASigner | undefined;
|
|
214
218
|
if (config.haSigningEnabled) {
|
|
215
219
|
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
216
220
|
const haConfig = {
|
|
217
221
|
...config,
|
|
218
222
|
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000,
|
|
219
223
|
};
|
|
220
|
-
const { signer } = await createHASigner(haConfig);
|
|
221
|
-
|
|
224
|
+
const { signer } = await createHASigner(haConfig, { telemetryClient: telemetry, dateProvider });
|
|
225
|
+
haSigner = signer;
|
|
226
|
+
validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, signer);
|
|
222
227
|
}
|
|
223
228
|
|
|
224
229
|
const validator = new ValidatorClient(
|
|
@@ -232,6 +237,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
232
237
|
l1ToL2MessageSource,
|
|
233
238
|
config,
|
|
234
239
|
blobClient,
|
|
240
|
+
haSigner,
|
|
235
241
|
dateProvider,
|
|
236
242
|
telemetry,
|
|
237
243
|
);
|
|
@@ -269,6 +275,28 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
269
275
|
this.config = { ...this.config, ...config };
|
|
270
276
|
}
|
|
271
277
|
|
|
278
|
+
public reloadKeystore(newManager: KeystoreManager): void {
|
|
279
|
+
if (this.config.haSigningEnabled && !this.haSigner) {
|
|
280
|
+
this.log.warn(
|
|
281
|
+
'HA signing is enabled in config but was not initialized at startup. ' +
|
|
282
|
+
'Restart the node to enable HA signing.',
|
|
283
|
+
);
|
|
284
|
+
} else if (!this.config.haSigningEnabled && this.haSigner) {
|
|
285
|
+
this.log.warn(
|
|
286
|
+
'HA signing was disabled via config update but the HA signer is still active. ' +
|
|
287
|
+
'Restart the node to fully disable HA signing.',
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
292
|
+
if (this.haSigner) {
|
|
293
|
+
this.keyStore = new HAKeyStore(newAdapter, this.haSigner);
|
|
294
|
+
} else {
|
|
295
|
+
this.keyStore = newAdapter;
|
|
296
|
+
}
|
|
297
|
+
this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
|
|
298
|
+
}
|
|
299
|
+
|
|
272
300
|
public async start() {
|
|
273
301
|
if (this.epochCacheUpdateLoop.isRunning()) {
|
|
274
302
|
this.log.warn(`Validator client already started`);
|
|
@@ -471,6 +499,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
471
499
|
return undefined;
|
|
472
500
|
}
|
|
473
501
|
|
|
502
|
+
// Validate fee asset price modifier is within allowed range
|
|
503
|
+
if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
|
|
504
|
+
this.log.warn(
|
|
505
|
+
`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`,
|
|
506
|
+
);
|
|
507
|
+
return undefined;
|
|
508
|
+
}
|
|
509
|
+
|
|
474
510
|
// Check that I have any address in current committee before attesting
|
|
475
511
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
476
512
|
const partOfCommittee = inCommittee.length > 0;
|
|
@@ -634,6 +670,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
634
670
|
return { isValid: false, reason: 'no_blocks_for_slot' };
|
|
635
671
|
}
|
|
636
672
|
|
|
673
|
+
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
674
|
+
if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
|
|
675
|
+
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
676
|
+
return { isValid: false, reason: 'last_block_archive_mismatch' };
|
|
677
|
+
}
|
|
678
|
+
|
|
637
679
|
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
638
680
|
...proposalInfo,
|
|
639
681
|
blockNumbers: blocks.map(b => b.number),
|
|
@@ -647,14 +689,11 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
647
689
|
// Get L1-to-L2 messages for this checkpoint
|
|
648
690
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
649
691
|
|
|
650
|
-
//
|
|
651
|
-
// TODO: There can be a more efficient way to get the previous checkpoint out hashes without having to fetch the
|
|
652
|
-
// actual checkpoints and the blocks/txs in them.
|
|
692
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
653
693
|
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
654
|
-
const
|
|
655
|
-
.filter(
|
|
656
|
-
.
|
|
657
|
-
const previousCheckpointOutHashes = previousCheckpoints.map(c => c.getCheckpointOutHash());
|
|
694
|
+
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch))
|
|
695
|
+
.filter(c => c.checkpointNumber < checkpointNumber)
|
|
696
|
+
.map(c => c.checkpointOutHash);
|
|
658
697
|
|
|
659
698
|
// Fork world state at the block before the first block
|
|
660
699
|
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
@@ -665,6 +704,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
665
704
|
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
|
|
666
705
|
checkpointNumber,
|
|
667
706
|
constants,
|
|
707
|
+
proposal.feeAssetPriceModifier,
|
|
668
708
|
l1ToL2Messages,
|
|
669
709
|
previousCheckpointOutHashes,
|
|
670
710
|
fork,
|
|
@@ -727,6 +767,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
727
767
|
chainId: gv.chainId,
|
|
728
768
|
version: gv.version,
|
|
729
769
|
slotNumber: gv.slotNumber,
|
|
770
|
+
timestamp: gv.timestamp,
|
|
730
771
|
coinbase: gv.coinbase,
|
|
731
772
|
feeRecipient: gv.feeRecipient,
|
|
732
773
|
gasFees: gv.gasFees,
|
|
@@ -736,7 +777,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
736
777
|
/**
|
|
737
778
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
738
779
|
*/
|
|
739
|
-
|
|
780
|
+
protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
|
|
740
781
|
try {
|
|
741
782
|
const lastBlockHeader = await this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
742
783
|
if (!lastBlockHeader) {
|
|
@@ -751,7 +792,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
751
792
|
}
|
|
752
793
|
|
|
753
794
|
const blobFields = blocks.flatMap(b => b.toBlobFields());
|
|
754
|
-
const blobs: Blob[] = getBlobsPerL1Block(blobFields);
|
|
795
|
+
const blobs: Blob[] = await getBlobsPerL1Block(blobFields);
|
|
755
796
|
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
756
797
|
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
757
798
|
...proposalInfo,
|
|
@@ -880,6 +921,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
880
921
|
async createCheckpointProposal(
|
|
881
922
|
checkpointHeader: CheckpointHeader,
|
|
882
923
|
archive: Fr,
|
|
924
|
+
feeAssetPriceModifier: bigint,
|
|
883
925
|
lastBlockInfo: CreateCheckpointProposalLastBlockData | undefined,
|
|
884
926
|
proposerAddress: EthAddress | undefined,
|
|
885
927
|
options: CheckpointProposalOptions = {},
|
|
@@ -901,6 +943,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
901
943
|
const newProposal = await this.validationService.createCheckpointProposal(
|
|
902
944
|
checkpointHeader,
|
|
903
945
|
archive,
|
|
946
|
+
feeAssetPriceModifier,
|
|
904
947
|
lastBlockInfo,
|
|
905
948
|
proposerAddress,
|
|
906
949
|
options,
|