Skip to content

Commit

Permalink
fix: when paying, also consider "expensive" hops from own node
Browse files Browse the repository at this point in the history
if "ignore fees from own channels" is not set, local channels
should be considered no matter the fee rate
C-Otto committed May 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 1dbb355 commit 051c7bf
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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)) {
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 051c7bf

Please sign in to comment.