Improve IThirdPartyFeeProvider interface
MODIFY
WalletWasabi.Tests/IntegrationTests/P2pTests.cs
WalletWasabi.Tests/IntegrationTests/P2pTests.cs
@@ -98,9 +98,7 @@ namespace WalletWasabi.Tests.IntegrationTests
KeyManager keyManager = KeyManager.CreateNew(out _, "password");
using HttpClientFactory httpClientFactory = new(Common.TorSocks5Endpoint, backendUriGetter: () => new Uri("http://localhost:12345"));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
- using BlockstreamInfoFeeProvider blockstreamInfoFeeProvider = new(TimeSpan.FromMinutes(3), new BlockstreamInfoClient(network, httpClientFactory));
- using ThirdPartyFeeProvider thirdPartyFeeProvider = new(TimeSpan.FromMinutes(3), synchronizer, blockstreamInfoFeeProvider);
- var feeProvider = new HybridFeeProvider(thirdPartyFeeProvider, null);
+ var feeProvider = new HybridFeeProvider(synchronizer, null);
ServiceConfiguration serviceConfig = new(MixUntilAnonymitySet.PrivacyLevelStrong.ToString(), 2, 21, 50, new IPEndPoint(IPAddress.Loopback, network.DefaultPort), Money.Coins(Constants.DefaultDustThreshold));
CachedBlockProvider blockProvider = new(

MODIFY
WalletWasabi.Tests/RegressionTests/BuildTests.cs
WalletWasabi.Tests/RegressionTests/BuildTests.cs
@@ -58,9 +58,7 @@ namespace WalletWasabi.Tests.RegressionTests
using HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
FilterProcessor filterProcessor = new(synchronizer, bitcoinStore);
- using BlockstreamInfoFeeProvider blockstreamInfoFeeProvider = new(TimeSpan.FromMinutes(3), new BlockstreamInfoClient(network, httpClientFactory));
- using ThirdPartyFeeProvider thirdPartyFeeProvider = new(TimeSpan.FromMinutes(3), synchronizer, blockstreamInfoFeeProvider);
- HybridFeeProvider feeProvider = new(thirdPartyFeeProvider, null);
+ HybridFeeProvider feeProvider = new(synchronizer, null);
// 4. Create key manager service.
var keyManager = KeyManager.CreateNew(out _, password);
@@ -216,9 +214,7 @@ namespace WalletWasabi.Tests.RegressionTests
using HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
FilterProcessor filterProcessor = new(synchronizer, bitcoinStore);
- using BlockstreamInfoFeeProvider blockstreamInfoFeeProvider = new(TimeSpan.FromMinutes(3), new BlockstreamInfoClient(network, httpClientFactory));
- using ThirdPartyFeeProvider thirdPartyFeeProvider = new(TimeSpan.FromMinutes(3), synchronizer, blockstreamInfoFeeProvider);
- HybridFeeProvider feeProvider = new(thirdPartyFeeProvider, null);
+ HybridFeeProvider feeProvider = new(synchronizer, null);
// 4. Create key manager service.
var keyManager = KeyManager.CreateNew(out _, password);

MODIFY
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
@@ -1382,9 +1382,7 @@ namespace WalletWasabi.Tests.RegressionTests
using HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
FilterProcessor filterProcessor = new(synchronizer, bitcoinStore);
- using BlockstreamInfoFeeProvider blockstreamInfoFeeProvider = new(TimeSpan.FromMinutes(3), new BlockstreamInfoClient(network, httpClientFactory));
- using ThirdPartyFeeProvider thirdPartyFeeProvider = new(TimeSpan.FromMinutes(3), synchronizer, blockstreamInfoFeeProvider);
- HybridFeeProvider feeProvider = new(thirdPartyFeeProvider, null);
+ HybridFeeProvider feeProvider = new(synchronizer, null);
// 4. Create key manager service.
var keyManager = KeyManager.CreateNew(out _, password);

MODIFY
WalletWasabi.Tests/RegressionTests/SendTests.cs
WalletWasabi.Tests/RegressionTests/SendTests.cs
@@ -55,9 +55,7 @@ namespace WalletWasabi.Tests.RegressionTests
using HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
FilterProcessor filterProcessor = new(synchronizer, bitcoinStore);
- using BlockstreamInfoFeeProvider blockstreamInfoFeeProvider = new(TimeSpan.FromMinutes(3), new BlockstreamInfoClient(network, httpClientFactory));
- using ThirdPartyFeeProvider thirdPartyFeeProvider = new(TimeSpan.FromMinutes(3), synchronizer, blockstreamInfoFeeProvider);
- HybridFeeProvider feeProvider = new(thirdPartyFeeProvider, null);
+ HybridFeeProvider feeProvider = new(synchronizer, null);
// 4. Create key manager service.
var keyManager = KeyManager.CreateNew(out _, password);
@@ -538,9 +536,7 @@ namespace WalletWasabi.Tests.RegressionTests
using HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
FilterProcessor filterProcessor = new(synchronizer, bitcoinStore);
- using BlockstreamInfoFeeProvider blockstreamInfoFeeProvider = new(TimeSpan.FromMinutes(3), new BlockstreamInfoClient(network, httpClientFactory));
- using ThirdPartyFeeProvider thirdPartyFeeProvider = new(TimeSpan.FromMinutes(3), synchronizer, blockstreamInfoFeeProvider);
- HybridFeeProvider feeProvider = new(thirdPartyFeeProvider, null);
+ HybridFeeProvider feeProvider = new(synchronizer, null);
// 4. Create key manager service.
var keyManager = KeyManager.CreateNew(out _, password);
@@ -712,9 +708,7 @@ namespace WalletWasabi.Tests.RegressionTests
using HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
FilterProcessor filterProcessor = new(synchronizer, bitcoinStore);
- using BlockstreamInfoFeeProvider blockstreamInfoFeeProvider = new(TimeSpan.FromMinutes(3), new BlockstreamInfoClient(network, httpClientFactory));
- using ThirdPartyFeeProvider thirdPartyFeeProvider = new(TimeSpan.FromMinutes(3), synchronizer, blockstreamInfoFeeProvider);
- HybridFeeProvider feeProvider = new(thirdPartyFeeProvider, null);
+ HybridFeeProvider feeProvider = new(synchronizer, null);
// 4. Create key manager service.
var keyManager = KeyManager.CreateNew(out _, password);

MODIFY
WalletWasabi.Tests/RegressionTests/WalletTests.cs
WalletWasabi.Tests/RegressionTests/WalletTests.cs
@@ -248,9 +248,7 @@ namespace WalletWasabi.Tests.RegressionTests
using HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
FilterProcessor filterProcessor = new(synchronizer, bitcoinStore);
- using BlockstreamInfoFeeProvider blockstreamInfoFeeProvider = new(TimeSpan.FromMinutes(3), new BlockstreamInfoClient(network, httpClientFactory));
- using ThirdPartyFeeProvider thirdPartyFeeProvider = new(TimeSpan.FromMinutes(3), synchronizer, blockstreamInfoFeeProvider);
- HybridFeeProvider feeProvider = new(thirdPartyFeeProvider, null);
+ HybridFeeProvider feeProvider = new(synchronizer, null);
// 3. Create key manager service.
var keyManager = KeyManager.CreateNew(out _, password);

MODIFY
WalletWasabi/Blockchain/Analysis/FeesEstimation/HybridFeeProvider.cs
WalletWasabi/Blockchain/Analysis/FeesEstimation/HybridFeeProvider.cs
@@ -20,7 +20,7 @@ namespace WalletWasabi.Blockchain.Analysis.FeesEstimation
/// </summary>
public class HybridFeeProvider : IHostedService
{
- public HybridFeeProvider(ThirdPartyFeeProvider thirdPartyFeeProvider, RpcFeeProvider? rpcFeeProvider)
+ public HybridFeeProvider(IThirdPartyFeeProvider thirdPartyFeeProvider, RpcFeeProvider? rpcFeeProvider)
{
ThirdPartyFeeProvider = thirdPartyFeeProvider;
RpcFeeProvider = rpcFeeProvider;
@@ -29,7 +29,7 @@ namespace WalletWasabi.Blockchain.Analysis.FeesEstimation
public event EventHandler<AllFeeEstimate>? AllFeeEstimateChanged;
public RpcFeeProvider? RpcFeeProvider { get; }
- public ThirdPartyFeeProvider ThirdPartyFeeProvider { get; }
+ public IThirdPartyFeeProvider ThirdPartyFeeProvider { get; }
private object Lock { get; } = new object();
public AllFeeEstimate? AllFeeEstimate { get; private set; }
private AbandonedTasks ProcessingEvents { get; } = new();

MODIFY
WalletWasabi/Blockchain/Analysis/FeesEstimation/IThirdPartyFeeProvider.cs
WalletWasabi/Blockchain/Analysis/FeesEstimation/IThirdPartyFeeProvider.cs
@@ -8,5 +8,9 @@ namespace WalletWasabi.Blockchain.Analysis.FeesEstimation
{
public interface IThirdPartyFeeProvider
{
+ event EventHandler<AllFeeEstimate>? AllFeeEstimateArrived;
+
+ AllFeeEstimate? LastAllFeeEstimate { get; }
+ bool InError { get; }
}
}

MODIFY
WalletWasabi/Blockchain/Analysis/FeesEstimation/ThirdPartyFeeProvider.cs
WalletWasabi/Blockchain/Analysis/FeesEstimation/ThirdPartyFeeProvider.cs
@@ -34,10 +34,10 @@ namespace WalletWasabi.Blockchain.Analysis.FeesEstimation
public override async Task StartAsync(CancellationToken cancellationToken)
{
- SetAllFeeEstimateIfLooksBetter(Synchronizer.LastResponse?.AllFeeEstimate);
+ SetAllFeeEstimateIfLooksBetter(Synchronizer.LastAllFeeEstimate);
SetAllFeeEstimateIfLooksBetter(BlockstreamProvider.LastAllFeeEstimate);
- Synchronizer.ResponseArrived += Synchronizer_ResponseArrived;
+ Synchronizer.AllFeeEstimateArrived += OnAllFeeEstimateArrived;
BlockstreamProvider.AllFeeEstimateArrived += OnAllFeeEstimateArrived;
await base.StartAsync(cancellationToken).ConfigureAwait(false);
@@ -45,18 +45,13 @@ namespace WalletWasabi.Blockchain.Analysis.FeesEstimation
public override async Task StopAsync(CancellationToken cancellationToken)
{
- Synchronizer.ResponseArrived -= Synchronizer_ResponseArrived;
+ Synchronizer.AllFeeEstimateArrived -= OnAllFeeEstimateArrived;
BlockstreamProvider.AllFeeEstimateArrived -= OnAllFeeEstimateArrived;
await ProcessingEvents.WhenAllAsync().ConfigureAwait(false);
await base.StopAsync(cancellationToken).ConfigureAwait(false);
}
- private void Synchronizer_ResponseArrived(object? sender, SynchronizeResponse e)
- {
- OnAllFeeEstimateArrived(sender, e.AllFeeEstimate);
- }
-
private void OnAllFeeEstimateArrived(object? sender, AllFeeEstimate? fees)
{
using (RunningTasks.RememberWith(ProcessingEvents))
@@ -105,15 +100,15 @@ namespace WalletWasabi.Blockchain.Analysis.FeesEstimation
protected override Task ActionAsync(CancellationToken cancel)
{
- if (Synchronizer.BackendStatus == BackendStatus.Connected)
+ if (Synchronizer.InError)
{
- BlockstreamProvider.IsPaused = true;
- InError = false;
+ BlockstreamProvider.IsPaused = false;
+ InError = BlockstreamProvider.InError;
}
else
{
- BlockstreamProvider.IsPaused = false;
- InError = BlockstreamProvider.InError;
+ BlockstreamProvider.IsPaused = true;
+ InError = false;
}
return Task.CompletedTask;

MODIFY
WalletWasabi/Services/WasabiSynchronizer.cs
WalletWasabi/Services/WasabiSynchronizer.cs
@@ -59,6 +59,8 @@ namespace WalletWasabi.Services
public event EventHandler<SynchronizeResponse>? ResponseArrived;
+ public event EventHandler<AllFeeEstimate>? AllFeeEstimateArrived;
+
public SynchronizeResponse? LastResponse { get; private set; }
/// <summary><see cref="WasabiSynchronizer"/> is responsible for disposing of this object.</summary>
@@ -98,6 +100,10 @@ namespace WalletWasabi.Services
/// </summary>
private CancellationTokenSource StopCts { get; }
+ public AllFeeEstimate? LastAllFeeEstimate => LastResponse?.AllFeeEstimate;
+
+ public bool InError => BackendStatus != BackendStatus.Connected;
+
public bool AreRequestsBlocked() => Interlocked.Read(ref _blockRequests) == 1;
public void BlockRequests() => Interlocked.Exchange(ref _blockRequests, 1);
@@ -219,6 +225,10 @@ namespace WalletWasabi.Services
LastResponse = response;
ResponseArrived?.Invoke(this, response);
+ if (response.AllFeeEstimate is { } allFeeEstimate)
+ {
+ AllFeeEstimateArrived?.Invoke(this, allFeeEstimate);
+ }
}
catch (OperationCanceledException)
{

Improve IThirdPartyFeeProvider interface