@aztec/validator-client 0.0.1-commit.b33fc05d0 → 0.0.1-commit.b3d3157a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/validator-client",
3
- "version": "0.0.1-commit.b33fc05d0",
3
+ "version": "0.0.1-commit.b3d3157a",
4
4
  "main": "dest/index.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -64,30 +64,30 @@
64
64
  ]
65
65
  },
66
66
  "dependencies": {
67
- "@aztec/blob-client": "0.0.1-commit.b33fc05d0",
68
- "@aztec/blob-lib": "0.0.1-commit.b33fc05d0",
69
- "@aztec/constants": "0.0.1-commit.b33fc05d0",
70
- "@aztec/epoch-cache": "0.0.1-commit.b33fc05d0",
71
- "@aztec/ethereum": "0.0.1-commit.b33fc05d0",
72
- "@aztec/foundation": "0.0.1-commit.b33fc05d0",
73
- "@aztec/node-keystore": "0.0.1-commit.b33fc05d0",
74
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.b33fc05d0",
75
- "@aztec/p2p": "0.0.1-commit.b33fc05d0",
76
- "@aztec/protocol-contracts": "0.0.1-commit.b33fc05d0",
77
- "@aztec/prover-client": "0.0.1-commit.b33fc05d0",
78
- "@aztec/simulator": "0.0.1-commit.b33fc05d0",
79
- "@aztec/slasher": "0.0.1-commit.b33fc05d0",
80
- "@aztec/stdlib": "0.0.1-commit.b33fc05d0",
81
- "@aztec/telemetry-client": "0.0.1-commit.b33fc05d0",
82
- "@aztec/validator-ha-signer": "0.0.1-commit.b33fc05d0",
67
+ "@aztec/blob-client": "0.0.1-commit.b3d3157a",
68
+ "@aztec/blob-lib": "0.0.1-commit.b3d3157a",
69
+ "@aztec/constants": "0.0.1-commit.b3d3157a",
70
+ "@aztec/epoch-cache": "0.0.1-commit.b3d3157a",
71
+ "@aztec/ethereum": "0.0.1-commit.b3d3157a",
72
+ "@aztec/foundation": "0.0.1-commit.b3d3157a",
73
+ "@aztec/node-keystore": "0.0.1-commit.b3d3157a",
74
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.b3d3157a",
75
+ "@aztec/p2p": "0.0.1-commit.b3d3157a",
76
+ "@aztec/protocol-contracts": "0.0.1-commit.b3d3157a",
77
+ "@aztec/prover-client": "0.0.1-commit.b3d3157a",
78
+ "@aztec/simulator": "0.0.1-commit.b3d3157a",
79
+ "@aztec/slasher": "0.0.1-commit.b3d3157a",
80
+ "@aztec/stdlib": "0.0.1-commit.b3d3157a",
81
+ "@aztec/telemetry-client": "0.0.1-commit.b3d3157a",
82
+ "@aztec/validator-ha-signer": "0.0.1-commit.b3d3157a",
83
83
  "koa": "^2.16.1",
84
84
  "koa-router": "^13.1.1",
85
85
  "tslib": "^2.4.0",
86
86
  "viem": "npm:@aztec/viem@2.38.2"
87
87
  },
