@aztec/validator-client 0.0.0-test.0

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.
Files changed (45) hide show
  1. package/dest/config.d.ts +22 -0
  2. package/dest/config.d.ts.map +1 -0
  3. package/dest/config.js +31 -0
  4. package/dest/duties/validation_service.d.ts +29 -0
  5. package/dest/duties/validation_service.d.ts.map +1 -0
  6. package/dest/duties/validation_service.js +35 -0
  7. package/dest/errors/index.d.ts +2 -0
  8. package/dest/errors/index.d.ts.map +1 -0
  9. package/dest/errors/index.js +1 -0
  10. package/dest/errors/validator.error.d.ts +29 -0
  11. package/dest/errors/validator.error.d.ts.map +1 -0
  12. package/dest/errors/validator.error.js +45 -0
  13. package/dest/factory.d.ts +13 -0
  14. package/dest/factory.d.ts.map +1 -0
  15. package/dest/factory.js +11 -0
  16. package/dest/index.d.ts +4 -0
  17. package/dest/index.d.ts.map +1 -0
  18. package/dest/index.js +3 -0
  19. package/dest/key_store/index.d.ts +3 -0
  20. package/dest/key_store/index.d.ts.map +1 -0
  21. package/dest/key_store/index.js +2 -0
  22. package/dest/key_store/interface.d.ts +25 -0
  23. package/dest/key_store/interface.d.ts.map +1 -0
  24. package/dest/key_store/interface.js +4 -0
  25. package/dest/key_store/local_key_store.d.ts +28 -0
  26. package/dest/key_store/local_key_store.d.ts.map +1 -0
  27. package/dest/key_store/local_key_store.js +32 -0
  28. package/dest/metrics.d.ts +11 -0
  29. package/dest/metrics.d.ts.map +1 -0
  30. package/dest/metrics.js +35 -0
  31. package/dest/validator.d.ts +81 -0
  32. package/dest/validator.d.ts.map +1 -0
  33. package/dest/validator.js +246 -0
  34. package/package.json +94 -0
  35. package/src/config.ts +56 -0
  36. package/src/duties/validation_service.ts +45 -0
  37. package/src/errors/index.ts +1 -0
  38. package/src/errors/validator.error.ts +55 -0
  39. package/src/factory.ts +28 -0
  40. package/src/index.ts +3 -0
  41. package/src/key_store/index.ts +2 -0
  42. package/src/key_store/interface.ts +26 -0
  43. package/src/key_store/local_key_store.ts +46 -0
  44. package/src/metrics.ts +50 -0
  45. package/src/validator.ts +362 -0
@@ -0,0 +1,22 @@
1
+ import { type ConfigMappingsType } from '@aztec/foundation/config';
2
+ /**
3
+ * The Validator Configuration
4
+ */
5
+ export interface ValidatorClientConfig {
6
+ /** The private key of the validator participating in attestation duties */
7
+ validatorPrivateKey?: string;
8
+ /** Do not run the validator */
9
+ disableValidator: boolean;
10
+ /** Interval between polling for new attestations from peers */
11
+ attestationPollingIntervalMs: number;
12
+ /** Re-execute transactions before attesting */
13
+ validatorReexecute: boolean;
14
+ }
15
+ export declare const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientConfig>;
16
+ /**
17
+ * Returns the prover configuration from the environment variables.
18
+ * Note: If an environment variable is not set, the default value is used.
19
+ * @returns The validator configuration.
20
+ */
21
+ export declare function getProverEnvVars(): ValidatorClientConfig;
22
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,kBAAkB,EAIxB,MAAM,0BAA0B,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,2EAA2E;IAC3E,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B,+BAA+B;IAC/B,gBAAgB,EAAE,OAAO,CAAC;IAE1B,+DAA+D;IAC/D,4BAA4B,EAAE,MAAM,CAAC;IAErC,+CAA+C;IAC/C,kBAAkB,EAAE,OAAO,CAAC;CAC7B;AAED,eAAO,MAAM,6BAA6B,EAAE,kBAAkB,CAAC,qBAAqB,CAqBnF,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,qBAAqB,CAExD"}
package/dest/config.js ADDED
@@ -0,0 +1,31 @@
1
+ import { NULL_KEY } from '@aztec/ethereum';
2
+ import { booleanConfigHelper, getConfigFromMappings, numberConfigHelper } from '@aztec/foundation/config';
3
+ export const validatorClientConfigMappings = {
4
+ validatorPrivateKey: {
5
+ env: 'VALIDATOR_PRIVATE_KEY',
6
+ parseEnv: (val)=>val ? `0x${val.replace('0x', '')}` : NULL_KEY,
7
+ description: 'The private key of the validator participating in attestation duties'
8
+ },
9
+ disableValidator: {
10
+ env: 'VALIDATOR_DISABLED',
11
+ description: 'Do not run the validator',
12
+ ...booleanConfigHelper()
13
+ },
14
+ attestationPollingIntervalMs: {
15
+ env: 'VALIDATOR_ATTESTATIONS_POLLING_INTERVAL_MS',
16
+ description: 'Interval between polling for new attestations',
17
+ ...numberConfigHelper(200)
18
+ },
19
+ validatorReexecute: {
20
+ env: 'VALIDATOR_REEXECUTE',
21
+ description: 'Re-execute transactions before attesting',
22
+ ...booleanConfigHelper(true)
23
+ }
24
+ };
25
+ /**
26
+ * Returns the prover configuration from the environment variables.
27
+ * Note: If an environment variable is not set, the default value is used.
28
+ * @returns The validator configuration.
29
+ */ export function getProverEnvVars() {
30
+ return getConfigFromMappings(validatorClientConfigMappings);
31
+ }
@@ -0,0 +1,29 @@
1
+ import type { Fr } from '@aztec/foundation/fields';
2
+ import { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
3
+ import type { BlockHeader, TxHash } from '@aztec/stdlib/tx';
4
+ import type { ValidatorKeyStore } from '../key_store/interface.js';
5
+ export declare class ValidationService {
6
+ private keyStore;
7
+ constructor(keyStore: ValidatorKeyStore);
8
+ /**
9
+ * Create a block proposal with the given header, archive, and transactions
10
+ *
11
+ * @param header - The block header
12
+ * @param archive - The archive of the current block
13
+ * @param txs - TxHash[] ordered list of transactions
14
+ *
15
+ * @returns A block proposal signing the above information (not the current implementation!!!)
16
+ */
17
+ createBlockProposal(header: BlockHeader, archive: Fr, txs: TxHash[]): Promise<BlockProposal>;
18
+ /**
19
+ * Attest to the given block proposal constructed by the current sequencer
20
+ *
21
+ * NOTE: This is just a blind signing.
22
+ * We assume that the proposal is valid and DA guarantees have been checked previously.
23
+ *
24
+ * @param proposal - The proposal to attest to
25
+ * @returns attestation
26
+ */
27
+ attestToProposal(proposal: BlockProposal): Promise<BlockAttestation>;
28
+ }
29
+ //# sourceMappingURL=validation_service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation_service.d.ts","sourceRoot":"","sources":["../../src/duties/validation_service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAA8C,MAAM,mBAAmB,CAAC;AAChH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,qBAAa,iBAAiB;IAChB,OAAO,CAAC,QAAQ;gBAAR,QAAQ,EAAE,iBAAiB;IAE/C;;;;;;;;OAQG;IACH,mBAAmB,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAM5F;;;;;;;;OAQG;IACG,gBAAgB,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAS3E"}
@@ -0,0 +1,35 @@
1
+ import { Buffer32 } from '@aztec/foundation/buffer';
2
+ import { keccak256 } from '@aztec/foundation/crypto';
3
+ import { BlockAttestation, BlockProposal, ConsensusPayload, SignatureDomainSeparator } from '@aztec/stdlib/p2p';
4
+ export class ValidationService {
5
+ keyStore;
6
+ constructor(keyStore){
7
+ this.keyStore = keyStore;
8
+ }
9
+ /**
10
+ * Create a block proposal with the given header, archive, and transactions
11
+ *
12
+ * @param header - The block header
13
+ * @param archive - The archive of the current block
14
+ * @param txs - TxHash[] ordered list of transactions
15
+ *
16
+ * @returns A block proposal signing the above information (not the current implementation!!!)
17
+ */ createBlockProposal(header, archive, txs) {
18
+ const payloadSigner = (payload)=>this.keyStore.signMessage(payload);
19
+ return BlockProposal.createProposalFromSigner(new ConsensusPayload(header, archive, txs), payloadSigner);
20
+ }
21
+ /**
22
+ * Attest to the given block proposal constructed by the current sequencer
23
+ *
24
+ * NOTE: This is just a blind signing.
25
+ * We assume that the proposal is valid and DA guarantees have been checked previously.
26
+ *
27
+ * @param proposal - The proposal to attest to
28
+ * @returns attestation
29
+ */ async attestToProposal(proposal) {
30
+ // TODO(https://github.com/AztecProtocol/aztec-packages/issues/7961): check that the current validator is correct
31
+ const buf = Buffer32.fromBuffer(keccak256(await proposal.payload.getPayloadToSign(SignatureDomainSeparator.blockAttestation)));
32
+ const sig = await this.keyStore.signMessage(buf);
33
+ return new BlockAttestation(proposal.payload, sig);
34
+ }
35
+ }
@@ -0,0 +1,2 @@
1
+ export * from './validator.error.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './validator.error.js';
@@ -0,0 +1,29 @@
1
+ import type { TxHash } from '@aztec/stdlib/tx';
2
+ export declare class ValidatorError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ export declare class InvalidValidatorPrivateKeyError extends ValidatorError {
6
+ constructor();
7
+ }
8
+ export declare class AttestationTimeoutError extends ValidatorError {
9
+ constructor(numberOfRequiredAttestations: number, slot: bigint);
10
+ }
11
+ export declare class TransactionsNotAvailableError extends ValidatorError {
12
+ constructor(txHashes: TxHash[]);
13
+ }
14
+ export declare class FailedToReExecuteTransactionsError extends ValidatorError {
15
+ constructor(txHashes: TxHash[]);
16
+ }
17
+ export declare class ReExStateMismatchError extends ValidatorError {
18
+ constructor();
19
+ }
20
+ export declare class ReExFailedTxsError extends ValidatorError {
21
+ constructor(numFailedTxs: number);
22
+ }
23
+ export declare class ReExTimeoutError extends ValidatorError {
24
+ constructor();
25
+ }
26
+ export declare class BlockBuilderNotProvidedError extends ValidatorError {
27
+ constructor();
28
+ }
29
+ //# sourceMappingURL=validator.error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.error.d.ts","sourceRoot":"","sources":["../../src/errors/validator.error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,+BAAgC,SAAQ,cAAc;;CAIlE;AAED,qBAAa,uBAAwB,SAAQ,cAAc;gBAC7C,4BAA4B,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAG/D;AAED,qBAAa,6BAA8B,SAAQ,cAAc;gBACnD,QAAQ,EAAE,MAAM,EAAE;CAG/B;AAED,qBAAa,kCAAmC,SAAQ,cAAc;gBACxD,QAAQ,EAAE,MAAM,EAAE;CAG/B;AAED,qBAAa,sBAAuB,SAAQ,cAAc;;CAIzD;AAED,qBAAa,kBAAmB,SAAQ,cAAc;gBACxC,YAAY,EAAE,MAAM;CAGjC;AAED,qBAAa,gBAAiB,SAAQ,cAAc;;CAInD;AAED,qBAAa,4BAA6B,SAAQ,cAAc;;CAI/D"}
@@ -0,0 +1,45 @@
1
+ export class ValidatorError extends Error {
2
+ constructor(message){
3
+ super(`Validator Error: ${message}`);
4
+ }
5
+ }
6
+ export class InvalidValidatorPrivateKeyError extends ValidatorError {
7
+ constructor(){
8
+ super('Invalid validator private key provided');
9
+ }
10
+ }
11
+ export class AttestationTimeoutError extends ValidatorError {
12
+ constructor(numberOfRequiredAttestations, slot){
13
+ super(`Timeout waiting for ${numberOfRequiredAttestations} attestations for slot, ${slot}`);
14
+ }
15
+ }
16
+ export class TransactionsNotAvailableError extends ValidatorError {
17
+ constructor(txHashes){
18
+ super(`Transactions not available: ${txHashes.join(', ')}`);
19
+ }
20
+ }
21
+ export class FailedToReExecuteTransactionsError extends ValidatorError {
22
+ constructor(txHashes){
23
+ super(`Failed to re-execute transactions: ${txHashes.join(', ')}`);
24
+ }
25
+ }
26
+ export class ReExStateMismatchError extends ValidatorError {
27
+ constructor(){
28
+ super('Re-execution state mismatch');
29
+ }
30
+ }
31
+ export class ReExFailedTxsError extends ValidatorError {
32
+ constructor(numFailedTxs){
33
+ super(`Re-execution failed to process ${numFailedTxs} txs`);
34
+ }
35
+ }
36
+ export class ReExTimeoutError extends ValidatorError {
37
+ constructor(){
38
+ super('Re-execution timed out or failed to process all txs in the proposal');
39
+ }
40
+ }
41
+ export class BlockBuilderNotProvidedError extends ValidatorError {
42
+ constructor(){
43
+ super('Block builder not provided');
44
+ }
45
+ }
@@ -0,0 +1,13 @@
1
+ import type { EpochCache } from '@aztec/epoch-cache';
2
+ import type { DateProvider } from '@aztec/foundation/timer';
3
+ import type { P2P } from '@aztec/p2p';
4
+ import type { TelemetryClient } from '@aztec/telemetry-client';
5
+ import type { ValidatorClientConfig } from './config.js';
6
+ import { ValidatorClient } from './validator.js';
7
+ export declare function createValidatorClient(config: ValidatorClientConfig, deps: {
8
+ p2pClient: P2P;
9
+ telemetry: TelemetryClient;
10
+ dateProvider: DateProvider;
11
+ epochCache: EpochCache;
12
+ }): ValidatorClient | undefined;
13
+ //# sourceMappingURL=factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAI/D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,qBAAqB,EAC7B,IAAI,EAAE;IACJ,SAAS,EAAE,GAAG,CAAC;IACf,SAAS,EAAE,eAAe,CAAC;IAC3B,YAAY,EAAE,YAAY,CAAC;IAC3B,UAAU,EAAE,UAAU,CAAC;CACxB,+BAUF"}
@@ -0,0 +1,11 @@
1
+ import { generatePrivateKey } from 'viem/accounts';
2
+ import { ValidatorClient } from './validator.js';
3
+ export function createValidatorClient(config, deps) {
4
+ if (config.disableValidator) {
5
+ return undefined;
6
+ }
7
+ if (config.validatorPrivateKey === undefined || config.validatorPrivateKey === '') {
8
+ config.validatorPrivateKey = generatePrivateKey();
9
+ }
10
+ return ValidatorClient.new(config, deps.epochCache, deps.p2pClient, deps.dateProvider, deps.telemetry);
11
+ }
@@ -0,0 +1,4 @@
1
+ export * from './config.js';
2
+ export * from './validator.js';
3
+ export * from './factory.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
package/dest/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './config.js';
2
+ export * from './validator.js';
3
+ export * from './factory.js';
@@ -0,0 +1,3 @@
1
+ export * from './interface.js';
2
+ export * from './local_key_store.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/key_store/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './interface.js';
2
+ export * from './local_key_store.js';
@@ -0,0 +1,25 @@
1
+ import type { Buffer32 } from '@aztec/foundation/buffer';
2
+ import type { EthAddress } from '@aztec/foundation/eth-address';
3
+ import type { Signature } from '@aztec/foundation/eth-signature';
4
+ /** Key Store
5
+ *
6
+ * A keystore interface that can be replaced with a local keystore / remote signer service
7
+ */
8
+ export interface ValidatorKeyStore {
9
+ /**
10
+ * Get the address of the signer
11
+ *
12
+ * @returns the address
13
+ */
14
+ getAddress(): EthAddress;
15
+ sign(message: Buffer32): Promise<Signature>;
16
+ /**
17
+ * Flavor of sign message that followed EIP-712 eth signed message prefix
18
+ * Note: this is only required when we are using ecdsa signatures over secp256k1
19
+ *
20
+ * @param message - The message to sign.
21
+ * @returns The signature.
22
+ */
23
+ signMessage(message: Buffer32): Promise<Signature>;
24
+ }
25
+ //# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/key_store/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAEjE;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,UAAU,IAAI,UAAU,CAAC;IAEzB,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAC5C;;;;;;OAMG;IACH,WAAW,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;CACpD"}
@@ -0,0 +1,4 @@
1
+ /** Key Store
2
+ *
3
+ * A keystore interface that can be replaced with a local keystore / remote signer service
4
+ */ export { };
@@ -0,0 +1,28 @@
1
+ import type { Buffer32 } from '@aztec/foundation/buffer';
2
+ import type { EthAddress } from '@aztec/foundation/eth-address';
3
+ import type { Signature } from '@aztec/foundation/eth-signature';
4
+ import type { ValidatorKeyStore } from './interface.js';
5
+ /**
6
+ * Local Key Store
7
+ *
8
+ * An implementation of the Key store using an in memory private key.
9
+ */
10
+ export declare class LocalKeyStore implements ValidatorKeyStore {
11
+ private signer;
12
+ constructor(privateKey: Buffer32);
13
+ /**
14
+ * Get the address of the signer
15
+ *
16
+ * @returns the address
17
+ */
18
+ getAddress(): EthAddress;
19
+ /**
20
+ * Sign a message with the keystore private key
21
+ *
22
+ * @param messageBuffer - The message buffer to sign
23
+ * @return signature
24
+ */
25
+ sign(digest: Buffer32): Promise<Signature>;
26
+ signMessage(message: Buffer32): Promise<Signature>;
27
+ }
28
+ //# sourceMappingURL=local_key_store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local_key_store.d.ts","sourceRoot":"","sources":["../../src/key_store/local_key_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAEjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD;;;;GAIG;AACH,qBAAa,aAAc,YAAW,iBAAiB;IACrD,OAAO,CAAC,MAAM,CAAkB;gBAEpB,UAAU,EAAE,QAAQ;IAIhC;;;;OAIG;IACI,UAAU,IAAI,UAAU;IAI/B;;;;;OAKG;IACI,IAAI,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;IAM1C,WAAW,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;CAK1D"}
@@ -0,0 +1,32 @@
1
+ import { Secp256k1Signer } from '@aztec/foundation/crypto';
2
+ /**
3
+ * Local Key Store
4
+ *
5
+ * An implementation of the Key store using an in memory private key.
6
+ */ export class LocalKeyStore {
7
+ signer;
8
+ constructor(privateKey){
9
+ this.signer = new Secp256k1Signer(privateKey);
10
+ }
11
+ /**
12
+ * Get the address of the signer
13
+ *
14
+ * @returns the address
15
+ */ getAddress() {
16
+ return this.signer.address;
17
+ }
18
+ /**
19
+ * Sign a message with the keystore private key
20
+ *
21
+ * @param messageBuffer - The message buffer to sign
22
+ * @return signature
23
+ */ sign(digest) {
24
+ const signature = this.signer.sign(digest);
25
+ return Promise.resolve(signature);
26
+ }
27
+ signMessage(message) {
28
+ // Sign message adds eth sign prefix and hashes before signing
29
+ const signature = this.signer.signMessage(message);
30
+ return Promise.resolve(signature);
31
+ }
32
+ }
@@ -0,0 +1,11 @@
1
+ import type { BlockProposal } from '@aztec/stdlib/p2p';
2
+ import { type TelemetryClient } from '@aztec/telemetry-client';
3
+ export declare class ValidatorMetrics {
4
+ private reExecutionTime;
5
+ private failedReexecutionCounter;
6
+ constructor(telemetryClient: TelemetryClient);
7
+ reExecutionTimer(): () => void;
8
+ recordReExecutionTime(time: number): void;
9
+ recordFailedReexecution(proposal: BlockProposal): Promise<void>;
10
+ }
11
+ //# sourceMappingURL=metrics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAIL,KAAK,eAAe,EAGrB,MAAM,yBAAyB,CAAC;AAEjC,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,eAAe,CAAQ;IAC/B,OAAO,CAAC,wBAAwB,CAAgB;gBAEpC,eAAe,EAAE,eAAe;IAgBrC,gBAAgB,IAAI,MAAM,IAAI;IAQ9B,qBAAqB,CAAC,IAAI,EAAE,MAAM;IAI5B,uBAAuB,CAAC,QAAQ,EAAE,aAAa;CAO7D"}
@@ -0,0 +1,35 @@
1
+ import { Attributes, Metrics, ValueType } from '@aztec/telemetry-client';
2
+ export class ValidatorMetrics {
3
+ reExecutionTime;
4
+ failedReexecutionCounter;
5
+ constructor(telemetryClient){
6
+ const meter = telemetryClient.getMeter('Validator');
7
+ this.failedReexecutionCounter = meter.createUpDownCounter(Metrics.VALIDATOR_FAILED_REEXECUTION_COUNT, {
8
+ description: 'The number of failed re-executions',
9
+ unit: 'count',
10
+ valueType: ValueType.INT
11
+ });
12
+ this.reExecutionTime = meter.createGauge(Metrics.VALIDATOR_RE_EXECUTION_TIME, {
13
+ description: 'The time taken to re-execute a transaction',
14
+ unit: 'ms',
15
+ valueType: ValueType.DOUBLE
16
+ });
17
+ }
18
+ reExecutionTimer() {
19
+ const start = performance.now();
20
+ return ()=>{
21
+ const end = performance.now();
22
+ this.recordReExecutionTime(end - start);
23
+ };
24
+ }
25
+ recordReExecutionTime(time) {
26
+ this.reExecutionTime.record(time);
27
+ }
28
+ async recordFailedReexecution(proposal) {
29
+ this.failedReexecutionCounter.add(1, {
30
+ [Attributes.STATUS]: 'failed',
31
+ [Attributes.BLOCK_NUMBER]: proposal.payload.header.globalVariables.blockNumber.toString(),
32
+ [Attributes.BLOCK_PROPOSER]: (await proposal.getSender())?.toString()
33
+ });
34
+ }
35
+ }
@@ -0,0 +1,81 @@
1
+ import type { EpochCache } from '@aztec/epoch-cache';
2
+ import type { Fr } from '@aztec/foundation/fields';
3
+ import { DateProvider, type Timer } from '@aztec/foundation/timer';
4
+ import type { P2P } from '@aztec/p2p';
5
+ import type { L2Block } from '@aztec/stdlib/block';
6
+ import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
7
+ import type { BlockHeader, GlobalVariables, Tx, TxHash } from '@aztec/stdlib/tx';
8
+ import { type TelemetryClient, WithTracer } from '@aztec/telemetry-client';
9
+ import type { ValidatorClientConfig } from './config.js';
10
+ import type { ValidatorKeyStore } from './key_store/interface.js';
11
+ /**
12
+ * Callback function for building a block
13
+ *
14
+ * We reuse the sequencer's block building functionality for re-execution
15
+ */
16
+ type BlockBuilderCallback = (txs: Iterable<Tx> | AsyncIterableIterator<Tx>, globalVariables: GlobalVariables, opts?: {
17
+ validateOnly?: boolean;
18
+ }) => Promise<{
19
+ block: L2Block;
20
+ publicProcessorDuration: number;
21
+ numTxs: number;
22
+ numFailedTxs: number;
23
+ blockBuildingTimer: Timer;
24
+ }>;
25
+ export interface Validator {
26
+ start(): Promise<void>;
27
+ registerBlockProposalHandler(): void;
28
+ registerBlockBuilder(blockBuilder: BlockBuilderCallback): void;
29
+ createBlockProposal(header: BlockHeader, archive: Fr, txs: TxHash[]): Promise<BlockProposal | undefined>;
30
+ attestToProposal(proposal: BlockProposal): void;
31
+ broadcastBlockProposal(proposal: BlockProposal): void;
32
+ collectAttestations(proposal: BlockProposal, required: number, deadline: Date): Promise<BlockAttestation[]>;
33
+ }
34
+ /**
35
+ * Validator Client
36
+ */
37
+ export declare class ValidatorClient extends WithTracer implements Validator {
38
+ private keyStore;
39
+ private epochCache;
40
+ private p2pClient;
41
+ private config;
42
+ private dateProvider;
43
+ private log;
44
+ private validationService;
45
+ private metrics;
46
+ private previousProposal?;
47
+ private blockBuilder?;
48
+ private epochCacheUpdateLoop;
49
+ private blockProposalValidator;
50
+ constructor(keyStore: ValidatorKeyStore, epochCache: EpochCache, p2pClient: P2P, config: ValidatorClientConfig, dateProvider?: DateProvider, telemetry?: TelemetryClient, log?: import("@aztec/foundation/log").Logger);
51
+ static new(config: ValidatorClientConfig, epochCache: EpochCache, p2pClient: P2P, dateProvider?: DateProvider, telemetry?: TelemetryClient): ValidatorClient;
52
+ start(): Promise<void>;
53
+ stop(): Promise<void>;
54
+ registerBlockProposalHandler(): void;
55
+ /**
56
+ * Register a callback function for building a block
57
+ *
58
+ * We reuse the sequencer's block building functionality for re-execution
59
+ */
60
+ registerBlockBuilder(blockBuilder: BlockBuilderCallback): void;
61
+ attestToProposal(proposal: BlockProposal): Promise<BlockAttestation | undefined>;
62
+ /**
63
+ * Re-execute the transactions in the proposal and check that the state updates match the header state
64
+ * @param proposal - The proposal to re-execute
65
+ */
66
+ reExecuteTransactions(proposal: BlockProposal): Promise<void>;
67
+ /**
68
+ * Ensure that all of the transactions in the proposal are available in the tx pool before attesting
69
+ *
70
+ * 1. Check if the local tx pool contains all of the transactions in the proposal
71
+ * 2. If any transactions are not in the local tx pool, request them from the network
72
+ * 3. If we cannot retrieve them from the network, throw an error
73
+ * @param proposal - The proposal to attest to
74
+ */
75
+ ensureTransactionsAreAvailable(proposal: BlockProposal): Promise<void>;
76
+ createBlockProposal(header: BlockHeader, archive: Fr, txs: TxHash[]): Promise<BlockProposal | undefined>;
77
+ broadcastBlockProposal(proposal: BlockProposal): void;
78
+ collectAttestations(proposal: BlockProposal, required: number, deadline: Date): Promise<BlockAttestation[]>;
79
+ }
80
+ export {};
81
+ //# sourceMappingURL=validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAInD,OAAO,EAAE,YAAY,EAAE,KAAK,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,KAAK,eAAe,EAAE,UAAU,EAAsB,MAAM,yBAAyB,CAAC;AAE/F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAWzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAIlE;;;;GAIG;AACH,KAAK,oBAAoB,GAAG,CAC1B,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,qBAAqB,CAAC,EAAE,CAAC,EAC7C,eAAe,E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