@aztec/validator-client 0.0.1-commit.934299a21 → 0.0.1-commit.949a33fd8

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 (40) hide show
  1. package/README.md +41 -2
  2. package/dest/checkpoint_builder.d.ts +14 -4
  3. package/dest/checkpoint_builder.d.ts.map +1 -1
  4. package/dest/checkpoint_builder.js +101 -30
  5. package/dest/config.d.ts +1 -1
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +29 -7
  8. package/dest/duties/validation_service.d.ts +11 -12
  9. package/dest/duties/validation_service.d.ts.map +1 -1
  10. package/dest/duties/validation_service.js +27 -45
  11. package/dest/factory.d.ts +7 -4
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +10 -5
  14. package/dest/index.d.ts +2 -2
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +1 -1
  17. package/dest/key_store/ha_key_store.js +1 -1
  18. package/dest/metrics.d.ts +14 -2
  19. package/dest/metrics.d.ts.map +1 -1
  20. package/dest/metrics.js +24 -0
  21. package/dest/proposal_handler.d.ts +108 -0
  22. package/dest/proposal_handler.d.ts.map +1 -0
  23. package/dest/proposal_handler.js +974 -0
  24. package/dest/validator.d.ts +19 -21
  25. package/dest/validator.d.ts.map +1 -1
  26. package/dest/validator.js +99 -232
  27. package/package.json +19 -19
  28. package/src/checkpoint_builder.ts +124 -35
  29. package/src/config.ts +29 -6
  30. package/src/duties/validation_service.ts +46 -53
  31. package/src/factory.ts +14 -3
  32. package/src/index.ts +1 -1
  33. package/src/key_store/ha_key_store.ts +1 -1
  34. package/src/metrics.ts +37 -1
  35. package/src/proposal_handler.ts +1042 -0
  36. package/src/validator.ts +144 -264
  37. package/dest/block_proposal_handler.d.ts +0 -63
  38. package/dest/block_proposal_handler.d.ts.map +0 -1
  39. package/dest/block_proposal_handler.js +0 -532
  40. package/src/block_proposal_handler.ts +0 -535
@@ -1,5 +1,7 @@
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';
@@ -18,13 +20,14 @@ import type { ContractDataSource } from '@aztec/stdlib/contract';
18
20
  import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
19
21
  import { Gas } from '@aztec/stdlib/gas';
20
22
  import {
23
+ type BlockBuilderOptions,
21
24
  type BuildBlockInCheckpointResult,
22
25
  type FullNodeBlockBuilderConfig,
23
26
  FullNodeBlockBuilderConfigKeys,
24
27
  type ICheckpointBlockBuilder,
25
28
  type ICheckpointsBuilder,
29
+ InsufficientValidTxsError,
26
30
  type MerkleTreeWriteOperations,
27
- NoValidTxsError,
28
31
  type PublicProcessorLimits,
29
32
  type WorldStateSynchronizer,
30
33
  } from '@aztec/stdlib/interfaces/server';
@@ -32,6 +35,7 @@ import { type DebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
32
35
  import { MerkleTreeId } from '@aztec/stdlib/trees';
33
36
  import { type CheckpointGlobalVariables, GlobalVariables, StateReference, Tx } from '@aztec/stdlib/tx';
34
37
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
38
+ import { ForkCheckpoint } from '@aztec/world-state';
35
39
 
36
40
  // Re-export for backward compatibility
37
41
  export type { BuildBlockInCheckpointResult } from '@aztec/stdlib/interfaces/server';
@@ -43,6 +47,9 @@ export type { BuildBlockInCheckpointResult } from '@aztec/stdlib/interfaces/serv
43
47
  export class CheckpointBuilder implements ICheckpointBlockBuilder {
44
48
  private log: Logger;
45
49
 
50
+ /** Persistent contracts DB shared across all blocks in this checkpoint. */
51
+ protected contractsDB: PublicContractsDB;
52
+
46
53
  constructor(
47
54
  private checkpointBuilder: LightweightCheckpointBuilder,
48
55
  private fork: MerkleTreeWriteOperations,
@@ -57,6 +64,7 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
57
64
  ...bindings,
58
65
  instanceId: `checkpoint-${checkpointBuilder.checkpointNumber}`,
59
66
  });
67
+ this.contractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings());
60
68
  }
