Select the best set of estimations
Given a set of estimations, select the best estimations available
for the 7 standard confirmation targets.
MODIFY
WalletWasabi.Tests/UnitTests/AllFeeEstimateTests.cs
WalletWasabi.Tests/UnitTests/AllFeeEstimateTests.cs
@@ -23,7 +23,7 @@ namespace WalletWasabi.Tests.UnitTests
Assert.Equal(estimations[2], deserialized.Estimations[2]);
Assert.Equal(estimations[3], deserialized.Estimations[3]);
- Assert.Equal(estimations[19], deserialized.Estimations[19]);
+ Assert.Equal(estimations[19], deserialized.Estimations[36]);
Assert.Equal(EstimateSmartFeeMode.Conservative, deserialized.Type);
}
@@ -34,13 +34,14 @@ namespace WalletWasabi.Tests.UnitTests
{
{ 3, 20 },
{ 2, 102 },
- { 19, 1 }
+ { 19, 1 },
+ { 20, 1 }
};
var allFee = new AllFeeEstimate(EstimateSmartFeeMode.Conservative, estimations, true);
Assert.Equal(estimations[2], allFee.Estimations[2]);
Assert.Equal(estimations[3], allFee.Estimations[3]);
- Assert.Equal(estimations[19], allFee.Estimations[19]);
+ Assert.Equal(estimations[19], allFee.Estimations[36]);
}
[Fact]
@@ -72,17 +73,17 @@ namespace WalletWasabi.Tests.UnitTests
estimations = new Dictionary<int, int>
{
- { 5, 1000 },
+ { 18, 1000 },
{ 3, 21 },
{ 2, 20 },
{ 100, 100 },
- { 4, 4 },
+ { 6, 4 },
};
allFee = new AllFeeEstimate(EstimateSmartFeeMode.Conservative, estimations, true);
Assert.Equal(2, allFee.Estimations.Count);
Assert.Equal(estimations[2], allFee.Estimations[2]);
- Assert.Equal(estimations[4], allFee.Estimations[4]);
+ Assert.Equal(estimations[6], allFee.Estimations[6]);
}
}
}

MODIFY
WalletWasabi/Blockchain/Analysis/FeesEstimation/AllFeeEstimate.cs
WalletWasabi/Blockchain/Analysis/FeesEstimation/AllFeeEstimate.cs
@@ -8,26 +8,40 @@ using WalletWasabi.Helpers;
namespace WalletWasabi.Blockchain.Analysis.FeesEstimation
{
+ /// <summary>
+ /// Estimates for 1w, 3d, 1d, 12h, 6h, 3h, 1h, 30m, 20m.
+ /// </summary>
[JsonObject(MemberSerialization.OptIn)]
public class AllFeeEstimate : IEquatable<AllFeeEstimate>
{
[JsonConstructor]
public AllFeeEstimate(EstimateSmartFeeMode type, IDictionary<int, int> estimations, bool isAccurate)
{
+ Guard.NotNullOrEmpty(nameof(estimations), estimations);
+
Type = type;
IsAccurate = isAccurate;
- Guard.NotNullOrEmpty(nameof(estimations), estimations);
- Estimations = new Dictionary<int, int>();
+
+ var targets = Constants.ConfirmationTargets.Prepend(1).ToArray();
+ var targetRanges = targets.Skip(1).Zip(targets, (x, y) => (Start: y, End: x));
+
+ var filteredEstimations = estimations
+ .Where(x => x.Key >= targets[0] && x.Key <= targets[^1])
+ .OrderBy(x => x.Key)
+ .Select(x => (ConfirmationTarget: x.Key, FeeRate: x.Value, Range: targetRanges.First(y => y.Start < x.Key && x.Key <= y.End)))
+ .GroupBy(x => x.Range, y => y, (x, y) => (Range: x, BestEstimation: y.Last()))
+ .Select(x => (ConfirmationTarget: x.Range.End, FeeRate: x.BestEstimation.FeeRate));
// Make sure values are unique and in the correct order and feerates are consistently decreasing.
+ Estimations = new Dictionary<int, int>();
var lastFeeRate = int.MaxValue;
- foreach (KeyValuePair<int, int> estimation in estimations.OrderBy(x => x.Key))
+ foreach (var estimation in filteredEstimations)
{
// Otherwise it's inconsistent data.
- if (lastFeeRate > estimation.Value)
+ if (lastFeeRate > estimation.FeeRate)
{
- lastFeeRate = estimation.Value;
- Estimations.TryAdd(estimation.Key, estimation.Value);
+ lastFeeRate = estimation.FeeRate;
+ Estimations.TryAdd(estimation.ConfirmationTarget, estimation.FeeRate);
}
}
}

Select the best set of estimations

Given a set of estimations, select the best estimations available
for the 7 standard confirmation targets.