Skip to content

Commit 39bb43c

Browse files
authored
Merge pull request #568 from GeorgeTsagk/fee-percentage-fix
liquidity: exclude prepay from total swap fees
2 parents 3f316c9 + bf4f72f commit 39bb43c

File tree

4 files changed

+4
-44
lines changed

4 files changed

+4
-44
lines changed

liquidity/fees.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,6 @@ func (f *FeePortion) loopOutLimits(swapAmt btcutil.Amount,
329329
return newReasonError(ReasonSwapFee)
330330
}
331331

332-
if quote.PrepayAmount > feeLimit {
333-
log.Debugf("prepay amount: %v greater than fee limit: %v, at "+
334-
"%v ppm", quote.PrepayAmount, feeLimit, f.PartsPerMillion)
335-
336-
return newReasonError(ReasonPrepay)
337-
}
338-
339332
// If our miner and swap fee equal our limit, we will have nothing left
340333
// for off-chain fees, so we fail out early.
341334
if minerFee+quote.SwapFee >= feeLimit {
@@ -351,7 +344,7 @@ func (f *FeePortion) loopOutLimits(swapAmt btcutil.Amount,
351344
// Calculate the worst case fees that we could pay for this swap,
352345
// ensuring that we are within our fee limit even if the swap fails.
353346
fees := worstCaseOutFees(
354-
prepay, route, quote.SwapFee, miner, quote.PrepayAmount,
347+
prepay, route, quote.SwapFee, miner,
355348
)
356349

357350
if fees > feeLimit {

liquidity/liquidity.go

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -845,19 +845,10 @@ func (m *Manager) getSwapRestrictions(ctx context.Context, swapType swap.Type) (
845845
// the prepay because they failed to sweep the on chain htlc. This is unlikely,
846846
// because we expect clients to be online to sweep, but we want to account for
847847
// every outcome so we include it.
848-
func worstCaseOutFees(prepayRouting, swapRouting, swapFee, minerFee,
849-
prepayAmount btcutil.Amount) btcutil.Amount {
848+
func worstCaseOutFees(prepayRouting, swapRouting, swapFee,
849+
minerFee btcutil.Amount) btcutil.Amount {
850850

851-
var (
852-
successFees = prepayRouting + minerFee + swapFee + swapRouting
853-
noShowFees = prepayRouting + prepayAmount
854-
)
855-
856-
if noShowFees > successFees {
857-
return noShowFees
858-
}
859-
860-
return successFees
851+
return prepayRouting + minerFee + swapFee + swapRouting
861852
}
862853

863854
// existingAutoLoopSummary provides a summary of the existing autoloops which
@@ -910,19 +901,11 @@ func (m *Manager) checkExistingAutoLoops(ctx context.Context,
910901
if out.State().State.Type() == loopdb.StateTypePending {
911902
summary.inFlightCount++
912903

913-
prepay, err := m.cfg.Lnd.Client.DecodePaymentRequest(
914-
ctx, out.Contract.PrepayInvoice,
915-
)
916-
if err != nil {
917-
return nil, err
918-
}
919-
920904
summary.pendingFees += worstCaseOutFees(
921905
out.Contract.MaxPrepayRoutingFee,
922906
out.Contract.MaxSwapRoutingFee,
923907
out.Contract.MaxSwapFee,
924908
out.Contract.MaxMinerFee,
925-
mSatToSatoshis(prepay.Value),
926909
)
927910
} else if out.LastUpdateTime().After(
928911
m.params.AutoloopBudgetLastRefresh,

liquidity/liquidity_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,21 +1564,6 @@ func TestFeePercentage(t *testing.T) {
15641564
DisqualifiedPeers: noPeersDisqualified,
15651565
},
15661566
},
1567-
{
1568-
name: "prepay too high",
1569-
feePPM: 30000,
1570-
quote: &loop.LoopOutQuote{
1571-
SwapFee: 75,
1572-
PrepayAmount: 300,
1573-
MinerFee: 1,
1574-
},
1575-
suggestions: &Suggestions{
1576-
DisqualifiedChans: map[lnwire.ShortChannelID]Reason{
1577-
chanID1: ReasonPrepay,
1578-
},
1579-
DisqualifiedPeers: noPeersDisqualified,
1580-
},
1581-
},
15821567
}
15831568

15841569
for _, testCase := range tests {

liquidity/loopout.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func (l *loopOutSwapSuggestion) fees() btcutil.Amount {
2828
return worstCaseOutFees(
2929
l.OutRequest.MaxPrepayRoutingFee, l.OutRequest.MaxSwapRoutingFee,
3030
l.OutRequest.MaxSwapFee, l.OutRequest.MaxMinerFee,
31-
l.OutRequest.MaxPrepayAmount,
3231
)
3332
}
3433

0 commit comments

Comments
 (0)