61
69
 
62
70
  getConstantData(): CheckpointGlobalVariables {
@@ -65,12 +73,13 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
65
73
 
66
74
  /**
67
75
  * Builds a single block within this checkpoint.
76
+ * Automatically caps gas and blob field limits based on checkpoint-level budgets and prior blocks.
68
77
  */
69
78
  async buildBlock(
70
79
  pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
71
80
  blockNumber: BlockNumber,
72
81
  timestamp: bigint,
73
- opts: PublicProcessorLimits & { expectedEndState?: StateReference } = {},
82
+ opts: BlockBuilderOptions & { expectedEndState?: StateReference },
74
83
  ): Promise<BuildBlockInCheckpointResult> {
75
84
  const slot = this.checkpointBuilder.constants.slotNumber;
76
85
 
@@ -94,39 +103,60 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
94
103
  });
95
104
  const { processor, validator } = await this.makeBlockBuilderDeps(globalVariables, this.fork);
96
105
 
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
- });
106
+ // Cap gas limits amd available blob fields by remaining checkpoint-level budgets
107
+ const cappedOpts: PublicProcessorLimits & { expectedEndState?: StateReference } = {
108
+ ...opts,
109
+ ...this.capLimitsByCheckpointBudgets(opts),
110
+ };
111
111
 
112
- // How much public gas was processed
113
- const publicGas = processedTxs.reduce((acc, tx) => acc.add(tx.gasUsed.publicGas), Gas.empty());
112
+ // Create a block-level checkpoint on the contracts DB so we can roll back on failure
113
+ this.contractsDB.createCheckpoint();
114
+ // We execute all merkle tree operations on a world state fork checkpoint
115
+ // This enables us to discard all modifications in the event that we fail to successfully process sufficient transactions
116
+ const forkCheckpoint = await ForkCheckpoint.new(this.fork);
114
117
 
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
- });
118
+ try {
119
+ const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(() =>
120
+ processor.process(pendingTxs, cappedOpts, validator),
121
+ );
120
122
 
121
- return {
122
- block,
123
- publicGas,
124
- publicProcessorDuration,
125
- numTxs: processedTxs.length,
126
- failedTxs,
127
- usedTxs,
128
- usedTxBlobFields,
129
- };
123
+ // Throw before updating state if we don't have enough valid txs
124
+ const minValidTxs = opts.minValidTxs ?? 0;
125
+ if (processedTxs.length < minValidTxs) {
126
+ throw new InsufficientValidTxsError(processedTxs.length, minValidTxs, failedTxs);
127
+ }
128
+
129
+ // Commit the fork checkpoint
130
+ await forkCheckpoint.commit();
131
+
132
+ // Add block to checkpoint
133
+ const { block } = await this.checkpointBuilder.addBlock(globalVariables, processedTxs, {
134
+ expectedEndState: opts.expectedEndState,
135
+ });
136
+
137
+ this.contractsDB.commitCheckpoint();
138
+
139
+ this.log.debug('Built block within checkpoint', {
140
+ header: block.header.toInspect(),
141
+ processedTxs: processedTxs.map(tx => tx.hash.toString()),
142
+ failedTxs: failedTxs.map(tx => tx.tx.txHash.toString()),
143
+ });
144
+
145
+ return {
146
+ block,
147
+ publicProcessorDuration,
148
+ numTxs: processedTxs.length,
149
+ failedTxs,
150
+ usedTxs,
151
+ };
152
+ } catch (err) {
153
+ // Revert all changes to contracts db
154
+ this.contractsDB.revertCheckpoint();
155
+ // If we reached the point of committing the checkpoint, this does nothing
156
+ // Otherwise it reverts any changes made to the fork for this failed block
157
+ await forkCheckpoint.revert();
158
+ throw err;
159
+ }
130
160
  }
131
161
 
132
162
  /** Completes the checkpoint and returns it. */
@@ -147,9 +177,68 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
147
177
  return this.checkpointBuilder.clone().completeCheckpoint();
148
178
  }
149
179
 
