@aztec/validator-client 0.0.1-commit.cd76b27 → 0.0.1-commit.d0fcfb7f

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 (48) hide show
  1. package/README.md +42 -0
  2. package/dest/block_proposal_handler.d.ts +4 -3
  3. package/dest/block_proposal_handler.d.ts.map +1 -1
  4. package/dest/block_proposal_handler.js +104 -30
  5. package/dest/checkpoint_builder.d.ts +14 -3
  6. package/dest/checkpoint_builder.d.ts.map +1 -1
  7. package/dest/checkpoint_builder.js +103 -37
  8. package/dest/config.d.ts +1 -1
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +20 -0
  11. package/dest/duties/validation_service.d.ts +1 -1
  12. package/dest/duties/validation_service.d.ts.map +1 -1
  13. package/dest/duties/validation_service.js +3 -9
  14. package/dest/factory.d.ts +1 -1
  15. package/dest/factory.d.ts.map +1 -1
  16. package/dest/factory.js +2 -1
  17. package/dest/index.d.ts +1 -2
  18. package/dest/index.d.ts.map +1 -1
  19. package/dest/index.js +0 -1
  20. package/dest/key_store/ha_key_store.js +1 -1
  21. package/dest/metrics.d.ts +9 -1
  22. package/dest/metrics.d.ts.map +1 -1
  23. package/dest/metrics.js +12 -0
  24. package/dest/validator.d.ts +3 -1
  25. package/dest/validator.d.ts.map +1 -1
  26. package/dest/validator.js +36 -8
  27. package/package.json +19 -19
  28. package/src/block_proposal_handler.ts +126 -37
  29. package/src/checkpoint_builder.ts +122 -39
  30. package/src/config.ts +20 -0
  31. package/src/duties/validation_service.ts +3 -9
  32. package/src/factory.ts +1 -0
  33. package/src/index.ts +0 -1
  34. package/src/key_store/ha_key_store.ts +1 -1
  35. package/src/metrics.ts +18 -0
  36. package/src/validator.ts +35 -6
  37. package/dest/tx_validator/index.d.ts +0 -3
  38. package/dest/tx_validator/index.d.ts.map +0 -1
  39. package/dest/tx_validator/index.js +0 -2
  40. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  41. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  42. package/dest/tx_validator/nullifier_cache.js +0 -24
  43. package/dest/tx_validator/tx_validator_factory.d.ts +0 -19
  44. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  45. package/dest/tx_validator/tx_validator_factory.js +0 -54
  46. package/src/tx_validator/index.ts +0 -2
  47. package/src/tx_validator/nullifier_cache.ts +0 -30
  48. package/src/tx_validator/tx_validator_factory.ts +0 -154
@@ -1,10 +1,12 @@
1
+ import { NUM_CHECKPOINT_END_MARKER_FIELDS, getNumBlockEndBlobFields } from '@aztec/blob-lib/encoding';
2
+ import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB, MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT } from '@aztec/constants';
1
3
  import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
2
- import { merge, pick } from '@aztec/foundation/collection';
4
+ import { merge, pick, sum } from '@aztec/foundation/collection';
3
5
  import { Fr } from '@aztec/foundation/curves/bn254';
4
6
  import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
5
7
  import { bufferToHex } from '@aztec/foundation/string';
6
8
  import { DateProvider, elapsed } from '@aztec/foundation/timer';
