@aztec/validator-client 0.0.1-commit.fffb133c → 0.0.1-dev
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 +62 -18
- package/dest/checkpoint_builder.d.ts +26 -14
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +136 -45
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +26 -3
- package/dest/duties/validation_service.d.ts +3 -4
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +11 -22
- package/dest/factory.d.ts +7 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +6 -5
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/key_store/ha_key_store.d.ts +1 -1
- package/dest/key_store/ha_key_store.d.ts.map +1 -1
- package/dest/key_store/ha_key_store.js +3 -3
- package/dest/metrics.d.ts +12 -3
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +46 -5
- package/dest/proposal_handler.d.ts +94 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/{block_proposal_handler.js → proposal_handler.js} +376 -69
- package/dest/validator.d.ts +37 -24
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +167 -215
- package/package.json +19 -17
- package/src/checkpoint_builder.ts +183 -50
- package/src/config.ts +26 -3
- package/src/duties/validation_service.ts +18 -24
- package/src/factory.ts +9 -3
- package/src/index.ts +1 -2
- package/src/key_store/ha_key_store.ts +3 -3
- package/src/metrics.ts +63 -6
- package/src/proposal_handler.ts +903 -0
- package/src/validator.ts +228 -248
- package/dest/block_proposal_handler.d.ts +0 -64
- package/dest/block_proposal_handler.d.ts.map +0 -1
- package/dest/tx_validator/index.d.ts +0 -3
- package/dest/tx_validator/index.d.ts.map +0 -1
- package/dest/tx_validator/index.js +0 -2
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -54
- package/src/block_proposal_handler.ts +0 -554
- package/src/tx_validator/index.ts +0 -2
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -135
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { NUM_CHECKPOINT_END_MARKER_FIELDS, getNumBlockEndBlobFields } from '@aztec/blob-lib/encoding';
|
|
2
|
+
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB, MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT } from '@aztec/constants';
|
|
1
3
|
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { merge, pick } from '@aztec/foundation/collection';
|
|
4
|
+
import { merge, pick, sum } from '@aztec/foundation/collection';
|
|
3
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
5
7
|
import { bufferToHex } from '@aztec/foundation/string';
|
|
6
|
-
import { DateProvider,
|
|
7
|
-
import { getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
|
|
8
|
+
import { DateProvider, elapsed } from '@aztec/foundation/timer';
|
|
9
|
+
import { createTxValidatorForBlockBuilding, getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
|
|
8
10
|
import { LightweightCheckpointBuilder } from '@aztec/prover-client/light';
|
|
9
11
|
import {
|
|
10
12
|
GuardedMerkleTreeOperations,
|
|
@@ -18,36 +20,36 @@ 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
31
|
type PublicProcessorLimits,
|
|
28
32
|
type WorldStateSynchronizer,
|
|
29
33
|
} from '@aztec/stdlib/interfaces/server';
|
|
34
|
+
import { type DebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
30
35
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
31
36
|
import { type CheckpointGlobalVariables, GlobalVariables, StateReference, Tx } from '@aztec/stdlib/tx';
|
|
32
37
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
33
|
-
|
|
34
|
-
import { createValidatorForBlockBuilding } from './tx_validator/tx_validator_factory.js';
|
|
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';
|
|
38
42
|
|
|
39
|
-
const log = createLogger('checkpoint-builder');
|
|
40
|
-
|
|
41
|
-
/** Result of building a block within a checkpoint. Extends the base interface with timer. */
|
|
42
|
-
export interface BuildBlockInCheckpointResultWithTimer extends BuildBlockInCheckpointResult {
|
|
43
|
-
blockBuildingTimer: Timer;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
43
|
/**
|
|
47
44
|
* Builder for a single checkpoint. Handles building blocks within the checkpoint
|
|
48
45
|
* and completing it.
|
|
49
46
|
*/
|
|
50
47
|
export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
48
|
+
private log: Logger;
|
|
49
|
+
|
|
50
|
+
/** Persistent contracts DB shared across all blocks in this checkpoint. */
|
|
51
|
+
protected contractsDB: PublicContractsDB;
|
|
52
|
+
|
|
51
53
|
constructor(
|
|
52
54
|
private checkpointBuilder: LightweightCheckpointBuilder,
|
|
53
55
|
private fork: MerkleTreeWriteOperations,
|
|
@@ -55,7 +57,15 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
55
57
|
private contractDataSource: ContractDataSource,
|
|
56
58
|
private dateProvider: DateProvider,
|
|
57
59
|
private telemetryClient: TelemetryClient,
|
|
58
|
-
|
|
60
|
+
bindings?: LoggerBindings,
|
|
61
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
62
|
+
) {
|
|
63
|
+
this.log = createLogger('checkpoint-builder', {
|
|
64
|
+
...bindings,
|
|
65
|
+
instanceId: `checkpoint-${checkpointBuilder.checkpointNumber}`,
|
|
66
|
+
});
|
|
67
|
+
this.contractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings());
|
|
68
|
+
}
|
|
59
69
|
|
|
60
70
|
getConstantData(): CheckpointGlobalVariables {
|
|
61
71
|
return this.checkpointBuilder.constants;
|
|
@@ -63,17 +73,17 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
63
73
|
|
|
64
74
|
/**
|
|
65
75
|
* Builds a single block within this checkpoint.
|
|
76
|
+
* Automatically caps gas and blob field limits based on checkpoint-level budgets and prior blocks.
|
|
66
77
|
*/
|
|
67
78
|
async buildBlock(
|
|
68
79
|
pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
69
80
|
blockNumber: BlockNumber,
|
|
70
81
|
timestamp: bigint,
|
|
71
|
-
opts:
|
|
72
|
-
): Promise<
|
|
73
|
-
const blockBuildingTimer = new Timer();
|
|
82
|
+
opts: BlockBuilderOptions & { expectedEndState?: StateReference },
|
|
83
|
+
): Promise<BuildBlockInCheckpointResult> {
|
|
74
84
|
const slot = this.checkpointBuilder.constants.slotNumber;
|
|
75
85
|
|
|
76
|
-
log.verbose(`Building block ${blockNumber} for slot ${slot} within checkpoint`, {
|
|
86
|
+
this.log.verbose(`Building block ${blockNumber} for slot ${slot} within checkpoint`, {
|
|
77
87
|
slot,
|
|
78
88
|
blockNumber,
|
|
79
89
|
...opts,
|
|
@@ -93,37 +103,67 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
93
103
|
});
|
|
94
104
|
const { processor, validator } = await this.makeBlockBuilderDeps(globalVariables, this.fork);
|
|
95
105
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
// Add block to checkpoint
|
|
101
|
-
const block = await this.checkpointBuilder.addBlock(globalVariables, processedTxs, {
|
|
102
|
-
expectedEndState: opts.expectedEndState,
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// How much public gas was processed
|
|
106
|
-
const publicGas = processedTxs.reduce((acc, tx) => acc.add(tx.gasUsed.publicGas), Gas.empty());
|
|
107
|
-
|
|
108
|
-
const res = {
|
|
109
|
-
block,
|
|
110
|
-
publicGas,
|
|
111
|
-
publicProcessorDuration,
|
|
112
|
-
numTxs: processedTxs.length,
|
|
113
|
-
failedTxs,
|
|
114
|
-
blockBuildingTimer,
|
|
115
|
-
usedTxs,
|
|
116
|
-
usedTxBlobFields,
|
|
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),
|
|
117
110
|
};
|
|
118
|
-
|
|
119
|
-
|
|
111
|
+
|
|
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);
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(() =>
|
|
120
|
+
processor.process(pendingTxs, cappedOpts, validator),
|
|
121
|
+
);
|
|
122
|
+
|
|
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
|
+
}
|
|
120
160
|
}
|
|
121
161
|
|
|
122
162
|
/** Completes the checkpoint and returns it. */
|
|
123
163
|
async completeCheckpoint(): Promise<Checkpoint> {
|
|
124
164
|
const checkpoint = await this.checkpointBuilder.completeCheckpoint();
|
|
125
165
|
|
|
126
|
-
log.verbose(`Completed checkpoint ${checkpoint.number}`, {
|
|
166
|
+
this.log.verbose(`Completed checkpoint ${checkpoint.number}`, {
|
|
127
167
|
checkpointNumber: checkpoint.number,
|
|
128
168
|
numBlocks: checkpoint.blocks.length,
|
|
129
169
|
archiveRoot: checkpoint.archive.root.toString(),
|
|
@@ -137,16 +177,80 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
137
177
|
return this.checkpointBuilder.clone().completeCheckpoint();
|
|
138
178
|
}
|
|
139
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
|
+
|
|
140
236
|
protected async makeBlockBuilderDeps(globalVariables: GlobalVariables, fork: MerkleTreeWriteOperations) {
|
|
141
|
-
const txPublicSetupAllowList =
|
|
142
|
-
|
|
237
|
+
const txPublicSetupAllowList = [
|
|
238
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
239
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
240
|
+
];
|
|
241
|
+
const contractsDB = this.contractsDB;
|
|
143
242
|
const guardedFork = new GuardedMerkleTreeOperations(fork);
|
|
144
243
|
|
|
244
|
+
const collectDebugLogs = this.debugLogStore.isEnabled;
|
|
245
|
+
|
|
246
|
+
const bindings = this.log.getBindings();
|
|
145
247
|
const publicTxSimulator = createPublicTxSimulatorForBlockBuilding(
|
|
146
248
|
guardedFork,
|
|
147
249
|
contractsDB,
|
|
148
250
|
globalVariables,
|
|
149
251
|
this.telemetryClient,
|
|
252
|
+
bindings,
|
|
253
|
+
collectDebugLogs,
|
|
150
254
|
);
|
|
151
255
|
|
|
152
256
|
const processor = new PublicProcessor(
|
|
@@ -156,15 +260,17 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
156
260
|
publicTxSimulator,
|
|
157
261
|
this.dateProvider,
|
|
158
262
|
this.telemetryClient,
|
|
159
|
-
|
|
263
|
+
createLogger('simulator:public-processor', bindings),
|
|
160
264
|
this.config,
|
|
265
|
+
this.debugLogStore,
|
|
161
266
|
);
|
|
162
267
|
|
|
163
|
-
const validator =
|
|
268
|
+
const validator = createTxValidatorForBlockBuilding(
|
|
164
269
|
fork,
|
|
165
270
|
this.contractDataSource,
|
|
166
271
|
globalVariables,
|
|
167
272
|
txPublicSetupAllowList,
|
|
273
|
+
this.log.getBindings(),
|
|
168
274
|
);
|
|
169
275
|
|
|
170
276
|
return {
|
|
@@ -176,13 +282,18 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
176
282
|
|
|
177
283
|
/** Factory for creating checkpoint builders. */
|
|
178
284
|
export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
285
|
+
private log: Logger;
|
|
286
|
+
|
|
179
287
|
constructor(
|
|
180
288
|
private config: FullNodeBlockBuilderConfig & Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>,
|
|
181
289
|
private worldState: WorldStateSynchronizer,
|
|
182
290
|
private contractDataSource: ContractDataSource,
|
|
183
291
|
private dateProvider: DateProvider,
|
|
184
292
|
private telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
185
|
-
|
|
293
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
294
|
+
) {
|
|
295
|
+
this.log = createLogger('checkpoint-builder');
|
|
296
|
+
}
|
|
186
297
|
|
|
187
298
|
public getConfig(): FullNodeBlockBuilderConfig {
|
|
188
299
|
return this.config;
|
|
@@ -198,19 +309,22 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
198
309
|
async startCheckpoint(
|
|
199
310
|
checkpointNumber: CheckpointNumber,
|
|
200
311
|
constants: CheckpointGlobalVariables,
|
|
312
|
+
feeAssetPriceModifier: bigint,
|
|
201
313
|
l1ToL2Messages: Fr[],
|
|
202
314
|
previousCheckpointOutHashes: Fr[],
|
|
203
315
|
fork: MerkleTreeWriteOperations,
|
|
316
|
+
bindings?: LoggerBindings,
|
|
204
317
|
): Promise<CheckpointBuilder> {
|
|
205
318
|
const stateReference = await fork.getStateReference();
|
|
206
319
|
const archiveTree = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
207
320
|
|
|
208
|
-
log.verbose(`Building new checkpoint ${checkpointNumber}`, {
|
|
321
|
+
this.log.verbose(`Building new checkpoint ${checkpointNumber}`, {
|
|
209
322
|
checkpointNumber,
|
|
210
323
|
msgCount: l1ToL2Messages.length,
|
|
211
324
|
initialStateReference: stateReference.toInspect(),
|
|
212
325
|
initialArchiveRoot: bufferToHex(archiveTree.root),
|
|
213
326
|
constants,
|
|
327
|
+
feeAssetPriceModifier,
|
|
214
328
|
});
|
|
215
329
|
|
|
216
330
|
const lightweightBuilder = await LightweightCheckpointBuilder.startNewCheckpoint(
|
|
@@ -219,6 +333,8 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
219
333
|
l1ToL2Messages,
|
|
220
334
|
previousCheckpointOutHashes,
|
|
221
335
|
fork,
|
|
336
|
+
bindings,
|
|
337
|
+
feeAssetPriceModifier,
|
|
222
338
|
);
|
|
223
339
|
|
|
224
340
|
return new CheckpointBuilder(
|
|
@@ -228,6 +344,8 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
228
344
|
this.contractDataSource,
|
|
229
345
|
this.dateProvider,
|
|
230
346
|
this.telemetryClient,
|
|
347
|
+
bindings,
|
|
348
|
+
this.debugLogStore,
|
|
231
349
|
);
|
|
232
350
|
}
|
|
233
351
|
|
|
@@ -237,34 +355,47 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
237
355
|
async openCheckpoint(
|
|
238
356
|
checkpointNumber: CheckpointNumber,
|
|
239
357
|
constants: CheckpointGlobalVariables,
|
|
358
|
+
feeAssetPriceModifier: bigint,
|
|
240
359
|
l1ToL2Messages: Fr[],
|
|
241
360
|
previousCheckpointOutHashes: Fr[],
|
|
242
361
|
fork: MerkleTreeWriteOperations,
|
|
243
362
|
existingBlocks: L2Block[] = [],
|
|
363
|
+
bindings?: LoggerBindings,
|
|
244
364
|
): Promise<CheckpointBuilder> {
|
|
245
365
|
const stateReference = await fork.getStateReference();
|
|
246
366
|
const archiveTree = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
247
367
|
|
|
248
368
|
if (existingBlocks.length === 0) {
|
|
249
|
-
return this.startCheckpoint(
|
|
369
|
+
return this.startCheckpoint(
|
|
370
|
+
checkpointNumber,
|
|
371
|
+
constants,
|
|
372
|
+
feeAssetPriceModifier,
|
|
373
|
+
l1ToL2Messages,
|
|
374
|
+
previousCheckpointOutHashes,
|
|
375
|
+
fork,
|
|
376
|
+
bindings,
|
|
377
|
+
);
|
|
250
378
|
}
|
|
251
379
|
|
|
252
|
-
log.verbose(`Resuming checkpoint ${checkpointNumber} with ${existingBlocks.length} existing blocks`, {
|
|
380
|
+
this.log.verbose(`Resuming checkpoint ${checkpointNumber} with ${existingBlocks.length} existing blocks`, {
|
|
253
381
|
checkpointNumber,
|
|
254
382
|
msgCount: l1ToL2Messages.length,
|
|
255
383
|
existingBlockCount: existingBlocks.length,
|
|
256
384
|
initialStateReference: stateReference.toInspect(),
|
|
257
385
|
initialArchiveRoot: bufferToHex(archiveTree.root),
|
|
258
386
|
constants,
|
|
387
|
+
feeAssetPriceModifier,
|
|
259
388
|
});
|
|
260
389
|
|
|
261
390
|
const lightweightBuilder = await LightweightCheckpointBuilder.resumeCheckpoint(
|
|
262
391
|
checkpointNumber,
|
|
263
392
|
constants,
|
|
393
|
+
feeAssetPriceModifier,
|
|
264
394
|
l1ToL2Messages,
|
|
265
395
|
previousCheckpointOutHashes,
|
|
266
396
|
fork,
|
|
267
397
|
existingBlocks,
|
|
398
|
+
bindings,
|
|
268
399
|
);
|
|
269
400
|
|
|
270
401
|
return new CheckpointBuilder(
|
|
@@ -274,6 +405,8 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
274
405
|
this.contractDataSource,
|
|
275
406
|
this.dateProvider,
|
|
276
407
|
this.telemetryClient,
|
|
408
|
+
bindings,
|
|
409
|
+
this.debugLogStore,
|
|
277
410
|
);
|
|
278
411
|
}
|
|
279
412
|
|
package/src/config.ts
CHANGED
|
@@ -65,15 +65,38 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
|
|
|
65
65
|
'Whether to run in fisherman mode: validates all proposals and attestations but does not broadcast attestations or participate in consensus.',
|
|
66
66
|
...booleanConfigHelper(false),
|
|
67
67
|
},
|
|
68
|
-
// TODO(palla/mbps): Change default to false once checkpoint validation is stable
|
|
69
68
|
skipCheckpointProposalValidation: {
|
|
70
|
-
description: 'Skip checkpoint proposal validation and always attest (default:
|
|
71
|
-
defaultValue:
|
|
69
|
+
description: 'Skip checkpoint proposal validation and always attest (default: false)',
|
|
70
|
+
defaultValue: false,
|
|
72
71
|
},
|
|
73
72
|
skipPushProposedBlocksToArchiver: {
|
|
74
73
|
description: 'Skip pushing re-executed blocks to archiver (default: false)',
|
|
75
74
|
defaultValue: false,
|
|
76
75
|
},
|
|
76
|
+
attestToEquivocatedProposals: {
|
|
77
|
+
description: 'Agree to attest to equivocated checkpoint proposals (for testing purposes only)',
|
|
78
|
+
...booleanConfigHelper(false),
|
|
79
|
+
},
|
|
80
|
+
validateMaxL2BlockGas: {
|
|
81
|
+
env: 'VALIDATOR_MAX_L2_BLOCK_GAS',
|
|
82
|
+
description: 'Maximum L2 block gas for validation. Proposals exceeding this limit are rejected.',
|
|
83
|
+
parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
|
|
84
|
+
},
|
|
85
|
+
validateMaxDABlockGas: {
|
|
86
|
+
env: 'VALIDATOR_MAX_DA_BLOCK_GAS',
|
|
87
|
+
description: 'Maximum DA block gas for validation. Proposals exceeding this limit are rejected.',
|
|
88
|
+
parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
|
|
89
|
+
},
|
|
90
|
+
validateMaxTxsPerBlock: {
|
|
91
|
+
env: 'VALIDATOR_MAX_TX_PER_BLOCK',
|
|
92
|
+
description: 'Maximum transactions per block for validation. Proposals exceeding this limit are rejected.',
|
|
93
|
+
parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
|
|
94
|
+
},
|
|
95
|
+
validateMaxTxsPerCheckpoint: {
|
|
96
|
+
env: 'VALIDATOR_MAX_TX_PER_CHECKPOINT',
|
|
97
|
+
description: 'Maximum transactions per checkpoint for validation. Proposals exceeding this limit are rejected.',
|
|
98
|
+
parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
|
|
99
|
+
},
|
|
77
100
|
...validatorHASignerConfigMappings,
|
|
78
101
|
};
|
|
79
102
|
|
|
@@ -11,7 +11,6 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
11
11
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
12
12
|
import { createLogger } from '@aztec/foundation/log';
|
|
13
13
|
import type { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
14
|
-
import type { CreateCheckpointProposalLastBlockData } from '@aztec/stdlib/interfaces/server';
|
|
15
14
|
import {
|
|
16
15
|
BlockProposal,
|
|
17
16
|
type BlockProposalOptions,
|
|
@@ -86,7 +85,7 @@ export class ValidationService {
|
|
|
86
85
|
*
|
|
87
86
|
* @param checkpointHeader - The checkpoint header containing aggregated data
|
|
88
87
|
* @param archive - The archive of the checkpoint
|
|
89
|
-
* @param
|
|
88
|
+
* @param lastBlockProposal - Signed block proposal for the last block in the checkpoint, or undefined
|
|
90
89
|
* @param proposerAttesterAddress - The address of the proposer
|
|
91
90
|
* @param options - Checkpoint proposal options
|
|
92
91
|
*
|
|
@@ -95,13 +94,16 @@ export class ValidationService {
|
|
|
95
94
|
public createCheckpointProposal(
|
|
96
95
|
checkpointHeader: CheckpointHeader,
|
|
97
96
|
archive: Fr,
|
|
98
|
-
|
|
97
|
+
feeAssetPriceModifier: bigint,
|
|
98
|
+
lastBlockProposal: BlockProposal | undefined,
|
|
99
99
|
proposerAttesterAddress: EthAddress | undefined,
|
|
100
100
|
options: CheckpointProposalOptions,
|
|
101
101
|
): Promise<CheckpointProposal> {
|
|
102
|
-
// For testing: change the archive to trigger state_mismatch validation failure
|
|
102
|
+
// For testing: change the archive to trigger state_mismatch validation failure.
|
|
103
|
+
// If there's a last block proposal, use its (already invalid) archive to keep signatures consistent
|
|
104
|
+
// so P2P validation passes and the slasher can detect the offense.
|
|
103
105
|
if (options.broadcastInvalidCheckpointProposal) {
|
|
104
|
-
archive = Fr.random();
|
|
106
|
+
archive = lastBlockProposal?.archiveRoot ?? Fr.random();
|
|
105
107
|
this.log.warn(`Creating INVALID checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
106
108
|
}
|
|
107
109
|
|
|
@@ -111,15 +113,13 @@ export class ValidationService {
|
|
|
111
113
|
return this.keyStore.signMessageWithAddress(address, payload, context);
|
|
112
114
|
};
|
|
113
115
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return CheckpointProposal.createProposalFromSigner(checkpointHeader, archive, lastBlock, payloadSigner);
|
|
116
|
+
return CheckpointProposal.createProposalFromSigner(
|
|
117
|
+
checkpointHeader,
|
|
118
|
+
archive,
|
|
119
|
+
feeAssetPriceModifier,
|
|
120
|
+
lastBlockProposal,
|
|
121
|
+
payloadSigner,
|
|
122
|
+
);
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
/**
|
|
@@ -137,22 +137,16 @@ export class ValidationService {
|
|
|
137
137
|
attestors: EthAddress[],
|
|
138
138
|
): Promise<CheckpointAttestation[]> {
|
|
139
139
|
// Create the attestation payload from the checkpoint proposal
|
|
140
|
-
const payload = new ConsensusPayload(proposal.checkpointHeader, proposal.archive);
|
|
140
|
+
const payload = new ConsensusPayload(proposal.checkpointHeader, proposal.archive, proposal.feeAssetPriceModifier);
|
|
141
141
|
const buf = Buffer32.fromBuffer(
|
|
142
142
|
keccak256(payload.getPayloadToSign(SignatureDomainSeparator.checkpointAttestation)),
|
|
143
143
|
);
|
|
144
144
|
|
|
145
145
|
// TODO(spy/ha): Use checkpointNumber instead of blockNumber once CheckpointHeader includes it.
|
|
146
|
-
//
|
|
146
|
+
// CheckpointProposalCore doesn't have lastBlock info, so use 0 as a proxy.
|
|
147
147
|
// blockNumber is NOT used for the primary key so it's safe to use here.
|
|
148
148
|
// See CheckpointHeader TODO and SigningContext types documentation.
|
|
149
|
-
|
|
150
|
-
try {
|
|
151
|
-
blockNumber = proposal.blockNumber;
|
|
152
|
-
} catch {
|
|
153
|
-
// Checkpoint proposal may not have lastBlock, use 0 as fallback
|
|
154
|
-
blockNumber = BlockNumber(0);
|
|
155
|
-
}
|
|
149
|
+
const blockNumber = BlockNumber(0);
|
|
156
150
|
const context: SigningContext = {
|
|
157
151
|
slot: proposal.slotNumber,
|
|
158
152
|
blockNumber,
|
|
@@ -176,7 +170,7 @@ export class ValidationService {
|
|
|
176
170
|
} else {
|
|
177
171
|
const error = result.reason;
|
|
178
172
|
if (error instanceof DutyAlreadySignedError || error instanceof SlashingProtectionError) {
|
|
179
|
-
this.log.
|
|
173
|
+
this.log.verbose(
|
|
180
174
|
`Attestation for slot ${proposal.slotNumber} by ${attestors[i]} already signed by another High-Availability node`,
|
|
181
175
|
);
|
|
182
176
|
// Continue with remaining attestors
|
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
|
|
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,9 @@ 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,
|
|
32
35
|
});
|
|
33
|
-
return new
|
|
36
|
+
return new ProposalHandler(
|
|
34
37
|
deps.checkpointsBuilder,
|
|
35
38
|
deps.worldState,
|
|
36
39
|
deps.blockSource,
|
|
@@ -39,6 +42,7 @@ export function createBlockProposalHandler(
|
|
|
39
42
|
blockProposalValidator,
|
|
40
43
|
deps.epochCache,
|
|
41
44
|
config,
|
|
45
|
+
deps.blobClient,
|
|
42
46
|
metrics,
|
|
43
47
|
deps.dateProvider,
|
|
44
48
|
deps.telemetry,
|
|
@@ -58,6 +62,7 @@ export function createValidatorClient(
|
|
|
58
62
|
epochCache: EpochCache;
|
|
59
63
|
keyStoreManager: KeystoreManager | undefined;
|
|
60
64
|
blobClient: BlobClientInterface;
|
|
65
|
+
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
61
66
|
},
|
|
62
67
|
) {
|
|
63
68
|
if (config.disableValidator || !deps.keyStoreManager) {
|
|
@@ -78,5 +83,6 @@ export function createValidatorClient(
|
|
|
78
83
|
deps.blobClient,
|
|
79
84
|
deps.dateProvider,
|
|
80
85
|
deps.telemetry,
|
|
86
|
+
deps.slashingProtectionDb,
|
|
81
87
|
);
|
|
82
88
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
export * from './
|
|
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';
|
|
5
5
|
export * from './validator.js';
|
|
6
6
|
export * from './key_store/index.js';
|
|
7
|
-
export * from './tx_validator/index.js';
|
|
@@ -240,7 +240,7 @@ export class HAKeyStore implements ExtendedValidatorKeyStore {
|
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
if (error instanceof SlashingProtectionError) {
|
|
243
|
-
this.log.
|
|
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,
|
|
@@ -256,8 +256,8 @@ export class HAKeyStore implements ExtendedValidatorKeyStore {
|
|
|
256
256
|
/**
|
|
257
257
|
* Start the high-availability key store
|
|
258
258
|
*/
|
|
259
|
-
public start()
|
|
260
|
-
|
|
259
|
+
public async start() {
|
|
260
|
+
await this.haSigner.start();
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
/**
|