From cf16a23408fcecbe7717d7d4f75ca256222af41a Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Wed, 1 Jun 2016 19:43:00 -0400 Subject: [PATCH] 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. --- lib/services/bitcoind.js | 5 +++++ test/services/bitcoind.unit.js | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/services/bitcoind.js b/lib/services/bitcoind.js index 4e79fcd6..7707303c 100644 --- a/lib/services/bitcoind.js +++ b/lib/services/bitcoind.js @@ -390,6 +390,11 @@ Bitcoin.prototype._checkConfigIndexes = function(spawnConfig, node) { 'Please add "zmqpubhashblock=tcp://127.0.0.1:" to your configuration and restart' ); + $.checkState( + (spawnConfig.zmqpubhashblock === spawnConfig.zmqpubrawtx), + '"zmqpubrawtx" and "zmqpubhashblock" are expected to the same host and port in bitcoin.conf' + ); + if (spawnConfig.reindex && spawnConfig.reindex === 1) { log.warn('Reindex option is currently enabled. This means that bitcoind is undergoing a reindex. ' + 'The reindex flag will start the index from beginning every time the node is started, so it ' + diff --git a/test/services/bitcoind.unit.js b/test/services/bitcoind.unit.js index 8719f7f5..00f616ef 100644 --- a/test/services/bitcoind.unit.js +++ b/test/services/bitcoind.unit.js @@ -429,7 +429,7 @@ describe('Bitcoin Service', function() { beforeEach(function() { sandbox.stub(log, 'warn'); }); - after(function() { + afterEach(function() { sandbox.restore(); }); 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() { log.warn.callCount.should.equal(1); node._reindex.should.equal(true); }); + it('should warn if zmq port and hosts do not match', function() { + var bitcoind = new BitcoinService(baseConfig); + var config = { + txindex: 1, + addressindex: 1, + spentindex: 1, + server: 1, + zmqpubrawtx: 'tcp://127.0.0.1:28332', + zmqpubhashblock: 'tcp://127.0.0.1:28331', + reindex: 1 + }; + var node = {}; + (function() { + bitcoind._checkConfigIndexes(config, node); + }).should.throw('"zmqpubrawtx" and "zmqpubhashblock"'); + }); }); describe('#_resetCaches', function() {