Address Service: Limit the length of outputs that can be queried at a time
This commit is contained in:
parent
40eb4f50ae
commit
cef2f7686d
@ -41,5 +41,11 @@ exports.SPACER_MAX = new Buffer('ff', 'hex');
|
|||||||
// to cache the summary to disk.
|
// to cache the summary to disk.
|
||||||
exports.SUMMARY_CACHE_THRESHOLD = 10000;
|
exports.SUMMARY_CACHE_THRESHOLD = 10000;
|
||||||
|
|
||||||
|
|
||||||
|
// The default maximum length queries
|
||||||
|
exports.MAX_INPUTS_QUERY_LENGTH = 50000;
|
||||||
|
exports.MAX_OUTPUTS_QUERY_LENGTH = 50000;
|
||||||
|
|
||||||
|
|
||||||
module.exports = exports;
|
module.exports = exports;
|
||||||
|
|
||||||
|
|||||||
@ -45,6 +45,8 @@ var AddressService = function(options) {
|
|||||||
this.node.services.bitcoind.on('txleave', this.transactionLeaveHandler.bind(this));
|
this.node.services.bitcoind.on('txleave', this.transactionLeaveHandler.bind(this));
|
||||||
|
|
||||||
this.summaryCacheThreshold = options.summaryCacheThreshold || constants.SUMMARY_CACHE_THRESHOLD;
|
this.summaryCacheThreshold = options.summaryCacheThreshold || constants.SUMMARY_CACHE_THRESHOLD;
|
||||||
|
this.maxInputsQueryLength = options.maxInputsQueryLength || constants.MAX_INPUTS_QUERY_LENGTH;
|
||||||
|
this.maxOutputsQueryLength = options.maxOutputsQueryLength || constants.MAX_OUTPUTS_QUERY_LENGTH;
|
||||||
|
|
||||||
this._setMempoolIndexPath();
|
this._setMempoolIndexPath();
|
||||||
this._setSummaryCachePath();
|
this._setSummaryCachePath();
|
||||||
@ -849,6 +851,12 @@ AddressService.prototype.getInputs = function(addressStr, options, callback) {
|
|||||||
|
|
||||||
stream.on('data', function(input) {
|
stream.on('data', function(input) {
|
||||||
inputs.push(input);
|
inputs.push(input);
|
||||||
|
if (inputs.length > self.maxInputsQueryLength) {
|
||||||
|
log.warn('Tried to query too many inputs (' + self.maxInputsQueryLength + ') for address '+ addressStr);
|
||||||
|
error = new Error('Maximum number of inputs (' + self.maxInputsQueryLength + ') per query reached');
|
||||||
|
stream.pause();
|
||||||
|
stream.end();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var error;
|
var error;
|
||||||
@ -859,7 +867,7 @@ AddressService.prototype.getInputs = function(addressStr, options, callback) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
stream.on('end', function() {
|
stream.on('finish', function() {
|
||||||
if (error) {
|
if (error) {
|
||||||
return callback(error);
|
return callback(error);
|
||||||
}
|
}
|
||||||
@ -1053,6 +1061,12 @@ AddressService.prototype.getOutputs = function(addressStr, options, callback) {
|
|||||||
|
|
||||||
stream.on('data', function(data) {
|
stream.on('data', function(data) {
|
||||||
outputs.push(data);
|
outputs.push(data);
|
||||||
|
if (outputs.length > self.maxOutputsQueryLength) {
|
||||||
|
log.warn('Tried to query too many outputs (' + self.maxOutputsQueryLength + ') for address ' + addressStr);
|
||||||
|
error = new Error('Maximum number of outputs (' + self.maxOutputsQueryLength + ') per query reached');
|
||||||
|
stream.pause();
|
||||||
|
stream.end();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var error;
|
var error;
|
||||||
@ -1063,7 +1077,7 @@ AddressService.prototype.getOutputs = function(addressStr, options, callback) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
stream.on('end', function() {
|
stream.on('finish', function() {
|
||||||
if (error) {
|
if (error) {
|
||||||
return callback(error);
|
return callback(error);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user