Skip to content

Commit

Permalink
Add validator address to initialized log
Browse files Browse the repository at this point in the history
clean up

add address to all validator logs

modify default logging to parse in tagged log data

fix types
  • Loading branch information
joeandrews committed Oct 10, 2024
1 parent 3138078 commit ebd04b2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
21 changes: 13 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,27 @@ 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 taggedLogData - 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, taggedLogData?: LogData ): DebugLogger {
const debugLogger = debug(name);
if (currentLevel === 'debug') debugLogger.enabled = true;

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: (...args: any[]) => logWithDebug(debugLogger, 'error', {...args, ...taggedLogData}),
warn: (...args: any[]) => logWithDebug(debugLogger, 'warn', {...args, ...taggedLogData}),
info: (...args: any[]) => logWithDebug(debugLogger, 'info', {...args, ...taggedLogData}),
verbose: (...args: any[]) => logWithDebug(debugLogger, 'verbose', {...args, ...taggedLogData}),
debug: (...args: any[]) => logWithDebug(debugLogger, 'debug', {...args, ...taggedLogData}),
};
return Object.assign((msg: string, data?: LogData) => logWithDebug(debugLogger, 'debug', msg, data), logger);
return Object.assign((...args: any[]) => logWithDebug(debugLogger, 'debug', {...args, ...taggedLogData}), 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
Expand Up @@ -6,6 +6,14 @@ 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(): string;

sign(message: Buffer32): Promise<Signature>;
/**
* Flavor of sign message that followed EIP-712 eth signed message prefix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ export class LocalKeyStore implements ValidatorKeyStore {
this.signer = new Secp256k1Signer(privateKey);
}

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

/**
* Sign a message with the keystore private key
*
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/validator-client/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class ValidatorClient implements Validator {
private p2pClient: P2P,
private attestationPoolingIntervalMs: number,
private attestationWaitTimeoutMs: number,
private log = createDebugLogger('aztec:validator'),
private log = createDebugLogger('aztec:validator', {validatorAddress: keyStore.getAddress()}),
) {
//TODO: We need to setup and store all of the currently active validators https://github.com/AztecProtocol/aztec-packages/issues/7962

Expand Down

0 comments on commit ebd04b2

Please sign in to comment.