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

refactor(core-p2p): increase network timeouts #2828

Merged
merged 3 commits into from
Jul 26, 2019
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
9 changes: 7 additions & 2 deletions packages/core-p2p/src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ export const defaults = {
*/
minimumNetworkReach: 20,
/**
* The timeout for requests to other peers
* The timeout to verify a peer. [milliseconds]
*/
globalTimeout: 5000,
verifyTimeout: 60000,
/**
* The timeout to download a batch of blocks (400). Notice that we start
* 25 concurrent such downloads, so the network may be saturated. [milliseconds]
*/
getBlocksTimeout: 600000,
/**
* The maximum number of peers we will broadcast data to
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/core-p2p/src/network-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class NetworkMonitor implements P2P.INetworkMonitor {
let max = peers.length;

let unresponsivePeers = 0;
const pingDelay = fast ? 1500 : app.resolveOptions("p2p").globalTimeout;
const pingDelay = fast ? 1500 : app.resolveOptions("p2p").verifyTimeout;

if (peerCount) {
peers = shuffle(peers).slice(0, peerCount);
Expand Down
5 changes: 2 additions & 3 deletions packages/core-p2p/src/peer-communicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,8 @@ export class PeerCommunicator implements P2P.IPeerCommunicator {
{
fromBlockHeight,
blockLimit,
timeoutMsec,
headersOnly,
}: { fromBlockHeight: number; blockLimit?: number; timeoutMsec?: number; headersOnly?: boolean },
}: { fromBlockHeight: number; blockLimit?: number; headersOnly?: boolean },
): Promise<Interfaces.IBlockData[]> {
const peerBlocks = await this.emit(
peer,
Expand All @@ -156,7 +155,7 @@ export class PeerCommunicator implements P2P.IPeerCommunicator {
"Content-Type": "application/json",
},
},
timeoutMsec || 10000,
app.resolveOptions("p2p").getBlocksTimeout,
);

if (!peerBlocks) {
Expand Down
6 changes: 6 additions & 0 deletions packages/core-p2p/src/peer-connector.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { app } from "@arkecosystem/core-container";
import { P2P } from "@arkecosystem/core-interfaces";
import { create, SCClientSocket } from "socketcluster-client";
import { PeerRepository } from "./peer-repository";
Expand All @@ -21,9 +22,14 @@ export class PeerConnector implements P2P.IPeerConnector {
return connection;
}

// https://socketcluster.io/#!/docs/api-socketcluster-client
connection = create({
port: peer.port,
hostname: peer.ip,
ackTimeout: Math.max(
app.resolveOptions("p2p").getBlocksTimeout,
app.resolveOptions("p2p").verifyTimeout
),
});

this.connections.set(peer.ip, connection);
Expand Down
2 changes: 1 addition & 1 deletion packages/core-p2p/src/peer-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class PeerProcessor implements P2P.IPeerProcessor {
try {
this.storage.setPendingPeer(peer);

await this.communicator.ping(newPeer, 3000);
await this.communicator.ping(newPeer, app.resolveOptions("p2p").verifyTimeout);

this.storage.setPeer(newPeer);

Expand Down
7 changes: 7 additions & 0 deletions packages/core-p2p/src/socket-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const startSocketServer = async (service: P2P.IPeerService, config: Recor
// when testing we also need to get socket files from dist folder
const relativeSocketPath = process.env.CORE_ENV === "test" ? "/../../dist/socket-server" : "";

// https://socketcluster.io/#!/docs/api-socketcluster
const server: SocketCluster = new SocketCluster({
...{
appName: "core-p2p",
Expand All @@ -21,6 +22,12 @@ export const startSocketServer = async (service: P2P.IPeerService, config: Recor
workerController: __dirname + `${relativeSocketPath}/worker.js`,
workers: 2,
wsEngine: "ws",
// See https://github.com/SocketCluster/socketcluster/issues/506 about
// details on how pingTimeout works.
pingTimeout: Math.max(
app.resolveOptions("p2p").getBlocksTimeout,
app.resolveOptions("p2p").verifyTimeout,
),
},
...config.server,
});
Expand Down