Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ethereum: disallow http(s) RPC transports #829

Merged
merged 2 commits into from
May 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}
},
"ethereum": {
"url": "http://localhost:8545",
"url": "ws://localhost:8546",
"contractDeployerAddress": "0xD1cf9D73a91DE6630c2bb068Ba5fDdF9F0DEac09",
"contractDeployerAddressPrivateKey": "0x797c13f7235c627f6bd013dc17fff4c12213ab49abcf091f77c83f16db10e90b",
"fromAddressSeed": "0x3f841bf589fdf83a521e55d51afddc34fa65351161eead24f064855fc29c9580",
Expand All @@ -23,4 +23,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}
},
"ethereum": {
"url": "http://localhost:8545",
"url": "ws://localhost:8546",
"contractDeployerAddress": "0xD1cf9D73a91DE6630c2bb068Ba5fDdF9F0DEac09",
"contractDeployerAddressPrivateKey": "0x797c13f7235c627f6bd013dc17fff4c12213ab49abcf091f77c83f16db10e90b",
"fromAddressSeed": "0x3f841bf589fdf83a521e55d51afddc34fa65351161eead24f064855fc29c9580",
Expand All @@ -23,4 +23,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}
},
"ethereum": {
"url": "http://localhost:8545",
"url": "ws://localhost:8546",
"contractDeployerAddress": "0xD1cf9D73a91DE6630c2bb068Ba5fDdF9F0DEac09",
"contractDeployerAddressPrivateKey": "0x797c13f7235c627f6bd013dc17fff4c12213ab49abcf091f77c83f16db10e90b",
"fromAddressSeed": "0x3f841bf589fdf83a521e55d51afddc34fa65351161eead24f064855fc29c9580",
Expand All @@ -23,4 +23,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}
},
"ethereum": {
"url": "http://localhost:8545",
"url": "ws://localhost:8546",
"contractDeployerAddress": "0xc0A8e4D217eB85b812aeb1226fAb6F588943C2C2",
"contractDeployerAddressPassword": "password",
"fromAddress": "0xc0A8e4D217eB85b812aeb1226fAb6F588943C2C2",
Expand Down