@aztec/validator-client 5.0.0-private.20260318 → 5.0.0-rc.1
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/README.md +21 -22
- package/dest/checkpoint_builder.d.ts +10 -8
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +31 -28
- package/dest/config.d.ts +9 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +23 -10
- package/dest/duties/validation_service.d.ts +12 -13
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +32 -38
- package/dest/factory.d.ts +10 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +18 -6
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/metrics.d.ts +6 -2
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +12 -0
- package/dest/proposal_handler.d.ts +142 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/proposal_handler.js +1081 -0
- package/dest/validator.d.ts +28 -20
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +241 -262
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +40 -33
- package/src/config.ts +31 -12
- package/src/duties/validation_service.ts +51 -47
- package/src/factory.ts +29 -5
- package/src/index.ts +1 -1
- package/src/metrics.ts +19 -1
- package/src/proposal_handler.ts +1160 -0
- package/src/validator.ts +313 -294
- package/dest/block_proposal_handler.d.ts +0 -64
- package/dest/block_proposal_handler.d.ts.map +0 -1
- package/dest/block_proposal_handler.js +0 -606
- package/src/block_proposal_handler.ts +0 -624
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/validator-client",
|
|
3
|
-
"version": "5.0.0-
|
|
3
|
+
"version": "5.0.0-rc.1",
|
|
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": "5.0.0-
|
|
68
|
-
"@aztec/blob-lib": "5.0.0-
|
|
69
|
-
"@aztec/constants": "5.0.0-
|
|
70
|
-
"@aztec/epoch-cache": "5.0.0-
|
|
71
|
-
"@aztec/ethereum": "5.0.0-
|
|
72
|
-
"@aztec/foundation": "5.0.0-
|
|
73
|
-
"@aztec/node-keystore": "5.0.0-
|
|
74
|
-
"@aztec/noir-protocol-circuits-types": "5.0.0-
|
|
75
|
-
"@aztec/p2p": "5.0.0-
|
|
76
|
-
"@aztec/protocol-contracts": "5.0.0-
|
|
77
|
-
"@aztec/prover-client": "5.0.0-
|
|
78
|
-
"@aztec/simulator": "5.0.0-
|
|
79
|
-
"@aztec/slasher": "5.0.0-
|
|
80
|
-
"@aztec/stdlib": "5.0.0-
|
|
81
|
-
"@aztec/telemetry-client": "5.0.0-
|
|
82
|
-
"@aztec/validator-ha-signer": "5.0.0-
|
|
67
|
+
"@aztec/blob-client": "5.0.0-rc.1",
|
|
68
|
+
"@aztec/blob-lib": "5.0.0-rc.1",
|
|
69
|
+
"@aztec/constants": "5.0.0-rc.1",
|
|
70
|
+
"@aztec/epoch-cache": "5.0.0-rc.1",
|
|
71
|
+
"@aztec/ethereum": "5.0.0-rc.1",
|
|
72
|
+
"@aztec/foundation": "5.0.0-rc.1",
|
|
73
|
+
"@aztec/node-keystore": "5.0.0-rc.1",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "5.0.0-rc.1",
|
|
75
|
+
"@aztec/p2p": "5.0.0-rc.1",
|
|
76
|
+
"@aztec/protocol-contracts": "5.0.0-rc.1",
|
|
77
|
+
"@aztec/prover-client": "5.0.0-rc.1",
|
|
78
|
+
"@aztec/simulator": "5.0.0-rc.1",
|
|
79
|
+
"@aztec/slasher": "5.0.0-rc.1",
|
|
80
|
+
"@aztec/stdlib": "5.0.0-rc.1",
|
|
81
|
+
"@aztec/telemetry-client": "5.0.0-rc.1",
|
|
82
|
+
"@aztec/validator-ha-signer": "5.0.0-rc.1",
|
|
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": "5.0.0-
|
|
90
|
-
"@aztec/world-state": "5.0.0-
|
|
89
|
+
"@aztec/archiver": "5.0.0-rc.1",
|
|
90
|
+
"@aztec/world-state": "5.0.0-rc.1",
|
|
91
91
|
"@electric-sql/pglite": "^0.3.14",
|
|
92
92
|
"@jest/globals": "^30.0.0",
|
|
93
93
|
"@types/jest": "^30.0.0",
|
|
@@ -20,6 +20,7 @@ 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,
|
|
@@ -46,6 +47,9 @@ export type { BuildBlockInCheckpointResult } from '@aztec/stdlib/interfaces/serv
|
|
|
46
47
|
export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
47
48
|
private log: Logger;
|
|
48
49
|
|
|
50
|
+
/** Persistent contracts DB shared across all blocks in this checkpoint. */
|
|
51
|
+
protected contractsDB: PublicContractsDB;
|
|
52
|
+
|
|
49
53
|
constructor(
|
|
50
54
|
private checkpointBuilder: LightweightCheckpointBuilder,
|
|
51
55
|
private fork: MerkleTreeWriteOperations,
|
|
@@ -60,6 +64,7 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
60
64
|
...bindings,
|
|
61
65
|
instanceId: `checkpoint-${checkpointBuilder.checkpointNumber}`,
|
|
62
66
|
});
|
|
67
|
+
this.contractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings());
|
|
63
68
|
}
|
|
64
69
|
|
|
65
70
|
getConstantData(): CheckpointGlobalVariables {
|
|
@@ -74,7 +79,7 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
74
79
|
pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
75
80
|
blockNumber: BlockNumber,
|
|
76
81
|
timestamp: bigint,
|
|
77
|
-
opts:
|
|
82
|
+
opts: BlockBuilderOptions & { expectedEndState?: StateReference },
|
|
78
83
|
): Promise<BuildBlockInCheckpointResult> {
|
|
79
84
|
const slot = this.checkpointBuilder.constants.slotNumber;
|
|
80
85
|
|
|
@@ -104,6 +109,8 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
104
109
|
...this.capLimitsByCheckpointBudgets(opts),
|
|
105
110
|
};
|
|
106
111
|
|
|
112
|
+
// Create a block-level checkpoint on the contracts DB so we can roll back on failure
|
|
113
|
+
this.contractsDB.createCheckpoint();
|
|
107
114
|
// We execute all merkle tree operations on a world state fork checkpoint
|
|
108
115
|
// This enables us to discard all modifications in the event that we fail to successfully process sufficient transactions
|
|
109
116
|
const forkCheckpoint = await ForkCheckpoint.new(this.fork);
|
|
@@ -112,6 +119,7 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
112
119
|
const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(() =>
|
|
113
120
|
processor.process(pendingTxs, cappedOpts, validator),
|
|
114
121
|
);
|
|
122
|
+
|
|
115
123
|
// Throw before updating state if we don't have enough valid txs
|
|
116
124
|
const minValidTxs = opts.minValidTxs ?? 0;
|
|
117
125
|
if (processedTxs.length < minValidTxs) {
|
|
@@ -126,6 +134,8 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
126
134
|
expectedEndState: opts.expectedEndState,
|
|
127
135
|
});
|
|
128
136
|
|
|
137
|
+
this.contractsDB.commitCheckpoint();
|
|
138
|
+
|
|
129
139
|
this.log.debug('Built block within checkpoint', {
|
|
130
140
|
header: block.header.toInspect(),
|
|
131
141
|
processedTxs: processedTxs.map(tx => tx.hash.toString()),
|
|
@@ -140,6 +150,8 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
140
150
|
usedTxs,
|
|
141
151
|
};
|
|
142
152
|
} catch (err) {
|
|
153
|
+
// Revert all changes to contracts db
|
|
154
|
+
this.contractsDB.revertCheckpoint();
|
|
143
155
|
// If we reached the point of committing the checkpoint, this does nothing
|
|
144
156
|
// Otherwise it reverts any changes made to the fork for this failed block
|
|
145
157
|
await forkCheckpoint.revert();
|
|
@@ -167,11 +179,12 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
167
179
|
|
|
168
180
|
/**
|
|
169
181
|
* Caps per-block gas and blob field limits by remaining checkpoint-level budgets.
|
|
170
|
-
*
|
|
171
|
-
*
|
|
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).
|
|
172
185
|
*/
|
|
173
186
|
protected capLimitsByCheckpointBudgets(
|
|
174
|
-
opts:
|
|
187
|
+
opts: BlockBuilderOptions,
|
|
175
188
|
): Pick<PublicProcessorLimits, 'maxBlockGas' | 'maxBlobFields' | 'maxTransactions'> {
|
|
176
189
|
const existingBlocks = this.checkpointBuilder.getBlocks();
|
|
177
190
|
|
|
@@ -192,39 +205,33 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
192
205
|
const blockEndOverhead = getNumBlockEndBlobFields(isFirstBlock);
|
|
193
206
|
const maxBlobFieldsForTxs = totalBlobCapacity - usedBlobFields - blockEndOverhead;
|
|
194
207
|
|
|
195
|
-
//
|
|
196
|
-
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
//
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
const usedTxs = sum(existingBlocks.map(b => b.body.txEffects.length));
|
|
217
|
-
const remainingTxs = Math.max(0, this.config.maxTxsPerCheckpoint - usedTxs);
|
|
218
|
-
const fairShareTxs = redistribute ? Math.ceil((remainingTxs / remainingBlocks) * multiplier) : Infinity;
|
|
219
|
-
cappedMaxTransactions = Math.min(opts.maxTransactions ?? Infinity, fairShareTxs, remainingTxs);
|
|
220
|
-
} else {
|
|
221
|
-
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
|
+
// DA gas and blob fields use a higher multiplier so the largest contract class deploy fits a block.
|
|
223
|
+
const daMultiplier = opts.perBlockDAAllocationMultiplier ?? multiplier;
|
|
224
|
+
|
|
225
|
+
cappedL2Gas = Math.min(cappedL2Gas, Math.ceil((remainingMana / remainingBlocks) * multiplier));
|
|
226
|
+
cappedDAGas = Math.min(cappedDAGas, Math.ceil((remainingDAGas / remainingBlocks) * daMultiplier));
|
|
227
|
+
cappedBlobFields = Math.min(cappedBlobFields, Math.ceil((maxBlobFieldsForTxs / remainingBlocks) * daMultiplier));
|
|
228
|
+
cappedMaxTransactions = Math.min(cappedMaxTransactions, Math.ceil((remainingTxs / remainingBlocks) * multiplier));
|
|
222
229
|
}
|
|
223
230
|
|
|
224
231
|
return {
|
|
225
232
|
maxBlockGas: new Gas(cappedDAGas, cappedL2Gas),
|
|
226
233
|
maxBlobFields: cappedBlobFields,
|
|
227
|
-
maxTransactions: cappedMaxTransactions,
|
|
234
|
+
maxTransactions: Number.isFinite(cappedMaxTransactions) ? cappedMaxTransactions : undefined,
|
|
228
235
|
};
|
|
229
236
|
}
|
|
230
237
|
|
|
@@ -233,7 +240,7 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
233
240
|
...(await getDefaultAllowedSetupFunctions()),
|
|
234
241
|
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
235
242
|
];
|
|
236
|
-
const contractsDB =
|
|
243
|
+
const contractsDB = this.contractsDB;
|
|
237
244
|
const guardedFork = new GuardedMerkleTreeOperations(fork);
|
|
238
245
|
|
|
239
246
|
const collectDebugLogs = this.debugLogStore.isEnabled;
|
package/src/config.ts
CHANGED
|
@@ -3,15 +3,27 @@ import {
|
|
|
3
3
|
booleanConfigHelper,
|
|
4
4
|
getConfigFromMappings,
|
|
5
5
|
numberConfigHelper,
|
|
6
|
+
optionalNumberConfigHelper,
|
|
7
|
+
pickConfigMappings,
|
|
6
8
|
secretValueConfigHelper,
|
|
7
9
|
} from '@aztec/foundation/config';
|
|
8
10
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
11
|
+
import { type SequencerConfig, sharedSequencerConfigMappings } from '@aztec/stdlib/config';
|
|
9
12
|
import { localSignerConfigMappings, validatorHASignerConfigMappings } from '@aztec/stdlib/ha-signing';
|
|
10
13
|
import type { ValidatorClientConfig } from '@aztec/stdlib/interfaces/server';
|
|
11
14
|
|
|
12
15
|
export type { ValidatorClientConfig };
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Default clock-disparity tolerance (ms) for proposal/attestation receive windows, mirroring the p2p config
|
|
19
|
+
* default. Used by the validator-client validators when the merged node config does not carry the value.
|
|
20
|
+
*/
|
|
21
|
+
export const DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS = 500;
|
|
22
|
+
|
|
23
|
+
export const validatorClientConfigMappings: ConfigMappingsType<
|
|
24
|
+
ValidatorClientConfig & Pick<SequencerConfig, 'blockDurationMs'>
|
|
25
|
+
> = {
|
|
26
|
+
...pickConfigMappings(sharedSequencerConfigMappings, ['blockDurationMs']),
|
|
15
27
|
validatorPrivateKeys: {
|
|
16
28
|
env: 'VALIDATOR_PRIVATE_KEYS',
|
|
17
29
|
description: 'List of private keys of the validators participating in attestation duties',
|
|
@@ -30,6 +42,12 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
|
|
|
30
42
|
.map(address => EthAddress.fromString(address.trim())),
|
|
31
43
|
defaultValue: [],
|
|
32
44
|
},
|
|
45
|
+
l1ChainId: {
|
|
46
|
+
env: 'L1_CHAIN_ID',
|
|
47
|
+
description: 'The chain ID of the ethereum host.',
|
|
48
|
+
parseEnv: (val: string) => +val,
|
|
49
|
+
defaultValue: 31337,
|
|
50
|
+
},
|
|
33
51
|
disableValidator: {
|
|
34
52
|
env: 'VALIDATOR_DISABLED',
|
|
35
53
|
description: 'Do not run the validator',
|
|
@@ -49,11 +67,6 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
|
|
|
49
67
|
description: 'Interval between polling for new attestations',
|
|
50
68
|
...numberConfigHelper(200),
|
|
51
69
|
},
|
|
52
|
-
validatorReexecute: {
|
|
53
|
-
env: 'VALIDATOR_REEXECUTE',
|
|
54
|
-
description: 'Re-execute transactions before attesting',
|
|
55
|
-
...booleanConfigHelper(true),
|
|
56
|
-
},
|
|
57
70
|
alwaysReexecuteBlockProposals: {
|
|
58
71
|
description:
|
|
59
72
|
'Whether to always reexecute block proposals, even for non-validator nodes (useful for monitoring network status).',
|
|
@@ -77,25 +90,29 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
|
|
|
77
90
|
description: 'Agree to attest to equivocated checkpoint proposals (for testing purposes only)',
|
|
78
91
|
...booleanConfigHelper(false),
|
|
79
92
|
},
|
|
93
|
+
skipProposalSlotValidation: {
|
|
94
|
+
description: 'Accept proposal validation regardless of slot timing (for testing only)',
|
|
95
|
+
...booleanConfigHelper(false),
|
|
96
|
+
},
|
|
80
97
|
validateMaxL2BlockGas: {
|
|
81
98
|
env: 'VALIDATOR_MAX_L2_BLOCK_GAS',
|
|
82
99
|
description: 'Maximum L2 block gas for validation. Proposals exceeding this limit are rejected.',
|
|
83
|
-
|
|
100
|
+
...optionalNumberConfigHelper(),
|
|
84
101
|
},
|
|
85
102
|
validateMaxDABlockGas: {
|
|
86
103
|
env: 'VALIDATOR_MAX_DA_BLOCK_GAS',
|
|
87
104
|
description: 'Maximum DA block gas for validation. Proposals exceeding this limit are rejected.',
|
|
88
|
-
|
|
105
|
+
...optionalNumberConfigHelper(),
|
|
89
106
|
},
|
|
90
107
|
validateMaxTxsPerBlock: {
|
|
91
108
|
env: 'VALIDATOR_MAX_TX_PER_BLOCK',
|
|
92
109
|
description: 'Maximum transactions per block for validation. Proposals exceeding this limit are rejected.',
|
|
93
|
-
|
|
110
|
+
...optionalNumberConfigHelper(),
|
|
94
111
|
},
|
|
95
112
|
validateMaxTxsPerCheckpoint: {
|
|
96
113
|
env: 'VALIDATOR_MAX_TX_PER_CHECKPOINT',
|
|
97
114
|
description: 'Maximum transactions per checkpoint for validation. Proposals exceeding this limit are rejected.',
|
|
98
|
-
|
|
115
|
+
...optionalNumberConfigHelper(),
|
|
99
116
|
},
|
|
100
117
|
...localSignerConfigMappings,
|
|
101
118
|
...validatorHASignerConfigMappings,
|
|
@@ -106,6 +123,8 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
|
|
|
106
123
|
* Note: If an environment variable is not set, the default value is used.
|
|
107
124
|
* @returns The validator configuration.
|
|
108
125
|
*/
|
|
109
|
-
export function getProverEnvVars(): ValidatorClientConfig {
|
|
110
|
-
return getConfigFromMappings<ValidatorClientConfig
|
|
126
|
+
export function getProverEnvVars(): ValidatorClientConfig & Pick<SequencerConfig, 'blockDurationMs'> {
|
|
127
|
+
return getConfigFromMappings<ValidatorClientConfig & Pick<SequencerConfig, 'blockDurationMs'>>(
|
|
128
|
+
validatorClientConfigMappings,
|
|
129
|
+
);
|
|
111
130
|
}
|
|
@@ -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
|
|
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
|
-
|
|
15
|
+
type CoordinationSignatureContext,
|
|
16
|
+
getCoordinationSignatureTypedData,
|
|
24
17
|
} from '@aztec/stdlib/p2p';
|
|
25
|
-
import
|
|
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 = (
|
|
71
|
-
|
|
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
|
|
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
|
-
|
|
104
|
+
lastBlockProposal: BlockProposal | undefined,
|
|
100
105
|
proposerAttesterAddress: EthAddress | undefined,
|
|
101
106
|
options: CheckpointProposalOptions,
|
|
102
107
|
): Promise<CheckpointProposal> {
|
|
103
|
-
// For testing:
|
|
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 = (
|
|
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.
|
|
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
|
-
|
|
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(
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
);
|
|
@@ -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
|
-
|
|
213
|
+
checkpointNumber: CheckpointNumber,
|
|
208
214
|
): Promise<Signature> {
|
|
209
215
|
const context: SigningContext = {
|
|
210
216
|
slot,
|
|
211
|
-
|
|
217
|
+
checkpointNumber,
|
|
212
218
|
dutyType: DutyType.ATTESTATIONS_AND_SIGNERS,
|
|
213
219
|
};
|
|
214
220
|
|
|
215
|
-
const
|
|
216
|
-
|
|
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,20 @@ 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';
|
|
10
|
+
import { ConsensusTimetable } from '@aztec/stdlib/timetable';
|
|
9
11
|
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
12
|
+
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
10
13
|
|
|
11
|
-
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
12
14
|
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
15
|
+
import { DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS } from './config.js';
|
|
13
16
|
import { ValidatorMetrics } from './metrics.js';
|
|
17
|
+
import { ProposalHandler } from './proposal_handler.js';
|
|
14
18
|
import { ValidatorClient } from './validator.js';
|
|
15
19
|
|
|
16
|
-
export function
|
|
20
|
+
export function createProposalHandler(
|
|
17
21
|
config: ValidatorClientFullConfig,
|
|
18
22
|
deps: {
|
|
19
23
|
checkpointsBuilder: FullNodeCheckpointsBuilder;
|
|
@@ -22,16 +26,28 @@ export function createBlockProposalHandler(
|
|
|
22
26
|
l1ToL2MessageSource: L1ToL2MessageSource;
|
|
23
27
|
p2pClient: P2PClient;
|
|
24
28
|
epochCache: EpochCache;
|
|
29
|
+
blobClient: BlobClientInterface;
|
|
25
30
|
dateProvider: DateProvider;
|
|
26
31
|
telemetry: TelemetryClient;
|
|
32
|
+
reexecutionTracker: CheckpointReexecutionTracker;
|
|
27
33
|
},
|
|
28
34
|
) {
|
|
29
35
|
const metrics = new ValidatorMetrics(deps.telemetry);
|
|
30
|
-
const
|
|
36
|
+
const consensusTimetable = new ConsensusTimetable({
|
|
37
|
+
l1Constants: deps.epochCache.getL1Constants(),
|
|
38
|
+
blockDuration: config.blockDurationMs / 1000,
|
|
39
|
+
});
|
|
40
|
+
const blockProposalValidator = new BlockProposalValidator(deps.epochCache, consensusTimetable, {
|
|
31
41
|
txsPermitted: !config.disableTransactions,
|
|
32
|
-
maxTxsPerBlock: config.validateMaxTxsPerBlock,
|
|
42
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
|
|
43
|
+
maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
|
|
44
|
+
signatureContext: {
|
|
45
|
+
chainId: config.l1ChainId,
|
|
46
|
+
rollupAddress: config.rollupAddress,
|
|
47
|
+
},
|
|
48
|
+
clockDisparityMs: config.maxGossipClockDisparityMs ?? DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS,
|
|
33
49
|
});
|
|
34
|
-
return new
|
|
50
|
+
return new ProposalHandler(
|
|
35
51
|
deps.checkpointsBuilder,
|
|
36
52
|
deps.worldState,
|
|
37
53
|
deps.blockSource,
|
|
@@ -39,10 +55,14 @@ export function createBlockProposalHandler(
|
|
|
39
55
|
deps.p2pClient.getTxProvider(),
|
|
40
56
|
blockProposalValidator,
|
|
41
57
|
deps.epochCache,
|
|
58
|
+
consensusTimetable,
|
|
42
59
|
config,
|
|
60
|
+
deps.blobClient,
|
|
61
|
+
deps.reexecutionTracker,
|
|
43
62
|
metrics,
|
|
44
63
|
deps.dateProvider,
|
|
45
64
|
deps.telemetry,
|
|
65
|
+
undefined,
|
|
46
66
|
);
|
|
47
67
|
}
|
|
48
68
|
|
|
@@ -59,6 +79,8 @@ export function createValidatorClient(
|
|
|
59
79
|
epochCache: EpochCache;
|
|
60
80
|
keyStoreManager: KeystoreManager | undefined;
|
|
61
81
|
blobClient: BlobClientInterface;
|
|
82
|
+
reexecutionTracker: CheckpointReexecutionTracker;
|
|
83
|
+
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
62
84
|
},
|
|
63
85
|
) {
|
|
64
86
|
if (config.disableValidator || !deps.keyStoreManager) {
|
|
@@ -77,7 +99,9 @@ export function createValidatorClient(
|
|
|
77
99
|
txProvider,
|
|
78
100
|
deps.keyStoreManager,
|
|
79
101
|
deps.blobClient,
|
|
102
|
+
deps.reexecutionTracker,
|
|
80
103
|
deps.dateProvider,
|
|
81
104
|
deps.telemetry,
|
|
105
|
+
deps.slashingProtectionDb,
|
|
82
106
|
);
|
|
83
107
|
}
|
package/src/index.ts
CHANGED