Skip to content

Commit

Permalink
ethereum: disallow http(s) RPC transports
Browse files Browse the repository at this point in the history
fixes hyperledger-caliper#776

Signed-off-by: Ben Burns <[email protected]>
  • Loading branch information
benjamincburns committed May 6, 2020
1 parent cd3ae29 commit ceed22a
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions packages/caliper-ethereum/lib/ethereum.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ceed22a

Please sign in to comment.