7
- import { getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
9
+ import { createTxValidatorForBlockBuilding, getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
8
10
  import { LightweightCheckpointBuilder } from '@aztec/prover-client/light';
9
11
  import {
10
12
  GuardedMerkleTreeOperations,
@@ -23,16 +25,16 @@ import {
23
25
  FullNodeBlockBuilderConfigKeys,
24
26
  type ICheckpointBlockBuilder,
25
27
  type ICheckpointsBuilder,
28
+ InsufficientValidTxsError,
26
29
  type MerkleTreeWriteOperations,
27
- NoValidTxsError,
28
30
  type PublicProcessorLimits,
29
31
  type WorldStateSynchronizer,
30
32
  } from '@aztec/stdlib/interfaces/server';
33
+ import { type DebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
31
34
  import { MerkleTreeId } from '@aztec/stdlib/trees';
32
35
  import { type CheckpointGlobalVariables, GlobalVariables, StateReference, Tx } from '@aztec/stdlib/tx';
33
36
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
34
-
35
- import { createValidatorForBlockBuilding } from './tx_validator/tx_validator_factory.js';
37
+ import { ForkCheckpoint } from '@aztec/world-state';
36
38
 
37
39
  // Re-export for backward compatibility
38
40
  export type { BuildBlockInCheckpointResult } from '@aztec/stdlib/interfaces/server';
@@ -52,6 +54,7 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
52
54
  private dateProvider: DateProvider,
53
55
  private telemetryClient: TelemetryClient,
54
56
  bindings?: LoggerBindings,
57
+ private debugLogStore: DebugLogStore = new NullDebugLogStore(),
55
58
  ) {
56
59
  this.log = createLogger('checkpoint-builder', {
57
60
  ...bindings,
@@ -65,12 +68,13 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
65
68
 
66
69
  /**
67
70
  * Builds a single block within this checkpoint.
71
+ * Automatically caps gas and blob field limits based on checkpoint-level budgets and prior blocks.
68
72
  */
69
73
  async buildBlock(
70
74
  pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
71
75
  blockNumber: BlockNumber,
72
76
  timestamp: bigint,
73
- opts: PublicProcessorLimits & { expectedEndState?: StateReference } = {},
77
+ opts: PublicProcessorLimits & { expectedEndState?: StateReference; minValidTxs?: number } = {},
74
78
  ): Promise<BuildBlockInCheckpointResult> {
75
79
  const slot = this.checkpointBuilder.constants.slotNumber;
76
80
 
@@ -94,39 +98,53 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
94
98
  });
95
99
  const { processor, validator } = await this.makeBlockBuilderDeps(globalVariables, this.fork);
96
100
 
97
- const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs, _, usedTxBlobFields]] = await elapsed(() =>
98
- processor.process(pendingTxs, opts, validator),
99
- );
100
-
101
- // Throw if we didn't collect a single valid tx and we're not allowed to build empty blocks
102
- // (only the first block in a checkpoint can be empty)
103
- if (processedTxs.length === 0 && this.checkpointBuilder.getBlockCount() > 0) {
104
- throw new NoValidTxsError(failedTxs);
105
- }
106
-
107
- // Add block to checkpoint
108
- const block = await this.checkpointBuilder.addBlock(globalVariables, processedTxs, {
109
- expectedEndState: opts.expectedEndState,
110
- });
111
-
112
- // How much public gas was processed
113
- const publicGas = processedTxs.reduce((acc, tx) => acc.add(tx.gasUsed.publicGas), Gas.empty());
101
+ // Cap gas limits amd available blob fields by remaining checkpoint-level budgets
102
+ const cappedOpts: PublicProcessorLimits & { expectedEndState?: StateReference } = {
103
+ ...opts,
104
+ ...this.capLimitsByCheckpointBudgets(opts),
105
+ };
114
106
 
115
- this.log.debug('Built block within checkpoint', {
116
- header: block.header.toInspect(),
117
- processedTxs: processedTxs.map(tx => tx.hash.toString()),
118
- failedTxs: failedTxs.map(tx => tx.tx.txHash.toString()),
119
- });
107
+ // We execute all merkle tree operations on a world state fork checkpoint
108
+ // This enables us to discard all modifications in the event that we fail to successfully process sufficient transactions
109
+ const forkCheckpoint = await ForkCheckpoint.new(this.fork);
120
110
 
121
- return {
122
- block,
123
- publicGas,
124
- publicProcessorDuration,
125
- numTxs: processedTxs.length,
126
- failedTxs,
127
- usedTxs,
128
- usedTxBlobFields,
129
- };
111
+ try {
112
+ const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(() =>
113
+ processor.process(pendingTxs, cappedOpts, validator),
114
+ );
115
+ // Throw before updating state if we don't have enough valid txs
116
+ const minValidTxs = opts.minValidTxs ?? 0;
117
+ if (processedTxs.length < minValidTxs) {
118
+ throw new InsufficientValidTxsError(processedTxs.length, minValidTxs, failedTxs);
119
+ }
120
+
121
+ // Commit the fork checkpoint
122
+ await forkCheckpoint.commit();
123
+
124
+ // Add block to checkpoint
125
+ const block = await this.checkpointBuilder.addBlock(globalVariables, processedTxs, {
126
+ expectedEndState: opts.expectedEndState,
127
+ });
128
+
129
+ this.log.debug('Built block within checkpoint', {
130
+ header: block.header.toInspect(),
131
+ processedTxs: processedTxs.map(tx => tx.hash.toString()),
132
+ failedTxs: failedTxs.map(tx => tx.tx.txHash.toString()),
133
+ });
134
+
135
+ return {
136
+ block,
137
+ publicProcessorDuration,
138
+ numTxs: processedTxs.length,
139
+ failedTxs,
140
+ usedTxs,
141
+ };
142
+ } catch (err) {
143
+ // If we reached the point of committing the checkpoint, this does nothing
144
+ // Otherwise it reverts any changes made to the fork for this failed block
145
+ await forkCheckpoint.revert();
146
+ throw err;
147
+ }
130
148
  }
131
149
 
132
150
  /** Completes the checkpoint and returns it. */
@@ -147,11 +165,71 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
147
165
  return this.checkpointBuilder.clone().completeCheckpoint();
148
166
  }
149
167
 
168
+ /**
169
+ * Caps per-block gas and blob field limits by remaining checkpoint-level budgets.
170
+ * Computes remaining L2 gas (mana), DA gas, and blob fields from blocks already added to the checkpoint,
171
+ * then returns opts with maxBlockGas and maxBlobFields capped accordingly.
172
+ */
173
+ protected capLimitsByCheckpointBudgets(
174
+ opts: PublicProcessorLimits,
175
+ ): Pick<PublicProcessorLimits, 'maxBlockGas' | 'maxBlobFields' | 'maxTransactions'> {
176
+ const existingBlocks = this.checkpointBuilder.getBlocks();
177
+
178
+ // Remaining L2 gas (mana)
179
+ // IMPORTANT: This assumes mana is computed solely based on L2 gas used in transactions.
180
+ // This may change in the future.
181
+ const usedMana = sum(existingBlocks.map(b => b.header.totalManaUsed.toNumber()));
182
+ const remainingMana = this.config.rollupManaLimit - usedMana;
183
+
184
+ // Remaining DA gas
185
+ const usedDAGas = sum(existingBlocks.map(b => b.computeDAGasUsed())) ?? 0;
186
+ const remainingDAGas = MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT - usedDAGas;
187
+
188
+ // Remaining blob fields (block blob fields include both tx data and block-end overhead)
189
+ const usedBlobFields = sum(existingBlocks.map(b => b.toBlobFields().length));
190
+ const totalBlobCapacity = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
191
+ const isFirstBlock = existingBlocks.length === 0;
192
+ const blockEndOverhead = getNumBlockEndBlobFields(isFirstBlock);
193
+ const maxBlobFieldsForTxs = totalBlobCapacity - usedBlobFields - blockEndOverhead;
194
+
195
+ // Cap L2 gas by remaining checkpoint mana
196
+ const cappedL2Gas = Math.min(opts.maxBlockGas?.l2Gas ?? remainingMana, remainingMana);
197
+
198
+ // Cap DA gas by remaining checkpoint DA gas budget
199
+ const cappedDAGas = Math.min(opts.maxBlockGas?.daGas ?? remainingDAGas, remainingDAGas);
200
+
201
+ // Cap blob fields by remaining checkpoint blob capacity
202
+ const cappedBlobFields =
203
+ opts.maxBlobFields !== undefined ? Math.min(opts.maxBlobFields, maxBlobFieldsForTxs) : maxBlobFieldsForTxs;
204
+
205
+ // Cap transaction count by remaining checkpoint tx budget
206
+ let cappedMaxTransactions: number | undefined;
207
+ if (this.config.maxTxsPerCheckpoint !== undefined) {
208
+ const usedTxs = sum(existingBlocks.map(b => b.body.txEffects.length));
209
+ const remainingTxs = Math.max(0, this.config.maxTxsPerCheckpoint - usedTxs);
210
+ cappedMaxTransactions =
211
+ opts.maxTransactions !== undefined ? Math.min(opts.maxTransactions, remainingTxs) : remainingTxs;
212
+ } else {
213
+ cappedMaxTransactions = opts.maxTransactions;
214
+ }
215
+
216
+ return {
217
+ maxBlockGas: new Gas(cappedDAGas, cappedL2Gas),
218
+ maxBlobFields: cappedBlobFields,
219
+ maxTransactions: cappedMaxTransactions,
220
+ };
221
+ }
222
+
150
223
  protected async makeBlockBuilderDeps(globalVariables: GlobalVariables, fork: MerkleTreeWriteOperations) {
151
- const txPublicSetupAllowList = this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
224
+ const txPublicSetupAllowList = [
225
+ ...(await getDefaultAllowedSetupFunctions()),
226
+ ...(this.config.txPublicSetupAllowListExtend ?? []),
227
+ ];
152
228
  const contractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings());
153
229
  const guardedFork = new GuardedMerkleTreeOperations(fork);
154
230
 
231
+ const collectDebugLogs = this.debugLogStore.isEnabled;
232
+
155
233
  const bindings = this.log.getBindings();
156
234
  const publicTxSimulator = createPublicTxSimulatorForBlockBuilding(
157
235
  guardedFork,
@@ -159,6 +237,7 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
159
237
  globalVariables,
160
238
  this.telemetryClient,
161
239
  bindings,
240
+ collectDebugLogs,
162
241
  );
163
242
 
164
243
  const processor = new PublicProcessor(
@@ -170,9 +249,10 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
170
249
  this.telemetryClient,
171
250
  createLogger('simulator:public-processor', bindings),
172
251
  this.config,
252
+ this.debugLogStore,
173
253
  );
174
254
 
175
- const validator = createValidatorForBlockBuilding(
255
+ const validator = createTxValidatorForBlockBuilding(
176
256
  fork,
177
257
  this.contractDataSource,
178
258
  globalVariables,
@@ -197,6 +277,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
197
277
  private contractDataSource: ContractDataSource,
198
278
  private dateProvider: DateProvider,
199
279
  private telemetryClient: TelemetryClient = getTelemetryClient(),
280
+ private debugLogStore: DebugLogStore = new NullDebugLogStore(),
200
281
  ) {
201
282
  this.log = createLogger('checkpoint-builder');
202
283
  }
@@ -251,6 +332,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
251
332
  this.dateProvider,
252
333
  this.telemetryClient,
253
334
  bindings,
335
+ this.debugLogStore,
254
336
  );
255
337
  }
