Skip to content

Commit 7f82caf

Browse files
spalladinoclaude
andcommitted
refactor(log): replace withLogNameSuffix with actor-based AsyncLocalStorage
Introduces a new actor system using AsyncLocalStorage for cleaner log output. Components created within a withBindings() callback automatically inherit the actor label in their logs, displayed as a separate field rather than appended to the module name. Key changes: - Add LoggerBindings type with actor and instanceId fields - Create pino-logger-server.ts with withBindings/getBindings using AsyncLocalStorage - Export server utilities from @aztec/foundation/log/server (not main export) - Keep pino-logger.ts browser-safe (no node:async_hooks import) - Update createLogger() to accept optional bindings - Update pretty print format to show: {actor} {module} {instanceId} {msg} - Deprecate withLogNameSuffix() in favor of withBindings() - Add actor option to PXECreationOptions (deprecate useLogSuffix) - Move module-level loggers to class instances in checkpoint_builder.ts - Add instanceId to epoch-proving-job logger using job UUID - Wrap main node/PXE creation with withBindings({ actor: 'MAIN' }) in e2e setup Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 3212811 commit 7f82caf

File tree

115 files changed

+1252
-556
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+1252
-556
lines changed

boxes/boxes/vanilla/app/embedded-wallet.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ export class EmbeddedWallet extends BaseWallet {
125125
const config = getPXEConfig();
126126
config.l1Contracts = await aztecNode.getL1ContractAddresses();
127127
config.proverEnabled = PROVER_ENABLED;
128-
const pxe = await createPXE(aztecNode, config, {
129-
useLogSuffix: true,
130-
});
128+
const pxe = await createPXE(aztecNode, config, {});
131129

132130
// Register Sponsored FPC Contract with PXE
133131
await pxe.registerContract(await EmbeddedWallet.#getSponsoredPFCContract());

boxes/boxes/vanilla/scripts/deploy.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import { SponsoredFeePaymentMethod } from '@aztec/aztec.js/fee';
99
import { Fr } from '@aztec/aztec.js/fields';
1010
import { PublicKeys } from '@aztec/aztec.js/keys';
1111
import { createAztecNodeClient } from '@aztec/aztec.js/node';
12-
import type {
13-
DeployAccountOptions,
14-
Wallet,
15-
} from '@aztec/aztec.js/wallet';
12+
import type { DeployAccountOptions, Wallet } from '@aztec/aztec.js/wallet';
1613
import { type AztecNode } from '@aztec/aztec.js/node';
1714
import { SPONSORED_FPC_SALT } from '@aztec/constants';
1815
import { createStore } from '@aztec/kv-store/lmdb';
@@ -43,10 +40,7 @@ async function setupWallet(aztecNode: AztecNode) {
4340
config.dataDirectory = 'pxe';
4441
config.proverEnabled = PROVER_ENABLED;
4542

46-
return await TestWallet.create(aztecNode, config, {
47-
store,
48-
useLogSuffix: true,
49-
});
43+
return await TestWallet.create(aztecNode, config, { store });
5044
}
5145

5246
async function getSponsoredPFCContract() {

yarn-project/archiver/src/archiver.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,11 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
158158

159159
await this.blobClient.testSources();
160160
await this.synchronizer.testEthereumNodeSynced();
161-
await validateAndLogTraceAvailability(this.debugClient, this.config.ethereumAllowNoDebugHosts ?? false);
161+
await validateAndLogTraceAvailability(
162+
this.debugClient,
163+
this.config.ethereumAllowNoDebugHosts ?? false,
164+
this.log.getBindings(),
165+
);
162166

163167
// Log initial state for the archiver
164168
const { l1StartBlock } = this.l1Constants;

yarn-project/archiver/src/factory.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
66
import { Buffer32 } from '@aztec/foundation/buffer';
77
import { merge } from '@aztec/foundation/collection';
88
import { Fr } from '@aztec/foundation/curves/bn254';
9-
import { createLogger } from '@aztec/foundation/log';
109
import { DateProvider } from '@aztec/foundation/timer';
1110
import type { DataStoreConfig } from '@aztec/kv-store/config';
1211
import { createStore } from '@aztec/kv-store/lmdb-v2';
@@ -38,7 +37,7 @@ export async function createArchiverStore(
3837
...userConfig,
3938
dataStoreMapSizeKb: userConfig.archiverStoreMapSizeKb ?? userConfig.dataStoreMapSizeKb,
4039
};
41-
const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config, createLogger('archiver:lmdb'));
40+
const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config);
4241
return new KVArchiverDataStore(store, config.maxLogs, l1Constants);
4342
}
4443

