mirror of https://github.com/embarklabs/embark.git
Fix race condition on deploy tracker
This commit is contained in:
parent
94758a1ea4
commit
e20d7bfc6a
|
@ -41,63 +41,69 @@ class DeployManager {
|
|||
|
||||
deployAll(done) {
|
||||
let self = this;
|
||||
|
||||
self.events.request('contracts:dependencies', (err, contractDependencies) => {
|
||||
self.events.request('contracts:list', (err, contracts) => {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
self.logger.info(__("deploying contracts"));
|
||||
self.events.emit("deploy:beforeAll");
|
||||
|
||||
const contractDeploys = {};
|
||||
const errors = [];
|
||||
contracts.forEach(contract => {
|
||||
function deploy(result, callback) {
|
||||
if (typeof result === 'function') {
|
||||
callback = result;
|
||||
async.waterfall([
|
||||
function loadTracker(next) {
|
||||
self.events.request("deployTracker:load", next);
|
||||
},
|
||||
function doDeployAll() {
|
||||
self.events.request('contracts:dependencies', (err, contractDependencies) => {
|
||||
self.events.request('contracts:list', (err, contracts) => {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
contract._gasLimit = self.gasLimit;
|
||||
self.events.request('deploy:contract', contract, (err) => {
|
||||
if (err) {
|
||||
contract.error = err.message || err;
|
||||
self.logger.error(err.message || err);
|
||||
errors.push(err);
|
||||
|
||||
self.logger.info(__("deploying contracts"));
|
||||
self.events.emit("deploy:beforeAll");
|
||||
|
||||
const contractDeploys = {};
|
||||
const errors = [];
|
||||
contracts.forEach(contract => {
|
||||
function deploy(result, callback) {
|
||||
if (typeof result === 'function') {
|
||||
callback = result;
|
||||
}
|
||||
contract._gasLimit = self.gasLimit;
|
||||
self.events.request('deploy:contract', contract, (err) => {
|
||||
if (err) {
|
||||
contract.error = err.message || err;
|
||||
self.logger.error(err.message || err);
|
||||
errors.push(err);
|
||||
}
|
||||
callback();
|
||||
});
|
||||
}
|
||||
callback();
|
||||
|
||||
const className = contract.className;
|
||||
if (!contractDependencies[className] || contractDependencies[className].length === 0) {
|
||||
contractDeploys[className] = deploy;
|
||||
return;
|
||||
}
|
||||
contractDeploys[className] = cloneDeep(contractDependencies[className]);
|
||||
contractDeploys[className].push(deploy);
|
||||
});
|
||||
}
|
||||
|
||||
const className = contract.className;
|
||||
if (!contractDependencies[className] || contractDependencies[className].length === 0) {
|
||||
contractDeploys[className] = deploy;
|
||||
return;
|
||||
}
|
||||
contractDeploys[className] = cloneDeep(contractDependencies[className]);
|
||||
contractDeploys[className].push(deploy);
|
||||
});
|
||||
|
||||
try {
|
||||
async.auto(contractDeploys, function(_err, _results) {
|
||||
if (errors.length) {
|
||||
_err = __("Error deploying contracts. Please fix errors to continue.");
|
||||
self.logger.error(_err);
|
||||
return done(_err);
|
||||
try {
|
||||
async.auto(contractDeploys, function(_err, _results) {
|
||||
if (errors.length) {
|
||||
_err = __("Error deploying contracts. Please fix errors to continue.");
|
||||
self.logger.error(_err);
|
||||
return done(_err);
|
||||
}
|
||||
if (contracts.length === 0) {
|
||||
self.logger.info(__("no contracts found"));
|
||||
return done();
|
||||
}
|
||||
self.logger.info(__("finished deploying contracts"));
|
||||
done(err);
|
||||
});
|
||||
} catch (e) {
|
||||
self.logger.error(e.message || e);
|
||||
done(__('Error deploying'));
|
||||
}
|
||||
if (contracts.length === 0) {
|
||||
self.logger.info(__("no contracts found"));
|
||||
return done();
|
||||
}
|
||||
self.logger.info(__("finished deploying contracts"));
|
||||
done(err);
|
||||
});
|
||||
} catch (e) {
|
||||
self.logger.error(e.message || e);
|
||||
done(__('Error deploying'));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
deployContracts(done) {
|
||||
|
|
|
@ -19,7 +19,7 @@ class DeployTracker {
|
|||
registerEvents() {
|
||||
const self = this;
|
||||
|
||||
this.events.on("deploy:beforeAll", this.setCurrentChain.bind(this));
|
||||
this.events.setCommandHandler("deployTracker:load", this.setCurrentChain.bind(this));
|
||||
|
||||
this.events.on("deploy:contract:deployed", (contract) => {
|
||||
self.trackContract(contract.className, contract.realRuntimeBytecode, contract.realArgs, contract.deployedAddress);
|
||||
|
@ -43,15 +43,12 @@ class DeployTracker {
|
|||
});
|
||||
}
|
||||
|
||||
// TODO: just an event might not be enought to the async nature
|
||||
// it needs to be a plugin api before deploy, that makes the deployment wait
|
||||
setCurrentChain() {
|
||||
setCurrentChain(cb) {
|
||||
const self = this;
|
||||
if (this.chainConfig === false) {
|
||||
this.currentChain = {contracts: []};
|
||||
//return cb();
|
||||
return cb();
|
||||
}
|
||||
|
||||
this.events.request("blockchain:block:byNumber", 0, function(_err, block) {
|
||||
let chainId = block.hash;
|
||||
|
||||
|
@ -62,7 +59,7 @@ class DeployTracker {
|
|||
self.currentChain = self.chainConfig[chainId];
|
||||
|
||||
self.currentChain.name = self.env;
|
||||
//cb();
|
||||
cb();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue