Skip to content
Merged
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
8 changes: 6 additions & 2 deletions yarn-project/p2p/src/services/libp2p/libp2p_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
*/
private blockReceivedCallback: (block: BlockProposal) => Promise<BlockAttestation | undefined>;

private gossipSubEventHandler: (e: CustomEvent<GossipsubMessage>) => void;

constructor(
private clientType: T,
private config: P2PConfig,
Expand Down Expand Up @@ -139,6 +141,8 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
this.attestationValidator = new AttestationValidator(epochCache);
this.blockProposalValidator = new BlockProposalValidator(epochCache);

this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);

this.blockReceivedCallback = async (block: BlockProposal): Promise<BlockAttestation | undefined> => {
this.logger.debug(
`Handler not yet registered: Block received callback not set. Received block for slot ${block.slotNumber.toNumber()} from peer.`,
Expand Down Expand Up @@ -329,7 +333,7 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
};

// add GossipSub listener
this.node.services.pubsub.addEventListener(GossipSubEvent.MESSAGE, this.handleGossipSubEvent.bind(this));
this.node.services.pubsub.addEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);

// Start running promise for peer discovery
this.discoveryRunningPromise = new RunningPromise(
Expand Down Expand Up @@ -360,7 +364,7 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
*/
public async stop() {
// Remove gossip sub listener
this.node.services.pubsub.removeEventListener(GossipSubEvent.MESSAGE, this.handleGossipSubEvent.bind(this));
this.node.services.pubsub.removeEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);

// Stop peer manager
this.logger.debug('Stopping peer manager...');
Expand Down