Skip to content

Commit fedee21

Browse files
committed
Better start of libp2p services
1 parent 7abe32e commit fedee21

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
@@ -436,17 +436,12 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
436436

437437
// Start job queue, peer discovery service and libp2p node
438438
this.jobQueue.start();
439+
await this.node.start();
439440

440441
await this.peerManager.initializePeers();
441442
if (!this.config.p2pDiscoveryDisabled) {
442443
await this.peerDiscoveryService.start();
443444
}
444-
await this.node.start();
445-
446-
// Subscribe to standard GossipSub topics by default
447-
for (const topic of getTopicTypeForClientType(this.clientType)) {
448-
this.subscribeToTopic(this.topicStrings[topic]);
449-
}
450445

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

470+
// Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
471+
const reqrespSubProtocolValidators = {
472+
...DEFAULT_SUB_PROTOCOL_VALIDATORS,
473+
// TODO(#11336): A request validator for blocks
474+
[ReqRespSubProtocol.TX]: this.validateRequestedTx.bind(this),
475+
};
476+
await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
477+
478+
// Subscribe to standard GossipSub topics by default
479+
for (const topic of getTopicTypeForClientType(this.clientType)) {
480+
this.subscribeToTopic(this.topicStrings[topic]);
481+
}
475482
// add GossipSub listener
476483
this.node.services.pubsub.addEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
477484

@@ -483,13 +490,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
483490
);
484491
this.discoveryRunningPromise.start();
485492

486-
// Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
487-
const reqrespSubProtocolValidators = {
488-
...DEFAULT_SUB_PROTOCOL_VALIDATORS,
489-
// TODO(#11336): A request validator for blocks
490-
[ReqRespSubProtocol.TX]: this.validateRequestedTx.bind(this),
491-
};
492-
await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
493493
this.logger.info(`Started P2P service`, {
494494
listen: this.config.listenAddress,
495495
port: this.config.p2pPort,

0 commit comments

Comments
 (0)