yarn-project/archiver/src/l1/validate_trace.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import type { ViemPublicDebugClient } from '@aztec/ethereum/types';
2-
import { createLogger } from '@aztec/foundation/log';
2+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
33

44
import type { Hex } from 'viem';
55
import type { ZodSchema } from 'zod';
66

77
import { callTraceSchema } from './debug_tx.js';
88
import { traceTransactionResponseSchema } from './trace_tx.js';
99

10-
const logger = createLogger('aztec:archiver:validate_trace');
11-
1210
/**
1311
* Helper function to test a trace method with validation
1412
*
@@ -17,6 +15,7 @@ const logger = createLogger('aztec:archiver:validate_trace');
1715
* @param schema - Zod schema to validate the response
1816
* @param method - Name of the RPC method ('debug_traceTransaction' or 'trace_transaction')
1917
* @param blockType - Type of block being tested ('recent' or 'old')
18+
* @param logger - Logger instance
2019
* @returns true if the method works and validation passes, false otherwise
2120
*/
2221
async function testTraceMethod(
@@ -25,6 +24,7 @@ async function testTraceMethod(
2524
schema: ZodSchema,
2625
method: 'debug_traceTransaction' | 'trace_transaction',
2726
blockType: string,
27+
logger: Logger,
2828
): Promise<boolean> {
2929
try {
3030
// Make request with appropriate params based on method name
@@ -59,9 +59,14 @@ export interface TraceAvailability {
5959
* Validates the availability of debug/trace methods on the Ethereum client.
6060
*
6161
* @param client - The Viem public debug client
62+
* @param bindings - Optional logger bindings for context
6263
* @returns Object indicating which trace methods are available for recent and old blocks
6364
*/
64-
export async function validateTraceAvailability(client: ViemPublicDebugClient): Promise<TraceAvailability> {
65+
export async function validateTraceAvailability(
66+
client: ViemPublicDebugClient,
67+
bindings?: LoggerBindings,
68+
): Promise<TraceAvailability> {
69+
const logger = createLogger('archiver:validate_trace', bindings);
6570
const result: TraceAvailability = {
6671
debugTraceRecent: false,
6772
traceTransactionRecent: false,
@@ -95,6 +100,7 @@ export async function validateTraceAvailability(client: ViemPublicDebugClient):
95100
callTraceSchema,
96101
'debug_traceTransaction',
97102
'recent',
103+
logger,
98104
);
99105

100106
// Test trace_transaction with recent block
@@ -104,6 +110,7 @@ export async function validateTraceAvailability(client: ViemPublicDebugClient):
104110
traceTransactionResponseSchema,
105111
'trace_transaction',
106112
'recent',
113+
logger,
107114
);
108115

109116
// Get a block from 512 blocks ago
@@ -132,7 +139,14 @@ export async function validateTraceAvailability(client: ViemPublicDebugClient):
132139
const oldTxHash = oldBlock.transactions[0] as Hex;
133140

134141
// Test debug_traceTransaction with old block
135-
result.debugTraceOld = await testTraceMethod(client, oldTxHash, callTraceSchema, 'debug_traceTransaction', 'old');
142+
result.debugTraceOld = await testTraceMethod(
143+
client,
144+
oldTxHash,
145+
callTraceSchema,
146+
'debug_traceTransaction',
147+
'old',
148+
logger,
149+
);
136150

137151
// Test trace_transaction with old block
138152
result.traceTransactionOld = await testTraceMethod(
@@ -141,6 +155,7 @@ export async function validateTraceAvailability(client: ViemPublicDebugClient):
141155
traceTransactionResponseSchema,
142156
'trace_transaction',
143157
'old',
158+
logger,
144159
);
145160
} catch (error) {
146161
logger.warn(`Error validating debug_traceTransaction and trace_transaction availability: ${error}`);
@@ -159,15 +174,18 @@ function hasTxs(block: { transactions?: Hex[] }): boolean {
159174
*
160175
* @param client - The Viem public debug client
161176
* @param ethereumAllowNoDebugHosts - If false, throws an error when no trace methods are available
177+
* @param bindings - Optional logger bindings for context
162178
* @throws Error if ethereumAllowNoDebugHosts is false and no trace methods are available
163179
*/
164180
export async function validateAndLogTraceAvailability(
165181
client: ViemPublicDebugClient,
166182
ethereumAllowNoDebugHosts: boolean,
183+
bindings?: LoggerBindings,
167184
): Promise<void> {
185+
const logger = createLogger('archiver:validate_trace', bindings);
168186
logger.debug('Validating trace/debug method availability...');
169187

170-
const availability = await validateTraceAvailability(client);
188+
const availability = await validateTraceAvailability(client, bindings);
171189

172190
// Check if we have support for old blocks (either debug or trace)
173191
const hasOldBlockSupport = availability.debugTraceOld || availability.traceTransactionOld;

yarn-project/aztec-node/src/aztec-node/server.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
11831183
this.contractDataSource,
11841184
new DateProvider(),
11851185
this.telemetry,
1186+
this.log.getBindings(),
11861187
);
11871188

11881189
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
@@ -1236,16 +1237,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
12361237
// We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
12371238
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
12381239
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1239-
const validator = createValidatorForAcceptingTxs(db, this.contractDataSource, verifier, {
1240-
timestamp: nextSlotTimestamp,
1241-
blockNumber,
1242-
l1ChainId: this.l1ChainId,
1243-
rollupVersion: this.version,
1244-
setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
1245-
gasFees: await this.getCurrentMinFees(),
1246-
skipFeeEnforcement,
1247-
txsPermitted: !this.config.disableTransactions,
1248-
});
1240+
const validator = createValidatorForAcceptingTxs(
1241+
db,
1242+
this.contractDataSource,
1243+
verifier,
1244+
{
1245+
timestamp: nextSlotTimestamp,
1246+
blockNumber,
1247+
l1ChainId: this.l1ChainId,
1248+
rollupVersion: this.version,
1249+
setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
1250+
gasFees: await this.getCurrentMinFees(),
1251+
skipFeeEnforcement,
1252+
txsPermitted: !this.config.disableTransactions,
1253+
},
1254+
this.log.getBindings(),
1255+
);
12491256

12501257
return await validator.validateTx(tx);
12511258
}

yarn-project/aztec-node/src/sentinel/factory.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ export async function createSentinel(
2020
if (!config.sentinelEnabled) {
2121
return undefined;
2222
}
23-
const kvStore = await createStore(
24-
'sentinel',
25-
SentinelStore.SCHEMA_VERSION,
26-
config,
27-
createLogger('node:sentinel:lmdb'),
28-
);
23+
const kvStore = await createStore('sentinel', SentinelStore.SCHEMA_VERSION, config, logger.getBindings());
2924
const storeHistoryLength = config.sentinelHistoryLengthInEpochs * epochCache.getL1Constants().epochDuration;
3025
const storeHistoricProvenPerformanceLength = config.sentinelHistoricProvenPerformanceLengthInEpochs;
3126
const sentinelStore = new SentinelStore(kvStore, {

yarn-project/aztec/src/cli/cmds/start_p2p_bootstrap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { jsonStringify } from '@aztec/foundation/json-rpc';
22
import type { NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
3-
import { type LogFn, createLogger } from '@aztec/foundation/log';
3+
import type { LogFn } from '@aztec/foundation/log';
44
import { createStore } from '@aztec/kv-store/lmdb-v2';
55
import { type BootnodeConfig, BootstrapNode, bootnodeConfigMappings } from '@aztec/p2p';
66
import { emptyChainConfig } from '@aztec/stdlib/config';
@@ -27,7 +27,7 @@ export async function startP2PBootstrap(
2727
const telemetryConfig = extractRelevantOptions<TelemetryClientConfig>(options, telemetryClientConfigMappings, 'tel');
2828
const telemetryClient = await initTelemetryClient(telemetryConfig);
2929

30-
const store = await createStore('p2p-bootstrap', 1, config, createLogger('p2p:bootstrap:store'));
30+
const store = await createStore('p2p-bootstrap', 1, config);
3131
const node = new BootstrapNode(store, telemetryClient);
3232
await node.start(config);
3333
signalHandlers.push(() => node.stop());

yarn-project/bb-prover/src/avm_proving_tests/avm_proving_tester.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class InterceptingLogger implements Logger {
4444
throw new Error('Not implemented');
4545
}
4646

47+
getBindings() {
48+
return this.logger.getBindings();
49+
}
50+
4751
private intercept(level: LogLevel, msg: string, ...args: any[]) {
4852
this.logs.push(...msg.split('\n'));
4953
// Forward to the wrapped logger

yarn-project/bb-prover/src/prover/server/bb_prover.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
463463
this.config.acvmWorkingDirectory,
464464
this.config.acvmBinaryPath,
465465
outputWitnessFile,
466+
logger,
466467
);
467468

468469
const artifact = getServerCircuitArtifact(circuitType);

0 commit comments

Comments
 (0)