Random feerate and ensure sanity (#5556)

Suggested at https://github.com/btcpayserver/btcpayserver/pull/5490#issuecomment-1851066223
We can also configure this httpclient to use tor
This commit is contained in:
Andrew Camilleri 2023-12-14 13:20:45 +01:00 committed by GitHub
parent e3863ac076
commit 541cef55b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -56,9 +56,22 @@ public class MempoolSpaceFeeProvider(
"minimumFee" => 144,
_ => -1
};
feesByBlockTarget.TryAdd(target, new FeeRate(value));
feesByBlockTarget.TryAdd(target, new FeeRate(RandomizeByPercentage(value, 10)));
}
return feesByBlockTarget;
})!;
}
static decimal RandomizeByPercentage(decimal value, int percentage)
{
decimal range = value * percentage / 100m;
var res = value + range * (Random.Shared.NextDouble() < 0.5 ? -1 : 1);
return res switch
{
< 1m => 1m,
> 850 => 850,
_ => res
};
}
}