lnd icon indicating copy to clipboard operation
lnd copied to clipboard

Try to send the largest amount from a single channel.

Open yaslama opened this issue 5 years ago • 6 comments

When trying to send an amount larger than the balance of any single channel but smaller than the total balance, it's better to send a shard with the amount set to the largest balance instead of halving the initial amount. For instance, if a user has 2 channels with balance of 128k and 16k respectively and tries to send 144k, it's better to try to send one htlc with 128k and another one with 16k than trying 72k, then another one with 36k etc..

yaslama avatar Sep 12 '20 19:09 yaslama

When trying to send an amount larger than the balance of any single channel but smaller than the total balance, it's better to send a shard with the amount set to the largest balance instead of halving the initial amount.

Is it? 🤔

Do you have any evidence to support this claim?

Roasbeef avatar Sep 15 '20 02:09 Roasbeef

I guess the argument is that this may end up with less splits total in the end?

Roasbeef avatar Sep 15 '20 02:09 Roasbeef

I guess the argument is that this may end up with less splits total in the end?

Exactly. For instance if a user with 2 channels with 128_000 and 16_000 sat respectively wants to pay 144_000, using only the divide by two algorithm (without taking into account the min shard value and the max number of shards), the following shards will be sent:

channels: [128000 16000]
paid: 72000
channels: [56000 16000]
paid: 36000
channels: [20000 16000]
paid: 18000
channels: [2000 16000]
paid: 9000
channels: [2000 7000]
paid: 4500
channels: [2000 2500]
paid: 2250
channels: [2000 250]
paid: 1125
channels: [875 250]
paid: 562
channels: [313 250]
paid: 281
channels: [32 250]
paid: 141
channels: [32 109]
paid: 70
channels: [32 39]
paid: 35
channels: [32 4]
paid: 18
channels: [14 4]
paid: 9
channels: [5 4]
paid: 4
channels: [1 4]
paid: 2
channels: [1 2]
paid: 1
channels: [0 2]
paid: 2
channels: [0 0] 

When taking into account the value of the channel with max balance, the following shards will be sent instead:

channels: [128000 16000]
paid: 128000
channels: [0 16000]
paid: 16000
channels: [0 0]

yaslama avatar Sep 15 '20 17:09 yaslama

In the case of 2 channels with balance 89000 and 15000 and a payment of 103000, the two ways to divide gives the following shard amounts:

channels: [89000 15000]
paid: 51500
channels: [37500 15000]
paid: 25750
channels: [11750 15000]
paid: 12875
channels: [11750 2125]
paid: 6437
channels: [5313 2125]
paid: 3219
channels: [2094 2125]
paid: 1609
channels: [485 2125]
paid: 1610
channels: [485 515]

and

channels: [89000 15000]
paid: 89000
channels: [0 15000]
paid: 14000
channels: [0 1000]

As you can see, another advantage of the second way is that we have less "channel fragmentation" after the payment.

yaslama avatar Sep 15 '20 20:09 yaslama

@joostjager: review reminder

lightninglabs-deploy avatar Aug 23 '22 04:08 lightninglabs-deploy

!lightninglabs-deploy mute

Roasbeef avatar Aug 23 '22 20:08 Roasbeef