180
+ /**
181
+ * Caps per-block gas and blob field limits by remaining checkpoint-level budgets.
182
+ * When building a proposal (isBuildingProposal=true), computes a fair share of remaining budget
183
+ * across remaining blocks scaled by the multiplier. When validating, only caps by per-block limit
184
+ * and remaining checkpoint budget (no redistribution or multiplier).
185
+ */
186
+ protected capLimitsByCheckpointBudgets(
187
+ opts: BlockBuilderOptions,
188
+ ): Pick<PublicProcessorLimits, 'maxBlockGas' | 'maxBlobFields' | 'maxTransactions'> {
189
+ const existingBlocks = this.checkpointBuilder.getBlocks();
190
+
191
+ // Remaining L2 gas (mana)
192
+ // IMPORTANT: This assumes mana is computed solely based on L2 gas used in transactions.
193
+ // This may change in the future.
194
+ const usedMana = sum(existingBlocks.map(b => b.header.totalManaUsed.toNumber()));
195
+ const remainingMana = this.config.rollupManaLimit - usedMana;
196
+
197
+ // Remaining DA gas
198
+ const usedDAGas = sum(existingBlocks.map(b => b.computeDAGasUsed())) ?? 0;
199
+ const remainingDAGas = MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT - usedDAGas;
200
+
201
+ // Remaining blob fields (block blob fields include both tx data and block-end overhead)
202
+ const usedBlobFields = sum(existingBlocks.map(b => b.toBlobFields().length));
203
+ const totalBlobCapacity = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
204
+ const isFirstBlock = existingBlocks.length === 0;
205
+ const blockEndOverhead = getNumBlockEndBlobFields(isFirstBlock);
206
+ const maxBlobFieldsForTxs = totalBlobCapacity - usedBlobFields - blockEndOverhead;
207
+
208
+ // Remaining txs
209
+ const usedTxs = sum(existingBlocks.map(b => b.body.txEffects.length));
210
+ const remainingTxs = Math.max(0, (this.config.maxTxsPerCheckpoint ?? Infinity) - usedTxs);
211
+
212
+ // Cap by per-block limit + remaining checkpoint budget
213
+ let cappedL2Gas = Math.min(opts.maxBlockGas?.l2Gas ?? Infinity, remainingMana);
214
+ let cappedDAGas = Math.min(opts.maxBlockGas?.daGas ?? Infinity, remainingDAGas);
215
+ let cappedBlobFields = Math.min(opts.maxBlobFields ?? Infinity, maxBlobFieldsForTxs);
216
+ let cappedMaxTransactions = Math.min(opts.maxTransactions ?? Infinity, remainingTxs);
217
+
218
+ // Proposer mode: further cap by fair share of remaining budget across remaining blocks
219
+ if (opts.isBuildingProposal) {
220
+ const remainingBlocks = Math.max(1, opts.maxBlocksPerCheckpoint - existingBlocks.length);
221
+ const multiplier = opts.perBlockAllocationMultiplier;
222
+
223
+ cappedL2Gas = Math.min(cappedL2Gas, Math.ceil((remainingMana / remainingBlocks) * multiplier));
224
+ cappedDAGas = Math.min(cappedDAGas, Math.ceil((remainingDAGas / remainingBlocks) * multiplier));
225
+ cappedBlobFields = Math.min(cappedBlobFields, Math.ceil((maxBlobFieldsForTxs / remainingBlocks) * multiplier));
226
+ cappedMaxTransactions = Math.min(cappedMaxTransactions, Math.ceil((remainingTxs / remainingBlocks) * multiplier));
227
+ }
228
+
229
+ return {
230
+ maxBlockGas: new Gas(cappedDAGas, cappedL2Gas),
231
+ maxBlobFields: cappedBlobFields,
232
+ maxTransactions: Number.isFinite(cappedMaxTransactions) ? cappedMaxTransactions : undefined,
233
+ };
234
+ }
235
+
150
236
  protected async makeBlockBuilderDeps(globalVariables: GlobalVariables, fork: MerkleTreeWriteOperations) {
151
- const txPublicSetupAllowList = this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
152
- const contractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings());
237
+ const txPublicSetupAllowList = [
238
+ ...(await getDefaultAllowedSetupFunctions()),
239
+ ...(this.config.txPublicSetupAllowListExtend ?? []),
240
+ ];
241
+ const contractsDB = this.contractsDB;
153
242
  const guardedFork = new GuardedMerkleTreeOperations(fork);
154
243
 
155
244
  const collectDebugLogs = this.debugLogStore.isEnabled;
