@aztec/validator-client 0.0.1-commit.4d3c002 → 0.0.1-commit.4d9804df
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 +12 -9
- package/dest/checkpoint_builder.d.ts +6 -4
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +16 -8
- package/dest/config.d.ts +9 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +23 -5
- package/dest/duties/validation_service.d.ts +12 -13
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +32 -38
- package/dest/factory.d.ts +4 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +16 -4
- package/dest/key_store/web3signer_key_store.d.ts +10 -2
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
- package/dest/key_store/web3signer_key_store.js +32 -41
- package/dest/metrics.d.ts +5 -1
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +12 -0
- package/dest/proposal_handler.d.ts +71 -13
- package/dest/proposal_handler.d.ts.map +1 -1
- package/dest/proposal_handler.js +400 -156
- package/dest/validator.d.ts +30 -11
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +215 -62
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +16 -7
- package/src/config.ts +31 -7
- package/src/duties/validation_service.ts +51 -47
- package/src/factory.ts +20 -1
- package/src/key_store/web3signer_key_store.ts +43 -59
- package/src/metrics.ts +18 -0
- package/src/proposal_handler.ts +466 -179
- package/src/validator.ts +281 -80
package/src/config.ts
CHANGED
|
@@ -3,15 +3,27 @@ import {
|
|
|
3
3
|
booleanConfigHelper,
|
|
4
4
|
getConfigFromMappings,
|
|
5
5
|
numberConfigHelper,
|
|
6
|
+
optionalNumberConfigHelper,
|
|
7
|
+
pickConfigMappings,
|
|
6
8
|
secretValueConfigHelper,
|
|
7
9
|
} from '@aztec/foundation/config';
|
|
8
10
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
11
|
+
import { type SequencerConfig, sharedSequencerConfigMappings } from '@aztec/stdlib/config';
|
|
9
12
|
import { localSignerConfigMappings, validatorHASignerConfigMappings } from '@aztec/stdlib/ha-signing';
|
|
10
13
|
import type { ValidatorClientConfig } from '@aztec/stdlib/interfaces/server';
|
|
11
14
|
|
|
12
15
|
export type { ValidatorClientConfig };
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Default clock-disparity tolerance (ms) for proposal/attestation receive windows, mirroring the p2p config
|
|
19
|
+
* default. Used by the validator-client validators when the merged node config does not carry the value.
|
|
20
|
+
*/
|
|
21
|
+
export const DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS = 500;
|
|
22
|
+
|
|
23
|
+
export const validatorClientConfigMappings: ConfigMappingsType<
|
|
24
|
+
ValidatorClientConfig & Pick<SequencerConfig, 'blockDurationMs'>
|
|
25
|
+
> = {
|
|
26
|
+
...pickConfigMappings(sharedSequencerConfigMappings, ['blockDurationMs']),
|
|
15
27
|
validatorPrivateKeys: {
|
|
16
28
|
env: 'VALIDATOR_PRIVATE_KEYS',
|
|
17
29
|
description: 'List of private keys of the validators participating in attestation duties',
|
|
@@ -30,6 +42,12 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
|
|
|
30
42
|
.map(address => EthAddress.fromString(address.trim())),
|
|
31
43
|
defaultValue: [],
|
|
32
44
|
},
|
|
45
|
+
l1ChainId: {
|
|
46
|
+
env: 'L1_CHAIN_ID',
|
|
47
|
+
description: 'The chain ID of the ethereum host.',
|
|
48
|
+
parseEnv: (val: string) => +val,
|
|
49
|
+
defaultValue: 31337,
|
|
50
|
+
},
|
|
33
51
|
disableValidator: {
|
|
34
52
|
env: 'VALIDATOR_DISABLED',
|
|
35
53
|
description: 'Do not run the validator',
|
|
@@ -72,25 +90,29 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
|
|
|
72
90
|
description: 'Agree to attest to equivocated checkpoint proposals (for testing purposes only)',
|
|
73
91
|
...booleanConfigHelper(false),
|
|
74
92
|
},
|
|
93
|
+
skipProposalSlotValidation: {
|
|
94
|
+
description: 'Accept proposal validation regardless of slot timing (for testing only)',
|
|
95
|
+
...booleanConfigHelper(false),
|
|
96
|
+
},
|
|
75
97
|
validateMaxL2BlockGas: {
|
|
76
98
|
env: 'VALIDATOR_MAX_L2_BLOCK_GAS',
|
|
77
99
|
description: 'Maximum L2 block gas for validation. Proposals exceeding this limit are rejected.',
|
|
78
|
-
|
|
100
|
+
...optionalNumberConfigHelper(),
|
|
79
101
|
},
|
|
80
102
|
validateMaxDABlockGas: {
|
|
81
103
|
env: 'VALIDATOR_MAX_DA_BLOCK_GAS',
|
|
82
104
|
description: 'Maximum DA block gas for validation. Proposals exceeding this limit are rejected.',
|
|
83
|
-
|
|
105
|
+
...optionalNumberConfigHelper(),
|
|
84
106
|
},
|
|
85
107
|
validateMaxTxsPerBlock: {
|
|
86
108
|
env: 'VALIDATOR_MAX_TX_PER_BLOCK',
|
|
87
109
|
description: 'Maximum transactions per block for validation. Proposals exceeding this limit are rejected.',
|
|
88
|
-
|
|
110
|
+
...optionalNumberConfigHelper(),
|
|
89
111
|
},
|
|
90
112
|
validateMaxTxsPerCheckpoint: {
|
|
91
113
|
env: 'VALIDATOR_MAX_TX_PER_CHECKPOINT',
|
|
92
114
|
description: 'Maximum transactions per checkpoint for validation. Proposals exceeding this limit are rejected.',
|
|
93
|
-
|
|
115
|
+
...optionalNumberConfigHelper(),
|
|
94
116
|
},
|
|
95
117
|
...localSignerConfigMappings,
|
|
96
118
|
...validatorHASignerConfigMappings,
|
|
@@ -101,6 +123,8 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
|
|
|
101
123
|
* Note: If an environment variable is not set, the default value is used.
|
|
102
124
|
* @returns The validator configuration.
|
|
103
125
|
*/
|
|
104
|
-
export function getProverEnvVars(): ValidatorClientConfig {
|
|
105
|
-
return getConfigFromMappings<ValidatorClientConfig
|
|
126
|
+
export function getProverEnvVars(): ValidatorClientConfig & Pick<SequencerConfig, 'blockDurationMs'> {
|
|
127
|
+
return getConfigFromMappings<ValidatorClientConfig & Pick<SequencerConfig, 'blockDurationMs'>>(
|
|
128
|
+
validatorClientConfigMappings,
|
|
129
|
+
);
|
|
106
130
|
}
|
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BlockNumber,
|
|
3
|
-
type CheckpointNumber,
|
|
4
|
-
IndexWithinCheckpoint,
|
|
5
|
-
type SlotNumber,
|
|
6
|
-
} from '@aztec/foundation/branded-types';
|
|
7
|
-
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
8
|
-
import { keccak256 } from '@aztec/foundation/crypto/keccak';
|
|
1
|
+
import { type CheckpointNumber, IndexWithinCheckpoint, type SlotNumber } from '@aztec/foundation/branded-types';
|
|
9
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
3
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
11
4
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
12
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
13
|
-
import
|
|
14
|
-
import type { CreateCheckpointProposalLastBlockData } from '@aztec/stdlib/interfaces/server';
|
|
6
|
+
import { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
15
7
|
import {
|
|
16
8
|
BlockProposal,
|
|
17
9
|
type BlockProposalOptions,
|
|
@@ -20,9 +12,10 @@ import {
|
|
|
20
12
|
type CheckpointProposalCore,
|
|
21
13
|
type CheckpointProposalOptions,
|
|
22
14
|
ConsensusPayload,
|
|
23
|
-
|
|
15
|
+
type CoordinationSignatureContext,
|
|
16
|
+
getCoordinationSignatureTypedData,
|
|
24
17
|
} from '@aztec/stdlib/p2p';
|
|
25
|
-
import
|
|
18
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
26
19
|
import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
|
|
27
20
|
import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
|
|
28
21
|
import { DutyType, type SigningContext } from '@aztec/validator-ha-signer/types';
|
|
@@ -32,6 +25,7 @@ import type { ValidatorKeyStore } from '../key_store/interface.js';
|
|
|
32
25
|
export class ValidationService {
|
|
33
26
|
constructor(
|
|
34
27
|
private keyStore: ValidatorKeyStore,
|
|
28
|
+
private signatureContext: CoordinationSignatureContext,
|
|
35
29
|
private log = createLogger('validator:validation-service'),
|
|
36
30
|
) {}
|
|
37
31
|
|
|
@@ -52,6 +46,7 @@ export class ValidationService {
|
|
|
52
46
|
*/
|
|
53
47
|
public createBlockProposal(
|
|
54
48
|
blockHeader: BlockHeader,
|
|
49
|
+
checkpointNumber: CheckpointNumber,
|
|
55
50
|
blockIndexWithinCheckpoint: IndexWithinCheckpoint,
|
|
56
51
|
inHash: Fr,
|
|
57
52
|
archive: Fr,
|
|
@@ -67,17 +62,26 @@ export class ValidationService {
|
|
|
67
62
|
|
|
68
63
|
// Create a signer that uses the appropriate address
|
|
69
64
|
const address = proposerAttesterAddress ?? this.keyStore.getAddress(0);
|
|
70
|
-
const payloadSigner = (
|
|
71
|
-
|
|
65
|
+
const payloadSigner = (
|
|
66
|
+
typedData: Parameters<ValidatorKeyStore['signTypedDataWithAddress']>[1],
|
|
67
|
+
context: SigningContext,
|
|
68
|
+
) => this.keyStore.signTypedDataWithAddress(address, typedData, context);
|
|
69
|
+
const txsSigner = (
|
|
70
|
+
typedData: Parameters<ValidatorKeyStore['signTypedDataWithAddress']>[1],
|
|
71
|
+
context: SigningContext,
|
|
72
|
+
) => this.keyStore.signTypedDataWithAddress(address, typedData, context);
|
|
72
73
|
|
|
73
74
|
return BlockProposal.createProposalFromSigner(
|
|
74
75
|
blockHeader,
|
|
76
|
+
checkpointNumber,
|
|
75
77
|
blockIndexWithinCheckpoint,
|
|
76
78
|
inHash,
|
|
77
79
|
archive,
|
|
78
80
|
txs.map(tx => tx.getTxHash()),
|
|
79
81
|
options.publishFullTxs ? txs : undefined,
|
|
82
|
+
this.signatureContext,
|
|
80
83
|
payloadSigner,
|
|
84
|
+
txsSigner,
|
|
81
85
|
);
|
|
82
86
|
}
|
|
83
87
|
|
|
@@ -86,7 +90,7 @@ export class ValidationService {
|
|
|
86
90
|
*
|
|
87
91
|
* @param checkpointHeader - The checkpoint header containing aggregated data
|
|
88
92
|
* @param archive - The archive of the checkpoint
|
|
89
|
-
* @param
|
|
93
|
+
* @param lastBlockProposal - Signed block proposal for the last block in the checkpoint, or undefined
|
|
90
94
|
* @param proposerAttesterAddress - The address of the proposer
|
|
91
95
|
* @param options - Checkpoint proposal options
|
|
92
96
|
*
|
|
@@ -95,36 +99,41 @@ export class ValidationService {
|
|
|
95
99
|
public createCheckpointProposal(
|
|
96
100
|
checkpointHeader: CheckpointHeader,
|
|
97
101
|
archive: Fr,
|
|
102
|
+
checkpointNumber: CheckpointNumber,
|
|
98
103
|
feeAssetPriceModifier: bigint,
|
|
99
|
-
|
|
104
|
+
lastBlockProposal: BlockProposal | undefined,
|
|
100
105
|
proposerAttesterAddress: EthAddress | undefined,
|
|
101
106
|
options: CheckpointProposalOptions,
|
|
102
107
|
): Promise<CheckpointProposal> {
|
|
103
|
-
// For testing:
|
|
108
|
+
// For testing: corrupt the checkpoint so observers' checkpoint validation fails.
|
|
109
|
+
//
|
|
110
|
+
// Keep `archive` aligned with `lastBlockProposal.archiveRoot` so the archive-based lookup
|
|
111
|
+
// in `validateCheckpointProposal` (`getBlockData({ archive })`) still succeeds
|
|
104
112
|
if (options.broadcastInvalidCheckpointProposal) {
|
|
105
|
-
archive = Fr.random();
|
|
113
|
+
archive = lastBlockProposal?.archiveRoot ?? Fr.random();
|
|
114
|
+
checkpointHeader = CheckpointHeader.from({
|
|
115
|
+
...checkpointHeader,
|
|
116
|
+
epochOutHash: Fr.random(),
|
|
117
|
+
});
|
|
106
118
|
this.log.warn(`Creating INVALID checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
107
119
|
}
|
|
108
120
|
|
|
109
121
|
// Create a signer that takes payload and context, and uses the appropriate address
|
|
110
|
-
const payloadSigner = (
|
|
122
|
+
const payloadSigner = (
|
|
123
|
+
typedData: Parameters<ValidatorKeyStore['signTypedDataWithAddress']>[1],
|
|
124
|
+
context: SigningContext,
|
|
125
|
+
) => {
|
|
111
126
|
const address = proposerAttesterAddress ?? this.keyStore.getAddress(0);
|
|
112
|
-
return this.keyStore.
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
// Last block to include in the proposal
|
|
116
|
-
const lastBlock = lastBlockInfo && {
|
|
117
|
-
blockHeader: lastBlockInfo.blockHeader,
|
|
118
|
-
indexWithinCheckpoint: lastBlockInfo.indexWithinCheckpoint,
|
|
119
|
-
txHashes: lastBlockInfo.txs.map(tx => tx.getTxHash()),
|
|
120
|
-
txs: options.publishFullTxs ? lastBlockInfo.txs : undefined,
|
|
127
|
+
return this.keyStore.signTypedDataWithAddress(address, typedData, context);
|
|
121
128
|
};
|
|
122
129
|
|
|
123
130
|
return CheckpointProposal.createProposalFromSigner(
|
|
124
131
|
checkpointHeader,
|
|
125
132
|
archive,
|
|
133
|
+
checkpointNumber,
|
|
126
134
|
feeAssetPriceModifier,
|
|
127
|
-
|
|
135
|
+
lastBlockProposal,
|
|
136
|
+
this.signatureContext,
|
|
128
137
|
payloadSigner,
|
|
129
138
|
);
|
|
130
139
|
}
|
|
@@ -142,29 +151,27 @@ export class ValidationService {
|
|
|
142
151
|
async attestToCheckpointProposal(
|
|
143
152
|
proposal: CheckpointProposalCore,
|
|
144
153
|
attestors: EthAddress[],
|
|
154
|
+
checkpointNumber: CheckpointNumber,
|
|
145
155
|
): Promise<CheckpointAttestation[]> {
|
|
146
156
|
// Create the attestation payload from the checkpoint proposal
|
|
147
|
-
const payload = new ConsensusPayload(
|
|
148
|
-
|
|
149
|
-
|
|
157
|
+
const payload = new ConsensusPayload(
|
|
158
|
+
proposal.checkpointHeader,
|
|
159
|
+
proposal.archive,
|
|
160
|
+
proposal.feeAssetPriceModifier,
|
|
161
|
+
this.signatureContext,
|
|
150
162
|
);
|
|
163
|
+
const typedData = getCoordinationSignatureTypedData(payload);
|
|
151
164
|
|
|
152
|
-
// TODO(spy/ha): Use checkpointNumber instead of blockNumber once CheckpointHeader includes it.
|
|
153
|
-
// CheckpointProposalCore doesn't have lastBlock info, so use 0 as a proxy.
|
|
154
|
-
// blockNumber is NOT used for the primary key so it's safe to use here.
|
|
155
|
-
// See CheckpointHeader TODO and SigningContext types documentation.
|
|
156
|
-
const blockNumber = BlockNumber(0);
|
|
157
165
|
const context: SigningContext = {
|
|
158
166
|
slot: proposal.slotNumber,
|
|
159
|
-
|
|
167
|
+
checkpointNumber,
|
|
160
168
|
dutyType: DutyType.ATTESTATION,
|
|
161
169
|
};
|
|
162
170
|
|
|
163
171
|
// Sign each attestor in parallel, catching HA errors per-attestor
|
|
164
172
|
const results = await Promise.allSettled(
|
|
165
173
|
attestors.map(async attestor => {
|
|
166
|
-
const sig = await this.keyStore.
|
|
167
|
-
// return new BlockAttestation(proposal.payload, sig, proposal.signature);
|
|
174
|
+
const sig = await this.keyStore.signTypedDataWithAddress(attestor, typedData, context);
|
|
168
175
|
return new CheckpointAttestation(payload, sig, proposal.signature);
|
|
169
176
|
}),
|
|
170
177
|
);
|
|
@@ -195,7 +202,6 @@ export class ValidationService {
|
|
|
195
202
|
* @param attestationsAndSigners - The attestations and signers to sign
|
|
196
203
|
* @param proposer - The proposer address to sign with
|
|
197
204
|
* @param slot - The slot number for HA signing context
|
|
198
|
-
* @param blockNumber - The block or checkpoint number for HA signing context
|
|
199
205
|
* @returns signature
|
|
200
206
|
* @throws DutyAlreadySignedError if already signed by another HA node
|
|
201
207
|
* @throws SlashingProtectionError if attempting to sign different data for same slot
|
|
@@ -204,17 +210,15 @@ export class ValidationService {
|
|
|
204
210
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
205
211
|
proposer: EthAddress,
|
|
206
212
|
slot: SlotNumber,
|
|
207
|
-
|
|
213
|
+
checkpointNumber: CheckpointNumber,
|
|
208
214
|
): Promise<Signature> {
|
|
209
215
|
const context: SigningContext = {
|
|
210
216
|
slot,
|
|
211
|
-
|
|
217
|
+
checkpointNumber,
|
|
212
218
|
dutyType: DutyType.ATTESTATIONS_AND_SIGNERS,
|
|
213
219
|
};
|
|
214
220
|
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
);
|
|
218
|
-
return this.keyStore.signMessageWithAddress(proposer, buf, context);
|
|
221
|
+
const typedData = getCoordinationSignatureTypedData(attestationsAndSigners);
|
|
222
|
+
return this.keyStore.signTypedDataWithAddress(proposer, typedData, context);
|
|
219
223
|
}
|
|
220
224
|
}
|
package/src/factory.ts
CHANGED
|
@@ -4,12 +4,15 @@ import type { DateProvider } from '@aztec/foundation/timer';
|
|
|
4
4
|
import type { KeystoreManager } from '@aztec/node-keystore';
|
|
5
5
|
import { BlockProposalValidator, type P2PClient } from '@aztec/p2p';
|
|
6
6
|
import type { L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
7
|
+
import type { CheckpointReexecutionTracker } from '@aztec/stdlib/checkpoint';
|
|
7
8
|
import type { ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
8
9
|
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
10
|
+
import { ConsensusTimetable } from '@aztec/stdlib/timetable';
|
|
9
11
|
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
10
12
|
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
11
13
|
|
|
12
14
|
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
15
|
+
import { DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS } from './config.js';
|
|
13
16
|
import { ValidatorMetrics } from './metrics.js';
|
|
14
17
|
import { ProposalHandler } from './proposal_handler.js';
|
|
15
18
|
import { ValidatorClient } from './validator.js';
|
|
@@ -26,12 +29,23 @@ export function createProposalHandler(
|
|
|
26
29
|
blobClient: BlobClientInterface;
|
|
27
30
|
dateProvider: DateProvider;
|
|
28
31
|
telemetry: TelemetryClient;
|
|
32
|
+
reexecutionTracker: CheckpointReexecutionTracker;
|
|
29
33
|
},
|
|
30
34
|
) {
|
|
31
35
|
const metrics = new ValidatorMetrics(deps.telemetry);
|
|
32
|
-
const
|
|
36
|
+
const consensusTimetable = new ConsensusTimetable({
|
|
37
|
+
l1Constants: deps.epochCache.getL1Constants(),
|
|
38
|
+
blockDuration: config.blockDurationMs / 1000,
|
|
39
|
+
});
|
|
40
|
+
const blockProposalValidator = new BlockProposalValidator(deps.epochCache, consensusTimetable, {
|
|
33
41
|
txsPermitted: !config.disableTransactions,
|
|
34
42
|
maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
|
|
43
|
+
maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
|
|
44
|
+
signatureContext: {
|
|
45
|
+
chainId: config.l1ChainId,
|
|
46
|
+
rollupAddress: config.rollupAddress,
|
|
47
|
+
},
|
|
48
|
+
clockDisparityMs: config.maxGossipClockDisparityMs ?? DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS,
|
|
35
49
|
});
|
|
36
50
|
return new ProposalHandler(
|
|
37
51
|
deps.checkpointsBuilder,
|
|
@@ -41,11 +55,14 @@ export function createProposalHandler(
|
|
|
41
55
|
deps.p2pClient.getTxProvider(),
|
|
42
56
|
blockProposalValidator,
|
|
43
57
|
deps.epochCache,
|
|
58
|
+
consensusTimetable,
|
|
44
59
|
config,
|
|
45
60
|
deps.blobClient,
|
|
61
|
+
deps.reexecutionTracker,
|
|
46
62
|
metrics,
|
|
47
63
|
deps.dateProvider,
|
|
48
64
|
deps.telemetry,
|
|
65
|
+
undefined,
|
|
49
66
|
);
|
|
50
67
|
}
|
|
51
68
|
|
|
@@ -62,6 +79,7 @@ export function createValidatorClient(
|
|
|
62
79
|
epochCache: EpochCache;
|
|
63
80
|
keyStoreManager: KeystoreManager | undefined;
|
|
64
81
|
blobClient: BlobClientInterface;
|
|
82
|
+
reexecutionTracker: CheckpointReexecutionTracker;
|
|
65
83
|
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
66
84
|
},
|
|
67
85
|
) {
|
|
@@ -81,6 +99,7 @@ export function createValidatorClient(
|
|
|
81
99
|
txProvider,
|
|
82
100
|
deps.keyStoreManager,
|
|
83
101
|
deps.blobClient,
|
|
102
|
+
deps.reexecutionTracker,
|
|
84
103
|
deps.dateProvider,
|
|
85
104
|
deps.telemetry,
|
|
86
105
|
deps.slashingProtectionDb,
|
|
@@ -8,6 +8,9 @@ import type { TypedDataDefinition } from 'viem';
|
|
|
8
8
|
|
|
9
9
|
import type { ValidatorKeyStore } from './interface.js';
|
|
10
10
|
|
|
11
|
+
/** Default hard timeout (ms) applied to each Web3Signer HTTP request. */
|
|
12
|
+
const DEFAULT_WEB3SIGNER_REQUEST_TIMEOUT_MS = 30_000;
|
|
13
|
+
|
|
11
14
|
/**
|
|
12
15
|
* Web3Signer Key Store
|
|
13
16
|
*
|
|
@@ -15,10 +18,15 @@ import type { ValidatorKeyStore } from './interface.js';
|
|
|
15
18
|
* This implementation uses the Web3Signer JSON-RPC API for secp256k1 signatures.
|
|
16
19
|
*/
|
|
17
20
|
export class Web3SignerKeyStore implements ValidatorKeyStore {
|
|
21
|
+
private readonly requestTimeoutMs: number;
|
|
22
|
+
|
|
18
23
|
constructor(
|
|
19
24
|
private addresses: EthAddress[],
|
|
20
25
|
private baseUrl: string,
|
|
21
|
-
|
|
26
|
+
requestTimeoutMs: number = DEFAULT_WEB3SIGNER_REQUEST_TIMEOUT_MS,
|
|
27
|
+
) {
|
|
28
|
+
this.requestTimeoutMs = requestTimeoutMs;
|
|
29
|
+
}
|
|
22
30
|
|
|
23
31
|
/**
|
|
24
32
|
* Get the address of a signer by index
|
|
@@ -108,75 +116,50 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
|
|
|
108
116
|
* @param data - The data to sign
|
|
109
117
|
* @returns The signature
|
|
110
118
|
*/
|
|
111
|
-
private
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
// Use JSON-RPC eth_sign method which automatically applies Ethereum message prefixing
|
|
115
|
-
const body = {
|
|
119
|
+
private makeJsonRpcSignRequest(address: EthAddress, data: Buffer32): Promise<Signature> {
|
|
120
|
+
// eth_sign automatically applies Ethereum message prefixing to the raw data.
|
|
121
|
+
return this.sendSignRequest({
|
|
116
122
|
jsonrpc: '2.0',
|
|
117
123
|
method: 'eth_sign',
|
|
118
|
-
params: [
|
|
119
|
-
address.toString(), // Ethereum address as identifier
|
|
120
|
-
data.toString(), // Raw data to sign (eth_sign will apply Ethereum message prefix)
|
|
121
|
-
],
|
|
124
|
+
params: [address.toString(), data.toString()],
|
|
122
125
|
id: 1,
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const response = await fetch(url, {
|
|
126
|
-
method: 'POST',
|
|
127
|
-
headers: {
|
|
128
|
-
'Content-Type': 'application/json',
|
|
129
|
-
},
|
|
130
|
-
body: JSON.stringify(body),
|
|
131
126
|
});
|
|
132
|
-
|
|
133
|
-
if (!response.ok) {
|
|
134
|
-
const errorText = await response.text();
|
|
135
|
-
throw new Error(`Web3Signer request failed: ${response.status} ${response.statusText} - ${errorText}`);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const result = await response.json();
|
|
139
|
-
|
|
140
|
-
// Handle JSON-RPC response format
|
|
141
|
-
if (result.error) {
|
|
142
|
-
throw new Error(`Web3Signer JSON-RPC error: ${result.error.code} - ${result.error.message}`);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (!result.result) {
|
|
146
|
-
throw new Error('Invalid response from Web3Signer: no result found');
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
let signatureHex = result.result;
|
|
150
|
-
|
|
151
|
-
// Ensure the signature has the 0x prefix
|
|
152
|
-
if (!signatureHex.startsWith('0x')) {
|
|
153
|
-
signatureHex = '0x' + signatureHex;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// Parse the signature from the hex string
|
|
157
|
-
return normalizeSignature(Signature.fromString(signatureHex as `0x${string}`));
|
|
158
127
|
}
|
|
159
128
|
|
|
160
|
-
private
|
|
161
|
-
|
|
162
|
-
typedData: TypedDataDefinition,
|
|
163
|
-
): Promise<Signature> {
|
|
164
|
-
const url = this.baseUrl;
|
|
165
|
-
|
|
166
|
-
const body = {
|
|
129
|
+
private makeJsonRpcSignTypedDataRequest(address: EthAddress, typedData: TypedDataDefinition): Promise<Signature> {
|
|
130
|
+
return this.sendSignRequest({
|
|
167
131
|
jsonrpc: '2.0',
|
|
168
132
|
method: 'eth_signTypedData',
|
|
169
133
|
params: [address.toString(), JSON.stringify(typedData)],
|
|
170
134
|
id: 1,
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
const response = await fetch(url, {
|
|
174
|
-
method: 'POST',
|
|
175
|
-
headers: {
|
|
176
|
-
'Content-Type': 'application/json',
|
|
177
|
-
},
|
|
178
|
-
body: JSON.stringify(body),
|
|
179
135
|
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Send a JSON-RPC request to Web3Signer under a hard request timeout and parse the signature.
|
|
140
|
+
* A timed-out or aborted request is surfaced as a clear timeout error rather than hanging, so a
|
|
141
|
+
* slow or unreachable signer cannot stall an HA signing operation past its own timeout budget.
|
|
142
|
+
*/
|
|
143
|
+
private async sendSignRequest(body: object): Promise<Signature> {
|
|
144
|
+
let response: Response;
|
|
145
|
+
try {
|
|
146
|
+
response = await fetch(this.baseUrl, {
|
|
147
|
+
method: 'POST',
|
|
148
|
+
headers: {
|
|
149
|
+
'Content-Type': 'application/json',
|
|
150
|
+
},
|
|
151
|
+
body: JSON.stringify(body),
|
|
152
|
+
signal: AbortSignal.timeout(this.requestTimeoutMs),
|
|
153
|
+
});
|
|
154
|
+
} catch (err) {
|
|
155
|
+
if (
|
|
156
|
+
(err instanceof Error || err instanceof DOMException) &&
|
|
157
|
+
(err.name === 'TimeoutError' || err.name === 'AbortError')
|
|
158
|
+
) {
|
|
159
|
+
throw new Error(`Web3Signer request timed out after ${this.requestTimeoutMs}ms`);
|
|
160
|
+
}
|
|
161
|
+
throw err;
|
|
162
|
+
}
|
|
180
163
|
|
|
181
164
|
if (!response.ok) {
|
|
182
165
|
const errorText = await response.text();
|
|
@@ -185,6 +168,7 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
|
|
|
185
168
|
|
|
186
169
|
const result = await response.json();
|
|
187
170
|
|
|
171
|
+
// Handle JSON-RPC response format
|
|
188
172
|
if (result.error) {
|
|
189
173
|
throw new Error(`Web3Signer JSON-RPC error: ${result.error.code} - ${result.error.message}`);
|
|
190
174
|
}
|
package/src/metrics.ts
CHANGED
|
@@ -24,6 +24,8 @@ export class ValidatorMetrics {
|
|
|
24
24
|
private reexMana: Histogram;
|
|
25
25
|
private reexTx: Histogram;
|
|
26
26
|
private reexDuration: Gauge;
|
|
27
|
+
private checkpointProposalToPipelinedStateDuration: Histogram;
|
|
28
|
+
private checkpointProposalReceiveOffsetFromNextSlotBoundary: Histogram;
|
|
27
29
|
|
|
28
30
|
constructor(telemetryClient: TelemetryClient) {
|
|
29
31
|
const meter = telemetryClient.getMeter('Validator');
|
|
@@ -77,6 +79,12 @@ export class ValidatorMetrics {
|
|
|
77
79
|
this.reexTx = meter.createHistogram(Metrics.VALIDATOR_RE_EXECUTION_TX_COUNT);
|
|
78
80
|
|
|
79
81
|
this.reexDuration = meter.createGauge(Metrics.VALIDATOR_RE_EXECUTION_TIME);
|
|
82
|
+
this.checkpointProposalToPipelinedStateDuration = meter.createHistogram(
|
|
83
|
+
Metrics.VALIDATOR_CHECKPOINT_PROPOSAL_TO_PIPELINED_STATE_DURATION,
|
|
84
|
+
);
|
|
85
|
+
this.checkpointProposalReceiveOffsetFromNextSlotBoundary = meter.createHistogram(
|
|
86
|
+
Metrics.VALIDATOR_CHECKPOINT_PROPOSAL_RECEIVE_OFFSET_FROM_NEXT_SLOT_BOUNDARY,
|
|
87
|
+
);
|
|
80
88
|
}
|
|
81
89
|
|
|
82
90
|
public recordReex(time: number, txs: number, mManaTotal: number) {
|
|
@@ -85,6 +93,16 @@ export class ValidatorMetrics {
|
|
|
85
93
|
this.reexMana.record(mManaTotal);
|
|
86
94
|
}
|
|
87
95
|
|
|
96
|
+
public recordCheckpointProposalToPipelinedStateDuration(durationMs: number) {
|
|
97
|
+
this.checkpointProposalToPipelinedStateDuration.record(Math.ceil(durationMs));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public recordCheckpointProposalReceiveOffsetFromNextSlotBoundary(offsetMs: number) {
|
|
101
|
+
this.checkpointProposalReceiveOffsetFromNextSlotBoundary.record(Math.ceil(Math.abs(offsetMs)), {
|
|
102
|
+
[Attributes.SLOT_BOUNDARY_SIDE]: offsetMs < 0 ? 'before' : 'after',
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
88
106
|
public recordFailedReexecution(proposal: BlockProposal) {
|
|
89
107
|
const proposer = proposal.getSender();
|
|
90
108
|
this.failedReexecutionCounter.add(1, {
|