Skip to content

Commit cb7abce

Browse files
committed
Better start of libp2p services
1 parent eb2b132 commit cb7abce

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

yarn-project/p2p/src/services/libp2p/libp2p_service.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -415,17 +415,12 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
415415

416416
// Start job queue, peer discovery service and libp2p node
417417
this.jobQueue.start();
418+
await this.node.start();
418419

419420
await this.peerManager.initializePeers();
420421
if (!this.config.p2pDiscoveryDisabled) {
421422
await this.peerDiscoveryService.start();
422423
}
423-
await this.node.start();
424-
425-
// Subscribe to standard GossipSub topics by default
426-
for (const topic of getTopicTypeForClientType(this.clientType)) {
427-
this.subscribeToTopic(this.topicStrings[topic]);
428-
}
429424

430425
// Create request response protocol handlers
431426
const txHandler = reqRespTxHandler(this.mempools);
@@ -451,6 +446,18 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
451446
requestResponseHandlers[ReqRespSubProtocol.BLOCK_TXS] = blockTxsHandler.bind(this);
452447
}
453448

449+
// Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
450+
const reqrespSubProtocolValidators = {
451+
...DEFAULT_SUB_PROTOCOL_VALIDATORS,
452+
// TODO(#11336): A request validator for blocks
453+
[ReqRespSubProtocol.TX]: this.validateRequestedTx.bind(this),
454+
};
455+
await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
456+
457+
// Subscribe to standard GossipSub topics by default
458+
for (const topic of getTopicTypeForClientType(this.clientType)) {
459+
this.subscribeToTopic(this.topicStrings[topic]);
460+
}
454461
// add GossipSub listener
455462
this.node.services.pubsub.addEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
456463

@@ -462,13 +469,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
462469
);
463470
this.discoveryRunningPromise.start();
464471

465-
// Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
466-
const reqrespSubProtocolValidators = {
467-
...DEFAULT_SUB_PROTOCOL_VALIDATORS,
468-
// TODO(#11336): A request validator for blocks
469-
[ReqRespSubProtocol.TX]: this.validateRequestedTx.bind(this),
470-
};
471-
await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
472472
this.logger.info(`Started P2P service`, {
473473
listen: this.config.listenAddress,
474474
port: this.config.p2pPort,

0 commit comments

Comments
 (0)