From c63e98f0616d6218a744454a6526014b1b4be0ab Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Fri, 22 Apr 2016 16:51:56 -0400 Subject: [PATCH] bitcoind: limit tx history range --- lib/services/bitcoind.js | 6 ++++++ test/services/bitcoind.unit.js | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/services/bitcoind.js b/lib/services/bitcoind.js index b72e2345..f99f30bd 100644 --- a/lib/services/bitcoind.js +++ b/lib/services/bitcoind.js @@ -48,6 +48,7 @@ function Bitcoin(options) { this.subscriptions.hashblock = []; // limits + this.maxTransactionHistory = options.maxTransactionHistory || Bitcoin.DEFAULT_MAX_HISTORY; this.maxAddressesQuery = options.maxAddressesQuery || Bitcoin.DEFAULT_MAX_ADDRESSES_QUERY; this.shutdownTimeout = options.shutdownTimeout || Bitcoin.DEFAULT_SHUTDOWN_TIMEOUT; @@ -62,6 +63,7 @@ util.inherits(Bitcoin, Service); Bitcoin.dependencies = []; +Bitcoin.DEFAULT_MAX_HISTORY = 10; Bitcoin.DEFAULT_SHUTDOWN_TIMEOUT = 15000; Bitcoin.DEFAULT_MAX_ADDRESSES_QUERY = 10000; Bitcoin.DEFAULT_TRY_ALL_INTERVAL = 1000; @@ -1132,6 +1134,10 @@ Bitcoin.prototype._paginateTxids = function(fullTxids, fromArg, toArg) { var to = parseInt(toArg); if (from >= 0 && to >= 0) { $.checkState(from < to, '"from" (' + from + ') is expected to be less than "to" (' + to + ')'); + $.checkState( + (to - from) <= this.maxTransactionHistory, + '"from" (' + from + ') and "to" (' + to + ') range should be less than or equal to ' + this.maxTransactionHistory + ); txids = fullTxids.slice(from, to); } else { txids = fullTxids; diff --git a/test/services/bitcoind.unit.js b/test/services/bitcoind.unit.js index d030cf8b..7d3d227a 100644 --- a/test/services/bitcoind.unit.js +++ b/test/services/bitcoind.unit.js @@ -2054,11 +2054,18 @@ describe('Bitcoin Service', function() { }); describe('#_paginateTxids', function() { + it('slice txids based on "from" and "to" (3 to 13)', function() { + var bitcoind = new BitcoinService(baseConfig); + var txids = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + var paginated = bitcoind._paginateTxids(txids, 3, 13); + paginated.should.deep.equal([3, 4, 5, 6, 7, 8, 9, 10]); + }); it('slice txids based on "from" and "to" (3 to 30)', function() { var bitcoind = new BitcoinService(baseConfig); var txids = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - var paginated = bitcoind._paginateTxids(txids, 3, 30); - paginated.should.deep.equal([3, 4, 5, 6, 7, 8, 9, 10]); + (function() { + bitcoind._paginateTxids(txids, 3, 30); + }).should.throw(Error); }); it('slice txids based on "from" and "to" (0 to 3)', function() { var bitcoind = new BitcoinService(baseConfig);