Skip to content

Commit

Permalink
include both policies for Edge and DirectedChannelEdge
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Otto committed May 3, 2024
1 parent 90f2e87 commit 08fec81
Show file tree
Hide file tree
Showing 23 changed files with 218 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ private DirectedChannelEdge toDirectedChannelEdge(RouteHint routeHint) {
FIFTY_COINS,
routeHint.sourceNode(),
routeHint.endNode(),
toPolicy(routeHint)
toPolicy(routeHint),
Policy.UNKNOWN
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ private DirectedChannelEdge edge(Policy policy, Coins capacity, Pubkey target) {
capacity,
PUBKEY,
target,
policy
policy,
Policy.UNKNOWN
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ void get_after_adding_decoded_payment_request() {
routeHintService.addDecodedPaymentRequest(DECODED_PAYMENT_REQUEST);
Policy policy1 = new Policy(123, Coins.NONE, true, 9, ONE_MILLI_SATOSHI, FIFTY_COINS);
Policy policy2 = new Policy(1234, ONE_MILLI_SATOSHI, true, 40, ONE_MILLI_SATOSHI, FIFTY_COINS);
DirectedChannelEdge edge1 = new DirectedChannelEdge(CHANNEL_ID, FIFTY_COINS, PUBKEY, PUBKEY_4, policy1);
DirectedChannelEdge edge2 = new DirectedChannelEdge(CHANNEL_ID_2, FIFTY_COINS, PUBKEY_3, PUBKEY_4, policy2);
DirectedChannelEdge edge1 =
new DirectedChannelEdge(CHANNEL_ID, FIFTY_COINS, PUBKEY, PUBKEY_4, policy1, Policy.UNKNOWN);
DirectedChannelEdge edge2 =
new DirectedChannelEdge(CHANNEL_ID_2, FIFTY_COINS, PUBKEY_3, PUBKEY_4, policy2, Policy.UNKNOWN);
assertThat(routeHintService.getEdgesFromPaymentHints()).contains(edge1, edge2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,23 @@ private Optional<Set<DirectedChannelEdge>> getChannelEdgesWithoutCache() {
Coins capacity = Coins.ofSatoshis(channelEdge.getCapacity());
Pubkey node1Pubkey = Pubkey.create(channelEdge.getNode1Pub());
Pubkey node2Pubkey = Pubkey.create(channelEdge.getNode2Pub());
Policy node1Policy = getNode1Policy(channelEdge);
Policy node2Policy = getNode2Policy(channelEdge);
DirectedChannelEdge directedChannelEdge1 = new DirectedChannelEdge(
channelId,
capacity,
node1Pubkey,
node2Pubkey,
getNode1Policy(channelEdge)
node1Policy,
node2Policy
);
DirectedChannelEdge directedChannelEdge2 = new DirectedChannelEdge(
channelId,
capacity,
node2Pubkey,
node1Pubkey,
getNode2Policy(channelEdge)
node2Policy,
node1Policy
);
channelEdges.add(directedChannelEdge1);
channelEdges.add(directedChannelEdge2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private static Route createLongRoute(DecodedPaymentRequest decodedPaymentRequest
ChannelId channelId = ChannelId.fromShortChannelId(111);
Pubkey pubkey = Pubkey.create("000000000000000000000000000000000000000000000000000000000000000000");
EdgeWithLiquidityInformation dummyEdge = new EdgeWithLiquidityInformation(
new Edge(channelId, pubkey, pubkey, Coins.NONE, Policy.UNKNOWN),
new Edge(channelId, pubkey, pubkey, Coins.NONE, Policy.UNKNOWN, Policy.UNKNOWN),
Coins.NONE,
Coins.NONE
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,23 @@ void two_edges() {
.setNode1Policy(policy(0, 0, true, 40))
.setNode2Policy(policy(1, 0, false, 144))
.build();
Policy policy1 = new Policy(0, Coins.NONE, false, 40, MIN_HTLC, MAX_HTLC);
Policy policy2 = new Policy(1, Coins.NONE, true, 144, MIN_HTLC, MAX_HTLC);
DirectedChannelEdge expectedEdge1 = new DirectedChannelEdge(
CHANNEL_ID,
CAPACITY,
PUBKEY,
PUBKEY_2,
new Policy(0, Coins.NONE, false, 40, MIN_HTLC, MAX_HTLC)
policy1,
policy2
);
DirectedChannelEdge expectedEdge2 = new DirectedChannelEdge(
CHANNEL_ID,
CAPACITY,
PUBKEY_2,
PUBKEY,
new Policy(1, Coins.NONE, true, 144, MIN_HTLC, MAX_HTLC)
policy2,
policy1
);
ChannelEdge edge2 = ChannelEdge.newBuilder()
.setChannelId(CHANNEL_ID_2.getShortChannelId())
Expand All @@ -94,19 +98,23 @@ void two_edges() {
.setNode1Policy(policy(456, 0, false, 123))
.setNode2Policy(policy(123, 1, false, 456))
.build();
Policy policy3 = new Policy(456, Coins.NONE, true, 123, MIN_HTLC, MAX_HTLC);
Policy policy4 = new Policy(123, Coins.ofMilliSatoshis(1), true, 456, MIN_HTLC, MAX_HTLC);
DirectedChannelEdge expectedEdge3 = new DirectedChannelEdge(
CHANNEL_ID_2,
CAPACITY_2,
PUBKEY_3,
PUBKEY_4,
new Policy(456, Coins.NONE, true, 123, MIN_HTLC, MAX_HTLC)
policy3,
policy4
);
DirectedChannelEdge expectedEdge4 = new DirectedChannelEdge(
CHANNEL_ID_2,
CAPACITY_2,
PUBKEY_4,
PUBKEY_3,
new Policy(123, Coins.ofMilliSatoshis(1), true, 456, MIN_HTLC, MAX_HTLC)
policy4,
policy3
);
ChannelGraph channelGraph = ChannelGraph.newBuilder()
.addEdges(edge1)
Expand All @@ -131,14 +139,16 @@ void missing_policy_results_in_disabled_channel() {
CAPACITY,
PUBKEY,
PUBKEY_2,
new Policy(0, Coins.NONE, false, 0, Coins.NONE, Coins.NONE)
Policy.UNKNOWN,
Policy.UNKNOWN
);
DirectedChannelEdge expectedPolicyForNode2 = new DirectedChannelEdge(
CHANNEL_ID,
CAPACITY,
PUBKEY_2,
PUBKEY,
new Policy(0, Coins.NONE, false, 0, Coins.NONE, Coins.NONE)
Policy.UNKNOWN,
Policy.UNKNOWN
);
ChannelGraph channelGraph = ChannelGraph.newBuilder().addEdges(edgeWithMissingPolicy).build();
when(grpcService.describeGraph()).thenReturn(Optional.of(channelGraph));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
package de.cotto.lndmanagej.model;

public record DirectedChannelEdge(ChannelId channelId, Coins capacity, Pubkey source, Pubkey target, Policy policy) {
public record DirectedChannelEdge(
ChannelId channelId,
Coins capacity,
Pubkey source,
Pubkey target,
Policy policy,
Policy reversePolicy
) {
}
11 changes: 9 additions & 2 deletions model/src/main/java/de/cotto/lndmanagej/model/Edge.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package de.cotto.lndmanagej.model;

public record Edge(ChannelId channelId, Pubkey startNode, Pubkey endNode, Coins capacity, Policy policy) {
public record Edge(
ChannelId channelId,
Pubkey startNode,
Pubkey endNode,
Coins capacity,
Policy policy,
Policy reversePolicy
) {
public Edge withCapacity(Coins capacity) {
return new Edge(channelId(), startNode(), endNode(), capacity, policy());
return new Edge(channelId(), startNode(), endNode(), capacity, policy(), reversePolicy());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID;
import static de.cotto.lndmanagej.model.DirectedChannelEdgeFixtures.CHANNEL_EDGE_WITH_POLICY;
import static de.cotto.lndmanagej.model.PolicyFixtures.POLICY_1;
import static de.cotto.lndmanagej.model.PolicyFixtures.POLICY_2;
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -35,4 +36,9 @@ void target() {
void policy() {
assertThat(CHANNEL_EDGE_WITH_POLICY.policy()).isEqualTo(POLICY_1);
}
}

@Test
void reversePolicy() {
assertThat(CHANNEL_EDGE_WITH_POLICY.reversePolicy()).isEqualTo(POLICY_2);
}
}
15 changes: 14 additions & 1 deletion model/src/test/java/de/cotto/lndmanagej/model/EdgeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID;
import static de.cotto.lndmanagej.model.EdgeFixtures.EDGE;
import static de.cotto.lndmanagej.model.PolicyFixtures.POLICY_1;
import static de.cotto.lndmanagej.model.PolicyFixtures.POLICY_2;
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -36,10 +37,22 @@ void policy() {
assertThat(EDGE.policy()).isEqualTo(POLICY_1);
}

@Test
void reversePolicy() {
assertThat(EDGE.reversePolicy()).isEqualTo(POLICY_2);
}

@Test
void withCapacity() {
Coins newCapacity = Coins.ofSatoshis(1);
Edge expected = new Edge(EDGE.channelId(), EDGE.startNode(), EDGE.endNode(), newCapacity, EDGE.policy());
Edge expected = new Edge(
EDGE.channelId(),
EDGE.startNode(),
EDGE.endNode(),
newCapacity,
EDGE.policy(),
EDGE.reversePolicy()
);
assertThat(EDGE.withCapacity(newCapacity)).isEqualTo(expected);
}
}
Loading

0 comments on commit 08fec81

Please sign in to comment.