88
88
  "devDependencies": {
89
- "@aztec/archiver": "0.0.1-commit.b33fc05d0",
90
- "@aztec/world-state": "0.0.1-commit.b33fc05d0",
89
+ "@aztec/archiver": "0.0.1-commit.b3d3157a",
90
+ "@aztec/world-state": "0.0.1-commit.b3d3157a",
91
91
  "@electric-sql/pglite": "^0.3.14",
92
92
  "@jest/globals": "^30.0.0",
93
93
  "@types/jest": "^30.0.0",
@@ -20,13 +20,14 @@ import type { ContractDataSource } from '@aztec/stdlib/contract';
20
20
  import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
21
21
  import { Gas } from '@aztec/stdlib/gas';
22
22
  import {
23
+ type BlockBuilderOptions,
23
24
  type BuildBlockInCheckpointResult,
24
25
  type FullNodeBlockBuilderConfig,
25
26
  FullNodeBlockBuilderConfigKeys,
26
27
  type ICheckpointBlockBuilder,
27
28
  type ICheckpointsBuilder,
29
+ InsufficientValidTxsError,
28
30
  type MerkleTreeWriteOperations,
29
- NoValidTxsError,
30
31
  type PublicProcessorLimits,
31
32
  type WorldStateSynchronizer,
32
33
  } from '@aztec/stdlib/interfaces/server';
@@ -34,6 +35,7 @@ import { type DebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
34
35
  import { MerkleTreeId } from '@aztec/stdlib/trees';
35
36
  import { type CheckpointGlobalVariables, GlobalVariables, StateReference, Tx } from '@aztec/stdlib/tx';
36
37
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
38
+ import { ForkCheckpoint } from '@aztec/world-state';
37
39
 
38
40
  // Re-export for backward compatibility
39
41
  export type { BuildBlockInCheckpointResult } from '@aztec/stdlib/interfaces/server';
@@ -45,6 +47,9 @@ export type { BuildBlockInCheckpointResult } from '@aztec/stdlib/interfaces/serv
45
47
  export class CheckpointBuilder implements ICheckpointBlockBuilder {
46
48
  private log: Logger;
47
49
 
50
+ /** Persistent contracts DB shared across all blocks in this checkpoint. */
51
+ protected contractsDB: PublicContractsDB;
52
+
48
53
  constructor(
49
54
  private checkpointBuilder: LightweightCheckpointBuilder,
50
55
  private fork: MerkleTreeWriteOperations,
@@ -59,6 +64,7 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
59
64
  ...bindings,
60
65
  instanceId: `checkpoint-${checkpointBuilder.checkpointNumber}`,
61
66
  });
67
+ this.contractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings());
62
68
  }
63
69
 
64
70
  getConstantData(): CheckpointGlobalVariables {
@@ -73,7 +79,7 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
73
79
  pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
74
80
  blockNumber: BlockNumber,
75
81
  timestamp: bigint,
76
- opts: PublicProcessorLimits & { expectedEndState?: StateReference } = {},
82
+ opts: BlockBuilderOptions & { expectedEndState?: StateReference },
77
83
  ): Promise<BuildBlockInCheckpointResult> {
78
84
  const slot = this.checkpointBuilder.constants.slotNumber;
79
85
 
@@ -103,34 +109,54 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
103
109
  ...this.capLimitsByCheckpointBudgets(opts),
104
110
  };
105
111
 
106
- const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(() =>
107
- processor.process(pendingTxs, cappedOpts, validator),
108
- );
109
-
110
- // Throw if we didn't collect a single valid tx and we're not allowed to build empty blocks
111
- // (only the first block in a checkpoint can be empty)
112
- if (processedTxs.length === 0 && this.checkpointBuilder.getBlockCount() > 0) {
113
- throw new NoValidTxsError(failedTxs);
114
- }
115
-
116
- // Add block to checkpoint
117
- const { block } = await this.checkpointBuilder.addBlock(globalVariables, processedTxs, {
118
- expectedEndState: opts.expectedEndState,
119
- });
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);
120
117
 
121
- this.log.debug('Built block within checkpoint', {
122
- header: block.header.toInspect(),
123
- processedTxs: processedTxs.map(tx => tx.hash.toString()),
124
- failedTxs: failedTxs.map(tx => tx.tx.txHash.toString()),
125
- });
118
+ try {
119
+ const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(() =>
120
+ processor.process(pendingTxs, cappedOpts, validator),
121
+ );
126
122
 
127
- return {
128
- block,
129
- publicProcessorDuration,
130
- numTxs: processedTxs.length,
131
- failedTxs,
132
- usedTxs,
133
- };
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
+ }
134
160
  }
135
161
 
136
162
  /** Completes the checkpoint and returns it. */
@@ -153,11 +179,12 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
153
179
 
154
180
  /**
155
181
  * Caps per-block gas and blob field limits by remaining checkpoint-level budgets.
156
- * Computes remaining L2 gas (mana), DA gas, and blob fields from blocks already added to the checkpoint,
157
- * then returns opts with maxBlockGas and maxBlobFields capped accordingly.
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).
158
185
  */
