From 419e4de7da99c92d2ff96a69c29d113c993188c5 Mon Sep 17 00:00:00 2001 From: Kirill Revenkov Date: Mon, 22 Apr 2019 23:19:30 +0300 Subject: [PATCH 1/6] get error with cellular link --- modules/blockHandler.js | 14 +++++++++----- modules/smartContracts/EcmaContract.js | 3 ++- modules/validators/dlcpoa.js | 10 ++++++++++ modules/validators/lcpoa.js | 11 ++++++++++- modules/validators/thrusted.js | 10 +++++++++- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/modules/blockHandler.js b/modules/blockHandler.js index 9575abc..e44eb79 100644 --- a/modules/blockHandler.js +++ b/modules/blockHandler.js @@ -238,11 +238,15 @@ class BlockHandler { try { let blockData; - try { - blockData = JSON.parse(block.data); - } catch (e) { - logger.info('Not JSON block ' + block.index); - return callback(); + if (typeof block.data ==="object") { + blockData = block.data; + } else { + try { + blockData = JSON.parse(block.data); + } catch (e) { + that.log('Info: Not JSON block ' + block.index); + return callback(); + } } diff --git a/modules/smartContracts/EcmaContract.js b/modules/smartContracts/EcmaContract.js index 22ac688..86c48ea 100644 --- a/modules/smartContracts/EcmaContract.js +++ b/modules/smartContracts/EcmaContract.js @@ -1480,7 +1480,8 @@ class EcmaContract { state.block = block; state.contractAddress = address; let contract = {code: code, state: state}; - + //console.log(contract); + console.log(state.block.data); that.contracts.put(address, JSON.stringify(contract), function (err) { if(err) { logger.error('Contract deploy handling error'); diff --git a/modules/validators/dlcpoa.js b/modules/validators/dlcpoa.js index 327a9b9..f8077a1 100644 --- a/modules/validators/dlcpoa.js +++ b/modules/validators/dlcpoa.js @@ -132,8 +132,18 @@ function generateNextBlock(blockData, cb, cancelCondition) { /*if(miningNow) { return; }*/ + /* if(typeof blockData === 'object') { blockData = JSON.stringify(blockData); + }*/ + + if (typeof blockData !== 'object') { + try { + blockData = JSON.parse(blockData); + } catch (e) { + console.log('Info: Error in block data.'); + return false; + } } /*if(blockchain.config.program.disableMining){ diff --git a/modules/validators/lcpoa.js b/modules/validators/lcpoa.js index 8b45ec3..e93d895 100644 --- a/modules/validators/lcpoa.js +++ b/modules/validators/lcpoa.js @@ -84,8 +84,17 @@ function generateNextBlock(blockData, cb, cancelCondition) { /*if(miningNow) { return; }*/ - if(typeof blockData === 'object') { + /*if(typeof blockData === 'object') { blockData = JSON.stringify(blockData); + }*/ + + if (typeof blockData !== 'object') { + try { + blockData = JSON.parse(blockData); + } catch (e) { + console.log('Info: Error in block data.'); + return false; + } } /*if(blockchain.config.program.disableMining){ diff --git a/modules/validators/thrusted.js b/modules/validators/thrusted.js index 5036ca4..036a679 100644 --- a/modules/validators/thrusted.js +++ b/modules/validators/thrusted.js @@ -183,8 +183,16 @@ function generateNextBlock(blockData, cb, cancelCondition, timestamp) { return false; } - if(typeof blockData === 'object') { + /*if(typeof blockData === 'object') { blockData = JSON.stringify(blockData); + }*/ + if (typeof blockData !== 'object') { + try { + blockData = JSON.parse(blockData); + } catch (e) { + console.log('Info: Error in block data.'); + return false; + } } blockchain.getLatestBlock(function (previousBlock) { From 88110cced820cb60d5a76d2b830a4dc32cce1c3c Mon Sep 17 00:00:00 2001 From: Kirill Revenkov Date: Thu, 25 Apr 2019 18:04:28 +0300 Subject: [PATCH 2/6] try to find problem --- modules/smartContracts/EcmaContract.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/smartContracts/EcmaContract.js b/modules/smartContracts/EcmaContract.js index 86c48ea..ac6a065 100644 --- a/modules/smartContracts/EcmaContract.js +++ b/modules/smartContracts/EcmaContract.js @@ -1320,7 +1320,16 @@ class EcmaContract { that.blockchain.generateNextBlockAuto(callBlock, function (generatedBlock) { that.events._handleBlockReplay(generatedBlock.index, function () { - that._handleBlock(JSON.parse(generatedBlock.data), generatedBlock, true, (err) => { + console.log(generatedBlock.data); + let generatedBlockData = generatedBlock.data; + if (typeof generatedBlockData !== "object"){ + try { + generatedBlockData = JSON.parse(generatedBlock.data) + } catch (e) { + assert.assert(false, e.toString()); + } + } + that._handleBlock(generatedBlock.data, generatedBlock, true, (err) => { if(err) { cb(err); return; @@ -1471,17 +1480,17 @@ class EcmaContract { _handleContractDeploy(address, code, state, block, callback) { let that = this; - /** * Initiate and run contract */ function addNewContract() { state.block = block; + delete state.block.data.state; state.contractAddress = address; + let contract = {code: code, state: state}; - //console.log(contract); - console.log(state.block.data); + that.contracts.put(address, JSON.stringify(contract), function (err) { if(err) { logger.error('Contract deploy handling error'); From a6226df0600a18c863847e4ff48d401d092caa6b Mon Sep 17 00:00:00 2001 From: Kirill Revenkov Date: Fri, 26 Apr 2019 09:56:37 +0300 Subject: [PATCH 3/6] fix one issue --- modules/smartContracts/EcmaContract.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/smartContracts/EcmaContract.js b/modules/smartContracts/EcmaContract.js index ac6a065..6eb9752 100644 --- a/modules/smartContracts/EcmaContract.js +++ b/modules/smartContracts/EcmaContract.js @@ -1485,8 +1485,13 @@ class EcmaContract { */ function addNewContract() { + //exclude circullar links + let blockState={}; + Object.assign(blockState, block.data.state); + block.data.state = blockState; + state.block = block; - delete state.block.data.state; + state.contractAddress = address; let contract = {code: code, state: state}; From 5078e1f956d6ed5298cbcf944cfc5e0593905ba3 Mon Sep 17 00:00:00 2001 From: Kirill Revenkov Date: Fri, 26 Apr 2019 17:47:08 +0300 Subject: [PATCH 4/6] try to find bug --- modules/smartContracts/EcmaContract.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/smartContracts/EcmaContract.js b/modules/smartContracts/EcmaContract.js index 6eb9752..fea6226 100644 --- a/modules/smartContracts/EcmaContract.js +++ b/modules/smartContracts/EcmaContract.js @@ -1489,7 +1489,7 @@ class EcmaContract { let blockState={}; Object.assign(blockState, block.data.state); block.data.state = blockState; - + state.block = block; state.contractAddress = address; From 878a965d7b310ddb4c58c0eab0cdc4f9df37dc68 Mon Sep 17 00:00:00 2001 From: Kirill Revenkov Date: Sun, 28 Apr 2019 22:02:51 +0300 Subject: [PATCH 5/6] exclude cillular --- modules/smartContracts/EcmaContract.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/smartContracts/EcmaContract.js b/modules/smartContracts/EcmaContract.js index fea6226..ba6b6ac 100644 --- a/modules/smartContracts/EcmaContract.js +++ b/modules/smartContracts/EcmaContract.js @@ -1320,7 +1320,7 @@ class EcmaContract { that.blockchain.generateNextBlockAuto(callBlock, function (generatedBlock) { that.events._handleBlockReplay(generatedBlock.index, function () { - console.log(generatedBlock.data); + //console.log(generatedBlock.data); let generatedBlockData = generatedBlock.data; if (typeof generatedBlockData !== "object"){ try { @@ -1576,6 +1576,11 @@ class EcmaContract { */ _handleContractCall(address, method, args, state, block, testOnly, callback) { + //exclude circullar links + let blockState={}; + Object.assign(blockState, block.data.state); + block.data.state = blockState; + let that = this; if((method === 'contract.deploy') || (method === 'deploy')) { logger.error('Calling deploy method of contract is not allowed'); From fd660e1c06414ae56e84aea343becd35964364ca Mon Sep 17 00:00:00 2001 From: Kirill Revenkov Date: Sun, 28 Apr 2019 22:23:52 +0300 Subject: [PATCH 6/6] Update EcmaContract.js --- modules/smartContracts/EcmaContract.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/modules/smartContracts/EcmaContract.js b/modules/smartContracts/EcmaContract.js index ba6b6ac..56b63ef 100644 --- a/modules/smartContracts/EcmaContract.js +++ b/modules/smartContracts/EcmaContract.js @@ -1485,15 +1485,8 @@ class EcmaContract { */ function addNewContract() { - //exclude circullar links - let blockState={}; - Object.assign(blockState, block.data.state); - block.data.state = blockState; - state.block = block; - state.contractAddress = address; - let contract = {code: code, state: state}; that.contracts.put(address, JSON.stringify(contract), function (err) { @@ -1576,11 +1569,6 @@ class EcmaContract { */ _handleContractCall(address, method, args, state, block, testOnly, callback) { - //exclude circullar links - let blockState={}; - Object.assign(blockState, block.data.state); - block.data.state = blockState; - let that = this; if((method === 'contract.deploy') || (method === 'deploy')) { logger.error('Calling deploy method of contract is not allowed'); @@ -1656,10 +1644,15 @@ class EcmaContract { let verifyBlock = {}; let testWallet = new Wallet(false, that.config); + //exclude circullar links + let blockState={}; + Object.assign(blockState, blockData.state); switch (blockData.type) { case EcmaContractDeployBlock.blockType: + + verifyBlock = new EcmaContractDeployBlock(blockData.ecmaCode, blockData.state); if(verifyBlock.data !== blockData.data) { @@ -1676,10 +1669,11 @@ class EcmaContract { return } - this._handleContractDeploy(block.index, blockData.ecmaCode, blockData.state, block, callback); + this._handleContractDeploy(block.index, blockData.ecmaCode, blockState, block, callback); break; case EcmaContractCallBlock.blockType: + verifyBlock = new EcmaContractCallBlock(blockData.address, blockData.method, blockData.args, blockData.state); if(verifyBlock.data !== blockData.data) { logger.error('Contract invalid data in block ' + block.index); @@ -1695,7 +1689,7 @@ class EcmaContract { return } - this._handleContractCall(blockData.address, blockData.method, blockData.args, blockData.state, block, testOnly, callback); + this._handleContractCall(blockData.address, blockData.method, blockData.args, blockState, block, testOnly, callback); break; default: