mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
liquidity: exclude prepay from total swap fees
This commit is contained in:
parent
257b5f212d
commit
bf4f72fd8d
4 changed files with 4 additions and 44 deletions
|
|
@ -329,13 +329,6 @@ func (f *FeePortion) loopOutLimits(swapAmt btcutil.Amount,
|
||||||
return newReasonError(ReasonSwapFee)
|
return newReasonError(ReasonSwapFee)
|
||||||
}
|
}
|
||||||
|
|
||||||
if quote.PrepayAmount > feeLimit {
|
|
||||||
log.Debugf("prepay amount: %v greater than fee limit: %v, at "+
|
|
||||||
"%v ppm", quote.PrepayAmount, feeLimit, f.PartsPerMillion)
|
|
||||||
|
|
||||||
return newReasonError(ReasonPrepay)
|
|
||||||
}
|
|
||||||
|
|
||||||
// If our miner and swap fee equal our limit, we will have nothing left
|
// If our miner and swap fee equal our limit, we will have nothing left
|
||||||
// for off-chain fees, so we fail out early.
|
// for off-chain fees, so we fail out early.
|
||||||
if minerFee+quote.SwapFee >= feeLimit {
|
if minerFee+quote.SwapFee >= feeLimit {
|
||||||
|
|
@ -351,7 +344,7 @@ func (f *FeePortion) loopOutLimits(swapAmt btcutil.Amount,
|
||||||
// Calculate the worst case fees that we could pay for this swap,
|
// Calculate the worst case fees that we could pay for this swap,
|
||||||
// ensuring that we are within our fee limit even if the swap fails.
|
// ensuring that we are within our fee limit even if the swap fails.
|
||||||
fees := worstCaseOutFees(
|
fees := worstCaseOutFees(
|
||||||
prepay, route, quote.SwapFee, miner, quote.PrepayAmount,
|
prepay, route, quote.SwapFee, miner,
|
||||||
)
|
)
|
||||||
|
|
||||||
if fees > feeLimit {
|
if fees > feeLimit {
|
||||||
|
|
|
||||||
|
|
@ -845,19 +845,10 @@ func (m *Manager) getSwapRestrictions(ctx context.Context, swapType swap.Type) (
|
||||||
// the prepay because they failed to sweep the on chain htlc. This is unlikely,
|
// the prepay because they failed to sweep the on chain htlc. This is unlikely,
|
||||||
// because we expect clients to be online to sweep, but we want to account for
|
// because we expect clients to be online to sweep, but we want to account for
|
||||||
// every outcome so we include it.
|
// every outcome so we include it.
|
||||||
func worstCaseOutFees(prepayRouting, swapRouting, swapFee, minerFee,
|
func worstCaseOutFees(prepayRouting, swapRouting, swapFee,
|
||||||
prepayAmount btcutil.Amount) btcutil.Amount {
|
minerFee btcutil.Amount) btcutil.Amount {
|
||||||
|
|
||||||
var (
|
return prepayRouting + minerFee + swapFee + swapRouting
|
||||||
successFees = prepayRouting + minerFee + swapFee + swapRouting
|
|
||||||
noShowFees = prepayRouting + prepayAmount
|
|
||||||
)
|
|
||||||
|
|
||||||
if noShowFees > successFees {
|
|
||||||
return noShowFees
|
|
||||||
}
|
|
||||||
|
|
||||||
return successFees
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// existingAutoLoopSummary provides a summary of the existing autoloops which
|
// existingAutoLoopSummary provides a summary of the existing autoloops which
|
||||||
|
|
@ -910,19 +901,11 @@ func (m *Manager) checkExistingAutoLoops(ctx context.Context,
|
||||||
if out.State().State.Type() == loopdb.StateTypePending {
|
if out.State().State.Type() == loopdb.StateTypePending {
|
||||||
summary.inFlightCount++
|
summary.inFlightCount++
|
||||||
|
|
||||||
prepay, err := m.cfg.Lnd.Client.DecodePaymentRequest(
|
|
||||||
ctx, out.Contract.PrepayInvoice,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
summary.pendingFees += worstCaseOutFees(
|
summary.pendingFees += worstCaseOutFees(
|
||||||
out.Contract.MaxPrepayRoutingFee,
|
out.Contract.MaxPrepayRoutingFee,
|
||||||
out.Contract.MaxSwapRoutingFee,
|
out.Contract.MaxSwapRoutingFee,
|
||||||
out.Contract.MaxSwapFee,
|
out.Contract.MaxSwapFee,
|
||||||
out.Contract.MaxMinerFee,
|
out.Contract.MaxMinerFee,
|
||||||
mSatToSatoshis(prepay.Value),
|
|
||||||
)
|
)
|
||||||
} else if out.LastUpdateTime().After(
|
} else if out.LastUpdateTime().After(
|
||||||
m.params.AutoloopBudgetLastRefresh,
|
m.params.AutoloopBudgetLastRefresh,
|
||||||
|
|
|
||||||
|
|
@ -1564,21 +1564,6 @@ func TestFeePercentage(t *testing.T) {
|
||||||
DisqualifiedPeers: noPeersDisqualified,
|
DisqualifiedPeers: noPeersDisqualified,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "prepay too high",
|
|
||||||
feePPM: 30000,
|
|
||||||
quote: &loop.LoopOutQuote{
|
|
||||||
SwapFee: 75,
|
|
||||||
PrepayAmount: 300,
|
|
||||||
MinerFee: 1,
|
|
||||||
},
|
|
||||||
suggestions: &Suggestions{
|
|
||||||
DisqualifiedChans: map[lnwire.ShortChannelID]Reason{
|
|
||||||
chanID1: ReasonPrepay,
|
|
||||||
},
|
|
||||||
DisqualifiedPeers: noPeersDisqualified,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range tests {
|
for _, testCase := range tests {
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ func (l *loopOutSwapSuggestion) fees() btcutil.Amount {
|
||||||
return worstCaseOutFees(
|
return worstCaseOutFees(
|
||||||
l.OutRequest.MaxPrepayRoutingFee, l.OutRequest.MaxSwapRoutingFee,
|
l.OutRequest.MaxPrepayRoutingFee, l.OutRequest.MaxSwapRoutingFee,
|
||||||
l.OutRequest.MaxSwapFee, l.OutRequest.MaxMinerFee,
|
l.OutRequest.MaxSwapFee, l.OutRequest.MaxMinerFee,
|
||||||
l.OutRequest.MaxPrepayAmount,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue