@aztec/validator-client 0.0.1-commit.592b9384 → 0.0.1-commit.59a0419c6
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 +60 -18
- package/dest/checkpoint_builder.d.ts +21 -8
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +124 -46
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +26 -6
- package/dest/duties/validation_service.d.ts +7 -9
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +15 -33
- 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 +14 -2
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +24 -0
- package/dest/proposal_handler.d.ts +108 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/proposal_handler.js +974 -0
- package/dest/validator.d.ts +45 -23
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +193 -199
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +142 -39
- package/src/config.ts +26 -6
- package/src/duties/validation_service.ts +25 -37
- package/src/factory.ts +10 -3
- package/src/index.ts +1 -2
- package/src/key_store/ha_key_store.ts +3 -3
- package/src/metrics.ts +37 -1
- package/src/proposal_handler.ts +1042 -0
- package/src/validator.ts +269 -227
- package/dest/block_proposal_handler.d.ts +0 -63
- package/dest/block_proposal_handler.d.ts.map +0 -1
- package/dest/block_proposal_handler.js +0 -546
- 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 -19
- 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 -555
- 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 -154
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/validator-client",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.59a0419c6",
|
|
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.
|
|
68
|
-
"@aztec/blob-lib": "0.0.1-commit.
|
|
69
|
-
"@aztec/constants": "0.0.1-commit.
|
|
70
|
-
"@aztec/epoch-cache": "0.0.1-commit.
|
|
71
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
72
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
73
|
-
"@aztec/node-keystore": "0.0.1-commit.
|
|
74
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
75
|
-
"@aztec/p2p": "0.0.1-commit.
|
|
76
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
77
|
-
"@aztec/prover-client": "0.0.1-commit.
|
|
78
|
-
"@aztec/simulator": "0.0.1-commit.
|
|
79
|
-
"@aztec/slasher": "0.0.1-commit.
|
|
80
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
81
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
82
|
-
"@aztec/validator-ha-signer": "0.0.1-commit.
|
|
67
|
+
"@aztec/blob-client": "0.0.1-commit.59a0419c6",
|
|
68
|
+
"@aztec/blob-lib": "0.0.1-commit.59a0419c6",
|
|
69
|
+
"@aztec/constants": "0.0.1-commit.59a0419c6",
|
|
70
|
+
"@aztec/epoch-cache": "0.0.1-commit.59a0419c6",
|
|
71
|
+
"@aztec/ethereum": "0.0.1-commit.59a0419c6",
|
|
72
|
+
"@aztec/foundation": "0.0.1-commit.59a0419c6",
|
|
73
|
+
"@aztec/node-keystore": "0.0.1-commit.59a0419c6",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.59a0419c6",
|
|
75
|
+
"@aztec/p2p": "0.0.1-commit.59a0419c6",
|
|
76
|
+
"@aztec/protocol-contracts": "0.0.1-commit.59a0419c6",
|
|
77
|
+
"@aztec/prover-client": "0.0.1-commit.59a0419c6",
|
|
78
|
+
"@aztec/simulator": "0.0.1-commit.59a0419c6",
|
|
79
|
+
"@aztec/slasher": "0.0.1-commit.59a0419c6",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.59a0419c6",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.59a0419c6",
|
|
82
|
+
"@aztec/validator-ha-signer": "0.0.1-commit.59a0419c6",
|
|
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.
|
|
90
|
-
"@aztec/world-state": "0.0.1-commit.
|
|
89
|
+
"@aztec/archiver": "0.0.1-commit.59a0419c6",
|
|
90
|
+
"@aztec/world-state": "0.0.1-commit.59a0419c6",
|
|
91
91
|
"@electric-sql/pglite": "^0.3.14",
|
|
92
92
|
"@jest/globals": "^30.0.0",
|
|
93
93
|
"@types/jest": "^30.0.0",
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { NUM_CHECKPOINT_END_MARKER_FIELDS, getNumBlockEndBlobFields } from '@aztec/blob-lib/encoding';
|
|
2
|
+
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB, MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT } from '@aztec/constants';
|
|
1
3
|
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { merge, pick } from '@aztec/foundation/collection';
|
|
4
|
+
import { merge, pick, sum } from '@aztec/foundation/collection';
|
|
3
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
6
|
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
5
7
|
import { bufferToHex } from '@aztec/foundation/string';
|
|
6
8
|
import { DateProvider, elapsed } from '@aztec/foundation/timer';
|
|
7
|
-
import { getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
|
|
9
|
+
import { createTxValidatorForBlockBuilding, getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
|
|
8
10
|
import { LightweightCheckpointBuilder } from '@aztec/prover-client/light';
|
|
9
11
|
import {
|
|
10
12
|
GuardedMerkleTreeOperations,
|
|
@@ -18,21 +20,22 @@ import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
|
18
20
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
19
21
|
import { Gas } from '@aztec/stdlib/gas';
|
|
20
22
|
import {
|
|
23
|
+
type BlockBuilderOptions,
|
|
21
24
|
type BuildBlockInCheckpointResult,
|
|
22
25
|
type FullNodeBlockBuilderConfig,
|
|
23
26
|
FullNodeBlockBuilderConfigKeys,
|
|
24
27
|
type ICheckpointBlockBuilder,
|
|
25
28
|
type ICheckpointsBuilder,
|
|
29
|
+
InsufficientValidTxsError,
|
|
26
30
|
type MerkleTreeWriteOperations,
|
|
27
|
-
NoValidTxsError,
|
|
28
31
|
type PublicProcessorLimits,
|
|
29
32
|
type WorldStateSynchronizer,
|
|
30
33
|
} from '@aztec/stdlib/interfaces/server';
|
|
34
|
+
import { type DebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
31
35
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
32
36
|
import { type CheckpointGlobalVariables, GlobalVariables, StateReference, Tx } from '@aztec/stdlib/tx';
|
|
33
37
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
34
|
-
|
|
35
|
-
import { createValidatorForBlockBuilding } from './tx_validator/tx_validator_factory.js';
|
|
38
|
+
import { ForkCheckpoint } from '@aztec/world-state';
|
|
36
39
|
|
|
37
40
|
// Re-export for backward compatibility
|
|
38
41
|
export type { BuildBlockInCheckpointResult } from '@aztec/stdlib/interfaces/server';
|
|
@@ -44,6 +47,9 @@ export type { BuildBlockInCheckpointResult } from '@aztec/stdlib/interfaces/serv
|
|
|
44
47
|
export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
45
48
|
private log: Logger;
|
|
46
49
|
|
|
50
|
+
/** Persistent contracts DB shared across all blocks in this checkpoint. */
|
|
51
|
+
protected contractsDB: PublicContractsDB;
|
|
52
|
+
|
|
47
53
|
constructor(
|
|
48
54
|
private checkpointBuilder: LightweightCheckpointBuilder,
|
|
49
55
|
private fork: MerkleTreeWriteOperations,
|
|
@@ -52,11 +58,13 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
52
58
|
private dateProvider: DateProvider,
|
|
53
59
|
private telemetryClient: TelemetryClient,
|
|
54
60
|
bindings?: LoggerBindings,
|
|
61
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
55
62
|
) {
|
|
56
63
|
this.log = createLogger('checkpoint-builder', {
|
|
57
64
|
...bindings,
|
|
58
65
|
instanceId: `checkpoint-${checkpointBuilder.checkpointNumber}`,
|
|
59
66
|
});
|
|
67
|
+
this.contractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings());
|
|
60
68
|
}
|
|
61
69
|
|
|
62
70
|
getConstantData(): CheckpointGlobalVariables {
|
|
@@ -65,12 +73,13 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
65
73
|
|
|
66
74
|
/**
|
|
67
75
|
* Builds a single block within this checkpoint.
|
|
76
|
+
* Automatically caps gas and blob field limits based on checkpoint-level budgets and prior blocks.
|
|
68
77
|
*/
|
|
69
78
|
async buildBlock(
|
|
70
79
|
pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
71
80
|
blockNumber: BlockNumber,
|
|
72
81
|
timestamp: bigint,
|
|
73
|
-
opts:
|
|
82
|
+
opts: BlockBuilderOptions & { expectedEndState?: StateReference },
|
|
74
83
|
): Promise<BuildBlockInCheckpointResult> {
|
|
75
84
|
const slot = this.checkpointBuilder.constants.slotNumber;
|
|
76
85
|
|
|
@@ -94,39 +103,60 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
94
103
|
});
|
|
95
104
|
const { processor, validator } = await this.makeBlockBuilderDeps(globalVariables, this.fork);
|
|
96
105
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
// (only the first block in a checkpoint can be empty)
|
|
103
|
-
if (processedTxs.length === 0 && this.checkpointBuilder.getBlockCount() > 0) {
|
|
104
|
-
throw new NoValidTxsError(failedTxs);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Add block to checkpoint
|
|
108
|
-
const block = await this.checkpointBuilder.addBlock(globalVariables, processedTxs, {
|
|
109
|
-
expectedEndState: opts.expectedEndState,
|
|
110
|
-
});
|
|
106
|
+
// Cap gas limits amd available blob fields by remaining checkpoint-level budgets
|
|
107
|
+
const cappedOpts: PublicProcessorLimits & { expectedEndState?: StateReference } = {
|
|
108
|
+
...opts,
|
|
109
|
+
...this.capLimitsByCheckpointBudgets(opts),
|
|
110
|
+
};
|
|
111
111
|
|
|
112
|
-
//
|
|
113
|
-
|
|
112
|
+
// Create a block-level checkpoint on the contracts DB so we can roll back on failure
|
|
113
|
+
this.contractsDB.createCheckpoint();
|
|
114
|
+
// We execute all merkle tree operations on a world state fork checkpoint
|
|
115
|
+
// This enables us to discard all modifications in the event that we fail to successfully process sufficient transactions
|
|
116
|
+
const forkCheckpoint = await ForkCheckpoint.new(this.fork);
|
|
114
117
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
});
|
|
118
|
+
try {
|
|
119
|
+
const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(() =>
|
|
120
|
+
processor.process(pendingTxs, cappedOpts, validator),
|
|
121
|
+
);
|
|
120
122
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
123
|
+
// Throw before updating state if we don't have enough valid txs
|
|
124
|
+
const minValidTxs = opts.minValidTxs ?? 0;
|
|
125
|
+
if (processedTxs.length < minValidTxs) {
|
|
126
|
+
throw new InsufficientValidTxsError(processedTxs.length, minValidTxs, failedTxs);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Commit the fork checkpoint
|
|
130
|
+
await forkCheckpoint.commit();
|
|
131
|
+
|
|
132
|
+
// Add block to checkpoint
|
|
133
|
+
const { block } = await this.checkpointBuilder.addBlock(globalVariables, processedTxs, {
|
|
134
|
+
expectedEndState: opts.expectedEndState,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
this.contractsDB.commitCheckpoint();
|
|
138
|
+
|
|
139
|
+
this.log.debug('Built block within checkpoint', {
|
|
140
|
+
header: block.header.toInspect(),
|
|
141
|
+
processedTxs: processedTxs.map(tx => tx.hash.toString()),
|
|
142
|
+
failedTxs: failedTxs.map(tx => tx.tx.txHash.toString()),
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
block,
|
|
147
|
+
publicProcessorDuration,
|
|
148
|
+
numTxs: processedTxs.length,
|
|
149
|
+
failedTxs,
|
|
150
|
+
usedTxs,
|
|
151
|
+
};
|
|
152
|
+
} catch (err) {
|
|
153
|
+
// Revert all changes to contracts db
|
|
154
|
+
this.contractsDB.revertCheckpoint();
|
|
155
|
+
// If we reached the point of committing the checkpoint, this does nothing
|
|
156
|
+
// Otherwise it reverts any changes made to the fork for this failed block
|
|
157
|
+
await forkCheckpoint.revert();
|
|
158
|
+
throw err;
|
|
159
|
+
}
|
|
130
160
|
}
|
|
131
161
|
|
|
132
162
|
/** Completes the checkpoint and returns it. */
|
|
@@ -147,11 +177,72 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
147
177
|
return this.checkpointBuilder.clone().completeCheckpoint();
|
|
148
178
|
}
|
|
149
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Caps per-block gas and blob field limits by remaining checkpoint-level budgets.
|
|
182
|
+
* When building a proposal (isBuildingProposal=true), computes a fair share of remaining budget
|
|
183
|
+
* across remaining blocks scaled by the multiplier. When validating, only caps by per-block limit
|
|
184
|
+
* and remaining checkpoint budget (no redistribution or multiplier).
|
|
185
|
+
*/
|
|
186
|
+
protected capLimitsByCheckpointBudgets(
|
|
187
|
+
opts: BlockBuilderOptions,
|
|
188
|
+
): Pick<PublicProcessorLimits, 'maxBlockGas' | 'maxBlobFields' | 'maxTransactions'> {
|
|
189
|
+
const existingBlocks = this.checkpointBuilder.getBlocks();
|
|
190
|
+
|
|
191
|
+
// Remaining L2 gas (mana)
|
|
192
|
+
// IMPORTANT: This assumes mana is computed solely based on L2 gas used in transactions.
|
|
193
|
+
// This may change in the future.
|
|
194
|
+
const usedMana = sum(existingBlocks.map(b => b.header.totalManaUsed.toNumber()));
|
|
195
|
+
const remainingMana = this.config.rollupManaLimit - usedMana;
|
|
196
|
+
|
|
197
|
+
// Remaining DA gas
|
|
198
|
+
const usedDAGas = sum(existingBlocks.map(b => b.computeDAGasUsed())) ?? 0;
|
|
199
|
+
const remainingDAGas = MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT - usedDAGas;
|
|
200
|
+
|
|
201
|
+
// Remaining blob fields (block blob fields include both tx data and block-end overhead)
|
|
202
|
+
const usedBlobFields = sum(existingBlocks.map(b => b.toBlobFields().length));
|
|
203
|
+
const totalBlobCapacity = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
|
|
204
|
+
const isFirstBlock = existingBlocks.length === 0;
|
|
205
|
+
const blockEndOverhead = getNumBlockEndBlobFields(isFirstBlock);
|
|
206
|
+
const maxBlobFieldsForTxs = totalBlobCapacity - usedBlobFields - blockEndOverhead;
|
|
207
|
+
|
|
208
|
+
// Remaining txs
|
|
209
|
+
const usedTxs = sum(existingBlocks.map(b => b.body.txEffects.length));
|
|
210
|
+
const remainingTxs = Math.max(0, (this.config.maxTxsPerCheckpoint ?? Infinity) - usedTxs);
|
|
211
|
+
|
|
212
|
+
// Cap by per-block limit + remaining checkpoint budget
|
|
213
|
+
let cappedL2Gas = Math.min(opts.maxBlockGas?.l2Gas ?? Infinity, remainingMana);
|
|
214
|
+
let cappedDAGas = Math.min(opts.maxBlockGas?.daGas ?? Infinity, remainingDAGas);
|
|
215
|
+
let cappedBlobFields = Math.min(opts.maxBlobFields ?? Infinity, maxBlobFieldsForTxs);
|
|
216
|
+
let cappedMaxTransactions = Math.min(opts.maxTransactions ?? Infinity, remainingTxs);
|
|
217
|
+
|
|
218
|
+
// Proposer mode: further cap by fair share of remaining budget across remaining blocks
|
|
219
|
+
if (opts.isBuildingProposal) {
|
|
220
|
+
const remainingBlocks = Math.max(1, opts.maxBlocksPerCheckpoint - existingBlocks.length);
|
|
221
|
+
const multiplier = opts.perBlockAllocationMultiplier;
|
|
222
|
+
|
|
223
|
+
cappedL2Gas = Math.min(cappedL2Gas, Math.ceil((remainingMana / remainingBlocks) * multiplier));
|
|
224
|
+
cappedDAGas = Math.min(cappedDAGas, Math.ceil((remainingDAGas / remainingBlocks) * multiplier));
|
|
225
|
+
cappedBlobFields = Math.min(cappedBlobFields, Math.ceil((maxBlobFieldsForTxs / remainingBlocks) * multiplier));
|
|
226
|
+
cappedMaxTransactions = Math.min(cappedMaxTransactions, Math.ceil((remainingTxs / remainingBlocks) * multiplier));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
maxBlockGas: new Gas(cappedDAGas, cappedL2Gas),
|
|
231
|
+
maxBlobFields: cappedBlobFields,
|
|
232
|
+
maxTransactions: Number.isFinite(cappedMaxTransactions) ? cappedMaxTransactions : undefined,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
150
236
|
protected async makeBlockBuilderDeps(globalVariables: GlobalVariables, fork: MerkleTreeWriteOperations) {
|
|
151
|
-
const txPublicSetupAllowList =
|
|
152
|
-
|
|
237
|
+
const txPublicSetupAllowList = [
|
|
238
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
239
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
240
|
+
];
|
|
241
|
+
const contractsDB = this.contractsDB;
|
|
153
242
|
const guardedFork = new GuardedMerkleTreeOperations(fork);
|
|
154
243
|
|
|
244
|
+
const collectDebugLogs = this.debugLogStore.isEnabled;
|
|
245
|
+
|
|
155
246
|
const bindings = this.log.getBindings();
|
|
156
247
|
const publicTxSimulator = createPublicTxSimulatorForBlockBuilding(
|
|
157
248
|
guardedFork,
|
|
@@ -159,6 +250,7 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
159
250
|
globalVariables,
|
|
160
251
|
this.telemetryClient,
|
|
161
252
|
bindings,
|
|
253
|
+
collectDebugLogs,
|
|
162
254
|
);
|
|
163
255
|
|
|
164
256
|
const processor = new PublicProcessor(
|
|
@@ -170,9 +262,10 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
170
262
|
this.telemetryClient,
|
|
171
263
|
createLogger('simulator:public-processor', bindings),
|
|
172
264
|
this.config,
|
|
265
|
+
this.debugLogStore,
|
|
173
266
|
);
|
|
174
267
|
|
|
175
|
-
const validator =
|
|
268
|
+
const validator = createTxValidatorForBlockBuilding(
|
|
176
269
|
fork,
|
|
177
270
|
this.contractDataSource,
|
|
178
271
|
globalVariables,
|
|
@@ -197,6 +290,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
197
290
|
private contractDataSource: ContractDataSource,
|
|
198
291
|
private dateProvider: DateProvider,
|
|
199
292
|
private telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
293
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
200
294
|
) {
|
|
201
295
|
this.log = createLogger('checkpoint-builder');
|
|
202
296
|
}
|
|
@@ -215,6 +309,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
215
309
|
async startCheckpoint(
|
|
216
310
|
checkpointNumber: CheckpointNumber,
|
|
217
311
|
constants: CheckpointGlobalVariables,
|
|
312
|
+
feeAssetPriceModifier: bigint,
|
|
218
313
|
l1ToL2Messages: Fr[],
|
|
219
314
|
previousCheckpointOutHashes: Fr[],
|
|
220
315
|
fork: MerkleTreeWriteOperations,
|
|
@@ -229,6 +324,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
229
324
|
initialStateReference: stateReference.toInspect(),
|
|
230
325
|
initialArchiveRoot: bufferToHex(archiveTree.root),
|
|
231
326
|
constants,
|
|
327
|
+
feeAssetPriceModifier,
|
|
232
328
|
});
|
|
233
329
|
|
|
234
330
|
const lightweightBuilder = await LightweightCheckpointBuilder.startNewCheckpoint(
|
|
@@ -238,6 +334,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
238
334
|
previousCheckpointOutHashes,
|
|
239
335
|
fork,
|
|
240
336
|
bindings,
|
|
337
|
+
feeAssetPriceModifier,
|
|
241
338
|
);
|
|
242
339
|
|
|
243
340
|
return new CheckpointBuilder(
|
|
@@ -248,6 +345,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
248
345
|
this.dateProvider,
|
|
249
346
|
this.telemetryClient,
|
|
250
347
|
bindings,
|
|
348
|
+
this.debugLogStore,
|
|
251
349
|
);
|
|
252
350
|
}
|
|
253
351
|
|
|
@@ -257,6 +355,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
257
355
|
async openCheckpoint(
|
|
258
356
|
checkpointNumber: CheckpointNumber,
|
|
259
357
|
constants: CheckpointGlobalVariables,
|
|
358
|
+
feeAssetPriceModifier: bigint,
|
|
260
359
|
l1ToL2Messages: Fr[],
|
|
261
360
|
previousCheckpointOutHashes: Fr[],
|
|
262
361
|
fork: MerkleTreeWriteOperations,
|
|
@@ -270,6 +369,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
270
369
|
return this.startCheckpoint(
|
|
271
370
|
checkpointNumber,
|
|
272
371
|
constants,
|
|
372
|
+
feeAssetPriceModifier,
|
|
273
373
|
l1ToL2Messages,
|
|
274
374
|
previousCheckpointOutHashes,
|
|
275
375
|
fork,
|
|
@@ -284,11 +384,13 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
284
384
|
initialStateReference: stateReference.toInspect(),
|
|
285
385
|
initialArchiveRoot: bufferToHex(archiveTree.root),
|
|
286
386
|
constants,
|
|
387
|
+
feeAssetPriceModifier,
|
|
287
388
|
});
|
|
288
389
|
|
|
289
390
|
const lightweightBuilder = await LightweightCheckpointBuilder.resumeCheckpoint(
|
|
290
391
|
checkpointNumber,
|
|
291
392
|
constants,
|
|
393
|
+
feeAssetPriceModifier,
|
|
292
394
|
l1ToL2Messages,
|
|
293
395
|
previousCheckpointOutHashes,
|
|
294
396
|
fork,
|
|
@@ -304,6 +406,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
304
406
|
this.dateProvider,
|
|
305
407
|
this.telemetryClient,
|
|
306
408
|
bindings,
|
|
409
|
+
this.debugLogStore,
|
|
307
410
|
);
|
|
308
411
|
}
|
|
309
412
|
|
package/src/config.ts
CHANGED
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
secretValueConfigHelper,
|
|
7
7
|
} from '@aztec/foundation/config';
|
|
8
8
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
9
|
+
import { localSignerConfigMappings, validatorHASignerConfigMappings } from '@aztec/stdlib/ha-signing';
|
|
9
10
|
import type { ValidatorClientConfig } from '@aztec/stdlib/interfaces/server';
|
|
10
|
-
import { validatorHASignerConfigMappings } from '@aztec/validator-ha-signer/config';
|
|
11
11
|
|
|
12
12
|
export type { ValidatorClientConfig };
|
|
13
13
|
|
|
@@ -49,11 +49,6 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
|
|
|
49
49
|
description: 'Interval between polling for new attestations',
|
|
50
50
|
...numberConfigHelper(200),
|
|
51
51
|
},
|
|
52
|
-
validatorReexecute: {
|
|
53
|
-
env: 'VALIDATOR_REEXECUTE',
|
|
54
|
-
description: 'Re-execute transactions before attesting',
|
|
55
|
-
...booleanConfigHelper(true),
|
|
56
|
-
},
|
|
57
52
|
alwaysReexecuteBlockProposals: {
|
|
58
53
|
description:
|
|
59
54
|
'Whether to always reexecute block proposals, even for non-validator nodes (useful for monitoring network status).',
|
|
@@ -73,6 +68,31 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
|
|
|
73
68
|
description: 'Skip pushing re-executed blocks to archiver (default: false)',
|
|
74
69
|
defaultValue: false,
|
|
75
70
|
},
|
|
71
|
+
attestToEquivocatedProposals: {
|
|
72
|
+
description: 'Agree to attest to equivocated checkpoint proposals (for testing purposes only)',
|
|
73
|
+
...booleanConfigHelper(false),
|
|
74
|
+
},
|
|
75
|
+
validateMaxL2BlockGas: {
|
|
76
|
+
env: 'VALIDATOR_MAX_L2_BLOCK_GAS',
|
|
77
|
+
description: 'Maximum L2 block gas for validation. Proposals exceeding this limit are rejected.',
|
|
78
|
+
parseEnv: (val: string) => parseInt(val, 10),
|
|
79
|
+
},
|
|
80
|
+
validateMaxDABlockGas: {
|
|
81
|
+
env: 'VALIDATOR_MAX_DA_BLOCK_GAS',
|
|
82
|
+
description: 'Maximum DA block gas for validation. Proposals exceeding this limit are rejected.',
|
|
83
|
+
parseEnv: (val: string) => parseInt(val, 10),
|
|
84
|
+
},
|
|
85
|
+
validateMaxTxsPerBlock: {
|
|
86
|
+
env: 'VALIDATOR_MAX_TX_PER_BLOCK',
|
|
87
|
+
description: 'Maximum transactions per block for validation. Proposals exceeding this limit are rejected.',
|
|
88
|
+
parseEnv: (val: string) => parseInt(val, 10),
|
|
89
|
+
},
|
|
90
|
+
validateMaxTxsPerCheckpoint: {
|
|
91
|
+
env: 'VALIDATOR_MAX_TX_PER_CHECKPOINT',
|
|
92
|
+
description: 'Maximum transactions per checkpoint for validation. Proposals exceeding this limit are rejected.',
|
|
93
|
+
parseEnv: (val: string) => parseInt(val, 10),
|
|
94
|
+
},
|
|
95
|
+
...localSignerConfigMappings,
|
|
76
96
|
...validatorHASignerConfigMappings,
|
|
77
97
|
};
|
|
78
98
|
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BlockNumber,
|
|
3
|
-
type CheckpointNumber,
|
|
4
|
-
IndexWithinCheckpoint,
|
|
5
|
-
type SlotNumber,
|
|
6
|
-
} from '@aztec/foundation/branded-types';
|
|
1
|
+
import { type CheckpointNumber, IndexWithinCheckpoint, type SlotNumber } from '@aztec/foundation/branded-types';
|
|
7
2
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
8
3
|
import { keccak256 } from '@aztec/foundation/crypto/keccak';
|
|
9
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
@@ -11,7 +6,6 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
11
6
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
12
7
|
import { createLogger } from '@aztec/foundation/log';
|
|
13
8
|
import type { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
14
|
-
import type { CreateCheckpointProposalLastBlockData } from '@aztec/stdlib/interfaces/server';
|
|
15
9
|
import {
|
|
16
10
|
BlockProposal,
|
|
17
11
|
type BlockProposalOptions,
|
|
@@ -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,
|
|
@@ -72,6 +67,7 @@ export class ValidationService {
|
|
|
72
67
|
|
|
73
68
|
return BlockProposal.createProposalFromSigner(
|
|
74
69
|
blockHeader,
|
|
70
|
+
checkpointNumber,
|
|
75
71
|
blockIndexWithinCheckpoint,
|
|
76
72
|
inHash,
|
|
77
73
|
archive,
|
|
@@ -86,7 +82,7 @@ export class ValidationService {
|
|
|
86
82
|
*
|
|
87
83
|
* @param checkpointHeader - The checkpoint header containing aggregated data
|
|
88
84
|
* @param archive - The archive of the checkpoint
|
|
89
|
-
* @param
|
|
85
|
+
* @param lastBlockProposal - Signed block proposal for the last block in the checkpoint, or undefined
|
|
90
86
|
* @param proposerAttesterAddress - The address of the proposer
|
|
91
87
|
* @param options - Checkpoint proposal options
|
|
92
88
|
*
|
|
@@ -95,13 +91,17 @@ export class ValidationService {
|
|
|
95
91
|
public createCheckpointProposal(
|
|
96
92
|
checkpointHeader: CheckpointHeader,
|
|
97
93
|
archive: Fr,
|
|
98
|
-
|
|
94
|
+
checkpointNumber: CheckpointNumber,
|
|
95
|
+
feeAssetPriceModifier: bigint,
|
|
96
|
+
lastBlockProposal: BlockProposal | undefined,
|
|
99
97
|
proposerAttesterAddress: EthAddress | undefined,
|
|
100
98
|
options: CheckpointProposalOptions,
|
|
101
99
|
): Promise<CheckpointProposal> {
|
|
102
|
-
// For testing: change the archive to trigger state_mismatch validation failure
|
|
100
|
+
// For testing: change the archive to trigger state_mismatch validation failure.
|
|
101
|
+
// If there's a last block proposal, use its (already invalid) archive to keep signatures consistent
|
|
102
|
+
// so P2P validation passes and the slasher can detect the offense.
|
|
103
103
|
if (options.broadcastInvalidCheckpointProposal) {
|
|
104
|
-
archive = Fr.random();
|
|
104
|
+
archive = lastBlockProposal?.archiveRoot ?? Fr.random();
|
|
105
105
|
this.log.warn(`Creating INVALID checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -111,15 +111,14 @@ export class ValidationService {
|
|
|
111
111
|
return this.keyStore.signMessageWithAddress(address, payload, context);
|
|
112
112
|
};
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return CheckpointProposal.createProposalFromSigner(checkpointHeader, archive, lastBlock, payloadSigner);
|
|
114
|
+
return CheckpointProposal.createProposalFromSigner(
|
|
115
|
+
checkpointHeader,
|
|
116
|
+
archive,
|
|
117
|
+
checkpointNumber,
|
|
118
|
+
feeAssetPriceModifier,
|
|
119
|
+
lastBlockProposal,
|
|
120
|
+
payloadSigner,
|
|
121
|
+
);
|
|
123
122
|
}
|
|
124
123
|
|
|
125
124
|
/**
|
|
@@ -135,27 +134,17 @@ export class ValidationService {
|
|
|
135
134
|
async attestToCheckpointProposal(
|
|
136
135
|
proposal: CheckpointProposalCore,
|
|
137
136
|
attestors: EthAddress[],
|
|
137
|
+
checkpointNumber: CheckpointNumber,
|
|
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
|
-
// TODO(spy/ha): Use checkpointNumber instead of blockNumber once CheckpointHeader includes it.
|
|
146
|
-
// Currently using lastBlock.blockNumber as a proxy for checkpoint identification in HA signing.
|
|
147
|
-
// blockNumber is NOT used for the primary key so it's safe to use here.
|
|
148
|
-
// See CheckpointHeader TODO and SigningContext types documentation.
|
|
149
|
-
let blockNumber: BlockNumber;
|
|
150
|
-
try {
|
|
151
|
-
blockNumber = proposal.blockNumber;
|
|
152
|
-
} catch {
|
|
153
|
-
// Checkpoint proposal may not have lastBlock, use 0 as fallback
|
|
154
|
-
blockNumber = BlockNumber(0);
|
|
155
|
-
}
|
|
156
145
|
const context: SigningContext = {
|
|
157
146
|
slot: proposal.slotNumber,
|
|
158
|
-
|
|
147
|
+
checkpointNumber,
|
|
159
148
|
dutyType: DutyType.ATTESTATION,
|
|
160
149
|
};
|
|
161
150
|
|
|
@@ -176,7 +165,7 @@ export class ValidationService {
|
|
|
176
165
|
} else {
|
|
177
166
|
const error = result.reason;
|
|
178
167
|
if (error instanceof DutyAlreadySignedError || error instanceof SlashingProtectionError) {
|
|
179
|
-
this.log.
|
|
168
|
+
this.log.verbose(
|
|
180
169
|
`Attestation for slot ${proposal.slotNumber} by ${attestors[i]} already signed by another High-Availability node`,
|
|
181
170
|
);
|
|
182
171
|
// Continue with remaining attestors
|
|
@@ -194,7 +183,6 @@ export class ValidationService {
|
|
|
194
183
|
* @param attestationsAndSigners - The attestations and signers to sign
|
|
195
184
|
* @param proposer - The proposer address to sign with
|
|
196
185
|
* @param slot - The slot number for HA signing context
|
|
197
|
-
* @param blockNumber - The block or checkpoint number for HA signing context
|
|
198
186
|
* @returns signature
|
|
199
187
|
* @throws DutyAlreadySignedError if already signed by another HA node
|
|
200
188
|
* @throws SlashingProtectionError if attempting to sign different data for same slot
|
|
@@ -203,11 +191,11 @@ export class ValidationService {
|
|
|
203
191
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
204
192
|
proposer: EthAddress,
|
|
205
193
|
slot: SlotNumber,
|
|
206
|
-
|
|
194
|
+
checkpointNumber: CheckpointNumber,
|
|
207
195
|
): Promise<Signature> {
|
|
208
196
|
const context: SigningContext = {
|
|
209
197
|
slot,
|
|
210
|
-
|
|
198
|
+
checkpointNumber,
|
|
211
199
|
dutyType: DutyType.ATTESTATIONS_AND_SIGNERS,
|
|
212
200
|
};
|
|
213
201
|
|
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,9 +42,11 @@ 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,
|
|
49
|
+
undefined,
|
|
45
50
|
);
|
|
46
51
|
}
|
|
47
52
|
|
|
@@ -58,6 +63,7 @@ export function createValidatorClient(
|
|
|
58
63
|
epochCache: EpochCache;
|
|
59
64
|
keyStoreManager: KeystoreManager | undefined;
|
|
60
65
|
blobClient: BlobClientInterface;
|
|
66
|
+
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
61
67
|
},
|
|
62
68
|
) {
|
|
63
69
|
if (config.disableValidator || !deps.keyStoreManager) {
|
|
@@ -78,5 +84,6 @@ export function createValidatorClient(
|
|
|
78
84
|
deps.blobClient,
|
|
79
85
|
deps.dateProvider,
|
|
80
86
|
deps.telemetry,
|
|
87
|
+
deps.slashingProtectionDb,
|
|
81
88
|
);
|
|
82
89
|
}
|
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';
|