Skip to content

Commit

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

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

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
Expand Down

0 comments on commit a763957

Please sign in to comment.