diff --git a/lib/modules/blockchain_process/blockchain.js b/lib/modules/blockchain_process/blockchain.js index 09400f55a..419b8a44b 100644 --- a/lib/modules/blockchain_process/blockchain.js +++ b/lib/modules/blockchain_process/blockchain.js @@ -305,6 +305,13 @@ Blockchain.prototype.isClientInstalled = function (callback) { if (err || !stdout || stderr.indexOf("not found") >= 0 || stdout.indexOf("not found") >= 0) { return callback(__('Ethereum client bin not found:') + ' ' + this.client.getBinaryPath()); } + const parsedVersion = this.client.parseVersion(stdout); + const supported = this.client.isSupportedVersion(parsedVersion); + if (supported === undefined) { + this.logger.error((__('WARNING! Ethereum client version could not be determined or compared with version range') + ' ' + this.client.versSupported + __(', for best results please use a supported version')).yellow); + } else if (!supported) { + this.logger.error((__('WARNING! Ethereum client version unsupported, for best results please use a version in range') + ' ' + this.client.versSupported).yellow); + } callback(); }); }; @@ -461,6 +468,7 @@ var BlockchainClient = function(userConfig, clientName, env, onReadyCallback, on userConfig.env = env; userConfig.onReadyCallback = onReadyCallback; userConfig.onExitCallback = onExitCallback; + userConfig.logger = logger; return new Blockchain(userConfig, clientClass); }; diff --git a/lib/modules/blockchain_process/blockchainProcess.js b/lib/modules/blockchain_process/blockchainProcess.js index b5d82486b..3f6b62bb2 100644 --- a/lib/modules/blockchain_process/blockchainProcess.js +++ b/lib/modules/blockchain_process/blockchainProcess.js @@ -21,7 +21,8 @@ class BlockchainProcess extends ProcessWrapper { this.client, this.env, this.blockchainReady.bind(this), - this.blockchainExit.bind(this) + this.blockchainExit.bind(this), + console ); this.blockchain.run(); diff --git a/lib/modules/blockchain_process/gethClient.js b/lib/modules/blockchain_process/gethClient.js index 953811d7d..477ec42a3 100644 --- a/lib/modules/blockchain_process/gethClient.js +++ b/lib/modules/blockchain_process/gethClient.js @@ -1,9 +1,11 @@ const async = require('async'); const GethMiner = require('./miner'); const os = require('os'); +const semver = require('semver'); const DEFAULTS = { "BIN": "geth", + "VERSIONS_SUPPORTED": ">=1.8.14", "NETWORK_TYPE": "custom", "NETWORK_ID": 1337, "RPC_API": ['eth', 'web3', 'net', 'debug', 'personal'], @@ -26,6 +28,7 @@ class GethClient { this.name = "geth"; this.prettyName = "Go-Ethereum (https://github.com/ethereum/go-ethereum)"; this.bin = this.config.ethereumClientBin || DEFAULTS.BIN; + this.versSupported = DEFAULTS.VERSIONS_SUPPORTED; this.httpReady = false; this.wsReady = !this.config.wsRPC; } @@ -92,6 +95,30 @@ class GethClient { return this.bin + " version"; } + parseVersion(rawVersionOutput) { + let parsed; + const match = rawVersionOutput.match(/Version: (.*)/); + if (match) { + parsed = match[1].trim(); + } + return parsed; + } + + isSupportedVersion(parsedVersion) { + let test; + try { + let v = semver(parsedVersion); + v = `${v.major}.${v.minor}.${v.patch}`; + test = semver.Range(this.versSupported).test(semver(v)); + if (typeof test !== 'boolean') { + test = undefined; + } + } finally { + // eslint-disable-next-line no-unsafe-finally + return test; + } + } + determineNetworkType(config) { let cmd; if (config.networkType === 'testnet') { diff --git a/lib/modules/blockchain_process/parityClient.js b/lib/modules/blockchain_process/parityClient.js index d1acd208e..316dec9e0 100644 --- a/lib/modules/blockchain_process/parityClient.js +++ b/lib/modules/blockchain_process/parityClient.js @@ -1,9 +1,11 @@ const async = require('async'); const fs = require('../../core/fs.js'); const os = require('os'); +const semver = require('semver'); const DEFAULTS = { "BIN": "parity", + "VERSIONS_SUPPORTED": ">=2.0.0", "NETWORK_TYPE": "dev", "NETWORK_ID": 17, "RPC_API": ["web3", "eth", "pubsub", "net", "parity", "private", "parity_pubsub", "traces", "rpc", "shh", "shh_pubsub"], @@ -33,6 +35,7 @@ class ParityClient { this.name = "parity"; this.prettyName = "Parity-Ethereum (https://github.com/paritytech/parity-ethereum)"; this.bin = this.config.ethereumClientBin || DEFAULTS.BIN; + this.versSupported = DEFAULTS.VERSIONS_SUPPORTED; } isReady(data) { @@ -113,6 +116,30 @@ class ParityClient { return this.bin + " --version"; } + parseVersion(rawVersionOutput) { + let parsed; + const match = rawVersionOutput.match(/version Parity-Ethereum\/(.*?)\//); + if (match) { + parsed = match[1].trim(); + } + return parsed; + } + + isSupportedVersion(parsedVersion) { + let test; + try { + let v = semver(parsedVersion); + v = `${v.major}.${v.minor}.${v.patch}`; + test = semver.Range(this.versSupported).test(semver(v)); + if (typeof test !== 'boolean') { + test = undefined; + } + } finally { + // eslint-disable-next-line no-unsafe-finally + return test; + } + } + determineNetworkType(config) { if (this.isDev) { return "--chain=dev";