@aztec/validator-client 0.0.1-commit.4d79d1f2d → 0.0.1-commit.5358163d3

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.
Files changed (45) hide show
  1. package/dest/block_proposal_handler.d.ts +2 -2
  2. package/dest/block_proposal_handler.d.ts.map +1 -1
  3. package/dest/block_proposal_handler.js +20 -34
  4. package/dest/checkpoint_builder.d.ts +8 -5
  5. package/dest/checkpoint_builder.d.ts.map +1 -1
  6. package/dest/checkpoint_builder.js +28 -18
  7. package/dest/config.d.ts +1 -1
  8. package/dest/config.d.ts.map +1 -1
  9. package/dest/config.js +1 -1
  10. package/dest/duties/validation_service.d.ts +2 -2
  11. package/dest/duties/validation_service.d.ts.map +1 -1
  12. package/dest/duties/validation_service.js +3 -3
  13. package/dest/factory.d.ts +1 -1
  14. package/dest/factory.d.ts.map +1 -1
  15. package/dest/factory.js +2 -1
  16. package/dest/index.d.ts +1 -2
  17. package/dest/index.d.ts.map +1 -1
  18. package/dest/index.js +0 -1
  19. package/dest/metrics.d.ts +9 -1
  20. package/dest/metrics.d.ts.map +1 -1
  21. package/dest/metrics.js +12 -0
  22. package/dest/validator.d.ts +13 -5
  23. package/dest/validator.d.ts.map +1 -1
  24. package/dest/validator.js +68 -19
  25. package/package.json +19 -19
  26. package/src/block_proposal_handler.ts +28 -48
  27. package/src/checkpoint_builder.ts +23 -6
  28. package/src/config.ts +1 -1
  29. package/src/duties/validation_service.ts +9 -2
  30. package/src/factory.ts +1 -0
  31. package/src/index.ts +0 -1
  32. package/src/metrics.ts +18 -0
  33. package/src/validator.ts +77 -15
  34. package/dest/tx_validator/index.d.ts +0 -3
  35. package/dest/tx_validator/index.d.ts.map +0 -1
  36. package/dest/tx_validator/index.js +0 -2
  37. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  38. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  39. package/dest/tx_validator/nullifier_cache.js +0 -24
  40. package/dest/tx_validator/tx_validator_factory.d.ts +0 -19
  41. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  42. package/dest/tx_validator/tx_validator_factory.js +0 -54
  43. package/src/tx_validator/index.ts +0 -2
  44. package/src/tx_validator/nullifier_cache.ts +0 -30
  45. package/src/tx_validator/tx_validator_factory.ts +0 -154
@@ -4,7 +4,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
5
5
  import { bufferToHex } from '@aztec/foundation/string';
6
6
  import { DateProvider, elapsed } from '@aztec/foundation/timer';
