From 0283be05db2e54b3d492dca95c0b93f2325d191f Mon Sep 17 00:00:00 2001 From: sairajzero Date: Fri, 27 Jan 2023 17:31:02 +0530 Subject: [PATCH] Limit max response size --- lib/services/address/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/services/address/index.js b/lib/services/address/index.js index 84ba9da0..3977219b 100644 --- a/lib/services/address/index.js +++ b/lib/services/address/index.js @@ -16,7 +16,7 @@ var utils = require('../../utils'); var LRU = require('lru-cache'); var XXHash = require('xxhash'); - +const MAX_TX_QUERY_LIMIT = 1000; // See rationale about this cache at function getTxList(next) const TXID_LIST_CACHE_ITEMS = 250; // nr of items (this translates to: consecutive @@ -365,6 +365,11 @@ AddressService.prototype.getAddressUnspentOutputs = function(address, options, c utxoStream.on('data', function(data) { + if(results.length >= MAX_TX_QUERY_LIMIT) { //Max array limit reached, end response + utxoStream.emit('end'); + return; + } + var key = self._encoding.decodeUtxoIndexKey(data.key); var value = self._encoding.decodeUtxoIndexValue(data.value); @@ -551,6 +556,12 @@ AddressService.prototype._getAddressTxidHistory = function(address, options, cal txIdTransformStream._transform = function(chunk, enc, callback) { var txInfo = self._encoding.decodeAddressIndexKey(chunk); + + if(results.length >= MAX_TX_QUERY_LIMIT) { //Max array limit reached, end response + txIdTransformStream.emit('end'); + return; + } + results.push({ txid: txInfo.txid, height: txInfo.height }); callback(); };