bitcoind: relative spawn.datadir handling
Will expand the datadir into an absolute path based on the location of the configuration file. This is to avoid unexpected behavior in regards to the location of configuration files.
This commit is contained in:
parent
c897f62d02
commit
814576953c
@ -228,6 +228,7 @@ Node.prototype._startService = function(serviceInfo, callback) {
|
|||||||
Node.prototype._logTitle = function() {
|
Node.prototype._logTitle = function() {
|
||||||
if (this.configPath) {
|
if (this.configPath) {
|
||||||
log.info('Using config:', this.configPath);
|
log.info('Using config:', this.configPath);
|
||||||
|
log.info('Using network:', this.getNetworkName());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -61,7 +61,6 @@ function checkConfigVersion2(fullConfig) {
|
|||||||
* @param {Object} options.config - The parsed bitcore-node.json configuration file
|
* @param {Object} options.config - The parsed bitcore-node.json configuration file
|
||||||
* @param {Array} options.config.services - An array of services names.
|
* @param {Array} options.config.services - An array of services names.
|
||||||
* @param {Object} options.config.servicesConfig - Parameters to pass to each service
|
* @param {Object} options.config.servicesConfig - Parameters to pass to each service
|
||||||
* @param {String} options.config.datadir - A relative (to options.path) or absolute path to the datadir
|
|
||||||
* @param {String} options.config.network - 'livenet', 'testnet' or 'regtest
|
* @param {String} options.config.network - 'livenet', 'testnet' or 'regtest
|
||||||
* @param {Number} options.config.port - The port to use for the web service
|
* @param {Number} options.config.port - The port to use for the web service
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
var spawn = require('child_process').spawn;
|
var spawn = require('child_process').spawn;
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var mkdirp = require('mkdirp');
|
var mkdirp = require('mkdirp');
|
||||||
@ -16,6 +17,7 @@ var Transaction = bitcore.Transaction;
|
|||||||
var index = require('../');
|
var index = require('../');
|
||||||
var errors = index.errors;
|
var errors = index.errors;
|
||||||
var log = index.log;
|
var log = index.log;
|
||||||
|
var utils = require('../utils');
|
||||||
var Service = require('../service');
|
var Service = require('../service');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -318,8 +320,17 @@ Bitcoin.prototype._loadSpawnConfiguration = function(node) {
|
|||||||
$.checkArgument(this.options.spawn.datadir, 'Please specify "spawn.datadir" in bitcoind config options');
|
$.checkArgument(this.options.spawn.datadir, 'Please specify "spawn.datadir" in bitcoind config options');
|
||||||
$.checkArgument(this.options.spawn.exec, 'Please specify "spawn.exec" in bitcoind config options');
|
$.checkArgument(this.options.spawn.exec, 'Please specify "spawn.exec" in bitcoind config options');
|
||||||
|
|
||||||
|
if (!utils.isAbsolutePath(this.options.spawn.datadir)) {
|
||||||
|
$.checkState(this.node.configPath);
|
||||||
|
$.checkState(utils.isAbsolutePath(this.node.configPath));
|
||||||
|
var baseConfigPath = path.dirname(this.node.configPath);
|
||||||
|
this.options.spawn.datadir = path.resolve(baseConfigPath, this.options.spawn.datadir);
|
||||||
|
}
|
||||||
|
|
||||||
var spawnOptions = this.options.spawn;
|
var spawnOptions = this.options.spawn;
|
||||||
var configPath = spawnOptions.datadir + '/bitcoin.conf';
|
var configPath = path.resolve(spawnOptions.datadir, './bitcoin.conf');
|
||||||
|
|
||||||
|
log.info('Using bitcoin config file:', configPath);
|
||||||
|
|
||||||
this.spawn = {};
|
this.spawn = {};
|
||||||
this.spawn.datadir = this.options.spawn.datadir;
|
this.spawn.datadir = this.options.spawn.datadir;
|
||||||
|
|||||||
@ -340,6 +340,13 @@ describe('Bitcoin Service', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#_loadSpawnConfiguration', function() {
|
describe('#_loadSpawnConfiguration', function() {
|
||||||
|
var sandbox = sinon.sandbox.create();
|
||||||
|
beforeEach(function() {
|
||||||
|
sandbox.stub(log, 'info');
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
sandbox.restore();
|
||||||
|
});
|
||||||
it('will parse a bitcoin.conf file', function() {
|
it('will parse a bitcoin.conf file', function() {
|
||||||
var TestBitcoin = proxyquire('../../lib/services/bitcoind', {
|
var TestBitcoin = proxyquire('../../lib/services/bitcoind', {
|
||||||
fs: {
|
fs: {
|
||||||
@ -352,7 +359,9 @@ describe('Bitcoin Service', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
var bitcoind = new TestBitcoin(baseConfig);
|
var bitcoind = new TestBitcoin(baseConfig);
|
||||||
bitcoind._loadSpawnConfiguration({datadir: process.env.HOME + '/.bitcoin'});
|
bitcoind.options.spawn.datadir = '/tmp/.bitcoin';
|
||||||
|
var node = {};
|
||||||
|
bitcoind._loadSpawnConfiguration(node);
|
||||||
should.exist(bitcoind.spawn.config);
|
should.exist(bitcoind.spawn.config);
|
||||||
bitcoind.spawn.config.should.deep.equal({
|
bitcoind.spawn.config.should.deep.equal({
|
||||||
addressindex: 1,
|
addressindex: 1,
|
||||||
@ -374,6 +383,33 @@ describe('Bitcoin Service', function() {
|
|||||||
zmqpubrawtx: 'tcp://127.0.0.1:28332'
|
zmqpubrawtx: 'tcp://127.0.0.1:28332'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('will expand relative datadir to absolute path', function() {
|
||||||
|
var TestBitcoin = proxyquire('../../lib/services/bitcoind', {
|
||||||
|
fs: {
|
||||||
|
readFileSync: readFileSync,
|
||||||
|
existsSync: sinon.stub().returns(true),
|
||||||
|
writeFileSync: sinon.stub()
|
||||||
|
},
|
||||||
|
mkdirp: {
|
||||||
|
sync: sinon.stub()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var config = {
|
||||||
|
node: {
|
||||||
|
network: bitcore.Networks.testnet,
|
||||||
|
configPath: '/tmp/.bitcore/bitcore-node.json'
|
||||||
|
},
|
||||||
|
spawn: {
|
||||||
|
datadir: './data',
|
||||||
|
exec: 'testpath'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var bitcoind = new TestBitcoin(config);
|
||||||
|
bitcoind.options.spawn.datadir = './data';
|
||||||
|
var node = {};
|
||||||
|
bitcoind._loadSpawnConfiguration(node);
|
||||||
|
bitcoind.options.spawn.datadir.should.equal('/tmp/.bitcore/data');
|
||||||
|
});
|
||||||
it('should throw an exception if txindex isn\'t enabled in the configuration', function() {
|
it('should throw an exception if txindex isn\'t enabled in the configuration', function() {
|
||||||
var TestBitcoin = proxyquire('../../lib/services/bitcoind', {
|
var TestBitcoin = proxyquire('../../lib/services/bitcoind', {
|
||||||
fs: {
|
fs: {
|
||||||
@ -420,7 +456,9 @@ describe('Bitcoin Service', function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
var bitcoind = new TestBitcoin(config);
|
var bitcoind = new TestBitcoin(config);
|
||||||
bitcoind._loadSpawnConfiguration({datadir: process.env.HOME + '/.bitcoin'});
|
bitcoind.options.spawn.datadir = '/tmp/.bitcoin';
|
||||||
|
var node = {};
|
||||||
|
bitcoind._loadSpawnConfiguration(node);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user