256
338
 
@@ -311,6 +393,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
311
393
  this.dateProvider,
312
394
  this.telemetryClient,
313
395
  bindings,
396
+ this.debugLogStore,
314
397
  );
315
398
  }
316
399
 
package/src/config.ts CHANGED
@@ -77,6 +77,26 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
77
77
  description: 'Agree to attest to equivocated checkpoint proposals (for testing purposes only)',
78
78
  ...booleanConfigHelper(false),
79
79
  },
80
+ validateMaxL2BlockGas: {
81
+ env: 'VALIDATOR_MAX_L2_BLOCK_GAS',
82
+ description: 'Maximum L2 block gas for validation. Proposals exceeding this limit are rejected.',
83
+ parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
84
+ },
85
+ validateMaxDABlockGas: {
86
+ env: 'VALIDATOR_MAX_DA_BLOCK_GAS',
87
+ description: 'Maximum DA block gas for validation. Proposals exceeding this limit are rejected.',
88
+ parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
89
+ },
90
+ validateMaxTxsPerBlock: {
91
+ env: 'VALIDATOR_MAX_TX_PER_BLOCK',
92
+ description: 'Maximum transactions per block for validation. Proposals exceeding this limit are rejected.',
93
+ parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
94
+ },
95
+ validateMaxTxsPerCheckpoint: {
96
+ env: 'VALIDATOR_MAX_TX_PER_CHECKPOINT',
97
+ description: 'Maximum transactions per checkpoint for validation. Proposals exceeding this limit are rejected.',
98
+ parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
99
+ },
80
100
  ...validatorHASignerConfigMappings,
