Skip to content

Commit

Permalink
Increase routing probability when the swap amount is > maxPendingLoca…
Browse files Browse the repository at this point in the history
…lSats (#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
  • Loading branch information
Jossec101 authored Jul 25, 2023
1 parent 887b2dd commit f3d435b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 3 additions & 2 deletions liquidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,9 @@ func manageChannelLiquidity(info ManageChannelLiquidityInfo) error {
// if the swapAmount is bigger than max pending htlc amount, set it to max pending htlc amount
maxPendingLocalSats := int64(channel.GetLocalConstraints().GetMaxPendingAmtMsat() / 1000)
if swapAmount > maxPendingLocalSats && maxPendingLocalSats > 0 {
swapAmount = maxPendingLocalSats
log.WithField("span",span).Infof("swap amount is bigger than max pending htlc amount, setting it to max pending htlc amount: %v", maxPendingLocalSats)
//Lets apply a backoff of 5% to the max pending htlc amount to avoid failing the swap round
swapAmount = int64(float64(maxPendingLocalSats) * 0.95)
log.WithField("span", span).Infof("swap amount is bigger than max pending htlc amount, setting it to max pending htlc amount: %v", swapAmount)
}

//Request nodeguard a new destination address for the reverse swap
Expand Down
18 changes: 16 additions & 2 deletions liquidator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func Test_manageChannelLiquidity(t *testing.T) {
CsvDelay: 144,
ChanReserveSat: 250,
DustLimitSat: 300,
MaxPendingAmtMsat: 300*1000,
MaxPendingAmtMsat: 300 * 1000,
MinHtlcMsat: 350 * 1000,
MaxAcceptedHtlcs: 30,
},
Expand Down Expand Up @@ -146,7 +146,21 @@ func Test_manageChannelLiquidity(t *testing.T) {
},
wantErr: false,
},
{
{
name: "Manage channel liquidity test valid reverse swap bypassing max pending amt",
args: ManageChannelLiquidityInfo{
channel: channelActive,
channelBalanceRatio: 0.1,
channelRules: &[]nodeguard.LiquidityRule{{ChannelId: 123, NodePubkey: "", WalletId: 1, MinimumLocalBalance: 20, MinimumRemoteBalance: 80, RebalanceTarget: 40}},
nodeguardClient: mockNodeGuardClient,
loopProvider: mockProvider,
loopdMacaroon: "0201036c6e6402f801030a10dc64226b045d25f090b114baebcbf04c1201301a160a0761646472657373120472656164120577726974651a130a04696e666f120472656164120577726974651a170a08696e766f69636573120472656164120577726974651a210a086d616361726f6f6e120867656e6572617465120472656164120577726974651a160a076d657373616765120472656164120577726974651a170a086f6666636861696e120472656164120577726974651a160a076f6e636861696e120472656164120577726974651a140a057065657273120472656164120577726974651a180a067369676e6572120867656e657261746512047265616400000620a21b8cc8c071aa5104b706b751aede972f642537c05da31450fb4b02c6da776e",
nodeInfo: nodeInfo,
ctx: context.TODO(),
},
wantErr: false,
},
{
name: "Manage channel liquidity test valid reverse swap bypassing max pending amt",
args: ManageChannelLiquidityInfo{
channel: channelActive,
Expand Down

0 comments on commit f3d435b

Please sign in to comment.