159
186
  protected capLimitsByCheckpointBudgets(
160
- opts: PublicProcessorLimits,
187
+ opts: BlockBuilderOptions,
161
188
  ): Pick<PublicProcessorLimits, 'maxBlockGas' | 'maxBlobFields' | 'maxTransactions'> {
162
189
  const existingBlocks = this.checkpointBuilder.getBlocks();
163
190
 
@@ -178,31 +205,31 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
178
205
  const blockEndOverhead = getNumBlockEndBlobFields(isFirstBlock);
179
206
  const maxBlobFieldsForTxs = totalBlobCapacity - usedBlobFields - blockEndOverhead;
180
207
 
181
- // Cap L2 gas by remaining checkpoint mana
182
- const cappedL2Gas = Math.min(opts.maxBlockGas?.l2Gas ?? remainingMana, remainingMana);
183
-
184
- // Cap DA gas by remaining checkpoint DA gas budget
185
- const cappedDAGas = Math.min(opts.maxBlockGas?.daGas ?? remainingDAGas, remainingDAGas);
186
-
187
- // Cap blob fields by remaining checkpoint blob capacity
188
- const cappedBlobFields =
189
- opts.maxBlobFields !== undefined ? Math.min(opts.maxBlobFields, maxBlobFieldsForTxs) : maxBlobFieldsForTxs;
190
-
191
- // Cap transaction count by remaining checkpoint tx budget
192
- let cappedMaxTransactions: number | undefined;
193
- if (this.config.maxTxsPerCheckpoint !== undefined) {
194
- const usedTxs = sum(existingBlocks.map(b => b.body.txEffects.length));
195
- const remainingTxs = Math.max(0, this.config.maxTxsPerCheckpoint - usedTxs);
196
- cappedMaxTransactions =
197
- opts.maxTransactions !== undefined ? Math.min(opts.maxTransactions, remainingTxs) : remainingTxs;
198
- } else {
199
- cappedMaxTransactions = opts.maxTransactions;
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));
200
227
  }
201
228
 
202
229
  return {
203
230
  maxBlockGas: new Gas(cappedDAGas, cappedL2Gas),
204
231
  maxBlobFields: cappedBlobFields,
205
- maxTransactions: cappedMaxTransactions,
232
+ maxTransactions: Number.isFinite(cappedMaxTransactions) ? cappedMaxTransactions : undefined,
206
233
  };
207
234
  }
208
235
 
@@ -211,7 +238,7 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
211
238
  ...(await getDefaultAllowedSetupFunctions()),
212
239
  ...(this.config.txPublicSetupAllowListExtend ?? []),
213
240
  ];
214
- const contractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings());
241
+ const contractsDB = this.contractsDB;
215
242
  const guardedFork = new GuardedMerkleTreeOperations(fork);
216
243
 
217
244
  const collectDebugLogs = this.debugLogStore.isEnabled;
package/src/config.ts CHANGED
@@ -3,6 +3,7 @@ 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';
@@ -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,25 +79,29 @@ 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
+ skipProposalSlotValidation: {
83
+ description: 'Accept proposal validation regardless of slot timing (for testing only)',
84
+ ...booleanConfigHelper(false),
85
+ },
80
86
  validateMaxL2BlockGas: {
81
87
  env: 'VALIDATOR_MAX_L2_BLOCK_GAS',
82
88
  description: 'Maximum L2 block gas for validation. Proposals exceeding this limit are rejected.',
83
- parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
89
+ ...optionalNumberConfigHelper(),
84
90
  },
85
91
  validateMaxDABlockGas: {
86
92
  env: 'VALIDATOR_MAX_DA_BLOCK_GAS',
87
93
  description: 'Maximum DA block gas for validation. Proposals exceeding this limit are rejected.',
88
- parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
94
+ ...optionalNumberConfigHelper(),
89
95
  },
90
96
  validateMaxTxsPerBlock: {
91
97
  env: 'VALIDATOR_MAX_TX_PER_BLOCK',
92
98
  description: 'Maximum transactions per block for validation. Proposals exceeding this limit are rejected.',
93
- parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
99
+ ...optionalNumberConfigHelper(),
94
100
  },
95
101
  validateMaxTxsPerCheckpoint: {
96
102
  env: 'VALIDATOR_MAX_TX_PER_CHECKPOINT',
97
103
  description: 'Maximum transactions per checkpoint for validation. Proposals exceeding this limit are rejected.',
98
- parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
104
+ ...optionalNumberConfigHelper(),
99
105
  },
100
106
  ...localSignerConfigMappings,
101
107
  ...validatorHASignerConfigMappings,
@@ -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,9 +12,10 @@ 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
- import type { CheckpointHeader } from '@aztec/stdlib/rollup';
18
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
26
19
  import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
27
20
  import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
28
21
  import { DutyType, type SigningContext } from '@aztec/validator-ha-signer/types';
@@ -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,41 @@ 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: corrupt the checkpoint so observers' checkpoint validation fails.
109
+ //
110
+ // Keep `archive` aligned with `lastBlockProposal.archiveRoot` so the archive-based lookup
111
+ // in `validateCheckpointProposal` (`getBlockData({ archive })`) still succeeds
104
112
  if (options.broadcastInvalidCheckpointProposal) {
105
- archive = Fr.random();
113
+ archive = lastBlockProposal?.archiveRoot ?? Fr.random();
114
+ checkpointHeader = CheckpointHeader.from({
115
+ ...checkpointHeader,
116
+ epochOutHash: Fr.random(),
117
+ });
106
118
  this.log.warn(`Creating INVALID checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
107
119
  }
108
120
 
109
121
  // Create a signer that takes payload and context, and uses the appropriate address
110
- const payloadSigner = (payload: Buffer32, context: SigningContext) => {
122
+ const payloadSigner = (
123
+ typedData: Parameters<ValidatorKeyStore['signTypedDataWithAddress']>[1],
124
+ context: SigningContext,
125
+ ) => {
111
126
  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,
127
+ return this.keyStore.signTypedDataWithAddress(address, typedData, context);
121
128
  };
122
129
 
123
130
  return CheckpointProposal.createProposalFromSigner(
124
131
  checkpointHeader,
125
132
  archive,
133
+ checkpointNumber,
126
134
  feeAssetPriceModifier,
127
- lastBlock,
135
+ lastBlockProposal,
136
+ this.signatureContext,
128
137
  payloadSigner,
129
138
  );
130
139
  }
@@ -142,29 +151,27 @@ export class ValidationService {
142
151
  async attestToCheckpointProposal(
143
152
  proposal: CheckpointProposalCore,
144
153
  attestors: EthAddress[],
154
+ checkpointNumber: CheckpointNumber,
145
155
  ): Promise<CheckpointAttestation[]> {
146
156
  // 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)),
157
+ const payload = new ConsensusPayload(
158
+ proposal.checkpointHeader,
159
+ proposal.archive,
160
+ proposal.feeAssetPriceModifier,
161
+ this.signatureContext,
150
162
  );
163
+ const typedData = getCoordinationSignatureTypedData(payload);
151
164
 
152
- // TODO(spy/ha): Use checkpointNumber instead of blockNumber once CheckpointHeader includes it.
153
- // CheckpointProposalCore doesn't have lastBlock info, so use 0 as a proxy.
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
- const blockNumber = BlockNumber(0);
157
165
  const context: SigningContext = {
158
166
  slot: proposal.slotNumber,
159
- blockNumber,
167
+ checkpointNumber,
160
168
  dutyType: DutyType.ATTESTATION,
161
169
  };
162
170
 
163
171
  // Sign each attestor in parallel, catching HA errors per-attestor
164
172
  const results = await Promise.allSettled(
165
173
  attestors.map(async attestor => {
166
- const sig = await this.keyStore.signMessageWithAddress(attestor, buf, context);
167
- // return new BlockAttestation(proposal.payload, sig, proposal.signature);
174
+ const sig = await this.keyStore.signTypedDataWithAddress(attestor, typedData, context);
168
175
  return new CheckpointAttestation(payload, sig, proposal.signature);
169
176
  }),
170
177
  );
@@ -177,7 +184,7 @@ export class ValidationService {
177
184
  } else {
178
185
  const error = result.reason;
179
186
  if (error instanceof DutyAlreadySignedError || error instanceof SlashingProtectionError) {
180
- this.log.info(
187
+ this.log.verbose(
181
188
  `Attestation for slot ${proposal.slotNumber} by ${attestors[i]} already signed by another High-Availability node`,
182
189
  );
183
190
  // Continue with remaining attestors
@@ -195,7 +202,6 @@ export class ValidationService {
195
202
  * @param attestationsAndSigners - The attestations and signers to sign
196
203
  * @param proposer - The proposer address to sign with
197
204
  * @param slot - The slot number for HA signing context
198
- * @param blockNumber - The block or checkpoint number for HA signing context
199
205
  * @returns signature
200
206
  * @throws DutyAlreadySignedError if already signed by another HA node
201
207
  * @throws SlashingProtectionError if attempting to sign different data for same slot
@@ -204,17 +210,15 @@ export class ValidationService {
204
210
  attestationsAndSigners: CommitteeAttestationsAndSigners,
205
211
  proposer: EthAddress,
206
212
  slot: SlotNumber,
207
- blockNumber: BlockNumber | CheckpointNumber,
213
+ checkpointNumber: CheckpointNumber,
208
214
  ): Promise<Signature> {
209
215
  const context: SigningContext = {
210
216
  slot,
211
- blockNumber,
217
+ checkpointNumber,
212
218
  dutyType: DutyType.ATTESTATIONS_AND_SIGNERS,
213
219
  };
214
220
 
215
- const buf = Buffer32.fromBuffer(
216
- keccak256(attestationsAndSigners.getPayloadToSign(SignatureDomainSeparator.attestationsAndSigners)),
217
- );
218
- return this.keyStore.signMessageWithAddress(proposer, buf, context);
221
+ const typedData = getCoordinationSignatureTypedData(attestationsAndSigners);
222
+ return this.keyStore.signTypedDataWithAddress(proposer, typedData, context);
219
223
  }
220
224
  }
package/src/factory.ts CHANGED
@@ -4,16 +4,18 @@ import type { DateProvider } from '@aztec/foundation/timer';
4
4
  import type { KeystoreManager } from '@aztec/node-keystore';
5
5
  import { BlockProposalValidator, type P2PClient } from '@aztec/p2p';
6
6
  import type { L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
7
+ import type { CheckpointReexecutionTracker } from '@aztec/stdlib/checkpoint';
7
8
  import type { ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
8
9
  import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
9
10
  import type { TelemetryClient } from '@aztec/telemetry-client';
11
+ import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
10
12
 
11
- import { BlockProposalHandler } from './block_proposal_handler.js';
12
13
  import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
13
14
  import { ValidatorMetrics } from './metrics.js';
15
+ import { ProposalHandler } from './proposal_handler.js';
14
16
  import { ValidatorClient } from './validator.js';
15
17
 
16
- export function createBlockProposalHandler(
18
+ export function createProposalHandler(
17
19
  config: ValidatorClientFullConfig,
18
20
  deps: {
19
21
  checkpointsBuilder: FullNodeCheckpointsBuilder;
@@ -22,16 +24,23 @@ export function createBlockProposalHandler(
22
24
  l1ToL2MessageSource: L1ToL2MessageSource;
23
25
  p2pClient: P2PClient;
24
26
  epochCache: EpochCache;
27
+ blobClient: BlobClientInterface;
25
28
  dateProvider: DateProvider;
26
29
  telemetry: TelemetryClient;
30
+ reexecutionTracker: CheckpointReexecutionTracker;
27
31
  },
28
32
  ) {
29
33
  const metrics = new ValidatorMetrics(deps.telemetry);
30
34
  const blockProposalValidator = new BlockProposalValidator(deps.epochCache, {
31
35
  txsPermitted: !config.disableTransactions,
32
- maxTxsPerBlock: config.validateMaxTxsPerBlock,
36
+ maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
37
+ maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
38
+ signatureContext: {
39
+ chainId: config.l1ChainId,
40
+ rollupAddress: config.rollupAddress,
41
+ },
33
42
  });
34
- return new BlockProposalHandler(
43
+ return new ProposalHandler(
35
44
  deps.checkpointsBuilder,
36
45
  deps.worldState,
37
46
  deps.blockSource,
@@ -40,9 +49,12 @@ export function createBlockProposalHandler(
40
49
  blockProposalValidator,
41
50
  deps.epochCache,
42
51
  config,
52
+ deps.blobClient,
53
+ deps.reexecutionTracker,
43
54
  metrics,
44
55
  deps.dateProvider,
45
56
  deps.telemetry,
57
+ undefined,
46
58
  );
47
59
  }
48
60
 
@@ -59,6 +71,8 @@ export function createValidatorClient(
59
71
  epochCache: EpochCache;
60
72
  keyStoreManager: KeystoreManager | undefined;
61
73
  blobClient: BlobClientInterface;
74
+ reexecutionTracker: CheckpointReexecutionTracker;
75
+ slashingProtectionDb?: SlashingProtectionDatabase;
62
76
  },
63
77
  ) {
64
78
  if (config.disableValidator || !deps.keyStoreManager) {
@@ -77,7 +91,9 @@ export function createValidatorClient(
77
91
  txProvider,
78
92
  deps.keyStoreManager,
79
93
  deps.blobClient,
94
+ deps.reexecutionTracker,
80
95
  deps.dateProvider,
81
96
  deps.telemetry,
97
+ deps.slashingProtectionDb,
82
98
  );
83
99
  }
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';