@@ -18,6 +18,7 @@ import { createDebugLogger } from '@aztec/foundation/log';
1818import { SerialQueue } from '@aztec/foundation/queue' ;
1919import { RunningPromise } from '@aztec/foundation/running-promise' ;
2020import type { AztecKVStore } from '@aztec/kv-store' ;
21+ import { Attributes , type TelemetryClient , WithTracer , trackSpan } from '@aztec/telemetry-client' ;
2122
2223import { type ENR } from '@chainsafe/enr' ;
2324import { type GossipSub , type GossipSubComponents , gossipsub } from '@chainsafe/libp2p-gossipsub' ;
@@ -77,7 +78,7 @@ export async function createLibP2PPeerId(privateKey?: string): Promise<PeerId> {
7778/**
7879 * Lib P2P implementation of the P2PService interface.
7980 */
80- export class LibP2PService implements P2PService {
81+ export class LibP2PService extends WithTracer implements P2PService {
8182 private jobQueue : SerialQueue = new SerialQueue ( ) ;
8283 private peerManager : PeerManager ;
8384 private discoveryRunningPromise ?: RunningPromise ;
@@ -100,9 +101,13 @@ export class LibP2PService implements P2PService {
100101 private l2BlockSource : L2BlockSource ,
101102 private proofVerifier : ClientProtocolCircuitVerifier ,
102103 private worldStateSynchronizer : WorldStateSynchronizer ,
104+ telemetry : TelemetryClient ,
103105 private requestResponseHandlers : ReqRespSubProtocolHandlers = DEFAULT_SUB_PROTOCOL_HANDLERS ,
104106 private logger = createDebugLogger ( 'aztec:libp2p_service' ) ,
105107 ) {
108+ // Instatntiate tracer
109+ super ( telemetry , 'LibP2PService' ) ;
110+
106111 this . peerManager = new PeerManager ( node , peerDiscoveryService , config , logger ) ;
107112 this . node . services . pubsub . score . params . appSpecificScore = ( peerId : string ) => {
108113 return this . peerManager . getPeerScore ( peerId ) ;
@@ -204,6 +209,7 @@ export class LibP2PService implements P2PService {
204209 proofVerifier : ClientProtocolCircuitVerifier ,
205210 worldStateSynchronizer : WorldStateSynchronizer ,
206211 store : AztecKVStore ,
212+ telemetry : TelemetryClient ,
207213 ) {
208214 const { tcpListenAddress, tcpAnnounceAddress, minPeerCount, maxPeerCount } = config ;
209215 const bindAddrTcp = convertToMultiaddr ( tcpListenAddress , 'tcp' ) ;
@@ -306,6 +312,7 @@ export class LibP2PService implements P2PService {
306312 l2BlockSource ,
307313 proofVerifier ,
308314 worldStateSynchronizer ,
315+ telemetry ,
309316 requestResponseHandlers ,
310317 ) ;
311318 }
@@ -397,6 +404,12 @@ export class LibP2PService implements P2PService {
397404 *
398405 * @param attestation - The attestation to process.
399406 */
407+ @trackSpan ( 'Libp2pService.processAttestationFromPeer' , attestation => ( {
408+ [ Attributes . BLOCK_NUMBER ] : attestation . payload . header . globalVariables . blockNumber . toNumber ( ) ,
409+ [ Attributes . SLOT_NUMBER ] : attestation . payload . header . globalVariables . slotNumber . toNumber ( ) ,
410+ [ Attributes . BLOCK_ARCHIVE ] : attestation . archive . toString ( ) ,
411+ [ Attributes . P2P_ID ] : attestation . p2pMessageIdentifier ( ) . toString ( ) ,
412+ } ) )
400413 private async processAttestationFromPeer ( attestation : BlockAttestation ) : Promise < void > {
401414 this . logger . debug ( `Received attestation ${ attestation . p2pMessageIdentifier ( ) } from external peer.` ) ;
402415 await this . mempools . attestationPool . addAttestations ( [ attestation ] ) ;
@@ -409,17 +422,37 @@ export class LibP2PService implements P2PService {
409422 * @param block - The block to process.
410423 */
411424 // REVIEW: callback pattern https://github.com/AztecProtocol/aztec-packages/issues/7963
425+ @trackSpan ( 'Libp2pService.processBlockFromPeer' , block => ( {
426+ [ Attributes . BLOCK_NUMBER ] : block . payload . header . globalVariables . blockNumber . toNumber ( ) ,
427+ [ Attributes . SLOT_NUMBER ] : block . payload . header . globalVariables . slotNumber . toNumber ( ) ,
428+ [ Attributes . BLOCK_ARCHIVE ] : block . archive . toString ( ) ,
429+ [ Attributes . P2P_ID ] : block . p2pMessageIdentifier ( ) . toString ( ) ,
430+ } ) )
412431 private async processBlockFromPeer ( block : BlockProposal ) : Promise < void > {
413432 this . logger . verbose ( `Received block ${ block . p2pMessageIdentifier ( ) } from external peer.` ) ;
414433 const attestation = await this . blockReceivedCallback ( block ) ;
415434
416435 // TODO: fix up this pattern - the abstraction is not nice
417436 // The attestation can be undefined if no handler is registered / the validator deems the block invalid
418437 if ( attestation != undefined ) {
419- this . propagate ( attestation ) ;
438+ this . broadcastAttestation ( attestation ) ;
420439 }
421440 }
422441
442+ /**
443+ * Broadcast an attestation to all peers.
444+ * @param attestation - The attestation to broadcast.
445+ */
446+ @trackSpan ( 'Libp2pService.broadcastAttestation' , attestation => ( {
447+ [ Attributes . BLOCK_NUMBER ] : attestation . payload . header . globalVariables . blockNumber . toNumber ( ) ,
448+ [ Attributes . SLOT_NUMBER ] : attestation . payload . header . globalVariables . slotNumber . toNumber ( ) ,
449+ [ Attributes . BLOCK_ARCHIVE ] : attestation . archive . toString ( ) ,
450+ [ Attributes . P2P_ID ] : attestation . p2pMessageIdentifier ( ) . toString ( ) ,
451+ } ) )
452+ private broadcastAttestation ( attestation : BlockAttestation ) : void {
453+ this . propagate ( attestation ) ;
454+ }
455+
423456 private processEpochProofQuoteFromPeer ( epochProofQuote : EpochProofQuote ) : void {
424457 this . logger . verbose ( `Received epoch proof quote ${ epochProofQuote . p2pMessageIdentifier ( ) } from external peer.` ) ;
425458 this . mempools . epochProofQuotePool . addQuote ( epochProofQuote ) ;
0 commit comments