Commit 9ef4dcde authored by Dan Gershony's avatar Dan Gershony

Light wallet fee estimator to use hard coded values

parent 6179f392
......@@ -9,36 +9,28 @@ namespace Breeze.Wallet
public class LightWalletFeePolicy : IWalletFeePolicy
{
private readonly BlockPolicyEstimator blockPolicyEstimator;
private readonly Money maxTxFee;
/// <summary>
/// Fees smaller than this (in satoshi) are considered zero fee (for transaction creation)
/// Override with -mintxfee
/// </summary>
private readonly FeeRate minTxFee;
private readonly Money maxTxFee;
private readonly FeeRate highxFeePerKb;
private readonly FeeRate mediumTxFeePerKb;
private readonly FeeRate lowTxFeePerKb;
/// <summary>
/// If fee estimation does not have enough data to provide estimates, use this fee instead.
/// Has no effect if not using fee estimation
/// Override with -fallbackfee
/// </summary>
private readonly FeeRate fallbackFee;
/// <summary>
/// Transaction fee set by the user
/// </summary>
private readonly FeeRate payTxFee;
public LightWalletFeePolicy(BlockPolicyEstimator blockPolicyEstimator)
public LightWalletFeePolicy()
{
this.blockPolicyEstimator = blockPolicyEstimator;
this.minTxFee = new FeeRate(1000);
this.fallbackFee = new FeeRate(20000);
this.payTxFee = new FeeRate(0);
// when estimating the fee, the fee of each transactions needs to be knowen
// as this is an estimator on a light wallet we dont have the UTXO set
// that leaves with few options:
// - an external service,
// - hard code fee per kb
// - we may even be able to monitor the size of the mempool (mini mempool)
// (not the entire trx) and try to estimate based on pending count
// TODO: make fee values confugurable on startup
this.highxFeePerKb = new FeeRate(385939);
this.mediumTxFeePerKb = new FeeRate(245347);
this.lowTxFeePerKb = new FeeRate(171274);
this.maxTxFee = new Money(0.1M, MoneyUnit.BTC);
this.minTxFee = new FeeRate(1000);
}
public Money GetRequiredFee(int txBytes)
......@@ -49,27 +41,23 @@ namespace Breeze.Wallet
public Money GetMinimumFee(int txBytes, int confirmTarget)
{
// payTxFee is the user-set global for desired feerate
return this.GetMinimumFee(txBytes, confirmTarget, this.payTxFee.GetFee(txBytes));
return this.GetMinimumFee(txBytes, confirmTarget, this.lowTxFeePerKb.GetFee(txBytes));
}
public Money GetMinimumFee(int txBytes, int confirmTarget, Money targetFee)
{
Money nFeeNeeded = targetFee;
// User didn't set: use -txconfirmtarget to estimate...
if (nFeeNeeded == 0)
{
int estimateFoundTarget = confirmTarget;
nFeeNeeded = this.blockPolicyEstimator.EstimateSmartFee(confirmTarget, null, out estimateFoundTarget).GetFee(txBytes);
// ... unless we don't have enough mempool data for estimatefee, then use fallbackFee
if (nFeeNeeded == 0)
nFeeNeeded = this.fallbackFee.GetFee(txBytes);
}
Money feeNeeded = targetFee;
feeNeeded = this.lowTxFeePerKb.GetFee(txBytes);
if (confirmTarget < 50) feeNeeded = this.mediumTxFeePerKb.GetFee(txBytes);
if (confirmTarget < 20) feeNeeded = this.highxFeePerKb.GetFee(txBytes);
// prevent user from paying a fee below minRelayTxFee or minTxFee
nFeeNeeded = Math.Max(nFeeNeeded, this.GetRequiredFee(txBytes));
feeNeeded = Math.Max(feeNeeded, this.GetRequiredFee(txBytes));
// But always obey the maximum
if (nFeeNeeded > this.maxTxFee)
nFeeNeeded = this.maxTxFee;
return nFeeNeeded;
if (feeNeeded > this.maxTxFee)
feeNeeded = this.maxTxFee;
return feeNeeded;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment