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 ...@@ -9,36 +9,28 @@ namespace Breeze.Wallet
public class LightWalletFeePolicy : IWalletFeePolicy 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 FeeRate minTxFee;
private readonly Money maxTxFee;
private readonly FeeRate highxFeePerKb;
private readonly FeeRate mediumTxFeePerKb;
private readonly FeeRate lowTxFeePerKb;
/// <summary> public LightWalletFeePolicy()
/// 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)
{ {
this.blockPolicyEstimator = blockPolicyEstimator; // 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
this.minTxFee = new FeeRate(1000); // that leaves with few options:
this.fallbackFee = new FeeRate(20000); // - an external service,
this.payTxFee = new FeeRate(0); // - 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.maxTxFee = new Money(0.1M, MoneyUnit.BTC);
this.minTxFee = new FeeRate(1000);
} }
public Money GetRequiredFee(int txBytes) public Money GetRequiredFee(int txBytes)
...@@ -49,27 +41,23 @@ namespace Breeze.Wallet ...@@ -49,27 +41,23 @@ namespace Breeze.Wallet
public Money GetMinimumFee(int txBytes, int confirmTarget) public Money GetMinimumFee(int txBytes, int confirmTarget)
{ {
// payTxFee is the user-set global for desired feerate // 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) public Money GetMinimumFee(int txBytes, int confirmTarget, Money targetFee)
{ {
Money nFeeNeeded = targetFee; Money feeNeeded = targetFee;
// User didn't set: use -txconfirmtarget to estimate...
if (nFeeNeeded == 0) feeNeeded = this.lowTxFeePerKb.GetFee(txBytes);
{ if (confirmTarget < 50) feeNeeded = this.mediumTxFeePerKb.GetFee(txBytes);
int estimateFoundTarget = confirmTarget; if (confirmTarget < 20) feeNeeded = this.highxFeePerKb.GetFee(txBytes);
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);
}
// prevent user from paying a fee below minRelayTxFee or minTxFee // 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 // But always obey the maximum
if (nFeeNeeded > this.maxTxFee) if (feeNeeded > this.maxTxFee)
nFeeNeeded = this.maxTxFee; feeNeeded = this.maxTxFee;
return nFeeNeeded; 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