mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2025-12-18 14:44:26 +01:00
use amount of received payments for rating
This commit is contained in:
@@ -8,6 +8,7 @@ import de.cotto.lndmanagej.model.ChannelId;
|
||||
import de.cotto.lndmanagej.model.ClosedChannel;
|
||||
import de.cotto.lndmanagej.model.Coins;
|
||||
import de.cotto.lndmanagej.model.FeeReport;
|
||||
import de.cotto.lndmanagej.model.FlowReport;
|
||||
import de.cotto.lndmanagej.model.LocalChannel;
|
||||
import de.cotto.lndmanagej.model.LocalOpenChannel;
|
||||
import de.cotto.lndmanagej.model.Pubkey;
|
||||
@@ -42,6 +43,7 @@ public class RatingService {
|
||||
private final PolicyService policyService;
|
||||
private final ConfigurationService configurationService;
|
||||
private final BalanceService balanceService;
|
||||
private final FlowService flowService;
|
||||
private final LoadingCache<Pubkey, Rating> peerCache = new CacheBuilder()
|
||||
.withExpiry(EXPIRY)
|
||||
.withRefresh(REFRESH)
|
||||
@@ -62,7 +64,8 @@ public class RatingService {
|
||||
RebalanceService rebalanceService,
|
||||
PolicyService policyService,
|
||||
ConfigurationService configurationService,
|
||||
BalanceService balanceService
|
||||
BalanceService balanceService,
|
||||
FlowService flowService
|
||||
) {
|
||||
this.channelService = channelService;
|
||||
this.ownNodeService = ownNodeService;
|
||||
@@ -71,6 +74,7 @@ public class RatingService {
|
||||
this.policyService = policyService;
|
||||
this.configurationService = configurationService;
|
||||
this.balanceService = balanceService;
|
||||
this.flowService = flowService;
|
||||
}
|
||||
|
||||
public Rating getRatingForPeer(Pubkey peer) {
|
||||
@@ -97,6 +101,7 @@ public class RatingService {
|
||||
}
|
||||
FeeReport feeReport = feeService.getFeeReportForChannel(channelId, durationForAnalysis);
|
||||
RebalanceReport rebalanceReport = rebalanceService.getReportForChannel(channelId, durationForAnalysis);
|
||||
FlowReport flowReport = flowService.getFlowReportForChannel(channelId, durationForAnalysis);
|
||||
long feeRate = policyService.getMinimumFeeRateTo(localChannel.getRemotePubkey()).orElse(0L);
|
||||
long localAvailableMilliSat = getLocalAvailableMilliSat(localChannel);
|
||||
double millionSat = 1.0 * localAvailableMilliSat / 1_000 / 1_000_000;
|
||||
@@ -107,6 +112,7 @@ public class RatingService {
|
||||
|
||||
long rating = feeReport.earned().milliSatoshis();
|
||||
rating += feeReport.sourced().milliSatoshis();
|
||||
rating += flowReport.receivedViaPayments().milliSatoshis();
|
||||
rating += rebalanceReport.supportAsSourceAmount().milliSatoshis() / 10_000;
|
||||
rating += rebalanceReport.supportAsTargetAmount().milliSatoshis() / 10_000;
|
||||
rating += (long) (1.0 * feeRate * millionSat / 10);
|
||||
|
||||
@@ -10,6 +10,7 @@ import de.cotto.lndmanagej.model.Coins;
|
||||
import de.cotto.lndmanagej.model.CoopClosedChannel;
|
||||
import de.cotto.lndmanagej.model.CoopClosedChannelBuilder;
|
||||
import de.cotto.lndmanagej.model.FeeReport;
|
||||
import de.cotto.lndmanagej.model.FlowReport;
|
||||
import de.cotto.lndmanagej.model.LocalChannel;
|
||||
import de.cotto.lndmanagej.model.LocalOpenChannel;
|
||||
import de.cotto.lndmanagej.model.LocalOpenChannelFixtures;
|
||||
@@ -81,6 +82,9 @@ class RatingServiceTest {
|
||||
@Mock
|
||||
private BalanceService balanceService;
|
||||
|
||||
@Mock
|
||||
private FlowService flowService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
int daysAhead = LOCAL_OPEN_CHANNEL_2.getId().getBlockHeight() + 100 * 24 * 60 / 10;
|
||||
@@ -91,6 +95,7 @@ class RatingServiceTest {
|
||||
lenient().when(configurationService.getIntegerValue(any())).thenReturn(Optional.empty());
|
||||
lenient().when(balanceService.getLocalBalanceAverage(any(), anyInt()))
|
||||
.thenReturn(Optional.of(Coins.ofSatoshis(1_000_000)));
|
||||
lenient().when(flowService.getFlowReportForChannel(any(), any())).thenReturn(FlowReport.EMPTY);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -293,6 +298,25 @@ class RatingServiceTest {
|
||||
.contains(new Rating(maxEarnings / 10 / ANALYSIS_DAYS));
|
||||
}
|
||||
|
||||
@Test
|
||||
void received_via_payments() {
|
||||
Coins receivedViaPayments = Coins.ofMilliSatoshis(123_456 * ANALYSIS_DAYS);
|
||||
FlowReport flowReport = new FlowReport(
|
||||
Coins.NONE,
|
||||
Coins.NONE,
|
||||
Coins.NONE,
|
||||
Coins.NONE,
|
||||
Coins.NONE,
|
||||
Coins.NONE,
|
||||
Coins.NONE,
|
||||
Coins.NONE,
|
||||
Coins.NONE,
|
||||
receivedViaPayments
|
||||
);
|
||||
when(flowService.getFlowReportForChannel(CHANNEL_ID, DEFAULT_DURATION_FOR_ANALYSIS)).thenReturn(flowReport);
|
||||
assertThat(ratingService.getRatingForChannel(CHANNEL_ID)).contains(new Rating(123_456));
|
||||
}
|
||||
|
||||
@Test
|
||||
void divided_by_average_million_sats_local() {
|
||||
Coins localAvailableAverage = Coins.ofSatoshis(2_500_000);
|
||||
|
||||
Reference in New Issue
Block a user