@aztec/validator-client 0.0.0-test.1 → 0.0.1-commit.1142ef1
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 +256 -0
- package/dest/block_proposal_handler.d.ts +63 -0
- package/dest/block_proposal_handler.d.ts.map +1 -0
- package/dest/block_proposal_handler.js +551 -0
- package/dest/checkpoint_builder.d.ts +70 -0
- package/dest/checkpoint_builder.d.ts.map +1 -0
- package/dest/checkpoint_builder.js +155 -0
- package/dest/config.d.ts +3 -14
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +46 -7
- package/dest/duties/validation_service.d.ts +36 -12
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +69 -16
- package/dest/factory.d.ts +27 -5
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +13 -6
- package/dest/index.d.ts +6 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +5 -1
- package/dest/key_store/index.d.ts +3 -1
- package/dest/key_store/index.d.ts.map +1 -1
- package/dest/key_store/index.js +2 -0
- package/dest/key_store/interface.d.ts +55 -6
- package/dest/key_store/interface.d.ts.map +1 -1
- package/dest/key_store/interface.js +3 -3
- package/dest/key_store/local_key_store.d.ts +41 -11
- package/dest/key_store/local_key_store.d.ts.map +1 -1
- package/dest/key_store/local_key_store.js +64 -17
- package/dest/key_store/node_keystore_adapter.d.ts +138 -0
- package/dest/key_store/node_keystore_adapter.d.ts.map +1 -0
- package/dest/key_store/node_keystore_adapter.js +316 -0
- package/dest/key_store/web3signer_key_store.d.ts +61 -0
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -0
- package/dest/key_store/web3signer_key_store.js +152 -0
- package/dest/metrics.d.ts +12 -5
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +36 -24
- package/dest/tx_validator/index.d.ts +3 -0
- package/dest/tx_validator/index.d.ts.map +1 -0
- package/dest/tx_validator/index.js +2 -0
- package/dest/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/tx_validator/nullifier_cache.js +24 -0
- package/dest/tx_validator/tx_validator_factory.d.ts +18 -0
- package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -0
- package/dest/tx_validator/tx_validator_factory.js +53 -0
- package/dest/validator.d.ts +73 -58
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +557 -166
- package/package.json +33 -21
- package/src/block_proposal_handler.ts +556 -0
- package/src/checkpoint_builder.ts +267 -0
- package/src/config.ts +58 -22
- package/src/duties/validation_service.ts +124 -18
- package/src/factory.ts +64 -11
- package/src/index.ts +5 -1
- package/src/key_store/index.ts +2 -0
- package/src/key_store/interface.ts +61 -5
- package/src/key_store/local_key_store.ts +68 -18
- package/src/key_store/node_keystore_adapter.ts +375 -0
- package/src/key_store/web3signer_key_store.ts +192 -0
- package/src/metrics.ts +48 -24
- package/src/tx_validator/index.ts +2 -0
- package/src/tx_validator/nullifier_cache.ts +30 -0
- package/src/tx_validator/tx_validator_factory.ts +133 -0
- package/src/validator.ts +749 -218
- package/dest/errors/index.d.ts +0 -2
- package/dest/errors/index.d.ts.map +0 -1
- package/dest/errors/index.js +0 -1
- package/dest/errors/validator.error.d.ts +0 -29
- package/dest/errors/validator.error.d.ts.map +0 -1
- package/dest/errors/validator.error.js +0 -45
- package/src/errors/index.ts +0 -1
- package/src/errors/validator.error.ts +0 -55
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { merge, pick } from '@aztec/foundation/collection';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
+
import { bufferToHex } from '@aztec/foundation/string';
|
|
6
|
+
import { DateProvider, Timer, elapsed } from '@aztec/foundation/timer';
|
|
7
|
+
import { getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
|
|
8
|
+
import { LightweightCheckpointBuilder } from '@aztec/prover-client/light';
|
|
9
|
+
import {
|
|
10
|
+
GuardedMerkleTreeOperations,
|
|
11
|
+
PublicContractsDB,
|
|
12
|
+
PublicProcessor,
|
|
13
|
+
createPublicTxSimulatorForBlockBuilding,
|
|
14
|
+
} from '@aztec/simulator/server';
|
|
15
|
+
import { L2BlockNew } from '@aztec/stdlib/block';
|
|
16
|
+
import { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
17
|
+
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
18
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
19
|
+
import {
|
|
20
|
+
type FullNodeBlockBuilderConfig,
|
|
21
|
+
FullNodeBlockBuilderConfigKeys,
|
|
22
|
+
type MerkleTreeWriteOperations,
|
|
23
|
+
type PublicProcessorLimits,
|
|
24
|
+
} from '@aztec/stdlib/interfaces/server';
|
|
25
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
26
|
+
import { type CheckpointGlobalVariables, type FailedTx, GlobalVariables, StateReference, Tx } from '@aztec/stdlib/tx';
|
|
27
|
+
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
28
|
+
|
|
29
|
+
import { createValidatorForBlockBuilding } from './tx_validator/tx_validator_factory.js';
|
|
30
|
+
|
|
31
|
+
const log = createLogger('checkpoint-builder');
|
|
32
|
+
|
|
33
|
+
export interface BuildBlockInCheckpointResult {
|
|
34
|
+
block: L2BlockNew;
|
|
35
|
+
publicGas: Gas;
|
|
36
|
+
publicProcessorDuration: number;
|
|
37
|
+
numTxs: number;
|
|
38
|
+
failedTxs: FailedTx[];
|
|
39
|
+
blockBuildingTimer: Timer;
|
|
40
|
+
usedTxs: Tx[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Builder for a single checkpoint. Handles building blocks within the checkpoint
|
|
45
|
+
* and completing it.
|
|
46
|
+
*/
|
|
47
|
+
export class CheckpointBuilder {
|
|
48
|
+
constructor(
|
|
49
|
+
private checkpointBuilder: LightweightCheckpointBuilder,
|
|
50
|
+
private fork: MerkleTreeWriteOperations,
|
|
51
|
+
private config: FullNodeBlockBuilderConfig,
|
|
52
|
+
private contractDataSource: ContractDataSource,
|
|
53
|
+
private dateProvider: DateProvider,
|
|
54
|
+
private telemetryClient: TelemetryClient,
|
|
55
|
+
) {}
|
|
56
|
+
|
|
57
|
+
getConstantData(): CheckpointGlobalVariables {
|
|
58
|
+
return this.checkpointBuilder.constants;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Builds a single block within this checkpoint.
|
|
63
|
+
*/
|
|
64
|
+
async buildBlock(
|
|
65
|
+
pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
66
|
+
blockNumber: BlockNumber,
|
|
67
|
+
timestamp: bigint,
|
|
68
|
+
opts: PublicProcessorLimits & { expectedEndState?: StateReference },
|
|
69
|
+
): Promise<BuildBlockInCheckpointResult> {
|
|
70
|
+
const blockBuildingTimer = new Timer();
|
|
71
|
+
const slot = this.checkpointBuilder.constants.slotNumber;
|
|
72
|
+
|
|
73
|
+
log.verbose(`Building block ${blockNumber} for slot ${slot} within checkpoint`, { slot, blockNumber, ...opts });
|
|
74
|
+
|
|
75
|
+
const constants = this.checkpointBuilder.constants;
|
|
76
|
+
const globalVariables = GlobalVariables.from({
|
|
77
|
+
chainId: constants.chainId,
|
|
78
|
+
version: constants.version,
|
|
79
|
+
blockNumber,
|
|
80
|
+
slotNumber: constants.slotNumber,
|
|
81
|
+
timestamp,
|
|
82
|
+
coinbase: constants.coinbase,
|
|
83
|
+
feeRecipient: constants.feeRecipient,
|
|
84
|
+
gasFees: constants.gasFees,
|
|
85
|
+
});
|
|
86
|
+
const { processor, validator } = await this.makeBlockBuilderDeps(globalVariables, this.fork);
|
|
87
|
+
|
|
88
|
+
const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(() =>
|
|
89
|
+
processor.process(pendingTxs, opts, validator),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// Add block to checkpoint
|
|
93
|
+
const block = await this.checkpointBuilder.addBlock(globalVariables, processedTxs, {
|
|
94
|
+
expectedEndState: opts.expectedEndState,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// How much public gas was processed
|
|
98
|
+
const publicGas = processedTxs.reduce((acc, tx) => acc.add(tx.gasUsed.publicGas), Gas.empty());
|
|
99
|
+
|
|
100
|
+
const res = {
|
|
101
|
+
block,
|
|
102
|
+
publicGas,
|
|
103
|
+
publicProcessorDuration,
|
|
104
|
+
numTxs: processedTxs.length,
|
|
105
|
+
failedTxs,
|
|
106
|
+
blockBuildingTimer,
|
|
107
|
+
usedTxs,
|
|
108
|
+
};
|
|
109
|
+
log.debug('Built block within checkpoint', res.block.header);
|
|
110
|
+
return res;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Completes the checkpoint and returns it. */
|
|
114
|
+
async completeCheckpoint(): Promise<Checkpoint> {
|
|
115
|
+
const checkpoint = await this.checkpointBuilder.completeCheckpoint();
|
|
116
|
+
|
|
117
|
+
log.verbose(`Completed checkpoint ${checkpoint.number}`, {
|
|
118
|
+
checkpointNumber: checkpoint.number,
|
|
119
|
+
numBlocks: checkpoint.blocks.length,
|
|
120
|
+
archiveRoot: checkpoint.archive.root.toString(),
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
return checkpoint;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Gets the checkpoint currently in progress. */
|
|
127
|
+
getCheckpoint(): Promise<Checkpoint> {
|
|
128
|
+
return this.checkpointBuilder.clone().completeCheckpoint();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
protected async makeBlockBuilderDeps(globalVariables: GlobalVariables, fork: MerkleTreeWriteOperations) {
|
|
132
|
+
const txPublicSetupAllowList = this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
|
|
133
|
+
const contractsDB = new PublicContractsDB(this.contractDataSource);
|
|
134
|
+
const guardedFork = new GuardedMerkleTreeOperations(fork);
|
|
135
|
+
|
|
136
|
+
const publicTxSimulator = createPublicTxSimulatorForBlockBuilding(
|
|
137
|
+
guardedFork,
|
|
138
|
+
contractsDB,
|
|
139
|
+
globalVariables,
|
|
140
|
+
this.telemetryClient,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const processor = new PublicProcessor(
|
|
144
|
+
globalVariables,
|
|
145
|
+
guardedFork,
|
|
146
|
+
contractsDB,
|
|
147
|
+
publicTxSimulator,
|
|
148
|
+
this.dateProvider,
|
|
149
|
+
this.telemetryClient,
|
|
150
|
+
undefined,
|
|
151
|
+
this.config,
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const validator = createValidatorForBlockBuilding(
|
|
155
|
+
fork,
|
|
156
|
+
this.contractDataSource,
|
|
157
|
+
globalVariables,
|
|
158
|
+
txPublicSetupAllowList,
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
return {
|
|
162
|
+
processor,
|
|
163
|
+
validator,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Factory for creating checkpoint builders.
|
|
170
|
+
*/
|
|
171
|
+
export class FullNodeCheckpointsBuilder {
|
|
172
|
+
constructor(
|
|
173
|
+
private config: FullNodeBlockBuilderConfig,
|
|
174
|
+
private contractDataSource: ContractDataSource,
|
|
175
|
+
private dateProvider: DateProvider,
|
|
176
|
+
private telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
177
|
+
) {}
|
|
178
|
+
|
|
179
|
+
public getConfig(): FullNodeBlockBuilderConfig {
|
|
180
|
+
return this.config;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
public updateConfig(config: Partial<FullNodeBlockBuilderConfig>) {
|
|
184
|
+
this.config = merge(this.config, pick(config, ...FullNodeBlockBuilderConfigKeys));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Starts a new checkpoint and returns a CheckpointBuilder to build blocks within it.
|
|
189
|
+
*/
|
|
190
|
+
async startCheckpoint(
|
|
191
|
+
checkpointNumber: CheckpointNumber,
|
|
192
|
+
constants: CheckpointGlobalVariables,
|
|
193
|
+
l1ToL2Messages: Fr[],
|
|
194
|
+
fork: MerkleTreeWriteOperations,
|
|
195
|
+
): Promise<CheckpointBuilder> {
|
|
196
|
+
const stateReference = await fork.getStateReference();
|
|
197
|
+
const archiveTree = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
198
|
+
|
|
199
|
+
log.verbose(`Building new checkpoint ${checkpointNumber}`, {
|
|
200
|
+
checkpointNumber,
|
|
201
|
+
msgCount: l1ToL2Messages.length,
|
|
202
|
+
initialStateReference: stateReference.toInspect(),
|
|
203
|
+
initialArchiveRoot: bufferToHex(archiveTree.root),
|
|
204
|
+
constants,
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const lightweightBuilder = await LightweightCheckpointBuilder.startNewCheckpoint(
|
|
208
|
+
checkpointNumber,
|
|
209
|
+
constants,
|
|
210
|
+
l1ToL2Messages,
|
|
211
|
+
fork,
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
return new CheckpointBuilder(
|
|
215
|
+
lightweightBuilder,
|
|
216
|
+
fork,
|
|
217
|
+
this.config,
|
|
218
|
+
this.contractDataSource,
|
|
219
|
+
this.dateProvider,
|
|
220
|
+
this.telemetryClient,
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Opens a checkpoint, either starting fresh or resuming from existing blocks.
|
|
226
|
+
*/
|
|
227
|
+
async openCheckpoint(
|
|
228
|
+
checkpointNumber: CheckpointNumber,
|
|
229
|
+
constants: CheckpointGlobalVariables,
|
|
230
|
+
l1ToL2Messages: Fr[],
|
|
231
|
+
fork: MerkleTreeWriteOperations,
|
|
232
|
+
existingBlocks: L2BlockNew[] = [],
|
|
233
|
+
): Promise<CheckpointBuilder> {
|
|
234
|
+
const stateReference = await fork.getStateReference();
|
|
235
|
+
const archiveTree = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
236
|
+
|
|
237
|
+
if (existingBlocks.length === 0) {
|
|
238
|
+
return this.startCheckpoint(checkpointNumber, constants, l1ToL2Messages, fork);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
log.verbose(`Resuming checkpoint ${checkpointNumber} with ${existingBlocks.length} existing blocks`, {
|
|
242
|
+
checkpointNumber,
|
|
243
|
+
msgCount: l1ToL2Messages.length,
|
|
244
|
+
existingBlockCount: existingBlocks.length,
|
|
245
|
+
initialStateReference: stateReference.toInspect(),
|
|
246
|
+
initialArchiveRoot: bufferToHex(archiveTree.root),
|
|
247
|
+
constants,
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
const lightweightBuilder = await LightweightCheckpointBuilder.resumeCheckpoint(
|
|
251
|
+
checkpointNumber,
|
|
252
|
+
constants,
|
|
253
|
+
l1ToL2Messages,
|
|
254
|
+
fork,
|
|
255
|
+
existingBlocks,
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
return new CheckpointBuilder(
|
|
259
|
+
lightweightBuilder,
|
|
260
|
+
fork,
|
|
261
|
+
this.config,
|
|
262
|
+
this.contractDataSource,
|
|
263
|
+
this.dateProvider,
|
|
264
|
+
this.telemetryClient,
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
}
|
package/src/config.ts
CHANGED
|
@@ -1,38 +1,47 @@
|
|
|
1
|
-
import { NULL_KEY } from '@aztec/ethereum';
|
|
2
1
|
import {
|
|
3
2
|
type ConfigMappingsType,
|
|
4
3
|
booleanConfigHelper,
|
|
5
4
|
getConfigFromMappings,
|
|
6
5
|
numberConfigHelper,
|
|
6
|
+
secretValueConfigHelper,
|
|
7
7
|
} from '@aztec/foundation/config';
|
|
8
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
9
|
+
import type { ValidatorClientConfig } from '@aztec/stdlib/interfaces/server';
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
* The Validator Configuration
|
|
11
|
-
*/
|
|
12
|
-
export interface ValidatorClientConfig {
|
|
13
|
-
/** The private key of the validator participating in attestation duties */
|
|
14
|
-
validatorPrivateKey?: string;
|
|
15
|
-
|
|
16
|
-
/** Do not run the validator */
|
|
17
|
-
disableValidator: boolean;
|
|
18
|
-
|
|
19
|
-
/** Interval between polling for new attestations from peers */
|
|
20
|
-
attestationPollingIntervalMs: number;
|
|
21
|
-
|
|
22
|
-
/** Re-execute transactions before attesting */
|
|
23
|
-
validatorReexecute: boolean;
|
|
24
|
-
}
|
|
11
|
+
export type { ValidatorClientConfig };
|
|
25
12
|
|
|
26
13
|
export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientConfig> = {
|
|
27
|
-
|
|
28
|
-
env: '
|
|
29
|
-
|
|
30
|
-
|
|
14
|
+
validatorPrivateKeys: {
|
|
15
|
+
env: 'VALIDATOR_PRIVATE_KEYS',
|
|
16
|
+
description: 'List of private keys of the validators participating in attestation duties',
|
|
17
|
+
...secretValueConfigHelper<`0x${string}`[]>(val =>
|
|
18
|
+
val ? val.split(',').map<`0x${string}`>(key => `0x${key.replace('0x', '')}`) : [],
|
|
19
|
+
),
|
|
20
|
+
fallback: ['VALIDATOR_PRIVATE_KEY'],
|
|
21
|
+
},
|
|
22
|
+
validatorAddresses: {
|
|
23
|
+
env: 'VALIDATOR_ADDRESSES',
|
|
24
|
+
description: 'List of addresses of the validators to use with remote signers',
|
|
25
|
+
parseEnv: (val: string) =>
|
|
26
|
+
val
|
|
27
|
+
.split(',')
|
|
28
|
+
.filter(address => address && address.trim().length > 0)
|
|
29
|
+
.map(address => EthAddress.fromString(address.trim())),
|
|
30
|
+
defaultValue: [],
|
|
31
31
|
},
|
|
32
32
|
disableValidator: {
|
|
33
33
|
env: 'VALIDATOR_DISABLED',
|
|
34
34
|
description: 'Do not run the validator',
|
|
35
|
-
...booleanConfigHelper(),
|
|
35
|
+
...booleanConfigHelper(false),
|
|
36
|
+
},
|
|
37
|
+
disabledValidators: {
|
|
38
|
+
description: 'Temporarily disable these specific validator addresses',
|
|
39
|
+
parseEnv: (val: string) =>
|
|
40
|
+
val
|
|
41
|
+
.split(',')
|
|
42
|
+
.filter(address => address && address.trim().length > 0)
|
|
43
|
+
.map(address => EthAddress.fromString(address.trim())),
|
|
44
|
+
defaultValue: [],
|
|
36
45
|
},
|
|
37
46
|
attestationPollingIntervalMs: {
|
|
38
47
|
env: 'VALIDATOR_ATTESTATIONS_POLLING_INTERVAL_MS',
|
|
@@ -44,6 +53,33 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
|
|
|
44
53
|
description: 'Re-execute transactions before attesting',
|
|
45
54
|
...booleanConfigHelper(true),
|
|
46
55
|
},
|
|
56
|
+
validatorReexecuteDeadlineMs: {
|
|
57
|
+
env: 'VALIDATOR_REEXECUTE_DEADLINE_MS',
|
|
58
|
+
description: 'Will re-execute until this many milliseconds are left in the slot',
|
|
59
|
+
...numberConfigHelper(6000),
|
|
60
|
+
},
|
|
61
|
+
alwaysReexecuteBlockProposals: {
|
|
62
|
+
env: 'ALWAYS_REEXECUTE_BLOCK_PROPOSALS',
|
|
63
|
+
description:
|
|
64
|
+
'Whether to always reexecute block proposals, even for non-validator nodes (useful for monitoring network status).',
|
|
65
|
+
...booleanConfigHelper(false),
|
|
66
|
+
},
|
|
67
|
+
fishermanMode: {
|
|
68
|
+
env: 'FISHERMAN_MODE',
|
|
69
|
+
description:
|
|
70
|
+
'Whether to run in fisherman mode: validates all proposals and attestations but does not broadcast attestations or participate in consensus.',
|
|
71
|
+
...booleanConfigHelper(false),
|
|
72
|
+
},
|
|
73
|
+
// TODO(palla/mbps): Change default to false once checkpoint validation is stable
|
|
74
|
+
skipCheckpointProposalValidation: {
|
|
75
|
+
description: 'Skip checkpoint proposal validation and always attest (default: true)',
|
|
76
|
+
defaultValue: true,
|
|
77
|
+
},
|
|
78
|
+
// TODO(palla/mbps): Change default to false once block sync is stable
|
|
79
|
+
skipPushProposedBlocksToArchiver: {
|
|
80
|
+
description: 'Skip pushing re-executed blocks to archiver (default: true)',
|
|
81
|
+
defaultValue: true,
|
|
82
|
+
},
|
|
47
83
|
};
|
|
48
84
|
|
|
49
85
|
/**
|
|
@@ -1,45 +1,151 @@
|
|
|
1
1
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
-
import { keccak256 } from '@aztec/foundation/crypto';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import type {
|
|
2
|
+
import { keccak256 } from '@aztec/foundation/crypto/keccak';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
|
+
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
6
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
7
|
+
import type { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
8
|
+
import type { CreateCheckpointProposalLastBlockData } from '@aztec/stdlib/interfaces/server';
|
|
9
|
+
import {
|
|
10
|
+
BlockProposal,
|
|
11
|
+
type BlockProposalOptions,
|
|
12
|
+
CheckpointAttestation,
|
|
13
|
+
CheckpointProposal,
|
|
14
|
+
type CheckpointProposalCore,
|
|
15
|
+
type CheckpointProposalOptions,
|
|
16
|
+
ConsensusPayload,
|
|
17
|
+
SignatureDomainSeparator,
|
|
18
|
+
} from '@aztec/stdlib/p2p';
|
|
19
|
+
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
20
|
+
import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
|
|
6
21
|
|
|
7
22
|
import type { ValidatorKeyStore } from '../key_store/interface.js';
|
|
8
23
|
|
|
9
24
|
export class ValidationService {
|
|
10
|
-
constructor(
|
|
25
|
+
constructor(
|
|
26
|
+
private keyStore: ValidatorKeyStore,
|
|
27
|
+
private log = createLogger('validator:validation-service'),
|
|
28
|
+
) {}
|
|
11
29
|
|
|
12
30
|
/**
|
|
13
31
|
* Create a block proposal with the given header, archive, and transactions
|
|
14
32
|
*
|
|
15
|
-
* @param
|
|
33
|
+
* @param blockHeader - The block header
|
|
34
|
+
* @param indexWithinCheckpoint - Index of this block within the checkpoint (0-indexed)
|
|
35
|
+
* @param inHash - Hash of L1 to L2 messages for this checkpoint
|
|
16
36
|
* @param archive - The archive of the current block
|
|
17
37
|
* @param txs - TxHash[] ordered list of transactions
|
|
38
|
+
* @param options - Block proposal options (including broadcastInvalidBlockProposal for testing)
|
|
18
39
|
*
|
|
19
|
-
* @returns A block proposal signing the above information
|
|
40
|
+
* @returns A block proposal signing the above information
|
|
20
41
|
*/
|
|
21
|
-
createBlockProposal(
|
|
22
|
-
|
|
42
|
+
public createBlockProposal(
|
|
43
|
+
blockHeader: BlockHeader,
|
|
44
|
+
indexWithinCheckpoint: number,
|
|
45
|
+
inHash: Fr,
|
|
46
|
+
archive: Fr,
|
|
47
|
+
txs: Tx[],
|
|
48
|
+
proposerAttesterAddress: EthAddress | undefined,
|
|
49
|
+
options: BlockProposalOptions,
|
|
50
|
+
): Promise<BlockProposal> {
|
|
51
|
+
const payloadSigner = this.getPayloadSigner(proposerAttesterAddress);
|
|
23
52
|
|
|
24
|
-
|
|
53
|
+
// For testing: change the new archive to trigger state_mismatch validation failure
|
|
54
|
+
if (options.broadcastInvalidBlockProposal) {
|
|
55
|
+
archive = Fr.random();
|
|
56
|
+
this.log.warn(`Creating INVALID block proposal for slot ${blockHeader.globalVariables.slotNumber}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return BlockProposal.createProposalFromSigner(
|
|
60
|
+
blockHeader,
|
|
61
|
+
indexWithinCheckpoint,
|
|
62
|
+
inHash,
|
|
63
|
+
archive,
|
|
64
|
+
txs.map(tx => tx.getTxHash()),
|
|
65
|
+
options.publishFullTxs ? txs : undefined,
|
|
66
|
+
payloadSigner,
|
|
67
|
+
);
|
|
25
68
|
}
|
|
26
69
|
|
|
27
70
|
/**
|
|
28
|
-
*
|
|
71
|
+
* Create a checkpoint proposal with the last block header and checkpoint header
|
|
72
|
+
*
|
|
73
|
+
* @param checkpointHeader - The checkpoint header containing aggregated data
|
|
74
|
+
* @param archive - The archive of the checkpoint
|
|
75
|
+
* @param lastBlockInfo - Info about the last block (header, index, txs) or undefined
|
|
76
|
+
* @param proposerAttesterAddress - The address of the proposer
|
|
77
|
+
* @param options - Checkpoint proposal options
|
|
78
|
+
*
|
|
79
|
+
* @returns A checkpoint proposal signing the above information
|
|
80
|
+
*/
|
|
81
|
+
public createCheckpointProposal(
|
|
82
|
+
checkpointHeader: CheckpointHeader,
|
|
83
|
+
archive: Fr,
|
|
84
|
+
lastBlockInfo: CreateCheckpointProposalLastBlockData | undefined,
|
|
85
|
+
proposerAttesterAddress: EthAddress | undefined,
|
|
86
|
+
options: CheckpointProposalOptions,
|
|
87
|
+
): Promise<CheckpointProposal> {
|
|
88
|
+
const payloadSigner = this.getPayloadSigner(proposerAttesterAddress);
|
|
89
|
+
|
|
90
|
+
// For testing: change the archive to trigger state_mismatch validation failure
|
|
91
|
+
if (options.broadcastInvalidCheckpointProposal) {
|
|
92
|
+
archive = Fr.random();
|
|
93
|
+
this.log.warn(`Creating INVALID checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Last block to include in the proposal
|
|
97
|
+
const lastBlock = lastBlockInfo && {
|
|
98
|
+
blockHeader: lastBlockInfo.blockHeader,
|
|
99
|
+
indexWithinCheckpoint: lastBlockInfo.indexWithinCheckpoint,
|
|
100
|
+
txHashes: lastBlockInfo.txs.map(tx => tx.getTxHash()),
|
|
101
|
+
txs: options.publishFullTxs ? lastBlockInfo.txs : undefined,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return CheckpointProposal.createProposalFromSigner(checkpointHeader, archive, lastBlock, payloadSigner);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private getPayloadSigner(proposerAttesterAddress: EthAddress | undefined): (payload: Buffer32) => Promise<Signature> {
|
|
108
|
+
if (proposerAttesterAddress !== undefined) {
|
|
109
|
+
return (payload: Buffer32) => this.keyStore.signMessageWithAddress(proposerAttesterAddress, payload);
|
|
110
|
+
} else {
|
|
111
|
+
// if there is no proposer attester address, just use the first signer
|
|
112
|
+
const signer = this.keyStore.getAddress(0);
|
|
113
|
+
return (payload: Buffer32) => this.keyStore.signMessageWithAddress(signer, payload);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Attest with selection of validators to the given checkpoint proposal
|
|
29
119
|
*
|
|
30
120
|
* NOTE: This is just a blind signing.
|
|
31
121
|
* We assume that the proposal is valid and DA guarantees have been checked previously.
|
|
32
122
|
*
|
|
33
|
-
* @param proposal - The proposal to attest to
|
|
34
|
-
* @
|
|
123
|
+
* @param proposal - The checkpoint proposal (core version without lastBlock) to attest to
|
|
124
|
+
* @param attestors - The validators to attest with
|
|
125
|
+
* @returns checkpoint attestations
|
|
35
126
|
*/
|
|
36
|
-
async
|
|
37
|
-
|
|
127
|
+
async attestToCheckpointProposal(
|
|
128
|
+
proposal: CheckpointProposalCore,
|
|
129
|
+
attestors: EthAddress[],
|
|
130
|
+
): Promise<CheckpointAttestation[]> {
|
|
131
|
+
// Create the attestation payload from the checkpoint proposal
|
|
132
|
+
const payload = new ConsensusPayload(proposal.checkpointHeader, proposal.archive);
|
|
133
|
+
const buf = Buffer32.fromBuffer(
|
|
134
|
+
keccak256(payload.getPayloadToSign(SignatureDomainSeparator.checkpointAttestation)),
|
|
135
|
+
);
|
|
136
|
+
const signatures = await Promise.all(
|
|
137
|
+
attestors.map(attestor => this.keyStore.signMessageWithAddress(attestor, buf)),
|
|
138
|
+
);
|
|
139
|
+
return signatures.map(sig => new CheckpointAttestation(payload, sig, proposal.signature));
|
|
140
|
+
}
|
|
38
141
|
|
|
142
|
+
async signAttestationsAndSigners(
|
|
143
|
+
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
144
|
+
proposer: EthAddress,
|
|
145
|
+
): Promise<Signature> {
|
|
39
146
|
const buf = Buffer32.fromBuffer(
|
|
40
|
-
keccak256(
|
|
147
|
+
keccak256(attestationsAndSigners.getPayloadToSign(SignatureDomainSeparator.attestationsAndSigners)),
|
|
41
148
|
);
|
|
42
|
-
|
|
43
|
-
return new BlockAttestation(proposal.payload, sig);
|
|
149
|
+
return await this.keyStore.signMessageWithAddress(proposer, buf);
|
|
44
150
|
}
|
|
45
151
|
}
|
package/src/factory.ts
CHANGED
|
@@ -1,28 +1,81 @@
|
|
|
1
|
+
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
1
2
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
2
3
|
import type { DateProvider } from '@aztec/foundation/timer';
|
|
3
|
-
import type {
|
|
4
|
+
import type { KeystoreManager } from '@aztec/node-keystore';
|
|
5
|
+
import { BlockProposalValidator, type P2PClient } from '@aztec/p2p';
|
|
6
|
+
import type { L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
7
|
+
import type { ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
8
|
+
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
4
9
|
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
5
10
|
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import
|
|
11
|
+
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
12
|
+
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
13
|
+
import { ValidatorMetrics } from './metrics.js';
|
|
9
14
|
import { ValidatorClient } from './validator.js';
|
|
10
15
|
|
|
16
|
+
export function createBlockProposalHandler(
|
|
17
|
+
config: ValidatorClientFullConfig,
|
|
18
|
+
deps: {
|
|
19
|
+
checkpointsBuilder: FullNodeCheckpointsBuilder;
|
|
20
|
+
worldState: WorldStateSynchronizer;
|
|
21
|
+
blockSource: L2BlockSource & L2BlockSink;
|
|
22
|
+
l1ToL2MessageSource: L1ToL2MessageSource;
|
|
23
|
+
p2pClient: P2PClient;
|
|
24
|
+
epochCache: EpochCache;
|
|
25
|
+
dateProvider: DateProvider;
|
|
26
|
+
telemetry: TelemetryClient;
|
|
27
|
+
},
|
|
28
|
+
) {
|
|
29
|
+
const metrics = new ValidatorMetrics(deps.telemetry);
|
|
30
|
+
const blockProposalValidator = new BlockProposalValidator(deps.epochCache, {
|
|
31
|
+
txsPermitted: !config.disableTransactions,
|
|
32
|
+
});
|
|
33
|
+
return new BlockProposalHandler(
|
|
34
|
+
deps.checkpointsBuilder,
|
|
35
|
+
deps.worldState,
|
|
36
|
+
deps.blockSource,
|
|
37
|
+
deps.l1ToL2MessageSource,
|
|
38
|
+
deps.p2pClient.getTxProvider(),
|
|
39
|
+
blockProposalValidator,
|
|
40
|
+
config,
|
|
41
|
+
metrics,
|
|
42
|
+
deps.dateProvider,
|
|
43
|
+
deps.telemetry,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
11
47
|
export function createValidatorClient(
|
|
12
|
-
config:
|
|
48
|
+
config: ValidatorClientFullConfig,
|
|
13
49
|
deps: {
|
|
14
|
-
|
|
50
|
+
checkpointsBuilder: FullNodeCheckpointsBuilder;
|
|
51
|
+
worldState: WorldStateSynchronizer;
|
|
52
|
+
p2pClient: P2PClient;
|
|
53
|
+
blockSource: L2BlockSource & L2BlockSink;
|
|
54
|
+
l1ToL2MessageSource: L1ToL2MessageSource;
|
|
15
55
|
telemetry: TelemetryClient;
|
|
16
56
|
dateProvider: DateProvider;
|
|
17
57
|
epochCache: EpochCache;
|
|
58
|
+
keyStoreManager: KeystoreManager | undefined;
|
|
59
|
+
blobClient: BlobClientInterface;
|
|
18
60
|
},
|
|
19
61
|
) {
|
|
20
|
-
if (config.disableValidator) {
|
|
62
|
+
if (config.disableValidator || !deps.keyStoreManager) {
|
|
21
63
|
return undefined;
|
|
22
64
|
}
|
|
23
|
-
if (config.validatorPrivateKey === undefined || config.validatorPrivateKey === '') {
|
|
24
|
-
config.validatorPrivateKey = generatePrivateKey();
|
|
25
|
-
}
|
|
26
65
|
|
|
27
|
-
|
|
66
|
+
const txProvider = deps.p2pClient.getTxProvider();
|
|
67
|
+
return ValidatorClient.new(
|
|
68
|
+
config,
|
|
69
|
+
deps.checkpointsBuilder,
|
|
70
|
+
deps.worldState,
|
|
71
|
+
deps.epochCache,
|
|
72
|
+
deps.p2pClient,
|
|
73
|
+
deps.blockSource,
|
|
74
|
+
deps.l1ToL2MessageSource,
|
|
75
|
+
txProvider,
|
|
76
|
+
deps.keyStoreManager,
|
|
77
|
+
deps.blobClient,
|
|
78
|
+
deps.dateProvider,
|
|
79
|
+
deps.telemetry,
|
|
80
|
+
);
|
|
28
81
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export * from './block_proposal_handler.js';
|
|
2
|
+
export * from './checkpoint_builder.js';
|
|
1
3
|
export * from './config.js';
|
|
2
|
-
export * from './validator.js';
|
|
3
4
|
export * from './factory.js';
|
|
5
|
+
export * from './validator.js';
|
|
6
|
+
export * from './key_store/index.js';
|
|
7
|
+
export * from './tx_validator/index.js';
|
package/src/key_store/index.ts
CHANGED