Merge pull request #9753 from f321x/debug_ln_payment_failure
ln: don't exclude single part configs for too small payments
This commit is contained in:
@@ -1915,20 +1915,24 @@ class LNWallet(LNWorker):
|
||||
else:
|
||||
return random.choice(list(hardcoded_trampoline_nodes().values())).pubkey
|
||||
|
||||
def suggest_splits(
|
||||
def suggest_payment_splits(
|
||||
self,
|
||||
*,
|
||||
amount_msat: int,
|
||||
final_total_msat: int,
|
||||
my_active_channels: Sequence[Channel],
|
||||
invoice_features: LnFeatures,
|
||||
r_tags,
|
||||
r_tags: Sequence[Sequence[Sequence[Any]]],
|
||||
receiver_pubkey: bytes,
|
||||
) -> List['SplitConfigRating']:
|
||||
channels_with_funds = {
|
||||
(chan.channel_id, chan.node_id): int(chan.available_to_spend(HTLCOwner.LOCAL))
|
||||
for chan in my_active_channels
|
||||
}
|
||||
self.logger.info(f"channels_with_funds: {channels_with_funds}")
|
||||
# if we have a direct channel it's preferrable to send a single part directly through this
|
||||
# channel, so this bool will disable excluding single part payments
|
||||
have_direct_channel = any(chan.node_id == receiver_pubkey for chan in my_active_channels)
|
||||
self.logger.info(f"channels_with_funds: {channels_with_funds}, {have_direct_channel=}")
|
||||
exclude_single_part_payments = False
|
||||
if self.uses_trampoline():
|
||||
# in the case of a legacy payment, we don't allow splitting via different
|
||||
@@ -1944,22 +1948,18 @@ class LNWallet(LNWorker):
|
||||
if invoice_features.supports(LnFeatures.BASIC_MPP_OPT) and not self.config.TEST_FORCE_DISABLE_MPP:
|
||||
# if amt is still large compared to total_msat, split it:
|
||||
if (amount_msat / final_total_msat > self.MPP_SPLIT_PART_FRACTION
|
||||
and amount_msat > self.MPP_SPLIT_PART_MINAMT_MSAT):
|
||||
and amount_msat > self.MPP_SPLIT_PART_MINAMT_MSAT
|
||||
and not have_direct_channel):
|
||||
exclude_single_part_payments = True
|
||||
|
||||
def get_splits():
|
||||
return suggest_splits(
|
||||
amount_msat,
|
||||
channels_with_funds,
|
||||
exclude_single_part_payments=exclude_single_part_payments,
|
||||
exclude_multinode_payments=exclude_multinode_payments,
|
||||
exclude_single_channel_splits=exclude_single_channel_splits
|
||||
)
|
||||
split_configurations = suggest_splits(
|
||||
amount_msat,
|
||||
channels_with_funds,
|
||||
exclude_single_part_payments=exclude_single_part_payments,
|
||||
exclude_multinode_payments=exclude_multinode_payments,
|
||||
exclude_single_channel_splits=exclude_single_channel_splits
|
||||
)
|
||||
|
||||
split_configurations = get_splits()
|
||||
if not split_configurations and exclude_single_part_payments:
|
||||
exclude_single_part_payments = False
|
||||
split_configurations = get_splits()
|
||||
self.logger.info(f'suggest_split {amount_msat} returned {len(split_configurations)} configurations')
|
||||
return split_configurations
|
||||
|
||||
@@ -1989,12 +1989,13 @@ class LNWallet(LNWorker):
|
||||
chan.is_active() and not chan.is_frozen_for_sending()]
|
||||
# try random order
|
||||
random.shuffle(my_active_channels)
|
||||
split_configurations = self.suggest_splits(
|
||||
split_configurations = self.suggest_payment_splits(
|
||||
amount_msat=amount_msat,
|
||||
final_total_msat=paysession.amount_to_pay,
|
||||
my_active_channels=my_active_channels,
|
||||
invoice_features=paysession.invoice_features,
|
||||
r_tags=paysession.r_tags,
|
||||
receiver_pubkey=paysession.invoice_pubkey,
|
||||
)
|
||||
for sc in split_configurations:
|
||||
is_multichan_mpp = len(sc.config.items()) > 1
|
||||
|
||||
@@ -167,6 +167,11 @@ def suggest_splits(
|
||||
if config.total_config_amount() != amount_msat:
|
||||
raise NoPathFound('Cannot distribute payment over channels.')
|
||||
if target_parts > 1 and config.is_any_amount_smaller_than_min_part_size():
|
||||
if target_parts == 2:
|
||||
# if there are already too small parts at the first split excluding single
|
||||
# part payments may return only few configurations, this will allow single part
|
||||
# payments for more payments, if they are too small to split
|
||||
exclude_single_part_payments = False
|
||||
continue
|
||||
assert config.total_config_amount() == amount_msat
|
||||
configs.append(config)
|
||||
|
||||
Reference in New Issue
Block a user