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

Peers communication protocol change to WS - Closes #446 #660

Merged
merged 140 commits into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
fcbc361
basic socket cluster setup
MaciejBaj Mar 31, 2017
5463a97
:changed ws transport concurrency concept
MaciejBaj Apr 2, 2017
1d2d2df
move responsibility for concurrency to wamp-socket-cluster lib
MaciejBaj Apr 5, 2017
71da101
use reassign endpoints with ConcurrentWAMPServer
MaciejBaj Apr 6, 2017
9a25299
register add / remove peer functions in transactions
MaciejBaj Apr 6, 2017
028cd62
web socket example test
MaciejBaj Apr 10, 2017
93436fb
provide layer of rpc integrated with WS
MaciejBaj Apr 19, 2017
ed99bb4
update sinon to 2.0.0 v
MaciejBaj Apr 19, 2017
d8a8680
link to newest wamp-sc version
MaciejBaj Apr 19, 2017
721a9b5
for travis fixes
MaciejBaj Apr 19, 2017
0b84cbc
revert handshake in transport for http compatibility
MaciejBaj Apr 19, 2017
c8f9f7b
add rpc client in every peer instance
MaciejBaj Apr 19, 2017
2f3480e
initialize rpc server in app file
MaciejBaj Apr 19, 2017
e17f414
fix RPC file
MaciejBaj Apr 19, 2017
fdf721d
change port header to int
MaciejBaj Apr 19, 2017
0a31fca
include all internal transport fn and add basic fun tests
MaciejBaj Apr 19, 2017
b56ba27
fix indent
MaciejBaj Apr 19, 2017
2bd3a6c
add condition for undefined trs
MaciejBaj Apr 20, 2017
e0e8903
initModule without node.js file
MaciejBaj Apr 20, 2017
3bba706
merge with 446-ws-peers-rc
MaciejBaj Mar 31, 2017
396fc3c
revert handshake in transport for http compatibility
MaciejBaj Apr 19, 2017
1b3088f
add rpc client in every peer instance
MaciejBaj Apr 19, 2017
a776319
initialize rpc server in app file
MaciejBaj Apr 19, 2017
05dc834
fix RPC file
MaciejBaj Apr 19, 2017
73c2c9d
change port header to int
MaciejBaj Apr 19, 2017
8c1630e
include all internal transport fn and add basic fun tests
MaciejBaj Apr 19, 2017
4b5d86d
fix indent
MaciejBaj Apr 19, 2017
c8eac90
add condition for undefined trs
MaciejBaj Apr 20, 2017
51d0ed8
fix handshake tests
MaciejBaj Apr 20, 2017
afbcd49
init worker process with data from master, include nonce
MaciejBaj Apr 21, 2017
68ef8c8
rpc integration in process
MaciejBaj Apr 28, 2017
3ec8539
attach rpc api in sync way
MaciejBaj May 2, 2017
8f9a5cc
discovering peers via web sockets
MaciejBaj May 2, 2017
3452194
include integration tests
MaciejBaj May 3, 2017
5e8b87f
add me as peers getter
MaciejBaj May 3, 2017
8e6bd9e
change getting transactions, signatures , common block, block into WS
MaciejBaj May 3, 2017
f2fb5b3
switch broadcasts into WS
MaciejBaj May 4, 2017
b2cdfc5
getSignatures and getTransactions as WS
MaciejBaj May 5, 2017
fea07cf
WSRPCServer as object not function
MaciejBaj May 5, 2017
d006779
test fixed
MaciejBaj May 5, 2017
182ef79
remove shared logic from RPC fix tests
MaciejBaj May 5, 2017
6727ca8
include nonce in randomPeer obj
MaciejBaj May 5, 2017
4a4255b
rewrite unit tests after moving to WS
MaciejBaj May 5, 2017
92aa012
use newest version of wamp-socket-cluster lib
MaciejBaj May 5, 2017
4432221
remove unused files
MaciejBaj May 5, 2017
02c89b5
prepare code for review
MaciejBaj May 5, 2017
69aff6c
remove logs file
MaciejBaj May 5, 2017
e32539d
remove dockerfiles
MaciejBaj May 5, 2017
8324ec9
ensure that folder exists before creating log file
MaciejBaj May 8, 2017
cda4dbb
add itself as frozen peer in test config.json
MaciejBaj May 9, 2017
28676d8
peer.blocks func tests rewrite to WS
MaciejBaj May 11, 2017
589e103
peer signature tests rewritten to WS
MaciejBaj May 11, 2017
9b584f3
peers collision functional test rewritten to WS
MaciejBaj May 11, 2017
427669e
peer delegates functional rewritten to WS
MaciejBaj May 11, 2017
230a1a3
peer transaction main rewritten to WS
MaciejBaj May 12, 2017
22de0ab
peer transaction signatures rewritten to WS
MaciejBaj May 12, 2017
0244919
peer transactions stress rewritten to WS
MaciejBaj May 12, 2017
b06cddf
remove dapp support in peer communication
MaciejBaj May 12, 2017
f7576b0
remove opt http support
MaciejBaj May 12, 2017
610d4b7
peer transaction votes rewritten to WS
MaciejBaj May 12, 2017
2ec9f3e
revert removal of dapp requests messages in transport module
MaciejBaj May 12, 2017
11214fe
integration tests fixes
MaciejBaj May 12, 2017
d4b5696
after merge with development changes
MaciejBaj May 14, 2017
5cc3d11
peer transaction votes rewritten to WS
MaciejBaj May 12, 2017
2fdf9d4
revert removal of dapp requests messages in transport module
MaciejBaj May 12, 2017
5aaa8c0
integration tests fixes
MaciejBaj May 12, 2017
e8fc1ed
polishing before PR
MaciejBaj May 15, 2017
604630e
fix workers controller paths so it works for build also
MaciejBaj May 16, 2017
1146abc
socket cluster runs app.js file for every process
MaciejBaj May 16, 2017
e072740
get remote peer address from different field
MaciejBaj May 17, 2017
c25939b
changes after merge with 446-ws-peers-test
MaciejBaj May 19, 2017
edca46a
start separate processes from workersController file
MaciejBaj May 16, 2017
8373ca1
initialize connection only once for every peer
MaciejBaj May 16, 2017
83d4128
lazy establishing WS connection
MaciejBaj May 17, 2017
07f8c99
event based WS handshake
MaciejBaj May 17, 2017
44996cc
go back to handshake middleware
MaciejBaj May 17, 2017
4f88cdb
update peers after sync fix
MaciejBaj May 17, 2017
0447eaf
upsert peer after updated headers
MaciejBaj May 18, 2017
86dd6ff
fix WS tests setup after changes in logic
MaciejBaj May 19, 2017
370e8ba
add blocks propagation integration tests
MaciejBaj May 19, 2017
85eb71b
fix tests and remove console logs
MaciejBaj May 19, 2017
936dcce
fix calling same callback twice when seeding peers
MaciejBaj May 22, 2017
52c7671
add new tests
MaciejBaj May 22, 2017
d18761c
broadcasting transactions and signatures fix
MaciejBaj May 22, 2017
dc80dad
always insert seed peers into peers list
MaciejBaj May 22, 2017
02b0329
trace sync peers
MaciejBaj May 23, 2017
c79ccaa
change RPC client
MaciejBaj May 24, 2017
ab45e29
include obfuscating of workersController in build process
MaciejBaj May 26, 2017
99af6bc
move workersController to root directory
MaciejBaj May 26, 2017
9b6b94f
split RPC file into smaller modules
MaciejBaj May 26, 2017
494b85c
use webpack to generate bundled workersController file
MaciejBaj May 29, 2017
d71a654
merge ws rpc features in one file
MaciejBaj May 29, 2017
a73d4c2
add commonjs2 webpack bundle option
MaciejBaj May 29, 2017
7d6ad86
remove console logs
MaciejBaj May 31, 2017
443117b
add transport/blocks functional test
MaciejBaj May 31, 2017
bdff334
revert unwanted changes against dev branch
MaciejBaj May 31, 2017
f1488b5
update headers with height and broadhash
MaciejBaj May 31, 2017
1a7e8ef
fix peer undefined err
MaciejBaj Jun 1, 2017
9a0659b
apply acceptable fn before inserting a peer
MaciejBaj Jun 1, 2017
819bc9f
update peer after receiving post data from it
MaciejBaj Jun 1, 2017
6cb6df6
change checking myself in acceptable function
MaciejBaj Jun 1, 2017
15d12d7
fix peers list from having wrong height and broadhash sometimes
MaciejBaj Jun 6, 2017
313ad33
Make separate ports for HTTP and WS connection configurable
MaciejBaj Jun 6, 2017
a66958a
fix http port assign from app parameters
MaciejBaj Jun 8, 2017
ca5290c
calculate broadhash more often
MaciejBaj Jun 8, 2017
52f6323
peers acceptable fix
MaciejBaj Jun 8, 2017
cc31345
fix tests after http port change
MaciejBaj Jun 9, 2017
3474dd5
count consensus every time when accessed
MaciejBaj Jun 9, 2017
28079c3
add trace logging about myself when inserting peer
MaciejBaj Jun 9, 2017
6e5a066
peers random list refactor
MaciejBaj Jun 15, 2017
aed51cc
tests fix
MaciejBaj Jun 16, 2017
d6a6279
change transaction log info from peer string to address
MaciejBaj Jun 16, 2017
d07b1d6
add logs for tracking connection with itself
MaciejBaj Jun 16, 2017
75b7973
rely on nonce only while broadcasting data
MaciejBaj Jun 16, 2017
d32a96a
fix unit tests
MaciejBaj Jun 19, 2017
cb8afb8
peers logic unit tests fix
MaciejBaj Jun 19, 2017
cf26e08
fix forging on multiple nodes
MaciejBaj Jun 20, 2017
c457121
calculate consensus basing on max 100 matched peers
MaciejBaj Jun 21, 2017
37ee125
after merge syntax fixes
MaciejBaj Jun 26, 2017
0ecf5f5
functional and integration tests fix
MaciejBaj Jul 3, 2017
4705bf7
apply indent eslint rule for switch case
MaciejBaj Jul 6, 2017
5b8964b
Merge remote-tracking branch 'origin/1.0.0' into 446-ws-peers-rebased
MaciejBaj Jul 11, 2017
8589a94
include peers functional tests in Jenkins build
MaciejBaj Jul 11, 2017
8120a1e
fix functional and unit tests
MaciejBaj Jul 11, 2017
1d2151e
Merge remote-tracking branch 'origin/1.0.0' into 446-ws-peers-rebased
MaciejBaj Jul 12, 2017
830a150
copy workersController to new folder in build task
MaciejBaj Jul 12, 2017
09830ba
Synchronize Jenkins file
Jul 13, 2017
b6ffb71
Add transport layer tests to Jenkinsfile
Jul 13, 2017
9f35dc9
Fix duplicate stage naming in Jenkinsfile
Jul 13, 2017
8baada3
change ws and http port numbers, log ip after trs received
MaciejBaj Jul 13, 2017
b365c5b
Merge remote-tracking branch 'origin/1.0.0' into 446-ws-peers-rebased
MaciejBaj Jul 19, 2017
ea21a3d
fix ws and http port switching tests
MaciejBaj Jul 19, 2017
0b765c0
migrate from Q to bluebird
MaciejBaj Jul 24, 2017
16ec4d4
switch http and ws ports in mainnet config.json
MaciejBaj Jul 24, 2017
83eebec
get headers from modules/system instead of helpers/constants
MaciejBaj Jul 24, 2017
d416fef
after review changes
MaciejBaj Jul 19, 2017
d5a864f
Merge remote-tracking branch 'origin/1.0.0' into 446-ws-peers-rebased
MaciejBaj Jul 24, 2017
963241e
extend handshake unit tests coverage
MaciejBaj Jul 24, 2017
3bbbeef
read workers number from config file
MaciejBaj Jul 25, 2017
475992d
restore chunking secrets between nodes in integration tests
MaciejBaj Jul 25, 2017
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
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"rules": {
"semi": "error",
"no-eq-null": "off",
"indent": ["error", "tab", { "flatTernaryExpressions": true }],
"indent": ["error", "tab", { "flatTernaryExpressions": true, "SwitchCase": 1 }],
"eqeqeq": "off",
"curly": "error",
"no-undef": "error",
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ tmp
sftp-config.json
*.swp
*.swo
test/integration/logs/
test/integration/configs/
!test/integration/configs/config.non-forge.json
22 changes: 21 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var util = require('util');
module.exports = function (grunt) {
var files = [
'logger.js',
'workersController.js',
'api/**/*.js',
'helpers/**/*.js',
'modules/**/*.js',
Expand Down Expand Up @@ -41,6 +42,7 @@ module.exports = function (grunt) {
util.format('mkdir -p %s/logs', version_dir),
util.format('mkdir -p %s/pids', version_dir),
util.format('cp %s/app.js %s', release_dir, version_dir),
util.format('cp %s/workersController.js %s', release_dir, version_dir),
util.format('cp %s/config.json %s', __dirname, version_dir),
util.format('cp %s/package.json %s', __dirname, version_dir),
util.format('cp %s/genesisBlock.json %s', __dirname, version_dir),
Expand Down Expand Up @@ -70,10 +72,26 @@ module.exports = function (grunt) {
maxBuffer: maxBufferSize
},

coverageUnit: {
command: 'node_modules/.bin/istanbul cover --dir test/.coverage-unit ./node_modules/.bin/_mocha test/unit/index.js',
maxBuffer: maxBufferSize
},

testFunctional: {
command: './node_modules/.bin/mocha test/api/index.js',
maxBuffer: maxBufferSize
},

fetchCoverage: {
command: 'rm -rf ./test/.coverage-func.zip; curl -o ./test/.coverage-func.zip $HOST/coverage/download',
maxBuffer: maxBufferSize
},

createBundles: {
command: 'npm run create-bundles',
maxBuffer: maxBufferSize
},

coverageReport: {
command: 'rm -f ./test/.coverage-unit/lcov.info; ./node_modules/.bin/istanbul report --root ./test/.coverage-unit/ --dir ./test/.coverage-unit'
}
Expand Down Expand Up @@ -118,11 +136,13 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-eslint');

grunt.registerTask('default', ['release']);
grunt.registerTask('release', ['exec:folder', 'obfuscator', 'exec:package', 'exec:build', 'compress']);
grunt.registerTask('release', ['exec:folder', 'obfuscator', 'exec:createBundles', 'exec:package', 'exec:build', 'compress']);
grunt.registerTask('jenkins', ['exec:coverageSingle']);
grunt.registerTask('coverageReport', ['exec:coverageReport']);
grunt.registerTask('eslint-nofix', ['eslint']);
grunt.registerTask('test', ['eslint', 'exec:coverage']);
grunt.registerTask('test-unit', ['eslint', 'exec:coverageUnit']);
grunt.registerTask('test-functional', ['eslint', 'exec:testFunctional']);

grunt.registerTask('eslint-fix', 'Run eslint and fix formatting', function () {
grunt.config.set('eslint.options.fix', true);
Expand Down
33 changes: 21 additions & 12 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ lock(resource: "Lisk-Core-Nodes", inversePrecedence: true) {
'''
}
}, //End node-01 tests
"Functional Peer - Peer" : {
"Functional Peer - Peers" : {
node('node-02'){
sh '''
export TEST=test/api/peer.js TEST_TYPE='FUNC'
export TEST=test/api/peers.js TEST_TYPE='FUNC'
cd "$(echo $WORKSPACE | cut -f 1 -d '@')"
npm run jenkins
'''
Expand All @@ -218,7 +218,7 @@ lock(resource: "Lisk-Core-Nodes", inversePrecedence: true) {
"Functional Peer - Blocks" : {
node('node-02'){
sh '''
export TEST=test/api/peer.blocks.js TEST_TYPE='FUNC'
export TEST=test/api/peer/peer.blocks.ws.js TEST_TYPE='FUNC'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not move those tests to test/api/ws/....?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after discussion with @karmacoma we decided to move WS tests to transport folder and rename them accordingly

cd "$(echo $WORKSPACE | cut -f 1 -d '@')"
npm run jenkins
'''
Expand All @@ -227,7 +227,7 @@ lock(resource: "Lisk-Core-Nodes", inversePrecedence: true) {
"Functional Peer - Signatures" : {
node('node-02'){
sh '''
export TEST=test/api/peer.signatures.js TEST_TYPE='FUNC'
export TEST=test/api/peer/peer.signatures.ws.js TEST_TYPE='FUNC'
cd "$(echo $WORKSPACE | cut -f 1 -d '@')"
npm run jenkins
'''
Expand All @@ -236,7 +236,7 @@ lock(resource: "Lisk-Core-Nodes", inversePrecedence: true) {
"Functional Peer - Transactions Collision" : {
node('node-02'){
sh '''
export TEST=test/api/peer.transactions.collision.js TEST_TYPE='FUNC'
export TEST=test/api/peer/peer.transactions.collision.ws.js TEST_TYPE='FUNC'
cd "$(echo $WORKSPACE | cut -f 1 -d '@')"
npm run jenkins
'''
Expand All @@ -245,7 +245,7 @@ lock(resource: "Lisk-Core-Nodes", inversePrecedence: true) {
"Functional Peer - Transactions Delegates" : {
node('node-02'){
sh '''
export TEST=test/api/peer.transactions.delegates.js TEST_TYPE='FUNC'
export TEST=test/api/peer/peer.transactions.delegates.ws.js TEST_TYPE='FUNC'
cd "$(echo $WORKSPACE | cut -f 1 -d '@')"
npm run jenkins
'''
Expand All @@ -254,7 +254,7 @@ lock(resource: "Lisk-Core-Nodes", inversePrecedence: true) {
"Functional Peer - Transactions Main" : {
node('node-02'){
sh '''
export TEST=test/api/peer.transactions.main.js TEST_TYPE='FUNC'
export TEST=test/api/peer/peer.transactions.main.ws.js TEST_TYPE='FUNC'
cd "$(echo $WORKSPACE | cut -f 1 -d '@')"
npm run jenkins
'''
Expand All @@ -263,16 +263,25 @@ lock(resource: "Lisk-Core-Nodes", inversePrecedence: true) {
"Functional Peer - Transaction Signatures" : {
node('node-02'){
sh '''
export TEST=test/api/peer.transactions.signatures.js TEST_TYPE='FUNC'
export TEST=test/api/peer/peer.transactions.signatures.ws.js TEST_TYPE='FUNC'
cd "$(echo $WORKSPACE | cut -f 1 -d '@')"
npm run jenkins
'''
}
},
"Functional Peer - Peers" : {
"Functional Peer - Transport" : {
node('node-02'){
sh '''
export TEST=test/api/peers.js TEST_TYPE='FUNC'
export TEST=test/api/peer/transport.js TEST_TYPE='FUNC'
cd "$(echo $WORKSPACE | cut -f 1 -d '@')"
npm run jenkins
'''
}
},
"Functional Peer - Peers websockets" : {
node('node-02'){
sh '''
export TEST=test/api/peer/peer.ws.js TEST_TYPE='FUNC'
cd "$(echo $WORKSPACE | cut -f 1 -d '@')"
npm run jenkins
'''
Expand All @@ -281,7 +290,7 @@ lock(resource: "Lisk-Core-Nodes", inversePrecedence: true) {
"Functional Peer - Votes" : {
node('node-02'){
sh '''
export TEST=test/api/peer.transactions.votes.js TEST_TYPE='FUNC'
export TEST=test/api/peer/peer.transactions.votes.ws.js TEST_TYPE='FUNC'
cd "$(echo $WORKSPACE | cut -f 1 -d '@')"
npm run jenkins
'''
Expand Down Expand Up @@ -338,7 +347,7 @@ lock(resource: "Lisk-Core-Nodes", inversePrecedence: true) {
"Functional Stress - Transactions" : {
node('node-04'){
sh '''
export TEST=test/api/peer.transactions.stress.js TEST_TYPE='FUNC'
export TEST=test/api/peer/peer.transactions.stress.ws.js TEST_TYPE='FUNC'
cd "$(echo $WORKSPACE | cut -f 1 -d '@')"
npm run jenkins
'''
Expand Down
111 changes: 0 additions & 111 deletions api/http/transport.js
Original file line number Diff line number Diff line change
@@ -1,111 +0,0 @@
'use strict';

var Router = require('../../helpers/router');
var httpApi = require('../../helpers/httpApi');
var schema = require('../../schema/transport');

/**
* Binds api with modules and creates common url.
* - End point: `/peer`
* - Private API:
* - get /blocks/common
* - get /blocks
* - get /list
* - get /height
* - get /ping
* - get /signatures
* - get /transactions
* - post /blocks
* - post /signatures
* - post /transactions
* @memberof module:transport
* @requires helpers/Router
* @requires helpers/httpApi
* @constructor
* @param {Object} transportModule - Module transport instance.
* @param {scope} app - Network app.
* @param {function} logger
*/
// Constructor
function TransportHttpApi (transportModule, app, logger, cache) {

var router = new Router();

router.use(httpApi.middleware.attachResponseHeaders.bind(null, transportModule.headers));
router.use(httpApi.middleware.blockchainReady.bind(null, transportModule.isLoaded));

router.use(handshakeMiddleware);

router.get('/blocks/common', getCommonBlocksMiddleware);
router.get('/blocks', httpApi.middleware.sanitize('query', schema.blocks, transportModule.internal.blocks));

router.map(transportModule.internal, {
'get /list': 'list',
'get /height': 'height',
'get /ping': 'ping',
'get /signatures': 'getSignatures',
'get /transactions': 'getTransactions'

});

// Custom parameters internal functions
router.post('/blocks', function (req, res) {
transportModule.internal.postBlock(req.body.block, req.peer, req.method + ' ' + req.url, httpApi.respond.bind(null, res));
});

router.post('/signatures', function (req, res) {
transportModule.internal.postSignatures({signatures: req.body.signatures, signature: req.body.signature}, httpApi.respond.bind(null, res));
});

router.post('/transactions', function (req, res) {
transportModule.internal.postTransactions({
transactions: req.body.transactions,
transaction: req.body.transaction
}, req.peer, req.method + ' ' + req.url, httpApi.respond.bind(null, res));
});

router.use(httpApi.middleware.notFound);

app.use('/peer', router);

function handshakeMiddleware (req, res, next) {
transportModule.internal.handshake(req.ip, req.headers.port, req.headers, validateHeaders, function (err, peer) {
if (err) {
return res.status(500).send(err);
}

req.peer = peer;

return next();
});

function validateHeaders (headers, cb) {
return req.sanitize(headers, schema.headers, function (err, report, sanitized) {
if (err) {
return cb(err.toString());
} else if (!report.isValid) {
return cb(report.issues);
}

return cb();
});
}
}

function getCommonBlocksMiddleware (req, res, next) {
req.sanitize(req.query, schema.commonBlock, function (err, report, query) {
if (err) {
logger.debug('Common block request validation failed', {err: err.toString(), req: req.query});
return next(err);
}
if (!report.isValid) {
logger.debug('Common block request validation failed', {err: report, req: req.query});
return res.json({success: false, error: report.issues});
}

return transportModule.internal.blocksCommon(query.ids, req.peer, req.method + ' ' + req.url, httpApi.respond.bind(null, res));
});
}
}

module.exports = TransportHttpApi;
Loading