@aztec/validator-client 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0
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 +327 -0
- package/dest/checkpoint_builder.d.ts +81 -0
- package/dest/checkpoint_builder.d.ts.map +1 -0
- package/dest/checkpoint_builder.js +259 -0
- package/dest/config.d.ts +9 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +56 -14
- package/dest/duties/validation_service.d.ts +44 -16
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +102 -31
- package/dest/factory.d.ts +22 -11
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +19 -6
- package/dest/index.d.ts +3 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -1
- package/dest/key_store/ha_key_store.d.ts +99 -0
- package/dest/key_store/ha_key_store.d.ts.map +1 -0
- package/dest/key_store/ha_key_store.js +208 -0
- package/dest/key_store/index.d.ts +2 -1
- package/dest/key_store/index.d.ts.map +1 -1
- package/dest/key_store/index.js +1 -0
- package/dest/key_store/interface.d.ts +36 -6
- package/dest/key_store/interface.d.ts.map +1 -1
- package/dest/key_store/local_key_store.d.ts +10 -5
- package/dest/key_store/local_key_store.d.ts.map +1 -1
- package/dest/key_store/local_key_store.js +9 -5
- package/dest/key_store/node_keystore_adapter.d.ts +18 -5
- package/dest/key_store/node_keystore_adapter.d.ts.map +1 -1
- package/dest/key_store/node_keystore_adapter.js +18 -4
- package/dest/key_store/web3signer_key_store.d.ts +19 -6
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
- package/dest/key_store/web3signer_key_store.js +41 -46
- package/dest/metrics.d.ts +16 -3
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +58 -30
- package/dest/proposal_handler.d.ts +165 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/proposal_handler.js +1207 -0
- package/dest/validator.d.ts +93 -25
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +491 -89
- package/package.json +21 -11
- package/src/checkpoint_builder.ts +426 -0
- package/src/config.ts +63 -15
- package/src/duties/validation_service.ts +168 -41
- package/src/factory.ts +46 -12
- package/src/index.ts +2 -1
- package/src/key_store/ha_key_store.ts +269 -0
- package/src/key_store/index.ts +1 -0
- package/src/key_store/interface.ts +44 -5
- package/src/key_store/local_key_store.ts +14 -5
- package/src/key_store/node_keystore_adapter.ts +28 -5
- package/src/key_store/web3signer_key_store.ts +61 -64
- package/src/metrics.ts +81 -33
- package/src/proposal_handler.ts +1314 -0
- package/src/validator.ts +721 -139
- package/dest/block_proposal_handler.d.ts +0 -53
- package/dest/block_proposal_handler.d.ts.map +0 -1
- package/dest/block_proposal_handler.js +0 -290
- package/src/block_proposal_handler.ts +0 -344
|
@@ -3,6 +3,7 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
3
3
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
4
4
|
import type { EthRemoteSignerConfig } from '@aztec/node-keystore';
|
|
5
5
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
+
import type { SigningContext } from '@aztec/validator-ha-signer/types';
|
|
6
7
|
|
|
7
8
|
import type { TypedDataDefinition } from 'viem';
|
|
8
9
|
|
|
@@ -26,17 +27,45 @@ export interface ValidatorKeyStore {
|
|
|
26
27
|
*/
|
|
27
28
|
getAddresses(): EthAddress[];
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Sign typed data with all keystore private keys
|
|
32
|
+
* @param typedData - The complete EIP-712 typed data structure
|
|
33
|
+
* @param context - Signing context for HA slashing protection
|
|
34
|
+
* @returns signatures (when context provided with HA, only successfully claimed signatures are returned)
|
|
35
|
+
*/
|
|
36
|
+
signTypedData(typedData: TypedDataDefinition, context: SigningContext): Promise<Signature[]>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Sign typed data with a specific address's private key
|
|
40
|
+
* @param address - The address of the signer to use
|
|
41
|
+
* @param typedData - The complete EIP-712 typed data structure
|
|
42
|
+
* @param context - Signing context for HA slashing protection
|
|
43
|
+
* @returns signature
|
|
44
|
+
*/
|
|
45
|
+
signTypedDataWithAddress(
|
|
46
|
+
address: EthAddress,
|
|
47
|
+
typedData: TypedDataDefinition,
|
|
48
|
+
context: SigningContext,
|
|
49
|
+
): Promise<Signature>;
|
|
50
|
+
|
|
31
51
|
/**
|
|
32
52
|
* Flavor of sign message that followed EIP-712 eth signed message prefix
|
|
33
53
|
* Note: this is only required when we are using ecdsa signatures over secp256k1
|
|
34
54
|
*
|
|
35
55
|
* @param message - The message to sign.
|
|
36
|
-
* @
|
|
56
|
+
* @param context - Signing context for HA slashing protection
|
|
57
|
+
* @returns The signatures (when context provided with HA, only successfully claimed signatures are returned).
|
|
37
58
|
*/
|
|
38
|
-
signMessage(message: Buffer32): Promise<Signature[]>;
|
|
39
|
-
|
|
59
|
+
signMessage(message: Buffer32, context: SigningContext): Promise<Signature[]>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Sign a message with a specific address's private key
|
|
63
|
+
* @param address - The address of the signer to use
|
|
64
|
+
* @param message - The message to sign
|
|
65
|
+
* @param context - Signing context for HA slashing protection
|
|
66
|
+
* @returns signature
|
|
67
|
+
*/
|
|
68
|
+
signMessageWithAddress(address: EthAddress, message: Buffer32, context: SigningContext): Promise<Signature>;
|
|
40
69
|
}
|
|
41
70
|
|
|
42
71
|
/**
|
|
@@ -79,4 +108,14 @@ export interface ExtendedValidatorKeyStore extends ValidatorKeyStore {
|
|
|
79
108
|
* @returns the remote signer configuration or undefined
|
|
80
109
|
*/
|
|
81
110
|
getRemoteSignerConfig(attesterAddress: EthAddress): EthRemoteSignerConfig | undefined;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Start the key store
|
|
114
|
+
*/
|
|
115
|
+
start(): Promise<void>;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Stop the key store
|
|
119
|
+
*/
|
|
120
|
+
stop(): Promise<void>;
|
|
82
121
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
-
import { Secp256k1Signer } from '@aztec/foundation/crypto';
|
|
2
|
+
import { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
3
3
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
4
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
5
|
+
import type { SigningContext } from '@aztec/validator-ha-signer/types';
|
|
5
6
|
|
|
6
7
|
import { type TypedDataDefinition, hashTypedData } from 'viem';
|
|
7
8
|
|
|
@@ -46,9 +47,10 @@ export class LocalKeyStore implements ValidatorKeyStore {
|
|
|
46
47
|
/**
|
|
47
48
|
* Sign a message with all keystore private keys
|
|
48
49
|
* @param typedData - The complete EIP-712 typed data structure (domain, types, primaryType, message)
|
|
50
|
+
* @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
|
|
49
51
|
* @return signature
|
|
50
52
|
*/
|
|
51
|
-
public signTypedData(typedData: TypedDataDefinition): Promise<Signature[]> {
|
|
53
|
+
public signTypedData(typedData: TypedDataDefinition, _context: SigningContext): Promise<Signature[]> {
|
|
52
54
|
const digest = hashTypedData(typedData);
|
|
53
55
|
return Promise.all(this.signers.map(signer => signer.sign(Buffer32.fromString(digest))));
|
|
54
56
|
}
|
|
@@ -57,10 +59,15 @@ export class LocalKeyStore implements ValidatorKeyStore {
|
|
|
57
59
|
* Sign a message with a specific address's private key
|
|
58
60
|
* @param address - The address of the signer to use
|
|
59
61
|
* @param typedData - The complete EIP-712 typed data structure (domain, types, primaryType, message)
|
|
62
|
+
* @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
|
|
60
63
|
* @returns signature for the specified address
|
|
61
64
|
* @throws Error if the address is not found in the keystore
|
|
62
65
|
*/
|
|
63
|
-
public signTypedDataWithAddress(
|
|
66
|
+
public signTypedDataWithAddress(
|
|
67
|
+
address: EthAddress,
|
|
68
|
+
typedData: TypedDataDefinition,
|
|
69
|
+
_context: SigningContext,
|
|
70
|
+
): Promise<Signature> {
|
|
64
71
|
const signer = this.signersByAddress.get(address.toString());
|
|
65
72
|
if (!signer) {
|
|
66
73
|
throw new Error(`No signer found for address ${address.toString()}`);
|
|
@@ -73,9 +80,10 @@ export class LocalKeyStore implements ValidatorKeyStore {
|
|
|
73
80
|
* Sign a message using eth_sign with all keystore private keys
|
|
74
81
|
*
|
|
75
82
|
* @param message - The message to sign
|
|
83
|
+
* @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
|
|
76
84
|
* @return signatures
|
|
77
85
|
*/
|
|
78
|
-
public signMessage(message: Buffer32): Promise<Signature[]> {
|
|
86
|
+
public signMessage(message: Buffer32, _context: SigningContext): Promise<Signature[]> {
|
|
79
87
|
return Promise.all(this.signers.map(signer => signer.signMessage(message)));
|
|
80
88
|
}
|
|
81
89
|
|
|
@@ -83,10 +91,11 @@ export class LocalKeyStore implements ValidatorKeyStore {
|
|
|
83
91
|
* Sign a message using eth_sign with a specific address's private key
|
|
84
92
|
* @param address - The address of the signer to use
|
|
85
93
|
* @param message - The message to sign
|
|
94
|
+
* @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
|
|
86
95
|
* @returns signature for the specified address
|
|
87
96
|
* @throws Error if the address is not found in the keystore
|
|
88
97
|
*/
|
|
89
|
-
public signMessageWithAddress(address: EthAddress, message: Buffer32): Promise<Signature> {
|
|
98
|
+
public signMessageWithAddress(address: EthAddress, message: Buffer32, _context: SigningContext): Promise<Signature> {
|
|
90
99
|
const signer = this.signersByAddress.get(address.toString());
|
|
91
100
|
if (!signer) {
|
|
92
101
|
throw new Error(`No signer found for address ${address.toString()}`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EthSigner } from '@aztec/ethereum';
|
|
1
|
+
import type { EthSigner } from '@aztec/ethereum/eth-signer';
|
|
2
2
|
import type { Buffer32 } from '@aztec/foundation/buffer';
|
|
3
3
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
4
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
@@ -6,6 +6,7 @@ import { KeystoreManager, loadKeystoreFile } from '@aztec/node-keystore';
|
|
|
6
6
|
import type { EthRemoteSignerConfig } from '@aztec/node-keystore';
|
|
7
7
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
8
|
import { InvalidValidatorPrivateKeyError } from '@aztec/stdlib/validators';
|
|
9
|
+
import type { SigningContext } from '@aztec/validator-ha-signer/types';
|
|
9
10
|
|
|
10
11
|
import type { TypedDataDefinition } from 'viem';
|
|
11
12
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
@@ -230,9 +231,10 @@ export class NodeKeystoreAdapter implements ExtendedValidatorKeyStore {
|
|
|
230
231
|
/**
|
|
231
232
|
* Sign typed data with all attester signers across validators.
|
|
232
233
|
* @param typedData EIP-712 typed data
|
|
234
|
+
* @param _context Signing context (ignored by NodeKeystoreAdapter, used for HA protection)
|
|
233
235
|
* @returns Array of signatures in validator order, flattened
|
|
234
236
|
*/
|
|
235
|
-
async signTypedData(typedData: TypedDataDefinition): Promise<Signature[]> {
|
|
237
|
+
async signTypedData(typedData: TypedDataDefinition, _context: SigningContext): Promise<Signature[]> {
|
|
236
238
|
const jobs: Promise<Signature>[] = [];
|
|
237
239
|
for (const i of this.validatorIndices()) {
|
|
238
240
|
const v = this.ensureValidator(i);
|
|
@@ -246,9 +248,10 @@ export class NodeKeystoreAdapter implements ExtendedValidatorKeyStore {
|
|
|
246
248
|
/**
|
|
247
249
|
* Sign a message with all attester signers across validators.
|
|
248
250
|
* @param message 32-byte message (already hashed/padded as needed)
|
|
251
|
+
* @param _context Signing context (ignored by NodeKeystoreAdapter, used for HA protection)
|
|
249
252
|
* @returns Array of signatures in validator order, flattened
|
|
250
253
|
*/
|
|
251
|
-
async signMessage(message: Buffer32): Promise<Signature[]> {
|
|
254
|
+
async signMessage(message: Buffer32, _context: SigningContext): Promise<Signature[]> {
|
|
252
255
|
const jobs: Promise<Signature>[] = [];
|
|
253
256
|
for (const i of this.validatorIndices()) {
|
|
254
257
|
const v = this.ensureValidator(i);
|
|
@@ -264,10 +267,15 @@ export class NodeKeystoreAdapter implements ExtendedValidatorKeyStore {
|
|
|
264
267
|
* Hydrates caches on-demand when the address is first seen.
|
|
265
268
|
* @param address Address to sign with
|
|
266
269
|
* @param typedData EIP-712 typed data
|
|
270
|
+
* @param _context Signing context (ignored by NodeKeystoreAdapter, used for HA protection)
|
|
267
271
|
* @returns Signature from the signer matching the address
|
|
268
272
|
* @throws Error when no signer exists for the address
|
|
269
273
|
*/
|
|
270
|
-
async signTypedDataWithAddress(
|
|
274
|
+
async signTypedDataWithAddress(
|
|
275
|
+
address: EthAddress,
|
|
276
|
+
typedData: TypedDataDefinition,
|
|
277
|
+
_context: SigningContext,
|
|
278
|
+
): Promise<Signature> {
|
|
271
279
|
const entry = this.addressIndex.get(NodeKeystoreAdapter.key(address));
|
|
272
280
|
if (entry) {
|
|
273
281
|
return await this.keystoreManager.signTypedData(entry.signer, typedData);
|
|
@@ -290,10 +298,11 @@ export class NodeKeystoreAdapter implements ExtendedValidatorKeyStore {
|
|
|
290
298
|
* Hydrates caches on-demand when the address is first seen.
|
|
291
299
|
* @param address Address to sign with
|
|
292
300
|
* @param message 32-byte message
|
|
301
|
+
* @param _context Signing context (ignored by NodeKeystoreAdapter, used for HA protection)
|
|
293
302
|
* @returns Signature from the signer matching the address
|
|
294
303
|
* @throws Error when no signer exists for the address
|
|
295
304
|
*/
|
|
296
|
-
async signMessageWithAddress(address: EthAddress, message: Buffer32): Promise<Signature> {
|
|
305
|
+
async signMessageWithAddress(address: EthAddress, message: Buffer32, _context: SigningContext): Promise<Signature> {
|
|
297
306
|
const entry = this.addressIndex.get(NodeKeystoreAdapter.key(address));
|
|
298
307
|
if (entry) {
|
|
299
308
|
return await this.keystoreManager.signMessage(entry.signer, message);
|
|
@@ -372,4 +381,18 @@ export class NodeKeystoreAdapter implements ExtendedValidatorKeyStore {
|
|
|
372
381
|
const validatorIndex = this.findValidatorIndexForAttester(attesterAddress);
|
|
373
382
|
return this.keystoreManager.getEffectiveRemoteSignerConfig(validatorIndex, attesterAddress);
|
|
374
383
|
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Start the key store - no-op
|
|
387
|
+
*/
|
|
388
|
+
start(): Promise<void> {
|
|
389
|
+
return Promise.resolve();
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Stop the key store - no-op
|
|
394
|
+
*/
|
|
395
|
+
stop(): Promise<void> {
|
|
396
|
+
return Promise.resolve();
|
|
397
|
+
}
|
|
375
398
|
}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import type { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
-
import { normalizeSignature } from '@aztec/foundation/crypto';
|
|
2
|
+
import { normalizeSignature } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
3
3
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
4
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
5
|
+
import type { SigningContext } from '@aztec/validator-ha-signer/types';
|
|
5
6
|
|
|
6
7
|
import type { TypedDataDefinition } from 'viem';
|
|
7
8
|
|
|
8
9
|
import type { ValidatorKeyStore } from './interface.js';
|
|
9
10
|
|
|
11
|
+
/** Default hard timeout (ms) applied to each Web3Signer HTTP request. */
|
|
12
|
+
const DEFAULT_WEB3SIGNER_REQUEST_TIMEOUT_MS = 30_000;
|
|
13
|
+
|
|
10
14
|
/**
|
|
11
15
|
* Web3Signer Key Store
|
|
12
16
|
*
|
|
@@ -14,10 +18,15 @@ import type { ValidatorKeyStore } from './interface.js';
|
|
|
14
18
|
* This implementation uses the Web3Signer JSON-RPC API for secp256k1 signatures.
|
|
15
19
|
*/
|
|
16
20
|
export class Web3SignerKeyStore implements ValidatorKeyStore {
|
|
21
|
+
private readonly requestTimeoutMs: number;
|
|
22
|
+
|
|
17
23
|
constructor(
|
|
18
24
|
private addresses: EthAddress[],
|
|
19
25
|
private baseUrl: string,
|
|
20
|
-
|
|
26
|
+
requestTimeoutMs: number = DEFAULT_WEB3SIGNER_REQUEST_TIMEOUT_MS,
|
|
27
|
+
) {
|
|
28
|
+
this.requestTimeoutMs = requestTimeoutMs;
|
|
29
|
+
}
|
|
21
30
|
|
|
22
31
|
/**
|
|
23
32
|
* Get the address of a signer by index
|
|
@@ -44,9 +53,10 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
|
|
|
44
53
|
/**
|
|
45
54
|
* Sign EIP-712 typed data with all keystore addresses
|
|
46
55
|
* @param typedData - The complete EIP-712 typed data structure (domain, types, primaryType, message)
|
|
56
|
+
* @param _context - Signing context (ignored by Web3SignerKeyStore, used for HA protection)
|
|
47
57
|
* @return signatures
|
|
48
58
|
*/
|
|
49
|
-
public signTypedData(typedData: TypedDataDefinition): Promise<Signature[]> {
|
|
59
|
+
public signTypedData(typedData: TypedDataDefinition, _context: SigningContext): Promise<Signature[]> {
|
|
50
60
|
return Promise.all(this.addresses.map(address => this.makeJsonRpcSignTypedDataRequest(address, typedData)));
|
|
51
61
|
}
|
|
52
62
|
|
|
@@ -54,10 +64,15 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
|
|
|
54
64
|
* Sign EIP-712 typed data with a specific address
|
|
55
65
|
* @param address - The address of the signer to use
|
|
56
66
|
* @param typedData - The complete EIP-712 typed data structure (domain, types, primaryType, message)
|
|
67
|
+
* @param _context - Signing context (ignored by Web3SignerKeyStore, used for HA protection)
|
|
57
68
|
* @returns signature for the specified address
|
|
58
69
|
* @throws Error if the address is not found in the keystore or signing fails
|
|
59
70
|
*/
|
|
60
|
-
public async signTypedDataWithAddress(
|
|
71
|
+
public async signTypedDataWithAddress(
|
|
72
|
+
address: EthAddress,
|
|
73
|
+
typedData: TypedDataDefinition,
|
|
74
|
+
_context: SigningContext,
|
|
75
|
+
): Promise<Signature> {
|
|
61
76
|
if (!this.addresses.some(addr => addr.equals(address))) {
|
|
62
77
|
throw new Error(`Address ${address.toString()} not found in keystore`);
|
|
63
78
|
}
|
|
@@ -69,9 +84,10 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
|
|
|
69
84
|
* Sign a message with all keystore addresses using EIP-191 prefix
|
|
70
85
|
*
|
|
71
86
|
* @param message - The message to sign
|
|
87
|
+
* @param _context - Signing context (ignored by Web3SignerKeyStore, used for HA protection)
|
|
72
88
|
* @return signatures
|
|
73
89
|
*/
|
|
74
|
-
public signMessage(message: Buffer32): Promise<Signature[]> {
|
|
90
|
+
public signMessage(message: Buffer32, _context: SigningContext): Promise<Signature[]> {
|
|
75
91
|
return Promise.all(this.addresses.map(address => this.makeJsonRpcSignRequest(address, message)));
|
|
76
92
|
}
|
|
77
93
|
|
|
@@ -79,10 +95,15 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
|
|
|
79
95
|
* Sign a message with a specific address using EIP-191 prefix
|
|
80
96
|
* @param address - The address of the signer to use
|
|
81
97
|
* @param message - The message to sign
|
|
98
|
+
* @param _context - Signing context (ignored by Web3SignerKeyStore, used for HA protection)
|
|
82
99
|
* @returns signature for the specified address
|
|
83
100
|
* @throws Error if the address is not found in the keystore or signing fails
|
|
84
101
|
*/
|
|
85
|
-
public async signMessageWithAddress(
|
|
102
|
+
public async signMessageWithAddress(
|
|
103
|
+
address: EthAddress,
|
|
104
|
+
message: Buffer32,
|
|
105
|
+
_context: SigningContext,
|
|
106
|
+
): Promise<Signature> {
|
|
86
107
|
if (!this.addresses.some(addr => addr.equals(address))) {
|
|
87
108
|
throw new Error(`Address ${address.toString()} not found in keystore`);
|
|
88
109
|
}
|
|
@@ -95,75 +116,50 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
|
|
|
95
116
|
* @param data - The data to sign
|
|
96
117
|
* @returns The signature
|
|
97
118
|
*/
|
|
98
|
-
private
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
// Use JSON-RPC eth_sign method which automatically applies Ethereum message prefixing
|
|
102
|
-
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({
|
|
103
122
|
jsonrpc: '2.0',
|
|
104
123
|
method: 'eth_sign',
|
|
105
|
-
params: [
|
|
106
|
-
address.toString(), // Ethereum address as identifier
|
|
107
|
-
data.toString(), // Raw data to sign (eth_sign will apply Ethereum message prefix)
|
|
108
|
-
],
|
|
124
|
+
params: [address.toString(), data.toString()],
|
|
109
125
|
id: 1,
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const response = await fetch(url, {
|
|
113
|
-
method: 'POST',
|
|
114
|
-
headers: {
|
|
115
|
-
'Content-Type': 'application/json',
|
|
116
|
-
},
|
|
117
|
-
body: JSON.stringify(body),
|
|
118
126
|
});
|
|
119
|
-
|
|
120
|
-
if (!response.ok) {
|
|
121
|
-
const errorText = await response.text();
|
|
122
|
-
throw new Error(`Web3Signer request failed: ${response.status} ${response.statusText} - ${errorText}`);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const result = await response.json();
|
|
126
|
-
|
|
127
|
-
// Handle JSON-RPC response format
|
|
128
|
-
if (result.error) {
|
|
129
|
-
throw new Error(`Web3Signer JSON-RPC error: ${result.error.code} - ${result.error.message}`);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (!result.result) {
|
|
133
|
-
throw new Error('Invalid response from Web3Signer: no result found');
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
let signatureHex = result.result;
|
|
137
|
-
|
|
138
|
-
// Ensure the signature has the 0x prefix
|
|
139
|
-
if (!signatureHex.startsWith('0x')) {
|
|
140
|
-
signatureHex = '0x' + signatureHex;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Parse the signature from the hex string
|
|
144
|
-
return normalizeSignature(Signature.fromString(signatureHex as `0x${string}`));
|
|
145
127
|
}
|
|
146
128
|
|
|
147
|
-
private
|
|
148
|
-
|
|
149
|
-
typedData: TypedDataDefinition,
|
|
150
|
-
): Promise<Signature> {
|
|
151
|
-
const url = this.baseUrl;
|
|
152
|
-
|
|
153
|
-
const body = {
|
|
129
|
+
private makeJsonRpcSignTypedDataRequest(address: EthAddress, typedData: TypedDataDefinition): Promise<Signature> {
|
|
130
|
+
return this.sendSignRequest({
|
|
154
131
|
jsonrpc: '2.0',
|
|
155
132
|
method: 'eth_signTypedData',
|
|
156
133
|
params: [address.toString(), JSON.stringify(typedData)],
|
|
157
134
|
id: 1,
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
const response = await fetch(url, {
|
|
161
|
-
method: 'POST',
|
|
162
|
-
headers: {
|
|
163
|
-
'Content-Type': 'application/json',
|
|
164
|
-
},
|
|
165
|
-
body: JSON.stringify(body),
|
|
166
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
|
+
}
|
|
167
163
|
|
|
168
164
|
if (!response.ok) {
|
|
169
165
|
const errorText = await response.text();
|
|
@@ -172,6 +168,7 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
|
|
|
172
168
|
|
|
173
169
|
const result = await response.json();
|
|
174
170
|
|
|
171
|
+
// Handle JSON-RPC response format
|
|
175
172
|
if (result.error) {
|
|
176
173
|
throw new Error(`Web3Signer JSON-RPC error: ${result.error.code} - ${result.error.message}`);
|
|
177
174
|
}
|
package/src/metrics.ts
CHANGED
|
@@ -1,70 +1,90 @@
|
|
|
1
|
+
import type { EpochNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
1
3
|
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
2
4
|
import {
|
|
3
5
|
Attributes,
|
|
6
|
+
type Gauge,
|
|
4
7
|
type Histogram,
|
|
5
8
|
Metrics,
|
|
6
9
|
type TelemetryClient,
|
|
7
10
|
type UpDownCounter,
|
|
8
|
-
|
|
11
|
+
createUpDownCounterWithDefault,
|
|
9
12
|
} from '@aztec/telemetry-client';
|
|
10
13
|
|
|
14
|
+
import type { BlockProposalValidationFailureReason } from './proposal_handler.js';
|
|
15
|
+
|
|
11
16
|
export class ValidatorMetrics {
|
|
12
17
|
private failedReexecutionCounter: UpDownCounter;
|
|
13
18
|
private successfulAttestationsCount: UpDownCounter;
|
|
14
19
|
private failedAttestationsBadProposalCount: UpDownCounter;
|
|
15
20
|
private failedAttestationsNodeIssueCount: UpDownCounter;
|
|
21
|
+
private currentEpoch: Gauge;
|
|
22
|
+
private attestedEpochCount: UpDownCounter;
|
|
16
23
|
|
|
17
24
|
private reexMana: Histogram;
|
|
18
25
|
private reexTx: Histogram;
|
|
19
|
-
private reexDuration:
|
|
26
|
+
private reexDuration: Gauge;
|
|
27
|
+
private checkpointProposalToPipelinedStateDuration: Histogram;
|
|
28
|
+
private checkpointProposalReceiveOffsetFromNextSlotBoundary: Histogram;
|
|
20
29
|
|
|
21
30
|
constructor(telemetryClient: TelemetryClient) {
|
|
22
31
|
const meter = telemetryClient.getMeter('Validator');
|
|
23
32
|
|
|
24
|
-
this.failedReexecutionCounter = meter
|
|
25
|
-
|
|
26
|
-
unit: 'count',
|
|
27
|
-
valueType: ValueType.INT,
|
|
33
|
+
this.failedReexecutionCounter = createUpDownCounterWithDefault(meter, Metrics.VALIDATOR_FAILED_REEXECUTION_COUNT, {
|
|
34
|
+
[Attributes.STATUS]: ['failed'],
|
|
28
35
|
});
|
|
29
36
|
|
|
30
|
-
this.successfulAttestationsCount =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
this.successfulAttestationsCount = createUpDownCounterWithDefault(
|
|
38
|
+
meter,
|
|
39
|
+
Metrics.VALIDATOR_ATTESTATION_SUCCESS_COUNT,
|
|
40
|
+
);
|
|
34
41
|
|
|
35
|
-
this.failedAttestationsBadProposalCount =
|
|
42
|
+
this.failedAttestationsBadProposalCount = createUpDownCounterWithDefault(
|
|
43
|
+
meter,
|
|
36
44
|
Metrics.VALIDATOR_ATTESTATION_FAILED_BAD_PROPOSAL_COUNT,
|
|
37
45
|
{
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
[Attributes.ERROR_TYPE]: [
|
|
47
|
+
'invalid_proposal',
|
|
48
|
+
'state_mismatch',
|
|
49
|
+
'failed_txs',
|
|
50
|
+
'in_hash_mismatch',
|
|
51
|
+
'parent_block_wrong_slot',
|
|
52
|
+
],
|
|
53
|
+
[Attributes.IS_COMMITTEE_MEMBER]: [true, false],
|
|
40
54
|
},
|
|
41
55
|
);
|
|
42
56
|
|
|
43
|
-
this.failedAttestationsNodeIssueCount =
|
|
57
|
+
this.failedAttestationsNodeIssueCount = createUpDownCounterWithDefault(
|
|
58
|
+
meter,
|
|
44
59
|
Metrics.VALIDATOR_ATTESTATION_FAILED_NODE_ISSUE_COUNT,
|
|
45
60
|
{
|
|
46
|
-
|
|
47
|
-
|
|
61
|
+
[Attributes.ERROR_TYPE]: [
|
|
62
|
+
'parent_block_not_found',
|
|
63
|
+
'global_variables_mismatch',
|
|
64
|
+
'block_number_already_exists',
|
|
65
|
+
'txs_not_available',
|
|
66
|
+
'timeout',
|
|
67
|
+
'unknown_error',
|
|
68
|
+
],
|
|
69
|
+
[Attributes.IS_COMMITTEE_MEMBER]: [true, false],
|
|
48
70
|
},
|
|
49
71
|
);
|
|
50
72
|
|
|
51
|
-
this.
|
|
52
|
-
description: 'The mana consumed by blocks',
|
|
53
|
-
valueType: ValueType.DOUBLE,
|
|
54
|
-
unit: 'Mmana',
|
|
55
|
-
});
|
|
73
|
+
this.currentEpoch = meter.createGauge(Metrics.VALIDATOR_CURRENT_EPOCH);
|
|
56
74
|
|
|
57
|
-
this.
|
|
58
|
-
description: 'The number of txs in a block proposal',
|
|
59
|
-
valueType: ValueType.INT,
|
|
60
|
-
unit: 'tx',
|
|
61
|
-
});
|
|
75
|
+
this.attestedEpochCount = createUpDownCounterWithDefault(meter, Metrics.VALIDATOR_ATTESTED_EPOCH_COUNT);
|
|
62
76
|
|
|
63
|
-
this.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
77
|
+
this.reexMana = meter.createHistogram(Metrics.VALIDATOR_RE_EXECUTION_MANA);
|
|
78
|
+
|
|
79
|
+
this.reexTx = meter.createHistogram(Metrics.VALIDATOR_RE_EXECUTION_TX_COUNT);
|
|
80
|
+
|
|
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
|
+
);
|
|
68
88
|
}
|
|
69
89
|
|
|
70
90
|
public recordReex(time: number, txs: number, mManaTotal: number) {
|
|
@@ -73,6 +93,16 @@ export class ValidatorMetrics {
|
|
|
73
93
|
this.reexMana.record(mManaTotal);
|
|
74
94
|
}
|
|
75
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
|
+
|
|
76
106
|
public recordFailedReexecution(proposal: BlockProposal) {
|
|
77
107
|
const proposer = proposal.getSender();
|
|
78
108
|
this.failedReexecutionCounter.add(1, {
|
|
@@ -85,17 +115,35 @@ export class ValidatorMetrics {
|
|
|
85
115
|
this.successfulAttestationsCount.add(num);
|
|
86
116
|
}
|
|
87
117
|
|
|
88
|
-
public incFailedAttestationsBadProposal(
|
|
118
|
+
public incFailedAttestationsBadProposal(
|
|
119
|
+
num: number,
|
|
120
|
+
reason: BlockProposalValidationFailureReason,
|
|
121
|
+
inCommittee: boolean,
|
|
122
|
+
) {
|
|
89
123
|
this.failedAttestationsBadProposalCount.add(num, {
|
|
90
124
|
[Attributes.ERROR_TYPE]: reason,
|
|
91
125
|
[Attributes.IS_COMMITTEE_MEMBER]: inCommittee,
|
|
92
126
|
});
|
|
93
127
|
}
|
|
94
128
|
|
|
95
|
-
public incFailedAttestationsNodeIssue(
|
|
129
|
+
public incFailedAttestationsNodeIssue(
|
|
130
|
+
num: number,
|
|
131
|
+
reason: BlockProposalValidationFailureReason,
|
|
132
|
+
inCommittee: boolean,
|
|
133
|
+
) {
|
|
96
134
|
this.failedAttestationsNodeIssueCount.add(num, {
|
|
97
135
|
[Attributes.ERROR_TYPE]: reason,
|
|
98
136
|
[Attributes.IS_COMMITTEE_MEMBER]: inCommittee,
|
|
99
137
|
});
|
|
100
138
|
}
|
|
139
|
+
|
|
140
|
+
/** Update the gauge tracking the current epoch number (proxy for total epochs elapsed). */
|
|
141
|
+
public setCurrentEpoch(epoch: EpochNumber) {
|
|
142
|
+
this.currentEpoch.record(Number(epoch));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Increment the count of epochs in which the given attester submitted at least one attestation. */
|
|
146
|
+
public incAttestedEpochCount(attester: EthAddress) {
|
|
147
|
+
this.attestedEpochCount.add(1, { [Attributes.ATTESTER_ADDRESS]: attester.toString() });
|
|
148
|
+
}
|
|
101
149
|
}
|