Skip to content

Commit

Permalink
bitcoind: get detailed transactions with concurrency
Browse files Browse the repository at this point in the history
increase performance of querying address history by executing multiple
rpc calls concurrently with a configurable limit
  • Loading branch information
braydonf committed Jun 7, 2016
1 parent e87f628 commit 3715f07
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/services/bitcoind.js
Expand Up @@ -76,6 +76,7 @@ Bitcoin.DEFAULT_TRY_ALL_INTERVAL = 1000;
Bitcoin.DEFAULT_REINDEX_INTERVAL = 10000;
Bitcoin.DEFAULT_START_RETRY_INTERVAL = 5000;
Bitcoin.DEFAULT_TIP_UPDATE_INTERVAL = 15000;
Bitcoin.DEFAULT_TRANSACTION_CONCURRENCY = 5;
Bitcoin.DEFAULT_CONFIG_SETTINGS = {
server: 1,
whitelist: '127.0.0.1',
Expand All @@ -92,6 +93,8 @@ Bitcoin.DEFAULT_CONFIG_SETTINGS = {
};

Bitcoin.prototype._initDefaults = function(options) {
/* jshint maxcomplexity: 15 */

// limits
this.maxTxids = options.maxTxids || Bitcoin.DEFAULT_MAX_TXIDS;
this.maxTransactionHistory = options.maxTransactionHistory || Bitcoin.DEFAULT_MAX_HISTORY;
Expand All @@ -106,6 +109,9 @@ Bitcoin.prototype._initDefaults = function(options) {
this.tryAllInterval = options.tryAllInterval || Bitcoin.DEFAULT_TRY_ALL_INTERVAL;
this.startRetryInterval = options.startRetryInterval || Bitcoin.DEFAULT_START_RETRY_INTERVAL;

// rpc limits
this.transactionConcurrency = options.transactionConcurrency || Bitcoin.DEFAULT_TRANSACTION_CONCURRENCY;

// sync progress level when zmq subscribes to events
this.zmqSubscribeProgress = options.zmqSubscribeProgress || Bitcoin.DEFAULT_ZMQ_SUBSCRIBE_PROGRESS;
};
Expand Down Expand Up @@ -1412,8 +1418,9 @@ Bitcoin.prototype.getAddressHistory = function(addressArg, options, callback) {
return callback(e);
}

async.mapSeries(
async.mapLimit(
txids,
self.transactionConcurrency,
function(txid, next) {
self._getAddressDetailedTransaction(txid, {
queryMempool: queryMempool,
Expand Down
10 changes: 10 additions & 0 deletions test/services/bitcoind.unit.js
Expand Up @@ -83,6 +83,16 @@ describe('Bitcoin Service', function() {
});
});

describe('#_initDefaults', function() {
it('will set transaction concurrency', function() {
var bitcoind = new BitcoinService(baseConfig);
bitcoind._initDefaults({transactionConcurrency: 10});
bitcoind.transactionConcurrency.should.equal(10);
bitcoind._initDefaults({});
bitcoind.transactionConcurrency.should.equal(5);
});
});

describe('@dependencies', function() {
it('will have no dependencies', function() {
BitcoinService.dependencies.should.deep.equal([]);
Expand Down

0 comments on commit 3715f07

Please sign in to comment.