Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add validator address to logs #9143

Merged
merged 17 commits into from
Oct 10, 2024
25 changes: 17 additions & 8 deletions yarn-project/foundation/src/log/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,31 @@ export type DebugLogger = Logger;
* If DEBUG="[module]" env is set, will enable debug logging if the module matches.
* Uses npm debug for debug level and console.error for other levels.
* @param name - Name of the module.
* @param fixedLogData - Additional data to include in the log message.
* @usage createDebugLogger('aztec:validator', {validatorAddress: '0x1234...'});
* // will always add the validator address to the log labels
* @returns A debug logger.
*/
export function createDebugLogger(name: string): DebugLogger {

export function createDebugLogger(name: string, fixedLogData?: LogData): DebugLogger {
const debugLogger = debug(name);

const attatchFixedLogData = (data?: LogData) => ({ ...fixedLogData, ...data });

const logger = {
silent: () => {},
error: (msg: string, err?: unknown, data?: LogData) => logWithDebug(debugLogger, 'error', fmtErr(msg, err), data),
warn: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'warn', msg, data),
info: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'info', msg, data),
verbose: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'verbose', msg, data),
debug: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'debug', msg, data),
error: (msg: string, err?: unknown, data?: LogData) =>
logWithDebug(debugLogger, 'error', fmtErr(msg, err), attatchFixedLogData(data)),
warn: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'warn', msg, attatchFixedLogData(data)),
info: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'info', msg, attatchFixedLogData(data)),
verbose: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'verbose', msg, attatchFixedLogData(data)),
debug: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'debug', msg, attatchFixedLogData(data)),
};
return Object.assign((msg: string, data?: LogData) => logWithDebug(debugLogger, 'debug', msg, data), logger);
return Object.assign(
(msg: string, data?: LogData) => logWithDebug(debugLogger, 'debug', msg, attatchFixedLogData(data)),
logger,
);
}

/** A callback to capture all logs. */
export type LogHandler = (level: LogLevel, namespace: string, msg: string, data?: LogData) => void;

Expand Down
8 changes: 8 additions & 0 deletions yarn-project/validator-client/src/key_store/interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type EthAddress } from '@aztec/circuits.js';
import { type Buffer32 } from '@aztec/foundation/buffer';
import { type Signature } from '@aztec/foundation/eth-signature';

Expand All @@ -6,6 +7,13 @@ import { type Signature } from '@aztec/foundation/eth-signature';
* A keystore interface that can be replaced with a local keystore / remote signer service
*/
export interface ValidatorKeyStore {
/**
* Get the address of the signer
*
* @returns the address
*/
getAddress(): EthAddress;

sign(message: Buffer32): Promise<Signature>;
/**
* Flavor of sign message that followed EIP-712 eth signed message prefix
Expand Down
10 changes: 10 additions & 0 deletions yarn-project/validator-client/src/key_store/local_key_store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type Buffer32 } from '@aztec/foundation/buffer';
import { Secp256k1Signer } from '@aztec/foundation/crypto';
import { type EthAddress } from '@aztec/foundation/eth-address';
import { type Signature } from '@aztec/foundation/eth-signature';

import { type ValidatorKeyStore } from './interface.js';
Expand All @@ -16,6 +17,15 @@ export class LocalKeyStore implements ValidatorKeyStore {
this.signer = new Secp256k1Signer(privateKey);
}

/**
* Get the address of the signer
*
* @returns the address
*/
public getAddress(): EthAddress {
return this.signer.address;
}

/**
* Sign a message with the keystore private key
*
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/validator-client/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export class ValidatorClient extends WithTracer implements Validator {
private attestationPoolingIntervalMs: number,
private attestationWaitTimeoutMs: number,
telemetry: TelemetryClient,
private log = createDebugLogger('aztec:validator'),
private log = createDebugLogger('aztec:validator', { validatorAddress: keyStore.getAddress().toString() }),
) {
// Instatntiate tracer
// Instantiate tracer
super(telemetry, 'Validator');

//TODO: We need to setup and store all of the currently active validators https://github.com/AztecProtocol/aztec-packages/issues/7962
Expand Down
Loading