From 051c7bf12cfd575b698dee78d655e0fb18b5301c Mon Sep 17 00:00:00 2001 From: Carsten Otto Date: Sat, 4 May 2024 18:50:11 +0200 Subject: [PATCH] fix: when paying, also consider "expensive" hops from own node if "ignore fees from own channels" is not set, local channels should be considered no matter the fee rate --- .../pickhardtpayments/EdgeComputation.java | 4 ++- .../EdgeComputationTest.java | 29 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/EdgeComputation.java b/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/EdgeComputation.java index da63f408..0c64cde9 100644 --- a/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/EdgeComputation.java +++ b/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/EdgeComputation.java @@ -132,7 +132,9 @@ private boolean shouldIgnore( return false; } long feeRate = policy.feeRate(); - if (feeRate >= feeRateLimit) { + boolean hopIsRelevantForFeeCheck = + !pubkey.equals(channelEdge.source()) || !paymentOptions.ignoreFeesForOwnChannels(); + if (feeRate >= feeRateLimit && hopIsRelevantForFeeCheck) { return true; } if (isEdgeToUnwantedFirstHop(channelEdge, paymentOptions, pubkey)) { diff --git a/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/EdgeComputationTest.java b/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/EdgeComputationTest.java index c374f16d..379845f7 100644 --- a/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/EdgeComputationTest.java +++ b/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/EdgeComputationTest.java @@ -151,6 +151,33 @@ void does_not_add_edge_with_fee_rate_at_or_above_limit() { ).containsExactly(CHANNEL_ID_3); } + @Test + void adds_edge_with_fee_rate_at_limit_if_first_hop_and_fee_is_ignored() { + int feeRateLimit = 1000; + PaymentOptions paymentOptions = PaymentOptions.forFeeRateLimit(feeRateLimit); + DirectedChannelEdge edge = + new DirectedChannelEdge(CHANNEL_ID, CAPACITY, PUBKEY_4, PUBKEY_2, policy(feeRateLimit), Policy.UNKNOWN); + when(grpcGraph.getChannelEdges()).thenReturn(Optional.of(Set.of(edge))); + assertThat(edgeComputation.getEdges(paymentOptions, MAX_TIME_LOCK_DELTA).edges()).isNotEmpty(); + } + + @Test + void does_not_add_edge_with_fee_rate_at_limit_if_first_hop_and_fee_is_not_ignored() { + long feeRateLimit = 2000L; + PaymentOptions paymentOptions = new PaymentOptions( + Optional.of(0), + Optional.of(feeRateLimit), + Optional.empty(), + false, + Optional.empty(), + Optional.empty() + ); + DirectedChannelEdge edge = + new DirectedChannelEdge(CHANNEL_ID, CAPACITY, PUBKEY_4, PUBKEY, policy(feeRateLimit), Policy.UNKNOWN); + when(grpcGraph.getChannelEdges()).thenReturn(Optional.of(Set.of(edge))); + assertThat(edgeComputation.getEdges(paymentOptions, MAX_TIME_LOCK_DELTA).edges()).isEmpty(); + } + @Test void does_not_add_first_hop_edge_with_fee_rate_at_or_above_limit_for_first_hops() { Pubkey ownPubkey = EDGE.startNode(); @@ -482,7 +509,7 @@ private void mockEdge() { when(grpcGraph.getChannelEdges()).thenReturn(Optional.of(Set.of(edge))); } - private static Policy policy(int feeRate) { + private static Policy policy(long feeRate) { return new Policy(feeRate, Coins.NONE, true, 40, Coins.NONE, Coins.NONE); }