Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Investigate P2P test #3929

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}
Expand Down
3 changes: 3 additions & 0 deletions yarn-project/p2p/src/client/p2p_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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...');
}

/**
Expand Down
13 changes: 3 additions & 10 deletions yarn-project/p2p/src/service/libp2p_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -118,22 +115,18 @@ 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);
}

/**
* Stops the LibP2P service.
* @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');
}

/**
Expand Down
1 change: 1 addition & 0 deletions yarn-project/sequencer-client/src/sequencer/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export class Sequencer {
* Stops the sequencer from processing txs and moves to STOPPED state.
*/
public async stop(): Promise<void> {
this.log(`Stopping sequencer`);
await this.runningPromise?.stop();
this.publisher.interrupt();
this.state = SequencerState.STOPPED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down