Skip to content

Commit

Permalink
Cache slow synchronize response (#11217)
Browse files Browse the repository at this point in the history
* Limit the number of filters to return

* Cache response for 60 seconds

* Download 10_000 filter for testnet

* Remove comment
  • Loading branch information
lontivero committed Aug 5, 2023
1 parent 18fd25c commit 5686d5d
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions WalletWasabi.Backend/Controllers/BatchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,12 @@ public BatchController(BlockchainController blockchainController, ChaumianCoinJo
public WabiSabiController WabiSabiController { get; }

[HttpGet("synchronize")]
[ResponseCache(Duration = 60)]
public async Task<IActionResult> GetSynchronizeAsync(
[FromQuery, Required] string bestKnownBlockHash,
[FromQuery, Required] int maxNumberOfFilters,
[FromQuery] string? estimateSmartFeeMode = nameof(EstimateSmartFeeMode.Conservative),
[FromQuery] string? indexType = null,
[FromQuery] string indexType = "segwittaproot",
CancellationToken cancellationToken = default)
{
bool estimateSmartFee = !string.IsNullOrWhiteSpace(estimateSmartFeeMode);
EstimateSmartFeeMode mode = EstimateSmartFeeMode.Conservative;
if (estimateSmartFee)
{
if (!Enum.TryParse(estimateSmartFeeMode, ignoreCase: true, out mode))
{
return BadRequest("Invalid estimation mode is provided, possible values: ECONOMICAL/CONSERVATIVE.");
}
}

if (!uint256.TryParse(bestKnownBlockHash, out var knownHash))
{
return BadRequest($"Invalid {nameof(bestKnownBlockHash)}.");
Expand All @@ -66,7 +55,8 @@ public async Task<IActionResult> GetSynchronizeAsync(
return BadRequest("Not supported index type.");
}

(Height bestHeight, IEnumerable<FilterModel> filters) = indexer.GetFilterLinesExcluding(knownHash, maxNumberOfFilters, out bool found);
var numberOfFilters = Global.Config.Network == Network.Main ? 1000 : 10000;
(Height bestHeight, IEnumerable<FilterModel> filters) = indexer.GetFilterLinesExcluding(knownHash, numberOfFilters, out bool found);

var response = new SynchronizeResponse { Filters = Enumerable.Empty<FilterModel>(), BestHeight = bestHeight };

Expand All @@ -86,16 +76,13 @@ public async Task<IActionResult> GetSynchronizeAsync(

response.CcjRoundStates = ChaumianCoinJoinController.GetStatesCollection();

if (estimateSmartFee)
try
{
try
{
response.AllFeeEstimate = await BlockchainController.GetAllFeeEstimateAsync(mode, cancellationToken);
}
catch (Exception ex)
{
Logger.LogError(ex);
}
response.AllFeeEstimate = await BlockchainController.GetAllFeeEstimateAsync(EstimateSmartFeeMode.Conservative, cancellationToken);
}
catch (Exception ex)
{
Logger.LogError(ex);
}

response.ExchangeRates = await OffchainController.GetExchangeRatesCollectionAsync(cancellationToken);
Expand All @@ -105,3 +92,4 @@ public async Task<IActionResult> GetSynchronizeAsync(
return Ok(response);
}
}

0 comments on commit 5686d5d

Please sign in to comment.