Skip to content

Commit

Permalink
More logs tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Dec 9, 2024
1 parent bc53740 commit 161fd7e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
3 changes: 3 additions & 0 deletions yarn-project/p2p/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const createP2PClient = async (
} = {},
) => {
let config = { ..._config };
const logger = createDebugLogger('p2p');
const store = deps.store ?? (await createStore('p2p', config, createDebugLogger('aztec:p2p:lmdb')));

const mempools: MemPools = {
Expand All @@ -46,6 +47,7 @@ export const createP2PClient = async (
let p2pService;

if (_config.p2pEnabled) {
logger.verbose('P2P is enabled. Using LibP2P service.');
config = await configureP2PClientAddresses(_config);

// Create peer discovery service
Expand All @@ -65,6 +67,7 @@ export const createP2PClient = async (
telemetry,
);
} else {
logger.verbose('P2P is disabled. Using dummy P2P service');
p2pService = new DummyP2PService();
}
return new P2PClient(store, l2BlockSource, mempools, p2pService, config.keepProvenTxsInPoolFor, telemetry);
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/p2p/src/client/p2p_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,9 @@ export class P2PClient extends WithTracer implements P2P {
* @param newState - New state value.
*/
private setCurrentState(newState: P2PClientState) {
const oldState = this.currentState;
this.currentState = newState;
this.log.debug(`Moved to state ${P2PClientState[this.currentState]}`);
this.log.debug(`Moved from state ${P2PClientState[oldState]} to ${P2PClientState[this.currentState]}`);
}

private async publishStoredTxs() {
Expand Down
8 changes: 3 additions & 5 deletions yarn-project/p2p/src/service/discV5_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,11 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
metricsRegistry,
});

this.logger.verbose(`DiscV5 ENR NodeId: ${this.enr.nodeId}`);
this.logger.info(`ENR UDP: ${multiAddrUdp.toString()}`);

(this.discv5 as Discv5EventEmitter).on('discovered', (enr: ENR) => this.onDiscovered(enr));
(this.discv5 as Discv5EventEmitter).on('enrAdded', async (enr: ENR) => {
const multiAddrTcp = await enr.getFullMultiaddr('tcp');
const multiAddrUdp = await enr.getFullMultiaddr('udp');
this.logger.debug(`Added ENR`, { multiAddrTcp, multiAddrUdp, nodeId: enr.nodeId });
this.logger.debug(`Added ENR ${enr.encodeTxt()}`, { multiAddrTcp, multiAddrUdp, nodeId: enr.nodeId });
this.onDiscovered(enr);
});
}
Expand All @@ -110,8 +107,9 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService

this.logger.info(`DiscV5 service started`, {
nodeId: this.enr.nodeId,
listenUdp: this.listenMultiAddrUdp,
peerId: this.peerId,
enrUdp: await this.enr.getFullMultiaddr('udp'),
enrTcp: await this.enr.getFullMultiaddr('tcp'),
});
this.currentState = PeerDiscoveryState.RUNNING;

Expand Down
21 changes: 12 additions & 9 deletions yarn-project/p2p/src/service/peer_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createDebugLogger } from '@aztec/foundation/log';
import { type ENR } from '@chainsafe/enr';
import { type PeerId } from '@libp2p/interface';
import { type Multiaddr } from '@multiformats/multiaddr';
import { inspect } from 'util';

import { type P2PConfig } from '../config.js';
import { type PubSubLibp2p } from '../util.js';
Expand Down Expand Up @@ -115,7 +116,7 @@ export class PeerManager {
const peersToConnect = this.config.maxPeerCount - connections.length;

const logLevel = this.heartbeatCounter % 60 === 0 ? 'info' : 'debug';
this.logger[logLevel](`P2P peers status`, {
this.logger[logLevel](`Connected to ${connections.length} peers`, {
connections: connections.length,
maxPeerCount: this.config.maxPeerCount,
cachedPeers: this.cachedPeers.size,
Expand Down Expand Up @@ -156,7 +157,7 @@ export class PeerManager {

// if we need more peers, start randomNodesQuery
if (peersToConnect > 0) {
this.logger.debug(`Running random nodes query to connect to ${peersToConnect} peers`);
this.logger.trace(`Running random nodes query to connect to ${peersToConnect} peers`);
void this.peerDiscoveryService.runRandomNodesQuery();
}
}
Expand All @@ -171,7 +172,9 @@ export class PeerManager {
// check if peer is already connected
const [peerId, multiaddrTcp] = await Promise.all([enr.peerId(), enr.getFullMultiaddr('tcp')]);

this.logger.debug(`Handling discovered peer ${peerId.toString()} at ${multiaddrTcp?.toString()}`);
this.logger.trace(
`Handling discovered peer ${peerId.toString()} at ${multiaddrTcp?.toString() ?? 'undefined address'}`,
);

// throw if no tcp addr in multiaddr
if (!multiaddrTcp) {
Expand All @@ -180,14 +183,14 @@ export class PeerManager {
}
const connections = this.libP2PNode.getConnections();
if (connections.some(conn => conn.remotePeer.equals(peerId))) {
this.logger.debug(`Already connected to peer ${peerId.toString()}`);
this.logger.trace(`Already connected to peer ${peerId.toString()}`);
return;
}

// check if peer is already in cache
const id = peerId.toString();
if (this.cachedPeers.has(id)) {
this.logger.debug(`Peer already in cache ${id}`);
this.logger.trace(`Peer already in cache ${id}`);
return;
}

Expand All @@ -203,7 +206,7 @@ export class PeerManager {
if (this.shouldDialPeer()) {
void this.dialPeer(cachedPeer);
} else {
this.logger.debug(`Caching peer ${id}`);
this.logger.trace(`Caching peer ${id}`);
this.cachedPeers.set(id, cachedPeer);
// Prune set of cached peers
this.pruneCachedPeers();
Expand All @@ -217,13 +220,13 @@ export class PeerManager {
this.logger.debug(`Dialing peer ${id}`);
try {
await this.libP2PNode.dial(peer.multiaddrTcp);
} catch {
} catch (error) {
peer.dialAttempts++;
if (peer.dialAttempts < MAX_DIAL_ATTEMPTS) {
this.logger.debug(`Failed to dial peer ${id} (attempt ${peer.dialAttempts})`);
this.logger.trace(`Failed to dial peer ${id} (attempt ${peer.dialAttempts})`, { error: inspect(error) });
this.cachedPeers.set(id, peer);
} else {
this.logger.debug(`Failed to dial peer ${id} (dropping)`);
this.logger.debug(`Failed to dial peer ${id} (dropping)`, { error: inspect(error) });
this.cachedPeers.delete(id);
}
}
Expand Down
13 changes: 9 additions & 4 deletions yarn-project/prover-node/src/prover-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,16 @@ export class ProverNode implements ClaimsMonitorHandler, EpochMonitorHandler, Pr
}

public getP2P() {
const asP2PClient = this.coordination as P2P;
if (asP2PClient.isP2PClient && asP2PClient.isP2PClient()) {
return asP2PClient;
// TODO(palla): Remove try/catch once #10544 lands
try {
const asP2PClient = this.coordination as P2P;
if (typeof asP2PClient.isP2PClient === 'function' && asP2PClient.isP2PClient()) {
return asP2PClient;
}
return undefined;
} catch {
return undefined;
}
return undefined;
}

async handleClaim(proofClaim: EpochProofClaim): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@
"engines": {
"node": ">=18"
}
}
}

0 comments on commit 161fd7e

Please sign in to comment.