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

fix(core-p2p): always refresh peer status #2318

Merged
merged 2 commits into from
Mar 26, 2019
Merged
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
8 changes: 7 additions & 1 deletion packages/core-p2p/src/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ export class Monitor implements P2P.IMonitor {
this.logger.info(`Refreshing ${this.getPeers().length} peers after fork.`);

// Reset all peers, except peers banned because of causing a fork.
await this.cleanPeers(false, true);
await this.guard.resetSuspendedPeers();

// Ban peer who caused the fork
Expand Down Expand Up @@ -506,7 +507,7 @@ export class Monitor implements P2P.IMonitor {
*/
public async checkNetworkHealth(): Promise<P2P.INetworkStatus> {
if (!this.__isColdStartActive()) {
await this.cleanPeers(true, true);
await this.cleanPeers(false, true);
await this.guard.resetSuspendedPeers();
}

Expand All @@ -518,6 +519,11 @@ export class Monitor implements P2P.IMonitor {
.filter(peer => peer.verification !== null);

const allPeers = [...peers, ...suspendedPeers];
if (!allPeers.length) {
this.logger.info("No peers available.");
return { forked: false };
}

const forkedPeers = allPeers.filter(peer => peer.verification.forked);
const majorityOnOurChain = forkedPeers.length / allPeers.length < 0.5;

Expand Down