From 08c561ddc2d59dafd8b30085faea4c6ea8e774b7 Mon Sep 17 00:00:00 2001 From: Carsten Otto Date: Sat, 2 Apr 2022 01:27:41 +0200 Subject: [PATCH] use fee rate weight instead of factor --- .../pickhardtpayments/ArcInitializer.java | 15 ++-- .../pickhardtpayments/FlowComputation.java | 8 +- .../pickhardtpayments/MinCostFlowSolver.java | 4 +- .../MultiPathPaymentSplitter.java | 12 +-- .../PickhardtPaymentsConfiguration.java | 2 +- .../pickhardtpayments/ArcInitializerTest.java | 77 +++++++++++-------- .../MinCostFlowSolverTest.java | 24 +++--- .../MultiPathPaymentSplitterTest.java | 34 ++++---- .../PickhardtPaymentsControllerIT.java | 26 +++---- .../PickhardtPaymentsController.java | 18 ++--- .../PickhardtPaymentsControllerTest.java | 22 +++--- 11 files changed, 129 insertions(+), 113 deletions(-) diff --git a/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/ArcInitializer.java b/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/ArcInitializer.java index 840f879a..3c18c7ad 100644 --- a/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/ArcInitializer.java +++ b/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/ArcInitializer.java @@ -18,7 +18,7 @@ class ArcInitializer { private final Map edgeMapping; private final long quantization; private final int piecewiseLinearApproximations; - private final int feeRateFactor; + private final int feeRateWeight; public ArcInitializer( MinCostFlow minCostFlow, @@ -26,14 +26,14 @@ class ArcInitializer { Map edgeMapping, long quantization, int piecewiseLinearApproximations, - int feeRateFactor + int feeRateWeight ) { this.minCostFlow = minCostFlow; this.pubkeyToIntegerMapping = integerMapping; this.edgeMapping = edgeMapping; this.quantization = quantization; this.piecewiseLinearApproximations = piecewiseLinearApproximations; - this.feeRateFactor = feeRateFactor; + this.feeRateWeight = feeRateWeight; } public void addArcs(Collection edgesWithLiquidityInformation) { @@ -61,14 +61,14 @@ class ArcInitializer { if (capacityPiece == 0) { return; } - long unitCost = quantize(maximumCapacity) / uncertainButPossibleLiquidity; - long feeRateAdditionSummand = feeRateFactor * edge.policy().feeRate(); + long unitCost = 10 * quantize(maximumCapacity) / uncertainButPossibleLiquidity; + long feeRateSummand = feeRateWeight * edge.policy().feeRate(); for (int i = 1; i <= remainingPieces; i++) { int arcIndex = minCostFlow.addArcWithCapacityAndUnitCost( startNode, endNode, capacityPiece, - i * unitCost + feeRateAdditionSummand + i * unitCost + feeRateSummand ); edgeMapping.put(arcIndex, edge); } @@ -78,7 +78,8 @@ class ArcInitializer { if (quantizedLowerBound <= 0) { return piecewiseLinearApproximations; } - int arcIndex = minCostFlow.addArcWithCapacityAndUnitCost(startNode, endNode, quantizedLowerBound, 0); + long feeRateCost = feeRateWeight * edge.policy().feeRate(); + int arcIndex = minCostFlow.addArcWithCapacityAndUnitCost(startNode, endNode, quantizedLowerBound, feeRateCost); edgeMapping.put(arcIndex, edge); return piecewiseLinearApproximations - 1; } diff --git a/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/FlowComputation.java b/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/FlowComputation.java index f62a4402..55144413 100644 --- a/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/FlowComputation.java +++ b/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/FlowComputation.java @@ -8,7 +8,7 @@ import org.springframework.stereotype.Component; import java.util.Map; -import static de.cotto.lndmanagej.pickhardtpayments.PickhardtPaymentsConfiguration.DEFAULT_FEE_RATE_FACTOR; +import static de.cotto.lndmanagej.pickhardtpayments.PickhardtPaymentsConfiguration.DEFAULT_FEE_RATE_WEIGHT; @Component public class FlowComputation { @@ -27,17 +27,17 @@ public class FlowComputation { } public Flows getOptimalFlows(Pubkey source, Pubkey target, Coins amount) { - return getOptimalFlows(source, target, amount, DEFAULT_FEE_RATE_FACTOR); + return getOptimalFlows(source, target, amount, DEFAULT_FEE_RATE_WEIGHT); } - public Flows getOptimalFlows(Pubkey source, Pubkey target, Coins amount, int feeRateFactor) { + public Flows getOptimalFlows(Pubkey source, Pubkey target, Coins amount, int feeRateWeight) { MinCostFlowSolver minCostFlowSolver = new MinCostFlowSolver( edgeComputation.getEdges(), Map.of(source, amount), Map.of(target, amount), quantization, piecewiseLinearApproximations, - feeRateFactor + feeRateWeight ); return minCostFlowSolver.solve(); } diff --git a/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/MinCostFlowSolver.java b/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/MinCostFlowSolver.java index 7b285ce2..22bf2675 100644 --- a/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/MinCostFlowSolver.java +++ b/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/MinCostFlowSolver.java @@ -37,7 +37,7 @@ class MinCostFlowSolver { Map sinks, long quantization, int piecewiseLinearApproximations, - int feeRateFactor + int feeRateWeight ) { this.quantization = quantization; ArcInitializer arcInitializer = new ArcInitializer( @@ -46,7 +46,7 @@ class MinCostFlowSolver { edgeMapping, quantization, piecewiseLinearApproximations, - feeRateFactor + feeRateWeight ); arcInitializer.addArcs(edgesWithLiquidityInformation); setSupply(sources, sinks); diff --git a/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/MultiPathPaymentSplitter.java b/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/MultiPathPaymentSplitter.java index 24ca8c24..b50e24a5 100644 --- a/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/MultiPathPaymentSplitter.java +++ b/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/MultiPathPaymentSplitter.java @@ -12,7 +12,7 @@ import org.springframework.stereotype.Component; import java.util.Set; -import static de.cotto.lndmanagej.pickhardtpayments.PickhardtPaymentsConfiguration.DEFAULT_FEE_RATE_FACTOR; +import static de.cotto.lndmanagej.pickhardtpayments.PickhardtPaymentsConfiguration.DEFAULT_FEE_RATE_WEIGHT; import static java.util.stream.Collectors.toSet; @Component @@ -36,17 +36,17 @@ public class MultiPathPaymentSplitter { return getMultiPathPayment(source, target, amount); } - public MultiPathPayment getMultiPathPaymentTo(Pubkey target, Coins amount, int feeRateFactor) { + public MultiPathPayment getMultiPathPaymentTo(Pubkey target, Coins amount, int feeRateWeight) { Pubkey source = grpcGetInfo.getPubkey(); - return getMultiPathPayment(source, target, amount, feeRateFactor); + return getMultiPathPayment(source, target, amount, feeRateWeight); } public MultiPathPayment getMultiPathPayment(Pubkey source, Pubkey target, Coins amount) { - return getMultiPathPayment(source, target, amount, DEFAULT_FEE_RATE_FACTOR); + return getMultiPathPayment(source, target, amount, DEFAULT_FEE_RATE_WEIGHT); } - public MultiPathPayment getMultiPathPayment(Pubkey source, Pubkey target, Coins amount, int feeRateFactor) { - Flows flows = flowComputation.getOptimalFlows(source, target, amount, feeRateFactor); + public MultiPathPayment getMultiPathPayment(Pubkey source, Pubkey target, Coins amount, int feeRateWeight) { + Flows flows = flowComputation.getOptimalFlows(source, target, amount, feeRateWeight); if (flows.isEmpty()) { return MultiPathPayment.FAILURE; } diff --git a/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/PickhardtPaymentsConfiguration.java b/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/PickhardtPaymentsConfiguration.java index 0dc2ec48..d9364d92 100644 --- a/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/PickhardtPaymentsConfiguration.java +++ b/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/PickhardtPaymentsConfiguration.java @@ -1,7 +1,7 @@ package de.cotto.lndmanagej.pickhardtpayments; public final class PickhardtPaymentsConfiguration { - public static final int DEFAULT_FEE_RATE_FACTOR = 0; + public static final int DEFAULT_FEE_RATE_WEIGHT = 0; private PickhardtPaymentsConfiguration() { // do not instantiate me diff --git a/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/ArcInitializerTest.java b/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/ArcInitializerTest.java index db437ced..0b157d46 100644 --- a/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/ArcInitializerTest.java +++ b/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/ArcInitializerTest.java @@ -25,7 +25,7 @@ import static org.assertj.core.api.Assertions.assertThat; class ArcInitializerTest { private static final int QUANTIZATION = 1; private static final int PIECEWISE_LINEAR_APPROXIMATIONS = 1; - private static final int FEE_RATE_FACTOR = 0; + private static final int FEE_RATE_WEIGHT = 0; static { Loader.loadNativeLibraries(); @@ -40,7 +40,7 @@ class ArcInitializerTest { edgeMapping, QUANTIZATION, PIECEWISE_LINEAR_APPROXIMATIONS, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ); @Test @@ -64,7 +64,7 @@ class ArcInitializerTest { edgeMapping, quantization, PIECEWISE_LINEAR_APPROXIMATIONS, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ); EdgeWithLiquidityInformation edgeWithLiquidityInformation = edge(EDGE, Coins.ofSatoshis(quantization)); @@ -117,10 +117,10 @@ class ArcInitializerTest { edgeMapping, QUANTIZATION, 2, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ); arcInitializer.addArcs(Set.of(edgeWithLiquidityInformation)); - assertThat(minCostFlow.getUnitCost(1)).isEqualTo(1); + assertThat(minCostFlow.getUnitCost(1)).isEqualTo(10 * 100 / (100 - 25)); assertThat(minCostFlow.getCapacity(1)).isEqualTo(75); } @@ -132,7 +132,7 @@ class ArcInitializerTest { edgeMapping, QUANTIZATION, 5, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ); arcInitializer.addArcs(Set.of(edgeWithLiquidityInformation)); assertThat(minCostFlow.getNumArcs()).isEqualTo(5); @@ -146,7 +146,7 @@ class ArcInitializerTest { edgeMapping, edgeWithLiquidityInformation.availableLiquidityLowerBound().satoshis(), PIECEWISE_LINEAR_APPROXIMATIONS, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ); arcInitializer.addArcs(Set.of(edgeWithLiquidityInformation)); assertThat(minCostFlow.getUnitCost(0)).isEqualTo(0); @@ -160,7 +160,7 @@ class ArcInitializerTest { edgeMapping, 20, PIECEWISE_LINEAR_APPROXIMATIONS, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ); arcInitializer.addArcs(Set.of(edgeWithLiquidityInformation)); assertThat(minCostFlow.getCapacity(0)).isEqualTo(1); @@ -174,7 +174,7 @@ class ArcInitializerTest { edgeMapping, 10, 2, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ); arcInitializer.addArcs(Set.of(edgeWithLiquidityInformation)); // one arc for the known liquidity (25 / 10 = 2), 100 / 10 - 2 = 8 remaining @@ -189,12 +189,27 @@ class ArcInitializerTest { edgeMapping, 20, 6, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ); arcInitializer.addArcs(Set.of(edgeWithLiquidityInformation)); // one arc for the known liquidity (25 / 20 = 1), 100 / 20 - 1 = 4 remaining: 4 < 5, no additional arc added assertThat(minCostFlow.getNumArcs()).isEqualTo(1); } + + @Test + void adds_fee_rate_as_cost() { + int feeRateWeight = 1; + ArcInitializer arcInitializer = new ArcInitializer( + minCostFlow, + integerMapping, + edgeMapping, + QUANTIZATION, + PIECEWISE_LINEAR_APPROXIMATIONS, + feeRateWeight + ); + arcInitializer.addArcs(Set.of(edgeWithLiquidityInformation)); + assertThat(minCostFlow.getUnitCost(0)).isEqualTo(200); + } } @Test @@ -206,7 +221,7 @@ class ArcInitializerTest { edgeMapping, QUANTIZATION, piecesPerChannel, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ); arcInitializer.addArcs(List.of( edge(EDGE, Coins.ofSatoshis(100)), @@ -225,7 +240,7 @@ class ArcInitializerTest { edgeMapping, quantization, PIECEWISE_LINEAR_APPROXIMATIONS, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ); EdgeWithLiquidityInformation edgeWithLiquidityInformation = edge(EDGE, Coins.ofSatoshis(quantization - 1)); @@ -242,7 +257,7 @@ class ArcInitializerTest { edgeMapping, quantization, PIECEWISE_LINEAR_APPROXIMATIONS, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ); arcInitializer.addArcs(Set.of(edge(EDGE, Coins.ofSatoshis(20_123)))); assertThat(minCostFlow.getCapacity(0)).isEqualTo(201); @@ -257,13 +272,13 @@ class ArcInitializerTest { edgeMapping, quantization, PIECEWISE_LINEAR_APPROXIMATIONS, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ); arcInitializer.addArcs(List.of( edge(EDGE, Coins.ofSatoshis(20_123)), edge(EDGE_3_4, Coins.ofSatoshis(1_000_000)) )); - assertThat(minCostFlow.getUnitCost(0)).isEqualTo(49); + assertThat(minCostFlow.getUnitCost(0)).isEqualTo(497); } @Test @@ -282,22 +297,22 @@ class ArcInitializerTest { edgeMapping, QUANTIZATION, piecewiseLinearApproximations, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ); arcInitializer.addArcs(List.of( edge(EDGE, Coins.ofSatoshis(10_000)), edge(EDGE_2_3, Coins.ofSatoshis(30_000)) )); assertThat(minCostFlow.getNumArcs()).isEqualTo(10); - assertThat(minCostFlow.getUnitCost(0)).isEqualTo(3); + assertThat(minCostFlow.getUnitCost(0)).isEqualTo(30); assertThat(minCostFlow.getCapacity(0)).isEqualTo(2_000); - assertThat(minCostFlow.getUnitCost(1)).isEqualTo(6); + assertThat(minCostFlow.getUnitCost(1)).isEqualTo(60); assertThat(minCostFlow.getCapacity(1)).isEqualTo(2_000); - assertThat(minCostFlow.getUnitCost(2)).isEqualTo(9); + assertThat(minCostFlow.getUnitCost(2)).isEqualTo(90); assertThat(minCostFlow.getCapacity(2)).isEqualTo(2_000); - assertThat(minCostFlow.getUnitCost(3)).isEqualTo(12); + assertThat(minCostFlow.getUnitCost(3)).isEqualTo(120); assertThat(minCostFlow.getCapacity(3)).isEqualTo(2_000); - assertThat(minCostFlow.getUnitCost(4)).isEqualTo(15); + assertThat(minCostFlow.getUnitCost(4)).isEqualTo(150); assertThat(minCostFlow.getCapacity(4)).isEqualTo(2_000); } @@ -321,8 +336,8 @@ class ArcInitializerTest { EdgeWithLiquidityInformation edge1 = edge(EDGE, Coins.ofSatoshis(3)); EdgeWithLiquidityInformation edge2 = edge(EDGE_1_3, Coins.ofSatoshis(21)); arcInitializer.addArcs(List.of(edge1, edge2)); - assertThat(minCostFlow.getUnitCost(0)).isEqualTo(7L); - assertThat(minCostFlow.getUnitCost(1)).isEqualTo(1L); + assertThat(minCostFlow.getUnitCost(0)).isEqualTo(70L); + assertThat(minCostFlow.getUnitCost(1)).isEqualTo(10L); } @Test @@ -333,8 +348,8 @@ class ArcInitializerTest { Coins.ofSatoshis(8) ); arcInitializer.addArcs(List.of(edge1, edge2)); - assertThat(minCostFlow.getUnitCost(0)).isEqualTo(42 / 3); - assertThat(minCostFlow.getUnitCost(1)).isEqualTo(42 / 8); + assertThat(minCostFlow.getUnitCost(0)).isEqualTo(10 * 42 / 3); + assertThat(minCostFlow.getUnitCost(1)).isEqualTo(10 * 42 / 8); } @Test @@ -342,7 +357,7 @@ class ArcInitializerTest { EdgeWithLiquidityInformation edge1 = edge(EDGE, Coins.ofSatoshis(3)); EdgeWithLiquidityInformation edge2 = edge(EDGE_1_3, Coins.ofSatoshis(20)); arcInitializer.addArcs(List.of(edge1, edge2)); - assertThat(minCostFlow.getUnitCost(0)).isEqualTo(6L); + assertThat(minCostFlow.getUnitCost(0)).isEqualTo(66L); } @Test @@ -351,23 +366,23 @@ class ArcInitializerTest { EdgeWithLiquidityInformation edge2 = edge(EDGE_1_3, Coins.ofSatoshis(20)); EdgeWithLiquidityInformation edge3 = edge(EDGE_1_3, Coins.ofSatoshis(10)); arcInitializer.addArcs(List.of(edge1, edge2, edge3)); - assertThat(minCostFlow.getUnitCost(0)).isEqualTo(10L); + assertThat(minCostFlow.getUnitCost(0)).isEqualTo(100L); } @Test - void computes_unit_cost_with_fee_rate() { - int feeRateFactor = 1; + void computes_unit_cost_with_fee_rate_weight() { + int feeRateWeight = 1; ArcInitializer arcInitializer = new ArcInitializer( minCostFlow, integerMapping, edgeMapping, QUANTIZATION, PIECEWISE_LINEAR_APPROXIMATIONS, - feeRateFactor + feeRateWeight ); EdgeWithLiquidityInformation edge = edge(EDGE, Coins.ofSatoshis(2_000_000)); arcInitializer.addArcs(List.of(edge)); - assertThat(minCostFlow.getUnitCost(0)).isEqualTo(201); + assertThat(minCostFlow.getUnitCost(0)).isEqualTo(210); } private EdgeWithLiquidityInformation edge(Edge edge, Coins capacity) { diff --git a/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/MinCostFlowSolverTest.java b/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/MinCostFlowSolverTest.java index b98d3a98..9f185d98 100644 --- a/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/MinCostFlowSolverTest.java +++ b/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/MinCostFlowSolverTest.java @@ -28,7 +28,7 @@ class MinCostFlowSolverTest { private static final long QUANTIZATION = 1; private static final int PIECEWISE_LINEAR_APPROXIMATIONS = 1; - private static final int FEE_RATE_FACTOR = 0; + private static final int FEE_RATE_WEIGHT = 0; private static final Coins ONE_SAT = Coins.ofSatoshis(PIECEWISE_LINEAR_APPROXIMATIONS); private static final Coins TWO_SATS = ONE_SAT.add(ONE_SAT); private static final Coins MANY_SATS = Coins.ofSatoshis(100_000_000); @@ -50,7 +50,7 @@ class MinCostFlowSolverTest { sinks, QUANTIZATION, PIECEWISE_LINEAR_APPROXIMATIONS, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ) ).doesNotThrowAnyException(); } @@ -68,7 +68,7 @@ class MinCostFlowSolverTest { sinks, QUANTIZATION, PIECEWISE_LINEAR_APPROXIMATIONS, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ) ).doesNotThrowAnyException(); } @@ -86,7 +86,7 @@ class MinCostFlowSolverTest { sinks, QUANTIZATION, PIECEWISE_LINEAR_APPROXIMATIONS, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ) ); } @@ -104,7 +104,7 @@ class MinCostFlowSolverTest { sinks, QUANTIZATION, PIECEWISE_LINEAR_APPROXIMATIONS, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ) ); } @@ -122,7 +122,7 @@ class MinCostFlowSolverTest { sinks, QUANTIZATION, PIECEWISE_LINEAR_APPROXIMATIONS, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ) ); } @@ -166,7 +166,7 @@ class MinCostFlowSolverTest { sinks, quantization, PIECEWISE_LINEAR_APPROXIMATIONS, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ).solve(); assertThat(flows).isEqualTo(new Flows(new Flow(EDGE_2_3, amount))); @@ -187,7 +187,7 @@ class MinCostFlowSolverTest { sinks, quantization, PIECEWISE_LINEAR_APPROXIMATIONS, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ).solve(); assertThat(flows).isEqualTo(new Flows(new Flow(EDGE_3_4, Coins.ofSatoshis(120_000)))); @@ -207,7 +207,7 @@ class MinCostFlowSolverTest { sinks, quantization, PIECEWISE_LINEAR_APPROXIMATIONS, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ).solve(); assertThat(flows).isEqualTo(new Flows()); @@ -228,7 +228,7 @@ class MinCostFlowSolverTest { sinks, QUANTIZATION, PIECEWISE_LINEAR_APPROXIMATIONS, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ); assertThat(minCostFlowSolver.solve()).isEqualTo(new Flows(FLOW_1_2, FLOW_3_4)); @@ -248,7 +248,7 @@ class MinCostFlowSolverTest { sinks, QUANTIZATION, PIECEWISE_LINEAR_APPROXIMATIONS, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ); assertThat(minCostFlowSolver.solve()).isEqualTo(new Flows(FLOW_1_2, FLOW_1_3)); @@ -293,7 +293,7 @@ class MinCostFlowSolverTest { sinks, QUANTIZATION, PIECEWISE_LINEAR_APPROXIMATIONS, - FEE_RATE_FACTOR + FEE_RATE_WEIGHT ).solve(); } } diff --git a/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/MultiPathPaymentSplitterTest.java b/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/MultiPathPaymentSplitterTest.java index cd77e8e2..ea639fb0 100644 --- a/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/MultiPathPaymentSplitterTest.java +++ b/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/MultiPathPaymentSplitterTest.java @@ -26,7 +26,7 @@ import static de.cotto.lndmanagej.model.PolicyFixtures.POLICY_1; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_4; -import static de.cotto.lndmanagej.pickhardtpayments.PickhardtPaymentsConfiguration.DEFAULT_FEE_RATE_FACTOR; +import static de.cotto.lndmanagej.pickhardtpayments.PickhardtPaymentsConfiguration.DEFAULT_FEE_RATE_WEIGHT; import static de.cotto.lndmanagej.pickhardtpayments.model.EdgeFixtures.EDGE; import static de.cotto.lndmanagej.pickhardtpayments.model.FlowFixtures.FLOW; import static org.assertj.core.api.Assertions.assertThat; @@ -62,22 +62,22 @@ class MultiPathPaymentSplitterTest { void getMultiPathPaymentTo_uses_own_pubkey_as_source() { when(grpcGetInfo.getPubkey()).thenReturn(PUBKEY_4); multiPathPaymentSplitter.getMultiPathPaymentTo(PUBKEY_2, AMOUNT); - verify(flowComputation).getOptimalFlows(PUBKEY_4, PUBKEY_2, AMOUNT, DEFAULT_FEE_RATE_FACTOR); + verify(flowComputation).getOptimalFlows(PUBKEY_4, PUBKEY_2, AMOUNT, DEFAULT_FEE_RATE_WEIGHT); } @Test - void getMultiPathPaymentTo_with_fee_rate() { - int feeRateFactor = 123; + void getMultiPathPaymentTo_with_fee_rate_weight() { + int feeRateWeight = 123; when(grpcGetInfo.getPubkey()).thenReturn(PUBKEY_4); MultiPathPayment multiPathPayment = - multiPathPaymentSplitter.getMultiPathPaymentTo(PUBKEY_2, AMOUNT, feeRateFactor); + multiPathPaymentSplitter.getMultiPathPaymentTo(PUBKEY_2, AMOUNT, feeRateWeight); assertThat(multiPathPayment.amount()).isEqualTo(Coins.NONE); - verify(flowComputation).getOptimalFlows(PUBKEY_4, PUBKEY_2, AMOUNT, feeRateFactor); + verify(flowComputation).getOptimalFlows(PUBKEY_4, PUBKEY_2, AMOUNT, feeRateWeight); } @Test void getMultiPathPaymentTo() { - when(flowComputation.getOptimalFlows(PUBKEY, PUBKEY_2, AMOUNT, DEFAULT_FEE_RATE_FACTOR)) + when(flowComputation.getOptimalFlows(PUBKEY, PUBKEY_2, AMOUNT, DEFAULT_FEE_RATE_WEIGHT)) .thenReturn(new Flows(FLOW)); when(grpcGetInfo.getPubkey()).thenReturn(PUBKEY); @@ -99,7 +99,7 @@ class MultiPathPaymentSplitterTest { long capacitySat = EDGE.capacity().satoshis(); Coins halfOfCapacity = Coins.ofSatoshis(capacitySat / 2); Flow flow = new Flow(EDGE, halfOfCapacity); - when(flowComputation.getOptimalFlows(PUBKEY, PUBKEY_2, halfOfCapacity, DEFAULT_FEE_RATE_FACTOR)) + when(flowComputation.getOptimalFlows(PUBKEY, PUBKEY_2, halfOfCapacity, DEFAULT_FEE_RATE_WEIGHT)) .thenReturn(new Flows(flow)); MultiPathPayment multiPathPayment = @@ -110,12 +110,12 @@ class MultiPathPaymentSplitterTest { } @Test - void getMultiPathPayment_with_fee_rate_factor() { - int feeRateFactor = 991; + void getMultiPathPayment_with_fee_rate_weight() { + int feeRateWeight = 991; MultiPathPayment multiPathPayment = - multiPathPaymentSplitter.getMultiPathPayment(PUBKEY, PUBKEY_2, AMOUNT, feeRateFactor); + multiPathPaymentSplitter.getMultiPathPayment(PUBKEY, PUBKEY_2, AMOUNT, feeRateWeight); assertThat(multiPathPayment.amount()).isEqualTo(Coins.NONE); - verify(flowComputation).getOptimalFlows(PUBKEY, PUBKEY_2, AMOUNT, feeRateFactor); + verify(flowComputation).getOptimalFlows(PUBKEY, PUBKEY_2, AMOUNT, feeRateWeight); } @Test @@ -129,7 +129,7 @@ class MultiPathPaymentSplitterTest { when(edgeComputation.getEdgeWithLiquidityInformation(edge1)).thenReturn(noInformationFor(edge1)); when(edgeComputation.getEdgeWithLiquidityInformation(edge2)).thenReturn(noInformationFor(edge2)); Coins totalAmount = halfOfCapacity.add(CAPACITY_2); - when(flowComputation.getOptimalFlows(PUBKEY, PUBKEY_2, totalAmount, DEFAULT_FEE_RATE_FACTOR)) + when(flowComputation.getOptimalFlows(PUBKEY, PUBKEY_2, totalAmount, DEFAULT_FEE_RATE_WEIGHT)) .thenReturn(new Flows(flow1, flow2)); MultiPathPayment multiPathPayment = @@ -146,7 +146,7 @@ class MultiPathPaymentSplitterTest { Coins halfOfCapacity = Coins.ofSatoshis(capacitySat / 2); Flow flow1 = new Flow(EDGE, halfOfCapacity); Flow flow2 = new Flow(EDGE, halfOfCapacity); - when(flowComputation.getOptimalFlows(PUBKEY, PUBKEY_2, EDGE.capacity(), DEFAULT_FEE_RATE_FACTOR)) + when(flowComputation.getOptimalFlows(PUBKEY, PUBKEY_2, EDGE.capacity(), DEFAULT_FEE_RATE_WEIGHT)) .thenReturn(new Flows(flow1, flow2)); MultiPathPayment multiPathPayment = @@ -157,7 +157,7 @@ class MultiPathPaymentSplitterTest { @Test void getMultiPathPayment_adds_remainder_to_most_probable_route() { - when(flowComputation.getOptimalFlows(PUBKEY, PUBKEY_2, AMOUNT, DEFAULT_FEE_RATE_FACTOR)) + when(flowComputation.getOptimalFlows(PUBKEY, PUBKEY_2, AMOUNT, DEFAULT_FEE_RATE_WEIGHT)) .thenReturn(new Flows(FLOW)); assumeThat(FLOW.amount()).isLessThan(AMOUNT); MultiPathPayment multiPathPayment = multiPathPaymentSplitter.getMultiPathPayment(PUBKEY, PUBKEY_2, AMOUNT); @@ -171,7 +171,7 @@ class MultiPathPaymentSplitterTest { EdgeWithLiquidityInformation withLiquidityInformation = EdgeWithLiquidityInformation.forKnownLiquidity(edge, Coins.ofSatoshis(1)); when(edgeComputation.getEdgeWithLiquidityInformation(edge)).thenReturn(withLiquidityInformation); - when(flowComputation.getOptimalFlows(PUBKEY, PUBKEY_2, amount, DEFAULT_FEE_RATE_FACTOR)) + when(flowComputation.getOptimalFlows(PUBKEY, PUBKEY_2, amount, DEFAULT_FEE_RATE_WEIGHT)) .thenReturn(new Flows(FLOW)); Route expected = new Route(List.of(edge), amount).withLiquidityInformation(Set.of(withLiquidityInformation)); @@ -194,7 +194,7 @@ class MultiPathPaymentSplitterTest { when(edgeComputation.getEdgeWithLiquidityInformation(edgeLargeCapacity)).thenReturn(liquidityInformationLarge); when(edgeComputation.getEdgeWithLiquidityInformation(edgeSmallCapacity)).thenReturn(liquidityInformationSmall); - when(flowComputation.getOptimalFlows(PUBKEY, PUBKEY_2, AMOUNT, DEFAULT_FEE_RATE_FACTOR)) + when(flowComputation.getOptimalFlows(PUBKEY, PUBKEY_2, AMOUNT, DEFAULT_FEE_RATE_WEIGHT)) .thenReturn(new Flows( new Flow(edgeLargeCapacity, oneSat), new Flow(edgeSmallCapacity, oneSat) diff --git a/web/src/integrationTest/java/de/cotto/lndmanagej/controller/PickhardtPaymentsControllerIT.java b/web/src/integrationTest/java/de/cotto/lndmanagej/controller/PickhardtPaymentsControllerIT.java index 268e1e45..d932f6a0 100644 --- a/web/src/integrationTest/java/de/cotto/lndmanagej/controller/PickhardtPaymentsControllerIT.java +++ b/web/src/integrationTest/java/de/cotto/lndmanagej/controller/PickhardtPaymentsControllerIT.java @@ -14,7 +14,7 @@ import org.springframework.test.web.servlet.MockMvc; import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2; -import static de.cotto.lndmanagej.pickhardtpayments.PickhardtPaymentsConfiguration.DEFAULT_FEE_RATE_FACTOR; +import static de.cotto.lndmanagej.pickhardtpayments.PickhardtPaymentsConfiguration.DEFAULT_FEE_RATE_WEIGHT; import static de.cotto.lndmanagej.pickhardtpayments.model.MultiPathPaymentFixtures.MULTI_PATH_PAYMENT; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.hasSize; @@ -45,7 +45,7 @@ class PickhardtPaymentsControllerIT { String amountAsString = String.valueOf(amount.satoshis()); String feesAsString = String.valueOf(MULTI_PATH_PAYMENT.fees().milliSatoshis()); double expectedProbability = MULTI_PATH_PAYMENT.probability(); - when(multiPathPaymentSplitter.getMultiPathPaymentTo(PUBKEY, amount, DEFAULT_FEE_RATE_FACTOR)) + when(multiPathPaymentSplitter.getMultiPathPaymentTo(PUBKEY, amount, DEFAULT_FEE_RATE_WEIGHT)) .thenReturn(MULTI_PATH_PAYMENT); mockMvc.perform(get("%s/to/%s/amount/%d".formatted(PREFIX, PUBKEY, amount.satoshis()))) .andExpect(jsonPath("$.probability", is(expectedProbability))) @@ -61,13 +61,13 @@ class PickhardtPaymentsControllerIT { } @Test - void sendTo_with_fee_rate_factor() throws Exception { - int feeRateFactor = 999; + void sendTo_with_fee_rate_weight() throws Exception { + int feeRateWeight = 999; Coins amount = MULTI_PATH_PAYMENT.amount(); - when(multiPathPaymentSplitter.getMultiPathPaymentTo(PUBKEY, amount, feeRateFactor)) + when(multiPathPaymentSplitter.getMultiPathPaymentTo(PUBKEY, amount, feeRateWeight)) .thenReturn(MULTI_PATH_PAYMENT); - String url = "%s/to/%s/amount/%d/fee-rate-factor/%d" - .formatted(PREFIX, PUBKEY, amount.satoshis(), feeRateFactor); + String url = "%s/to/%s/amount/%d/fee-rate-weight/%d" + .formatted(PREFIX, PUBKEY, amount.satoshis(), feeRateWeight); mockMvc.perform(get(url)).andExpect(status().isOk()); } @@ -83,7 +83,7 @@ class PickhardtPaymentsControllerIT { PUBKEY, PUBKEY_2, Coins.ofSatoshis(1_234), - DEFAULT_FEE_RATE_FACTOR + DEFAULT_FEE_RATE_WEIGHT )).thenReturn(MULTI_PATH_PAYMENT); mockMvc.perform(get("%s/from/%s/to/%s/amount/%d".formatted(PREFIX, PUBKEY, PUBKEY_2, 1_234))) .andExpect(jsonPath("$.probability", is(expectedProbability))) @@ -99,13 +99,13 @@ class PickhardtPaymentsControllerIT { } @Test - void send_with_fee_rate_factor() throws Exception { - int feeRateFactor = 999; + void send_with_fee_rate_weight() throws Exception { + int feeRateWeight = 999; Coins amount = MULTI_PATH_PAYMENT.amount(); - when(multiPathPaymentSplitter.getMultiPathPayment(PUBKEY, PUBKEY_2, amount, feeRateFactor)) + when(multiPathPaymentSplitter.getMultiPathPayment(PUBKEY, PUBKEY_2, amount, feeRateWeight)) .thenReturn(MULTI_PATH_PAYMENT); - String url = "%s/from/%s/to/%s/amount/%d/fee-rate-factor/%d" - .formatted(PREFIX, PUBKEY, PUBKEY_2, amount.satoshis(), feeRateFactor); + String url = "%s/from/%s/to/%s/amount/%d/fee-rate-weight/%d" + .formatted(PREFIX, PUBKEY, PUBKEY_2, amount.satoshis(), feeRateWeight); mockMvc.perform(get(url)).andExpect(status().isOk()); } } diff --git a/web/src/main/java/de/cotto/lndmanagej/controller/PickhardtPaymentsController.java b/web/src/main/java/de/cotto/lndmanagej/controller/PickhardtPaymentsController.java index 2804c386..5e238eb0 100644 --- a/web/src/main/java/de/cotto/lndmanagej/controller/PickhardtPaymentsController.java +++ b/web/src/main/java/de/cotto/lndmanagej/controller/PickhardtPaymentsController.java @@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import static de.cotto.lndmanagej.pickhardtpayments.PickhardtPaymentsConfiguration.DEFAULT_FEE_RATE_FACTOR; +import static de.cotto.lndmanagej.pickhardtpayments.PickhardtPaymentsConfiguration.DEFAULT_FEE_RATE_WEIGHT; @RestController @RequestMapping("/beta/pickhardt-payments/") @@ -23,15 +23,15 @@ public class PickhardtPaymentsController { } @Timed - @GetMapping("/to/{pubkey}/amount/{amount}/fee-rate-factor/{feeRateFactor}") + @GetMapping("/to/{pubkey}/amount/{amount}/fee-rate-weight/{feeRateWeight}") public MultiPathPaymentDto sendTo( @PathVariable Pubkey pubkey, @PathVariable long amount, - @PathVariable int feeRateFactor + @PathVariable int feeRateWeight ) { Coins coins = Coins.ofSatoshis(amount); MultiPathPayment multiPathPaymentTo = - multiPathPaymentSplitter.getMultiPathPaymentTo(pubkey, coins, feeRateFactor); + multiPathPaymentSplitter.getMultiPathPaymentTo(pubkey, coins, feeRateWeight); return MultiPathPaymentDto.fromModel(multiPathPaymentTo); } @@ -41,20 +41,20 @@ public class PickhardtPaymentsController { @PathVariable Pubkey pubkey, @PathVariable long amount ) { - return sendTo(pubkey, amount, DEFAULT_FEE_RATE_FACTOR); + return sendTo(pubkey, amount, DEFAULT_FEE_RATE_WEIGHT); } @Timed - @GetMapping("/from/{source}/to/{target}/amount/{amount}/fee-rate-factor/{feeRateFactor}") + @GetMapping("/from/{source}/to/{target}/amount/{amount}/fee-rate-weight/{feeRateWeight}") public MultiPathPaymentDto send( @PathVariable Pubkey source, @PathVariable Pubkey target, @PathVariable long amount, - @PathVariable int feeRateFactor + @PathVariable int feeRateWeight ) { Coins coins = Coins.ofSatoshis(amount); MultiPathPayment multiPathPayment = - multiPathPaymentSplitter.getMultiPathPayment(source, target, coins, feeRateFactor); + multiPathPaymentSplitter.getMultiPathPayment(source, target, coins, feeRateWeight); return MultiPathPaymentDto.fromModel(multiPathPayment); } @@ -65,6 +65,6 @@ public class PickhardtPaymentsController { @PathVariable Pubkey target, @PathVariable long amount ) { - return send(source, target, amount, DEFAULT_FEE_RATE_FACTOR); + return send(source, target, amount, DEFAULT_FEE_RATE_WEIGHT); } } diff --git a/web/src/test/java/de/cotto/lndmanagej/controller/PickhardtPaymentsControllerTest.java b/web/src/test/java/de/cotto/lndmanagej/controller/PickhardtPaymentsControllerTest.java index b52765ec..562ca120 100644 --- a/web/src/test/java/de/cotto/lndmanagej/controller/PickhardtPaymentsControllerTest.java +++ b/web/src/test/java/de/cotto/lndmanagej/controller/PickhardtPaymentsControllerTest.java @@ -11,7 +11,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2; -import static de.cotto.lndmanagej.pickhardtpayments.PickhardtPaymentsConfiguration.DEFAULT_FEE_RATE_FACTOR; +import static de.cotto.lndmanagej.pickhardtpayments.PickhardtPaymentsConfiguration.DEFAULT_FEE_RATE_WEIGHT; import static de.cotto.lndmanagej.pickhardtpayments.model.MultiPathPaymentFixtures.MULTI_PATH_PAYMENT; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @@ -27,18 +27,18 @@ class PickhardtPaymentsControllerTest { @Test void sendTo() { - when(multiPathPaymentSplitter.getMultiPathPaymentTo(PUBKEY, Coins.ofSatoshis(456), DEFAULT_FEE_RATE_FACTOR)) + when(multiPathPaymentSplitter.getMultiPathPaymentTo(PUBKEY, Coins.ofSatoshis(456), DEFAULT_FEE_RATE_WEIGHT)) .thenReturn(MULTI_PATH_PAYMENT); assertThat(controller.sendTo(PUBKEY, 456)) .isEqualTo(MultiPathPaymentDto.fromModel(MULTI_PATH_PAYMENT)); } @Test - void sendTo_with_fee_rate_factor() { - int feeRateFactor = 10; - when(multiPathPaymentSplitter.getMultiPathPaymentTo(PUBKEY, Coins.ofSatoshis(456), feeRateFactor)) + void sendTo_with_fee_rate_weight() { + int feeRateWeight = 10; + when(multiPathPaymentSplitter.getMultiPathPaymentTo(PUBKEY, Coins.ofSatoshis(456), feeRateWeight)) .thenReturn(MULTI_PATH_PAYMENT); - assertThat(controller.sendTo(PUBKEY, 456, feeRateFactor)) + assertThat(controller.sendTo(PUBKEY, 456, feeRateWeight)) .isEqualTo(MultiPathPaymentDto.fromModel(MULTI_PATH_PAYMENT)); } @@ -48,22 +48,22 @@ class PickhardtPaymentsControllerTest { PUBKEY, PUBKEY_2, Coins.ofSatoshis(123), - DEFAULT_FEE_RATE_FACTOR + DEFAULT_FEE_RATE_WEIGHT )).thenReturn(MULTI_PATH_PAYMENT); assertThat(controller.send(PUBKEY, PUBKEY_2, 123)) .isEqualTo(MultiPathPaymentDto.fromModel(MULTI_PATH_PAYMENT)); } @Test - void send_with_fee_rate_factor() { - int feeRateFactor = 20; + void send_with_fee_rate_weight() { + int feeRateWeight = 20; when(multiPathPaymentSplitter.getMultiPathPayment( PUBKEY, PUBKEY_2, Coins.ofSatoshis(123), - feeRateFactor + feeRateWeight )).thenReturn(MULTI_PATH_PAYMENT); - assertThat(controller.send(PUBKEY, PUBKEY_2, 123, feeRateFactor)) + assertThat(controller.send(PUBKEY, PUBKEY_2, 123, feeRateWeight)) .isEqualTo(MultiPathPaymentDto.fromModel(MULTI_PATH_PAYMENT)); } }