Implement filter limit on server side.
MODIFY
WalletWasabi.Backend/Controllers/BlockchainController.cs
WalletWasabi.Backend/Controllers/BlockchainController.cs
@@ -151,45 +151,35 @@ namespace WalletWasabi.Backend.Controllers
/// Gets block filters from the specified block hash.
/// </summary>
/// <remarks>
- /// Sample request:
+ /// Filter examples:
///
- /// Main: GET /filters/0000000000000000001c8018d9cb3b742ef25114f27563e3fc4a1902167f9893
- /// TestNet: GET /filters/00000000000f0d5edcaeba823db17f366be49a80d91d15b77747c2e017b8c20a
- /// RegTest: GET /filters/0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206
+ /// Main: 0000000000000000001c8018d9cb3b742ef25114f27563e3fc4a1902167f9893
+ /// TestNet: 00000000000f0d5edcaeba823db17f366be49a80d91d15b77747c2e017b8c20a
+ /// RegTest: 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206
///
/// </remarks>
/// <param name="bestKnownBlockHash">The best block hash the client knows its filter.</param>
- /// <param name="count">The number of filters to return. By default we return 1000 filters and never more than 10000.</param>
+ /// <param name="count">The number of filters to return.</param>
/// <returns>An array of block hash : element count : filter pairs.</returns>
/// <response code="200">An array of block hash : element count : filter pairs.</response>
/// <response code="204">When the provided hash is the tip.</response>
/// <response code="400">The provided hash was malformed or the count value is out of range</response>
/// <response code="404">If the hash is not found. This happens at blockhain reorg.</response>
- [HttpGet("filters/{bestKnownBlockHash}")]
+ [HttpGet("filters")]
[ProducesResponseType(200)] // Note: If you add typeof(IList<string>) then swagger UI visualization will be ugly.
[ProducesResponseType(204)]
[ProducesResponseType(400)]
[ProducesResponseType(404)]
- public IActionResult GetFilters(string bestKnownBlockHash, int count=1_000)
- {
- if (string.IsNullOrWhiteSpace(bestKnownBlockHash) || !ModelState.IsValid)
+ public IActionResult GetFilters([FromQuery]string bestKnownBlockHash, [FromQuery]int count)
{
- return BadRequest("Invalid block hash provided.");
- }
-
- // Restricts the amount of filters to be returned to about a month of filters. The estimated
- // worst-case-data-size = max-filter-count * avg-filter-size. Taking into account that
- // max-filter-count = (144 filters/day * 30 days/month) and avg-filter-size = 100 bytes/filter
- // worst-case-data-size = (144 * 30) * 100 bytes ~= 420 kb.
- const int maxCount = (144 * 30); //
- if(count < 1 || count > maxCount)
+ if (string.IsNullOrWhiteSpace(bestKnownBlockHash) || count <= 0 || !ModelState.IsValid)
{
- return BadRequest($"Cannot serve less than 1 filter nor more that {maxCount} at a time.");
+ return BadRequest("Invalid block hash or count is provided.");
}
var knownHash = new uint256(bestKnownBlockHash);
- IEnumerable<string> filters = Global.IndexBuilderService.GetFilterLinesExcluding(knownHash, out bool found);
+ IEnumerable<string> filters = Global.IndexBuilderService.GetFilterLinesExcluding(knownHash, count, out bool found);
if(!found)
{
@@ -201,7 +191,7 @@ namespace WalletWasabi.Backend.Controllers
return NoContent();
}
- return Ok(filters.Take(count));
+ return Ok(filters);
}
private async Task<EstimateSmartFeeResponse> GetEstimateSmartFeeAsync(int target, EstimateSmartFeeMode mode)

MODIFY
WalletWasabi/Services/IndexBuilderService.cs
WalletWasabi/Services/IndexBuilderService.cs
@@ -369,17 +369,21 @@ namespace WalletWasabi.Services
});
}
- public IEnumerable<string> GetFilterLinesExcluding(uint256 bestKnownBlockHash, out bool found)
+ public IEnumerable<string> GetFilterLinesExcluding(uint256 bestKnownBlockHash, int count, out bool found)
{
using (IndexLock.Lock())
{
- found = false;
+ found = false; // Only build the filter list from when the known hash is found.
var filters = new List<string>();
foreach (var filter in Index)
{
if (found)
{
filters.Add(filter.ToLine());
+ if(filters.Count >= count)
+ {
+ break;
+ }
}
else
{

Implement filter limit on server side.