package/src/config.ts CHANGED
@@ -3,10 +3,11 @@ import {
3
3
  booleanConfigHelper,
4
4
  getConfigFromMappings,
5
5
  numberConfigHelper,
6
+ optionalNumberConfigHelper,
6
7
  secretValueConfigHelper,
7
8
  } from '@aztec/foundation/config';
8
9
  import { EthAddress } from '@aztec/foundation/eth-address';
9
- import { validatorHASignerConfigMappings } from '@aztec/stdlib/ha-signing';
10
+ import { localSignerConfigMappings, validatorHASignerConfigMappings } from '@aztec/stdlib/ha-signing';
10
11
  import type { ValidatorClientConfig } from '@aztec/stdlib/interfaces/server';
11
12
 
12
13
  export type { ValidatorClientConfig };
@@ -30,6 +31,12 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
30
31
  .map(address => EthAddress.fromString(address.trim())),
31
32
  defaultValue: [],
32
33
  },
34
+ l1ChainId: {
35
+ env: 'L1_CHAIN_ID',
36
+ description: 'The chain ID of the ethereum host.',
37
+ parseEnv: (val: string) => +val,
38
+ defaultValue: 31337,
39
+ },
33
40
  disableValidator: {
34
41
  env: 'VALIDATOR_DISABLED',
35
42
  description: 'Do not run the validator',
@@ -49,11 +56,6 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
49
56
  description: 'Interval between polling for new attestations',
50
57
  ...numberConfigHelper(200),
51
58
  },
52
- validatorReexecute: {
53
- env: 'VALIDATOR_REEXECUTE',
54
- description: 'Re-execute transactions before attesting',
55
- ...booleanConfigHelper(true),
56
- },
57
59
  alwaysReexecuteBlockProposals: {
58
60
  description:
59
61
  'Whether to always reexecute block proposals, even for non-validator nodes (useful for monitoring network status).',
@@ -77,6 +79,27 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
77
79
  description: 'Agree to attest to equivocated checkpoint proposals (for testing purposes only)',
78
80
  ...booleanConfigHelper(false),
79
81
  },
82
+ validateMaxL2BlockGas: {
83
+ env: 'VALIDATOR_MAX_L2_BLOCK_GAS',
84
+ description: 'Maximum L2 block gas for validation. Proposals exceeding this limit are rejected.',
85
+ ...optionalNumberConfigHelper(),
86
+ },
87
+ validateMaxDABlockGas: {
88
+ env: 'VALIDATOR_MAX_DA_BLOCK_GAS',
89
+ description: 'Maximum DA block gas for validation. Proposals exceeding this limit are rejected.',
90
+ ...optionalNumberConfigHelper(),
91
+ },
92
+ validateMaxTxsPerBlock: {
93
+ env: 'VALIDATOR_MAX_TX_PER_BLOCK',
94
+ description: 'Maximum transactions per block for validation. Proposals exceeding this limit are rejected.',
95
+ ...optionalNumberConfigHelper(),
96
+ },
97
+ validateMaxTxsPerCheckpoint: {
98
+ env: 'VALIDATOR_MAX_TX_PER_CHECKPOINT',
99
+ description: 'Maximum transactions per checkpoint for validation. Proposals exceeding this limit are rejected.',
100
+ ...optionalNumberConfigHelper(),
101
+ },
102
+ ...localSignerConfigMappings,
80
103
  ...validatorHASignerConfigMappings,
81
104
  };
82
105
 
@@ -1,17 +1,9 @@
1
- import {
2
- BlockNumber,
3
- type CheckpointNumber,
4
- IndexWithinCheckpoint,
5
- type SlotNumber,
6
- } from '@aztec/foundation/branded-types';
7
- import { Buffer32 } from '@aztec/foundation/buffer';
8
- import { keccak256 } from '@aztec/foundation/crypto/keccak';
1
+ import { type CheckpointNumber, IndexWithinCheckpoint, type SlotNumber } from '@aztec/foundation/branded-types';
9
2
  import { Fr } from '@aztec/foundation/curves/bn254';
10
3
  import type { EthAddress } from '@aztec/foundation/eth-address';
11
4
  import type { Signature } from '@aztec/foundation/eth-signature';
12
5
  import { createLogger } from '@aztec/foundation/log';
