From ceed22a9a8ff0a91e7f57743a5d69bb5464f1e54 Mon Sep 17 00:00:00 2001 From: Ben Burns <803016+benjamincburns@users.noreply.github.com> Date: Wed, 6 May 2020 10:32:12 -0700 Subject: [PATCH 1/2] ethereum: disallow http(s) RPC transports fixes #776 Signed-off-by: Ben Burns <803016+benjamincburns@users.noreply.github.com> --- packages/caliper-ethereum/lib/ethereum.js | 33 +++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/packages/caliper-ethereum/lib/ethereum.js b/packages/caliper-ethereum/lib/ethereum.js index 418a4a8a0..ed9eec202 100644 --- a/packages/caliper-ethereum/lib/ethereum.js +++ b/packages/caliper-ethereum/lib/ethereum.js @@ -38,14 +38,43 @@ class Ethereum extends BlockchainInterface { */ constructor(workerIndex) { super(); - let configPath = CaliperUtils.resolvePath(ConfigUtil.get(ConfigUtil.keys.NetworkConfig)); this.bcType = 'ethereum'; - this.ethereumConfig = require(configPath).ethereum; + + let configPath = CaliperUtils.resolvePath(ConfigUtil.get(ConfigUtil.keys.NetworkConfig)); + let ethereumConfig = require(configPath).ethereum; + + // throws on configuration error + this.checkConfig(ethereumConfig); + + this.ethereumConfig = ethereumConfig; this.web3 = new Web3(this.ethereumConfig.url); this.web3.transactionConfirmationBlocks = this.ethereumConfig.transactionConfirmationBlocks; this.clientIndex = workerIndex; } + /** + * Check the ethereum networkconfig file for errors, throw if invalid + * @param {object} ethereumConfig The ethereum networkconfig to check. + */ + checkConfig(ethereumConfig) { + if (!ethereumConfig.url) { + throw new Error( + 'No URL given to access the Ethereum SUT. Please check your network configuration. ' + + 'Please see https://hyperledger.github.io/caliper/v0.3/ethereum-config/ for more info.' + ); + } + + if (ethereumConfig.url.toLowerCase().indexOf('http') === 0) { + throw new Error( + 'Ethereum benchmarks must not use http(s) RPC connections, as there is no way to guarantee the ' + + 'order of submitted transactions when using other transports. For more information, please see ' + + 'https://github.com/hyperledger/caliper/issues/776#issuecomment-624771622' + ); + } + + //TODO: add validation logic for the rest of the configuration object + } + /** * Retrieve the blockchain type the implementation relates to * @returns {string} the blockchain type From e31a1e461188cedc46538fd3146858fe61dd2c02 Mon Sep 17 00:00:00 2001 From: Ben Burns <803016+benjamincburns@users.noreply.github.com> Date: Wed, 6 May 2020 16:19:55 -0700 Subject: [PATCH 2/2] fix up integration tests Signed-off-by: Ben Burns <803016+benjamincburns@users.noreply.github.com> --- .../besu_tests/phase1/networkconfig.json | 4 ++-- .../besu_tests/phase2/networkconfig.json | 4 ++-- .../besu_tests/phase3/networkconfig.json | 4 ++-- .../ethereum_tests/config/docker-compose.yml | 4 ++-- .../ethereum_tests/networkconfig.json | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/caliper-tests-integration/besu_tests/phase1/networkconfig.json b/packages/caliper-tests-integration/besu_tests/phase1/networkconfig.json index c24c023d1..68da84c58 100644 --- a/packages/caliper-tests-integration/besu_tests/phase1/networkconfig.json +++ b/packages/caliper-tests-integration/besu_tests/phase1/networkconfig.json @@ -7,7 +7,7 @@ } }, "ethereum": { - "url": "http://localhost:8545", + "url": "ws://localhost:8546", "contractDeployerAddress": "0xD1cf9D73a91DE6630c2bb068Ba5fDdF9F0DEac09", "contractDeployerAddressPrivateKey": "0x797c13f7235c627f6bd013dc17fff4c12213ab49abcf091f77c83f16db10e90b", "fromAddressSeed": "0x3f841bf589fdf83a521e55d51afddc34fa65351161eead24f064855fc29c9580", @@ -23,4 +23,4 @@ } } } -} \ No newline at end of file +} diff --git a/packages/caliper-tests-integration/besu_tests/phase2/networkconfig.json b/packages/caliper-tests-integration/besu_tests/phase2/networkconfig.json index ef7455ba9..2c80e4655 100644 --- a/packages/caliper-tests-integration/besu_tests/phase2/networkconfig.json +++ b/packages/caliper-tests-integration/besu_tests/phase2/networkconfig.json @@ -7,7 +7,7 @@ } }, "ethereum": { - "url": "http://localhost:8545", + "url": "ws://localhost:8546", "contractDeployerAddress": "0xD1cf9D73a91DE6630c2bb068Ba5fDdF9F0DEac09", "contractDeployerAddressPrivateKey": "0x797c13f7235c627f6bd013dc17fff4c12213ab49abcf091f77c83f16db10e90b", "fromAddressSeed": "0x3f841bf589fdf83a521e55d51afddc34fa65351161eead24f064855fc29c9580", @@ -23,4 +23,4 @@ } } } -} \ No newline at end of file +} diff --git a/packages/caliper-tests-integration/besu_tests/phase3/networkconfig.json b/packages/caliper-tests-integration/besu_tests/phase3/networkconfig.json index c24c023d1..68da84c58 100644 --- a/packages/caliper-tests-integration/besu_tests/phase3/networkconfig.json +++ b/packages/caliper-tests-integration/besu_tests/phase3/networkconfig.json @@ -7,7 +7,7 @@ } }, "ethereum": { - "url": "http://localhost:8545", + "url": "ws://localhost:8546", "contractDeployerAddress": "0xD1cf9D73a91DE6630c2bb068Ba5fDdF9F0DEac09", "contractDeployerAddressPrivateKey": "0x797c13f7235c627f6bd013dc17fff4c12213ab49abcf091f77c83f16db10e90b", "fromAddressSeed": "0x3f841bf589fdf83a521e55d51afddc34fa65351161eead24f064855fc29c9580", @@ -23,4 +23,4 @@ } } } -} \ No newline at end of file +} diff --git a/packages/caliper-tests-integration/ethereum_tests/config/docker-compose.yml b/packages/caliper-tests-integration/ethereum_tests/config/docker-compose.yml index 7c27bb63b..bf8d548d5 100644 --- a/packages/caliper-tests-integration/ethereum_tests/config/docker-compose.yml +++ b/packages/caliper-tests-integration/ethereum_tests/config/docker-compose.yml @@ -23,5 +23,5 @@ services: volumes: - ./keys:/root/.ethereum/keystore ports: - - 8545:8545 - command: --unlock 0xc0A8e4D217eB85b812aeb1226fAb6F588943C2C2 --password /root/.ethereum/keystore/password --mine --minerthreads 2 --etherbase 0xc0A8e4D217eB85b812aeb1226fAb6F588943C2C2 --rpc --rpcaddr 0.0.0.0 --rpcvhosts=* --rpcapi admin,eth,miner,personal,web3 --allow-insecure-unlock --nodiscover --gasprice 1 + - 8546:8546 + command: --unlock 0xc0A8e4D217eB85b812aeb1226fAb6F588943C2C2 --password /root/.ethereum/keystore/password --mine --minerthreads 2 --etherbase 0xc0A8e4D217eB85b812aeb1226fAb6F588943C2C2 --ws --wsaddr 0.0.0.0 --wsorigins='*' --wsapi admin,eth,miner,personal,web3 --allow-insecure-unlock --nodiscover --gasprice 1 diff --git a/packages/caliper-tests-integration/ethereum_tests/networkconfig.json b/packages/caliper-tests-integration/ethereum_tests/networkconfig.json index e35cc04ce..2ae91ac54 100644 --- a/packages/caliper-tests-integration/ethereum_tests/networkconfig.json +++ b/packages/caliper-tests-integration/ethereum_tests/networkconfig.json @@ -7,7 +7,7 @@ } }, "ethereum": { - "url": "http://localhost:8545", + "url": "ws://localhost:8546", "contractDeployerAddress": "0xc0A8e4D217eB85b812aeb1226fAb6F588943C2C2", "contractDeployerAddressPassword": "password", "fromAddress": "0xc0A8e4D217eB85b812aeb1226fAb6F588943C2C2",