Skip to content

Commit

Permalink
chore: Investigate P2P test (AztecProtocol#3929)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
PhilWindle authored Jan 11, 2024
1 parent a09fd2a commit 0fca2c4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
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

0 comments on commit 0fca2c4

Please sign in to comment.