From 0fca2c4084f2033f86d0df60536cba1341538dbd Mon Sep 17 00:00:00 2001 From: PhilWindle <60546371+PhilWindle@users.noreply.github.com> Date: Thu, 11 Jan 2024 10:42:12 +0000 Subject: [PATCH] chore: Investigate P2P test (#3929) This PR removes the unnecessary initial routing table request and adds logging to assist in diagnosing the P2P failing test. # Checklist: Remove the checklist to signal you've completed it. Enable auto-merge if the PR is ready to merge. - [ ] If the pull request requires a cryptography review (e.g. cryptographic algorithm implementations) I have added the 'crypto' tag. - [ ] I have reviewed my diff in github, line by line and removed unexpected formatting changes, testing logs, or commented-out code. - [ ] Every change is related to the PR description. - [ ] I have [linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) this pull request to relevant issues (if any exist). --- yarn-project/aztec-node/src/aztec-node/server.ts | 1 + yarn-project/p2p/src/client/p2p_client.ts | 3 +++ yarn-project/p2p/src/service/libp2p_service.ts | 13 +++---------- .../sequencer-client/src/sequencer/sequencer.ts | 1 + .../synchronizer/server_world_state_synchronizer.ts | 4 ++++ 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 1a8ff721839..d2fd81c6075 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -285,6 +285,7 @@ export class AztecNodeService implements AztecNode { await this.p2pClient.stop(); await this.worldStateSynchronizer.stop(); await this.blockSource.stop(); + this.log('Closing Merkle Trees'); await this.merkleTreesDb.close(); this.log.info(`Stopped`); } diff --git a/yarn-project/p2p/src/client/p2p_client.ts b/yarn-project/p2p/src/client/p2p_client.ts index 99798622e1d..96a5738752d 100644 --- a/yarn-project/p2p/src/client/p2p_client.ts +++ b/yarn-project/p2p/src/client/p2p_client.ts @@ -194,9 +194,12 @@ export class P2PClient implements P2P { this.log('Stopping p2p client...'); this.stopping = true; await this.p2pService.stop(); + this.log('Stopped p2p service'); await this.blockDownloader.stop(); + this.log('Stopped block downloader'); await this.runningPromise; this.setCurrentState(P2PClientState.STOPPED); + this.log('P2P client stopped...'); } /** diff --git a/yarn-project/p2p/src/service/libp2p_service.ts b/yarn-project/p2p/src/service/libp2p_service.ts index e13c7e18eda..772c27ff53d 100644 --- a/yarn-project/p2p/src/service/libp2p_service.ts +++ b/yarn-project/p2p/src/service/libp2p_service.ts @@ -31,8 +31,6 @@ import { getEncodedMessage, } from './tx_messages.js'; -const INITIAL_PEER_REFRESH_INTERVAL = 20000; - /** * Create a libp2p peer ID from the private key if provided, otherwise creates a new random ID. * @param privateKey - Optional peer ID private key as hex string @@ -63,7 +61,6 @@ export function exportLibP2PPeerIdToString(peerId: PeerId) { */ export class LibP2PService implements P2PService { private jobQueue: SerialQueue = new SerialQueue(); - private timeout: NodeJS.Timer | undefined = undefined; private knownTxLookup: KnownTxLookup = new KnownTxLookup(); constructor( private config: P2PConfig, @@ -118,10 +115,6 @@ export class LibP2PService implements P2PService { ); const dht = this.node.services['kadDHT'] as DualKadDHT; this.logger(`Started P2P client as ${await dht.getMode()} with Peer ID ${this.node.peerId.toString()}`); - this.timeout = setTimeout(async () => { - this.logger(`Refreshing routing table...`); - await dht.refreshRoutingTable(); - }, INITIAL_PEER_REFRESH_INTERVAL); } /** @@ -129,11 +122,11 @@ export class LibP2PService implements P2PService { * @returns An empty promise. */ public async stop() { - if (this.timeout) { - clearTimeout(this.timeout); - } + this.logger('Stopping job queue...'); await this.jobQueue.end(); + this.logger('Stopping LibP2P...'); await this.node.stop(); + this.logger('LibP2P service stopped'); } /** diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.ts index 59d53665595..4bc5d91f204 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.ts @@ -83,6 +83,7 @@ export class Sequencer { * Stops the sequencer from processing txs and moves to STOPPED state. */ public async stop(): Promise { + this.log(`Stopping sequencer`); await this.runningPromise?.stop(); this.publisher.interrupt(); this.state = SequencerState.STOPPED; diff --git a/yarn-project/world-state/src/synchronizer/server_world_state_synchronizer.ts b/yarn-project/world-state/src/synchronizer/server_world_state_synchronizer.ts index 200db8482a4..a064f6ae1af 100644 --- a/yarn-project/world-state/src/synchronizer/server_world_state_synchronizer.ts +++ b/yarn-project/world-state/src/synchronizer/server_world_state_synchronizer.ts @@ -117,9 +117,13 @@ export class ServerWorldStateSynchronizer implements WorldStateSynchronizer { this.log('Stopping world state...'); this.stopping = true; await this.l2BlockDownloader.stop(); + this.log('Cancelling job queue...'); await this.jobQueue.cancel(); + this.log('Stopping Merkle trees'); await this.merkleTreeDb.stop(); + this.log('Awaiting promise'); await this.runningPromise; + this.log('Commiting current block number'); await this.commitCurrentL2BlockNumber(); this.setCurrentState(WorldStateRunningState.STOPPED); }