Merge pull request #1068 from chaotixkilla/fix-multi-coin-install
Prevent multiple blockchains to be installed simultaneously
This commit is contained in:
commit
14260807c2
11 changed files with 155 additions and 12 deletions
|
|
@ -9,6 +9,8 @@ const _ = require('lodash/fp')
|
||||||
|
|
||||||
const { utils: coinUtils } = require('lamassu-coins')
|
const { utils: coinUtils } = require('lamassu-coins')
|
||||||
const options = require('../options')
|
const options = require('../options')
|
||||||
|
const settingsLoader = require('../new-settings-loader')
|
||||||
|
const wallet = require('../wallet')
|
||||||
|
|
||||||
const common = require('./common')
|
const common = require('./common')
|
||||||
const doVolume = require('./do-volume')
|
const doVolume = require('./do-volume')
|
||||||
|
|
@ -112,6 +114,35 @@ function plugin (crypto) {
|
||||||
return plugin
|
return plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getBlockchainSyncStatus (cryptoList) {
|
||||||
|
const installedCryptos = _.reduce((acc, value) => ({ ...acc, [value.cryptoCode]: isInstalledSoftware(value) && isInstalledVolume(value) }), {}, cryptoList)
|
||||||
|
|
||||||
|
return settingsLoader.loadLatest()
|
||||||
|
.then(settings => {
|
||||||
|
const installedButNotConfigured = []
|
||||||
|
const blockchainStatuses = _.reduce((acc, value) => {
|
||||||
|
const processStatus = common.es(`sudo supervisorctl status ${value.code} | awk '{ print $2 }'`).trim()
|
||||||
|
return acc.then(a => {
|
||||||
|
return wallet.checkBlockchainStatus(settings, value.cryptoCode)
|
||||||
|
.then(res => _.includes(value.cryptoCode, _.keys(installedCryptos)) ? Promise.resolve({ ...a, [value.cryptoCode]: res }) : Promise.resolve({ ...a }))
|
||||||
|
.catch(() => {
|
||||||
|
if (processStatus === 'RUNNING') {
|
||||||
|
installedButNotConfigured.push(value.cryptoCode)
|
||||||
|
return Promise.resolve({ ...a, [value.cryptoCode]: 'syncing' })
|
||||||
|
}
|
||||||
|
return Promise.resolve({ ...a })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
Promise.resolve({}),
|
||||||
|
cryptoList
|
||||||
|
)
|
||||||
|
|
||||||
|
return Promise.all([blockchainStatuses, installedButNotConfigured])
|
||||||
|
})
|
||||||
|
.then(([blockchainStatuses, installedButNotConfigured]) => ({ blockchainStatuses, installedButNotConfigured }))
|
||||||
|
}
|
||||||
|
|
||||||
function run () {
|
function run () {
|
||||||
const choices = _.flow([
|
const choices = _.flow([
|
||||||
_.filter(c => c.type !== 'erc-20'),
|
_.filter(c => c.type !== 'erc-20'),
|
||||||
|
|
@ -129,13 +160,40 @@ function run () {
|
||||||
|
|
||||||
const questions = []
|
const questions = []
|
||||||
|
|
||||||
|
const validateAnswers = async (answers) => {
|
||||||
|
if (_.size(answers) > 2) return { message: `Please insert a maximum of two coins to install.`, isValid: false }
|
||||||
|
return getBlockchainSyncStatus(cryptos)
|
||||||
|
.then(({ blockchainStatuses, installedButNotConfigured }) => {
|
||||||
|
if (!_.isEmpty(installedButNotConfigured)) {
|
||||||
|
logger.warn(`Detected ${_.join(' and ', installedButNotConfigured)} installed on this machine, but couldn't establish connection. ${_.size(installedButNotConfigured) === 1 ? `Is this plugin` : `Are these plugins`} configured via admin?`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = _.reduce((acc, value) => ({ ...acc, [value]: _.isNil(acc[value]) ? 1 : acc[value] + 1 }), {}, _.values(blockchainStatuses))
|
||||||
|
if (_.size(answers) + result.syncing > 2) {
|
||||||
|
return { message: `Installing these coins would pass the 2 parallel blockchain synchronization limit. Please try again with fewer coins or try again later.`, isValid: false }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.syncing > 2) {
|
||||||
|
return { message: `There are currently more than 2 blockchains in their initial synchronization. Please try again later.`, isValid: false }
|
||||||
|
}
|
||||||
|
|
||||||
|
return { message: null, isValid: true }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
questions.push({
|
questions.push({
|
||||||
type: 'checkbox',
|
type: 'checkbox',
|
||||||
name: 'crypto',
|
name: 'crypto',
|
||||||
message: 'Which cryptocurrencies would you like to install?',
|
message: 'Which cryptocurrencies would you like to install?\nTo prevent server resource overloading, only TWO coins should be syncing simultaneously.\nMore coins can be installed after this process is over.',
|
||||||
choices
|
choices
|
||||||
})
|
})
|
||||||
|
|
||||||
inquirer.prompt(questions)
|
inquirer.prompt(questions)
|
||||||
.then(answers => processCryptos(answers.crypto))
|
.then(answers => Promise.all([validateAnswers(answers.crypto), answers]))
|
||||||
|
.then(([res, answers]) => {
|
||||||
|
if (res.isValid) {
|
||||||
|
return processCryptos(answers.crypto)
|
||||||
|
}
|
||||||
|
logger.error(res.message)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,12 @@ function supportsBatching (cryptoCode) {
|
||||||
.then(() => SUPPORTS_BATCHING)
|
.then(() => SUPPORTS_BATCHING)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkBlockchainStatus (cryptoCode) {
|
||||||
|
return checkCryptoCode(cryptoCode)
|
||||||
|
.then(() => fetch('getblockchaininfo'))
|
||||||
|
.then(res => !!res['initialblockdownload'] ? 'syncing' : 'ready')
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
balance,
|
balance,
|
||||||
sendCoins,
|
sendCoins,
|
||||||
|
|
@ -130,5 +136,6 @@ module.exports = {
|
||||||
getStatus,
|
getStatus,
|
||||||
newFunding,
|
newFunding,
|
||||||
cryptoNetwork,
|
cryptoNetwork,
|
||||||
supportsBatching
|
supportsBatching,
|
||||||
|
checkBlockchainStatus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -176,6 +176,12 @@ function supportsBatching (cryptoCode) {
|
||||||
.then(() => SUPPORTS_BATCHING)
|
.then(() => SUPPORTS_BATCHING)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkBlockchainStatus (cryptoCode) {
|
||||||
|
return checkCryptoCode(cryptoCode)
|
||||||
|
.then(() => fetch('getblockchaininfo'))
|
||||||
|
.then(res => !!res['initialblockdownload'] ? 'syncing' : 'ready')
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
balance,
|
balance,
|
||||||
sendCoins,
|
sendCoins,
|
||||||
|
|
@ -186,5 +192,6 @@ module.exports = {
|
||||||
fetchRBF,
|
fetchRBF,
|
||||||
estimateFee,
|
estimateFee,
|
||||||
sendCoinsBatch,
|
sendCoinsBatch,
|
||||||
supportsBatching
|
supportsBatching,
|
||||||
|
checkBlockchainStatus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -164,6 +164,11 @@ function supportsBatching (cryptoCode) {
|
||||||
.then(() => SUPPORTS_BATCHING)
|
.then(() => SUPPORTS_BATCHING)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkBlockchainStatus (cryptoCode) {
|
||||||
|
return checkCryptoCode(cryptoCode)
|
||||||
|
.then(() => Promise.resolve('ready'))
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
NAME,
|
NAME,
|
||||||
balance,
|
balance,
|
||||||
|
|
@ -172,5 +177,6 @@ module.exports = {
|
||||||
getStatus,
|
getStatus,
|
||||||
newFunding,
|
newFunding,
|
||||||
cryptoNetwork,
|
cryptoNetwork,
|
||||||
supportsBatching
|
supportsBatching,
|
||||||
|
checkBlockchainStatus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -118,11 +118,18 @@ function supportsBatching (cryptoCode) {
|
||||||
.then(() => SUPPORTS_BATCHING)
|
.then(() => SUPPORTS_BATCHING)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkBlockchainStatus (cryptoCode) {
|
||||||
|
return checkCryptoCode(cryptoCode)
|
||||||
|
.then(() => fetch('getblockchaininfo'))
|
||||||
|
.then(res => !!res['initialblockdownload'] ? 'syncing' : 'ready')
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
balance,
|
balance,
|
||||||
sendCoins,
|
sendCoins,
|
||||||
newAddress,
|
newAddress,
|
||||||
getStatus,
|
getStatus,
|
||||||
newFunding,
|
newFunding,
|
||||||
supportsBatching
|
supportsBatching,
|
||||||
|
checkBlockchainStatus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,8 @@ module.exports = {
|
||||||
privateKey,
|
privateKey,
|
||||||
isStrictAddress,
|
isStrictAddress,
|
||||||
connect,
|
connect,
|
||||||
supportsBatching
|
supportsBatching,
|
||||||
|
checkBlockchainStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
function connect (url) {
|
function connect (url) {
|
||||||
|
|
@ -230,3 +231,9 @@ function supportsBatching (cryptoCode) {
|
||||||
return checkCryptoCode(cryptoCode)
|
return checkCryptoCode(cryptoCode)
|
||||||
.then(() => SUPPORTS_BATCHING)
|
.then(() => SUPPORTS_BATCHING)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkBlockchainStatus (cryptoCode) {
|
||||||
|
return checkCryptoCode(cryptoCode)
|
||||||
|
.then(pify(web3.eth.isSyncing))
|
||||||
|
.then(res => _.isObject(res) ? 'syncing' : 'ready')
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -118,11 +118,18 @@ function supportsBatching (cryptoCode) {
|
||||||
.then(() => SUPPORTS_BATCHING)
|
.then(() => SUPPORTS_BATCHING)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkBlockchainStatus (cryptoCode) {
|
||||||
|
return checkCryptoCode(cryptoCode)
|
||||||
|
.then(() => fetch('getblockchaininfo'))
|
||||||
|
.then(res => !!res['initialblockdownload'] ? 'syncing' : 'ready')
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
balance,
|
balance,
|
||||||
sendCoins,
|
sendCoins,
|
||||||
newAddress,
|
newAddress,
|
||||||
getStatus,
|
getStatus,
|
||||||
newFunding,
|
newFunding,
|
||||||
supportsBatching
|
supportsBatching,
|
||||||
|
checkBlockchainStatus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,11 @@ function supportsBatching (cryptoCode) {
|
||||||
return Promise.resolve(_.includes(cryptoCode, BATCHABLE_COINS))
|
return Promise.resolve(_.includes(cryptoCode, BATCHABLE_COINS))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkBlockchainStatus (cryptoCode) {
|
||||||
|
return checkCryptoCode(cryptoCode)
|
||||||
|
.then(() => Promise.resolve('ready'))
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
NAME,
|
NAME,
|
||||||
balance,
|
balance,
|
||||||
|
|
@ -123,5 +128,6 @@ module.exports = {
|
||||||
newAddress,
|
newAddress,
|
||||||
getStatus,
|
getStatus,
|
||||||
newFunding,
|
newFunding,
|
||||||
supportsBatching
|
supportsBatching,
|
||||||
|
checkBlockchainStatus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -205,6 +205,30 @@ function supportsBatching (cryptoCode) {
|
||||||
.then(() => SUPPORTS_BATCHING)
|
.then(() => SUPPORTS_BATCHING)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkBlockchainStatus (cryptoCode) {
|
||||||
|
return checkCryptoCode(cryptoCode)
|
||||||
|
.then(() => {
|
||||||
|
try {
|
||||||
|
const config = jsonRpc.parseConf(configPath)
|
||||||
|
|
||||||
|
// Daemon uses a different connection of the wallet
|
||||||
|
const rpcConfig = {
|
||||||
|
username: config['rpc-login'].split(':')[0],
|
||||||
|
password: config['rpc-login'].split(':')[1],
|
||||||
|
port: cryptoRec.defaultPort
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsonRpc.fetchDigest(rpcConfig, 'get_info')
|
||||||
|
.then(res => {
|
||||||
|
console.log('res XMR', res)
|
||||||
|
return !!res.synchronized ? 'ready' : 'syncing'
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error('XMR daemon is currently not installed')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
balance,
|
balance,
|
||||||
sendCoins,
|
sendCoins,
|
||||||
|
|
@ -212,5 +236,6 @@ module.exports = {
|
||||||
getStatus,
|
getStatus,
|
||||||
newFunding,
|
newFunding,
|
||||||
cryptoNetwork,
|
cryptoNetwork,
|
||||||
supportsBatching
|
supportsBatching,
|
||||||
|
checkBlockchainStatus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -144,11 +144,18 @@ function supportsBatching (cryptoCode) {
|
||||||
.then(() => SUPPORTS_BATCHING)
|
.then(() => SUPPORTS_BATCHING)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkBlockchainStatus (cryptoCode) {
|
||||||
|
return checkCryptoCode(cryptoCode)
|
||||||
|
.then(() => fetch('getblockchaininfo'))
|
||||||
|
.then(res => !!res['initial_block_download_complete'] ? 'ready' : 'syncing')
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
balance,
|
balance,
|
||||||
sendCoins,
|
sendCoins,
|
||||||
newAddress,
|
newAddress,
|
||||||
getStatus,
|
getStatus,
|
||||||
newFunding,
|
newFunding,
|
||||||
supportsBatching
|
supportsBatching,
|
||||||
|
checkBlockchainStatus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -237,6 +237,11 @@ function supportsBatching (settings, cryptoCode) {
|
||||||
.then(r => r.wallet.supportsBatching(cryptoCode))
|
.then(r => r.wallet.supportsBatching(cryptoCode))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkBlockchainStatus (settings, cryptoCode) {
|
||||||
|
return fetchWallet(settings, cryptoCode)
|
||||||
|
.then(r => r.wallet.checkBlockchainStatus(cryptoCode))
|
||||||
|
}
|
||||||
|
|
||||||
const coinFilter = ['ETH']
|
const coinFilter = ['ETH']
|
||||||
|
|
||||||
const balance = (settings, cryptoCode) => {
|
const balance = (settings, cryptoCode) => {
|
||||||
|
|
@ -265,5 +270,6 @@ module.exports = {
|
||||||
isHd,
|
isHd,
|
||||||
newFunding,
|
newFunding,
|
||||||
cryptoNetwork,
|
cryptoNetwork,
|
||||||
supportsBatching
|
supportsBatching,
|
||||||
|
checkBlockchainStatus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue