Skip to content

Commit 3a1828f

Browse files
committed
fix contract deployment; timeout & retry
1 parent dec7ae8 commit 3a1828f

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

lib/deploy.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ var fs = require('fs');
33
var grunt = require('grunt');
44
var readYaml = require('read-yaml');
55
var Config = require('./config/config.js');
6-
var sleep = require('sleep');
6+
7+
// Ugly, but sleep lib has issues on osx
8+
sleep = function sleep(ms) {
9+
var start = new Date().getTime();
10+
while (new Date().getTime() < start + ms);
11+
}
712

813
Deploy = function(env, contractFiles, blockchainConfig, contractsConfig) {
914
//this.blockchainConfig = (new Config.Blockchain()).loadConfigFile('config/blockchain.yml').config(env);
@@ -25,6 +30,20 @@ Deploy = function(env, contractFiles, blockchainConfig, contractsConfig) {
2530
console.log("primary account address is : " + primaryAddress);
2631
};
2732

33+
Deploy.prototype.deploy_contract = function(contractObject, contractParams) {
34+
var transactionHash = contractObject["new"].apply(contractObject, contractParams).transactionHash;
35+
var receipt = null;
36+
var time = 0;
37+
while ((receipt = web3.eth.getTransactionReceipt(transactionHash)) === null || receipt.contractAddress === null) {
38+
sleep(1000);
39+
time += 1;
40+
if (time >= 20) {
41+
return false;
42+
}
43+
}
44+
return receipt;
45+
}
46+
2847
Deploy.prototype.deploy_contracts = function(env) {
2948
this.contractsManager.compileContracts(env);
3049
all_contracts = this.contractsManager.all_contracts;
@@ -64,16 +83,12 @@ Deploy.prototype.deploy_contracts = function(env) {
6483
gasPrice: contract.gasPrice
6584
});
6685

67-
var transactionHash = contractObject["new"].apply(contractObject, contractParams).transactionHash;
68-
// TODO: get this with sync until a different mechanism is implemented
69-
//this.deployedContracts[className] = contractAddress;
70-
//console.log("address is " + contractAddress);
71-
7286
console.log('trying to obtain ' + className + ' address...');
73-
var receipt = null;
74-
while ((receipt = web3.eth.getTransactionReceipt(transactionHash)) === null || receipt.contractAddress === null) {
75-
sleep.sleep(1);
87+
88+
while((receipt = this.deploy_contract(contractObject, contractParams)) === false) {
89+
console.log("timeout... failed to deploy contract.. retrying...");
7690
}
91+
7792
var contractAddress = receipt.contractAddress;
7893
this.deployedContracts[className] = contractAddress;
7994

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"python": "^0.0.4",
2424
"read-yaml": "^1.0.0",
2525
"shelljs": "^0.5.0",
26-
"sleep": "^3.0.0",
2726
"sync-me": "^0.1.1",
2827
"toposort": "^0.2.10",
2928
"web3": "^0.8.1",

test/support/blockchain.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ development:
66
genesis_block: config/genesis.json
77
datadir: /tmp/embark
88
mine_when_needed: true
9-
gas_limit: 500000
9+
gas_limit: 1000000
1010
gas_price: 10000000000000
1111
console: false
1212
account:

0 commit comments

Comments
 (0)