diff --git a/packages/caliper-application/benchmark/simple/config-ethereum.yaml b/packages/caliper-application/benchmark/simple/config-ethereum.yaml index 664809f1a3..c17f81cb9c 100644 --- a/packages/caliper-application/benchmark/simple/config-ethereum.yaml +++ b/packages/caliper-application/benchmark/simple/config-ethereum.yaml @@ -28,8 +28,12 @@ test: monitor: type: - process + - docker process: - command: node arguments: local-client.js multiOutput: avg + docker: + name: + - all interval: 1 diff --git a/packages/caliper-application/network/ethereum/1node-clique/Dockerfile b/packages/caliper-application/network/ethereum/1node-clique/Dockerfile new file mode 100644 index 0000000000..ad4c50e3e4 --- /dev/null +++ b/packages/caliper-application/network/ethereum/1node-clique/Dockerfile @@ -0,0 +1,5 @@ +FROM ethereum/client-go:stable +COPY ./data/ /root/ +VOLUME [ "/root/.ethereum/keystore/" ] +RUN geth init /root/genesis.json && geth import /root/bc.dat +ENTRYPOINT [ "geth" ] \ No newline at end of file diff --git a/packages/caliper-application/network/ethereum/1node-clique/data/bc.dat b/packages/caliper-application/network/ethereum/1node-clique/data/bc.dat new file mode 100755 index 0000000000..140eb9c8b8 Binary files /dev/null and b/packages/caliper-application/network/ethereum/1node-clique/data/bc.dat differ diff --git a/packages/caliper-application/network/ethereum/1node-clique/data/genesis.json b/packages/caliper-application/network/ethereum/1node-clique/data/genesis.json new file mode 100644 index 0000000000..02445215d3 --- /dev/null +++ b/packages/caliper-application/network/ethereum/1node-clique/data/genesis.json @@ -0,0 +1,31 @@ +{ + "config": { + "chainId": 48122, + "homesteadBlock": 1, + "eip150Block": 2, + "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "eip155Block": 3, + "eip158Block": 3, + "byzantiumBlock": 4, + "constantinopleBlock": 5, + "clique": { + "period": 5, + "epoch": 30000 + } + }, + "nonce": "0x0", + "timestamp": "0x5ca916c6", + "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000c0A8e4D217eB85b812aeb1226fAb6F588943C2C20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "gasLimit": "0x47b760", + "difficulty": "0x1", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "coinbase": "0xc0A8e4D217eB85b812aeb1226fAb6F588943C2C2", + "number": "0x0", + "gasUsed": "0x0", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "alloc": { + "0xc0A8e4D217eB85b812aeb1226fAb6F588943C2C2": { + "balance": "0x200000000000000000000000000000000000000000000000000000000000000" + } + } +} \ No newline at end of file diff --git a/packages/caliper-application/network/ethereum/1node-clique/docker-compose.yml b/packages/caliper-application/network/ethereum/1node-clique/docker-compose.yml new file mode 100644 index 0000000000..375a5ef372 --- /dev/null +++ b/packages/caliper-application/network/ethereum/1node-clique/docker-compose.yml @@ -0,0 +1,11 @@ +version: "3" +services: + node: + build: . + image: caliper-ethereum-clique + container_name: ethereum_clique + 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 --nodiscover --gasprice 1 \ No newline at end of file diff --git a/packages/caliper-application/network/ethereum/1node-clique/ethereum.json b/packages/caliper-application/network/ethereum/1node-clique/ethereum.json new file mode 100644 index 0000000000..c84f639888 --- /dev/null +++ b/packages/caliper-application/network/ethereum/1node-clique/ethereum.json @@ -0,0 +1,26 @@ +{ + "caliper": { + "blockchain": "ethereum", + "command" : { + "start": "docker-compose -f network/ethereum/1node-clique/docker-compose.yml up -d && sleep 3", + "end" : "docker-compose -f network/ethereum/1node-clique/docker-compose.yml down" + } + }, + "ethereum": { + "url": "http://localhost:8545", + "contractDeployerAddress": "0xc0A8e4D217eB85b812aeb1226fAb6F588943C2C2", + "contractDeployerAddressPassword": "password", + "fromAddress": "0xc0A8e4D217eB85b812aeb1226fAb6F588943C2C2", + "fromAddressPassword": "password", + "transactionConfirmationBlocks": 2, + "registry": { + "address": "0x91496eafe3C54C48D1Add5c1Fb30655d6b76e56b", + "path": "src/contract/ethereum/registry/registry.json" + }, + "contracts": { + "simple": { + "path": "src/contract/ethereum/simple/simple.json" + } + } + } +} \ No newline at end of file diff --git a/packages/caliper-application/network/ethereum/1node-clique/keys/UTC--2019-05-05T20-07-38.958128475Z--c0a8e4d217eb85b812aeb1226fab6f588943c2c2 b/packages/caliper-application/network/ethereum/1node-clique/keys/UTC--2019-05-05T20-07-38.958128475Z--c0a8e4d217eb85b812aeb1226fab6f588943c2c2 new file mode 100644 index 0000000000..237ff7e2bc --- /dev/null +++ b/packages/caliper-application/network/ethereum/1node-clique/keys/UTC--2019-05-05T20-07-38.958128475Z--c0a8e4d217eb85b812aeb1226fab6f588943c2c2 @@ -0,0 +1 @@ +{"address":"c0a8e4d217eb85b812aeb1226fab6f588943c2c2","crypto":{"cipher":"aes-128-ctr","ciphertext":"521588833e66d0e052120c30080e37e847ae7877eb09dc6760eb10382c2e6d4f","cipherparams":{"iv":"cee02dbf21538798041c99f49bef9afa"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"916a08841725aba0bf2a2d39f489f0d5d3f2b5032067e44655b8ff542c492f03"},"mac":"f90667ea4de3e977b1cdd23ed722ddffc3f6888b21ea68cc7d5ef77463022e94"},"id":"7543fa05-dac5-4ae9-856d-e96ddea28c41","version":3} \ No newline at end of file diff --git a/packages/caliper-application/network/ethereum/1node-clique/keys/password b/packages/caliper-application/network/ethereum/1node-clique/keys/password new file mode 100644 index 0000000000..7aa311adf9 --- /dev/null +++ b/packages/caliper-application/network/ethereum/1node-clique/keys/password @@ -0,0 +1 @@ +password \ No newline at end of file diff --git a/packages/caliper-application/network/ethereum/1node/Dockerfile b/packages/caliper-application/network/ethereum/1node/Dockerfile new file mode 100644 index 0000000000..cddfb3b093 --- /dev/null +++ b/packages/caliper-application/network/ethereum/1node/Dockerfile @@ -0,0 +1,5 @@ +FROM ethereum/client-go:stable +COPY ./data/ /root/ +VOLUME [ "/root/.ethereum/keystore/" ] +RUN geth init /root/genesis.json && geth import /root/bc.dat && geth makedag 0 /root/.ethash && geth makedag 30000 /root/.ethash +ENTRYPOINT [ "geth" ] \ No newline at end of file diff --git a/packages/caliper-application/network/ethereum/1node/data/bc.dat b/packages/caliper-application/network/ethereum/1node/data/bc.dat new file mode 100755 index 0000000000..54a7fd8890 Binary files /dev/null and b/packages/caliper-application/network/ethereum/1node/data/bc.dat differ diff --git a/packages/caliper-application/network/ethereum/1node/data/genesis.json b/packages/caliper-application/network/ethereum/1node/data/genesis.json new file mode 100644 index 0000000000..400af6d6da --- /dev/null +++ b/packages/caliper-application/network/ethereum/1node/data/genesis.json @@ -0,0 +1,28 @@ +{ + "config": { + "chainId": 21194, + "homesteadBlock": 1, + "eip150Block": 2, + "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "eip155Block": 3, + "eip158Block": 3, + "byzantiumBlock": 4, + "constantinopleBlock": 5, + "ethash": {} + }, + "nonce": "0x0", + "timestamp": "0x5cd09c57", + "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", + "gasLimit": "0x47b760", + "difficulty": "0x80000", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "coinbase": "0x0000000000000000000000000000000000000000", + "alloc": { + "c0a8e4d217eb85b812aeb1226fab6f588943c2c2": { + "balance": "0x200000000000000000000000000000000000000000000000000000000000000" + } + }, + "number": "0x0", + "gasUsed": "0x0", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000" +} \ No newline at end of file diff --git a/packages/caliper-application/network/ethereum/1node/docker-compose.yml b/packages/caliper-application/network/ethereum/1node/docker-compose.yml new file mode 100644 index 0000000000..4f8c5f8d90 --- /dev/null +++ b/packages/caliper-application/network/ethereum/1node/docker-compose.yml @@ -0,0 +1,11 @@ +version: "3" +services: + node: + build: . + image: caliper-ethereum + container_name: ethereum + 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 --nodiscover --gasprice 1 \ No newline at end of file diff --git a/packages/caliper-application/network/ethereum/1node/ethereum.json b/packages/caliper-application/network/ethereum/1node/ethereum.json new file mode 100644 index 0000000000..2dd3bf8571 --- /dev/null +++ b/packages/caliper-application/network/ethereum/1node/ethereum.json @@ -0,0 +1,26 @@ +{ + "caliper": { + "blockchain": "ethereum", + "command" : { + "start": "docker-compose -f network/ethereum/1node/docker-compose.yml up -d && sleep 3", + "end" : "docker-compose -f network/ethereum/1node/docker-compose.yml down" + } + }, + "ethereum": { + "url": "http://localhost:8545", + "contractDeployerAddress": "0xc0A8e4D217eB85b812aeb1226fAb6F588943C2C2", + "contractDeployerAddressPassword": "password", + "fromAddress": "0xc0A8e4D217eB85b812aeb1226fAb6F588943C2C2", + "fromAddressPassword": "password", + "transactionConfirmationBlocks": 2, + "registry": { + "address": "0xB1B0e1Fd4c456146A808fDF668aCC2FaF16Ee2ab", + "path": "src/contract/ethereum/registry/registry.json" + }, + "contracts": { + "simple": { + "path": "src/contract/ethereum/simple/simple.json" + } + } + } +} \ No newline at end of file diff --git a/packages/caliper-application/network/ethereum/1node/keys/UTC--2019-05-05T20-07-38.958128475Z--c0a8e4d217eb85b812aeb1226fab6f588943c2c2 b/packages/caliper-application/network/ethereum/1node/keys/UTC--2019-05-05T20-07-38.958128475Z--c0a8e4d217eb85b812aeb1226fab6f588943c2c2 new file mode 100644 index 0000000000..237ff7e2bc --- /dev/null +++ b/packages/caliper-application/network/ethereum/1node/keys/UTC--2019-05-05T20-07-38.958128475Z--c0a8e4d217eb85b812aeb1226fab6f588943c2c2 @@ -0,0 +1 @@ +{"address":"c0a8e4d217eb85b812aeb1226fab6f588943c2c2","crypto":{"cipher":"aes-128-ctr","ciphertext":"521588833e66d0e052120c30080e37e847ae7877eb09dc6760eb10382c2e6d4f","cipherparams":{"iv":"cee02dbf21538798041c99f49bef9afa"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"916a08841725aba0bf2a2d39f489f0d5d3f2b5032067e44655b8ff542c492f03"},"mac":"f90667ea4de3e977b1cdd23ed722ddffc3f6888b21ea68cc7d5ef77463022e94"},"id":"7543fa05-dac5-4ae9-856d-e96ddea28c41","version":3} \ No newline at end of file diff --git a/packages/caliper-application/network/ethereum/1node/keys/password b/packages/caliper-application/network/ethereum/1node/keys/password new file mode 100644 index 0000000000..7aa311adf9 --- /dev/null +++ b/packages/caliper-application/network/ethereum/1node/keys/password @@ -0,0 +1 @@ +password \ No newline at end of file diff --git a/packages/caliper-ethereum/lib/ethereum.js b/packages/caliper-ethereum/lib/ethereum.js index 07e0453429..9bd3b2f8ca 100644 --- a/packages/caliper-ethereum/lib/ethereum.js +++ b/packages/caliper-ethereum/lib/ethereum.js @@ -52,7 +52,7 @@ class Ethereum extends BlockchainInterface { for (const key of Object.keys(this.ethereumConfig.contracts)) { let contractData = require(CaliperUtils.resolvePath(this.ethereumConfig.contracts[key].path, this.workspaceRoot)); // TODO remove path property promises.push(new Promise(function(resolve, reject) { - self.deployContract(self.web3, contractData).then((contractInstance) => { + self.deployContract(contractData).then((contractInstance) => { self.bindContract(key, contractInstance.address).then((receipt) => { resolve() }) @@ -110,7 +110,7 @@ class Ethereum extends BlockchainInterface { } /** - * Submit a transaction to the geth context. + * Submit a transaction to the ethereum context. * @param {Object} context Context object. * @param {String} contractID Identity of the contract. * @param {String} contractVer Version of the contract. @@ -139,7 +139,7 @@ class Ethereum extends BlockchainInterface { /** * Query the given smart contract according to the specified options. - * @param {object} context The Burrow context returned by {getContext}. + * @param {object} context The Ethereum context returned by {getContext}. * @param {string} contractID The name of the contract. * @param {string} contractVer The version of the contract. * @param {string} key The argument to pass to the smart contract query. @@ -175,22 +175,32 @@ class Ethereum extends BlockchainInterface { // empty } - lookupContract(contract_id) { - return this.registry.methods.lookup(contract_id).call(); + /** + * Fetch the address for the contract with the given label from the registry + * @param {string} contract_id + * @return {string} The contract address + */ + lookupContract(label) { + return this.registry.methods.lookup(label).call(); } - bindContract(contract_id, address) { - return this.registry.methods.bind(contract_id, address).send({from: this.ethereumConfig.contractDeployerAddress}); + /** + * Binds the address to the label registering on the registry + * @param {string} label label to bind address to + * @param {string} address deployed contract address + */ + bindContract(label, address) { + return this.registry.methods.bind(label, address).send({from: this.ethereumConfig.contractDeployerAddress}); } /** * Deploys a new contract using the given web3 instance - * @param {Object} web3 The Web3 object * @param {JSON} contractData Contract data with abi and bytecode properties * @returns {Promise} The deployed contract instance */ - deployContract(web3, contractData) { - var contractDeployerAddress = this.ethereumConfig.contractDeployerAddress + deployContract(contractData) { + let web3 = this.web3 + let contractDeployerAddress = this.ethereumConfig.contractDeployerAddress return new Promise(function(resolve, reject) { let contract = new web3.eth.Contract(contractData.abi); let contractDeploy = contract.deploy({