Skip to content

Commit f3d435b

Browse files
authored
Increase routing probability when the swap amount is > maxPendingLocalSats (#38)
fix(liquidator.go): apply 5% backoff to max pending htlc amount to prevent swap round failures style(liquidator_test.go): adjust spacing for better code readability
1 parent 887b2dd commit f3d435b

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

liquidator.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,9 @@ func manageChannelLiquidity(info ManageChannelLiquidityInfo) error {
446446
// if the swapAmount is bigger than max pending htlc amount, set it to max pending htlc amount
447447
maxPendingLocalSats := int64(channel.GetLocalConstraints().GetMaxPendingAmtMsat() / 1000)
448448
if swapAmount > maxPendingLocalSats && maxPendingLocalSats > 0 {
449-
swapAmount = maxPendingLocalSats
450-
log.WithField("span",span).Infof("swap amount is bigger than max pending htlc amount, setting it to max pending htlc amount: %v", maxPendingLocalSats)
449+
//Lets apply a backoff of 5% to the max pending htlc amount to avoid failing the swap round
450+
swapAmount = int64(float64(maxPendingLocalSats) * 0.95)
451+
log.WithField("span", span).Infof("swap amount is bigger than max pending htlc amount, setting it to max pending htlc amount: %v", swapAmount)
451452
}
452453

453454
//Request nodeguard a new destination address for the reverse swap

liquidator_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func Test_manageChannelLiquidity(t *testing.T) {
117117
CsvDelay: 144,
118118
ChanReserveSat: 250,
119119
DustLimitSat: 300,
120-
MaxPendingAmtMsat: 300*1000,
120+
MaxPendingAmtMsat: 300 * 1000,
121121
MinHtlcMsat: 350 * 1000,
122122
MaxAcceptedHtlcs: 30,
123123
},
@@ -146,7 +146,21 @@ func Test_manageChannelLiquidity(t *testing.T) {
146146
},
147147
wantErr: false,
148148
},
149-
{
149+
{
150+
name: "Manage channel liquidity test valid reverse swap bypassing max pending amt",
151+
args: ManageChannelLiquidityInfo{
152+
channel: channelActive,
153+
channelBalanceRatio: 0.1,
154+
channelRules: &[]nodeguard.LiquidityRule{{ChannelId: 123, NodePubkey: "", WalletId: 1, MinimumLocalBalance: 20, MinimumRemoteBalance: 80, RebalanceTarget: 40}},
155+
nodeguardClient: mockNodeGuardClient,
156+
loopProvider: mockProvider,
157+
loopdMacaroon: "0201036c6e6402f801030a10dc64226b045d25f090b114baebcbf04c1201301a160a0761646472657373120472656164120577726974651a130a04696e666f120472656164120577726974651a170a08696e766f69636573120472656164120577726974651a210a086d616361726f6f6e120867656e6572617465120472656164120577726974651a160a076d657373616765120472656164120577726974651a170a086f6666636861696e120472656164120577726974651a160a076f6e636861696e120472656164120577726974651a140a057065657273120472656164120577726974651a180a067369676e6572120867656e657261746512047265616400000620a21b8cc8c071aa5104b706b751aede972f642537c05da31450fb4b02c6da776e",
158+
nodeInfo: nodeInfo,
159+
ctx: context.TODO(),
160+
},
161+
wantErr: false,
162+
},
163+
{
150164
name: "Manage channel liquidity test valid reverse swap bypassing max pending amt",
151165
args: ManageChannelLiquidityInfo{
152166
channel: channelActive,

0 commit comments

Comments
 (0)