7
- import { getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
7
+ import { createTxValidatorForBlockBuilding, getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
8
8
  import { LightweightCheckpointBuilder } from '@aztec/prover-client/light';
9
9
  import {
10
10
  GuardedMerkleTreeOperations,
@@ -28,12 +28,11 @@ import {
28
28
  type PublicProcessorLimits,
29
29
  type WorldStateSynchronizer,
30
30
  } from '@aztec/stdlib/interfaces/server';
31
+ import { type DebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
31
32
  import { MerkleTreeId } from '@aztec/stdlib/trees';
32
33
  import { type CheckpointGlobalVariables, GlobalVariables, StateReference, Tx } from '@aztec/stdlib/tx';
33
34
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
34
35
 
35
- import { createValidatorForBlockBuilding } from './tx_validator/tx_validator_factory.js';
36
-
37
36
  // Re-export for backward compatibility
38
37
  export type { BuildBlockInCheckpointResult } from '@aztec/stdlib/interfaces/server';
39
38
 
@@ -52,6 +51,7 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
52
51
  private dateProvider: DateProvider,
53
52
  private telemetryClient: TelemetryClient,
54
53
  bindings?: LoggerBindings,
54
+ private debugLogStore: DebugLogStore = new NullDebugLogStore(),
55
55
  ) {
56
56
  this.log = createLogger('checkpoint-builder', {
57
57
  ...bindings,
@@ -105,7 +105,7 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
105
105
  }
106
106
 
107
107
  // Add block to checkpoint
108
- const block = await this.checkpointBuilder.addBlock(globalVariables, processedTxs, {
108
+ const { block } = await this.checkpointBuilder.addBlock(globalVariables, processedTxs, {
109
109
  expectedEndState: opts.expectedEndState,
110
110
  });
111
111
 
@@ -148,10 +148,15 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
148
148
  }
149
149
 
150
150
  protected async makeBlockBuilderDeps(globalVariables: GlobalVariables, fork: MerkleTreeWriteOperations) {
151
- const txPublicSetupAllowList = this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
151
+ const txPublicSetupAllowList = [
152
+ ...(await getDefaultAllowedSetupFunctions()),
153
+ ...(this.config.txPublicSetupAllowListExtend ?? []),
154
+ ];
152
155
  const contractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings());
153
156
  const guardedFork = new GuardedMerkleTreeOperations(fork);
154
157
 
158
+ const collectDebugLogs = this.debugLogStore.isEnabled;
159
+
155
160
  const bindings = this.log.getBindings();
156
161
  const publicTxSimulator = createPublicTxSimulatorForBlockBuilding(
157
162
  guardedFork,
@@ -159,6 +164,7 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
159
164
  globalVariables,
160
165
  this.telemetryClient,
161
166
  bindings,
167
+ collectDebugLogs,
162
168
  );
163
169
 
164
170
  const processor = new PublicProcessor(
@@ -170,9 +176,10 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
170
176
  this.telemetryClient,
171
177
  createLogger('simulator:public-processor', bindings),
172
178
  this.config,
179
+ this.debugLogStore,
173
180
  );
174
181
 
175
- const validator = createValidatorForBlockBuilding(
182
+ const validator = createTxValidatorForBlockBuilding(
176
183
  fork,
177
184
  this.contractDataSource,
178
185
  globalVariables,
@@ -197,6 +204,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
197
204
  private contractDataSource: ContractDataSource,
198
205
  private dateProvider: DateProvider,
199
206
  private telemetryClient: TelemetryClient = getTelemetryClient(),
207
+ private debugLogStore: DebugLogStore = new NullDebugLogStore(),
200
208
  ) {
201
209
  this.log = createLogger('checkpoint-builder');
202
210
  }
@@ -215,6 +223,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
215
223
  async startCheckpoint(
216
224
  checkpointNumber: CheckpointNumber,
217
225
  constants: CheckpointGlobalVariables,
226
+ feeAssetPriceModifier: bigint,
218
227
  l1ToL2Messages: Fr[],
219
228
  previousCheckpointOutHashes: Fr[],
220
229
  fork: MerkleTreeWriteOperations,
@@ -229,6 +238,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
229
238
  initialStateReference: stateReference.toInspect(),
230
239
  initialArchiveRoot: bufferToHex(archiveTree.root),
231
240
  constants,
241
+ feeAssetPriceModifier,
232
242
  });
233
243
 
234
244
  const lightweightBuilder = await LightweightCheckpointBuilder.startNewCheckpoint(
@@ -238,6 +248,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
238
248
  previousCheckpointOutHashes,
239
249
  fork,
240
250
  bindings,
251
+ feeAssetPriceModifier,
241
252
  );
242
253
 
243
254
  return new CheckpointBuilder(
@@ -248,6 +259,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
248
259
  this.dateProvider,
249
260
  this.telemetryClient,
250
261
  bindings,
262
+ this.debugLogStore,
251
263
  );
252
264
  }
253
265
 
@@ -257,6 +269,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
257
269
  async openCheckpoint(
258
270
  checkpointNumber: CheckpointNumber,
259
271
  constants: CheckpointGlobalVariables,
272
+ feeAssetPriceModifier: bigint,
260
273
  l1ToL2Messages: Fr[],
261
274
  previousCheckpointOutHashes: Fr[],
262
275
  fork: MerkleTreeWriteOperations,
@@ -270,6 +283,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
270
283
  return this.startCheckpoint(
271
284
  checkpointNumber,
272
285
  constants,
286
+ feeAssetPriceModifier,
273
287
  l1ToL2Messages,
274
288
  previousCheckpointOutHashes,
275
289
  fork,
@@ -284,11 +298,13 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
284
298
  initialStateReference: stateReference.toInspect(),
285
299
  initialArchiveRoot: bufferToHex(archiveTree.root),
286
300
  constants,
301
+ feeAssetPriceModifier,
287
302
  });
288
303
 
289
304
  const lightweightBuilder = await LightweightCheckpointBuilder.resumeCheckpoint(
290
305
  checkpointNumber,
291
306
  constants,
307
+ feeAssetPriceModifier,
292
308
  l1ToL2Messages,
293
309
  previousCheckpointOutHashes,
294
310
  fork,
@@ -304,6 +320,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
304
320
  this.dateProvider,
305
321
  this.telemetryClient,
306
322
  bindings,
323
+ this.debugLogStore,
307
324
  );
308
325
  }
309
326
 
package/src/config.ts CHANGED
@@ -6,8 +6,8 @@ import {
6
6
  secretValueConfigHelper,
7
7
  } from '@aztec/foundation/config';
8
8
  import { EthAddress } from '@aztec/foundation/eth-address';
9
+ import { validatorHASignerConfigMappings } from '@aztec/stdlib/ha-signing';
9
10
  import type { ValidatorClientConfig } from '@aztec/stdlib/interfaces/server';
10
- import { validatorHASignerConfigMappings } from '@aztec/validator-ha-signer/config';
11
11
 
12
12
  export type { ValidatorClientConfig };
13
13
 
@@ -95,6 +95,7 @@ export class ValidationService {
95
95
  public createCheckpointProposal(
96
96
  checkpointHeader: CheckpointHeader,
97
97
  archive: Fr,
98
+ feeAssetPriceModifier: bigint,
98
99
  lastBlockInfo: CreateCheckpointProposalLastBlockData | undefined,
99
100
  proposerAttesterAddress: EthAddress | undefined,
100
101
  options: CheckpointProposalOptions,
@@ -119,7 +120,13 @@ export class ValidationService {
119
120
  txs: options.publishFullTxs ? lastBlockInfo.txs : undefined,
120
121
  };
121
122
 
122
- return CheckpointProposal.createProposalFromSigner(checkpointHeader, archive, lastBlock, payloadSigner);
123
+ return CheckpointProposal.createProposalFromSigner(
124
+ checkpointHeader,
125
+ archive,
126
+ feeAssetPriceModifier,
127
+ lastBlock,
128
+ payloadSigner,
129
+ );
123
130
  }
124
131
 
125
132
  /**
@@ -137,7 +144,7 @@ export class ValidationService {
137
144
  attestors: EthAddress[],
138
145
  ): Promise<CheckpointAttestation[]> {
139
146
  // Create the attestation payload from the checkpoint proposal
140
- const payload = new ConsensusPayload(proposal.checkpointHeader, proposal.archive);
147
+ const payload = new ConsensusPayload(proposal.checkpointHeader, proposal.archive, proposal.feeAssetPriceModifier);
141
148
  const buf = Buffer32.fromBuffer(
142
149
  keccak256(payload.getPayloadToSign(SignatureDomainSeparator.checkpointAttestation)),
143
150
  );
package/src/factory.ts CHANGED
@@ -29,6 +29,7 @@ export function createBlockProposalHandler(
29
29
  const metrics = new ValidatorMetrics(deps.telemetry);
30
30
  const blockProposalValidator = new BlockProposalValidator(deps.epochCache, {
31
31
  txsPermitted: !config.disableTransactions,
32
+ maxTxsPerBlock: config.maxTxsPerBlock,
32
33
  });
33
34
  return new BlockProposalHandler(
34
35
  deps.checkpointsBuilder,
package/src/index.ts CHANGED
@@ -4,4 +4,3 @@ export * from './config.js';
4
4
  export * from './factory.js';
5
5
  export * from './validator.js';
6
6
  export * from './key_store/index.js';
7
- export * from './tx_validator/index.js';
package/src/metrics.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { EpochNumber } from '@aztec/foundation/branded-types';
2
+ import type { EthAddress } from '@aztec/foundation/eth-address';
1
3
  import type { BlockProposal } from '@aztec/stdlib/p2p';
2
4
  import {
3
5
  Attributes,
@@ -16,6 +18,8 @@ export class ValidatorMetrics {
16
18
  private successfulAttestationsCount: UpDownCounter;
17
19
  private failedAttestationsBadProposalCount: UpDownCounter;
18
20
  private failedAttestationsNodeIssueCount: UpDownCounter;
21
+ private currentEpoch: Gauge;
22
+ private attestedEpochCount: UpDownCounter;
19
23
 
20
24
  private reexMana: Histogram;
21
25
  private reexTx: Histogram;
@@ -64,6 +68,10 @@ export class ValidatorMetrics {
64
68
  },
65
69
  );
66
70
 
71
+ this.currentEpoch = meter.createGauge(Metrics.VALIDATOR_CURRENT_EPOCH);
72
+
73
+ this.attestedEpochCount = createUpDownCounterWithDefault(meter, Metrics.VALIDATOR_ATTESTED_EPOCH_COUNT);
74
+
67
75
  this.reexMana = meter.createHistogram(Metrics.VALIDATOR_RE_EXECUTION_MANA);
68
76
 
69
77
  this.reexTx = meter.createHistogram(Metrics.VALIDATOR_RE_EXECUTION_TX_COUNT);
@@ -110,4 +118,14 @@ export class ValidatorMetrics {
110
118
  [Attributes.IS_COMMITTEE_MEMBER]: inCommittee,
111
119
  });
112
120
  }
121
+
122
+ /** Update the gauge tracking the current epoch number (proxy for total epochs elapsed). */
123
+ public setCurrentEpoch(epoch: EpochNumber) {
124
+ this.currentEpoch.record(Number(epoch));
125
+ }
126
+
127
+ /** Increment the count of epochs in which the given attester submitted at least one attestation. */
128
+ public incAttestedEpochCount(attester: EthAddress) {
129
+ this.attestedEpochCount.add(1, { [Attributes.ATTESTER_ADDRESS]: attester.toString() });
130
+ }
113
131
  }
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,
@@ -23,7 +24,7 @@ import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol }
23
24
  import { OffenseType, WANT_TO_SLASH_EVENT, type Watcher, type WatcherEmitter } from '@aztec/slasher';
24
25
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
25
26
  import type { CommitteeAttestationsAndSigners, L2Block, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
26
- import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
27
+ import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
27
28
  import type {
28
29
  CreateCheckpointProposalLastBlockData,
29
30
  ITxProvider,
@@ -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
 
@@ -88,6 +89,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
88
89
 
89
90
  private lastEpochForCommitteeUpdateLoop: EpochNumber | undefined;
90
91
  private epochCacheUpdateLoop: RunningPromise;
92
+ /** Tracks the last epoch in which each attester successfully submitted at least one attestation. */
93
+ private lastAttestedEpochByAttester: Map<string, EpochNumber> = new Map();
91
94
 
92
95
  private proposersOfInvalidBlocks: Set<string> = new Set();
93
96
 
@@ -105,6 +108,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
105
108
  private l1ToL2MessageSource: L1ToL2MessageSource,
106
109
  private config: ValidatorClientFullConfig,
107
110
  private blobClient: BlobClientInterface,
111
+ private haSigner: ValidatorHASigner | undefined,
108
112
  private dateProvider: DateProvider = new DateProvider(),
109
113
  telemetry: TelemetryClient = getTelemetryClient(),
110
114
  log = createLogger('validator'),
@@ -158,6 +162,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
158
162
  this.log.trace(`No committee found for slot`);
159
163
  return;
160
164
  }
165
+ this.metrics.setCurrentEpoch(epoch);
161
166
  if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
162
167
  const me = this.getValidatorAddresses();
163
168
  const committeeSet = new Set(committee.map(v => v.toString()));
@@ -195,6 +200,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
195
200
  const metrics = new ValidatorMetrics(telemetry);
196
201
  const blockProposalValidator = new BlockProposalValidator(epochCache, {
197
202
  txsPermitted: !config.disableTransactions,
203
+ maxTxsPerBlock: config.maxTxsPerBlock,
198
204
  });
199
205
  const blockProposalHandler = new BlockProposalHandler(
200
206
  checkpointsBuilder,
@@ -210,15 +216,18 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
210
216
  telemetry,
211
217
  );
212
218
 
213
- let validatorKeyStore: ExtendedValidatorKeyStore = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
219
+ const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
220
+ let validatorKeyStore: ExtendedValidatorKeyStore = nodeKeystoreAdapter;
221
+ let haSigner: ValidatorHASigner | undefined;
214
222
  if (config.haSigningEnabled) {
215
223
  // If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
216
224
  const haConfig = {
217
225
  ...config,
218
226
  maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000,
219
227
  };
220
- const { signer } = await createHASigner(haConfig);
221
- validatorKeyStore = new HAKeyStore(validatorKeyStore, signer);
228
+ const { signer } = await createHASigner(haConfig, { telemetryClient: telemetry, dateProvider });
229
+ haSigner = signer;
230
+ validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, signer);
222
231
  }
223
232
 
224
233
  const validator = new ValidatorClient(
@@ -232,6 +241,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
232
241
  l1ToL2MessageSource,
233
242
  config,
234
243
  blobClient,
244
+ haSigner,
235
245
  dateProvider,
236
246
  telemetry,
237
247
  );
@@ -269,6 +279,28 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
269
279
  this.config = { ...this.config, ...config };
270
280
  }
271
281
 
282
+ public reloadKeystore(newManager: KeystoreManager): void {
283
+ if (this.config.haSigningEnabled && !this.haSigner) {
284
+ this.log.warn(
285
+ 'HA signing is enabled in config but was not initialized at startup. ' +
286
+ 'Restart the node to enable HA signing.',
287
+ );
288
+ } else if (!this.config.haSigningEnabled && this.haSigner) {
289
+ this.log.warn(
290
+ 'HA signing was disabled via config update but the HA signer is still active. ' +
291
+ 'Restart the node to fully disable HA signing.',
292
+ );
293
+ }
294
+
295
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
296
+ if (this.haSigner) {
297
+ this.keyStore = new HAKeyStore(newAdapter, this.haSigner);
298
+ } else {
299
+ this.keyStore = newAdapter;
300
+ }
301
+ this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
302
+ }
303
+
272
304
  public async start() {
273
305
  if (this.epochCacheUpdateLoop.isRunning()) {
274
306
  this.log.warn(`Validator client already started`);
@@ -471,6 +503,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
471
503
  return undefined;
472
504
  }
473
505
 
506
+ // Validate fee asset price modifier is within allowed range
507
+ if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
508
+ this.log.warn(
509
+ `Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`,
510
+ );
511
+ return undefined;
512
+ }
513
+
474
514
  // Check that I have any address in current committee before attesting
475
515
  const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
476
516
  const partOfCommittee = inCommittee.length > 0;
@@ -519,6 +559,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
519
559
 
520
560
  this.metrics.incSuccessfulAttestations(inCommittee.length);
521
561
 
562
+ // Track epoch participation per attester: count each (attester, epoch) pair at most once
563
+ const proposalEpoch = getEpochAtSlot(slotNumber, this.epochCache.getL1Constants());
564
+ for (const attester of inCommittee) {
565
+ const key = attester.toString();
566
+ const lastEpoch = this.lastAttestedEpochByAttester.get(key);
567
+ if (lastEpoch === undefined || proposalEpoch > lastEpoch) {
568
+ this.lastAttestedEpochByAttester.set(key, proposalEpoch);
569
+ this.metrics.incAttestedEpochCount(attester);
570
+ }
571
+ }
572
+
522
573
  // Determine which validators should attest
523
574
  let attestors: EthAddress[];
524
575
  if (partOfCommittee) {
@@ -595,7 +646,11 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
595
646
  proposalInfo: LogData,
596
647
  ): Promise<{ isValid: true } | { isValid: false; reason: string }> {
597
648
  const slot = proposal.slotNumber;
598
- const timeoutSeconds = 10; // TODO(palla/mbps): This should map to the timetable settings
649
+
650
+ // Timeout block syncing at the start of the next slot
651
+ const config = this.checkpointsBuilder.getConfig();
652
+ const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
653
+ const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
599
654
 
600
655
  // Wait for last block to sync by archive
601
656
  let lastBlockHeader: BlockHeader | undefined;
@@ -630,6 +685,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
630
685
  return { isValid: false, reason: 'no_blocks_for_slot' };
631
686
  }
632
687
 
688
+ // Ensure the last block for this slot matches the archive in the checkpoint proposal
689
+ if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
690
+ this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
691
+ return { isValid: false, reason: 'last_block_archive_mismatch' };
692
+ }
693
+
633
694
  this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
634
695
  ...proposalInfo,
635
696
  blockNumbers: blocks.map(b => b.number),
@@ -643,14 +704,11 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
643
704
  // Get L1-to-L2 messages for this checkpoint
644
705
  const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
645
706
 
646
- // Compute the previous checkpoint out hashes for the epoch.
647
- // TODO: There can be a more efficient way to get the previous checkpoint out hashes without having to fetch the
648
- // actual checkpoints and the blocks/txs in them.
707
+ // Collect the out hashes of all the checkpoints before this one in the same epoch
649
708
  const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
650
- const previousCheckpoints = (await this.blockSource.getCheckpointsForEpoch(epoch))
651
- .filter(b => b.number < checkpointNumber)
652
- .sort((a, b) => a.number - b.number);
653
- const previousCheckpointOutHashes = previousCheckpoints.map(c => c.getCheckpointOutHash());
709
+ const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch))
710
+ .filter(c => c.checkpointNumber < checkpointNumber)
711
+ .map(c => c.checkpointOutHash);
654
712
 
