Skip to content

Commit

Permalink
Remove status API (WalletWasabi#13018) (WalletWasabi#13242)
Browse files Browse the repository at this point in the history
It is not used by the wallet.
  • Loading branch information
lontivero authored Jul 25, 2024
1 parent 56fa013 commit 3e447df
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 141 deletions.
63 changes: 0 additions & 63 deletions WalletWasabi.Backend/Controllers/BlockchainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,69 +365,6 @@ public IActionResult GetFilters([FromQuery, Required] string bestKnownBlockHash,
return Ok(response);
}

[HttpGet("status")]
[ProducesResponseType(typeof(StatusResponse), 200)]
public async Task<StatusResponse> GetStatusAsync(CancellationToken cancellationToken)
{
try
{
var cacheKey = $"{nameof(GetStatusAsync)}";
var cacheOptions = new MemoryCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(7) };

return await Cache.GetCachedResponseAsync(
cacheKey,
action: (string request, CancellationToken token) => FetchStatusAsync(token),
options: cacheOptions,
cancellationToken);
}
catch (Exception ex)
{
Logger.LogDebug(ex);
throw;
}
}

private async Task<StatusResponse> FetchStatusAsync(CancellationToken cancellationToken = default)
{
StatusResponse status = new();

// Updating the status of the filters.
if (DateTimeOffset.UtcNow - Global.IndexBuilderService.LastFilterBuildTime > FilterTimeout)
{
// Checking if the last generated filter is created for one of the last two blocks on the blockchain.
var lastFilter = Global.IndexBuilderService.GetLastFilter();
var lastFilterHash = lastFilter.Header.BlockHash;
var bestHash = await RpcClient.GetBestBlockHashAsync(cancellationToken);
var lastBlockHeader = await RpcClient.GetBlockHeaderAsync(bestHash, cancellationToken);
var prevHash = lastBlockHeader.HashPrevBlock;

if (bestHash == lastFilterHash || prevHash == lastFilterHash)
{
status.FilterCreationActive = true;
}
}
else
{
status.FilterCreationActive = true;
}

// Updating the status of WabiSabi coinjoin.
if (Global.WabiSabiCoordinator is { } wabiSabiCoordinator)
{
var ww2CjDownAfter = TimeSpan.FromHours(3);
var wabiSabiValidInterval = wabiSabiCoordinator.Config.StandardInputRegistrationTimeout * 2;
if (wabiSabiValidInterval < ww2CjDownAfter)
{
wabiSabiValidInterval = ww2CjDownAfter;
}
if (DateTimeOffset.UtcNow - wabiSabiCoordinator.LastSuccessfulCoinJoinTime < wabiSabiValidInterval)
{
status.WabiSabiCoinJoinCreationActive = true;
}
}

return status;
}

[HttpGet("unconfirmed-transaction-chain")]
[ProducesResponseType(200)]
Expand Down
71 changes: 0 additions & 71 deletions WalletWasabi.Tests/RegressionTests/BackendTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,76 +307,5 @@ public async Task FilterBuilderTestAsync()
}
}

[Fact]
public async Task StatusRequestTestAsync()
{
await using RegTestSetup setup = await RegTestSetup.InitializeTestEnvironmentAsync(RegTestFixture, numberOfBlocksToGenerate: 1);
IRPCClient rpc = setup.RpcClient;
using Backend.Global global = setup.Global;

var requestUri = "btc/Blockchain/status";

try
{
global.IndexBuilderService.Synchronize();

// Test initial synchronization.
var times = 0;
uint256 firstHash = await rpc.GetBlockHashAsync(0);
while (global.IndexBuilderService.GetFilterLinesExcluding(firstHash, 101, out _).filters.Count() != 101)
{
if (times > 500) // 30 sec
{
throw new TimeoutException($"{nameof(IndexBuilderService)} test timed out.");
}
await Task.Delay(100);
times++;
}

// First request.
using (HttpResponseMessage response = await BackendApiHttpClient.SendAsync(HttpMethod.Get, requestUri))
{
Assert.NotNull(response);

var resp = await response.Content.ReadAsJsonAsync<StatusResponse>();
Assert.True(resp.FilterCreationActive);

// Simulate an unintended stop
await global.IndexBuilderService.StopAsync();
await rpc.GenerateAsync(1);
}

// Second request.
using (HttpResponseMessage response = await BackendApiHttpClient.SendAsync(HttpMethod.Get, requestUri))
{
Assert.NotNull(response);

var resp = await response.Content.ReadAsJsonAsync<StatusResponse>();
Assert.True(resp.FilterCreationActive);

await rpc.GenerateAsync(1);

var blockchainController = RegTestFixture.BackendHost.Services.GetRequiredService<BlockchainController>();
blockchainController.Cache.Remove($"{nameof(BlockchainController.GetStatusAsync)}");

// Set back the time to trigger timeout in BlockchainController.GetStatusAsync.
global.IndexBuilderService.LastFilterBuildTime = DateTimeOffset.UtcNow - BlockchainController.FilterTimeout;
}

// Third request.
using (HttpResponseMessage response = await BackendApiHttpClient.SendAsync(HttpMethod.Get, requestUri))
{
Assert.NotNull(response);

var resp = await response.Content.ReadAsJsonAsync<StatusResponse>();
Assert.False(resp.FilterCreationActive);
}
}
finally
{
await global.IndexBuilderService.StopAsync();
}
}

#endregion BackendTests
}
7 changes: 0 additions & 7 deletions WalletWasabi/Backend/Models/Responses/StatusResponse.cs

This file was deleted.

0 comments on commit 3e447df

Please sign in to comment.