Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions yarn-project/foundation/src/log/bigint-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export function convertBigintsToStrings(obj: unknown): unknown {
}

if (obj !== null && typeof obj === 'object') {
if (typeof (obj as any).toJSON === 'function') {
return convertBigintsToStrings((obj as any).toJSON());
}
const result: Record<string, unknown> = {};
for (const key in obj) {
result[key] = convertBigintsToStrings((obj as Record<string, unknown>)[key]);
Expand Down
29 changes: 29 additions & 0 deletions yarn-project/foundation/src/log/pino-logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,35 @@ describe('pino-logger', () => {
});
});

it('serializes objects with toJSON() instead of dumping raw properties', () => {
const testLogger = createLogger('tojson-test');
capturingStream.clear();

// Simulate an EthAddress-like object with an internal buffer and a toJSON method
const addressLike = {
buffer: Buffer.from('1234567890abcdef1234567890abcdef12345678', 'hex'),
toJSON() {
return '0x1234567890abcdef1234567890abcdef12345678';
},
};

testLogger.info('address logging test', {
validator: addressLike,
nested: { addr: addressLike },
array: [addressLike],
plainString: 'hello',
});

const entries = capturingStream.getJsonLines();
expect(entries).toHaveLength(1);
expect(entries[0]).toMatchObject({
validator: '0x1234567890abcdef1234567890abcdef12345678',
nested: { addr: '0x1234567890abcdef1234567890abcdef12345678' },
array: ['0x1234567890abcdef1234567890abcdef12345678'],
plainString: 'hello',
});
});

it('returns bindings via getBindings', () => {
const testLogger = createLogger('bindings-test', { actor: 'main', instanceId: 'id-123' });
const bindings = testLogger.getBindings();
Expand Down
6 changes: 1 addition & 5 deletions yarn-project/slasher/src/tally_slasher_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,11 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
return undefined;
}

const offensesToSlashLog = offensesToSlash.map(offense => ({
...offense,
amount: offense.amount.toString(),
}));
this.log.info(`Voting to slash ${offensesToSlash.length} offenses`, {
slotNumber,
currentRound,
slashedRound,
offensesToSlash: offensesToSlashLog,
offensesToSlash,
});

const committees = await this.collectCommitteesActiveDuringRound(slashedRound);
Expand Down
Loading