Add feeestimate accurracy.
MODIFY
WalletWasabi.Tests/UnitTests/AllFeeEstimateTests.cs
WalletWasabi.Tests/UnitTests/AllFeeEstimateTests.cs
@@ -19,7 +19,7 @@ namespace WalletWasabi.Tests.UnitTests
{ 3, 20 },
{ 19, 1 }
};
- var allFee = new AllFeeEstimate(EstimateSmartFeeMode.Conservative, estimations);
+ var allFee = new AllFeeEstimate(EstimateSmartFeeMode.Conservative, estimations, true);
var serialized = JsonConvert.SerializeObject(allFee);
var deserialized = JsonConvert.DeserializeObject<AllFeeEstimate>(serialized);

MODIFY
WalletWasabi/BitcoinCore/Monitoring/RpcMonitor.cs
WalletWasabi/BitcoinCore/Monitoring/RpcMonitor.cs
@@ -20,24 +20,7 @@ namespace WalletWasabi.BitcoinCore.Monitoring
public override async Task<object> ActionAsync(CancellationToken cancel)
{
- try
- {
- var batch = RpcClient.PrepareBatch();
- var bciTask = batch.GetBlockchainInfoAsync();
- var piTask = RpcClient.GetPeersInfoAsync();
- batch.SendBatch();
-
- var bci = await bciTask.ConfigureAwait(false);
- cancel.ThrowIfCancellationRequested();
- var pi = await piTask.ConfigureAwait(false);
-
- return RpcStatus.Responsive(bci.Headers, bci.Blocks, pi.Length);
- }
- catch (Exception ex) when (!(ex is OperationCanceledException || ex is TaskCanceledException || ex is TimeoutException))
- {
- Logger.LogError(ex);
- return RpcStatus.Unresponsive;
- }
+ return await RpcClient.GetRpcStatusAsync(cancel).ConfigureAwait(false);
}
}
}

MODIFY
WalletWasabi/BlockchainAnalysis/FeesEstimation/AllFeeEstimate.cs
WalletWasabi/BlockchainAnalysis/FeesEstimation/AllFeeEstimate.cs
@@ -15,6 +15,12 @@ namespace WalletWasabi.BlockchainAnalysis.FeesEstimation
[JsonProperty]
public EstimateSmartFeeMode Type { get; }
+ /// <summary>
+ /// If it's been fetched from a fully synced node.
+ /// </summary>
+ [JsonProperty]
+ public bool IsAccurate { get; }
+
/// <summary>
/// int: fee target, decimal: satoshi/byte
/// </summary>
@@ -22,9 +28,10 @@ namespace WalletWasabi.BlockchainAnalysis.FeesEstimation
public Dictionary<int, int> Estimations { get; }
[JsonConstructor]
- public AllFeeEstimate(EstimateSmartFeeMode type, IDictionary<int, int> estimations)
+ public AllFeeEstimate(EstimateSmartFeeMode type, IDictionary<int, int> estimations, bool isAccurate)
{
Type = type;
+ IsAccurate = isAccurate;
Guard.NotNullOrEmpty(nameof(estimations), estimations);
Estimations = new Dictionary<int, int>();
var valueSet = new HashSet<decimal>();

MODIFY
WalletWasabi/BlockchainAnalysis/FeesEstimation/FeeProviders.cs
WalletWasabi/BlockchainAnalysis/FeesEstimation/FeeProviders.cs
@@ -52,7 +52,7 @@ namespace WalletWasabi.BlockchainAnalysis.FeesEstimation
{
IFeeProvider provider = providerArray[i];
var allFee = provider.AllFeeEstimate;
- if (allFee != null)
+ if (allFee != null && allFee.IsAccurate)
{
AllFeeEstimate = allFee;
return;

MODIFY
WalletWasabi/Extensions/RPCClientExtensions.cs
WalletWasabi/Extensions/RPCClientExtensions.cs
@@ -3,7 +3,9 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
+using WalletWasabi.BitcoinCore.Monitoring;
using WalletWasabi.BlockchainAnalysis.FeesEstimation;
using WalletWasabi.Helpers;
using WalletWasabi.Logging;
@@ -134,11 +136,34 @@ namespace NBitcoin.RPC
public static async Task<AllFeeEstimate> EstimateAllFeeAsync(this RPCClient rpc, EstimateSmartFeeMode estimateMode = EstimateSmartFeeMode.Conservative, bool simulateIfRegTest = false, bool tolerateBitcoinCoreBrainfuck = true)
{
- var estimations = await rpc.EstimateHalfFeesAsync(new Dictionary<int, int>(), 2, 0, Constants.SevenDaysConfirmationTarget, 0, estimateMode, simulateIfRegTest, tolerateBitcoinCoreBrainfuck);
- var allFeeEstimate = new AllFeeEstimate(estimateMode, estimations);
+ var rpcStatus = await rpc.GetRpcStatusAsync(CancellationToken.None).ConfigureAwait(false);
+ var estimations = await rpc.EstimateHalfFeesAsync(new Dictionary<int, int>(), 2, 0, Constants.SevenDaysConfirmationTarget, 0, estimateMode, simulateIfRegTest, tolerateBitcoinCoreBrainfuck).ConfigureAwait(false);
+ var allFeeEstimate = new AllFeeEstimate(estimateMode, estimations, rpcStatus.Synchronized);
return allFeeEstimate;
}
+ public static async Task<RpcStatus> GetRpcStatusAsync(this RPCClient rpc, CancellationToken cancel)
+ {
+ try
+ {
+ var batch = rpc.PrepareBatch();
+ var bciTask = batch.GetBlockchainInfoAsync();
+ var piTask = rpc.GetPeersInfoAsync();
+ batch.SendBatch();
+
+ var bci = await bciTask.ConfigureAwait(false);
+ cancel.ThrowIfCancellationRequested();
+ var pi = await piTask.ConfigureAwait(false);
+
+ return RpcStatus.Responsive(bci.Headers, bci.Blocks, pi.Length);
+ }
+ catch (Exception ex) when (!(ex is OperationCanceledException || ex is TaskCanceledException || ex is TimeoutException))
+ {
+ Logger.LogError(ex);
+ return RpcStatus.Unresponsive;
+ }
+ }
+
private static async Task<Dictionary<int, int>> EstimateHalfFeesAsync(this RPCClient rpc, IDictionary<int, int> estimations, int smallTarget, int smallFee, int largeTarget, int largeFee, EstimateSmartFeeMode estimateMode = EstimateSmartFeeMode.Conservative, bool simulateIfRegTest = false, bool tolerateBitcoinCoreBrainfuck = true)
{
var newEstimations = new Dictionary<int, int>();

Add feeestimate accurracy.