655
713
  // Fork world state at the block before the first block
656
714
  const parentBlockNumber = BlockNumber(firstBlock.number - 1);
@@ -661,6 +719,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
661
719
  const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
662
720
  checkpointNumber,
663
721
  constants,
722
+ proposal.feeAssetPriceModifier,
664
723
  l1ToL2Messages,
665
724
  previousCheckpointOutHashes,
666
725
  fork,
@@ -723,6 +782,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
723
782
  chainId: gv.chainId,
724
783
  version: gv.version,
725
784
  slotNumber: gv.slotNumber,
785
+ timestamp: gv.timestamp,
726
786
  coinbase: gv.coinbase,
727
787
  feeRecipient: gv.feeRecipient,
728
788
  gasFees: gv.gasFees,
@@ -732,7 +792,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
732
792
  /**
733
793
  * Uploads blobs for a checkpoint to the filestore (fire and forget).
734
794
  */
735
- private async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
795
+ protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
736
796
  try {
737
797
  const lastBlockHeader = await this.blockSource.getBlockHeaderByArchive(proposal.archive);
738
798
  if (!lastBlockHeader) {
@@ -747,7 +807,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
747
807
  }
748
808
 
749
809
  const blobFields = blocks.flatMap(b => b.toBlobFields());
750
- const blobs: Blob[] = getBlobsPerL1Block(blobFields);
810
+ const blobs: Blob[] = await getBlobsPerL1Block(blobFields);
751
811
  await this.blobClient.sendBlobsToFilestore(blobs);
752
812
  this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
753
813
  ...proposalInfo,
@@ -876,6 +936,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
876
936
  async createCheckpointProposal(
877
937
  checkpointHeader: CheckpointHeader,
878
938
  archive: Fr,
939
+ feeAssetPriceModifier: bigint,
879
940
  lastBlockInfo: CreateCheckpointProposalLastBlockData | undefined,
880
941
  proposerAddress: EthAddress | undefined,
881
942
  options: CheckpointProposalOptions = {},
@@ -897,6 +958,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
897
958
  const newProposal = await this.validationService.createCheckpointProposal(
898
959
  checkpointHeader,
899
960
  archive,
961
+ feeAssetPriceModifier,
900
962
  lastBlockInfo,
901
963
  proposerAddress,
902
964
  options,
@@ -1,3 +0,0 @@
1
- export * from './nullifier_cache.js';
2
- export * from './tx_validator_factory.js';
3
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90eF92YWxpZGF0b3IvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxzQkFBc0IsQ0FBQztBQUNyQyxjQUFjLDJCQUEyQixDQUFDIn0=
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tx_validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './nullifier_cache.js';
2
- export * from './tx_validator_factory.js';
@@ -1,14 +0,0 @@
1
- import type { NullifierSource } from '@aztec/p2p';
2
- import type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
3
- /**
4
- * Implements a nullifier source by checking a DB and an in-memory collection.
5
- * Intended for validating transactions as they are added to a block.
6
- */
7
- export declare class NullifierCache implements NullifierSource {
8
- private db;
9
- nullifiers: Set<string>;
10
- constructor(db: MerkleTreeReadOperations);
11
- nullifiersExist(nullifiers: Buffer[]): Promise<boolean[]>;
12
- addNullifiers(nullifiers: Buffer[]): void;
13
- }
14
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnVsbGlmaWVyX2NhY2hlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdHhfdmFsaWRhdG9yL251bGxpZmllcl9jYWNoZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxlQUFlLEVBQUUsTUFBTSxZQUFZLENBQUM7QUFDbEQsT0FBTyxLQUFLLEVBQUUsd0JBQXdCLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUdoRjs7O0dBR0c7QUFDSCxxQkFBYSxjQUFlLFlBQVcsZUFBZTtJQUd4QyxPQUFPLENBQUMsRUFBRTtJQUZ0QixVQUFVLEVBQUUsR0FBRyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0lBRXhCLFlBQW9CLEVBQUUsRUFBRSx3QkFBd0IsRUFFL0M7SUFFWSxlQUFlLENBQUMsVUFBVSxFQUFFLE1BQU0sRUFBRSxHQUFHLE9BQU8sQ0FBQyxPQUFPLEVBQUUsQ0FBQyxDQU9yRTtJQUVNLGFBQWEsQ0FBQyxVQUFVLEVBQUUsTUFBTSxFQUFFLFFBSXhDO0NBQ0YifQ==
@@ -1 +0,0 @@
1
- {"version":3,"file":"nullifier_cache.d.ts","sourceRoot":"","sources":["../../src/tx_validator/nullifier_cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAGhF;;;GAGG;AACH,qBAAa,cAAe,YAAW,eAAe;IAGxC,OAAO,CAAC,EAAE;IAFtB,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAExB,YAAoB,EAAE,EAAE,wBAAwB,EAE/C;IAEY,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAOrE;IAEM,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,QAIxC;CACF"}
@@ -1,24 +0,0 @@
1
- import { MerkleTreeId } from '@aztec/stdlib/trees';
2
- /**
3
- * Implements a nullifier source by checking a DB and an in-memory collection.
4
- * Intended for validating transactions as they are added to a block.
5
- */ export class NullifierCache {
6
- db;
7
- nullifiers;
8
- constructor(db){
9
- this.db = db;
10
- this.nullifiers = new Set();
11
- }
12
- async nullifiersExist(nullifiers) {
13
- const cacheResults = nullifiers.map((n)=>this.nullifiers.has(n.toString()));
14
- const toCheckDb = nullifiers.filter((_n, index)=>!cacheResults[index]);
15
- const dbHits = await this.db.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, toCheckDb);
16
- let dbIndex = 0;
17
- return nullifiers.map((_n, index)=>cacheResults[index] || dbHits[dbIndex++] !== undefined);
18
- }
19
- addNullifiers(nullifiers) {
20
- for (const nullifier of nullifiers){
21
- this.nullifiers.add(nullifier.toString());
22
- }
23
- }
24
- }
@@ -1,19 +0,0 @@
1
- import { BlockNumber } from '@aztec/foundation/branded-types';
2
- import type { LoggerBindings } from '@aztec/foundation/log';
3
- import type { ContractDataSource } from '@aztec/stdlib/contract';
4
- import type { GasFees } from '@aztec/stdlib/gas';
5
- import type { AllowedElement, ClientProtocolCircuitVerifier, MerkleTreeReadOperations, PublicProcessorValidator } from '@aztec/stdlib/interfaces/server';
6
- import { GlobalVariables, type Tx, type TxValidator } from '@aztec/stdlib/tx';
7
- import type { UInt64 } from '@aztec/stdlib/types';
8
- export declare function createValidatorForAcceptingTxs(db: MerkleTreeReadOperations, contractDataSource: ContractDataSource, verifier: ClientProtocolCircuitVerifier | undefined, { l1ChainId, rollupVersion, setupAllowList, gasFees, skipFeeEnforcement, timestamp, blockNumber, txsPermitted }: {
9
- l1ChainId: number;
10
- rollupVersion: number;
11
- setupAllowList: AllowedElement[];
12
- gasFees: GasFees;
13
- skipFeeEnforcement?: boolean;
14
- timestamp: UInt64;
15
- blockNumber: BlockNumber;
16
- txsPermitted: boolean;
17
- }, bindings?: LoggerBindings): TxValidator<Tx>;
18
- export declare function createValidatorForBlockBuilding(db: MerkleTreeReadOperations, contractDataSource: ContractDataSource, globalVariables: GlobalVariables, setupAllowList: AllowedElement[], bindings?: LoggerBindings): PublicProcessorValidator;
19
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhfdmFsaWRhdG9yX2ZhY3RvcnkuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90eF92YWxpZGF0b3IvdHhfdmFsaWRhdG9yX2ZhY3RvcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBRTlELE9BQU8sS0FBSyxFQUFFLGNBQWMsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBaUI1RCxPQUFPLEtBQUssRUFBRSxrQkFBa0IsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQ2pFLE9BQU8sS0FBSyxFQUFFLE9BQU8sRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQ2pELE9BQU8sS0FBSyxFQUNWLGNBQWMsRUFDZCw2QkFBNkIsRUFDN0Isd0JBQXdCLEVBQ3hCLHdCQUF3QixFQUN6QixNQUFNLGlDQUFpQyxDQUFDO0FBRXpDLE9BQU8sRUFBRSxlQUFlLEVBQUUsS0FBSyxFQUFFLEVBQUUsS0FBSyxXQUFXLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUM5RSxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUlsRCx3QkFBZ0IsOEJBQThCLENBQzVDLEVBQUUsRUFBRSx3QkFBd0IsRUFDNUIsa0JBQWtCLEVBQUUsa0JBQWtCLEVBQ3RDLFFBQVEsRUFBRSw2QkFBNkIsR0FBRyxTQUFTLEVBQ25ELEVBQ0UsU0FBUyxFQUNULGFBQWEsRUFDYixjQUFjLEVBQ2QsT0FBTyxFQUNQLGtCQUFrQixFQUNsQixTQUFTLEVBQ1QsV0FBVyxFQUNYLFlBQVksRUFDYixFQUFFO0lBQ0QsU0FBUyxFQUFFLE1BQU0sQ0FBQztJQUNsQixhQUFhLEVBQUUsTUFBTSxDQUFDO0lBQ3RCLGNBQWMsRUFBRSxjQUFjLEVBQUUsQ0FBQztJQUNqQyxPQUFPLEVBQUUsT0FBTyxDQUFDO0lBQ2pCLGtCQUFrQixDQUFDLEVBQUUsT0FBTyxDQUFDO0lBQzdCLFNBQVMsRUFBRSxNQUFNLENBQUM7SUFDbEIsV0FBVyxFQUFFLFdBQVcsQ0FBQztJQUN6QixZQUFZLEVBQUUsT0FBTyxDQUFDO0NBQ3ZCLEVBQ0QsUUFBUSxDQUFDLEVBQUUsY0FBYyxHQUN4QixXQUFXLENBQUMsRUFBRSxDQUFDLENBcUNqQjtBQUVELHdCQUFnQiwrQkFBK0IsQ0FDN0MsRUFBRSxFQUFFLHdCQUF3QixFQUM1QixrQkFBa0IsRUFBRSxrQkFBa0IsRUFDdEMsZUFBZSxFQUFFLGVBQWUsRUFDaEMsY0FBYyxFQUFFLGNBQWMsRUFBRSxFQUNoQyxRQUFRLENBQUMsRUFBRSxjQUFjLEdBQ3hCLHdCQUF3QixDQWlCMUIifQ==
@@ -1 +0,0 @@
1
- {"version":3,"file":"tx_validator_factory.d.ts","sourceRoot":"","sources":["../../src/tx_validator/tx_validator_factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAiB5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EACV,cAAc,EACd,6BAA6B,EAC7B,wBAAwB,EACxB,wBAAwB,EACzB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAIlD,wBAAgB,8BAA8B,CAC5C,EAAE,EAAE,wBAAwB,EAC5B,kBAAkB,EAAE,kBAAkB,EACtC,QAAQ,EAAE,6BAA6B,GAAG,SAAS,EACnD,EACE,SAAS,EACT,aAAa,EACb,cAAc,EACd,OAAO,EACP,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,YAAY,EACb,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,cAAc,EAAE,CAAC;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,WAAW,CAAC;IACzB,YAAY,EAAE,OAAO,CAAC;CACvB,EACD,QAAQ,CAAC,EAAE,cAAc,GACxB,WAAW,CAAC,EAAE,CAAC,CAqCjB;AAED,wBAAgB,+BAA+B,CAC7C,EAAE,EAAE,wBAAwB,EAC5B,kBAAkB,EAAE,kBAAkB,EACtC,eAAe,EAAE,eAAe,EAChC,cAAc,EAAE,cAAc,EAAE,EAChC,QAAQ,CAAC,EAAE,cAAc,GACxB,wBAAwB,CAiB1B"}
@@ -1,54 +0,0 @@
1
- import { Fr } from '@aztec/foundation/curves/bn254';
2
- import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
3
- import { AggregateTxValidator, ArchiveCache, BlockHeaderTxValidator, DataTxValidator, DoubleSpendTxValidator, GasTxValidator, MetadataTxValidator, PhasesTxValidator, SizeTxValidator, TimestampTxValidator, TxPermittedValidator, TxProofValidator } from '@aztec/p2p';
4
- import { ProtocolContractAddress, protocolContractsHash } from '@aztec/protocol-contracts';
5
- import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
6
- import { NullifierCache } from './nullifier_cache.js';
7
- export function createValidatorForAcceptingTxs(db, contractDataSource, verifier, { l1ChainId, rollupVersion, setupAllowList, gasFees, skipFeeEnforcement, timestamp, blockNumber, txsPermitted }, bindings) {
8
- const validators = [
9
- new TxPermittedValidator(txsPermitted, bindings),
10
- new SizeTxValidator(bindings),
11
- new DataTxValidator(bindings),
12
- new MetadataTxValidator({
13
- l1ChainId: new Fr(l1ChainId),
14
- rollupVersion: new Fr(rollupVersion),
15
- protocolContractsHash,
16
- vkTreeRoot: getVKTreeRoot()
17
- }, bindings),
18
- new TimestampTxValidator({
19
- timestamp,
20
- blockNumber
21
- }, bindings),
22
- new DoubleSpendTxValidator(new NullifierCache(db), bindings),
23
- new PhasesTxValidator(contractDataSource, setupAllowList, timestamp, bindings),
24
- new BlockHeaderTxValidator(new ArchiveCache(db), bindings)
25
- ];
26
- if (!skipFeeEnforcement) {
27
- validators.push(new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, gasFees, bindings));
28
- }
29
- if (verifier) {
30
- validators.push(new TxProofValidator(verifier, bindings));
31
- }
32
- return new AggregateTxValidator(...validators);
33
- }
34
- export function createValidatorForBlockBuilding(db, contractDataSource, globalVariables, setupAllowList, bindings) {
35
- const nullifierCache = new NullifierCache(db);
36
- const archiveCache = new ArchiveCache(db);
37
- const publicStateSource = new DatabasePublicStateSource(db);
38
- return {
39
- preprocessValidator: preprocessValidator(nullifierCache, archiveCache, publicStateSource, contractDataSource, globalVariables, setupAllowList, bindings),
40
- nullifierCache
41
- };
42
- }
43
- function preprocessValidator(nullifierCache, archiveCache, publicStateSource, contractDataSource, globalVariables, setupAllowList, bindings) {
44
- // We don't include the TxProofValidator nor the DataTxValidator here because they are already checked by the time we get to block building.
45
- return new AggregateTxValidator(new MetadataTxValidator({
46
- l1ChainId: globalVariables.chainId,
47
- rollupVersion: globalVariables.version,
48
- protocolContractsHash,
49
- vkTreeRoot: getVKTreeRoot()
50
- }, bindings), new TimestampTxValidator({
51
- timestamp: globalVariables.timestamp,
52
- blockNumber: globalVariables.blockNumber
53
- }, bindings), new DoubleSpendTxValidator(nullifierCache, bindings), new PhasesTxValidator(contractDataSource, setupAllowList, globalVariables.timestamp, bindings), new GasTxValidator(publicStateSource, ProtocolContractAddress.FeeJuice, globalVariables.gasFees, bindings), new BlockHeaderTxValidator(archiveCache, bindings));
54
- }
@@ -1,2 +0,0 @@
1
- export * from './nullifier_cache.js';
2
- export * from './tx_validator_factory.js';