-
Notifications
You must be signed in to change notification settings - Fork 615
Expand file tree
/
Copy pathvalidator.ts
More file actions
199 lines (169 loc) · 7.68 KB
/
Copy pathvalidator.ts
File metadata and controls
199 lines (169 loc) · 7.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import type { CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
import type { SecretValue } from '@aztec/foundation/config';
import { Fr } from '@aztec/foundation/curves/bn254';
import type { EthAddress } from '@aztec/foundation/eth-address';
import type { Signature } from '@aztec/foundation/eth-signature';
import { schemas, zodFor } from '@aztec/foundation/schemas';
import type { SequencerConfig, SlasherConfig } from '@aztec/stdlib/interfaces/server';
import type {
BlockProposal,
BlockProposalOptions,
CheckpointAttestation,
CheckpointProposal,
CheckpointProposalOptions,
} from '@aztec/stdlib/p2p';
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
import type { PeerId } from '@libp2p/interface';
import { z } from 'zod';
import type { CommitteeAttestationsAndSigners } from '../block/index.js';
import type { ChainConfig } from '../config/chain-config.js';
import {
type LocalSignerConfig,
LocalSignerConfigSchema,
type ValidatorHASignerConfig,
ValidatorHASignerConfigSchema,
} from '../ha-signing/index.js';
import { AllowedElementSchema } from './allowed_element.js';
/**
* Validator client configuration
*/
export type ValidatorClientConfig = ValidatorHASignerConfig &
LocalSignerConfig & {
/** The L1 chain id used for EIP-712 proposal-path signing. */
l1ChainId: ChainConfig['l1ChainId'];
/** The private keys of the validators participating in attestation duties */
validatorPrivateKeys?: SecretValue<`0x${string}`[]>;
/** The addresses of the validators to use with remote signers */
validatorAddresses?: EthAddress[];
/** Do not run the validator */
disableValidator: boolean;
/** Temporarily disable these specific validator addresses */
disabledValidators: EthAddress[];
/** Interval between polling for new attestations from peers */
attestationPollingIntervalMs: number;
/** Whether to always reexecute block proposals, even for non-validator nodes or when out of the current committee */
alwaysReexecuteBlockProposals?: boolean;
/** Whether to run in fisherman mode: validates all proposals and attestations but does not broadcast attestations or participate in consensus */
fishermanMode?: boolean;
/** Skip checkpoint proposal validation and always attest (default: false) */
skipCheckpointProposalValidation?: boolean;
/** Skip pushing re-executed blocks to archiver (default: false) */
skipPushProposedBlocksToArchiver?: boolean;
/** Agree to attest to equivocated checkpoint proposals (for testing purposes only) */
attestToEquivocatedProposals?: boolean;
/** Accept proposal validation regardless of slot timing (for testing only) */
skipProposalSlotValidation?: boolean;
/** Maximum L2 gas per block for validation. Proposals exceeding this limit are rejected. */
validateMaxL2BlockGas?: number;
/** Maximum DA gas per block for validation. Proposals exceeding this limit are rejected. */
validateMaxDABlockGas?: number;
/** Maximum transactions per block for validation. Proposals exceeding this limit are rejected. */
validateMaxTxsPerBlock?: number;
/** Maximum transactions per checkpoint for validation. Proposals exceeding this limit are rejected. */
validateMaxTxsPerCheckpoint?: number;
};
export type ValidatorClientFullConfig = ValidatorClientConfig &
Pick<SequencerConfig, 'txPublicSetupAllowListExtend' | 'broadcastInvalidBlockProposal' | 'maxBlocksPerCheckpoint'> &
Pick<
SlasherConfig,
| 'slashBroadcastedInvalidBlockPenalty'
| 'slashDuplicateProposalPenalty'
| 'slashDuplicateAttestationPenalty'
| 'slashAttestInvalidCheckpointProposalPenalty'
> & {
/**
* Whether transactions are disabled for this node
* @remarks This should match the property in P2PConfig. It's not picked from there to avoid circular dependencies.
*/
disableTransactions?: boolean;
};
export const ValidatorClientConfigSchema = zodFor<Omit<ValidatorClientConfig, 'validatorPrivateKeys'>>()(
ValidatorHASignerConfigSchema.merge(LocalSignerConfigSchema).extend({
l1ChainId: z.number().int().nonnegative(),
validatorAddresses: z.array(schemas.EthAddress).optional(),
disableValidator: z.boolean(),
disabledValidators: z.array(schemas.EthAddress),
attestationPollingIntervalMs: z.number().min(0),
alwaysReexecuteBlockProposals: z.boolean().optional(),
fishermanMode: z.boolean().optional(),
skipCheckpointProposalValidation: z.boolean().optional(),
skipPushProposedBlocksToArchiver: z.boolean().optional(),
attestToEquivocatedProposals: z.boolean().optional(),
skipProposalSlotValidation: z.boolean().optional(),
validateMaxL2BlockGas: z.number().optional(),
validateMaxDABlockGas: z.number().optional(),
validateMaxTxsPerBlock: z.number().optional(),
validateMaxTxsPerCheckpoint: z.number().optional(),
}),
);
export const ValidatorClientFullConfigSchema = zodFor<Omit<ValidatorClientFullConfig, 'validatorPrivateKeys'>>()(
ValidatorClientConfigSchema.extend({
txPublicSetupAllowListExtend: z.array(AllowedElementSchema).optional(),
broadcastInvalidBlockProposal: z.boolean().optional(),
maxBlocksPerCheckpoint: z.number().positive().optional(),
slashBroadcastedInvalidBlockPenalty: schemas.BigInt,
slashDuplicateProposalPenalty: schemas.BigInt,
slashDuplicateAttestationPenalty: schemas.BigInt,
slashAttestInvalidCheckpointProposalPenalty: schemas.BigInt,
disableTransactions: z.boolean().optional(),
}),
);
export interface Validator {
start(): Promise<void>;
updateConfig(config: Partial<ValidatorClientFullConfig>): void;
// Block validation responsibilities
createBlockProposal(
blockHeader: BlockHeader,
checkpointNumber: CheckpointNumber,
indexWithinCheckpoint: number,
inHash: Fr,
archive: Fr,
txs: Tx[],
proposerAddress: EthAddress | undefined,
options: BlockProposalOptions,
): Promise<BlockProposal | undefined>;
/** Creates a checkpoint proposal for the last block in a checkpoint */
createCheckpointProposal(
checkpointHeader: CheckpointHeader,
archive: Fr,
checkpointNumber: CheckpointNumber,
feeAssetPriceModifier: bigint,
lastBlockProposal: BlockProposal | undefined,
proposerAddress: EthAddress | undefined,
options: CheckpointProposalOptions,
): Promise<CheckpointProposal>;
/**
* Validate a block proposal from a peer.
* Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
* @returns true if the proposal is valid, false otherwise
*/
validateBlockProposal(proposal: BlockProposal, sender: PeerId): Promise<boolean>;
/**
* Validate and attest to a checkpoint proposal from a peer.
* @returns Checkpoint attestations if valid, undefined otherwise
*/
attestToCheckpointProposal(
proposal: CheckpointProposal,
sender: PeerId,
): Promise<CheckpointAttestation[] | undefined>;
broadcastBlockProposal(proposal: BlockProposal): Promise<void>;
/** Collect own attestations for a checkpoint proposal (used when skipping p2p attestation collection) */
collectOwnAttestations(
proposal: CheckpointProposal,
checkpointNumber: CheckpointNumber,
): Promise<CheckpointAttestation[]>;
/** Collect attestations from the p2p network for a checkpoint proposal */
collectAttestations(
proposal: CheckpointProposal,
required: number,
deadline: Date,
checkpointNumber: CheckpointNumber,
): Promise<CheckpointAttestation[]>;
signAttestationsAndSigners(
attestationsAndSigners: CommitteeAttestationsAndSigners,
proposer: EthAddress,
slot: SlotNumber,
checkpointNumber: CheckpointNumber,
): Promise<Signature>;
}