Skip to content

Commit cf16a23

Browse files
committed
bitcoind: added zmq precondition
Adds a state check that transaction and block events are over the same host and port. This is to make sure that block events can be subscribed to and that the tip of the chain stays up to date for correct confirmation counts.
1 parent c897f62 commit cf16a23

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/services/bitcoind.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ Bitcoin.prototype._checkConfigIndexes = function(spawnConfig, node) {
390390
'Please add "zmqpubhashblock=tcp://127.0.0.1:<port>" to your configuration and restart'
391391
);
392392

393+
$.checkState(
394+
(spawnConfig.zmqpubhashblock === spawnConfig.zmqpubrawtx),
395+
'"zmqpubrawtx" and "zmqpubhashblock" are expected to the same host and port in bitcoin.conf'
396+
);
397+
393398
if (spawnConfig.reindex && spawnConfig.reindex === 1) {
394399
log.warn('Reindex option is currently enabled. This means that bitcoind is undergoing a reindex. ' +
395400
'The reindex flag will start the index from beginning every time the node is started, so it ' +

test/services/bitcoind.unit.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ describe('Bitcoin Service', function() {
429429
beforeEach(function() {
430430
sandbox.stub(log, 'warn');
431431
});
432-
after(function() {
432+
afterEach(function() {
433433
sandbox.restore();
434434
});
435435
it('should warn the user if reindex is set to 1 in the bitcoin.conf file', function() {
@@ -448,6 +448,22 @@ describe('Bitcoin Service', function() {
448448
log.warn.callCount.should.equal(1);
449449
node._reindex.should.equal(true);
450450
});
451+
it('should warn if zmq port and hosts do not match', function() {
452+
var bitcoind = new BitcoinService(baseConfig);
453+
var config = {
454+
txindex: 1,
455+
addressindex: 1,
456+
spentindex: 1,
457+
server: 1,
458+
zmqpubrawtx: 'tcp://127.0.0.1:28332',
459+
zmqpubhashblock: 'tcp://127.0.0.1:28331',
460+
reindex: 1
461+
};
462+
var node = {};
463+
(function() {
464+
bitcoind._checkConfigIndexes(config, node);
465+
}).should.throw('"zmqpubrawtx" and "zmqpubhashblock"');
466+
});
451467
});
452468

453469
describe('#_resetCaches', function() {

0 commit comments

Comments
 (0)