fix(blockchain): check if node is synched after connection

This commit is contained in:
Jonathan Rainville 2019-02-26 14:09:47 -05:00
parent 217357640a
commit 0639717d0c
2 changed files with 37 additions and 18 deletions

View File

@ -174,23 +174,39 @@ class BlockchainConnector {
if (err) { if (err) {
return self.logger.error(err); return self.logger.error(err);
} }
self.provider.startWeb3Provider(() => { self.provider.startWeb3Provider(async () => {
this.getNetworkId() try {
.then(id => { const blockNumber = await self.web3.eth.getBlockNumber();
await self.web3.eth.getBlock(blockNumber);
self.provider.fundAccounts(() => {
self._emitWeb3Ready();
cb();
});
} catch (e) {
const errorMessage = e.message || e;
if (errorMessage.indexOf('no suitable peers available') > 0) {
self.logger.warn(errorMessage);
self.logger.warn(__('Your node is probably not synchronized. Wait until your node is synchronized before deploying'));
process.exit(1);
}
self.logger.error(errorMessage);
cb(errorMessage);
}
try {
const id = await this.getNetworkId();
let networkId = self.config.blockchainConfig.networkId; let networkId = self.config.blockchainConfig.networkId;
if (!networkId && constants.blockchain.networkIds[self.config.blockchainConfig.networkType]) { if (!networkId &&
constants.blockchain.networkIds[self.config.blockchainConfig.networkType]) {
networkId = constants.blockchain.networkIds[self.config.blockchainConfig.networkType]; networkId = constants.blockchain.networkIds[self.config.blockchainConfig.networkType];
} }
if (networkId && id.toString() !== networkId.toString()) { if (networkId && id.toString() !== networkId.toString()) {
self.logger.warn(__('Connected to a blockchain node on network {{realId}} while your config specifies {{configId}}', {realId: id, configId: networkId})); self.logger.warn(__('Connected to a blockchain node on network {{realId}} while your config specifies {{configId}}', {realId: id, configId: networkId}));
self.logger.warn(__('Make sure you started the right blockchain node')); self.logger.warn(__('Make sure you started the right blockchain node'));
} }
}) } catch (e) {
.catch(console.error); console.error(e);
self.provider.fundAccounts(() => { }
self._emitWeb3Ready();
cb();
});
}); });
}); });
} }

View File

@ -185,7 +185,10 @@ class ContractDeployer {
return self.deployContract(contract, next); return self.deployContract(contract, next);
} }
self.blockchain.getCode(trackedContract.address, function(_getCodeErr, codeInChain) { self.blockchain.getCode(trackedContract.address, function(getCodeErr, codeInChain) {
if (getCodeErr) {
return next(getCodeErr);
}
if (codeInChain.length > 3 || skipBytecodeCheck) { // it is "0x" or "0x0" for empty code, depending on web3 version if (codeInChain.length > 3 || skipBytecodeCheck) { // it is "0x" or "0x0" for empty code, depending on web3 version
self.contractAlreadyDeployed(contract, trackedContract, next); self.contractAlreadyDeployed(contract, trackedContract, next);
} else { } else {