When fee estimation isn't available take the minimum fees instead of throwing exception
MODIFY
WalletWasabi/Extensions/RPCClientExtensions.cs
WalletWasabi/Extensions/RPCClientExtensions.cs
@@ -69,23 +69,45 @@ namespace NBitcoin.RPC
/// </summary>
public static async Task<AllFeeEstimate> EstimateAllFeeAsync(this IRPCClient rpc, EstimateSmartFeeMode estimateMode = EstimateSmartFeeMode.Conservative, bool simulateIfRegTest = false)
{
- var smartEstimations = (simulateIfRegTest && rpc.Network == Network.RegTest)
+ NoEstimationException? noe = null;
+ Dictionary<int, int>? smartEstimations = null;
+ try
+ {
+ smartEstimations = (simulateIfRegTest && rpc.Network == Network.RegTest)
? SimulateRegTestFeeEstimation(estimateMode)
: await GetFeeEstimationsAsync(rpc, estimateMode).ConfigureAwait(false);
+ }
+ catch (NoEstimationException ex)
+ {
+ noe = ex;
+ }
var mempoolInfo = await rpc.GetMempoolInfoAsync().ConfigureAwait(false);
+
+ if ((mempoolInfo.Histogram is null || !mempoolInfo.Histogram.Any()) && noe is not null)
+ {
+ throw noe;
+ }
+
var sanityFeeRate = mempoolInfo.GetSanityFeeRate();
var rpcStatus = await rpc.GetRpcStatusAsync(CancellationToken.None).ConfigureAwait(false);
var minEstimations = GetFeeEstimationsFromMempoolInfo(mempoolInfo);
- var fixedEstimations = smartEstimations.GroupJoin(minEstimations,
+ var fixedEstimations =
+ smartEstimations?
+ .GroupJoin(
+ minEstimations,
outer => outer.Key,
inner => inner.Key,
(outer, inner) => new { Estimation = outer, MinimumFromMemPool = inner })
- .SelectMany(x => x.MinimumFromMemPool.DefaultIfEmpty(),
- (a, b) => (Target: a.Estimation.Key, FeeRate: Math.Max((int)sanityFeeRate.SatoshiPerByte, Math.Max(a.Estimation.Value, b.Value))))
- .ToDictionary(x => x.Target, x => x.FeeRate);
+ .SelectMany(x =>
+ x.MinimumFromMemPool.DefaultIfEmpty(),
+ (a, b) => (
+ Target: a.Estimation.Key,
+ FeeRate: Math.Max((int)sanityFeeRate.SatoshiPerByte, Math.Max(a.Estimation.Value, b.Value))))
+ .ToDictionary(x => x.Target, x => x.FeeRate)
+ ?? minEstimations;
return new AllFeeEstimate(
estimateMode,
@@ -126,6 +148,11 @@ namespace NBitcoin.RPC
private static Dictionary<int, int> GetFeeEstimationsFromMempoolInfo(MemPoolInfo mempoolInfo)
{
+ if (mempoolInfo.Histogram is null || !mempoolInfo.Histogram.Any())
+ {
+ return new Dictionary<int, int>(0);
+ }
+
const int BlockSize = 1_000_000;
static IEnumerable<(int Size, FeeRate From, FeeRate To)> SplitFeeGroupInBlocks(FeeRateGroup group)
{

When fee estimation isn't available take the minimum fees instead of throwing exception