liquidity: exclude prepay from total swap fees

pull/568/head
George Tsagkarelis 1 year ago
parent 257b5f212d
commit bf4f72fd8d
No known key found for this signature in database
GPG Key ID: 0807D1013F48208A

@ -329,13 +329,6 @@ func (f *FeePortion) loopOutLimits(swapAmt btcutil.Amount,
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
// for off-chain fees, so we fail out early.
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,
// ensuring that we are within our fee limit even if the swap fails.
fees := worstCaseOutFees(
prepay, route, quote.SwapFee, miner, quote.PrepayAmount,
prepay, route, quote.SwapFee, miner,
)
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,
// because we expect clients to be online to sweep, but we want to account for
// every outcome so we include it.
func worstCaseOutFees(prepayRouting, swapRouting, swapFee, minerFee,
prepayAmount btcutil.Amount) btcutil.Amount {
func worstCaseOutFees(prepayRouting, swapRouting, swapFee,
minerFee btcutil.Amount) btcutil.Amount {
var (
successFees = prepayRouting + minerFee + swapFee + swapRouting
noShowFees = prepayRouting + prepayAmount
)
if noShowFees > successFees {
return noShowFees
}
return successFees
return prepayRouting + minerFee + swapFee + swapRouting
}
// 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 {
summary.inFlightCount++
prepay, err := m.cfg.Lnd.Client.DecodePaymentRequest(
ctx, out.Contract.PrepayInvoice,
)
if err != nil {
return nil, err
}
summary.pendingFees += worstCaseOutFees(
out.Contract.MaxPrepayRoutingFee,
out.Contract.MaxSwapRoutingFee,
out.Contract.MaxSwapFee,
out.Contract.MaxMinerFee,
mSatToSatoshis(prepay.Value),
)
} else if out.LastUpdateTime().After(
m.params.AutoloopBudgetLastRefresh,

@ -1564,21 +1564,6 @@ func TestFeePercentage(t *testing.T) {
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 {

@ -28,7 +28,6 @@ func (l *loopOutSwapSuggestion) fees() btcutil.Amount {
return worstCaseOutFees(
l.OutRequest.MaxPrepayRoutingFee, l.OutRequest.MaxSwapRoutingFee,
l.OutRequest.MaxSwapFee, l.OutRequest.MaxMinerFee,
l.OutRequest.MaxPrepayAmount,
)
}

Loading…
Cancel
Save