From 10ce549fa6135f856f304fe74f40cb54713397fc Mon Sep 17 00:00:00 2001 From: Manu Nelamane Siddalingegowda Date: Thu, 5 Sep 2019 14:20:26 +0200 Subject: [PATCH 01/24] :lock: Fix security alerts --- package-lock.json | 60 ++++++++++++++++------------------------------- 1 file changed, 20 insertions(+), 40 deletions(-) diff --git a/package-lock.json b/package-lock.json index f884c92c58a..765db1986fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3002,10 +3002,13 @@ } }, "eslint-utils": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.3.1.tgz", - "integrity": "sha512-Z7YjnIldX+2XMcjr7ZkgEsOj/bREONV60qYeB/bjMAqqqZ4zxKyWX+BOUkdmRmA9riiIPVvo5x86m5elviOk0Q==", - "dev": true + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.4.2.tgz", + "integrity": "sha512-eAZS2sEUMlIeCjBeubdj45dmBHQwPHWyBcT1VSYB7o9x9WRRqKxyUoiXlRjyAwzN7YEzHJlYg0NmzDRWx6GP4Q==", + "dev": true, + "requires": { + "eslint-visitor-keys": "^1.0.0" + } }, "eslint-visitor-keys": { "version": "1.0.0", @@ -4961,9 +4964,9 @@ } }, "lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", "dev": true }, "lodash._reinterpolate": { @@ -5347,9 +5350,9 @@ } }, "mixin-deep": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.1.tgz", - "integrity": "sha512-8ZItLHeEgaqEvd5lYBXfm4EZSFCX29Jb9K+lAHhDKzReKBQKj3R+7NOF6tjqYi9t4oI8VUfaWITJQm86wnXGNQ==", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.2.tgz", + "integrity": "sha512-WRoDn//mXBiJ1H40rqa3vH0toePwSsGb45iInWlTySa+Uu4k3tYUSxa2v1KqAiLtvlrSzaExqS1gtk96A9zvEA==", "dev": true, "requires": { "for-in": "^1.0.2", @@ -6695,9 +6698,9 @@ "dev": true }, "set-value": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.0.tgz", - "integrity": "sha512-hw0yxk9GT/Hr5yJEYnHNKYXkIA8mVJgd9ditYZCe16ZczcaELYYcfvaXesNACk2O8O0nTiPQcQhGUQj8JLzeeg==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.1.tgz", + "integrity": "sha512-JxHc1weCN68wRY0fhCoXpyK55m/XPHafOmK4UWD7m2CI14GMcFypt4w/0+NV5f/ZMby2F6S2wwA7fgynh9gWSw==", "dev": true, "requires": { "extend-shallow": "^2.0.1", @@ -7575,38 +7578,15 @@ "dev": true }, "union-value": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.0.tgz", - "integrity": "sha1-XHHDTLW61dzr4+oM0IIHulqhrqQ=", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz", + "integrity": "sha512-tJfXmxMeWYnczCVs7XAEvIV7ieppALdyepWMkHkwciRpZraG/xwT+s2JN8+pr1+8jCRf80FFzvr+MpQeeoF4Xg==", "dev": true, "requires": { "arr-union": "^3.1.0", "get-value": "^2.0.6", "is-extendable": "^0.1.1", - "set-value": "^0.4.3" - }, - "dependencies": { - "extend-shallow": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", - "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", - "dev": true, - "requires": { - "is-extendable": "^0.1.0" - } - }, - "set-value": { - "version": "0.4.3", - "resolved": "https://registry.npmjs.org/set-value/-/set-value-0.4.3.tgz", - "integrity": "sha1-fbCPnT0i3H945Trzw79GZuzfzPE=", - "dev": true, - "requires": { - "extend-shallow": "^2.0.1", - "is-extendable": "^0.1.1", - "is-plain-object": "^2.0.1", - "to-object-path": "^0.3.0" - } - } + "set-value": "^2.0.1" } }, "unique-filename": { From 17841f98d321239c65317269bc30eb392def30f8 Mon Sep 17 00:00:00 2001 From: Shusetsu Toda Date: Thu, 5 Sep 2019 15:50:19 +0200 Subject: [PATCH 02/24] :recycle: Fix cache logging and destruction --- framework/src/modules/http_api/controllers/node.js | 13 +++++-------- .../src/modules/http_api/fittings/lisk_cache.js | 8 ++++---- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/framework/src/modules/http_api/controllers/node.js b/framework/src/modules/http_api/controllers/node.js index 2bb25024e7e..64a8e91f036 100644 --- a/framework/src/modules/http_api/controllers/node.js +++ b/framework/src/modules/http_api/controllers/node.js @@ -99,17 +99,14 @@ async function _getConfirmedTransactionCount() { // if cache is ready, then get cache and return if (library.components.cache.ready) { try { - const { confirmed } = await library.components.cache.getJsonForKey( + const data = await library.components.cache.getJsonForKey( CACHE_KEYS_TRANSACTION_COUNT, ); - if (confirmed === undefined || confirmed === null) { - throw new Error( - 'Transaction count wasn cached but confirmed did not exist', - ); + if (data && data.confirmed !== null && data.confirmed !== undefined) { + return data.confirmed; } - return confirmed; } catch (error) { - library.components.logger.warn("Transaction count wasn't cached", error); + library.components.logger.debug("Transaction count wasn't cached"); } } const confirmed = await library.components.storage.entities.Transaction.count(); @@ -124,7 +121,7 @@ async function _getConfirmedTransactionCount() { ); } catch (error) { // Ignore error and just put warn - library.components.logger.warn("Transaction count wasn't cached", error); + library.components.logger.debug(error, "Transaction count wasn't cached"); } } return confirmed; diff --git a/framework/src/modules/http_api/fittings/lisk_cache.js b/framework/src/modules/http_api/fittings/lisk_cache.js index 38b6e826880..87aafdf52d4 100644 --- a/framework/src/modules/http_api/fittings/lisk_cache.js +++ b/framework/src/modules/http_api/fittings/lisk_cache.js @@ -82,7 +82,7 @@ module.exports = function create(fittingDef) { .getJsonForKey(cacheKey) .then(cachedValue => { if (cachedValue) { - logger.debug( + logger.trace( 'Cache - Sending cached response for url:', context.request.url, ); @@ -91,7 +91,7 @@ module.exports = function create(fittingDef) { return next(null, context.input); }) .catch(getJsonForKeyErr => { - logger.debug(getJsonForKeyErr.message); + logger.trace(getJsonForKeyErr.message); return next(null, context.input); }); } @@ -99,7 +99,7 @@ module.exports = function create(fittingDef) { // If cache fitting is called after response processing if (mode === 'post_response') { if (context.statusCode === 200 || context.response.statusCode === 200) { - logger.debug( + logger.trace( 'Cache - Setting response cache for url:', context.request.url, ); @@ -107,7 +107,7 @@ module.exports = function create(fittingDef) { .setJsonForKey(cacheKey, context.input) .then(() => next(null, context.input)) .catch(error => { - logger.debug(error.message); + logger.trace(error.message); return next(null, context.input); }); } From cd2991a394277d29dc1b6df2d4a993a8ada345d5 Mon Sep 17 00:00:00 2001 From: Shusetsu Toda Date: Thu, 5 Sep 2019 16:04:39 +0200 Subject: [PATCH 03/24] :bug: Fix invalid event handling on network event --- framework/src/modules/chain/chain.js | 39 ++++++++++++------- .../src/modules/chain/transport/transport.js | 27 +++---------- .../functional/ws/transport/transport.js | 22 ++++++++++- 3 files changed, 51 insertions(+), 37 deletions(-) diff --git a/framework/src/modules/chain/chain.js b/framework/src/modules/chain/chain.js index 7c9d5a7e797..080b029855a 100644 --- a/framework/src/modules/chain/chain.js +++ b/framework/src/modules/chain/chain.js @@ -170,21 +170,30 @@ module.exports = class Chain { // Avoid receiving blocks/transactions from the network during snapshotting process if (!this.options.loading.rebuildUpToRound) { - this.channel.subscribe('network:event', ({ data: { event, data } }) => { - if (event === 'postTransactions') { - this.transport.postTransactions(data); - return; - } - if (event === 'postSignatures') { - this.transport.postSignatures(data); - return; - } - if (event === 'postBlock') { - this.transport.postBlock(data); - // eslint-disable-next-line no-useless-return - return; - } - }); + this.channel.subscribe( + 'network:event', + async ({ data: { event, data } }) => { + try { + if (event === 'postTransactions') { + await this.transport.postTransactions(data); + return; + } + if (event === 'postSignatures') { + await this.transport.postSignatures(data); + return; + } + if (event === 'postBlock') { + await this.transport.postBlock(data); + return; + } + } catch (error) { + this.logger.info( + { error, event, data }, + 'Received invalid event message', + ); + } + }, + ); } } catch (error) { this.logger.fatal('Chain initialization', { diff --git a/framework/src/modules/chain/transport/transport.js b/framework/src/modules/chain/transport/transport.js index ed7543da5c5..4213c0a78a3 100644 --- a/framework/src/modules/chain/transport/transport.js +++ b/framework/src/modules/chain/transport/transport.js @@ -363,28 +363,16 @@ class Transport { query, }, ); - throw new Error(errors); + throw errors; } let block; - let success = true; - try { - block = blocksUtils.addBlockProperties(query.block); + block = blocksUtils.addBlockProperties(query.block); - // Instantiate transaction classes - block.transactions = this.interfaceAdapters.transactions.fromBlock(block); - - block = blocksUtils.objectNormalize(block); - } catch (e) { - success = false; - this.logger.debug('Block normalization failed', { - err: e.toString(), - module: 'transport', - block: query.block, - }); + // Instantiate transaction classes + block.transactions = this.interfaceAdapters.transactions.fromBlock(block); - // TODO: If there is an error, invoke the applyPenalty action on the Network module once it is implemented. - } + block = blocksUtils.objectNormalize(block); // TODO: endpoint should be protected before if (this.loaderModule.syncing()) { return this.logger.debug( @@ -392,10 +380,7 @@ class Transport { block.id, ); } - if (success) { - return this.blocksModule.receiveBlockFromNetwork(block); - } - return null; + return this.blocksModule.receiveBlockFromNetwork(block); } /** diff --git a/framework/test/mocha/functional/ws/transport/transport.js b/framework/test/mocha/functional/ws/transport/transport.js index e65b23bdea7..f260461bcce 100644 --- a/framework/test/mocha/functional/ws/transport/transport.js +++ b/framework/test/mocha/functional/ws/transport/transport.js @@ -32,7 +32,7 @@ describe('WS transport', () => { let p2p; function postTransaction(transactionToPost) { - p2p.send({ + return p2p.send({ event: 'postTransactions', data: { nonce: 'sYHEDBKcScaAAAYg', @@ -72,6 +72,10 @@ describe('WS transport', () => { goodTransactions.push(transaction); done(); }); + + it('should not crash the application', async () => { + await postTransaction('Invalid transaction'); + }); }); describe('confirmation', () => { @@ -379,6 +383,22 @@ describe('WS transport', () => { }); await p2p.send({ event: 'postBlock', data: { block: testBlock } }); }); + + it('should not crash the application when sending the invalid block', async () => { + await p2p.send({ + event: 'postBlock', + data: { block: { generatorPublicKey: '123' } }, + }); + }); + }); + + describe('postSignatures', () => { + it('should not crash the application when sending the invalid signatures', async () => { + await p2p.send({ + event: 'postSignatures', + data: { signatures: ['not object signature'] }, + }); + }); }); }); }); From d0ff273d05cc76a10d9c365de67760d2c4a5a745 Mon Sep 17 00:00:00 2001 From: Shusetsu Toda Date: Thu, 5 Sep 2019 16:30:20 +0200 Subject: [PATCH 04/24] :recycle: Add logs for starting genesis block apply --- framework/src/modules/chain/blocks/blocks.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/framework/src/modules/chain/blocks/blocks.js b/framework/src/modules/chain/blocks/blocks.js index c80e7e038aa..b8e91955ea4 100644 --- a/framework/src/modules/chain/blocks/blocks.js +++ b/framework/src/modules/chain/blocks/blocks.js @@ -241,6 +241,7 @@ class Blocks extends EventEmitter { }, ); if (blocksCount === 1) { + this.logger.info('Applying genesis block'); this._lastBlock = await this._reload(blocksCount); this._isActive = false; return; @@ -580,7 +581,7 @@ class Blocks extends EventEmitter { this._lastBlock = block; this.logger.info( { blockId: block.id, height: block.height }, - 'Rebuilding block', + 'Rebuilt block', ); }, ); From 756522d3283360683bf28e2138a82789cac561c4 Mon Sep 17 00:00:00 2001 From: Shusetsu Toda Date: Thu, 5 Sep 2019 16:44:08 +0200 Subject: [PATCH 05/24] :white_check_mark: Fix unit test --- .../unit/modules/chain/transport/transport.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/framework/test/mocha/unit/modules/chain/transport/transport.js b/framework/test/mocha/unit/modules/chain/transport/transport.js index df6457f5fb9..46cb08fb739 100644 --- a/framework/test/mocha/unit/modules/chain/transport/transport.js +++ b/framework/test/mocha/unit/modules/chain/transport/transport.js @@ -895,19 +895,15 @@ describe('transport', () => { beforeEach(async () => { sinonSandbox .stub(blocksModule, 'objectNormalize') - .throws(blockValidationError); - transportModule.postBlock(postBlockQuery); + .throws(new Error(blockValidationError)); }); - it('should call transportModule.logger.debug with "Block normalization failed" and {err: error, module: "transport", block: query.block }', async () => { - expect(transportModule.logger.debug).to.be.calledWith( - 'Block normalization failed', - { - err: blockValidationError.toString(), - module: 'transport', - block: blockMock, - }, - ); + it('should throw an error', async () => { + try { + await transportModule.postBlock(postBlockQuery); + } catch (err) { + expect(err.message).to.equal(blockValidationError); + } }); }); From 74c15141503dda8776be55797e83ec6dd818c19a Mon Sep 17 00:00:00 2001 From: Shusetsu Toda Date: Thu, 5 Sep 2019 17:02:11 +0200 Subject: [PATCH 06/24] :recycle: Update log message --- framework/src/modules/http_api/controllers/node.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/framework/src/modules/http_api/controllers/node.js b/framework/src/modules/http_api/controllers/node.js index 64a8e91f036..3a7a4e3fbe0 100644 --- a/framework/src/modules/http_api/controllers/node.js +++ b/framework/src/modules/http_api/controllers/node.js @@ -121,7 +121,10 @@ async function _getConfirmedTransactionCount() { ); } catch (error) { // Ignore error and just put warn - library.components.logger.debug(error, "Transaction count wasn't cached"); + library.components.logger.debug( + error, + 'Failed to cache Transaction count', + ); } } return confirmed; From bc27505e42adf05ff70bb26655b6d8231ff6593e Mon Sep 17 00:00:00 2001 From: Shusetsu Toda Date: Thu, 5 Sep 2019 17:04:16 +0200 Subject: [PATCH 07/24] :recycle: Update log message --- framework/src/modules/chain/blocks/blocks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/modules/chain/blocks/blocks.js b/framework/src/modules/chain/blocks/blocks.js index b8e91955ea4..9f1539a82fd 100644 --- a/framework/src/modules/chain/blocks/blocks.js +++ b/framework/src/modules/chain/blocks/blocks.js @@ -581,7 +581,7 @@ class Blocks extends EventEmitter { this._lastBlock = block; this.logger.info( { blockId: block.id, height: block.height }, - 'Rebuilt block', + 'Reloaded block', ); }, ); From 1f4ec4225072e519449c9f4a029d6e002ce68950 Mon Sep 17 00:00:00 2001 From: Ishan Date: Thu, 5 Sep 2019 17:46:58 +0200 Subject: [PATCH 08/24] Accept a peer object with ip and port instead of only array of ips --- .../src/modules/network/defaults/config.js | 48 ++++++++++++++++--- framework/src/modules/network/network.js | 3 ++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/framework/src/modules/network/defaults/config.js b/framework/src/modules/network/defaults/config.js index ead4e8842cc..5d3ed1b5967 100644 --- a/framework/src/modules/network/defaults/config.js +++ b/framework/src/modules/network/defaults/config.js @@ -52,27 +52,63 @@ const defaultConfig = { blacklistedPeers: { type: 'array', items: { - type: 'string', - format: 'ip', + type: 'object', + properties: { + ip: { + type: 'string', + format: 'ipOrFQDN', + }, + wsPort: { + type: 'integer', + minimum: 1, + maximum: 65535, + }, + }, }, + env: { variable: 'LISK_PEERS', formatter: 'stringToIpPortSet' }, + arg: { name: '--peers,-x', formatter: 'stringToIpPortSet' }, }, // Warning! The connectivity of the node might be negatively impacted if using this option. fixedPeers: { type: 'array', items: { - type: 'string', - format: 'ip', + type: 'object', + properties: { + ip: { + type: 'string', + format: 'ipOrFQDN', + }, + wsPort: { + type: 'integer', + minimum: 1, + maximum: 65535, + }, + }, }, maximum: 4, + env: { variable: 'LISK_PEERS', formatter: 'stringToIpPortSet' }, + arg: { name: '--peers,-x', formatter: 'stringToIpPortSet' }, }, // Warning! Beware of declaring only trustworthy peers in this array as these could attack a // node with a denial-of-service attack because the banning mechanism is deactivated. whitelistedPeers: { type: 'array', items: { - type: 'string', - format: 'ip', + type: 'object', + properties: { + ip: { + type: 'string', + format: 'ipOrFQDN', + }, + wsPort: { + type: 'integer', + minimum: 1, + maximum: 65535, + }, + }, }, + env: { variable: 'LISK_PEERS', formatter: 'stringToIpPortSet' }, + arg: { name: '--peers,-x', formatter: 'stringToIpPortSet' }, }, discoveryInterval: { type: 'integer', diff --git a/framework/src/modules/network/network.js b/framework/src/modules/network/network.js index e2d122eb9aa..24f8f204ed6 100644 --- a/framework/src/modules/network/network.js +++ b/framework/src/modules/network/network.js @@ -114,16 +114,19 @@ module.exports = class Network { const blacklistedPeers = this.options.blacklistedPeers ? this.options.blacklistedPeers.map(peer => ({ ipAddress: peer.ip, + wsPort: peer.wsPort, })) : []; const fixedPeers = this.options.fixedPeers ? this.options.fixedPeers.map(peer => ({ ipAddress: peer.ip, + wsPort: peer.wsPort, })) : []; const whitelistedPeers = this.options.whiteListedPeers ? this.options.whiteListedPeers.map(peer => ({ ipAddress: peer.ip, + wsPort: peer.wsPort, })) : []; From 75ca8092da579f5c87c2d0826807484bb0b89b6e Mon Sep 17 00:00:00 2001 From: Ishan Date: Thu, 5 Sep 2019 17:52:29 +0200 Subject: [PATCH 09/24] Introduce peerlists in PeerPool to handle them in connections --- elements/lisk-p2p/src/p2p.ts | 1 + elements/lisk-p2p/src/peer_pool.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/elements/lisk-p2p/src/p2p.ts b/elements/lisk-p2p/src/p2p.ts index 12924e7539f..fa7e66c363d 100644 --- a/elements/lisk-p2p/src/p2p.ts +++ b/elements/lisk-p2p/src/p2p.ts @@ -477,6 +477,7 @@ export class P2P extends EventEmitter { ? config.rateCalculationInterval : DEFAULT_RATE_CALCULATION_INTERVAL, secret: config.secret ? config.secret : DEFAULT_RANDOM_SECRET, + peerList: this._sanitizedPeerLists, }); this._bindHandlersToPeerPool(this._peerPool); diff --git a/elements/lisk-p2p/src/peer_pool.ts b/elements/lisk-p2p/src/peer_pool.ts index ad48a5d66ba..d9ec6638cb4 100644 --- a/elements/lisk-p2p/src/peer_pool.ts +++ b/elements/lisk-p2p/src/peer_pool.ts @@ -37,6 +37,7 @@ import { P2PPenalty, P2PRequestPacket, P2PResponsePacket, + PeerLists, } from './p2p_types'; import { ConnectionState, @@ -109,6 +110,7 @@ interface PeerPoolConfig { readonly wsMaxMessageRatePenalty: number; readonly rateCalculationInterval: number; readonly secret: number; + readonly peerList: PeerLists; } export const MAX_PEER_LIST_BATCH_SIZE = 100; @@ -190,6 +192,7 @@ export class PeerPool extends EventEmitter { private readonly _sendPeerLimit: number; private readonly _outboundShuffleIntervalId: NodeJS.Timer | undefined; private readonly _peerConfig: PeerConfig; + private readonly _peerLists: PeerLists; public constructor(peerPoolConfig: PeerPoolConfig) { super(); @@ -207,6 +210,7 @@ export class PeerPool extends EventEmitter { maxPeerInfoSize: this._peerPoolConfig.maxPeerInfoSize, secret: this._peerPoolConfig.secret, }; + this._peerLists = peerPoolConfig.peerList; this._peerSelectForSend = peerPoolConfig.peerSelectionForSend; this._peerSelectForRequest = peerPoolConfig.peerSelectionForRequest; this._peerSelectForConnection = peerPoolConfig.peerSelectionForConnection; From 7a5ac876ecab6a53ea6c550a370ae642cf60cde0 Mon Sep 17 00:00:00 2001 From: Ishan Date: Thu, 5 Sep 2019 18:01:31 +0200 Subject: [PATCH 10/24] Dont evict fixed peer during shuffling and whitelist peer during eviction from inbounds --- elements/lisk-p2p/src/peer_pool.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/elements/lisk-p2p/src/peer_pool.ts b/elements/lisk-p2p/src/peer_pool.ts index d9ec6638cb4..e513750f7e5 100644 --- a/elements/lisk-p2p/src/peer_pool.ts +++ b/elements/lisk-p2p/src/peer_pool.ts @@ -601,7 +601,13 @@ export class PeerPool extends EventEmitter { } private _selectPeersForEviction(): Peer[] { - const peers = [...this.getPeers(InboundPeer)]; + const peers = [...this.getPeers(InboundPeer)].filter(peer => { + const found = this._peerLists.whitelisted.find( + whitePeer => constructPeerIdFromPeerInfo(whitePeer) === peer.id, + ); + + return found ? false : true; + }); // Cannot predict which netgroups will be protected const filteredPeersByNetgroup = this._peerPoolConfig.netgroupProtectionRatio ? filterPeersByCategory(peers, { @@ -659,7 +665,15 @@ export class PeerPool extends EventEmitter { } if (kind === OutboundPeer) { - const selectedPeer = shuffle(peers)[0]; + const selectedPeer = shuffle( + peers.filter(peer => { + const found = this._peerLists.fixedPeers.find( + fixedPeer => constructPeerIdFromPeerInfo(fixedPeer) === peer.id, + ); + + return found ? false : true; + }), + )[0]; if (selectedPeer) { this.removePeer( selectedPeer.id, From 155c23c050ca91f7b526011b402beb568d47d101 Mon Sep 17 00:00:00 2001 From: Ishan Date: Thu, 5 Sep 2019 18:09:25 +0200 Subject: [PATCH 11/24] Get a peer by id from the peer map instead by reference --- elements/lisk-p2p/src/peer_pool.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/elements/lisk-p2p/src/peer_pool.ts b/elements/lisk-p2p/src/peer_pool.ts index e513750f7e5..40eb272819e 100644 --- a/elements/lisk-p2p/src/peer_pool.ts +++ b/elements/lisk-p2p/src/peer_pool.ts @@ -402,17 +402,17 @@ export class PeerPool extends EventEmitter { // Try to connect to disconnected peers without including the fixed ones which are specially treated thereafter const disconnectedNewPeers = newPeers.filter( peer => - !this._peerMap.has(constructPeerIdFromPeerInfo(peer)) || + !this._peerMap.get(constructPeerIdFromPeerInfo(peer)) || !fixedPeers.includes(peer), ); const disconnectedTriedPeers = triedPeers.filter( peer => - !this._peerMap.has(constructPeerIdFromPeerInfo(peer)) || + !this._peerMap.get(constructPeerIdFromPeerInfo(peer)) || !fixedPeers.includes(peer), ); const { outboundCount } = this.getPeersCountPerKind(); const disconnectedFixedPeers = fixedPeers - .filter(peer => !this._peerMap.has(constructPeerIdFromPeerInfo(peer))) + .filter(peer => !this._peerMap.get(constructPeerIdFromPeerInfo(peer))) .map(peer2Convert => peer2Convert as P2PDiscoveredPeerInfo); // Trigger new connections only if the maximum of outbound connections has not been reached From 5d3e66ebbc7b93af129587cdf1f30172fa1ad3fc Mon Sep 17 00:00:00 2001 From: Ishan Date: Thu, 5 Sep 2019 18:42:06 +0200 Subject: [PATCH 12/24] Add whitelist peers to triedPeers on startup --- elements/lisk-p2p/src/p2p.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/elements/lisk-p2p/src/p2p.ts b/elements/lisk-p2p/src/p2p.ts index fa7e66c363d..9e4513b2b11 100644 --- a/elements/lisk-p2p/src/p2p.ts +++ b/elements/lisk-p2p/src/p2p.ts @@ -898,6 +898,10 @@ export class P2P extends EventEmitter { } }); + // According to LIP, add whitelist peers to triedPeer by upgrading them initially. + this._sanitizedPeerLists.whitelisted.forEach(whitelistPeer => + this._peerBook.upgradePeer(whitelistPeer), + ); await this._startPeerServer(); // We need this check this._isActive in case the P2P library is shut down while it was in the middle of starting up. From c8270fb0bea7b5bc7c4471625802e688f74df8a9 Mon Sep 17 00:00:00 2001 From: Shusetsu Toda Date: Fri, 6 Sep 2019 09:05:46 +0200 Subject: [PATCH 13/24] :recycle: Remove data and increase log level --- framework/src/modules/chain/chain.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/src/modules/chain/chain.js b/framework/src/modules/chain/chain.js index 080b029855a..524ef807bd3 100644 --- a/framework/src/modules/chain/chain.js +++ b/framework/src/modules/chain/chain.js @@ -187,8 +187,8 @@ module.exports = class Chain { return; } } catch (error) { - this.logger.info( - { error, event, data }, + this.logger.warn( + { error, event }, 'Received invalid event message', ); } From cea655360628a8d3aaedad7522b81340d3daa803 Mon Sep 17 00:00:00 2001 From: Ishan Date: Fri, 6 Sep 2019 11:08:24 +0200 Subject: [PATCH 14/24] Use only ip for blacklisted peers --- .../src/modules/network/defaults/config.js | 20 ++++--------------- framework/src/modules/network/network.js | 8 ++------ 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/framework/src/modules/network/defaults/config.js b/framework/src/modules/network/defaults/config.js index 5d3ed1b5967..a298aa5decc 100644 --- a/framework/src/modules/network/defaults/config.js +++ b/framework/src/modules/network/defaults/config.js @@ -52,21 +52,9 @@ const defaultConfig = { blacklistedPeers: { type: 'array', items: { - type: 'object', - properties: { - ip: { - type: 'string', - format: 'ipOrFQDN', - }, - wsPort: { - type: 'integer', - minimum: 1, - maximum: 65535, - }, - }, + type: 'string', + format: 'ip', }, - env: { variable: 'LISK_PEERS', formatter: 'stringToIpPortSet' }, - arg: { name: '--peers,-x', formatter: 'stringToIpPortSet' }, }, // Warning! The connectivity of the node might be negatively impacted if using this option. fixedPeers: { @@ -76,7 +64,7 @@ const defaultConfig = { properties: { ip: { type: 'string', - format: 'ipOrFQDN', + format: 'ip', }, wsPort: { type: 'integer', @@ -98,7 +86,7 @@ const defaultConfig = { properties: { ip: { type: 'string', - format: 'ipOrFQDN', + format: 'ip', }, wsPort: { type: 'integer', diff --git a/framework/src/modules/network/network.js b/framework/src/modules/network/network.js index 24f8f204ed6..0b8b651b5f8 100644 --- a/framework/src/modules/network/network.js +++ b/framework/src/modules/network/network.js @@ -111,12 +111,8 @@ module.exports = class Network { ); const seedPeers = await lookupPeersIPs(this.options.seedPeers, true); - const blacklistedPeers = this.options.blacklistedPeers - ? this.options.blacklistedPeers.map(peer => ({ - ipAddress: peer.ip, - wsPort: peer.wsPort, - })) - : []; + const blacklistedPeers = this.options.blacklistedPeers || []; + const fixedPeers = this.options.fixedPeers ? this.options.fixedPeers.map(peer => ({ ipAddress: peer.ip, From 6236206b52fb3a314cbe8ab59271e5c23211a829 Mon Sep 17 00:00:00 2001 From: Ishan Date: Fri, 6 Sep 2019 11:18:16 +0200 Subject: [PATCH 15/24] Check with ip adress for fixed peers and improve filter for fixed/white list --- elements/lisk-p2p/src/peer_pool.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/elements/lisk-p2p/src/peer_pool.ts b/elements/lisk-p2p/src/peer_pool.ts index 40eb272819e..0823aa57ed2 100644 --- a/elements/lisk-p2p/src/peer_pool.ts +++ b/elements/lisk-p2p/src/peer_pool.ts @@ -401,14 +401,18 @@ export class PeerPool extends EventEmitter { ): void { // Try to connect to disconnected peers without including the fixed ones which are specially treated thereafter const disconnectedNewPeers = newPeers.filter( - peer => - !this._peerMap.get(constructPeerIdFromPeerInfo(peer)) || - !fixedPeers.includes(peer), + newPeer => + !this._peerMap.has(constructPeerIdFromPeerInfo(newPeer)) || + !fixedPeers + .map(fixedPeer => fixedPeer.ipAddress) + .includes(newPeer.ipAddress), ); const disconnectedTriedPeers = triedPeers.filter( - peer => - !this._peerMap.get(constructPeerIdFromPeerInfo(peer)) || - !fixedPeers.includes(peer), + triedPeer => + !this._peerMap.has(constructPeerIdFromPeerInfo(triedPeer)) || + !fixedPeers + .map(fixedPeer => fixedPeer.ipAddress) + .includes(triedPeer.ipAddress), ); const { outboundCount } = this.getPeersCountPerKind(); const disconnectedFixedPeers = fixedPeers @@ -602,12 +606,13 @@ export class PeerPool extends EventEmitter { private _selectPeersForEviction(): Peer[] { const peers = [...this.getPeers(InboundPeer)].filter(peer => { - const found = this._peerLists.whitelisted.find( + const found = !!this._peerLists.whitelisted.find( whitePeer => constructPeerIdFromPeerInfo(whitePeer) === peer.id, ); - return found ? false : true; + return !found; }); + // Cannot predict which netgroups will be protected const filteredPeersByNetgroup = this._peerPoolConfig.netgroupProtectionRatio ? filterPeersByCategory(peers, { @@ -667,11 +672,11 @@ export class PeerPool extends EventEmitter { if (kind === OutboundPeer) { const selectedPeer = shuffle( peers.filter(peer => { - const found = this._peerLists.fixedPeers.find( + const found = !!this._peerLists.fixedPeers.find( fixedPeer => constructPeerIdFromPeerInfo(fixedPeer) === peer.id, ); - return found ? false : true; + return !found; }), )[0]; if (selectedPeer) { From 5f264baed31e5a3a41676d2cc4d748ac2f54097e Mon Sep 17 00:00:00 2001 From: Ishan Date: Fri, 6 Sep 2019 12:09:29 +0200 Subject: [PATCH 16/24] Correct wrong whitelistedPeers config name in network --- framework/src/modules/network/network.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/framework/src/modules/network/network.js b/framework/src/modules/network/network.js index 0b8b651b5f8..6029a1545ea 100644 --- a/framework/src/modules/network/network.js +++ b/framework/src/modules/network/network.js @@ -119,8 +119,9 @@ module.exports = class Network { wsPort: peer.wsPort, })) : []; - const whitelistedPeers = this.options.whiteListedPeers - ? this.options.whiteListedPeers.map(peer => ({ + + const whitelistedPeers = this.options.whitelistedPeers + ? this.options.whitelistedPeers.map(peer => ({ ipAddress: peer.ip, wsPort: peer.wsPort, })) From 203478fd0e7573580ac3cebde52623bc4d5c4a93 Mon Sep 17 00:00:00 2001 From: Shusetsu Toda Date: Fri, 6 Sep 2019 12:11:19 +0200 Subject: [PATCH 17/24] :recycle: Add comment back --- framework/src/modules/chain/transport/transport.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/framework/src/modules/chain/transport/transport.js b/framework/src/modules/chain/transport/transport.js index 4213c0a78a3..5bf2e03e9e7 100644 --- a/framework/src/modules/chain/transport/transport.js +++ b/framework/src/modules/chain/transport/transport.js @@ -363,6 +363,7 @@ class Transport { query, }, ); + // TODO: If there is an error, invoke the applyPenalty action on the Network module once it is implemented. throw errors; } @@ -434,6 +435,7 @@ class Transport { if (errors.length) { this.logger.debug('Invalid signatures body', errors); + // TODO: If there is an error, invoke the applyPenalty action on the Network module once it is implemented. throw errors; } @@ -528,6 +530,7 @@ class Transport { if (errors.length) { this.logger.debug('Invalid transactions body', errors); + // TODO: If there is an error, invoke the applyPenalty action on the Network module once it is implemented. throw errors; } From ecf85fdbf901924d0c5e6178c795981dbc1cfd80 Mon Sep 17 00:00:00 2001 From: Jonathan Gros-Dubois Date: Mon, 2 Sep 2019 11:45:55 +0200 Subject: [PATCH 18/24] Ban peers if they exceed rate limit --- elements/lisk-p2p/src/p2p.ts | 2 +- elements/lisk-p2p/src/peer/base.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/elements/lisk-p2p/src/p2p.ts b/elements/lisk-p2p/src/p2p.ts index 12924e7539f..057c87e0c19 100644 --- a/elements/lisk-p2p/src/p2p.ts +++ b/elements/lisk-p2p/src/p2p.ts @@ -127,7 +127,7 @@ export const DEFAULT_POPULATOR_INTERVAL = 10000; export const DEFAULT_SEND_PEER_LIMIT = 25; // Max rate of WebSocket messages per second per peer. export const DEFAULT_WS_MAX_MESSAGE_RATE = 100; -export const DEFAULT_WS_MAX_MESSAGE_RATE_PENALTY = 10; +export const DEFAULT_WS_MAX_MESSAGE_RATE_PENALTY = 100; export const DEFAULT_RATE_CALCULATION_INTERVAL = 1000; export const DEFAULT_WS_MAX_PAYLOAD = 3048576; // Size in bytes diff --git a/elements/lisk-p2p/src/peer/base.ts b/elements/lisk-p2p/src/peer/base.ts index 545fc5de8a3..c2183ddfb19 100644 --- a/elements/lisk-p2p/src/peer/base.ts +++ b/elements/lisk-p2p/src/peer/base.ts @@ -210,7 +210,6 @@ export class Peer extends EventEmitter { this._wsMessageCount = 0; if (this._wsMessageRate > this._peerConfig.wsMaxMessageRate) { - this.disconnect(FORBIDDEN_CONNECTION, FORBIDDEN_CONNECTION_REASON); this.applyPenalty(this._peerConfig.wsMaxMessageRatePenalty); return; From 5d4b14adb2685193d95f3694e245760f18c31d2a Mon Sep 17 00:00:00 2001 From: Ishan Date: Fri, 6 Sep 2019 13:30:19 +0200 Subject: [PATCH 19/24] Rename config variable blacklistedPeers -> blacklistedIps --- framework/src/modules/network/defaults/config.js | 4 ++-- framework/src/modules/network/network.js | 2 +- .../specs/controller/__snapshots__/application.spec.js.snap | 2 +- sdk/src/samples/config_devnet.json | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/framework/src/modules/network/defaults/config.js b/framework/src/modules/network/defaults/config.js index a298aa5decc..ea88b14dd7c 100644 --- a/framework/src/modules/network/defaults/config.js +++ b/framework/src/modules/network/defaults/config.js @@ -49,7 +49,7 @@ const defaultConfig = { env: { variable: 'LISK_PEERS', formatter: 'stringToIpPortSet' }, arg: { name: '--peers,-x', formatter: 'stringToIpPortSet' }, // TODO: Need to confirm parsing logic, old logic was using network WSPort to be default port for peers, we don't have it at the time of compilation }, - blacklistedPeers: { + blacklistedIps: { type: 'array', items: { type: 'string', @@ -151,7 +151,7 @@ const defaultConfig = { peerBanTime: 86400, populatorInterval: 10000, seedPeers: [], - blacklistedPeers: [], + blacklistedIps: [], fixedPeers: [], whitelistedPeers: [], ackTimeout: 20000, diff --git a/framework/src/modules/network/network.js b/framework/src/modules/network/network.js index 6029a1545ea..017b55cf7b5 100644 --- a/framework/src/modules/network/network.js +++ b/framework/src/modules/network/network.js @@ -111,7 +111,7 @@ module.exports = class Network { ); const seedPeers = await lookupPeersIPs(this.options.seedPeers, true); - const blacklistedPeers = this.options.blacklistedPeers || []; + const blacklistedPeers = this.options.blacklistedIps || []; const fixedPeers = this.options.fixedPeers ? this.options.fixedPeers.map(peer => ({ diff --git a/framework/test/jest/unit/specs/controller/__snapshots__/application.spec.js.snap b/framework/test/jest/unit/specs/controller/__snapshots__/application.spec.js.snap index 62b16efb180..2470c4c981c 100644 --- a/framework/test/jest/unit/specs/controller/__snapshots__/application.spec.js.snap +++ b/framework/test/jest/unit/specs/controller/__snapshots__/application.spec.js.snap @@ -564,7 +564,7 @@ Object { "network": Object { "ackTimeout": 20000, "address": "0.0.0.0", - "blacklistedPeers": Array [], + "blacklistedIps": Array [], "connectTimeout": 5000, "discoveryInterval": 30000, "emitPeerLimit": 25, diff --git a/sdk/src/samples/config_devnet.json b/sdk/src/samples/config_devnet.json index 70cb46b1d89..af59790c00d 100644 --- a/sdk/src/samples/config_devnet.json +++ b/sdk/src/samples/config_devnet.json @@ -548,7 +548,7 @@ "wsPort": 5000 } ], - "blacklistedPeers": [], + "blacklistedIps": [], "ackTimeout": 20000, "connectTimeout": 5000, "wsEngine": "ws", From 85af0f5f0898a7ecb9fa688e378718e6aa5f9e54 Mon Sep 17 00:00:00 2001 From: Shusetsu Toda Date: Fri, 6 Sep 2019 13:42:19 +0200 Subject: [PATCH 20/24] :fire: Remove unnecessary declaration --- framework/src/modules/chain/transport/transport.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/framework/src/modules/chain/transport/transport.js b/framework/src/modules/chain/transport/transport.js index 5bf2e03e9e7..2871039ba9d 100644 --- a/framework/src/modules/chain/transport/transport.js +++ b/framework/src/modules/chain/transport/transport.js @@ -344,13 +344,12 @@ class Transport { * @todo Add @returns tag * @todo Add description of the function */ - async postBlock(query) { + async postBlock(query = {}) { if (!this.constants.broadcasts.active) { return this.logger.debug( 'Receiving blocks disabled by user through config.json', ); } - query = query || {}; const errors = validator.validate(definitions.WSBlocksBroadcast, query); @@ -367,8 +366,7 @@ class Transport { throw errors; } - let block; - block = blocksUtils.addBlockProperties(query.block); + let block = blocksUtils.addBlockProperties(query.block); // Instantiate transaction classes block.transactions = this.interfaceAdapters.transactions.fromBlock(block); From 7c434dd7ce12bf28f00a0391824320d0413c6ea6 Mon Sep 17 00:00:00 2001 From: Ishan Date: Fri, 6 Sep 2019 14:00:16 +0200 Subject: [PATCH 21/24] Test sanitized white peerlist in integration test --- elements/lisk-p2p/test/integration/p2p.ts | 15 +++++++++++++++ elements/lisk-p2p/test/unit/peer_pool.ts | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/elements/lisk-p2p/test/integration/p2p.ts b/elements/lisk-p2p/test/integration/p2p.ts index d5dff96e25f..a4cedf3092a 100644 --- a/elements/lisk-p2p/test/integration/p2p.ts +++ b/elements/lisk-p2p/test/integration/p2p.ts @@ -2092,6 +2092,12 @@ describe('Integration tests for P2P library', () => { connectTimeout: 100, ackTimeout: 200, seedPeers, + whitelistedPeers: [ + { + ipAddress: '127.0.0.3', + wsPort: NETWORK_START_PORT, + }, + ], wsEngine: 'ws', populatorInterval: POPULATOR_INTERVAL_WITH_LIMIT, maxOutboundConnections: MAX_INBOUND_CONNECTIONS, @@ -2146,6 +2152,15 @@ describe('Integration tests for P2P library', () => { ); }); }); + + // TODO: add a test to see if it doesn't drop the inbound connection with the whitelist + describe('whitelist peer', () => { + // Test to check if the whitelist peer is added to the sanitized whitelist. + it('should have whitelistpeer from config', async () => { + expect(p2pNodeList[1]['_sanitizedPeerLists'].whitelisted).not.to.be + .empty; + }); + }); }); describe('Fully connected network with a custom maximum payload', () => { diff --git a/elements/lisk-p2p/test/unit/peer_pool.ts b/elements/lisk-p2p/test/unit/peer_pool.ts index 5d3d4a3f9ed..b9494ff8dc8 100644 --- a/elements/lisk-p2p/test/unit/peer_pool.ts +++ b/elements/lisk-p2p/test/unit/peer_pool.ts @@ -57,6 +57,13 @@ describe('peerPool', () => { maxPeerInfoSize: 10000, maxPeerDiscoveryResponseLength: 1000, secret: DEFAULT_RANDOM_SECRET, + peerList: { + blacklistedPeers: [], + fixedPeers: [], + previousPeers: [], + seedPeers: [], + whitelisted: [], + }, }); describe('#constructor', () => { From 40621be333a7b47a492ac835f48904ee7669d104 Mon Sep 17 00:00:00 2001 From: Ishan Date: Fri, 6 Sep 2019 14:16:46 +0200 Subject: [PATCH 22/24] Revert name blacklistedIps -> blacklistedPeers and peerList -> peerLists --- elements/lisk-p2p/src/p2p.ts | 2 +- elements/lisk-p2p/src/peer_pool.ts | 4 ++-- elements/lisk-p2p/test/unit/peer_pool.ts | 2 +- framework/src/modules/network/defaults/config.js | 4 ++-- framework/src/modules/network/network.js | 2 +- .../specs/controller/__snapshots__/application.spec.js.snap | 2 +- sdk/src/samples/config_devnet.json | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/elements/lisk-p2p/src/p2p.ts b/elements/lisk-p2p/src/p2p.ts index 9e4513b2b11..04d4f946cae 100644 --- a/elements/lisk-p2p/src/p2p.ts +++ b/elements/lisk-p2p/src/p2p.ts @@ -477,7 +477,7 @@ export class P2P extends EventEmitter { ? config.rateCalculationInterval : DEFAULT_RATE_CALCULATION_INTERVAL, secret: config.secret ? config.secret : DEFAULT_RANDOM_SECRET, - peerList: this._sanitizedPeerLists, + peerLists: this._sanitizedPeerLists, }); this._bindHandlersToPeerPool(this._peerPool); diff --git a/elements/lisk-p2p/src/peer_pool.ts b/elements/lisk-p2p/src/peer_pool.ts index 0823aa57ed2..358bb7be5f5 100644 --- a/elements/lisk-p2p/src/peer_pool.ts +++ b/elements/lisk-p2p/src/peer_pool.ts @@ -110,7 +110,7 @@ interface PeerPoolConfig { readonly wsMaxMessageRatePenalty: number; readonly rateCalculationInterval: number; readonly secret: number; - readonly peerList: PeerLists; + readonly peerLists: PeerLists; } export const MAX_PEER_LIST_BATCH_SIZE = 100; @@ -210,7 +210,7 @@ export class PeerPool extends EventEmitter { maxPeerInfoSize: this._peerPoolConfig.maxPeerInfoSize, secret: this._peerPoolConfig.secret, }; - this._peerLists = peerPoolConfig.peerList; + this._peerLists = peerPoolConfig.peerLists; this._peerSelectForSend = peerPoolConfig.peerSelectionForSend; this._peerSelectForRequest = peerPoolConfig.peerSelectionForRequest; this._peerSelectForConnection = peerPoolConfig.peerSelectionForConnection; diff --git a/elements/lisk-p2p/test/unit/peer_pool.ts b/elements/lisk-p2p/test/unit/peer_pool.ts index b9494ff8dc8..ea6d7ded89e 100644 --- a/elements/lisk-p2p/test/unit/peer_pool.ts +++ b/elements/lisk-p2p/test/unit/peer_pool.ts @@ -57,7 +57,7 @@ describe('peerPool', () => { maxPeerInfoSize: 10000, maxPeerDiscoveryResponseLength: 1000, secret: DEFAULT_RANDOM_SECRET, - peerList: { + peerLists: { blacklistedPeers: [], fixedPeers: [], previousPeers: [], diff --git a/framework/src/modules/network/defaults/config.js b/framework/src/modules/network/defaults/config.js index ea88b14dd7c..a298aa5decc 100644 --- a/framework/src/modules/network/defaults/config.js +++ b/framework/src/modules/network/defaults/config.js @@ -49,7 +49,7 @@ const defaultConfig = { env: { variable: 'LISK_PEERS', formatter: 'stringToIpPortSet' }, arg: { name: '--peers,-x', formatter: 'stringToIpPortSet' }, // TODO: Need to confirm parsing logic, old logic was using network WSPort to be default port for peers, we don't have it at the time of compilation }, - blacklistedIps: { + blacklistedPeers: { type: 'array', items: { type: 'string', @@ -151,7 +151,7 @@ const defaultConfig = { peerBanTime: 86400, populatorInterval: 10000, seedPeers: [], - blacklistedIps: [], + blacklistedPeers: [], fixedPeers: [], whitelistedPeers: [], ackTimeout: 20000, diff --git a/framework/src/modules/network/network.js b/framework/src/modules/network/network.js index 017b55cf7b5..6029a1545ea 100644 --- a/framework/src/modules/network/network.js +++ b/framework/src/modules/network/network.js @@ -111,7 +111,7 @@ module.exports = class Network { ); const seedPeers = await lookupPeersIPs(this.options.seedPeers, true); - const blacklistedPeers = this.options.blacklistedIps || []; + const blacklistedPeers = this.options.blacklistedPeers || []; const fixedPeers = this.options.fixedPeers ? this.options.fixedPeers.map(peer => ({ diff --git a/framework/test/jest/unit/specs/controller/__snapshots__/application.spec.js.snap b/framework/test/jest/unit/specs/controller/__snapshots__/application.spec.js.snap index 2470c4c981c..62b16efb180 100644 --- a/framework/test/jest/unit/specs/controller/__snapshots__/application.spec.js.snap +++ b/framework/test/jest/unit/specs/controller/__snapshots__/application.spec.js.snap @@ -564,7 +564,7 @@ Object { "network": Object { "ackTimeout": 20000, "address": "0.0.0.0", - "blacklistedIps": Array [], + "blacklistedPeers": Array [], "connectTimeout": 5000, "discoveryInterval": 30000, "emitPeerLimit": 25, diff --git a/sdk/src/samples/config_devnet.json b/sdk/src/samples/config_devnet.json index af59790c00d..70cb46b1d89 100644 --- a/sdk/src/samples/config_devnet.json +++ b/sdk/src/samples/config_devnet.json @@ -548,7 +548,7 @@ "wsPort": 5000 } ], - "blacklistedIps": [], + "blacklistedPeers": [], "ackTimeout": 20000, "connectTimeout": 5000, "wsEngine": "ws", From e6b92cb52991a255d1496574d9c9a100ace2e854 Mon Sep 17 00:00:00 2001 From: Ishan Date: Fri, 6 Sep 2019 15:40:24 +0200 Subject: [PATCH 23/24] Improve filter for fixed and whitelisted peer --- elements/lisk-p2p/src/peer_pool.ts | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/elements/lisk-p2p/src/peer_pool.ts b/elements/lisk-p2p/src/peer_pool.ts index 358bb7be5f5..a0bdaf8d7f3 100644 --- a/elements/lisk-p2p/src/peer_pool.ts +++ b/elements/lisk-p2p/src/peer_pool.ts @@ -605,13 +605,11 @@ export class PeerPool extends EventEmitter { } private _selectPeersForEviction(): Peer[] { - const peers = [...this.getPeers(InboundPeer)].filter(peer => { - const found = !!this._peerLists.whitelisted.find( - whitePeer => constructPeerIdFromPeerInfo(whitePeer) === peer.id, - ); - - return !found; - }); + const peers = [...this.getPeers(InboundPeer)].filter(peer => + this._peerLists.whitelisted.every( + p => constructPeerIdFromPeerInfo(p) !== peer.id, + ), + ); // Cannot predict which netgroups will be protected const filteredPeersByNetgroup = this._peerPoolConfig.netgroupProtectionRatio @@ -671,13 +669,11 @@ export class PeerPool extends EventEmitter { if (kind === OutboundPeer) { const selectedPeer = shuffle( - peers.filter(peer => { - const found = !!this._peerLists.fixedPeers.find( - fixedPeer => constructPeerIdFromPeerInfo(fixedPeer) === peer.id, - ); - - return !found; - }), + peers.filter(peer => + this._peerLists.fixedPeers.every( + p => constructPeerIdFromPeerInfo(p) !== peer.id, + ), + ), )[0]; if (selectedPeer) { this.removePeer( From 81b88ef2e66371025601e7984c950db45fbd4837 Mon Sep 17 00:00:00 2001 From: Shusetsu Toda Date: Fri, 6 Sep 2019 16:01:22 +0200 Subject: [PATCH 24/24] :arrow_up: Update version --- elements/lisk-elements/package-lock.json | 2 +- elements/lisk-elements/package.json | 2 +- elements/lisk-p2p/package-lock.json | 2 +- elements/lisk-p2p/package.json | 2 +- framework/package-lock.json | 2 +- framework/package.json | 4 ++-- sdk/package-lock.json | 2 +- sdk/package.json | 4 ++-- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/elements/lisk-elements/package-lock.json b/elements/lisk-elements/package-lock.json index 10a050c3579..815ca98fe9e 100644 --- a/elements/lisk-elements/package-lock.json +++ b/elements/lisk-elements/package-lock.json @@ -1,6 +1,6 @@ { "name": "lisk-elements", - "version": "2.4.1", + "version": "2.4.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/elements/lisk-elements/package.json b/elements/lisk-elements/package.json index ad65c1ff198..872f1e3b515 100644 --- a/elements/lisk-elements/package.json +++ b/elements/lisk-elements/package.json @@ -1,6 +1,6 @@ { "name": "lisk-elements", - "version": "2.4.1", + "version": "2.4.2", "description": "Elements for building blockchain applications in the Lisk network", "author": "Lisk Foundation , lightcurve GmbH ", "license": "Apache-2.0", diff --git a/elements/lisk-p2p/package-lock.json b/elements/lisk-p2p/package-lock.json index baad57c4903..0653c2640c2 100644 --- a/elements/lisk-p2p/package-lock.json +++ b/elements/lisk-p2p/package-lock.json @@ -1,6 +1,6 @@ { "name": "@liskhq/lisk-p2p", - "version": "0.3.2", + "version": "0.3.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/elements/lisk-p2p/package.json b/elements/lisk-p2p/package.json index 39cdae3bf78..6ec31dbd83f 100644 --- a/elements/lisk-p2p/package.json +++ b/elements/lisk-p2p/package.json @@ -1,6 +1,6 @@ { "name": "@liskhq/lisk-p2p", - "version": "0.3.2", + "version": "0.3.3", "description": "Unstructured P2P library for use with Lisk-related software", "author": "Lisk Foundation , lightcurve GmbH ", "license": "Apache-2.0", diff --git a/framework/package-lock.json b/framework/package-lock.json index 9c2828f5ce3..3d0b3e9d75c 100644 --- a/framework/package-lock.json +++ b/framework/package-lock.json @@ -1,6 +1,6 @@ { "name": "lisk-framework", - "version": "0.4.2", + "version": "0.4.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/framework/package.json b/framework/package.json index 481a8334cac..4d95c798f87 100644 --- a/framework/package.json +++ b/framework/package.json @@ -1,6 +1,6 @@ { "name": "lisk-framework", - "version": "0.4.2", + "version": "0.4.3", "description": "Lisk blockchain application platform", "author": "Lisk Foundation , lightcurve GmbH ", "license": "Apache-2.0", @@ -50,7 +50,7 @@ "dependencies": { "@liskhq/bignum": "1.3.1", "@liskhq/lisk-cryptography": "2.3.0", - "@liskhq/lisk-p2p": "0.3.2", + "@liskhq/lisk-p2p": "0.3.3", "@liskhq/lisk-transaction-pool": "0.1.2", "@liskhq/lisk-transactions": "2.3.1", "@liskhq/lisk-validator": "0.2.1", diff --git a/sdk/package-lock.json b/sdk/package-lock.json index b5b1b2bb6bf..4283116a1ff 100644 --- a/sdk/package-lock.json +++ b/sdk/package-lock.json @@ -1,6 +1,6 @@ { "name": "lisk-sdk", - "version": "2.3.2", + "version": "2.3.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/sdk/package.json b/sdk/package.json index e4fe662e66b..bf119249d69 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -1,6 +1,6 @@ { "name": "lisk-sdk", - "version": "2.3.2", + "version": "2.3.3", "description": "Official SDK for the Lisk blockchain application platform", "author": "Lisk Foundation , lightcurve GmbH ", "license": "Apache-2.0", @@ -25,6 +25,6 @@ "@liskhq/bignum": "1.3.1", "@liskhq/lisk-cryptography": "2.3.0", "@liskhq/lisk-transactions": "2.3.1", - "lisk-framework": "0.4.2" + "lisk-framework": "0.4.3" } }