From 1364eecb50902e93fad77ebe512f52da1ed0b385 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] 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 418a4a8a09..e7ac4f4a18 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 {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