Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/2.3.5' of https://github.com/LiskHQ/lisk-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
shuse2 committed Sep 16, 2019
2 parents 87a989c + 56d2616 commit 94c271f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions elements/lisk-p2p/src/p2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ const BASE_10_RADIX = 10;
export const DEFAULT_MAX_OUTBOUND_CONNECTIONS = 20;
export const DEFAULT_MAX_INBOUND_CONNECTIONS = 100;
export const DEFAULT_OUTBOUND_SHUFFLE_INTERVAL = 300000;
export const DEFAULT_OUTBOUND_UPDATE_STATUS_INTERVAL = 2000;
export const DEFAULT_PEER_PROTECTION_FOR_NETGROUP = 0.034;
export const DEFAULT_PEER_PROTECTION_FOR_LATENCY = 0.068;
export const DEFAULT_PEER_PROTECTION_FOR_USEFULNESS = 0.068;
Expand Down Expand Up @@ -448,6 +449,9 @@ export class P2P extends EventEmitter {
outboundShuffleInterval: config.outboundShuffleInterval
? config.outboundShuffleInterval
: DEFAULT_OUTBOUND_SHUFFLE_INTERVAL,
outboundUpdateStatusInterval: config.outboundUpdateStatusInterval
? config.outboundUpdateStatusInterval
: DEFAULT_OUTBOUND_UPDATE_STATUS_INTERVAL,
netgroupProtectionRatio:
typeof config.netgroupProtectionRatio === 'number'
? config.netgroupProtectionRatio
Expand Down
1 change: 1 addition & 0 deletions elements/lisk-p2p/src/p2p_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export interface P2PConfig {
readonly peerBanTime?: number;
readonly sendPeerLimit?: number;
readonly outboundShuffleInterval?: number;
readonly outboundUpdateStatusInterval?: number;
readonly latencyProtectionRatio?: number;
readonly productivityProtectionRatio?: number;
readonly longevityProtectionRatio?: number;
Expand Down
22 changes: 22 additions & 0 deletions elements/lisk-p2p/src/peer_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ interface PeerPoolConfig {
readonly sendPeerLimit: number;
readonly peerBanTime: number;
readonly maxOutboundConnections: number;
readonly outboundUpdateStatusInterval?: number;
readonly maxInboundConnections: number;
readonly maxPeerDiscoveryResponseLength: number;
readonly outboundShuffleInterval: number;
Expand Down Expand Up @@ -191,6 +192,7 @@ export class PeerPool extends EventEmitter {
private readonly _peerSelectForConnection: P2PPeerSelectionForConnectionFunction;
private readonly _sendPeerLimit: number;
private readonly _outboundShuffleIntervalId: NodeJS.Timer | undefined;
private readonly _outboundUpdateStatusId: number;
private readonly _peerConfig: PeerConfig;
private readonly _peerLists: PeerLists;

Expand All @@ -217,6 +219,13 @@ export class PeerPool extends EventEmitter {
this._maxOutboundConnections = peerPoolConfig.maxOutboundConnections;
this._maxInboundConnections = peerPoolConfig.maxInboundConnections;
this._sendPeerLimit = peerPoolConfig.sendPeerLimit;
this._outboundUpdateStatusId = setInterval(() => {
// tslint:disable-next-line: no-floating-promises
(async () => {
await this._updateOutboundConnections();
})().catch(error => error);
}, peerPoolConfig.outboundUpdateStatusInterval);

this._outboundShuffleIntervalId = setInterval(() => {
this._evictPeer(OutboundPeer);
}, peerPoolConfig.outboundShuffleInterval);
Expand Down Expand Up @@ -513,6 +522,7 @@ export class PeerPool extends EventEmitter {
// Clear periodic eviction of outbound peers for shuffling
if (this._outboundShuffleIntervalId) {
clearInterval(this._outboundShuffleIntervalId);
clearInterval(this._outboundUpdateStatusId);
}

this._peerMap.forEach((peer: Peer) => {
Expand Down Expand Up @@ -604,6 +614,18 @@ export class PeerPool extends EventEmitter {
})();
}

private async _updateOutboundConnections(): Promise<void> {
try {
await Promise.all(
this.getConnectedPeers(OutboundPeer).map(async peer =>
peer.fetchStatus().catch(err => err),
),
);
} catch (err) {
return;
}
}

private _selectPeersForEviction(): Peer[] {
const peers = [...this.getPeers(InboundPeer)].filter(peer =>
this._peerLists.whitelisted.every(
Expand Down
2 changes: 2 additions & 0 deletions elements/lisk-p2p/test/unit/peer_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
DEFAULT_PEER_PROTECTION_FOR_LATENCY,
DEFAULT_PEER_PROTECTION_FOR_USEFULNESS,
DEFAULT_PEER_PROTECTION_FOR_LONGEVITY,
DEFAULT_OUTBOUND_UPDATE_STATUS_INTERVAL,
DEFAULT_RANDOM_SECRET,
} from '../../src/p2p';

Expand All @@ -50,6 +51,7 @@ describe('peerPool', () => {
maxOutboundConnections: DEFAULT_MAX_OUTBOUND_CONNECTIONS,
maxInboundConnections: DEFAULT_MAX_INBOUND_CONNECTIONS,
outboundShuffleInterval: DEFAULT_OUTBOUND_SHUFFLE_INTERVAL,
outboundUpdateStatusInterval: DEFAULT_OUTBOUND_UPDATE_STATUS_INTERVAL,
netgroupProtectionRatio: DEFAULT_PEER_PROTECTION_FOR_NETGROUP,
latencyProtectionRatio: DEFAULT_PEER_PROTECTION_FOR_LATENCY,
productivityProtectionRatio: DEFAULT_PEER_PROTECTION_FOR_USEFULNESS,
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/samples/config_devnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"user": "lisk",
"password": "password",
"min": 10,
"max": 95,
"max": 25,
"poolIdleTimeout": 30000,
"reapIntervalMillis": 1000,
"logEvents": ["error"]
Expand Down

0 comments on commit 94c271f

Please sign in to comment.