13
- import type { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
14
- import type { CreateCheckpointProposalLastBlockData } from '@aztec/stdlib/interfaces/server';
6
+ import { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
15
7
  import {
16
8
  BlockProposal,
17
9
  type BlockProposalOptions,
@@ -20,7 +12,8 @@ import {
20
12
  type CheckpointProposalCore,
21
13
  type CheckpointProposalOptions,
22
14
  ConsensusPayload,
23
- SignatureDomainSeparator,
15
+ type CoordinationSignatureContext,
16
+ getCoordinationSignatureTypedData,
24
17
  } from '@aztec/stdlib/p2p';
25
18
  import type { CheckpointHeader } from '@aztec/stdlib/rollup';
26
19
  import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
@@ -32,6 +25,7 @@ import type { ValidatorKeyStore } from '../key_store/interface.js';
32
25
  export class ValidationService {
33
26
  constructor(
34
27
  private keyStore: ValidatorKeyStore,
28
+ private signatureContext: CoordinationSignatureContext,
35
29
  private log = createLogger('validator:validation-service'),
36
30
  ) {}
37
31
 
@@ -52,6 +46,7 @@ export class ValidationService {
52
46
  */
53
47
  public createBlockProposal(
54
48
  blockHeader: BlockHeader,
49
+ checkpointNumber: CheckpointNumber,
55
50
  blockIndexWithinCheckpoint: IndexWithinCheckpoint,
56
51
  inHash: Fr,
57
52
  archive: Fr,
@@ -67,17 +62,26 @@ export class ValidationService {
67
62
 
68
63
  // Create a signer that uses the appropriate address
69
64
  const address = proposerAttesterAddress ?? this.keyStore.getAddress(0);
70
- const payloadSigner = (payload: Buffer32, context: SigningContext) =>
71
- this.keyStore.signMessageWithAddress(address, payload, context);
65
+ const payloadSigner = (
66
+ typedData: Parameters<ValidatorKeyStore['signTypedDataWithAddress']>[1],
67
+ context: SigningContext,
68
+ ) => this.keyStore.signTypedDataWithAddress(address, typedData, context);
69
+ const txsSigner = (
70
+ typedData: Parameters<ValidatorKeyStore['signTypedDataWithAddress']>[1],
71
+ context: SigningContext,
72
+ ) => this.keyStore.signTypedDataWithAddress(address, typedData, context);
72
73
 
73
74
  return BlockProposal.createProposalFromSigner(
74
75
  blockHeader,
76
+ checkpointNumber,
75
77
  blockIndexWithinCheckpoint,
76
78
  inHash,
77
79
  archive,
78
80
  txs.map(tx => tx.getTxHash()),
79
81
  options.publishFullTxs ? txs : undefined,
82
+ this.signatureContext,
80
83
  payloadSigner,
84
+ txsSigner,
81
85
  );
82
86
  }
83
87
 
@@ -86,7 +90,7 @@ export class ValidationService {
86
90
  *
87
91
  * @param checkpointHeader - The checkpoint header containing aggregated data
88
92
  * @param archive - The archive of the checkpoint
89
- * @param lastBlockInfo - Info about the last block (header, index, txs) or undefined
93
+ * @param lastBlockProposal - Signed block proposal for the last block in the checkpoint, or undefined
90
94
  * @param proposerAttesterAddress - The address of the proposer
91
95
  * @param options - Checkpoint proposal options
92
96
  *
@@ -95,36 +99,36 @@ export class ValidationService {
95
99
  public createCheckpointProposal(
96
100
  checkpointHeader: CheckpointHeader,
97
101
  archive: Fr,
102
+ checkpointNumber: CheckpointNumber,
98
103
  feeAssetPriceModifier: bigint,
99
- lastBlockInfo: CreateCheckpointProposalLastBlockData | undefined,
104
+ lastBlockProposal: BlockProposal | undefined,
100
105
  proposerAttesterAddress: EthAddress | undefined,
101
106
  options: CheckpointProposalOptions,
102
107
  ): Promise<CheckpointProposal> {
103
- // For testing: change the archive to trigger state_mismatch validation failure
108
+ // For testing: change the archive to trigger state_mismatch validation failure.
109
+ // If there's a last block proposal, use its (already invalid) archive to keep signatures consistent
110
+ // so P2P validation passes and the slasher can detect the offense.
104
111
  if (options.broadcastInvalidCheckpointProposal) {
105
- archive = Fr.random();
112
+ archive = lastBlockProposal?.archiveRoot ?? Fr.random();
106
113
  this.log.warn(`Creating INVALID checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
107
114
  }
108
115
 
109
116
  // Create a signer that takes payload and context, and uses the appropriate address
110
- const payloadSigner = (payload: Buffer32, context: SigningContext) => {
117
+ const payloadSigner = (
118
+ typedData: Parameters<ValidatorKeyStore['signTypedDataWithAddress']>[1],
119
+ context: SigningContext,
120
+ ) => {
111
121
  const address = proposerAttesterAddress ?? this.keyStore.getAddress(0);
112
- return this.keyStore.signMessageWithAddress(address, payload, context);
113
- };
114
-
115
- // Last block to include in the proposal
116
- const lastBlock = lastBlockInfo && {
117
- blockHeader: lastBlockInfo.blockHeader,
118
- indexWithinCheckpoint: lastBlockInfo.indexWithinCheckpoint,
119
- txHashes: lastBlockInfo.txs.map(tx => tx.getTxHash()),
120
- txs: options.publishFullTxs ? lastBlockInfo.txs : undefined,
122
+ return this.keyStore.signTypedDataWithAddress(address, typedData, context);
121
123
  };
122
124
 
123
125
  return CheckpointProposal.createProposalFromSigner(
124
126
  checkpointHeader,
125
127
  archive,
128
+ checkpointNumber,
126
129
  feeAssetPriceModifier,
127
- lastBlock,
130
+ lastBlockProposal,
131
+ this.signatureContext,
128
132
  payloadSigner,
129
133
  );
130
134
  }
@@ -142,35 +146,27 @@ export class ValidationService {
142
146
  async attestToCheckpointProposal(
143
147
  proposal: CheckpointProposalCore,
144
148
  attestors: EthAddress[],
149
+ checkpointNumber: CheckpointNumber,
145
150
  ): Promise<CheckpointAttestation[]> {
146
151
  // Create the attestation payload from the checkpoint proposal
147
- const payload = new ConsensusPayload(proposal.checkpointHeader, proposal.archive, proposal.feeAssetPriceModifier);
148
- const buf = Buffer32.fromBuffer(
149
- keccak256(payload.getPayloadToSign(SignatureDomainSeparator.checkpointAttestation)),
152
+ const payload = new ConsensusPayload(
153
+ proposal.checkpointHeader,
154
+ proposal.archive,
155
+ proposal.feeAssetPriceModifier,
156
+ this.signatureContext,
150
157
  );
158
+ const typedData = getCoordinationSignatureTypedData(payload);
151
159
 
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.
154
- // blockNumber is NOT used for the primary key so it's safe to use here.
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
- }
163
160
  const context: SigningContext = {
164
161
  slot: proposal.slotNumber,
165
- blockNumber,
162
+ checkpointNumber,
166
163
  dutyType: DutyType.ATTESTATION,
167
164
  };
168
165
 
169
166
  // Sign each attestor in parallel, catching HA errors per-attestor
170
167
  const results = await Promise.allSettled(
171
168
  attestors.map(async attestor => {
172
- const sig = await this.keyStore.signMessageWithAddress(attestor, buf, context);
173
- // return new BlockAttestation(proposal.payload, sig, proposal.signature);
169
+ const sig = await this.keyStore.signTypedDataWithAddress(attestor, typedData, context);
174
170
  return new CheckpointAttestation(payload, sig, proposal.signature);
175
171
  }),
176
172
  );
@@ -183,7 +179,7 @@ export class ValidationService {
183
179
  } else {
184
180
  const error = result.reason;
185
181
  if (error instanceof DutyAlreadySignedError || error instanceof SlashingProtectionError) {
186
- this.log.info(
182
+ this.log.verbose(
187
183
  `Attestation for slot ${proposal.slotNumber} by ${attestors[i]} already signed by another High-Availability node`,
188
184
  );
189
185
  // Continue with remaining attestors
@@ -201,7 +197,6 @@ export class ValidationService {
201
197
  * @param attestationsAndSigners - The attestations and signers to sign
202
198
  * @param proposer - The proposer address to sign with
203
199
  * @param slot - The slot number for HA signing context
204
- * @param blockNumber - The block or checkpoint number for HA signing context
205
200
  * @returns signature
206
201
  * @throws DutyAlreadySignedError if already signed by another HA node
207
202
  * @throws SlashingProtectionError if attempting to sign different data for same slot
@@ -210,17 +205,15 @@ export class ValidationService {
210
205
  attestationsAndSigners: CommitteeAttestationsAndSigners,
211
206
  proposer: EthAddress,
212
207
  slot: SlotNumber,
213
- blockNumber: BlockNumber | CheckpointNumber,
208
+ checkpointNumber: CheckpointNumber,
214
209
  ): Promise<Signature> {
215
210
  const context: SigningContext = {
216
211
  slot,
217
- blockNumber,
212
+ checkpointNumber,
218
213
  dutyType: DutyType.ATTESTATIONS_AND_SIGNERS,
219
214
  };
220
215
 
221
- const buf = Buffer32.fromBuffer(
222
- keccak256(attestationsAndSigners.getPayloadToSign(SignatureDomainSeparator.attestationsAndSigners)),
223
- );
224
- return this.keyStore.signMessageWithAddress(proposer, buf, context);
216
+ const typedData = getCoordinationSignatureTypedData(attestationsAndSigners);
217
+ return this.keyStore.signTypedDataWithAddress(proposer, typedData, context);
225
218
  }
226
219
  }
package/src/factory.ts CHANGED
@@ -7,13 +7,14 @@ import type { L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
7
7
  import type { ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
8
8
  import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
9
9
  import type { TelemetryClient } from '@aztec/telemetry-client';
10
+ import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
10
11
 
11
- import { BlockProposalHandler } from './block_proposal_handler.js';
12
12
  import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
13
13
  import { ValidatorMetrics } from './metrics.js';
14
+ import { ProposalHandler } from './proposal_handler.js';
14
15
  import { ValidatorClient } from './validator.js';
15
16
 
16
- export function createBlockProposalHandler(
17
+ export function createProposalHandler(
17
18
  config: ValidatorClientFullConfig,
18
19
  deps: {
19
20
  checkpointsBuilder: FullNodeCheckpointsBuilder;
@@ -22,6 +23,7 @@ export function createBlockProposalHandler(
22
23
  l1ToL2MessageSource: L1ToL2MessageSource;
23
24
  p2pClient: P2PClient;
24
25
  epochCache: EpochCache;
26
+ blobClient: BlobClientInterface;
25
27
  dateProvider: DateProvider;
26
28
  telemetry: TelemetryClient;
27
29
  },
@@ -29,8 +31,13 @@ export function createBlockProposalHandler(
29
31
  const metrics = new ValidatorMetrics(deps.telemetry);
30
32
  const blockProposalValidator = new BlockProposalValidator(deps.epochCache, {
31
33
  txsPermitted: !config.disableTransactions,
34
+ maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
35
+ signatureContext: {
36
+ chainId: config.l1ChainId,
37
+ rollupAddress: config.l1Contracts.rollupAddress,
38
+ },
32
39
  });
33
- return new BlockProposalHandler(
40
+ return new ProposalHandler(
34
41
  deps.checkpointsBuilder,
35
42
  deps.worldState,
36
43
  deps.blockSource,
@@ -39,9 +46,11 @@ export function createBlockProposalHandler(
39
46
  blockProposalValidator,
40
47
  deps.epochCache,
41
48
  config,
49
+ deps.blobClient,
42
50
  metrics,
43
51
  deps.dateProvider,
44
52
  deps.telemetry,
53
+ undefined,
45
54
  );
46
55
  }
47
56
 
@@ -58,6 +67,7 @@ export function createValidatorClient(
58
67
  epochCache: EpochCache;
59
68
  keyStoreManager: KeystoreManager | undefined;
60
69
  blobClient: BlobClientInterface;
70
+ slashingProtectionDb?: SlashingProtectionDatabase;
61
71
  },
62
72
  ) {
63
73
  if (config.disableValidator || !deps.keyStoreManager) {
@@ -78,5 +88,6 @@ export function createValidatorClient(
78
88
  deps.blobClient,
79
89
  deps.dateProvider,
80
90
  deps.telemetry,
91
+ deps.slashingProtectionDb,
81
92
  );
82
93
  }
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './block_proposal_handler.js';
1
+ export * from './proposal_handler.js';
2
2
  export * from './checkpoint_builder.js';
3
3
  export * from './config.js';
4
4
  export * from './factory.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,
@@ -9,17 +11,21 @@ import {
9
11
  createUpDownCounterWithDefault,
10
12
  } from '@aztec/telemetry-client';
11
13
 
12
- import type { BlockProposalValidationFailureReason } from './block_proposal_handler.js';
14
+ import type { BlockProposalValidationFailureReason } from './proposal_handler.js';
13
15
 
14
16
  export class ValidatorMetrics {
15
17
  private failedReexecutionCounter: UpDownCounter;
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;
22
26
  private reexDuration: Gauge;
27
+ private checkpointProposalToPipelinedStateDuration: Histogram;
28
+ private checkpointProposalReceiveOffsetFromNextSlotBoundary: Histogram;
23
29
 
24
30
  constructor(telemetryClient: TelemetryClient) {
25
31
  const meter = telemetryClient.getMeter('Validator');
@@ -64,11 +70,21 @@ export class ValidatorMetrics {
64
70
  },
65
71
  );
66
72
 
73
+ this.currentEpoch = meter.createGauge(Metrics.VALIDATOR_CURRENT_EPOCH);
74
+
75
+ this.attestedEpochCount = createUpDownCounterWithDefault(meter, Metrics.VALIDATOR_ATTESTED_EPOCH_COUNT);
76
+
67
77
  this.reexMana = meter.createHistogram(Metrics.VALIDATOR_RE_EXECUTION_MANA);
68
78
 
69
79
  this.reexTx = meter.createHistogram(Metrics.VALIDATOR_RE_EXECUTION_TX_COUNT);
70
80
 
71
81
  this.reexDuration = meter.createGauge(Metrics.VALIDATOR_RE_EXECUTION_TIME);
82
+ this.checkpointProposalToPipelinedStateDuration = meter.createHistogram(
83
+ Metrics.VALIDATOR_CHECKPOINT_PROPOSAL_TO_PIPELINED_STATE_DURATION,
84
+ );
85
+ this.checkpointProposalReceiveOffsetFromNextSlotBoundary = meter.createHistogram(
86
+ Metrics.VALIDATOR_CHECKPOINT_PROPOSAL_RECEIVE_OFFSET_FROM_NEXT_SLOT_BOUNDARY,
87
+ );
72
88
  }
73
89
 
74
90
  public recordReex(time: number, txs: number, mManaTotal: number) {
@@ -77,6 +93,16 @@ export class ValidatorMetrics {
77
93
  this.reexMana.record(mManaTotal);
78
94
  }
79
95
 
96
+ public recordCheckpointProposalToPipelinedStateDuration(durationMs: number) {
97
+ this.checkpointProposalToPipelinedStateDuration.record(Math.ceil(durationMs));
98
+ }
99
+
100
+ public recordCheckpointProposalReceiveOffsetFromNextSlotBoundary(offsetMs: number) {
101
+ this.checkpointProposalReceiveOffsetFromNextSlotBoundary.record(Math.ceil(Math.abs(offsetMs)), {
102
+ [Attributes.SLOT_BOUNDARY_SIDE]: offsetMs < 0 ? 'before' : 'after',
103
+ });
104
+ }
105
+
80
106
  public recordFailedReexecution(proposal: BlockProposal) {
81
107
  const proposer = proposal.getSender();
82
108
  this.failedReexecutionCounter.add(1, {
@@ -110,4 +136,14 @@ export class ValidatorMetrics {
110
136
  [Attributes.IS_COMMITTEE_MEMBER]: inCommittee,
111
137
  });
112
138
  }
139
+
140
+ /** Update the gauge tracking the current epoch number (proxy for total epochs elapsed). */
141
+ public setCurrentEpoch(epoch: EpochNumber) {
142
+ this.currentEpoch.record(Number(epoch));
143
+ }
144
+
145
+ /** Increment the count of epochs in which the given attester submitted at least one attestation. */
146
+ public incAttestedEpochCount(attester: EthAddress) {
147
+ this.attestedEpochCount.add(1, { [Attributes.ATTESTER_ADDRESS]: attester.toString() });
148
+ }
113
149
  }