81
101
  };
82
102
 
@@ -150,16 +150,10 @@ export class ValidationService {
150
150
  );
151
151
 
152
152
  // TODO(spy/ha): Use checkpointNumber instead of blockNumber once CheckpointHeader includes it.
153
- // Currently using lastBlock.blockNumber as a proxy for checkpoint identification in HA signing.
153
+ // CheckpointProposalCore doesn't have lastBlock info, so use 0 as a proxy.
154
154
  // blockNumber is NOT used for the primary key so it's safe to use here.
155
155
  // See CheckpointHeader TODO and SigningContext types documentation.
156
- let blockNumber: BlockNumber;
157
- try {
158
- blockNumber = proposal.blockNumber;
159
- } catch {
160
- // Checkpoint proposal may not have lastBlock, use 0 as fallback
161
- blockNumber = BlockNumber(0);
162
- }
156
+ const blockNumber = BlockNumber(0);
163
157
  const context: SigningContext = {
164
158
  slot: proposal.slotNumber,
165
159
  blockNumber,
@@ -183,7 +177,7 @@ export class ValidationService {
183
177
  } else {
184
178
  const error = result.reason;
185
179
  if (error instanceof DutyAlreadySignedError || error instanceof SlashingProtectionError) {
186
- this.log.info(
180
+ this.log.verbose(
187
181
  `Attestation for slot ${proposal.slotNumber} by ${attestors[i]} already signed by another High-Availability node`,
188
182
  );
189
183
  // Continue with remaining attestors
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.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
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';
@@ -240,7 +240,7 @@ export class HAKeyStore implements ExtendedValidatorKeyStore {
240
240
  }
241
241
 
242
242
  if (error instanceof SlashingProtectionError) {
243
- this.log.warn(`Duty already signed by another node with different payload`, {
243
+ this.log.info(`Duty already signed by another node with different payload`, {
244
244
  dutyType: context.dutyType,
245
245
  slot: context.slot,
246
246
  existingMessageHash: error.existingMessageHash,
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
@@ -24,6 +24,7 @@ import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol }
24
24
  import { OffenseType, WANT_TO_SLASH_EVENT, type Watcher, type WatcherEmitter } from '@aztec/slasher';
25
25
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
26
26
  import type { CommitteeAttestationsAndSigners, L2Block, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
27
+ import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
27
28
  import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
28
29
  import type {
29
30
  CreateCheckpointProposalLastBlockData,
@@ -89,6 +90,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
89
90
 
90
91
  private lastEpochForCommitteeUpdateLoop: EpochNumber | undefined;
91
92
  private epochCacheUpdateLoop: RunningPromise;
93
+ /** Tracks the last epoch in which each attester successfully submitted at least one attestation. */
94
+ private lastAttestedEpochByAttester: Map<string, EpochNumber> = new Map();
92
95
 
93
96
  private proposersOfInvalidBlocks: Set<string> = new Set();
94
97
 
@@ -160,6 +163,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
160
163
  this.log.trace(`No committee found for slot`);
161
164
  return;
162
165
  }
166
+ this.metrics.setCurrentEpoch(epoch);
163
167
  if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
164
168
  const me = this.getValidatorAddresses();
165
169
  const committeeSet = new Set(committee.map(v => v.toString()));
@@ -197,6 +201,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
197
201
  const metrics = new ValidatorMetrics(telemetry);
198
202
  const blockProposalValidator = new BlockProposalValidator(epochCache, {
199
203
  txsPermitted: !config.disableTransactions,
204
+ maxTxsPerBlock: config.validateMaxTxsPerBlock,
200
205
  });
201
206
  const blockProposalHandler = new BlockProposalHandler(
202
207
  checkpointsBuilder,
@@ -382,7 +387,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
382
387
 
383
388
  // Ignore proposals from ourselves (may happen in HA setups)
384
389
  if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
385
- this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
390
+ this.log.debug(`Ignoring block proposal from self for slot ${slotNumber}`, {
386
391
  proposer: proposer.toString(),
387
392
  slotNumber,
388
393
  });
@@ -418,9 +423,10 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
418
423
  );
419
424
 
420
425
  if (!validationResult.isValid) {
421
- this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
422
-
423
426
  const reason = validationResult.reason || 'unknown';
427
+
428
+ this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
429
+
424
430
  // Classify failure reason: bad proposal vs node issue
425
431
  const badProposalReasons: BlockProposalValidationFailureReason[] = [
426
432
  'invalid_proposal',
@@ -492,7 +498,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
492
498
 
493
499
  // Ignore proposals from ourselves (may happen in HA setups)
494
500
  if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
495
- this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
501
+ this.log.debug(`Ignoring block proposal from self for slot ${slotNumber}`, {
496
502
  proposer: proposer.toString(),
497
503
  slotNumber,
498
504
  });
@@ -515,11 +521,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
515
521
  slotNumber,
516
522
  archive: proposal.archive.toString(),
517
523
  proposer: proposer.toString(),
518
- txCount: proposal.txHashes.length,
519
524
  };
520
525
  this.log.info(`Received checkpoint proposal for slot ${slotNumber}`, {
521
526
  ...proposalInfo,
522
- txHashes: proposal.txHashes.map(t => t.toString()),
523
527
  fishermanMode: this.config.fishermanMode || false,
524
528
  });
525
529
 
@@ -555,6 +559,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
555
559
 
556
560
  this.metrics.incSuccessfulAttestations(inCommittee.length);
557
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
+
558
573
  // Determine which validators should attest
559
574
  let attestors: EthAddress[];
560
575
  if (partOfCommittee) {
@@ -751,6 +766,20 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
751
766
  return { isValid: false, reason: 'out_hash_mismatch' };
752
767
  }
753
768
 
769
+ // Final round of validations on the checkpoint, just in case.
770
+ try {
771
+ validateCheckpoint(computedCheckpoint, {
772
+ rollupManaLimit: this.checkpointsBuilder.getConfig().rollupManaLimit,
773
+ maxDABlockGas: this.config.validateMaxDABlockGas,
774
+ maxL2BlockGas: this.config.validateMaxL2BlockGas,
775
+ maxTxsPerBlock: this.config.validateMaxTxsPerBlock,
776
+ maxTxsPerCheckpoint: this.config.validateMaxTxsPerCheckpoint,
777
+ });
778
+ } catch (err) {
779
+ this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
780
+ return { isValid: false, reason: 'checkpoint_validation_failed' };
781
+ }
782
+
754
783
  this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
755
784
  return { isValid: true };
756
785
  } finally {
@@ -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';